Sarna News: Bad 'Mechs - Icestorm

Difference between revisions of "MediaWiki:Common.js/edit.js"

m
(moved wiki button images to regular dir on webserver)
 
(47 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on all edit pages. */
 
/* Any JavaScript here will be loaded for all users on all edit pages. */
 
//<source lang="javascript">
 
//<source lang="javascript">
+
 
 +
/******** GLOBAL VARIABLES ********/
 +
/*** Symbol information list ***/
 +
var symbols = new Array();
 +
symbols["id"] = "symbols_box";
 +
symbols["header"] = "Insert a character";
 +
symbols["sections"] = new Array();
 +
 
 +
symbols["sections"]["nonstandard"] = new Array();
 +
symbols["sections"]["nonstandard"]["title"] = "Symbols";
 +
symbols["sections"]["nonstandard"]["items"] = new Array("–", "—", " ", "¡", "¿", "†", "‡", "§", "Ø", "ø", " ", "·", "…", " ", "←", "→", "↑", "↓", " ", "½", "⅓", "⅔", "¼", "¾", "⅛", "⅜", "⅝", "⅞");
 +
 
 +
symbols["sections"]["vowels"] = new Array();
 +
symbols["sections"]["vowels"]["title"] = "Vowels"
 +
symbols["sections"]["vowels"]["items"] = new Array("Á", "á", "À", "à", "Ã", "ã", " ", "É", "é", "È", "è", "Ẽ", "ẽ", " ", "Í", "í", "Ì", "ì", "Ĩ", "ĩ", " ", "Ó", "ó", "Ò", "ò", "Õ", "õ", " ", "Ú", "ú", "Ù", "ù", "Ũ", "ũ");
 +
 
 +
symbols["sections"]["consonants"] = new Array();
 +
symbols["sections"]["consonants"]["title"] = "Consonants"
 +
symbols["sections"]["consonants"]["items"] = new Array("Ć", "ć", "Ç", "ç", " ", "Ģ", "ģ", " ", "Ķ", "ķ", " ", "Ĺ", "ĺ", "Ļ", "ļ", " ", "Ń", "ń", "Ñ", "ñ", "Ņ", "ņ", " ", "Ŕ", "ŕ", "Ŗ", "ŗ", " ", "Ś", "ś", "Ş", "ş", " ", "Ţ", "ţ", " ", "Ý", "ý", "Ỹ", "ỹ", " ", "Ź", "ź", " ", "ß", "Đ", "đ");
 +
 
 +
/*** Template information list ***/
 +
var templates = new Array();
 +
templates["id"] = "templates_box";
 +
templates["header"] = "Insert a template";
 +
templates["sections"] = new Array();
 +
 
 +
templates["sections"]["stubs"] = new Array();
 +
templates["sections"]["stubs"]["title"] = "Stubs";
 +
templates["sections"]["stubs"]["items"] = new Array("{{Stub}}", "{{Sectionstub}}");
 +
 
 +
templates["sections"]["notices"] = new Array();
 +
templates["sections"]["notices"]["title"] = "Notices";
 +
templates["sections"]["notices"]["items"] = new Array("{{Citation needed}}", "{{Refimprove}}", "{{Update Needed}}", "{{Cleanup}}", "{{Verify}}", "{{NonCanon}}");
 +
 
 +
templates["sections"]["misc"] = new Array();
 +
templates["sections"]["misc"]["title"] = "Miscellaneous";
 +
templates["sections"]["misc"]["items"] = new Array("{{Disambig}}", "{{Emoticon| :) }}", "{{Quote|Write quote here}}", "{{Yearlist}}", "|{{PAGENAME}}");
 +
 
 +
 
 
/***********************************************************
 
/***********************************************************
  * Extra toolbar options
+
  * Extra toolbar options
 
  *
 
  *
  * Description: Adds extra buttons to the editing toolbar.
+
  * Description: Adds extra buttons to the editing toolbar.
 
  ***********************************************************/
 
  ***********************************************************/
 
if (mwCustomEditButtons) {
 
if (mwCustomEditButtons) {
 
     mwCustomEditButtons.push({
 
     mwCustomEditButtons.push({
         "imageFile": "http://sarna.net/wiki/images/c/c8/Button_redirect.png",
+
         "imageId": "mw-editbutton-br",
        "speedTip": "Redirect",
+
         "imageFile": "http://www.sarna.net/images/Button_enter.png",
        "tagOpen": "#REDIRECT[[",
 
        "tagClose": "]]",
 
        "sampleText": "Target page name"
 
    });
 
 
    mwCustomEditButtons.push({
 
         "imageFile": "http://sarna.net/wiki/images/1/13/Button_enter.png",
 
 
         "speedTip": "Line break",
 
         "speedTip": "Line break",
 
         "tagOpen": "<br />",
 
         "tagOpen": "<br />",
Line 25: Line 56:
 
   
 
   
 
     mwCustomEditButtons.push({
 
     mwCustomEditButtons.push({
         "imageFile": "http://sarna.net/wiki/images/6/6a/Button_sup_letter.png",
+
         "imageFile": "http://www.sarna.net/images/Button_sup_letter.png",
 
         "speedTip": "Superscript",
 
         "speedTip": "Superscript",
 
         "tagOpen": "<sup>",
 
         "tagOpen": "<sup>",
Line 33: Line 64:
 
   
 
   
 
     mwCustomEditButtons.push({
 
     mwCustomEditButtons.push({
         "imageFile": "http://sarna.net/wiki/images/a/aa/Button_sub_letter.png",
+
         "imageFile": "http://www.sarna.net/images/Button_sub_letter.png",
 
         "speedTip": "Subscript",
 
         "speedTip": "Subscript",
 
         "tagOpen": "<sub>",
 
         "tagOpen": "<sub>",
Line 41: Line 72:
 
   
 
   
 
     mwCustomEditButtons.push({
 
     mwCustomEditButtons.push({
         "imageFile": "http://sarna.net/wiki/images/1/17/Button_small_2.png",
+
         "imageFile": "http://www.sarna.net/images/Button_small_2.png",
 
         "speedTip": "Small text",
 
         "speedTip": "Small text",
 
         "tagOpen": "<small>",
 
         "tagOpen": "<small>",
 
         "tagClose": "</small>",
 
         "tagClose": "</small>",
 
         "sampleText": "Small text"
 
         "sampleText": "Small text"
 +
    });
 +
 +
    mwCustomEditButtons.push({
 +
        "imageFile": "http://www.sarna.net/images/Button_redirect.png",
 +
        "speedTip": "Redirect",
 +
        "tagOpen": "#REDIRECT[[",
 +
        "tagClose": "]]",
 +
        "sampleText": "Target page name"
 
     });
 
     });
 
   
 
   
 
     mwCustomEditButtons.push({
 
     mwCustomEditButtons.push({
         "imageFile": "http://sarna.net/wiki/images/1/12/Button_gallery.png",
+
         "imageFile": "http://www.sarna.net/images/Button_gallery.png",
 
         "speedTip": "Insert a picture gallery",
 
         "speedTip": "Insert a picture gallery",
 
         "tagOpen": "\n<gallery>\n",
 
         "tagOpen": "\n<gallery>\n",
Line 57: Line 96:
 
   
 
   
 
     mwCustomEditButtons.push({
 
     mwCustomEditButtons.push({
         "imageFile": "http://sarna.net/wiki/images/6/60/Button_insert_table.png",
+
         "imageFile": "http://www.sarna.net/images/Button_insert_table.png",
 
         "speedTip": "Insert a table",
 
         "speedTip": "Insert a table",
 
         "tagOpen": '{| class="wikitable" border="1"\n|',
 
         "tagOpen": '{| class="wikitable" border="1"\n|',
Line 63: Line 102:
 
         "sampleText": "-\n! header 1\n! header 2\n! header 3\n|-\n| row 1, cell 1\n| row 1, cell 2\n| row 1, cell 3\n|-\n| row 2, cell 1\n| row 2, cell 2\n| row 2, cell 3"
 
         "sampleText": "-\n! header 1\n! header 2\n! header 3\n|-\n| row 1, cell 1\n| row 1, cell 2\n| row 1, cell 3\n|-\n| row 2, cell 1\n| row 2, cell 2\n| row 2, cell 3"
 
     });
 
     });
+
 
 
     mwCustomEditButtons.push({
 
     mwCustomEditButtons.push({
         "imageFile": "http://sarna.net/wiki/images/7/79/Button_reflink.png",
+
        "imageId": "mw-editbutton-ref",
         "speedTip": "Insert a reference",
+
         "imageFile": "http://www.sarna.net/images/Button_reflink.png",
 +
         "speedTip": "Insert a reference (requires a reference footer)",
 
         "tagOpen": "<ref>",
 
         "tagOpen": "<ref>",
 
         "tagClose": "</ref>",
 
         "tagClose": "</ref>",
Line 72: Line 112:
 
     });
 
     });
  
     if (isTesting) {
+
    mwCustomEditButtons.push({
         addOnloadHook(insertToolbarMenus);
+
        "imageId": "mw-editbutton-references",
 +
        "imageFile": "http://www.sarna.net/images/Button_referencesR.png",
 +
        "speedTip": "Insert the reference footer",
 +
        "tagOpen": "<references />",
 +
        "tagClose": "",
 +
        "sampleText": ""
 +
    });
 +
 
 +
     if (window.jQuery) {  
 +
        var menus = new Array(symbols, templates);
 +
 
 +
         addOnloadHook(function(){
 +
            insertToolbarExtras(menus);
 +
        });
 
     }
 
     }
 
}
 
}
  
 +
/******************************************************
 +
* insertToolbarExtras()
 +
*
 +
* Description: Creates a <div> placed above the edit
 +
*  form and fills it with toolbar menus.
 +
*  Requires jQuery JavaScript library.
 +
*
 +
* @author  ebakunin
 +
* @param  menus (array)
 +
******************************************************/
 +
function insertToolbarExtras(menus)
 +
{
 +
    var code = '<div id="toolbar-menu-header">';
 +
    for (var i=0; i < menus.length; i++) {
 +
        code += insertToolbarHeader(menus[i]);
 +
    }
 +
    code += '</div>';
  
var symbols = new Array();
+
    for (var i=0; i < menus.length; i++) {
symbols["text"] = "Insert a symbol";
+
        code += insertToolbarMenu(menus[i]);
 +
    }
  
symbols["nonstandard"] = new Array();
+
    jQuery("#editform").prepend(code);
symbols["nonstandard"]["vowels"] = new Array();
+
}
symbols["nonstandard"]["vowels"]["title"] = "Vowels: "
 
symbols["nonstandard"]["vowels"]["items"] = new Array("Á", "á", "À", "à", "Ã", "ã", "É", "é", "È", "è", "Ẽ", "ẽ", "Í", "í", "Ì", "ì", "Ĩ", "ĩ", "Ó", "ó", "Ò", "ò", "Õ", "õ", "Ú", "ú", "Ù", "ù", "Ũ", "ũ");
 
  
symbols["sections"] = new Array();
+
/*********************************************************
symbols["sections"]["vowels"] = new Array();
+
* insertToolbarHeader()
symbols["sections"]["vowels"]["title"] = "Vowels: "
+
*
symbols["sections"]["vowels"]["items"] = new Array("Á", "á", "À", "à", "Ã", "ã", "É", "é", "È", "è", "Ẽ", "ẽ", "Í", "í", "Ì", "ì", "Ĩ", "ĩ", "Ó", "ó", "Ò", "ò", "Õ", "õ", "Ú", "ú", "Ù", "ù", "Ũ", "ũ");
+
* Description: Inserts the name of the toolbar extra
 +
*  section. Clicking on the header shows/hides the
 +
*  related section. Requires jQuery JavaScript library.
 +
*
 +
* @author  ebakunin
 +
* @param  menu (array)
 +
*********************************************************/
 +
function insertToolbarHeader(menu)
 +
{
 +
    return "<span onclick=\"jQuery('#" + menu['id'] + "').slideToggle('fast')\">" + menu['header'] + "</span>";
 +
}
  
symbols["sections"]["consonants"] = new Array();
+
/****************************************************
symbols["sections"]["consonants"]["title"] = "Consonants: "
+
* insertToolbarMenu()
symbols["sections"]["consonants"]["items"] = new Array("Ć", "ć", "Ç", "ç", "Ģ", "ģ", "Ķ", "ķ", "Ĺ", "ĺ", "Ļ", "ļ", "Ń", "ń", "Ñ", "ñ", "Ņ", "ņ", "Ŕ", "ŕ", "Ŗ", "ŗ", "Ś", "ś", "Ş", "ş", "Ţ", "ţ", "Ý", "ý", "Ỹ", "ỹ", "Ź", "ź", "ß", "Đ", "đ");
+
*
 
+
* Description: Creates a hidden <div> and fills it
 
+
*   with insertable characters.
var stubs = new Array("{{stub}}", "{{sectionstub}}");
+
  *   Requires jQuery JavaScript library.
var notices = new Array("{{Citation needed}}", "{{Update Needed}}", "{{Cleanup}}", "{{Verify}}", "{{NonCanon}}", "{{Moratorium}}");
 
var misc = new Array("{{disambig}}", "{{quote| }}", "{{yearlist}}", "{{otheruses| | | }}");
 
 
 
/***********************************************************
 
  * insertToolbarMenus()
 
 
  *
 
  *
  *  Description:
+
  * @author ebakunin
  ***********************************************************/
+
  * @param  list (array)
function insertToolbarMenus() {
+
****************************************************/
     var insert = '<div><strong>' + symbols['text'] + '<br />';
+
function insertToolbarMenu(list)
 +
{
 +
     var insert = '<div id="' + list["id"] + '" class="toolbar-menu">';
  
     for (var i in symbols['sections']) {
+
     for (var i in list['sections']) {
         insert += symbols['sections'][i]['title'] + ": ";
+
         insert += "<strong>" + list['sections'][i]['title'] + "</strong>: ";
  
         for (var j=0; j < symbols['sections'][i]['items'].length; j++) {
+
         for (var j=0; j < list['sections'][i]['items'].length; j++) {
             insert += wrapToolbarCharacter(symbols['sections'][i]['items'][j]);
+
             insert += wrapToolbarCharacter(list['sections'][i]['items'][j]);
 
         }
 
         }
         insert += "<hr />";
+
         insert += "<br />";
 
     }
 
     }
  
 
     insert += "</div>";
 
     insert += "</div>";
  
     $("#editform").prepend(insert);
+
     return insert;
};
+
}
  
/***********************************************************
+
/********************************************************
  * wrapToolbarCharacter()
+
* wrapToolbarCharacter()
 +
*
 +
* Description: Places an <a> tag around a character to
 +
  *   call insertTags() from the "CharInsert" extension.
 
  *
 
  *
  *  Description:
+
  * @author ebakunin
  ***********************************************************/
+
  * @param  char (string)
function wrapToolbarCharacter(char) {
+
********************************************************/
     return '<a title="Click on the character or tag to insert it into the edit window" href="javascript:insertTags(\'' + char + '\',\'\',\'\'); return false">' + char + '</a> &nbsp;';
+
function wrapToolbarCharacter(char)
};
+
{
 +
     return (char == " " || char == "&nbsp;")
 +
      ? ' &nbsp; '
 +
      : '<a title="Click on the character or tag to insert it into the edit window" href="javascript:insertTags(\'' + char + '\',\'\',\'\')">' + char + '</a> &nbsp;';
 +
}
  
 
//</source>
 
//</source>

Latest revision as of 23:57, 18 November 2010

/* Any JavaScript here will be loaded for all users on all edit pages. */
//<source lang="javascript">

/******** GLOBAL VARIABLES ********/
/*** Symbol information list ***/
var symbols = new Array();
symbols["id"] = "symbols_box";
symbols["header"] = "Insert a character";
symbols["sections"] = new Array();

symbols["sections"]["nonstandard"] = new Array();
symbols["sections"]["nonstandard"]["title"] = "Symbols";
symbols["sections"]["nonstandard"]["items"] = new Array("–", "—", " ", "¡", "¿", "†", "‡", "§", "Ø", "ø", " ", "·", "…", " ", "←", "→", "↑", "↓", " ", "½", "⅓", "⅔", "¼", "¾", "⅛", "⅜", "⅝", "⅞");

symbols["sections"]["vowels"] = new Array();
symbols["sections"]["vowels"]["title"] = "Vowels"
symbols["sections"]["vowels"]["items"] = new Array("Á", "á", "À", "à", "Ã", "ã", " ", "É", "é", "È", "è", "Ẽ", "ẽ", " ", "Í", "í", "Ì", "ì", "Ĩ", "ĩ", " ", "Ó", "ó", "Ò", "ò", "Õ", "õ", " ", "Ú", "ú", "Ù", "ù", "Ũ", "ũ");

symbols["sections"]["consonants"] = new Array();
symbols["sections"]["consonants"]["title"] = "Consonants"
symbols["sections"]["consonants"]["items"] = new Array("Ć", "ć", "Ç", "ç", " ", "Ģ", "ģ", " ", "Ķ", "ķ", " ", "Ĺ", "ĺ", "Ļ", "ļ", " ", "Ń", "ń", "Ñ", "ñ", "Ņ", "ņ", " ", "Ŕ", "ŕ", "Ŗ", "ŗ", " ", "Ś", "ś", "Ş", "ş", " ", "Ţ", "ţ", " ", "Ý", "ý", "Ỹ", "ỹ", " ", "Ź", "ź", " ", "ß", "Đ", "đ");

/*** Template information list ***/
var templates = new Array();
templates["id"] = "templates_box";
templates["header"] = "Insert a template";
templates["sections"] = new Array();

templates["sections"]["stubs"] = new Array();
templates["sections"]["stubs"]["title"] = "Stubs";
templates["sections"]["stubs"]["items"] = new Array("{{Stub}}", "{{Sectionstub}}");

templates["sections"]["notices"] = new Array();
templates["sections"]["notices"]["title"] = "Notices";
templates["sections"]["notices"]["items"] = new Array("{{Citation needed}}", "{{Refimprove}}", "{{Update Needed}}", "{{Cleanup}}", "{{Verify}}", "{{NonCanon}}");

templates["sections"]["misc"] = new Array();
templates["sections"]["misc"]["title"] = "Miscellaneous";
templates["sections"]["misc"]["items"] = new Array("{{Disambig}}", "{{Emoticon| :) }}", "{{Quote|Write quote here}}", "{{Yearlist}}", "|{{PAGENAME}}");


/***********************************************************
 * Extra toolbar options
 *
 * Description: Adds extra buttons to the editing toolbar.
 ***********************************************************/
if (mwCustomEditButtons) {
    mwCustomEditButtons.push({
        "imageId": "mw-editbutton-br",
        "imageFile": "http://www.sarna.net/images/Button_enter.png",
        "speedTip": "Line break",
        "tagOpen": "<br />",
        "tagClose": "",
        "sampleText": ""
    });
 
    mwCustomEditButtons.push({
        "imageFile": "http://www.sarna.net/images/Button_sup_letter.png",
        "speedTip": "Superscript",
        "tagOpen": "<sup>",
        "tagClose": "</sup>",
        "sampleText": "Superscript text"
    });
 
    mwCustomEditButtons.push({
        "imageFile": "http://www.sarna.net/images/Button_sub_letter.png",
        "speedTip": "Subscript",
        "tagOpen": "<sub>",
        "tagClose": "</sub>",
        "sampleText": "Subscript text"
    });
 
    mwCustomEditButtons.push({
        "imageFile": "http://www.sarna.net/images/Button_small_2.png",
        "speedTip": "Small text",
        "tagOpen": "<small>",
        "tagClose": "</small>",
        "sampleText": "Small text"
    });

    mwCustomEditButtons.push({
        "imageFile": "http://www.sarna.net/images/Button_redirect.png",
        "speedTip": "Redirect",
        "tagOpen": "#REDIRECT[[",
        "tagClose": "]]",
        "sampleText": "Target page name"
    });
 
    mwCustomEditButtons.push({
        "imageFile": "http://www.sarna.net/images/Button_gallery.png",
        "speedTip": "Insert a picture gallery",
        "tagOpen": "\n<gallery>\n",
        "tagClose": "\n</gallery>",
        "sampleText": "Image:Example.jpg|Caption1\nImage:Example.jpg|Caption2"
    });
 
    mwCustomEditButtons.push({
        "imageFile": "http://www.sarna.net/images/Button_insert_table.png",
        "speedTip": "Insert a table",
        "tagOpen": '{| class="wikitable" border="1"\n|',
        "tagClose": "\n|}",
        "sampleText": "-\n! header 1\n! header 2\n! header 3\n|-\n| row 1, cell 1\n| row 1, cell 2\n| row 1, cell 3\n|-\n| row 2, cell 1\n| row 2, cell 2\n| row 2, cell 3"
    });

    mwCustomEditButtons.push({
        "imageId": "mw-editbutton-ref",
        "imageFile": "http://www.sarna.net/images/Button_reflink.png",
        "speedTip": "Insert a reference (requires a reference footer)",
        "tagOpen": "<ref>",
        "tagClose": "</ref>",
        "sampleText": "Insert footnote text here"
    });

    mwCustomEditButtons.push({
        "imageId": "mw-editbutton-references",
        "imageFile": "http://www.sarna.net/images/Button_referencesR.png",
        "speedTip": "Insert the reference footer",
        "tagOpen": "<references />",
        "tagClose": "",
        "sampleText": ""
    });

    if (window.jQuery) { 
        var menus = new Array(symbols, templates);

        addOnloadHook(function(){
            insertToolbarExtras(menus);
        });
    }
}

/******************************************************
 * insertToolbarExtras()
 *
 * Description: Creates a <div> placed above the edit 
 *   form and fills it with toolbar menus.
 *   Requires jQuery JavaScript library.
 *
 * @author  ebakunin
 * @param   menus (array) 
 ******************************************************/
function insertToolbarExtras(menus)
{
    var code = '<div id="toolbar-menu-header">';
    for (var i=0; i < menus.length; i++) {
        code += insertToolbarHeader(menus[i]);
    }
    code += '</div>';

    for (var i=0; i < menus.length; i++) {
        code += insertToolbarMenu(menus[i]);
    }

    jQuery("#editform").prepend(code);
}

/*********************************************************
 * insertToolbarHeader()
 *
 * Description: Inserts the name of the toolbar extra
 *   section. Clicking on the header shows/hides the
 *   related section. Requires jQuery JavaScript library.
 * 
 * @author  ebakunin
 * @param   menu (array)
 *********************************************************/
function insertToolbarHeader(menu)
{
    return "<span onclick=\"jQuery('#" + menu['id'] + "').slideToggle('fast')\">" + menu['header'] + "</span>";
}

/****************************************************
 * insertToolbarMenu()
 *
 * Description: Creates a hidden <div> and fills it 
 *   with insertable characters.
 *   Requires jQuery JavaScript library.
 *
 * @author  ebakunin
 * @param   list (array) 
 ****************************************************/
function insertToolbarMenu(list)
{
    var insert = '<div id="' + list["id"] + '" class="toolbar-menu">';

    for (var i in list['sections']) {
        insert += "<strong>" + list['sections'][i]['title'] + "</strong>: ";

        for (var j=0; j < list['sections'][i]['items'].length; j++) {
            insert += wrapToolbarCharacter(list['sections'][i]['items'][j]);
        }
        insert += "<br />";
    }

    insert += "</div>";

    return insert;
}

/********************************************************
 * wrapToolbarCharacter()
 *
 * Description: Places an <a> tag around a character to 
 *   call insertTags() from the "CharInsert" extension.
 *
 * @author  ebakunin
 * @param   char (string) 
 ********************************************************/
function wrapToolbarCharacter(char)
{
    return (char == " " || char == "&nbsp;")
      ? ' &nbsp; '
      : '<a title="Click on the character or tag to insert it into the edit window" href="javascript:insertTags(\'' + char + '\',\'\',\'\')">' + char + '</a> &nbsp;';
}

//</source>