(ie support *sigh*) |
(forgot one.) |
||
Line 49: | Line 49: | ||
var countdown = document.querySelector("#countdown-clock"); |
var countdown = document.querySelector("#countdown-clock"); |
||
if(countdown != undefined) { |
if(countdown != undefined) { |
||
− | countdown.style="border:6px double #012E59; padding:3px; margin:0 10px 3px; box-shadow:0 0 10px #012E59; text-align:center;"; |
+ | countdown.style.cssText="border:6px double #012E59; padding:3px; margin:0 10px 3px; box-shadow:0 0 10px #012E59; text-align:center;"; |
var heading = document.createElement("strong"); |
var heading = document.createElement("strong"); |
Revision as of 06:52, 25 January 2015
/*
Any JavaScript here will be loaded for all users on every page load.
See MediaWiki:Wikia.js for scripts that only affect the oasis skin.
*/
/* Table of Contents
-----------------------
* (X00) importArticle pre-script actions
* * (X01) LastEdited
* (Y00) importArticles
*/
//##############################################################
/* ==importArticle pre-script actions== (X00)*/
// The code in this section is for a script imported below
//###########################################
/* ===LastEdited=== (X01) */
window.lastEdited = {
avatar: true,
size: false,
diff: true,
comment: true,
time: false
};
//##############################################################
/* ==importArticles== (Y00)*/
// Imports scripts from other pages/wikis.
importArticles({
type: 'script',
articles: [
'MediaWiki:Common.js/cellTemplate.js',
'w:dev:WallGreetingButton/code.js',
'u:dev:LastEdited/code.js'
]
});
//##############################################################
/* ==Countdown Timer== (Y00)*/
// Counts down the time to Steam release
(function(){
function init(){
var countdown = document.querySelector("#countdown-clock");
if(countdown != undefined) {
countdown.style.cssText="border:6px double #012E59; padding:3px; margin:0 10px 3px; box-shadow:0 0 10px #012E59; text-align:center;";
var heading = document.createElement("strong");
countdown.appendChild(heading);
heading.style.cssText="display:block; position:relative; font-size:30px; background:#012E59; border-bottom:3px solid skyblue; padding: 15px 5px 17px; color:#DDD; margin:0 0 8px; background-image:url(http://vignette1.wikia.nocookie.net/transformice/images/6/64/Badge_42.png), url(http://vignette1.wikia.nocookie.net/transformice/images/6/64/Badge_42.png); background-repeat:no-repeat; background-position:1% center, 99% center;";
heading.innerHTML="Countdown to Steam release:";
var time = document.createElement("div");
countdown.appendChild(time);
time.id="countdownTime"
time.style.cssText="font-size:40px; font-family:monospace; padding:20px 0;";
time.innerHTML = "[Loading...]";
countdown.appendChild(document.createElement("hr"));
var footer = document.createElement("div");
countdown.appendChild(footer);
footer.style.cssText="font-size:12px;";
footer.innerHTML="This timer is not set to the exact time of release, and simply counts down to January 30th at 10AM, to correspond closely with time given on <a href='http://store.steampowered.com/app/335240/' target='_blank'>the Steam page</a>.<br />Find details of the Steam release on the <a href='http://atelier801.com/topic?f=5&t=787441&p=1' target='_blank'>Official Forums</a>.";
var cdown = new CDown();
cdown.add(new Date(2015,0,30,10,0,0), "countdownTime");
}
}
//###################################################################
// Author: ricocheting.com
// Version: v3.0
// Date: 2014-09-05
// Description: displays the amount of time until the "dateFuture" entered below.
var CDown = function() {
this.state=0;// if initialized
this.counts=[];// array holding countdown date objects and id to print to {d:new Date(2013,11,18,18,54,36), id:"countbox1"}
this.interval=null;// setInterval object
}
CDown.prototype = {
init: function(){
this.state=1;
var self=this;
this.interval=window.setInterval(function(){self.tick();}, 1000);
},
add: function(date,id){
this.counts.push({d:date,id:id});
this.tick();
if(this.state==0) this.init();
},
expire: function(idxs){
for(var x in idxs) {
this.display(this.counts[idxs[x]], "Release Imminent!");
this.counts.splice(idxs[x], 1);
}
},
format: function(r){
var out="";
if(r.d != 0){out += r.d +" "+((r.d==1)?"day":"days")+", ";}
out += (r.h<=9?'0':'')+r.h +" "+((r.h==1)?"hour":"hours")+", ";
out += (r.m<=9?'0':'')+r.m +" "+((r.m==1)?"min":"mins")+", ";
out += (r.s<=9?'0':'')+r.s +" "+((r.s==1)?"sec":"secs")+", ";
return out.substr(0,out.length-2);
},
math: function(work){
var y=w=d=h=m=s=ms=0;
ms=(""+((work%1000)+1000)).substr(1,3);
work=Math.floor(work/1000);//kill the "milliseconds" so just secs
y=Math.floor(work/31536000);//years (no leapyear support)
w=Math.floor(work/604800);//weeks
d=Math.floor(work/86400);//days
work=work%86400;
h=Math.floor(work/3600);//hours
work=work%3600;
m=Math.floor(work/60);//minutes
work=work%60;
s=Math.floor(work);//seconds
return {y:y,w:w,d:d,h:h,m:m,s:s,ms:ms};
},
tick: function(){
var now=(new Date()).getTime(),
expired=[],cnt=0,amount=0;
if(this.counts)
for(var idx=0,n=this.counts.length; idx<n; ++idx){
cnt=this.counts[idx];
amount=cnt.d.getTime()-now;//calc milliseconds between dates
// if time is already past
if(amount<0){
expired.push(idx);
}
// date is still good
else{
this.display(cnt, this.format(this.math(amount)));
}
}
// deal with any expired
if(expired.length>0) this.expire(expired);
// if no active counts, stop updating
if(this.counts.length==0) window.clearTimeout(this.interval);
},
display: function(cnt,msg){
document.getElementById(cnt.id).innerHTML=msg;
}
};
init();
})();