r63476 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63475‎ | r63476 | r63477 >
Date:17:34, 9 March 2010
Author:adam
Status:ok (Comments)
Tags:
Comment:
Template Editor: removing multiple line breaks from dialog on update, and two improvements to the auto expanding textareas on the dialogs
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -78,14 +78,14 @@
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 19 ),
8080 array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 97 ),
8181 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 11 ),
82 - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 41 ),
 82+ array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 42 ),
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 3 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 310 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 311 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 310 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 311 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -211,7 +211,7 @@
212212 var $templateText = $templateDiv.children( '.wikiEditor-template-text' );
213213 var templateModel = $templateText.data( 'model' );
214214 $( this ).find( '.wikiEditor-template-dialog-field-wrapper textarea' ).each( function() {
215 - templateModel.setValue( $( this ).data( 'name' ), $( this ).val() );
 215+ templateModel.setValue( $( this ).data( 'name' ), $( this ).val().replace( /\n+/g, '/n' ) );
216216 });
217217 //keep text consistent
218218 $.wikiEditor.modules.templateEditor.fn.updateModel( $templateText, templateModel );
@@ -264,11 +264,13 @@
265265 .data( 'name', param.name )
266266 .val( paramVal )
267267 .data( 'expanded', false )
268 - .bind( 'cut paste keypress click change', function() {
269 - var $this = $(this);
 268+ .bind( 'cut paste keypress click change', function( e ) {
 269+ // If this was fired by a tab keypress, let it go
 270+ if ( e.keyCode == '9' ) return true;
 271+ var $this = $( this );
270272 setTimeout( function() {
271273 var expanded = $this.data( 'expanded' );
272 - if ( $this.val().length > 24 ) {
 274+ if ( $this.val().match( /\n/ ) || $this.val().length > 24 ) {
273275 if ( !expanded ) {
274276 $this.animate( { 'height': '4.5em' }, 'fast' );
275277 $this.data( 'expanded', true );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -9325,7 +9325,7 @@
93269326 var $templateText = $templateDiv.children( '.wikiEditor-template-text' );
93279327 var templateModel = $templateText.data( 'model' );
93289328 $( this ).find( '.wikiEditor-template-dialog-field-wrapper textarea' ).each( function() {
9329 - templateModel.setValue( $( this ).data( 'name' ), $( this ).val() );
 9329+ templateModel.setValue( $( this ).data( 'name' ), $( this ).val().replace( /\n+/g, '/n' ) );
93309330 });
93319331 //keep text consistent
93329332 $.wikiEditor.modules.templateEditor.fn.updateModel( $templateText, templateModel );
@@ -9378,11 +9378,13 @@
93799379 .data( 'name', param.name )
93809380 .val( paramVal )
93819381 .data( 'expanded', false )
9382 - .bind( 'cut paste keypress click change', function() {
9383 - var $this = $(this);
 9382+ .bind( 'cut paste keypress click change', function( e ) {
 9383+ // If this was fired by a tab keypress, let it go
 9384+ if ( e.keyCode == '9' ) return true;
 9385+ var $this = $( this );
93849386 setTimeout( function() {
93859387 var expanded = $this.data( 'expanded' );
9386 - if ( $this.val().length > 24 ) {
 9388+ if ( $this.val().match( /\n/ ) || $this.val().length > 24 ) {
93879389 if ( !expanded ) {
93889390 $this.animate( { 'height': '4.5em' }, 'fast' );
93899391 $this.data( 'expanded', true );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -645,9 +645,9 @@
646646 <fieldset>\
647647 <div class="wikiEditor-template-dialog-title" />\
648648 <div class="wikiEditor-template-dialog-fields" />\
649 - </fieldset>',init:function(){$(this).find('[rel]').each(function(){$(this).text(mw.usability.getMsg($(this).attr('rel')));});},dialog:{width:600,height:400,dialogClass:'wikiEditor-toolbar-dialog',buttons:{'wikieditor-template-editor-dialog-submit':function(){var $templateDiv=$(this).data('templateDiv');context.fn.highlightLine($templateDiv);var $templateText=$templateDiv.children('.wikiEditor-template-text');var templateModel=$templateText.data('model');$(this).find('.wikiEditor-template-dialog-field-wrapper textarea').each(function(){templateModel.setValue($(this).data('name'),$(this).val());});$.wikiEditor.modules.templateEditor.fn.updateModel($templateText,templateModel);$(this).dialog('close');}},open:function(){var $templateDiv=$(this).data('templateDiv');var $templateText=$templateDiv.children('.wikiEditor-template-text');var templateModel=$templateText.data('model');if($templateText.html()!=$templateText.data('oldHTML')){templateModel=$.wikiEditor.modules.templateEditor.fn.updateModel($templateText);}
 649+ </fieldset>',init:function(){$(this).find('[rel]').each(function(){$(this).text(mw.usability.getMsg($(this).attr('rel')));});},dialog:{width:600,height:400,dialogClass:'wikiEditor-toolbar-dialog',buttons:{'wikieditor-template-editor-dialog-submit':function(){var $templateDiv=$(this).data('templateDiv');context.fn.highlightLine($templateDiv);var $templateText=$templateDiv.children('.wikiEditor-template-text');var templateModel=$templateText.data('model');$(this).find('.wikiEditor-template-dialog-field-wrapper textarea').each(function(){templateModel.setValue($(this).data('name'),$(this).val().replace(/\n+/g,'/n'));});$.wikiEditor.modules.templateEditor.fn.updateModel($templateText,templateModel);$(this).dialog('close');}},open:function(){var $templateDiv=$(this).data('templateDiv');var $templateText=$templateDiv.children('.wikiEditor-template-text');var templateModel=$templateText.data('model');if($templateText.html()!=$templateText.data('oldHTML')){templateModel=$.wikiEditor.modules.templateEditor.fn.updateModel($templateText);}
650650 var params=templateModel.getAllInitialParams();var $fields=$(this).find('.wikiEditor-template-dialog-fields');var $rows=$fields.find('.wikiEditor-template-dialog-field-wrapper');for(var paramIndex in params){var param=params[paramIndex];if(typeof param.name=='undefined'){continue;}
651 -var paramText=typeof param=='string'?param.name.replace(/[\_\-]/g,' '):param.name;var paramVal=templateModel.getValue(param.name);if($rows.length>0){var $row=$rows.eq(0);$row.children('label').text(paramText);$row.children('textarea').data('name',param.name).val(paramVal).change();$rows=$rows.not($row);}else{var $paramRow=$('<div />').addClass('wikiEditor-template-dialog-field-wrapper');$('<label />').text(paramText).appendTo($paramRow);$('<textarea />').data('name',param.name).val(paramVal).data('expanded',false).bind('cut paste keypress click change',function(){var $this=$(this);setTimeout(function(){var expanded=$this.data('expanded');if($this.val().length>24){if(!expanded){$this.animate({'height':'4.5em'},'fast');$this.data('expanded',true);}}else{if(expanded){$this.animate({'height':'1.5em'},'fast');$this.data('expanded',false);}}},0);}).appendTo($paramRow);$paramRow.append('<div style="clear:both"></div>').appendTo($fields);}}
 651+var paramText=typeof param=='string'?param.name.replace(/[\_\-]/g,' '):param.name;var paramVal=templateModel.getValue(param.name);if($rows.length>0){var $row=$rows.eq(0);$row.children('label').text(paramText);$row.children('textarea').data('name',param.name).val(paramVal).change();$rows=$rows.not($row);}else{var $paramRow=$('<div />').addClass('wikiEditor-template-dialog-field-wrapper');$('<label />').text(paramText).appendTo($paramRow);$('<textarea />').data('name',param.name).val(paramVal).data('expanded',false).bind('cut paste keypress click change',function(e){if(e.keyCode=='9')return true;var $this=$(this);setTimeout(function(){var expanded=$this.data('expanded');if($this.val().match(/\n/)||$this.val().length>24){if(!expanded){$this.animate({'height':'4.5em'},'fast');$this.data('expanded',true);}}else{if(expanded){$this.animate({'height':'1.5em'},'fast');$this.data('expanded',false);}}},0);}).appendTo($paramRow);$paramRow.append('<div style="clear:both"></div>').appendTo($fields);}}
652652 $rows.remove();$fields.find('label').autoEllipsis();$(this).parent('.ui-dialog').find('.ui-dialog-titlebar-close').removeClass('ui-state-focus');}}};function createDialog($templateDiv){context.$textarea.wikiEditor('addDialog',{'templateEditor':dialog});$('#'+dialog.id).data('templateDiv',$templateDiv).dialog('open');}},unwrapTemplate:function($wrapper){$wrapper.parent().replaceWith($wrapper);},updateModel:function($templateText,model){var context=$templateText.data('marker').context;var text;if(typeof model=='undefined'){text=context.fn.htmlToText($templateText.html());}else{text=model.getText();}
653653 $templateText.text(text);$templateText.html($templateText.html().replace(/\n/g,'<br />'));$templateText.data('oldHTML',$templateText.html());if(typeof model=='undefined'){model=new $.wikiEditor.modules.templateEditor.fn.model(text);$templateText.data('model',model);}
654654 return model;},getTemplateInfo:function(templateName){var templateInfo='';return $(templateInfo);},model:function(wikitext){var collapsible=true;function Param(name,value,number,nameIndex,equalsIndex,valueIndex){this.name=name;this.value=value;this.number=number;this.nameIndex=nameIndex;this.equalsIndex=equalsIndex;this.valueIndex=valueIndex;}

Follow-up revisions

RevisionCommit summaryAuthorDate
r63519Follow up to r63476 to impliment Roan's suggestions.adam22:18, 9 March 2010

Comments

#Comment by Catrope (talk | contribs)   20:51, 9 March 2010
+							templateModel.setValue( $( this ).data( 'name' ), $( this ).val().replace( /\n+/g, '/n' ) );

A comment explaining why we're collapsing sequences of newlines into one newline would be appropriate.

+										if ( $this.val().match( /\n/ ) || $this.val().length > 24 ) {

I suggest you just use .indexOf( '\n' ) != -1 to check for the presence of a single character, a regex is probably overkill for that purpose.

Status & tagging log