Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -213,9 +213,17 @@ |
214 | 214 | } |
215 | 215 | } |
216 | 216 | } |
217 | | - /* Event Handlers */ |
| 217 | + |
| 218 | + /* |
| 219 | + * Event Handlers |
| 220 | + * |
| 221 | + * These act as filters returning false if the event should be ignored or returning true if it should be passed |
| 222 | + * on to all modules. This is also where we can attach some extra information to the events. |
| 223 | + */ |
| 224 | + |
218 | 225 | context.evt = { |
219 | 226 | 'change': function( event ) { |
| 227 | + // Event filtering |
220 | 228 | switch ( event.type ) { |
221 | 229 | case 'keypress': |
222 | 230 | if ( /* TODO: test if something interesting was deleted */ true ) { |
— | — | @@ -228,26 +236,35 @@ |
229 | 237 | if ( /* TODO: test if text was dragged and dropped */ true ) { |
230 | 238 | event.data.scope = 'division'; |
231 | 239 | } else { |
232 | | - event.data.scope = 'none'; |
| 240 | + return false; |
233 | 241 | } |
234 | 242 | break; |
235 | 243 | default: |
236 | 244 | event.data.scope = 'division'; |
237 | 245 | break; |
238 | 246 | } |
239 | | - if ( event.data.scope !== 'none' ) { |
240 | | - for ( module in $.wikiEditor.modules ) { |
241 | | - if ( 'evt' in $.wikiEditor.modules[module] && 'change' in $.wikiEditor.modules[module].evt ) { |
242 | | - $.wikiEditor.modules[module].evt.change( context, event ); |
243 | | - } |
244 | | - } |
245 | | - } |
| 247 | + return true; |
246 | 248 | } |
247 | 249 | }; |
248 | 250 | |
249 | 251 | /* Internal Functions */ |
250 | 252 | |
251 | 253 | context.fn = { |
| 254 | + 'trigger': function( name, event ) { |
| 255 | + // Make a place for extra information to live |
| 256 | + event.data = {}; |
| 257 | + // Allow filtering to occur |
| 258 | + if ( name in context.evt ) { |
| 259 | + if ( !context.evt[name]( event ) ) { |
| 260 | + return false; |
| 261 | + } |
| 262 | + } |
| 263 | + for ( module in $.wikiEditor.modules ) { |
| 264 | + if ( 'evt' in $.wikiEditor.modules[module] && name in $.wikiEditor.modules[module].evt ) { |
| 265 | + $.wikiEditor.modules[module].evt[name]( context, event ); |
| 266 | + } |
| 267 | + } |
| 268 | + }, |
252 | 269 | 'addButton': function( options ) { |
253 | 270 | // Ensure that buttons and tabs are visible |
254 | 271 | context.$controls.show(); |
— | — | @@ -309,7 +326,7 @@ |
310 | 327 | context.$iframe[0].contentWindow.document.open(); |
311 | 328 | context.$iframe[0].contentWindow.document.write( |
312 | 329 | // FIXME: Break this line |
313 | | - '<html><head><title>wikiEditor</title><script>var context = window.parent.jQuery.wikiEditor.instances[' + context.instance + '].data( "wikiEditor-context" ); window.parent.jQuery( document ).bind( "keydown keypress keyup mousedown mouseup cut paste", { "context": context }, context.evt.change );</script></head><body style="margin:0;padding:0;width:100%;height:100%;white-space:pre-wrap;font-family:monospace">' + contentHTML + '</body></html>' |
| 330 | + '<html><head><title>wikiEditor</title><script>var context = window.parent.jQuery.wikiEditor.instances[' + context.instance + '].data( "wikiEditor-context" ); window.parent.jQuery( document ).bind( "keydown keypress keyup mousedown mouseup cut paste", function( event ) { context.fn.trigger( "change", event ) } );</script></head><body style="margin:0;padding:0;width:100%;height:100%;white-space:pre-wrap;font-family:monospace">' + contentHTML + '</body></html>' |
314 | 331 | ); |
315 | 332 | context.$iframe[0].contentWindow.document.close(); |
316 | 333 | // Turn the document's design mode on |