r61834 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61833‎ | r61834 | r61835 >
Date:00:17, 2 February 2010
Author:nimishg
Status:deferred
Tags:
Comment:
changed functionality of templateEditor to be more in line with newer mocks
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
@@ -94,43 +94,53 @@
9595 return;
9696 }
9797 // Build a model for this
 98+ var model = new $.wikiEditor.modules.templateEditor.fn.model( $( this ).text() );
9899
99 - var model = new $.wikiEditor.modules.templateEditor.fn.model( $( this ).text() );
 100+ //check if model is collapsible
100101 if ( !model.isCollapsible() ) {
101102 return;
102103 }
 104+
103105 var $template = $( this )
104106 .wrap( '<div class="wikiEditor-template"></div>' )
105107 .addClass( 'wikiEditor-template-text wikiEditor-nodisplay' )
106 - .html(
107 - // Wrap the start and end of the wikitext in spans so we can bind events to them
108 - $( this ).html()
109 - .replace( /\{\{/, '<span class="wikiEditor-template-start">{{</span><span class="wikiEditor-template-inner-text">' )
110 - .replace( /\}\}$/, '</span><span class="wikiEditor-template-end">}}</span>' ) ) //grab the *last* {{
111 - .css( 'visibility', 'hidden' )
112108 .parent()
113109 .addClass( 'wikiEditor-template-collapsed' )
114110 .data( 'model', model );
 111+
115112 $( '<span />' )
116 - .addClass( 'wikiEditor-template-name wikiEditor-noinclude' )
117 - .text( model.getName() )
118 - .mousedown( noEdit )
119 - .prependTo( $template );
120 - $template.find( '.wikiEditor-template-end, .wikiEditor-template-start' ).mousedown( toggleWikiText );
 113+ .addClass( 'wikiEditor-template-name wikiEditor-noinclude' )
 114+ .text( model.getName() )
 115+ .mousedown( function(){createDialog( $template );} ) //have to pass template so model stays in sync
 116+ .prependTo( $template );
 117+
 118+
121119 var $options = $( '<ul />' )
122 - .addClass( 'wikiEditor-template-modes wikiEditor-noinclude' )
123 - .append( $( '<li />' )
124 - .addClass( 'wikiEditor-template-action-wikiText' )
125 - .append( $( '<img />' ).attr( 'src',
126 - $.wikiEditor.imgPath + 'templateEditor/' + 'wiki-text.png' ) )
127 - .mousedown( toggleWikiText ) )
128 - .insertAfter( $template.find( '.wikiEditor-template-name' ) );
129 - $options.append(
130 - $( '<li />' )
131 - .addClass( 'wikiEditor-template-action-form' )
132 - .append( $( '<span>F</span>' ) )
133 - .mousedown( function(){createDialog($template); return false;} ));
 120+ .addClass( 'wikiEditor-template-modes wikiEditor-noinclude' )
 121+ .append( $( '<li />' )
 122+ .addClass( 'wikiEditor-template-action-wikiText' )
 123+ .append( $( '<img />' ).attr( 'src',
 124+ $.wikiEditor.imgPath + 'templateEditor/' + 'wiki-text.png' ) )
 125+ .mousedown( toggleWikiTextEditor ) )
 126+ .insertAfter( $template.find( '.wikiEditor-template-name' ) );
134127
 128+ function toggleWikiTextEditor(){
 129+ var $template = $( this ).closest( '.wikiEditor-template' );
 130+ $template
 131+ .toggleClass( 'wikiEditor-template-expanded' )
 132+ .toggleClass( 'wikiEditor-template-collapsed' );
 133+ var $wikitext = $template.children('.wikiEditor-template-text');
 134+ $wikitext.toggleClass('wikiEditor-nodisplay');
 135+
 136+ //if we just collapsed this
 137+ if( $template.hasClass('wikiEditor-template-collapsed') ) {
 138+ var model = new $.wikiEditor.modules.templateEditor.fn.model( $template.children( '.wikiEditor-template-text' ).text() );
 139+ $template.data( 'model' , model );
 140+ $template.children( '.wikiEditor-template-name' ).text( model.getName() );
 141+ }
 142+
 143+ return false;
 144+ };
135145
136146 // Expand
137147 function expandTemplate( $displayDiv ) {
@@ -171,6 +181,7 @@
172182
173183 function createDialog( $templateDiv ){
174184 var templateModel = $templateDiv.data('model');
 185+ console.log(templateModel.getText());
175186 var $dialog = $("<div></div>");
176187 var $title = $("<div>" + templateModel.getName() + "</div>").addClass('wikiEditor-template-dialog-title');
177188 var $table = $("<table></table>")
@@ -203,9 +214,12 @@
204215
205216 }).text("OK").appendTo($dialog);
206217 $dialog.dialog(); //opens dialog
 218+ return false;
207219 };
208220
209221
 222+
 223+
210224 function toggleWikiText( ) {
211225 var $template = $( this ).closest( '.wikiEditor-template' );
212226 $template
@@ -231,9 +245,11 @@
232246 }
233247 return false;
234248 }
235 - function noEdit() {
236 - return false;
237 - }
 249+
 250+ function noEdit() {
 251+ return false;
 252+ }
 253+
238254 });
239255
240256 },
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html
@@ -39,7 +39,7 @@
4040 padding-left: 4em;
4141 }
4242 /* A collapsed template */
43 - .wikiEditor-template-collapsed {
 43+ .wikiEditor-template-name {
4444 background-color:#DDEEFF;
4545 border:1px outset #DDEEFF;
4646 color:#333333;
@@ -73,7 +73,7 @@
7474 display: inline;
7575 }
7676 .wikiEditor-template-text{
77 - display: inline;
 77+ border: solid 1px blue;
7878 }
7979 .wikiEditor-template-end, .wikiEditor-template-start{
8080 color: blue;

Status & tagging log