1/*! RESOURCE: /scripts/bootstrap-datetimepicker.js */ 2;(function (root, factory) { 3 'use strict'; 4 if (typeof define === 'function' && define.amd) { 5 define(['jquery', 'moment'], factory); 6 } else if (typeof exports === 'object') { 7 factory(require('jquery'), require('moment')); 8 } 9 else { 10 if (!jQuery) { 11 throw new Error('bootstrap-datetimepicker requires jQuery to be loaded first'); 12 } 13 if (!moment) { 14 throw new Error('bootstrap-datetimepicker requires moment.js to be loaded first'); 15 } 16 factory(root.jQuery, moment); 17 } 18}(this, function ($, moment) { 19 'use strict'; 20 if (typeof moment === 'undefined') { 21 throw new Error('momentjs is required'); 22 } 23 var dpgId = 0, 24 DateTimePicker = function (element, options) { 25 var defaults = $.fn.datetimepicker.defaults, 26 icons = { 27 time: 'glyphicon glyphicon-time', 28 date: 'glyphicon glyphicon-calendar', 29 up: 'glyphicon glyphicon-chevron-up', 30 down: 'glyphicon glyphicon-chevron-down' 31 }, 32 picker = this, 33 errored = false, 34 dDate, 35 init = function () { 36 var icon = false, localeData, rInterval; 37 picker.options = $.extend({}, defaults, options); 38 picker.options.icons = $.extend({}, icons, picker.options.icons); 39 picker.element = $(element); 40 dataToOptions(); 41 if (!(picker.options.pickTime || picker.options.pickDate)) { 42 throw new Error('Must choose at least one picker'); 43 } 44 picker.id = dpgId++; 45 moment.locale(picker.options.language); 46 picker.date = moment(); 47 picker.unset = false; 48 picker.isInput = picker.element.is('input'); 49 picker.component = false; 50 if (picker.element.hasClass('input-group')) { 51if (picker.element.find('.datepickerbutton').size() === 0) { 52 picker.component = picker.element.find('[class^="input-group-"]'); 53 } 54 else { 55 picker.component = picker.element.find('.datepickerbutton'); 56 } 57 } 58 picker.format = picker.options.format; 59 localeData = moment().localeData(); 60 if (!picker.format) { 61 picker.format = (picker.options.pickDate ? localeData.longDateFormat('L') : ''); 62 if (picker.options.pickDate && picker.options.pickTime) { 63 picker.format += ' '; 64 } 65 picker.format += (picker.options.pickTime ? localeData.longDateFormat('LT') : ''); 66 if (picker.options.useSeconds) { 67 if (localeData.longDateFormat('LT').indexOf(' A') !== -1) { 68 picker.format = picker.format.split(' A')[0] + ':ss A'; 69 } 70 else { 71 picker.format += ':ss'; 72 } 73 } 74 } 75 picker.use24hours = (picker.format.toLowerCase().indexOf('a') < 0 && picker.format.indexOf('h') < 0); 76 if (picker.component) { 77 icon = picker.component.find('span'); 78 } 79 if (picker.options.pickTime) { 80 if (icon) { 81 icon.addClass(picker.options.icons.time); 82 } 83 } 84 if (picker.options.pickDate) { 85 if (icon) { 86 icon.removeClass(picker.options.icons.time); 87 icon.addClass(picker.options.icons.date); 88 } 89 } 90 picker.options.widgetParent = 91 typeof picker.options.widgetParent === 'string' && picker.options.widgetParent || 92 (window.NOW && window.NOW.isAIUXContainer === true && ($('#angular-hoist-host')[0])) || 93 picker.element.parents().filter(function () { 94 return 'scroll' === $(this).css('overflow-y'); 95 }).get(0) || 96 'body'; 97 picker.widget = $(getTemplate()).appendTo(picker.options.widgetParent); 98 picker.minViewMode = picker.options.minViewMode || 0; 99 if (typeof picker.minViewMode === 'string') { 100 switch (picker.minViewMode) { 101 case 'months': 102 picker.minViewMode = 1; 103 break; 104 case 'years': 105 picker.minViewMode = 2; 106 break; 107 default: 108 picker.minViewMode = 0; 109 break; 110 } 111 } 112 picker.viewMode = picker.options.viewMode || 0; 113 if (typeof picker.viewMode === 'string') { 114 switch (picker.viewMode) { 115 case 'months': 116 picker.viewMode = 1; 117 break; 118 case 'years': 119 picker.viewMode = 2; 120 break; 121 default: 122 picker.viewMode = 0; 123 break; 124 } 125 } 126 picker.viewMode = Math.max(picker.viewMode, picker.minViewMode); 127 picker.options.disabledDates = indexGivenDates(picker.options.disabledDates); 128 picker.options.enabledDates = indexGivenDates(picker.options.enabledDates); 129 picker.startViewMode = picker.viewMode; 130 picker.setMinDate(picker.options.minDate); 131 picker.setMaxDate(picker.options.maxDate); 132 fillDow(); 133 fillMonths(); 134 fillHours(); 135 fillMinutes(); 136 fillSeconds(); 137 update(); 138 showMode(); 139 if (!getPickerInput().prop('disabled')) { 140 attachDatePickerEvents(); 141 } 142 if (picker.options.defaultDate !== '' && getPickerInput().val() === '') { 143 picker.setValue(picker.options.defaultDate); 144 } 145 if (picker.options.minuteStepping !== 1) { 146 rInterval = picker.options.minuteStepping; 147picker.date.minutes((Math.round(picker.date.minutes() / rInterval) * rInterval) % 60).seconds(0); 148 } 149 }, 150 getPickerInput = function () { 151 var input; 152 if (picker.isInput) { 153 return picker.element; 154 } 155 input = picker.element.find('.datepickerinput'); 156 if (input.size() === 0) { 157 input = picker.element.find('input'); 158 } 159 else if (!input.is('input')) { 160 throw new Error('CSS class "datepickerinput" cannot be applied to non input element'); 161 } 162 return input; 163 }, 164 dataToOptions = function () { 165 var eData; 166 if (picker.element.is('input')) { 167 eData = picker.element.data(); 168 } 169 else { 170 eData = picker.element.find('input').data(); 171 } 172 if (eData.dateFormat !== undefined) { 173 picker.options.format = eData.dateFormat; 174 } 175 if (eData.datePickdate !== undefined) { 176 picker.options.pickDate = eData.datePickdate; 177 } 178 if (eData.datePicktime !== undefined) { 179 picker.options.pickTime = eData.datePicktime; 180 } 181 if (eData.dateUseminutes !== undefined) { 182 picker.options.useMinutes = eData.dateUseminutes; 183 } 184 if (eData.dateUseseconds !== undefined) { 185 picker.options.useSeconds = eData.dateUseseconds; 186 } 187 if (eData.dateUsecurrent !== undefined) { 188 picker.options.useCurrent = eData.dateUsecurrent; 189 } 190 if (eData.calendarWeeks !== undefined) { 191 picker.options.calendarWeeks = eData.calendarWeeks; 192 } 193 if (eData.dateMinutestepping !== undefined) { 194 picker.options.minuteStepping = eData.dateMinutestepping; 195 } 196 if (eData.dateMindate !== undefined) { 197 picker.options.minDate = eData.dateMindate; 198 } 199 if (eData.dateMaxdate !== undefined) { 200 picker.options.maxDate = eData.dateMaxdate; 201 } 202 if (eData.dateShowtoday !== undefined) { 203 picker.options.showToday = eData.dateShowtoday; 204 } 205 if (eData.dateCollapse !== undefined) { 206 picker.options.collapse = eData.dateCollapse; 207 } 208 if (eData.dateLanguage !== undefined) { 209 picker.options.language = eData.dateLanguage; 210 } 211 if (eData.dateDefaultdate !== undefined) { 212 picker.options.defaultDate = eData.dateDefaultdate; 213 } 214 if (eData.dateDisableddates !== undefined) { 215 picker.options.disabledDates = eData.dateDisableddates; 216 } 217 if (eData.dateEnableddates !== undefined) { 218 picker.options.enabledDates = eData.dateEnableddates; 219 } 220 if (eData.dateIcons !== undefined) { 221 picker.options.icons = eData.dateIcons; 222 } 223 if (eData.dateUsestrict !== undefined) { 224 picker.options.useStrict = eData.dateUsestrict; 225 } 226 if (eData.dateDirection !== undefined) { 227 picker.options.direction = eData.dateDirection; 228 } 229 if (eData.dateSidebyside !== undefined) { 230 picker.options.sideBySide = eData.dateSidebyside; 231 } 232 if (eData.dateDaysofweekdisabled !== undefined) { 233 picker.options.daysOfWeekDisabled = eData.dateDaysofweekdisabled; 234 } 235 }, 236 place = function () { 237 var position = 'fixed', 238 offset = picker.component ? picker.component.offset() : picker.element.offset(), 239 $window = $(window), 240 placePosition; 241 picker.width = picker.component ? picker.component.outerWidth() : picker.element.outerWidth(); 242 offset.top = offset.top + picker.element.outerHeight(); 243 if (picker.options.direction === 'up') { 244 placePosition = 'top'; 245 } else if (picker.options.direction === 'bottom') { 246 placePosition = 'bottom'; 247 } else if (picker.options.direction === 'auto') { 248 if (offset.top + picker.widget.height() > $window.height() + $window.scrollTop() && picker.widget.height() + picker.element.outerHeight() < offset.top) { 249 placePosition = 'top'; 250 } else { 251 placePosition = 'bottom'; 252 } 253 } 254 if (placePosition === 'top') { 255 offset.top = offset.top - picker.element.outerHeight() - picker.widget.height() - 13; 256 picker.widget.addClass('top').removeClass('bottom'); 257 } else { 258 offset.top += 1; 259 picker.widget.addClass('bottom').removeClass('top'); 260 } 261 if (picker.options.width !== undefined) { 262 picker.widget.width(picker.options.width); 263 } 264 if (picker.options.orientation === 'left') { 265 picker.widget.addClass('left-oriented'); 266 offset.left = offset.left - picker.widget.width() + 20; 267 } 268 if (isInFixed()) { 269 position = 'fixed'; 270 offset.top -= $window.scrollTop(); 271 offset.left -= $window.scrollLeft(); 272 } 273 if ($window.width() < offset.left + picker.widget.outerWidth()) { 274 offset.right = $window.width() - offset.left - picker.width; 275 offset.left = 'auto'; 276 picker.widget.addClass('pull-right'); 277 } else { 278 offset.right = 'auto'; 279 picker.widget.removeClass('pull-right'); 280 } 281 if (placePosition === 'top') { 282 picker.widget.css({ 283 position: position, 284 bottom: 'auto', 285 top: offset.top, 286 left: offset.left, 287 right: offset.right 288 }); 289 } else { 290 picker.widget.css({ 291 position: position, 292 top: offset.top, 293 bottom: 'auto', 294 left: offset.left, 295 right: offset.right 296 }); 297 } 298 }, 299 notifyChange = function (oldDate, eventType) { 300 if (moment(picker.date).isSame(moment(oldDate)) && !errored) { 301 return; 302 } 303 errored = false;
304 picker.element.trigger({ 305 type: 'dp.change', 306 date: moment(picker.date), 307 oldDate: moment(oldDate) 308 }); 309 if (eventType !== 'change') { 310 picker.element.change(); 311 } 312 }, 313 notifyError = function (date) { 314 errored = true; 315 picker.element.trigger({ 316 type: 'dp.error', 317 date: moment(date, picker.format, picker.options.useStrict) 318 }); 319 }, 320 update = function (newDate) { 321 moment.locale(picker.options.language); 322 var dateStr = newDate; 323 if (!dateStr) { 324 dateStr = getPickerInput().val(); 325 if (dateStr) { 326 picker.date = moment(dateStr, picker.format, picker.options.useStrict); 327 } 328 if (!picker.date) { 329 picker.date = moment(); 330 } 331 } 332 picker.viewDate = moment(picker.date).startOf('month'); 333 fillDate(); 334 fillTime(); 335 }, 336 fillDow = function () { 337 moment.locale(picker.options.language); 338 if (picker.options.language == 'pt-br') { 339 moment.updateLocale('pt-br', { weekdaysMin: ["D", "S", "T", "Q", "Q", "S", "S"]}); 340 } 341 var html = $('<tr>'), weekdaysMin = moment.weekdaysMin(), i, j, 342 startOfWeek = moment().localeData()._week.dow; 343 if (picker.options.calendarWeeks === true) { 344html.append('<th class="cw">#</th>'); 345 } 346 for (i = 0; i < 7; i++) { 347 j = (startOfWeek + i) % 7; 348html.append('<th class="dow">' + weekdaysMin[j] + '</th>'); 349 } 350 picker.widget.find('.datepicker-days thead').append(html); 351 }, 352 fillMonths = function () { 353 moment.locale(picker.options.language); 354 var html = '', i, monthsShort = moment.monthsShort(); 355 for (i = 0; i < 12; i++) { 356html += '<span class="month">' + monthsShort[i] + '</span>'; 357 } 358 picker.widget.find('.datepicker-months td').append(html); 359 }, 360 fillDate = function () { 361 if (!picker.options.pickDate) { 362 return; 363 } 364 moment.locale(picker.options.language); 365 var year = picker.viewDate.year(), 366 month = picker.viewDate.month(), 367 startYear = picker.options.minDate.year(), 368 startMonth = picker.options.minDate.month(), 369 endYear = picker.options.maxDate.year(), 370 endMonth = picker.options.maxDate.month(), 371 currentDate, 372 prevMonth, nextMonth, html = [], row, clsName, i, days, yearCont, currentYear, months = moment.months(); 373 picker.widget.find('.datepicker-days').find('.disabled').removeClass('disabled'); 374 picker.widget.find('.datepicker-months').find('.disabled').removeClass('disabled'); 375 picker.widget.find('.datepicker-years').find('.disabled').removeClass('disabled'); 376 picker.widget.find('.datepicker-days th:eq(1)').text( 377 months[month] + ' ' + year); 378 prevMonth = moment(picker.viewDate, picker.format, picker.options.useStrict).subtract(1, 'months'); 379 days = prevMonth.daysInMonth(); 380 prevMonth.date(days).startOf('week'); 381 if ((year === startYear && month <= startMonth) || year < startYear) { 382 picker.widget.find('.datepicker-days th:eq(0)').addClass('disabled'); 383 } 384 if ((year === endYear && month >= endMonth) || year > endYear) { 385 picker.widget.find('.datepicker-days th:eq(2)').addClass('disabled'); 386 } 387 nextMonth = moment(prevMonth).add(42, 'd'); 388 while (prevMonth.isBefore(nextMonth)) { 389 if (prevMonth.weekday() === moment().startOf('week').weekday()) { 390 row = $('<tr>'); 391 html.push(row); 392 if (picker.options.calendarWeeks === true) { 393row.append('<td class="cw">' + prevMonth.week() + '</td>'); 394 } 395 } 396 clsName = ''; 397 if (prevMonth.year() < year || (prevMonth.year() === year && prevMonth.month() < month)) { 398 clsName += ' old'; 399 } else if (prevMonth.year() > year || (prevMonth.year() === year && prevMonth.month() > month)) { 400 clsName += ' new'; 401 } 402 if (prevMonth.isSame(moment({y: picker.date.year(), M: picker.date.month(), d: picker.date.date()}))) { 403 clsName += ' active'; 404 } 405 if (isInDisableDates(prevMonth, 'day') || !isInEnableDates(prevMonth)) { 406 clsName += ' disabled'; 407 } 408 if (picker.options.showToday === true) { 409 if (prevMonth.isSame(moment(), 'day')) { 410 clsName += ' today'; 411 } 412 } 413 if (picker.options.daysOfWeekDisabled) { 414 for (i = 0; i < picker.options.daysOfWeekDisabled.length; i++) { 415 if (prevMonth.day() === picker.options.daysOfWeekDisabled[i]) { 416 clsName += ' disabled'; 417 break; 418 } 419 } 420 } 421row.append('<td class="day' + clsName + '"><div>' + prevMonth.date() + '</div></td>'); 422 currentDate = prevMonth.date(); 423 prevMonth.add(1, 'd'); 424 if (currentDate === prevMonth.date()) { 425 prevMonth.add(1, 'd'); 426 } 427 } 428 picker.widget.find('.datepicker-days tbody').empty().append(html); 429 currentYear = picker.date.year(); 430 months = picker.widget.find('.datepicker-months').find('th:eq(1)').text(year).end().find('span').removeClass('active'); 431 if (currentYear === year) { 432 months.eq(picker.date.month()).addClass('active'); 433 } 434 if (year - 1 < startYear) { 435 picker.widget.find('.datepicker-months th:eq(0)').addClass('disabled'); 436 } 437 if (year + 1 > endYear) { 438 picker.widget.find('.datepicker-months th:eq(2)').addClass('disabled'); 439 } 440 for (i = 0; i < 12; i++) { 441 if ((year === startYear && startMonth > i) || (year < startYear)) { 442 $(months[i]).addClass('disabled'); 443 } else if ((year === endYear && endMonth < i) || (year > endYear)) { 444 $(months[i]).addClass('disabled'); 445 } 446 } 447 html = ''; 448year = parseInt(year / 10, 10) * 10; 449 yearCont = picker.widget.find('.datepicker-years').find( 450 'th:eq(1)').text(year + '-' + (year + 9)).parents('table').find('td'); 451 picker.widget.find('.datepicker-years').find('th').removeClass('disabled'); 452 if (startYear > year) { 453 picker.widget.find('.datepicker-years').find('th:eq(0)').addClass('disabled'); 454 } 455 if (endYear < year + 9) { 456 picker.widget.find('.datepicker-years').find('th:eq(2)').addClass('disabled'); 457 } 458 year -= 1; 459 for (i = -1; i < 11; i++) { 460html += '<span class="year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + ((year < startYear || year > endYear) ? ' disabled' : '') + '">' + year + '</span>'; 461 year += 1; 462 } 463 yearCont.html(html); 464 }, 465 fillHours = function () { 466 moment.locale(picker.options.language); 467 var table = picker.widget.find('.timepicker .timepicker-hours table'), html = '', current, i, j; 468 table.parent().hide(); 469 if (picker.use24hours) { 470 current = 0; 471 for (i = 0; i < 6; i += 1) { 472 html += '<tr>'; 473 for (j = 0; j < 4; j += 1) { 474html += '<td class="hour">' + padLeft(current.toString()) + '</td>'; 475 current++; 476 } 477html += '</tr>'; 478 } 479 } 480 else { 481 current = 1; 482 for (i = 0; i < 3; i += 1) { 483 html += '<tr>'; 484 for (j = 0; j < 4; j += 1) { 485html += '<td class="hour">' + padLeft(current.toString()) + '</td>'; 486 current++; 487 } 488html += '</tr>'; 489 } 490 } 491 table.html(html); 492 }, 493 fillMinutes = function () { 494 var table = picker.widget.find('.timepicker .timepicker-minutes table'), html = '', current = 0, i, j, step = picker.options.minuteStepping; 495 table.parent().hide(); 496 if (step === 1) { 497 step = 5; 498 } 499for (i = 0;
499 i < Math.ceil(60 / step / 4) ; i++) { 500 html += '<tr>'; 501 for (j = 0; j < 4; j += 1) { 502 if (current < 60) { 503html += '<td class="minute">' + padLeft(current.toString()) + '</td>'; 504 current += step; 505 } else { 506html += '<td></td>'; 507 } 508 } 509html += '</tr>'; 510 } 511 table.html(html); 512 }, 513 fillSeconds = function () { 514 var table = picker.widget.find('.timepicker .timepicker-seconds table'), html = '', current = 0, i, j; 515 table.parent().hide(); 516 for (i = 0; i < 3; i++) { 517 html += '<tr>'; 518 for (j = 0; j < 4; j += 1) { 519html += '<td class="second">' + padLeft(current.toString()) + '</td>'; 520 current += 5; 521 } 522html += '</tr>'; 523 } 524 table.html(html); 525 }, 526 fillTime = function () { 527 if (!picker.date) { 528 return; 529 } 530 var timeComponents = picker.widget.find('.timepicker span[data-time-component]'), 531 hour = picker.date.hours(), 532 period = picker.date.format('A'); 533 if (!picker.use24hours) { 534 if (hour === 0) { 535 hour = 12; 536 } else if (hour !== 12) { 537 hour = hour % 12; 538 } 539 picker.widget.find('.timepicker [data-action=togglePeriod]').text(period); 540 } 541 timeComponents.filter('[data-time-component=hours]').text(padLeft(hour)); 542 timeComponents.filter('[data-time-component=minutes]').text(padLeft(picker.date.minutes())); 543 timeComponents.filter('[data-time-component=seconds]').text(padLeft(picker.date.second())); 544 }, 545 click = function (e) { 546 e.stopPropagation(); 547 e.preventDefault(); 548 picker.unset = false; 549 var target = $(e.target).closest('span, td, th'), month, year, step, day, oldDate = moment(picker.date); 550 if (target.length === 1) { 551 if (!target.is('.disabled')) { 552 switch (target[0].nodeName.toLowerCase()) { 553 case 'th': 554 switch (target[0].className) { 555 case 'picker-switch': 556 showMode(1); 557 break; 558 case 'prev': 559 case 'next': 560 step = dpGlobal.modes[picker.viewMode].navStep; 561 if (target[0].className === 'prev') { 562 step = step * -1; 563 } 564 picker.viewDate.add(step, dpGlobal.modes[picker.viewMode].navFnc); 565 fillDate(); 566 break; 567 } 568 break; 569 case 'span': 570 if (target.is('.month')) { 571 month = target.parent().find('span').index(target); 572 picker.viewDate.month(month); 573 } else { 574 year = parseInt(target.text(), 10) || 0; 575 picker.viewDate.year(year); 576 } 577 if (picker.viewMode === picker.minViewMode) { 578 picker.date = moment({ 579 y: picker.viewDate.year(), 580 M: picker.viewDate.month(), 581 d: picker.viewDate.date(), 582 h: picker.date.hours(), 583 m: picker.date.minutes(), 584 s: picker.date.seconds() 585 }); 586 set(); 587 notifyChange(oldDate, e.type); 588 } 589 showMode(-1); 590 fillDate(); 591 break; 592 case 'td': 593 if (target.is('.day')) { 594 day = parseInt(target.text(), 10) || 1;
595 month = picker.viewDate.month(); 596 year = picker.viewDate.year(); 597 if (target.is('.old')) { 598 if (month === 0) { 599 month = 11; 600 year -= 1; 601 } else { 602 month -= 1; 603 } 604 } else if (target.is('.new')) { 605 if (month === 11) { 606 month = 0; 607 year += 1; 608 } else { 609 month += 1; 610 } 611 } 612 picker.date = moment({ 613 y: year, 614 M: month, 615 d: day, 616 h: picker.date.hours(), 617 m: picker.date.minutes(), 618 s: picker.date.seconds() 619 } 620 ); 621 picker.viewDate = moment({ 622 y: year, M: month, d: Math.min(28, day) 623 }); 624 fillDate(); 625 set(); 626 notifyChange(oldDate, e.type); 627 } 628 break; 629 } 630 } 631 } 632 }, 633 actions = { 634 incrementYears: function () { 635 checkDate('add', 'years', 1); 636 }, 637 incrementMonths: function () { 638 checkDate('add', 'months', 1); 639 }, 640 incrementDays: function () { 641 checkDate('add', 'days', 1); 642 }, 643 incrementWeeks: function () { 644 checkDate('add', 'weeks', 1); 645 }, 646 incrementHours: function () { 647 checkDate('add', 'hours', 1); 648 }, 649 incrementMinutes: function () { 650 checkDate('add', 'minutes', picker.options.minuteStepping); 651 }, 652 incrementSeconds: function () { 653 checkDate('add', 'seconds', 1); 654 }, 655 decrementYears: function () { 656 checkDate('subtract', 'years', 1); 657 }, 658 decrementMonths: function () { 659 checkDate('subtract', 'months', 1); 660 }, 661 decrementWeeks: function () { 662 checkDate('subtract', 'weeks', 1); 663 }, 664 decrementDays: function () { 665 checkDate('subtract', 'days', 1); 666 }, 667 decrementHours: function () { 668 checkDate('subtract', 'hours', 1); 669 }, 670 decrementMinutes: function () { 671 checkDate('subtract', 'minutes', picker.options.minuteStepping); 672 }, 673 decrementSeconds: function () { 674 checkDate('subtract', 'seconds', 1); 675 }, 676 startOfMonth: function () { 677 picker.setValue(moment().startOf('month')); 678 }, 679 endOfMonth: function () { 680 picker.setValue(moment().endOf('month')); 681 }, 682 startOfCurrentMonth: function () { 683 picker.setValue(moment(picker.date).startOf('month')); 684 }, 685 endOfCurrentMonth: function () { 686 picker.setValue(moment(picker.date).endOf('month')); 687 }, 688 togglePeriod: function () { 689 var hour = picker.date.hours(); 690 if (hour >= 12) { 691 hour -= 12; 692 } else { 693 hour += 12; 694 } 695 picker.date.hours(hour); 696 }, 697 showPicker: function () { 698 picker.widget.find('.timepicker > div:not(.timepicker-picker)').hide(); 699 picker.widget.find('.timepicker .timepicker-picker').show(); 700 }, 701 showHours: function () { 702 picker.widget.find('.timepicker .timepicker-picker').hide(); 703 picker.widget.find('.timepicker .timepicker-hours').show(); 704 }, 705 showMinutes: function () { 706 picker.widget.find('.timepicker .timepicker-picker').hide(); 707 picker.widget.find('.timepicker .timepicker-minutes').show(); 708 }, 709 showSeconds: function () { 710 picker.widget.find('.timepicker .timepicker-picker').hide(); 711 picker.widget.find('.timepicker .timepicker-seconds').show(); 712 }, 713 selectHour: function (e) { 714 var hour = parseInt($(e.target).text(), 10); 715 if (!picker.use24hours) { 716 if (picker.date.hours() >= 12) { 717 if (hour !== 12) { 718 hour += 12; 719 } 720 } else { 721 if (hour === 12) { 722 hour = 0; 723 } 724 } 725 } 726 picker.date.hours(hour); 727 actions.showPicker.call(picker); 728 }, 729 selectMinute: function (e) { 730 picker.date.minutes(parseInt($(e.target).text(), 10)); 731 actions.showPicker.call(picker); 732 }, 733 selectSecond: function (e) { 734 picker.date.seconds(parseInt($(e.target).text(), 10)); 735 actions.showPicker.call(picker); 736 }, 737 toggleDateTimePicker: function (e) { 738 var toggleElement = picker.widget.find('.accordion-toggle')[0]; 739 $(toggleElement).trigger('click.togglePicker'); 740 } 741 }, 742 doAction = function (e) { 743 var oldDate = moment(picker.date), 744 action = $(e.currentTarget).data('action') || e.action,
745 rv = actions[action].apply(picker, arguments); 746 stopEvent(e); 747 if (!picker.date) { 748 picker.date = moment({y: 1970}); 749 } 750 set(); 751 fillTime(); 752 notifyChange(oldDate, e.type); 753 picker.element.trigger({ 754 type: 'dp.action', 755 picker: picker, 756 date: picker.date, 757 action: action 758 }); 759 return rv; 760 }, 761 stopEvent = function (e) { 762 e.stopPropagation(); 763 e.preventDefault(); 764 }, 765 keydown = function (e) { 766if (e.keyCode === 27) { 767 picker.hide(); 768 } 769 }, 770 change = function (e) { 771 moment.locale(picker.options.language); 772 var input = $(e.target), oldDate = moment(picker.date), newDate = moment(input.val(), picker.format, picker.options.useStrict); 773 if (newDate.isValid() && !isInDisableDates(newDate) && isInEnableDates(newDate)) { 774 update(); 775 picker.setValue(newDate); 776 notifyChange(oldDate, e.type); 777 set(); 778 } 779 else { 780 picker.viewDate = oldDate; 781 picker.unset = true; 782 notifyChange(oldDate, e.type); 783 notifyError(newDate); 784 } 785 }, 786 showMode = function (dir) { 787 if (dir) { 788 picker.viewMode = Math.max(picker.minViewMode, Math.min(2, picker.viewMode + dir)); 789 } 790 picker.widget.find('.datepicker > div').hide().filter('.datepicker-' + dpGlobal.modes[picker.viewMode].clsName).show(); 791 }, 792 attachDatePickerEvents = function () { 793 var $this, $parent, expanded, closed, collapseData; 794picker.widget.on('click', '.datepicker *', $.proxy(click, this)); 795picker.widget.on('click', '[data-action]', $.proxy(doAction, this)); 796 picker.widget.on('mousedown', $.proxy(stopEvent, this)); 797 picker.element.on('keydown', $.proxy(keydown, this)); 798 picker.widget.on('doAction', $.proxy(doAction, this)); 799 if (picker.options.pickDate && picker.options.pickTime) { 800 picker.widget.on('click.togglePicker', '.accordion-toggle', function (e) { 801 e.stopPropagation(); 802 $this = $(this); 803 $parent = $this.closest('ul'); 804 expanded = $parent.find('.in'); 805 closed = $parent.find('.collapse:not(.in)'); 806 if (expanded && expanded.length) { 807 collapseData = expanded.data('collapse'); 808 if (collapseData && collapseData.transitioning) { 809 return; 810 } 811 expanded.collapse('hide'); 812 closed.collapse('show'); 813 $this.find('span').toggleClass(picker.options.icons.time + ' ' + picker.options.icons.date); 814 if (picker.component) { 815 picker.component.find('span').toggleClass(picker.options.icons.time + ' ' + picker.options.icons.date); 816 } 817 } 818 picker.element.trigger({ 819 type: 'dp.toggle' 820 }); 821 }); 822 } 823 if (picker.isInput) { 824 picker.element.on({ 825 'click': $.proxy(picker.show, this), 826 'focus': $.proxy(picker.show, this), 827 'change': $.proxy(change, this), 828 'blur': $.proxy(picker.hide, this) 829 }); 830 } else { 831 picker.element.on({ 832 'change': $.proxy(change, this) 833 }, 'input'); 834 if (picker.component) { 835 picker.component.on('click', $.proxy(picker.show, this)); 836 picker.component.on('mousedown', $.proxy(stopEvent, this)); 837 } else { 838 picker.element.on('click', $.proxy(picker.show, this)); 839 } 840 } 841 }, 842 attachDatePickerGlobalEvents = function () { 843 $(window).on( 844 'resize.datetimepicker' + picker.id, $.proxy(place, this)); 845 if (!picker.isInput) { 846 $(document).on( 847 'mousedown.datetimepicker' + picker.id, $.proxy(picker.hide, this)); 848 } 849 }, 850 detachDatePickerEvents = function () { 851 picker.widget.off('click', '.datepicker *', picker.click); 852 picker.widget.off('click', '[data-action]'); 853 picker.widget.off('mousedown', picker.stopEvent); 854 if (picker.options.pickDate && picker.options.pickTime) { 855 picker.widget.off('click.togglePicker'); 856 } 857 if (picker.isInput) { 858 picker.element.off({
859 'focus': picker.show, 860 'change': change, 861 'click': picker.show, 862 'blur' : picker.hide 863 }); 864 } else { 865 picker.element.off({ 866 'change': change 867 }, 'input'); 868 if (picker.component) { 869 picker.component.off('click', picker.show); 870 picker.component.off('mousedown', picker.stopEvent); 871 } else { 872 picker.element.off('click', picker.show); 873 } 874 } 875 }, 876 detachDatePickerGlobalEvents = function () { 877 $(window).off('resize.datetimepicker' + picker.id); 878 if (!picker.isInput) { 879 $(document).off('mousedown.datetimepicker' + picker.id); 880 } 881 }, 882 isInFixed = function () { 883 if (picker.element) { 884 var parents = picker.element.parents(), inFixed = false, i; 885 for (i = 0; i < parents.length; i++) { 886 if ($(parents[i]).css('position') === 'fixed') { 887 inFixed = true; 888 break; 889 } 890 } 891 return inFixed; 892 } else { 893 return false; 894 } 895 }, 896 set = function () { 897 moment.locale(picker.options.language); 898 var formatted = ''; 899 if (!picker.unset) { 900 formatted = moment(picker.date).format(picker.format); 901 } 902 getPickerInput().val(formatted); 903 picker.element.data('date', formatted); 904 }, 905 checkDate = function (direction, unit, amount) { 906 moment.locale(picker.options.language); 907 var newDate; 908 if (direction === 'add') { 909 newDate = moment(picker.date); 910 if (newDate.hours() === 23) { 911 newDate.add(amount, unit); 912 } 913 newDate.add(amount, unit); 914 } 915 else { 916 newDate = moment(picker.date).subtract(amount, unit); 917 } 918 if (isInDisableDates(moment(newDate.subtract(amount, unit))) || isInDisableDates(newDate)) { 919 notifyError(newDate.format(picker.format)); 920 return; 921 } 922 if (direction === 'add') { 923 picker.date.add(amount, unit); 924 } 925 else { 926 picker.date.subtract(amount, unit); 927 } 928 picker.unset = false; 929 }, 930 isInDisableDates = function (date, timeUnit) { 931 moment.locale(picker.options.language); 932 var maxDate = moment(picker.options.maxDate, picker.format, picker.options.useStrict), 933 minDate = moment(picker.options.minDate, picker.format, picker.options.useStrict); 934 if (timeUnit) { 935 maxDate = maxDate.endOf(timeUnit); 936 minDate = minDate.startOf(timeUnit); 937 } 938 if (date.isAfter(maxDate) || date.isBefore(minDate)) { 939 return true; 940 } 941 if (picker.options.disabledDates === false) { 942 return false; 943 } 944 return picker.options.disabledDates[date.format('YYYY-MM-DD')] === true; 945 }, 946 isInEnableDates = function (date) { 947 moment.locale(picker.options.language); 948 if (picker.options.enabledDates === false) { 949 return true; 950 } 951 return picker.options.enabledDates[date.format('YYYY-MM-DD')] === true; 952 }, 953 indexGivenDates = function (givenDatesArray) { 954 var givenDatesIndexed = {}, givenDatesCount = 0, i; 955 for (i = 0; i < givenDatesArray.length; i++) { 956 if (moment.isMoment(givenDatesArray[i]) || givenDatesArray[i] instanceof Date) { 957 dDate = moment(givenDatesArray[i]); 958 } else { 959 dDate = moment(givenDatesArray[i], picker.format, picker.options.useStrict); 960 } 961 if (dDate.isValid()) { 962 givenDatesIndexed[dDate.format('YYYY-MM-DD')] = true; 963 givenDatesCount++; 964 } 965 } 966 if (givenDatesCount > 0) {
967 return givenDatesIndexed; 968 } 969 return false; 970 }, 971 padLeft = function (string) { 972 string = string.toString(); 973 if (string.length >= 2) { 974 return string; 975 } 976 return '0' + string; 977 }, 978 getTemplate = function () { 979 var 980 headTemplate = 981 '<thead>' + 982 '<tr>' + 983'<th class="prev">‹</th><th colspan="' + (picker.options.calendarWeeks ? '6' : '5') + '" class="picker-switch"></th><th class="next">›</th>' + 984'</tr>' + 985'</thead>', 986 contTemplate = 987'<tbody><tr><td colspan="' + (picker.options.calendarWeeks ? '8' : '7') + '"></td></tr></tbody>', 988 template = '<div class="datepicker-days">' + 989'<table class="table-condensed">' + headTemplate + '<tbody></tbody></table>' + 990'</div>' + 991 '<div class="datepicker-months">' + 992'<table class="table-condensed">' + headTemplate + contTemplate + '</table>' + 993'</div>' + 994 '<div class="datepicker-years">' + 995'<table class="table-condensed">' + headTemplate + contTemplate + '</table>' + 996'</div>', 997 ret = ''; 998 if (picker.options.pickDate && picker.options.pickTime) { 999 ret = '<div role="dialog" aria-label="' + g_choose_date_msg + '" class="bootstrap-datetimepicker-widget' + (picker.options.sideBySide ? ' timepicker-sbs' : '') + (picker.use24hours ? ' usetwentyfour' : '') + ' dropdown-menu" style="z-index:9999 !important;">'; 1000 if (picker.options.sideBySide) { 1001 ret += '<div class="row">' + 1002'<div class="col-sm-6 datepicker">' + template + '</div>' + 1003'<div class="col-sm-6 timepicker">' + tpGlobal.getTemplate() + '</div>' + 1004'</div>'; 1005 } else { 1006 ret += '<ul class="list-unstyled">' + 1007 '<li' + (picker.options.collapse ? ' class="collapse in"' : '') + '>' + 1008'<div class="datepicker">' + template + '</div>' + 1009'</li>' + 1010'<li class="picker-switch accordion-toggle"><a href="#" data-action="toggleDateTimePicker" class="btn" style="width:100%"><span class="' + picker.options.icons.time + '"></span></a></li>' + 1011 '<li' + (picker.options.collapse ? ' class="collapse"' : '') + '>' + 1012'<div class="timepicker">' + tpGlobal.getTemplate() + '</div>' + 1013'</li>' + 1014'</ul>'; 1015 } 1016ret += '</div>'; 1017 return ret; 1018 } 1019 if (picker.options.pickTime) { 1020 return ( 1021 '<div role="dialog" aria-label="' + g_choose_date_msg + '" class="bootstrap-datetimepicker-widget dropdown-menu">' + 1022'<div class="timepicker">' + tpGlobal.getTemplate() + '</div>' + 1023'</div>' 1024 ); 1025 } 1026 return ( 1027 '<div role="dialog" aria-label="' + g_choose_date_msg + '" class="bootstrap-datetimepicker-widget dropdown-menu">' + 1028'<div class="datepicker">' + template + '</div>' + 1029'</div>' 1030 ); 1031 }, 1032 dpGlobal = { 1033 modes: [ 1034 { 1035 clsName: 'days', 1036 navFnc: 'month', 1037 navStep: 1 1038 }, 1039 { 1040 clsName: 'months', 1041 navFnc: 'year', 1042 navStep: 1 1043 }, 1044 { 1045 clsName: 'years', 1046 navFnc: 'year', 1047 navStep: 10 1048 } 1049 ] 1050 }, 1051 tpGlobal = { 1052hourTemplate: '<span data-action="showHours" data-time-component="hours" class="timepicker-hour"></span>', 1053minuteTemplate: '<span data-action="showMinutes" data-time-component="minutes" class="timepicker-minute"></span>', 1054secondTemplate: '<span data-action="showSeconds" data-time-component="seconds" class="timepicker-second"></span>' 1055 }; 1056 tpGlobal.getTemplate = function () { 1057 return ( 1058 '<div class="timepicker-picker">' + 1059 '<table class="table-condensed">' + 1060 '<tr>' + 1061'<td><a href="#" class="btn" data-action="incrementHours"><span class="' + picker.options.icons.up + '"></span></a></td>' + 1062'<td class="separator"></td>' + 1063'<td>' + (picker.options.useMinutes ? '<a href="#" class="btn" data-action="incrementMinutes"><span class="' + picker.options.icons.up + '"></span></a>' : '') + '</td>' + 1064 (picker.options.useSeconds ? 1065'<td class="separator"></td><td><a href="#" class="btn" data-action="incrementSeconds"><span class="' + picker.options.icons.up + '"></span></a></td>' : '') + 1066(picker.use24hours ? '' : '<td class="separator"></td>') + 1067'</tr>' + 1068 '<tr>' + 1069'<td>' + tpGlobal.hourTemplate + '</td> ' + 1070'<td class="separator">:</td>' + 1071'<td>' + (picker.options.useMinutes ? tpGlobal.minuteTemplate : '<span class="timepicker-minute">00</span>') + '</td> ' + 1072 (picker.options.useSeconds ? 1073'<td class="separator">:</td><td>' + tpGlobal.secondTemplate + '</td>' : '') + 1074(picker.use24hours ? '' : '<td class="separator"></td>' + 1075'<td><button type="button" class="btn btn-primary" data-action="togglePeriod"></button></td>') + 1076'</tr>' + 1077 '<tr>' + 1078'<td><a href="#" class="btn" data-action="decrementHours"><span class="' + picker.options.icons.down + '"></span></a></td>' + 1079'<td class="separator"></td>' + 1080'<td>' + (picker.options.useMinutes ? '<a href="#" class="btn" data-action="decrementMinutes"><span class="' + picker.options.icons.down + '"></span></a>' : '') + '</td>' + 1081 (picker.options.useSeconds ? 1082'<td class="separator"></td><td><a href="#" class="btn" data-action="decrementSeconds"><span class="' + picker.options.icons.down + '"></span></a></td>' : '') + 1083(picker.use24hours ? '' : '<td class="separator"></td>') + 1084'</tr>' + 1085'</table>' + 1086'</div>' + 1087 '<div class="timepicker-hours" data-action="selectHour">' + 1088'<table class="table-condensed"></table>' + 1089'</div>' + 1090 '<div class="timepicker-minutes" data-action="selectMinute">' + 1091'<table class="table-condensed"></table>' + 1092'</div>' + 1093 (picker.options.useSeconds ? 1094'<div class="timepicker-seconds" data-action="selectSecond"><table class="table-condensed"></table></div>' : '') 1095 ); 1096 }; 1097 picker.destroy = function () { 1098 detachDatePickerEvents(); 1099 detachDatePickerGlobalEvents(); 1100 picker.widget.remove(); 1101 picker.element.removeData('DateTimePicker'); 1102 if (picker.component) { 1103 picker.component.removeData('DateTimePicker'); 1104 } 1105 }; 1106 picker.place = function() { 1107 place(); 1108 }; 1109 picker.show = function (e) { 1110 if (getPickerInput().prop('disabled')) { 1111 return; 1112 } 1113 if (picker.options.useCurrent) { 1114 if (getPickerInput().val() === '') { 1115 if (picker.options.minuteStepping !== 1) { 1116 var mDate = moment(), 1117 rInterval = picker.options.minuteStepping; 1118mDate.minutes((Math.round(mDate.minutes() / rInterval) * rInterval) % 60).seconds(0); 1119 picker.setValue(mDate.format(picker.format)); 1120 } else { 1121 picker.setValue(moment().format(picker.format)); 1122 } 1123 notifyChange('', e.type); 1124 } 1125 } 1126 if (e && e.type === 'click' && picker.isInput && picker.widget.hasClass('picker-open')) { 1127 return; 1128 } 1129 if (picker.widget.hasClass('picker-open')) { 1130 picker.widget.hide(); 1131 picker.widget.removeClass('picker-open'); 1132 } 1133 else { 1134 picker.widget.show(); 1135 picker.widget.addClass('picker-open'); 1136 } 1137 picker.height = picker.component ? picker.component.outerHeight() : picker.element.outerHeight(); 1138 place(); 1139 picker.element.trigger({ 1140 type: 'dp.show', 1141 date: moment(picker.date) 1142 }); 1143 attachDatePickerGlobalEvents(); 1144 if (e) { 1145 stopEvent(e); 1146 } 1147 }; 1148 picker.disable = function () { 1149 var input = getPickerInput(); 1150 if (input.prop('disabled')) { 1151 return; 1152 } 1153 input.prop('disabled', true); 1154 detachDatePickerEvents(); 1155 }; 1156 picker.enable = function () { 1157 var input = getPickerInput(); 1158 if (!input.prop('disabled')) { 1159 return; 1160 } 1161 input.prop('disabled', false); 1162 attachDatePickerEvents(); 1163 }; 1164 picker.hide = function () { 1165 var collapse = picker.widget.find('.collapse'), i, collapseData; 1166 for (i = 0; i < collapse.length; i++) { 1167 collapseData = collapse.eq(i).data('collapse'); 1168 if (collapseData && collapseData.transitioning) { 1169 return; 1170 } 1171 } 1172 picker.widget.hide(); 1173 picker.widget.removeClass('picker-open'); 1174 picker.viewMode = picker.startViewMode; 1175 showMode(); 1176 picker.element.trigger({ 1177 type: 'dp.hide', 1178 date: moment(picker.date) 1179 }); 1180 detachDatePickerGlobalEvents(); 1181 }; 1182 picker.setValue = function (newDate) { 1183 moment.locale(picker.options.language); 1184 if (!newDate) { 1185 picker.unset = true; 1186 set(); 1187 } else { 1188 picker.unset = false;
1189 } 1190 if (!moment.isMoment(newDate)) { 1191 newDate = (newDate instanceof Date) ? moment(newDate) : moment(newDate, picker.format, picker.options.useStrict); 1192 } else { 1193 newDate = newDate.locale(picker.options.language); 1194 } 1195 if (newDate.isValid()) { 1196 picker.date = newDate; 1197 set(); 1198 picker.viewDate = moment({y: picker.date.year(), M: picker.date.month()}); 1199 fillDate(); 1200 fillTime(); 1201 } 1202 else { 1203 notifyError(newDate); 1204 } 1205 }; 1206 picker.getDate = function () { 1207 if (picker.unset) { 1208 return null; 1209 } 1210 return moment(picker.date); 1211 }; 1212 picker.setDate = function (date) { 1213 var oldDate = moment(picker.date); 1214 if (!date) { 1215 picker.setValue(null); 1216 } else { 1217 picker.setValue(date); 1218 } 1219 notifyChange(oldDate, 'function'); 1220 }; 1221 picker.setDisabledDates = function (dates) { 1222 picker.options.disabledDates = indexGivenDates(dates); 1223 if (picker.viewDate) { 1224 update(); 1225 } 1226 }; 1227 picker.setEnabledDates = function (dates) { 1228 picker.options.enabledDates = indexGivenDates(dates); 1229 if (picker.viewDate) { 1230 update(); 1231 } 1232 }; 1233 picker.setMaxDate = function (date) { 1234 if (date === undefined) { 1235 return; 1236 } 1237 if (moment.isMoment(date) || date instanceof Date) { 1238 picker.options.maxDate = moment(date); 1239 } else { 1240 picker.options.maxDate = moment(date, picker.format, picker.options.useStrict); 1241 } 1242 if (picker.viewDate) { 1243 update(); 1244 } 1245 }; 1246 picker.setMinDate = function (date) { 1247 if (date === undefined) { 1248 return; 1249 } 1250 if (moment.isMoment(date) || date instanceof Date) { 1251 picker.options.minDate = moment(date); 1252 } else { 1253 picker.options.minDate = moment(date, picker.format, picker.options.useStrict); 1254 } 1255 if (picker.viewDate) { 1256 update(); 1257 } 1258 }; 1259 init(); 1260 }; 1261 $.fn.datetimepicker = function (options) { 1262 return this.each(function () { 1263 var $this = $(this), 1264 data = $this.data('DateTimePicker'); 1265 if (!data) { 1266 $this.data('DateTimePicker', new DateTimePicker(this, options)); 1267 } 1268 }); 1269 }; 1270 $.fn.datetimepicker.defaults = { 1271 format: false, 1272 pickDate: true, 1273 pickTime: true, 1274 useMinutes: true, 1275 useSeconds: false, 1276 useCurrent: true, 1277 calendarWeeks: false, 1278 minuteStepping: 1, 1279 minDate: moment({y: 1900}), 1280 maxDate: moment().add(100, 'y'), 1281 showToday: true, 1282 collapse: true, 1283 language: moment.locale(), 1284 defaultDate: '', 1285 disabledDates: false, 1286 enabledDates: false, 1287 icons: {}, 1288 useStrict: false, 1289 direction: 'auto', 1290 sideBySide: false, 1291 daysOfWeekDisabled: [], 1292 widgetParent: false 1293 }; 1294})); 1295;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.