r61094 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61093‎ | r61094 | r61095 >
Date:18:15, 15 January 2010
Author:nimishg
Status:deferred (Comments)
Tags:
Comment:
template editor--with a basic 'form'
Modified paths:
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -89,6 +89,7 @@
9090 return;
9191 }
9292 // Build a model for this
 93+
9394 var model = new $.wikiEditor.modules.templateEditor.fn.model( $( this ).text() );
9495 var $template = $( this )
9596 .wrap( '<div class="wikiEditor-template"></div>' )
@@ -96,8 +97,8 @@
9798 .html(
9899 // Wrap the start and end of the wikitext in spans so we can bind events to them
99100 $( this ).html()
100 - .replace( /\{\{/, '<span class="wikiEditor-template-start">{{</span>' )
101 - .replace( /\}\}$/, '<span class="wikiEditor-template-end">}}</span>' ) ) //grab the *last* {{
 101+ .replace( /\{\{/, '<span class="wikiEditor-template-start">{{</span><span class="wikiEditor-template-inner-text">' )
 102+ .replace( /\}\}$/, '</span><span class="wikiEditor-template-end">}}</span>' ) ) //grab the *last* {{
102103 .parent()
103104 .addClass( 'wikiEditor-template-collapsed' )
104105 .data( 'model', model );
@@ -107,7 +108,7 @@
108109 .mousedown( noEdit )
109110 .prependTo( $template );
110111 $template.find( '.wikiEditor-template-end, .wikiEditor-template-start' ).mousedown( toggleWikiText );
111 - $( '<ul />' )
 112+ var $options = $( '<ul />' )
112113 .addClass( 'wikiEditor-template-modes wikiEditor-noinclude' )
113114 .append( $( '<li />' )
114115 .addClass( 'wikiEditor-template-action-wikiText' )
@@ -115,6 +116,14 @@
116117 $.wikiEditor.imgPath + 'templateEditor/' + 'wiki-text.png' ) )
117118 .mousedown( toggleWikiText ) )
118119 .insertAfter( $template.find( '.wikiEditor-template-name' ) );
 120+ $options.append(
 121+ $( '<li />' )
 122+ .addClass( 'wikiEditor-template-action-form' )
 123+ .append( $( '<span>F</span>' ) )
 124+ .mousedown( function(){createDialog($template); return false;} ));
 125+
 126+
 127+
119128 // Expand
120129 function expandTemplate( $displayDiv ) {
121130 // Housekeeping
@@ -150,6 +159,45 @@
151160 $displayDiv.removeClass( 'wikiEditor-template-expanded' );
152161 $displayDiv.text( model.getName() );
153162 };
 163+
 164+
 165+ function createDialog( $templateDiv ){
 166+ var templateModel = $templateDiv.data('model');
 167+ var $dialog = $("<div></div>");
 168+ var $title = $("<div>" + templateModel.getName() + "</div>").addClass('wikiEditor-template-dialog-title');
 169+ var $table = $("<table></table>")
 170+ .addClass('wikiEditor-template-dialog-table')
 171+ .appendTo($dialog);
 172+ var allInitialParams = templateModel.getAllInitialParams();
 173+ for( var paramIndex in allInitialParams ){
 174+ var param = allInitialParams[paramIndex];
 175+ if(typeof param.name == 'undefined'){continue;} //param 0 is the name
 176+ var $paramRow = $("<tr></tr>")
 177+ .addClass('wikiEditor-template-dialog-row');
 178+ var $paramName = $("<td></td>")
 179+ .addClass('wikiEditor-template-dialog-name')
 180+ .text( param.name );
 181+ var $paramVal = $("<td></td>")
 182+ .addClass('wikiEditor-template-dialog-value');
 183+ var $paramInput =$("<input></input>")
 184+ .data('name', param.name)
 185+ .val( templateModel.getValue(param.name) );
 186+ $paramVal.append($paramInput);
 187+ $paramRow.append($paramName).append($paramVal);
 188+ $table.append($paramRow);
 189+ }
 190+ //click handler for values
 191+ $("<button></button>").click(function(){
 192+ $('.wikiEditor-template-dialog-value input').each( function(){
 193+ templateModel.setValue( $(this).data('name'), $(this).val() );
 194+ });
 195+ $dialog.dialog('close');
 196+
 197+ }).text("OK").appendTo($dialog);
 198+ $dialog.dialog(); //opens dialog
 199+ };
 200+
 201+
154202 function toggleWikiText( ) {
155203 var $template = $( this ).closest( '.wikiEditor-template' );
156204 $template
@@ -159,11 +207,20 @@
160208 .toggleClass( 'wikiEditor-nodisplay' );
161209
162210 //if we just collapsed this
163 - if( $template.hasClass('wikiEditor-template-collapsed') ){
 211+ if( $template.hasClass('wikiEditor-template-collapsed') ) {
164212 var model = new $.wikiEditor.modules.templateEditor.fn.model( $template.children( '.wikiEditor-template-text' ).text() );
165213 $template.data( 'model' , model );
166214 $template.children( '.wikiEditor-template-name' ).text( model.getName() );
167215 }
 216+ else{ //else we just expanded this
 217+ $template.children( '.wikiEditor-template-text' ).children('.wikiEditor-template-inner-text').text(
 218+ $template.data('model')
 219+ .getText()
 220+ .replace(/\{\{/, '')
 221+ .replace(/\}\}$/, '')
 222+ );
 223+
 224+ }
168225 return false;
169226 }
170227 function noEdit() {
@@ -377,7 +434,7 @@
378435 startIndex = sanatizedStr.indexOf( '{{' ) + 1;
379436 openBraces = 2;
380437 endIndex = startIndex;
381 - while ( openBraces > 0 ) {
 438+ while ( (openBraces > 0) && (endIndex < sanatizedStr.length) ) {
382439 var brace = sanatizedStr[++endIndex];
383440 openBraces += brace == '}' ? -1 : brace == '{' ? 1 : 0;
384441 }
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html
@@ -12,6 +12,7 @@
1313 font-family: monospace;
1414 white-space: pre-wrap;
1515 font-size: 9.5pt;
 16+ line-height:16px;
1617 }
1718 /* Wikitext that's folded away and shouldn't be displayed */
1819 .wikiEditor-nodisplay {

Comments

#Comment by Catrope (talk | contribs)   18:52, 15 January 2010

Needs style version bump and recombine

Status & tagging log