http://www.mediawiki.org/wiki/Special:Code/MediaWiki/80731
Revision: 80731 Author: janpaul123 Date: 2011-01-21 23:48:35 +0000 (Fri, 21 Jan 2011) Log Message: ----------- Followup to r80717: fixed some browser bugs, added some nice collapsing functionality to the algorithm, cleaned some stuff up. Modified Paths: -------------- trunk/extensions/InlineEditor/InlineEditor.class.php trunk/extensions/InlineEditor/InlineEditorMarking.class.php trunk/extensions/InlineEditor/InlineEditorText.class.php trunk/extensions/InlineEditor/jquery.inlineEditor.basicEditor.js trunk/extensions/InlineEditor/jquery.inlineEditor.js Modified: trunk/extensions/InlineEditor/InlineEditor.class.php =================================================================== --- trunk/extensions/InlineEditor/InlineEditor.class.php 2011-01-21 23:35:58 UTC (rev 80730) +++ trunk/extensions/InlineEditor/InlineEditor.class.php 2011-01-21 23:48:35 UTC (rev 80731) @@ -371,6 +371,7 @@ * @return bool */ public static function partialRenderCite( $markedWiki ) { - return ( preg_match( '/<ref[^\/]*?>.*?<\/ref>|<ref.*?\/>/is', $markedWiki) <= 0) ; + return true; + /*return ( preg_match( '/<ref[^\/]*?>.*?<\/ref>|<ref.*?\/>/is', $markedWiki) <= 0) ;*/ } } Modified: trunk/extensions/InlineEditor/InlineEditorMarking.class.php =================================================================== --- trunk/extensions/InlineEditor/InlineEditorMarking.class.php 2011-01-21 23:35:58 UTC (rev 80730) +++ trunk/extensions/InlineEditor/InlineEditorMarking.class.php 2011-01-21 23:48:35 UTC (rev 80731) @@ -9,34 +9,38 @@ const autoClasses = 'block inline bar nobar'; // automatically added classes which shouldn't be added by hand protected static $lastId = 0; /// < counter which is used to generate unique ids - protected $start; /// < start position of the marking in the wikitext - protected $end; /// < end position of the marking in the wikitext - protected $classes; /// < class(es) attached to the marking which identifies the type - protected $block; /// < whether the tag should be added as a block or inline - protected $bar; /// < whether the text should carry a bar at the left, or be fully selectable - protected $id; /// < id in the original text; this will be unique even when calculating new ids! - protected $matched; /// < bool whether or not this marking has been matched with a previous marking (default: true) - protected $level; /// < nesting level, which is used to sort consistently when two markings are of same length + protected $start; /// < start position of the marking in the wikitext + protected $end; /// < end position of the marking in the wikitext + protected $classes; /// < class(es) attached to the marking which identifies the type + protected $block; /// < whether the tag should be added as a block or inline + protected $bar; /// < whether the text should carry a bar at the left, or be fully selectable + protected $level; /// < nesting level, which is used to sort consistently when two markings are of same length + protected $collapsible; /// < whether or not the marking can be collapsed when only containing one nested element + protected $id; /// < id in the original text; this will be unique even when calculating new ids! + protected $matched; /// < bool whether or not this marking has been matched with a previous marking (default: true) + /** - * @param $start int Start of the marking, offset in number of characters from the begin of the wikitext - * @param $end int End of the marking, offset in number of characters from the begin of the wikitext - * @param $classes mixed Class(es) the marking should be labeled with, can be either a string or an array of strings - * @param $block bool Whether the tag should be added as a block or inline - * @param $bar bool Whether the text should carry a bar at the left, or be fully selectable - * @param $level int Nesting level, which is used to sort consistently when two markings are of same length, default: 0 + * @param $start int Start of the marking, offset in number of characters from the begin of the wikitext + * @param $end int End of the marking, offset in number of characters from the begin of the wikitext + * @param $classes mixed Class(es) the marking should be labeled with, can be either a string or an array of strings + * @param $block bool Whether the tag should be added as a block or inline + * @param $bar bool Whether the text should carry a bar at the left, or be fully selectable + * @param $level int Nesting level, which is used to sort consistently when two markings are of same length, default: 0 + * @param $collapsible bool Whether or not the marking can be collapsed when only containing one nested element, default: true */ - function __construct( $start, $end, $classes, $block, $bar, $level = 0 ) { - $this->start = $start; - $this->end = $end; - $this->block = $block; - $this->bar = $bar; - $this->level = $level; + function __construct( $start, $end, $classes, $block, $bar, $level = 0, $collapsible = true ) { + $this->start = $start; + $this->end = $end; + $this->block = $block; + $this->bar = $bar; + $this->level = $level; + $this->collapsible = $collapsible; - $this->matched = true; - $this->id = self::uniqueId(); + $this->matched = true; + $this->id = self::uniqueId(); - $this->classes = array(); + $this->classes = array(); $this->addClasses( $classes ); } @@ -184,11 +188,11 @@ } /** - * Set the nesting level, which is used to sort consistently when two markings are of same length. + * Get whether or not the marking can be collapsed when only containing one nested element. * @param $value int */ - public function setLevel( $value ) { - $this->level = $value; + public function getCollapsible() { + return $this->collapsible; } /** Modified: trunk/extensions/InlineEditor/InlineEditorText.class.php =================================================================== --- trunk/extensions/InlineEditor/InlineEditorText.class.php 2011-01-21 23:35:58 UTC (rev 80730) +++ trunk/extensions/InlineEditor/InlineEditorText.class.php 2011-01-21 23:48:35 UTC (rev 80731) @@ -178,6 +178,9 @@ // sort the markings while preserving the keys (ids) uasort( $this->markings, 'InlineEditorText::sortByStartAndLength' ); + // collapse markings + $this->collapseMarkings(); + // match up previous markings $this->matchPreviousMarkings(); } @@ -217,6 +220,21 @@ } /** + * Finds markings of exact same positions, and uses only the deepest markings. + */ + protected function collapseMarkings() { + foreach( $this->markings as $id => $marking ) { + if( isset( $previous ) ) { + if( $previous->getCollapsible() && $marking->samePositionAs( $previous ) ) { + unset( $this->markings[$previousID] ); + } + } + $previous = $marking; + $previousID = $id; + } + } + + /** * Previous markings are moved into the current markings list to be able to only * render a part of the page which is much faster. * @@ -249,29 +267,23 @@ while( isset( $this->previous[$indexPrevious] ) ) { $previous = $this->previous[$indexPrevious]; - if( $previous->getStart() < $marking->getStart() ) { - $indexPrevious++; + switch( self::sortByStartAndLength( $previous, $marking ) ) { + case 1: + // if we've moved past the current marking, break, mismatch, and go to the next current marking + break(2); + case -1: + // if we haven't moved past the current marking but also haven't found it, continue the search + $indexPrevious++; + break; + default: + // a previous marking has been matched with a current marking + // the previous marking will replace the current one + $previous->setMatched( true ); + $newMarkings[$previous->getId()] = $previous; + $foundMatch = true; + $indexPrevious++; + break(2); } - elseif( $previous->getStart() == $marking->getStart() && $previous->getLength() > $marking->getLength() ) { - $indexPrevious++; - } - elseif( $previous->samePositionAs( $marking ) && strcmp( $previous->getClass(), $marking->getClass() ) < 0 ) { - $indexPrevious++; - } - elseif( $marking->equals( $previous, array( 'edited', 'lastEdit') ) ) - { - // a previous marking has been matched with a current marking - // the previous marking will replace the current one - $previous->setMatched( true ); - $newMarkings[$previous->getId()] = $previous; - $foundMatch = true; - $indexPrevious++; - break; - } - else { - // if we've moved past the current marking, break, mismatch, and go to the next current marking - break; - } } if( !$foundMatch ) { @@ -373,7 +385,6 @@ * - start position (asc) * - length (desc) * - level (desc) - * - class name (asc) * @param $a InlineEditorMarking * @param $b InlineEditorMarking * @return int @@ -382,7 +393,7 @@ if( $a->getStart() == $b->getStart() ) { if( $a->getLength() == $b->getLength() ) { if( $a->getLevel() == $b->getLevel() ) { - return strcmp( $a->getClass(), $b->getClass() ); + return $a->equals( $b, array( 'edited', 'lastEdit' ) ) ? 0 : 1; } else { return ( $a->getLevel() > $b->getLevel() ? -1 : 1 ); Modified: trunk/extensions/InlineEditor/jquery.inlineEditor.basicEditor.js =================================================================== --- trunk/extensions/InlineEditor/jquery.inlineEditor.basicEditor.js 2011-01-21 23:35:58 UTC (rev 80730) +++ trunk/extensions/InlineEditor/jquery.inlineEditor.basicEditor.js 2011-01-21 23:48:35 UTC (rev 80731) @@ -2,178 +2,182 @@ * Provides a basic editor with preview and cancel functionality. */ ( function( $ ) { $.inlineEditor.basicEditor = { - -/** - * Creates a new hovering edit field. - */ -newField: function( $field, originalClickEvent ) { - // create a new field - var $newField = $( '<' + $field.get(0).nodeName + '/>' ); - $newField.addClass( 'editing' ); - // position the field floating on the page, at the same position the original field - $newField.css( 'top', $field.position().top ); + /** + * Creates a new hovering edit field. + */ + newField: function( $field, originalClickEvent ) { + // create a new field + var $newField = $( '<' + $field.get(0).nodeName + '/>' ); + $newField.addClass( 'editing' ); + + // position the field floating on the page, at the same position the original field + $newField.css( 'top', $field.position().top ); + + // point to the original field using jQuery data + $newField.data( 'orig', $field ); + + // make sure click and mousemove events aren't passed on + $newField.click( function( event ) { event.stopPropagation(); } ); + $newField.mousemove( function( event ) { event.stopPropagation(); } ); + + // add the field after the current field in code + $field.after( $newField ); + return $newField; + }, - // point to the original field using jQuery data - $newField.data( 'orig', $field ); + /** + * Adds an edit bar to the field with preview and cancel functionality. + */ + addEditBar: function( $newSpan, wiki ) { + // build the input field + var $input = $( '<textarea></textarea>' ); + $input.text( wiki ); + + // build preview and cancel buttons and add click events + var $preview = $( '<input type="button" value="Preview" class="preview"/>' ); + var $cancel = $( '<input type="button" value="Cancel" class="cancel"/>' ); + $preview.click( $.inlineEditor.basicEditor.preview ); + $cancel.click( $.inlineEditor.basicEditor.cancel ); + + // build a div for the buttons + var $buttons = $( '<div class="buttons"></div> '); + $buttons.append( $preview ); + $buttons.append( $cancel ); + + // build the edit bar from the input field and buttons + var $editBar = $( '<div class="editbar"></div>' ); + $editBar.append( $input ); + $editBar.append( $buttons ); + + // append the edit bar to the new span + $newSpan.append( $editBar ); + + // automatically resize the textarea using the Elastic plugin + $input.elastic(); + + // focus on the input so you can start typing immediately + $input.focus(); + + return $editBar; + }, - // add the field after the current field in code - $field.after( $newField ); - return $newField; -}, - -/** - * Adds an edit bar to the field with preview and cancel functionality. - */ -addEditBar: function( $newSpan, wiki ) { - // build the input field - var $input = $( '<textarea></textarea>' ); - $input.text( wiki ); + /** + * Default click handler for simple editors. Recommended to override. + */ + click: function( event ) { + var $field = $(this); + + if( $field.hasClass( 'nobar' ) || event.pageX - $field.offset().left < 10 ) { + // prevent clicks from reaching other elements + event.stopPropagation(); + event.preventDefault(); + + // disable the existing editing field if necessary + $.inlineEditor.basicEditor.cancelAll(); + + // find the element and retrieve the corresponding wikitext + var wiki = $.inlineEditor.getTextById( $field.attr( 'id' ) ); + + // create the edit field and build the edit bar + var $newField = $.inlineEditor.basicEditor.newField( $field, $.inlineEditor.basicEditor.click ); + $.inlineEditor.basicEditor.addEditBar( $newField, wiki ); + } + }, - // build preview and cancel buttons and add click events - var $preview = $( '<input type="button" value="Preview" class="preview"/>' ); - var $cancel = $( '<input type="button" value="Cancel" class="cancel"/>' ); - $preview.click( $.inlineEditor.basicEditor.preview ); - $cancel.click( $.inlineEditor.basicEditor.cancel ); + /** + * Cancels the current edit operation. + */ + cancel: function( event ) { + // prevent clicks from reaching other elements + event.stopPropagation(); + event.preventDefault(); + + // find the outer span, three parents above the buttons + var $span = $(this).parent().parent().parent(); + + // find the span with the original value + var $orig = $span.data( 'orig' ); + + // convert the span to it's original state + $orig.removeClass( 'orig' ); + $orig.removeClass( 'hover' ); + + // place the original span after the current span and remove the current span + $span.after( $orig ); + $span.remove(); + + // reload the editor to fix stuff that might or might not be broken + $.inlineEditor.reload(); + }, - // build a div for the buttons - var $buttons = $( '<div class="buttons"></div> '); - $buttons.append( $preview ); - $buttons.append( $cancel ); - - // build the edit bar from the input field and buttons - var $editBar = $( '<div class="editbar"></div>' ); - $editBar.append( $input ); - $editBar.append( $buttons ); - - // append the edit bar to the new span - $newSpan.append( $editBar ); - - // automatically resize the textarea using the Elastic plugin - $input.elastic(); - - // focus on the input so you can start typing immediately - $input.focus(); - - return $editBar; -}, - -/** - * Default click handler for simple editors. Recommended to override. - */ -click: function( event ) { - var $field = $(this); - - if( $field.hasClass( 'nobar' ) || event.pageX - $field.offset().left < 10 ) { + /** + * Previews the current edit operation. + */ + preview: function( event ) { // prevent clicks from reaching other elements event.stopPropagation(); event.preventDefault(); - - // disable the existing editing field if necessary - $.inlineEditor.basicEditor.cancelAll(); - // find the element and retrieve the corresponding wikitext - var wiki = $.inlineEditor.getTextById( $field.attr( 'id' ) ); + // find the span with class 'editbar', two parent above the buttons + var $editbar = $(this).parent().parent(); - // create the edit field and build the edit bar - $newField = $.inlineEditor.basicEditor.newField( $field, $.inlineEditor.basicEditor.click ); - $.inlineEditor.basicEditor.addEditBar( $newField, wiki ); - } -}, - -/** - * Cancels the current edit operation. - */ -cancel: function( event ) { - // prevent clicks from reaching other elements - event.stopPropagation(); - event.preventDefault(); + // the element is one level above the editbar + var $element = $editbar.parent(); + + // add a visual indicator to show the preview is loading + $element.addClass( 'saving' ); + var $overlay = $( '<div class="overlay"><div class="alpha"></div><img class="spinner" src="' + wgScriptPath + '/extensions/InlineEditor/ajax-loader.gif"/></div>' ); + $editbar.after( $overlay ); + + // get the edited text and the id to save it to + var text = $editbar.children( 'textarea' ).val(); + var id = $element.data( 'orig' ).attr( 'id' ); + + // let the inlineEditor framework handle the preview + $.inlineEditor.previewTextById( text, id ); + }, - // find the outer span, three parents above the buttons - var $span = $(this).parent().parent().parent(); + /** + * Cancel all basic editors. + */ + cancelAll: function() { + $('.editing').find('.cancel').click(); + }, - // find the span with the original value - var $orig = $span.data( 'orig' ); + /** + * Bind all required events. + */ + bindEvents: function( $elements ) { + $elements.unbind(); + $elements.click( $.inlineEditor.basicEditor.click ); + $elements.mousemove( $.inlineEditor.basicEditor.mouseMove ); + $elements.mouseleave( $.inlineEditor.basicEditor.mouseLeave ); + }, - // convert the span to it's original state - $orig.removeClass( 'orig' ); - $orig.removeClass( 'hover' ); + /** + * Do a javascript hover on the bars at the left. + */ + mouseMove: function( event ) { + var $field = $( this ); + if( $field.hasClass( 'bar' ) ) { + if( event.pageX - $field.offset().left < 10 ) { + $field.addClass( 'hover' ); + } + else { + $field.removeClass( 'hover' ); + } + } + }, - // place the original span after the current span and remove the current span - $span.after( $orig ); - $span.remove(); - - // reload the editor to fix stuff that might or might not be broken - $.inlineEditor.reload(); -}, - -/** - * Previews the current edit operation. - */ -preview: function( event ) { - // prevent clicks from reaching other elements - event.stopPropagation(); - event.preventDefault(); - - // find the span with class 'editbar', two parent above the buttons - var $editbar = $(this).parent().parent(); - - // the element is one level above the editbar - var $element = $editbar.parent(); - - // add a visual indicator to show the preview is loading - $element.addClass( 'saving' ); - var $overlay = $( '<div class="overlay"><div class="alpha"></div><img class="spinner" src="' + wgScriptPath + '/extensions/InlineEditor/ajax-loader.gif"/></div>' ); - $editbar.after( $overlay ); - - // get the edited text and the id to save it to - text = $editbar.children( 'textarea' ).val(); - id = $element.data( 'orig' ).attr( 'id' ); - - // let the inlineEditor framework handle the preview - $.inlineEditor.previewTextById( text, id ); -}, - -/** - * Cancel all basic editors. - */ -cancelAll: function() { - $('.editing').find('.cancel').click(); -}, - -/** - * Bind all required events. - */ -bindEvents: function( $elements ) { - $elements.unbind(); - $elements.click( $.inlineEditor.basicEditor.click ); - $elements.mousemove( $.inlineEditor.basicEditor.mouseMove ); - $elements.mouseleave( $.inlineEditor.basicEditor.mouseLeave ); -}, - -/** - * Do a javascript hover on the bars at the left. - */ -mouseMove: function( event ) { - $field = $( this ); - if( $field.hasClass( 'bar' ) ) { - if( event.pageX - $field.offset().left < 10 ) { - $field.addClass( 'hover' ); - } - else { + /** + * Remove the hover class when leaving the element. + */ + mouseLeave: function( event ) { + var $field = $( this ); + if( $field.hasClass( 'bar' ) ) { $field.removeClass( 'hover' ); } } -}, -/** - * Remove the hover class when leaving the element. - */ -mouseLeave: function( event ) { - $field = $( this ); - if( $field.hasClass( 'bar' ) ) { - $field.removeClass( 'hover' ); - } -} - }; } ) ( jQuery ); Modified: trunk/extensions/InlineEditor/jquery.inlineEditor.js =================================================================== --- trunk/extensions/InlineEditor/jquery.inlineEditor.js 2011-01-21 23:35:58 UTC (rev 80730) +++ trunk/extensions/InlineEditor/jquery.inlineEditor.js 2011-01-21 23:48:35 UTC (rev 80731) @@ -3,181 +3,181 @@ * using specific editors, and undo/redo operations. */ ( function( $ ) { $.inlineEditor = { -editors: {}, - -states: [], -currentState: 0, -lastState: 0, - -/** - * Adds the initial state from the current HTML and a wiki string. - */ -addInitialState: function( state ) { - $.inlineEditor.currentState = 0; - $.inlineEditor.states[$.inlineEditor.currentState] = { - 'object': state.object, - 'texts': state.texts, - 'html': $( '#editContent' ).html() - }; -}, - -/** - * Returns wikitext in the current state given an ID. - */ -getTextById: function( id ) { - return $.inlineEditor.states[$.inlineEditor.currentState].texts[id]; -}, - -/** - * Previews given a new text for a given field by ID. - */ -previewTextById: function( text, id ) { - // send out an AJAX request which will be handled by addNewState() - var data = { - 'object': $.inlineEditor.states[$.inlineEditor.currentState].object, - 'lastEdit': { 'id': id, 'text': text } - }; + editors: {}, - var args = [ JSON.stringify( data ), wgPageName ]; - sajax_request_type = 'POST'; - sajax_do_call( 'InlineEditor::ajaxPreview', args, $.inlineEditor.addNewState ); -}, - -/** - * Adds a new state from an AJAX request. - */ -addNewState: function( request ) { - state = JSON.parse( request.responseText ); + states: [], + currentState: 0, + lastState: 0, - // restore the html to the current state, instantly remove the lastEdit, - // and then add the new html - $( '#editContent' ).html( $.inlineEditor.states[$.inlineEditor.currentState].html ); - $( '.lastEdit' ).removeClass( 'lastEdit' ); - $( '#' + state.partialHtml.id ).replaceWith( state.partialHtml.html ); + /** + * Adds the initial state from the current HTML and a wiki string. + */ + addInitialState: function( state ) { + $.inlineEditor.currentState = 0; + $.inlineEditor.states[$.inlineEditor.currentState] = { + 'object': state.object, + 'texts': state.texts, + 'html': $( '#editContent' ).html() + }; + }, - // add the new state - $.inlineEditor.currentState += 1; - $.inlineEditor.states[$.inlineEditor.currentState] = { - 'object': state.object, - 'texts': state.texts, - 'html': $( '#editContent' ).html() - }; + /** + * Returns wikitext in the current state given an ID. + */ + getTextById: function( id ) { + return $.inlineEditor.states[$.inlineEditor.currentState].texts[id]; + }, - // clear out all states after the current state, because undo/redo would be broken - var i = $.inlineEditor.currentState + 1; - while( i <= $.inlineEditor.lastState ) { - delete $.inlineEditor.states[i]; - i += 1; - } - $.inlineEditor.lastState = $.inlineEditor.currentState; + /** + * Previews given a new text for a given field by ID. + */ + previewTextById: function( text, id ) { + // send out an AJAX request which will be handled by addNewState() + var data = { + 'object': $.inlineEditor.states[$.inlineEditor.currentState].object, + 'lastEdit': { 'id': id, 'text': text } + }; + + var args = [ JSON.stringify( data ), wgPageName ]; + sajax_request_type = 'POST'; + sajax_do_call( 'InlineEditor::ajaxPreview', args, $.inlineEditor.addNewState ); + }, - // reload the current editor and update the edit counter - $.inlineEditor.reload(); - $.inlineEditor.updateEditCounter(); -}, - -/** - * Reloads the current editor and finish some things in the HTML. - */ -reload: function() { - $.inlineEditor.basicEditor.cancelAll(); + /** + * Adds a new state from an AJAX request. + */ + addNewState: function( request ) { + var state = JSON.parse( request.responseText ); + + // restore the html to the current state, instantly remove the lastEdit, + // and then add the new html + $( '#editContent' ).html( $.inlineEditor.states[$.inlineEditor.currentState].html ); + $( '.lastEdit' ).removeClass( 'lastEdit' ); + $( '#' + state.partialHtml.id ).replaceWith( state.partialHtml.html ); + + // add the new state + $.inlineEditor.currentState += 1; + $.inlineEditor.states[$.inlineEditor.currentState] = { + 'object': state.object, + 'texts': state.texts, + 'html': $( '#editContent' ).html() + }; + + // clear out all states after the current state, because undo/redo would be broken + var i = $.inlineEditor.currentState + 1; + while( i <= $.inlineEditor.lastState ) { + delete $.inlineEditor.states[i]; + i += 1; + } + $.inlineEditor.lastState = $.inlineEditor.currentState; + + // reload the current editor and update the edit counter + $.inlineEditor.reload(); + $.inlineEditor.updateEditCounter(); + }, - // bind all events of the basic editor - $.inlineEditor.basicEditor.bindEvents( $( '.inlineEditorElement' ) ); + /** + * Reloads the current editor and finish some things in the HTML. + */ + reload: function() { + $.inlineEditor.basicEditor.cancelAll(); + + // bind all events of the basic editor + $.inlineEditor.basicEditor.bindEvents( $( '.inlineEditorElement' ) ); + + // reload the specific editors + for( var optionNr in $.inlineEditor.editors ) { + $.inlineEditor.editors[optionNr].reload(); + } + + // remove all lastEdit elements + $('.lastEdit').removeClass( 'lastEdit' ); + + // make the links in the article unusable + $( '#editContent a' ).click( function( event ) { event.preventDefault(); } ); + }, - // reload the specific editors - for( var optionNr in $.inlineEditor.editors) { - $.inlineEditor.editors[optionNr].reload(); - } + /** + * Moves back one state. + */ + undo: function( event ) { + event.stopPropagation(); + event.preventDefault(); + + // check if we can move backward one state and do it + if( $.inlineEditor.currentState > 0 ) { + $.inlineEditor.currentState -= 1; + $( '#editContent' ).html( $.inlineEditor.states[$.inlineEditor.currentState].html ); + $.inlineEditor.reload(); + } + + // refresh the edit counter regardless of actually switching, this confirms + // that the button works, even if there is nothing to switch to + $.inlineEditor.updateEditCounter(); + }, - // remove all lastEdit elements - $('.lastEdit').removeClass( 'lastEdit' ); + /** + * Moves forward one state. + */ + redo: function( event ) { + event.stopPropagation(); + event.preventDefault(); + + // check if we can move forward one state and do it + if( $.inlineEditor.currentState < $.inlineEditor.lastState ) { + $.inlineEditor.currentState += 1; + $('#editContent').html( $.inlineEditor.states[$.inlineEditor.currentState].html ); + $.inlineEditor.reload(); + } + + // refresh the edit counter regardless of actually switching, this confirms + // that the button works, even if there is nothing to switch to + $.inlineEditor.updateEditCounter(); + }, - // make the links in the article unusable - $( '#editContent a' ).click( function( event ) { event.preventDefault(); } ); -}, - -/** - * Moves back one state. - */ -undo: function( event ) { - event.stopPropagation(); - event.preventDefault(); + /** + * Updates the edit counter and makes it flash. + */ + updateEditCounter: function() { + // update the value of the edit counter + var $editCounter = $( '#editCounter' ); + $editCounter.text( '#' + $.inlineEditor.currentState ); + + // remove everything from the editcounter, and have it fade again + $editCounter.removeClass( 'changeHighlight' ); + $editCounter.attr( 'style', '' ); + $editCounter.addClass( 'changeHighlight' ); + $editCounter.removeClass( 'changeHighlight', 200 ); + }, - // check if we can move backward one state and do it - if( $.inlineEditor.currentState > 0 ) { - $.inlineEditor.currentState -= 1; - $( '#editContent' ).html( $.inlineEditor.states[$.inlineEditor.currentState].html ); - $.inlineEditor.reload(); - } + /** + * Publishes the document in its current state. + */ + publish: function( event ) { + event.stopPropagation(); + event.preventDefault(); + + // get the wikitext from the state as it's currently on the screen + var data = { + 'object': $.inlineEditor.states[$.inlineEditor.currentState].object + }; + var json = JSON.stringify( data ); + + // set and send the form + $( '#json' ).val( json ); + $( '#editForm' ).submit(); + }, - // refresh the edit counter regardless of actually switching, this confirms - // that the button works, even if there is nothing to switch to - $.inlineEditor.updateEditCounter(); -}, - -/** - * Moves forward one state. - */ -redo: function( event ) { - event.stopPropagation(); - event.preventDefault(); - - // check if we can move forward one state and do it - if( $.inlineEditor.currentState < $.inlineEditor.lastState ) { - $.inlineEditor.currentState += 1; - $('#editContent').html( $.inlineEditor.states[$.inlineEditor.currentState].html ); + /** + * Initializes the editor. + */ + init : function() { + $( '#publish' ).click( $.inlineEditor.publish ); + //$( '#undo' ).click( $.inlineEditor.undo ); + //$( '#redo' ).click( $.inlineEditor.redo ); + + // reload the current editor $.inlineEditor.reload(); } - - // refresh the edit counter regardless of actually switching, this confirms - // that the button works, even if there is nothing to switch to - $.inlineEditor.updateEditCounter(); -}, -/** - * Updates the edit counter and makes it flash. - */ -updateEditCounter: function() { - // update the value of the edit counter - var $editCounter = $( '#editCounter' ); - $editCounter.text( '#' + $.inlineEditor.currentState ); - - // remove everything from the editcounter, and have it fade again - $editCounter.removeClass( 'changeHighlight' ); - $editCounter.attr( 'style', '' ); - $editCounter.addClass( 'changeHighlight' ); - $editCounter.removeClass( 'changeHighlight', 200 ); -}, - -/** - * Publishes the document in its current state. - */ -publish: function( event ) { - event.stopPropagation(); - event.preventDefault(); - - // get the wikitext from the state as it's currently on the screen - var data = { - 'object': $.inlineEditor.states[$.inlineEditor.currentState].object - }; - var json = JSON.stringify( data ); - - // set and send the form - $( '#json' ).val( json ); - $( '#editForm' ).submit(); -}, - -/** - * Initializes the editor. - */ -init : function() { - $( '#publish' ).click( $.inlineEditor.publish ); - //$( '#undo' ).click( $.inlineEditor.undo ); - //$( '#redo' ).click( $.inlineEditor.redo ); - - // reload the current editor - $.inlineEditor.reload(); -} - }; } ) ( jQuery ); \ No newline at end of file _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs