chronoline
Version:
chronoline.js is a library for making a chronology timeline out of events on a horizontal timescale.
4 lines • 19.6 kB
JavaScript
/* chronoline.js v0.1.6 21-05-2018
* by Kevin Leung for Zanbato, https://zanbato.com
* MIT SEE LICENSE IN https://github.com/StoicLoofah/chronoline.js/LICENSE.md */
function addElemClass(a,b,c){"SVG"==a?b.setAttribute("class",c):b.className+=" "+c}function strftime(a,b){return b.formatDate(a)}function getLeft(a){return parseInt(a.style.left)}function getEndDate(a){return a[a.length-1]}function isFifthDay(a){var b=a.getDate();return(1==b||b%5===0)&&30!=b}function isHalfMonth(a){var b=a.getDate();return 1==b||15==b}function prevMonth(a){var b=new Date(a.getTime()-DAY_IN_MILLISECONDS);return new Date(b.getFullYear(),b.getMonth(),1)}function nextMonth(a){return new Date(a.getFullYear(),a.getMonth()+1,1)}function prevQuarter(a){var b=new Date(a.getTime()-DAY_IN_MILLISECONDS),c=b.getMonth();return new Date(b.getFullYear(),c-c%3,1)}function nextQuarter(a){var b=a.getMonth();return new Date(a.getFullYear(),b-b%3+3,1)}function backWeek(a){return new Date(a.getTime()-7*DAY_IN_MILLISECONDS)}function forwardWeek(a){return new Date(a.getTime()+7*DAY_IN_MILLISECONDS)}function Chronoline(a,b,c){function d(){if(b=null!=b?b:[],c=null!=c?c:{},null==a)throw"Dom element not defined."}function e(){for(var d in h)g[d]=h[d];for(var d in c)g[d]=c[d];g.originalStartDate=g.startDate,g.originalEndDate=g.endDate,g.originalDefaultStartDate=g.defaultStartDate,g.domElement=a,g.wrapper=document.createElement("div"),g.wrapper.className="chronoline-wrapper",g.domElement.appendChild(g.wrapper),g.events=b,g.today=new Date(Date.now()),g.today.stripTime(),null===g.defaultStartDate&&(g.defaultStartDate=g.today)}function f(){g.events=null===g.events?[]:g.events;for(var a=0;a<g.events.length;a++)for(var b=0;b<g.events[a].dates.length;b++)g.events[a].dates[b]=new Date(Date.parse(g.events[a].dates[b])),g.events[a].dates[b].stripTime();g.events.sort(g.sortEvents),g.sections=null===g.sections?[]:g.sections,g.floatingSectionLabels&=0!==g.sections.length,g.sectionLabelsOnHover&=0!==g.sections.length;for(var a=0;a<g.sections.length;a++)for(var b=0;b<g.sections[a].dates.length;b++)g.sections[a].dates[b]=new Date(Date.parse(g.sections[a].dates[b])),g.sections[a].dates[b].stripTime();g.sections.sort(g.sortEvents),g.drawnStartMs=null,g.drawnEndMs=null,g.isMoving=!1}var g=this;g.VERSION="0.1.6";var h={defaultStartDate:null,startDate:null,endDate:null,visibleSpan:2592e6,timelinePadding:0,fitVisibleSpan:!1,topMargin:40,eventHeight:5,eventMargin:4,dateLabelHeight:50,hashLength:4,minEventsHeight:40,maxEventsHeight:1e3,hashColor:"#b8b8b8",eventAttrs:{fill:"#0055e1",stroke:"#0055e1","stroke-width":2},hashInterval:null,labelInterval:null,labelFormat:"%d",subLabel:"month",subLabelMargin:2,subLabelAttrs:{"font-weight":"bold"},floatingSubLabels:!0,subSubLabel:"year",subSubLabelMargin:2,subSubLabelAttrs:{"font-weight":"bold"},floatingSubSubLabels:!0,fontAttrs:{"font-size":10,fill:"#000000"},scrollable:!0,scrollLeft:backWeek,scrollRight:forwardWeek,animated:!1,tooltips:!1,qtipOptions:{},markToday:"line",todayAttrs:{stroke:"#484848"},sections:[],floatingSectionLabels:!0,sectionLabelAttrs:{},sectionLabelsOnHover:!0,draggable:!1,continuousScroll:!0,continuousScrollSpeed:1,eventClick:null,eventDblClick:null,sectionClick:null,sectionDblClick:null,backgroundClick:null,backgroundDblClick:null};return g.init=function(){if(null===g.startDate)if(g.events.length>0){g.startDate=new Date(Date.parse(g.events[0].dates[0]));for(var a=1;a<g.events.length;a++)g.events[a].dates[0]<g.startDate&&(g.startDate=new Date(Date.parse(g.events[a].dates[0])))}else if(g.sections.length>0){g.startDate=new Date(Date.parse(g.sections[0].dates[0]));for(var a=0;a<g.sections.length;a++)g.sections[a].dates[0]<g.startDate&&(g.startDate=new Date(Date.parse(g.sections[a].dates[0])))}else g.startDate=g.defaultStartDate;if(g.startDate.stripTime(),g.startDate>g.defaultStartDate&&(g.startDate=g.defaultStartDate),g.startDate=new Date(g.startDate.getTime()-g.timelinePadding),g.startTime=g.startDate.getTime(),null===g.endDate)if(g.events.length>0){g.endDate=getEndDate(g.events[0].dates);for(var a=1;a<g.events.length;a++)getEndDate(g.events[a].dates)>g.endDate&&(g.endDate=getEndDate(g.events[a].dates))}else if(g.sections.length>0){g.endDate=Date.parse(g.sections[0].dates[1]);for(var a=0;a<g.sections.length;a++)g.sections[a].dates[1]>g.endDate&&(g.endDate=Date.parse(g.sections[a].dates[1]))}else g.endDate=g.defaultStartDate;g.endDate<g.defaultStartDate&&(g.endDate=g.defaultStartDate),g.endDate=new Date(Math.max(g.endDate.getTime(),g.startDate.getTime()+g.visibleSpan)+g.timelinePadding),g.endDate.stripTime(),g.visibleWidth=g.domElement.clientWidth,g.fitVisibleSpan?(g.startDate=new Date(g.startDate.getTime()-DAY_IN_MILLISECONDS),g.endDate=new Date(g.endDate.getTime()+DAY_IN_MILLISECONDS),g.pxRatio=g.visibleWidth/(g.endDate-g.startDate)):g.pxRatio=g.visibleWidth/g.visibleSpan,g.totalWidth=g.pxRatio*(g.endDate.getTime()-g.startDate.getTime()),g.maxLeftPx=g.totalWidth-g.visibleWidth,g.circleRadius=g.eventHeight/2,g.eventRows=[[]],g.rowLastPxs=[0];for(var a=0;a<g.events.length;a++){for(var b=!1,c=g.msToPx(g.events[a].dates[0].getTime())-g.circleRadius,d=0;d<g.eventRows.length;d++)if(g.rowLastPxs[d]<c){g.eventRows[d].push(g.events[a]),g.rowLastPxs[d]=g.msToPx(getEndDate(g.events[a].dates).getTime())+g.circleRadius,b=!0;break}b||(g.eventRows.push([g.events[a]]),g.rowLastPxs.push(g.msToPx(getEndDate(g.events[a].dates).getTime())+g.circleRadius))}if(g.eventsHeight=Math.max(Math.min(g.eventRows.length*(g.eventMargin+g.eventHeight),g.maxEventsHeight),g.minEventsHeight),g.totalHeight=g.dateLabelHeight+g.eventsHeight+g.topMargin,g.myCanvas&&g.wrapper.hasChildNodes())for(a=g.wrapper.childNodes.length-1;a>=0;a--)if(g.wrapper.childNodes[a]===g.myCanvas){g.wrapper.removeChild(g.myCanvas);break}if(g.myCanvas=document.createElement("div"),g.myCanvas.className="chronoline-canvas",g.wrapper.appendChild(g.myCanvas),g.paper=Raphael(g.myCanvas,g.totalWidth,g.totalHeight),g.paperType=g.paper.raphael.type,g.paperElem=g.myCanvas.childNodes[0],g.floatingSet=g.paper.set(),g.sectionLabelSet=g.paper.set(),g.backgroundClick&&(g.myCanvas.onclick=function(a){if("circle"!=a.target.nodeName&&"rect"!=a.target.nodeName){var b=new Date(g.pxToMs(a.clientX));b.stripTime(),g.backgroundClick(b)}}),g.backgroundDblClick&&(g.myCanvas.ondblclick=function(a){if("circle"!=a.target.nodeName&&"rect"!=a.target.nodeName){var b=new Date(g.pxToMs(a.clientX));b.stripTime(),g.backgroundDblClick(b)}}),null!==g.sections)for(var a=0;a<g.sections.length;a++){var e=g.sections[a],f=(e.dates[0].getTime()-g.startTime)*g.pxRatio,h=(e.dates[1]-e.dates[0])*g.pxRatio,i=g.paper.rect(f,0,h,g.totalHeight);(g.sectionClick||g.sectionDblClick)&&i.data("sectionData",e),g.sectionClick&&i.click(function(a){a.preventDefault();var b=new Date(g.pxToMs(a.clientX));b.stripTime(),g.sectionClick(this.data("sectionData"),b)}),g.sectionDblClick&&i.dblclick(function(a){a.preventDefault();var b=new Date(g.pxToMs(a.clientX));b.stripTime(),g.sectionDblClick(this.data("sectionData"),b)}),addElemClass(g.paperType,i.node,"chronoline-section"),i.attr("stroke-width",0),i.attr("stroke","#ffffff"),"undefined"!=typeof e.attrs&&i.attr(e.attrs);var j=g.paper.text(f+10,10,e.title);j.attr("text-anchor","start"),j.attr(g.sectionLabelAttrs),g.floatingSectionLabels&&(j.data("left-bound",f+10),j.data("right-bound",f+h-j.attr("width")),g.floatingSet.push(j),g.sectionLabelSet.push(j)),i.data("label",j),g.sectionLabelsOnHover&&(i.hover(function(){this.data("label").animate({opacity:1},200)},function(){this.data("label").animate({opacity:0},200)}),j.hover(function(){this.animate({opacity:1},200)},function(){this.animate({opacity:0},200)}),j.attr("opacity",0))}g.sectionLabelSet.forEach(function(a){a.toFront()});for(var k=0;k<g.eventRows.length;k++)for(var l=g.totalHeight-g.dateLabelHeight-(k+1)*(g.eventMargin+g.eventHeight),m=0;m<g.eventRows[k].length;m++){var n=g.eventRows[k][m],f=(n.dates[0].getTime()-g.startTime)*g.pxRatio,i=null;if(1==n.dates.length)i=g.paper.circle(f,l+g.circleRadius,g.circleRadius).attr(g.eventAttrs);else{var h=(getEndDate(n.dates)-n.dates[0])*g.pxRatio,o=g.paper.circle(f,l+g.circleRadius,g.circleRadius).attr(g.eventAttrs);"undefined"!=typeof n.attrs&&o.attr(n.attrs),addElemClass(g.paperType,o.node,"chronoline-event");var p=g.paper.circle(f+h,l+g.circleRadius,g.circleRadius).attr(g.eventAttrs);"undefined"!=typeof n.attrs&&p.attr(n.attrs),addElemClass(g.paperType,p.node,"chronoline-event"),i=g.paper.rect(f,l,h,g.eventHeight).attr(g.eventAttrs)}if((g.eventClick||g.eventDblClick)&&i.data("eventData",n),g.eventClick&&i.click(function(a){a.preventDefault(),g.eventClick(this.data("eventData"))}),g.eventDblClick&&i.dblclick(function(a){a.preventDefault(),g.eventDblClick(this.data("eventData"))}),"undefined"!=typeof n.link&&(i.data("link",n.link),i.click(function(){window.location.href=this.data("link")})),"undefined"!=typeof n.attrs&&i.attr(n.attrs),addElemClass(g.paperType,i.node,"chronoline-event"),i.attr("title",n.title),g.tooltips){var q=n.description,r=n.title,s=jQuery(i.node);"undefined"!=typeof q&&""!==q||(q=r,r=""),"SVG"==Raphael.type&&(s=s.parent());var t={content:{title:r,text:q},position:{my:"top left",target:"mouse",viewport:jQuery(window),adjust:{x:10,y:10}},hide:{fixed:!0},style:{classes:"qtip-shadow qtip-dark qtip-rounded"}};$.extend(!0,t,g.qtipOptions),s.qtip(t)}if(null!==g.sections&&g.sectionLabelsOnHover){var u=n.section;if("undefined"!=typeof u){for(var a=0;a<g.sections.length;a++)if(g.sections[a].section==u){i.data("sectionLabel",g.sectionLabelSet[a]);break}i.hover(function(){this.data("sectionLabel").animate({opacity:1},200)},function(){this.data("sectionLabel").animate({opacity:0},200)})}}}g.dateLineY=g.totalHeight-g.dateLabelHeight;var v=g.paper.path("M0,"+g.dateLineY+"L"+g.totalWidth+","+g.dateLineY);if(v.attr("stroke",g.hashColor),g.bottomHashY=g.dateLineY+g.hashLength,g.labelY=g.bottomHashY+g.fontAttrs["font-size"],g.subLabelY=g.bottomHashY+2*g.fontAttrs["font-size"]+g.subLabelMargin,g.subSubLabelY=g.subLabelY+g.fontAttrs["font-size"]+g.subSubLabelMargin,"year"==g.subSubLabel)for(var w=g.endDate.getFullYear(),x=g.startDate.getFullYear();x<=w;x++){var y=new Date(x,0,1);y.stripTime();var z=g.msToPx(y.getTime()),A=g.paper.text(z,g.subSubLabelY,y.formatDate("%Y").toUpperCase());if(A.attr(g.fontAttrs),A.attr(g.subSubLabelAttrs),g.floatingSubSubLabels){A.data("left-bound",z);var B=new Date(x,11,31);B.stripTime(),A.data("right-bound",Math.min((B.getTime()-g.startTime)*g.pxRatio-5,g.totalWidth)),g.floatingSet.push(A)}}g.scrollable&&g.initScrollable(),g.draggable&&g.initDraggable(),g.drawnStartMs=null,g.drawnEndMs=null,g.paperElem.style.left=-(g.defaultStartDate-g.startDate)*g.pxRatio+20+"px",g.goToPx(getLeft(g.paperElem)),g.myCanvas.style.height=g.totalHeight+"px"},g.sortEvents=function(a,b){a=a.dates,b=b.dates;var c=a[a.length-1].getTime(),d=b[b.length-1].getTime();return c!=d?c-d:a[0].getTime()-b[0].getTime()},g.pxToMs=function(a){return g.startTime+a/g.pxRatio},g.msToPx=function(a){return(a-g.startTime)*g.pxRatio},g.resize=function(a){g.visibleSpan=a,g.init()},g.zoom=function(a){g.resize(g.visibleSpan/a)},g.drawLabelsHelper=function(a,b){for(var c=a;c<b;c+=DAY_IN_MILLISECONDS){var d=new Date(c),e=d.getDate(),f=g.msToPx(c);if(null===g.hashInterval||g.hashInterval(d)){var h=g.paper.path("M"+f+","+g.dateLineY+"L"+f+","+g.bottomHashY);h.attr("stroke",g.hashColor)}if(null===g.labelInterval||g.labelInterval(d)){var i=g.paper.text(f,g.labelY,d.formatDate(g.labelFormat));i.attr(g.fontAttrs)}if(g.markToday&&c==g.today.getTime())if("labelBox"==g.markToday){i.attr({text:i.attr("text")+"\n"+d.formatDate("%b").toUpperCase(),"font-size":g.fontAttrs["font-size"]+2,y:g.bottomHashY+g.fontAttrs["font-size"]+5});var j=i.getBBox(),k=g.paper.rect(j.x-2,j.y-2,j.width+4,j.height+4);k.attr("fill","90-#f4f4f4-#e8e8e8"),k.insertBefore(i)}else if("line"==g.markToday){var l=g.paper.path("M"+f+",0L"+f+","+g.dateLineY);l.attr(g.todayAttrs)}if(1==e&&"month"==g.subLabel){var m=g.paper.text(f,g.subLabelY,d.formatDate("%b").toUpperCase());if(m.attr(g.fontAttrs),m.attr(g.subLabelAttrs),g.floatingSubLabels){m.data("left-bound",f);var n=new Date(d.getFullYear(),d.getMonth()+1,0,CL_HOUR);m.data("right-bound",Math.min((n.getTime()-g.startTime)*g.pxRatio-5,g.totalWidth)),g.floatingSet.push(m)}}}},g.drawLabels=function(a){var b=Math.max(0,a-g.visibleWidth),c=(Math.min(g.totalWidth,a+2*g.visibleWidth),new Date(g.pxToMs(b)));c=new Date(c.getFullYear(),c.getMonth(),1,CL_HOUR);var d=c.getTime(),e=new Date(g.pxToMs(Math.min(g.totalWidth,a+2*g.visibleWidth)));e.stripTime();var f=e.getTime();null===g.drawnStartMs?(g.drawnStartMs=d,g.drawnEndMs=f,g.drawLabelsHelper(d,f)):d>g.drawnEndMs?(g.drawLabelsHelper(g.drawnEndMs,f),g.drawnEndMs=f):f<g.drawnStartMs?(g.drawLabelsHelper(d,g.drawnStartMs),g.drawnStartMs=d):(d<g.drawnStartMs&&(g.drawLabelsHelper(d,g.drawnStartMs),g.drawnStartMs=d),f>g.drawnEndMs&&(g.drawLabelsHelper(g.drawnEndMs,f),g.drawnEndMs=f))},g.goToPx=function(a,b,c){function d(b){null===i&&(i=b);var c=(b-i)/200,h=(a-e)*c+e;j.style.left=h+"px";for(var k=0;k<f.length;k++)f[k][0].attr("x",f[k][2]*c+f[k][1]);if(c<1)requestAnimationFrame(d);else{g.paperElem.style.left=a+"px";for(var k=0;k<f.length;k++)f[k][0].attr("x",f[k][2]+f[k][1]);g.isMoving=!1}}if(g.isMoving)return!1;b="undefined"!=typeof b?b:g.animated,c="undefined"==typeof c||c,a=Math.max(Math.min(a,0),-g.maxLeftPx),c&&g.drawLabels(-a);var e=getLeft(g.paperElem);g.scrollable&&(0===a?(g.leftControl.style.display="none",g.isScrolling=!1):g.leftControl.style.display="",a==g.visibleWidth-g.totalWidth?(g.rightControl.style.display="none",g.isScrolling=!1):g.rightControl.style.display="");var f=[],h=-a+5;if(g.floatingSet.forEach(function(a){a.data("left-bound")<h&&a.data("right-bound")>h?f.push([a,a.attr("x"),h-a.attr("x")+10]):a.attr("x")!=a.data("left-bound")&&f.push([a,a.attr("x"),a.data("left-bound")-a.attr("x")])}),b){g.isMoving=!0;var i=null,j=g.paperElem;requestAnimationFrame(d)}else{g.paperElem.style.left=a+"px";for(var k=0;k<f.length;k++)f[k][0].attr("x",f[k][2]+f[k][1])}return 0!==a&&a!=-g.maxLeftPx},g.goToDate=function(a,b){a=new Date(a.getTime()),a.stripTime(),b<0?g.goToPx(-g.msToPx(a.getTime())):b>0?g.goToPx(-g.msToPx(a.getTime())+g.visibleWidth):g.goToPx(-g.msToPx(a.getTime())+g.visibleWidth/2)},g.initScrollable=function(){if(g.leftControl&&g.wrapper.hasChildNodes())for(i=g.wrapper.childNodes.length-1;i>=0;i--)if(g.wrapper.childNodes[i]===g.leftControl){g.wrapper.removeChild(g.leftControl);break}g.leftControl=document.createElement("div"),g.leftControl.className="chronoline-left",g.leftControl.style.marginTop=g.topMargin+"px";var a=document.createElement("div");a.className="chronoline-left-icon",g.leftControl.appendChild(a),g.wrapper.appendChild(g.leftControl);var b=Math.max(g.eventsHeight,g.leftControl.clientHeight);if(g.leftControl.style.height=b+"px",a.style.marginTop=(b-15)/2+"px",g.rightControl&&g.wrapper.hasChildNodes())for(i=g.wrapper.childNodes.length-1;i>=0;i--)if(g.wrapper.childNodes[i]===g.rightControl){g.wrapper.removeChild(g.rightControl);break}g.rightControl=document.createElement("div"),g.rightControl.className="chronoline-right",g.rightControl.style.marginTop=g.topMargin+"px";var c=document.createElement("div");c.className="chronoline-right-icon",g.rightControl.appendChild(c),g.wrapper.appendChild(g.rightControl),g.rightControl.style.height=g.leftControl.style.height,c.style.marginTop=a.style.marginTop,g.scrollLeftDiscrete=function(a){return g.goToDate(g.scrollLeft(new Date(g.pxToMs(-getLeft(g.paperElem)))),-1),!1},g.scrollRightDiscrete=function(a){return g.goToDate(g.scrollRight(new Date(g.pxToMs(-getLeft(g.paperElem)))),-1),!1},g.continuousScroll?(g.isScrolling=!1,g.timeoutId=-1,g.scrollLeftContinuous=function(a){null===g.scrollStart&&(g.scrollStart=a),g.isScrolling&&requestAnimationFrame(g.scrollLeftContinuous);var b=g.continuousScrollSpeed*(a-g.scrollStart)+g.scrollPaperStart;g.goToPx(b,!1,b>-g.msToPx(g.drawnStartMs))},g.endScrollLeft=function(a){clearTimeout(g.scrollTimeoutId),g.toScrollDiscrete&&(g.toScrollDiscrete=!1,g.scrollLeftDiscrete()),g.isScrolling=!1},g.leftControl.onmousedown=function(a){g.toScrollDiscrete=!0,g.scrollPaperStart=getLeft(g.paperElem),g.scrollTimeoutId=setTimeout(function(){g.toScrollDiscrete=!1,g.scrollStart=null,g.isScrolling=!0,requestAnimationFrame(g.scrollLeftContinuous)},200)},g.leftControl.onmouseup=g.endScrollLeft,g.leftControl.onmouseleave=g.endScrollLeft,g.scrollRightContinuous=function(a){null===g.scrollStart&&(g.scrollStart=a),g.isScrolling&&requestAnimationFrame(g.scrollRightContinuous);var b=g.continuousScrollSpeed*(g.scrollStart-a)+g.scrollPaperStart;g.goToPx(b,!1,b-g.visibleWidth<-g.msToPx(g.drawnEndMs))},g.endScrollRight=function(a){clearTimeout(g.scrollTimeoutId),g.toScrollDiscrete&&(g.toScrollDiscrete=!1,g.scrollRightDiscrete()),g.isScrolling=!1},g.rightControl.onmousedown=function(a){g.toScrollDiscrete=!0,g.scrollPaperStart=getLeft(g.paperElem),g.scrollTimeoutId=setTimeout(function(){g.toScrollDiscrete=!1,g.scrollStart=null,g.isScrolling=!0,requestAnimationFrame(g.scrollRightContinuous)},500)},g.rightControl.onmouseup=g.endScrollRight,g.rightControl.onmouseleave=g.endScrollRight):(g.leftControl.onclick=g.scrollLeftDiscrete,g.rightControl.onclick=g.scrollRightDiscrete)},g.initDraggable=function(){g.stopDragging=function(a){jQuery(g.wrapper).removeClass("dragging").unbind("mousemove",g.mouseMoved).unbind("mouseleave",g.stopDragging).unbind("mouseup",g.stopDragging),g.drawLabels(-getLeft(g.paperElem))},g.mouseMoved=function(a){g.goToPx(g.dragPaperStart-(g.dragMouseStart-a.pageX),!1,!1)},g.wrapper.className+=" chronoline-draggable",jQuery(g.paperElem).mousedown(function(a){a.preventDefault(),g.dragMouseStart=a.pageX,g.dragPaperStart=getLeft(g.paperElem),jQuery(g.wrapper).addClass("dragging").bind("mousemove",g.mouseMoved).bind("mouseleave",g.stopDragging).bind("mouseup",g.stopDragging)})},g.goToToday=function(){g.goToDate(g.today,0)},g.getLeftTime=function(){return Math.floor(g.startTime-getLeft(g.paperElem)/g.pxRatio)},g.getRightTime=function(){return Math.floor(g.startTime-(getLeft(g.paperElem)-g.visibleWidth)/g.pxRatio)},g.refresh=function(){return f(),g.init(),g},d(),e(),f(),g.init(),g}Date.now||(Date.now=function(){return+new Date}),DAY_IN_MILLISECONDS=864e5,requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||function(a,b){return window.setTimeout(function(){a(+new Date)},1e3/60)},Date.prototype.stdTimezoneOffset=function(){var a=new Date(this.getFullYear(),0,1),b=new Date(this.getFullYear(),6,1);return Math.max(a.getTimezoneOffset(),b.getTimezoneOffset())},Date.prototype.dstHourAdjustment=function(){return(this.stdTimezoneOffset()-this.getTimezoneOffset())/60},CL_HOUR=12,Date.prototype.stripTime=function(){this.setHours(CL_HOUR+this.dstHourAdjustment()),this.setMinutes(0),this.setSeconds(0),this.setMilliseconds(0)},Date.MONTH_NAMES=["January","February","March","April","May","June","July","August","September","October","November","December"],Date.DAY_NAMES=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],Date.prototype.formatDate=function(a){var b=a;if(a.indexOf("%d")!=-1){var c=this.getDate().toString();c.length<2&&(c="0"+c),b=b.replace("%d",c)}if(a.indexOf("%b")!=-1){var d=Date.MONTH_NAMES[this.getMonth()].substring(0,3);b=b.replace("%b",d)}if(a.indexOf("%Y")!=-1&&(b=b.replace("%Y",this.getFullYear())),a.indexOf("%a")!=-1){var e=Date.DAY_NAMES[this.getDay()].substring(0,3);b=b.replace("%a",e)}return b};