From 36146b3fadc47543f4b696ab75c31b3459afb15b Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Thu, 14 Aug 2014 14:10:40 +0200 Subject: [PATCH] [FIX] web: update moment and datepicker library also add a controller to lazily load locale --- addons/web/controllers/main.py | 28 + .../css/bootstrap-datetimepicker.css | 26 +- .../css/bootstrap-datetimepicker.min.css | 4 - .../js/bootstrap-datetimepicker.min.js | 105 - .../src/js/bootstrap-datetimepicker.js | 907 +- .../less/bootstrap-datetimepicker-build.less | 2 +- .../src/less/bootstrap-datetimepicker.less | 20 +- addons/web/static/lib/moment/locale/af.js | 65 + addons/web/static/lib/moment/locale/ar-ma.js | 56 + addons/web/static/lib/moment/locale/ar-sa.js | 96 + addons/web/static/lib/moment/locale/ar.js | 97 + addons/web/static/lib/moment/locale/az.js | 101 + addons/web/static/lib/moment/locale/be.js | 150 + addons/web/static/lib/moment/locale/bg.js | 86 + addons/web/static/lib/moment/locale/bn.js | 106 + addons/web/static/lib/moment/locale/bo.js | 103 + addons/web/static/lib/moment/locale/br.js | 107 + addons/web/static/lib/moment/locale/bs.js | 138 + addons/web/static/lib/moment/locale/ca.js | 66 + addons/web/static/lib/moment/locale/cs.js | 155 + addons/web/static/lib/moment/locale/cv.js | 59 + addons/web/static/lib/moment/locale/cy.js | 77 + addons/web/static/lib/moment/locale/da.js | 56 + addons/web/static/lib/moment/locale/de-at.js | 72 + addons/web/static/lib/moment/locale/de.js | 71 + addons/web/static/lib/moment/locale/el.js | 90 + addons/web/static/lib/moment/locale/en-au.js | 62 + addons/web/static/lib/moment/locale/en-ca.js | 59 + addons/web/static/lib/moment/locale/en-gb.js | 63 + addons/web/static/lib/moment/locale/eo.js | 65 + addons/web/static/lib/moment/locale/es.js | 75 + addons/web/static/lib/moment/locale/et.js | 76 + addons/web/static/lib/moment/locale/eu.js | 60 + addons/web/static/lib/moment/locale/fa.js | 97 + addons/web/static/lib/moment/locale/fi.js | 105 + addons/web/static/lib/moment/locale/fo.js | 56 + addons/web/static/lib/moment/locale/fr-ca.js | 54 + addons/web/static/lib/moment/locale/fr.js | 58 + addons/web/static/lib/moment/locale/gl.js | 71 + addons/web/static/lib/moment/locale/he.js | 77 + addons/web/static/lib/moment/locale/hi.js | 105 + addons/web/static/lib/moment/locale/hr.js | 139 + addons/web/static/lib/moment/locale/hu.js | 105 + addons/web/static/lib/moment/locale/hy-am.js | 112 + addons/web/static/lib/moment/locale/id.js | 67 + addons/web/static/lib/moment/locale/is.js | 124 + addons/web/static/lib/moment/locale/it.js | 59 + addons/web/static/lib/moment/locale/ja.js | 58 + addons/web/static/lib/moment/locale/ka.js | 107 + addons/web/static/lib/moment/locale/km.js | 55 + addons/web/static/lib/moment/locale/ko.js | 63 + addons/web/static/lib/moment/locale/lb.js | 137 + addons/web/static/lib/moment/locale/lt.js | 118 + addons/web/static/lib/moment/locale/lv.js | 77 + addons/web/static/lib/moment/locale/mk.js | 86 + addons/web/static/lib/moment/locale/ml.js | 64 + addons/web/static/lib/moment/locale/mr.js | 104 + addons/web/static/lib/moment/locale/ms-my.js | 66 + addons/web/static/lib/moment/locale/my.js | 88 + addons/web/static/lib/moment/locale/nb.js | 57 + addons/web/static/lib/moment/locale/ne.js | 105 + addons/web/static/lib/moment/locale/nl.js | 67 + addons/web/static/lib/moment/locale/nn.js | 56 + addons/web/static/lib/moment/locale/pl.js | 98 + addons/web/static/lib/moment/locale/pt-br.js | 56 + addons/web/static/lib/moment/locale/pt.js | 60 + addons/web/static/lib/moment/locale/ro.js | 72 + addons/web/static/lib/moment/locale/ru.js | 166 + addons/web/static/lib/moment/locale/sk.js | 156 + addons/web/static/lib/moment/locale/sl.js | 144 + addons/web/static/lib/moment/locale/sq.js | 61 + .../web/static/lib/moment/locale/sr-cyrl.js | 105 + addons/web/static/lib/moment/locale/sr.js | 105 + addons/web/static/lib/moment/locale/sv.js | 63 + addons/web/static/lib/moment/locale/ta.js | 112 + addons/web/static/lib/moment/locale/th.js | 58 + addons/web/static/lib/moment/locale/tl-ph.js | 58 + addons/web/static/lib/moment/locale/tr.js | 92 + .../web/static/lib/moment/locale/tzm-latn.js | 55 + addons/web/static/lib/moment/locale/tzm.js | 55 + addons/web/static/lib/moment/locale/uk.js | 157 + addons/web/static/lib/moment/locale/uz.js | 55 + addons/web/static/lib/moment/locale/vi.js | 62 + addons/web/static/lib/moment/locale/zh-cn.js | 108 + addons/web/static/lib/moment/locale/zh-tw.js | 84 + .../static/lib/moment/moment-with-langs.js | 8521 ----------------- .../lib/moment/moment-with-langs.min.js | 9 - addons/web/static/lib/moment/moment.js | 930 +- addons/web/static/lib/moment/moment.min.js | 6 - addons/web/static/src/js/core.js | 100 +- addons/web/static/src/js/view_form.js | 27 +- addons/web/views/webclient_templates.xml | 2 +- 92 files changed, 7909 insertions(+), 9508 deletions(-) delete mode 100644 addons/web/static/lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css delete mode 100644 addons/web/static/lib/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js create mode 100644 addons/web/static/lib/moment/locale/af.js create mode 100644 addons/web/static/lib/moment/locale/ar-ma.js create mode 100644 addons/web/static/lib/moment/locale/ar-sa.js create mode 100644 addons/web/static/lib/moment/locale/ar.js create mode 100644 addons/web/static/lib/moment/locale/az.js create mode 100644 addons/web/static/lib/moment/locale/be.js create mode 100644 addons/web/static/lib/moment/locale/bg.js create mode 100644 addons/web/static/lib/moment/locale/bn.js create mode 100644 addons/web/static/lib/moment/locale/bo.js create mode 100644 addons/web/static/lib/moment/locale/br.js create mode 100644 addons/web/static/lib/moment/locale/bs.js create mode 100644 addons/web/static/lib/moment/locale/ca.js create mode 100644 addons/web/static/lib/moment/locale/cs.js create mode 100644 addons/web/static/lib/moment/locale/cv.js create mode 100644 addons/web/static/lib/moment/locale/cy.js create mode 100644 addons/web/static/lib/moment/locale/da.js create mode 100644 addons/web/static/lib/moment/locale/de-at.js create mode 100644 addons/web/static/lib/moment/locale/de.js create mode 100644 addons/web/static/lib/moment/locale/el.js create mode 100644 addons/web/static/lib/moment/locale/en-au.js create mode 100644 addons/web/static/lib/moment/locale/en-ca.js create mode 100644 addons/web/static/lib/moment/locale/en-gb.js create mode 100644 addons/web/static/lib/moment/locale/eo.js create mode 100644 addons/web/static/lib/moment/locale/es.js create mode 100644 addons/web/static/lib/moment/locale/et.js create mode 100644 addons/web/static/lib/moment/locale/eu.js create mode 100644 addons/web/static/lib/moment/locale/fa.js create mode 100644 addons/web/static/lib/moment/locale/fi.js create mode 100644 addons/web/static/lib/moment/locale/fo.js create mode 100644 addons/web/static/lib/moment/locale/fr-ca.js create mode 100644 addons/web/static/lib/moment/locale/fr.js create mode 100644 addons/web/static/lib/moment/locale/gl.js create mode 100644 addons/web/static/lib/moment/locale/he.js create mode 100644 addons/web/static/lib/moment/locale/hi.js create mode 100644 addons/web/static/lib/moment/locale/hr.js create mode 100644 addons/web/static/lib/moment/locale/hu.js create mode 100644 addons/web/static/lib/moment/locale/hy-am.js create mode 100644 addons/web/static/lib/moment/locale/id.js create mode 100644 addons/web/static/lib/moment/locale/is.js create mode 100644 addons/web/static/lib/moment/locale/it.js create mode 100644 addons/web/static/lib/moment/locale/ja.js create mode 100644 addons/web/static/lib/moment/locale/ka.js create mode 100644 addons/web/static/lib/moment/locale/km.js create mode 100644 addons/web/static/lib/moment/locale/ko.js create mode 100644 addons/web/static/lib/moment/locale/lb.js create mode 100644 addons/web/static/lib/moment/locale/lt.js create mode 100644 addons/web/static/lib/moment/locale/lv.js create mode 100644 addons/web/static/lib/moment/locale/mk.js create mode 100644 addons/web/static/lib/moment/locale/ml.js create mode 100644 addons/web/static/lib/moment/locale/mr.js create mode 100644 addons/web/static/lib/moment/locale/ms-my.js create mode 100644 addons/web/static/lib/moment/locale/my.js create mode 100644 addons/web/static/lib/moment/locale/nb.js create mode 100644 addons/web/static/lib/moment/locale/ne.js create mode 100644 addons/web/static/lib/moment/locale/nl.js create mode 100644 addons/web/static/lib/moment/locale/nn.js create mode 100644 addons/web/static/lib/moment/locale/pl.js create mode 100644 addons/web/static/lib/moment/locale/pt-br.js create mode 100644 addons/web/static/lib/moment/locale/pt.js create mode 100644 addons/web/static/lib/moment/locale/ro.js create mode 100644 addons/web/static/lib/moment/locale/ru.js create mode 100644 addons/web/static/lib/moment/locale/sk.js create mode 100644 addons/web/static/lib/moment/locale/sl.js create mode 100644 addons/web/static/lib/moment/locale/sq.js create mode 100644 addons/web/static/lib/moment/locale/sr-cyrl.js create mode 100644 addons/web/static/lib/moment/locale/sr.js create mode 100644 addons/web/static/lib/moment/locale/sv.js create mode 100644 addons/web/static/lib/moment/locale/ta.js create mode 100644 addons/web/static/lib/moment/locale/th.js create mode 100644 addons/web/static/lib/moment/locale/tl-ph.js create mode 100644 addons/web/static/lib/moment/locale/tr.js create mode 100644 addons/web/static/lib/moment/locale/tzm-latn.js create mode 100644 addons/web/static/lib/moment/locale/tzm.js create mode 100644 addons/web/static/lib/moment/locale/uk.js create mode 100644 addons/web/static/lib/moment/locale/uz.js create mode 100644 addons/web/static/lib/moment/locale/vi.js create mode 100644 addons/web/static/lib/moment/locale/zh-cn.js create mode 100644 addons/web/static/lib/moment/locale/zh-tw.js delete mode 100644 addons/web/static/lib/moment/moment-with-langs.js delete mode 100644 addons/web/static/lib/moment/moment-with-langs.min.js delete mode 100644 addons/web/static/lib/moment/moment.min.js diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 5c812e5139c..b34c33d4a23 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -590,6 +590,34 @@ class WebClient(http.Controller): def jslist(self, mods=None): return manifest_list('js', mods=mods) + @http.route('/web/webclient/locale/', type='http', auth="none") + def load_locale(self, lang): + magic_file_finding = [lang.replace("_",'-').lower(), lang.split('_')[0]] + addons_path = http.addons_manifest['web']['addons_path'] + #load datejs locale + datejs_locale = "" + try: + with open(os.path.join(addons_path, 'web', 'static', 'lib', 'datejs', 'globalization', lang.replace('_', '-') + '.js'), 'r') as f: + datejs_locale = f.read() + except IOError: + pass + + #load momentjs locale + momentjs_locale_file = False + momentjs_locale = "" + for code in magic_file_finding: + try: + with open(os.path.join(addons_path, 'web', 'static', 'lib', 'moment', 'locale', code + '.js'), 'r') as f: + momentjs_locale = f.read() + #we found a locale matching so we can exit + break + except IOError: + continue + + #return the content of the locale + headers = [('Content-Type', 'application/javascript'), ('Cache-Control', 'max-age=%s' % (36000))] + return request.make_response(datejs_locale + "\n"+ momentjs_locale, headers) + @http.route('/web/webclient/qweb', type='http', auth="none") def qweb(self, mods=None, db=None): files = [f[0] for f in manifest_glob('qweb', addons=mods, db=db)] diff --git a/addons/web/static/lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css b/addons/web/static/lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css index de9d85e2bac..69ca89a2e5e 100644 --- a/addons/web/static/lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css +++ b/addons/web/static/lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css @@ -1,5 +1,6 @@ /*! * Datetimepicker for Bootstrap v3 +//! version : 3.0.3 * https://github.com/Eonasdan/bootstrap-datetimepicker/ */ .bootstrap-datetimepicker-widget { @@ -110,16 +111,16 @@ line-height: 54px; width: 54px; } -.bootstrap-datetimepicker-widget td.day { - height: 20px; - line-height: 20px; - width: 20px; -} .bootstrap-datetimepicker-widget td.cw { font-size: 10px; height: 20px; line-height: 20px; } +.bootstrap-datetimepicker-widget td.day { + height: 20px; + line-height: 20px; + width: 20px; +} .bootstrap-datetimepicker-widget td.day:hover, .bootstrap-datetimepicker-widget td.hour:hover, .bootstrap-datetimepicker-widget td.minute:hover, @@ -129,7 +130,7 @@ } .bootstrap-datetimepicker-widget td.old, .bootstrap-datetimepicker-widget td.new { - color: #999999; + color: #777777; } .bootstrap-datetimepicker-widget td.today { position: relative; @@ -156,15 +157,14 @@ .bootstrap-datetimepicker-widget td.disabled, .bootstrap-datetimepicker-widget td.disabled:hover { background: none; - color: #999999; + color: #777777; cursor: not-allowed; } .bootstrap-datetimepicker-widget td span { - display: block; + display: inline-block; width: 54px; height: 54px; line-height: 54px; - float: left; margin: 2px 1.5px; cursor: pointer; border-radius: 4px; @@ -178,12 +178,12 @@ text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); } .bootstrap-datetimepicker-widget td span.old { - color: #999999; + color: #777777; } .bootstrap-datetimepicker-widget td span.disabled, .bootstrap-datetimepicker-widget td span.disabled:hover { background: none; - color: #999999; + color: #777777; cursor: not-allowed; } .bootstrap-datetimepicker-widget th { @@ -191,7 +191,7 @@ line-height: 20px; width: 20px; } -.bootstrap-datetimepicker-widget th.switch { +.bootstrap-datetimepicker-widget th.picker-switch { width: 145px; } .bootstrap-datetimepicker-widget th.next, @@ -201,7 +201,7 @@ .bootstrap-datetimepicker-widget th.disabled, .bootstrap-datetimepicker-widget th.disabled:hover { background: none; - color: #999999; + color: #777777; cursor: not-allowed; } .bootstrap-datetimepicker-widget thead tr:first-child th { diff --git a/addons/web/static/lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css b/addons/web/static/lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css deleted file mode 100644 index 8535b639e1a..00000000000 --- a/addons/web/static/lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css +++ /dev/null @@ -1,4 +0,0 @@ -/*! - * Datetimepicker for Bootstrap v3 - * https://github.com/Eonasdan/bootstrap-datetimepicker/ - */.bootstrap-datetimepicker-widget{top:0;left:0;width:250px;padding:4px;margin-top:1px;z-index:99999 !important;border-radius:4px}.bootstrap-datetimepicker-widget.timepicker-sbs{width:600px}.bootstrap-datetimepicker-widget.bottom:before{content:'';display:inline-block;border-left:7px solid transparent;border-right:7px solid transparent;border-bottom:7px solid #ccc;border-bottom-color:rgba(0,0,0,0.2);position:absolute;top:-7px;left:7px}.bootstrap-datetimepicker-widget.bottom:after{content:'';display:inline-block;border-left:6px solid transparent;border-right:6px solid transparent;border-bottom:6px solid #fff;position:absolute;top:-6px;left:8px}.bootstrap-datetimepicker-widget.top:before{content:'';display:inline-block;border-left:7px solid transparent;border-right:7px solid transparent;border-top:7px solid #ccc;border-top-color:rgba(0,0,0,0.2);position:absolute;bottom:-7px;left:6px}.bootstrap-datetimepicker-widget.top:after{content:'';display:inline-block;border-left:6px solid transparent;border-right:6px solid transparent;border-top:6px solid #fff;position:absolute;bottom:-6px;left:7px}.bootstrap-datetimepicker-widget .dow{width:14.2857%}.bootstrap-datetimepicker-widget.pull-right:before{left:auto;right:6px}.bootstrap-datetimepicker-widget.pull-right:after{left:auto;right:7px}.bootstrap-datetimepicker-widget>ul{list-style-type:none;margin:0}.bootstrap-datetimepicker-widget a[data-action]{padding:6px 0}.bootstrap-datetimepicker-widget .timepicker-hour,.bootstrap-datetimepicker-widget .timepicker-minute,.bootstrap-datetimepicker-widget .timepicker-second{width:54px;font-weight:bold;font-size:1.2em;margin:0}.bootstrap-datetimepicker-widget button[data-action]{padding:6px}.bootstrap-datetimepicker-widget table[data-hour-format="12"] .separator{width:4px;padding:0;margin:0}.bootstrap-datetimepicker-widget .datepicker>div{display:none}.bootstrap-datetimepicker-widget .picker-switch{text-align:center}.bootstrap-datetimepicker-widget table{width:100%;margin:0}.bootstrap-datetimepicker-widget td,.bootstrap-datetimepicker-widget th{text-align:center;border-radius:4px}.bootstrap-datetimepicker-widget td{height:54px;line-height:54px;width:54px}.bootstrap-datetimepicker-widget td.day{height:20px;line-height:20px;width:20px}.bootstrap-datetimepicker-widget td.day:hover,.bootstrap-datetimepicker-widget td.hour:hover,.bootstrap-datetimepicker-widget td.minute:hover,.bootstrap-datetimepicker-widget td.second:hover{background:#eee;cursor:pointer}.bootstrap-datetimepicker-widget td.old,.bootstrap-datetimepicker-widget td.new{color:#999}.bootstrap-datetimepicker-widget td.today{position:relative}.bootstrap-datetimepicker-widget td.today:before{content:'';display:inline-block;border-left:7px solid transparent;border-bottom:7px solid #428bca;border-top-color:rgba(0,0,0,0.2);position:absolute;bottom:4px;right:4px}.bootstrap-datetimepicker-widget td.active,.bootstrap-datetimepicker-widget td.active:hover{background-color:#428bca;color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25)}.bootstrap-datetimepicker-widget td.active.today:before{border-bottom-color:#fff}.bootstrap-datetimepicker-widget td.disabled,.bootstrap-datetimepicker-widget td.disabled:hover{background:none;color:#999;cursor:not-allowed}.bootstrap-datetimepicker-widget td span{display:block;width:54px;height:54px;line-height:54px;float:left;margin:2px 1.5px;cursor:pointer;border-radius:4px}.bootstrap-datetimepicker-widget td span:hover{background:#eee}.bootstrap-datetimepicker-widget td span.active{background-color:#428bca;color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,0.25)}.bootstrap-datetimepicker-widget td span.old{color:#999}.bootstrap-datetimepicker-widget td span.disabled,.bootstrap-datetimepicker-widget td span.disabled:hover{background:none;color:#999;cursor:not-allowed}.bootstrap-datetimepicker-widget th{height:20px;line-height:20px;width:20px}.bootstrap-datetimepicker-widget th.switch{width:145px}.bootstrap-datetimepicker-widget th.next,.bootstrap-datetimepicker-widget th.prev{font-size:21px}.bootstrap-datetimepicker-widget th.disabled,.bootstrap-datetimepicker-widget th.disabled:hover{background:none;color:#999;cursor:not-allowed}.bootstrap-datetimepicker-widget thead tr:first-child th{cursor:pointer}.bootstrap-datetimepicker-widget thead tr:first-child th:hover{background:#eee}.input-group.date .input-group-addon span{display:block;cursor:pointer;width:16px;height:16px}.bootstrap-datetimepicker-widget.left-oriented:before{left:auto;right:6px}.bootstrap-datetimepicker-widget.left-oriented:after{left:auto;right:7px}.bootstrap-datetimepicker-widget ul.list-unstyled li div.timepicker div.timepicker-picker table.table-condensed tbody>tr>td{padding:0 !important}@media screen and (max-width:767px){.bootstrap-datetimepicker-widget.timepicker-sbs{width:283px}} \ No newline at end of file diff --git a/addons/web/static/lib/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js b/addons/web/static/lib/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js deleted file mode 100644 index 69194362393..00000000000 --- a/addons/web/static/lib/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js +++ /dev/null @@ -1,105 +0,0 @@ -/* -Version 3.0.0 -========================================================= -bootstrap-datetimepicker.js -https://github.com/Eonasdan/bootstrap-datetimepicker -========================================================= -The MIT License (MIT) - -Copyright (c) 2014 Jonathan Peterson - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ -!function(e){if("function"==typeof define&&define.amd)define(["jquery","moment"],e) -else{if(!jQuery)throw"bootstrap-datetimepicker requires jQuery to be loaded first" -if(!moment)throw"bootstrap-datetimepicker requires moment.js to be loaded first" -e(jQuery,moment)}}(function(e,t){if(void 0===t)throw alert("momentjs is requried"),Error("momentjs is required") -var a=0,o=t,n=function(t,n){var s={pickDate:!0,pickTime:!0,useMinutes:!0,useSeconds:!1,useCurrent:!0,minuteStepping:1,minDate:new o({y:1900}),maxDate:(new o).add(100,"y"),showToday:!0,collapse:!0,language:"en",defaultDate:"",disabledDates:!1,enabledDates:!1,icons:{},useStrict:!1,direction:"auto",sideBySide:!1,daysOfWeekDisabled:!1},d={time:"glyphicon glyphicon-time",date:"glyphicon glyphicon-calendar",up:"glyphicon glyphicon-chevron-up",down:"glyphicon glyphicon-chevron-down"},r=this,c=function(){var i,c=!1 -if(r.options=e.extend({},s,n),r.options.icons=e.extend({},d,r.options.icons),r.element=e(t),l(),!r.options.pickTime&&!r.options.pickDate)throw Error("Must choose at least one picker") -if(r.id=a++,o.lang(r.options.language),r.date=o(),r.unset=!1,r.isInput=r.element.is("input"),r.component=!1,r.element.hasClass("input-group")&&(r.component=r.element.find(0==r.element.find(".datepickerbutton").size()?"[class^='input-group-']":".datepickerbutton")),r.format=r.options.format,i=o()._lang._longDateFormat,r.format||(r.format=r.options.pickDate?i.L:"",r.options.pickDate&&r.options.pickTime&&(r.format+=" "),r.format+=r.options.pickTime?i.LT:"",r.options.useSeconds&&(~i.LT.indexOf(" A")?r.format=r.format.split(" A")[0]+":ss A":r.format+=":ss")),r.use24hours=r.format.toLowerCase().indexOf("a")<1,r.component&&(c=r.component.find("span")),r.options.pickTime&&c&&c.addClass(r.options.icons.time),r.options.pickDate&&c&&(c.removeClass(r.options.icons.time),c.addClass(r.options.icons.date)),r.widget=e(W()).appendTo("body"),r.options.useSeconds&&!r.use24hours&&r.widget.width(300),r.minViewMode=r.options.minViewMode||0,"string"==typeof r.minViewMode)switch(r.minViewMode){case"months":r.minViewMode=1 -break -case"years":r.minViewMode=2 -break -default:r.minViewMode=0}if(r.viewMode=r.options.viewMode||0,"string"==typeof r.viewMode)switch(r.viewMode){case"months":r.viewMode=1 -break -case"years":r.viewMode=2 -break -default:r.viewMode=0}if(r.options.disabledDates=j(r.options.disabledDates),r.options.enabledDates=j(r.options.enabledDates),r.startViewMode=r.viewMode,r.setMinDate(r.options.minDate),r.setMaxDate(r.options.maxDate),g(),w(),k(),b(),y(),h(),P(),V(),""!==r.options.defaultDate&&""==p().val()&&r.setValue(r.options.defaultDate),1!==r.options.minuteStepping){var m=r.options.minuteStepping -r.date.minutes(Math.round(r.date.minutes()/m)*m%60).seconds(0)}},p=function(){return r.isInput?r.element:dateStr=r.element.find("input")},l=function(){var e -e=(r.element.is("input"),r.element.data()),void 0!==e.dateFormat&&(r.options.format=e.dateFormat),void 0!==e.datePickdate&&(r.options.pickDate=e.datePickdate),void 0!==e.datePicktime&&(r.options.pickTime=e.datePicktime),void 0!==e.dateUseminutes&&(r.options.useMinutes=e.dateUseminutes),void 0!==e.dateUseseconds&&(r.options.useSeconds=e.dateUseseconds),void 0!==e.dateUsecurrent&&(r.options.useCurrent=e.dateUsecurrent),void 0!==e.dateMinutestepping&&(r.options.minuteStepping=e.dateMinutestepping),void 0!==e.dateMindate&&(r.options.minDate=e.dateMindate),void 0!==e.dateMaxdate&&(r.options.maxDate=e.dateMaxdate),void 0!==e.dateShowtoday&&(r.options.showToday=e.dateShowtoday),void 0!==e.dateCollapse&&(r.options.collapse=e.dateCollapse),void 0!==e.dateLanguage&&(r.options.language=e.dateLanguage),void 0!==e.dateDefaultdate&&(r.options.defaultDate=e.dateDefaultdate),void 0!==e.dateDisableddates&&(r.options.disabledDates=e.dateDisableddates),void 0!==e.dateEnableddates&&(r.options.enabledDates=e.dateEnableddates),void 0!==e.dateIcons&&(r.options.icons=e.dateIcons),void 0!==e.dateUsestrict&&(r.options.useStrict=e.dateUsestrict),void 0!==e.dateDirection&&(r.options.direction=e.dateDirection),void 0!==e.dateSidebyside&&(r.options.sideBySide=e.dateSidebyside)},m=function(){var t="absolute",i=r.component?r.component.offset():r.element.offset(),a=e(window) -r.width=r.component?r.component.outerWidth():r.element.outerWidth(),i.top=i.top+r.element.outerHeight() -var o -"up"===r.options.direction?o="top":"bottom"===r.options.direction?o="bottom":"auto"===r.options.direction&&(o=i.top+r.widget.height()>a.height()+a.scrollTop()&&r.widget.height()+r.element.outerHeight()"),a=o.weekdaysMin() -if(0==o()._lang._week.dow)for(t=0;7>t;t++)i.append(''+a[t]+"") -else for(t=1;8>t;t++)i.append(7==t?''+a[0]+"":''+a[t]+"") -r.widget.find(".datepicker-days thead").append(i)},w=function(){o.lang(r.options.language) -for(var e="",t=0,i=o.monthsShort();12>t;)e+=''+i[t++]+"" -r.widget.find(".datepicker-months td").append(e)},v=function(){o.lang(r.options.language) -var t,i,a,n,s,d,c,p,l=r.viewDate.year(),m=r.viewDate.month(),u=r.options.minDate.year(),f=r.options.minDate.month(),h=r.options.maxDate.year(),g=r.options.maxDate.month(),w=[],v=o.months() -for(r.widget.find(".datepicker-days").find(".disabled").removeClass("disabled"),r.widget.find(".datepicker-months").find(".disabled").removeClass("disabled"),r.widget.find(".datepicker-years").find(".disabled").removeClass("disabled"),r.widget.find(".datepicker-days th:eq(1)").text(v[m]+" "+l),t=o(r.viewDate).subtract("months",1),d=t.daysInMonth(),t.date(d).startOf("week"),(l==u&&f>=m||u>l)&&r.widget.find(".datepicker-days th:eq(0)").addClass("disabled"),(l==h&&m>=g||l>h)&&r.widget.find(".datepicker-days th:eq(2)").addClass("disabled"),i=o(t).add(42,"d");t.isBefore(i);){if(t.weekday()===o().startOf("week").weekday()&&(a=e(""),w.push(a)),n="",t.year()l||t.year()==l&&t.month()>m)&&(n+=" new"),t.isSame(o({y:r.date.year(),M:r.date.month(),d:r.date.date()}))&&(n+=" active"),(N(t)||!U(t))&&(n+=" disabled"),r.options.showToday===!0&&t.isSame(o(),"day")&&(n+=" today"),r.options.daysOfWeekDisabled)for(s in r.options.daysOfWeekDisabled)if(t.day()==r.options.daysOfWeekDisabled[s]){n+=" disabled" -break}a.append(''+t.date()+""),t.add(1,"d")}for(r.widget.find(".datepicker-days tbody").empty().append(w),p=r.date.year(),v=r.widget.find(".datepicker-months").find("th:eq(1)").text(l).end().find("span").removeClass("active"),p===l&&v.eq(r.date.month()).addClass("active"),u>p-1&&r.widget.find(".datepicker-months th:eq(0)").addClass("disabled"),p+1>h&&r.widget.find(".datepicker-months th:eq(2)").addClass("disabled"),s=0;12>s;s++)l==u&&f>s||u>l?e(v[s]).addClass("disabled"):(l==h&&s>g||l>h)&&e(v[s]).addClass("disabled") -for(w="",l=10*parseInt(l/10,10),c=r.widget.find(".datepicker-years").find("th:eq(1)").text(l+"-"+(l+9)).end().find("td"),r.widget.find(".datepicker-years").find("th").removeClass("disabled"),u>l&&r.widget.find(".datepicker-years").find("th:eq(0)").addClass("disabled"),l+9>h&&r.widget.find(".datepicker-years").find("th:eq(2)").addClass("disabled"),l-=1,s=-1;11>s;s++)w+='l||l>h?" disabled":"")+'">'+l+"",l+=1 -c.html(w)},k=function(){o.lang(r.options.language) -var e,t,i,a=r.widget.find(".timepicker .timepicker-hours table"),n="" -if(a.parent().hide(),r.use24hours)for(e=0,t=0;6>t;t+=1){for(n+="",i=0;4>i;i+=1)n+=''+F(""+e)+"",e++ -n+=""}else for(e=1,t=0;3>t;t+=1){for(n+="",i=0;4>i;i+=1)n+=''+F(""+e)+"",e++ -n+=""}a.html(n)},b=function(){var e,t,i=r.widget.find(".timepicker .timepicker-minutes table"),a="",o=0,n=r.options.minuteStepping -for(i.parent().hide(),1==n&&(n=5),e=0;et;t+=1)60>o?(a+=''+F(""+o)+"",o+=n):a+="" -a+=""}i.html(a)},y=function(){var e,t,i=r.widget.find(".timepicker .timepicker-seconds table"),a="",o=0 -for(i.parent().hide(),e=0;3>e;e++){for(a+="",t=0;4>t;t+=1)a+=''+F(""+o)+"",o+=5 -a+=""}i.html(a)},D=function(){if(r.date){var e=r.widget.find(".timepicker span[data-time-component]"),t=r.date.hours(),i="AM" -r.use24hours||(t>=12&&(i="PM"),0===t?t=12:12!=t&&(t%=12),r.widget.find(".timepicker [data-action=togglePeriod]").text(i)),e.filter("[data-time-component=hours]").text(F(t)),e.filter("[data-time-component=minutes]").text(F(r.date.minutes())),e.filter("[data-time-component=seconds]").text(F(r.date.second()))}},M=function(t){t.stopPropagation(),t.preventDefault(),r.unset=!1 -var i,a,n,s,d=e(t.target).closest("span, td, th"),c=o(r.date) -if(1===d.length&&!d.is(".disabled"))switch(d[0].nodeName.toLowerCase()){case"th":switch(d[0].className){case"switch":P(1) -break -case"prev":case"next":n=B.modes[r.viewMode].navStep,"prev"===d[0].className&&(n=-1*n),r.viewDate.add(n,B.modes[r.viewMode].navFnc),v()}break -case"span":d.is(".month")?(i=d.parent().find("span").index(d),r.viewDate.month(i)):(a=parseInt(d.text(),10)||0,r.viewDate.year(a)),r.viewMode===r.minViewMode&&(r.date=o({y:r.viewDate.year(),M:r.viewDate.month(),d:r.viewDate.date(),h:r.date.hours(),m:r.date.minutes(),s:r.date.seconds()}),u(c,t.type),O()),P(-1),v() -break -case"td":d.is(".day")&&(s=parseInt(d.text(),10)||1,i=r.viewDate.month(),a=r.viewDate.year(),d.is(".old")?0===i?(i=11,a-=1):i-=1:d.is(".new")&&(11==i?(i=0,a+=1):i+=1),r.date=o({y:a,M:i,d:s,h:r.date.hours(),m:r.date.minutes(),s:r.date.seconds()}),r.viewDate=o({y:a,M:i,d:Math.min(28,s)}),v(),O(),u(c,t.type))}},x={incrementHours:function(){L("add","hours",1)},incrementMinutes:function(){L("add","minutes",r.options.minuteStepping)},incrementSeconds:function(){L("add","seconds",1)},decrementHours:function(){L("subtract","hours",1)},decrementMinutes:function(){L("subtract","minutes",r.options.minuteStepping)},decrementSeconds:function(){L("subtract","seconds",1)},togglePeriod:function(){var e=r.date.hours() -e>=12?e-=12:e+=12,r.date.hours(e)},showPicker:function(){r.widget.find(".timepicker > div:not(.timepicker-picker)").hide(),r.widget.find(".timepicker .timepicker-picker").show()},showHours:function(){r.widget.find(".timepicker .timepicker-picker").hide(),r.widget.find(".timepicker .timepicker-hours").show()},showMinutes:function(){r.widget.find(".timepicker .timepicker-picker").hide(),r.widget.find(".timepicker .timepicker-minutes").show()},showSeconds:function(){r.widget.find(".timepicker .timepicker-picker").hide(),r.widget.find(".timepicker .timepicker-seconds").show()},selectHour:function(t){var i=r.widget.find(".timepicker [data-action=togglePeriod]").text(),a=parseInt(e(t.target).text(),10) -"PM"==i&&(a+=12),r.date.hours(a),x.showPicker.call(r)},selectMinute:function(t){r.date.minutes(parseInt(e(t.target).text(),10)),x.showPicker.call(r)},selectSecond:function(t){r.date.seconds(parseInt(e(t.target).text(),10)),x.showPicker.call(r)}},S=function(t){var i=o(r.date),a=e(t.currentTarget).data("action"),n=x[a].apply(r,arguments) -return T(t),r.date||(r.date=o({y:1970})),O(),D(),u(i,t.type),n},T=function(e){e.stopPropagation(),e.preventDefault()},C=function(t){o.lang(r.options.language) -var i=e(t.target),a=o(r.date),n=o(i.val(),r.format,r.options.useStrict) -n.isValid()&&!N(n)&&U(n)?(h(),r.setValue(n),u(a,t.type),O()):(r.viewDate=a,u(a,t.type),f(n),r.unset=!0)},P=function(e){e&&(r.viewMode=Math.max(r.minViewMode,Math.min(2,r.viewMode+e))) -B.modes[r.viewMode].clsName -r.widget.find(".datepicker > div").hide().filter(".datepicker-"+B.modes[r.viewMode].clsName).show()},V=function(){var t,i,a,o,n -r.widget.on("click",".datepicker *",e.proxy(M,this)),r.widget.on("click","[data-action]",e.proxy(S,this)),r.widget.on("mousedown",e.proxy(T,this)),r.options.pickDate&&r.options.pickTime&&r.widget.on("click.togglePicker",".accordion-toggle",function(s){if(s.stopPropagation(),t=e(this),i=t.closest("ul"),a=i.find(".in"),o=i.find(".collapse:not(.in)"),a&&a.length){if(n=a.data("collapse"),n&&n.date-transitioning)return -a.collapse("hide"),o.collapse("show"),t.find("span").toggleClass(r.options.icons.time+" "+r.options.icons.date),r.element.find(".input-group-addon span").toggleClass(r.options.icons.time+" "+r.options.icons.date)}}),r.isInput?r.element.on({focus:e.proxy(r.show,this),change:e.proxy(C,this),blur:e.proxy(r.hide,this)}):(r.element.on({change:e.proxy(C,this)},"input"),r.component?r.component.on("click",e.proxy(r.show,this)):r.element.on("click",e.proxy(r.show,this)))},q=function(){e(window).on("resize.datetimepicker"+r.id,e.proxy(m,this)),r.isInput||e(document).on("mousedown.datetimepicker"+r.id,e.proxy(r.hide,this))},I=function(){r.widget.off("click",".datepicker *",r.click),r.widget.off("click","[data-action]"),r.widget.off("mousedown",r.stopEvent),r.options.pickDate&&r.options.pickTime&&r.widget.off("click.togglePicker"),r.isInput?r.element.off({focus:r.show,change:r.change}):(r.element.off({change:r.change},"input"),r.component?r.component.off("click",r.show):r.element.off("click",r.show))},H=function(){e(window).off("resize.datetimepicker"+r.id),r.isInput||e(document).off("mousedown.datetimepicker"+r.id)},Y=function(){if(r.element){var t,i=r.element.parents(),a=!1 -for(t=0;t0?t:!1},F=function(e){return e=""+e,e.length>=2?e:"0"+e},W=function(){if(r.options.pickDate&&r.options.pickTime){var e="" -return e='
',e+=r.options.sideBySide?'
'+B.template+'
'+E.getTemplate()+"
":'
    '+B.template+'
  • '+E.getTemplate()+"
",e+="
"}return r.options.pickTime?'":'"},B={modes:[{clsName:"days",navFnc:"month",navStep:1},{clsName:"months",navFnc:"year",navStep:1},{clsName:"years",navFnc:"year",navStep:10}],headTemplate:'‹›',contTemplate:''},E={hourTemplate:'',minuteTemplate:'',secondTemplate:''} -B.template='
'+B.headTemplate+'
'+B.headTemplate+B.contTemplate+'
'+B.headTemplate+B.contTemplate+"
",E.getTemplate=function(){return'
"+(r.options.useSeconds?'':"")+(r.use24hours?"":'')+" "+(r.options.useSeconds?'":"")+(r.use24hours?"":'')+'"+(r.options.useSeconds?'':"")+(r.use24hours?"":'')+'
'+(r.options.useMinutes?'':"")+"
"+E.hourTemplate+' :'+(r.options.useMinutes?E.minuteTemplate:'00')+":'+E.secondTemplate+"
'+(r.options.useMinutes?'':"")+"
'+(r.options.useSeconds?'
':"")},r.destroy=function(){I(),H(),r.widget.remove(),r.element.removeData("DateTimePicker"),r.component&&r.component.removeData("DateTimePicker")},r.show=function(e){if(r.options.useCurrent&&""==p().val())if(1!==r.options.minuteStepping){var t=o(),i=r.options.minuteStepping -t.minutes(Math.round(t.minutes()/i)*i%60).seconds(0),r.setValue(t.format(r.format))}else r.setValue(o().format(r.format)) -r.widget.show(),r.height=r.component?r.component.outerHeight():r.element.outerHeight(),m(),r.element.trigger({type:"dp.show",date:o(r.date)}),q(),e&&T(e)},r.disable=function(){var e=r.element.find("input") -e.prop("disabled")||(e.prop("disabled",!0),I())},r.enable=function(){var e=r.element.find("input") -e.prop("disabled")&&(e.prop("disabled",!1),V())},r.hide=function(t){if(!t||!e(t.target).is(r.element.attr("id"))){var i,a,n=r.widget.find(".collapse") -for(i=0;i $window.height() + $window.scrollTop() && picker.widget.height() + picker.element.outerHeight() < offset.top) { placePosition = 'top'; } else { placePosition = 'bottom'; } - }; + } if (placePosition === 'top') { offset.top -= picker.widget.height() + picker.element.outerHeight() + 15; picker.widget.addClass('top').removeClass('bottom'); @@ -276,72 +347,80 @@ THE SOFTWARE. }, notifyChange = function (oldDate, eventType) { - if (pMoment(picker.date).isSame(pMoment(oldDate))) return; + if (moment(picker.date).isSame(moment(oldDate))) { + return; + } picker.element.trigger({ type: 'dp.change', - date: pMoment(picker.date), - oldDate: pMoment(oldDate) + date: moment(picker.date), + oldDate: moment(oldDate) }); - if (eventType !== 'change') + if (eventType !== 'change') { picker.element.change(); + } }, - notifyError = function (date) { - picker.element.trigger({ - type: 'dp.error', - date: pMoment(date) - }); - }, + notifyError = function (date) { + picker.element.trigger({ + type: 'dp.error', + date: moment(date, picker.format, picker.options.useStrict) + }); + }, update = function (newDate) { - pMoment.lang(picker.options.language); + moment.locale(picker.options.language); var dateStr = newDate; if (!dateStr) { dateStr = getPickerInput().val(); - if (dateStr) picker.date = pMoment(dateStr, picker.format, picker.options.useStrict); - if (!picker.date) picker.date = pMoment(); + if (dateStr) { + picker.date = moment(dateStr, picker.format, picker.options.useStrict); + } + if (!picker.date) { + picker.date = moment(); + } } - picker.viewDate = pMoment(picker.date).startOf("month"); + picker.viewDate = moment(picker.date).startOf('month'); fillDate(); fillTime(); }, - fillDow = function () { - pMoment.lang(picker.options.language); - var html = $(''), weekdaysMin = pMoment.weekdaysMin(), i; - if (picker.options.calendarWeeks === true){ - html.append(' '); + fillDow = function () { + moment.locale(picker.options.language); + var html = $(''), weekdaysMin = moment.weekdaysMin(), i; + if (picker.options.calendarWeeks === true) { + html.append('#'); } - // - if (pMoment()._lang._week.dow == 0) { // starts on Sunday - for (i = 0; i < 7; i++) { - html.append('' + weekdaysMin[i] + ''); - } - } else { - for (i = 1; i < 8; i++) { - if (i == 7) { - html.append('' + weekdaysMin[0] + ''); - } else { - html.append('' + weekdaysMin[i] + ''); - } - } - } - picker.widget.find('.datepicker-days thead').append(html); - }, + if (moment().localeData()._week.dow === 0) { // starts on Sunday + for (i = 0; i < 7; i++) { + html.append('' + weekdaysMin[i] + ''); + } + } else { + for (i = 1; i < 8; i++) { + if (i === 7) { + html.append('' + weekdaysMin[0] + ''); + } else { + html.append('' + weekdaysMin[i] + ''); + } + } + } + picker.widget.find('.datepicker-days thead').append(html); + }, fillMonths = function () { - pMoment.lang(picker.options.language); - var html = '', i = 0, monthsShort = pMoment.monthsShort(); - while (i < 12) { - html += '' + monthsShort[i++] + ''; + moment.locale(picker.options.language); + var html = '', i, monthsShort = moment.monthsShort(); + for (i = 0; i < 12; i++) { + html += '' + monthsShort[i] + ''; } picker.widget.find('.datepicker-months td').append(html); }, fillDate = function () { - if(!picker.options.pickDate) return; - pMoment.lang(picker.options.language); + if (!picker.options.pickDate) { + return; + } + moment.locale(picker.options.language); var year = picker.viewDate.year(), month = picker.viewDate.month(), startYear = picker.options.minDate.year(), @@ -349,7 +428,7 @@ THE SOFTWARE. endYear = picker.options.maxDate.year(), endMonth = picker.options.maxDate.month(), currentDate, - prevMonth, nextMonth, html = [], row, clsName, i, days, yearCont, currentYear, months = pMoment.months(); + prevMonth, nextMonth, html = [], row, clsName, i, days, yearCont, currentYear, months = moment.months(); picker.widget.find('.datepicker-days').find('.disabled').removeClass('disabled'); picker.widget.find('.datepicker-months').find('.disabled').removeClass('disabled'); @@ -358,45 +437,45 @@ THE SOFTWARE. picker.widget.find('.datepicker-days th:eq(1)').text( months[month] + ' ' + year); - prevMonth = pMoment(picker.viewDate).subtract("months", 1); + prevMonth = moment(picker.viewDate, picker.format, picker.options.useStrict).subtract(1, 'months'); days = prevMonth.daysInMonth(); prevMonth.date(days).startOf('week'); - if ((year == startYear && month <= startMonth) || year < startYear) { + if ((year === startYear && month <= startMonth) || year < startYear) { picker.widget.find('.datepicker-days th:eq(0)').addClass('disabled'); } - if ((year == endYear && month >= endMonth) || year > endYear) { + if ((year === endYear && month >= endMonth) || year > endYear) { picker.widget.find('.datepicker-days th:eq(2)').addClass('disabled'); } - nextMonth = pMoment(prevMonth).add(42, "d"); + nextMonth = moment(prevMonth).add(42, 'd'); while (prevMonth.isBefore(nextMonth)) { - if (prevMonth.weekday() === pMoment().startOf('week').weekday()) { + if (prevMonth.weekday() === moment().startOf('week').weekday()) { row = $(''); html.push(row); - if (picker.options.calendarWeeks === true){ - row.append(''+prevMonth.week()+''); + if (picker.options.calendarWeeks === true) { + row.append('' + prevMonth.week() + ''); } } clsName = ''; - if (prevMonth.year() < year || (prevMonth.year() == year && prevMonth.month() < month)) { + if (prevMonth.year() < year || (prevMonth.year() === year && prevMonth.month() < month)) { clsName += ' old'; - } else if (prevMonth.year() > year || (prevMonth.year() == year && prevMonth.month() > month)) { + } else if (prevMonth.year() > year || (prevMonth.year() === year && prevMonth.month() > month)) { clsName += ' new'; } - if (prevMonth.isSame(pMoment({ y: picker.date.year(), M: picker.date.month(), d: picker.date.date() }))) { + if (prevMonth.isSame(moment({y: picker.date.year(), M: picker.date.month(), d: picker.date.date()}))) { clsName += ' active'; } - if (isInDisableDates(prevMonth) || !isInEnableDates(prevMonth)) { + if (isInDisableDates(prevMonth, 'day') || !isInEnableDates(prevMonth)) { clsName += ' disabled'; } if (picker.options.showToday === true) { - if (prevMonth.isSame(pMoment(), 'day')) { + if (prevMonth.isSame(moment(), 'day')) { clsName += ' today'; } } if (picker.options.daysOfWeekDisabled) { - for (i in picker.options.daysOfWeekDisabled) { - if (prevMonth.day() == picker.options.daysOfWeekDisabled[i]) { + for (i = 0; i < picker.options.daysOfWeekDisabled.length; i++) { + if (prevMonth.day() === picker.options.daysOfWeekDisabled[i]) { clsName += ' disabled'; break; } @@ -405,28 +484,28 @@ THE SOFTWARE. row.append('' + prevMonth.date() + ''); currentDate = prevMonth.date(); - prevMonth.add(1, "d"); + prevMonth.add(1, 'd'); - if (currentDate == prevMonth.date()) { - prevMonth.add(1, "d"); + if (currentDate === prevMonth.date()) { + prevMonth.add(1, 'd'); } } picker.widget.find('.datepicker-days tbody').empty().append(html); - currentYear = picker.date.year(), months = picker.widget.find('.datepicker-months') - .find('th:eq(1)').text(year).end().find('span').removeClass('active'); + currentYear = picker.date.year(); + months = picker.widget.find('.datepicker-months').find('th:eq(1)').text(year).end().find('span').removeClass('active'); if (currentYear === year) { months.eq(picker.date.month()).addClass('active'); } - if (currentYear - 1 < startYear) { + if (year - 1 < startYear) { picker.widget.find('.datepicker-months th:eq(0)').addClass('disabled'); } - if (currentYear + 1 > endYear) { + if (year + 1 > endYear) { picker.widget.find('.datepicker-months th:eq(2)').addClass('disabled'); } for (i = 0; i < 12; i++) { - if ((year == startYear && startMonth > i) || (year < startYear)) { + if ((year === startYear && startMonth > i) || (year < startYear)) { $(months[i]).addClass('disabled'); - } else if ((year == endYear && endMonth < i) || (year > endYear)) { + } else if ((year === endYear && endMonth < i) || (year > endYear)) { $(months[i]).addClass('disabled'); } } @@ -434,7 +513,7 @@ THE SOFTWARE. html = ''; year = parseInt(year / 10, 10) * 10; yearCont = picker.widget.find('.datepicker-years').find( - 'th:eq(1)').text(year + '-' + (year + 9)).end().find('td'); + 'th:eq(1)').text(year + '-' + (year + 9)).parents('table').find('td'); picker.widget.find('.datepicker-years').find('th').removeClass('disabled'); if (startYear > year) { picker.widget.find('.datepicker-years').find('th:eq(0)').addClass('disabled'); @@ -451,7 +530,7 @@ THE SOFTWARE. }, fillHours = function () { - pMoment.lang(picker.options.language); + moment.locale(picker.options.language); var table = picker.widget.find('.timepicker .timepicker-hours table'), html = '', current, i, j; table.parent().hide(); if (picker.use24hours) { @@ -482,7 +561,9 @@ THE SOFTWARE. fillMinutes = function () { var table = picker.widget.find('.timepicker .timepicker-minutes table'), html = '', current = 0, i, j, step = picker.options.minuteStepping; table.parent().hide(); - if (step == 1) step = 5; + if (step === 1) { + step = 5; + } for (i = 0; i < Math.ceil(60 / step / 4) ; i++) { html += ''; for (j = 0; j < 4; j += 1) { @@ -513,14 +594,18 @@ THE SOFTWARE. }, fillTime = function () { - if (!picker.date) return; + if (!picker.date) { + return; + } var timeComponents = picker.widget.find('.timepicker span[data-time-component]'), - hour = picker.date.hours(), - period = 'AM'; + hour = picker.date.hours(), + period = picker.date.format('A'); if (!picker.use24hours) { - if (hour >= 12) period = 'PM'; - if (hour === 0) hour = 12; - else if (hour != 12) hour = hour % 12; + if (hour === 0) { + hour = 12; + } else if (hour !== 12) { + hour = hour % 12; + } picker.widget.find('.timepicker [data-action=togglePeriod]').text(period); } timeComponents.filter('[data-time-component=hours]').text(padLeft(hour)); @@ -532,19 +617,21 @@ THE SOFTWARE. e.stopPropagation(); e.preventDefault(); picker.unset = false; - var target = $(e.target).closest('span, td, th'), month, year, step, day, oldDate = pMoment(picker.date); + var target = $(e.target).closest('span, td, th'), month, year, step, day, oldDate = moment(picker.date); if (target.length === 1) { if (!target.is('.disabled')) { switch (target[0].nodeName.toLowerCase()) { case 'th': switch (target[0].className) { - case 'switch': + case 'picker-switch': showMode(1); break; case 'prev': case 'next': step = dpGlobal.modes[picker.viewMode].navStep; - if (target[0].className === 'prev') step = step * -1; + if (target[0].className === 'prev') { + step = step * -1; + } picker.viewDate.add(step, dpGlobal.modes[picker.viewMode].navFnc); fillDate(); break; @@ -559,7 +646,7 @@ THE SOFTWARE. picker.viewDate.year(year); } if (picker.viewMode === picker.minViewMode) { - picker.date = pMoment({ + picker.date = moment({ y: picker.viewDate.year(), M: picker.viewDate.month(), d: picker.viewDate.date(), @@ -567,8 +654,8 @@ THE SOFTWARE. m: picker.date.minutes(), s: picker.date.seconds() }); - notifyChange(oldDate, e.type); set(); + notifyChange(oldDate, e.type); } showMode(-1); fillDate(); @@ -586,14 +673,14 @@ THE SOFTWARE. month -= 1; } } else if (target.is('.new')) { - if (month == 11) { + if (month === 11) { month = 0; year += 1; } else { month += 1; } } - picker.date = pMoment({ + picker.date = moment({ y: year, M: month, d: day, @@ -602,7 +689,7 @@ THE SOFTWARE. s: picker.date.seconds() } ); - picker.viewDate = pMoment({ + picker.viewDate = moment({ y: year, M: month, d: Math.min(28, day) }); fillDate(); @@ -615,94 +702,117 @@ THE SOFTWARE. } }, - actions = { - incrementHours: function () { - checkDate("add", "hours", 1); - }, + actions = { + incrementHours: function () { + checkDate('add', 'hours', 1); + }, - incrementMinutes: function () { - checkDate("add", "minutes", picker.options.minuteStepping); - }, + incrementMinutes: function () { + checkDate('add', 'minutes', picker.options.minuteStepping); + }, - incrementSeconds: function () { - checkDate("add", "seconds", 1); - }, + incrementSeconds: function () { + checkDate('add', 'seconds', 1); + }, - decrementHours: function () { - checkDate("subtract", "hours", 1); - }, + decrementHours: function () { + checkDate('subtract', 'hours', 1); + }, - decrementMinutes: function () { - checkDate("subtract", "minutes", picker.options.minuteStepping); - }, + decrementMinutes: function () { + checkDate('subtract', 'minutes', picker.options.minuteStepping); + }, - decrementSeconds: function () { - checkDate("subtract", "seconds", 1); - }, + decrementSeconds: function () { + checkDate('subtract', 'seconds', 1); + }, - togglePeriod: function () { - var hour = picker.date.hours(); - if (hour >= 12) hour -= 12; - else hour += 12; - picker.date.hours(hour); - }, + togglePeriod: function () { + var hour = picker.date.hours(); + if (hour >= 12) { + hour -= 12; + } else { + hour += 12; + } + picker.date.hours(hour); + }, - showPicker: function () { - picker.widget.find('.timepicker > div:not(.timepicker-picker)').hide(); - picker.widget.find('.timepicker .timepicker-picker').show(); - }, + showPicker: function () { + picker.widget.find('.timepicker > div:not(.timepicker-picker)').hide(); + picker.widget.find('.timepicker .timepicker-picker').show(); + }, - showHours: function () { - picker.widget.find('.timepicker .timepicker-picker').hide(); - picker.widget.find('.timepicker .timepicker-hours').show(); - }, + showHours: function () { + picker.widget.find('.timepicker .timepicker-picker').hide(); + picker.widget.find('.timepicker .timepicker-hours').show(); + }, - showMinutes: function () { - picker.widget.find('.timepicker .timepicker-picker').hide(); - picker.widget.find('.timepicker .timepicker-minutes').show(); - }, + showMinutes: function () { + picker.widget.find('.timepicker .timepicker-picker').hide(); + picker.widget.find('.timepicker .timepicker-minutes').show(); + }, - showSeconds: function () { - picker.widget.find('.timepicker .timepicker-picker').hide(); - picker.widget.find('.timepicker .timepicker-seconds').show(); - }, + showSeconds: function () { + picker.widget.find('.timepicker .timepicker-picker').hide(); + picker.widget.find('.timepicker .timepicker-seconds').show(); + }, - selectHour: function (e) { - var period = picker.widget.find('.timepicker [data-action=togglePeriod]').text(), hour = parseInt($(e.target).text(), 10); - if (period == "PM") hour += 12 - picker.date.hours(hour); - actions.showPicker.call(picker); - }, + selectHour: function (e) { + var hour = parseInt($(e.target).text(), 10); + if (!picker.use24hours) { + if (picker.date.hours() >= 12) { + if (hour !== 12) { + hour += 12; + } + } else { + if (hour === 12) { + hour = 0; + } + } + } + picker.date.hours(hour); + actions.showPicker.call(picker); + }, - selectMinute: function (e) { - picker.date.minutes(parseInt($(e.target).text(), 10)); - actions.showPicker.call(picker); - }, + selectMinute: function (e) { + picker.date.minutes(parseInt($(e.target).text(), 10)); + actions.showPicker.call(picker); + }, - selectSecond: function (e) { - picker.date.seconds(parseInt($(e.target).text(), 10)); - actions.showPicker.call(picker); - } - }, + selectSecond: function (e) { + picker.date.seconds(parseInt($(e.target).text(), 10)); + actions.showPicker.call(picker); + } + }, - doAction = function (e) { - var oldDate = pMoment(picker.date), action = $(e.currentTarget).data('action'), rv = actions[action].apply(picker, arguments); - stopEvent(e); - if (!picker.date) picker.date = pMoment({ y: 1970 }); - set(); - fillTime(); - notifyChange(oldDate, e.type); - return rv; - }, + doAction = function (e) { + var oldDate = moment(picker.date), + action = $(e.currentTarget).data('action'), + rv = actions[action].apply(picker, arguments); + stopEvent(e); + if (!picker.date) { + picker.date = moment({y: 1970}); + } + set(); + fillTime(); + notifyChange(oldDate, e.type); + return rv; + }, stopEvent = function (e) { e.stopPropagation(); e.preventDefault(); }, + keydown = function (e) { + if (e.keyCode === 27) { // allow escape to hide picker + picker.hide(); + } + }, + change = function (e) { - pMoment.lang(picker.options.language); - var input = $(e.target), oldDate = pMoment(picker.date), newDate = pMoment(input.val(), picker.format, picker.options.useStrict); + moment.locale(picker.options.language); + var input = $(e.target), oldDate = moment(picker.date), newDate = moment(input.val(), picker.format, picker.options.useStrict); if (newDate.isValid() && !isInDisableDates(newDate) && isInEnableDates(newDate)) { update(); picker.setValue(newDate); @@ -711,9 +821,9 @@ THE SOFTWARE. } else { picker.viewDate = oldDate; + picker.unset = true; notifyChange(oldDate, e.type); notifyError(newDate); - picker.unset = true; } }, @@ -721,7 +831,6 @@ THE SOFTWARE. if (dir) { picker.viewMode = Math.max(picker.minViewMode, Math.min(2, picker.viewMode + dir)); } - var f = dpGlobal.modes[picker.viewMode].clsName; picker.widget.find('.datepicker > div').hide().filter('.datepicker-' + dpGlobal.modes[picker.viewMode].clsName).show(); }, @@ -730,6 +839,7 @@ THE SOFTWARE. picker.widget.on('click', '.datepicker *', $.proxy(click, this)); // this handles date picker clicks picker.widget.on('click', '[data-action]', $.proxy(doAction, this)); // this handles time picker clicks picker.widget.on('mousedown', $.proxy(stopEvent, this)); + picker.element.on('keydown', $.proxy(keydown, this)); if (picker.options.pickDate && picker.options.pickTime) { picker.widget.on('click.togglePicker', '.accordion-toggle', function (e) { e.stopPropagation(); @@ -740,16 +850,21 @@ THE SOFTWARE. if (expanded && expanded.length) { collapseData = expanded.data('collapse'); - if (collapseData && collapseData.date - transitioning) return; + if (collapseData && collapseData.transitioning) { + return; + } expanded.collapse('hide'); closed.collapse('show'); $this.find('span').toggleClass(picker.options.icons.time + ' ' + picker.options.icons.date); - picker.element.find('.input-group-addon span').toggleClass(picker.options.icons.time + ' ' + picker.options.icons.date); + if (picker.component) { + picker.component.find('span').toggleClass(picker.options.icons.time + ' ' + picker.options.icons.date); + } } }); } if (picker.isInput) { picker.element.on({ + 'click': $.proxy(picker.show, this), 'focus': $.proxy(picker.show, this), 'change': $.proxy(change, this), 'blur': $.proxy(picker.hide, this) @@ -760,6 +875,7 @@ THE SOFTWARE. }, 'input'); if (picker.component) { picker.component.on('click', $.proxy(picker.show, this)); + picker.component.on('mousedown', $.proxy(stopEvent, this)); } else { picker.element.on('click', $.proxy(picker.show, this)); } @@ -785,7 +901,9 @@ THE SOFTWARE. if (picker.isInput) { picker.element.off({ 'focus': picker.show, - 'change': picker.change + 'change': picker.change, + 'click': picker.show, + 'blur' : picker.hide }); } else { picker.element.off({ @@ -793,6 +911,7 @@ THE SOFTWARE. }, 'input'); if (picker.component) { picker.component.off('click', picker.show); + picker.component.off('mousedown', picker.stopEvent); } else { picker.element.off('click', picker.show); } @@ -810,12 +929,11 @@ THE SOFTWARE. if (picker.element) { var parents = picker.element.parents(), inFixed = false, i; for (i = 0; i < parents.length; i++) { - if ($(parents[i]).css('position') == 'fixed') { + if ($(parents[i]).css('position') === 'fixed') { inFixed = true; break; } } - ; return inFixed; } else { return false; @@ -823,65 +941,84 @@ THE SOFTWARE. }, set = function () { - pMoment.lang(picker.options.language); - var formatted = '', input; - if (!picker.unset) formatted = pMoment(picker.date).format(picker.format); + moment.locale(picker.options.language); + var formatted = ''; + if (!picker.unset) { + formatted = moment(picker.date).format(picker.format); + } getPickerInput().val(formatted); picker.element.data('date', formatted); - if (!picker.options.pickTime) picker.hide(); + if (!picker.options.pickTime) { + picker.hide(); + } }, - checkDate = function (direction, unit, amount) { - pMoment.lang(picker.options.language); - var newDate; - if (direction == "add") { - newDate = pMoment(picker.date); - if (newDate.hours() == 23) newDate.add(amount, unit); - newDate.add(amount, unit); - } - else { - newDate = pMoment(picker.date).subtract(amount, unit); - } - if (isInDisableDates(pMoment(newDate.subtract(amount, unit))) || isInDisableDates(newDate)) { - notifyError(newDate.format(picker.format)); - return; - } + checkDate = function (direction, unit, amount) { + moment.locale(picker.options.language); + var newDate; + if (direction === 'add') { + newDate = moment(picker.date); + if (newDate.hours() === 23) { + newDate.add(amount, unit); + } + newDate.add(amount, unit); + } + else { + newDate = moment(picker.date).subtract(amount, unit); + } + if (isInDisableDates(moment(newDate.subtract(amount, unit))) || isInDisableDates(newDate)) { + notifyError(newDate.format(picker.format)); + return; + } - if (direction == "add") { - picker.date.add(amount, unit); - } - else { - picker.date.subtract(amount, unit); - } - picker.unset = false; - }, + if (direction === 'add') { + picker.date.add(amount, unit); + } + else { + picker.date.subtract(amount, unit); + } + picker.unset = false; + }, - isInDisableDates = function (date) { - pMoment.lang(picker.options.language); - if (date.isAfter(picker.options.maxDate) || date.isBefore(picker.options.minDate)) return true; + isInDisableDates = function (date, timeUnit) { + moment.locale(picker.options.language); + var maxDate = moment(picker.options.maxDate, picker.format, picker.options.useStrict), + minDate = moment(picker.options.minDate, picker.format, picker.options.useStrict); + + if (timeUnit) { + maxDate = maxDate.endOf(timeUnit); + minDate = minDate.startOf(timeUnit); + } + + if (date.isAfter(maxDate) || date.isBefore(minDate)) { + return true; + } if (picker.options.disabledDates === false) { return false; } - return picker.options.disabledDates[pMoment(date).format("YYYY-MM-DD")] === true; + return picker.options.disabledDates[date.format('YYYY-MM-DD')] === true; }, isInEnableDates = function (date) { - pMoment.lang(picker.options.language); + moment.locale(picker.options.language); if (picker.options.enabledDates === false) { return true; } - return picker.options.enabledDates[pMoment(date).format("YYYY-MM-DD")] === true; + return picker.options.enabledDates[date.format('YYYY-MM-DD')] === true; }, indexGivenDates = function (givenDatesArray) { // Store given enabledDates and disabledDates as keys. // This way we can check their existence in O(1) time instead of looping through whole array. // (for example: picker.options.enabledDates['2014-02-27'] === true) - var givenDatesIndexed = {}; - var givenDatesCount = 0; + var givenDatesIndexed = {}, givenDatesCount = 0, i; for (i = 0; i < givenDatesArray.length; i++) { - dDate = pMoment(givenDatesArray[i]); + if (moment.isMoment(givenDatesArray[i]) || givenDatesArray[i] instanceof Date) { + dDate = moment(givenDatesArray[i]); + } else { + dDate = moment(givenDatesArray[i], picker.format, picker.options.useStrict); + } if (dDate.isValid()) { - givenDatesIndexed[dDate.format("YYYY-MM-DD")] = true; + givenDatesIndexed[dDate.format('YYYY-MM-DD')] = true; givenDatesCount++; } } @@ -893,14 +1030,16 @@ THE SOFTWARE. padLeft = function (string) { string = string.toString(); - if (string.length >= 2) return string; - else return '0' + string; + if (string.length >= 2) { + return string; + } + return '0' + string; }, getTemplate = function () { if (picker.options.pickDate && picker.options.pickTime) { var ret = ''; - ret = '