MediaWiki:Common.js

Dari Wikikamus bahasa Indonesia, kamus bebas

Catatan: Setelah disimpan, Anda mungkin perlu melewati tembolok peramban web untuk melihat perubahan.

  • Firefox/Safari: Tekan dan tahan Shift sembari mengeklik Reload, atau tekan Ctrl-F5 atau Ctrl-R (⌘-R di Mac)
  • Google Chrome: Tekan Ctrl-Shift-R (⌘-Shift-R di Mac)
  • Internet Explorer / Edge: Tahan Ctrl sembari mengeklik Refresh, atau tekan Ctrl-F5
  • Opera: Tekan Ctrl-F5.
/*
* Disabling imports from user namespace. This is a security issue. Do not reinstate. -- [[User:Ladsgroup]]
importScript('User:Bennylin/Editor.js');
importScript('User:Bennylin/languagenametocode.js');
importScript('User:Bennylin/TargetedTranslations.js');
importScript('User:Bennylin/rhymesedit.js');
importScript('User:Bennylin/adddefinition.js');
importScript('User:Bennylin/editor2.js');
importScript('User:Bennylin/newentrywiz.js');
*/
mw.loader.load('//id.wikipedia.org/w/index.php?title=MediaWiki:Common.js&action=raw&ctype=text/javascript');

// See also [[MediaWiki:Gadget-DefSideBoxes.js]]
// Disabling imports from user namespace. This is a security issue. Do not reinstate. -- [[User:Ladsgroup]]
//window.defsideboxes_preload = window.defsideboxes_preload || mw.loader.getScript('https://id.wiktionary.org/w/index.php?title=User:Bennylin/languagecodefinder.js&action=raw&ctype=text/javascript');

/**
 
JavaScript yang ada di sini akan diterapkan untuk semua kulit.
__TOC__
== Deklarasi variabel ==
 
 Variabel-variabel yang dipakai secara global */
 var LoadInterProject = true;
 var load_edittools = true;
 var LoadExtraEditButtons = true;
/**
 
== InterProject ==
 
InterProject, link di menu samping untuk proyek lain.
 
 */
if (LoadInterProject == true) {
	mw.loader.using('mediawiki.util', function() {
		mw.util.addCSS('#interProyek {display: none; speak: none;} #p-tb .pBody {padding-right: 0;}');
	});
	$(document).ready(function() {
		if (document.getElementById("interProyek")) {
			var iProject = document.getElementById("interProyek").innerHTML;
			var interProject = document.createElement("div");
			interProject.style.marginTop = "0.7em"; 
			interProject.innerHTML = '<h5>Proyek lain<\/h5><div class="pBody">'+iProject+'<\/div>';
			document.getElementById("p-tb").appendChild(interProject);
		}
	});
}

/**
== MainPageTransform ==
 
 Menghilangkan judul [[Halaman Utama]] dan mengganti nama tab. */
 
 if ( mw.config.get( 'wgIsMainPage' ) && mw.config.get( 'wgIsArticle' ) ) 
 {
	 mw.loader.using('mediawiki.util', function() {
		mw.util.addCSS('#siteSub, #contentSub, h1.firstHeading { display: none!important; } #content, #content div.thumb, #p-cactions li a, #p-cactions li a:hover, #p-cactions li.selected a { background: #fff!important; }');
	});
 }

/*
== Visibility toggling ==
*/
var VisibilityToggles = {
    // toggles[category] = [[show, hide],...]; statuses[category] = [true, false,...]; buttons = <li>
    toggles: {}, statuses: {}, buttons: null,

    // Add a new toggle, adds a Show/Hide category button in the toolbar,
    // and will call show_function and hide_function once on register, and every alternate click.
    register: function (category, show_function, hide_function) {

        var id = 0;
        if (!this.toggles[category]) {
            this.toggles[category] = [];
            this.statuses[category] = [];
        } else {
            id = this.toggles[category].length;
        }
        this.toggles[category].push([show_function, hide_function]);
        this.statuses[category].push(this.currentStatus(category));
        this.addGlobalToggle(category);

        (this.statuses[category][id] ? show_function : hide_function)();

        return function () {
            var statuses = VisibilityToggles.statuses[category];
            statuses[id] = !statuses[id]
            VisibilityToggles.checkGlobalToggle(category);
            return (statuses[id] ? show_function : hide_function)();
        }

    },

    // Add a new global toggle to the side bar
    addGlobalToggle: function(category) {
        if (document.getElementById('p-visibility-'+category))
            return;
        if (!this.buttons) {
            this.buttons = newNode('ul');
            var collapsed = $.cookie("vector-nav-p-visibility") == "false", toolbox = newNode('div', {'class': "portal portlet "+(collapsed?"collapsed":"expanded"), 'id': 'p-visibility'},
                            newNode('h5', 'Visibility'),
                            newNode('div', {'class': "pBody body"}, collapsed?undefined:{'style':'display:block;'}, this.buttons)
                          );
            var sidebar = document.getElementById('mw-panel') || document.getElementById('column-one');
            var insert = null;
            if (insert = (document.getElementById('p-lang') || document.getElementById('p-feedback')))
                sidebar.insertBefore(toolbox, insert);
            else
                sidebar.appendChild(toolbox);

        }
        var status = this.currentStatus(category);
        var newToggle = newNode('li', newNode('a', {
            id: 'p-visibility-' + category, 
            style: 'cursor: pointer',
            href: '#visibility-' + category,
            click: function(e)
            {
                VisibilityToggles.toggleGlobal(category); 
                if (e && e.preventDefault)
                    e.preventDefault();
                else 
                    window.event.returnValue = false;
                return false; 
            }},
            (status ? 'Hide ' : 'Show ') + category));
        for (var i=0; i < this.buttons.childNodes.length; i++) {
            if (this.buttons.childNodes[i].id < newToggle.id) {
                this.buttons.insertBefore(newToggle, this.buttons.childNodes[i]);
                return;
            }
        }
        this.buttons.appendChild(newToggle);
    },

    // Update the toggle-all buttons when all things are toggled one way
    checkGlobalToggle: function(category) {
        var statuses = this.statuses[category];
        var status = statuses[0];
        for (var i = 1; i < statuses.length; i++) {
            if (status != statuses[i])
                return;
        }
        document.getElementById('p-visibility-' + category).innerHTML = (status ? 'Hide ' : 'Show ') + category;
    },

    // Toggle all un-toggled elements when the global button is clicked
    toggleGlobal: function(category) {
        var status = document.getElementById('p-visibility-' + category).innerHTML.indexOf('Show ') == 0;
        for (var i = 0; i < this.toggles[category].length; i++ ) {
            if (this.statuses[category][i] != status) {
                this.toggles[category][i][status ? 0 : 1]();
                this.statuses[category][i] = status;
            }
        }
        document.getElementById('p-visibility-' + category).innerHTML = (status ? 'Hide ' : 'Show ') + category;
        var current = getCookie('Visibility');
        if (!current)
            current = ";";
        current = current.replace(';' + category + ';', ';');
        if (status)
            current = current + category + ";";
        setCookie('Visibility', current);
    },

    currentStatus: function(category) {
        if (getCookie('WiktionaryPreferencesShowNav') == 'true')
            return true;
        else if (getCookie('Visibility').indexOf(';' + category + ';') >= 0)
            return true;
        return false; // TODO load this from category specific cookies
    }
};

/*
=== DOM creation ===
*/
/**
 * Create a new DOM node for the current document.
 *    Basic usage:  var mySpan = newNode('span', "Hello World!")
 *    Supports attributes and event handlers*: var mySpan = newNode('span', {style:"color: red", focus: function(){alert(this)}, id:"hello"}, "World, Hello!")
 *    Also allows nesting to create trees: var myPar = newNode('p', newNode('b',{style:"color: blue"},"Hello"), mySpan)
 *
 * *event handlers, there are some issues with IE6 not registering event handlers on some nodes that are not yet attached to the DOM,
 * it may be safer to add event handlers later manually.
**/
function newNode(tagname){

  var node = document.createElement(tagname);
  
  for( var i=1;i<arguments.length;i++ ){
    
    if(typeof arguments[i] == 'string'){ //Text
      node.appendChild( document.createTextNode(arguments[i]) );
      
    }else if(typeof arguments[i] == 'object'){ 
      
      if(arguments[i].nodeName){ //If it is a DOM Node
        node.appendChild(arguments[i]);
        
      }else{ //Attributes (hopefully)
        for(var j in arguments[i]){
          if(j == 'class'){ //Classname different because...
            node.className = arguments[i][j];
            
          }else if(j == 'style'){ //Style is special
            node.style.cssText = arguments[i][j];
            
          }else if(typeof arguments[i][j] == 'function'){ //Basic event handlers
            try{ node.addEventListener(j,arguments[i][j],false); //W3C
            }catch(e){try{ node.attachEvent('on'+j,arguments[i][j],"Language"); //MSIE
            }catch(e){ node['on'+j]=arguments[i][j]; }}; //Legacy
          
          }else{
            node.setAttribute(j,arguments[i][j]); //Normal attributes

          }
        }
      }
    }
  }
  
  return node;
}

/*

===Cookies===
*/

/* @deprecated: Use $.cookie instead */
function setCookie(cookieName, cookieValue) {
 var today = new Date();
 var expire = new Date();
 var nDays = 30;
 expire.setTime( today.getTime() + (3600000 * 24 * nDays) );
 document.cookie = cookieName + "=" + escape(cookieValue)
                 + ";path=/"
                 + ";expires="+expire.toGMTString();
 // We need to delete the more specific paths for the next while. Safe to remove this by July 2011, if not before.
 document.cookie = cookieName + "=" + ";path=/w" +
  ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
 document.cookie = cookieName + "=" + ";path=/wiki" +
  ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function getCookie(cookieName) {
  var start = document.cookie.indexOf( cookieName + "=" );
  if ( start == -1 ) return "";
  var len = start + cookieName.length + 1;
  if ( ( !start ) &&
    ( cookieName != document.cookie.substring( 0, cookieName.length ) ) )
      {
        return "";
      }
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 ) end = document.cookie.length;
  return unescape( document.cookie.substring( len, end ) );
}

function deleteCookie(cookieName) {
  if ( getCookie(cookieName) ) {
    document.cookie = cookieName + "=" + ";path=/" +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
  }
}
/**
 * Collapsible tables *********************************************************
 *
 * Description: Allows tables to be collapsed, showing only the header. See
 *              [[Wikipedia:NavFrame]].
 * Maintainers: [[User:R. Koot]]
 */
 
var autoCollapse = 2;
var collapseCaption = 'sembunyikan';
var expandCaption = 'tampilkan';
 
window.collapseTable = function ( tableIndex ) {
    var Button = document.getElementById( 'collapseButton' + tableIndex );
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );
 
    if ( !Table || !Button ) {
        return false;
    }
 
    var Rows = Table.rows;
    var i;
 
    if ( Button.firstChild.data === collapseCaption ) {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = 'none';
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
};
 
function createCollapseButtons() {
    var tableIndex = 0;
    var NavigationBoxes = {};
    var Tables = document.getElementsByTagName( 'table' );
    var i;
 
    function handleButtonLink( index, e ) {
        window.collapseTable( index );
        e.preventDefault();
    }
 
    for ( i = 0; i < Tables.length; i++ ) {
        if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
 
            /* only add button and increment count if there is a header row to work with */
            var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
            if ( !HeaderRow ) continue;
            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', '#' );
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
            ButtonLink.appendChild( ButtonText );
 
            Button.appendChild( document.createTextNode( '[' ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( ']' ) );
 
            Header.insertBefore( Button, Header.firstChild );
            tableIndex++;
        }
    }
 
    for ( i = 0;  i < tableIndex; i++ ) {
        if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
            window.collapseTable( i );
        } 
        else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
            var element = NavigationBoxes[i];
            while ((element = element.parentNode)) {
                if ( $( element ).hasClass( 'outercollapse' ) ) {
                    window.collapseTable ( i );
                    break;
                }
            }
        }
    }
}
 
$( createCollapseButtons );
 
/**
 * 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
 **/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
    var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
    var NavChild;
 
    if ( !NavFrame || !NavToggle ) {
        return false;
    }
 
    /* if shown now */
    if ( NavToggle.firstChild.data === NavigationBarHide ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'none';
            }
        }
    NavToggle.firstChild.data = NavigationBarShow;
 
    /* if hidden now */
    } else if ( NavToggle.firstChild.data === NavigationBarShow ) {
        for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
            if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
                NavChild.style.display = 'block';
            }
        }
        NavToggle.firstChild.data = NavigationBarHide;
    }
 
    event.preventDefault();
};
 
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton() {
    var indexNavigationBar = 0;
    var NavFrame;
    var NavChild;
    /* iterate over all < div >-elements */
    var divs = document.getElementsByTagName( 'div' );
    for ( var i = 0; (NavFrame = divs[i]); i++ ) {
        /* if found a navigation bar */
        if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
 
            indexNavigationBar++;
            var NavToggle = document.createElement( 'a' );
            NavToggle.className = 'NavToggle';
            NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
            NavToggle.setAttribute( 'href', '#' );
            $( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
 
            var isCollapsed = $( NavFrame ).hasClass( '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 ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
                if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
                    if ( NavChild.style.display === 'none' ) {
                        isCollapsed = true;
                    }
                }
            }
            if ( isCollapsed ) {
                for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
                    if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( '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 ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
                    NavToggle.style.color = NavFrame.childNodes[j].style.color;
                    NavFrame.childNodes[j].appendChild( NavToggle );
                }
            }
            NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
        }
    }
}
 
$( createNavigationBarToggleButton );
 
/**
 
=== Notice di [[Wiktionary:Bak pasir]] dan [[Pembicaraan Wiktionary:Bak pasir]] ===
 */
 function sandboxNotice() {
 notice = document.createElement('div');
 document.getElementById('bodyContent').insertBefore(notice, document.getElementById('jump-to-nav').nextSibling);
 noticeLoader = sajax_init_object();
 noticeLoader.open('GET', '//id.wiktionary.org/w/index.php?title=Templat:Bak_pasir&action=render', true);
 noticeLoader.onreadystatechange = function()
    {
        if (noticeLoader.readyState == 4 && noticeLoader.status == 200) {
            notice.innerHTML = noticeLoader.responseText;
        }
    };
 noticeLoader.send('');
 }
 if (mw.config.get('wgAction').match(/view|edit|submit/)) {
    $(document).ready(function() {
        if (document.getElementsByTagName('body')[0].className.match(/page-(Pembicaraan_)?Wiktionary_Bak_pasir/)) {
            return sandboxNotice();
        }
    });
 }

/**
== Edittools ==

 Drop down box for the Special character menu in [[MediaWiki:Edittools]]
 Adapted from:
 //de.wiktionary.org/wiki/MediaWiki:Onlyifediting.js ,
 //de.wikipedia.org/wiki/MediaWiki:Onlyifediting.js and
 //en.wiktionary.org/wiki/MediaWiki:Monobook.js
 */

 function addCharSubsetMenu() {
     if ( load_edittools !== true ) return;
  var specialchars = document.getElementById('specialchars');
  
  if (specialchars) {
   var menu = "<select style=\"display:inline\" onChange=\"chooseCharSubset(selectedIndex)\">";
   menu += "<option>Standar+Templat</option>";
   menu += "<option>IPA</option>";
   menu += "<option>Latin</option>";
   menu += "<option>Jawa+Jawa Kuna</option>";
   menu += "<option>Pinyin+Romaji</option>";
   menu += "<option>Arab</option>";
   menu += "<option>Ibrani</option>";
   menu += "<option>Sirilik</option>";
   menu += "<option>Yunani</option>";
   menu += "<option>Devanāgarī</option>";
   menu += "<option>Yiddish</option>";
   menu += "</select>";
   specialchars.innerHTML = menu + specialchars.innerHTML;
  
   // Standard-CharSubset
   chooseCharSubset(0);
  }
 }
  
 // CharSubset selection
 function chooseCharSubset(s) {
  var l = document.getElementById('specialchars').getElementsByTagName('p');
  for (var i = 0; i < l.length ; i++) {
   l[i].style.display = i == s ? 'inline' : 'none';
   // l[i].style.visibility = i == s ? 'visible' : 'hidden';
  }
 }
  
 // Menu insertion
 $( addCharSubsetMenu );

// Results from Wikidata
// [[File:Wdsearch_script_screenshot.png]]
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||  ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
        mw.loader.load("//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript");
}

/* ==Page specific extensions== */
/* ===[[Wiktionary:Main Page]]=== */
mw.loader.using("mediawiki.util", function(){
	// Hide the title and "Redirected from" (maybe we should keep the redirected from so's people update their bookmarks ;)
	// Broken in IE!
	if (mw.config.get('wgIsMainPage') && !(mw.config.get('wgAction') === 'view' || mw.config.get('wgAction') === 'submit')) {
		mw.util.addCSS('.firstHeading { display: block !important; }');
		mw.util.addCSS('#contentSub { display: inline !important; }');
	}
	
	if (mw.config.get('wgIsMainPage')) {
		$(function(){
			mw.util.addPortletLink('p-lang', '//meta.wikimedia.org/wiki/Wiktionary#List_of_Wiktionaries',
				'Daftar lengkap', 'interwiki-completelist', 'Daftar WikiKamus lengkap');
		});
	}
});