sql-jarvis 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/CHANGELOG.md +228 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +775 -0
  7. data/Rakefile +1 -0
  8. data/app/assets/fonts/blazer/glyphicons-halflings-regular.eot +0 -0
  9. data/app/assets/fonts/blazer/glyphicons-halflings-regular.svg +288 -0
  10. data/app/assets/fonts/blazer/glyphicons-halflings-regular.ttf +0 -0
  11. data/app/assets/fonts/blazer/glyphicons-halflings-regular.woff +0 -0
  12. data/app/assets/fonts/blazer/glyphicons-halflings-regular.woff2 +0 -0
  13. data/app/assets/javascripts/blazer/Chart.js +14145 -0
  14. data/app/assets/javascripts/blazer/Sortable.js +1144 -0
  15. data/app/assets/javascripts/blazer/ace.js +6 -0
  16. data/app/assets/javascripts/blazer/ace/ace.js +11 -0
  17. data/app/assets/javascripts/blazer/ace/ext-language_tools.js +5 -0
  18. data/app/assets/javascripts/blazer/ace/mode-sql.js +1 -0
  19. data/app/assets/javascripts/blazer/ace/snippets/sql.js +1 -0
  20. data/app/assets/javascripts/blazer/ace/snippets/text.js +1 -0
  21. data/app/assets/javascripts/blazer/ace/theme-twilight.js +1 -0
  22. data/app/assets/javascripts/blazer/application.js +79 -0
  23. data/app/assets/javascripts/blazer/bootstrap.js +2366 -0
  24. data/app/assets/javascripts/blazer/chartkick.js +1693 -0
  25. data/app/assets/javascripts/blazer/daterangepicker.js +1505 -0
  26. data/app/assets/javascripts/blazer/fuzzysearch.js +24 -0
  27. data/app/assets/javascripts/blazer/highlight.pack.js +1 -0
  28. data/app/assets/javascripts/blazer/jquery.js +10308 -0
  29. data/app/assets/javascripts/blazer/jquery.stickytableheaders.js +263 -0
  30. data/app/assets/javascripts/blazer/jquery_ujs.js +469 -0
  31. data/app/assets/javascripts/blazer/moment-timezone.js +1007 -0
  32. data/app/assets/javascripts/blazer/moment.js +3043 -0
  33. data/app/assets/javascripts/blazer/queries.js +110 -0
  34. data/app/assets/javascripts/blazer/routes.js +23 -0
  35. data/app/assets/javascripts/blazer/selectize.js +3667 -0
  36. data/app/assets/javascripts/blazer/stupidtable.js +114 -0
  37. data/app/assets/javascripts/blazer/vue.js +7515 -0
  38. data/app/assets/stylesheets/blazer/application.css +198 -0
  39. data/app/assets/stylesheets/blazer/bootstrap.css.erb +6202 -0
  40. data/app/assets/stylesheets/blazer/daterangepicker-bs3.css +375 -0
  41. data/app/assets/stylesheets/blazer/github.css +125 -0
  42. data/app/assets/stylesheets/blazer/selectize.default.css +387 -0
  43. data/app/controllers/blazer/base_controller.rb +103 -0
  44. data/app/controllers/blazer/checks_controller.rb +56 -0
  45. data/app/controllers/blazer/dashboards_controller.rb +105 -0
  46. data/app/controllers/blazer/queries_controller.rb +325 -0
  47. data/app/helpers/blazer/base_helper.rb +57 -0
  48. data/app/mailers/blazer/check_mailer.rb +27 -0
  49. data/app/models/blazer/audit.rb +6 -0
  50. data/app/models/blazer/check.rb +95 -0
  51. data/app/models/blazer/connection.rb +5 -0
  52. data/app/models/blazer/dashboard.rb +13 -0
  53. data/app/models/blazer/dashboard_query.rb +9 -0
  54. data/app/models/blazer/query.rb +31 -0
  55. data/app/models/blazer/record.rb +5 -0
  56. data/app/views/blazer/_nav.html.erb +16 -0
  57. data/app/views/blazer/_variables.html.erb +102 -0
  58. data/app/views/blazer/check_mailer/failing_checks.html.erb +6 -0
  59. data/app/views/blazer/check_mailer/state_change.html.erb +47 -0
  60. data/app/views/blazer/checks/_form.html.erb +71 -0
  61. data/app/views/blazer/checks/edit.html.erb +1 -0
  62. data/app/views/blazer/checks/index.html.erb +40 -0
  63. data/app/views/blazer/checks/new.html.erb +1 -0
  64. data/app/views/blazer/dashboards/_form.html.erb +76 -0
  65. data/app/views/blazer/dashboards/edit.html.erb +1 -0
  66. data/app/views/blazer/dashboards/new.html.erb +1 -0
  67. data/app/views/blazer/dashboards/show.html.erb +47 -0
  68. data/app/views/blazer/queries/_form.html.erb +240 -0
  69. data/app/views/blazer/queries/edit.html.erb +2 -0
  70. data/app/views/blazer/queries/home.html.erb +152 -0
  71. data/app/views/blazer/queries/new.html.erb +2 -0
  72. data/app/views/blazer/queries/run.html.erb +163 -0
  73. data/app/views/blazer/queries/schema.html.erb +18 -0
  74. data/app/views/blazer/queries/show.html.erb +73 -0
  75. data/app/views/layouts/blazer/application.html.erb +24 -0
  76. data/blazer.gemspec +26 -0
  77. data/config/routes.rb +16 -0
  78. data/lib/blazer.rb +185 -0
  79. data/lib/blazer/adapters/athena_adapter.rb +128 -0
  80. data/lib/blazer/adapters/base_adapter.rb +53 -0
  81. data/lib/blazer/adapters/bigquery_adapter.rb +67 -0
  82. data/lib/blazer/adapters/drill_adapter.rb +28 -0
  83. data/lib/blazer/adapters/elasticsearch_adapter.rb +49 -0
  84. data/lib/blazer/adapters/mongodb_adapter.rb +39 -0
  85. data/lib/blazer/adapters/presto_adapter.rb +45 -0
  86. data/lib/blazer/adapters/sql_adapter.rb +182 -0
  87. data/lib/blazer/data_source.rb +193 -0
  88. data/lib/blazer/detect_anomalies.R +19 -0
  89. data/lib/blazer/engine.rb +47 -0
  90. data/lib/blazer/result.rb +170 -0
  91. data/lib/blazer/run_statement.rb +40 -0
  92. data/lib/blazer/run_statement_job.rb +21 -0
  93. data/lib/blazer/version.rb +3 -0
  94. data/lib/generators/blazer/install_generator.rb +39 -0
  95. data/lib/generators/blazer/templates/config.yml +62 -0
  96. data/lib/generators/blazer/templates/install.rb +45 -0
  97. data/lib/tasks/blazer.rake +10 -0
  98. metadata +211 -0
@@ -0,0 +1,1505 @@
1
+ /**
2
+ * @version: 2.1.14
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
+
9
+ (function(root, factory) {
10
+
11
+ if (typeof define === 'function' && define.amd) {
12
+ define(['moment', 'jquery', 'exports'], function(momentjs, $, exports) {
13
+ root.daterangepicker = factory(root, exports, momentjs, $);
14
+ });
15
+
16
+ } else if (typeof exports !== 'undefined') {
17
+ var momentjs = require('moment');
18
+ var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined; //isomorphic issue
19
+ if (!jQuery) {
20
+ try {
21
+ jQuery = require('jquery');
22
+ if (!jQuery.fn) jQuery.fn = {}; //isomorphic issue
23
+ } catch (err) {
24
+ if (!jQuery) throw new Error('jQuery dependency not found');
25
+ }
26
+ }
27
+
28
+ factory(root, exports, momentjs, jQuery);
29
+
30
+ // Finally, as a browser global.
31
+ } else {
32
+ root.daterangepicker = factory(root, {}, root.moment || moment, (root.jQuery || root.Zepto || root.ender || root.$));
33
+ }
34
+
35
+ }(this || {}, function(root, daterangepicker, moment, $) { // 'this' doesn't exist on a server
36
+
37
+ var DateRangePicker = function(element, options, cb) {
38
+
39
+ //default settings for options
40
+ this.parentEl = 'body';
41
+ this.element = $(element);
42
+ this.startDate = moment().startOf('day');
43
+ this.endDate = moment().endOf('day');
44
+ this.minDate = false;
45
+ this.maxDate = false;
46
+ this.dateLimit = false;
47
+ this.autoApply = false;
48
+ this.singleDatePicker = false;
49
+ this.showDropdowns = false;
50
+ this.showWeekNumbers = false;
51
+ this.timePicker = false;
52
+ this.timePicker24Hour = false;
53
+ this.timePickerIncrement = 1;
54
+ this.timePickerSeconds = false;
55
+ this.linkedCalendars = true;
56
+ this.autoUpdateInput = true;
57
+ this.ranges = {};
58
+
59
+ this.opens = 'right';
60
+ if (this.element.hasClass('pull-right'))
61
+ this.opens = 'left';
62
+
63
+ this.drops = 'down';
64
+ if (this.element.hasClass('dropup'))
65
+ this.drops = 'up';
66
+
67
+ this.buttonClasses = 'btn btn-sm';
68
+ this.applyClass = 'btn-success';
69
+ this.cancelClass = 'btn-default';
70
+
71
+ this.locale = {
72
+ format: 'MM/DD/YYYY',
73
+ separator: ' - ',
74
+ applyLabel: 'Apply',
75
+ cancelLabel: 'Cancel',
76
+ weekLabel: 'W',
77
+ customRangeLabel: 'Custom Range',
78
+ daysOfWeek: moment.weekdaysMin(),
79
+ monthNames: moment.monthsShort(),
80
+ firstDay: moment.localeData().firstDayOfWeek()
81
+ };
82
+
83
+ this.callback = function() { };
84
+
85
+ //some state information
86
+ this.isShowing = false;
87
+ this.leftCalendar = {};
88
+ this.rightCalendar = {};
89
+
90
+ //custom options from user
91
+ if (typeof options !== 'object' || options === null)
92
+ options = {};
93
+
94
+ //allow setting options with data attributes
95
+ //data-api options will be overwritten with custom javascript options
96
+ options = $.extend(this.element.data(), options);
97
+
98
+ //html template for the picker UI
99
+ if (typeof options.template !== 'string')
100
+ options.template = '<div class="daterangepicker dropdown-menu">' +
101
+ '<div class="calendar left">' +
102
+ '<div class="daterangepicker_input">' +
103
+ '<input class="input-mini" type="text" name="daterangepicker_start" value="" />' +
104
+ '<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>' +
105
+ '<div class="calendar-time">' +
106
+ '<div></div>' +
107
+ '<i class="fa fa-clock-o glyphicon glyphicon-time"></i>' +
108
+ '</div>' +
109
+ '</div>' +
110
+ '<div class="calendar-table"></div>' +
111
+ '</div>' +
112
+ '<div class="calendar right">' +
113
+ '<div class="daterangepicker_input">' +
114
+ '<input class="input-mini" type="text" name="daterangepicker_end" value="" />' +
115
+ '<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>' +
116
+ '<div class="calendar-time">' +
117
+ '<div></div>' +
118
+ '<i class="fa fa-clock-o glyphicon glyphicon-time"></i>' +
119
+ '</div>' +
120
+ '</div>' +
121
+ '<div class="calendar-table"></div>' +
122
+ '</div>' +
123
+ '<div class="ranges">' +
124
+ '<div class="range_inputs">' +
125
+ '<button class="applyBtn" disabled="disabled" type="button"></button> ' +
126
+ '<button class="cancelBtn" type="button"></button>' +
127
+ '</div>' +
128
+ '</div>' +
129
+ '</div>';
130
+
131
+ this.parentEl = (options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl);
132
+ this.container = $(options.template).appendTo(this.parentEl);
133
+
134
+ //
135
+ // handle all the possible options overriding defaults
136
+ //
137
+
138
+ if (typeof options.locale === 'object') {
139
+
140
+ if (typeof options.locale.format === 'string')
141
+ this.locale.format = options.locale.format;
142
+
143
+ if (typeof options.locale.separator === 'string')
144
+ this.locale.separator = options.locale.separator;
145
+
146
+ if (typeof options.locale.daysOfWeek === 'object')
147
+ this.locale.daysOfWeek = options.locale.daysOfWeek.slice();
148
+
149
+ if (typeof options.locale.monthNames === 'object')
150
+ this.locale.monthNames = options.locale.monthNames.slice();
151
+
152
+ if (typeof options.locale.firstDay === 'number')
153
+ this.locale.firstDay = options.locale.firstDay;
154
+
155
+ if (typeof options.locale.applyLabel === 'string')
156
+ this.locale.applyLabel = options.locale.applyLabel;
157
+
158
+ if (typeof options.locale.cancelLabel === 'string')
159
+ this.locale.cancelLabel = options.locale.cancelLabel;
160
+
161
+ if (typeof options.locale.weekLabel === 'string')
162
+ this.locale.weekLabel = options.locale.weekLabel;
163
+
164
+ if (typeof options.locale.customRangeLabel === 'string')
165
+ this.locale.customRangeLabel = options.locale.customRangeLabel;
166
+
167
+ }
168
+
169
+ if (typeof options.startDate === 'string')
170
+ this.startDate = moment(options.startDate, this.locale.format);
171
+
172
+ if (typeof options.endDate === 'string')
173
+ this.endDate = moment(options.endDate, this.locale.format);
174
+
175
+ if (typeof options.minDate === 'string')
176
+ this.minDate = moment(options.minDate, this.locale.format);
177
+
178
+ if (typeof options.maxDate === 'string')
179
+ this.maxDate = moment(options.maxDate, this.locale.format);
180
+
181
+ if (typeof options.startDate === 'object')
182
+ this.startDate = moment(options.startDate);
183
+
184
+ if (typeof options.endDate === 'object')
185
+ this.endDate = moment(options.endDate);
186
+
187
+ if (typeof options.minDate === 'object')
188
+ this.minDate = moment(options.minDate);
189
+
190
+ if (typeof options.maxDate === 'object')
191
+ this.maxDate = moment(options.maxDate);
192
+
193
+ // sanity check for bad options
194
+ if (this.minDate && this.startDate.isBefore(this.minDate))
195
+ this.startDate = this.minDate.clone();
196
+
197
+ // sanity check for bad options
198
+ if (this.maxDate && this.endDate.isAfter(this.maxDate))
199
+ this.endDate = this.maxDate.clone();
200
+
201
+ if (typeof options.applyClass === 'string')
202
+ this.applyClass = options.applyClass;
203
+
204
+ if (typeof options.cancelClass === 'string')
205
+ this.cancelClass = options.cancelClass;
206
+
207
+ if (typeof options.dateLimit === 'object')
208
+ this.dateLimit = options.dateLimit;
209
+
210
+ if (typeof options.opens === 'string')
211
+ this.opens = options.opens;
212
+
213
+ if (typeof options.drops === 'string')
214
+ this.drops = options.drops;
215
+
216
+ if (typeof options.showWeekNumbers === 'boolean')
217
+ this.showWeekNumbers = options.showWeekNumbers;
218
+
219
+ if (typeof options.buttonClasses === 'string')
220
+ this.buttonClasses = options.buttonClasses;
221
+
222
+ if (typeof options.buttonClasses === 'object')
223
+ this.buttonClasses = options.buttonClasses.join(' ');
224
+
225
+ if (typeof options.showDropdowns === 'boolean')
226
+ this.showDropdowns = options.showDropdowns;
227
+
228
+ if (typeof options.singleDatePicker === 'boolean') {
229
+ this.singleDatePicker = options.singleDatePicker;
230
+ if (this.singleDatePicker)
231
+ this.endDate = this.startDate.clone();
232
+ }
233
+
234
+ if (typeof options.timePicker === 'boolean')
235
+ this.timePicker = options.timePicker;
236
+
237
+ if (typeof options.timePickerSeconds === 'boolean')
238
+ this.timePickerSeconds = options.timePickerSeconds;
239
+
240
+ if (typeof options.timePickerIncrement === 'number')
241
+ this.timePickerIncrement = options.timePickerIncrement;
242
+
243
+ if (typeof options.timePicker24Hour === 'boolean')
244
+ this.timePicker24Hour = options.timePicker24Hour;
245
+
246
+ if (typeof options.autoApply === 'boolean')
247
+ this.autoApply = options.autoApply;
248
+
249
+ if (typeof options.autoUpdateInput === 'boolean')
250
+ this.autoUpdateInput = options.autoUpdateInput;
251
+
252
+ if (typeof options.linkedCalendars === 'boolean')
253
+ this.linkedCalendars = options.linkedCalendars;
254
+
255
+ if (typeof options.isInvalidDate === 'function')
256
+ this.isInvalidDate = options.isInvalidDate;
257
+
258
+ // update day names order to firstDay
259
+ if (this.locale.firstDay != 0) {
260
+ var iterator = this.locale.firstDay;
261
+ while (iterator > 0) {
262
+ this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift());
263
+ iterator--;
264
+ }
265
+ }
266
+
267
+ var start, end, range;
268
+
269
+ //if no start/end dates set, check if an input element contains initial values
270
+ if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') {
271
+ if ($(this.element).is('input[type=text]')) {
272
+ var val = $(this.element).val(),
273
+ split = val.split(this.locale.separator);
274
+
275
+ start = end = null;
276
+
277
+ if (split.length == 2) {
278
+ start = moment(split[0], this.locale.format);
279
+ end = moment(split[1], this.locale.format);
280
+ } else if (this.singleDatePicker && val !== "") {
281
+ start = moment(val, this.locale.format);
282
+ end = moment(val, this.locale.format);
283
+ }
284
+ if (start !== null && end !== null) {
285
+ this.setStartDate(start);
286
+ this.setEndDate(end);
287
+ }
288
+ }
289
+ }
290
+
291
+ if (typeof options.ranges === 'object') {
292
+ for (range in options.ranges) {
293
+
294
+ if (typeof options.ranges[range][0] === 'string')
295
+ start = moment(options.ranges[range][0], this.locale.format);
296
+ else
297
+ start = moment(options.ranges[range][0]);
298
+
299
+ if (typeof options.ranges[range][1] === 'string')
300
+ end = moment(options.ranges[range][1], this.locale.format);
301
+ else
302
+ end = moment(options.ranges[range][1]);
303
+
304
+ // If the start or end date exceed those allowed by the minDate or dateLimit
305
+ // options, shorten the range to the allowable period.
306
+ if (this.minDate && start.isBefore(this.minDate))
307
+ start = this.minDate.clone();
308
+
309
+ var maxDate = this.maxDate;
310
+ if (this.dateLimit && start.clone().add(this.dateLimit).isAfter(maxDate))
311
+ maxDate = start.clone().add(this.dateLimit);
312
+ if (maxDate && end.isAfter(maxDate))
313
+ end = maxDate.clone();
314
+
315
+ // If the end of the range is before the minimum or the start of the range is
316
+ // after the maximum, don't display this range option at all.
317
+ if ((this.minDate && end.isBefore(this.minDate)) || (maxDate && start.isAfter(maxDate)))
318
+ continue;
319
+
320
+ //Support unicode chars in the range names.
321
+ var elem = document.createElement('textarea');
322
+ elem.innerHTML = range;
323
+ var rangeHtml = elem.value;
324
+
325
+ this.ranges[rangeHtml] = [start, end];
326
+ }
327
+
328
+ var list = '<ul>';
329
+ for (range in this.ranges) {
330
+ list += '<li>' + range + '</li>';
331
+ }
332
+ list += '<li>' + this.locale.customRangeLabel + '</li>';
333
+ list += '</ul>';
334
+ this.container.find('.ranges').prepend(list);
335
+ }
336
+
337
+ if (typeof cb === 'function') {
338
+ this.callback = cb;
339
+ }
340
+
341
+ if (!this.timePicker) {
342
+ this.startDate = this.startDate.startOf('day');
343
+ this.endDate = this.endDate.endOf('day');
344
+ this.container.find('.calendar-time').hide();
345
+ }
346
+
347
+ //can't be used together for now
348
+ if (this.timePicker && this.autoApply)
349
+ this.autoApply = false;
350
+
351
+ if (this.autoApply && typeof options.ranges !== 'object') {
352
+ this.container.find('.ranges').hide();
353
+ } else if (this.autoApply) {
354
+ this.container.find('.applyBtn, .cancelBtn').addClass('hide');
355
+ }
356
+
357
+ if (this.singleDatePicker) {
358
+ this.container.addClass('single');
359
+ this.container.find('.calendar.left').addClass('single');
360
+ this.container.find('.calendar.left').show();
361
+ this.container.find('.calendar.right').hide();
362
+ this.container.find('.daterangepicker_input input, .daterangepicker_input i').hide();
363
+ if (!this.timePicker) {
364
+ this.container.find('.ranges').hide();
365
+ }
366
+ }
367
+
368
+ if (typeof options.ranges === 'undefined' && !this.singleDatePicker) {
369
+ this.container.addClass('show-calendar');
370
+ }
371
+
372
+ this.container.addClass('opens' + this.opens);
373
+
374
+ //swap the position of the predefined ranges if opens right
375
+ if (typeof options.ranges !== 'undefined' && this.opens == 'right') {
376
+ var ranges = this.container.find('.ranges');
377
+ var html = ranges.clone();
378
+ ranges.remove();
379
+ this.container.find('.calendar.left').parent().prepend(html);
380
+ }
381
+
382
+ //apply CSS classes and labels to buttons
383
+ this.container.find('.applyBtn, .cancelBtn').addClass(this.buttonClasses);
384
+ if (this.applyClass.length)
385
+ this.container.find('.applyBtn').addClass(this.applyClass);
386
+ if (this.cancelClass.length)
387
+ this.container.find('.cancelBtn').addClass(this.cancelClass);
388
+ this.container.find('.applyBtn').html(this.locale.applyLabel);
389
+ this.container.find('.cancelBtn').html(this.locale.cancelLabel);
390
+
391
+ //
392
+ // event listeners
393
+ //
394
+
395
+ this.container.find('.calendar')
396
+ .on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this))
397
+ .on('click.daterangepicker', '.next', $.proxy(this.clickNext, this))
398
+ .on('click.daterangepicker', 'td.available', $.proxy(this.clickDate, this))
399
+ .on('mouseenter.daterangepicker', 'td.available', $.proxy(this.hoverDate, this))
400
+ .on('mouseleave.daterangepicker', 'td.available', $.proxy(this.updateFormInputs, this))
401
+ .on('change.daterangepicker', 'select.yearselect', $.proxy(this.monthOrYearChanged, this))
402
+ .on('change.daterangepicker', 'select.monthselect', $.proxy(this.monthOrYearChanged, this))
403
+ .on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.secondselect,select.ampmselect', $.proxy(this.timeChanged, this))
404
+ .on('click.daterangepicker', '.daterangepicker_input input', $.proxy(this.showCalendars, this))
405
+ //.on('keyup.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this))
406
+ .on('change.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this));
407
+
408
+ this.container.find('.ranges')
409
+ .on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this))
410
+ .on('click.daterangepicker', 'button.cancelBtn', $.proxy(this.clickCancel, this))
411
+ .on('click.daterangepicker', 'li', $.proxy(this.clickRange, this))
412
+ .on('mouseenter.daterangepicker', 'li', $.proxy(this.hoverRange, this))
413
+ .on('mouseleave.daterangepicker', 'li', $.proxy(this.updateFormInputs, this));
414
+
415
+ if (this.element.is('input')) {
416
+ this.element.on({
417
+ 'click.daterangepicker': $.proxy(this.show, this),
418
+ 'focus.daterangepicker': $.proxy(this.show, this),
419
+ 'keyup.daterangepicker': $.proxy(this.elementChanged, this),
420
+ 'keydown.daterangepicker': $.proxy(this.keydown, this)
421
+ });
422
+ } else {
423
+ this.element.on('click.daterangepicker', $.proxy(this.toggle, this));
424
+ }
425
+
426
+ //
427
+ // if attached to a text input, set the initial value
428
+ //
429
+
430
+ if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
431
+ this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
432
+ this.element.trigger('change');
433
+ } else if (this.element.is('input') && this.autoUpdateInput) {
434
+ this.element.val(this.startDate.format(this.locale.format));
435
+ this.element.trigger('change');
436
+ }
437
+
438
+ };
439
+
440
+ DateRangePicker.prototype = {
441
+
442
+ constructor: DateRangePicker,
443
+
444
+ setStartDate: function(startDate) {
445
+ if (typeof startDate === 'string')
446
+ this.startDate = moment(startDate, this.locale.format);
447
+
448
+ if (typeof startDate === 'object')
449
+ this.startDate = moment(startDate);
450
+
451
+ if (!this.timePicker)
452
+ this.startDate = this.startDate.startOf('day');
453
+
454
+ if (this.timePicker && this.timePickerIncrement)
455
+ this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
456
+
457
+ if (this.minDate && this.startDate.isBefore(this.minDate))
458
+ this.startDate = this.minDate;
459
+
460
+ if (this.maxDate && this.startDate.isAfter(this.maxDate))
461
+ this.startDate = this.maxDate;
462
+
463
+ if (!this.isShowing)
464
+ this.updateElement();
465
+
466
+ this.updateMonthsInView();
467
+ },
468
+
469
+ setEndDate: function(endDate) {
470
+ if (typeof endDate === 'string')
471
+ this.endDate = moment(endDate, this.locale.format);
472
+
473
+ if (typeof endDate === 'object')
474
+ this.endDate = moment(endDate);
475
+
476
+ if (!this.timePicker)
477
+ this.endDate = this.endDate.endOf('day');
478
+
479
+ if (this.timePicker && this.timePickerIncrement)
480
+ this.endDate.minute(Math.round(this.endDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
481
+
482
+ if (this.endDate.isBefore(this.startDate))
483
+ this.endDate = this.startDate.clone();
484
+
485
+ if (this.maxDate && this.endDate.isAfter(this.maxDate))
486
+ this.endDate = this.maxDate;
487
+
488
+ if (this.dateLimit && this.startDate.clone().add(this.dateLimit).isBefore(this.endDate))
489
+ this.endDate = this.startDate.clone().add(this.dateLimit);
490
+
491
+ if (!this.isShowing)
492
+ this.updateElement();
493
+
494
+ this.updateMonthsInView();
495
+ },
496
+
497
+ isInvalidDate: function() {
498
+ return false;
499
+ },
500
+
501
+ updateView: function() {
502
+ if (this.timePicker) {
503
+ this.renderTimePicker('left');
504
+ this.renderTimePicker('right');
505
+ if (!this.endDate) {
506
+ this.container.find('.right .calendar-time select').attr('disabled', 'disabled').addClass('disabled');
507
+ } else {
508
+ this.container.find('.right .calendar-time select').removeAttr('disabled').removeClass('disabled');
509
+ }
510
+ }
511
+ if (this.endDate) {
512
+ this.container.find('input[name="daterangepicker_end"]').removeClass('active');
513
+ this.container.find('input[name="daterangepicker_start"]').addClass('active');
514
+ } else {
515
+ this.container.find('input[name="daterangepicker_end"]').addClass('active');
516
+ this.container.find('input[name="daterangepicker_start"]').removeClass('active');
517
+ }
518
+ this.updateMonthsInView();
519
+ this.updateCalendars();
520
+ this.updateFormInputs();
521
+ },
522
+
523
+ updateMonthsInView: function() {
524
+ if (this.endDate) {
525
+
526
+ //if both dates are visible already, do nothing
527
+ if (!this.singleDatePicker && this.leftCalendar.month && this.rightCalendar.month &&
528
+ (this.startDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.startDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
529
+ &&
530
+ (this.endDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.endDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
531
+ ) {
532
+ return;
533
+ }
534
+
535
+ this.leftCalendar.month = this.startDate.clone().date(2);
536
+ if (!this.linkedCalendars && (this.endDate.month() != this.startDate.month() || this.endDate.year() != this.startDate.year())) {
537
+ this.rightCalendar.month = this.endDate.clone().date(2);
538
+ } else {
539
+ this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
540
+ }
541
+
542
+ } else {
543
+ if (this.leftCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM') && this.rightCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM')) {
544
+ this.leftCalendar.month = this.startDate.clone().date(2);
545
+ this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
546
+ }
547
+ }
548
+ },
549
+
550
+ updateCalendars: function() {
551
+
552
+ if (this.timePicker) {
553
+ var hour, minute, second;
554
+ if (this.endDate) {
555
+ hour = parseInt(this.container.find('.left .hourselect').val(), 10);
556
+ minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
557
+ second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
558
+ if (!this.timePicker24Hour) {
559
+ var ampm = this.container.find('.left .ampmselect').val();
560
+ if (ampm === 'PM' && hour < 12)
561
+ hour += 12;
562
+ if (ampm === 'AM' && hour === 12)
563
+ hour = 0;
564
+ }
565
+ } else {
566
+ hour = parseInt(this.container.find('.right .hourselect').val(), 10);
567
+ minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
568
+ second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
569
+ if (!this.timePicker24Hour) {
570
+ var ampm = this.container.find('.right .ampmselect').val();
571
+ if (ampm === 'PM' && hour < 12)
572
+ hour += 12;
573
+ if (ampm === 'AM' && hour === 12)
574
+ hour = 0;
575
+ }
576
+ }
577
+ this.leftCalendar.month.hour(hour).minute(minute).second(second);
578
+ this.rightCalendar.month.hour(hour).minute(minute).second(second);
579
+ }
580
+
581
+ this.renderCalendar('left');
582
+ this.renderCalendar('right');
583
+
584
+ //highlight any predefined range matching the current start and end dates
585
+ this.container.find('.ranges li').removeClass('active');
586
+ if (this.endDate == null) return;
587
+
588
+ var customRange = true;
589
+ var i = 0;
590
+ for (var range in this.ranges) {
591
+ if (this.timePicker) {
592
+ if (this.startDate.isSame(this.ranges[range][0]) && this.endDate.isSame(this.ranges[range][1])) {
593
+ customRange = false;
594
+ this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
595
+ break;
596
+ }
597
+ } else {
598
+ //ignore times when comparing dates if time picker is not enabled
599
+ 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')) {
600
+ customRange = false;
601
+ this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
602
+ break;
603
+ }
604
+ }
605
+ i++;
606
+ }
607
+ if (customRange) {
608
+ this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
609
+ this.showCalendars();
610
+ }
611
+
612
+ },
613
+
614
+ renderCalendar: function(side) {
615
+
616
+ //
617
+ // Build the matrix of dates that will populate the calendar
618
+ //
619
+
620
+ var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar;
621
+ var month = calendar.month.month();
622
+ var year = calendar.month.year();
623
+ var hour = calendar.month.hour();
624
+ var minute = calendar.month.minute();
625
+ var second = calendar.month.second();
626
+ var daysInMonth = moment([year, month]).daysInMonth();
627
+ var firstDay = moment([year, month, 1]);
628
+ var lastDay = moment([year, month, daysInMonth]);
629
+ var lastMonth = moment(firstDay).subtract(1, 'month').month();
630
+ var lastYear = moment(firstDay).subtract(1, 'month').year();
631
+ var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth();
632
+ var dayOfWeek = firstDay.day();
633
+
634
+ //initialize a 6 rows x 7 columns array for the calendar
635
+ var calendar = [];
636
+ calendar.firstDay = firstDay;
637
+ calendar.lastDay = lastDay;
638
+
639
+ for (var i = 0; i < 6; i++) {
640
+ calendar[i] = [];
641
+ }
642
+
643
+ //populate the calendar with date objects
644
+ var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1;
645
+ if (startDay > daysInLastMonth)
646
+ startDay -= 7;
647
+
648
+ if (dayOfWeek == this.locale.firstDay)
649
+ startDay = daysInLastMonth - 6;
650
+
651
+ var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]);
652
+
653
+ var col, row;
654
+ for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) {
655
+ if (i > 0 && col % 7 === 0) {
656
+ col = 0;
657
+ row++;
658
+ }
659
+ calendar[row][col] = curDate.clone().hour(hour).minute(minute).second(second);
660
+ curDate.hour(12);
661
+
662
+ if (this.minDate && calendar[row][col].format('YYYY-MM-DD') == this.minDate.format('YYYY-MM-DD') && calendar[row][col].isBefore(this.minDate) && side == 'left') {
663
+ calendar[row][col] = this.minDate.clone();
664
+ }
665
+
666
+ if (this.maxDate && calendar[row][col].format('YYYY-MM-DD') == this.maxDate.format('YYYY-MM-DD') && calendar[row][col].isAfter(this.maxDate) && side == 'right') {
667
+ calendar[row][col] = this.maxDate.clone();
668
+ }
669
+
670
+ }
671
+
672
+ //make the calendar object available to hoverDate/clickDate
673
+ if (side == 'left') {
674
+ this.leftCalendar.calendar = calendar;
675
+ } else {
676
+ this.rightCalendar.calendar = calendar;
677
+ }
678
+
679
+ //
680
+ // Display the calendar
681
+ //
682
+
683
+ var minDate = side == 'left' ? this.minDate : this.startDate;
684
+ var maxDate = this.maxDate;
685
+ var selected = side == 'left' ? this.startDate : this.endDate;
686
+
687
+ var html = '<table class="table-condensed">';
688
+ html += '<thead>';
689
+ html += '<tr>';
690
+
691
+ // add empty cell for week number
692
+ if (this.showWeekNumbers)
693
+ html += '<th></th>';
694
+
695
+ if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) {
696
+ html += '<th class="prev available"><i class="fa fa-chevron-left glyphicon glyphicon-chevron-left"></i></th>';
697
+ } else {
698
+ html += '<th></th>';
699
+ }
700
+
701
+ var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");
702
+
703
+ if (this.showDropdowns) {
704
+ var currentMonth = calendar[1][1].month();
705
+ var currentYear = calendar[1][1].year();
706
+ var maxYear = (maxDate && maxDate.year()) || (currentYear + 5);
707
+ var minYear = (minDate && minDate.year()) || (currentYear - 50);
708
+ var inMinYear = currentYear == minYear;
709
+ var inMaxYear = currentYear == maxYear;
710
+
711
+ var monthHtml = '<select class="monthselect">';
712
+ for (var m = 0; m < 12; m++) {
713
+ if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || m <= maxDate.month())) {
714
+ monthHtml += "<option value='" + m + "'" +
715
+ (m === currentMonth ? " selected='selected'" : "") +
716
+ ">" + this.locale.monthNames[m] + "</option>";
717
+ } else {
718
+ monthHtml += "<option value='" + m + "'" +
719
+ (m === currentMonth ? " selected='selected'" : "") +
720
+ " disabled='disabled'>" + this.locale.monthNames[m] + "</option>";
721
+ }
722
+ }
723
+ monthHtml += "</select>";
724
+
725
+ var yearHtml = '<select class="yearselect">';
726
+ for (var y = minYear; y <= maxYear; y++) {
727
+ yearHtml += '<option value="' + y + '"' +
728
+ (y === currentYear ? ' selected="selected"' : '') +
729
+ '>' + y + '</option>';
730
+ }
731
+ yearHtml += '</select>';
732
+
733
+ dateHtml = monthHtml + yearHtml;
734
+ }
735
+
736
+ html += '<th colspan="5" class="month">' + dateHtml + '</th>';
737
+ if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) {
738
+ html += '<th class="next available"><i class="fa fa-chevron-right glyphicon glyphicon-chevron-right"></i></th>';
739
+ } else {
740
+ html += '<th></th>';
741
+ }
742
+
743
+ html += '</tr>';
744
+ html += '<tr>';
745
+
746
+ // add week number label
747
+ if (this.showWeekNumbers)
748
+ html += '<th class="week">' + this.locale.weekLabel + '</th>';
749
+
750
+ $.each(this.locale.daysOfWeek, function(index, dayOfWeek) {
751
+ html += '<th>' + dayOfWeek + '</th>';
752
+ });
753
+
754
+ html += '</tr>';
755
+ html += '</thead>';
756
+ html += '<tbody>';
757
+
758
+ //adjust maxDate to reflect the dateLimit setting in order to
759
+ //grey out end dates beyond the dateLimit
760
+ if (this.endDate == null && this.dateLimit) {
761
+ var maxLimit = this.startDate.clone().add(this.dateLimit).endOf('day');
762
+ if (!maxDate || maxLimit.isBefore(maxDate)) {
763
+ maxDate = maxLimit;
764
+ }
765
+ }
766
+
767
+ for (var row = 0; row < 6; row++) {
768
+ html += '<tr>';
769
+
770
+ // add week number
771
+ if (this.showWeekNumbers)
772
+ html += '<td class="week">' + calendar[row][0].week() + '</td>';
773
+
774
+ for (var col = 0; col < 7; col++) {
775
+
776
+ var classes = [];
777
+
778
+ //highlight today's date
779
+ if (calendar[row][col].isSame(new Date(), "day"))
780
+ classes.push('today');
781
+
782
+ //highlight weekends
783
+ if (calendar[row][col].isoWeekday() > 5)
784
+ classes.push('weekend');
785
+
786
+ //grey out the dates in other months displayed at beginning and end of this calendar
787
+ if (calendar[row][col].month() != calendar[1][1].month())
788
+ classes.push('off');
789
+
790
+ //don't allow selection of dates before the minimum date
791
+ if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day'))
792
+ classes.push('off', 'disabled');
793
+
794
+ //don't allow selection of dates after the maximum date
795
+ if (maxDate && calendar[row][col].isAfter(maxDate, 'day'))
796
+ classes.push('off', 'disabled');
797
+
798
+ //don't allow selection of date if a custom function decides it's invalid
799
+ if (this.isInvalidDate(calendar[row][col]))
800
+ classes.push('off', 'disabled');
801
+
802
+ //highlight the currently selected start date
803
+ if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD'))
804
+ classes.push('active', 'start-date');
805
+
806
+ //highlight the currently selected end date
807
+ if (this.endDate != null && calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD'))
808
+ classes.push('active', 'end-date');
809
+
810
+ //highlight dates in-between the selected dates
811
+ if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate)
812
+ classes.push('in-range');
813
+
814
+ var cname = '', disabled = false;
815
+ for (var i = 0; i < classes.length; i++) {
816
+ cname += classes[i] + ' ';
817
+ if (classes[i] == 'disabled')
818
+ disabled = true;
819
+ }
820
+ if (!disabled)
821
+ cname += 'available';
822
+
823
+ html += '<td class="' + cname.replace(/^\s+|\s+$/g, '') + '" data-title="' + 'r' + row + 'c' + col + '">' + calendar[row][col].date() + '</td>';
824
+
825
+ }
826
+ html += '</tr>';
827
+ }
828
+
829
+ html += '</tbody>';
830
+ html += '</table>';
831
+
832
+ this.container.find('.calendar.' + side + ' .calendar-table').html(html);
833
+
834
+ },
835
+
836
+ renderTimePicker: function(side) {
837
+
838
+ var html, selected, minDate, maxDate = this.maxDate;
839
+
840
+ if (this.dateLimit && (!this.maxDate || this.startDate.clone().add(this.dateLimit).isAfter(this.maxDate)))
841
+ maxDate = this.startDate.clone().add(this.dateLimit);
842
+
843
+ if (side == 'left') {
844
+ selected = this.startDate.clone();
845
+ minDate = this.minDate;
846
+ } else if (side == 'right') {
847
+ selected = this.endDate ? this.endDate.clone() : this.startDate.clone();
848
+ minDate = this.startDate;
849
+
850
+ //Preserve the time already selected
851
+ var timeSelector = this.container.find('.calendar.right .calendar-time div');
852
+ if (timeSelector.html() != '') {
853
+ selected.hour(timeSelector.find('.hourselect option:selected').val() || selected.hour());
854
+ selected.minute(timeSelector.find('.minuteselect option:selected').val() || selected.minute());
855
+ selected.second(timeSelector.find('.secondselect option:selected').val() || selected.second());
856
+ if (selected.isAfter(maxDate))
857
+ selected = maxDate.clone();
858
+ }
859
+ }
860
+
861
+ //
862
+ // hours
863
+ //
864
+
865
+ html = '<select class="hourselect">';
866
+
867
+ var start = this.timePicker24Hour ? 0 : 1;
868
+ var end = this.timePicker24Hour ? 23 : 12;
869
+
870
+ for (var i = start; i <= end; i++) {
871
+ var i_in_24 = i;
872
+ if (!this.timePicker24Hour)
873
+ i_in_24 = selected.hour() >= 12 ? (i == 12 ? 12 : i + 12) : (i == 12 ? 0 : i);
874
+
875
+ var time = selected.clone().hour(i_in_24);
876
+ var disabled = false;
877
+ if (minDate && time.minute(59).isBefore(minDate))
878
+ disabled = true;
879
+ if (maxDate && time.minute(0).isAfter(maxDate))
880
+ disabled = true;
881
+
882
+ if (i_in_24 == selected.hour() && !disabled) {
883
+ html += '<option value="' + i + '" selected="selected">' + i + '</option>';
884
+ } else if (disabled) {
885
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + i + '</option>';
886
+ } else {
887
+ html += '<option value="' + i + '">' + i + '</option>';
888
+ }
889
+ }
890
+
891
+ html += '</select> ';
892
+
893
+ //
894
+ // minutes
895
+ //
896
+
897
+ html += ': <select class="minuteselect">';
898
+
899
+ for (var i = 0; i < 60; i += this.timePickerIncrement) {
900
+ var padded = i < 10 ? '0' + i : i;
901
+ var time = selected.clone().minute(i);
902
+
903
+ var disabled = false;
904
+ if (minDate && time.second(59).isBefore(minDate))
905
+ disabled = true;
906
+ if (maxDate && time.second(0).isAfter(maxDate))
907
+ disabled = true;
908
+
909
+ if (selected.minute() == i && !disabled) {
910
+ html += '<option value="' + i + '" selected="selected">' + padded + '</option>';
911
+ } else if (disabled) {
912
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';
913
+ } else {
914
+ html += '<option value="' + i + '">' + padded + '</option>';
915
+ }
916
+ }
917
+
918
+ html += '</select> ';
919
+
920
+ //
921
+ // seconds
922
+ //
923
+
924
+ if (this.timePickerSeconds) {
925
+ html += ': <select class="secondselect">';
926
+
927
+ for (var i = 0; i < 60; i++) {
928
+ var padded = i < 10 ? '0' + i : i;
929
+ var time = selected.clone().second(i);
930
+
931
+ var disabled = false;
932
+ if (minDate && time.isBefore(minDate))
933
+ disabled = true;
934
+ if (maxDate && time.isAfter(maxDate))
935
+ disabled = true;
936
+
937
+ if (selected.second() == i && !disabled) {
938
+ html += '<option value="' + i + '" selected="selected">' + padded + '</option>';
939
+ } else if (disabled) {
940
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';
941
+ } else {
942
+ html += '<option value="' + i + '">' + padded + '</option>';
943
+ }
944
+ }
945
+
946
+ html += '</select> ';
947
+ }
948
+
949
+ //
950
+ // AM/PM
951
+ //
952
+
953
+ if (!this.timePicker24Hour) {
954
+ html += '<select class="ampmselect">';
955
+
956
+ var am_html = '';
957
+ var pm_html = '';
958
+
959
+ if (minDate && selected.clone().hour(12).minute(0).second(0).isBefore(minDate))
960
+ am_html = ' disabled="disabled" class="disabled"';
961
+
962
+ if (maxDate && selected.clone().hour(0).minute(0).second(0).isAfter(maxDate))
963
+ pm_html = ' disabled="disabled" class="disabled"';
964
+
965
+ if (selected.hour() >= 12) {
966
+ html += '<option value="AM"' + am_html + '>AM</option><option value="PM" selected="selected"' + pm_html + '>PM</option>';
967
+ } else {
968
+ html += '<option value="AM" selected="selected"' + am_html + '>AM</option><option value="PM"' + pm_html + '>PM</option>';
969
+ }
970
+
971
+ html += '</select>';
972
+ }
973
+
974
+ this.container.find('.calendar.' + side + ' .calendar-time div').html(html);
975
+
976
+ },
977
+
978
+ updateFormInputs: function() {
979
+
980
+ //ignore mouse movements while an above-calendar text input has focus
981
+ if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
982
+ return;
983
+
984
+ this.container.find('input[name=daterangepicker_start]').val(this.startDate.format(this.locale.format));
985
+ if (this.endDate)
986
+ this.container.find('input[name=daterangepicker_end]').val(this.endDate.format(this.locale.format));
987
+
988
+ if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) {
989
+ this.container.find('button.applyBtn').removeAttr('disabled');
990
+ } else {
991
+ this.container.find('button.applyBtn').attr('disabled', 'disabled');
992
+ }
993
+
994
+ },
995
+
996
+ move: function() {
997
+ var parentOffset = { top: 0, left: 0 },
998
+ containerTop;
999
+ var parentRightEdge = $(window).width();
1000
+ if (!this.parentEl.is('body')) {
1001
+ parentOffset = {
1002
+ top: this.parentEl.offset().top - this.parentEl.scrollTop(),
1003
+ left: this.parentEl.offset().left - this.parentEl.scrollLeft()
1004
+ };
1005
+ parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left;
1006
+ }
1007
+
1008
+ if (this.drops == 'up')
1009
+ containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
1010
+ else
1011
+ containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
1012
+ this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('dropup');
1013
+
1014
+ if (this.opens == 'left') {
1015
+ this.container.css({
1016
+ top: containerTop,
1017
+ right: parentRightEdge - this.element.offset().left - this.element.outerWidth(),
1018
+ left: 'auto'
1019
+ });
1020
+ if (this.container.offset().left < 0) {
1021
+ this.container.css({
1022
+ right: 'auto',
1023
+ left: 9
1024
+ });
1025
+ }
1026
+ } else if (this.opens == 'center') {
1027
+ this.container.css({
1028
+ top: containerTop,
1029
+ left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
1030
+ - this.container.outerWidth() / 2,
1031
+ right: 'auto'
1032
+ });
1033
+ if (this.container.offset().left < 0) {
1034
+ this.container.css({
1035
+ right: 'auto',
1036
+ left: 9
1037
+ });
1038
+ }
1039
+ } else {
1040
+ this.container.css({
1041
+ top: containerTop,
1042
+ left: this.element.offset().left - parentOffset.left,
1043
+ right: 'auto'
1044
+ });
1045
+ if (this.container.offset().left + this.container.outerWidth() > $(window).width()) {
1046
+ this.container.css({
1047
+ left: 'auto',
1048
+ right: 0
1049
+ });
1050
+ }
1051
+ }
1052
+ },
1053
+
1054
+ show: function(e) {
1055
+ if (this.isShowing) return;
1056
+
1057
+ // Create a click proxy that is private to this instance of datepicker, for unbinding
1058
+ this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this);
1059
+
1060
+ // Bind global datepicker mousedown for hiding and
1061
+ $(document)
1062
+ .on('mousedown.daterangepicker', this._outsideClickProxy)
1063
+ // also support mobile devices
1064
+ .on('touchend.daterangepicker', this._outsideClickProxy)
1065
+ // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them
1066
+ .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)
1067
+ // and also close when focus changes to outside the picker (eg. tabbing between controls)
1068
+ .on('focusin.daterangepicker', this._outsideClickProxy);
1069
+
1070
+ // Reposition the picker if the window is resized while it's open
1071
+ $(window).on('resize.daterangepicker', $.proxy(function(e) { this.move(e); }, this));
1072
+
1073
+ this.oldStartDate = this.startDate.clone();
1074
+ this.oldEndDate = this.endDate.clone();
1075
+
1076
+ this.updateView();
1077
+ this.container.show();
1078
+ this.move();
1079
+ this.element.trigger('show.daterangepicker', this);
1080
+ this.isShowing = true;
1081
+ },
1082
+
1083
+ hide: function(e) {
1084
+ if (!this.isShowing) return;
1085
+
1086
+ //incomplete date selection, revert to last values
1087
+ if (!this.endDate) {
1088
+ this.startDate = this.oldStartDate.clone();
1089
+ this.endDate = this.oldEndDate.clone();
1090
+ }
1091
+
1092
+ //if a new date range was selected, invoke the user callback function
1093
+ if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
1094
+ this.callback(this.startDate, this.endDate, this.chosenLabel);
1095
+
1096
+ //if picker is attached to a text input, update it
1097
+ this.updateElement();
1098
+
1099
+ $(document).off('.daterangepicker');
1100
+ $(window).off('.daterangepicker');
1101
+ this.container.hide();
1102
+ this.element.trigger('hide.daterangepicker', this);
1103
+ this.isShowing = false;
1104
+ },
1105
+
1106
+ toggle: function(e) {
1107
+ if (this.isShowing) {
1108
+ this.hide();
1109
+ } else {
1110
+ this.show();
1111
+ }
1112
+ },
1113
+
1114
+ outsideClick: function(e) {
1115
+ var target = $(e.target);
1116
+ // if the page is clicked anywhere except within the daterangerpicker/button
1117
+ // itself then call this.hide()
1118
+ if (
1119
+ // ie modal dialog fix
1120
+ e.type == "focusin" ||
1121
+ target.closest(this.element).length ||
1122
+ target.closest(this.container).length ||
1123
+ target.closest('.calendar-table').length
1124
+ ) return;
1125
+ this.hide();
1126
+ },
1127
+
1128
+ showCalendars: function() {
1129
+ this.container.addClass('show-calendar');
1130
+ this.move();
1131
+ this.element.trigger('showCalendar.daterangepicker', this);
1132
+ },
1133
+
1134
+ hideCalendars: function() {
1135
+ this.container.removeClass('show-calendar');
1136
+ this.element.trigger('hideCalendar.daterangepicker', this);
1137
+ },
1138
+
1139
+ hoverRange: function(e) {
1140
+
1141
+ //ignore mouse movements while an above-calendar text input has focus
1142
+ if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
1143
+ return;
1144
+
1145
+ var label = e.target.innerHTML;
1146
+ if (label == this.locale.customRangeLabel) {
1147
+ this.updateView();
1148
+ } else {
1149
+ var dates = this.ranges[label];
1150
+ this.container.find('input[name=daterangepicker_start]').val(dates[0].format(this.locale.format));
1151
+ this.container.find('input[name=daterangepicker_end]').val(dates[1].format(this.locale.format));
1152
+ }
1153
+
1154
+ },
1155
+
1156
+ clickRange: function(e) {
1157
+ var label = e.target.innerHTML;
1158
+ this.chosenLabel = label;
1159
+ if (label == this.locale.customRangeLabel) {
1160
+ this.showCalendars();
1161
+ } else {
1162
+ var dates = this.ranges[label];
1163
+ this.startDate = dates[0];
1164
+ this.endDate = dates[1];
1165
+
1166
+ if (!this.timePicker) {
1167
+ this.startDate.startOf('day');
1168
+ this.endDate.endOf('day');
1169
+ }
1170
+
1171
+ this.hideCalendars();
1172
+ this.clickApply();
1173
+ }
1174
+ },
1175
+
1176
+ clickPrev: function(e) {
1177
+ var cal = $(e.target).parents('.calendar');
1178
+ if (cal.hasClass('left')) {
1179
+ this.leftCalendar.month.subtract(1, 'month');
1180
+ if (this.linkedCalendars)
1181
+ this.rightCalendar.month.subtract(1, 'month');
1182
+ } else {
1183
+ this.rightCalendar.month.subtract(1, 'month');
1184
+ }
1185
+ this.updateCalendars();
1186
+ },
1187
+
1188
+ clickNext: function(e) {
1189
+ var cal = $(e.target).parents('.calendar');
1190
+ if (cal.hasClass('left')) {
1191
+ this.leftCalendar.month.add(1, 'month');
1192
+ } else {
1193
+ this.rightCalendar.month.add(1, 'month');
1194
+ if (this.linkedCalendars)
1195
+ this.leftCalendar.month.add(1, 'month');
1196
+ }
1197
+ this.updateCalendars();
1198
+ },
1199
+
1200
+ hoverDate: function(e) {
1201
+
1202
+ //ignore mouse movements while an above-calendar text input has focus
1203
+ if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
1204
+ return;
1205
+
1206
+ //ignore dates that can't be selected
1207
+ if (!$(e.target).hasClass('available')) return;
1208
+
1209
+ //have the text inputs above calendars reflect the date being hovered over
1210
+ var title = $(e.target).attr('data-title');
1211
+ var row = title.substr(1, 1);
1212
+ var col = title.substr(3, 1);
1213
+ var cal = $(e.target).parents('.calendar');
1214
+ var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
1215
+
1216
+ if (this.endDate) {
1217
+ this.container.find('input[name=daterangepicker_start]').val(date.format(this.locale.format));
1218
+ } else {
1219
+ this.container.find('input[name=daterangepicker_end]').val(date.format(this.locale.format));
1220
+ }
1221
+
1222
+ //highlight the dates between the start date and the date being hovered as a potential end date
1223
+ var leftCalendar = this.leftCalendar;
1224
+ var rightCalendar = this.rightCalendar;
1225
+ var startDate = this.startDate;
1226
+ if (!this.endDate) {
1227
+ this.container.find('.calendar td').each(function(index, el) {
1228
+
1229
+ //skip week numbers, only look at dates
1230
+ if ($(el).hasClass('week')) return;
1231
+
1232
+ var title = $(el).attr('data-title');
1233
+ var row = title.substr(1, 1);
1234
+ var col = title.substr(3, 1);
1235
+ var cal = $(el).parents('.calendar');
1236
+ var dt = cal.hasClass('left') ? leftCalendar.calendar[row][col] : rightCalendar.calendar[row][col];
1237
+
1238
+ if (dt.isAfter(startDate) && dt.isBefore(date)) {
1239
+ $(el).addClass('in-range');
1240
+ } else {
1241
+ $(el).removeClass('in-range');
1242
+ }
1243
+
1244
+ });
1245
+ }
1246
+
1247
+ },
1248
+
1249
+ clickDate: function(e) {
1250
+
1251
+ if (!$(e.target).hasClass('available')) return;
1252
+
1253
+ var title = $(e.target).attr('data-title');
1254
+ var row = title.substr(1, 1);
1255
+ var col = title.substr(3, 1);
1256
+ var cal = $(e.target).parents('.calendar');
1257
+ var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
1258
+
1259
+ //
1260
+ // this function needs to do a few things:
1261
+ // * alternate between selecting a start and end date for the range,
1262
+ // * if the time picker is enabled, apply the hour/minute/second from the select boxes to the clicked date
1263
+ // * if autoapply is enabled, and an end date was chosen, apply the selection
1264
+ // * if single date picker mode, and time picker isn't enabled, apply the selection immediately
1265
+ //
1266
+
1267
+ if (this.endDate || date.isBefore(this.startDate)) {
1268
+ if (this.timePicker) {
1269
+ var hour = parseInt(this.container.find('.left .hourselect').val(), 10);
1270
+ if (!this.timePicker24Hour) {
1271
+ var ampm = cal.find('.ampmselect').val();
1272
+ if (ampm === 'PM' && hour < 12)
1273
+ hour += 12;
1274
+ if (ampm === 'AM' && hour === 12)
1275
+ hour = 0;
1276
+ }
1277
+ var minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
1278
+ var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
1279
+ date = date.clone().hour(hour).minute(minute).second(second);
1280
+ }
1281
+ this.endDate = null;
1282
+ this.setStartDate(date.clone());
1283
+ } else {
1284
+ if (this.timePicker) {
1285
+ var hour = parseInt(this.container.find('.right .hourselect').val(), 10);
1286
+ if (!this.timePicker24Hour) {
1287
+ var ampm = this.container.find('.right .ampmselect').val();
1288
+ if (ampm === 'PM' && hour < 12)
1289
+ hour += 12;
1290
+ if (ampm === 'AM' && hour === 12)
1291
+ hour = 0;
1292
+ }
1293
+ var minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
1294
+ var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
1295
+ date = date.clone().hour(hour).minute(minute).second(second);
1296
+ }
1297
+ this.setEndDate(date.clone());
1298
+ if (this.autoApply)
1299
+ this.clickApply();
1300
+ }
1301
+
1302
+ if (this.singleDatePicker) {
1303
+ this.setEndDate(this.startDate);
1304
+ if (!this.timePicker)
1305
+ this.clickApply();
1306
+ }
1307
+
1308
+ this.updateView();
1309
+
1310
+ },
1311
+
1312
+ clickApply: function(e) {
1313
+ this.hide();
1314
+ this.element.trigger('apply.daterangepicker', this);
1315
+ },
1316
+
1317
+ clickCancel: function(e) {
1318
+ this.startDate = this.oldStartDate;
1319
+ this.endDate = this.oldEndDate;
1320
+ this.hide();
1321
+ this.element.trigger('cancel.daterangepicker', this);
1322
+ },
1323
+
1324
+ monthOrYearChanged: function(e) {
1325
+ var isLeft = $(e.target).closest('.calendar').hasClass('left'),
1326
+ leftOrRight = isLeft ? 'left' : 'right',
1327
+ cal = this.container.find('.calendar.'+leftOrRight);
1328
+
1329
+ // Month must be Number for new moment versions
1330
+ var month = parseInt(cal.find('.monthselect').val(), 10);
1331
+ var year = cal.find('.yearselect').val();
1332
+
1333
+ if (!isLeft) {
1334
+ if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) {
1335
+ month = this.startDate.month();
1336
+ year = this.startDate.year();
1337
+ }
1338
+ }
1339
+
1340
+ if (this.minDate) {
1341
+ if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) {
1342
+ month = this.minDate.month();
1343
+ year = this.minDate.year();
1344
+ }
1345
+ }
1346
+
1347
+ if (this.maxDate) {
1348
+ if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) {
1349
+ month = this.maxDate.month();
1350
+ year = this.maxDate.year();
1351
+ }
1352
+ }
1353
+
1354
+ if (isLeft) {
1355
+ this.leftCalendar.month.month(month).year(year);
1356
+ if (this.linkedCalendars)
1357
+ this.rightCalendar.month = this.leftCalendar.month.clone().add(1, 'month');
1358
+ } else {
1359
+ this.rightCalendar.month.month(month).year(year);
1360
+ if (this.linkedCalendars)
1361
+ this.leftCalendar.month = this.rightCalendar.month.clone().subtract(1, 'month');
1362
+ }
1363
+ this.updateCalendars();
1364
+ },
1365
+
1366
+ timeChanged: function(e) {
1367
+
1368
+ var cal = $(e.target).closest('.calendar'),
1369
+ isLeft = cal.hasClass('left');
1370
+
1371
+ var hour = parseInt(cal.find('.hourselect').val(), 10);
1372
+ var minute = parseInt(cal.find('.minuteselect').val(), 10);
1373
+ var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0;
1374
+
1375
+ if (!this.timePicker24Hour) {
1376
+ var ampm = cal.find('.ampmselect').val();
1377
+ if (ampm === 'PM' && hour < 12)
1378
+ hour += 12;
1379
+ if (ampm === 'AM' && hour === 12)
1380
+ hour = 0;
1381
+ }
1382
+
1383
+ if (isLeft) {
1384
+ var start = this.startDate.clone();
1385
+ start.hour(hour);
1386
+ start.minute(minute);
1387
+ start.second(second);
1388
+ this.setStartDate(start);
1389
+ if (this.singleDatePicker) {
1390
+ this.endDate = this.startDate.clone();
1391
+ } else if (this.endDate && this.endDate.format('YYYY-MM-DD') == start.format('YYYY-MM-DD') && this.endDate.isBefore(start)) {
1392
+ this.setEndDate(start.clone());
1393
+ }
1394
+ } else if (this.endDate) {
1395
+ var end = this.endDate.clone();
1396
+ end.hour(hour);
1397
+ end.minute(minute);
1398
+ end.second(second);
1399
+ this.setEndDate(end);
1400
+ }
1401
+
1402
+ //update the calendars so all clickable dates reflect the new time component
1403
+ this.updateCalendars();
1404
+
1405
+ //update the form inputs above the calendars with the new time
1406
+ this.updateFormInputs();
1407
+
1408
+ //re-render the time pickers because changing one selection can affect what's enabled in another
1409
+ this.renderTimePicker('left');
1410
+ this.renderTimePicker('right');
1411
+
1412
+ },
1413
+
1414
+ formInputsChanged: function(e) {
1415
+ var isRight = $(e.target).closest('.calendar').hasClass('right');
1416
+ var start = moment(this.container.find('input[name="daterangepicker_start"]').val(), this.locale.format);
1417
+ var end = moment(this.container.find('input[name="daterangepicker_end"]').val(), this.locale.format);
1418
+
1419
+ if (start.isValid() && end.isValid()) {
1420
+
1421
+ if (isRight && end.isBefore(start))
1422
+ start = end.clone();
1423
+
1424
+ this.setStartDate(start);
1425
+ this.setEndDate(end);
1426
+
1427
+ if (isRight) {
1428
+ this.container.find('input[name="daterangepicker_start"]').val(this.startDate.format(this.locale.format));
1429
+ } else {
1430
+ this.container.find('input[name="daterangepicker_end"]').val(this.endDate.format(this.locale.format));
1431
+ }
1432
+
1433
+ }
1434
+
1435
+ this.updateCalendars();
1436
+ if (this.timePicker) {
1437
+ this.renderTimePicker('left');
1438
+ this.renderTimePicker('right');
1439
+ }
1440
+ },
1441
+
1442
+ elementChanged: function() {
1443
+ if (!this.element.is('input')) return;
1444
+ if (!this.element.val().length) return;
1445
+ if (this.element.val().length < this.locale.format.length) return;
1446
+
1447
+ var dateString = this.element.val().split(this.locale.separator),
1448
+ start = null,
1449
+ end = null;
1450
+
1451
+ if (dateString.length === 2) {
1452
+ start = moment(dateString[0], this.locale.format);
1453
+ end = moment(dateString[1], this.locale.format);
1454
+ }
1455
+
1456
+ if (this.singleDatePicker || start === null || end === null) {
1457
+ start = moment(this.element.val(), this.locale.format);
1458
+ end = start;
1459
+ }
1460
+
1461
+ if (!start.isValid() || !end.isValid()) return;
1462
+
1463
+ this.setStartDate(start);
1464
+ this.setEndDate(end);
1465
+ this.updateView();
1466
+ },
1467
+
1468
+ keydown: function(e) {
1469
+ //hide on tab or enter
1470
+ if ((e.keyCode === 9) || (e.keyCode === 13)) {
1471
+ this.hide();
1472
+ }
1473
+ },
1474
+
1475
+ updateElement: function() {
1476
+ if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
1477
+ this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
1478
+ this.element.trigger('change');
1479
+ } else if (this.element.is('input') && this.autoUpdateInput) {
1480
+ this.element.val(this.startDate.format(this.locale.format));
1481
+ this.element.trigger('change');
1482
+ }
1483
+ },
1484
+
1485
+ remove: function() {
1486
+ this.container.remove();
1487
+ this.element.off('.daterangepicker');
1488
+ this.element.removeData();
1489
+ }
1490
+
1491
+ };
1492
+
1493
+ $.fn.daterangepicker = function(options, callback) {
1494
+ this.each(function() {
1495
+ var el = $(this);
1496
+ if (el.data('daterangepicker'))
1497
+ el.data('daterangepicker').remove();
1498
+ el.data('daterangepicker', new DateRangePicker(el, options, callback));
1499
+ });
1500
+ return this;
1501
+ };
1502
+
1503
+ return DateRangePicker;
1504
+
1505
+ }));