MediaWiki:Common.js

   

Fra Villmark

Gå til: navigasjon, søk

Merk: Etter lagring vil det kanskje være nødvendig at nettleseren sletter mellomlageret sitt for at endringene skal tre i kraft. Mozilla og Firefox: trykk Ctrl-Shift-R, Internet Explorer: Ctrl-F5, Safari: Cmd-Shift-R i engelskspråklig versjon, Cmd-Alt-E i norskspråklig versjon, Konqueror og Opera: F5.

/* Javascript i denne fila vil gjelde for alle drakter. */

// Remove sitenotice for anonymous users, must be added several days before it is actually used!
/*
if (!wgUserName) {
    addOnloadHook( function () {
        try {
            var x = document.getElementById('siteNotice');
            if (x) x.style.display = 'none';
        }
        catch (e) {
            // just go away without notice 
        }
    });
}
*/

/** Change Special:Search to use a radio menu *******************************************************
   *
   *  Description: Change Special:Search to use a radio menu, with the default being
   *               the internal MediaWiki engine
   *  Created and maintained by: [[:fr:User:Pmartin]]
   */
 
if ((wgNamespaceNumber == -1) && (wgCanonicalSpecialPageName == "Search")) {
	var searchEngines = {
	  mediawiki: {
	    ShortName: "MediaWiki-søk",
	    Template: "/w/index.php?search={searchTerms}"
	  },
	  google: {
	    ShortName: "Google",
	    Template: "http://www.google.no/search?hl=" + wgUserLanguage + "&q={searchTerms}&as_sitesearch=" + wgServer.substr(7, wgServer.length - 1 )
	  },
	  yahoo: {
	    ShortName: "Yahoo",
	    Template: "http://" + wgUserLanguage + ".search.yahoo.com/search?p={searchTerms}&vs=" + wgServer
	  },
	  wikiwix: {
	    ShortName: "Wikiwix",
            Template: "http://www.wikiwix.com/index.php?action={searchTerms}&lang="+wgContentLanguage
	  },
          wikiseek: {
            ShortName: "Wikiseek",
	    Template: "http://www.wikiseek.com/?q={searchTerms}&lang="+wgContentLanguage
          }
	};
	addOnloadHook(externalSearchEngines);
}
 

function externalSearchEngines() {
 
  if (typeof SpecialSearchEnhanced2Disabled != 'undefined') return;
 
  var mainNode;
  if (document.forms["search"]) { 
    mainNode = document.forms["search"];
  } else {
    mainNode = document.getElementById("powersearch");
    if (!mainNode) return;
    var mainNode = mainNode.lastChild;
    if (!mainNode) return;
 
    while(mainNode.nodeType == 3) {
      mainNode = mainNode.previousSibling;
    }
  }
 
  var firstEngine = "mediawiki";
 
  var choices = document.createElement("div");
  choices.setAttribute("id","searchengineChoices");
  choices.style.textAlign = "center";
 
  var lsearchbox = document.getElementById("powerSearchText");
  var initValue = lsearchbox.value;
 
  var space = "";
 
  for (var id in searchEngines) {
    var engine = searchEngines[id];
	if(engine.ShortName)
	   {
	    if (space) choices.appendChild(space);
	    space = document.createTextNode(" ");
 
	    var attr = { 
	      type: "radio", 
	      name: "searchengineselect",
	      value: id,
	      onFocus: "changeSearchEngine(this.value)",
	      id: "searchengineRadio-"+id
	    };
 
	    var html = "<input";
	    for (var a in attr) html += " " + a + "='" + attr[a] + "'";
	    html += " />";
	    var span = document.createElement("span");
	    span.innerHTML = html;
 
	    choices.appendChild( span );
	    var label = document.createElement("label");
	    label.htmlFor = "searchengineRadio-"+id;
 
	    label.appendChild( document.createTextNode( engine.ShortName ) );
	    choices.appendChild( label );
	  }
	 }
	  mainNode.appendChild(choices);
 
	  var input = document.createElement("input");
	  input.id = "searchengineextraparam";
	  input.type = "hidden";
 
	  mainNode.appendChild(input);
 
	  changeSearchEngine(firstEngine, initValue);
}
 
function changeSearchEngine(selectedId, searchTerms) {
 
	  var currentId = document.getElementById("searchengineChoices").currentChoice;
	  if (selectedId == currentId) return;
 
	  document.getElementById("searchengineChoices").currentChoice = selectedId;
	  var radio = document.getElementById('searchengineRadio-'  + selectedId);
	  radio.checked = "checked";
 
	  var engine = searchEngines[selectedId];
	  var p = engine.Template.indexOf('?');
	  var params = engine.Template.substr(p+1);
 
	  var form;
	  if (document.forms["search"]) {
	    form = document.forms["search"];
	  } else {
	    form = document.getElementById("powersearch");
	  }
	  form.setAttribute("action", engine.Template.substr(0,p));
 
	  var l = ("" + params).split("&");
	  for (var i in l) {
	    var p = l[i].split("=");
	    var pValue = p[1];
 
	    if (pValue == "{language}") {
	    } else if (pValue == "{searchTerms}") {
	      var input;
	      if (document.forms["search"]) {
	        input = document.getElementById("searchText");
	      } else {
	        input = document.getElementById("powerSearchText");
	      } 
 
	      input.name = p[0];
	    } else {
	      var input = document.getElementById("searchengineextraparam");
 
	      input.name = p[0];
	      input.value = pValue;
	    }
	  }
}

 //********Internasjonalt ********************
 function mainPageAppendCompleteListLink() {
     try {
         var node = document.getElementById( "p-lang" )
                            .getElementsByTagName('div')[0]
                            .getElementsByTagName('ul')[0];
 
         var aNode = document.createElement( 'a' );
         var liNode = document.createElement( 'li' );
 
         aNode.appendChild( document.createTextNode( 'Alle språk' ) );
         aNode.setAttribute( 'href' , 'http://no.wikipedia.org/wiki/Wikipedia:Internasjonalt' );
         liNode.appendChild( aNode );
         liNode.className = 'interwiki-completelist';
         node.appendChild( liNode );
      } catch(e) {
        // lets just ignore what's happened
        return;
     }
 }
 
 if ( wgTitle == 'Hovedside' && wgNamespaceNumber == 0 ) {
        addOnloadHook( mainPageAppendCompleteListLink );
 }
 //********Internasjonalt slutt ********************


/** Linjekart: Vis/skjul definerte seksjoner ***** */

 importScript('MediaWiki:Linjekart.js')


/** Multibilde: Klikkbare bildeserier ***** */

 importScript('MediaWiki:Multibilde.js')


/** Interwikilenker: sortering, lokalisering og babel ***** */

 if (!wgUserName
     || (wgUserName
         && (((typeof wgLangPrefs == 'undefined') ? false : true)
             || ((typeof wgUseBabelLinks == 'undefined') ? false : wgUseBabelLinks)
             || ((typeof wgUseUserLanguage == 'undefined') ? false : wgUseUserLanguage))))
     importScript('MediaWiki:Interwiki-links.js');


/** Redigeringslenker: endrer plassering av redigeringslenker for seksjoner ***** */
 
 if ((typeof wgNoChangeEditLink == 'undefined') ? true : !wgNoChangeEditLink)
     importScript('MediaWiki:Change-editlink.js');

/** Infobokser: No Indexing ***** 
 importScript('MediaWiki:Gadget-menu-index.js')

/** Infobokser: Vis/skjul, samt samle ***** 
 *
 *  Dersom dette skriptet ikke står sist blir [vis/skjul]-knappen ikke vist i Opera.
 *  Testet med Opera 9.26, IE 6.0 hadde ingen problemer med at skriptet ikke sto sist.
 *  -- [[Bruker:BjørnN|BjørnN]] 10. mar 2008 kl. 21:23 (CET)
 */

 importScript('MediaWiki:Visskjul.js')

/** Tabellsorteringsfix
  * Hack för att få sorterbara tabeller att sortera korrekt med komma som decimalseparator och
  * punkt som tusentalsseparator.
  * 
  * /[[Användare:Skagedal]]
  */
function ts_parseFloat(num) {
        if (!num) return 0;
        num = num.replace(/\./g, "");
        num = num.replace(/,/, ".");
        num = parseFloat(num);
        return (isNaN(num) ? 0 : num);
}

if (skin != 'simple' && skin != 'nostalgia' && (wgAction == 'edit' || wgAction == 'submit')) {
  importScript('MediaWiki:CustomEditButtons.js')
}


/**
 * Brukt av Mal:Scroll gallery
 */
function toggleImage(group, remindex, shwindex) {
   document.getElementById("ImageGroupsGr"+group+"Im"+remindex).style.display="none";
   document.getElementById("ImageGroupsGr"+group+"Im"+shwindex).style.display="inline";
}
 
function imageGroup(){
  if (document.URL.match(/printable/g)) return;
  var bc=document.getElementById("bodyContent");
  if( !bc ) bc = document.getElementById("mw_contentholder");
  if( !bc ) return;
  var divs=bc.getElementsByTagName("div");
  var i = 0, j = 0;
  var units, search;
  var currentimage;
  var UnitNode;
  for (i = 0; i < divs.length ; i++) {
    if (divs[i].className != "ImageGroup") continue;
    UnitNode=undefined;
    search=divs[i].getElementsByTagName("div");
    for (j = 0; j < search.length ; j++) {
      if (search[j].className != "ImageGroupUnits") continue;
      UnitNode=search[j];
      break;
    }
    if (UnitNode==undefined) continue;
    units=Array();
    for (j = 0 ; j < UnitNode.childNodes.length ; j++ ) {
      var temp = UnitNode.childNodes[j];
      if (temp.className=="center") units.push(temp);
    }
    for (j = 0 ; j < units.length ; j++) {
      currentimage=units[j];
      currentimage.id="ImageGroupsGr"+i+"Im"+j;
      var imghead = document.createElement("div");
      var leftlink;
      var rightlink;
      if (j != 0) {
        leftlink = document.createElement("a");
        leftlink.href = "javascript:toggleImage("+i+","+j+","+(j-1)+");";
        leftlink.innerHTML="â—€";
      } else {
        leftlink = document.createElement("span");
        leftlink.innerHTML="&nbsp;";
      }
      if (j != units.length - 1) {
        rightlink = document.createElement("a");
        rightlink.href = "javascript:toggleImage("+i+","+j+","+(j+1)+");";
        rightlink.innerHTML="â–¶";
      } else {
        rightlink = document.createElement("span");
        rightlink.innerHTML="&nbsp;";
      }
      var comment = document.createElement("tt");
      comment.innerHTML = "("+ (j+1) + "/" + units.length + ")";
      with(imghead) {
        style.fontSize="110%";
        style.fontweight="bold";
        appendChild(leftlink);
        appendChild(comment);
        appendChild(rightlink);
      }
      currentimage.insertBefore(imghead,currentimage.childNodes[0]);
      if (j != 0) currentimage.style.display="none";
    }
  }
}
addOnloadHook(imageGroup);
Personlige verktøy