r59813 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59812‎ | r59813 | r59814 >
Date:00:58, 8 December 2009
Author:tparscal
Status:ok
Tags:
Comment:
Switched the event handling scheme around a bit, now context.fn.trigger will pass an event to a given handler on any existing module. core event handlers are called, if present, as filters (deciding to use the event or not) and enhancers (doing some extra processing on the event to make it more useful).
Modified paths:
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -213,9 +213,17 @@
214214 }
215215 }
216216 }
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+
218225 context.evt = {
219226 'change': function( event ) {
 227+ // Event filtering
220228 switch ( event.type ) {
221229 case 'keypress':
222230 if ( /* TODO: test if something interesting was deleted */ true ) {
@@ -228,26 +236,35 @@
229237 if ( /* TODO: test if text was dragged and dropped */ true ) {
230238 event.data.scope = 'division';
231239 } else {
232 - event.data.scope = 'none';
 240+ return false;
233241 }
234242 break;
235243 default:
236244 event.data.scope = 'division';
237245 break;
238246 }
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;
246248 }
247249 };
248250
249251 /* Internal Functions */
250252
251253 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+ },
252269 'addButton': function( options ) {
253270 // Ensure that buttons and tabs are visible
254271 context.$controls.show();
@@ -309,7 +326,7 @@
310327 context.$iframe[0].contentWindow.document.open();
311328 context.$iframe[0].contentWindow.document.write(
312329 // 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>'
314331 );
315332 context.$iframe[0].contentWindow.document.close();
316333 // Turn the document's design mode on

Follow-up revisions

RevisionCommit summaryAuthorDate
r59825UsabilityInitiative: Recombine JS and bump style versions for r59813, r59814,...catrope13:54, 8 December 2009

Status & tagging log