Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.templateEditor.js |
— | — | @@ -94,43 +94,53 @@ |
95 | 95 | return; |
96 | 96 | } |
97 | 97 | // Build a model for this |
| 98 | + var model = new $.wikiEditor.modules.templateEditor.fn.model( $( this ).text() ); |
98 | 99 | |
99 | | - var model = new $.wikiEditor.modules.templateEditor.fn.model( $( this ).text() ); |
| 100 | + //check if model is collapsible |
100 | 101 | if ( !model.isCollapsible() ) { |
101 | 102 | return; |
102 | 103 | } |
| 104 | + |
103 | 105 | var $template = $( this ) |
104 | 106 | .wrap( '<div class="wikiEditor-template"></div>' ) |
105 | 107 | .addClass( 'wikiEditor-template-text wikiEditor-nodisplay' ) |
106 | | - .html( |
107 | | - // Wrap the start and end of the wikitext in spans so we can bind events to them |
108 | | - $( this ).html() |
109 | | - .replace( /\{\{/, '<span class="wikiEditor-template-start">{{</span><span class="wikiEditor-template-inner-text">' ) |
110 | | - .replace( /\}\}$/, '</span><span class="wikiEditor-template-end">}}</span>' ) ) //grab the *last* {{ |
111 | | - .css( 'visibility', 'hidden' ) |
112 | 108 | .parent() |
113 | 109 | .addClass( 'wikiEditor-template-collapsed' ) |
114 | 110 | .data( 'model', model ); |
| 111 | + |
115 | 112 | $( '<span />' ) |
116 | | - .addClass( 'wikiEditor-template-name wikiEditor-noinclude' ) |
117 | | - .text( model.getName() ) |
118 | | - .mousedown( noEdit ) |
119 | | - .prependTo( $template ); |
120 | | - $template.find( '.wikiEditor-template-end, .wikiEditor-template-start' ).mousedown( toggleWikiText ); |
| 113 | + .addClass( 'wikiEditor-template-name wikiEditor-noinclude' ) |
| 114 | + .text( model.getName() ) |
| 115 | + .mousedown( function(){createDialog( $template );} ) //have to pass template so model stays in sync |
| 116 | + .prependTo( $template ); |
| 117 | + |
| 118 | + |
121 | 119 | var $options = $( '<ul />' ) |
122 | | - .addClass( 'wikiEditor-template-modes wikiEditor-noinclude' ) |
123 | | - .append( $( '<li />' ) |
124 | | - .addClass( 'wikiEditor-template-action-wikiText' ) |
125 | | - .append( $( '<img />' ).attr( 'src', |
126 | | - $.wikiEditor.imgPath + 'templateEditor/' + 'wiki-text.png' ) ) |
127 | | - .mousedown( toggleWikiText ) ) |
128 | | - .insertAfter( $template.find( '.wikiEditor-template-name' ) ); |
129 | | - $options.append( |
130 | | - $( '<li />' ) |
131 | | - .addClass( 'wikiEditor-template-action-form' ) |
132 | | - .append( $( '<span>F</span>' ) ) |
133 | | - .mousedown( function(){createDialog($template); return false;} )); |
| 120 | + .addClass( 'wikiEditor-template-modes wikiEditor-noinclude' ) |
| 121 | + .append( $( '<li />' ) |
| 122 | + .addClass( 'wikiEditor-template-action-wikiText' ) |
| 123 | + .append( $( '<img />' ).attr( 'src', |
| 124 | + $.wikiEditor.imgPath + 'templateEditor/' + 'wiki-text.png' ) ) |
| 125 | + .mousedown( toggleWikiTextEditor ) ) |
| 126 | + .insertAfter( $template.find( '.wikiEditor-template-name' ) ); |
134 | 127 | |
| 128 | + function toggleWikiTextEditor(){ |
| 129 | + var $template = $( this ).closest( '.wikiEditor-template' ); |
| 130 | + $template |
| 131 | + .toggleClass( 'wikiEditor-template-expanded' ) |
| 132 | + .toggleClass( 'wikiEditor-template-collapsed' ); |
| 133 | + var $wikitext = $template.children('.wikiEditor-template-text'); |
| 134 | + $wikitext.toggleClass('wikiEditor-nodisplay'); |
| 135 | + |
| 136 | + //if we just collapsed this |
| 137 | + if( $template.hasClass('wikiEditor-template-collapsed') ) { |
| 138 | + var model = new $.wikiEditor.modules.templateEditor.fn.model( $template.children( '.wikiEditor-template-text' ).text() ); |
| 139 | + $template.data( 'model' , model ); |
| 140 | + $template.children( '.wikiEditor-template-name' ).text( model.getName() ); |
| 141 | + } |
| 142 | + |
| 143 | + return false; |
| 144 | + }; |
135 | 145 | |
136 | 146 | // Expand |
137 | 147 | function expandTemplate( $displayDiv ) { |
— | — | @@ -171,6 +181,7 @@ |
172 | 182 | |
173 | 183 | function createDialog( $templateDiv ){ |
174 | 184 | var templateModel = $templateDiv.data('model'); |
| 185 | + console.log(templateModel.getText()); |
175 | 186 | var $dialog = $("<div></div>"); |
176 | 187 | var $title = $("<div>" + templateModel.getName() + "</div>").addClass('wikiEditor-template-dialog-title'); |
177 | 188 | var $table = $("<table></table>") |
— | — | @@ -203,9 +214,12 @@ |
204 | 215 | |
205 | 216 | }).text("OK").appendTo($dialog); |
206 | 217 | $dialog.dialog(); //opens dialog |
| 218 | + return false; |
207 | 219 | }; |
208 | 220 | |
209 | 221 | |
| 222 | + |
| 223 | + |
210 | 224 | function toggleWikiText( ) { |
211 | 225 | var $template = $( this ).closest( '.wikiEditor-template' ); |
212 | 226 | $template |
— | — | @@ -231,9 +245,11 @@ |
232 | 246 | } |
233 | 247 | return false; |
234 | 248 | } |
235 | | - function noEdit() { |
236 | | - return false; |
237 | | - } |
| 249 | + |
| 250 | + function noEdit() { |
| 251 | + return false; |
| 252 | + } |
| 253 | + |
238 | 254 | }); |
239 | 255 | |
240 | 256 | }, |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | padding-left: 4em; |
41 | 41 | } |
42 | 42 | /* A collapsed template */ |
43 | | - .wikiEditor-template-collapsed { |
| 43 | + .wikiEditor-template-name { |
44 | 44 | background-color:#DDEEFF; |
45 | 45 | border:1px outset #DDEEFF; |
46 | 46 | color:#333333; |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | display: inline; |
75 | 75 | } |
76 | 76 | .wikiEditor-template-text{ |
77 | | - display: inline; |
| 77 | + border: solid 1px blue; |
78 | 78 | } |
79 | 79 | .wikiEditor-template-end, .wikiEditor-template-start{ |
80 | 80 | color: blue; |