{I" class:ETI"ProcessedAsset; FI"logical_path; TI"#angular-strap/angular-strap.js; FI" pathname; TI"{/home/josh/.rvm/gems/ruby-2.1.5/gems/rails-assets-angular-strap-2.2.0/app/assets/javascripts/angular-strap/angular-strap.js; FI"content_type; TI"application/javascript; TI" mtime; Tl+Ù‘çTI"length; TiÀ§I"digest; TI"%123c7889b1910d7193381bf0163207c7; FI"source; TI"À§/** * angular-strap * @version v2.1.6 - 2015-01-11 * @link http://mgcrea.github.io/angular-strap * @author Olivier Louvignes (olivier@mg-crea.com) * @license MIT License, http://www.opensource.org/licenses/MIT */ (function(window, document, undefined) { 'use strict'; // Source: module.js angular.module('mgcrea.ngStrap', [ 'mgcrea.ngStrap.modal', 'mgcrea.ngStrap.aside', 'mgcrea.ngStrap.alert', 'mgcrea.ngStrap.button', 'mgcrea.ngStrap.select', 'mgcrea.ngStrap.datepicker', 'mgcrea.ngStrap.timepicker', 'mgcrea.ngStrap.navbar', 'mgcrea.ngStrap.tooltip', 'mgcrea.ngStrap.popover', 'mgcrea.ngStrap.dropdown', 'mgcrea.ngStrap.typeahead', 'mgcrea.ngStrap.scrollspy', 'mgcrea.ngStrap.affix', 'mgcrea.ngStrap.tab', 'mgcrea.ngStrap.collapse' ]); // Source: affix.js angular.module('mgcrea.ngStrap.affix', ['mgcrea.ngStrap.helpers.dimensions', 'mgcrea.ngStrap.helpers.debounce']) .provider('$affix', function() { var defaults = this.defaults = { offsetTop: 'auto' }; this.$get = ["$window", "debounce", "dimensions", function($window, debounce, dimensions) { var bodyEl = angular.element($window.document.body); var windowEl = angular.element($window); function AffixFactory(element, config) { var $affix = {}; // Common vars var options = angular.extend({}, defaults, config); var targetEl = options.target; // Initial private vars var reset = 'affix affix-top affix-bottom', setWidth = false, initialAffixTop = 0, initialOffsetTop = 0, offsetTop = 0, offsetBottom = 0, affixed = null, unpin = null; var parent = element.parent(); // Options: custom parent if (options.offsetParent) { if (options.offsetParent.match(/^\d+$/)) { for (var i = 0; i < (options.offsetParent * 1) - 1; i++) { parent = parent.parent(); } } else { parent = angular.element(options.offsetParent); } } $affix.init = function() { this.$parseOffsets(); initialOffsetTop = dimensions.offset(element[0]).top + initialAffixTop; setWidth = !element[0].style.width; // Bind events targetEl.on('scroll', this.checkPosition); targetEl.on('click', this.checkPositionWithEventLoop); windowEl.on('resize', this.$debouncedOnResize); // Both of these checkPosition() calls are necessary for the case where // the user hits refresh after scrolling to the bottom of the page. this.checkPosition(); this.checkPositionWithEventLoop(); }; $affix.destroy = function() { // Unbind events targetEl.off('scroll', this.checkPosition); targetEl.off('click', this.checkPositionWithEventLoop); windowEl.off('resize', this.$debouncedOnResize); }; $affix.checkPositionWithEventLoop = function() { // IE 9 throws an error if we use 'this' instead of '$affix' // in this setTimeout call setTimeout($affix.checkPosition, 1); }; $affix.checkPosition = function() { // if (!this.$element.is(':visible')) return var scrollTop = getScrollTop(); var position = dimensions.offset(element[0]); var elementHeight = dimensions.height(element[0]); // Get required affix class according to position var affix = getRequiredAffixClass(unpin, position, elementHeight); // Did affix status changed this last check? if(affixed === affix) return; affixed = affix; // Add proper affix class element.removeClass(reset).addClass('affix' + ((affix !== 'middle') ? '-' + affix : '')); if(affix === 'top') { unpin = null; element.css('position', (options.offsetParent) ? '' : 'relative'); if(setWidth) { element.css('width', ''); } element.css('top', ''); } else if(affix === 'bottom') { if (options.offsetUnpin) { unpin = -(options.offsetUnpin * 1); } else { // Calculate unpin threshold when affixed to bottom. // Hopefully the browser scrolls pixel by pixel. unpin = position.top - scrollTop; } if(setWidth) { element.css('width', ''); } element.css('position', (options.offsetParent) ? '' : 'relative'); element.css('top', (options.offsetParent) ? '' : ((bodyEl[0].offsetHeight - offsetBottom - elementHeight - initialOffsetTop) + 'px')); } else { // affix === 'middle' unpin = null; if(setWidth) { element.css('width', element[0].offsetWidth + 'px'); } element.css('position', 'fixed'); element.css('top', initialAffixTop + 'px'); } }; $affix.$onResize = function() { $affix.$parseOffsets(); $affix.checkPosition(); }; $affix.$debouncedOnResize = debounce($affix.$onResize, 50); $affix.$parseOffsets = function() { var initialPosition = element.css('position'); // Reset position to calculate correct offsetTop element.css('position', (options.offsetParent) ? '' : 'relative'); if(options.offsetTop) { if(options.offsetTop === 'auto') { options.offsetTop = '+0'; } if(options.offsetTop.match(/^[-+]\d+$/)) { initialAffixTop = - options.offsetTop * 1; if(options.offsetParent) { offsetTop = dimensions.offset(parent[0]).top + (options.offsetTop * 1); } else { offsetTop = dimensions.offset(element[0]).top - dimensions.css(element[0], 'marginTop', true) + (options.offsetTop * 1); } } else { offsetTop = options.offsetTop * 1; } } if(options.offsetBottom) { if(options.offsetParent && options.offsetBottom.match(/^[-+]\d+$/)) { // add 1 pixel due to rounding problems... offsetBottom = getScrollHeight() - (dimensions.offset(parent[0]).top + dimensions.height(parent[0])) + (options.offsetBottom * 1) + 1; } else { offsetBottom = options.offsetBottom * 1; } } // Bring back the element's position after calculations element.css('position', initialPosition); }; // Private methods function getRequiredAffixClass(unpin, position, elementHeight) { var scrollTop = getScrollTop(); var scrollHeight = getScrollHeight(); if(scrollTop <= offsetTop) { return 'top'; } else if(unpin !== null && (scrollTop + unpin <= position.top)) { return 'middle'; } else if(offsetBottom !== null && (position.top + elementHeight + initialAffixTop >= scrollHeight - offsetBottom)) { return 'bottom'; } else { return 'middle'; } } function getScrollTop() { return targetEl[0] === $window ? $window.pageYOffset : targetEl[0].scrollTop; } function getScrollHeight() { return targetEl[0] === $window ? $window.document.body.scrollHeight : targetEl[0].scrollHeight; } $affix.init(); return $affix; } return AffixFactory; }]; }) .directive('bsAffix', ["$affix", "$window", function($affix, $window) { return { restrict: 'EAC', require: '^?bsAffixTarget', link: function postLink(scope, element, attr, affixTarget) { var options = {scope: scope, offsetTop: 'auto', target: affixTarget ? affixTarget.$element : angular.element($window)}; angular.forEach(['offsetTop', 'offsetBottom', 'offsetParent', 'offsetUnpin'], function(key) { if(angular.isDefined(attr[key])) options[key] = attr[key]; }); var affix = $affix(element, options); scope.$on('$destroy', function() { affix && affix.destroy(); options = null; affix = null; }); } }; }]) .directive('bsAffixTarget', function() { return { controller: ["$element", function($element) { this.$element = $element; }] }; }); // Source: alert.js // @BUG: following snippet won't compile correctly // @TODO: submit issue to core // ' ' + angular.module('mgcrea.ngStrap.alert', ['mgcrea.ngStrap.modal']) .provider('$alert', function() { var defaults = this.defaults = { animation: 'am-fade', prefixClass: 'alert', prefixEvent: 'alert', placement: null, template: 'alert/alert.tpl.html', container: false, element: null, backdrop: false, keyboard: true, show: true, // Specific options duration: false, type: false, dismissable: true }; this.$get = ["$modal", "$timeout", function($modal, $timeout) { function AlertFactory(config) { var $alert = {}; // Common vars var options = angular.extend({}, defaults, config); $alert = $modal(options); // Support scope as string options [/*title, content, */ type, dismissable] $alert.$scope.dismissable = !!options.dismissable; if(options.type) { $alert.$scope.type = options.type; } // Support auto-close duration var show = $alert.show; if(options.duration) { $alert.show = function() { show(); $timeout(function() { $alert.hide(); }, options.duration * 1000); }; } return $alert; } return AlertFactory; }]; }) .directive('bsAlert', ["$window", "$sce", "$alert", function($window, $sce, $alert) { var requestAnimationFrame = $window.requestAnimationFrame || $window.setTimeout; return { restrict: 'EAC', scope: true, link: function postLink(scope, element, attr, transclusion) { // Directive options var options = {scope: scope, element: element, show: false}; angular.forEach(['template', 'placement', 'keyboard', 'html', 'container', 'animation', 'duration', 'dismissable'], function(key) { if(angular.isDefined(attr[key])) options[key] = attr[key]; }); // Support scope as data-attrs angular.forEach(['title', 'content', 'type'], function(key) { attr[key] && attr.$observe(key, function(newValue, oldValue) { scope[key] = $sce.trustAsHtml(newValue); }); }); // Support scope as an object attr.bsAlert && scope.$watch(attr.bsAlert, function(newValue, oldValue) { if(angular.isObject(newValue)) { angular.extend(scope, newValue); } else { scope.content = newValue; } }, true); // Initialize alert var alert = $alert(options); // Trigger element.on(attr.trigger || 'click', alert.toggle); // Garbage collection scope.$on('$destroy', function() { if (alert) alert.destroy(); options = null; alert = null; }); } }; }]); // Source: aside.js angular.module('mgcrea.ngStrap.aside', ['mgcrea.ngStrap.modal']) .provider('$aside', function() { var defaults = this.defaults = { animation: 'am-fade-and-slide-right', prefixClass: 'aside', prefixEvent: 'aside', placement: 'right', template: 'aside/aside.tpl.html', contentTemplate: false, container: false, element: null, backdrop: true, keyboard: true, html: false, show: true }; this.$get = ["$modal", function($modal) { function AsideFactory(config) { var $aside = {}; // Common vars var options = angular.extend({}, defaults, config); $aside = $modal(options); return $aside; } return AsideFactory; }]; }) .directive('bsAside', ["$window", "$sce", "$aside", function($window, $sce, $aside) { var requestAnimationFrame = $window.requestAnimationFrame || $window.setTimeout; return { restrict: 'EAC', scope: true, link: function postLink(scope, element, attr, transclusion) { // Directive options var options = {scope: scope, element: element, show: false}; angular.forEach(['template', 'contentTemplate', 'placement', 'backdrop', 'keyboard', 'html', 'container', 'animation'], function(key) { if(angular.isDefined(attr[key])) options[key] = attr[key]; }); // Support scope as data-attrs angular.forEach(['title', 'content'], function(key) { attr[key] && attr.$observe(key, function(newValue, oldValue) { scope[key] = $sce.trustAsHtml(newValue); }); }); // Support scope as an object attr.bsAside && scope.$watch(attr.bsAside, function(newValue, oldValue) { if(angular.isObject(newValue)) { angular.extend(scope, newValue); } else { scope.content = newValue; } }, true); // Initialize aside var aside = $aside(options); // Trigger element.on(attr.trigger || 'click', aside.toggle); // Garbage collection scope.$on('$destroy', function() { if (aside) aside.destroy(); options = null; aside = null; }); } }; }]); // Source: button.js angular.module('mgcrea.ngStrap.button', []) .provider('$button', function() { var defaults = this.defaults = { activeClass:'active', toggleEvent:'click' }; this.$get = function() { return {defaults: defaults}; }; }) .directive('bsCheckboxGroup', function() { return { restrict: 'A', require: 'ngModel', compile: function postLink(element, attr) { element.attr('data-toggle', 'buttons'); element.removeAttr('ng-model'); var children = element[0].querySelectorAll('input[type="checkbox"]'); angular.forEach(children, function(child) { var childEl = angular.element(child); childEl.attr('bs-checkbox', ''); childEl.attr('ng-model', attr.ngModel + '.' + childEl.attr('value')); }); } }; }) .directive('bsCheckbox', ["$button", "$$rAF", function($button, $$rAF) { var defaults = $button.defaults; var constantValueRegExp = /^(true|false|\d+)$/; return { restrict: 'A', require: 'ngModel', link: function postLink(scope, element, attr, controller) { var options = defaults; // Support label > input[type="checkbox"] var isInput = element[0].nodeName === 'INPUT'; var activeElement = isInput ? element.parent() : element; var trueValue = angular.isDefined(attr.trueValue) ? attr.trueValue : true; if(constantValueRegExp.test(attr.trueValue)) { trueValue = scope.$eval(attr.trueValue); } var falseValue = angular.isDefined(attr.falseValue) ? attr.falseValue : false; if(constantValueRegExp.test(attr.falseValue)) { falseValue = scope.$eval(attr.falseValue); } // Parse exotic values var hasExoticValues = typeof trueValue !== 'boolean' || typeof falseValue !== 'boolean'; if(hasExoticValues) { controller.$parsers.push(function(viewValue) { // console.warn('$parser', element.attr('ng-model'), 'viewValue', viewValue); return viewValue ? trueValue : falseValue; }); // modelValue -> $formatters -> viewValue controller.$formatters.push(function(modelValue) { // console.warn('$formatter("%s"): modelValue=%o (%o)', element.attr('ng-model'), modelValue, typeof modelValue); return angular.equals(modelValue, trueValue); }); // Fix rendering for exotic values scope.$watch(attr.ngModel, function(newValue, oldValue) { controller.$render(); }); } // model -> view controller.$render = function () { // console.warn('$render', element.attr('ng-model'), 'controller.$modelValue', typeof controller.$modelValue, controller.$modelValue, 'controller.$viewValue', typeof controller.$viewValue, controller.$viewValue); var isActive = angular.equals(controller.$modelValue, trueValue); $$rAF(function() { if(isInput) element[0].checked = isActive; activeElement.toggleClass(options.activeClass, isActive); }); }; // view -> model element.bind(options.toggleEvent, function() { scope.$apply(function () { // console.warn('!click', element.attr('ng-model'), 'controller.$viewValue', typeof controller.$viewValue, controller.$viewValue, 'controller.$modelValue', typeof controller.$modelValue, controller.$modelValue); if(!isInput) { controller.$setViewValue(!activeElement.hasClass('active')); } if(!hasExoticValues) { controller.$render(); } }); }); } }; }]) .directive('bsRadioGroup', function() { return { restrict: 'A', require: 'ngModel', compile: function postLink(element, attr) { element.attr('data-toggle', 'buttons'); element.removeAttr('ng-model'); var children = element[0].querySelectorAll('input[type="radio"]'); angular.forEach(children, function(child) { angular.element(child).attr('bs-radio', ''); angular.element(child).attr('ng-model', attr.ngModel); }); } }; }) .directive('bsRadio', ["$button", "$$rAF", function($button, $$rAF) { var defaults = $button.defaults; var constantValueRegExp = /^(true|false|\d+)$/; return { restrict: 'A', require: 'ngModel', link: function postLink(scope, element, attr, controller) { var options = defaults; // Support `label > input[type="radio"]` markup var isInput = element[0].nodeName === 'INPUT'; var activeElement = isInput ? element.parent() : element; var value = constantValueRegExp.test(attr.value) ? scope.$eval(attr.value) : attr.value; // model -> view controller.$render = function () { // console.warn('$render', element.attr('value'), 'controller.$modelValue', typeof controller.$modelValue, controller.$modelValue, 'controller.$viewValue', typeof controller.$viewValue, controller.$viewValue); var isActive = angular.equals(controller.$modelValue, value); $$rAF(function() { if(isInput) element[0].checked = isActive; activeElement.toggleClass(options.activeClass, isActive); }); }; // view -> model element.bind(options.toggleEvent, function() { scope.$apply(function () { // console.warn('!click', element.attr('value'), 'controller.$viewValue', typeof controller.$viewValue, controller.$viewValue, 'controller.$modelValue', typeof controller.$modelValue, controller.$modelValue); controller.$setViewValue(value); controller.$render(); }); }); } }; }]); // Source: collapse.js angular.module('mgcrea.ngStrap.collapse', []) .provider('$collapse', function() { var defaults = this.defaults = { animation: 'am-collapse', disallowToggle: false, activeClass: 'in', startCollapsed: false, allowMultiple: false }; var controller = this.controller = function($scope, $element, $attrs) { var self = this; // Attributes options self.$options = angular.copy(defaults); angular.forEach(['animation', 'disallowToggle', 'activeClass', 'startCollapsed', 'allowMultiple'], function (key) { if(angular.isDefined($attrs[key])) self.$options[key] = $attrs[key]; }); self.$toggles = []; self.$targets = []; self.$viewChangeListeners = []; self.$registerToggle = function(element) { self.$toggles.push(element); }; self.$registerTarget = function(element) { self.$targets.push(element); }; self.$unregisterToggle = function(element) { var index = self.$toggles.indexOf(element); // remove toggle from $toggles array self.$toggles.splice(index, 1); }; self.$unregisterTarget = function(element) { var index = self.$targets.indexOf(element); // remove element from $targets array self.$targets.splice(index, 1); if (self.$options.allowMultiple) { // remove target index from $active array values deactivateItem(element); } // fix active item indexes fixActiveItemIndexes(index); self.$viewChangeListeners.forEach(function(fn) { fn(); }); }; // use array to store all the currently open panels self.$targets.$active = !self.$options.startCollapsed ? [0] : []; self.$setActive = $scope.$setActive = function(value) { if(angular.isArray(value)) { self.$targets.$active = angular.copy(value); } else if(!self.$options.disallowToggle) { // toogle element active status isActive(value) ? deactivateItem(value) : activateItem(value); } else { activateItem(value); } self.$viewChangeListeners.forEach(function(fn) { fn(); }); }; self.$activeIndexes = function() { return self.$options.allowMultiple ? self.$targets.$active : self.$targets.$active.length === 1 ? self.$targets.$active[0] : -1; }; function fixActiveItemIndexes(index) { // item with index was removed, so we // need to adjust other items index values var activeIndexes = self.$targets.$active; for(var i = 0; i < activeIndexes.length; i++) { if (index < activeIndexes[i]) { activeIndexes[i] = activeIndexes[i] - 1; } // the last item is active, so we need to // adjust its index if (activeIndexes[i] === self.$targets.length) { activeIndexes[i] = self.$targets.length - 1; } } } function isActive(value) { var activeItems = self.$targets.$active; return activeItems.indexOf(value) === -1 ? false : true; } function deactivateItem(value) { var index = self.$targets.$active.indexOf(value); if (index !== -1) { self.$targets.$active.splice(index, 1); } } function activateItem(value) { if (!self.$options.allowMultiple) { // remove current selected item self.$targets.$active.splice(0, 1); } if (self.$targets.$active.indexOf(value) === -1) { self.$targets.$active.push(value); } } }; this.$get = function() { var $collapse = {}; $collapse.defaults = defaults; $collapse.controller = controller; return $collapse; }; }) .directive('bsCollapse', ["$window", "$animate", "$collapse", function($window, $animate, $collapse) { var defaults = $collapse.defaults; return { require: ['?ngModel', 'bsCollapse'], controller: ['$scope', '$element', '$attrs', $collapse.controller], link: function postLink(scope, element, attrs, controllers) { var ngModelCtrl = controllers[0]; var bsCollapseCtrl = controllers[1]; if(ngModelCtrl) { // Update the modelValue following bsCollapseCtrl.$viewChangeListeners.push(function() { ngModelCtrl.$setViewValue(bsCollapseCtrl.$activeIndexes()); }); // modelValue -> $formatters -> viewValue ngModelCtrl.$formatters.push(function(modelValue) { // console.warn('$formatter("%s"): modelValue=%o (%o)', element.attr('ng-model'), modelValue, typeof modelValue); if (angular.isArray(modelValue)) { // model value is an array, so just replace // the active items directly bsCollapseCtrl.$setActive(modelValue); } else { var activeIndexes = bsCollapseCtrl.$activeIndexes(); if (angular.isArray(activeIndexes)) { // we have an array of selected indexes if (activeIndexes.indexOf(modelValue * 1) === -1) { // item with modelValue index is not active bsCollapseCtrl.$setActive(modelValue * 1); } } else if (activeIndexes !== modelValue * 1) { bsCollapseCtrl.$setActive(modelValue * 1); } } return modelValue; }); } } }; }]) .directive('bsCollapseToggle', function() { return { require: ['^?ngModel', '^bsCollapse'], link: function postLink(scope, element, attrs, controllers) { var ngModelCtrl = controllers[0]; var bsCollapseCtrl = controllers[1]; // Add base attr element.attr('data-toggle', 'collapse'); // Push pane to parent bsCollapse controller bsCollapseCtrl.$registerToggle(element); // remove toggle from collapse controller when toggle is destroyed scope.$on('$destroy', function() { bsCollapseCtrl.$unregisterToggle(element); }); element.on('click', function() { var index = attrs.bsCollapseToggle || bsCollapseCtrl.$toggles.indexOf(element); bsCollapseCtrl.$setActive(index * 1); scope.$apply(); }); } }; }) .directive('bsCollapseTarget', ["$animate", function($animate) { return { require: ['^?ngModel', '^bsCollapse'], // scope: true, link: function postLink(scope, element, attrs, controllers) { var ngModelCtrl = controllers[0]; var bsCollapseCtrl = controllers[1]; // Add base class element.addClass('collapse'); // Add animation class if(bsCollapseCtrl.$options.animation) { element.addClass(bsCollapseCtrl.$options.animation); } // Push pane to parent bsCollapse controller bsCollapseCtrl.$registerTarget(element); // remove pane target from collapse controller when target is destroyed scope.$on('$destroy', function() { bsCollapseCtrl.$unregisterTarget(element); }); function render() { var index = bsCollapseCtrl.$targets.indexOf(element); var active = bsCollapseCtrl.$activeIndexes(); var action = 'removeClass'; if (angular.isArray(active)) { if (active.indexOf(index) !== -1) { action = 'addClass'; } } else if (index === active) { action = 'addClass'; } $animate[action](element, bsCollapseCtrl.$options.activeClass); } bsCollapseCtrl.$viewChangeListeners.push(function() { render(); }); render(); } }; }]); // Source: datepicker.js angular.module('mgcrea.ngStrap.datepicker', [ 'mgcrea.ngStrap.helpers.dateParser', 'mgcrea.ngStrap.helpers.dateFormatter', 'mgcrea.ngStrap.tooltip']) .provider('$datepicker', function() { var defaults = this.defaults = { animation: 'am-fade', prefixClass: 'datepicker', placement: 'bottom-left', template: 'datepicker/datepicker.tpl.html', trigger: 'focus', container: false, keyboard: true, html: false, delay: 0, // lang: $locale.id, useNative: false, dateType: 'date', dateFormat: 'shortDate', modelDateFormat: null, dayFormat: 'dd', monthFormat: 'MMM', yearFormat: 'yyyy', monthTitleFormat: 'MMMM yyyy', yearTitleFormat: 'yyyy', strictFormat: false, autoclose: false, minDate: -Infinity, maxDate: +Infinity, startView: 0, minView: 0, startWeek: 0, daysOfWeekDisabled: '', iconLeft: 'glyphicon glyphicon-chevron-left', iconRight: 'glyphicon glyphicon-chevron-right' }; this.$get = ["$window", "$document", "$rootScope", "$sce", "$dateFormatter", "datepickerViews", "$tooltip", "$timeout", function($window, $document, $rootScope, $sce, $dateFormatter, datepickerViews, $tooltip, $timeout) { var bodyEl = angular.element($window.document.body); var isNative = /(ip(a|o)d|iphone|android)/ig.test($window.navigator.userAgent); var isTouch = ('createTouch' in $window.document) && isNative; if(!defaults.lang) defaults.lang = $dateFormatter.getDefaultLocale(); function DatepickerFactory(element, controller, config) { var $datepicker = $tooltip(element, angular.extend({}, defaults, config)); var parentScope = config.scope; var options = $datepicker.$options; var scope = $datepicker.$scope; if(options.startView) options.startView -= options.minView; // View vars var pickerViews = datepickerViews($datepicker); $datepicker.$views = pickerViews.views; var viewDate = pickerViews.viewDate; scope.$mode = options.startView; scope.$iconLeft = options.iconLeft; scope.$iconRight = options.iconRight; var $picker = $datepicker.$views[scope.$mode]; // Scope methods scope.$select = function(date) { $datepicker.select(date); }; scope.$selectPane = function(value) { $datepicker.$selectPane(value); }; scope.$toggleMode = function() { $datepicker.setMode((scope.$mode + 1) % $datepicker.$views.length); }; // Public methods $datepicker.update = function(date) { // console.warn('$datepicker.update() newValue=%o', date); if(angular.isDate(date) && !isNaN(date.getTime())) { $datepicker.$date = date; $picker.update.call($picker, date); } // Build only if pristine $datepicker.$build(true); }; $datepicker.updateDisabledDates = function(dateRanges) { options.disabledDateRanges = dateRanges; for(var i = 0, l = scope.rows.length; i < l; i++) { angular.forEach(scope.rows[i], $datepicker.$setDisabledEl); } }; $datepicker.select = function(date, keep) { // console.warn('$datepicker.select', date, scope.$mode); if(!angular.isDate(controller.$dateValue)) controller.$dateValue = new Date(date); if(!scope.$mode || keep) { controller.$setViewValue(angular.copy(date)); controller.$render(); if(options.autoclose && !keep) { $timeout(function() { $datepicker.hide(true); }); } } else { angular.extend(viewDate, {year: date.getFullYear(), month: date.getMonth(), date: date.getDate()}); $datepicker.setMode(scope.$mode - 1); $datepicker.$build(); } }; $datepicker.setMode = function(mode) { // console.warn('$datepicker.setMode', mode); scope.$mode = mode; $picker = $datepicker.$views[scope.$mode]; $datepicker.$build(); }; // Protected methods $datepicker.$build = function(pristine) { // console.warn('$datepicker.$build() viewDate=%o', viewDate); if(pristine === true && $picker.built) return; if(pristine === false && !$picker.built) return; $picker.build.call($picker); }; $datepicker.$updateSelected = function() { for(var i = 0, l = scope.rows.length; i < l; i++) { angular.forEach(scope.rows[i], updateSelected); } }; $datepicker.$isSelected = function(date) { return $picker.isSelected(date); }; $datepicker.$setDisabledEl = function(el) { el.disabled = $picker.isDisabled(el.date); }; $datepicker.$selectPane = function(value) { var steps = $picker.steps; // set targetDate to first day of month to avoid problems with // date values rollover. This assumes the viewDate does not // depend on the day of the month var targetDate = new Date(Date.UTC(viewDate.year + ((steps.year || 0) * value), viewDate.month + ((steps.month || 0) * value), 1)); angular.extend(viewDate, {year: targetDate.getUTCFullYear(), month: targetDate.getUTCMonth(), date: targetDate.getUTCDate()}); $datepicker.$build(); }; $datepicker.$onMouseDown = function(evt) { // Prevent blur on mousedown on .dropdown-menu evt.preventDefault(); evt.stopPropagation(); // Emulate click for mobile devices if(isTouch) { var targetEl = angular.element(evt.target); if(targetEl[0].nodeName.toLowerCase() !== 'button') { targetEl = targetEl.parent(); } targetEl.triggerHandler('click'); } }; $datepicker.$onKeyDown = function(evt) { if (!/(38|37|39|40|13)/.test(evt.keyCode) || evt.shiftKey || evt.altKey) return; evt.preventDefault(); evt.stopPropagation(); if(evt.keyCode === 13) { if(!scope.$mode) { return $datepicker.hide(true); } else { return scope.$apply(function() { $datepicker.setMode(scope.$mode - 1); }); } } // Navigate with keyboard $picker.onKeyDown(evt); parentScope.$digest(); }; // Private function updateSelected(el) { el.selected = $datepicker.$isSelected(el.date); } function focusElement() { element[0].focus(); } // Overrides var _init = $datepicker.init; $datepicker.init = function() { if(isNative && options.useNative) { element.prop('type', 'date'); element.css('-webkit-appearance', 'textfield'); return; } else if(isTouch) { element.prop('type', 'text'); element.attr('readonly', 'true'); element.on('click', focusElement); } _init(); }; var _destroy = $datepicker.destroy; $datepicker.destroy = function() { if(isNative && options.useNative) { element.off('click', focusElement); } _destroy(); }; var _show = $datepicker.show; $datepicker.show = function() { _show(); // use timeout to hookup the events to prevent // event bubbling from being processed imediately. $timeout(function() { // if $datepicker is no longer showing, don't setup events if(!$datepicker.$isShown) return; $datepicker.$element.on(isTouch ? 'touchstart' : 'mousedown', $datepicker.$onMouseDown); if(options.keyboard) { element.on('keydown', $datepicker.$onKeyDown); } }, 0, false); }; var _hide = $datepicker.hide; $datepicker.hide = function(blur) { if(!$datepicker.$isShown) return; $datepicker.$element.off(isTouch ? 'touchstart' : 'mousedown', $datepicker.$onMouseDown); if(options.keyboard) { element.off('keydown', $datepicker.$onKeyDown); } _hide(blur); }; return $datepicker; } DatepickerFactory.defaults = defaults; return DatepickerFactory; }]; }) .directive('bsDatepicker', ["$window", "$parse", "$q", "$dateFormatter", "$dateParser", "$datepicker", function($window, $parse, $q, $dateFormatter, $dateParser, $datepicker) { var defaults = $datepicker.defaults; var isNative = /(ip(a|o)d|iphone|android)/ig.test($window.navigator.userAgent); return { restrict: 'EAC', require: 'ngModel', link: function postLink(scope, element, attr, controller) { // Directive options var options = {scope: scope, controller: controller}; angular.forEach(['placement', 'container', 'delay', 'trigger', 'keyboard', 'html', 'animation', 'template', 'autoclose', 'dateType', 'dateFormat', 'modelDateFormat', 'dayFormat', 'strictFormat', 'startWeek', 'startDate', 'useNative', 'lang', 'startView', 'minView', 'iconLeft', 'iconRight', 'daysOfWeekDisabled', 'id'], function(key) { if(angular.isDefined(attr[key])) options[key] = attr[key]; }); // Visibility binding support attr.bsShow && scope.$watch(attr.bsShow, function(newValue, oldValue) { if(!datepicker || !angular.isDefined(newValue)) return; if(angular.isString(newValue)) newValue = !!newValue.match(/true|,?(datepicker),?/i); newValue === true ? datepicker.show() : datepicker.hide(); }); // Initialize datepicker var datepicker = $datepicker(element, controller, options); options = datepicker.$options; // Set expected iOS format if(isNative && options.useNative) options.dateFormat = 'yyyy-MM-dd'; var lang = options.lang; var formatDate = function(date, format) { return $dateFormatter.formatDate(date, format, lang); }; var dateParser = $dateParser({format: options.dateFormat, lang: lang, strict: options.strictFormat}); // Observe attributes for changes angular.forEach(['minDate', 'maxDate'], function(key) { // console.warn('attr.$observe(%s)', key, attr[key]); angular.isDefined(attr[key]) && attr.$observe(key, function(newValue) { // console.warn('attr.$observe(%s)=%o', key, newValue); datepicker.$options[key] = dateParser.getDateForAttribute(key, newValue); // Build only if dirty !isNaN(datepicker.$options[key]) && datepicker.$build(false); validateAgainstMinMaxDate(controller.$dateValue); }); }); // Watch model for changes scope.$watch(attr.ngModel, function(newValue, oldValue) { datepicker.update(controller.$dateValue); }, true); // Normalize undefined/null/empty array, // so that we don't treat changing from undefined->null as a change. function normalizeDateRanges(ranges) { if (!ranges || !ranges.length) return null; return ranges; } if (angular.isDefined(attr.disabledDates)) { scope.$watch(attr.disabledDates, function(disabledRanges, previousValue) { disabledRanges = normalizeDateRanges(disabledRanges); previousValue = normalizeDateRanges(previousValue); if (disabledRanges) { datepicker.updateDisabledDates(disabledRanges); } }); } function validateAgainstMinMaxDate(parsedDate) { if (!angular.isDate(parsedDate)) return; var isMinValid = isNaN(datepicker.$options.minDate) || parsedDate.getTime() >= datepicker.$options.minDate; var isMaxValid = isNaN(datepicker.$options.maxDate) || parsedDate.getTime() <= datepicker.$options.maxDate; var isValid = isMinValid && isMaxValid; controller.$setValidity('date', isValid); controller.$setValidity('min', isMinValid); controller.$setValidity('max', isMaxValid); // Only update the model when we have a valid date if(isValid) controller.$dateValue = parsedDate; } // viewValue -> $parsers -> modelValue controller.$parsers.unshift(function(viewValue) { // console.warn('$parser("%s"): viewValue=%o', element.attr('ng-model'), viewValue); // Null values should correctly reset the model value & validity if(!viewValue) { controller.$setValidity('date', true); // BREAKING CHANGE: // return null (not undefined) when input value is empty, so angularjs 1.3 // ngModelController can go ahead and run validators, like ngRequired return null; } var parsedDate = dateParser.parse(viewValue, controller.$dateValue); if(!parsedDate || isNaN(parsedDate.getTime())) { controller.$setValidity('date', false); // return undefined, causes ngModelController to // invalidate model value return; } else { validateAgainstMinMaxDate(parsedDate); } if(options.dateType === 'string') { return formatDate(parsedDate, options.modelDateFormat || options.dateFormat); } else if(options.dateType === 'number') { return controller.$dateValue.getTime(); } else if(options.dateType === 'unix') { return controller.$dateValue.getTime() / 1000; } else if(options.dateType === 'iso') { return controller.$dateValue.toISOString(); } else { return new Date(controller.$dateValue); } }); // modelValue -> $formatters -> viewValue controller.$formatters.push(function(modelValue) { // console.warn('$formatter("%s"): modelValue=%o (%o)', element.attr('ng-model'), modelValue, typeof modelValue); var date; if(angular.isUndefined(modelValue) || modelValue === null) { date = NaN; } else if(angular.isDate(modelValue)) { date = modelValue; } else if(options.dateType === 'string') { date = dateParser.parse(modelValue, null, options.modelDateFormat); } else if(options.dateType === 'unix') { date = new Date(modelValue * 1000); } else { date = new Date(modelValue); } // Setup default value? // if(isNaN(date.getTime())) { // var today = new Date(); // date = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 0, 0, 0, 0); // } controller.$dateValue = date; return getDateFormattedString(); }); // viewValue -> element controller.$render = function() { // console.warn('$render("%s"): viewValue=%o', element.attr('ng-model'), controller.$viewValue); element.val(getDateFormattedString()); }; function getDateFormattedString() { return !controller.$dateValue || isNaN(controller.$dateValue.getTime()) ? '' : formatDate(controller.$dateValue, options.dateFormat); } // Garbage collection scope.$on('$destroy', function() { if(datepicker) datepicker.destroy(); options = null; datepicker = null; }); } }; }]) .provider('datepickerViews', function() { var defaults = this.defaults = { dayFormat: 'dd', daySplit: 7 }; // Split array into smaller arrays function split(arr, size) { var arrays = []; while(arr.length > 0) { arrays.push(arr.splice(0, size)); } return arrays; } // Modulus operator function mod(n, m) { return ((n % m) + m) % m; } this.$get = ["$dateFormatter", "$dateParser", "$sce", function($dateFormatter, $dateParser, $sce) { return function(picker) { var scope = picker.$scope; var options = picker.$options; var lang = options.lang; var formatDate = function(date, format) { return $dateFormatter.formatDate(date, format, lang); }; var dateParser = $dateParser({format: options.dateFormat, lang: lang, strict: options.strictFormat}); var weekDaysMin = $dateFormatter.weekdaysShort(lang); var weekDaysLabels = weekDaysMin.slice(options.startWeek).concat(weekDaysMin.slice(0, options.startWeek)); var weekDaysLabelsHtml = $sce.trustAsHtml('