官网 管理后台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

bootstrap-datepicker.js 57KB

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