r82900 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82899‎ | r82900 | r82901 >
Date:17:14, 27 February 2011
Author:janpaul123
Status:resolved (Comments)
Tags:
Comment:
Fixes bug when having multiple textareas, which is caused by the fact that dialogs are kept in memory for performance, even when selecting a different textarea.
Modified paths:
  • /trunk/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js
@@ -84,7 +84,12 @@
8585 }
8686 }
8787 }
88 - if ( !filtered && $.wikiEditor.isSupported( module ) && $( '#' + module.id ).size() == 0 ) {
 88+ // If the dialog already exists, but for another textarea, simply remove it
 89+ var $existingDialog = $( '#' + module.id );
 90+ if ( $existingDialog.size() > 0 && $existingDialog.data( 'context' ).$textarea != context.$textarea ) {
 91+ $existingDialog.remove();
 92+ }
 93+ if ( !filtered && $.wikiEditor.isSupported( module ) && $existingDialog.size() == 0 ) {
8994 $.wikiEditor.modules.dialogs.modules[mod] = module;
9095 // If this dialog requires the iframe, set it up
9196 if ( typeof context.$iframe == 'undefined' && $.wikiEditor.isRequired( module, 'iframe' ) ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r95079Followup r82900: per CR, use .length instead of size(), strict comparison wit...catrope12:47, 20 August 2011

Comments

#Comment by Krinkle (talk | contribs)   18:20, 11 August 2011

Please use .length instead of .size(). Less function call overhead, same number of characters. A strict comparison to 0 is preferred (general good practice, also a bit faster).

The remove() call followed by .size() on the next line is a bit confusing, take the following:

$("<div>").remove().length
// Returns 1

I assume you'd wanna re-select the ID from the dom ?

Status & tagging log