From 15bb2b2d180c23205abc428520ee02a267e413bd Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Wed, 16 Feb 2011 23:05:38 +0000 Subject: [PATCH] (Bug #27447) Added option to toolbar-item to switch off text-selection Carsten Nielsen explains: A client of mine was a bit annoyed by the editor: Every time he inserted - lets say - an image, the default contents of the image-fields "thumbs|width|caption...." were automatically marked/selected. So with a tip on the keyboard all "helping" text was gone. I added an option to the toolbar-items to optional deactivate this behaviour. --- includes/EditPage.php | 1 + skins/common/edit.js | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 9db10d76e8..fb0a3f82d8 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2387,6 +2387,7 @@ HTML $close = $tool['close'], $sample = $tool['sample'], $cssId = $tool['id'], + $select = $tool['select'], ); $paramList = implode( ',', diff --git a/skins/common/edit.js b/skins/common/edit.js index f986c854b0..dd5d13046a 100644 --- a/skins/common/edit.js +++ b/skins/common/edit.js @@ -1,7 +1,7 @@ window.currentFocused = undefined; // this function adds a toolbar button to the mwEditButtons list -window.addButton = function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId ) { +window.addButton = function( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId, selectText ) { // Don't generate buttons for browsers which don't fully // support it. mwEditButtons.push({ @@ -10,7 +10,8 @@ window.addButton = function( imageFile, speedTip, tagOpen, tagClose, sampleText, 'speedTip': speedTip, 'tagOpen': tagOpen, 'tagClose': tagClose, - 'sampleText': sampleText + 'sampleText': sampleText, + 'selectText': selectText }); }; @@ -29,7 +30,7 @@ window.mwInsertEditButton = function( parent, item ) { image.title = item.speedTip; image.style.cursor = 'pointer'; image.onclick = function() { - insertTags( item.tagOpen, item.tagClose, item.sampleText ); + insertTags( item.tagOpen, item.tagClose, item.sampleText, item.selectText ); // click tracking if ( ( typeof $ != 'undefined' ) && ( typeof $.trackAction != 'undefined' ) ) { $.trackAction( 'oldedit.' + item.speedTip.replace(/ /g, "-") ); @@ -77,7 +78,7 @@ window.mwSetupToolbar = function() { // apply tagOpen/tagClose to selection in textarea, // use sampleText instead of selection if there is none -window.insertTags = function( tagOpen, tagClose, sampleText ) { +window.insertTags = function( tagOpen, tagClose, sampleText, selectText) { if ( typeof $ != 'undefined' && typeof $.fn.textSelection != 'undefined' && currentFocused && ( currentFocused.nodeName.toLowerCase() == 'iframe' || currentFocused.id == 'wpTextbox1' ) ) { $( '#wpTextbox1' ).textSelection( @@ -109,15 +110,17 @@ window.insertTags = function( tagOpen, tagClose, sampleText ) { // insert tags checkSelectedText(); range.text = tagOpen + selText + tagClose; - // mark sample text as selected - if ( isSample && range.moveStart ) { - if ( window.opera ) { - tagClose = tagClose.replace(/\n/g,''); + // mark sample text as selected if not switched off by option + if ( selectText !== false ) { + 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; @@ -139,7 +142,7 @@ window.insertTags = function( tagOpen, tagClose, sampleText ) { + tagOpen + selText + tagClose + txtarea.value.substring(endPos, txtarea.value.length); // set new selection - if ( isSample ) { + if ( isSample && ( selectText !== false )) { txtarea.selectionStart = startPos + tagOpen.length; txtarea.selectionEnd = startPos + tagOpen.length + selText.length; } else { -- 2.20.1