Index: trunk/extensions/InlineEditor/InlineEditor.class.php |
— | — | @@ -371,6 +371,7 @@ |
372 | 372 | * @return bool |
373 | 373 | */ |
374 | 374 | public static function partialRenderCite( $markedWiki ) { |
375 | | - return ( preg_match( '/<ref[^\/]*?>.*?<\/ref>|<ref.*?\/>/is', $markedWiki) <= 0) ; |
| 375 | + return true; |
| 376 | + /*return ( preg_match( '/<ref[^\/]*?>.*?<\/ref>|<ref.*?\/>/is', $markedWiki) <= 0) ;*/ |
376 | 377 | } |
377 | 378 | } |
Index: trunk/extensions/InlineEditor/InlineEditorText.class.php |
— | — | @@ -178,6 +178,9 @@ |
179 | 179 | // sort the markings while preserving the keys (ids) |
180 | 180 | uasort( $this->markings, 'InlineEditorText::sortByStartAndLength' ); |
181 | 181 | |
| 182 | + // collapse markings |
| 183 | + $this->collapseMarkings(); |
| 184 | + |
182 | 185 | // match up previous markings |
183 | 186 | $this->matchPreviousMarkings(); |
184 | 187 | } |
— | — | @@ -217,6 +220,21 @@ |
218 | 221 | } |
219 | 222 | |
220 | 223 | /** |
| 224 | + * Finds markings of exact same positions, and uses only the deepest markings. |
| 225 | + */ |
| 226 | + protected function collapseMarkings() { |
| 227 | + foreach( $this->markings as $id => $marking ) { |
| 228 | + if( isset( $previous ) ) { |
| 229 | + if( $previous->getCollapsible() && $marking->samePositionAs( $previous ) ) { |
| 230 | + unset( $this->markings[$previousID] ); |
| 231 | + } |
| 232 | + } |
| 233 | + $previous = $marking; |
| 234 | + $previousID = $id; |
| 235 | + } |
| 236 | + } |
| 237 | + |
| 238 | + /** |
221 | 239 | * Previous markings are moved into the current markings list to be able to only |
222 | 240 | * render a part of the page which is much faster. |
223 | 241 | * |
— | — | @@ -249,29 +267,23 @@ |
250 | 268 | while( isset( $this->previous[$indexPrevious] ) ) { |
251 | 269 | $previous = $this->previous[$indexPrevious]; |
252 | 270 | |
253 | | - if( $previous->getStart() < $marking->getStart() ) { |
254 | | - $indexPrevious++; |
| 271 | + switch( self::sortByStartAndLength( $previous, $marking ) ) { |
| 272 | + case 1: |
| 273 | + // if we've moved past the current marking, break, mismatch, and go to the next current marking |
| 274 | + break(2); |
| 275 | + case -1: |
| 276 | + // if we haven't moved past the current marking but also haven't found it, continue the search |
| 277 | + $indexPrevious++; |
| 278 | + break; |
| 279 | + default: |
| 280 | + // a previous marking has been matched with a current marking |
| 281 | + // the previous marking will replace the current one |
| 282 | + $previous->setMatched( true ); |
| 283 | + $newMarkings[$previous->getId()] = $previous; |
| 284 | + $foundMatch = true; |
| 285 | + $indexPrevious++; |
| 286 | + break(2); |
255 | 287 | } |
256 | | - elseif( $previous->getStart() == $marking->getStart() && $previous->getLength() > $marking->getLength() ) { |
257 | | - $indexPrevious++; |
258 | | - } |
259 | | - elseif( $previous->samePositionAs( $marking ) && strcmp( $previous->getClass(), $marking->getClass() ) < 0 ) { |
260 | | - $indexPrevious++; |
261 | | - } |
262 | | - elseif( $marking->equals( $previous, array( 'edited', 'lastEdit') ) ) |
263 | | - { |
264 | | - // a previous marking has been matched with a current marking |
265 | | - // the previous marking will replace the current one |
266 | | - $previous->setMatched( true ); |
267 | | - $newMarkings[$previous->getId()] = $previous; |
268 | | - $foundMatch = true; |
269 | | - $indexPrevious++; |
270 | | - break; |
271 | | - } |
272 | | - else { |
273 | | - // if we've moved past the current marking, break, mismatch, and go to the next current marking |
274 | | - break; |
275 | | - } |
276 | 288 | } |
277 | 289 | |
278 | 290 | if( !$foundMatch ) { |
— | — | @@ -373,7 +385,6 @@ |
374 | 386 | * - start position (asc) |
375 | 387 | * - length (desc) |
376 | 388 | * - level (desc) |
377 | | - * - class name (asc) |
378 | 389 | * @param $a InlineEditorMarking |
379 | 390 | * @param $b InlineEditorMarking |
380 | 391 | * @return int |
— | — | @@ -382,7 +393,7 @@ |
383 | 394 | if( $a->getStart() == $b->getStart() ) { |
384 | 395 | if( $a->getLength() == $b->getLength() ) { |
385 | 396 | if( $a->getLevel() == $b->getLevel() ) { |
386 | | - return strcmp( $a->getClass(), $b->getClass() ); |
| 397 | + return $a->equals( $b, array( 'edited', 'lastEdit' ) ) ? 0 : 1; |
387 | 398 | } |
388 | 399 | else { |
389 | 400 | return ( $a->getLevel() > $b->getLevel() ? -1 : 1 ); |
Index: trunk/extensions/InlineEditor/InlineEditorMarking.class.php |
— | — | @@ -9,34 +9,38 @@ |
10 | 10 | const autoClasses = 'block inline bar nobar'; // automatically added classes which shouldn't be added by hand |
11 | 11 | protected static $lastId = 0; /// < counter which is used to generate unique ids |
12 | 12 | |
13 | | - protected $start; /// < start position of the marking in the wikitext |
14 | | - protected $end; /// < end position of the marking in the wikitext |
15 | | - protected $classes; /// < class(es) attached to the marking which identifies the type |
16 | | - protected $block; /// < whether the tag should be added as a block or inline |
17 | | - protected $bar; /// < whether the text should carry a bar at the left, or be fully selectable |
18 | | - protected $id; /// < id in the original text; this will be unique even when calculating new ids! |
19 | | - protected $matched; /// < bool whether or not this marking has been matched with a previous marking (default: true) |
20 | | - protected $level; /// < nesting level, which is used to sort consistently when two markings are of same length |
| 13 | + protected $start; /// < start position of the marking in the wikitext |
| 14 | + protected $end; /// < end position of the marking in the wikitext |
| 15 | + protected $classes; /// < class(es) attached to the marking which identifies the type |
| 16 | + protected $block; /// < whether the tag should be added as a block or inline |
| 17 | + protected $bar; /// < whether the text should carry a bar at the left, or be fully selectable |
| 18 | + protected $level; /// < nesting level, which is used to sort consistently when two markings are of same length |
| 19 | + protected $collapsible; /// < whether or not the marking can be collapsed when only containing one nested element |
21 | 20 | |
| 21 | + protected $id; /// < id in the original text; this will be unique even when calculating new ids! |
| 22 | + protected $matched; /// < bool whether or not this marking has been matched with a previous marking (default: true) |
| 23 | + |
22 | 24 | /** |
23 | | - * @param $start int Start of the marking, offset in number of characters from the begin of the wikitext |
24 | | - * @param $end int End of the marking, offset in number of characters from the begin of the wikitext |
25 | | - * @param $classes mixed Class(es) the marking should be labeled with, can be either a string or an array of strings |
26 | | - * @param $block bool Whether the tag should be added as a block or inline |
27 | | - * @param $bar bool Whether the text should carry a bar at the left, or be fully selectable |
28 | | - * @param $level int Nesting level, which is used to sort consistently when two markings are of same length, default: 0 |
| 25 | + * @param $start int Start of the marking, offset in number of characters from the begin of the wikitext |
| 26 | + * @param $end int End of the marking, offset in number of characters from the begin of the wikitext |
| 27 | + * @param $classes mixed Class(es) the marking should be labeled with, can be either a string or an array of strings |
| 28 | + * @param $block bool Whether the tag should be added as a block or inline |
| 29 | + * @param $bar bool Whether the text should carry a bar at the left, or be fully selectable |
| 30 | + * @param $level int Nesting level, which is used to sort consistently when two markings are of same length, default: 0 |
| 31 | + * @param $collapsible bool Whether or not the marking can be collapsed when only containing one nested element, default: true |
29 | 32 | */ |
30 | | - function __construct( $start, $end, $classes, $block, $bar, $level = 0 ) { |
31 | | - $this->start = $start; |
32 | | - $this->end = $end; |
33 | | - $this->block = $block; |
34 | | - $this->bar = $bar; |
35 | | - $this->level = $level; |
| 33 | + function __construct( $start, $end, $classes, $block, $bar, $level = 0, $collapsible = true ) { |
| 34 | + $this->start = $start; |
| 35 | + $this->end = $end; |
| 36 | + $this->block = $block; |
| 37 | + $this->bar = $bar; |
| 38 | + $this->level = $level; |
| 39 | + $this->collapsible = $collapsible; |
36 | 40 | |
37 | | - $this->matched = true; |
38 | | - $this->id = self::uniqueId(); |
| 41 | + $this->matched = true; |
| 42 | + $this->id = self::uniqueId(); |
39 | 43 | |
40 | | - $this->classes = array(); |
| 44 | + $this->classes = array(); |
41 | 45 | $this->addClasses( $classes ); |
42 | 46 | |
43 | 47 | } |
— | — | @@ -184,11 +188,11 @@ |
185 | 189 | } |
186 | 190 | |
187 | 191 | /** |
188 | | - * Set the nesting level, which is used to sort consistently when two markings are of same length. |
| 192 | + * Get whether or not the marking can be collapsed when only containing one nested element. |
189 | 193 | * @param $value int |
190 | 194 | */ |
191 | | - public function setLevel( $value ) { |
192 | | - $this->level = $value; |
| 195 | + public function getCollapsible() { |
| 196 | + return $this->collapsible; |
193 | 197 | } |
194 | 198 | |
195 | 199 | /** |
Index: trunk/extensions/InlineEditor/jquery.inlineEditor.basicEditor.js |
— | — | @@ -2,178 +2,182 @@ |
3 | 3 | * Provides a basic editor with preview and cancel functionality. |
4 | 4 | */ |
5 | 5 | ( function( $ ) { $.inlineEditor.basicEditor = { |
6 | | - |
7 | | -/** |
8 | | - * Creates a new hovering edit field. |
9 | | - */ |
10 | | -newField: function( $field, originalClickEvent ) { |
11 | | - // create a new field |
12 | | - var $newField = $( '<' + $field.get(0).nodeName + '/>' ); |
13 | | - $newField.addClass( 'editing' ); |
14 | 6 | |
15 | | - // position the field floating on the page, at the same position the original field |
16 | | - $newField.css( 'top', $field.position().top ); |
| 7 | + /** |
| 8 | + * Creates a new hovering edit field. |
| 9 | + */ |
| 10 | + newField: function( $field, originalClickEvent ) { |
| 11 | + // create a new field |
| 12 | + var $newField = $( '<' + $field.get(0).nodeName + '/>' ); |
| 13 | + $newField.addClass( 'editing' ); |
| 14 | + |
| 15 | + // position the field floating on the page, at the same position the original field |
| 16 | + $newField.css( 'top', $field.position().top ); |
| 17 | + |
| 18 | + // point to the original field using jQuery data |
| 19 | + $newField.data( 'orig', $field ); |
| 20 | + |
| 21 | + // make sure click and mousemove events aren't passed on |
| 22 | + $newField.click( function( event ) { event.stopPropagation(); } ); |
| 23 | + $newField.mousemove( function( event ) { event.stopPropagation(); } ); |
| 24 | + |
| 25 | + // add the field after the current field in code |
| 26 | + $field.after( $newField ); |
| 27 | + return $newField; |
| 28 | + }, |
17 | 29 | |
18 | | - // point to the original field using jQuery data |
19 | | - $newField.data( 'orig', $field ); |
| 30 | + /** |
| 31 | + * Adds an edit bar to the field with preview and cancel functionality. |
| 32 | + */ |
| 33 | + addEditBar: function( $newSpan, wiki ) { |
| 34 | + // build the input field |
| 35 | + var $input = $( '<textarea></textarea>' ); |
| 36 | + $input.text( wiki ); |
| 37 | + |
| 38 | + // build preview and cancel buttons and add click events |
| 39 | + var $preview = $( '<input type="button" value="Preview" class="preview"/>' ); |
| 40 | + var $cancel = $( '<input type="button" value="Cancel" class="cancel"/>' ); |
| 41 | + $preview.click( $.inlineEditor.basicEditor.preview ); |
| 42 | + $cancel.click( $.inlineEditor.basicEditor.cancel ); |
| 43 | + |
| 44 | + // build a div for the buttons |
| 45 | + var $buttons = $( '<div class="buttons"></div> '); |
| 46 | + $buttons.append( $preview ); |
| 47 | + $buttons.append( $cancel ); |
| 48 | + |
| 49 | + // build the edit bar from the input field and buttons |
| 50 | + var $editBar = $( '<div class="editbar"></div>' ); |
| 51 | + $editBar.append( $input ); |
| 52 | + $editBar.append( $buttons ); |
| 53 | + |
| 54 | + // append the edit bar to the new span |
| 55 | + $newSpan.append( $editBar ); |
| 56 | + |
| 57 | + // automatically resize the textarea using the Elastic plugin |
| 58 | + $input.elastic(); |
| 59 | + |
| 60 | + // focus on the input so you can start typing immediately |
| 61 | + $input.focus(); |
| 62 | + |
| 63 | + return $editBar; |
| 64 | + }, |
20 | 65 | |
21 | | - // add the field after the current field in code |
22 | | - $field.after( $newField ); |
23 | | - return $newField; |
24 | | -}, |
25 | | - |
26 | | -/** |
27 | | - * Adds an edit bar to the field with preview and cancel functionality. |
28 | | - */ |
29 | | -addEditBar: function( $newSpan, wiki ) { |
30 | | - // build the input field |
31 | | - var $input = $( '<textarea></textarea>' ); |
32 | | - $input.text( wiki ); |
| 66 | + /** |
| 67 | + * Default click handler for simple editors. Recommended to override. |
| 68 | + */ |
| 69 | + click: function( event ) { |
| 70 | + var $field = $(this); |
| 71 | + |
| 72 | + if( $field.hasClass( 'nobar' ) || event.pageX - $field.offset().left < 10 ) { |
| 73 | + // prevent clicks from reaching other elements |
| 74 | + event.stopPropagation(); |
| 75 | + event.preventDefault(); |
| 76 | + |
| 77 | + // disable the existing editing field if necessary |
| 78 | + $.inlineEditor.basicEditor.cancelAll(); |
| 79 | + |
| 80 | + // find the element and retrieve the corresponding wikitext |
| 81 | + var wiki = $.inlineEditor.getTextById( $field.attr( 'id' ) ); |
| 82 | + |
| 83 | + // create the edit field and build the edit bar |
| 84 | + var $newField = $.inlineEditor.basicEditor.newField( $field, $.inlineEditor.basicEditor.click ); |
| 85 | + $.inlineEditor.basicEditor.addEditBar( $newField, wiki ); |
| 86 | + } |
| 87 | + }, |
33 | 88 | |
34 | | - // build preview and cancel buttons and add click events |
35 | | - var $preview = $( '<input type="button" value="Preview" class="preview"/>' ); |
36 | | - var $cancel = $( '<input type="button" value="Cancel" class="cancel"/>' ); |
37 | | - $preview.click( $.inlineEditor.basicEditor.preview ); |
38 | | - $cancel.click( $.inlineEditor.basicEditor.cancel ); |
| 89 | + /** |
| 90 | + * Cancels the current edit operation. |
| 91 | + */ |
| 92 | + cancel: function( event ) { |
| 93 | + // prevent clicks from reaching other elements |
| 94 | + event.stopPropagation(); |
| 95 | + event.preventDefault(); |
| 96 | + |
| 97 | + // find the outer span, three parents above the buttons |
| 98 | + var $span = $(this).parent().parent().parent(); |
| 99 | + |
| 100 | + // find the span with the original value |
| 101 | + var $orig = $span.data( 'orig' ); |
| 102 | + |
| 103 | + // convert the span to it's original state |
| 104 | + $orig.removeClass( 'orig' ); |
| 105 | + $orig.removeClass( 'hover' ); |
| 106 | + |
| 107 | + // place the original span after the current span and remove the current span |
| 108 | + $span.after( $orig ); |
| 109 | + $span.remove(); |
| 110 | + |
| 111 | + // reload the editor to fix stuff that might or might not be broken |
| 112 | + $.inlineEditor.reload(); |
| 113 | + }, |
39 | 114 | |
40 | | - // build a div for the buttons |
41 | | - var $buttons = $( '<div class="buttons"></div> '); |
42 | | - $buttons.append( $preview ); |
43 | | - $buttons.append( $cancel ); |
44 | | - |
45 | | - // build the edit bar from the input field and buttons |
46 | | - var $editBar = $( '<div class="editbar"></div>' ); |
47 | | - $editBar.append( $input ); |
48 | | - $editBar.append( $buttons ); |
49 | | - |
50 | | - // append the edit bar to the new span |
51 | | - $newSpan.append( $editBar ); |
52 | | - |
53 | | - // automatically resize the textarea using the Elastic plugin |
54 | | - $input.elastic(); |
55 | | - |
56 | | - // focus on the input so you can start typing immediately |
57 | | - $input.focus(); |
58 | | - |
59 | | - return $editBar; |
60 | | -}, |
61 | | - |
62 | | -/** |
63 | | - * Default click handler for simple editors. Recommended to override. |
64 | | - */ |
65 | | -click: function( event ) { |
66 | | - var $field = $(this); |
67 | | - |
68 | | - if( $field.hasClass( 'nobar' ) || event.pageX - $field.offset().left < 10 ) { |
| 115 | + /** |
| 116 | + * Previews the current edit operation. |
| 117 | + */ |
| 118 | + preview: function( event ) { |
69 | 119 | // prevent clicks from reaching other elements |
70 | 120 | event.stopPropagation(); |
71 | 121 | event.preventDefault(); |
72 | | - |
73 | | - // disable the existing editing field if necessary |
74 | | - $.inlineEditor.basicEditor.cancelAll(); |
75 | 122 | |
76 | | - // find the element and retrieve the corresponding wikitext |
77 | | - var wiki = $.inlineEditor.getTextById( $field.attr( 'id' ) ); |
| 123 | + // find the span with class 'editbar', two parent above the buttons |
| 124 | + var $editbar = $(this).parent().parent(); |
78 | 125 | |
79 | | - // create the edit field and build the edit bar |
80 | | - $newField = $.inlineEditor.basicEditor.newField( $field, $.inlineEditor.basicEditor.click ); |
81 | | - $.inlineEditor.basicEditor.addEditBar( $newField, wiki ); |
82 | | - } |
83 | | -}, |
84 | | - |
85 | | -/** |
86 | | - * Cancels the current edit operation. |
87 | | - */ |
88 | | -cancel: function( event ) { |
89 | | - // prevent clicks from reaching other elements |
90 | | - event.stopPropagation(); |
91 | | - event.preventDefault(); |
| 126 | + // the element is one level above the editbar |
| 127 | + var $element = $editbar.parent(); |
| 128 | + |
| 129 | + // add a visual indicator to show the preview is loading |
| 130 | + $element.addClass( 'saving' ); |
| 131 | + var $overlay = $( '<div class="overlay"><div class="alpha"></div><img class="spinner" src="' + wgScriptPath + '/extensions/InlineEditor/ajax-loader.gif"/></div>' ); |
| 132 | + $editbar.after( $overlay ); |
| 133 | + |
| 134 | + // get the edited text and the id to save it to |
| 135 | + var text = $editbar.children( 'textarea' ).val(); |
| 136 | + var id = $element.data( 'orig' ).attr( 'id' ); |
| 137 | + |
| 138 | + // let the inlineEditor framework handle the preview |
| 139 | + $.inlineEditor.previewTextById( text, id ); |
| 140 | + }, |
92 | 141 | |
93 | | - // find the outer span, three parents above the buttons |
94 | | - var $span = $(this).parent().parent().parent(); |
| 142 | + /** |
| 143 | + * Cancel all basic editors. |
| 144 | + */ |
| 145 | + cancelAll: function() { |
| 146 | + $('.editing').find('.cancel').click(); |
| 147 | + }, |
95 | 148 | |
96 | | - // find the span with the original value |
97 | | - var $orig = $span.data( 'orig' ); |
| 149 | + /** |
| 150 | + * Bind all required events. |
| 151 | + */ |
| 152 | + bindEvents: function( $elements ) { |
| 153 | + $elements.unbind(); |
| 154 | + $elements.click( $.inlineEditor.basicEditor.click ); |
| 155 | + $elements.mousemove( $.inlineEditor.basicEditor.mouseMove ); |
| 156 | + $elements.mouseleave( $.inlineEditor.basicEditor.mouseLeave ); |
| 157 | + }, |
98 | 158 | |
99 | | - // convert the span to it's original state |
100 | | - $orig.removeClass( 'orig' ); |
101 | | - $orig.removeClass( 'hover' ); |
| 159 | + /** |
| 160 | + * Do a javascript hover on the bars at the left. |
| 161 | + */ |
| 162 | + mouseMove: function( event ) { |
| 163 | + var $field = $( this ); |
| 164 | + if( $field.hasClass( 'bar' ) ) { |
| 165 | + if( event.pageX - $field.offset().left < 10 ) { |
| 166 | + $field.addClass( 'hover' ); |
| 167 | + } |
| 168 | + else { |
| 169 | + $field.removeClass( 'hover' ); |
| 170 | + } |
| 171 | + } |
| 172 | + }, |
102 | 173 | |
103 | | - // place the original span after the current span and remove the current span |
104 | | - $span.after( $orig ); |
105 | | - $span.remove(); |
106 | | - |
107 | | - // reload the editor to fix stuff that might or might not be broken |
108 | | - $.inlineEditor.reload(); |
109 | | -}, |
110 | | - |
111 | | -/** |
112 | | - * Previews the current edit operation. |
113 | | - */ |
114 | | -preview: function( event ) { |
115 | | - // prevent clicks from reaching other elements |
116 | | - event.stopPropagation(); |
117 | | - event.preventDefault(); |
118 | | - |
119 | | - // find the span with class 'editbar', two parent above the buttons |
120 | | - var $editbar = $(this).parent().parent(); |
121 | | - |
122 | | - // the element is one level above the editbar |
123 | | - var $element = $editbar.parent(); |
124 | | - |
125 | | - // add a visual indicator to show the preview is loading |
126 | | - $element.addClass( 'saving' ); |
127 | | - var $overlay = $( '<div class="overlay"><div class="alpha"></div><img class="spinner" src="' + wgScriptPath + '/extensions/InlineEditor/ajax-loader.gif"/></div>' ); |
128 | | - $editbar.after( $overlay ); |
129 | | - |
130 | | - // get the edited text and the id to save it to |
131 | | - text = $editbar.children( 'textarea' ).val(); |
132 | | - id = $element.data( 'orig' ).attr( 'id' ); |
133 | | - |
134 | | - // let the inlineEditor framework handle the preview |
135 | | - $.inlineEditor.previewTextById( text, id ); |
136 | | -}, |
137 | | - |
138 | | -/** |
139 | | - * Cancel all basic editors. |
140 | | - */ |
141 | | -cancelAll: function() { |
142 | | - $('.editing').find('.cancel').click(); |
143 | | -}, |
144 | | - |
145 | | -/** |
146 | | - * Bind all required events. |
147 | | - */ |
148 | | -bindEvents: function( $elements ) { |
149 | | - $elements.unbind(); |
150 | | - $elements.click( $.inlineEditor.basicEditor.click ); |
151 | | - $elements.mousemove( $.inlineEditor.basicEditor.mouseMove ); |
152 | | - $elements.mouseleave( $.inlineEditor.basicEditor.mouseLeave ); |
153 | | -}, |
154 | | - |
155 | | -/** |
156 | | - * Do a javascript hover on the bars at the left. |
157 | | - */ |
158 | | -mouseMove: function( event ) { |
159 | | - $field = $( this ); |
160 | | - if( $field.hasClass( 'bar' ) ) { |
161 | | - if( event.pageX - $field.offset().left < 10 ) { |
162 | | - $field.addClass( 'hover' ); |
163 | | - } |
164 | | - else { |
| 174 | + /** |
| 175 | + * Remove the hover class when leaving the element. |
| 176 | + */ |
| 177 | + mouseLeave: function( event ) { |
| 178 | + var $field = $( this ); |
| 179 | + if( $field.hasClass( 'bar' ) ) { |
165 | 180 | $field.removeClass( 'hover' ); |
166 | 181 | } |
167 | 182 | } |
168 | | -}, |
169 | 183 | |
170 | | -/** |
171 | | - * Remove the hover class when leaving the element. |
172 | | - */ |
173 | | -mouseLeave: function( event ) { |
174 | | - $field = $( this ); |
175 | | - if( $field.hasClass( 'bar' ) ) { |
176 | | - $field.removeClass( 'hover' ); |
177 | | - } |
178 | | -} |
179 | | - |
180 | 184 | }; } ) ( jQuery ); |
Index: trunk/extensions/InlineEditor/jquery.inlineEditor.js |
— | — | @@ -3,181 +3,181 @@ |
4 | 4 | * using specific editors, and undo/redo operations. |
5 | 5 | */ |
6 | 6 | ( function( $ ) { $.inlineEditor = { |
7 | | -editors: {}, |
8 | | - |
9 | | -states: [], |
10 | | -currentState: 0, |
11 | | -lastState: 0, |
12 | | - |
13 | | -/** |
14 | | - * Adds the initial state from the current HTML and a wiki string. |
15 | | - */ |
16 | | -addInitialState: function( state ) { |
17 | | - $.inlineEditor.currentState = 0; |
18 | | - $.inlineEditor.states[$.inlineEditor.currentState] = { |
19 | | - 'object': state.object, |
20 | | - 'texts': state.texts, |
21 | | - 'html': $( '#editContent' ).html() |
22 | | - }; |
23 | | -}, |
24 | | - |
25 | | -/** |
26 | | - * Returns wikitext in the current state given an ID. |
27 | | - */ |
28 | | -getTextById: function( id ) { |
29 | | - return $.inlineEditor.states[$.inlineEditor.currentState].texts[id]; |
30 | | -}, |
31 | | - |
32 | | -/** |
33 | | - * Previews given a new text for a given field by ID. |
34 | | - */ |
35 | | -previewTextById: function( text, id ) { |
36 | | - // send out an AJAX request which will be handled by addNewState() |
37 | | - var data = { |
38 | | - 'object': $.inlineEditor.states[$.inlineEditor.currentState].object, |
39 | | - 'lastEdit': { 'id': id, 'text': text } |
40 | | - }; |
| 7 | + editors: {}, |
41 | 8 | |
42 | | - var args = [ JSON.stringify( data ), wgPageName ]; |
43 | | - sajax_request_type = 'POST'; |
44 | | - sajax_do_call( 'InlineEditor::ajaxPreview', args, $.inlineEditor.addNewState ); |
45 | | -}, |
46 | | - |
47 | | -/** |
48 | | - * Adds a new state from an AJAX request. |
49 | | - */ |
50 | | -addNewState: function( request ) { |
51 | | - state = JSON.parse( request.responseText ); |
| 9 | + states: [], |
| 10 | + currentState: 0, |
| 11 | + lastState: 0, |
52 | 12 | |
53 | | - // restore the html to the current state, instantly remove the lastEdit, |
54 | | - // and then add the new html |
55 | | - $( '#editContent' ).html( $.inlineEditor.states[$.inlineEditor.currentState].html ); |
56 | | - $( '.lastEdit' ).removeClass( 'lastEdit' ); |
57 | | - $( '#' + state.partialHtml.id ).replaceWith( state.partialHtml.html ); |
| 13 | + /** |
| 14 | + * Adds the initial state from the current HTML and a wiki string. |
| 15 | + */ |
| 16 | + addInitialState: function( state ) { |
| 17 | + $.inlineEditor.currentState = 0; |
| 18 | + $.inlineEditor.states[$.inlineEditor.currentState] = { |
| 19 | + 'object': state.object, |
| 20 | + 'texts': state.texts, |
| 21 | + 'html': $( '#editContent' ).html() |
| 22 | + }; |
| 23 | + }, |
58 | 24 | |
59 | | - // add the new state |
60 | | - $.inlineEditor.currentState += 1; |
61 | | - $.inlineEditor.states[$.inlineEditor.currentState] = { |
62 | | - 'object': state.object, |
63 | | - 'texts': state.texts, |
64 | | - 'html': $( '#editContent' ).html() |
65 | | - }; |
| 25 | + /** |
| 26 | + * Returns wikitext in the current state given an ID. |
| 27 | + */ |
| 28 | + getTextById: function( id ) { |
| 29 | + return $.inlineEditor.states[$.inlineEditor.currentState].texts[id]; |
| 30 | + }, |
66 | 31 | |
67 | | - // clear out all states after the current state, because undo/redo would be broken |
68 | | - var i = $.inlineEditor.currentState + 1; |
69 | | - while( i <= $.inlineEditor.lastState ) { |
70 | | - delete $.inlineEditor.states[i]; |
71 | | - i += 1; |
72 | | - } |
73 | | - $.inlineEditor.lastState = $.inlineEditor.currentState; |
| 32 | + /** |
| 33 | + * Previews given a new text for a given field by ID. |
| 34 | + */ |
| 35 | + previewTextById: function( text, id ) { |
| 36 | + // send out an AJAX request which will be handled by addNewState() |
| 37 | + var data = { |
| 38 | + 'object': $.inlineEditor.states[$.inlineEditor.currentState].object, |
| 39 | + 'lastEdit': { 'id': id, 'text': text } |
| 40 | + }; |
| 41 | + |
| 42 | + var args = [ JSON.stringify( data ), wgPageName ]; |
| 43 | + sajax_request_type = 'POST'; |
| 44 | + sajax_do_call( 'InlineEditor::ajaxPreview', args, $.inlineEditor.addNewState ); |
| 45 | + }, |
74 | 46 | |
75 | | - // reload the current editor and update the edit counter |
76 | | - $.inlineEditor.reload(); |
77 | | - $.inlineEditor.updateEditCounter(); |
78 | | -}, |
79 | | - |
80 | | -/** |
81 | | - * Reloads the current editor and finish some things in the HTML. |
82 | | - */ |
83 | | -reload: function() { |
84 | | - $.inlineEditor.basicEditor.cancelAll(); |
| 47 | + /** |
| 48 | + * Adds a new state from an AJAX request. |
| 49 | + */ |
| 50 | + addNewState: function( request ) { |
| 51 | + var state = JSON.parse( request.responseText ); |
| 52 | + |
| 53 | + // restore the html to the current state, instantly remove the lastEdit, |
| 54 | + // and then add the new html |
| 55 | + $( '#editContent' ).html( $.inlineEditor.states[$.inlineEditor.currentState].html ); |
| 56 | + $( '.lastEdit' ).removeClass( 'lastEdit' ); |
| 57 | + $( '#' + state.partialHtml.id ).replaceWith( state.partialHtml.html ); |
| 58 | + |
| 59 | + // add the new state |
| 60 | + $.inlineEditor.currentState += 1; |
| 61 | + $.inlineEditor.states[$.inlineEditor.currentState] = { |
| 62 | + 'object': state.object, |
| 63 | + 'texts': state.texts, |
| 64 | + 'html': $( '#editContent' ).html() |
| 65 | + }; |
| 66 | + |
| 67 | + // clear out all states after the current state, because undo/redo would be broken |
| 68 | + var i = $.inlineEditor.currentState + 1; |
| 69 | + while( i <= $.inlineEditor.lastState ) { |
| 70 | + delete $.inlineEditor.states[i]; |
| 71 | + i += 1; |
| 72 | + } |
| 73 | + $.inlineEditor.lastState = $.inlineEditor.currentState; |
| 74 | + |
| 75 | + // reload the current editor and update the edit counter |
| 76 | + $.inlineEditor.reload(); |
| 77 | + $.inlineEditor.updateEditCounter(); |
| 78 | + }, |
85 | 79 | |
86 | | - // bind all events of the basic editor |
87 | | - $.inlineEditor.basicEditor.bindEvents( $( '.inlineEditorElement' ) ); |
| 80 | + /** |
| 81 | + * Reloads the current editor and finish some things in the HTML. |
| 82 | + */ |
| 83 | + reload: function() { |
| 84 | + $.inlineEditor.basicEditor.cancelAll(); |
| 85 | + |
| 86 | + // bind all events of the basic editor |
| 87 | + $.inlineEditor.basicEditor.bindEvents( $( '.inlineEditorElement' ) ); |
| 88 | + |
| 89 | + // reload the specific editors |
| 90 | + for( var optionNr in $.inlineEditor.editors ) { |
| 91 | + $.inlineEditor.editors[optionNr].reload(); |
| 92 | + } |
| 93 | + |
| 94 | + // remove all lastEdit elements |
| 95 | + $('.lastEdit').removeClass( 'lastEdit' ); |
| 96 | + |
| 97 | + // make the links in the article unusable |
| 98 | + $( '#editContent a' ).click( function( event ) { event.preventDefault(); } ); |
| 99 | + }, |
88 | 100 | |
89 | | - // reload the specific editors |
90 | | - for( var optionNr in $.inlineEditor.editors) { |
91 | | - $.inlineEditor.editors[optionNr].reload(); |
92 | | - } |
| 101 | + /** |
| 102 | + * Moves back one state. |
| 103 | + */ |
| 104 | + undo: function( event ) { |
| 105 | + event.stopPropagation(); |
| 106 | + event.preventDefault(); |
| 107 | + |
| 108 | + // check if we can move backward one state and do it |
| 109 | + if( $.inlineEditor.currentState > 0 ) { |
| 110 | + $.inlineEditor.currentState -= 1; |
| 111 | + $( '#editContent' ).html( $.inlineEditor.states[$.inlineEditor.currentState].html ); |
| 112 | + $.inlineEditor.reload(); |
| 113 | + } |
| 114 | + |
| 115 | + // refresh the edit counter regardless of actually switching, this confirms |
| 116 | + // that the button works, even if there is nothing to switch to |
| 117 | + $.inlineEditor.updateEditCounter(); |
| 118 | + }, |
93 | 119 | |
94 | | - // remove all lastEdit elements |
95 | | - $('.lastEdit').removeClass( 'lastEdit' ); |
| 120 | + /** |
| 121 | + * Moves forward one state. |
| 122 | + */ |
| 123 | + redo: function( event ) { |
| 124 | + event.stopPropagation(); |
| 125 | + event.preventDefault(); |
| 126 | + |
| 127 | + // check if we can move forward one state and do it |
| 128 | + if( $.inlineEditor.currentState < $.inlineEditor.lastState ) { |
| 129 | + $.inlineEditor.currentState += 1; |
| 130 | + $('#editContent').html( $.inlineEditor.states[$.inlineEditor.currentState].html ); |
| 131 | + $.inlineEditor.reload(); |
| 132 | + } |
| 133 | + |
| 134 | + // refresh the edit counter regardless of actually switching, this confirms |
| 135 | + // that the button works, even if there is nothing to switch to |
| 136 | + $.inlineEditor.updateEditCounter(); |
| 137 | + }, |
96 | 138 | |
97 | | - // make the links in the article unusable |
98 | | - $( '#editContent a' ).click( function( event ) { event.preventDefault(); } ); |
99 | | -}, |
100 | | - |
101 | | -/** |
102 | | - * Moves back one state. |
103 | | - */ |
104 | | -undo: function( event ) { |
105 | | - event.stopPropagation(); |
106 | | - event.preventDefault(); |
| 139 | + /** |
| 140 | + * Updates the edit counter and makes it flash. |
| 141 | + */ |
| 142 | + updateEditCounter: function() { |
| 143 | + // update the value of the edit counter |
| 144 | + var $editCounter = $( '#editCounter' ); |
| 145 | + $editCounter.text( '#' + $.inlineEditor.currentState ); |
| 146 | + |
| 147 | + // remove everything from the editcounter, and have it fade again |
| 148 | + $editCounter.removeClass( 'changeHighlight' ); |
| 149 | + $editCounter.attr( 'style', '' ); |
| 150 | + $editCounter.addClass( 'changeHighlight' ); |
| 151 | + $editCounter.removeClass( 'changeHighlight', 200 ); |
| 152 | + }, |
107 | 153 | |
108 | | - // check if we can move backward one state and do it |
109 | | - if( $.inlineEditor.currentState > 0 ) { |
110 | | - $.inlineEditor.currentState -= 1; |
111 | | - $( '#editContent' ).html( $.inlineEditor.states[$.inlineEditor.currentState].html ); |
112 | | - $.inlineEditor.reload(); |
113 | | - } |
| 154 | + /** |
| 155 | + * Publishes the document in its current state. |
| 156 | + */ |
| 157 | + publish: function( event ) { |
| 158 | + event.stopPropagation(); |
| 159 | + event.preventDefault(); |
| 160 | + |
| 161 | + // get the wikitext from the state as it's currently on the screen |
| 162 | + var data = { |
| 163 | + 'object': $.inlineEditor.states[$.inlineEditor.currentState].object |
| 164 | + }; |
| 165 | + var json = JSON.stringify( data ); |
| 166 | + |
| 167 | + // set and send the form |
| 168 | + $( '#json' ).val( json ); |
| 169 | + $( '#editForm' ).submit(); |
| 170 | + }, |
114 | 171 | |
115 | | - // refresh the edit counter regardless of actually switching, this confirms |
116 | | - // that the button works, even if there is nothing to switch to |
117 | | - $.inlineEditor.updateEditCounter(); |
118 | | -}, |
119 | | - |
120 | | -/** |
121 | | - * Moves forward one state. |
122 | | - */ |
123 | | -redo: function( event ) { |
124 | | - event.stopPropagation(); |
125 | | - event.preventDefault(); |
126 | | - |
127 | | - // check if we can move forward one state and do it |
128 | | - if( $.inlineEditor.currentState < $.inlineEditor.lastState ) { |
129 | | - $.inlineEditor.currentState += 1; |
130 | | - $('#editContent').html( $.inlineEditor.states[$.inlineEditor.currentState].html ); |
| 172 | + /** |
| 173 | + * Initializes the editor. |
| 174 | + */ |
| 175 | + init : function() { |
| 176 | + $( '#publish' ).click( $.inlineEditor.publish ); |
| 177 | + //$( '#undo' ).click( $.inlineEditor.undo ); |
| 178 | + //$( '#redo' ).click( $.inlineEditor.redo ); |
| 179 | + |
| 180 | + // reload the current editor |
131 | 181 | $.inlineEditor.reload(); |
132 | 182 | } |
133 | | - |
134 | | - // refresh the edit counter regardless of actually switching, this confirms |
135 | | - // that the button works, even if there is nothing to switch to |
136 | | - $.inlineEditor.updateEditCounter(); |
137 | | -}, |
138 | 183 | |
139 | | -/** |
140 | | - * Updates the edit counter and makes it flash. |
141 | | - */ |
142 | | -updateEditCounter: function() { |
143 | | - // update the value of the edit counter |
144 | | - var $editCounter = $( '#editCounter' ); |
145 | | - $editCounter.text( '#' + $.inlineEditor.currentState ); |
146 | | - |
147 | | - // remove everything from the editcounter, and have it fade again |
148 | | - $editCounter.removeClass( 'changeHighlight' ); |
149 | | - $editCounter.attr( 'style', '' ); |
150 | | - $editCounter.addClass( 'changeHighlight' ); |
151 | | - $editCounter.removeClass( 'changeHighlight', 200 ); |
152 | | -}, |
153 | | - |
154 | | -/** |
155 | | - * Publishes the document in its current state. |
156 | | - */ |
157 | | -publish: function( event ) { |
158 | | - event.stopPropagation(); |
159 | | - event.preventDefault(); |
160 | | - |
161 | | - // get the wikitext from the state as it's currently on the screen |
162 | | - var data = { |
163 | | - 'object': $.inlineEditor.states[$.inlineEditor.currentState].object |
164 | | - }; |
165 | | - var json = JSON.stringify( data ); |
166 | | - |
167 | | - // set and send the form |
168 | | - $( '#json' ).val( json ); |
169 | | - $( '#editForm' ).submit(); |
170 | | -}, |
171 | | - |
172 | | -/** |
173 | | - * Initializes the editor. |
174 | | - */ |
175 | | -init : function() { |
176 | | - $( '#publish' ).click( $.inlineEditor.publish ); |
177 | | - //$( '#undo' ).click( $.inlineEditor.undo ); |
178 | | - //$( '#redo' ).click( $.inlineEditor.redo ); |
179 | | - |
180 | | - // reload the current editor |
181 | | - $.inlineEditor.reload(); |
182 | | -} |
183 | | - |
184 | 184 | }; } ) ( jQuery ); |
\ No newline at end of file |