daterangepicker.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. /**
  2. * @version: 1.3.19
  3. * @author: Dan Grossman http://www.dangrossman.info/
  4. * @copyright: Copyright (c) 2012-2015 Dan Grossman. All rights reserved.
  5. * @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
  6. * @website: https://www.improvely.com/
  7. */
  8. (function(root, factory) {
  9. if (typeof define === 'function' && define.amd) {
  10. define(['moment', 'jquery', 'exports'], function(momentjs, $, exports) {
  11. root.daterangepicker = factory(root, exports, momentjs, $);
  12. });
  13. } else if (typeof exports !== 'undefined') {
  14. var momentjs = require('moment');
  15. var jQuery;
  16. try {
  17. jQuery = require('jquery');
  18. } catch (err) {
  19. jQuery = window.jQuery;
  20. if (!jQuery) throw new Error('jQuery dependency not found');
  21. }
  22. factory(root, exports, momentjs, jQuery);
  23. // Finally, as a browser global.
  24. } else {
  25. root.daterangepicker = factory(root, {}, root.moment, (root.jQuery || root.Zepto || root.ender || root.$));
  26. }
  27. }(this, function(root, daterangepicker, moment, $) {
  28. var DateRangePicker = function (element, options, cb) {
  29. // by default, the daterangepicker element is placed at the bottom of HTML body
  30. this.parentEl = 'body';
  31. //element that triggered the date range picker
  32. this.element = $(element);
  33. //tracks visible state
  34. this.isShowing = false;
  35. //create the picker HTML object
  36. var DRPTemplate = '<div class="daterangepicker dropdown-menu">' +
  37. '<div class="calendar first left"></div>' +
  38. '<div class="calendar second right"></div>' +
  39. '<div class="ranges">' +
  40. '<div class="range_inputs">' +
  41. '<div class="daterangepicker_start_input">' +
  42. '<label for="daterangepicker_start"></label>' +
  43. '<input class="input-mini" type="text" name="daterangepicker_start" value="" />' +
  44. '</div>' +
  45. '<div class="daterangepicker_end_input">' +
  46. '<label for="daterangepicker_end"></label>' +
  47. '<input class="input-mini" type="text" name="daterangepicker_end" value="" />' +
  48. '</div>' +
  49. '<button class="applyBtn" disabled="disabled"></button>&nbsp;' +
  50. '<button class="cancelBtn"></button>' +
  51. '</div>' +
  52. '</div>' +
  53. '</div>';
  54. //custom options
  55. if (typeof options !== 'object' || options === null)
  56. options = {};
  57. this.parentEl = (typeof options === 'object' && options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl);
  58. this.container = $(DRPTemplate).appendTo(this.parentEl);
  59. this.setOptions(options, cb);
  60. //apply CSS classes and labels to buttons
  61. var c = this.container;
  62. $.each(this.buttonClasses, function (idx, val) {
  63. c.find('button').addClass(val);
  64. });
  65. this.container.find('.daterangepicker_start_input label').html(this.locale.fromLabel);
  66. this.container.find('.daterangepicker_end_input label').html(this.locale.toLabel);
  67. if (this.applyClass.length)
  68. this.container.find('.applyBtn').addClass(this.applyClass);
  69. if (this.cancelClass.length)
  70. this.container.find('.cancelBtn').addClass(this.cancelClass);
  71. this.container.find('.applyBtn').html(this.locale.applyLabel);
  72. this.container.find('.cancelBtn').html(this.locale.cancelLabel);
  73. //event listeners
  74. this.container.find('.calendar')
  75. .on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this))
  76. .on('click.daterangepicker', '.next', $.proxy(this.clickNext, this))
  77. .on('click.daterangepicker', 'td.available', $.proxy(this.clickDate, this))
  78. .on('mouseenter.daterangepicker', 'td.available', $.proxy(this.hoverDate, this))
  79. .on('mouseleave.daterangepicker', 'td.available', $.proxy(this.updateFormInputs, this))
  80. .on('change.daterangepicker', 'select.yearselect', $.proxy(this.updateMonthYear, this))
  81. .on('change.daterangepicker', 'select.monthselect', $.proxy(this.updateMonthYear, this))
  82. .on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.secondselect,select.ampmselect', $.proxy(this.updateTime, this));
  83. this.container.find('.ranges')
  84. .on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this))
  85. .on('click.daterangepicker', 'button.cancelBtn', $.proxy(this.clickCancel, this))
  86. .on('click.daterangepicker', '.daterangepicker_start_input,.daterangepicker_end_input', $.proxy(this.showCalendars, this))
  87. .on('change.daterangepicker', '.daterangepicker_start_input,.daterangepicker_end_input', $.proxy(this.inputsChanged, this))
  88. .on('keydown.daterangepicker', '.daterangepicker_start_input,.daterangepicker_end_input', $.proxy(this.inputsKeydown, this))
  89. .on('click.daterangepicker', 'li', $.proxy(this.clickRange, this))
  90. .on('mouseenter.daterangepicker', 'li', $.proxy(this.enterRange, this))
  91. .on('mouseleave.daterangepicker', 'li', $.proxy(this.updateFormInputs, this));
  92. if (this.element.is('input')) {
  93. this.element.on({
  94. 'click.daterangepicker': $.proxy(this.show, this),
  95. 'focus.daterangepicker': $.proxy(this.show, this),
  96. 'keyup.daterangepicker': $.proxy(this.updateFromControl, this)
  97. });
  98. } else {
  99. this.element.on('click.daterangepicker', $.proxy(this.toggle, this));
  100. }
  101. };
  102. DateRangePicker.prototype = {
  103. constructor: DateRangePicker,
  104. setOptions: function(options, callback) {
  105. this.startDate = moment().startOf('day');
  106. this.endDate = moment().endOf('day');
  107. this.timeZone = moment().utcOffset();
  108. this.minDate = false;
  109. this.maxDate = false;
  110. this.dateLimit = false;
  111. this.showDropdowns = false;
  112. this.showWeekNumbers = false;
  113. this.timePicker = false;
  114. this.timePickerSeconds = false;
  115. this.timePickerIncrement = 30;
  116. this.timePicker12Hour = true;
  117. this.singleDatePicker = false;
  118. this.ranges = {};
  119. this.opens = 'right';
  120. if (this.element.hasClass('pull-right'))
  121. this.opens = 'left';
  122. this.buttonClasses = ['btn', 'btn-small btn-sm'];
  123. this.applyClass = 'btn-success';
  124. this.cancelClass = 'btn-default';
  125. this.format = 'MM/DD/YYYY';
  126. this.separator = ' - ';
  127. this.locale = {
  128. applyLabel: 'Apply',
  129. cancelLabel: 'Cancel',
  130. fromLabel: 'From',
  131. toLabel: 'To',
  132. weekLabel: 'W',
  133. customRangeLabel: 'Custom Range',
  134. daysOfWeek: moment.weekdaysMin(),
  135. monthNames: moment.monthsShort(),
  136. firstDay: moment.localeData()._week.dow
  137. };
  138. this.cb = function () { };
  139. if (typeof options.format === 'string')
  140. this.format = options.format;
  141. if (typeof options.separator === 'string')
  142. this.separator = options.separator;
  143. if (typeof options.startDate === 'string')
  144. this.startDate = moment(options.startDate, this.format);
  145. if (typeof options.endDate === 'string')
  146. this.endDate = moment(options.endDate, this.format);
  147. if (typeof options.minDate === 'string')
  148. this.minDate = moment(options.minDate, this.format);
  149. if (typeof options.maxDate === 'string')
  150. this.maxDate = moment(options.maxDate, this.format);
  151. if (typeof options.startDate === 'object')
  152. this.startDate = moment(options.startDate);
  153. if (typeof options.endDate === 'object')
  154. this.endDate = moment(options.endDate);
  155. if (typeof options.minDate === 'object')
  156. this.minDate = moment(options.minDate);
  157. if (typeof options.maxDate === 'object')
  158. this.maxDate = moment(options.maxDate);
  159. if (typeof options.applyClass === 'string')
  160. this.applyClass = options.applyClass;
  161. if (typeof options.cancelClass === 'string')
  162. this.cancelClass = options.cancelClass;
  163. if (typeof options.dateLimit === 'object')
  164. this.dateLimit = options.dateLimit;
  165. if (typeof options.locale === 'object') {
  166. if (typeof options.locale.daysOfWeek === 'object') {
  167. // Create a copy of daysOfWeek to avoid modification of original
  168. // options object for reusability in multiple daterangepicker instances
  169. this.locale.daysOfWeek = options.locale.daysOfWeek.slice();
  170. }
  171. if (typeof options.locale.monthNames === 'object') {
  172. this.locale.monthNames = options.locale.monthNames.slice();
  173. }
  174. if (typeof options.locale.firstDay === 'number') {
  175. this.locale.firstDay = options.locale.firstDay;
  176. }
  177. if (typeof options.locale.applyLabel === 'string') {
  178. this.locale.applyLabel = options.locale.applyLabel;
  179. }
  180. if (typeof options.locale.cancelLabel === 'string') {
  181. this.locale.cancelLabel = options.locale.cancelLabel;
  182. }
  183. if (typeof options.locale.fromLabel === 'string') {
  184. this.locale.fromLabel = options.locale.fromLabel;
  185. }
  186. if (typeof options.locale.toLabel === 'string') {
  187. this.locale.toLabel = options.locale.toLabel;
  188. }
  189. if (typeof options.locale.weekLabel === 'string') {
  190. this.locale.weekLabel = options.locale.weekLabel;
  191. }
  192. if (typeof options.locale.customRangeLabel === 'string') {
  193. this.locale.customRangeLabel = options.locale.customRangeLabel;
  194. }
  195. }
  196. if (typeof options.opens === 'string')
  197. this.opens = options.opens;
  198. if (typeof options.showWeekNumbers === 'boolean') {
  199. this.showWeekNumbers = options.showWeekNumbers;
  200. }
  201. if (typeof options.buttonClasses === 'string') {
  202. this.buttonClasses = [options.buttonClasses];
  203. }
  204. if (typeof options.buttonClasses === 'object') {
  205. this.buttonClasses = options.buttonClasses;
  206. }
  207. if (typeof options.showDropdowns === 'boolean') {
  208. this.showDropdowns = options.showDropdowns;
  209. }
  210. if (typeof options.singleDatePicker === 'boolean') {
  211. this.singleDatePicker = options.singleDatePicker;
  212. if (this.singleDatePicker) {
  213. this.endDate = this.startDate.clone();
  214. }
  215. }
  216. if (typeof options.timePicker === 'boolean') {
  217. this.timePicker = options.timePicker;
  218. }
  219. if (typeof options.timePickerSeconds === 'boolean') {
  220. this.timePickerSeconds = options.timePickerSeconds;
  221. }
  222. if (typeof options.timePickerIncrement === 'number') {
  223. this.timePickerIncrement = options.timePickerIncrement;
  224. }
  225. if (typeof options.timePicker12Hour === 'boolean') {
  226. this.timePicker12Hour = options.timePicker12Hour;
  227. }
  228. // update day names order to firstDay
  229. if (this.locale.firstDay != 0) {
  230. var iterator = this.locale.firstDay;
  231. while (iterator > 0) {
  232. this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift());
  233. iterator--;
  234. }
  235. }
  236. var start, end, range;
  237. //if no start/end dates set, check if an input element contains initial values
  238. if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') {
  239. if ($(this.element).is('input[type=text]')) {
  240. var val = $(this.element).val(),
  241. split = val.split(this.separator);
  242. start = end = null;
  243. if (split.length == 2) {
  244. start = moment(split[0], this.format);
  245. end = moment(split[1], this.format);
  246. } else if (this.singleDatePicker && val !== "") {
  247. start = moment(val, this.format);
  248. end = moment(val, this.format);
  249. }
  250. if (start !== null && end !== null) {
  251. this.startDate = start;
  252. this.endDate = end;
  253. }
  254. }
  255. }
  256. // bind the time zone used to build the calendar to either the timeZone passed in through the options or the zone of the startDate (which will be the local time zone by default)
  257. if (typeof options.timeZone === 'string' || typeof options.timeZone === 'number') {
  258. this.timeZone = options.timeZone;
  259. this.startDate.utcOffset(this.timeZone);
  260. this.endDate.utcOffset(this.timeZone);
  261. } else {
  262. this.timeZone = moment(this.startDate).utcOffset();
  263. }
  264. if (typeof options.ranges === 'object') {
  265. for (range in options.ranges) {
  266. if (typeof options.ranges[range][0] === 'string')
  267. start = moment(options.ranges[range][0], this.format);
  268. else
  269. start = moment(options.ranges[range][0]);
  270. if (typeof options.ranges[range][1] === 'string')
  271. end = moment(options.ranges[range][1], this.format);
  272. else
  273. end = moment(options.ranges[range][1]);
  274. // If we have a min/max date set, bound this range
  275. // to it, but only if it would otherwise fall
  276. // outside of the min/max.
  277. if (this.minDate && start.isBefore(this.minDate))
  278. start = moment(this.minDate);
  279. if (this.maxDate && end.isAfter(this.maxDate))
  280. end = moment(this.maxDate);
  281. // If the end of the range is before the minimum (if min is set) OR
  282. // the start of the range is after the max (also if set) don't display this
  283. // range option.
  284. if ((this.minDate && end.isBefore(this.minDate)) || (this.maxDate && start.isAfter(this.maxDate))) {
  285. continue;
  286. }
  287. this.ranges[range] = [start, end];
  288. }
  289. var list = '<ul>';
  290. for (range in this.ranges) {
  291. list += '<li>' + range + '</li>';
  292. }
  293. list += '<li>' + this.locale.customRangeLabel + '</li>';
  294. list += '</ul>';
  295. this.container.find('.ranges ul').remove();
  296. this.container.find('.ranges').prepend(list);
  297. }
  298. if (typeof callback === 'function') {
  299. this.cb = callback;
  300. }
  301. if (!this.timePicker) {
  302. this.startDate = this.startDate.startOf('day');
  303. this.endDate = this.endDate.endOf('day');
  304. }
  305. if (this.singleDatePicker) {
  306. this.opens = 'right';
  307. this.container.addClass('single');
  308. this.container.find('.calendar.right').show();
  309. this.container.find('.calendar.left').hide();
  310. if (!this.timePicker) {
  311. this.container.find('.ranges').hide();
  312. } else {
  313. this.container.find('.ranges .daterangepicker_start_input, .ranges .daterangepicker_end_input').hide();
  314. }
  315. if (!this.container.find('.calendar.right').hasClass('single'))
  316. this.container.find('.calendar.right').addClass('single');
  317. } else {
  318. this.container.removeClass('single');
  319. this.container.find('.calendar.right').removeClass('single');
  320. this.container.find('.ranges').show();
  321. }
  322. this.oldStartDate = this.startDate.clone();
  323. this.oldEndDate = this.endDate.clone();
  324. this.oldChosenLabel = this.chosenLabel;
  325. this.leftCalendar = {
  326. month: moment([this.startDate.year(), this.startDate.month(), 1, this.startDate.hour(), this.startDate.minute(), this.startDate.second()]),
  327. calendar: []
  328. };
  329. this.rightCalendar = {
  330. month: moment([this.endDate.year(), this.endDate.month(), 1, this.endDate.hour(), this.endDate.minute(), this.endDate.second()]),
  331. calendar: []
  332. };
  333. if (this.opens == 'right' || this.opens == 'center') {
  334. //swap calendar positions
  335. var first = this.container.find('.calendar.first');
  336. var second = this.container.find('.calendar.second');
  337. if (second.hasClass('single')) {
  338. second.removeClass('single');
  339. first.addClass('single');
  340. }
  341. first.removeClass('left').addClass('right');
  342. second.removeClass('right').addClass('left');
  343. if (this.singleDatePicker) {
  344. first.show();
  345. second.hide();
  346. }
  347. }
  348. if (typeof options.ranges === 'undefined' && !this.singleDatePicker) {
  349. this.container.addClass('show-calendar');
  350. }
  351. this.container.addClass('opens' + this.opens);
  352. this.updateView();
  353. this.updateCalendars();
  354. },
  355. setStartDate: function(startDate) {
  356. if (typeof startDate === 'string')
  357. this.startDate = moment(startDate, this.format).utcOffset(this.timeZone);
  358. if (typeof startDate === 'object')
  359. this.startDate = moment(startDate);
  360. if (!this.timePicker)
  361. this.startDate = this.startDate.startOf('day');
  362. this.oldStartDate = this.startDate.clone();
  363. this.updateView();
  364. this.updateCalendars();
  365. this.updateInputText();
  366. },
  367. setEndDate: function(endDate) {
  368. if (typeof endDate === 'string')
  369. this.endDate = moment(endDate, this.format).utcOffset(this.timeZone);
  370. if (typeof endDate === 'object')
  371. this.endDate = moment(endDate);
  372. if (!this.timePicker)
  373. this.endDate = this.endDate.endOf('day');
  374. this.oldEndDate = this.endDate.clone();
  375. this.updateView();
  376. this.updateCalendars();
  377. this.updateInputText();
  378. },
  379. updateView: function () {
  380. this.leftCalendar.month.month(this.startDate.month()).year(this.startDate.year()).hour(this.startDate.hour()).minute(this.startDate.minute());
  381. this.rightCalendar.month.month(this.endDate.month()).year(this.endDate.year()).hour(this.endDate.hour()).minute(this.endDate.minute());
  382. this.updateFormInputs();
  383. },
  384. updateFormInputs: function () {
  385. this.container.find('input[name=daterangepicker_start]').val(this.startDate.format(this.format));
  386. this.container.find('input[name=daterangepicker_end]').val(this.endDate.format(this.format));
  387. if (this.startDate.isSame(this.endDate) || this.startDate.isBefore(this.endDate)) {
  388. this.container.find('button.applyBtn').removeAttr('disabled');
  389. } else {
  390. this.container.find('button.applyBtn').attr('disabled', 'disabled');
  391. }
  392. },
  393. updateFromControl: function () {
  394. if (!this.element.is('input')) return;
  395. if (!this.element.val().length) return;
  396. var dateString = this.element.val().split(this.separator),
  397. start = null,
  398. end = null;
  399. if(dateString.length === 2) {
  400. start = moment(dateString[0], this.format).utcOffset(this.timeZone);
  401. end = moment(dateString[1], this.format).utcOffset(this.timeZone);
  402. }
  403. if (this.singleDatePicker || start === null || end === null) {
  404. start = moment(this.element.val(), this.format).utcOffset(this.timeZone);
  405. end = start;
  406. }
  407. if (end.isBefore(start)) return;
  408. this.oldStartDate = this.startDate.clone();
  409. this.oldEndDate = this.endDate.clone();
  410. this.startDate = start;
  411. this.endDate = end;
  412. if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
  413. this.notify();
  414. this.updateCalendars();
  415. },
  416. notify: function () {
  417. this.updateView();
  418. this.cb(this.startDate, this.endDate, this.chosenLabel);
  419. },
  420. move: function () {
  421. var parentOffset = { top: 0, left: 0 };
  422. var parentRightEdge = $(window).width();
  423. if (!this.parentEl.is('body')) {
  424. parentOffset = {
  425. top: this.parentEl.offset().top - this.parentEl.scrollTop(),
  426. left: this.parentEl.offset().left - this.parentEl.scrollLeft()
  427. };
  428. parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left;
  429. }
  430. if (this.opens == 'left') {
  431. this.container.css({
  432. top: this.element.offset().top + this.element.outerHeight() - parentOffset.top,
  433. right: parentRightEdge - this.element.offset().left - this.element.outerWidth(),
  434. left: 'auto'
  435. });
  436. if (this.container.offset().left < 0) {
  437. this.container.css({
  438. right: 'auto',
  439. left: 9
  440. });
  441. }
  442. } else if (this.opens == 'center') {
  443. this.container.css({
  444. top: this.element.offset().top + this.element.outerHeight() - parentOffset.top,
  445. left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
  446. - this.container.outerWidth() / 2,
  447. right: 'auto'
  448. });
  449. if (this.container.offset().left < 0) {
  450. this.container.css({
  451. right: 'auto',
  452. left: 9
  453. });
  454. }
  455. } else {
  456. this.container.css({
  457. top: this.element.offset().top + this.element.outerHeight() - parentOffset.top,
  458. left: this.element.offset().left - parentOffset.left,
  459. right: 'auto'
  460. });
  461. if (this.container.offset().left + this.container.outerWidth() > $(window).width()) {
  462. this.container.css({
  463. left: 'auto',
  464. right: 0
  465. });
  466. }
  467. }
  468. },
  469. toggle: function (e) {
  470. if (this.element.hasClass('active')) {
  471. this.hide();
  472. } else {
  473. this.show();
  474. }
  475. },
  476. show: function (e) {
  477. if (this.isShowing) return;
  478. this.element.addClass('active');
  479. this.container.show();
  480. this.move();
  481. // Create a click proxy that is private to this instance of datepicker, for unbinding
  482. this._outsideClickProxy = $.proxy(function (e) { this.outsideClick(e); }, this);
  483. // Bind global datepicker mousedown for hiding and
  484. $(document)
  485. .on('mousedown.daterangepicker', this._outsideClickProxy)
  486. // also support mobile devices
  487. .on('touchend.daterangepicker', this._outsideClickProxy)
  488. // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them
  489. .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)
  490. // and also close when focus changes to outside the picker (eg. tabbing between controls)
  491. .on('focusin.daterangepicker', this._outsideClickProxy);
  492. this.isShowing = true;
  493. this.element.trigger('show.daterangepicker', this);
  494. },
  495. outsideClick: function (e) {
  496. var target = $(e.target);
  497. // if the page is clicked anywhere except within the daterangerpicker/button
  498. // itself then call this.hide()
  499. if (
  500. // ie modal dialog fix
  501. e.type == "focusin" ||
  502. target.closest(this.element).length ||
  503. target.closest(this.container).length ||
  504. target.closest('.calendar-date').length
  505. ) return;
  506. this.hide();
  507. },
  508. hide: function (e) {
  509. if (!this.isShowing) return;
  510. $(document)
  511. .off('.daterangepicker');
  512. this.element.removeClass('active');
  513. this.container.hide();
  514. if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
  515. this.notify();
  516. this.oldStartDate = this.startDate.clone();
  517. this.oldEndDate = this.endDate.clone();
  518. this.isShowing = false;
  519. this.element.trigger('hide.daterangepicker', this);
  520. },
  521. enterRange: function (e) {
  522. // mouse pointer has entered a range label
  523. var label = e.target.innerHTML;
  524. if (label == this.locale.customRangeLabel) {
  525. this.updateView();
  526. } else {
  527. var dates = this.ranges[label];
  528. this.container.find('input[name=daterangepicker_start]').val(dates[0].format(this.format));
  529. this.container.find('input[name=daterangepicker_end]').val(dates[1].format(this.format));
  530. }
  531. },
  532. showCalendars: function() {
  533. this.container.addClass('show-calendar');
  534. this.move();
  535. this.element.trigger('showCalendar.daterangepicker', this);
  536. },
  537. hideCalendars: function() {
  538. this.container.removeClass('show-calendar');
  539. this.element.trigger('hideCalendar.daterangepicker', this);
  540. },
  541. // when a date is typed into the start to end date textboxes
  542. inputsChanged: function (e) {
  543. var el = $(e.target);
  544. var date = moment(el.val(), this.format);
  545. if (!date.isValid()) return;
  546. var startDate, endDate;
  547. if (el.attr('name') === 'daterangepicker_start') {
  548. startDate = (false !== this.minDate && date.isBefore(this.minDate)) ? this.minDate : date;
  549. endDate = this.endDate;
  550. } else {
  551. startDate = this.startDate;
  552. endDate = (false !== this.maxDate && date.isAfter(this.maxDate)) ? this.maxDate : date;
  553. }
  554. this.setCustomDates(startDate, endDate);
  555. },
  556. inputsKeydown: function(e) {
  557. if (e.keyCode === 13) {
  558. this.inputsChanged(e);
  559. this.notify();
  560. }
  561. },
  562. updateInputText: function() {
  563. if (this.element.is('input') && !this.singleDatePicker) {
  564. this.element.val(this.startDate.format(this.format) + this.separator + this.endDate.format(this.format));
  565. this.element.trigger('change');
  566. } else if (this.element.is('input')) {
  567. this.element.val(this.endDate.format(this.format));
  568. this.element.trigger('change');
  569. }
  570. },
  571. clickRange: function (e) {
  572. var label = e.target.innerHTML;
  573. this.chosenLabel = label;
  574. if (label == this.locale.customRangeLabel) {
  575. this.showCalendars();
  576. } else {
  577. var dates = this.ranges[label];
  578. this.startDate = dates[0];
  579. this.endDate = dates[1];
  580. if (!this.timePicker) {
  581. this.startDate.startOf('day');
  582. this.endDate.endOf('day');
  583. }
  584. this.leftCalendar.month.month(this.startDate.month()).year(this.startDate.year()).hour(this.startDate.hour()).minute(this.startDate.minute());
  585. this.rightCalendar.month.month(this.endDate.month()).year(this.endDate.year()).hour(this.endDate.hour()).minute(this.endDate.minute());
  586. this.updateCalendars();
  587. this.updateInputText();
  588. this.hideCalendars();
  589. this.hide();
  590. this.element.trigger('apply.daterangepicker', this);
  591. }
  592. },
  593. clickPrev: function (e) {
  594. var cal = $(e.target).parents('.calendar');
  595. if (cal.hasClass('left')) {
  596. this.leftCalendar.month.subtract(1, 'month');
  597. } else {
  598. this.rightCalendar.month.subtract(1, 'month');
  599. }
  600. this.updateCalendars();
  601. },
  602. clickNext: function (e) {
  603. var cal = $(e.target).parents('.calendar');
  604. if (cal.hasClass('left')) {
  605. this.leftCalendar.month.add(1, 'month');
  606. } else {
  607. this.rightCalendar.month.add(1, 'month');
  608. }
  609. this.updateCalendars();
  610. },
  611. hoverDate: function (e) {
  612. var title = $(e.target).attr('data-title');
  613. var row = title.substr(1, 1);
  614. var col = title.substr(3, 1);
  615. var cal = $(e.target).parents('.calendar');
  616. if (cal.hasClass('left')) {
  617. this.container.find('input[name=daterangepicker_start]').val(this.leftCalendar.calendar[row][col].format(this.format));
  618. } else {
  619. this.container.find('input[name=daterangepicker_end]').val(this.rightCalendar.calendar[row][col].format(this.format));
  620. }
  621. },
  622. setCustomDates: function(startDate, endDate) {
  623. this.chosenLabel = this.locale.customRangeLabel;
  624. if (startDate.isAfter(endDate)) {
  625. var difference = this.endDate.diff(this.startDate);
  626. endDate = moment(startDate).add(difference, 'ms');
  627. if (this.maxDate && endDate.isAfter(this.maxDate)) {
  628. endDate = this.maxDate;
  629. }
  630. }
  631. this.startDate = startDate;
  632. this.endDate = endDate;
  633. this.updateView();
  634. this.updateCalendars();
  635. },
  636. clickDate: function (e) {
  637. var title = $(e.target).attr('data-title');
  638. var row = title.substr(1, 1);
  639. var col = title.substr(3, 1);
  640. var cal = $(e.target).parents('.calendar');
  641. var startDate, endDate;
  642. if (cal.hasClass('left')) {
  643. startDate = this.leftCalendar.calendar[row][col];
  644. endDate = this.endDate;
  645. if (typeof this.dateLimit === 'object') {
  646. var maxDate = moment(startDate).add(this.dateLimit).startOf('day');
  647. if (endDate.isAfter(maxDate)) {
  648. endDate = maxDate;
  649. }
  650. }
  651. } else {
  652. startDate = this.startDate;
  653. endDate = this.rightCalendar.calendar[row][col];
  654. if (typeof this.dateLimit === 'object') {
  655. var minDate = moment(endDate).subtract(this.dateLimit).startOf('day');
  656. if (startDate.isBefore(minDate)) {
  657. startDate = minDate;
  658. }
  659. }
  660. }
  661. if (this.singleDatePicker && cal.hasClass('left')) {
  662. endDate = startDate.clone();
  663. } else if (this.singleDatePicker && cal.hasClass('right')) {
  664. startDate = endDate.clone();
  665. }
  666. cal.find('td').removeClass('active');
  667. $(e.target).addClass('active');
  668. this.setCustomDates(startDate, endDate);
  669. if (!this.timePicker)
  670. endDate.endOf('day');
  671. if (this.singleDatePicker && !this.timePicker)
  672. this.clickApply();
  673. },
  674. clickApply: function (e) {
  675. this.updateInputText();
  676. this.hide();
  677. this.element.trigger('apply.daterangepicker', this);
  678. },
  679. clickCancel: function (e) {
  680. this.startDate = this.oldStartDate;
  681. this.endDate = this.oldEndDate;
  682. this.chosenLabel = this.oldChosenLabel;
  683. this.updateView();
  684. this.updateCalendars();
  685. this.hide();
  686. this.element.trigger('cancel.daterangepicker', this);
  687. },
  688. updateMonthYear: function (e) {
  689. var isLeft = $(e.target).closest('.calendar').hasClass('left'),
  690. leftOrRight = isLeft ? 'left' : 'right',
  691. cal = this.container.find('.calendar.'+leftOrRight);
  692. // Month must be Number for new moment versions
  693. var month = parseInt(cal.find('.monthselect').val(), 10);
  694. var year = cal.find('.yearselect').val();
  695. if (!isLeft && !this.singleDatePicker) {
  696. if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) {
  697. month = this.startDate.month();
  698. year = this.startDate.year();
  699. }
  700. }
  701. if (this.minDate) {
  702. if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) {
  703. month = this.minDate.month();
  704. year = this.minDate.year();
  705. }
  706. }
  707. if (this.maxDate) {
  708. if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) {
  709. month = this.maxDate.month();
  710. year = this.maxDate.year();
  711. }
  712. }
  713. this[leftOrRight+'Calendar'].month.month(month).year(year);
  714. this.updateCalendars();
  715. },
  716. updateTime: function(e) {
  717. var cal = $(e.target).closest('.calendar'),
  718. isLeft = cal.hasClass('left');
  719. var hour = parseInt(cal.find('.hourselect').val(), 10);
  720. var minute = parseInt(cal.find('.minuteselect').val(), 10);
  721. var second = 0;
  722. if (this.timePickerSeconds) {
  723. second = parseInt(cal.find('.secondselect').val(), 10);
  724. }
  725. if (this.timePicker12Hour) {
  726. var ampm = cal.find('.ampmselect').val();
  727. if (ampm === 'PM' && hour < 12)
  728. hour += 12;
  729. if (ampm === 'AM' && hour === 12)
  730. hour = 0;
  731. }
  732. if (isLeft) {
  733. var start = this.startDate.clone();
  734. start.hour(hour);
  735. start.minute(minute);
  736. start.second(second);
  737. this.startDate = start;
  738. this.leftCalendar.month.hour(hour).minute(minute).second(second);
  739. if (this.singleDatePicker)
  740. this.endDate = start.clone();
  741. } else {
  742. var end = this.endDate.clone();
  743. end.hour(hour);
  744. end.minute(minute);
  745. end.second(second);
  746. this.endDate = end;
  747. if (this.singleDatePicker)
  748. this.startDate = end.clone();
  749. this.rightCalendar.month.hour(hour).minute(minute).second(second);
  750. }
  751. this.updateView();
  752. this.updateCalendars();
  753. },
  754. updateCalendars: function () {
  755. this.leftCalendar.calendar = this.buildCalendar(this.leftCalendar.month.month(), this.leftCalendar.month.year(), this.leftCalendar.month.hour(), this.leftCalendar.month.minute(), this.leftCalendar.month.second(), 'left');
  756. this.rightCalendar.calendar = this.buildCalendar(this.rightCalendar.month.month(), this.rightCalendar.month.year(), this.rightCalendar.month.hour(), this.rightCalendar.month.minute(), this.rightCalendar.month.second(), 'right');
  757. this.container.find('.calendar.left').empty().html(this.renderCalendar(this.leftCalendar.calendar, this.startDate, this.minDate, this.maxDate, 'left'));
  758. this.container.find('.calendar.right').empty().html(this.renderCalendar(this.rightCalendar.calendar, this.endDate, this.singleDatePicker ? this.minDate : this.startDate, this.maxDate, 'right'));
  759. this.container.find('.ranges li').removeClass('active');
  760. var customRange = true;
  761. var i = 0;
  762. for (var range in this.ranges) {
  763. if (this.timePicker) {
  764. if (this.startDate.isSame(this.ranges[range][0]) && this.endDate.isSame(this.ranges[range][1])) {
  765. customRange = false;
  766. this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')')
  767. .addClass('active').html();
  768. }
  769. } else {
  770. //ignore times when comparing dates if time picker is not enabled
  771. if (this.startDate.format('YYYY-MM-DD') == this.ranges[range][0].format('YYYY-MM-DD') && this.endDate.format('YYYY-MM-DD') == this.ranges[range][1].format('YYYY-MM-DD')) {
  772. customRange = false;
  773. this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')')
  774. .addClass('active').html();
  775. }
  776. }
  777. i++;
  778. }
  779. if (customRange) {
  780. this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
  781. this.showCalendars();
  782. }
  783. },
  784. buildCalendar: function (month, year, hour, minute, second, side) {
  785. var daysInMonth = moment([year, month]).daysInMonth();
  786. var firstDay = moment([year, month, 1]);
  787. var lastDay = moment([year, month, daysInMonth]);
  788. var lastMonth = moment(firstDay).subtract(1, 'month').month();
  789. var lastYear = moment(firstDay).subtract(1, 'month').year();
  790. var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth();
  791. var dayOfWeek = firstDay.day();
  792. var i;
  793. //initialize a 6 rows x 7 columns array for the calendar
  794. var calendar = [];
  795. calendar.firstDay = firstDay;
  796. calendar.lastDay = lastDay;
  797. for (i = 0; i < 6; i++) {
  798. calendar[i] = [];
  799. }
  800. //populate the calendar with date objects
  801. var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1;
  802. if (startDay > daysInLastMonth)
  803. startDay -= 7;
  804. if (dayOfWeek == this.locale.firstDay)
  805. startDay = daysInLastMonth - 6;
  806. var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]).utcOffset(this.timeZone);
  807. var col, row;
  808. for (i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) {
  809. if (i > 0 && col % 7 === 0) {
  810. col = 0;
  811. row++;
  812. }
  813. calendar[row][col] = curDate.clone().hour(hour);
  814. curDate.hour(12);
  815. if (this.minDate && calendar[row][col].format('YYYY-MM-DD') == this.minDate.format('YYYY-MM-DD') && calendar[row][col].isBefore(this.minDate) && side == 'left') {
  816. calendar[row][col] = this.minDate.clone();
  817. }
  818. if (this.maxDate && calendar[row][col].format('YYYY-MM-DD') == this.maxDate.format('YYYY-MM-DD') && calendar[row][col].isAfter(this.maxDate) && side == 'right') {
  819. calendar[row][col] = this.maxDate.clone();
  820. }
  821. }
  822. return calendar;
  823. },
  824. renderDropdowns: function (selected, minDate, maxDate) {
  825. var currentMonth = selected.month();
  826. var currentYear = selected.year();
  827. var maxYear = (maxDate && maxDate.year()) || (currentYear + 5);
  828. var minYear = (minDate && minDate.year()) || (currentYear - 50);
  829. var monthHtml = '<select class="monthselect">';
  830. var inMinYear = currentYear == minYear;
  831. var inMaxYear = currentYear == maxYear;
  832. for (var m = 0; m < 12; m++) {
  833. if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || m <= maxDate.month())) {
  834. monthHtml += "<option value='" + m + "'" +
  835. (m === currentMonth ? " selected='selected'" : "") +
  836. ">" + this.locale.monthNames[m] + "</option>";
  837. }
  838. }
  839. monthHtml += "</select>";
  840. var yearHtml = '<select class="yearselect">';
  841. for (var y = minYear; y <= maxYear; y++) {
  842. yearHtml += '<option value="' + y + '"' +
  843. (y === currentYear ? ' selected="selected"' : '') +
  844. '>' + y + '</option>';
  845. }
  846. yearHtml += '</select>';
  847. return monthHtml + yearHtml;
  848. },
  849. renderCalendar: function (calendar, selected, minDate, maxDate, side) {
  850. var html = '<div class="calendar-date">';
  851. html += '<table class="table-condensed">';
  852. html += '<thead>';
  853. html += '<tr>';
  854. // add empty cell for week number
  855. if (this.showWeekNumbers)
  856. html += '<th></th>';
  857. if (!minDate || minDate.isBefore(calendar.firstDay)) {
  858. html += '<th class="prev available"><i class="fa fa-arrow-left icon icon-arrow-left glyphicon glyphicon-arrow-left"></i></th>';
  859. } else {
  860. html += '<th></th>';
  861. }
  862. var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");
  863. if (this.showDropdowns) {
  864. dateHtml = this.renderDropdowns(calendar[1][1], minDate, maxDate);
  865. }
  866. html += '<th colspan="5" class="month">' + dateHtml + '</th>';
  867. if (!maxDate || maxDate.isAfter(calendar.lastDay)) {
  868. html += '<th class="next available"><i class="fa fa-arrow-right icon icon-arrow-right glyphicon glyphicon-arrow-right"></i></th>';
  869. } else {
  870. html += '<th></th>';
  871. }
  872. html += '</tr>';
  873. html += '<tr>';
  874. // add week number label
  875. if (this.showWeekNumbers)
  876. html += '<th class="week">' + this.locale.weekLabel + '</th>';
  877. $.each(this.locale.daysOfWeek, function (index, dayOfWeek) {
  878. html += '<th>' + dayOfWeek + '</th>';
  879. });
  880. html += '</tr>';
  881. html += '</thead>';
  882. html += '<tbody>';
  883. for (var row = 0; row < 6; row++) {
  884. html += '<tr>';
  885. // add week number
  886. if (this.showWeekNumbers)
  887. html += '<td class="week">' + calendar[row][0].week() + '</td>';
  888. for (var col = 0; col < 7; col++) {
  889. var cname = 'available ';
  890. cname += (calendar[row][col].month() == calendar[1][1].month()) ? '' : 'off';
  891. if ((minDate && calendar[row][col].isBefore(minDate, 'day')) || (maxDate && calendar[row][col].isAfter(maxDate, 'day'))) {
  892. cname = ' off disabled ';
  893. } else if (calendar[row][col].format('YYYY-MM-DD') == selected.format('YYYY-MM-DD')) {
  894. cname += ' active ';
  895. if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD')) {
  896. cname += ' start-date ';
  897. }
  898. if (calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD')) {
  899. cname += ' end-date ';
  900. }
  901. } else if (calendar[row][col] >= this.startDate && calendar[row][col] <= this.endDate) {
  902. cname += ' in-range ';
  903. if (calendar[row][col].isSame(this.startDate)) { cname += ' start-date '; }
  904. if (calendar[row][col].isSame(this.endDate)) { cname += ' end-date '; }
  905. }
  906. var title = 'r' + row + 'c' + col;
  907. html += '<td class="' + cname.replace(/\s+/g, ' ').replace(/^\s?(.*?)\s?$/, '$1') + '" data-title="' + title + '">' + calendar[row][col].date() + '</td>';
  908. }
  909. html += '</tr>';
  910. }
  911. html += '</tbody>';
  912. html += '</table>';
  913. html += '</div>';
  914. var i;
  915. if (this.timePicker) {
  916. html += '<div class="calendar-time">';
  917. html += '<select class="hourselect">';
  918. // Disallow selections before the minDate or after the maxDate
  919. var min_hour = 0;
  920. var max_hour = 23;
  921. if (minDate && (side == 'left' || this.singleDatePicker) && selected.format('YYYY-MM-DD') == minDate.format('YYYY-MM-DD')) {
  922. min_hour = minDate.hour();
  923. if (selected.hour() < min_hour)
  924. selected.hour(min_hour);
  925. if (this.timePicker12Hour && min_hour >= 12 && selected.hour() >= 12)
  926. min_hour -= 12;
  927. if (this.timePicker12Hour && min_hour == 12)
  928. min_hour = 1;
  929. }
  930. if (maxDate && (side == 'right' || this.singleDatePicker) && selected.format('YYYY-MM-DD') == maxDate.format('YYYY-MM-DD')) {
  931. max_hour = maxDate.hour();
  932. if (selected.hour() > max_hour)
  933. selected.hour(max_hour);
  934. if (this.timePicker12Hour && max_hour >= 12 && selected.hour() >= 12)
  935. max_hour -= 12;
  936. }
  937. var start = 0;
  938. var end = 23;
  939. var selected_hour = selected.hour();
  940. if (this.timePicker12Hour) {
  941. start = 1;
  942. end = 12;
  943. if (selected_hour >= 12)
  944. selected_hour -= 12;
  945. if (selected_hour === 0)
  946. selected_hour = 12;
  947. }
  948. for (i = start; i <= end; i++) {
  949. if (i == selected_hour) {
  950. html += '<option value="' + i + '" selected="selected">' + i + '</option>';
  951. } else if (i < min_hour || i > max_hour) {
  952. html += '<option value="' + i + '" disabled="disabled" class="disabled">' + i + '</option>';
  953. } else {
  954. html += '<option value="' + i + '">' + i + '</option>';
  955. }
  956. }
  957. html += '</select> : ';
  958. html += '<select class="minuteselect">';
  959. // Disallow selections before the minDate or after the maxDate
  960. var min_minute = 0;
  961. var max_minute = 59;
  962. if (minDate && (side == 'left' || this.singleDatePicker) && selected.format('YYYY-MM-DD h A') == minDate.format('YYYY-MM-DD h A')) {
  963. min_minute = minDate.minute();
  964. if (selected.minute() < min_minute)
  965. selected.minute(min_minute);
  966. }
  967. if (maxDate && (side == 'right' || this.singleDatePicker) && selected.format('YYYY-MM-DD h A') == maxDate.format('YYYY-MM-DD h A')) {
  968. max_minute = maxDate.minute();
  969. if (selected.minute() > max_minute)
  970. selected.minute(max_minute);
  971. }
  972. for (i = 0; i < 60; i += this.timePickerIncrement) {
  973. var num = i;
  974. if (num < 10)
  975. num = '0' + num;
  976. if (i == selected.minute()) {
  977. html += '<option value="' + i + '" selected="selected">' + num + '</option>';
  978. } else if (i < min_minute || i > max_minute) {
  979. html += '<option value="' + i + '" disabled="disabled" class="disabled">' + num + '</option>';
  980. } else {
  981. html += '<option value="' + i + '">' + num + '</option>';
  982. }
  983. }
  984. html += '</select> ';
  985. if (this.timePickerSeconds) {
  986. html += ': <select class="secondselect">';
  987. for (i = 0; i < 60; i += this.timePickerIncrement) {
  988. var num = i;
  989. if (num < 10)
  990. num = '0' + num;
  991. if (i == selected.second()) {
  992. html += '<option value="' + i + '" selected="selected">' + num + '</option>';
  993. } else {
  994. html += '<option value="' + i + '">' + num + '</option>';
  995. }
  996. }
  997. html += '</select>';
  998. }
  999. if (this.timePicker12Hour) {
  1000. html += '<select class="ampmselect">';
  1001. // Disallow selection before the minDate or after the maxDate
  1002. var am_html = '';
  1003. var pm_html = '';
  1004. if (minDate && (side == 'left' || this.singleDatePicker) && selected.format('YYYY-MM-DD') == minDate.format('YYYY-MM-DD') && minDate.hour() >= 12) {
  1005. am_html = ' disabled="disabled" class="disabled"';
  1006. }
  1007. if (maxDate && (side == 'right' || this.singleDatePicker) && selected.format('YYYY-MM-DD') == maxDate.format('YYYY-MM-DD') && maxDate.hour() < 12) {
  1008. pm_html = ' disabled="disabled" class="disabled"';
  1009. }
  1010. if (selected.hour() >= 12) {
  1011. html += '<option value="AM"' + am_html + '>AM</option><option value="PM" selected="selected"' + pm_html + '>PM</option>';
  1012. } else {
  1013. html += '<option value="AM" selected="selected"' + am_html + '>AM</option><option value="PM"' + pm_html + '>PM</option>';
  1014. }
  1015. html += '</select>';
  1016. }
  1017. html += '</div>';
  1018. }
  1019. return html;
  1020. },
  1021. remove: function() {
  1022. this.container.remove();
  1023. this.element.off('.daterangepicker');
  1024. this.element.removeData('daterangepicker');
  1025. }
  1026. };
  1027. $.fn.daterangepicker = function (options, cb) {
  1028. this.each(function () {
  1029. var el = $(this);
  1030. if (el.data('daterangepicker'))
  1031. el.data('daterangepicker').remove();
  1032. el.data('daterangepicker', new DateRangePicker(el, options, cb));
  1033. });
  1034. return this;
  1035. };
  1036. }));