MediaWiki:Common.js: Difference between revisions

From WikiIslam, the online resource on Islam
Jump to navigation Jump to search
(will work on this toolbar later)
No edit summary
 
(9 intermediate revisions by 2 users not shown)
Line 3: Line 3:
  * @stats [[File:Krinkle_InsertWikiEditorButton.js]]
  * @stats [[File:Krinkle_InsertWikiEditorButton.js]]
  */
  */
jQuery.getScript('//www.wikiislam.net/w/index.php?title=MediaWiki:InsertWikiEditorButton.js&action=raw&ctype=text/javascript', function () {
jQuery.getScript('//www.wikiislam.net/index.php?title=MediaWiki:InsertWikiEditorButton.js&action=raw&ctype=text/javascript', function () {


buttomimagepath = "http://www.wikiislam.net/wiki/uploads/";
buttomimagepath = "http://www.wikiislam.net/wiki/uploads/";
Line 351: Line 351:
*/
*/


// =========================== START OF SHOW/HIDE =====================================
/** Collapsible tables *********************************************************
*
*  Description: Allows tables to be collapsed, showing only the header. See
*              [[Wikipedia:NavFrame]].
*  Maintainers: [[User:R. Koot]]
*/


var autoCollapse = 2;
var collapseCaption = "hide";
var expandCaption = "show";


function collapseTable( tableIndex )
/* Main Page drop down box */
{
    var Button = document.getElementById( "collapseButton" + tableIndex );
    var Table = document.getElementById( "collapsibleTable" + tableIndex );


    if ( !Table || !Button ) {
jQuery("#mouseoverpopupopener").mouseenter(function() {
        return false;
    jQuery("#mouseoverpopupwindow").show();
    }
});


    var Rows = Table.rows;


    if ( Button.firstChild.data == collapseCaption ) {
//================================================================================
        for ( var i = 1; i < Rows.length; i++ ) {
//                    drop down menus
            Rows[i].style.display = "none";
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( var i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
}


function createCollapseButtons()
// Start: Dropdown menu
{
$(function(){
    var tableIndex = 0;
     $("div.dropdownmenu ul li").hover(function(){
    var NavigationBoxes = new Object();
         $(this).addClass("hover");
    var Tables = document.getElementsByTagName( "table" );
         $('ul:first',this).css('visibility', 'visible');
 
     }, function(){
    for ( var i = 0; i < Tables.length; i++ ) {
         $(this).removeClass("hover");
        if ( hasClass( Tables[i], "collapsible" ) ) {
        $('ul:first',this).css('visibility', 'hidden');
 
    });
            /* only add button and increment count if there is a header row to work with */
    $("div.dropdownmenu ul li ul li:has(ul)").find("a:first").append(" &raquo; ");
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
});
            if (!HeaderRow) continue;
// end: dropdown menus
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
            if (!Header) continue;
 
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
 
            var Button     = document.createElement( "span" );
            var ButtonLink = document.createElement( "a" );
            var ButtonText = document.createTextNode( collapseCaption );
 
            Button.className = "collapseButton";  //Styles are declared in Common.css
 
            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
            ButtonLink.appendChild( ButtonText );
 
            Button.appendChild( document.createTextNode( "[" ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( "]" ) );
 
            Header.insertBefore( Button, Header.childNodes[0] );
            tableIndex++;
        }
    }
 
    for ( var i = 0;  i < tableIndex; i++ ) {
         if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
            collapseTable( i );
        }
        else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) {
            var element = NavigationBoxes[i];
            while (element = element.parentNode) {
                if ( hasClass( element, "outercollapse" ) ) {
                    collapseTable ( i );
                    break;
                }
            }
         }
    }
}
 
addOnloadHook( createCollapseButtons );
 
var hasClass = (function () {
var reCache = {};
return function (element, className) {
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
};
})();
 
 
/** Dynamic Navigation Bars (experimental) *************************************
*
*  Description: See [[Wikipedia:NavFrame]].
*  Maintainers: UNMAINTAINED
*/
 
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
 
// shows and hides content and picture (if available) of navigation bars
// Parameters:
//    indexNavigationBar: the index of navigation bar to be toggled
function toggleNavigationBar(indexNavigationBar)
{
    var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
    var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
 
    if (!NavFrame || !NavToggle) {
        return false;
    }
 
    // if shown now
    if (NavToggle.firstChild.data == NavigationBarHide) {
        for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
            if ( hasClass( NavChild, 'NavPic' ) ) {
                NavChild.style.display = 'none';
            }
            if ( hasClass( NavChild, 'NavContent') ) {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;
 
    // if hidden now
    } else if (NavToggle.firstChild.data == NavigationBarShow) {
        for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
            if (hasClass(NavChild, 'NavPic')) {
                NavChild.style.display = 'block';
            }
            if (hasClass(NavChild, 'NavContent')) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
     }
}
 
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
    var indexNavigationBar = 0;
    // iterate over all < div >-elements
    var divs = document.getElementsByTagName("div");
    for (var i = 0; NavFrame = divs[i]; i++) {
         // if found a navigation bar
        if (hasClass(NavFrame, "NavFrame")) {
 
            indexNavigationBar++;
            var NavToggle = document.createElement("a");
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
            NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
 
            var isCollapsed = hasClass( NavFrame, "collapsed" );
            /*
            * Check if any children are already hidden.  This loop is here for backwards compatibility:
            * the old way of making NavFrames start out collapsed was to manually add style="display:none"
            * to all the NavPic/NavContent elements.  Since this was bad for accessibility (no way to make
            * the content visible without JavaScript support), the new recommended way is to add the class
            * "collapsed" to the NavFrame itself, just like with collapsible tables.
            */
            for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
                if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
                    if ( NavChild.style.display == 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if (isCollapsed) {
                for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
                    if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
                        NavChild.style.display = 'none';
                    }
                }
            }
            var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
            NavToggle.appendChild(NavToggleText);
 
            // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
            for(var j=0; j < NavFrame.childNodes.length; j++) {
                if (hasClass(NavFrame.childNodes[j], "NavHead")) {
                    NavFrame.childNodes[j].appendChild(NavToggle);
                }
            }
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
        }
    }
}
 
addOnloadHook( createNavigationBarToggleButton );
 
// =========================== END OF SHOW/HIDE =====================================

Latest revision as of 20:35, 24 October 2021

/**
 * Extra buttons in toolbar
 * @stats [[File:Krinkle_InsertWikiEditorButton.js]]
 */
jQuery.getScript('//www.wikiislam.net/index.php?title=MediaWiki:InsertWikiEditorButton.js&action=raw&ctype=text/javascript', function () {

buttomimagepath = "http://www.wikiislam.net/wiki/uploads/";

krInsertWikiEditorButton({
     id: "mw-customeditbutton-button-1",
icon: "http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png",
     label: "Line break",
     insertBefore: "<br />",
     insertAfter: "",
     sampleText: ""});
 
   krInsertWikiEditorButton({
     id: "mw-customeditbutton-button-2",
icon: "http://upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png",
     label: "Superscript",
     insertBefore: "<sup>",
     insertAfter: "</sup>",
     sampleText: "Superscript text"});
 
   krInsertWikiEditorButton({
     id: "mw-customeditbutton-button-3",
icon: "http://upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png",
     label: "Subscript",
     insertBefore: "<sub>",
     insertAfter: "</sub>",
     sampleText: "Subscript text"});
 
   krInsertWikiEditorButton({
     id: "mw-customeditbutton-button-4",
icon: "http://upload.wikimedia.org/wikipedia/en/5/58/Button_small.png",
     label: "Small",
     insertBefore: "<small>",
     insertAfter: "</small>",
     sampleText: "Small Text"});
 
   krInsertWikiEditorButton({
     id: "mw-customeditbutton-button-5",
icon: "http://upload.wikimedia.org/wikipedia/en/3/34/Button_hide_comment.png",
     label: "Insert hidden Comment",
     insertBefore: "<!-- ",
     insertAfter: " -->",
     sampleText: "Comment"});
 
   krInsertWikiEditorButton({
     id: "mw-customeditbutton-button-6",
icon: "http://upload.wikimedia.org/wikipedia/en/1/12/Button_gallery.png",
     label: "Insert a picture gallery",
     insertBefore: "\n<gallery>\n",
     insertAfter: "\n</gallery>",
     sampleText: "Image:Example.jpg|Caption1\nImage:Example.jpg|Caption2"});
 
   krInsertWikiEditorButton({
     id: "mw-customeditbutton-button-7",
icon: "http://upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png",
     label: "Insert block of quoted text",
     insertBefore: "<blockquote>\n",
     insertAfter: "\n</blockquote>",
     sampleText: "Block quote"});
 
   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-8",
icon: buttomimagepath + "0/04/Button_array.png",
     label: "Insert a table",
     insertBefore: '{| class="wikitable"\n|-\n',
     insertAfter: "\n|}",
     sampleText: "! 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"});

   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-9",
icon: buttomimagepath + "7/79/Button_reflink.png",
     label: "Reference",
     insertBefore: "<"+ "ref>",
     insertAfter: "</ref>",
     sampleText: ""});

   krInsertWikiEditorButton({
     id: "mw-customeditbutton-button-10",
icon: buttomimagepath + "a/ae/Button_RefList.png",
     label: "RefList Template",
     insertBefore: "{"+"{" + "reflist",
     insertAfter: "}}",
     sampleText: ""});

   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-11",
icon: buttomimagepath + "6/69/Button_Wikipedia_link.png",
     label: "Wikipedia link",
     insertBefore: "[["+ "w:",
     insertAfter: "]]",
     sampleText: "Article|LinkText"});

   krInsertWikiEditorButton({
     id: "mw-customeditbutton-button-12",
icon: buttomimagepath + "b/b1/Button_Quran.png",
     label: "Quran",
     insertBefore: "{"+"{" + "Quran|",
     insertAfter: "}}",
     sampleText: "Surah|Verse"});
 
   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-13",
icon: buttomimagepath + "5/50/Button_HB.png",
     label: "Sahih Bukhari",
     insertBefore: "{"+"{" + "Bukhari|",
     insertAfter: "}}",
     sampleText: "Volume|Book|Verse"});

   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-14",
icon: buttomimagepath + "d/d6/Button_HM.png",
     label: "Sahih Muslim",
     insertBefore: "{"+"{" + "Muslim|",
     insertAfter: "}}",
     sampleText: "Book|Verse"});

   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-15",
icon: buttomimagepath + "1/11/Button_HTab.png",
     label: "Tabari",
     insertBefore: "{"+"{" + "Tabari|",
     insertAfter: "}}",
     sampleText: "Volume|Pages"});

   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-16",
icon: buttomimagepath + "2/2d/Button_HAd.png",
     label: "Abu Dawud",
     insertBefore: "{"+"{" + "Abudawud|",
     insertAfter: "}}",
     sampleText: "Book|Verse"});

   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-17",
icon: buttomimagepath + "9/94/Button_HMw.png",
     label: "Muwatta",
     insertBefore: "{"+"{" + "Muwatta|",
     insertAfter: "}}",
     sampleText: "Book|Section|Verse|"});

   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-18",
icon: buttomimagepath + "f/ff/Button_HIM.png",
     label: "Ibn Majah",
     insertBefore: "{"+"{" + "Ibn Majah|",
     insertAfter: "}}",
     sampleText: "Volume|Book|Hadith"});

   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-19",
icon: buttomimagepath + "0/0f/Button_Quote.png",
     label: "Quote Box",
     insertBefore: "{"+"{" + "Quote|",
     insertAfter: "}}",
     sampleText: "Source|QuotationText|SecondaryText"});

   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-20",
icon: buttomimagepath + "9/91/Button_cite_web.png",
     label: "Cite web",
     insertBefore: "{"+"{" + "Cite web|",
     insertAfter: "}}",
     sampleText: "url= |title= |publisher= |author= |date= |archiveurl= |deadurl=no"});

   krInsertWikiEditorButton({
    id: "mw-customeditbutton-button-21",
icon: buttomimagepath + "0/02/Button_cite_web_quote.png",
     label: "Cite web for Quote box",
     insertBefore: "{"+"{" + "Cite web quotebox|",
     insertAfter: "}}",
     sampleText: "url= |title= |publisher= |author= |date= |archiveurl= |deadurl=no"});
 
/*

// Buttons are:
Button_HTab.png
Button_reflink.png
Button_RefList.png
Button_Wikipedia_link.png
Button_Quran.png
Button_HB.png
Button_HM.png
Button_HTab.png
Button_HAd.png
Button_HMw.png
Button_HIM.png
Button_Quote.png
Button_cite_web.png
Button_cite_web_quote.png
*/
 
});


/*
if (mwCustomEditButtons) {
buttomimagepath = "http://www.wikiislam.net/wiki/uploads/"

   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png",
     "speedTip": "Line break",
     "tagOpen": "<br />",
     "tagClose": "",
     "sampleText": ""};
 
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png",
     "speedTip": "Superscript",
     "tagOpen": "<sup>",
     "tagClose": "</sup>",
     "sampleText": "Superscript text"};
 
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png",
     "speedTip": "Subscript",
     "tagOpen": "<sub>",
     "tagClose": "</sub>",
     "sampleText": "Subscript text"};
 
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/en/5/58/Button_small.png",
     "speedTip": "Small",
     "tagOpen": "<small>",
     "tagClose": "</small>",
     "sampleText": "Small Text"};
 
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/en/3/34/Button_hide_comment.png",
     "speedTip": "Insert hidden Comment",
     "tagOpen": "<!-- ",
     "tagClose": " -->",
     "sampleText": "Comment"};
 
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/12/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[mwCustomEditButtons.length] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png",
     "speedTip": "Insert block of quoted text",
     "tagOpen": "<blockquote>\n",
     "tagClose": "\n</blockquote>",
     "sampleText": "Block quote"};
 
   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "0/04/Button_array.png",
     "speedTip": "Insert a table",
     "tagOpen": '{| class="wikitable"\n|-\n',
     "tagClose": "\n|}",
     "sampleText": "! 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[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "7/79/Button_reflink.png",
     "speedTip": "Reference",
     "tagOpen": "<"+ "ref>",
     "tagClose": "</ref>",
     "sampleText": ""};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": buttomimagepath + "a/ae/Button_RefList.png",
     "speedTip": "RefList Template",
     "tagOpen": "{"+"{" + "reflist",
     "tagClose": "}}",
     "sampleText": ""};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "6/69/Button_Wikipedia_link.png",
     "speedTip": "Wikipedia link",
     "tagOpen": "[["+ "w:",
     "tagClose": "]]",
     "sampleText": "Article|LinkText"};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": buttomimagepath + "b/b1/Button_Quran.png",
     "speedTip": "Quran",
     "tagOpen": "{"+"{" + "Quran|",
     "tagClose": "}}",
     "sampleText": "Surah|Verse"};
 
   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "5/50/Button_HB.png",
     "speedTip": "Sahih Bukhari",
     "tagOpen": "{"+"{" + "Bukhari|",
     "tagClose": "}}",
     "sampleText": "Volume|Book|Verse"};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "d/d6/Button_HM.png",
     "speedTip": "Sahih Muslim",
     "tagOpen": "{"+"{" + "Muslim|",
     "tagClose": "}}",
     "sampleText": "Book|Verse"};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "1/11/Button_HTab.png",
     "speedTip": "Tabari",
     "tagOpen": "{"+"{" + "Tabari|",
     "tagClose": "}}",
     "sampleText": "Volume|Pages"};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "2/2d/Button_HAd.png",
     "speedTip": "Abu Dawud",
     "tagOpen": "{"+"{" + "Abudawud|",
     "tagClose": "}}",
     "sampleText": "Book|Verse"};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "9/94/Button_HMw.png",
     "speedTip": "Muwatta",
     "tagOpen": "{"+"{" + "Muwatta|",
     "tagClose": "}}",
     "sampleText": "Book|Section|Verse|"};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "f/ff/Button_HIM.png",
     "speedTip": "Ibn Majah",
     "tagOpen": "{"+"{" + "Ibn Majah|",
     "tagClose": "}}",
     "sampleText": "Volume|Book|Hadith"};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "0/0f/Button_Quote.png",
     "speedTip": "Quote Box",
     "tagOpen": "{"+"{" + "Quote|",
     "tagClose": "}}",
     "sampleText": "Source|QuotationText|SecondaryText"};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "9/91/Button_cite_web.png",
     "speedTip": "Cite web",
     "tagOpen": "{"+"{" + "Cite web|",
     "tagClose": "}}",
     "sampleText": "url= |title= |publisher= |author= |date= |archiveurl= |deadurl=no"};

   mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": buttomimagepath + "0/02/Button_cite_web_quote.png",
     "speedTip": "Cite web for Quote box",
     "tagOpen": "{"+"{" + "Cite web quotebox|",
     "tagClose": "}}",
     "sampleText": "url= |title= |publisher= |author= |date= |archiveurl= |deadurl=no"};

 }
*/



/* Main Page drop down box */

jQuery("#mouseoverpopupopener").mouseenter(function() {
    jQuery("#mouseoverpopupwindow").show();
});


//================================================================================
//                    drop down menus

// Start: Dropdown menu
$(function(){
    $("div.dropdownmenu ul li").hover(function(){
        $(this).addClass("hover");
        $('ul:first',this).css('visibility', 'visible');
    }, function(){
        $(this).removeClass("hover");
        $('ul:first',this).css('visibility', 'hidden');
    });
    $("div.dropdownmenu ul li ul li:has(ul)").find("a:first").append(" &raquo; ");
});
// end: dropdown menus