diff --git a/modules/ext.wikiEditor.dialogs.js b/modules/ext.wikiEditor.dialogs.js index f8f22f0a..51e908ff 100644 --- a/modules/ext.wikiEditor.dialogs.js +++ b/modules/ext.wikiEditor.dialogs.js @@ -502,7 +502,7 @@ $( document ).ready( function() { 'wikieditor-toolbar-tool-link-cancel': function() { // Clear any saved selection state var context = $(this).data( 'context' ); - context.fn.restoreStuffForIE(); + context.fn.restoreCursorAndScrollTop(); $(this).dialog( 'close' ); } }, @@ -515,8 +515,8 @@ $( document ).ready( function() { // Pre-fill the text fields based on the current selection var context = $(this).data( 'context' ); // Restore and immediately save selection state, needed for inserting stuff later - context.fn.restoreStuffForIE(); - context.fn.saveStuffForIE(); + context.fn.restoreCursorAndScrollTop(); + context.fn.saveCursorAndScrollTop(); var selection = context.$textarea.textSelection( 'getSelection' ); $( '#wikieditor-toolbar-link-int-target' ).focus(); // Trigger the change event, so the link status indicator is up to date @@ -649,7 +649,7 @@ $( document ).ready( function() { 'wikieditor-toolbar-tool-reference-cancel': function() { // Clear any saved selection state var context = $( this ).data( 'context' ); - context.fn.restoreStuffForIE(); + context.fn.restoreCursorAndScrollTop(); $( this ).dialog( 'close' ); } }, @@ -657,8 +657,8 @@ $( document ).ready( function() { // Pre-fill the text fields based on the current selection var context = $(this).data( 'context' ); // Restore and immediately save selection state, needed for inserting stuff later - context.fn.restoreStuffForIE(); - context.fn.saveStuffForIE(); + context.fn.restoreCursorAndScrollTop(); + context.fn.saveCursorAndScrollTop(); var selection = context.$textarea.textSelection( 'getSelection' ); // set focus $( '#wikieditor-toolbar-reference-text' ).focus(); diff --git a/modules/jquery.wikiEditor.iframe.js b/modules/jquery.wikiEditor.iframe.js index 3e4c547d..eedec122 100644 --- a/modules/jquery.wikiEditor.iframe.js +++ b/modules/jquery.wikiEditor.iframe.js @@ -542,30 +542,26 @@ context.fn = $.extend( context.fn, { t = nextT; } }, + 'saveCursorAndScrollTop': function() { + // Stub out textarea behavior + return; + }, + 'restoreCursorAndScrollTop': function() { + // Stub out textarea behavior + return; + }, 'saveSelection': function() { - if ( !$.browser.msie ) { - // Only IE needs this - return; - } - if ( typeof context.$iframe != 'undefined' ) { + if ( $.client.name === 'msie' ) { context.$iframe[0].contentWindow.focus(); context.savedSelection = context.$iframe[0].contentWindow.document.selection.createRange(); - } else { - context.$textarea.focus(); - context.savedSelection = document.selection.createRange(); } }, 'restoreSelection': function() { - if ( !$.browser.msie || context.savedSelection === null ) { - return; - } - if ( typeof context.$iframe != 'undefined' ) { + if ( $.client.name === 'msie' && context.savedSelection !== null ) { context.$iframe[0].contentWindow.focus(); - } else { - context.$textarea.focus(); + context.savedSelection.select(); + context.savedSelection = null; } - context.savedSelection.select(); - context.savedSelection = null; }, /** * Update the history queue diff --git a/modules/jquery.wikiEditor.js b/modules/jquery.wikiEditor.js index 1a2105e0..cf5dd19d 100644 --- a/modules/jquery.wikiEditor.js +++ b/modules/jquery.wikiEditor.js @@ -488,32 +488,49 @@ if ( !context || typeof context == 'undefined' ) { .appendTo( context.$ui ); }, /** - * Save scrollTop and cursor position for IE. + * 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 ); + 'saveCursorAndScrollTop': function() { + if ( $.client.name === 'msie' ) { + 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. + * 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 ); - } + 'restoreCursorAndScrollTop': function() { + if ( $.client.name === 'msie' ) { + var IHateIE = context.$textarea.data( 'IHateIE' ); + if ( IHateIE ) { + context.$textarea.scrollTop( IHateIE.scrollTop ); + context.$textarea.textSelection( 'setSelection', { start: IHateIE.pos[0], end: IHateIE.pos[1] } ); + context.$textarea.data( 'IHateIE', null ); + } + } + }, + /** + * Save text selection for IE + */ + 'saveSelection': function() { + if ( $.client.name === 'msie' ) { + context.$textarea.focus(); + context.savedSelection = document.selection.createRange(); + } + }, + /** + * Restore text selection for IE + */ + 'restoreSelection': function() { + if ( $.client.name === 'msie' && context.savedSelection !== null ) { + context.$textarea.focus(); + context.savedSelection.select(); + context.savedSelection = null; + } + }, }; /* diff --git a/modules/jquery.wikiEditor.toolbar.js b/modules/jquery.wikiEditor.toolbar.js index da534047..f896fc8d 100644 --- a/modules/jquery.wikiEditor.toolbar.js +++ b/modules/jquery.wikiEditor.toolbar.js @@ -111,7 +111,7 @@ api : { .append( $( $.wikiEditor.modules.toolbar.fn.buildCharacter( data[type][character], actions ) ) .mousedown( function( e ) { - context.fn.saveStuffForIE(); + context.fn.saveCursorAndScrollTop(); // No dragging! e.preventDefault(); return false; @@ -350,7 +350,7 @@ fn: { .data( 'action', tool.action ) .data( 'context', context ) .mousedown( function( e ) { - context.fn.saveStuffForIE(); + context.fn.saveCursorAndScrollTop(); // No dragging! e.preventDefault(); return false; @@ -376,7 +376,7 @@ fn: { .data( 'action', tool.list[option].action ) .data( 'context', context ) .mousedown( function( e ) { - context.fn.saveStuffForIE(); + context.fn.saveCursorAndScrollTop(); // No dragging! e.preventDefault(); return false; @@ -493,7 +493,7 @@ fn: { .html( html ) .children() .mousedown( function( e ) { - context.fn.saveStuffForIE(); + context.fn.saveCursorAndScrollTop(); // No dragging! e.preventDefault(); return false;