r74325 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74324‎ | r74325 | r74326 >
Date:20:54, 5 October 2010
Author:tparscal
Status:ok
Tags:
Comment:
* Fixed mistake made in r74271 where some functions were moved from core jquery.wikiEditor into jquery.wikiEditor.iframe, causing errors for textarea mode. These changes properly split the functions, allowing the iframe to override the textarea functions, and using $.client to only execute them on IE. (tested in IE7)
* Also fixed IE bug, where "delete window.myThing;" fails but "delete myThing;" succeeds.
Modified paths:
  • /trunk/extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js (modified) (history)
  • /trunk/extensions/WikiEditor/modules/jquery.wikiEditor.iframe.js (modified) (history)
  • /trunk/extensions/WikiEditor/modules/jquery.wikiEditor.js (modified) (history)
  • /trunk/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js (modified) (history)
  • /trunk/phase3/includes/ResourceLoaderModule.php (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)
  • /trunk/phase3/resources/startup.js (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ResourceLoaderModule.php
@@ -1123,11 +1123,11 @@
11241124 // Startup function
11251125 $configuration = FormatJson::encode( $this->getConfig( $context ) );
11261126 $registrations = self::getModuleRegistrations( $context );
1127 - $out .= "window.startUp = function() {\n\t$registrations\n\tmediaWiki.config.set( $configuration );\n};";
 1127+ $out .= "var startUp = function() {\n\t$registrations\n\tmediaWiki.config.set( $configuration );\n};";
11281128
11291129 // Conditional script injection
11301130 $scriptTag = Xml::escapeJsString( Html::linkedScript( $wgLoadScript . '?' . wfArrayToCGI( $query ) ) );
1131 - $out .= "if ( isCompatible() ) {\n\tdocument.write( '$scriptTag' );\n}\ndelete window['isCompatible'];";
 1131+ $out .= "if ( isCompatible() ) {\n\tdocument.write( '$scriptTag' );\n}\ndelete isCompatible;";
11321132 }
11331133
11341134 return $out;
Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -758,10 +758,9 @@
759759
760760 } )( jQuery );
761761
762 -
763762 /* Auto-register from pre-loaded startup scripts */
764763
765 -if ( typeof window['startUp'] === 'function' ) {
766 - window['startUp']();
767 - delete window['startUp'];
 764+if ( typeof startUp === 'function' ) {
 765+ startUp();
 766+ delete startUp;
768767 }
\ No newline at end of file
Index: trunk/phase3/resources/startup.js
@@ -14,7 +14,7 @@
1515 * * Opera 9+
1616 * * Chrome 1+
1717 */
18 -window.isCompatible = function() {
 18+var isCompatible = function() {
1919 // IE < 6
2020 if ( navigator.appVersion.indexOf( 'MSIE' ) !== -1 && parseFloat( navigator.appVersion.split( 'MSIE' )[1] ) < 6 ) {
2121 return false;
Index: trunk/extensions/WikiEditor/modules/jquery.wikiEditor.js
@@ -488,32 +488,49 @@
489489 .appendTo( context.$ui );
490490 },
491491 /**
492 - * Save scrollTop and cursor position for IE.
 492+ * Save scrollTop and cursor position for IE
493493 */
494 - 'saveStuffForIE': function() {
495 - // Only need this for IE in textarea mode
496 - if ( !$.browser.msie || context.$iframe )
497 - return;
498 - var IHateIE = {
499 - 'scrollTop' : context.$textarea.scrollTop(),
500 - 'pos': context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } )
501 - };
502 - context.$textarea.data( 'IHateIE', IHateIE );
 494+ 'saveCursorAndScrollTop': function() {
 495+ if ( $.client.name === 'msie' ) {
 496+ var IHateIE = {
 497+ 'scrollTop' : context.$textarea.scrollTop(),
 498+ 'pos': context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } )
 499+ };
 500+ context.$textarea.data( 'IHateIE', IHateIE );
 501+ }
503502 },
504503 /**
505 - * Restore scrollTo and cursor position for IE.
 504+ * Restore scrollTo and cursor position for IE
506505 */
507 - 'restoreStuffForIE': function() {
508 - // Only need this for IE in textarea mode
509 - if ( !$.browser.msie || context.$iframe )
510 - return;
511 - var IHateIE = context.$textarea.data( 'IHateIE' );
512 - if ( !IHateIE )
513 - return;
514 - context.$textarea.scrollTop( IHateIE.scrollTop );
515 - context.$textarea.textSelection( 'setSelection', { start: IHateIE.pos[0], end: IHateIE.pos[1] } );
516 - context.$textarea.data( 'IHateIE', null );
517 - }
 506+ 'restoreCursorAndScrollTop': function() {
 507+ if ( $.client.name === 'msie' ) {
 508+ var IHateIE = context.$textarea.data( 'IHateIE' );
 509+ if ( IHateIE ) {
 510+ context.$textarea.scrollTop( IHateIE.scrollTop );
 511+ context.$textarea.textSelection( 'setSelection', { start: IHateIE.pos[0], end: IHateIE.pos[1] } );
 512+ context.$textarea.data( 'IHateIE', null );
 513+ }
 514+ }
 515+ },
 516+ /**
 517+ * Save text selection for IE
 518+ */
 519+ 'saveSelection': function() {
 520+ if ( $.client.name === 'msie' ) {
 521+ context.$textarea.focus();
 522+ context.savedSelection = document.selection.createRange();
 523+ }
 524+ },
 525+ /**
 526+ * Restore text selection for IE
 527+ */
 528+ 'restoreSelection': function() {
 529+ if ( $.client.name === 'msie' && context.savedSelection !== null ) {
 530+ context.$textarea.focus();
 531+ context.savedSelection.select();
 532+ context.savedSelection = null;
 533+ }
 534+ },
518535 };
519536
520537 /*
Index: trunk/extensions/WikiEditor/modules/jquery.wikiEditor.toolbar.js
@@ -111,7 +111,7 @@
112112 .append(
113113 $( $.wikiEditor.modules.toolbar.fn.buildCharacter( data[type][character], actions ) )
114114 .mousedown( function( e ) {
115 - context.fn.saveStuffForIE();
 115+ context.fn.saveCursorAndScrollTop();
116116 // No dragging!
117117 e.preventDefault();
118118 return false;
@@ -350,7 +350,7 @@
351351 .data( 'action', tool.action )
352352 .data( 'context', context )
353353 .mousedown( function( e ) {
354 - context.fn.saveStuffForIE();
 354+ context.fn.saveCursorAndScrollTop();
355355 // No dragging!
356356 e.preventDefault();
357357 return false;
@@ -376,7 +376,7 @@
377377 .data( 'action', tool.list[option].action )
378378 .data( 'context', context )
379379 .mousedown( function( e ) {
380 - context.fn.saveStuffForIE();
 380+ context.fn.saveCursorAndScrollTop();
381381 // No dragging!
382382 e.preventDefault();
383383 return false;
@@ -493,7 +493,7 @@
494494 .html( html )
495495 .children()
496496 .mousedown( function( e ) {
497 - context.fn.saveStuffForIE();
 497+ context.fn.saveCursorAndScrollTop();
498498 // No dragging!
499499 e.preventDefault();
500500 return false;
Index: trunk/extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js
@@ -502,7 +502,7 @@
503503 'wikieditor-toolbar-tool-link-cancel': function() {
504504 // Clear any saved selection state
505505 var context = $(this).data( 'context' );
506 - context.fn.restoreStuffForIE();
 506+ context.fn.restoreCursorAndScrollTop();
507507 $(this).dialog( 'close' );
508508 }
509509 },
@@ -515,8 +515,8 @@
516516 // Pre-fill the text fields based on the current selection
517517 var context = $(this).data( 'context' );
518518 // Restore and immediately save selection state, needed for inserting stuff later
519 - context.fn.restoreStuffForIE();
520 - context.fn.saveStuffForIE();
 519+ context.fn.restoreCursorAndScrollTop();
 520+ context.fn.saveCursorAndScrollTop();
521521 var selection = context.$textarea.textSelection( 'getSelection' );
522522 $( '#wikieditor-toolbar-link-int-target' ).focus();
523523 // Trigger the change event, so the link status indicator is up to date
@@ -649,7 +649,7 @@
650650 'wikieditor-toolbar-tool-reference-cancel': function() {
651651 // Clear any saved selection state
652652 var context = $( this ).data( 'context' );
653 - context.fn.restoreStuffForIE();
 653+ context.fn.restoreCursorAndScrollTop();
654654 $( this ).dialog( 'close' );
655655 }
656656 },
@@ -657,8 +657,8 @@
658658 // Pre-fill the text fields based on the current selection
659659 var context = $(this).data( 'context' );
660660 // Restore and immediately save selection state, needed for inserting stuff later
661 - context.fn.restoreStuffForIE();
662 - context.fn.saveStuffForIE();
 661+ context.fn.restoreCursorAndScrollTop();
 662+ context.fn.saveCursorAndScrollTop();
663663 var selection = context.$textarea.textSelection( 'getSelection' );
664664 // set focus
665665 $( '#wikieditor-toolbar-reference-text' ).focus();
Index: trunk/extensions/WikiEditor/modules/jquery.wikiEditor.iframe.js
@@ -542,30 +542,26 @@
543543 t = nextT;
544544 }
545545 },
 546+ 'saveCursorAndScrollTop': function() {
 547+ // Stub out textarea behavior
 548+ return;
 549+ },
 550+ 'restoreCursorAndScrollTop': function() {
 551+ // Stub out textarea behavior
 552+ return;
 553+ },
546554 'saveSelection': function() {
547 - if ( !$.browser.msie ) {
548 - // Only IE needs this
549 - return;
550 - }
551 - if ( typeof context.$iframe != 'undefined' ) {
 555+ if ( $.client.name === 'msie' ) {
552556 context.$iframe[0].contentWindow.focus();
553557 context.savedSelection = context.$iframe[0].contentWindow.document.selection.createRange();
554 - } else {
555 - context.$textarea.focus();
556 - context.savedSelection = document.selection.createRange();
557558 }
558559 },
559560 'restoreSelection': function() {
560 - if ( !$.browser.msie || context.savedSelection === null ) {
561 - return;
562 - }
563 - if ( typeof context.$iframe != 'undefined' ) {
 561+ if ( $.client.name === 'msie' && context.savedSelection !== null ) {
564562 context.$iframe[0].contentWindow.focus();
565 - } else {
566 - context.$textarea.focus();
 563+ context.savedSelection.select();
 564+ context.savedSelection = null;
567565 }
568 - context.savedSelection.select();
569 - context.savedSelection = null;
570566 },
571567 /**
572568 * Update the history queue

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r74271* Introduced the concept of context extensions...tparscal20:12, 4 October 2010

Status & tagging log