r59933 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59932‎ | r59933 | r59934 >
Date:17:45, 10 December 2009
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Fix coding style for templateEditor and highlight modules (mostly whitespace, but some non-whitespace as well; more to come) and add templateEditor to Makefile
Modified paths:
  • /trunk/extensions/UsabilityInitiative/Makefile (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js
@@ -9,75 +9,68 @@
1010 },
1111
1212 evt: {
13 - mark: function(){
14 -
15 - var findOutermostTemplates = function(){
16 - templateBeginFound = false;
17 - for(;i< tokenStack.length; i++){
18 - if(tokenStack[i].label == "TEMPLATE_BEGIN"){
 13+ mark: function() {
 14+ function findOutermostTemplates( tokenStack ) {
 15+ var templateBeginFound = false;
 16+ for ( ;i< tokenStack.length; i++ ) {
 17+ if ( tokenStack[i].label == "TEMPLATE_BEGIN" ) {
1918 templateBeginFound = true;
20 - break;
 19+ break;
2120 }
2221 }
2322 var j = i;
2423 i++;
25 - if(!templateBeginFound){
 24+ if ( !templateBeginFound ) {
2625 return false;
27 - }
28 - else{
 26+ } else {
2927 // This is only designed to find the outermost template boundaries, the model handles nested template
3028 // and template-like objects better
3129 var nestedBegins = 1;
32 - while(nestedBegins > 0 && j < tokenStack.length){
 30+ while ( nestedBegins > 0 && j < tokenStack.length ) {
3331 j++;
34 - if(tokenStack[j].label == "TEMPLATE_END"){
 32+ if ( tokenStack[j].label == "TEMPLATE_END" ) {
3533 nestedBegins--;
3634 }
37 - if(tokenStack[j].label == "TEMPLATE_BEGIN"){
 35+ if ( tokenStack[j].label == "TEMPLATE_BEGIN" ) {
3836 nestedBegins++;
3937 }
40 - }//while
41 - if(nestedBegins == 0){
 38+ }
 39+ if ( nestedBegins == 0 ) {
4240 // outer template begins at tokenStack[i].offset
4341 // and ends at tokenStack[j].offset + 2
4442 var leftMarker = i -1;
4543 var rightMarker = j;
4644 i = j;
4745 return [ leftMarker, rightMarker ];
48 - }
49 - else{
 46+ } else {
5047 return false;
5148 }
5249 }
5350 }; //find outermost templates
5451
5552 var markers = $.wikiEditor.modules.highlight.fn.markers;
56 - tokenStack = $.wikiEditor.modules.highlight.fn.tokenArray;
57 - var i=0;
58 - var templateBoundaries = findOutermostTemplates();
 53+ var tokenStack = $.wikiEditor.modules.highlight.fn.tokenArray;
 54+ var i = 0;
 55+ var templateBoundaries;
 56+ var templateBeginFound = false;
5957
60 - templateBeginFound = false;
61 -
62 - while(templateBoundaries){
63 - if(typeof(markers[tokenStack[templateBoundaries[0]].offset]) == 'undefined'){
64 - markers[tokenStack[templateBoundaries[0]].offset] = new Array();
 58+ while ( templateBoundaries = findOutermostTemplates( tokenStack ) ) {
 59+ if ( typeof markers[tokenStack[templateBoundaries[0]].offset] == 'undefined' ) {
 60+ markers[tokenStack[templateBoundaries[0]].offset] = [];
6561 }
66 - if(typeof(markers[tokenStack[templateBoundaries[1]].offset]) == 'undefined'){
67 - markers[tokenStack[templateBoundaries[1]].offset] = new Array();
 62+ if ( typeof markers[tokenStack[templateBoundaries[1]].offset] == 'undefined' ) {
 63+ markers[tokenStack[templateBoundaries[1]].offset] = [];
6864 }
6965
70 - markers[tokenStack[templateBoundaries[0]].offset].push("<div class='wiki-template'>");
71 - markers[tokenStack[templateBoundaries[1]].offset].push("</div>");
72 -
73 - templateBoundaries = findOutermostTemplates();
74 - }
 66+ markers[tokenStack[templateBoundaries[0]].offset].push( "<div class='wiki-template'>" );
 67+ markers[tokenStack[templateBoundaries[1]].offset].push( "</div>" );
 68+ }
7569 }
7670 },
7771
78 -
7972 exp: [
80 - { regex: /{{/ , label: "TEMPLATE_BEGIN" },
81 - { regex: /}}/ , label: "TEMPLATE_END" , markAfter:true}
 73+ { regex: /{{/, label: "TEMPLATE_BEGIN" },
 74+ { regex: /}}/, label: "TEMPLATE_END", markAfter: true }
8275 ],
8376
8477 /**
@@ -91,16 +84,13 @@
9285 */
9386 create: function( context, config ) {
9487
95 - //check if text is selected
96 -
97 -
98 - },
 88+ // check if text is selected
 89+ },
9990
10091 //template Model
101 - model: function (wikitext){
102 -
103 - //param object
104 - function param(name, value, number, nameIndex, equalsIndex, valueIndex){
 92+ model: function( wikitext ) {
 93+ // Param object
 94+ function Param( name, value, number, nameIndex, equalsIndex, valueIndex ) {
10595 this.name = name;
10696 this.value = value;
10797 this.number = number;
@@ -109,163 +99,167 @@
110100 this.valueIndex = valueIndex;
111101 }
112102
113 - //range object
114 - function range(begin, end){
 103+ // Range object
 104+ function Range( begin, end ) {
115105 this.begin = begin;
116106 this.end = end;
117107 }
118108
119 - var ranges = new Array();
 109+ var ranges = [];
120110 var sanatizedStr = "";
121 - var params = new Array();
122 - var paramsByName = new Array();
 111+ var params = [];
 112+ var paramsByName = [];
123113 var templateNameIndex = 0;
124114
125 - //markOffTemplates
126 - markOffTemplates = function () {
127 - sanatizedStr = wikitext;
 115+ function markOffTemplates() {
 116+ sanatizedStr = wikitext.replace( /{{/, " " ); //get rid of first {{ with whitespace
 117+ endBraces = sanatizedStr.match( /}}\s*$/ ); //replace end
 118+ sanatizedStr = sanatizedStr.substring( 0, endBraces.index ) + " " +
 119+ sanatizedStr.substring( endBraces.index + 2 );
128120
129 - sanatizedStr = sanatizedStr.replace(/{{/, " "); //get rid of first {{ with whitespace
130 - endBraces = sanatizedStr.match(/}}\s*$/); //replace end
131 - sanatizedStr = sanatizedStr.substring(0,endBraces.index) + " " + sanatizedStr.substring(endBraces.index+2);
132 -
133 - while(sanatizedStr.indexOf('{{') != -1){
 121+ while ( sanatizedStr.indexOf( '{{' ) != -1 ) {
134122 startIndex = sanatizedStr.indexOf('{{') + 1;
135123 openBraces = 2;
136124 endIndex = startIndex;
137 - while(openBraces > 0){
 125+ while ( openBraces > 0 ) {
138126 endIndex++;
139 - switch (sanatizedStr[endIndex]){
 127+ switch ( sanatizedStr[endIndex] ) {
140128 case '}': openBraces--; break;
141129 case '{': openBraces++; break;
142130 }
143131 }
144 - sanatizedSegment = sanatizedStr.substring(startIndex,endIndex);
145 - sanatizedSegment = sanatizedSegment.replace(/}/g, "X");
146 - sanatizedSegment = sanatizedSegment.replace(/{/g, "X");
147 - sanatizedSegment = sanatizedSegment.replace(/\|/g, "X");
148 - sanatizedSegment = sanatizedSegment.replace(/=/g, "X");
149 - sanatizedStr = sanatizedStr.substring(0, startIndex) + sanatizedSegment + sanatizedStr.substring(endIndex);
150 - }
 132+ sanatizedSegment = sanatizedStr.substring( startIndex,endIndex )
 133+ .replace( /[{}|=]/g 'X' );
 134+ sanatizedStr = sanatizedStr.substring( 0, startIndex ) +
 135+ sanatizedSegment + sanatizedStr.substring( endIndex );
151136 };
152137
153138 // Whitespace* {{ whitespace* nonwhitespace:
154 - if(wikitext.match(/\s*{{\s*\S*:/)){
155 - //we have a parser function!
 139+ if ( wikitext.match( /\s*{{\s*\S*:/ ) ) {
 140+ // we have a parser function!
156141 }
157142
158143 markOffTemplates();
159144
160145 var doneParsing = false;
161146 oldDivider = 0;
162 - divider = sanatizedStr.indexOf('|', oldDivider);
163 - if(divider == -1){divider = sanatizedStr.length; doneParsing = true;}
164 - nameMatch = wikitext.substring(oldDivider, divider).match(/[^{\s]+/);
 147+ divider = sanatizedStr.indexOf( '|', oldDivider );
 148+ if ( divider == -1 ) {
 149+ divider = sanatizedStr.length;
 150+ doneParsing = true;
 151+ }
 152+ nameMatch = wikitext.substring( oldDivider, divider ).match( /[^{\s]+/ );
165153 if(nameMatch != undefined){
166 - ranges.push( new range(oldDivider,nameMatch.index) ); //whitespace and squiggles upto the name
167 - templateNameIndex = ranges.push( new range(nameMatch.index, nameMatch.index + nameMatch[0].length));
 154+ ranges.push( new Range( oldDivider,nameMatch.index ) ); //whitespace and squiggles upto the name
 155+ templateNameIndex = ranges.push( new Range( nameMatch.index,
 156+ nameMatch.index + nameMatch[0].length ) );
168157 templateNameIndex--; //push returns 1 less than the array
169 - ranges[templateNameIndex].old = wikitext.substring(ranges[templateNameIndex].begin, ranges[templateNameIndex].end);
 158+ ranges[templateNameIndex].old = wikitext.substring( ranges[templateNameIndex].begin,
 159+ ranges[templateNameIndex].end );
170160 }
171 - params.push(ranges[templateNameIndex].old); //put something in params (0)
 161+ params.push( ranges[templateNameIndex].old ); //put something in params (0)
172162
173163 currentParamNumber = 0;
174164 var valueEndIndex;
175 - while(!doneParsing){
 165+ while ( !doneParsing ) {
176166 currentParamNumber++;
177167 oldDivider = divider;
178 - divider = sanatizedStr.indexOf('|', oldDivider+1);
179 - if(divider == -1){divider = sanatizedStr.length; doneParsing = true;}
180 - currentField = sanatizedStr.substring(oldDivider+1,divider);
181 - if(currentField.indexOf('=') == -1){
182 - //anonymous field, gets a number
183 - valueBegin = currentField.match(/\S+/); //first nonwhitespace character
184 - valueBeginIndex = valueBegin.index + oldDivider+1;
185 - valueEnd = currentField.match(/[^\s]\s*$/); //last nonwhitespace character
 168+ divider = sanatizedStr.indexOf( '|', oldDivider + 1 );
 169+ if ( divider == -1 ) {
 170+ divider = sanatizedStr.length;
 171+ doneParsing = true;
 172+ }
 173+ currentField = sanatizedStr.substring( oldDivider+1, divider );
 174+ if ( currentField.indexOf( '=' ) == -1 ) {
 175+ // anonymous field, gets a number
 176+ valueBegin = currentField.match( /\S+/ ); //first nonwhitespace character
 177+ valueBeginIndex = valueBegin.index + oldDivider + 1;
 178+ valueEnd = currentField.match( /[^\s]\s*$/ ); //last nonwhitespace character
186179 valueEndIndex = valueEnd.index + oldDivider + 2;
187 - ranges.push(new range(ranges[ranges.length-1].end, valueBeginIndex) ); //all the chars upto now
188 - nameIndex = ranges.push(new range(valueBeginIndex, valueBeginIndex));
 180+ ranges.push( new Range( ranges[ranges.length-1].end,
 181+ valueBeginIndex ) ); //all the chars upto now
 182+ nameIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) );
189183 nameIndex--;
190 - equalsIndex = ranges.push(new range(valueBeginIndex, valueBeginIndex));
 184+ equalsIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) );
191185 equalsIndex--;
192 - valueIndex = ranges.push(new range(valueBeginIndex, valueEndIndex));
 186+ valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) );
193187 valueIndex--;
194 - params.push(new param(currentParamNumber,
195 - wikitext.substring(ranges[valueIndex].begin, ranges[valueIndex].end),
196 - currentParamNumber, nameIndex, equalsIndex, valueIndex));
 188+ params.push( new Param( currentParamNumber,
 189+ wikitext.substring( ranges[valueIndex].begin, ranges[valueIndex].end ),
 190+ currentParamNumber, nameIndex, equalsIndex, valueIndex ) );
197191 paramsByName[currentParamNumber] = currentParamNumber;
198 - }
199 - else{
200 - //there's an equals, could be comment or a value pair
201 - currentName = currentField.substring(0, currentField.indexOf('='));
202 - //(still offset by oldDivider)
203 - nameBegin = currentName.match(/\S+/); //first nonwhitespace character
204 - if(nameBegin == null){ divider++; currentParamNumber--; continue;} // this is a comment inside a template call/parser abuse. let's not encourage it
205 - nameBeginIndex = nameBegin.index + oldDivider+1;
206 - nameEnd = currentName.match(/[^\s]\s*$/); //last nonwhitespace and non } character
207 - nameEndIndex = nameEnd.index + oldDivider+2;
 192+ } else {
 193+ // there's an equals, could be comment or a value pair
 194+ currentName = currentField.substring( 0, currentField.indexOf( '=' ) );
 195+ // (still offset by oldDivider)
 196+ nameBegin = currentName.match( /\S+/ ); //first nonwhitespace character
 197+ if ( nameBegin == null ) {
 198+ // this is a comment inside a template call/parser abuse. let's not encourage it
 199+ divider++;
 200+ currentParamNumber--;
 201+ continue;
 202+ }
 203+ nameBeginIndex = nameBegin.index + oldDivider + 1;
 204+ nameEnd = currentName.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character
 205+ nameEndIndex = nameEnd.index + oldDivider + 2;
208206
209 - ranges.push(new range(ranges[ranges.length-1].end, nameBeginIndex) ); //all the chars upto now
210 - nameIndex = ranges.push(new range(nameBeginIndex, nameEndIndex));
 207+ ranges.push( new Range( ranges[ranges.length-1].end,
 208+ nameBeginIndex ) ); //all the chars upto now
 209+ nameIndex = ranges.push( new Range( nameBeginIndex, nameEndIndex ) );
211210 nameIndex--;
212 - currentValue = currentField.substring(currentField.indexOf('=') + 1);
213 - oldDivider += (currentField.indexOf('=') +1);
214 - valueBegin = currentValue.match(/\S+/); //first nonwhitespace character
 211+ currentValue = currentField.substring( currentField.indexOf( '=' ) + 1);
 212+ oldDivider += currentField.indexOf( '=' ) + 1;
 213+ valueBegin = currentValue.match( /\S+/ ); //first nonwhitespace character
215214 valueBeginIndex = valueBegin.index + oldDivider + 1;
216 - valueEnd = currentValue.match(/[^\s]\s*$/); //last nonwhitespace and non } character
 215+ valueEnd = currentValue.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character
217216 valueEndIndex = valueEnd.index + oldDivider + 2;
218 - equalsIndex = ranges.push(new range(ranges[ranges.length-1].end, valueBeginIndex) ); //all the chars upto now
 217+ equalsIndex = ranges.push( new Range( ranges[ranges.length-1].end,
 218+ valueBeginIndex) ); //all the chars upto now
219219 equalsIndex--;
220 - valueIndex = ranges.push(new range(valueBeginIndex, valueEndIndex));
 220+ valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) );
221221 valueIndex--;
222 - params.push(new param(wikitext.substring(nameBeginIndex, nameEndIndex),
223 - wikitext.substring(valueBeginIndex, valueEndIndex),
224 - currentParamNumber, nameIndex, equalsIndex, valueIndex));
225 - paramsByName[wikitext.substring(nameBeginIndex, nameEndIndex)] = currentParamNumber;
 222+ params.push( new Param( wikitext.substring( nameBeginIndex, nameEndIndex ),
 223+ wikitext.substring( valueBeginIndex, valueEndIndex ),
 224+ currentParamNumber, nameIndex, equalsIndex, valueIndex ) );
 225+ paramsByName[wikitext.substring( nameBeginIndex, nameEndIndex )] = currentParamNumber;
226226 }
227227 }
228228 //the rest of the string
229 - ranges.push(new range(valueEndIndex, wikitext.length));
 229+ ranges.push( new Range( valueEndIndex, wikitext.length ) );
230230
231231 //FUNCTIONS
232232 //set 'original' to true if you want the original value irrespective of whether the model's been changed
233 - getSetValue = function(name, value, original){
 233+ function getSetValue( name, value, original ) {
234234 var valueRange;
235235 var rangeIndex;
236236 var retVal;
237 - if(isNaN(name)){
238 - //it's a string!
239 - if(typeof(paramsByName[name]) == 'undefined'){
 237+ if ( isNaN( name ) ) {
 238+ // it's a string!
 239+ if ( typeof paramsByName[name] == 'undefined' ) {
240240 //does not exist
241241 return "";
242242 }
243 - else{
244 - rangeIndex = paramsByName[name];
245 - }
246 - }
247 - else{
 243+ rangeIndex = paramsByName[name];
 244+ } else {
248245 //it's a number!
249 - rangeIndex = parseInt(name);
 246+ rangeIndex = parseInt( name );
250247 }
251248
252 - if(typeof(params[rangeIndex]) == 'undefined' ){
 249+ if ( typeof params[rangeIndex] == 'undefined' ) {
253250 //does not exist
254251 return "";
255252 }
256 - else{
257 - valueRange = ranges[params[rangeIndex].valueIndex];
258 - }
 253+ valueRange = ranges[params[rangeIndex].valueIndex];
259254
260 - if(typeof(valueRange.newVal) == 'undefined' || original ){
 255+ if ( typeof valueRange.newVal == 'undefined' || original ) {
261256 //value unchanged, return original wikitext
262 - retVal= wikitext.substring(valueRange.begin, valueRange.end);
263 - }
264 - else{
 257+ retVal = wikitext.substring( valueRange.begin, valueRange.end );
 258+ } else {
265259 //new value exists, return new value
266260 retVal = valueRange.newVal;
267261 }
268262
269 - if(value != null){
 263+ if ( value != null ) {
270264 ranges[params[rangeIndex].valueIndex].newVal = value;
271265 }
272266
@@ -275,65 +269,52 @@
276270 //'public' functions
277271
278272 //get template name
279 - this.getName = function(){
280 - if(typeof(ranges[templateNameIndex].newVal) == 'undefined'){
281 - return wikitext.substring(ranges[templateNameIndex].begin, ranges[templateNameIndex].end);
282 - }
283 - else{
284 - return ranges[templateNameIndex].newVal;
285 - }
 273+ this.getName = function() {
 274+ return ranges[templateNameIndex].newVal ||
 275+ wikitext.substring( ranges[templateNameIndex].begin,
 276+ ranges[templateNameIndex].end );
286277 };
287278
288279 //set template name (if we want to support this)
289 - this.setName = function(name){
 280+ this.setName = function( name ) {
290281 ranges[templateNameIndex].newVal = name;
291282 };
292283
293284 //set value for a given param name/number
294 - this.setValue = function(name, value){
295 - return getSetValue(name, value, false);
 285+ this.setValue = function( name, value ) {
 286+ return getSetValue( name, value, false );
296287 };
297288
298289 //get value for a given param name/number
299 - this.getValue = function(name){
300 - return getSetValue(name, null, false);
 290+ this.getValue = function( name ) {
 291+ return getSetValue( name, null, false );
301292 };
302293
303294 //get original value of a param
304 - this.getOriginalValue = function(name){
305 - return getSetValue(name, null, true);
 295+ this.getOriginalValue = function( name ) {
 296+ return getSetValue( name, null, true );
306297 };
307298
308299 //get a list of all param names (numbers for the anonymous ones)
309 - this.getAllParams = function(){
 300+ this.getAllParams = function() {
310301 return paramsByName;
311302 };
312303
313304 //get original template text
314 - this.getOriginalText = function(){
 305+ this.getOriginalText = function() {
315306 return wikitext;
316307 };
317308
318309 //get modified template text
319 - this.getText = function(){
 310+ this.getText = function() {
320311 newText = "";
321 - for(i = 0 ; i < ranges.length; i++){
322 - if(typeof(ranges[i].newVal) == 'undefined'){
323 - newText += wikitext.substring(ranges[i].begin, ranges[i].end);
324 - }
325 - else{
326 - newText += ranges[i].newVal;
327 - }
 312+ for ( i = 0 ; i < ranges.length; i++ ) {
 313+ newText += ranges[i].newVal || wikitext.substring(
 314+ ranges[i].begin, ranges[i].end );
328315 }
329316 return newText;
330317 };
331 -
332318 }//template model
333 -
334 -
335 -
336 -
337 -
338319 }
339320
340321 }; } )( jQuery );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js
@@ -34,10 +34,10 @@
3535 * ; Definition
3636 * : Definition
3737 */
38 - if(event.data.scope == 'do_not_trigger'){
39 - $.wikiEditor.modules.highlight.fn.scan(context, "");
40 - $.wikiEditor.modules.highlight.fn.mark(context, "", "");
41 - }
 38+ if ( event.data.scope == 'do_not_trigger' ) {
 39+ $.wikiEditor.modules.highlight.fn.scan( context, "" );
 40+ $.wikiEditor.modules.highlight.fn.mark( context, "", "" );
 41+ }
4242 }
4343 },
4444
@@ -67,40 +67,40 @@
6868 strip: function( context, division ) {
6969 return $( '<div />' ).html( division.html().replace( /\<br[^\>]*\>/g, "\n" ) ).text();
7070 },
71 - tokenArray : [],
 71+ tokenArray: [],
7272 scan: function( context, division ) {
73 - /*
74 - * We need to look over some text and find interesting areas, then return the positions of those areas as tokens
75 - */
76 - token = function(offset, label){
 73+ // We need to look over some text and find interesting areas, then return the
 74+ // positions of those areas as tokens
 75+ function Token( offset, label ) {
7776 this.offset = offset;
7877 this.label = label;
7978 }
8079
81 - this.tokenArray = new Array();
 80+ this.tokenArray = [];
8281 var text = context.fn.getContents();
8382 for ( module in $.wikiEditor.modules ) {
8483 if ( 'exp' in $.wikiEditor.modules[module] ) {
85 - for(var i = 0; i < $.wikiEditor.modules[module].exp.length; i++){
 84+ for ( var i = 0; i < $.wikiEditor.modules[module].exp.length; i++ ) {
8685 var regex = $.wikiEditor.modules[module].exp[i].regex;
8786 var label = $.wikiEditor.modules[module].exp[i].label;
8887 var markAfter = false;
89 - if(typeof($.wikiEditor.modules[module].exp[i].markAfter) != 'undefined'){
 88+ if ( typeof $.wikiEditor.modules[module].exp[i].markAfter != 'undefined' ) {
9089 markAfter = true;
9190 }
92 - match = text.match(regex);
 91+ match = text.match( regex );
9392 var oldOffset = 0;
94 - while(match != null){
 93+ while ( match != null ) {
9594 var markOffset = 0;
96 - if(markAfter){
 95+ if ( markAfter ) {
9796 markOffset += match[0].length;
9897 }
99 - this.tokenArray.push(new token(match.index + oldOffset + markOffset, label));
100 - oldOffset += (match.index + match[0].length);
101 - newSubstring = text.substring(oldOffset);
102 - match = newSubstring.match(regex);
 98+ this.tokenArray.push( new Token(
 99+ match.index + oldOffset + markOffset, label ) );
 100+ oldOffset += match.index + match[0].length;
 101+ newSubstring = text.substring( oldOffset );
 102+ match = newSubstring.match( regex );
103103 }
104 - }
 104+ }
105105 }
106106 }
107107
@@ -108,34 +108,31 @@
109109 },
110110 markers: [],
111111 mark: function( context, division, tokens ) {
112 - /*
113 - * We need to markup some text based on some tokens
114 - */
 112+ // We need to markup some text based on some tokens
115113 var rawText = context.fn.getContents();
116114
117 -
118115 //get all markers
119116 for ( module in $.wikiEditor.modules ) {
120 - if ( 'evt' in $.wikiEditor.modules[module] && 'mark' in $.wikiEditor.modules[module].evt) {
 117+ if ( 'evt' in $.wikiEditor.modules[module] && 'mark' in $.wikiEditor.modules[module].evt ) {
121118 $.wikiEditor.modules[module].evt.mark();
122119 }
123120 }
124121 markedText = "";
125122 var previousIndex = 0;
126 - for(var currentIndex in this.markers){
127 - markedText+= rawText.substring(previousIndex, currentIndex);
 123+ for ( var i = 0; i < this.markers.length; i++ ) {
 124+ markedText += rawText.substring( previousIndex, currentIndex );
128125
129 - for(var i = 0 ; i < this.markers[currentIndex].length; i++){
130 - markedText += this.markers[currentIndex][i];
 126+ for ( var j = 0 ; i < this.markers[i].length; j++ ) {
 127+ markedText += this.markers[i][j];
131128 }
132129
133130 previousIndex = currentIndex;
134131 }
135 - if(markedText != ""){
136 - markedText.replace(/\n/g, '<br\>');
137 - context.fn.setContents({contents:markedText});
 132+ if ( markedText != "" ) {
 133+ markedText.replace( /\n/g, '<br>' );
 134+ context.fn.setContents( { contents:markedText } );
138135 }
139 - }//endmark
 136+ }
140137 }
141138
142139 }; })( jQuery );
\ No newline at end of file
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -2136,10 +2136,10 @@
21372137 * ; Definition
21382138 * : Definition
21392139 */
2140 - if(event.data.scope == 'do_not_trigger'){
2141 - $.wikiEditor.modules.highlight.fn.scan(context, "");
2142 - $.wikiEditor.modules.highlight.fn.mark(context, "", "");
2143 - }
 2140+ if ( event.data.scope == 'do_not_trigger' ) {
 2141+ $.wikiEditor.modules.highlight.fn.scan( context, "" );
 2142+ $.wikiEditor.modules.highlight.fn.mark( context, "", "" );
 2143+ }
21442144 }
21452145 },
21462146
@@ -2169,40 +2169,40 @@
21702170 strip: function( context, division ) {
21712171 return $( '<div />' ).html( division.html().replace( /\<br[^\>]*\>/g, "\n" ) ).text();
21722172 },
2173 - tokenArray : [],
 2173+ tokenArray: [],
21742174 scan: function( context, division ) {
2175 - /*
2176 - * We need to look over some text and find interesting areas, then return the positions of those areas as tokens
2177 - */
2178 - token = function(offset, label){
 2175+ // We need to look over some text and find interesting areas, then return the
 2176+ // positions of those areas as tokens
 2177+ function Token( offset, label ) {
21792178 this.offset = offset;
21802179 this.label = label;
21812180 }
21822181
2183 - this.tokenArray = new Array();
 2182+ this.tokenArray = [];
21842183 var text = context.fn.getContents();
21852184 for ( module in $.wikiEditor.modules ) {
21862185 if ( 'exp' in $.wikiEditor.modules[module] ) {
2187 - for(var i = 0; i < $.wikiEditor.modules[module].exp.length; i++){
 2186+ for ( var i = 0; i < $.wikiEditor.modules[module].exp.length; i++ ) {
21882187 var regex = $.wikiEditor.modules[module].exp[i].regex;
21892188 var label = $.wikiEditor.modules[module].exp[i].label;
21902189 var markAfter = false;
2191 - if(typeof($.wikiEditor.modules[module].exp[i].markAfter) != 'undefined'){
 2190+ if ( typeof $.wikiEditor.modules[module].exp[i].markAfter != 'undefined' ) {
21922191 markAfter = true;
21932192 }
2194 - match = text.match(regex);
 2193+ match = text.match( regex );
21952194 var oldOffset = 0;
2196 - while(match != null){
 2195+ while ( match != null ) {
21972196 var markOffset = 0;
2198 - if(markAfter){
 2197+ if ( markAfter ) {
21992198 markOffset += match[0].length;
22002199 }
2201 - this.tokenArray.push(new token(match.index + oldOffset + markOffset, label));
2202 - oldOffset += (match.index + match[0].length);
2203 - newSubstring = text.substring(oldOffset);
2204 - match = newSubstring.match(regex);
 2200+ this.tokenArray.push( new Token(
 2201+ match.index + oldOffset + markOffset, label ) );
 2202+ oldOffset += match.index + match[0].length;
 2203+ newSubstring = text.substring( oldOffset );
 2204+ match = newSubstring.match( regex );
22052205 }
2206 - }
 2206+ }
22072207 }
22082208 }
22092209
@@ -2210,34 +2210,31 @@
22112211 },
22122212 markers: [],
22132213 mark: function( context, division, tokens ) {
2214 - /*
2215 - * We need to markup some text based on some tokens
2216 - */
 2214+ // We need to markup some text based on some tokens
22172215 var rawText = context.fn.getContents();
22182216
2219 -
22202217 //get all markers
22212218 for ( module in $.wikiEditor.modules ) {
2222 - if ( 'evt' in $.wikiEditor.modules[module] && 'mark' in $.wikiEditor.modules[module].evt) {
 2219+ if ( 'evt' in $.wikiEditor.modules[module] && 'mark' in $.wikiEditor.modules[module].evt ) {
22232220 $.wikiEditor.modules[module].evt.mark();
22242221 }
22252222 }
22262223 markedText = "";
22272224 var previousIndex = 0;
2228 - for(var currentIndex in this.markers){
2229 - markedText+= rawText.substring(previousIndex, currentIndex);
 2225+ for ( var i = 0; i < this.markers.length; i++ ) {
 2226+ markedText += rawText.substring( previousIndex, currentIndex );
22302227
2231 - for(var i = 0 ; i < this.markers[currentIndex].length; i++){
2232 - markedText += this.markers[currentIndex][i];
 2228+ for ( var j = 0 ; i < this.markers[i].length; j++ ) {
 2229+ markedText += this.markers[i][j];
22332230 }
22342231
22352232 previousIndex = currentIndex;
22362233 }
2237 - if(markedText != ""){
2238 - markedText.replace(/\n/g, '<br\>');
2239 - context.fn.setContents({contents:markedText});
 2234+ if ( markedText != "" ) {
 2235+ markedText.replace( /\n/g, '<br>' );
 2236+ context.fn.setContents( { contents:markedText } );
22402237 }
2241 - }//endmark
 2238+ }
22422239 }
22432240
22442241 }; })( jQuery );/* Preview module for wikiEditor */
@@ -2497,7 +2494,328 @@
24982495 }
24992496 }
25002497
2501 -}; } )( jQuery );/* TOC Module for wikiEditor */
 2498+}; } )( jQuery );/* template forms module for wikiEditor */
 2499+( function( $ ) { $.wikiEditor.modules.templateEditor = {
 2500+
 2501+/**
 2502+ * API accessible functions
 2503+ */
 2504+api: {
 2505+ //
 2506+},
 2507+
 2508+evt: {
 2509+ mark: function() {
 2510+ function findOutermostTemplates( tokenStack ) {
 2511+ var templateBeginFound = false;
 2512+ for ( ;i< tokenStack.length; i++ ) {
 2513+ if ( tokenStack[i].label == "TEMPLATE_BEGIN" ) {
 2514+ templateBeginFound = true;
 2515+ break;
 2516+ }
 2517+ }
 2518+ var j = i;
 2519+ i++;
 2520+ if ( !templateBeginFound ) {
 2521+ return false;
 2522+ } else {
 2523+ // This is only designed to find the outermost template boundaries, the model handles nested template
 2524+ // and template-like objects better
 2525+ var nestedBegins = 1;
 2526+ while ( nestedBegins > 0 && j < tokenStack.length ) {
 2527+ j++;
 2528+ if ( tokenStack[j].label == "TEMPLATE_END" ) {
 2529+ nestedBegins--;
 2530+ }
 2531+ if ( tokenStack[j].label == "TEMPLATE_BEGIN" ) {
 2532+ nestedBegins++;
 2533+ }
 2534+ }
 2535+ if ( nestedBegins == 0 ) {
 2536+ // outer template begins at tokenStack[i].offset
 2537+ // and ends at tokenStack[j].offset + 2
 2538+ var leftMarker = i -1;
 2539+ var rightMarker = j;
 2540+ i = j;
 2541+ return [ leftMarker, rightMarker ];
 2542+ } else {
 2543+ return false;
 2544+ }
 2545+ }
 2546+ }; //find outermost templates
 2547+
 2548+ var markers = $.wikiEditor.modules.highlight.fn.markers;
 2549+ var tokenStack = $.wikiEditor.modules.highlight.fn.tokenArray;
 2550+ var i = 0;
 2551+ var templateBoundaries;
 2552+ var templateBeginFound = false;
 2553+
 2554+ while ( templateBoundaries = findOutermostTemplates( tokenStack ) ) {
 2555+ if ( typeof markers[tokenStack[templateBoundaries[0]].offset] == 'undefined' ) {
 2556+ markers[tokenStack[templateBoundaries[0]].offset] = [];
 2557+ }
 2558+ if ( typeof markers[tokenStack[templateBoundaries[1]].offset] == 'undefined' ) {
 2559+ markers[tokenStack[templateBoundaries[1]].offset] = [];
 2560+ }
 2561+
 2562+ markers[tokenStack[templateBoundaries[0]].offset].push( "<div class='wiki-template'>" );
 2563+ markers[tokenStack[templateBoundaries[1]].offset].push( "</div>" );
 2564+ }
 2565+ }
 2566+},
 2567+
 2568+exp: [
 2569+ { regex: /{{/, label: "TEMPLATE_BEGIN" },
 2570+ { regex: /}}/, label: "TEMPLATE_END", markAfter: true }
 2571+],
 2572+
 2573+/**
 2574+ * Internally used functions
 2575+ */
 2576+fn: {
 2577+ /**
 2578+ * Creates template form module within wikieditor
 2579+ * @param context Context object of editor to create module in
 2580+ * @param config Configuration object to create module from
 2581+ */
 2582+ create: function( context, config ) {
 2583+
 2584+ // check if text is selected
 2585+ },
 2586+
 2587+ //template Model
 2588+ model: function( wikitext ) {
 2589+ // Param object
 2590+ function Param( name, value, number, nameIndex, equalsIndex, valueIndex ) {
 2591+ this.name = name;
 2592+ this.value = value;
 2593+ this.number = number;
 2594+ this.nameIndex = nameIndex;
 2595+ this.equalsIndex = equalsIndex;
 2596+ this.valueIndex = valueIndex;
 2597+ }
 2598+
 2599+ // Range object
 2600+ function Range( begin, end ) {
 2601+ this.begin = begin;
 2602+ this.end = end;
 2603+ }
 2604+
 2605+ var ranges = [];
 2606+ var sanatizedStr = "";
 2607+ var params = [];
 2608+ var paramsByName = [];
 2609+ var templateNameIndex = 0;
 2610+
 2611+ function markOffTemplates() {
 2612+ sanatizedStr = wikitext.replace( /{{/, " " ); //get rid of first {{ with whitespace
 2613+ endBraces = sanatizedStr.match( /}}\s*$/ ); //replace end
 2614+ sanatizedStr = sanatizedStr.substring( 0, endBraces.index ) + " " +
 2615+ sanatizedStr.substring( endBraces.index + 2 );
 2616+
 2617+ while ( sanatizedStr.indexOf( '{{' ) != -1 ) {
 2618+ startIndex = sanatizedStr.indexOf('{{') + 1;
 2619+ openBraces = 2;
 2620+ endIndex = startIndex;
 2621+ while ( openBraces > 0 ) {
 2622+ endIndex++;
 2623+ switch ( sanatizedStr[endIndex] ) {
 2624+ case '}': openBraces--; break;
 2625+ case '{': openBraces++; break;
 2626+ }
 2627+ }
 2628+ sanatizedSegment = sanatizedStr.substring( startIndex,endIndex )
 2629+ .replace( /[{}|=]/g 'X' );
 2630+ sanatizedStr = sanatizedStr.substring( 0, startIndex ) +
 2631+ sanatizedSegment + sanatizedStr.substring( endIndex );
 2632+ };
 2633+
 2634+ // Whitespace* {{ whitespace* nonwhitespace:
 2635+ if ( wikitext.match( /\s*{{\s*\S*:/ ) ) {
 2636+ // we have a parser function!
 2637+ }
 2638+
 2639+ markOffTemplates();
 2640+
 2641+ var doneParsing = false;
 2642+ oldDivider = 0;
 2643+ divider = sanatizedStr.indexOf( '|', oldDivider );
 2644+ if ( divider == -1 ) {
 2645+ divider = sanatizedStr.length;
 2646+ doneParsing = true;
 2647+ }
 2648+ nameMatch = wikitext.substring( oldDivider, divider ).match( /[^{\s]+/ );
 2649+ if(nameMatch != undefined){
 2650+ ranges.push( new Range( oldDivider,nameMatch.index ) ); //whitespace and squiggles upto the name
 2651+ templateNameIndex = ranges.push( new Range( nameMatch.index,
 2652+ nameMatch.index + nameMatch[0].length ) );
 2653+ templateNameIndex--; //push returns 1 less than the array
 2654+ ranges[templateNameIndex].old = wikitext.substring( ranges[templateNameIndex].begin,
 2655+ ranges[templateNameIndex].end );
 2656+ }
 2657+ params.push( ranges[templateNameIndex].old ); //put something in params (0)
 2658+
 2659+ currentParamNumber = 0;
 2660+ var valueEndIndex;
 2661+ while ( !doneParsing ) {
 2662+ currentParamNumber++;
 2663+ oldDivider = divider;
 2664+ divider = sanatizedStr.indexOf( '|', oldDivider + 1 );
 2665+ if ( divider == -1 ) {
 2666+ divider = sanatizedStr.length;
 2667+ doneParsing = true;
 2668+ }
 2669+ currentField = sanatizedStr.substring( oldDivider+1, divider );
 2670+ if ( currentField.indexOf( '=' ) == -1 ) {
 2671+ // anonymous field, gets a number
 2672+ valueBegin = currentField.match( /\S+/ ); //first nonwhitespace character
 2673+ valueBeginIndex = valueBegin.index + oldDivider + 1;
 2674+ valueEnd = currentField.match( /[^\s]\s*$/ ); //last nonwhitespace character
 2675+ valueEndIndex = valueEnd.index + oldDivider + 2;
 2676+ ranges.push( new Range( ranges[ranges.length-1].end,
 2677+ valueBeginIndex ) ); //all the chars upto now
 2678+ nameIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) );
 2679+ nameIndex--;
 2680+ equalsIndex = ranges.push( new Range( valueBeginIndex, valueBeginIndex ) );
 2681+ equalsIndex--;
 2682+ valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) );
 2683+ valueIndex--;
 2684+ params.push( new Param( currentParamNumber,
 2685+ wikitext.substring( ranges[valueIndex].begin, ranges[valueIndex].end ),
 2686+ currentParamNumber, nameIndex, equalsIndex, valueIndex ) );
 2687+ paramsByName[currentParamNumber] = currentParamNumber;
 2688+ } else {
 2689+ // there's an equals, could be comment or a value pair
 2690+ currentName = currentField.substring( 0, currentField.indexOf( '=' ) );
 2691+ // (still offset by oldDivider)
 2692+ nameBegin = currentName.match( /\S+/ ); //first nonwhitespace character
 2693+ if ( nameBegin == null ) {
 2694+ divider++;
 2695+ currentParamNumber--;
 2696+ continue;
 2697+ } // this is a comment inside a template call/parser abuse. let's not encourage it
 2698+ nameBeginIndex = nameBegin.index + oldDivider + 1;
 2699+ nameEnd = currentName.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character
 2700+ nameEndIndex = nameEnd.index + oldDivider + 2;
 2701+
 2702+ ranges.push( new Range( ranges[ranges.length-1].end,
 2703+ nameBeginIndex ) ); //all the chars upto now
 2704+ nameIndex = ranges.push( new Range( nameBeginIndex, nameEndIndex ) );
 2705+ nameIndex--;
 2706+ currentValue = currentField.substring( currentField.indexOf( '=' ) + 1);
 2707+ oldDivider += currentField.indexOf( '=' ) + 1;
 2708+ valueBegin = currentValue.match( /\S+/ ); //first nonwhitespace character
 2709+ valueBeginIndex = valueBegin.index + oldDivider + 1;
 2710+ valueEnd = currentValue.match( /[^\s]\s*$/ ); //last nonwhitespace and non } character
 2711+ valueEndIndex = valueEnd.index + oldDivider + 2;
 2712+ equalsIndex = ranges.push( new Range( ranges[ranges.length-1].end,
 2713+ valueBeginIndex) ); //all the chars upto now
 2714+ equalsIndex--;
 2715+ valueIndex = ranges.push( new Range( valueBeginIndex, valueEndIndex ) );
 2716+ valueIndex--;
 2717+ params.push( new Param( wikitext.substring( nameBeginIndex, nameEndIndex ),
 2718+ wikitext.substring( valueBeginIndex, valueEndIndex ),
 2719+ currentParamNumber, nameIndex, equalsIndex, valueIndex ) );
 2720+ paramsByName[wikitext.substring( nameBeginIndex, nameEndIndex )] = currentParamNumber;
 2721+ }
 2722+ }
 2723+ //the rest of the string
 2724+ ranges.push( new Range( valueEndIndex, wikitext.length ) );
 2725+
 2726+ //FUNCTIONS
 2727+ //set 'original' to true if you want the original value irrespective of whether the model's been changed
 2728+ function getSetValue( name, value, original ) {
 2729+ var valueRange;
 2730+ var rangeIndex;
 2731+ var retVal;
 2732+ if ( isNaN( name ) ) {
 2733+ // it's a string!
 2734+ if ( typeof paramsByName[name] == 'undefined' ) {
 2735+ //does not exist
 2736+ return "";
 2737+ }
 2738+ rangeIndex = paramsByName[name];
 2739+ } else {
 2740+ //it's a number!
 2741+ rangeIndex = parseInt( name );
 2742+ }
 2743+
 2744+ if ( typeof params[rangeIndex] == 'undefined' ) {
 2745+ //does not exist
 2746+ return "";
 2747+ }
 2748+ valueRange = ranges[params[rangeIndex].valueIndex];
 2749+
 2750+ if ( typeof valueRange.newVal == 'undefined' || original ) {
 2751+ //value unchanged, return original wikitext
 2752+ retVal = wikitext.substring( valueRange.begin, valueRange.end );
 2753+ } else {
 2754+ //new value exists, return new value
 2755+ retVal = valueRange.newVal;
 2756+ }
 2757+
 2758+ if ( value != null ) {
 2759+ ranges[params[rangeIndex].valueIndex].newVal = value;
 2760+ }
 2761+
 2762+ return retVal;
 2763+ };
 2764+
 2765+ //'public' functions
 2766+
 2767+ //get template name
 2768+ this.getName = function() {
 2769+ return ranges[templateNameIndex].newVal ||
 2770+ wikitext.substring( ranges[templateNameIndex].begin,
 2771+ ranges[templateNameIndex].end );
 2772+ };
 2773+
 2774+ //set template name (if we want to support this)
 2775+ this.setName = function( name ) {
 2776+ ranges[templateNameIndex].newVal = name;
 2777+ };
 2778+
 2779+ //set value for a given param name/number
 2780+ this.setValue = function( name, value ) {
 2781+ return getSetValue( name, value, false );
 2782+ };
 2783+
 2784+ //get value for a given param name/number
 2785+ this.getValue = function( name ) {
 2786+ return getSetValue( name, null, false );
 2787+ };
 2788+
 2789+ //get original value of a param
 2790+ this.getOriginalValue = function( name ) {
 2791+ return getSetValue( name, null, true );
 2792+ };
 2793+
 2794+ //get a list of all param names (numbers for the anonymous ones)
 2795+ this.getAllParams = function() {
 2796+ return paramsByName;
 2797+ };
 2798+
 2799+ //get original template text
 2800+ this.getOriginalText = function() {
 2801+ return wikitext;
 2802+ };
 2803+
 2804+ //get modified template text
 2805+ this.getText = function() {
 2806+ newText = "";
 2807+ for ( i = 0 ; i < ranges.length; i++ ) {
 2808+ newText += ranges[i].newVal || wikitext.substring(
 2809+ ranges[i].begin, ranges[i].end );
 2810+ }
 2811+ return newText;
 2812+ };
 2813+ }//template model
 2814+}
 2815+
 2816+}; } )( jQuery );
 2817+
 2818+
 2819+/* TOC Module for wikiEditor */
25022820 ( function( $ ) { $.wikiEditor.modules.toc = {
25032821
25042822 /**
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -124,14 +124,14 @@
125125 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)
126126 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'))-
127127 (wrapper.width()-oldWidth)/2);}
128 -$(this).css('white-space',oldWS);oldHidden.each(function(){$(this).attr('style',$(this).data('oldstyle'));});}},modules:{},quickDialog:function(body,settings){$('<div />').text(body).appendTo($('body')).dialog($.extend({bgiframe:true,modal:true},settings)).dialog('open');}};})(jQuery);(function($){$.wikiEditor.modules.highlight={api:{},evt:{change:function(context,event){if(event.data.scope=='do_not_trigger'){$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}}},fn:{create:function(context,config){},divide:function(context){},isolate:function(context){return[];},strip:function(context,division){return $('<div />').html(division.html().replace(/\<br[^\>]*\>/g,"\n")).text();},tokenArray:[],scan:function(context,division){token=function(offset,label){this.offset=offset;this.label=label;}
129 -this.tokenArray=new Array();var text=context.fn.getContents();for(module in $.wikiEditor.modules){if('exp'in $.wikiEditor.modules[module]){for(var i=0;i<$.wikiEditor.modules[module].exp.length;i++){var regex=$.wikiEditor.modules[module].exp[i].regex;var label=$.wikiEditor.modules[module].exp[i].label;var markAfter=false;if(typeof($.wikiEditor.modules[module].exp[i].markAfter)!='undefined'){markAfter=true;}
 128+$(this).css('white-space',oldWS);oldHidden.each(function(){$(this).attr('style',$(this).data('oldstyle'));});}},modules:{},quickDialog:function(body,settings){$('<div />').text(body).appendTo($('body')).dialog($.extend({bgiframe:true,modal:true},settings)).dialog('open');}};})(jQuery);(function($){$.wikiEditor.modules.highlight={api:{},evt:{change:function(context,event){if(event.data.scope=='do_not_trigger'){$.wikiEditor.modules.highlight.fn.scan(context,"");$.wikiEditor.modules.highlight.fn.mark(context,"","");}}},fn:{create:function(context,config){},divide:function(context){},isolate:function(context){return[];},strip:function(context,division){return $('<div />').html(division.html().replace(/\<br[^\>]*\>/g,"\n")).text();},tokenArray:[],scan:function(context,division){function Token(offset,label){this.offset=offset;this.label=label;}
 129+this.tokenArray=[];var text=context.fn.getContents();for(module in $.wikiEditor.modules){if('exp'in $.wikiEditor.modules[module]){for(var i=0;i<$.wikiEditor.modules[module].exp.length;i++){var regex=$.wikiEditor.modules[module].exp[i].regex;var label=$.wikiEditor.modules[module].exp[i].label;var markAfter=false;if(typeof $.wikiEditor.modules[module].exp[i].markAfter!='undefined'){markAfter=true;}
130130 match=text.match(regex);var oldOffset=0;while(match!=null){var markOffset=0;if(markAfter){markOffset+=match[0].length;}
131 -this.tokenArray.push(new token(match.index+oldOffset+markOffset,label));oldOffset+=(match.index+match[0].length);newSubstring=text.substring(oldOffset);match=newSubstring.match(regex);}}}}
 131+this.tokenArray.push(new Token(match.index+oldOffset+markOffset,label));oldOffset+=match.index+match[0].length;newSubstring=text.substring(oldOffset);match=newSubstring.match(regex);}}}}
132132 return this.tokenArray;},markers:[],mark:function(context,division,tokens){var rawText=context.fn.getContents();for(module in $.wikiEditor.modules){if('evt'in $.wikiEditor.modules[module]&&'mark'in $.wikiEditor.modules[module].evt){$.wikiEditor.modules[module].evt.mark();}}
133 -markedText="";var previousIndex=0;for(var currentIndex in this.markers){markedText+=rawText.substring(previousIndex,currentIndex);for(var i=0;i<this.markers[currentIndex].length;i++){markedText+=this.markers[currentIndex][i];}
 133+markedText="";var previousIndex=0;for(var i=0;i<this.markers.length;i++){markedText+=rawText.substring(previousIndex,currentIndex);for(var j=0;i<this.markers[i].length;j++){markedText+=this.markers[i][j];}
134134 previousIndex=currentIndex;}
135 -if(markedText!=""){markedText.replace(/\n/g,'<br\>');context.fn.setContents({contents:markedText});}}}};})(jQuery);(function($){$.wikiEditor.modules.preview={api:{},fn:{create:function(context,config){if('initialized'in context.modules.preview){return;}
 135+if(markedText!=""){markedText.replace(/\n/g,'<br>');context.fn.setContents({contents:markedText});}}}};})(jQuery);(function($){$.wikiEditor.modules.preview={api:{},fn:{create:function(context,config){if('initialized'in context.modules.preview){return;}
136136 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;}
137137 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;}
138138 context.modules.preview.previewText=wikitext;context.modules.preview.$preview.find('.wikiEditor-preview-loading').hide();context.modules.preview.$preview.find('.wikiEditor-preview-contents').html(data.parse.text['*']).find('a:not([href^=#])').click(function(){return false;});},'json');}});context.$changesTab=context.fn.addView({'name':'changes','titleMsg':'wikieditor-preview-changes-tab','init':function(context){var wikitext=context.fn.getContents();if(context.modules.preview.changesText==wikitext){return;}
@@ -161,7 +161,29 @@
162162 $('#wikiEditor-'+context.instance+'-dialog-minor').hide();else if($('#wpMinoredit').is(':checked'))
163163 $('#wikiEditor-'+context.instance+'-dialog-minor').attr('checked','checked');if($('#wpWatchthis').size()==0)
164164 $('#wikiEditor-'+context.instance+'-dialog-watch').hide();else if($('#wpWatchthis').is(':checked'))
165 -$('#wikiEditor-'+context.instance+'-dialog-watch').attr('checked','checked');$(this).find('form').submit(function(e){$(this).closest('.ui-dialog').find('button:first').click();e.preventDefault();});},dialog:{buttons:{'wikieditor-publish-dialog-publish':function(){var minorChecked=$('#wikiEditor-'+context.instance+'-dialog-minor').is(':checked')?'checked':'';var watchChecked=$('#wikiEditor-'+context.instance+'-dialog-watch').is(':checked')?'checked':'';$('#wpMinoredit').attr('checked',minorChecked);$('#wpWatchthis').attr('checked',watchChecked);$('#wpSummary').val($j('#wikiEditor-'+context.instance+'-dialog-summary').val());$('#editform').submit();},'wikieditor-publish-dialog-goback':function(){$(this).dialog('close');}},open:function(){$('#wikiEditor-'+context.instance+'-dialog-summary').focus();},width:500},resizeme:false}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-publish','action':function(){$('#'+dialogID).dialog('open');return false;}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-cancel','action':function(){}});}}};})(jQuery);(function($){$.wikiEditor.modules.toc={defaultWidth:'166px',minimumWidth:'70px',api:{},evt:{ready:function(context,event){$.wikiEditor.modules.toc.fn.build(context);context.$content.parent().delayedBind(250,'mouseup scrollToTop keyup change',function(){$(this).eachAsync({bulk:0,loop:function(){$.wikiEditor.modules.toc.fn.build(context);$.wikiEditor.modules.toc.fn.update(context);}});}).blur(function(event){var context=event.data.context;context.$textarea.delayedBindCancel(250,'mouseup scrollToTop keyup change');$.wikiEditor.modules.toc.fn.unhighlight(context);});},resize:function(context,event){context.modules.toc.$toc.height(context.$ui.find('.wikiEditor-ui-left').height()-
 165+$('#wikiEditor-'+context.instance+'-dialog-watch').attr('checked','checked');$(this).find('form').submit(function(e){$(this).closest('.ui-dialog').find('button:first').click();e.preventDefault();});},dialog:{buttons:{'wikieditor-publish-dialog-publish':function(){var minorChecked=$('#wikiEditor-'+context.instance+'-dialog-minor').is(':checked')?'checked':'';var watchChecked=$('#wikiEditor-'+context.instance+'-dialog-watch').is(':checked')?'checked':'';$('#wpMinoredit').attr('checked',minorChecked);$('#wpWatchthis').attr('checked',watchChecked);$('#wpSummary').val($j('#wikiEditor-'+context.instance+'-dialog-summary').val());$('#editform').submit();},'wikieditor-publish-dialog-goback':function(){$(this).dialog('close');}},open:function(){$('#wikiEditor-'+context.instance+'-dialog-summary').focus();},width:500},resizeme:false}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-publish','action':function(){$('#'+dialogID).dialog('open');return false;}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-cancel','action':function(){}});}}};})(jQuery);(function($){$.wikiEditor.modules.templateEditor={api:{},evt:{mark:function(){function findOutermostTemplates(tokenStack){var templateBeginFound=false;for(;i<tokenStack.length;i++){if(tokenStack[i].label=="TEMPLATE_BEGIN"){templateBeginFound=true;break;}}
 166+var j=i;i++;if(!templateBeginFound){return false;}else{var nestedBegins=1;while(nestedBegins>0&&j<tokenStack.length){j++;if(tokenStack[j].label=="TEMPLATE_END"){nestedBegins--;}
 167+if(tokenStack[j].label=="TEMPLATE_BEGIN"){nestedBegins++;}}
 168+if(nestedBegins==0){var leftMarker=i-1;var rightMarker=j;i=j;return[leftMarker,rightMarker];}else{return false;}}};var markers=$.wikiEditor.modules.highlight.fn.markers;var tokenStack=$.wikiEditor.modules.highlight.fn.tokenArray;var i=0;var templateBoundaries;var templateBeginFound=false;while(templateBoundaries=findOutermostTemplates(tokenStack)){if(typeof markers[tokenStack[templateBoundaries[0]].offset]=='undefined'){markers[tokenStack[templateBoundaries[0]].offset]=[];}
 169+if(typeof markers[tokenStack[templateBoundaries[1]].offset]=='undefined'){markers[tokenStack[templateBoundaries[1]].offset]=[];}
 170+markers[tokenStack[templateBoundaries[0]].offset].push("<div class='wiki-template'>");markers[tokenStack[templateBoundaries[1]].offset].push("</div>");}}},exp:[{regex:/{{/,label:"TEMPLATE_BEGIN"},{regex:/}}/,label:"TEMPLATE_END",markAfter:true}],fn:{create:function(context,config){},model:function(wikitext){function Param(name,value,number,nameIndex,equalsIndex,valueIndex){this.name=name;this.value=value;this.number=number;this.nameIndex=nameIndex;this.equalsIndex=equalsIndex;this.valueIndex=valueIndex;}
 171+function Range(begin,end){this.begin=begin;this.end=end;}
 172+var ranges=[];var sanatizedStr="";var params=[];var paramsByName=[];var templateNameIndex=0;function markOffTemplates(){sanatizedStr=wikitext.replace(/{{/," ");endBraces=sanatizedStr.match(/}}\s*$/);sanatizedStr=sanatizedStr.substring(0,endBraces.index)+" "+
 173+sanatizedStr.substring(endBraces.index+2);while(sanatizedStr.indexOf('{{')!=-1){startIndex=sanatizedStr.indexOf('{{')+1;openBraces=2;endIndex=startIndex;while(openBraces>0){endIndex++;switch(sanatizedStr[endIndex]){case'}':openBraces--;break;case'{':openBraces++;break;}}
 174+sanatizedSegment=sanatizedStr.substring(startIndex,endIndex).replace(/[{}|=]/g'X');sanatizedStr=sanatizedStr.substring(0,startIndex)+
 175+sanatizedSegment+sanatizedStr.substring(endIndex);};if(wikitext.match(/\s*{{\s*\S*:/)){}
 176+markOffTemplates();var doneParsing=false;oldDivider=0;divider=sanatizedStr.indexOf('|',oldDivider);if(divider==-1){divider=sanatizedStr.length;doneParsing=true;}
 177+nameMatch=wikitext.substring(oldDivider,divider).match(/[^{\s]+/);if(nameMatch!=undefined){ranges.push(new Range(oldDivider,nameMatch.index));templateNameIndex=ranges.push(new Range(nameMatch.index,nameMatch.index+nameMatch[0].length));templateNameIndex--;ranges[templateNameIndex].old=wikitext.substring(ranges[templateNameIndex].begin,ranges[templateNameIndex].end);}
 178+params.push(ranges[templateNameIndex].old);currentParamNumber=0;var valueEndIndex;while(!doneParsing){currentParamNumber++;oldDivider=divider;divider=sanatizedStr.indexOf('|',oldDivider+1);if(divider==-1){divider=sanatizedStr.length;doneParsing=true;}
 179+currentField=sanatizedStr.substring(oldDivider+1,divider);if(currentField.indexOf('=')==-1){valueBegin=currentField.match(/\S+/);valueBeginIndex=valueBegin.index+oldDivider+1;valueEnd=currentField.match(/[^\s]\s*$/);valueEndIndex=valueEnd.index+oldDivider+2;ranges.push(new Range(ranges[ranges.length-1].end,valueBeginIndex));nameIndex=ranges.push(new Range(valueBeginIndex,valueBeginIndex));nameIndex--;equalsIndex=ranges.push(new Range(valueBeginIndex,valueBeginIndex));equalsIndex--;valueIndex=ranges.push(new Range(valueBeginIndex,valueEndIndex));valueIndex--;params.push(new Param(currentParamNumber,wikitext.substring(ranges[valueIndex].begin,ranges[valueIndex].end),currentParamNumber,nameIndex,equalsIndex,valueIndex));paramsByName[currentParamNumber]=currentParamNumber;}else{currentName=currentField.substring(0,currentField.indexOf('='));nameBegin=currentName.match(/\S+/);if(nameBegin==null){divider++;currentParamNumber--;continue;}
 180+nameBeginIndex=nameBegin.index+oldDivider+1;nameEnd=currentName.match(/[^\s]\s*$/);nameEndIndex=nameEnd.index+oldDivider+2;ranges.push(new Range(ranges[ranges.length-1].end,nameBeginIndex));nameIndex=ranges.push(new Range(nameBeginIndex,nameEndIndex));nameIndex--;currentValue=currentField.substring(currentField.indexOf('=')+1);oldDivider+=currentField.indexOf('=')+1;valueBegin=currentValue.match(/\S+/);valueBeginIndex=valueBegin.index+oldDivider+1;valueEnd=currentValue.match(/[^\s]\s*$/);valueEndIndex=valueEnd.index+oldDivider+2;equalsIndex=ranges.push(new Range(ranges[ranges.length-1].end,valueBeginIndex));equalsIndex--;valueIndex=ranges.push(new Range(valueBeginIndex,valueEndIndex));valueIndex--;params.push(new Param(wikitext.substring(nameBeginIndex,nameEndIndex),wikitext.substring(valueBeginIndex,valueEndIndex),currentParamNumber,nameIndex,equalsIndex,valueIndex));paramsByName[wikitext.substring(nameBeginIndex,nameEndIndex)]=currentParamNumber;}}
 181+ranges.push(new Range(valueEndIndex,wikitext.length));function getSetValue(name,value,original){var valueRange;var rangeIndex;var retVal;if(isNaN(name)){if(typeof paramsByName[name]=='undefined'){return"";}
 182+rangeIndex=paramsByName[name];}else{rangeIndex=parseInt(name);}
 183+if(typeof params[rangeIndex]=='undefined'){return"";}
 184+valueRange=ranges[params[rangeIndex].valueIndex];if(typeof valueRange.newVal=='undefined'||original){retVal=wikitext.substring(valueRange.begin,valueRange.end);}else{retVal=valueRange.newVal;}
 185+if(value!=null){ranges[params[rangeIndex].valueIndex].newVal=value;}
 186+return retVal;};this.getName=function(){return ranges[templateNameIndex].newVal||wikitext.substring(ranges[templateNameIndex].begin,ranges[templateNameIndex].end);};this.setName=function(name){ranges[templateNameIndex].newVal=name;};this.setValue=function(name,value){return getSetValue(name,value,false);};this.getValue=function(name){return getSetValue(name,null,false);};this.getOriginalValue=function(name){return getSetValue(name,null,true);};this.getAllParams=function(){return paramsByName;};this.getOriginalText=function(){return wikitext;};this.getText=function(){newText="";for(i=0;i<ranges.length;i++){newText+=ranges[i].newVal||wikitext.substring(ranges[i].begin,ranges[i].end);}
 187+return newText;};}}};})(jQuery);(function($){$.wikiEditor.modules.toc={defaultWidth:'166px',minimumWidth:'70px',api:{},evt:{ready:function(context,event){$.wikiEditor.modules.toc.fn.build(context);context.$content.parent().delayedBind(250,'mouseup scrollToTop keyup change',function(){$(this).eachAsync({bulk:0,loop:function(){$.wikiEditor.modules.toc.fn.build(context);$.wikiEditor.modules.toc.fn.update(context);}});}).blur(function(event){var context=event.data.context;context.$textarea.delayedBindCancel(250,'mouseup scrollToTop keyup change');$.wikiEditor.modules.toc.fn.unhighlight(context);});},resize:function(context,event){context.modules.toc.$toc.height(context.$ui.find('.wikiEditor-ui-left').height()-
166188 context.$ui.find('.tab-toc').outerHeight());}},fn:{create:function(context,config){if('$toc'in context.modules.toc){return;}
167189 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++;}
168190 section=Math.max(0,section);}
Index: trunk/extensions/UsabilityInitiative/Makefile
@@ -25,6 +25,7 @@
2626 js/plugins/jquery.wikiEditor.highlight.js\
2727 js/plugins/jquery.wikiEditor.preview.js\
2828 js/plugins/jquery.wikiEditor.publish.js\
 29+ js/plugins/jquery.wikiEditor.templateEditor.js\
2930 js/plugins/jquery.wikiEditor.toc.js\
3031 js/plugins/jquery.wikiEditor.toolbar.js
3132

Status & tagging log