MediaWiki:Common.js

ဝီကီပီးဒီးယား မှ
Jump to navigation Jump to search

မှတ်ချက်။ သိမ်းဆည်းလိုက်ပြီးသည့်နောက် ပြောင်းလဲမှုများ မြင်ရနိုင်ရန် သင့်အနေဖြင့် ဘရောက်ဇာ၏ cache အား ဖြတ်ကျော်နိုင်ရန် လိုအပ်ပါသည်။

  • Firefox / Safari: Reload ကို နှိပ်နေစဉ်အတွင်း Shift ကို ဖိထားပါ၊ သို့မဟုတ် Ctrl-F5 သို့ Ctrl-R (Mac တွင် ⌘-R) ကို နှိပ်ပါ။
  • Google Chrome: Ctrl-Shift-R (Mac တွင် ⌘-Shift-R) ကို နှိပ်ပါ။
  • Internet Explorer: Refresh ကို နှိပ်နေစဉ်အတွင်း Ctrl ကို ဖိထားပါ၊ သို့မဟုတ် Ctrl-F5 ကို နှိပ်ပါ။
  • Opera: Menu → Settings (Mac တွင် Opera → Preferences) သို့ သွားပြီး Privacy & security → Clear browsing data → Cached images and files ကို ပြုလုပ်ပါ။
/** Collapsible tables *********************************************************
 *
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               [[Wikipedia:NavFrame]].
 *  Maintainers: [[User:R. Koot]]
 *  Added by:    [[User:Hintha]]
 */
 
var autoCollapse = 2;
var collapseCaption = "ဝှက်";
var expandCaption = "ပြ";
 
function collapseTable( tableIndex )
{
    var Button = document.getElementById( "collapseButton" + tableIndex );
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
 
    if ( !Table || !Button ) {
        return false;
    }
 
    var Rows = Table.rows;
 
    if ( Button.firstChild.data == collapseCaption ) {
        for ( var i = 1; i < Rows.length; i++ ) {
            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()
{
    var tableIndex = 0;
    var NavigationBoxes = new Object();
    var Tables = document.getElementsByTagName( "table" );

    for ( var 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.style.styleFloat = "right";
            Button.style.cssFloat = "right";
            Button.style.fontWeight = "normal";
            Button.style.textAlign = "right";
            Button.style.width = "6em";
 
            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 ( $(NavigationBoxes[i]).hasClass( "collapsed" ) || ( tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass( "autocollapse" ) ) ) {
            collapseTable( i );
        }
    }
}
 
$(document).ready( createCollapseButtons );

/** Dynamic Navigation Bars (experimental) *************************************
 *
 *  Description: See [[Wikipedia:NavFrame]].
 *  Maintainers: UNMAINTAINED
 *  Added by:    [[User:Hintha]]
 */
 
// set up the words in your language
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
 
  // set up max count of Navigation Bars on page,
// if there are more, all will be hidden
// NavigationBarShowDefault = 0; // all bars will be hidden
// NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden
var NavigationBarShowDefault = autoCollapse;
 
 
 // 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 ($(NavChild).hasClass( 'NavPic')) {
        NavChild.style.display = 'none';
      }
      if ($(NavChild).hasClass( '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 ($(NavChild).hasClass( 'NavPic')) {
        NavChild.style.display = 'block';
      }
      if ($(NavChild).hasClass( 'NavContent')) {
        NavChild.style.display = 'block';
      }
    }
    NavToggle.firstChild.data = NavigationBarHide;
  }
}

/* Adds show/hide-button to navigation bars **************************************
 *
 * Description: Uses regular expressions and caching for better performance.
 * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
 */
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 ($(NavFrame).hasClass( "NavFrame")) {
 
      indexNavigationBar++;
      var NavToggle = document.createElement("a");
      NavToggle.className = 'NavToggle';
      NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
      NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
 
      var NavToggleText = document.createTextNode(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")) {
          NavFrame.childNodes[j].appendChild(NavToggle);
        }
      }
      NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
    }
  }
     // if more Navigation Bars found than Default: hide all
  if (NavigationBarShowDefault < indexNavigationBar) {
    for (
        var i = 1;
        i <= indexNavigationBar;
        i++
        ) {
      toggleNavigationBar(i);
    }
  }
 
}
$(document).ready(createNavigationBarToggleButton);

/** Main Page layout fixes *********************************************************
 *
 *  Description: Adds an additional link to the complete list of languages available.
 *  Maintainers: [[User:AzaToth]], [[User:R. Koot]], [[User:Alex Smotrov]]
 */
 
if ( mw.config.get( 'wgPageName' ) === 'ဗဟိုစာမျက်နှာ' || mw.config.get( 'wgPageName' ) === 'Talk:ဗဟိုစာမျက်နှာ' ) {
    $( document ).ready( function () {
        mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/List_of_Wikipedias',
            'အပြည့်အစုံစာရင်း', 'interwiki-completelist', 'ဝီကီပီးဒီးယားများ အပြည့်အစုံစာရင်း' );
    } );
}

/**
 * WikiMiniAtlas
 *
 * Description: WikiMiniAtlas is a popup click and drag world map.
 *              This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
 *              The script itself is located on meta because it is used by many projects.
 *              See [[Meta:WikiMiniAtlas]] for more information.
 * Maintainers: [[User:Dschwen]]
 */
( function () {
    var require_wikiminiatlas = false;
    var coord_filter = /geohack/;
    $( function () {
        $( 'a.external.text' ).each( function( key, link ) {
            if ( link.href && coord_filter.exec( link.href ) ) {
                require_wikiminiatlas = true;
                // break from loop
                return false;
            }
        } );
        if ( $( 'div.kmldata' ).length ) {
            require_wikiminiatlas = true;
        }
        if ( require_wikiminiatlas ) {
            mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );
        }
    } );
} )();

// JavaScript font detect code begins
/**
 * JavaScript code to detect available availability of a 
 * particular font in a browser using JavaScript and CSS. 
 * 
 * Author : Lalit Patel
 * Website: http://www.lalit.org/lab/jsoncookies
 * License: Creative Commons Attribution-ShareAlike 2.5
 *          http://creativecommons.org/licenses/by-sa/2.5/
 * Version: 0.1
 * Updated: Aug 11, 2007 10:09am
 * 
 */
 
/**
 * Actual function that does all the work. Returns an array with all the info.
 * My Assumption is that most of the browsers will have arial set as their default sans-serif font.
 */
var Detector = function(){
	var h = document.getElementsByTagName("BODY")[0];
	var d = document.createElement("DIV");
	var s = document.createElement("SPAN");
	d.appendChild(s);
	d.style.fontFamily = "Arial";		//font for the parent element DIV.
	s.style.fontFamily = "Arial";		//arial font used as a comparator.
	s.style.fontSize   = "72px";			//we test using 72px font size, we may use any size. I guess larger the better.
	s.innerHTML        = "ကကကကကကကကကကင";		//we use  က for maximum width. And we use a င so that the same matching fonts can get separated
	h.appendChild(d);
	var defaultWidth   = s.offsetWidth;		//now we have the defaultWidth
	var defaultHeight  = s.offsetHeight;	//and the defaultHeight, we compare other fonts with these.
	h.removeChild(d);
	/* test
	 * params:
	 * font - name of the font you wish to detect
	 * return: 
	 * f[0] - Input font name.
	 * f[1] - Computed width.
	 * f[2] - Computed height.
	 * f[3] - Detected? (true/false).
	 */
	function test(font) {
                h.appendChild(d);		
		var f = [];
		f[0] = s.style.fontFamily = font;	// Name of the font        
                s.style.innerHTML = "ကကကကကကကကကကင"
                s.style.fontSize = "72px";         
                h.appendChild(d);
		f[1] = s.offsetWidth;				// Width
		f[2] = s.offsetHeight;				// Height        
		h.removeChild(d);
		font = font.toLowerCase();
		if (font == "arial" || font == "sans-serif") {
			f[3] = true;	// to set arial and sans-serif true
		} else {
			f[3] = (f[1] != defaultWidth && f[2] != defaultHeight);	// Detected?
		}        
		return f;
	}
	this.test = test;
}

// Create new instance of Detector and pass each U51 font. 
// Update table with result[3]
function detectFont(){
    d = new Detector;
    result = d.test("Padauk");
	var p = document.getElementById("Padauk");
	if(p) p.innerHTML = result[3]
	result = d.test("Myanmar3");
	var p = document.getElementById("Myanmar3");
	if(p) p.innerHTML = result[3]
	result = d.test("Parabaik");
	var p = document.getElementById("Parabaik");
	if(p) p.innerHTML = result[3]
	result = d.test("MyMyanmar Unicode");
	var p = document.getElementById("MyMyanmar");
	if(p) p.innerHTML = result[3]
	result = d.test("Myanmar2");
	var p = document.getElementById("Myanmar2");
	if(p) p.innerHTML = result[3]
}
 
$(document).ready(detectFont);
// JavaScript font detect code ends

/**
 * Magic editintros ****************************************************
 *
 * Description: Adds editintros on disambiguation pages and BLP pages.
 * Maintainers: [[User:RockMFR]]
 */
function addEditIntro( name ) {
    $( '.mw-editsection, #ca-edit' ).find( 'a' ).each( function ( i, el ) {
        el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
    } );
}

if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
    $( function () {
        if ( document.getElementById( 'disambigbox' ) ) {
            addEditIntro( 'Template:Disambig_editintro' );
        }
    } );

    $( function () {
        var cats = mw.config.get('wgCategories');
        if ( !cats ) {
            return;
        }
        if ( $.inArray( 'သက်ရှိထင်ရှားပုဂ္ဂိုလ်များ', cats ) !== -1 || $.inArray( 'Possibly living people', cats ) !== -1 ) {
            addEditIntro( 'Template:BLP_editintro' );
        }
    } );
}