From aa69029e2727e3b6e747ab98aaa5482125cc7fce Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Wed, 10 Feb 2010 13:19:21 +0000 Subject: [PATCH] Some tweaks to edit.js to make currentFocused detection work in IE (was completely broken) and with the usability iframe. Will backport a simplified version to wmf-deployment shortly. --- includes/DefaultSettings.php | 2 +- skins/common/edit.js | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 79ec6b9c4b..2c964dbc1b 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1686,7 +1686,7 @@ $wgCacheEpoch = '20030516000000'; * to ensure that client-side caches do not keep obsolete copies of global * styles. */ -$wgStyleVersion = '266'; +$wgStyleVersion = '267'; # Server-side caching: diff --git a/skins/common/edit.js b/skins/common/edit.js index 8001164a88..423205f8f7 100644 --- a/skins/common/edit.js +++ b/skins/common/edit.js @@ -78,7 +78,8 @@ function mwSetupToolbar() { // apply tagOpen/tagClose to selection in textarea, // use sampleText instead of selection if there is none function insertTags( tagOpen, tagClose, sampleText ) { - if ( typeof $j != 'undefined' && typeof $j.fn.textSelection != 'undefined' ) { + if ( typeof $j != 'undefined' && typeof $j.fn.textSelection != 'undefined' && + ( currentFocused.nodeName.toLowerCase() == 'iframe' || currentFocused.id == 'wpTextbox1' ) ) { $j( '#wpTextbox1' ).textSelection( 'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose } ); @@ -190,16 +191,16 @@ hookEvent( 'load', function() { return; } function onfocus( e ) { - var elm = e.target; + var elm = e.target || e.srcElement; if ( !elm ) { return; } var tagName = elm.tagName.toLowerCase(); - var type = elm.type.toLowerCase(); + var type = elm.type || ''; if ( tagName !== 'textarea' && tagName !== 'input' ) { return; } - if ( tagName === 'input' && type && type !== 'text' ) { + if ( tagName === 'input' && type.toLowerCase() !== 'text' ) { return; } @@ -213,6 +214,17 @@ hookEvent( 'load', function() { // IE needs a specific trick here since it doesn't support the standard editForm.attachEvent( 'onfocusin', function() { onfocus( event ); } ); } + + // HACK: make currentFocused work with the usability iframe + // With proper focus detection support (HTML 5!) this'll be much cleaner + if ( typeof $j != 'undefined' ) { + var iframe = $j( '.wikiEditor-ui-text iframe' ); + if ( iframe.length > 0 ) { + $j( iframe.get( 0 ).contentWindow.document ) + .add( iframe.get( 0 ).contentWindow.document.body ) // for IE + .focus( function() { currentFocused = iframe.get( 0 ); } ); + } + } editForm } ); -- 2.20.1