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 */
| |
| // Switch language variants of messages (from zh) | | // Switch language variants of messages (from zh) |
| function wgULS(latn,arab){ | | function wgULS(latn,arab){ |
Sətir 97: |
Sətir 96: |
| } | | } |
| }); | | }); |
− |
| |
− | /* 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 104: |
| * Maintainers: [[User:R. Koot]] | | * Maintainers: [[User:R. Koot]] |
| */ | | */ |
| + | |
| + | /** |
| + | * NAVFRAME |
| + | */ |
| | | |
| //Messages | | //Messages |
Sətir 128: |
Sətir 117: |
| 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 152: |
| | | |
| | | |
− | /** 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 [[Wikipedia: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 + ']'; |
− | {
| + | var navigationBarShow = '[' + expandCaption + ']'; |
− | 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";
| + | /** |
− | Button.style.fontWeight = "normal";
| + | * Adds show/hide-button to navigation bars. |
− | Button.style.textAlign = "right";
| + | * |
− | Button.style.width = "6em";
| + | * @param {jQuery} $content |
− |
| + | */ |
− | ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
| + | function createNavigationBarToggleButton( $content ) { |
− | ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
| + | var i, j, navChild, navToggle, navToggleText, isCollapsed, |
− | ButtonLink.appendChild( ButtonText );
| + | indexNavigationBar = 0; |
− |
| + | // Iterate over all < div >-elements |
− | Button.appendChild( document.createTextNode( "[" ) );
| + | var $divs = $content.find( 'div.NavFrame:not(.mw-collapsible)' ); |
− | Button.appendChild( ButtonLink );
| + | $divs.each( function ( i, navFrame ) { |
− | Button.appendChild( document.createTextNode( "]" ) );
| + | indexNavigationBar++; |
− |
| + | navToggle = document.createElement( 'a' ); |
− | var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
| + | navToggle.className = 'NavToggle'; |
− | /* only add button and increment count if there is a header row to work with */
| + | navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar ); |
− | if (Header) {
| + | navToggle.setAttribute( 'href', '#' ); |
− | Header.insertBefore( Button, Header.childNodes[0] );
| + | $( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) ); |
− | tableIndex++;
| + | |
− | }
| + | 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" |
− | for ( i = 0; i < tableIndex; i++ ) {
| + | * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make |
− | if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
| + | * the content visible without JavaScript support), the new recommended way is to add the class |
− | collapseTable( i );
| + | * "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' ) { |
− | $( createCollapseButtons );
| + | 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 571: |
Sətir 533: |
| var searchEngines = { | | var searchEngines = { |
| mediawiki: { | | mediawiki: { |
− | ShortName: "Şəki Ensiklopediyasında axtarış", | + | ShortName: "MediaWiki axtarışı", |
− | Template: "/encyclopedia/index.php?search={searchTerms}" | + | Template: "/w/index.php?search={searchTerms}" |
| }, | | }, |
| globalwpsearch: { | | globalwpsearch: { |
Sətir 580: |
Sətir 542: |
| google: { | | google: { |
| ShortName: "Google", | | ShortName: "Google", |
− | Template: "http://www.google.cat/search?as_sitesearch=sheki.wiki&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 550: |
| yahoo: { | | yahoo: { |
| ShortName: "Yahoo!", | | ShortName: "Yahoo!", |
− | Template: "http://search.yahoo.com/search?p={searchTerms}&vs=sheki.wiki" | + | Template: "http://search.yahoo.com/search?p={searchTerms}&vs=az.wikipedia.org" |
| }, | | }, |
| wlive: { | | wlive: { |
| ShortName: "Windows Live", | | ShortName: "Windows Live", |
− | Template: "http://search.live.com/results.aspx?q={searchTerms}&q1=site:http://sheki.wiki" | + | Template: "http://search.live.com/results.aspx?q={searchTerms}&q1=site:http://az.wikipedia.org" |
| } | | } |
| }; | | }; |
Sətir 776: |
Sətir 738: |
| } | | } |
| | | |
| + | |
| + | /** |
| + | * Imagemap Highlight |
| + | */ |
| + | // На странице есть как минимум один элемент .imageMapHighlighter, а браузер поддерживает <canvas> |
| + | if ( $( '.imageMapHighlighter' ).length && $( '<canvas>' )[ 0 ].getContext ) { |
| + | importScript( 'MediaWiki:Imagemap-Highlight.js' ); |
| + | } |
| /** | | /** |
| * imgToggle | | * imgToggle |
Sətir 812: |
Sətir 782: |
| } ); | | } ); |
| } | | } |
− |
| |
− | $(function() {
| |
− |
| |
− | var
| |
− | //add this class to all elements created by the script. the reason is that we call the script again on
| |
− | //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);
| |
− | });
| |