Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -72,19 +72,19 @@ |
73 | 73 | array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 6 ), |
74 | 74 | array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 21 ), |
75 | 75 | array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 36 ), |
76 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 3 ), |
| 76 | + array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 5 ), |
77 | 77 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 40 ), |
78 | 78 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 10 ), |
79 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 54 ), |
| 79 | + array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 52 ), |
80 | 80 | array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 8 ), |
81 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 3 ), |
| 81 | + array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 5 ), |
82 | 82 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 1 ), |
83 | 83 | ), |
84 | 84 | 'combined' => array( |
85 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 114 ), |
| 85 | + array( 'src' => 'js/plugins.combined.js', 'version' => 115 ), |
86 | 86 | ), |
87 | 87 | 'minified' => array( |
88 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 114 ), |
| 88 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 115 ), |
89 | 89 | ), |
90 | 90 | ), |
91 | 91 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js |
— | — | @@ -6,59 +6,39 @@ |
7 | 7 | */ |
8 | 8 | evt: { |
9 | 9 | mark: function( context, event ) { |
10 | | - // This is shared by both the closure findOutermostTemplates and the calling code - is this a good idea? |
11 | | - var tokenIterator = 0; |
12 | | - /** |
13 | | - * Finds the left and right character positions of the outer-most template declaration, playing nicely with |
14 | | - * nested template calls of any depth. This function acts as an iterator, which is why the i var is shared - but |
15 | | - * this seems a bit scary seeing as 'i' is so often used in loops. |
16 | | - * |
17 | | - * @param tokenStack Array of tokens to find boundries within |
18 | | - */ |
19 | | - function findOutermostTemplates( tokenStack ) { |
20 | | - var templateBeginFound = false; |
21 | | - for ( ; tokenIterator < tokenStack.length; tokenIterator++ ) { |
22 | | - if ( tokenStack[tokenIterator].label == 'TEMPLATE_BEGIN' ) { |
23 | | - templateBeginFound = true; |
24 | | - break; |
| 10 | + // Get refrences to the markers and tokens from the current context |
| 11 | + var markers = context.modules.highlight.markers; |
| 12 | + var tokenArray = context.modules.highlight.tokenArray; |
| 13 | + // Collect matching level 0 template call boundries from the tokenArrray |
| 14 | + var level = 0; |
| 15 | + var boundries = []; |
| 16 | + var boundry = 0; |
| 17 | + for ( token in tokenArray ) { |
| 18 | + if ( tokenArray[token].label == 'TEMPLATE_BEGIN' ) { |
| 19 | + if ( level++ == 0 ) { |
| 20 | + boundry = boundries.push( { 'begin': tokenArray[token].offset } ) - 1; |
25 | 21 | } |
| 22 | + } else if ( tokenArray[token].label == 'TEMPLATE_END' ) { |
| 23 | + if ( --level == 0 ) { |
| 24 | + boundries[boundry].end = tokenArray[token].offset; |
| 25 | + } |
26 | 26 | } |
27 | | - var j = tokenIterator++; |
28 | | - if ( !templateBeginFound ) { |
29 | | - return false; |
30 | | - } else { |
31 | | - // This is only designed to find the outermost template boundaries, the model handles nested template |
32 | | - // and template-like objects better |
33 | | - var nestedBegins = 1; |
34 | | - while ( nestedBegins > 0 && j < tokenStack.length ) { |
35 | | - var label = tokenStack[++j].label; |
36 | | - nestedBegins += label == 'TEMPLATE_END' ? -1 : label == 'TEMPLATE_BEGIN' ? 1 : 0; |
| 27 | + } |
| 28 | + // Add encapsulations to markers at the offsets of matching sets of level 0 template call boundries |
| 29 | + for ( boundry in boundries ) { |
| 30 | + if ( 'begin' in boundries[boundry] && 'end' in boundries[boundry] ) { |
| 31 | + // Ensure arrays exist at the begining and ending offsets for boundry |
| 32 | + if ( !( boundries[boundry].begin in markers ) ) { |
| 33 | + markers[boundries[boundry].begin] = []; |
37 | 34 | } |
38 | | - if ( nestedBegins == 0 ) { |
39 | | - // Outer template begins at tokenStack[i].offset and ends at tokenStack[j].offset + 2 |
40 | | - var leftMarker = tokenIterator -1; |
41 | | - var rightMarker = j; |
42 | | - tokenIterator = j; |
43 | | - return [leftMarker, rightMarker]; |
44 | | - } else { |
45 | | - return false; |
| 35 | + if ( !( boundries[boundry].end in markers ) ) { |
| 36 | + markers[boundries[boundry].end] = []; |
46 | 37 | } |
| 38 | + // Append boundry markers |
| 39 | + markers[boundries[boundry].begin].push( "<div class='wiki-template'>" ); |
| 40 | + markers[boundries[boundry].end].push( "</div>" ); |
| 41 | + |
47 | 42 | } |
48 | | - }; |
49 | | - // Get the markers and tokens from the current context |
50 | | - var markers = context.modules.highlight.markers; |
51 | | - var tokenStack = context.modules.highlight.tokenArray; |
52 | | - // Scan through and detect the boundries of template calls |
53 | | - var templateBeginFound = false; |
54 | | - var templateBoundaries; |
55 | | - while ( templateBoundaries = findOutermostTemplates( tokenStack ) ) { |
56 | | - context.modules.highlight.markers.push( { |
57 | | - start: tokenStack[templateBoundaries[0]].offset, |
58 | | - end: tokenStack[templateBoundaries[1]].offset, |
59 | | - wrapElement: function() { |
60 | | - return $( '<div />' ).addClass( 'wikiEditor-highlight-template' ); |
61 | | - } |
62 | | - } ); |
63 | 43 | } |
64 | 44 | } |
65 | 45 | }, |
— | — | @@ -90,69 +70,6 @@ |
91 | 71 | model: function( wikitext ) { |
92 | 72 | |
93 | 73 | /* 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 | | - }, |
157 | 74 | |
158 | 75 | /** |
159 | 76 | * Builds a Param object. |
— | — | @@ -373,15 +290,17 @@ |
374 | 291 | valueEndIndex = valueEnd.index + oldDivider + 2; |
375 | 292 | ranges.push( new Range( ranges[ranges.length-1].end, |
376 | 293 | valueBeginIndex ) ); //all the chars upto now |
377 | | - nameIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ); |
378 | | - nameIndex--; |
379 | | - equalsIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ); |
380 | | - equalsIndex--; |
381 | | - valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ); |
382 | | - valueIndex--; |
383 | | - params.push( new Param( currentParamNumber, |
| 294 | + nameIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ) - 1; |
| 295 | + equalsIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ) - 1; |
| 296 | + valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ) - 1; |
| 297 | + params.push( new Param( |
| 298 | + currentParamNumber, |
384 | 299 | wikitext.substring( ranges[valueIndex].begin, ranges[valueIndex].end ), |
385 | | - currentParamNumber, nameIndex, equalsIndex, valueIndex ) ); |
| 300 | + currentParamNumber, |
| 301 | + nameIndex, |
| 302 | + equalsIndex, |
| 303 | + valueIndex |
| 304 | + ) ); |
386 | 305 | paramsByName[currentParamNumber] = currentParamNumber; |
387 | 306 | } else { |
388 | 307 | // There's an equals, could be comment or a value pair |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js |
— | — | @@ -40,7 +40,6 @@ |
41 | 41 | 'type': 'text/css', |
42 | 42 | 'href': wgScriptPath + '/extensions/UsabilityInitiative/css/wikiEditor.highlight.css', |
43 | 43 | } ) ); |
44 | | - |
45 | 44 | // Highlight stuff for the first time |
46 | 45 | $.wikiEditor.modules.highlight.fn.scan( context, "" ); |
47 | 46 | $.wikiEditor.modules.highlight.fn.mark( context, "", "" ); |
— | — | @@ -99,8 +98,9 @@ |
100 | 99 | this.offset = offset; |
101 | 100 | this.label = label; |
102 | 101 | } |
| 102 | + // Reset tokens |
| 103 | + var tokenArray = context.modules.highlight.tokenArray = []; |
103 | 104 | // We need to look over some text and find interesting areas, then return the positions of those areas as tokens |
104 | | - context.modules.highlight.tokenArray = []; |
105 | 105 | var text = context.fn.getContents(); |
106 | 106 | for ( module in $.wikiEditor.modules ) { |
107 | 107 | if ( 'exp' in $.wikiEditor.modules[module] ) { |
— | — | @@ -118,7 +118,7 @@ |
119 | 119 | if ( markAfter ) { |
120 | 120 | markOffset += match[0].length; |
121 | 121 | } |
122 | | - context.modules.highlight.tokenArray.push( |
| 122 | + tokenArray.push( |
123 | 123 | new Token( match.index + oldOffset + markOffset, label ) |
124 | 124 | ); |
125 | 125 | oldOffset += match.index + match[0].length; |
— | — | @@ -128,9 +128,8 @@ |
129 | 129 | } |
130 | 130 | } |
131 | 131 | } |
132 | | - |
133 | | - context.modules.highlight.tokenArray.sort( function( a, b ) { return a.offset - b.offset; } ); |
134 | | - return context.modules.highlight.tokenArray; // array of tokens |
| 132 | + tokenArray.sort( function( a, b ) { return a.offset - b.offset; } ); |
| 133 | + context.fn.trigger( 'scan' ); |
135 | 134 | }, |
136 | 135 | /** |
137 | 136 | * Marks up text with HTML |
— | — | @@ -140,26 +139,19 @@ |
141 | 140 | */ |
142 | 141 | // FIXME: What do division and tokens do? |
143 | 142 | mark: function( context, division, tokens ) { |
| 143 | + // Reset markers |
| 144 | + var markers = context.modules.highlight.markers = []; |
144 | 145 | // Get all markers |
145 | | - context.modules.highlight.markers = []; |
146 | | - for ( module in $.wikiEditor.modules ) { |
147 | | - if ( 'evt' in $.wikiEditor.modules[module] && 'mark' in $.wikiEditor.modules[module].evt ) { |
148 | | - $.wikiEditor.modules[module].evt.mark( context ); // FIXME: event? |
149 | | - } |
150 | | - } |
151 | | - var markers = context.modules.highlight.markers; |
| 146 | + context.fn.trigger( 'mark' ); |
152 | 147 | markers.sort( function( a, b ) { return a.start - b.start || a.end - b.end; } ); |
153 | | - |
154 | | - // Traverse the iframe DOM, inserting markers where they're needed |
155 | | - // The loop traverses all leaf nodes in the DOM, and uses DOM methods |
156 | | - // rather than jQuery because it has to work with text nodes and for performance |
| 148 | + // Traverse the iframe DOM, inserting markers where they're needed. The loop traverses all leaf nodes in the |
| 149 | + // DOM, and uses DOM methods rather than jQuery because it has to work with text nodes and for performance. |
157 | 150 | var pos = 0; |
158 | 151 | var node = context.$content.get( 0 ); |
159 | 152 | var next = null; |
160 | 153 | var i = 0; // index for markers[] |
161 | 154 | var startNode = null; |
162 | 155 | var depth = 0, nextDepth = 0, startDepth = null; |
163 | | - |
164 | 156 | // Find the leftmost leaf node in the tree |
165 | 157 | while ( node.firstChild ) { |
166 | 158 | node = node.firstChild; |
— | — | @@ -179,17 +171,16 @@ |
180 | 172 | nextDepth++; |
181 | 173 | } |
182 | 174 | next = p; |
183 | | - |
184 | 175 | if ( node.nodeName != '#text' ) { |
185 | | - if ( node.nodeName == 'BR' ) |
| 176 | + if ( node.nodeName == 'BR' ) { |
186 | 177 | pos++; |
| 178 | + } |
187 | 179 | // Skip this node |
188 | 180 | node = next; |
189 | 181 | depth = nextDepth; |
190 | 182 | continue; |
191 | 183 | } |
192 | 184 | var newPos = pos + node.nodeValue.length; |
193 | | - |
194 | 185 | // We want to isolate each marker, so we may need to split textNodes |
195 | 186 | // if a marker starts or end halfway one. |
196 | 187 | if ( !startNode && markers[i].start >= pos && markers[i].start < newPos ) { |
— | — | @@ -204,30 +195,22 @@ |
205 | 196 | startNode = node; |
206 | 197 | startDepth = depth; |
207 | 198 | } |
208 | | - |
209 | 199 | // TODO: What happens when wrapping a zero-length string? |
210 | 200 | // TODO: Detect that something's already been wrapped and leave it alone |
211 | 201 | if ( startNode && markers[i].end > pos && markers[i].end <= newPos ) { |
212 | 202 | // The marker ends somewhere in this textNode |
213 | 203 | if ( markers[i].end < newPos ) { |
214 | | - // Split off the suffix |
215 | | - // This puts the suffix in a new node and leaves the rest |
216 | | - // in the current node. We have to make sure the split-off |
217 | | - // node will be visited correctly |
218 | | - |
| 204 | + // Split off the suffix - This puts the suffix in a new node and leaves the rest in the current |
| 205 | + // node. We have to make sure the split-off node will be visited correctly |
219 | 206 | // node.nodeValue.length - ( newPos - markers[i].end ) |
220 | 207 | next = node.splitText( node.nodeValue.length - newPos + markers[i].end ); |
221 | 208 | newPos = markers[i].end; |
222 | 209 | } |
223 | | - |
224 | | - // Now wrap everything between startNode and node (may be equal). |
225 | | - // First find the common ancestor of startNode and node. |
226 | | - // ca1 and ca2 will be children of this common ancestor, such that |
227 | | - // ca1 is an ancestor of startNode and ca2 of node. |
228 | | - // We also check that startNode and node are the leftmost and rightmost |
229 | | - // leaves in the subtrees rooted at ca1 and ca2 respectively; if this is |
230 | | - // not the case, we can't cleanly wrap things without misnesting and we |
231 | | - // silently fail. |
| 210 | + // Now wrap everything between startNode and node (may be equal). First find the common ancestor of |
| 211 | + // startNode and node. ca1 and ca2 will be children of this common ancestor, such that ca1 is an |
| 212 | + // ancestor of startNode and ca2 of node. We also check that startNode and node are the leftmost and |
| 213 | + // rightmost leaves in the subtrees rooted at ca1 and ca2 respectively; if this is not the case, we |
| 214 | + // can't cleanly wrap things without misnesting and we silently fail. |
232 | 215 | var ca1 = startNode, ca2 = node; |
233 | 216 | // Correct for startNode and node possibly not having the same depth |
234 | 217 | if ( startDepth > depth ) { |
— | — | @@ -249,38 +232,37 @@ |
250 | 233 | ca2 = ca2.parentNode; |
251 | 234 | } |
252 | 235 | } |
253 | | - |
254 | 236 | if ( ca1 && ca2 ) { |
255 | | - // We have to store things like .parentNode and .nextSibling |
256 | | - // because appendChild() changes these properties |
| 237 | + // We have to store things like .parentNode and .nextSibling because appendChild() changes these |
| 238 | + // properties |
257 | 239 | var newNode = markers[i].wrapElement; |
258 | | - if ( typeof newNode == 'function' ) |
| 240 | + if ( typeof newNode == 'function' ) { |
259 | 241 | newNode = newNode(); |
260 | | - if ( newNode.jquery ) |
| 242 | + } |
| 243 | + if ( newNode.jquery ) { |
261 | 244 | newNode = newNode.get( 0 ); |
| 245 | + } |
262 | 246 | var commonAncestor = ca1.parentNode; |
263 | 247 | var nextNode = ca2.nextSibling; |
264 | | - |
265 | | - // Append all nodes between ca1 and ca2 (inclusive) |
266 | | - // to newNode |
| 248 | + // Append all nodes between ca1 and ca2 (inclusive) to newNode |
267 | 249 | var n = ca1; |
268 | 250 | while ( n != nextNode ) { |
269 | 251 | var ns = n.nextSibling; |
270 | 252 | newNode.appendChild( n ); |
271 | 253 | n = ns; |
272 | 254 | } |
273 | | - |
274 | 255 | // Insert newNode in the right place |
275 | | - if ( nextNode ) |
| 256 | + if ( nextNode ) { |
276 | 257 | commonAncestor.insertBefore( newNode, nextNode ); |
277 | | - else |
| 258 | + } else { |
278 | 259 | commonAncestor.appendChild( newNode ); |
| 260 | + } |
279 | 261 | } |
280 | | - startNode = null; // Clear for next iteration |
| 262 | + // Clear for next iteration |
| 263 | + startNode = null; |
281 | 264 | startDepth = null; |
282 | 265 | i++; |
283 | 266 | } |
284 | | - |
285 | 267 | pos = newPos; |
286 | 268 | node = next; |
287 | 269 | depth = nextDepth; |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -2168,7 +2168,6 @@ |
2169 | 2169 | 'type': 'text/css', |
2170 | 2170 | 'href': wgScriptPath + '/extensions/UsabilityInitiative/css/wikiEditor.highlight.css', |
2171 | 2171 | } ) ); |
2172 | | - |
2173 | 2172 | // Highlight stuff for the first time |
2174 | 2173 | $.wikiEditor.modules.highlight.fn.scan( context, "" ); |
2175 | 2174 | $.wikiEditor.modules.highlight.fn.mark( context, "", "" ); |
— | — | @@ -2227,8 +2226,9 @@ |
2228 | 2227 | this.offset = offset; |
2229 | 2228 | this.label = label; |
2230 | 2229 | } |
| 2230 | + // Reset tokens |
| 2231 | + var tokenArray = context.modules.highlight.tokenArray = []; |
2231 | 2232 | // We need to look over some text and find interesting areas, then return the positions of those areas as tokens |
2232 | | - context.modules.highlight.tokenArray = []; |
2233 | 2233 | var text = context.fn.getContents(); |
2234 | 2234 | for ( module in $.wikiEditor.modules ) { |
2235 | 2235 | if ( 'exp' in $.wikiEditor.modules[module] ) { |
— | — | @@ -2246,7 +2246,7 @@ |
2247 | 2247 | if ( markAfter ) { |
2248 | 2248 | markOffset += match[0].length; |
2249 | 2249 | } |
2250 | | - context.modules.highlight.tokenArray.push( |
| 2250 | + tokenArray.push( |
2251 | 2251 | new Token( match.index + oldOffset + markOffset, label ) |
2252 | 2252 | ); |
2253 | 2253 | oldOffset += match.index + match[0].length; |
— | — | @@ -2256,9 +2256,8 @@ |
2257 | 2257 | } |
2258 | 2258 | } |
2259 | 2259 | } |
2260 | | - |
2261 | | - context.modules.highlight.tokenArray.sort( function( a, b ) { return a.offset - b.offset; } ); |
2262 | | - return context.modules.highlight.tokenArray; // array of tokens |
| 2260 | + tokenArray.sort( function( a, b ) { return a.offset - b.offset; } ); |
| 2261 | + context.fn.trigger( 'scan' ); |
2263 | 2262 | }, |
2264 | 2263 | /** |
2265 | 2264 | * Marks up text with HTML |
— | — | @@ -2268,26 +2267,19 @@ |
2269 | 2268 | */ |
2270 | 2269 | // FIXME: What do division and tokens do? |
2271 | 2270 | mark: function( context, division, tokens ) { |
| 2271 | + // Reset markers |
| 2272 | + var markers = context.modules.highlight.markers = []; |
2272 | 2273 | // Get all markers |
2273 | | - context.modules.highlight.markers = []; |
2274 | | - for ( module in $.wikiEditor.modules ) { |
2275 | | - if ( 'evt' in $.wikiEditor.modules[module] && 'mark' in $.wikiEditor.modules[module].evt ) { |
2276 | | - $.wikiEditor.modules[module].evt.mark( context ); // FIXME: event? |
2277 | | - } |
2278 | | - } |
2279 | | - var markers = context.modules.highlight.markers; |
| 2274 | + context.fn.trigger( 'mark' ); |
2280 | 2275 | markers.sort( function( a, b ) { return a.start - b.start || a.end - b.end; } ); |
2281 | | - |
2282 | | - // Traverse the iframe DOM, inserting markers where they're needed |
2283 | | - // The loop traverses all leaf nodes in the DOM, and uses DOM methods |
2284 | | - // rather than jQuery because it has to work with text nodes and for performance |
| 2276 | + // Traverse the iframe DOM, inserting markers where they're needed. The loop traverses all leaf nodes in the |
| 2277 | + // DOM, and uses DOM methods rather than jQuery because it has to work with text nodes and for performance. |
2285 | 2278 | var pos = 0; |
2286 | 2279 | var node = context.$content.get( 0 ); |
2287 | 2280 | var next = null; |
2288 | 2281 | var i = 0; // index for markers[] |
2289 | 2282 | var startNode = null; |
2290 | 2283 | var depth = 0, nextDepth = 0, startDepth = null; |
2291 | | - |
2292 | 2284 | // Find the leftmost leaf node in the tree |
2293 | 2285 | while ( node.firstChild ) { |
2294 | 2286 | node = node.firstChild; |
— | — | @@ -2307,17 +2299,16 @@ |
2308 | 2300 | nextDepth++; |
2309 | 2301 | } |
2310 | 2302 | next = p; |
2311 | | - |
2312 | 2303 | if ( node.nodeName != '#text' ) { |
2313 | | - if ( node.nodeName == 'BR' ) |
| 2304 | + if ( node.nodeName == 'BR' ) { |
2314 | 2305 | pos++; |
| 2306 | + } |
2315 | 2307 | // Skip this node |
2316 | 2308 | node = next; |
2317 | 2309 | depth = nextDepth; |
2318 | 2310 | continue; |
2319 | 2311 | } |
2320 | 2312 | var newPos = pos + node.nodeValue.length; |
2321 | | - |
2322 | 2313 | // We want to isolate each marker, so we may need to split textNodes |
2323 | 2314 | // if a marker starts or end halfway one. |
2324 | 2315 | if ( !startNode && markers[i].start >= pos && markers[i].start < newPos ) { |
— | — | @@ -2332,30 +2323,22 @@ |
2333 | 2324 | startNode = node; |
2334 | 2325 | startDepth = depth; |
2335 | 2326 | } |
2336 | | - |
2337 | 2327 | // TODO: What happens when wrapping a zero-length string? |
2338 | 2328 | // TODO: Detect that something's already been wrapped and leave it alone |
2339 | 2329 | if ( startNode && markers[i].end > pos && markers[i].end <= newPos ) { |
2340 | 2330 | // The marker ends somewhere in this textNode |
2341 | 2331 | if ( markers[i].end < newPos ) { |
2342 | | - // Split off the suffix |
2343 | | - // This puts the suffix in a new node and leaves the rest |
2344 | | - // in the current node. We have to make sure the split-off |
2345 | | - // node will be visited correctly |
2346 | | - |
| 2332 | + // Split off the suffix - This puts the suffix in a new node and leaves the rest in the current |
| 2333 | + // node. We have to make sure the split-off node will be visited correctly |
2347 | 2334 | // node.nodeValue.length - ( newPos - markers[i].end ) |
2348 | 2335 | next = node.splitText( node.nodeValue.length - newPos + markers[i].end ); |
2349 | 2336 | newPos = markers[i].end; |
2350 | 2337 | } |
2351 | | - |
2352 | | - // Now wrap everything between startNode and node (may be equal). |
2353 | | - // First find the common ancestor of startNode and node. |
2354 | | - // ca1 and ca2 will be children of this common ancestor, such that |
2355 | | - // ca1 is an ancestor of startNode and ca2 of node. |
2356 | | - // We also check that startNode and node are the leftmost and rightmost |
2357 | | - // leaves in the subtrees rooted at ca1 and ca2 respectively; if this is |
2358 | | - // not the case, we can't cleanly wrap things without misnesting and we |
2359 | | - // silently fail. |
| 2338 | + // Now wrap everything between startNode and node (may be equal). First find the common ancestor of |
| 2339 | + // startNode and node. ca1 and ca2 will be children of this common ancestor, such that ca1 is an |
| 2340 | + // ancestor of startNode and ca2 of node. We also check that startNode and node are the leftmost and |
| 2341 | + // rightmost leaves in the subtrees rooted at ca1 and ca2 respectively; if this is not the case, we |
| 2342 | + // can't cleanly wrap things without misnesting and we silently fail. |
2360 | 2343 | var ca1 = startNode, ca2 = node; |
2361 | 2344 | // Correct for startNode and node possibly not having the same depth |
2362 | 2345 | if ( startDepth > depth ) { |
— | — | @@ -2377,38 +2360,37 @@ |
2378 | 2361 | ca2 = ca2.parentNode; |
2379 | 2362 | } |
2380 | 2363 | } |
2381 | | - |
2382 | 2364 | if ( ca1 && ca2 ) { |
2383 | | - // We have to store things like .parentNode and .nextSibling |
2384 | | - // because appendChild() changes these properties |
| 2365 | + // We have to store things like .parentNode and .nextSibling because appendChild() changes these |
| 2366 | + // properties |
2385 | 2367 | var newNode = markers[i].wrapElement; |
2386 | | - if ( typeof newNode == 'function' ) |
| 2368 | + if ( typeof newNode == 'function' ) { |
2387 | 2369 | newNode = newNode(); |
2388 | | - if ( newNode.jquery ) |
| 2370 | + } |
| 2371 | + if ( newNode.jquery ) { |
2389 | 2372 | newNode = newNode.get( 0 ); |
| 2373 | + } |
2390 | 2374 | var commonAncestor = ca1.parentNode; |
2391 | 2375 | var nextNode = ca2.nextSibling; |
2392 | | - |
2393 | | - // Append all nodes between ca1 and ca2 (inclusive) |
2394 | | - // to newNode |
| 2376 | + // Append all nodes between ca1 and ca2 (inclusive) to newNode |
2395 | 2377 | var n = ca1; |
2396 | 2378 | while ( n != nextNode ) { |
2397 | 2379 | var ns = n.nextSibling; |
2398 | 2380 | newNode.appendChild( n ); |
2399 | 2381 | n = ns; |
2400 | 2382 | } |
2401 | | - |
2402 | 2383 | // Insert newNode in the right place |
2403 | | - if ( nextNode ) |
| 2384 | + if ( nextNode ) { |
2404 | 2385 | commonAncestor.insertBefore( newNode, nextNode ); |
2405 | | - else |
| 2386 | + } else { |
2406 | 2387 | commonAncestor.appendChild( newNode ); |
| 2388 | + } |
2407 | 2389 | } |
2408 | | - startNode = null; // Clear for next iteration |
| 2390 | + // Clear for next iteration |
| 2391 | + startNode = null; |
2409 | 2392 | startDepth = null; |
2410 | 2393 | i++; |
2411 | 2394 | } |
2412 | | - |
2413 | 2395 | pos = newPos; |
2414 | 2396 | node = next; |
2415 | 2397 | depth = nextDepth; |
— | — | @@ -2671,59 +2653,39 @@ |
2672 | 2654 | */ |
2673 | 2655 | evt: { |
2674 | 2656 | mark: function( context, event ) { |
2675 | | - // This is shared by both the closure findOutermostTemplates and the calling code - is this a good idea? |
2676 | | - var i = 0; |
2677 | | - /** |
2678 | | - * Finds the left and right character positions of the outer-most template declaration, playing nicely with |
2679 | | - * nested template calls of any depth. This function acts as an iterator, which is why the i var is shared - but |
2680 | | - * this seems a bit scary seeing as 'i' is so often used in loops. |
2681 | | - * |
2682 | | - * @param tokenStack Array of tokens to find boundries within |
2683 | | - */ |
2684 | | - function findOutermostTemplates( tokenStack ) { |
2685 | | - var templateBeginFound = false; |
2686 | | - for ( ; i < tokenStack.length; i++ ) { |
2687 | | - if ( tokenStack[i].label == 'TEMPLATE_BEGIN' ) { |
2688 | | - templateBeginFound = true; |
2689 | | - break; |
| 2657 | + // Get refrences to the markers and tokens from the current context |
| 2658 | + var markers = context.modules.highlight.markers; |
| 2659 | + var tokenArray = context.modules.highlight.tokenArray; |
| 2660 | + // Collect matching level 0 template call boundries from the tokenArrray |
| 2661 | + var level = 0; |
| 2662 | + var boundries = []; |
| 2663 | + var boundry = 0; |
| 2664 | + for ( token in tokenArray ) { |
| 2665 | + if ( tokenArray[token].label == 'TEMPLATE_BEGIN' ) { |
| 2666 | + if ( level++ == 0 ) { |
| 2667 | + boundry = boundries.push( { 'begin': tokenArray[token].offset } ) - 1; |
2690 | 2668 | } |
| 2669 | + } else if ( tokenArray[token].label == 'TEMPLATE_END' ) { |
| 2670 | + if ( --level == 0 ) { |
| 2671 | + boundries[boundry].end = tokenArray[token].offset; |
| 2672 | + } |
2691 | 2673 | } |
2692 | | - var j = i++; |
2693 | | - if ( !templateBeginFound ) { |
2694 | | - return false; |
2695 | | - } else { |
2696 | | - // This is only designed to find the outermost template boundaries, the model handles nested template |
2697 | | - // and template-like objects better |
2698 | | - var nestedBegins = 1; |
2699 | | - while ( nestedBegins > 0 && j < tokenStack.length ) { |
2700 | | - var label = tokenStack[++j].label; |
2701 | | - nestedBegins += label == 'TEMPLATE_END' ? -1 : label == 'TEMPLATE_BEGIN' ? 1 : 0; |
| 2674 | + } |
| 2675 | + // Add encapsulations to markers at the offsets of matching sets of level 0 template call boundries |
| 2676 | + for ( boundry in boundries ) { |
| 2677 | + if ( 'begin' in boundries[boundry] && 'end' in boundries[boundry] ) { |
| 2678 | + // Ensure arrays exist at the begining and ending offsets for boundry |
| 2679 | + if ( !( boundries[boundry].begin in markers ) ) { |
| 2680 | + markers[boundries[boundry].begin] = []; |
2702 | 2681 | } |
2703 | | - if ( nestedBegins == 0 ) { |
2704 | | - // Outer template begins at tokenStack[i].offset and ends at tokenStack[j].offset + 2 |
2705 | | - var leftMarker = i -1; |
2706 | | - var rightMarker = j; |
2707 | | - i = j; |
2708 | | - return [leftMarker, rightMarker]; |
2709 | | - } else { |
2710 | | - return false; |
| 2682 | + if ( !( boundries[boundry].end in markers ) ) { |
| 2683 | + markers[boundries[boundry].end] = []; |
2711 | 2684 | } |
| 2685 | + // Append boundry markers |
| 2686 | + markers[boundries[boundry].begin].push( "<div class='wiki-template'>" ); |
| 2687 | + markers[boundries[boundry].end].push( "</div>" ); |
| 2688 | + |
2712 | 2689 | } |
2713 | | - }; |
2714 | | - // Get the markers and tokens from the current context |
2715 | | - var markers = context.modules.highlight.markers; |
2716 | | - var tokenStack = context.modules.highlight.tokenArray; |
2717 | | - // Scan through and detect the boundries of template calls |
2718 | | - var templateBeginFound = false; |
2719 | | - var templateBoundaries; |
2720 | | - while ( templateBoundaries = findOutermostTemplates( tokenStack ) ) { |
2721 | | - context.modules.highlight.markers.push( { |
2722 | | - start: tokenStack[templateBoundaries[0]].offset, |
2723 | | - end: tokenStack[templateBoundaries[1]].offset, |
2724 | | - wrapElement: function() { |
2725 | | - return $( '<div />' ).addClass( 'wikiEditor-highlight-template' ); |
2726 | | - } |
2727 | | - } ); |
2728 | 2690 | } |
2729 | 2691 | } |
2730 | 2692 | }, |
— | — | @@ -2975,15 +2937,17 @@ |
2976 | 2938 | valueEndIndex = valueEnd.index + oldDivider + 2; |
2977 | 2939 | ranges.push( new Range( ranges[ranges.length-1].end, |
2978 | 2940 | valueBeginIndex ) ); //all the chars upto now |
2979 | | - nameIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ); |
2980 | | - nameIndex--; |
2981 | | - equalsIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ); |
2982 | | - equalsIndex--; |
2983 | | - valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ); |
2984 | | - valueIndex--; |
2985 | | - params.push( new Param( currentParamNumber, |
| 2941 | + nameIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ) - 1; |
| 2942 | + equalsIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ) - 1; |
| 2943 | + valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ) - 1; |
| 2944 | + params.push( new Param( |
| 2945 | + currentParamNumber, |
2986 | 2946 | wikitext.substring( ranges[valueIndex].begin, ranges[valueIndex].end ), |
2987 | | - currentParamNumber, nameIndex, equalsIndex, valueIndex ) ); |
| 2947 | + currentParamNumber, |
| 2948 | + nameIndex, |
| 2949 | + equalsIndex, |
| 2950 | + valueIndex |
| 2951 | + ) ); |
2988 | 2952 | paramsByName[currentParamNumber] = currentParamNumber; |
2989 | 2953 | } else { |
2990 | 2954 | // There's an equals, could be comment or a value pair |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -120,27 +120,24 @@ |
121 | 121 | var maxTI=0;$j('[tabindex]').each(function(){var ti=parseInt($j(this).attr('tabindex'));if(ti>maxTI) |
122 | 122 | maxTI=ti;});var tabIndex=maxTI+1;$j('.ui-dialog input, .ui-dialog button').not('[tabindex]').each(function(){$j(this).attr('tabindex',tabIndex++);});}}});},resize:function(){var wrapper=$(this).closest('.ui-dialog');var oldWidth=wrapper.width();var oldHidden=$(this).find('*').not(':visible');oldHidden.each(function(){$(this).data('oldstyle',$(this).attr('style'));});oldHidden.show();var oldWS=$(this).css('white-space');$(this).css('white-space','nowrap');if(wrapper.width()<=$(this).get(0).scrollWidth){var thisWidth=$(this).data('thisWidth')?$(this).data('thisWidth'):0;thisWidth=Math.max($(this).get(0).scrollWidth,thisWidth);$(this).width(thisWidth);$(this).data('thisWidth',thisWidth);var wrapperWidth=$(this).data('wrapperWidth')?$(this).data('wrapperWidth'):0;wrapperWidth=Math.max(wrapper.get(0).scrollWidth,wrapperWidth);wrapper.width(wrapperWidth);$(this).data('wrapperWidth',wrapperWidth);$(this).dialog({'width':wrapper.width()});wrapper.css('left',parseInt(wrapper.css('left'))-(wrapper.width()-oldWidth)/2);} |
123 | 123 | $(this).css('white-space',oldWS);oldHidden.each(function(){$(this).attr('style',$(this).data('oldstyle'));});}},modules:{},quickDialog:function(body,settings){$('<div />').text(body).appendTo($('body')).dialog($.extend({bgiframe:true,modal:true},settings)).dialog('open');}};})(jQuery);(function($){$.wikiEditor.modules.highlight={evt:{change:function(context,event){if(event.data.scope=='keydown'){$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}},ready:function(context,event){context.$content.parent().find('head').append($j('<link />').attr({'rel':'stylesheet','type':'text/css','href':wgScriptPath+'/extensions/UsabilityInitiative/css/wikiEditor.highlight.css',}));$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}},fn:{create:function(context,config){},divide:function(context){},isolate:function(context){return[];},strip:function(context,division){return $('<div />').html(division.html().replace(/\<br[^\>]*\>/g,"\n")).text();},scan:function(context,division){function Token(offset,label){this.offset=offset;this.label=label;} |
124 | | -context.modules.highlight.tokenArray=[];var text=context.fn.getContents();for(module in $.wikiEditor.modules){if('exp'in $.wikiEditor.modules[module]){for(var i=0;i<$.wikiEditor.modules[module].exp.length;i++){var regex=$.wikiEditor.modules[module].exp[i].regex;var label=$.wikiEditor.modules[module].exp[i].label;var markAfter=false;if(typeof $.wikiEditor.modules[module].exp[i].markAfter!='undefined'){markAfter=true;} |
| 124 | +var tokenArray=context.modules.highlight.tokenArray=[];var text=context.fn.getContents();for(module in $.wikiEditor.modules){if('exp'in $.wikiEditor.modules[module]){for(var i=0;i<$.wikiEditor.modules[module].exp.length;i++){var regex=$.wikiEditor.modules[module].exp[i].regex;var label=$.wikiEditor.modules[module].exp[i].label;var markAfter=false;if(typeof $.wikiEditor.modules[module].exp[i].markAfter!='undefined'){markAfter=true;} |
125 | 125 | match=text.match(regex);var oldOffset=0;while(match!=null){var markOffset=0;if(markAfter){markOffset+=match[0].length;} |
126 | | -context.modules.highlight.tokenArray.push(new Token(match.index+oldOffset+markOffset,label));oldOffset+=match.index+match[0].length;newSubstring=text.substring(oldOffset);match=newSubstring.match(regex);}}}} |
127 | | -context.modules.highlight.tokenArray.sort(function(a,b){return a.offset-b.offset;});return context.modules.highlight.tokenArray;},mark:function(context,division,tokens){context.modules.highlight.markers=[];for(module in $.wikiEditor.modules){if('evt'in $.wikiEditor.modules[module]&&'mark'in $.wikiEditor.modules[module].evt){$.wikiEditor.modules[module].evt.mark(context);}} |
128 | | -var markers=context.modules.highlight.markers;markers.sort(function(a,b){return a.start-b.start||a.end-b.end;});var pos=0;var node=context.$content.get(0);var next=null;var i=0;var startNode=null;var depth=0,nextDepth=0,startDepth=null;while(node.firstChild){node=node.firstChild;depth++;} |
| 126 | +tokenArray.push(new Token(match.index+oldOffset+markOffset,label));oldOffset+=match.index+match[0].length;newSubstring=text.substring(oldOffset);match=newSubstring.match(regex);}}}} |
| 127 | +tokenArray.sort(function(a,b){return a.offset-b.offset;});context.fn.trigger('scan');},mark:function(context,division,tokens){var markers=context.modules.highlight.markers=[];context.fn.trigger('mark');markers.sort(function(a,b){return a.start-b.start||a.end-b.end;});var pos=0;var node=context.$content.get(0);var next=null;var i=0;var startNode=null;var depth=0,nextDepth=0,startDepth=null;while(node.firstChild){node=node.firstChild;depth++;} |
129 | 128 | while(i<markers.length&&node){var p=node;nextDepth=depth;while(p&&!p.nextSibling){p=p.parentNode;nextDepth--;} |
130 | 129 | p=p?p.nextSibling:null;while(p&&p.firstChild){p=p.firstChild;nextDepth++;} |
131 | | -next=p;if(node.nodeName!='#text'){if(node.nodeName=='BR') |
132 | | -pos++;node=next;depth=nextDepth;continue;} |
| 130 | +next=p;if(node.nodeName!='#text'){if(node.nodeName=='BR'){pos++;} |
| 131 | +node=next;depth=nextDepth;continue;} |
133 | 132 | var newPos=pos+node.nodeValue.length;if(!startNode&&markers[i].start>=pos&&markers[i].start<newPos){if(markers[i].start>pos){node=node.splitText(markers[i].start-pos);pos=markers[i].start;} |
134 | 133 | startNode=node;startDepth=depth;} |
135 | 134 | if(startNode&&markers[i].end>pos&&markers[i].end<=newPos){if(markers[i].end<newPos){next=node.splitText(node.nodeValue.length-newPos+markers[i].end);newPos=markers[i].end;} |
136 | 135 | var ca1=startNode,ca2=node;if(startDepth>depth){for(var j=0;j<startDepth-depth&&ca1;j++){ca1=ca1.parentNode;}} |
137 | 136 | else if(startDepth<depth){for(var j=0;j<depth-startDepth&&ca2;j++){ca2=ca2.parentNode;}} |
138 | 137 | while(ca1&&ca2&&ca1.parentNode!=ca2.parentNode){if(ca1.parentNode.firstChild!=ca1||ca2.parentNode.lastChild!=ca2){ca1=ca2=null;}else{ca1=ca1.parentNode;ca2=ca2.parentNode;}} |
139 | | -if(ca1&&ca2){var newNode=markers[i].wrapElement;if(typeof newNode=='function') |
140 | | -newNode=newNode();if(newNode.jquery) |
141 | | -newNode=newNode.get(0);var commonAncestor=ca1.parentNode;var nextNode=ca2.nextSibling;var n=ca1;while(n!=nextNode){var ns=n.nextSibling;newNode.appendChild(n);n=ns;} |
142 | | -if(nextNode) |
143 | | -commonAncestor.insertBefore(newNode,nextNode);else |
144 | | -commonAncestor.appendChild(newNode);} |
| 138 | +if(ca1&&ca2){var newNode=markers[i].wrapElement;if(typeof newNode=='function'){newNode=newNode();} |
| 139 | +if(newNode.jquery){newNode=newNode.get(0);} |
| 140 | +var commonAncestor=ca1.parentNode;var nextNode=ca2.nextSibling;var n=ca1;while(n!=nextNode){var ns=n.nextSibling;newNode.appendChild(n);n=ns;} |
| 141 | +if(nextNode){commonAncestor.insertBefore(newNode,nextNode);}else{commonAncestor.appendChild(newNode);}} |
145 | 142 | startNode=null;startDepth=null;i++;} |
146 | 143 | pos=newPos;node=next;depth=nextDepth;}}}};})(jQuery);(function($){$.wikiEditor.modules.preview={fn:{create:function(context,config){if('initialized'in context.modules.preview){return;} |
147 | 144 | context.modules.preview={'initialized':true,'previewText':null,'changesText':null};context.modules.preview.$preview=context.fn.addView({'name':'preview','titleMsg':'wikieditor-preview-tab','init':function(context){var wikitext=context.fn.getContents();if(context.modules.preview.previewText==wikitext){return;} |
— | — | @@ -172,9 +169,10 @@ |
173 | 170 | $('#wikiEditor-'+context.instance+'-dialog-minor').hide();else if($('#wpMinoredit').is(':checked')) |
174 | 171 | $('#wikiEditor-'+context.instance+'-dialog-minor').attr('checked','checked');if($('#wpWatchthis').size()==0) |
175 | 172 | $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked')) |
176 | | -$('#wikiEditor-'+context.instance+'-dialog-watch').attr('checked','checked');$(this).find('form').submit(function(e){$(this).closest('.ui-dialog').find('button:first').click();e.preventDefault();});},dialog:{buttons:{'wikieditor-publish-dialog-publish':function(){var minorChecked=$('#wikiEditor-'+context.instance+'-dialog-minor').is(':checked')?'checked':'';var watchChecked=$('#wikiEditor-'+context.instance+'-dialog-watch').is(':checked')?'checked':'';$('#wpMinoredit').attr('checked',minorChecked);$('#wpWatchthis').attr('checked',watchChecked);$('#wpSummary').val($j('#wikiEditor-'+context.instance+'-dialog-summary').val());$('#editform').submit();},'wikieditor-publish-dialog-goback':function(){$(this).dialog('close');}},open:function(){$('#wikiEditor-'+context.instance+'-dialog-summary').focus();},width:500},resizeme:false}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-publish','action':function(){$('#'+dialogID).dialog('open');return false;}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-cancel','action':function(){}});}}};})(jQuery);(function($){$.wikiEditor.modules.templateEditor={evt:{mark:function(context,event){var i=0;function findOutermostTemplates(tokenStack){var templateBeginFound=false;for(;i<tokenStack.length;i++){if(tokenStack[i].label=='TEMPLATE_BEGIN'){templateBeginFound=true;break;}} |
177 | | -var j=i++;if(!templateBeginFound){return false;}else{var nestedBegins=1;while(nestedBegins>0&&j<tokenStack.length){var label=tokenStack[++j].label;nestedBegins+=label=='TEMPLATE_END'?-1:label=='TEMPLATE_BEGIN'?1:0;} |
178 | | -if(nestedBegins==0){var leftMarker=i-1;var rightMarker=j;i=j;return[leftMarker,rightMarker];}else{return false;}}};var markers=context.modules.highlight.markers;var tokenStack=context.modules.highlight.tokenArray;var templateBeginFound=false;var templateBoundaries;while(templateBoundaries=findOutermostTemplates(tokenStack)){context.modules.highlight.markers.push({start:tokenStack[templateBoundaries[0]].offset,end:tokenStack[templateBoundaries[1]].offset,wrapElement:function(){return $('<div />').addClass('wikiEditor-highlight-template');}});}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],fn:{create:function(context,config){},model:function(wikitext){function Param(name,value,number,nameIndex,equalsIndex,valueIndex){this.name=name;this.value=value;this.number=number;this.nameIndex=nameIndex;this.equalsIndex=equalsIndex;this.valueIndex=valueIndex;} |
| 173 | +$('#wikiEditor-'+context.instance+'-dialog-watch').attr('checked','checked');$(this).find('form').submit(function(e){$(this).closest('.ui-dialog').find('button:first').click();e.preventDefault();});},dialog:{buttons:{'wikieditor-publish-dialog-publish':function(){var minorChecked=$('#wikiEditor-'+context.instance+'-dialog-minor').is(':checked')?'checked':'';var watchChecked=$('#wikiEditor-'+context.instance+'-dialog-watch').is(':checked')?'checked':'';$('#wpMinoredit').attr('checked',minorChecked);$('#wpWatchthis').attr('checked',watchChecked);$('#wpSummary').val($j('#wikiEditor-'+context.instance+'-dialog-summary').val());$('#editform').submit();},'wikieditor-publish-dialog-goback':function(){$(this).dialog('close');}},open:function(){$('#wikiEditor-'+context.instance+'-dialog-summary').focus();},width:500},resizeme:false}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-publish','action':function(){$('#'+dialogID).dialog('open');return false;}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-cancel','action':function(){}});}}};})(jQuery);(function($){$.wikiEditor.modules.templateEditor={evt:{mark:function(context,event){var markers=context.modules.highlight.markers;var tokenArray=context.modules.highlight.tokenArray;var level=0;var boundries=[];var boundry=0;for(token in tokenArray){if(tokenArray[token].label=='TEMPLATE_BEGIN'){if(level++==0){boundry=boundries.push({'begin':tokenArray[token].offset})-1;}}else if(tokenArray[token].label=='TEMPLATE_END'){if(--level==0){boundries[boundry].end=tokenArray[token].offset;}}} |
| 174 | +for(boundry in boundries){if('begin'in boundries[boundry]&&'end'in boundries[boundry]){if(!(boundries[boundry].begin in markers)){markers[boundries[boundry].begin]=[];} |
| 175 | +if(!(boundries[boundry].end in markers)){markers[boundries[boundry].end]=[];} |
| 176 | +markers[boundries[boundry].begin].push("<div class='wiki-template'>");markers[boundries[boundry].end].push("</div>");}}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],fn:{create:function(context,config){},model:function(wikitext){function Param(name,value,number,nameIndex,equalsIndex,valueIndex){this.name=name;this.value=value;this.number=number;this.nameIndex=nameIndex;this.equalsIndex=equalsIndex;this.valueIndex=valueIndex;} |
179 | 177 | function Range(begin,end){this.begin=begin;this.end=end;} |
180 | 178 | function getSetValue(name,value,original){var valueRange;var rangeIndex;var retVal;if(isNaN(name)){if(typeof paramsByName[name]=='undefined'){return"";} |
181 | 179 | rangeIndex=paramsByName[name];}else{rangeIndex=parseInt(name);} |
— | — | @@ -189,7 +187,7 @@ |
190 | 188 | var ranges=[];var params=[];var templateNameIndex=0;var doneParsing=false;oldDivider=0;divider=sanatizedStr.indexOf('|',oldDivider);if(divider==-1){divider=sanatizedStr.length;doneParsing=true;} |
191 | 189 | nameMatch=wikitext.substring(oldDivider,divider).match(/[^{\s]+/);if(nameMatch!=undefined){ranges.push(new Range(oldDivider,nameMatch.index));templateNameIndex=ranges.push(new Range(nameMatch.index,nameMatch.index+nameMatch[0].length));templateNameIndex--;ranges[templateNameIndex].old=wikitext.substring(ranges[templateNameIndex].begin,ranges[templateNameIndex].end);} |
192 | 190 | params.push(ranges[templateNameIndex].old);var currentParamNumber=0;var valueEndIndex;var paramsByName=[];while(!doneParsing){currentParamNumber++;oldDivider=divider;divider=sanatizedStr.indexOf('|',oldDivider+1);if(divider==-1){divider=sanatizedStr.length;doneParsing=true;} |
193 | | -currentField=sanatizedStr.substring(oldDivider+1,divider);if(currentField.indexOf('=')==-1){valueBegin=currentField.match(/\S+/);valueBeginIndex=valueBegin.index+oldDivider+1;valueEnd=currentField.match(/[^\s]\s*$/);valueEndIndex=valueEnd.index+oldDivider+2;ranges.push(new Range(ranges[ranges.length-1].end,valueBeginIndex));nameIndex=ranges.push(new Range(valueBeginIndex,valueBeginIndex));nameIndex--;equalsIndex=ranges.push(new Range(valueBeginIndex,valueBeginIndex));equalsIndex--;valueIndex=ranges.push(new Range(valueBeginIndex,valueEndIndex));valueIndex--;params.push(new Param(currentParamNumber,wikitext.substring(ranges[valueIndex].begin,ranges[valueIndex].end),currentParamNumber,nameIndex,equalsIndex,valueIndex));paramsByName[currentParamNumber]=currentParamNumber;}else{currentName=currentField.substring(0,currentField.indexOf('='));nameBegin=currentName.match(/\S+/);if(nameBegin==null){divider++;currentParamNumber--;continue;} |
| 191 | +currentField=sanatizedStr.substring(oldDivider+1,divider);if(currentField.indexOf('=')==-1){valueBegin=currentField.match(/\S+/);valueBeginIndex=valueBegin.index+oldDivider+1;valueEnd=currentField.match(/[^\s]\s*$/);valueEndIndex=valueEnd.index+oldDivider+2;ranges.push(new Range(ranges[ranges.length-1].end,valueBeginIndex));nameIndex=ranges.push(new Range(valueBeginIndex,valueBeginIndex))-1;equalsIndex=ranges.push(new Range(valueBeginIndex,valueBeginIndex))-1;valueIndex=ranges.push(new Range(valueBeginIndex,valueEndIndex))-1;params.push(new Param(currentParamNumber,wikitext.substring(ranges[valueIndex].begin,ranges[valueIndex].end),currentParamNumber,nameIndex,equalsIndex,valueIndex));paramsByName[currentParamNumber]=currentParamNumber;}else{currentName=currentField.substring(0,currentField.indexOf('='));nameBegin=currentName.match(/\S+/);if(nameBegin==null){divider++;currentParamNumber--;continue;} |
194 | 192 | nameBeginIndex=nameBegin.index+oldDivider+1;nameEnd=currentName.match(/[^\s]\s*$/);nameEndIndex=nameEnd.index+oldDivider+2;ranges.push(new Range(ranges[ranges.length-1].end,nameBeginIndex));nameIndex=ranges.push(new Range(nameBeginIndex,nameEndIndex))-1;currentValue=currentField.substring(currentField.indexOf('=')+1);oldDivider+=currentField.indexOf('=')+1;valueBegin=currentValue.match(/\S+/);valueBeginIndex=valueBegin.index+oldDivider+1;valueEnd=currentValue.match(/[^\s]\s*$/);valueEndIndex=valueEnd.index+oldDivider+2;equalsIndex=ranges.push(new Range(ranges[ranges.length-1].end,valueBeginIndex))-1;valueIndex=ranges.push(new Range(valueBeginIndex,valueEndIndex))-1;params.push(new Param(wikitext.substring(nameBeginIndex,nameEndIndex),wikitext.substring(valueBeginIndex,valueEndIndex),currentParamNumber,nameIndex,equalsIndex,valueIndex));paramsByName[wikitext.substring(nameBeginIndex,nameEndIndex)]=currentParamNumber;}} |
195 | 193 | ranges.push(new Range(valueEndIndex,wikitext.length));}}};})(jQuery);(function($){$.wikiEditor.modules.toc={cfg:{defaultWidth:'166px',minimumWidth:'70px',},api:{},evt:{ready:function(context,event){$.wikiEditor.modules.toc.fn.build(context);context.$content.parent().delayedBind(250,'mouseup scrollToTop keyup change',function(){$(this).eachAsync({bulk:0,loop:function(){$.wikiEditor.modules.toc.fn.build(context);$.wikiEditor.modules.toc.fn.update(context);}});}).blur(function(event){var context=event.data.context;context.$textarea.delayedBindCancel(250,'mouseup scrollToTop keyup change');$.wikiEditor.modules.toc.fn.unhighlight(context);});},resize:function(context,event){context.modules.toc.$toc.height(context.$ui.find('.wikiEditor-ui-left').height()- |
196 | 194 | context.$ui.find('.tab-toc').outerHeight());}},fn:{create:function(context,config){if('$toc'in context.modules.toc){return;} |