LocalCDN-Firefox-Chrome-Brave/resources/twix.js/0.3.0/twix.min.jsm

1 line
9.8 KiB
JavaScript

(function(){var t,n,r,e=[].slice,a=[].indexOf||function(t){for(var n=0,r=this.length;r>n;n++)if(n in this&&this[n]===t)return n;return-1};t="undefined"!=typeof module&&null!==module&&null!=module.exports,n="function"==typeof define,r=function(n){var r,o;if(null==n)throw"Can't find moment";return o=["en"],r=function(){function r(t,r,e){this.start=n(t),this.end=n(r),this.allDay=e||!1}return r._extend=function(){var t,n,r,a,o,i;for(n=arguments[0],a=arguments.length>=2?e.call(arguments,1):[],o=0,i=a.length;i>o;o++){r=a[o];for(t in r)r[t]!==void 0&&(n[t]=r[t])}return n},r.defaults={twentyFourHour:!1,allDaySimple:{fn:function(t){return function(){return t.allDay}},slot:0,pre:" "},dayOfWeek:{fn:function(t){return function(n){return n.format(t.weekdayFormat)}},slot:1,pre:" "},allDayMonth:{fn:function(t){return function(n){return n.format(""+t.monthFormat+" "+t.dayFormat)}},slot:2,pre:" "},month:{fn:function(t){return function(n){return n.format(t.monthFormat)}},slot:2,pre:" "},date:{fn:function(t){return function(n){return n.format(t.dayFormat)}},slot:3,pre:" "},year:{fn:function(t){return function(n){return n.format(t.yearFormat)}},slot:4,pre:", "},time:{fn:function(t){return function(n){var r;return r=0===n.minutes()&&t.implicitMinutes&&!t.twentyFourHour?n.format(t.hourFormat):n.format(""+t.hourFormat+":"+t.minuteFormat),t.groupMeridiems||t.twentyFourHour||(t.spaceBeforeMeridiem&&(r+=" "),r+=n.format(t.meridiemFormat)),r}},slot:5,pre:", "},meridiem:{fn:function(t){return function(n){return n.format(t.meridiemFormat)}},slot:6,pre:function(t){return t.spaceBeforeMeridiem?" ":""}}},r.registerLang=function(t,e){return n.lang(t,{twix:r._extend({},r.defaults,e)})},r.prototype.isSame=function(t){return this.start.isSame(this.end,t)},r.prototype.length=function(t){return this._trueEnd().add(1,"millisecond").diff(this._trueStart(),t)},r.prototype.count=function(t){var n,r;return r=this.start.clone().startOf(t),n=this.end.clone().startOf(t),n.diff(r,t)+1},r.prototype.countInner=function(t){var n,r,e;return e=this._inner(t),r=e[0],n=e[1],r>=n?0:n.diff(r,t)},r.prototype.iterate=function(t,n){var r,e,a,o=this;return a=this.start.clone().startOf(t),r=this.end.clone().startOf(t),e=function(){return r>=a&&(!n||a.valueOf()!==r.valueOf()||o.end.hours()>n||o.allDay)},this._iterateHelper(t,a,e)},r.prototype.iterateInner=function(t){var n,r,e,a;return a=this._inner(t),e=a[0],n=a[1],r=function(){return n>e},this._iterateHelper(t,e,r)},r.prototype.humanizeLength=function(){return this.allDay?this.isSame("day")?"all day":this.start.from(this.end.clone().add(1,"day"),!0):this.start.from(this.end,!0)},r.prototype.asDuration=function(){var t;return t=this.end.diff(this.start),n.duration(t)},r.prototype.isPast=function(){return this.allDay?this.end.clone().endOf("day")<n():this.end<n()},r.prototype.isFuture=function(){return this.allDay?this.start.clone().startOf("day")>n():this.start>n()},r.prototype.isCurrent=function(){return!this.isPast()&&!this.isFuture()},r.prototype.contains=function(t){return t=n(t),t>=this._trueStart()&&this._trueEnd()>=t},r.prototype.overlaps=function(t){return this._trueEnd().isAfter(t._trueStart())&&this._trueStart().isBefore(t._trueEnd())},r.prototype.engulfs=function(t){return this._trueStart()<=t._trueStart()&&this._trueEnd()>=t._trueEnd()},r.prototype.union=function(t){var n,e,a;return n=this.allDay&&t.allDay,n?(a=this.start<t.start?this.start:t.start,e=this.end>t.end?this.end:t.end):(a=this._trueStart()<t._trueStart()?this._trueStart():t._trueStart(),e=this._trueEnd()>t._trueEnd()?this._trueEnd():t._trueEnd()),new r(a,e,n)},r.prototype.intersection=function(t){var e,a,o,i;return i=this.start>t.start?this.start:t.start,this.allDay?(a=n(this.end),a.add(1,"day"),a.subtract(1,"millisecond"),o=t.allDay?t.end>a?this.end:t.end:t.end>a?a:t.end):o=this.end<t.end?this.end:t.end,e=this.allDay&&t.allDay,new r(i,o,e)},r.prototype.isValid=function(){return this._trueStart()<=this._trueEnd()},r.prototype.equals=function(t){return t instanceof r&&this.allDay===t.allDay&&this.start.valueOf()===t.start.valueOf()&&this.end.valueOf()===t.end.valueOf()},r.prototype.toString=function(){var t;return"{start: "+this.start.format()+", end: "+this.end.format()+", allDay: "+(null!=(t=this.allDay)?t:{"true":"false"})+"}"},r.prototype.simpleFormat=function(t,n){var e,a;return e={allDay:"(all day)"},r._extend(e,n||{}),a=""+this.start.format(t)+" - "+this.end.format(t),this.allDay&&e.allDay&&(a+=" "+e.allDay),a},r.prototype.format=function(t){var e,a,o,i,u,s,l,f,h,d,m,c,p,y,_=this;for(this._lazyLang(),h={groupMeridiems:!0,spaceBeforeMeridiem:!0,showDate:!0,showDayOfWeek:!1,twentyFourHour:this.langData.twentyFourHour,implicitMinutes:!0,implicitYear:!0,yearFormat:"YYYY",monthFormat:"MMM",weekdayFormat:"ddd",dayFormat:"D",meridiemFormat:"A",hourFormat:"h",minuteFormat:"mm",allDay:"all day",explicitAllDay:!1,lastNightEndsAt:0},r._extend(h,t||{}),u=[],h.twentyFourHour&&(h.hourFormat=h.hourFormat.replace("h","H")),l=h.lastNightEndsAt>0&&!this.allDay&&this.end.clone().startOf("day").valueOf()===this.start.clone().add(1,"day").startOf("day").valueOf()&&this.start.hours()>12&&this.end.hours()<h.lastNightEndsAt,f=h.showDate||!this.isSame("day")&&!l,this.allDay&&this.isSame("day")&&(!h.showDate||h.explicitAllDay)&&u.push({name:"all day simple",fn:this._formatFn("allDaySimple",h),pre:this._formatPre("allDaySimple",h),slot:this._formatSlot("allDaySimple")}),!f||h.implicitYear&&this.start.year()===n().year()&&this.isSame("year")||u.push({name:"year",fn:this._formatFn("year",h),pre:this._formatPre("year",h),slot:this._formatSlot("year")}),!this.allDay&&f&&u.push({name:"all day month",fn:this._formatFn("allDayMonth",h),ignoreEnd:function(){return l},pre:this._formatPre("allDayMonth",h),slot:this._formatSlot("allDayMonth")}),this.allDay&&f&&u.push({name:"month",fn:this._formatFn("month",h),pre:this._formatPre("month",h),slot:this._formatSlot("month")}),this.allDay&&f&&u.push({name:"date",fn:this._formatFn("date",h),pre:this._formatPre("date",h),slot:this._formatSlot("date")}),f&&h.showDayOfWeek&&u.push({name:"day of week",fn:this._formatFn("dayOfWeek",h),pre:this._formatPre("dayOfWeek",h),slot:this._formatSlot("dayOfWeek")}),!h.groupMeridiems||h.twentyFourHour||this.allDay||u.push({name:"meridiem",fn:this._formatFn("meridiem",h),pre:this._formatPre("meridiem",h),slot:this._formatSlot("meridiem")}),this.allDay||u.push({name:"time",fn:this._formatFn("time",h),pre:this._formatPre("time",h),slot:this._formatSlot("time")}),m=[],a=[],e=[],c=!0,d=function(t){var n,r,i;return i=t.fn(_.start),n=t.ignoreEnd&&t.ignoreEnd()?i:t.fn(_.end),r={format:t,value:function(){return i}},n===i&&c?e.push(r):(c&&(c=!1,e.push({format:{slot:t.slot,pre:""},value:function(){return""+o(m)+" -"+o(a,!0)}})),m.push(r),a.push({format:t,value:function(){return n}}))},p=0,y=u.length;y>p;p++)i=u[p],d(i);return s=!0,o=function(t,n){var r,e,a,o,i,u;for(r=!0,a="",u=t.sort(function(t,n){return t.format.slot-n.format.slot}),o=0,i=u.length;i>o;o++)e=u[o],s||(a+=r&&n?" ":e.format.pre),a+=e.value(),s=!1,r=!1;return a},o(e)},r.prototype._trueStart=function(){return this.allDay?this.start.clone().startOf("day"):this.start},r.prototype._trueEnd=function(){return this.allDay?this.end.clone().endOf("day"):this.end},r.prototype._iterateHelper=function(t,n,r){return{next:function(){var e;return r()?(e=n.clone(),n.add(1,t),e):null},hasNext:r}},r.prototype._inner=function(t){var n,r;return r=this.start.clone(),n=this.end.clone(),this.allDay&&(r.startOf("day"),n.startOf("day").add(1,"days")),r>r.clone().startOf(t)&&r.startOf(t).add(1,t),n.clone().endOf(t)>n&&n.startOf(t),[r,n]},r.prototype._lazyLang=function(){var n,e,i,u;if(i=this.start.lang(),null!=i&&this.end.lang()._abbr!==i._abbr&&this.end.lang(i._abbr),null==this.langData||this.langData._abbr!==i._abbr){if(t&&(u=i._abbr,!(a.call(o,u)>=0))){try{e=require("./lang/"+i._abbr),e(r)}catch(s){n=s}o.push(i._abbr)}return this.langData=(null!=i?i._twix:void 0)||r.defaults}},r.prototype._formatFn=function(t,n){return this.langData[t].fn(n)},r.prototype._formatSlot=function(t){return this.langData[t].slot},r.prototype._formatPre=function(t,n){return"function"==typeof this.langData[t].pre?this.langData[t].pre(n):this.langData[t].pre},r.prototype._deprecate=function(t,n,r){return console&&console.warn&&console.warn("#"+t+" is deprecated. Use #"+n+" instead."),r.apply(this)},r.prototype.sameDay=function(){return this._deprecate("sameDay","isSame('day')",function(){return this.isSame("day")})},r.prototype.sameYear=function(){return this._deprecate("sameYear","isSame('year')",function(){return this.isSame("year")})},r.prototype.countDays=function(){return this._deprecate("countDays","countOuter('days')",function(){return this.countOuter("days")})},r.prototype.daysIn=function(t){return this._deprecate("daysIn","iterate('days' [,minHours])",function(){return this.iterate("days",t)})},r.prototype.past=function(){return this._deprecate("past","isPast()",function(){return this.isPast()})},r.prototype.duration=function(){return this._deprecate("duration","humanizeLength()",function(){return this.humanizeLength()})},r.prototype.merge=function(t){return this._deprecate("merge","union(other)",function(){return this.union(t)})},r}(),r._extend(Object.getPrototypeOf(n.fn._lang),{_twix:r.defaults}),n.twix=function(){return function(t,n,r){r.prototype=t.prototype;var e=new r,a=t.apply(e,n);return Object(a)===a?a:e}(r,arguments,function(){})},n.fn.twix=function(){return function(t,n,r){r.prototype=t.prototype;var e=new r,a=t.apply(e,n);return Object(a)===a?a:e}(r,[this].concat(e.call(arguments)),function(){})},n.fn.forDuration=function(t,n){return new r(this,this.clone().add(t),n)},n.duration.fn.afterMoment=function(t,e){return new r(t,n(t).clone().add(this),e)},n.duration.fn.beforeMoment=function(t,e){return new r(n(t).clone().subtract(this),t,e)},r},t&&(module.exports=r(require("moment"))),n&&define("twix",["moment"],function(t){return r(t)}),this.moment&&(this.Twix=r(this.moment))}).call(this);