MediaWiki:Gadget-charinsert.js: Difference between revisions

Update for mediawiki-1.24.1
m (minor tweaks)
(Update for mediawiki-1.24.1)
Line 1: Line 1:
// copied from [[mw:User:Alex Smotrov/edittools.js]], modified for use on the [[English Wikipedia]].
/**
// enableForAllFields() feature from [[commons:MediaWiki:Edittools.js]]
* Copied from [[mw:User:Alex Smotrov/edittools.js]], modified for use on the English Wikipedia.
// combined and modified by [[User:Ilmari Karonen]]
* enableForAllFields() feature from [[commons:MediaWiki:Edittools.js]]
 
* combined and modified by [[User:Ilmari Karonen]]
// Configuration (to be set from [[Special:MyPage/common.js]]):
*
//   window.charinsertCustom – Object. Merged into the default charinsert list. For example, setting
* Configuration (to be set from [[Special:MyPage/common.js]]):
//       this to { Symbols: '‽' } will add the interrobang to the end of the Symbols section.
*   window.charinsertCustom – Object. Merged into the default charinsert list. For example, setting
//   window.editToolsRecall – Boolean. Set true to create a recall switch.
*       this to { Symbols: '‽' } will add the interrobang to the end of the Symbols section.
//   window.charinsertDontMove – Boolean. Set true to leave the box in its default position, rather
*   window.editToolsRecall – Boolean. Set true to create a recall switch.
//       than moving it above the edit summary.
*   window.charinsertDontMove – Boolean. Set true to leave the box in its default position, rather
//   window.updateEditTools() – Function. Call after updating window.charinsertCustom to regenerate the
*       than moving it above the edit summary.
//       EditTools window.
*   window.updateEditTools() – Function. Call after updating window.charinsertCustom to regenerate the
 
*       EditTools window.
*/
/* global jQuery, mw, charinsertCustom */


window.updateEditTools = function () {
window.updateEditTools = function () {
Line 72: Line 74:
                     sel.selectedIndex = prevSubset;
                     sel.selectedIndex = prevSubset;
                     selectSubset();
                     selectSubset();
                 }
                 };
                 with ( recall.style ) {
                 with ( recall.style ) {
                     cssFloat = styleFloat = 'left';
                     cssFloat = styleFloat = 'left';
Line 118: Line 120:
                 if ( !p ) {
                 if ( !p ) {
                     p = document.createElement( 'p' );
                     p = document.createElement( 'p' );
                    p.className = "nowraplinks";
                     p.id = id;
                     p.id = id;
                     if ( id == 'Arabic' || id == 'Hebrew' ) {
                     if ( id == 'Arabic' || id == 'Hebrew' ) {
Line 177: Line 180:
                     var path = tagOpen.substring( dle + 1 ).split( '.' );
                     var path = tagOpen.substring( dle + 1 ).split( '.' );
                     tagOpen = tagOpen.substring( 0, dle );
                     tagOpen = tagOpen.substring( 0, dle );
                     var handler = window;
                     handler = window;
                     for ( var i = 0; i < path.length; i++ ) {
                     for ( var i = 0; i < path.length; i++ ) {
                         handler = handler[path[i]];
                         handler = handler[path[i]];
Line 186: Line 189:
                     handler = new Function(
                     handler = new Function(
                         "evt",
                         "evt",
                         "insertTags('" + tagOpen + "', '" + tagClose + "', ''); return killEvt( evt );"
                         "mw.toolbar.insertTags('" + tagOpen + "', '" + tagClose + "', ''); evt.preventDefault(); return false;"
                     );
                     );
                 }
                 }
Line 194: Line 197:
                 a.appendChild( document.createTextNode( name ) );
                 a.appendChild( document.createTextNode( name ) );
                 a.href = "#";
                 a.href = "#";
                 addHandler( a, 'click', handler );
                 $( a ).click( handler );
                 paragraph.appendChild( a );
                 paragraph.appendChild( a );
                 addText( ' ' );
                 addText( ' ' );
Line 211: Line 214:


         enableForAllFields: function () {
         enableForAllFields: function () {
             if ( typeof( insertTags ) != 'function' || window.WikEdInsertTags ) {
             if ( typeof( mw.toolbar.insertTags ) != 'function' || window.WikEdInsertTags ) {
                 return;
                 return;
             }
             }
Line 224: Line 227:
             var texts = document.getElementsByTagName( 'textarea' );
             var texts = document.getElementsByTagName( 'textarea' );
             for ( var i = 0; i < texts.length; i++ ) {
             for ( var i = 0; i < texts.length; i++ ) {
                 addHandler( texts[i], 'focus', EditTools.registerTextField );
                 $( texts[i] ).focus( EditTools.registerTextField );
             }
             }
             // While we're at it, also enable it for input fields
             // While we're at it, also enable it for input fields
Line 230: Line 233:
             for ( var i = 0; i < texts.length; i++ ) {
             for ( var i = 0; i < texts.length; i++ ) {
                 if ( texts[i].type == 'text' ) {
                 if ( texts[i].type == 'text' ) {
                     addHandler( texts[i], 'focus', EditTools.registerTextField );
                     $(texts[i]).focus( EditTools.registerTextField );
                 }
                 }
             }
             }
             insertTags = EditTools.insertTags; // Redefine the global insertTags
             mw.toolbar.insertTags = EditTools.insertTags; // Redefine the global insertTags
         },
         },


Line 276: Line 279:


             /* Usability initiative compatibility */
             /* Usability initiative compatibility */
             if ( typeof $j != 'undefined' && typeof $j.fn.textSelection != 'undefined' ) {
             if ( typeof $jQuery != 'undefined' && typeof $jQuery.fn.textSelection != 'undefined' ) {
                 $j( txtarea ).textSelection(
                 $jQuery( txtarea ).textSelection(
                     'encapsulateSelection',
                     'encapsulateSelection',
                     { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
                     { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
Line 353: Line 356:
         setup: function () {
         setup: function () {
             var placeholder;
             var placeholder;
             if ( $( '#editpage-specialchars' ).length ) {
             if ( $( '#mw-edittools-charinsert' ).length ) {
                placeholder = $( '#editpage-specialchars' )[0];
                placeholder = $( '#mw-edittools-charinsert' )[0];
            } else if ( $( '#editpage-specialchars' ).length ) {
              placeholder = $( '#editpage-specialchars' )[0];
             } else {
             } else {
                 placeholder = $( '<div id="editpage-specialchars"> </div>' ).prependTo( '.mw-editTools' )[0];
                 placeholder = $( '<div id="editpage-specialchars"> </div>' ).prependTo( '.mw-editTools' )[0];
Line 361: Line 366:
                 return;
                 return;
             }
             }
            EditTools.createEditTools( placeholder );
            EditTools.enableForAllFields();
            placeholder = $( '#editpage-specialchars' )[0];
             if ( !window.charinsertDontMove ) {
             if ( !window.charinsertDontMove ) {
                 $( '.editOptions' ).before( placeholder );
                 $( '.editOptions' ).before( placeholder );
             }
             }
            EditTools.createEditTools( placeholder );
            EditTools.enableForAllFields();
             window.updateEditTools = function () {
             window.updateEditTools = function () {
                 EditTools.createEditTools( $( '#editpage-specialchars' )[0] );
                 EditTools.createEditTools( $( '#editpage-specialchars' )[0] );