From fb20dff897e244735cd882f6011931f8756eefd4 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Sun, 17 May 2009 19:04:05 +0000 Subject: [PATCH] (bug 18342) insertTags works in edit summary box now (patch contributed by Ahmad Sherif) --- RELEASE-NOTES | 1 + skins/common/edit.js | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 8be866e102..de6187b536 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -52,6 +52,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * New hook: MessageNotInMwNs to handle localised messages that aren't in the Mediawiki Namespace, before checking the message files * (bug 18466) Add note or warning when overruling a move (semi-)protection +* (bug 18342) insertTags works in edit summary box === Bug fixes in 1.16 === diff --git a/skins/common/edit.js b/skins/common/edit.js index 945059e07b..94c24a259b 100644 --- a/skins/common/edit.js +++ b/skins/common/edit.js @@ -1,3 +1,5 @@ +var currentFocused; + // this function generates the actual toolbar buttons with localized text // we use it to avoid creating the toolbar where javascript is not enabled function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText, imageId) { @@ -62,7 +64,7 @@ function mwSetupToolbar() { function insertTags(tagOpen, tagClose, sampleText) { var txtarea; if (document.editform) { - txtarea = document.editform.wpTextbox1; + txtarea = currentFocused; } else { // some alternate form? take the first one we can find var areas = document.getElementsByTagName('textarea'); @@ -77,7 +79,7 @@ function insertTags(tagOpen, tagClose, sampleText) { var winScroll = document.documentElement.scrollTop else if (document.body) var winScroll = document.body.scrollTop; - //get current selection + //get current selection txtarea.focus(); var range = document.selection.createRange(); selText = range.text; @@ -88,10 +90,10 @@ function insertTags(tagOpen, tagClose, sampleText) { if (isSample && range.moveStart) { if (window.opera) tagClose = tagClose.replace(/\n/g,''); - range.moveStart('character', - tagClose.length - selText.length); - range.moveEnd('character', - tagClose.length); + range.moveStart('character', - tagClose.length - selText.length); + range.moveEnd('character', - tagClose.length); } - range.select(); + range.select(); //restore window scroll position if (document.documentElement && document.documentElement.scrollTop) document.documentElement.scrollTop = winScroll @@ -122,7 +124,7 @@ function insertTags(tagOpen, tagClose, sampleText) { } //restore textarea scroll position txtarea.scrollTop = textScroll; - } + } function checkSelectedText(){ if (!selText) { @@ -131,7 +133,7 @@ function insertTags(tagOpen, tagClose, sampleText) { } else if (selText.charAt(selText.length - 1) == ' ') { //exclude ending space char selText = selText.substring(0, selText.length - 1); tagClose += ' ' - } + } } } @@ -148,9 +150,17 @@ function scrollEditBox() { if( scrollTop.value ) editBox.scrollTop = scrollTop.value; addHandler( editForm, 'submit', function() { - document.getElementById( 'wpScrolltop' ).value = document.getElementById( 'wpTextbox1' ).scrollTop; + document.getElementById( 'wpScrolltop' ).value = document.getElementById( 'wpTextbox1' ).scrollTop; } ); } } hookEvent( 'load', scrollEditBox ); hookEvent( 'load', mwSetupToolbar ); +hookEvent( 'load', function() { + if ( document.editform ) { + currentFocused = document.editform.wpTextbox1; + document.editform.wpTextbox1.onfocus = function() { currentFocused = document.editform.wpTextbox1; }; + document.editform.wpSummary.onfocus = function() { currentFocused = document.editform.wpSummary; }; + } +} ); + -- 2.20.1