r60104 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60103‎ | r60104 | r60105 >
Date:23:29, 15 December 2009
Author:nimishg
Status:resolved (Comments)
Tags:
Comment:
created (yet untested) 'stylize' function for some basic functionality to the templateEditor
Modified paths:
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -7,7 +7,7 @@
88 evt: {
99 mark: function( context, event ) {
1010 // This is shared by both the closure findOutermostTemplates and the calling code - is this a good idea?
11 - var i = 0;
 11+ var tokenIterator = 0;
1212 /**
1313 * Finds the left and right character positions of the outer-most template declaration, playing nicely with
1414 * nested template calls of any depth. This function acts as an iterator, which is why the i var is shared - but
@@ -17,13 +17,13 @@
1818 */
1919 function findOutermostTemplates( tokenStack ) {
2020 var templateBeginFound = false;
21 - for ( ; i < tokenStack.length; i++ ) {
22 - if ( tokenStack[i].label == 'TEMPLATE_BEGIN' ) {
 21+ for ( ; tokenIterator < tokenStack.length; tokenIterator++ ) {
 22+ if ( tokenStack[tokenIterator].label == 'TEMPLATE_BEGIN' ) {
2323 templateBeginFound = true;
2424 break;
2525 }
2626 }
27 - var j = i++;
 27+ var j = tokenIterator++;
2828 if ( !templateBeginFound ) {
2929 return false;
3030 } else {
@@ -36,9 +36,9 @@
3737 }
3838 if ( nestedBegins == 0 ) {
3939 // Outer template begins at tokenStack[i].offset and ends at tokenStack[j].offset + 2
40 - var leftMarker = i -1;
 40+ var leftMarker = tokenIterator -1;
4141 var rightMarker = j;
42 - i = j;
 42+ tokenIterator = j;
4343 return [leftMarker, rightMarker];
4444 } else {
4545 return false;
@@ -90,6 +90,69 @@
9191 model: function( wikitext ) {
9292
9393 /* Private Functions */
 94+ },
 95+
 96+
 97+ stylize: function( context ) {
 98+ var $templates = context.$content.find( ".wiki-template" );
 99+ $templates.each( function(){
 100+ if( typeof $( this ).data( 'model' ) != 'undefined' ){
 101+ //we have a model, so all this init stuff has already happened
 102+ return;
 103+ }
 104+
 105+ //hide this
 106+ $(this).addClass('wikieditor-nodisplay');
 107+
 108+ //build a model for this
 109+ $( this ).data( 'model' , new model( $( this ).text() ) );
 110+ var model = $( this ).data( 'model' );
 111+
 112+
 113+ //expand
 114+ function expandTemplate($displayDiv){
 115+ //housekeeping
 116+ $displayDiv.removeClass('wiki-collapsed-template');
 117+ $displayDiv.addClass('wiki-expanded-template');
 118+ $displayDiv.data('mode') = "expanded";
 119+
 120+ $displayDiv.text( model.getText() );
 121+
 122+ };
 123+
 124+ //collapse
 125+ function collapseTemplate($displayDiv){
 126+ //housekeeping
 127+ $displayDiv.addClass('wiki-collapsed-template');
 128+ $displayDiv.removeClass('wiki-expanded-template');
 129+ $displayDiv.data('mode') = "collapsed";
 130+
 131+ $displayDiv.text( model.getName() );
 132+
 133+ };
 134+
 135+ //build the collapsed version of this template
 136+ var $visibleDiv = $( "<div></div>" ).addClass( 'wikieditor-noinclude' );
 137+
 138+ //let these two know about eachother
 139+ $(this).data( 'display' , $visibleDiv );
 140+ $visibleDiv.data('wikitext-node', $(this));
 141+ $(this).after( $visibleDiv );
 142+
 143+ //onClick
 144+ $visibleDiv.click( function(){
 145+ //is collapsed, switch to expand
 146+ if( $(this).data('mode') == 'collapsed' ){
 147+ expandTemplate( $(this) );
 148+ }
 149+ else{
 150+ collapseTemplate( $(this) );
 151+ }
 152+ });//click
 153+
 154+ collapseTemplate($visibleDiv);
 155+ });
 156+ },
94157
95158 /**
96159 * Builds a Param object.

Comments

#Comment by Catrope (talk | contribs)   23:42, 15 December 2009
+		var $templates = context.$content.find( ".wiki-template" );

Should be .wikiEditor-highlight-template per my latest commit.

+				$displayDiv.data('mode') = "expanded";

This doesn't work, use $blah.data( 'foo', 'bar' );

Also, this commit doesn't follow our coding style past the first 5 lines or so.

The wikieditor-nodisplay class should probably have a display: none; rule in wikiEditor.highlight.css

#Comment by Catrope (talk | contribs)   17:41, 27 January 2010

All of these issues were resolved in later commits.

Status & tagging log