http://www.mediawiki.org/wiki/Special:Code/MediaWiki/66286
Revision: 66286 Author: catrope Date: 2010-05-12 19:40:08 +0000 (Wed, 12 May 2010) Log Message: ----------- UsabilityInitiative: (bug 23485) (bug 23061) Selection not getting picked up in IE. Save and restore cursor position in addition to scrollTop, and generalize that into context.fn.saveStuffForIE() and context.fn.restoreStuffForIE() Modified Paths: -------------- trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Toolbar/Toolbar.js trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.js trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.min.js trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toolbar.js trunk/extensions/UsabilityInitiative/js/plugins.combined.js trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js Modified: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php =================================================================== --- trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php 2010-05-12 19:37:43 UTC (rev 66285) +++ trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php 2010-05-12 19:40:08 UTC (rev 66286) @@ -71,10 +71,10 @@ array( 'src' => 'js/plugins/jquery.cookie.js', 'version' => 4 ), array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 1 ), array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 13 ), - array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 31 ), - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 186 ), + array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 32 ), + array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 187 ), array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 53 ), - array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 60 ), + array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 61 ), array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 24 ), array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 98 ), array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 11 ), @@ -83,10 +83,10 @@ array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 5 ), ), 'combined' => array( - array( 'src' => 'js/plugins.combined.js', 'version' => 392 ), + array( 'src' => 'js/plugins.combined.js', 'version' => 393 ), ), 'minified' => array( - array( 'src' => 'js/plugins.combined.min.js', 'version' => 392 ), + array( 'src' => 'js/plugins.combined.min.js', 'version' => 393 ), ), ), ); Modified: trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Toolbar/Toolbar.js =================================================================== --- trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Toolbar/Toolbar.js 2010-05-12 19:37:43 UTC (rev 66285) +++ trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Toolbar/Toolbar.js 2010-05-12 19:40:08 UTC (rev 66286) @@ -1375,6 +1375,8 @@ $j( '#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext' ).attr( 'checked', '' ); }, 'wikieditor-toolbar-tool-link-cancel': function() { + // Clear any saved selection state + context.fn.restoreStuffForIE(); $j(this).dialog( 'close' ); } }, @@ -1385,8 +1387,11 @@ .replace( /\\\$1/g, '(.*)' ) + '$' ) ); // Pre-fill the text fields based on the current selection - var selection = $j(this).data( 'context' ) - .$textarea.textSelection( 'getSelection' ); + var context = $j(this).data( 'context' ); + // Restore and immediately save selection state, needed for inserting stuff later + context.fn.restoreStuffForIE(); + context.fn.saveStuffForIE(); + var selection = context.$textarea.textSelection( 'getSelection' ); $j( '#wikieditor-toolbar-link-int-target' ).focus(); // Trigger the change event, so the link status indicator is up to date $j( '#wikieditor-toolbar-link-int-target' ).change(); @@ -1505,13 +1510,18 @@ $j( '#wikieditor-toolbar-reference-text' ).val( "" ); }, 'wikieditor-toolbar-tool-reference-cancel': function() { + // Clear any saved selection state + context.fn.restoreStuffForIE(); $j( this ).dialog( 'close' ); } }, open: function() { // Pre-fill the text fields based on the current selection - var selection = $j(this).data( 'context' ) - .$textarea.textSelection( 'getSelection' ); + var context = $j(this).data( 'context' ); + // Restore and immediately save selection state, needed for inserting stuff later + context.fn.restoreStuffForIE(); + context.fn.saveStuffForIE(); + var selection = context.$textarea.textSelection( 'getSelection' ); // set focus $j( '#wikieditor-toolbar-reference-text' ).focus(); $j( '#wikieditor-toolbar-reference-dialog' ) Modified: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.js =================================================================== --- trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.js 2010-05-12 19:37:43 UTC (rev 66285) +++ trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.js 2010-05-12 19:40:08 UTC (rev 66286) @@ -1424,6 +1424,8 @@ $j( '#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext' ).attr( 'checked', '' ); }, 'wikieditor-toolbar-tool-link-cancel': function() { + // Clear any saved selection state + context.fn.restoreStuffForIE(); $j(this).dialog( 'close' ); } }, @@ -1434,8 +1436,11 @@ .replace( /\\\$1/g, '(.*)' ) + '$' ) ); // Pre-fill the text fields based on the current selection - var selection = $j(this).data( 'context' ) - .$textarea.textSelection( 'getSelection' ); + var context = $j(this).data( 'context' ); + // Restore and immediately save selection state, needed for inserting stuff later + context.fn.restoreStuffForIE(); + context.fn.saveStuffForIE(); + var selection = context.$textarea.textSelection( 'getSelection' ); $j( '#wikieditor-toolbar-link-int-target' ).focus(); // Trigger the change event, so the link status indicator is up to date $j( '#wikieditor-toolbar-link-int-target' ).change(); @@ -1554,13 +1559,18 @@ $j( '#wikieditor-toolbar-reference-text' ).val( "" ); }, 'wikieditor-toolbar-tool-reference-cancel': function() { + // Clear any saved selection state + context.fn.restoreStuffForIE(); $j( this ).dialog( 'close' ); } }, open: function() { // Pre-fill the text fields based on the current selection - var selection = $j(this).data( 'context' ) - .$textarea.textSelection( 'getSelection' ); + var context = $j(this).data( 'context' ); + // Restore and immediately save selection state, needed for inserting stuff later + context.fn.restoreStuffForIE(); + context.fn.saveStuffForIE(); + var selection = context.$textarea.textSelection( 'getSelection' ); // set focus $j( '#wikieditor-toolbar-reference-text' ).focus(); $j( '#wikieditor-toolbar-reference-dialog' ) Modified: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.min.js =================================================================== --- trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.min.js 2010-05-12 19:37:43 UTC (rev 66285) +++ trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.min.js 2010-05-12 19:40:08 UTC (rev 66286) @@ -68,7 +68,7 @@ insertText=escTarget;else if(text=='') insertText='['+escTarget+']';else insertText='['+escTarget+' '+escText+']';} -if(whitespace)insertText=whitespace[0]+insertText+whitespace[1];$j(this).dialog('close');$j.wikiEditor.modules.toolbar.fn.doAction($j(this).data('context'),{type:'replace',options:{pre:insertText}},$j(this));$j('#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text').val('');$j('#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext').attr('checked','');},'wikieditor-toolbar-tool-link-cancel':function(){$j(this).dialog('close');}},open:function(){$j(this).data('articlePathRegex',new RegExp('^'+RegExp.escape(wgServer+wgArticlePath).replace(/\\\$1/g,'(.*)')+'$'));var selection=$j(this).data('context').$textarea.textSelection('getSelection');$j('#wikieditor-toolbar-link-int-target').focus();$j('#wikieditor-toolbar-link-int-target').change();$j('#wikieditor-toolbar-link-dialog').data('whitespace',['','']);if(selection!=''){var target,text,type;var matches;if((matches=selection.match(/^(\s*)\[\[([^\]\|]+)(\|([^\]\|]*))?\]\](\s*)$/))){target=matches[2];text=(matches[4]?matches[4]:matches[2]);type='int';$j('#wikieditor-toolbar-link-dialog').data('whitespace',[matches[1],matches[5]]);}else if((matches=selection.match(/^(\s*)\[([^\] ]+)( ([^\]]+))?\](\s*)$/))){target=matches[2];text=(matches[4]?matches[4]:'');type='ext';$j('#wikieditor-toolbar-link-dialog').data('whitespace',[matches[1],matches[5]]);}else{target=text=selection;} +if(whitespace)insertText=whitespace[0]+insertText+whitespace[1];$j(this).dialog('close');$j.wikiEditor.modules.toolbar.fn.doAction($j(this).data('context'),{type:'replace',options:{pre:insertText}},$j(this));$j('#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text').val('');$j('#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext').attr('checked','');},'wikieditor-toolbar-tool-link-cancel':function(){context.fn.restoreStuffForIE();$j(this).dialog('close');}},open:function(){$j(this).data('articlePathRegex',new RegExp('^'+RegExp.escape(wgServer+wgArticlePath).replace(/\\\$1/g,'(.*)')+'$'));var context=$j(this).data('context');context.fn.restoreStuffForIE();context.fn.saveStuffForIE();var selection=context.$textarea.textSelection('getSelection');$j('#wikieditor-toolbar-link-int-target').focus();$j('#wikieditor-toolbar-link-int-target').change();$j('#wikieditor-toolbar-link-dialog').data('whitespace',['','']);if(selection!=''){var target,text,type;var matches;if((matches=selection.match(/^(\s*)\[\[([^\]\|]+)(\|([^\]\|]*))?\]\](\s*)$/))){target=matches[2];text=(matches[4]?matches[4]:matches[2]);type='int';$j('#wikieditor-toolbar-link-dialog').data('whitespace',[matches[1],matches[5]]);}else if((matches=selection.match(/^(\s*)\[([^\] ]+)( ([^\]]+))?\](\s*)$/))){target=matches[2];text=(matches[4]?matches[4]:'');type='ext';$j('#wikieditor-toolbar-link-dialog').data('whitespace',[matches[1],matches[5]]);}else{target=text=selection;} if(typeof text!='undefined') $j('#wikieditor-toolbar-link-int-text').val(text).change();if(typeof target!='undefined') $j('#wikieditor-toolbar-link-int-target').val(target).change();if(typeof type!='undefined') @@ -84,7 +84,7 @@ <input type="text" id="wikieditor-toolbar-reference-text" />\ </div>\ </div></fieldset>\ - </div>',init:function(){$j(this).find('[rel]').each(function(){$j(this).text(mw.usability.getMsg($j(this).attr('rel')));});},dialog:{dialogClass:'wikiEditor-toolbar-dialog',width:590,buttons:{'wikieditor-toolbar-tool-reference-insert':function(){var insertText=$j('#wikieditor-toolbar-reference-text').val();var whitespace=$j('#wikieditor-toolbar-reference-dialog').data('whitespace');var attributes=$j('#wikieditor-toolbar-reference-dialog').data('attributes');$j(this).dialog('close');$j.wikiEditor.modules.toolbar.fn.doAction($j(this).data('context'),{type:'replace',options:{pre:whitespace[0]+'<ref'+attributes+'>',peri:insertText,post:'</ref>'+whitespace[1]}},$j(this));$j('#wikieditor-toolbar-reference-text').val("");},'wikieditor-toolbar-tool-reference-cancel':function(){$j(this).dialog('close');}},open:function(){var selection=$j(this).data('context').$textarea.textSelection('getSelection');$j('#wikieditor-toolbar-reference-text').focus();$j('#wikieditor-toolbar-reference-dialog').data('whitespace',['','']).data('attributes','');if(selection!=''){var matches,text;if((matches=selection.match(/^(\s*)<ref([^\>]*)>([^\<]*)<\/ref\>(\s*)$/))){text=matches[3];$j('#wikieditor-toolbar-reference-dialog').data('whitespace',[matches[1],matches[4]]);$j('#wikieditor-toolbar-reference-dialog').data('attributes',matches[2]);}else{text=selection;} + </div>',init:function(){$j(this).find('[rel]').each(function(){$j(this).text(mw.usability.getMsg($j(this).attr('rel')));});},dialog:{dialogClass:'wikiEditor-toolbar-dialog',width:590,buttons:{'wikieditor-toolbar-tool-reference-insert':function(){var insertText=$j('#wikieditor-toolbar-reference-text').val();var whitespace=$j('#wikieditor-toolbar-reference-dialog').data('whitespace');var attributes=$j('#wikieditor-toolbar-reference-dialog').data('attributes');$j(this).dialog('close');$j.wikiEditor.modules.toolbar.fn.doAction($j(this).data('context'),{type:'replace',options:{pre:whitespace[0]+'<ref'+attributes+'>',peri:insertText,post:'</ref>'+whitespace[1]}},$j(this));$j('#wikieditor-toolbar-reference-text').val("");},'wikieditor-toolbar-tool-reference-cancel':function(){context.fn.restoreStuffForIE();$j(this).dialog('close');}},open:function(){var context=$j(this).data('context');context.fn.restoreStuffForIE();context.fn.saveStuffForIE();var selection=context.$textarea.textSelection('getSelection');$j('#wikieditor-toolbar-reference-text').focus();$j('#wikieditor-toolbar-reference-dialog').data('whitespace',['','']).data('attributes','');if(selection!=''){var matches,text;if((matches=selection.match(/^(\s*)<ref([^\>]*)>([^\<]*)<\/ref\>(\s*)$/))){text=matches[3];$j('#wikieditor-toolbar-reference-dialog').data('whitespace',[matches[1],matches[4]]);$j('#wikieditor-toolbar-reference-dialog').data('attributes',matches[2]);}else{text=selection;} $j('#wikieditor-toolbar-reference-text').val(text);} if(!($j(this).data('dialogkeypressset'))){$j(this).data('dialogkeypressset',true);$j(this).closest('.ui-dialog').keypress(function(e){if((e.keyCode||e.which)==13){var button=$j(this).data('dialogaction')||$j(this).find('button:first');button.click();e.preventDefault();}});$j(this).closest('.ui-dialog').find('button').focus(function(){$j(this).closest('.ui-dialog').data('dialogaction',this);});}}}},'insert-table':{filters:['#wpTextbox1.toolbar-dialogs'],titleMsg:'wikieditor-toolbar-tool-table-title',id:'wikieditor-toolbar-table-dialog',html:'\ <div class="wikieditor-toolbar-dialog-wrapper">\ Modified: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php =================================================================== --- trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php 2010-05-12 19:37:43 UTC (rev 66285) +++ trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php 2010-05-12 19:40:08 UTC (rev 66286) @@ -16,16 +16,16 @@ array( 'src' => 'Modules/Preview/Preview.js', 'version' => 6 ), array( 'src' => 'Modules/Publish/Publish.js', 'version' => 6 ), array( 'src' => 'Modules/Toc/Toc.js', 'version' => 7 ), - array( 'src' => 'Modules/Toolbar/Toolbar.js', 'version' => 84 ), + array( 'src' => 'Modules/Toolbar/Toolbar.js', 'version' => 85 ), array( 'src' => 'Modules/TemplateEditor/TemplateEditor.js', 'version' => 6 ), array( 'src' => 'Modules/Templates/Templates.js', 'version' => 1 ), array( 'src' => 'Modules/AddMediaWizard/AddMediaWizard.js', 'version' => 6 ), ), 'combined' => array( - array( 'src' => 'WikiEditor.combined.js', 'version' => 89 ), + array( 'src' => 'WikiEditor.combined.js', 'version' => 90 ), ), 'minified' => array( - array( 'src' => 'WikiEditor.combined.min.js', 'version' => 89 ), + array( 'src' => 'WikiEditor.combined.min.js', 'version' => 90 ), ), ); static $messages = array( Modified: trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js =================================================================== --- trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js 2010-05-12 19:37:43 UTC (rev 66285) +++ trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js 2010-05-12 19:40:08 UTC (rev 66286) @@ -52,13 +52,13 @@ options.post += ' '; } } - var selText = $(this).textSelection( 'getSelection' ); var isSample = false; if ( this.style.display == 'none' ) { // Do nothing } else if ( this.selectionStart || this.selectionStart == '0' ) { // Mozilla/Opera $(this).focus(); + var selText = $(this).textSelection( 'getSelection' ); var startPos = this.selectionStart; var endPos = this.selectionEnd; var scrollTop = this.scrollTop; @@ -90,13 +90,10 @@ } } else if ( document.selection && document.selection.createRange ) { // IE - // For some mysterious reason, clicking a toolbar button is enough to make - // the textarea scroll. Check if a toolbar button's mousedown handler saved - // the scroll position and use it if available. - var scrollTop = $(this).data( 'scrollTop' ) || this.scrollTop; - $(this).data( 'scrollTop', null ); $(this).focus(); - this.scrollTop = scrollTop; + context.fn.restoreStuffForIE(); + var selText = $(this).textSelection( 'getSelection' ); + var scrollTop = this.scrollTop; var range = document.selection.createRange(); if ( options.ownline && range.moveStart ) { var range2 = document.selection.createRange(); Modified: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js =================================================================== --- trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js 2010-05-12 19:37:43 UTC (rev 66285) +++ trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js 2010-05-12 19:40:08 UTC (rev 66286) @@ -1724,6 +1724,33 @@ body.scrollTop( y ); } $element.trigger( 'scrollToTop' ); + }, + /** + * Save scrollTop and cursor position for IE. + */ + 'saveStuffForIE': function() { + // Only need this for IE in textarea mode + if ( !$.browser.msie || context.$iframe ) + return; + var IHateIE = { + 'scrollTop' : context.$textarea.scrollTop(), + 'pos': context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } ) + }; + context.$textarea.data( 'IHateIE', IHateIE ); + }, + /** + * Restore scrollTo and cursor position for IE. + */ + 'restoreStuffForIE': function() { + // Only need this for IE in textarea mode + if ( !$.browser.msie || context.$iframe ) + return; + var IHateIE = context.$textarea.data( 'IHateIE' ); + if ( !IHateIE ) + return; + context.$textarea.scrollTop( IHateIE.scrollTop ); + context.$textarea.textSelection( 'setSelection', { start: IHateIE.pos[0], end: IHateIE.pos[1] } ); + context.$textarea.data( 'IHateIE', null ); } }; Modified: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toolbar.js =================================================================== --- trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toolbar.js 2010-05-12 19:37:43 UTC (rev 66285) +++ trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toolbar.js 2010-05-12 19:40:08 UTC (rev 66286) @@ -111,8 +111,7 @@ .append( $( $.wikiEditor.modules.toolbar.fn.buildCharacter( data[type][character], actions ) ) .mousedown( function( e ) { - // Save scroll position for IE - context.$textarea.data( 'scrollTop', context.$textarea.scrollTop() ); + context.fn.saveStuffForIE(); // No dragging! e.preventDefault(); return false; @@ -344,8 +343,7 @@ .data( 'action', tool.action ) .data( 'context', context ) .mousedown( function( e ) { - // Save scroll position for IE - context.$textarea.data( 'scrollTop', context.$textarea.scrollTop() ); + context.fn.saveStuffForIE(); // No dragging! e.preventDefault(); return false; @@ -382,8 +380,7 @@ .data( 'action', tool.list[option].action ) .data( 'context', context ) .mousedown( function( e ) { - // Save scroll position for IE - context.$textarea.data( 'scrollTop', context.$textarea.scrollTop() ); + context.fn.saveStuffForIE(); // No dragging! e.preventDefault(); return false; @@ -499,8 +496,7 @@ .html( html ) .children() .mousedown( function( e ) { - // Save scroll position for IE - context.$textarea.data( 'scrollTop', context.$textarea.scrollTop() ); + context.fn.saveStuffForIE(); // No dragging! e.preventDefault(); return false; Modified: trunk/extensions/UsabilityInitiative/js/plugins.combined.js =================================================================== --- trunk/extensions/UsabilityInitiative/js/plugins.combined.js 2010-05-12 19:37:43 UTC (rev 66285) +++ trunk/extensions/UsabilityInitiative/js/plugins.combined.js 2010-05-12 19:40:08 UTC (rev 66286) @@ -6254,13 +6254,13 @@ options.post += ' '; } } - var selText = $(this).textSelection( 'getSelection' ); var isSample = false; if ( this.style.display == 'none' ) { // Do nothing } else if ( this.selectionStart || this.selectionStart == '0' ) { // Mozilla/Opera $(this).focus(); + var selText = $(this).textSelection( 'getSelection' ); var startPos = this.selectionStart; var endPos = this.selectionEnd; var scrollTop = this.scrollTop; @@ -6292,13 +6292,10 @@ } } else if ( document.selection && document.selection.createRange ) { // IE - // For some mysterious reason, clicking a toolbar button is enough to make - // the textarea scroll. Check if a toolbar button's mousedown handler saved - // the scroll position and use it if available. - var scrollTop = $(this).data( 'scrollTop' ) || this.scrollTop; - $(this).data( 'scrollTop', null ); $(this).focus(); - this.scrollTop = scrollTop; + context.fn.restoreStuffForIE(); + var selText = $(this).textSelection( 'getSelection' ); + var scrollTop = this.scrollTop; var range = document.selection.createRange(); if ( options.ownline && range.moveStart ) { var range2 = document.selection.createRange(); @@ -8325,6 +8322,33 @@ body.scrollTop( y ); } $element.trigger( 'scrollToTop' ); + }, + /** + * Save scrollTop and cursor position for IE. + */ + 'saveStuffForIE': function() { + // Only need this for IE in textarea mode + if ( !$.browser.msie || context.$iframe ) + return; + var IHateIE = { + 'scrollTop' : context.$textarea.scrollTop(), + 'pos': context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } ) + }; + context.$textarea.data( 'IHateIE', IHateIE ); + }, + /** + * Restore scrollTo and cursor position for IE. + */ + 'restoreStuffForIE': function() { + // Only need this for IE in textarea mode + if ( !$.browser.msie || context.$iframe ) + return; + var IHateIE = context.$textarea.data( 'IHateIE' ); + if ( !IHateIE ) + return; + context.$textarea.scrollTop( IHateIE.scrollTop ); + context.$textarea.textSelection( 'setSelection', { start: IHateIE.pos[0], end: IHateIE.pos[1] } ); + context.$textarea.data( 'IHateIE', null ); } }; @@ -10935,8 +10959,7 @@ .append( $( $.wikiEditor.modules.toolbar.fn.buildCharacter( data[type][character], actions ) ) .mousedown( function( e ) { - // Save scroll position for IE - context.$textarea.data( 'scrollTop', context.$textarea.scrollTop() ); + context.fn.saveStuffForIE(); // No dragging! e.preventDefault(); return false; @@ -11168,8 +11191,7 @@ .data( 'action', tool.action ) .data( 'context', context ) .mousedown( function( e ) { - // Save scroll position for IE - context.$textarea.data( 'scrollTop', context.$textarea.scrollTop() ); + context.fn.saveStuffForIE(); // No dragging! e.preventDefault(); return false; @@ -11206,8 +11228,7 @@ .data( 'action', tool.list[option].action ) .data( 'context', context ) .mousedown( function( e ) { - // Save scroll position for IE - context.$textarea.data( 'scrollTop', context.$textarea.scrollTop() ); + context.fn.saveStuffForIE(); // No dragging! e.preventDefault(); return false; @@ -11323,8 +11344,7 @@ .html( html ) .children() .mousedown( function( e ) { - // Save scroll position for IE - context.$textarea.data( 'scrollTop', context.$textarea.scrollTop() ); + context.fn.saveStuffForIE(); // No dragging! e.preventDefault(); return false; Modified: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js =================================================================== --- trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js 2010-05-12 19:37:43 UTC (rev 66285) +++ trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js 2010-05-12 19:40:08 UTC (rev 66286) @@ -414,12 +414,12 @@ context.data.$container.hide();$.suggestions.cancel(context);});} $(this).data('suggestions-context',context);});return returnValue!==null?returnValue:$(this);};})(jQuery);(function($){$.fn.textSelection=function(command,options){var fn={getContents:function(){return this.val();},getSelection:function(){var e=this.get(0);var retval='';if($(e).is(':hidden')){}else if(document.selection&&document.selection.createRange){e.focus();var range=document.selection.createRange();retval=range.text;}else if(e.selectionStart||e.selectionStart=='0'){retval=e.value.substring(e.selectionStart,e.selectionEnd);} return retval;},encapsulateSelection:function(options){return this.each(function(){function checkSelectedText(){if(!selText){selText=options.peri;isSample=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);options.post+=' ';}} -var selText=$(this).textSelection('getSelection');var isSample=false;if(this.style.display=='none'){}else if(this.selectionStart||this.selectionStart=='0'){$(this).focus();var startPos=this.selectionStart;var endPos=this.selectionEnd;var scrollTop=this.scrollTop;checkSelectedText();if(options.ownline){if(startPos!=0&&this.value.charAt(startPos-1)!="\n"){options.pre="\n"+options.pre;} +var isSample=false;if(this.style.display=='none'){}else if(this.selectionStart||this.selectionStart=='0'){$(this).focus();var selText=$(this).textSelection('getSelection');var startPos=this.selectionStart;var endPos=this.selectionEnd;var scrollTop=this.scrollTop;checkSelectedText();if(options.ownline){if(startPos!=0&&this.value.charAt(startPos-1)!="\n"){options.pre="\n"+options.pre;} if(this.value.charAt(endPos)!="\n"){options.post+="\n";}} this.value=this.value.substring(0,startPos)+options.pre+selText+options.post+ this.value.substring(endPos,this.value.length);this.scrollTop=scrollTop;if(window.opera){options.pre=options.pre.replace(/\r?\n/g,"\r\n");selText=selText.replace(/\r?\n/g,"\r\n");options.post=options.post.replace(/\r?\n/g,"\r\n");} if(isSample){this.selectionStart=startPos+options.pre.length;this.selectionEnd=startPos+options.pre.length+selText.length;}else{this.selectionStart=startPos+options.pre.length+selText.length+ -options.post.length;this.selectionEnd=this.selectionStart;}}else if(document.selection&&document.selection.createRange){var scrollTop=$(this).data('scrollTop')||this.scrollTop;$(this).data('scrollTop',null);$(this).focus();this.scrollTop=scrollTop;var range=document.selection.createRange();if(options.ownline&&range.moveStart){var range2=document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range2.text!=""){options.pre="\n"+options.pre;} +options.post.length;this.selectionEnd=this.selectionStart;}}else if(document.selection&&document.selection.createRange){$(this).focus();context.fn.restoreStuffForIE();var selText=$(this).textSelection('getSelection');var scrollTop=this.scrollTop;var range=document.selection.createRange();if(options.ownline&&range.moveStart){var range2=document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range2.text!=""){options.pre="\n"+options.pre;} var range3=document.selection.createRange();range3.collapse(false);range3.moveEnd('character',1);if(range3.text!="\r"&&range3.text!="\n"&&range3.text!=""){options.post+="\n";}} checkSelectedText();range.text=options.pre+selText+options.post;if(isSample&&range.moveStart){range.moveStart('character',-options.post.length-selText.length);range.moveEnd('character',-options.post.length);} range.select();this.scrollTop=scrollTop;} @@ -576,7 +576,10 @@ range2.setEndPoint('StartToEnd',range);range2.select();} return context.$textarea;},'scrollToCaretPosition':function(options){context.fn.scrollToTop(context.fn.getElementAtCursor(),true);},'scrollToTop':function($element,force){var html=context.$content.closest('html'),body=context.$content.closest('body'),parentHtml=$('html'),parentBody=$('body');var y=$element.offset().top;if(!$.browser.msie&&!$element.is('body')){y=parentHtml.scrollTop()>0?y+html.scrollTop()-parentHtml.scrollTop():y;y=parentBody.scrollTop()>0?y+body.scrollTop()-parentBody.scrollTop():y;} var topBound=html.scrollTop()>body.scrollTop()?html.scrollTop():body.scrollTop(),bottomBound=topBound+context.$iframe.height();if(force||y<topBound||y>bottomBound){html.scrollTop(y);body.scrollTop(y);} -$element.trigger('scrollToTop');}};context.$textarea.wrapAll($('<div></div>').addClass('wikiEditor-ui')).wrapAll($('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-wikitext')).wrapAll($('<div></div>').addClass('wikiEditor-ui-left')).wrapAll($('<div></div>').addClass('wikiEditor-ui-bottom')).wrapAll($('<div></div>').addClass('wikiEditor-ui-text'));context.$ui=context.$textarea.parent().parent().parent().parent().parent();context.$wikitext=context.$textarea.parent().parent().parent().parent();context.$wikitext.before($('<div></div>').addClass('wikiEditor-ui-controls').append($('<div></div>').addClass('wikiEditor-ui-tabs').hide()).append($('<div></div>').addClass('wikiEditor-ui-buttons'))).before($('<div style="clear:both;"></div>'));context.$controls=context.$ui.find('.wikiEditor-ui-buttons').hide();context.$buttons=context.$ui.find('.wikiEditor-ui-buttons');context.$tabs=context.$ui.find('.wikiEditor-ui-tabs');context.$ui.after($('<div style="clear:both;"></div>'));context.$wikitext.append($('<div></div>').addClass('wikiEditor-ui-right'));context.$wikitext.find('.wikiEditor-ui-left').prepend($('<div></div>').addClass('wikiEditor-ui-top'));context.view='wikitext';$(window).resize(function(event){context.fn.trigger('resize',event);});} +$element.trigger('scrollToTop');},'saveStuffForIE':function(){if(!$.browser.msie||context.$iframe) +return;var IHateIE={'scrollTop':context.$textarea.scrollTop(),'pos':context.$textarea.textSelection('getCaretPosition',{startAndEnd:true})};context.$textarea.data('IHateIE',IHateIE);},'restoreStuffForIE':function(){if(!$.browser.msie||context.$iframe) +return;var IHateIE=context.$textarea.data('IHateIE');if(!IHateIE) +return;context.$textarea.scrollTop(IHateIE.scrollTop);context.$textarea.textSelection('setSelection',{start:IHateIE.pos[0],end:IHateIE.pos[1]});context.$textarea.data('IHateIE',null);}};context.$textarea.wrapAll($('<div></div>').addClass('wikiEditor-ui')).wrapAll($('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-wikitext')).wrapAll($('<div></div>').addClass('wikiEditor-ui-left')).wrapAll($('<div></div>').addClass('wikiEditor-ui-bottom')).wrapAll($('<div></div>').addClass('wikiEditor-ui-text'));context.$ui=context.$textarea.parent().parent().parent().parent().parent();context.$wikitext=context.$textarea.parent().parent().parent().parent();context.$wikitext.before($('<div></div>').addClass('wikiEditor-ui-controls').append($('<div></div>').addClass('wikiEditor-ui-tabs').hide()).append($('<div></div>').addClass('wikiEditor-ui-buttons'))).before($('<div style="clear:both;"></div>'));context.$controls=context.$ui.find('.wikiEditor-ui-buttons').hide();context.$buttons=context.$ui.find('.wikiEditor-ui-buttons');context.$tabs=context.$ui.find('.wikiEditor-ui-tabs');context.$ui.after($('<div style="clear:both;"></div>'));context.$wikitext.append($('<div></div>').addClass('wikiEditor-ui-right'));context.$wikitext.find('.wikiEditor-ui-left').prepend($('<div></div>').addClass('wikiEditor-ui-top'));context.view='wikitext';$(window).resize(function(event){context.fn.trigger('resize',event);});} var args=$.makeArray(arguments);if(typeof context.$iframe==='undefined'&&args[0]=='addModule'&&typeof args[1]!='undefined'){var modules=args[1];if(typeof modules!="object"){modules={};modules[args[1]]='';} for(module in modules){if(module in $.wikiEditor.modules&&$.wikiEditor.isSupported($.wikiEditor.modules[module])&&$.wikiEditor.isRequired($.wikiEditor.modules[module],'iframe')){context.fn.setupIframe();break;}}} if(args.length>0){var call=args.shift();if(call in context.api){context.api[call](context,typeof args[0]=='undefined'?{}:args[0]);}} @@ -746,7 +749,7 @@ $.wikiEditor.modules.toolbar.fn.updateBookletSelection(context,page,$pages,$index);break;case'rows':if(!('section'in data&&'page'in data)){continue;} var $table=context.modules.toolbar.$toolbar.find('div[rel='+data.section+'].section '+'div[rel='+data.page+'].page table');for(row in data[type]){$table.append($.wikiEditor.modules.toolbar.fn.buildRow(context,data[type][row]));} break;case'characters':if(!('section'in data&&'page'in data)){continue;} -$characters=context.modules.toolbar.$toolbar.find('div[rel='+data.section+'].section '+'div[rel='+data.page+'].page div');var actions=$characters.data('actions');for(character in data[type]){$characters.append($($.wikiEditor.modules.toolbar.fn.buildCharacter(data[type][character],actions)).mousedown(function(e){context.$textarea.data('scrollTop',context.$textarea.scrollTop());e.preventDefault();return false;}).click(function(e){$.wikiEditor.modules.toolbar.fn.doAction($(this).parent().data('context'),$(this).parent().data('actions')[$(this).attr('rel')]);e.preventDefault();return false;}));} +$characters=context.modules.toolbar.$toolbar.find('div[rel='+data.section+'].section '+'div[rel='+data.page+'].page div');var actions=$characters.data('actions');for(character in data[type]){$characters.append($($.wikiEditor.modules.toolbar.fn.buildCharacter(data[type][character],actions)).mousedown(function(e){context.fn.saveStuffForIE();e.preventDefault();return false;}).click(function(e){$.wikiEditor.modules.toolbar.fn.doAction($(this).parent().data('context'),$(this).parent().data('actions')[$(this).attr('rel')]);e.preventDefault();return false;}));} break;default:break;}}},removeFromToolbar:function(context,data){if(typeof data.section=='string'){var tab='div.tabs span[rel='+data.section+'].tab';var target='div[rel='+data.section+'].section';var group=null;if(typeof data.group=='string'){target+=' div[rel='+data.group+'].group';if(typeof data.tool=='string'){group=target;target+=' div[rel='+data.tool+'].tool';}}else if(typeof data.page=='string'){var index=target+' div.index div[rel='+data.page+']';target+=' div.pages div[rel='+data.page+'].page';if(typeof data.character=='string'){target+=' a[rel='+data.character+']';}else if(typeof data.row=='number'){target+=' table tr:not(:has(th)):eq('+data.row+')';}else{context.modules.toolbar.$toolbar.find(index).remove();$.wikiEditor.modules.toolbar.fn.updateBookletSelection(context,null,context.modules.toolbar.$toolbar.find(target),context.modules.toolbar.$toolbar.find(index));}}else{context.modules.toolbar.$toolbar.find(tab).remove();} context.modules.toolbar.$toolbar.find(target).remove();if(group){$group=context.modules.toolbar.$toolbar.find(group);if($group.children().length==0){$group.hide();}}}}},evt:{resize:function(context,event){context.$ui.find('.sections').height(context.$ui.find('.sections .section-visible').outerHeight());},tocCollapse:function(context,event){$.wikiEditor.modules.toolbar.evt.resize(context,event);},tocExpand:function(context,event){$.wikiEditor.modules.toolbar.evt.resize(context,event);}},fn:{create:function(context,config){if('$toolbar'in context.modules.toolbar){return;} context.modules.toolbar.$toolbar=$('<div />').addClass('wikiEditor-ui-toolbar').attr('id','wikiEditor-ui-toolbar');$.wikiEditor.modules.toolbar.fn.build(context,config);context.$ui.find('.wikiEditor-ui-top').append(context.modules.toolbar.$toolbar);},doAction:function(context,action,source){if($.trackAction!=undefined&&source.closest('.wikiEditor-ui-toolbar').size()){var rels=[];var step=source;var i=0;while(!step.hasClass('wikiEditor-ui-toolbar')){if(i>25){break;} @@ -761,8 +764,8 @@ if(empty){$group.hide();} return $group;},buildTool:function(context,id,tool){if('filters'in tool){for(filter in tool.filters){if($(tool.filters[filter]).size()==0){return null;}}} var label=$.wikiEditor.autoMsg(tool,'label');switch(tool.type){case'button':var src=$.wikiEditor.autoIcon(tool.icon,$.wikiEditor.imgPath+'toolbar/');var $button;if('offset'in tool){var offset=$.wikiEditor.autoLang(tool.offset);$button=$('<span />').attr({'alt':label,'title':label,'rel':id,'class':'wikiEditor-toolbar-spritedButton'}).text(label).css('backgroundPosition',offset[0]+'px '+offset[1]+'px');}else{$button=$('<img />').attr({'src':src,'width':22,'height':22,'alt':label,'title':label,'rel':id,'class':'tool tool-button'});} -if('action'in tool){$button.data('action',tool.action).data('context',context).mousedown(function(e){context.$textarea.data('scrollTop',context.$textarea.scrollTop());e.preventDefault();return false;}).click(function(e){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'),$(this));e.preventDefault();return false;});if(tool.action.type=='dialog'&&!(tool.action.module in $.wikiEditor.modules.dialogs.modules)){$button.hide();context.$textarea.bind('wikiEditor-dialogs-setup-'+tool.action.module,{button:$button},function(event){event.data.button.show().parent().show();});}} -return $button;case'select':var $select=$('<div />').attr({'rel':id,'class':'tool tool-select'});var $options=$('<div />').addClass('options');if('list'in tool){for(option in tool.list){var optionLabel=$.wikiEditor.autoMsg(tool.list[option],'label');$options.append($('<a />').data('action',tool.list[option].action).data('context',context).mousedown(function(e){context.$textarea.data('scrollTop',context.$textarea.scrollTop());e.preventDefault();return false;}).click(function(e){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'),$(this));if($(this).parent().is(':visible')){$(this).parent().animate({'opacity':'toggle'},'fast');} +if('action'in tool){$button.data('action',tool.action).data('context',context).mousedown(function(e){context.fn.saveStuffForIE();e.preventDefault();return false;}).click(function(e){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'),$(this));e.preventDefault();return false;});if(tool.action.type=='dialog'&&!(tool.action.module in $.wikiEditor.modules.dialogs.modules)){$button.hide();context.$textarea.bind('wikiEditor-dialogs-setup-'+tool.action.module,{button:$button},function(event){event.data.button.show().parent().show();});}} +return $button;case'select':var $select=$('<div />').attr({'rel':id,'class':'tool tool-select'});var $options=$('<div />').addClass('options');if('list'in tool){for(option in tool.list){var optionLabel=$.wikiEditor.autoMsg(tool.list[option],'label');$options.append($('<a />').data('action',tool.list[option].action).data('context',context).mousedown(function(e){context.fn.saveStuffForIE();e.preventDefault();return false;}).click(function(e){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'),$(this));if($(this).parent().is(':visible')){$(this).parent().animate({'opacity':'toggle'},'fast');} e.preventDefault();return false;}).text(optionLabel).addClass('option').attr({'rel':option,'href':'#'}));}} $select.append($('<div />').addClass('menu').append($options));$select.append($('<a />').addClass('label').text(label).data('options',$options).attr('href','#').mousedown(function(e){e.preventDefault();return false;}).click(function(e){$(this).data('options').animate({'opacity':'toggle'},'fast');e.preventDefault();return false;}));return $select;default:return null;}},buildBookmark:function(context,id,page){var label=$.wikiEditor.autoMsg(page,'label');return $('<div />').text(label).attr('rel',id).data('context',context).mousedown(function(e){e.preventDefault();return false;}).click(function(event){$(this).parent().parent().find('.page').hide();$(this).parent().parent().find('.page-'+$(this).attr('rel')).show();$(this).siblings().removeClass('current');$(this).addClass('current');var section=$(this).parent().parent().attr('rel');$.cookie('wikiEditor-'+$(this).data('context').instance+'-booklet-'+section+'-page',$(this).attr('rel'));if($.trackAction!=undefined){$.trackAction(section+'.'+$(this).attr('rel'));} event.preventDefault();return false;})},buildPage:function(context,id,page){var $page=$('<div />').attr({'class':'page page-'+id,'rel':id});switch(page.layout){case'table':$page.addClass('page-table');var html='<table cellpadding=0 cellspacing=0 '+'border=0 width="100%" class="table table-"'+id+'">';if('headings'in page){html+=$.wikiEditor.modules.toolbar.fn.buildHeading(context,page.headings)} @@ -770,7 +773,7 @@ $page.html(html);break;case'characters':$page.addClass('page-characters');$characters=$('<div />').data('context',context).data('actions',{});var actions=$characters.data('actions');if('language'in page){$characters.attr('lang',page.language);} if('direction'in page){$characters.attr('dir',page.direction);} if('characters'in page){var html='';for(character in page.characters){html+=$.wikiEditor.modules.toolbar.fn.buildCharacter(page.characters[character],actions);} -$characters.html(html).children().mousedown(function(e){context.$textarea.data('scrollTop',context.$textarea.scrollTop());e.preventDefault();return false;}).click(function(e){$.wikiEditor.modules.toolbar.fn.doAction($(this).parent().data('context'),$(this).parent().data('actions')[$(this).attr('rel')],$(this));e.preventDefault();return false;});} +$characters.html(html).children().mousedown(function(e){context.fn.saveStuffForIE();e.preventDefault();return false;}).click(function(e){$.wikiEditor.modules.toolbar.fn.doAction($(this).parent().data('context'),$(this).parent().data('actions')[$(this).attr('rel')],$(this));e.preventDefault();return false;});} $page.append($characters);break;} return $page;},buildHeading:function(context,headings){var html='<tr>';for(heading in headings){html+='<th>'+$.wikiEditor.autoMsg(headings[heading],['html','text'])+'</th>';} return html;},buildRow:function(context,row){var html='<tr>';for(cell in row){html+='<td class="cell cell-'+cell+'" valign="top"><span>'+ _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs