Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js |
— | — | @@ -89,6 +89,7 @@ |
90 | 90 | return; |
91 | 91 | } |
92 | 92 | // Build a model for this |
| 93 | + |
93 | 94 | var model = new $.wikiEditor.modules.templateEditor.fn.model( $( this ).text() ); |
94 | 95 | var $template = $( this ) |
95 | 96 | .wrap( '<div class="wikiEditor-template"></div>' ) |
— | — | @@ -96,8 +97,8 @@ |
97 | 98 | .html( |
98 | 99 | // Wrap the start and end of the wikitext in spans so we can bind events to them |
99 | 100 | $( this ).html() |
100 | | - .replace( /\{\{/, '<span class="wikiEditor-template-start">{{</span>' ) |
101 | | - .replace( /\}\}$/, '<span class="wikiEditor-template-end">}}</span>' ) ) //grab the *last* {{ |
| 101 | + .replace( /\{\{/, '<span class="wikiEditor-template-start">{{</span><span class="wikiEditor-template-inner-text">' ) |
| 102 | + .replace( /\}\}$/, '</span><span class="wikiEditor-template-end">}}</span>' ) ) //grab the *last* {{ |
102 | 103 | .parent() |
103 | 104 | .addClass( 'wikiEditor-template-collapsed' ) |
104 | 105 | .data( 'model', model ); |
— | — | @@ -107,7 +108,7 @@ |
108 | 109 | .mousedown( noEdit ) |
109 | 110 | .prependTo( $template ); |
110 | 111 | $template.find( '.wikiEditor-template-end, .wikiEditor-template-start' ).mousedown( toggleWikiText ); |
111 | | - $( '<ul />' ) |
| 112 | + var $options = $( '<ul />' ) |
112 | 113 | .addClass( 'wikiEditor-template-modes wikiEditor-noinclude' ) |
113 | 114 | .append( $( '<li />' ) |
114 | 115 | .addClass( 'wikiEditor-template-action-wikiText' ) |
— | — | @@ -115,6 +116,14 @@ |
116 | 117 | $.wikiEditor.imgPath + 'templateEditor/' + 'wiki-text.png' ) ) |
117 | 118 | .mousedown( toggleWikiText ) ) |
118 | 119 | .insertAfter( $template.find( '.wikiEditor-template-name' ) ); |
| 120 | + $options.append( |
| 121 | + $( '<li />' ) |
| 122 | + .addClass( 'wikiEditor-template-action-form' ) |
| 123 | + .append( $( '<span>F</span>' ) ) |
| 124 | + .mousedown( function(){createDialog($template); return false;} )); |
| 125 | + |
| 126 | + |
| 127 | + |
119 | 128 | // Expand |
120 | 129 | function expandTemplate( $displayDiv ) { |
121 | 130 | // Housekeeping |
— | — | @@ -150,6 +159,45 @@ |
151 | 160 | $displayDiv.removeClass( 'wikiEditor-template-expanded' ); |
152 | 161 | $displayDiv.text( model.getName() ); |
153 | 162 | }; |
| 163 | + |
| 164 | + |
| 165 | + function createDialog( $templateDiv ){ |
| 166 | + var templateModel = $templateDiv.data('model'); |
| 167 | + var $dialog = $("<div></div>"); |
| 168 | + var $title = $("<div>" + templateModel.getName() + "</div>").addClass('wikiEditor-template-dialog-title'); |
| 169 | + var $table = $("<table></table>") |
| 170 | + .addClass('wikiEditor-template-dialog-table') |
| 171 | + .appendTo($dialog); |
| 172 | + var allInitialParams = templateModel.getAllInitialParams(); |
| 173 | + for( var paramIndex in allInitialParams ){ |
| 174 | + var param = allInitialParams[paramIndex]; |
| 175 | + if(typeof param.name == 'undefined'){continue;} //param 0 is the name |
| 176 | + var $paramRow = $("<tr></tr>") |
| 177 | + .addClass('wikiEditor-template-dialog-row'); |
| 178 | + var $paramName = $("<td></td>") |
| 179 | + .addClass('wikiEditor-template-dialog-name') |
| 180 | + .text( param.name ); |
| 181 | + var $paramVal = $("<td></td>") |
| 182 | + .addClass('wikiEditor-template-dialog-value'); |
| 183 | + var $paramInput =$("<input></input>") |
| 184 | + .data('name', param.name) |
| 185 | + .val( templateModel.getValue(param.name) ); |
| 186 | + $paramVal.append($paramInput); |
| 187 | + $paramRow.append($paramName).append($paramVal); |
| 188 | + $table.append($paramRow); |
| 189 | + } |
| 190 | + //click handler for values |
| 191 | + $("<button></button>").click(function(){ |
| 192 | + $('.wikiEditor-template-dialog-value input').each( function(){ |
| 193 | + templateModel.setValue( $(this).data('name'), $(this).val() ); |
| 194 | + }); |
| 195 | + $dialog.dialog('close'); |
| 196 | + |
| 197 | + }).text("OK").appendTo($dialog); |
| 198 | + $dialog.dialog(); //opens dialog |
| 199 | + }; |
| 200 | + |
| 201 | + |
154 | 202 | function toggleWikiText( ) { |
155 | 203 | var $template = $( this ).closest( '.wikiEditor-template' ); |
156 | 204 | $template |
— | — | @@ -159,11 +207,20 @@ |
160 | 208 | .toggleClass( 'wikiEditor-nodisplay' ); |
161 | 209 | |
162 | 210 | //if we just collapsed this |
163 | | - if( $template.hasClass('wikiEditor-template-collapsed') ){ |
| 211 | + if( $template.hasClass('wikiEditor-template-collapsed') ) { |
164 | 212 | var model = new $.wikiEditor.modules.templateEditor.fn.model( $template.children( '.wikiEditor-template-text' ).text() ); |
165 | 213 | $template.data( 'model' , model ); |
166 | 214 | $template.children( '.wikiEditor-template-name' ).text( model.getName() ); |
167 | 215 | } |
| 216 | + else{ //else we just expanded this |
| 217 | + $template.children( '.wikiEditor-template-text' ).children('.wikiEditor-template-inner-text').text( |
| 218 | + $template.data('model') |
| 219 | + .getText() |
| 220 | + .replace(/\{\{/, '') |
| 221 | + .replace(/\}\}$/, '') |
| 222 | + ); |
| 223 | + |
| 224 | + } |
168 | 225 | return false; |
169 | 226 | } |
170 | 227 | function noEdit() { |
— | — | @@ -377,7 +434,7 @@ |
378 | 435 | startIndex = sanatizedStr.indexOf( '{{' ) + 1; |
379 | 436 | openBraces = 2; |
380 | 437 | endIndex = startIndex; |
381 | | - while ( openBraces > 0 ) { |
| 438 | + while ( (openBraces > 0) && (endIndex < sanatizedStr.length) ) { |
382 | 439 | var brace = sanatizedStr[++endIndex]; |
383 | 440 | openBraces += brace == '}' ? -1 : brace == '{' ? 1 : 0; |
384 | 441 | } |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html |
— | — | @@ -12,6 +12,7 @@ |
13 | 13 | font-family: monospace; |
14 | 14 | white-space: pre-wrap; |
15 | 15 | font-size: 9.5pt; |
| 16 | + line-height:16px; |
16 | 17 | } |
17 | 18 | /* Wikitext that's folded away and shouldn't be displayed */ |
18 | 19 | .wikiEditor-nodisplay { |