Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
chamilo-lms/main/inc/lib/javascript/jquery.epiclock.min.js

9 lines
8.0 KiB

/*
* epiClock 2.1 - Create Epic Clocks Easily
*
* Copyright (c) 2008 Eric Garside (http://eric.garside.name)
* Dual licensed under:
* MIT: http://www.opensource.org/licenses/mit-license.php
* GPLv3: http://www.opensource.org/licenses/gpl-3.0.html
*/
var EC_HALT="disable",EC_RUN="enable",EC_KILL="destroy",EC_CLOCK=0,EC_COUNTDOWN=1,EC_COUNTUP=2,EC_ROLLOVER=3,EC_EXPIRE=4,EC_LOOP=5,EC_STOPWATCH=6,EC_HOLDUP=7;(function(c){c.epiclocks={};var f={epiClock:{offset:{hours:0,minutes:0,seconds:0,days:0,years:0},arbitrary:{days:0,years:0},gmt:false,target:null,onTimer:null,onKill:null,onRender:function(h,i){h.html(i)},format:null,frame:{},dead:false,displace:0,modifier:0,variance:0,daysadded:0,paused:0,tolerance:0,selfLoc:-1,mode:EC_CLOCK,onSetup:null,stylesheet:null,containerClass:null,tpl:"<span></span>"},formats:["F j, Y, g:i:s a","V{d} x{h} i{m} s{s}","Q{y} K{d} x{h} i{m} s{s}","V{d} x{h} i{m} s{s}","x{h} i{m} s{s}","i{m} s{s}","x{h} i{m} s{s}","Q{y} K{d} x{h} i{m} s{s}"]},e=null,a=null,d=[];c.cssIncludes={};c.cssInclude=function(h,i){if(c.cssIncludes[h]){return false}c.cssIncludes[h]=true;i=i||"screen";c('<link type="text/css" rel="stylesheet" href="'+h+'" media="'+i+'"/>').appendTo("head")};c.epiclock=c.fn.clocks=function(j,h,i){j=j||EC_RUN;h=h||500;if(j==e){return}switch(j){case EC_KILL:c.each(d,function(){this.removeData("epiClock")});d=[];case EC_HALT:if(a){clearInterval(a);a=null}e=j;break;case EC_RUN:if(!a){b();a=setInterval(b,h)}e=j;break}return this};function b(){c.each(d,function(h){this.data("epiClock").render()})}c.fn.epiclock=function(h,j){var i=null;if(typeof h=="string"&&c.epiclocks&&c.epiclocks[h]){h=c.epiclocks[h]}else{if(j&&c.epiclocks&&c.epiclocks[j]){h=c.extend(true,{},c.epiclocks[j],h)}}switch(h){case"destroy":i="kill";case"disable":i=i||"pause";case"enable":i=i||"resume";return this.each(function(){var k=c(this).data("epiClock");if(k instanceof g){k[i]()}});default:h=c.extend(true,{},f.epiClock,h);break}this.each(function(){var m=c(this),p=(h.format||f.formats[h.mode]).split(""),o=false,l=h.tpl||f.tpl,k="",n=new g(h,m);m.data("epiClock",n);c.each(p,function(){x=this+"";switch(x){case" ":if(!o){c(l).addClass("epiclock epiclock-spacer").appendTo(m)}else{k+=x}break;case"{":o=true;break;case"}":o=false;c(l).addClass("epiclock").html(k).appendTo(m);k="";break;default:if(o){k+=x}else{if(Date.prototype[x]||n[x]){n.frame[x]=c(l).addClass("epiclock epiclock-digit").data("ec-encoding",x).appendTo(m)}else{c(l).addClass("epiclock epiclock-separator").html(x).appendTo(m)}}break}});n.selfLoc=d.push(m)-1;if(c.isFunction(n.onSetup)){n.onSetup.call(n,[])}if(n.stylesheet){c.cssInclude(n.stylesheet)}if(n.containerClass){m.addClass(n.containerClass)}});return this};function g(h,i){if(this instanceof g){return this.init(h,i)}else{return new g(h,i)}}g.prototype={Q:function(){return this.arbitrary.years},E:function(){return this.arbitrary.days},e:function(){return this.arbitrary.days.pad(0)},zero:new Date(0),pause:function(){if(this.dead){return}this.paused=new Date().valueOf();this.dead=true},resume:function(){if(!this.dead){return}if(this.mode==EC_STOPWATCH){this.displace+=(this.paused-new Date().valueOf())}this.paused=0;this.dead=false},kill:function(){d.splice(this.selfLoc,1);c.each(d,function(h){this.data("epiClock").selfLoc=h});if(c.isFunction(this.onKill)){this.onKill()}this.dead=true},init:function(h,j){if(h.mode<EC_CLOCK||h.mode>EC_HOLDUP){throw"EPICLOCK_INVALID_MODE"}var i=this;c.each(h,function(m,l){i[m]=l});switch(this.mode){case EC_LOOP:case EC_EXPIRE:this.target=this.target||new Date();case EC_COUNTDOWN:case EC_ROLLOVER:this.modifier=-1;this.variance=1;break;case EC_STOPWATCH:this.displace+=this.calculateOffset()+(-1*new Date().valueOf());return;case EC_HOLDUP:this.variance=-1;this.modifier=1;break;default:this.modifier=1;this.variance=0;break}if(this.gmt){this.normalize()}switch(true){case this.target instanceof Date:this.target=this.target.valueOf();break;case typeof this.target=="string":this.target=new Date(this.target).valueOf();break}this.displace+=this.modifier*this.calculateOffset()},calculateOffset:function(h){h=h||this.offset;return(h.years*31570560000+h.days*86400000+h.hours*3600000+h.minutes*60000+(this.variance+h.seconds)*1000)},normalize:function(){this.displace+=new Date().getTimezoneOffset()*60000},render:function(){if(!this.tick()){return}var h=this,i=(this.mode==EC_HOLDUP)?this.zero:this.now;c.each(this.frame,function(l,j){var m=(c.isFunction(i[l])?i[l]():h[l]())+"";if(j.data("last")!=m){h.onRender(j,m)}j.data("last",m)})},tick:function(){if(this.dead){return false}var h=new Date().valueOf()+this.displace;switch(this.mode){case EC_HOLDUP:if(this.target<h){this.mode=EC_COUNTUP}case EC_COUNTUP:h-=this.target;break;case EC_ROLLOVER:if(h>this.target){h=h-this.target}else{h=this.target-h}break;case EC_COUNTDOWN:case EC_EXPIRE:case EC_LOOP:h=this.target-h;if(h<this.tolerance){return this.timerEnd()}break}this.now=new Date(h);var i=this.now.V();if(i<=this.daysadded){return true}this.daysadded=i;this.arbitrary.days+=i;if(this.arbitrary.days<365){return true}this.arbitrary.years+=Math.floor(this.arbitrary.days/365.4%365.4);this.arbitrary.days=Math.floor(this.arbitrary.days%365.4);return true},timerEnd:function(){if(c.isFunction(this.onTimer)){this.onTimer()}switch(this.mode){case EC_COUNTDOWN:case EC_EXPIRE:this.kill();break;case EC_LOOP:this.displace+=this.modifier*this.calculateOffset();return this.render();case EC_ROLLOVER:this.mode=EC_COUNTUP;return true}this.now=new Date(0);return true}};c.extend(String.prototype,{pad:function(i,h){h=h||2;return this.length<h?new Array(1+h-this.length).join(i)+this:this},rpad:function(i,h){h=h||2;return this.length<h?this+new Array(1+h-this.length).join(i):this}});c.extend(Number.prototype,{pad:function(i,h){return(this+"").pad(i,h)},rpad:function(i,h){return(this+"").rpad(i,h)}});c.extend(Date.prototype,{modCalc:function(i,h){return(Math.floor(Math.floor(this.valueOf()/1000)/i)%h)},months:["January","February","March","April","May","June","July","August","September","October","November","December"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],suffix:[null,"st","nd","rd"],V:function(){return this.modCalc(86400,100000)},v:function(){return this.V().pad(0)},K:function(){return this.V()%365},k:function(){return this.K().pad(0)},X:function(){return this.modCalc(3600,24)},x:function(){return this.X().pad(0)},d:function(){return this.getDate().pad("0")},D:function(){return this.days[this.getDay()].substring(0,3)},j:function(){return this.getDate()},l:function(){return this.days[this.getDay()]},N:function(){return this.getDay()+1},S:function(){return this.suffix[this.getDate()]||"th"},w:function(){return this.getDay()},z:function(){return Math.round((this-this.f())/86400000)},W:function(){return Math.ceil(((((this-this.f())/86400000)+this.f().w())/7))},F:function(){return this.months[this.getMonth()]},m:function(){return(this.getMonth()+1).pad(0)},M:function(){return this.months[this.getMonth()].substring(0,3)},n:function(){return this.getMonth()+1},L:function(){var h=this.Y();return h%4?false:h%100?true:h%400?false:true},f:function(){return new Date(this.getFullYear(),0,1)},Y:function(){return this.getFullYear()},y:function(){return(""+this.getFullYear()).substr(2)},a:function(){return this.getHours()<12?"am":"pm"},A:function(){return this.a().toUpperCase()},B:function(){return Math.floor((((this.getHours())*3600000)+(this.getMinutes()*60000)+(this.getSeconds()*1000))/86400).pad(0,3)},g:function(){return this.getHours()%12||12},G:function(){return this.getHours()},h:function(){return this.g().pad("0")},H:function(){return this.getHours().pad("0")},i:function(){return this.getMinutes().pad(0)},s:function(){return this.getSeconds().pad("0")},u:function(){return this.getTime()%1000},O:function(){var h=this.getTimezoneOffset()/60;return(h>=0?"+":"-")+Math.abs(h).pad(0).rpad(0,4)},P:function(){var h=this.O();return h.substr(0,3)+":"+h.substr(3)},Z:function(){return this.getTimezoneOffset()*60},c:function(){return this.Y()+"-"+this.m()+"-"+this.d()+"T"+this.H()+":"+this.i()+":"+this.s()+this.P()},r:function(){return this.toString()},U:function(){return this.getTime()/1000}})})(jQuery);