From 4727fbc2da9b1a7ea8e3f030c9f470c1e5e31977 Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Tue, 9 Feb 2010 01:31:00 +0000 Subject: [PATCH] Updated to use the textSelection plugin when possible. --- skins/common/edit.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/skins/common/edit.js b/skins/common/edit.js index e39d35b151..c2d1e2173a 100644 --- a/skins/common/edit.js +++ b/skins/common/edit.js @@ -57,11 +57,15 @@ function mwSetupToolbar() { // No toolbar if we can't find any textarea return false; } - if ( !( document.selection && document.selection.createRange ) - && textboxes[0].selectionStart === null ) { - return false; + // Only check for selection capability if the textarea is visible - errors will occur otherwise - just because + // the textarea is not visible, doesn't mean we shouldn't build out the toolbar though - it might have been replaced + // with some other kind of control + if ( textboxes[0].style.display != 'none' ) { + if ( !( document.selection && document.selection.createRange ) + && textboxes[0].selectionStart === null ) { + return false; + } } - for ( var i = 0; i < mwEditButtons.length; i++ ) { mwInsertEditButton( toolbar, mwEditButtons[i] ); } @@ -74,6 +78,12 @@ 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.fn.textSelection != 'undefined' ) { + $j( '#wpTextbox1' ).textSelection( + 'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose } + ); + return; + } var txtarea; if ( document.editform ) { txtarea = currentFocused; -- 2.20.1