暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

bootstrap-datepicker.js 56KB

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