Məzmuna keçin

MediaWiki:Common.js: Redaktələr arasındakı fərq

7.598 bayt çıxarıldı ,  10 mart
redaktənin izahı yoxdur
Redaktənin izahı yoxdur
Redaktənin izahı yoxdur
Sətir 1: Sətir 1:
/* Burada redaktorların hamısı üçün bütün səhifələrdə istənilən JavaScript yüklənəcək */
/**
* Skriptləri yükləmək üçün lokal skript
*/
var importScript_ = importScript;
importScript = function ( page, proj ) {
if ( !proj ) {
importScript_( page );
} else {
if ( proj.indexOf( '.' ) === -1 ) {
proj += '.sheki.org';
}
mw.loader.using( 'mediawiki.util' ).done( function () {
mw.loader.load( '//' + proj + '/w/index.php?title=' + mw.util.wikiUrlencode( page ) +
'&action=raw&ctype=text/javascript' );
} );
}
};
 
//runAsEarlyAsPossible from ruwiki
function runAsEarlyAsPossible( callback, $testElement, func ) {
func = func || $;
$testElement = $testElement || $( '#footer' );
 
if ( $testElement.length ) {
callback();
} else {
func( callback );
}
}
 
// Switch language variants of messages (from zh)
// Switch language variants of messages (from zh)
function wgULS(latn,arab){
function wgULS(latn,arab){
Sətir 45: Sətir 74:
     for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
     for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
       var temp = UnitNode.childNodes[j];
       var temp = UnitNode.childNodes[j];
       if (temp.className === "center") { units.push(temp); }
       if (['center', 'mw-halign-center'].some(function(className) { return temp.classList.contains(className); })) { units.push(temp); }
     }
     }
     var rightlink;
     var rightlink;
     var commentText;
     var commentText;
    var wrap;
     for (j = 0; j < units.length; j++) {
     for (j = 0; j < units.length; j++) {
       currentimage = units[j];
       currentimage = units[j];
       currentimage.id = "ImageGroupsGr" + i + "Im" + j;
       wrap = document.createElement('div');
      wrap.id = "ImageGroupsGr" + i + "Im" + j;
      currentimage.parentNode.insertBefore(wrap, currentimage);
      wrap.appendChild(currentimage);
       var leftlink = document.createElement("a");
       var leftlink = document.createElement("a");
       if (commentText !== undefined) {
       if (commentText !== undefined) {
Sətir 89: Sətir 122:
       imghead.appendChild(rightlink);
       imghead.appendChild(rightlink);
       if (units.length > 1) {
       if (units.length > 1) {
         currentimage.insertBefore(imghead,currentimage.childNodes[0]);
         wrap.insertBefore(imghead,wrap.childNodes[0]);
       }
       }
       if (j !== 0) {
       if (j !== 0) {
         currentimage.style.display = "none";
         wrap.style.display = "none";
       }
       }
     }
     }
   }
   }
});
});
/* Test if an element has a certain class **************************************
  *
  * Description: Uses regular expressions and caching for better performance.
  * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
  */
var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();


  /** Interwiki links to featured articles ***************************************
  /** Interwiki links to featured articles ***************************************
Sətir 119: Sətir 138:
   *  Maintainers: [[User:R. Koot]]
   *  Maintainers: [[User:R. Koot]]
   */
   */
 
/**
* NAVFRAME
*/
   
   
//Messages
//Messages
Sətir 128: Sətir 151:
var zeroSectionTip = 'Girişi redaktə et';
var zeroSectionTip = 'Girişi redaktə et';


var NavigationBarHide = '[bağla]';
var NavigationBarHide = '[gizlət]';
var NavigationBarShow = '[bax]';
var NavigationBarShow = '[göstər]';
var NavigationBarShowDefault = 2;
var NavigationBarShowDefault = 2;


Sətir 163: Sətir 186:




/** Collapsible tables *********************************************************
var NavigationBarShowDefault;
  *
if ( typeof NavigationBarShowDefault === 'undefined' ) {
  * Description: Allows tables to be collapsed, showing only the header. See
NavigationBarShowDefault = 1;
  *              [[Wikipedia:NavFrame]].
}
  * Maintainers: [[User:R. Koot]]
 
  */
// table.collapsible
function makeCollapsibleMwCollapsible( $content ) {
var $tables = $content
.find( 'table.collapsible:not(.mw-collapsible)' )
.addClass( 'mw-collapsible' );
 
$.each( $tables, function( index, table ) {
// mw.log.warn( 'This page is using the deprecated class collapsible. Please replace it with mw-collapsible.');
if( $( table ).hasClass( 'collapsed') ) {
$( table ).addClass( 'mw-collapsed' );
// mw.log.warn( 'This page is using the deprecated class collapsed. Please replace it with mw-collapsed.');
}
} );
if( $tables.length > 0 ) {
mw.loader.using( 'jquery.makeCollapsible' ).then( function() {
$tables.makeCollapsible();
} );
}
}
mw.hook( 'wikipage.content' ).add( makeCollapsibleMwCollapsible );
 
/**
* Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
*
* Maintainers: TheDJ
*/
function mwCollapsibleSetup( $collapsibleContent ) {
var $element,
$toggle,
autoCollapseThreshold = 2;
$.each( $collapsibleContent, function (index, element) {
$element = $( element );
if ( $element.hasClass( 'collapsible' ) ) {
$element.find('tr:first > th:first').prepend( $element.find('tr:first > * > .mw-collapsible-toggle'));
}
if ( $collapsibleContent.length >= autoCollapseThreshold && $element.hasClass( 'autocollapse' ) ) {
$element.data( 'mw-collapsible' ).collapse();
} else if ( $element.hasClass( 'innercollapse' ) ) {
if ( $element.parents( '.outercollapse' ).length > 0 ) {
$element.data( 'mw-collapsible' ).collapse();
}
}
// because of colored backgrounds, style the link in the text color
// to ensure accessible contrast
$toggle = $element.find( '.mw-collapsible-toggle' );
if ( $toggle.length ) {
// Make the toggle inherit text color
if( $toggle.parent()[0].style.color ) {
$toggle.find( 'a' ).css( 'color', 'inherit' );
}
}
} );
}
 
mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );
 
/**
* Dynamic Navigation Bars (experimental)
*
* Description: See [[Şəki Ensiklopediyası:NavFrame]].
* Maintainers: UNMAINTAINED
*/
   
   
var autoCollapse = 2;
var collapseCaption = 'gizlə';
var collapseCaption = "bağla";
var expandCaption = 'göstər';
var expandCaption = "bax";
 
   
// Set up the words in your language
  function collapseTable( tableIndex )
var navigationBarHide = '[' + collapseCaption.toLowerCase() + ']';
{
var navigationBarShow = '[' + expandCaption.toLowerCase() + ']';
    var Button = document.getElementById( "collapseButton" + tableIndex );
 
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
/**
    var i;
* Shows and hides content and picture (if available) of navigation bars.
    if ( !Table || !Button ) {
*
        return false;
  * @param {number} indexNavigationBar The index of navigation bar to be toggled
    }
  * @param {jQuery.Event} event Event object
*/
    var Rows = Table.getElementsByTagName( "tr" );
function toggleNavigationBar( indexNavigationBar, event ) {
var navToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
    if ( Button.firstChild.data == collapseCaption ) {
var navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
        for ( i = 1; i < Rows.length; i++ ) {
var navChild;
            Rows[i].style.display = "none";
 
        }
if ( !navFrame || !navToggle ) {
        Button.firstChild.data = expandCaption;
return false;
    } else {
}
        for ( i = 1; i < Rows.length; i++ ) {
 
            Rows[i].style.display = Rows[0].style.display;
// If shown now
        }
if ( navToggle.firstChild.data === navigationBarHide ) {
        Button.firstChild.data = collapseCaption;
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
    }
if ( $( navChild ).hasClass( 'NavContent' ) ) {
}
navChild.style.display = 'none';
}
function createCollapseButtons()
}
{
navToggle.firstChild.data = navigationBarShow;
    var tableIndex = 0;
    var NavigationBoxes = {};
// If hidden now
    var Tables = document.getElementsByTagName( "table" );
} else if ( navToggle.firstChild.data === navigationBarShow ) {
    var i;
for ( navChild = navFrame.firstChild; navChild !== null; navChild = navChild.nextSibling ) {
    for ( i = 0; i < Tables.length; i++ ) {
if ( $( navChild ).hasClass( 'NavContent' ) ) {
        if ( hasClass( Tables[i], "collapsible" ) ) {
navChild.style.display = 'block';
            NavigationBoxes[ tableIndex ] = Tables[i];
}
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
}
navToggle.firstChild.data = navigationBarHide;
            var Button    = document.createElement( "span" );
}
            var ButtonLink = document.createElement( "a" );
 
            var ButtonText = document.createTextNode( collapseCaption );
event.preventDefault();
}
            Button.style.styleFloat = "right";
 
            Button.style.cssFloat = "right";
/* [[Şablon:Yarımbaşlıq]] üçün */
            Button.style.fontWeight = "normal";
 
            Button.style.textAlign = "right";
function sousTitreH1( $content ) {
            Button.style.width = "6em";
$( '#firstHeading > #second_header_h1' ).remove();
var $span = $content.find( '#second_header_h1' );
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
if ( $span.length ) {
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
$span.prepend( ' ' );
            ButtonLink.appendChild( ButtonText );
$( '#firstHeading' ).append( $span );
}
            Button.appendChild( document.createTextNode( "[" ) );
}
            Button.appendChild( ButtonLink );
mw.hook( 'wikipage.content' ).add( sousTitreH1 );
            Button.appendChild( document.createTextNode( "]" ) );
 
/**
            var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
* Adds show/hide-button to navigation bars.
            /* only add button and increment count if there is a header row to work with */
*
            if (Header) {
* @param {jQuery} $content
                Header.insertBefore( Button, Header.childNodes[0] );
*/
                tableIndex++;
function createNavigationBarToggleButton( $content ) {
            }
var i, j, navChild, navToggle, navToggleText, isCollapsed,
        }
indexNavigationBar = 0;
    }
// Iterate over all < div >-elements
var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' );
    for ( i = 0; i < tableIndex; i++ ) {
$divs.each( function ( i, navFrame ) {
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
indexNavigationBar++;
            collapseTable( i );
navToggle = document.createElement( 'a' );
        }
navToggle.className = 'NavToggle';
    }
navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
}
navToggle.setAttribute( 'href', '#' );
$( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );
$( createCollapseButtons );
 
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';
}
}
}
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 ( 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 );
} );
}


/** Dynamic Navigation Bars (experimental) *************************************
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
  *
  *  Description: See [[Wikipedia:NavFrame]].
  *  Maintainers: UNMAINTAINED
  */
  // 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 ( 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 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 (hasClass(NavFrame.childNodes[j], "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);
        }
    }
 
  }
 
  $( createNavigationBarToggleButton );


  /** "Technical restrictions" title fix *****************************************
  /** "Technical restrictions" title fix *****************************************
Sətir 414: Sətir 422:
                         realTitleBanner.style.display = "none";
                         realTitleBanner.style.display = "none";
                 }
                 }
                 document.title = realTitleText + " - Wikipedia, the free encyclopedia";
                 document.title = realTitleText + " - Şəki Ensiklopediyası";
             }
             }
         }
         }
Sətir 571: Sətir 579:
var searchEngines = {
var searchEngines = {
   mediawiki: {
   mediawiki: {
     ShortName: "Şəki Ensiklopediyasında axtarış",
     ShortName: "Şəki Ensiklopediyası",
     Template: "/wiki/index.php?search={searchTerms}"
     Template: "/wiki/index.php?search={searchTerms}"
   },
   },
   globalwpsearch: {
   globalwpsearch: {
     ShortName: "Qlobal vikipediyalar",
     ShortName: "Vikipediya",
     Template: "http://vs.aka-online.de/cgi-bin/globalwpsearch.pl?timeout=120&search={searchTerms}"
     Template: "http://vs.aka-online.de/cgi-bin/globalwpsearch.pl?timeout=120&search={searchTerms}"
   },
   },
   google: {
   google: {
     ShortName: "Google",
     ShortName: "Google",
     Template: "http://www.google.cat/search?as_sitesearch=shaki.info&hl={language}&q={searchTerms}"
     Template: "http://www.google.cat/search?as_sitesearch=az.wikipedia.org&hl={language}&q={searchTerms}"
   },
   },
   wikiwix: {
   wikiwix: {
Sətir 588: Sətir 596:
   yahoo: {
   yahoo: {
     ShortName: "Yahoo!",
     ShortName: "Yahoo!",
     Template: "http://search.yahoo.com/search?p={searchTerms}&vs=shaki.info"
     Template: "http://search.yahoo.com/search?p={searchTerms}&vs=sheki.org"
   },
   },
   wlive: {
   wlive: {
     ShortName: "Windows Live",
     ShortName: "Windows Live",
     Template: "http://search.live.com/results.aspx?q={searchTerms}&q1=site:http://shaki.info"
     Template: "http://search.live.com/results.aspx?q={searchTerms}&q1=site:http://sheki.org"
   }
   }
};
};
Sətir 706: Sətir 714:
   }
   }
}
}


if (mw.config.get('wgCanonicalSpecialPageName') == "Search") {
if (mw.config.get('wgCanonicalSpecialPageName') == "Search") {
Sətir 713: Sətir 720:
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit") {
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit") {
   importScript('MediaWiki:Editpage.js');
   importScript('MediaWiki:Editpage.js');
  mw.loader.load('ext.gadget.wikificator');
}
}


Sətir 769: Sətir 777:
     }
     }
}
}
//</source>
//</source>
// Results from Wikidata
// Results from Wikidata
Sətir 776: Sətir 785:
}
}


    /**
* imgToggle
*/
// На странице есть как минимум один элемент div.img_toggle
if ( $( 'div.img_toggle' ).length ) {
mw.loader.load( 'ext.gadget.imgToggle' );
}
/**
/**
  * Magic editintros ****************************************************
  * Imagemap Highlight
  *
*/
  * Description: Adds editintros on disambiguation pages and BLP pages.
if ( $( '.imageMapHighlighter' ).length && $( '<canvas>' )[ 0 ].getContext ) {
  * Maintainers: [[User:RockMFR]]
importScript( 'MediaWiki:Imagemap-Highlight.js' );
}
/**
* imgToggle
*/
if ( $( 'div.img_toggle' ).length ) {
mw.loader.load( 'ext.gadget.imgToggle' );
}
/**  
* withJS
* İzah: URL keçidləri ilə MediaViki skriptlərinin işə salınması
* @mənbə: www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
*/
(function() {
    var extraJS = mw.util.getParamValue('withJS');
    if (extraJS) {
        if (extraJS.match(/^Media[VW]iki:[^&<>=%#]*\.js$/)) {
            importScript(extraJS);
        } else {
            mw.notify( 'Yalnız MediaViki ad fəzasındakı səhifələrə icazə verilir.', { title: 'Yanlış "withJS" dəyəri' } );
        }
    }
}());
 
/**
  * Magic editintros
  * İzah: Yaşayan insanların məqalələrini redaktə edərkən göstərilən xəbərdarlıq qutusu
  * Müəllif: [[User:RockMFR]]
  */
  */
function addEditIntro( name ) {
function addEditIntro( name ) {
$( '.mw-editsection, #ca-edit, #ca-ve-edit' ).find( 'a' ).each( function ( i, el ) {
$( '.mw-editsection, #ca-edit, #ca-ve-edit' ).find( 'a' ).each( function ( i, el ) {
el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
el.href = $( this ).attr( 'href' ) + '&editintro=' + name;
} );
}
if ( mw.config.get( 'wgNamespaceNumber' ) === 2 || mw.config.get( 'wgNamespaceNumber' ) === 3) {
$( function () {
if ( document.getElementById( 'userpageedn' ) ) {
addEditIntro( 'Şablon:Editnotice_userpage' );
}
} );
} );
}
}
Sətir 807: Sətir 846:
return;
return;
}
}
if ( $.inArray( 'Yaşayan insanlar', cats ) !== -1 || $.inArray( 'Yaşayan insanlar', cats ) !== -1 ) {
if ( $.inArray( 'Yaşayan insanlar', cats ) !== -1 || $.inArray( 'Yaşayan uzunömürlülər', cats ) !== -1 ) {
addEditIntro( 'Template:BLP_editintro' );
addEditIntro( 'Template:BLP_editintro' );
}
}
Sətir 813: Sətir 852:
}
}


$(function() {
// Web2Cit
mw.loader.load( '//en.wikipedia.org/w/index.php?title=User:Diegodlh/Web2Cit/script.js&action=raw&ctype=text/javascript' ); // Backlink: [[:en:User:Diegodlh/Web2Cit/script.js]]


var
// Naviqasiya panelində "İnzibatçıların iş bölgüsü" başlığının yerləşdirilməsi
//add this class to all elements created by the script. the reason is that we call the script again on
importScript("MediaWiki:SysopDuties.js");
//window resize, and use the class to remove all the "artefacts" we created in the previous run.
myClassName = 'imageMapHighlighterArtefacts',
liHighlightClass = 'liHighlighting',
specialAreaMark = 'area_mark',
specialLiClassesMark = 'list_classes',
specialAreaMarkFile = 'area_mark_file',
// "2d context" attributes used for highlighting.
areaHighLighting = {
fillStyle: 'rgba(0,0,0,0.35)',
strokeStyle: 'yellow',
lineJoin: 'round',
lineWidth: 2
},
//every imagemap that wants highlighting, should reside in a div of this 'class':
hilightDivMarker = '.imageMapHighlighter',
// specifically for wikis - redlinks tooltip adds this message
ru = mw && mw.config && mw.config.get('wgUserLanguage') == 'ru',
expandLegend = ru ? 'показать ссылки текстом' : 'sıyahını aç',
collapseLegend = ru ? 'скрыть ссылки текстом' : 'siyahını bağla',
files = [];
 
 
function drawMarker(context, areas) { // this is where the magic is done.
 
function drawPoly(coords) {
context.moveTo(coords.shift(), coords.shift());
while (coords.length)
context.lineTo(coords.shift(), coords.shift());
}
 
for (var i in areas) {
var coords = areas[i].coords.split(',');
context.beginPath();
switch (areas[i].shape) {
case 'rect':
drawPoly([coords[0], coords[1], coords[0], coords[3], coords[2], coords[
3], coords[2], coords[1]]);
break;
case 'circle':
context.arc(coords[0], coords[1], coords[2], 0, Math.PI * 2);
break; //x,y,r,startAngle,endAngle
case 'poly':
drawPoly(coords);
break;
}
context.closePath();
context.stroke();
context.fill();
}
}
 
function mouseAction(e) {
var $this = $(this),
activate = e.type == 'mouseover',
caption = $this.text(),
ol = $this.parent(),
context = ol.data('context'),
special = ol.data(specialAreaMark),
specialFile = ol.data(specialAreaMarkFile); //read JSON file addition
 
if (specialFile) {
if (files[specialFile]) {
$.extend(special, files[specialFile]);
always(activate, caption, context, ol, special, $this);
} else {
$.get(mw.util.wikiScript(), {
title: specialFile,
action: 'raw'
})
.done(function(data) {
files[specialFile] = JSON.parse(data);
$.extend(special, files[specialFile]);
})
.always(function() {
always(activate, caption, context, ol, special, $this);
});
}
} else
always(activate, caption, context, ol, special, $this);
}
 
function always(activate, caption, context, ol, special, $this) {
$this.toggleClass(liHighlightClass, activate); // mark/unmark the list item.
 
context.clearRect(0, 0, context.canvas.width, context.canvas.height); // prepare for a new day.
 
ol.find('li')
.each(function() {
var $li = $(this);
var licap = $li.text();
var param;
if (activate && licap === caption) { // highlight!!!
param = special && (special.hover && special.hover[licap]
|| getblocks(special, licap)) || areaHighLighting;
} else {
param = special && special.nover && (special.nover[licap] || special.nover
.default);
}
if (param) {
$.extend(context, param);
drawMarker(context, $li.data('areas'));
}
});
}
 
function getblocks(special, licap) {
if (special.hoverblocks) {
if (special.hoverblocks[licap])
return special.hoverblocks[licap].value;
for (var key in special.hoverblocks)
if (special.hoverblocks[key] && special.hoverblocks[key].list.indexOf(licap) >=0 )
return special.hoverblocks[key].value;
}
if (special.hover)
return special.hover.default;
}
function handleOneMap() {
var img = $(this),
w = img.width(),
h = img.height(),
infoIcon = img.next(),
parent = img.parent(),
map = img.siblings('map:first'),
dims = {
position: 'absolute',
width: w + 'px',
height: h + 'px',
border: 0,
top: 0,
left: 0
},
specialHighlight = img.closest(hilightDivMarker)
.data(specialAreaMark),
specialLiClasses = img.closest(hilightDivMarker)
.data(specialLiClassesMark),
specialHover = img.closest(hilightDivMarker)
.data(specialAreaMarkFile);
 
if (!('area', map)
.length)
return; //not an imagemap. inside "each" anonymous function, 'return' means "continue".
 
var jcanvas = $('<canvas>', {
'class': myClassName
})
.css(dims)
.attr({
width: w,
height: h
});
var bgimg = $('<img>', {
'class': myClassName,
src: img.attr('src')
})
.css(dims); //completely inert image. this is what we see.
var context = $.extend(jcanvas[0].getContext("2d"), areaHighLighting);
 
// this is where the magic is done: prepare a sandwich of the inert bgimg at the bottom,
// the canvas above it, and the original image on top,
// so canvas won't steal the mouse events.
// pack them all TIGHTLY in a newly minted "relative" div, so when page chnage
// (other scripts adding elements, window resize etc.), canvas and imagese remain aligned.
var div = $('<div>')
.css({
position: 'relative',
width: w + 'px',
height: h + 'px'
});
img.before(div); // put the div just above the image, and ...
div.append(bgimg) // place the background image in the div
.append(jcanvas) // and the canvas. both are "absolute", so they don't occupy space in the div
.append(img); // now yank the original image from the window and place it on the div.
img.fadeTo(1, 0); // make the image transparent - we see canvas and bgimg through it.
// the original, now transparent image is creating our mouse events
 
infoIcon.css({
position: 'relative'
}); // set position to info icon
var ol = $('<ol>', {
'class': myClassName
})
.css({
clear: 'both',
margin: 0,
listStyle: 'none',
maxWidth: w + 'px',
position: 'relative'
})
.data(specialAreaMark, specialHighlight)
.data(specialAreaMarkFile, specialHover)
.data('context', context);
var oldiv = $('<div>')
.html(ol)
.css({
clear: 'both',
margin: 0,
listStyle: 'none',
maxWidth: w + 'px',
position: 'relative'
})
.attr({
'data-expandtext': expandLegend,
'data-collapsetext': collapseLegend
});
 
// ol below image parent, hr below ol. original caption pushed below hr.
parent.after($('<hr>', {
'class': myClassName
})
.css('clear', 'both'))
.after(oldiv);
$('<hr>', {
'class': myClassName
})
.css('clear', 'both')
.insertBefore($(oldiv));
var lis = {}; //collapse areas with same caption to one list item
var someli; // select arbitrary one
$('area', map)
.each(function() {
var text = this.title;
var li = lis[text]; // title already met? use the same li
if (!li) { //no? create a new one.
var href = this.href;
lis[text] = li = $('<li>', {
'class': myClassName
})
.append($('<a>', {
href: href,
text: text
}))
.on('mouseover mouseout', mouseAction)
.data('areas', [])
.addClass(specialLiClasses && (specialLiClasses[text] ||
specialLiClasses['default']))
.appendTo(ol);
if (specialLiClasses && specialLiClasses[text + ' super'])
li.find('a')
.addClass(specialLiClasses[text + ' super']);
}
li.data('areas')
.push(this); //add the area to the li
someli = li; // whichever - we just want one...
$(this)
.on('mouseover mouseout', function(e) {
li.trigger(e);
});
});
if (someli) someli.trigger('mouseout');
oldiv.addClass('mw-collapsed')
.makeCollapsible();
ol.attr('style', ol.attr('style')
.replace('none', 'disc'));
}
 
function init() {
mw.util.addCSS('li.' + myClassName +
'{white-space:nowrap; font-size:88.36%;}\n' + //css for li element
'li.' + liHighlightClass + '{background-color:yellow;}\n' + //css for highlighted li element.
'.rtl li.' + myClassName + '{float: right; margin-left: 1.5em;}\n' +
'.ltr li.' + myClassName + '{float: left; margin-right: 1.5em;}\n' +
hilightDivMarker + ' .mw-collapsible-toggle {float: none}');
$(hilightDivMarker + ' img')
.each(handleOneMap);
}
 
//has at least one "imagehighlight" div, and canvas-capable browser:
if ($(hilightDivMarker)
.length && $('<canvas>')[0].getContext)
mw.loader.using(['jquery.makeCollapsible', 'mediawiki.util'])
.done(init);
});