Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js |
— | — | @@ -9,75 +9,68 @@ |
10 | 10 | }, |
11 | 11 | |
12 | 12 | evt: { |
13 | | - mark: function(){ |
14 | | - |
15 | | - var findOutermostTemplates = function(){ |
16 | | - templateBeginFound = false; |
17 | | - for(;i< tokenStack.length; i++){ |
18 | | - if(tokenStack[i].label == "TEMPLATE_BEGIN"){ |
| 13 | + mark: function() { |
| 14 | + function findOutermostTemplates( tokenStack ) { |
| 15 | + var templateBeginFound = false; |
| 16 | + for ( ;i< tokenStack.length; i++ ) { |
| 17 | + if ( tokenStack[i].label == "TEMPLATE_BEGIN" ) { |
19 | 18 | templateBeginFound = true; |
20 | | - break; |
| 19 | + break; |
21 | 20 | } |
22 | 21 | } |
23 | 22 | var j = i; |
24 | 23 | i++; |
25 | | - if(!templateBeginFound){ |
| 24 | + if ( !templateBeginFound ) { |
26 | 25 | return false; |
27 | | - } |
28 | | - else{ |
| 26 | + } else { |
29 | 27 | // This is only designed to find the outermost template boundaries, the model handles nested template |
30 | 28 | // and template-like objects better |
31 | 29 | var nestedBegins = 1; |
32 | | - while(nestedBegins > 0 && j < tokenStack.length){ |
| 30 | + while ( nestedBegins > 0 && j < tokenStack.length ) { |
33 | 31 | j++; |
34 | | - if(tokenStack[j].label == "TEMPLATE_END"){ |
| 32 | + if ( tokenStack[j].label == "TEMPLATE_END" ) { |
35 | 33 | nestedBegins--; |
36 | 34 | } |
37 | | - if(tokenStack[j].label == "TEMPLATE_BEGIN"){ |
| 35 | + if ( tokenStack[j].label == "TEMPLATE_BEGIN" ) { |
38 | 36 | nestedBegins++; |
39 | 37 | } |
40 | | - }//while |
41 | | - if(nestedBegins == 0){ |
| 38 | + } |
| 39 | + if ( nestedBegins == 0 ) { |
42 | 40 | // outer template begins at tokenStack[i].offset |
43 | 41 | // and ends at tokenStack[j].offset + 2 |
44 | 42 | var leftMarker = i -1; |
45 | 43 | var rightMarker = j; |
46 | 44 | i = j; |
47 | 45 | return [ leftMarker, rightMarker ]; |
48 | | - } |
49 | | - else{ |
| 46 | + } else { |
50 | 47 | return false; |
51 | 48 | } |
52 | 49 | } |
53 | 50 | }; //find outermost templates |
54 | 51 | |
55 | 52 | var markers = $.wikiEditor.modules.highlight.fn.markers; |
56 | | - tokenStack = $.wikiEditor.modules.highlight.fn.tokenArray; |
57 | | - var i=0; |
58 | | - var templateBoundaries = findOutermostTemplates(); |
| 53 | + var tokenStack = $.wikiEditor.modules.highlight.fn.tokenArray; |
| 54 | + var i = 0; |
| 55 | + var templateBoundaries; |
| 56 | + var templateBeginFound = false; |
59 | 57 | |
60 | | - templateBeginFound = false; |
61 | | - |
62 | | - while(templateBoundaries){ |
63 | | - if(typeof(markers[tokenStack[templateBoundaries[0]].offset]) == 'undefined'){ |
64 | | - markers[tokenStack[templateBoundaries[0]].offset] = new Array(); |
| 58 | + while ( templateBoundaries = findOutermostTemplates( tokenStack ) ) { |
| 59 | + if ( typeof markers[tokenStack[templateBoundaries[0]].offset] == 'undefined' ) { |
| 60 | + markers[tokenStack[templateBoundaries[0]].offset] = []; |
65 | 61 | } |
66 | | - if(typeof(markers[tokenStack[templateBoundaries[1]].offset]) == 'undefined'){ |
67 | | - markers[tokenStack[templateBoundaries[1]].offset] = new Array(); |
| 62 | + if ( typeof markers[tokenStack[templateBoundaries[1]].offset] == 'undefined' ) { |
| 63 | + markers[tokenStack[templateBoundaries[1]].offset] = []; |
68 | 64 | } |
69 | 65 | |
70 | | - markers[tokenStack[templateBoundaries[0]].offset].push("<div class='wiki-template'>"); |
71 | | - markers[tokenStack[templateBoundaries[1]].offset].push("</div>"); |
72 | | - |
73 | | - templateBoundaries = findOutermostTemplates(); |
74 | | - } |
| 66 | + markers[tokenStack[templateBoundaries[0]].offset].push( "<div class='wiki-template'>" ); |
| 67 | + markers[tokenStack[templateBoundaries[1]].offset].push( "</div>" ); |
| 68 | + } |
75 | 69 | } |
76 | 70 | }, |
77 | 71 | |
78 | | - |
79 | 72 | exp: [ |
80 | | - { regex: /{{/ , label: "TEMPLATE_BEGIN" }, |
81 | | - { regex: /}}/ , label: "TEMPLATE_END" , markAfter:true} |
| 73 | + { regex: /{{/, label: "TEMPLATE_BEGIN" }, |
| 74 | + { regex: /}}/, label: "TEMPLATE_END", markAfter: true } |
82 | 75 | ], |
83 | 76 | |
84 | 77 | /** |
— | — | @@ -91,16 +84,13 @@ |
92 | 85 | */ |
93 | 86 | create: function( context, config ) { |
94 | 87 | |
95 | | - //check if text is selected |
96 | | - |
97 | | - |
98 | | - }, |
| 88 | + // check if text is selected |
| 89 | + }, |
99 | 90 | |
100 | 91 | //template Model |
101 | | - model: function (wikitext){ |
102 | | - |
103 | | - //param object |
104 | | - function param(name, value, number, nameIndex, equalsIndex, valueIndex){ |
| 92 | + model: function( wikitext ) { |
| 93 | + // Param object |
| 94 | + function Param( name, value, number, nameIndex, equalsIndex, valueIndex ) { |
105 | 95 | this.name = name; |
106 | 96 | this.value = value; |
107 | 97 | this.number = number; |
— | — | @@ -109,163 +99,167 @@ |
110 | 100 | this.valueIndex = valueIndex; |
111 | 101 | } |
112 | 102 | |
113 | | - //range object |
114 | | - function range(begin, end){ |
| 103 | + // Range object |
| 104 | + function Range( begin, end ) { |
115 | 105 | this.begin = begin; |
116 | 106 | this.end = end; |
117 | 107 | } |
118 | 108 | |
119 | | - var ranges = new Array(); |
| 109 | + var ranges = []; |
120 | 110 | var sanatizedStr = ""; |
121 | | - var params = new Array(); |
122 | | - var paramsByName = new Array(); |
| 111 | + var params = []; |
| 112 | + var paramsByName = []; |
123 | 113 | var templateNameIndex = 0; |
124 | 114 | |
125 | | - //markOffTemplates |
126 | | - markOffTemplates = function () { |
127 | | - sanatizedStr = wikitext; |
| 115 | + function markOffTemplates() { |
| 116 | + sanatizedStr = wikitext.replace( /{{/, " " ); //get rid of first {{ with whitespace |
| 117 | + endBraces = sanatizedStr.match( /}}\s*$/ ); //replace end |
| 118 | + sanatizedStr = sanatizedStr.substring( 0, endBraces.index ) + " " + |
| 119 | + sanatizedStr.substring( endBraces.index + 2 ); |
128 | 120 | |
129 | | - sanatizedStr = sanatizedStr.replace(/{{/, " "); //get rid of first {{ with whitespace |
130 | | - endBraces = sanatizedStr.match(/}}\s*$/); //replace end |
131 | | - sanatizedStr = sanatizedStr.substring(0,endBraces.index) + " " + sanatizedStr.substring(endBraces.index+2); |
132 | | - |
133 | | - while(sanatizedStr.indexOf('{{') != -1){ |
| 121 | + while ( sanatizedStr.indexOf( '{{' ) != -1 ) { |
134 | 122 | startIndex = sanatizedStr.indexOf('{{') + 1; |
135 | 123 | openBraces = 2; |
136 | 124 | endIndex = startIndex; |
137 | | - while(openBraces > 0){ |
| 125 | + while ( openBraces > 0 ) { |
138 | 126 | endIndex++; |
139 | | - switch (sanatizedStr[endIndex]){ |
| 127 | + switch ( sanatizedStr[endIndex] ) { |
140 | 128 | case '}': openBraces--; break; |
141 | 129 | case '{': openBraces++; break; |
142 | 130 | } |
143 | 131 | } |
144 | | - sanatizedSegment = sanatizedStr.substring(startIndex,endIndex); |
145 | | - sanatizedSegment = sanatizedSegment.replace(/}/g, "X"); |
146 | | - sanatizedSegment = sanatizedSegment.replace(/{/g, "X"); |
147 | | - sanatizedSegment = sanatizedSegment.replace(/\|/g, "X"); |
148 | | - sanatizedSegment = sanatizedSegment.replace(/=/g, "X"); |
149 | | - sanatizedStr = sanatizedStr.substring(0, startIndex) + sanatizedSegment + sanatizedStr.substring(endIndex); |
150 | | - } |
| 132 | + sanatizedSegment = sanatizedStr.substring( startIndex,endIndex ) |
| 133 | + .replace( /[{}|=]/g 'X' ); |
| 134 | + sanatizedStr = sanatizedStr.substring( 0, startIndex ) + |
| 135 | + sanatizedSegment + sanatizedStr.substring( endIndex ); |
151 | 136 | }; |
152 | 137 | |
153 | 138 | // Whitespace* {{ whitespace* nonwhitespace: |
154 | | - if(wikitext.match(/\s*{{\s*\S*:/)){ |
155 | | - //we have a parser function! |
| 139 | + if ( wikitext.match( /\s*{{\s*\S*:/ ) ) { |
| 140 | + // we have a parser function! |
156 | 141 | } |
157 | 142 | |
158 | 143 | markOffTemplates(); |
159 | 144 | |
160 | 145 | var doneParsing = false; |
161 | 146 | oldDivider = 0; |
162 | | - divider = sanatizedStr.indexOf('|', oldDivider); |
163 | | - if(divider == -1){divider = sanatizedStr.length; doneParsing = true;} |
164 | | - nameMatch = wikitext.substring(oldDivider, divider).match(/[^{\s]+/); |
| 147 | + divider = sanatizedStr.indexOf( '|', oldDivider ); |
| 148 | + if ( divider == -1 ) { |
| 149 | + divider = sanatizedStr.length; |
| 150 | + doneParsing = true; |
| 151 | + } |
| 152 | + nameMatch = wikitext.substring( oldDivider, divider ).match( /[^{\s]+/ ); |
165 | 153 | if(nameMatch != undefined){ |
166 | | - ranges.push( new range(oldDivider,nameMatch.index) ); //whitespace and squiggles upto the name |
167 | | - templateNameIndex = ranges.push( new range(nameMatch.index, nameMatch.index + nameMatch[0].length)); |
| 154 | + ranges.push( new Range( oldDivider,nameMatch.index ) ); //whitespace and squiggles upto the name |
| 155 | + templateNameIndex = ranges.push( new Range( nameMatch.index, |
| 156 | + nameMatch.index + nameMatch[0].length ) ); |
168 | 157 | templateNameIndex--; //push returns 1 less than the array |
169 | | - ranges[templateNameIndex].old = wikitext.substring(ranges[templateNameIndex].begin, ranges[templateNameIndex].end); |
| 158 | + ranges[templateNameIndex].old = wikitext.substring( ranges[templateNameIndex].begin, |
| 159 | + ranges[templateNameIndex].end ); |
170 | 160 | } |
171 | | - params.push(ranges[templateNameIndex].old); //put something in params (0) |
| 161 | + params.push( ranges[templateNameIndex].old ); //put something in params (0) |
172 | 162 | |
173 | 163 | currentParamNumber = 0; |
174 | 164 | var valueEndIndex; |
175 | | - while(!doneParsing){ |
| 165 | + while ( !doneParsing ) { |
176 | 166 | currentParamNumber++; |
177 | 167 | oldDivider = divider; |
178 | | - divider = sanatizedStr.indexOf('|', oldDivider+1); |
179 | | - if(divider == -1){divider = sanatizedStr.length; doneParsing = true;} |
180 | | - currentField = sanatizedStr.substring(oldDivider+1,divider); |
181 | | - if(currentField.indexOf('=') == -1){ |
182 | | - //anonymous field, gets a number |
183 | | - valueBegin = currentField.match(/\S+/); //first nonwhitespace character |
184 | | - valueBeginIndex = valueBegin.index + oldDivider+1; |
185 | | - valueEnd = currentField.match(/[^\s]\s*$/); //last nonwhitespace character |
| 168 | + divider = sanatizedStr.indexOf( '|', oldDivider + 1 ); |
| 169 | + if ( divider == -1 ) { |
| 170 | + divider = sanatizedStr.length; |
| 171 | + doneParsing = true; |
| 172 | + } |
| 173 | + currentField = sanatizedStr.substring( oldDivider+1, divider ); |
| 174 | + if ( currentField.indexOf( '=' ) == -1 ) { |
| 175 | + // anonymous field, gets a number |
| 176 | + valueBegin = currentField.match( /\S+/ ); //first nonwhitespace character |
| 177 | + valueBeginIndex = valueBegin.index + oldDivider + 1; |
| 178 | + valueEnd = currentField.match( /[^\s]\s*$/ ); //last nonwhitespace character |
186 | 179 | valueEndIndex = valueEnd.index + oldDivider + 2; |
187 | | - ranges.push(new range(ranges[ranges.length-1].end, valueBeginIndex) ); //all the chars upto now |
188 | | - nameIndex = ranges.push(new range(valueBeginIndex, valueBeginIndex)); |
| 180 | + ranges.push( new Range( ranges[ranges.length-1].end, |
| 181 | + valueBeginIndex ) ); //all the chars upto now |
| 182 | + nameIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ); |
189 | 183 | nameIndex--; |
190 | | - equalsIndex = ranges.push(new range(valueBeginIndex, valueBeginIndex)); |
| 184 | + equalsIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ); |
191 | 185 | equalsIndex--; |
192 | | - valueIndex = ranges.push(new range(valueBeginIndex, valueEndIndex)); |
| 186 | + valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ); |
193 | 187 | valueIndex--; |
194 | | - params.push(new param(currentParamNumber, |
195 | | - wikitext.substring(ranges[valueIndex].begin, ranges[valueIndex].end), |
196 | | - currentParamNumber, nameIndex, equalsIndex, valueIndex)); |
| 188 | + params.push( new Param( currentParamNumber, |
| 189 | + wikitext.substring( ranges[valueIndex].begin, ranges[valueIndex].end ), |
| 190 | + currentParamNumber, nameIndex, equalsIndex, valueIndex ) ); |
197 | 191 | paramsByName[currentParamNumber] = currentParamNumber; |
198 | | - } |
199 | | - else{ |
200 | | - //there's an equals, could be comment or a value pair |
201 | | - currentName = currentField.substring(0, currentField.indexOf('=')); |
202 | | - //(still offset by oldDivider) |
203 | | - nameBegin = currentName.match(/\S+/); //first nonwhitespace character |
204 | | - if(nameBegin == null){ divider++; currentParamNumber--; continue;} // this is a comment inside a template call/parser abuse. let's not encourage it |
205 | | - nameBeginIndex = nameBegin.index + oldDivider+1; |
206 | | - nameEnd = currentName.match(/[^\s]\s*$/); //last nonwhitespace and non } character |
207 | | - nameEndIndex = nameEnd.index + oldDivider+2; |
| 192 | + } else { |
| 193 | + // there's an equals, could be comment or a value pair |
| 194 | + currentName = currentField.substring( 0, currentField.indexOf( '=' ) ); |
| 195 | + // (still offset by oldDivider) |
| 196 | + nameBegin = currentName.match( /\S+/ ); //first nonwhitespace character |
| 197 | + if ( nameBegin == null ) { |
| 198 | + // this is a comment inside a template call/parser abuse. let's not encourage it |
| 199 | + divider++; |
| 200 | + currentParamNumber--; |
| 201 | + continue; |
| 202 | + } |
| 203 | + nameBeginIndex = nameBegin.index + oldDivider + 1; |
| 204 | + nameEnd = currentName.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character |
| 205 | + nameEndIndex = nameEnd.index + oldDivider + 2; |
208 | 206 | |
209 | | - ranges.push(new range(ranges[ranges.length-1].end, nameBeginIndex) ); //all the chars upto now |
210 | | - nameIndex = ranges.push(new range(nameBeginIndex, nameEndIndex)); |
| 207 | + ranges.push( new Range( ranges[ranges.length-1].end, |
| 208 | + nameBeginIndex ) ); //all the chars upto now |
| 209 | + nameIndex = ranges.push( new Range( nameBeginIndex, nameEndIndex ) ); |
211 | 210 | nameIndex--; |
212 | | - currentValue = currentField.substring(currentField.indexOf('=') + 1); |
213 | | - oldDivider += (currentField.indexOf('=') +1); |
214 | | - valueBegin = currentValue.match(/\S+/); //first nonwhitespace character |
| 211 | + currentValue = currentField.substring( currentField.indexOf( '=' ) + 1); |
| 212 | + oldDivider += currentField.indexOf( '=' ) + 1; |
| 213 | + valueBegin = currentValue.match( /\S+/ ); //first nonwhitespace character |
215 | 214 | valueBeginIndex = valueBegin.index + oldDivider + 1; |
216 | | - valueEnd = currentValue.match(/[^\s]\s*$/); //last nonwhitespace and non } character |
| 215 | + valueEnd = currentValue.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character |
217 | 216 | valueEndIndex = valueEnd.index + oldDivider + 2; |
218 | | - equalsIndex = ranges.push(new range(ranges[ranges.length-1].end, valueBeginIndex) ); //all the chars upto now |
| 217 | + equalsIndex = ranges.push( new Range( ranges[ranges.length-1].end, |
| 218 | + valueBeginIndex) ); //all the chars upto now |
219 | 219 | equalsIndex--; |
220 | | - valueIndex = ranges.push(new range(valueBeginIndex, valueEndIndex)); |
| 220 | + valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ); |
221 | 221 | valueIndex--; |
222 | | - params.push(new param(wikitext.substring(nameBeginIndex, nameEndIndex), |
223 | | - wikitext.substring(valueBeginIndex, valueEndIndex), |
224 | | - currentParamNumber, nameIndex, equalsIndex, valueIndex)); |
225 | | - paramsByName[wikitext.substring(nameBeginIndex, nameEndIndex)] = currentParamNumber; |
| 222 | + params.push( new Param( wikitext.substring( nameBeginIndex, nameEndIndex ), |
| 223 | + wikitext.substring( valueBeginIndex, valueEndIndex ), |
| 224 | + currentParamNumber, nameIndex, equalsIndex, valueIndex ) ); |
| 225 | + paramsByName[wikitext.substring( nameBeginIndex, nameEndIndex )] = currentParamNumber; |
226 | 226 | } |
227 | 227 | } |
228 | 228 | //the rest of the string |
229 | | - ranges.push(new range(valueEndIndex, wikitext.length)); |
| 229 | + ranges.push( new Range( valueEndIndex, wikitext.length ) ); |
230 | 230 | |
231 | 231 | //FUNCTIONS |
232 | 232 | //set 'original' to true if you want the original value irrespective of whether the model's been changed |
233 | | - getSetValue = function(name, value, original){ |
| 233 | + function getSetValue( name, value, original ) { |
234 | 234 | var valueRange; |
235 | 235 | var rangeIndex; |
236 | 236 | var retVal; |
237 | | - if(isNaN(name)){ |
238 | | - //it's a string! |
239 | | - if(typeof(paramsByName[name]) == 'undefined'){ |
| 237 | + if ( isNaN( name ) ) { |
| 238 | + // it's a string! |
| 239 | + if ( typeof paramsByName[name] == 'undefined' ) { |
240 | 240 | //does not exist |
241 | 241 | return ""; |
242 | 242 | } |
243 | | - else{ |
244 | | - rangeIndex = paramsByName[name]; |
245 | | - } |
246 | | - } |
247 | | - else{ |
| 243 | + rangeIndex = paramsByName[name]; |
| 244 | + } else { |
248 | 245 | //it's a number! |
249 | | - rangeIndex = parseInt(name); |
| 246 | + rangeIndex = parseInt( name ); |
250 | 247 | } |
251 | 248 | |
252 | | - if(typeof(params[rangeIndex]) == 'undefined' ){ |
| 249 | + if ( typeof params[rangeIndex] == 'undefined' ) { |
253 | 250 | //does not exist |
254 | 251 | return ""; |
255 | 252 | } |
256 | | - else{ |
257 | | - valueRange = ranges[params[rangeIndex].valueIndex]; |
258 | | - } |
| 253 | + valueRange = ranges[params[rangeIndex].valueIndex]; |
259 | 254 | |
260 | | - if(typeof(valueRange.newVal) == 'undefined' || original ){ |
| 255 | + if ( typeof valueRange.newVal == 'undefined' || original ) { |
261 | 256 | //value unchanged, return original wikitext |
262 | | - retVal= wikitext.substring(valueRange.begin, valueRange.end); |
263 | | - } |
264 | | - else{ |
| 257 | + retVal = wikitext.substring( valueRange.begin, valueRange.end ); |
| 258 | + } else { |
265 | 259 | //new value exists, return new value |
266 | 260 | retVal = valueRange.newVal; |
267 | 261 | } |
268 | 262 | |
269 | | - if(value != null){ |
| 263 | + if ( value != null ) { |
270 | 264 | ranges[params[rangeIndex].valueIndex].newVal = value; |
271 | 265 | } |
272 | 266 | |
— | — | @@ -275,65 +269,52 @@ |
276 | 270 | //'public' functions |
277 | 271 | |
278 | 272 | //get template name |
279 | | - this.getName = function(){ |
280 | | - if(typeof(ranges[templateNameIndex].newVal) == 'undefined'){ |
281 | | - return wikitext.substring(ranges[templateNameIndex].begin, ranges[templateNameIndex].end); |
282 | | - } |
283 | | - else{ |
284 | | - return ranges[templateNameIndex].newVal; |
285 | | - } |
| 273 | + this.getName = function() { |
| 274 | + return ranges[templateNameIndex].newVal || |
| 275 | + wikitext.substring( ranges[templateNameIndex].begin, |
| 276 | + ranges[templateNameIndex].end ); |
286 | 277 | }; |
287 | 278 | |
288 | 279 | //set template name (if we want to support this) |
289 | | - this.setName = function(name){ |
| 280 | + this.setName = function( name ) { |
290 | 281 | ranges[templateNameIndex].newVal = name; |
291 | 282 | }; |
292 | 283 | |
293 | 284 | //set value for a given param name/number |
294 | | - this.setValue = function(name, value){ |
295 | | - return getSetValue(name, value, false); |
| 285 | + this.setValue = function( name, value ) { |
| 286 | + return getSetValue( name, value, false ); |
296 | 287 | }; |
297 | 288 | |
298 | 289 | //get value for a given param name/number |
299 | | - this.getValue = function(name){ |
300 | | - return getSetValue(name, null, false); |
| 290 | + this.getValue = function( name ) { |
| 291 | + return getSetValue( name, null, false ); |
301 | 292 | }; |
302 | 293 | |
303 | 294 | //get original value of a param |
304 | | - this.getOriginalValue = function(name){ |
305 | | - return getSetValue(name, null, true); |
| 295 | + this.getOriginalValue = function( name ) { |
| 296 | + return getSetValue( name, null, true ); |
306 | 297 | }; |
307 | 298 | |
308 | 299 | //get a list of all param names (numbers for the anonymous ones) |
309 | | - this.getAllParams = function(){ |
| 300 | + this.getAllParams = function() { |
310 | 301 | return paramsByName; |
311 | 302 | }; |
312 | 303 | |
313 | 304 | //get original template text |
314 | | - this.getOriginalText = function(){ |
| 305 | + this.getOriginalText = function() { |
315 | 306 | return wikitext; |
316 | 307 | }; |
317 | 308 | |
318 | 309 | //get modified template text |
319 | | - this.getText = function(){ |
| 310 | + this.getText = function() { |
320 | 311 | newText = ""; |
321 | | - for(i = 0 ; i < ranges.length; i++){ |
322 | | - if(typeof(ranges[i].newVal) == 'undefined'){ |
323 | | - newText += wikitext.substring(ranges[i].begin, ranges[i].end); |
324 | | - } |
325 | | - else{ |
326 | | - newText += ranges[i].newVal; |
327 | | - } |
| 312 | + for ( i = 0 ; i < ranges.length; i++ ) { |
| 313 | + newText += ranges[i].newVal || wikitext.substring( |
| 314 | + ranges[i].begin, ranges[i].end ); |
328 | 315 | } |
329 | 316 | return newText; |
330 | 317 | }; |
331 | | - |
332 | 318 | }//template model |
333 | | - |
334 | | - |
335 | | - |
336 | | - |
337 | | - |
338 | 319 | } |
339 | 320 | |
340 | 321 | }; } )( jQuery ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js |
— | — | @@ -34,10 +34,10 @@ |
35 | 35 | * ; Definition |
36 | 36 | * : Definition |
37 | 37 | */ |
38 | | - if(event.data.scope == 'do_not_trigger'){ |
39 | | - $.wikiEditor.modules.highlight.fn.scan(context, ""); |
40 | | - $.wikiEditor.modules.highlight.fn.mark(context, "", ""); |
41 | | - } |
| 38 | + if ( event.data.scope == 'do_not_trigger' ) { |
| 39 | + $.wikiEditor.modules.highlight.fn.scan( context, "" ); |
| 40 | + $.wikiEditor.modules.highlight.fn.mark( context, "", "" ); |
| 41 | + } |
42 | 42 | } |
43 | 43 | }, |
44 | 44 | |
— | — | @@ -67,40 +67,40 @@ |
68 | 68 | strip: function( context, division ) { |
69 | 69 | return $( '<div />' ).html( division.html().replace( /\<br[^\>]*\>/g, "\n" ) ).text(); |
70 | 70 | }, |
71 | | - tokenArray : [], |
| 71 | + tokenArray: [], |
72 | 72 | scan: function( context, division ) { |
73 | | - /* |
74 | | - * We need to look over some text and find interesting areas, then return the positions of those areas as tokens |
75 | | - */ |
76 | | - token = function(offset, label){ |
| 73 | + // We need to look over some text and find interesting areas, then return the |
| 74 | + // positions of those areas as tokens |
| 75 | + function Token( offset, label ) { |
77 | 76 | this.offset = offset; |
78 | 77 | this.label = label; |
79 | 78 | } |
80 | 79 | |
81 | | - this.tokenArray = new Array(); |
| 80 | + this.tokenArray = []; |
82 | 81 | var text = context.fn.getContents(); |
83 | 82 | for ( module in $.wikiEditor.modules ) { |
84 | 83 | if ( 'exp' in $.wikiEditor.modules[module] ) { |
85 | | - for(var i = 0; i < $.wikiEditor.modules[module].exp.length; i++){ |
| 84 | + for ( var i = 0; i < $.wikiEditor.modules[module].exp.length; i++ ) { |
86 | 85 | var regex = $.wikiEditor.modules[module].exp[i].regex; |
87 | 86 | var label = $.wikiEditor.modules[module].exp[i].label; |
88 | 87 | var markAfter = false; |
89 | | - if(typeof($.wikiEditor.modules[module].exp[i].markAfter) != 'undefined'){ |
| 88 | + if ( typeof $.wikiEditor.modules[module].exp[i].markAfter != 'undefined' ) { |
90 | 89 | markAfter = true; |
91 | 90 | } |
92 | | - match = text.match(regex); |
| 91 | + match = text.match( regex ); |
93 | 92 | var oldOffset = 0; |
94 | | - while(match != null){ |
| 93 | + while ( match != null ) { |
95 | 94 | var markOffset = 0; |
96 | | - if(markAfter){ |
| 95 | + if ( markAfter ) { |
97 | 96 | markOffset += match[0].length; |
98 | 97 | } |
99 | | - this.tokenArray.push(new token(match.index + oldOffset + markOffset, label)); |
100 | | - oldOffset += (match.index + match[0].length); |
101 | | - newSubstring = text.substring(oldOffset); |
102 | | - match = newSubstring.match(regex); |
| 98 | + this.tokenArray.push( new Token( |
| 99 | + match.index + oldOffset + markOffset, label ) ); |
| 100 | + oldOffset += match.index + match[0].length; |
| 101 | + newSubstring = text.substring( oldOffset ); |
| 102 | + match = newSubstring.match( regex ); |
103 | 103 | } |
104 | | - } |
| 104 | + } |
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
— | — | @@ -108,34 +108,31 @@ |
109 | 109 | }, |
110 | 110 | markers: [], |
111 | 111 | mark: function( context, division, tokens ) { |
112 | | - /* |
113 | | - * We need to markup some text based on some tokens |
114 | | - */ |
| 112 | + // We need to markup some text based on some tokens |
115 | 113 | var rawText = context.fn.getContents(); |
116 | 114 | |
117 | | - |
118 | 115 | //get all markers |
119 | 116 | for ( module in $.wikiEditor.modules ) { |
120 | | - if ( 'evt' in $.wikiEditor.modules[module] && 'mark' in $.wikiEditor.modules[module].evt) { |
| 117 | + if ( 'evt' in $.wikiEditor.modules[module] && 'mark' in $.wikiEditor.modules[module].evt ) { |
121 | 118 | $.wikiEditor.modules[module].evt.mark(); |
122 | 119 | } |
123 | 120 | } |
124 | 121 | markedText = ""; |
125 | 122 | var previousIndex = 0; |
126 | | - for(var currentIndex in this.markers){ |
127 | | - markedText+= rawText.substring(previousIndex, currentIndex); |
| 123 | + for ( var i = 0; i < this.markers.length; i++ ) { |
| 124 | + markedText += rawText.substring( previousIndex, currentIndex ); |
128 | 125 | |
129 | | - for(var i = 0 ; i < this.markers[currentIndex].length; i++){ |
130 | | - markedText += this.markers[currentIndex][i]; |
| 126 | + for ( var j = 0 ; i < this.markers[i].length; j++ ) { |
| 127 | + markedText += this.markers[i][j]; |
131 | 128 | } |
132 | 129 | |
133 | 130 | previousIndex = currentIndex; |
134 | 131 | } |
135 | | - if(markedText != ""){ |
136 | | - markedText.replace(/\n/g, '<br\>'); |
137 | | - context.fn.setContents({contents:markedText}); |
| 132 | + if ( markedText != "" ) { |
| 133 | + markedText.replace( /\n/g, '<br>' ); |
| 134 | + context.fn.setContents( { contents:markedText } ); |
138 | 135 | } |
139 | | - }//endmark |
| 136 | + } |
140 | 137 | } |
141 | 138 | |
142 | 139 | }; })( jQuery ); |
\ No newline at end of file |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -2136,10 +2136,10 @@ |
2137 | 2137 | * ; Definition |
2138 | 2138 | * : Definition |
2139 | 2139 | */ |
2140 | | - if(event.data.scope == 'do_not_trigger'){ |
2141 | | - $.wikiEditor.modules.highlight.fn.scan(context, ""); |
2142 | | - $.wikiEditor.modules.highlight.fn.mark(context, "", ""); |
2143 | | - } |
| 2140 | + if ( event.data.scope == 'do_not_trigger' ) { |
| 2141 | + $.wikiEditor.modules.highlight.fn.scan( context, "" ); |
| 2142 | + $.wikiEditor.modules.highlight.fn.mark( context, "", "" ); |
| 2143 | + } |
2144 | 2144 | } |
2145 | 2145 | }, |
2146 | 2146 | |
— | — | @@ -2169,40 +2169,40 @@ |
2170 | 2170 | strip: function( context, division ) { |
2171 | 2171 | return $( '<div />' ).html( division.html().replace( /\<br[^\>]*\>/g, "\n" ) ).text(); |
2172 | 2172 | }, |
2173 | | - tokenArray : [], |
| 2173 | + tokenArray: [], |
2174 | 2174 | scan: function( context, division ) { |
2175 | | - /* |
2176 | | - * We need to look over some text and find interesting areas, then return the positions of those areas as tokens |
2177 | | - */ |
2178 | | - token = function(offset, label){ |
| 2175 | + // We need to look over some text and find interesting areas, then return the |
| 2176 | + // positions of those areas as tokens |
| 2177 | + function Token( offset, label ) { |
2179 | 2178 | this.offset = offset; |
2180 | 2179 | this.label = label; |
2181 | 2180 | } |
2182 | 2181 | |
2183 | | - this.tokenArray = new Array(); |
| 2182 | + this.tokenArray = []; |
2184 | 2183 | var text = context.fn.getContents(); |
2185 | 2184 | for ( module in $.wikiEditor.modules ) { |
2186 | 2185 | if ( 'exp' in $.wikiEditor.modules[module] ) { |
2187 | | - for(var i = 0; i < $.wikiEditor.modules[module].exp.length; i++){ |
| 2186 | + for ( var i = 0; i < $.wikiEditor.modules[module].exp.length; i++ ) { |
2188 | 2187 | var regex = $.wikiEditor.modules[module].exp[i].regex; |
2189 | 2188 | var label = $.wikiEditor.modules[module].exp[i].label; |
2190 | 2189 | var markAfter = false; |
2191 | | - if(typeof($.wikiEditor.modules[module].exp[i].markAfter) != 'undefined'){ |
| 2190 | + if ( typeof $.wikiEditor.modules[module].exp[i].markAfter != 'undefined' ) { |
2192 | 2191 | markAfter = true; |
2193 | 2192 | } |
2194 | | - match = text.match(regex); |
| 2193 | + match = text.match( regex ); |
2195 | 2194 | var oldOffset = 0; |
2196 | | - while(match != null){ |
| 2195 | + while ( match != null ) { |
2197 | 2196 | var markOffset = 0; |
2198 | | - if(markAfter){ |
| 2197 | + if ( markAfter ) { |
2199 | 2198 | markOffset += match[0].length; |
2200 | 2199 | } |
2201 | | - this.tokenArray.push(new token(match.index + oldOffset + markOffset, label)); |
2202 | | - oldOffset += (match.index + match[0].length); |
2203 | | - newSubstring = text.substring(oldOffset); |
2204 | | - match = newSubstring.match(regex); |
| 2200 | + this.tokenArray.push( new Token( |
| 2201 | + match.index + oldOffset + markOffset, label ) ); |
| 2202 | + oldOffset += match.index + match[0].length; |
| 2203 | + newSubstring = text.substring( oldOffset ); |
| 2204 | + match = newSubstring.match( regex ); |
2205 | 2205 | } |
2206 | | - } |
| 2206 | + } |
2207 | 2207 | } |
2208 | 2208 | } |
2209 | 2209 | |
— | — | @@ -2210,34 +2210,31 @@ |
2211 | 2211 | }, |
2212 | 2212 | markers: [], |
2213 | 2213 | mark: function( context, division, tokens ) { |
2214 | | - /* |
2215 | | - * We need to markup some text based on some tokens |
2216 | | - */ |
| 2214 | + // We need to markup some text based on some tokens |
2217 | 2215 | var rawText = context.fn.getContents(); |
2218 | 2216 | |
2219 | | - |
2220 | 2217 | //get all markers |
2221 | 2218 | for ( module in $.wikiEditor.modules ) { |
2222 | | - if ( 'evt' in $.wikiEditor.modules[module] && 'mark' in $.wikiEditor.modules[module].evt) { |
| 2219 | + if ( 'evt' in $.wikiEditor.modules[module] && 'mark' in $.wikiEditor.modules[module].evt ) { |
2223 | 2220 | $.wikiEditor.modules[module].evt.mark(); |
2224 | 2221 | } |
2225 | 2222 | } |
2226 | 2223 | markedText = ""; |
2227 | 2224 | var previousIndex = 0; |
2228 | | - for(var currentIndex in this.markers){ |
2229 | | - markedText+= rawText.substring(previousIndex, currentIndex); |
| 2225 | + for ( var i = 0; i < this.markers.length; i++ ) { |
| 2226 | + markedText += rawText.substring( previousIndex, currentIndex ); |
2230 | 2227 | |
2231 | | - for(var i = 0 ; i < this.markers[currentIndex].length; i++){ |
2232 | | - markedText += this.markers[currentIndex][i]; |
| 2228 | + for ( var j = 0 ; i < this.markers[i].length; j++ ) { |
| 2229 | + markedText += this.markers[i][j]; |
2233 | 2230 | } |
2234 | 2231 | |
2235 | 2232 | previousIndex = currentIndex; |
2236 | 2233 | } |
2237 | | - if(markedText != ""){ |
2238 | | - markedText.replace(/\n/g, '<br\>'); |
2239 | | - context.fn.setContents({contents:markedText}); |
| 2234 | + if ( markedText != "" ) { |
| 2235 | + markedText.replace( /\n/g, '<br>' ); |
| 2236 | + context.fn.setContents( { contents:markedText } ); |
2240 | 2237 | } |
2241 | | - }//endmark |
| 2238 | + } |
2242 | 2239 | } |
2243 | 2240 | |
2244 | 2241 | }; })( jQuery );/* Preview module for wikiEditor */ |
— | — | @@ -2497,7 +2494,328 @@ |
2498 | 2495 | } |
2499 | 2496 | } |
2500 | 2497 | |
2501 | | -}; } )( jQuery );/* TOC Module for wikiEditor */ |
| 2498 | +}; } )( jQuery );/* template forms module for wikiEditor */ |
| 2499 | +( function( $ ) { $.wikiEditor.modules.templateEditor = { |
| 2500 | + |
| 2501 | +/** |
| 2502 | + * API accessible functions |
| 2503 | + */ |
| 2504 | +api: { |
| 2505 | + // |
| 2506 | +}, |
| 2507 | + |
| 2508 | +evt: { |
| 2509 | + mark: function() { |
| 2510 | + function findOutermostTemplates( tokenStack ) { |
| 2511 | + var templateBeginFound = false; |
| 2512 | + for ( ;i< tokenStack.length; i++ ) { |
| 2513 | + if ( tokenStack[i].label == "TEMPLATE_BEGIN" ) { |
| 2514 | + templateBeginFound = true; |
| 2515 | + break; |
| 2516 | + } |
| 2517 | + } |
| 2518 | + var j = i; |
| 2519 | + i++; |
| 2520 | + if ( !templateBeginFound ) { |
| 2521 | + return false; |
| 2522 | + } else { |
| 2523 | + // This is only designed to find the outermost template boundaries, the model handles nested template |
| 2524 | + // and template-like objects better |
| 2525 | + var nestedBegins = 1; |
| 2526 | + while ( nestedBegins > 0 && j < tokenStack.length ) { |
| 2527 | + j++; |
| 2528 | + if ( tokenStack[j].label == "TEMPLATE_END" ) { |
| 2529 | + nestedBegins--; |
| 2530 | + } |
| 2531 | + if ( tokenStack[j].label == "TEMPLATE_BEGIN" ) { |
| 2532 | + nestedBegins++; |
| 2533 | + } |
| 2534 | + } |
| 2535 | + if ( nestedBegins == 0 ) { |
| 2536 | + // outer template begins at tokenStack[i].offset |
| 2537 | + // and ends at tokenStack[j].offset + 2 |
| 2538 | + var leftMarker = i -1; |
| 2539 | + var rightMarker = j; |
| 2540 | + i = j; |
| 2541 | + return [ leftMarker, rightMarker ]; |
| 2542 | + } else { |
| 2543 | + return false; |
| 2544 | + } |
| 2545 | + } |
| 2546 | + }; //find outermost templates |
| 2547 | + |
| 2548 | + var markers = $.wikiEditor.modules.highlight.fn.markers; |
| 2549 | + var tokenStack = $.wikiEditor.modules.highlight.fn.tokenArray; |
| 2550 | + var i = 0; |
| 2551 | + var templateBoundaries; |
| 2552 | + var templateBeginFound = false; |
| 2553 | + |
| 2554 | + while ( templateBoundaries = findOutermostTemplates( tokenStack ) ) { |
| 2555 | + if ( typeof markers[tokenStack[templateBoundaries[0]].offset] == 'undefined' ) { |
| 2556 | + markers[tokenStack[templateBoundaries[0]].offset] = []; |
| 2557 | + } |
| 2558 | + if ( typeof markers[tokenStack[templateBoundaries[1]].offset] == 'undefined' ) { |
| 2559 | + markers[tokenStack[templateBoundaries[1]].offset] = []; |
| 2560 | + } |
| 2561 | + |
| 2562 | + markers[tokenStack[templateBoundaries[0]].offset].push( "<div class='wiki-template'>" ); |
| 2563 | + markers[tokenStack[templateBoundaries[1]].offset].push( "</div>" ); |
| 2564 | + } |
| 2565 | + } |
| 2566 | +}, |
| 2567 | + |
| 2568 | +exp: [ |
| 2569 | + { regex: /{{/, label: "TEMPLATE_BEGIN" }, |
| 2570 | + { regex: /}}/, label: "TEMPLATE_END", markAfter: true } |
| 2571 | +], |
| 2572 | + |
| 2573 | +/** |
| 2574 | + * Internally used functions |
| 2575 | + */ |
| 2576 | +fn: { |
| 2577 | + /** |
| 2578 | + * Creates template form module within wikieditor |
| 2579 | + * @param context Context object of editor to create module in |
| 2580 | + * @param config Configuration object to create module from |
| 2581 | + */ |
| 2582 | + create: function( context, config ) { |
| 2583 | + |
| 2584 | + // check if text is selected |
| 2585 | + }, |
| 2586 | + |
| 2587 | + //template Model |
| 2588 | + model: function( wikitext ) { |
| 2589 | + // Param object |
| 2590 | + function Param( name, value, number, nameIndex, equalsIndex, valueIndex ) { |
| 2591 | + this.name = name; |
| 2592 | + this.value = value; |
| 2593 | + this.number = number; |
| 2594 | + this.nameIndex = nameIndex; |
| 2595 | + this.equalsIndex = equalsIndex; |
| 2596 | + this.valueIndex = valueIndex; |
| 2597 | + } |
| 2598 | + |
| 2599 | + // Range object |
| 2600 | + function Range( begin, end ) { |
| 2601 | + this.begin = begin; |
| 2602 | + this.end = end; |
| 2603 | + } |
| 2604 | + |
| 2605 | + var ranges = []; |
| 2606 | + var sanatizedStr = ""; |
| 2607 | + var params = []; |
| 2608 | + var paramsByName = []; |
| 2609 | + var templateNameIndex = 0; |
| 2610 | + |
| 2611 | + function markOffTemplates() { |
| 2612 | + sanatizedStr = wikitext.replace( /{{/, " " ); //get rid of first {{ with whitespace |
| 2613 | + endBraces = sanatizedStr.match( /}}\s*$/ ); //replace end |
| 2614 | + sanatizedStr = sanatizedStr.substring( 0, endBraces.index ) + " " + |
| 2615 | + sanatizedStr.substring( endBraces.index + 2 ); |
| 2616 | + |
| 2617 | + while ( sanatizedStr.indexOf( '{{' ) != -1 ) { |
| 2618 | + startIndex = sanatizedStr.indexOf('{{') + 1; |
| 2619 | + openBraces = 2; |
| 2620 | + endIndex = startIndex; |
| 2621 | + while ( openBraces > 0 ) { |
| 2622 | + endIndex++; |
| 2623 | + switch ( sanatizedStr[endIndex] ) { |
| 2624 | + case '}': openBraces--; break; |
| 2625 | + case '{': openBraces++; break; |
| 2626 | + } |
| 2627 | + } |
| 2628 | + sanatizedSegment = sanatizedStr.substring( startIndex,endIndex ) |
| 2629 | + .replace( /[{}|=]/g 'X' ); |
| 2630 | + sanatizedStr = sanatizedStr.substring( 0, startIndex ) + |
| 2631 | + sanatizedSegment + sanatizedStr.substring( endIndex ); |
| 2632 | + }; |
| 2633 | + |
| 2634 | + // Whitespace* {{ whitespace* nonwhitespace: |
| 2635 | + if ( wikitext.match( /\s*{{\s*\S*:/ ) ) { |
| 2636 | + // we have a parser function! |
| 2637 | + } |
| 2638 | + |
| 2639 | + markOffTemplates(); |
| 2640 | + |
| 2641 | + var doneParsing = false; |
| 2642 | + oldDivider = 0; |
| 2643 | + divider = sanatizedStr.indexOf( '|', oldDivider ); |
| 2644 | + if ( divider == -1 ) { |
| 2645 | + divider = sanatizedStr.length; |
| 2646 | + doneParsing = true; |
| 2647 | + } |
| 2648 | + nameMatch = wikitext.substring( oldDivider, divider ).match( /[^{\s]+/ ); |
| 2649 | + if(nameMatch != undefined){ |
| 2650 | + ranges.push( new Range( oldDivider,nameMatch.index ) ); //whitespace and squiggles upto the name |
| 2651 | + templateNameIndex = ranges.push( new Range( nameMatch.index, |
| 2652 | + nameMatch.index + nameMatch[0].length ) ); |
| 2653 | + templateNameIndex--; //push returns 1 less than the array |
| 2654 | + ranges[templateNameIndex].old = wikitext.substring( ranges[templateNameIndex].begin, |
| 2655 | + ranges[templateNameIndex].end ); |
| 2656 | + } |
| 2657 | + params.push( ranges[templateNameIndex].old ); //put something in params (0) |
| 2658 | + |
| 2659 | + currentParamNumber = 0; |
| 2660 | + var valueEndIndex; |
| 2661 | + while ( !doneParsing ) { |
| 2662 | + currentParamNumber++; |
| 2663 | + oldDivider = divider; |
| 2664 | + divider = sanatizedStr.indexOf( '|', oldDivider + 1 ); |
| 2665 | + if ( divider == -1 ) { |
| 2666 | + divider = sanatizedStr.length; |
| 2667 | + doneParsing = true; |
| 2668 | + } |
| 2669 | + currentField = sanatizedStr.substring( oldDivider+1, divider ); |
| 2670 | + if ( currentField.indexOf( '=' ) == -1 ) { |
| 2671 | + // anonymous field, gets a number |
| 2672 | + valueBegin = currentField.match( /\S+/ ); //first nonwhitespace character |
| 2673 | + valueBeginIndex = valueBegin.index + oldDivider + 1; |
| 2674 | + valueEnd = currentField.match( /[^\s]\s*$/ ); //last nonwhitespace character |
| 2675 | + valueEndIndex = valueEnd.index + oldDivider + 2; |
| 2676 | + ranges.push( new Range( ranges[ranges.length-1].end, |
| 2677 | + valueBeginIndex ) ); //all the chars upto now |
| 2678 | + nameIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ); |
| 2679 | + nameIndex--; |
| 2680 | + equalsIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) ); |
| 2681 | + equalsIndex--; |
| 2682 | + valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ); |
| 2683 | + valueIndex--; |
| 2684 | + params.push( new Param( currentParamNumber, |
| 2685 | + wikitext.substring( ranges[valueIndex].begin, ranges[valueIndex].end ), |
| 2686 | + currentParamNumber, nameIndex, equalsIndex, valueIndex ) ); |
| 2687 | + paramsByName[currentParamNumber] = currentParamNumber; |
| 2688 | + } else { |
| 2689 | + // there's an equals, could be comment or a value pair |
| 2690 | + currentName = currentField.substring( 0, currentField.indexOf( '=' ) ); |
| 2691 | + // (still offset by oldDivider) |
| 2692 | + nameBegin = currentName.match( /\S+/ ); //first nonwhitespace character |
| 2693 | + if ( nameBegin == null ) { |
| 2694 | + divider++; |
| 2695 | + currentParamNumber--; |
| 2696 | + continue; |
| 2697 | + } // this is a comment inside a template call/parser abuse. let's not encourage it |
| 2698 | + nameBeginIndex = nameBegin.index + oldDivider + 1; |
| 2699 | + nameEnd = currentName.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character |
| 2700 | + nameEndIndex = nameEnd.index + oldDivider + 2; |
| 2701 | + |
| 2702 | + ranges.push( new Range( ranges[ranges.length-1].end, |
| 2703 | + nameBeginIndex ) ); //all the chars upto now |
| 2704 | + nameIndex = ranges.push( new Range( nameBeginIndex, nameEndIndex ) ); |
| 2705 | + nameIndex--; |
| 2706 | + currentValue = currentField.substring( currentField.indexOf( '=' ) + 1); |
| 2707 | + oldDivider += currentField.indexOf( '=' ) + 1; |
| 2708 | + valueBegin = currentValue.match( /\S+/ ); //first nonwhitespace character |
| 2709 | + valueBeginIndex = valueBegin.index + oldDivider + 1; |
| 2710 | + valueEnd = currentValue.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character |
| 2711 | + valueEndIndex = valueEnd.index + oldDivider + 2; |
| 2712 | + equalsIndex = ranges.push( new Range( ranges[ranges.length-1].end, |
| 2713 | + valueBeginIndex) ); //all the chars upto now |
| 2714 | + equalsIndex--; |
| 2715 | + valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ); |
| 2716 | + valueIndex--; |
| 2717 | + params.push( new Param( wikitext.substring( nameBeginIndex, nameEndIndex ), |
| 2718 | + wikitext.substring( valueBeginIndex, valueEndIndex ), |
| 2719 | + currentParamNumber, nameIndex, equalsIndex, valueIndex ) ); |
| 2720 | + paramsByName[wikitext.substring( nameBeginIndex, nameEndIndex )] = currentParamNumber; |
| 2721 | + } |
| 2722 | + } |
| 2723 | + //the rest of the string |
| 2724 | + ranges.push( new Range( valueEndIndex, wikitext.length ) ); |
| 2725 | + |
| 2726 | + //FUNCTIONS |
| 2727 | + //set 'original' to true if you want the original value irrespective of whether the model's been changed |
| 2728 | + function getSetValue( name, value, original ) { |
| 2729 | + var valueRange; |
| 2730 | + var rangeIndex; |
| 2731 | + var retVal; |
| 2732 | + if ( isNaN( name ) ) { |
| 2733 | + // it's a string! |
| 2734 | + if ( typeof paramsByName[name] == 'undefined' ) { |
| 2735 | + //does not exist |
| 2736 | + return ""; |
| 2737 | + } |
| 2738 | + rangeIndex = paramsByName[name]; |
| 2739 | + } else { |
| 2740 | + //it's a number! |
| 2741 | + rangeIndex = parseInt( name ); |
| 2742 | + } |
| 2743 | + |
| 2744 | + if ( typeof params[rangeIndex] == 'undefined' ) { |
| 2745 | + //does not exist |
| 2746 | + return ""; |
| 2747 | + } |
| 2748 | + valueRange = ranges[params[rangeIndex].valueIndex]; |
| 2749 | + |
| 2750 | + if ( typeof valueRange.newVal == 'undefined' || original ) { |
| 2751 | + //value unchanged, return original wikitext |
| 2752 | + retVal = wikitext.substring( valueRange.begin, valueRange.end ); |
| 2753 | + } else { |
| 2754 | + //new value exists, return new value |
| 2755 | + retVal = valueRange.newVal; |
| 2756 | + } |
| 2757 | + |
| 2758 | + if ( value != null ) { |
| 2759 | + ranges[params[rangeIndex].valueIndex].newVal = value; |
| 2760 | + } |
| 2761 | + |
| 2762 | + return retVal; |
| 2763 | + }; |
| 2764 | + |
| 2765 | + //'public' functions |
| 2766 | + |
| 2767 | + //get template name |
| 2768 | + this.getName = function() { |
| 2769 | + return ranges[templateNameIndex].newVal || |
| 2770 | + wikitext.substring( ranges[templateNameIndex].begin, |
| 2771 | + ranges[templateNameIndex].end ); |
| 2772 | + }; |
| 2773 | + |
| 2774 | + //set template name (if we want to support this) |
| 2775 | + this.setName = function( name ) { |
| 2776 | + ranges[templateNameIndex].newVal = name; |
| 2777 | + }; |
| 2778 | + |
| 2779 | + //set value for a given param name/number |
| 2780 | + this.setValue = function( name, value ) { |
| 2781 | + return getSetValue( name, value, false ); |
| 2782 | + }; |
| 2783 | + |
| 2784 | + //get value for a given param name/number |
| 2785 | + this.getValue = function( name ) { |
| 2786 | + return getSetValue( name, null, false ); |
| 2787 | + }; |
| 2788 | + |
| 2789 | + //get original value of a param |
| 2790 | + this.getOriginalValue = function( name ) { |
| 2791 | + return getSetValue( name, null, true ); |
| 2792 | + }; |
| 2793 | + |
| 2794 | + //get a list of all param names (numbers for the anonymous ones) |
| 2795 | + this.getAllParams = function() { |
| 2796 | + return paramsByName; |
| 2797 | + }; |
| 2798 | + |
| 2799 | + //get original template text |
| 2800 | + this.getOriginalText = function() { |
| 2801 | + return wikitext; |
| 2802 | + }; |
| 2803 | + |
| 2804 | + //get modified template text |
| 2805 | + this.getText = function() { |
| 2806 | + newText = ""; |
| 2807 | + for ( i = 0 ; i < ranges.length; i++ ) { |
| 2808 | + newText += ranges[i].newVal || wikitext.substring( |
| 2809 | + ranges[i].begin, ranges[i].end ); |
| 2810 | + } |
| 2811 | + return newText; |
| 2812 | + }; |
| 2813 | + }//template model |
| 2814 | +} |
| 2815 | + |
| 2816 | +}; } )( jQuery ); |
| 2817 | + |
| 2818 | + |
| 2819 | +/* TOC Module for wikiEditor */ |
2502 | 2820 | ( function( $ ) { $.wikiEditor.modules.toc = { |
2503 | 2821 | |
2504 | 2822 | /** |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -124,14 +124,14 @@ |
125 | 125 | dialogDiv.bind('dialogopen',$.wikiEditor.modules.dialogs.fn.resize).find('.ui-tabs').bind('tabsshow',function(){$(this).closest('.ui-dialog-content').each($.wikiEditor.modules.dialogs.fn.resize);});var maxTI=0;$j('[tabindex]').each(function(){var ti=parseInt($j(this).attr('tabindex'));if(ti>maxTI) |
126 | 126 | 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'))- |
127 | 127 | (wrapper.width()-oldWidth)/2);} |
128 | | -$(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={api:{},evt:{change:function(context,event){if(event.data.scope=='do_not_trigger'){$.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();},tokenArray:[],scan:function(context,division){token=function(offset,label){this.offset=offset;this.label=label;} |
129 | | -this.tokenArray=new Array();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;} |
| 128 | +$(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={api:{},evt:{change:function(context,event){if(event.data.scope=='do_not_trigger'){$.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();},tokenArray:[],scan:function(context,division){function Token(offset,label){this.offset=offset;this.label=label;} |
| 129 | +this.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;} |
130 | 130 | match=text.match(regex);var oldOffset=0;while(match!=null){var markOffset=0;if(markAfter){markOffset+=match[0].length;} |
131 | | -this.tokenArray.push(new token(match.index+oldOffset+markOffset,label));oldOffset+=(match.index+match[0].length);newSubstring=text.substring(oldOffset);match=newSubstring.match(regex);}}}} |
| 131 | +this.tokenArray.push(new Token(match.index+oldOffset+markOffset,label));oldOffset+=match.index+match[0].length;newSubstring=text.substring(oldOffset);match=newSubstring.match(regex);}}}} |
132 | 132 | return this.tokenArray;},markers:[],mark:function(context,division,tokens){var rawText=context.fn.getContents();for(module in $.wikiEditor.modules){if('evt'in $.wikiEditor.modules[module]&&'mark'in $.wikiEditor.modules[module].evt){$.wikiEditor.modules[module].evt.mark();}} |
133 | | -markedText="";var previousIndex=0;for(var currentIndex in this.markers){markedText+=rawText.substring(previousIndex,currentIndex);for(var i=0;i<this.markers[currentIndex].length;i++){markedText+=this.markers[currentIndex][i];} |
| 133 | +markedText="";var previousIndex=0;for(var i=0;i<this.markers.length;i++){markedText+=rawText.substring(previousIndex,currentIndex);for(var j=0;i<this.markers[i].length;j++){markedText+=this.markers[i][j];} |
134 | 134 | previousIndex=currentIndex;} |
135 | | -if(markedText!=""){markedText.replace(/\n/g,'<br\>');context.fn.setContents({contents:markedText});}}}};})(jQuery);(function($){$.wikiEditor.modules.preview={api:{},fn:{create:function(context,config){if('initialized'in context.modules.preview){return;} |
| 135 | +if(markedText!=""){markedText.replace(/\n/g,'<br>');context.fn.setContents({contents:markedText});}}}};})(jQuery);(function($){$.wikiEditor.modules.preview={api:{},fn:{create:function(context,config){if('initialized'in context.modules.preview){return;} |
136 | 136 | 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;} |
137 | 137 | context.modules.preview.$preview.find('.wikiEditor-preview-contents').empty();context.modules.preview.$preview.find('.wikiEditor-preview-loading').show();$.post(wgScriptPath+'/api.php',{'action':'parse','title':wgPageName,'text':wikitext,'prop':'text','pst':'','format':'json'},function(data){if(typeof data.parse=='undefined'||typeof data.parse.text=='undefined'||typeof data.parse.text['*']=='undefined'){return;} |
138 | 138 | context.modules.preview.previewText=wikitext;context.modules.preview.$preview.find('.wikiEditor-preview-loading').hide();context.modules.preview.$preview.find('.wikiEditor-preview-contents').html(data.parse.text['*']).find('a:not([href^=#])').click(function(){return false;});},'json');}});context.$changesTab=context.fn.addView({'name':'changes','titleMsg':'wikieditor-preview-changes-tab','init':function(context){var wikitext=context.fn.getContents();if(context.modules.preview.changesText==wikitext){return;} |
— | — | @@ -161,7 +161,29 @@ |
162 | 162 | $('#wikiEditor-'+context.instance+'-dialog-minor').hide();else if($('#wpMinoredit').is(':checked')) |
163 | 163 | $('#wikiEditor-'+context.instance+'-dialog-minor').attr('checked','checked');if($('#wpWatchthis').size()==0) |
164 | 164 | $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked')) |
165 | | -$('#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.toc={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()- |
| 165 | +$('#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={api:{},evt:{mark:function(){function findOutermostTemplates(tokenStack){var templateBeginFound=false;for(;i<tokenStack.length;i++){if(tokenStack[i].label=="TEMPLATE_BEGIN"){templateBeginFound=true;break;}} |
| 166 | +var j=i;i++;if(!templateBeginFound){return false;}else{var nestedBegins=1;while(nestedBegins>0&&j<tokenStack.length){j++;if(tokenStack[j].label=="TEMPLATE_END"){nestedBegins--;} |
| 167 | +if(tokenStack[j].label=="TEMPLATE_BEGIN"){nestedBegins++;}} |
| 168 | +if(nestedBegins==0){var leftMarker=i-1;var rightMarker=j;i=j;return[leftMarker,rightMarker];}else{return false;}}};var markers=$.wikiEditor.modules.highlight.fn.markers;var tokenStack=$.wikiEditor.modules.highlight.fn.tokenArray;var i=0;var templateBoundaries;var templateBeginFound=false;while(templateBoundaries=findOutermostTemplates(tokenStack)){if(typeof markers[tokenStack[templateBoundaries[0]].offset]=='undefined'){markers[tokenStack[templateBoundaries[0]].offset]=[];} |
| 169 | +if(typeof markers[tokenStack[templateBoundaries[1]].offset]=='undefined'){markers[tokenStack[templateBoundaries[1]].offset]=[];} |
| 170 | +markers[tokenStack[templateBoundaries[0]].offset].push("<div class='wiki-template'>");markers[tokenStack[templateBoundaries[1]].offset].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;} |
| 171 | +function Range(begin,end){this.begin=begin;this.end=end;} |
| 172 | +var ranges=[];var sanatizedStr="";var params=[];var paramsByName=[];var templateNameIndex=0;function markOffTemplates(){sanatizedStr=wikitext.replace(/{{/," ");endBraces=sanatizedStr.match(/}}\s*$/);sanatizedStr=sanatizedStr.substring(0,endBraces.index)+" "+ |
| 173 | +sanatizedStr.substring(endBraces.index+2);while(sanatizedStr.indexOf('{{')!=-1){startIndex=sanatizedStr.indexOf('{{')+1;openBraces=2;endIndex=startIndex;while(openBraces>0){endIndex++;switch(sanatizedStr[endIndex]){case'}':openBraces--;break;case'{':openBraces++;break;}} |
| 174 | +sanatizedSegment=sanatizedStr.substring(startIndex,endIndex).replace(/[{}|=]/g'X');sanatizedStr=sanatizedStr.substring(0,startIndex)+ |
| 175 | +sanatizedSegment+sanatizedStr.substring(endIndex);};if(wikitext.match(/\s*{{\s*\S*:/)){} |
| 176 | +markOffTemplates();var doneParsing=false;oldDivider=0;divider=sanatizedStr.indexOf('|',oldDivider);if(divider==-1){divider=sanatizedStr.length;doneParsing=true;} |
| 177 | +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);} |
| 178 | +params.push(ranges[templateNameIndex].old);currentParamNumber=0;var valueEndIndex;while(!doneParsing){currentParamNumber++;oldDivider=divider;divider=sanatizedStr.indexOf('|',oldDivider+1);if(divider==-1){divider=sanatizedStr.length;doneParsing=true;} |
| 179 | +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;} |
| 180 | +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));nameIndex--;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));equalsIndex--;valueIndex=ranges.push(new Range(valueBeginIndex,valueEndIndex));valueIndex--;params.push(new Param(wikitext.substring(nameBeginIndex,nameEndIndex),wikitext.substring(valueBeginIndex,valueEndIndex),currentParamNumber,nameIndex,equalsIndex,valueIndex));paramsByName[wikitext.substring(nameBeginIndex,nameEndIndex)]=currentParamNumber;}} |
| 181 | +ranges.push(new Range(valueEndIndex,wikitext.length));function getSetValue(name,value,original){var valueRange;var rangeIndex;var retVal;if(isNaN(name)){if(typeof paramsByName[name]=='undefined'){return"";} |
| 182 | +rangeIndex=paramsByName[name];}else{rangeIndex=parseInt(name);} |
| 183 | +if(typeof params[rangeIndex]=='undefined'){return"";} |
| 184 | +valueRange=ranges[params[rangeIndex].valueIndex];if(typeof valueRange.newVal=='undefined'||original){retVal=wikitext.substring(valueRange.begin,valueRange.end);}else{retVal=valueRange.newVal;} |
| 185 | +if(value!=null){ranges[params[rangeIndex].valueIndex].newVal=value;} |
| 186 | +return retVal;};this.getName=function(){return ranges[templateNameIndex].newVal||wikitext.substring(ranges[templateNameIndex].begin,ranges[templateNameIndex].end);};this.setName=function(name){ranges[templateNameIndex].newVal=name;};this.setValue=function(name,value){return getSetValue(name,value,false);};this.getValue=function(name){return getSetValue(name,null,false);};this.getOriginalValue=function(name){return getSetValue(name,null,true);};this.getAllParams=function(){return paramsByName;};this.getOriginalText=function(){return wikitext;};this.getText=function(){newText="";for(i=0;i<ranges.length;i++){newText+=ranges[i].newVal||wikitext.substring(ranges[i].begin,ranges[i].end);} |
| 187 | +return newText;};}}};})(jQuery);(function($){$.wikiEditor.modules.toc={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()- |
166 | 188 | context.$ui.find('.tab-toc').outerHeight());}},fn:{create:function(context,config){if('$toc'in context.modules.toc){return;} |
167 | 189 | var height=context.$ui.find('.wikiEditor-ui-left').height();context.modules.toc.$toc=$('<div />').addClass('wikiEditor-ui-toc').data('context',context);context.$ui.find('.wikiEditor-ui-right').css('width',$.wikiEditor.modules.toc.defaultWidth).append(context.modules.toc.$toc);context.modules.toc.$toc.height(context.$ui.find('.wikiEditor-ui-left').height());context.$ui.find('.wikiEditor-ui-left').css('marginRight',"-"+$.wikiEditor.modules.toc.defaultWidth).children().css('marginRight',$.wikiEditor.modules.toc.defaultWidth);},unhighlight:function(context){context.modules.toc.$toc.find('div').removeClass('current');},update:function(context){$.wikiEditor.modules.toc.fn.unhighlight(context);var position=context.$textarea.textSelection('getCaretPosition');var section=0;if(context.data.outline.length>0){if(!(position<context.data.outline[0].position-1)){while(section<context.data.outline.length&&context.data.outline[section].position-1<position){section++;} |
168 | 190 | section=Math.max(0,section);} |
Index: trunk/extensions/UsabilityInitiative/Makefile |
— | — | @@ -25,6 +25,7 @@ |
26 | 26 | js/plugins/jquery.wikiEditor.highlight.js\ |
27 | 27 | js/plugins/jquery.wikiEditor.preview.js\ |
28 | 28 | js/plugins/jquery.wikiEditor.publish.js\ |
| 29 | + js/plugins/jquery.wikiEditor.templateEditor.js\ |
29 | 30 | js/plugins/jquery.wikiEditor.toc.js\ |
30 | 31 | js/plugins/jquery.wikiEditor.toolbar.js |
31 | 32 | |