diff --git a/config/routes/battery.yaml b/config/routes/battery.yaml index 00045f0a..7fa4c9e2 100644 --- a/config/routes/battery.yaml +++ b/config/routes/battery.yaml @@ -55,6 +55,11 @@ bmfg_create_submit: controller: App\Controller\BatteryManufacturerController::addSubmit methods: [POST] +bmfg_batteries: + path: /battery-manufacturers/batteries + controller: App\Controller\BatteryManufacturerController::getBatteries + methods: [POST] + bmfg_update: path: /battery-manufacturers/{id} controller: App\Controller\BatteryManufacturerController::updateForm diff --git a/config/routes/rider.yaml b/config/routes/rider.yaml new file mode 100644 index 00000000..61a4522e --- /dev/null +++ b/config/routes/rider.yaml @@ -0,0 +1,38 @@ +rider_list: + path: /riders + controller: App\Controller\RiderController::index + +rider_rows: + path: /riders/rows + controller: App\Controller\RiderController::rows + methods: [POST] + +rider_upload_image: + path: /riders/upload + controller: App\Controller\RiderController::uploadImage + methods: [POST] + +rider_create: + path: /riders/create + controller: App\Controller\RiderController::addForm + methods: [GET] + +rider_create_submit: + path: /riders/create + controller: App\Controller\RiderController::addSubmit + methods: [POST] + +rider_update: + path: /riders/{id} + controller: App\Controller\RiderController::updateForm + methods: [GET] + +rider_update_submit: + path: /riders/{id} + controller: App\Controller\RiderController::updateSubmit + methods: [POST] + +rider_delete: + path: /riders/{id} + controller: App\Controller\RiderController::destroy + methods: [DELETE] diff --git a/config/services.yaml b/config/services.yaml index e6db3247..1ca0e73d 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -5,6 +5,7 @@ parameters: map_default: latitude: 14.6091 longitude: 121.0223 + image_upload_directory: '%kernel.project_dir%/public/uploads' services: # default configuration for services in *this* file @@ -45,3 +46,7 @@ services: arguments: $acl_gen: "@App\\Access\\Generator" tags: ['security.voter'] + + App\Service\FileUploader: + arguments: + $target_dir: '%image_upload_directory%' diff --git a/public/assets/css/style.css b/public/assets/css/style.css index 6bedb575..418fae62 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -1,7 +1,9 @@ /* template add-ons */ label.has-danger, -.form-control-feedback.has-danger { +.form-control-feedback.has-danger, +span.has-danger, +.nav-link.has-danger { color: #f4516c !important; } @@ -36,4 +38,36 @@ label.has-danger, .normal-font { font-size: inherit !important; font-weight: inherit !important; +} + +.block-switch { + display: block; +} + +.switch-label { + margin: 6px 0 0 8px; +} + +.portrait-box { + border: 2px solid #5867DD; + background-size: 100%; + background-repeat: no-repeat; + background-position: 50% 50%; + width: 150px; + height: 150px; +} + +.user-portrait-sm { + width: 40px; + height: 40px; + background-size: 100%; + background-repeat: no-repeat; + background-position: 50% 50%; + border-radius: 100%; +} + +@media (min-width: 995px) { + .modal-lg { + max-width: 1024px; + } } \ No newline at end of file diff --git a/public/assets/vendors/base/vendors.bundle.js b/public/assets/vendors/base/vendors.bundle.js index f1554473..fb5a4937 100644 --- a/public/assets/vendors/base/vendors.bundle.js +++ b/public/assets/vendors/base/vendors.bundle.js @@ -12872,363 +12872,363 @@ var bootstrap=function(t,e,n){"use strict";function i(t,e){for(var n=0;n0)for(n=0;n=0?n?"+":"":"-")+Math.pow(10,Math.max(0,i)).toString().substr(1)+s}function P(e,t,n,s){var i=s;"string"==typeof s&&(i=function(){return this[s]()}),e&&(ut[e]=i),t&&(ut[t[0]]=function(){return b(i.apply(this,arguments),t[1],t[2])}),n&&(ut[n]=function(){return this.localeData().ordinal(i.apply(this,arguments),e)})}function W(e){return e.match(/\[[\s\S]/)?e.replace(/^\[|\]$/g,""):e.replace(/\\/g,"")}function R(e,t){return e.isValid()?(t=C(t,e.localeData()),ot[t]=ot[t]||function(e){var t,n,s=e.match(rt);for(t=0,n=s.length;t=0&&at.test(e);)e=e.replace(at,n),at.lastIndex=0,s-=1;return e}function F(e,t,n){Yt[e]=k(t)?t:function(e,s){return e&&n?n:t}}function U(e,t){return o(Yt,e)?Yt[e](t._strict,t._locale):new RegExp(function(e){return N(e.replace("\\","").replace(/\\(\[)|\\(\])|\[([^\]\[]*)\]|\\(.)/g,function(e,t,n,s,i){return t||n||s||i}))}(e))}function N(e){return e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}function H(e,t){var n,s=t;for("string"==typeof e&&(e=[e]),i(t)&&(s=function(e,n){n[t]=g(e)}),n=0;n=0&&isFinite(t.getUTCFullYear())&&t.setUTCFullYear(e),t}function B(e,t,n){var s=7+t-n;return-((7+J(e,0,s).getUTCDay()-t)%7)+s-1}function Q(e,t,n,s,i){var r,a,o=1+7*(t-1)+(7+n-s)%7+B(e,s,i);return o<=0?a=V(r=e-1)+o:o>V(e)?(r=e+1,a=o-V(e)):(r=e,a=o),{year:r,dayOfYear:a}}function X(e,t,n){var s,i,r=B(e.year(),t,n),a=Math.floor((e.dayOfYear()-r-1)/7)+1;return a<1?s=a+K(i=e.year()-1,t,n):a>K(e.year(),t,n)?(s=a-K(e.year(),t,n),i=e.year()+1):(i=e.year(),s=a),{week:s,year:i}}function K(e,t,n){var s=B(e,t,n),i=B(e+1,t,n);return(V(e)-s+i)/7}function ee(){function e(e,t){return t.length-e.length}var t,n,s,i,r,a=[],o=[],u=[],d=[];for(t=0;t<7;t++)n=l([2e3,1]).day(t),s=this.weekdaysMin(n,""),i=this.weekdaysShort(n,""),r=this.weekdays(n,""),a.push(s),o.push(i),u.push(r),d.push(s),d.push(i),d.push(r);for(a.sort(e),o.sort(e),u.sort(e),d.sort(e),t=0;t<7;t++)o[t]=N(o[t]),u[t]=N(u[t]),d[t]=N(d[t]);this._weekdaysRegex=new RegExp("^("+d.join("|")+")","i"),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp("^("+u.join("|")+")","i"),this._weekdaysShortStrictRegex=new RegExp("^("+o.join("|")+")","i"),this._weekdaysMinStrictRegex=new RegExp("^("+a.join("|")+")","i")}function te(){return this.hours()%12||12}function ne(e,t){P(e,0,0,function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)})}function se(e,t){return t._meridiemParse}function ie(e){return e?e.toLowerCase().replace("_","-"):e}function re(e){var t=null;if(!Xt[e]&&"undefined"!=typeof module&&module&&module.exports)try{t=Jt._abbr;require("./locale/"+e),ae(t)}catch(e){}return Xt[e]}function ae(e,t){var n;return e&&(n=s(t)?ue(e):oe(e,t))&&(Jt=n),Jt._abbr}function oe(e,t){if(null!==t){var n=Qt;if(t.abbr=e,null!=Xt[e])M("defineLocaleOverride","use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info."),n=Xt[e]._config;else if(null!=t.parentLocale){if(null==Xt[t.parentLocale])return Kt[t.parentLocale]||(Kt[t.parentLocale]=[]),Kt[t.parentLocale].push({name:e,config:t}),null;n=Xt[t.parentLocale]._config}return Xt[e]=new D(S(n,t)),Kt[e]&&Kt[e].forEach(function(e){oe(e.name,e.config)}),ae(e),Xt[e]}return delete Xt[e],null}function ue(e){var n;if(e&&e._locale&&e._locale._abbr&&(e=e._locale._abbr),!e)return Jt;if(!t(e)){if(n=re(e))return n;e=[e]}return function(e){for(var t,n,s,i,r=0;r0;){if(s=re(i.slice(0,t).join("-")))return s;if(n&&n.length>=t&&p(i,n,!0)>=t-1)break;t--}r++}return null}(e)}function le(e){var t,n=e._a;return n&&-2===d(e).overflow&&(t=n[Tt]<0||n[Tt]>11?Tt:n[bt]<1||n[bt]>z(n[xt],n[Tt])?bt:n[Pt]<0||n[Pt]>24||24===n[Pt]&&(0!==n[Wt]||0!==n[Rt]||0!==n[Ct])?Pt:n[Wt]<0||n[Wt]>59?Wt:n[Rt]<0||n[Rt]>59?Rt:n[Ct]<0||n[Ct]>999?Ct:-1,d(e)._overflowDayOfYear&&(tbt)&&(t=bt),d(e)._overflowWeeks&&-1===t&&(t=Ft),d(e)._overflowWeekday&&-1===t&&(t=Ut),d(e).overflow=t),e}function de(e,t,n){return null!=e?e:null!=t?t:n}function he(t){var n,s,i,r,a,o=[];if(!t._d){for(i=function(t){var n=new Date(e.now());return t._useUTC?[n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()]:[n.getFullYear(),n.getMonth(),n.getDate()]}(t),t._w&&null==t._a[bt]&&null==t._a[Tt]&&function(e){var t,n,s,i,r,a,o,u;if(null!=(t=e._w).GG||null!=t.W||null!=t.E)r=1,a=4,n=de(t.GG,e._a[xt],X(pe(),1,4).year),s=de(t.W,1),((i=de(t.E,1))<1||i>7)&&(u=!0);else{r=e._locale._week.dow,a=e._locale._week.doy;var l=X(pe(),r,a);n=de(t.gg,e._a[xt],l.year),s=de(t.w,l.week),null!=t.d?((i=t.d)<0||i>6)&&(u=!0):null!=t.e?(i=t.e+r,(t.e<0||t.e>6)&&(u=!0)):i=r}s<1||s>K(n,r,a)?d(e)._overflowWeeks=!0:null!=u?d(e)._overflowWeekday=!0:(o=Q(n,s,i,r,a),e._a[xt]=o.year,e._dayOfYear=o.dayOfYear)}(t),null!=t._dayOfYear&&(a=de(t._a[xt],i[xt]),(t._dayOfYear>V(a)||0===t._dayOfYear)&&(d(t)._overflowDayOfYear=!0),s=J(a,0,t._dayOfYear),t._a[Tt]=s.getUTCMonth(),t._a[bt]=s.getUTCDate()),n=0;n<3&&null==t._a[n];++n)t._a[n]=o[n]=i[n];for(;n<7;n++)t._a[n]=o[n]=null==t._a[n]?2===n?1:0:t._a[n];24===t._a[Pt]&&0===t._a[Wt]&&0===t._a[Rt]&&0===t._a[Ct]&&(t._nextDay=!0,t._a[Pt]=0),t._d=(t._useUTC?J:function(e,t,n,s,i,r,a){var o=new Date(e,t,n,s,i,r,a);return e<100&&e>=0&&isFinite(o.getFullYear())&&o.setFullYear(e),o}).apply(null,o),r=t._useUTC?t._d.getUTCDay():t._d.getDay(),null!=t._tzm&&t._d.setUTCMinutes(t._d.getUTCMinutes()-t._tzm),t._nextDay&&(t._a[Pt]=24),t._w&&void 0!==t._w.d&&t._w.d!==r&&(d(t).weekdayMismatch=!0)}}function ce(e){var t,n,s,i,r,a,o=e._i,u=en.exec(o)||tn.exec(o);if(u){for(d(e).iso=!0,t=0,n=sn.length;t0&&d(t).unusedInput.push(a),o=o.slice(o.indexOf(s)+s.length),l+=s.length),ut[r]?(s?d(t).empty=!1:d(t).unusedTokens.push(r),G(r,s,t)):t._strict&&!s&&d(t).unusedTokens.push(r);d(t).charsLeftOver=u-l,o.length>0&&d(t).unusedInput.push(o),t._a[Pt]<=12&&!0===d(t).bigHour&&t._a[Pt]>0&&(d(t).bigHour=void 0),d(t).parsedDateParts=t._a.slice(0),d(t).meridiem=t._meridiem,t._a[Pt]=function(e,t,n){var s;if(null==n)return t;return null!=e.meridiemHour?e.meridiemHour(t,n):null!=e.isPM?((s=e.isPM(n))&&t<12&&(t+=12),s||12!==t||(t=0),t):t}(t._locale,t._a[Pt],t._meridiem),he(t),le(t)}else me(t);else ce(t)}function ye(o){var l=o._i,y=o._f;return o._locale=o._locale||ue(o._l),null===l||void 0===y&&""===l?c({nullInput:!0}):("string"==typeof l&&(o._i=l=o._locale.preparse(l)),_(l)?new m(le(l)):(r(l)?o._d=l:t(y)?function(e){var t,n,s,i,r;if(0===e._f.length)return d(e).invalidFormat=!0,void(e._d=new Date(NaN));for(i=0;ir&&(t=r),function(e,t,n,s,i){var r=Q(e,t,n,s,i),a=J(r.year,0,r.dayOfYear);return this.year(a.getUTCFullYear()),this.month(a.getUTCMonth()),this.date(a.getUTCDate()),this}.call(this,e,t,n,s,i))}function Le(e,t){t[Ct]=g(1e3*("0."+e))}function Ge(e){return e}function Ve(e,t,n,s){var i=ue(),r=l().set(s,t);return i[n](r,e)}function je(e,t,n){if(i(e)&&(t=e,e=void 0),e=e||"",null!=t)return Ve(e,t,n,"month");var s,r=[];for(s=0;s<12;s++)r[s]=Ve(e,s,n,"month");return r}function Ie(e,t,n,s){"boolean"==typeof e?(i(t)&&(n=t,t=void 0),t=t||""):(n=t=e,e=!1,i(t)&&(n=t,t=void 0),t=t||"");var r=ue(),a=e?r._week.dow:0;if(null!=n)return Ve(t,(n+a)%7,s,"day");var o,u=[];for(o=0;o<7;o++)u[o]=Ve(t,(o+a)%7,s,"day");return u}function Ee(e,t,n,s){var i=Te(t,n);return e._milliseconds+=s*i._milliseconds,e._days+=s*i._days,e._months+=s*i._months,e._bubble()}function Ae(e){return e<0?Math.floor(e):Math.ceil(e)}function ze(e){return 4800*e/146097}function Ze(e){return 146097*e/4800}function $e(e){return function(){return this.as(e)}}function qe(e){return function(){return this.isValid()?this._data[e]:NaN}}function Je(e){return(e>0)-(e<0)||+e}function Be(){if(!this.isValid())return this.localeData().invalidDate();var e,t,n=En(this._milliseconds)/1e3,s=En(this._days),i=En(this._months);t=y((e=y(n/60))/60),n%=60,e%=60;var r=y(i/12),a=i%=12,o=s,u=t,l=e,d=n?n.toFixed(3).replace(/\.?0+$/,""):"",h=this.asSeconds();if(!h)return"P0D";var c=h<0?"-":"",f=Je(this._months)!==Je(h)?"-":"",m=Je(this._days)!==Je(h)?"-":"",_=Je(this._milliseconds)!==Je(h)?"-":"";return c+"P"+(r?f+r+"Y":"")+(a?f+a+"M":"")+(o?m+o+"D":"")+(u||l||d?"T":"")+(u?_+u+"H":"")+(l?_+l+"M":"")+(d?_+d+"S":"")}var Qe,Xe;Xe=Array.prototype.some?Array.prototype.some:function(e){for(var t=Object(this),n=t.length>>>0,s=0;s68?1900:2e3)};var Nt,Ht=I("FullYear",!0);Nt=Array.prototype.indexOf?Array.prototype.indexOf:function(e){var t;for(t=0;tthis?this:e:c()}),hn=["year","quarter","month","week","day","hour","minute","second","millisecond"];Se("Z",":"),Se("ZZ",""),F("Z",St),F("ZZ",St),H(["Z","ZZ"],function(e,t,n){n._useUTC=!0,n._tzm=De(St,e)});var cn=/([\+\-]|\d\d)/gi;e.updateOffset=function(){};var fn=/^(\-|\+)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)(\.\d*)?)?$/,mn=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;Te.fn=ve.prototype,Te.invalid=function(){return Te(NaN)};var _n=We(1,"add"),yn=We(-1,"subtract");e.defaultFormat="YYYY-MM-DDTHH:mm:ssZ",e.defaultFormatUtc="YYYY-MM-DDTHH:mm:ss[Z]";var gn=v("moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.",function(e){return void 0===e?this.localeData():this.locale(e)});P(0,["gg",2],0,function(){return this.weekYear()%100}),P(0,["GG",2],0,function(){return this.isoWeekYear()%100}),Ne("gggg","weekYear"),Ne("ggggg","weekYear"),Ne("GGGG","isoWeekYear"),Ne("GGGGG","isoWeekYear"),Y("weekYear","gg"),Y("isoWeekYear","GG"),T("weekYear",1),T("isoWeekYear",1),F("G",Mt),F("g",Mt),F("GG",mt,dt),F("gg",mt,dt),F("GGGG",pt,ct),F("gggg",pt,ct),F("GGGGG",wt,ft),F("ggggg",wt,ft),L(["gggg","ggggg","GGGG","GGGGG"],function(e,t,n,s){t[s.substr(0,2)]=g(e)}),L(["gg","GG"],function(t,n,s,i){n[i]=e.parseTwoDigitYear(t)}),P("Q",0,"Qo","quarter"),Y("quarter","Q"),T("quarter",7),F("Q",lt),H("Q",function(e,t){t[Tt]=3*(g(e)-1)}),P("D",["DD",2],"Do","date"),Y("date","D"),T("date",9),F("D",mt),F("DD",mt,dt),F("Do",function(e,t){return e?t._dayOfMonthOrdinalParse||t._ordinalParse:t._dayOfMonthOrdinalParseLenient}),H(["D","DD"],bt),H("Do",function(e,t){t[bt]=g(e.match(mt)[0])});var pn=I("Date",!0);P("DDD",["DDDD",3],"DDDo","dayOfYear"),Y("dayOfYear","DDD"),T("dayOfYear",4),F("DDD",gt),F("DDDD",ht),H(["DDD","DDDD"],function(e,t,n){n._dayOfYear=g(e)}),P("m",["mm",2],0,"minute"),Y("minute","m"),T("minute",14),F("m",mt),F("mm",mt,dt),H(["m","mm"],Wt);var wn=I("Minutes",!1);P("s",["ss",2],0,"second"),Y("second","s"),T("second",15),F("s",mt),F("ss",mt,dt),H(["s","ss"],Rt);var vn=I("Seconds",!1);P("S",0,0,function(){return~~(this.millisecond()/100)}),P(0,["SS",2],0,function(){return~~(this.millisecond()/10)}),P(0,["SSS",3],0,"millisecond"),P(0,["SSSS",4],0,function(){return 10*this.millisecond()}),P(0,["SSSSS",5],0,function(){return 100*this.millisecond()}),P(0,["SSSSSS",6],0,function(){return 1e3*this.millisecond()}),P(0,["SSSSSSS",7],0,function(){return 1e4*this.millisecond()}),P(0,["SSSSSSSS",8],0,function(){return 1e5*this.millisecond()}),P(0,["SSSSSSSSS",9],0,function(){return 1e6*this.millisecond()}),Y("millisecond","ms"),T("millisecond",16),F("S",gt,lt),F("SS",gt,dt),F("SSS",gt,ht);var Mn;for(Mn="SSSS";Mn.length<=9;Mn+="S")F(Mn,vt);for(Mn="S";Mn.length<=9;Mn+="S")H(Mn,Le);var kn=I("Milliseconds",!1);P("z",0,0,"zoneAbbr"),P("zz",0,0,"zoneName");var Sn=m.prototype;Sn.add=_n,Sn.calendar=function(t,n){var s=t||pe(),i=Ye(s,this).startOf("day"),r=e.calendarFormat(this,i)||"sameElse",a=n&&(k(n[r])?n[r].call(this,s):n[r]);return this.format(a||this.localeData().calendar(r,this,pe(s)))},Sn.clone=function(){return new m(this)},Sn.diff=function(e,t,n){var s,i,r;if(!this.isValid())return NaN;if(!(s=Ye(e,this)).isValid())return NaN;switch(i=6e4*(s.utcOffset()-this.utcOffset()),t=O(t)){case"year":r=Ce(this,s)/12;break;case"month":r=Ce(this,s);break;case"quarter":r=Ce(this,s)/3;break;case"second":r=(this-s)/1e3;break;case"minute":r=(this-s)/6e4;break;case"hour":r=(this-s)/36e5;break;case"day":r=(this-s-i)/864e5;break;case"week":r=(this-s-i)/6048e5;break;default:r=this-s}return n?r:y(r)},Sn.endOf=function(e){return void 0===(e=O(e))||"millisecond"===e?this:("date"===e&&(e="day"),this.startOf(e).add(1,"isoWeek"===e?"week":e).subtract(1,"ms"))},Sn.format=function(t){t||(t=this.isUtc()?e.defaultFormatUtc:e.defaultFormat);var n=R(this,t);return this.localeData().postformat(n)},Sn.from=function(e,t){return this.isValid()&&(_(e)&&e.isValid()||pe(e).isValid())?Te({to:this,from:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()},Sn.fromNow=function(e){return this.from(pe(),e)},Sn.to=function(e,t){return this.isValid()&&(_(e)&&e.isValid()||pe(e).isValid())?Te({from:this,to:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()},Sn.toNow=function(e){return this.to(pe(),e)},Sn.get=function(e){return e=O(e),k(this[e])?this[e]():this},Sn.invalidAt=function(){return d(this).overflow},Sn.isAfter=function(e,t){var n=_(e)?e:pe(e);return!(!this.isValid()||!n.isValid())&&("millisecond"===(t=O(s(t)?"millisecond":t))?this.valueOf()>n.valueOf():n.valueOf()9999?R(e,"YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]"):k(Date.prototype.toISOString)?this.toDate().toISOString():R(e,"YYYY-MM-DD[T]HH:mm:ss.SSS[Z]")},Sn.inspect=function(){if(!this.isValid())return"moment.invalid(/* "+this._i+" */)";var e="moment",t="";this.isLocal()||(e=0===this.utcOffset()?"moment.utc":"moment.parseZone",t="Z");var n="["+e+'("]',s=0<=this.year()&&this.year()<=9999?"YYYY":"YYYYYY",i=t+'[")]';return this.format(n+s+"-MM-DD[T]HH:mm:ss.SSS"+i)},Sn.toJSON=function(){return this.isValid()?this.toISOString():null},Sn.toString=function(){return this.clone().locale("en").format("ddd MMM DD YYYY HH:mm:ss [GMT]ZZ")},Sn.unix=function(){return Math.floor(this.valueOf()/1e3)},Sn.valueOf=function(){return this._d.valueOf()-6e4*(this._offset||0)},Sn.creationData=function(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}},Sn.year=Ht,Sn.isLeapYear=function(){return j(this.year())},Sn.weekYear=function(e){return He.call(this,e,this.week(),this.weekday(),this.localeData()._week.dow,this.localeData()._week.doy)},Sn.isoWeekYear=function(e){return He.call(this,e,this.isoWeek(),this.isoWeekday(),1,4)},Sn.quarter=Sn.quarters=function(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)},Sn.month=$,Sn.daysInMonth=function(){return z(this.year(),this.month())},Sn.week=Sn.weeks=function(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),"d")},Sn.isoWeek=Sn.isoWeeks=function(e){var t=X(this,1,4).week;return null==e?t:this.add(7*(e-t),"d")},Sn.weeksInYear=function(){var e=this.localeData()._week;return K(this.year(),e.dow,e.doy)},Sn.isoWeeksInYear=function(){return K(this.year(),1,4)},Sn.date=pn,Sn.day=Sn.days=function(e){if(!this.isValid())return null!=e?this:NaN;var t=this._isUTC?this._d.getUTCDay():this._d.getDay();return null!=e?(e=function(e,t){return"string"!=typeof e?e:isNaN(e)?"number"==typeof(e=t.weekdaysParse(e))?e:null:parseInt(e,10)}(e,this.localeData()),this.add(e-t,"d")):t},Sn.weekday=function(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,"d")},Sn.isoWeekday=function(e){if(!this.isValid())return null!=e?this:NaN;if(null!=e){var t=function(e,t){return"string"==typeof e?t.weekdaysParse(e)%7||7:isNaN(e)?null:e}(e,this.localeData());return this.day(this.day()%7?t:t-7)}return this.day()||7},Sn.dayOfYear=function(e){var t=Math.round((this.clone().startOf("day")-this.clone().startOf("year"))/864e5)+1;return null==e?t:this.add(e-t,"d")},Sn.hour=Sn.hours=Bt,Sn.minute=Sn.minutes=wn,Sn.second=Sn.seconds=vn,Sn.millisecond=Sn.milliseconds=kn,Sn.utcOffset=function(t,n,s){var i,r=this._offset||0;if(!this.isValid())return null!=t?this:NaN;if(null!=t){if("string"==typeof t){if(null===(t=De(St,t)))return this}else Math.abs(t)<16&&!s&&(t*=60);return!this._isUTC&&n&&(i=Oe(this)),this._offset=t,this._isUTC=!0,null!=i&&this.add(i,"m"),r!==t&&(!n||this._changeInProgress?Re(this,Te(t-r,"m"),1,!1):this._changeInProgress||(this._changeInProgress=!0,e.updateOffset(this,!0),this._changeInProgress=null)),this}return this._isUTC?r:Oe(this)},Sn.utc=function(e){return this.utcOffset(0,e)},Sn.local=function(e){return this._isUTC&&(this.utcOffset(0,e),this._isUTC=!1,e&&this.subtract(Oe(this),"m")),this},Sn.parseZone=function(){if(null!=this._tzm)this.utcOffset(this._tzm,!1,!0);else if("string"==typeof this._i){var e=De(kt,this._i);null!=e?this.utcOffset(e):this.utcOffset(0,!0)}return this},Sn.hasAlignedHourOffset=function(e){return!!this.isValid()&&(e=e?pe(e).utcOffset():0,(this.utcOffset()-e)%60==0)},Sn.isDST=function(){return this.utcOffset()>this.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()},Sn.isLocal=function(){return!!this.isValid()&&!this._isUTC},Sn.isUtcOffset=function(){return!!this.isValid()&&this._isUTC},Sn.isUtc=xe,Sn.isUTC=xe,Sn.zoneAbbr=function(){return this._isUTC?"UTC":""},Sn.zoneName=function(){return this._isUTC?"Coordinated Universal Time":""},Sn.dates=v("dates accessor is deprecated. Use date instead.",pn),Sn.months=v("months accessor is deprecated. Use month instead",$),Sn.years=v("years accessor is deprecated. Use year instead",Ht),Sn.zone=v("moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/",function(e,t){return null!=e?("string"!=typeof e&&(e=-e),this.utcOffset(e,t),this):-this.utcOffset()}),Sn.isDSTShifted=v("isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information",function(){if(!s(this._isDSTShifted))return this._isDSTShifted;var e={};if(f(e,this),(e=ye(e))._a){var t=e._isUTC?l(e._a):pe(e._a);this._isDSTShifted=this.isValid()&&p(e._a,t.toArray())>0}else this._isDSTShifted=!1;return this._isDSTShifted});var Dn=D.prototype;Dn.calendar=function(e,t,n){var s=this._calendar[e]||this._calendar.sameElse;return k(s)?s.call(t,n):s},Dn.longDateFormat=function(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.replace(/MMMM|MM|DD|dddd/g,function(e){return e.slice(1)}),this._longDateFormat[e])},Dn.invalidDate=function(){return this._invalidDate},Dn.ordinal=function(e){return this._ordinal.replace("%d",e)},Dn.preparse=Ge,Dn.postformat=Ge,Dn.relativeTime=function(e,t,n,s){var i=this._relativeTime[n];return k(i)?i(e,t,n,s):i.replace(/%d/i,e)},Dn.pastFuture=function(e,t){var n=this._relativeTime[e>0?"future":"past"];return k(n)?n(t):n.replace(/%s/i,t)},Dn.set=function(e){var t,n;for(n in e)k(t=e[n])?this[n]=t:this["_"+n]=t;this._config=e,this._dayOfMonthOrdinalParseLenient=new RegExp((this._dayOfMonthOrdinalParse.source||this._ordinalParse.source)+"|"+/\d{1,2}/.source)},Dn.months=function(e,n){return e?t(this._months)?this._months[e.month()]:this._months[(this._months.isFormat||Lt).test(n)?"format":"standalone"][e.month()]:t(this._months)?this._months:this._months.standalone},Dn.monthsShort=function(e,n){return e?t(this._monthsShort)?this._monthsShort[e.month()]:this._monthsShort[Lt.test(n)?"format":"standalone"][e.month()]:t(this._monthsShort)?this._monthsShort:this._monthsShort.standalone},Dn.monthsParse=function(e,t,n){var s,i,r;if(this._monthsParseExact)return function(e,t,n){var s,i,r,a=e.toLocaleLowerCase();if(!this._monthsParse)for(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[],s=0;s<12;++s)r=l([2e3,s]),this._shortMonthsParse[s]=this.monthsShort(r,"").toLocaleLowerCase(),this._longMonthsParse[s]=this.months(r,"").toLocaleLowerCase();return n?"MMM"===t?-1!==(i=Nt.call(this._shortMonthsParse,a))?i:null:-1!==(i=Nt.call(this._longMonthsParse,a))?i:null:"MMM"===t?-1!==(i=Nt.call(this._shortMonthsParse,a))?i:-1!==(i=Nt.call(this._longMonthsParse,a))?i:null:-1!==(i=Nt.call(this._longMonthsParse,a))?i:-1!==(i=Nt.call(this._shortMonthsParse,a))?i:null}.call(this,e,t,n);for(this._monthsParse||(this._monthsParse=[],this._longMonthsParse=[],this._shortMonthsParse=[]),s=0;s<12;s++){if(i=l([2e3,s]),n&&!this._longMonthsParse[s]&&(this._longMonthsParse[s]=new RegExp("^"+this.months(i,"").replace(".","")+"$","i"),this._shortMonthsParse[s]=new RegExp("^"+this.monthsShort(i,"").replace(".","")+"$","i")),n||this._monthsParse[s]||(r="^"+this.months(i,"")+"|^"+this.monthsShort(i,""),this._monthsParse[s]=new RegExp(r.replace(".",""),"i")),n&&"MMMM"===t&&this._longMonthsParse[s].test(e))return s;if(n&&"MMM"===t&&this._shortMonthsParse[s].test(e))return s;if(!n&&this._monthsParse[s].test(e))return s}},Dn.monthsRegex=function(e){return this._monthsParseExact?(o(this,"_monthsRegex")||q.call(this),e?this._monthsStrictRegex:this._monthsRegex):(o(this,"_monthsRegex")||(this._monthsRegex=It),this._monthsStrictRegex&&e?this._monthsStrictRegex:this._monthsRegex)},Dn.monthsShortRegex=function(e){return this._monthsParseExact?(o(this,"_monthsRegex")||q.call(this),e?this._monthsShortStrictRegex:this._monthsShortRegex):(o(this,"_monthsShortRegex")||(this._monthsShortRegex=jt),this._monthsShortStrictRegex&&e?this._monthsShortStrictRegex:this._monthsShortRegex)},Dn.week=function(e){return X(e,this._week.dow,this._week.doy).week},Dn.firstDayOfYear=function(){return this._week.doy},Dn.firstDayOfWeek=function(){return this._week.dow},Dn.weekdays=function(e,n){return e?t(this._weekdays)?this._weekdays[e.day()]:this._weekdays[this._weekdays.isFormat.test(n)?"format":"standalone"][e.day()]:t(this._weekdays)?this._weekdays:this._weekdays.standalone},Dn.weekdaysMin=function(e){return e?this._weekdaysMin[e.day()]:this._weekdaysMin},Dn.weekdaysShort=function(e){return e?this._weekdaysShort[e.day()]:this._weekdaysShort},Dn.weekdaysParse=function(e,t,n){var s,i,r;if(this._weekdaysParseExact)return function(e,t,n){var s,i,r,a=e.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],s=0;s<7;++s)r=l([2e3,1]).day(s),this._minWeekdaysParse[s]=this.weekdaysMin(r,"").toLocaleLowerCase(),this._shortWeekdaysParse[s]=this.weekdaysShort(r,"").toLocaleLowerCase(),this._weekdaysParse[s]=this.weekdays(r,"").toLocaleLowerCase();return n?"dddd"===t?-1!==(i=Nt.call(this._weekdaysParse,a))?i:null:"ddd"===t?-1!==(i=Nt.call(this._shortWeekdaysParse,a))?i:null:-1!==(i=Nt.call(this._minWeekdaysParse,a))?i:null:"dddd"===t?-1!==(i=Nt.call(this._weekdaysParse,a))?i:-1!==(i=Nt.call(this._shortWeekdaysParse,a))?i:-1!==(i=Nt.call(this._minWeekdaysParse,a))?i:null:"ddd"===t?-1!==(i=Nt.call(this._shortWeekdaysParse,a))?i:-1!==(i=Nt.call(this._weekdaysParse,a))?i:-1!==(i=Nt.call(this._minWeekdaysParse,a))?i:null:-1!==(i=Nt.call(this._minWeekdaysParse,a))?i:-1!==(i=Nt.call(this._weekdaysParse,a))?i:-1!==(i=Nt.call(this._shortWeekdaysParse,a))?i:null}.call(this,e,t,n);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),s=0;s<7;s++){if(i=l([2e3,1]).day(s),n&&!this._fullWeekdaysParse[s]&&(this._fullWeekdaysParse[s]=new RegExp("^"+this.weekdays(i,"").replace(".",".?")+"$","i"),this._shortWeekdaysParse[s]=new RegExp("^"+this.weekdaysShort(i,"").replace(".",".?")+"$","i"),this._minWeekdaysParse[s]=new RegExp("^"+this.weekdaysMin(i,"").replace(".",".?")+"$","i")),this._weekdaysParse[s]||(r="^"+this.weekdays(i,"")+"|^"+this.weekdaysShort(i,"")+"|^"+this.weekdaysMin(i,""),this._weekdaysParse[s]=new RegExp(r.replace(".",""),"i")),n&&"dddd"===t&&this._fullWeekdaysParse[s].test(e))return s;if(n&&"ddd"===t&&this._shortWeekdaysParse[s].test(e))return s;if(n&&"dd"===t&&this._minWeekdaysParse[s].test(e))return s;if(!n&&this._weekdaysParse[s].test(e))return s}},Dn.weekdaysRegex=function(e){return this._weekdaysParseExact?(o(this,"_weekdaysRegex")||ee.call(this),e?this._weekdaysStrictRegex:this._weekdaysRegex):(o(this,"_weekdaysRegex")||(this._weekdaysRegex=Zt),this._weekdaysStrictRegex&&e?this._weekdaysStrictRegex:this._weekdaysRegex)},Dn.weekdaysShortRegex=function(e){return this._weekdaysParseExact?(o(this,"_weekdaysRegex")||ee.call(this),e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(o(this,"_weekdaysShortRegex")||(this._weekdaysShortRegex=$t),this._weekdaysShortStrictRegex&&e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)},Dn.weekdaysMinRegex=function(e){return this._weekdaysParseExact?(o(this,"_weekdaysRegex")||ee.call(this),e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(o(this,"_weekdaysMinRegex")||(this._weekdaysMinRegex=qt),this._weekdaysMinStrictRegex&&e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)},Dn.isPM=function(e){return"p"===(e+"").toLowerCase().charAt(0)},Dn.meridiem=function(e,t,n){return e>11?n?"pm":"PM":n?"am":"AM"},ae("en",{dayOfMonthOrdinalParse:/\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===g(e%100/10)?"th":1===t?"st":2===t?"nd":3===t?"rd":"th")}}),e.lang=v("moment.lang is deprecated. Use moment.locale instead.",ae),e.langData=v("moment.langData is deprecated. Use moment.localeData instead.",ue);var Yn=Math.abs,On=$e("ms"),xn=$e("s"),Tn=$e("m"),bn=$e("h"),Pn=$e("d"),Wn=$e("w"),Rn=$e("M"),Cn=$e("y"),Fn=qe("milliseconds"),Un=qe("seconds"),Nn=qe("minutes"),Hn=qe("hours"),Ln=qe("days"),Gn=qe("months"),Vn=qe("years"),jn=Math.round,In={ss:44,s:45,m:45,h:22,d:26,M:11},En=Math.abs,An=ve.prototype;return An.isValid=function(){return this._isValid},An.abs=function(){var e=this._data;return this._milliseconds=Yn(this._milliseconds),this._days=Yn(this._days),this._months=Yn(this._months),e.milliseconds=Yn(e.milliseconds),e.seconds=Yn(e.seconds),e.minutes=Yn(e.minutes),e.hours=Yn(e.hours),e.months=Yn(e.months),e.years=Yn(e.years),this},An.add=function(e,t){return Ee(this,e,t,1)},An.subtract=function(e,t){return Ee(this,e,t,-1)},An.as=function(e){if(!this.isValid())return NaN;var t,n,s=this._milliseconds;if("month"===(e=O(e))||"year"===e)return t=this._days+s/864e5,n=this._months+ze(t),"month"===e?n:n/12;switch(t=this._days+Math.round(Ze(this._months)),e){case"week":return t/7+s/6048e5;case"day":return t+s/864e5;case"hour":return 24*t+s/36e5;case"minute":return 1440*t+s/6e4;case"second":return 86400*t+s/1e3;case"millisecond":return Math.floor(864e5*t)+s;default:throw new Error("Unknown unit "+e)}},An.asMilliseconds=On,An.asSeconds=xn,An.asMinutes=Tn,An.asHours=bn,An.asDays=Pn,An.asWeeks=Wn,An.asMonths=Rn,An.asYears=Cn,An.valueOf=function(){return this.isValid()?this._milliseconds+864e5*this._days+this._months%12*2592e6+31536e6*g(this._months/12):NaN},An._bubble=function(){var e,t,n,s,i,r=this._milliseconds,a=this._days,o=this._months,u=this._data;return r>=0&&a>=0&&o>=0||r<=0&&a<=0&&o<=0||(r+=864e5*Ae(Ze(o)+a),a=0,o=0),u.milliseconds=r%1e3,e=y(r/1e3),u.seconds=e%60,t=y(e/60),u.minutes=t%60,n=y(t/60),u.hours=n%24,a+=y(n/24),i=y(ze(a)),o+=i,a-=Ae(Ze(i)),s=y(o/12),o%=12,u.days=a,u.months=o,u.years=s,this},An.clone=function(){return Te(this)},An.get=function(e){return e=O(e),this.isValid()?this[e+"s"]():NaN},An.milliseconds=Fn,An.seconds=Un,An.minutes=Nn,An.hours=Hn,An.days=Ln,An.weeks=function(){return y(this.days()/7)},An.months=Gn,An.years=Vn,An.humanize=function(e){if(!this.isValid())return this.localeData().invalidDate();var t=this.localeData(),n=function(e,t,n){var s=Te(e).abs(),i=jn(s.as("s")),r=jn(s.as("m")),a=jn(s.as("h")),o=jn(s.as("d")),u=jn(s.as("M")),l=jn(s.as("y")),d=i<=In.ss&&["s",i]||i0,d[4]=n,function(e,t,n,s,i){return i.relativeTime(t||1,!!n,e,s)}.apply(null,d)}(this,!e,t);return e&&(n=t.pastFuture(+this,n)),t.postformat(n)},An.toISOString=Be,An.toString=Be,An.toJSON=Be,An.locale=Fe,An.localeData=Ue,An.toIsoString=v("toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)",Be),An.lang=gn,P("X",0,0,"unix"),P("x",0,0,"valueOf"),F("x",Mt),F("X",/[+-]?\d+(\.\d{1,3})?/),H("X",function(e,t,n){n._d=new Date(1e3*parseFloat(e,10))}),H("x",function(e,t,n){n._d=new Date(g(e))}),e.version="2.19.4",function(e){Qe=e}(pe),e.fn=Sn,e.min=function(){return we("isBefore",[].slice.call(arguments,0))},e.max=function(){return we("isAfter",[].slice.call(arguments,0))},e.now=function(){return Date.now?Date.now():+new Date},e.utc=l,e.unix=function(e){return pe(1e3*e)},e.months=function(e,t){return je(e,t,"months")},e.isDate=r,e.locale=ae,e.invalid=c,e.duration=Te,e.isMoment=_,e.weekdays=function(e,t,n){return Ie(e,t,n,"weekdays")},e.parseZone=function(){return pe.apply(null,arguments).parseZone()},e.localeData=ue,e.isDuration=Me,e.monthsShort=function(e,t){return je(e,t,"monthsShort")},e.weekdaysMin=function(e,t,n){return Ie(e,t,n,"weekdaysMin")},e.defineLocale=oe,e.updateLocale=function(e,t){if(null!=t){var n,s,i=Qt;null!=(s=re(e))&&(i=s._config),(n=new D(t=S(i,t))).parentLocale=Xt[e],Xt[e]=n,ae(e)}else null!=Xt[e]&&(null!=Xt[e].parentLocale?Xt[e]=Xt[e].parentLocale:null!=Xt[e]&&delete Xt[e]);return Xt[e]},e.locales=function(){return nt(Xt)},e.weekdaysShort=function(e,t,n){return Ie(e,t,n,"weekdaysShort")},e.normalizeUnits=O,e.relativeTimeRounding=function(e){return void 0===e?jn:"function"==typeof e&&(jn=e,!0)},e.relativeTimeThreshold=function(e,t){return void 0!==In[e]&&(void 0===t?In[e]:(In[e]=t,"s"===e&&(In.ss=t-1),!0))},e.calendarFormat=function(e,t){var n=e.diff(t,"days",!0);return n<-6?"sameElse":n<-1?"lastWeek":n<0?"lastDay":n<1?"sameDay":n<2?"nextDay":n<7?"nextWeek":"sameElse"},e.prototype=Sn,e}); -(function (factory) { - - if ( typeof define === 'function' && define.amd ) { - - // AMD. Register as an anonymous module. - define([], factory); - - } else if ( typeof exports === 'object' ) { - - // Node/CommonJS - module.exports = factory(); - - } else { - - // Browser globals - window.wNumb = factory(); - } - -}(function(){ - - 'use strict'; - -var FormatOptions = [ - 'decimals', - 'thousand', - 'mark', - 'prefix', - 'suffix', - 'encoder', - 'decoder', - 'negativeBefore', - 'negative', - 'edit', - 'undo' -]; - -// General - - // Reverse a string - function strReverse ( a ) { - return a.split('').reverse().join(''); - } - - // Check if a string starts with a specified prefix. - function strStartsWith ( input, match ) { - return input.substring(0, match.length) === match; - } - - // Check is a string ends in a specified suffix. - function strEndsWith ( input, match ) { - return input.slice(-1 * match.length) === match; - } - - // Throw an error if formatting options are incompatible. - function throwEqualError( F, a, b ) { - if ( (F[a] || F[b]) && (F[a] === F[b]) ) { - throw new Error(a); - } - } - - // Check if a number is finite and not NaN - function isValidNumber ( input ) { - return typeof input === 'number' && isFinite( input ); - } - - // Provide rounding-accurate toFixed method. - // Borrowed: http://stackoverflow.com/a/21323330/775265 - function toFixed ( value, exp ) { - value = value.toString().split('e'); - value = Math.round(+(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp))); - value = value.toString().split('e'); - return (+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp))).toFixed(exp); - } - - -// Formatting - - // Accept a number as input, output formatted string. - function formatTo ( decimals, thousand, mark, prefix, suffix, encoder, decoder, negativeBefore, negative, edit, undo, input ) { - - var originalInput = input, inputIsNegative, inputPieces, inputBase, inputDecimals = '', output = ''; - - // Apply user encoder to the input. - // Expected outcome: number. - if ( encoder ) { - input = encoder(input); - } - - // Stop if no valid number was provided, the number is infinite or NaN. - if ( !isValidNumber(input) ) { - return false; - } - - // Rounding away decimals might cause a value of -0 - // when using very small ranges. Remove those cases. - if ( decimals !== false && parseFloat(input.toFixed(decimals)) === 0 ) { - input = 0; - } - - // Formatting is done on absolute numbers, - // decorated by an optional negative symbol. - if ( input < 0 ) { - inputIsNegative = true; - input = Math.abs(input); - } - - // Reduce the number of decimals to the specified option. - if ( decimals !== false ) { - input = toFixed( input, decimals ); - } - - // Transform the number into a string, so it can be split. - input = input.toString(); - - // Break the number on the decimal separator. - if ( input.indexOf('.') !== -1 ) { - inputPieces = input.split('.'); - - inputBase = inputPieces[0]; - - if ( mark ) { - inputDecimals = mark + inputPieces[1]; - } - - } else { - - // If it isn't split, the entire number will do. - inputBase = input; - } - - // Group numbers in sets of three. - if ( thousand ) { - inputBase = strReverse(inputBase).match(/.{1,3}/g); - inputBase = strReverse(inputBase.join( strReverse( thousand ) )); - } - - // If the number is negative, prefix with negation symbol. - if ( inputIsNegative && negativeBefore ) { - output += negativeBefore; - } - - // Prefix the number - if ( prefix ) { - output += prefix; - } - - // Normal negative option comes after the prefix. Defaults to '-'. - if ( inputIsNegative && negative ) { - output += negative; - } - - // Append the actual number. - output += inputBase; - output += inputDecimals; - - // Apply the suffix. - if ( suffix ) { - output += suffix; - } - - // Run the output through a user-specified post-formatter. - if ( edit ) { - output = edit ( output, originalInput ); - } - - // All done. - return output; - } - - // Accept a sting as input, output decoded number. - function formatFrom ( decimals, thousand, mark, prefix, suffix, encoder, decoder, negativeBefore, negative, edit, undo, input ) { - - var originalInput = input, inputIsNegative, output = ''; - - // User defined pre-decoder. Result must be a non empty string. - if ( undo ) { - input = undo(input); - } - - // Test the input. Can't be empty. - if ( !input || typeof input !== 'string' ) { - return false; - } - - // If the string starts with the negativeBefore value: remove it. - // Remember is was there, the number is negative. - if ( negativeBefore && strStartsWith(input, negativeBefore) ) { - input = input.replace(negativeBefore, ''); - inputIsNegative = true; - } - - // Repeat the same procedure for the prefix. - if ( prefix && strStartsWith(input, prefix) ) { - input = input.replace(prefix, ''); - } - - // And again for negative. - if ( negative && strStartsWith(input, negative) ) { - input = input.replace(negative, ''); - inputIsNegative = true; - } - - // Remove the suffix. - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice - if ( suffix && strEndsWith(input, suffix) ) { - input = input.slice(0, -1 * suffix.length); - } - - // Remove the thousand grouping. - if ( thousand ) { - input = input.split(thousand).join(''); - } - - // Set the decimal separator back to period. - if ( mark ) { - input = input.replace(mark, '.'); - } - - // Prepend the negative symbol. - if ( inputIsNegative ) { - output += '-'; - } - - // Add the number - output += input; - - // Trim all non-numeric characters (allow '.' and '-'); - output = output.replace(/[^0-9\.\-.]/g, ''); - - // The value contains no parse-able number. - if ( output === '' ) { - return false; - } - - // Covert to number. - output = Number(output); - - // Run the user-specified post-decoder. - if ( decoder ) { - output = decoder(output); - } - - // Check is the output is valid, otherwise: return false. - if ( !isValidNumber(output) ) { - return false; - } - - return output; - } - - -// Framework - - // Validate formatting options - function validate ( inputOptions ) { - - var i, optionName, optionValue, - filteredOptions = {}; - - if ( inputOptions['suffix'] === undefined ) { - inputOptions['suffix'] = inputOptions['postfix']; - } - - for ( i = 0; i < FormatOptions.length; i+=1 ) { - - optionName = FormatOptions[i]; - optionValue = inputOptions[optionName]; - - if ( optionValue === undefined ) { - - // Only default if negativeBefore isn't set. - if ( optionName === 'negative' && !filteredOptions.negativeBefore ) { - filteredOptions[optionName] = '-'; - // Don't set a default for mark when 'thousand' is set. - } else if ( optionName === 'mark' && filteredOptions.thousand !== '.' ) { - filteredOptions[optionName] = '.'; - } else { - filteredOptions[optionName] = false; - } - - // Floating points in JS are stable up to 7 decimals. - } else if ( optionName === 'decimals' ) { - if ( optionValue >= 0 && optionValue < 8 ) { - filteredOptions[optionName] = optionValue; - } else { - throw new Error(optionName); - } - - // These options, when provided, must be functions. - } else if ( optionName === 'encoder' || optionName === 'decoder' || optionName === 'edit' || optionName === 'undo' ) { - if ( typeof optionValue === 'function' ) { - filteredOptions[optionName] = optionValue; - } else { - throw new Error(optionName); - } - - // Other options are strings. - } else { - - if ( typeof optionValue === 'string' ) { - filteredOptions[optionName] = optionValue; - } else { - throw new Error(optionName); - } - } - } - - // Some values can't be extracted from a - // string if certain combinations are present. - throwEqualError(filteredOptions, 'mark', 'thousand'); - throwEqualError(filteredOptions, 'prefix', 'negative'); - throwEqualError(filteredOptions, 'prefix', 'negativeBefore'); - - return filteredOptions; - } - - // Pass all options as function arguments - function passAll ( options, method, input ) { - var i, args = []; - - // Add all options in order of FormatOptions - for ( i = 0; i < FormatOptions.length; i+=1 ) { - args.push(options[FormatOptions[i]]); - } - - // Append the input, then call the method, presenting all - // options as arguments. - args.push(input); - return method.apply('', args); - } - - function wNumb ( options ) { - - if ( !(this instanceof wNumb) ) { - return new wNumb ( options ); - } - - if ( typeof options !== "object" ) { - return; - } - - options = validate(options); - - // Call 'formatTo' with proper arguments. - this.to = function ( input ) { - return passAll(options, formatTo, input); - }; - - // Call 'formatFrom' with proper arguments. - this.from = function ( input ) { - return passAll(options, formatFrom, input); - }; - } - - return wNumb; - -})); +(function (factory) { + + if ( typeof define === 'function' && define.amd ) { + + // AMD. Register as an anonymous module. + define([], factory); + + } else if ( typeof exports === 'object' ) { + + // Node/CommonJS + module.exports = factory(); + + } else { + + // Browser globals + window.wNumb = factory(); + } + +}(function(){ + + 'use strict'; + +var FormatOptions = [ + 'decimals', + 'thousand', + 'mark', + 'prefix', + 'suffix', + 'encoder', + 'decoder', + 'negativeBefore', + 'negative', + 'edit', + 'undo' +]; + +// General + + // Reverse a string + function strReverse ( a ) { + return a.split('').reverse().join(''); + } + + // Check if a string starts with a specified prefix. + function strStartsWith ( input, match ) { + return input.substring(0, match.length) === match; + } + + // Check is a string ends in a specified suffix. + function strEndsWith ( input, match ) { + return input.slice(-1 * match.length) === match; + } + + // Throw an error if formatting options are incompatible. + function throwEqualError( F, a, b ) { + if ( (F[a] || F[b]) && (F[a] === F[b]) ) { + throw new Error(a); + } + } + + // Check if a number is finite and not NaN + function isValidNumber ( input ) { + return typeof input === 'number' && isFinite( input ); + } + + // Provide rounding-accurate toFixed method. + // Borrowed: http://stackoverflow.com/a/21323330/775265 + function toFixed ( value, exp ) { + value = value.toString().split('e'); + value = Math.round(+(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp))); + value = value.toString().split('e'); + return (+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp))).toFixed(exp); + } + + +// Formatting + + // Accept a number as input, output formatted string. + function formatTo ( decimals, thousand, mark, prefix, suffix, encoder, decoder, negativeBefore, negative, edit, undo, input ) { + + var originalInput = input, inputIsNegative, inputPieces, inputBase, inputDecimals = '', output = ''; + + // Apply user encoder to the input. + // Expected outcome: number. + if ( encoder ) { + input = encoder(input); + } + + // Stop if no valid number was provided, the number is infinite or NaN. + if ( !isValidNumber(input) ) { + return false; + } + + // Rounding away decimals might cause a value of -0 + // when using very small ranges. Remove those cases. + if ( decimals !== false && parseFloat(input.toFixed(decimals)) === 0 ) { + input = 0; + } + + // Formatting is done on absolute numbers, + // decorated by an optional negative symbol. + if ( input < 0 ) { + inputIsNegative = true; + input = Math.abs(input); + } + + // Reduce the number of decimals to the specified option. + if ( decimals !== false ) { + input = toFixed( input, decimals ); + } + + // Transform the number into a string, so it can be split. + input = input.toString(); + + // Break the number on the decimal separator. + if ( input.indexOf('.') !== -1 ) { + inputPieces = input.split('.'); + + inputBase = inputPieces[0]; + + if ( mark ) { + inputDecimals = mark + inputPieces[1]; + } + + } else { + + // If it isn't split, the entire number will do. + inputBase = input; + } + + // Group numbers in sets of three. + if ( thousand ) { + inputBase = strReverse(inputBase).match(/.{1,3}/g); + inputBase = strReverse(inputBase.join( strReverse( thousand ) )); + } + + // If the number is negative, prefix with negation symbol. + if ( inputIsNegative && negativeBefore ) { + output += negativeBefore; + } + + // Prefix the number + if ( prefix ) { + output += prefix; + } + + // Normal negative option comes after the prefix. Defaults to '-'. + if ( inputIsNegative && negative ) { + output += negative; + } + + // Append the actual number. + output += inputBase; + output += inputDecimals; + + // Apply the suffix. + if ( suffix ) { + output += suffix; + } + + // Run the output through a user-specified post-formatter. + if ( edit ) { + output = edit ( output, originalInput ); + } + + // All done. + return output; + } + + // Accept a sting as input, output decoded number. + function formatFrom ( decimals, thousand, mark, prefix, suffix, encoder, decoder, negativeBefore, negative, edit, undo, input ) { + + var originalInput = input, inputIsNegative, output = ''; + + // User defined pre-decoder. Result must be a non empty string. + if ( undo ) { + input = undo(input); + } + + // Test the input. Can't be empty. + if ( !input || typeof input !== 'string' ) { + return false; + } + + // If the string starts with the negativeBefore value: remove it. + // Remember is was there, the number is negative. + if ( negativeBefore && strStartsWith(input, negativeBefore) ) { + input = input.replace(negativeBefore, ''); + inputIsNegative = true; + } + + // Repeat the same procedure for the prefix. + if ( prefix && strStartsWith(input, prefix) ) { + input = input.replace(prefix, ''); + } + + // And again for negative. + if ( negative && strStartsWith(input, negative) ) { + input = input.replace(negative, ''); + inputIsNegative = true; + } + + // Remove the suffix. + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice + if ( suffix && strEndsWith(input, suffix) ) { + input = input.slice(0, -1 * suffix.length); + } + + // Remove the thousand grouping. + if ( thousand ) { + input = input.split(thousand).join(''); + } + + // Set the decimal separator back to period. + if ( mark ) { + input = input.replace(mark, '.'); + } + + // Prepend the negative symbol. + if ( inputIsNegative ) { + output += '-'; + } + + // Add the number + output += input; + + // Trim all non-numeric characters (allow '.' and '-'); + output = output.replace(/[^0-9\.\-.]/g, ''); + + // The value contains no parse-able number. + if ( output === '' ) { + return false; + } + + // Covert to number. + output = Number(output); + + // Run the user-specified post-decoder. + if ( decoder ) { + output = decoder(output); + } + + // Check is the output is valid, otherwise: return false. + if ( !isValidNumber(output) ) { + return false; + } + + return output; + } + + +// Framework + + // Validate formatting options + function validate ( inputOptions ) { + + var i, optionName, optionValue, + filteredOptions = {}; + + if ( inputOptions['suffix'] === undefined ) { + inputOptions['suffix'] = inputOptions['postfix']; + } + + for ( i = 0; i < FormatOptions.length; i+=1 ) { + + optionName = FormatOptions[i]; + optionValue = inputOptions[optionName]; + + if ( optionValue === undefined ) { + + // Only default if negativeBefore isn't set. + if ( optionName === 'negative' && !filteredOptions.negativeBefore ) { + filteredOptions[optionName] = '-'; + // Don't set a default for mark when 'thousand' is set. + } else if ( optionName === 'mark' && filteredOptions.thousand !== '.' ) { + filteredOptions[optionName] = '.'; + } else { + filteredOptions[optionName] = false; + } + + // Floating points in JS are stable up to 7 decimals. + } else if ( optionName === 'decimals' ) { + if ( optionValue >= 0 && optionValue < 8 ) { + filteredOptions[optionName] = optionValue; + } else { + throw new Error(optionName); + } + + // These options, when provided, must be functions. + } else if ( optionName === 'encoder' || optionName === 'decoder' || optionName === 'edit' || optionName === 'undo' ) { + if ( typeof optionValue === 'function' ) { + filteredOptions[optionName] = optionValue; + } else { + throw new Error(optionName); + } + + // Other options are strings. + } else { + + if ( typeof optionValue === 'string' ) { + filteredOptions[optionName] = optionValue; + } else { + throw new Error(optionName); + } + } + } + + // Some values can't be extracted from a + // string if certain combinations are present. + throwEqualError(filteredOptions, 'mark', 'thousand'); + throwEqualError(filteredOptions, 'prefix', 'negative'); + throwEqualError(filteredOptions, 'prefix', 'negativeBefore'); + + return filteredOptions; + } + + // Pass all options as function arguments + function passAll ( options, method, input ) { + var i, args = []; + + // Add all options in order of FormatOptions + for ( i = 0; i < FormatOptions.length; i+=1 ) { + args.push(options[FormatOptions[i]]); + } + + // Append the input, then call the method, presenting all + // options as arguments. + args.push(input); + return method.apply('', args); + } + + function wNumb ( options ) { + + if ( !(this instanceof wNumb) ) { + return new wNumb ( options ); + } + + if ( typeof options !== "object" ) { + return; + } + + options = validate(options); + + // Call 'formatTo' with proper arguments. + this.to = function ( input ) { + return passAll(options, formatTo, input); + }; + + // Call 'formatFrom' with proper arguments. + this.from = function ( input ) { + return passAll(options, formatFrom, input); + }; + } + + return wNumb; + +})); (function ($) { 'use strict'; @@ -14266,3089 +14266,3089 @@ $.fn.repeater = function (fig) { !function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&module.exports?module.exports=function(t,r){return void 0===r&&(r="undefined"!=typeof window?require("jquery"):require("jquery")(t)),e(r),r}:e(jQuery)}(function(e){"use strict";function t(t){var r=t.data;t.isDefaultPrevented()||(t.preventDefault(),e(t.target).closest("form").ajaxSubmit(r))}function r(t){var r=t.target,a=e(r);if(!a.is("[type=submit],[type=image]")){var n=a.closest("[type=submit]");if(0===n.length)return;r=n[0]}var i=r.form;if(i.clk=r,"image"===r.type)if(void 0!==t.offsetX)i.clk_x=t.offsetX,i.clk_y=t.offsetY;else if("function"==typeof e.fn.offset){var o=a.offset();i.clk_x=t.pageX-o.left,i.clk_y=t.pageY-o.top}else i.clk_x=t.pageX-r.offsetLeft,i.clk_y=t.pageY-r.offsetTop;setTimeout(function(){i.clk=i.clk_x=i.clk_y=null},100)}function a(){if(e.fn.ajaxSubmit.debug){var t="[jquery.form] "+Array.prototype.join.call(arguments,"");window.console&&window.console.log?window.console.log(t):window.opera&&window.opera.postError&&window.opera.postError(t)}}var n=/\r?\n/g,i={};i.fileapi=void 0!==e('').get(0).files,i.formdata=void 0!==window.FormData;var o=!!e.fn.prop;e.fn.attr2=function(){if(!o)return this.attr.apply(this,arguments);var e=this.prop.apply(this,arguments);return e&&e.jquery||"string"==typeof e?e:this.attr.apply(this,arguments)},e.fn.ajaxSubmit=function(t,r,n,s){function u(r){var a,n,i=e.param(r,t.traditional).split("&"),o=i.length,s=[];for(a=0;a',k).val(f.extraData[c].value).appendTo(w)[0]):u.push(e('',k).val(f.extraData[c]).appendTo(w)[0]));f.iframeTarget||h.appendTo(D),v.attachEvent?v.attachEvent("onload",s):v.addEventListener("load",s,!1),setTimeout(t,15);try{w.submit()}catch(e){document.createElement("form").submit.apply(w)}}finally{w.setAttribute("action",i),w.setAttribute("enctype",o),r?w.setAttribute("target",r):p.removeAttr("target"),e(u).remove()}}function s(t){if(!x.aborted&&!X){if((O=n(v))||(a("cannot access response document"),t=L),t===A&&x)return x.abort("timeout"),void S.reject(x,"timeout");if(t===L&&x)return x.abort("server abort"),void S.reject(x,"error","server abort");if(O&&O.location.href!==f.iframeSrc||T){v.detachEvent?v.detachEvent("onload",s):v.removeEventListener("load",s,!1);var r,i="success";try{if(T)throw"timeout";var o="xml"===f.dataType||O.XMLDocument||e.isXMLDoc(O);if(a("isXml="+o),!o&&window.opera&&(null===O.body||!O.body.innerHTML)&&--C)return a("requeing onLoad callback, DOM not available"),void setTimeout(s,250);var u=O.body?O.body:O.documentElement;x.responseText=u?u.innerHTML:null,x.responseXML=O.XMLDocument?O.XMLDocument:O,o&&(f.dataType="xml"),x.getResponseHeader=function(e){return{"content-type":f.dataType}[e.toLowerCase()]},u&&(x.status=Number(u.getAttribute("status"))||x.status,x.statusText=u.getAttribute("statusText")||x.statusText);var c=(f.dataType||"").toLowerCase(),l=/(json|script|text)/.test(c);if(l||f.textarea){var p=O.getElementsByTagName("textarea")[0];if(p)x.responseText=p.value,x.status=Number(p.getAttribute("status"))||x.status,x.statusText=p.getAttribute("statusText")||x.statusText;else if(l){var m=O.getElementsByTagName("pre")[0],g=O.getElementsByTagName("body")[0];m?x.responseText=m.textContent?m.textContent:m.innerText:g&&(x.responseText=g.textContent?g.textContent:g.innerText)}}else"xml"===c&&!x.responseXML&&x.responseText&&(x.responseXML=q(x.responseText));try{M=N(x,c,f)}catch(e){i="parsererror",x.error=r=e||i}}catch(e){a("error caught: ",e),i="error",x.error=r=e||i}x.aborted&&(a("upload aborted"),i=null),x.status&&(i=x.status>=200&&x.status<300||304===x.status?"success":"error"),"success"===i?(f.success&&f.success.call(f.context,M,"success",x),S.resolve(x.responseText,"success",x),d&&e.event.trigger("ajaxSuccess",[x,f])):i&&(void 0===r&&(r=x.statusText),f.error&&f.error.call(f.context,x,i,r),S.reject(x,"error",r),d&&e.event.trigger("ajaxError",[x,f,r])),d&&e.event.trigger("ajaxComplete",[x,f]),d&&!--e.active&&e.event.trigger("ajaxStop"),f.complete&&f.complete.call(f.context,x,i),X=!0,f.timeout&&clearTimeout(j),setTimeout(function(){f.iframeTarget?h.attr("src",f.iframeSrc):h.remove(),x.responseXML=null},100)}}}var u,c,f,d,m,h,v,x,y,b,T,j,w=p[0],S=e.Deferred();if(S.abort=function(e){x.abort(e)},r)for(c=0;c',k)).css({position:"absolute",top:"-1000px",left:"-1000px"}),v=h[0],x={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(t){var r="timeout"===t?"timeout":"aborted";a("aborting upload... "+r),this.aborted=1;try{v.contentWindow.document.execCommand&&v.contentWindow.document.execCommand("Stop")}catch(e){}h.attr("src",f.iframeSrc),x.error=r,f.error&&f.error.call(f.context,x,r,t),d&&e.event.trigger("ajaxError",[x,f,r]),f.complete&&f.complete.call(f.context,x,r)}},(d=f.global)&&0==e.active++&&e.event.trigger("ajaxStart"),d&&e.event.trigger("ajaxSend",[x,f]),f.beforeSend&&!1===f.beforeSend.call(f.context,x,f))return f.global&&e.active--,S.reject(),S;if(x.aborted)return S.reject(),S;(y=w.clk)&&(b=y.name)&&!y.disabled&&(f.extraData=f.extraData||{},f.extraData[b]=y.value,"image"===y.type&&(f.extraData[b+".x"]=w.clk_x,f.extraData[b+".y"]=w.clk_y));var A=1,L=2,F=e("meta[name=csrf-token]").attr("content"),E=e("meta[name=csrf-param]").attr("content");E&&F&&(f.extraData=f.extraData||{},f.extraData[E]=F),f.forceSync?i():setTimeout(i,10);var M,O,X,C=50,q=e.parseXML||function(e,t){return window.ActiveXObject?((t=new ActiveXObject("Microsoft.XMLDOM")).async="false",t.loadXML(e)):t=(new DOMParser).parseFromString(e,"text/xml"),t&&t.documentElement&&"parsererror"!==t.documentElement.nodeName?t:null},_=e.parseJSON||function(e){return window.eval("("+e+")")},N=function(t,r,a){var n=t.getResponseHeader("content-type")||"",i=("xml"===r||!r)&&n.indexOf("xml")>=0,o=i?t.responseXML:t.responseText;return i&&"parsererror"===o.documentElement.nodeName&&e.error&&e.error("parsererror"),a&&a.dataFilter&&(o=a.dataFilter(o,r)),"string"==typeof o&&(("json"===r||!r)&&n.indexOf("json")>=0?o=_(o):("script"===r||!r)&&n.indexOf("javascript")>=0&&e.globalEval(o)),o};return S}if(!this.length)return a("ajaxSubmit: skipping submit process - no element selected"),this;var l,f,d,p=this;"function"==typeof t?t={success:t}:"string"==typeof t||!1===t&&arguments.length>0?(t={url:t,data:r,dataType:n},"function"==typeof s&&(t.success=s)):void 0===t&&(t={}),l=t.method||t.type||this.attr2("method"),(d=(d="string"==typeof(f=t.url||this.attr2("action"))?e.trim(f):"")||window.location.href||"")&&(d=(d.match(/^([^#]+)/)||[])[1]),t=e.extend(!0,{url:d,success:e.ajaxSettings.success,type:l||e.ajaxSettings.type,iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},t);var m={};if(this.trigger("form-pre-serialize",[this,t,m]),m.veto)return a("ajaxSubmit: submit vetoed via form-pre-serialize trigger"),this;if(t.beforeSerialize&&!1===t.beforeSerialize(this,t))return a("ajaxSubmit: submit aborted via beforeSerialize callback"),this;var h=t.traditional;void 0===h&&(h=e.ajaxSettings.traditional);var v,g=[],x=this.formToArray(t.semantic,g,t.filtering);if(t.data){var y=e.isFunction(t.data)?t.data(x):t.data;t.extraData=y,v=e.param(y,h)}if(t.beforeSubmit&&!1===t.beforeSubmit(x,this,t))return a("ajaxSubmit: submit aborted via beforeSubmit callback"),this;if(this.trigger("form-submit-validate",[x,this,t,m]),m.veto)return a("ajaxSubmit: submit vetoed via form-submit-validate trigger"),this;var b=e.param(x,h);v&&(b=b?b+"&"+v:v),"GET"===t.type.toUpperCase()?(t.url+=(t.url.indexOf("?")>=0?"&":"?")+b,t.data=null):t.data=b;var T=[];if(t.resetForm&&T.push(function(){p.resetForm()}),t.clearForm&&T.push(function(){p.clearForm(t.includeHidden)}),!t.dataType&&t.target){var j=t.success||function(){};T.push(function(r,a,n){var i=arguments,o=t.replaceTarget?"replaceWith":"html";e(t.target)[o](r).each(function(){j.apply(this,i)})})}else t.success&&(e.isArray(t.success)?e.merge(T,t.success):T.push(t.success));if(t.success=function(e,r,a){for(var n=t.context||this,i=0,o=T.length;i0,D="multipart/form-data",A=p.attr("enctype")===D||p.attr("encoding")===D,L=i.fileapi&&i.formdata;a("fileAPI :"+L);var F,E=(k||A)&&!L;!1!==t.iframe&&(t.iframe||E)?t.closeKeepAlive?e.get(t.closeKeepAlive,function(){F=c(x)}):F=c(x):F=(k||A)&&L?function(r){for(var a=new FormData,n=0;n0)&&(n={url:n,data:i,dataType:o},"function"==typeof s&&(n.success=s)),n=n||{},n.delegation=n.delegation&&e.isFunction(e.fn.on),!n.delegation&&0===this.length){var u={s:this.selector,c:this.context};return!e.isReady&&u.s?(a("DOM not ready, queuing ajaxForm"),e(function(){e(u.s,u.c).ajaxForm(n)}),this):(a("terminating; zero elements found by selector"+(e.isReady?"":" (DOM not ready)")),this)}return n.delegation?(e(document).off("submit.form-plugin",this.selector,t).off("click.form-plugin",this.selector,r).on("submit.form-plugin",this.selector,n,t).on("click.form-plugin",this.selector,n,r),this):this.ajaxFormUnbind().on("submit.form-plugin",n,t).on("click.form-plugin",n,r)},e.fn.ajaxFormUnbind=function(){return this.off("submit.form-plugin click.form-plugin")},e.fn.formToArray=function(t,r,a){var n=[];if(0===this.length)return n;var o,s=this[0],u=this.attr("id"),c=t||void 0===s.elements?s.getElementsByTagName("*"):s.elements;if(c&&(c=e.makeArray(c)),u&&(t||/(Edge|Trident)\//.test(navigator.userAgent))&&(o=e(':input[form="'+u+'"]').get()).length&&(c=(c||[]).concat(o)),!c||!c.length)return n;e.isFunction(a)&&(c=e.map(c,a));var l,f,d,p,m,h,v;for(l=0,h=c.length;l0 && options.scrollInertia<17 ? 17 : options.scrollInertia; - if(typeof options.mouseWheel!=="object" && options.mouseWheel==true){ /* old school mouseWheel option (non-object) */ - options.mouseWheel={enable:true,scrollAmount:"auto",axis:"y",preventDefault:false,deltaFactor:"auto",normalizeDelta:false,invert:false} - } - options.mouseWheel.scrollAmount=!options.mouseWheelPixels ? options.mouseWheel.scrollAmount : options.mouseWheelPixels; - options.mouseWheel.normalizeDelta=!options.advanced.normalizeMouseWheelDelta ? options.mouseWheel.normalizeDelta : options.advanced.normalizeMouseWheelDelta; - options.scrollButtons.scrollType=_findScrollButtonsType(options.scrollButtons.scrollType); - - _theme(options); /* theme-specific options */ - - /* plugin constructor */ - return $(selector).each(function(){ - - var $this=$(this); - - if(!$this.data(pluginPfx)){ /* prevent multiple instantiations */ - - /* store options and create objects in jquery data */ - $this.data(pluginPfx,{ - idx:++totalInstances, /* instance index */ - opt:options, /* options */ - scrollRatio:{y:null,x:null}, /* scrollbar to content ratio */ - overflowed:null, /* overflowed axis */ - contentReset:{y:null,x:null}, /* object to check when content resets */ - bindEvents:false, /* object to check if events are bound */ - tweenRunning:false, /* object to check if tween is running */ - sequential:{}, /* sequential scrolling object */ - langDir:$this.css("direction"), /* detect/store direction (ltr or rtl) */ - cbOffsets:null, /* object to check whether callback offsets always trigger */ - /* - object to check how scrolling events where last triggered - "internal" (default - triggered by this script), "external" (triggered by other scripts, e.g. via scrollTo method) - usage: object.data("mCS").trigger - */ - trigger:null, - /* - object to check for changes in elements in order to call the update method automatically - */ - poll:{size:{o:0,n:0},img:{o:0,n:0},change:{o:0,n:0}} - }); - - var d=$this.data(pluginPfx),o=d.opt, - /* HTML data attributes */ - htmlDataAxis=$this.data("mcs-axis"),htmlDataSbPos=$this.data("mcs-scrollbar-position"),htmlDataTheme=$this.data("mcs-theme"); - - if(htmlDataAxis){o.axis=htmlDataAxis;} /* usage example: data-mcs-axis="y" */ - if(htmlDataSbPos){o.scrollbarPosition=htmlDataSbPos;} /* usage example: data-mcs-scrollbar-position="outside" */ - if(htmlDataTheme){ /* usage example: data-mcs-theme="minimal" */ - o.theme=htmlDataTheme; - _theme(o); /* theme-specific options */ - } - - _pluginMarkup.call(this); /* add plugin markup */ - - if(d && o.callbacks.onCreate && typeof o.callbacks.onCreate==="function"){o.callbacks.onCreate.call(this);} /* callbacks: onCreate */ - - $("#mCSB_"+d.idx+"_container img:not(."+classes[2]+")").addClass(classes[2]); /* flag loaded images */ - - methods.update.call(null,$this); /* call the update method */ - - } - - }); - - }, - /* ---------------------------------------- */ - - - - /* - plugin update method - updates content and scrollbar(s) values, events and status - ---------------------------------------- - usage: $(selector).mCustomScrollbar("update"); - */ - - update:function(el,cb){ - - var selector=el || _selector.call(this); /* validate selector */ - - return $(selector).each(function(){ - - var $this=$(this); - - if($this.data(pluginPfx)){ /* check if plugin has initialized */ - - var d=$this.data(pluginPfx),o=d.opt, - mCSB_container=$("#mCSB_"+d.idx+"_container"), - mCustomScrollBox=$("#mCSB_"+d.idx), - mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")]; - - if(!mCSB_container.length){return;} - - if(d.tweenRunning){_stop($this);} /* stop any running tweens while updating */ - - if(cb && d && o.callbacks.onBeforeUpdate && typeof o.callbacks.onBeforeUpdate==="function"){o.callbacks.onBeforeUpdate.call(this);} /* callbacks: onBeforeUpdate */ - - /* if element was disabled or destroyed, remove class(es) */ - if($this.hasClass(classes[3])){$this.removeClass(classes[3]);} - if($this.hasClass(classes[4])){$this.removeClass(classes[4]);} - - /* css flexbox fix, detect/set max-height */ - mCustomScrollBox.css("max-height","none"); - if(mCustomScrollBox.height()!==$this.height()){mCustomScrollBox.css("max-height",$this.height());} - - _expandContentHorizontally.call(this); /* expand content horizontally */ - - if(o.axis!=="y" && !o.advanced.autoExpandHorizontalScroll){ - mCSB_container.css("width",_contentWidth(mCSB_container)); - } - - d.overflowed=_overflowed.call(this); /* determine if scrolling is required */ - - _scrollbarVisibility.call(this); /* show/hide scrollbar(s) */ - - /* auto-adjust scrollbar dragger length analogous to content */ - if(o.autoDraggerLength){_setDraggerLength.call(this);} - - _scrollRatio.call(this); /* calculate and store scrollbar to content ratio */ - - _bindEvents.call(this); /* bind scrollbar events */ - - /* reset scrolling position and/or events */ - var to=[Math.abs(mCSB_container[0].offsetTop),Math.abs(mCSB_container[0].offsetLeft)]; - if(o.axis!=="x"){ /* y/yx axis */ - if(!d.overflowed[0]){ /* y scrolling is not required */ - _resetContentPosition.call(this); /* reset content position */ - if(o.axis==="y"){ - _unbindEvents.call(this); - }else if(o.axis==="yx" && d.overflowed[1]){ - _scrollTo($this,to[1].toString(),{dir:"x",dur:0,overwrite:"none"}); - } - }else if(mCSB_dragger[0].height()>mCSB_dragger[0].parent().height()){ - _resetContentPosition.call(this); /* reset content position */ - }else{ /* y scrolling is required */ - _scrollTo($this,to[0].toString(),{dir:"y",dur:0,overwrite:"none"}); - d.contentReset.y=null; - } - } - if(o.axis!=="y"){ /* x/yx axis */ - if(!d.overflowed[1]){ /* x scrolling is not required */ - _resetContentPosition.call(this); /* reset content position */ - if(o.axis==="x"){ - _unbindEvents.call(this); - }else if(o.axis==="yx" && d.overflowed[0]){ - _scrollTo($this,to[0].toString(),{dir:"y",dur:0,overwrite:"none"}); - } - }else if(mCSB_dragger[1].width()>mCSB_dragger[1].parent().width()){ - _resetContentPosition.call(this); /* reset content position */ - }else{ /* x scrolling is required */ - _scrollTo($this,to[1].toString(),{dir:"x",dur:0,overwrite:"none"}); - d.contentReset.x=null; - } - } - - /* callbacks: onImageLoad, onSelectorChange, onUpdate */ - if(cb && d){ - if(cb===2 && o.callbacks.onImageLoad && typeof o.callbacks.onImageLoad==="function"){ - o.callbacks.onImageLoad.call(this); - }else if(cb===3 && o.callbacks.onSelectorChange && typeof o.callbacks.onSelectorChange==="function"){ - o.callbacks.onSelectorChange.call(this); - }else if(o.callbacks.onUpdate && typeof o.callbacks.onUpdate==="function"){ - o.callbacks.onUpdate.call(this); - } - } - - _autoUpdate.call(this); /* initialize automatic updating (for dynamic content, fluid layouts etc.) */ - - } - - }); - - }, - /* ---------------------------------------- */ - - - - /* - plugin scrollTo method - triggers a scrolling event to a specific value - ---------------------------------------- - usage: $(selector).mCustomScrollbar("scrollTo",value,options); - */ - - scrollTo:function(val,options){ - - /* prevent silly things like $(selector).mCustomScrollbar("scrollTo",undefined); */ - if(typeof val=="undefined" || val==null){return;} - - var selector=_selector.call(this); /* validate selector */ - - return $(selector).each(function(){ - - var $this=$(this); - - if($this.data(pluginPfx)){ /* check if plugin has initialized */ - - var d=$this.data(pluginPfx),o=d.opt, - /* method default options */ - methodDefaults={ - trigger:"external", /* method is by default triggered externally (e.g. from other scripts) */ - scrollInertia:o.scrollInertia, /* scrolling inertia (animation duration) */ - scrollEasing:"mcsEaseInOut", /* animation easing */ - moveDragger:false, /* move dragger instead of content */ - timeout:60, /* scroll-to delay */ - callbacks:true, /* enable/disable callbacks */ - onStart:true, - onUpdate:true, - onComplete:true - }, - methodOptions=$.extend(true,{},methodDefaults,options), - to=_arr.call(this,val),dur=methodOptions.scrollInertia>0 && methodOptions.scrollInertia<17 ? 17 : methodOptions.scrollInertia; - - /* translate yx values to actual scroll-to positions */ - to[0]=_to.call(this,to[0],"y"); - to[1]=_to.call(this,to[1],"x"); - - /* - check if scroll-to value moves the dragger instead of content. - Only pixel values apply on dragger (e.g. 100, "100px", "-=100" etc.) - */ - if(methodOptions.moveDragger){ - to[0]*=d.scrollRatio.y; - to[1]*=d.scrollRatio.x; - } - - methodOptions.dur=_isTabHidden() ? 0 : dur; //skip animations if browser tab is hidden - - setTimeout(function(){ - /* do the scrolling */ - if(to[0]!==null && typeof to[0]!=="undefined" && o.axis!=="x" && d.overflowed[0]){ /* scroll y */ - methodOptions.dir="y"; - methodOptions.overwrite="all"; - _scrollTo($this,to[0].toString(),methodOptions); - } - if(to[1]!==null && typeof to[1]!=="undefined" && o.axis!=="y" && d.overflowed[1]){ /* scroll x */ - methodOptions.dir="x"; - methodOptions.overwrite="none"; - _scrollTo($this,to[1].toString(),methodOptions); - } - },methodOptions.timeout); - - } - - }); - - }, - /* ---------------------------------------- */ - - - - /* - plugin stop method - stops scrolling animation - ---------------------------------------- - usage: $(selector).mCustomScrollbar("stop"); - */ - stop:function(){ - - var selector=_selector.call(this); /* validate selector */ - - return $(selector).each(function(){ - - var $this=$(this); - - if($this.data(pluginPfx)){ /* check if plugin has initialized */ - - _stop($this); - - } - - }); - - }, - /* ---------------------------------------- */ - - - - /* - plugin disable method - temporarily disables the scrollbar(s) - ---------------------------------------- - usage: $(selector).mCustomScrollbar("disable",reset); - reset (boolean): resets content position to 0 - */ - disable:function(r){ - - var selector=_selector.call(this); /* validate selector */ - - return $(selector).each(function(){ - - var $this=$(this); - - if($this.data(pluginPfx)){ /* check if plugin has initialized */ - - var d=$this.data(pluginPfx); - - _autoUpdate.call(this,"remove"); /* remove automatic updating */ - - _unbindEvents.call(this); /* unbind events */ - - if(r){_resetContentPosition.call(this);} /* reset content position */ - - _scrollbarVisibility.call(this,true); /* show/hide scrollbar(s) */ - - $this.addClass(classes[3]); /* add disable class */ - - } - - }); - - }, - /* ---------------------------------------- */ - - - - /* - plugin destroy method - completely removes the scrollbar(s) and returns the element to its original state - ---------------------------------------- - usage: $(selector).mCustomScrollbar("destroy"); - */ - destroy:function(){ - - var selector=_selector.call(this); /* validate selector */ - - return $(selector).each(function(){ - - var $this=$(this); - - if($this.data(pluginPfx)){ /* check if plugin has initialized */ - - var d=$this.data(pluginPfx),o=d.opt, - mCustomScrollBox=$("#mCSB_"+d.idx), - mCSB_container=$("#mCSB_"+d.idx+"_container"), - scrollbar=$(".mCSB_"+d.idx+"_scrollbar"); - - if(o.live){removeLiveTimers(o.liveSelector || $(selector).selector);} /* remove live timers */ - - _autoUpdate.call(this,"remove"); /* remove automatic updating */ - - _unbindEvents.call(this); /* unbind events */ - - _resetContentPosition.call(this); /* reset content position */ - - $this.removeData(pluginPfx); /* remove plugin data object */ - - _delete(this,"mcs"); /* delete callbacks object */ - - /* remove plugin markup */ - scrollbar.remove(); /* remove scrollbar(s) first (those can be either inside or outside plugin's inner wrapper) */ - mCSB_container.find("img."+classes[2]).removeClass(classes[2]); /* remove loaded images flag */ - mCustomScrollBox.replaceWith(mCSB_container.contents()); /* replace plugin's inner wrapper with the original content */ - /* remove plugin classes from the element and add destroy class */ - $this.removeClass(pluginNS+" _"+pluginPfx+"_"+d.idx+" "+classes[6]+" "+classes[7]+" "+classes[5]+" "+classes[3]).addClass(classes[4]); - - } - - }); - - } - /* ---------------------------------------- */ - - }, - - - - - - /* - ---------------------------------------- - FUNCTIONS - ---------------------------------------- - */ - - /* validates selector (if selector is invalid or undefined uses the default one) */ - _selector=function(){ - return (typeof $(this)!=="object" || $(this).length<1) ? defaultSelector : this; - }, - /* -------------------- */ - - - /* changes options according to theme */ - _theme=function(obj){ - var fixedSizeScrollbarThemes=["rounded","rounded-dark","rounded-dots","rounded-dots-dark"], - nonExpandedScrollbarThemes=["rounded-dots","rounded-dots-dark","3d","3d-dark","3d-thick","3d-thick-dark","inset","inset-dark","inset-2","inset-2-dark","inset-3","inset-3-dark"], - disabledScrollButtonsThemes=["minimal","minimal-dark"], - enabledAutoHideScrollbarThemes=["minimal","minimal-dark"], - scrollbarPositionOutsideThemes=["minimal","minimal-dark"]; - obj.autoDraggerLength=$.inArray(obj.theme,fixedSizeScrollbarThemes) > -1 ? false : obj.autoDraggerLength; - obj.autoExpandScrollbar=$.inArray(obj.theme,nonExpandedScrollbarThemes) > -1 ? false : obj.autoExpandScrollbar; - obj.scrollButtons.enable=$.inArray(obj.theme,disabledScrollButtonsThemes) > -1 ? false : obj.scrollButtons.enable; - obj.autoHideScrollbar=$.inArray(obj.theme,enabledAutoHideScrollbarThemes) > -1 ? true : obj.autoHideScrollbar; - obj.scrollbarPosition=$.inArray(obj.theme,scrollbarPositionOutsideThemes) > -1 ? "outside" : obj.scrollbarPosition; - }, - /* -------------------- */ - - - /* live option timers removal */ - removeLiveTimers=function(selector){ - if(liveTimers[selector]){ - clearTimeout(liveTimers[selector]); - _delete(liveTimers,selector); - } - }, - /* -------------------- */ - - - /* normalizes axis option to valid values: "y", "x", "yx" */ - _findAxis=function(val){ - return (val==="yx" || val==="xy" || val==="auto") ? "yx" : (val==="x" || val==="horizontal") ? "x" : "y"; - }, - /* -------------------- */ - - - /* normalizes scrollButtons.scrollType option to valid values: "stepless", "stepped" */ - _findScrollButtonsType=function(val){ - return (val==="stepped" || val==="pixels" || val==="step" || val==="click") ? "stepped" : "stepless"; - }, - /* -------------------- */ - - - /* generates plugin markup */ - _pluginMarkup=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - expandClass=o.autoExpandScrollbar ? " "+classes[1]+"_expand" : "", - scrollbar=["
","
"], - wrapperClass=o.axis==="yx" ? "mCSB_vertical_horizontal" : o.axis==="x" ? "mCSB_horizontal" : "mCSB_vertical", - scrollbars=o.axis==="yx" ? scrollbar[0]+scrollbar[1] : o.axis==="x" ? scrollbar[1] : scrollbar[0], - contentWrapper=o.axis==="yx" ? "
" : "", - autoHideClass=o.autoHideScrollbar ? " "+classes[6] : "", - scrollbarDirClass=(o.axis!=="x" && d.langDir==="rtl") ? " "+classes[7] : ""; - if(o.setWidth){$this.css("width",o.setWidth);} /* set element width */ - if(o.setHeight){$this.css("height",o.setHeight);} /* set element height */ - o.setLeft=(o.axis!=="y" && d.langDir==="rtl") ? "989999px" : o.setLeft; /* adjust left position for rtl direction */ - $this.addClass(pluginNS+" _"+pluginPfx+"_"+d.idx+autoHideClass+scrollbarDirClass).wrapInner("
"); - var mCustomScrollBox=$("#mCSB_"+d.idx), - mCSB_container=$("#mCSB_"+d.idx+"_container"); - if(o.axis!=="y" && !o.advanced.autoExpandHorizontalScroll){ - mCSB_container.css("width",_contentWidth(mCSB_container)); - } - if(o.scrollbarPosition==="outside"){ - if($this.css("position")==="static"){ /* requires elements with non-static position */ - $this.css("position","relative"); - } - $this.css("overflow","visible"); - mCustomScrollBox.addClass("mCSB_outside").after(scrollbars); - }else{ - mCustomScrollBox.addClass("mCSB_inside").append(scrollbars); - mCSB_container.wrap(contentWrapper); - } - _scrollButtons.call(this); /* add scrollbar buttons */ - /* minimum dragger length */ - var mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")]; - mCSB_dragger[0].css("min-height",mCSB_dragger[0].height()); - mCSB_dragger[1].css("min-width",mCSB_dragger[1].width()); - }, - /* -------------------- */ - - - /* calculates content width */ - _contentWidth=function(el){ - var val=[el[0].scrollWidth,Math.max.apply(Math,el.children().map(function(){return $(this).outerWidth(true);}).get())],w=el.parent().width(); - return val[0]>w ? val[0] : val[1]>w ? val[1] : "100%"; - }, - /* -------------------- */ - - - /* expands content horizontally */ - _expandContentHorizontally=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - mCSB_container=$("#mCSB_"+d.idx+"_container"); - if(o.advanced.autoExpandHorizontalScroll && o.axis!=="y"){ - /* calculate scrollWidth */ - mCSB_container.css({"width":"auto","min-width":0,"overflow-x":"scroll"}); - var w=Math.ceil(mCSB_container[0].scrollWidth); - if(o.advanced.autoExpandHorizontalScroll===3 || (o.advanced.autoExpandHorizontalScroll!==2 && w>mCSB_container.parent().width())){ - mCSB_container.css({"width":w,"min-width":"100%","overflow-x":"inherit"}); - }else{ - /* - wrap content with an infinite width div and set its position to absolute and width to auto. - Setting width to auto before calculating the actual width is important! - We must let the browser set the width as browser zoom values are impossible to calculate. - */ - mCSB_container.css({"overflow-x":"inherit","position":"absolute"}) - .wrap("
") - .css({ /* set actual width, original position and un-wrap */ - /* - get the exact width (with decimals) and then round-up. - Using jquery outerWidth() will round the width value which will mess up with inner elements that have non-integer width - */ - "width":(Math.ceil(mCSB_container[0].getBoundingClientRect().right+0.4)-Math.floor(mCSB_container[0].getBoundingClientRect().left)), - "min-width":"100%", - "position":"relative" - }).unwrap(); - } - } - }, - /* -------------------- */ - - - /* adds scrollbar buttons */ - _scrollButtons=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - mCSB_scrollTools=$(".mCSB_"+d.idx+"_scrollbar:first"), - tabindex=!_isNumeric(o.scrollButtons.tabindex) ? "" : "tabindex='"+o.scrollButtons.tabindex+"'", - btnHTML=[ - "", - "", - "", - "" - ], - btn=[(o.axis==="x" ? btnHTML[2] : btnHTML[0]),(o.axis==="x" ? btnHTML[3] : btnHTML[1]),btnHTML[2],btnHTML[3]]; - if(o.scrollButtons.enable){ - mCSB_scrollTools.prepend(btn[0]).append(btn[1]).next(".mCSB_scrollTools").prepend(btn[2]).append(btn[3]); - } - }, - /* -------------------- */ - - - /* auto-adjusts scrollbar dragger length */ - _setDraggerLength=function(){ - var $this=$(this),d=$this.data(pluginPfx), - mCustomScrollBox=$("#mCSB_"+d.idx), - mCSB_container=$("#mCSB_"+d.idx+"_container"), - mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")], - ratio=[mCustomScrollBox.height()/mCSB_container.outerHeight(false),mCustomScrollBox.width()/mCSB_container.outerWidth(false)], - l=[ - parseInt(mCSB_dragger[0].css("min-height")),Math.round(ratio[0]*mCSB_dragger[0].parent().height()), - parseInt(mCSB_dragger[1].css("min-width")),Math.round(ratio[1]*mCSB_dragger[1].parent().width()) - ], - h=oldIE && (l[1]contentHeight){contentHeight=h;} - if(w>contentWidth){contentWidth=w;} - return [contentHeight>mCustomScrollBox.height(),contentWidth>mCustomScrollBox.width()]; - }, - /* -------------------- */ - - - /* resets content position to 0 */ - _resetContentPosition=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - mCustomScrollBox=$("#mCSB_"+d.idx), - mCSB_container=$("#mCSB_"+d.idx+"_container"), - mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")]; - _stop($this); /* stop any current scrolling before resetting */ - if((o.axis!=="x" && !d.overflowed[0]) || (o.axis==="y" && d.overflowed[0])){ /* reset y */ - mCSB_dragger[0].add(mCSB_container).css("top",0); - _scrollTo($this,"_resetY"); - } - if((o.axis!=="y" && !d.overflowed[1]) || (o.axis==="x" && d.overflowed[1])){ /* reset x */ - var cx=dx=0; - if(d.langDir==="rtl"){ /* adjust left position for rtl direction */ - cx=mCustomScrollBox.width()-mCSB_container.outerWidth(false); - dx=Math.abs(cx/d.scrollRatio.x); - } - mCSB_container.css("left",cx); - mCSB_dragger[1].css("left",dx); - _scrollTo($this,"_resetX"); - } - }, - /* -------------------- */ - - - /* binds scrollbar events */ - _bindEvents=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt; - if(!d.bindEvents){ /* check if events are already bound */ - _draggable.call(this); - if(o.contentTouchScroll){_contentDraggable.call(this);} - _selectable.call(this); - if(o.mouseWheel.enable){ /* bind mousewheel fn when plugin is available */ - function _mwt(){ - mousewheelTimeout=setTimeout(function(){ - if(!$.event.special.mousewheel){ - _mwt(); - }else{ - clearTimeout(mousewheelTimeout); - _mousewheel.call($this[0]); - } - },100); - } - var mousewheelTimeout; - _mwt(); - } - _draggerRail.call(this); - _wrapperScroll.call(this); - if(o.advanced.autoScrollOnFocus){_focus.call(this);} - if(o.scrollButtons.enable){_buttons.call(this);} - if(o.keyboard.enable){_keyboard.call(this);} - d.bindEvents=true; - } - }, - /* -------------------- */ - - - /* unbinds scrollbar events */ - _unbindEvents=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - namespace=pluginPfx+"_"+d.idx, - sb=".mCSB_"+d.idx+"_scrollbar", - sel=$("#mCSB_"+d.idx+",#mCSB_"+d.idx+"_container,#mCSB_"+d.idx+"_container_wrapper,"+sb+" ."+classes[12]+",#mCSB_"+d.idx+"_dragger_vertical,#mCSB_"+d.idx+"_dragger_horizontal,"+sb+">a"), - mCSB_container=$("#mCSB_"+d.idx+"_container"); - if(o.advanced.releaseDraggableSelectors){sel.add($(o.advanced.releaseDraggableSelectors));} - if(o.advanced.extraDraggableSelectors){sel.add($(o.advanced.extraDraggableSelectors));} - if(d.bindEvents){ /* check if events are bound */ - /* unbind namespaced events from document/selectors */ - $(document).add($(!_canAccessIFrame() || top.document)).unbind("."+namespace); - sel.each(function(){ - $(this).unbind("."+namespace); - }); - /* clear and delete timeouts/objects */ - clearTimeout($this[0]._focusTimeout); _delete($this[0],"_focusTimeout"); - clearTimeout(d.sequential.step); _delete(d.sequential,"step"); - clearTimeout(mCSB_container[0].onCompleteTimeout); _delete(mCSB_container[0],"onCompleteTimeout"); - d.bindEvents=false; - } - }, - /* -------------------- */ - - - /* toggles scrollbar visibility */ - _scrollbarVisibility=function(disabled){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - contentWrapper=$("#mCSB_"+d.idx+"_container_wrapper"), - content=contentWrapper.length ? contentWrapper : $("#mCSB_"+d.idx+"_container"), - scrollbar=[$("#mCSB_"+d.idx+"_scrollbar_vertical"),$("#mCSB_"+d.idx+"_scrollbar_horizontal")], - mCSB_dragger=[scrollbar[0].find(".mCSB_dragger"),scrollbar[1].find(".mCSB_dragger")]; - if(o.axis!=="x"){ - if(d.overflowed[0] && !disabled){ - scrollbar[0].add(mCSB_dragger[0]).add(scrollbar[0].children("a")).css("display","block"); - content.removeClass(classes[8]+" "+classes[10]); - }else{ - if(o.alwaysShowScrollbar){ - if(o.alwaysShowScrollbar!==2){mCSB_dragger[0].css("display","none");} - content.removeClass(classes[10]); - }else{ - scrollbar[0].css("display","none"); - content.addClass(classes[10]); - } - content.addClass(classes[8]); - } - } - if(o.axis!=="y"){ - if(d.overflowed[1] && !disabled){ - scrollbar[1].add(mCSB_dragger[1]).add(scrollbar[1].children("a")).css("display","block"); - content.removeClass(classes[9]+" "+classes[11]); - }else{ - if(o.alwaysShowScrollbar){ - if(o.alwaysShowScrollbar!==2){mCSB_dragger[1].css("display","none");} - content.removeClass(classes[11]); - }else{ - scrollbar[1].css("display","none"); - content.addClass(classes[11]); - } - content.addClass(classes[9]); - } - } - if(!d.overflowed[0] && !d.overflowed[1]){ - $this.addClass(classes[5]); - }else{ - $this.removeClass(classes[5]); - } - }, - /* -------------------- */ - - - /* returns input coordinates of pointer, touch and mouse events (relative to document) */ - _coordinates=function(e){ - var t=e.type,o=e.target.ownerDocument!==document && frameElement!==null ? [$(frameElement).offset().top,$(frameElement).offset().left] : null, - io=_canAccessIFrame() && e.target.ownerDocument!==top.document && frameElement!==null ? [$(e.view.frameElement).offset().top,$(e.view.frameElement).offset().left] : [0,0]; - switch(t){ - case "pointerdown": case "MSPointerDown": case "pointermove": case "MSPointerMove": case "pointerup": case "MSPointerUp": - return o ? [e.originalEvent.pageY-o[0]+io[0],e.originalEvent.pageX-o[1]+io[1],false] : [e.originalEvent.pageY,e.originalEvent.pageX,false]; - break; - case "touchstart": case "touchmove": case "touchend": - var touch=e.originalEvent.touches[0] || e.originalEvent.changedTouches[0], - touches=e.originalEvent.touches.length || e.originalEvent.changedTouches.length; - return e.target.ownerDocument!==document ? [touch.screenY,touch.screenX,touches>1] : [touch.pageY,touch.pageX,touches>1]; - break; - default: - return o ? [e.pageY-o[0]+io[0],e.pageX-o[1]+io[1],false] : [e.pageY,e.pageX,false]; - } - }, - /* -------------------- */ - - - /* - SCROLLBAR DRAG EVENTS - scrolls content via scrollbar dragging - */ - _draggable=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - namespace=pluginPfx+"_"+d.idx, - draggerId=["mCSB_"+d.idx+"_dragger_vertical","mCSB_"+d.idx+"_dragger_horizontal"], - mCSB_container=$("#mCSB_"+d.idx+"_container"), - mCSB_dragger=$("#"+draggerId[0]+",#"+draggerId[1]), - draggable,dragY,dragX, - rds=o.advanced.releaseDraggableSelectors ? mCSB_dragger.add($(o.advanced.releaseDraggableSelectors)) : mCSB_dragger, - eds=o.advanced.extraDraggableSelectors ? $(!_canAccessIFrame() || top.document).add($(o.advanced.extraDraggableSelectors)) : $(!_canAccessIFrame() || top.document); - mCSB_dragger.bind("contextmenu."+namespace,function(e){ - e.preventDefault(); //prevent right click - }).bind("mousedown."+namespace+" touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace,function(e){ - e.stopImmediatePropagation(); - e.preventDefault(); - if(!_mouseBtnLeft(e)){return;} /* left mouse button only */ - touchActive=true; - if(oldIE){document.onselectstart=function(){return false;}} /* disable text selection for IE < 9 */ - _iframe.call(mCSB_container,false); /* enable scrollbar dragging over iframes by disabling their events */ - _stop($this); - draggable=$(this); - var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left, - h=draggable.height()+offset.top,w=draggable.width()+offset.left; - if(y0 && x0){ - dragY=y; - dragX=x; - } - _onDragClasses(draggable,"active",o.autoExpandScrollbar); - }).bind("touchmove."+namespace,function(e){ - e.stopImmediatePropagation(); - e.preventDefault(); - var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left; - _drag(dragY,dragX,y,x); - }); - $(document).add(eds).bind("mousemove."+namespace+" pointermove."+namespace+" MSPointerMove."+namespace,function(e){ - if(draggable){ - var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left; - if(dragY===y && dragX===x){return;} /* has it really moved? */ - _drag(dragY,dragX,y,x); - } - }).add(rds).bind("mouseup."+namespace+" touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace,function(e){ - if(draggable){ - _onDragClasses(draggable,"active",o.autoExpandScrollbar); - draggable=null; - } - touchActive=false; - if(oldIE){document.onselectstart=null;} /* enable text selection for IE < 9 */ - _iframe.call(mCSB_container,true); /* enable iframes events */ - }); - function _drag(dragY,dragX,y,x){ - mCSB_container[0].idleTimer=o.scrollInertia<233 ? 250 : 0; - if(draggable.attr("id")===draggerId[1]){ - var dir="x",to=((draggable[0].offsetLeft-dragX)+x)*d.scrollRatio.x; - }else{ - var dir="y",to=((draggable[0].offsetTop-dragY)+y)*d.scrollRatio.y; - } - _scrollTo($this,to.toString(),{dir:dir,drag:true}); - } - }, - /* -------------------- */ - - - /* - TOUCH SWIPE EVENTS - scrolls content via touch swipe - Emulates the native touch-swipe scrolling with momentum found in iOS, Android and WP devices - */ - _contentDraggable=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - namespace=pluginPfx+"_"+d.idx, - mCustomScrollBox=$("#mCSB_"+d.idx), - mCSB_container=$("#mCSB_"+d.idx+"_container"), - mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")], - draggable,dragY,dragX,touchStartY,touchStartX,touchMoveY=[],touchMoveX=[],startTime,runningTime,endTime,distance,speed,amount, - durA=0,durB,overwrite=o.axis==="yx" ? "none" : "all",touchIntent=[],touchDrag,docDrag, - iframe=mCSB_container.find("iframe"), - events=[ - "touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace, //start - "touchmove."+namespace+" pointermove."+namespace+" MSPointerMove."+namespace, //move - "touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace //end - ], - touchAction=document.body.style.touchAction!==undefined && document.body.style.touchAction!==""; - mCSB_container.bind(events[0],function(e){ - _onTouchstart(e); - }).bind(events[1],function(e){ - _onTouchmove(e); - }); - mCustomScrollBox.bind(events[0],function(e){ - _onTouchstart2(e); - }).bind(events[2],function(e){ - _onTouchend(e); - }); - if(iframe.length){ - iframe.each(function(){ - $(this).bind("load",function(){ - /* bind events on accessible iframes */ - if(_canAccessIFrame(this)){ - $(this.contentDocument || this.contentWindow.document).bind(events[0],function(e){ - _onTouchstart(e); - _onTouchstart2(e); - }).bind(events[1],function(e){ - _onTouchmove(e); - }).bind(events[2],function(e){ - _onTouchend(e); - }); - } - }); - }); - } - function _onTouchstart(e){ - if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){touchable=0; return;} - touchable=1; touchDrag=0; docDrag=0; draggable=1; - $this.removeClass("mCS_touch_action"); - var offset=mCSB_container.offset(); - dragY=_coordinates(e)[0]-offset.top; - dragX=_coordinates(e)[1]-offset.left; - touchIntent=[_coordinates(e)[0],_coordinates(e)[1]]; - } - function _onTouchmove(e){ - if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){return;} - if(!o.documentTouchScroll){e.preventDefault();} - e.stopImmediatePropagation(); - if(docDrag && !touchDrag){return;} - if(draggable){ - runningTime=_getTime(); - var offset=mCustomScrollBox.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left, - easing="mcsLinearOut"; - touchMoveY.push(y); - touchMoveX.push(x); - touchIntent[2]=Math.abs(_coordinates(e)[0]-touchIntent[0]); touchIntent[3]=Math.abs(_coordinates(e)[1]-touchIntent[1]); - if(d.overflowed[0]){ - var limit=mCSB_dragger[0].parent().height()-mCSB_dragger[0].height(), - prevent=((dragY-y)>0 && (y-dragY)>-(limit*d.scrollRatio.y) && (touchIntent[3]*20 && (x-dragX)>-(limitX*d.scrollRatio.x) && (touchIntent[2]*230){return;} - speed=1000/(endTime-startTime); - var easing="mcsEaseOut",slow=speed<2.5, - diff=slow ? [touchMoveY[touchMoveY.length-2],touchMoveX[touchMoveX.length-2]] : [0,0]; - distance=slow ? [(y-diff[0]),(x-diff[1])] : [y-touchStartY,x-touchStartX]; - var absDistance=[Math.abs(distance[0]),Math.abs(distance[1])]; - speed=slow ? [Math.abs(distance[0]/4),Math.abs(distance[1]/4)] : [speed,speed]; - var a=[ - Math.abs(mCSB_container[0].offsetTop)-(distance[0]*_m((absDistance[0]/speed[0]),speed[0])), - Math.abs(mCSB_container[0].offsetLeft)-(distance[1]*_m((absDistance[1]/speed[1]),speed[1])) - ]; - amount=o.axis==="yx" ? [a[0],a[1]] : o.axis==="x" ? [null,a[1]] : [a[0],null]; - durB=[(absDistance[0]*4)+o.scrollInertia,(absDistance[1]*4)+o.scrollInertia]; - var md=parseInt(o.contentTouchScroll) || 0; /* absolute minimum distance required */ - amount[0]=absDistance[0]>md ? amount[0] : 0; - amount[1]=absDistance[1]>md ? amount[1] : 0; - if(d.overflowed[0]){_drag(amount[0],durB[0],easing,"y",overwrite,false);} - if(d.overflowed[1]){_drag(amount[1],durB[1],easing,"x",overwrite,false);} - } - function _m(ds,s){ - var r=[s*1.5,s*2,s/1.5,s/2]; - if(ds>90){ - return s>4 ? r[0] : r[3]; - }else if(ds>60){ - return s>3 ? r[3] : r[2]; - }else if(ds>30){ - return s>8 ? r[1] : s>6 ? r[0] : s>4 ? s : r[2]; - }else{ - return s>8 ? s : r[3]; - } - } - function _drag(amount,dur,easing,dir,overwrite,drag){ - if(!amount){return;} - _scrollTo($this,amount.toString(),{dur:dur,scrollEasing:easing,dir:dir,overwrite:overwrite,drag:drag}); - } - }, - /* -------------------- */ - - - /* - SELECT TEXT EVENTS - scrolls content when text is selected - */ - _selectable=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt,seq=d.sequential, - namespace=pluginPfx+"_"+d.idx, - mCSB_container=$("#mCSB_"+d.idx+"_container"), - wrapper=mCSB_container.parent(), - action; - mCSB_container.bind("mousedown."+namespace,function(e){ - if(touchable){return;} - if(!action){action=1; touchActive=true;} - }).add(document).bind("mousemove."+namespace,function(e){ - if(!touchable && action && _sel()){ - var offset=mCSB_container.offset(), - y=_coordinates(e)[0]-offset.top+mCSB_container[0].offsetTop,x=_coordinates(e)[1]-offset.left+mCSB_container[0].offsetLeft; - if(y>0 && y0 && xwrapper.height()){ - _seq("on",40); - } - } - if(o.axis!=="y" && d.overflowed[1]){ - if(x<0){ - _seq("on",37); - }else if(x>wrapper.width()){ - _seq("on",39); - } - } - } - } - }).bind("mouseup."+namespace+" dragend."+namespace,function(e){ - if(touchable){return;} - if(action){action=0; _seq("off",null);} - touchActive=false; - }); - function _sel(){ - return window.getSelection ? window.getSelection().toString() : - document.selection && document.selection.type!="Control" ? document.selection.createRange().text : 0; - } - function _seq(a,c,s){ - seq.type=s && action ? "stepped" : "stepless"; - seq.scrollAmount=10; - _sequentialScroll($this,a,c,"mcsLinearOut",s ? 60 : null); - } - }, - /* -------------------- */ - - - /* - MOUSE WHEEL EVENT - scrolls content via mouse-wheel - via mouse-wheel plugin (https://github.com/brandonaaron/jquery-mousewheel) - */ - _mousewheel=function(){ - if(!$(this).data(pluginPfx)){return;} /* Check if the scrollbar is ready to use mousewheel events (issue: #185) */ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - namespace=pluginPfx+"_"+d.idx, - mCustomScrollBox=$("#mCSB_"+d.idx), - mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")], - iframe=$("#mCSB_"+d.idx+"_container").find("iframe"); - if(iframe.length){ - iframe.each(function(){ - $(this).bind("load",function(){ - /* bind events on accessible iframes */ - if(_canAccessIFrame(this)){ - $(this.contentDocument || this.contentWindow.document).bind("mousewheel."+namespace,function(e,delta){ - _onMousewheel(e,delta); - }); - } - }); - }); - } - mCustomScrollBox.bind("mousewheel."+namespace,function(e,delta){ - _onMousewheel(e,delta); - }); - function _onMousewheel(e,delta){ - _stop($this); - if(_disableMousewheel($this,e.target)){return;} /* disables mouse-wheel when hovering specific elements */ - var deltaFactor=o.mouseWheel.deltaFactor!=="auto" ? parseInt(o.mouseWheel.deltaFactor) : (oldIE && e.deltaFactor<100) ? 100 : e.deltaFactor || 100, - dur=o.scrollInertia; - if(o.axis==="x" || o.mouseWheel.axis==="x"){ - var dir="x", - px=[Math.round(deltaFactor*d.scrollRatio.x),parseInt(o.mouseWheel.scrollAmount)], - amount=o.mouseWheel.scrollAmount!=="auto" ? px[1] : px[0]>=mCustomScrollBox.width() ? mCustomScrollBox.width()*0.9 : px[0], - contentPos=Math.abs($("#mCSB_"+d.idx+"_container")[0].offsetLeft), - draggerPos=mCSB_dragger[1][0].offsetLeft, - limit=mCSB_dragger[1].parent().width()-mCSB_dragger[1].width(), - dlt=o.mouseWheel.axis==="y" ? (e.deltaY || delta) : e.deltaX; - }else{ - var dir="y", - px=[Math.round(deltaFactor*d.scrollRatio.y),parseInt(o.mouseWheel.scrollAmount)], - amount=o.mouseWheel.scrollAmount!=="auto" ? px[1] : px[0]>=mCustomScrollBox.height() ? mCustomScrollBox.height()*0.9 : px[0], - contentPos=Math.abs($("#mCSB_"+d.idx+"_container")[0].offsetTop), - draggerPos=mCSB_dragger[0][0].offsetTop, - limit=mCSB_dragger[0].parent().height()-mCSB_dragger[0].height(), - dlt=e.deltaY || delta; - } - if((dir==="y" && !d.overflowed[0]) || (dir==="x" && !d.overflowed[1])){return;} - if(o.mouseWheel.invert || e.webkitDirectionInvertedFromDevice){dlt=-dlt;} - if(o.mouseWheel.normalizeDelta){dlt=dlt<0 ? -1 : 1;} - if((dlt>0 && draggerPos!==0) || (dlt<0 && draggerPos!==limit) || o.mouseWheel.preventDefault){ - e.stopImmediatePropagation(); - e.preventDefault(); - } - if(e.deltaFactor<5 && !o.mouseWheel.normalizeDelta){ - //very low deltaFactor values mean some kind of delta acceleration (e.g. osx trackpad), so adjusting scrolling accordingly - amount=e.deltaFactor; dur=17; - } - _scrollTo($this,(contentPos-(dlt*amount)).toString(),{dir:dir,dur:dur}); - } - }, - /* -------------------- */ - - - /* checks if iframe can be accessed */ - _canAccessIFrameCache=new Object(), - _canAccessIFrame=function(iframe){ - var result=false,cacheKey=false,html=null; - if(iframe===undefined){ - cacheKey="#empty"; - }else if($(iframe).attr("id")!==undefined){ - cacheKey=$(iframe).attr("id"); - } - if(cacheKey!==false && _canAccessIFrameCache[cacheKey]!==undefined){ - return _canAccessIFrameCache[cacheKey]; - } - if(!iframe){ - try{ - var doc=top.document; - html=doc.body.innerHTML; - }catch(err){/* do nothing */} - result=(html!==null); - }else{ - try{ - var doc=iframe.contentDocument || iframe.contentWindow.document; - html=doc.body.innerHTML; - }catch(err){/* do nothing */} - result=(html!==null); - } - if(cacheKey!==false){_canAccessIFrameCache[cacheKey]=result;} - return result; - }, - /* -------------------- */ - - - /* switches iframe's pointer-events property (drag, mousewheel etc. over cross-domain iframes) */ - _iframe=function(evt){ - var el=this.find("iframe"); - if(!el.length){return;} /* check if content contains iframes */ - var val=!evt ? "none" : "auto"; - el.css("pointer-events",val); /* for IE11, iframe's display property should not be "block" */ - }, - /* -------------------- */ - - - /* disables mouse-wheel when hovering specific elements like select, datalist etc. */ - _disableMousewheel=function(el,target){ - var tag=target.nodeName.toLowerCase(), - tags=el.data(pluginPfx).opt.mouseWheel.disableOver, - /* elements that require focus */ - focusTags=["select","textarea"]; - return $.inArray(tag,tags) > -1 && !($.inArray(tag,focusTags) > -1 && !$(target).is(":focus")); - }, - /* -------------------- */ - - - /* - DRAGGER RAIL CLICK EVENT - scrolls content via dragger rail - */ - _draggerRail=function(){ - var $this=$(this),d=$this.data(pluginPfx), - namespace=pluginPfx+"_"+d.idx, - mCSB_container=$("#mCSB_"+d.idx+"_container"), - wrapper=mCSB_container.parent(), - mCSB_draggerContainer=$(".mCSB_"+d.idx+"_scrollbar ."+classes[12]), - clickable; - mCSB_draggerContainer.bind("mousedown."+namespace+" touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace,function(e){ - touchActive=true; - if(!$(e.target).hasClass("mCSB_dragger")){clickable=1;} - }).bind("touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace,function(e){ - touchActive=false; - }).bind("click."+namespace,function(e){ - if(!clickable){return;} - clickable=0; - if($(e.target).hasClass(classes[12]) || $(e.target).hasClass("mCSB_draggerRail")){ - _stop($this); - var el=$(this),mCSB_dragger=el.find(".mCSB_dragger"); - if(el.parent(".mCSB_scrollTools_horizontal").length>0){ - if(!d.overflowed[1]){return;} - var dir="x", - clickDir=e.pageX>mCSB_dragger.offset().left ? -1 : 1, - to=Math.abs(mCSB_container[0].offsetLeft)-(clickDir*(wrapper.width()*0.9)); - }else{ - if(!d.overflowed[0]){return;} - var dir="y", - clickDir=e.pageY>mCSB_dragger.offset().top ? -1 : 1, - to=Math.abs(mCSB_container[0].offsetTop)-(clickDir*(wrapper.height()*0.9)); - } - _scrollTo($this,to.toString(),{dir:dir,scrollEasing:"mcsEaseInOut"}); - } - }); - }, - /* -------------------- */ - - - /* - FOCUS EVENT - scrolls content via element focus (e.g. clicking an input, pressing TAB key etc.) - */ - _focus=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - namespace=pluginPfx+"_"+d.idx, - mCSB_container=$("#mCSB_"+d.idx+"_container"), - wrapper=mCSB_container.parent(); - mCSB_container.bind("focusin."+namespace,function(e){ - var el=$(document.activeElement), - nested=mCSB_container.find(".mCustomScrollBox").length, - dur=0; - if(!el.is(o.advanced.autoScrollOnFocus)){return;} - _stop($this); - clearTimeout($this[0]._focusTimeout); - $this[0]._focusTimer=nested ? (dur+17)*nested : 0; - $this[0]._focusTimeout=setTimeout(function(){ - var to=[_childPos(el)[0],_childPos(el)[1]], - contentPos=[mCSB_container[0].offsetTop,mCSB_container[0].offsetLeft], - isVisible=[ - (contentPos[0]+to[0]>=0 && contentPos[0]+to[0]=0 && contentPos[0]+to[1]a"); - btn.bind("contextmenu."+namespace,function(e){ - e.preventDefault(); //prevent right click - }).bind("mousedown."+namespace+" touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace+" mouseup."+namespace+" touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace+" mouseout."+namespace+" pointerout."+namespace+" MSPointerOut."+namespace+" click."+namespace,function(e){ - e.preventDefault(); - if(!_mouseBtnLeft(e)){return;} /* left mouse button only */ - var btnClass=$(this).attr("class"); - seq.type=o.scrollButtons.scrollType; - switch(e.type){ - case "mousedown": case "touchstart": case "pointerdown": case "MSPointerDown": - if(seq.type==="stepped"){return;} - touchActive=true; - d.tweenRunning=false; - _seq("on",btnClass); - break; - case "mouseup": case "touchend": case "pointerup": case "MSPointerUp": - case "mouseout": case "pointerout": case "MSPointerOut": - if(seq.type==="stepped"){return;} - touchActive=false; - if(seq.dir){_seq("off",btnClass);} - break; - case "click": - if(seq.type!=="stepped" || d.tweenRunning){return;} - _seq("on",btnClass); - break; - } - function _seq(a,c){ - seq.scrollAmount=o.scrollButtons.scrollAmount; - _sequentialScroll($this,a,c); - } - }); - }, - /* -------------------- */ - - - /* - KEYBOARD EVENTS - scrolls content via keyboard - Keys: up arrow, down arrow, left arrow, right arrow, PgUp, PgDn, Home, End - */ - _keyboard=function(){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt,seq=d.sequential, - namespace=pluginPfx+"_"+d.idx, - mCustomScrollBox=$("#mCSB_"+d.idx), - mCSB_container=$("#mCSB_"+d.idx+"_container"), - wrapper=mCSB_container.parent(), - editables="input,textarea,select,datalist,keygen,[contenteditable='true']", - iframe=mCSB_container.find("iframe"), - events=["blur."+namespace+" keydown."+namespace+" keyup."+namespace]; - if(iframe.length){ - iframe.each(function(){ - $(this).bind("load",function(){ - /* bind events on accessible iframes */ - if(_canAccessIFrame(this)){ - $(this.contentDocument || this.contentWindow.document).bind(events[0],function(e){ - _onKeyboard(e); - }); - } - }); - }); - } - mCustomScrollBox.attr("tabindex","0").bind(events[0],function(e){ - _onKeyboard(e); - }); - function _onKeyboard(e){ - switch(e.type){ - case "blur": - if(d.tweenRunning && seq.dir){_seq("off",null);} - break; - case "keydown": case "keyup": - var code=e.keyCode ? e.keyCode : e.which,action="on"; - if((o.axis!=="x" && (code===38 || code===40)) || (o.axis!=="y" && (code===37 || code===39))){ - /* up (38), down (40), left (37), right (39) arrows */ - if(((code===38 || code===40) && !d.overflowed[0]) || ((code===37 || code===39) && !d.overflowed[1])){return;} - if(e.type==="keyup"){action="off";} - if(!$(document.activeElement).is(editables)){ - e.preventDefault(); - e.stopImmediatePropagation(); - _seq(action,code); - } - }else if(code===33 || code===34){ - /* PgUp (33), PgDn (34) */ - if(d.overflowed[0] || d.overflowed[1]){ - e.preventDefault(); - e.stopImmediatePropagation(); - } - if(e.type==="keyup"){ - _stop($this); - var keyboardDir=code===34 ? -1 : 1; - if(o.axis==="x" || (o.axis==="yx" && d.overflowed[1] && !d.overflowed[0])){ - var dir="x",to=Math.abs(mCSB_container[0].offsetLeft)-(keyboardDir*(wrapper.width()*0.9)); - }else{ - var dir="y",to=Math.abs(mCSB_container[0].offsetTop)-(keyboardDir*(wrapper.height()*0.9)); - } - _scrollTo($this,to.toString(),{dir:dir,scrollEasing:"mcsEaseInOut"}); - } - }else if(code===35 || code===36){ - /* End (35), Home (36) */ - if(!$(document.activeElement).is(editables)){ - if(d.overflowed[0] || d.overflowed[1]){ - e.preventDefault(); - e.stopImmediatePropagation(); - } - if(e.type==="keyup"){ - if(o.axis==="x" || (o.axis==="yx" && d.overflowed[1] && !d.overflowed[0])){ - var dir="x",to=code===35 ? Math.abs(wrapper.width()-mCSB_container.outerWidth(false)) : 0; - }else{ - var dir="y",to=code===35 ? Math.abs(wrapper.height()-mCSB_container.outerHeight(false)) : 0; - } - _scrollTo($this,to.toString(),{dir:dir,scrollEasing:"mcsEaseInOut"}); - } - } - } - break; - } - function _seq(a,c){ - seq.type=o.keyboard.scrollType; - seq.scrollAmount=o.keyboard.scrollAmount; - if(seq.type==="stepped" && d.tweenRunning){return;} - _sequentialScroll($this,a,c); - } - } - }, - /* -------------------- */ - - - /* scrolls content sequentially (used when scrolling via buttons, keyboard arrows etc.) */ - _sequentialScroll=function(el,action,trigger,e,s){ - var d=el.data(pluginPfx),o=d.opt,seq=d.sequential, - mCSB_container=$("#mCSB_"+d.idx+"_container"), - once=seq.type==="stepped" ? true : false, - steplessSpeed=o.scrollInertia < 26 ? 26 : o.scrollInertia, /* 26/1.5=17 */ - steppedSpeed=o.scrollInertia < 1 ? 17 : o.scrollInertia; - switch(action){ - case "on": - seq.dir=[ - (trigger===classes[16] || trigger===classes[15] || trigger===39 || trigger===37 ? "x" : "y"), - (trigger===classes[13] || trigger===classes[15] || trigger===38 || trigger===37 ? -1 : 1) - ]; - _stop(el); - if(_isNumeric(trigger) && seq.type==="stepped"){return;} - _on(once); - break; - case "off": - _off(); - if(once || (d.tweenRunning && seq.dir)){ - _on(true); - } - break; - } - - /* starts sequence */ - function _on(once){ - if(o.snapAmount){seq.scrollAmount=!(o.snapAmount instanceof Array) ? o.snapAmount : seq.dir[0]==="x" ? o.snapAmount[1] : o.snapAmount[0];} /* scrolling snapping */ - var c=seq.type!=="stepped", /* continuous scrolling */ - t=s ? s : !once ? 1000/60 : c ? steplessSpeed/1.5 : steppedSpeed, /* timer */ - m=!once ? 2.5 : c ? 7.5 : 40, /* multiplier */ - contentPos=[Math.abs(mCSB_container[0].offsetTop),Math.abs(mCSB_container[0].offsetLeft)], - ratio=[d.scrollRatio.y>10 ? 10 : d.scrollRatio.y,d.scrollRatio.x>10 ? 10 : d.scrollRatio.x], - amount=seq.dir[0]==="x" ? contentPos[1]+(seq.dir[1]*(ratio[1]*m)) : contentPos[0]+(seq.dir[1]*(ratio[0]*m)), - px=seq.dir[0]==="x" ? contentPos[1]+(seq.dir[1]*parseInt(seq.scrollAmount)) : contentPos[0]+(seq.dir[1]*parseInt(seq.scrollAmount)), - to=seq.scrollAmount!=="auto" ? px : amount, - easing=e ? e : !once ? "mcsLinear" : c ? "mcsLinearOut" : "mcsEaseInOut", - onComplete=!once ? false : true; - if(once && t<17){ - to=seq.dir[0]==="x" ? contentPos[1] : contentPos[0]; - } - _scrollTo(el,to.toString(),{dir:seq.dir[0],scrollEasing:easing,dur:t,onComplete:onComplete}); - if(once){ - seq.dir=false; - return; - } - clearTimeout(seq.step); - seq.step=setTimeout(function(){ - _on(); - },t); - } - /* stops sequence */ - function _off(){ - clearTimeout(seq.step); - _delete(seq,"step"); - _stop(el); - } - }, - /* -------------------- */ - - - /* returns a yx array from value */ - _arr=function(val){ - var o=$(this).data(pluginPfx).opt,vals=[]; - if(typeof val==="function"){val=val();} /* check if the value is a single anonymous function */ - /* check if value is object or array, its length and create an array with yx values */ - if(!(val instanceof Array)){ /* object value (e.g. {y:"100",x:"100"}, 100 etc.) */ - vals[0]=val.y ? val.y : val.x || o.axis==="x" ? null : val; - vals[1]=val.x ? val.x : val.y || o.axis==="y" ? null : val; - }else{ /* array value (e.g. [100,100]) */ - vals=val.length>1 ? [val[0],val[1]] : o.axis==="x" ? [null,val[0]] : [val[0],null]; - } - /* check if array values are anonymous functions */ - if(typeof vals[0]==="function"){vals[0]=vals[0]();} - if(typeof vals[1]==="function"){vals[1]=vals[1]();} - return vals; - }, - /* -------------------- */ - - - /* translates values (e.g. "top", 100, "100px", "#id") to actual scroll-to positions */ - _to=function(val,dir){ - if(val==null || typeof val=="undefined"){return;} - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - mCSB_container=$("#mCSB_"+d.idx+"_container"), - wrapper=mCSB_container.parent(), - t=typeof val; - if(!dir){dir=o.axis==="x" ? "x" : "y";} - var contentLength=dir==="x" ? mCSB_container.outerWidth(false)-wrapper.width() : mCSB_container.outerHeight(false)-wrapper.height(), - contentPos=dir==="x" ? mCSB_container[0].offsetLeft : mCSB_container[0].offsetTop, - cssProp=dir==="x" ? "left" : "top"; - switch(t){ - case "function": /* this currently is not used. Consider removing it */ - return val(); - break; - case "object": /* js/jquery object */ - var obj=val.jquery ? val : $(val); - if(!obj.length){return;} - return dir==="x" ? _childPos(obj)[1] : _childPos(obj)[0]; - break; - case "string": case "number": - if(_isNumeric(val)){ /* numeric value */ - return Math.abs(val); - }else if(val.indexOf("%")!==-1){ /* percentage value */ - return Math.abs(contentLength*parseInt(val)/100); - }else if(val.indexOf("-=")!==-1){ /* decrease value */ - return Math.abs(contentPos-parseInt(val.split("-=")[1])); - }else if(val.indexOf("+=")!==-1){ /* inrease value */ - var p=(contentPos+parseInt(val.split("+=")[1])); - return p>=0 ? 0 : Math.abs(p); - }else if(val.indexOf("px")!==-1 && _isNumeric(val.split("px")[0])){ /* pixels string value (e.g. "100px") */ - return Math.abs(val.split("px")[0]); - }else{ - if(val==="top" || val==="left"){ /* special strings */ - return 0; - }else if(val==="bottom"){ - return Math.abs(wrapper.height()-mCSB_container.outerHeight(false)); - }else if(val==="right"){ - return Math.abs(wrapper.width()-mCSB_container.outerWidth(false)); - }else if(val==="first" || val==="last"){ - var obj=mCSB_container.find(":"+val); - return dir==="x" ? _childPos(obj)[1] : _childPos(obj)[0]; - }else{ - if($(val).length){ /* jquery selector */ - return dir==="x" ? _childPos($(val))[1] : _childPos($(val))[0]; - }else{ /* other values (e.g. "100em") */ - mCSB_container.css(cssProp,val); - methods.update.call(null,$this[0]); - return; - } - } - } - break; - } - }, - /* -------------------- */ - - - /* calls the update method automatically */ - _autoUpdate=function(rem){ - var $this=$(this),d=$this.data(pluginPfx),o=d.opt, - mCSB_container=$("#mCSB_"+d.idx+"_container"); - if(rem){ - /* - removes autoUpdate timer - usage: _autoUpdate.call(this,"remove"); - */ - clearTimeout(mCSB_container[0].autoUpdate); - _delete(mCSB_container[0],"autoUpdate"); - return; - } - upd(); - function upd(){ - clearTimeout(mCSB_container[0].autoUpdate); - if($this.parents("html").length===0){ - /* check element in dom tree */ - $this=null; - return; - } - mCSB_container[0].autoUpdate=setTimeout(function(){ - /* update on specific selector(s) length and size change */ - if(o.advanced.updateOnSelectorChange){ - d.poll.change.n=sizesSum(); - if(d.poll.change.n!==d.poll.change.o){ - d.poll.change.o=d.poll.change.n; - doUpd(3); - return; - } - } - /* update on main element and scrollbar size changes */ - if(o.advanced.updateOnContentResize){ - d.poll.size.n=$this[0].scrollHeight+$this[0].scrollWidth+mCSB_container[0].offsetHeight+$this[0].offsetHeight+$this[0].offsetWidth; - if(d.poll.size.n!==d.poll.size.o){ - d.poll.size.o=d.poll.size.n; - doUpd(1); - return; - } - } - /* update on image load */ - if(o.advanced.updateOnImageLoad){ - if(!(o.advanced.updateOnImageLoad==="auto" && o.axis==="y")){ //by default, it doesn't run on vertical content - d.poll.img.n=mCSB_container.find("img").length; - if(d.poll.img.n!==d.poll.img.o){ - d.poll.img.o=d.poll.img.n; - mCSB_container.find("img").each(function(){ - imgLoader(this); - }); - return; - } - } - } - if(o.advanced.updateOnSelectorChange || o.advanced.updateOnContentResize || o.advanced.updateOnImageLoad){upd();} - },o.advanced.autoUpdateTimeout); - } - /* a tiny image loader */ - function imgLoader(el){ - if($(el).hasClass(classes[2])){doUpd(); return;} - var img=new Image(); - function createDelegate(contextObject,delegateMethod){ - return function(){return delegateMethod.apply(contextObject,arguments);} - } - function imgOnLoad(){ - this.onload=null; - $(el).addClass(classes[2]); - doUpd(2); - } - img.onload=createDelegate(img,imgOnLoad); - img.src=el.src; - } - /* returns the total height and width sum of all elements matching the selector */ - function sizesSum(){ - if(o.advanced.updateOnSelectorChange===true){o.advanced.updateOnSelectorChange="*";} - var total=0,sel=mCSB_container.find(o.advanced.updateOnSelectorChange); - if(o.advanced.updateOnSelectorChange && sel.length>0){sel.each(function(){total+=this.offsetHeight+this.offsetWidth;});} - return total; - } - /* calls the update method */ - function doUpd(cb){ - clearTimeout(mCSB_container[0].autoUpdate); - methods.update.call(null,$this[0],cb); - } - }, - /* -------------------- */ - - - /* snaps scrolling to a multiple of a pixels number */ - _snapAmount=function(to,amount,offset){ - return (Math.round(to/amount)*amount-offset); - }, - /* -------------------- */ - - - /* stops content and scrollbar animations */ - _stop=function(el){ - var d=el.data(pluginPfx), - sel=$("#mCSB_"+d.idx+"_container,#mCSB_"+d.idx+"_container_wrapper,#mCSB_"+d.idx+"_dragger_vertical,#mCSB_"+d.idx+"_dragger_horizontal"); - sel.each(function(){ - _stopTween.call(this); - }); - }, - /* -------------------- */ - - - /* - ANIMATES CONTENT - This is where the actual scrolling happens - */ - _scrollTo=function(el,to,options){ - var d=el.data(pluginPfx),o=d.opt, - defaults={ - trigger:"internal", - dir:"y", - scrollEasing:"mcsEaseOut", - drag:false, - dur:o.scrollInertia, - overwrite:"all", - callbacks:true, - onStart:true, - onUpdate:true, - onComplete:true - }, - options=$.extend(defaults,options), - dur=[options.dur,(options.drag ? 0 : options.dur)], - mCustomScrollBox=$("#mCSB_"+d.idx), - mCSB_container=$("#mCSB_"+d.idx+"_container"), - wrapper=mCSB_container.parent(), - totalScrollOffsets=o.callbacks.onTotalScrollOffset ? _arr.call(el,o.callbacks.onTotalScrollOffset) : [0,0], - totalScrollBackOffsets=o.callbacks.onTotalScrollBackOffset ? _arr.call(el,o.callbacks.onTotalScrollBackOffset) : [0,0]; - d.trigger=options.trigger; - if(wrapper.scrollTop()!==0 || wrapper.scrollLeft()!==0){ /* always reset scrollTop/Left */ - $(".mCSB_"+d.idx+"_scrollbar").css("visibility","visible"); - wrapper.scrollTop(0).scrollLeft(0); - } - if(to==="_resetY" && !d.contentReset.y){ - /* callbacks: onOverflowYNone */ - if(_cb("onOverflowYNone")){o.callbacks.onOverflowYNone.call(el[0]);} - d.contentReset.y=1; - } - if(to==="_resetX" && !d.contentReset.x){ - /* callbacks: onOverflowXNone */ - if(_cb("onOverflowXNone")){o.callbacks.onOverflowXNone.call(el[0]);} - d.contentReset.x=1; - } - if(to==="_resetY" || to==="_resetX"){return;} - if((d.contentReset.y || !el[0].mcs) && d.overflowed[0]){ - /* callbacks: onOverflowY */ - if(_cb("onOverflowY")){o.callbacks.onOverflowY.call(el[0]);} - d.contentReset.x=null; - } - if((d.contentReset.x || !el[0].mcs) && d.overflowed[1]){ - /* callbacks: onOverflowX */ - if(_cb("onOverflowX")){o.callbacks.onOverflowX.call(el[0]);} - d.contentReset.x=null; - } - if(o.snapAmount){ /* scrolling snapping */ - var snapAmount=!(o.snapAmount instanceof Array) ? o.snapAmount : options.dir==="x" ? o.snapAmount[1] : o.snapAmount[0]; - to=_snapAmount(to,snapAmount,o.snapOffset); - } - switch(options.dir){ - case "x": - var mCSB_dragger=$("#mCSB_"+d.idx+"_dragger_horizontal"), - property="left", - contentPos=mCSB_container[0].offsetLeft, - limit=[ - mCustomScrollBox.width()-mCSB_container.outerWidth(false), - mCSB_dragger.parent().width()-mCSB_dragger.width() - ], - scrollTo=[to,to===0 ? 0 : (to/d.scrollRatio.x)], - tso=totalScrollOffsets[1], - tsbo=totalScrollBackOffsets[1], - totalScrollOffset=tso>0 ? tso/d.scrollRatio.x : 0, - totalScrollBackOffset=tsbo>0 ? tsbo/d.scrollRatio.x : 0; - break; - case "y": - var mCSB_dragger=$("#mCSB_"+d.idx+"_dragger_vertical"), - property="top", - contentPos=mCSB_container[0].offsetTop, - limit=[ - mCustomScrollBox.height()-mCSB_container.outerHeight(false), - mCSB_dragger.parent().height()-mCSB_dragger.height() - ], - scrollTo=[to,to===0 ? 0 : (to/d.scrollRatio.y)], - tso=totalScrollOffsets[0], - tsbo=totalScrollBackOffsets[0], - totalScrollOffset=tso>0 ? tso/d.scrollRatio.y : 0, - totalScrollBackOffset=tsbo>0 ? tsbo/d.scrollRatio.y : 0; - break; - } - if(scrollTo[1]<0 || (scrollTo[0]===0 && scrollTo[1]===0)){ - scrollTo=[0,0]; - }else if(scrollTo[1]>=limit[1]){ - scrollTo=[limit[0],limit[1]]; - }else{ - scrollTo[0]=-scrollTo[0]; - } - if(!el[0].mcs){ - _mcs(); /* init mcs object (once) to make it available before callbacks */ - if(_cb("onInit")){o.callbacks.onInit.call(el[0]);} /* callbacks: onInit */ - } - clearTimeout(mCSB_container[0].onCompleteTimeout); - _tweenTo(mCSB_dragger[0],property,Math.round(scrollTo[1]),dur[1],options.scrollEasing); - if(!d.tweenRunning && ((contentPos===0 && scrollTo[0]>=0) || (contentPos===limit[0] && scrollTo[0]<=limit[0]))){return;} - _tweenTo(mCSB_container[0],property,Math.round(scrollTo[0]),dur[0],options.scrollEasing,options.overwrite,{ - onStart:function(){ - if(options.callbacks && options.onStart && !d.tweenRunning){ - /* callbacks: onScrollStart */ - if(_cb("onScrollStart")){_mcs(); o.callbacks.onScrollStart.call(el[0]);} - d.tweenRunning=true; - _onDragClasses(mCSB_dragger); - d.cbOffsets=_cbOffsets(); - } - },onUpdate:function(){ - if(options.callbacks && options.onUpdate){ - /* callbacks: whileScrolling */ - if(_cb("whileScrolling")){_mcs(); o.callbacks.whileScrolling.call(el[0]);} - } - },onComplete:function(){ - if(options.callbacks && options.onComplete){ - if(o.axis==="yx"){clearTimeout(mCSB_container[0].onCompleteTimeout);} - var t=mCSB_container[0].idleTimer || 0; - mCSB_container[0].onCompleteTimeout=setTimeout(function(){ - /* callbacks: onScroll, onTotalScroll, onTotalScrollBack */ - if(_cb("onScroll")){_mcs(); o.callbacks.onScroll.call(el[0]);} - if(_cb("onTotalScroll") && scrollTo[1]>=limit[1]-totalScrollOffset && d.cbOffsets[0]){_mcs(); o.callbacks.onTotalScroll.call(el[0]);} - if(_cb("onTotalScrollBack") && scrollTo[1]<=totalScrollBackOffset && d.cbOffsets[1]){_mcs(); o.callbacks.onTotalScrollBack.call(el[0]);} - d.tweenRunning=false; - mCSB_container[0].idleTimer=0; - _onDragClasses(mCSB_dragger,"hide"); - },t); - } - } - }); - /* checks if callback function exists */ - function _cb(cb){ - return d && o.callbacks[cb] && typeof o.callbacks[cb]==="function"; - } - /* checks whether callback offsets always trigger */ - function _cbOffsets(){ - return [o.callbacks.alwaysTriggerOffsets || contentPos>=limit[0]+tso,o.callbacks.alwaysTriggerOffsets || contentPos<=-tsbo]; - } - /* - populates object with useful values for the user - values: - content: this.mcs.content - content top position: this.mcs.top - content left position: this.mcs.left - dragger top position: this.mcs.draggerTop - dragger left position: this.mcs.draggerLeft - scrolling y percentage: this.mcs.topPct - scrolling x percentage: this.mcs.leftPct - scrolling direction: this.mcs.direction - */ - function _mcs(){ - var cp=[mCSB_container[0].offsetTop,mCSB_container[0].offsetLeft], /* content position */ - dp=[mCSB_dragger[0].offsetTop,mCSB_dragger[0].offsetLeft], /* dragger position */ - cl=[mCSB_container.outerHeight(false),mCSB_container.outerWidth(false)], /* content length */ - pl=[mCustomScrollBox.height(),mCustomScrollBox.width()]; /* content parent length */ - el[0].mcs={ - content:mCSB_container, /* original content wrapper as jquery object */ - top:cp[0],left:cp[1],draggerTop:dp[0],draggerLeft:dp[1], - topPct:Math.round((100*Math.abs(cp[0]))/(Math.abs(cl[0])-pl[0])),leftPct:Math.round((100*Math.abs(cp[1]))/(Math.abs(cl[1])-pl[1])), - direction:options.dir - }; - /* - this refers to the original element containing the scrollbar(s) - usage: this.mcs.top, this.mcs.leftPct etc. - */ - } - }, - /* -------------------- */ - - - /* - CUSTOM JAVASCRIPT ANIMATION TWEEN - Lighter and faster than jquery animate() and css transitions - Animates top/left properties and includes easings - */ - _tweenTo=function(el,prop,to,duration,easing,overwrite,callbacks){ - if(!el._mTween){el._mTween={top:{},left:{}};} - var callbacks=callbacks || {}, - onStart=callbacks.onStart || function(){},onUpdate=callbacks.onUpdate || function(){},onComplete=callbacks.onComplete || function(){}, - startTime=_getTime(),_delay,progress=0,from=el.offsetTop,elStyle=el.style,_request,tobj=el._mTween[prop]; - if(prop==="left"){from=el.offsetLeft;} - var diff=to-from; - tobj.stop=0; - if(overwrite!=="none"){_cancelTween();} - _startTween(); - function _step(){ - if(tobj.stop){return;} - if(!progress){onStart.call();} - progress=_getTime()-startTime; - _tween(); - if(progress>=tobj.time){ - tobj.time=(progress>tobj.time) ? progress+_delay-(progress-tobj.time) : progress+_delay-1; - if(tobj.time0){ - tobj.currVal=_ease(tobj.time,from,diff,duration,easing); - elStyle[prop]=Math.round(tobj.currVal)+"px"; - }else{ - elStyle[prop]=to+"px"; - } - onUpdate.call(); - } - function _startTween(){ - _delay=1000/60; - tobj.time=progress+_delay; - _request=(!window.requestAnimationFrame) ? function(f){_tween(); return setTimeout(f,0.01);} : window.requestAnimationFrame; - tobj.id=_request(_step); - } - function _cancelTween(){ - if(tobj.id==null){return;} - if(!window.requestAnimationFrame){clearTimeout(tobj.id); - }else{window.cancelAnimationFrame(tobj.id);} - tobj.id=null; - } - function _ease(t,b,c,d,type){ - switch(type){ - case "linear": case "mcsLinear": - return c*t/d + b; - break; - case "mcsLinearOut": - t/=d; t--; return c * Math.sqrt(1 - t*t) + b; - break; - case "easeInOutSmooth": - t/=d/2; - if(t<1) return c/2*t*t + b; - t--; - return -c/2 * (t*(t-2) - 1) + b; - break; - case "easeInOutStrong": - t/=d/2; - if(t<1) return c/2 * Math.pow( 2, 10 * (t - 1) ) + b; - t--; - return c/2 * ( -Math.pow( 2, -10 * t) + 2 ) + b; - break; - case "easeInOut": case "mcsEaseInOut": - t/=d/2; - if(t<1) return c/2*t*t*t + b; - t-=2; - return c/2*(t*t*t + 2) + b; - break; - case "easeOutSmooth": - t/=d; t--; - return -c * (t*t*t*t - 1) + b; - break; - case "easeOutStrong": - return c * ( -Math.pow( 2, -10 * t/d ) + 1 ) + b; - break; - case "easeOut": case "mcsEaseOut": default: - var ts=(t/=d)*t,tc=ts*t; - return b+c*(0.499999999999997*tc*ts + -2.5*ts*ts + 5.5*tc + -6.5*ts + 4*t); - } - } - }, - /* -------------------- */ - - - /* returns current time */ - _getTime=function(){ - if(window.performance && window.performance.now){ - return window.performance.now(); - }else{ - if(window.performance && window.performance.webkitNow){ - return window.performance.webkitNow(); - }else{ - if(Date.now){return Date.now();}else{return new Date().getTime();} - } - } - }, - /* -------------------- */ - - - /* stops a tween */ - _stopTween=function(){ - var el=this; - if(!el._mTween){el._mTween={top:{},left:{}};} - var props=["top","left"]; - for(var i=0; i
","
"], + wrapperClass=o.axis==="yx" ? "mCSB_vertical_horizontal" : o.axis==="x" ? "mCSB_horizontal" : "mCSB_vertical", + scrollbars=o.axis==="yx" ? scrollbar[0]+scrollbar[1] : o.axis==="x" ? scrollbar[1] : scrollbar[0], + contentWrapper=o.axis==="yx" ? "
" : "", + autoHideClass=o.autoHideScrollbar ? " "+classes[6] : "", + scrollbarDirClass=(o.axis!=="x" && d.langDir==="rtl") ? " "+classes[7] : ""; + if(o.setWidth){$this.css("width",o.setWidth);} /* set element width */ + if(o.setHeight){$this.css("height",o.setHeight);} /* set element height */ + o.setLeft=(o.axis!=="y" && d.langDir==="rtl") ? "989999px" : o.setLeft; /* adjust left position for rtl direction */ + $this.addClass(pluginNS+" _"+pluginPfx+"_"+d.idx+autoHideClass+scrollbarDirClass).wrapInner("
"); + var mCustomScrollBox=$("#mCSB_"+d.idx), + mCSB_container=$("#mCSB_"+d.idx+"_container"); + if(o.axis!=="y" && !o.advanced.autoExpandHorizontalScroll){ + mCSB_container.css("width",_contentWidth(mCSB_container)); + } + if(o.scrollbarPosition==="outside"){ + if($this.css("position")==="static"){ /* requires elements with non-static position */ + $this.css("position","relative"); + } + $this.css("overflow","visible"); + mCustomScrollBox.addClass("mCSB_outside").after(scrollbars); + }else{ + mCustomScrollBox.addClass("mCSB_inside").append(scrollbars); + mCSB_container.wrap(contentWrapper); + } + _scrollButtons.call(this); /* add scrollbar buttons */ + /* minimum dragger length */ + var mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")]; + mCSB_dragger[0].css("min-height",mCSB_dragger[0].height()); + mCSB_dragger[1].css("min-width",mCSB_dragger[1].width()); + }, + /* -------------------- */ + + + /* calculates content width */ + _contentWidth=function(el){ + var val=[el[0].scrollWidth,Math.max.apply(Math,el.children().map(function(){return $(this).outerWidth(true);}).get())],w=el.parent().width(); + return val[0]>w ? val[0] : val[1]>w ? val[1] : "100%"; + }, + /* -------------------- */ + + + /* expands content horizontally */ + _expandContentHorizontally=function(){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + mCSB_container=$("#mCSB_"+d.idx+"_container"); + if(o.advanced.autoExpandHorizontalScroll && o.axis!=="y"){ + /* calculate scrollWidth */ + mCSB_container.css({"width":"auto","min-width":0,"overflow-x":"scroll"}); + var w=Math.ceil(mCSB_container[0].scrollWidth); + if(o.advanced.autoExpandHorizontalScroll===3 || (o.advanced.autoExpandHorizontalScroll!==2 && w>mCSB_container.parent().width())){ + mCSB_container.css({"width":w,"min-width":"100%","overflow-x":"inherit"}); + }else{ + /* + wrap content with an infinite width div and set its position to absolute and width to auto. + Setting width to auto before calculating the actual width is important! + We must let the browser set the width as browser zoom values are impossible to calculate. + */ + mCSB_container.css({"overflow-x":"inherit","position":"absolute"}) + .wrap("
") + .css({ /* set actual width, original position and un-wrap */ + /* + get the exact width (with decimals) and then round-up. + Using jquery outerWidth() will round the width value which will mess up with inner elements that have non-integer width + */ + "width":(Math.ceil(mCSB_container[0].getBoundingClientRect().right+0.4)-Math.floor(mCSB_container[0].getBoundingClientRect().left)), + "min-width":"100%", + "position":"relative" + }).unwrap(); + } + } + }, + /* -------------------- */ + + + /* adds scrollbar buttons */ + _scrollButtons=function(){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + mCSB_scrollTools=$(".mCSB_"+d.idx+"_scrollbar:first"), + tabindex=!_isNumeric(o.scrollButtons.tabindex) ? "" : "tabindex='"+o.scrollButtons.tabindex+"'", + btnHTML=[ + "", + "", + "", + "" + ], + btn=[(o.axis==="x" ? btnHTML[2] : btnHTML[0]),(o.axis==="x" ? btnHTML[3] : btnHTML[1]),btnHTML[2],btnHTML[3]]; + if(o.scrollButtons.enable){ + mCSB_scrollTools.prepend(btn[0]).append(btn[1]).next(".mCSB_scrollTools").prepend(btn[2]).append(btn[3]); + } + }, + /* -------------------- */ + + + /* auto-adjusts scrollbar dragger length */ + _setDraggerLength=function(){ + var $this=$(this),d=$this.data(pluginPfx), + mCustomScrollBox=$("#mCSB_"+d.idx), + mCSB_container=$("#mCSB_"+d.idx+"_container"), + mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")], + ratio=[mCustomScrollBox.height()/mCSB_container.outerHeight(false),mCustomScrollBox.width()/mCSB_container.outerWidth(false)], + l=[ + parseInt(mCSB_dragger[0].css("min-height")),Math.round(ratio[0]*mCSB_dragger[0].parent().height()), + parseInt(mCSB_dragger[1].css("min-width")),Math.round(ratio[1]*mCSB_dragger[1].parent().width()) + ], + h=oldIE && (l[1]contentHeight){contentHeight=h;} + if(w>contentWidth){contentWidth=w;} + return [contentHeight>mCustomScrollBox.height(),contentWidth>mCustomScrollBox.width()]; + }, + /* -------------------- */ + + + /* resets content position to 0 */ + _resetContentPosition=function(){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + mCustomScrollBox=$("#mCSB_"+d.idx), + mCSB_container=$("#mCSB_"+d.idx+"_container"), + mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")]; + _stop($this); /* stop any current scrolling before resetting */ + if((o.axis!=="x" && !d.overflowed[0]) || (o.axis==="y" && d.overflowed[0])){ /* reset y */ + mCSB_dragger[0].add(mCSB_container).css("top",0); + _scrollTo($this,"_resetY"); + } + if((o.axis!=="y" && !d.overflowed[1]) || (o.axis==="x" && d.overflowed[1])){ /* reset x */ + var cx=dx=0; + if(d.langDir==="rtl"){ /* adjust left position for rtl direction */ + cx=mCustomScrollBox.width()-mCSB_container.outerWidth(false); + dx=Math.abs(cx/d.scrollRatio.x); + } + mCSB_container.css("left",cx); + mCSB_dragger[1].css("left",dx); + _scrollTo($this,"_resetX"); + } + }, + /* -------------------- */ + + + /* binds scrollbar events */ + _bindEvents=function(){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt; + if(!d.bindEvents){ /* check if events are already bound */ + _draggable.call(this); + if(o.contentTouchScroll){_contentDraggable.call(this);} + _selectable.call(this); + if(o.mouseWheel.enable){ /* bind mousewheel fn when plugin is available */ + function _mwt(){ + mousewheelTimeout=setTimeout(function(){ + if(!$.event.special.mousewheel){ + _mwt(); + }else{ + clearTimeout(mousewheelTimeout); + _mousewheel.call($this[0]); + } + },100); + } + var mousewheelTimeout; + _mwt(); + } + _draggerRail.call(this); + _wrapperScroll.call(this); + if(o.advanced.autoScrollOnFocus){_focus.call(this);} + if(o.scrollButtons.enable){_buttons.call(this);} + if(o.keyboard.enable){_keyboard.call(this);} + d.bindEvents=true; + } + }, + /* -------------------- */ + + + /* unbinds scrollbar events */ + _unbindEvents=function(){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + namespace=pluginPfx+"_"+d.idx, + sb=".mCSB_"+d.idx+"_scrollbar", + sel=$("#mCSB_"+d.idx+",#mCSB_"+d.idx+"_container,#mCSB_"+d.idx+"_container_wrapper,"+sb+" ."+classes[12]+",#mCSB_"+d.idx+"_dragger_vertical,#mCSB_"+d.idx+"_dragger_horizontal,"+sb+">a"), + mCSB_container=$("#mCSB_"+d.idx+"_container"); + if(o.advanced.releaseDraggableSelectors){sel.add($(o.advanced.releaseDraggableSelectors));} + if(o.advanced.extraDraggableSelectors){sel.add($(o.advanced.extraDraggableSelectors));} + if(d.bindEvents){ /* check if events are bound */ + /* unbind namespaced events from document/selectors */ + $(document).add($(!_canAccessIFrame() || top.document)).unbind("."+namespace); + sel.each(function(){ + $(this).unbind("."+namespace); + }); + /* clear and delete timeouts/objects */ + clearTimeout($this[0]._focusTimeout); _delete($this[0],"_focusTimeout"); + clearTimeout(d.sequential.step); _delete(d.sequential,"step"); + clearTimeout(mCSB_container[0].onCompleteTimeout); _delete(mCSB_container[0],"onCompleteTimeout"); + d.bindEvents=false; + } + }, + /* -------------------- */ + + + /* toggles scrollbar visibility */ + _scrollbarVisibility=function(disabled){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + contentWrapper=$("#mCSB_"+d.idx+"_container_wrapper"), + content=contentWrapper.length ? contentWrapper : $("#mCSB_"+d.idx+"_container"), + scrollbar=[$("#mCSB_"+d.idx+"_scrollbar_vertical"),$("#mCSB_"+d.idx+"_scrollbar_horizontal")], + mCSB_dragger=[scrollbar[0].find(".mCSB_dragger"),scrollbar[1].find(".mCSB_dragger")]; + if(o.axis!=="x"){ + if(d.overflowed[0] && !disabled){ + scrollbar[0].add(mCSB_dragger[0]).add(scrollbar[0].children("a")).css("display","block"); + content.removeClass(classes[8]+" "+classes[10]); + }else{ + if(o.alwaysShowScrollbar){ + if(o.alwaysShowScrollbar!==2){mCSB_dragger[0].css("display","none");} + content.removeClass(classes[10]); + }else{ + scrollbar[0].css("display","none"); + content.addClass(classes[10]); + } + content.addClass(classes[8]); + } + } + if(o.axis!=="y"){ + if(d.overflowed[1] && !disabled){ + scrollbar[1].add(mCSB_dragger[1]).add(scrollbar[1].children("a")).css("display","block"); + content.removeClass(classes[9]+" "+classes[11]); + }else{ + if(o.alwaysShowScrollbar){ + if(o.alwaysShowScrollbar!==2){mCSB_dragger[1].css("display","none");} + content.removeClass(classes[11]); + }else{ + scrollbar[1].css("display","none"); + content.addClass(classes[11]); + } + content.addClass(classes[9]); + } + } + if(!d.overflowed[0] && !d.overflowed[1]){ + $this.addClass(classes[5]); + }else{ + $this.removeClass(classes[5]); + } + }, + /* -------------------- */ + + + /* returns input coordinates of pointer, touch and mouse events (relative to document) */ + _coordinates=function(e){ + var t=e.type,o=e.target.ownerDocument!==document && frameElement!==null ? [$(frameElement).offset().top,$(frameElement).offset().left] : null, + io=_canAccessIFrame() && e.target.ownerDocument!==top.document && frameElement!==null ? [$(e.view.frameElement).offset().top,$(e.view.frameElement).offset().left] : [0,0]; + switch(t){ + case "pointerdown": case "MSPointerDown": case "pointermove": case "MSPointerMove": case "pointerup": case "MSPointerUp": + return o ? [e.originalEvent.pageY-o[0]+io[0],e.originalEvent.pageX-o[1]+io[1],false] : [e.originalEvent.pageY,e.originalEvent.pageX,false]; + break; + case "touchstart": case "touchmove": case "touchend": + var touch=e.originalEvent.touches[0] || e.originalEvent.changedTouches[0], + touches=e.originalEvent.touches.length || e.originalEvent.changedTouches.length; + return e.target.ownerDocument!==document ? [touch.screenY,touch.screenX,touches>1] : [touch.pageY,touch.pageX,touches>1]; + break; + default: + return o ? [e.pageY-o[0]+io[0],e.pageX-o[1]+io[1],false] : [e.pageY,e.pageX,false]; + } + }, + /* -------------------- */ + + + /* + SCROLLBAR DRAG EVENTS + scrolls content via scrollbar dragging + */ + _draggable=function(){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + namespace=pluginPfx+"_"+d.idx, + draggerId=["mCSB_"+d.idx+"_dragger_vertical","mCSB_"+d.idx+"_dragger_horizontal"], + mCSB_container=$("#mCSB_"+d.idx+"_container"), + mCSB_dragger=$("#"+draggerId[0]+",#"+draggerId[1]), + draggable,dragY,dragX, + rds=o.advanced.releaseDraggableSelectors ? mCSB_dragger.add($(o.advanced.releaseDraggableSelectors)) : mCSB_dragger, + eds=o.advanced.extraDraggableSelectors ? $(!_canAccessIFrame() || top.document).add($(o.advanced.extraDraggableSelectors)) : $(!_canAccessIFrame() || top.document); + mCSB_dragger.bind("contextmenu."+namespace,function(e){ + e.preventDefault(); //prevent right click + }).bind("mousedown."+namespace+" touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace,function(e){ + e.stopImmediatePropagation(); + e.preventDefault(); + if(!_mouseBtnLeft(e)){return;} /* left mouse button only */ + touchActive=true; + if(oldIE){document.onselectstart=function(){return false;}} /* disable text selection for IE < 9 */ + _iframe.call(mCSB_container,false); /* enable scrollbar dragging over iframes by disabling their events */ + _stop($this); + draggable=$(this); + var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left, + h=draggable.height()+offset.top,w=draggable.width()+offset.left; + if(y0 && x0){ + dragY=y; + dragX=x; + } + _onDragClasses(draggable,"active",o.autoExpandScrollbar); + }).bind("touchmove."+namespace,function(e){ + e.stopImmediatePropagation(); + e.preventDefault(); + var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left; + _drag(dragY,dragX,y,x); + }); + $(document).add(eds).bind("mousemove."+namespace+" pointermove."+namespace+" MSPointerMove."+namespace,function(e){ + if(draggable){ + var offset=draggable.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left; + if(dragY===y && dragX===x){return;} /* has it really moved? */ + _drag(dragY,dragX,y,x); + } + }).add(rds).bind("mouseup."+namespace+" touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace,function(e){ + if(draggable){ + _onDragClasses(draggable,"active",o.autoExpandScrollbar); + draggable=null; + } + touchActive=false; + if(oldIE){document.onselectstart=null;} /* enable text selection for IE < 9 */ + _iframe.call(mCSB_container,true); /* enable iframes events */ + }); + function _drag(dragY,dragX,y,x){ + mCSB_container[0].idleTimer=o.scrollInertia<233 ? 250 : 0; + if(draggable.attr("id")===draggerId[1]){ + var dir="x",to=((draggable[0].offsetLeft-dragX)+x)*d.scrollRatio.x; + }else{ + var dir="y",to=((draggable[0].offsetTop-dragY)+y)*d.scrollRatio.y; + } + _scrollTo($this,to.toString(),{dir:dir,drag:true}); + } + }, + /* -------------------- */ + + + /* + TOUCH SWIPE EVENTS + scrolls content via touch swipe + Emulates the native touch-swipe scrolling with momentum found in iOS, Android and WP devices + */ + _contentDraggable=function(){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + namespace=pluginPfx+"_"+d.idx, + mCustomScrollBox=$("#mCSB_"+d.idx), + mCSB_container=$("#mCSB_"+d.idx+"_container"), + mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")], + draggable,dragY,dragX,touchStartY,touchStartX,touchMoveY=[],touchMoveX=[],startTime,runningTime,endTime,distance,speed,amount, + durA=0,durB,overwrite=o.axis==="yx" ? "none" : "all",touchIntent=[],touchDrag,docDrag, + iframe=mCSB_container.find("iframe"), + events=[ + "touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace, //start + "touchmove."+namespace+" pointermove."+namespace+" MSPointerMove."+namespace, //move + "touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace //end + ], + touchAction=document.body.style.touchAction!==undefined && document.body.style.touchAction!==""; + mCSB_container.bind(events[0],function(e){ + _onTouchstart(e); + }).bind(events[1],function(e){ + _onTouchmove(e); + }); + mCustomScrollBox.bind(events[0],function(e){ + _onTouchstart2(e); + }).bind(events[2],function(e){ + _onTouchend(e); + }); + if(iframe.length){ + iframe.each(function(){ + $(this).bind("load",function(){ + /* bind events on accessible iframes */ + if(_canAccessIFrame(this)){ + $(this.contentDocument || this.contentWindow.document).bind(events[0],function(e){ + _onTouchstart(e); + _onTouchstart2(e); + }).bind(events[1],function(e){ + _onTouchmove(e); + }).bind(events[2],function(e){ + _onTouchend(e); + }); + } + }); + }); + } + function _onTouchstart(e){ + if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){touchable=0; return;} + touchable=1; touchDrag=0; docDrag=0; draggable=1; + $this.removeClass("mCS_touch_action"); + var offset=mCSB_container.offset(); + dragY=_coordinates(e)[0]-offset.top; + dragX=_coordinates(e)[1]-offset.left; + touchIntent=[_coordinates(e)[0],_coordinates(e)[1]]; + } + function _onTouchmove(e){ + if(!_pointerTouch(e) || touchActive || _coordinates(e)[2]){return;} + if(!o.documentTouchScroll){e.preventDefault();} + e.stopImmediatePropagation(); + if(docDrag && !touchDrag){return;} + if(draggable){ + runningTime=_getTime(); + var offset=mCustomScrollBox.offset(),y=_coordinates(e)[0]-offset.top,x=_coordinates(e)[1]-offset.left, + easing="mcsLinearOut"; + touchMoveY.push(y); + touchMoveX.push(x); + touchIntent[2]=Math.abs(_coordinates(e)[0]-touchIntent[0]); touchIntent[3]=Math.abs(_coordinates(e)[1]-touchIntent[1]); + if(d.overflowed[0]){ + var limit=mCSB_dragger[0].parent().height()-mCSB_dragger[0].height(), + prevent=((dragY-y)>0 && (y-dragY)>-(limit*d.scrollRatio.y) && (touchIntent[3]*20 && (x-dragX)>-(limitX*d.scrollRatio.x) && (touchIntent[2]*230){return;} + speed=1000/(endTime-startTime); + var easing="mcsEaseOut",slow=speed<2.5, + diff=slow ? [touchMoveY[touchMoveY.length-2],touchMoveX[touchMoveX.length-2]] : [0,0]; + distance=slow ? [(y-diff[0]),(x-diff[1])] : [y-touchStartY,x-touchStartX]; + var absDistance=[Math.abs(distance[0]),Math.abs(distance[1])]; + speed=slow ? [Math.abs(distance[0]/4),Math.abs(distance[1]/4)] : [speed,speed]; + var a=[ + Math.abs(mCSB_container[0].offsetTop)-(distance[0]*_m((absDistance[0]/speed[0]),speed[0])), + Math.abs(mCSB_container[0].offsetLeft)-(distance[1]*_m((absDistance[1]/speed[1]),speed[1])) + ]; + amount=o.axis==="yx" ? [a[0],a[1]] : o.axis==="x" ? [null,a[1]] : [a[0],null]; + durB=[(absDistance[0]*4)+o.scrollInertia,(absDistance[1]*4)+o.scrollInertia]; + var md=parseInt(o.contentTouchScroll) || 0; /* absolute minimum distance required */ + amount[0]=absDistance[0]>md ? amount[0] : 0; + amount[1]=absDistance[1]>md ? amount[1] : 0; + if(d.overflowed[0]){_drag(amount[0],durB[0],easing,"y",overwrite,false);} + if(d.overflowed[1]){_drag(amount[1],durB[1],easing,"x",overwrite,false);} + } + function _m(ds,s){ + var r=[s*1.5,s*2,s/1.5,s/2]; + if(ds>90){ + return s>4 ? r[0] : r[3]; + }else if(ds>60){ + return s>3 ? r[3] : r[2]; + }else if(ds>30){ + return s>8 ? r[1] : s>6 ? r[0] : s>4 ? s : r[2]; + }else{ + return s>8 ? s : r[3]; + } + } + function _drag(amount,dur,easing,dir,overwrite,drag){ + if(!amount){return;} + _scrollTo($this,amount.toString(),{dur:dur,scrollEasing:easing,dir:dir,overwrite:overwrite,drag:drag}); + } + }, + /* -------------------- */ + + + /* + SELECT TEXT EVENTS + scrolls content when text is selected + */ + _selectable=function(){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt,seq=d.sequential, + namespace=pluginPfx+"_"+d.idx, + mCSB_container=$("#mCSB_"+d.idx+"_container"), + wrapper=mCSB_container.parent(), + action; + mCSB_container.bind("mousedown."+namespace,function(e){ + if(touchable){return;} + if(!action){action=1; touchActive=true;} + }).add(document).bind("mousemove."+namespace,function(e){ + if(!touchable && action && _sel()){ + var offset=mCSB_container.offset(), + y=_coordinates(e)[0]-offset.top+mCSB_container[0].offsetTop,x=_coordinates(e)[1]-offset.left+mCSB_container[0].offsetLeft; + if(y>0 && y0 && xwrapper.height()){ + _seq("on",40); + } + } + if(o.axis!=="y" && d.overflowed[1]){ + if(x<0){ + _seq("on",37); + }else if(x>wrapper.width()){ + _seq("on",39); + } + } + } + } + }).bind("mouseup."+namespace+" dragend."+namespace,function(e){ + if(touchable){return;} + if(action){action=0; _seq("off",null);} + touchActive=false; + }); + function _sel(){ + return window.getSelection ? window.getSelection().toString() : + document.selection && document.selection.type!="Control" ? document.selection.createRange().text : 0; + } + function _seq(a,c,s){ + seq.type=s && action ? "stepped" : "stepless"; + seq.scrollAmount=10; + _sequentialScroll($this,a,c,"mcsLinearOut",s ? 60 : null); + } + }, + /* -------------------- */ + + + /* + MOUSE WHEEL EVENT + scrolls content via mouse-wheel + via mouse-wheel plugin (https://github.com/brandonaaron/jquery-mousewheel) + */ + _mousewheel=function(){ + if(!$(this).data(pluginPfx)){return;} /* Check if the scrollbar is ready to use mousewheel events (issue: #185) */ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + namespace=pluginPfx+"_"+d.idx, + mCustomScrollBox=$("#mCSB_"+d.idx), + mCSB_dragger=[$("#mCSB_"+d.idx+"_dragger_vertical"),$("#mCSB_"+d.idx+"_dragger_horizontal")], + iframe=$("#mCSB_"+d.idx+"_container").find("iframe"); + if(iframe.length){ + iframe.each(function(){ + $(this).bind("load",function(){ + /* bind events on accessible iframes */ + if(_canAccessIFrame(this)){ + $(this.contentDocument || this.contentWindow.document).bind("mousewheel."+namespace,function(e,delta){ + _onMousewheel(e,delta); + }); + } + }); + }); + } + mCustomScrollBox.bind("mousewheel."+namespace,function(e,delta){ + _onMousewheel(e,delta); + }); + function _onMousewheel(e,delta){ + _stop($this); + if(_disableMousewheel($this,e.target)){return;} /* disables mouse-wheel when hovering specific elements */ + var deltaFactor=o.mouseWheel.deltaFactor!=="auto" ? parseInt(o.mouseWheel.deltaFactor) : (oldIE && e.deltaFactor<100) ? 100 : e.deltaFactor || 100, + dur=o.scrollInertia; + if(o.axis==="x" || o.mouseWheel.axis==="x"){ + var dir="x", + px=[Math.round(deltaFactor*d.scrollRatio.x),parseInt(o.mouseWheel.scrollAmount)], + amount=o.mouseWheel.scrollAmount!=="auto" ? px[1] : px[0]>=mCustomScrollBox.width() ? mCustomScrollBox.width()*0.9 : px[0], + contentPos=Math.abs($("#mCSB_"+d.idx+"_container")[0].offsetLeft), + draggerPos=mCSB_dragger[1][0].offsetLeft, + limit=mCSB_dragger[1].parent().width()-mCSB_dragger[1].width(), + dlt=o.mouseWheel.axis==="y" ? (e.deltaY || delta) : e.deltaX; + }else{ + var dir="y", + px=[Math.round(deltaFactor*d.scrollRatio.y),parseInt(o.mouseWheel.scrollAmount)], + amount=o.mouseWheel.scrollAmount!=="auto" ? px[1] : px[0]>=mCustomScrollBox.height() ? mCustomScrollBox.height()*0.9 : px[0], + contentPos=Math.abs($("#mCSB_"+d.idx+"_container")[0].offsetTop), + draggerPos=mCSB_dragger[0][0].offsetTop, + limit=mCSB_dragger[0].parent().height()-mCSB_dragger[0].height(), + dlt=e.deltaY || delta; + } + if((dir==="y" && !d.overflowed[0]) || (dir==="x" && !d.overflowed[1])){return;} + if(o.mouseWheel.invert || e.webkitDirectionInvertedFromDevice){dlt=-dlt;} + if(o.mouseWheel.normalizeDelta){dlt=dlt<0 ? -1 : 1;} + if((dlt>0 && draggerPos!==0) || (dlt<0 && draggerPos!==limit) || o.mouseWheel.preventDefault){ + e.stopImmediatePropagation(); + e.preventDefault(); + } + if(e.deltaFactor<5 && !o.mouseWheel.normalizeDelta){ + //very low deltaFactor values mean some kind of delta acceleration (e.g. osx trackpad), so adjusting scrolling accordingly + amount=e.deltaFactor; dur=17; + } + _scrollTo($this,(contentPos-(dlt*amount)).toString(),{dir:dir,dur:dur}); + } + }, + /* -------------------- */ + + + /* checks if iframe can be accessed */ + _canAccessIFrameCache=new Object(), + _canAccessIFrame=function(iframe){ + var result=false,cacheKey=false,html=null; + if(iframe===undefined){ + cacheKey="#empty"; + }else if($(iframe).attr("id")!==undefined){ + cacheKey=$(iframe).attr("id"); + } + if(cacheKey!==false && _canAccessIFrameCache[cacheKey]!==undefined){ + return _canAccessIFrameCache[cacheKey]; + } + if(!iframe){ + try{ + var doc=top.document; + html=doc.body.innerHTML; + }catch(err){/* do nothing */} + result=(html!==null); + }else{ + try{ + var doc=iframe.contentDocument || iframe.contentWindow.document; + html=doc.body.innerHTML; + }catch(err){/* do nothing */} + result=(html!==null); + } + if(cacheKey!==false){_canAccessIFrameCache[cacheKey]=result;} + return result; + }, + /* -------------------- */ + + + /* switches iframe's pointer-events property (drag, mousewheel etc. over cross-domain iframes) */ + _iframe=function(evt){ + var el=this.find("iframe"); + if(!el.length){return;} /* check if content contains iframes */ + var val=!evt ? "none" : "auto"; + el.css("pointer-events",val); /* for IE11, iframe's display property should not be "block" */ + }, + /* -------------------- */ + + + /* disables mouse-wheel when hovering specific elements like select, datalist etc. */ + _disableMousewheel=function(el,target){ + var tag=target.nodeName.toLowerCase(), + tags=el.data(pluginPfx).opt.mouseWheel.disableOver, + /* elements that require focus */ + focusTags=["select","textarea"]; + return $.inArray(tag,tags) > -1 && !($.inArray(tag,focusTags) > -1 && !$(target).is(":focus")); + }, + /* -------------------- */ + + + /* + DRAGGER RAIL CLICK EVENT + scrolls content via dragger rail + */ + _draggerRail=function(){ + var $this=$(this),d=$this.data(pluginPfx), + namespace=pluginPfx+"_"+d.idx, + mCSB_container=$("#mCSB_"+d.idx+"_container"), + wrapper=mCSB_container.parent(), + mCSB_draggerContainer=$(".mCSB_"+d.idx+"_scrollbar ."+classes[12]), + clickable; + mCSB_draggerContainer.bind("mousedown."+namespace+" touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace,function(e){ + touchActive=true; + if(!$(e.target).hasClass("mCSB_dragger")){clickable=1;} + }).bind("touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace,function(e){ + touchActive=false; + }).bind("click."+namespace,function(e){ + if(!clickable){return;} + clickable=0; + if($(e.target).hasClass(classes[12]) || $(e.target).hasClass("mCSB_draggerRail")){ + _stop($this); + var el=$(this),mCSB_dragger=el.find(".mCSB_dragger"); + if(el.parent(".mCSB_scrollTools_horizontal").length>0){ + if(!d.overflowed[1]){return;} + var dir="x", + clickDir=e.pageX>mCSB_dragger.offset().left ? -1 : 1, + to=Math.abs(mCSB_container[0].offsetLeft)-(clickDir*(wrapper.width()*0.9)); + }else{ + if(!d.overflowed[0]){return;} + var dir="y", + clickDir=e.pageY>mCSB_dragger.offset().top ? -1 : 1, + to=Math.abs(mCSB_container[0].offsetTop)-(clickDir*(wrapper.height()*0.9)); + } + _scrollTo($this,to.toString(),{dir:dir,scrollEasing:"mcsEaseInOut"}); + } + }); + }, + /* -------------------- */ + + + /* + FOCUS EVENT + scrolls content via element focus (e.g. clicking an input, pressing TAB key etc.) + */ + _focus=function(){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + namespace=pluginPfx+"_"+d.idx, + mCSB_container=$("#mCSB_"+d.idx+"_container"), + wrapper=mCSB_container.parent(); + mCSB_container.bind("focusin."+namespace,function(e){ + var el=$(document.activeElement), + nested=mCSB_container.find(".mCustomScrollBox").length, + dur=0; + if(!el.is(o.advanced.autoScrollOnFocus)){return;} + _stop($this); + clearTimeout($this[0]._focusTimeout); + $this[0]._focusTimer=nested ? (dur+17)*nested : 0; + $this[0]._focusTimeout=setTimeout(function(){ + var to=[_childPos(el)[0],_childPos(el)[1]], + contentPos=[mCSB_container[0].offsetTop,mCSB_container[0].offsetLeft], + isVisible=[ + (contentPos[0]+to[0]>=0 && contentPos[0]+to[0]=0 && contentPos[0]+to[1]a"); + btn.bind("contextmenu."+namespace,function(e){ + e.preventDefault(); //prevent right click + }).bind("mousedown."+namespace+" touchstart."+namespace+" pointerdown."+namespace+" MSPointerDown."+namespace+" mouseup."+namespace+" touchend."+namespace+" pointerup."+namespace+" MSPointerUp."+namespace+" mouseout."+namespace+" pointerout."+namespace+" MSPointerOut."+namespace+" click."+namespace,function(e){ + e.preventDefault(); + if(!_mouseBtnLeft(e)){return;} /* left mouse button only */ + var btnClass=$(this).attr("class"); + seq.type=o.scrollButtons.scrollType; + switch(e.type){ + case "mousedown": case "touchstart": case "pointerdown": case "MSPointerDown": + if(seq.type==="stepped"){return;} + touchActive=true; + d.tweenRunning=false; + _seq("on",btnClass); + break; + case "mouseup": case "touchend": case "pointerup": case "MSPointerUp": + case "mouseout": case "pointerout": case "MSPointerOut": + if(seq.type==="stepped"){return;} + touchActive=false; + if(seq.dir){_seq("off",btnClass);} + break; + case "click": + if(seq.type!=="stepped" || d.tweenRunning){return;} + _seq("on",btnClass); + break; + } + function _seq(a,c){ + seq.scrollAmount=o.scrollButtons.scrollAmount; + _sequentialScroll($this,a,c); + } + }); + }, + /* -------------------- */ + + + /* + KEYBOARD EVENTS + scrolls content via keyboard + Keys: up arrow, down arrow, left arrow, right arrow, PgUp, PgDn, Home, End + */ + _keyboard=function(){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt,seq=d.sequential, + namespace=pluginPfx+"_"+d.idx, + mCustomScrollBox=$("#mCSB_"+d.idx), + mCSB_container=$("#mCSB_"+d.idx+"_container"), + wrapper=mCSB_container.parent(), + editables="input,textarea,select,datalist,keygen,[contenteditable='true']", + iframe=mCSB_container.find("iframe"), + events=["blur."+namespace+" keydown."+namespace+" keyup."+namespace]; + if(iframe.length){ + iframe.each(function(){ + $(this).bind("load",function(){ + /* bind events on accessible iframes */ + if(_canAccessIFrame(this)){ + $(this.contentDocument || this.contentWindow.document).bind(events[0],function(e){ + _onKeyboard(e); + }); + } + }); + }); + } + mCustomScrollBox.attr("tabindex","0").bind(events[0],function(e){ + _onKeyboard(e); + }); + function _onKeyboard(e){ + switch(e.type){ + case "blur": + if(d.tweenRunning && seq.dir){_seq("off",null);} + break; + case "keydown": case "keyup": + var code=e.keyCode ? e.keyCode : e.which,action="on"; + if((o.axis!=="x" && (code===38 || code===40)) || (o.axis!=="y" && (code===37 || code===39))){ + /* up (38), down (40), left (37), right (39) arrows */ + if(((code===38 || code===40) && !d.overflowed[0]) || ((code===37 || code===39) && !d.overflowed[1])){return;} + if(e.type==="keyup"){action="off";} + if(!$(document.activeElement).is(editables)){ + e.preventDefault(); + e.stopImmediatePropagation(); + _seq(action,code); + } + }else if(code===33 || code===34){ + /* PgUp (33), PgDn (34) */ + if(d.overflowed[0] || d.overflowed[1]){ + e.preventDefault(); + e.stopImmediatePropagation(); + } + if(e.type==="keyup"){ + _stop($this); + var keyboardDir=code===34 ? -1 : 1; + if(o.axis==="x" || (o.axis==="yx" && d.overflowed[1] && !d.overflowed[0])){ + var dir="x",to=Math.abs(mCSB_container[0].offsetLeft)-(keyboardDir*(wrapper.width()*0.9)); + }else{ + var dir="y",to=Math.abs(mCSB_container[0].offsetTop)-(keyboardDir*(wrapper.height()*0.9)); + } + _scrollTo($this,to.toString(),{dir:dir,scrollEasing:"mcsEaseInOut"}); + } + }else if(code===35 || code===36){ + /* End (35), Home (36) */ + if(!$(document.activeElement).is(editables)){ + if(d.overflowed[0] || d.overflowed[1]){ + e.preventDefault(); + e.stopImmediatePropagation(); + } + if(e.type==="keyup"){ + if(o.axis==="x" || (o.axis==="yx" && d.overflowed[1] && !d.overflowed[0])){ + var dir="x",to=code===35 ? Math.abs(wrapper.width()-mCSB_container.outerWidth(false)) : 0; + }else{ + var dir="y",to=code===35 ? Math.abs(wrapper.height()-mCSB_container.outerHeight(false)) : 0; + } + _scrollTo($this,to.toString(),{dir:dir,scrollEasing:"mcsEaseInOut"}); + } + } + } + break; + } + function _seq(a,c){ + seq.type=o.keyboard.scrollType; + seq.scrollAmount=o.keyboard.scrollAmount; + if(seq.type==="stepped" && d.tweenRunning){return;} + _sequentialScroll($this,a,c); + } + } + }, + /* -------------------- */ + + + /* scrolls content sequentially (used when scrolling via buttons, keyboard arrows etc.) */ + _sequentialScroll=function(el,action,trigger,e,s){ + var d=el.data(pluginPfx),o=d.opt,seq=d.sequential, + mCSB_container=$("#mCSB_"+d.idx+"_container"), + once=seq.type==="stepped" ? true : false, + steplessSpeed=o.scrollInertia < 26 ? 26 : o.scrollInertia, /* 26/1.5=17 */ + steppedSpeed=o.scrollInertia < 1 ? 17 : o.scrollInertia; + switch(action){ + case "on": + seq.dir=[ + (trigger===classes[16] || trigger===classes[15] || trigger===39 || trigger===37 ? "x" : "y"), + (trigger===classes[13] || trigger===classes[15] || trigger===38 || trigger===37 ? -1 : 1) + ]; + _stop(el); + if(_isNumeric(trigger) && seq.type==="stepped"){return;} + _on(once); + break; + case "off": + _off(); + if(once || (d.tweenRunning && seq.dir)){ + _on(true); + } + break; + } + + /* starts sequence */ + function _on(once){ + if(o.snapAmount){seq.scrollAmount=!(o.snapAmount instanceof Array) ? o.snapAmount : seq.dir[0]==="x" ? o.snapAmount[1] : o.snapAmount[0];} /* scrolling snapping */ + var c=seq.type!=="stepped", /* continuous scrolling */ + t=s ? s : !once ? 1000/60 : c ? steplessSpeed/1.5 : steppedSpeed, /* timer */ + m=!once ? 2.5 : c ? 7.5 : 40, /* multiplier */ + contentPos=[Math.abs(mCSB_container[0].offsetTop),Math.abs(mCSB_container[0].offsetLeft)], + ratio=[d.scrollRatio.y>10 ? 10 : d.scrollRatio.y,d.scrollRatio.x>10 ? 10 : d.scrollRatio.x], + amount=seq.dir[0]==="x" ? contentPos[1]+(seq.dir[1]*(ratio[1]*m)) : contentPos[0]+(seq.dir[1]*(ratio[0]*m)), + px=seq.dir[0]==="x" ? contentPos[1]+(seq.dir[1]*parseInt(seq.scrollAmount)) : contentPos[0]+(seq.dir[1]*parseInt(seq.scrollAmount)), + to=seq.scrollAmount!=="auto" ? px : amount, + easing=e ? e : !once ? "mcsLinear" : c ? "mcsLinearOut" : "mcsEaseInOut", + onComplete=!once ? false : true; + if(once && t<17){ + to=seq.dir[0]==="x" ? contentPos[1] : contentPos[0]; + } + _scrollTo(el,to.toString(),{dir:seq.dir[0],scrollEasing:easing,dur:t,onComplete:onComplete}); + if(once){ + seq.dir=false; + return; + } + clearTimeout(seq.step); + seq.step=setTimeout(function(){ + _on(); + },t); + } + /* stops sequence */ + function _off(){ + clearTimeout(seq.step); + _delete(seq,"step"); + _stop(el); + } + }, + /* -------------------- */ + + + /* returns a yx array from value */ + _arr=function(val){ + var o=$(this).data(pluginPfx).opt,vals=[]; + if(typeof val==="function"){val=val();} /* check if the value is a single anonymous function */ + /* check if value is object or array, its length and create an array with yx values */ + if(!(val instanceof Array)){ /* object value (e.g. {y:"100",x:"100"}, 100 etc.) */ + vals[0]=val.y ? val.y : val.x || o.axis==="x" ? null : val; + vals[1]=val.x ? val.x : val.y || o.axis==="y" ? null : val; + }else{ /* array value (e.g. [100,100]) */ + vals=val.length>1 ? [val[0],val[1]] : o.axis==="x" ? [null,val[0]] : [val[0],null]; + } + /* check if array values are anonymous functions */ + if(typeof vals[0]==="function"){vals[0]=vals[0]();} + if(typeof vals[1]==="function"){vals[1]=vals[1]();} + return vals; + }, + /* -------------------- */ + + + /* translates values (e.g. "top", 100, "100px", "#id") to actual scroll-to positions */ + _to=function(val,dir){ + if(val==null || typeof val=="undefined"){return;} + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + mCSB_container=$("#mCSB_"+d.idx+"_container"), + wrapper=mCSB_container.parent(), + t=typeof val; + if(!dir){dir=o.axis==="x" ? "x" : "y";} + var contentLength=dir==="x" ? mCSB_container.outerWidth(false)-wrapper.width() : mCSB_container.outerHeight(false)-wrapper.height(), + contentPos=dir==="x" ? mCSB_container[0].offsetLeft : mCSB_container[0].offsetTop, + cssProp=dir==="x" ? "left" : "top"; + switch(t){ + case "function": /* this currently is not used. Consider removing it */ + return val(); + break; + case "object": /* js/jquery object */ + var obj=val.jquery ? val : $(val); + if(!obj.length){return;} + return dir==="x" ? _childPos(obj)[1] : _childPos(obj)[0]; + break; + case "string": case "number": + if(_isNumeric(val)){ /* numeric value */ + return Math.abs(val); + }else if(val.indexOf("%")!==-1){ /* percentage value */ + return Math.abs(contentLength*parseInt(val)/100); + }else if(val.indexOf("-=")!==-1){ /* decrease value */ + return Math.abs(contentPos-parseInt(val.split("-=")[1])); + }else if(val.indexOf("+=")!==-1){ /* inrease value */ + var p=(contentPos+parseInt(val.split("+=")[1])); + return p>=0 ? 0 : Math.abs(p); + }else if(val.indexOf("px")!==-1 && _isNumeric(val.split("px")[0])){ /* pixels string value (e.g. "100px") */ + return Math.abs(val.split("px")[0]); + }else{ + if(val==="top" || val==="left"){ /* special strings */ + return 0; + }else if(val==="bottom"){ + return Math.abs(wrapper.height()-mCSB_container.outerHeight(false)); + }else if(val==="right"){ + return Math.abs(wrapper.width()-mCSB_container.outerWidth(false)); + }else if(val==="first" || val==="last"){ + var obj=mCSB_container.find(":"+val); + return dir==="x" ? _childPos(obj)[1] : _childPos(obj)[0]; + }else{ + if($(val).length){ /* jquery selector */ + return dir==="x" ? _childPos($(val))[1] : _childPos($(val))[0]; + }else{ /* other values (e.g. "100em") */ + mCSB_container.css(cssProp,val); + methods.update.call(null,$this[0]); + return; + } + } + } + break; + } + }, + /* -------------------- */ + + + /* calls the update method automatically */ + _autoUpdate=function(rem){ + var $this=$(this),d=$this.data(pluginPfx),o=d.opt, + mCSB_container=$("#mCSB_"+d.idx+"_container"); + if(rem){ + /* + removes autoUpdate timer + usage: _autoUpdate.call(this,"remove"); + */ + clearTimeout(mCSB_container[0].autoUpdate); + _delete(mCSB_container[0],"autoUpdate"); + return; + } + upd(); + function upd(){ + clearTimeout(mCSB_container[0].autoUpdate); + if($this.parents("html").length===0){ + /* check element in dom tree */ + $this=null; + return; + } + mCSB_container[0].autoUpdate=setTimeout(function(){ + /* update on specific selector(s) length and size change */ + if(o.advanced.updateOnSelectorChange){ + d.poll.change.n=sizesSum(); + if(d.poll.change.n!==d.poll.change.o){ + d.poll.change.o=d.poll.change.n; + doUpd(3); + return; + } + } + /* update on main element and scrollbar size changes */ + if(o.advanced.updateOnContentResize){ + d.poll.size.n=$this[0].scrollHeight+$this[0].scrollWidth+mCSB_container[0].offsetHeight+$this[0].offsetHeight+$this[0].offsetWidth; + if(d.poll.size.n!==d.poll.size.o){ + d.poll.size.o=d.poll.size.n; + doUpd(1); + return; + } + } + /* update on image load */ + if(o.advanced.updateOnImageLoad){ + if(!(o.advanced.updateOnImageLoad==="auto" && o.axis==="y")){ //by default, it doesn't run on vertical content + d.poll.img.n=mCSB_container.find("img").length; + if(d.poll.img.n!==d.poll.img.o){ + d.poll.img.o=d.poll.img.n; + mCSB_container.find("img").each(function(){ + imgLoader(this); + }); + return; + } + } + } + if(o.advanced.updateOnSelectorChange || o.advanced.updateOnContentResize || o.advanced.updateOnImageLoad){upd();} + },o.advanced.autoUpdateTimeout); + } + /* a tiny image loader */ + function imgLoader(el){ + if($(el).hasClass(classes[2])){doUpd(); return;} + var img=new Image(); + function createDelegate(contextObject,delegateMethod){ + return function(){return delegateMethod.apply(contextObject,arguments);} + } + function imgOnLoad(){ + this.onload=null; + $(el).addClass(classes[2]); + doUpd(2); + } + img.onload=createDelegate(img,imgOnLoad); + img.src=el.src; + } + /* returns the total height and width sum of all elements matching the selector */ + function sizesSum(){ + if(o.advanced.updateOnSelectorChange===true){o.advanced.updateOnSelectorChange="*";} + var total=0,sel=mCSB_container.find(o.advanced.updateOnSelectorChange); + if(o.advanced.updateOnSelectorChange && sel.length>0){sel.each(function(){total+=this.offsetHeight+this.offsetWidth;});} + return total; + } + /* calls the update method */ + function doUpd(cb){ + clearTimeout(mCSB_container[0].autoUpdate); + methods.update.call(null,$this[0],cb); + } + }, + /* -------------------- */ + + + /* snaps scrolling to a multiple of a pixels number */ + _snapAmount=function(to,amount,offset){ + return (Math.round(to/amount)*amount-offset); + }, + /* -------------------- */ + + + /* stops content and scrollbar animations */ + _stop=function(el){ + var d=el.data(pluginPfx), + sel=$("#mCSB_"+d.idx+"_container,#mCSB_"+d.idx+"_container_wrapper,#mCSB_"+d.idx+"_dragger_vertical,#mCSB_"+d.idx+"_dragger_horizontal"); + sel.each(function(){ + _stopTween.call(this); + }); + }, + /* -------------------- */ + + + /* + ANIMATES CONTENT + This is where the actual scrolling happens + */ + _scrollTo=function(el,to,options){ + var d=el.data(pluginPfx),o=d.opt, + defaults={ + trigger:"internal", + dir:"y", + scrollEasing:"mcsEaseOut", + drag:false, + dur:o.scrollInertia, + overwrite:"all", + callbacks:true, + onStart:true, + onUpdate:true, + onComplete:true + }, + options=$.extend(defaults,options), + dur=[options.dur,(options.drag ? 0 : options.dur)], + mCustomScrollBox=$("#mCSB_"+d.idx), + mCSB_container=$("#mCSB_"+d.idx+"_container"), + wrapper=mCSB_container.parent(), + totalScrollOffsets=o.callbacks.onTotalScrollOffset ? _arr.call(el,o.callbacks.onTotalScrollOffset) : [0,0], + totalScrollBackOffsets=o.callbacks.onTotalScrollBackOffset ? _arr.call(el,o.callbacks.onTotalScrollBackOffset) : [0,0]; + d.trigger=options.trigger; + if(wrapper.scrollTop()!==0 || wrapper.scrollLeft()!==0){ /* always reset scrollTop/Left */ + $(".mCSB_"+d.idx+"_scrollbar").css("visibility","visible"); + wrapper.scrollTop(0).scrollLeft(0); + } + if(to==="_resetY" && !d.contentReset.y){ + /* callbacks: onOverflowYNone */ + if(_cb("onOverflowYNone")){o.callbacks.onOverflowYNone.call(el[0]);} + d.contentReset.y=1; + } + if(to==="_resetX" && !d.contentReset.x){ + /* callbacks: onOverflowXNone */ + if(_cb("onOverflowXNone")){o.callbacks.onOverflowXNone.call(el[0]);} + d.contentReset.x=1; + } + if(to==="_resetY" || to==="_resetX"){return;} + if((d.contentReset.y || !el[0].mcs) && d.overflowed[0]){ + /* callbacks: onOverflowY */ + if(_cb("onOverflowY")){o.callbacks.onOverflowY.call(el[0]);} + d.contentReset.x=null; + } + if((d.contentReset.x || !el[0].mcs) && d.overflowed[1]){ + /* callbacks: onOverflowX */ + if(_cb("onOverflowX")){o.callbacks.onOverflowX.call(el[0]);} + d.contentReset.x=null; + } + if(o.snapAmount){ /* scrolling snapping */ + var snapAmount=!(o.snapAmount instanceof Array) ? o.snapAmount : options.dir==="x" ? o.snapAmount[1] : o.snapAmount[0]; + to=_snapAmount(to,snapAmount,o.snapOffset); + } + switch(options.dir){ + case "x": + var mCSB_dragger=$("#mCSB_"+d.idx+"_dragger_horizontal"), + property="left", + contentPos=mCSB_container[0].offsetLeft, + limit=[ + mCustomScrollBox.width()-mCSB_container.outerWidth(false), + mCSB_dragger.parent().width()-mCSB_dragger.width() + ], + scrollTo=[to,to===0 ? 0 : (to/d.scrollRatio.x)], + tso=totalScrollOffsets[1], + tsbo=totalScrollBackOffsets[1], + totalScrollOffset=tso>0 ? tso/d.scrollRatio.x : 0, + totalScrollBackOffset=tsbo>0 ? tsbo/d.scrollRatio.x : 0; + break; + case "y": + var mCSB_dragger=$("#mCSB_"+d.idx+"_dragger_vertical"), + property="top", + contentPos=mCSB_container[0].offsetTop, + limit=[ + mCustomScrollBox.height()-mCSB_container.outerHeight(false), + mCSB_dragger.parent().height()-mCSB_dragger.height() + ], + scrollTo=[to,to===0 ? 0 : (to/d.scrollRatio.y)], + tso=totalScrollOffsets[0], + tsbo=totalScrollBackOffsets[0], + totalScrollOffset=tso>0 ? tso/d.scrollRatio.y : 0, + totalScrollBackOffset=tsbo>0 ? tsbo/d.scrollRatio.y : 0; + break; + } + if(scrollTo[1]<0 || (scrollTo[0]===0 && scrollTo[1]===0)){ + scrollTo=[0,0]; + }else if(scrollTo[1]>=limit[1]){ + scrollTo=[limit[0],limit[1]]; + }else{ + scrollTo[0]=-scrollTo[0]; + } + if(!el[0].mcs){ + _mcs(); /* init mcs object (once) to make it available before callbacks */ + if(_cb("onInit")){o.callbacks.onInit.call(el[0]);} /* callbacks: onInit */ + } + clearTimeout(mCSB_container[0].onCompleteTimeout); + _tweenTo(mCSB_dragger[0],property,Math.round(scrollTo[1]),dur[1],options.scrollEasing); + if(!d.tweenRunning && ((contentPos===0 && scrollTo[0]>=0) || (contentPos===limit[0] && scrollTo[0]<=limit[0]))){return;} + _tweenTo(mCSB_container[0],property,Math.round(scrollTo[0]),dur[0],options.scrollEasing,options.overwrite,{ + onStart:function(){ + if(options.callbacks && options.onStart && !d.tweenRunning){ + /* callbacks: onScrollStart */ + if(_cb("onScrollStart")){_mcs(); o.callbacks.onScrollStart.call(el[0]);} + d.tweenRunning=true; + _onDragClasses(mCSB_dragger); + d.cbOffsets=_cbOffsets(); + } + },onUpdate:function(){ + if(options.callbacks && options.onUpdate){ + /* callbacks: whileScrolling */ + if(_cb("whileScrolling")){_mcs(); o.callbacks.whileScrolling.call(el[0]);} + } + },onComplete:function(){ + if(options.callbacks && options.onComplete){ + if(o.axis==="yx"){clearTimeout(mCSB_container[0].onCompleteTimeout);} + var t=mCSB_container[0].idleTimer || 0; + mCSB_container[0].onCompleteTimeout=setTimeout(function(){ + /* callbacks: onScroll, onTotalScroll, onTotalScrollBack */ + if(_cb("onScroll")){_mcs(); o.callbacks.onScroll.call(el[0]);} + if(_cb("onTotalScroll") && scrollTo[1]>=limit[1]-totalScrollOffset && d.cbOffsets[0]){_mcs(); o.callbacks.onTotalScroll.call(el[0]);} + if(_cb("onTotalScrollBack") && scrollTo[1]<=totalScrollBackOffset && d.cbOffsets[1]){_mcs(); o.callbacks.onTotalScrollBack.call(el[0]);} + d.tweenRunning=false; + mCSB_container[0].idleTimer=0; + _onDragClasses(mCSB_dragger,"hide"); + },t); + } + } + }); + /* checks if callback function exists */ + function _cb(cb){ + return d && o.callbacks[cb] && typeof o.callbacks[cb]==="function"; + } + /* checks whether callback offsets always trigger */ + function _cbOffsets(){ + return [o.callbacks.alwaysTriggerOffsets || contentPos>=limit[0]+tso,o.callbacks.alwaysTriggerOffsets || contentPos<=-tsbo]; + } + /* + populates object with useful values for the user + values: + content: this.mcs.content + content top position: this.mcs.top + content left position: this.mcs.left + dragger top position: this.mcs.draggerTop + dragger left position: this.mcs.draggerLeft + scrolling y percentage: this.mcs.topPct + scrolling x percentage: this.mcs.leftPct + scrolling direction: this.mcs.direction + */ + function _mcs(){ + var cp=[mCSB_container[0].offsetTop,mCSB_container[0].offsetLeft], /* content position */ + dp=[mCSB_dragger[0].offsetTop,mCSB_dragger[0].offsetLeft], /* dragger position */ + cl=[mCSB_container.outerHeight(false),mCSB_container.outerWidth(false)], /* content length */ + pl=[mCustomScrollBox.height(),mCustomScrollBox.width()]; /* content parent length */ + el[0].mcs={ + content:mCSB_container, /* original content wrapper as jquery object */ + top:cp[0],left:cp[1],draggerTop:dp[0],draggerLeft:dp[1], + topPct:Math.round((100*Math.abs(cp[0]))/(Math.abs(cl[0])-pl[0])),leftPct:Math.round((100*Math.abs(cp[1]))/(Math.abs(cl[1])-pl[1])), + direction:options.dir + }; + /* + this refers to the original element containing the scrollbar(s) + usage: this.mcs.top, this.mcs.leftPct etc. + */ + } + }, + /* -------------------- */ + + + /* + CUSTOM JAVASCRIPT ANIMATION TWEEN + Lighter and faster than jquery animate() and css transitions + Animates top/left properties and includes easings + */ + _tweenTo=function(el,prop,to,duration,easing,overwrite,callbacks){ + if(!el._mTween){el._mTween={top:{},left:{}};} + var callbacks=callbacks || {}, + onStart=callbacks.onStart || function(){},onUpdate=callbacks.onUpdate || function(){},onComplete=callbacks.onComplete || function(){}, + startTime=_getTime(),_delay,progress=0,from=el.offsetTop,elStyle=el.style,_request,tobj=el._mTween[prop]; + if(prop==="left"){from=el.offsetLeft;} + var diff=to-from; + tobj.stop=0; + if(overwrite!=="none"){_cancelTween();} + _startTween(); + function _step(){ + if(tobj.stop){return;} + if(!progress){onStart.call();} + progress=_getTime()-startTime; + _tween(); + if(progress>=tobj.time){ + tobj.time=(progress>tobj.time) ? progress+_delay-(progress-tobj.time) : progress+_delay-1; + if(tobj.time0){ + tobj.currVal=_ease(tobj.time,from,diff,duration,easing); + elStyle[prop]=Math.round(tobj.currVal)+"px"; + }else{ + elStyle[prop]=to+"px"; + } + onUpdate.call(); + } + function _startTween(){ + _delay=1000/60; + tobj.time=progress+_delay; + _request=(!window.requestAnimationFrame) ? function(f){_tween(); return setTimeout(f,0.01);} : window.requestAnimationFrame; + tobj.id=_request(_step); + } + function _cancelTween(){ + if(tobj.id==null){return;} + if(!window.requestAnimationFrame){clearTimeout(tobj.id); + }else{window.cancelAnimationFrame(tobj.id);} + tobj.id=null; + } + function _ease(t,b,c,d,type){ + switch(type){ + case "linear": case "mcsLinear": + return c*t/d + b; + break; + case "mcsLinearOut": + t/=d; t--; return c * Math.sqrt(1 - t*t) + b; + break; + case "easeInOutSmooth": + t/=d/2; + if(t<1) return c/2*t*t + b; + t--; + return -c/2 * (t*(t-2) - 1) + b; + break; + case "easeInOutStrong": + t/=d/2; + if(t<1) return c/2 * Math.pow( 2, 10 * (t - 1) ) + b; + t--; + return c/2 * ( -Math.pow( 2, -10 * t) + 2 ) + b; + break; + case "easeInOut": case "mcsEaseInOut": + t/=d/2; + if(t<1) return c/2*t*t*t + b; + t-=2; + return c/2*(t*t*t + 2) + b; + break; + case "easeOutSmooth": + t/=d; t--; + return -c * (t*t*t*t - 1) + b; + break; + case "easeOutStrong": + return c * ( -Math.pow( 2, -10 * t/d ) + 1 ) + b; + break; + case "easeOut": case "mcsEaseOut": default: + var ts=(t/=d)*t,tc=ts*t; + return b+c*(0.499999999999997*tc*ts + -2.5*ts*ts + 5.5*tc + -6.5*ts + 4*t); + } + } + }, + /* -------------------- */ + + + /* returns current time */ + _getTime=function(){ + if(window.performance && window.performance.now){ + return window.performance.now(); + }else{ + if(window.performance && window.performance.webkitNow){ + return window.performance.webkitNow(); + }else{ + if(Date.now){return Date.now();}else{return new Date().getTime();} + } + } + }, + /* -------------------- */ + + + /* stops a tween */ + _stopTween=function(){ + var el=this; + if(!el._mTween){el._mTween={top:{},left:{}};} + var props=["top","left"]; + for(var i=0; i';break;case"dropdown":a='"}return a},getTime:function(){return""===this.hour?"":this.hour+":"+(1===this.minute.toString().length?"0"+this.minute:this.minute)+(this.showSeconds?":"+(1===this.second.toString().length?"0"+this.second:this.second):"")+(this.showMeridian?" "+this.meridian:"")},hideWidget:function(){this.isOpen!==!1&&(this.$element.trigger({type:"hide.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),"modal"===this.template&&this.$widget.modal?this.$widget.modal("hide"):this.$widget.removeClass("open"),a(c).off("mousedown.timepicker, touchend.timepicker",this.handleDocumentClick),this.isOpen=!1,this.$widget.detach())},highlightUnit:function(){this.position=this.getCursorPosition(),this.position>=0&&this.position<=2?this.highlightHour():this.position>=3&&this.position<=5?this.highlightMinute():this.position>=6&&this.position<=8?this.showSeconds?this.highlightSecond():this.highlightMeridian():this.position>=9&&this.position<=11&&this.highlightMeridian()},highlightNextUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMinute();break;case"minute":this.showSeconds?this.highlightSecond():this.showMeridian?this.highlightMeridian():this.highlightHour();break;case"second":this.showMeridian?this.highlightMeridian():this.highlightHour();break;case"meridian":this.highlightHour()}},highlightPrevUnit:function(){switch(this.highlightedUnit){case"hour":this.showMeridian?this.highlightMeridian():this.showSeconds?this.highlightSecond():this.highlightMinute();break;case"minute":this.highlightHour();break;case"second":this.highlightMinute();break;case"meridian":this.showSeconds?this.highlightSecond():this.highlightMinute()}},highlightHour:function(){var a=this.$element.get(0),b=this;this.highlightedUnit="hour",a.setSelectionRange&&setTimeout(function(){b.hour<10?a.setSelectionRange(0,1):a.setSelectionRange(0,2)},0)},highlightMinute:function(){var a=this.$element.get(0),b=this;this.highlightedUnit="minute",a.setSelectionRange&&setTimeout(function(){b.hour<10?a.setSelectionRange(2,4):a.setSelectionRange(3,5)},0)},highlightSecond:function(){var a=this.$element.get(0),b=this;this.highlightedUnit="second",a.setSelectionRange&&setTimeout(function(){b.hour<10?a.setSelectionRange(5,7):a.setSelectionRange(6,8)},0)},highlightMeridian:function(){var a=this.$element.get(0),b=this;this.highlightedUnit="meridian",a.setSelectionRange&&(this.showSeconds?setTimeout(function(){b.hour<10?a.setSelectionRange(8,10):a.setSelectionRange(9,11)},0):setTimeout(function(){b.hour<10?a.setSelectionRange(5,7):a.setSelectionRange(6,8)},0))},incrementHour:function(){if(this.showMeridian){if(11===this.hour)return this.hour++,this.toggleMeridian();12===this.hour&&(this.hour=0)}return this.hour===this.maxHours-1?void(this.hour=0):void this.hour++},incrementMinute:function(a){var b;b=a?this.minute+a:this.minute+this.minuteStep-this.minute%this.minuteStep,b>59?(this.incrementHour(),this.minute=b-60):this.minute=b},incrementSecond:function(){var a=this.second+this.secondStep-this.second%this.secondStep;a>59?(this.incrementMinute(!0),this.second=a-60):this.second=a},mousewheel:function(b){if(!this.disableMousewheel){b.preventDefault(),b.stopPropagation();var c=b.originalEvent.wheelDelta||-b.originalEvent.detail,d=null;switch("mousewheel"===b.type?d=-1*b.originalEvent.wheelDelta:"DOMMouseScroll"===b.type&&(d=40*b.originalEvent.detail),d&&(b.preventDefault(),a(this).scrollTop(d+a(this).scrollTop())),this.highlightedUnit){case"minute":c>0?this.incrementMinute():this.decrementMinute(),this.highlightMinute();break;case"second":c>0?this.incrementSecond():this.decrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian();break;default:c>0?this.incrementHour():this.decrementHour(),this.highlightHour()}return!1}},changeToNearestStep:function(a,b){return a%b===0?a:Math.round(a%b/b)?(a+(b-a%b))%60:a-a%b},place:function(){if(!this.isInline){var c=this.$widget.outerWidth(),d=this.$widget.outerHeight(),e=10,f=a(b).width(),g=a(b).height(),h=a(b).scrollTop(),i=parseInt(this.$element.parents().filter(function(){return"auto"!==a(this).css("z-index")}).first().css("z-index"),10)+10,j=this.component?this.component.parent().offset():this.$element.offset(),k=this.component?this.component.outerHeight(!0):this.$element.outerHeight(!1),l=this.component?this.component.outerWidth(!0):this.$element.outerWidth(!1),m=j.left,n=j.top;this.$widget.removeClass("timepicker-orient-top timepicker-orient-bottom timepicker-orient-right timepicker-orient-left"),"auto"!==this.orientation.x?(this.$widget.addClass("timepicker-orient-"+this.orientation.x),"right"===this.orientation.x&&(m-=c-l)):(this.$widget.addClass("timepicker-orient-left"),j.left<0?m-=j.left-e:j.left+c>f&&(m=f-c-e));var o,p,q=this.orientation.y;"auto"===q&&(o=-h+j.top-d,p=h+g-(j.top+k+d),q=Math.max(o,p)===p?"top":"bottom"),this.$widget.addClass("timepicker-orient-"+q),"top"===q?n+=k:n-=d+parseInt(this.$widget.css("padding-top"),10),this.$widget.css({top:n,left:m,zIndex:i})}},remove:function(){a("document").off(".timepicker"),this.$widget&&this.$widget.remove(),delete this.$element.data().timepicker},setDefaultTime:function(a){if(this.$element.val())this.updateFromElementVal();else if("current"===a){var b=new Date,c=b.getHours(),d=b.getMinutes(),e=b.getSeconds(),f="AM";0!==e&&(e=Math.ceil(b.getSeconds()/this.secondStep)*this.secondStep,60===e&&(d+=1,e=0)),0!==d&&(d=Math.ceil(b.getMinutes()/this.minuteStep)*this.minuteStep,60===d&&(c+=1,d=0)),this.showMeridian&&(0===c?c=12:c>=12?(c>12&&(c-=12),f="PM"):f="AM"),this.hour=c,this.minute=d,this.second=e,this.meridian=f,this.update()}else a===!1?(this.hour=0,this.minute=0,this.second=0,this.meridian="AM"):this.setTime(a)},setTime:function(a,b){if(!a)return void this.clear();var c,d,e,f,g,h;if("object"==typeof a&&a.getMonth)e=a.getHours(),f=a.getMinutes(),g=a.getSeconds(),this.showMeridian&&(h="AM",e>12&&(h="PM",e%=12),12===e&&(h="PM"));else{if(c=(/a/i.test(a)?1:0)+(/p/i.test(a)?2:0),c>2)return void this.clear();if(d=a.replace(/[^0-9\:]/g,"").split(":"),e=d[0]?d[0].toString():d.toString(),this.explicitMode&&e.length>2&&e.length%2!==0)return void this.clear();f=d[1]?d[1].toString():"",g=d[2]?d[2].toString():"",e.length>4&&(g=e.slice(-2),e=e.slice(0,-2)),e.length>2&&(f=e.slice(-2),e=e.slice(0,-2)),f.length>2&&(g=f.slice(-2),f=f.slice(0,-2)),e=parseInt(e,10),f=parseInt(f,10),g=parseInt(g,10),isNaN(e)&&(e=0),isNaN(f)&&(f=0),isNaN(g)&&(g=0),g>59&&(g=59),f>59&&(f=59),e>=this.maxHours&&(e=this.maxHours-1),this.showMeridian?(e>12&&(c=2,e-=12),c||(c=1),0===e&&(e=12),h=1===c?"AM":"PM"):12>e&&2===c?e+=12:e>=this.maxHours?e=this.maxHours-1:(0>e||12===e&&1===c)&&(e=0)}this.hour=e,this.snapToStep?(this.minute=this.changeToNearestStep(f,this.minuteStep),this.second=this.changeToNearestStep(g,this.secondStep)):(this.minute=f,this.second=g),this.meridian=h,this.update(b)},showWidget:function(){this.isOpen||this.$element.is(":disabled")||(this.$widget.appendTo(this.appendWidgetTo),a(c).on("mousedown.timepicker, touchend.timepicker",{scope:this},this.handleDocumentClick),this.$element.trigger({type:"show.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),this.place(),this.disableFocus&&this.$element.blur(),""===this.hour&&(this.defaultTime?this.setDefaultTime(this.defaultTime):this.setTime("0:0:0")),"modal"===this.template&&this.$widget.modal?this.$widget.modal("show").on("hidden",a.proxy(this.hideWidget,this)):this.isOpen===!1&&this.$widget.addClass("open"),this.isOpen=!0)},toggleMeridian:function(){this.meridian="AM"===this.meridian?"PM":"AM"},update:function(a){this.updateElement(),a||this.updateWidget(),this.$element.trigger({type:"changeTime.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}})},updateElement:function(){this.$element.val(this.getTime()).change()},updateFromElementVal:function(){this.setTime(this.$element.val())},updateWidget:function(){if(this.$widget!==!1){var a=this.hour,b=1===this.minute.toString().length?"0"+this.minute:this.minute,c=1===this.second.toString().length?"0"+this.second:this.second;this.showInputs?(this.$widget.find("input.bootstrap-timepicker-hour").val(a),this.$widget.find("input.bootstrap-timepicker-minute").val(b),this.showSeconds&&this.$widget.find("input.bootstrap-timepicker-second").val(c),this.showMeridian&&this.$widget.find("input.bootstrap-timepicker-meridian").val(this.meridian)):(this.$widget.find("span.bootstrap-timepicker-hour").text(a),this.$widget.find("span.bootstrap-timepicker-minute").text(b),this.showSeconds&&this.$widget.find("span.bootstrap-timepicker-second").text(c),this.showMeridian&&this.$widget.find("span.bootstrap-timepicker-meridian").text(this.meridian))}},updateFromWidgetInputs:function(){if(this.$widget!==!1){var a=this.$widget.find("input.bootstrap-timepicker-hour").val()+":"+this.$widget.find("input.bootstrap-timepicker-minute").val()+(this.showSeconds?":"+this.$widget.find("input.bootstrap-timepicker-second").val():"")+(this.showMeridian?this.$widget.find("input.bootstrap-timepicker-meridian").val():"");this.setTime(a,!0)}},widgetClick:function(b){b.stopPropagation(),b.preventDefault();var c=a(b.target),d=c.closest("a").data("action");d&&this[d](),this.update(),c.is("input")&&c.get(0).setSelectionRange(0,2)},widgetKeydown:function(b){var c=a(b.target),d=c.attr("class").replace("bootstrap-timepicker-","");switch(b.which){case 9:if(b.shiftKey){if("hour"===d)return this.hideWidget()}else if(this.showMeridian&&"meridian"===d||this.showSeconds&&"second"===d||!this.showMeridian&&!this.showSeconds&&"minute"===d)return this.hideWidget();break;case 27:this.hideWidget();break;case 38:switch(b.preventDefault(),d){case"hour":this.incrementHour();break;case"minute":this.incrementMinute();break;case"second":this.incrementSecond();break;case"meridian":this.toggleMeridian()}this.setTime(this.getTime()),c.get(0).setSelectionRange(0,2);break;case 40:switch(b.preventDefault(),d){case"hour":this.decrementHour();break;case"minute":this.decrementMinute();break;case"second":this.decrementSecond();break;case"meridian":this.toggleMeridian()}this.setTime(this.getTime()),c.get(0).setSelectionRange(0,2)}},widgetKeyup:function(a){(65===a.which||77===a.which||80===a.which||46===a.which||8===a.which||a.which>=48&&a.which<=57||a.which>=96&&a.which<=105)&&this.updateFromWidgetInputs()}},a.fn.timepicker=function(b){var c=Array.apply(null,arguments);return c.shift(),this.each(function(){var e=a(this),f=e.data("timepicker"),g="object"==typeof b&&b;f||e.data("timepicker",f=new d(this,a.extend({},a.fn.timepicker.defaults,g,a(this).data()))),"string"==typeof b&&f[b].apply(f,c)})},a.fn.timepicker.defaults={defaultTime:"current",disableFocus:!1,disableMousewheel:!1,isOpen:!1,minuteStep:15,modalBackdrop:!1,orientation:{x:"auto",y:"auto"},secondStep:15,snapToStep:!1,showSeconds:!1,showInputs:!0,showMeridian:!0,template:"dropdown",appendWidgetTo:"body",showWidgetOnAddonClick:!0,icons:{up:"glyphicon glyphicon-chevron-up",down:"glyphicon glyphicon-chevron-down"},maxHours:24,explicitMode:!1},a.fn.timepicker.Constructor=d,a(c).on("focus.timepicker.data-api click.timepicker.data-api",'[data-provide="timepicker"]',function(b){var c=a(this);c.data("timepicker")||(b.preventDefault(),c.timepicker())})}(jQuery,window,document); -$.fn.timepicker.defaults = $.extend(true, {}, $.fn.timepicker.defaults, { - icons: { - up: 'la la-angle-up', - down: 'la la-angle-down' - } +$.fn.timepicker.defaults = $.extend(true, {}, $.fn.timepicker.defaults, { + icons: { + up: 'la la-angle-up', + down: 'la la-angle-down' + } }); -/** -* @version: 2.1.30 -* @author: Dan Grossman http://www.dangrossman.info/ -* @copyright: Copyright (c) 2012-2017 Dan Grossman. All rights reserved. -* @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php -* @website: http://www.daterangepicker.com/ -*/ -// Follow the UMD template https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js -(function (root, factory) { - if (typeof define === 'function' && define.amd) { - // AMD. Make globaly available as well - define(['moment', 'jquery'], function (moment, jquery) { - if (!jquery.fn) jquery.fn = {}; // webpack server rendering - return factory(moment, jquery); - }); - } else if (typeof module === 'object' && module.exports) { - // Node / Browserify - //isomorphic issue - var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined; - if (!jQuery) { - jQuery = require('jquery'); - if (!jQuery.fn) jQuery.fn = {}; - } - var moment = (typeof window != 'undefined' && typeof window.moment != 'undefined') ? window.moment : require('moment'); - module.exports = factory(moment, jQuery); - } else { - // Browser globals - root.daterangepicker = factory(root.moment, root.jQuery); - } -}(this, function(moment, $) { - var DateRangePicker = function(element, options, cb) { - - //default settings for options - this.parentEl = 'body'; - this.element = $(element); - this.startDate = moment().startOf('day'); - this.endDate = moment().endOf('day'); - this.minDate = false; - this.maxDate = false; - this.dateLimit = false; - this.autoApply = false; - this.singleDatePicker = false; - this.showDropdowns = false; - this.showWeekNumbers = false; - this.showISOWeekNumbers = false; - this.showCustomRangeLabel = true; - this.timePicker = false; - this.timePicker24Hour = false; - this.timePickerIncrement = 1; - this.timePickerSeconds = false; - this.linkedCalendars = true; - this.autoUpdateInput = true; - this.alwaysShowCalendars = false; - this.ranges = {}; - - this.opens = 'right'; - if (this.element.hasClass('pull-right')) - this.opens = 'left'; - - this.drops = 'down'; - if (this.element.hasClass('dropup')) - this.drops = 'up'; - - this.buttonClasses = 'btn btn-sm'; - this.applyClass = 'btn-success'; - this.cancelClass = 'btn-default'; - - this.locale = { - direction: 'ltr', - format: moment.localeData().longDateFormat('L'), - separator: ' - ', - applyLabel: 'Apply', - cancelLabel: 'Cancel', - weekLabel: 'W', - customRangeLabel: 'Custom Range', - daysOfWeek: moment.weekdaysMin(), - monthNames: moment.monthsShort(), - firstDay: moment.localeData().firstDayOfWeek() - }; - - this.callback = function() { }; - - //some state information - this.isShowing = false; - this.leftCalendar = {}; - this.rightCalendar = {}; - - //custom options from user - if (typeof options !== 'object' || options === null) - options = {}; - - //allow setting options with data attributes - //data-api options will be overwritten with custom javascript options - options = $.extend(this.element.data(), options); - - //html template for the picker UI - if (typeof options.template !== 'string' && !(options.template instanceof $)) - options.template = ''; - - this.parentEl = (options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl); - this.container = $(options.template).appendTo(this.parentEl); - - // - // handle all the possible options overriding defaults - // - - if (typeof options.locale === 'object') { - - if (typeof options.locale.direction === 'string') - this.locale.direction = options.locale.direction; - - if (typeof options.locale.format === 'string') - this.locale.format = options.locale.format; - - if (typeof options.locale.separator === 'string') - this.locale.separator = options.locale.separator; - - if (typeof options.locale.daysOfWeek === 'object') - this.locale.daysOfWeek = options.locale.daysOfWeek.slice(); - - if (typeof options.locale.monthNames === 'object') - this.locale.monthNames = options.locale.monthNames.slice(); - - if (typeof options.locale.firstDay === 'number') - this.locale.firstDay = options.locale.firstDay; - - if (typeof options.locale.applyLabel === 'string') - this.locale.applyLabel = options.locale.applyLabel; - - if (typeof options.locale.cancelLabel === 'string') - this.locale.cancelLabel = options.locale.cancelLabel; - - if (typeof options.locale.weekLabel === 'string') - this.locale.weekLabel = options.locale.weekLabel; - - if (typeof options.locale.customRangeLabel === 'string'){ - //Support unicode chars in the custom range name. - var elem = document.createElement('textarea'); - elem.innerHTML = options.locale.customRangeLabel; - var rangeHtml = elem.value; - this.locale.customRangeLabel = rangeHtml; - } - } - this.container.addClass(this.locale.direction); - - if (typeof options.startDate === 'string') - this.startDate = moment(options.startDate, this.locale.format); - - if (typeof options.endDate === 'string') - this.endDate = moment(options.endDate, this.locale.format); - - if (typeof options.minDate === 'string') - this.minDate = moment(options.minDate, this.locale.format); - - if (typeof options.maxDate === 'string') - this.maxDate = moment(options.maxDate, this.locale.format); - - if (typeof options.startDate === 'object') - this.startDate = moment(options.startDate); - - if (typeof options.endDate === 'object') - this.endDate = moment(options.endDate); - - if (typeof options.minDate === 'object') - this.minDate = moment(options.minDate); - - if (typeof options.maxDate === 'object') - this.maxDate = moment(options.maxDate); - - // sanity check for bad options - if (this.minDate && this.startDate.isBefore(this.minDate)) - this.startDate = this.minDate.clone(); - - // sanity check for bad options - if (this.maxDate && this.endDate.isAfter(this.maxDate)) - this.endDate = this.maxDate.clone(); - - if (typeof options.applyClass === 'string') - this.applyClass = options.applyClass; - - if (typeof options.cancelClass === 'string') - this.cancelClass = options.cancelClass; - - if (typeof options.dateLimit === 'object') - this.dateLimit = options.dateLimit; - - if (typeof options.opens === 'string') - this.opens = options.opens; - - if (typeof options.drops === 'string') - this.drops = options.drops; - - if (typeof options.showWeekNumbers === 'boolean') - this.showWeekNumbers = options.showWeekNumbers; - - if (typeof options.showISOWeekNumbers === 'boolean') - this.showISOWeekNumbers = options.showISOWeekNumbers; - - if (typeof options.buttonClasses === 'string') - this.buttonClasses = options.buttonClasses; - - if (typeof options.buttonClasses === 'object') - this.buttonClasses = options.buttonClasses.join(' '); - - if (typeof options.showDropdowns === 'boolean') - this.showDropdowns = options.showDropdowns; - - if (typeof options.showCustomRangeLabel === 'boolean') - this.showCustomRangeLabel = options.showCustomRangeLabel; - - if (typeof options.singleDatePicker === 'boolean') { - this.singleDatePicker = options.singleDatePicker; - if (this.singleDatePicker) - this.endDate = this.startDate.clone(); - } - - if (typeof options.timePicker === 'boolean') - this.timePicker = options.timePicker; - - if (typeof options.timePickerSeconds === 'boolean') - this.timePickerSeconds = options.timePickerSeconds; - - if (typeof options.timePickerIncrement === 'number') - this.timePickerIncrement = options.timePickerIncrement; - - if (typeof options.timePicker24Hour === 'boolean') - this.timePicker24Hour = options.timePicker24Hour; - - if (typeof options.autoApply === 'boolean') - this.autoApply = options.autoApply; - - if (typeof options.autoUpdateInput === 'boolean') - this.autoUpdateInput = options.autoUpdateInput; - - if (typeof options.linkedCalendars === 'boolean') - this.linkedCalendars = options.linkedCalendars; - - if (typeof options.isInvalidDate === 'function') - this.isInvalidDate = options.isInvalidDate; - - if (typeof options.isCustomDate === 'function') - this.isCustomDate = options.isCustomDate; - - if (typeof options.alwaysShowCalendars === 'boolean') - this.alwaysShowCalendars = options.alwaysShowCalendars; - - // update day names order to firstDay - if (this.locale.firstDay != 0) { - var iterator = this.locale.firstDay; - while (iterator > 0) { - this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift()); - iterator--; - } - } - - var start, end, range; - - //if no start/end dates set, check if an input element contains initial values - if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') { - if ($(this.element).is('input[type=text]')) { - var val = $(this.element).val(), - split = val.split(this.locale.separator); - - start = end = null; - - if (split.length == 2) { - start = moment(split[0], this.locale.format); - end = moment(split[1], this.locale.format); - } else if (this.singleDatePicker && val !== "") { - start = moment(val, this.locale.format); - end = moment(val, this.locale.format); - } - if (start !== null && end !== null) { - this.setStartDate(start); - this.setEndDate(end); - } - } - } - - if (typeof options.ranges === 'object') { - for (range in options.ranges) { - - if (typeof options.ranges[range][0] === 'string') - start = moment(options.ranges[range][0], this.locale.format); - else - start = moment(options.ranges[range][0]); - - if (typeof options.ranges[range][1] === 'string') - end = moment(options.ranges[range][1], this.locale.format); - else - end = moment(options.ranges[range][1]); - - // If the start or end date exceed those allowed by the minDate or dateLimit - // options, shorten the range to the allowable period. - if (this.minDate && start.isBefore(this.minDate)) - start = this.minDate.clone(); - - var maxDate = this.maxDate; - if (this.dateLimit && maxDate && start.clone().add(this.dateLimit).isAfter(maxDate)) - maxDate = start.clone().add(this.dateLimit); - if (maxDate && end.isAfter(maxDate)) - end = maxDate.clone(); - - // If the end of the range is before the minimum or the start of the range is - // after the maximum, don't display this range option at all. - if ((this.minDate && end.isBefore(this.minDate, this.timepicker ? 'minute' : 'day')) - || (maxDate && start.isAfter(maxDate, this.timepicker ? 'minute' : 'day'))) - continue; - - //Support unicode chars in the range names. - var elem = document.createElement('textarea'); - elem.innerHTML = range; - var rangeHtml = elem.value; - - this.ranges[rangeHtml] = [start, end]; - } - - var list = '
    '; - for (range in this.ranges) { - list += '
  • ' + range + '
  • '; - } - if (this.showCustomRangeLabel) { - list += '
  • ' + this.locale.customRangeLabel + '
  • '; - } - list += '
'; - this.container.find('.ranges').prepend(list); - } - - if (typeof cb === 'function') { - this.callback = cb; - } - - if (!this.timePicker) { - this.startDate = this.startDate.startOf('day'); - this.endDate = this.endDate.endOf('day'); - this.container.find('.calendar-time').hide(); - } - - //can't be used together for now - if (this.timePicker && this.autoApply) - this.autoApply = false; - - if (this.autoApply && typeof options.ranges !== 'object') { - this.container.find('.ranges').hide(); - } else if (this.autoApply) { - this.container.find('.applyBtn, .cancelBtn').addClass('hide'); - } - - if (this.singleDatePicker) { - this.container.addClass('single'); - this.container.find('.calendar.left').addClass('single'); - this.container.find('.calendar.left').show(); - this.container.find('.calendar.right').hide(); - this.container.find('.daterangepicker_input input, .daterangepicker_input > i').hide(); - if (this.timePicker) { - this.container.find('.ranges ul').hide(); - } else { - this.container.find('.ranges').hide(); - } - } - - if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars) { - this.container.addClass('show-calendar'); - } - - this.container.addClass('opens' + this.opens); - - //swap the position of the predefined ranges if opens right - if (typeof options.ranges !== 'undefined' && this.opens == 'right') { - this.container.find('.ranges').prependTo( this.container.find('.calendar.left').parent() ); - } - - //apply CSS classes and labels to buttons - this.container.find('.applyBtn, .cancelBtn').addClass(this.buttonClasses); - if (this.applyClass.length) - this.container.find('.applyBtn').addClass(this.applyClass); - if (this.cancelClass.length) - this.container.find('.cancelBtn').addClass(this.cancelClass); - this.container.find('.applyBtn').html(this.locale.applyLabel); - this.container.find('.cancelBtn').html(this.locale.cancelLabel); - - // - // event listeners - // - - this.container.find('.calendar') - .on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this)) - .on('click.daterangepicker', '.next', $.proxy(this.clickNext, this)) - .on('mousedown.daterangepicker', 'td.available', $.proxy(this.clickDate, this)) - .on('mouseenter.daterangepicker', 'td.available', $.proxy(this.hoverDate, this)) - .on('mouseleave.daterangepicker', 'td.available', $.proxy(this.updateFormInputs, this)) - .on('change.daterangepicker', 'select.yearselect', $.proxy(this.monthOrYearChanged, this)) - .on('change.daterangepicker', 'select.monthselect', $.proxy(this.monthOrYearChanged, this)) - .on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.secondselect,select.ampmselect', $.proxy(this.timeChanged, this)) - .on('click.daterangepicker', '.daterangepicker_input input', $.proxy(this.showCalendars, this)) - .on('focus.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsFocused, this)) - .on('blur.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsBlurred, this)) - .on('change.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this)) - .on('keydown.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsKeydown, this)); - - this.container.find('.ranges') - .on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this)) - .on('click.daterangepicker', 'button.cancelBtn', $.proxy(this.clickCancel, this)) - .on('click.daterangepicker', 'li', $.proxy(this.clickRange, this)) - .on('mouseenter.daterangepicker', 'li', $.proxy(this.hoverRange, this)) - .on('mouseleave.daterangepicker', 'li', $.proxy(this.updateFormInputs, this)); - - if (this.element.is('input') || this.element.is('button')) { - this.element.on({ - 'click.daterangepicker': $.proxy(this.show, this), - 'focus.daterangepicker': $.proxy(this.show, this), - 'keyup.daterangepicker': $.proxy(this.elementChanged, this), - 'keydown.daterangepicker': $.proxy(this.keydown, this) //IE 11 compatibility - }); - } else { - this.element.on('click.daterangepicker', $.proxy(this.toggle, this)); - this.element.on('keydown.daterangepicker', $.proxy(this.toggle, this)); - } - - // - // if attached to a text input, set the initial value - // - - if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) { - this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format)); - this.element.trigger('change'); - } else if (this.element.is('input') && this.autoUpdateInput) { - this.element.val(this.startDate.format(this.locale.format)); - this.element.trigger('change'); - } - - }; - - DateRangePicker.prototype = { - - constructor: DateRangePicker, - - setStartDate: function(startDate) { - if (typeof startDate === 'string') - this.startDate = moment(startDate, this.locale.format); - - if (typeof startDate === 'object') - this.startDate = moment(startDate); - - if (!this.timePicker) - this.startDate = this.startDate.startOf('day'); - - if (this.timePicker && this.timePickerIncrement) - this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement); - - if (this.minDate && this.startDate.isBefore(this.minDate)) { - this.startDate = this.minDate.clone(); - if (this.timePicker && this.timePickerIncrement) - this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement); - } - - if (this.maxDate && this.startDate.isAfter(this.maxDate)) { - this.startDate = this.maxDate.clone(); - if (this.timePicker && this.timePickerIncrement) - this.startDate.minute(Math.floor(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement); - } - - if (!this.isShowing) - this.updateElement(); - - this.updateMonthsInView(); - }, - - setEndDate: function(endDate) { - if (typeof endDate === 'string') - this.endDate = moment(endDate, this.locale.format); - - if (typeof endDate === 'object') - this.endDate = moment(endDate); - - if (!this.timePicker) - this.endDate = this.endDate.add(1,'d').startOf('day').subtract(1,'second'); - - if (this.timePicker && this.timePickerIncrement) - this.endDate.minute(Math.round(this.endDate.minute() / this.timePickerIncrement) * this.timePickerIncrement); - - if (this.endDate.isBefore(this.startDate)) - this.endDate = this.startDate.clone(); - - if (this.maxDate && this.endDate.isAfter(this.maxDate)) - this.endDate = this.maxDate.clone(); - - if (this.dateLimit && this.startDate.clone().add(this.dateLimit).isBefore(this.endDate)) - this.endDate = this.startDate.clone().add(this.dateLimit); - - this.previousRightTime = this.endDate.clone(); - - if (!this.isShowing) - this.updateElement(); - - this.updateMonthsInView(); - }, - - isInvalidDate: function() { - return false; - }, - - isCustomDate: function() { - return false; - }, - - updateView: function() { - if (this.timePicker) { - this.renderTimePicker('left'); - this.renderTimePicker('right'); - if (!this.endDate) { - this.container.find('.right .calendar-time select').attr('disabled', 'disabled').addClass('disabled'); - } else { - this.container.find('.right .calendar-time select').removeAttr('disabled').removeClass('disabled'); - } - } - if (this.endDate) { - this.container.find('input[name="daterangepicker_end"]').removeClass('active'); - this.container.find('input[name="daterangepicker_start"]').addClass('active'); - } else { - this.container.find('input[name="daterangepicker_end"]').addClass('active'); - this.container.find('input[name="daterangepicker_start"]').removeClass('active'); - } - this.updateMonthsInView(); - this.updateCalendars(); - this.updateFormInputs(); - }, - - updateMonthsInView: function() { - if (this.endDate) { - - //if both dates are visible already, do nothing - if (!this.singleDatePicker && this.leftCalendar.month && this.rightCalendar.month && - (this.startDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.startDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM')) - && - (this.endDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.endDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM')) - ) { - return; - } - - this.leftCalendar.month = this.startDate.clone().date(2); - if (!this.linkedCalendars && (this.endDate.month() != this.startDate.month() || this.endDate.year() != this.startDate.year())) { - this.rightCalendar.month = this.endDate.clone().date(2); - } else { - this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month'); - } - - } else { - if (this.leftCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM') && this.rightCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM')) { - this.leftCalendar.month = this.startDate.clone().date(2); - this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month'); - } - } - if (this.maxDate && this.linkedCalendars && !this.singleDatePicker && this.rightCalendar.month > this.maxDate) { - this.rightCalendar.month = this.maxDate.clone().date(2); - this.leftCalendar.month = this.maxDate.clone().date(2).subtract(1, 'month'); - } - }, - - updateCalendars: function() { - - if (this.timePicker) { - var hour, minute, second; - if (this.endDate) { - hour = parseInt(this.container.find('.left .hourselect').val(), 10); - minute = parseInt(this.container.find('.left .minuteselect').val(), 10); - second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0; - if (!this.timePicker24Hour) { - var ampm = this.container.find('.left .ampmselect').val(); - if (ampm === 'PM' && hour < 12) - hour += 12; - if (ampm === 'AM' && hour === 12) - hour = 0; - } - } else { - hour = parseInt(this.container.find('.right .hourselect').val(), 10); - minute = parseInt(this.container.find('.right .minuteselect').val(), 10); - second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0; - if (!this.timePicker24Hour) { - var ampm = this.container.find('.right .ampmselect').val(); - if (ampm === 'PM' && hour < 12) - hour += 12; - if (ampm === 'AM' && hour === 12) - hour = 0; - } - } - this.leftCalendar.month.hour(hour).minute(minute).second(second); - this.rightCalendar.month.hour(hour).minute(minute).second(second); - } - - this.renderCalendar('left'); - this.renderCalendar('right'); - - //highlight any predefined range matching the current start and end dates - this.container.find('.ranges li').removeClass('active'); - if (this.endDate == null) return; - - this.calculateChosenLabel(); - }, - - renderCalendar: function(side) { - - // - // Build the matrix of dates that will populate the calendar - // - - var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar; - var month = calendar.month.month(); - var year = calendar.month.year(); - var hour = calendar.month.hour(); - var minute = calendar.month.minute(); - var second = calendar.month.second(); - var daysInMonth = moment([year, month]).daysInMonth(); - var firstDay = moment([year, month, 1]); - var lastDay = moment([year, month, daysInMonth]); - var lastMonth = moment(firstDay).subtract(1, 'month').month(); - var lastYear = moment(firstDay).subtract(1, 'month').year(); - var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth(); - var dayOfWeek = firstDay.day(); - - //initialize a 6 rows x 7 columns array for the calendar - var calendar = []; - calendar.firstDay = firstDay; - calendar.lastDay = lastDay; - - for (var i = 0; i < 6; i++) { - calendar[i] = []; - } - - //populate the calendar with date objects - var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1; - if (startDay > daysInLastMonth) - startDay -= 7; - - if (dayOfWeek == this.locale.firstDay) - startDay = daysInLastMonth - 6; - - var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]); - - var col, row; - for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) { - if (i > 0 && col % 7 === 0) { - col = 0; - row++; - } - calendar[row][col] = curDate.clone().hour(hour).minute(minute).second(second); - curDate.hour(12); - - if (this.minDate && calendar[row][col].format('YYYY-MM-DD') == this.minDate.format('YYYY-MM-DD') && calendar[row][col].isBefore(this.minDate) && side == 'left') { - calendar[row][col] = this.minDate.clone(); - } - - if (this.maxDate && calendar[row][col].format('YYYY-MM-DD') == this.maxDate.format('YYYY-MM-DD') && calendar[row][col].isAfter(this.maxDate) && side == 'right') { - calendar[row][col] = this.maxDate.clone(); - } - - } - - //make the calendar object available to hoverDate/clickDate - if (side == 'left') { - this.leftCalendar.calendar = calendar; - } else { - this.rightCalendar.calendar = calendar; - } - - // - // Display the calendar - // - - var minDate = side == 'left' ? this.minDate : this.startDate; - var maxDate = this.maxDate; - var selected = side == 'left' ? this.startDate : this.endDate; - var arrow = this.locale.direction == 'ltr' ? {left: 'chevron-left', right: 'chevron-right'} : {left: 'chevron-right', right: 'chevron-left'}; - - var html = ''; - html += ''; - html += ''; - - // add empty cell for week number - if (this.showWeekNumbers || this.showISOWeekNumbers) - html += ''; - - if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) { - html += ''; - } else { - html += ''; - } - - var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY"); - - if (this.showDropdowns) { - var currentMonth = calendar[1][1].month(); - var currentYear = calendar[1][1].year(); - var maxYear = (maxDate && maxDate.year()) || (currentYear + 5); - var minYear = (minDate && minDate.year()) || (currentYear - 50); - var inMinYear = currentYear == minYear; - var inMaxYear = currentYear == maxYear; - - var monthHtml = '"; - - var yearHtml = ''; - - dateHtml = monthHtml + yearHtml; - } - - html += ''; - if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) { - html += ''; - } else { - html += ''; - } - - html += ''; - html += ''; - - // add week number label - if (this.showWeekNumbers || this.showISOWeekNumbers) - html += ''; - - $.each(this.locale.daysOfWeek, function(index, dayOfWeek) { - html += ''; - }); - - html += ''; - html += ''; - html += ''; - - //adjust maxDate to reflect the dateLimit setting in order to - //grey out end dates beyond the dateLimit - if (this.endDate == null && this.dateLimit) { - var maxLimit = this.startDate.clone().add(this.dateLimit).endOf('day'); - if (!maxDate || maxLimit.isBefore(maxDate)) { - maxDate = maxLimit; - } - } - - for (var row = 0; row < 6; row++) { - html += ''; - - // add week number - if (this.showWeekNumbers) - html += ''; - else if (this.showISOWeekNumbers) - html += ''; - - for (var col = 0; col < 7; col++) { - - var classes = []; - - //highlight today's date - if (calendar[row][col].isSame(new Date(), "day")) - classes.push('today'); - - //highlight weekends - if (calendar[row][col].isoWeekday() > 5) - classes.push('weekend'); - - //grey out the dates in other months displayed at beginning and end of this calendar - if (calendar[row][col].month() != calendar[1][1].month()) - classes.push('off'); - - //don't allow selection of dates before the minimum date - if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day')) - classes.push('off', 'disabled'); - - //don't allow selection of dates after the maximum date - if (maxDate && calendar[row][col].isAfter(maxDate, 'day')) - classes.push('off', 'disabled'); - - //don't allow selection of date if a custom function decides it's invalid - if (this.isInvalidDate(calendar[row][col])) - classes.push('off', 'disabled'); - - //highlight the currently selected start date - if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD')) - classes.push('active', 'start-date'); - - //highlight the currently selected end date - if (this.endDate != null && calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD')) - classes.push('active', 'end-date'); - - //highlight dates in-between the selected dates - if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate) - classes.push('in-range'); - - //apply custom classes for this date - var isCustom = this.isCustomDate(calendar[row][col]); - if (isCustom !== false) { - if (typeof isCustom === 'string') - classes.push(isCustom); - else - Array.prototype.push.apply(classes, isCustom); - } - - var cname = '', disabled = false; - for (var i = 0; i < classes.length; i++) { - cname += classes[i] + ' '; - if (classes[i] == 'disabled') - disabled = true; - } - if (!disabled) - cname += 'available'; - - html += ''; - - } - html += ''; - } - - html += ''; - html += '
' + dateHtml + '
' + this.locale.weekLabel + '' + dayOfWeek + '
' + calendar[row][0].week() + '' + calendar[row][0].isoWeek() + '' + calendar[row][col].date() + '
'; - - this.container.find('.calendar.' + side + ' .calendar-table').html(html); - - }, - - renderTimePicker: function(side) { - - // Don't bother updating the time picker if it's currently disabled - // because an end date hasn't been clicked yet - if (side == 'right' && !this.endDate) return; - - var html, selected, minDate, maxDate = this.maxDate; - - if (this.dateLimit && (!this.maxDate || this.startDate.clone().add(this.dateLimit).isAfter(this.maxDate))) - maxDate = this.startDate.clone().add(this.dateLimit); - - if (side == 'left') { - selected = this.startDate.clone(); - minDate = this.minDate; - } else if (side == 'right') { - selected = this.endDate.clone(); - minDate = this.startDate; - - //Preserve the time already selected - var timeSelector = this.container.find('.calendar.right .calendar-time div'); - if (timeSelector.html() != '') { - - selected.hour(timeSelector.find('.hourselect option:selected').val() || selected.hour()); - selected.minute(timeSelector.find('.minuteselect option:selected').val() || selected.minute()); - selected.second(timeSelector.find('.secondselect option:selected').val() || selected.second()); - - if (!this.timePicker24Hour) { - var ampm = timeSelector.find('.ampmselect option:selected').val(); - if (ampm === 'PM' && selected.hour() < 12) - selected.hour(selected.hour() + 12); - if (ampm === 'AM' && selected.hour() === 12) - selected.hour(0); - } - - } - - if (selected.isBefore(this.startDate)) - selected = this.startDate.clone(); - - if (maxDate && selected.isAfter(maxDate)) - selected = maxDate.clone(); - - } - - // - // hours - // - - html = ' '; - - // - // minutes - // - - html += ': '; - - // - // seconds - // - - if (this.timePickerSeconds) { - html += ': '; - } - - // - // AM/PM - // - - if (!this.timePicker24Hour) { - html += ''; - } - - this.container.find('.calendar.' + side + ' .calendar-time div').html(html); - - }, - - updateFormInputs: function() { - - //ignore mouse movements while an above-calendar text input has focus - if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus")) - return; - - this.container.find('input[name=daterangepicker_start]').val(this.startDate.format(this.locale.format)); - if (this.endDate) - this.container.find('input[name=daterangepicker_end]').val(this.endDate.format(this.locale.format)); - - if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) { - this.container.find('button.applyBtn').removeAttr('disabled'); - } else { - this.container.find('button.applyBtn').attr('disabled', 'disabled'); - } - - }, - - move: function() { - var parentOffset = { top: 0, left: 0 }, - containerTop; - var parentRightEdge = $(window).width(); - if (!this.parentEl.is('body')) { - parentOffset = { - top: this.parentEl.offset().top - this.parentEl.scrollTop(), - left: this.parentEl.offset().left - this.parentEl.scrollLeft() - }; - parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left; - } - - if (this.drops == 'up') - containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top; - else - containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top; - this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('dropup'); - - if (this.opens == 'left') { - this.container.css({ - top: containerTop, - right: parentRightEdge - this.element.offset().left - this.element.outerWidth(), - left: 'auto' - }); - if (this.container.offset().left < 0) { - this.container.css({ - right: 'auto', - left: 9 - }); - } - } else if (this.opens == 'center') { - this.container.css({ - top: containerTop, - left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2 - - this.container.outerWidth() / 2, - right: 'auto' - }); - if (this.container.offset().left < 0) { - this.container.css({ - right: 'auto', - left: 9 - }); - } - } else { - this.container.css({ - top: containerTop, - left: this.element.offset().left - parentOffset.left, - right: 'auto' - }); - if (this.container.offset().left + this.container.outerWidth() > $(window).width()) { - this.container.css({ - left: 'auto', - right: 0 - }); - } - } - }, - - show: function(e) { - if (this.isShowing) return; - - // Create a click proxy that is private to this instance of datepicker, for unbinding - this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this); - - // Bind global datepicker mousedown for hiding and - $(document) - .on('mousedown.daterangepicker', this._outsideClickProxy) - // also support mobile devices - .on('touchend.daterangepicker', this._outsideClickProxy) - // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them - .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy) - // and also close when focus changes to outside the picker (eg. tabbing between controls) - .on('focusin.daterangepicker', this._outsideClickProxy); - - // Reposition the picker if the window is resized while it's open - $(window).on('resize.daterangepicker', $.proxy(function(e) { this.move(e); }, this)); - - this.oldStartDate = this.startDate.clone(); - this.oldEndDate = this.endDate.clone(); - this.previousRightTime = this.endDate.clone(); - - this.updateView(); - this.container.show(); - this.move(); - this.element.trigger('show.daterangepicker', this); - this.isShowing = true; - }, - - hide: function(e) { - if (!this.isShowing) return; - - //incomplete date selection, revert to last values - if (!this.endDate) { - this.startDate = this.oldStartDate.clone(); - this.endDate = this.oldEndDate.clone(); - } - - //if a new date range was selected, invoke the user callback function - if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate)) - this.callback(this.startDate, this.endDate, this.chosenLabel); - - //if picker is attached to a text input, update it - this.updateElement(); - - $(document).off('.daterangepicker'); - $(window).off('.daterangepicker'); - this.container.hide(); - this.element.trigger('hide.daterangepicker', this); - this.isShowing = false; - }, - - toggle: function(e) { - if (this.isShowing) { - this.hide(); - } else { - this.show(); - } - }, - - outsideClick: function(e) { - var target = $(e.target); - // if the page is clicked anywhere except within the daterangerpicker/button - // itself then call this.hide() - if ( - // ie modal dialog fix - e.type == "focusin" || - target.closest(this.element).length || - target.closest(this.container).length || - target.closest('.calendar-table').length - ) return; - this.hide(); - this.element.trigger('outsideClick.daterangepicker', this); - }, - - showCalendars: function() { - this.container.addClass('show-calendar'); - this.move(); - this.element.trigger('showCalendar.daterangepicker', this); - }, - - hideCalendars: function() { - this.container.removeClass('show-calendar'); - this.element.trigger('hideCalendar.daterangepicker', this); - }, - - hoverRange: function(e) { - - //ignore mouse movements while an above-calendar text input has focus - if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus")) - return; - - var label = e.target.getAttribute('data-range-key'); - - if (label == this.locale.customRangeLabel) { - this.updateView(); - } else { - var dates = this.ranges[label]; - this.container.find('input[name=daterangepicker_start]').val(dates[0].format(this.locale.format)); - this.container.find('input[name=daterangepicker_end]').val(dates[1].format(this.locale.format)); - } - - }, - - clickRange: function(e) { - var label = e.target.getAttribute('data-range-key'); - this.chosenLabel = label; - if (label == this.locale.customRangeLabel) { - this.showCalendars(); - } else { - var dates = this.ranges[label]; - this.startDate = dates[0]; - this.endDate = dates[1]; - - if (!this.timePicker) { - this.startDate.startOf('day'); - this.endDate.endOf('day'); - } - - if (!this.alwaysShowCalendars) - this.hideCalendars(); - this.clickApply(); - } - }, - - clickPrev: function(e) { - var cal = $(e.target).parents('.calendar'); - if (cal.hasClass('left')) { - this.leftCalendar.month.subtract(1, 'month'); - if (this.linkedCalendars) - this.rightCalendar.month.subtract(1, 'month'); - } else { - this.rightCalendar.month.subtract(1, 'month'); - } - this.updateCalendars(); - }, - - clickNext: function(e) { - var cal = $(e.target).parents('.calendar'); - if (cal.hasClass('left')) { - this.leftCalendar.month.add(1, 'month'); - } else { - this.rightCalendar.month.add(1, 'month'); - if (this.linkedCalendars) - this.leftCalendar.month.add(1, 'month'); - } - this.updateCalendars(); - }, - - hoverDate: function(e) { - - //ignore mouse movements while an above-calendar text input has focus - //if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus")) - // return; - - //ignore dates that can't be selected - if (!$(e.target).hasClass('available')) return; - - //have the text inputs above calendars reflect the date being hovered over - var title = $(e.target).attr('data-title'); - var row = title.substr(1, 1); - var col = title.substr(3, 1); - var cal = $(e.target).parents('.calendar'); - var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col]; - - if (this.endDate && !this.container.find('input[name=daterangepicker_start]').is(":focus")) { - this.container.find('input[name=daterangepicker_start]').val(date.format(this.locale.format)); - } else if (!this.endDate && !this.container.find('input[name=daterangepicker_end]').is(":focus")) { - this.container.find('input[name=daterangepicker_end]').val(date.format(this.locale.format)); - } - - //highlight the dates between the start date and the date being hovered as a potential end date - var leftCalendar = this.leftCalendar; - var rightCalendar = this.rightCalendar; - var startDate = this.startDate; - if (!this.endDate) { - this.container.find('.calendar tbody td').each(function(index, el) { - - //skip week numbers, only look at dates - if ($(el).hasClass('week')) return; - - var title = $(el).attr('data-title'); - var row = title.substr(1, 1); - var col = title.substr(3, 1); - var cal = $(el).parents('.calendar'); - var dt = cal.hasClass('left') ? leftCalendar.calendar[row][col] : rightCalendar.calendar[row][col]; - - if ((dt.isAfter(startDate) && dt.isBefore(date)) || dt.isSame(date, 'day')) { - $(el).addClass('in-range'); - } else { - $(el).removeClass('in-range'); - } - - }); - } - - }, - - clickDate: function(e) { - - if (!$(e.target).hasClass('available')) return; - - var title = $(e.target).attr('data-title'); - var row = title.substr(1, 1); - var col = title.substr(3, 1); - var cal = $(e.target).parents('.calendar'); - var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col]; - - // - // this function needs to do a few things: - // * alternate between selecting a start and end date for the range, - // * if the time picker is enabled, apply the hour/minute/second from the select boxes to the clicked date - // * if autoapply is enabled, and an end date was chosen, apply the selection - // * if single date picker mode, and time picker isn't enabled, apply the selection immediately - // * if one of the inputs above the calendars was focused, cancel that manual input - // - - if (this.endDate || date.isBefore(this.startDate, 'day')) { //picking start - if (this.timePicker) { - var hour = parseInt(this.container.find('.left .hourselect').val(), 10); - if (!this.timePicker24Hour) { - var ampm = this.container.find('.left .ampmselect').val(); - if (ampm === 'PM' && hour < 12) - hour += 12; - if (ampm === 'AM' && hour === 12) - hour = 0; - } - var minute = parseInt(this.container.find('.left .minuteselect').val(), 10); - var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0; - date = date.clone().hour(hour).minute(minute).second(second); - } - this.endDate = null; - this.setStartDate(date.clone()); - } else if (!this.endDate && date.isBefore(this.startDate)) { - //special case: clicking the same date for start/end, - //but the time of the end date is before the start date - this.setEndDate(this.startDate.clone()); - } else { // picking end - if (this.timePicker) { - var hour = parseInt(this.container.find('.right .hourselect').val(), 10); - if (!this.timePicker24Hour) { - var ampm = this.container.find('.right .ampmselect').val(); - if (ampm === 'PM' && hour < 12) - hour += 12; - if (ampm === 'AM' && hour === 12) - hour = 0; - } - var minute = parseInt(this.container.find('.right .minuteselect').val(), 10); - var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0; - date = date.clone().hour(hour).minute(minute).second(second); - } - this.setEndDate(date.clone()); - if (this.autoApply) { - this.calculateChosenLabel(); - this.clickApply(); - } - } - - if (this.singleDatePicker) { - this.setEndDate(this.startDate); - if (!this.timePicker) - this.clickApply(); - } - - this.updateView(); - - //This is to cancel the blur event handler if the mouse was in one of the inputs - e.stopPropagation(); - - }, - - calculateChosenLabel: function () { - var customRange = true; - var i = 0; - for (var range in this.ranges) { - if (this.timePicker) { - var format = this.timePickerSeconds ? "YYYY-MM-DD hh:mm:ss" : "YYYY-MM-DD hh:mm"; - //ignore times when comparing dates if time picker seconds is not enabled - if (this.startDate.format(format) == this.ranges[range][0].format(format) && this.endDate.format(format) == this.ranges[range][1].format(format)) { - customRange = false; - this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html(); - break; - } - } else { - //ignore times when comparing dates if time picker is not enabled - 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')) { - customRange = false; - this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html(); - break; - } - } - i++; - } - if (customRange) { - if (this.showCustomRangeLabel) { - this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html(); - } else { - this.chosenLabel = null; - } - this.showCalendars(); - } - }, - - clickApply: function(e) { - this.hide(); - this.element.trigger('apply.daterangepicker', this); - }, - - clickCancel: function(e) { - this.startDate = this.oldStartDate; - this.endDate = this.oldEndDate; - this.hide(); - this.element.trigger('cancel.daterangepicker', this); - }, - - monthOrYearChanged: function(e) { - var isLeft = $(e.target).closest('.calendar').hasClass('left'), - leftOrRight = isLeft ? 'left' : 'right', - cal = this.container.find('.calendar.'+leftOrRight); - - // Month must be Number for new moment versions - var month = parseInt(cal.find('.monthselect').val(), 10); - var year = cal.find('.yearselect').val(); - - if (!isLeft) { - if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) { - month = this.startDate.month(); - year = this.startDate.year(); - } - } - - if (this.minDate) { - if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) { - month = this.minDate.month(); - year = this.minDate.year(); - } - } - - if (this.maxDate) { - if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) { - month = this.maxDate.month(); - year = this.maxDate.year(); - } - } - - if (isLeft) { - this.leftCalendar.month.month(month).year(year); - if (this.linkedCalendars) - this.rightCalendar.month = this.leftCalendar.month.clone().add(1, 'month'); - } else { - this.rightCalendar.month.month(month).year(year); - if (this.linkedCalendars) - this.leftCalendar.month = this.rightCalendar.month.clone().subtract(1, 'month'); - } - this.updateCalendars(); - }, - - timeChanged: function(e) { - - var cal = $(e.target).closest('.calendar'), - isLeft = cal.hasClass('left'); - - var hour = parseInt(cal.find('.hourselect').val(), 10); - var minute = parseInt(cal.find('.minuteselect').val(), 10); - var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0; - - if (!this.timePicker24Hour) { - var ampm = cal.find('.ampmselect').val(); - if (ampm === 'PM' && hour < 12) - hour += 12; - if (ampm === 'AM' && hour === 12) - hour = 0; - } - - if (isLeft) { - var start = this.startDate.clone(); - start.hour(hour); - start.minute(minute); - start.second(second); - this.setStartDate(start); - if (this.singleDatePicker) { - this.endDate = this.startDate.clone(); - } else if (this.endDate && this.endDate.format('YYYY-MM-DD') == start.format('YYYY-MM-DD') && this.endDate.isBefore(start)) { - this.setEndDate(start.clone()); - } - } else if (this.endDate) { - var end = this.endDate.clone(); - end.hour(hour); - end.minute(minute); - end.second(second); - this.setEndDate(end); - } - - //update the calendars so all clickable dates reflect the new time component - this.updateCalendars(); - - //update the form inputs above the calendars with the new time - this.updateFormInputs(); - - //re-render the time pickers because changing one selection can affect what's enabled in another - this.renderTimePicker('left'); - this.renderTimePicker('right'); - - }, - - formInputsChanged: function(e) { - var isRight = $(e.target).closest('.calendar').hasClass('right'); - var start = moment(this.container.find('input[name="daterangepicker_start"]').val(), this.locale.format); - var end = moment(this.container.find('input[name="daterangepicker_end"]').val(), this.locale.format); - - if (start.isValid() && end.isValid()) { - - if (isRight && end.isBefore(start)) - start = end.clone(); - - this.setStartDate(start); - this.setEndDate(end); - - if (isRight) { - this.container.find('input[name="daterangepicker_start"]').val(this.startDate.format(this.locale.format)); - } else { - this.container.find('input[name="daterangepicker_end"]').val(this.endDate.format(this.locale.format)); - } - - } - - this.updateView(); - }, - - formInputsFocused: function(e) { - - // Highlight the focused input - this.container.find('input[name="daterangepicker_start"], input[name="daterangepicker_end"]').removeClass('active'); - $(e.target).addClass('active'); - - // Set the state such that if the user goes back to using a mouse, - // the calendars are aware we're selecting the end of the range, not - // the start. This allows someone to edit the end of a date range without - // re-selecting the beginning, by clicking on the end date input then - // using the calendar. - var isRight = $(e.target).closest('.calendar').hasClass('right'); - if (isRight) { - this.endDate = null; - this.setStartDate(this.startDate.clone()); - this.updateView(); - } - - }, - - formInputsBlurred: function(e) { - - // this function has one purpose right now: if you tab from the first - // text input to the second in the UI, the endDate is nulled so that - // you can click another, but if you tab out without clicking anything - // or changing the input value, the old endDate should be retained - - if (!this.endDate) { - var val = this.container.find('input[name="daterangepicker_end"]').val(); - var end = moment(val, this.locale.format); - if (end.isValid()) { - this.setEndDate(end); - this.updateView(); - } - } - - }, - - formInputsKeydown: function(e) { - // This function ensures that if the 'enter' key was pressed in the input, then the calendars - // are updated with the startDate and endDate. - // This behaviour is automatic in Chrome/Firefox/Edge but not in IE 11 hence why this exists. - // Other browsers and versions of IE are untested and the behaviour is unknown. - if (e.keyCode === 13) { - // Prevent the calendar from being updated twice on Chrome/Firefox/Edge - e.preventDefault(); - this.formInputsChanged(e); - } - }, - - - elementChanged: function() { - if (!this.element.is('input')) return; - if (!this.element.val().length) return; - - var dateString = this.element.val().split(this.locale.separator), - start = null, - end = null; - - if (dateString.length === 2) { - start = moment(dateString[0], this.locale.format); - end = moment(dateString[1], this.locale.format); - } - - if (this.singleDatePicker || start === null || end === null) { - start = moment(this.element.val(), this.locale.format); - end = start; - } - - if (!start.isValid() || !end.isValid()) return; - - this.setStartDate(start); - this.setEndDate(end); - this.updateView(); - }, - - keydown: function(e) { - //hide on tab or enter - if ((e.keyCode === 9) || (e.keyCode === 13)) { - this.hide(); - } - - //hide on esc and prevent propagation - if (e.keyCode === 27) { - e.preventDefault(); - e.stopPropagation(); - - this.hide(); - } - }, - - updateElement: function() { - if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) { - this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format)); - this.element.trigger('change'); - } else if (this.element.is('input') && this.autoUpdateInput) { - this.element.val(this.startDate.format(this.locale.format)); - this.element.trigger('change'); - } - }, - - remove: function() { - this.container.remove(); - this.element.off('.daterangepicker'); - this.element.removeData(); - } - - }; - - $.fn.daterangepicker = function(options, callback) { - var implementOptions = $.extend(true, {}, $.fn.daterangepicker.defaultOptions, options); - this.each(function() { - var el = $(this); - if (el.data('daterangepicker')) - el.data('daterangepicker').remove(); - el.data('daterangepicker', new DateRangePicker(el, implementOptions, callback)); - }); - return this; - }; - - return DateRangePicker; - -})); +/** +* @version: 2.1.30 +* @author: Dan Grossman http://www.dangrossman.info/ +* @copyright: Copyright (c) 2012-2017 Dan Grossman. All rights reserved. +* @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php +* @website: http://www.daterangepicker.com/ +*/ +// Follow the UMD template https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Make globaly available as well + define(['moment', 'jquery'], function (moment, jquery) { + if (!jquery.fn) jquery.fn = {}; // webpack server rendering + return factory(moment, jquery); + }); + } else if (typeof module === 'object' && module.exports) { + // Node / Browserify + //isomorphic issue + var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined; + if (!jQuery) { + jQuery = require('jquery'); + if (!jQuery.fn) jQuery.fn = {}; + } + var moment = (typeof window != 'undefined' && typeof window.moment != 'undefined') ? window.moment : require('moment'); + module.exports = factory(moment, jQuery); + } else { + // Browser globals + root.daterangepicker = factory(root.moment, root.jQuery); + } +}(this, function(moment, $) { + var DateRangePicker = function(element, options, cb) { + + //default settings for options + this.parentEl = 'body'; + this.element = $(element); + this.startDate = moment().startOf('day'); + this.endDate = moment().endOf('day'); + this.minDate = false; + this.maxDate = false; + this.dateLimit = false; + this.autoApply = false; + this.singleDatePicker = false; + this.showDropdowns = false; + this.showWeekNumbers = false; + this.showISOWeekNumbers = false; + this.showCustomRangeLabel = true; + this.timePicker = false; + this.timePicker24Hour = false; + this.timePickerIncrement = 1; + this.timePickerSeconds = false; + this.linkedCalendars = true; + this.autoUpdateInput = true; + this.alwaysShowCalendars = false; + this.ranges = {}; + + this.opens = 'right'; + if (this.element.hasClass('pull-right')) + this.opens = 'left'; + + this.drops = 'down'; + if (this.element.hasClass('dropup')) + this.drops = 'up'; + + this.buttonClasses = 'btn btn-sm'; + this.applyClass = 'btn-success'; + this.cancelClass = 'btn-default'; + + this.locale = { + direction: 'ltr', + format: moment.localeData().longDateFormat('L'), + separator: ' - ', + applyLabel: 'Apply', + cancelLabel: 'Cancel', + weekLabel: 'W', + customRangeLabel: 'Custom Range', + daysOfWeek: moment.weekdaysMin(), + monthNames: moment.monthsShort(), + firstDay: moment.localeData().firstDayOfWeek() + }; + + this.callback = function() { }; + + //some state information + this.isShowing = false; + this.leftCalendar = {}; + this.rightCalendar = {}; + + //custom options from user + if (typeof options !== 'object' || options === null) + options = {}; + + //allow setting options with data attributes + //data-api options will be overwritten with custom javascript options + options = $.extend(this.element.data(), options); + + //html template for the picker UI + if (typeof options.template !== 'string' && !(options.template instanceof $)) + options.template = ''; + + this.parentEl = (options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl); + this.container = $(options.template).appendTo(this.parentEl); + + // + // handle all the possible options overriding defaults + // + + if (typeof options.locale === 'object') { + + if (typeof options.locale.direction === 'string') + this.locale.direction = options.locale.direction; + + if (typeof options.locale.format === 'string') + this.locale.format = options.locale.format; + + if (typeof options.locale.separator === 'string') + this.locale.separator = options.locale.separator; + + if (typeof options.locale.daysOfWeek === 'object') + this.locale.daysOfWeek = options.locale.daysOfWeek.slice(); + + if (typeof options.locale.monthNames === 'object') + this.locale.monthNames = options.locale.monthNames.slice(); + + if (typeof options.locale.firstDay === 'number') + this.locale.firstDay = options.locale.firstDay; + + if (typeof options.locale.applyLabel === 'string') + this.locale.applyLabel = options.locale.applyLabel; + + if (typeof options.locale.cancelLabel === 'string') + this.locale.cancelLabel = options.locale.cancelLabel; + + if (typeof options.locale.weekLabel === 'string') + this.locale.weekLabel = options.locale.weekLabel; + + if (typeof options.locale.customRangeLabel === 'string'){ + //Support unicode chars in the custom range name. + var elem = document.createElement('textarea'); + elem.innerHTML = options.locale.customRangeLabel; + var rangeHtml = elem.value; + this.locale.customRangeLabel = rangeHtml; + } + } + this.container.addClass(this.locale.direction); + + if (typeof options.startDate === 'string') + this.startDate = moment(options.startDate, this.locale.format); + + if (typeof options.endDate === 'string') + this.endDate = moment(options.endDate, this.locale.format); + + if (typeof options.minDate === 'string') + this.minDate = moment(options.minDate, this.locale.format); + + if (typeof options.maxDate === 'string') + this.maxDate = moment(options.maxDate, this.locale.format); + + if (typeof options.startDate === 'object') + this.startDate = moment(options.startDate); + + if (typeof options.endDate === 'object') + this.endDate = moment(options.endDate); + + if (typeof options.minDate === 'object') + this.minDate = moment(options.minDate); + + if (typeof options.maxDate === 'object') + this.maxDate = moment(options.maxDate); + + // sanity check for bad options + if (this.minDate && this.startDate.isBefore(this.minDate)) + this.startDate = this.minDate.clone(); + + // sanity check for bad options + if (this.maxDate && this.endDate.isAfter(this.maxDate)) + this.endDate = this.maxDate.clone(); + + if (typeof options.applyClass === 'string') + this.applyClass = options.applyClass; + + if (typeof options.cancelClass === 'string') + this.cancelClass = options.cancelClass; + + if (typeof options.dateLimit === 'object') + this.dateLimit = options.dateLimit; + + if (typeof options.opens === 'string') + this.opens = options.opens; + + if (typeof options.drops === 'string') + this.drops = options.drops; + + if (typeof options.showWeekNumbers === 'boolean') + this.showWeekNumbers = options.showWeekNumbers; + + if (typeof options.showISOWeekNumbers === 'boolean') + this.showISOWeekNumbers = options.showISOWeekNumbers; + + if (typeof options.buttonClasses === 'string') + this.buttonClasses = options.buttonClasses; + + if (typeof options.buttonClasses === 'object') + this.buttonClasses = options.buttonClasses.join(' '); + + if (typeof options.showDropdowns === 'boolean') + this.showDropdowns = options.showDropdowns; + + if (typeof options.showCustomRangeLabel === 'boolean') + this.showCustomRangeLabel = options.showCustomRangeLabel; + + if (typeof options.singleDatePicker === 'boolean') { + this.singleDatePicker = options.singleDatePicker; + if (this.singleDatePicker) + this.endDate = this.startDate.clone(); + } + + if (typeof options.timePicker === 'boolean') + this.timePicker = options.timePicker; + + if (typeof options.timePickerSeconds === 'boolean') + this.timePickerSeconds = options.timePickerSeconds; + + if (typeof options.timePickerIncrement === 'number') + this.timePickerIncrement = options.timePickerIncrement; + + if (typeof options.timePicker24Hour === 'boolean') + this.timePicker24Hour = options.timePicker24Hour; + + if (typeof options.autoApply === 'boolean') + this.autoApply = options.autoApply; + + if (typeof options.autoUpdateInput === 'boolean') + this.autoUpdateInput = options.autoUpdateInput; + + if (typeof options.linkedCalendars === 'boolean') + this.linkedCalendars = options.linkedCalendars; + + if (typeof options.isInvalidDate === 'function') + this.isInvalidDate = options.isInvalidDate; + + if (typeof options.isCustomDate === 'function') + this.isCustomDate = options.isCustomDate; + + if (typeof options.alwaysShowCalendars === 'boolean') + this.alwaysShowCalendars = options.alwaysShowCalendars; + + // update day names order to firstDay + if (this.locale.firstDay != 0) { + var iterator = this.locale.firstDay; + while (iterator > 0) { + this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift()); + iterator--; + } + } + + var start, end, range; + + //if no start/end dates set, check if an input element contains initial values + if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') { + if ($(this.element).is('input[type=text]')) { + var val = $(this.element).val(), + split = val.split(this.locale.separator); + + start = end = null; + + if (split.length == 2) { + start = moment(split[0], this.locale.format); + end = moment(split[1], this.locale.format); + } else if (this.singleDatePicker && val !== "") { + start = moment(val, this.locale.format); + end = moment(val, this.locale.format); + } + if (start !== null && end !== null) { + this.setStartDate(start); + this.setEndDate(end); + } + } + } + + if (typeof options.ranges === 'object') { + for (range in options.ranges) { + + if (typeof options.ranges[range][0] === 'string') + start = moment(options.ranges[range][0], this.locale.format); + else + start = moment(options.ranges[range][0]); + + if (typeof options.ranges[range][1] === 'string') + end = moment(options.ranges[range][1], this.locale.format); + else + end = moment(options.ranges[range][1]); + + // If the start or end date exceed those allowed by the minDate or dateLimit + // options, shorten the range to the allowable period. + if (this.minDate && start.isBefore(this.minDate)) + start = this.minDate.clone(); + + var maxDate = this.maxDate; + if (this.dateLimit && maxDate && start.clone().add(this.dateLimit).isAfter(maxDate)) + maxDate = start.clone().add(this.dateLimit); + if (maxDate && end.isAfter(maxDate)) + end = maxDate.clone(); + + // If the end of the range is before the minimum or the start of the range is + // after the maximum, don't display this range option at all. + if ((this.minDate && end.isBefore(this.minDate, this.timepicker ? 'minute' : 'day')) + || (maxDate && start.isAfter(maxDate, this.timepicker ? 'minute' : 'day'))) + continue; + + //Support unicode chars in the range names. + var elem = document.createElement('textarea'); + elem.innerHTML = range; + var rangeHtml = elem.value; + + this.ranges[rangeHtml] = [start, end]; + } + + var list = '
    '; + for (range in this.ranges) { + list += '
  • ' + range + '
  • '; + } + if (this.showCustomRangeLabel) { + list += '
  • ' + this.locale.customRangeLabel + '
  • '; + } + list += '
'; + this.container.find('.ranges').prepend(list); + } + + if (typeof cb === 'function') { + this.callback = cb; + } + + if (!this.timePicker) { + this.startDate = this.startDate.startOf('day'); + this.endDate = this.endDate.endOf('day'); + this.container.find('.calendar-time').hide(); + } + + //can't be used together for now + if (this.timePicker && this.autoApply) + this.autoApply = false; + + if (this.autoApply && typeof options.ranges !== 'object') { + this.container.find('.ranges').hide(); + } else if (this.autoApply) { + this.container.find('.applyBtn, .cancelBtn').addClass('hide'); + } + + if (this.singleDatePicker) { + this.container.addClass('single'); + this.container.find('.calendar.left').addClass('single'); + this.container.find('.calendar.left').show(); + this.container.find('.calendar.right').hide(); + this.container.find('.daterangepicker_input input, .daterangepicker_input > i').hide(); + if (this.timePicker) { + this.container.find('.ranges ul').hide(); + } else { + this.container.find('.ranges').hide(); + } + } + + if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars) { + this.container.addClass('show-calendar'); + } + + this.container.addClass('opens' + this.opens); + + //swap the position of the predefined ranges if opens right + if (typeof options.ranges !== 'undefined' && this.opens == 'right') { + this.container.find('.ranges').prependTo( this.container.find('.calendar.left').parent() ); + } + + //apply CSS classes and labels to buttons + this.container.find('.applyBtn, .cancelBtn').addClass(this.buttonClasses); + if (this.applyClass.length) + this.container.find('.applyBtn').addClass(this.applyClass); + if (this.cancelClass.length) + this.container.find('.cancelBtn').addClass(this.cancelClass); + this.container.find('.applyBtn').html(this.locale.applyLabel); + this.container.find('.cancelBtn').html(this.locale.cancelLabel); + + // + // event listeners + // + + this.container.find('.calendar') + .on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this)) + .on('click.daterangepicker', '.next', $.proxy(this.clickNext, this)) + .on('mousedown.daterangepicker', 'td.available', $.proxy(this.clickDate, this)) + .on('mouseenter.daterangepicker', 'td.available', $.proxy(this.hoverDate, this)) + .on('mouseleave.daterangepicker', 'td.available', $.proxy(this.updateFormInputs, this)) + .on('change.daterangepicker', 'select.yearselect', $.proxy(this.monthOrYearChanged, this)) + .on('change.daterangepicker', 'select.monthselect', $.proxy(this.monthOrYearChanged, this)) + .on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.secondselect,select.ampmselect', $.proxy(this.timeChanged, this)) + .on('click.daterangepicker', '.daterangepicker_input input', $.proxy(this.showCalendars, this)) + .on('focus.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsFocused, this)) + .on('blur.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsBlurred, this)) + .on('change.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this)) + .on('keydown.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsKeydown, this)); + + this.container.find('.ranges') + .on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this)) + .on('click.daterangepicker', 'button.cancelBtn', $.proxy(this.clickCancel, this)) + .on('click.daterangepicker', 'li', $.proxy(this.clickRange, this)) + .on('mouseenter.daterangepicker', 'li', $.proxy(this.hoverRange, this)) + .on('mouseleave.daterangepicker', 'li', $.proxy(this.updateFormInputs, this)); + + if (this.element.is('input') || this.element.is('button')) { + this.element.on({ + 'click.daterangepicker': $.proxy(this.show, this), + 'focus.daterangepicker': $.proxy(this.show, this), + 'keyup.daterangepicker': $.proxy(this.elementChanged, this), + 'keydown.daterangepicker': $.proxy(this.keydown, this) //IE 11 compatibility + }); + } else { + this.element.on('click.daterangepicker', $.proxy(this.toggle, this)); + this.element.on('keydown.daterangepicker', $.proxy(this.toggle, this)); + } + + // + // if attached to a text input, set the initial value + // + + if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) { + this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format)); + this.element.trigger('change'); + } else if (this.element.is('input') && this.autoUpdateInput) { + this.element.val(this.startDate.format(this.locale.format)); + this.element.trigger('change'); + } + + }; + + DateRangePicker.prototype = { + + constructor: DateRangePicker, + + setStartDate: function(startDate) { + if (typeof startDate === 'string') + this.startDate = moment(startDate, this.locale.format); + + if (typeof startDate === 'object') + this.startDate = moment(startDate); + + if (!this.timePicker) + this.startDate = this.startDate.startOf('day'); + + if (this.timePicker && this.timePickerIncrement) + this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement); + + if (this.minDate && this.startDate.isBefore(this.minDate)) { + this.startDate = this.minDate.clone(); + if (this.timePicker && this.timePickerIncrement) + this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement); + } + + if (this.maxDate && this.startDate.isAfter(this.maxDate)) { + this.startDate = this.maxDate.clone(); + if (this.timePicker && this.timePickerIncrement) + this.startDate.minute(Math.floor(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement); + } + + if (!this.isShowing) + this.updateElement(); + + this.updateMonthsInView(); + }, + + setEndDate: function(endDate) { + if (typeof endDate === 'string') + this.endDate = moment(endDate, this.locale.format); + + if (typeof endDate === 'object') + this.endDate = moment(endDate); + + if (!this.timePicker) + this.endDate = this.endDate.add(1,'d').startOf('day').subtract(1,'second'); + + if (this.timePicker && this.timePickerIncrement) + this.endDate.minute(Math.round(this.endDate.minute() / this.timePickerIncrement) * this.timePickerIncrement); + + if (this.endDate.isBefore(this.startDate)) + this.endDate = this.startDate.clone(); + + if (this.maxDate && this.endDate.isAfter(this.maxDate)) + this.endDate = this.maxDate.clone(); + + if (this.dateLimit && this.startDate.clone().add(this.dateLimit).isBefore(this.endDate)) + this.endDate = this.startDate.clone().add(this.dateLimit); + + this.previousRightTime = this.endDate.clone(); + + if (!this.isShowing) + this.updateElement(); + + this.updateMonthsInView(); + }, + + isInvalidDate: function() { + return false; + }, + + isCustomDate: function() { + return false; + }, + + updateView: function() { + if (this.timePicker) { + this.renderTimePicker('left'); + this.renderTimePicker('right'); + if (!this.endDate) { + this.container.find('.right .calendar-time select').attr('disabled', 'disabled').addClass('disabled'); + } else { + this.container.find('.right .calendar-time select').removeAttr('disabled').removeClass('disabled'); + } + } + if (this.endDate) { + this.container.find('input[name="daterangepicker_end"]').removeClass('active'); + this.container.find('input[name="daterangepicker_start"]').addClass('active'); + } else { + this.container.find('input[name="daterangepicker_end"]').addClass('active'); + this.container.find('input[name="daterangepicker_start"]').removeClass('active'); + } + this.updateMonthsInView(); + this.updateCalendars(); + this.updateFormInputs(); + }, + + updateMonthsInView: function() { + if (this.endDate) { + + //if both dates are visible already, do nothing + if (!this.singleDatePicker && this.leftCalendar.month && this.rightCalendar.month && + (this.startDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.startDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM')) + && + (this.endDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.endDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM')) + ) { + return; + } + + this.leftCalendar.month = this.startDate.clone().date(2); + if (!this.linkedCalendars && (this.endDate.month() != this.startDate.month() || this.endDate.year() != this.startDate.year())) { + this.rightCalendar.month = this.endDate.clone().date(2); + } else { + this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month'); + } + + } else { + if (this.leftCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM') && this.rightCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM')) { + this.leftCalendar.month = this.startDate.clone().date(2); + this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month'); + } + } + if (this.maxDate && this.linkedCalendars && !this.singleDatePicker && this.rightCalendar.month > this.maxDate) { + this.rightCalendar.month = this.maxDate.clone().date(2); + this.leftCalendar.month = this.maxDate.clone().date(2).subtract(1, 'month'); + } + }, + + updateCalendars: function() { + + if (this.timePicker) { + var hour, minute, second; + if (this.endDate) { + hour = parseInt(this.container.find('.left .hourselect').val(), 10); + minute = parseInt(this.container.find('.left .minuteselect').val(), 10); + second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0; + if (!this.timePicker24Hour) { + var ampm = this.container.find('.left .ampmselect').val(); + if (ampm === 'PM' && hour < 12) + hour += 12; + if (ampm === 'AM' && hour === 12) + hour = 0; + } + } else { + hour = parseInt(this.container.find('.right .hourselect').val(), 10); + minute = parseInt(this.container.find('.right .minuteselect').val(), 10); + second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0; + if (!this.timePicker24Hour) { + var ampm = this.container.find('.right .ampmselect').val(); + if (ampm === 'PM' && hour < 12) + hour += 12; + if (ampm === 'AM' && hour === 12) + hour = 0; + } + } + this.leftCalendar.month.hour(hour).minute(minute).second(second); + this.rightCalendar.month.hour(hour).minute(minute).second(second); + } + + this.renderCalendar('left'); + this.renderCalendar('right'); + + //highlight any predefined range matching the current start and end dates + this.container.find('.ranges li').removeClass('active'); + if (this.endDate == null) return; + + this.calculateChosenLabel(); + }, + + renderCalendar: function(side) { + + // + // Build the matrix of dates that will populate the calendar + // + + var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar; + var month = calendar.month.month(); + var year = calendar.month.year(); + var hour = calendar.month.hour(); + var minute = calendar.month.minute(); + var second = calendar.month.second(); + var daysInMonth = moment([year, month]).daysInMonth(); + var firstDay = moment([year, month, 1]); + var lastDay = moment([year, month, daysInMonth]); + var lastMonth = moment(firstDay).subtract(1, 'month').month(); + var lastYear = moment(firstDay).subtract(1, 'month').year(); + var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth(); + var dayOfWeek = firstDay.day(); + + //initialize a 6 rows x 7 columns array for the calendar + var calendar = []; + calendar.firstDay = firstDay; + calendar.lastDay = lastDay; + + for (var i = 0; i < 6; i++) { + calendar[i] = []; + } + + //populate the calendar with date objects + var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1; + if (startDay > daysInLastMonth) + startDay -= 7; + + if (dayOfWeek == this.locale.firstDay) + startDay = daysInLastMonth - 6; + + var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]); + + var col, row; + for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) { + if (i > 0 && col % 7 === 0) { + col = 0; + row++; + } + calendar[row][col] = curDate.clone().hour(hour).minute(minute).second(second); + curDate.hour(12); + + if (this.minDate && calendar[row][col].format('YYYY-MM-DD') == this.minDate.format('YYYY-MM-DD') && calendar[row][col].isBefore(this.minDate) && side == 'left') { + calendar[row][col] = this.minDate.clone(); + } + + if (this.maxDate && calendar[row][col].format('YYYY-MM-DD') == this.maxDate.format('YYYY-MM-DD') && calendar[row][col].isAfter(this.maxDate) && side == 'right') { + calendar[row][col] = this.maxDate.clone(); + } + + } + + //make the calendar object available to hoverDate/clickDate + if (side == 'left') { + this.leftCalendar.calendar = calendar; + } else { + this.rightCalendar.calendar = calendar; + } + + // + // Display the calendar + // + + var minDate = side == 'left' ? this.minDate : this.startDate; + var maxDate = this.maxDate; + var selected = side == 'left' ? this.startDate : this.endDate; + var arrow = this.locale.direction == 'ltr' ? {left: 'chevron-left', right: 'chevron-right'} : {left: 'chevron-right', right: 'chevron-left'}; + + var html = ''; + html += ''; + html += ''; + + // add empty cell for week number + if (this.showWeekNumbers || this.showISOWeekNumbers) + html += ''; + + if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) { + html += ''; + } else { + html += ''; + } + + var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY"); + + if (this.showDropdowns) { + var currentMonth = calendar[1][1].month(); + var currentYear = calendar[1][1].year(); + var maxYear = (maxDate && maxDate.year()) || (currentYear + 5); + var minYear = (minDate && minDate.year()) || (currentYear - 50); + var inMinYear = currentYear == minYear; + var inMaxYear = currentYear == maxYear; + + var monthHtml = '"; + + var yearHtml = ''; + + dateHtml = monthHtml + yearHtml; + } + + html += ''; + if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) { + html += ''; + } else { + html += ''; + } + + html += ''; + html += ''; + + // add week number label + if (this.showWeekNumbers || this.showISOWeekNumbers) + html += ''; + + $.each(this.locale.daysOfWeek, function(index, dayOfWeek) { + html += ''; + }); + + html += ''; + html += ''; + html += ''; + + //adjust maxDate to reflect the dateLimit setting in order to + //grey out end dates beyond the dateLimit + if (this.endDate == null && this.dateLimit) { + var maxLimit = this.startDate.clone().add(this.dateLimit).endOf('day'); + if (!maxDate || maxLimit.isBefore(maxDate)) { + maxDate = maxLimit; + } + } + + for (var row = 0; row < 6; row++) { + html += ''; + + // add week number + if (this.showWeekNumbers) + html += ''; + else if (this.showISOWeekNumbers) + html += ''; + + for (var col = 0; col < 7; col++) { + + var classes = []; + + //highlight today's date + if (calendar[row][col].isSame(new Date(), "day")) + classes.push('today'); + + //highlight weekends + if (calendar[row][col].isoWeekday() > 5) + classes.push('weekend'); + + //grey out the dates in other months displayed at beginning and end of this calendar + if (calendar[row][col].month() != calendar[1][1].month()) + classes.push('off'); + + //don't allow selection of dates before the minimum date + if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day')) + classes.push('off', 'disabled'); + + //don't allow selection of dates after the maximum date + if (maxDate && calendar[row][col].isAfter(maxDate, 'day')) + classes.push('off', 'disabled'); + + //don't allow selection of date if a custom function decides it's invalid + if (this.isInvalidDate(calendar[row][col])) + classes.push('off', 'disabled'); + + //highlight the currently selected start date + if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD')) + classes.push('active', 'start-date'); + + //highlight the currently selected end date + if (this.endDate != null && calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD')) + classes.push('active', 'end-date'); + + //highlight dates in-between the selected dates + if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate) + classes.push('in-range'); + + //apply custom classes for this date + var isCustom = this.isCustomDate(calendar[row][col]); + if (isCustom !== false) { + if (typeof isCustom === 'string') + classes.push(isCustom); + else + Array.prototype.push.apply(classes, isCustom); + } + + var cname = '', disabled = false; + for (var i = 0; i < classes.length; i++) { + cname += classes[i] + ' '; + if (classes[i] == 'disabled') + disabled = true; + } + if (!disabled) + cname += 'available'; + + html += ''; + + } + html += ''; + } + + html += ''; + html += '
' + dateHtml + '
' + this.locale.weekLabel + '' + dayOfWeek + '
' + calendar[row][0].week() + '' + calendar[row][0].isoWeek() + '' + calendar[row][col].date() + '
'; + + this.container.find('.calendar.' + side + ' .calendar-table').html(html); + + }, + + renderTimePicker: function(side) { + + // Don't bother updating the time picker if it's currently disabled + // because an end date hasn't been clicked yet + if (side == 'right' && !this.endDate) return; + + var html, selected, minDate, maxDate = this.maxDate; + + if (this.dateLimit && (!this.maxDate || this.startDate.clone().add(this.dateLimit).isAfter(this.maxDate))) + maxDate = this.startDate.clone().add(this.dateLimit); + + if (side == 'left') { + selected = this.startDate.clone(); + minDate = this.minDate; + } else if (side == 'right') { + selected = this.endDate.clone(); + minDate = this.startDate; + + //Preserve the time already selected + var timeSelector = this.container.find('.calendar.right .calendar-time div'); + if (timeSelector.html() != '') { + + selected.hour(timeSelector.find('.hourselect option:selected').val() || selected.hour()); + selected.minute(timeSelector.find('.minuteselect option:selected').val() || selected.minute()); + selected.second(timeSelector.find('.secondselect option:selected').val() || selected.second()); + + if (!this.timePicker24Hour) { + var ampm = timeSelector.find('.ampmselect option:selected').val(); + if (ampm === 'PM' && selected.hour() < 12) + selected.hour(selected.hour() + 12); + if (ampm === 'AM' && selected.hour() === 12) + selected.hour(0); + } + + } + + if (selected.isBefore(this.startDate)) + selected = this.startDate.clone(); + + if (maxDate && selected.isAfter(maxDate)) + selected = maxDate.clone(); + + } + + // + // hours + // + + html = ' '; + + // + // minutes + // + + html += ': '; + + // + // seconds + // + + if (this.timePickerSeconds) { + html += ': '; + } + + // + // AM/PM + // + + if (!this.timePicker24Hour) { + html += ''; + } + + this.container.find('.calendar.' + side + ' .calendar-time div').html(html); + + }, + + updateFormInputs: function() { + + //ignore mouse movements while an above-calendar text input has focus + if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus")) + return; + + this.container.find('input[name=daterangepicker_start]').val(this.startDate.format(this.locale.format)); + if (this.endDate) + this.container.find('input[name=daterangepicker_end]').val(this.endDate.format(this.locale.format)); + + if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) { + this.container.find('button.applyBtn').removeAttr('disabled'); + } else { + this.container.find('button.applyBtn').attr('disabled', 'disabled'); + } + + }, + + move: function() { + var parentOffset = { top: 0, left: 0 }, + containerTop; + var parentRightEdge = $(window).width(); + if (!this.parentEl.is('body')) { + parentOffset = { + top: this.parentEl.offset().top - this.parentEl.scrollTop(), + left: this.parentEl.offset().left - this.parentEl.scrollLeft() + }; + parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left; + } + + if (this.drops == 'up') + containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top; + else + containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top; + this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('dropup'); + + if (this.opens == 'left') { + this.container.css({ + top: containerTop, + right: parentRightEdge - this.element.offset().left - this.element.outerWidth(), + left: 'auto' + }); + if (this.container.offset().left < 0) { + this.container.css({ + right: 'auto', + left: 9 + }); + } + } else if (this.opens == 'center') { + this.container.css({ + top: containerTop, + left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2 + - this.container.outerWidth() / 2, + right: 'auto' + }); + if (this.container.offset().left < 0) { + this.container.css({ + right: 'auto', + left: 9 + }); + } + } else { + this.container.css({ + top: containerTop, + left: this.element.offset().left - parentOffset.left, + right: 'auto' + }); + if (this.container.offset().left + this.container.outerWidth() > $(window).width()) { + this.container.css({ + left: 'auto', + right: 0 + }); + } + } + }, + + show: function(e) { + if (this.isShowing) return; + + // Create a click proxy that is private to this instance of datepicker, for unbinding + this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this); + + // Bind global datepicker mousedown for hiding and + $(document) + .on('mousedown.daterangepicker', this._outsideClickProxy) + // also support mobile devices + .on('touchend.daterangepicker', this._outsideClickProxy) + // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them + .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy) + // and also close when focus changes to outside the picker (eg. tabbing between controls) + .on('focusin.daterangepicker', this._outsideClickProxy); + + // Reposition the picker if the window is resized while it's open + $(window).on('resize.daterangepicker', $.proxy(function(e) { this.move(e); }, this)); + + this.oldStartDate = this.startDate.clone(); + this.oldEndDate = this.endDate.clone(); + this.previousRightTime = this.endDate.clone(); + + this.updateView(); + this.container.show(); + this.move(); + this.element.trigger('show.daterangepicker', this); + this.isShowing = true; + }, + + hide: function(e) { + if (!this.isShowing) return; + + //incomplete date selection, revert to last values + if (!this.endDate) { + this.startDate = this.oldStartDate.clone(); + this.endDate = this.oldEndDate.clone(); + } + + //if a new date range was selected, invoke the user callback function + if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate)) + this.callback(this.startDate, this.endDate, this.chosenLabel); + + //if picker is attached to a text input, update it + this.updateElement(); + + $(document).off('.daterangepicker'); + $(window).off('.daterangepicker'); + this.container.hide(); + this.element.trigger('hide.daterangepicker', this); + this.isShowing = false; + }, + + toggle: function(e) { + if (this.isShowing) { + this.hide(); + } else { + this.show(); + } + }, + + outsideClick: function(e) { + var target = $(e.target); + // if the page is clicked anywhere except within the daterangerpicker/button + // itself then call this.hide() + if ( + // ie modal dialog fix + e.type == "focusin" || + target.closest(this.element).length || + target.closest(this.container).length || + target.closest('.calendar-table').length + ) return; + this.hide(); + this.element.trigger('outsideClick.daterangepicker', this); + }, + + showCalendars: function() { + this.container.addClass('show-calendar'); + this.move(); + this.element.trigger('showCalendar.daterangepicker', this); + }, + + hideCalendars: function() { + this.container.removeClass('show-calendar'); + this.element.trigger('hideCalendar.daterangepicker', this); + }, + + hoverRange: function(e) { + + //ignore mouse movements while an above-calendar text input has focus + if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus")) + return; + + var label = e.target.getAttribute('data-range-key'); + + if (label == this.locale.customRangeLabel) { + this.updateView(); + } else { + var dates = this.ranges[label]; + this.container.find('input[name=daterangepicker_start]').val(dates[0].format(this.locale.format)); + this.container.find('input[name=daterangepicker_end]').val(dates[1].format(this.locale.format)); + } + + }, + + clickRange: function(e) { + var label = e.target.getAttribute('data-range-key'); + this.chosenLabel = label; + if (label == this.locale.customRangeLabel) { + this.showCalendars(); + } else { + var dates = this.ranges[label]; + this.startDate = dates[0]; + this.endDate = dates[1]; + + if (!this.timePicker) { + this.startDate.startOf('day'); + this.endDate.endOf('day'); + } + + if (!this.alwaysShowCalendars) + this.hideCalendars(); + this.clickApply(); + } + }, + + clickPrev: function(e) { + var cal = $(e.target).parents('.calendar'); + if (cal.hasClass('left')) { + this.leftCalendar.month.subtract(1, 'month'); + if (this.linkedCalendars) + this.rightCalendar.month.subtract(1, 'month'); + } else { + this.rightCalendar.month.subtract(1, 'month'); + } + this.updateCalendars(); + }, + + clickNext: function(e) { + var cal = $(e.target).parents('.calendar'); + if (cal.hasClass('left')) { + this.leftCalendar.month.add(1, 'month'); + } else { + this.rightCalendar.month.add(1, 'month'); + if (this.linkedCalendars) + this.leftCalendar.month.add(1, 'month'); + } + this.updateCalendars(); + }, + + hoverDate: function(e) { + + //ignore mouse movements while an above-calendar text input has focus + //if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus")) + // return; + + //ignore dates that can't be selected + if (!$(e.target).hasClass('available')) return; + + //have the text inputs above calendars reflect the date being hovered over + var title = $(e.target).attr('data-title'); + var row = title.substr(1, 1); + var col = title.substr(3, 1); + var cal = $(e.target).parents('.calendar'); + var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col]; + + if (this.endDate && !this.container.find('input[name=daterangepicker_start]').is(":focus")) { + this.container.find('input[name=daterangepicker_start]').val(date.format(this.locale.format)); + } else if (!this.endDate && !this.container.find('input[name=daterangepicker_end]').is(":focus")) { + this.container.find('input[name=daterangepicker_end]').val(date.format(this.locale.format)); + } + + //highlight the dates between the start date and the date being hovered as a potential end date + var leftCalendar = this.leftCalendar; + var rightCalendar = this.rightCalendar; + var startDate = this.startDate; + if (!this.endDate) { + this.container.find('.calendar tbody td').each(function(index, el) { + + //skip week numbers, only look at dates + if ($(el).hasClass('week')) return; + + var title = $(el).attr('data-title'); + var row = title.substr(1, 1); + var col = title.substr(3, 1); + var cal = $(el).parents('.calendar'); + var dt = cal.hasClass('left') ? leftCalendar.calendar[row][col] : rightCalendar.calendar[row][col]; + + if ((dt.isAfter(startDate) && dt.isBefore(date)) || dt.isSame(date, 'day')) { + $(el).addClass('in-range'); + } else { + $(el).removeClass('in-range'); + } + + }); + } + + }, + + clickDate: function(e) { + + if (!$(e.target).hasClass('available')) return; + + var title = $(e.target).attr('data-title'); + var row = title.substr(1, 1); + var col = title.substr(3, 1); + var cal = $(e.target).parents('.calendar'); + var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col]; + + // + // this function needs to do a few things: + // * alternate between selecting a start and end date for the range, + // * if the time picker is enabled, apply the hour/minute/second from the select boxes to the clicked date + // * if autoapply is enabled, and an end date was chosen, apply the selection + // * if single date picker mode, and time picker isn't enabled, apply the selection immediately + // * if one of the inputs above the calendars was focused, cancel that manual input + // + + if (this.endDate || date.isBefore(this.startDate, 'day')) { //picking start + if (this.timePicker) { + var hour = parseInt(this.container.find('.left .hourselect').val(), 10); + if (!this.timePicker24Hour) { + var ampm = this.container.find('.left .ampmselect').val(); + if (ampm === 'PM' && hour < 12) + hour += 12; + if (ampm === 'AM' && hour === 12) + hour = 0; + } + var minute = parseInt(this.container.find('.left .minuteselect').val(), 10); + var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0; + date = date.clone().hour(hour).minute(minute).second(second); + } + this.endDate = null; + this.setStartDate(date.clone()); + } else if (!this.endDate && date.isBefore(this.startDate)) { + //special case: clicking the same date for start/end, + //but the time of the end date is before the start date + this.setEndDate(this.startDate.clone()); + } else { // picking end + if (this.timePicker) { + var hour = parseInt(this.container.find('.right .hourselect').val(), 10); + if (!this.timePicker24Hour) { + var ampm = this.container.find('.right .ampmselect').val(); + if (ampm === 'PM' && hour < 12) + hour += 12; + if (ampm === 'AM' && hour === 12) + hour = 0; + } + var minute = parseInt(this.container.find('.right .minuteselect').val(), 10); + var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0; + date = date.clone().hour(hour).minute(minute).second(second); + } + this.setEndDate(date.clone()); + if (this.autoApply) { + this.calculateChosenLabel(); + this.clickApply(); + } + } + + if (this.singleDatePicker) { + this.setEndDate(this.startDate); + if (!this.timePicker) + this.clickApply(); + } + + this.updateView(); + + //This is to cancel the blur event handler if the mouse was in one of the inputs + e.stopPropagation(); + + }, + + calculateChosenLabel: function () { + var customRange = true; + var i = 0; + for (var range in this.ranges) { + if (this.timePicker) { + var format = this.timePickerSeconds ? "YYYY-MM-DD hh:mm:ss" : "YYYY-MM-DD hh:mm"; + //ignore times when comparing dates if time picker seconds is not enabled + if (this.startDate.format(format) == this.ranges[range][0].format(format) && this.endDate.format(format) == this.ranges[range][1].format(format)) { + customRange = false; + this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html(); + break; + } + } else { + //ignore times when comparing dates if time picker is not enabled + 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')) { + customRange = false; + this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html(); + break; + } + } + i++; + } + if (customRange) { + if (this.showCustomRangeLabel) { + this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html(); + } else { + this.chosenLabel = null; + } + this.showCalendars(); + } + }, + + clickApply: function(e) { + this.hide(); + this.element.trigger('apply.daterangepicker', this); + }, + + clickCancel: function(e) { + this.startDate = this.oldStartDate; + this.endDate = this.oldEndDate; + this.hide(); + this.element.trigger('cancel.daterangepicker', this); + }, + + monthOrYearChanged: function(e) { + var isLeft = $(e.target).closest('.calendar').hasClass('left'), + leftOrRight = isLeft ? 'left' : 'right', + cal = this.container.find('.calendar.'+leftOrRight); + + // Month must be Number for new moment versions + var month = parseInt(cal.find('.monthselect').val(), 10); + var year = cal.find('.yearselect').val(); + + if (!isLeft) { + if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) { + month = this.startDate.month(); + year = this.startDate.year(); + } + } + + if (this.minDate) { + if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) { + month = this.minDate.month(); + year = this.minDate.year(); + } + } + + if (this.maxDate) { + if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) { + month = this.maxDate.month(); + year = this.maxDate.year(); + } + } + + if (isLeft) { + this.leftCalendar.month.month(month).year(year); + if (this.linkedCalendars) + this.rightCalendar.month = this.leftCalendar.month.clone().add(1, 'month'); + } else { + this.rightCalendar.month.month(month).year(year); + if (this.linkedCalendars) + this.leftCalendar.month = this.rightCalendar.month.clone().subtract(1, 'month'); + } + this.updateCalendars(); + }, + + timeChanged: function(e) { + + var cal = $(e.target).closest('.calendar'), + isLeft = cal.hasClass('left'); + + var hour = parseInt(cal.find('.hourselect').val(), 10); + var minute = parseInt(cal.find('.minuteselect').val(), 10); + var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0; + + if (!this.timePicker24Hour) { + var ampm = cal.find('.ampmselect').val(); + if (ampm === 'PM' && hour < 12) + hour += 12; + if (ampm === 'AM' && hour === 12) + hour = 0; + } + + if (isLeft) { + var start = this.startDate.clone(); + start.hour(hour); + start.minute(minute); + start.second(second); + this.setStartDate(start); + if (this.singleDatePicker) { + this.endDate = this.startDate.clone(); + } else if (this.endDate && this.endDate.format('YYYY-MM-DD') == start.format('YYYY-MM-DD') && this.endDate.isBefore(start)) { + this.setEndDate(start.clone()); + } + } else if (this.endDate) { + var end = this.endDate.clone(); + end.hour(hour); + end.minute(minute); + end.second(second); + this.setEndDate(end); + } + + //update the calendars so all clickable dates reflect the new time component + this.updateCalendars(); + + //update the form inputs above the calendars with the new time + this.updateFormInputs(); + + //re-render the time pickers because changing one selection can affect what's enabled in another + this.renderTimePicker('left'); + this.renderTimePicker('right'); + + }, + + formInputsChanged: function(e) { + var isRight = $(e.target).closest('.calendar').hasClass('right'); + var start = moment(this.container.find('input[name="daterangepicker_start"]').val(), this.locale.format); + var end = moment(this.container.find('input[name="daterangepicker_end"]').val(), this.locale.format); + + if (start.isValid() && end.isValid()) { + + if (isRight && end.isBefore(start)) + start = end.clone(); + + this.setStartDate(start); + this.setEndDate(end); + + if (isRight) { + this.container.find('input[name="daterangepicker_start"]').val(this.startDate.format(this.locale.format)); + } else { + this.container.find('input[name="daterangepicker_end"]').val(this.endDate.format(this.locale.format)); + } + + } + + this.updateView(); + }, + + formInputsFocused: function(e) { + + // Highlight the focused input + this.container.find('input[name="daterangepicker_start"], input[name="daterangepicker_end"]').removeClass('active'); + $(e.target).addClass('active'); + + // Set the state such that if the user goes back to using a mouse, + // the calendars are aware we're selecting the end of the range, not + // the start. This allows someone to edit the end of a date range without + // re-selecting the beginning, by clicking on the end date input then + // using the calendar. + var isRight = $(e.target).closest('.calendar').hasClass('right'); + if (isRight) { + this.endDate = null; + this.setStartDate(this.startDate.clone()); + this.updateView(); + } + + }, + + formInputsBlurred: function(e) { + + // this function has one purpose right now: if you tab from the first + // text input to the second in the UI, the endDate is nulled so that + // you can click another, but if you tab out without clicking anything + // or changing the input value, the old endDate should be retained + + if (!this.endDate) { + var val = this.container.find('input[name="daterangepicker_end"]').val(); + var end = moment(val, this.locale.format); + if (end.isValid()) { + this.setEndDate(end); + this.updateView(); + } + } + + }, + + formInputsKeydown: function(e) { + // This function ensures that if the 'enter' key was pressed in the input, then the calendars + // are updated with the startDate and endDate. + // This behaviour is automatic in Chrome/Firefox/Edge but not in IE 11 hence why this exists. + // Other browsers and versions of IE are untested and the behaviour is unknown. + if (e.keyCode === 13) { + // Prevent the calendar from being updated twice on Chrome/Firefox/Edge + e.preventDefault(); + this.formInputsChanged(e); + } + }, + + + elementChanged: function() { + if (!this.element.is('input')) return; + if (!this.element.val().length) return; + + var dateString = this.element.val().split(this.locale.separator), + start = null, + end = null; + + if (dateString.length === 2) { + start = moment(dateString[0], this.locale.format); + end = moment(dateString[1], this.locale.format); + } + + if (this.singleDatePicker || start === null || end === null) { + start = moment(this.element.val(), this.locale.format); + end = start; + } + + if (!start.isValid() || !end.isValid()) return; + + this.setStartDate(start); + this.setEndDate(end); + this.updateView(); + }, + + keydown: function(e) { + //hide on tab or enter + if ((e.keyCode === 9) || (e.keyCode === 13)) { + this.hide(); + } + + //hide on esc and prevent propagation + if (e.keyCode === 27) { + e.preventDefault(); + e.stopPropagation(); + + this.hide(); + } + }, + + updateElement: function() { + if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) { + this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format)); + this.element.trigger('change'); + } else if (this.element.is('input') && this.autoUpdateInput) { + this.element.val(this.startDate.format(this.locale.format)); + this.element.trigger('change'); + } + }, + + remove: function() { + this.container.remove(); + this.element.off('.daterangepicker'); + this.element.removeData(); + } + + }; + + $.fn.daterangepicker = function(options, callback) { + var implementOptions = $.extend(true, {}, $.fn.daterangepicker.defaultOptions, options); + this.each(function() { + var el = $(this); + if (el.data('daterangepicker')) + el.data('daterangepicker').remove(); + el.data('daterangepicker', new DateRangePicker(el, implementOptions, callback)); + }); + return this; + }; + + return DateRangePicker; + +})); /* @@ -21010,16 +21010,16 @@ $.fn.timepicker.defaults = $.extend(true, {}, $.fn.timepicker.defaults, { }; }); -//$.fn.bootstrapSwitch.defaults.size = 'large'; +//$.fn.bootstrapSwitch.defaults.size = 'large'; //$.fn.bootstrapSwitch.defaults.onColor = 'success'; +function(a){"use strict";function c(c){return this.each(function(){var d=a(this),e=d.data("multiselectsplitter"),f="object"==typeof c&&c;(e||"destroy"!=c)&&(e||d.data("multiselectsplitter",e=new b(this,f)),"string"==typeof c&&e[c]())})}var b=function(a,b){this.init("multiselectsplitter",a,b)};b.DEFAULTS={selectSize:null,maxSelectSize:null,clearOnFirstChange:!1,onlySameGroup:!1,groupCounter:!1,maximumSelected:null,afterInitialize:null,maximumAlert:function(a){alert("Only "+a+" values can be selected")},createFirstSelect:function(a,b){return""},createSecondSelect:function(a,b){return""},template:'
'},b.prototype.init=function(c,d,e){var f=this;f.type=c,f.last$ElementSelected=[],f.initialized=!1,f.$element=a(d),f.$element.hide(),f.options=a.extend({},b.DEFAULTS,e),f.$element.after(f.options.template),f.$wrapper=f.$element.next("div[data-multiselectsplitter-wrapper-selector]"),f.$firstSelect=a("select[data-multiselectsplitter-firstselect-selector]",f.$wrapper),f.$secondSelect=a("select[data-multiselectsplitter-secondselect-selector]",f.$wrapper);var g=0,h=0;if(0!=f.$element.find("optgroup").length){f.$element.find("optgroup").each(function(){var b=a(this).attr("label"),c=a(f.options.createFirstSelect(b,f.$element));c.val(b),c.attr("data-current-label",c.text()),f.$firstSelect.append(c);var d=a(this).find("option").length;d>h&&(h=d),g++});var i=Math.max(g,h);i=Math.min(i,10),f.options.selectSize?i=f.options.selectSize:f.options.maxSelectSize&&(i=Math.min(i,f.options.maxSelectSize)),f.$firstSelect.attr("size",i),f.$secondSelect.attr("size",i),f.$element.attr("multiple")&&f.$secondSelect.attr("multiple","multiple"),f.$element.is(":disabled")&&f.disable(),f.$firstSelect.on("change",a.proxy(f.updateParentCategory,f)),f.$secondSelect.on("click change",a.proxy(f.updateChildCategory,f)),f.update=function(){if(!(f.$element.find("option").length<1)){var b,a=f.$element.find("option:selected:first");b=a.length?a.parent().attr("label"):f.$element.find("option:first").parent().attr("label"),f.$firstSelect.find('option[value="'+b+'"]').prop("selected",!0),f.$firstSelect.trigger("change")}},f.update(),f.initialized=!0,f.options.afterInitialize&&f.options.afterInitialize(f.$firstSelect,f.$secondSelect)}},b.prototype.disable=function(){this.$secondSelect.prop("disabled",!0),this.$firstSelect.prop("disabled",!0)},b.prototype.enable=function(){this.$secondSelect.prop("disabled",!1),this.$firstSelect.prop("disabled",!1)},b.prototype.createSecondSelect=function(){var b=this;b.$secondSelect.empty(),a.each(b.$element.find('optgroup[label="'+b.$firstSelect.val()+'"] option'),function(c,d){var e=a(this).val(),f=a(this).text(),g=a(b.options.createSecondSelect(f,b.$firstSelect));g.val(e),a.each(b.$element.find("option:selected"),function(b,c){a(c).val()==e&&g.prop("selected",!0)}),b.$secondSelect.append(g)})},b.prototype.updateParentCategory=function(){var a=this;a.last$ElementSelected=a.$element.find("option:selected"),a.options.clearOnFirstChange&&a.initialized&&a.$element.find("option:selected").prop("selected",!1),a.createSecondSelect(),a.checkSelected(),a.updateCounter()},b.prototype.updateCounter=function(){var b=this;b.$element.attr("multiple")&&b.options.groupCounter&&a.each(b.$firstSelect.find("option"),function(c,d){var e=a(d).val(),f=a(d).data("currentLabel"),g=b.$element.find('optgroup[label="'+e+'"] option:selected').length;g>0&&(f+=" ("+g+")"),a(d).html(f)})},b.prototype.checkSelected=function(){var b=this;if(b.$element.attr("multiple")&&b.options.maximumSelected){var c=0;if(c="function"==typeof b.options.maximumSelected?b.options.maximumSelected(b.$firstSelect,b.$secondSelect):b.options.maximumSelected,!(c<1)){var d=b.$element.find("option:selected");if(d.length>c){b.$firstSelect.find("option:selected").prop("selected",!1),b.$secondSelect.find("option:selected").prop("selected",!1),b.initialized?(b.$element.find("option:selected").prop("selected",!1),b.last$ElementSelected.prop("selected",!0)):a.each(b.$element.find("option:selected"),function(b,d){b>c-1&&a(d).prop("selected",!1)});var e=b.last$ElementSelected.first().parent().attr("label");b.$firstSelect.find('option[value="'+e+'"]').prop("selected",!0),b.createSecondSelect(),b.options.maximumAlert(c)}}}},b.prototype.basicUpdateChildCategory=function(b,c){var d=this;d.last$ElementSelected=d.$element.find("option:selected");var e=d.$secondSelect.val();a.isArray(e)||(e=[e]);var f=d.$firstSelect.val(),g=!1;d.$element.attr("multiple")?d.options.onlySameGroup?a.each(d.$element.find("option:selected"),function(b,c){if(a(c).parent().attr("label")!=f)return g=!0,!1}):c||(g=!0):g=!0,g?d.$element.find("option:selected").prop("selected",!1):a.each(d.$element.find("option:selected"),function(b,c){f==a(c).parent().attr("label")&&a.inArray(a(c).val(),e)==-1&&a(c).prop("selected",!1)}),a.each(e,function(a,b){d.$element.find('option[value="'+b+'"]').prop("selected",!0)}),d.checkSelected(),d.updateCounter(),d.$element.trigger("change")},b.prototype.updateChildCategory=function(b){"change"==b.type?this.timeOut=setTimeout(a.proxy(function(){this.basicUpdateChildCategory(b,b.ctrlKey)},this),10):"click"==b.type&&(clearTimeout(this.timeOut),this.basicUpdateChildCategory(b,b.ctrlKey))},b.prototype.destroy=function(){this.$wrapper.remove(),this.$element.removeData(this.type),this.$element.show()},a.fn.multiselectsplitter=c,a.fn.multiselectsplitter.Constructor=b,a.fn.multiselectsplitter.VERSION="1.0.1"}(jQuery); -/*! - * Bootstrap-select v1.12.4 (http://silviomoreto.github.io/bootstrap-select) - * - * Copyright 2013-2017 bootstrap-select - * Licensed under MIT (https://github.com/silviomoreto/bootstrap-select/blob/master/LICENSE) - */ - +/*! + * Bootstrap-select v1.12.4 (http://silviomoreto.github.io/bootstrap-select) + * + * Copyright 2013-2017 bootstrap-select + * Licensed under MIT (https://github.com/silviomoreto/bootstrap-select/blob/master/LICENSE) + */ + (function (root, factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module unless amdModuleId is set @@ -21036,1852 +21036,1852 @@ $.fn.timepicker.defaults = $.extend(true, {}, $.fn.timepicker.defaults, { } }(this, function (jQuery) { -(function ($) { - 'use strict'; - - // - if (!String.prototype.includes) { - (function () { - 'use strict'; // needed to support `apply`/`call` with `undefined`/`null` - var toString = {}.toString; - var defineProperty = (function () { - // IE 8 only supports `Object.defineProperty` on DOM elements - try { - var object = {}; - var $defineProperty = Object.defineProperty; - var result = $defineProperty(object, object, object) && $defineProperty; - } catch (error) { - } - return result; - }()); - var indexOf = ''.indexOf; - var includes = function (search) { - if (this == null) { - throw new TypeError(); - } - var string = String(this); - if (search && toString.call(search) == '[object RegExp]') { - throw new TypeError(); - } - var stringLength = string.length; - var searchString = String(search); - var searchLength = searchString.length; - var position = arguments.length > 1 ? arguments[1] : undefined; - // `ToInteger` - var pos = position ? Number(position) : 0; - if (pos != pos) { // better `isNaN` - pos = 0; - } - var start = Math.min(Math.max(pos, 0), stringLength); - // Avoid the `indexOf` call if no match is possible - if (searchLength + start > stringLength) { - return false; - } - return indexOf.call(string, searchString, pos) != -1; - }; - if (defineProperty) { - defineProperty(String.prototype, 'includes', { - 'value': includes, - 'configurable': true, - 'writable': true - }); - } else { - String.prototype.includes = includes; - } - }()); - } - - if (!String.prototype.startsWith) { - (function () { - 'use strict'; // needed to support `apply`/`call` with `undefined`/`null` - var defineProperty = (function () { - // IE 8 only supports `Object.defineProperty` on DOM elements - try { - var object = {}; - var $defineProperty = Object.defineProperty; - var result = $defineProperty(object, object, object) && $defineProperty; - } catch (error) { - } - return result; - }()); - var toString = {}.toString; - var startsWith = function (search) { - if (this == null) { - throw new TypeError(); - } - var string = String(this); - if (search && toString.call(search) == '[object RegExp]') { - throw new TypeError(); - } - var stringLength = string.length; - var searchString = String(search); - var searchLength = searchString.length; - var position = arguments.length > 1 ? arguments[1] : undefined; - // `ToInteger` - var pos = position ? Number(position) : 0; - if (pos != pos) { // better `isNaN` - pos = 0; - } - var start = Math.min(Math.max(pos, 0), stringLength); - // Avoid the `indexOf` call if no match is possible - if (searchLength + start > stringLength) { - return false; - } - var index = -1; - while (++index < searchLength) { - if (string.charCodeAt(start + index) != searchString.charCodeAt(index)) { - return false; - } - } - return true; - }; - if (defineProperty) { - defineProperty(String.prototype, 'startsWith', { - 'value': startsWith, - 'configurable': true, - 'writable': true - }); - } else { - String.prototype.startsWith = startsWith; - } - }()); - } - - if (!Object.keys) { - Object.keys = function ( - o, // object - k, // key - r // result array - ){ - // initialize object and result - r=[]; - // iterate over object keys - for (k in o) - // fill result array with non-prototypical keys - r.hasOwnProperty.call(o, k) && r.push(k); - // return result - return r; - }; - } - - // set data-selected on select element if the value has been programmatically selected - // prior to initialization of bootstrap-select - // * consider removing or replacing an alternative method * - var valHooks = { - useDefault: false, - _set: $.valHooks.select.set - }; - - $.valHooks.select.set = function(elem, value) { - if (value && !valHooks.useDefault) $(elem).data('selected', true); - - return valHooks._set.apply(this, arguments); - }; - - var changed_arguments = null; - - var EventIsSupported = (function() { - try { - new Event('change'); - return true; - } catch (e) { - return false; - } - })(); - - $.fn.triggerNative = function (eventName) { - var el = this[0], - event; - - if (el.dispatchEvent) { // for modern browsers & IE9+ - if (EventIsSupported) { - // For modern browsers - event = new Event(eventName, { - bubbles: true - }); - } else { - // For IE since it doesn't support Event constructor - event = document.createEvent('Event'); - event.initEvent(eventName, true, false); - } - - el.dispatchEvent(event); - } else if (el.fireEvent) { // for IE8 - event = document.createEventObject(); - event.eventType = eventName; - el.fireEvent('on' + eventName, event); - } else { - // fall back to jQuery.trigger - this.trigger(eventName); - } - }; - // - - // Case insensitive contains search - $.expr.pseudos.icontains = function (obj, index, meta) { - var $obj = $(obj).find('a'); - var haystack = ($obj.data('tokens') || $obj.text()).toString().toUpperCase(); - return haystack.includes(meta[3].toUpperCase()); - }; - - // Case insensitive begins search - $.expr.pseudos.ibegins = function (obj, index, meta) { - var $obj = $(obj).find('a'); - var haystack = ($obj.data('tokens') || $obj.text()).toString().toUpperCase(); - return haystack.startsWith(meta[3].toUpperCase()); - }; - - // Case and accent insensitive contains search - $.expr.pseudos.aicontains = function (obj, index, meta) { - var $obj = $(obj).find('a'); - var haystack = ($obj.data('tokens') || $obj.data('normalizedText') || $obj.text()).toString().toUpperCase(); - return haystack.includes(meta[3].toUpperCase()); - }; - - // Case and accent insensitive begins search - $.expr.pseudos.aibegins = function (obj, index, meta) { - var $obj = $(obj).find('a'); - var haystack = ($obj.data('tokens') || $obj.data('normalizedText') || $obj.text()).toString().toUpperCase(); - return haystack.startsWith(meta[3].toUpperCase()); - }; - - /** - * Remove all diatrics from the given text. - * @access private - * @param {String} text - * @returns {String} - */ - function normalizeToBase(text) { - var rExps = [ - {re: /[\xC0-\xC6]/g, ch: "A"}, - {re: /[\xE0-\xE6]/g, ch: "a"}, - {re: /[\xC8-\xCB]/g, ch: "E"}, - {re: /[\xE8-\xEB]/g, ch: "e"}, - {re: /[\xCC-\xCF]/g, ch: "I"}, - {re: /[\xEC-\xEF]/g, ch: "i"}, - {re: /[\xD2-\xD6]/g, ch: "O"}, - {re: /[\xF2-\xF6]/g, ch: "o"}, - {re: /[\xD9-\xDC]/g, ch: "U"}, - {re: /[\xF9-\xFC]/g, ch: "u"}, - {re: /[\xC7-\xE7]/g, ch: "c"}, - {re: /[\xD1]/g, ch: "N"}, - {re: /[\xF1]/g, ch: "n"} - ]; - $.each(rExps, function () { - text = text ? text.replace(this.re, this.ch) : ''; - }); - return text; - } - - - // List of HTML entities for escaping. - var escapeMap = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''', - '`': '`' - }; - - var unescapeMap = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - ''': "'", - '`': '`' - }; - - // Functions for escaping and unescaping strings to/from HTML interpolation. - var createEscaper = function(map) { - var escaper = function(match) { - return map[match]; - }; - // Regexes for identifying a key that needs to be escaped. - var source = '(?:' + Object.keys(map).join('|') + ')'; - var testRegexp = RegExp(source); - var replaceRegexp = RegExp(source, 'g'); - return function(string) { - string = string == null ? '' : '' + string; - return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string; - }; - }; - - var htmlEscape = createEscaper(escapeMap); - var htmlUnescape = createEscaper(unescapeMap); - - var Selectpicker = function (element, options) { - // bootstrap-select has been initialized - revert valHooks.select.set back to its original function - if (!valHooks.useDefault) { - $.valHooks.select.set = valHooks._set; - valHooks.useDefault = true; - } - - this.$element = $(element); - this.$newElement = null; - this.$button = null; - this.$menu = null; - this.$lis = null; - this.options = options; - - // If we have no title yet, try to pull it from the html title attribute (jQuery doesnt' pick it up as it's not a - // data-attribute) - if (this.options.title === null) { - this.options.title = this.$element.attr('title'); - } - - // Format window padding - var winPad = this.options.windowPadding; - if (typeof winPad === 'number') { - this.options.windowPadding = [winPad, winPad, winPad, winPad]; - } - - //Expose public methods - this.val = Selectpicker.prototype.val; - this.render = Selectpicker.prototype.render; - this.refresh = Selectpicker.prototype.refresh; - this.setStyle = Selectpicker.prototype.setStyle; - this.selectAll = Selectpicker.prototype.selectAll; - this.deselectAll = Selectpicker.prototype.deselectAll; - this.destroy = Selectpicker.prototype.destroy; - this.remove = Selectpicker.prototype.remove; - this.show = Selectpicker.prototype.show; - this.hide = Selectpicker.prototype.hide; - - this.init(); - }; - - Selectpicker.VERSION = '1.12.4'; - - // part of this is duplicated in i18n/defaults-en_US.js. Make sure to update both. - Selectpicker.DEFAULTS = { - noneSelectedText: 'Nothing selected', - noneResultsText: 'No results matched {0}', - countSelectedText: function (numSelected, numTotal) { - return (numSelected == 1) ? "{0} item selected" : "{0} items selected"; - }, - maxOptionsText: function (numAll, numGroup) { - return [ - (numAll == 1) ? 'Limit reached ({n} item max)' : 'Limit reached ({n} items max)', - (numGroup == 1) ? 'Group limit reached ({n} item max)' : 'Group limit reached ({n} items max)' - ]; - }, - selectAllText: 'Select All', - deselectAllText: 'Deselect All', - doneButton: false, - doneButtonText: 'Close', - multipleSeparator: ', ', - styleBase: 'btn', - style: 'btn-default', - size: 'auto', - title: null, - selectedTextFormat: 'values', - width: false, - container: false, - hideDisabled: false, - showSubtext: false, - showIcon: true, - showContent: true, - dropupAuto: true, - header: false, - liveSearch: false, - liveSearchPlaceholder: null, - liveSearchNormalize: false, - liveSearchStyle: 'contains', - actionsBox: false, - iconBase: 'glyphicon', - tickIcon: 'glyphicon-ok', - showTick: false, - template: { - caret: '' - }, - maxOptions: false, - mobile: false, - selectOnTab: false, - dropdownAlignRight: false, - windowPadding: 0 - }; - - Selectpicker.prototype = { - - constructor: Selectpicker, - - init: function () { - var that = this, - id = this.$element.attr('id'); - - this.$element.addClass('bs-select-hidden'); - - // store originalIndex (key) and newIndex (value) in this.liObj for fast accessibility - // allows us to do this.$lis.eq(that.liObj[index]) instead of this.$lis.filter('[data-original-index="' + index + '"]') - this.liObj = {}; - this.multiple = this.$element.prop('multiple'); - this.autofocus = this.$element.prop('autofocus'); - this.$newElement = this.createView(); - this.$element - .after(this.$newElement) - .appendTo(this.$newElement); - this.$button = this.$newElement.children('button'); - this.$menu = this.$newElement.children('.dropdown-menu'); - this.$menuInner = this.$menu.children('.inner'); - this.$searchbox = this.$menu.find('input'); - - this.$element.removeClass('bs-select-hidden'); - - if (this.options.dropdownAlignRight === true) this.$menu.addClass('dropdown-menu-right'); - - if (typeof id !== 'undefined') { - this.$button.attr('data-id', id); - $('label[for="' + id + '"]').click(function (e) { - e.preventDefault(); - that.$button.focus(); - }); - } - - this.checkDisabled(); - this.clickListener(); - if (this.options.liveSearch) this.liveSearchListener(); - this.render(); - this.setStyle(); - this.setWidth(); - if (this.options.container) this.selectPosition(); - this.$menu.data('this', this); - this.$newElement.data('this', this); - if (this.options.mobile) this.mobile(); - - this.$newElement.on({ - 'hide.bs.dropdown': function (e) { - that.$menuInner.attr('aria-expanded', false); - that.$element.trigger('hide.bs.select', e); - }, - 'hidden.bs.dropdown': function (e) { - that.$element.trigger('hidden.bs.select', e); - }, - 'show.bs.dropdown': function (e) { - that.$menuInner.attr('aria-expanded', true); - that.$element.trigger('show.bs.select', e); - }, - 'shown.bs.dropdown': function (e) { - that.$element.trigger('shown.bs.select', e); - } - }); - - if (that.$element[0].hasAttribute('required')) { - this.$element.on('invalid', function () { - that.$button.addClass('bs-invalid'); - - that.$element.on({ - 'focus.bs.select': function () { - that.$button.focus(); - that.$element.off('focus.bs.select'); - }, - 'shown.bs.select': function () { - that.$element - .val(that.$element.val()) // set the value to hide the validation message in Chrome when menu is opened - .off('shown.bs.select'); - }, - 'rendered.bs.select': function () { - // if select is no longer invalid, remove the bs-invalid class - if (this.validity.valid) that.$button.removeClass('bs-invalid'); - that.$element.off('rendered.bs.select'); - } - }); - - that.$button.on('blur.bs.select', function() { - that.$element.focus().blur(); - that.$button.off('blur.bs.select'); - }); - }); - } - - setTimeout(function () { - that.$element.trigger('loaded.bs.select'); - }); - }, - - createDropdown: function () { - // Options - // If we are multiple or showTick option is set, then add the show-tick class - var showTick = (this.multiple || this.options.showTick) ? ' show-tick' : '', - inputGroup = this.$element.parent().hasClass('input-group') ? ' input-group-btn' : '', - autofocus = this.autofocus ? ' autofocus' : ''; - // Elements - var header = this.options.header ? '
' + this.options.header + '
' : ''; - var searchbox = this.options.liveSearch ? - '' - : ''; - var actionsbox = this.multiple && this.options.actionsBox ? - '
' + - '
' + - '' + - '' + - '
' + - '
' - : ''; - var donebutton = this.multiple && this.options.doneButton ? - '
' + - '
' + - '' + - '
' + - '
' - : ''; - var drop = - '
' + - '' + - '' + - '
'; - - return $(drop); - }, - - createView: function () { - var $drop = this.createDropdown(), - li = this.createLi(); - - $drop.find('ul')[0].innerHTML = li; - return $drop; - }, - - reloadLi: function () { - // rebuild - var li = this.createLi(); - this.$menuInner[0].innerHTML = li; - }, - - createLi: function () { - var that = this, - _li = [], - optID = 0, - titleOption = document.createElement('option'), - liIndex = -1; // increment liIndex whenever a new
  • element is created to ensure liObj is correct - - // Helper functions - /** - * @param content - * @param [index] - * @param [classes] - * @param [optgroup] - * @returns {string} - */ - var generateLI = function (content, index, classes, optgroup) { - return '' + content + '
  • '; - }; - - /** - * @param text - * @param [classes] - * @param [inline] - * @param [tokens] - * @returns {string} - */ - var generateA = function (text, classes, inline, tokens) { - return '' + text + - '' + - ''; - }; - - if (this.options.title && !this.multiple) { - // this option doesn't create a new
  • element, but does add a new option, so liIndex is decreased - // since liObj is recalculated on every refresh, liIndex needs to be decreased even if the titleOption is already appended - liIndex--; - - if (!this.$element.find('.bs-title-option').length) { - // Use native JS to prepend option (faster) - var element = this.$element[0]; - titleOption.className = 'bs-title-option'; - titleOption.innerHTML = this.options.title; - titleOption.value = ''; - element.insertBefore(titleOption, element.firstChild); - // Check if selected or data-selected attribute is already set on an option. If not, select the titleOption option. - // the selected item may have been changed by user or programmatically before the bootstrap select plugin runs, - // if so, the select will have the data-selected attribute - var $opt = $(element.options[element.selectedIndex]); - if ($opt.attr('selected') === undefined && this.$element.data('selected') === undefined) { - titleOption.selected = true; - } - } - } - - var $selectOptions = this.$element.find('option'); - - $selectOptions.each(function (index) { - var $this = $(this); - - liIndex++; - - if ($this.hasClass('bs-title-option')) return; - - // Get the class and text for the option - var optionClass = this.className || '', - inline = htmlEscape(this.style.cssText), - text = $this.data('content') ? $this.data('content') : $this.html(), - tokens = $this.data('tokens') ? $this.data('tokens') : null, - subtext = typeof $this.data('subtext') !== 'undefined' ? '' + $this.data('subtext') + '' : '', - icon = typeof $this.data('icon') !== 'undefined' ? ' ' : '', - $parent = $this.parent(), - isOptgroup = $parent[0].tagName === 'OPTGROUP', - isOptgroupDisabled = isOptgroup && $parent[0].disabled, - isDisabled = this.disabled || isOptgroupDisabled, - prevHiddenIndex; - - if (icon !== '' && isDisabled) { - icon = '' + icon + ''; - } - - if (that.options.hideDisabled && (isDisabled && !isOptgroup || isOptgroupDisabled)) { - // set prevHiddenIndex - the index of the first hidden option in a group of hidden options - // used to determine whether or not a divider should be placed after an optgroup if there are - // hidden options between the optgroup and the first visible option - prevHiddenIndex = $this.data('prevHiddenIndex'); - $this.next().data('prevHiddenIndex', (prevHiddenIndex !== undefined ? prevHiddenIndex : index)); - - liIndex--; - return; - } - - if (!$this.data('content')) { - // Prepend any icon and append any subtext to the main text. - text = icon + '' + text + subtext + ''; - } - - if (isOptgroup && $this.data('divider') !== true) { - if (that.options.hideDisabled && isDisabled) { - if ($parent.data('allOptionsDisabled') === undefined) { - var $options = $parent.children(); - $parent.data('allOptionsDisabled', $options.filter(':disabled').length === $options.length); - } - - if ($parent.data('allOptionsDisabled')) { - liIndex--; - return; - } - } - - var optGroupClass = ' ' + $parent[0].className || ''; - - if ($this.index() === 0) { // Is it the first option of the optgroup? - optID += 1; - - // Get the opt group label - var label = $parent[0].label, - labelSubtext = typeof $parent.data('subtext') !== 'undefined' ? '' + $parent.data('subtext') + '' : '', - labelIcon = $parent.data('icon') ? ' ' : ''; - - label = labelIcon + '' + htmlEscape(label) + labelSubtext + ''; - - if (index !== 0 && _li.length > 0) { // Is it NOT the first option of the select && are there elements in the dropdown? - liIndex++; - _li.push(generateLI('', null, 'divider', optID + 'div')); - } - liIndex++; - _li.push(generateLI(label, null, 'dropdown-header' + optGroupClass, optID)); - } - - if (that.options.hideDisabled && isDisabled) { - liIndex--; - return; - } - - _li.push(generateLI(generateA(text, 'opt ' + optionClass + optGroupClass, inline, tokens), index, '', optID)); - } else if ($this.data('divider') === true) { - _li.push(generateLI('', index, 'divider')); - } else if ($this.data('hidden') === true) { - // set prevHiddenIndex - the index of the first hidden option in a group of hidden options - // used to determine whether or not a divider should be placed after an optgroup if there are - // hidden options between the optgroup and the first visible option - prevHiddenIndex = $this.data('prevHiddenIndex'); - $this.next().data('prevHiddenIndex', (prevHiddenIndex !== undefined ? prevHiddenIndex : index)); - - _li.push(generateLI(generateA(text, optionClass, inline, tokens), index, 'hidden is-hidden')); - } else { - var showDivider = this.previousElementSibling && this.previousElementSibling.tagName === 'OPTGROUP'; - - // if previous element is not an optgroup and hideDisabled is true - if (!showDivider && that.options.hideDisabled) { - prevHiddenIndex = $this.data('prevHiddenIndex'); - - if (prevHiddenIndex !== undefined) { - // select the element **before** the first hidden element in the group - var prevHidden = $selectOptions.eq(prevHiddenIndex)[0].previousElementSibling; - - if (prevHidden && prevHidden.tagName === 'OPTGROUP' && !prevHidden.disabled) { - showDivider = true; - } - } - } - - if (showDivider) { - liIndex++; - _li.push(generateLI('', null, 'divider', optID + 'div')); - } - _li.push(generateLI(generateA(text, optionClass, inline, tokens), index)); - } - - that.liObj[index] = liIndex; - }); - - //If we are not multiple, we don't have a selected item, and we don't have a title, select the first element so something is set in the button - if (!this.multiple && this.$element.find('option:selected').length === 0 && !this.options.title) { - this.$element.find('option').eq(0).prop('selected', true).attr('selected', 'selected'); - } - - return _li.join(''); - }, - - findLis: function () { - if (this.$lis == null) this.$lis = this.$menu.find('li'); - return this.$lis; - }, - - /** - * @param [updateLi] defaults to true - */ - render: function (updateLi) { - var that = this, - notDisabled, - $selectOptions = this.$element.find('option'); - - //Update the LI to match the SELECT - if (updateLi !== false) { - $selectOptions.each(function (index) { - var $lis = that.findLis().eq(that.liObj[index]); - - that.setDisabled(index, this.disabled || this.parentNode.tagName === 'OPTGROUP' && this.parentNode.disabled, $lis); - that.setSelected(index, this.selected, $lis); - }); - } - - this.togglePlaceholder(); - - this.tabIndex(); - - var selectedItems = $selectOptions.map(function () { - if (this.selected) { - if (that.options.hideDisabled && (this.disabled || this.parentNode.tagName === 'OPTGROUP' && this.parentNode.disabled)) return; - - var $this = $(this), - icon = $this.data('icon') && that.options.showIcon ? ' ' : '', - subtext; - - if (that.options.showSubtext && $this.data('subtext') && !that.multiple) { - subtext = ' ' + $this.data('subtext') + ''; - } else { - subtext = ''; - } - if (typeof $this.attr('title') !== 'undefined') { - return $this.attr('title'); - } else if ($this.data('content') && that.options.showContent) { - return $this.data('content').toString(); - } else { - return icon + $this.html() + subtext; - } - } - }).toArray(); - - //Fixes issue in IE10 occurring when no default option is selected and at least one option is disabled - //Convert all the values into a comma delimited string - var title = !this.multiple ? selectedItems[0] : selectedItems.join(this.options.multipleSeparator); - - //If this is multi select, and the selectText type is count, the show 1 of 2 selected etc.. - if (this.multiple && this.options.selectedTextFormat.indexOf('count') > -1) { - var max = this.options.selectedTextFormat.split('>'); - if ((max.length > 1 && selectedItems.length > max[1]) || (max.length == 1 && selectedItems.length >= 2)) { - notDisabled = this.options.hideDisabled ? ', [disabled]' : ''; - var totalCount = $selectOptions.not('[data-divider="true"], [data-hidden="true"]' + notDisabled).length, - tr8nText = (typeof this.options.countSelectedText === 'function') ? this.options.countSelectedText(selectedItems.length, totalCount) : this.options.countSelectedText; - title = tr8nText.replace('{0}', selectedItems.length.toString()).replace('{1}', totalCount.toString()); - } - } - - if (this.options.title == undefined) { - this.options.title = this.$element.attr('title'); - } - - if (this.options.selectedTextFormat == 'static') { - title = this.options.title; - } - - //If we dont have a title, then use the default, or if nothing is set at all, use the not selected text - if (!title) { - title = typeof this.options.title !== 'undefined' ? this.options.title : this.options.noneSelectedText; - } - - //strip all HTML tags and trim the result, then unescape any escaped tags - this.$button.attr('title', htmlUnescape($.trim(title.replace(/<[^>]*>?/g, '')))); - this.$button.children('.filter-option').html(title); - - this.$element.trigger('rendered.bs.select'); - }, - - /** - * @param [style] - * @param [status] - */ - setStyle: function (style, status) { - if (this.$element.attr('class')) { - this.$newElement.addClass(this.$element.attr('class').replace(/selectpicker|mobile-device|bs-select-hidden|validate\[.*\]/gi, '')); - } - - var buttonClass = style ? style : this.options.style; - - if (status == 'add') { - this.$button.addClass(buttonClass); - } else if (status == 'remove') { - this.$button.removeClass(buttonClass); - } else { - this.$button.removeClass(this.options.style); - this.$button.addClass(buttonClass); - } - }, - - liHeight: function (refresh) { - if (!refresh && (this.options.size === false || this.sizeInfo)) return; - - var newElement = document.createElement('div'), - menu = document.createElement('div'), - menuInner = document.createElement('ul'), - divider = document.createElement('li'), - li = document.createElement('li'), - a = document.createElement('a'), - text = document.createElement('span'), - header = this.options.header && this.$menu.find('.popover-title').length > 0 ? this.$menu.find('.popover-title')[0].cloneNode(true) : null, - search = this.options.liveSearch ? document.createElement('div') : null, - actions = this.options.actionsBox && this.multiple && this.$menu.find('.bs-actionsbox').length > 0 ? this.$menu.find('.bs-actionsbox')[0].cloneNode(true) : null, - doneButton = this.options.doneButton && this.multiple && this.$menu.find('.bs-donebutton').length > 0 ? this.$menu.find('.bs-donebutton')[0].cloneNode(true) : null; - - text.className = 'text'; - newElement.className = this.$menu[0].parentNode.className + ' open'; - menu.className = 'dropdown-menu open'; - menuInner.className = 'dropdown-menu inner'; - divider.className = 'divider'; - - text.appendChild(document.createTextNode('Inner text')); - a.appendChild(text); - li.appendChild(a); - menuInner.appendChild(li); - menuInner.appendChild(divider); - if (header) menu.appendChild(header); - if (search) { - var input = document.createElement('input'); - search.className = 'bs-searchbox'; - input.className = 'form-control'; - search.appendChild(input); - menu.appendChild(search); - } - if (actions) menu.appendChild(actions); - menu.appendChild(menuInner); - if (doneButton) menu.appendChild(doneButton); - newElement.appendChild(menu); - - document.body.appendChild(newElement); - - var liHeight = a.offsetHeight, - headerHeight = header ? header.offsetHeight : 0, - searchHeight = search ? search.offsetHeight : 0, - actionsHeight = actions ? actions.offsetHeight : 0, - doneButtonHeight = doneButton ? doneButton.offsetHeight : 0, - dividerHeight = $(divider).outerHeight(true), - // fall back to jQuery if getComputedStyle is not supported - menuStyle = typeof getComputedStyle === 'function' ? getComputedStyle(menu) : false, - $menu = menuStyle ? null : $(menu), - menuPadding = { - vert: parseInt(menuStyle ? menuStyle.paddingTop : $menu.css('paddingTop')) + - parseInt(menuStyle ? menuStyle.paddingBottom : $menu.css('paddingBottom')) + - parseInt(menuStyle ? menuStyle.borderTopWidth : $menu.css('borderTopWidth')) + - parseInt(menuStyle ? menuStyle.borderBottomWidth : $menu.css('borderBottomWidth')), - horiz: parseInt(menuStyle ? menuStyle.paddingLeft : $menu.css('paddingLeft')) + - parseInt(menuStyle ? menuStyle.paddingRight : $menu.css('paddingRight')) + - parseInt(menuStyle ? menuStyle.borderLeftWidth : $menu.css('borderLeftWidth')) + - parseInt(menuStyle ? menuStyle.borderRightWidth : $menu.css('borderRightWidth')) - }, - menuExtras = { - vert: menuPadding.vert + - parseInt(menuStyle ? menuStyle.marginTop : $menu.css('marginTop')) + - parseInt(menuStyle ? menuStyle.marginBottom : $menu.css('marginBottom')) + 2, - horiz: menuPadding.horiz + - parseInt(menuStyle ? menuStyle.marginLeft : $menu.css('marginLeft')) + - parseInt(menuStyle ? menuStyle.marginRight : $menu.css('marginRight')) + 2 - } - - document.body.removeChild(newElement); - - this.sizeInfo = { - liHeight: liHeight, - headerHeight: headerHeight, - searchHeight: searchHeight, - actionsHeight: actionsHeight, - doneButtonHeight: doneButtonHeight, - dividerHeight: dividerHeight, - menuPadding: menuPadding, - menuExtras: menuExtras - }; - }, - - setSize: function () { - this.findLis(); - this.liHeight(); - - if (this.options.header) this.$menu.css('padding-top', 0); - if (this.options.size === false) return; - - var that = this, - $menu = this.$menu, - $menuInner = this.$menuInner, - $window = $(window), - selectHeight = this.$newElement[0].offsetHeight, - selectWidth = this.$newElement[0].offsetWidth, - liHeight = this.sizeInfo['liHeight'], - headerHeight = this.sizeInfo['headerHeight'], - searchHeight = this.sizeInfo['searchHeight'], - actionsHeight = this.sizeInfo['actionsHeight'], - doneButtonHeight = this.sizeInfo['doneButtonHeight'], - divHeight = this.sizeInfo['dividerHeight'], - menuPadding = this.sizeInfo['menuPadding'], - menuExtras = this.sizeInfo['menuExtras'], - notDisabled = this.options.hideDisabled ? '.disabled' : '', - menuHeight, - menuWidth, - getHeight, - getWidth, - selectOffsetTop, - selectOffsetBot, - selectOffsetLeft, - selectOffsetRight, - getPos = function() { - var pos = that.$newElement.offset(), - $container = $(that.options.container), - containerPos; - - if (that.options.container && !$container.is('body')) { - containerPos = $container.offset(); - containerPos.top += parseInt($container.css('borderTopWidth')); - containerPos.left += parseInt($container.css('borderLeftWidth')); - } else { - containerPos = { top: 0, left: 0 }; - } - - var winPad = that.options.windowPadding; - selectOffsetTop = pos.top - containerPos.top - $window.scrollTop(); - selectOffsetBot = $window.height() - selectOffsetTop - selectHeight - containerPos.top - winPad[2]; - selectOffsetLeft = pos.left - containerPos.left - $window.scrollLeft(); - selectOffsetRight = $window.width() - selectOffsetLeft - selectWidth - containerPos.left - winPad[1]; - selectOffsetTop -= winPad[0]; - selectOffsetLeft -= winPad[3]; - }; - - getPos(); - - if (this.options.size === 'auto') { - var getSize = function () { - var minHeight, - hasClass = function (className, include) { - return function (element) { - if (include) { - return (element.classList ? element.classList.contains(className) : $(element).hasClass(className)); - } else { - return !(element.classList ? element.classList.contains(className) : $(element).hasClass(className)); - } - }; - }, - lis = that.$menuInner[0].getElementsByTagName('li'), - lisVisible = Array.prototype.filter ? Array.prototype.filter.call(lis, hasClass('hidden', false)) : that.$lis.not('.hidden'), - optGroup = Array.prototype.filter ? Array.prototype.filter.call(lisVisible, hasClass('dropdown-header', true)) : lisVisible.filter('.dropdown-header'); - - getPos(); - menuHeight = selectOffsetBot - menuExtras.vert; - menuWidth = selectOffsetRight - menuExtras.horiz; - - if (that.options.container) { - if (!$menu.data('height')) $menu.data('height', $menu.height()); - getHeight = $menu.data('height'); - - if (!$menu.data('width')) $menu.data('width', $menu.width()); - getWidth = $menu.data('width'); - } else { - getHeight = $menu.height(); - getWidth = $menu.width(); - } - - if (that.options.dropupAuto) { - that.$newElement.toggleClass('dropup', selectOffsetTop > selectOffsetBot && (menuHeight - menuExtras.vert) < getHeight); - } - - if (that.$newElement.hasClass('dropup')) { - menuHeight = selectOffsetTop - menuExtras.vert; - } - - if (that.options.dropdownAlignRight === 'auto') { - $menu.toggleClass('dropdown-menu-right', selectOffsetLeft > selectOffsetRight && (menuWidth - menuExtras.horiz) < (getWidth - selectWidth)); - } - - if ((lisVisible.length + optGroup.length) > 3) { - minHeight = liHeight * 3 + menuExtras.vert - 2; - } else { - minHeight = 0; - } - - $menu.css({ - 'max-height': menuHeight + 'px', - 'overflow': 'hidden', - 'min-height': minHeight + headerHeight + searchHeight + actionsHeight + doneButtonHeight + 'px' - }); - $menuInner.css({ - 'max-height': menuHeight - headerHeight - searchHeight - actionsHeight - doneButtonHeight - menuPadding.vert + 'px', - 'overflow-y': 'auto', - 'min-height': Math.max(minHeight - menuPadding.vert, 0) + 'px' - }); - }; - getSize(); - this.$searchbox.off('input.getSize propertychange.getSize').on('input.getSize propertychange.getSize', getSize); - $window.off('resize.getSize scroll.getSize').on('resize.getSize scroll.getSize', getSize); - } else if (this.options.size && this.options.size != 'auto' && this.$lis.not(notDisabled).length > this.options.size) { - var optIndex = this.$lis.not('.divider').not(notDisabled).children().slice(0, this.options.size).last().parent().index(), - divLength = this.$lis.slice(0, optIndex + 1).filter('.divider').length; - menuHeight = liHeight * this.options.size + divLength * divHeight + menuPadding.vert; - - if (that.options.container) { - if (!$menu.data('height')) $menu.data('height', $menu.height()); - getHeight = $menu.data('height'); - } else { - getHeight = $menu.height(); - } - - if (that.options.dropupAuto) { - //noinspection JSUnusedAssignment - this.$newElement.toggleClass('dropup', selectOffsetTop > selectOffsetBot && (menuHeight - menuExtras.vert) < getHeight); - } - $menu.css({ - 'max-height': menuHeight + headerHeight + searchHeight + actionsHeight + doneButtonHeight + 'px', - 'overflow': 'hidden', - 'min-height': '' - }); - $menuInner.css({ - 'max-height': menuHeight - menuPadding.vert + 'px', - 'overflow-y': 'auto', - 'min-height': '' - }); - } - }, - - setWidth: function () { - if (this.options.width === 'auto') { - this.$menu.css('min-width', '0'); - - // Get correct width if element is hidden - var $selectClone = this.$menu.parent().clone().appendTo('body'), - $selectClone2 = this.options.container ? this.$newElement.clone().appendTo('body') : $selectClone, - ulWidth = $selectClone.children('.dropdown-menu').outerWidth(), - btnWidth = $selectClone2.css('width', 'auto').children('button').outerWidth(); - - $selectClone.remove(); - $selectClone2.remove(); - - // Set width to whatever's larger, button title or longest option - this.$newElement.css('width', Math.max(ulWidth, btnWidth) + 'px'); - } else if (this.options.width === 'fit') { - // Remove inline min-width so width can be changed from 'auto' - this.$menu.css('min-width', ''); - this.$newElement.css('width', '').addClass('fit-width'); - } else if (this.options.width) { - // Remove inline min-width so width can be changed from 'auto' - this.$menu.css('min-width', ''); - this.$newElement.css('width', this.options.width); - } else { - // Remove inline min-width/width so width can be changed - this.$menu.css('min-width', ''); - this.$newElement.css('width', ''); - } - // Remove fit-width class if width is changed programmatically - if (this.$newElement.hasClass('fit-width') && this.options.width !== 'fit') { - this.$newElement.removeClass('fit-width'); - } - }, - - selectPosition: function () { - this.$bsContainer = $('
    '); - - var that = this, - $container = $(this.options.container), - pos, - containerPos, - actualHeight, - getPlacement = function ($element) { - that.$bsContainer.addClass($element.attr('class').replace(/form-control|fit-width/gi, '')).toggleClass('dropup', $element.hasClass('dropup')); - pos = $element.offset(); - - if (!$container.is('body')) { - containerPos = $container.offset(); - containerPos.top += parseInt($container.css('borderTopWidth')) - $container.scrollTop(); - containerPos.left += parseInt($container.css('borderLeftWidth')) - $container.scrollLeft(); - } else { - containerPos = { top: 0, left: 0 }; - } - - actualHeight = $element.hasClass('dropup') ? 0 : $element[0].offsetHeight; - - that.$bsContainer.css({ - 'top': pos.top - containerPos.top + actualHeight, - 'left': pos.left - containerPos.left, - 'width': $element[0].offsetWidth - }); - }; - - this.$button.on('click', function () { - var $this = $(this); - - if (that.isDisabled()) { - return; - } - - getPlacement(that.$newElement); - - that.$bsContainer - .appendTo(that.options.container) - .toggleClass('open', !$this.hasClass('open')) - .append(that.$menu); - }); - - $(window).on('resize scroll', function () { - getPlacement(that.$newElement); - }); - - this.$element.on('hide.bs.select', function () { - that.$menu.data('height', that.$menu.height()); - that.$bsContainer.detach(); - }); - }, - - /** - * @param {number} index - the index of the option that is being changed - * @param {boolean} selected - true if the option is being selected, false if being deselected - * @param {JQuery} $lis - the 'li' element that is being modified - */ - setSelected: function (index, selected, $lis) { - if (!$lis) { - this.togglePlaceholder(); // check if setSelected is being called by changing the value of the select - $lis = this.findLis().eq(this.liObj[index]); - } - - $lis.toggleClass('selected', selected).find('a').attr('aria-selected', selected); - }, - - /** - * @param {number} index - the index of the option that is being disabled - * @param {boolean} disabled - true if the option is being disabled, false if being enabled - * @param {JQuery} $lis - the 'li' element that is being modified - */ - setDisabled: function (index, disabled, $lis) { - if (!$lis) { - $lis = this.findLis().eq(this.liObj[index]); - } - - if (disabled) { - $lis.addClass('disabled').children('a').attr('href', '#').attr('tabindex', -1).attr('aria-disabled', true); - } else { - $lis.removeClass('disabled').children('a').removeAttr('href').attr('tabindex', 0).attr('aria-disabled', false); - } - }, - - isDisabled: function () { - return this.$element[0].disabled; - }, - - checkDisabled: function () { - var that = this; - - if (this.isDisabled()) { - this.$newElement.addClass('disabled'); - this.$button.addClass('disabled').attr('tabindex', -1).attr('aria-disabled', true); - } else { - if (this.$button.hasClass('disabled')) { - this.$newElement.removeClass('disabled'); - this.$button.removeClass('disabled').attr('aria-disabled', false); - } - - if (this.$button.attr('tabindex') == -1 && !this.$element.data('tabindex')) { - this.$button.removeAttr('tabindex'); - } - } - - this.$button.click(function () { - return !that.isDisabled(); - }); - }, - - togglePlaceholder: function () { - var value = this.$element.val(); - this.$button.toggleClass('bs-placeholder', value === null || value === '' || (value.constructor === Array && value.length === 0)); - }, - - tabIndex: function () { - if (this.$element.data('tabindex') !== this.$element.attr('tabindex') && - (this.$element.attr('tabindex') !== -98 && this.$element.attr('tabindex') !== '-98')) { - this.$element.data('tabindex', this.$element.attr('tabindex')); - this.$button.attr('tabindex', this.$element.data('tabindex')); - } - - this.$element.attr('tabindex', -98); - }, - - clickListener: function () { - var that = this, - $document = $(document); - - $document.data('spaceSelect', false); - - this.$button.on('keyup', function (e) { - if (/(32)/.test(e.keyCode.toString(10)) && $document.data('spaceSelect')) { - e.preventDefault(); - $document.data('spaceSelect', false); - } - }); - - this.$button.on('click', function () { - that.setSize(); - }); - - this.$element.on('shown.bs.select', function () { - if (!that.options.liveSearch && !that.multiple) { - that.$menuInner.find('.selected a').focus(); - } else if (!that.multiple) { - var selectedIndex = that.liObj[that.$element[0].selectedIndex]; - - if (typeof selectedIndex !== 'number' || that.options.size === false) return; - - // scroll to selected option - var offset = that.$lis.eq(selectedIndex)[0].offsetTop - that.$menuInner[0].offsetTop; - offset = offset - that.$menuInner[0].offsetHeight/2 + that.sizeInfo.liHeight/2; - that.$menuInner[0].scrollTop = offset; - } - }); - - this.$menuInner.on('click', 'li a', function (e) { - var $this = $(this), - clickedIndex = $this.parent().data('originalIndex'), - prevValue = that.$element.val(), - prevIndex = that.$element.prop('selectedIndex'), - triggerChange = true; - - // Don't close on multi choice menu - if (that.multiple && that.options.maxOptions !== 1) { - e.stopPropagation(); - } - - e.preventDefault(); - - //Don't run if we have been disabled - if (!that.isDisabled() && !$this.parent().hasClass('disabled')) { - var $options = that.$element.find('option'), - $option = $options.eq(clickedIndex), - state = $option.prop('selected'), - $optgroup = $option.parent('optgroup'), - maxOptions = that.options.maxOptions, - maxOptionsGrp = $optgroup.data('maxOptions') || false; - - if (!that.multiple) { // Deselect all others if not multi select box - $options.prop('selected', false); - $option.prop('selected', true); - that.$menuInner.find('.selected').removeClass('selected').find('a').attr('aria-selected', false); - that.setSelected(clickedIndex, true); - } else { // Toggle the one we have chosen if we are multi select. - $option.prop('selected', !state); - that.setSelected(clickedIndex, !state); - $this.blur(); - - if (maxOptions !== false || maxOptionsGrp !== false) { - var maxReached = maxOptions < $options.filter(':selected').length, - maxReachedGrp = maxOptionsGrp < $optgroup.find('option:selected').length; - - if ((maxOptions && maxReached) || (maxOptionsGrp && maxReachedGrp)) { - if (maxOptions && maxOptions == 1) { - $options.prop('selected', false); - $option.prop('selected', true); - that.$menuInner.find('.selected').removeClass('selected'); - that.setSelected(clickedIndex, true); - } else if (maxOptionsGrp && maxOptionsGrp == 1) { - $optgroup.find('option:selected').prop('selected', false); - $option.prop('selected', true); - var optgroupID = $this.parent().data('optgroup'); - that.$menuInner.find('[data-optgroup="' + optgroupID + '"]').removeClass('selected'); - that.setSelected(clickedIndex, true); - } else { - var maxOptionsText = typeof that.options.maxOptionsText === 'string' ? [that.options.maxOptionsText, that.options.maxOptionsText] : that.options.maxOptionsText, - maxOptionsArr = typeof maxOptionsText === 'function' ? maxOptionsText(maxOptions, maxOptionsGrp) : maxOptionsText, - maxTxt = maxOptionsArr[0].replace('{n}', maxOptions), - maxTxtGrp = maxOptionsArr[1].replace('{n}', maxOptionsGrp), - $notify = $('
    '); - // If {var} is set in array, replace it - /** @deprecated */ - if (maxOptionsArr[2]) { - maxTxt = maxTxt.replace('{var}', maxOptionsArr[2][maxOptions > 1 ? 0 : 1]); - maxTxtGrp = maxTxtGrp.replace('{var}', maxOptionsArr[2][maxOptionsGrp > 1 ? 0 : 1]); - } - - $option.prop('selected', false); - - that.$menu.append($notify); - - if (maxOptions && maxReached) { - $notify.append($('
    ' + maxTxt + '
    ')); - triggerChange = false; - that.$element.trigger('maxReached.bs.select'); - } - - if (maxOptionsGrp && maxReachedGrp) { - $notify.append($('
    ' + maxTxtGrp + '
    ')); - triggerChange = false; - that.$element.trigger('maxReachedGrp.bs.select'); - } - - setTimeout(function () { - that.setSelected(clickedIndex, false); - }, 10); - - $notify.delay(750).fadeOut(300, function () { - $(this).remove(); - }); - } - } - } - } - - if (!that.multiple || (that.multiple && that.options.maxOptions === 1)) { - that.$button.focus(); - } else if (that.options.liveSearch) { - that.$searchbox.focus(); - } - - // Trigger select 'change' - if (triggerChange) { - if ((prevValue != that.$element.val() && that.multiple) || (prevIndex != that.$element.prop('selectedIndex') && !that.multiple)) { - // $option.prop('selected') is current option state (selected/unselected). state is previous option state. - changed_arguments = [clickedIndex, $option.prop('selected'), state]; - that.$element - .triggerNative('change'); - } - } - } - }); - - this.$menu.on('click', 'li.disabled a, .popover-title, .popover-title :not(.close)', function (e) { - if (e.currentTarget == this) { - e.preventDefault(); - e.stopPropagation(); - if (that.options.liveSearch && !$(e.target).hasClass('close')) { - that.$searchbox.focus(); - } else { - that.$button.focus(); - } - } - }); - - this.$menuInner.on('click', '.divider, .dropdown-header', function (e) { - e.preventDefault(); - e.stopPropagation(); - if (that.options.liveSearch) { - that.$searchbox.focus(); - } else { - that.$button.focus(); - } - }); - - this.$menu.on('click', '.popover-title .close', function () { - that.$button.click(); - }); - - this.$searchbox.on('click', function (e) { - e.stopPropagation(); - }); - - this.$menu.on('click', '.actions-btn', function (e) { - if (that.options.liveSearch) { - that.$searchbox.focus(); - } else { - that.$button.focus(); - } - - e.preventDefault(); - e.stopPropagation(); - - if ($(this).hasClass('bs-select-all')) { - that.selectAll(); - } else { - that.deselectAll(); - } - }); - - this.$element.change(function () { - that.render(false); - that.$element.trigger('changed.bs.select', changed_arguments); - changed_arguments = null; - }); - }, - - liveSearchListener: function () { - var that = this, - $no_results = $('
  • '); - - this.$button.on('click.dropdown.data-api', function () { - that.$menuInner.find('.active').removeClass('active'); - if (!!that.$searchbox.val()) { - that.$searchbox.val(''); - that.$lis.not('.is-hidden').removeClass('hidden'); - if (!!$no_results.parent().length) $no_results.remove(); - } - if (!that.multiple) that.$menuInner.find('.selected').addClass('active'); - setTimeout(function () { - that.$searchbox.focus(); - }, 10); - }); - - this.$searchbox.on('click.dropdown.data-api focus.dropdown.data-api touchend.dropdown.data-api', function (e) { - e.stopPropagation(); - }); - - this.$searchbox.on('input propertychange', function () { - that.$lis.not('.is-hidden').removeClass('hidden'); - that.$lis.filter('.active').removeClass('active'); - $no_results.remove(); - - if (that.$searchbox.val()) { - var $searchBase = that.$lis.not('.is-hidden, .divider, .dropdown-header'), - $hideItems; - if (that.options.liveSearchNormalize) { - $hideItems = $searchBase.not(':a' + that._searchStyle() + '("' + normalizeToBase(that.$searchbox.val()) + '")'); - } else { - $hideItems = $searchBase.not(':' + that._searchStyle() + '("' + that.$searchbox.val() + '")'); - } - - if ($hideItems.length === $searchBase.length) { - $no_results.html(that.options.noneResultsText.replace('{0}', '"' + htmlEscape(that.$searchbox.val()) + '"')); - that.$menuInner.append($no_results); - that.$lis.addClass('hidden'); - } else { - $hideItems.addClass('hidden'); - - var $lisVisible = that.$lis.not('.hidden'), - $foundDiv; - - // hide divider if first or last visible, or if followed by another divider - $lisVisible.each(function (index) { - var $this = $(this); - - if ($this.hasClass('divider')) { - if ($foundDiv === undefined) { - $this.addClass('hidden'); - } else { - if ($foundDiv) $foundDiv.addClass('hidden'); - $foundDiv = $this; - } - } else if ($this.hasClass('dropdown-header') && $lisVisible.eq(index + 1).data('optgroup') !== $this.data('optgroup')) { - $this.addClass('hidden'); - } else { - $foundDiv = null; - } - }); - if ($foundDiv) $foundDiv.addClass('hidden'); - - $searchBase.not('.hidden').first().addClass('active'); - that.$menuInner.scrollTop(0); - } - } - }); - }, - - _searchStyle: function () { - var styles = { - begins: 'ibegins', - startsWith: 'ibegins' - }; - - return styles[this.options.liveSearchStyle] || 'icontains'; - }, - - val: function (value) { - if (typeof value !== 'undefined') { - this.$element.val(value); - this.render(); - - return this.$element; - } else { - return this.$element.val(); - } - }, - - changeAll: function (status) { - if (!this.multiple) return; - if (typeof status === 'undefined') status = true; - - this.findLis(); - - var $options = this.$element.find('option'), - $lisVisible = this.$lis.not('.divider, .dropdown-header, .disabled, .hidden'), - lisVisLen = $lisVisible.length, - selectedOptions = []; - - if (status) { - if ($lisVisible.filter('.selected').length === $lisVisible.length) return; - } else { - if ($lisVisible.filter('.selected').length === 0) return; - } - - $lisVisible.toggleClass('selected', status); - - for (var i = 0; i < lisVisLen; i++) { - var origIndex = $lisVisible[i].getAttribute('data-original-index'); - selectedOptions[selectedOptions.length] = $options.eq(origIndex)[0]; - } - - $(selectedOptions).prop('selected', status); - - this.render(false); - - this.togglePlaceholder(); - - this.$element - .triggerNative('change'); - }, - - selectAll: function () { - return this.changeAll(true); - }, - - deselectAll: function () { - return this.changeAll(false); - }, - - toggle: function (e) { - e = e || window.event; - - if (e) e.stopPropagation(); - - this.$button.trigger('click'); - }, - - keydown: function (e) { - var $this = $(this), - $parent = $this.is('input') ? $this.parent().parent() : $this.parent(), - $items, - that = $parent.data('this'), - index, - prevIndex, - isActive, - selector = ':not(.disabled, .hidden, .dropdown-header, .divider)', - keyCodeMap = { - 32: ' ', - 48: '0', - 49: '1', - 50: '2', - 51: '3', - 52: '4', - 53: '5', - 54: '6', - 55: '7', - 56: '8', - 57: '9', - 59: ';', - 65: 'a', - 66: 'b', - 67: 'c', - 68: 'd', - 69: 'e', - 70: 'f', - 71: 'g', - 72: 'h', - 73: 'i', - 74: 'j', - 75: 'k', - 76: 'l', - 77: 'm', - 78: 'n', - 79: 'o', - 80: 'p', - 81: 'q', - 82: 'r', - 83: 's', - 84: 't', - 85: 'u', - 86: 'v', - 87: 'w', - 88: 'x', - 89: 'y', - 90: 'z', - 96: '0', - 97: '1', - 98: '2', - 99: '3', - 100: '4', - 101: '5', - 102: '6', - 103: '7', - 104: '8', - 105: '9' - }; - - - isActive = that.$newElement.hasClass('open'); - - if (!isActive && (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 65 && e.keyCode <= 90)) { - if (!that.options.container) { - that.setSize(); - that.$menu.parent().addClass('open'); - isActive = true; - } else { - that.$button.trigger('click'); - } - that.$searchbox.focus(); - return; - } - - if (that.options.liveSearch) { - if (/(^9$|27)/.test(e.keyCode.toString(10)) && isActive) { - e.preventDefault(); - e.stopPropagation(); - that.$menuInner.click(); - that.$button.focus(); - } - } - - if (/(38|40)/.test(e.keyCode.toString(10))) { - $items = that.$lis.filter(selector); - if (!$items.length) return; - - if (!that.options.liveSearch) { - index = $items.index($items.find('a').filter(':focus').parent()); - } else { - index = $items.index($items.filter('.active')); - } - - prevIndex = that.$menuInner.data('prevIndex'); - - if (e.keyCode == 38) { - if ((that.options.liveSearch || index == prevIndex) && index != -1) index--; - if (index < 0) index += $items.length; - } else if (e.keyCode == 40) { - if (that.options.liveSearch || index == prevIndex) index++; - index = index % $items.length; - } - - that.$menuInner.data('prevIndex', index); - - if (!that.options.liveSearch) { - $items.eq(index).children('a').focus(); - } else { - e.preventDefault(); - if (!$this.hasClass('dropdown-toggle')) { - $items.removeClass('active').eq(index).addClass('active').children('a').focus(); - $this.focus(); - } - } - - } else if (!$this.is('input')) { - var keyIndex = [], - count, - prevKey; - - $items = that.$lis.filter(selector); - $items.each(function (i) { - if ($.trim($(this).children('a').text().toLowerCase()).substring(0, 1) == keyCodeMap[e.keyCode]) { - keyIndex.push(i); - } - }); - - count = $(document).data('keycount'); - count++; - $(document).data('keycount', count); - - prevKey = $.trim($(':focus').text().toLowerCase()).substring(0, 1); - - if (prevKey != keyCodeMap[e.keyCode]) { - count = 1; - $(document).data('keycount', count); - } else if (count >= keyIndex.length) { - $(document).data('keycount', 0); - if (count > keyIndex.length) count = 1; - } - - $items.eq(keyIndex[count - 1]).children('a').focus(); - } - - // Select focused option if "Enter", "Spacebar" or "Tab" (when selectOnTab is true) are pressed inside the menu. - if ((/(13|32)/.test(e.keyCode.toString(10)) || (/(^9$)/.test(e.keyCode.toString(10)) && that.options.selectOnTab)) && isActive) { - if (!/(32)/.test(e.keyCode.toString(10))) e.preventDefault(); - if (!that.options.liveSearch) { - var elem = $(':focus'); - elem.click(); - // Bring back focus for multiselects - elem.focus(); - // Prevent screen from scrolling if the user hit the spacebar - e.preventDefault(); - // Fixes spacebar selection of dropdown items in FF & IE - $(document).data('spaceSelect', true); - } else if (!/(32)/.test(e.keyCode.toString(10))) { - that.$menuInner.find('.active a').click(); - $this.focus(); - } - $(document).data('keycount', 0); - } - - if ((/(^9$|27)/.test(e.keyCode.toString(10)) && isActive && (that.multiple || that.options.liveSearch)) || (/(27)/.test(e.keyCode.toString(10)) && !isActive)) { - that.$menu.parent().removeClass('open'); - if (that.options.container) that.$newElement.removeClass('open'); - that.$button.focus(); - } - }, - - mobile: function () { - this.$element.addClass('mobile-device'); - }, - - refresh: function () { - this.$lis = null; - this.liObj = {}; - this.reloadLi(); - this.render(); - this.checkDisabled(); - this.liHeight(true); - this.setStyle(); - this.setWidth(); - if (this.$lis) this.$searchbox.trigger('propertychange'); - - this.$element.trigger('refreshed.bs.select'); - }, - - hide: function () { - this.$newElement.hide(); - }, - - show: function () { - this.$newElement.show(); - }, - - remove: function () { - this.$newElement.remove(); - this.$element.remove(); - }, - - destroy: function () { - this.$newElement.before(this.$element).remove(); - - if (this.$bsContainer) { - this.$bsContainer.remove(); - } else { - this.$menu.remove(); - } - - this.$element - .off('.bs.select') - .removeData('selectpicker') - .removeClass('bs-select-hidden selectpicker'); - } - }; - - // SELECTPICKER PLUGIN DEFINITION - // ============================== - function Plugin(option) { - // get the args of the outer function.. - var args = arguments; - // The arguments of the function are explicitly re-defined from the argument list, because the shift causes them - // to get lost/corrupted in android 2.3 and IE9 #715 #775 - var _option = option; - - [].shift.apply(args); - - var value; - var chain = this.each(function () { - var $this = $(this); - if ($this.is('select')) { - var data = $this.data('selectpicker'), - options = typeof _option == 'object' && _option; - - if (!data) { - var config = $.extend({}, Selectpicker.DEFAULTS, $.fn.selectpicker.defaults || {}, $this.data(), options); - config.template = $.extend({}, Selectpicker.DEFAULTS.template, ($.fn.selectpicker.defaults ? $.fn.selectpicker.defaults.template : {}), $this.data().template, options.template); - $this.data('selectpicker', (data = new Selectpicker(this, config))); - } else if (options) { - for (var i in options) { - if (options.hasOwnProperty(i)) { - data.options[i] = options[i]; - } - } - } - - if (typeof _option == 'string') { - if (data[_option] instanceof Function) { - value = data[_option].apply(data, args); - } else { - value = data.options[_option]; - } - } - } - }); - - if (typeof value !== 'undefined') { - //noinspection JSUnusedAssignment - return value; - } else { - return chain; - } - } - - var old = $.fn.selectpicker; - $.fn.selectpicker = Plugin; - $.fn.selectpicker.Constructor = Selectpicker; - - // SELECTPICKER NO CONFLICT - // ======================== - $.fn.selectpicker.noConflict = function () { - $.fn.selectpicker = old; - return this; - }; - - $(document) - .data('keycount', 0) - .on('keydown.bs.select', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="listbox"], .bs-searchbox input', Selectpicker.prototype.keydown) - .on('focusin.modal', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="listbox"], .bs-searchbox input', function (e) { - e.stopPropagation(); - }); - - // SELECTPICKER DATA-API - // ===================== - $(window).on('load.bs.select.data-api', function () { - $('.selectpicker').each(function () { - var $selectpicker = $(this); - Plugin.call($selectpicker, $selectpicker.data()); - }) - }); -})(jQuery); +(function ($) { + 'use strict'; + + // + if (!String.prototype.includes) { + (function () { + 'use strict'; // needed to support `apply`/`call` with `undefined`/`null` + var toString = {}.toString; + var defineProperty = (function () { + // IE 8 only supports `Object.defineProperty` on DOM elements + try { + var object = {}; + var $defineProperty = Object.defineProperty; + var result = $defineProperty(object, object, object) && $defineProperty; + } catch (error) { + } + return result; + }()); + var indexOf = ''.indexOf; + var includes = function (search) { + if (this == null) { + throw new TypeError(); + } + var string = String(this); + if (search && toString.call(search) == '[object RegExp]') { + throw new TypeError(); + } + var stringLength = string.length; + var searchString = String(search); + var searchLength = searchString.length; + var position = arguments.length > 1 ? arguments[1] : undefined; + // `ToInteger` + var pos = position ? Number(position) : 0; + if (pos != pos) { // better `isNaN` + pos = 0; + } + var start = Math.min(Math.max(pos, 0), stringLength); + // Avoid the `indexOf` call if no match is possible + if (searchLength + start > stringLength) { + return false; + } + return indexOf.call(string, searchString, pos) != -1; + }; + if (defineProperty) { + defineProperty(String.prototype, 'includes', { + 'value': includes, + 'configurable': true, + 'writable': true + }); + } else { + String.prototype.includes = includes; + } + }()); + } + + if (!String.prototype.startsWith) { + (function () { + 'use strict'; // needed to support `apply`/`call` with `undefined`/`null` + var defineProperty = (function () { + // IE 8 only supports `Object.defineProperty` on DOM elements + try { + var object = {}; + var $defineProperty = Object.defineProperty; + var result = $defineProperty(object, object, object) && $defineProperty; + } catch (error) { + } + return result; + }()); + var toString = {}.toString; + var startsWith = function (search) { + if (this == null) { + throw new TypeError(); + } + var string = String(this); + if (search && toString.call(search) == '[object RegExp]') { + throw new TypeError(); + } + var stringLength = string.length; + var searchString = String(search); + var searchLength = searchString.length; + var position = arguments.length > 1 ? arguments[1] : undefined; + // `ToInteger` + var pos = position ? Number(position) : 0; + if (pos != pos) { // better `isNaN` + pos = 0; + } + var start = Math.min(Math.max(pos, 0), stringLength); + // Avoid the `indexOf` call if no match is possible + if (searchLength + start > stringLength) { + return false; + } + var index = -1; + while (++index < searchLength) { + if (string.charCodeAt(start + index) != searchString.charCodeAt(index)) { + return false; + } + } + return true; + }; + if (defineProperty) { + defineProperty(String.prototype, 'startsWith', { + 'value': startsWith, + 'configurable': true, + 'writable': true + }); + } else { + String.prototype.startsWith = startsWith; + } + }()); + } + + if (!Object.keys) { + Object.keys = function ( + o, // object + k, // key + r // result array + ){ + // initialize object and result + r=[]; + // iterate over object keys + for (k in o) + // fill result array with non-prototypical keys + r.hasOwnProperty.call(o, k) && r.push(k); + // return result + return r; + }; + } + + // set data-selected on select element if the value has been programmatically selected + // prior to initialization of bootstrap-select + // * consider removing or replacing an alternative method * + var valHooks = { + useDefault: false, + _set: $.valHooks.select.set + }; + + $.valHooks.select.set = function(elem, value) { + if (value && !valHooks.useDefault) $(elem).data('selected', true); + + return valHooks._set.apply(this, arguments); + }; + + var changed_arguments = null; + + var EventIsSupported = (function() { + try { + new Event('change'); + return true; + } catch (e) { + return false; + } + })(); + + $.fn.triggerNative = function (eventName) { + var el = this[0], + event; + + if (el.dispatchEvent) { // for modern browsers & IE9+ + if (EventIsSupported) { + // For modern browsers + event = new Event(eventName, { + bubbles: true + }); + } else { + // For IE since it doesn't support Event constructor + event = document.createEvent('Event'); + event.initEvent(eventName, true, false); + } + + el.dispatchEvent(event); + } else if (el.fireEvent) { // for IE8 + event = document.createEventObject(); + event.eventType = eventName; + el.fireEvent('on' + eventName, event); + } else { + // fall back to jQuery.trigger + this.trigger(eventName); + } + }; + // + + // Case insensitive contains search + $.expr.pseudos.icontains = function (obj, index, meta) { + var $obj = $(obj).find('a'); + var haystack = ($obj.data('tokens') || $obj.text()).toString().toUpperCase(); + return haystack.includes(meta[3].toUpperCase()); + }; + + // Case insensitive begins search + $.expr.pseudos.ibegins = function (obj, index, meta) { + var $obj = $(obj).find('a'); + var haystack = ($obj.data('tokens') || $obj.text()).toString().toUpperCase(); + return haystack.startsWith(meta[3].toUpperCase()); + }; + + // Case and accent insensitive contains search + $.expr.pseudos.aicontains = function (obj, index, meta) { + var $obj = $(obj).find('a'); + var haystack = ($obj.data('tokens') || $obj.data('normalizedText') || $obj.text()).toString().toUpperCase(); + return haystack.includes(meta[3].toUpperCase()); + }; + + // Case and accent insensitive begins search + $.expr.pseudos.aibegins = function (obj, index, meta) { + var $obj = $(obj).find('a'); + var haystack = ($obj.data('tokens') || $obj.data('normalizedText') || $obj.text()).toString().toUpperCase(); + return haystack.startsWith(meta[3].toUpperCase()); + }; + + /** + * Remove all diatrics from the given text. + * @access private + * @param {String} text + * @returns {String} + */ + function normalizeToBase(text) { + var rExps = [ + {re: /[\xC0-\xC6]/g, ch: "A"}, + {re: /[\xE0-\xE6]/g, ch: "a"}, + {re: /[\xC8-\xCB]/g, ch: "E"}, + {re: /[\xE8-\xEB]/g, ch: "e"}, + {re: /[\xCC-\xCF]/g, ch: "I"}, + {re: /[\xEC-\xEF]/g, ch: "i"}, + {re: /[\xD2-\xD6]/g, ch: "O"}, + {re: /[\xF2-\xF6]/g, ch: "o"}, + {re: /[\xD9-\xDC]/g, ch: "U"}, + {re: /[\xF9-\xFC]/g, ch: "u"}, + {re: /[\xC7-\xE7]/g, ch: "c"}, + {re: /[\xD1]/g, ch: "N"}, + {re: /[\xF1]/g, ch: "n"} + ]; + $.each(rExps, function () { + text = text ? text.replace(this.re, this.ch) : ''; + }); + return text; + } + + + // List of HTML entities for escaping. + var escapeMap = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''', + '`': '`' + }; + + var unescapeMap = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'", + '`': '`' + }; + + // Functions for escaping and unescaping strings to/from HTML interpolation. + var createEscaper = function(map) { + var escaper = function(match) { + return map[match]; + }; + // Regexes for identifying a key that needs to be escaped. + var source = '(?:' + Object.keys(map).join('|') + ')'; + var testRegexp = RegExp(source); + var replaceRegexp = RegExp(source, 'g'); + return function(string) { + string = string == null ? '' : '' + string; + return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string; + }; + }; + + var htmlEscape = createEscaper(escapeMap); + var htmlUnescape = createEscaper(unescapeMap); + + var Selectpicker = function (element, options) { + // bootstrap-select has been initialized - revert valHooks.select.set back to its original function + if (!valHooks.useDefault) { + $.valHooks.select.set = valHooks._set; + valHooks.useDefault = true; + } + + this.$element = $(element); + this.$newElement = null; + this.$button = null; + this.$menu = null; + this.$lis = null; + this.options = options; + + // If we have no title yet, try to pull it from the html title attribute (jQuery doesnt' pick it up as it's not a + // data-attribute) + if (this.options.title === null) { + this.options.title = this.$element.attr('title'); + } + + // Format window padding + var winPad = this.options.windowPadding; + if (typeof winPad === 'number') { + this.options.windowPadding = [winPad, winPad, winPad, winPad]; + } + + //Expose public methods + this.val = Selectpicker.prototype.val; + this.render = Selectpicker.prototype.render; + this.refresh = Selectpicker.prototype.refresh; + this.setStyle = Selectpicker.prototype.setStyle; + this.selectAll = Selectpicker.prototype.selectAll; + this.deselectAll = Selectpicker.prototype.deselectAll; + this.destroy = Selectpicker.prototype.destroy; + this.remove = Selectpicker.prototype.remove; + this.show = Selectpicker.prototype.show; + this.hide = Selectpicker.prototype.hide; + + this.init(); + }; + + Selectpicker.VERSION = '1.12.4'; + + // part of this is duplicated in i18n/defaults-en_US.js. Make sure to update both. + Selectpicker.DEFAULTS = { + noneSelectedText: 'Nothing selected', + noneResultsText: 'No results matched {0}', + countSelectedText: function (numSelected, numTotal) { + return (numSelected == 1) ? "{0} item selected" : "{0} items selected"; + }, + maxOptionsText: function (numAll, numGroup) { + return [ + (numAll == 1) ? 'Limit reached ({n} item max)' : 'Limit reached ({n} items max)', + (numGroup == 1) ? 'Group limit reached ({n} item max)' : 'Group limit reached ({n} items max)' + ]; + }, + selectAllText: 'Select All', + deselectAllText: 'Deselect All', + doneButton: false, + doneButtonText: 'Close', + multipleSeparator: ', ', + styleBase: 'btn', + style: 'btn-default', + size: 'auto', + title: null, + selectedTextFormat: 'values', + width: false, + container: false, + hideDisabled: false, + showSubtext: false, + showIcon: true, + showContent: true, + dropupAuto: true, + header: false, + liveSearch: false, + liveSearchPlaceholder: null, + liveSearchNormalize: false, + liveSearchStyle: 'contains', + actionsBox: false, + iconBase: 'glyphicon', + tickIcon: 'glyphicon-ok', + showTick: false, + template: { + caret: '' + }, + maxOptions: false, + mobile: false, + selectOnTab: false, + dropdownAlignRight: false, + windowPadding: 0 + }; + + Selectpicker.prototype = { + + constructor: Selectpicker, + + init: function () { + var that = this, + id = this.$element.attr('id'); + + this.$element.addClass('bs-select-hidden'); + + // store originalIndex (key) and newIndex (value) in this.liObj for fast accessibility + // allows us to do this.$lis.eq(that.liObj[index]) instead of this.$lis.filter('[data-original-index="' + index + '"]') + this.liObj = {}; + this.multiple = this.$element.prop('multiple'); + this.autofocus = this.$element.prop('autofocus'); + this.$newElement = this.createView(); + this.$element + .after(this.$newElement) + .appendTo(this.$newElement); + this.$button = this.$newElement.children('button'); + this.$menu = this.$newElement.children('.dropdown-menu'); + this.$menuInner = this.$menu.children('.inner'); + this.$searchbox = this.$menu.find('input'); + + this.$element.removeClass('bs-select-hidden'); + + if (this.options.dropdownAlignRight === true) this.$menu.addClass('dropdown-menu-right'); + + if (typeof id !== 'undefined') { + this.$button.attr('data-id', id); + $('label[for="' + id + '"]').click(function (e) { + e.preventDefault(); + that.$button.focus(); + }); + } + + this.checkDisabled(); + this.clickListener(); + if (this.options.liveSearch) this.liveSearchListener(); + this.render(); + this.setStyle(); + this.setWidth(); + if (this.options.container) this.selectPosition(); + this.$menu.data('this', this); + this.$newElement.data('this', this); + if (this.options.mobile) this.mobile(); + + this.$newElement.on({ + 'hide.bs.dropdown': function (e) { + that.$menuInner.attr('aria-expanded', false); + that.$element.trigger('hide.bs.select', e); + }, + 'hidden.bs.dropdown': function (e) { + that.$element.trigger('hidden.bs.select', e); + }, + 'show.bs.dropdown': function (e) { + that.$menuInner.attr('aria-expanded', true); + that.$element.trigger('show.bs.select', e); + }, + 'shown.bs.dropdown': function (e) { + that.$element.trigger('shown.bs.select', e); + } + }); + + if (that.$element[0].hasAttribute('required')) { + this.$element.on('invalid', function () { + that.$button.addClass('bs-invalid'); + + that.$element.on({ + 'focus.bs.select': function () { + that.$button.focus(); + that.$element.off('focus.bs.select'); + }, + 'shown.bs.select': function () { + that.$element + .val(that.$element.val()) // set the value to hide the validation message in Chrome when menu is opened + .off('shown.bs.select'); + }, + 'rendered.bs.select': function () { + // if select is no longer invalid, remove the bs-invalid class + if (this.validity.valid) that.$button.removeClass('bs-invalid'); + that.$element.off('rendered.bs.select'); + } + }); + + that.$button.on('blur.bs.select', function() { + that.$element.focus().blur(); + that.$button.off('blur.bs.select'); + }); + }); + } + + setTimeout(function () { + that.$element.trigger('loaded.bs.select'); + }); + }, + + createDropdown: function () { + // Options + // If we are multiple or showTick option is set, then add the show-tick class + var showTick = (this.multiple || this.options.showTick) ? ' show-tick' : '', + inputGroup = this.$element.parent().hasClass('input-group') ? ' input-group-btn' : '', + autofocus = this.autofocus ? ' autofocus' : ''; + // Elements + var header = this.options.header ? '
    ' + this.options.header + '
    ' : ''; + var searchbox = this.options.liveSearch ? + '' + : ''; + var actionsbox = this.multiple && this.options.actionsBox ? + '
    ' + + '
    ' + + '' + + '' + + '
    ' + + '
    ' + : ''; + var donebutton = this.multiple && this.options.doneButton ? + '
    ' + + '
    ' + + '' + + '
    ' + + '
    ' + : ''; + var drop = + '
    ' + + '' + + '' + + '
    '; + + return $(drop); + }, + + createView: function () { + var $drop = this.createDropdown(), + li = this.createLi(); + + $drop.find('ul')[0].innerHTML = li; + return $drop; + }, + + reloadLi: function () { + // rebuild + var li = this.createLi(); + this.$menuInner[0].innerHTML = li; + }, + + createLi: function () { + var that = this, + _li = [], + optID = 0, + titleOption = document.createElement('option'), + liIndex = -1; // increment liIndex whenever a new
  • element is created to ensure liObj is correct + + // Helper functions + /** + * @param content + * @param [index] + * @param [classes] + * @param [optgroup] + * @returns {string} + */ + var generateLI = function (content, index, classes, optgroup) { + return '' + content + '
  • '; + }; + + /** + * @param text + * @param [classes] + * @param [inline] + * @param [tokens] + * @returns {string} + */ + var generateA = function (text, classes, inline, tokens) { + return '' + text + + '' + + ''; + }; + + if (this.options.title && !this.multiple) { + // this option doesn't create a new
  • element, but does add a new option, so liIndex is decreased + // since liObj is recalculated on every refresh, liIndex needs to be decreased even if the titleOption is already appended + liIndex--; + + if (!this.$element.find('.bs-title-option').length) { + // Use native JS to prepend option (faster) + var element = this.$element[0]; + titleOption.className = 'bs-title-option'; + titleOption.innerHTML = this.options.title; + titleOption.value = ''; + element.insertBefore(titleOption, element.firstChild); + // Check if selected or data-selected attribute is already set on an option. If not, select the titleOption option. + // the selected item may have been changed by user or programmatically before the bootstrap select plugin runs, + // if so, the select will have the data-selected attribute + var $opt = $(element.options[element.selectedIndex]); + if ($opt.attr('selected') === undefined && this.$element.data('selected') === undefined) { + titleOption.selected = true; + } + } + } + + var $selectOptions = this.$element.find('option'); + + $selectOptions.each(function (index) { + var $this = $(this); + + liIndex++; + + if ($this.hasClass('bs-title-option')) return; + + // Get the class and text for the option + var optionClass = this.className || '', + inline = htmlEscape(this.style.cssText), + text = $this.data('content') ? $this.data('content') : $this.html(), + tokens = $this.data('tokens') ? $this.data('tokens') : null, + subtext = typeof $this.data('subtext') !== 'undefined' ? '' + $this.data('subtext') + '' : '', + icon = typeof $this.data('icon') !== 'undefined' ? ' ' : '', + $parent = $this.parent(), + isOptgroup = $parent[0].tagName === 'OPTGROUP', + isOptgroupDisabled = isOptgroup && $parent[0].disabled, + isDisabled = this.disabled || isOptgroupDisabled, + prevHiddenIndex; + + if (icon !== '' && isDisabled) { + icon = '' + icon + ''; + } + + if (that.options.hideDisabled && (isDisabled && !isOptgroup || isOptgroupDisabled)) { + // set prevHiddenIndex - the index of the first hidden option in a group of hidden options + // used to determine whether or not a divider should be placed after an optgroup if there are + // hidden options between the optgroup and the first visible option + prevHiddenIndex = $this.data('prevHiddenIndex'); + $this.next().data('prevHiddenIndex', (prevHiddenIndex !== undefined ? prevHiddenIndex : index)); + + liIndex--; + return; + } + + if (!$this.data('content')) { + // Prepend any icon and append any subtext to the main text. + text = icon + '' + text + subtext + ''; + } + + if (isOptgroup && $this.data('divider') !== true) { + if (that.options.hideDisabled && isDisabled) { + if ($parent.data('allOptionsDisabled') === undefined) { + var $options = $parent.children(); + $parent.data('allOptionsDisabled', $options.filter(':disabled').length === $options.length); + } + + if ($parent.data('allOptionsDisabled')) { + liIndex--; + return; + } + } + + var optGroupClass = ' ' + $parent[0].className || ''; + + if ($this.index() === 0) { // Is it the first option of the optgroup? + optID += 1; + + // Get the opt group label + var label = $parent[0].label, + labelSubtext = typeof $parent.data('subtext') !== 'undefined' ? '' + $parent.data('subtext') + '' : '', + labelIcon = $parent.data('icon') ? ' ' : ''; + + label = labelIcon + '' + htmlEscape(label) + labelSubtext + ''; + + if (index !== 0 && _li.length > 0) { // Is it NOT the first option of the select && are there elements in the dropdown? + liIndex++; + _li.push(generateLI('', null, 'divider', optID + 'div')); + } + liIndex++; + _li.push(generateLI(label, null, 'dropdown-header' + optGroupClass, optID)); + } + + if (that.options.hideDisabled && isDisabled) { + liIndex--; + return; + } + + _li.push(generateLI(generateA(text, 'opt ' + optionClass + optGroupClass, inline, tokens), index, '', optID)); + } else if ($this.data('divider') === true) { + _li.push(generateLI('', index, 'divider')); + } else if ($this.data('hidden') === true) { + // set prevHiddenIndex - the index of the first hidden option in a group of hidden options + // used to determine whether or not a divider should be placed after an optgroup if there are + // hidden options between the optgroup and the first visible option + prevHiddenIndex = $this.data('prevHiddenIndex'); + $this.next().data('prevHiddenIndex', (prevHiddenIndex !== undefined ? prevHiddenIndex : index)); + + _li.push(generateLI(generateA(text, optionClass, inline, tokens), index, 'hidden is-hidden')); + } else { + var showDivider = this.previousElementSibling && this.previousElementSibling.tagName === 'OPTGROUP'; + + // if previous element is not an optgroup and hideDisabled is true + if (!showDivider && that.options.hideDisabled) { + prevHiddenIndex = $this.data('prevHiddenIndex'); + + if (prevHiddenIndex !== undefined) { + // select the element **before** the first hidden element in the group + var prevHidden = $selectOptions.eq(prevHiddenIndex)[0].previousElementSibling; + + if (prevHidden && prevHidden.tagName === 'OPTGROUP' && !prevHidden.disabled) { + showDivider = true; + } + } + } + + if (showDivider) { + liIndex++; + _li.push(generateLI('', null, 'divider', optID + 'div')); + } + _li.push(generateLI(generateA(text, optionClass, inline, tokens), index)); + } + + that.liObj[index] = liIndex; + }); + + //If we are not multiple, we don't have a selected item, and we don't have a title, select the first element so something is set in the button + if (!this.multiple && this.$element.find('option:selected').length === 0 && !this.options.title) { + this.$element.find('option').eq(0).prop('selected', true).attr('selected', 'selected'); + } + + return _li.join(''); + }, + + findLis: function () { + if (this.$lis == null) this.$lis = this.$menu.find('li'); + return this.$lis; + }, + + /** + * @param [updateLi] defaults to true + */ + render: function (updateLi) { + var that = this, + notDisabled, + $selectOptions = this.$element.find('option'); + + //Update the LI to match the SELECT + if (updateLi !== false) { + $selectOptions.each(function (index) { + var $lis = that.findLis().eq(that.liObj[index]); + + that.setDisabled(index, this.disabled || this.parentNode.tagName === 'OPTGROUP' && this.parentNode.disabled, $lis); + that.setSelected(index, this.selected, $lis); + }); + } + + this.togglePlaceholder(); + + this.tabIndex(); + + var selectedItems = $selectOptions.map(function () { + if (this.selected) { + if (that.options.hideDisabled && (this.disabled || this.parentNode.tagName === 'OPTGROUP' && this.parentNode.disabled)) return; + + var $this = $(this), + icon = $this.data('icon') && that.options.showIcon ? ' ' : '', + subtext; + + if (that.options.showSubtext && $this.data('subtext') && !that.multiple) { + subtext = ' ' + $this.data('subtext') + ''; + } else { + subtext = ''; + } + if (typeof $this.attr('title') !== 'undefined') { + return $this.attr('title'); + } else if ($this.data('content') && that.options.showContent) { + return $this.data('content').toString(); + } else { + return icon + $this.html() + subtext; + } + } + }).toArray(); + + //Fixes issue in IE10 occurring when no default option is selected and at least one option is disabled + //Convert all the values into a comma delimited string + var title = !this.multiple ? selectedItems[0] : selectedItems.join(this.options.multipleSeparator); + + //If this is multi select, and the selectText type is count, the show 1 of 2 selected etc.. + if (this.multiple && this.options.selectedTextFormat.indexOf('count') > -1) { + var max = this.options.selectedTextFormat.split('>'); + if ((max.length > 1 && selectedItems.length > max[1]) || (max.length == 1 && selectedItems.length >= 2)) { + notDisabled = this.options.hideDisabled ? ', [disabled]' : ''; + var totalCount = $selectOptions.not('[data-divider="true"], [data-hidden="true"]' + notDisabled).length, + tr8nText = (typeof this.options.countSelectedText === 'function') ? this.options.countSelectedText(selectedItems.length, totalCount) : this.options.countSelectedText; + title = tr8nText.replace('{0}', selectedItems.length.toString()).replace('{1}', totalCount.toString()); + } + } + + if (this.options.title == undefined) { + this.options.title = this.$element.attr('title'); + } + + if (this.options.selectedTextFormat == 'static') { + title = this.options.title; + } + + //If we dont have a title, then use the default, or if nothing is set at all, use the not selected text + if (!title) { + title = typeof this.options.title !== 'undefined' ? this.options.title : this.options.noneSelectedText; + } + + //strip all HTML tags and trim the result, then unescape any escaped tags + this.$button.attr('title', htmlUnescape($.trim(title.replace(/<[^>]*>?/g, '')))); + this.$button.children('.filter-option').html(title); + + this.$element.trigger('rendered.bs.select'); + }, + + /** + * @param [style] + * @param [status] + */ + setStyle: function (style, status) { + if (this.$element.attr('class')) { + this.$newElement.addClass(this.$element.attr('class').replace(/selectpicker|mobile-device|bs-select-hidden|validate\[.*\]/gi, '')); + } + + var buttonClass = style ? style : this.options.style; + + if (status == 'add') { + this.$button.addClass(buttonClass); + } else if (status == 'remove') { + this.$button.removeClass(buttonClass); + } else { + this.$button.removeClass(this.options.style); + this.$button.addClass(buttonClass); + } + }, + + liHeight: function (refresh) { + if (!refresh && (this.options.size === false || this.sizeInfo)) return; + + var newElement = document.createElement('div'), + menu = document.createElement('div'), + menuInner = document.createElement('ul'), + divider = document.createElement('li'), + li = document.createElement('li'), + a = document.createElement('a'), + text = document.createElement('span'), + header = this.options.header && this.$menu.find('.popover-title').length > 0 ? this.$menu.find('.popover-title')[0].cloneNode(true) : null, + search = this.options.liveSearch ? document.createElement('div') : null, + actions = this.options.actionsBox && this.multiple && this.$menu.find('.bs-actionsbox').length > 0 ? this.$menu.find('.bs-actionsbox')[0].cloneNode(true) : null, + doneButton = this.options.doneButton && this.multiple && this.$menu.find('.bs-donebutton').length > 0 ? this.$menu.find('.bs-donebutton')[0].cloneNode(true) : null; + + text.className = 'text'; + newElement.className = this.$menu[0].parentNode.className + ' open'; + menu.className = 'dropdown-menu open'; + menuInner.className = 'dropdown-menu inner'; + divider.className = 'divider'; + + text.appendChild(document.createTextNode('Inner text')); + a.appendChild(text); + li.appendChild(a); + menuInner.appendChild(li); + menuInner.appendChild(divider); + if (header) menu.appendChild(header); + if (search) { + var input = document.createElement('input'); + search.className = 'bs-searchbox'; + input.className = 'form-control'; + search.appendChild(input); + menu.appendChild(search); + } + if (actions) menu.appendChild(actions); + menu.appendChild(menuInner); + if (doneButton) menu.appendChild(doneButton); + newElement.appendChild(menu); + + document.body.appendChild(newElement); + + var liHeight = a.offsetHeight, + headerHeight = header ? header.offsetHeight : 0, + searchHeight = search ? search.offsetHeight : 0, + actionsHeight = actions ? actions.offsetHeight : 0, + doneButtonHeight = doneButton ? doneButton.offsetHeight : 0, + dividerHeight = $(divider).outerHeight(true), + // fall back to jQuery if getComputedStyle is not supported + menuStyle = typeof getComputedStyle === 'function' ? getComputedStyle(menu) : false, + $menu = menuStyle ? null : $(menu), + menuPadding = { + vert: parseInt(menuStyle ? menuStyle.paddingTop : $menu.css('paddingTop')) + + parseInt(menuStyle ? menuStyle.paddingBottom : $menu.css('paddingBottom')) + + parseInt(menuStyle ? menuStyle.borderTopWidth : $menu.css('borderTopWidth')) + + parseInt(menuStyle ? menuStyle.borderBottomWidth : $menu.css('borderBottomWidth')), + horiz: parseInt(menuStyle ? menuStyle.paddingLeft : $menu.css('paddingLeft')) + + parseInt(menuStyle ? menuStyle.paddingRight : $menu.css('paddingRight')) + + parseInt(menuStyle ? menuStyle.borderLeftWidth : $menu.css('borderLeftWidth')) + + parseInt(menuStyle ? menuStyle.borderRightWidth : $menu.css('borderRightWidth')) + }, + menuExtras = { + vert: menuPadding.vert + + parseInt(menuStyle ? menuStyle.marginTop : $menu.css('marginTop')) + + parseInt(menuStyle ? menuStyle.marginBottom : $menu.css('marginBottom')) + 2, + horiz: menuPadding.horiz + + parseInt(menuStyle ? menuStyle.marginLeft : $menu.css('marginLeft')) + + parseInt(menuStyle ? menuStyle.marginRight : $menu.css('marginRight')) + 2 + } + + document.body.removeChild(newElement); + + this.sizeInfo = { + liHeight: liHeight, + headerHeight: headerHeight, + searchHeight: searchHeight, + actionsHeight: actionsHeight, + doneButtonHeight: doneButtonHeight, + dividerHeight: dividerHeight, + menuPadding: menuPadding, + menuExtras: menuExtras + }; + }, + + setSize: function () { + this.findLis(); + this.liHeight(); + + if (this.options.header) this.$menu.css('padding-top', 0); + if (this.options.size === false) return; + + var that = this, + $menu = this.$menu, + $menuInner = this.$menuInner, + $window = $(window), + selectHeight = this.$newElement[0].offsetHeight, + selectWidth = this.$newElement[0].offsetWidth, + liHeight = this.sizeInfo['liHeight'], + headerHeight = this.sizeInfo['headerHeight'], + searchHeight = this.sizeInfo['searchHeight'], + actionsHeight = this.sizeInfo['actionsHeight'], + doneButtonHeight = this.sizeInfo['doneButtonHeight'], + divHeight = this.sizeInfo['dividerHeight'], + menuPadding = this.sizeInfo['menuPadding'], + menuExtras = this.sizeInfo['menuExtras'], + notDisabled = this.options.hideDisabled ? '.disabled' : '', + menuHeight, + menuWidth, + getHeight, + getWidth, + selectOffsetTop, + selectOffsetBot, + selectOffsetLeft, + selectOffsetRight, + getPos = function() { + var pos = that.$newElement.offset(), + $container = $(that.options.container), + containerPos; + + if (that.options.container && !$container.is('body')) { + containerPos = $container.offset(); + containerPos.top += parseInt($container.css('borderTopWidth')); + containerPos.left += parseInt($container.css('borderLeftWidth')); + } else { + containerPos = { top: 0, left: 0 }; + } + + var winPad = that.options.windowPadding; + selectOffsetTop = pos.top - containerPos.top - $window.scrollTop(); + selectOffsetBot = $window.height() - selectOffsetTop - selectHeight - containerPos.top - winPad[2]; + selectOffsetLeft = pos.left - containerPos.left - $window.scrollLeft(); + selectOffsetRight = $window.width() - selectOffsetLeft - selectWidth - containerPos.left - winPad[1]; + selectOffsetTop -= winPad[0]; + selectOffsetLeft -= winPad[3]; + }; + + getPos(); + + if (this.options.size === 'auto') { + var getSize = function () { + var minHeight, + hasClass = function (className, include) { + return function (element) { + if (include) { + return (element.classList ? element.classList.contains(className) : $(element).hasClass(className)); + } else { + return !(element.classList ? element.classList.contains(className) : $(element).hasClass(className)); + } + }; + }, + lis = that.$menuInner[0].getElementsByTagName('li'), + lisVisible = Array.prototype.filter ? Array.prototype.filter.call(lis, hasClass('hidden', false)) : that.$lis.not('.hidden'), + optGroup = Array.prototype.filter ? Array.prototype.filter.call(lisVisible, hasClass('dropdown-header', true)) : lisVisible.filter('.dropdown-header'); + + getPos(); + menuHeight = selectOffsetBot - menuExtras.vert; + menuWidth = selectOffsetRight - menuExtras.horiz; + + if (that.options.container) { + if (!$menu.data('height')) $menu.data('height', $menu.height()); + getHeight = $menu.data('height'); + + if (!$menu.data('width')) $menu.data('width', $menu.width()); + getWidth = $menu.data('width'); + } else { + getHeight = $menu.height(); + getWidth = $menu.width(); + } + + if (that.options.dropupAuto) { + that.$newElement.toggleClass('dropup', selectOffsetTop > selectOffsetBot && (menuHeight - menuExtras.vert) < getHeight); + } + + if (that.$newElement.hasClass('dropup')) { + menuHeight = selectOffsetTop - menuExtras.vert; + } + + if (that.options.dropdownAlignRight === 'auto') { + $menu.toggleClass('dropdown-menu-right', selectOffsetLeft > selectOffsetRight && (menuWidth - menuExtras.horiz) < (getWidth - selectWidth)); + } + + if ((lisVisible.length + optGroup.length) > 3) { + minHeight = liHeight * 3 + menuExtras.vert - 2; + } else { + minHeight = 0; + } + + $menu.css({ + 'max-height': menuHeight + 'px', + 'overflow': 'hidden', + 'min-height': minHeight + headerHeight + searchHeight + actionsHeight + doneButtonHeight + 'px' + }); + $menuInner.css({ + 'max-height': menuHeight - headerHeight - searchHeight - actionsHeight - doneButtonHeight - menuPadding.vert + 'px', + 'overflow-y': 'auto', + 'min-height': Math.max(minHeight - menuPadding.vert, 0) + 'px' + }); + }; + getSize(); + this.$searchbox.off('input.getSize propertychange.getSize').on('input.getSize propertychange.getSize', getSize); + $window.off('resize.getSize scroll.getSize').on('resize.getSize scroll.getSize', getSize); + } else if (this.options.size && this.options.size != 'auto' && this.$lis.not(notDisabled).length > this.options.size) { + var optIndex = this.$lis.not('.divider').not(notDisabled).children().slice(0, this.options.size).last().parent().index(), + divLength = this.$lis.slice(0, optIndex + 1).filter('.divider').length; + menuHeight = liHeight * this.options.size + divLength * divHeight + menuPadding.vert; + + if (that.options.container) { + if (!$menu.data('height')) $menu.data('height', $menu.height()); + getHeight = $menu.data('height'); + } else { + getHeight = $menu.height(); + } + + if (that.options.dropupAuto) { + //noinspection JSUnusedAssignment + this.$newElement.toggleClass('dropup', selectOffsetTop > selectOffsetBot && (menuHeight - menuExtras.vert) < getHeight); + } + $menu.css({ + 'max-height': menuHeight + headerHeight + searchHeight + actionsHeight + doneButtonHeight + 'px', + 'overflow': 'hidden', + 'min-height': '' + }); + $menuInner.css({ + 'max-height': menuHeight - menuPadding.vert + 'px', + 'overflow-y': 'auto', + 'min-height': '' + }); + } + }, + + setWidth: function () { + if (this.options.width === 'auto') { + this.$menu.css('min-width', '0'); + + // Get correct width if element is hidden + var $selectClone = this.$menu.parent().clone().appendTo('body'), + $selectClone2 = this.options.container ? this.$newElement.clone().appendTo('body') : $selectClone, + ulWidth = $selectClone.children('.dropdown-menu').outerWidth(), + btnWidth = $selectClone2.css('width', 'auto').children('button').outerWidth(); + + $selectClone.remove(); + $selectClone2.remove(); + + // Set width to whatever's larger, button title or longest option + this.$newElement.css('width', Math.max(ulWidth, btnWidth) + 'px'); + } else if (this.options.width === 'fit') { + // Remove inline min-width so width can be changed from 'auto' + this.$menu.css('min-width', ''); + this.$newElement.css('width', '').addClass('fit-width'); + } else if (this.options.width) { + // Remove inline min-width so width can be changed from 'auto' + this.$menu.css('min-width', ''); + this.$newElement.css('width', this.options.width); + } else { + // Remove inline min-width/width so width can be changed + this.$menu.css('min-width', ''); + this.$newElement.css('width', ''); + } + // Remove fit-width class if width is changed programmatically + if (this.$newElement.hasClass('fit-width') && this.options.width !== 'fit') { + this.$newElement.removeClass('fit-width'); + } + }, + + selectPosition: function () { + this.$bsContainer = $('
    '); + + var that = this, + $container = $(this.options.container), + pos, + containerPos, + actualHeight, + getPlacement = function ($element) { + that.$bsContainer.addClass($element.attr('class').replace(/form-control|fit-width/gi, '')).toggleClass('dropup', $element.hasClass('dropup')); + pos = $element.offset(); + + if (!$container.is('body')) { + containerPos = $container.offset(); + containerPos.top += parseInt($container.css('borderTopWidth')) - $container.scrollTop(); + containerPos.left += parseInt($container.css('borderLeftWidth')) - $container.scrollLeft(); + } else { + containerPos = { top: 0, left: 0 }; + } + + actualHeight = $element.hasClass('dropup') ? 0 : $element[0].offsetHeight; + + that.$bsContainer.css({ + 'top': pos.top - containerPos.top + actualHeight, + 'left': pos.left - containerPos.left, + 'width': $element[0].offsetWidth + }); + }; + + this.$button.on('click', function () { + var $this = $(this); + + if (that.isDisabled()) { + return; + } + + getPlacement(that.$newElement); + + that.$bsContainer + .appendTo(that.options.container) + .toggleClass('open', !$this.hasClass('open')) + .append(that.$menu); + }); + + $(window).on('resize scroll', function () { + getPlacement(that.$newElement); + }); + + this.$element.on('hide.bs.select', function () { + that.$menu.data('height', that.$menu.height()); + that.$bsContainer.detach(); + }); + }, + + /** + * @param {number} index - the index of the option that is being changed + * @param {boolean} selected - true if the option is being selected, false if being deselected + * @param {JQuery} $lis - the 'li' element that is being modified + */ + setSelected: function (index, selected, $lis) { + if (!$lis) { + this.togglePlaceholder(); // check if setSelected is being called by changing the value of the select + $lis = this.findLis().eq(this.liObj[index]); + } + + $lis.toggleClass('selected', selected).find('a').attr('aria-selected', selected); + }, + + /** + * @param {number} index - the index of the option that is being disabled + * @param {boolean} disabled - true if the option is being disabled, false if being enabled + * @param {JQuery} $lis - the 'li' element that is being modified + */ + setDisabled: function (index, disabled, $lis) { + if (!$lis) { + $lis = this.findLis().eq(this.liObj[index]); + } + + if (disabled) { + $lis.addClass('disabled').children('a').attr('href', '#').attr('tabindex', -1).attr('aria-disabled', true); + } else { + $lis.removeClass('disabled').children('a').removeAttr('href').attr('tabindex', 0).attr('aria-disabled', false); + } + }, + + isDisabled: function () { + return this.$element[0].disabled; + }, + + checkDisabled: function () { + var that = this; + + if (this.isDisabled()) { + this.$newElement.addClass('disabled'); + this.$button.addClass('disabled').attr('tabindex', -1).attr('aria-disabled', true); + } else { + if (this.$button.hasClass('disabled')) { + this.$newElement.removeClass('disabled'); + this.$button.removeClass('disabled').attr('aria-disabled', false); + } + + if (this.$button.attr('tabindex') == -1 && !this.$element.data('tabindex')) { + this.$button.removeAttr('tabindex'); + } + } + + this.$button.click(function () { + return !that.isDisabled(); + }); + }, + + togglePlaceholder: function () { + var value = this.$element.val(); + this.$button.toggleClass('bs-placeholder', value === null || value === '' || (value.constructor === Array && value.length === 0)); + }, + + tabIndex: function () { + if (this.$element.data('tabindex') !== this.$element.attr('tabindex') && + (this.$element.attr('tabindex') !== -98 && this.$element.attr('tabindex') !== '-98')) { + this.$element.data('tabindex', this.$element.attr('tabindex')); + this.$button.attr('tabindex', this.$element.data('tabindex')); + } + + this.$element.attr('tabindex', -98); + }, + + clickListener: function () { + var that = this, + $document = $(document); + + $document.data('spaceSelect', false); + + this.$button.on('keyup', function (e) { + if (/(32)/.test(e.keyCode.toString(10)) && $document.data('spaceSelect')) { + e.preventDefault(); + $document.data('spaceSelect', false); + } + }); + + this.$button.on('click', function () { + that.setSize(); + }); + + this.$element.on('shown.bs.select', function () { + if (!that.options.liveSearch && !that.multiple) { + that.$menuInner.find('.selected a').focus(); + } else if (!that.multiple) { + var selectedIndex = that.liObj[that.$element[0].selectedIndex]; + + if (typeof selectedIndex !== 'number' || that.options.size === false) return; + + // scroll to selected option + var offset = that.$lis.eq(selectedIndex)[0].offsetTop - that.$menuInner[0].offsetTop; + offset = offset - that.$menuInner[0].offsetHeight/2 + that.sizeInfo.liHeight/2; + that.$menuInner[0].scrollTop = offset; + } + }); + + this.$menuInner.on('click', 'li a', function (e) { + var $this = $(this), + clickedIndex = $this.parent().data('originalIndex'), + prevValue = that.$element.val(), + prevIndex = that.$element.prop('selectedIndex'), + triggerChange = true; + + // Don't close on multi choice menu + if (that.multiple && that.options.maxOptions !== 1) { + e.stopPropagation(); + } + + e.preventDefault(); + + //Don't run if we have been disabled + if (!that.isDisabled() && !$this.parent().hasClass('disabled')) { + var $options = that.$element.find('option'), + $option = $options.eq(clickedIndex), + state = $option.prop('selected'), + $optgroup = $option.parent('optgroup'), + maxOptions = that.options.maxOptions, + maxOptionsGrp = $optgroup.data('maxOptions') || false; + + if (!that.multiple) { // Deselect all others if not multi select box + $options.prop('selected', false); + $option.prop('selected', true); + that.$menuInner.find('.selected').removeClass('selected').find('a').attr('aria-selected', false); + that.setSelected(clickedIndex, true); + } else { // Toggle the one we have chosen if we are multi select. + $option.prop('selected', !state); + that.setSelected(clickedIndex, !state); + $this.blur(); + + if (maxOptions !== false || maxOptionsGrp !== false) { + var maxReached = maxOptions < $options.filter(':selected').length, + maxReachedGrp = maxOptionsGrp < $optgroup.find('option:selected').length; + + if ((maxOptions && maxReached) || (maxOptionsGrp && maxReachedGrp)) { + if (maxOptions && maxOptions == 1) { + $options.prop('selected', false); + $option.prop('selected', true); + that.$menuInner.find('.selected').removeClass('selected'); + that.setSelected(clickedIndex, true); + } else if (maxOptionsGrp && maxOptionsGrp == 1) { + $optgroup.find('option:selected').prop('selected', false); + $option.prop('selected', true); + var optgroupID = $this.parent().data('optgroup'); + that.$menuInner.find('[data-optgroup="' + optgroupID + '"]').removeClass('selected'); + that.setSelected(clickedIndex, true); + } else { + var maxOptionsText = typeof that.options.maxOptionsText === 'string' ? [that.options.maxOptionsText, that.options.maxOptionsText] : that.options.maxOptionsText, + maxOptionsArr = typeof maxOptionsText === 'function' ? maxOptionsText(maxOptions, maxOptionsGrp) : maxOptionsText, + maxTxt = maxOptionsArr[0].replace('{n}', maxOptions), + maxTxtGrp = maxOptionsArr[1].replace('{n}', maxOptionsGrp), + $notify = $('
    '); + // If {var} is set in array, replace it + /** @deprecated */ + if (maxOptionsArr[2]) { + maxTxt = maxTxt.replace('{var}', maxOptionsArr[2][maxOptions > 1 ? 0 : 1]); + maxTxtGrp = maxTxtGrp.replace('{var}', maxOptionsArr[2][maxOptionsGrp > 1 ? 0 : 1]); + } + + $option.prop('selected', false); + + that.$menu.append($notify); + + if (maxOptions && maxReached) { + $notify.append($('
    ' + maxTxt + '
    ')); + triggerChange = false; + that.$element.trigger('maxReached.bs.select'); + } + + if (maxOptionsGrp && maxReachedGrp) { + $notify.append($('
    ' + maxTxtGrp + '
    ')); + triggerChange = false; + that.$element.trigger('maxReachedGrp.bs.select'); + } + + setTimeout(function () { + that.setSelected(clickedIndex, false); + }, 10); + + $notify.delay(750).fadeOut(300, function () { + $(this).remove(); + }); + } + } + } + } + + if (!that.multiple || (that.multiple && that.options.maxOptions === 1)) { + that.$button.focus(); + } else if (that.options.liveSearch) { + that.$searchbox.focus(); + } + + // Trigger select 'change' + if (triggerChange) { + if ((prevValue != that.$element.val() && that.multiple) || (prevIndex != that.$element.prop('selectedIndex') && !that.multiple)) { + // $option.prop('selected') is current option state (selected/unselected). state is previous option state. + changed_arguments = [clickedIndex, $option.prop('selected'), state]; + that.$element + .triggerNative('change'); + } + } + } + }); + + this.$menu.on('click', 'li.disabled a, .popover-title, .popover-title :not(.close)', function (e) { + if (e.currentTarget == this) { + e.preventDefault(); + e.stopPropagation(); + if (that.options.liveSearch && !$(e.target).hasClass('close')) { + that.$searchbox.focus(); + } else { + that.$button.focus(); + } + } + }); + + this.$menuInner.on('click', '.divider, .dropdown-header', function (e) { + e.preventDefault(); + e.stopPropagation(); + if (that.options.liveSearch) { + that.$searchbox.focus(); + } else { + that.$button.focus(); + } + }); + + this.$menu.on('click', '.popover-title .close', function () { + that.$button.click(); + }); + + this.$searchbox.on('click', function (e) { + e.stopPropagation(); + }); + + this.$menu.on('click', '.actions-btn', function (e) { + if (that.options.liveSearch) { + that.$searchbox.focus(); + } else { + that.$button.focus(); + } + + e.preventDefault(); + e.stopPropagation(); + + if ($(this).hasClass('bs-select-all')) { + that.selectAll(); + } else { + that.deselectAll(); + } + }); + + this.$element.change(function () { + that.render(false); + that.$element.trigger('changed.bs.select', changed_arguments); + changed_arguments = null; + }); + }, + + liveSearchListener: function () { + var that = this, + $no_results = $('
  • '); + + this.$button.on('click.dropdown.data-api', function () { + that.$menuInner.find('.active').removeClass('active'); + if (!!that.$searchbox.val()) { + that.$searchbox.val(''); + that.$lis.not('.is-hidden').removeClass('hidden'); + if (!!$no_results.parent().length) $no_results.remove(); + } + if (!that.multiple) that.$menuInner.find('.selected').addClass('active'); + setTimeout(function () { + that.$searchbox.focus(); + }, 10); + }); + + this.$searchbox.on('click.dropdown.data-api focus.dropdown.data-api touchend.dropdown.data-api', function (e) { + e.stopPropagation(); + }); + + this.$searchbox.on('input propertychange', function () { + that.$lis.not('.is-hidden').removeClass('hidden'); + that.$lis.filter('.active').removeClass('active'); + $no_results.remove(); + + if (that.$searchbox.val()) { + var $searchBase = that.$lis.not('.is-hidden, .divider, .dropdown-header'), + $hideItems; + if (that.options.liveSearchNormalize) { + $hideItems = $searchBase.not(':a' + that._searchStyle() + '("' + normalizeToBase(that.$searchbox.val()) + '")'); + } else { + $hideItems = $searchBase.not(':' + that._searchStyle() + '("' + that.$searchbox.val() + '")'); + } + + if ($hideItems.length === $searchBase.length) { + $no_results.html(that.options.noneResultsText.replace('{0}', '"' + htmlEscape(that.$searchbox.val()) + '"')); + that.$menuInner.append($no_results); + that.$lis.addClass('hidden'); + } else { + $hideItems.addClass('hidden'); + + var $lisVisible = that.$lis.not('.hidden'), + $foundDiv; + + // hide divider if first or last visible, or if followed by another divider + $lisVisible.each(function (index) { + var $this = $(this); + + if ($this.hasClass('divider')) { + if ($foundDiv === undefined) { + $this.addClass('hidden'); + } else { + if ($foundDiv) $foundDiv.addClass('hidden'); + $foundDiv = $this; + } + } else if ($this.hasClass('dropdown-header') && $lisVisible.eq(index + 1).data('optgroup') !== $this.data('optgroup')) { + $this.addClass('hidden'); + } else { + $foundDiv = null; + } + }); + if ($foundDiv) $foundDiv.addClass('hidden'); + + $searchBase.not('.hidden').first().addClass('active'); + that.$menuInner.scrollTop(0); + } + } + }); + }, + + _searchStyle: function () { + var styles = { + begins: 'ibegins', + startsWith: 'ibegins' + }; + + return styles[this.options.liveSearchStyle] || 'icontains'; + }, + + val: function (value) { + if (typeof value !== 'undefined') { + this.$element.val(value); + this.render(); + + return this.$element; + } else { + return this.$element.val(); + } + }, + + changeAll: function (status) { + if (!this.multiple) return; + if (typeof status === 'undefined') status = true; + + this.findLis(); + + var $options = this.$element.find('option'), + $lisVisible = this.$lis.not('.divider, .dropdown-header, .disabled, .hidden'), + lisVisLen = $lisVisible.length, + selectedOptions = []; + + if (status) { + if ($lisVisible.filter('.selected').length === $lisVisible.length) return; + } else { + if ($lisVisible.filter('.selected').length === 0) return; + } + + $lisVisible.toggleClass('selected', status); + + for (var i = 0; i < lisVisLen; i++) { + var origIndex = $lisVisible[i].getAttribute('data-original-index'); + selectedOptions[selectedOptions.length] = $options.eq(origIndex)[0]; + } + + $(selectedOptions).prop('selected', status); + + this.render(false); + + this.togglePlaceholder(); + + this.$element + .triggerNative('change'); + }, + + selectAll: function () { + return this.changeAll(true); + }, + + deselectAll: function () { + return this.changeAll(false); + }, + + toggle: function (e) { + e = e || window.event; + + if (e) e.stopPropagation(); + + this.$button.trigger('click'); + }, + + keydown: function (e) { + var $this = $(this), + $parent = $this.is('input') ? $this.parent().parent() : $this.parent(), + $items, + that = $parent.data('this'), + index, + prevIndex, + isActive, + selector = ':not(.disabled, .hidden, .dropdown-header, .divider)', + keyCodeMap = { + 32: ' ', + 48: '0', + 49: '1', + 50: '2', + 51: '3', + 52: '4', + 53: '5', + 54: '6', + 55: '7', + 56: '8', + 57: '9', + 59: ';', + 65: 'a', + 66: 'b', + 67: 'c', + 68: 'd', + 69: 'e', + 70: 'f', + 71: 'g', + 72: 'h', + 73: 'i', + 74: 'j', + 75: 'k', + 76: 'l', + 77: 'm', + 78: 'n', + 79: 'o', + 80: 'p', + 81: 'q', + 82: 'r', + 83: 's', + 84: 't', + 85: 'u', + 86: 'v', + 87: 'w', + 88: 'x', + 89: 'y', + 90: 'z', + 96: '0', + 97: '1', + 98: '2', + 99: '3', + 100: '4', + 101: '5', + 102: '6', + 103: '7', + 104: '8', + 105: '9' + }; + + + isActive = that.$newElement.hasClass('open'); + + if (!isActive && (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 65 && e.keyCode <= 90)) { + if (!that.options.container) { + that.setSize(); + that.$menu.parent().addClass('open'); + isActive = true; + } else { + that.$button.trigger('click'); + } + that.$searchbox.focus(); + return; + } + + if (that.options.liveSearch) { + if (/(^9$|27)/.test(e.keyCode.toString(10)) && isActive) { + e.preventDefault(); + e.stopPropagation(); + that.$menuInner.click(); + that.$button.focus(); + } + } + + if (/(38|40)/.test(e.keyCode.toString(10))) { + $items = that.$lis.filter(selector); + if (!$items.length) return; + + if (!that.options.liveSearch) { + index = $items.index($items.find('a').filter(':focus').parent()); + } else { + index = $items.index($items.filter('.active')); + } + + prevIndex = that.$menuInner.data('prevIndex'); + + if (e.keyCode == 38) { + if ((that.options.liveSearch || index == prevIndex) && index != -1) index--; + if (index < 0) index += $items.length; + } else if (e.keyCode == 40) { + if (that.options.liveSearch || index == prevIndex) index++; + index = index % $items.length; + } + + that.$menuInner.data('prevIndex', index); + + if (!that.options.liveSearch) { + $items.eq(index).children('a').focus(); + } else { + e.preventDefault(); + if (!$this.hasClass('dropdown-toggle')) { + $items.removeClass('active').eq(index).addClass('active').children('a').focus(); + $this.focus(); + } + } + + } else if (!$this.is('input')) { + var keyIndex = [], + count, + prevKey; + + $items = that.$lis.filter(selector); + $items.each(function (i) { + if ($.trim($(this).children('a').text().toLowerCase()).substring(0, 1) == keyCodeMap[e.keyCode]) { + keyIndex.push(i); + } + }); + + count = $(document).data('keycount'); + count++; + $(document).data('keycount', count); + + prevKey = $.trim($(':focus').text().toLowerCase()).substring(0, 1); + + if (prevKey != keyCodeMap[e.keyCode]) { + count = 1; + $(document).data('keycount', count); + } else if (count >= keyIndex.length) { + $(document).data('keycount', 0); + if (count > keyIndex.length) count = 1; + } + + $items.eq(keyIndex[count - 1]).children('a').focus(); + } + + // Select focused option if "Enter", "Spacebar" or "Tab" (when selectOnTab is true) are pressed inside the menu. + if ((/(13|32)/.test(e.keyCode.toString(10)) || (/(^9$)/.test(e.keyCode.toString(10)) && that.options.selectOnTab)) && isActive) { + if (!/(32)/.test(e.keyCode.toString(10))) e.preventDefault(); + if (!that.options.liveSearch) { + var elem = $(':focus'); + elem.click(); + // Bring back focus for multiselects + elem.focus(); + // Prevent screen from scrolling if the user hit the spacebar + e.preventDefault(); + // Fixes spacebar selection of dropdown items in FF & IE + $(document).data('spaceSelect', true); + } else if (!/(32)/.test(e.keyCode.toString(10))) { + that.$menuInner.find('.active a').click(); + $this.focus(); + } + $(document).data('keycount', 0); + } + + if ((/(^9$|27)/.test(e.keyCode.toString(10)) && isActive && (that.multiple || that.options.liveSearch)) || (/(27)/.test(e.keyCode.toString(10)) && !isActive)) { + that.$menu.parent().removeClass('open'); + if (that.options.container) that.$newElement.removeClass('open'); + that.$button.focus(); + } + }, + + mobile: function () { + this.$element.addClass('mobile-device'); + }, + + refresh: function () { + this.$lis = null; + this.liObj = {}; + this.reloadLi(); + this.render(); + this.checkDisabled(); + this.liHeight(true); + this.setStyle(); + this.setWidth(); + if (this.$lis) this.$searchbox.trigger('propertychange'); + + this.$element.trigger('refreshed.bs.select'); + }, + + hide: function () { + this.$newElement.hide(); + }, + + show: function () { + this.$newElement.show(); + }, + + remove: function () { + this.$newElement.remove(); + this.$element.remove(); + }, + + destroy: function () { + this.$newElement.before(this.$element).remove(); + + if (this.$bsContainer) { + this.$bsContainer.remove(); + } else { + this.$menu.remove(); + } + + this.$element + .off('.bs.select') + .removeData('selectpicker') + .removeClass('bs-select-hidden selectpicker'); + } + }; + + // SELECTPICKER PLUGIN DEFINITION + // ============================== + function Plugin(option) { + // get the args of the outer function.. + var args = arguments; + // The arguments of the function are explicitly re-defined from the argument list, because the shift causes them + // to get lost/corrupted in android 2.3 and IE9 #715 #775 + var _option = option; + + [].shift.apply(args); + + var value; + var chain = this.each(function () { + var $this = $(this); + if ($this.is('select')) { + var data = $this.data('selectpicker'), + options = typeof _option == 'object' && _option; + + if (!data) { + var config = $.extend({}, Selectpicker.DEFAULTS, $.fn.selectpicker.defaults || {}, $this.data(), options); + config.template = $.extend({}, Selectpicker.DEFAULTS.template, ($.fn.selectpicker.defaults ? $.fn.selectpicker.defaults.template : {}), $this.data().template, options.template); + $this.data('selectpicker', (data = new Selectpicker(this, config))); + } else if (options) { + for (var i in options) { + if (options.hasOwnProperty(i)) { + data.options[i] = options[i]; + } + } + } + + if (typeof _option == 'string') { + if (data[_option] instanceof Function) { + value = data[_option].apply(data, args); + } else { + value = data.options[_option]; + } + } + } + }); + + if (typeof value !== 'undefined') { + //noinspection JSUnusedAssignment + return value; + } else { + return chain; + } + } + + var old = $.fn.selectpicker; + $.fn.selectpicker = Plugin; + $.fn.selectpicker.Constructor = Selectpicker; + + // SELECTPICKER NO CONFLICT + // ======================== + $.fn.selectpicker.noConflict = function () { + $.fn.selectpicker = old; + return this; + }; + + $(document) + .data('keycount', 0) + .on('keydown.bs.select', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="listbox"], .bs-searchbox input', Selectpicker.prototype.keydown) + .on('focusin.modal', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="listbox"], .bs-searchbox input', function (e) { + e.stopPropagation(); + }); + + // SELECTPICKER DATA-API + // ===================== + $(window).on('load.bs.select.data-api', function () { + $('.selectpicker').each(function () { + var $selectpicker = $(this); + Plugin.call($selectpicker, $selectpicker.data()); + }) + }); +})(jQuery); })); @@ -59631,24 +59631,24 @@ function merge_text_nodes( jsonml ) { })); $.fn.markdown.defaults.iconlibrary = 'fa'; -/*! - * jQuery Validation Plugin v1.17.0 - * - * https://jqueryvalidation.org/ - * - * Copyright (c) 2017 Jörn Zaefferer - * Released under the MIT license - */ -(function( factory ) { - if ( typeof define === "function" && define.amd ) { - define( ["jquery"], factory ); - } else if (typeof module === "object" && module.exports) { - module.exports = factory( require( "jquery" ) ); - } else { - factory( jQuery ); - } -}(function( $ ) { - +/*! + * jQuery Validation Plugin v1.17.0 + * + * https://jqueryvalidation.org/ + * + * Copyright (c) 2017 Jörn Zaefferer + * Released under the MIT license + */ +(function( factory ) { + if ( typeof define === "function" && define.amd ) { + define( ["jquery"], factory ); + } else if (typeof module === "object" && module.exports) { + module.exports = factory( require( "jquery" ) ); + } else { + factory( jQuery ); + } +}(function( $ ) { + $.extend( $.fn, { // https://jqueryvalidation.org/validate/ @@ -61194,7 +61194,7 @@ $.extend( $.validator, { } } ); - + // Ajax mode: abort // usage: $.ajax({ mode: "abort"[, port: "uniqueport"]}); // if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort() @@ -61230,26 +61230,26 @@ if ( $.ajaxPrefilter ) { return ajax.apply( this, arguments ); }; } -return $; +return $; })); -/*! - * jQuery Validation Plugin v1.17.0 - * - * https://jqueryvalidation.org/ - * - * Copyright (c) 2017 Jörn Zaefferer - * Released under the MIT license - */ -(function( factory ) { - if ( typeof define === "function" && define.amd ) { - define( ["jquery", "./jquery.validate"], factory ); - } else if (typeof module === "object" && module.exports) { - module.exports = factory( require( "jquery" ) ); - } else { - factory( jQuery ); - } -}(function( $ ) { - +/*! + * jQuery Validation Plugin v1.17.0 + * + * https://jqueryvalidation.org/ + * + * Copyright (c) 2017 Jörn Zaefferer + * Released under the MIT license + */ +(function( factory ) { + if ( typeof define === "function" && define.amd ) { + define( ["jquery", "./jquery.validate"], factory ); + } else if (typeof module === "object" && module.exports) { + module.exports = factory( require( "jquery" ) ); + } else { + factory( jQuery ); + } +}(function( $ ) { + ( function() { function stripHtml( value ) { @@ -61276,7 +61276,7 @@ return $; }, $.validator.format( "Please enter between {0} and {1} words." ) ); }() ); - + // Accept a value from a file input based on a required mimetype $.validator.addMethod( "accept", function( value, element, param ) { @@ -61318,11 +61318,11 @@ $.validator.addMethod( "accept", function( value, element, param ) { // browser does not support element.files and the FileList feature return true; }, $.validator.format( "Please enter a value with a valid mimetype." ) ); - + $.validator.addMethod( "alphanumeric", function( value, element ) { return this.optional( element ) || /^\w+$/i.test( value ); }, "Letters, numbers, and underscores only please" ); - + /* * Dutch bank account numbers (not 'giro' numbers) have 9 digits * and pass the '11 check'. @@ -61349,13 +61349,13 @@ $.validator.addMethod( "bankaccountNL", function( value, element ) { } return sum % 11 === 0; }, "Please specify a valid bank account number" ); - + $.validator.addMethod( "bankorgiroaccountNL", function( value, element ) { return this.optional( element ) || ( $.validator.methods.bankaccountNL.call( this, value, element ) ) || ( $.validator.methods.giroaccountNL.call( this, value, element ) ); }, "Please specify a valid bank or giro account number" ); - + /** * BIC is the business identifier code (ISO 9362). This BIC check is not a guarantee for authenticity. * @@ -61374,7 +61374,7 @@ $.validator.addMethod( "bankorgiroaccountNL", function( value, element ) { $.validator.addMethod( "bic", function( value, element ) { return this.optional( element ) || /^([A-Z]{6}[A-Z2-9][A-NP-Z1-9])(X{3}|[A-WY-Z0-9][A-Z0-9]{2})?$/.test( value.toUpperCase() ); }, "Please specify a valid BIC code" ); - + /* * Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities * Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal @@ -61489,7 +61489,7 @@ $.validator.addMethod( "cifES", function( value, element ) { return control === control_digit || control === control_letter; }, "Please specify a valid CIF number." ); - + /* * Brazillian CPF number (Cadastrado de Pessoas Físicas) is the equivalent of a Brazilian tax registration number. * CPF numbers have 11 digits in total: 9 numbers followed by 2 check numbers that are being used for validation. @@ -61550,7 +61550,7 @@ $.validator.addMethod( "cpfBR", function( value ) { return false; }, "Please specify a valid CPF number" ); - + // https://jqueryvalidation.org/creditcard-method/ // based on https://en.wikipedia.org/wiki/Luhn_algorithm $.validator.addMethod( "creditcard", function( value, element ) { @@ -61591,7 +61591,7 @@ $.validator.addMethod( "creditcard", function( value, element ) { return ( nCheck % 10 ) === 0; }, "Please enter a valid credit card number." ); - + /* NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator * Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0 * Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings) @@ -61661,7 +61661,7 @@ $.validator.addMethod( "creditcardtypes", function( value, element, param ) { } return false; }, "Please enter a valid credit card number." ); - + /** * Validates currencies with any given symbols by @jameslouiz * Symbols can be optional or required. Symbols required by default @@ -61703,11 +61703,11 @@ $.validator.addMethod( "currency", function( value, element, param ) { return this.optional( element ) || regex.test( value ); }, "Please specify a valid currency" ); - + $.validator.addMethod( "dateFA", function( value, element ) { return this.optional( element ) || /^[1-4]\d{3}\/((0?[1-6]\/((3[0-1])|([1-2][0-9])|(0?[1-9])))|((1[0-2]|(0?[7-9]))\/(30|([1-2][0-9])|(0?[1-9]))))$/.test( value ); }, $.validator.messages.date ); - + /** * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy. * @@ -61747,24 +61747,24 @@ $.validator.addMethod( "dateITA", function( value, element ) { } return this.optional( element ) || check; }, $.validator.messages.date ); - + $.validator.addMethod( "dateNL", function( value, element ) { return this.optional( element ) || /^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test( value ); }, $.validator.messages.date ); - + // Older "accept" file extension method. Old docs: http://docs.jquery.com/Plugins/Validation/Methods/accept $.validator.addMethod( "extension", function( value, element, param ) { param = typeof param === "string" ? param.replace( /,/g, "|" ) : "png|jpe?g|gif"; return this.optional( element ) || value.match( new RegExp( "\\.(" + param + ")$", "i" ) ); }, $.validator.format( "Please enter a value with a valid extension." ) ); - + /** * Dutch giro account numbers (not bank numbers) have max 7 digits */ $.validator.addMethod( "giroaccountNL", function( value, element ) { return this.optional( element ) || /^[0-9]{1,7}$/.test( value ); }, "Please specify a valid giro account number" ); - + /** * IBAN is the international bank account number. * It has a country - specific format, that is checked here too @@ -61901,31 +61901,31 @@ $.validator.addMethod( "iban", function( value, element ) { } return cRest === 1; }, "Please specify a valid IBAN" ); - + $.validator.addMethod( "integer", function( value, element ) { return this.optional( element ) || /^-?\d+$/.test( value ); }, "A positive or negative non-decimal number please" ); - + $.validator.addMethod( "ipv4", function( value, element ) { return this.optional( element ) || /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i.test( value ); }, "Please enter a valid IP v4 address." ); - + $.validator.addMethod( "ipv6", function( value, element ) { return this.optional( element ) || /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test( value ); }, "Please enter a valid IP v6 address." ); - + $.validator.addMethod( "lettersonly", function( value, element ) { return this.optional( element ) || /^[a-z]+$/i.test( value ); }, "Letters only please" ); - + $.validator.addMethod( "letterswithbasicpunc", function( value, element ) { return this.optional( element ) || /^[a-z\-.,()'"\s]+$/i.test( value ); }, "Letters or punctuation only please" ); - + $.validator.addMethod( "mobileNL", function( value, element ) { return this.optional( element ) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test( value ); }, "Please specify a valid mobile number" ); - + /* For UK phone functions, do the following server side processing: * Compare original input with this RegEx pattern: * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$ @@ -61939,11 +61939,11 @@ $.validator.addMethod( "mobileUK", function( phone_number, element ) { return this.optional( element ) || phone_number.length > 9 && phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/ ); }, "Please specify a valid mobile number" ); - + $.validator.addMethod( "netmask", function( value, element ) { return this.optional( element ) || /^(254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(254|252|248|240|224|192|128|0)/i.test( value ); }, "Please enter a valid netmask." ); - + /* * The NIE (Número de Identificación de Extranjero) is a Spanish tax identification number assigned by the Spanish * authorities to any foreigner. @@ -61983,7 +61983,7 @@ $.validator.addMethod( "nieES", function( value, element ) { return validChars.charAt( parseInt( number, 10 ) % 23 ) === letter; }, "Please specify a valid NIE number." ); - + /* * The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals */ @@ -62014,7 +62014,7 @@ $.validator.addMethod( "nifES", function( value, element ) { return false; }, "Please specify a valid NIF number." ); - + /* * Numer identyfikacji podatkowej ( NIP ) is the way tax identification used in Poland for companies */ @@ -62037,15 +62037,15 @@ $.validator.addMethod( "nipPL", function( value ) { return ( intControlNr === parseInt( value[ 9 ], 10 ) ); }, "Please specify a valid NIP number." ); - + $.validator.addMethod( "notEqualTo", function( value, element, param ) { return this.optional( element ) || !$.validator.methods.equalTo.call( this, value, element, param ); }, "Please enter a different value, values must not be the same." ); - + $.validator.addMethod( "nowhitespace", function( value, element ) { return this.optional( element ) || /^\S+$/i.test( value ); }, "No white space please" ); - + /** * Return true if the field value matches the given format RegExp * @@ -62068,14 +62068,14 @@ $.validator.addMethod( "pattern", function( value, element, param ) { } return param.test( value ); }, "Invalid format." ); - + /** * Dutch phone numbers have 10 digits (or 11 and start with +31). */ $.validator.addMethod( "phoneNL", function( value, element ) { return this.optional( element ) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test( value ); }, "Please specify a valid phone number." ); - + /* For UK phone functions, do the following server side processing: * Compare original input with this RegEx pattern: * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$ @@ -62091,7 +62091,7 @@ $.validator.addMethod( "phonesUK", function( phone_number, element ) { return this.optional( element ) || phone_number.length > 9 && phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/ ); }, "Please specify a valid uk phone number" ); - + /* For UK phone functions, do the following server side processing: * Compare original input with this RegEx pattern: * ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$ @@ -62105,7 +62105,7 @@ $.validator.addMethod( "phoneUK", function( phone_number, element ) { return this.optional( element ) || phone_number.length > 9 && phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/ ); }, "Please specify a valid phone number" ); - + /** * Matches US phone number format * @@ -62127,7 +62127,7 @@ $.validator.addMethod( "phoneUS", function( phone_number, element ) { return this.optional( element ) || phone_number.length > 9 && phone_number.match( /^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/ ); }, "Please specify a valid phone number" ); - + /* * Valida CEPs do brasileiros: * @@ -62139,7 +62139,7 @@ $.validator.addMethod( "phoneUS", function( phone_number, element ) { $.validator.addMethod( "postalcodeBR", function( cep_value, element ) { return this.optional( element ) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value ); }, "Informe um CEP válido." ); - + /** * Matches a valid Canadian Postal Code * @@ -62156,21 +62156,21 @@ $.validator.addMethod( "postalcodeBR", function( cep_value, element ) { $.validator.addMethod( "postalCodeCA", function( value, element ) { return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] *\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i.test( value ); }, "Please specify a valid postal code" ); - + /* Matches Italian postcode (CAP) */ $.validator.addMethod( "postalcodeIT", function( value, element ) { return this.optional( element ) || /^\d{5}$/.test( value ); }, "Please specify a valid postal code" ); - + $.validator.addMethod( "postalcodeNL", function( value, element ) { return this.optional( element ) || /^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test( value ); }, "Please specify a valid postal code" ); - + // Matches UK postcode. Does not match to UK Channel Islands that have their own postcodes (non standard UK) $.validator.addMethod( "postcodeUK", function( value, element ) { return this.optional( element ) || /^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/i.test( value ); }, "Please specify a valid UK postcode" ); - + /* * Lets you say "at least X inputs that match selector Y must be filled." * @@ -62208,7 +62208,7 @@ $.validator.addMethod( "require_from_group", function( value, element, options ) } return isValid; }, $.validator.format( "Please fill at least {0} of these fields." ) ); - + /* * Lets you say "either at least X inputs that match selector Y must be filled, * OR they must all be skipped (left blank)." @@ -62252,7 +62252,7 @@ $.validator.addMethod( "skip_or_fill_minimum", function( value, element, options } return isValid; }, $.validator.format( "Please either skip these fields or fill at least {0} of them." ) ); - + /* Validates US States and/or Territories by @jdforsythe * Can be case insensitive or require capitalization - default is case insensitive * Can include US Territories or not - default does not @@ -62307,25 +62307,25 @@ $.validator.addMethod( "stateUS", function( value, element, options ) { regex = caseSensitive ? new RegExp( regex ) : new RegExp( regex, "i" ); return this.optional( element ) || regex.test( value ); }, "Please specify a valid state" ); - + // TODO check if value starts with <, otherwise don't try stripping anything $.validator.addMethod( "strippedminlength", function( value, element, param ) { return $( value ).text().length >= param; }, $.validator.format( "Please enter at least {0} characters" ) ); - + $.validator.addMethod( "time", function( value, element ) { return this.optional( element ) || /^([01]\d|2[0-3]|[0-9])(:[0-5]\d){1,2}$/.test( value ); }, "Please enter a valid time, between 00:00 and 23:59" ); - + $.validator.addMethod( "time12h", function( value, element ) { return this.optional( element ) || /^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test( value ); }, "Please enter a valid time in 12-hour am/pm format" ); - + // Same as url, but TLD is optional $.validator.addMethod( "url2", function( value, element ) { return this.optional( element ) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test( value ); }, $.validator.messages.url ); - + /** * Return true, if the value is a valid vehicle identification number (VIN). * @@ -62380,82 +62380,82 @@ $.validator.addMethod( "vinUS", function( v ) { } return false; }, "The specified vehicle identification number (VIN) is invalid." ); - + $.validator.addMethod( "zipcodeUS", function( value, element ) { return this.optional( element ) || /^\d{5}(-\d{4})?$/.test( value ); }, "The specified US ZIP Code is invalid" ); - + $.validator.addMethod( "ziprange", function( value, element ) { return this.optional( element ) || /^90[2-5]\d\{2\}-\d{4}$/.test( value ); }, "Your ZIP-code must be in the range 902xx-xxxx to 905xx-xxxx" ); -return $; +return $; })); -jQuery.validator.setDefaults({ - errorElement: 'div', //default input error message container - errorClass: 'form-control-feedback', // default input error message class - focusInvalid: false, // do not focus the last invalid input - ignore: "", // validate all fields including form hidden input - - errorPlacement: function(error, element) { // render error placement for each input type - var group = $(element).closest('.m-form__group-sub').length > 0 ? $(element).closest('.m-form__group-sub') : $(element).closest('.m-form__group'); - var help = group.find('.m-form__help'); - - if (group.find('.form-control-feedback').length !== 0) { - return; - } - - if (help.length > 0) { - help.before(error); - } else { - if ($(element).closest('.input-group').length > 0) { - $(element).closest('.input-group').after(error); - } else { - if ($(element).is(':checkbox')) { - $(element).closest('.m-checkbox').find('>span').after(error); - } else { - $(element).after(error); - } - } - } - }, - - highlight: function(element) { // hightlight error inputs - var group = $(element).closest('.m-form__group-sub').length > 0 ? $(element).closest('.m-form__group-sub') : $(element).closest('.m-form__group'); - - console.log('add' + group.attr('class')); - - group.addClass('has-danger'); // set error class to the control groupx - }, - - unhighlight: function(element) { // revert the change done by hightlight - var group = $(element).closest('.m-form__group-sub').length > 0 ? $(element).closest('.m-form__group-sub') : $(element).closest('.m-form__group'); - - group.removeClass('has-danger'); // set error class to the control group - }, - - success: function(label, element) { - var group = $(label).closest('.m-form__group-sub').length > 0 ? $(label).closest('.m-form__group-sub') : $(label).closest('.m-form__group'); - - //group.addClass('has-success').removeClass('has-danger'); // set success class and hide error class - group.removeClass('has-danger'); // hide error class - group.find('.form-control-feedback').remove(); - } +jQuery.validator.setDefaults({ + errorElement: 'div', //default input error message container + errorClass: 'form-control-feedback', // default input error message class + focusInvalid: false, // do not focus the last invalid input + ignore: "", // validate all fields including form hidden input + + errorPlacement: function(error, element) { // render error placement for each input type + var group = $(element).closest('.m-form__group-sub').length > 0 ? $(element).closest('.m-form__group-sub') : $(element).closest('.m-form__group'); + var help = group.find('.m-form__help'); + + if (group.find('.form-control-feedback').length !== 0) { + return; + } + + if (help.length > 0) { + help.before(error); + } else { + if ($(element).closest('.input-group').length > 0) { + $(element).closest('.input-group').after(error); + } else { + if ($(element).is(':checkbox')) { + $(element).closest('.m-checkbox').find('>span').after(error); + } else { + $(element).after(error); + } + } + } + }, + + highlight: function(element) { // hightlight error inputs + var group = $(element).closest('.m-form__group-sub').length > 0 ? $(element).closest('.m-form__group-sub') : $(element).closest('.m-form__group'); + + console.log('add' + group.attr('class')); + + group.addClass('has-danger'); // set error class to the control groupx + }, + + unhighlight: function(element) { // revert the change done by hightlight + var group = $(element).closest('.m-form__group-sub').length > 0 ? $(element).closest('.m-form__group-sub') : $(element).closest('.m-form__group'); + + group.removeClass('has-danger'); // set error class to the control group + }, + + success: function(label, element) { + var group = $(label).closest('.m-form__group-sub').length > 0 ? $(label).closest('.m-form__group-sub') : $(label).closest('.m-form__group'); + + //group.addClass('has-success').removeClass('has-danger'); // set success class and hide error class + group.removeClass('has-danger'); // hide error class + group.find('.form-control-feedback').remove(); + } }); !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){function b(b,d,e){var d={content:{message:"object"==typeof d?d.message:d,title:d.title?d.title:"",icon:d.icon?d.icon:"",url:d.url?d.url:"#",target:d.target?d.target:"-"}};e=a.extend(!0,{},d,e),this.settings=a.extend(!0,{},c,e),this._defaults=c,"-"==this.settings.content.target&&(this.settings.content.target=this.settings.url_target),this.animations={start:"webkitAnimationStart oanimationstart MSAnimationStart animationstart",end:"webkitAnimationEnd oanimationend MSAnimationEnd animationend"},"number"==typeof this.settings.offset&&(this.settings.offset={x:this.settings.offset,y:this.settings.offset}),this.init()}var c={element:"body",position:null,type:"info",allow_dismiss:!0,newest_on_top:!1,showProgressbar:!1,placement:{from:"top",align:"right"},offset:20,spacing:10,z_index:1031,delay:5e3,timer:1e3,url_target:"_blank",mouse_over:null,animate:{enter:"animated fadeInDown",exit:"animated fadeOutUp"},onShow:null,onShown:null,onClose:null,onClosed:null,icon_type:"class",template:''};String.format=function(){for(var a=arguments[0],b=1;b .progress-bar').removeClass("progress-bar-"+a.settings.type),a.settings.type=d[b],this.$ele.addClass("alert-"+d[b]).find('[data-notify="progressbar"] > .progress-bar').addClass("progress-bar-"+d[b]);break;case"icon":var e=this.$ele.find('[data-notify="icon"]');"class"==a.settings.icon_type.toLowerCase()?e.removeClass(a.settings.content.icon).addClass(d[b]):(e.is("img")||e.find("img"),e.attr("src",d[b]));break;case"progress":var f=a.settings.delay-a.settings.delay*(d[b]/100);this.$ele.data("notify-delay",f),this.$ele.find('[data-notify="progressbar"] > div').attr("aria-valuenow",d[b]).css("width",d[b]+"%");break;case"url":this.$ele.find('[data-notify="url"]').attr("href",d[b]);break;case"target":this.$ele.find('[data-notify="url"]').attr("target",d[b]);break;default:this.$ele.find('[data-notify="'+b+'"]').html(d[b])}var g=this.$ele.outerHeight()+parseInt(a.settings.spacing)+parseInt(a.settings.offset.y);a.reposition(g)},close:function(){a.close()}}},buildNotify:function(){var b=this.settings.content;this.$ele=a(String.format(this.settings.template,this.settings.type,b.title,b.message,b.url,b.target)),this.$ele.attr("data-notify-position",this.settings.placement.from+"-"+this.settings.placement.align),this.settings.allow_dismiss||this.$ele.find('[data-notify="dismiss"]').css("display","none"),(this.settings.delay<=0&&!this.settings.showProgressbar||!this.settings.showProgressbar)&&this.$ele.find('[data-notify="progressbar"]').remove()},setIcon:function(){"class"==this.settings.icon_type.toLowerCase()?this.$ele.find('[data-notify="icon"]').addClass(this.settings.content.icon):this.$ele.find('[data-notify="icon"]').is("img")?this.$ele.find('[data-notify="icon"]').attr("src",this.settings.content.icon):this.$ele.find('[data-notify="icon"]').append('Notify Icon')},styleDismiss:function(){this.$ele.find('[data-notify="dismiss"]').css({position:"absolute",right:"10px",top:"5px",zIndex:this.settings.z_index+2})},styleURL:function(){this.$ele.find('[data-notify="url"]').css({backgroundImage:"url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)",height:"100%",left:"0px",position:"absolute",top:"0px",width:"100%",zIndex:this.settings.z_index+1})},placement:function(){var b=this,c=this.settings.offset.y,d={display:"inline-block",margin:"0px auto",position:this.settings.position?this.settings.position:"body"===this.settings.element?"fixed":"absolute",transition:"all .5s ease-in-out",zIndex:this.settings.z_index},e=!1,f=this.settings;switch(a('[data-notify-position="'+this.settings.placement.from+"-"+this.settings.placement.align+'"]:not([data-closing="true"])').each(function(){return c=Math.max(c,parseInt(a(this).css(f.placement.from))+parseInt(a(this).outerHeight())+parseInt(f.spacing))}),1==this.settings.newest_on_top&&(c=this.settings.offset.y),d[this.settings.placement.from]=c+"px",this.settings.placement.align){case"left":case"right":d[this.settings.placement.align]=this.settings.offset.x+"px";break;case"center":d.left=0,d.right=0}this.$ele.css(d).addClass(this.settings.animate.enter),a.each(Array("webkit","moz","o","ms",""),function(a,c){b.$ele[0].style[c+"AnimationIterationCount"]=1}),a(this.settings.element).append(this.$ele),1==this.settings.newest_on_top&&(c=parseInt(c)+parseInt(this.settings.spacing)+this.$ele.outerHeight(),this.reposition(c)),a.isFunction(b.settings.onShow)&&b.settings.onShow.call(this.$ele),this.$ele.one(this.animations.start,function(a){e=!0}).one(this.animations.end,function(c){a.isFunction(b.settings.onShown)&&b.settings.onShown.call(this)}),setTimeout(function(){e||a.isFunction(b.settings.onShown)&&b.settings.onShown.call(this)},600)},bind:function(){var b=this;if(this.$ele.find('[data-notify="dismiss"]').on("click",function(){b.close()}),this.$ele.mouseover(function(b){a(this).data("data-hover","true")}).mouseout(function(b){a(this).data("data-hover","false")}),this.$ele.data("data-hover","false"),this.settings.delay>0){b.$ele.data("notify-delay",b.settings.delay);var c=setInterval(function(){var a=parseInt(b.$ele.data("notify-delay"))-b.settings.timer;if("false"===b.$ele.data("data-hover")&&"pause"==b.settings.mouse_over||"pause"!=b.settings.mouse_over){var d=(b.settings.delay-a)/b.settings.delay*100;b.$ele.data("notify-delay",a),b.$ele.find('[data-notify="progressbar"] > div').attr("aria-valuenow",d).css("width",d+"%")}a<=-b.settings.timer&&(clearInterval(c),b.close())},b.settings.timer)}},close:function(){var b=this,c=parseInt(this.$ele.css(this.settings.placement.from)),d=!1;this.$ele.data("closing","true").addClass(this.settings.animate.exit),b.reposition(c),a.isFunction(b.settings.onClose)&&b.settings.onClose.call(this.$ele),this.$ele.one(this.animations.start,function(a){d=!0}).one(this.animations.end,function(c){a(this).remove(),a.isFunction(b.settings.onClosed)&&b.settings.onClosed.call(this)}),setTimeout(function(){d||(b.$ele.remove(),b.settings.onClosed&&b.settings.onClosed(b.$ele))},600)},reposition:function(b){var c=this,d='[data-notify-position="'+this.settings.placement.from+"-"+this.settings.placement.align+'"]:not([data-closing="true"])',e=this.$ele.nextAll(d);1==this.settings.newest_on_top&&(e=this.$ele.prevAll(d)),e.each(function(){a(this).css(c.settings.placement.from,b),b=parseInt(b)+parseInt(c.settings.spacing)+a(this).outerHeight()})}}),a.notify=function(a,c){var d=new b(this,a,c);return d.notify},a.notifyDefaults=function(b){return c=a.extend(!0,{},c,b)},a.notifyClose=function(b){"undefined"==typeof b||"all"==b?a("[data-notify]").find('[data-notify="dismiss"]').trigger("click"):a('[data-notify-position="'+b+'"]').find('[data-notify="dismiss"]').trigger("click")}}); -//== Set defaults - -$.notifyDefaults({ - template: '' + - '' +//== Set defaults + +$.notifyDefaults({ + template: '' + + '' }); !function(e){e(["jquery"],function(e){return function(){function t(e,t,n){return g({type:O.error,iconClass:m().iconClasses.error,message:e,optionsOverride:n,title:t})}function n(t,n){return t||(t=m()),v=e("#"+t.containerId),v.length?v:(n&&(v=d(t)),v)}function o(e,t,n){return g({type:O.info,iconClass:m().iconClasses.info,message:e,optionsOverride:n,title:t})}function s(e){C=e}function i(e,t,n){return g({type:O.success,iconClass:m().iconClasses.success,message:e,optionsOverride:n,title:t})}function a(e,t,n){return g({type:O.warning,iconClass:m().iconClasses.warning,message:e,optionsOverride:n,title:t})}function r(e,t){var o=m();v||n(o),u(e,o,t)||l(o)}function c(t){var o=m();return v||n(o),t&&0===e(":focus",t).length?void h(t):void(v.children().length&&v.remove())}function l(t){for(var n=v.children(),o=n.length-1;o>=0;o--)u(e(n[o]),t)}function u(t,n,o){var s=!(!o||!o.force)&&o.force;return!(!t||!s&&0!==e(":focus",t).length)&&(t[n.hideMethod]({duration:n.hideDuration,easing:n.hideEasing,complete:function(){h(t)}}),!0)}function d(t){return v=e("
    ").attr("id",t.containerId).addClass(t.positionClass),v.appendTo(e(t.target)),v}function p(){return{tapToDismiss:!0,toastClass:"toast",containerId:"toast-container",debug:!1,showMethod:"fadeIn",showDuration:300,showEasing:"swing",onShown:void 0,hideMethod:"fadeOut",hideDuration:1e3,hideEasing:"swing",onHidden:void 0,closeMethod:!1,closeDuration:!1,closeEasing:!1,closeOnHover:!0,extendedTimeOut:1e3,iconClasses:{error:"toast-error",info:"toast-info",success:"toast-success",warning:"toast-warning"},iconClass:"toast-info",positionClass:"toast-top-right",timeOut:5e3,titleClass:"toast-title",messageClass:"toast-message",escapeHtml:!1,target:"body",closeHtml:'',closeClass:"toast-close-button",newestOnTop:!0,preventDuplicates:!1,progressBar:!1,progressClass:"toast-progress",rtl:!1}}function f(e){C&&C(e)}function g(t){function o(e){return null==e&&(e=""),e.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(//g,">")}function s(){c(),u(),d(),p(),g(),C(),l(),i()}function i(){var e="";switch(t.iconClass){case"toast-success":case"toast-info":e="polite";break;default:e="assertive"}I.attr("aria-live",e)}function a(){E.closeOnHover&&I.hover(H,D),!E.onclick&&E.tapToDismiss&&I.click(b),E.closeButton&&j&&j.click(function(e){e.stopPropagation?e.stopPropagation():void 0!==e.cancelBubble&&e.cancelBubble!==!0&&(e.cancelBubble=!0),E.onCloseClick&&E.onCloseClick(e),b(!0)}),E.onclick&&I.click(function(e){E.onclick(e),b()})}function r(){I.hide(),I[E.showMethod]({duration:E.showDuration,easing:E.showEasing,complete:E.onShown}),E.timeOut>0&&(k=setTimeout(b,E.timeOut),F.maxHideTime=parseFloat(E.timeOut),F.hideEta=(new Date).getTime()+F.maxHideTime,E.progressBar&&(F.intervalId=setInterval(x,10)))}function c(){t.iconClass&&I.addClass(E.toastClass).addClass(y)}function l(){E.newestOnTop?v.prepend(I):v.append(I)}function u(){if(t.title){var e=t.title;E.escapeHtml&&(e=o(t.title)),M.append(e).addClass(E.titleClass),I.append(M)}}function d(){if(t.message){var e=t.message;E.escapeHtml&&(e=o(t.message)),B.append(e).addClass(E.messageClass),I.append(B)}}function p(){E.closeButton&&(j.addClass(E.closeClass).attr("role","button"),I.prepend(j))}function g(){E.progressBar&&(q.addClass(E.progressClass),I.prepend(q))}function C(){E.rtl&&I.addClass("rtl")}function O(e,t){if(e.preventDuplicates){if(t.message===w)return!0;w=t.message}return!1}function b(t){var n=t&&E.closeMethod!==!1?E.closeMethod:E.hideMethod,o=t&&E.closeDuration!==!1?E.closeDuration:E.hideDuration,s=t&&E.closeEasing!==!1?E.closeEasing:E.hideEasing;if(!e(":focus",I).length||t)return clearTimeout(F.intervalId),I[n]({duration:o,easing:s,complete:function(){h(I),clearTimeout(k),E.onHidden&&"hidden"!==P.state&&E.onHidden(),P.state="hidden",P.endTime=new Date,f(P)}})}function D(){(E.timeOut>0||E.extendedTimeOut>0)&&(k=setTimeout(b,E.extendedTimeOut),F.maxHideTime=parseFloat(E.extendedTimeOut),F.hideEta=(new Date).getTime()+F.maxHideTime)}function H(){clearTimeout(k),F.hideEta=0,I.stop(!0,!0)[E.showMethod]({duration:E.showDuration,easing:E.showEasing})}function x(){var e=(F.hideEta-(new Date).getTime())/F.maxHideTime*100;q.width(e+"%")}var E=m(),y=t.iconClass||E.iconClass;if("undefined"!=typeof t.optionsOverride&&(E=e.extend(E,t.optionsOverride),y=t.optionsOverride.iconClass||y),!O(E,t)){T++,v=n(E,!0);var k=null,I=e("
    "),M=e("
    "),B=e("
    "),q=e("
    "),j=e(E.closeHtml),F={intervalId:null,hideEta:null,maxHideTime:null},P={toastId:T,state:"visible",startTime:new Date,options:E,map:t};return s(),r(),a(),f(P),E.debug&&console&&console.log(P),I}}function m(){return e.extend({},p(),b.options)}function h(e){v||(v=n()),e.is(":visible")||(e.remove(),e=null,0===v.children().length&&(v.remove(),w=void 0))}var v,C,w,T=0,O={error:"error",info:"info",success:"success",warning:"warning"},b={clear:r,remove:c,error:t,getContainer:n,info:o,options:{},subscribe:s,success:i,version:"2.1.4",warning:a};return b}()})}("function"==typeof define&&define.amd?define:function(e,t){"undefined"!=typeof module&&module.exports?module.exports=t(require("jquery")):window.toastr=t(window.jQuery)}); //# sourceMappingURL=toastr.js.map @@ -87131,158 +87131,158 @@ Converter.prototype.getValues = function(space) { module.exports = convert; },{"3":3}],5:[function(require,module,exports){ -'use strict' - -module.exports = { - "aliceblue": [240, 248, 255], - "antiquewhite": [250, 235, 215], - "aqua": [0, 255, 255], - "aquamarine": [127, 255, 212], - "azure": [240, 255, 255], - "beige": [245, 245, 220], - "bisque": [255, 228, 196], - "black": [0, 0, 0], - "blanchedalmond": [255, 235, 205], - "blue": [0, 0, 255], - "blueviolet": [138, 43, 226], - "brown": [165, 42, 42], - "burlywood": [222, 184, 135], - "cadetblue": [95, 158, 160], - "chartreuse": [127, 255, 0], - "chocolate": [210, 105, 30], - "coral": [255, 127, 80], - "cornflowerblue": [100, 149, 237], - "cornsilk": [255, 248, 220], - "crimson": [220, 20, 60], - "cyan": [0, 255, 255], - "darkblue": [0, 0, 139], - "darkcyan": [0, 139, 139], - "darkgoldenrod": [184, 134, 11], - "darkgray": [169, 169, 169], - "darkgreen": [0, 100, 0], - "darkgrey": [169, 169, 169], - "darkkhaki": [189, 183, 107], - "darkmagenta": [139, 0, 139], - "darkolivegreen": [85, 107, 47], - "darkorange": [255, 140, 0], - "darkorchid": [153, 50, 204], - "darkred": [139, 0, 0], - "darksalmon": [233, 150, 122], - "darkseagreen": [143, 188, 143], - "darkslateblue": [72, 61, 139], - "darkslategray": [47, 79, 79], - "darkslategrey": [47, 79, 79], - "darkturquoise": [0, 206, 209], - "darkviolet": [148, 0, 211], - "deeppink": [255, 20, 147], - "deepskyblue": [0, 191, 255], - "dimgray": [105, 105, 105], - "dimgrey": [105, 105, 105], - "dodgerblue": [30, 144, 255], - "firebrick": [178, 34, 34], - "floralwhite": [255, 250, 240], - "forestgreen": [34, 139, 34], - "fuchsia": [255, 0, 255], - "gainsboro": [220, 220, 220], - "ghostwhite": [248, 248, 255], - "gold": [255, 215, 0], - "goldenrod": [218, 165, 32], - "gray": [128, 128, 128], - "green": [0, 128, 0], - "greenyellow": [173, 255, 47], - "grey": [128, 128, 128], - "honeydew": [240, 255, 240], - "hotpink": [255, 105, 180], - "indianred": [205, 92, 92], - "indigo": [75, 0, 130], - "ivory": [255, 255, 240], - "khaki": [240, 230, 140], - "lavender": [230, 230, 250], - "lavenderblush": [255, 240, 245], - "lawngreen": [124, 252, 0], - "lemonchiffon": [255, 250, 205], - "lightblue": [173, 216, 230], - "lightcoral": [240, 128, 128], - "lightcyan": [224, 255, 255], - "lightgoldenrodyellow": [250, 250, 210], - "lightgray": [211, 211, 211], - "lightgreen": [144, 238, 144], - "lightgrey": [211, 211, 211], - "lightpink": [255, 182, 193], - "lightsalmon": [255, 160, 122], - "lightseagreen": [32, 178, 170], - "lightskyblue": [135, 206, 250], - "lightslategray": [119, 136, 153], - "lightslategrey": [119, 136, 153], - "lightsteelblue": [176, 196, 222], - "lightyellow": [255, 255, 224], - "lime": [0, 255, 0], - "limegreen": [50, 205, 50], - "linen": [250, 240, 230], - "magenta": [255, 0, 255], - "maroon": [128, 0, 0], - "mediumaquamarine": [102, 205, 170], - "mediumblue": [0, 0, 205], - "mediumorchid": [186, 85, 211], - "mediumpurple": [147, 112, 219], - "mediumseagreen": [60, 179, 113], - "mediumslateblue": [123, 104, 238], - "mediumspringgreen": [0, 250, 154], - "mediumturquoise": [72, 209, 204], - "mediumvioletred": [199, 21, 133], - "midnightblue": [25, 25, 112], - "mintcream": [245, 255, 250], - "mistyrose": [255, 228, 225], - "moccasin": [255, 228, 181], - "navajowhite": [255, 222, 173], - "navy": [0, 0, 128], - "oldlace": [253, 245, 230], - "olive": [128, 128, 0], - "olivedrab": [107, 142, 35], - "orange": [255, 165, 0], - "orangered": [255, 69, 0], - "orchid": [218, 112, 214], - "palegoldenrod": [238, 232, 170], - "palegreen": [152, 251, 152], - "paleturquoise": [175, 238, 238], - "palevioletred": [219, 112, 147], - "papayawhip": [255, 239, 213], - "peachpuff": [255, 218, 185], - "peru": [205, 133, 63], - "pink": [255, 192, 203], - "plum": [221, 160, 221], - "powderblue": [176, 224, 230], - "purple": [128, 0, 128], - "rebeccapurple": [102, 51, 153], - "red": [255, 0, 0], - "rosybrown": [188, 143, 143], - "royalblue": [65, 105, 225], - "saddlebrown": [139, 69, 19], - "salmon": [250, 128, 114], - "sandybrown": [244, 164, 96], - "seagreen": [46, 139, 87], - "seashell": [255, 245, 238], - "sienna": [160, 82, 45], - "silver": [192, 192, 192], - "skyblue": [135, 206, 235], - "slateblue": [106, 90, 205], - "slategray": [112, 128, 144], - "slategrey": [112, 128, 144], - "snow": [255, 250, 250], - "springgreen": [0, 255, 127], - "steelblue": [70, 130, 180], - "tan": [210, 180, 140], - "teal": [0, 128, 128], - "thistle": [216, 191, 216], - "tomato": [255, 99, 71], - "turquoise": [64, 224, 208], - "violet": [238, 130, 238], - "wheat": [245, 222, 179], - "white": [255, 255, 255], - "whitesmoke": [245, 245, 245], - "yellow": [255, 255, 0], - "yellowgreen": [154, 205, 50] -}; +'use strict' + +module.exports = { + "aliceblue": [240, 248, 255], + "antiquewhite": [250, 235, 215], + "aqua": [0, 255, 255], + "aquamarine": [127, 255, 212], + "azure": [240, 255, 255], + "beige": [245, 245, 220], + "bisque": [255, 228, 196], + "black": [0, 0, 0], + "blanchedalmond": [255, 235, 205], + "blue": [0, 0, 255], + "blueviolet": [138, 43, 226], + "brown": [165, 42, 42], + "burlywood": [222, 184, 135], + "cadetblue": [95, 158, 160], + "chartreuse": [127, 255, 0], + "chocolate": [210, 105, 30], + "coral": [255, 127, 80], + "cornflowerblue": [100, 149, 237], + "cornsilk": [255, 248, 220], + "crimson": [220, 20, 60], + "cyan": [0, 255, 255], + "darkblue": [0, 0, 139], + "darkcyan": [0, 139, 139], + "darkgoldenrod": [184, 134, 11], + "darkgray": [169, 169, 169], + "darkgreen": [0, 100, 0], + "darkgrey": [169, 169, 169], + "darkkhaki": [189, 183, 107], + "darkmagenta": [139, 0, 139], + "darkolivegreen": [85, 107, 47], + "darkorange": [255, 140, 0], + "darkorchid": [153, 50, 204], + "darkred": [139, 0, 0], + "darksalmon": [233, 150, 122], + "darkseagreen": [143, 188, 143], + "darkslateblue": [72, 61, 139], + "darkslategray": [47, 79, 79], + "darkslategrey": [47, 79, 79], + "darkturquoise": [0, 206, 209], + "darkviolet": [148, 0, 211], + "deeppink": [255, 20, 147], + "deepskyblue": [0, 191, 255], + "dimgray": [105, 105, 105], + "dimgrey": [105, 105, 105], + "dodgerblue": [30, 144, 255], + "firebrick": [178, 34, 34], + "floralwhite": [255, 250, 240], + "forestgreen": [34, 139, 34], + "fuchsia": [255, 0, 255], + "gainsboro": [220, 220, 220], + "ghostwhite": [248, 248, 255], + "gold": [255, 215, 0], + "goldenrod": [218, 165, 32], + "gray": [128, 128, 128], + "green": [0, 128, 0], + "greenyellow": [173, 255, 47], + "grey": [128, 128, 128], + "honeydew": [240, 255, 240], + "hotpink": [255, 105, 180], + "indianred": [205, 92, 92], + "indigo": [75, 0, 130], + "ivory": [255, 255, 240], + "khaki": [240, 230, 140], + "lavender": [230, 230, 250], + "lavenderblush": [255, 240, 245], + "lawngreen": [124, 252, 0], + "lemonchiffon": [255, 250, 205], + "lightblue": [173, 216, 230], + "lightcoral": [240, 128, 128], + "lightcyan": [224, 255, 255], + "lightgoldenrodyellow": [250, 250, 210], + "lightgray": [211, 211, 211], + "lightgreen": [144, 238, 144], + "lightgrey": [211, 211, 211], + "lightpink": [255, 182, 193], + "lightsalmon": [255, 160, 122], + "lightseagreen": [32, 178, 170], + "lightskyblue": [135, 206, 250], + "lightslategray": [119, 136, 153], + "lightslategrey": [119, 136, 153], + "lightsteelblue": [176, 196, 222], + "lightyellow": [255, 255, 224], + "lime": [0, 255, 0], + "limegreen": [50, 205, 50], + "linen": [250, 240, 230], + "magenta": [255, 0, 255], + "maroon": [128, 0, 0], + "mediumaquamarine": [102, 205, 170], + "mediumblue": [0, 0, 205], + "mediumorchid": [186, 85, 211], + "mediumpurple": [147, 112, 219], + "mediumseagreen": [60, 179, 113], + "mediumslateblue": [123, 104, 238], + "mediumspringgreen": [0, 250, 154], + "mediumturquoise": [72, 209, 204], + "mediumvioletred": [199, 21, 133], + "midnightblue": [25, 25, 112], + "mintcream": [245, 255, 250], + "mistyrose": [255, 228, 225], + "moccasin": [255, 228, 181], + "navajowhite": [255, 222, 173], + "navy": [0, 0, 128], + "oldlace": [253, 245, 230], + "olive": [128, 128, 0], + "olivedrab": [107, 142, 35], + "orange": [255, 165, 0], + "orangered": [255, 69, 0], + "orchid": [218, 112, 214], + "palegoldenrod": [238, 232, 170], + "palegreen": [152, 251, 152], + "paleturquoise": [175, 238, 238], + "palevioletred": [219, 112, 147], + "papayawhip": [255, 239, 213], + "peachpuff": [255, 218, 185], + "peru": [205, 133, 63], + "pink": [255, 192, 203], + "plum": [221, 160, 221], + "powderblue": [176, 224, 230], + "purple": [128, 0, 128], + "rebeccapurple": [102, 51, 153], + "red": [255, 0, 0], + "rosybrown": [188, 143, 143], + "royalblue": [65, 105, 225], + "saddlebrown": [139, 69, 19], + "salmon": [250, 128, 114], + "sandybrown": [244, 164, 96], + "seagreen": [46, 139, 87], + "seashell": [255, 245, 238], + "sienna": [160, 82, 45], + "silver": [192, 192, 192], + "skyblue": [135, 206, 235], + "slateblue": [106, 90, 205], + "slategray": [112, 128, 144], + "slategrey": [112, 128, 144], + "snow": [255, 250, 250], + "springgreen": [0, 255, 127], + "steelblue": [70, 130, 180], + "tan": [210, 180, 140], + "teal": [0, 128, 128], + "thistle": [216, 191, 216], + "tomato": [255, 99, 71], + "turquoise": [64, 224, 208], + "violet": [238, 130, 238], + "wheat": [245, 222, 179], + "white": [255, 255, 255], + "whitesmoke": [245, 245, 245], + "yellow": [255, 255, 0], + "yellowgreen": [154, 205, 50] +}; },{}],6:[function(require,module,exports){ //! moment.js @@ -104226,138 +104226,138 @@ module.exports = function(Chart) { },{"25":25,"45":45,"6":6}]},{},[7])(7) }); -Chart.elements.Rectangle.prototype.draw = function() { - var ctx = this._chart.ctx; - var vm = this._view; - var left, right, top, bottom, signX, signY, borderSkipped, radius; - var borderWidth = vm.borderWidth; - - // Set Radius Here - // If radius is large enough to cause drawing errors a max radius is imposed - var cornerRadius = this._chart.options.barRadius ? this._chart.options.barRadius : 0; - - if (!vm.horizontal) { - // bar - left = vm.x - vm.width / 2; - right = vm.x + vm.width / 2; - - if (vm.y > 2 * cornerRadius) { - top = vm.y - cornerRadius; - } else { - top = vm.y; - } - - bottom = vm.base; - signX = 1; - signY = bottom > top? 1: -1; - borderSkipped = vm.borderSkipped || 'bottom'; - //console.log(vm.base + '-' + vm.y); - } else { - // horizontal bar - left = vm.base; - right = vm.x; - top = vm.y - vm.height / 2; - bottom = vm.y + vm.height / 2; - signX = right > left? 1: -1; - signY = 1; - borderSkipped = vm.borderSkipped || 'left'; - } - - // Canvas doesn't allow us to stroke inside the width so we can - // adjust the sizes to fit if we're setting a stroke on the line - if (borderWidth) { - // borderWidth shold be less than bar width and bar height. - var barSize = Math.min(Math.abs(left - right), Math.abs(top - bottom)); - borderWidth = borderWidth > barSize? barSize: borderWidth; - var halfStroke = borderWidth / 2; - // Adjust borderWidth when bar top position is near vm.base(zero). - var borderLeft = left + (borderSkipped !== 'left'? halfStroke * signX: 0); - var borderRight = right + (borderSkipped !== 'right'? -halfStroke * signX: 0); - var borderTop = top + (borderSkipped !== 'top'? halfStroke * signY: 0); - var borderBottom = bottom + (borderSkipped !== 'bottom'? -halfStroke * signY: 0); - // not become a vertical line? - if (borderLeft !== borderRight) { - top = borderTop; - bottom = borderBottom; - } - // not become a horizontal line? - if (borderTop !== borderBottom) { - left = borderLeft; - right = borderRight; - } - } - - ctx.beginPath(); - ctx.fillStyle = vm.backgroundColor; - ctx.strokeStyle = vm.borderColor; - ctx.lineWidth = borderWidth; - - // Corner points, from bottom-left to bottom-right clockwise - // | 1 2 | - // | 0 3 | - var corners = [ - [left, bottom], - [left, top], - [right, top], - [right, bottom] - ]; - - // Find first (starting) corner with fallback to 'bottom' - var borders = ['bottom', 'left', 'top', 'right']; - var startCorner = borders.indexOf(borderSkipped, 0); - if (startCorner === -1) { - startCorner = 0; - } - - function cornerAt(index) { - return corners[(startCorner + index) % 4]; - } - - // Draw rectangle from 'startCorner' - var corner = cornerAt(0); - ctx.moveTo(corner[0], corner[1]); - - for (var i = 1; i < 4; i++) { - corner = cornerAt(i); - nextCornerId = i+1; - if(nextCornerId == 4){ - nextCornerId = 0 - } - - nextCorner = cornerAt(nextCornerId); - - width = corners[2][0] - corners[1][0]; - height = corners[0][1] - corners[1][1]; - x = corners[1][0]; - y = corners[1][1]; - - var radius = cornerRadius; - - // Fix radius being too large - if(radius > height/2){ - radius = height/2; - }if(radius > width/2){ - radius = width/2; - } - - ctx.moveTo(x + radius, y); - ctx.lineTo(x + width - radius, y); - ctx.quadraticCurveTo(x + width, y, x + width, y + radius); - ctx.lineTo(x + width, y + height - radius); - ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height); - ctx.lineTo(x + radius, y + height); - ctx.quadraticCurveTo(x, y + height, x, y + height - radius); - ctx.lineTo(x, y + radius); - ctx.quadraticCurveTo(x, y, x + radius, y); - } - - ctx.fill(); - if (borderWidth) { - ctx.stroke(); - } +Chart.elements.Rectangle.prototype.draw = function() { + var ctx = this._chart.ctx; + var vm = this._view; + var left, right, top, bottom, signX, signY, borderSkipped, radius; + var borderWidth = vm.borderWidth; + + // Set Radius Here + // If radius is large enough to cause drawing errors a max radius is imposed + var cornerRadius = this._chart.options.barRadius ? this._chart.options.barRadius : 0; + + if (!vm.horizontal) { + // bar + left = vm.x - vm.width / 2; + right = vm.x + vm.width / 2; + + if (vm.y > 2 * cornerRadius) { + top = vm.y - cornerRadius; + } else { + top = vm.y; + } + + bottom = vm.base; + signX = 1; + signY = bottom > top? 1: -1; + borderSkipped = vm.borderSkipped || 'bottom'; + //console.log(vm.base + '-' + vm.y); + } else { + // horizontal bar + left = vm.base; + right = vm.x; + top = vm.y - vm.height / 2; + bottom = vm.y + vm.height / 2; + signX = right > left? 1: -1; + signY = 1; + borderSkipped = vm.borderSkipped || 'left'; + } + + // Canvas doesn't allow us to stroke inside the width so we can + // adjust the sizes to fit if we're setting a stroke on the line + if (borderWidth) { + // borderWidth shold be less than bar width and bar height. + var barSize = Math.min(Math.abs(left - right), Math.abs(top - bottom)); + borderWidth = borderWidth > barSize? barSize: borderWidth; + var halfStroke = borderWidth / 2; + // Adjust borderWidth when bar top position is near vm.base(zero). + var borderLeft = left + (borderSkipped !== 'left'? halfStroke * signX: 0); + var borderRight = right + (borderSkipped !== 'right'? -halfStroke * signX: 0); + var borderTop = top + (borderSkipped !== 'top'? halfStroke * signY: 0); + var borderBottom = bottom + (borderSkipped !== 'bottom'? -halfStroke * signY: 0); + // not become a vertical line? + if (borderLeft !== borderRight) { + top = borderTop; + bottom = borderBottom; + } + // not become a horizontal line? + if (borderTop !== borderBottom) { + left = borderLeft; + right = borderRight; + } + } + + ctx.beginPath(); + ctx.fillStyle = vm.backgroundColor; + ctx.strokeStyle = vm.borderColor; + ctx.lineWidth = borderWidth; + + // Corner points, from bottom-left to bottom-right clockwise + // | 1 2 | + // | 0 3 | + var corners = [ + [left, bottom], + [left, top], + [right, top], + [right, bottom] + ]; + + // Find first (starting) corner with fallback to 'bottom' + var borders = ['bottom', 'left', 'top', 'right']; + var startCorner = borders.indexOf(borderSkipped, 0); + if (startCorner === -1) { + startCorner = 0; + } + + function cornerAt(index) { + return corners[(startCorner + index) % 4]; + } + + // Draw rectangle from 'startCorner' + var corner = cornerAt(0); + ctx.moveTo(corner[0], corner[1]); + + for (var i = 1; i < 4; i++) { + corner = cornerAt(i); + nextCornerId = i+1; + if(nextCornerId == 4){ + nextCornerId = 0 + } + + nextCorner = cornerAt(nextCornerId); + + width = corners[2][0] - corners[1][0]; + height = corners[0][1] - corners[1][1]; + x = corners[1][0]; + y = corners[1][1]; + + var radius = cornerRadius; + + // Fix radius being too large + if(radius > height/2){ + radius = height/2; + }if(radius > width/2){ + radius = width/2; + } + + ctx.moveTo(x + radius, y); + ctx.lineTo(x + width - radius, y); + ctx.quadraticCurveTo(x + width, y, x + width, y + radius); + ctx.lineTo(x + width, y + height - radius); + ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height); + ctx.lineTo(x + radius, y + height); + ctx.quadraticCurveTo(x, y + height, x, y + height - radius); + ctx.lineTo(x, y + radius); + ctx.quadraticCurveTo(x, y, x + radius, y); + } + + ctx.fill(); + if (borderWidth) { + ctx.stroke(); + } }; !function(a){"use strict";a.sessionTimeout=function(b){function c(){n||(a.ajax({type:i.ajaxType,url:i.keepAliveUrl,data:i.ajaxData}),n=!0,setTimeout(function(){n=!1},i.keepAliveInterval))}function d(){clearTimeout(g),(i.countdownMessage||i.countdownBar)&&f("session",!0),"function"==typeof i.onStart&&i.onStart(i),i.keepAlive&&c(),g=setTimeout(function(){"function"!=typeof i.onWarn?a("#session-timeout-dialog").modal("show"):i.onWarn(i),e()},i.warnAfter)}function e(){clearTimeout(g),a("#session-timeout-dialog").hasClass("in")||!i.countdownMessage&&!i.countdownBar||f("dialog",!0),g=setTimeout(function(){"function"!=typeof i.onRedir?window.location=i.redirUrl:i.onRedir(i)},i.redirAfter-i.warnAfter)}function f(b,c){clearTimeout(j.timer),"dialog"===b&&c?j.timeLeft=Math.floor((i.redirAfter-i.warnAfter)/1e3):"session"===b&&c&&(j.timeLeft=Math.floor(i.redirAfter/1e3)),i.countdownBar&&"dialog"===b?j.percentLeft=Math.floor(j.timeLeft/((i.redirAfter-i.warnAfter)/1e3)*100):i.countdownBar&&"session"===b&&(j.percentLeft=Math.floor(j.timeLeft/(i.redirAfter/1e3)*100));var d=a(".countdown-holder"),e=j.timeLeft>=0?j.timeLeft:0;if(i.countdownSmart){var g=Math.floor(e/60),h=e%60,k=g>0?g+"m":"";k.length>0&&(k+=" "),k+=h+"s",d.text(k)}else d.text(e+"s");i.countdownBar&&a(".countdown-bar").css("width",j.percentLeft+"%"),j.timeLeft=j.timeLeft-1,j.timer=setTimeout(function(){f(b)},1e3)}var g,h={title:"Your Session is About to Expire!",message:"Your session is about to expire.",logoutButton:"Logout",keepAliveButton:"Stay Connected",keepAliveUrl:"/keep-alive",ajaxType:"POST",ajaxData:"",redirUrl:"/timed-out",logoutUrl:"/log-out",warnAfter:9e5,redirAfter:12e5,keepAliveInterval:5e3,keepAlive:!0,ignoreUserActivity:!1,onStart:!1,onWarn:!1,onRedir:!1,countdownMessage:!1,countdownBar:!1,countdownSmart:!1},i=h,j={};if(b&&(i=a.extend(h,b)),i.warnAfter>=i.redirAfter)return console.error('Bootstrap-session-timeout plugin is miss-configured. Option "redirAfter" must be equal or greater than "warnAfter".'),!1;if("function"!=typeof i.onWarn){var k=i.countdownMessage?"

    "+i.countdownMessage.replace(/{timer}/g,'')+"

    ":"",l=i.countdownBar?'
    ':"";a("body").append('"),a("#session-timeout-dialog-logout").on("click",function(){window.location=i.logoutUrl}),a("#session-timeout-dialog").on("hide.bs.modal",function(){d()})}if(!i.ignoreUserActivity){var m=[-1,-1];a(document).on("keyup mouseup mousemove touchend touchmove",function(b){if("mousemove"===b.type){if(b.clientX===m[0]&&b.clientY===m[1])return;m[0]=b.clientX,m[1]=b.clientY}d(),a("#session-timeout-dialog").length>0&&a("#session-timeout-dialog").data("bs.modal")&&a("#session-timeout-dialog").data("bs.modal").isShown&&(a("#session-timeout-dialog").modal("hide"),a("body").removeClass("modal-open"),a("div.modal-backdrop").remove())})}var n=!1;d()}}(jQuery); -/*! Idle Timer v1.1.0 2016-03-21 | https://github.com/thorst/jquery-idletimer | (c) 2016 Paul Irish | Licensed MIT */ +/*! Idle Timer v1.1.0 2016-03-21 | https://github.com/thorst/jquery-idletimer | (c) 2016 Paul Irish | Licensed MIT */ !function(a){a.idleTimer=function(b,c){var d;"object"==typeof b?(d=b,b=null):"number"==typeof b&&(d={timeout:b},b=null),c=c||document,d=a.extend({idle:!1,timeout:3e4,events:"mousemove keydown wheel DOMMouseScroll mousewheel mousedown touchstart touchmove MSPointerDown MSPointerMove"},d);var e=a(c),f=e.data("idleTimerObj")||{},g=function(b){var d=a.data(c,"idleTimerObj")||{};d.idle=!d.idle,d.olddate=+new Date;var e=a.Event((d.idle?"idle":"active")+".idleTimer");a(c).trigger(e,[c,a.extend({},d),b])},h=function(b){var d=a.data(c,"idleTimerObj")||{};if(("storage"!==b.type||b.originalEvent.key===d.timerSyncId)&&null==d.remaining){if("mousemove"===b.type){if(b.pageX===d.pageX&&b.pageY===d.pageY)return;if("undefined"==typeof b.pageX&&"undefined"==typeof b.pageY)return;var e=+new Date-d.olddate;if(200>e)return}clearTimeout(d.tId),d.idle&&g(b),d.lastActive=+new Date,d.pageX=b.pageX,d.pageY=b.pageY,"storage"!==b.type&&d.timerSyncId&&"undefined"!=typeof localStorage&&localStorage.setItem(d.timerSyncId,d.lastActive),d.tId=setTimeout(g,d.timeout)}},i=function(){var b=a.data(c,"idleTimerObj")||{};b.idle=b.idleBackup,b.olddate=+new Date,b.lastActive=b.olddate,b.remaining=null,clearTimeout(b.tId),b.idle||(b.tId=setTimeout(g,b.timeout))},j=function(){var b=a.data(c,"idleTimerObj")||{};null==b.remaining&&(b.remaining=b.timeout-(+new Date-b.olddate),clearTimeout(b.tId))},k=function(){var b=a.data(c,"idleTimerObj")||{};null!=b.remaining&&(b.idle||(b.tId=setTimeout(g,b.remaining)),b.remaining=null)},l=function(){var b=a.data(c,"idleTimerObj")||{};clearTimeout(b.tId),e.removeData("idleTimerObj"),e.off("._idleTimer")},m=function(){var b=a.data(c,"idleTimerObj")||{};if(b.idle)return 0;if(null!=b.remaining)return b.remaining;var d=b.timeout-(+new Date-b.lastActive);return 0>d&&(d=0),d};if(null===b&&"undefined"!=typeof f.idle)return i(),e;if(null===b);else{if(null!==b&&"undefined"==typeof f.idle)return!1;if("destroy"===b)return l(),e;if("pause"===b)return j(),e;if("resume"===b)return k(),e;if("reset"===b)return i(),e;if("getRemainingTime"===b)return m();if("getElapsedTime"===b)return+new Date-f.olddate;if("getLastActiveTime"===b)return f.lastActive;if("isIdle"===b)return f.idle}return e.on(a.trim((d.events+" ").split(" ").join("._idleTimer ")),function(a){h(a)}),d.timerSyncId&&a(window).bind("storage",h),f=a.extend({},{olddate:+new Date,lastActive:+new Date,idle:d.idle,idleBackup:d.idle,timeout:d.timeout,remaining:null,timerSyncId:d.timerSyncId,tId:null,pageX:null,pageY:null}),f.idle||(f.tId=setTimeout(g,f.timeout)),a.data(c,"idleTimerObj",f),e},a.fn.idleTimer=function(b){return this[0]?a.idleTimer(b,this[0]):this}}(jQuery); /*! Waypoints - 4.0.1 @@ -105039,13 +105039,13 @@ Object.prototype.toString.call(a))throw new TypeError("You must pass an array to typeof d.then?d.then(b,c):b(d)})};e.resolve=function(a){return a&&"object"===typeof a&&a.constructor===this?a:new this(function(b){b(a)})};e.reject=function(a){return new this(function(b,c){c(a)})}})("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this); !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Sweetalert2=t()}(this,function(){"use strict";var e={title:"",titleText:"",text:"",html:"",type:null,toast:!1,customClass:"",target:"body",backdrop:!0,animation:!0,allowOutsideClick:!0,allowEscapeKey:!0,allowEnterKey:!0,showConfirmButton:!0,showCancelButton:!1,preConfirm:null,confirmButtonText:"OK",confirmButtonAriaLabel:"",confirmButtonColor:"#3085d6",confirmButtonClass:null,cancelButtonText:"Cancel",cancelButtonAriaLabel:"",cancelButtonColor:"#aaa",cancelButtonClass:null,buttonsStyling:!0,reverseButtons:!1,focusConfirm:!0,focusCancel:!1,showCloseButton:!1,closeButtonAriaLabel:"Close this dialog",showLoaderOnConfirm:!1,imageUrl:null,imageWidth:null,imageHeight:null,imageAlt:"",imageClass:null,timer:null,width:500,padding:20,background:"#fff",input:null,inputPlaceholder:"",inputValue:"",inputOptions:{},inputAutoTrim:!0,inputClass:null,inputAttributes:{},inputValidator:null,grow:!1,position:"center",progressSteps:[],currentProgressStep:null,progressStepsDistance:"40px",onBeforeOpen:null,onOpen:null,onClose:null,useRejections:!1,expectRejections:!1},t=["useRejections","expectRejections"],n=function(e){var t={};for(var n in e)t[e[n]]="swal2-"+e[n];return t},o=n(["container","shown","iosfix","popup","modal","no-backdrop","toast","toast-shown","overlay","fade","show","hide","noanimation","close","title","content","contentwrapper","buttonswrapper","confirm","cancel","icon","image","input","has-input","file","range","select","radio","checkbox","textarea","inputerror","validationerror","progresssteps","activeprogressstep","progresscircle","progressline","loading","styled","top","top-left","top-right","center","center-left","center-right","bottom","bottom-left","bottom-right","grow-row","grow-column","grow-fullscreen"]),r=n(["success","warning","info","question","error"]),i="SweetAlert2:",a=function(e,t){(e=String(e).replace(/[^0-9a-f]/gi,"")).length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),t=t||0;for(var n="#",o=0;o<3;o++){var r=parseInt(e.substr(2*o,2),16);n+=("00"+(r=Math.round(Math.min(Math.max(0,r+r*t),255)).toString(16))).substr(r.length)}return n},s=function(e){console.warn(i+" "+e)},l=function(e){console.error(i+" "+e)},u=[],c=function(e){-1===u.indexOf(e)&&(u.push(e),s(e))},d={previousActiveElement:null,previousBodyPadding:null},p=function(){return"undefined"==typeof window||"undefined"==typeof document},f=function(e){var t=b();t&&(t.parentNode.removeChild(t),V(document.body,o["no-backdrop"]),V(document.body,o["has-input"]),V(document.body,o["toast-shown"]));{if(!p()){var n=document.createElement("div");n.className=o.container,n.innerHTML=m;("string"==typeof e.target?document.querySelector(e.target):e.target).appendChild(n);var r=h(),i=O(r,o.input),a=O(r,o.file),s=r.querySelector("."+o.range+" input"),u=r.querySelector("."+o.range+" output"),c=O(r,o.select),d=r.querySelector("."+o.checkbox+" input"),f=O(r,o.textarea);r.setAttribute("aria-live",e.toast?"polite":"assertive");var g=function(){Y.isVisible()&&Y.resetValidationError()};return i.oninput=g,a.onchange=g,c.onchange=g,d.onchange=g,f.oninput=g,s.oninput=function(){g(),u.value=s.value},s.onchange=function(){g(),s.previousSibling.value=s.value},r}l("SweetAlert2 requires document to initialize")}},m=('\n \n').replace(/(^|\n)\s*/g,""),b=function(){return document.body.querySelector("."+o.container)},h=function(){return b()?b().querySelector("."+o.popup):null},g=function(e){return b()?b().querySelector("."+e):null},v=function(){return g(o.title)},y=function(){return g(o.content)},w=function(){return g(o.image)},C=function(){return g(o.progresssteps)},x=function(){return g(o.validationerror)},k=function(){return g(o.confirm)},S=function(){return g(o.cancel)},A=function(){return g(o.buttonswrapper)},B=function(){return g(o.close)},P=function(){var e=Array.from(h().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')).sort(function(e,t){return e=parseInt(e.getAttribute("tabindex")),t=parseInt(t.getAttribute("tabindex")),e>t?1:e"),t.backdrop||q(document.body,o["no-backdrop"]),t.text||t.html){if("object"===R(t.html))if(x.innerHTML="",0 in t.html)for(var O=0;O in t.html;O++)x.appendChild(t.html[O].cloneNode(!0));else x.appendChild(t.html.cloneNode(!0));else t.html?x.innerHTML=t.html:t.text&&(x.textContent=t.text);j(x)}else N(x);if(t.position in o&&q(m,o[t.position]),t.grow&&"string"==typeof t.grow){var M="grow-"+t.grow;M in o&&q(m,o[M])}t.showCloseButton?(T.setAttribute("aria-label",t.closeButtonAriaLabel),j(T)):N(T),n.className=o.popup,t.toast?(q(document.body,o["toast-shown"]),q(n,o.toast)):q(n,o.modal),t.customClass&&q(n,t.customClass);var H=C(),I=parseInt(null===t.currentProgressStep?Y.getQueueStep():t.currentProgressStep,10);t.progressSteps.length?(j(H),function(e){for(;e.firstChild;)e.removeChild(e.firstChild)}(H),I>=t.progressSteps.length&&s("Invalid currentProgressStep parameter, it should be less than progressSteps.length (currentProgressStep like JS arrays starts from 0)"),t.progressSteps.forEach(function(e,n){var r=document.createElement("li");if(q(r,o.progresscircle),r.innerHTML=e,n===I&&q(r,o.activeprogressstep),H.appendChild(r),n!==t.progressSteps.length-1){var i=document.createElement("li");q(i,o.progressline),i.style.width=t.progressStepsDistance,H.appendChild(i)}})):N(H);for(var D=h().querySelectorAll("."+o.icon),U=0;Uwindow.innerHeight&&(d.previousBodyPadding=document.body.style.paddingRight,document.body.style.paddingRight=function(){if("ontouchstart"in window||navigator.msMaxTouchPoints)return 0;var e=document.createElement("div");e.style.width="50px",e.style.height="50px",e.style.overflow="scroll",document.body.appendChild(e);var t=e.offsetWidth-e.clientWidth;return document.body.removeChild(e),t}()+"px")},Q=function(){if(/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream&&!L(document.body,o.iosfix)){var e=document.body.scrollTop;document.body.style.top=-1*e+"px",q(document.body,o.iosfix)}},Y=function e(){for(var t=arguments.length,n=Array(t),r=0;rsend(); } + public function getBatteries(Request $req) + { + if (!$this->isGranted('customer.add') && !$this->isGranted('customer.update')) { + $exception = $this->createAccessDeniedException('No access.'); + throw $exception; + } + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(BatteryManufacturer::class)->find($req->request->get('id')); + + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // build batteries array + $batteries = []; + + foreach ($row->getBatteries() as $battery) { + $batteries[] = [ + 'id' => $battery->getID(), + 'mfg_name' => $battery->getManufacturer()->getName(), + 'model_name' => $battery->getModel()->getName(), + 'size_name' => $battery->getSize()->getName(), + 'prod_code' => $battery->getProductCode() + ]; + } + + // response + return $this->json([ + 'data' => $batteries + ]); + } + // check if datatable filter is present and append to query protected function setQueryFilters($datatable, &$query) { if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { diff --git a/src/Controller/CustomerController.php b/src/Controller/CustomerController.php index 7a496ae0..57b1971e 100644 --- a/src/Controller/CustomerController.php +++ b/src/Controller/CustomerController.php @@ -5,8 +5,11 @@ namespace App\Controller; use App\Ramcar\BaseController; use App\Entity\Customer; use App\Entity\CustomerVehicle; +use App\Entity\MobileNumber; use App\Entity\Vehicle; use App\Entity\VehicleManufacturer; +use App\Entity\Battery; +use App\Entity\BatteryManufacturer; use Doctrine\ORM\Query; use Symfony\Component\HttpFoundation\Request; @@ -16,6 +19,8 @@ use Symfony\Component\Validator\Validator\ValidatorInterface; use App\Menu\Generator as MenuGenerator; use App\Access\Generator as ACLGenerator; +use DateTime; + class CustomerController extends BaseController { protected $acl_gen; @@ -134,8 +139,11 @@ class CustomerController extends BaseController $em = $this->getDoctrine()->getManager(); // get parent associations + $params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll(); $params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll(); + $params['years'] = $this->generateYearOptions(); + // response return $this->render('customer/form.html.twig', $params); } @@ -149,25 +157,121 @@ class CustomerController extends BaseController $row = new Customer(); // set and save values - $row->setName($req->request->get('name')); + $row->setFirstName($req->request->get('first_name')) + ->setLastName($req->request->get('last_name')) + ->setConfirmed(false); + + // initialize error lists + $error_array = []; + $nerror_array = []; + $verror_array = []; + + // custom validation for mobile numbers + $numbers = json_decode($req->request->get('mobile_numbers')); + + if (!empty($numbers)) { + foreach ($numbers as $key => $number) { + $mobile_number = new MobileNumber(); + $mobile_number->setID($number->id) + ->setDateRegistered(DateTime::createFromFormat("d M Y - h:i A", $number->date_registered)) + ->setCustomer($row); + + if (!empty($number->date_confirmed)) { + $mobile_number->setDateConfirmed(DateTime::createFromFormat("d M Y - h:i A", $number->date_confirmed)) + ->setConfirmed(); + } else { + $mobile_number->setConfirmed(false); + } + + $nerrors = $validator->validate($mobile_number); + + // add errors to list + foreach ($nerrors as $error) { + if (!isset($nerror_array[$key])) + $nerror_array[$key] = []; + + $nerror_array[$key][$error->getPropertyPath()] = $error->getMessage(); + } + + if (!isset($nerror_array[$key])) { + $row->addMobileNumber($mobile_number); + } + } + } + + // custom validation for vehicles + $vehicles = json_decode($req->request->get('vehicles')); + + if (!empty($vehicles)) { + foreach ($vehicles as $vehicle) { + // check if vehicle exists + $vobj = $em->getRepository(Vehicle::class)->find($vehicle->vehicle); + + if (empty($vobj)) { + $verror_array[$vehicle->index]['vehicle'] = 'Invalid vehicle specified.'; + } else { + $cust_vehicle = new CustomerVehicle(); + $cust_vehicle->setName($vehicle->name) + ->setVehicle($vobj) + ->setPlateNumber($vehicle->plate_number) + ->setModelYear($vehicle->model_year) + ->setColor($vehicle->color) + ->setStatusCondition($vehicle->status_condition) + ->setFuelType($vehicle->fuel_type) + ->setActive($vehicle->flag_active) + ->setCustomer($row); + + // if specified, check if battery exists + if ($vehicle->battery) { + // check if battery exists + $bobj = $em->getRepository(Battery::class)->find($vehicle->battery); + + if (empty($bobj)) { + $verror_array[$vehicle->index]['battery'] = 'Invalid battery specified.'; + } else { + $cust_vehicle->setHasMotoliteBattery(true) + ->setCurrentBattery($bobj) + ->setWarrantyCode($vehicle->warranty_code) + ->setWarrantyExpiration(DateTime::createFromFormat("d M Y", $vehicle->warranty_expiration)); + } + } else { + $cust_vehicle->setHasMotoliteBattery(false); + } + + $verrors = $validator->validate($cust_vehicle); + + // add errors to list + foreach ($verrors as $error) { + if (!isset($verror_array[$vehicle->index])) + $verror_array[$vehicle->index] = []; + + $verror_array[$vehicle->index][$error->getPropertyPath()] = $error->getMessage(); + } + + // add to entity + if (!isset($verror_array[$vehicle->index])) { + $row->addVehicle($cust_vehicle); + } + } + } + } // validate $errors = $validator->validate($row); - // initialize error list - $error_array = []; - // add errors to list foreach ($errors as $error) { $error_array[$error->getPropertyPath()] = $error->getMessage(); } // check if any errors were found - if (!empty($error_array)) { + if (!empty($error_array) || !empty($nerror_array) || !empty($verror_array)) { // return validation failure response return $this->json([ 'success' => false, - 'errors' => $error_array + 'errors' => $error_array, + 'nerrors' => $nerror_array, + 'verrors' => $verror_array ], 422); } else { // validated! save the entity @@ -196,8 +300,13 @@ class CustomerController extends BaseController if (empty($row)) throw $this->createNotFoundException('The item does not exist'); + // get parent associations + $params['bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll(); + $params['vmfgs'] = $em->getRepository(VehicleManufacturer::class)->findAll(); + + $params['years'] = $this->generateYearOptions(); + $params['obj'] = $row; - $params['values'] = []; // response return $this->render('customer/form.html.twig', $params); @@ -216,28 +325,180 @@ class CustomerController extends BaseController throw $this->createNotFoundException('The item does not exist'); // set and save values - $row->setName($req->request->get('name')); + $row->setFirstName($req->request->get('first_name')) + ->setLastName($req->request->get('last_name')); + + // initialize error lists + $error_array = []; + $nerror_array = []; + $verror_array = []; + + // initialize child id lists + $number_ids = []; + $vehicle_ids = []; + + // custom validation for mobile numbers + $numbers = json_decode($req->request->get('mobile_numbers')); + + if (!empty($numbers)) { + foreach ($numbers as $key => $number) { + // check if number exists + $mobile_number = $em->getRepository(MobileNumber::class)->find($number->id); + + // this is a new number + if (empty($mobile_number)) { + $mobile_number = new MobileNumber(); + $mobile_number->setID($number->id) + ->setDateRegistered(DateTime::createFromFormat("d M Y - h:i A", $number->date_registered)) + ->setCustomer($row); + + if (!empty($number->date_confirmed)) { + $mobile_number->setDateConfirmed(DateTime::createFromFormat("d M Y - h:i A", $number->date_confirmed)) + ->setConfirmed(); + } else { + $mobile_number->setConfirmed(false); + } + + $nerrors = $validator->validate($mobile_number); + + // add errors to list + foreach ($nerrors as $error) { + if (!isset($nerror_array[$key])) + $nerror_array[$key] = []; + + $nerror_array[$key][$error->getPropertyPath()] = $error->getMessage(); + } + + if (!isset($nerror_array[$key])) { + $row->addMobileNumber($mobile_number); + } + } + + // add to list of numbers to keep + $number_ids[] = $mobile_number->getID(); + } + } + + // delete all numbers not in list + $qb = $em->createQueryBuilder(); + $del_numbers = $qb->select('m') + ->from(MobileNumber::class, 'm') + ->where($qb->expr()->notIn('m.id', $number_ids)) + ->getQuery() + ->getResult(); + + if (!empty($del_numbers)) { + foreach ($del_numbers as $dn) { + $em->remove($dn); + } + } + + // custom validation for vehicles + $vehicles = json_decode($req->request->get('vehicles')); + + if (!empty($vehicles)) { + foreach ($vehicles as $vehicle) { + $cust_vehicle = false; + $is_new_vehicle = false; + + // check if customer vehicle exists + if (!empty($vehicle->id)) { + $cust_vehicle = $em->getRepository(CustomerVehicle::class)->find($vehicle->id); + } + + // this is a new vehicle + if (empty($cust_vehicle)) { + $cust_vehicle = new CustomerVehicle(); + $cust_vehicle->setCustomer($row); + $is_new_vehicle = true; + } + + // check if vehicle exists + $vobj = $em->getRepository(Vehicle::class)->find($vehicle->vehicle); + + if (empty($vobj)) { + $verror_array[$vehicle->index]['vehicle'] = 'Invalid vehicle specified.'; + } else { + $cust_vehicle->setName($vehicle->name) + ->setVehicle($vobj) + ->setPlateNumber($vehicle->plate_number) + ->setModelYear($vehicle->model_year) + ->setColor($vehicle->color) + ->setStatusCondition($vehicle->status_condition) + ->setFuelType($vehicle->fuel_type) + ->setActive($vehicle->flag_active); + + // if specified, check if battery exists + if ($vehicle->battery) { + // check if battery exists + $bobj = $em->getRepository(Battery::class)->find($vehicle->battery); + + if (empty($bobj)) { + $verror_array[$vehicle->index]['battery'] = 'Invalid battery specified.'; + } else { + $cust_vehicle->setHasMotoliteBattery(true) + ->setCurrentBattery($bobj) + ->setWarrantyCode($vehicle->warranty_code) + ->setWarrantyExpiration(DateTime::createFromFormat("d M Y", $vehicle->warranty_expiration)); + } + } else { + $cust_vehicle->setHasMotoliteBattery(false); + } + + $verrors = $validator->validate($cust_vehicle); + + // add errors to list + foreach ($verrors as $error) { + if (!isset($verror_array[$vehicle->index])) + $verror_array[$vehicle->index] = []; + + $verror_array[$vehicle->index][$error->getPropertyPath()] = $error->getMessage(); + } + + if (!isset($verror_array[$vehicle->index]) && $is_new_vehicle) { + $row->addVehicle($cust_vehicle); + } + + // add to list of vehicles to keep + $vehicle_ids[] = $cust_vehicle->getID(); + } + } + } + + // delete all vehicles not in list + $qb = $em->createQueryBuilder(); + $del_vehicles = $qb->select('cv') + ->from(CustomerVehicle::class, 'cv') + ->where($qb->expr()->notIn('cv.id', $vehicle_ids)) + ->getQuery() + ->getResult(); + + if (!empty($del_vehicles)) { + foreach ($del_vehicles as $dv) { + $em->remove($dv); + } + } // validate $errors = $validator->validate($row); - // initialize error list - $error_array = []; - // add errors to list foreach ($errors as $error) { $error_array[$error->getPropertyPath()] = $error->getMessage(); } // check if any errors were found - if (!empty($error_array)) { + if (!empty($error_array) || !empty($nerror_array) || !empty($verror_array)) { // return validation failure response return $this->json([ 'success' => false, - 'errors' => $error_array + 'errors' => $error_array, + 'nerrors' => $nerror_array, + 'verrors' => $verror_array ], 422); } else { - // validated! save the entity + // validated! save the entity. do a persist anyway to save child entities + $em->persist($row); $em->flush(); // return successful response @@ -270,6 +531,12 @@ class CustomerController extends BaseController $response->send(); } + protected function generateYearOptions() + { + $start_year = 1950; + return range($start_year, date("Y") + 1); + } + // check if datatable filter is present and append to query protected function setQueryFilters($datatable, &$query) { if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { diff --git a/src/Controller/RiderController.php b/src/Controller/RiderController.php new file mode 100644 index 00000000..f86a5f90 --- /dev/null +++ b/src/Controller/RiderController.php @@ -0,0 +1,336 @@ +denyAccessUnlessGranted('rider.list', null, 'No access.'); + + $params = $this->initParameters('rider_list'); + + return $this->render('rider/list.html.twig', $params); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('rider.list', null, 'No access.'); + + // get query builder + $qb = $this->getDoctrine() + ->getRepository(Rider::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)') + ->leftJoin('q.hub', 'hub'); + + // add filters to count query + $this->setQueryFilters($datatable, $tquery); + + $total = $tquery->getQuery() + ->getSingleScalarResult(); + + // get current page number + $page = $datatable['pagination']['page'] ?? 1; + + $perpage = $datatable['pagination']['perpage']; + $offset = ($page - 1) * $perpage; + + // add metadata + $meta = [ + 'page' => $page, + 'perpage' => $perpage, + 'pages' => ceil($total / $perpage), + 'total' => $total, + 'sort' => 'asc', + 'field' => 'id' + ]; + + // build query + $query = $qb->select('q') + ->addSelect('hub.name as hub_name'); + + // add filters to query + $this->setQueryFilters($datatable, $query); + + // check if sorting is present, otherwise use default + if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) { + $order = $datatable['sort']['sort'] ?? 'asc'; + $query->orderBy('q.' . $datatable['sort']['field'], $order); + } else { + $query->orderBy('q.id', 'asc'); + } + + // get rows for this page + $obj_rows = $query->setFirstResult($offset) + ->setMaxResults($perpage) + ->getQuery() + ->getResult(); + // Query::HYDRATE_ARRAY); + + // process rows + $rows = []; + foreach ($obj_rows as $orow) { + // add row data + $row['id'] = $orow[0]->getID(); + $row['image_file'] = $orow[0]->getImageFile(); + $row['first_name'] = $orow[0]->getFirstName(); + $row['last_name'] = $orow[0]->getLastName(); + $row['contact_num'] = $orow[0]->getContactNumber(); + $row['hub'] = $orow['hub_name']; + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('rider.update')) + $row['meta']['update_url'] = $this->generateUrl('rider_update', ['id' => $row['id']]); + if ($this->isGranted('rider.delete')) + $row['meta']['delete_url'] = $this->generateUrl('rider_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + } + + public function addForm() + { + $this->denyAccessUnlessGranted('rider.add', null, 'No access.'); + + $params = $this->initParameters('rider_list'); + $params['obj'] = new Rider(); + $params['mode'] = 'create'; + + $em = $this->getDoctrine()->getManager(); + + // get parent associations + $params['hubs'] = $em->getRepository(Hub::class)->findAll(); + + // response + return $this->render('rider/form.html.twig', $params); + } + + public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator) + { + $this->denyAccessUnlessGranted('rider.add', null, 'No access.'); + + // create new row + $em = $this->getDoctrine()->getManager(); + $row = new Rider(); + + // set and save values + $row->setFirstName($req->request->get('first_name')) + ->setLastName($req->request->get('last_name')) + ->setContactNumber($req->request->get('contact_no')) + ->setImageFile($req->request->get('image_file')); + + // initialize error list + $error_array = []; + + // custom validation for associations + $hub_id = $req->request->get('hub'); + + if ($hub_id) { + $hub = $em->getRepository(Hub::class) + ->find($hub_id); + + if (empty($hub)) + $error_array['hub'] = 'Invalid hub selected.'; + else + $row->setHub($hub); + } + + // validate + $errors = $validator->validate($row); + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } else { + // validated! save the entity + $em->persist($row); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + public function updateForm(FileUploader $uploader, $id) + { + $this->denyAccessUnlessGranted('rider.update', null, 'No access.'); + + $params = $this->initParameters('rider_list'); + $params['mode'] = 'update'; + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(Rider::class)->find($id); + + // make sure this row exists + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + $em = $this->getDoctrine()->getManager(); + + // get parent associations + $params['hubs'] = $em->getRepository(Hub::class)->findAll(); + + $params['obj'] = $row; + + // get file params if present + if (!empty($row->getImageFile())) { + $file = $uploader->getTargetDir() . '/' . $row->getImageFile(); + $params['filesize'] = filesize($file); + } + + // response + return $this->render('rider/form.html.twig', $params); + } + + public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('rider.update', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(Rider::class)->find($id); + + // make sure this row exists + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // set and save values + $row->setFirstName($req->request->get('first_name')) + ->setLastName($req->request->get('last_name')) + ->setContactNumber($req->request->get('contact_no')) + ->setImageFile($req->request->get('image_file')); + + // initialize error list + $error_array = []; + + // custom validation for associations + $hub_id = $req->request->get('hub'); + + if ($hub_id) { + $hub = $em->getRepository(Hub::class) + ->find($hub_id); + + if (empty($hub)) + $error_array['hub'] = 'Invalid hub selected.'; + else + $row->setHub($hub); + } else { + $row->clearHub(); + } + + // validate + $errors = $validator->validate($row); + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } else { + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + } + + public function destroy($id) + { + $this->denyAccessUnlessGranted('rider.delete', null, 'No access.'); + + $params = $this->initParameters('rider_list'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $row = $em->getRepository(Rider::class)->find($id); + + if (empty($row)) + throw $this->createNotFoundException('The item does not exist'); + + // delete this row + $em->remove($row); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } + + public function uploadImage(Request $req, FileUploader $uploader) + { + // retrieve temporary info for file + $file = $req->files->get('image_file'); + + // upload the file + $filename = $uploader->upload($file); + + // return response + return $this->json([ + 'success' => true, + 'filename' => $filename + ]); + } + + // check if datatable filter is present and append to query + protected function setQueryFilters($datatable, &$query) { + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('hub.name LIKE :filter') + ->orWhere('q.first_name LIKE :filter') + ->orWhere('q.last_name LIKE :filter') + ->orWhere('q.contact_num LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } +} diff --git a/src/Controller/RoleController.php b/src/Controller/RoleController.php index b8a14184..49c03bc5 100644 --- a/src/Controller/RoleController.php +++ b/src/Controller/RoleController.php @@ -216,7 +216,6 @@ class RoleController extends BaseController throw $this->createNotFoundException('The item does not exist'); $params['obj'] = $row; - $params['values'] = []; // response return $this->render('role/form.html.twig', $params); diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index c6cfaf2a..4defeaf5 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -242,7 +242,6 @@ class UserController extends BaseController $params['roles'] = $em->getRepository(Role::class)->findAll(); $params['obj'] = $row; - $params['values'] = []; // response return $this->render('user/form.html.twig', $params); diff --git a/src/Controller/VehicleController.php b/src/Controller/VehicleController.php index d2568fd0..cadc7857 100644 --- a/src/Controller/VehicleController.php +++ b/src/Controller/VehicleController.php @@ -296,7 +296,7 @@ class VehicleController extends BaseController protected function generateYearOptions() { $start_year = 1950; - return range($start_year, date("Y")); + return range($start_year, date("Y") + 1); } // check if datatable filter is present and append to query diff --git a/src/Entity/BatteryManufacturer.php b/src/Entity/BatteryManufacturer.php index 2d6bd21e..ddeaada4 100644 --- a/src/Entity/BatteryManufacturer.php +++ b/src/Entity/BatteryManufacturer.php @@ -68,11 +68,6 @@ class BatteryManufacturer public function getBatteries() { - // has to return set of strings because symfony is trying to move away from role objects - $str_batteries = []; - foreach ($this->batteries as $battery) - $str_batteries[] = $this->getProductCode(); - - return $str_batteries; + return $this->batteries; } } diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index d968691f..c1cd86cd 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -36,7 +36,7 @@ class Customer // mobile numbers linked to this customer /** - * @ORM\OneToMany(targetEntity="MobileNumber", mappedBy="customer") + * @ORM\OneToMany(targetEntity="MobileNumber", mappedBy="customer", cascade={"persist"}) */ protected $numbers; @@ -48,7 +48,7 @@ class Customer // vehicles linked to customer /** - * @ORM\OneToMany(targetEntity="CustomerVehicle", mappedBy="customer") + * @ORM\OneToMany(targetEntity="CustomerVehicle", mappedBy="customer", cascade={"persist"}) */ protected $vehicles; @@ -133,7 +133,7 @@ class Customer return $this->sessions; } - public function addVehicle(Vehicle $vehicle) + public function addVehicle(CustomerVehicle $vehicle) { $this->vehicles->add($vehicle); return $this; diff --git a/src/Entity/CustomerVehicle.php b/src/Entity/CustomerVehicle.php index 42f352c1..60271608 100644 --- a/src/Entity/CustomerVehicle.php +++ b/src/Entity/CustomerVehicle.php @@ -23,6 +23,7 @@ class CustomerVehicle // user-defined name for vehicle /** * @ORM\Column(type="string", length=80) + * @Assert\NotBlank() */ protected $name; @@ -81,7 +82,6 @@ class CustomerVehicle // TODO: figure out how to check expiration /** * @ORM\Column(type="string", length=20, nullable=true) - * @Assert\NotBlank() */ protected $warranty_code; @@ -121,6 +121,17 @@ class CustomerVehicle return $this->id; } + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + public function setCustomer(Customer $customer) { $this->customer = $customer; @@ -220,7 +231,7 @@ class CustomerVehicle return $this->warranty_expiration; } - public function setCurrentBattery($curr_battery) + public function setCurrentBattery(Battery $curr_battery) { $this->curr_battery = $curr_battery; return $this; @@ -242,14 +253,14 @@ class CustomerVehicle return $this->flag_motolite_battery; } - public function setActive($active = true) + public function setActive($flag_active = true) { - $this->active = $active; + $this->flag_active = $flag_active; return $this; } public function isActive() { - return $this->active; + return $this->flag_active; } } diff --git a/src/Entity/MobileNumber.php b/src/Entity/MobileNumber.php index 7ddef1ab..586a5392 100644 --- a/src/Entity/MobileNumber.php +++ b/src/Entity/MobileNumber.php @@ -117,4 +117,15 @@ class MobileNumber { return $this->date_confirmed; } + + public function setConfirmed($flag_confirmed = true) + { + $this->flag_confirmed = $flag_confirmed; + return $this; + } + + public function isConfirmed() + { + return $this->flag_confirmed; + } } diff --git a/src/Entity/Rider.php b/src/Entity/Rider.php index 34f6fea1..76b04ee0 100644 --- a/src/Entity/Rider.php +++ b/src/Entity/Rider.php @@ -50,6 +50,11 @@ class Rider */ protected $job_orders; + /** + * @ORM\Column(type="string", nullable=true) + */ + protected $image_file; + public function __construct() { $this->job_orders = new ArrayCollection(); @@ -103,4 +108,21 @@ class Rider { return $this->hub; } + + public function clearHub() + { + $this->hub = null; + return $this; + } + + public function setImageFile($image_file) + { + $this->image_file = $image_file; + return $this; + } + + public function getImageFile() + { + return $this->image_file; + } } diff --git a/src/Service/FileUploader.php b/src/Service/FileUploader.php new file mode 100644 index 00000000..c33fb672 --- /dev/null +++ b/src/Service/FileUploader.php @@ -0,0 +1,29 @@ +target_dir = $target_dir; + } + + public function upload(UploadedFile $file) + { + $filename = md5(uniqid()) . '.' . $file->guessExtension(); + + $file->move($this->getTargetDir(), $filename); + + return $filename; + } + + public function getTargetDir() + { + return $this->target_dir; + } +} diff --git a/templates/battery/form.html.twig b/templates/battery/form.html.twig index 32da2479..8e2a791e 100644 --- a/templates/battery/form.html.twig +++ b/templates/battery/form.html.twig @@ -195,7 +195,7 @@ Add Vehicle:
    - {% for manufacturer in vmfgs %} @@ -328,12 +328,12 @@ // update vehicle list when changing manufacturer $("#vmfg").change(function() { var id = $(this).val(); - var vehiclefield = $("#vehicle"); + var field = $("#vehicle"); var btn = $("#btn-add-vehicle"); // no id specified if (!id) { - vehiclefield.html('').prop('disabled', true); + field.html('').prop('disabled', true); btn.prop('disabled', true); return true; } @@ -346,18 +346,18 @@ url: "{{ url('vmfg_vehicles') }}", data: {id: id} }).done(function(response) { - if (response.data) { + if (response.data.length > 0) { var html = ''; $.each(response.data, function(index, vehicle) { - html += ''; + html += ''; }); - vehiclefield.html(html).prop('disabled', false); + field.html(html).prop('disabled', false); btn.prop('disabled', false); mfgVehicles = response.data; } else { - vehiclefield.html('').prop('disabled', true); + field.html('').prop('disabled', true); btn.prop('disabled', true); } }) diff --git a/templates/customer/form.html.twig b/templates/customer/form.html.twig index 020bf319..79a4bdb8 100644 --- a/templates/customer/form.html.twig +++ b/templates/customer/form.html.twig @@ -34,7 +34,7 @@
    -
    @@ -77,7 +77,7 @@ Use the format 63xxxxxxxxxx
    -
    +
    @@ -95,7 +95,10 @@
    -
    +
    +
    + +
    @@ -115,6 +118,172 @@
    + {% endblock %} {% block scripts %} @@ -122,13 +291,26 @@ $(function() { $("#row-form").submit(function(e) { var form = $(this); + var formdata = form.serializeArray(); e.preventDefault(); + // add mobile number data + formdata.push({ + name: 'mobile_numbers', + value: JSON.stringify(numberRows) + }); + + // add vehicle data + formdata.push({ + name: 'vehicles', + value: JSON.stringify(vehicleRows) + }); + $.ajax({ method: "POST", url: form.prop('action'), - data: form.serialize() + data: formdata }).done(function(response) { // remove all error classes removeErrors(); @@ -141,7 +323,10 @@ } }); }).fail(function(response) { - var errors = response.responseJSON.errors; + var json = response.responseJSON; + var errors = json.errors; + var nerrors = json.nerrors; + var verrors = json.verrors; var firstfield = false; // remove all error classes first @@ -149,7 +334,7 @@ // display errors contextually $.each(errors, function(field, msg) { - var formfield = $("[name='" + field + "']"); + var formfield = $("[data-name='" + field + "']"); var label = $("label[data-field='" + field + "']"); var msgbox = $(".form-control-feedback[data-field='" + field + "']"); @@ -164,8 +349,66 @@ if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) { firstfield = domfield; } + + // add error class to this tab + var tabId = $(formfield).closest('.tab-pane').prop('id'); + $("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger'); }); + // loop through mobile number errors + $.each(nerrors, function(rowindex, errorlist) { + var row = $("#data-mobile-numbers table").find("[name='index'][value='" + rowindex + "']").closest('tr'); + + $.each(errorlist, function(field, msg) { + var msgbox = row.find(".form-control-feedback[data-field='" + field + "']"); + var col = msgbox.closest('span'); + + // add error classes to bad fields + col.addClass('has-danger'); + msgbox.html(msg).addClass('has-danger').removeClass('hide'); + + // check if this field comes first in DOM + var domfield = col.get(0); + + if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) { + firstfield = domfield; + } + + // add error class to this tab + var tabId = $(col).closest('.tab-pane').prop('id'); + $("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger'); + }); + }); + + // loop through vehicle errors + $.each(verrors, function(rowindex, errorlist) { + var row = $("#data-vehicles table").find("[name='index'][value='" + rowindex + "']").closest('tr'); + + $.each(errorlist, function(field, msg) { + var msgbox = row.find(".form-control-feedback[data-field='" + field + "']"); + var col = msgbox.closest('span'); + + // add error classes to bad fields + col.addClass('has-danger'); + msgbox.html(msg).addClass('has-danger').removeClass('hide'); + + // check if this field comes first in DOM + var domfield = col.get(0); + + if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) { + firstfield = domfield; + } + + // add error class to this tab + var tabId = $(col).closest('.tab-pane').prop('id'); + $("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger'); + }); + }); + + // focus on tab containing first field + var firstTabId = $(firstfield).closest('.tab-pane').prop('id'); + $("#customer-tabs").find("a[href='#" + firstTabId + "']").tab('show'); + // focus on first bad field firstfield.focus(); @@ -179,19 +422,30 @@ // remove all error classes function removeErrors() { $(".form-control-danger").removeClass('form-control-danger'); - $("[data-field]").removeClass('has-danger'); + $(".has-danger").removeClass('has-danger'); $(".form-control-feedback[data-field]").addClass('hide'); } // datetimepicker - $(".date").datetimepicker({ + $(".dtp").datetimepicker({ format: "dd M yyyy - HH:ii P", showMeridian: true, todayHighlight: true, autoclose: true, pickerPosition: 'top-left', bootcssVer: 3, - todayBtn: true + todayBtn: true, + clearBtn: true + }); + + // datepicker + $(".dp").datepicker({ + format: "dd M yyyy", + todayHighlight: true, + autoclose: true, + pickerPosition: 'top-left', + bootcssVer: 3, + clearBtn: true }); // input mask @@ -200,18 +454,22 @@ placeholder: "" }); + $("#vehicle-year").inputmask("mask", { + mask: "9999", + placeholder: "" + }); + // initialize arrays var numberRows = []; var numberIds = []; var mfgVehicles = []; var vehicleRows = []; - var vehicleIds = []; {% for number in obj.getMobileNumbers() %} nrow = { id: "{{ number.getID() }}", - date_registered: "{{ number.getDateRegistered() }}", - date_confirmed: "{{ number.getDateConfirmed() }}" + date_registered: "{{ number.getDateRegistered()|date('d M Y - h:i A') }}", + date_confirmed: "{{ number.getDateConfirmed()|date('d M Y - h:i A') }}" }; numberRows.push(nrow); @@ -224,44 +482,28 @@ vrow = { id: "{{ cv.getID() }}", - mfg_name: "{{ vehicle.getManufacturer().getName() }}", - make: "{{ vehicle.getMake() }}", - model_year: "{{ cv.getModelYear() }}", + name: "{{ cv.getName() }}", + index: moment().unix(), + battery: "{{ battery ? battery.getID() }}", + battery_label: "{{ battery ? battery.getModel().getName() ~ ' ' ~ battery.getSize().getName() ~ ' (' ~ battery.getProductCode() ~ ')' }}", + bmfg: "{{ battery ? battery.getManufacturer().getID() }}", color: "{{ cv.getColor() }}", - status_condition: "{{ cv.getStatusCondition() }}", + flag_active: {{ cv.isActive() ? 'true' : 'false' }}, + flag_motolite_battery: {{ cv.hasMotoliteBattery() ? 'true' : 'false' }}, fuel_type: "{{ cv.getFuelType() }}", + model_year: "{{ cv.getModelYear() }}", + plate_number: "{{ cv.getPlateNumber() }}", + status_condition: "{{ cv.getStatusCondition() }}", + vehicle: "{{ vehicle ? vehicle.getID() }}", + vehicle_label: "{{ vehicle ? vehicle.getManufacturer().getName() ~ ' ' ~ vehicle.getMake() ~ ' (' ~ vehicle.getModelYearFrom() ~ ' ' ~ vehicle.getModelYearTo() ~ ')' }}", + vmfg: "{{ vehicle ? vehicle.getManufacturer().getID() }}", warranty_code: "{{ cv.getWarrantyCode() }}", - warranty_expiration: "{{ cv.getWarrantyExpiration() ? cv.getWarrantyExpiration()|date('d M Y') }}", - curr_battery_id: "{{ battery.getID() }}", - curr_battery_prod_code: "{{ battery.getProductCode() }}", - curr_battery_manufacturer: "{{ battery.getManufacturer().getName() }}", - flag_motolite_battery: {{ cv.hasMotoliteBattery() }}, - flag_active: {{ cv.isActive() }} + warranty_expiration: "{{ cv.getWarrantyExpiration() ? cv.getWarrantyExpiration()|date('d M Y') }}" }; vehicleRows.push(vrow); - vehicleIds.push("{{ cv.getID() }}"); {% endfor %} - vrow = { - id: "123", - mfg_name: "Mitsubishi", - make: "Lancer", - model_year: "1996", - color: "Red", - status_condition: "New", - fuel_type: "Gas", - warranty_code: "12345", - warranty_expiration: "15 Jan 2018", - curr_battery_id: "11", - curr_battery_prod_code: "TESTBATT", - curr_battery_manufacturer: "Motolite", - flag_motolite_battery: 1, - flag_active: 1 - }; - - vehicleRows.push(vrow); - // add a mobile number to the table $("#btn-add-mobile-number").click(function() { var id = $("#mobile-number").val(); @@ -311,65 +553,295 @@ numberTable.reload(); }); - // add a vehicle to the table - $("#btn-add-vehicle").click(function() { - var id = $("#vehicle").val(); - var index = $("#vehicle").find(":selected").data('index'); + // remove mobile number from table + $(document).on('click', '.btn-delete-number', function(e) { + var btn = $(this); + var id = $(this).data('id'); + var table = $(this).closest('table'); - if (vehicleIds.indexOf(id) !== -1) { - swal({ - title: 'Whoops', - text: 'This vehicle is already on the list.', - type: 'warning' - }); + // remove from ids + numberIds.splice(numberIds.indexOf(id), 1); - return true; - } + $.each(numberRows, function(index, row) { + if (row.id == id) { + numberRows.splice(index, 1); + return false; + } + }); + + // reload table + numberTable.row(btn.parents('tr')).remove(); + numberTable.originalDataSet = numberRows; + numberTable.reload(); + }); - // add vehicle to arrays - vehicleIds.push(id); - vehicleRows.push(mfgVehicles[index]); + // remove vehicle from table + $(document).on('click', '.btn-delete-vehicle', function(e) { + var btn = $(this); + var id = $(this).data('index'); + var table = $(this).closest('table'); - // refresh the data table + $.each(vehicleRows, function(index, row) { + if (row.index == id) { + vehicleRows.splice(index, 1); + return false; + } + }); + + // reload table + vehicleTable.row(btn.parents('tr')).remove(); vehicleTable.originalDataSet = vehicleRows; vehicleTable.reload(); }); - // remove mobile number from table - $(document).on('click', '.btn-delete', function(e) { - var btn = $(this); - var id = $(this).data('id'); - var table = $(this).closest('table'); - var rowArray; - var rowIds; - var dt; + // display create vehicle form + $("#add-vehicle").click(function() { + $("#vehicle-form").data('mode', 'create'); + $("#vehicle-form-title").html("Add Vehicle"); + $("#vehicle-form-modal").modal('show'); + }); - if (table.parent().prop('id') == 'data-mobile-numbers') { - rowArray = numberRows; - rowIds = numberIds; - dt = numberTable; - } else { - rowArray = vehicleRows; - rowIds = vehicleIds; - dt = vehicleTable; - } + // find vehicle row by index + function findVehicleRow(index) { + for (var i = 0, len = vehicleRows.length; i < len; i++) { + if (vehicleRows[i].index === index) { + return { + row: vehicleRows[i], + index: i + }; + } + } - $.each(rowArray, function(index, row) { - if (row.id == id) { - rowArray.splice(index, 1); - return false; + return false; + } + + // display edit vehicle form + $(document).on("click", ".btn-edit-vehicle", function() { + var form = $("#vehicle-form"); + var tr = $(this).closest('tr'); + var index = parseInt(tr.find("[name='index']").val()); + var rowData = findVehicleRow(index); + + if (!rowData) { + return; + } + + row = rowData.row; + + // set form mode + form.data('mode', 'update'); + $("#vehicle-form-title").html("Edit Vehicle"); + + // set index + $("#row-index").val(row.index); + + // set text/select field values manually + form.find("input[type='text'], select").each(function() { + var rowval = row[$(this).prop('name')]; + + if (typeof rowval !== 'undefined') { + $(this).val(rowval); } }); - // remove from ids - rowIds.splice(rowIds.indexOf(id), 1); - - // reload table - dt.row(btn.parents('tr')).remove(); - dt.originalDataSet = rowArray; - dt.reload(); + // set entity ids + $("#vehicle").data('id', row.vehicle); + $("#battery").data('id', row.battery); + $("#cv-id").val(row.id); + + // set select box values + $("#vmfg").val(row.vmfg).change(); + + if (row.battery) { + $("#flag-motolite-battery").prop('checked', true).change(); + $("#bmfg").val(row.bmfg).change(); + } + + $("#flag-active").prop('checked', row.flag_active); + + // show modal + $("#vehicle-form-modal").modal('show'); }); + // update vehicle list when changing manufacturer + $("#vmfg").change(function() { + var id = $(this).val(); + var field = $("#vehicle"); + + // no id specified + if (!id) { + field.html('').prop('disabled', true); + return true; + } + + // get vehicles for this manufacturer + $.ajax({ + method: "POST", + url: "{{ url('vmfg_vehicles') }}", + data: {id: id} + }).done(function(response) { + if (response.data.length > 0) { + var html = ''; + + $.each(response.data, function(index, vehicle) { + html += ''; + }); + + field.html(html).prop('disabled', false); + } else { + field.html('').prop('disabled', true); + } + }) + }); + + // update battery list when changing manufacturer + $("#bmfg").change(function() { + var id = $(this).val(); + var field = $("#battery"); + + // no id specified + if (!id) { + field.html('').prop('disabled', true); + return true; + } + + // get vehicles for this manufacturer + $.ajax({ + method: "POST", + url: "{{ url('bmfg_batteries') }}", + data: {id: id} + }).done(function(response) { + if (response.data.length > 0) { + var html = ''; + + $.each(response.data, function(index, battery) { + html += ''; + }); + + field.html(html).prop('disabled', false); + } else { + field.html('').prop('disabled', true); + } + }) + }); + + // toggle motolite battery area + $("#flag-motolite-battery").change(function() { + var currBatteryRows = $(".curr_battery_row"); + + if ($(this).prop('checked') == true) { + currBatteryRows.removeClass('hide').find("[name='battery']").data('required', 1); + } else { + currBatteryRows.addClass('hide').find("[name='battery']").data('required', 0); + } + }); + + // save vehicle form + $("#vehicle-form").submit(function(e) { + var form = $(this); + var mode = form.data('mode'); + + // get all fields, including disabled ones + var disabled = form.find(":input:disabled").prop('disabled', false); + var fields = form.serializeArray().map(function(x){this[x.name] = x.value; return this;}.bind({}))[0]; + disabled.prop('disabled', true); + + e.preventDefault(); + + var errors = 0; + var firstfield = false; + + // remove all error classes first + removeVehicleErrors(); + + // check for required fields + $.each(fields, function(field, value) { + var formfield = form.find("[name='" + field + "']"); + var label = form.find("label[data-field='" + field + "']"); + var msgbox = form.find(".form-control-feedback[data-field='" + field + "']"); + var required = formfield.data('required'); + + if (required === 1 && !value) { + errors++; + + // add error classes to bad fields + formfield.addClass('form-control-danger'); + label.addClass('has-danger'); + msgbox.html("This value should not be blank.").addClass('has-danger').removeClass('hide'); + + // check if this field comes first in DOM + var domfield = formfield.get(0); + + if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) { + firstfield = domfield; + } + } + }); + + // errors were found + if (errors > 0) { + // focus on first bad field + firstfield.focus(); + + // scroll to above that field to make it visible + $('html, body').animate({ + scrollTop: $(firstfield).offset().top - 200 + }, 100); + + return false; + } + + // build table row + var row = fields; + row.vehicle_label = $("#vmfg option:selected").text() + " " + $("#vehicle option:selected").text(); + row.flag_active = row.flag_active == 1 ? true : false; + + // add optional field + if (typeof fields.flag_motolite_battery === 'undefined') { + row.flag_motolite_battery = false; + row.battery_label = ""; + } else { + row.flag_motolite_battery = true; + row.battery_label = $("#battery option:selected").text(); + } + + if (mode == 'create') { + // set an index + row.index = moment().unix(); + + // save to table + vehicleRows.push(row); + } else { + // get vehicle row by index + row.index = parseInt(row.index); + rowData = findVehicleRow(row.index); + vehicleRows[rowData.index] = row; + } + + // refresh the data table + vehicleTable.originalDataSet = vehicleRows; + vehicleTable.reload(); + + // close modal + $("#vehicle-form-modal").modal('hide'); + }); + + // reset vehicle form status on close + $("#vehicle-form-modal").on('hidden.bs.modal', function(e) { + $("#flag-motolite-battery").prop('checked', false).change(); + $("#flag-active").prop('checked', true); + $("#vehicle-form").find("input[type='text'], select").val("").change(); + removeVehicleErrors(); + }); + + // remove all error classes on vehicle form + function removeVehicleErrors() { + var form = $("#vehicle-form"); + form.find(".form-control-danger").removeClass('form-control-danger'); + form.find("[data-field]").removeClass('has-danger'); + form.find(".form-control-feedback[data-field]").addClass('hide'); + } + // mobile numbers data table var numberOptions = { data: { @@ -386,15 +858,24 @@ columns: [ { field: 'id', - title: 'Mobile Number' + title: 'Mobile Number', + template: function (row, index, datatable) { + return row.id + ''; + } }, { field: 'date_registered', - title: 'Date Registered' + title: 'Date Registered', + template: function (row, index, datatable) { + return row.date_registered + ''; + } }, { field: 'date_confirmed', - title: 'Date Confirmed' + title: 'Date Confirmed', + template: function (row, index, datatable) { + return row.date_confirmed + ''; + } }, { field: 'Actions', @@ -403,7 +884,7 @@ sortable: false, overflow: 'visible', template: function (row, index, datatable) { - return ''; + return ''; }, } ], @@ -427,79 +908,91 @@ }, columns: [ { - field: 'mfg_name', - title: 'Manufacturer' + field: 'name', + title: 'Name', + template: function (row, index, datatable) { + return row.name + ''; + } }, { - field: 'make', - title: 'Make' + field: 'vehicle_label', + title: 'Vehicle', + width: 150, + template: function (row, index, datatable) { + return row.vehicle_label + ''; + } }, { field: 'model_year', title: 'Year', template: function (row, index, datatable) { - return '' + return row.model_year + ''; + } + }, + { + field: 'plate_number', + title: 'Plate No.', + template: function (row, index, datatable) { + return row.plate_number + ''; } }, { field: 'color', title: 'Color', + width: 70, template: function (row, index, datatable) { - return '' + return row.color + ''; } }, { field: 'status_condition', - title: 'Status', - width: 50 + title: 'Cond.', + template: function (row, index, datatable) { + return row.status_condition + ''; + } }, { field: 'fuel_type', - title: 'Fuel Type' + title: 'Fuel Type', + template: function (row, index, datatable) { + return row.fuel_type + ''; + } }, { field: 'warranty_code', - title: 'Warranty Code', + title: 'Wty. Code', template: function (row, index, datatable) { - return '' + return row.warranty_code + ''; } }, { field: 'warranty_expiration', - title: 'Warranty Expiration', + title: 'Wty. Exp.', + width: 80, + template: function (row, index, datatable) { + return row.warranty_expiration + ''; + } + }, + { + field: 'battery_label', + title: 'Battery', width: 150, template: function (row, index, datatable) { - return '' - } - }, - { - field: 'curr_battery', - title: 'Current Battery', - template: function (row, index, datatable) { - return row.curr_battery_manufacturer + ' ' + row.curr_battery_prod_code; - } - }, - { - field: 'flag_motolite_battery', - title: 'Using Motolite battery?', - template: function (row, index, datatable) { - html = ''; - return html; + return row.battery_label + ''; } }, { field: 'flag_active', - title: 'Is the vehicle active?', + title: 'Status', template: function (row, index, datatable) { - html = ''; + if (row.flag_active === true) { + html = 'Active'; + } else { + html = 'Inactive'; + } + + html += ''; + return html; } }, @@ -510,7 +1003,12 @@ sortable: false, overflow: 'visible', template: function (row, index, datatable) { - return ''; + html = ''; + + html += '' + + ''; + + return html; }, } ], diff --git a/templates/rider/form.html.twig b/templates/rider/form.html.twig new file mode 100644 index 00000000..485ef353 --- /dev/null +++ b/templates/rider/form.html.twig @@ -0,0 +1,229 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
    +
    +
    +

    Riders

    +
    +
    +
    + +
    + +
    +
    +
    +
    +
    +
    + + + +

    + {% if mode == 'update' %} + Edit Rider + {{ obj.getFirstName() ~ ' ' ~ obj.getLastName() }} + {% else %} + New Rider + {% endif %} +

    +
    +
    +
    +
    +
    +
    + +
    + + +
    + +
    + + +
    +
    +
    + +
    + + +
    + +
    + + +
    +
    +
    + +
    +
    +
    +

    + Drop files here or click to upload. +

    + + Upload only valid PNG, GIF, or JPEG images + +
    +
    + {% if mode == 'update' %} + Leave blank for unchanged + {% endif %} + +
    + {% if mode == 'update' %} +
    +
    +
    + {% endif %} +
    +
    +
    +
    +
    +
    + + + Cancel +
    +
    +
    +
    +
    +
    +
    +
    +
    +{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/rider/list.html.twig b/templates/rider/list.html.twig new file mode 100644 index 00000000..6db8bc97 --- /dev/null +++ b/templates/rider/list.html.twig @@ -0,0 +1,172 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
    +
    +
    +

    + Riders +

    +
    +
    +
    + +
    + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + + +
    +
    +
    +
    + +
    +
    + +
    + +
    +
    +
    +
    +
    +{% endblock %} + +{% block scripts %} + +{% endblock %}