bootstrap-datepicker.js 57 KB

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