bootstrap-datepicker.js 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058
  1. /* =========================================================
  2. * bootstrap-datepicker.js
  3. * Repo: https://github.com/uxsolutions/bootstrap-datepicker/
  4. * Demo: https://uxsolutions.github.io/bootstrap-datepicker/
  5. * Docs: https://bootstrap-datepicker.readthedocs.org/
  6. * =========================================================
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * https://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * ========================================================= */
  19. (function(factory){
  20. if (typeof define === 'function' && define.amd) {
  21. define(['jquery'], factory);
  22. } else if (typeof exports === 'object') {
  23. factory(require('jquery'));
  24. } else {
  25. factory(jQuery);
  26. }
  27. }(function($, undefined){
  28. function UTCDate(){
  29. return new Date(Date.UTC.apply(Date, arguments));
  30. }
  31. function UTCToday(){
  32. var today = new Date();
  33. return UTCDate(today.getFullYear(), today.getMonth(), today.getDate());
  34. }
  35. function isUTCEquals(date1, date2) {
  36. return (
  37. date1.getUTCFullYear() === date2.getUTCFullYear() &&
  38. date1.getUTCMonth() === date2.getUTCMonth() &&
  39. date1.getUTCDate() === date2.getUTCDate()
  40. );
  41. }
  42. function alias(method, deprecationMsg){
  43. return function(){
  44. if (deprecationMsg !== undefined) {
  45. $.fn.datepicker.deprecated(deprecationMsg);
  46. }
  47. return this[method].apply(this, arguments);
  48. };
  49. }
  50. function isValidDate(d) {
  51. return d && !isNaN(d.getTime());
  52. }
  53. var DateArray = (function(){
  54. var extras = {
  55. get: function(i){
  56. return this.slice(i)[0];
  57. },
  58. contains: function(d){
  59. // Array.indexOf is not cross-browser;
  60. // $.inArray doesn't work with Dates
  61. var val = d && d.valueOf();
  62. for (var i=0, l=this.length; i < l; i++)
  63. // Use date arithmetic to allow dates with different times to match
  64. if (0 <= this[i].valueOf() - val && this[i].valueOf() - val < 1000*60*60*24)
  65. return i;
  66. return -1;
  67. },
  68. remove: function(i){
  69. this.splice(i,1);
  70. },
  71. replace: function(new_array){
  72. if (!new_array)
  73. return;
  74. if (!Array.isArray(new_array))
  75. new_array = [new_array];
  76. this.clear();
  77. this.push.apply(this, new_array);
  78. },
  79. clear: function(){
  80. this.length = 0;
  81. },
  82. copy: function(){
  83. var a = new DateArray();
  84. a.replace(this);
  85. return a;
  86. }
  87. };
  88. return function(){
  89. var a = [];
  90. a.push.apply(a, arguments);
  91. $.extend(a, extras);
  92. return a;
  93. };
  94. })();
  95. // Picker object
  96. var Datepicker = function(element, options){
  97. $.data(element, 'datepicker', this);
  98. this._events = [];
  99. this._secondaryEvents = [];
  100. this._process_options(options);
  101. this.dates = new DateArray();
  102. this.viewDate = this.o.defaultViewDate;
  103. this.focusDate = null;
  104. this.element = $(element);
  105. this.isInput = this.element.is('input');
  106. this.inputField = this.isInput ? this.element : this.element.find('input');
  107. this.component = this.element.hasClass('date') ? this.element.find('.add-on, .input-group-addon, .input-group-append, .input-group-prepend, .btn') : false;
  108. if (this.component && this.component.length === 0){
  109. this.component = false;
  110. }
  111. if (this.o.isInline === null){
  112. this.isInline = !this.component && !this.isInput;
  113. } else {
  114. this.isInline = this.o.isInline;
  115. }
  116. this.picker = $(DPGlobal.template);
  117. // Checking templates and inserting
  118. if (this._check_template(this.o.templates.leftArrow)) {
  119. this.picker.find('.prev').html(this.o.templates.leftArrow);
  120. }
  121. if (this._check_template(this.o.templates.rightArrow)) {
  122. this.picker.find('.next').html(this.o.templates.rightArrow);
  123. }
  124. this._buildEvents();
  125. this._attachEvents();
  126. if (this.isInline){
  127. this.picker.addClass('datepicker-inline').appendTo(this.element);
  128. }
  129. else {
  130. this.picker.addClass('datepicker-dropdown dropdown-menu');
  131. }
  132. if (this.o.rtl){
  133. this.picker.addClass('datepicker-rtl');
  134. }
  135. if (this.o.calendarWeeks) {
  136. this.picker.find('.datepicker-days .datepicker-switch, thead .datepicker-title, tfoot .today, tfoot .clear')
  137. .attr('colspan', function(i, val){
  138. return Number(val) + 1;
  139. });
  140. }
  141. this._process_options({
  142. startDate: this._o.startDate,
  143. endDate: this._o.endDate,
  144. daysOfWeekDisabled: this.o.daysOfWeekDisabled,
  145. daysOfWeekHighlighted: this.o.daysOfWeekHighlighted,
  146. datesDisabled: this.o.datesDisabled
  147. });
  148. this._allow_update = false;
  149. this.setViewMode(this.o.startView);
  150. this._allow_update = true;
  151. this.fillDow();
  152. this.fillMonths();
  153. this.update();
  154. if (this.isInline){
  155. this.show();
  156. }
  157. };
  158. Datepicker.prototype = {
  159. constructor: Datepicker,
  160. _resolveViewName: function(view){
  161. $.each(DPGlobal.viewModes, function(i, viewMode){
  162. if (view === i || $.inArray(view, viewMode.names) !== -1){
  163. view = i;
  164. return false;
  165. }
  166. });
  167. return view;
  168. },
  169. _resolveDaysOfWeek: function(daysOfWeek){
  170. if (!Array.isArray(daysOfWeek))
  171. daysOfWeek = daysOfWeek.split(/[,\s]*/);
  172. return $.map(daysOfWeek, Number);
  173. },
  174. _check_template: function(tmp){
  175. try {
  176. // If empty
  177. if (tmp === undefined || tmp === "") {
  178. return false;
  179. }
  180. // If no html, everything ok
  181. if ((tmp.match(/[<>]/g) || []).length <= 0) {
  182. return true;
  183. }
  184. // Checking if html is fine
  185. var jDom = $(tmp);
  186. return jDom.length > 0;
  187. }
  188. catch (ex) {
  189. return false;
  190. }
  191. },
  192. _process_options: function(opts){
  193. // Store raw options for reference
  194. this._o = $.extend({}, this._o, opts);
  195. // Processed options
  196. var o = this.o = $.extend({}, this._o);
  197. // Check if "de-DE" style date is available, if not language should
  198. // fallback to 2 letter code eg "de"
  199. var lang = o.language;
  200. if (!dates[lang]){
  201. lang = lang.split('-')[0];
  202. if (!dates[lang])
  203. lang = defaults.language;
  204. }
  205. o.language = lang;
  206. // Retrieve view index from any aliases
  207. o.startView = this._resolveViewName(o.startView);
  208. o.minViewMode = this._resolveViewName(o.minViewMode);
  209. o.maxViewMode = this._resolveViewName(o.maxViewMode);
  210. // Check view is between min and max
  211. o.startView = Math.max(this.o.minViewMode, Math.min(this.o.maxViewMode, o.startView));
  212. // true, false, or Number > 0
  213. if (o.multidate !== true){
  214. o.multidate = Number(o.multidate) || false;
  215. if (o.multidate !== false)
  216. o.multidate = Math.max(0, o.multidate);
  217. }
  218. o.multidateSeparator = String(o.multidateSeparator);
  219. o.weekStart %= 7;
  220. o.weekEnd = (o.weekStart + 6) % 7;
  221. var format = DPGlobal.parseFormat(o.format);
  222. if (o.startDate !== -Infinity){
  223. if (!!o.startDate){
  224. if (o.startDate instanceof Date)
  225. o.startDate = this._local_to_utc(this._zero_time(o.startDate));
  226. else
  227. o.startDate = DPGlobal.parseDate(o.startDate, format, o.language, o.assumeNearbyYear);
  228. }
  229. else {
  230. o.startDate = -Infinity;
  231. }
  232. }
  233. if (o.endDate !== Infinity){
  234. if (!!o.endDate){
  235. if (o.endDate instanceof Date)
  236. o.endDate = this._local_to_utc(this._zero_time(o.endDate));
  237. else
  238. o.endDate = DPGlobal.parseDate(o.endDate, format, o.language, o.assumeNearbyYear);
  239. }
  240. else {
  241. o.endDate = Infinity;
  242. }
  243. }
  244. o.daysOfWeekDisabled = this._resolveDaysOfWeek(o.daysOfWeekDisabled||[]);
  245. o.daysOfWeekHighlighted = this._resolveDaysOfWeek(o.daysOfWeekHighlighted||[]);
  246. o.datesDisabled = o.datesDisabled||[];
  247. if (!Array.isArray(o.datesDisabled)) {
  248. o.datesDisabled = o.datesDisabled.split(',');
  249. }
  250. o.datesDisabled = $.map(o.datesDisabled, function(d){
  251. return DPGlobal.parseDate(d, format, o.language, o.assumeNearbyYear);
  252. });
  253. var plc = String(o.orientation).toLowerCase().split(/\s+/g),
  254. _plc = o.orientation.toLowerCase();
  255. plc = $.grep(plc, function(word){
  256. return /^auto|left|right|top|bottom$/.test(word);
  257. });
  258. o.orientation = {x: 'auto', y: 'auto'};
  259. if (!_plc || _plc === 'auto')
  260. ; // no action
  261. else if (plc.length === 1){
  262. switch (plc[0]){
  263. case 'top':
  264. case 'bottom':
  265. o.orientation.y = plc[0];
  266. break;
  267. case 'left':
  268. case 'right':
  269. o.orientation.x = plc[0];
  270. break;
  271. }
  272. }
  273. else {
  274. _plc = $.grep(plc, function(word){
  275. return /^left|right$/.test(word);
  276. });
  277. o.orientation.x = _plc[0] || 'auto';
  278. _plc = $.grep(plc, function(word){
  279. return /^top|bottom$/.test(word);
  280. });
  281. o.orientation.y = _plc[0] || 'auto';
  282. }
  283. if (o.defaultViewDate instanceof Date || typeof o.defaultViewDate === 'string') {
  284. o.defaultViewDate = DPGlobal.parseDate(o.defaultViewDate, format, o.language, o.assumeNearbyYear);
  285. } else if (o.defaultViewDate) {
  286. var year = o.defaultViewDate.year || new Date().getFullYear();
  287. var month = o.defaultViewDate.month || 0;
  288. var day = o.defaultViewDate.day || 1;
  289. o.defaultViewDate = UTCDate(year, month, day);
  290. } else {
  291. o.defaultViewDate = UTCToday();
  292. }
  293. },
  294. _applyEvents: function(evs){
  295. for (var i=0, el, ch, ev; i < evs.length; i++){
  296. el = evs[i][0];
  297. if (evs[i].length === 2){
  298. ch = undefined;
  299. ev = evs[i][1];
  300. } else if (evs[i].length === 3){
  301. ch = evs[i][1];
  302. ev = evs[i][2];
  303. }
  304. el.on(ev, ch);
  305. }
  306. },
  307. _unapplyEvents: function(evs){
  308. for (var i=0, el, ev, ch; i < evs.length; i++){
  309. el = evs[i][0];
  310. if (evs[i].length === 2){
  311. ch = undefined;
  312. ev = evs[i][1];
  313. } else if (evs[i].length === 3){
  314. ch = evs[i][1];
  315. ev = evs[i][2];
  316. }
  317. el.off(ev, ch);
  318. }
  319. },
  320. _buildEvents: function(){
  321. var events = {
  322. keyup: $.proxy(function(e){
  323. if ($.inArray(e.keyCode, [27, 37, 39, 38, 40, 32, 13, 9]) === -1)
  324. this.update();
  325. }, this),
  326. keydown: $.proxy(this.keydown, this),
  327. paste: $.proxy(this.paste, this)
  328. };
  329. if (this.o.showOnFocus === true) {
  330. events.focus = $.proxy(this.show, this);
  331. }
  332. if (this.isInput) { // single input
  333. this._events = [
  334. [this.element, events]
  335. ];
  336. }
  337. // component: input + button
  338. else if (this.component && this.inputField.length) {
  339. this._events = [
  340. // For components that are not readonly, allow keyboard nav
  341. [this.inputField, events],
  342. [this.component, {
  343. click: $.proxy(this.show, this)
  344. }]
  345. ];
  346. }
  347. else {
  348. this._events = [
  349. [this.element, {
  350. click: $.proxy(this.show, this),
  351. keydown: $.proxy(this.keydown, this)
  352. }]
  353. ];
  354. }
  355. this._events.push(
  356. // Component: listen for blur on element descendants
  357. [this.element, '*', {
  358. blur: $.proxy(function(e){
  359. this._focused_from = e.target;
  360. }, this)
  361. }],
  362. // Input: listen for blur on element
  363. [this.element, {
  364. blur: $.proxy(function(e){
  365. this._focused_from = e.target;
  366. }, this)
  367. }]
  368. );
  369. if (this.o.immediateUpdates) {
  370. // Trigger input updates immediately on changed year/month
  371. this._events.push([this.element, {
  372. 'changeYear changeMonth': $.proxy(function(e){
  373. this.update(e.date);
  374. }, this)
  375. }]);
  376. }
  377. this._secondaryEvents = [
  378. [this.picker, {
  379. click: $.proxy(this.click, this)
  380. }],
  381. [this.picker, '.prev, .next', {
  382. click: $.proxy(this.navArrowsClick, this)
  383. }],
  384. [this.picker, '.day:not(.disabled)', {
  385. click: $.proxy(this.dayCellClick, this)
  386. }],
  387. [$(window), {
  388. resize: $.proxy(this.place, this)
  389. }],
  390. [$(document), {
  391. 'mousedown touchstart': $.proxy(function(e){
  392. // Clicked outside the datepicker, hide it
  393. if (!(
  394. this.element.is(e.target) ||
  395. this.element.find(e.target).length ||
  396. this.picker.is(e.target) ||
  397. this.picker.find(e.target).length ||
  398. this.isInline
  399. )){
  400. this.hide();
  401. }
  402. }, this)
  403. }]
  404. ];
  405. },
  406. _attachEvents: function(){
  407. this._detachEvents();
  408. this._applyEvents(this._events);
  409. },
  410. _detachEvents: function(){
  411. this._unapplyEvents(this._events);
  412. },
  413. _attachSecondaryEvents: function(){
  414. this._detachSecondaryEvents();
  415. this._applyEvents(this._secondaryEvents);
  416. },
  417. _detachSecondaryEvents: function(){
  418. this._unapplyEvents(this._secondaryEvents);
  419. },
  420. _trigger: function(event, altdate){
  421. var date = altdate || this.dates.get(-1),
  422. local_date = this._utc_to_local(date);
  423. this.element.trigger({
  424. type: event,
  425. date: local_date,
  426. viewMode: this.viewMode,
  427. dates: $.map(this.dates, this._utc_to_local),
  428. format: $.proxy(function(ix, format){
  429. if (arguments.length === 0){
  430. ix = this.dates.length - 1;
  431. format = this.o.format;
  432. } else if (typeof ix === 'string'){
  433. format = ix;
  434. ix = this.dates.length - 1;
  435. }
  436. format = format || this.o.format;
  437. var date = this.dates.get(ix);
  438. return DPGlobal.formatDate(date, format, this.o.language);
  439. }, this)
  440. });
  441. },
  442. show: function(){
  443. if (this.inputField.is(':disabled') || (this.inputField.prop('readonly') && this.o.enableOnReadonly === false))
  444. return;
  445. if (!this.isInline)
  446. this.picker.appendTo(this.o.container);
  447. this.place();
  448. this.picker.show();
  449. this._attachSecondaryEvents();
  450. this._trigger('show');
  451. if ((window.navigator.msMaxTouchPoints || 'ontouchstart' in document) && this.o.disableTouchKeyboard) {
  452. $(this.element).blur();
  453. }
  454. return this;
  455. },
  456. hide: function(){
  457. if (this.isInline || !this.picker.is(':visible'))
  458. return this;
  459. this.focusDate = null;
  460. this.picker.hide().detach();
  461. this._detachSecondaryEvents();
  462. this.setViewMode(this.o.startView);
  463. if (this.o.forceParse && this.inputField.val())
  464. this.setValue();
  465. this._trigger('hide');
  466. return this;
  467. },
  468. destroy: function(){
  469. this.hide();
  470. this._detachEvents();
  471. this._detachSecondaryEvents();
  472. this.picker.remove();
  473. delete this.element.data().datepicker;
  474. if (!this.isInput){
  475. delete this.element.data().date;
  476. }
  477. return this;
  478. },
  479. paste: function(e){
  480. var dateString;
  481. if (e.originalEvent.clipboardData && e.originalEvent.clipboardData.types
  482. && $.inArray('text/plain', e.originalEvent.clipboardData.types) !== -1) {
  483. dateString = e.originalEvent.clipboardData.getData('text/plain');
  484. } else if (window.clipboardData) {
  485. dateString = window.clipboardData.getData('Text');
  486. } else {
  487. return;
  488. }
  489. this.setDate(dateString);
  490. this.update();
  491. e.preventDefault();
  492. },
  493. _utc_to_local: function(utc){
  494. if (!utc) {
  495. return utc;
  496. }
  497. var local = new Date(utc.getTime() + (utc.getTimezoneOffset() * 60000));
  498. if (local.getTimezoneOffset() !== utc.getTimezoneOffset()) {
  499. local = new Date(utc.getTime() + (local.getTimezoneOffset() * 60000));
  500. }
  501. return local;
  502. },
  503. _local_to_utc: function(local){
  504. return local && new Date(local.getTime() - (local.getTimezoneOffset()*60000));
  505. },
  506. _zero_time: function(local){
  507. return local && new Date(local.getFullYear(), local.getMonth(), local.getDate());
  508. },
  509. _zero_utc_time: function(utc){
  510. return utc && UTCDate(utc.getUTCFullYear(), utc.getUTCMonth(), utc.getUTCDate());
  511. },
  512. getDates: function(){
  513. return $.map(this.dates, this._utc_to_local);
  514. },
  515. getUTCDates: function(){
  516. return $.map(this.dates, function(d){
  517. return new Date(d);
  518. });
  519. },
  520. getDate: function(){
  521. return this._utc_to_local(this.getUTCDate());
  522. },
  523. getUTCDate: function(){
  524. var selected_date = this.dates.get(-1);
  525. if (selected_date !== undefined) {
  526. return new Date(selected_date);
  527. } else {
  528. return null;
  529. }
  530. },
  531. clearDates: function(){
  532. this.inputField.val('');
  533. this._trigger('changeDate');
  534. this.update();
  535. if (this.o.autoclose) {
  536. this.hide();
  537. }
  538. },
  539. setDates: function(){
  540. var args = Array.isArray(arguments[0]) ? arguments[0] : arguments;
  541. this.update.apply(this, args);
  542. this._trigger('changeDate');
  543. this.setValue();
  544. return this;
  545. },
  546. setUTCDates: function(){
  547. var args = Array.isArray(arguments[0]) ? arguments[0] : arguments;
  548. this.setDates.apply(this, $.map(args, this._utc_to_local));
  549. return this;
  550. },
  551. setDate: alias('setDates'),
  552. setUTCDate: alias('setUTCDates'),
  553. remove: alias('destroy', 'Method `remove` is deprecated and will be removed in version 2.0. Use `destroy` instead'),
  554. setValue: function(){
  555. var formatted = this.getFormattedDate();
  556. this.inputField.val(formatted);
  557. return this;
  558. },
  559. getFormattedDate: function(format){
  560. if (format === undefined)
  561. format = this.o.format;
  562. var lang = this.o.language;
  563. return $.map(this.dates, function(d){
  564. return DPGlobal.formatDate(d, format, lang);
  565. }).join(this.o.multidateSeparator);
  566. },
  567. getStartDate: function(){
  568. return this.o.startDate;
  569. },
  570. setStartDate: function(startDate){
  571. this._process_options({startDate: startDate});
  572. this.update();
  573. this.updateNavArrows();
  574. return this;
  575. },
  576. getEndDate: function(){
  577. return this.o.endDate;
  578. },
  579. setEndDate: function(endDate){
  580. this._process_options({endDate: endDate});
  581. this.update();
  582. this.updateNavArrows();
  583. return this;
  584. },
  585. setDaysOfWeekDisabled: function(daysOfWeekDisabled){
  586. this._process_options({daysOfWeekDisabled: daysOfWeekDisabled});
  587. this.update();
  588. return this;
  589. },
  590. setDaysOfWeekHighlighted: function(daysOfWeekHighlighted){
  591. this._process_options({daysOfWeekHighlighted: daysOfWeekHighlighted});
  592. this.update();
  593. return this;
  594. },
  595. setDatesDisabled: function(datesDisabled){
  596. this._process_options({datesDisabled: datesDisabled});
  597. this.update();
  598. return this;
  599. },
  600. place: function(){
  601. if (this.isInline)
  602. return this;
  603. var calendarWidth = this.picker.outerWidth(),
  604. calendarHeight = this.picker.outerHeight(),
  605. visualPadding = 10,
  606. container = $(this.o.container),
  607. windowWidth = container.width(),
  608. scrollTop = this.o.container === 'body' ? $(document).scrollTop() : container.scrollTop(),
  609. appendOffset = container.offset();
  610. var parentsZindex = [0];
  611. this.element.parents().each(function(){
  612. var itemZIndex = $(this).css('z-index');
  613. if (itemZIndex !== 'auto' && Number(itemZIndex) !== 0) parentsZindex.push(Number(itemZIndex));
  614. });
  615. var zIndex = Math.max.apply(Math, parentsZindex) + this.o.zIndexOffset;
  616. var offset = this.component ? this.component.parent().offset() : this.element.offset();
  617. var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(false);
  618. var width = this.component ? this.component.outerWidth(true) : this.element.outerWidth(false);
  619. var left = offset.left - appendOffset.left;
  620. var top = offset.top - appendOffset.top;
  621. if (this.o.container !== 'body') {
  622. top += scrollTop;
  623. }
  624. this.picker.removeClass(
  625. 'datepicker-orient-top datepicker-orient-bottom '+
  626. 'datepicker-orient-right datepicker-orient-left'
  627. );
  628. if (this.o.orientation.x !== 'auto'){
  629. this.picker.addClass('datepicker-orient-' + this.o.orientation.x);
  630. if (this.o.orientation.x === 'right')
  631. left -= calendarWidth - width;
  632. }
  633. // auto x orientation is best-placement: if it crosses a window
  634. // edge, fudge it sideways
  635. else {
  636. if (offset.left < 0) {
  637. // component is outside the window on the left side. Move it into visible range
  638. this.picker.addClass('datepicker-orient-left');
  639. left -= offset.left - visualPadding;
  640. } else if (left + calendarWidth > windowWidth) {
  641. // the calendar passes the widow right edge. Align it to component right side
  642. this.picker.addClass('datepicker-orient-right');
  643. left += width - calendarWidth;
  644. } else {
  645. if (this.o.rtl) {
  646. // Default to right
  647. this.picker.addClass('datepicker-orient-right');
  648. } else {
  649. // Default to left
  650. this.picker.addClass('datepicker-orient-left');
  651. }
  652. }
  653. }
  654. // auto y orientation is best-situation: top or bottom, no fudging,
  655. // decision based on which shows more of the calendar
  656. var yorient = this.o.orientation.y,
  657. top_overflow;
  658. if (yorient === 'auto'){
  659. top_overflow = -scrollTop + top - calendarHeight;
  660. yorient = top_overflow < 0 ? 'bottom' : 'top';
  661. }
  662. this.picker.addClass('datepicker-orient-' + yorient);
  663. if (yorient === 'top')
  664. top -= calendarHeight + parseInt(this.picker.css('padding-top'));
  665. else
  666. top += height;
  667. if (this.o.rtl) {
  668. var right = windowWidth - (left + width);
  669. this.picker.css({
  670. top: top,
  671. right: right,
  672. zIndex: zIndex
  673. });
  674. } else {
  675. this.picker.css({
  676. top: top,
  677. left: left,
  678. zIndex: zIndex
  679. });
  680. }
  681. return this;
  682. },
  683. _allow_update: true,
  684. update: function(){
  685. if (!this._allow_update)
  686. return this;
  687. var oldDates = this.dates.copy(),
  688. dates = [],
  689. fromArgs = false;
  690. if (arguments.length){
  691. $.each(arguments, $.proxy(function(i, date){
  692. if (date instanceof Date)
  693. date = this._local_to_utc(date);
  694. dates.push(date);
  695. }, this));
  696. fromArgs = true;
  697. } else {
  698. dates = this.isInput
  699. ? this.element.val()
  700. : this.element.data('date') || this.inputField.val();
  701. if (dates && this.o.multidate)
  702. dates = dates.split(this.o.multidateSeparator);
  703. else
  704. dates = [dates];
  705. delete this.element.data().date;
  706. }
  707. dates = $.map(dates, $.proxy(function(date){
  708. return DPGlobal.parseDate(date, this.o.format, this.o.language, this.o.assumeNearbyYear);
  709. }, this));
  710. dates = $.grep(dates, $.proxy(function(date){
  711. return (
  712. !this.dateWithinRange(date) ||
  713. !date
  714. );
  715. }, this), true);
  716. this.dates.replace(dates);
  717. if (this.o.updateViewDate) {
  718. if (this.dates.length)
  719. this.viewDate = new Date(this.dates.get(-1));
  720. else if (this.viewDate < this.o.startDate)
  721. this.viewDate = new Date(this.o.startDate);
  722. else if (this.viewDate > this.o.endDate)
  723. this.viewDate = new Date(this.o.endDate);
  724. else
  725. this.viewDate = this.o.defaultViewDate;
  726. }
  727. if (fromArgs){
  728. // setting date by clicking
  729. this.setValue();
  730. this.element.change();
  731. }
  732. else if (this.dates.length){
  733. // setting date by typing
  734. if (String(oldDates) !== String(this.dates) && fromArgs) {
  735. this._trigger('changeDate');
  736. this.element.change();
  737. }
  738. }
  739. if (!this.dates.length && oldDates.length) {
  740. this._trigger('clearDate');
  741. this.element.change();
  742. }
  743. this.fill();
  744. return this;
  745. },
  746. fillDow: function(){
  747. if (this.o.showWeekDays) {
  748. var dowCnt = this.o.weekStart,
  749. html = '<tr>';
  750. if (this.o.calendarWeeks){
  751. html += '<th class="cw">&#160;</th>';
  752. }
  753. while (dowCnt < this.o.weekStart + 7){
  754. html += '<th class="dow';
  755. if ($.inArray(dowCnt, this.o.daysOfWeekDisabled) !== -1)
  756. html += ' disabled';
  757. html += '">'+dates[this.o.language].daysMin[(dowCnt++)%7]+'</th>';
  758. }
  759. html += '</tr>';
  760. this.picker.find('.datepicker-days thead').append(html);
  761. }
  762. },
  763. fillMonths: function(){
  764. var localDate = this._utc_to_local(this.viewDate);
  765. var html = '';
  766. var focused;
  767. for (var i = 0; i < 12; i++){
  768. focused = localDate && localDate.getMonth() === i ? ' focused' : '';
  769. html += '<span class="month' + focused + '">' + dates[this.o.language].monthsShort[i] + '</span>';
  770. }
  771. this.picker.find('.datepicker-months td').html(html);
  772. },
  773. setRange: function(range){
  774. if (!range || !range.length)
  775. delete this.range;
  776. else
  777. this.range = $.map(range, function(d){
  778. return d.valueOf();
  779. });
  780. this.fill();
  781. },
  782. getClassNames: function(date){
  783. var cls = [],
  784. year = this.viewDate.getUTCFullYear(),
  785. month = this.viewDate.getUTCMonth(),
  786. today = UTCToday();
  787. if (date.getUTCFullYear() < year || (date.getUTCFullYear() === year && date.getUTCMonth() < month)){
  788. cls.push('old');
  789. } else if (date.getUTCFullYear() > year || (date.getUTCFullYear() === year && date.getUTCMonth() > month)){
  790. cls.push('new');
  791. }
  792. if (this.focusDate && date.valueOf() === this.focusDate.valueOf())
  793. cls.push('focused');
  794. // Compare internal UTC date with UTC today, not local today
  795. if (this.o.todayHighlight && isUTCEquals(date, today)) {
  796. cls.push('today');
  797. }
  798. if (this.dates.contains(date) !== -1)
  799. cls.push('active');
  800. if (!this.dateWithinRange(date)){
  801. cls.push('disabled');
  802. }
  803. if (this.dateIsDisabled(date)){
  804. cls.push('disabled', 'disabled-date');
  805. }
  806. if ($.inArray(date.getUTCDay(), this.o.daysOfWeekHighlighted) !== -1){
  807. cls.push('highlighted');
  808. }
  809. if (this.range){
  810. if (date > this.range[0] && date < this.range[this.range.length-1]){
  811. cls.push('range');
  812. }
  813. if ($.inArray(date.valueOf(), this.range) !== -1){
  814. cls.push('selected');
  815. }
  816. if (date.valueOf() === this.range[0]){
  817. cls.push('range-start');
  818. }
  819. if (date.valueOf() === this.range[this.range.length-1]){
  820. cls.push('range-end');
  821. }
  822. }
  823. return cls;
  824. },
  825. _fill_yearsView: function(selector, cssClass, factor, year, startYear, endYear, beforeFn){
  826. var html = '';
  827. var step = factor / 10;
  828. var view = this.picker.find(selector);
  829. var startVal = Math.floor(year / factor) * factor;
  830. var endVal = startVal + step * 9;
  831. var focusedVal = Math.floor(this.viewDate.getFullYear() / step) * step;
  832. var selected = $.map(this.dates, function(d){
  833. return Math.floor(d.getUTCFullYear() / step) * step;
  834. });
  835. var classes, tooltip, before;
  836. for (var currVal = startVal - step; currVal <= endVal + step; currVal += step) {
  837. classes = [cssClass];
  838. tooltip = null;
  839. if (currVal === startVal - step) {
  840. classes.push('old');
  841. } else if (currVal === endVal + step) {
  842. classes.push('new');
  843. }
  844. if ($.inArray(currVal, selected) !== -1) {
  845. classes.push('active');
  846. }
  847. if (currVal < startYear || currVal > endYear) {
  848. classes.push('disabled');
  849. }
  850. if (currVal === focusedVal) {
  851. classes.push('focused');
  852. }
  853. if (beforeFn !== $.noop) {
  854. before = beforeFn(new Date(currVal, 0, 1));
  855. if (before === undefined) {
  856. before = {};
  857. } else if (typeof before === 'boolean') {
  858. before = {enabled: before};
  859. } else if (typeof before === 'string') {
  860. before = {classes: before};
  861. }
  862. if (before.enabled === false) {
  863. classes.push('disabled');
  864. }
  865. if (before.classes) {
  866. classes = classes.concat(before.classes.split(/\s+/));
  867. }
  868. if (before.tooltip) {
  869. tooltip = before.tooltip;
  870. }
  871. }
  872. html += '<span class="' + classes.join(' ') + '"' + (tooltip ? ' title="' + tooltip + '"' : '') + '>' + currVal + '</span>';
  873. }
  874. view.find('.datepicker-switch').text(startVal + '-' + endVal);
  875. view.find('td').html(html);
  876. },
  877. fill: function(){
  878. var d = new Date(this.viewDate),
  879. year = d.getUTCFullYear(),
  880. month = d.getUTCMonth(),
  881. startYear = this.o.startDate !== -Infinity ? this.o.startDate.getUTCFullYear() : -Infinity,
  882. startMonth = this.o.startDate !== -Infinity ? this.o.startDate.getUTCMonth() : -Infinity,
  883. endYear = this.o.endDate !== Infinity ? this.o.endDate.getUTCFullYear() : Infinity,
  884. endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity,
  885. todaytxt = dates[this.o.language].today || dates['en'].today || '',
  886. cleartxt = dates[this.o.language].clear || dates['en'].clear || '',
  887. titleFormat = dates[this.o.language].titleFormat || dates['en'].titleFormat,
  888. todayDate = UTCToday(),
  889. titleBtnVisible = (this.o.todayBtn === true || this.o.todayBtn === 'linked') && todayDate >= this.o.startDate && todayDate <= this.o.endDate && !this.weekOfDateIsDisabled(todayDate),
  890. tooltip,
  891. before;
  892. if (isNaN(year) || isNaN(month))
  893. return;
  894. this.picker.find('.datepicker-days .datepicker-switch')
  895. .text(DPGlobal.formatDate(d, titleFormat, this.o.language));
  896. this.picker.find('tfoot .today')
  897. .text(todaytxt)
  898. .css('display', titleBtnVisible ? 'table-cell' : 'none');
  899. this.picker.find('tfoot .clear')
  900. .text(cleartxt)
  901. .css('display', this.o.clearBtn === true ? 'table-cell' : 'none');
  902. this.picker.find('thead .datepicker-title')
  903. .text(this.o.title)
  904. .css('display', typeof this.o.title === 'string' && this.o.title !== '' ? 'table-cell' : 'none');
  905. this.updateNavArrows();
  906. this.fillMonths();
  907. var prevMonth = UTCDate(year, month, 0),
  908. day = prevMonth.getUTCDate();
  909. prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.o.weekStart + 7)%7);
  910. var nextMonth = new Date(prevMonth);
  911. if (prevMonth.getUTCFullYear() < 100){
  912. nextMonth.setUTCFullYear(prevMonth.getUTCFullYear());
  913. }
  914. nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
  915. nextMonth = nextMonth.valueOf();
  916. var html = [];
  917. var weekDay, clsName;
  918. while (prevMonth.valueOf() < nextMonth){
  919. weekDay = prevMonth.getUTCDay();
  920. if (weekDay === this.o.weekStart){
  921. html.push('<tr>');
  922. if (this.o.calendarWeeks){
  923. // ISO 8601: First week contains first thursday.
  924. // ISO also states week starts on Monday, but we can be more abstract here.
  925. var
  926. // Start of current week: based on weekstart/current date
  927. ws = new Date(+prevMonth + (this.o.weekStart - weekDay - 7) % 7 * 864e5),
  928. // Thursday of this week
  929. th = new Date(Number(ws) + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
  930. // First Thursday of year, year from thursday
  931. yth = new Date(Number(yth = UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay()) % 7 * 864e5),
  932. // Calendar week: ms between thursdays, div ms per day, div 7 days
  933. calWeek = (th - yth) / 864e5 / 7 + 1;
  934. html.push('<td class="cw">'+ calWeek +'</td>');
  935. }
  936. }
  937. clsName = this.getClassNames(prevMonth);
  938. clsName.push('day');
  939. var content = prevMonth.getUTCDate();
  940. if (this.o.beforeShowDay !== $.noop){
  941. before = this.o.beforeShowDay(this._utc_to_local(prevMonth));
  942. if (before === undefined)
  943. before = {};
  944. else if (typeof before === 'boolean')
  945. before = {enabled: before};
  946. else if (typeof before === 'string')
  947. before = {classes: before};
  948. if (before.enabled === false)
  949. clsName.push('disabled');
  950. if (before.classes)
  951. clsName = clsName.concat(before.classes.split(/\s+/));
  952. if (before.tooltip)
  953. tooltip = before.tooltip;
  954. if (before.content)
  955. content = before.content;
  956. }
  957. //Check if uniqueSort exists (supported by jquery >=1.12 and >=2.2)
  958. //Fallback to unique function for older jquery versions
  959. if (typeof $.uniqueSort === "function") {
  960. clsName = $.uniqueSort(clsName);
  961. } else {
  962. clsName = $.unique(clsName);
  963. }
  964. html.push('<td class="'+clsName.join(' ')+'"' + (tooltip ? ' title="'+tooltip+'"' : '') + ' data-date="' + prevMonth.getTime().toString() + '">' + content + '</td>');
  965. tooltip = null;
  966. if (weekDay === this.o.weekEnd){
  967. html.push('</tr>');
  968. }
  969. prevMonth.setUTCDate(prevMonth.getUTCDate() + 1);
  970. }
  971. this.picker.find('.datepicker-days tbody').html(html.join(''));
  972. var monthsTitle = dates[this.o.language].monthsTitle || dates['en'].monthsTitle || 'Months';
  973. var months = this.picker.find('.datepicker-months')
  974. .find('.datepicker-switch')
  975. .text(this.o.maxViewMode < 2 ? monthsTitle : year)
  976. .end()
  977. .find('tbody span').removeClass('active');
  978. $.each(this.dates, function(i, d){
  979. if (d.getUTCFullYear() === year)
  980. months.eq(d.getUTCMonth()).addClass('active');
  981. });
  982. if (year < startYear || year > endYear){
  983. months.addClass('disabled');
  984. }
  985. if (year === startYear){
  986. months.slice(0, startMonth).addClass('disabled');
  987. }
  988. if (year === endYear){
  989. months.slice(endMonth+1).addClass('disabled');
  990. }
  991. if (this.o.beforeShowMonth !== $.noop){
  992. var that = this;
  993. $.each(months, function(i, month){
  994. var moDate = new Date(year, i, 1);
  995. var before = that.o.beforeShowMonth(moDate);
  996. if (before === undefined)
  997. before = {};
  998. else if (typeof before === 'boolean')
  999. before = {enabled: before};
  1000. else if (typeof before === 'string')
  1001. before = {classes: before};
  1002. if (before.enabled === false && !$(month).hasClass('disabled'))
  1003. $(month).addClass('disabled');
  1004. if (before.classes)
  1005. $(month).addClass(before.classes);
  1006. if (before.tooltip)
  1007. $(month).prop('title', before.tooltip);
  1008. });
  1009. }
  1010. // Generating decade/years picker
  1011. this._fill_yearsView(
  1012. '.datepicker-years',
  1013. 'year',
  1014. 10,
  1015. year,
  1016. startYear,
  1017. endYear,
  1018. this.o.beforeShowYear
  1019. );
  1020. // Generating century/decades picker
  1021. this._fill_yearsView(
  1022. '.datepicker-decades',
  1023. 'decade',
  1024. 100,
  1025. year,
  1026. startYear,
  1027. endYear,
  1028. this.o.beforeShowDecade
  1029. );
  1030. // Generating millennium/centuries picker
  1031. this._fill_yearsView(
  1032. '.datepicker-centuries',
  1033. 'century',
  1034. 1000,
  1035. year,
  1036. startYear,
  1037. endYear,
  1038. this.o.beforeShowCentury
  1039. );
  1040. },
  1041. updateNavArrows: function(){
  1042. if (!this._allow_update)
  1043. return;
  1044. var d = new Date(this.viewDate),
  1045. year = d.getUTCFullYear(),
  1046. month = d.getUTCMonth(),
  1047. startYear = this.o.startDate !== -Infinity ? this.o.startDate.getUTCFullYear() : -Infinity,
  1048. startMonth = this.o.startDate !== -Infinity ? this.o.startDate.getUTCMonth() : -Infinity,
  1049. endYear = this.o.endDate !== Infinity ? this.o.endDate.getUTCFullYear() : Infinity,
  1050. endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity,
  1051. prevIsDisabled,
  1052. nextIsDisabled,
  1053. factor = 1;
  1054. switch (this.viewMode){
  1055. case 4:
  1056. factor *= 10;
  1057. /* falls through */
  1058. case 3:
  1059. factor *= 10;
  1060. /* falls through */
  1061. case 2:
  1062. factor *= 10;
  1063. /* falls through */
  1064. case 1:
  1065. prevIsDisabled = Math.floor(year / factor) * factor <= startYear;
  1066. nextIsDisabled = Math.floor(year / factor) * factor + factor > endYear;
  1067. break;
  1068. case 0:
  1069. prevIsDisabled = year <= startYear && month <= startMonth;
  1070. nextIsDisabled = year >= endYear && month >= endMonth;
  1071. break;
  1072. }
  1073. this.picker.find('.prev').toggleClass('disabled', prevIsDisabled);
  1074. this.picker.find('.next').toggleClass('disabled', nextIsDisabled);
  1075. },
  1076. click: function(e){
  1077. e.preventDefault();
  1078. e.stopPropagation();
  1079. var target, dir, day, year, month;
  1080. target = $(e.target);
  1081. // Clicked on the switch
  1082. if (target.hasClass('datepicker-switch') && this.viewMode !== this.o.maxViewMode){
  1083. this.setViewMode(this.viewMode + 1);
  1084. }
  1085. // Clicked on today button
  1086. if (target.hasClass('today') && !target.hasClass('day')){
  1087. this.setViewMode(0);
  1088. this._setDate(UTCToday(), this.o.todayBtn === 'linked' ? null : 'view');
  1089. }
  1090. // Clicked on clear button
  1091. if (target.hasClass('clear')){
  1092. this.clearDates();
  1093. }
  1094. if (!target.hasClass('disabled')){
  1095. // Clicked on a month, year, decade, century
  1096. if (target.hasClass('month')
  1097. || target.hasClass('year')
  1098. || target.hasClass('decade')
  1099. || target.hasClass('century')) {
  1100. this.viewDate.setUTCDate(1);
  1101. day = 1;
  1102. if (this.viewMode === 1){
  1103. month = target.parent().find('span').index(target);
  1104. year = this.viewDate.getUTCFullYear();
  1105. this.viewDate.setUTCMonth(month);
  1106. } else {
  1107. month = 0;
  1108. year = Number(target.text());
  1109. this.viewDate.setUTCFullYear(year);
  1110. }
  1111. this._trigger(DPGlobal.viewModes[this.viewMode - 1].e, this.viewDate);
  1112. if (this.viewMode === this.o.minViewMode){
  1113. this._setDate(UTCDate(year, month, day));
  1114. } else {
  1115. this.setViewMode(this.viewMode - 1);
  1116. this.fill();
  1117. }
  1118. }
  1119. }
  1120. if (this.picker.is(':visible') && this._focused_from){
  1121. this._focused_from.focus();
  1122. }
  1123. delete this._focused_from;
  1124. },
  1125. dayCellClick: function(e){
  1126. var $target = $(e.currentTarget);
  1127. var timestamp = $target.data('date');
  1128. var date = new Date(timestamp);
  1129. if (this.o.updateViewDate) {
  1130. if (date.getUTCFullYear() !== this.viewDate.getUTCFullYear()) {
  1131. this._trigger('changeYear', this.viewDate);
  1132. }
  1133. if (date.getUTCMonth() !== this.viewDate.getUTCMonth()) {
  1134. this._trigger('changeMonth', this.viewDate);
  1135. }
  1136. }
  1137. this._setDate(date);
  1138. },
  1139. // Clicked on prev or next
  1140. navArrowsClick: function(e){
  1141. var $target = $(e.currentTarget);
  1142. var dir = $target.hasClass('prev') ? -1 : 1;
  1143. if (this.viewMode !== 0){
  1144. dir *= DPGlobal.viewModes[this.viewMode].navStep * 12;
  1145. }
  1146. this.viewDate = this.moveMonth(this.viewDate, dir);
  1147. this._trigger(DPGlobal.viewModes[this.viewMode].e, this.viewDate);
  1148. this.fill();
  1149. },
  1150. _toggle_multidate: function(date){
  1151. var ix = this.dates.contains(date);
  1152. if (!date){
  1153. this.dates.clear();
  1154. }
  1155. if (ix !== -1){
  1156. if (this.o.multidate === true || this.o.multidate > 1 || this.o.toggleActive){
  1157. this.dates.remove(ix);
  1158. }
  1159. } else if (this.o.multidate === false) {
  1160. this.dates.clear();
  1161. this.dates.push(date);
  1162. }
  1163. else {
  1164. this.dates.push(date);
  1165. }
  1166. if (typeof this.o.multidate === 'number')
  1167. while (this.dates.length > this.o.multidate)
  1168. this.dates.remove(0);
  1169. },
  1170. _setDate: function(date, which){
  1171. if (!which || which === 'date')
  1172. this._toggle_multidate(date && new Date(date));
  1173. if ((!which && this.o.updateViewDate) || which === 'view')
  1174. this.viewDate = date && new Date(date);
  1175. this.fill();
  1176. this.setValue();
  1177. if (!which || which !== 'view') {
  1178. this._trigger('changeDate');
  1179. }
  1180. this.inputField.trigger('change');
  1181. if (this.o.autoclose && (!which || which === 'date')){
  1182. this.hide();
  1183. }
  1184. },
  1185. moveDay: function(date, dir){
  1186. var newDate = new Date(date);
  1187. newDate.setUTCDate(date.getUTCDate() + dir);
  1188. return newDate;
  1189. },
  1190. moveWeek: function(date, dir){
  1191. return this.moveDay(date, dir * 7);
  1192. },
  1193. moveMonth: function(date, dir){
  1194. if (!isValidDate(date))
  1195. return this.o.defaultViewDate;
  1196. if (!dir)
  1197. return date;
  1198. var new_date = new Date(date.valueOf()),
  1199. day = new_date.getUTCDate(),
  1200. month = new_date.getUTCMonth(),
  1201. mag = Math.abs(dir),
  1202. new_month, test;
  1203. dir = dir > 0 ? 1 : -1;
  1204. if (mag === 1){
  1205. test = dir === -1
  1206. // If going back one month, make sure month is not current month
  1207. // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
  1208. ? function(){
  1209. return new_date.getUTCMonth() === month;
  1210. }
  1211. // If going forward one month, make sure month is as expected
  1212. // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
  1213. : function(){
  1214. return new_date.getUTCMonth() !== new_month;
  1215. };
  1216. new_month = month + dir;
  1217. new_date.setUTCMonth(new_month);
  1218. // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
  1219. new_month = (new_month + 12) % 12;
  1220. }
  1221. else {
  1222. // For magnitudes >1, move one month at a time...
  1223. for (var i=0; i < mag; i++)
  1224. // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
  1225. new_date = this.moveMonth(new_date, dir);
  1226. // ...then reset the day, keeping it in the new month
  1227. new_month = new_date.getUTCMonth();
  1228. new_date.setUTCDate(day);
  1229. test = function(){
  1230. return new_month !== new_date.getUTCMonth();
  1231. };
  1232. }
  1233. // Common date-resetting loop -- if date is beyond end of month, make it
  1234. // end of month
  1235. while (test()){
  1236. new_date.setUTCDate(--day);
  1237. new_date.setUTCMonth(new_month);
  1238. }
  1239. return new_date;
  1240. },
  1241. moveYear: function(date, dir){
  1242. return this.moveMonth(date, dir*12);
  1243. },
  1244. moveAvailableDate: function(date, dir, fn){
  1245. do {
  1246. date = this[fn](date, dir);
  1247. if (!this.dateWithinRange(date))
  1248. return false;
  1249. fn = 'moveDay';
  1250. }
  1251. while (this.dateIsDisabled(date));
  1252. return date;
  1253. },
  1254. weekOfDateIsDisabled: function(date){
  1255. return $.inArray(date.getUTCDay(), this.o.daysOfWeekDisabled) !== -1;
  1256. },
  1257. dateIsDisabled: function(date){
  1258. return (
  1259. this.weekOfDateIsDisabled(date) ||
  1260. $.grep(this.o.datesDisabled, function(d){
  1261. return isUTCEquals(date, d);
  1262. }).length > 0
  1263. );
  1264. },
  1265. dateWithinRange: function(date){
  1266. return date >= this.o.startDate && date <= this.o.endDate;
  1267. },
  1268. keydown: function(e){
  1269. if (!this.picker.is(':visible')){
  1270. if (e.keyCode === 40 || e.keyCode === 27) { // allow down to re-show picker
  1271. this.show();
  1272. e.stopPropagation();
  1273. }
  1274. return;
  1275. }
  1276. var dateChanged = false,
  1277. dir, newViewDate,
  1278. focusDate = this.focusDate || this.viewDate;
  1279. switch (e.keyCode){
  1280. case 27: // escape
  1281. if (this.focusDate){
  1282. this.focusDate = null;
  1283. this.viewDate = this.dates.get(-1) || this.viewDate;
  1284. this.fill();
  1285. }
  1286. else
  1287. this.hide();
  1288. e.preventDefault();
  1289. e.stopPropagation();
  1290. break;
  1291. case 37: // left
  1292. case 38: // up
  1293. case 39: // right
  1294. case 40: // down
  1295. if (!this.o.keyboardNavigation || this.o.daysOfWeekDisabled.length === 7)
  1296. break;
  1297. dir = e.keyCode === 37 || e.keyCode === 38 ? -1 : 1;
  1298. if (this.viewMode === 0) {
  1299. if (e.ctrlKey){
  1300. newViewDate = this.moveAvailableDate(focusDate, dir, 'moveYear');
  1301. if (newViewDate)
  1302. this._trigger('changeYear', this.viewDate);
  1303. } else if (e.shiftKey){
  1304. newViewDate = this.moveAvailableDate(focusDate, dir, 'moveMonth');
  1305. if (newViewDate)
  1306. this._trigger('changeMonth', this.viewDate);
  1307. } else if (e.keyCode === 37 || e.keyCode === 39){
  1308. newViewDate = this.moveAvailableDate(focusDate, dir, 'moveDay');
  1309. } else if (!this.weekOfDateIsDisabled(focusDate)){
  1310. newViewDate = this.moveAvailableDate(focusDate, dir, 'moveWeek');
  1311. }
  1312. } else if (this.viewMode === 1) {
  1313. if (e.keyCode === 38 || e.keyCode === 40) {
  1314. dir = dir * 4;
  1315. }
  1316. newViewDate = this.moveAvailableDate(focusDate, dir, 'moveMonth');
  1317. } else if (this.viewMode === 2) {
  1318. if (e.keyCode === 38 || e.keyCode === 40) {
  1319. dir = dir * 4;
  1320. }
  1321. newViewDate = this.moveAvailableDate(focusDate, dir, 'moveYear');
  1322. }
  1323. if (newViewDate){
  1324. this.focusDate = this.viewDate = newViewDate;
  1325. this.setValue();
  1326. this.fill();
  1327. e.preventDefault();
  1328. }
  1329. break;
  1330. case 13: // enter
  1331. if (!this.o.forceParse)
  1332. break;
  1333. focusDate = this.focusDate || this.dates.get(-1) || this.viewDate;
  1334. if (this.o.keyboardNavigation) {
  1335. this._toggle_multidate(focusDate);
  1336. dateChanged = true;
  1337. }
  1338. this.focusDate = null;
  1339. this.viewDate = this.dates.get(-1) || this.viewDate;
  1340. this.setValue();
  1341. this.fill();
  1342. if (this.picker.is(':visible')){
  1343. e.preventDefault();
  1344. e.stopPropagation();
  1345. if (this.o.autoclose)
  1346. this.hide();
  1347. }
  1348. break;
  1349. case 9: // tab
  1350. this.focusDate = null;
  1351. this.viewDate = this.dates.get(-1) || this.viewDate;
  1352. this.fill();
  1353. this.hide();
  1354. break;
  1355. }
  1356. if (dateChanged){
  1357. if (this.dates.length)
  1358. this._trigger('changeDate');
  1359. else
  1360. this._trigger('clearDate');
  1361. this.inputField.trigger('change');
  1362. }
  1363. },
  1364. setViewMode: function(viewMode){
  1365. this.viewMode = viewMode;
  1366. this.picker
  1367. .children('div')
  1368. .hide()
  1369. .filter('.datepicker-' + DPGlobal.viewModes[this.viewMode].clsName)
  1370. .show();
  1371. this.updateNavArrows();
  1372. this._trigger('changeViewMode', new Date(this.viewDate));
  1373. }
  1374. };
  1375. var DateRangePicker = function(element, options){
  1376. $.data(element, 'datepicker', this);
  1377. this.element = $(element);
  1378. this.inputs = $.map(options.inputs, function(i){
  1379. return i.jquery ? i[0] : i;
  1380. });
  1381. delete options.inputs;
  1382. this.keepEmptyValues = options.keepEmptyValues;
  1383. delete options.keepEmptyValues;
  1384. datepickerPlugin.call($(this.inputs), options)
  1385. .on('changeDate', $.proxy(this.dateUpdated, this));
  1386. this.pickers = $.map(this.inputs, function(i){
  1387. return $.data(i, 'datepicker');
  1388. });
  1389. this.updateDates();
  1390. };
  1391. DateRangePicker.prototype = {
  1392. updateDates: function(){
  1393. this.dates = $.map(this.pickers, function(i){
  1394. return i.getUTCDate();
  1395. });
  1396. this.updateRanges();
  1397. },
  1398. updateRanges: function(){
  1399. var range = $.map(this.dates, function(d){
  1400. return d.valueOf();
  1401. });
  1402. $.each(this.pickers, function(i, p){
  1403. p.setRange(range);
  1404. });
  1405. },
  1406. clearDates: function(){
  1407. $.each(this.pickers, function(i, p){
  1408. p.clearDates();
  1409. });
  1410. },
  1411. dateUpdated: function(e){
  1412. // `this.updating` is a workaround for preventing infinite recursion
  1413. // between `changeDate` triggering and `setUTCDate` calling. Until
  1414. // there is a better mechanism.
  1415. if (this.updating)
  1416. return;
  1417. this.updating = true;
  1418. var dp = $.data(e.target, 'datepicker');
  1419. if (dp === undefined) {
  1420. return;
  1421. }
  1422. var new_date = dp.getUTCDate(),
  1423. keep_empty_values = this.keepEmptyValues,
  1424. i = $.inArray(e.target, this.inputs),
  1425. j = i - 1,
  1426. k = i + 1,
  1427. l = this.inputs.length;
  1428. if (i === -1)
  1429. return;
  1430. $.each(this.pickers, function(i, p){
  1431. if (!p.getUTCDate() && (p === dp || !keep_empty_values))
  1432. p.setUTCDate(new_date);
  1433. });
  1434. if (new_date < this.dates[j]){
  1435. // Date being moved earlier/left
  1436. while (j >= 0 && new_date < this.dates[j] && (this.pickers[j].element.val() || "").length > 0) {
  1437. this.pickers[j--].setUTCDate(new_date);
  1438. }
  1439. } else if (new_date > this.dates[k]){
  1440. // Date being moved later/right
  1441. while (k < l && new_date > this.dates[k] && (this.pickers[k].element.val() || "").length > 0) {
  1442. this.pickers[k++].setUTCDate(new_date);
  1443. }
  1444. }
  1445. this.updateDates();
  1446. delete this.updating;
  1447. },
  1448. destroy: function(){
  1449. $.map(this.pickers, function(p){ p.destroy(); });
  1450. $(this.inputs).off('changeDate', this.dateUpdated);
  1451. delete this.element.data().datepicker;
  1452. },
  1453. remove: alias('destroy', 'Method `remove` is deprecated and will be removed in version 2.0. Use `destroy` instead')
  1454. };
  1455. function opts_from_el(el, prefix){
  1456. // Derive options from element data-attrs
  1457. var data = $(el).data(),
  1458. out = {}, inkey,
  1459. replace = new RegExp('^' + prefix.toLowerCase() + '([A-Z])');
  1460. prefix = new RegExp('^' + prefix.toLowerCase());
  1461. function re_lower(_,a){
  1462. return a.toLowerCase();
  1463. }
  1464. for (var key in data)
  1465. if (prefix.test(key)){
  1466. inkey = key.replace(replace, re_lower);
  1467. out[inkey] = data[key];
  1468. }
  1469. return out;
  1470. }
  1471. function opts_from_locale(lang){
  1472. // Derive options from locale plugins
  1473. var out = {};
  1474. // Check if "de-DE" style date is available, if not language should
  1475. // fallback to 2 letter code eg "de"
  1476. if (!dates[lang]){
  1477. lang = lang.split('-')[0];
  1478. if (!dates[lang])
  1479. return;
  1480. }
  1481. var d = dates[lang];
  1482. $.each(locale_opts, function(i,k){
  1483. if (k in d)
  1484. out[k] = d[k];
  1485. });
  1486. return out;
  1487. }
  1488. var old = $.fn.datepicker;
  1489. var datepickerPlugin = function(option){
  1490. var args = Array.apply(null, arguments);
  1491. args.shift();
  1492. var internal_return;
  1493. this.each(function(){
  1494. var $this = $(this),
  1495. data = $this.data('datepicker'),
  1496. options = typeof option === 'object' && option;
  1497. if (!data){
  1498. var elopts = opts_from_el(this, 'date'),
  1499. // Preliminary otions
  1500. xopts = $.extend({}, defaults, elopts, options),
  1501. locopts = opts_from_locale(xopts.language),
  1502. // Options priority: js args, data-attrs, locales, defaults
  1503. opts = $.extend({}, defaults, locopts, elopts, options);
  1504. if ($this.hasClass('input-daterange') || opts.inputs){
  1505. $.extend(opts, {
  1506. inputs: opts.inputs || $this.find('input').toArray()
  1507. });
  1508. data = new DateRangePicker(this, opts);
  1509. }
  1510. else {
  1511. data = new Datepicker(this, opts);
  1512. }
  1513. $this.data('datepicker', data);
  1514. }
  1515. if (typeof option === 'string' && typeof data[option] === 'function'){
  1516. internal_return = data[option].apply(data, args);
  1517. }
  1518. });
  1519. if (
  1520. internal_return === undefined ||
  1521. internal_return instanceof Datepicker ||
  1522. internal_return instanceof DateRangePicker
  1523. )
  1524. return this;
  1525. if (this.length > 1)
  1526. throw new Error('Using only allowed for the collection of a single element (' + option + ' function)');
  1527. else
  1528. return internal_return;
  1529. };
  1530. $.fn.datepicker = datepickerPlugin;
  1531. var defaults = $.fn.datepicker.defaults = {
  1532. assumeNearbyYear: false,
  1533. autoclose: false,
  1534. beforeShowDay: $.noop,
  1535. beforeShowMonth: $.noop,
  1536. beforeShowYear: $.noop,
  1537. beforeShowDecade: $.noop,
  1538. beforeShowCentury: $.noop,
  1539. calendarWeeks: false,
  1540. clearBtn: false,
  1541. toggleActive: false,
  1542. daysOfWeekDisabled: [],
  1543. daysOfWeekHighlighted: [],
  1544. datesDisabled: [],
  1545. endDate: Infinity,
  1546. forceParse: true,
  1547. format: 'mm/dd/yyyy',
  1548. isInline: null,
  1549. keepEmptyValues: false,
  1550. keyboardNavigation: true,
  1551. language: 'en',
  1552. minViewMode: 0,
  1553. maxViewMode: 4,
  1554. multidate: false,
  1555. multidateSeparator: ',',
  1556. orientation: "auto",
  1557. rtl: false,
  1558. startDate: -Infinity,
  1559. startView: 0,
  1560. todayBtn: false,
  1561. todayHighlight: false,
  1562. updateViewDate: true,
  1563. weekStart: 0,
  1564. disableTouchKeyboard: false,
  1565. enableOnReadonly: true,
  1566. showOnFocus: true,
  1567. zIndexOffset: 10,
  1568. container: 'body',
  1569. immediateUpdates: false,
  1570. title: '',
  1571. templates: {
  1572. leftArrow: '&#x00AB;',
  1573. rightArrow: '&#x00BB;'
  1574. },
  1575. showWeekDays: true
  1576. };
  1577. var locale_opts = $.fn.datepicker.locale_opts = [
  1578. 'format',
  1579. 'rtl',
  1580. 'weekStart'
  1581. ];
  1582. $.fn.datepicker.Constructor = Datepicker;
  1583. var dates = $.fn.datepicker.dates = {
  1584. en: {
  1585. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
  1586. daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
  1587. daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
  1588. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  1589. monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  1590. today: "Today",
  1591. clear: "Clear",
  1592. titleFormat: "MM yyyy"
  1593. }
  1594. };
  1595. var DPGlobal = {
  1596. viewModes: [
  1597. {
  1598. names: ['days', 'month'],
  1599. clsName: 'days',
  1600. e: 'changeMonth'
  1601. },
  1602. {
  1603. names: ['months', 'year'],
  1604. clsName: 'months',
  1605. e: 'changeYear',
  1606. navStep: 1
  1607. },
  1608. {
  1609. names: ['years', 'decade'],
  1610. clsName: 'years',
  1611. e: 'changeDecade',
  1612. navStep: 10
  1613. },
  1614. {
  1615. names: ['decades', 'century'],
  1616. clsName: 'decades',
  1617. e: 'changeCentury',
  1618. navStep: 100
  1619. },
  1620. {
  1621. names: ['centuries', 'millennium'],
  1622. clsName: 'centuries',
  1623. e: 'changeMillennium',
  1624. navStep: 1000
  1625. }
  1626. ],
  1627. validParts: /dd?|DD?|mm?|MM?|yy(?:yy)?/g,
  1628. nonpunctuation: /[^ -\/:-@\u5e74\u6708\u65e5\[-`{-~\t\n\r]+/g,
  1629. parseFormat: function(format){
  1630. if (typeof format.toValue === 'function' && typeof format.toDisplay === 'function')
  1631. return format;
  1632. // IE treats \0 as a string end in inputs (truncating the value),
  1633. // so it's a bad format delimiter, anyway
  1634. var separators = format.replace(this.validParts, '\0').split('\0'),
  1635. parts = format.match(this.validParts);
  1636. if (!separators || !separators.length || !parts || parts.length === 0){
  1637. throw new Error("Invalid date format.");
  1638. }
  1639. return {separators: separators, parts: parts};
  1640. },
  1641. parseDate: function(date, format, language, assumeNearby){
  1642. if (!date)
  1643. return undefined;
  1644. if (date instanceof Date)
  1645. return date;
  1646. if (typeof format === 'string')
  1647. format = DPGlobal.parseFormat(format);
  1648. if (format.toValue)
  1649. return format.toValue(date, format, language);
  1650. var fn_map = {
  1651. d: 'moveDay',
  1652. m: 'moveMonth',
  1653. w: 'moveWeek',
  1654. y: 'moveYear'
  1655. },
  1656. dateAliases = {
  1657. yesterday: '-1d',
  1658. today: '+0d',
  1659. tomorrow: '+1d'
  1660. },
  1661. parts, part, dir, i, fn;
  1662. if (date in dateAliases){
  1663. date = dateAliases[date];
  1664. }
  1665. if (/^[\-+]\d+[dmwy]([\s,]+[\-+]\d+[dmwy])*$/i.test(date)){
  1666. parts = date.match(/([\-+]\d+)([dmwy])/gi);
  1667. date = new Date();
  1668. for (i=0; i < parts.length; i++){
  1669. part = parts[i].match(/([\-+]\d+)([dmwy])/i);
  1670. dir = Number(part[1]);
  1671. fn = fn_map[part[2].toLowerCase()];
  1672. date = Datepicker.prototype[fn](date, dir);
  1673. }
  1674. return Datepicker.prototype._zero_utc_time(date);
  1675. }
  1676. parts = date && date.match(this.nonpunctuation) || [];
  1677. function applyNearbyYear(year, threshold){
  1678. if (threshold === true)
  1679. threshold = 10;
  1680. // if year is 2 digits or less, than the user most likely is trying to get a recent century
  1681. if (year < 100){
  1682. year += 2000;
  1683. // if the new year is more than threshold years in advance, use last century
  1684. if (year > ((new Date()).getFullYear()+threshold)){
  1685. year -= 100;
  1686. }
  1687. }
  1688. return year;
  1689. }
  1690. var parsed = {},
  1691. setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
  1692. setters_map = {
  1693. yyyy: function(d,v){
  1694. return d.setUTCFullYear(assumeNearby ? applyNearbyYear(v, assumeNearby) : v);
  1695. },
  1696. m: function(d,v){
  1697. if (isNaN(d))
  1698. return d;
  1699. v -= 1;
  1700. while (v < 0) v += 12;
  1701. v %= 12;
  1702. d.setUTCMonth(v);
  1703. while (d.getUTCMonth() !== v)
  1704. d.setUTCDate(d.getUTCDate()-1);
  1705. return d;
  1706. },
  1707. d: function(d,v){
  1708. return d.setUTCDate(v);
  1709. }
  1710. },
  1711. val, filtered;
  1712. setters_map['yy'] = setters_map['yyyy'];
  1713. setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
  1714. setters_map['dd'] = setters_map['d'];
  1715. date = UTCToday();
  1716. var fparts = format.parts.slice();
  1717. // Remove noop parts
  1718. if (parts.length !== fparts.length){
  1719. fparts = $(fparts).filter(function(i,p){
  1720. return $.inArray(p, setters_order) !== -1;
  1721. }).toArray();
  1722. }
  1723. // Process remainder
  1724. function match_part(){
  1725. var m = this.slice(0, parts[i].length),
  1726. p = parts[i].slice(0, m.length);
  1727. return m.toLowerCase() === p.toLowerCase();
  1728. }
  1729. if (parts.length === fparts.length){
  1730. var cnt;
  1731. for (i=0, cnt = fparts.length; i < cnt; i++){
  1732. val = parseInt(parts[i], 10);
  1733. part = fparts[i];
  1734. if (isNaN(val)){
  1735. switch (part){
  1736. case 'MM':
  1737. filtered = $(dates[language].months).filter(match_part);
  1738. val = $.inArray(filtered[0], dates[language].months) + 1;
  1739. break;
  1740. case 'M':
  1741. filtered = $(dates[language].monthsShort).filter(match_part);
  1742. val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
  1743. break;
  1744. }
  1745. }
  1746. parsed[part] = val;
  1747. }
  1748. var _date, s;
  1749. for (i=0; i < setters_order.length; i++){
  1750. s = setters_order[i];
  1751. if (s in parsed && !isNaN(parsed[s])){
  1752. _date = new Date(date);
  1753. setters_map[s](_date, parsed[s]);
  1754. if (!isNaN(_date))
  1755. date = _date;
  1756. }
  1757. }
  1758. }
  1759. return date;
  1760. },
  1761. formatDate: function(date, format, language){
  1762. if (!date)
  1763. return '';
  1764. if (typeof format === 'string')
  1765. format = DPGlobal.parseFormat(format);
  1766. if (format.toDisplay)
  1767. return format.toDisplay(date, format, language);
  1768. var val = {
  1769. d: date.getUTCDate(),
  1770. D: dates[language].daysShort[date.getUTCDay()],
  1771. DD: dates[language].days[date.getUTCDay()],
  1772. m: date.getUTCMonth() + 1,
  1773. M: dates[language].monthsShort[date.getUTCMonth()],
  1774. MM: dates[language].months[date.getUTCMonth()],
  1775. yy: date.getUTCFullYear().toString().substring(2),
  1776. yyyy: date.getUTCFullYear()
  1777. };
  1778. val.dd = (val.d < 10 ? '0' : '') + val.d;
  1779. val.mm = (val.m < 10 ? '0' : '') + val.m;
  1780. date = [];
  1781. var seps = $.extend([], format.separators);
  1782. for (var i=0, cnt = format.parts.length; i <= cnt; i++){
  1783. if (seps.length)
  1784. date.push(seps.shift());
  1785. date.push(val[format.parts[i]]);
  1786. }
  1787. return date.join('');
  1788. },
  1789. headTemplate: '<thead>'+
  1790. '<tr>'+
  1791. '<th colspan="7" class="datepicker-title"></th>'+
  1792. '</tr>'+
  1793. '<tr>'+
  1794. '<th class="prev">'+defaults.templates.leftArrow+'</th>'+
  1795. '<th colspan="5" class="datepicker-switch"></th>'+
  1796. '<th class="next">'+defaults.templates.rightArrow+'</th>'+
  1797. '</tr>'+
  1798. '</thead>',
  1799. contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
  1800. footTemplate: '<tfoot>'+
  1801. '<tr>'+
  1802. '<th colspan="7" class="today"></th>'+
  1803. '</tr>'+
  1804. '<tr>'+
  1805. '<th colspan="7" class="clear"></th>'+
  1806. '</tr>'+
  1807. '</tfoot>'
  1808. };
  1809. DPGlobal.template = '<div class="datepicker">'+
  1810. '<div class="datepicker-days">'+
  1811. '<table class="table-condensed">'+
  1812. DPGlobal.headTemplate+
  1813. '<tbody></tbody>'+
  1814. DPGlobal.footTemplate+
  1815. '</table>'+
  1816. '</div>'+
  1817. '<div class="datepicker-months">'+
  1818. '<table class="table-condensed">'+
  1819. DPGlobal.headTemplate+
  1820. DPGlobal.contTemplate+
  1821. DPGlobal.footTemplate+
  1822. '</table>'+
  1823. '</div>'+
  1824. '<div class="datepicker-years">'+
  1825. '<table class="table-condensed">'+
  1826. DPGlobal.headTemplate+
  1827. DPGlobal.contTemplate+
  1828. DPGlobal.footTemplate+
  1829. '</table>'+
  1830. '</div>'+
  1831. '<div class="datepicker-decades">'+
  1832. '<table class="table-condensed">'+
  1833. DPGlobal.headTemplate+
  1834. DPGlobal.contTemplate+
  1835. DPGlobal.footTemplate+
  1836. '</table>'+
  1837. '</div>'+
  1838. '<div class="datepicker-centuries">'+
  1839. '<table class="table-condensed">'+
  1840. DPGlobal.headTemplate+
  1841. DPGlobal.contTemplate+
  1842. DPGlobal.footTemplate+
  1843. '</table>'+
  1844. '</div>'+
  1845. '</div>';
  1846. $.fn.datepicker.DPGlobal = DPGlobal;
  1847. /* DATEPICKER NO CONFLICT
  1848. * =================== */
  1849. $.fn.datepicker.noConflict = function(){
  1850. $.fn.datepicker = old;
  1851. return this;
  1852. };
  1853. /* DATEPICKER VERSION
  1854. * =================== */
  1855. $.fn.datepicker.version = '1.10.0';
  1856. $.fn.datepicker.deprecated = function(msg){
  1857. var console = window.console;
  1858. if (console && console.warn) {
  1859. console.warn('DEPRECATED: ' + msg);
  1860. }
  1861. };
  1862. /* DATEPICKER DATA-API
  1863. * ================== */
  1864. $(document).on(
  1865. 'focus.datepicker.data-api click.datepicker.data-api',
  1866. '[data-provide="datepicker"]',
  1867. function(e){
  1868. var $this = $(this);
  1869. if ($this.data('datepicker'))
  1870. return;
  1871. e.preventDefault();
  1872. // component click requires us to explicitly show it
  1873. datepickerPlugin.call($this, 'show');
  1874. }
  1875. );
  1876. $(function(){
  1877. datepickerPlugin.call($('[data-provide="datepicker-inline"]'));
  1878. });
  1879. }));