MediaWiki:Common.js

/* Javascript inkluderet her vil være aktivt for alle brugere. */

/**
 * WikiMiniAtlas is a popup click and drag world map.
 * See [[meta:WikiMiniAtlas]] for more information.
 * Maintainers: [[w:User:Dschwen]]
 */
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript' );


/**
 * 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);
};
})();

	/**
	 * Koperet og indsat fra en:MediaWiki:Common.js 2024-04-22
	 * Collapsible tables; reimplemented with mw-collapsible
	 * Styling is also in place to avoid FOUC
	 *
	 * Allows tables to be collapsed, showing only the header. See [[Help:Collapsing]].
	 * @version 3.0.0 (2018-05-20)
	 * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTables.js
	 * @author [[User:R. Koot]]
	 * @author [[User:Krinkle]]
	 * @author [[User:TheDJ]]
	 * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which
	 * is supported in MediaWiki core. Shimmable since MediaWiki 1.32
	 *
	 * @param {jQuery} $content
	 */
	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 );

	/**
	 * Koperet og indsat fra en:MediaWiki:Common.js 2024-04-22
	 * 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 (Updated for T333357 2023-04-29)
				if ( $toggle.parent()[ 0 ].style.color ) {
					$toggle.css( 'color', 'inherit' );
					$toggle.find( '.mw-collapsible-text' ).css( 'color', 'inherit' );
				}
			}
		} );
	}

	mw.hook( 'wikipage.collapsibleContent' ).add( mwCollapsibleSetup );

/**
 * Flyt portallinks
 *
 *  Beskrivelse: Flytter portallinks op i toppen af siden. Bruges af [[:Skabelon:Portaltop]]
 */
$( function () {
  try {
    var x = document.getElementById('siteSub');
    if(!x) return;
    var y = document.getElementById('portlinks');
    if(!y) return;
    var str = y.innerHTML;
    if (str.length) str = str.replace(/(?: | |\u00a0|\u000d|\x0d|\r|\u000a|\x0a|\n)*(?:·|·|\|)(?: | |\u00a0|\u000d|\x0d|\r|\u000a|\x0a|\n)*/g, ", ");
    y = y.parentNode;
    if(!y) return;
    y.parentNode.removeChild(y);
    x.innerHTML = str;
  }
  catch (e) {
    // Woopsie, die without a notice
  }
});
// Flyt portallinks slut


// OpenStreetMap til at  åbne i artikler med koordinater - ligger i egen js fil. Inkludert af [[Bruger:Nico]] efter vejledning af  [[:no:Bruker:Haros]]

 mw.config.set( 'osm_proj_map', 'kort' ); //"map" in project language
 mw.config.set( 'osm_proj_lang', 'da' );  //project language
 mw.loader.load('//meta.wikimedia.org/w/index.php?title=MediaWiki:OSM.js&action=raw&ctype=text/javascript');

/**
 * iProject (InterProjectLinks)
 * Written by: Erwin ([[:nl:MediaWiki:IProject.js]]), modified by Kildor
 * Description: Adds links to other WMF projects in the sidebar
 *   ([[:bugzilla:708]]). Works for all skins with a sidebar.
 *
 * Originally written by Magnus Manske. Version forked from
 *   [[:es:MediaWiki:Common.js]] and [[:de:wikt:Mediawiki:monobook.js]]
 */

function iProject() {
    // Find templates with interproject links. These templates should have a div
    // with class 'interProject' that only contains a link to the other project.
    iProjectLinks = $('div.interProject').toArray();

    if (iProjectLinks.length > 0) {
        // The element below should always be available. To not break code
        // we do check for it, but don't have a fallback.
        if (document.getElementById('p-tb')) {
            prevNode = document.getElementById('p-tb');
        } else {
            return false;
        }

        // Clone previous node including child nodes.
        interProject = prevNode.cloneNode(true);
        interProject.id = 'p-project';

        // Set header of new toolbox
        h = interProject.getElementsByTagName('h5');
        if(h[0]) {
            h[0].innerHTML = 'På andre projekter';
        }

        // The links are included in the first and only div of the toolbox
        d = interProject.getElementsByTagName('div');
        if(d[0]) {
            d = d[0];
        } else {
            return false;
        }

        // Remove current children, i.e. current ul element.
        while(d.hasChildNodes()) {
            d.removeChild(d.childNodes[0])
        }

        // Create new list with links
        ul = document.createElement('ul')
        ul.className += " interProject";
        for (i = 0; i< iProjectLinks.length; i++) {
            li = document.createElement('li');
            li.className += " " + iProjectLinks[i].className;
            li.innerHTML = iProjectLinks[i].innerHTML;
            ul.appendChild(li)
        }
        d.appendChild(ul);

        // Insert new node
        prevNode.parentNode.insertBefore(interProject, prevNode.nextSibling);
    }
}

$(iProject);


//Søg i Wikidata
mw.loader.load('//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript');

/* End */

/* indsæt fra [[Bruger:Murma174/common.js]] iflg
 */

//*** Configuration for "star" logo in front of interwiki links to Featured Articles
//*** and green symbol in front of interwiki links to Good Articles
/** set in Special:Mypage/common.js to switch off this "feature"
mw.user.options.set( 'linkFA_enabled', false );
 * star logo for featured articles in other languages,
 * see Template:Link_FA / Template:Link_GA and MediaWiki:Common.css
 */
mw.loader.using( [ 'user', 'mediawiki.user', 'user.options' ], function() { $(function() {
    /** description that is displayed when cursor hovers above FA interwiki links */
    var linkFA_description = "Denne artikel er markeret som en fremragende artikel";
    var linkGA_description = "Denne artikel er markeret som en god artikel";

    // linkFA_bullet/linkGA_bullet and linkFA_style/linkGA_Style wird nur für cologneblue verwendet,
    // für monobook, modern siehe [[MediaWiki:Common.css]], vector hat in [[MediaWiki:Vector.css]] eigene Definitionen

    /** image to use instead of the standard bullet (for cologneblue) */
    var linkFA_bullet = "//upload.wikimedia.org/wikipedia/commons/d/d0/Monobook-bullet-star-transparent.png";
    var linkGA_bullet = "//upload.wikimedia.org/wikipedia/commons/a/a1/Monobook-bullet-star-gray.png";

    /** style to use for the linkFA_bullet/LinkGA_bullet img */
    var linkFA_style = "margin-right: 0.2em;";
    var linkGA_style = "margin-right: 0.2em;";

    // early exit when disabled
    if ( !mw.user.options.get( 'linkFA_enabled', true ) ) {
        return;
    }

    // skins that can be handled the CSS class way
    var skin = mw.config.get( 'skin' );
    if (skin === "monobook" || skin === "modern" || skin === "vector" ) {
        linkFA_CSS();
    }
    else if (skin === "cologneblue") {
        linkFA_decorate();
    }

    /** skin == "monobook" || skin="modern" || skin== "vector" */
    function linkFA_CSS() {
        // links are to replaced in p-lang only
        var pLang = document.getElementById("p-lang");
        if (!pLang) return;
        var lis = pLang.getElementsByTagName("li");
        for (var i = 0; i < lis.length; i++) {
            var li = lis[i];
            //extract necessary classname
            var matches = li.className.match( /(?:^| )(interwiki-[^ ]+)(?: |$)/ );
            if ( !matches || matches.length != 2 ) {
                 continue;
            }
            var className = matches[1];
            // only links with a corresponding Link_FA template are interesting
            if (document.getElementById(className + "-fa") && li.className.indexOf("badge-featuredarticle") === -1) {
              li.className += " FA";         // additional class so the template can be hidden with CSS
              li.title = linkFA_description; // change title
              continue;
            }
            if (document.getElementById(className + "-ga") && li.className.indexOf("badge-goodarticle") === -1) {
              li.className += " GA";         // additional class so the template can be hidden with CSS
              li.title = linkGA_description; // change title
              continue;
            }
        }
    }

    /** skin == "cologneblue" */
    function linkFA_decorate() {
        // these root elements can contain FA-/GA-links
        var rootIds = new Array("topbar", "footer");
        for (var i=0; i<rootIds.length; i++) {
            var root    = document.getElementById(rootIds[i]);
            if (!root)  continue;

            // if the root exists, try to decorate all the links within
            var links   = root.getElementsByTagName("a");
            for (var j=0; j<links.length; j++) {
                decorate(links[j], "-fa", linkFA_bullet, linkFA_description, linkFA_style);
                decorate(links[j], "-ga", linkGA_bullet, linkGA_description, linkGA_style);
            }
        }
    }

    /** id necessary, modify a link to show the FA- or GA-star (older) */
    function decorate(link, idSuffix, bullet, description, style) {
        var lang    = link.hostname.split(".")[0];
        var fa      = document.getElementById("interwiki-" + lang + idSuffix);
        if (!fa)  return;

  // build an image-node for the FA-star
  var img = document.createElement("img");
  img.setAttribute("src",     bullet);
  img.setAttribute("alt",     description);
  img.setAttribute("style",   style);
  // decorate the link with the image
  link.appendChild(img);
  link.appendChild(link.removeChild(link.firstChild));
  link.setAttribute("title", description);
    }
})});

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.