daterangepicker.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. // moment.js
  2. // version : 2.1.0
  3. // author : Tim Wood
  4. // license : MIT
  5. // momentjs.com
  6. !function(t){function e(t,e){return function(n){return u(t.call(this,n),e)}}function n(t,e){return function(n){return this.lang().ordinal(t.call(this,n),e)}}function s(){}function i(t){a(this,t)}function r(t){var e=t.years||t.year||t.y||0,n=t.months||t.month||t.M||0,s=t.weeks||t.week||t.w||0,i=t.days||t.day||t.d||0,r=t.hours||t.hour||t.h||0,a=t.minutes||t.minute||t.m||0,o=t.seconds||t.second||t.s||0,u=t.milliseconds||t.millisecond||t.ms||0;this._input=t,this._milliseconds=u+1e3*o+6e4*a+36e5*r,this._days=i+7*s,this._months=n+12*e,this._data={},this._bubble()}function a(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function o(t){return 0>t?Math.ceil(t):Math.floor(t)}function u(t,e){for(var n=t+"";n.length<e;)n="0"+n;return n}function h(t,e,n,s){var i,r,a=e._milliseconds,o=e._days,u=e._months;a&&t._d.setTime(+t._d+a*n),(o||u)&&(i=t.minute(),r=t.hour()),o&&t.date(t.date()+o*n),u&&t.month(t.month()+u*n),a&&!s&&H.updateOffset(t),(o||u)&&(t.minute(i),t.hour(r))}function d(t){return"[object Array]"===Object.prototype.toString.call(t)}function c(t,e){var n,s=Math.min(t.length,e.length),i=Math.abs(t.length-e.length),r=0;for(n=0;s>n;n++)~~t[n]!==~~e[n]&&r++;return r+i}function f(t){return t?ie[t]||t.toLowerCase().replace(/(.)s$/,"$1"):t}function l(t,e){return e.abbr=t,x[t]||(x[t]=new s),x[t].set(e),x[t]}function _(t){if(!t)return H.fn._lang;if(!x[t]&&A)try{require("./lang/"+t)}catch(e){return H.fn._lang}return x[t]}function m(t){return t.match(/\[.*\]/)?t.replace(/^\[|\]$/g,""):t.replace(/\\/g,"")}function y(t){var e,n,s=t.match(E);for(e=0,n=s.length;n>e;e++)s[e]=ue[s[e]]?ue[s[e]]:m(s[e]);return function(i){var r="";for(e=0;n>e;e++)r+=s[e]instanceof Function?s[e].call(i,t):s[e];return r}}function M(t,e){function n(e){return t.lang().longDateFormat(e)||e}for(var s=5;s--&&N.test(e);)e=e.replace(N,n);return re[e]||(re[e]=y(e)),re[e](t)}function g(t,e){switch(t){case"DDDD":return V;case"YYYY":return X;case"YYYYY":return $;case"S":case"SS":case"SSS":case"DDD":return I;case"MMM":case"MMMM":case"dd":case"ddd":case"dddd":return R;case"a":case"A":return _(e._l)._meridiemParse;case"X":return B;case"Z":case"ZZ":return j;case"T":return q;case"MM":case"DD":case"YY":case"HH":case"hh":case"mm":case"ss":case"M":case"D":case"d":case"H":case"h":case"m":case"s":return J;default:return new RegExp(t.replace("\\",""))}}function p(t){var e=(j.exec(t)||[])[0],n=(e+"").match(ee)||["-",0,0],s=+(60*n[1])+~~n[2];return"+"===n[0]?-s:s}function D(t,e,n){var s,i=n._a;switch(t){case"M":case"MM":i[1]=null==e?0:~~e-1;break;case"MMM":case"MMMM":s=_(n._l).monthsParse(e),null!=s?i[1]=s:n._isValid=!1;break;case"D":case"DD":case"DDD":case"DDDD":null!=e&&(i[2]=~~e);break;case"YY":i[0]=~~e+(~~e>68?1900:2e3);break;case"YYYY":case"YYYYY":i[0]=~~e;break;case"a":case"A":n._isPm=_(n._l).isPM(e);break;case"H":case"HH":case"h":case"hh":i[3]=~~e;break;case"m":case"mm":i[4]=~~e;break;case"s":case"ss":i[5]=~~e;break;case"S":case"SS":case"SSS":i[6]=~~(1e3*("0."+e));break;case"X":n._d=new Date(1e3*parseFloat(e));break;case"Z":case"ZZ":n._useUTC=!0,n._tzm=p(e)}null==e&&(n._isValid=!1)}function Y(t){var e,n,s=[];if(!t._d){for(e=0;7>e;e++)t._a[e]=s[e]=null==t._a[e]?2===e?1:0:t._a[e];s[3]+=~~((t._tzm||0)/60),s[4]+=~~((t._tzm||0)%60),n=new Date(0),t._useUTC?(n.setUTCFullYear(s[0],s[1],s[2]),n.setUTCHours(s[3],s[4],s[5],s[6])):(n.setFullYear(s[0],s[1],s[2]),n.setHours(s[3],s[4],s[5],s[6])),t._d=n}}function w(t){var e,n,s=t._f.match(E),i=t._i;for(t._a=[],e=0;e<s.length;e++)n=(g(s[e],t).exec(i)||[])[0],n&&(i=i.slice(i.indexOf(n)+n.length)),ue[s[e]]&&D(s[e],n,t);i&&(t._il=i),t._isPm&&t._a[3]<12&&(t._a[3]+=12),t._isPm===!1&&12===t._a[3]&&(t._a[3]=0),Y(t)}function k(t){var e,n,s,r,o,u=99;for(r=0;r<t._f.length;r++)e=a({},t),e._f=t._f[r],w(e),n=new i(e),o=c(e._a,n.toArray()),n._il&&(o+=n._il.length),u>o&&(u=o,s=n);a(t,s)}function v(t){var e,n=t._i,s=K.exec(n);if(s){for(t._f="YYYY-MM-DD"+(s[2]||" "),e=0;4>e;e++)if(te[e][1].exec(n)){t._f+=te[e][0];break}j.exec(n)&&(t._f+=" Z"),w(t)}else t._d=new Date(n)}function T(e){var n=e._i,s=G.exec(n);n===t?e._d=new Date:s?e._d=new Date(+s[1]):"string"==typeof n?v(e):d(n)?(e._a=n.slice(0),Y(e)):e._d=n instanceof Date?new Date(+n):new Date(n)}function b(t,e,n,s,i){return i.relativeTime(e||1,!!n,t,s)}function S(t,e,n){var s=W(Math.abs(t)/1e3),i=W(s/60),r=W(i/60),a=W(r/24),o=W(a/365),u=45>s&&["s",s]||1===i&&["m"]||45>i&&["mm",i]||1===r&&["h"]||22>r&&["hh",r]||1===a&&["d"]||25>=a&&["dd",a]||45>=a&&["M"]||345>a&&["MM",W(a/30)]||1===o&&["y"]||["yy",o];return u[2]=e,u[3]=t>0,u[4]=n,b.apply({},u)}function F(t,e,n){var s,i=n-e,r=n-t.day();return r>i&&(r-=7),i-7>r&&(r+=7),s=H(t).add("d",r),{week:Math.ceil(s.dayOfYear()/7),year:s.year()}}function O(t){var e=t._i,n=t._f;return null===e||""===e?null:("string"==typeof e&&(t._i=e=_().preparse(e)),H.isMoment(e)?(t=a({},e),t._d=new Date(+e._d)):n?d(n)?k(t):w(t):T(t),new i(t))}function z(t,e){H.fn[t]=H.fn[t+"s"]=function(t){var n=this._isUTC?"UTC":"";return null!=t?(this._d["set"+n+e](t),H.updateOffset(this),this):this._d["get"+n+e]()}}function C(t){H.duration.fn[t]=function(){return this._data[t]}}function L(t,e){H.duration.fn["as"+t]=function(){return+this/e}}for(var H,P,U="2.1.0",W=Math.round,x={},A="undefined"!=typeof module&&module.exports,G=/^\/?Date\((\-?\d+)/i,Z=/(\-)?(\d*)?\.?(\d+)\:(\d+)\:(\d+)\.?(\d{3})?/,E=/(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|SS?S?|X|zz?|ZZ?|.)/g,N=/(\[[^\[]*\])|(\\)?(LT|LL?L?L?|l{1,4})/g,J=/\d\d?/,I=/\d{1,3}/,V=/\d{3}/,X=/\d{1,4}/,$=/[+\-]?\d{1,6}/,R=/[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i,j=/Z|[\+\-]\d\d:?\d\d/i,q=/T/i,B=/[\+\-]?\d+(\.\d{1,3})?/,K=/^\s*\d{4}-\d\d-\d\d((T| )(\d\d(:\d\d(:\d\d(\.\d\d?\d?)?)?)?)?([\+\-]\d\d:?\d\d)?)?/,Q="YYYY-MM-DDTHH:mm:ssZ",te=[["HH:mm:ss.S",/(T| )\d\d:\d\d:\d\d\.\d{1,3}/],["HH:mm:ss",/(T| )\d\d:\d\d:\d\d/],["HH:mm",/(T| )\d\d:\d\d/],["HH",/(T| )\d\d/]],ee=/([\+\-]|\d\d)/gi,ne="Date|Hours|Minutes|Seconds|Milliseconds".split("|"),se={Milliseconds:1,Seconds:1e3,Minutes:6e4,Hours:36e5,Days:864e5,Months:2592e6,Years:31536e6},ie={ms:"millisecond",s:"second",m:"minute",h:"hour",d:"day",w:"week",M:"month",y:"year"},re={},ae="DDD w W M D d".split(" "),oe="M D H h m s w W".split(" "),ue={M:function(){return this.month()+1},MMM:function(t){return this.lang().monthsShort(this,t)},MMMM:function(t){return this.lang().months(this,t)},D:function(){return this.date()},DDD:function(){return this.dayOfYear()},d:function(){return this.day()},dd:function(t){return this.lang().weekdaysMin(this,t)},ddd:function(t){return this.lang().weekdaysShort(this,t)},dddd:function(t){return this.lang().weekdays(this,t)},w:function(){return this.week()},W:function(){return this.isoWeek()},YY:function(){return u(this.year()%100,2)},YYYY:function(){return u(this.year(),4)},YYYYY:function(){return u(this.year(),5)},gg:function(){return u(this.weekYear()%100,2)},gggg:function(){return this.weekYear()},ggggg:function(){return u(this.weekYear(),5)},GG:function(){return u(this.isoWeekYear()%100,2)},GGGG:function(){return this.isoWeekYear()},GGGGG:function(){return u(this.isoWeekYear(),5)},e:function(){return this.weekday()},E:function(){return this.isoWeekday()},a:function(){return this.lang().meridiem(this.hours(),this.minutes(),!0)},A:function(){return this.lang().meridiem(this.hours(),this.minutes(),!1)},H:function(){return this.hours()},h:function(){return this.hours()%12||12},m:function(){return this.minutes()},s:function(){return this.seconds()},S:function(){return~~(this.milliseconds()/100)},SS:function(){return u(~~(this.milliseconds()/10),2)},SSS:function(){return u(this.milliseconds(),3)},Z:function(){var t=-this.zone(),e="+";return 0>t&&(t=-t,e="-"),e+u(~~(t/60),2)+":"+u(~~t%60,2)},ZZ:function(){var t=-this.zone(),e="+";return 0>t&&(t=-t,e="-"),e+u(~~(10*t/6),4)},z:function(){return this.zoneAbbr()},zz:function(){return this.zoneName()},X:function(){return this.unix()}};ae.length;)P=ae.pop(),ue[P+"o"]=n(ue[P],P);for(;oe.length;)P=oe.pop(),ue[P+P]=e(ue[P],2);for(ue.DDDD=e(ue.DDD,3),s.prototype={set:function(t){var e,n;for(n in t)e=t[n],"function"==typeof e?this[n]=e:this["_"+n]=e},_months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),months:function(t){return this._months[t.month()]},_monthsShort:"Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),monthsShort:function(t){return this._monthsShort[t.month()]},monthsParse:function(t){var e,n,s;for(this._monthsParse||(this._monthsParse=[]),e=0;12>e;e++)if(this._monthsParse[e]||(n=H([2e3,e]),s="^"+this.months(n,"")+"|^"+this.monthsShort(n,""),this._monthsParse[e]=new RegExp(s.replace(".",""),"i")),this._monthsParse[e].test(t))return e},_weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),weekdays:function(t){return this._weekdays[t.day()]},_weekdaysShort:"Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),weekdaysShort:function(t){return this._weekdaysShort[t.day()]},_weekdaysMin:"Su_Mo_Tu_We_Th_Fr_Sa".split("_"),weekdaysMin:function(t){return this._weekdaysMin[t.day()]},weekdaysParse:function(t){var e,n,s;for(this._weekdaysParse||(this._weekdaysParse=[]),e=0;7>e;e++)if(this._weekdaysParse[e]||(n=H([2e3,1]).day(e),s="^"+this.weekdays(n,"")+"|^"+this.weekdaysShort(n,"")+"|^"+this.weekdaysMin(n,""),this._weekdaysParse[e]=new RegExp(s.replace(".",""),"i")),this._weekdaysParse[e].test(t))return e},_longDateFormat:{LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D YYYY",LLL:"MMMM D YYYY LT",LLLL:"dddd, MMMM D YYYY LT"},longDateFormat:function(t){var e=this._longDateFormat[t];return!e&&this._longDateFormat[t.toUpperCase()]&&(e=this._longDateFormat[t.toUpperCase()].replace(/MMMM|MM|DD|dddd/g,function(t){return t.slice(1)}),this._longDateFormat[t]=e),e},isPM:function(t){return"p"===(t+"").toLowerCase()[0]},_meridiemParse:/[ap]\.?m?\.?/i,meridiem:function(t,e,n){return t>11?n?"pm":"PM":n?"am":"AM"},_calendar:{sameDay:"[Today at] LT",nextDay:"[Tomorrow at] LT",nextWeek:"dddd [at] LT",lastDay:"[Yesterday at] LT",lastWeek:"[Last] dddd [at] LT",sameElse:"L"},calendar:function(t,e){var n=this._calendar[t];return"function"==typeof n?n.apply(e):n},_relativeTime:{future:"in %s",past:"%s ago",s:"a few seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},relativeTime:function(t,e,n,s){var i=this._relativeTime[n];return"function"==typeof i?i(t,e,n,s):i.replace(/%d/i,t)},pastFuture:function(t,e){var n=this._relativeTime[t>0?"future":"past"];return"function"==typeof n?n(e):n.replace(/%s/i,e)},ordinal:function(t){return this._ordinal.replace("%d",t)},_ordinal:"%d",preparse:function(t){return t},postformat:function(t){return t},week:function(t){return F(t,this._week.dow,this._week.doy).week},_week:{dow:0,doy:6}},H=function(t,e,n){return O({_i:t,_f:e,_l:n,_isUTC:!1})},H.utc=function(t,e,n){return O({_useUTC:!0,_isUTC:!0,_l:n,_i:t,_f:e})},H.unix=function(t){return H(1e3*t)},H.duration=function(t,e){var n,s,i=H.isDuration(t),a="number"==typeof t,o=i?t._input:a?{}:t,u=Z.exec(t);return a?e?o[e]=t:o.milliseconds=t:u&&(n="-"===u[1]?-1:1,o={y:0,d:~~u[2]*n,h:~~u[3]*n,m:~~u[4]*n,s:~~u[5]*n,ms:~~u[6]*n}),s=new r(o),i&&t.hasOwnProperty("_lang")&&(s._lang=t._lang),s},H.version=U,H.defaultFormat=Q,H.updateOffset=function(){},H.lang=function(t,e){return t?(e?l(t,e):x[t]||_(t),H.duration.fn._lang=H.fn._lang=_(t),void 0):H.fn._lang._abbr},H.langData=function(t){return t&&t._lang&&t._lang._abbr&&(t=t._lang._abbr),_(t)},H.isMoment=function(t){return t instanceof i},H.isDuration=function(t){return t instanceof r},H.fn=i.prototype={clone:function(){return H(this)},valueOf:function(){return+this._d+6e4*(this._offset||0)},unix:function(){return Math.floor(+this/1e3)},toString:function(){return this.format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")},toDate:function(){return this._offset?new Date(+this):this._d},toISOString:function(){return M(H(this).utc(),"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]")},toArray:function(){var t=this;return[t.year(),t.month(),t.date(),t.hours(),t.minutes(),t.seconds(),t.milliseconds()]},isValid:function(){return null==this._isValid&&(this._isValid=this._a?!c(this._a,(this._isUTC?H.utc(this._a):H(this._a)).toArray()):!isNaN(this._d.getTime())),!!this._isValid},utc:function(){return this.zone(0)},local:function(){return this.zone(0),this._isUTC=!1,this},format:function(t){var e=M(this,t||H.defaultFormat);return this.lang().postformat(e)},add:function(t,e){var n;return n="string"==typeof t?H.duration(+e,t):H.duration(t,e),h(this,n,1),this},subtract:function(t,e){var n;return n="string"==typeof t?H.duration(+e,t):H.duration(t,e),h(this,n,-1),this},diff:function(t,e,n){var s,i,r=this._isUTC?H(t).zone(this._offset||0):H(t).local(),a=6e4*(this.zone()-r.zone());return e=f(e),"year"===e||"month"===e?(s=432e5*(this.daysInMonth()+r.daysInMonth()),i=12*(this.year()-r.year())+(this.month()-r.month()),i+=(this-H(this).startOf("month")-(r-H(r).startOf("month")))/s,i-=6e4*(this.zone()-H(this).startOf("month").zone()-(r.zone()-H(r).startOf("month").zone()))/s,"year"===e&&(i/=12)):(s=this-r,i="second"===e?s/1e3:"minute"===e?s/6e4:"hour"===e?s/36e5:"day"===e?(s-a)/864e5:"week"===e?(s-a)/6048e5:s),n?i:o(i)},from:function(t,e){return H.duration(this.diff(t)).lang(this.lang()._abbr).humanize(!e)},fromNow:function(t){return this.from(H(),t)},calendar:function(){var t=this.diff(H().startOf("day"),"days",!0),e=-6>t?"sameElse":-1>t?"lastWeek":0>t?"lastDay":1>t?"sameDay":2>t?"nextDay":7>t?"nextWeek":"sameElse";return this.format(this.lang().calendar(e,this))},isLeapYear:function(){var t=this.year();return 0===t%4&&0!==t%100||0===t%400},isDST:function(){return this.zone()<this.clone().month(0).zone()||this.zone()<this.clone().month(5).zone()},day:function(t){var e=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=t?"string"==typeof t&&(t=this.lang().weekdaysParse(t),"number"!=typeof t)?this:this.add({d:t-e}):e},month:function(t){var e,n=this._isUTC?"UTC":"";return null!=t?"string"==typeof t&&(t=this.lang().monthsParse(t),"number"!=typeof t)?this:(e=this.date(),this.date(1),this._d["set"+n+"Month"](t),this.date(Math.min(e,this.daysInMonth())),H.updateOffset(this),this):this._d["get"+n+"Month"]()},startOf:function(t){switch(t=f(t)){case"year":this.month(0);case"month":this.date(1);case"week":case"day":this.hours(0);case"hour":this.minutes(0);case"minute":this.seconds(0);case"second":this.milliseconds(0)}return"week"===t&&this.weekday(0),this},endOf:function(t){return this.startOf(t).add(t,1).subtract("ms",1)},isAfter:function(t,e){return e="undefined"!=typeof e?e:"millisecond",+this.clone().startOf(e)>+H(t).startOf(e)},isBefore:function(t,e){return e="undefined"!=typeof e?e:"millisecond",+this.clone().startOf(e)<+H(t).startOf(e)},isSame:function(t,e){return e="undefined"!=typeof e?e:"millisecond",+this.clone().startOf(e)===+H(t).startOf(e)},min:function(t){return t=H.apply(null,arguments),this>t?this:t},max:function(t){return t=H.apply(null,arguments),t>this?this:t},zone:function(t){var e=this._offset||0;return null==t?this._isUTC?e:this._d.getTimezoneOffset():("string"==typeof t&&(t=p(t)),Math.abs(t)<16&&(t=60*t),this._offset=t,this._isUTC=!0,e!==t&&h(this,H.duration(e-t,"m"),1,!0),this)},zoneAbbr:function(){return this._isUTC?"UTC":""},zoneName:function(){return this._isUTC?"Coordinated Universal Time":""},daysInMonth:function(){return H.utc([this.year(),this.month()+1,0]).date()},dayOfYear:function(t){var e=W((H(this).startOf("day")-H(this).startOf("year"))/864e5)+1;return null==t?e:this.add("d",t-e)},weekYear:function(t){var e=F(this,this.lang()._week.dow,this.lang()._week.doy).year;return null==t?e:this.add("y",t-e)},isoWeekYear:function(t){var e=F(this,1,4).year;return null==t?e:this.add("y",t-e)},week:function(t){var e=this.lang().week(this);return null==t?e:this.add("d",7*(t-e))},isoWeek:function(t){var e=F(this,1,4).week;return null==t?e:this.add("d",7*(t-e))},weekday:function(t){var e=(this._d.getDay()+7-this.lang()._week.dow)%7;return null==t?e:this.add("d",t-e)},isoWeekday:function(t){return null==t?this.day()||7:this.day(this.day()%7?t:t-7)},lang:function(e){return e===t?this._lang:(this._lang=_(e),this)}},P=0;P<ne.length;P++)z(ne[P].toLowerCase().replace(/s$/,""),ne[P]);z("year","FullYear"),H.fn.days=H.fn.day,H.fn.months=H.fn.month,H.fn.weeks=H.fn.week,H.fn.isoWeeks=H.fn.isoWeek,H.fn.toJSON=H.fn.toISOString,H.duration.fn=r.prototype={_bubble:function(){var t,e,n,s,i=this._milliseconds,r=this._days,a=this._months,u=this._data;u.milliseconds=i%1e3,t=o(i/1e3),u.seconds=t%60,e=o(t/60),u.minutes=e%60,n=o(e/60),u.hours=n%24,r+=o(n/24),u.days=r%30,a+=o(r/30),u.months=a%12,s=o(a/12),u.years=s},weeks:function(){return o(this.days()/7)},valueOf:function(){return this._milliseconds+864e5*this._days+2592e6*(this._months%12)+31536e6*~~(this._months/12)},humanize:function(t){var e=+this,n=S(e,!t,this.lang());return t&&(n=this.lang().pastFuture(e,n)),this.lang().postformat(n)},add:function(t,e){var n=H.duration(t,e);return this._milliseconds+=n._milliseconds,this._days+=n._days,this._months+=n._months,this._bubble(),this},subtract:function(t,e){var n=H.duration(t,e);return this._milliseconds-=n._milliseconds,this._days-=n._days,this._months-=n._months,this._bubble(),this},get:function(t){return t=f(t),this[t.toLowerCase()+"s"]()},as:function(t){return t=f(t),this["as"+t.charAt(0).toUpperCase()+t.slice(1)+"s"]()},lang:H.fn.lang};for(P in se)se.hasOwnProperty(P)&&(L(P,se[P]),C(P.toLowerCase()));L("Weeks",6048e5),H.duration.fn.asMonths=function(){return(+this-31536e6*this.years())/2592e6+12*this.years()},H.lang("en",{ordinal:function(t){var e=t%10,n=1===~~(t%100/10)?"th":1===e?"st":2===e?"nd":3===e?"rd":"th";return t+n}}),A&&(module.exports=H),"undefined"==typeof ender&&(this.moment=H),"function"==typeof define&&define.amd&&define("moment",[],function(){return H})}.call(this);
  7. /**
  8. * @version: 1.2
  9. * @author: Dan Grossman http://www.dangrossman.info/
  10. * @date: 2013-07-25
  11. * @copyright: Copyright (c) 2012-2013 Dan Grossman. All rights reserved.
  12. * @license: Licensed under Apache License v2.0. See http://www.apache.org/licenses/LICENSE-2.0
  13. * @website: http://www.improvely.com/
  14. */
  15. !function ($) {
  16. var DateRangePicker = function (element, options, cb) {
  17. var hasOptions = typeof options == 'object';
  18. var localeObject;
  19. //option defaults
  20. this.startDate = moment().startOf('day');
  21. this.endDate = moment().startOf('day');
  22. this.minDate = false;
  23. this.maxDate = false;
  24. this.dateLimit = false;
  25. this.showDropdowns = false;
  26. this.showWeekNumbers = false;
  27. this.timePicker = false;
  28. this.timePickerIncrement = 30;
  29. this.timePicker12Hour = true;
  30. this.ranges = {};
  31. this.opens = 'right';
  32. this.buttonClasses = ['btn', 'btn-small'];
  33. this.applyClass = 'btn-success';
  34. this.cancelClass = 'btn-default';
  35. this.format = 'MM/DD/YYYY';
  36. this.separator = ' - ';
  37. this.locale = {
  38. applyLabel: 'Apply',
  39. cancelLabel: 'Cancel',
  40. fromLabel: 'From',
  41. toLabel: 'To',
  42. weekLabel: 'W',
  43. customRangeLabel: 'Custom Range',
  44. daysOfWeek: moment()._lang._weekdaysMin.slice(),
  45. monthNames: moment()._lang._monthsShort.slice(),
  46. firstDay: 0
  47. };
  48. this.cb = function () { };
  49. // by default, the daterangepicker element is placed at the bottom of HTML body
  50. this.parentEl = 'body';
  51. //element that triggered the date range picker
  52. this.element = $(element);
  53. if (this.element.hasClass('pull-right'))
  54. this.opens = 'left';
  55. if (this.element.is('input')) {
  56. this.element.on({
  57. click: $.proxy(this.show, this),
  58. focus: $.proxy(this.show, this)
  59. });
  60. } else {
  61. this.element.on('click', $.proxy(this.show, this));
  62. }
  63. localeObject = this.locale;
  64. if (hasOptions) {
  65. if (typeof options.locale == 'object') {
  66. $.each(localeObject, function (property, value) {
  67. localeObject[property] = options.locale[property] || value;
  68. });
  69. }
  70. if (options.applyClass) {
  71. this.applyClass = options.applyClass;
  72. }
  73. if (options.cancelClass) {
  74. this.cancelClass = options.cancelClass;
  75. }
  76. }
  77. var DRPTemplate = '<div class="daterangepicker dropdown-menu">' +
  78. '<div class="calendar left"></div>' +
  79. '<div class="calendar right"></div>' +
  80. '<div class="ranges">' +
  81. '<div class="range_inputs">' +
  82. '<div class="daterangepicker_start_input" style="float: left">' +
  83. '<label for="daterangepicker_start">' + this.locale.fromLabel + '</label>' +
  84. '<input class="input-mini" type="text" name="daterangepicker_start" value="" disabled="disabled" />' +
  85. '</div>' +
  86. '<div class="daterangepicker_end_input" style="float: left; padding-left: 11px">' +
  87. '<label for="daterangepicker_end">' + this.locale.toLabel + '</label>' +
  88. '<input class="input-mini" type="text" name="daterangepicker_end" value="" disabled="disabled" />' +
  89. '</div>' +
  90. '<button class="' + this.applyClass + ' applyBtn" disabled="disabled">' + this.locale.applyLabel + '</button>&nbsp;' +
  91. '<button class="' + this.cancelClass + ' cancelBtn">' + this.locale.cancelLabel + '</button>' +
  92. '</div>' +
  93. '</div>' +
  94. '</div>';
  95. this.parentEl = (hasOptions && options.parentEl && $(options.parentEl)) || $(this.parentEl);
  96. //the date range picker
  97. this.container = $(DRPTemplate).appendTo(this.parentEl);
  98. if (hasOptions) {
  99. if (typeof options.format == 'string')
  100. this.format = options.format;
  101. if (typeof options.separator == 'string')
  102. this.separator = options.separator;
  103. if (typeof options.startDate == 'string')
  104. this.startDate = moment(options.startDate, this.format);
  105. if (typeof options.endDate == 'string')
  106. this.endDate = moment(options.endDate, this.format);
  107. if (typeof options.minDate == 'string')
  108. this.minDate = moment(options.minDate, this.format);
  109. if (typeof options.maxDate == 'string')
  110. this.maxDate = moment(options.maxDate, this.format);
  111. if (typeof options.startDate == 'object')
  112. this.startDate = moment(options.startDate);
  113. if (typeof options.endDate == 'object')
  114. this.endDate = moment(options.endDate);
  115. if (typeof options.minDate == 'object')
  116. this.minDate = moment(options.minDate);
  117. if (typeof options.maxDate == 'object')
  118. this.maxDate = moment(options.maxDate);
  119. if (typeof options.ranges == 'object') {
  120. for (var range in options.ranges) {
  121. var start = moment(options.ranges[range][0]);
  122. var end = moment(options.ranges[range][1]);
  123. // If we have a min/max date set, bound this range
  124. // to it, but only if it would otherwise fall
  125. // outside of the min/max.
  126. if (this.minDate && start.isBefore(this.minDate))
  127. start = moment(this.minDate);
  128. if (this.maxDate && end.isAfter(this.maxDate))
  129. end = moment(this.maxDate);
  130. // If the end of the range is before the minimum (if min is set) OR
  131. // the start of the range is after the max (also if set) don't display this
  132. // range option.
  133. if ((this.minDate && end.isBefore(this.minDate)) || (this.maxDate && start.isAfter(this.maxDate))) {
  134. continue;
  135. }
  136. this.ranges[range] = [start, end];
  137. }
  138. var list = '<ul>';
  139. for (var range in this.ranges) {
  140. list += '<li>' + range + '</li>';
  141. }
  142. list += '<li>' + this.locale.customRangeLabel + '</li>';
  143. list += '</ul>';
  144. this.container.find('.ranges').prepend(list);
  145. }
  146. if (typeof options.dateLimit == 'object')
  147. this.dateLimit = options.dateLimit;
  148. // update day names order to firstDay
  149. if (typeof options.locale == 'object') {
  150. if (typeof options.locale.daysOfWeek == 'object') {
  151. // Create a copy of daysOfWeek to avoid modification of original
  152. // options object for reusability in multiple daterangepicker instances
  153. this.locale.daysOfWeek = options.locale.daysOfWeek.slice();
  154. }
  155. if (typeof options.locale.firstDay == 'number') {
  156. this.locale.firstDay = options.locale.firstDay;
  157. var iterator = options.locale.firstDay;
  158. while (iterator > 0) {
  159. this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift());
  160. iterator--;
  161. }
  162. }
  163. }
  164. if (typeof options.opens == 'string')
  165. this.opens = options.opens;
  166. if (typeof options.showWeekNumbers == 'boolean') {
  167. this.showWeekNumbers = options.showWeekNumbers;
  168. }
  169. if (typeof options.buttonClasses == 'string') {
  170. this.buttonClasses = [options.buttonClasses];
  171. }
  172. if (typeof options.buttonClasses == 'object') {
  173. this.buttonClasses = options.buttonClasses;
  174. }
  175. if (typeof options.showDropdowns == 'boolean') {
  176. this.showDropdowns = options.showDropdowns;
  177. }
  178. if (typeof options.timePicker == 'boolean') {
  179. this.timePicker = options.timePicker;
  180. }
  181. if (typeof options.timePickerIncrement == 'number') {
  182. this.timePickerIncrement = options.timePickerIncrement;
  183. }
  184. if (typeof options.timePicker12Hour == 'boolean') {
  185. this.timePicker12Hour = options.timePicker12Hour;
  186. }
  187. }
  188. if (!this.timePicker) {
  189. this.startDate = this.startDate.startOf('day');
  190. this.endDate = this.endDate.startOf('day');
  191. }
  192. //apply CSS classes to buttons
  193. var c = this.container;
  194. $.each(this.buttonClasses, function (idx, val) {
  195. c.find('button').addClass(val);
  196. });
  197. if (this.opens == 'right') {
  198. //swap calendar positions
  199. var left = this.container.find('.calendar.left');
  200. var right = this.container.find('.calendar.right');
  201. left.removeClass('left').addClass('right');
  202. right.removeClass('right').addClass('left');
  203. }
  204. if (typeof options == 'undefined' || typeof options.ranges == 'undefined') {
  205. this.container.find('.calendar').show();
  206. this.move();
  207. }
  208. if (typeof cb == 'function')
  209. this.cb = cb;
  210. this.container.addClass('opens' + this.opens);
  211. //try parse date if in text input
  212. if (!hasOptions || (typeof options.startDate == 'undefined' && typeof options.endDate == 'undefined')) {
  213. if ($(this.element).is('input[type=text]')) {
  214. var val = $(this.element).val();
  215. var split = val.split(this.separator);
  216. var start, end;
  217. if (split.length == 2) {
  218. start = moment(split[0], this.format);
  219. end = moment(split[1], this.format);
  220. }
  221. if (start != null && end != null) {
  222. this.startDate = start;
  223. this.endDate = end;
  224. }
  225. }
  226. }
  227. //state
  228. this.oldStartDate = this.startDate.clone();
  229. this.oldEndDate = this.endDate.clone();
  230. this.leftCalendar = {
  231. month: moment([this.startDate.year(), this.startDate.month(), 1, this.startDate.hour(), this.startDate.minute()]),
  232. calendar: []
  233. };
  234. this.rightCalendar = {
  235. month: moment([this.endDate.year(), this.endDate.month(), 1, this.endDate.hour(), this.endDate.minute()]),
  236. calendar: []
  237. };
  238. //event listeners
  239. this.container.on('mousedown', $.proxy(this.mousedown, this));
  240. this.container.find('.calendar')
  241. .on('click', '.prev', $.proxy(this.clickPrev, this))
  242. .on('click', '.next', $.proxy(this.clickNext, this))
  243. .on('click', 'td.available', $.proxy(this.clickDate, this))
  244. .on('mouseenter', 'td.available', $.proxy(this.enterDate, this))
  245. .on('mouseleave', 'td.available', $.proxy(this.updateFormInputs, this))
  246. .on('change', 'select.yearselect', $.proxy(this.updateMonthYear, this))
  247. .on('change', 'select.monthselect', $.proxy(this.updateMonthYear, this))
  248. .on('change', 'select.hourselect,select.minuteselect,select.ampmselect', $.proxy(this.updateTime, this));
  249. this.container.find('.ranges')
  250. .on('click', 'button.applyBtn', $.proxy(this.clickApply, this))
  251. .on('click', 'button.cancelBtn', $.proxy(this.clickCancel, this))
  252. .on('click', '.daterangepicker_start_input,.daterangepicker_end_input', $.proxy(this.showCalendars, this))
  253. .on('click', 'li', $.proxy(this.clickRange, this))
  254. .on('mouseenter', 'li', $.proxy(this.enterRange, this))
  255. .on('mouseleave', 'li', $.proxy(this.updateFormInputs, this));
  256. this.element.on('keyup', $.proxy(this.updateFromControl, this));
  257. this.updateView();
  258. this.updateCalendars();
  259. };
  260. DateRangePicker.prototype = {
  261. constructor: DateRangePicker,
  262. mousedown: function (e) {
  263. e.stopPropagation();
  264. },
  265. updateView: function () {
  266. this.leftCalendar.month.month(this.startDate.month()).year(this.startDate.year());
  267. this.rightCalendar.month.month(this.endDate.month()).year(this.endDate.year());
  268. this.updateFormInputs();
  269. },
  270. updateFormInputs: function () {
  271. this.container.find('input[name=daterangepicker_start]').val(this.startDate.format(this.format));
  272. this.container.find('input[name=daterangepicker_end]').val(this.endDate.format(this.format));
  273. if (this.startDate.isSame(this.endDate) || this.startDate.isBefore(this.endDate)) {
  274. this.container.find('button.applyBtn').removeAttr('disabled');
  275. } else {
  276. this.container.find('button.applyBtn').attr('disabled', 'disabled');
  277. }
  278. },
  279. updateFromControl: function () {
  280. if (!this.element.is('input')) return;
  281. if (!this.element.val().length) return;
  282. var dateString = this.element.val().split(this.separator);
  283. var start = moment(dateString[0], this.format);
  284. var end = moment(dateString[1], this.format);
  285. if (start == null || end == null) return;
  286. if (end.isBefore(start)) return;
  287. this.oldStartDate = this.startDate.clone();
  288. this.oldEndDate = this.endDate.clone();
  289. this.startDate = start;
  290. this.endDate = end;
  291. if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
  292. this.notify();
  293. this.updateCalendars();
  294. },
  295. notify: function () {
  296. this.updateView();
  297. this.cb(this.startDate, this.endDate);
  298. },
  299. move: function () {
  300. var parentOffset = {
  301. top: this.parentEl.offset().top - (this.parentEl.is('body') ? 0 : this.parentEl.scrollTop()),
  302. left: this.parentEl.offset().left - (this.parentEl.is('body') ? 0 : this.parentEl.scrollLeft())
  303. };
  304. if (this.opens == 'left') {
  305. this.container.css({
  306. top: this.element.offset().top + this.element.outerHeight() - parentOffset.top,
  307. right: $(window).width() - this.element.offset().left - this.element.outerWidth() - parentOffset.left,
  308. left: 'auto'
  309. });
  310. if (this.container.offset().left < 0) {
  311. this.container.css({
  312. right: 'auto',
  313. left: 9
  314. });
  315. }
  316. } else {
  317. this.container.css({
  318. top: this.element.offset().top + this.element.outerHeight() - parentOffset.top,
  319. left: this.element.offset().left - parentOffset.left,
  320. right: 'auto'
  321. });
  322. if (this.container.offset().left + this.container.outerWidth() > $(window).width()) {
  323. this.container.css({
  324. left: 'auto',
  325. right: 0
  326. });
  327. }
  328. }
  329. },
  330. show: function (e) {
  331. this.container.show();
  332. this.move();
  333. if (e) {
  334. e.stopPropagation();
  335. e.preventDefault();
  336. }
  337. $(document).on('mousedown', $.proxy(this.hide, this));
  338. this.element.trigger('shown', {target: e.target, picker: this});
  339. },
  340. hide: function (e) {
  341. this.container.hide();
  342. if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
  343. this.notify();
  344. this.oldStartDate = this.startDate.clone();
  345. this.oldEndDate = this.endDate.clone();
  346. $(document).off('mousedown', this.hide);
  347. this.element.trigger('hidden', { picker: this });
  348. },
  349. enterRange: function (e) {
  350. var label = e.target.innerHTML;
  351. if (label == this.locale.customRangeLabel) {
  352. this.updateView();
  353. } else {
  354. var dates = this.ranges[label];
  355. this.container.find('input[name=daterangepicker_start]').val(dates[0].format(this.format));
  356. this.container.find('input[name=daterangepicker_end]').val(dates[1].format(this.format));
  357. }
  358. },
  359. showCalendars: function() {
  360. this.container.find('.calendar').show();
  361. this.move();
  362. },
  363. updateInputText: function() {
  364. if (this.element.is('input'))
  365. this.element.val(this.startDate.format(this.format) + this.separator + this.endDate.format(this.format));
  366. },
  367. clickRange: function (e) {
  368. var label = e.target.innerHTML;
  369. if (label == this.locale.customRangeLabel) {
  370. this.showCalendars();
  371. } else {
  372. var dates = this.ranges[label];
  373. this.startDate = dates[0];
  374. this.endDate = dates[1];
  375. if (!this.timePicker) {
  376. this.startDate.startOf('day');
  377. this.endDate.startOf('day');
  378. }
  379. this.leftCalendar.month.month(this.startDate.month()).year(this.startDate.year()).hour(this.startDate.hour()).minute(this.startDate.minute());
  380. this.rightCalendar.month.month(this.endDate.month()).year(this.endDate.year()).hour(this.endDate.hour()).minute(this.endDate.minute());
  381. this.updateCalendars();
  382. this.updateInputText();
  383. this.container.find('.calendar').hide();
  384. this.hide();
  385. }
  386. },
  387. clickPrev: function (e) {
  388. var cal = $(e.target).parents('.calendar');
  389. if (cal.hasClass('left')) {
  390. this.leftCalendar.month.subtract('month', 1);
  391. } else {
  392. this.rightCalendar.month.subtract('month', 1);
  393. }
  394. this.updateCalendars();
  395. },
  396. clickNext: function (e) {
  397. var cal = $(e.target).parents('.calendar');
  398. if (cal.hasClass('left')) {
  399. this.leftCalendar.month.add('month', 1);
  400. } else {
  401. this.rightCalendar.month.add('month', 1);
  402. }
  403. this.updateCalendars();
  404. },
  405. enterDate: function (e) {
  406. var title = $(e.target).attr('data-title');
  407. var row = title.substr(1, 1);
  408. var col = title.substr(3, 1);
  409. var cal = $(e.target).parents('.calendar');
  410. if (cal.hasClass('left')) {
  411. this.container.find('input[name=daterangepicker_start]').val(this.leftCalendar.calendar[row][col].format(this.format));
  412. } else {
  413. this.container.find('input[name=daterangepicker_end]').val(this.rightCalendar.calendar[row][col].format(this.format));
  414. }
  415. },
  416. clickDate: function (e) {
  417. var title = $(e.target).attr('data-title');
  418. var row = title.substr(1, 1);
  419. var col = title.substr(3, 1);
  420. var cal = $(e.target).parents('.calendar');
  421. if (cal.hasClass('left')) {
  422. var startDate = this.leftCalendar.calendar[row][col];
  423. var endDate = this.endDate;
  424. if (typeof this.dateLimit == 'object') {
  425. var maxDate = moment(startDate).add(this.dateLimit).startOf('day');
  426. if (endDate.isAfter(maxDate)) {
  427. endDate = maxDate;
  428. }
  429. }
  430. } else {
  431. var startDate = this.startDate;
  432. var endDate = this.rightCalendar.calendar[row][col];
  433. if (typeof this.dateLimit == 'object') {
  434. var minDate = moment(endDate).subtract(this.dateLimit).startOf('day');
  435. if (startDate.isBefore(minDate)) {
  436. startDate = minDate;
  437. }
  438. }
  439. }
  440. cal.find('td').removeClass('active');
  441. if (startDate.isSame(endDate) || startDate.isBefore(endDate)) {
  442. $(e.target).addClass('active');
  443. this.startDate = startDate;
  444. this.endDate = endDate;
  445. } else if (startDate.isAfter(endDate)) {
  446. $(e.target).addClass('active');
  447. this.startDate = startDate;
  448. this.endDate = moment(startDate).add('day', 1).startOf('day');
  449. }
  450. this.leftCalendar.month.month(this.startDate.month()).year(this.startDate.year());
  451. this.rightCalendar.month.month(this.endDate.month()).year(this.endDate.year());
  452. this.updateCalendars();
  453. },
  454. clickApply: function (e) {
  455. this.updateInputText();
  456. this.hide();
  457. },
  458. clickCancel: function (e) {
  459. this.startDate = this.oldStartDate;
  460. this.endDate = this.oldEndDate;
  461. this.updateView();
  462. this.updateCalendars();
  463. this.hide();
  464. },
  465. updateMonthYear: function (e) {
  466. var isLeft = $(e.target).closest('.calendar').hasClass('left');
  467. var cal = this.container.find('.calendar.left');
  468. if (!isLeft)
  469. cal = this.container.find('.calendar.right');
  470. // Month must be Number for new moment versions
  471. var month = parseInt(cal.find('.monthselect').val(), 10);
  472. var year = cal.find('.yearselect').val();
  473. if (isLeft) {
  474. this.leftCalendar.month.month(month).year(year);
  475. } else {
  476. this.rightCalendar.month.month(month).year(year);
  477. }
  478. this.updateCalendars();
  479. },
  480. updateTime: function(e) {
  481. var isLeft = $(e.target).closest('.calendar').hasClass('left');
  482. var cal = this.container.find('.calendar.left');
  483. if (!isLeft)
  484. cal = this.container.find('.calendar.right');
  485. var hour = parseInt(cal.find('.hourselect').val());
  486. var minute = parseInt(cal.find('.minuteselect').val());
  487. if (this.timePicker12Hour) {
  488. var ampm = cal.find('.ampmselect').val();
  489. if (ampm == 'PM' && hour < 12)
  490. hour += 12;
  491. if (ampm == 'AM' && hour == 12)
  492. hour = 0;
  493. }
  494. if (isLeft) {
  495. var start = this.startDate.clone();
  496. start.hour(hour);
  497. start.minute(minute);
  498. this.startDate = start;
  499. this.leftCalendar.month.hour(hour).minute(minute);
  500. } else {
  501. var end = this.endDate.clone();
  502. end.hour(hour);
  503. end.minute(minute);
  504. this.endDate = end;
  505. this.rightCalendar.month.hour(hour).minute(minute);
  506. }
  507. this.updateCalendars();
  508. },
  509. updateCalendars: function () {
  510. this.leftCalendar.calendar = this.buildCalendar(this.leftCalendar.month.month(), this.leftCalendar.month.year(), this.leftCalendar.month.hour(), this.leftCalendar.month.minute(), 'left');
  511. this.rightCalendar.calendar = this.buildCalendar(this.rightCalendar.month.month(), this.rightCalendar.month.year(), this.rightCalendar.month.hour(), this.rightCalendar.month.minute(), 'right');
  512. this.container.find('.calendar.left').html(this.renderCalendar(this.leftCalendar.calendar, this.startDate, this.minDate, this.maxDate));
  513. this.container.find('.calendar.right').html(this.renderCalendar(this.rightCalendar.calendar, this.endDate, this.startDate, this.maxDate));
  514. this.container.find('.ranges li').removeClass('active');
  515. var customRange = true;
  516. var i = 0;
  517. for (var range in this.ranges) {
  518. if (this.timePicker) {
  519. if (this.startDate.isSame(this.ranges[range][0]) && this.endDate.isSame(this.ranges[range][1])) {
  520. customRange = false;
  521. this.container.find('.ranges li:eq(' + i + ')').addClass('active');
  522. }
  523. } else {
  524. //ignore times when comparing dates if time picker is not enabled
  525. if (this.startDate.format('YYYY-MM-DD') == this.ranges[range][0].format('YYYY-MM-DD') && this.endDate.format('YYYY-MM-DD') == this.ranges[range][1].format('YYYY-MM-DD')) {
  526. customRange = false;
  527. this.container.find('.ranges li:eq(' + i + ')').addClass('active');
  528. }
  529. }
  530. i++;
  531. }
  532. if (customRange)
  533. this.container.find('.ranges li:last').addClass('active');
  534. },
  535. buildCalendar: function (month, year, hour, minute, side) {
  536. var firstDay = moment([year, month, 1]);
  537. var lastMonth = moment(firstDay).subtract('month', 1).month();
  538. var lastYear = moment(firstDay).subtract('month', 1).year();
  539. var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth();
  540. var dayOfWeek = firstDay.day();
  541. //initialize a 6 rows x 7 columns array for the calendar
  542. var calendar = [];
  543. for (var i = 0; i < 6; i++) {
  544. calendar[i] = [];
  545. }
  546. //populate the calendar with date objects
  547. var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1;
  548. if (startDay > daysInLastMonth)
  549. startDay -= 7;
  550. if (dayOfWeek == this.locale.firstDay)
  551. startDay = daysInLastMonth - 6;
  552. var curDate = moment([lastYear, lastMonth, startDay, 12, minute]);
  553. for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add('hour', 24)) {
  554. if (i > 0 && col % 7 == 0) {
  555. col = 0;
  556. row++;
  557. }
  558. calendar[row][col] = curDate.clone().hour(hour);
  559. curDate.hour(12);
  560. }
  561. return calendar;
  562. },
  563. renderDropdowns: function (selected, minDate, maxDate) {
  564. var currentMonth = selected.month();
  565. var monthHtml = '<select class="monthselect">';
  566. var inMinYear = false;
  567. var inMaxYear = false;
  568. for (var m = 0; m < 12; m++) {
  569. if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || m <= maxDate.month())) {
  570. monthHtml += "<option value='" + m + "'" +
  571. (m === currentMonth ? " selected='selected'" : "") +
  572. ">" + this.locale.monthNames[m] + "</option>";
  573. }
  574. }
  575. monthHtml += "</select>";
  576. var currentYear = selected.year();
  577. var maxYear = (maxDate && maxDate.year()) || (currentYear + 5);
  578. var minYear = (minDate && minDate.year()) || (currentYear - 50);
  579. var yearHtml = '<select class="yearselect">';
  580. for (var y = minYear; y <= maxYear; y++) {
  581. yearHtml += '<option value="' + y + '"' +
  582. (y === currentYear ? ' selected="selected"' : '') +
  583. '>' + y + '</option>';
  584. }
  585. yearHtml += '</select>';
  586. return monthHtml + yearHtml;
  587. },
  588. renderCalendar: function (calendar, selected, minDate, maxDate) {
  589. var html = '<div class="calendar-date">';
  590. html += '<table class="table-condensed">';
  591. html += '<thead>';
  592. html += '<tr>';
  593. // add empty cell for week number
  594. if (this.showWeekNumbers)
  595. html += '<th></th>';
  596. if (!minDate || minDate.isBefore(calendar[1][1])) {
  597. html += '<th class="prev available"><i class="icon-arrow-left glyphicon glyphicon-arrow-left"></i></th>';
  598. } else {
  599. html += '<th></th>';
  600. }
  601. var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");
  602. if (this.showDropdowns) {
  603. dateHtml = this.renderDropdowns(calendar[1][1], minDate, maxDate);
  604. }
  605. html += '<th colspan="5" style="width: auto">' + dateHtml + '</th>';
  606. if (!maxDate || maxDate.isAfter(calendar[1][1])) {
  607. html += '<th class="next available"><i class="icon-arrow-right glyphicon glyphicon-arrow-right"></i></th>';
  608. } else {
  609. html += '<th></th>';
  610. }
  611. html += '</tr>';
  612. html += '<tr>';
  613. // add week number label
  614. if (this.showWeekNumbers)
  615. html += '<th class="week">' + this.locale.weekLabel + '</th>';
  616. $.each(this.locale.daysOfWeek, function (index, dayOfWeek) {
  617. html += '<th>' + dayOfWeek + '</th>';
  618. });
  619. html += '</tr>';
  620. html += '</thead>';
  621. html += '<tbody>';
  622. for (var row = 0; row < 6; row++) {
  623. html += '<tr>';
  624. // add week number
  625. if (this.showWeekNumbers)
  626. html += '<td class="week">' + calendar[row][0].week() + '</td>';
  627. for (var col = 0; col < 7; col++) {
  628. var cname = 'available ';
  629. cname += (calendar[row][col].month() == calendar[1][1].month()) ? '' : 'off';
  630. if ((minDate && calendar[row][col].isBefore(minDate)) || (maxDate && calendar[row][col].isAfter(maxDate))) {
  631. cname = ' off disabled ';
  632. } else if (calendar[row][col].format('YYYY-MM-DD') == selected.format('YYYY-MM-DD')) {
  633. cname += ' active ';
  634. if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD')) {
  635. cname += ' start-date ';
  636. }
  637. if (calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD')) {
  638. cname += ' end-date ';
  639. }
  640. } else if (calendar[row][col] >= this.startDate && calendar[row][col] <= this.endDate) {
  641. cname += ' in-range ';
  642. if (calendar[row][col].isSame(this.startDate)) { cname += ' start-date '; }
  643. if (calendar[row][col].isSame(this.endDate)) { cname += ' end-date '; }
  644. }
  645. var title = 'r' + row + 'c' + col;
  646. html += '<td class="' + cname.replace(/\s+/g, ' ').replace(/^\s?(.*?)\s?$/, '$1') + '" data-title="' + title + '">' + calendar[row][col].date() + '</td>';
  647. }
  648. html += '</tr>';
  649. }
  650. html += '</tbody>';
  651. html += '</table>';
  652. html += '</div>';
  653. if (this.timePicker) {
  654. html += '<div class="calendar-time">';
  655. html += '<select class="hourselect">';
  656. var start = 0;
  657. var end = 23;
  658. var selected_hour = selected.hour();
  659. if (this.timePicker12Hour) {
  660. start = 1;
  661. end = 12;
  662. if (selected_hour >= 12)
  663. selected_hour -= 12;
  664. if (selected_hour == 0)
  665. selected_hour = 12;
  666. }
  667. for (var i = start; i <= end; i++) {
  668. if (i == selected_hour) {
  669. html += '<option value="' + i + '" selected="selected">' + i + '</option>';
  670. } else {
  671. html += '<option value="' + i + '">' + i + '</option>';
  672. }
  673. }
  674. html += '</select> : ';
  675. html += '<select class="minuteselect">';
  676. for (var i = 0; i < 60; i += this.timePickerIncrement) {
  677. var num = i;
  678. if (num < 10)
  679. num = '0' + num;
  680. if (i == selected.minute()) {
  681. html += '<option value="' + i + '" selected="selected">' + num + '</option>';
  682. } else {
  683. html += '<option value="' + i + '">' + num + '</option>';
  684. }
  685. }
  686. html += '</select> ';
  687. if (this.timePicker12Hour) {
  688. html += '<select class="ampmselect">';
  689. if (selected.hour() >= 12) {
  690. html += '<option value="AM">AM</option><option value="PM" selected="selected">PM</option>';
  691. } else {
  692. html += '<option value="AM" selected="selected">AM</option><option value="PM">PM</option>';
  693. }
  694. html += '</select>';
  695. }
  696. html += '</div>';
  697. }
  698. return html;
  699. }
  700. };
  701. $.fn.daterangepicker = function (options, cb) {
  702. this.each(function () {
  703. var el = $(this);
  704. if (!el.data('daterangepicker'))
  705. el.data('daterangepicker', new DateRangePicker(el, options, cb));
  706. });
  707. return this;
  708. };
  709. }(window.jQuery);