MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */ //

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images.wikia.com/redwall/images/c/c9/Button_strike.png", "speedTip": "Strike", "tagOpen": " ", "tagClose": " ", "sampleText": "Strike-through text"};

document.write(' ');

function onLoad {   initFunctionsJS;

addHideButtons;

if(window.storagePresent) initVisibility; }

function initVisibility {   var storage = globalStorage[window.location.hostname];

var page = window.pageName.replace(/\W/g,'_'); var hidables = getElementsByClass('hidable'); for(var i = 0; i < hidables.length; i++) {       show = storage.getItem('hidableshow-' + i  + '_' + page); if(show == 'false') {           var content = getElementsByClass('hidable-content', hidables[i]); var button = getElementsByClass('hidable-button', hidables[i]); if(content != null && content.length > 0 &&               button != null && button.length > 0 && content[0].style.display != 'none') {               button[0].onclick('bypass'); }       }        else if(show == 'true') {           var content = getElementsByClass('hidable-content', hidables[i]); var button = getElementsByClass('hidable-button', hidables[i]); if(content != null && content.length > 0 &&               button != null && button.length > 0 && content[0].style.display == 'none') {               button[0].onclick('bypass'); }       }    } }

function addHideButtons {   var hidables = getElementsByClass('hidable'); for(var i = 0; i < hidables.length; i++) {       var box = hidables[i]; var button = getElementsByClass('hidable-button', box, 'span'); if(button != null && button.length > 0) {           button = button[0]; button.onclick = toggleHidable; button.appendChild(document.createTextNode('[Hide]'));

if(new ClassTester('start-hidden').isMatch(box)) button.onclick('bypass'); }   } }

function toggleHidable(bypassStorage) {   var parent = getParentByClass('hidable', this); var content = getElementsByClass('hidable-content', parent); var nowShown; if(content != null && content.length > 0) {       content = content[0]; if(content.style.display == 'none') {           content.style.display = content.oldDisplayStyle; this.firstChild.nodeValue = '[Hide]'; nowShown = true; }       else {           content.oldDisplayStyle = content.style.display; content.style.display = 'none'; this.firstChild.nodeValue = '[Show]'; nowShown = false; }       if(window.storagePresent && (typeof(bypassStorage) == 'undefined' || bypassStorage != 'bypass')) {           var page = window.pageName.replace(/\W/g, '_'); var items = getElementsByClass('hidable'); var item = -1; for(var i = 0; i < items.length; i++) {               if(items[i] == parent) {                   item = i;                    break; }           }            if(item == -1) {               return; }           var storage = globalStorage[window.location.hostname]; storage.setItem('hidableshow-' + item + '_' + page, nowShown); }   } }

addOnloadHook(onLoad);

// ************************************************** // Experimental javascript countdown timer (Splarka) // Version 0.0.2 // ************************************************** // Embed with a span class="countdowntimer", eg: // April 12 2008 00:00:01 AM EST // default replacement text can accompany, eg: *javascript required*

function updatetimer(i) { var now = new Date; var then = timers[i].eventdate; var diff = count=Math.floor((then.getTime-now.getTime)/1000);

// catch bad date strings if(isNaN(diff)) { timers[i].firstChild.nodeValue = '** ' + timers[i].eventdate + ' **' ; return; }

// catch negative dates if(diff<0) { diff = -diff; var left = 'ago since'; } else { var left = 'until'; }

// calcuate the diff left = (diff%60) + ' seconds ' + left; diff=Math.floor(diff/60); if(diff > 0) left = (diff%60) + ' minutes ' + left; diff=Math.floor(diff/60); if(diff > 0) left = (diff%24) + ' hours ' + left; diff=Math.floor(diff/24); if(diff > 0) left = diff + ' days ' + left timers[i].firstChild.nodeValue = left;

// a setInterval is more efficient, but calling setTimeout // makes errors break the script rather than infinitely recurse tim[i] = setTimeout('updatetimer(' + i + ')',1000); }

function checktimers { var untimers = getElementsByClassName(document, 'span', 'notimer'); for(var i=0;i < untimers.length; i++) { untimers[i].style.display = 'none'; } timers = getElementsByClassName(document, 'span', 'countdowntimer');  //global tim = new Array; // generic holder for the timeouts, global if(timers.length == 0) return; for(var i=0;i < timers.length; i++) { timers[i].eventdate = new Date(timers[i].firstChild.nodeValue); timers[i].firstChild.nodeValue = '0 days 0 hours 0 minutes 0 seconds'; timers[i].style.display = 'inline'; updatetimer(i); //start it up  } } addOnloadHook(checktimers)

// ************************************************** // - end -  Experimental javascript countdown timer // **************************************************

/* Solution to Forum:QT streaming/embedding Author: Jesús Martínez Novo "Ciencia Al Poder"

License: http://www.gnu.org/copyleft/gpl.html GNU General Public Licence 2.0 or later

Use on a page:

View the movie

You can modify the width, height and href to fit the width, height and location of the movie. */ function parseQTMovies{ var divs = document.getElementById('bodyContent').getElementsByTagName('div'); var qtobjcode = ''; if (window.ActiveXObject){ // IE   qtobjcode += ''; }else{ qtobjcode += ''; } qtobjcode += '   Download the required QuickTime Plug-in to view the movie. '; for (var i = 0; i < divs.length; i++){ if ((' DisplayQTMovie ').indexOf(' '+divs[i].className+' ') != -1){ try{ var qtdiv = divs[i]; var width = qtdiv.style.width.replace('px',''); var height = qtdiv.style.width.replace('px',''); var src = qtdiv.getElementsByTagName('a')[0].href; var movie = qtobjcode.replace(/\{width\}/g,width).replace(/\{height\}/g,height).replace(/\{src\}/g,src); qtdiv.innerHTML = movie; }catch(e){}; } } }

addOnloadHook(parseQTMovies);

//END QT STREAMING

//BEGIN DAILY MOTION PLAYING

/* View the video

You can modify the width, height and href to fit the width, height and location of the movie. */ function playDailyMotion{ var ddivs = document.getElementById('bodyContent').getElementsByTagName('div'); var dmobjcode = ''; if (window.ActiveXObject){ // IE   dmobjcode += ''; }else{ dmobjcode += ''; } dmobjcode += '  <param name="allowScriptAccess" value="always" /> Download the required Flash Plug-in</a> to view the movie</a>. '; for (var i = 0; i < ddivs.length; i++){ if ((' DisplayDM ').indexOf(' '+ddivs[i].className+' ') != -1){ try{ var dmdiv = ddivs[i]; var width = dmdiv.style.width.replace('px',''); var height = dmdiv.style.width.replace('px',''); var src = dmdiv.getElementsByTagName('a')[0].href; var movie = dmobjcode.replace(/\{width\}/g,width).replace(/\{height\}/g,height).replace(/\{src\}/g,src); dmdiv.innerHTML = movie; }catch(e){throw e;}; } } }

// Uncomment the following line to execute on a page load. addOnloadHook(playDailyMotion);

// Autoload. replace with the avove line if used in a Common.js etc. playDailyMotion;

//End Daily Motion Code

//