MediaWiki:Common.js

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

if(mwCustomEditButtons) mwCustomEditButtons.push({   "imageFile": "http://images.wikia.com/redwall/images/c/c9/Button_strike.png",    "speedTip": "Strike",    "tagOpen": " ",    "tagClose": " ",    "sampleText": "Strike-through text"  });

importScript('MediaWiki:Functions.js');

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); }   } }

// ************************************************** // 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'); if(divs == null) return false; divs = divs.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

//************************************************** //Player for DailyMotion.com Videos by LordTBT 2007 //************************************************** //Inspired by Ciencia Al Poder /* 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'); if(ddivs==null) return false; ddivs = ddivs.getElementsByTagName('div'); var dmobjcode = ''; if (window.ActiveXObject){ // IE   dmobjcode += ''; }else{ dmobjcode += ''; } dmobjcode += '   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){}; } } }

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

//End Daily Motion Code

/*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 doc

You can modify the width, height and href to fit the width, height and location of the movie. */ function playDocstoc{ var divs = document.getElementById('bodyContent'); if(divs==null) return false; divs = divs.getElementsByTagName('div'); var dsobjcode = ''; if (window.ActiveXObject){ // IE		dsobjcode += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}" data="http://viewer.docstoc.com/" width="{width}" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'; }else{ dsobjcode += '<object type="application/x-shockwave-flash" data="http://viewer.docstoc.com/" width="{width}" height="{height}">'; }	dsobjcode += '<param name="movie" value="http://viewer.docstoc.com/" /><param value="always" name="allowScriptAccess"><param value="true" name="allowFullScreen"><param value="transparent" name="wmode"><param value="doc_id={doc}&amp;mem_id={mem}&amp;embed=0&amp;showrelated=0&amp;showotherdocs=0" name="flashvars"> Download the required FlashPlayer Plug-in</a> to view the doc</a>. ';	for (var i = 0; i < divs.length; i++){ if ((' Docstoc ').indexOf(' '+divs[i].className+' ') != -1){ try{ var dsdiv = divs[i]; var width = dsdiv.style.width.replace('px',''); var height = dsdiv.style.width.replace('px',''); var src = dsdiv.getElementsByTagName('a')[0].href; var doc = ''; var mem = ''; if (src.indexOf('?') < 0) continue; var qsparam = src.substring(src.indexOf('?')+1,src.length).split('&'); for (var i=0; i < qsparam.length; i++){ var parg = qsparam[i].split('='); if (parg[0] == 'doc_id') doc = parg[1]; if (parg[0] == 'mem_id') mem = parg[1]; }				var movie = dsobjcode.replace(/\{width\}/g,width).replace(/\{height\}/g,height).replace(/\{src\}/g,src).replace(/\{doc\}/g,doc).replace(/\{mem\}/g,mem); dsdiv.innerHTML = movie; }catch(e){}; }	} } addOnloadHook(playDocstoc);

//End Docstoc code

//************************************************** //Twitter Widget Implementation by LordTBT 2009 //************************************************** //Licensed under GNU /* Twitter */ function playTwitter{ var divs = document.getElementById('bodyContent'); if(divs == null) return false; divs = divs.getElementsByTagName('div'); var twobjcode = ''; if (window.ActiveXObject){ // IE		twobjcode += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="{width}" height="{height}" id="TwitterWidget" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0" align="middle">'; }else{ twobjcode += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="{width}" height="{height}" id="TwitterWidget" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,124,0" align="middle">'; }	twobjcode += '<param name="movie" value="http://static.twitter.com/flash/widgets/profile/TwitterWidget.swf" /><param value="always" name="allowScriptAccess"><param value="false" name="allowFullScreen"><param value="high" name="quality"><param value="#000000" name="bgcolor"><param value="userID=36320432&styleURL=http://static.twitter.com/flash/widgets/profile/revo.xml" name="flashvars"><embed src="http://static.twitter.com/flash/widgets/profile/TwitterWidget.swf" quality="high" bgcolor="#000000" width="{width}" height="{height}" name="TwitterWidget" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="userID=36320432&styleURL=http://static.twitter.com/flash/widgets/profile/revo.xml"/> '; for (var i = 0; i < divs.length; i++){ if ((' Twitter ').indexOf(' '+divs[i].className+' ') != -1){ try{ var twdiv = divs[i]; var width = twdiv.style.width.replace('px',''); var height = twdiv.style.width.replace('px',''); var src = twdiv.getElementsByTagName('a')[0].href; var movie = twobjcode.replace(/\{width\}/g,width).replace(/\{height\}/g,height).replace(/\{src\}/g,src); twdiv.innerHTML = movie; }catch(e){ window._customTWerror = e; }; }	} }

//addOnloadHook(playTwitter);

//************************************************** //Twitter Widget Second Implementation by LordTBT 2009 //************************************************** //Credit to designisphilosophy /* Twitter */ function playTwitter2{ importScriptURI('http://twitter.com/javascripts/blogger.js');

importScriptURI('http://twitter.com/statuses/user_timeline/redwallwiki.json?callback=twitterCallback2&count=5'); }

addOnloadHook(playTwitter2);

//thanks Ciencia function fBox { $('#redwallfbox').append('<iframe marginheight="0" marginwidth="0" src="http://www.facebook.com/connect/connect.php?id=84155975777&amp;connections=10&amp;stream=0" align="top" frameborder="0" width="300" height="250" scrolling="no" />'); }

$(fBox);

function fBoxx { $('#redwallfboxx').append('<iframe marginheight="0" marginwidth="0" src="http://www.facebook.com/plugins/likebox.php?id=84155975777&width=292&connections=0&stream=0&header=0&send=true" allowTransparency="true" align="top" frameborder="0" width="292" height="80" scrolling="no" />'); }

$(fBoxx);

function BnVid { $('#bnvid').append('<iframe marginheight="0" marginwidth="0" src="http://media.barnesandnoble.com/linking/index.jsp?skin=oneclip&ehv=http://media.barnesandnoble.com&fr_story=b8b70aefdc0b090c7980696df26e563688d835d1&rf=ev&hl=true" frameborder="0" width="413" height="355" scrolling="no" />'); }

$(BnVid);

//Pcj redundancy removal $(function { if (wgNamespaceNumber == 6) $("#file").html($("#file").html.replace(/ .* /i," ")); });

//************************************************** //Tweet Button by LordTBT 2010 //************************************************** /* */

$(function { $('.tweet').html('Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"> '); });

//************************************************** //Kindle For Web //************************************************** // /* Amazon */

function fill_amazon { $.getScript("http://kindleweb.s3.amazonaws.com/app/KindleReader-min.js", function {   amHTML = $("#kindleReaderDiv").html;    $("#kindleReaderDiv").html("");    KindleReader.LoadSample({containerID: 'kindleReaderDiv', asin: amHTML, width: '800', height: '700', assoctag: 'redwwiki-20'});  }); }

addOnloadHook( fill_amazon );

//