User:Emanuele/smfcurve.js From Online Manual

Jump to: navigation, search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
function create_translation_dropdown ()
{
var translation_bar = document.getElementById('translation_bar');
var avail_languages = translation_bar.getElementsByTagName('a');
// Get the <td> where the list is
var tds = translation_bar.getElementsByTagName('td');
for (var i = 0; i < tds.length; i++)
	if (tds[i].className == 'mw-pt-languages-list')
		var list_position = tds[i];

var tSelect = document.createElement('select');
tSelect.onchange = function() {
	window.location = this.options[this.selectedIndex].value;
};

var tSelectLang = document.createElement('option');
tSelectLang.value = window.location.href;
tSelectLang.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);';
tSelectLang.appendChild(document.createTextNode('Select your language'));
tSelect.appendChild(tSelectLang);

var tEnglish = document.createElement('option');
tEnglish.value = getEnglishPage(window.location.href);
tEnglish.style = 'background: url(http://wiki.simplemachines.org/extensions/Translate/images/prog-5.png) rgba(0,0,0,0);';
tEnglish.appendChild(document.createTextNode('English'));
tSelect.appendChild(tEnglish);

var langs = avail_languages.length;
for (var i = 0; i < langs; i++)
{
	var tOption = document.createElement('option');
	tOption.value = avail_languages[0].href;
	var tImg = avail_languages[0].getElementsByTagName('img')[0];
	if (tImg == undefined)
		continue;
	tOption.style = 'background: url(' + tImg.src + ') rgba(0,0,0,0);';
	avail_languages[0].removeChild(tImg);
	if (avail_languages[0].innerHTML.replace(/^\s\s*/, '').replace(/\s\s*$/, '') != '')
	{
		tOption.appendChild(document.createTextNode(avail_languages[0].innerHTML));
		tSelect.appendChild(tOption);
	}
	avail_languages[0].parentNode.removeChild(avail_languages[0]);
}
list_position.innerHTML = '';
list_position.appendChild(tSelect);
}

function getEnglishPage(aUrl)
{
	aUrl.replace(aUrl.substr(aUrl.lastIndexOf('/') + 1), '');
}


/******************************************************
License:

(The MIT License)

Copyright © 2010 Jakob Mattsson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************/
/*
  https://github.com/jakobmattsson/onDomReady

  onDomReady, Copyright © 2010 Jakob Mattsson

  This is a small implementation of an onDomReady-function, for situations when frameworks are no-no.
  It's loosely based on jQuery's implementation of $.ready, Copyright (c) 2010 John Resig, http://jquery.com/
*/

(function() {

  var onDomReadyIdentifier = 'onDomReady';
  var isBound = false;
  var readyList = [];

  if (window[onDomReadyIdentifier] && typeof window[onDomReadyIdentifier] == 'function') {
    return;
  }

  var whenReady = function() {
    // Make sure body exists, at least, in case IE gets a little overzealous.
    // This is taked directly from jQuery's implementation.
    if (!document.body) {
      return setTimeout(whenReady, 13);
    }

    for (var i=0; i<readyList.length; i++) {
      readyList[i]();
    }
    readyList = [];
  };

  var bindReady = function() {
    // Mozilla, Opera and webkit nightlies currently support this event
    if (document.addEventListener) {
      var DOMContentLoaded = function() {
        document.removeEventListener("DOMContentLoaded", DOMContentLoaded, false);
        whenReady();
      };
      
      document.addEventListener("DOMContentLoaded", DOMContentLoaded, false);
      window.addEventListener("load", whenReady, false); // fallback
      
      // If IE event model is used
    } else if (document.attachEvent) {
      
      var onreadystatechange = function() {
        if (document.readyState === "complete") {
          document.detachEvent("onreadystatechange", onreadystatechange);
          whenReady();
        }
      };
      
      document.attachEvent("onreadystatechange", onreadystatechange);
      window.attachEvent("onload", whenReady); // fallback

      // If IE and not a frame, continually check to see if the document is ready
      var toplevel = false;

      try {
        toplevel = window.frameElement == null;
      } catch(e) {}

      // The DOM ready check for Internet Explorer
      if (document.documentElement.doScroll && toplevel) {
        var doScrollCheck = function() {

          // stop searching if we have no functions to call 
          // (or, in other words, if they have already been called)
          if (readyList.length == 0) {
            return;
          }

          try {
            // If IE is used, use the trick by Diego Perini
            // http://javascript.nwbox.com/IEContentLoaded/
            document.documentElement.doScroll("left");
          } catch(e) {
            setTimeout(doScrollCheck, 1);
            return;
          }

          // and execute any waiting functions
          whenReady();
        }  
        doScrollCheck();
      }
    } 
  };

  window[onDomReadyIdentifier] = function(callback) {
    // Push the given callback onto the list of functions to execute when ready.
    // If the dom has alredy loaded, call 'whenReady' right away.
    // Otherwise bind the ready-event if it hasn't been done already
    readyList.push(callback);
    if (document.readyState == "complete") {   
      whenReady();
    } else if (!isBound) {
      bindReady();
      isBound = true;
    }
  };
})();

onDomReady(create_translation_dropdown());


Advertisement: