r61342 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61341‎ | r61342 | r61343 >
Date:21:34, 21 January 2010
Author:simetrical
Status:ok
Tags:
Comment:
Revert broken r61251 use of strong equality

== and === mean different things. Do *not* blindly change one to the
other, *only* change them if you know that weak equality checks are
causing a bug -- or at least if you're sure that changing them will not
cause a bug. r61251 caused subtle bugs in mwsuggest that took me an
unnecessarily long time to track down while I was doing unrelated work.
Modified paths:
  • /trunk/phase3/skins/common/mwsuggest.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/mwsuggest.js
@@ -92,7 +92,7 @@
9393 var id = os_autoload_inputs[i];
9494 var form = os_autoload_forms[i];
9595 element = document.getElementById( id );
96 - if( element !== null ) {
 96+ if( element != null ) {
9797 os_initHandlers( id, form, element );
9898 }
9999 }
@@ -112,7 +112,7 @@
113113 os_hookEvent( document.getElementById( formname ), 'submit', function( event ) { return os_eventOnsubmit( event ); } );
114114 os_map[name] = r;
115115 // toggle link
116 - if( document.getElementById( r.toggle ) === null ) {
 116+ if( document.getElementById( r.toggle ) == null ) {
117117 // TODO: disable this while we figure out a way for this to work in all browsers
118118 /* if( name == 'searchInput' ) {
119119 // special case: place above the main search box
@@ -153,12 +153,12 @@
154154 function os_eventKeyup( e ) {
155155 var targ = os_getTarget( e );
156156 var r = os_map[targ.id];
157 - if( r === null ) {
 157+ if( r == null ) {
158158 return; // not our event
159159 }
160160
161161 // some browsers won't generate keypressed for arrow keys, catch it
162 - if( os_keypressed_count === 0 ) {
 162+ if( os_keypressed_count == 0 ) {
163163 os_processKey( r, os_cur_keypressed, targ );
164164 }
165165 var query = targ.value;
@@ -170,7 +170,7 @@
171171 if ( keypressed == 40 ) { // Arrow Down
172172 if ( r.visible ) {
173173 os_changeHighlight( r, r.selected, r.selected + 1, true );
174 - } else if( os_timer === null ) {
 174+ } else if( os_timer == null ) {
175175 // user wants to get suggestions now
176176 r.query = '';
177177 os_fetchResults( r, targ.value, 0 );
@@ -192,7 +192,7 @@
193193 function os_eventKeypress( e ) {
194194 var targ = os_getTarget( e );
195195 var r = os_map[targ.id];
196 - if( r === null ) {
 196+ if( r == null ) {
197197 return; // not our event
198198 }
199199
@@ -209,13 +209,13 @@
210210 }
211211 var targ = os_getTarget( e );
212212 var r = os_map[targ.id];
213 - if( r === null ) {
 213+ if( r == null ) {
214214 return; // not our event
215215 }
216216
217217 os_mouse_moved = false;
218218
219 - os_cur_keypressed = ( e.keyCode === undefined ) ? e.which : e.keyCode;
 219+ os_cur_keypressed = ( e.keyCode == undefined ) ? e.which : e.keyCode;
220220 os_keypressed_count = 0;
221221 }
222222
@@ -223,7 +223,7 @@
224224 function os_eventBlur( e ) {
225225 var targ = os_getTarget( e );
226226 var r = os_map[targ.id];
227 - if( r === null ) {
 227+ if( r == null ) {
228228 return; // not our event
229229 }
230230 if( !os_mouse_pressed ) {
@@ -231,7 +231,7 @@
232232 // force canvas to stay hidden
233233 r.stayHidden = true;
234234 // cancel any pending fetches
235 - if( os_timer !== null && os_timer.id !== null ) {
 235+ if( os_timer != null && os_timer.id != null ) {
236236 clearTimeout( os_timer.id );
237237 }
238238 os_timer = null;
@@ -242,7 +242,7 @@
243243 function os_eventFocus( e ) {
244244 var targ = os_getTarget( e );
245245 var r = os_map[targ.id];
246 - if( r === null ) {
 246+ if( r == null ) {
247247 return; // not our event
248248 }
249249 r.stayHidden = false;
@@ -255,16 +255,16 @@
256256
257257 os_is_stopped = true;
258258 // kill timed requests
259 - if( os_timer !== null && os_timer.id !== null ) {
 259+ if( os_timer != null && os_timer.id != null ) {
260260 clearTimeout( os_timer.id );
261261 os_timer = null;
262262 }
263263 // Hide all suggestions
264264 for( i = 0; i < os_autoload_inputs.length; i++ ) {
265265 var r = os_map[os_autoload_inputs[i]];
266 - if( r !== null ) {
 266+ if( r != null ) {
267267 var b = document.getElementById( r.searchform );
268 - if( b !== null && b == targ ) {
 268+ if( b != null && b == targ ) {
269269 // set query value so the handler won't try to fetch additional results
270270 r.query = document.getElementById( r.searchbox ).value;
271271 }
@@ -279,7 +279,7 @@
280280 /** Hide results div */
281281 function os_hideResults( r ) {
282282 var c = document.getElementById( r.container );
283 - if( c !== null ) {
 283+ if( c != null ) {
284284 c.style.visibility = 'hidden';
285285 }
286286 r.visible = false;
@@ -297,7 +297,7 @@
298298 os_fitContainer( r );
299299 var c = document.getElementById( r.container );
300300 r.selected = -1;
301 - if( c !== null ) {
 301+ if( c != null ) {
302302 c.scrollTop = 0;
303303 c.style.visibility = 'visible';
304304 r.visible = true;
@@ -480,7 +480,7 @@
481481 var newW = Math.round( normW * prop );
482482 if( w != newW ) {
483483 w = newW;
484 - if( os_animation_timer !== null ) {
 484+ if( os_animation_timer != null ) {
485485 clearInterval( os_animation_timer.id );
486486 }
487487 os_animation_timer = new os_AnimationTimer( r, w );
@@ -549,14 +549,14 @@
550550 } else {
551551 try {
552552 var p = eval( '(' + text + ')' ); // simple json parse, could do a safer one
553 - if( p.length < 2 || p[1].length === 0 ) {
 553+ if( p.length < 2 || p[1].length == 0 ) {
554554 r.results = null;
555555 r.resultCount = 0;
556556 os_hideResults( r );
557557 return;
558558 }
559559 var c = document.getElementById( r.container );
560 - if( c === null ) {
 560+ if( c == null ) {
561561 c = os_createContainer( r );
562562 }
563563 c.innerHTML = os_createResultTable( r, p[1] );
@@ -619,7 +619,7 @@
620620 /** Update results if user hasn't already typed something else */
621621 function os_updateIfRelevant( r, query, text, cacheKey ) {
622622 var t = document.getElementById( r.searchbox );
623 - if( t !== null && t.value == query ) { // check if response is still relevant
 623+ if( t != null && t.value == query ) { // check if response is still relevant
624624 os_updateResults( r, query, text, cacheKey );
625625 }
626626 r.query = query;
@@ -627,7 +627,7 @@
628628
629629 /** Fetch results after some timeout */
630630 function os_delayedFetch() {
631 - if( os_timer === null ) {
 631+ if( os_timer == null ) {
632632 return;
633633 }
634634 var r = os_timer.r;
@@ -639,7 +639,7 @@
640640
641641 // try to get from cache, if not fetch using ajax
642642 var cached = os_cache[path];
643 - if( cached !== null ) {
 643+ if( cached != null ) {
644644 os_updateIfRelevant( r, query, cached, path );
645645 } else {
646646 var xmlhttp = sajax_init_object();
@@ -682,11 +682,11 @@
683683 } */
684684
685685 // cancel any pending fetches
686 - if( os_timer !== null && os_timer.id !== null ) {
 686+ if( os_timer != null && os_timer.id != null ) {
687687 clearTimeout( os_timer.id );
688688 }
689689 // schedule delayed fetching of results
690 - if( timeout !== 0 ) {
 690+ if( timeout != 0 ) {
691691 os_timer = new os_Timer( setTimeout( "os_delayedFetch()", timeout ), r, query );
692692 } else {
693693 os_timer = new os_Timer( null, r, query );
@@ -710,14 +710,14 @@
711711
712712 if( cur >= 0 ) {
713713 var curRow = document.getElementById( r.resultTable + cur );
714 - if( curRow !== null ) {
 714+ if( curRow != null ) {
715715 curRow.className = 'os-suggest-result';
716716 }
717717 }
718718 var newText;
719719 if( next >= 0 ) {
720720 var nextRow = document.getElementById( r.resultTable + next );
721 - if( nextRow !== null ) {
 721+ if( nextRow != null ) {
722722 nextRow.className = os_HighlightClass();
723723 }
724724 newText = r.results[next];
@@ -785,7 +785,7 @@
786786 function os_eventMouseover( srcId, e ) {
787787 var targ = os_getTarget( e );
788788 var r = os_map[srcId];
789 - if( r === null || !os_mouse_moved ) {
 789+ if( r == null || !os_mouse_moved ) {
790790 return; // not our event
791791 }
792792 var num = os_getNumberSuffix( targ.id );
@@ -816,7 +816,7 @@
817817 function os_eventMousedown( srcId, e ) {
818818 var targ = os_getTarget( e );
819819 var r = os_map[srcId];
820 - if( r === null ) {
 820+ if( r == null ) {
821821 return; // not our event
822822 }
823823 var num = os_getNumberSuffix( targ.id );
@@ -836,7 +836,7 @@
837837 function os_eventMouseup( srcId, e ) {
838838 var targ = os_getTarget( e );
839839 var r = os_map[srcId];
840 - if( r === null ) {
 840+ if( r == null ) {
841841 return; // not our event
842842 }
843843 var num = os_getNumberSuffix( targ.id );
@@ -883,7 +883,7 @@
884884 function os_toggle( inputId, formName ) {
885885 r = os_map[inputId];
886886 var msg = '';
887 - if( r === null ) {
 887+ if( r == null ) {
888888 os_enableSuggestionsOn( inputId, formName );
889889 r = os_map[inputId];
890890 msg = wgMWSuggestMessages[0];
@@ -904,7 +904,7 @@
905905 /** Call this to disable suggestios on input box (id=inputId) */
906906 function os_disableSuggestionsOn( inputId ) {
907907 r = os_map[inputId];
908 - if( r !== null ) {
 908+ if( r != null ) {
909909 // cancel/hide results
910910 os_timer = null;
911911 os_hideResults( r );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r61251cleanup to mwsuggest.js & fix some things suggested by JSLintashley15:29, 19 January 2010

Status & tagging log