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' => 35 ), |
76 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 1 ), |
| 76 | + array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 2 ), |
77 | 77 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 39 ), |
78 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 9 ), |
79 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 50 ), |
80 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 7 ), |
81 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 1 ), |
82 | | - array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 0 ), |
| 78 | + array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 10 ), |
| 79 | + array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 51 ), |
| 80 | + array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 8 ), |
| 81 | + array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 2 ), |
| 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' => 109 ), |
| 85 | + array( 'src' => 'js/plugins.combined.js', 'version' => 110 ), |
86 | 86 | ), |
87 | 87 | 'minified' => array( |
88 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 109 ), |
| 88 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 110 ), |
89 | 89 | ), |
90 | 90 | ), |
91 | 91 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.preview.js |
— | — | @@ -2,12 +2,6 @@ |
3 | 3 | ( function( $ ) { $.wikiEditor.modules.preview = { |
4 | 4 | |
5 | 5 | /** |
6 | | - * API accessible functions |
7 | | - */ |
8 | | -api: { |
9 | | - // |
10 | | -}, |
11 | | -/** |
12 | 6 | * Internally used functions |
13 | 7 | */ |
14 | 8 | fn: { |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js |
— | — | @@ -1,77 +1,77 @@ |
2 | | -/* template forms module for wikiEditor */ |
| 2 | +/* TemplateEditor module for wikiEditor */ |
3 | 3 | ( function( $ ) { $.wikiEditor.modules.templateEditor = { |
4 | 4 | |
5 | 5 | /** |
6 | | - * API accessible functions |
| 6 | + * Event handlers |
7 | 7 | */ |
8 | | -api: { |
9 | | - // |
10 | | -}, |
11 | | - |
12 | 8 | evt: { |
13 | | - mark: function() { |
14 | | - function findOutermostTemplates( tokenStack ) { |
15 | | - templateBeginFound = false; |
16 | | - for ( ;i< tokenStack.length; i++ ) { |
17 | | - if ( tokenStack[i].label == "TEMPLATE_BEGIN" ) { |
18 | | - templateBeginFound = true; |
19 | | - break; |
20 | | - } |
| 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 i = 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 ( ; i < tokenStack.length; i++ ) { |
| 22 | + if ( tokenStack[i].label == 'TEMPLATE_BEGIN' ) { |
| 23 | + templateBeginFound = true; |
| 24 | + break; |
21 | 25 | } |
22 | | - var j = i; |
23 | | - i++; |
24 | | - if ( !templateBeginFound ) { |
| 26 | + } |
| 27 | + var j = i++; |
| 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; |
| 37 | + } |
| 38 | + if ( nestedBegins == 0 ) { |
| 39 | + // Outer template begins at tokenStack[i].offset and ends at tokenStack[j].offset + 2 |
| 40 | + var leftMarker = i -1; |
| 41 | + var rightMarker = j; |
| 42 | + i = j; |
| 43 | + return [leftMarker, rightMarker]; |
| 44 | + } else { |
25 | 45 | return false; |
26 | | - } else { |
27 | | - // This is only designed to find the outermost template boundaries, the model handles nested template |
28 | | - // and template-like objects better |
29 | | - var nestedBegins = 1; |
30 | | - while ( nestedBegins > 0 && j < tokenStack.length ) { |
31 | | - j++; |
32 | | - if ( tokenStack[j].label == "TEMPLATE_END" ) { |
33 | | - nestedBegins--; |
34 | | - } |
35 | | - if ( tokenStack[j].label == "TEMPLATE_BEGIN" ) { |
36 | | - nestedBegins++; |
37 | | - } |
38 | | - } |
39 | | - if ( nestedBegins == 0 ) { |
40 | | - // outer template begins at tokenStack[i].offset |
41 | | - // and ends at tokenStack[j].offset + 2 |
42 | | - var leftMarker = i -1; |
43 | | - var rightMarker = j; |
44 | | - i = j; |
45 | | - return [ leftMarker, rightMarker ]; |
46 | | - } else { |
47 | | - return false; |
48 | | - } |
49 | 46 | } |
50 | | - }; //find outermost templates |
51 | | - |
52 | | - markers = $.wikiEditor.modules.highlight.fn.markers; |
53 | | - var tokenStack = $.wikiEditor.modules.highlight.fn.tokenArray; |
54 | | - i = 0; |
55 | | - var templateBoundaries; |
56 | | - templateBeginFound = false; |
57 | | - |
58 | | - while ( templateBoundaries = findOutermostTemplates( tokenStack ) ) { |
59 | | - if ( typeof markers[tokenStack[templateBoundaries[0]].offset] == 'undefined' ) { |
60 | | - markers[tokenStack[templateBoundaries[0]].offset] = []; |
61 | | - } |
62 | | - if ( typeof markers[tokenStack[templateBoundaries[1]].offset] == 'undefined' ) { |
63 | | - markers[tokenStack[templateBoundaries[1]].offset] = []; |
64 | | - } |
65 | | - markers[tokenStack[templateBoundaries[0]].offset].push( "<div class='wiki-template'>" ); |
66 | | - markers[tokenStack[templateBoundaries[1]].offset].push( "</div>" ); |
67 | 47 | } |
| 48 | + }; |
| 49 | + // Get the markers and tokens from the current context |
| 50 | + var markers = context.modules.highlight.data.markers; |
| 51 | + var tokenStack = context.modules.highlight.data.tokenArray; |
| 52 | + // Scan through and detect the boundries of template calls |
| 53 | + var templateBeginFound = false; |
| 54 | + var templateBoundaries; |
| 55 | + while ( templateBoundaries = findOutermostTemplates( tokenStack ) ) { |
| 56 | + // Ensure indexes exist for left and right boundry markers |
| 57 | + if ( typeof markers[tokenStack[templateBoundaries[0]].offset] == 'undefined' ) { |
| 58 | + markers[tokenStack[templateBoundaries[0]].offset] = []; |
| 59 | + } |
| 60 | + if ( typeof markers[tokenStack[templateBoundaries[1]].offset] == 'undefined' ) { |
| 61 | + markers[tokenStack[templateBoundaries[1]].offset] = []; |
| 62 | + } |
| 63 | + // Append boundry markers |
| 64 | + markers[tokenStack[templateBoundaries[0]].offset].push( "<div class='wiki-template'>" ); |
| 65 | + markers[tokenStack[templateBoundaries[1]].offset].push( "</div>" ); |
68 | 66 | } |
| 67 | + } |
69 | 68 | }, |
70 | | - |
| 69 | +/** |
| 70 | + * Regular expressions that produce tokens |
| 71 | + */ |
71 | 72 | exp: [ |
72 | | - { regex: /{{/, label: "TEMPLATE_BEGIN" }, |
73 | | - { regex: /}}/, label: "TEMPLATE_END", markAfter: true } |
| 73 | + { 'regex': /{{/, 'label': "TEMPLATE_BEGIN" }, |
| 74 | + { 'regex': /}}/, 'label': "TEMPLATE_END", 'markAfter': true } |
74 | 75 | ], |
75 | | - |
76 | 76 | /** |
77 | 77 | * Internally used functions |
78 | 78 | */ |
— | — | @@ -82,14 +82,28 @@ |
83 | 83 | * @param config Configuration object to create module from |
84 | 84 | */ |
85 | 85 | create: function( context, config ) { |
| 86 | + // Initialize module within the context |
| 87 | + }, |
| 88 | + /** |
| 89 | + * Builds a template model from given wikitext representation, allowing object-oriented manipulation of the contents |
| 90 | + * of the template while preserving whitespace and formatting. |
| 91 | + * |
| 92 | + * @param wikitext String of wikitext content |
| 93 | + */ |
| 94 | + model: function( wikitext ) { |
86 | 95 | |
87 | | - //initializations |
| 96 | + /* Private Functions */ |
88 | 97 | |
89 | | - }, |
90 | | - |
91 | | - //template Model |
92 | | - model: function( wikitext ) { |
93 | | - // Param object |
| 98 | + /** |
| 99 | + * Builds a Param object. |
| 100 | + * |
| 101 | + * @param name |
| 102 | + * @param value |
| 103 | + * @param number |
| 104 | + * @param nameIndex |
| 105 | + * @param equalsIndex |
| 106 | + * @param valueIndex |
| 107 | + */ |
94 | 108 | function Param( name, value, number, nameIndex, equalsIndex, valueIndex ) { |
95 | 109 | this.name = name; |
96 | 110 | this.value = value; |
— | — | @@ -98,56 +112,167 @@ |
99 | 113 | this.equalsIndex = equalsIndex; |
100 | 114 | this.valueIndex = valueIndex; |
101 | 115 | } |
102 | | - |
103 | | - // Range object |
| 116 | + /** |
| 117 | + * Builds a Range object. |
| 118 | + * |
| 119 | + * @param begin |
| 120 | + * @param end |
| 121 | + */ |
104 | 122 | function Range( begin, end ) { |
105 | 123 | this.begin = begin; |
106 | 124 | this.end = end; |
107 | 125 | } |
| 126 | + /** |
| 127 | + * Set 'original' to true if you want the original value irrespective of whether the model's been changed |
| 128 | + * |
| 129 | + * @param name |
| 130 | + * @param value |
| 131 | + * @param original |
| 132 | + */ |
| 133 | + function getSetValue( name, value, original ) { |
| 134 | + var valueRange; |
| 135 | + var rangeIndex; |
| 136 | + var retVal; |
| 137 | + if ( isNaN( name ) ) { |
| 138 | + // It's a string! |
| 139 | + if ( typeof paramsByName[name] == 'undefined' ) { |
| 140 | + // Does not exist |
| 141 | + return ""; |
| 142 | + } |
| 143 | + rangeIndex = paramsByName[name]; |
| 144 | + } else { |
| 145 | + // It's a number! |
| 146 | + rangeIndex = parseInt( name ); |
| 147 | + } |
| 148 | + if ( typeof params[rangeIndex] == 'undefined' ) { |
| 149 | + // Does not exist |
| 150 | + return ""; |
| 151 | + } |
| 152 | + valueRange = ranges[params[rangeIndex].valueIndex]; |
| 153 | + if ( typeof valueRange.newVal == 'undefined' || original ) { |
| 154 | + // Value unchanged, return original wikitext |
| 155 | + retVal = wikitext.substring( valueRange.begin, valueRange.end ); |
| 156 | + } else { |
| 157 | + // New value exists, return new value |
| 158 | + retVal = valueRange.newVal; |
| 159 | + } |
| 160 | + if ( value != null ) { |
| 161 | + ranges[params[rangeIndex].valueIndex].newVal = value; |
| 162 | + } |
| 163 | + return retVal; |
| 164 | + }; |
108 | 165 | |
109 | | - var ranges = []; |
110 | | - var sanatizedStr = ""; |
111 | | - var params = []; |
112 | | - var paramsByName = []; |
113 | | - var templateNameIndex = 0; |
| 166 | + /* Public Functions */ |
114 | 167 | |
115 | | - //takes all template-specific characters, namely {|=} away if they're not particular to the |
116 | | - //template we're looking at |
117 | | - function markOffTemplates() { |
118 | | - sanatizedStr = wikitext.replace( /{{/, " " ); //get rid of first {{ with whitespace |
119 | | - endBraces = sanatizedStr.match( /}}\s*$/ ); //replace end |
120 | | - sanatizedStr = sanatizedStr.substring( 0, endBraces.index ) + " " + |
121 | | - sanatizedStr.substring( endBraces.index + 2 ); |
122 | | - |
123 | | - //match the open braces we just found with equivalent closing braces |
124 | | - //note, works for any level of braces |
125 | | - while ( sanatizedStr.indexOf( '{{' ) != -1 ) { |
126 | | - startIndex = sanatizedStr.indexOf('{{') + 1; |
127 | | - openBraces = 2; |
128 | | - endIndex = startIndex; |
129 | | - while ( openBraces > 0 ) { |
130 | | - endIndex++; |
131 | | - switch ( sanatizedStr[endIndex] ) { |
132 | | - case '}': openBraces--; break; |
133 | | - case '{': openBraces++; break; |
134 | | - } |
| 168 | + /** |
| 169 | + * Get template name |
| 170 | + */ |
| 171 | + this.getName = function() { |
| 172 | + if( typeof ranges[templateNameIndex].newVal == 'undefined' ) { |
| 173 | + return wikitext.substring( ranges[templateNameIndex].begin, ranges[templateNameIndex].end ); |
| 174 | + } else { |
| 175 | + return ranges[templateNameIndex].newVal; |
| 176 | + } |
| 177 | + }; |
| 178 | + /** |
| 179 | + * Set template name (if we want to support this) |
| 180 | + * |
| 181 | + * @param name |
| 182 | + */ |
| 183 | + this.setName = function( name ) { |
| 184 | + ranges[templateNameIndex].newVal = name; |
| 185 | + }; |
| 186 | + /** |
| 187 | + * Set value for a given param name / number |
| 188 | + * |
| 189 | + * @param name |
| 190 | + * @param value |
| 191 | + */ |
| 192 | + this.setValue = function( name, value ) { |
| 193 | + return getSetValue( name, value, false ); |
| 194 | + }; |
| 195 | + /** |
| 196 | + * Get value for a given param name / number |
| 197 | + * |
| 198 | + * @param name |
| 199 | + */ |
| 200 | + this.getValue = function( name ) { |
| 201 | + return getSetValue( name, null, false ); |
| 202 | + }; |
| 203 | + /** |
| 204 | + * Get original value of a param |
| 205 | + * |
| 206 | + * @param name |
| 207 | + */ |
| 208 | + this.getOriginalValue = function( name ) { |
| 209 | + return getSetValue( name, null, true ); |
| 210 | + }; |
| 211 | + /** |
| 212 | + * Get a list of all param names (numbers for the anonymous ones) |
| 213 | + */ |
| 214 | + this.getAllParamNames = function() { |
| 215 | + return paramsByName; |
| 216 | + }; |
| 217 | + /** |
| 218 | + * Get the initial params |
| 219 | + */ |
| 220 | + this.getAllInitialParams = function(){ |
| 221 | + return params; |
| 222 | + } |
| 223 | + /** |
| 224 | + * Get original template text |
| 225 | + */ |
| 226 | + this.getOriginalText = function() { |
| 227 | + return wikitext; |
| 228 | + }; |
| 229 | + /** |
| 230 | + * Get modified template text |
| 231 | + */ |
| 232 | + this.getText = function() { |
| 233 | + newText = ""; |
| 234 | + for ( i = 0 ; i < ranges.length; i++ ) { |
| 235 | + if( typeof ranges[i].newVal == 'undefined' ) { |
| 236 | + wikitext.substring( ranges[i].begin, ranges[i].end ); |
| 237 | + } else { |
| 238 | + newText += ranges[i].newVal; |
135 | 239 | } |
136 | | - sanatizedSegment = sanatizedStr.substring( startIndex,endIndex ) |
137 | | - .replace( /[{}|=]/g , 'X' ); |
138 | | - sanatizedStr = sanatizedStr.substring( 0, startIndex ) + |
139 | | - sanatizedSegment + sanatizedStr.substring( endIndex ); |
140 | | - }//while |
141 | | - return sanatizedStr; |
| 240 | + } |
| 241 | + return newText; |
142 | 242 | }; |
143 | | - |
| 243 | + |
144 | 244 | // Whitespace* {{ whitespace* nonwhitespace: |
145 | 245 | if ( wikitext.match( /\s*{{\s*\S*:/ ) ) { |
146 | | - // we have a parser function! |
| 246 | + // We have a parser function! |
147 | 247 | } |
148 | | - |
149 | | - markOffTemplates(); |
150 | | - |
151 | | - //parse 1 param at a time |
| 248 | + /* |
| 249 | + * Take all template-specific characters that are not particular to the template we're looking at, namely {|=}, |
| 250 | + * and convert them into something harmless, in this case 'X' |
| 251 | + */ |
| 252 | + // Get rid of first {{ with whitespace |
| 253 | + var sanatizedStr = wikitext.replace( /{{/, " " ); |
| 254 | + // Replace end |
| 255 | + endBraces = sanatizedStr.match( /}}\s*$/ ); |
| 256 | + sanatizedStr = |
| 257 | + sanatizedStr.substring( 0, endBraces.index ) + " " + sanatizedStr.substring( endBraces.index + 2 ); |
| 258 | + // Match the open braces we just found with equivalent closing braces note, works for any level of braces |
| 259 | + while ( sanatizedStr.indexOf( '{{' ) != -1 ) { |
| 260 | + startIndex = sanatizedStr.indexOf('{{') + 1; |
| 261 | + openBraces = 2; |
| 262 | + endIndex = startIndex; |
| 263 | + while ( openBraces > 0 ) { |
| 264 | + var brace = sanatizedStr[++endIndex]; |
| 265 | + openBraces += brace == '}' ? -1 : brace == '{' ? 1 : 0; |
| 266 | + } |
| 267 | + sanatizedSegment = sanatizedStr.substring( startIndex,endIndex ).replace( /[{}|=]/g , 'X' ); |
| 268 | + sanatizedStr = |
| 269 | + sanatizedStr.substring( 0, startIndex ) + sanatizedSegment + sanatizedStr.substring( endIndex ); |
| 270 | + } |
| 271 | + /* |
| 272 | + * Parse 1 param at a time |
| 273 | + */ |
| 274 | + var ranges = []; |
| 275 | + var params = []; |
| 276 | + var templateNameIndex = 0; |
152 | 277 | var doneParsing = false; |
153 | 278 | oldDivider = 0; |
154 | 279 | divider = sanatizedStr.indexOf( '|', oldDivider ); |
— | — | @@ -165,11 +290,12 @@ |
166 | 291 | ranges[templateNameIndex].end ); |
167 | 292 | } |
168 | 293 | params.push( ranges[templateNameIndex].old ); //put something in params (0) |
169 | | - |
170 | | - currentParamNumber = 0; |
| 294 | + /* |
| 295 | + * Start looping over params |
| 296 | + */ |
| 297 | + var currentParamNumber = 0; |
171 | 298 | var valueEndIndex; |
172 | | - |
173 | | - //start looping over params |
| 299 | + var paramsByName = []; |
174 | 300 | while ( !doneParsing ) { |
175 | 301 | currentParamNumber++; |
176 | 302 | oldDivider = divider; |
— | — | @@ -198,147 +324,48 @@ |
199 | 325 | currentParamNumber, nameIndex, equalsIndex, valueIndex ) ); |
200 | 326 | paramsByName[currentParamNumber] = currentParamNumber; |
201 | 327 | } else { |
202 | | - // there's an equals, could be comment or a value pair |
| 328 | + // There's an equals, could be comment or a value pair |
203 | 329 | currentName = currentField.substring( 0, currentField.indexOf( '=' ) ); |
204 | | - // (still offset by oldDivider) |
205 | | - nameBegin = currentName.match( /\S+/ ); //first nonwhitespace character |
| 330 | + // Still offset by oldDivider - first nonwhitespace character |
| 331 | + nameBegin = currentName.match( /\S+/ ); |
206 | 332 | if ( nameBegin == null ) { |
207 | | - // this is a comment inside a template call/parser abuse. let's not encourage it |
| 333 | + // This is a comment inside a template call / parser abuse. let's not encourage it |
208 | 334 | divider++; |
209 | 335 | currentParamNumber--; |
210 | 336 | continue; |
211 | 337 | } |
212 | 338 | nameBeginIndex = nameBegin.index + oldDivider + 1; |
213 | | - nameEnd = currentName.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character |
| 339 | + // Last nonwhitespace and non } character |
| 340 | + nameEnd = currentName.match( /[^\s]\s*$/ ); |
214 | 341 | nameEndIndex = nameEnd.index + oldDivider + 2; |
215 | | - |
216 | | - ranges.push( new Range( ranges[ranges.length-1].end, |
217 | | - nameBeginIndex ) ); //all the chars upto now |
218 | | - nameIndex = ranges.push( new Range( nameBeginIndex, nameEndIndex ) ); |
219 | | - nameIndex--; |
| 342 | + // All the chars upto now |
| 343 | + ranges.push( new Range( ranges[ranges.length-1].end, nameBeginIndex ) ); |
| 344 | + nameIndex = ranges.push( new Range( nameBeginIndex, nameEndIndex ) ) - 1; |
220 | 345 | currentValue = currentField.substring( currentField.indexOf( '=' ) + 1); |
221 | 346 | oldDivider += currentField.indexOf( '=' ) + 1; |
222 | | - valueBegin = currentValue.match( /\S+/ ); //first nonwhitespace character |
| 347 | + // First nonwhitespace character |
| 348 | + valueBegin = currentValue.match( /\S+/ ); |
223 | 349 | valueBeginIndex = valueBegin.index + oldDivider + 1; |
224 | | - valueEnd = currentValue.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character |
| 350 | + // Last nonwhitespace and non } character |
| 351 | + valueEnd = currentValue.match( /[^\s]\s*$/ ); |
225 | 352 | valueEndIndex = valueEnd.index + oldDivider + 2; |
226 | | - equalsIndex = ranges.push( new Range( ranges[ranges.length-1].end, |
227 | | - valueBeginIndex) ); //all the chars upto now |
228 | | - equalsIndex--; |
229 | | - valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ); |
230 | | - valueIndex--; |
231 | | - params.push( new Param( wikitext.substring( nameBeginIndex, nameEndIndex ), |
| 353 | + // All the chars upto now |
| 354 | + equalsIndex = ranges.push( new Range( ranges[ranges.length-1].end, valueBeginIndex) ) - 1; |
| 355 | + valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ) - 1; |
| 356 | + params.push( new Param( |
| 357 | + wikitext.substring( nameBeginIndex, nameEndIndex ), |
232 | 358 | wikitext.substring( valueBeginIndex, valueEndIndex ), |
233 | | - currentParamNumber, nameIndex, equalsIndex, valueIndex ) ); |
| 359 | + currentParamNumber, |
| 360 | + nameIndex, |
| 361 | + equalsIndex, |
| 362 | + valueIndex |
| 363 | + ) ); |
234 | 364 | paramsByName[wikitext.substring( nameBeginIndex, nameEndIndex )] = currentParamNumber; |
235 | 365 | } |
236 | 366 | } |
237 | | - //the rest of the string |
| 367 | + // The rest of the string |
238 | 368 | ranges.push( new Range( valueEndIndex, wikitext.length ) ); |
239 | | - |
240 | | - //FUNCTIONS |
241 | | - //set 'original' to true if you want the original value irrespective of whether the model's been changed |
242 | | - function getSetValue( name, value, original ) { |
243 | | - var valueRange; |
244 | | - var rangeIndex; |
245 | | - var retVal; |
246 | | - if ( isNaN( name ) ) { |
247 | | - // it's a string! |
248 | | - if ( typeof paramsByName[name] == 'undefined' ) { |
249 | | - //does not exist |
250 | | - return ""; |
251 | | - } |
252 | | - rangeIndex = paramsByName[name]; |
253 | | - } else { |
254 | | - //it's a number! |
255 | | - rangeIndex = parseInt( name ); |
256 | | - } |
257 | | - |
258 | | - if ( typeof params[rangeIndex] == 'undefined' ) { |
259 | | - //does not exist |
260 | | - return ""; |
261 | | - } |
262 | | - valueRange = ranges[params[rangeIndex].valueIndex]; |
263 | | - |
264 | | - if ( typeof valueRange.newVal == 'undefined' || original ) { |
265 | | - //value unchanged, return original wikitext |
266 | | - retVal = wikitext.substring( valueRange.begin, valueRange.end ); |
267 | | - } else { |
268 | | - //new value exists, return new value |
269 | | - retVal = valueRange.newVal; |
270 | | - } |
271 | | - |
272 | | - if ( value != null ) { |
273 | | - ranges[params[rangeIndex].valueIndex].newVal = value; |
274 | | - } |
275 | | - |
276 | | - return retVal; |
277 | | - }; |
278 | | - |
279 | | - //'public' functions |
280 | | - |
281 | | - //get template name |
282 | | - this.getName = function() { |
283 | | - if( typeof ranges[templateNameIndex].newVal == 'undefined' ) { |
284 | | - return wikitext.substring( ranges[templateNameIndex].begin, |
285 | | - ranges[templateNameIndex].end ); |
286 | | - |
287 | | - } else { |
288 | | - return ranges[templateNameIndex].newVal; |
289 | | - } |
290 | | - }; |
291 | | - |
292 | | - //set template name (if we want to support this) |
293 | | - this.setName = function( name ) { |
294 | | - ranges[templateNameIndex].newVal = name; |
295 | | - }; |
296 | | - |
297 | | - //set value for a given param name/number |
298 | | - this.setValue = function( name, value ) { |
299 | | - return getSetValue( name, value, false ); |
300 | | - }; |
| 369 | + } // model |
| 370 | +} |
301 | 371 | |
302 | | - //get value for a given param name/number |
303 | | - this.getValue = function( name ) { |
304 | | - return getSetValue( name, null, false ); |
305 | | - }; |
306 | | - |
307 | | - //get original value of a param |
308 | | - this.getOriginalValue = function( name ) { |
309 | | - return getSetValue( name, null, true ); |
310 | | - }; |
311 | | - |
312 | | - //get a list of all param names (numbers for the anonymous ones) |
313 | | - this.getAllParamNames = function() { |
314 | | - return paramsByName; |
315 | | - }; |
316 | | - |
317 | | - //get the initial params |
318 | | - this.getAllInitialParams = function(){ |
319 | | - return params; |
320 | | - } |
321 | | - |
322 | | - //get original template text |
323 | | - this.getOriginalText = function() { |
324 | | - return wikitext; |
325 | | - }; |
326 | | - |
327 | | - //get modified template text |
328 | | - this.getText = function() { |
329 | | - newText = ""; |
330 | | - for ( i = 0 ; i < ranges.length; i++ ) { |
331 | | - if( typeof ranges[i].newVal == 'undefined' ) { |
332 | | - wikitext.substring( ranges[i].begin, ranges[i].end ); |
333 | | - } else { |
334 | | - newText += ranges[i].newVal; |
335 | | - } |
336 | | - } |
337 | | - return newText; |
338 | | - }; |
339 | | - }//template model |
340 | | - |
341 | | -}//fn |
342 | | - |
343 | 372 | }; } )( jQuery ); |
344 | | - |
345 | | - |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.dialogs.js |
— | — | @@ -69,14 +69,14 @@ |
70 | 70 | .appendTo( $( 'body' ) ) |
71 | 71 | .each( module.init ) |
72 | 72 | .dialog( configuration ); |
73 | | - if ( !( 'resizeme' in module ) || module.resizeme ) |
| 73 | + if ( !( 'resizeme' in module ) || module.resizeme ) { |
74 | 74 | dialogDiv |
75 | 75 | .bind( 'dialogopen', $.wikiEditor.modules.dialogs.fn.resize ) |
76 | 76 | .find( '.ui-tabs' ).bind( 'tabsshow', function() { |
77 | 77 | $(this).closest( '.ui-dialog-content' ).each( |
78 | 78 | $.wikiEditor.modules.dialogs.fn.resize ); |
79 | 79 | }); |
80 | | - |
| 80 | + } |
81 | 81 | // Add tabindexes to dialog form elements |
82 | 82 | // Find the highest tabindex in use |
83 | 83 | var maxTI = 0; |
— | — | @@ -96,7 +96,6 @@ |
97 | 97 | } |
98 | 98 | }); |
99 | 99 | }, |
100 | | - |
101 | 100 | /** |
102 | 101 | * Resize a dialog so its contents fit |
103 | 102 | * |
— | — | @@ -106,48 +105,37 @@ |
107 | 106 | resize: function() { |
108 | 107 | var wrapper = $(this).closest( '.ui-dialog' ); |
109 | 108 | var oldWidth = wrapper.width(); |
110 | | - // Make sure elements don't wrapped so we get an accurate idea |
111 | | - // of whether they really fit. Also temporarily show hidden |
112 | | - // elements. |
113 | | - |
114 | | - // Work around jQuery bug where <div style="display:inline;" /> |
115 | | - // inside a dialog is both :visible and :hidden |
| 109 | + // Make sure elements don't wrapped so we get an accurate idea of whether they really fit. Also temporarily show |
| 110 | + // hidden elements. Work around jQuery bug where <div style="display:inline;" /> inside a dialog is both |
| 111 | + // :visible and :hidden |
116 | 112 | var oldHidden = $(this).find( '*' ).not( ':visible' ); |
117 | | - |
118 | | - // Save the style attributes of the hidden elements to restore |
119 | | - // them later. Calling hide() after show() messes up for |
120 | | - // elements hidden with a class |
| 113 | + // Save the style attributes of the hidden elements to restore them later. Calling hide() after show() messes up |
| 114 | + // for elements hidden with a class |
121 | 115 | oldHidden.each( function() { |
122 | 116 | $(this).data( 'oldstyle', $(this).attr( 'style' ) ); |
123 | 117 | }); |
124 | 118 | oldHidden.show(); |
125 | 119 | var oldWS = $(this).css( 'white-space' ); |
126 | 120 | $(this).css( 'white-space', 'nowrap' ); |
127 | | - |
128 | 121 | if ( wrapper.width() <= $(this).get(0).scrollWidth ) { |
129 | 122 | var thisWidth = $(this).data( 'thisWidth' ) ? $(this).data( 'thisWidth' ) : 0; |
130 | 123 | thisWidth = Math.max( $(this).get(0).scrollWidth, thisWidth ); |
131 | 124 | $(this).width( thisWidth ); |
132 | 125 | $(this).data( 'thisWidth', thisWidth ); |
133 | | - |
134 | 126 | var wrapperWidth = $(this).data( 'wrapperWidth' ) ? $(this).data( 'wrapperWidth' ) : 0; |
135 | 127 | wrapperWidth = Math.max( wrapper.get(0).scrollWidth, wrapperWidth ); |
136 | 128 | wrapper.width( wrapperWidth ); |
137 | 129 | $(this).data( 'wrapperWidth', wrapperWidth ); |
138 | | - |
139 | 130 | $(this).dialog( { 'width': wrapper.width() } ); |
140 | | - wrapper.css( 'left', |
141 | | - parseInt( wrapper.css( 'left' ) ) - |
142 | | - ( wrapper.width() - oldWidth ) / 2 ); |
| 131 | + wrapper.css( 'left', parseInt( wrapper.css( 'left' ) ) - ( wrapper.width() - oldWidth ) / 2 ); |
143 | 132 | } |
144 | | - |
145 | 133 | $(this).css( 'white-space', oldWS ); |
146 | 134 | oldHidden.each( function() { |
147 | 135 | $(this).attr( 'style', $(this).data( 'oldstyle' ) ); |
148 | | - }); |
149 | | - |
| 136 | + }); |
150 | 137 | } |
151 | 138 | }, |
| 139 | +// This stuff is just hanging here, perhaps we could come up with a better home for this stuff |
152 | 140 | modules: {}, |
153 | 141 | quickDialog: function( body, settings ) { |
154 | 142 | $( '<div />' ) |
— | — | @@ -160,4 +148,4 @@ |
161 | 149 | .dialog( 'open' ); |
162 | 150 | } |
163 | 151 | |
164 | | -}; } ) ( jQuery ); |
| 152 | +}; } ) ( jQuery ); |
\ No newline at end of file |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js |
— | — | @@ -1,16 +1,16 @@ |
2 | 2 | /* TOC Module for wikiEditor */ |
3 | 3 | ( function( $ ) { $.wikiEditor.modules.toc = { |
4 | | - |
| 4 | + |
5 | 5 | /** |
6 | | - * Default width of table of contents |
| 6 | + * Configuration |
7 | 7 | */ |
8 | | -defaultWidth: '166px', |
| 8 | +cfg: { |
| 9 | + // Default width of table of contents |
| 10 | + defaultWidth: '166px', |
| 11 | + // Minimum width to allow resizing to before collapsing the table of contents - used when resizing and collapsing |
| 12 | + minimumWidth: '70px', |
| 13 | +}, |
9 | 14 | /** |
10 | | - * Minimum width to allow resizing to before collapsing the table of contents |
11 | | - * Only used if resizing and collapsing is enabled |
12 | | - */ |
13 | | -minimumWidth: '70px', |
14 | | -/** |
15 | 15 | * API accessible functions |
16 | 16 | */ |
17 | 17 | api: { |
— | — | @@ -68,15 +68,15 @@ |
69 | 69 | .addClass( 'wikiEditor-ui-toc' ) |
70 | 70 | .data( 'context', context ); |
71 | 71 | context.$ui.find( '.wikiEditor-ui-right' ) |
72 | | - .css( 'width', $.wikiEditor.modules.toc.defaultWidth ) |
| 72 | + .css( 'width', $.wikiEditor.modules.toc.cfg.defaultWidth ) |
73 | 73 | .append( context.modules.toc.$toc ); |
74 | 74 | context.modules.toc.$toc.height( |
75 | 75 | context.$ui.find( '.wikiEditor-ui-left' ).height() |
76 | 76 | ); |
77 | 77 | context.$ui.find( '.wikiEditor-ui-left' ) |
78 | | - .css( 'marginRight', "-" + $.wikiEditor.modules.toc.defaultWidth ) |
| 78 | + .css( 'marginRight', "-" + $.wikiEditor.modules.toc.cfg.defaultWidth ) |
79 | 79 | .children() |
80 | | - .css( 'marginRight', $.wikiEditor.modules.toc.defaultWidth ); |
| 80 | + .css( 'marginRight', $.wikiEditor.modules.toc.cfg.defaultWidth ); |
81 | 81 | }, |
82 | 82 | |
83 | 83 | unhighlight: function( context ) { |
— | — | @@ -280,7 +280,14 @@ |
281 | 281 | // Toss a transparent cover over our iframe |
282 | 282 | $( '<div />' ) |
283 | 283 | .addClass( 'wikiEditor-ui-resize-mask' ) |
284 | | - .css( { 'position': 'absolute', 'z-index': 2, 'left': 0, 'top': 0, 'bottom': 0, 'right': 0 } ) |
| 284 | + .css( { |
| 285 | + 'position': 'absolute', |
| 286 | + 'z-index': 2, |
| 287 | + 'left': 0, |
| 288 | + 'top': 0, |
| 289 | + 'bottom': 0, |
| 290 | + 'right': 0 |
| 291 | + } ) |
285 | 292 | .appendTo( context.$ui.find( '.wikiEditor-ui-left' ) ); |
286 | 293 | $this.resizable( 'option', 'maxWidth', $this.parent().width() - 450 ); |
287 | 294 | }, |
— | — | @@ -296,7 +303,7 @@ |
297 | 304 | stop: function ( e, ui ) { |
298 | 305 | context.$ui.find( '.wikiEditor-ui-resize-mask' ).remove(); |
299 | 306 | context.$content.trigger( 'mouseup' ); |
300 | | - if( ui.size.width < parseFloat( $.wikiEditor.modules.toc.minimumWidth ) ) { |
| 307 | + if( ui.size.width < parseFloat( $.wikiEditor.modules.toc.cfg.minimumWidth ) ) { |
301 | 308 | context.modules.toc.$toc.trigger( 'collapse' ); |
302 | 309 | } else { |
303 | 310 | context.modules.toc.$toc.data( 'openWidth', ui.size.width ); |
— | — | @@ -316,14 +323,14 @@ |
317 | 324 | context.modules.toc.$toc |
318 | 325 | .bind( 'collapse.wikiEditor-toc', $.wikiEditor.modules.toc.fn.collapse ) |
319 | 326 | .bind( 'expand.wikiEditor-toc', $.wikiEditor.modules.toc.fn.expand ); |
320 | | - context.modules.toc.$toc.data( 'openWidth', $.wikiEditor.modules.toc.defaultWidth ); |
| 327 | + context.modules.toc.$toc.data( 'openWidth', $.wikiEditor.modules.toc.cfg.defaultWidth ); |
321 | 328 | // If the toc-width cookie is set, reset the widths based upon that |
322 | 329 | if ( $.cookie( 'wikiEditor-' + context.instance + '-toc-width' ) == 0 ) { |
323 | 330 | context.modules.toc.$toc.trigger( 'collapse.wikiEditor-toc', { data: context } ); |
324 | 331 | } else if ( $.cookie( 'wikiEditor-' + context.instance + '-toc-width' ) > 0 ) { |
325 | 332 | var initialWidth = $.cookie( 'wikiEditor-' + context.instance + '-toc-width' ); |
326 | | - if( initialWidth < parseFloat( $.wikiEditor.modules.toc.minimumWidth ) ) |
327 | | - initialWidth = parseFloat( $.wikiEditor.modules.toc.minimumWidth ) + 1; |
| 333 | + if( initialWidth < parseFloat( $.wikiEditor.modules.toc.cfg.minimumWidth ) ) |
| 334 | + initialWidth = parseFloat( $.wikiEditor.modules.toc.cfg.minimumWidth ) + 1; |
328 | 335 | context.modules.toc.$toc.data( 'openWidth', initialWidth + 'px' ); |
329 | 336 | context.$ui.find( '.wikiEditor-ui-right' ) |
330 | 337 | .css( 'width', initialWidth + 'px' ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.publish.js |
— | — | @@ -2,12 +2,6 @@ |
3 | 3 | ( function( $ ) { $.wikiEditor.modules.publish = { |
4 | 4 | |
5 | 5 | /** |
6 | | - * API accessible functions |
7 | | - */ |
8 | | -api: { |
9 | | - // |
10 | | -}, |
11 | | -/** |
12 | 6 | * Internally used functions |
13 | 7 | */ |
14 | 8 | fn: { |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js |
— | — | @@ -2,12 +2,6 @@ |
3 | 3 | ( function( $ ) { $.wikiEditor.modules.highlight = { |
4 | 4 | |
5 | 5 | /** |
6 | | - * API accessible functions |
7 | | - */ |
8 | | -api: { |
9 | | - // |
10 | | -}, |
11 | | -/** |
12 | 6 | * Internally used event handlers |
13 | 7 | */ |
14 | 8 | evt: { |
— | — | @@ -40,43 +34,61 @@ |
41 | 35 | } |
42 | 36 | } |
43 | 37 | }, |
44 | | - |
45 | 38 | /** |
46 | 39 | * Internally used functions |
47 | 40 | */ |
48 | 41 | fn: { |
49 | 42 | /** |
50 | 43 | * Creates a highlight module within a wikiEditor |
51 | | - * @param context Context object of editor to create module in |
| 44 | + * |
52 | 45 | * @param config Configuration object to create module from |
53 | 46 | */ |
54 | 47 | create: function( context, config ) { |
55 | 48 | // hook $.wikiEditor.modules.highlight.evt.change to context.evt.change |
56 | 49 | }, |
| 50 | + /** |
| 51 | + * Divides text into divisions |
| 52 | + */ |
57 | 53 | divide: function( context ) { |
58 | 54 | /* |
59 | 55 | * We need to add some markup to the iframe content to encapsulate divisions |
60 | 56 | */ |
61 | 57 | }, |
| 58 | + /** |
| 59 | + * Isolates division which was affected by most recent change |
| 60 | + */ |
62 | 61 | isolate: function( context ) { |
63 | 62 | /* |
64 | 63 | * A change just occured, and we need to know which sections were affected |
65 | 64 | */ |
66 | 65 | return []; // array of sections? |
67 | 66 | }, |
| 67 | + /** |
| 68 | + * Strips division of HTML |
| 69 | + * |
| 70 | + * @param division |
| 71 | + */ |
68 | 72 | strip: function( context, division ) { |
69 | 73 | return $( '<div />' ).html( division.html().replace( /\<br[^\>]*\>/g, "\n" ) ).text(); |
70 | 74 | }, |
71 | | - tokenArray: [], |
| 75 | + /** |
| 76 | + * Scans text division for tokens |
| 77 | + * |
| 78 | + * @param division |
| 79 | + */ |
72 | 80 | scan: function( context, division ) { |
73 | | - // We need to look over some text and find interesting areas, then return the |
74 | | - // positions of those areas as tokens |
| 81 | + /** |
| 82 | + * Builds a Token object |
| 83 | + * |
| 84 | + * @param offset |
| 85 | + * @param label |
| 86 | + */ |
75 | 87 | function Token( offset, label ) { |
76 | 88 | this.offset = offset; |
77 | 89 | this.label = label; |
78 | 90 | } |
79 | | - |
80 | | - this.tokenArray = []; |
| 91 | + // We need to look over some text and find interesting areas, then return the positions of those areas as tokens |
| 92 | + context.modules.highlight.tokenArray = []; |
81 | 93 | var text = context.fn.getContents(); |
82 | 94 | for ( module in $.wikiEditor.modules ) { |
83 | 95 | if ( 'exp' in $.wikiEditor.modules[module] ) { |
— | — | @@ -94,8 +106,9 @@ |
95 | 107 | if ( markAfter ) { |
96 | 108 | markOffset += match[0].length; |
97 | 109 | } |
98 | | - this.tokenArray.push( new Token( |
99 | | - match.index + oldOffset + markOffset, label ) ); |
| 110 | + context.modules.highlight.tokenArray.push( |
| 111 | + new Token( match.index + oldOffset + markOffset, label ) |
| 112 | + ); |
100 | 113 | oldOffset += match.index + match[0].length; |
101 | 114 | newSubstring = text.substring( oldOffset ); |
102 | 115 | match = newSubstring.match( regex ); |
— | — | @@ -104,9 +117,14 @@ |
105 | 118 | } |
106 | 119 | } |
107 | 120 | |
108 | | - return this.tokenArray; // array of tokens |
| 121 | + return context.modules.highlight.tokenArray; // array of tokens |
109 | 122 | }, |
110 | | - markers: [], |
| 123 | + /** |
| 124 | + * Marks up text with HTML |
| 125 | + * |
| 126 | + * @param division |
| 127 | + * @param tokens |
| 128 | + */ |
111 | 129 | mark: function( context, division, tokens ) { |
112 | 130 | // We need to markup some text based on some tokens |
113 | 131 | var rawText = context.fn.getContents(); |
— | — | @@ -117,20 +135,20 @@ |
118 | 136 | $.wikiEditor.modules[module].evt.mark(); |
119 | 137 | } |
120 | 138 | } |
121 | | - markedText = ""; |
| 139 | + markedText = ''; |
122 | 140 | var previousIndex = 0; |
123 | | - for(var currentIndex in this.markers){ |
124 | | - markedText+= rawText.substring(previousIndex, currentIndex); |
125 | | - for(var i = 0 ; i < this.markers[currentIndex].length; i++){ |
126 | | - markedText += this.markers[currentIndex][i]; |
| 141 | + for ( var currentIndex in context.modules.highlight.markers ){ |
| 142 | + markedText += rawText.substring( previousIndex, currentIndex ); |
| 143 | + for( var i = 0 ; i < context.modules.highlight.markers[currentIndex].length; i++ ){ |
| 144 | + markedText += context.modules.highlight.markers[currentIndex][i]; |
127 | 145 | } |
128 | 146 | previousIndex = currentIndex; |
129 | 147 | } |
130 | | - if(markedText != ""){ |
131 | | - markedText.replace(/\n/g, '<br\>'); |
| 148 | + if ( markedText != '' ){ |
| 149 | + markedText.replace( /\n/g, '<br\>' ); |
132 | 150 | context.fn.setContents( { contents:markedText } ); |
133 | 151 | } |
134 | | - }//mark |
| 152 | + } |
135 | 153 | } |
136 | 154 | |
137 | 155 | }; })( jQuery ); |
\ No newline at end of file |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -2042,14 +2042,14 @@ |
2043 | 2043 | .appendTo( $( 'body' ) ) |
2044 | 2044 | .each( module.init ) |
2045 | 2045 | .dialog( configuration ); |
2046 | | - if ( !( 'resizeme' in module ) || module.resizeme ) |
| 2046 | + if ( !( 'resizeme' in module ) || module.resizeme ) { |
2047 | 2047 | dialogDiv |
2048 | 2048 | .bind( 'dialogopen', $.wikiEditor.modules.dialogs.fn.resize ) |
2049 | 2049 | .find( '.ui-tabs' ).bind( 'tabsshow', function() { |
2050 | 2050 | $(this).closest( '.ui-dialog-content' ).each( |
2051 | 2051 | $.wikiEditor.modules.dialogs.fn.resize ); |
2052 | 2052 | }); |
2053 | | - |
| 2053 | + } |
2054 | 2054 | // Add tabindexes to dialog form elements |
2055 | 2055 | // Find the highest tabindex in use |
2056 | 2056 | var maxTI = 0; |
— | — | @@ -2069,7 +2069,6 @@ |
2070 | 2070 | } |
2071 | 2071 | }); |
2072 | 2072 | }, |
2073 | | - |
2074 | 2073 | /** |
2075 | 2074 | * Resize a dialog so its contents fit |
2076 | 2075 | * |
— | — | @@ -2079,48 +2078,37 @@ |
2080 | 2079 | resize: function() { |
2081 | 2080 | var wrapper = $(this).closest( '.ui-dialog' ); |
2082 | 2081 | var oldWidth = wrapper.width(); |
2083 | | - // Make sure elements don't wrapped so we get an accurate idea |
2084 | | - // of whether they really fit. Also temporarily show hidden |
2085 | | - // elements. |
2086 | | - |
2087 | | - // Work around jQuery bug where <div style="display:inline;" /> |
2088 | | - // inside a dialog is both :visible and :hidden |
| 2082 | + // Make sure elements don't wrapped so we get an accurate idea of whether they really fit. Also temporarily show |
| 2083 | + // hidden elements. Work around jQuery bug where <div style="display:inline;" /> inside a dialog is both |
| 2084 | + // :visible and :hidden |
2089 | 2085 | var oldHidden = $(this).find( '*' ).not( ':visible' ); |
2090 | | - |
2091 | | - // Save the style attributes of the hidden elements to restore |
2092 | | - // them later. Calling hide() after show() messes up for |
2093 | | - // elements hidden with a class |
| 2086 | + // Save the style attributes of the hidden elements to restore them later. Calling hide() after show() messes up |
| 2087 | + // for elements hidden with a class |
2094 | 2088 | oldHidden.each( function() { |
2095 | 2089 | $(this).data( 'oldstyle', $(this).attr( 'style' ) ); |
2096 | 2090 | }); |
2097 | 2091 | oldHidden.show(); |
2098 | 2092 | var oldWS = $(this).css( 'white-space' ); |
2099 | 2093 | $(this).css( 'white-space', 'nowrap' ); |
2100 | | - |
2101 | 2094 | if ( wrapper.width() <= $(this).get(0).scrollWidth ) { |
2102 | 2095 | var thisWidth = $(this).data( 'thisWidth' ) ? $(this).data( 'thisWidth' ) : 0; |
2103 | 2096 | thisWidth = Math.max( $(this).get(0).scrollWidth, thisWidth ); |
2104 | 2097 | $(this).width( thisWidth ); |
2105 | 2098 | $(this).data( 'thisWidth', thisWidth ); |
2106 | | - |
2107 | 2099 | var wrapperWidth = $(this).data( 'wrapperWidth' ) ? $(this).data( 'wrapperWidth' ) : 0; |
2108 | 2100 | wrapperWidth = Math.max( wrapper.get(0).scrollWidth, wrapperWidth ); |
2109 | 2101 | wrapper.width( wrapperWidth ); |
2110 | 2102 | $(this).data( 'wrapperWidth', wrapperWidth ); |
2111 | | - |
2112 | 2103 | $(this).dialog( { 'width': wrapper.width() } ); |
2113 | | - wrapper.css( 'left', |
2114 | | - parseInt( wrapper.css( 'left' ) ) - |
2115 | | - ( wrapper.width() - oldWidth ) / 2 ); |
| 2104 | + wrapper.css( 'left', parseInt( wrapper.css( 'left' ) ) - ( wrapper.width() - oldWidth ) / 2 ); |
2116 | 2105 | } |
2117 | | - |
2118 | 2106 | $(this).css( 'white-space', oldWS ); |
2119 | 2107 | oldHidden.each( function() { |
2120 | 2108 | $(this).attr( 'style', $(this).data( 'oldstyle' ) ); |
2121 | | - }); |
2122 | | - |
| 2109 | + }); |
2123 | 2110 | } |
2124 | 2111 | }, |
| 2112 | +// This stuff is just hanging here, perhaps we could come up with a better home for this stuff |
2125 | 2113 | modules: {}, |
2126 | 2114 | quickDialog: function( body, settings ) { |
2127 | 2115 | $( '<div />' ) |
— | — | @@ -2133,17 +2121,10 @@ |
2134 | 2122 | .dialog( 'open' ); |
2135 | 2123 | } |
2136 | 2124 | |
2137 | | -}; } ) ( jQuery ); |
2138 | | -/* Highlight module for wikiEditor */ |
| 2125 | +}; } ) ( jQuery );/* Highlight module for wikiEditor */ |
2139 | 2126 | ( function( $ ) { $.wikiEditor.modules.highlight = { |
2140 | 2127 | |
2141 | 2128 | /** |
2142 | | - * API accessible functions |
2143 | | - */ |
2144 | | -api: { |
2145 | | - // |
2146 | | -}, |
2147 | | -/** |
2148 | 2129 | * Internally used event handlers |
2149 | 2130 | */ |
2150 | 2131 | evt: { |
— | — | @@ -2176,43 +2157,61 @@ |
2177 | 2158 | } |
2178 | 2159 | } |
2179 | 2160 | }, |
2180 | | - |
2181 | 2161 | /** |
2182 | 2162 | * Internally used functions |
2183 | 2163 | */ |
2184 | 2164 | fn: { |
2185 | 2165 | /** |
2186 | 2166 | * Creates a highlight module within a wikiEditor |
2187 | | - * @param context Context object of editor to create module in |
| 2167 | + * |
2188 | 2168 | * @param config Configuration object to create module from |
2189 | 2169 | */ |
2190 | 2170 | create: function( context, config ) { |
2191 | 2171 | // hook $.wikiEditor.modules.highlight.evt.change to context.evt.change |
2192 | 2172 | }, |
| 2173 | + /** |
| 2174 | + * Divides text into divisions |
| 2175 | + */ |
2193 | 2176 | divide: function( context ) { |
2194 | 2177 | /* |
2195 | 2178 | * We need to add some markup to the iframe content to encapsulate divisions |
2196 | 2179 | */ |
2197 | 2180 | }, |
| 2181 | + /** |
| 2182 | + * Isolates division which was affected by most recent change |
| 2183 | + */ |
2198 | 2184 | isolate: function( context ) { |
2199 | 2185 | /* |
2200 | 2186 | * A change just occured, and we need to know which sections were affected |
2201 | 2187 | */ |
2202 | 2188 | return []; // array of sections? |
2203 | 2189 | }, |
| 2190 | + /** |
| 2191 | + * Strips division of HTML |
| 2192 | + * |
| 2193 | + * @param division |
| 2194 | + */ |
2204 | 2195 | strip: function( context, division ) { |
2205 | 2196 | return $( '<div />' ).html( division.html().replace( /\<br[^\>]*\>/g, "\n" ) ).text(); |
2206 | 2197 | }, |
2207 | | - tokenArray: [], |
| 2198 | + /** |
| 2199 | + * Scans text division for tokens |
| 2200 | + * |
| 2201 | + * @param division |
| 2202 | + */ |
2208 | 2203 | scan: function( context, division ) { |
2209 | | - // We need to look over some text and find interesting areas, then return the |
2210 | | - // positions of those areas as tokens |
| 2204 | + /** |
| 2205 | + * Builds a Token object |
| 2206 | + * |
| 2207 | + * @param offset |
| 2208 | + * @param label |
| 2209 | + */ |
2211 | 2210 | function Token( offset, label ) { |
2212 | 2211 | this.offset = offset; |
2213 | 2212 | this.label = label; |
2214 | 2213 | } |
2215 | | - |
2216 | | - this.tokenArray = []; |
| 2214 | + // We need to look over some text and find interesting areas, then return the positions of those areas as tokens |
| 2215 | + context.modules.highlight.tokenArray = []; |
2217 | 2216 | var text = context.fn.getContents(); |
2218 | 2217 | for ( module in $.wikiEditor.modules ) { |
2219 | 2218 | if ( 'exp' in $.wikiEditor.modules[module] ) { |
— | — | @@ -2230,8 +2229,9 @@ |
2231 | 2230 | if ( markAfter ) { |
2232 | 2231 | markOffset += match[0].length; |
2233 | 2232 | } |
2234 | | - this.tokenArray.push( new Token( |
2235 | | - match.index + oldOffset + markOffset, label ) ); |
| 2233 | + context.modules.highlight.tokenArray.push( |
| 2234 | + new Token( match.index + oldOffset + markOffset, label ) |
| 2235 | + ); |
2236 | 2236 | oldOffset += match.index + match[0].length; |
2237 | 2237 | newSubstring = text.substring( oldOffset ); |
2238 | 2238 | match = newSubstring.match( regex ); |
— | — | @@ -2240,9 +2240,14 @@ |
2241 | 2241 | } |
2242 | 2242 | } |
2243 | 2243 | |
2244 | | - return this.tokenArray; // array of tokens |
| 2244 | + return context.modules.highlight.tokenArray; // array of tokens |
2245 | 2245 | }, |
2246 | | - markers: [], |
| 2246 | + /** |
| 2247 | + * Marks up text with HTML |
| 2248 | + * |
| 2249 | + * @param division |
| 2250 | + * @param tokens |
| 2251 | + */ |
2247 | 2252 | mark: function( context, division, tokens ) { |
2248 | 2253 | // We need to markup some text based on some tokens |
2249 | 2254 | var rawText = context.fn.getContents(); |
— | — | @@ -2253,32 +2258,26 @@ |
2254 | 2259 | $.wikiEditor.modules[module].evt.mark(); |
2255 | 2260 | } |
2256 | 2261 | } |
2257 | | - markedText = ""; |
| 2262 | + markedText = ''; |
2258 | 2263 | var previousIndex = 0; |
2259 | | - for(var currentIndex in this.markers){ |
2260 | | - markedText+= rawText.substring(previousIndex, currentIndex); |
2261 | | - for(var i = 0 ; i < this.markers[currentIndex].length; i++){ |
2262 | | - markedText += this.markers[currentIndex][i]; |
| 2264 | + for ( var currentIndex in context.modules.highlight.markers ){ |
| 2265 | + markedText += rawText.substring( previousIndex, currentIndex ); |
| 2266 | + for( var i = 0 ; i < context.modules.highlight.markers[currentIndex].length; i++ ){ |
| 2267 | + markedText += context.modules.highlight.markers[currentIndex][i]; |
2263 | 2268 | } |
2264 | 2269 | previousIndex = currentIndex; |
2265 | 2270 | } |
2266 | | - if(markedText != ""){ |
2267 | | - markedText.replace(/\n/g, '<br\>'); |
| 2271 | + if ( markedText != '' ){ |
| 2272 | + markedText.replace( /\n/g, '<br\>' ); |
2268 | 2273 | context.fn.setContents( { contents:markedText } ); |
2269 | 2274 | } |
2270 | | - }//mark |
| 2275 | + } |
2271 | 2276 | } |
2272 | 2277 | |
2273 | 2278 | }; })( jQuery );/* Preview module for wikiEditor */ |
2274 | 2279 | ( function( $ ) { $.wikiEditor.modules.preview = { |
2275 | 2280 | |
2276 | 2281 | /** |
2277 | | - * API accessible functions |
2278 | | - */ |
2279 | | -api: { |
2280 | | - // |
2281 | | -}, |
2282 | | -/** |
2283 | 2282 | * Internally used functions |
2284 | 2283 | */ |
2285 | 2284 | fn: { |
— | — | @@ -2417,12 +2416,6 @@ |
2418 | 2417 | ( function( $ ) { $.wikiEditor.modules.publish = { |
2419 | 2418 | |
2420 | 2419 | /** |
2421 | | - * API accessible functions |
2422 | | - */ |
2423 | | -api: { |
2424 | | - // |
2425 | | -}, |
2426 | | -/** |
2427 | 2420 | * Internally used functions |
2428 | 2421 | */ |
2429 | 2422 | fn: { |
— | — | @@ -2526,80 +2519,80 @@ |
2527 | 2520 | } |
2528 | 2521 | } |
2529 | 2522 | |
2530 | | -}; } )( jQuery );/* template forms module for wikiEditor */ |
| 2523 | +}; } )( jQuery );/* TemplateEditor module for wikiEditor */ |
2531 | 2524 | ( function( $ ) { $.wikiEditor.modules.templateEditor = { |
2532 | 2525 | |
2533 | 2526 | /** |
2534 | | - * API accessible functions |
| 2527 | + * Event handlers |
2535 | 2528 | */ |
2536 | | -api: { |
2537 | | - // |
2538 | | -}, |
2539 | | - |
2540 | 2529 | evt: { |
2541 | | - mark: function() { |
2542 | | - function findOutermostTemplates( tokenStack ) { |
2543 | | - templateBeginFound = false; |
2544 | | - for ( ;i< tokenStack.length; i++ ) { |
2545 | | - if ( tokenStack[i].label == "TEMPLATE_BEGIN" ) { |
2546 | | - templateBeginFound = true; |
2547 | | - break; |
2548 | | - } |
| 2530 | + mark: function( context, event ) { |
| 2531 | + // This is shared by both the closure findOutermostTemplates and the calling code - is this a good idea? |
| 2532 | + var i = 0; |
| 2533 | + /** |
| 2534 | + * Finds the left and right character positions of the outer-most template declaration, playing nicely with |
| 2535 | + * nested template calls of any depth. This function acts as an iterator, which is why the i var is shared - but |
| 2536 | + * this seems a bit scary seeing as 'i' is so often used in loops. |
| 2537 | + * |
| 2538 | + * @param tokenStack Array of tokens to find boundries within |
| 2539 | + */ |
| 2540 | + function findOutermostTemplates( tokenStack ) { |
| 2541 | + var templateBeginFound = false; |
| 2542 | + for ( ; i < tokenStack.length; i++ ) { |
| 2543 | + if ( tokenStack[i].label == 'TEMPLATE_BEGIN' ) { |
| 2544 | + templateBeginFound = true; |
| 2545 | + break; |
2549 | 2546 | } |
2550 | | - var j = i; |
2551 | | - i++; |
2552 | | - if ( !templateBeginFound ) { |
| 2547 | + } |
| 2548 | + var j = i++; |
| 2549 | + if ( !templateBeginFound ) { |
| 2550 | + return false; |
| 2551 | + } else { |
| 2552 | + // This is only designed to find the outermost template boundaries, the model handles nested template |
| 2553 | + // and template-like objects better |
| 2554 | + var nestedBegins = 1; |
| 2555 | + while ( nestedBegins > 0 && j < tokenStack.length ) { |
| 2556 | + var label = tokenStack[++j].label; |
| 2557 | + nestedBegins += label == 'TEMPLATE_END' ? -1 : label == 'TEMPLATE_BEGIN' ? 1 : 0; |
| 2558 | + } |
| 2559 | + if ( nestedBegins == 0 ) { |
| 2560 | + // Outer template begins at tokenStack[i].offset and ends at tokenStack[j].offset + 2 |
| 2561 | + var leftMarker = i -1; |
| 2562 | + var rightMarker = j; |
| 2563 | + i = j; |
| 2564 | + return [leftMarker, rightMarker]; |
| 2565 | + } else { |
2553 | 2566 | return false; |
2554 | | - } else { |
2555 | | - // This is only designed to find the outermost template boundaries, the model handles nested template |
2556 | | - // and template-like objects better |
2557 | | - var nestedBegins = 1; |
2558 | | - while ( nestedBegins > 0 && j < tokenStack.length ) { |
2559 | | - j++; |
2560 | | - if ( tokenStack[j].label == "TEMPLATE_END" ) { |
2561 | | - nestedBegins--; |
2562 | | - } |
2563 | | - if ( tokenStack[j].label == "TEMPLATE_BEGIN" ) { |
2564 | | - nestedBegins++; |
2565 | | - } |
2566 | | - } |
2567 | | - if ( nestedBegins == 0 ) { |
2568 | | - // outer template begins at tokenStack[i].offset |
2569 | | - // and ends at tokenStack[j].offset + 2 |
2570 | | - var leftMarker = i -1; |
2571 | | - var rightMarker = j; |
2572 | | - i = j; |
2573 | | - return [ leftMarker, rightMarker ]; |
2574 | | - } else { |
2575 | | - return false; |
2576 | | - } |
2577 | 2567 | } |
2578 | | - }; //find outermost templates |
2579 | | - |
2580 | | - markers = $.wikiEditor.modules.highlight.fn.markers; |
2581 | | - var tokenStack = $.wikiEditor.modules.highlight.fn.tokenArray; |
2582 | | - i = 0; |
2583 | | - var templateBoundaries; |
2584 | | - templateBeginFound = false; |
2585 | | - |
2586 | | - while ( templateBoundaries = findOutermostTemplates( tokenStack ) ) { |
2587 | | - if ( typeof markers[tokenStack[templateBoundaries[0]].offset] == 'undefined' ) { |
2588 | | - markers[tokenStack[templateBoundaries[0]].offset] = []; |
2589 | | - } |
2590 | | - if ( typeof markers[tokenStack[templateBoundaries[1]].offset] == 'undefined' ) { |
2591 | | - markers[tokenStack[templateBoundaries[1]].offset] = []; |
2592 | | - } |
2593 | | - markers[tokenStack[templateBoundaries[0]].offset].push( "<div class='wiki-template'>" ); |
2594 | | - markers[tokenStack[templateBoundaries[1]].offset].push( "</div>" ); |
2595 | 2568 | } |
| 2569 | + }; |
| 2570 | + // Get the markers and tokens from the current context |
| 2571 | + var markers = context.modules.highlight.data.markers; |
| 2572 | + var tokenStack = context.modules.highlight.data.tokenArray; |
| 2573 | + // Scan through and detect the boundries of template calls |
| 2574 | + var templateBeginFound = false; |
| 2575 | + var templateBoundaries; |
| 2576 | + while ( templateBoundaries = findOutermostTemplates( tokenStack ) ) { |
| 2577 | + // Ensure indexes exist for left and right boundry markers |
| 2578 | + if ( typeof markers[tokenStack[templateBoundaries[0]].offset] == 'undefined' ) { |
| 2579 | + markers[tokenStack[templateBoundaries[0]].offset] = []; |
| 2580 | + } |
| 2581 | + if ( typeof markers[tokenStack[templateBoundaries[1]].offset] == 'undefined' ) { |
| 2582 | + markers[tokenStack[templateBoundaries[1]].offset] = []; |
| 2583 | + } |
| 2584 | + // Append boundry markers |
| 2585 | + markers[tokenStack[templateBoundaries[0]].offset].push( "<div class='wiki-template'>" ); |
| 2586 | + markers[tokenStack[templateBoundaries[1]].offset].push( "</div>" ); |
2596 | 2587 | } |
| 2588 | + } |
2597 | 2589 | }, |
2598 | | - |
| 2590 | +/** |
| 2591 | + * Regular expressions that produce tokens |
| 2592 | + */ |
2599 | 2593 | exp: [ |
2600 | | - { regex: /{{/, label: "TEMPLATE_BEGIN" }, |
2601 | | - { regex: /}}/, label: "TEMPLATE_END", markAfter: true } |
| 2594 | + { 'regex': /{{/, 'label': "TEMPLATE_BEGIN" }, |
| 2595 | + { 'regex': /}}/, 'label': "TEMPLATE_END", 'markAfter': true } |
2602 | 2596 | ], |
2603 | | - |
2604 | 2597 | /** |
2605 | 2598 | * Internally used functions |
2606 | 2599 | */ |
— | — | @@ -2610,14 +2603,28 @@ |
2611 | 2604 | * @param config Configuration object to create module from |
2612 | 2605 | */ |
2613 | 2606 | create: function( context, config ) { |
| 2607 | + // Initialize module within the context |
| 2608 | + }, |
| 2609 | + /** |
| 2610 | + * Builds a template model from given wikitext representation, allowing object-oriented manipulation of the contents |
| 2611 | + * of the template while preserving whitespace and formatting. |
| 2612 | + * |
| 2613 | + * @param wikitext String of wikitext content |
| 2614 | + */ |
| 2615 | + model: function( wikitext ) { |
2614 | 2616 | |
2615 | | - //initializations |
| 2617 | + /* Private Functions */ |
2616 | 2618 | |
2617 | | - }, |
2618 | | - |
2619 | | - //template Model |
2620 | | - model: function( wikitext ) { |
2621 | | - // Param object |
| 2619 | + /** |
| 2620 | + * Builds a Param object. |
| 2621 | + * |
| 2622 | + * @param name |
| 2623 | + * @param value |
| 2624 | + * @param number |
| 2625 | + * @param nameIndex |
| 2626 | + * @param equalsIndex |
| 2627 | + * @param valueIndex |
| 2628 | + */ |
2622 | 2629 | function Param( name, value, number, nameIndex, equalsIndex, valueIndex ) { |
2623 | 2630 | this.name = name; |
2624 | 2631 | this.value = value; |
— | — | @@ -2626,56 +2633,167 @@ |
2627 | 2634 | this.equalsIndex = equalsIndex; |
2628 | 2635 | this.valueIndex = valueIndex; |
2629 | 2636 | } |
2630 | | - |
2631 | | - // Range object |
| 2637 | + /** |
| 2638 | + * Builds a Range object. |
| 2639 | + * |
| 2640 | + * @param begin |
| 2641 | + * @param end |
| 2642 | + */ |
2632 | 2643 | function Range( begin, end ) { |
2633 | 2644 | this.begin = begin; |
2634 | 2645 | this.end = end; |
2635 | 2646 | } |
| 2647 | + /** |
| 2648 | + * Set 'original' to true if you want the original value irrespective of whether the model's been changed |
| 2649 | + * |
| 2650 | + * @param name |
| 2651 | + * @param value |
| 2652 | + * @param original |
| 2653 | + */ |
| 2654 | + function getSetValue( name, value, original ) { |
| 2655 | + var valueRange; |
| 2656 | + var rangeIndex; |
| 2657 | + var retVal; |
| 2658 | + if ( isNaN( name ) ) { |
| 2659 | + // It's a string! |
| 2660 | + if ( typeof paramsByName[name] == 'undefined' ) { |
| 2661 | + // Does not exist |
| 2662 | + return ""; |
| 2663 | + } |
| 2664 | + rangeIndex = paramsByName[name]; |
| 2665 | + } else { |
| 2666 | + // It's a number! |
| 2667 | + rangeIndex = parseInt( name ); |
| 2668 | + } |
| 2669 | + if ( typeof params[rangeIndex] == 'undefined' ) { |
| 2670 | + // Does not exist |
| 2671 | + return ""; |
| 2672 | + } |
| 2673 | + valueRange = ranges[params[rangeIndex].valueIndex]; |
| 2674 | + if ( typeof valueRange.newVal == 'undefined' || original ) { |
| 2675 | + // Value unchanged, return original wikitext |
| 2676 | + retVal = wikitext.substring( valueRange.begin, valueRange.end ); |
| 2677 | + } else { |
| 2678 | + // New value exists, return new value |
| 2679 | + retVal = valueRange.newVal; |
| 2680 | + } |
| 2681 | + if ( value != null ) { |
| 2682 | + ranges[params[rangeIndex].valueIndex].newVal = value; |
| 2683 | + } |
| 2684 | + return retVal; |
| 2685 | + }; |
2636 | 2686 | |
2637 | | - var ranges = []; |
2638 | | - var sanatizedStr = ""; |
2639 | | - var params = []; |
2640 | | - var paramsByName = []; |
2641 | | - var templateNameIndex = 0; |
| 2687 | + /* Public Functions */ |
2642 | 2688 | |
2643 | | - //takes all template-specific characters, namely {|=} away if they're not particular to the |
2644 | | - //template we're looking at |
2645 | | - function markOffTemplates() { |
2646 | | - sanatizedStr = wikitext.replace( /{{/, " " ); //get rid of first {{ with whitespace |
2647 | | - endBraces = sanatizedStr.match( /}}\s*$/ ); //replace end |
2648 | | - sanatizedStr = sanatizedStr.substring( 0, endBraces.index ) + " " + |
2649 | | - sanatizedStr.substring( endBraces.index + 2 ); |
2650 | | - |
2651 | | - //match the open braces we just found with equivalent closing braces |
2652 | | - //note, works for any level of braces |
2653 | | - while ( sanatizedStr.indexOf( '{{' ) != -1 ) { |
2654 | | - startIndex = sanatizedStr.indexOf('{{') + 1; |
2655 | | - openBraces = 2; |
2656 | | - endIndex = startIndex; |
2657 | | - while ( openBraces > 0 ) { |
2658 | | - endIndex++; |
2659 | | - switch ( sanatizedStr[endIndex] ) { |
2660 | | - case '}': openBraces--; break; |
2661 | | - case '{': openBraces++; break; |
2662 | | - } |
| 2689 | + /** |
| 2690 | + * Get template name |
| 2691 | + */ |
| 2692 | + this.getName = function() { |
| 2693 | + if( typeof ranges[templateNameIndex].newVal == 'undefined' ) { |
| 2694 | + return wikitext.substring( ranges[templateNameIndex].begin, ranges[templateNameIndex].end ); |
| 2695 | + } else { |
| 2696 | + return ranges[templateNameIndex].newVal; |
| 2697 | + } |
| 2698 | + }; |
| 2699 | + /** |
| 2700 | + * Set template name (if we want to support this) |
| 2701 | + * |
| 2702 | + * @param name |
| 2703 | + */ |
| 2704 | + this.setName = function( name ) { |
| 2705 | + ranges[templateNameIndex].newVal = name; |
| 2706 | + }; |
| 2707 | + /** |
| 2708 | + * Set value for a given param name / number |
| 2709 | + * |
| 2710 | + * @param name |
| 2711 | + * @param value |
| 2712 | + */ |
| 2713 | + this.setValue = function( name, value ) { |
| 2714 | + return getSetValue( name, value, false ); |
| 2715 | + }; |
| 2716 | + /** |
| 2717 | + * Get value for a given param name / number |
| 2718 | + * |
| 2719 | + * @param name |
| 2720 | + */ |
| 2721 | + this.getValue = function( name ) { |
| 2722 | + return getSetValue( name, null, false ); |
| 2723 | + }; |
| 2724 | + /** |
| 2725 | + * Get original value of a param |
| 2726 | + * |
| 2727 | + * @param name |
| 2728 | + */ |
| 2729 | + this.getOriginalValue = function( name ) { |
| 2730 | + return getSetValue( name, null, true ); |
| 2731 | + }; |
| 2732 | + /** |
| 2733 | + * Get a list of all param names (numbers for the anonymous ones) |
| 2734 | + */ |
| 2735 | + this.getAllParamNames = function() { |
| 2736 | + return paramsByName; |
| 2737 | + }; |
| 2738 | + /** |
| 2739 | + * Get the initial params |
| 2740 | + */ |
| 2741 | + this.getAllInitialParams = function(){ |
| 2742 | + return params; |
| 2743 | + } |
| 2744 | + /** |
| 2745 | + * Get original template text |
| 2746 | + */ |
| 2747 | + this.getOriginalText = function() { |
| 2748 | + return wikitext; |
| 2749 | + }; |
| 2750 | + /** |
| 2751 | + * Get modified template text |
| 2752 | + */ |
| 2753 | + this.getText = function() { |
| 2754 | + newText = ""; |
| 2755 | + for ( i = 0 ; i < ranges.length; i++ ) { |
| 2756 | + if( typeof ranges[i].newVal == 'undefined' ) { |
| 2757 | + wikitext.substring( ranges[i].begin, ranges[i].end ); |
| 2758 | + } else { |
| 2759 | + newText += ranges[i].newVal; |
2663 | 2760 | } |
2664 | | - sanatizedSegment = sanatizedStr.substring( startIndex,endIndex ) |
2665 | | - .replace( /[{}|=]/g , 'X' ); |
2666 | | - sanatizedStr = sanatizedStr.substring( 0, startIndex ) + |
2667 | | - sanatizedSegment + sanatizedStr.substring( endIndex ); |
2668 | | - }//while |
2669 | | - return sanatizedStr; |
| 2761 | + } |
| 2762 | + return newText; |
2670 | 2763 | }; |
2671 | | - |
| 2764 | + |
2672 | 2765 | // Whitespace* {{ whitespace* nonwhitespace: |
2673 | 2766 | if ( wikitext.match( /\s*{{\s*\S*:/ ) ) { |
2674 | | - // we have a parser function! |
| 2767 | + // We have a parser function! |
2675 | 2768 | } |
2676 | | - |
2677 | | - markOffTemplates(); |
2678 | | - |
2679 | | - //parse 1 param at a time |
| 2769 | + /* |
| 2770 | + * Take all template-specific characters that are not particular to the template we're looking at, namely {|=}, |
| 2771 | + * and convert them into something harmless, in this case 'X' |
| 2772 | + */ |
| 2773 | + // Get rid of first {{ with whitespace |
| 2774 | + var sanatizedStr = wikitext.replace( /{{/, " " ); |
| 2775 | + // Replace end |
| 2776 | + endBraces = sanatizedStr.match( /}}\s*$/ ); |
| 2777 | + sanatizedStr = |
| 2778 | + sanatizedStr.substring( 0, endBraces.index ) + " " + sanatizedStr.substring( endBraces.index + 2 ); |
| 2779 | + // Match the open braces we just found with equivalent closing braces note, works for any level of braces |
| 2780 | + while ( sanatizedStr.indexOf( '{{' ) != -1 ) { |
| 2781 | + startIndex = sanatizedStr.indexOf('{{') + 1; |
| 2782 | + openBraces = 2; |
| 2783 | + endIndex = startIndex; |
| 2784 | + while ( openBraces > 0 ) { |
| 2785 | + var brace = sanatizedStr[++endIndex]; |
| 2786 | + openBraces += brace == '}' ? -1 : brace == '{' ? 1 : 0; |
| 2787 | + } |
| 2788 | + sanatizedSegment = sanatizedStr.substring( startIndex,endIndex ).replace( /[{}|=]/g , 'X' ); |
| 2789 | + sanatizedStr = |
| 2790 | + sanatizedStr.substring( 0, startIndex ) + sanatizedSegment + sanatizedStr.substring( endIndex ); |
| 2791 | + } |
| 2792 | + /* |
| 2793 | + * Parse 1 param at a time |
| 2794 | + */ |
| 2795 | + var ranges = []; |
| 2796 | + var params = []; |
| 2797 | + var templateNameIndex = 0; |
2680 | 2798 | var doneParsing = false; |
2681 | 2799 | oldDivider = 0; |
2682 | 2800 | divider = sanatizedStr.indexOf( '|', oldDivider ); |
— | — | @@ -2693,11 +2811,12 @@ |
2694 | 2812 | ranges[templateNameIndex].end ); |
2695 | 2813 | } |
2696 | 2814 | params.push( ranges[templateNameIndex].old ); //put something in params (0) |
2697 | | - |
2698 | | - currentParamNumber = 0; |
| 2815 | + /* |
| 2816 | + * Start looping over params |
| 2817 | + */ |
| 2818 | + var currentParamNumber = 0; |
2699 | 2819 | var valueEndIndex; |
2700 | | - |
2701 | | - //start looping over params |
| 2820 | + var paramsByName = []; |
2702 | 2821 | while ( !doneParsing ) { |
2703 | 2822 | currentParamNumber++; |
2704 | 2823 | oldDivider = divider; |
— | — | @@ -2726,163 +2845,64 @@ |
2727 | 2846 | currentParamNumber, nameIndex, equalsIndex, valueIndex ) ); |
2728 | 2847 | paramsByName[currentParamNumber] = currentParamNumber; |
2729 | 2848 | } else { |
2730 | | - // there's an equals, could be comment or a value pair |
| 2849 | + // There's an equals, could be comment or a value pair |
2731 | 2850 | currentName = currentField.substring( 0, currentField.indexOf( '=' ) ); |
2732 | | - // (still offset by oldDivider) |
2733 | | - nameBegin = currentName.match( /\S+/ ); //first nonwhitespace character |
| 2851 | + // Still offset by oldDivider - first nonwhitespace character |
| 2852 | + nameBegin = currentName.match( /\S+/ ); |
2734 | 2853 | if ( nameBegin == null ) { |
2735 | | - // this is a comment inside a template call/parser abuse. let's not encourage it |
| 2854 | + // This is a comment inside a template call / parser abuse. let's not encourage it |
2736 | 2855 | divider++; |
2737 | 2856 | currentParamNumber--; |
2738 | 2857 | continue; |
2739 | 2858 | } |
2740 | 2859 | nameBeginIndex = nameBegin.index + oldDivider + 1; |
2741 | | - nameEnd = currentName.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character |
| 2860 | + // Last nonwhitespace and non } character |
| 2861 | + nameEnd = currentName.match( /[^\s]\s*$/ ); |
2742 | 2862 | nameEndIndex = nameEnd.index + oldDivider + 2; |
2743 | | - |
2744 | | - ranges.push( new Range( ranges[ranges.length-1].end, |
2745 | | - nameBeginIndex ) ); //all the chars upto now |
2746 | | - nameIndex = ranges.push( new Range( nameBeginIndex, nameEndIndex ) ); |
2747 | | - nameIndex--; |
| 2863 | + // All the chars upto now |
| 2864 | + ranges.push( new Range( ranges[ranges.length-1].end, nameBeginIndex ) ); |
| 2865 | + nameIndex = ranges.push( new Range( nameBeginIndex, nameEndIndex ) ) - 1; |
2748 | 2866 | currentValue = currentField.substring( currentField.indexOf( '=' ) + 1); |
2749 | 2867 | oldDivider += currentField.indexOf( '=' ) + 1; |
2750 | | - valueBegin = currentValue.match( /\S+/ ); //first nonwhitespace character |
| 2868 | + // First nonwhitespace character |
| 2869 | + valueBegin = currentValue.match( /\S+/ ); |
2751 | 2870 | valueBeginIndex = valueBegin.index + oldDivider + 1; |
2752 | | - valueEnd = currentValue.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character |
| 2871 | + // Last nonwhitespace and non } character |
| 2872 | + valueEnd = currentValue.match( /[^\s]\s*$/ ); |
2753 | 2873 | valueEndIndex = valueEnd.index + oldDivider + 2; |
2754 | | - equalsIndex = ranges.push( new Range( ranges[ranges.length-1].end, |
2755 | | - valueBeginIndex) ); //all the chars upto now |
2756 | | - equalsIndex--; |
2757 | | - valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ); |
2758 | | - valueIndex--; |
2759 | | - params.push( new Param( wikitext.substring( nameBeginIndex, nameEndIndex ), |
| 2874 | + // All the chars upto now |
| 2875 | + equalsIndex = ranges.push( new Range( ranges[ranges.length-1].end, valueBeginIndex) ) - 1; |
| 2876 | + valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) ) - 1; |
| 2877 | + params.push( new Param( |
| 2878 | + wikitext.substring( nameBeginIndex, nameEndIndex ), |
2760 | 2879 | wikitext.substring( valueBeginIndex, valueEndIndex ), |
2761 | | - currentParamNumber, nameIndex, equalsIndex, valueIndex ) ); |
| 2880 | + currentParamNumber, |
| 2881 | + nameIndex, |
| 2882 | + equalsIndex, |
| 2883 | + valueIndex |
| 2884 | + ) ); |
2762 | 2885 | paramsByName[wikitext.substring( nameBeginIndex, nameEndIndex )] = currentParamNumber; |
2763 | 2886 | } |
2764 | 2887 | } |
2765 | | - //the rest of the string |
| 2888 | + // The rest of the string |
2766 | 2889 | ranges.push( new Range( valueEndIndex, wikitext.length ) ); |
2767 | | - |
2768 | | - //FUNCTIONS |
2769 | | - //set 'original' to true if you want the original value irrespective of whether the model's been changed |
2770 | | - function getSetValue( name, value, original ) { |
2771 | | - var valueRange; |
2772 | | - var rangeIndex; |
2773 | | - var retVal; |
2774 | | - if ( isNaN( name ) ) { |
2775 | | - // it's a string! |
2776 | | - if ( typeof paramsByName[name] == 'undefined' ) { |
2777 | | - //does not exist |
2778 | | - return ""; |
2779 | | - } |
2780 | | - rangeIndex = paramsByName[name]; |
2781 | | - } else { |
2782 | | - //it's a number! |
2783 | | - rangeIndex = parseInt( name ); |
2784 | | - } |
2785 | | - |
2786 | | - if ( typeof params[rangeIndex] == 'undefined' ) { |
2787 | | - //does not exist |
2788 | | - return ""; |
2789 | | - } |
2790 | | - valueRange = ranges[params[rangeIndex].valueIndex]; |
2791 | | - |
2792 | | - if ( typeof valueRange.newVal == 'undefined' || original ) { |
2793 | | - //value unchanged, return original wikitext |
2794 | | - retVal = wikitext.substring( valueRange.begin, valueRange.end ); |
2795 | | - } else { |
2796 | | - //new value exists, return new value |
2797 | | - retVal = valueRange.newVal; |
2798 | | - } |
2799 | | - |
2800 | | - if ( value != null ) { |
2801 | | - ranges[params[rangeIndex].valueIndex].newVal = value; |
2802 | | - } |
2803 | | - |
2804 | | - return retVal; |
2805 | | - }; |
2806 | | - |
2807 | | - //'public' functions |
2808 | | - |
2809 | | - //get template name |
2810 | | - this.getName = function() { |
2811 | | - if( typeof ranges[templateNameIndex].newVal == 'undefined' ) { |
2812 | | - return wikitext.substring( ranges[templateNameIndex].begin, |
2813 | | - ranges[templateNameIndex].end ); |
2814 | | - |
2815 | | - } else { |
2816 | | - return ranges[templateNameIndex].newVal; |
2817 | | - } |
2818 | | - }; |
2819 | | - |
2820 | | - //set template name (if we want to support this) |
2821 | | - this.setName = function( name ) { |
2822 | | - ranges[templateNameIndex].newVal = name; |
2823 | | - }; |
2824 | | - |
2825 | | - //set value for a given param name/number |
2826 | | - this.setValue = function( name, value ) { |
2827 | | - return getSetValue( name, value, false ); |
2828 | | - }; |
| 2890 | + } // model |
| 2891 | +} |
2829 | 2892 | |
2830 | | - //get value for a given param name/number |
2831 | | - this.getValue = function( name ) { |
2832 | | - return getSetValue( name, null, false ); |
2833 | | - }; |
2834 | | - |
2835 | | - //get original value of a param |
2836 | | - this.getOriginalValue = function( name ) { |
2837 | | - return getSetValue( name, null, true ); |
2838 | | - }; |
2839 | | - |
2840 | | - //get a list of all param names (numbers for the anonymous ones) |
2841 | | - this.getAllParamNames = function() { |
2842 | | - return paramsByName; |
2843 | | - }; |
2844 | | - |
2845 | | - //get the initial params |
2846 | | - this.getAllInitialParams = function(){ |
2847 | | - return params; |
2848 | | - } |
2849 | | - |
2850 | | - //get original template text |
2851 | | - this.getOriginalText = function() { |
2852 | | - return wikitext; |
2853 | | - }; |
2854 | | - |
2855 | | - //get modified template text |
2856 | | - this.getText = function() { |
2857 | | - newText = ""; |
2858 | | - for ( i = 0 ; i < ranges.length; i++ ) { |
2859 | | - if( typeof ranges[i].newVal == 'undefined' ) { |
2860 | | - wikitext.substring( ranges[i].begin, ranges[i].end ); |
2861 | | - } else { |
2862 | | - newText += ranges[i].newVal; |
2863 | | - } |
2864 | | - } |
2865 | | - return newText; |
2866 | | - }; |
2867 | | - }//template model |
2868 | | - |
2869 | | -}//fn |
2870 | | - |
2871 | 2893 | }; } )( jQuery ); |
2872 | | - |
2873 | | - |
2874 | 2894 | /* TOC Module for wikiEditor */ |
2875 | 2895 | ( function( $ ) { $.wikiEditor.modules.toc = { |
2876 | | - |
| 2896 | + |
2877 | 2897 | /** |
2878 | | - * Default width of table of contents |
| 2898 | + * Configuration |
2879 | 2899 | */ |
2880 | | -defaultWidth: '166px', |
| 2900 | +cfg: { |
| 2901 | + // Default width of table of contents |
| 2902 | + defaultWidth: '166px', |
| 2903 | + // Minimum width to allow resizing to before collapsing the table of contents - used when resizing and collapsing |
| 2904 | + minimumWidth: '70px', |
| 2905 | +}, |
2881 | 2906 | /** |
2882 | | - * Minimum width to allow resizing to before collapsing the table of contents |
2883 | | - * Only used if resizing and collapsing is enabled |
2884 | | - */ |
2885 | | -minimumWidth: '70px', |
2886 | | -/** |
2887 | 2907 | * API accessible functions |
2888 | 2908 | */ |
2889 | 2909 | api: { |
— | — | @@ -2940,15 +2960,15 @@ |
2941 | 2961 | .addClass( 'wikiEditor-ui-toc' ) |
2942 | 2962 | .data( 'context', context ); |
2943 | 2963 | context.$ui.find( '.wikiEditor-ui-right' ) |
2944 | | - .css( 'width', $.wikiEditor.modules.toc.defaultWidth ) |
| 2964 | + .css( 'width', $.wikiEditor.modules.toc.cfg.defaultWidth ) |
2945 | 2965 | .append( context.modules.toc.$toc ); |
2946 | 2966 | context.modules.toc.$toc.height( |
2947 | 2967 | context.$ui.find( '.wikiEditor-ui-left' ).height() |
2948 | 2968 | ); |
2949 | 2969 | context.$ui.find( '.wikiEditor-ui-left' ) |
2950 | | - .css( 'marginRight', "-" + $.wikiEditor.modules.toc.defaultWidth ) |
| 2970 | + .css( 'marginRight', "-" + $.wikiEditor.modules.toc.cfg.defaultWidth ) |
2951 | 2971 | .children() |
2952 | | - .css( 'marginRight', $.wikiEditor.modules.toc.defaultWidth ); |
| 2972 | + .css( 'marginRight', $.wikiEditor.modules.toc.cfg.defaultWidth ); |
2953 | 2973 | }, |
2954 | 2974 | |
2955 | 2975 | unhighlight: function( context ) { |
— | — | @@ -3152,7 +3172,14 @@ |
3153 | 3173 | // Toss a transparent cover over our iframe |
3154 | 3174 | $( '<div />' ) |
3155 | 3175 | .addClass( 'wikiEditor-ui-resize-mask' ) |
3156 | | - .css( { 'position': 'absolute', 'z-index': 2, 'left': 0, 'top': 0, 'bottom': 0, 'right': 0 } ) |
| 3176 | + .css( { |
| 3177 | + 'position': 'absolute', |
| 3178 | + 'z-index': 2, |
| 3179 | + 'left': 0, |
| 3180 | + 'top': 0, |
| 3181 | + 'bottom': 0, |
| 3182 | + 'right': 0 |
| 3183 | + } ) |
3157 | 3184 | .appendTo( context.$ui.find( '.wikiEditor-ui-left' ) ); |
3158 | 3185 | $this.resizable( 'option', 'maxWidth', $this.parent().width() - 450 ); |
3159 | 3186 | }, |
— | — | @@ -3168,7 +3195,7 @@ |
3169 | 3196 | stop: function ( e, ui ) { |
3170 | 3197 | context.$ui.find( '.wikiEditor-ui-resize-mask' ).remove(); |
3171 | 3198 | context.$content.trigger( 'mouseup' ); |
3172 | | - if( ui.size.width < parseFloat( $.wikiEditor.modules.toc.minimumWidth ) ) { |
| 3199 | + if( ui.size.width < parseFloat( $.wikiEditor.modules.toc.cfg.minimumWidth ) ) { |
3173 | 3200 | context.modules.toc.$toc.trigger( 'collapse' ); |
3174 | 3201 | } else { |
3175 | 3202 | context.modules.toc.$toc.data( 'openWidth', ui.size.width ); |
— | — | @@ -3188,14 +3215,14 @@ |
3189 | 3216 | context.modules.toc.$toc |
3190 | 3217 | .bind( 'collapse.wikiEditor-toc', $.wikiEditor.modules.toc.fn.collapse ) |
3191 | 3218 | .bind( 'expand.wikiEditor-toc', $.wikiEditor.modules.toc.fn.expand ); |
3192 | | - context.modules.toc.$toc.data( 'openWidth', $.wikiEditor.modules.toc.defaultWidth ); |
| 3219 | + context.modules.toc.$toc.data( 'openWidth', $.wikiEditor.modules.toc.cfg.defaultWidth ); |
3193 | 3220 | // If the toc-width cookie is set, reset the widths based upon that |
3194 | 3221 | if ( $.cookie( 'wikiEditor-' + context.instance + '-toc-width' ) == 0 ) { |
3195 | 3222 | context.modules.toc.$toc.trigger( 'collapse.wikiEditor-toc', { data: context } ); |
3196 | 3223 | } else if ( $.cookie( 'wikiEditor-' + context.instance + '-toc-width' ) > 0 ) { |
3197 | 3224 | var initialWidth = $.cookie( 'wikiEditor-' + context.instance + '-toc-width' ); |
3198 | | - if( initialWidth < parseFloat( $.wikiEditor.modules.toc.minimumWidth ) ) |
3199 | | - initialWidth = parseFloat( $.wikiEditor.modules.toc.minimumWidth ) + 1; |
| 3225 | + if( initialWidth < parseFloat( $.wikiEditor.modules.toc.cfg.minimumWidth ) ) |
| 3226 | + initialWidth = parseFloat( $.wikiEditor.modules.toc.cfg.minimumWidth ) + 1; |
3200 | 3227 | context.modules.toc.$toc.data( 'openWidth', initialWidth + 'px' ); |
3201 | 3228 | context.$ui.find( '.wikiEditor-ui-right' ) |
3202 | 3229 | .css( 'width', initialWidth + 'px' ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -116,24 +116,23 @@ |
117 | 117 | arguments=$.makeArray(arguments);if(arguments.length>0){var call=arguments.shift();if(call in context.api){context.api[call](context,typeof arguments[0]=='undefined'?{}:arguments[0]);}} |
118 | 118 | return $(this).data('wikiEditor-context',context);};})(jQuery);RegExp.escape=function(s){return s.replace(/([.*+?^${}()|\/\\[\]])/g,'\\$1');};(function($){$.wikiEditor.modules.dialogs={api:{addDialog:function(context,data){$.wikiEditor.modules.dialogs.fn.create(context,data)},openDialog:function(context,module){if(module in $.wikiEditor.modules.dialogs.modules){$('#'+$.wikiEditor.modules.dialogs.modules[module].id).dialog('open');}},closeDialog:function(context,data){if(module in $.wikiEditor.modules.dialogs.modules){$('#'+$.wikiEditor.modules.dialogs.modules[module].id).dialog('close');}}},fn:{create:function(context,config){for(module in config){$.wikiEditor.modules.dialogs.modules[module]=config[module];} |
119 | 119 | mw.load(['$j.ui','$j.ui.dialog','$j.ui.draggable','$j.ui.resizable'],function(){for(module in $.wikiEditor.modules.dialogs.modules){var module=$.wikiEditor.modules.dialogs.modules[module];if($('#'+module.id).size()==0){var configuration=module.dialog;configuration.bgiframe=true;configuration.autoOpen=false;configuration.modal=true;configuration.title=$.wikiEditor.autoMsg(module,'title');configuration.newButtons={};for(msg in configuration.buttons) |
120 | | -configuration.newButtons[gM(msg)]=configuration.buttons[msg];configuration.buttons=configuration.newButtons;var dialogDiv=$('<div /> ').attr('id',module.id).html(module.html).data('context',context).appendTo($('body')).each(module.init).dialog(configuration);if(!('resizeme'in module)||module.resizeme) |
121 | | -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) |
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'))- |
123 | | -(wrapper.width()-oldWidth)/2);} |
124 | | -$(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;} |
125 | | -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;} |
| 120 | +configuration.newButtons[gM(msg)]=configuration.buttons[msg];configuration.buttons=configuration.newButtons;var dialogDiv=$('<div /> ').attr('id',module.id).html(module.html).data('context',context).appendTo($('body')).each(module.init).dialog(configuration);if(!('resizeme'in module)||module.resizeme){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);});} |
| 121 | +var maxTI=0;$j('[tabindex]').each(function(){var ti=parseInt($j(this).attr('tabindex'));if(ti>maxTI) |
| 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 | +$(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=='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();},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;} |
126 | 125 | match=text.match(regex);var oldOffset=0;while(match!=null){var markOffset=0;if(markAfter){markOffset+=match[0].length;} |
127 | | -this.tokenArray.push(new Token(match.index+oldOffset+markOffset,label));oldOffset+=match.index+match[0].length;newSubstring=text.substring(oldOffset);match=newSubstring.match(regex);}}}} |
128 | | -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();}} |
129 | | -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];} |
| 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 | +return context.modules.highlight.tokenArray;},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();}} |
| 128 | +markedText='';var previousIndex=0;for(var currentIndex in context.modules.highlight.markers){markedText+=rawText.substring(previousIndex,currentIndex);for(var i=0;i<context.modules.highlight.markers[currentIndex].length;i++){markedText+=context.modules.highlight.markers[currentIndex][i];} |
130 | 129 | previousIndex=currentIndex;} |
131 | | -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;} |
| 130 | +if(markedText!=''){markedText.replace(/\n/g,'<br\>');context.fn.setContents({contents:markedText});}}}};})(jQuery);(function($){$.wikiEditor.modules.preview={fn:{create:function(context,config){if('initialized'in context.modules.preview){return;} |
132 | 131 | 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;} |
133 | 132 | 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;} |
134 | 133 | 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;} |
135 | 134 | context.$changesTab.find('table.diff tbody').empty();context.$changesTab.find('.wikiEditor-preview-loading').show();var postdata={'action':'query','indexpageids':'','prop':'revisions','titles':wgPageName,'rvdifftotext':wikitext,'rvprop':'','format':'json'};var section=$('[name=wpSection]').val();if(section!='') |
136 | 135 | postdata['rvsection']=section;$.post(wgScriptPath+'/api.php',postdata,function(data){if($('link[href='+stylepath+'/common/diff.css]').size()==0){$('head').append($('<link />').attr({'rel':'stylesheet','type':'text/css','href':stylepath+'/common/diff.css'}));} |
137 | | -try{var diff=data.query.pages[data.query.pageids[0]].revisions[0].diff['*'];context.$changesTab.find('table.diff tbody').html(diff);context.$changesTab.find('.wikiEditor-preview-loading').hide();context.modules.preview.changesText=wikitext;}catch(e){}},'json');}});var loadingMsg=gM('wikieditor-preview-loading');context.modules.preview.$preview.add(context.$changesTab).append($('<div />').addClass('wikiEditor-preview-loading').append($('<img />').addClass('wikiEditor-preview-spinner').attr({'src':$.wikiEditor.imgPath+'dialogs/loading.gif','valign':'absmiddle','alt':loadingMsg,'title':loadingMsg})).append($('<span></span>').text(loadingMsg))).append($('<div />').addClass('wikiEditor-preview-contents'));context.$changesTab.find('.wikiEditor-preview-contents').html('<table class="diff"><col class="diff-marker" /><col class="diff-content" />'+'<col class="diff-marker" /><col class="diff-content" /><tbody /></table>');}}};})(jQuery);(function($){$.wikiEditor.modules.publish={api:{},fn:{create:function(context,config){var dialogID='wikiEditor-'+context.instance+'-dialog';$.wikiEditor.modules.dialogs.fn.create(context,{previewsave:{id:dialogID,titleMsg:'wikieditor-publish-dialog-title',html:'\ |
| 136 | +try{var diff=data.query.pages[data.query.pageids[0]].revisions[0].diff['*'];context.$changesTab.find('table.diff tbody').html(diff);context.$changesTab.find('.wikiEditor-preview-loading').hide();context.modules.preview.changesText=wikitext;}catch(e){}},'json');}});var loadingMsg=gM('wikieditor-preview-loading');context.modules.preview.$preview.add(context.$changesTab).append($('<div />').addClass('wikiEditor-preview-loading').append($('<img />').addClass('wikiEditor-preview-spinner').attr({'src':$.wikiEditor.imgPath+'dialogs/loading.gif','valign':'absmiddle','alt':loadingMsg,'title':loadingMsg})).append($('<span></span>').text(loadingMsg))).append($('<div />').addClass('wikiEditor-preview-contents'));context.$changesTab.find('.wikiEditor-preview-contents').html('<table class="diff"><col class="diff-marker" /><col class="diff-content" />'+'<col class="diff-marker" /><col class="diff-content" /><tbody /></table>');}}};})(jQuery);(function($){$.wikiEditor.modules.publish={fn:{create:function(context,config){var dialogID='wikiEditor-'+context.instance+'-dialog';$.wikiEditor.modules.dialogs.fn.create(context,{previewsave:{id:dialogID,titleMsg:'wikieditor-publish-dialog-title',html:'\ |
138 | 137 | <div class="wikiEditor-dialog-copywarn"></div>\ |
139 | 138 | <div class="wikiEditor-dialog-editoptions">\ |
140 | 139 | <form>\ |
— | — | @@ -157,33 +156,30 @@ |
158 | 157 | $('#wikiEditor-'+context.instance+'-dialog-minor').hide();else if($('#wpMinoredit').is(':checked')) |
159 | 158 | $('#wikiEditor-'+context.instance+'-dialog-minor').attr('checked','checked');if($('#wpWatchthis').size()==0) |
160 | 159 | $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked')) |
161 | | -$('#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){templateBeginFound=false;for(;i<tokenStack.length;i++){if(tokenStack[i].label=="TEMPLATE_BEGIN"){templateBeginFound=true;break;}} |
162 | | -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--;} |
163 | | -if(tokenStack[j].label=="TEMPLATE_BEGIN"){nestedBegins++;}} |
164 | | -if(nestedBegins==0){var leftMarker=i-1;var rightMarker=j;i=j;return[leftMarker,rightMarker];}else{return false;}}};markers=$.wikiEditor.modules.highlight.fn.markers;var tokenStack=$.wikiEditor.modules.highlight.fn.tokenArray;i=0;var templateBoundaries;templateBeginFound=false;while(templateBoundaries=findOutermostTemplates(tokenStack)){if(typeof markers[tokenStack[templateBoundaries[0]].offset]=='undefined'){markers[tokenStack[templateBoundaries[0]].offset]=[];} |
| 160 | +$('#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;}} |
| 161 | +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;} |
| 162 | +if(nestedBegins==0){var leftMarker=i-1;var rightMarker=j;i=j;return[leftMarker,rightMarker];}else{return false;}}};var markers=context.modules.highlight.data.markers;var tokenStack=context.modules.highlight.data.tokenArray;var templateBeginFound=false;var templateBoundaries;while(templateBoundaries=findOutermostTemplates(tokenStack)){if(typeof markers[tokenStack[templateBoundaries[0]].offset]=='undefined'){markers[tokenStack[templateBoundaries[0]].offset]=[];} |
165 | 163 | if(typeof markers[tokenStack[templateBoundaries[1]].offset]=='undefined'){markers[tokenStack[templateBoundaries[1]].offset]=[];} |
166 | | -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;} |
| 164 | +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;} |
167 | 165 | function Range(begin,end){this.begin=begin;this.end=end;} |
168 | | -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)+" "+ |
169 | | -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;}} |
170 | | -sanatizedSegment=sanatizedStr.substring(startIndex,endIndex).replace(/[{}|=]/g,'X');sanatizedStr=sanatizedStr.substring(0,startIndex)+ |
171 | | -sanatizedSegment+sanatizedStr.substring(endIndex);} |
172 | | -return sanatizedStr;};if(wikitext.match(/\s*{{\s*\S*:/)){} |
173 | | -markOffTemplates();var doneParsing=false;oldDivider=0;divider=sanatizedStr.indexOf('|',oldDivider);if(divider==-1){divider=sanatizedStr.length;doneParsing=true;} |
174 | | -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);} |
175 | | -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;} |
176 | | -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;} |
177 | | -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;}} |
178 | | -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"";} |
| 166 | +function getSetValue(name,value,original){var valueRange;var rangeIndex;var retVal;if(isNaN(name)){if(typeof paramsByName[name]=='undefined'){return"";} |
179 | 167 | rangeIndex=paramsByName[name];}else{rangeIndex=parseInt(name);} |
180 | 168 | if(typeof params[rangeIndex]=='undefined'){return"";} |
181 | 169 | valueRange=ranges[params[rangeIndex].valueIndex];if(typeof valueRange.newVal=='undefined'||original){retVal=wikitext.substring(valueRange.begin,valueRange.end);}else{retVal=valueRange.newVal;} |
182 | 170 | if(value!=null){ranges[params[rangeIndex].valueIndex].newVal=value;} |
183 | 171 | return retVal;};this.getName=function(){if(typeof ranges[templateNameIndex].newVal=='undefined'){return wikitext.substring(ranges[templateNameIndex].begin,ranges[templateNameIndex].end);}else{return ranges[templateNameIndex].newVal;}};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.getAllParamNames=function(){return paramsByName;};this.getAllInitialParams=function(){return params;} |
184 | 172 | this.getOriginalText=function(){return wikitext;};this.getText=function(){newText="";for(i=0;i<ranges.length;i++){if(typeof ranges[i].newVal=='undefined'){wikitext.substring(ranges[i].begin,ranges[i].end);}else{newText+=ranges[i].newVal;}} |
185 | | -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()- |
| 173 | +return newText;};if(wikitext.match(/\s*{{\s*\S*:/)){} |
| 174 | +var sanatizedStr=wikitext.replace(/{{/," ");endBraces=sanatizedStr.match(/}}\s*$/);sanatizedStr=sanatizedStr.substring(0,endBraces.index)+" "+sanatizedStr.substring(endBraces.index+2);while(sanatizedStr.indexOf('{{')!=-1){startIndex=sanatizedStr.indexOf('{{')+1;openBraces=2;endIndex=startIndex;while(openBraces>0){var brace=sanatizedStr[++endIndex];openBraces+=brace=='}'?-1:brace=='{'?1:0;} |
| 175 | +sanatizedSegment=sanatizedStr.substring(startIndex,endIndex).replace(/[{}|=]/g,'X');sanatizedStr=sanatizedStr.substring(0,startIndex)+sanatizedSegment+sanatizedStr.substring(endIndex);} |
| 176 | +var ranges=[];var params=[];var templateNameIndex=0;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);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;} |
| 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))-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;}} |
| 181 | +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()- |
186 | 182 | context.$ui.find('.tab-toc').outerHeight());}},fn:{create:function(context,config){if('$toc'in context.modules.toc){return;} |
187 | | -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++;} |
| 183 | +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.cfg.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.cfg.defaultWidth).children().css('marginRight',$.wikiEditor.modules.toc.cfg.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++;} |
188 | 184 | section=Math.max(0,section);} |
189 | 185 | var sectionLink=context.modules.toc.$toc.find('div.section-'+section);sectionLink.addClass('current');var relTop=sectionLink.offset().top-context.modules.toc.$toc.offset().top;var scrollTop=context.modules.toc.$toc.scrollTop();var divHeight=context.modules.toc.$toc.height();var sectionHeight=sectionLink.height();if(relTop<0) |
190 | 186 | context.modules.toc.$toc.scrollTop(scrollTop+relTop);else if(relTop+sectionHeight>divHeight) |
— | — | @@ -196,10 +192,10 @@ |
197 | 193 | list.append(item);} |
198 | 194 | return list;} |
199 | 195 | function buildCollapseControls(){var $collapseControl=$('<div />'),$expandControl=$('<div />');$collapseControl.addClass('tab').addClass('tab-toc').append('<a href="#" />').bind('click.wikiEditor-toc',function(){context.modules.toc.$toc.trigger('collapse.wikiEditor-toc');return false;}).find('a').text(gM('wikieditor-toc-hide'));$expandControl.addClass('wikiEditor-ui-toc-expandControl').append('<a href="#" />').bind('click.wikiEditor-toc',function(){context.modules.toc.$toc.trigger('expand.wikiEditor-toc');return false;}).hide().find('a').text(gM('wikieditor-toc-show'));$collapseControl.insertBefore(context.modules.toc.$toc);context.$ui.find('.wikiEditor-ui-left .wikiEditor-ui-top').append($expandControl);context.fn.trigger('resize');} |
200 | | -function buildResizeControls(){context.$ui.data('resizableDone',true).find('.wikiEditor-ui-right').data('wikiEditor-ui-left',context.$ui.find('.wikiEditor-ui-left')).resizable({handles:'w,e',preventPositionLeftChange:true,minWidth:50,start:function(e,ui){var $this=$(this);$('<div />').addClass('wikiEditor-ui-resize-mask').css({'position':'absolute','z-index':2,'left':0,'top':0,'bottom':0,'right':0}).appendTo(context.$ui.find('.wikiEditor-ui-left'));$this.resizable('option','maxWidth',$this.parent().width()-450);},resize:function(e,ui){$(this).css({'width':ui.size.width,'top':'auto','height':'auto'}).data('wikiEditor-ui-left').css('marginRight',(-1*ui.size.width)).children().css('marginRight',ui.size.width);context.fn.trigger('resize');},stop:function(e,ui){context.$ui.find('.wikiEditor-ui-resize-mask').remove();context.$content.trigger('mouseup');if(ui.size.width<parseFloat($.wikiEditor.modules.toc.minimumWidth)){context.modules.toc.$toc.trigger('collapse');}else{context.modules.toc.$toc.data('openWidth',ui.size.width);$.cookie('wikiEditor-'+context.instance+'-toc-width',ui.size.width);} |
| 196 | +function buildResizeControls(){context.$ui.data('resizableDone',true).find('.wikiEditor-ui-right').data('wikiEditor-ui-left',context.$ui.find('.wikiEditor-ui-left')).resizable({handles:'w,e',preventPositionLeftChange:true,minWidth:50,start:function(e,ui){var $this=$(this);$('<div />').addClass('wikiEditor-ui-resize-mask').css({'position':'absolute','z-index':2,'left':0,'top':0,'bottom':0,'right':0}).appendTo(context.$ui.find('.wikiEditor-ui-left'));$this.resizable('option','maxWidth',$this.parent().width()-450);},resize:function(e,ui){$(this).css({'width':ui.size.width,'top':'auto','height':'auto'}).data('wikiEditor-ui-left').css('marginRight',(-1*ui.size.width)).children().css('marginRight',ui.size.width);context.fn.trigger('resize');},stop:function(e,ui){context.$ui.find('.wikiEditor-ui-resize-mask').remove();context.$content.trigger('mouseup');if(ui.size.width<parseFloat($.wikiEditor.modules.toc.cfg.minimumWidth)){context.modules.toc.$toc.trigger('collapse');}else{context.modules.toc.$toc.data('openWidth',ui.size.width);$.cookie('wikiEditor-'+context.instance+'-toc-width',ui.size.width);} |
201 | 197 | context.fn.trigger('resize');}});var handle=$j('body').is('.rtl')?'w':'e' |
202 | | -context.$ui.find('.ui-resizable-'+handle).removeClass('ui-resizable-'+handle).addClass('ui-resizable-'+(handle=='w'?'e':'w')).addClass('wikiEditor-ui-toc-resize-grip');context.modules.toc.$toc.bind('collapse.wikiEditor-toc',$.wikiEditor.modules.toc.fn.collapse).bind('expand.wikiEditor-toc',$.wikiEditor.modules.toc.fn.expand);context.modules.toc.$toc.data('openWidth',$.wikiEditor.modules.toc.defaultWidth);if($.cookie('wikiEditor-'+context.instance+'-toc-width')==0){context.modules.toc.$toc.trigger('collapse.wikiEditor-toc',{data:context});}else if($.cookie('wikiEditor-'+context.instance+'-toc-width')>0){var initialWidth=$.cookie('wikiEditor-'+context.instance+'-toc-width');if(initialWidth<parseFloat($.wikiEditor.modules.toc.minimumWidth)) |
203 | | -initialWidth=parseFloat($.wikiEditor.modules.toc.minimumWidth)+1;context.modules.toc.$toc.data('openWidth',initialWidth+'px');context.$ui.find('.wikiEditor-ui-right').css('width',initialWidth+'px');context.$ui.find('.wikiEditor-ui-left').css('marginRight',(parseFloat(initialWidth)*-1)+'px').children().css('marginRight',initialWidth+'px');}} |
| 198 | +context.$ui.find('.ui-resizable-'+handle).removeClass('ui-resizable-'+handle).addClass('ui-resizable-'+(handle=='w'?'e':'w')).addClass('wikiEditor-ui-toc-resize-grip');context.modules.toc.$toc.bind('collapse.wikiEditor-toc',$.wikiEditor.modules.toc.fn.collapse).bind('expand.wikiEditor-toc',$.wikiEditor.modules.toc.fn.expand);context.modules.toc.$toc.data('openWidth',$.wikiEditor.modules.toc.cfg.defaultWidth);if($.cookie('wikiEditor-'+context.instance+'-toc-width')==0){context.modules.toc.$toc.trigger('collapse.wikiEditor-toc',{data:context});}else if($.cookie('wikiEditor-'+context.instance+'-toc-width')>0){var initialWidth=$.cookie('wikiEditor-'+context.instance+'-toc-width');if(initialWidth<parseFloat($.wikiEditor.modules.toc.cfg.minimumWidth)) |
| 199 | +initialWidth=parseFloat($.wikiEditor.modules.toc.cfg.minimumWidth)+1;context.modules.toc.$toc.data('openWidth',initialWidth+'px');context.$ui.find('.wikiEditor-ui-right').css('width',initialWidth+'px');context.$ui.find('.wikiEditor-ui-left').css('marginRight',(parseFloat(initialWidth)*-1)+'px').children().css('marginRight',initialWidth+'px');}} |
204 | 200 | var outline=[],h=0;function traverseTextNodes(){if(this.nodeName!='#text'){$(this.childNodes).each(traverseTextNodes);return;} |
205 | 201 | var text=this.nodeValue;var p=this;while(!p.previousSibling) |
206 | 202 | p=p.parentNode;var prev=p?p.previousSibling:null;p=this;while(p&&!p.nextSibling) |