');
backdropElement.css({
position: 'fixed',
top: '0px',
left: '0px',
bottom: '0px',
right: '0px'
});
promise.then(function(data) {
compileData = data;
$modal.init();
});
$modal.init = function() {
if (options.show) {
scope.$$postDigest(function() {
$modal.show();
});
}
};
$modal.destroy = function() {
destroyModalElement();
if (backdropElement) {
backdropElement.remove();
backdropElement = null;
}
scope.$destroy();
};
$modal.show = function() {
if ($modal.$isShown) return;
var parent;
var after;
if (angular.isElement(options.container)) {
parent = options.container;
after = options.container[0].lastChild ? angular.element(options.container[0].lastChild) : null;
} else {
if (options.container) {
parent = findElement(options.container);
after = parent[0] && parent[0].lastChild ? angular.element(parent[0].lastChild) : null;
} else {
parent = null;
after = options.element;
}
}
if (modalElement) destroyModalElement();
modalScope = $modal.$scope.$new();
modalElement = $modal.$element = compileData.link(modalScope, function(clonedElement, scope) {});
if (options.backdrop) {
modalElement.css({
'z-index': dialogBaseZindex + backdropCount * 20
});
backdropElement.css({
'z-index': backdropBaseZindex + backdropCount * 20
});
backdropCount++;
}
if (scope.$emit(options.prefixEvent + '.show.before', $modal).defaultPrevented) {
return;
}
modalElement.css({
display: 'block'
}).addClass(options.placement);
if (options.customClass) {
modalElement.addClass(options.customClass);
}
if (options.size && validSizes[options.size]) {
angular.element(findElement('.modal-dialog', modalElement[0])).addClass(validSizes[options.size]);
}
if (options.animation) {
if (options.backdrop) {
backdropElement.addClass(options.backdropAnimation);
}
modalElement.addClass(options.animation);
}
if (options.backdrop) {
$animate.enter(backdropElement, bodyElement, null);
}
if (angular.version.minor <= 2) {
$animate.enter(modalElement, parent, after, enterAnimateCallback);
} else {
$animate.enter(modalElement, parent, after).then(enterAnimateCallback);
}
$modal.$isShown = scope.$isShown = true;
safeDigest(scope);
var el = modalElement[0];
requestAnimationFrame(function() {
el.focus();
});
bodyElement.addClass(options.prefixClass + '-open');
if (options.animation) {
bodyElement.addClass(options.prefixClass + '-with-' + options.animation);
}
bindBackdropEvents();
bindKeyboardEvents();
};
function enterAnimateCallback() {
scope.$emit(options.prefixEvent + '.show', $modal);
}
$modal.hide = function() {
if (!$modal.$isShown) return;
if (options.backdrop) {
backdropCount--;
}
if (scope.$emit(options.prefixEvent + '.hide.before', $modal).defaultPrevented) {
return;
}
if (angular.version.minor <= 2) {
$animate.leave(modalElement, leaveAnimateCallback);
} else {
$animate.leave(modalElement).then(leaveAnimateCallback);
}
if (options.backdrop) {
$animate.leave(backdropElement);
}
$modal.$isShown = scope.$isShown = false;
safeDigest(scope);
unbindBackdropEvents();
unbindKeyboardEvents();
};
function leaveAnimateCallback() {
scope.$emit(options.prefixEvent + '.hide', $modal);
bodyElement.removeClass(options.prefixClass + '-open');
if (options.animation) {
bodyElement.removeClass(options.prefixClass + '-with-' + options.animation);
}
}
$modal.toggle = function() {
if ($modal.$isShown) {
$modal.hide();
} else {
$modal.show();
}
};
$modal.focus = function() {
modalElement[0].focus();
};
$modal.$onKeyUp = function(evt) {
if (evt.which === 27 && $modal.$isShown) {
$modal.hide();
evt.stopPropagation();
}
};
function bindBackdropEvents() {
if (options.backdrop) {
modalElement.on('click', hideOnBackdropClick);
backdropElement.on('click', hideOnBackdropClick);
backdropElement.on('wheel', preventEventDefault);
}
}
function unbindBackdropEvents() {
if (options.backdrop) {
modalElement.off('click', hideOnBackdropClick);
backdropElement.off('click', hideOnBackdropClick);
backdropElement.off('wheel', preventEventDefault);
}
}
function bindKeyboardEvents() {
if (options.keyboard) {
modalElement.on('keyup', $modal.$onKeyUp);
}
}
function unbindKeyboardEvents() {
if (options.keyboard) {
modalElement.off('keyup', $modal.$onKeyUp);
}
}
function hideOnBackdropClick(evt) {
if (evt.target !== evt.currentTarget) return;
if (options.backdrop === 'static') {
$modal.focus();
} else {
$modal.hide();
}
}
function preventEventDefault(evt) {
evt.preventDefault();
}
function destroyModalElement() {
if ($modal.$isShown && modalElement !== null) {
unbindBackdropEvents();
unbindKeyboardEvents();
}
if (modalScope) {
modalScope.$destroy();
modalScope = null;
}
if (modalElement) {
modalElement.remove();
modalElement = $modal.$element = null;
}
}
return $modal;
}
function safeDigest(scope) {
scope.$$phase || scope.$root && scope.$root.$$phase || scope.$digest();
}
function findElement(query, element) {
return angular.element((element || document).querySelectorAll(query));
}
return ModalFactory;
} ];
}).directive('bsModal', [ '$window', '$sce', '$modal', function($window, $sce, $modal) {
return {
restrict: 'EAC',
scope: true,
link: function postLink(scope, element, attr, transclusion) {
var options = {
scope: scope,
element: element,
show: false
};
angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'contentTemplate', 'placement', 'backdrop', 'keyboard', 'html', 'container', 'animation', 'backdropAnimation', 'id', 'prefixEvent', 'prefixClass', 'customClass', 'modalClass', 'size' ], function(key) {
if (angular.isDefined(attr[key])) options[key] = attr[key];
});
if (options.modalClass) {
options.customClass = options.modalClass;
}
var falseValueRegExp = /^(false|0|)$/i;
angular.forEach([ 'backdrop', 'keyboard', 'html', 'container' ], function(key) {
if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) options[key] = false;
});
angular.forEach([ 'title', 'content' ], function(key) {
if (attr[key]) {
attr.$observe(key, function(newValue, oldValue) {
scope[key] = $sce.trustAsHtml(newValue);
});
}
});
if (attr.bsModal) {
scope.$watch(attr.bsModal, function(newValue, oldValue) {
if (angular.isObject(newValue)) {
angular.extend(scope, newValue);
} else {
scope.content = newValue;
}
}, true);
}
var modal = $modal(options);
element.on(attr.trigger || 'click', modal.toggle);
scope.$on('$destroy', function() {
if (modal) modal.destroy();
options = null;
modal = null;
});
}
};
} ]);
if (angular.version.minor < 3 && angular.version.dot < 14) {
angular.module('ng').factory('$$rAF', [ '$window', '$timeout', function($window, $timeout) {
var requestAnimationFrame = $window.requestAnimationFrame || $window.webkitRequestAnimationFrame || $window.mozRequestAnimationFrame;
var cancelAnimationFrame = $window.cancelAnimationFrame || $window.webkitCancelAnimationFrame || $window.mozCancelAnimationFrame || $window.webkitCancelRequestAnimationFrame;
var rafSupported = !!requestAnimationFrame;
var raf = rafSupported ? function(fn) {
var id = requestAnimationFrame(fn);
return function() {
cancelAnimationFrame(id);
};
} : function(fn) {
var timer = $timeout(fn, 16.66, false);
return function() {
$timeout.cancel(timer);
};
};
raf.supported = rafSupported;
return raf;
} ]);
}
angular.module('mgcrea.ngStrap.helpers.parseOptions', []).provider('$parseOptions', function() {
var defaults = this.defaults = {
regexp: /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/
};
this.$get = [ '$parse', '$q', function($parse, $q) {
function ParseOptionsFactory(attr, config) {
var $parseOptions = {};
var options = angular.extend({}, defaults, config);
$parseOptions.$values = [];
var match;
var displayFn;
var valueName;
var keyName;
var groupByFn;
var valueFn;
var valuesFn;
$parseOptions.init = function() {
$parseOptions.$match = match = attr.match(options.regexp);
displayFn = $parse(match[2] || match[1]);
valueName = match[4] || match[6];
keyName = match[5];
groupByFn = $parse(match[3] || '');
valueFn = $parse(match[2] ? match[1] : valueName);
valuesFn = $parse(match[7]);
};
$parseOptions.valuesFn = function(scope, controller) {
return $q.when(valuesFn(scope, controller)).then(function(values) {
if (!angular.isArray(values)) {
values = [];
}
$parseOptions.$values = values.length ? parseValues(values, scope) : [];
return $parseOptions.$values;
});
};
$parseOptions.displayValue = function(modelValue) {
var scope = {};
scope[valueName] = modelValue;
return displayFn(scope);
};
function parseValues(values, scope) {
return values.map(function(match, index) {
var locals = {};
var label;
var value;
locals[valueName] = match;
label = displayFn(scope, locals);
value = valueFn(scope, locals);
return {
label: label,
value: value,
index: index
};
});
}
$parseOptions.init();
return $parseOptions;
}
return ParseOptionsFactory;
} ];
});
angular.module('mgcrea.ngStrap.helpers.dimensions', []).factory('dimensions', function() {
var fn = {};
var nodeName = fn.nodeName = function(element, name) {
return element.nodeName && element.nodeName.toLowerCase() === name.toLowerCase();
};
fn.css = function(element, prop, extra) {
var value;
if (element.currentStyle) {
value = element.currentStyle[prop];
} else if (window.getComputedStyle) {
value = window.getComputedStyle(element)[prop];
} else {
value = element.style[prop];
}
return extra === true ? parseFloat(value) || 0 : value;
};
fn.offset = function(element) {
var boxRect = element.getBoundingClientRect();
var docElement = element.ownerDocument;
return {
width: boxRect.width || element.offsetWidth,
height: boxRect.height || element.offsetHeight,
top: boxRect.top + (window.pageYOffset || docElement.documentElement.scrollTop) - (docElement.documentElement.clientTop || 0),
left: boxRect.left + (window.pageXOffset || docElement.documentElement.scrollLeft) - (docElement.documentElement.clientLeft || 0)
};
};
fn.setOffset = function(element, options, i) {
var curPosition;
var curLeft;
var curCSSTop;
var curTop;
var curOffset;
var curCSSLeft;
var calculatePosition;
var position = fn.css(element, 'position');
var curElem = angular.element(element);
var props = {};
if (position === 'static') {
element.style.position = 'relative';
}
curOffset = fn.offset(element);
curCSSTop = fn.css(element, 'top');
curCSSLeft = fn.css(element, 'left');
calculatePosition = (position === 'absolute' || position === 'fixed') && (curCSSTop + curCSSLeft).indexOf('auto') > -1;
if (calculatePosition) {
curPosition = fn.position(element);
curTop = curPosition.top;
curLeft = curPosition.left;
} else {
curTop = parseFloat(curCSSTop) || 0;
curLeft = parseFloat(curCSSLeft) || 0;
}
if (angular.isFunction(options)) {
options = options.call(element, i, curOffset);
}
if (options.top !== null) {
props.top = options.top - curOffset.top + curTop;
}
if (options.left !== null) {
props.left = options.left - curOffset.left + curLeft;
}
if ('using' in options) {
options.using.call(curElem, props);
} else {
curElem.css({
top: props.top + 'px',
left: props.left + 'px'
});
}
};
fn.position = function(element) {
var offsetParentRect = {
top: 0,
left: 0
};
var offsetParentEl;
var offset;
if (fn.css(element, 'position') === 'fixed') {
offset = element.getBoundingClientRect();
} else {
offsetParentEl = offsetParentElement(element);
offset = fn.offset(element);
if (!nodeName(offsetParentEl, 'html')) {
offsetParentRect = fn.offset(offsetParentEl);
}
offsetParentRect.top += fn.css(offsetParentEl, 'borderTopWidth', true);
offsetParentRect.left += fn.css(offsetParentEl, 'borderLeftWidth', true);
}
return {
width: element.offsetWidth,
height: element.offsetHeight,
top: offset.top - offsetParentRect.top - fn.css(element, 'marginTop', true),
left: offset.left - offsetParentRect.left - fn.css(element, 'marginLeft', true)
};
};
function offsetParentElement(element) {
var docElement = element.ownerDocument;
var offsetParent = element.offsetParent || docElement;
if (nodeName(offsetParent, '#document')) return docElement.documentElement;
while (offsetParent && !nodeName(offsetParent, 'html') && fn.css(offsetParent, 'position') === 'static') {
offsetParent = offsetParent.offsetParent;
}
return offsetParent || docElement.documentElement;
}
fn.height = function(element, outer) {
var value = element.offsetHeight;
if (outer) {
value += fn.css(element, 'marginTop', true) + fn.css(element, 'marginBottom', true);
} else {
value -= fn.css(element, 'paddingTop', true) + fn.css(element, 'paddingBottom', true) + fn.css(element, 'borderTopWidth', true) + fn.css(element, 'borderBottomWidth', true);
}
return value;
};
fn.width = function(element, outer) {
var value = element.offsetWidth;
if (outer) {
value += fn.css(element, 'marginLeft', true) + fn.css(element, 'marginRight', true);
} else {
value -= fn.css(element, 'paddingLeft', true) + fn.css(element, 'paddingRight', true) + fn.css(element, 'borderLeftWidth', true) + fn.css(element, 'borderRightWidth', true);
}
return value;
};
return fn;
});
angular.module('mgcrea.ngStrap.helpers.debounce', []).factory('debounce', [ '$timeout', function($timeout) {
return function(func, wait, immediate) {
var timeout = null;
return function() {
var context = this;
var args = arguments;
var callNow = immediate && !timeout;
if (timeout) {
$timeout.cancel(timeout);
}
timeout = $timeout(function later() {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
}, wait, false);
if (callNow) {
func.apply(context, args);
}
return timeout;
};
};
} ]).factory('throttle', [ '$timeout', function($timeout) {
return function(func, wait, options) {
var timeout = null;
if (!options) options = {};
return function() {
var context = this;
var args = arguments;
if (!timeout) {
if (options.leading !== false) {
func.apply(context, args);
}
timeout = $timeout(function later() {
timeout = null;
if (options.trailing !== false) {
func.apply(context, args);
}
}, wait, false);
}
};
};
} ]);
angular.module('mgcrea.ngStrap.helpers.dateParser', []).provider('$dateParser', [ '$localeProvider', function($localeProvider) {
function ParseDate() {
this.year = 1970;
this.month = 0;
this.day = 1;
this.hours = 0;
this.minutes = 0;
this.seconds = 0;
this.milliseconds = 0;
}
ParseDate.prototype.setMilliseconds = function(value) {
this.milliseconds = value;
};
ParseDate.prototype.setSeconds = function(value) {
this.seconds = value;
};
ParseDate.prototype.setMinutes = function(value) {
this.minutes = value;
};
ParseDate.prototype.setHours = function(value) {
this.hours = value;
};
ParseDate.prototype.getHours = function() {
return this.hours;
};
ParseDate.prototype.setDate = function(value) {
this.day = value;
};
ParseDate.prototype.setMonth = function(value) {
this.month = value;
};
ParseDate.prototype.setFullYear = function(value) {
this.year = value;
};
ParseDate.prototype.fromDate = function(value) {
this.year = value.getFullYear();
this.month = value.getMonth();
this.day = value.getDate();
this.hours = value.getHours();
this.minutes = value.getMinutes();
this.seconds = value.getSeconds();
this.milliseconds = value.getMilliseconds();
return this;
};
ParseDate.prototype.toDate = function() {
return new Date(this.year, this.month, this.day, this.hours, this.minutes, this.seconds, this.milliseconds);
};
var proto = ParseDate.prototype;
function noop() {}
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function indexOfCaseInsensitive(array, value) {
var len = array.length;
var str = value.toString().toLowerCase();
for (var i = 0; i < len; i++) {
if (array[i].toLowerCase() === str) {
return i;
}
}
return -1;
}
var defaults = this.defaults = {
format: 'shortDate',
strict: false
};
this.$get = [ '$locale', 'dateFilter', function($locale, dateFilter) {
var DateParserFactory = function(config) {
var options = angular.extend({}, defaults, config);
var $dateParser = {};
var regExpMap = {
sss: '[0-9]{3}',
ss: '[0-5][0-9]',
s: options.strict ? '[1-5]?[0-9]' : '[0-9]|[0-5][0-9]',
mm: '[0-5][0-9]',
m: options.strict ? '[1-5]?[0-9]' : '[0-9]|[0-5][0-9]',
HH: '[01][0-9]|2[0-3]',
H: options.strict ? '1?[0-9]|2[0-3]' : '[01]?[0-9]|2[0-3]',
hh: '[0][1-9]|[1][012]',
h: options.strict ? '[1-9]|1[012]' : '0?[1-9]|1[012]',
a: 'AM|PM',
EEEE: $locale.DATETIME_FORMATS.DAY.join('|'),
EEE: $locale.DATETIME_FORMATS.SHORTDAY.join('|'),
dd: '0[1-9]|[12][0-9]|3[01]',
d: options.strict ? '[1-9]|[1-2][0-9]|3[01]' : '0?[1-9]|[1-2][0-9]|3[01]',
MMMM: $locale.DATETIME_FORMATS.MONTH.join('|'),
MMM: $locale.DATETIME_FORMATS.SHORTMONTH.join('|'),
MM: '0[1-9]|1[012]',
M: options.strict ? '[1-9]|1[012]' : '0?[1-9]|1[012]',
yyyy: '[1]{1}[0-9]{3}|[2]{1}[0-9]{3}',
yy: '[0-9]{2}',
y: options.strict ? '-?(0|[1-9][0-9]{0,3})' : '-?0*[0-9]{1,4}'
};
var setFnMap = {
sss: proto.setMilliseconds,
ss: proto.setSeconds,
s: proto.setSeconds,
mm: proto.setMinutes,
m: proto.setMinutes,
HH: proto.setHours,
H: proto.setHours,
hh: proto.setHours,
h: proto.setHours,
EEEE: noop,
EEE: noop,
dd: proto.setDate,
d: proto.setDate,
a: function(value) {
var hours = this.getHours() % 12;
return this.setHours(value.match(/pm/i) ? hours + 12 : hours);
},
MMMM: function(value) {
return this.setMonth(indexOfCaseInsensitive($locale.DATETIME_FORMATS.MONTH, value));
},
MMM: function(value) {
return this.setMonth(indexOfCaseInsensitive($locale.DATETIME_FORMATS.SHORTMONTH, value));
},
MM: function(value) {
return this.setMonth(1 * value - 1);
},
M: function(value) {
return this.setMonth(1 * value - 1);
},
yyyy: proto.setFullYear,
yy: function(value) {
return this.setFullYear(2e3 + 1 * value);
},
y: function(value) {
return 1 * value <= 50 && value.length === 2 ? this.setFullYear(2e3 + 1 * value) : this.setFullYear(1 * value);
}
};
var regex;
var setMap;
$dateParser.init = function() {
$dateParser.$format = $locale.DATETIME_FORMATS[options.format] || options.format;
regex = regExpForFormat($dateParser.$format);
setMap = setMapForFormat($dateParser.$format);
};
$dateParser.isValid = function(date) {
if (angular.isDate(date)) return !isNaN(date.getTime());
return regex.test(date);
};
$dateParser.parse = function(value, baseDate, format, timezone) {
if (format) format = $locale.DATETIME_FORMATS[format] || format;
if (angular.isDate(value)) value = dateFilter(value, format || $dateParser.$format, timezone);
var formatRegex = format ? regExpForFormat(format) : regex;
var formatSetMap = format ? setMapForFormat(format) : setMap;
var matches = formatRegex.exec(value);
if (!matches) return false;
var date = baseDate && !isNaN(baseDate.getTime()) ? new ParseDate().fromDate(baseDate) : new ParseDate().fromDate(new Date(1970, 0, 1, 0));
for (var i = 0; i < matches.length - 1; i++) {
if (formatSetMap[i]) formatSetMap[i].call(date, matches[i + 1]);
}
var newDate = date.toDate();
if (parseInt(date.day, 10) !== newDate.getDate()) {
return false;
}
return newDate;
};
$dateParser.getDateForAttribute = function(key, value) {
var date;
if (value === 'today') {
var today = new Date();
date = new Date(today.getFullYear(), today.getMonth(), today.getDate() + (key === 'maxDate' ? 1 : 0), 0, 0, 0, key === 'minDate' ? 0 : -1);
} else if (angular.isString(value) && value.match(/^".+"$/)) {
date = new Date(value.substr(1, value.length - 2));
} else if (isNumeric(value)) {
date = new Date(parseInt(value, 10));
} else if (angular.isString(value) && value.length === 0) {
date = key === 'minDate' ? -Infinity : +Infinity;
} else {
date = new Date(value);
}
return date;
};
$dateParser.getTimeForAttribute = function(key, value) {
var time;
if (value === 'now') {
time = new Date().setFullYear(1970, 0, 1);
} else if (angular.isString(value) && value.match(/^".+"$/)) {
time = new Date(value.substr(1, value.length - 2)).setFullYear(1970, 0, 1);
} else if (isNumeric(value)) {
time = new Date(parseInt(value, 10)).setFullYear(1970, 0, 1);
} else if (angular.isString(value) && value.length === 0) {
time = key === 'minTime' ? -Infinity : +Infinity;
} else {
time = $dateParser.parse(value, new Date(1970, 0, 1, 0));
}
return time;
};
$dateParser.daylightSavingAdjust = function(date) {
if (!date) {
return null;
}
date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
return date;
};
$dateParser.timezoneOffsetAdjust = function(date, timezone, undo) {
if (!date) {
return null;
}
if (timezone && timezone === 'UTC') {
date = new Date(date.getTime());
date.setMinutes(date.getMinutes() + (undo ? -1 : 1) * date.getTimezoneOffset());
}
return date;
};
function regExpForFormat(format) {
var re = buildDateAbstractRegex(format);
return buildDateParseRegex(re);
}
function buildDateAbstractRegex(format) {
var escapedFormat = escapeReservedSymbols(format);
var escapedLiteralFormat = escapedFormat.replace(/''/g, '\\\'');
var literalRegex = /('(?:\\'|.)*?')/;
var formatParts = escapedLiteralFormat.split(literalRegex);
var dateElements = Object.keys(regExpMap);
var dateRegexParts = [];
angular.forEach(formatParts, function(part) {
if (isFormatStringLiteral(part)) {
part = trimLiteralEscapeChars(part);
} else {
for (var i = 0; i < dateElements.length; i++) {
part = part.split(dateElements[i]).join('${' + i + '}');
}
}
dateRegexParts.push(part);
});
return dateRegexParts.join('');
}
function escapeReservedSymbols(text) {
return text.replace(/\\/g, '[\\\\]').replace(/-/g, '[-]').replace(/\./g, '[.]').replace(/\*/g, '[*]').replace(/\+/g, '[+]').replace(/\?/g, '[?]').replace(/\$/g, '[$]').replace(/\^/g, '[^]').replace(/\//g, '[/]').replace(/\\s/g, '[\\s]');
}
function isFormatStringLiteral(text) {
return /^'.*'$/.test(text);
}
function trimLiteralEscapeChars(text) {
return text.replace(/^'(.*)'$/, '$1');
}
function buildDateParseRegex(abstractRegex) {
var dateElements = Object.keys(regExpMap);
var re = abstractRegex;
for (var i = 0; i < dateElements.length; i++) {
re = re.split('${' + i + '}').join('(' + regExpMap[dateElements[i]] + ')');
}
return new RegExp('^' + re + '$', [ 'i' ]);
}
function setMapForFormat(format) {
var re = buildDateAbstractRegex(format);
return buildDateParseValuesMap(re);
}
function buildDateParseValuesMap(abstractRegex) {
var dateElements = Object.keys(regExpMap);
var valuesRegex = new RegExp('\\${(\\d+)}', 'g');
var valuesMatch;
var keyIndex;
var valueKey;
var valueFunction;
var valuesFunctionMap = [];
while ((valuesMatch = valuesRegex.exec(abstractRegex)) !== null) {
keyIndex = valuesMatch[1];
valueKey = dateElements[keyIndex];
valueFunction = setFnMap[valueKey];
valuesFunctionMap.push(valueFunction);
}
return valuesFunctionMap;
}
$dateParser.init();
return $dateParser;
};
return DateParserFactory;
} ];
} ]);
angular.module('mgcrea.ngStrap.helpers.dateFormatter', []).service('$dateFormatter', [ '$locale', 'dateFilter', function($locale, dateFilter) {
this.getDefaultLocale = function() {
return $locale.id;
};
this.getDatetimeFormat = function(format, lang) {
return $locale.DATETIME_FORMATS[format] || format;
};
this.weekdaysShort = function(lang) {
return $locale.DATETIME_FORMATS.SHORTDAY;
};
function splitTimeFormat(format) {
return /(h+)([:\.])?(m+)([:\.])?(s*)[ ]?(a?)/i.exec(format).slice(1);
}
this.hoursFormat = function(timeFormat) {
return splitTimeFormat(timeFormat)[0];
};
this.minutesFormat = function(timeFormat) {
return splitTimeFormat(timeFormat)[2];
};
this.secondsFormat = function(timeFormat) {
return splitTimeFormat(timeFormat)[4];
};
this.timeSeparator = function(timeFormat) {
return splitTimeFormat(timeFormat)[1];
};
this.showSeconds = function(timeFormat) {
return !!splitTimeFormat(timeFormat)[4];
};
this.showAM = function(timeFormat) {
return !!splitTimeFormat(timeFormat)[5];
};
this.formatDate = function(date, format, lang, timezone) {
return dateFilter(date, format, timezone);
};
} ]);
angular.module('mgcrea.ngStrap.core', []).service('$bsCompiler', bsCompilerService);
function bsCompilerService($q, $http, $injector, $compile, $controller, $templateCache) {
this.compile = function(options) {
if (options.template && /\.html$/.test(options.template)) {
console.warn('Deprecated use of `template` option to pass a file. Please use the `templateUrl` option instead.');
options.templateUrl = options.template;
options.template = '';
}
var templateUrl = options.templateUrl;
var template = options.template || '';
var controller = options.controller;
var controllerAs = options.controllerAs;
var resolve = angular.copy(options.resolve || {});
var locals = angular.copy(options.locals || {});
var transformTemplate = options.transformTemplate || angular.identity;
var bindToController = options.bindToController;
angular.forEach(resolve, function(value, key) {
if (angular.isString(value)) {
resolve[key] = $injector.get(value);
} else {
resolve[key] = $injector.invoke(value);
}
});
angular.extend(resolve, locals);
if (template) {
resolve.$template = $q.when(template);
} else if (templateUrl) {
resolve.$template = fetchTemplate(templateUrl);
} else {
throw new Error('Missing `template` / `templateUrl` option.');
}
if (options.titleTemplate) {
resolve.$template = $q.all([ resolve.$template, fetchTemplate(options.titleTemplate) ]).then(function(templates) {
var templateEl = angular.element(templates[0]);
findElement('[ng-bind="title"]', templateEl[0]).removeAttr('ng-bind').html(templates[1]);
return templateEl[0].outerHTML;
});
}
if (options.contentTemplate) {
resolve.$template = $q.all([ resolve.$template, fetchTemplate(options.contentTemplate) ]).then(function(templates) {
var templateEl = angular.element(templates[0]);
var contentEl = findElement('[ng-bind="content"]', templateEl[0]).removeAttr('ng-bind').html(templates[1]);
if (!options.templateUrl) contentEl.next().remove();
return templateEl[0].outerHTML;
});
}
return $q.all(resolve).then(function(locals) {
var template = transformTemplate(locals.$template);
if (options.html) {
template = template.replace(/ng-bind="/gi, 'ng-bind-html="');
}
var element = angular.element('
').html(template.trim()).contents();
var linkFn = $compile(element);
return {
locals: locals,
element: element,
link: function link(scope) {
locals.$scope = scope;
if (controller) {
var invokeCtrl = $controller(controller, locals, true);
if (bindToController) {
angular.extend(invokeCtrl.instance, locals);
}
var ctrl = angular.isObject(invokeCtrl) ? invokeCtrl : invokeCtrl();
element.data('$ngControllerController', ctrl);
element.children().data('$ngControllerController', ctrl);
if (controllerAs) {
scope[controllerAs] = ctrl;
}
}
return linkFn.apply(null, arguments);
}
};
});
};
function findElement(query, element) {
return angular.element((element || document).querySelectorAll(query));
}
var fetchPromises = {};
function fetchTemplate(template) {
if (fetchPromises[template]) return fetchPromises[template];
return fetchPromises[template] = $http.get(template, {
cache: $templateCache
}).then(function(res) {
return res.data;
});
}
}
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',
templateUrl: 'datepicker/datepicker.tpl.html',
trigger: 'focus',
container: false,
keyboard: true,
html: false,
delay: 0,
useNative: false,
dateType: 'date',
dateFormat: 'shortDate',
timezone: null,
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 isNative = /(ip[ao]d|iphone|android)/gi.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;
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.$select = function(date) {
$datepicker.select(date);
};
scope.$selectPane = function(value) {
$datepicker.$selectPane(value);
};
scope.$toggleMode = function() {
$datepicker.setMode((scope.$mode + 1) % $datepicker.$views.length);
};
$datepicker.update = function(date) {
if (angular.isDate(date) && !isNaN(date.getTime())) {
$datepicker.$date = date;
$picker.update.call($picker, date);
}
$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) {
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) {
scope.$mode = mode;
$picker = $datepicker.$views[scope.$mode];
$datepicker.$build();
};
$datepicker.$build = function(pristine) {
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;
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) {
evt.preventDefault();
evt.stopPropagation();
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) {
$datepicker.hide(true);
} else {
scope.$apply(function() {
$datepicker.setMode(scope.$mode - 1);
});
}
return;
}
$picker.onKeyDown(evt);
parentScope.$digest();
};
function updateSelected(el) {
el.selected = $datepicker.$isSelected(el.date);
}
function focusElement() {
element[0].focus();
}
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() {
if (!isTouch && element.attr('readonly') || element.attr('disabled')) return;
_show();
$timeout(function() {
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 isNative = /(ip[ao]d|iphone|android)/gi.test($window.navigator.userAgent);
return {
restrict: 'EAC',
require: 'ngModel',
link: function postLink(scope, element, attr, controller) {
var options = {
scope: scope
};
angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'placement', 'container', 'delay', 'trigger', 'html', 'animation', 'autoclose', 'dateType', 'dateFormat', 'timezone', 'modelDateFormat', 'dayFormat', 'strictFormat', 'startWeek', 'startDate', 'useNative', 'lang', 'startView', 'minView', 'iconLeft', 'iconRight', 'daysOfWeekDisabled', 'id', 'prefixClass', 'prefixEvent' ], function(key) {
if (angular.isDefined(attr[key])) options[key] = attr[key];
});
var falseValueRegExp = /^(false|0|)$/i;
angular.forEach([ 'html', 'container', 'autoclose', 'useNative' ], function(key) {
if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) {
options[key] = false;
}
});
var datepicker = $datepicker(element, controller, options);
options = datepicker.$options;
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
});
if (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);
if (newValue === true) {
datepicker.show();
} else {
datepicker.hide();
}
});
}
angular.forEach([ 'minDate', 'maxDate' ], function(key) {
if (angular.isDefined(attr[key])) {
attr.$observe(key, function(newValue) {
datepicker.$options[key] = dateParser.getDateForAttribute(key, newValue);
if (!isNaN(datepicker.$options[key])) datepicker.$build(false);
validateAgainstMinMaxDate(controller.$dateValue);
});
}
});
if (angular.isDefined(attr.dateFormat)) {
attr.$observe('dateFormat', function(newValue) {
datepicker.$options.dateFormat = newValue;
});
}
scope.$watch(attr.ngModel, function(newValue, oldValue) {
datepicker.update(controller.$dateValue);
}, true);
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);
if (isValid) controller.$dateValue = parsedDate;
}
controller.$parsers.unshift(function(viewValue) {
var date;
if (!viewValue) {
controller.$setValidity('date', true);
return null;
}
var parsedDate = dateParser.parse(viewValue, controller.$dateValue);
if (!parsedDate || isNaN(parsedDate.getTime())) {
controller.$setValidity('date', false);
return;
}
validateAgainstMinMaxDate(parsedDate);
if (options.dateType === 'string') {
date = dateParser.timezoneOffsetAdjust(parsedDate, options.timezone, true);
return formatDate(date, options.modelDateFormat || options.dateFormat);
}
date = dateParser.timezoneOffsetAdjust(controller.$dateValue, options.timezone, true);
if (options.dateType === 'number') {
return date.getTime();
} else if (options.dateType === 'unix') {
return date.getTime() / 1e3;
} else if (options.dateType === 'iso') {
return date.toISOString();
}
return new Date(date);
});
controller.$formatters.push(function(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 * 1e3);
} else {
date = new Date(modelValue);
}
controller.$dateValue = dateParser.timezoneOffsetAdjust(date, options.timezone);
return getDateFormattedString();
});
controller.$render = function() {
element.val(getDateFormattedString());
};
function getDateFormattedString() {
return !controller.$dateValue || isNaN(controller.$dateValue.getTime()) ? '' : formatDate(controller.$dateValue, options.dateFormat);
}
scope.$on('$destroy', function() {
if (datepicker) datepicker.destroy();
options = null;
datepicker = null;
});
}
};
} ]).provider('datepickerViews', function() {
function split(arr, size) {
var arrays = [];
while (arr.length > 0) {
arrays.push(arr.splice(0, size));
}
return arrays;
}
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('' + weekDaysLabels.join('') + '');
var startDate = picker.$date || (options.startDate ? dateParser.getDateForAttribute('startDate', options.startDate) : new Date());
var viewDate = {
year: startDate.getFullYear(),
month: startDate.getMonth(),
date: startDate.getDate()
};
var views = [ {
format: options.dayFormat,
split: 7,
steps: {
month: 1
},
update: function(date, force) {
if (!this.built || force || date.getFullYear() !== viewDate.year || date.getMonth() !== viewDate.month) {
angular.extend(viewDate, {
year: picker.$date.getFullYear(),
month: picker.$date.getMonth(),
date: picker.$date.getDate()
});
picker.$build();
} else if (date.getDate() !== viewDate.date || date.getDate() === 1) {
viewDate.date = picker.$date.getDate();
picker.$updateSelected();
}
},
build: function() {
var firstDayOfMonth = new Date(viewDate.year, viewDate.month, 1);
var firstDayOfMonthOffset = firstDayOfMonth.getTimezoneOffset();
var firstDate = new Date(+firstDayOfMonth - mod(firstDayOfMonth.getDay() - options.startWeek, 7) * 864e5);
var firstDateOffset = firstDate.getTimezoneOffset();
var today = dateParser.timezoneOffsetAdjust(new Date(), options.timezone).toDateString();
if (firstDateOffset !== firstDayOfMonthOffset) firstDate = new Date(+firstDate + (firstDateOffset - firstDayOfMonthOffset) * 6e4);
var days = [];
var day;
for (var i = 0; i < 42; i++) {
day = dateParser.daylightSavingAdjust(new Date(firstDate.getFullYear(), firstDate.getMonth(), firstDate.getDate() + i));
days.push({
date: day,
isToday: day.toDateString() === today,
label: formatDate(day, this.format),
selected: picker.$date && this.isSelected(day),
muted: day.getMonth() !== viewDate.month,
disabled: this.isDisabled(day)
});
}
scope.title = formatDate(firstDayOfMonth, options.monthTitleFormat);
scope.showLabels = true;
scope.labels = weekDaysLabelsHtml;
scope.rows = split(days, this.split);
this.built = true;
},
isSelected: function(date) {
return picker.$date && date.getFullYear() === picker.$date.getFullYear() && date.getMonth() === picker.$date.getMonth() && date.getDate() === picker.$date.getDate();
},
isDisabled: function(date) {
var time = date.getTime();
if (time < options.minDate || time > options.maxDate) return true;
if (options.daysOfWeekDisabled.indexOf(date.getDay()) !== -1) return true;
if (options.disabledDateRanges) {
for (var i = 0; i < options.disabledDateRanges.length; i++) {
if (time >= options.disabledDateRanges[i].start && time <= options.disabledDateRanges[i].end) {
return true;
}
}
}
return false;
},
onKeyDown: function(evt) {
if (!picker.$date) {
return;
}
var actualTime = picker.$date.getTime();
var newDate;
if (evt.keyCode === 37) newDate = new Date(actualTime - 1 * 864e5); else if (evt.keyCode === 38) newDate = new Date(actualTime - 7 * 864e5); else if (evt.keyCode === 39) newDate = new Date(actualTime + 1 * 864e5); else if (evt.keyCode === 40) newDate = new Date(actualTime + 7 * 864e5);
if (!this.isDisabled(newDate)) picker.select(newDate, true);
}
}, {
name: 'month',
format: options.monthFormat,
split: 4,
steps: {
year: 1
},
update: function(date, force) {
if (!this.built || date.getFullYear() !== viewDate.year) {
angular.extend(viewDate, {
year: picker.$date.getFullYear(),
month: picker.$date.getMonth(),
date: picker.$date.getDate()
});
picker.$build();
} else if (date.getMonth() !== viewDate.month) {
angular.extend(viewDate, {
month: picker.$date.getMonth(),
date: picker.$date.getDate()
});
picker.$updateSelected();
}
},
build: function() {
var months = [];
var month;
for (var i = 0; i < 12; i++) {
month = new Date(viewDate.year, i, 1);
months.push({
date: month,
label: formatDate(month, this.format),
selected: picker.$isSelected(month),
disabled: this.isDisabled(month)
});
}
scope.title = formatDate(month, options.yearTitleFormat);
scope.showLabels = false;
scope.rows = split(months, this.split);
this.built = true;
},
isSelected: function(date) {
return picker.$date && date.getFullYear() === picker.$date.getFullYear() && date.getMonth() === picker.$date.getMonth();
},
isDisabled: function(date) {
var lastDate = +new Date(date.getFullYear(), date.getMonth() + 1, 0);
return lastDate < options.minDate || date.getTime() > options.maxDate;
},
onKeyDown: function(evt) {
if (!picker.$date) {
return;
}
var actualMonth = picker.$date.getMonth();
var newDate = new Date(picker.$date);
if (evt.keyCode === 37) newDate.setMonth(actualMonth - 1); else if (evt.keyCode === 38) newDate.setMonth(actualMonth - 4); else if (evt.keyCode === 39) newDate.setMonth(actualMonth + 1); else if (evt.keyCode === 40) newDate.setMonth(actualMonth + 4);
if (!this.isDisabled(newDate)) picker.select(newDate, true);
}
}, {
name: 'year',
format: options.yearFormat,
split: 4,
steps: {
year: 12
},
update: function(date, force) {
if (!this.built || force || parseInt(date.getFullYear() / 20, 10) !== parseInt(viewDate.year / 20, 10)) {
angular.extend(viewDate, {
year: picker.$date.getFullYear(),
month: picker.$date.getMonth(),
date: picker.$date.getDate()
});
picker.$build();
} else if (date.getFullYear() !== viewDate.year) {
angular.extend(viewDate, {
year: picker.$date.getFullYear(),
month: picker.$date.getMonth(),
date: picker.$date.getDate()
});
picker.$updateSelected();
}
},
build: function() {
var firstYear = viewDate.year - viewDate.year % (this.split * 3);
var years = [];
var year;
for (var i = 0; i < 12; i++) {
year = new Date(firstYear + i, 0, 1);
years.push({
date: year,
label: formatDate(year, this.format),
selected: picker.$isSelected(year),
disabled: this.isDisabled(year)
});
}
scope.title = years[0].label + '-' + years[years.length - 1].label;
scope.showLabels = false;
scope.rows = split(years, this.split);
this.built = true;
},
isSelected: function(date) {
return picker.$date && date.getFullYear() === picker.$date.getFullYear();
},
isDisabled: function(date) {
var lastDate = +new Date(date.getFullYear() + 1, 0, 0);
return lastDate < options.minDate || date.getTime() > options.maxDate;
},
onKeyDown: function(evt) {
if (!picker.$date) {
return;
}
var actualYear = picker.$date.getFullYear();
var newDate = new Date(picker.$date);
if (evt.keyCode === 37) newDate.setYear(actualYear - 1); else if (evt.keyCode === 38) newDate.setYear(actualYear - 4); else if (evt.keyCode === 39) newDate.setYear(actualYear + 1); else if (evt.keyCode === 40) newDate.setYear(actualYear + 4);
if (!this.isDisabled(newDate)) picker.select(newDate, true);
}
} ];
return {
views: options.minView ? Array.prototype.slice.call(views, options.minView) : views,
viewDate: viewDate
};
};
} ];
});
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;
self.$options = angular.copy(defaults);
angular.forEach([ 'animation', 'disallowToggle', 'activeClass', 'startCollapsed', 'allowMultiple' ], function(key) {
if (angular.isDefined($attrs[key])) self.$options[key] = $attrs[key];
});
var falseValueRegExp = /^(false|0|)$/i;
angular.forEach([ 'disallowToggle', 'startCollapsed', 'allowMultiple' ], function(key) {
if (angular.isDefined($attrs[key]) && falseValueRegExp.test($attrs[key])) {
self.$options[key] = false;
}
});
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);
self.$toggles.splice(index, 1);
};
self.$unregisterTarget = function(element) {
var index = self.$targets.indexOf(element);
self.$targets.splice(index, 1);
if (self.$options.allowMultiple) {
deactivateItem(element);
}
fixActiveItemIndexes(index);
self.$viewChangeListeners.forEach(function(fn) {
fn();
});
};
self.$targets.$active = !self.$options.startCollapsed ? [ 0 ] : [];
self.$setActive = $scope.$setActive = function(value) {
if (angular.isArray(value)) {
self.$targets.$active = value;
} else if (!self.$options.disallowToggle && isActive(value)) {
deactivateItem(value);
} else {
activateItem(value);
}
self.$viewChangeListeners.forEach(function(fn) {
fn();
});
};
self.$activeIndexes = function() {
if (self.$options.allowMultiple) {
return self.$targets.$active;
}
return self.$targets.$active.length === 1 ? self.$targets.$active[0] : -1;
};
function fixActiveItemIndexes(index) {
var activeIndexes = self.$targets.$active;
for (var i = 0; i < activeIndexes.length; i++) {
if (index < activeIndexes[i]) {
activeIndexes[i] = activeIndexes[i] - 1;
}
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;
}
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) {
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) {
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) {
bsCollapseCtrl.$viewChangeListeners.push(function() {
ngModelCtrl.$setViewValue(bsCollapseCtrl.$activeIndexes());
});
ngModelCtrl.$formatters.push(function(modelValue) {
if (angular.isArray(modelValue)) {
bsCollapseCtrl.$setActive(modelValue);
} else {
var activeIndexes = bsCollapseCtrl.$activeIndexes();
if (angular.isArray(activeIndexes)) {
if (activeIndexes.indexOf(modelValue * 1) === -1) {
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 bsCollapseCtrl = controllers[1];
element.attr('data-toggle', 'collapse');
bsCollapseCtrl.$registerToggle(element);
scope.$on('$destroy', function() {
bsCollapseCtrl.$unregisterToggle(element);
});
element.on('click', function() {
if (!attrs.disabled) {
var index = attrs.bsCollapseToggle && attrs.bsCollapseToggle !== 'bs-collapse-toggle' ? attrs.bsCollapseToggle : bsCollapseCtrl.$toggles.indexOf(element);
bsCollapseCtrl.$setActive(index * 1);
scope.$apply();
}
});
}
};
}).directive('bsCollapseTarget', [ '$animate', function($animate) {
return {
require: [ '^?ngModel', '^bsCollapse' ],
link: function postLink(scope, element, attrs, controllers) {
var bsCollapseCtrl = controllers[1];
element.addClass('collapse');
if (bsCollapseCtrl.$options.animation) {
element.addClass(bsCollapseCtrl.$options.animation);
}
bsCollapseCtrl.$registerTarget(element);
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();
}
};
} ]);
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;
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);
}
var hasExoticValues = typeof trueValue !== 'boolean' || typeof falseValue !== 'boolean';
if (hasExoticValues) {
controller.$parsers.push(function(viewValue) {
return viewValue ? trueValue : falseValue;
});
controller.$formatters.push(function(modelValue) {
return angular.equals(modelValue, trueValue);
});
scope.$watch(attr.ngModel, function(newValue, oldValue) {
controller.$render();
});
}
controller.$render = function() {
var isActive = angular.equals(controller.$modelValue, trueValue);
$$rAF(function() {
if (isInput) element[0].checked = isActive;
activeElement.toggleClass(options.activeClass, isActive);
});
};
element.bind(options.toggleEvent, function() {
scope.$apply(function() {
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;
var isInput = element[0].nodeName === 'INPUT';
var activeElement = isInput ? element.parent() : element;
var value;
attr.$observe('value', function(v) {
if (typeof v !== 'boolean' && constantValueRegExp.test(v)) {
value = scope.$eval(v);
} else {
value = v;
}
controller.$render();
});
controller.$render = function() {
var isActive = angular.equals(controller.$modelValue, value);
$$rAF(function() {
if (isInput) element[0].checked = isActive;
activeElement.toggleClass(options.activeClass, isActive);
});
};
element.bind(options.toggleEvent, function() {
scope.$apply(function() {
controller.$setViewValue(value);
controller.$render();
});
});
}
};
} ]);
angular.module('mgcrea.ngStrap.alert', [ 'mgcrea.ngStrap.modal' ]).provider('$alert', function() {
var defaults = this.defaults = {
animation: 'am-fade',
prefixClass: 'alert',
prefixEvent: 'alert',
placement: null,
templateUrl: 'alert/alert.tpl.html',
container: false,
element: null,
backdrop: false,
keyboard: true,
show: true,
duration: false,
type: false,
dismissable: true
};
this.$get = [ '$modal', '$timeout', function($modal, $timeout) {
function AlertFactory(config) {
var $alert = {};
var options = angular.extend({}, defaults, config);
$alert = $modal(options);
$alert.$scope.dismissable = !!options.dismissable;
if (options.type) {
$alert.$scope.type = options.type;
}
var show = $alert.show;
if (options.duration) {
$alert.show = function() {
show();
$timeout(function() {
$alert.hide();
}, options.duration * 1e3);
};
}
return $alert;
}
return AlertFactory;
} ];
}).directive('bsAlert', [ '$window', '$sce', '$alert', function($window, $sce, $alert) {
return {
restrict: 'EAC',
scope: true,
link: function postLink(scope, element, attr, transclusion) {
var options = {
scope: scope,
element: element,
show: false
};
angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'placement', 'keyboard', 'html', 'container', 'animation', 'duration', 'dismissable' ], function(key) {
if (angular.isDefined(attr[key])) options[key] = attr[key];
});
var falseValueRegExp = /^(false|0|)$/i;
angular.forEach([ 'keyboard', 'html', 'container', 'dismissable' ], function(key) {
if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) options[key] = false;
});
if (!scope.hasOwnProperty('title')) {
scope.title = '';
}
angular.forEach([ 'title', 'content', 'type' ], function(key) {
if (attr[key]) {
attr.$observe(key, function(newValue, oldValue) {
scope[key] = $sce.trustAsHtml(newValue);
});
}
});
if (attr.bsAlert) {
scope.$watch(attr.bsAlert, function(newValue, oldValue) {
if (angular.isObject(newValue)) {
angular.extend(scope, newValue);
} else {
scope.content = newValue;
}
}, true);
}
var alert = $alert(options);
element.on(attr.trigger || 'click', alert.toggle);
scope.$on('$destroy', function() {
if (alert) alert.destroy();
options = null;
alert = null;
});
}
};
} ]);
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',
templateUrl: '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 = {};
var options = angular.extend({}, defaults, config);
$aside = $modal(options);
return $aside;
}
return AsideFactory;
} ];
}).directive('bsAside', [ '$window', '$sce', '$aside', function($window, $sce, $aside) {
return {
restrict: 'EAC',
scope: true,
link: function postLink(scope, element, attr, transclusion) {
var options = {
scope: scope,
element: element,
show: false
};
angular.forEach([ 'template', 'templateUrl', 'controller', 'controllerAs', 'contentTemplate', 'placement', 'backdrop', 'keyboard', 'html', 'container', 'animation' ], function(key) {
if (angular.isDefined(attr[key])) options[key] = attr[key];
});
var falseValueRegExp = /^(false|0|)$/i;
angular.forEach([ 'backdrop', 'keyboard', 'html', 'container' ], function(key) {
if (angular.isDefined(attr[key]) && falseValueRegExp.test(attr[key])) options[key] = false;
});
angular.forEach([ 'title', 'content' ], function(key) {
if (attr[key]) {
attr.$observe(key, function(newValue, oldValue) {
scope[key] = $sce.trustAsHtml(newValue);
});
}
});
if (attr.bsAside) {
scope.$watch(attr.bsAside, function(newValue, oldValue) {
if (angular.isObject(newValue)) {
angular.extend(scope, newValue);
} else {
scope.content = newValue;
}
}, true);
}
var aside = $aside(options);
element.on(attr.trigger || 'click', aside.toggle);
scope.$on('$destroy', function() {
if (aside) aside.destroy();
options = null;
aside = null;
});
}
};
} ]);
angular.module('mgcrea.ngStrap.affix', [ 'mgcrea.ngStrap.helpers.dimensions', 'mgcrea.ngStrap.helpers.debounce' ]).provider('$affix', function() {
var defaults = this.defaults = {
offsetTop: 'auto',
inlineStyles: true
};
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 = {};
var options = angular.extend({}, defaults, config);
var targetEl = options.target;
var reset = 'affix affix-top affix-bottom';
var setWidth = false;
var initialAffixTop = 0;
var initialOffsetTop = 0;
var offsetTop = 0;
var offsetBottom = 0;
var affixed = null;
var unpin = null;
var parent = element.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;
targetEl.on('scroll', this.checkPosition);
targetEl.on('click', this.checkPositionWithEventLoop);
windowEl.on('resize', this.$debouncedOnResize);
this.checkPosition();
this.checkPositionWithEventLoop();
};
$affix.destroy = function() {
targetEl.off('scroll', this.checkPosition);
targetEl.off('click', this.checkPositionWithEventLoop);
windowEl.off('resize', this.$debouncedOnResize);
};
$affix.checkPositionWithEventLoop = function() {
setTimeout($affix.checkPosition, 1);
};
$affix.checkPosition = function() {
var scrollTop = getScrollTop();
var position = dimensions.offset(element[0]);
var elementHeight = dimensions.height(element[0]);
var affix = getRequiredAffixClass(unpin, position, elementHeight);
if (affixed === affix) return;
affixed = affix;
if (affix === 'top') {
unpin = null;
if (setWidth) {
element.css('width', '');
}
if (options.inlineStyles) {
element.css('position', options.offsetParent ? '' : 'relative');
element.css('top', '');
}
} else if (affix === 'bottom') {
if (options.offsetUnpin) {
unpin = -(options.offsetUnpin * 1);
} else {
unpin = position.top - scrollTop;
}
if (setWidth) {
element.css('width', '');
}
if (options.inlineStyles) {
element.css('position', options.offsetParent ? '' : 'relative');
element.css('top', options.offsetParent ? '' : bodyEl[0].offsetHeight - offsetBottom - elementHeight - initialOffsetTop + 'px');
}
} else {
unpin = null;
if (setWidth) {
element.css('width', element[0].offsetWidth + 'px');
}
if (options.inlineStyles) {
element.css('position', 'fixed');
element.css('top', initialAffixTop + 'px');
}
}
element.removeClass(reset).addClass('affix' + (affix !== 'middle' ? '-' + affix : ''));
};
$affix.$onResize = function() {
$affix.$parseOffsets();
$affix.checkPosition();
};
$affix.$debouncedOnResize = debounce($affix.$onResize, 50);
$affix.$parseOffsets = function() {
var initialPosition = element.css('position');
if (options.inlineStyles) {
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+$/)) {
offsetBottom = getScrollHeight() - (dimensions.offset(parent[0]).top + dimensions.height(parent[0])) + options.offsetBottom * 1 + 1;
} else {
offsetBottom = options.offsetBottom * 1;
}
}
if (options.inlineStyles) {
element.css('position', initialPosition);
}
};
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';
}
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,
target: affixTarget ? affixTarget.$element : angular.element($window)
};
angular.forEach([ 'offsetTop', 'offsetBottom', 'offsetParent', 'offsetUnpin', 'inlineStyles' ], function(key) {
if (angular.isDefined(attr[key])) {
var option = attr[key];
if (/true/i.test(option)) option = true;
if (/false/i.test(option)) option = false;
options[key] = option;
}
});
var affix = $affix(element, options);
scope.$on('$destroy', function() {
if (affix) affix.destroy();
options = null;
affix = null;
});
}
};
} ]).directive('bsAffixTarget', function() {
return {
controller: [ '$element', function($element) {
this.$element = $element;
} ]
};
});
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' ]);
})(window, document);