r60107 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60106‎ | r60107 | r60108 >
Date:23:44, 15 December 2009
Author:tparscal
Status:ok
Tags:
Comment:
Added back in the stylize function.
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
@@ -77,14 +77,14 @@
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 10 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 52 ),
8080 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 8 ),
81 - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 5 ),
 81+ array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 6 ),
8282 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 1 ),
8383 ),
8484 'combined' => array(
85 - array( 'src' => 'js/plugins.combined.js', 'version' => 115 ),
 85+ array( 'src' => 'js/plugins.combined.js', 'version' => 116 ),
8686 ),
8787 'minified' => array(
88 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 115 ),
 88+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 116 ),
8989 ),
9090 ),
9191 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -61,6 +61,52 @@
6262 create: function( context, config ) {
6363 // Initialize module within the context
6464 },
 65+ stylize: function( context ) {
 66+ var $templates = context.$content.find( '.wiki-template' );
 67+ $templates.each( function(){
 68+ if ( typeof $( this ).data( 'model' ) != 'undefined' ) {
 69+ // We have a model, so all this init stuff has already happened
 70+ return;
 71+ }
 72+ // Hide this
 73+ $(this).addClass('wikieditor-nodisplay');
 74+ // Build a model for this
 75+ $( this ).data( 'model' , new model( $( this ).text() ) );
 76+ var model = $( this ).data( 'model' );
 77+ // Expand
 78+ function expandTemplate($displayDiv){
 79+ // Housekeeping
 80+ $displayDiv.removeClass( 'wiki-collapsed-template' );
 81+ $displayDiv.addClass( 'wiki-expanded-template' );
 82+ $displayDiv.data( 'mode' ) = "expanded";
 83+ $displayDiv.text( model.getText() );
 84+ };
 85+ // Collapse
 86+ function collapseTemplate($displayDiv){
 87+ // Housekeeping
 88+ $displayDiv.addClass( 'wiki-collapsed-template' );
 89+ $displayDiv.removeClass( 'wiki-expanded-template' );
 90+ $displayDiv.data( 'mode' ) = "collapsed";
 91+ $displayDiv.text( model.getName() );
 92+ };
 93+ // Build the collapsed version of this template
 94+ var $visibleDiv = $( "<div></div>" ).addClass( 'wikieditor-noinclude' );
 95+ // Let these two know about eachother
 96+ $(this).data( 'display' , $visibleDiv );
 97+ $visibleDiv.data( 'wikitext-node', $(this) );
 98+ $(this).after( $visibleDiv );
 99+ // Add click handler
 100+ $visibleDiv.click( function(){
 101+ // Is collapsed, switch to expand
 102+ if ( $(this).data('mode') == 'collapsed' ) {
 103+ expandTemplate( $(this) );
 104+ } else {
 105+ collapseTemplate( $(this) );
 106+ }
 107+ });
 108+ collapseTemplate( $visibleDiv );
 109+ });
 110+ },
65111 /**
66112 * Builds a template model from given wikitext representation, allowing object-oriented manipulation of the contents
67113 * of the template while preserving whitespace and formatting.
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -1700,7 +1700,7 @@
17011701
17021702 //get rid of the noincludes when getting text
17031703 var $dummyDiv = $( '<div />' ).html( context.$content.html().replace( /\<br\>/g, "\n" ) );
1704 - $dummyDiv.find( ".wiki-editor-noinclude" ).each( function() { $( this ).remove(); } );
 1704+ $dummyDiv.find( ".wikieditor-noinclude" ).each( function() { $( this ).remove(); } );
17051705 return $dummyDiv.text();
17061706
17071707 },
@@ -2708,6 +2708,52 @@
27092709 create: function( context, config ) {
27102710 // Initialize module within the context
27112711 },
 2712+ stylize: function( context ) {
 2713+ var $templates = context.$content.find( '.wiki-template' );
 2714+ $templates.each( function(){
 2715+ if ( typeof $( this ).data( 'model' ) != 'undefined' ) {
 2716+ // We have a model, so all this init stuff has already happened
 2717+ return;
 2718+ }
 2719+ // Hide this
 2720+ $(this).addClass('wikieditor-nodisplay');
 2721+ // Build a model for this
 2722+ $( this ).data( 'model' , new model( $( this ).text() ) );
 2723+ var model = $( this ).data( 'model' );
 2724+ // Expand
 2725+ function expandTemplate($displayDiv){
 2726+ // Housekeeping
 2727+ $displayDiv.removeClass( 'wiki-collapsed-template' );
 2728+ $displayDiv.addClass( 'wiki-expanded-template' );
 2729+ $displayDiv.data( 'mode' ) = "expanded";
 2730+ $displayDiv.text( model.getText() );
 2731+ };
 2732+ // Collapse
 2733+ function collapseTemplate($displayDiv){
 2734+ // Housekeeping
 2735+ $displayDiv.addClass( 'wiki-collapsed-template' );
 2736+ $displayDiv.removeClass( 'wiki-expanded-template' );
 2737+ $displayDiv.data( 'mode' ) = "collapsed";
 2738+ $displayDiv.text( model.getName() );
 2739+ };
 2740+ // Build the collapsed version of this template
 2741+ var $visibleDiv = $( "<div></div>" ).addClass( 'wikieditor-noinclude' );
 2742+ // Let these two know about eachother
 2743+ $(this).data( 'display' , $visibleDiv );
 2744+ $visibleDiv.data( 'wikitext-node', $(this) );
 2745+ $(this).after( $visibleDiv );
 2746+ // Add click handler
 2747+ $visibleDiv.click( function(){
 2748+ // Is collapsed, switch to expand
 2749+ if ( $(this).data('mode') == 'collapsed' ) {
 2750+ expandTemplate( $(this) );
 2751+ } else {
 2752+ collapseTemplate( $(this) );
 2753+ }
 2754+ });
 2755+ collapseTemplate( $visibleDiv );
 2756+ });
 2757+ },
27122758 /**
27132759 * Builds a template model from given wikitext representation, allowing object-oriented manipulation of the contents
27142760 * of the template while preserving whitespace and formatting.
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -100,7 +100,7 @@
101101 event.preventDefault();return false;}).text($.wikiEditor.autoMsg(options,'title'))).appendTo(context.$tabs);}
102102 if(!context.$tabs.children().size()){addTab({'name':'wikitext','titleMsg':'wikieditor-wikitext-tab'});}
103103 addTab(options);return $('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-'+options.name).hide().appendTo(context.$ui);},'getContents':function(){if($.browser.name=='msie'){return context.$content.text();}
104 -var $dummyDiv=$('<div />').html(context.$content.html().replace(/\<br\>/g,"\n"));$dummyDiv.find(".wiki-editor-noinclude").each(function(){$(this).remove();});return $dummyDiv.text();},'setContents':function(options){context.$content.text(options.contents);return context.$textarea;},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();}
 104+var $dummyDiv=$('<div />').html(context.$content.html().replace(/\<br\>/g,"\n"));$dummyDiv.find(".wikieditor-noinclude").each(function(){$(this).remove();});return $dummyDiv.text();},'setContents':function(options){context.$content.text(options.contents);return context.$textarea;},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();}
105105 if(retval.text){retval=retval.text;}else if(retval.toString){retval=retval.toString();}
106106 return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selectAfter=false;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';}
107107 var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);if(options.ownline){if(range.startOffset!=0){pre="\n"+options.pre;}
@@ -172,7 +172,8 @@
173173 $('#wikiEditor-'+context.instance+'-dialog-watch').attr('checked','checked');$(this).find('form').submit(function(e){$(this).closest('.ui-dialog').find('button:first').click();e.preventDefault();});},dialog:{buttons:{'wikieditor-publish-dialog-publish':function(){var minorChecked=$('#wikiEditor-'+context.instance+'-dialog-minor').is(':checked')?'checked':'';var watchChecked=$('#wikiEditor-'+context.instance+'-dialog-watch').is(':checked')?'checked':'';$('#wpMinoredit').attr('checked',minorChecked);$('#wpWatchthis').attr('checked',watchChecked);$('#wpSummary').val($j('#wikiEditor-'+context.instance+'-dialog-summary').val());$('#editform').submit();},'wikieditor-publish-dialog-goback':function(){$(this).dialog('close');}},open:function(){$('#wikiEditor-'+context.instance+'-dialog-summary').focus();},width:500},resizeme:false}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-publish','action':function(){$('#'+dialogID).dialog('open');return false;}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-cancel','action':function(){}});}}};})(jQuery);(function($){$.wikiEditor.modules.templateEditor={evt:{mark:function(context,event){var markers=context.modules.highlight.markers;var tokenArray=context.modules.highlight.tokenArray;var level=0;var boundries=[];var boundry=0;for(token in tokenArray){if(tokenArray[token].label=='TEMPLATE_BEGIN'){if(level++==0){boundry=boundries.push({'begin':tokenArray[token].offset})-1;}}else if(tokenArray[token].label=='TEMPLATE_END'){if(--level==0){boundries[boundry].end=tokenArray[token].offset;}}}
174174 for(boundry in boundries){if('begin'in boundries[boundry]&&'end'in boundries[boundry]){if(!(boundries[boundry].begin in markers)){markers[boundries[boundry].begin]=[];}
175175 if(!(boundries[boundry].end in markers)){markers[boundries[boundry].end]=[];}
176 -markers[boundries[boundry].begin].push("<div class='wiki-template'>");markers[boundries[boundry].end].push("</div>");}}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],fn:{create:function(context,config){},model:function(wikitext){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;}
 176+markers[boundries[boundry].begin].push("<div class='wiki-template'>");markers[boundries[boundry].end].push("</div>");}}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],fn:{create:function(context,config){},stylize:function(context){var $templates=context.$content.find('.wiki-template');$templates.each(function(){if(typeof $(this).data('model')!='undefined'){return;}
 177+$(this).addClass('wikieditor-nodisplay');$(this).data('model',new model($(this).text()));var model=$(this).data('model');function expandTemplate($displayDiv){$displayDiv.removeClass('wiki-collapsed-template');$displayDiv.addClass('wiki-expanded-template');$displayDiv.data('mode')="expanded";$displayDiv.text(model.getText());};function collapseTemplate($displayDiv){$displayDiv.addClass('wiki-collapsed-template');$displayDiv.removeClass('wiki-expanded-template');$displayDiv.data('mode')="collapsed";$displayDiv.text(model.getName());};var $visibleDiv=$("<div></div>").addClass('wikieditor-noinclude');$(this).data('display',$visibleDiv);$visibleDiv.data('wikitext-node',$(this));$(this).after($visibleDiv);$visibleDiv.click(function(){if($(this).data('mode')=='collapsed'){expandTemplate($(this));}else{collapseTemplate($(this));}});collapseTemplate($visibleDiv);});},model:function(wikitext){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;}
177178 function Range(begin,end){this.begin=begin;this.end=end;}
178179 function getSetValue(name,value,original){var valueRange;var rangeIndex;var retVal;if(isNaN(name)){if(typeof paramsByName[name]=='undefined'){return"";}
179180 rangeIndex=paramsByName[name];}else{rangeIndex=parseInt(name);}

Status & tagging log