UNPKG

gumga-date-ng

Version:

Gumga Date

1,114 lines (949 loc) 67.6 kB
/******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // identity function for calling harmony imports with the correct context /******/ __webpack_require__.i = function(value) { return value; }; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { /******/ configurable: false, /******/ enumerable: true, /******/ get: getter /******/ }); /******/ } /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "/dist/"; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 4); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var DateHoliday = exports.DateHoliday = function () { function DateHoliday(_date, _holidays) { _classCallCheck(this, DateHoliday); this.date = moment(_date, "YYYY-MM-DD"); this._holidays = _holidays; } _createClass(DateHoliday, [{ key: "isHoliday", value: function isHoliday() { return this.date.holiday(this._holidays) != undefined; } }, { key: "getNameHoliday", value: function getNameHoliday() { return this.date.holiday(this._holidays); } }]); return DateHoliday; }(); /***/ }), /* 1 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; (function () { 'use strict'; Mask.$inject = ['$parse']; function Mask($parse) { function isFocused(elem) { return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex); } return { priority: 100, require: 'ngModel', restrict: 'A', scope: false, compile: function gumgaDateMaskCompilingFunction() { var options = { maskDefinitions: { // Numéricos '9': /\d/, // Alfa 'A': /[a-zA-Z]/, // Alfanuméricos '*': /[a-zA-Z0-9]/ }, // Se true, limpa o campo caso inválido no evento onBlur clearOnBlur: true, // Eventos para processamento eventsToHandle: ['input', 'keyup', 'click', 'focus'] }; return function gumgaDateMaskLinkingFunction(scope, elm, attrs, ctrl) { var maskProcessed = false, eventsBound = false, maskCaretMap, maskPatterns, maskPlaceholder, maskComponents, minRequiredLength, value, valueMasked, isValid, originalPlaceholder = attrs.placeholder, originalMaxlength = attrs.maxlength, // // Variáveis usadas exclusivamente para eventos oldValue, oldValueUnmasked, oldCaretPosition, oldSelectionLength; function initialize(maskAttr) { if (!angular.isDefined(maskAttr)) { return uninitialize(); } processRawMask(maskAttr); if (!maskProcessed) { return uninitialize(); } initializeElement(); bindEventListeners(); return true; } function initPlaceholder(placeholderAttr) { if (!placeholderAttr) { return; } maskPlaceholder = placeholderAttr; // Atualizamos o valor do input if (maskProcessed) { elm.val(maskValue(unmaskValue(elm.val()))); } } function formatter(fromModelValue) { if (!maskProcessed) { return fromModelValue; } value = unmaskValue(fromModelValue || ''); isValid = validateValue(value); ctrl.$setValidity('mask', isValid); return isValid && value.length ? maskValue(value) : undefined; } function parser(fromViewValue) { if (!maskProcessed) { return fromViewValue; } value = unmaskValue(fromViewValue || ''); isValid = validateValue(value); ctrl.$viewValue = value.length ? maskValue(value) : ''; ctrl.$setValidity('mask', isValid); if (value === '' && attrs.required) { ctrl.$setValidity('required', !ctrl.$error.required); } return isValid ? value : undefined; } var linkOptions = options; if (attrs.gumgaDateMaskOptions) { linkOptions = scope.$eval(attrs.gumgaDateMaskOptions); if (angular.isObject(linkOptions)) { linkOptions = function (original, current) { for (var i in original) { if (Object.prototype.hasOwnProperty.call(original, i)) { if (current[i] === undefined) { current[i] = angular.copy(original[i]); } else { angular.extend(current[i], original[i]); } } } return current; }(options, linkOptions); } } else { linkOptions = options; } attrs.$observe('gumgaDateMask', initialize); if (angular.isDefined(attrs.gumgaDateMaskPlaceholder)) { attrs.$observe('gumgaDateMaskPlaceholder', initPlaceholder); } else { attrs.$observe('placeholder', initPlaceholder); } var modelViewValue = false; attrs.$observe('modelViewValue', function (val) { if (val === 'true') { modelViewValue = true; } }); scope.$watch(attrs.ngModel, function (val) { if (modelViewValue && val) { var model = $parse(attrs.ngModel); model.assign(scope, ctrl.$viewValue); } }); ctrl.$formatters.push(formatter); ctrl.$parsers.push(parser); function uninitialize() { maskProcessed = false; unbindEventListeners(); if (angular.isDefined(originalPlaceholder)) { elm.attr('placeholder', originalPlaceholder); } else { elm.removeAttr('placeholder'); } if (angular.isDefined(originalMaxlength)) { elm.attr('maxlength', originalMaxlength); } else { elm.removeAttr('maxlength'); } elm.val(ctrl.$modelValue); ctrl.$viewValue = ctrl.$modelValue; return false; } function initializeElement() { value = oldValueUnmasked = unmaskValue(ctrl.$modelValue || ''); valueMasked = oldValue = maskValue(value); isValid = validateValue(value); var viewValue = isValid && value.length ? valueMasked : ''; if (attrs.maxlength) { // Double maxlength to allow pasting new val at end of mask elm.attr('maxlength', maskCaretMap[maskCaretMap.length - 1] * 2); } if (!originalPlaceholder) { elm.attr('placeholder', maskPlaceholder); } elm.val(viewValue); ctrl.$viewValue = viewValue; ctrl.$setValidity('mask', isValid); // Não usando $setViewValue, então não sobreescreve // o valor do model sem interação do usuário. } function bindEventListeners() { if (eventsBound) { return; } elm.bind('blur', blurHandler); elm.bind('mousedown mouseup', mouseDownUpHandler); elm.bind(linkOptions.eventsToHandle.join(' '), eventHandler); elm.bind('paste', onPasteHandler); eventsBound = true; } function unbindEventListeners() { if (!eventsBound) { return; } elm.unbind('blur', blurHandler); elm.unbind('mousedown', mouseDownUpHandler); elm.unbind('mouseup', mouseDownUpHandler); elm.unbind('input', eventHandler); elm.unbind('keyup', eventHandler); elm.unbind('click', eventHandler); elm.unbind('focus', eventHandler); elm.unbind('paste', onPasteHandler); eventsBound = false; } function validateValue(value) { // Valida o tamanho mínimo requerido da máscara return value.length ? value.length >= minRequiredLength : true; } // Remove máscara function unmaskValue(value) { var valueUnmasked = '', maskPatternsCopy = maskPatterns.slice(); // Processo para retirar componentes do valor value = value.toString(); angular.forEach(maskComponents, function (component) { value = value.replace(component, ''); }); angular.forEach(value.split(''), function (chr) { if (maskPatternsCopy.length && maskPatternsCopy[0].test(chr)) { valueUnmasked += chr; maskPatternsCopy.shift(); } }); return valueUnmasked; } // Adiciona máscara function maskValue(unmaskedValue) { var valueMasked = '', maskCaretMapCopy = maskCaretMap.slice(); angular.forEach(maskPlaceholder.split(''), function (chr, i) { if (unmaskedValue.length && i === maskCaretMapCopy[0]) { valueMasked += unmaskedValue.charAt(0) || '_'; unmaskedValue = unmaskedValue.substr(1); maskCaretMapCopy.shift(); } else { valueMasked += chr; } }); return valueMasked; } // O atributo padrão placeholder funciona normalmente, // o atributo gumgaDateMaskPlaceholder define a máscara com o placeholder // e deve atender a quantidade de caracteres da máscara. function getPlaceholderChar(i) { var placeholder = angular.isDefined(attrs.gumgaDateMaskPlaceholder) ? attrs.gumgaDateMaskPlaceholder : attrs.placeholder; if (typeof placeholder !== 'undefined' && placeholder[i]) { return placeholder[i]; } else { return '_'; } } function getMaskComponents() { return maskPlaceholder.replace(/[_]+/g, '_').replace(/([^_]+)([a-zA-Z0-9])([^_])/g, '$1$2_$3').split('_'); } function processRawMask(mask) { var characterCount = 0; maskCaretMap = []; maskPatterns = []; maskPlaceholder = ''; if (typeof mask === 'string') { minRequiredLength = 0; var isOptional = false, numberOfOptionalCharacters = 0, splitMask = mask.split(''); angular.forEach(splitMask, function (chr, i) { if (linkOptions.maskDefinitions[chr]) { maskCaretMap.push(characterCount); maskPlaceholder += getPlaceholderChar(i - numberOfOptionalCharacters); maskPatterns.push(linkOptions.maskDefinitions[chr]); characterCount++; if (!isOptional) { minRequiredLength++; } } else if (chr === '?') { isOptional = true; numberOfOptionalCharacters++; } else { maskPlaceholder += chr; characterCount++; } }); } // Posição do cursor imediatamente após última posição válida maskCaretMap.push(maskCaretMap.slice().pop() + 1); maskComponents = getMaskComponents(); maskProcessed = maskCaretMap.length > 1 ? true : false; } function blurHandler() { // Se clearOnBlur for true em options, // limpa o campo caso esteja inválido. if (linkOptions.clearOnBlur) { oldCaretPosition = 0; oldSelectionLength = 0; if (!isValid || value.length === 0) { valueMasked = ''; elm.val(''); scope.$apply(function () { ctrl.$setViewValue(''); }); } } } function mouseDownUpHandler(e) { if (e.type === 'mousedown') { elm.bind('mouseout', mouseoutHandler); } else { elm.unbind('mouseout', mouseoutHandler); } } elm.bind('mousedown mouseup', mouseDownUpHandler); function mouseoutHandler() { /*jshint validthis: true */ oldSelectionLength = getSelectionLength(this); elm.unbind('mouseout', mouseoutHandler); } function onPasteHandler() { /*jshint validthis: true */ setCaretPosition(this, elm.val().length); } function eventHandler(e) { /*jshint validthis: true */ e = e || {}; // Permite uma minificação mais eficiente var eventWhich = e.which, eventType = e.type; if (eventWhich === 16 || eventWhich === 91) { return; } var val = elm.val(), valOld = oldValue, valMasked, valUnmasked = unmaskValue(val), valUnmaskedOld = oldValueUnmasked, caretPos = getCaretPosition(this) || 0, caretPosOld = oldCaretPosition || 0, caretPosDelta = caretPos - caretPosOld, caretPosMin = maskCaretMap[0], caretPosMax = maskCaretMap[valUnmasked.length] || maskCaretMap.slice().shift(), selectionLenOld = oldSelectionLength || 0, isSelected = getSelectionLength(this) > 0, wasSelected = selectionLenOld > 0, // Case: Digitando um caracter para substituir uma seleção isAddition = val.length > valOld.length || selectionLenOld && val.length > valOld.length - selectionLenOld, // Case: Delete e backspace se comportam de forma idêntica em uma seleção isDeletion = val.length < valOld.length || selectionLenOld && val.length === valOld.length - selectionLenOld, isSelection = eventWhich >= 37 && eventWhich <= 40 && e.shiftKey, // Arrow key codes isKeyLeftArrow = eventWhich === 37, // Necessária devido ao evento não fornecer um keycode isKeyBackspace = eventWhich === 8 || eventType !== 'keyup' && isDeletion && caretPosDelta === -1, isKeyDelete = eventWhich === 46 || eventType !== 'keyup' && isDeletion && caretPosDelta === 0 && !wasSelected, // Lida com casos onde acento circunflexo é movido e colocado na frente da posição maskCaretMap inválido. // Logic abaixo assegura que, ao clicar ou posicionamento acento circunflexo para a esquerda, acento // circunflexo é movido para a esquerda até à direita directamente de caráter não-máscara. // Também aplicado para clicar uma vez que os usuários são (discutivelmente) mais propensos a voltar // atrás com um personagem ao clicar dentro de uma entrada cheia. caretBumpBack = (isKeyLeftArrow || isKeyBackspace || eventType === 'click') && caretPos > caretPosMin; oldSelectionLength = getSelectionLength(this); // Eventos que não requerem nenhuma ação if (isSelection || isSelected && (eventType === 'click' || eventType === 'keyup')) { return; } // Controle de valores // ============== // User attempted to delete but raw value was unaffected--correct this grievous offense // O usuário tentou apagar, mas valor bruto não foi afetado - corrigir este grave ofensa if (eventType === 'input' && isDeletion && !wasSelected && valUnmasked === valUnmaskedOld) { while (isKeyBackspace && caretPos > caretPosMin && !isValidCaretPosition(caretPos)) { caretPos--; } while (isKeyDelete && caretPos < caretPosMax && maskCaretMap.indexOf(caretPos) === -1) { caretPos++; } var charIndex = maskCaretMap.indexOf(caretPos); // Strip out non-mask character that user would have deleted if mask hadn't been in the way. valUnmasked = valUnmasked.substring(0, charIndex) + valUnmasked.substring(charIndex + 1); } // Atualiza valor valMasked = maskValue(valUnmasked); oldValue = valMasked; oldValueUnmasked = valUnmasked; elm.val(valMasked); ctrl.$setViewValue(valUnmasked); // Posição do cursor // =================== // Caractere digitado a frente nos casos em que o primeiro caractere de entrada é um char máscara e o cursor // for colocado na posição 0. if (isAddition && caretPos <= caretPosMin) { caretPos = caretPosMin + 1; } if (caretBumpBack) { caretPos--; } caretPos = caretPos > caretPosMax ? caretPosMax : caretPos < caretPosMin ? caretPosMin : caretPos; while (!isValidCaretPosition(caretPos) && caretPos > caretPosMin && caretPos < caretPosMax) { caretPos += caretBumpBack ? -1 : 1; } if (caretBumpBack && caretPos < caretPosMax || isAddition && !isValidCaretPosition(caretPosOld)) { caretPos++; } oldCaretPosition = caretPos; setCaretPosition(this, caretPos); } function isValidCaretPosition(pos) { return maskCaretMap.indexOf(pos) > -1; } function getCaretPosition(input) { if (!input) return 0; if (input.selectionStart !== undefined) { return input.selectionStart; } else if (document.selection) { if (isFocused(elm[0])) { // Maldito seja o IE input.focus(); var selection = document.selection.createRange(); selection.moveStart('character', input.value ? -input.value.length : 0); return selection.text.length; } } return 0; } function setCaretPosition(input, pos) { if (!input) return 0; if (input.offsetWidth === 0 || input.offsetHeight === 0) { return; // Inputs escondidos } if (input.setSelectionRange) { if (isFocused(elm[0])) { input.focus(); input.setSelectionRange(pos, pos); } } else if (input.createTextRange) { // Maldito seja o IE var range = input.createTextRange(); range.collapse(true); range.moveEnd('character', pos); range.moveStart('character', pos); range.select(); } } function getSelectionLength(input) { if (!input) return 0; if (input.selectionStart !== undefined) { return input.selectionEnd - input.selectionStart; } if (document.selection) { return document.selection.createRange().text.length; } return 0; } }; } }; } angular.module('gumga.date.mask', []).directive('gumgaDateMask', Mask); })(); /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; (function () { 'use strict'; var GumgaService = function GumgaService() { var configuration = { activeMobileMode: false, background: '#1abc9c', primaryColor: '#1abc9c', fontColor: '#fff', format: 'dd/MM/yyyy', minYear: 1700, timeZone: "America/Sao_Paulo", maxYear: 2050, position: 'BOTTOM_LEFT', changeDateOnTab: false, showCalendar: true, closeOnChange: false, inputProperties: { class: 'form-control gmd' } }; var _holidays = { 'M': { //Month, Day '01/01': "Confraternização Universal", '04/14': "Paixão de Cristo", '04/21': "Tiradentes", '05/01': "Dia do Trabalho", '09/05': "Independência do Brasil", '10/12': "Nossa Senhora Aparecida", '11/02': "Finados", '11/15': "Proclamação da República", '12/25': "Natal" }, 'W': {//Month, Week of Month, Day of Week // '1/3/1': "Martin Luther King Jr. Day", // '2/3/1': "Washington's Birthday", // '5/5/1': "Memorial Day", // '9/1/1': "Labor Day", // '10/2/1': "Columbus Day", // '11/4/4': "Thanksgiving Day" } }; var getDefaultConfiguration = function getDefaultConfiguration() { return configuration; }; var setDefaultConfiguration = function setDefaultConfiguration(config) { Object.keys(config).forEach(function (key) { return configuration[key] = config[key]; }); }; var getHolidays = function getHolidays() { return _holidays; }; var addHoliday = function addHoliday(date, description) { var month = moment(date).month() + 1; var day = moment(date).date(); if (day < 10) day = '0' + day; if (month < 10) month = '0' + month; _holidays['M'][month + '/' + day] = description; }; return { getDefaultConfiguration: getDefaultConfiguration, setDefaultConfiguration: setDefaultConfiguration, getHolidays: getHolidays, addHoliday: addHoliday, $get: function $get() { return { getDefaultConfiguration: getDefaultConfiguration, setDefaultConfiguration: setDefaultConfiguration, getHolidays: getHolidays, addHoliday: addHoliday }; } }; }; angular.module('gumga.date.service', []).provider('GumgaDateService', GumgaService); })(); /***/ }), /* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _dateStyle = __webpack_require__(5); var _dateStyle2 = _interopRequireDefault(_dateStyle); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function useGumgaLayout() { try { return !!angular.module('gumga.layout'); } catch (error) { return false; } } var input = useGumgaLayout() ? '\n <div style="{{label ? \'height: 34px;\' : \'\'}}">\n <input ng-focus="config.open();inputFocused = true;"\n ng-blur="inputFocused = false;dateBlur($event);"\n ng-model="value"\n gumga-date-mask="{{mask}}"\n ng-disabled="ngDisabled"\n ng-keydown="keyPressInput($event)"\n class="gumga-date-input {{inputProperties.class}}"\n placeholder="{{inputProperties.placeholder}} "/>\n <span class="bar"></span>\n <label for="email" class="control-label" ng-if="label">{{label}}</label>\n <i class="material-icons" ng-show="icon" ng-click="iconClick($event);">{{icon}}</i>\n </div>\n ' : '\n <div>\n <input ng-focus="config.open();inputFocused = true;"\n ng-blur="inputFocused = false;dateBlur($event);"\n ng-model="value"\n ng-keydown="keyPressInput($event)"\n gumga-date-mask="{{mask}}"\n ng-disabled="ngDisabled"\n class="gumga-date-input {{inputProperties.class}}"\n placeholder="{{inputProperties.placeholder}} "/>\n </div>\n '; exports.default = '\n <div class="date-backdrop" ng-click="config.close()" ng-show="opened && isMobile"></div>\n <style>' + _dateStyle2.default + '</style>\n\n ' + input + '\n\n <div class="gumga-date" ng-class="{\'mobile-mode\' : isMobile}" ng-show="opened" id="gumga-date-{{uid}}" style="{{getPosition()}}">\n <div class="month" style="background:{{config.background ? config.background : getDefaultConfiguration().background}}">\n <ul>\n <span data-ng-click="alterView(\'hours\')"\n ng-hide="type == \'DATE\'" ng-show="view != \'hours\' || type == \'HOUR\'"\n class="hours">\n {{gumgaDateValue.getHours() < 10 ? "0"+gumgaDateValue.getHours() : gumgaDateValue.getHours()}}\n :\n {{gumgaDateValue.getMinutes() < 10 ? "0"+gumgaDateValue.getMinutes() : gumgaDateValue.getMinutes()}}\n </span><br>\n\n <span data-ng-click="alterView(\'days\')"\n ng-show="view == \'hours\' && (type == \'DATE\' || type == \'DATE_HOUR\') || type == \'DATE\'"\n class="hours">{{value}}</span>\n\n <br>\n <li ng-show="view != \'hours\' && (type == \'DATE\' || type == \'DATE_HOUR\')" class="prev" ng-click="handlingMonths(gumgaDateValue, -1)">&#10094;</li>\n <li ng-show="view != \'hours\' && (type == \'DATE\' || type == \'DATE_HOUR\')" class="next" ng-click="handlingMonths(gumgaDateValue, +1)">&#10095;</li>\n <li ng-show="view != \'hours\' && (type == \'DATE\' || type == \'DATE_HOUR\')" style="text-align:center">\n <span style="padding: 10px;" data-ng-click="alterView(\'months\')">{{getMonth()}}</span><br>\n <span data-ng-click="alterView(\'months\')" style="font-size:18px">{{getYear()}}</span>\n </li>\n\n <div class="gumga-date-hour" ng-show="view == \'hours\'">\n <span class="glyphicon glyphicon-chevron-up" ng-click="handlingHours(1)"></span>\n <li>{{gumgaDateValue.getHours() < 10 ? "0"+gumgaDateValue.getHours() : gumgaDateValue.getHours()}}</li>\n <span class="glyphicon glyphicon-chevron-down" ng-click="handlingHours(-1)"></span>\n </div>\n <div ng-show="view == \'hours\'" class="gumga-date-separator">\n <span>:</span>\n </div>\n <div class="gumga-date-minutes" ng-show="view == \'hours\'">\n <span class="glyphicon glyphicon-chevron-up" ng-click="handlingMinutes(1)"></span>\n <li >{{gumgaDateValue.getMinutes() < 10 ? "0"+gumgaDateValue.getMinutes() : gumgaDateValue.getMinutes()}}</li>\n <span class="glyphicon glyphicon-chevron-down" ng-click="handlingMinutes(-1)"></span>\n </div>\n\n </ul>\n </div>\n\n <div class="year-and-month" id="year-and-month-{{uid}}">\n <ul class="change-month" ng-show="view == \'months\'" ng-repeat="year in years">\n <span class="year">{{::year}}</span>\n\n <div style="width: 170px;float: right;">\n <li data-ng-repeat="month in getGumgaMonths(true)" data-ng-click="setYearAndMonth(year, month)">\n <span ng-class="{\'active\' : isThatMonth(year, month)}">{{::month}}</span>\n </li>\n </div>\n\n </ul>\n </div>\n\n <ul class="weekdays" ng-show="view == \'days\'">\n <li ng-repeat="weekday in getWeekDays()">{{weekday}}</li>\n </ul>\n <ul class="days" ng-show="view == \'days\'">\n <li data-ng-click="setDay(row, $event)" data-ng-repeat="row in rows track by $index" class="{{getWeekdayClass(row)}}">\n <span ng-class="{\'active\' : isToday(row), \'holiday\': isHoliday(row)}"\n data-tooltip="{{getNameHoliday(row)}}"\n style="{{row.style}}">\n {{row.value}}\n </span>\n </li>\n </ul>\n </div>\n\n'; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var _date = __webpack_require__(0); (function () { 'use strict'; __webpack_require__(2); __webpack_require__(1); var TEMPLATE = __webpack_require__(3).default; var GumgaDate = function GumgaDate($timeout, $filter, $locale, GumgaDateService) { return { restrict: 'E', template: TEMPLATE, scope: { config: '=?configuration', ngModel: '=', ngDisabled: '=?', ngBlur: '&?' }, require: '^ngModel', link: function link(scope, elm, attrs) { moment.fn.holiday = function (_holidays) { var diff = 1 + (0 | (this._d.getDate() - 1) / 7), memorial = this._d.getDay() === 1 && this._d.getDate() + 7 > 30 ? "5" : null; return _holidays['M'][this.format('MM/DD')] || _holidays['W'][this.format('M/' + (memorial || diff) + '/d')]; }; var self = scope; self.uid = Math.floor(Math.random() * 99999999); self.config = self.config || {}; self.label = attrs.label; self.icon = attrs.icon; self.iconClick = function ($event) { $event.stopPropagation(); var input = elm.find('input'); input.focus(); }; self.isHoliday = function (row) { return new _date.DateHoliday(row.year + '-' + (row.mouth + 1) + '-' + row.value, GumgaDateService.getHolidays()).isHoliday(); }; self.getNameHoliday = function (row) { return new _date.DateHoliday(row.year + '-' + (row.mouth + 1) + '-' + row.value, GumgaDateService.getHolidays()).getNameHoliday(); }; self.getWeekdayClass = function (row) { return moment(row.year + '-' + (row.mouth + 1) + '-' + row.value, 'YYYY-MM-DD').format('dddd').toLowerCase(); }; self.getDefaultConfiguration = function () { return GumgaDateService.getDefaultConfiguration(); }; self.dateBlur = function (evt) { if (self.ngBlur) { self.ngBlur({ $event: evt }); } }; self.keyPressInput = function (evt) { if (evt.keyCode == 9 && self.opened) { self.config.close(); } }; self.range = function (min, max, step) { if (!self.opened) return []; step = step || 1; var input = []; for (var i = min; i <= max; i += step) { input.push(i); } return input; }; self.getScrollSize = function () { if (!self.gumgaDateValue) return; var index = self.gumgaDateValue.getFullYear() - self.getMinYear(); return index * 92 - 50; }; self.getWeekDays = function () { var dateformats = $locale.DATETIME_FORMATS; return dateformats.SHORTDAY.map(function (day) { return day.substring(0, 3); }); }; self.getGumgaMonths = function (cut) { var dateformats = $locale.DATETIME_FORMATS; return dateformats.STANDALONEMONTH.map(function (day) { return cut ? day.substring(0, 3) : day; }); }; var formatDate = function formatDate(date, format) { return $filter('date')(date, format); }; var setType = function setType() { self.type = self.inputFormat.toLowerCase().indexOf('hh:mm') != -1 && self.inputFormat.toLowerCase().indexOf('dd') == -1 ? 'HOUR' : self.type; self.type = self.inputFormat.toLowerCase().indexOf('hh:mm') != -1 && self.inputFormat.toLowerCase().indexOf('dd') != -1 ? 'DATE_HOUR' : self.type; self.type = self.inputFormat.toLowerCase().indexOf('hh:mm') == -1 && self.inputFormat.toLowerCase().indexOf('dd') != -1 ? 'DATE' : self.type; if (self.type == 'HOUR') { self.alterView('hours'); } else { self.alterView('days'); } }; var init = function init() { self.inputFormat = self.config.format ? self.config.format : self.getDefaultConfiguration().format; setType(); self.mask = self.inputFormat.replace(/[a-zA-Z\d]/g, '9'); self.inputProperties = { class: self.config.inputProperties && self.config.inputProperties.class ? self.config.inputProperties.class : self.getDefaultConfiguration().inputProperties.class, placeholder: self.config.inputProperties && self.config.inputProperties.placeholder ? self.config.inputProperties.placeholder : angular.noop() }; self.style = { fontColor: self.config.fontColor || self.getDefaultConfiguration().fontColor, background: self.config.background || self.getDefaultConfiguration().background }; if (self.ngModel && self.ngModel instanceof Date) { self.gumgaDateValue = self.ngModel; self.setNgModel(self.gumgaDateValue); } else if (self.ngModel && typeof self.ngModel == "string") { var date = moment(self.ngModel).toDate(); self.gumgaDateValue = date; self.setNgModel(self.gumgaDateValue); } else { self.gumgaDateValue = new Date(); } }; var isDate = function isDate(s) { var separators = ['\\.', '\\-', '\\/']; var bits = s.split(new RegExp(separators.join('|'), 'g')); var d = new Date(bits[2], bits[1] - 1, bits[0]); return d.getFullYear() == bits[2] && d.getMonth() + 1 == bits[1]; }; self.alterView = function (view) { $timeout(function () { self.view = view; if (view == 'months') { if (!self.years) self.years = self.range(self.getMinYear(), self.getMaxYear()); handlingScroll(); } }); }; var calendar = undefined; var animateScroll = function animateScroll(size, scrollTop) { angular.element(calendar).animate({ scrollTop: size }, 400); }; $timeout(function () { calendar = document.getElementById('year-and-month-' + self.uid); }, 1000); var handlingScroll = function handlingScroll() { $timeout(function () { var size = self.getScrollSize(); animateScroll(size, calendar.scrollTop); }); }; self.handlingHours = function (num) { self.gumgaDateValue.setHours(self.gumgaDateValue.getHours() + num); self.setNgModel(self.gumgaDateValue); }; self.handlingMinutes = function (num) { self.gumgaDateValue.setMinutes(self.gumgaDateValue.getMinutes() + num); self.setNgModel(self.gumgaDateValue); }; function checkIsMobile() { var check = false; (function (a) { if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4))) check = true; })(navigator.userAgent || navigator.vendor || window.opera); return check && self.config.activeMobileMode; } self.isMobile = checkIsMobile(); self.getFormatLength = function () { return self.inputFormat ? self.inputFormat.replace(/[^a-zA-Z0-9]/g, '').length : 0; }; self.setGumgaDateValue = function (value, event) { if (!value) return; checkDateIsValid(value); }; function checkDateIsValid(value, ignoreModel) { self.inputFormat = self.config.format ? self.config.format : self.getDefaultConfiguration().format; var minYear = self.getMinYear(); var maxYear = self.getMaxYear(); var timeZone = self.config.timeZone ? self.config.timeZone : self.getDefaultConfiguration().timeZone; var date = moment(value, self.inputFormat.toUpperCase().replace('HH:MM', 'hh:mm')).tz(timeZone).toDate(); if (value && date != 'Invalid Date' && date.getFullYear() >= minYear && date.getFullYear() <= maxYear) { self.gumgaDateValue = date; if (!ignoreModel) { self.setNgModel(self.gumgaDateValue); } if (self.config.change) self.config.change(self.ngModel); } else { self.value = null; } } self.getMinYear = function () { return self.config.minYear ? self.config.minYear : self.getDefaultConfiguration().minYear; }; self.getMaxYear = function () { return self.config.maxYear ? self.config.maxYear : self.getDefaultConfiguration().maxYear; }; self.getMonth = function () { if (!self.gumgaDateValue || !(self.gumgaDateValue instanceof Date)) return; return self.getGumgaMonths()[self.gumgaDateValue.getMonth()]; }; self.setDay = function (day, evt) { if (!self.gumgaDateValue || !(self.gumgaDateValue instanceof Date)) return; var update = new Date(); update.setYear(day.year); update.setMonth(day.mouth); update.setDate(day.value); update.setHours(self.gumgaDateValue.getHours()); update.setMinutes(self.gumgaDateValue.getMinutes()); update.setSeconds(self.gumgaDateValue.getSeconds()); self.gumgaDateValue = update; self.setNgModel(self.gumgaDateValue); if (self.config.change) self.config.change(self.ngModel); if (self.config.hasOwnProperty('closeOnChange') ? self.config.closeOnChange : self.getDefaultConfiguration().closeOnChange) { self.config.close(); } }; self.setYearAndMonth = function (year, month) { if (!self.gumgaDateValue || !(self.gumgaDateValue instanceof Date)) return; self.getGumgaMonths(true).forEach(function (gumgaMonth, index) { if (gumgaMonth == month) { var update = new Date(); update.setYear(year); update.setMonth(index); update.setDate(self.gumgaDateValue.getDate()); update.setHours(self.gumgaDateValue.getHours()); update.setMinutes(self.gumgaDateValue.getMinutes()); update.setSeconds(self.gumgaDateValue.getSeconds()); self.gumgaDateValue = update; self.setNgModel(self.gumgaDateValue); self.alterView('days'); } }); }; self.getYear = function () { if (!self.gumgaDateValue) return; return self.gumgaDateValue.getFullYear(); }; self.isToday = function (day) { return day.value == self.gumgaDateValue.getDate() && day.mouth == self.gumgaDateValue.getMonth(); }; self.isThatMonth = function (year, mouth) { return self.getGumgaMonths(true)[self.gumgaDateValue.getMonth()] == mouth && self.gumgaDateValue.getFullYear() == year; }; self.config.open = function (event) { try { if (event) event.stopPropagation(); if (self.config.hasOwnProperty('showCalendar') ? self.config.showCalendar : self.getDefaultConfiguration().showCalendar) { if (checkIsMobile()) { elm.find('input')[0].blur(); } self.opened = true; setType(); newCalendar(self.gumgaDateValue.getMonth(), self.gumgaDateValue.getFullYear()); $timeout(function () { if (!self.years) self.years = self.range(self.getMinYear(), self.getMaxYear()); }); } } catch (e) {} }; self.config.close = function () { self.opened = false; self.alterView('days'); }; var getDaysInMonth = function getDaysInMonth(date) { return new Date(date.getFullYear(), date.getMonth(), 0).getDate(); }; self.handlingMonths = function (date, num, evt) { self.gumgaDateValue = moment(date).add(num, 'months').toDate(); self.setNgModel(self.gumgaDateValue); if (self.view == 'months') { handlingScroll(); } }; self.$watch('config', function () { init(); }, true); self.$watch('ngModel', function (value) { $timeout(function () { if (self.ngModel && self.ngModel instanceof Date) { self.gumgaDateValue = self.ngModel; newCalendar(value.getMonth(), value.getFullYear()); self.value = formatDate(angular.copy(value), self.inputFormat); } if (self.ngModel && typeof self.ngModel == "string") { var date = moment(self.ngModel).toDate(); self.gumgaDateValue = date; newCalendar(date.getMonth(), date.getFullYear()); var timeZone = self.config.timeZone ? self.config.timeZone : self.getDefaultConfiguration().timeZone; var dateValue = moment(self.value, self.inputFormat.toUpperCase().replace('HH:MM', 'hh:mm')).tz(timeZone).toDate(); if (self.value != formatDate(angular.copy(date), self.inputFormat) && dateValue.getMinutes() != date.getMinutes() + 1) { checkDateIsValid(formatDate(angular.copy(date), self.inputFormat), true); } } if (!value && !self.inputFocused) { self.gumgaDateValue = new Date(); newCalendar(self.gumgaDateValue.getMonth(), self.gumgaDateValue.getFullYear()); self.value = null; } }); }, true); self.$watch('value', function (value) { return value ? self.setGumgaDateValue(value) : self.ngModel = null; }); self.setNgModel = function (value) { var timeZone = self.config.timeZone ? self.config.timeZone : self.getDefaultConfiguration().timeZone; self.ngModel = moment.tz(value, timeZone).format(); newCalendar(value.getMonth(), value.getFullYear()); self.value = formatDate(angular.copy(value), self.inputFormat); }; elm.bind('click', function (event) { event.stopPropagation(); });