nyc-bookstores/node_modules/tabletop/examples/timeline_setter/timeline_setter.js

1 line
17 KiB
JavaScript
Raw Normal View History

2013-05-27 20:45:59 +00:00
(function(e,i){var m=window.TimelineSetter=(window.TimelineSetter||{});var s=function(E){E.bind=function(I,F){var G=(this._callbacks=this._callbacks||{});var H=(G[I]=G[I]||[]);H.push(F)};E.trigger=function(H){if(!this._callbacks){return}var G=this._callbacks[H];if(!G){return}for(var F=0;F<G.length;F++){G[F].apply(this,arguments)}}};var B=function(E){E.move=function(G,F){if(!F.deltaX){return}if(_.isUndefined(this.currOffset)){this.currOffset=0}this.currOffset+=F.deltaX;this.el.css({left:this.currOffset})};E.zoom=function(G,F){if(!F.width){return}this.el.css({width:F.width})}};var c=function(F,E){F.$=function(G){return window.$(G,E)}};var A="ontouchstart" in document;if(A){e.event.props.push("touches")}var d=function(I){var G;function E(K){K.preventDefault();G={x:K.pageX};K.type="dragstart";I.el.trigger(K)}function F(K){if(!G){return}K.preventDefault();K.type="dragging";K=_.extend(K,{deltaX:(K.pageX||K.touches[0].pageX)-G.x});G={x:(K.pageX||K.touches[0].pageX)};I.el.trigger(K)}function J(K){if(!G){return}G=null;K.type="dragend";I.el.trigger(K)}if(!A){I.el.bind("mousedown",E);e(document).bind("mousemove",F);e(document).bind("mouseup",J)}else{var H;I.el.bind("touchstart",function(M){var K=Date.now();var N=K-(H||K);var L=N>0&&N<=250?"doubletap":"tap";G={x:M.touches[0].pageX};H=K;I.el.trigger(e.Event(L))});I.el.bind("touchmove",F);I.el.bind("touchend",J)}};var o=/WebKit\/533/.test(navigator.userAgent);var y=function(F){function E(H){H.preventDefault();var I=(H.wheelDelta||-H.detail);if(o){var G=I<0?-1:1;I=Math.log(Math.abs(I))*G*2}H.type="scrolled";H.deltaX=I;F.el.trigger(H)}F.el.bind("mousewheel DOMMouseScroll",E)};var w=function(){this.min=+Infinity;this.max=-Infinity};w.prototype.extend=function(E){this.min=Math.min(E,this.min);this.max=Math.max(E,this.max)};w.prototype.width=function(){return this.max-this.min};w.prototype.project=function(F,E){return(F-this.min)/this.width()*E};var h=function(G,E){this.max=G.max;this.min=G.min;if(!E||!this.INTERVALS[E]){var F=this.computeMaxInterval();this.maxInterval=this.INTERVAL_ORDER[F];this.idx=F}else{this.maxInterval=E;this.idx=_.indexOf(this.INTERVAL_ORDER,E)}};h.dateFormats=function(H){var J=new Date(H);var I={};var F=["Jan.","Feb.","March","April","May","June","July","Aug.","Sept.","Oct.","Nov.","Dec."];var G=J.getHours()>12;var E=J.getHours()>=12;I.month=F[J.getMonth()];I.year=J.getFullYear();I.date=I.month+" "+J.getDate()+", "+I.year;I.hourWithMinutes=(G?J.getHours()-12:(J.getHours()>0?J.getHours():"12"))+":"+z(J.getMinutes())+" "+(E?"p.m.":"a.m.");I.hourWithMinutesAndSeconds=I.hourWithMinutes+":"+z(J.getSeconds());return h.formatter(J,I)||I};h.dateStr=function(F,E){var G=new h.dateFormats(F);switch(E){case"Decade":return G.year;case"Lustrum":return G.year;case"FullYear":return G.year;case"Month":return G.month+", "+G.year;case"Week":return G.date;case"Date":return G.date;case"Hours":return G.hourWithMinutes;case"Minutes":return G.hourWithMinutes;case"Seconds":return G.hourWithMinutesAndSeconds}};h.prototype={INTERVALS:{Decade:315360000000,Lustrum:157680000000,FullYear:31536000000,Month:2592000000,Week:604800000,Date:86400000,Hours:3600000,Minutes:60000,Seconds:1000},INTERVAL_ORDER:["Seconds","Minutes","Hours","Date","Week","Month","FullYear","Lustrum","Decade"],isAtLeastA:function(E){return((this.max-this.min)>this.INTERVALS[E])},computeMaxInterval:function(){for(var E=0;E<this.INTERVAL_ORDER.length;E++){if(!this.isAtLeastA(this.INTERVAL_ORDER[E])){break}}return E-1},getMaxInterval:function(){return this.INTERVALS[this.INTERVAL_ORDER[this.idx]]},getDecade:function(E){return(E.getFullYear()/10|0)*10},getLustrum:function(E){return(E.getFullYear()/5|0)*5},getWeekFloor:function(E){thisDate=new Date(E.getFullYear(),E.getMonth(),E.getDate());thisDate.setDate(E.getDate()-E.getDay());return thisDate},getWeekCeil:function(E){thisDate=new Date(E.getFullYear(),E.getMonth(),E.getDate());thisDate.setDate(thisDate.getDate()+(7-E.getDay()));return thisDate},floor:function(G){var F=new Date(G);var H=this.INTERVAL_ORDER[this.idx];var E=this.idx>_.indexOf(this.INTERVAL_ORDER,"FullYear")?_.inde