* 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.
This commit is contained in:
Trevor Parscal 2010-10-05 20:54:38 +00:00
parent 3fbe9b3ce7
commit 49eb154f2c
4 changed files with 61 additions and 48 deletions

View file

@ -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();

View file

@ -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

View file

@ -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;
}
},
};
/*

View file

@ -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;