-var currentFocused;
+// This file is still referenced from
+// tests/selenium/data/SimpleSeleniumTestDB.sql
+// includes/specials/SpecialUpload.php
+// /extensions/SemanticForms/specials/SF_UploadWindow2.php
+window.currentFocused = undefined;
// this function adds a toolbar button to the mwEditButtons list
-function addButton( 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({
'speedTip': speedTip,
'tagOpen': tagOpen,
'tagClose': tagClose,
- 'sampleText': sampleText
+ 'sampleText': sampleText,
+ 'selectText': selectText
});
-}
+};
// this function adds one toolbar button from a mwEditButtons/mwCustomEditButtons item
-function mwInsertEditButton( parent, item ) {
+window.mwInsertEditButton = function( parent, item ) {
var image = document.createElement( 'img' );
image.width = 23;
image.height = 22;
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 $j != 'undefined' ) && ( typeof $j.trackAction != 'undefined' ) ) {
- $j.trackAction( 'oldedit.' + item.speedTip.replace(/ /g, "-") );
+ if ( ( typeof $ != 'undefined' ) && ( typeof $.trackAction != 'undefined' ) ) {
+ $.trackAction( 'oldedit.' + item.speedTip.replace(/ /g, '-') );
}
return false;
};
parent.appendChild( image );
return true;
-}
+};
// this function generates the actual toolbar buttons with localized text
// we use it to avoid creating the toolbar where javascript is not enabled
-function mwSetupToolbar() {
+window.mwSetupToolbar = function() {
var toolbar = document.getElementById( 'toolbar' );
+ var i = 0;
if ( !toolbar ) {
return false;
}
return false;
}
}
- for ( var i = 0; i < mwEditButtons.length; i++ ) {
+ for ( i = 0; i < mwEditButtons.length; i++ ) {
mwInsertEditButton( toolbar, mwEditButtons[i] );
}
- for ( var i = 0; i < mwCustomEditButtons.length; i++ ) {
+ for ( i = 0; i < mwCustomEditButtons.length; i++ ) {
mwInsertEditButton( toolbar, mwCustomEditButtons[i] );
}
return true;
-}
+};
// 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' &&
+window.insertTags = function( tagOpen, tagClose, sampleText, selectText) {
+ if ( typeof $ != 'undefined' && typeof $.fn.textSelection != 'undefined' && currentFocused &&
( currentFocused.nodeName.toLowerCase() == 'iframe' || currentFocused.id == 'wpTextbox1' ) ) {
- $j( '#wpTextbox1' ).textSelection(
+ $( '#wpTextbox1' ).textSelection(
'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
);
return;
}
var selText, isSample = false;
+ function checkSelectedText() {
+ if ( !selText ) {
+ selText = sampleText;
+ isSample = true;
+ } else if ( selText.charAt(selText.length - 1) == ' ' ) { // exclude ending space char
+ selText = selText.substring(0, selText.length - 1);
+ tagClose += ' ';
+ }
+ }
+
if ( document.selection && document.selection.createRange ) { // IE/Opera
// save window scroll position
+ var winScroll = null;
if ( document.documentElement && document.documentElement.scrollTop ) {
- var winScroll = document.documentElement.scrollTop
+ winScroll = document.documentElement.scrollTop;
} else if ( document.body ) {
- var winScroll = document.body.scrollTop;
+ winScroll = document.body.scrollTop;
}
// get current selection
txtarea.focus();
// 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;
+ 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 {
txtarea.scrollTop = textScroll;
}
- function checkSelectedText() {
- if ( !selText ) {
- selText = sampleText;
- isSample = true;
- } else if ( selText.charAt(selText.length - 1) == ' ' ) { // exclude ending space char
- selText = selText.substring(0, selText.length - 1);
- tagClose += ' ';
- }
- }
-
-}
+};
/**
* Restore the edit box scroll state following a preview operation,
* and set up a form submission handler to remember this state
*/
-function scrollEditBox() {
+window.scrollEditBox = function() {
var editBox = document.getElementById( 'wpTextbox1' );
var scrollTop = document.getElementById( 'wpScrolltop' );
var editForm = document.getElementById( 'editform' );
scrollTop.value = editBox.scrollTop;
} );
}
-}
+};
hookEvent( 'load', scrollEditBox );
hookEvent( 'load', mwSetupToolbar );
hookEvent( 'load', function() {
// 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 ( typeof $ != 'undefined' ) {
+ var iframe = $( '.wikiEditor-ui-text iframe' );
if ( iframe.length > 0 ) {
- $j( iframe.get( 0 ).contentWindow.document )
+ $( iframe.get( 0 ).contentWindow.document )
.add( iframe.get( 0 ).contentWindow.document.body ) // for IE
.focus( function() { currentFocused = iframe.get( 0 ); } );
}
}
- editForm
-} );
-
-//make sure edit summary does not exceed byte limit
-addOnloadHook(function () {
- var summary = document.getElementById( 'wpSummary' );
- if ( !summary ) {
- return;
- }
- summary.maxLength = 250; //L must be capitalized in length.
-
- checkSummary = function (e) {
- if (!e) e = window.event; //IE
-
- //first check to see if this is actually a character key
- // being pressed.
- //Based on key-event info from http://unixpapa.com/js/key.html
- //note === sign, if undefined, still could be a real key
-
- if (e.which === 0 || e.charCode === 0 || e.ctrlKey || e.altKey || e.metaKey) {
- return true; //a special key (backspace, etc) so don't interefere.
- }
-
- //This basically figures out how many bytes a utf-16 string (which is what js sees) will take in utf-8
- //by replacing a 2 byte character with 2 *'s, etc, and counting that.
- //Note, surogate (\uD800-\uDFFF) characters are counted as 2 bytes, since theres two of them
- //and the actual character takes 4 bytes in utf-8 (2*2=4). might not work perfectly in edge cases such as
- //such as illegal sequences, but that should never happen.
-
- len = summary.value.replace(/[\u0080-\u07FF\uD800-\uDFFF]/g, '**').replace(/[\u0800-\uD7FF\uE000-\uFFFF]/g, '***').length;
- //247 as this doesn't count character about to be inserted.
- if (len > 247) {
- if (e.preventDefault) e.preventDefault();
- e.returnValue = false; //IE
- return false;
- }
- }
-
- addHandler(summary, 'keypress', checkSummary);
-});
-
+} );
\ No newline at end of file