\n Snippet:
\n
\n \n Filter | \n Source | \n Rendered | \n
\n \n linky filter | \n \n <div ng-bind-html=\"snippet | linky\"> </div> \n | \n \n \n | \n
\n \n linky target | \n \n <div ng-bind-html=\"snippetWithTarget | linky:'_blank'\"> </div> \n | \n \n \n | \n
\n \n no filter | \n <div ng-bind=\"snippet\"> </div> | \n | \n
\n
\n \n
\n it('should linkify the snippet with urls', function() {\n expect(element(by.id('linky-filter')).element(by.binding('snippet | linky')).getText()).\n toBe('Pretty text with some links: http://angularjs.org/, us@somewhere.org, ' +\n 'another@somewhere.org, and one more: ftp://127.0.0.1/.');\n expect(element.all(by.css('#linky-filter a')).count()).toEqual(4);\n });\n\n it('should not linkify snippet without the linky filter', function() {\n expect(element(by.id('escaped-html')).element(by.binding('snippet')).getText()).\n toBe('Pretty text with some links: http://angularjs.org/, mailto:us@somewhere.org, ' +\n 'another@somewhere.org, and one more: ftp://127.0.0.1/.');\n expect(element.all(by.css('#escaped-html a')).count()).toEqual(0);\n });\n\n it('should update', function() {\n element(by.model('snippet')).clear();\n element(by.model('snippet')).sendKeys('new http://link.');\n expect(element(by.id('linky-filter')).element(by.binding('snippet | linky')).getText()).\n toBe('new http://link.');\n expect(element.all(by.css('#linky-filter a')).count()).toEqual(1);\n expect(element(by.id('escaped-html')).element(by.binding('snippet')).getText())\n .toBe('new http://link.');\n });\n\n it('should work with the target property', function() {\n expect(element(by.id('linky-target')).\n element(by.binding(\"snippetWithTarget | linky:'_blank'\")).getText()).\n toBe('http://angularjs.org/');\n expect(element(by.css('#linky-target a')).getAttribute('target')).toEqual('_blank');\n });\n \n \n */\nangular.module('ngSanitize').filter('linky', ['$sanitize', function($sanitize) {\n var LINKY_URL_REGEXP =\n /((ftp|https?):\\/\\/|(www\\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\\S*[^\\s.;,(){}<>\"\\u201d\\u2019]/i,\n MAILTO_REGEXP = /^mailto:/i;\n\n return function(text, target) {\n if (!text) return text;\n var match;\n var raw = text;\n var html = [];\n var url;\n var i;\n while ((match = raw.match(LINKY_URL_REGEXP))) {\n // We can not end in these as they are sometimes found at the end of the sentence\n url = match[0];\n // if we did not match ftp/http/www/mailto then assume mailto\n if (!match[2] && !match[4]) {\n url = (match[3] ? 'http://' : 'mailto:') + url;\n }\n i = match.index;\n addText(raw.substr(0, i));\n addLink(url, match[0].replace(MAILTO_REGEXP, ''));\n raw = raw.substring(i + match[0].length);\n }\n addText(raw);\n return $sanitize(html.join(''));\n\n function addText(text) {\n if (!text) {\n return;\n }\n html.push(sanitizeText(text));\n }\n\n function addLink(url, text) {\n html.push('
');\n addText(text);\n html.push('');\n }\n };\n}]);\n\n\n})(window, window.angular);\n\n//! moment.js\n//! version : 2.9.0\n//! authors : Tim Wood, Iskren Chernev, Moment.js contributors\n//! license : MIT\n//! momentjs.com\n\n(function (undefined) {\n /************************************\n Constants\n ************************************/\n\n var moment,\n VERSION = '2.9.0',\n // the global-scope this is NOT the global object in Node.js\n globalScope = (typeof global !== 'undefined' && (typeof window === 'undefined' || window === global.window)) ? global : this,\n oldGlobalMoment,\n round = Math.round,\n hasOwnProperty = Object.prototype.hasOwnProperty,\n i,\n\n YEAR = 0,\n MONTH = 1,\n DATE = 2,\n HOUR = 3,\n MINUTE = 4,\n SECOND = 5,\n MILLISECOND = 6,\n\n // internal storage for locale config files\n locales = {},\n\n // extra moment internal properties (plugins register props here)\n momentProperties = [],\n\n // check for nodeJS\n hasModule = (typeof module !== 'undefined' && module && module.exports),\n\n // ASP.NET json date format regex\n aspNetJsonRegex = /^\\/?Date\\((\\-?\\d+)/i,\n aspNetTimeSpanJsonRegex = /(\\-)?(?:(\\d*)\\.)?(\\d+)\\:(\\d+)(?:\\:(\\d+)\\.?(\\d{3})?)?/,\n\n // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html\n // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere\n isoDurationRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/,\n\n // format tokens\n formattingTokens = /(\\[[^\\[]*\\])|(\\\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Q|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,4}|x|X|zz?|ZZ?|.)/g,\n localFormattingTokens = /(\\[[^\\[]*\\])|(\\\\)?(LTS|LT|LL?L?L?|l{1,4})/g,\n\n // parsing token regexes\n parseTokenOneOrTwoDigits = /\\d\\d?/, // 0 - 99\n parseTokenOneToThreeDigits = /\\d{1,3}/, // 0 - 999\n parseTokenOneToFourDigits = /\\d{1,4}/, // 0 - 9999\n parseTokenOneToSixDigits = /[+\\-]?\\d{1,6}/, // -999,999 - 999,999\n parseTokenDigits = /\\d+/, // nonzero number of digits\n parseTokenWord = /[0-9]*['a-z\\u00A0-\\u05FF\\u0700-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]+|[\\u0600-\\u06FF\\/]+(\\s*?[\\u0600-\\u06FF]+){1,2}/i, // any word (or two) characters or numbers including two/three word month in arabic.\n parseTokenTimezone = /Z|[\\+\\-]\\d\\d:?\\d\\d/gi, // +00:00 -00:00 +0000 -0000 or Z\n parseTokenT = /T/i, // T (ISO separator)\n parseTokenOffsetMs = /[\\+\\-]?\\d+/, // 1234567890123\n parseTokenTimestampMs = /[\\+\\-]?\\d+(\\.\\d{1,3})?/, // 123456789 123456789.123\n\n //strict parsing regexes\n parseTokenOneDigit = /\\d/, // 0 - 9\n parseTokenTwoDigits = /\\d\\d/, // 00 - 99\n parseTokenThreeDigits = /\\d{3}/, // 000 - 999\n parseTokenFourDigits = /\\d{4}/, // 0000 - 9999\n parseTokenSixDigits = /[+-]?\\d{6}/, // -999,999 - 999,999\n parseTokenSignedNumber = /[+-]?\\d+/, // -inf - inf\n\n // iso 8601 regex\n // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000 or +00)\n isoRegex = /^\\s*(?:[+-]\\d{6}|\\d{4})-(?:(\\d\\d-\\d\\d)|(W\\d\\d$)|(W\\d\\d-\\d)|(\\d\\d\\d))((T| )(\\d\\d(:\\d\\d(:\\d\\d(\\.\\d+)?)?)?)?([\\+\\-]\\d\\d(?::?\\d\\d)?|\\s*Z)?)?$/,\n\n isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',\n\n isoDates = [\n ['YYYYYY-MM-DD', /[+-]\\d{6}-\\d{2}-\\d{2}/],\n ['YYYY-MM-DD', /\\d{4}-\\d{2}-\\d{2}/],\n ['GGGG-[W]WW-E', /\\d{4}-W\\d{2}-\\d/],\n ['GGGG-[W]WW', /\\d{4}-W\\d{2}/],\n ['YYYY-DDD', /\\d{4}-\\d{3}/]\n ],\n\n // iso time formats and regexes\n isoTimes = [\n ['HH:mm:ss.SSSS', /(T| )\\d\\d:\\d\\d:\\d\\d\\.\\d+/],\n ['HH:mm:ss', /(T| )\\d\\d:\\d\\d:\\d\\d/],\n ['HH:mm', /(T| )\\d\\d:\\d\\d/],\n ['HH', /(T| )\\d\\d/]\n ],\n\n // timezone chunker '+10:00' > ['10', '00'] or '-1530' > ['-', '15', '30']\n parseTimezoneChunker = /([\\+\\-]|\\d\\d)/gi,\n\n // getter and setter names\n proxyGettersAndSetters = 'Date|Hours|Minutes|Seconds|Milliseconds'.split('|'),\n unitMillisecondFactors = {\n 'Milliseconds' : 1,\n 'Seconds' : 1e3,\n 'Minutes' : 6e4,\n 'Hours' : 36e5,\n 'Days' : 864e5,\n 'Months' : 2592e6,\n 'Years' : 31536e6\n },\n\n unitAliases = {\n ms : 'millisecond',\n s : 'second',\n m : 'minute',\n h : 'hour',\n d : 'day',\n D : 'date',\n w : 'week',\n W : 'isoWeek',\n M : 'month',\n Q : 'quarter',\n y : 'year',\n DDD : 'dayOfYear',\n e : 'weekday',\n E : 'isoWeekday',\n gg: 'weekYear',\n GG: 'isoWeekYear'\n },\n\n camelFunctions = {\n dayofyear : 'dayOfYear',\n isoweekday : 'isoWeekday',\n isoweek : 'isoWeek',\n weekyear : 'weekYear',\n isoweekyear : 'isoWeekYear'\n },\n\n // format function strings\n formatFunctions = {},\n\n // default relative time thresholds\n relativeTimeThresholds = {\n s: 45, // seconds to minute\n m: 45, // minutes to hour\n h: 22, // hours to day\n d: 26, // days to month\n M: 11 // months to year\n },\n\n // tokens to ordinalize and pad\n ordinalizeTokens = 'DDD w W M D d'.split(' '),\n paddedTokens = 'M D H h m s w W'.split(' '),\n\n formatTokenFunctions = {\n M : function () {\n return this.month() + 1;\n },\n MMM : function (format) {\n return this.localeData().monthsShort(this, format);\n },\n MMMM : function (format) {\n return this.localeData().months(this, format);\n },\n D : function () {\n return this.date();\n },\n DDD : function () {\n return this.dayOfYear();\n },\n d : function () {\n return this.day();\n },\n dd : function (format) {\n return this.localeData().weekdaysMin(this, format);\n },\n ddd : function (format) {\n return this.localeData().weekdaysShort(this, format);\n },\n dddd : function (format) {\n return this.localeData().weekdays(this, format);\n },\n w : function () {\n return this.week();\n },\n W : function () {\n return this.isoWeek();\n },\n YY : function () {\n return leftZeroFill(this.year() % 100, 2);\n },\n YYYY : function () {\n return leftZeroFill(this.year(), 4);\n },\n YYYYY : function () {\n return leftZeroFill(this.year(), 5);\n },\n YYYYYY : function () {\n var y = this.year(), sign = y >= 0 ? '+' : '-';\n return sign + leftZeroFill(Math.abs(y), 6);\n },\n gg : function () {\n return leftZeroFill(this.weekYear() % 100, 2);\n },\n gggg : function () {\n return leftZeroFill(this.weekYear(), 4);\n },\n ggggg : function () {\n return leftZeroFill(this.weekYear(), 5);\n },\n GG : function () {\n return leftZeroFill(this.isoWeekYear() % 100, 2);\n },\n GGGG : function () {\n return leftZeroFill(this.isoWeekYear(), 4);\n },\n GGGGG : function () {\n return leftZeroFill(this.isoWeekYear(), 5);\n },\n e : function () {\n return this.weekday();\n },\n E : function () {\n return this.isoWeekday();\n },\n a : function () {\n return this.localeData().meridiem(this.hours(), this.minutes(), true);\n },\n A : function () {\n return this.localeData().meridiem(this.hours(), this.minutes(), false);\n },\n H : function () {\n return this.hours();\n },\n h : function () {\n return this.hours() % 12 || 12;\n },\n m : function () {\n return this.minutes();\n },\n s : function () {\n return this.seconds();\n },\n S : function () {\n return toInt(this.milliseconds() / 100);\n },\n SS : function () {\n return leftZeroFill(toInt(this.milliseconds() / 10), 2);\n },\n SSS : function () {\n return leftZeroFill(this.milliseconds(), 3);\n },\n SSSS : function () {\n return leftZeroFill(this.milliseconds(), 3);\n },\n Z : function () {\n var a = this.utcOffset(),\n b = '+';\n if (a < 0) {\n a = -a;\n b = '-';\n }\n return b + leftZeroFill(toInt(a / 60), 2) + ':' + leftZeroFill(toInt(a) % 60, 2);\n },\n ZZ : function () {\n var a = this.utcOffset(),\n b = '+';\n if (a < 0) {\n a = -a;\n b = '-';\n }\n return b + leftZeroFill(toInt(a / 60), 2) + leftZeroFill(toInt(a) % 60, 2);\n },\n z : function () {\n return this.zoneAbbr();\n },\n zz : function () {\n return this.zoneName();\n },\n x : function () {\n return this.valueOf();\n },\n X : function () {\n return this.unix();\n },\n Q : function () {\n return this.quarter();\n }\n },\n\n deprecations = {},\n\n lists = ['months', 'monthsShort', 'weekdays', 'weekdaysShort', 'weekdaysMin'],\n\n updateInProgress = false;\n\n // Pick the first defined of two or three arguments. dfl comes from\n // default.\n function dfl(a, b, c) {\n switch (arguments.length) {\n case 2: return a != null ? a : b;\n case 3: return a != null ? a : b != null ? b : c;\n default: throw new Error('Implement me');\n }\n }\n\n function hasOwnProp(a, b) {\n return hasOwnProperty.call(a, b);\n }\n\n function defaultParsingFlags() {\n // We need to deep clone this object, and es5 standard is not very\n // helpful.\n return {\n empty : false,\n unusedTokens : [],\n unusedInput : [],\n overflow : -2,\n charsLeftOver : 0,\n nullInput : false,\n invalidMonth : null,\n invalidFormat : false,\n userInvalidated : false,\n iso: false\n };\n }\n\n function printMsg(msg) {\n if (moment.suppressDeprecationWarnings === false &&\n typeof console !== 'undefined' && console.warn) {\n console.warn('Deprecation warning: ' + msg);\n }\n }\n\n function deprecate(msg, fn) {\n var firstTime = true;\n return extend(function () {\n if (firstTime) {\n printMsg(msg);\n firstTime = false;\n }\n return fn.apply(this, arguments);\n }, fn);\n }\n\n function deprecateSimple(name, msg) {\n if (!deprecations[name]) {\n printMsg(msg);\n deprecations[name] = true;\n }\n }\n\n function padToken(func, count) {\n return function (a) {\n return leftZeroFill(func.call(this, a), count);\n };\n }\n function ordinalizeToken(func, period) {\n return function (a) {\n return this.localeData().ordinal(func.call(this, a), period);\n };\n }\n\n function monthDiff(a, b) {\n // difference in months\n var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),\n // b is in (anchor - 1 month, anchor + 1 month)\n anchor = a.clone().add(wholeMonthDiff, 'months'),\n anchor2, adjust;\n\n if (b - anchor < 0) {\n anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');\n // linear across the month\n adjust = (b - anchor) / (anchor - anchor2);\n } else {\n anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');\n // linear across the month\n adjust = (b - anchor) / (anchor2 - anchor);\n }\n\n return -(wholeMonthDiff + adjust);\n }\n\n while (ordinalizeTokens.length) {\n i = ordinalizeTokens.pop();\n formatTokenFunctions[i + 'o'] = ordinalizeToken(formatTokenFunctions[i], i);\n }\n while (paddedTokens.length) {\n i = paddedTokens.pop();\n formatTokenFunctions[i + i] = padToken(formatTokenFunctions[i], 2);\n }\n formatTokenFunctions.DDDD = padToken(formatTokenFunctions.DDD, 3);\n\n\n function meridiemFixWrap(locale, hour, meridiem) {\n var isPm;\n\n if (meridiem == null) {\n // nothing to do\n return hour;\n }\n if (locale.meridiemHour != null) {\n return locale.meridiemHour(hour, meridiem);\n } else if (locale.isPM != null) {\n // Fallback\n isPm = locale.isPM(meridiem);\n if (isPm && hour < 12) {\n hour += 12;\n }\n if (!isPm && hour === 12) {\n hour = 0;\n }\n return hour;\n } else {\n // thie is not supposed to happen\n return hour;\n }\n }\n\n /************************************\n Constructors\n ************************************/\n\n function Locale() {\n }\n\n // Moment prototype object\n function Moment(config, skipOverflow) {\n if (skipOverflow !== false) {\n checkOverflow(config);\n }\n copyConfig(this, config);\n this._d = new Date(+config._d);\n // Prevent infinite loop in case updateOffset creates new moment\n // objects.\n if (updateInProgress === false) {\n updateInProgress = true;\n moment.updateOffset(this);\n updateInProgress = false;\n }\n }\n\n // Duration Constructor\n function Duration(duration) {\n var normalizedInput = normalizeObjectUnits(duration),\n years = normalizedInput.year || 0,\n quarters = normalizedInput.quarter || 0,\n months = normalizedInput.month || 0,\n weeks = normalizedInput.week || 0,\n days = normalizedInput.day || 0,\n hours = normalizedInput.hour || 0,\n minutes = normalizedInput.minute || 0,\n seconds = normalizedInput.second || 0,\n milliseconds = normalizedInput.millisecond || 0;\n\n // representation for dateAddRemove\n this._milliseconds = +milliseconds +\n seconds * 1e3 + // 1000\n minutes * 6e4 + // 1000 * 60\n hours * 36e5; // 1000 * 60 * 60\n // Because of dateAddRemove treats 24 hours as different from a\n // day when working around DST, we need to store them separately\n this._days = +days +\n weeks * 7;\n // It is impossible translate months into days without knowing\n // which months you are are talking about, so we have to store\n // it separately.\n this._months = +months +\n quarters * 3 +\n years * 12;\n\n this._data = {};\n\n this._locale = moment.localeData();\n\n this._bubble();\n }\n\n /************************************\n Helpers\n ************************************/\n\n\n function extend(a, b) {\n for (var i in b) {\n if (hasOwnProp(b, i)) {\n a[i] = b[i];\n }\n }\n\n if (hasOwnProp(b, 'toString')) {\n a.toString = b.toString;\n }\n\n if (hasOwnProp(b, 'valueOf')) {\n a.valueOf = b.valueOf;\n }\n\n return a;\n }\n\n function copyConfig(to, from) {\n var i, prop, val;\n\n if (typeof from._isAMomentObject !== 'undefined') {\n to._isAMomentObject = from._isAMomentObject;\n }\n if (typeof from._i !== 'undefined') {\n to._i = from._i;\n }\n if (typeof from._f !== 'undefined') {\n to._f = from._f;\n }\n if (typeof from._l !== 'undefined') {\n to._l = from._l;\n }\n if (typeof from._strict !== 'undefined') {\n to._strict = from._strict;\n }\n if (typeof from._tzm !== 'undefined') {\n to._tzm = from._tzm;\n }\n if (typeof from._isUTC !== 'undefined') {\n to._isUTC = from._isUTC;\n }\n if (typeof from._offset !== 'undefined') {\n to._offset = from._offset;\n }\n if (typeof from._pf !== 'undefined') {\n to._pf = from._pf;\n }\n if (typeof from._locale !== 'undefined') {\n to._locale = from._locale;\n }\n\n if (momentProperties.length > 0) {\n for (i in momentProperties) {\n prop = momentProperties[i];\n val = from[prop];\n if (typeof val !== 'undefined') {\n to[prop] = val;\n }\n }\n }\n\n return to;\n }\n\n function absRound(number) {\n if (number < 0) {\n return Math.ceil(number);\n } else {\n return Math.floor(number);\n }\n }\n\n // left zero fill a number\n // see http://jsperf.com/left-zero-filling for performance comparison\n function leftZeroFill(number, targetLength, forceSign) {\n var output = '' + Math.abs(number),\n sign = number >= 0;\n\n while (output.length < targetLength) {\n output = '0' + output;\n }\n return (sign ? (forceSign ? '+' : '') : '-') + output;\n }\n\n function positiveMomentsDifference(base, other) {\n var res = {milliseconds: 0, months: 0};\n\n res.months = other.month() - base.month() +\n (other.year() - base.year()) * 12;\n if (base.clone().add(res.months, 'M').isAfter(other)) {\n --res.months;\n }\n\n res.milliseconds = +other - +(base.clone().add(res.months, 'M'));\n\n return res;\n }\n\n function momentsDifference(base, other) {\n var res;\n other = makeAs(other, base);\n if (base.isBefore(other)) {\n res = positiveMomentsDifference(base, other);\n } else {\n res = positiveMomentsDifference(other, base);\n res.milliseconds = -res.milliseconds;\n res.months = -res.months;\n }\n\n return res;\n }\n\n // TODO: remove 'name' arg after deprecation is removed\n function createAdder(direction, name) {\n return function (val, period) {\n var dur, tmp;\n //invert the arguments, but complain about it\n if (period !== null && !isNaN(+period)) {\n deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');\n tmp = val; val = period; period = tmp;\n }\n\n val = typeof val === 'string' ? +val : val;\n dur = moment.duration(val, period);\n addOrSubtractDurationFromMoment(this, dur, direction);\n return this;\n };\n }\n\n function addOrSubtractDurationFromMoment(mom, duration, isAdding, updateOffset) {\n var milliseconds = duration._milliseconds,\n days = duration._days,\n months = duration._months;\n updateOffset = updateOffset == null ? true : updateOffset;\n\n if (milliseconds) {\n mom._d.setTime(+mom._d + milliseconds * isAdding);\n }\n if (days) {\n rawSetter(mom, 'Date', rawGetter(mom, 'Date') + days * isAdding);\n }\n if (months) {\n rawMonthSetter(mom, rawGetter(mom, 'Month') + months * isAdding);\n }\n if (updateOffset) {\n moment.updateOffset(mom, days || months);\n }\n }\n\n // check if is an array\n function isArray(input) {\n return Object.prototype.toString.call(input) === '[object Array]';\n }\n\n function isDate(input) {\n return Object.prototype.toString.call(input) === '[object Date]' ||\n input instanceof Date;\n }\n\n // compare two arrays, return the number of differences\n function compareArrays(array1, array2, dontConvert) {\n var len = Math.min(array1.length, array2.length),\n lengthDiff = Math.abs(array1.length - array2.length),\n diffs = 0,\n i;\n for (i = 0; i < len; i++) {\n if ((dontConvert && array1[i] !== array2[i]) ||\n (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {\n diffs++;\n }\n }\n return diffs + lengthDiff;\n }\n\n function normalizeUnits(units) {\n if (units) {\n var lowered = units.toLowerCase().replace(/(.)s$/, '$1');\n units = unitAliases[units] || camelFunctions[lowered] || lowered;\n }\n return units;\n }\n\n function normalizeObjectUnits(inputObject) {\n var normalizedInput = {},\n normalizedProp,\n prop;\n\n for (prop in inputObject) {\n if (hasOwnProp(inputObject, prop)) {\n normalizedProp = normalizeUnits(prop);\n if (normalizedProp) {\n normalizedInput[normalizedProp] = inputObject[prop];\n }\n }\n }\n\n return normalizedInput;\n }\n\n function makeList(field) {\n var count, setter;\n\n if (field.indexOf('week') === 0) {\n count = 7;\n setter = 'day';\n }\n else if (field.indexOf('month') === 0) {\n count = 12;\n setter = 'month';\n }\n else {\n return;\n }\n\n moment[field] = function (format, index) {\n var i, getter,\n method = moment._locale[field],\n results = [];\n\n if (typeof format === 'number') {\n index = format;\n format = undefined;\n }\n\n getter = function (i) {\n var m = moment().utc().set(setter, i);\n return method.call(moment._locale, m, format || '');\n };\n\n if (index != null) {\n return getter(index);\n }\n else {\n for (i = 0; i < count; i++) {\n results.push(getter(i));\n }\n return results;\n }\n };\n }\n\n function toInt(argumentForCoercion) {\n var coercedNumber = +argumentForCoercion,\n value = 0;\n\n if (coercedNumber !== 0 && isFinite(coercedNumber)) {\n if (coercedNumber >= 0) {\n value = Math.floor(coercedNumber);\n } else {\n value = Math.ceil(coercedNumber);\n }\n }\n\n return value;\n }\n\n function daysInMonth(year, month) {\n return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();\n }\n\n function weeksInYear(year, dow, doy) {\n return weekOfYear(moment([year, 11, 31 + dow - doy]), dow, doy).week;\n }\n\n function daysInYear(year) {\n return isLeapYear(year) ? 366 : 365;\n }\n\n function isLeapYear(year) {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n }\n\n function checkOverflow(m) {\n var overflow;\n if (m._a && m._pf.overflow === -2) {\n overflow =\n m._a[MONTH] < 0 || m._a[MONTH] > 11 ? MONTH :\n m._a[DATE] < 1 || m._a[DATE] > daysInMonth(m._a[YEAR], m._a[MONTH]) ? DATE :\n m._a[HOUR] < 0 || m._a[HOUR] > 24 ||\n (m._a[HOUR] === 24 && (m._a[MINUTE] !== 0 ||\n m._a[SECOND] !== 0 ||\n m._a[MILLISECOND] !== 0)) ? HOUR :\n m._a[MINUTE] < 0 || m._a[MINUTE] > 59 ? MINUTE :\n m._a[SECOND] < 0 || m._a[SECOND] > 59 ? SECOND :\n m._a[MILLISECOND] < 0 || m._a[MILLISECOND] > 999 ? MILLISECOND :\n -1;\n\n if (m._pf._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {\n overflow = DATE;\n }\n\n m._pf.overflow = overflow;\n }\n }\n\n function isValid(m) {\n if (m._isValid == null) {\n m._isValid = !isNaN(m._d.getTime()) &&\n m._pf.overflow < 0 &&\n !m._pf.empty &&\n !m._pf.invalidMonth &&\n !m._pf.nullInput &&\n !m._pf.invalidFormat &&\n !m._pf.userInvalidated;\n\n if (m._strict) {\n m._isValid = m._isValid &&\n m._pf.charsLeftOver === 0 &&\n m._pf.unusedTokens.length === 0 &&\n m._pf.bigHour === undefined;\n }\n }\n return m._isValid;\n }\n\n function normalizeLocale(key) {\n return key ? key.toLowerCase().replace('_', '-') : key;\n }\n\n // pick the locale from the array\n // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each\n // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root\n function chooseLocale(names) {\n var i = 0, j, next, locale, split;\n\n while (i < names.length) {\n split = normalizeLocale(names[i]).split('-');\n j = split.length;\n next = normalizeLocale(names[i + 1]);\n next = next ? next.split('-') : null;\n while (j > 0) {\n locale = loadLocale(split.slice(0, j).join('-'));\n if (locale) {\n return locale;\n }\n if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {\n //the next array item is better than a shallower substring of this one\n break;\n }\n j--;\n }\n i++;\n }\n return null;\n }\n\n function loadLocale(name) {\n var oldLocale = null;\n if (!locales[name] && hasModule) {\n try {\n oldLocale = moment.locale();\n require('./locale/' + name);\n // because defineLocale currently also sets the global locale, we want to undo that for lazy loaded locales\n moment.locale(oldLocale);\n } catch (e) { }\n }\n return locales[name];\n }\n\n // Return a moment from input, that is local/utc/utcOffset equivalent to\n // model.\n function makeAs(input, model) {\n var res, diff;\n if (model._isUTC) {\n res = model.clone();\n diff = (moment.isMoment(input) || isDate(input) ?\n +input : +moment(input)) - (+res);\n // Use low-level api, because this fn is low-level api.\n res._d.setTime(+res._d + diff);\n moment.updateOffset(res, false);\n return res;\n } else {\n return moment(input).local();\n }\n }\n\n /************************************\n Locale\n ************************************/\n\n\n extend(Locale.prototype, {\n\n set : function (config) {\n var prop, i;\n for (i in config) {\n prop = config[i];\n if (typeof prop === 'function') {\n this[i] = prop;\n } else {\n this['_' + i] = prop;\n }\n }\n // Lenient ordinal parsing accepts just a number in addition to\n // number + (possibly) stuff coming from _ordinalParseLenient.\n this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + /\\d{1,2}/.source);\n },\n\n _months : 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),\n months : function (m) {\n return this._months[m.month()];\n },\n\n _monthsShort : 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_'),\n monthsShort : function (m) {\n return this._monthsShort[m.month()];\n },\n\n monthsParse : function (monthName, format, strict) {\n var i, mom, regex;\n\n if (!this._monthsParse) {\n this._monthsParse = [];\n this._longMonthsParse = [];\n this._shortMonthsParse = [];\n }\n\n for (i = 0; i < 12; i++) {\n // make the regex if we don't have it already\n mom = moment.utc([2000, i]);\n if (strict && !this._longMonthsParse[i]) {\n this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');\n this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');\n }\n if (!strict && !this._monthsParse[i]) {\n regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');\n this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');\n }\n // test the regex\n if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {\n return i;\n } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {\n return i;\n } else if (!strict && this._monthsParse[i].test(monthName)) {\n return i;\n }\n }\n },\n\n _weekdays : 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),\n weekdays : function (m) {\n return this._weekdays[m.day()];\n },\n\n _weekdaysShort : 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),\n weekdaysShort : function (m) {\n return this._weekdaysShort[m.day()];\n },\n\n _weekdaysMin : 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),\n weekdaysMin : function (m) {\n return this._weekdaysMin[m.day()];\n },\n\n weekdaysParse : function (weekdayName) {\n var i, mom, regex;\n\n if (!this._weekdaysParse) {\n this._weekdaysParse = [];\n }\n\n for (i = 0; i < 7; i++) {\n // make the regex if we don't have it already\n if (!this._weekdaysParse[i]) {\n mom = moment([2000, 1]).day(i);\n regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');\n this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');\n }\n // test the regex\n if (this._weekdaysParse[i].test(weekdayName)) {\n return i;\n }\n }\n },\n\n _longDateFormat : {\n LTS : 'h:mm:ss A',\n LT : 'h:mm A',\n L : 'MM/DD/YYYY',\n LL : 'MMMM D, YYYY',\n LLL : 'MMMM D, YYYY LT',\n LLLL : 'dddd, MMMM D, YYYY LT'\n },\n longDateFormat : function (key) {\n var output = this._longDateFormat[key];\n if (!output && this._longDateFormat[key.toUpperCase()]) {\n output = this._longDateFormat[key.toUpperCase()].replace(/MMMM|MM|DD|dddd/g, function (val) {\n return val.slice(1);\n });\n this._longDateFormat[key] = output;\n }\n return output;\n },\n\n isPM : function (input) {\n // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays\n // Using charAt should be more compatible.\n return ((input + '').toLowerCase().charAt(0) === 'p');\n },\n\n _meridiemParse : /[ap]\\.?m?\\.?/i,\n meridiem : function (hours, minutes, isLower) {\n if (hours > 11) {\n return isLower ? 'pm' : 'PM';\n } else {\n return isLower ? 'am' : 'AM';\n }\n },\n\n\n _calendar : {\n sameDay : '[Today at] LT',\n nextDay : '[Tomorrow at] LT',\n nextWeek : 'dddd [at] LT',\n lastDay : '[Yesterday at] LT',\n lastWeek : '[Last] dddd [at] LT',\n sameElse : 'L'\n },\n calendar : function (key, mom, now) {\n var output = this._calendar[key];\n return typeof output === 'function' ? output.apply(mom, [now]) : output;\n },\n\n _relativeTime : {\n future : 'in %s',\n past : '%s ago',\n s : 'a few seconds',\n m : 'a minute',\n mm : '%d minutes',\n h : 'an hour',\n hh : '%d hours',\n d : 'a day',\n dd : '%d days',\n M : 'a month',\n MM : '%d months',\n y : 'a year',\n yy : '%d years'\n },\n\n relativeTime : function (number, withoutSuffix, string, isFuture) {\n var output = this._relativeTime[string];\n return (typeof output === 'function') ?\n output(number, withoutSuffix, string, isFuture) :\n output.replace(/%d/i, number);\n },\n\n pastFuture : function (diff, output) {\n var format = this._relativeTime[diff > 0 ? 'future' : 'past'];\n return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);\n },\n\n ordinal : function (number) {\n return this._ordinal.replace('%d', number);\n },\n _ordinal : '%d',\n _ordinalParse : /\\d{1,2}/,\n\n preparse : function (string) {\n return string;\n },\n\n postformat : function (string) {\n return string;\n },\n\n week : function (mom) {\n return weekOfYear(mom, this._week.dow, this._week.doy).week;\n },\n\n _week : {\n dow : 0, // Sunday is the first day of the week.\n doy : 6 // The week that contains Jan 1st is the first week of the year.\n },\n\n firstDayOfWeek : function () {\n return this._week.dow;\n },\n\n firstDayOfYear : function () {\n return this._week.doy;\n },\n\n _invalidDate: 'Invalid date',\n invalidDate: function () {\n return this._invalidDate;\n }\n });\n\n /************************************\n Formatting\n ************************************/\n\n\n function removeFormattingTokens(input) {\n if (input.match(/\\[[\\s\\S]/)) {\n return input.replace(/^\\[|\\]$/g, '');\n }\n return input.replace(/\\\\/g, '');\n }\n\n function makeFormatFunction(format) {\n var array = format.match(formattingTokens), i, length;\n\n for (i = 0, length = array.length; i < length; i++) {\n if (formatTokenFunctions[array[i]]) {\n array[i] = formatTokenFunctions[array[i]];\n } else {\n array[i] = removeFormattingTokens(array[i]);\n }\n }\n\n return function (mom) {\n var output = '';\n for (i = 0; i < length; i++) {\n output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];\n }\n return output;\n };\n }\n\n // format date using native date object\n function formatMoment(m, format) {\n if (!m.isValid()) {\n return m.localeData().invalidDate();\n }\n\n format = expandFormat(format, m.localeData());\n\n if (!formatFunctions[format]) {\n formatFunctions[format] = makeFormatFunction(format);\n }\n\n return formatFunctions[format](m);\n }\n\n function expandFormat(format, locale) {\n var i = 5;\n\n function replaceLongDateFormatTokens(input) {\n return locale.longDateFormat(input) || input;\n }\n\n localFormattingTokens.lastIndex = 0;\n while (i >= 0 && localFormattingTokens.test(format)) {\n format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);\n localFormattingTokens.lastIndex = 0;\n i -= 1;\n }\n\n return format;\n }\n\n\n /************************************\n Parsing\n ************************************/\n\n\n // get the regex to find the next token\n function getParseRegexForToken(token, config) {\n var a, strict = config._strict;\n switch (token) {\n case 'Q':\n return parseTokenOneDigit;\n case 'DDDD':\n return parseTokenThreeDigits;\n case 'YYYY':\n case 'GGGG':\n case 'gggg':\n return strict ? parseTokenFourDigits : parseTokenOneToFourDigits;\n case 'Y':\n case 'G':\n case 'g':\n return parseTokenSignedNumber;\n case 'YYYYYY':\n case 'YYYYY':\n case 'GGGGG':\n case 'ggggg':\n return strict ? parseTokenSixDigits : parseTokenOneToSixDigits;\n case 'S':\n if (strict) {\n return parseTokenOneDigit;\n }\n /* falls through */\n case 'SS':\n if (strict) {\n return parseTokenTwoDigits;\n }\n /* falls through */\n case 'SSS':\n if (strict) {\n return parseTokenThreeDigits;\n }\n /* falls through */\n case 'DDD':\n return parseTokenOneToThreeDigits;\n case 'MMM':\n case 'MMMM':\n case 'dd':\n case 'ddd':\n case 'dddd':\n return parseTokenWord;\n case 'a':\n case 'A':\n return config._locale._meridiemParse;\n case 'x':\n return parseTokenOffsetMs;\n case 'X':\n return parseTokenTimestampMs;\n case 'Z':\n case 'ZZ':\n return parseTokenTimezone;\n case 'T':\n return parseTokenT;\n case 'SSSS':\n return parseTokenDigits;\n case 'MM':\n case 'DD':\n case 'YY':\n case 'GG':\n case 'gg':\n case 'HH':\n case 'hh':\n case 'mm':\n case 'ss':\n case 'ww':\n case 'WW':\n return strict ? parseTokenTwoDigits : parseTokenOneOrTwoDigits;\n case 'M':\n case 'D':\n case 'd':\n case 'H':\n case 'h':\n case 'm':\n case 's':\n case 'w':\n case 'W':\n case 'e':\n case 'E':\n return parseTokenOneOrTwoDigits;\n case 'Do':\n return strict ? config._locale._ordinalParse : config._locale._ordinalParseLenient;\n default :\n a = new RegExp(regexpEscape(unescapeFormat(token.replace('\\\\', '')), 'i'));\n return a;\n }\n }\n\n function utcOffsetFromString(string) {\n string = string || '';\n var possibleTzMatches = (string.match(parseTokenTimezone) || []),\n tzChunk = possibleTzMatches[possibleTzMatches.length - 1] || [],\n parts = (tzChunk + '').match(parseTimezoneChunker) || ['-', 0, 0],\n minutes = +(parts[1] * 60) + toInt(parts[2]);\n\n return parts[0] === '+' ? minutes : -minutes;\n }\n\n // function to convert string input to date\n function addTimeToArrayFromToken(token, input, config) {\n var a, datePartArray = config._a;\n\n switch (token) {\n // QUARTER\n case 'Q':\n if (input != null) {\n datePartArray[MONTH] = (toInt(input) - 1) * 3;\n }\n break;\n // MONTH\n case 'M' : // fall through to MM\n case 'MM' :\n if (input != null) {\n datePartArray[MONTH] = toInt(input) - 1;\n }\n break;\n case 'MMM' : // fall through to MMMM\n case 'MMMM' :\n a = config._locale.monthsParse(input, token, config._strict);\n // if we didn't find a month name, mark the date as invalid.\n if (a != null) {\n datePartArray[MONTH] = a;\n } else {\n config._pf.invalidMonth = input;\n }\n break;\n // DAY OF MONTH\n case 'D' : // fall through to DD\n case 'DD' :\n if (input != null) {\n datePartArray[DATE] = toInt(input);\n }\n break;\n case 'Do' :\n if (input != null) {\n datePartArray[DATE] = toInt(parseInt(\n input.match(/\\d{1,2}/)[0], 10));\n }\n break;\n // DAY OF YEAR\n case 'DDD' : // fall through to DDDD\n case 'DDDD' :\n if (input != null) {\n config._dayOfYear = toInt(input);\n }\n\n break;\n // YEAR\n case 'YY' :\n datePartArray[YEAR] = moment.parseTwoDigitYear(input);\n break;\n case 'YYYY' :\n case 'YYYYY' :\n case 'YYYYYY' :\n datePartArray[YEAR] = toInt(input);\n break;\n // AM / PM\n case 'a' : // fall through to A\n case 'A' :\n config._meridiem = input;\n // config._isPm = config._locale.isPM(input);\n break;\n // HOUR\n case 'h' : // fall through to hh\n case 'hh' :\n config._pf.bigHour = true;\n /* falls through */\n case 'H' : // fall through to HH\n case 'HH' :\n datePartArray[HOUR] = toInt(input);\n break;\n // MINUTE\n case 'm' : // fall through to mm\n case 'mm' :\n datePartArray[MINUTE] = toInt(input);\n break;\n // SECOND\n case 's' : // fall through to ss\n case 'ss' :\n datePartArray[SECOND] = toInt(input);\n break;\n // MILLISECOND\n case 'S' :\n case 'SS' :\n case 'SSS' :\n case 'SSSS' :\n datePartArray[MILLISECOND] = toInt(('0.' + input) * 1000);\n break;\n // UNIX OFFSET (MILLISECONDS)\n case 'x':\n config._d = new Date(toInt(input));\n break;\n // UNIX TIMESTAMP WITH MS\n case 'X':\n config._d = new Date(parseFloat(input) * 1000);\n break;\n // TIMEZONE\n case 'Z' : // fall through to ZZ\n case 'ZZ' :\n config._useUTC = true;\n config._tzm = utcOffsetFromString(input);\n break;\n // WEEKDAY - human\n case 'dd':\n case 'ddd':\n case 'dddd':\n a = config._locale.weekdaysParse(input);\n // if we didn't get a weekday name, mark the date as invalid\n if (a != null) {\n config._w = config._w || {};\n config._w['d'] = a;\n } else {\n config._pf.invalidWeekday = input;\n }\n break;\n // WEEK, WEEK DAY - numeric\n case 'w':\n case 'ww':\n case 'W':\n case 'WW':\n case 'd':\n case 'e':\n case 'E':\n token = token.substr(0, 1);\n /* falls through */\n case 'gggg':\n case 'GGGG':\n case 'GGGGG':\n token = token.substr(0, 2);\n if (input) {\n config._w = config._w || {};\n config._w[token] = toInt(input);\n }\n break;\n case 'gg':\n case 'GG':\n config._w = config._w || {};\n config._w[token] = moment.parseTwoDigitYear(input);\n }\n }\n\n function dayOfYearFromWeekInfo(config) {\n var w, weekYear, week, weekday, dow, doy, temp;\n\n w = config._w;\n if (w.GG != null || w.W != null || w.E != null) {\n dow = 1;\n doy = 4;\n\n // TODO: We need to take the current isoWeekYear, but that depends on\n // how we interpret now (local, utc, fixed offset). So create\n // a now version of current config (take local/utc/offset flags, and\n // create now).\n weekYear = dfl(w.GG, config._a[YEAR], weekOfYear(moment(), 1, 4).year);\n week = dfl(w.W, 1);\n weekday = dfl(w.E, 1);\n } else {\n dow = config._locale._week.dow;\n doy = config._locale._week.doy;\n\n weekYear = dfl(w.gg, config._a[YEAR], weekOfYear(moment(), dow, doy).year);\n week = dfl(w.w, 1);\n\n if (w.d != null) {\n // weekday -- low day numbers are considered next week\n weekday = w.d;\n if (weekday < dow) {\n ++week;\n }\n } else if (w.e != null) {\n // local weekday -- counting starts from begining of week\n weekday = w.e + dow;\n } else {\n // default to begining of week\n weekday = dow;\n }\n }\n temp = dayOfYearFromWeeks(weekYear, week, weekday, doy, dow);\n\n config._a[YEAR] = temp.year;\n config._dayOfYear = temp.dayOfYear;\n }\n\n // convert an array to a date.\n // the array should mirror the parameters below\n // note: all values past the year are optional and will default to the lowest possible value.\n // [year, month, day , hour, minute, second, millisecond]\n function dateFromConfig(config) {\n var i, date, input = [], currentDate, yearToUse;\n\n if (config._d) {\n return;\n }\n\n currentDate = currentDateArray(config);\n\n //compute day of the year from weeks and weekdays\n if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {\n dayOfYearFromWeekInfo(config);\n }\n\n //if the day of the year is set, figure out what it is\n if (config._dayOfYear) {\n yearToUse = dfl(config._a[YEAR], currentDate[YEAR]);\n\n if (config._dayOfYear > daysInYear(yearToUse)) {\n config._pf._overflowDayOfYear = true;\n }\n\n date = makeUTCDate(yearToUse, 0, config._dayOfYear);\n config._a[MONTH] = date.getUTCMonth();\n config._a[DATE] = date.getUTCDate();\n }\n\n // Default to current date.\n // * if no year, month, day of month are given, default to today\n // * if day of month is given, default month and year\n // * if month is given, default only year\n // * if year is given, don't default anything\n for (i = 0; i < 3 && config._a[i] == null; ++i) {\n config._a[i] = input[i] = currentDate[i];\n }\n\n // Zero out whatever was not defaulted, including time\n for (; i < 7; i++) {\n config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];\n }\n\n // Check for 24:00:00.000\n if (config._a[HOUR] === 24 &&\n config._a[MINUTE] === 0 &&\n config._a[SECOND] === 0 &&\n config._a[MILLISECOND] === 0) {\n config._nextDay = true;\n config._a[HOUR] = 0;\n }\n\n config._d = (config._useUTC ? makeUTCDate : makeDate).apply(null, input);\n // Apply timezone offset from input. The actual utcOffset can be changed\n // with parseZone.\n if (config._tzm != null) {\n config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);\n }\n\n if (config._nextDay) {\n config._a[HOUR] = 24;\n }\n }\n\n function dateFromObject(config) {\n var normalizedInput;\n\n if (config._d) {\n return;\n }\n\n normalizedInput = normalizeObjectUnits(config._i);\n config._a = [\n normalizedInput.year,\n normalizedInput.month,\n normalizedInput.day || normalizedInput.date,\n normalizedInput.hour,\n normalizedInput.minute,\n normalizedInput.second,\n normalizedInput.millisecond\n ];\n\n dateFromConfig(config);\n }\n\n function currentDateArray(config) {\n var now = new Date();\n if (config._useUTC) {\n return [\n now.getUTCFullYear(),\n now.getUTCMonth(),\n now.getUTCDate()\n ];\n } else {\n return [now.getFullYear(), now.getMonth(), now.getDate()];\n }\n }\n\n // date from string and format string\n function makeDateFromStringAndFormat(config) {\n if (config._f === moment.ISO_8601) {\n parseISO(config);\n return;\n }\n\n config._a = [];\n config._pf.empty = true;\n\n // This array is used to make a Date, either with `new Date` or `Date.UTC`\n var string = '' + config._i,\n i, parsedInput, tokens, token, skipped,\n stringLength = string.length,\n totalParsedInputLength = 0;\n\n tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];\n\n for (i = 0; i < tokens.length; i++) {\n token = tokens[i];\n parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];\n if (parsedInput) {\n skipped = string.substr(0, string.indexOf(parsedInput));\n if (skipped.length > 0) {\n config._pf.unusedInput.push(skipped);\n }\n string = string.slice(string.indexOf(parsedInput) + parsedInput.length);\n totalParsedInputLength += parsedInput.length;\n }\n // don't parse if it's not a known token\n if (formatTokenFunctions[token]) {\n if (parsedInput) {\n config._pf.empty = false;\n }\n else {\n config._pf.unusedTokens.push(token);\n }\n addTimeToArrayFromToken(token, parsedInput, config);\n }\n else if (config._strict && !parsedInput) {\n config._pf.unusedTokens.push(token);\n }\n }\n\n // add remaining unparsed input length to the string\n config._pf.charsLeftOver = stringLength - totalParsedInputLength;\n if (string.length > 0) {\n config._pf.unusedInput.push(string);\n }\n\n // clear _12h flag if hour is <= 12\n if (config._pf.bigHour === true && config._a[HOUR] <= 12) {\n config._pf.bigHour = undefined;\n }\n // handle meridiem\n config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR],\n config._meridiem);\n dateFromConfig(config);\n checkOverflow(config);\n }\n\n function unescapeFormat(s) {\n return s.replace(/\\\\(\\[)|\\\\(\\])|\\[([^\\]\\[]*)\\]|\\\\(.)/g, function (matched, p1, p2, p3, p4) {\n return p1 || p2 || p3 || p4;\n });\n }\n\n // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript\n function regexpEscape(s) {\n return s.replace(/[-\\/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n }\n\n // date from string and array of format strings\n function makeDateFromStringAndArray(config) {\n var tempConfig,\n bestMoment,\n\n scoreToBeat,\n i,\n currentScore;\n\n if (config._f.length === 0) {\n config._pf.invalidFormat = true;\n config._d = new Date(NaN);\n return;\n }\n\n for (i = 0; i < config._f.length; i++) {\n currentScore = 0;\n tempConfig = copyConfig({}, config);\n if (config._useUTC != null) {\n tempConfig._useUTC = config._useUTC;\n }\n tempConfig._pf = defaultParsingFlags();\n tempConfig._f = config._f[i];\n makeDateFromStringAndFormat(tempConfig);\n\n if (!isValid(tempConfig)) {\n continue;\n }\n\n // if there is any input that was not parsed add a penalty for that format\n currentScore += tempConfig._pf.charsLeftOver;\n\n //or tokens\n currentScore += tempConfig._pf.unusedTokens.length * 10;\n\n tempConfig._pf.score = currentScore;\n\n if (scoreToBeat == null || currentScore < scoreToBeat) {\n scoreToBeat = currentScore;\n bestMoment = tempConfig;\n }\n }\n\n extend(config, bestMoment || tempConfig);\n }\n\n // date from iso format\n function parseISO(config) {\n var i, l,\n string = config._i,\n match = isoRegex.exec(string);\n\n if (match) {\n config._pf.iso = true;\n for (i = 0, l = isoDates.length; i < l; i++) {\n if (isoDates[i][1].exec(string)) {\n // match[5] should be 'T' or undefined\n config._f = isoDates[i][0] + (match[6] || ' ');\n break;\n }\n }\n for (i = 0, l = isoTimes.length; i < l; i++) {\n if (isoTimes[i][1].exec(string)) {\n config._f += isoTimes[i][0];\n break;\n }\n }\n if (string.match(parseTokenTimezone)) {\n config._f += 'Z';\n }\n makeDateFromStringAndFormat(config);\n } else {\n config._isValid = false;\n }\n }\n\n // date from iso format or fallback\n function makeDateFromString(config) {\n parseISO(config);\n if (config._isValid === false) {\n delete config._isValid;\n moment.createFromInputFallback(config);\n }\n }\n\n function map(arr, fn) {\n var res = [], i;\n for (i = 0; i < arr.length; ++i) {\n res.push(fn(arr[i], i));\n }\n return res;\n }\n\n function makeDateFromInput(config) {\n var input = config._i, matched;\n if (input === undefined) {\n config._d = new Date();\n } else if (isDate(input)) {\n config._d = new Date(+input);\n } else if ((matched = aspNetJsonRegex.exec(input)) !== null) {\n config._d = new Date(+matched[1]);\n } else if (typeof input === 'string') {\n makeDateFromString(config);\n } else if (isArray(input)) {\n config._a = map(input.slice(0), function (obj) {\n return parseInt(obj, 10);\n });\n dateFromConfig(config);\n } else if (typeof(input) === 'object') {\n dateFromObject(config);\n } else if (typeof(input) === 'number') {\n // from milliseconds\n config._d = new Date(input);\n } else {\n moment.createFromInputFallback(config);\n }\n }\n\n function makeDate(y, m, d, h, M, s, ms) {\n //can't just apply() to create a date:\n //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply\n var date = new Date(y, m, d, h, M, s, ms);\n\n //the date constructor doesn't accept years < 1970\n if (y < 1970) {\n date.setFullYear(y);\n }\n return date;\n }\n\n function makeUTCDate(y) {\n var date = new Date(Date.UTC.apply(null, arguments));\n if (y < 1970) {\n date.setUTCFullYear(y);\n }\n return date;\n }\n\n function parseWeekday(input, locale) {\n if (typeof input === 'string') {\n if (!isNaN(input)) {\n input = parseInt(input, 10);\n }\n else {\n input = locale.weekdaysParse(input);\n if (typeof input !== 'number') {\n return null;\n }\n }\n }\n return input;\n }\n\n /************************************\n Relative Time\n ************************************/\n\n\n // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize\n function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {\n return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);\n }\n\n function relativeTime(posNegDuration, withoutSuffix, locale) {\n var duration = moment.duration(posNegDuration).abs(),\n seconds = round(duration.as('s')),\n minutes = round(duration.as('m')),\n hours = round(duration.as('h')),\n days = round(duration.as('d')),\n months = round(duration.as('M')),\n years = round(duration.as('y')),\n\n args = seconds < relativeTimeThresholds.s && ['s', seconds] ||\n minutes === 1 && ['m'] ||\n minutes < relativeTimeThresholds.m && ['mm', minutes] ||\n hours === 1 && ['h'] ||\n hours < relativeTimeThresholds.h && ['hh', hours] ||\n days === 1 && ['d'] ||\n days < relativeTimeThresholds.d && ['dd', days] ||\n months === 1 && ['M'] ||\n months < relativeTimeThresholds.M && ['MM', months] ||\n years === 1 && ['y'] || ['yy', years];\n\n args[2] = withoutSuffix;\n args[3] = +posNegDuration > 0;\n args[4] = locale;\n return substituteTimeAgo.apply({}, args);\n }\n\n\n /************************************\n Week of Year\n ************************************/\n\n\n // firstDayOfWeek 0 = sun, 6 = sat\n // the day of the week that starts the week\n // (usually sunday or monday)\n // firstDayOfWeekOfYear 0 = sun, 6 = sat\n // the first week is the week that contains the first\n // of this day of the week\n // (eg. ISO weeks use thursday (4))\n function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {\n var end = firstDayOfWeekOfYear - firstDayOfWeek,\n daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),\n adjustedMoment;\n\n\n if (daysToDayOfWeek > end) {\n daysToDayOfWeek -= 7;\n }\n\n if (daysToDayOfWeek < end - 7) {\n daysToDayOfWeek += 7;\n }\n\n adjustedMoment = moment(mom).add(daysToDayOfWeek, 'd');\n return {\n week: Math.ceil(adjustedMoment.dayOfYear() / 7),\n year: adjustedMoment.year()\n };\n }\n\n //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday\n function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {\n var d = makeUTCDate(year, 0, 1).getUTCDay(), daysToAdd, dayOfYear;\n\n d = d === 0 ? 7 : d;\n weekday = weekday != null ? weekday : firstDayOfWeek;\n daysToAdd = firstDayOfWeek - d + (d > firstDayOfWeekOfYear ? 7 : 0) - (d < firstDayOfWeek ? 7 : 0);\n dayOfYear = 7 * (week - 1) + (weekday - firstDayOfWeek) + daysToAdd + 1;\n\n return {\n year: dayOfYear > 0 ? year : year - 1,\n dayOfYear: dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear\n };\n }\n\n /************************************\n Top Level Functions\n ************************************/\n\n function makeMoment(config) {\n var input = config._i,\n format = config._f,\n res;\n\n config._locale = config._locale || moment.localeData(config._l);\n\n if (input === null || (format === undefined && input === '')) {\n return moment.invalid({nullInput: true});\n }\n\n if (typeof input === 'string') {\n config._i = input = config._locale.preparse(input);\n }\n\n if (moment.isMoment(input)) {\n return new Moment(input, true);\n } else if (format) {\n if (isArray(format)) {\n makeDateFromStringAndArray(config);\n } else {\n makeDateFromStringAndFormat(config);\n }\n } else {\n makeDateFromInput(config);\n }\n\n res = new Moment(config);\n if (res._nextDay) {\n // Adding is smart enough around DST\n res.add(1, 'd');\n res._nextDay = undefined;\n }\n\n return res;\n }\n\n moment = function (input, format, locale, strict) {\n var c;\n\n if (typeof(locale) === 'boolean') {\n strict = locale;\n locale = undefined;\n }\n // object construction must be done this way.\n // https://github.com/moment/moment/issues/1423\n c = {};\n c._isAMomentObject = true;\n c._i = input;\n c._f = format;\n c._l = locale;\n c._strict = strict;\n c._isUTC = false;\n c._pf = defaultParsingFlags();\n\n return makeMoment(c);\n };\n\n moment.suppressDeprecationWarnings = false;\n\n moment.createFromInputFallback = deprecate(\n 'moment construction falls back to js Date. This is ' +\n 'discouraged and will be removed in upcoming major ' +\n 'release. Please refer to ' +\n 'https://github.com/moment/moment/issues/1407 for more info.',\n function (config) {\n config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));\n }\n );\n\n // Pick a moment m from moments so that m[fn](other) is true for all\n // other. This relies on the function fn to be transitive.\n //\n // moments should either be an array of moment objects or an array, whose\n // first element is an array of moment objects.\n function pickBy(fn, moments) {\n var res, i;\n if (moments.length === 1 && isArray(moments[0])) {\n moments = moments[0];\n }\n if (!moments.length) {\n return moment();\n }\n res = moments[0];\n for (i = 1; i < moments.length; ++i) {\n if (moments[i][fn](res)) {\n res = moments[i];\n }\n }\n return res;\n }\n\n moment.min = function () {\n var args = [].slice.call(arguments, 0);\n\n return pickBy('isBefore', args);\n };\n\n moment.max = function () {\n var args = [].slice.call(arguments, 0);\n\n return pickBy('isAfter', args);\n };\n\n // creating with utc\n moment.utc = function (input, format, locale, strict) {\n var c;\n\n if (typeof(locale) === 'boolean') {\n strict = locale;\n locale = undefined;\n }\n // object construction must be done this way.\n // https://github.com/moment/moment/issues/1423\n c = {};\n c._isAMomentObject = true;\n c._useUTC = true;\n c._isUTC = true;\n c._l = locale;\n c._i = input;\n c._f = format;\n c._strict = strict;\n c._pf = defaultParsingFlags();\n\n return makeMoment(c).utc();\n };\n\n // creating with unix timestamp (in seconds)\n moment.unix = function (input) {\n return moment(input * 1000);\n };\n\n // duration\n moment.duration = function (input, key) {\n var duration = input,\n // matching against regexp is expensive, do it on demand\n match = null,\n sign,\n ret,\n parseIso,\n diffRes;\n\n if (moment.isDuration(input)) {\n duration = {\n ms: input._milliseconds,\n d: input._days,\n M: input._months\n };\n } else if (typeof input === 'number') {\n duration = {};\n if (key) {\n duration[key] = input;\n } else {\n duration.milliseconds = input;\n }\n } else if (!!(match = aspNetTimeSpanJsonRegex.exec(input))) {\n sign = (match[1] === '-') ? -1 : 1;\n duration = {\n y: 0,\n d: toInt(match[DATE]) * sign,\n h: toInt(match[HOUR]) * sign,\n m: toInt(match[MINUTE]) * sign,\n s: toInt(match[SECOND]) * sign,\n ms: toInt(match[MILLISECOND]) * sign\n };\n } else if (!!(match = isoDurationRegex.exec(input))) {\n sign = (match[1] === '-') ? -1 : 1;\n parseIso = function (inp) {\n // We'd normally use ~~inp for this, but unfortunately it also\n // converts floats to ints.\n // inp may be undefined, so careful calling replace on it.\n var res = inp && parseFloat(inp.replace(',', '.'));\n // apply sign while we're at it\n return (isNaN(res) ? 0 : res) * sign;\n };\n duration = {\n y: parseIso(match[2]),\n M: parseIso(match[3]),\n d: parseIso(match[4]),\n h: parseIso(match[5]),\n m: parseIso(match[6]),\n s: parseIso(match[7]),\n w: parseIso(match[8])\n };\n } else if (duration == null) {// checks for null or undefined\n duration = {};\n } else if (typeof duration === 'object' &&\n ('from' in duration || 'to' in duration)) {\n diffRes = momentsDifference(moment(duration.from), moment(duration.to));\n\n duration = {};\n duration.ms = diffRes.milliseconds;\n duration.M = diffRes.months;\n }\n\n ret = new Duration(duration);\n\n if (moment.isDuration(input) && hasOwnProp(input, '_locale')) {\n ret._locale = input._locale;\n }\n\n return ret;\n };\n\n // version number\n moment.version = VERSION;\n\n // default format\n moment.defaultFormat = isoFormat;\n\n // constant that refers to the ISO standard\n moment.ISO_8601 = function () {};\n\n // Plugins that add properties should also add the key here (null value),\n // so we can properly clone ourselves.\n moment.momentProperties = momentProperties;\n\n // This function will be called whenever a moment is mutated.\n // It is intended to keep the offset in sync with the timezone.\n moment.updateOffset = function () {};\n\n // This function allows you to set a threshold for relative time strings\n moment.relativeTimeThreshold = function (threshold, limit) {\n if (relativeTimeThresholds[threshold] === undefined) {\n return false;\n }\n if (limit === undefined) {\n return relativeTimeThresholds[threshold];\n }\n relativeTimeThresholds[threshold] = limit;\n return true;\n };\n\n moment.lang = deprecate(\n 'moment.lang is deprecated. Use moment.locale instead.',\n function (key, value) {\n return moment.locale(key, value);\n }\n );\n\n // This function will load locale and then set the global locale. If\n // no arguments are passed in, it will simply return the current global\n // locale key.\n moment.locale = function (key, values) {\n var data;\n if (key) {\n if (typeof(values) !== 'undefined') {\n data = moment.defineLocale(key, values);\n }\n else {\n data = moment.localeData(key);\n }\n\n if (data) {\n moment.duration._locale = moment._locale = data;\n }\n }\n\n return moment._locale._abbr;\n };\n\n moment.defineLocale = function (name, values) {\n if (values !== null) {\n values.abbr = name;\n if (!locales[name]) {\n locales[name] = new Locale();\n }\n locales[name].set(values);\n\n // backwards compat for now: also set the locale\n moment.locale(name);\n\n return locales[name];\n } else {\n // useful for testing\n delete locales[name];\n return null;\n }\n };\n\n moment.langData = deprecate(\n 'moment.langData is deprecated. Use moment.localeData instead.',\n function (key) {\n return moment.localeData(key);\n }\n );\n\n // returns locale data\n moment.localeData = function (key) {\n var locale;\n\n if (key && key._locale && key._locale._abbr) {\n key = key._locale._abbr;\n }\n\n if (!key) {\n return moment._locale;\n }\n\n if (!isArray(key)) {\n //short-circuit everything else\n locale = loadLocale(key);\n if (locale) {\n return locale;\n }\n key = [key];\n }\n\n return chooseLocale(key);\n };\n\n // compare moment object\n moment.isMoment = function (obj) {\n return obj instanceof Moment ||\n (obj != null && hasOwnProp(obj, '_isAMomentObject'));\n };\n\n // for typechecking Duration objects\n moment.isDuration = function (obj) {\n return obj instanceof Duration;\n };\n\n for (i = lists.length - 1; i >= 0; --i) {\n makeList(lists[i]);\n }\n\n moment.normalizeUnits = function (units) {\n return normalizeUnits(units);\n };\n\n moment.invalid = function (flags) {\n var m = moment.utc(NaN);\n if (flags != null) {\n extend(m._pf, flags);\n }\n else {\n m._pf.userInvalidated = true;\n }\n\n return m;\n };\n\n moment.parseZone = function () {\n return moment.apply(null, arguments).parseZone();\n };\n\n moment.parseTwoDigitYear = function (input) {\n return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);\n };\n\n moment.isDate = isDate;\n\n /************************************\n Moment Prototype\n ************************************/\n\n\n extend(moment.fn = Moment.prototype, {\n\n clone : function () {\n return moment(this);\n },\n\n valueOf : function () {\n return +this._d - ((this._offset || 0) * 60000);\n },\n\n unix : function () {\n return Math.floor(+this / 1000);\n },\n\n toString : function () {\n return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');\n },\n\n toDate : function () {\n return this._offset ? new Date(+this) : this._d;\n },\n\n toISOString : function () {\n var m = moment(this).utc();\n if (0 < m.year() && m.year() <= 9999) {\n if ('function' === typeof Date.prototype.toISOString) {\n // native implementation is ~50x faster, use it when we can\n return this.toDate().toISOString();\n } else {\n return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');\n }\n } else {\n return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');\n }\n },\n\n toArray : function () {\n var m = this;\n return [\n m.year(),\n m.month(),\n m.date(),\n m.hours(),\n m.minutes(),\n m.seconds(),\n m.milliseconds()\n ];\n },\n\n isValid : function () {\n return isValid(this);\n },\n\n isDSTShifted : function () {\n if (this._a) {\n return this.isValid() && compareArrays(this._a, (this._isUTC ? moment.utc(this._a) : moment(this._a)).toArray()) > 0;\n }\n\n return false;\n },\n\n parsingFlags : function () {\n return extend({}, this._pf);\n },\n\n invalidAt: function () {\n return this._pf.overflow;\n },\n\n utc : function (keepLocalTime) {\n return this.utcOffset(0, keepLocalTime);\n },\n\n local : function (keepLocalTime) {\n if (this._isUTC) {\n this.utcOffset(0, keepLocalTime);\n this._isUTC = false;\n\n if (keepLocalTime) {\n this.subtract(this._dateUtcOffset(), 'm');\n }\n }\n return this;\n },\n\n format : function (inputString) {\n var output = formatMoment(this, inputString || moment.defaultFormat);\n return this.localeData().postformat(output);\n },\n\n add : createAdder(1, 'add'),\n\n subtract : createAdder(-1, 'subtract'),\n\n diff : function (input, units, asFloat) {\n var that = makeAs(input, this),\n zoneDiff = (that.utcOffset() - this.utcOffset()) * 6e4,\n anchor, diff, output, daysAdjust;\n\n units = normalizeUnits(units);\n\n if (units === 'year' || units === 'month' || units === 'quarter') {\n output = monthDiff(this, that);\n if (units === 'quarter') {\n output = output / 3;\n } else if (units === 'year') {\n output = output / 12;\n }\n } else {\n diff = this - that;\n output = units === 'second' ? diff / 1e3 : // 1000\n units === 'minute' ? diff / 6e4 : // 1000 * 60\n units === 'hour' ? diff / 36e5 : // 1000 * 60 * 60\n units === 'day' ? (diff - zoneDiff) / 864e5 : // 1000 * 60 * 60 * 24, negate dst\n units === 'week' ? (diff - zoneDiff) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst\n diff;\n }\n return asFloat ? output : absRound(output);\n },\n\n from : function (time, withoutSuffix) {\n return moment.duration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);\n },\n\n fromNow : function (withoutSuffix) {\n return this.from(moment(), withoutSuffix);\n },\n\n calendar : function (time) {\n // We want to compare the start of today, vs this.\n // Getting start-of-today depends on whether we're locat/utc/offset\n // or not.\n var now = time || moment(),\n sod = makeAs(now, this).startOf('day'),\n diff = this.diff(sod, 'days', true),\n format = diff < -6 ? 'sameElse' :\n diff < -1 ? 'lastWeek' :\n diff < 0 ? 'lastDay' :\n diff < 1 ? 'sameDay' :\n diff < 2 ? 'nextDay' :\n diff < 7 ? 'nextWeek' : 'sameElse';\n return this.format(this.localeData().calendar(format, this, moment(now)));\n },\n\n isLeapYear : function () {\n return isLeapYear(this.year());\n },\n\n isDST : function () {\n return (this.utcOffset() > this.clone().month(0).utcOffset() ||\n this.utcOffset() > this.clone().month(5).utcOffset());\n },\n\n day : function (input) {\n var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();\n if (input != null) {\n input = parseWeekday(input, this.localeData());\n return this.add(input - day, 'd');\n } else {\n return day;\n }\n },\n\n month : makeAccessor('Month', true),\n\n startOf : function (units) {\n units = normalizeUnits(units);\n // the following switch intentionally omits break keywords\n // to utilize falling through the cases.\n switch (units) {\n case 'year':\n this.month(0);\n /* falls through */\n case 'quarter':\n case 'month':\n this.date(1);\n /* falls through */\n case 'week':\n case 'isoWeek':\n case 'day':\n this.hours(0);\n /* falls through */\n case 'hour':\n this.minutes(0);\n /* falls through */\n case 'minute':\n this.seconds(0);\n /* falls through */\n case 'second':\n this.milliseconds(0);\n /* falls through */\n }\n\n // weeks are a special case\n if (units === 'week') {\n this.weekday(0);\n } else if (units === 'isoWeek') {\n this.isoWeekday(1);\n }\n\n // quarters are also special\n if (units === 'quarter') {\n this.month(Math.floor(this.month() / 3) * 3);\n }\n\n return this;\n },\n\n endOf: function (units) {\n units = normalizeUnits(units);\n if (units === undefined || units === 'millisecond') {\n return this;\n }\n return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');\n },\n\n isAfter: function (input, units) {\n var inputMs;\n units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');\n if (units === 'millisecond') {\n input = moment.isMoment(input) ? input : moment(input);\n return +this > +input;\n } else {\n inputMs = moment.isMoment(input) ? +input : +moment(input);\n return inputMs < +this.clone().startOf(units);\n }\n },\n\n isBefore: function (input, units) {\n var inputMs;\n units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');\n if (units === 'millisecond') {\n input = moment.isMoment(input) ? input : moment(input);\n return +this < +input;\n } else {\n inputMs = moment.isMoment(input) ? +input : +moment(input);\n return +this.clone().endOf(units) < inputMs;\n }\n },\n\n isBetween: function (from, to, units) {\n return this.isAfter(from, units) && this.isBefore(to, units);\n },\n\n isSame: function (input, units) {\n var inputMs;\n units = normalizeUnits(units || 'millisecond');\n if (units === 'millisecond') {\n input = moment.isMoment(input) ? input : moment(input);\n return +this === +input;\n } else {\n inputMs = +moment(input);\n return +(this.clone().startOf(units)) <= inputMs && inputMs <= +(this.clone().endOf(units));\n }\n },\n\n min: deprecate(\n 'moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',\n function (other) {\n other = moment.apply(null, arguments);\n return other < this ? this : other;\n }\n ),\n\n max: deprecate(\n 'moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',\n function (other) {\n other = moment.apply(null, arguments);\n return other > this ? this : other;\n }\n ),\n\n zone : deprecate(\n 'moment().zone is deprecated, use moment().utcOffset instead. ' +\n 'https://github.com/moment/moment/issues/1779',\n function (input, keepLocalTime) {\n if (input != null) {\n if (typeof input !== 'string') {\n input = -input;\n }\n\n this.utcOffset(input, keepLocalTime);\n\n return this;\n } else {\n return -this.utcOffset();\n }\n }\n ),\n\n // keepLocalTime = true means only change the timezone, without\n // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->\n // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset\n // +0200, so we adjust the time as needed, to be valid.\n //\n // Keeping the time actually adds/subtracts (one hour)\n // from the actual represented time. That is why we call updateOffset\n // a second time. In case it wants us to change the offset again\n // _changeInProgress == true case, then we have to adjust, because\n // there is no such time in the given timezone.\n utcOffset : function (input, keepLocalTime) {\n var offset = this._offset || 0,\n localAdjust;\n if (input != null) {\n if (typeof input === 'string') {\n input = utcOffsetFromString(input);\n }\n if (Math.abs(input) < 16) {\n input = input * 60;\n }\n if (!this._isUTC && keepLocalTime) {\n localAdjust = this._dateUtcOffset();\n }\n this._offset = input;\n this._isUTC = true;\n if (localAdjust != null) {\n this.add(localAdjust, 'm');\n }\n if (offset !== input) {\n if (!keepLocalTime || this._changeInProgress) {\n addOrSubtractDurationFromMoment(this,\n moment.duration(input - offset, 'm'), 1, false);\n } else if (!this._changeInProgress) {\n this._changeInProgress = true;\n moment.updateOffset(this, true);\n this._changeInProgress = null;\n }\n }\n\n return this;\n } else {\n return this._isUTC ? offset : this._dateUtcOffset();\n }\n },\n\n isLocal : function () {\n return !this._isUTC;\n },\n\n isUtcOffset : function () {\n return this._isUTC;\n },\n\n isUtc : function () {\n return this._isUTC && this._offset === 0;\n },\n\n zoneAbbr : function () {\n return this._isUTC ? 'UTC' : '';\n },\n\n zoneName : function () {\n return this._isUTC ? 'Coordinated Universal Time' : '';\n },\n\n parseZone : function () {\n if (this._tzm) {\n this.utcOffset(this._tzm);\n } else if (typeof this._i === 'string') {\n this.utcOffset(utcOffsetFromString(this._i));\n }\n return this;\n },\n\n hasAlignedHourOffset : function (input) {\n if (!input) {\n input = 0;\n }\n else {\n input = moment(input).utcOffset();\n }\n\n return (this.utcOffset() - input) % 60 === 0;\n },\n\n daysInMonth : function () {\n return daysInMonth(this.year(), this.month());\n },\n\n dayOfYear : function (input) {\n var dayOfYear = round((moment(this).startOf('day') - moment(this).startOf('year')) / 864e5) + 1;\n return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');\n },\n\n quarter : function (input) {\n return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);\n },\n\n weekYear : function (input) {\n var year = weekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year;\n return input == null ? year : this.add((input - year), 'y');\n },\n\n isoWeekYear : function (input) {\n var year = weekOfYear(this, 1, 4).year;\n return input == null ? year : this.add((input - year), 'y');\n },\n\n week : function (input) {\n var week = this.localeData().week(this);\n return input == null ? week : this.add((input - week) * 7, 'd');\n },\n\n isoWeek : function (input) {\n var week = weekOfYear(this, 1, 4).week;\n return input == null ? week : this.add((input - week) * 7, 'd');\n },\n\n weekday : function (input) {\n var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;\n return input == null ? weekday : this.add(input - weekday, 'd');\n },\n\n isoWeekday : function (input) {\n // behaves the same as moment#day except\n // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)\n // as a setter, sunday should belong to the previous week.\n return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);\n },\n\n isoWeeksInYear : function () {\n return weeksInYear(this.year(), 1, 4);\n },\n\n weeksInYear : function () {\n var weekInfo = this.localeData()._week;\n return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);\n },\n\n get : function (units) {\n units = normalizeUnits(units);\n return this[units]();\n },\n\n set : function (units, value) {\n var unit;\n if (typeof units === 'object') {\n for (unit in units) {\n this.set(unit, units[unit]);\n }\n }\n else {\n units = normalizeUnits(units);\n if (typeof this[units] === 'function') {\n this[units](value);\n }\n }\n return this;\n },\n\n // If passed a locale key, it will set the locale for this\n // instance. Otherwise, it will return the locale configuration\n // variables for this instance.\n locale : function (key) {\n var newLocaleData;\n\n if (key === undefined) {\n return this._locale._abbr;\n } else {\n newLocaleData = moment.localeData(key);\n if (newLocaleData != null) {\n this._locale = newLocaleData;\n }\n return this;\n }\n },\n\n lang : deprecate(\n 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',\n function (key) {\n if (key === undefined) {\n return this.localeData();\n } else {\n return this.locale(key);\n }\n }\n ),\n\n localeData : function () {\n return this._locale;\n },\n\n _dateUtcOffset : function () {\n // On Firefox.24 Date#getTimezoneOffset returns a floating point.\n // https://github.com/moment/moment/pull/1871\n return -Math.round(this._d.getTimezoneOffset() / 15) * 15;\n }\n\n });\n\n function rawMonthSetter(mom, value) {\n var dayOfMonth;\n\n // TODO: Move this out of here!\n if (typeof value === 'string') {\n value = mom.localeData().monthsParse(value);\n // TODO: Another silent failure?\n if (typeof value !== 'number') {\n return mom;\n }\n }\n\n dayOfMonth = Math.min(mom.date(),\n daysInMonth(mom.year(), value));\n mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);\n return mom;\n }\n\n function rawGetter(mom, unit) {\n return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]();\n }\n\n function rawSetter(mom, unit, value) {\n if (unit === 'Month') {\n return rawMonthSetter(mom, value);\n } else {\n return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);\n }\n }\n\n function makeAccessor(unit, keepTime) {\n return function (value) {\n if (value != null) {\n rawSetter(this, unit, value);\n moment.updateOffset(this, keepTime);\n return this;\n } else {\n return rawGetter(this, unit);\n }\n };\n }\n\n moment.fn.millisecond = moment.fn.milliseconds = makeAccessor('Milliseconds', false);\n moment.fn.second = moment.fn.seconds = makeAccessor('Seconds', false);\n moment.fn.minute = moment.fn.minutes = makeAccessor('Minutes', false);\n // Setting the hour should keep the time, because the user explicitly\n // specified which hour he wants. So trying to maintain the same hour (in\n // a new timezone) makes sense. Adding/subtracting hours does not follow\n // this rule.\n moment.fn.hour = moment.fn.hours = makeAccessor('Hours', true);\n // moment.fn.month is defined separately\n moment.fn.date = makeAccessor('Date', true);\n moment.fn.dates = deprecate('dates accessor is deprecated. Use date instead.', makeAccessor('Date', true));\n moment.fn.year = makeAccessor('FullYear', true);\n moment.fn.years = deprecate('years accessor is deprecated. Use year instead.', makeAccessor('FullYear', true));\n\n // add plural methods\n moment.fn.days = moment.fn.day;\n moment.fn.months = moment.fn.month;\n moment.fn.weeks = moment.fn.week;\n moment.fn.isoWeeks = moment.fn.isoWeek;\n moment.fn.quarters = moment.fn.quarter;\n\n // add aliased format methods\n moment.fn.toJSON = moment.fn.toISOString;\n\n // alias isUtc for dev-friendliness\n moment.fn.isUTC = moment.fn.isUtc;\n\n /************************************\n Duration Prototype\n ************************************/\n\n\n function daysToYears (days) {\n // 400 years have 146097 days (taking into account leap year rules)\n return days * 400 / 146097;\n }\n\n function yearsToDays (years) {\n // years * 365 + absRound(years / 4) -\n // absRound(years / 100) + absRound(years / 400);\n return years * 146097 / 400;\n }\n\n extend(moment.duration.fn = Duration.prototype, {\n\n _bubble : function () {\n var milliseconds = this._milliseconds,\n days = this._days,\n months = this._months,\n data = this._data,\n seconds, minutes, hours, years = 0;\n\n // The following code bubbles up values, see the tests for\n // examples of what that means.\n data.milliseconds = milliseconds % 1000;\n\n seconds = absRound(milliseconds / 1000);\n data.seconds = seconds % 60;\n\n minutes = absRound(seconds / 60);\n data.minutes = minutes % 60;\n\n hours = absRound(minutes / 60);\n data.hours = hours % 24;\n\n days += absRound(hours / 24);\n\n // Accurately convert days to years, assume start from year 0.\n years = absRound(daysToYears(days));\n days -= absRound(yearsToDays(years));\n\n // 30 days to a month\n // TODO (iskren): Use anchor date (like 1st Jan) to compute this.\n months += absRound(days / 30);\n days %= 30;\n\n // 12 months -> 1 year\n years += absRound(months / 12);\n months %= 12;\n\n data.days = days;\n data.months = months;\n data.years = years;\n },\n\n abs : function () {\n this._milliseconds = Math.abs(this._milliseconds);\n this._days = Math.abs(this._days);\n this._months = Math.abs(this._months);\n\n this._data.milliseconds = Math.abs(this._data.milliseconds);\n this._data.seconds = Math.abs(this._data.seconds);\n this._data.minutes = Math.abs(this._data.minutes);\n this._data.hours = Math.abs(this._data.hours);\n this._data.months = Math.abs(this._data.months);\n this._data.years = Math.abs(this._data.years);\n\n return this;\n },\n\n weeks : function () {\n return absRound(this.days() / 7);\n },\n\n valueOf : function () {\n return this._milliseconds +\n this._days * 864e5 +\n (this._months % 12) * 2592e6 +\n toInt(this._months / 12) * 31536e6;\n },\n\n humanize : function (withSuffix) {\n var output = relativeTime(this, !withSuffix, this.localeData());\n\n if (withSuffix) {\n output = this.localeData().pastFuture(+this, output);\n }\n\n return this.localeData().postformat(output);\n },\n\n add : function (input, val) {\n // supports only 2.0-style add(1, 's') or add(moment)\n var dur = moment.duration(input, val);\n\n this._milliseconds += dur._milliseconds;\n this._days += dur._days;\n this._months += dur._months;\n\n this._bubble();\n\n return this;\n },\n\n subtract : function (input, val) {\n var dur = moment.duration(input, val);\n\n this._milliseconds -= dur._milliseconds;\n this._days -= dur._days;\n this._months -= dur._months;\n\n this._bubble();\n\n return this;\n },\n\n get : function (units) {\n units = normalizeUnits(units);\n return this[units.toLowerCase() + 's']();\n },\n\n as : function (units) {\n var days, months;\n units = normalizeUnits(units);\n\n if (units === 'month' || units === 'year') {\n days = this._days + this._milliseconds / 864e5;\n months = this._months + daysToYears(days) * 12;\n return units === 'month' ? months : months / 12;\n } else {\n // handle milliseconds separately because of floating point math errors (issue #1867)\n days = this._days + Math.round(yearsToDays(this._months / 12));\n switch (units) {\n case 'week': return days / 7 + this._milliseconds / 6048e5;\n case 'day': return days + this._milliseconds / 864e5;\n case 'hour': return days * 24 + this._milliseconds / 36e5;\n case 'minute': return days * 24 * 60 + this._milliseconds / 6e4;\n case 'second': return days * 24 * 60 * 60 + this._milliseconds / 1000;\n // Math.floor prevents floating point math errors here\n case 'millisecond': return Math.floor(days * 24 * 60 * 60 * 1000) + this._milliseconds;\n default: throw new Error('Unknown unit ' + units);\n }\n }\n },\n\n lang : moment.fn.lang,\n locale : moment.fn.locale,\n\n toIsoString : deprecate(\n 'toIsoString() is deprecated. Please use toISOString() instead ' +\n '(notice the capitals)',\n function () {\n return this.toISOString();\n }\n ),\n\n toISOString : function () {\n // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js\n var years = Math.abs(this.years()),\n months = Math.abs(this.months()),\n days = Math.abs(this.days()),\n hours = Math.abs(this.hours()),\n minutes = Math.abs(this.minutes()),\n seconds = Math.abs(this.seconds() + this.milliseconds() / 1000);\n\n if (!this.asSeconds()) {\n // this is the same as C#'s (Noda) and python (isodate)...\n // but not other JS (goog.date)\n return 'P0D';\n }\n\n return (this.asSeconds() < 0 ? '-' : '') +\n 'P' +\n (years ? years + 'Y' : '') +\n (months ? months + 'M' : '') +\n (days ? days + 'D' : '') +\n ((hours || minutes || seconds) ? 'T' : '') +\n (hours ? hours + 'H' : '') +\n (minutes ? minutes + 'M' : '') +\n (seconds ? seconds + 'S' : '');\n },\n\n localeData : function () {\n return this._locale;\n },\n\n toJSON : function () {\n return this.toISOString();\n }\n });\n\n moment.duration.fn.toString = moment.duration.fn.toISOString;\n\n function makeDurationGetter(name) {\n moment.duration.fn[name] = function () {\n return this._data[name];\n };\n }\n\n for (i in unitMillisecondFactors) {\n if (hasOwnProp(unitMillisecondFactors, i)) {\n makeDurationGetter(i.toLowerCase());\n }\n }\n\n moment.duration.fn.asMilliseconds = function () {\n return this.as('ms');\n };\n moment.duration.fn.asSeconds = function () {\n return this.as('s');\n };\n moment.duration.fn.asMinutes = function () {\n return this.as('m');\n };\n moment.duration.fn.asHours = function () {\n return this.as('h');\n };\n moment.duration.fn.asDays = function () {\n return this.as('d');\n };\n moment.duration.fn.asWeeks = function () {\n return this.as('weeks');\n };\n moment.duration.fn.asMonths = function () {\n return this.as('M');\n };\n moment.duration.fn.asYears = function () {\n return this.as('y');\n };\n\n /************************************\n Default Locale\n ************************************/\n\n\n // Set default locale, other locale will inherit from English.\n moment.locale('en', {\n ordinalParse: /\\d{1,2}(th|st|nd|rd)/,\n ordinal : function (number) {\n var b = number % 10,\n output = (toInt(number % 100 / 10) === 1) ? 'th' :\n (b === 1) ? 'st' :\n (b === 2) ? 'nd' :\n (b === 3) ? 'rd' : 'th';\n return number + output;\n }\n });\n\n /* EMBED_LOCALES */\n\n /************************************\n Exposing Moment\n ************************************/\n\n function makeGlobal(shouldDeprecate) {\n /*global ender:false */\n if (typeof ender !== 'undefined') {\n return;\n }\n oldGlobalMoment = globalScope.moment;\n if (shouldDeprecate) {\n globalScope.moment = deprecate(\n 'Accessing Moment through the global scope is ' +\n 'deprecated, and will be removed in an upcoming ' +\n 'release.',\n moment);\n } else {\n globalScope.moment = moment;\n }\n }\n\n // CommonJS module is defined\n if (hasModule) {\n module.exports = moment;\n } else if (typeof define === 'function' && define.amd) {\n define(function (require, exports, module) {\n if (module.config && module.config() && module.config().noGlobal === true) {\n // release the global variable\n globalScope.moment = oldGlobalMoment;\n }\n\n return moment;\n });\n makeGlobal(true);\n } else {\n makeGlobal();\n }\n}).call(this);\n\n// HumanizeDuration.js - http://git.io/j0HgmQ\n\n(function() {\n\n var UNITS = {\n year: 31557600000,\n month: 2629800000,\n week: 604800000,\n day: 86400000,\n hour: 3600000,\n minute: 60000,\n second: 1000,\n millisecond: 1\n };\n\n var languages = {\n ar: {\n year: function(c) { return ((c === 1) ? \"سنة\" : \"سنوات\"); },\n month: function(c) { return ((c === 1) ? \"شهر\" : \"أشهر\"); },\n week: function(c) { return ((c === 1) ? \"أسبوع\" : \"أسابيع\"); },\n day: function(c) { return ((c === 1) ? \"يوم\" : \"أيام\"); },\n hour: function(c) { return ((c === 1) ? \"ساعة\" : \"ساعات\"); },\n minute: function(c) { return ((c === 1) ? \"دقيقة\" : \"دقائق\"); },\n second: function(c) { return ((c === 1) ? \"ثانية\" : \"ثواني\"); },\n millisecond: function(c) { return ((c === 1) ? \"جزء من الثانية\" : \"أجزاء من الثانية\"); }\n },\n ca: {\n year: function(c) { return \"any\" + ((c !== 1) ? \"s\" : \"\"); },\n month: function(c) { return \"mes\" + ((c !== 1) ? \"os\" : \"\"); },\n week: function(c) { return \"setman\" + ((c !== 1) ? \"es\" : \"a\"); },\n day: function(c) { return \"di\" + ((c !== 1) ? \"es\" : \"a\"); },\n hour: function(c) { return \"hor\" + ((c !== 1) ? \"es\" : \"a\"); },\n minute: function(c) { return \"minut\" + ((c !== 1) ? \"s\" : \"\"); },\n second: function(c) { return \"segon\" + ((c !== 1) ? \"s\" : \"\"); },\n millisecond: function(c) { return \"milisegon\" + ((c !== 1) ? \"s\" : \"\" ); }\n },\n da: {\n year: \"år\",\n month: function(c) { return \"måned\" + ((c !== 1) ? \"er\" : \"\"); },\n week: function(c) { return \"uge\" + ((c !== 1) ? \"r\" : \"\"); },\n day: function(c) { return \"dag\" + ((c !== 1) ? \"e\" : \"\"); },\n hour: function(c) { return \"time\" + ((c !== 1) ? \"r\" : \"\"); },\n minute: function(c) { return \"minut\" + ((c !== 1) ? \"ter\" : \"\"); },\n second: function(c) { return \"sekund\" + ((c !== 1) ? \"er\" : \"\"); },\n millisecond: function(c) { return \"millisekund\" + ((c !== 1) ? \"er\" : \"\"); }\n },\n de: {\n year: function(c) { return \"Jahr\" + ((c !== 1) ? \"e\" : \"\"); },\n month: function(c) { return \"Monat\" + ((c !== 1) ? \"e\" : \"\"); },\n week: function(c) { return \"Woche\" + ((c !== 1) ? \"n\" : \"\"); },\n day: function(c) { return \"Tag\" + ((c !== 1) ? \"e\" : \"\"); },\n hour: function(c) { return \"Stunde\" + ((c !== 1) ? \"n\" : \"\"); },\n minute: function(c) { return \"Minute\" + ((c !== 1) ? \"n\" : \"\"); },\n second: function(c) { return \"Sekunde\" + ((c !== 1) ? \"n\" : \"\"); },\n millisecond: function(c) { return \"Millisekunde\" + ((c !== 1) ? \"n\" : \"\"); }\n },\n en: {\n year: function(c) { return \"year\" + ((c !== 1) ? \"s\" : \"\"); },\n month: function(c) { return \"month\" + ((c !== 1) ? \"s\" : \"\"); },\n week: function(c) { return \"week\" + ((c !== 1) ? \"s\" : \"\"); },\n day: function(c) { return \"day\" + ((c !== 1) ? \"s\" : \"\"); },\n hour: function(c) { return \"hour\" + ((c !== 1) ? \"s\" : \"\"); },\n minute: function(c) { return \"minute\" + ((c !== 1) ? \"s\" : \"\"); },\n second: function(c) { return \"second\" + ((c !== 1) ? \"s\" : \"\"); },\n millisecond: function(c) { return \"millisecond\" + ((c !== 1) ? \"s\" : \"\"); }\n },\n es: {\n year: function(c) { return \"año\" + ((c !== 1) ? \"s\" : \"\"); },\n month: function(c) { return \"mes\" + ((c !== 1) ? \"es\" : \"\"); },\n week: function(c) { return \"semana\" + ((c !== 1) ? \"s\" : \"\"); },\n day: function(c) { return \"día\" + ((c !== 1) ? \"s\" : \"\"); },\n hour: function(c) { return \"hora\" + ((c !== 1) ? \"s\" : \"\"); },\n minute: function(c) { return \"minuto\" + ((c !== 1) ? \"s\" : \"\"); },\n second: function(c) { return \"segundo\" + ((c !== 1) ? \"s\" : \"\"); },\n millisecond: function(c) { return \"milisegundo\" + ((c !== 1) ? \"s\" : \"\" ); }\n },\n fr: {\n year: function(c) { return \"an\" + ((c !== 1) ? \"s\" : \"\"); },\n month: \"mois\",\n week: function(c) { return \"semaine\" + ((c !== 1) ? \"s\" : \"\"); },\n day: function(c) { return \"jour\" + ((c !== 1) ? \"s\" : \"\"); },\n hour: function(c) { return \"heure\" + ((c !== 1) ? \"s\" : \"\"); },\n minute: function(c) { return \"minute\" + ((c !== 1) ? \"s\" : \"\"); },\n second: function(c) { return \"seconde\" + ((c !== 1) ? \"s\" : \"\"); },\n millisecond: function(c) { return \"milliseconde\" + ((c !== 1) ? \"s\" : \"\"); }\n },\n hu: {\n year: \"év\",\n month: \"hónap\",\n week: \"hét\",\n day: \"nap\",\n hour: \"óra\",\n minute: \"perc\",\n second: \"másodperc\",\n millisecond: \"ezredmásodperc\"\n },\n it: {\n year: function(c) { return \"ann\" + ((c !== 1) ? \"i\" : \"o\"); },\n month: function(c) { return \"mes\" + ((c !== 1) ? \"i\" : \"e\"); },\n week: function(c) { return \"settiman\" + ((c !== 1) ? \"e\" : \"a\"); },\n day: function(c) { return \"giorn\" + ((c !== 1) ? \"i\" : \"o\"); },\n hour: function(c) { return \"or\" + ((c !== 1) ? \"e\" : \"a\"); },\n minute: function(c) { return \"minut\" + ((c !== 1) ? \"i\" : \"o\"); },\n second: function(c) { return \"second\" + ((c !== 1) ? \"i\" : \"o\"); },\n millisecond: function(c) { return \"millisecond\" + ((c !== 1) ? \"i\" : \"o\" ); }\n },\n ja: {\n year: \"年\",\n month: \"月\",\n week: \"週\",\n day: \"日\",\n hour: \"時間\",\n minute: \"分\",\n second: \"秒\",\n millisecond: \"ミリ秒\"\n },\n ko: {\n year: \"년\",\n month: \"개월\",\n week: \"주일\",\n day: \"일\",\n hour: \"시간\",\n minute: \"분\",\n second: \"초\",\n millisecond: \"밀리 초\"\n },\n nl: {\n year: \"jaar\",\n month: function(c) { return (c === 1) ? \"maand\" : \"maanden\"; },\n week: function(c) { return (c === 1) ? \"week\" : \"weken\"; },\n day: function(c) { return (c === 1) ? \"dag\" : \"dagen\"; },\n hour: \"uur\",\n minute: function(c) { return (c === 1) ? \"minuut\" : \"minuten\"; },\n second: function(c) { return (c === 1) ? \"seconde\" : \"seconden\"; },\n millisecond: function(c) { return (c === 1) ? \"milliseconde\" : \"milliseconden\"; }\n },\n nob: {\n year: \"år\",\n month: function(c) { return \"måned\" + ((c !== 1) ? \"er\" : \"\"); },\n week: function(c) { return \"uke\" + ((c !== 1) ? \"r\" : \"\"); },\n day: function(c) { return \"dag\" + ((c !== 1) ? \"er\" : \"\"); },\n hour: function(c) { return \"time\" + ((c !== 1) ? \"r\" : \"\"); },\n minute: function(c) { return \"minutt\" + ((c !== 1) ? \"er\" : \"\"); },\n second: function(c) { return \"sekund\" + ((c !== 1) ? \"er\" : \"\"); },\n millisecond: function(c) { return \"millisekund\" + ((c !== 1) ? \"er\" : \"\"); }\n },\n pl: {\n year: function(c) { return [\"rok\", \"roku\", \"lata\", \"lat\"][getPolishForm(c)]; },\n month: function(c) { return [\"miesiąc\", \"miesiąca\", \"miesiące\", \"miesięcy\"][getPolishForm(c)]; },\n week: function(c) { return [\"tydzień\", \"tygodnia\", \"tygodnie\", \"tygodni\"][getPolishForm(c)]; },\n day: function(c) { return [\"dzień\", \"dnia\", \"dni\", \"dni\"][getPolishForm(c)]; },\n hour: function(c) { return [\"godzina\", \"godziny\", \"godziny\", \"godzin\"][getPolishForm(c)]; },\n minute: function(c) { return [\"minuta\", \"minuty\", \"minuty\", \"minut\"][getPolishForm(c)]; },\n second: function(c) { return [\"sekunda\", \"sekundy\", \"sekundy\", \"sekund\"][getPolishForm(c)]; },\n millisecond: function(c) { return [\"milisekunda\", \"milisekundy\", \"milisekundy\", \"milisekund\"][getPolishForm(c)]; }\n },\n pt: {\n year: function(c) { return \"ano\" + ((c !== 1) ? \"s\" : \"\"); },\n month: function(c) { return (c !== 1) ? \"meses\" : \"mês\"; },\n week: function(c) { return \"semana\" + ((c !== 1) ? \"s\" : \"\"); },\n day: function(c) { return \"dia\" + ((c !== 1) ? \"s\" : \"\"); },\n hour: function(c) { return \"hora\" + ((c !== 1) ? \"s\" : \"\"); },\n minute: function(c) { return \"minuto\" + ((c !== 1) ? \"s\" : \"\"); },\n second: function(c) { return \"segundo\" + ((c !== 1) ? \"s\" : \"\"); },\n millisecond: function(c) { return \"milissegundo\" + ((c !== 1) ? \"s\" : \"\"); }\n },\n ru: {\n year: function(c) { return [\"лет\", \"год\", \"года\"][getRussianForm(c)]; },\n month: function(c) { return [\"месяцев\", \"месяц\", \"месяца\"][getRussianForm(c)]; },\n week: function(c) { return [\"недель\", \"неделя\", \"недели\"][getRussianForm(c)]; },\n day: function(c) { return [\"дней\", \"день\", \"дня\"][getRussianForm(c)]; },\n hour: function(c) { return [\"часов\", \"час\", \"часа\"][getRussianForm(c)]; },\n minute: function(c) { return [\"минут\", \"минута\", \"минуты\"][getRussianForm(c)]; },\n second: function(c) { return [\"секунд\", \"секунда\", \"секунды\"][getRussianForm(c)]; },\n millisecond: function(c) { return [\"миллисекунд\", \"миллисекунда\", \"миллисекунды\"][getRussianForm(c)]; }\n },\n sv: {\n year: \"år\",\n month: function(c) { return \"månad\" + ((c !== 1) ? \"er\" : \"\"); },\n week: function(c) { return \"veck\" + ((c !== 1) ? \"or\" : \"a\"); },\n day: function(c) { return \"dag\" + ((c !== 1) ? \"ar\" : \"\"); },\n hour: function(c) { return \"timm\" + ((c !== 1) ? \"ar\" : \"e\"); },\n minute: function(c) { return \"minut\" + ((c !== 1) ? \"er\" : \"\"); },\n second: function(c) { return \"sekund\" + ((c !== 1) ? \"er\" : \"\"); },\n millisecond: function(c) { return \"millisekund\" + ((c !== 1) ? \"er\" : \"\"); }\n },\n tr: {\n year: \"yıl\",\n month: \"ay\",\n week: \"hafta\",\n day: \"gün\",\n hour: \"saat\",\n minute: \"dakika\",\n second: \"saniye\",\n millisecond: \"milisaniye\"\n },\n \"zh-CN\": {\n year: \"年\",\n month: \"个月\",\n week: \"周\",\n day: \"天\",\n hour: \"小时\",\n minute: \"分钟\",\n second: \"秒\",\n millisecond: \"毫秒\"\n },\n \"zh-TW\": {\n year: \"年\",\n month: \"個月\",\n week: \"周\",\n day: \"天\",\n hour: \"小時\",\n minute: \"分鐘\",\n second: \"秒\",\n millisecond: \"毫秒\"\n }\n };\n\n // You can create a humanizer, which returns a function with defaults\n // parameters.\n function humanizer(passedOptions) {\n\n var result = function humanizer(ms, humanizerOptions) {\n var options = extend({}, result, humanizerOptions || {});\n return doHumanization(ms, options);\n };\n\n return extend(result, {\n language: \"en\",\n delimiter: \", \",\n spacer: \" \",\n units: [\"year\", \"month\", \"week\", \"day\", \"hour\", \"minute\", \"second\"],\n languages: {},\n halfUnit: true,\n round: false\n }, passedOptions);\n\n }\n\n // The main function is just a wrapper around a default humanizer.\n var defaultHumanizer = humanizer({});\n function humanizeDuration() {\n return defaultHumanizer.apply(defaultHumanizer, arguments);\n }\n\n // doHumanization does the bulk of the work.\n function doHumanization(ms, options) {\n\n // Make sure we have a positive number.\n // Has the nice sideffect of turning Number objects into primitives.\n ms = Math.abs(ms);\n\n if (ms === 0) {\n return \"0\";\n }\n\n var dictionary = options.languages[options.language] || languages[options.language];\n if (!dictionary) {\n throw new Error(\"No language \" + dictionary + \".\");\n }\n\n var result = [];\n\n // Start at the top and keep removing units, bit by bit.\n var unitName, unitMS, unitCount, mightBeHalfUnit;\n for (var i = 0, len = options.units.length; i < len; i ++) {\n\n unitName = options.units[i];\n if (unitName[unitName.length - 1] === \"s\") { // strip plurals\n unitName = unitName.substring(0, unitName.length - 1);\n }\n unitMS = UNITS[unitName];\n\n // If it's a half-unit interval, we're done.\n if (result.length === 0 && options.halfUnit) {\n mightBeHalfUnit = (ms / unitMS) * 2;\n if (mightBeHalfUnit === Math.floor(mightBeHalfUnit)) {\n return render(mightBeHalfUnit / 2, unitName, dictionary, options.spacer);\n }\n }\n\n // What's the number of full units we can fit?\n if ((i + 1) === len) {\n unitCount = ms / unitMS;\n if (options.round) {\n unitCount = Math.round(unitCount);\n }\n } else {\n unitCount = Math.floor(ms / unitMS);\n }\n\n // Add the string.\n if (unitCount) {\n result.push(render(unitCount, unitName, dictionary, options.spacer));\n }\n\n // Remove what we just figured out.\n ms -= unitCount * unitMS;\n\n }\n\n return result.join(options.delimiter);\n\n }\n\n function render(count, type, dictionary, spacer) {\n var dictionaryValue = dictionary[type];\n var word;\n if (typeof dictionaryValue === \"function\") {\n word = dictionaryValue(count);\n } else {\n word = dictionaryValue;\n }\n return count + spacer + word;\n }\n\n function extend(destination) {\n var source;\n for (var i = 1; i < arguments.length; i ++) {\n source = arguments[i];\n for (var prop in source) {\n if (source.hasOwnProperty(prop)) {\n destination[prop] = source[prop];\n }\n }\n }\n return destination;\n }\n\n // Internal helper function for Polish language.\n function getPolishForm(c) {\n if (c === 1) {\n return 0;\n } else if (Math.floor(c) !== c) {\n return 1;\n } else if (2 <= c % 10 && c % 10 <= 4 && !(10 < c % 100 && c % 100 < 20)) {\n return 2;\n } else {\n return 3;\n }\n }\n\n // Internal helper function for Russian language.\n function getRussianForm(c) {\n if (Math.floor(c) !== c) {\n return 2;\n } else if (c === 0 || (c >= 5 && c <= 20) || (c % 10 >= 5 && c % 10 <= 9) || (c % 10 === 0)) {\n return 0;\n } else if (c === 1 || c % 10 === 1) {\n return 1;\n } else if (c > 1) {\n return 2;\n } else {\n return 0;\n }\n }\n\n function getSupportedLanguages() {\n var result = [];\n for (var language in languages) {\n if (languages.hasOwnProperty(language)) {\n result.push(language);\n }\n }\n return result;\n }\n\n humanizeDuration.humanizer = humanizer;\n humanizeDuration.getSupportedLanguages = getSupportedLanguages;\n\n if (typeof define === \"function\" && define.amd) {\n define(function() {\n return humanizeDuration;\n });\n } else if (typeof module !== \"undefined\" && module.exports) {\n module.exports = humanizeDuration;\n } else {\n this.humanizeDuration = humanizeDuration;\n }\n\n})();\n\n/**\n * angular-timer - v1.3.3 - 2015-05-28 9:05 AM\n * https://github.com/siddii/angular-timer\n *\n * Copyright (c) 2015 Siddique Hameed\n * Licensed MIT
\n */\nvar timerModule = angular.module('timer', [])\n .directive('timer', ['$compile', function ($compile) {\n return {\n restrict: 'EA',\n replace: false,\n scope: {\n interval: '=interval',\n startTimeAttr: '=startTime',\n endTimeAttr: '=endTime',\n countdownattr: '=countdown',\n finishCallback: '&finishCallback',\n autoStart: '&autoStart',\n language: '@?',\n fallback: '@?',\n maxTimeUnit: '='\n },\n controller: ['$scope', '$element', '$attrs', '$timeout', 'I18nService', '$interpolate', 'progressBarService', function ($scope, $element, $attrs, $timeout, I18nService, $interpolate, progressBarService) {\n\n // Checking for trim function since IE8 doesn't have it\n // If not a function, create tirm with RegEx to mimic native trim\n if (typeof String.prototype.trim !== 'function') {\n String.prototype.trim = function () {\n return this.replace(/^\\s+|\\s+$/g, '');\n };\n }\n\n //angular 1.2 doesn't support attributes ending in \"-start\", so we're\n //supporting both \"autostart\" and \"auto-start\" as a solution for\n //backward and forward compatibility.\n $scope.autoStart = $attrs.autoStart || $attrs.autostart;\n\n\n $scope.language = $scope.language || 'en';\n $scope.fallback = $scope.fallback || 'en';\n\n //allow to change the language of the directive while already launched\n $scope.$watch('language', function(newVal, oldVal) {\n if(newVal !== undefined) {\n i18nService.init(newVal, $scope.fallback);\n }\n });\n\n //init momentJS i18n, default english\n var i18nService = new I18nService();\n i18nService.init($scope.language, $scope.fallback);\n\n //progress bar\n $scope.displayProgressBar = 0;\n $scope.displayProgressActive = 'active'; //Bootstrap active effect for progress bar\n\n if ($element.html().trim().length === 0) {\n $element.append($compile('' + $interpolate.startSymbol() + 'millis' + $interpolate.endSymbol() + '')($scope));\n } else {\n $element.append($compile($element.contents())($scope));\n }\n\n $scope.startTime = null;\n $scope.endTime = null;\n $scope.timeoutId = null;\n $scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) >= 0 ? parseInt($scope.countdownattr, 10) : undefined;\n $scope.isRunning = false;\n\n $scope.$on('timer-start', function () {\n $scope.start();\n });\n\n $scope.$on('timer-resume', function () {\n $scope.resume();\n });\n\n $scope.$on('timer-stop', function () {\n $scope.stop();\n });\n\n $scope.$on('timer-clear', function () {\n $scope.clear();\n });\n\n $scope.$on('timer-reset', function () {\n $scope.reset();\n });\n\n $scope.$on('timer-set-countdown', function (e, countdown) {\n $scope.countdown = countdown;\n });\n\n function resetTimeout() {\n if ($scope.timeoutId) {\n clearTimeout($scope.timeoutId);\n }\n }\n\n $scope.$watch('startTimeAttr', function(newValue, oldValue) {\n if (newValue !== oldValue && $scope.isRunning) {\n $scope.start();\n }\n });\n\n $scope.$watch('endTimeAttr', function(newValue, oldValue) {\n if (newValue !== oldValue && $scope.isRunning) {\n $scope.start();\n }\n });\n\n $scope.start = $element[0].start = function () {\n $scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment();\n $scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null;\n if (!$scope.countdown) {\n $scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;\n }\n resetTimeout();\n tick();\n $scope.isRunning = true;\n };\n\n $scope.resume = $element[0].resume = function () {\n resetTimeout();\n if ($scope.countdownattr) {\n $scope.countdown += 1;\n }\n $scope.startTime = moment().diff((moment($scope.stoppedTime).diff(moment($scope.startTime))));\n tick();\n $scope.isRunning = true;\n };\n\n $scope.stop = $scope.pause = $element[0].stop = $element[0].pause = function () {\n var timeoutId = $scope.timeoutId;\n $scope.clear();\n $scope.$emit('timer-stopped', {timeoutId: timeoutId, millis: $scope.millis, seconds: $scope.seconds, minutes: $scope.minutes, hours: $scope.hours, days: $scope.days});\n };\n\n $scope.clear = $element[0].clear = function () {\n // same as stop but without the event being triggered\n $scope.stoppedTime = moment();\n resetTimeout();\n $scope.timeoutId = null;\n $scope.isRunning = false;\n };\n\n $scope.reset = $element[0].reset = function () {\n $scope.startTime = $scope.startTimeAttr ? moment($scope.startTimeAttr) : moment();\n $scope.endTime = $scope.endTimeAttr ? moment($scope.endTimeAttr) : null;\n $scope.countdown = $scope.countdownattr && parseInt($scope.countdownattr, 10) > 0 ? parseInt($scope.countdownattr, 10) : undefined;\n resetTimeout();\n tick();\n $scope.isRunning = false;\n $scope.clear();\n };\n\n $element.bind('$destroy', function () {\n resetTimeout();\n $scope.isRunning = false;\n });\n\n\n function calculateTimeUnits() {\n var timeUnits = {}; //will contains time with units\n\n if ($attrs.startTime !== undefined){\n $scope.millis = moment().diff(moment($scope.startTimeAttr));\n }\n\n timeUnits = i18nService.getTimeUnits($scope.millis);\n\n // compute time values based on maxTimeUnit specification\n if (!$scope.maxTimeUnit || $scope.maxTimeUnit === 'day') {\n $scope.seconds = Math.floor(($scope.millis / 1000) % 60);\n $scope.minutes = Math.floor((($scope.millis / (60000)) % 60));\n $scope.hours = Math.floor((($scope.millis / (3600000)) % 24));\n $scope.days = Math.floor((($scope.millis / (3600000)) / 24));\n $scope.months = 0;\n $scope.years = 0;\n } else if ($scope.maxTimeUnit === 'second') {\n $scope.seconds = Math.floor($scope.millis / 1000);\n $scope.minutes = 0;\n $scope.hours = 0;\n $scope.days = 0;\n $scope.months = 0;\n $scope.years = 0;\n } else if ($scope.maxTimeUnit === 'minute') {\n $scope.seconds = Math.floor(($scope.millis / 1000) % 60);\n $scope.minutes = Math.floor($scope.millis / 60000);\n $scope.hours = 0;\n $scope.days = 0;\n $scope.months = 0;\n $scope.years = 0;\n } else if ($scope.maxTimeUnit === 'hour') {\n $scope.seconds = Math.floor(($scope.millis / 1000) % 60);\n $scope.minutes = Math.floor((($scope.millis / (60000)) % 60));\n $scope.hours = Math.floor($scope.millis / 3600000);\n $scope.days = 0;\n $scope.months = 0;\n $scope.years = 0;\n } else if ($scope.maxTimeUnit === 'month') {\n $scope.seconds = Math.floor(($scope.millis / 1000) % 60);\n $scope.minutes = Math.floor((($scope.millis / (60000)) % 60));\n $scope.hours = Math.floor((($scope.millis / (3600000)) % 24));\n $scope.days = Math.floor((($scope.millis / (3600000)) / 24) % 30);\n $scope.months = Math.floor((($scope.millis / (3600000)) / 24) / 30);\n $scope.years = 0;\n } else if ($scope.maxTimeUnit === 'year') {\n $scope.seconds = Math.floor(($scope.millis / 1000) % 60);\n $scope.minutes = Math.floor((($scope.millis / (60000)) % 60));\n $scope.hours = Math.floor((($scope.millis / (3600000)) % 24));\n $scope.days = Math.floor((($scope.millis / (3600000)) / 24) % 30);\n $scope.months = Math.floor((($scope.millis / (3600000)) / 24 / 30) % 12);\n $scope.years = Math.floor(($scope.millis / (3600000)) / 24 / 365);\n }\n // plural - singular unit decision (old syntax, for backwards compatibility and English only, could be deprecated!)\n $scope.secondsS = ($scope.seconds === 1) ? '' : 's';\n $scope.minutesS = ($scope.minutes === 1) ? '' : 's';\n $scope.hoursS = ($scope.hours === 1) ? '' : 's';\n $scope.daysS = ($scope.days === 1)? '' : 's';\n $scope.monthsS = ($scope.months === 1)? '' : 's';\n $scope.yearsS = ($scope.years === 1)? '' : 's';\n\n\n // new plural-singular unit decision functions (for custom units and multilingual support)\n $scope.secondUnit = timeUnits.seconds;\n $scope.minuteUnit = timeUnits.minutes;\n $scope.hourUnit = timeUnits.hours;\n $scope.dayUnit = timeUnits.days;\n $scope.monthUnit = timeUnits.months;\n $scope.yearUnit = timeUnits.years;\n\n //add leading zero if number is smaller than 10\n $scope.sseconds = $scope.seconds < 10 ? '0' + $scope.seconds : $scope.seconds;\n $scope.mminutes = $scope.minutes < 10 ? '0' + $scope.minutes : $scope.minutes;\n $scope.hhours = $scope.hours < 10 ? '0' + $scope.hours : $scope.hours;\n $scope.ddays = $scope.days < 10 ? '0' + $scope.days : $scope.days;\n $scope.mmonths = $scope.months < 10 ? '0' + $scope.months : $scope.months;\n $scope.yyears = $scope.years < 10 ? '0' + $scope.years : $scope.years;\n\n }\n\n //determine initial values of time units and add AddSeconds functionality\n if ($scope.countdownattr) {\n $scope.millis = $scope.countdownattr * 1000;\n\n $scope.addCDSeconds = $element[0].addCDSeconds = function (extraSeconds) {\n $scope.countdown += extraSeconds;\n $scope.$digest();\n if (!$scope.isRunning) {\n $scope.start();\n }\n };\n\n $scope.$on('timer-add-cd-seconds', function (e, extraSeconds) {\n $timeout(function () {\n $scope.addCDSeconds(extraSeconds);\n });\n });\n\n $scope.$on('timer-set-countdown-seconds', function (e, countdownSeconds) {\n if (!$scope.isRunning) {\n $scope.clear();\n }\n\n $scope.countdown = countdownSeconds;\n $scope.millis = countdownSeconds * 1000;\n calculateTimeUnits();\n });\n } else {\n $scope.millis = 0;\n }\n calculateTimeUnits();\n\n var tick = function tick() {\n var typeTimer = null; // countdown or endTimeAttr\n $scope.millis = moment().diff($scope.startTime);\n var adjustment = $scope.millis % 1000;\n\n if ($scope.endTimeAttr) {\n typeTimer = $scope.endTimeAttr;\n $scope.millis = moment($scope.endTime).diff(moment());\n adjustment = $scope.interval - $scope.millis % 1000;\n }\n\n if ($scope.countdownattr) {\n typeTimer = $scope.countdownattr;\n $scope.millis = $scope.countdown * 1000;\n }\n\n if ($scope.millis < 0) {\n $scope.stop();\n $scope.millis = 0;\n calculateTimeUnits();\n if($scope.finishCallback) {\n $scope.$eval($scope.finishCallback);\n }\n return;\n }\n calculateTimeUnits();\n\n //We are not using $timeout for a reason. Please read here - https://github.com/siddii/angular-timer/pull/5\n $scope.timeoutId = setTimeout(function () {\n tick();\n $scope.$digest();\n }, $scope.interval - adjustment);\n\n $scope.$emit('timer-tick', {timeoutId: $scope.timeoutId, millis: $scope.millis});\n\n if ($scope.countdown > 0) {\n $scope.countdown--;\n }\n else if ($scope.countdown <= 0) {\n $scope.stop();\n if($scope.finishCallback) {\n $scope.$eval($scope.finishCallback);\n }\n }\n\n if(typeTimer !== null){\n //calculate progress bar\n $scope.progressBar = progressBarService.calculateProgressBar($scope.startTime, $scope.millis, $scope.endTime, $scope.countdownattr);\n\n if($scope.progressBar === 100){\n $scope.displayProgressActive = ''; //No more Bootstrap active effect\n }\n }\n };\n\n if ($scope.autoStart === undefined || $scope.autoStart === true) {\n $scope.start();\n }\n }]\n };\n }]);\n\n/* commonjs package manager support (eg componentjs) */\nif (typeof module !== \"undefined\" && typeof exports !== \"undefined\" && module.exports === exports){\n module.exports = timerModule;\n}\n\nvar app = angular.module('timer');\n\napp.factory('I18nService', function() {\n\n var I18nService = function() {};\n\n I18nService.prototype.language = 'en';\n I18nService.prototype.fallback = 'en';\n I18nService.prototype.timeHumanizer = {};\n\n I18nService.prototype.init = function init(lang, fallback) {\n var supported_languages = humanizeDuration.getSupportedLanguages();\n\n this.fallback = (fallback !== undefined) ? fallback : 'en';\n if (supported_languages.indexOf(fallback) === -1) {\n this.fallback = 'en';\n }\n\n this.language = lang;\n if (supported_languages.indexOf(lang) === -1) {\n this.language = this.fallback;\n }\n\n //moment init\n moment.locale(this.language); //@TODO maybe to remove, it should be handle by the user's application itself, and not inside the directive\n\n //human duration init, using it because momentjs does not allow accurate time (\n // momentJS: a few moment ago, human duration : 4 seconds ago\n this.timeHumanizer = humanizeDuration.humanizer({\n language: this.language,\n halfUnit:false\n });\n };\n\n /**\n * get time with units from momentJS i18n\n * @param {int} millis\n * @returns {{millis: string, seconds: string, minutes: string, hours: string, days: string, months: string, years: string}}\n */\n I18nService.prototype.getTimeUnits = function getTimeUnits(millis) {\n var diffFromAlarm = Math.round(millis/1000) * 1000; //time in milliseconds, get rid of the last 3 ms value to avoid 2.12 seconds display\n\n var time = {};\n\n if (typeof this.timeHumanizer != 'undefined'){\n time = {\n 'millis' : this.timeHumanizer(diffFromAlarm, { units: [\"milliseconds\"] }),\n 'seconds' : this.timeHumanizer(diffFromAlarm, { units: [\"seconds\"] }),\n 'minutes' : this.timeHumanizer(diffFromAlarm, { units: [\"minutes\", \"seconds\"] }) ,\n 'hours' : this.timeHumanizer(diffFromAlarm, { units: [\"hours\", \"minutes\", \"seconds\"] }) ,\n 'days' : this.timeHumanizer(diffFromAlarm, { units: [\"days\", \"hours\", \"minutes\", \"seconds\"] }) ,\n 'months' : this.timeHumanizer(diffFromAlarm, { units: [\"months\", \"days\", \"hours\", \"minutes\", \"seconds\"] }) ,\n 'years' : this.timeHumanizer(diffFromAlarm, { units: [\"years\", \"months\", \"days\", \"hours\", \"minutes\", \"seconds\"] })\n };\n }\n else {\n console.error('i18nService has not been initialized. You must call i18nService.init(\"en\") for example');\n }\n\n return time;\n };\n\n return I18nService;\n});\n\nvar app = angular.module('timer');\n\napp.factory('progressBarService', function() {\n\n var ProgressBarService = function() {};\n\n /**\n * calculate the remaining time in a progress bar in percentage\n * @param {momentjs} startValue in seconds\n * @param {integer} currentCountdown, where are we in the countdown\n * @param {integer} remainingTime, remaining milliseconds\n * @param {integer} endTime, end time, can be undefined\n * @param {integer} coutdown, original coutdown value, can be undefined\n *\n * joke : https://www.youtube.com/watch?v=gENVB6tjq_M\n * @return {float} 0 --> 100\n */\n ProgressBarService.prototype.calculateProgressBar = function calculateProgressBar(startValue, remainingTime, endTimeAttr, coutdown) {\n var displayProgressBar = 0,\n endTimeValue,\n initialCountdown;\n\n remainingTime = remainingTime / 1000; //seconds\n\n\n if(endTimeAttr !== null){\n endTimeValue = moment(endTimeAttr);\n initialCountdown = endTimeValue.diff(startValue, 'seconds');\n displayProgressBar = remainingTime * 100 / initialCountdown;\n }\n else {\n displayProgressBar = remainingTime * 100 / coutdown;\n }\n\n displayProgressBar = 100 - displayProgressBar; //To have 0 to 100 and not 100 to 0\n displayProgressBar = Math.round(displayProgressBar * 10) / 10; //learn more why : http://stackoverflow.com/questions/588004/is-floating-point-math-broken\n\n if(displayProgressBar > 100){ //security\n displayProgressBar = 100;\n }\n\n return displayProgressBar;\n };\n\n return new ProgressBarService();\n});\n\n/*!\n * angular-translate - v2.8.1 - 2015-10-01\n * \n * Copyright (c) 2015 The angular-translate team, Pascal Precht; Licensed MIT\n */\n(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module unless amdModuleId is set\n define([], function () {\n return (factory());\n });\n } else if (typeof exports === 'object') {\n // Node. Does not work with strict CommonJS, but\n // only CommonJS-like environments that support module.exports,\n // like Node.\n module.exports = factory();\n } else {\n factory();\n }\n}(this, function () {\n\n/**\n * @ngdoc overview\n * @name pascalprecht.translate\n *\n * @description\n * The main module which holds everything together.\n */\nangular.module('pascalprecht.translate', ['ng'])\n .run(runTranslate);\n\nfunction runTranslate($translate) {\n\n 'use strict';\n\n var key = $translate.storageKey(),\n storage = $translate.storage();\n\n var fallbackFromIncorrectStorageValue = function () {\n var preferred = $translate.preferredLanguage();\n if (angular.isString(preferred)) {\n $translate.use(preferred);\n // $translate.use() will also remember the language.\n // So, we don't need to call storage.put() here.\n } else {\n storage.put(key, $translate.use());\n }\n };\n\n fallbackFromIncorrectStorageValue.displayName = 'fallbackFromIncorrectStorageValue';\n\n if (storage) {\n if (!storage.get(key)) {\n fallbackFromIncorrectStorageValue();\n } else {\n $translate.use(storage.get(key))['catch'](fallbackFromIncorrectStorageValue);\n }\n } else if (angular.isString($translate.preferredLanguage())) {\n $translate.use($translate.preferredLanguage());\n }\n}\nrunTranslate.$inject = ['$translate'];\n\nrunTranslate.displayName = 'runTranslate';\n\n/**\n * @ngdoc object\n * @name pascalprecht.translate.$translateSanitizationProvider\n *\n * @description\n *\n * Configurations for $translateSanitization\n */\nangular.module('pascalprecht.translate').provider('$translateSanitization', $translateSanitizationProvider);\n\nfunction $translateSanitizationProvider () {\n\n 'use strict';\n\n var $sanitize,\n currentStrategy = null, // TODO change to either 'sanitize', 'escape' or ['sanitize', 'escapeParameters'] in 3.0.\n hasConfiguredStrategy = false,\n hasShownNoStrategyConfiguredWarning = false,\n strategies;\n\n /**\n * Definition of a sanitization strategy function\n * @callback StrategyFunction\n * @param {string|object} value - value to be sanitized (either a string or an interpolated value map)\n * @param {string} mode - either 'text' for a string (translation) or 'params' for the interpolated params\n * @return {string|object}\n */\n\n /**\n * @ngdoc property\n * @name strategies\n * @propertyOf pascalprecht.translate.$translateSanitizationProvider\n *\n * @description\n * Following strategies are built-in:\n * \n * - sanitize
\n * - Sanitizes HTML in the translation text using $sanitize
\n * - escape
\n * - Escapes HTML in the translation
\n * - sanitizeParameters
\n * - Sanitizes HTML in the values of the interpolation parameters using $sanitize
\n * - escapeParameters
\n * - Escapes HTML in the values of the interpolation parameters
\n * - escaped
\n * - Support legacy strategy name 'escaped' for backwards compatibility (will be removed in 3.0)
\n *
\n *\n */\n\n strategies = {\n sanitize: function (value, mode) {\n if (mode === 'text') {\n value = htmlSanitizeValue(value);\n }\n return value;\n },\n escape: function (value, mode) {\n if (mode === 'text') {\n value = htmlEscapeValue(value);\n }\n return value;\n },\n sanitizeParameters: function (value, mode) {\n if (mode === 'params') {\n value = mapInterpolationParameters(value, htmlSanitizeValue);\n }\n return value;\n },\n escapeParameters: function (value, mode) {\n if (mode === 'params') {\n value = mapInterpolationParameters(value, htmlEscapeValue);\n }\n return value;\n }\n };\n // Support legacy strategy name 'escaped' for backwards compatibility.\n // TODO should be removed in 3.0\n strategies.escaped = strategies.escapeParameters;\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateSanitizationProvider#addStrategy\n * @methodOf pascalprecht.translate.$translateSanitizationProvider\n *\n * @description\n * Adds a sanitization strategy to the list of known strategies.\n *\n * @param {string} strategyName - unique key for a strategy\n * @param {StrategyFunction} strategyFunction - strategy function\n * @returns {object} this\n */\n this.addStrategy = function (strategyName, strategyFunction) {\n strategies[strategyName] = strategyFunction;\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateSanitizationProvider#removeStrategy\n * @methodOf pascalprecht.translate.$translateSanitizationProvider\n *\n * @description\n * Removes a sanitization strategy from the list of known strategies.\n *\n * @param {string} strategyName - unique key for a strategy\n * @returns {object} this\n */\n this.removeStrategy = function (strategyName) {\n delete strategies[strategyName];\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateSanitizationProvider#useStrategy\n * @methodOf pascalprecht.translate.$translateSanitizationProvider\n *\n * @description\n * Selects a sanitization strategy. When an array is provided the strategies will be executed in order.\n *\n * @param {string|StrategyFunction|array} strategy The sanitization strategy / strategies which should be used. Either a name of an existing strategy, a custom strategy function, or an array consisting of multiple names and / or custom functions.\n * @returns {object} this\n */\n this.useStrategy = function (strategy) {\n hasConfiguredStrategy = true;\n currentStrategy = strategy;\n return this;\n };\n\n /**\n * @ngdoc object\n * @name pascalprecht.translate.$translateSanitization\n * @requires $injector\n * @requires $log\n *\n * @description\n * Sanitizes interpolation parameters and translated texts.\n *\n */\n this.$get = ['$injector', '$log', function ($injector, $log) {\n\n var cachedStrategyMap = {};\n\n var applyStrategies = function (value, mode, selectedStrategies) {\n angular.forEach(selectedStrategies, function (selectedStrategy) {\n if (angular.isFunction(selectedStrategy)) {\n value = selectedStrategy(value, mode);\n } else if (angular.isFunction(strategies[selectedStrategy])) {\n value = strategies[selectedStrategy](value, mode);\n } else if (angular.isString(strategies[selectedStrategy])) {\n if (!cachedStrategyMap[strategies[selectedStrategy]]) {\n try {\n cachedStrategyMap[strategies[selectedStrategy]] = $injector.get(strategies[selectedStrategy]);\n } catch (e) {\n cachedStrategyMap[strategies[selectedStrategy]] = function() {};\n throw new Error('pascalprecht.translate.$translateSanitization: Unknown sanitization strategy: \\'' + selectedStrategy + '\\'');\n }\n }\n value = cachedStrategyMap[strategies[selectedStrategy]](value, mode);\n } else {\n throw new Error('pascalprecht.translate.$translateSanitization: Unknown sanitization strategy: \\'' + selectedStrategy + '\\'');\n }\n });\n return value;\n };\n\n // TODO: should be removed in 3.0\n var showNoStrategyConfiguredWarning = function () {\n if (!hasConfiguredStrategy && !hasShownNoStrategyConfiguredWarning) {\n $log.warn('pascalprecht.translate.$translateSanitization: No sanitization strategy has been configured. This can have serious security implications. See http://angular-translate.github.io/docs/#/guide/19_security for details.');\n hasShownNoStrategyConfiguredWarning = true;\n }\n };\n\n if ($injector.has('$sanitize')) {\n $sanitize = $injector.get('$sanitize');\n }\n\n return {\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateSanitization#useStrategy\n * @methodOf pascalprecht.translate.$translateSanitization\n *\n * @description\n * Selects a sanitization strategy. When an array is provided the strategies will be executed in order.\n *\n * @param {string|StrategyFunction|array} strategy The sanitization strategy / strategies which should be used. Either a name of an existing strategy, a custom strategy function, or an array consisting of multiple names and / or custom functions.\n */\n useStrategy: (function (self) {\n return function (strategy) {\n self.useStrategy(strategy);\n };\n })(this),\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateSanitization#sanitize\n * @methodOf pascalprecht.translate.$translateSanitization\n *\n * @description\n * Sanitizes a value.\n *\n * @param {string|object} value The value which should be sanitized.\n * @param {string} mode The current sanitization mode, either 'params' or 'text'.\n * @param {string|StrategyFunction|array} [strategy] Optional custom strategy which should be used instead of the currently selected strategy.\n * @returns {string|object} sanitized value\n */\n sanitize: function (value, mode, strategy) {\n if (!currentStrategy) {\n showNoStrategyConfiguredWarning();\n }\n\n if (arguments.length < 3) {\n strategy = currentStrategy;\n }\n\n if (!strategy) {\n return value;\n }\n\n var selectedStrategies = angular.isArray(strategy) ? strategy : [strategy];\n return applyStrategies(value, mode, selectedStrategies);\n }\n };\n }];\n\n var htmlEscapeValue = function (value) {\n var element = angular.element('');\n element.text(value); // not chainable, see #1044\n return element.html();\n };\n\n var htmlSanitizeValue = function (value) {\n if (!$sanitize) {\n throw new Error('pascalprecht.translate.$translateSanitization: Error cannot find $sanitize service. Either include the ngSanitize module (https://docs.angularjs.org/api/ngSanitize) or use a sanitization strategy which does not depend on $sanitize, such as \\'escape\\'.');\n }\n return $sanitize(value);\n };\n\n var mapInterpolationParameters = function (value, iteratee) {\n if (angular.isObject(value)) {\n var result = angular.isArray(value) ? [] : {};\n\n angular.forEach(value, function (propertyValue, propertyKey) {\n result[propertyKey] = mapInterpolationParameters(propertyValue, iteratee);\n });\n\n return result;\n } else if (angular.isNumber(value)) {\n return value;\n } else {\n return iteratee(value);\n }\n };\n}\n\n/**\n * @ngdoc object\n * @name pascalprecht.translate.$translateProvider\n * @description\n *\n * $translateProvider allows developers to register translation-tables, asynchronous loaders\n * and similar to configure translation behavior directly inside of a module.\n *\n */\nangular.module('pascalprecht.translate')\n.constant('pascalprechtTranslateOverrider', {})\n.provider('$translate', $translate);\n\nfunction $translate($STORAGE_KEY, $windowProvider, $translateSanitizationProvider, pascalprechtTranslateOverrider) {\n\n 'use strict';\n\n var $translationTable = {},\n $preferredLanguage,\n $availableLanguageKeys = [],\n $languageKeyAliases,\n $fallbackLanguage,\n $fallbackWasString,\n $uses,\n $nextLang,\n $storageFactory,\n $storageKey = $STORAGE_KEY,\n $storagePrefix,\n $missingTranslationHandlerFactory,\n $interpolationFactory,\n $interpolatorFactories = [],\n $loaderFactory,\n $cloakClassName = 'translate-cloak',\n $loaderOptions,\n $notFoundIndicatorLeft,\n $notFoundIndicatorRight,\n $postCompilingEnabled = false,\n $forceAsyncReloadEnabled = false,\n $nestedObjectDelimeter = '.',\n $isReady = false,\n loaderCache,\n directivePriority = 0,\n statefulFilter = true,\n uniformLanguageTagResolver = 'default',\n languageTagResolver = {\n 'default': function (tag) {\n return (tag || '').split('-').join('_');\n },\n java: function (tag) {\n var temp = (tag || '').split('-').join('_');\n var parts = temp.split('_');\n return parts.length > 1 ? (parts[0].toLowerCase() + '_' + parts[1].toUpperCase()) : temp;\n },\n bcp47: function (tag) {\n var temp = (tag || '').split('_').join('-');\n var parts = temp.split('-');\n return parts.length > 1 ? (parts[0].toLowerCase() + '-' + parts[1].toUpperCase()) : temp;\n }\n };\n\n var version = '2.8.1';\n\n // tries to determine the browsers language\n var getFirstBrowserLanguage = function () {\n\n // internal purpose only\n if (angular.isFunction(pascalprechtTranslateOverrider.getLocale)) {\n return pascalprechtTranslateOverrider.getLocale();\n }\n\n var nav = $windowProvider.$get().navigator,\n browserLanguagePropertyKeys = ['language', 'browserLanguage', 'systemLanguage', 'userLanguage'],\n i,\n language;\n\n // support for HTML 5.1 \"navigator.languages\"\n if (angular.isArray(nav.languages)) {\n for (i = 0; i < nav.languages.length; i++) {\n language = nav.languages[i];\n if (language && language.length) {\n return language;\n }\n }\n }\n\n // support for other well known properties in browsers\n for (i = 0; i < browserLanguagePropertyKeys.length; i++) {\n language = nav[browserLanguagePropertyKeys[i]];\n if (language && language.length) {\n return language;\n }\n }\n\n return null;\n };\n getFirstBrowserLanguage.displayName = 'angular-translate/service: getFirstBrowserLanguage';\n\n // tries to determine the browsers locale\n var getLocale = function () {\n var locale = getFirstBrowserLanguage() || '';\n if (languageTagResolver[uniformLanguageTagResolver]) {\n locale = languageTagResolver[uniformLanguageTagResolver](locale);\n }\n return locale;\n };\n getLocale.displayName = 'angular-translate/service: getLocale';\n\n /**\n * @name indexOf\n * @private\n *\n * @description\n * indexOf polyfill. Kinda sorta.\n *\n * @param {array} array Array to search in.\n * @param {string} searchElement Element to search for.\n *\n * @returns {int} Index of search element.\n */\n var indexOf = function(array, searchElement) {\n for (var i = 0, len = array.length; i < len; i++) {\n if (array[i] === searchElement) {\n return i;\n }\n }\n return -1;\n };\n\n /**\n * @name trim\n * @private\n *\n * @description\n * trim polyfill\n *\n * @returns {string} The string stripped of whitespace from both ends\n */\n var trim = function() {\n return this.toString().replace(/^\\s+|\\s+$/g, '');\n };\n\n var negotiateLocale = function (preferred) {\n\n var avail = [],\n locale = angular.lowercase(preferred),\n i = 0,\n n = $availableLanguageKeys.length;\n\n for (; i < n; i++) {\n avail.push(angular.lowercase($availableLanguageKeys[i]));\n }\n\n if (indexOf(avail, locale) > -1) {\n return preferred;\n }\n\n if ($languageKeyAliases) {\n var alias;\n for (var langKeyAlias in $languageKeyAliases) {\n var hasWildcardKey = false;\n var hasExactKey = Object.prototype.hasOwnProperty.call($languageKeyAliases, langKeyAlias) &&\n angular.lowercase(langKeyAlias) === angular.lowercase(preferred);\n\n if (langKeyAlias.slice(-1) === '*') {\n hasWildcardKey = langKeyAlias.slice(0, -1) === preferred.slice(0, langKeyAlias.length-1);\n }\n if (hasExactKey || hasWildcardKey) {\n alias = $languageKeyAliases[langKeyAlias];\n if (indexOf(avail, angular.lowercase(alias)) > -1) {\n return alias;\n }\n }\n }\n }\n\n if (preferred) {\n var parts = preferred.split('_');\n\n if (parts.length > 1 && indexOf(avail, angular.lowercase(parts[0])) > -1) {\n return parts[0];\n }\n }\n\n // If everything fails, just return the preferred, unchanged.\n return preferred;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#translations\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Registers a new translation table for specific language key.\n *\n * To register a translation table for specific language, pass a defined language\n * key as first parameter.\n *\n * \n * // register translation table for language: 'de_DE'\n * $translateProvider.translations('de_DE', {\n * 'GREETING': 'Hallo Welt!'\n * });\n *\n * // register another one\n * $translateProvider.translations('en_US', {\n * 'GREETING': 'Hello world!'\n * });\n *
\n *\n * When registering multiple translation tables for for the same language key,\n * the actual translation table gets extended. This allows you to define module\n * specific translation which only get added, once a specific module is loaded in\n * your app.\n *\n * Invoking this method with no arguments returns the translation table which was\n * registered with no language key. Invoking it with a language key returns the\n * related translation table.\n *\n * @param {string} key A language key.\n * @param {object} translationTable A plain old JavaScript object that represents a translation table.\n *\n */\n var translations = function (langKey, translationTable) {\n\n if (!langKey && !translationTable) {\n return $translationTable;\n }\n\n if (langKey && !translationTable) {\n if (angular.isString(langKey)) {\n return $translationTable[langKey];\n }\n } else {\n if (!angular.isObject($translationTable[langKey])) {\n $translationTable[langKey] = {};\n }\n angular.extend($translationTable[langKey], flatObject(translationTable));\n }\n return this;\n };\n\n this.translations = translations;\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#cloakClassName\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n *\n * Let's you change the class name for `translate-cloak` directive.\n * Default class name is `translate-cloak`.\n *\n * @param {string} name translate-cloak class name\n */\n this.cloakClassName = function (name) {\n if (!name) {\n return $cloakClassName;\n }\n $cloakClassName = name;\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#nestedObjectDelimeter\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n *\n * Let's you change the delimiter for namespaced translations.\n * Default delimiter is `.`.\n *\n * @param {string} delimiter namespace separator\n */\n this.nestedObjectDelimeter = function (delimiter) {\n if (!delimiter) {\n return $nestedObjectDelimeter;\n }\n $nestedObjectDelimeter = delimiter;\n return this;\n };\n\n /**\n * @name flatObject\n * @private\n *\n * @description\n * Flats an object. This function is used to flatten given translation data with\n * namespaces, so they are later accessible via dot notation.\n */\n var flatObject = function (data, path, result, prevKey) {\n var key, keyWithPath, keyWithShortPath, val;\n\n if (!path) {\n path = [];\n }\n if (!result) {\n result = {};\n }\n for (key in data) {\n if (!Object.prototype.hasOwnProperty.call(data, key)) {\n continue;\n }\n val = data[key];\n if (angular.isObject(val)) {\n flatObject(val, path.concat(key), result, key);\n } else {\n keyWithPath = path.length ? ('' + path.join($nestedObjectDelimeter) + $nestedObjectDelimeter + key) : key;\n if(path.length && key === prevKey){\n // Create shortcut path (foo.bar == foo.bar.bar)\n keyWithShortPath = '' + path.join($nestedObjectDelimeter);\n // Link it to original path\n result[keyWithShortPath] = '@:' + keyWithPath;\n }\n result[keyWithPath] = val;\n }\n }\n return result;\n };\n flatObject.displayName = 'flatObject';\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#addInterpolation\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Adds interpolation services to angular-translate, so it can manage them.\n *\n * @param {object} factory Interpolation service factory\n */\n this.addInterpolation = function (factory) {\n $interpolatorFactories.push(factory);\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useMessageFormatInterpolation\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate to use interpolation functionality of messageformat.js.\n * This is useful when having high level pluralization and gender selection.\n */\n this.useMessageFormatInterpolation = function () {\n return this.useInterpolation('$translateMessageFormatInterpolation');\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useInterpolation\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate which interpolation style to use as default, application-wide.\n * Simply pass a factory/service name. The interpolation service has to implement\n * the correct interface.\n *\n * @param {string} factory Interpolation service name.\n */\n this.useInterpolation = function (factory) {\n $interpolationFactory = factory;\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useSanitizeStrategy\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Simply sets a sanitation strategy type.\n *\n * @param {string} value Strategy type.\n */\n this.useSanitizeValueStrategy = function (value) {\n $translateSanitizationProvider.useStrategy(value);\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#preferredLanguage\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells the module which of the registered translation tables to use for translation\n * at initial startup by passing a language key. Similar to `$translateProvider#use`\n * only that it says which language to **prefer**.\n *\n * @param {string} langKey A language key.\n */\n this.preferredLanguage = function(langKey) {\n if (langKey) {\n setupPreferredLanguage(langKey);\n return this;\n }\n return $preferredLanguage;\n };\n var setupPreferredLanguage = function (langKey) {\n if (langKey) {\n $preferredLanguage = langKey;\n }\n return $preferredLanguage;\n };\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#translationNotFoundIndicator\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Sets an indicator which is used when a translation isn't found. E.g. when\n * setting the indicator as 'X' and one tries to translate a translation id\n * called `NOT_FOUND`, this will result in `X NOT_FOUND X`.\n *\n * Internally this methods sets a left indicator and a right indicator using\n * `$translateProvider.translationNotFoundIndicatorLeft()` and\n * `$translateProvider.translationNotFoundIndicatorRight()`.\n *\n * **Note**: These methods automatically add a whitespace between the indicators\n * and the translation id.\n *\n * @param {string} indicator An indicator, could be any string.\n */\n this.translationNotFoundIndicator = function (indicator) {\n this.translationNotFoundIndicatorLeft(indicator);\n this.translationNotFoundIndicatorRight(indicator);\n return this;\n };\n\n /**\n * ngdoc function\n * @name pascalprecht.translate.$translateProvider#translationNotFoundIndicatorLeft\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Sets an indicator which is used when a translation isn't found left to the\n * translation id.\n *\n * @param {string} indicator An indicator.\n */\n this.translationNotFoundIndicatorLeft = function (indicator) {\n if (!indicator) {\n return $notFoundIndicatorLeft;\n }\n $notFoundIndicatorLeft = indicator;\n return this;\n };\n\n /**\n * ngdoc function\n * @name pascalprecht.translate.$translateProvider#translationNotFoundIndicatorLeft\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Sets an indicator which is used when a translation isn't found right to the\n * translation id.\n *\n * @param {string} indicator An indicator.\n */\n this.translationNotFoundIndicatorRight = function (indicator) {\n if (!indicator) {\n return $notFoundIndicatorRight;\n }\n $notFoundIndicatorRight = indicator;\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#fallbackLanguage\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells the module which of the registered translation tables to use when missing translations\n * at initial startup by passing a language key. Similar to `$translateProvider#use`\n * only that it says which language to **fallback**.\n *\n * @param {string||array} langKey A language key.\n *\n */\n this.fallbackLanguage = function (langKey) {\n fallbackStack(langKey);\n return this;\n };\n\n var fallbackStack = function (langKey) {\n if (langKey) {\n if (angular.isString(langKey)) {\n $fallbackWasString = true;\n $fallbackLanguage = [ langKey ];\n } else if (angular.isArray(langKey)) {\n $fallbackWasString = false;\n $fallbackLanguage = langKey;\n }\n if (angular.isString($preferredLanguage) && indexOf($fallbackLanguage, $preferredLanguage) < 0) {\n $fallbackLanguage.push($preferredLanguage);\n }\n\n return this;\n } else {\n if ($fallbackWasString) {\n return $fallbackLanguage[0];\n } else {\n return $fallbackLanguage;\n }\n }\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#use\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Set which translation table to use for translation by given language key. When\n * trying to 'use' a language which isn't provided, it'll throw an error.\n *\n * You actually don't have to use this method since `$translateProvider#preferredLanguage`\n * does the job too.\n *\n * @param {string} langKey A language key.\n */\n this.use = function (langKey) {\n if (langKey) {\n if (!$translationTable[langKey] && (!$loaderFactory)) {\n // only throw an error, when not loading translation data asynchronously\n throw new Error('$translateProvider couldn\\'t find translationTable for langKey: \\'' + langKey + '\\'');\n }\n $uses = langKey;\n return this;\n }\n return $uses;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#storageKey\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells the module which key must represent the choosed language by a user in the storage.\n *\n * @param {string} key A key for the storage.\n */\n var storageKey = function(key) {\n if (!key) {\n if ($storagePrefix) {\n return $storagePrefix + $storageKey;\n }\n return $storageKey;\n }\n $storageKey = key;\n return this;\n };\n\n this.storageKey = storageKey;\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useUrlLoader\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate to use `$translateUrlLoader` extension service as loader.\n *\n * @param {string} url Url\n * @param {Object=} options Optional configuration object\n */\n this.useUrlLoader = function (url, options) {\n return this.useLoader('$translateUrlLoader', angular.extend({ url: url }, options));\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useStaticFilesLoader\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate to use `$translateStaticFilesLoader` extension service as loader.\n *\n * @param {Object=} options Optional configuration object\n */\n this.useStaticFilesLoader = function (options) {\n return this.useLoader('$translateStaticFilesLoader', options);\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useLoader\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate to use any other service as loader.\n *\n * @param {string} loaderFactory Factory name to use\n * @param {Object=} options Optional configuration object\n */\n this.useLoader = function (loaderFactory, options) {\n $loaderFactory = loaderFactory;\n $loaderOptions = options || {};\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useLocalStorage\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate to use `$translateLocalStorage` service as storage layer.\n *\n */\n this.useLocalStorage = function () {\n return this.useStorage('$translateLocalStorage');\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useCookieStorage\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate to use `$translateCookieStorage` service as storage layer.\n */\n this.useCookieStorage = function () {\n return this.useStorage('$translateCookieStorage');\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useStorage\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate to use custom service as storage layer.\n */\n this.useStorage = function (storageFactory) {\n $storageFactory = storageFactory;\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#storagePrefix\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Sets prefix for storage key.\n *\n * @param {string} prefix Storage key prefix\n */\n this.storagePrefix = function (prefix) {\n if (!prefix) {\n return prefix;\n }\n $storagePrefix = prefix;\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useMissingTranslationHandlerLog\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate to use built-in log handler when trying to translate\n * a translation Id which doesn't exist.\n *\n * This is actually a shortcut method for `useMissingTranslationHandler()`.\n *\n */\n this.useMissingTranslationHandlerLog = function () {\n return this.useMissingTranslationHandler('$translateMissingTranslationHandlerLog');\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useMissingTranslationHandler\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Expects a factory name which later gets instantiated with `$injector`.\n * This method can be used to tell angular-translate to use a custom\n * missingTranslationHandler. Just build a factory which returns a function\n * and expects a translation id as argument.\n *\n * Example:\n * \n * app.config(function ($translateProvider) {\n * $translateProvider.useMissingTranslationHandler('customHandler');\n * });\n *\n * app.factory('customHandler', function (dep1, dep2) {\n * return function (translationId) {\n * // something with translationId and dep1 and dep2\n * };\n * });\n *
\n *\n * @param {string} factory Factory name\n */\n this.useMissingTranslationHandler = function (factory) {\n $missingTranslationHandlerFactory = factory;\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#usePostCompiling\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * If post compiling is enabled, all translated values will be processed\n * again with AngularJS' $compile.\n *\n * Example:\n * \n * app.config(function ($translateProvider) {\n * $translateProvider.usePostCompiling(true);\n * });\n *
\n *\n * @param {string} factory Factory name\n */\n this.usePostCompiling = function (value) {\n $postCompilingEnabled = !(!value);\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#forceAsyncReload\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * If force async reload is enabled, async loader will always be called\n * even if $translationTable already contains the language key, adding\n * possible new entries to the $translationTable.\n *\n * Example:\n * \n * app.config(function ($translateProvider) {\n * $translateProvider.forceAsyncReload(true);\n * });\n *
\n *\n * @param {boolean} value - valid values are true or false\n */\n this.forceAsyncReload = function (value) {\n $forceAsyncReloadEnabled = !(!value);\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#uniformLanguageTag\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate which language tag should be used as a result when determining\n * the current browser language.\n *\n * This setting must be set before invoking {@link pascalprecht.translate.$translateProvider#methods_determinePreferredLanguage determinePreferredLanguage()}.\n *\n * \n * $translateProvider\n * .uniformLanguageTag('bcp47')\n * .determinePreferredLanguage()\n *
\n *\n * The resolver currently supports:\n * * default\n * (traditionally: hyphens will be converted into underscores, i.e. en-US => en_US)\n * en-US => en_US\n * en_US => en_US\n * en-us => en_us\n * * java\n * like default, but the second part will be always in uppercase\n * en-US => en_US\n * en_US => en_US\n * en-us => en_US\n * * BCP 47 (RFC 4646 & 4647)\n * en-US => en-US\n * en_US => en-US\n * en-us => en-US\n *\n * See also:\n * * http://en.wikipedia.org/wiki/IETF_language_tag\n * * http://www.w3.org/International/core/langtags/\n * * http://tools.ietf.org/html/bcp47\n *\n * @param {string|object} options - options (or standard)\n * @param {string} options.standard - valid values are 'default', 'bcp47', 'java'\n */\n this.uniformLanguageTag = function (options) {\n\n if (!options) {\n options = {};\n } else if (angular.isString(options)) {\n options = {\n standard: options\n };\n }\n\n uniformLanguageTagResolver = options.standard;\n\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#determinePreferredLanguage\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Tells angular-translate to try to determine on its own which language key\n * to set as preferred language. When `fn` is given, angular-translate uses it\n * to determine a language key, otherwise it uses the built-in `getLocale()`\n * method.\n *\n * The `getLocale()` returns a language key in the format `[lang]_[country]` or\n * `[lang]` depending on what the browser provides.\n *\n * Use this method at your own risk, since not all browsers return a valid\n * locale (see {@link pascalprecht.translate.$translateProvider#methods_uniformLanguageTag uniformLanguageTag()}).\n *\n * @param {Function=} fn Function to determine a browser's locale\n */\n this.determinePreferredLanguage = function (fn) {\n\n var locale = (fn && angular.isFunction(fn)) ? fn() : getLocale();\n\n if (!$availableLanguageKeys.length) {\n $preferredLanguage = locale;\n } else {\n $preferredLanguage = negotiateLocale(locale);\n }\n\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#registerAvailableLanguageKeys\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Registers a set of language keys the app will work with. Use this method in\n * combination with\n * {@link pascalprecht.translate.$translateProvider#determinePreferredLanguage determinePreferredLanguage}.\n * When available languages keys are registered, angular-translate\n * tries to find the best fitting language key depending on the browsers locale,\n * considering your language key convention.\n *\n * @param {object} languageKeys Array of language keys the your app will use\n * @param {object=} aliases Alias map.\n */\n this.registerAvailableLanguageKeys = function (languageKeys, aliases) {\n if (languageKeys) {\n $availableLanguageKeys = languageKeys;\n if (aliases) {\n $languageKeyAliases = aliases;\n }\n return this;\n }\n return $availableLanguageKeys;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#useLoaderCache\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Registers a cache for internal $http based loaders.\n * {@link pascalprecht.translate.$translationCache $translationCache}.\n * When false the cache will be disabled (default). When true or undefined\n * the cache will be a default (see $cacheFactory). When an object it will\n * be treat as a cache object itself: the usage is $http({cache: cache})\n *\n * @param {object} cache boolean, string or cache-object\n */\n this.useLoaderCache = function (cache) {\n if (cache === false) {\n // disable cache\n loaderCache = undefined;\n } else if (cache === true) {\n // enable cache using AJS defaults\n loaderCache = true;\n } else if (typeof(cache) === 'undefined') {\n // enable cache using default\n loaderCache = '$translationCache';\n } else if (cache) {\n // enable cache using given one (see $cacheFactory)\n loaderCache = cache;\n }\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#directivePriority\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Sets the default priority of the translate directive. The standard value is `0`.\n * Calling this function without an argument will return the current value.\n *\n * @param {number} priority for the translate-directive\n */\n this.directivePriority = function (priority) {\n if (priority === undefined) {\n // getter\n return directivePriority;\n } else {\n // setter with chaining\n directivePriority = priority;\n return this;\n }\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateProvider#statefulFilter\n * @methodOf pascalprecht.translate.$translateProvider\n *\n * @description\n * Since AngularJS 1.3, filters which are not stateless (depending at the scope)\n * have to explicit define this behavior.\n * Sets whether the translate filter should be stateful or stateless. The standard value is `true`\n * meaning being stateful.\n * Calling this function without an argument will return the current value.\n *\n * @param {boolean} state - defines the state of the filter\n */\n this.statefulFilter = function (state) {\n if (state === undefined) {\n // getter\n return statefulFilter;\n } else {\n // setter with chaining\n statefulFilter = state;\n return this;\n }\n };\n\n /**\n * @ngdoc object\n * @name pascalprecht.translate.$translate\n * @requires $interpolate\n * @requires $log\n * @requires $rootScope\n * @requires $q\n *\n * @description\n * The `$translate` service is the actual core of angular-translate. It expects a translation id\n * and optional interpolate parameters to translate contents.\n *\n * \n * $translate('HEADLINE_TEXT').then(function (translation) {\n * $scope.translatedText = translation;\n * });\n *
\n *\n * @param {string|array} translationId A token which represents a translation id\n * This can be optionally an array of translation ids which\n * results that the function returns an object where each key\n * is the translation id and the value the translation.\n * @param {object=} interpolateParams An object hash for dynamic values\n * @param {string} interpolationId The id of the interpolation to use\n * @returns {object} promise\n */\n this.$get = [\n '$log',\n '$injector',\n '$rootScope',\n '$q',\n function ($log, $injector, $rootScope, $q) {\n\n var Storage,\n defaultInterpolator = $injector.get($interpolationFactory || '$translateDefaultInterpolation'),\n pendingLoader = false,\n interpolatorHashMap = {},\n langPromises = {},\n fallbackIndex,\n startFallbackIteration;\n\n var $translate = function (translationId, interpolateParams, interpolationId, defaultTranslationText) {\n\n // Duck detection: If the first argument is an array, a bunch of translations was requested.\n // The result is an object.\n if (angular.isArray(translationId)) {\n // Inspired by Q.allSettled by Kris Kowal\n // https://github.com/kriskowal/q/blob/b0fa72980717dc202ffc3cbf03b936e10ebbb9d7/q.js#L1553-1563\n // This transforms all promises regardless resolved or rejected\n var translateAll = function (translationIds) {\n var results = {}; // storing the actual results\n var promises = []; // promises to wait for\n // Wraps the promise a) being always resolved and b) storing the link id->value\n var translate = function (translationId) {\n var deferred = $q.defer();\n var regardless = function (value) {\n results[translationId] = value;\n deferred.resolve([translationId, value]);\n };\n // we don't care whether the promise was resolved or rejected; just store the values\n $translate(translationId, interpolateParams, interpolationId, defaultTranslationText).then(regardless, regardless);\n return deferred.promise;\n };\n for (var i = 0, c = translationIds.length; i < c; i++) {\n promises.push(translate(translationIds[i]));\n }\n // wait for all (including storing to results)\n return $q.all(promises).then(function () {\n // return the results\n return results;\n });\n };\n return translateAll(translationId);\n }\n\n var deferred = $q.defer();\n\n // trim off any whitespace\n if (translationId) {\n translationId = trim.apply(translationId);\n }\n\n var promiseToWaitFor = (function () {\n var promise = $preferredLanguage ?\n langPromises[$preferredLanguage] :\n langPromises[$uses];\n\n fallbackIndex = 0;\n\n if ($storageFactory && !promise) {\n // looks like there's no pending promise for $preferredLanguage or\n // $uses. Maybe there's one pending for a language that comes from\n // storage.\n var langKey = Storage.get($storageKey);\n promise = langPromises[langKey];\n\n if ($fallbackLanguage && $fallbackLanguage.length) {\n var index = indexOf($fallbackLanguage, langKey);\n // maybe the language from storage is also defined as fallback language\n // we increase the fallback language index to not search in that language\n // as fallback, since it's probably the first used language\n // in that case the index starts after the first element\n fallbackIndex = (index === 0) ? 1 : 0;\n\n // but we can make sure to ALWAYS fallback to preferred language at least\n if (indexOf($fallbackLanguage, $preferredLanguage) < 0) {\n $fallbackLanguage.push($preferredLanguage);\n }\n }\n }\n return promise;\n }());\n\n if (!promiseToWaitFor) {\n // no promise to wait for? okay. Then there's no loader registered\n // nor is a one pending for language that comes from storage.\n // We can just translate.\n determineTranslation(translationId, interpolateParams, interpolationId, defaultTranslationText).then(deferred.resolve, deferred.reject);\n } else {\n var promiseResolved = function () {\n determineTranslation(translationId, interpolateParams, interpolationId, defaultTranslationText).then(deferred.resolve, deferred.reject);\n };\n promiseResolved.displayName = 'promiseResolved';\n\n promiseToWaitFor['finally'](promiseResolved, deferred.reject);\n }\n return deferred.promise;\n };\n\n /**\n * @name applyNotFoundIndicators\n * @private\n *\n * @description\n * Applies not fount indicators to given translation id, if needed.\n * This function gets only executed, if a translation id doesn't exist,\n * which is why a translation id is expected as argument.\n *\n * @param {string} translationId Translation id.\n * @returns {string} Same as given translation id but applied with not found\n * indicators.\n */\n var applyNotFoundIndicators = function (translationId) {\n // applying notFoundIndicators\n if ($notFoundIndicatorLeft) {\n translationId = [$notFoundIndicatorLeft, translationId].join(' ');\n }\n if ($notFoundIndicatorRight) {\n translationId = [translationId, $notFoundIndicatorRight].join(' ');\n }\n return translationId;\n };\n\n /**\n * @name useLanguage\n * @private\n *\n * @description\n * Makes actual use of a language by setting a given language key as used\n * language and informs registered interpolators to also use the given\n * key as locale.\n *\n * @param {key} Locale key.\n */\n var useLanguage = function (key) {\n $uses = key;\n\n // make sure to store new language key before triggering success event\n if ($storageFactory) {\n Storage.put($translate.storageKey(), $uses);\n }\n\n $rootScope.$emit('$translateChangeSuccess', {language: key});\n\n // inform default interpolator\n defaultInterpolator.setLocale($uses);\n\n var eachInterpolator = function (interpolator, id) {\n interpolatorHashMap[id].setLocale($uses);\n };\n eachInterpolator.displayName = 'eachInterpolatorLocaleSetter';\n\n // inform all others too!\n angular.forEach(interpolatorHashMap, eachInterpolator);\n $rootScope.$emit('$translateChangeEnd', {language: key});\n };\n\n /**\n * @name loadAsync\n * @private\n *\n * @description\n * Kicks of registered async loader using `$injector` and applies existing\n * loader options. When resolved, it updates translation tables accordingly\n * or rejects with given language key.\n *\n * @param {string} key Language key.\n * @return {Promise} A promise.\n */\n var loadAsync = function (key) {\n if (!key) {\n throw 'No language key specified for loading.';\n }\n\n var deferred = $q.defer();\n\n $rootScope.$emit('$translateLoadingStart', {language: key});\n pendingLoader = true;\n\n var cache = loaderCache;\n if (typeof(cache) === 'string') {\n // getting on-demand instance of loader\n cache = $injector.get(cache);\n }\n\n var loaderOptions = angular.extend({}, $loaderOptions, {\n key: key,\n $http: angular.extend({}, {\n cache: cache\n }, $loaderOptions.$http)\n });\n\n var onLoaderSuccess = function (data) {\n var translationTable = {};\n $rootScope.$emit('$translateLoadingSuccess', {language: key});\n\n if (angular.isArray(data)) {\n angular.forEach(data, function (table) {\n angular.extend(translationTable, flatObject(table));\n });\n } else {\n angular.extend(translationTable, flatObject(data));\n }\n pendingLoader = false;\n deferred.resolve({\n key: key,\n table: translationTable\n });\n $rootScope.$emit('$translateLoadingEnd', {language: key});\n };\n onLoaderSuccess.displayName = 'onLoaderSuccess';\n\n var onLoaderError = function (key) {\n $rootScope.$emit('$translateLoadingError', {language: key});\n deferred.reject(key);\n $rootScope.$emit('$translateLoadingEnd', {language: key});\n };\n onLoaderError.displayName = 'onLoaderError';\n\n $injector.get($loaderFactory)(loaderOptions)\n .then(onLoaderSuccess, onLoaderError);\n\n return deferred.promise;\n };\n\n if ($storageFactory) {\n Storage = $injector.get($storageFactory);\n\n if (!Storage.get || !Storage.put) {\n throw new Error('Couldn\\'t use storage \\'' + $storageFactory + '\\', missing get() or put() method!');\n }\n }\n\n // if we have additional interpolations that were added via\n // $translateProvider.addInterpolation(), we have to map'em\n if ($interpolatorFactories.length) {\n var eachInterpolationFactory = function (interpolatorFactory) {\n var interpolator = $injector.get(interpolatorFactory);\n // setting initial locale for each interpolation service\n interpolator.setLocale($preferredLanguage || $uses);\n // make'em recognizable through id\n interpolatorHashMap[interpolator.getInterpolationIdentifier()] = interpolator;\n };\n eachInterpolationFactory.displayName = 'interpolationFactoryAdder';\n\n angular.forEach($interpolatorFactories, eachInterpolationFactory);\n }\n\n /**\n * @name getTranslationTable\n * @private\n *\n * @description\n * Returns a promise that resolves to the translation table\n * or is rejected if an error occurred.\n *\n * @param langKey\n * @returns {Q.promise}\n */\n var getTranslationTable = function (langKey) {\n var deferred = $q.defer();\n if (Object.prototype.hasOwnProperty.call($translationTable, langKey)) {\n deferred.resolve($translationTable[langKey]);\n } else if (langPromises[langKey]) {\n var onResolve = function (data) {\n translations(data.key, data.table);\n deferred.resolve(data.table);\n };\n onResolve.displayName = 'translationTableResolver';\n langPromises[langKey].then(onResolve, deferred.reject);\n } else {\n deferred.reject();\n }\n return deferred.promise;\n };\n\n /**\n * @name getFallbackTranslation\n * @private\n *\n * @description\n * Returns a promise that will resolve to the translation\n * or be rejected if no translation was found for the language.\n * This function is currently only used for fallback language translation.\n *\n * @param langKey The language to translate to.\n * @param translationId\n * @param interpolateParams\n * @param Interpolator\n * @returns {Q.promise}\n */\n var getFallbackTranslation = function (langKey, translationId, interpolateParams, Interpolator) {\n var deferred = $q.defer();\n\n var onResolve = function (translationTable) {\n if (Object.prototype.hasOwnProperty.call(translationTable, translationId)) {\n Interpolator.setLocale(langKey);\n var translation = translationTable[translationId];\n if (translation.substr(0, 2) === '@:') {\n getFallbackTranslation(langKey, translation.substr(2), interpolateParams, Interpolator)\n .then(deferred.resolve, deferred.reject);\n } else {\n deferred.resolve(Interpolator.interpolate(translationTable[translationId], interpolateParams));\n }\n Interpolator.setLocale($uses);\n } else {\n deferred.reject();\n }\n };\n onResolve.displayName = 'fallbackTranslationResolver';\n\n getTranslationTable(langKey).then(onResolve, deferred.reject);\n\n return deferred.promise;\n };\n\n /**\n * @name getFallbackTranslationInstant\n * @private\n *\n * @description\n * Returns a translation\n * This function is currently only used for fallback language translation.\n *\n * @param langKey The language to translate to.\n * @param translationId\n * @param interpolateParams\n * @param Interpolator\n * @returns {string} translation\n */\n var getFallbackTranslationInstant = function (langKey, translationId, interpolateParams, Interpolator) {\n var result, translationTable = $translationTable[langKey];\n\n if (translationTable && Object.prototype.hasOwnProperty.call(translationTable, translationId)) {\n Interpolator.setLocale(langKey);\n result = Interpolator.interpolate(translationTable[translationId], interpolateParams);\n if (result.substr(0, 2) === '@:') {\n return getFallbackTranslationInstant(langKey, result.substr(2), interpolateParams, Interpolator);\n }\n Interpolator.setLocale($uses);\n }\n\n return result;\n };\n\n\n /**\n * @name translateByHandler\n * @private\n *\n * Translate by missing translation handler.\n *\n * @param translationId\n * @returns translation created by $missingTranslationHandler or translationId is $missingTranslationHandler is\n * absent\n */\n var translateByHandler = function (translationId, interpolateParams) {\n // If we have a handler factory - we might also call it here to determine if it provides\n // a default text for a translationid that can't be found anywhere in our tables\n if ($missingTranslationHandlerFactory) {\n var resultString = $injector.get($missingTranslationHandlerFactory)(translationId, $uses, interpolateParams);\n if (resultString !== undefined) {\n return resultString;\n } else {\n return translationId;\n }\n } else {\n return translationId;\n }\n };\n\n /**\n * @name resolveForFallbackLanguage\n * @private\n *\n * Recursive helper function for fallbackTranslation that will sequentially look\n * for a translation in the fallbackLanguages starting with fallbackLanguageIndex.\n *\n * @param fallbackLanguageIndex\n * @param translationId\n * @param interpolateParams\n * @param Interpolator\n * @returns {Q.promise} Promise that will resolve to the translation.\n */\n var resolveForFallbackLanguage = function (fallbackLanguageIndex, translationId, interpolateParams, Interpolator, defaultTranslationText) {\n var deferred = $q.defer();\n\n if (fallbackLanguageIndex < $fallbackLanguage.length) {\n var langKey = $fallbackLanguage[fallbackLanguageIndex];\n getFallbackTranslation(langKey, translationId, interpolateParams, Interpolator).then(\n deferred.resolve,\n function () {\n // Look in the next fallback language for a translation.\n // It delays the resolving by passing another promise to resolve.\n resolveForFallbackLanguage(fallbackLanguageIndex + 1, translationId, interpolateParams, Interpolator, defaultTranslationText).then(deferred.resolve);\n }\n );\n } else {\n // No translation found in any fallback language\n // if a default translation text is set in the directive, then return this as a result\n if (defaultTranslationText) {\n deferred.resolve(defaultTranslationText);\n } else {\n // if no default translation is set and an error handler is defined, send it to the handler\n // and then return the result\n deferred.resolve(translateByHandler(translationId, interpolateParams));\n }\n }\n return deferred.promise;\n };\n\n /**\n * @name resolveForFallbackLanguageInstant\n * @private\n *\n * Recursive helper function for fallbackTranslation that will sequentially look\n * for a translation in the fallbackLanguages starting with fallbackLanguageIndex.\n *\n * @param fallbackLanguageIndex\n * @param translationId\n * @param interpolateParams\n * @param Interpolator\n * @returns {string} translation\n */\n var resolveForFallbackLanguageInstant = function (fallbackLanguageIndex, translationId, interpolateParams, Interpolator) {\n var result;\n\n if (fallbackLanguageIndex < $fallbackLanguage.length) {\n var langKey = $fallbackLanguage[fallbackLanguageIndex];\n result = getFallbackTranslationInstant(langKey, translationId, interpolateParams, Interpolator);\n if (!result) {\n result = resolveForFallbackLanguageInstant(fallbackLanguageIndex + 1, translationId, interpolateParams, Interpolator);\n }\n }\n return result;\n };\n\n /**\n * Translates with the usage of the fallback languages.\n *\n * @param translationId\n * @param interpolateParams\n * @param Interpolator\n * @returns {Q.promise} Promise, that resolves to the translation.\n */\n var fallbackTranslation = function (translationId, interpolateParams, Interpolator, defaultTranslationText) {\n // Start with the fallbackLanguage with index 0\n return resolveForFallbackLanguage((startFallbackIteration>0 ? startFallbackIteration : fallbackIndex), translationId, interpolateParams, Interpolator, defaultTranslationText);\n };\n\n /**\n * Translates with the usage of the fallback languages.\n *\n * @param translationId\n * @param interpolateParams\n * @param Interpolator\n * @returns {String} translation\n */\n var fallbackTranslationInstant = function (translationId, interpolateParams, Interpolator) {\n // Start with the fallbackLanguage with index 0\n return resolveForFallbackLanguageInstant((startFallbackIteration>0 ? startFallbackIteration : fallbackIndex), translationId, interpolateParams, Interpolator);\n };\n\n var determineTranslation = function (translationId, interpolateParams, interpolationId, defaultTranslationText) {\n\n var deferred = $q.defer();\n\n var table = $uses ? $translationTable[$uses] : $translationTable,\n Interpolator = (interpolationId) ? interpolatorHashMap[interpolationId] : defaultInterpolator;\n\n // if the translation id exists, we can just interpolate it\n if (table && Object.prototype.hasOwnProperty.call(table, translationId)) {\n var translation = table[translationId];\n\n // If using link, rerun $translate with linked translationId and return it\n if (translation.substr(0, 2) === '@:') {\n\n $translate(translation.substr(2), interpolateParams, interpolationId, defaultTranslationText)\n .then(deferred.resolve, deferred.reject);\n } else {\n deferred.resolve(Interpolator.interpolate(translation, interpolateParams));\n }\n } else {\n var missingTranslationHandlerTranslation;\n // for logging purposes only (as in $translateMissingTranslationHandlerLog), value is not returned to promise\n if ($missingTranslationHandlerFactory && !pendingLoader) {\n missingTranslationHandlerTranslation = translateByHandler(translationId, interpolateParams);\n }\n\n // since we couldn't translate the inital requested translation id,\n // we try it now with one or more fallback languages, if fallback language(s) is\n // configured.\n if ($uses && $fallbackLanguage && $fallbackLanguage.length) {\n fallbackTranslation(translationId, interpolateParams, Interpolator, defaultTranslationText)\n .then(function (translation) {\n deferred.resolve(translation);\n }, function (_translationId) {\n deferred.reject(applyNotFoundIndicators(_translationId));\n });\n } else if ($missingTranslationHandlerFactory && !pendingLoader && missingTranslationHandlerTranslation) {\n // looks like the requested translation id doesn't exists.\n // Now, if there is a registered handler for missing translations and no\n // asyncLoader is pending, we execute the handler\n if (defaultTranslationText) {\n deferred.resolve(defaultTranslationText);\n } else {\n deferred.resolve(missingTranslationHandlerTranslation);\n }\n } else {\n if (defaultTranslationText) {\n deferred.resolve(defaultTranslationText);\n } else {\n deferred.reject(applyNotFoundIndicators(translationId));\n }\n }\n }\n return deferred.promise;\n };\n\n var determineTranslationInstant = function (translationId, interpolateParams, interpolationId) {\n\n var result, table = $uses ? $translationTable[$uses] : $translationTable,\n Interpolator = defaultInterpolator;\n\n // if the interpolation id exists use custom interpolator\n if (interpolatorHashMap && Object.prototype.hasOwnProperty.call(interpolatorHashMap, interpolationId)) {\n Interpolator = interpolatorHashMap[interpolationId];\n }\n\n // if the translation id exists, we can just interpolate it\n if (table && Object.prototype.hasOwnProperty.call(table, translationId)) {\n var translation = table[translationId];\n\n // If using link, rerun $translate with linked translationId and return it\n if (translation.substr(0, 2) === '@:') {\n result = determineTranslationInstant(translation.substr(2), interpolateParams, interpolationId);\n } else {\n result = Interpolator.interpolate(translation, interpolateParams);\n }\n } else {\n var missingTranslationHandlerTranslation;\n // for logging purposes only (as in $translateMissingTranslationHandlerLog), value is not returned to promise\n if ($missingTranslationHandlerFactory && !pendingLoader) {\n missingTranslationHandlerTranslation = translateByHandler(translationId, interpolateParams);\n }\n\n // since we couldn't translate the inital requested translation id,\n // we try it now with one or more fallback languages, if fallback language(s) is\n // configured.\n if ($uses && $fallbackLanguage && $fallbackLanguage.length) {\n fallbackIndex = 0;\n result = fallbackTranslationInstant(translationId, interpolateParams, Interpolator);\n } else if ($missingTranslationHandlerFactory && !pendingLoader && missingTranslationHandlerTranslation) {\n // looks like the requested translation id doesn't exists.\n // Now, if there is a registered handler for missing translations and no\n // asyncLoader is pending, we execute the handler\n result = missingTranslationHandlerTranslation;\n } else {\n result = applyNotFoundIndicators(translationId);\n }\n }\n\n return result;\n };\n\n var clearNextLangAndPromise = function(key) {\n if ($nextLang === key) {\n $nextLang = undefined;\n }\n langPromises[key] = undefined;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#preferredLanguage\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns the language key for the preferred language.\n *\n * @param {string} langKey language String or Array to be used as preferredLanguage (changing at runtime)\n *\n * @return {string} preferred language key\n */\n $translate.preferredLanguage = function (langKey) {\n if(langKey) {\n setupPreferredLanguage(langKey);\n }\n return $preferredLanguage;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#cloakClassName\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns the configured class name for `translate-cloak` directive.\n *\n * @return {string} cloakClassName\n */\n $translate.cloakClassName = function () {\n return $cloakClassName;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#nestedObjectDelimeter\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns the configured delimiter for nested namespaces.\n *\n * @return {string} nestedObjectDelimeter\n */\n $translate.nestedObjectDelimeter = function () {\n return $nestedObjectDelimeter;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#fallbackLanguage\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns the language key for the fallback languages or sets a new fallback stack.\n *\n * @param {string=} langKey language String or Array of fallback languages to be used (to change stack at runtime)\n *\n * @return {string||array} fallback language key\n */\n $translate.fallbackLanguage = function (langKey) {\n if (langKey !== undefined && langKey !== null) {\n fallbackStack(langKey);\n\n // as we might have an async loader initiated and a new translation language might have been defined\n // we need to add the promise to the stack also. So - iterate.\n if ($loaderFactory) {\n if ($fallbackLanguage && $fallbackLanguage.length) {\n for (var i = 0, len = $fallbackLanguage.length; i < len; i++) {\n if (!langPromises[$fallbackLanguage[i]]) {\n langPromises[$fallbackLanguage[i]] = loadAsync($fallbackLanguage[i]);\n }\n }\n }\n }\n $translate.use($translate.use());\n }\n if ($fallbackWasString) {\n return $fallbackLanguage[0];\n } else {\n return $fallbackLanguage;\n }\n\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#useFallbackLanguage\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Sets the first key of the fallback language stack to be used for translation.\n * Therefore all languages in the fallback array BEFORE this key will be skipped!\n *\n * @param {string=} langKey Contains the langKey the iteration shall start with. Set to false if you want to\n * get back to the whole stack\n */\n $translate.useFallbackLanguage = function (langKey) {\n if (langKey !== undefined && langKey !== null) {\n if (!langKey) {\n startFallbackIteration = 0;\n } else {\n var langKeyPosition = indexOf($fallbackLanguage, langKey);\n if (langKeyPosition > -1) {\n startFallbackIteration = langKeyPosition;\n }\n }\n\n }\n\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#proposedLanguage\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns the language key of language that is currently loaded asynchronously.\n *\n * @return {string} language key\n */\n $translate.proposedLanguage = function () {\n return $nextLang;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#storage\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns registered storage.\n *\n * @return {object} Storage\n */\n $translate.storage = function () {\n return Storage;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#use\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Tells angular-translate which language to use by given language key. This method is\n * used to change language at runtime. It also takes care of storing the language\n * key in a configured store to let your app remember the choosed language.\n *\n * When trying to 'use' a language which isn't available it tries to load it\n * asynchronously with registered loaders.\n *\n * Returns promise object with loaded language file data or string of the currently used language.\n *\n * If no or a falsy key is given it returns the currently used language key.\n * The returned string will be ```undefined``` if setting up $translate hasn't finished.\n * @example\n * $translate.use(\"en_US\").then(function(data){\n * $scope.text = $translate(\"HELLO\");\n * });\n *\n * @param {string} [key] Language key\n * @return {object|string} Promise with loaded language data or the language key if a falsy param was given.\n */\n $translate.use = function (key) {\n if (!key) {\n return $uses;\n }\n\n var deferred = $q.defer();\n\n $rootScope.$emit('$translateChangeStart', {language: key});\n\n // Try to get the aliased language key\n var aliasedKey = negotiateLocale(key);\n if (aliasedKey) {\n key = aliasedKey;\n }\n\n // if there isn't a translation table for the language we've requested,\n // we load it asynchronously\n if (($forceAsyncReloadEnabled || !$translationTable[key]) && $loaderFactory && !langPromises[key]) {\n $nextLang = key;\n langPromises[key] = loadAsync(key).then(function (translation) {\n translations(translation.key, translation.table);\n deferred.resolve(translation.key);\n if ($nextLang === key) {\n useLanguage(translation.key);\n }\n return translation;\n }, function (key) {\n $rootScope.$emit('$translateChangeError', {language: key});\n deferred.reject(key);\n $rootScope.$emit('$translateChangeEnd', {language: key});\n return $q.reject(key);\n });\n langPromises[key]['finally'](function () {\n clearNextLangAndPromise(key);\n });\n } else if ($nextLang === key && langPromises[key]) {\n // we are already loading this asynchronously\n // resolve our new deferred when the old langPromise is resolved\n langPromises[key].then(function (translation) {\n deferred.resolve(translation.key);\n return translation;\n }, function (key) {\n deferred.reject(key);\n return $q.reject(key);\n });\n } else {\n deferred.resolve(key);\n useLanguage(key);\n }\n\n return deferred.promise;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#storageKey\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns the key for the storage.\n *\n * @return {string} storage key\n */\n $translate.storageKey = function () {\n return storageKey();\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#isPostCompilingEnabled\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns whether post compiling is enabled or not\n *\n * @return {bool} storage key\n */\n $translate.isPostCompilingEnabled = function () {\n return $postCompilingEnabled;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#isForceAsyncReloadEnabled\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns whether force async reload is enabled or not\n *\n * @return {boolean} forceAsyncReload value\n */\n $translate.isForceAsyncReloadEnabled = function () {\n return $forceAsyncReloadEnabled;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#refresh\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Refreshes a translation table pointed by the given langKey. If langKey is not specified,\n * the module will drop all existent translation tables and load new version of those which\n * are currently in use.\n *\n * Refresh means that the module will drop target translation table and try to load it again.\n *\n * In case there are no loaders registered the refresh() method will throw an Error.\n *\n * If the module is able to refresh translation tables refresh() method will broadcast\n * $translateRefreshStart and $translateRefreshEnd events.\n *\n * @example\n * // this will drop all currently existent translation tables and reload those which are\n * // currently in use\n * $translate.refresh();\n * // this will refresh a translation table for the en_US language\n * $translate.refresh('en_US');\n *\n * @param {string} langKey A language key of the table, which has to be refreshed\n *\n * @return {promise} Promise, which will be resolved in case a translation tables refreshing\n * process is finished successfully, and reject if not.\n */\n $translate.refresh = function (langKey) {\n if (!$loaderFactory) {\n throw new Error('Couldn\\'t refresh translation table, no loader registered!');\n }\n\n var deferred = $q.defer();\n\n function resolve() {\n deferred.resolve();\n $rootScope.$emit('$translateRefreshEnd', {language: langKey});\n }\n\n function reject() {\n deferred.reject();\n $rootScope.$emit('$translateRefreshEnd', {language: langKey});\n }\n\n $rootScope.$emit('$translateRefreshStart', {language: langKey});\n\n if (!langKey) {\n // if there's no language key specified we refresh ALL THE THINGS!\n var tables = [], loadingKeys = {};\n\n // reload registered fallback languages\n if ($fallbackLanguage && $fallbackLanguage.length) {\n for (var i = 0, len = $fallbackLanguage.length; i < len; i++) {\n tables.push(loadAsync($fallbackLanguage[i]));\n loadingKeys[$fallbackLanguage[i]] = true;\n }\n }\n\n // reload currently used language\n if ($uses && !loadingKeys[$uses]) {\n tables.push(loadAsync($uses));\n }\n\n var allTranslationsLoaded = function (tableData) {\n $translationTable = {};\n angular.forEach(tableData, function (data) {\n translations(data.key, data.table);\n });\n if ($uses) {\n useLanguage($uses);\n }\n resolve();\n };\n allTranslationsLoaded.displayName = 'refreshPostProcessor';\n\n $q.all(tables).then(allTranslationsLoaded, reject);\n\n } else if ($translationTable[langKey]) {\n\n var oneTranslationsLoaded = function (data) {\n translations(data.key, data.table);\n if (langKey === $uses) {\n useLanguage($uses);\n }\n resolve();\n };\n oneTranslationsLoaded.displayName = 'refreshPostProcessor';\n\n loadAsync(langKey).then(oneTranslationsLoaded, reject);\n\n } else {\n reject();\n }\n return deferred.promise;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#instant\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns a translation instantly from the internal state of loaded translation. All rules\n * regarding the current language, the preferred language of even fallback languages will be\n * used except any promise handling. If a language was not found, an asynchronous loading\n * will be invoked in the background.\n *\n * @param {string|array} translationId A token which represents a translation id\n * This can be optionally an array of translation ids which\n * results that the function's promise returns an object where\n * each key is the translation id and the value the translation.\n * @param {object} interpolateParams Params\n * @param {string} interpolationId The id of the interpolation to use\n *\n * @return {string|object} translation\n */\n $translate.instant = function (translationId, interpolateParams, interpolationId) {\n\n // Detect undefined and null values to shorten the execution and prevent exceptions\n if (translationId === null || angular.isUndefined(translationId)) {\n return translationId;\n }\n\n // Duck detection: If the first argument is an array, a bunch of translations was requested.\n // The result is an object.\n if (angular.isArray(translationId)) {\n var results = {};\n for (var i = 0, c = translationId.length; i < c; i++) {\n results[translationId[i]] = $translate.instant(translationId[i], interpolateParams, interpolationId);\n }\n return results;\n }\n\n // We discarded unacceptable values. So we just need to verify if translationId is empty String\n if (angular.isString(translationId) && translationId.length < 1) {\n return translationId;\n }\n\n // trim off any whitespace\n if (translationId) {\n translationId = trim.apply(translationId);\n }\n\n var result, possibleLangKeys = [];\n if ($preferredLanguage) {\n possibleLangKeys.push($preferredLanguage);\n }\n if ($uses) {\n possibleLangKeys.push($uses);\n }\n if ($fallbackLanguage && $fallbackLanguage.length) {\n possibleLangKeys = possibleLangKeys.concat($fallbackLanguage);\n }\n for (var j = 0, d = possibleLangKeys.length; j < d; j++) {\n var possibleLangKey = possibleLangKeys[j];\n if ($translationTable[possibleLangKey]) {\n if (typeof $translationTable[possibleLangKey][translationId] !== 'undefined') {\n result = determineTranslationInstant(translationId, interpolateParams, interpolationId);\n } else if ($notFoundIndicatorLeft || $notFoundIndicatorRight) {\n result = applyNotFoundIndicators(translationId);\n }\n }\n if (typeof result !== 'undefined') {\n break;\n }\n }\n\n if (!result && result !== '') {\n // Return translation of default interpolator if not found anything.\n result = defaultInterpolator.interpolate(translationId, interpolateParams);\n if ($missingTranslationHandlerFactory && !pendingLoader) {\n result = translateByHandler(translationId, interpolateParams);\n }\n }\n\n return result;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#versionInfo\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns the current version information for the angular-translate library\n *\n * @return {string} angular-translate version\n */\n $translate.versionInfo = function () {\n return version;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#loaderCache\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns the defined loaderCache.\n *\n * @return {boolean|string|object} current value of loaderCache\n */\n $translate.loaderCache = function () {\n return loaderCache;\n };\n\n // internal purpose only\n $translate.directivePriority = function () {\n return directivePriority;\n };\n\n // internal purpose only\n $translate.statefulFilter = function () {\n return statefulFilter;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#isReady\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns whether the service is \"ready\" to translate (i.e. loading 1st language).\n *\n * See also {@link pascalprecht.translate.$translate#methods_onReady onReady()}.\n *\n * @return {boolean} current value of ready\n */\n $translate.isReady = function () {\n return $isReady;\n };\n\n var $onReadyDeferred = $q.defer();\n $onReadyDeferred.promise.then(function () {\n $isReady = true;\n });\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translate#onReady\n * @methodOf pascalprecht.translate.$translate\n *\n * @description\n * Returns whether the service is \"ready\" to translate (i.e. loading 1st language).\n *\n * See also {@link pascalprecht.translate.$translate#methods_isReady isReady()}.\n *\n * @param {Function=} fn Function to invoke when service is ready\n * @return {object} Promise resolved when service is ready\n */\n $translate.onReady = function (fn) {\n var deferred = $q.defer();\n if (angular.isFunction(fn)) {\n deferred.promise.then(fn);\n }\n if ($isReady) {\n deferred.resolve();\n } else {\n $onReadyDeferred.promise.then(deferred.resolve);\n }\n return deferred.promise;\n };\n\n // Whenever $translateReady is being fired, this will ensure the state of $isReady\n var globalOnReadyListener = $rootScope.$on('$translateReady', function () {\n $onReadyDeferred.resolve();\n globalOnReadyListener(); // one time only\n globalOnReadyListener = null;\n });\n var globalOnChangeListener = $rootScope.$on('$translateChangeEnd', function () {\n $onReadyDeferred.resolve();\n globalOnChangeListener(); // one time only\n globalOnChangeListener = null;\n });\n\n if ($loaderFactory) {\n\n // If at least one async loader is defined and there are no\n // (default) translations available we should try to load them.\n if (angular.equals($translationTable, {})) {\n if ($translate.use()) {\n $translate.use($translate.use());\n }\n }\n\n // Also, if there are any fallback language registered, we start\n // loading them asynchronously as soon as we can.\n if ($fallbackLanguage && $fallbackLanguage.length) {\n var processAsyncResult = function (translation) {\n translations(translation.key, translation.table);\n $rootScope.$emit('$translateChangeEnd', { language: translation.key });\n return translation;\n };\n for (var i = 0, len = $fallbackLanguage.length; i < len; i++) {\n var fallbackLanguageId = $fallbackLanguage[i];\n if ($forceAsyncReloadEnabled || !$translationTable[fallbackLanguageId]) {\n langPromises[fallbackLanguageId] = loadAsync(fallbackLanguageId).then(processAsyncResult);\n }\n }\n }\n } else {\n $rootScope.$emit('$translateReady', { language: $translate.use() });\n }\n\n return $translate;\n }\n ];\n}\n$translate.$inject = ['$STORAGE_KEY', '$windowProvider', '$translateSanitizationProvider', 'pascalprechtTranslateOverrider'];\n\n$translate.displayName = 'displayName';\n\n/**\n * @ngdoc object\n * @name pascalprecht.translate.$translateDefaultInterpolation\n * @requires $interpolate\n *\n * @description\n * Uses angular's `$interpolate` services to interpolate strings against some values.\n *\n * Be aware to configure a proper sanitization strategy.\n *\n * See also:\n * * {@link pascalprecht.translate.$translateSanitization}\n *\n * @return {object} $translateDefaultInterpolation Interpolator service\n */\nangular.module('pascalprecht.translate').factory('$translateDefaultInterpolation', $translateDefaultInterpolation);\n\nfunction $translateDefaultInterpolation ($interpolate, $translateSanitization) {\n\n 'use strict';\n\n var $translateInterpolator = {},\n $locale,\n $identifier = 'default';\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateDefaultInterpolation#setLocale\n * @methodOf pascalprecht.translate.$translateDefaultInterpolation\n *\n * @description\n * Sets current locale (this is currently not use in this interpolation).\n *\n * @param {string} locale Language key or locale.\n */\n $translateInterpolator.setLocale = function (locale) {\n $locale = locale;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateDefaultInterpolation#getInterpolationIdentifier\n * @methodOf pascalprecht.translate.$translateDefaultInterpolation\n *\n * @description\n * Returns an identifier for this interpolation service.\n *\n * @returns {string} $identifier\n */\n $translateInterpolator.getInterpolationIdentifier = function () {\n return $identifier;\n };\n\n /**\n * @deprecated will be removed in 3.0\n * @see {@link pascalprecht.translate.$translateSanitization}\n */\n $translateInterpolator.useSanitizeValueStrategy = function (value) {\n $translateSanitization.useStrategy(value);\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translateDefaultInterpolation#interpolate\n * @methodOf pascalprecht.translate.$translateDefaultInterpolation\n *\n * @description\n * Interpolates given string agains given interpolate params using angulars\n * `$interpolate` service.\n *\n * @returns {string} interpolated string.\n */\n $translateInterpolator.interpolate = function (string, interpolationParams) {\n interpolationParams = interpolationParams || {};\n interpolationParams = $translateSanitization.sanitize(interpolationParams, 'params');\n\n var interpolatedText = $interpolate(string)(interpolationParams);\n interpolatedText = $translateSanitization.sanitize(interpolatedText, 'text');\n\n return interpolatedText;\n };\n\n return $translateInterpolator;\n}\n$translateDefaultInterpolation.$inject = ['$interpolate', '$translateSanitization'];\n\n$translateDefaultInterpolation.displayName = '$translateDefaultInterpolation';\n\nangular.module('pascalprecht.translate').constant('$STORAGE_KEY', 'NG_TRANSLATE_LANG_KEY');\n\nangular.module('pascalprecht.translate')\n/**\n * @ngdoc directive\n * @name pascalprecht.translate.directive:translate\n * @requires $compile\n * @requires $filter\n * @requires $interpolate\n * @restrict A\n *\n * @description\n * Translates given translation id either through attribute or DOM content.\n * Internally it uses `translate` filter to translate translation id. It possible to\n * pass an optional `translate-values` object literal as string into translation id.\n *\n * @param {string=} translate Translation id which could be either string or interpolated string.\n * @param {string=} translate-values Values to pass into translation id. Can be passed as object literal string or interpolated object.\n * @param {string=} translate-attr-ATTR translate Translation id and put it into ATTR attribute.\n * @param {string=} translate-default will be used unless translation was successful\n * @param {boolean=} translate-compile (default true if present) defines locally activation of {@link pascalprecht.translate.$translateProvider#methods_usePostCompiling}\n *\n * @example\n \n \n \n\n
\n
TRANSLATION_ID
\n
\n
\n
{{translationId}}
\n
\n
WITH_VALUES
\n
\n
WITH_VALUES
\n
\n\n
\n \n \n angular.module('ngView', ['pascalprecht.translate'])\n\n .config(function ($translateProvider) {\n\n $translateProvider.translations('en',{\n 'TRANSLATION_ID': 'Hello there!',\n 'WITH_VALUES': 'The following value is dynamic: {{value}}'\n }).preferredLanguage('en');\n\n });\n\n angular.module('ngView').controller('TranslateCtrl', function ($scope) {\n $scope.translationId = 'TRANSLATION_ID';\n\n $scope.values = {\n value: 78\n };\n });\n \n \n it('should translate', function () {\n inject(function ($rootScope, $compile) {\n $rootScope.translationId = 'TRANSLATION_ID';\n\n element = $compile('')($rootScope);\n $rootScope.$digest();\n expect(element.text()).toBe('Hello there!');\n\n element = $compile('')($rootScope);\n $rootScope.$digest();\n expect(element.text()).toBe('Hello there!');\n\n element = $compile('TRANSLATION_ID
')($rootScope);\n $rootScope.$digest();\n expect(element.text()).toBe('Hello there!');\n\n element = $compile('{{translationId}}
')($rootScope);\n $rootScope.$digest();\n expect(element.text()).toBe('Hello there!');\n\n element = $compile('')($rootScope);\n $rootScope.$digest();\n expect(element.attr('title')).toBe('Hello there!');\n });\n });\n \n \n */\n.directive('translate', translateDirective);\nfunction translateDirective($translate, $q, $interpolate, $compile, $parse, $rootScope) {\n\n 'use strict';\n\n /**\n * @name trim\n * @private\n *\n * @description\n * trim polyfill\n *\n * @returns {string} The string stripped of whitespace from both ends\n */\n var trim = function() {\n return this.toString().replace(/^\\s+|\\s+$/g, '');\n };\n\n return {\n restrict: 'AE',\n scope: true,\n priority: $translate.directivePriority(),\n compile: function (tElement, tAttr) {\n\n var translateValuesExist = (tAttr.translateValues) ?\n tAttr.translateValues : undefined;\n\n var translateInterpolation = (tAttr.translateInterpolation) ?\n tAttr.translateInterpolation : undefined;\n\n var translateValueExist = tElement[0].outerHTML.match(/translate-value-+/i);\n\n var interpolateRegExp = '^(.*)(' + $interpolate.startSymbol() + '.*' + $interpolate.endSymbol() + ')(.*)',\n watcherRegExp = '^(.*)' + $interpolate.startSymbol() + '(.*)' + $interpolate.endSymbol() + '(.*)';\n\n return function linkFn(scope, iElement, iAttr) {\n\n scope.interpolateParams = {};\n scope.preText = '';\n scope.postText = '';\n scope.translateNamespace = getTranslateNamespace(scope);\n var translationIds = {};\n\n var initInterpolationParams = function (interpolateParams, iAttr, tAttr) {\n // initial setup\n if (iAttr.translateValues) {\n angular.extend(interpolateParams, $parse(iAttr.translateValues)(scope.$parent));\n }\n // initially fetch all attributes if existing and fill the params\n if (translateValueExist) {\n for (var attr in tAttr) {\n if (Object.prototype.hasOwnProperty.call(iAttr, attr) && attr.substr(0, 14) === 'translateValue' && attr !== 'translateValues') {\n var attributeName = angular.lowercase(attr.substr(14, 1)) + attr.substr(15);\n interpolateParams[attributeName] = tAttr[attr];\n }\n }\n }\n };\n\n // Ensures any change of the attribute \"translate\" containing the id will\n // be re-stored to the scope's \"translationId\".\n // If the attribute has no content, the element's text value (white spaces trimmed off) will be used.\n var observeElementTranslation = function (translationId) {\n\n // Remove any old watcher\n if (angular.isFunction(observeElementTranslation._unwatchOld)) {\n observeElementTranslation._unwatchOld();\n observeElementTranslation._unwatchOld = undefined;\n }\n\n if (angular.equals(translationId , '') || !angular.isDefined(translationId)) {\n var iElementText = trim.apply(iElement.text());\n\n // Resolve translation id by inner html if required\n var interpolateMatches = iElementText.match(interpolateRegExp);\n // Interpolate translation id if required\n if (angular.isArray(interpolateMatches)) {\n scope.preText = interpolateMatches[1];\n scope.postText = interpolateMatches[3];\n translationIds.translate = $interpolate(interpolateMatches[2])(scope.$parent);\n var watcherMatches = iElementText.match(watcherRegExp);\n if (angular.isArray(watcherMatches) && watcherMatches[2] && watcherMatches[2].length) {\n observeElementTranslation._unwatchOld = scope.$watch(watcherMatches[2], function (newValue) {\n translationIds.translate = newValue;\n updateTranslations();\n });\n }\n } else {\n translationIds.translate = iElementText;\n }\n } else {\n translationIds.translate = translationId;\n }\n updateTranslations();\n };\n\n var observeAttributeTranslation = function (translateAttr) {\n iAttr.$observe(translateAttr, function (translationId) {\n translationIds[translateAttr] = translationId;\n updateTranslations();\n });\n };\n\n // initial setup with values\n initInterpolationParams(scope.interpolateParams, iAttr, tAttr);\n\n var firstAttributeChangedEvent = true;\n iAttr.$observe('translate', function (translationId) {\n if (typeof translationId === 'undefined') {\n // case of element \"xyz\"\n observeElementTranslation('');\n } else {\n // case of regular attribute\n if (translationId !== '' || !firstAttributeChangedEvent) {\n translationIds.translate = translationId;\n updateTranslations();\n }\n }\n firstAttributeChangedEvent = false;\n });\n\n for (var translateAttr in iAttr) {\n if (iAttr.hasOwnProperty(translateAttr) && translateAttr.substr(0, 13) === 'translateAttr') {\n observeAttributeTranslation(translateAttr);\n }\n }\n\n iAttr.$observe('translateDefault', function (value) {\n scope.defaultText = value;\n });\n\n if (translateValuesExist) {\n iAttr.$observe('translateValues', function (interpolateParams) {\n if (interpolateParams) {\n scope.$parent.$watch(function () {\n angular.extend(scope.interpolateParams, $parse(interpolateParams)(scope.$parent));\n });\n }\n });\n }\n\n if (translateValueExist) {\n var observeValueAttribute = function (attrName) {\n iAttr.$observe(attrName, function (value) {\n var attributeName = angular.lowercase(attrName.substr(14, 1)) + attrName.substr(15);\n scope.interpolateParams[attributeName] = value;\n });\n };\n for (var attr in iAttr) {\n if (Object.prototype.hasOwnProperty.call(iAttr, attr) && attr.substr(0, 14) === 'translateValue' && attr !== 'translateValues') {\n observeValueAttribute(attr);\n }\n }\n }\n\n // Master update function\n var updateTranslations = function () {\n for (var key in translationIds) {\n\n if (translationIds.hasOwnProperty(key) && translationIds[key] !== undefined) {\n updateTranslation(key, translationIds[key], scope, scope.interpolateParams, scope.defaultText, scope.translateNamespace);\n }\n }\n };\n\n // Put translation processing function outside loop\n var updateTranslation = function(translateAttr, translationId, scope, interpolateParams, defaultTranslationText, translateNamespace) {\n if (translationId) {\n // if translation id starts with '.' and translateNamespace given, prepend namespace\n if (translateNamespace && translationId.charAt(0) === '.') {\n translationId = translateNamespace + translationId;\n }\n\n $translate(translationId, interpolateParams, translateInterpolation, defaultTranslationText)\n .then(function (translation) {\n applyTranslation(translation, scope, true, translateAttr);\n }, function (translationId) {\n applyTranslation(translationId, scope, false, translateAttr);\n });\n } else {\n // as an empty string cannot be translated, we can solve this using successful=false\n applyTranslation(translationId, scope, false, translateAttr);\n }\n };\n\n var applyTranslation = function (value, scope, successful, translateAttr) {\n if (translateAttr === 'translate') {\n // default translate into innerHTML\n if (!successful && typeof scope.defaultText !== 'undefined') {\n value = scope.defaultText;\n }\n iElement.empty().append(scope.preText + value + scope.postText);\n var globallyEnabled = $translate.isPostCompilingEnabled();\n var locallyDefined = typeof tAttr.translateCompile !== 'undefined';\n var locallyEnabled = locallyDefined && tAttr.translateCompile !== 'false';\n if ((globallyEnabled && !locallyDefined) || locallyEnabled) {\n $compile(iElement.contents())(scope);\n }\n } else {\n // translate attribute\n if (!successful && typeof scope.defaultText !== 'undefined') {\n value = scope.defaultText;\n }\n var attributeName = iAttr.$attr[translateAttr];\n if (attributeName.substr(0, 5) === 'data-') {\n // ensure html5 data prefix is stripped\n attributeName = attributeName.substr(5);\n }\n attributeName = attributeName.substr(15);\n iElement.attr(attributeName, value);\n }\n };\n\n if (translateValuesExist || translateValueExist || iAttr.translateDefault) {\n scope.$watch('interpolateParams', updateTranslations, true);\n }\n\n // Ensures the text will be refreshed after the current language was changed\n // w/ $translate.use(...)\n var unbind = $rootScope.$on('$translateChangeSuccess', updateTranslations);\n\n // ensure translation will be looked up at least one\n if (iElement.text().length) {\n if (iAttr.translate) {\n observeElementTranslation(iAttr.translate);\n } else {\n observeElementTranslation('');\n }\n } else if (iAttr.translate) {\n // ensure attribute will be not skipped\n observeElementTranslation(iAttr.translate);\n }\n updateTranslations();\n scope.$on('$destroy', unbind);\n };\n }\n };\n}\ntranslateDirective.$inject = ['$translate', '$q', '$interpolate', '$compile', '$parse', '$rootScope'];\n\n/**\n * Returns the scope's namespace.\n * @private\n * @param scope\n * @returns {string}\n */\nfunction getTranslateNamespace(scope) {\n 'use strict';\n if (scope.translateNamespace) {\n return scope.translateNamespace;\n }\n if (scope.$parent) {\n return getTranslateNamespace(scope.$parent);\n }\n}\n\ntranslateDirective.displayName = 'translateDirective';\n\nangular.module('pascalprecht.translate')\n/**\n * @ngdoc directive\n * @name pascalprecht.translate.directive:translateCloak\n * @requires $rootScope\n * @requires $translate\n * @restrict A\n *\n * $description\n * Adds a `translate-cloak` class name to the given element where this directive\n * is applied initially and removes it, once a loader has finished loading.\n *\n * This directive can be used to prevent initial flickering when loading translation\n * data asynchronously.\n *\n * The class name is defined in\n * {@link pascalprecht.translate.$translateProvider#cloakClassName $translate.cloakClassName()}.\n *\n * @param {string=} translate-cloak If a translationId is provided, it will be used for showing\n * or hiding the cloak. Basically it relies on the translation\n * resolve.\n */\n.directive('translateCloak', translateCloakDirective);\n\nfunction translateCloakDirective($translate) {\n\n 'use strict';\n\n return {\n compile: function (tElement) {\n var applyCloak = function () {\n tElement.addClass($translate.cloakClassName());\n },\n removeCloak = function () {\n tElement.removeClass($translate.cloakClassName());\n };\n $translate.onReady(function () {\n removeCloak();\n });\n applyCloak();\n\n return function linkFn(scope, iElement, iAttr) {\n // Register a watcher for the defined translation allowing a fine tuned cloak\n if (iAttr.translateCloak && iAttr.translateCloak.length) {\n iAttr.$observe('translateCloak', function (translationId) {\n $translate(translationId).then(removeCloak, applyCloak);\n });\n }\n };\n }\n };\n}\ntranslateCloakDirective.$inject = ['$translate'];\n\ntranslateCloakDirective.displayName = 'translateCloakDirective';\n\nangular.module('pascalprecht.translate')\n/**\n * @ngdoc directive\n * @name pascalprecht.translate.directive:translateNamespace\n * @restrict A\n *\n * @description\n * Translates given translation id either through attribute or DOM content.\n * Internally it uses `translate` filter to translate translation id. It possible to\n * pass an optional `translate-values` object literal as string into translation id.\n *\n * @param {string=} translate namespace name which could be either string or interpolated string.\n *\n * @example\n \n \n \n\n
\n
.HEADERS.TITLE
\n .HEADERS.WELCOME
\n \n\n
\n
.TITLE
\n .WELCOME
\n \n\n
\n \n \n angular.module('ngView', ['pascalprecht.translate'])\n\n .config(function ($translateProvider) {\n\n $translateProvider.translations('en',{\n 'TRANSLATION_ID': 'Hello there!',\n 'CONTENT': {\n 'HEADERS': {\n TITLE: 'Title'\n }\n },\n 'CONTENT.HEADERS.WELCOME': 'Welcome'\n }).preferredLanguage('en');\n\n });\n\n \n \n */\n.directive('translateNamespace', translateNamespaceDirective);\n\nfunction translateNamespaceDirective() {\n\n 'use strict';\n\n return {\n restrict: 'A',\n scope: true,\n compile: function () {\n return {\n pre: function (scope, iElement, iAttrs) {\n scope.translateNamespace = getTranslateNamespace(scope);\n\n if (scope.translateNamespace && iAttrs.translateNamespace.charAt(0) === '.') {\n scope.translateNamespace += iAttrs.translateNamespace;\n } else {\n scope.translateNamespace = iAttrs.translateNamespace;\n }\n }\n };\n }\n };\n}\n\n/**\n * Returns the scope's namespace.\n * @private\n * @param scope\n * @returns {string}\n */\nfunction getTranslateNamespace(scope) {\n 'use strict';\n if (scope.translateNamespace) {\n return scope.translateNamespace;\n }\n if (scope.$parent) {\n return getTranslateNamespace(scope.$parent);\n }\n}\n\ntranslateNamespaceDirective.displayName = 'translateNamespaceDirective';\n\nangular.module('pascalprecht.translate')\n/**\n * @ngdoc filter\n * @name pascalprecht.translate.filter:translate\n * @requires $parse\n * @requires pascalprecht.translate.$translate\n * @function\n *\n * @description\n * Uses `$translate` service to translate contents. Accepts interpolate parameters\n * to pass dynamized values though translation.\n *\n * @param {string} translationId A translation id to be translated.\n * @param {*=} interpolateParams Optional object literal (as hash or string) to pass values into translation.\n *\n * @returns {string} Translated text.\n *\n * @example\n \n \n \n\n
{{ 'TRANSLATION_ID' | translate }}
\n
{{ translationId | translate }}
\n
{{ 'WITH_VALUES' | translate:'{value: 5}' }}
\n
{{ 'WITH_VALUES' | translate:values }}
\n\n
\n \n \n angular.module('ngView', ['pascalprecht.translate'])\n\n .config(function ($translateProvider) {\n\n $translateProvider.translations('en', {\n 'TRANSLATION_ID': 'Hello there!',\n 'WITH_VALUES': 'The following value is dynamic: {{value}}'\n });\n $translateProvider.preferredLanguage('en');\n\n });\n\n angular.module('ngView').controller('TranslateCtrl', function ($scope) {\n $scope.translationId = 'TRANSLATION_ID';\n\n $scope.values = {\n value: 78\n };\n });\n \n \n */\n.filter('translate', translateFilterFactory);\n\nfunction translateFilterFactory($parse, $translate) {\n\n 'use strict';\n\n var translateFilter = function (translationId, interpolateParams, interpolation) {\n\n if (!angular.isObject(interpolateParams)) {\n interpolateParams = $parse(interpolateParams)(this);\n }\n\n return $translate.instant(translationId, interpolateParams, interpolation);\n };\n\n if ($translate.statefulFilter()) {\n translateFilter.$stateful = true;\n }\n\n return translateFilter;\n}\ntranslateFilterFactory.$inject = ['$parse', '$translate'];\n\ntranslateFilterFactory.displayName = 'translateFilterFactory';\n\nangular.module('pascalprecht.translate')\n\n/**\n * @ngdoc object\n * @name pascalprecht.translate.$translationCache\n * @requires $cacheFactory\n *\n * @description\n * The first time a translation table is used, it is loaded in the translation cache for quick retrieval. You\n * can load translation tables directly into the cache by consuming the\n * `$translationCache` service directly.\n *\n * @return {object} $cacheFactory object.\n */\n .factory('$translationCache', $translationCache);\n\nfunction $translationCache($cacheFactory) {\n\n 'use strict';\n\n return $cacheFactory('translations');\n}\n$translationCache.$inject = ['$cacheFactory'];\n\n$translationCache.displayName = '$translationCache';\nreturn 'pascalprecht.translate';\n\n}));\n\n/*!\n * angular-translate - v2.8.1 - 2015-10-01\n * \n * Copyright (c) 2015 The angular-translate team, Pascal Precht; Licensed MIT\n */\n(function (root, factory) {\n if (typeof define === 'function' && define.amd) {\n // AMD. Register as an anonymous module unless amdModuleId is set\n define([], function () {\n return (factory());\n });\n } else if (typeof exports === 'object') {\n // Node. Does not work with strict CommonJS, but\n // only CommonJS-like environments that support module.exports,\n // like Node.\n module.exports = factory();\n } else {\n factory();\n }\n}(this, function () {\n\nangular.module('pascalprecht.translate')\n/**\n * @ngdoc object\n * @name pascalprecht.translate.$translatePartialLoaderProvider\n *\n * @description\n * By using a $translatePartialLoaderProvider you can configure a list of a needed\n * translation parts directly during the configuration phase of your application's\n * lifetime. All parts you add by using this provider would be loaded by\n * angular-translate at the startup as soon as possible.\n */\n .provider('$translatePartialLoader', $translatePartialLoader);\n\nfunction $translatePartialLoader() {\n\n 'use strict';\n\n /**\n * @constructor\n * @name Part\n *\n * @description\n * Represents Part object to add and set parts at runtime.\n */\n function Part(name, priority) {\n this.name = name;\n this.isActive = true;\n this.tables = {};\n this.priority = priority || 0;\n }\n\n /**\n * @name parseUrl\n * @method\n *\n * @description\n * Returns a parsed url template string and replaces given target lang\n * and part name it.\n *\n * @param {string|function} urlTemplate - Either a string containing an url pattern (with\n * '{part}' and '{lang}') or a function(part, lang)\n * returning a string.\n * @param {string} targetLang - Language key for language to be used.\n * @return {string} Parsed url template string\n */\n Part.prototype.parseUrl = function(urlTemplate, targetLang) {\n if (angular.isFunction(urlTemplate)) {\n return urlTemplate(this.name, targetLang);\n }\n return urlTemplate.replace(/\\{part\\}/g, this.name).replace(/\\{lang\\}/g, targetLang);\n };\n\n Part.prototype.getTable = function(lang, $q, $http, $httpOptions, urlTemplate, errorHandler) {\n\n if (!this.tables[lang]) {\n var self = this;\n\n return $http(angular.extend({\n method : 'GET',\n url: this.parseUrl(urlTemplate, lang)\n }, $httpOptions))\n .then(function(result){\n self.tables[lang] = result.data;\n return result.data;\n }, function() {\n if (errorHandler) {\n return errorHandler(self.name, lang)\n .then(function(data) {\n self.tables[lang] = data;\n return data;\n }, function() {\n return $q.reject(self.name);\n });\n } else {\n return $q.reject(self.name);\n }\n });\n\n } else {\n return $q.when(this.tables[lang]);\n }\n };\n\n var parts = {};\n\n function hasPart(name) {\n return Object.prototype.hasOwnProperty.call(parts, name);\n }\n\n function isStringValid(str) {\n return angular.isString(str) && str !== '';\n }\n\n function isPartAvailable(name) {\n if (!isStringValid(name)) {\n throw new TypeError('Invalid type of a first argument, a non-empty string expected.');\n }\n\n return (hasPart(name) && parts[name].isActive);\n }\n\n function deepExtend(dst, src) {\n for (var property in src) {\n if (src[property] && src[property].constructor &&\n src[property].constructor === Object) {\n dst[property] = dst[property] || {};\n deepExtend(dst[property], src[property]);\n } else {\n dst[property] = src[property];\n }\n }\n return dst;\n }\n\n function getPrioritizedParts() {\n var prioritizedParts = [];\n for(var part in parts) {\n if (parts[part].isActive) {\n prioritizedParts.push(parts[part]);\n }\n }\n prioritizedParts.sort(function (a, b) {\n return a.priority - b.priority;\n });\n return prioritizedParts;\n }\n\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translatePartialLoaderProvider#addPart\n * @methodOf pascalprecht.translate.$translatePartialLoaderProvider\n *\n * @description\n * Registers a new part of the translation table to be loaded once the\n * `angular-translate` gets into runtime phase. It does not actually load any\n * translation data, but only registers a part to be loaded in the future.\n *\n * @param {string} name A name of the part to add\n * @param {int} [priority=0] Sets the load priority of this part.\n *\n * @returns {object} $translatePartialLoaderProvider, so this method is chainable\n * @throws {TypeError} The method could throw a **TypeError** if you pass the param\n * of the wrong type. Please, note that the `name` param has to be a\n * non-empty **string**.\n */\n this.addPart = function(name, priority) {\n if (!isStringValid(name)) {\n throw new TypeError('Couldn\\'t add part, part name has to be a string!');\n }\n\n if (!hasPart(name)) {\n parts[name] = new Part(name, priority);\n }\n parts[name].isActive = true;\n\n return this;\n };\n\n /**\n * @ngdocs function\n * @name pascalprecht.translate.$translatePartialLoaderProvider#setPart\n * @methodOf pascalprecht.translate.$translatePartialLoaderProvider\n *\n * @description\n * Sets a translation table to the specified part. This method does not make the\n * specified part available, but only avoids loading this part from the server.\n *\n * @param {string} lang A language of the given translation table\n * @param {string} part A name of the target part\n * @param {object} table A translation table to set to the specified part\n *\n * @return {object} $translatePartialLoaderProvider, so this method is chainable\n * @throws {TypeError} The method could throw a **TypeError** if you pass params\n * of the wrong type. Please, note that the `lang` and `part` params have to be a\n * non-empty **string**s and the `table` param has to be an object.\n */\n this.setPart = function (lang, part, table) {\n if (!isStringValid(lang)) {\n throw new TypeError('Couldn\\'t set part.`lang` parameter has to be a string!');\n }\n if (!isStringValid(part)) {\n throw new TypeError('Couldn\\'t set part.`part` parameter has to be a string!');\n }\n if (typeof table !== 'object' || table === null) {\n throw new TypeError('Couldn\\'t set part. `table` parameter has to be an object!');\n }\n\n if (!hasPart(part)) {\n parts[part] = new Part(part);\n parts[part].isActive = false;\n }\n\n parts[part].tables[lang] = table;\n return this;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translatePartialLoaderProvider#deletePart\n * @methodOf pascalprecht.translate.$translatePartialLoaderProvider\n *\n * @description\n * Removes the previously added part of the translation data. So, `angular-translate` will not\n * load it at the startup.\n *\n * @param {string} name A name of the part to delete\n *\n * @returns {object} $translatePartialLoaderProvider, so this method is chainable\n *\n * @throws {TypeError} The method could throw a **TypeError** if you pass the param of the wrong\n * type. Please, note that the `name` param has to be a non-empty **string**.\n */\n this.deletePart = function (name) {\n if (!isStringValid(name)) {\n throw new TypeError('Couldn\\'t delete part, first arg has to be string.');\n }\n\n if (hasPart(name)) {\n parts[name].isActive = false;\n }\n\n return this;\n };\n\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translatePartialLoaderProvider#isPartAvailable\n * @methodOf pascalprecht.translate.$translatePartialLoaderProvider\n *\n * @description\n * Checks if the specific part is available. A part becomes available after it was added by the\n * `addPart` method. Available parts would be loaded from the server once the `angular-translate`\n * asks the loader to that.\n *\n * @param {string} name A name of the part to check\n *\n * @returns {boolean} Returns **true** if the part is available now and **false** if not.\n *\n * @throws {TypeError} The method could throw a **TypeError** if you pass the param of the wrong\n * type. Please, note that the `name` param has to be a non-empty **string**.\n */\n this.isPartAvailable = isPartAvailable;\n\n /**\n * @ngdoc object\n * @name pascalprecht.translate.$translatePartialLoader\n *\n * @requires $q\n * @requires $http\n * @requires $injector\n * @requires $rootScope\n * @requires $translate\n *\n * @description\n *\n * @param {object} options Options object\n *\n * @throws {TypeError}\n */\n this.$get = ['$rootScope', '$injector', '$q', '$http',\n function($rootScope, $injector, $q, $http) {\n\n /**\n * @ngdoc event\n * @name pascalprecht.translate.$translatePartialLoader#$translatePartialLoaderStructureChanged\n * @eventOf pascalprecht.translate.$translatePartialLoader\n * @eventType broadcast on root scope\n *\n * @description\n * A $translatePartialLoaderStructureChanged event is called when a state of the loader was\n * changed somehow. It could mean either some part is added or some part is deleted. Anyway when\n * you get this event the translation table is not longer current and has to be updated.\n *\n * @param {string} name A name of the part which is a reason why the event was fired\n */\n\n var service = function(options) {\n if (!isStringValid(options.key)) {\n throw new TypeError('Unable to load data, a key is not a non-empty string.');\n }\n\n if (!isStringValid(options.urlTemplate) && !angular.isFunction(options.urlTemplate)) {\n throw new TypeError('Unable to load data, a urlTemplate is not a non-empty string or not a function.');\n }\n\n var errorHandler = options.loadFailureHandler;\n if (errorHandler !== undefined) {\n if (!angular.isString(errorHandler)) {\n throw new Error('Unable to load data, a loadFailureHandler is not a string.');\n } else {\n errorHandler = $injector.get(errorHandler);\n }\n }\n\n var loaders = [],\n deferred = $q.defer(),\n prioritizedParts = getPrioritizedParts();\n\n angular.forEach(prioritizedParts, function(part) {\n loaders.push(\n part.getTable(options.key, $q, $http, options.$http, options.urlTemplate, errorHandler)\n );\n part.urlTemplate = options.urlTemplate;\n });\n\n $q.all(loaders)\n .then(function() {\n var table = {};\n angular.forEach(prioritizedParts, function(part) {\n deepExtend(table, part.tables[options.key]);\n });\n deferred.resolve(table);\n }, function() {\n deferred.reject(options.key);\n }\n );\n\n return deferred.promise;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translatePartialLoader#addPart\n * @methodOf pascalprecht.translate.$translatePartialLoader\n *\n * @description\n * Registers a new part of the translation table. This method does not actually perform any xhr\n * requests to get translation data. The new parts will be loaded in order of priority from the server next time\n * `angular-translate` asks the loader to load translations.\n *\n * @param {string} name A name of the part to add\n * @param {int} [priority=0] Sets the load priority of this part.\n *\n * @returns {object} $translatePartialLoader, so this method is chainable\n *\n * @fires {$translatePartialLoaderStructureChanged} The $translatePartialLoaderStructureChanged\n * event would be fired by this method in case the new part affected somehow on the loaders\n * state. This way it means that there are a new translation data available to be loaded from\n * the server.\n *\n * @throws {TypeError} The method could throw a **TypeError** if you pass the param of the wrong\n * type. Please, note that the `name` param has to be a non-empty **string**.\n */\n service.addPart = function(name, priority) {\n if (!isStringValid(name)) {\n throw new TypeError('Couldn\\'t add part, first arg has to be a string');\n }\n\n if (!hasPart(name)) {\n parts[name] = new Part(name, priority);\n $rootScope.$emit('$translatePartialLoaderStructureChanged', name);\n } else if (!parts[name].isActive) {\n parts[name].isActive = true;\n $rootScope.$emit('$translatePartialLoaderStructureChanged', name);\n }\n\n return service;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translatePartialLoader#deletePart\n * @methodOf pascalprecht.translate.$translatePartialLoader\n *\n * @description\n * Deletes the previously added part of the translation data. The target part could be deleted\n * either logically or physically. When the data is deleted logically it is not actually deleted\n * from the browser, but the loader marks it as not active and prevents it from affecting on the\n * translations. If the deleted in such way part is added again, the loader will use the\n * previously loaded data rather than loading it from the server once more time. But if the data\n * is deleted physically, the loader will completely remove all information about it. So in case\n * of recycling this part will be loaded from the server again.\n *\n * @param {string} name A name of the part to delete\n * @param {boolean=} [removeData=false] An indicator if the loader has to remove a loaded\n * translation data physically. If the `removeData` if set to **false** the loaded data will not be\n * deleted physically and might be reused in the future to prevent an additional xhr requests.\n *\n * @returns {object} $translatePartialLoader, so this method is chainable\n *\n * @fires {$translatePartialLoaderStructureChanged} The $translatePartialLoaderStructureChanged\n * event would be fired by this method in case a part deletion process affects somehow on the\n * loaders state. This way it means that some part of the translation data is now deprecated and\n * the translation table has to be recompiled with the remaining translation parts.\n *\n * @throws {TypeError} The method could throw a **TypeError** if you pass some param of the\n * wrong type. Please, note that the `name` param has to be a non-empty **string** and\n * the `removeData` param has to be either **undefined** or **boolean**.\n */\n service.deletePart = function(name, removeData) {\n if (!isStringValid(name)) {\n throw new TypeError('Couldn\\'t delete part, first arg has to be string');\n }\n\n if (removeData === undefined) {\n removeData = false;\n } else if (typeof removeData !== 'boolean') {\n throw new TypeError('Invalid type of a second argument, a boolean expected.');\n }\n\n if (hasPart(name)) {\n var wasActive = parts[name].isActive;\n if (removeData) {\n var $translate = $injector.get('$translate');\n var cache = $translate.loaderCache();\n if (typeof(cache) === 'string') {\n // getting on-demand instance of loader\n cache = $injector.get(cache);\n }\n // Purging items from cache...\n if (typeof(cache) === 'object') {\n angular.forEach(parts[name].tables, function(value, key) {\n cache.remove(parts[name].parseUrl(parts[name].urlTemplate, key));\n });\n }\n delete parts[name];\n } else {\n parts[name].isActive = false;\n }\n if (wasActive) {\n $rootScope.$emit('$translatePartialLoaderStructureChanged', name);\n }\n }\n\n return service;\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translatePartialLoader#isPartLoaded\n * @methodOf pascalprecht.translate.$translatePartialLoader\n *\n * @description\n * Checks if the registered translation part is loaded into the translation table.\n *\n * @param {string} name A name of the part\n * @param {string} lang A key of the language\n *\n * @returns {boolean} Returns **true** if the translation of the part is loaded to the translation table and **false** if not.\n *\n * @throws {TypeError} The method could throw a **TypeError** if you pass the param of the wrong\n * type. Please, note that the `name` and `lang` params have to be non-empty **string**.\n */\n service.isPartLoaded = function(name, lang) {\n return angular.isDefined(parts[name]) && angular.isDefined(parts[name].tables[lang]);\n };\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translatePartialLoader#getRegisteredParts\n * @methodOf pascalprecht.translate.$translatePartialLoader\n *\n * @description\n * Gets names of the parts that were added with the `addPart`.\n *\n * @returns {array} Returns array of registered parts, if none were registered then an empty array is returned.\n */\n service.getRegisteredParts = function() {\n var registeredParts = [];\n angular.forEach(parts, function(p){\n if(p.isActive) {\n registeredParts.push(p.name);\n }\n });\n return registeredParts;\n };\n\n\n\n /**\n * @ngdoc function\n * @name pascalprecht.translate.$translatePartialLoader#isPartAvailable\n * @methodOf pascalprecht.translate.$translatePartialLoader\n *\n * @description\n * Checks if a target translation part is available. The part becomes available just after it was\n * added by the `addPart` method. Part's availability does not mean that it was loaded from the\n * server, but only that it was added to the loader. The available part might be loaded next\n * time the loader is called.\n *\n * @param {string} name A name of the part to delete\n *\n * @returns {boolean} Returns **true** if the part is available now and **false** if not.\n *\n * @throws {TypeError} The method could throw a **TypeError** if you pass the param of the wrong\n * type. Please, note that the `name` param has to be a non-empty **string**.\n */\n service.isPartAvailable = isPartAvailable;\n\n return service;\n\n }];\n\n}\n\n$translatePartialLoader.displayName = '$translatePartialLoader';\nreturn 'pascalprecht.translate';\n\n}));\n\n//! moment.js\n//! version : 2.10.6\n//! authors : Tim Wood, Iskren Chernev, Moment.js contributors\n//! license : MIT\n//! momentjs.com\n\n(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :\n typeof define === 'function' && define.amd ? define(factory) :\n global.moment = factory()\n}(this, function () { 'use strict';\n\n var hookCallback;\n\n function utils_hooks__hooks () {\n return hookCallback.apply(null, arguments);\n }\n\n // This is done to register the method called with moment()\n // without creating circular dependencies.\n function setHookCallback (callback) {\n hookCallback = callback;\n }\n\n function isArray(input) {\n return Object.prototype.toString.call(input) === '[object Array]';\n }\n\n function isDate(input) {\n return input instanceof Date || Object.prototype.toString.call(input) === '[object Date]';\n }\n\n function map(arr, fn) {\n var res = [], i;\n for (i = 0; i < arr.length; ++i) {\n res.push(fn(arr[i], i));\n }\n return res;\n }\n\n function hasOwnProp(a, b) {\n return Object.prototype.hasOwnProperty.call(a, b);\n }\n\n function extend(a, b) {\n for (var i in b) {\n if (hasOwnProp(b, i)) {\n a[i] = b[i];\n }\n }\n\n if (hasOwnProp(b, 'toString')) {\n a.toString = b.toString;\n }\n\n if (hasOwnProp(b, 'valueOf')) {\n a.valueOf = b.valueOf;\n }\n\n return a;\n }\n\n function create_utc__createUTC (input, format, locale, strict) {\n return createLocalOrUTC(input, format, locale, strict, true).utc();\n }\n\n function defaultParsingFlags() {\n // We need to deep clone this object.\n return {\n empty : false,\n unusedTokens : [],\n unusedInput : [],\n overflow : -2,\n charsLeftOver : 0,\n nullInput : false,\n invalidMonth : null,\n invalidFormat : false,\n userInvalidated : false,\n iso : false\n };\n }\n\n function getParsingFlags(m) {\n if (m._pf == null) {\n m._pf = defaultParsingFlags();\n }\n return m._pf;\n }\n\n function valid__isValid(m) {\n if (m._isValid == null) {\n var flags = getParsingFlags(m);\n m._isValid = !isNaN(m._d.getTime()) &&\n flags.overflow < 0 &&\n !flags.empty &&\n !flags.invalidMonth &&\n !flags.invalidWeekday &&\n !flags.nullInput &&\n !flags.invalidFormat &&\n !flags.userInvalidated;\n\n if (m._strict) {\n m._isValid = m._isValid &&\n flags.charsLeftOver === 0 &&\n flags.unusedTokens.length === 0 &&\n flags.bigHour === undefined;\n }\n }\n return m._isValid;\n }\n\n function valid__createInvalid (flags) {\n var m = create_utc__createUTC(NaN);\n if (flags != null) {\n extend(getParsingFlags(m), flags);\n }\n else {\n getParsingFlags(m).userInvalidated = true;\n }\n\n return m;\n }\n\n var momentProperties = utils_hooks__hooks.momentProperties = [];\n\n function copyConfig(to, from) {\n var i, prop, val;\n\n if (typeof from._isAMomentObject !== 'undefined') {\n to._isAMomentObject = from._isAMomentObject;\n }\n if (typeof from._i !== 'undefined') {\n to._i = from._i;\n }\n if (typeof from._f !== 'undefined') {\n to._f = from._f;\n }\n if (typeof from._l !== 'undefined') {\n to._l = from._l;\n }\n if (typeof from._strict !== 'undefined') {\n to._strict = from._strict;\n }\n if (typeof from._tzm !== 'undefined') {\n to._tzm = from._tzm;\n }\n if (typeof from._isUTC !== 'undefined') {\n to._isUTC = from._isUTC;\n }\n if (typeof from._offset !== 'undefined') {\n to._offset = from._offset;\n }\n if (typeof from._pf !== 'undefined') {\n to._pf = getParsingFlags(from);\n }\n if (typeof from._locale !== 'undefined') {\n to._locale = from._locale;\n }\n\n if (momentProperties.length > 0) {\n for (i in momentProperties) {\n prop = momentProperties[i];\n val = from[prop];\n if (typeof val !== 'undefined') {\n to[prop] = val;\n }\n }\n }\n\n return to;\n }\n\n var updateInProgress = false;\n\n // Moment prototype object\n function Moment(config) {\n copyConfig(this, config);\n this._d = new Date(config._d != null ? config._d.getTime() : NaN);\n // Prevent infinite loop in case updateOffset creates new moment\n // objects.\n if (updateInProgress === false) {\n updateInProgress = true;\n utils_hooks__hooks.updateOffset(this);\n updateInProgress = false;\n }\n }\n\n function isMoment (obj) {\n return obj instanceof Moment || (obj != null && obj._isAMomentObject != null);\n }\n\n function absFloor (number) {\n if (number < 0) {\n return Math.ceil(number);\n } else {\n return Math.floor(number);\n }\n }\n\n function toInt(argumentForCoercion) {\n var coercedNumber = +argumentForCoercion,\n value = 0;\n\n if (coercedNumber !== 0 && isFinite(coercedNumber)) {\n value = absFloor(coercedNumber);\n }\n\n return value;\n }\n\n function compareArrays(array1, array2, dontConvert) {\n var len = Math.min(array1.length, array2.length),\n lengthDiff = Math.abs(array1.length - array2.length),\n diffs = 0,\n i;\n for (i = 0; i < len; i++) {\n if ((dontConvert && array1[i] !== array2[i]) ||\n (!dontConvert && toInt(array1[i]) !== toInt(array2[i]))) {\n diffs++;\n }\n }\n return diffs + lengthDiff;\n }\n\n function Locale() {\n }\n\n var locales = {};\n var globalLocale;\n\n function normalizeLocale(key) {\n return key ? key.toLowerCase().replace('_', '-') : key;\n }\n\n // pick the locale from the array\n // try ['en-au', 'en-gb'] as 'en-au', 'en-gb', 'en', as in move through the list trying each\n // substring from most specific to least, but move to the next array item if it's a more specific variant than the current root\n function chooseLocale(names) {\n var i = 0, j, next, locale, split;\n\n while (i < names.length) {\n split = normalizeLocale(names[i]).split('-');\n j = split.length;\n next = normalizeLocale(names[i + 1]);\n next = next ? next.split('-') : null;\n while (j > 0) {\n locale = loadLocale(split.slice(0, j).join('-'));\n if (locale) {\n return locale;\n }\n if (next && next.length >= j && compareArrays(split, next, true) >= j - 1) {\n //the next array item is better than a shallower substring of this one\n break;\n }\n j--;\n }\n i++;\n }\n return null;\n }\n\n function loadLocale(name) {\n var oldLocale = null;\n // TODO: Find a better way to register and load all the locales in Node\n if (!locales[name] && typeof module !== 'undefined' &&\n module && module.exports) {\n try {\n oldLocale = globalLocale._abbr;\n require('./locale/' + name);\n // because defineLocale currently also sets the global locale, we\n // want to undo that for lazy loaded locales\n locale_locales__getSetGlobalLocale(oldLocale);\n } catch (e) { }\n }\n return locales[name];\n }\n\n // This function will load locale and then set the global locale. If\n // no arguments are passed in, it will simply return the current global\n // locale key.\n function locale_locales__getSetGlobalLocale (key, values) {\n var data;\n if (key) {\n if (typeof values === 'undefined') {\n data = locale_locales__getLocale(key);\n }\n else {\n data = defineLocale(key, values);\n }\n\n if (data) {\n // moment.duration._locale = moment._locale = data;\n globalLocale = data;\n }\n }\n\n return globalLocale._abbr;\n }\n\n function defineLocale (name, values) {\n if (values !== null) {\n values.abbr = name;\n locales[name] = locales[name] || new Locale();\n locales[name].set(values);\n\n // backwards compat for now: also set the locale\n locale_locales__getSetGlobalLocale(name);\n\n return locales[name];\n } else {\n // useful for testing\n delete locales[name];\n return null;\n }\n }\n\n // returns locale data\n function locale_locales__getLocale (key) {\n var locale;\n\n if (key && key._locale && key._locale._abbr) {\n key = key._locale._abbr;\n }\n\n if (!key) {\n return globalLocale;\n }\n\n if (!isArray(key)) {\n //short-circuit everything else\n locale = loadLocale(key);\n if (locale) {\n return locale;\n }\n key = [key];\n }\n\n return chooseLocale(key);\n }\n\n var aliases = {};\n\n function addUnitAlias (unit, shorthand) {\n var lowerCase = unit.toLowerCase();\n aliases[lowerCase] = aliases[lowerCase + 's'] = aliases[shorthand] = unit;\n }\n\n function normalizeUnits(units) {\n return typeof units === 'string' ? aliases[units] || aliases[units.toLowerCase()] : undefined;\n }\n\n function normalizeObjectUnits(inputObject) {\n var normalizedInput = {},\n normalizedProp,\n prop;\n\n for (prop in inputObject) {\n if (hasOwnProp(inputObject, prop)) {\n normalizedProp = normalizeUnits(prop);\n if (normalizedProp) {\n normalizedInput[normalizedProp] = inputObject[prop];\n }\n }\n }\n\n return normalizedInput;\n }\n\n function makeGetSet (unit, keepTime) {\n return function (value) {\n if (value != null) {\n get_set__set(this, unit, value);\n utils_hooks__hooks.updateOffset(this, keepTime);\n return this;\n } else {\n return get_set__get(this, unit);\n }\n };\n }\n\n function get_set__get (mom, unit) {\n return mom._d['get' + (mom._isUTC ? 'UTC' : '') + unit]();\n }\n\n function get_set__set (mom, unit, value) {\n return mom._d['set' + (mom._isUTC ? 'UTC' : '') + unit](value);\n }\n\n // MOMENTS\n\n function getSet (units, value) {\n var unit;\n if (typeof units === 'object') {\n for (unit in units) {\n this.set(unit, units[unit]);\n }\n } else {\n units = normalizeUnits(units);\n if (typeof this[units] === 'function') {\n return this[units](value);\n }\n }\n return this;\n }\n\n function zeroFill(number, targetLength, forceSign) {\n var absNumber = '' + Math.abs(number),\n zerosToFill = targetLength - absNumber.length,\n sign = number >= 0;\n return (sign ? (forceSign ? '+' : '') : '-') +\n Math.pow(10, Math.max(0, zerosToFill)).toString().substr(1) + absNumber;\n }\n\n var formattingTokens = /(\\[[^\\[]*\\])|(\\\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Q|YYYYYY|YYYYY|YYYY|YY|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;\n\n var localFormattingTokens = /(\\[[^\\[]*\\])|(\\\\)?(LTS|LT|LL?L?L?|l{1,4})/g;\n\n var formatFunctions = {};\n\n var formatTokenFunctions = {};\n\n // token: 'M'\n // padded: ['MM', 2]\n // ordinal: 'Mo'\n // callback: function () { this.month() + 1 }\n function addFormatToken (token, padded, ordinal, callback) {\n var func = callback;\n if (typeof callback === 'string') {\n func = function () {\n return this[callback]();\n };\n }\n if (token) {\n formatTokenFunctions[token] = func;\n }\n if (padded) {\n formatTokenFunctions[padded[0]] = function () {\n return zeroFill(func.apply(this, arguments), padded[1], padded[2]);\n };\n }\n if (ordinal) {\n formatTokenFunctions[ordinal] = function () {\n return this.localeData().ordinal(func.apply(this, arguments), token);\n };\n }\n }\n\n function removeFormattingTokens(input) {\n if (input.match(/\\[[\\s\\S]/)) {\n return input.replace(/^\\[|\\]$/g, '');\n }\n return input.replace(/\\\\/g, '');\n }\n\n function makeFormatFunction(format) {\n var array = format.match(formattingTokens), i, length;\n\n for (i = 0, length = array.length; i < length; i++) {\n if (formatTokenFunctions[array[i]]) {\n array[i] = formatTokenFunctions[array[i]];\n } else {\n array[i] = removeFormattingTokens(array[i]);\n }\n }\n\n return function (mom) {\n var output = '';\n for (i = 0; i < length; i++) {\n output += array[i] instanceof Function ? array[i].call(mom, format) : array[i];\n }\n return output;\n };\n }\n\n // format date using native date object\n function formatMoment(m, format) {\n if (!m.isValid()) {\n return m.localeData().invalidDate();\n }\n\n format = expandFormat(format, m.localeData());\n formatFunctions[format] = formatFunctions[format] || makeFormatFunction(format);\n\n return formatFunctions[format](m);\n }\n\n function expandFormat(format, locale) {\n var i = 5;\n\n function replaceLongDateFormatTokens(input) {\n return locale.longDateFormat(input) || input;\n }\n\n localFormattingTokens.lastIndex = 0;\n while (i >= 0 && localFormattingTokens.test(format)) {\n format = format.replace(localFormattingTokens, replaceLongDateFormatTokens);\n localFormattingTokens.lastIndex = 0;\n i -= 1;\n }\n\n return format;\n }\n\n var match1 = /\\d/; // 0 - 9\n var match2 = /\\d\\d/; // 00 - 99\n var match3 = /\\d{3}/; // 000 - 999\n var match4 = /\\d{4}/; // 0000 - 9999\n var match6 = /[+-]?\\d{6}/; // -999999 - 999999\n var match1to2 = /\\d\\d?/; // 0 - 99\n var match1to3 = /\\d{1,3}/; // 0 - 999\n var match1to4 = /\\d{1,4}/; // 0 - 9999\n var match1to6 = /[+-]?\\d{1,6}/; // -999999 - 999999\n\n var matchUnsigned = /\\d+/; // 0 - inf\n var matchSigned = /[+-]?\\d+/; // -inf - inf\n\n var matchOffset = /Z|[+-]\\d\\d:?\\d\\d/gi; // +00:00 -00:00 +0000 -0000 or Z\n\n var matchTimestamp = /[+-]?\\d+(\\.\\d{1,3})?/; // 123456789 123456789.123\n\n // any word (or two) characters or numbers including two/three word month in arabic.\n var matchWord = /[0-9]*['a-z\\u00A0-\\u05FF\\u0700-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]+|[\\u0600-\\u06FF\\/]+(\\s*?[\\u0600-\\u06FF]+){1,2}/i;\n\n var regexes = {};\n\n function isFunction (sth) {\n // https://github.com/moment/moment/issues/2325\n return typeof sth === 'function' &&\n Object.prototype.toString.call(sth) === '[object Function]';\n }\n\n\n function addRegexToken (token, regex, strictRegex) {\n regexes[token] = isFunction(regex) ? regex : function (isStrict) {\n return (isStrict && strictRegex) ? strictRegex : regex;\n };\n }\n\n function getParseRegexForToken (token, config) {\n if (!hasOwnProp(regexes, token)) {\n return new RegExp(unescapeFormat(token));\n }\n\n return regexes[token](config._strict, config._locale);\n }\n\n // Code from http://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript\n function unescapeFormat(s) {\n return s.replace('\\\\', '').replace(/\\\\(\\[)|\\\\(\\])|\\[([^\\]\\[]*)\\]|\\\\(.)/g, function (matched, p1, p2, p3, p4) {\n return p1 || p2 || p3 || p4;\n }).replace(/[-\\/\\\\^$*+?.()|[\\]{}]/g, '\\\\$&');\n }\n\n var tokens = {};\n\n function addParseToken (token, callback) {\n var i, func = callback;\n if (typeof token === 'string') {\n token = [token];\n }\n if (typeof callback === 'number') {\n func = function (input, array) {\n array[callback] = toInt(input);\n };\n }\n for (i = 0; i < token.length; i++) {\n tokens[token[i]] = func;\n }\n }\n\n function addWeekParseToken (token, callback) {\n addParseToken(token, function (input, array, config, token) {\n config._w = config._w || {};\n callback(input, config._w, config, token);\n });\n }\n\n function addTimeToArrayFromToken(token, input, config) {\n if (input != null && hasOwnProp(tokens, token)) {\n tokens[token](input, config._a, config, token);\n }\n }\n\n var YEAR = 0;\n var MONTH = 1;\n var DATE = 2;\n var HOUR = 3;\n var MINUTE = 4;\n var SECOND = 5;\n var MILLISECOND = 6;\n\n function daysInMonth(year, month) {\n return new Date(Date.UTC(year, month + 1, 0)).getUTCDate();\n }\n\n // FORMATTING\n\n addFormatToken('M', ['MM', 2], 'Mo', function () {\n return this.month() + 1;\n });\n\n addFormatToken('MMM', 0, 0, function (format) {\n return this.localeData().monthsShort(this, format);\n });\n\n addFormatToken('MMMM', 0, 0, function (format) {\n return this.localeData().months(this, format);\n });\n\n // ALIASES\n\n addUnitAlias('month', 'M');\n\n // PARSING\n\n addRegexToken('M', match1to2);\n addRegexToken('MM', match1to2, match2);\n addRegexToken('MMM', matchWord);\n addRegexToken('MMMM', matchWord);\n\n addParseToken(['M', 'MM'], function (input, array) {\n array[MONTH] = toInt(input) - 1;\n });\n\n addParseToken(['MMM', 'MMMM'], function (input, array, config, token) {\n var month = config._locale.monthsParse(input, token, config._strict);\n // if we didn't find a month name, mark the date as invalid.\n if (month != null) {\n array[MONTH] = month;\n } else {\n getParsingFlags(config).invalidMonth = input;\n }\n });\n\n // LOCALES\n\n var defaultLocaleMonths = 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_');\n function localeMonths (m) {\n return this._months[m.month()];\n }\n\n var defaultLocaleMonthsShort = 'Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec'.split('_');\n function localeMonthsShort (m) {\n return this._monthsShort[m.month()];\n }\n\n function localeMonthsParse (monthName, format, strict) {\n var i, mom, regex;\n\n if (!this._monthsParse) {\n this._monthsParse = [];\n this._longMonthsParse = [];\n this._shortMonthsParse = [];\n }\n\n for (i = 0; i < 12; i++) {\n // make the regex if we don't have it already\n mom = create_utc__createUTC([2000, i]);\n if (strict && !this._longMonthsParse[i]) {\n this._longMonthsParse[i] = new RegExp('^' + this.months(mom, '').replace('.', '') + '$', 'i');\n this._shortMonthsParse[i] = new RegExp('^' + this.monthsShort(mom, '').replace('.', '') + '$', 'i');\n }\n if (!strict && !this._monthsParse[i]) {\n regex = '^' + this.months(mom, '') + '|^' + this.monthsShort(mom, '');\n this._monthsParse[i] = new RegExp(regex.replace('.', ''), 'i');\n }\n // test the regex\n if (strict && format === 'MMMM' && this._longMonthsParse[i].test(monthName)) {\n return i;\n } else if (strict && format === 'MMM' && this._shortMonthsParse[i].test(monthName)) {\n return i;\n } else if (!strict && this._monthsParse[i].test(monthName)) {\n return i;\n }\n }\n }\n\n // MOMENTS\n\n function setMonth (mom, value) {\n var dayOfMonth;\n\n // TODO: Move this out of here!\n if (typeof value === 'string') {\n value = mom.localeData().monthsParse(value);\n // TODO: Another silent failure?\n if (typeof value !== 'number') {\n return mom;\n }\n }\n\n dayOfMonth = Math.min(mom.date(), daysInMonth(mom.year(), value));\n mom._d['set' + (mom._isUTC ? 'UTC' : '') + 'Month'](value, dayOfMonth);\n return mom;\n }\n\n function getSetMonth (value) {\n if (value != null) {\n setMonth(this, value);\n utils_hooks__hooks.updateOffset(this, true);\n return this;\n } else {\n return get_set__get(this, 'Month');\n }\n }\n\n function getDaysInMonth () {\n return daysInMonth(this.year(), this.month());\n }\n\n function checkOverflow (m) {\n var overflow;\n var a = m._a;\n\n if (a && getParsingFlags(m).overflow === -2) {\n overflow =\n a[MONTH] < 0 || a[MONTH] > 11 ? MONTH :\n a[DATE] < 1 || a[DATE] > daysInMonth(a[YEAR], a[MONTH]) ? DATE :\n a[HOUR] < 0 || a[HOUR] > 24 || (a[HOUR] === 24 && (a[MINUTE] !== 0 || a[SECOND] !== 0 || a[MILLISECOND] !== 0)) ? HOUR :\n a[MINUTE] < 0 || a[MINUTE] > 59 ? MINUTE :\n a[SECOND] < 0 || a[SECOND] > 59 ? SECOND :\n a[MILLISECOND] < 0 || a[MILLISECOND] > 999 ? MILLISECOND :\n -1;\n\n if (getParsingFlags(m)._overflowDayOfYear && (overflow < YEAR || overflow > DATE)) {\n overflow = DATE;\n }\n\n getParsingFlags(m).overflow = overflow;\n }\n\n return m;\n }\n\n function warn(msg) {\n if (utils_hooks__hooks.suppressDeprecationWarnings === false && typeof console !== 'undefined' && console.warn) {\n console.warn('Deprecation warning: ' + msg);\n }\n }\n\n function deprecate(msg, fn) {\n var firstTime = true;\n\n return extend(function () {\n if (firstTime) {\n warn(msg + '\\n' + (new Error()).stack);\n firstTime = false;\n }\n return fn.apply(this, arguments);\n }, fn);\n }\n\n var deprecations = {};\n\n function deprecateSimple(name, msg) {\n if (!deprecations[name]) {\n warn(msg);\n deprecations[name] = true;\n }\n }\n\n utils_hooks__hooks.suppressDeprecationWarnings = false;\n\n var from_string__isoRegex = /^\\s*(?:[+-]\\d{6}|\\d{4})-(?:(\\d\\d-\\d\\d)|(W\\d\\d$)|(W\\d\\d-\\d)|(\\d\\d\\d))((T| )(\\d\\d(:\\d\\d(:\\d\\d(\\.\\d+)?)?)?)?([\\+\\-]\\d\\d(?::?\\d\\d)?|\\s*Z)?)?$/;\n\n var isoDates = [\n ['YYYYYY-MM-DD', /[+-]\\d{6}-\\d{2}-\\d{2}/],\n ['YYYY-MM-DD', /\\d{4}-\\d{2}-\\d{2}/],\n ['GGGG-[W]WW-E', /\\d{4}-W\\d{2}-\\d/],\n ['GGGG-[W]WW', /\\d{4}-W\\d{2}/],\n ['YYYY-DDD', /\\d{4}-\\d{3}/]\n ];\n\n // iso time formats and regexes\n var isoTimes = [\n ['HH:mm:ss.SSSS', /(T| )\\d\\d:\\d\\d:\\d\\d\\.\\d+/],\n ['HH:mm:ss', /(T| )\\d\\d:\\d\\d:\\d\\d/],\n ['HH:mm', /(T| )\\d\\d:\\d\\d/],\n ['HH', /(T| )\\d\\d/]\n ];\n\n var aspNetJsonRegex = /^\\/?Date\\((\\-?\\d+)/i;\n\n // date from iso format\n function configFromISO(config) {\n var i, l,\n string = config._i,\n match = from_string__isoRegex.exec(string);\n\n if (match) {\n getParsingFlags(config).iso = true;\n for (i = 0, l = isoDates.length; i < l; i++) {\n if (isoDates[i][1].exec(string)) {\n config._f = isoDates[i][0];\n break;\n }\n }\n for (i = 0, l = isoTimes.length; i < l; i++) {\n if (isoTimes[i][1].exec(string)) {\n // match[6] should be 'T' or space\n config._f += (match[6] || ' ') + isoTimes[i][0];\n break;\n }\n }\n if (string.match(matchOffset)) {\n config._f += 'Z';\n }\n configFromStringAndFormat(config);\n } else {\n config._isValid = false;\n }\n }\n\n // date from iso format or fallback\n function configFromString(config) {\n var matched = aspNetJsonRegex.exec(config._i);\n\n if (matched !== null) {\n config._d = new Date(+matched[1]);\n return;\n }\n\n configFromISO(config);\n if (config._isValid === false) {\n delete config._isValid;\n utils_hooks__hooks.createFromInputFallback(config);\n }\n }\n\n utils_hooks__hooks.createFromInputFallback = deprecate(\n 'moment construction falls back to js Date. This is ' +\n 'discouraged and will be removed in upcoming major ' +\n 'release. Please refer to ' +\n 'https://github.com/moment/moment/issues/1407 for more info.',\n function (config) {\n config._d = new Date(config._i + (config._useUTC ? ' UTC' : ''));\n }\n );\n\n function createDate (y, m, d, h, M, s, ms) {\n //can't just apply() to create a date:\n //http://stackoverflow.com/questions/181348/instantiating-a-javascript-object-by-calling-prototype-constructor-apply\n var date = new Date(y, m, d, h, M, s, ms);\n\n //the date constructor doesn't accept years < 1970\n if (y < 1970) {\n date.setFullYear(y);\n }\n return date;\n }\n\n function createUTCDate (y) {\n var date = new Date(Date.UTC.apply(null, arguments));\n if (y < 1970) {\n date.setUTCFullYear(y);\n }\n return date;\n }\n\n addFormatToken(0, ['YY', 2], 0, function () {\n return this.year() % 100;\n });\n\n addFormatToken(0, ['YYYY', 4], 0, 'year');\n addFormatToken(0, ['YYYYY', 5], 0, 'year');\n addFormatToken(0, ['YYYYYY', 6, true], 0, 'year');\n\n // ALIASES\n\n addUnitAlias('year', 'y');\n\n // PARSING\n\n addRegexToken('Y', matchSigned);\n addRegexToken('YY', match1to2, match2);\n addRegexToken('YYYY', match1to4, match4);\n addRegexToken('YYYYY', match1to6, match6);\n addRegexToken('YYYYYY', match1to6, match6);\n\n addParseToken(['YYYYY', 'YYYYYY'], YEAR);\n addParseToken('YYYY', function (input, array) {\n array[YEAR] = input.length === 2 ? utils_hooks__hooks.parseTwoDigitYear(input) : toInt(input);\n });\n addParseToken('YY', function (input, array) {\n array[YEAR] = utils_hooks__hooks.parseTwoDigitYear(input);\n });\n\n // HELPERS\n\n function daysInYear(year) {\n return isLeapYear(year) ? 366 : 365;\n }\n\n function isLeapYear(year) {\n return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;\n }\n\n // HOOKS\n\n utils_hooks__hooks.parseTwoDigitYear = function (input) {\n return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);\n };\n\n // MOMENTS\n\n var getSetYear = makeGetSet('FullYear', false);\n\n function getIsLeapYear () {\n return isLeapYear(this.year());\n }\n\n addFormatToken('w', ['ww', 2], 'wo', 'week');\n addFormatToken('W', ['WW', 2], 'Wo', 'isoWeek');\n\n // ALIASES\n\n addUnitAlias('week', 'w');\n addUnitAlias('isoWeek', 'W');\n\n // PARSING\n\n addRegexToken('w', match1to2);\n addRegexToken('ww', match1to2, match2);\n addRegexToken('W', match1to2);\n addRegexToken('WW', match1to2, match2);\n\n addWeekParseToken(['w', 'ww', 'W', 'WW'], function (input, week, config, token) {\n week[token.substr(0, 1)] = toInt(input);\n });\n\n // HELPERS\n\n // firstDayOfWeek 0 = sun, 6 = sat\n // the day of the week that starts the week\n // (usually sunday or monday)\n // firstDayOfWeekOfYear 0 = sun, 6 = sat\n // the first week is the week that contains the first\n // of this day of the week\n // (eg. ISO weeks use thursday (4))\n function weekOfYear(mom, firstDayOfWeek, firstDayOfWeekOfYear) {\n var end = firstDayOfWeekOfYear - firstDayOfWeek,\n daysToDayOfWeek = firstDayOfWeekOfYear - mom.day(),\n adjustedMoment;\n\n\n if (daysToDayOfWeek > end) {\n daysToDayOfWeek -= 7;\n }\n\n if (daysToDayOfWeek < end - 7) {\n daysToDayOfWeek += 7;\n }\n\n adjustedMoment = local__createLocal(mom).add(daysToDayOfWeek, 'd');\n return {\n week: Math.ceil(adjustedMoment.dayOfYear() / 7),\n year: adjustedMoment.year()\n };\n }\n\n // LOCALES\n\n function localeWeek (mom) {\n return weekOfYear(mom, this._week.dow, this._week.doy).week;\n }\n\n var defaultLocaleWeek = {\n dow : 0, // Sunday is the first day of the week.\n doy : 6 // The week that contains Jan 1st is the first week of the year.\n };\n\n function localeFirstDayOfWeek () {\n return this._week.dow;\n }\n\n function localeFirstDayOfYear () {\n return this._week.doy;\n }\n\n // MOMENTS\n\n function getSetWeek (input) {\n var week = this.localeData().week(this);\n return input == null ? week : this.add((input - week) * 7, 'd');\n }\n\n function getSetISOWeek (input) {\n var week = weekOfYear(this, 1, 4).week;\n return input == null ? week : this.add((input - week) * 7, 'd');\n }\n\n addFormatToken('DDD', ['DDDD', 3], 'DDDo', 'dayOfYear');\n\n // ALIASES\n\n addUnitAlias('dayOfYear', 'DDD');\n\n // PARSING\n\n addRegexToken('DDD', match1to3);\n addRegexToken('DDDD', match3);\n addParseToken(['DDD', 'DDDD'], function (input, array, config) {\n config._dayOfYear = toInt(input);\n });\n\n // HELPERS\n\n //http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday\n function dayOfYearFromWeeks(year, week, weekday, firstDayOfWeekOfYear, firstDayOfWeek) {\n var week1Jan = 6 + firstDayOfWeek - firstDayOfWeekOfYear, janX = createUTCDate(year, 0, 1 + week1Jan), d = janX.getUTCDay(), dayOfYear;\n if (d < firstDayOfWeek) {\n d += 7;\n }\n\n weekday = weekday != null ? 1 * weekday : firstDayOfWeek;\n\n dayOfYear = 1 + week1Jan + 7 * (week - 1) - d + weekday;\n\n return {\n year: dayOfYear > 0 ? year : year - 1,\n dayOfYear: dayOfYear > 0 ? dayOfYear : daysInYear(year - 1) + dayOfYear\n };\n }\n\n // MOMENTS\n\n function getSetDayOfYear (input) {\n var dayOfYear = Math.round((this.clone().startOf('day') - this.clone().startOf('year')) / 864e5) + 1;\n return input == null ? dayOfYear : this.add((input - dayOfYear), 'd');\n }\n\n // Pick the first defined of two or three arguments.\n function defaults(a, b, c) {\n if (a != null) {\n return a;\n }\n if (b != null) {\n return b;\n }\n return c;\n }\n\n function currentDateArray(config) {\n var now = new Date();\n if (config._useUTC) {\n return [now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()];\n }\n return [now.getFullYear(), now.getMonth(), now.getDate()];\n }\n\n // convert an array to a date.\n // the array should mirror the parameters below\n // note: all values past the year are optional and will default to the lowest possible value.\n // [year, month, day , hour, minute, second, millisecond]\n function configFromArray (config) {\n var i, date, input = [], currentDate, yearToUse;\n\n if (config._d) {\n return;\n }\n\n currentDate = currentDateArray(config);\n\n //compute day of the year from weeks and weekdays\n if (config._w && config._a[DATE] == null && config._a[MONTH] == null) {\n dayOfYearFromWeekInfo(config);\n }\n\n //if the day of the year is set, figure out what it is\n if (config._dayOfYear) {\n yearToUse = defaults(config._a[YEAR], currentDate[YEAR]);\n\n if (config._dayOfYear > daysInYear(yearToUse)) {\n getParsingFlags(config)._overflowDayOfYear = true;\n }\n\n date = createUTCDate(yearToUse, 0, config._dayOfYear);\n config._a[MONTH] = date.getUTCMonth();\n config._a[DATE] = date.getUTCDate();\n }\n\n // Default to current date.\n // * if no year, month, day of month are given, default to today\n // * if day of month is given, default month and year\n // * if month is given, default only year\n // * if year is given, don't default anything\n for (i = 0; i < 3 && config._a[i] == null; ++i) {\n config._a[i] = input[i] = currentDate[i];\n }\n\n // Zero out whatever was not defaulted, including time\n for (; i < 7; i++) {\n config._a[i] = input[i] = (config._a[i] == null) ? (i === 2 ? 1 : 0) : config._a[i];\n }\n\n // Check for 24:00:00.000\n if (config._a[HOUR] === 24 &&\n config._a[MINUTE] === 0 &&\n config._a[SECOND] === 0 &&\n config._a[MILLISECOND] === 0) {\n config._nextDay = true;\n config._a[HOUR] = 0;\n }\n\n config._d = (config._useUTC ? createUTCDate : createDate).apply(null, input);\n // Apply timezone offset from input. The actual utcOffset can be changed\n // with parseZone.\n if (config._tzm != null) {\n config._d.setUTCMinutes(config._d.getUTCMinutes() - config._tzm);\n }\n\n if (config._nextDay) {\n config._a[HOUR] = 24;\n }\n }\n\n function dayOfYearFromWeekInfo(config) {\n var w, weekYear, week, weekday, dow, doy, temp;\n\n w = config._w;\n if (w.GG != null || w.W != null || w.E != null) {\n dow = 1;\n doy = 4;\n\n // TODO: We need to take the current isoWeekYear, but that depends on\n // how we interpret now (local, utc, fixed offset). So create\n // a now version of current config (take local/utc/offset flags, and\n // create now).\n weekYear = defaults(w.GG, config._a[YEAR], weekOfYear(local__createLocal(), 1, 4).year);\n week = defaults(w.W, 1);\n weekday = defaults(w.E, 1);\n } else {\n dow = config._locale._week.dow;\n doy = config._locale._week.doy;\n\n weekYear = defaults(w.gg, config._a[YEAR], weekOfYear(local__createLocal(), dow, doy).year);\n week = defaults(w.w, 1);\n\n if (w.d != null) {\n // weekday -- low day numbers are considered next week\n weekday = w.d;\n if (weekday < dow) {\n ++week;\n }\n } else if (w.e != null) {\n // local weekday -- counting starts from begining of week\n weekday = w.e + dow;\n } else {\n // default to begining of week\n weekday = dow;\n }\n }\n temp = dayOfYearFromWeeks(weekYear, week, weekday, doy, dow);\n\n config._a[YEAR] = temp.year;\n config._dayOfYear = temp.dayOfYear;\n }\n\n utils_hooks__hooks.ISO_8601 = function () {};\n\n // date from string and format string\n function configFromStringAndFormat(config) {\n // TODO: Move this to another part of the creation flow to prevent circular deps\n if (config._f === utils_hooks__hooks.ISO_8601) {\n configFromISO(config);\n return;\n }\n\n config._a = [];\n getParsingFlags(config).empty = true;\n\n // This array is used to make a Date, either with `new Date` or `Date.UTC`\n var string = '' + config._i,\n i, parsedInput, tokens, token, skipped,\n stringLength = string.length,\n totalParsedInputLength = 0;\n\n tokens = expandFormat(config._f, config._locale).match(formattingTokens) || [];\n\n for (i = 0; i < tokens.length; i++) {\n token = tokens[i];\n parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0];\n if (parsedInput) {\n skipped = string.substr(0, string.indexOf(parsedInput));\n if (skipped.length > 0) {\n getParsingFlags(config).unusedInput.push(skipped);\n }\n string = string.slice(string.indexOf(parsedInput) + parsedInput.length);\n totalParsedInputLength += parsedInput.length;\n }\n // don't parse if it's not a known token\n if (formatTokenFunctions[token]) {\n if (parsedInput) {\n getParsingFlags(config).empty = false;\n }\n else {\n getParsingFlags(config).unusedTokens.push(token);\n }\n addTimeToArrayFromToken(token, parsedInput, config);\n }\n else if (config._strict && !parsedInput) {\n getParsingFlags(config).unusedTokens.push(token);\n }\n }\n\n // add remaining unparsed input length to the string\n getParsingFlags(config).charsLeftOver = stringLength - totalParsedInputLength;\n if (string.length > 0) {\n getParsingFlags(config).unusedInput.push(string);\n }\n\n // clear _12h flag if hour is <= 12\n if (getParsingFlags(config).bigHour === true &&\n config._a[HOUR] <= 12 &&\n config._a[HOUR] > 0) {\n getParsingFlags(config).bigHour = undefined;\n }\n // handle meridiem\n config._a[HOUR] = meridiemFixWrap(config._locale, config._a[HOUR], config._meridiem);\n\n configFromArray(config);\n checkOverflow(config);\n }\n\n\n function meridiemFixWrap (locale, hour, meridiem) {\n var isPm;\n\n if (meridiem == null) {\n // nothing to do\n return hour;\n }\n if (locale.meridiemHour != null) {\n return locale.meridiemHour(hour, meridiem);\n } else if (locale.isPM != null) {\n // Fallback\n isPm = locale.isPM(meridiem);\n if (isPm && hour < 12) {\n hour += 12;\n }\n if (!isPm && hour === 12) {\n hour = 0;\n }\n return hour;\n } else {\n // this is not supposed to happen\n return hour;\n }\n }\n\n function configFromStringAndArray(config) {\n var tempConfig,\n bestMoment,\n\n scoreToBeat,\n i,\n currentScore;\n\n if (config._f.length === 0) {\n getParsingFlags(config).invalidFormat = true;\n config._d = new Date(NaN);\n return;\n }\n\n for (i = 0; i < config._f.length; i++) {\n currentScore = 0;\n tempConfig = copyConfig({}, config);\n if (config._useUTC != null) {\n tempConfig._useUTC = config._useUTC;\n }\n tempConfig._f = config._f[i];\n configFromStringAndFormat(tempConfig);\n\n if (!valid__isValid(tempConfig)) {\n continue;\n }\n\n // if there is any input that was not parsed add a penalty for that format\n currentScore += getParsingFlags(tempConfig).charsLeftOver;\n\n //or tokens\n currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;\n\n getParsingFlags(tempConfig).score = currentScore;\n\n if (scoreToBeat == null || currentScore < scoreToBeat) {\n scoreToBeat = currentScore;\n bestMoment = tempConfig;\n }\n }\n\n extend(config, bestMoment || tempConfig);\n }\n\n function configFromObject(config) {\n if (config._d) {\n return;\n }\n\n var i = normalizeObjectUnits(config._i);\n config._a = [i.year, i.month, i.day || i.date, i.hour, i.minute, i.second, i.millisecond];\n\n configFromArray(config);\n }\n\n function createFromConfig (config) {\n var res = new Moment(checkOverflow(prepareConfig(config)));\n if (res._nextDay) {\n // Adding is smart enough around DST\n res.add(1, 'd');\n res._nextDay = undefined;\n }\n\n return res;\n }\n\n function prepareConfig (config) {\n var input = config._i,\n format = config._f;\n\n config._locale = config._locale || locale_locales__getLocale(config._l);\n\n if (input === null || (format === undefined && input === '')) {\n return valid__createInvalid({nullInput: true});\n }\n\n if (typeof input === 'string') {\n config._i = input = config._locale.preparse(input);\n }\n\n if (isMoment(input)) {\n return new Moment(checkOverflow(input));\n } else if (isArray(format)) {\n configFromStringAndArray(config);\n } else if (format) {\n configFromStringAndFormat(config);\n } else if (isDate(input)) {\n config._d = input;\n } else {\n configFromInput(config);\n }\n\n return config;\n }\n\n function configFromInput(config) {\n var input = config._i;\n if (input === undefined) {\n config._d = new Date();\n } else if (isDate(input)) {\n config._d = new Date(+input);\n } else if (typeof input === 'string') {\n configFromString(config);\n } else if (isArray(input)) {\n config._a = map(input.slice(0), function (obj) {\n return parseInt(obj, 10);\n });\n configFromArray(config);\n } else if (typeof(input) === 'object') {\n configFromObject(config);\n } else if (typeof(input) === 'number') {\n // from milliseconds\n config._d = new Date(input);\n } else {\n utils_hooks__hooks.createFromInputFallback(config);\n }\n }\n\n function createLocalOrUTC (input, format, locale, strict, isUTC) {\n var c = {};\n\n if (typeof(locale) === 'boolean') {\n strict = locale;\n locale = undefined;\n }\n // object construction must be done this way.\n // https://github.com/moment/moment/issues/1423\n c._isAMomentObject = true;\n c._useUTC = c._isUTC = isUTC;\n c._l = locale;\n c._i = input;\n c._f = format;\n c._strict = strict;\n\n return createFromConfig(c);\n }\n\n function local__createLocal (input, format, locale, strict) {\n return createLocalOrUTC(input, format, locale, strict, false);\n }\n\n var prototypeMin = deprecate(\n 'moment().min is deprecated, use moment.min instead. https://github.com/moment/moment/issues/1548',\n function () {\n var other = local__createLocal.apply(null, arguments);\n return other < this ? this : other;\n }\n );\n\n var prototypeMax = deprecate(\n 'moment().max is deprecated, use moment.max instead. https://github.com/moment/moment/issues/1548',\n function () {\n var other = local__createLocal.apply(null, arguments);\n return other > this ? this : other;\n }\n );\n\n // Pick a moment m from moments so that m[fn](other) is true for all\n // other. This relies on the function fn to be transitive.\n //\n // moments should either be an array of moment objects or an array, whose\n // first element is an array of moment objects.\n function pickBy(fn, moments) {\n var res, i;\n if (moments.length === 1 && isArray(moments[0])) {\n moments = moments[0];\n }\n if (!moments.length) {\n return local__createLocal();\n }\n res = moments[0];\n for (i = 1; i < moments.length; ++i) {\n if (!moments[i].isValid() || moments[i][fn](res)) {\n res = moments[i];\n }\n }\n return res;\n }\n\n // TODO: Use [].sort instead?\n function min () {\n var args = [].slice.call(arguments, 0);\n\n return pickBy('isBefore', args);\n }\n\n function max () {\n var args = [].slice.call(arguments, 0);\n\n return pickBy('isAfter', args);\n }\n\n function Duration (duration) {\n var normalizedInput = normalizeObjectUnits(duration),\n years = normalizedInput.year || 0,\n quarters = normalizedInput.quarter || 0,\n months = normalizedInput.month || 0,\n weeks = normalizedInput.week || 0,\n days = normalizedInput.day || 0,\n hours = normalizedInput.hour || 0,\n minutes = normalizedInput.minute || 0,\n seconds = normalizedInput.second || 0,\n milliseconds = normalizedInput.millisecond || 0;\n\n // representation for dateAddRemove\n this._milliseconds = +milliseconds +\n seconds * 1e3 + // 1000\n minutes * 6e4 + // 1000 * 60\n hours * 36e5; // 1000 * 60 * 60\n // Because of dateAddRemove treats 24 hours as different from a\n // day when working around DST, we need to store them separately\n this._days = +days +\n weeks * 7;\n // It is impossible translate months into days without knowing\n // which months you are are talking about, so we have to store\n // it separately.\n this._months = +months +\n quarters * 3 +\n years * 12;\n\n this._data = {};\n\n this._locale = locale_locales__getLocale();\n\n this._bubble();\n }\n\n function isDuration (obj) {\n return obj instanceof Duration;\n }\n\n function offset (token, separator) {\n addFormatToken(token, 0, 0, function () {\n var offset = this.utcOffset();\n var sign = '+';\n if (offset < 0) {\n offset = -offset;\n sign = '-';\n }\n return sign + zeroFill(~~(offset / 60), 2) + separator + zeroFill(~~(offset) % 60, 2);\n });\n }\n\n offset('Z', ':');\n offset('ZZ', '');\n\n // PARSING\n\n addRegexToken('Z', matchOffset);\n addRegexToken('ZZ', matchOffset);\n addParseToken(['Z', 'ZZ'], function (input, array, config) {\n config._useUTC = true;\n config._tzm = offsetFromString(input);\n });\n\n // HELPERS\n\n // timezone chunker\n // '+10:00' > ['10', '00']\n // '-1530' > ['-15', '30']\n var chunkOffset = /([\\+\\-]|\\d\\d)/gi;\n\n function offsetFromString(string) {\n var matches = ((string || '').match(matchOffset) || []);\n var chunk = matches[matches.length - 1] || [];\n var parts = (chunk + '').match(chunkOffset) || ['-', 0, 0];\n var minutes = +(parts[1] * 60) + toInt(parts[2]);\n\n return parts[0] === '+' ? minutes : -minutes;\n }\n\n // Return a moment from input, that is local/utc/zone equivalent to model.\n function cloneWithOffset(input, model) {\n var res, diff;\n if (model._isUTC) {\n res = model.clone();\n diff = (isMoment(input) || isDate(input) ? +input : +local__createLocal(input)) - (+res);\n // Use low-level api, because this fn is low-level api.\n res._d.setTime(+res._d + diff);\n utils_hooks__hooks.updateOffset(res, false);\n return res;\n } else {\n return local__createLocal(input).local();\n }\n }\n\n function getDateOffset (m) {\n // On Firefox.24 Date#getTimezoneOffset returns a floating point.\n // https://github.com/moment/moment/pull/1871\n return -Math.round(m._d.getTimezoneOffset() / 15) * 15;\n }\n\n // HOOKS\n\n // This function will be called whenever a moment is mutated.\n // It is intended to keep the offset in sync with the timezone.\n utils_hooks__hooks.updateOffset = function () {};\n\n // MOMENTS\n\n // keepLocalTime = true means only change the timezone, without\n // affecting the local hour. So 5:31:26 +0300 --[utcOffset(2, true)]-->\n // 5:31:26 +0200 It is possible that 5:31:26 doesn't exist with offset\n // +0200, so we adjust the time as needed, to be valid.\n //\n // Keeping the time actually adds/subtracts (one hour)\n // from the actual represented time. That is why we call updateOffset\n // a second time. In case it wants us to change the offset again\n // _changeInProgress == true case, then we have to adjust, because\n // there is no such time in the given timezone.\n function getSetOffset (input, keepLocalTime) {\n var offset = this._offset || 0,\n localAdjust;\n if (input != null) {\n if (typeof input === 'string') {\n input = offsetFromString(input);\n }\n if (Math.abs(input) < 16) {\n input = input * 60;\n }\n if (!this._isUTC && keepLocalTime) {\n localAdjust = getDateOffset(this);\n }\n this._offset = input;\n this._isUTC = true;\n if (localAdjust != null) {\n this.add(localAdjust, 'm');\n }\n if (offset !== input) {\n if (!keepLocalTime || this._changeInProgress) {\n add_subtract__addSubtract(this, create__createDuration(input - offset, 'm'), 1, false);\n } else if (!this._changeInProgress) {\n this._changeInProgress = true;\n utils_hooks__hooks.updateOffset(this, true);\n this._changeInProgress = null;\n }\n }\n return this;\n } else {\n return this._isUTC ? offset : getDateOffset(this);\n }\n }\n\n function getSetZone (input, keepLocalTime) {\n if (input != null) {\n if (typeof input !== 'string') {\n input = -input;\n }\n\n this.utcOffset(input, keepLocalTime);\n\n return this;\n } else {\n return -this.utcOffset();\n }\n }\n\n function setOffsetToUTC (keepLocalTime) {\n return this.utcOffset(0, keepLocalTime);\n }\n\n function setOffsetToLocal (keepLocalTime) {\n if (this._isUTC) {\n this.utcOffset(0, keepLocalTime);\n this._isUTC = false;\n\n if (keepLocalTime) {\n this.subtract(getDateOffset(this), 'm');\n }\n }\n return this;\n }\n\n function setOffsetToParsedOffset () {\n if (this._tzm) {\n this.utcOffset(this._tzm);\n } else if (typeof this._i === 'string') {\n this.utcOffset(offsetFromString(this._i));\n }\n return this;\n }\n\n function hasAlignedHourOffset (input) {\n input = input ? local__createLocal(input).utcOffset() : 0;\n\n return (this.utcOffset() - input) % 60 === 0;\n }\n\n function isDaylightSavingTime () {\n return (\n this.utcOffset() > this.clone().month(0).utcOffset() ||\n this.utcOffset() > this.clone().month(5).utcOffset()\n );\n }\n\n function isDaylightSavingTimeShifted () {\n if (typeof this._isDSTShifted !== 'undefined') {\n return this._isDSTShifted;\n }\n\n var c = {};\n\n copyConfig(c, this);\n c = prepareConfig(c);\n\n if (c._a) {\n var other = c._isUTC ? create_utc__createUTC(c._a) : local__createLocal(c._a);\n this._isDSTShifted = this.isValid() &&\n compareArrays(c._a, other.toArray()) > 0;\n } else {\n this._isDSTShifted = false;\n }\n\n return this._isDSTShifted;\n }\n\n function isLocal () {\n return !this._isUTC;\n }\n\n function isUtcOffset () {\n return this._isUTC;\n }\n\n function isUtc () {\n return this._isUTC && this._offset === 0;\n }\n\n var aspNetRegex = /(\\-)?(?:(\\d*)\\.)?(\\d+)\\:(\\d+)(?:\\:(\\d+)\\.?(\\d{3})?)?/;\n\n // from http://docs.closure-library.googlecode.com/git/closure_goog_date_date.js.source.html\n // somewhat more in line with 4.4.3.2 2004 spec, but allows decimal anywhere\n var create__isoRegex = /^(-)?P(?:(?:([0-9,.]*)Y)?(?:([0-9,.]*)M)?(?:([0-9,.]*)D)?(?:T(?:([0-9,.]*)H)?(?:([0-9,.]*)M)?(?:([0-9,.]*)S)?)?|([0-9,.]*)W)$/;\n\n function create__createDuration (input, key) {\n var duration = input,\n // matching against regexp is expensive, do it on demand\n match = null,\n sign,\n ret,\n diffRes;\n\n if (isDuration(input)) {\n duration = {\n ms : input._milliseconds,\n d : input._days,\n M : input._months\n };\n } else if (typeof input === 'number') {\n duration = {};\n if (key) {\n duration[key] = input;\n } else {\n duration.milliseconds = input;\n }\n } else if (!!(match = aspNetRegex.exec(input))) {\n sign = (match[1] === '-') ? -1 : 1;\n duration = {\n y : 0,\n d : toInt(match[DATE]) * sign,\n h : toInt(match[HOUR]) * sign,\n m : toInt(match[MINUTE]) * sign,\n s : toInt(match[SECOND]) * sign,\n ms : toInt(match[MILLISECOND]) * sign\n };\n } else if (!!(match = create__isoRegex.exec(input))) {\n sign = (match[1] === '-') ? -1 : 1;\n duration = {\n y : parseIso(match[2], sign),\n M : parseIso(match[3], sign),\n d : parseIso(match[4], sign),\n h : parseIso(match[5], sign),\n m : parseIso(match[6], sign),\n s : parseIso(match[7], sign),\n w : parseIso(match[8], sign)\n };\n } else if (duration == null) {// checks for null or undefined\n duration = {};\n } else if (typeof duration === 'object' && ('from' in duration || 'to' in duration)) {\n diffRes = momentsDifference(local__createLocal(duration.from), local__createLocal(duration.to));\n\n duration = {};\n duration.ms = diffRes.milliseconds;\n duration.M = diffRes.months;\n }\n\n ret = new Duration(duration);\n\n if (isDuration(input) && hasOwnProp(input, '_locale')) {\n ret._locale = input._locale;\n }\n\n return ret;\n }\n\n create__createDuration.fn = Duration.prototype;\n\n function parseIso (inp, sign) {\n // We'd normally use ~~inp for this, but unfortunately it also\n // converts floats to ints.\n // inp may be undefined, so careful calling replace on it.\n var res = inp && parseFloat(inp.replace(',', '.'));\n // apply sign while we're at it\n return (isNaN(res) ? 0 : res) * sign;\n }\n\n function positiveMomentsDifference(base, other) {\n var res = {milliseconds: 0, months: 0};\n\n res.months = other.month() - base.month() +\n (other.year() - base.year()) * 12;\n if (base.clone().add(res.months, 'M').isAfter(other)) {\n --res.months;\n }\n\n res.milliseconds = +other - +(base.clone().add(res.months, 'M'));\n\n return res;\n }\n\n function momentsDifference(base, other) {\n var res;\n other = cloneWithOffset(other, base);\n if (base.isBefore(other)) {\n res = positiveMomentsDifference(base, other);\n } else {\n res = positiveMomentsDifference(other, base);\n res.milliseconds = -res.milliseconds;\n res.months = -res.months;\n }\n\n return res;\n }\n\n function createAdder(direction, name) {\n return function (val, period) {\n var dur, tmp;\n //invert the arguments, but complain about it\n if (period !== null && !isNaN(+period)) {\n deprecateSimple(name, 'moment().' + name + '(period, number) is deprecated. Please use moment().' + name + '(number, period).');\n tmp = val; val = period; period = tmp;\n }\n\n val = typeof val === 'string' ? +val : val;\n dur = create__createDuration(val, period);\n add_subtract__addSubtract(this, dur, direction);\n return this;\n };\n }\n\n function add_subtract__addSubtract (mom, duration, isAdding, updateOffset) {\n var milliseconds = duration._milliseconds,\n days = duration._days,\n months = duration._months;\n updateOffset = updateOffset == null ? true : updateOffset;\n\n if (milliseconds) {\n mom._d.setTime(+mom._d + milliseconds * isAdding);\n }\n if (days) {\n get_set__set(mom, 'Date', get_set__get(mom, 'Date') + days * isAdding);\n }\n if (months) {\n setMonth(mom, get_set__get(mom, 'Month') + months * isAdding);\n }\n if (updateOffset) {\n utils_hooks__hooks.updateOffset(mom, days || months);\n }\n }\n\n var add_subtract__add = createAdder(1, 'add');\n var add_subtract__subtract = createAdder(-1, 'subtract');\n\n function moment_calendar__calendar (time, formats) {\n // We want to compare the start of today, vs this.\n // Getting start-of-today depends on whether we're local/utc/offset or not.\n var now = time || local__createLocal(),\n sod = cloneWithOffset(now, this).startOf('day'),\n diff = this.diff(sod, 'days', true),\n format = diff < -6 ? 'sameElse' :\n diff < -1 ? 'lastWeek' :\n diff < 0 ? 'lastDay' :\n diff < 1 ? 'sameDay' :\n diff < 2 ? 'nextDay' :\n diff < 7 ? 'nextWeek' : 'sameElse';\n return this.format(formats && formats[format] || this.localeData().calendar(format, this, local__createLocal(now)));\n }\n\n function clone () {\n return new Moment(this);\n }\n\n function isAfter (input, units) {\n var inputMs;\n units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');\n if (units === 'millisecond') {\n input = isMoment(input) ? input : local__createLocal(input);\n return +this > +input;\n } else {\n inputMs = isMoment(input) ? +input : +local__createLocal(input);\n return inputMs < +this.clone().startOf(units);\n }\n }\n\n function isBefore (input, units) {\n var inputMs;\n units = normalizeUnits(typeof units !== 'undefined' ? units : 'millisecond');\n if (units === 'millisecond') {\n input = isMoment(input) ? input : local__createLocal(input);\n return +this < +input;\n } else {\n inputMs = isMoment(input) ? +input : +local__createLocal(input);\n return +this.clone().endOf(units) < inputMs;\n }\n }\n\n function isBetween (from, to, units) {\n return this.isAfter(from, units) && this.isBefore(to, units);\n }\n\n function isSame (input, units) {\n var inputMs;\n units = normalizeUnits(units || 'millisecond');\n if (units === 'millisecond') {\n input = isMoment(input) ? input : local__createLocal(input);\n return +this === +input;\n } else {\n inputMs = +local__createLocal(input);\n return +(this.clone().startOf(units)) <= inputMs && inputMs <= +(this.clone().endOf(units));\n }\n }\n\n function diff (input, units, asFloat) {\n var that = cloneWithOffset(input, this),\n zoneDelta = (that.utcOffset() - this.utcOffset()) * 6e4,\n delta, output;\n\n units = normalizeUnits(units);\n\n if (units === 'year' || units === 'month' || units === 'quarter') {\n output = monthDiff(this, that);\n if (units === 'quarter') {\n output = output / 3;\n } else if (units === 'year') {\n output = output / 12;\n }\n } else {\n delta = this - that;\n output = units === 'second' ? delta / 1e3 : // 1000\n units === 'minute' ? delta / 6e4 : // 1000 * 60\n units === 'hour' ? delta / 36e5 : // 1000 * 60 * 60\n units === 'day' ? (delta - zoneDelta) / 864e5 : // 1000 * 60 * 60 * 24, negate dst\n units === 'week' ? (delta - zoneDelta) / 6048e5 : // 1000 * 60 * 60 * 24 * 7, negate dst\n delta;\n }\n return asFloat ? output : absFloor(output);\n }\n\n function monthDiff (a, b) {\n // difference in months\n var wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month()),\n // b is in (anchor - 1 month, anchor + 1 month)\n anchor = a.clone().add(wholeMonthDiff, 'months'),\n anchor2, adjust;\n\n if (b - anchor < 0) {\n anchor2 = a.clone().add(wholeMonthDiff - 1, 'months');\n // linear across the month\n adjust = (b - anchor) / (anchor - anchor2);\n } else {\n anchor2 = a.clone().add(wholeMonthDiff + 1, 'months');\n // linear across the month\n adjust = (b - anchor) / (anchor2 - anchor);\n }\n\n return -(wholeMonthDiff + adjust);\n }\n\n utils_hooks__hooks.defaultFormat = 'YYYY-MM-DDTHH:mm:ssZ';\n\n function toString () {\n return this.clone().locale('en').format('ddd MMM DD YYYY HH:mm:ss [GMT]ZZ');\n }\n\n function moment_format__toISOString () {\n var m = this.clone().utc();\n if (0 < m.year() && m.year() <= 9999) {\n if ('function' === typeof Date.prototype.toISOString) {\n // native implementation is ~50x faster, use it when we can\n return this.toDate().toISOString();\n } else {\n return formatMoment(m, 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]');\n }\n } else {\n return formatMoment(m, 'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]');\n }\n }\n\n function format (inputString) {\n var output = formatMoment(this, inputString || utils_hooks__hooks.defaultFormat);\n return this.localeData().postformat(output);\n }\n\n function from (time, withoutSuffix) {\n if (!this.isValid()) {\n return this.localeData().invalidDate();\n }\n return create__createDuration({to: this, from: time}).locale(this.locale()).humanize(!withoutSuffix);\n }\n\n function fromNow (withoutSuffix) {\n return this.from(local__createLocal(), withoutSuffix);\n }\n\n function to (time, withoutSuffix) {\n if (!this.isValid()) {\n return this.localeData().invalidDate();\n }\n return create__createDuration({from: this, to: time}).locale(this.locale()).humanize(!withoutSuffix);\n }\n\n function toNow (withoutSuffix) {\n return this.to(local__createLocal(), withoutSuffix);\n }\n\n function locale (key) {\n var newLocaleData;\n\n if (key === undefined) {\n return this._locale._abbr;\n } else {\n newLocaleData = locale_locales__getLocale(key);\n if (newLocaleData != null) {\n this._locale = newLocaleData;\n }\n return this;\n }\n }\n\n var lang = deprecate(\n 'moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',\n function (key) {\n if (key === undefined) {\n return this.localeData();\n } else {\n return this.locale(key);\n }\n }\n );\n\n function localeData () {\n return this._locale;\n }\n\n function startOf (units) {\n units = normalizeUnits(units);\n // the following switch intentionally omits break keywords\n // to utilize falling through the cases.\n switch (units) {\n case 'year':\n this.month(0);\n /* falls through */\n case 'quarter':\n case 'month':\n this.date(1);\n /* falls through */\n case 'week':\n case 'isoWeek':\n case 'day':\n this.hours(0);\n /* falls through */\n case 'hour':\n this.minutes(0);\n /* falls through */\n case 'minute':\n this.seconds(0);\n /* falls through */\n case 'second':\n this.milliseconds(0);\n }\n\n // weeks are a special case\n if (units === 'week') {\n this.weekday(0);\n }\n if (units === 'isoWeek') {\n this.isoWeekday(1);\n }\n\n // quarters are also special\n if (units === 'quarter') {\n this.month(Math.floor(this.month() / 3) * 3);\n }\n\n return this;\n }\n\n function endOf (units) {\n units = normalizeUnits(units);\n if (units === undefined || units === 'millisecond') {\n return this;\n }\n return this.startOf(units).add(1, (units === 'isoWeek' ? 'week' : units)).subtract(1, 'ms');\n }\n\n function to_type__valueOf () {\n return +this._d - ((this._offset || 0) * 60000);\n }\n\n function unix () {\n return Math.floor(+this / 1000);\n }\n\n function toDate () {\n return this._offset ? new Date(+this) : this._d;\n }\n\n function toArray () {\n var m = this;\n return [m.year(), m.month(), m.date(), m.hour(), m.minute(), m.second(), m.millisecond()];\n }\n\n function toObject () {\n var m = this;\n return {\n years: m.year(),\n months: m.month(),\n date: m.date(),\n hours: m.hours(),\n minutes: m.minutes(),\n seconds: m.seconds(),\n milliseconds: m.milliseconds()\n };\n }\n\n function moment_valid__isValid () {\n return valid__isValid(this);\n }\n\n function parsingFlags () {\n return extend({}, getParsingFlags(this));\n }\n\n function invalidAt () {\n return getParsingFlags(this).overflow;\n }\n\n addFormatToken(0, ['gg', 2], 0, function () {\n return this.weekYear() % 100;\n });\n\n addFormatToken(0, ['GG', 2], 0, function () {\n return this.isoWeekYear() % 100;\n });\n\n function addWeekYearFormatToken (token, getter) {\n addFormatToken(0, [token, token.length], 0, getter);\n }\n\n addWeekYearFormatToken('gggg', 'weekYear');\n addWeekYearFormatToken('ggggg', 'weekYear');\n addWeekYearFormatToken('GGGG', 'isoWeekYear');\n addWeekYearFormatToken('GGGGG', 'isoWeekYear');\n\n // ALIASES\n\n addUnitAlias('weekYear', 'gg');\n addUnitAlias('isoWeekYear', 'GG');\n\n // PARSING\n\n addRegexToken('G', matchSigned);\n addRegexToken('g', matchSigned);\n addRegexToken('GG', match1to2, match2);\n addRegexToken('gg', match1to2, match2);\n addRegexToken('GGGG', match1to4, match4);\n addRegexToken('gggg', match1to4, match4);\n addRegexToken('GGGGG', match1to6, match6);\n addRegexToken('ggggg', match1to6, match6);\n\n addWeekParseToken(['gggg', 'ggggg', 'GGGG', 'GGGGG'], function (input, week, config, token) {\n week[token.substr(0, 2)] = toInt(input);\n });\n\n addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {\n week[token] = utils_hooks__hooks.parseTwoDigitYear(input);\n });\n\n // HELPERS\n\n function weeksInYear(year, dow, doy) {\n return weekOfYear(local__createLocal([year, 11, 31 + dow - doy]), dow, doy).week;\n }\n\n // MOMENTS\n\n function getSetWeekYear (input) {\n var year = weekOfYear(this, this.localeData()._week.dow, this.localeData()._week.doy).year;\n return input == null ? year : this.add((input - year), 'y');\n }\n\n function getSetISOWeekYear (input) {\n var year = weekOfYear(this, 1, 4).year;\n return input == null ? year : this.add((input - year), 'y');\n }\n\n function getISOWeeksInYear () {\n return weeksInYear(this.year(), 1, 4);\n }\n\n function getWeeksInYear () {\n var weekInfo = this.localeData()._week;\n return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);\n }\n\n addFormatToken('Q', 0, 0, 'quarter');\n\n // ALIASES\n\n addUnitAlias('quarter', 'Q');\n\n // PARSING\n\n addRegexToken('Q', match1);\n addParseToken('Q', function (input, array) {\n array[MONTH] = (toInt(input) - 1) * 3;\n });\n\n // MOMENTS\n\n function getSetQuarter (input) {\n return input == null ? Math.ceil((this.month() + 1) / 3) : this.month((input - 1) * 3 + this.month() % 3);\n }\n\n addFormatToken('D', ['DD', 2], 'Do', 'date');\n\n // ALIASES\n\n addUnitAlias('date', 'D');\n\n // PARSING\n\n addRegexToken('D', match1to2);\n addRegexToken('DD', match1to2, match2);\n addRegexToken('Do', function (isStrict, locale) {\n return isStrict ? locale._ordinalParse : locale._ordinalParseLenient;\n });\n\n addParseToken(['D', 'DD'], DATE);\n addParseToken('Do', function (input, array) {\n array[DATE] = toInt(input.match(match1to2)[0], 10);\n });\n\n // MOMENTS\n\n var getSetDayOfMonth = makeGetSet('Date', true);\n\n addFormatToken('d', 0, 'do', 'day');\n\n addFormatToken('dd', 0, 0, function (format) {\n return this.localeData().weekdaysMin(this, format);\n });\n\n addFormatToken('ddd', 0, 0, function (format) {\n return this.localeData().weekdaysShort(this, format);\n });\n\n addFormatToken('dddd', 0, 0, function (format) {\n return this.localeData().weekdays(this, format);\n });\n\n addFormatToken('e', 0, 0, 'weekday');\n addFormatToken('E', 0, 0, 'isoWeekday');\n\n // ALIASES\n\n addUnitAlias('day', 'd');\n addUnitAlias('weekday', 'e');\n addUnitAlias('isoWeekday', 'E');\n\n // PARSING\n\n addRegexToken('d', match1to2);\n addRegexToken('e', match1to2);\n addRegexToken('E', match1to2);\n addRegexToken('dd', matchWord);\n addRegexToken('ddd', matchWord);\n addRegexToken('dddd', matchWord);\n\n addWeekParseToken(['dd', 'ddd', 'dddd'], function (input, week, config) {\n var weekday = config._locale.weekdaysParse(input);\n // if we didn't get a weekday name, mark the date as invalid\n if (weekday != null) {\n week.d = weekday;\n } else {\n getParsingFlags(config).invalidWeekday = input;\n }\n });\n\n addWeekParseToken(['d', 'e', 'E'], function (input, week, config, token) {\n week[token] = toInt(input);\n });\n\n // HELPERS\n\n function parseWeekday(input, locale) {\n if (typeof input !== 'string') {\n return input;\n }\n\n if (!isNaN(input)) {\n return parseInt(input, 10);\n }\n\n input = locale.weekdaysParse(input);\n if (typeof input === 'number') {\n return input;\n }\n\n return null;\n }\n\n // LOCALES\n\n var defaultLocaleWeekdays = 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_');\n function localeWeekdays (m) {\n return this._weekdays[m.day()];\n }\n\n var defaultLocaleWeekdaysShort = 'Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_');\n function localeWeekdaysShort (m) {\n return this._weekdaysShort[m.day()];\n }\n\n var defaultLocaleWeekdaysMin = 'Su_Mo_Tu_We_Th_Fr_Sa'.split('_');\n function localeWeekdaysMin (m) {\n return this._weekdaysMin[m.day()];\n }\n\n function localeWeekdaysParse (weekdayName) {\n var i, mom, regex;\n\n this._weekdaysParse = this._weekdaysParse || [];\n\n for (i = 0; i < 7; i++) {\n // make the regex if we don't have it already\n if (!this._weekdaysParse[i]) {\n mom = local__createLocal([2000, 1]).day(i);\n regex = '^' + this.weekdays(mom, '') + '|^' + this.weekdaysShort(mom, '') + '|^' + this.weekdaysMin(mom, '');\n this._weekdaysParse[i] = new RegExp(regex.replace('.', ''), 'i');\n }\n // test the regex\n if (this._weekdaysParse[i].test(weekdayName)) {\n return i;\n }\n }\n }\n\n // MOMENTS\n\n function getSetDayOfWeek (input) {\n var day = this._isUTC ? this._d.getUTCDay() : this._d.getDay();\n if (input != null) {\n input = parseWeekday(input, this.localeData());\n return this.add(input - day, 'd');\n } else {\n return day;\n }\n }\n\n function getSetLocaleDayOfWeek (input) {\n var weekday = (this.day() + 7 - this.localeData()._week.dow) % 7;\n return input == null ? weekday : this.add(input - weekday, 'd');\n }\n\n function getSetISODayOfWeek (input) {\n // behaves the same as moment#day except\n // as a getter, returns 7 instead of 0 (1-7 range instead of 0-6)\n // as a setter, sunday should belong to the previous week.\n return input == null ? this.day() || 7 : this.day(this.day() % 7 ? input : input - 7);\n }\n\n addFormatToken('H', ['HH', 2], 0, 'hour');\n addFormatToken('h', ['hh', 2], 0, function () {\n return this.hours() % 12 || 12;\n });\n\n function meridiem (token, lowercase) {\n addFormatToken(token, 0, 0, function () {\n return this.localeData().meridiem(this.hours(), this.minutes(), lowercase);\n });\n }\n\n meridiem('a', true);\n meridiem('A', false);\n\n // ALIASES\n\n addUnitAlias('hour', 'h');\n\n // PARSING\n\n function matchMeridiem (isStrict, locale) {\n return locale._meridiemParse;\n }\n\n addRegexToken('a', matchMeridiem);\n addRegexToken('A', matchMeridiem);\n addRegexToken('H', match1to2);\n addRegexToken('h', match1to2);\n addRegexToken('HH', match1to2, match2);\n addRegexToken('hh', match1to2, match2);\n\n addParseToken(['H', 'HH'], HOUR);\n addParseToken(['a', 'A'], function (input, array, config) {\n config._isPm = config._locale.isPM(input);\n config._meridiem = input;\n });\n addParseToken(['h', 'hh'], function (input, array, config) {\n array[HOUR] = toInt(input);\n getParsingFlags(config).bigHour = true;\n });\n\n // LOCALES\n\n function localeIsPM (input) {\n // IE8 Quirks Mode & IE7 Standards Mode do not allow accessing strings like arrays\n // Using charAt should be more compatible.\n return ((input + '').toLowerCase().charAt(0) === 'p');\n }\n\n var defaultLocaleMeridiemParse = /[ap]\\.?m?\\.?/i;\n function localeMeridiem (hours, minutes, isLower) {\n if (hours > 11) {\n return isLower ? 'pm' : 'PM';\n } else {\n return isLower ? 'am' : 'AM';\n }\n }\n\n\n // MOMENTS\n\n // Setting the hour should keep the time, because the user explicitly\n // specified which hour he wants. So trying to maintain the same hour (in\n // a new timezone) makes sense. Adding/subtracting hours does not follow\n // this rule.\n var getSetHour = makeGetSet('Hours', true);\n\n addFormatToken('m', ['mm', 2], 0, 'minute');\n\n // ALIASES\n\n addUnitAlias('minute', 'm');\n\n // PARSING\n\n addRegexToken('m', match1to2);\n addRegexToken('mm', match1to2, match2);\n addParseToken(['m', 'mm'], MINUTE);\n\n // MOMENTS\n\n var getSetMinute = makeGetSet('Minutes', false);\n\n addFormatToken('s', ['ss', 2], 0, 'second');\n\n // ALIASES\n\n addUnitAlias('second', 's');\n\n // PARSING\n\n addRegexToken('s', match1to2);\n addRegexToken('ss', match1to2, match2);\n addParseToken(['s', 'ss'], SECOND);\n\n // MOMENTS\n\n var getSetSecond = makeGetSet('Seconds', false);\n\n addFormatToken('S', 0, 0, function () {\n return ~~(this.millisecond() / 100);\n });\n\n addFormatToken(0, ['SS', 2], 0, function () {\n return ~~(this.millisecond() / 10);\n });\n\n addFormatToken(0, ['SSS', 3], 0, 'millisecond');\n addFormatToken(0, ['SSSS', 4], 0, function () {\n return this.millisecond() * 10;\n });\n addFormatToken(0, ['SSSSS', 5], 0, function () {\n return this.millisecond() * 100;\n });\n addFormatToken(0, ['SSSSSS', 6], 0, function () {\n return this.millisecond() * 1000;\n });\n addFormatToken(0, ['SSSSSSS', 7], 0, function () {\n return this.millisecond() * 10000;\n });\n addFormatToken(0, ['SSSSSSSS', 8], 0, function () {\n return this.millisecond() * 100000;\n });\n addFormatToken(0, ['SSSSSSSSS', 9], 0, function () {\n return this.millisecond() * 1000000;\n });\n\n\n // ALIASES\n\n addUnitAlias('millisecond', 'ms');\n\n // PARSING\n\n addRegexToken('S', match1to3, match1);\n addRegexToken('SS', match1to3, match2);\n addRegexToken('SSS', match1to3, match3);\n\n var token;\n for (token = 'SSSS'; token.length <= 9; token += 'S') {\n addRegexToken(token, matchUnsigned);\n }\n\n function parseMs(input, array) {\n array[MILLISECOND] = toInt(('0.' + input) * 1000);\n }\n\n for (token = 'S'; token.length <= 9; token += 'S') {\n addParseToken(token, parseMs);\n }\n // MOMENTS\n\n var getSetMillisecond = makeGetSet('Milliseconds', false);\n\n addFormatToken('z', 0, 0, 'zoneAbbr');\n addFormatToken('zz', 0, 0, 'zoneName');\n\n // MOMENTS\n\n function getZoneAbbr () {\n return this._isUTC ? 'UTC' : '';\n }\n\n function getZoneName () {\n return this._isUTC ? 'Coordinated Universal Time' : '';\n }\n\n var momentPrototype__proto = Moment.prototype;\n\n momentPrototype__proto.add = add_subtract__add;\n momentPrototype__proto.calendar = moment_calendar__calendar;\n momentPrototype__proto.clone = clone;\n momentPrototype__proto.diff = diff;\n momentPrototype__proto.endOf = endOf;\n momentPrototype__proto.format = format;\n momentPrototype__proto.from = from;\n momentPrototype__proto.fromNow = fromNow;\n momentPrototype__proto.to = to;\n momentPrototype__proto.toNow = toNow;\n momentPrototype__proto.get = getSet;\n momentPrototype__proto.invalidAt = invalidAt;\n momentPrototype__proto.isAfter = isAfter;\n momentPrototype__proto.isBefore = isBefore;\n momentPrototype__proto.isBetween = isBetween;\n momentPrototype__proto.isSame = isSame;\n momentPrototype__proto.isValid = moment_valid__isValid;\n momentPrototype__proto.lang = lang;\n momentPrototype__proto.locale = locale;\n momentPrototype__proto.localeData = localeData;\n momentPrototype__proto.max = prototypeMax;\n momentPrototype__proto.min = prototypeMin;\n momentPrototype__proto.parsingFlags = parsingFlags;\n momentPrototype__proto.set = getSet;\n momentPrototype__proto.startOf = startOf;\n momentPrototype__proto.subtract = add_subtract__subtract;\n momentPrototype__proto.toArray = toArray;\n momentPrototype__proto.toObject = toObject;\n momentPrototype__proto.toDate = toDate;\n momentPrototype__proto.toISOString = moment_format__toISOString;\n momentPrototype__proto.toJSON = moment_format__toISOString;\n momentPrototype__proto.toString = toString;\n momentPrototype__proto.unix = unix;\n momentPrototype__proto.valueOf = to_type__valueOf;\n\n // Year\n momentPrototype__proto.year = getSetYear;\n momentPrototype__proto.isLeapYear = getIsLeapYear;\n\n // Week Year\n momentPrototype__proto.weekYear = getSetWeekYear;\n momentPrototype__proto.isoWeekYear = getSetISOWeekYear;\n\n // Quarter\n momentPrototype__proto.quarter = momentPrototype__proto.quarters = getSetQuarter;\n\n // Month\n momentPrototype__proto.month = getSetMonth;\n momentPrototype__proto.daysInMonth = getDaysInMonth;\n\n // Week\n momentPrototype__proto.week = momentPrototype__proto.weeks = getSetWeek;\n momentPrototype__proto.isoWeek = momentPrototype__proto.isoWeeks = getSetISOWeek;\n momentPrototype__proto.weeksInYear = getWeeksInYear;\n momentPrototype__proto.isoWeeksInYear = getISOWeeksInYear;\n\n // Day\n momentPrototype__proto.date = getSetDayOfMonth;\n momentPrototype__proto.day = momentPrototype__proto.days = getSetDayOfWeek;\n momentPrototype__proto.weekday = getSetLocaleDayOfWeek;\n momentPrototype__proto.isoWeekday = getSetISODayOfWeek;\n momentPrototype__proto.dayOfYear = getSetDayOfYear;\n\n // Hour\n momentPrototype__proto.hour = momentPrototype__proto.hours = getSetHour;\n\n // Minute\n momentPrototype__proto.minute = momentPrototype__proto.minutes = getSetMinute;\n\n // Second\n momentPrototype__proto.second = momentPrototype__proto.seconds = getSetSecond;\n\n // Millisecond\n momentPrototype__proto.millisecond = momentPrototype__proto.milliseconds = getSetMillisecond;\n\n // Offset\n momentPrototype__proto.utcOffset = getSetOffset;\n momentPrototype__proto.utc = setOffsetToUTC;\n momentPrototype__proto.local = setOffsetToLocal;\n momentPrototype__proto.parseZone = setOffsetToParsedOffset;\n momentPrototype__proto.hasAlignedHourOffset = hasAlignedHourOffset;\n momentPrototype__proto.isDST = isDaylightSavingTime;\n momentPrototype__proto.isDSTShifted = isDaylightSavingTimeShifted;\n momentPrototype__proto.isLocal = isLocal;\n momentPrototype__proto.isUtcOffset = isUtcOffset;\n momentPrototype__proto.isUtc = isUtc;\n momentPrototype__proto.isUTC = isUtc;\n\n // Timezone\n momentPrototype__proto.zoneAbbr = getZoneAbbr;\n momentPrototype__proto.zoneName = getZoneName;\n\n // Deprecations\n momentPrototype__proto.dates = deprecate('dates accessor is deprecated. Use date instead.', getSetDayOfMonth);\n momentPrototype__proto.months = deprecate('months accessor is deprecated. Use month instead', getSetMonth);\n momentPrototype__proto.years = deprecate('years accessor is deprecated. Use year instead', getSetYear);\n momentPrototype__proto.zone = deprecate('moment().zone is deprecated, use moment().utcOffset instead. https://github.com/moment/moment/issues/1779', getSetZone);\n\n var momentPrototype = momentPrototype__proto;\n\n function moment__createUnix (input) {\n return local__createLocal(input * 1000);\n }\n\n function moment__createInZone () {\n return local__createLocal.apply(null, arguments).parseZone();\n }\n\n var defaultCalendar = {\n sameDay : '[Today at] LT',\n nextDay : '[Tomorrow at] LT',\n nextWeek : 'dddd [at] LT',\n lastDay : '[Yesterday at] LT',\n lastWeek : '[Last] dddd [at] LT',\n sameElse : 'L'\n };\n\n function locale_calendar__calendar (key, mom, now) {\n var output = this._calendar[key];\n return typeof output === 'function' ? output.call(mom, now) : output;\n }\n\n var defaultLongDateFormat = {\n LTS : 'h:mm:ss A',\n LT : 'h:mm A',\n L : 'MM/DD/YYYY',\n LL : 'MMMM D, YYYY',\n LLL : 'MMMM D, YYYY h:mm A',\n LLLL : 'dddd, MMMM D, YYYY h:mm A'\n };\n\n function longDateFormat (key) {\n var format = this._longDateFormat[key],\n formatUpper = this._longDateFormat[key.toUpperCase()];\n\n if (format || !formatUpper) {\n return format;\n }\n\n this._longDateFormat[key] = formatUpper.replace(/MMMM|MM|DD|dddd/g, function (val) {\n return val.slice(1);\n });\n\n return this._longDateFormat[key];\n }\n\n var defaultInvalidDate = 'Invalid date';\n\n function invalidDate () {\n return this._invalidDate;\n }\n\n var defaultOrdinal = '%d';\n var defaultOrdinalParse = /\\d{1,2}/;\n\n function ordinal (number) {\n return this._ordinal.replace('%d', number);\n }\n\n function preParsePostFormat (string) {\n return string;\n }\n\n var defaultRelativeTime = {\n future : 'in %s',\n past : '%s ago',\n s : 'a few seconds',\n m : 'a minute',\n mm : '%d minutes',\n h : 'an hour',\n hh : '%d hours',\n d : 'a day',\n dd : '%d days',\n M : 'a month',\n MM : '%d months',\n y : 'a year',\n yy : '%d years'\n };\n\n function relative__relativeTime (number, withoutSuffix, string, isFuture) {\n var output = this._relativeTime[string];\n return (typeof output === 'function') ?\n output(number, withoutSuffix, string, isFuture) :\n output.replace(/%d/i, number);\n }\n\n function pastFuture (diff, output) {\n var format = this._relativeTime[diff > 0 ? 'future' : 'past'];\n return typeof format === 'function' ? format(output) : format.replace(/%s/i, output);\n }\n\n function locale_set__set (config) {\n var prop, i;\n for (i in config) {\n prop = config[i];\n if (typeof prop === 'function') {\n this[i] = prop;\n } else {\n this['_' + i] = prop;\n }\n }\n // Lenient ordinal parsing accepts just a number in addition to\n // number + (possibly) stuff coming from _ordinalParseLenient.\n this._ordinalParseLenient = new RegExp(this._ordinalParse.source + '|' + (/\\d{1,2}/).source);\n }\n\n var prototype__proto = Locale.prototype;\n\n prototype__proto._calendar = defaultCalendar;\n prototype__proto.calendar = locale_calendar__calendar;\n prototype__proto._longDateFormat = defaultLongDateFormat;\n prototype__proto.longDateFormat = longDateFormat;\n prototype__proto._invalidDate = defaultInvalidDate;\n prototype__proto.invalidDate = invalidDate;\n prototype__proto._ordinal = defaultOrdinal;\n prototype__proto.ordinal = ordinal;\n prototype__proto._ordinalParse = defaultOrdinalParse;\n prototype__proto.preparse = preParsePostFormat;\n prototype__proto.postformat = preParsePostFormat;\n prototype__proto._relativeTime = defaultRelativeTime;\n prototype__proto.relativeTime = relative__relativeTime;\n prototype__proto.pastFuture = pastFuture;\n prototype__proto.set = locale_set__set;\n\n // Month\n prototype__proto.months = localeMonths;\n prototype__proto._months = defaultLocaleMonths;\n prototype__proto.monthsShort = localeMonthsShort;\n prototype__proto._monthsShort = defaultLocaleMonthsShort;\n prototype__proto.monthsParse = localeMonthsParse;\n\n // Week\n prototype__proto.week = localeWeek;\n prototype__proto._week = defaultLocaleWeek;\n prototype__proto.firstDayOfYear = localeFirstDayOfYear;\n prototype__proto.firstDayOfWeek = localeFirstDayOfWeek;\n\n // Day of Week\n prototype__proto.weekdays = localeWeekdays;\n prototype__proto._weekdays = defaultLocaleWeekdays;\n prototype__proto.weekdaysMin = localeWeekdaysMin;\n prototype__proto._weekdaysMin = defaultLocaleWeekdaysMin;\n prototype__proto.weekdaysShort = localeWeekdaysShort;\n prototype__proto._weekdaysShort = defaultLocaleWeekdaysShort;\n prototype__proto.weekdaysParse = localeWeekdaysParse;\n\n // Hours\n prototype__proto.isPM = localeIsPM;\n prototype__proto._meridiemParse = defaultLocaleMeridiemParse;\n prototype__proto.meridiem = localeMeridiem;\n\n function lists__get (format, index, field, setter) {\n var locale = locale_locales__getLocale();\n var utc = create_utc__createUTC().set(setter, index);\n return locale[field](utc, format);\n }\n\n function list (format, index, field, count, setter) {\n if (typeof format === 'number') {\n index = format;\n format = undefined;\n }\n\n format = format || '';\n\n if (index != null) {\n return lists__get(format, index, field, setter);\n }\n\n var i;\n var out = [];\n for (i = 0; i < count; i++) {\n out[i] = lists__get(format, i, field, setter);\n }\n return out;\n }\n\n function lists__listMonths (format, index) {\n return list(format, index, 'months', 12, 'month');\n }\n\n function lists__listMonthsShort (format, index) {\n return list(format, index, 'monthsShort', 12, 'month');\n }\n\n function lists__listWeekdays (format, index) {\n return list(format, index, 'weekdays', 7, 'day');\n }\n\n function lists__listWeekdaysShort (format, index) {\n return list(format, index, 'weekdaysShort', 7, 'day');\n }\n\n function lists__listWeekdaysMin (format, index) {\n return list(format, index, 'weekdaysMin', 7, 'day');\n }\n\n locale_locales__getSetGlobalLocale('en', {\n ordinalParse: /\\d{1,2}(th|st|nd|rd)/,\n ordinal : function (number) {\n var b = number % 10,\n output = (toInt(number % 100 / 10) === 1) ? 'th' :\n (b === 1) ? 'st' :\n (b === 2) ? 'nd' :\n (b === 3) ? 'rd' : 'th';\n return number + output;\n }\n });\n\n // Side effect imports\n utils_hooks__hooks.lang = deprecate('moment.lang is deprecated. Use moment.locale instead.', locale_locales__getSetGlobalLocale);\n utils_hooks__hooks.langData = deprecate('moment.langData is deprecated. Use moment.localeData instead.', locale_locales__getLocale);\n\n var mathAbs = Math.abs;\n\n function duration_abs__abs () {\n var data = this._data;\n\n this._milliseconds = mathAbs(this._milliseconds);\n this._days = mathAbs(this._days);\n this._months = mathAbs(this._months);\n\n data.milliseconds = mathAbs(data.milliseconds);\n data.seconds = mathAbs(data.seconds);\n data.minutes = mathAbs(data.minutes);\n data.hours = mathAbs(data.hours);\n data.months = mathAbs(data.months);\n data.years = mathAbs(data.years);\n\n return this;\n }\n\n function duration_add_subtract__addSubtract (duration, input, value, direction) {\n var other = create__createDuration(input, value);\n\n duration._milliseconds += direction * other._milliseconds;\n duration._days += direction * other._days;\n duration._months += direction * other._months;\n\n return duration._bubble();\n }\n\n // supports only 2.0-style add(1, 's') or add(duration)\n function duration_add_subtract__add (input, value) {\n return duration_add_subtract__addSubtract(this, input, value, 1);\n }\n\n // supports only 2.0-style subtract(1, 's') or subtract(duration)\n function duration_add_subtract__subtract (input, value) {\n return duration_add_subtract__addSubtract(this, input, value, -1);\n }\n\n function absCeil (number) {\n if (number < 0) {\n return Math.floor(number);\n } else {\n return Math.ceil(number);\n }\n }\n\n function bubble () {\n var milliseconds = this._milliseconds;\n var days = this._days;\n var months = this._months;\n var data = this._data;\n var seconds, minutes, hours, years, monthsFromDays;\n\n // if we have a mix of positive and negative values, bubble down first\n // check: https://github.com/moment/moment/issues/2166\n if (!((milliseconds >= 0 && days >= 0 && months >= 0) ||\n (milliseconds <= 0 && days <= 0 && months <= 0))) {\n milliseconds += absCeil(monthsToDays(months) + days) * 864e5;\n days = 0;\n months = 0;\n }\n\n // The following code bubbles up values, see the tests for\n // examples of what that means.\n data.milliseconds = milliseconds % 1000;\n\n seconds = absFloor(milliseconds / 1000);\n data.seconds = seconds % 60;\n\n minutes = absFloor(seconds / 60);\n data.minutes = minutes % 60;\n\n hours = absFloor(minutes / 60);\n data.hours = hours % 24;\n\n days += absFloor(hours / 24);\n\n // convert days to months\n monthsFromDays = absFloor(daysToMonths(days));\n months += monthsFromDays;\n days -= absCeil(monthsToDays(monthsFromDays));\n\n // 12 months -> 1 year\n years = absFloor(months / 12);\n months %= 12;\n\n data.days = days;\n data.months = months;\n data.years = years;\n\n return this;\n }\n\n function daysToMonths (days) {\n // 400 years have 146097 days (taking into account leap year rules)\n // 400 years have 12 months === 4800\n return days * 4800 / 146097;\n }\n\n function monthsToDays (months) {\n // the reverse of daysToMonths\n return months * 146097 / 4800;\n }\n\n function as (units) {\n var days;\n var months;\n var milliseconds = this._milliseconds;\n\n units = normalizeUnits(units);\n\n if (units === 'month' || units === 'year') {\n days = this._days + milliseconds / 864e5;\n months = this._months + daysToMonths(days);\n return units === 'month' ? months : months / 12;\n } else {\n // handle milliseconds separately because of floating point math errors (issue #1867)\n days = this._days + Math.round(monthsToDays(this._months));\n switch (units) {\n case 'week' : return days / 7 + milliseconds / 6048e5;\n case 'day' : return days + milliseconds / 864e5;\n case 'hour' : return days * 24 + milliseconds / 36e5;\n case 'minute' : return days * 1440 + milliseconds / 6e4;\n case 'second' : return days * 86400 + milliseconds / 1000;\n // Math.floor prevents floating point math errors here\n case 'millisecond': return Math.floor(days * 864e5) + milliseconds;\n default: throw new Error('Unknown unit ' + units);\n }\n }\n }\n\n // TODO: Use this.as('ms')?\n function duration_as__valueOf () {\n return (\n this._milliseconds +\n this._days * 864e5 +\n (this._months % 12) * 2592e6 +\n toInt(this._months / 12) * 31536e6\n );\n }\n\n function makeAs (alias) {\n return function () {\n return this.as(alias);\n };\n }\n\n var asMilliseconds = makeAs('ms');\n var asSeconds = makeAs('s');\n var asMinutes = makeAs('m');\n var asHours = makeAs('h');\n var asDays = makeAs('d');\n var asWeeks = makeAs('w');\n var asMonths = makeAs('M');\n var asYears = makeAs('y');\n\n function duration_get__get (units) {\n units = normalizeUnits(units);\n return this[units + 's']();\n }\n\n function makeGetter(name) {\n return function () {\n return this._data[name];\n };\n }\n\n var milliseconds = makeGetter('milliseconds');\n var seconds = makeGetter('seconds');\n var minutes = makeGetter('minutes');\n var hours = makeGetter('hours');\n var days = makeGetter('days');\n var months = makeGetter('months');\n var years = makeGetter('years');\n\n function weeks () {\n return absFloor(this.days() / 7);\n }\n\n var round = Math.round;\n var thresholds = {\n s: 45, // seconds to minute\n m: 45, // minutes to hour\n h: 22, // hours to day\n d: 26, // days to month\n M: 11 // months to year\n };\n\n // helper function for moment.fn.from, moment.fn.fromNow, and moment.duration.fn.humanize\n function substituteTimeAgo(string, number, withoutSuffix, isFuture, locale) {\n return locale.relativeTime(number || 1, !!withoutSuffix, string, isFuture);\n }\n\n function duration_humanize__relativeTime (posNegDuration, withoutSuffix, locale) {\n var duration = create__createDuration(posNegDuration).abs();\n var seconds = round(duration.as('s'));\n var minutes = round(duration.as('m'));\n var hours = round(duration.as('h'));\n var days = round(duration.as('d'));\n var months = round(duration.as('M'));\n var years = round(duration.as('y'));\n\n var a = seconds < thresholds.s && ['s', seconds] ||\n minutes === 1 && ['m'] ||\n minutes < thresholds.m && ['mm', minutes] ||\n hours === 1 && ['h'] ||\n hours < thresholds.h && ['hh', hours] ||\n days === 1 && ['d'] ||\n days < thresholds.d && ['dd', days] ||\n months === 1 && ['M'] ||\n months < thresholds.M && ['MM', months] ||\n years === 1 && ['y'] || ['yy', years];\n\n a[2] = withoutSuffix;\n a[3] = +posNegDuration > 0;\n a[4] = locale;\n return substituteTimeAgo.apply(null, a);\n }\n\n // This function allows you to set a threshold for relative time strings\n function duration_humanize__getSetRelativeTimeThreshold (threshold, limit) {\n if (thresholds[threshold] === undefined) {\n return false;\n }\n if (limit === undefined) {\n return thresholds[threshold];\n }\n thresholds[threshold] = limit;\n return true;\n }\n\n function humanize (withSuffix) {\n var locale = this.localeData();\n var output = duration_humanize__relativeTime(this, !withSuffix, locale);\n\n if (withSuffix) {\n output = locale.pastFuture(+this, output);\n }\n\n return locale.postformat(output);\n }\n\n var iso_string__abs = Math.abs;\n\n function iso_string__toISOString() {\n // for ISO strings we do not use the normal bubbling rules:\n // * milliseconds bubble up until they become hours\n // * days do not bubble at all\n // * months bubble up until they become years\n // This is because there is no context-free conversion between hours and days\n // (think of clock changes)\n // and also not between days and months (28-31 days per month)\n var seconds = iso_string__abs(this._milliseconds) / 1000;\n var days = iso_string__abs(this._days);\n var months = iso_string__abs(this._months);\n var minutes, hours, years;\n\n // 3600 seconds -> 60 minutes -> 1 hour\n minutes = absFloor(seconds / 60);\n hours = absFloor(minutes / 60);\n seconds %= 60;\n minutes %= 60;\n\n // 12 months -> 1 year\n years = absFloor(months / 12);\n months %= 12;\n\n\n // inspired by https://github.com/dordille/moment-isoduration/blob/master/moment.isoduration.js\n var Y = years;\n var M = months;\n var D = days;\n var h = hours;\n var m = minutes;\n var s = seconds;\n var total = this.asSeconds();\n\n if (!total) {\n // this is the same as C#'s (Noda) and python (isodate)...\n // but not other JS (goog.date)\n return 'P0D';\n }\n\n return (total < 0 ? '-' : '') +\n 'P' +\n (Y ? Y + 'Y' : '') +\n (M ? M + 'M' : '') +\n (D ? D + 'D' : '') +\n ((h || m || s) ? 'T' : '') +\n (h ? h + 'H' : '') +\n (m ? m + 'M' : '') +\n (s ? s + 'S' : '');\n }\n\n var duration_prototype__proto = Duration.prototype;\n\n duration_prototype__proto.abs = duration_abs__abs;\n duration_prototype__proto.add = duration_add_subtract__add;\n duration_prototype__proto.subtract = duration_add_subtract__subtract;\n duration_prototype__proto.as = as;\n duration_prototype__proto.asMilliseconds = asMilliseconds;\n duration_prototype__proto.asSeconds = asSeconds;\n duration_prototype__proto.asMinutes = asMinutes;\n duration_prototype__proto.asHours = asHours;\n duration_prototype__proto.asDays = asDays;\n duration_prototype__proto.asWeeks = asWeeks;\n duration_prototype__proto.asMonths = asMonths;\n duration_prototype__proto.asYears = asYears;\n duration_prototype__proto.valueOf = duration_as__valueOf;\n duration_prototype__proto._bubble = bubble;\n duration_prototype__proto.get = duration_get__get;\n duration_prototype__proto.milliseconds = milliseconds;\n duration_prototype__proto.seconds = seconds;\n duration_prototype__proto.minutes = minutes;\n duration_prototype__proto.hours = hours;\n duration_prototype__proto.days = days;\n duration_prototype__proto.weeks = weeks;\n duration_prototype__proto.months = months;\n duration_prototype__proto.years = years;\n duration_prototype__proto.humanize = humanize;\n duration_prototype__proto.toISOString = iso_string__toISOString;\n duration_prototype__proto.toString = iso_string__toISOString;\n duration_prototype__proto.toJSON = iso_string__toISOString;\n duration_prototype__proto.locale = locale;\n duration_prototype__proto.localeData = localeData;\n\n // Deprecations\n duration_prototype__proto.toIsoString = deprecate('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)', iso_string__toISOString);\n duration_prototype__proto.lang = lang;\n\n // Side effect imports\n\n addFormatToken('X', 0, 0, 'unix');\n addFormatToken('x', 0, 0, 'valueOf');\n\n // PARSING\n\n addRegexToken('x', matchSigned);\n addRegexToken('X', matchTimestamp);\n addParseToken('X', function (input, array, config) {\n config._d = new Date(parseFloat(input, 10) * 1000);\n });\n addParseToken('x', function (input, array, config) {\n config._d = new Date(toInt(input));\n });\n\n // Side effect imports\n\n\n utils_hooks__hooks.version = '2.10.6';\n\n setHookCallback(local__createLocal);\n\n utils_hooks__hooks.fn = momentPrototype;\n utils_hooks__hooks.min = min;\n utils_hooks__hooks.max = max;\n utils_hooks__hooks.utc = create_utc__createUTC;\n utils_hooks__hooks.unix = moment__createUnix;\n utils_hooks__hooks.months = lists__listMonths;\n utils_hooks__hooks.isDate = isDate;\n utils_hooks__hooks.locale = locale_locales__getSetGlobalLocale;\n utils_hooks__hooks.invalid = valid__createInvalid;\n utils_hooks__hooks.duration = create__createDuration;\n utils_hooks__hooks.isMoment = isMoment;\n utils_hooks__hooks.weekdays = lists__listWeekdays;\n utils_hooks__hooks.parseZone = moment__createInZone;\n utils_hooks__hooks.localeData = locale_locales__getLocale;\n utils_hooks__hooks.isDuration = isDuration;\n utils_hooks__hooks.monthsShort = lists__listMonthsShort;\n utils_hooks__hooks.weekdaysMin = lists__listWeekdaysMin;\n utils_hooks__hooks.defineLocale = defineLocale;\n utils_hooks__hooks.weekdaysShort = lists__listWeekdaysShort;\n utils_hooks__hooks.normalizeUnits = normalizeUnits;\n utils_hooks__hooks.relativeTimeThreshold = duration_humanize__getSetRelativeTimeThreshold;\n\n var _moment = utils_hooks__hooks;\n\n return _moment;\n\n}));\n/*!\n * FullCalendar v2.3.1\n * Docs & License: http://fullcalendar.io/\n * (c) 2015 Adam Shaw\n */\n\n(function(factory) {\n\tif (typeof define === 'function' && define.amd) {\n\t\tdefine([ 'jquery', 'moment' ], factory);\n\t}\n\telse if (typeof exports === 'object') { // Node/CommonJS\n\t\tmodule.exports = factory(require('jquery'), require('moment'));\n\t}\n\telse {\n\t\tfactory(jQuery, moment);\n\t}\n})(function($, moment) {\n\n;;\n\nvar fc = $.fullCalendar = { version: \"2.3.1\" };\nvar fcViews = fc.views = {};\n\n\n$.fn.fullCalendar = function(options) {\n\tvar args = Array.prototype.slice.call(arguments, 1); // for a possible method call\n\tvar res = this; // what this function will return (this jQuery object by default)\n\n\tthis.each(function(i, _element) { // loop each DOM element involved\n\t\tvar element = $(_element);\n\t\tvar calendar = element.data('fullCalendar'); // get the existing calendar object (if any)\n\t\tvar singleRes; // the returned value of this single method call\n\n\t\t// a method call\n\t\tif (typeof options === 'string') {\n\t\t\tif (calendar && $.isFunction(calendar[options])) {\n\t\t\t\tsingleRes = calendar[options].apply(calendar, args);\n\t\t\t\tif (!i) {\n\t\t\t\t\tres = singleRes; // record the first method call result\n\t\t\t\t}\n\t\t\t\tif (options === 'destroy') { // for the destroy method, must remove Calendar object data\n\t\t\t\t\telement.removeData('fullCalendar');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// a new calendar initialization\n\t\telse if (!calendar) { // don't initialize twice\n\t\t\tcalendar = new fc.CalendarBase(element, options);\n\t\t\telement.data('fullCalendar', calendar);\n\t\t\tcalendar.render();\n\t\t}\n\t});\n\t\n\treturn res;\n};\n\n\nvar complexOptions = [ // names of options that are objects whose properties should be combined\n\t'header',\n\t'buttonText',\n\t'buttonIcons',\n\t'themeButtonIcons'\n];\n\n\n// Recursively combines all passed-in option-hash arguments into a new single option-hash.\n// Given option-hashes are ordered from lowest to highest priority.\nfunction mergeOptions() {\n\tvar chain = Array.prototype.slice.call(arguments); // convert to a real array\n\tvar complexVals = {}; // hash for each complex option's combined values\n\tvar i, name;\n\tvar combinedVal;\n\tvar j;\n\tvar val;\n\n\t// for each complex option, loop through each option-hash and accumulate the combined values\n\tfor (i = 0; i < complexOptions.length; i++) {\n\t\tname = complexOptions[i];\n\t\tcombinedVal = null; // an object holding the merge of all the values\n\n\t\tfor (j = 0; j < chain.length; j++) {\n\t\t\tval = chain[j][name];\n\n\t\t\tif ($.isPlainObject(val)) {\n\t\t\t\tcombinedVal = $.extend(combinedVal || {}, val); // merge new properties\n\t\t\t}\n\t\t\telse if (val != null) { // a non-null non-undefined atomic option\n\t\t\t\tcombinedVal = null; // signal to use the atomic value\n\t\t\t}\n\t\t}\n\n\t\t// if not null, the final value was a combination of other objects. record it\n\t\tif (combinedVal !== null) {\n\t\t\tcomplexVals[name] = combinedVal;\n\t\t}\n\t}\n\n\tchain.unshift({}); // $.extend will mutate this with the result\n\tchain.push(complexVals); // computed complex values are applied last\n\treturn $.extend.apply($, chain); // combine\n}\n\n\n// Given options specified for the calendar's constructor, massages any legacy options into a non-legacy form.\n// Converts View-Option-Hashes into the View-Specific-Options format.\nfunction massageOverrides(input) {\n\tvar overrides = { views: input.views || {} }; // the output. ensure a `views` hash\n\tvar subObj;\n\n\t// iterate through all option override properties (except `views`)\n\t$.each(input, function(name, val) {\n\t\tif (name != 'views') {\n\n\t\t\t// could the value be a legacy View-Option-Hash?\n\t\t\tif (\n\t\t\t\t$.isPlainObject(val) &&\n\t\t\t\t!/(time|duration|interval)$/i.test(name) && // exclude duration options. might be given as objects\n\t\t\t\t$.inArray(name, complexOptions) == -1 // complex options aren't allowed to be View-Option-Hashes\n\t\t\t) {\n\t\t\t\tsubObj = null;\n\n\t\t\t\t// iterate through the properties of this possible View-Option-Hash value\n\t\t\t\t$.each(val, function(subName, subVal) {\n\n\t\t\t\t\t// is the property targeting a view?\n\t\t\t\t\tif (/^(month|week|day|default|basic(Week|Day)?|agenda(Week|Day)?)$/.test(subName)) {\n\t\t\t\t\t\tif (!overrides.views[subName]) { // ensure the view-target entry exists\n\t\t\t\t\t\t\toverrides.views[subName] = {};\n\t\t\t\t\t\t}\n\t\t\t\t\t\toverrides.views[subName][name] = subVal; // record the value in the `views` object\n\t\t\t\t\t}\n\t\t\t\t\telse { // a non-View-Option-Hash property\n\t\t\t\t\t\tif (!subObj) {\n\t\t\t\t\t\t\tsubObj = {};\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsubObj[subName] = subVal; // accumulate these unrelated values for later\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tif (subObj) { // non-View-Option-Hash properties? transfer them as-is\n\t\t\t\t\toverrides[name] = subObj;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\toverrides[name] = val; // transfer normal options as-is\n\t\t\t}\n\t\t}\n\t});\n\n\treturn overrides;\n}\n\n;;\n\n// exports\nfc.intersectionToSeg = intersectionToSeg;\nfc.applyAll = applyAll;\nfc.debounce = debounce;\nfc.isInt = isInt;\nfc.htmlEscape = htmlEscape;\nfc.cssToStr = cssToStr;\nfc.proxy = proxy;\n\n\n/* FullCalendar-specific DOM Utilities\n----------------------------------------------------------------------------------------------------------------------*/\n\n\n// Given the scrollbar widths of some other container, create borders/margins on rowEls in order to match the left\n// and right space that was offset by the scrollbars. A 1-pixel border first, then margin beyond that.\nfunction compensateScroll(rowEls, scrollbarWidths) {\n\tif (scrollbarWidths.left) {\n\t\trowEls.css({\n\t\t\t'border-left-width': 1,\n\t\t\t'margin-left': scrollbarWidths.left - 1\n\t\t});\n\t}\n\tif (scrollbarWidths.right) {\n\t\trowEls.css({\n\t\t\t'border-right-width': 1,\n\t\t\t'margin-right': scrollbarWidths.right - 1\n\t\t});\n\t}\n}\n\n\n// Undoes compensateScroll and restores all borders/margins\nfunction uncompensateScroll(rowEls) {\n\trowEls.css({\n\t\t'margin-left': '',\n\t\t'margin-right': '',\n\t\t'border-left-width': '',\n\t\t'border-right-width': ''\n\t});\n}\n\n\n// Make the mouse cursor express that an event is not allowed in the current area\nfunction disableCursor() {\n\t$('body').addClass('fc-not-allowed');\n}\n\n\n// Returns the mouse cursor to its original look\nfunction enableCursor() {\n\t$('body').removeClass('fc-not-allowed');\n}\n\n\n// Given a total available height to fill, have `els` (essentially child rows) expand to accomodate.\n// By default, all elements that are shorter than the recommended height are expanded uniformly, not considering\n// any other els that are already too tall. if `shouldRedistribute` is on, it considers these tall rows and \n// reduces the available height.\nfunction distributeHeight(els, availableHeight, shouldRedistribute) {\n\n\t// *FLOORING NOTE*: we floor in certain places because zoom can give inaccurate floating-point dimensions,\n\t// and it is better to be shorter than taller, to avoid creating unnecessary scrollbars.\n\n\tvar minOffset1 = Math.floor(availableHeight / els.length); // for non-last element\n\tvar minOffset2 = Math.floor(availableHeight - minOffset1 * (els.length - 1)); // for last element *FLOORING NOTE*\n\tvar flexEls = []; // elements that are allowed to expand. array of DOM nodes\n\tvar flexOffsets = []; // amount of vertical space it takes up\n\tvar flexHeights = []; // actual css height\n\tvar usedHeight = 0;\n\n\tundistributeHeight(els); // give all elements their natural height\n\n\t// find elements that are below the recommended height (expandable).\n\t// important to query for heights in a single first pass (to avoid reflow oscillation).\n\tels.each(function(i, el) {\n\t\tvar minOffset = i === els.length - 1 ? minOffset2 : minOffset1;\n\t\tvar naturalOffset = $(el).outerHeight(true);\n\n\t\tif (naturalOffset < minOffset) {\n\t\t\tflexEls.push(el);\n\t\t\tflexOffsets.push(naturalOffset);\n\t\t\tflexHeights.push($(el).height());\n\t\t}\n\t\telse {\n\t\t\t// this element stretches past recommended height (non-expandable). mark the space as occupied.\n\t\t\tusedHeight += naturalOffset;\n\t\t}\n\t});\n\n\t// readjust the recommended height to only consider the height available to non-maxed-out rows.\n\tif (shouldRedistribute) {\n\t\tavailableHeight -= usedHeight;\n\t\tminOffset1 = Math.floor(availableHeight / flexEls.length);\n\t\tminOffset2 = Math.floor(availableHeight - minOffset1 * (flexEls.length - 1)); // *FLOORING NOTE*\n\t}\n\n\t// assign heights to all expandable elements\n\t$(flexEls).each(function(i, el) {\n\t\tvar minOffset = i === flexEls.length - 1 ? minOffset2 : minOffset1;\n\t\tvar naturalOffset = flexOffsets[i];\n\t\tvar naturalHeight = flexHeights[i];\n\t\tvar newHeight = minOffset - (naturalOffset - naturalHeight); // subtract the margin/padding\n\n\t\tif (naturalOffset < minOffset) { // we check this again because redistribution might have changed things\n\t\t\t$(el).height(newHeight);\n\t\t}\n\t});\n}\n\n\n// Undoes distrubuteHeight, restoring all els to their natural height\nfunction undistributeHeight(els) {\n\tels.height('');\n}\n\n\n// Given `els`, a jQuery set of cells, find the cell with the largest natural width and set the widths of all the\n// cells to be that width.\n// PREREQUISITE: if you want a cell to take up width, it needs to have a single inner element w/ display:inline\nfunction matchCellWidths(els) {\n\tvar maxInnerWidth = 0;\n\n\tels.find('> *').each(function(i, innerEl) {\n\t\tvar innerWidth = $(innerEl).outerWidth();\n\t\tif (innerWidth > maxInnerWidth) {\n\t\t\tmaxInnerWidth = innerWidth;\n\t\t}\n\t});\n\n\tmaxInnerWidth++; // sometimes not accurate of width the text needs to stay on one line. insurance\n\n\tels.width(maxInnerWidth);\n\n\treturn maxInnerWidth;\n}\n\n\n// Turns a container element into a scroller if its contents is taller than the allotted height.\n// Returns true if the element is now a scroller, false otherwise.\n// NOTE: this method is best because it takes weird zooming dimensions into account\nfunction setPotentialScroller(containerEl, height) {\n\tcontainerEl.height(height).addClass('fc-scroller');\n\n\t// are scrollbars needed?\n\tif (containerEl[0].scrollHeight - 1 > containerEl[0].clientHeight) { // !!! -1 because IE is often off-by-one :(\n\t\treturn true;\n\t}\n\n\tunsetScroller(containerEl); // undo\n\treturn false;\n}\n\n\n// Takes an element that might have been a scroller, and turns it back into a normal element.\nfunction unsetScroller(containerEl) {\n\tcontainerEl.height('').removeClass('fc-scroller');\n}\n\n\n/* General DOM Utilities\n----------------------------------------------------------------------------------------------------------------------*/\n\nfc.getClientRect = getClientRect;\nfc.getContentRect = getContentRect;\nfc.getScrollbarWidths = getScrollbarWidths;\n\n\n// borrowed from https://github.com/jquery/jquery-ui/blob/1.11.0/ui/core.js#L51\nfunction getScrollParent(el) {\n\tvar position = el.css('position'),\n\t\tscrollParent = el.parents().filter(function() {\n\t\t\tvar parent = $(this);\n\t\t\treturn (/(auto|scroll)/).test(\n\t\t\t\tparent.css('overflow') + parent.css('overflow-y') + parent.css('overflow-x')\n\t\t\t);\n\t\t}).eq(0);\n\n\treturn position === 'fixed' || !scrollParent.length ? $(el[0].ownerDocument || document) : scrollParent;\n}\n\n\n// Queries the outer bounding area of a jQuery element.\n// Returns a rectangle with absolute coordinates: left, right (exclusive), top, bottom (exclusive).\nfunction getOuterRect(el) {\n\tvar offset = el.offset();\n\n\treturn {\n\t\tleft: offset.left,\n\t\tright: offset.left + el.outerWidth(),\n\t\ttop: offset.top,\n\t\tbottom: offset.top + el.outerHeight()\n\t};\n}\n\n\n// Queries the area within the margin/border/scrollbars of a jQuery element. Does not go within the padding.\n// Returns a rectangle with absolute coordinates: left, right (exclusive), top, bottom (exclusive).\n// NOTE: should use clientLeft/clientTop, but very unreliable cross-browser.\nfunction getClientRect(el) {\n\tvar offset = el.offset();\n\tvar scrollbarWidths = getScrollbarWidths(el);\n\tvar left = offset.left + getCssFloat(el, 'border-left-width') + scrollbarWidths.left;\n\tvar top = offset.top + getCssFloat(el, 'border-top-width') + scrollbarWidths.top;\n\n\treturn {\n\t\tleft: left,\n\t\tright: left + el[0].clientWidth, // clientWidth includes padding but NOT scrollbars\n\t\ttop: top,\n\t\tbottom: top + el[0].clientHeight // clientHeight includes padding but NOT scrollbars\n\t};\n}\n\n\n// Queries the area within the margin/border/padding of a jQuery element. Assumed not to have scrollbars.\n// Returns a rectangle with absolute coordinates: left, right (exclusive), top, bottom (exclusive).\nfunction getContentRect(el) {\n\tvar offset = el.offset(); // just outside of border, margin not included\n\tvar left = offset.left + getCssFloat(el, 'border-left-width') + getCssFloat(el, 'padding-left');\n\tvar top = offset.top + getCssFloat(el, 'border-top-width') + getCssFloat(el, 'padding-top');\n\n\treturn {\n\t\tleft: left,\n\t\tright: left + el.width(),\n\t\ttop: top,\n\t\tbottom: top + el.height()\n\t};\n}\n\n\n// Returns the computed left/right/top/bottom scrollbar widths for the given jQuery element.\n// NOTE: should use clientLeft/clientTop, but very unreliable cross-browser.\nfunction getScrollbarWidths(el) {\n\tvar leftRightWidth = el.innerWidth() - el[0].clientWidth; // the paddings cancel out, leaving the scrollbars\n\tvar widths = {\n\t\tleft: 0,\n\t\tright: 0,\n\t\ttop: 0,\n\t\tbottom: el.innerHeight() - el[0].clientHeight // the paddings cancel out, leaving the bottom scrollbar\n\t};\n\n\tif (getIsLeftRtlScrollbars() && el.css('direction') == 'rtl') { // is the scrollbar on the left side?\n\t\twidths.left = leftRightWidth;\n\t}\n\telse {\n\t\twidths.right = leftRightWidth;\n\t}\n\n\treturn widths;\n}\n\n\n// Logic for determining if, when the element is right-to-left, the scrollbar appears on the left side\n\nvar _isLeftRtlScrollbars = null;\n\nfunction getIsLeftRtlScrollbars() { // responsible for caching the computation\n\tif (_isLeftRtlScrollbars === null) {\n\t\t_isLeftRtlScrollbars = computeIsLeftRtlScrollbars();\n\t}\n\treturn _isLeftRtlScrollbars;\n}\n\nfunction computeIsLeftRtlScrollbars() { // creates an offscreen test element, then removes it\n\tvar el = $('')\n\t\t.css({\n\t\t\tposition: 'absolute',\n\t\t\ttop: -1000,\n\t\t\tleft: 0,\n\t\t\tborder: 0,\n\t\t\tpadding: 0,\n\t\t\toverflow: 'scroll',\n\t\t\tdirection: 'rtl'\n\t\t})\n\t\t.appendTo('body');\n\tvar innerEl = el.children();\n\tvar res = innerEl.offset().left > el.offset().left; // is the inner div shifted to accommodate a left scrollbar?\n\tel.remove();\n\treturn res;\n}\n\n\n// Retrieves a jQuery element's computed CSS value as a floating-point number.\n// If the queried value is non-numeric (ex: IE can return \"medium\" for border width), will just return zero.\nfunction getCssFloat(el, prop) {\n\treturn parseFloat(el.css(prop)) || 0;\n}\n\n\n// Returns a boolean whether this was a left mouse click and no ctrl key (which means right click on Mac)\nfunction isPrimaryMouseButton(ev) {\n\treturn ev.which == 1 && !ev.ctrlKey;\n}\n\n\n/* Geometry\n----------------------------------------------------------------------------------------------------------------------*/\n\n\n// Returns a new rectangle that is the intersection of the two rectangles. If they don't intersect, returns false\nfunction intersectRects(rect1, rect2) {\n\tvar res = {\n\t\tleft: Math.max(rect1.left, rect2.left),\n\t\tright: Math.min(rect1.right, rect2.right),\n\t\ttop: Math.max(rect1.top, rect2.top),\n\t\tbottom: Math.min(rect1.bottom, rect2.bottom)\n\t};\n\n\tif (res.left < res.right && res.top < res.bottom) {\n\t\treturn res;\n\t}\n\treturn false;\n}\n\n\n// Returns a new point that will have been moved to reside within the given rectangle\nfunction constrainPoint(point, rect) {\n\treturn {\n\t\tleft: Math.min(Math.max(point.left, rect.left), rect.right),\n\t\ttop: Math.min(Math.max(point.top, rect.top), rect.bottom)\n\t};\n}\n\n\n// Returns a point that is the center of the given rectangle\nfunction getRectCenter(rect) {\n\treturn {\n\t\tleft: (rect.left + rect.right) / 2,\n\t\ttop: (rect.top + rect.bottom) / 2\n\t};\n}\n\n\n// Subtracts point2's coordinates from point1's coordinates, returning a delta\nfunction diffPoints(point1, point2) {\n\treturn {\n\t\tleft: point1.left - point2.left,\n\t\ttop: point1.top - point2.top\n\t};\n}\n\n\n/* FullCalendar-specific Misc Utilities\n----------------------------------------------------------------------------------------------------------------------*/\n\n\n// Creates a basic segment with the intersection of the two ranges. Returns undefined if no intersection.\n// Expects all dates to be normalized to the same timezone beforehand.\n// TODO: move to date section?\nfunction intersectionToSeg(subjectRange, constraintRange) {\n\tvar subjectStart = subjectRange.start;\n\tvar subjectEnd = subjectRange.end;\n\tvar constraintStart = constraintRange.start;\n\tvar constraintEnd = constraintRange.end;\n\tvar segStart, segEnd;\n\tvar isStart, isEnd;\n\n\tif (subjectEnd > constraintStart && subjectStart < constraintEnd) { // in bounds at all?\n\n\t\tif (subjectStart >= constraintStart) {\n\t\t\tsegStart = subjectStart.clone();\n\t\t\tisStart = true;\n\t\t}\n\t\telse {\n\t\t\tsegStart = constraintStart.clone();\n\t\t\tisStart = false;\n\t\t}\n\n\t\tif (subjectEnd <= constraintEnd) {\n\t\t\tsegEnd = subjectEnd.clone();\n\t\t\tisEnd = true;\n\t\t}\n\t\telse {\n\t\t\tsegEnd = constraintEnd.clone();\n\t\t\tisEnd = false;\n\t\t}\n\n\t\treturn {\n\t\t\tstart: segStart,\n\t\t\tend: segEnd,\n\t\t\tisStart: isStart,\n\t\t\tisEnd: isEnd\n\t\t};\n\t}\n}\n\n\n/* Date Utilities\n----------------------------------------------------------------------------------------------------------------------*/\n\nfc.computeIntervalUnit = computeIntervalUnit;\nfc.durationHasTime = durationHasTime;\n\nvar dayIDs = [ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ];\nvar intervalUnits = [ 'year', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond' ];\n\n\n// Diffs the two moments into a Duration where full-days are recorded first, then the remaining time.\n// Moments will have their timezones normalized.\nfunction diffDayTime(a, b) {\n\treturn moment.duration({\n\t\tdays: a.clone().stripTime().diff(b.clone().stripTime(), 'days'),\n\t\tms: a.time() - b.time() // time-of-day from day start. disregards timezone\n\t});\n}\n\n\n// Diffs the two moments via their start-of-day (regardless of timezone). Produces whole-day durations.\nfunction diffDay(a, b) {\n\treturn moment.duration({\n\t\tdays: a.clone().stripTime().diff(b.clone().stripTime(), 'days')\n\t});\n}\n\n\n// Diffs two moments, producing a duration, made of a whole-unit-increment of the given unit. Uses rounding.\nfunction diffByUnit(a, b, unit) {\n\treturn moment.duration(\n\t\tMath.round(a.diff(b, unit, true)), // returnFloat=true\n\t\tunit\n\t);\n}\n\n\n// Computes the unit name of the largest whole-unit period of time.\n// For example, 48 hours will be \"days\" whereas 49 hours will be \"hours\".\n// Accepts start/end, a range object, or an original duration object.\nfunction computeIntervalUnit(start, end) {\n\tvar i, unit;\n\tvar val;\n\n\tfor (i = 0; i < intervalUnits.length; i++) {\n\t\tunit = intervalUnits[i];\n\t\tval = computeRangeAs(unit, start, end);\n\n\t\tif (val >= 1 && isInt(val)) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn unit; // will be \"milliseconds\" if nothing else matches\n}\n\n\n// Computes the number of units (like \"hours\") in the given range.\n// Range can be a {start,end} object, separate start/end args, or a Duration.\n// Results are based on Moment's .as() and .diff() methods, so results can depend on internal handling\n// of month-diffing logic (which tends to vary from version to version).\nfunction computeRangeAs(unit, start, end) {\n\n\tif (end != null) { // given start, end\n\t\treturn end.diff(start, unit, true);\n\t}\n\telse if (moment.isDuration(start)) { // given duration\n\t\treturn start.as(unit);\n\t}\n\telse { // given { start, end } range object\n\t\treturn start.end.diff(start.start, unit, true);\n\t}\n}\n\n\n// Returns a boolean about whether the given duration has any time parts (hours/minutes/seconds/ms)\nfunction durationHasTime(dur) {\n\treturn Boolean(dur.hours() || dur.minutes() || dur.seconds() || dur.milliseconds());\n}\n\n\nfunction isNativeDate(input) {\n\treturn Object.prototype.toString.call(input) === '[object Date]' || input instanceof Date;\n}\n\n\n// Returns a boolean about whether the given input is a time string, like \"06:40:00\" or \"06:00\"\nfunction isTimeString(str) {\n\treturn /^\\d+\\:\\d+(?:\\:\\d+\\.?(?:\\d{3})?)?$/.test(str);\n}\n\n\n/* General Utilities\n----------------------------------------------------------------------------------------------------------------------*/\n\nvar hasOwnPropMethod = {}.hasOwnProperty;\n\n\n// Create an object that has the given prototype. Just like Object.create\nfunction createObject(proto) {\n\tvar f = function() {};\n\tf.prototype = proto;\n\treturn new f();\n}\n\n\nfunction copyOwnProps(src, dest) {\n\tfor (var name in src) {\n\t\tif (hasOwnProp(src, name)) {\n\t\t\tdest[name] = src[name];\n\t\t}\n\t}\n}\n\n\n// Copies over certain methods with the same names as Object.prototype methods. Overcomes an IE<=8 bug:\n// https://developer.mozilla.org/en-US/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug\nfunction copyNativeMethods(src, dest) {\n\tvar names = [ 'constructor', 'toString', 'valueOf' ];\n\tvar i, name;\n\n\tfor (i = 0; i < names.length; i++) {\n\t\tname = names[i];\n\n\t\tif (src[name] !== Object.prototype[name]) {\n\t\t\tdest[name] = src[name];\n\t\t}\n\t}\n}\n\n\nfunction hasOwnProp(obj, name) {\n\treturn hasOwnPropMethod.call(obj, name);\n}\n\n\n// Is the given value a non-object non-function value?\nfunction isAtomic(val) {\n\treturn /undefined|null|boolean|number|string/.test($.type(val));\n}\n\n\nfunction applyAll(functions, thisObj, args) {\n\tif ($.isFunction(functions)) {\n\t\tfunctions = [ functions ];\n\t}\n\tif (functions) {\n\t\tvar i;\n\t\tvar ret;\n\t\tfor (i=0; i/g, '>')\n\t\t.replace(/'/g, ''')\n\t\t.replace(/\"/g, '"')\n\t\t.replace(/\\n/g, ' ');\n}\n\n\nfunction stripHtmlEntities(text) {\n\treturn text.replace(/&.*?;/g, '');\n}\n\n\n// Given a hash of CSS properties, returns a string of CSS.\n// Uses property names as-is (no camel-case conversion). Will not make statements for null/undefined values.\nfunction cssToStr(cssProps) {\n\tvar statements = [];\n\n\t$.each(cssProps, function(name, val) {\n\t\tif (val != null) {\n\t\t\tstatements.push(name + ':' + val);\n\t\t}\n\t});\n\n\treturn statements.join(';');\n}\n\n\nfunction capitaliseFirstLetter(str) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1);\n}\n\n\nfunction compareNumbers(a, b) { // for .sort()\n\treturn a - b;\n}\n\n\nfunction isInt(n) {\n\treturn n % 1 === 0;\n}\n\n\n// Returns a method bound to the given object context.\n// Just like one of the jQuery.proxy signatures, but without the undesired behavior of treating the same method with\n// different contexts as identical when binding/unbinding events.\nfunction proxy(obj, methodName) {\n\tvar method = obj[methodName];\n\n\treturn function() {\n\t\treturn method.apply(obj, arguments);\n\t};\n}\n\n\n// Returns a function, that, as long as it continues to be invoked, will not\n// be triggered. The function will be called after it stops being called for\n// N milliseconds.\n// https://github.com/jashkenas/underscore/blob/1.6.0/underscore.js#L714\nfunction debounce(func, wait) {\n\tvar timeoutId;\n\tvar args;\n\tvar context;\n\tvar timestamp; // of most recent call\n\tvar later = function() {\n\t\tvar last = +new Date() - timestamp;\n\t\tif (last < wait && last > 0) {\n\t\t\ttimeoutId = setTimeout(later, wait - last);\n\t\t}\n\t\telse {\n\t\t\ttimeoutId = null;\n\t\t\tfunc.apply(context, args);\n\t\t\tif (!timeoutId) {\n\t\t\t\tcontext = args = null;\n\t\t\t}\n\t\t}\n\t};\n\n\treturn function() {\n\t\tcontext = this;\n\t\targs = arguments;\n\t\ttimestamp = +new Date();\n\t\tif (!timeoutId) {\n\t\t\ttimeoutId = setTimeout(later, wait);\n\t\t}\n\t};\n}\n\n;;\n\nvar ambigDateOfMonthRegex = /^\\s*\\d{4}-\\d\\d$/;\nvar ambigTimeOrZoneRegex =\n\t/^\\s*\\d{4}-(?:(\\d\\d-\\d\\d)|(W\\d\\d$)|(W\\d\\d-\\d)|(\\d\\d\\d))((T| )(\\d\\d(:\\d\\d(:\\d\\d(\\.\\d+)?)?)?)?)?$/;\nvar newMomentProto = moment.fn; // where we will attach our new methods\nvar oldMomentProto = $.extend({}, newMomentProto); // copy of original moment methods\nvar allowValueOptimization;\nvar setUTCValues; // function defined below\nvar setLocalValues; // function defined below\n\n\n// Creating\n// -------------------------------------------------------------------------------------------------\n\n// Creates a new moment, similar to the vanilla moment(...) constructor, but with\n// extra features (ambiguous time, enhanced formatting). When given an existing moment,\n// it will function as a clone (and retain the zone of the moment). Anything else will\n// result in a moment in the local zone.\nfc.moment = function() {\n\treturn makeMoment(arguments);\n};\n\n// Sames as fc.moment, but forces the resulting moment to be in the UTC timezone.\nfc.moment.utc = function() {\n\tvar mom = makeMoment(arguments, true);\n\n\t// Force it into UTC because makeMoment doesn't guarantee it\n\t// (if given a pre-existing moment for example)\n\tif (mom.hasTime()) { // don't give ambiguously-timed moments a UTC zone\n\t\tmom.utc();\n\t}\n\n\treturn mom;\n};\n\n// Same as fc.moment, but when given an ISO8601 string, the timezone offset is preserved.\n// ISO8601 strings with no timezone offset will become ambiguously zoned.\nfc.moment.parseZone = function() {\n\treturn makeMoment(arguments, true, true);\n};\n\n// Builds an enhanced moment from args. When given an existing moment, it clones. When given a\n// native Date, or called with no arguments (the current time), the resulting moment will be local.\n// Anything else needs to be \"parsed\" (a string or an array), and will be affected by:\n// parseAsUTC - if there is no zone information, should we parse the input in UTC?\n// parseZone - if there is zone information, should we force the zone of the moment?\nfunction makeMoment(args, parseAsUTC, parseZone) {\n\tvar input = args[0];\n\tvar isSingleString = args.length == 1 && typeof input === 'string';\n\tvar isAmbigTime;\n\tvar isAmbigZone;\n\tvar ambigMatch;\n\tvar mom;\n\n\tif (moment.isMoment(input)) {\n\t\tmom = moment.apply(null, args); // clone it\n\t\ttransferAmbigs(input, mom); // the ambig flags weren't transfered with the clone\n\t}\n\telse if (isNativeDate(input) || input === undefined) {\n\t\tmom = moment.apply(null, args); // will be local\n\t}\n\telse { // \"parsing\" is required\n\t\tisAmbigTime = false;\n\t\tisAmbigZone = false;\n\n\t\tif (isSingleString) {\n\t\t\tif (ambigDateOfMonthRegex.test(input)) {\n\t\t\t\t// accept strings like '2014-05', but convert to the first of the month\n\t\t\t\tinput += '-01';\n\t\t\t\targs = [ input ]; // for when we pass it on to moment's constructor\n\t\t\t\tisAmbigTime = true;\n\t\t\t\tisAmbigZone = true;\n\t\t\t}\n\t\t\telse if ((ambigMatch = ambigTimeOrZoneRegex.exec(input))) {\n\t\t\t\tisAmbigTime = !ambigMatch[5]; // no time part?\n\t\t\t\tisAmbigZone = true;\n\t\t\t}\n\t\t}\n\t\telse if ($.isArray(input)) {\n\t\t\t// arrays have no timezone information, so assume ambiguous zone\n\t\t\tisAmbigZone = true;\n\t\t}\n\t\t// otherwise, probably a string with a format\n\n\t\tif (parseAsUTC || isAmbigTime) {\n\t\t\tmom = moment.utc.apply(moment, args);\n\t\t}\n\t\telse {\n\t\t\tmom = moment.apply(null, args);\n\t\t}\n\n\t\tif (isAmbigTime) {\n\t\t\tmom._ambigTime = true;\n\t\t\tmom._ambigZone = true; // ambiguous time always means ambiguous zone\n\t\t}\n\t\telse if (parseZone) { // let's record the inputted zone somehow\n\t\t\tif (isAmbigZone) {\n\t\t\t\tmom._ambigZone = true;\n\t\t\t}\n\t\t\telse if (isSingleString) {\n\t\t\t\tif (mom.utcOffset) {\n\t\t\t\t\tmom.utcOffset(input); // if not a valid zone, will assign UTC\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tmom.zone(input); // for moment-pre-2.9\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tmom._fullCalendar = true; // flag for extended functionality\n\n\treturn mom;\n}\n\n\n// A clone method that works with the flags related to our enhanced functionality.\n// In the future, use moment.momentProperties\nnewMomentProto.clone = function() {\n\tvar mom = oldMomentProto.clone.apply(this, arguments);\n\n\t// these flags weren't transfered with the clone\n\ttransferAmbigs(this, mom);\n\tif (this._fullCalendar) {\n\t\tmom._fullCalendar = true;\n\t}\n\n\treturn mom;\n};\n\n\n// Week Number\n// -------------------------------------------------------------------------------------------------\n\n\n// Returns the week number, considering the locale's custom week number calcuation\n// `weeks` is an alias for `week`\nnewMomentProto.week = newMomentProto.weeks = function(input) {\n\tvar weekCalc = (this._locale || this._lang) // works pre-moment-2.8\n\t\t._fullCalendar_weekCalc;\n\n\tif (input == null && typeof weekCalc === 'function') { // custom function only works for getter\n\t\treturn weekCalc(this);\n\t}\n\telse if (weekCalc === 'ISO') {\n\t\treturn oldMomentProto.isoWeek.apply(this, arguments); // ISO getter/setter\n\t}\n\n\treturn oldMomentProto.week.apply(this, arguments); // local getter/setter\n};\n\n\n// Time-of-day\n// -------------------------------------------------------------------------------------------------\n\n// GETTER\n// Returns a Duration with the hours/minutes/seconds/ms values of the moment.\n// If the moment has an ambiguous time, a duration of 00:00 will be returned.\n//\n// SETTER\n// You can supply a Duration, a Moment, or a Duration-like argument.\n// When setting the time, and the moment has an ambiguous time, it then becomes unambiguous.\nnewMomentProto.time = function(time) {\n\n\t// Fallback to the original method (if there is one) if this moment wasn't created via FullCalendar.\n\t// `time` is a generic enough method name where this precaution is necessary to avoid collisions w/ other plugins.\n\tif (!this._fullCalendar) {\n\t\treturn oldMomentProto.time.apply(this, arguments);\n\t}\n\n\tif (time == null) { // getter\n\t\treturn moment.duration({\n\t\t\thours: this.hours(),\n\t\t\tminutes: this.minutes(),\n\t\t\tseconds: this.seconds(),\n\t\t\tmilliseconds: this.milliseconds()\n\t\t});\n\t}\n\telse { // setter\n\n\t\tthis._ambigTime = false; // mark that the moment now has a time\n\n\t\tif (!moment.isDuration(time) && !moment.isMoment(time)) {\n\t\t\ttime = moment.duration(time);\n\t\t}\n\n\t\t// The day value should cause overflow (so 24 hours becomes 00:00:00 of next day).\n\t\t// Only for Duration times, not Moment times.\n\t\tvar dayHours = 0;\n\t\tif (moment.isDuration(time)) {\n\t\t\tdayHours = Math.floor(time.asDays()) * 24;\n\t\t}\n\n\t\t// We need to set the individual fields.\n\t\t// Can't use startOf('day') then add duration. In case of DST at start of day.\n\t\treturn this.hours(dayHours + time.hours())\n\t\t\t.minutes(time.minutes())\n\t\t\t.seconds(time.seconds())\n\t\t\t.milliseconds(time.milliseconds());\n\t}\n};\n\n// Converts the moment to UTC, stripping out its time-of-day and timezone offset,\n// but preserving its YMD. A moment with a stripped time will display no time\n// nor timezone offset when .format() is called.\nnewMomentProto.stripTime = function() {\n\tvar a;\n\n\tif (!this._ambigTime) {\n\n\t\t// get the values before any conversion happens\n\t\ta = this.toArray(); // array of y/m/d/h/m/s/ms\n\n\t\t// TODO: use keepLocalTime in the future\n\t\tthis.utc(); // set the internal UTC flag (will clear the ambig flags)\n\t\tsetUTCValues(this, a.slice(0, 3)); // set the year/month/date. time will be zero\n\n\t\t// Mark the time as ambiguous. This needs to happen after the .utc() call, which might call .utcOffset(),\n\t\t// which clears all ambig flags. Same with setUTCValues with moment-timezone.\n\t\tthis._ambigTime = true;\n\t\tthis._ambigZone = true; // if ambiguous time, also ambiguous timezone offset\n\t}\n\n\treturn this; // for chaining\n};\n\n// Returns if the moment has a non-ambiguous time (boolean)\nnewMomentProto.hasTime = function() {\n\treturn !this._ambigTime;\n};\n\n\n// Timezone\n// -------------------------------------------------------------------------------------------------\n\n// Converts the moment to UTC, stripping out its timezone offset, but preserving its\n// YMD and time-of-day. A moment with a stripped timezone offset will display no\n// timezone offset when .format() is called.\n// TODO: look into Moment's keepLocalTime functionality\nnewMomentProto.stripZone = function() {\n\tvar a, wasAmbigTime;\n\n\tif (!this._ambigZone) {\n\n\t\t// get the values before any conversion happens\n\t\ta = this.toArray(); // array of y/m/d/h/m/s/ms\n\t\twasAmbigTime = this._ambigTime;\n\n\t\tthis.utc(); // set the internal UTC flag (might clear the ambig flags, depending on Moment internals)\n\t\tsetUTCValues(this, a); // will set the year/month/date/hours/minutes/seconds/ms\n\n\t\t// the above call to .utc()/.utcOffset() unfortunately might clear the ambig flags, so restore\n\t\tthis._ambigTime = wasAmbigTime || false;\n\n\t\t// Mark the zone as ambiguous. This needs to happen after the .utc() call, which might call .utcOffset(),\n\t\t// which clears the ambig flags. Same with setUTCValues with moment-timezone.\n\t\tthis._ambigZone = true;\n\t}\n\n\treturn this; // for chaining\n};\n\n// Returns of the moment has a non-ambiguous timezone offset (boolean)\nnewMomentProto.hasZone = function() {\n\treturn !this._ambigZone;\n};\n\n\n// this method implicitly marks a zone\nnewMomentProto.local = function() {\n\tvar a = this.toArray(); // year,month,date,hours,minutes,seconds,ms as an array\n\tvar wasAmbigZone = this._ambigZone;\n\n\toldMomentProto.local.apply(this, arguments);\n\n\t// ensure non-ambiguous\n\t// this probably already happened via local() -> utcOffset(), but don't rely on Moment's internals\n\tthis._ambigTime = false;\n\tthis._ambigZone = false;\n\n\tif (wasAmbigZone) {\n\t\t// If the moment was ambiguously zoned, the date fields were stored as UTC.\n\t\t// We want to preserve these, but in local time.\n\t\t// TODO: look into Moment's keepLocalTime functionality\n\t\tsetLocalValues(this, a);\n\t}\n\n\treturn this; // for chaining\n};\n\n\n// implicitly marks a zone\nnewMomentProto.utc = function() {\n\toldMomentProto.utc.apply(this, arguments);\n\n\t// ensure non-ambiguous\n\t// this probably already happened via utc() -> utcOffset(), but don't rely on Moment's internals\n\tthis._ambigTime = false;\n\tthis._ambigZone = false;\n\n\treturn this;\n};\n\n\n// methods for arbitrarily manipulating timezone offset.\n// should clear time/zone ambiguity when called.\n$.each([\n\t'zone', // only in moment-pre-2.9. deprecated afterwards\n\t'utcOffset'\n], function(i, name) {\n\tif (oldMomentProto[name]) { // original method exists?\n\n\t\t// this method implicitly marks a zone (will probably get called upon .utc() and .local())\n\t\tnewMomentProto[name] = function(tzo) {\n\n\t\t\tif (tzo != null) { // setter\n\t\t\t\t// these assignments needs to happen before the original zone method is called.\n\t\t\t\t// I forget why, something to do with a browser crash.\n\t\t\t\tthis._ambigTime = false;\n\t\t\t\tthis._ambigZone = false;\n\t\t\t}\n\n\t\t\treturn oldMomentProto[name].apply(this, arguments);\n\t\t};\n\t}\n});\n\n\n// Formatting\n// -------------------------------------------------------------------------------------------------\n\nnewMomentProto.format = function() {\n\tif (this._fullCalendar && arguments[0]) { // an enhanced moment? and a format string provided?\n\t\treturn formatDate(this, arguments[0]); // our extended formatting\n\t}\n\tif (this._ambigTime) {\n\t\treturn oldMomentFormat(this, 'YYYY-MM-DD');\n\t}\n\tif (this._ambigZone) {\n\t\treturn oldMomentFormat(this, 'YYYY-MM-DD[T]HH:mm:ss');\n\t}\n\treturn oldMomentProto.format.apply(this, arguments);\n};\n\nnewMomentProto.toISOString = function() {\n\tif (this._ambigTime) {\n\t\treturn oldMomentFormat(this, 'YYYY-MM-DD');\n\t}\n\tif (this._ambigZone) {\n\t\treturn oldMomentFormat(this, 'YYYY-MM-DD[T]HH:mm:ss');\n\t}\n\treturn oldMomentProto.toISOString.apply(this, arguments);\n};\n\n\n// Querying\n// -------------------------------------------------------------------------------------------------\n\n// Is the moment within the specified range? `end` is exclusive.\n// FYI, this method is not a standard Moment method, so always do our enhanced logic.\nnewMomentProto.isWithin = function(start, end) {\n\tvar a = commonlyAmbiguate([ this, start, end ]);\n\treturn a[0] >= a[1] && a[0] < a[2];\n};\n\n// When isSame is called with units, timezone ambiguity is normalized before the comparison happens.\n// If no units specified, the two moments must be identically the same, with matching ambig flags.\nnewMomentProto.isSame = function(input, units) {\n\tvar a;\n\n\t// only do custom logic if this is an enhanced moment\n\tif (!this._fullCalendar) {\n\t\treturn oldMomentProto.isSame.apply(this, arguments);\n\t}\n\n\tif (units) {\n\t\ta = commonlyAmbiguate([ this, input ], true); // normalize timezones but don't erase times\n\t\treturn oldMomentProto.isSame.call(a[0], a[1], units);\n\t}\n\telse {\n\t\tinput = fc.moment.parseZone(input); // normalize input\n\t\treturn oldMomentProto.isSame.call(this, input) &&\n\t\t\tBoolean(this._ambigTime) === Boolean(input._ambigTime) &&\n\t\t\tBoolean(this._ambigZone) === Boolean(input._ambigZone);\n\t}\n};\n\n// Make these query methods work with ambiguous moments\n$.each([\n\t'isBefore',\n\t'isAfter'\n], function(i, methodName) {\n\tnewMomentProto[methodName] = function(input, units) {\n\t\tvar a;\n\n\t\t// only do custom logic if this is an enhanced moment\n\t\tif (!this._fullCalendar) {\n\t\t\treturn oldMomentProto[methodName].apply(this, arguments);\n\t\t}\n\n\t\ta = commonlyAmbiguate([ this, input ]);\n\t\treturn oldMomentProto[methodName].call(a[0], a[1], units);\n\t};\n});\n\n\n// Misc Internals\n// -------------------------------------------------------------------------------------------------\n\n// given an array of moment-like inputs, return a parallel array w/ moments similarly ambiguated.\n// for example, of one moment has ambig time, but not others, all moments will have their time stripped.\n// set `preserveTime` to `true` to keep times, but only normalize zone ambiguity.\n// returns the original moments if no modifications are necessary.\nfunction commonlyAmbiguate(inputs, preserveTime) {\n\tvar anyAmbigTime = false;\n\tvar anyAmbigZone = false;\n\tvar len = inputs.length;\n\tvar moms = [];\n\tvar i, mom;\n\n\t// parse inputs into real moments and query their ambig flags\n\tfor (i = 0; i < len; i++) {\n\t\tmom = inputs[i];\n\t\tif (!moment.isMoment(mom)) {\n\t\t\tmom = fc.moment.parseZone(mom);\n\t\t}\n\t\tanyAmbigTime = anyAmbigTime || mom._ambigTime;\n\t\tanyAmbigZone = anyAmbigZone || mom._ambigZone;\n\t\tmoms.push(mom);\n\t}\n\n\t// strip each moment down to lowest common ambiguity\n\t// use clones to avoid modifying the original moments\n\tfor (i = 0; i < len; i++) {\n\t\tmom = moms[i];\n\t\tif (!preserveTime && anyAmbigTime && !mom._ambigTime) {\n\t\t\tmoms[i] = mom.clone().stripTime();\n\t\t}\n\t\telse if (anyAmbigZone && !mom._ambigZone) {\n\t\t\tmoms[i] = mom.clone().stripZone();\n\t\t}\n\t}\n\n\treturn moms;\n}\n\n// Transfers all the flags related to ambiguous time/zone from the `src` moment to the `dest` moment\n// TODO: look into moment.momentProperties for this.\nfunction transferAmbigs(src, dest) {\n\tif (src._ambigTime) {\n\t\tdest._ambigTime = true;\n\t}\n\telse if (dest._ambigTime) {\n\t\tdest._ambigTime = false;\n\t}\n\n\tif (src._ambigZone) {\n\t\tdest._ambigZone = true;\n\t}\n\telse if (dest._ambigZone) {\n\t\tdest._ambigZone = false;\n\t}\n}\n\n\n// Sets the year/month/date/etc values of the moment from the given array.\n// Inefficient because it calls each individual setter.\nfunction setMomentValues(mom, a) {\n\tmom.year(a[0] || 0)\n\t\t.month(a[1] || 0)\n\t\t.date(a[2] || 0)\n\t\t.hours(a[3] || 0)\n\t\t.minutes(a[4] || 0)\n\t\t.seconds(a[5] || 0)\n\t\t.milliseconds(a[6] || 0);\n}\n\n// Can we set the moment's internal date directly?\nallowValueOptimization = '_d' in moment() && 'updateOffset' in moment;\n\n// Utility function. Accepts a moment and an array of the UTC year/month/date/etc values to set.\n// Assumes the given moment is already in UTC mode.\nsetUTCValues = allowValueOptimization ? function(mom, a) {\n\t// simlate what moment's accessors do\n\tmom._d.setTime(Date.UTC.apply(Date, a));\n\tmoment.updateOffset(mom, false); // keepTime=false\n} : setMomentValues;\n\n// Utility function. Accepts a moment and an array of the local year/month/date/etc values to set.\n// Assumes the given moment is already in local mode.\nsetLocalValues = allowValueOptimization ? function(mom, a) {\n\t// simlate what moment's accessors do\n\tmom._d.setTime(+new Date( // FYI, there is now way to apply an array of args to a constructor\n\t\ta[0] || 0,\n\t\ta[1] || 0,\n\t\ta[2] || 0,\n\t\ta[3] || 0,\n\t\ta[4] || 0,\n\t\ta[5] || 0,\n\t\ta[6] || 0\n\t));\n\tmoment.updateOffset(mom, false); // keepTime=false\n} : setMomentValues;\n\n;;\n\n// Single Date Formatting\n// -------------------------------------------------------------------------------------------------\n\n\n// call this if you want Moment's original format method to be used\nfunction oldMomentFormat(mom, formatStr) {\n\treturn oldMomentProto.format.call(mom, formatStr); // oldMomentProto defined in moment-ext.js\n}\n\n\n// Formats `date` with a Moment formatting string, but allow our non-zero areas and\n// additional token.\nfunction formatDate(date, formatStr) {\n\treturn formatDateWithChunks(date, getFormatStringChunks(formatStr));\n}\n\n\nfunction formatDateWithChunks(date, chunks) {\n\tvar s = '';\n\tvar i;\n\n\tfor (i=0; i \"MMMM D YYYY\"\n\tformatStr = localeData.longDateFormat(formatStr) || formatStr;\n\t// BTW, this is not important for `formatDate` because it is impossible to put custom tokens\n\t// or non-zero areas in Moment's localized format strings.\n\n\tseparator = separator || ' - ';\n\n\treturn formatRangeWithChunks(\n\t\tdate1,\n\t\tdate2,\n\t\tgetFormatStringChunks(formatStr),\n\t\tseparator,\n\t\tisRTL\n\t);\n}\nfc.formatRange = formatRange; // expose\n\n\nfunction formatRangeWithChunks(date1, date2, chunks, separator, isRTL) {\n\tvar chunkStr; // the rendering of the chunk\n\tvar leftI;\n\tvar leftStr = '';\n\tvar rightI;\n\tvar rightStr = '';\n\tvar middleI;\n\tvar middleStr1 = '';\n\tvar middleStr2 = '';\n\tvar middleStr = '';\n\n\t// Start at the leftmost side of the formatting string and continue until you hit a token\n\t// that is not the same between dates.\n\tfor (leftI=0; leftIleftI; rightI--) {\n\t\tchunkStr = formatSimilarChunk(date1, date2, chunks[rightI]);\n\t\tif (chunkStr === false) {\n\t\t\tbreak;\n\t\t}\n\t\trightStr = chunkStr + rightStr;\n\t}\n\n\t// The area in the middle is different for both of the dates.\n\t// Collect them distinctly so we can jam them together later.\n\tfor (middleI=leftI; middleI<=rightI; middleI++) {\n\t\tmiddleStr1 += formatDateWithChunk(date1, chunks[middleI]);\n\t\tmiddleStr2 += formatDateWithChunk(date2, chunks[middleI]);\n\t}\n\n\tif (middleStr1 || middleStr2) {\n\t\tif (isRTL) {\n\t\t\tmiddleStr = middleStr2 + separator + middleStr1;\n\t\t}\n\t\telse {\n\t\t\tmiddleStr = middleStr1 + separator + middleStr2;\n\t\t}\n\t}\n\n\treturn leftStr + middleStr + rightStr;\n}\n\n\nvar similarUnitMap = {\n\tY: 'year',\n\tM: 'month',\n\tD: 'day', // day of month\n\td: 'day', // day of week\n\t// prevents a separator between anything time-related...\n\tA: 'second', // AM/PM\n\ta: 'second', // am/pm\n\tT: 'second', // A/P\n\tt: 'second', // a/p\n\tH: 'second', // hour (24)\n\th: 'second', // hour (12)\n\tm: 'second', // minute\n\ts: 'second' // second\n};\n// TODO: week maybe?\n\n\n// Given a formatting chunk, and given that both dates are similar in the regard the\n// formatting chunk is concerned, format date1 against `chunk`. Otherwise, return `false`.\nfunction formatSimilarChunk(date1, date2, chunk) {\n\tvar token;\n\tvar unit;\n\n\tif (typeof chunk === 'string') { // a literal string\n\t\treturn chunk;\n\t}\n\telse if ((token = chunk.token)) {\n\t\tunit = similarUnitMap[token.charAt(0)];\n\t\t// are the dates the same for this unit of measurement?\n\t\tif (unit && date1.isSame(date2, unit)) {\n\t\t\treturn oldMomentFormat(date1, token); // would be the same if we used `date2`\n\t\t\t// BTW, don't support custom tokens\n\t\t}\n\t}\n\n\treturn false; // the chunk is NOT the same for the two dates\n\t// BTW, don't support splitting on non-zero areas\n}\n\n\n// Chunking Utils\n// -------------------------------------------------------------------------------------------------\n\n\nvar formatStringChunkCache = {};\n\n\nfunction getFormatStringChunks(formatStr) {\n\tif (formatStr in formatStringChunkCache) {\n\t\treturn formatStringChunkCache[formatStr];\n\t}\n\treturn (formatStringChunkCache[formatStr] = chunkFormatString(formatStr));\n}\n\n\n// Break the formatting string into an array of chunks\nfunction chunkFormatString(formatStr) {\n\tvar chunks = [];\n\tvar chunker = /\\[([^\\]]*)\\]|\\(([^\\)]*)\\)|(LTS|LT|(\\w)\\4*o?)|([^\\w\\[\\(]+)/g; // TODO: more descrimination\n\tvar match;\n\n\twhile ((match = chunker.exec(formatStr))) {\n\t\tif (match[1]) { // a literal string inside [ ... ]\n\t\t\tchunks.push(match[1]);\n\t\t}\n\t\telse if (match[2]) { // non-zero formatting inside ( ... )\n\t\t\tchunks.push({ maybe: chunkFormatString(match[2]) });\n\t\t}\n\t\telse if (match[3]) { // a formatting token\n\t\t\tchunks.push({ token: match[3] });\n\t\t}\n\t\telse if (match[5]) { // an unenclosed literal string\n\t\t\tchunks.push(match[5]);\n\t\t}\n\t}\n\n\treturn chunks;\n}\n\n;;\n\nfc.Class = Class; // export\n\n// class that all other classes will inherit from\nfunction Class() { }\n\n// called upon a class to create a subclass\nClass.extend = function(members) {\n\tvar superClass = this;\n\tvar subClass;\n\n\tmembers = members || {};\n\n\t// ensure a constructor for the subclass, forwarding all arguments to the super-constructor if it doesn't exist\n\tif (hasOwnProp(members, 'constructor')) {\n\t\tsubClass = members.constructor;\n\t}\n\tif (typeof subClass !== 'function') {\n\t\tsubClass = members.constructor = function() {\n\t\t\tsuperClass.apply(this, arguments);\n\t\t};\n\t}\n\n\t// build the base prototype for the subclass, which is an new object chained to the superclass's prototype\n\tsubClass.prototype = createObject(superClass.prototype);\n\n\t// copy each member variable/method onto the the subclass's prototype\n\tcopyOwnProps(members, subClass.prototype);\n\tcopyNativeMethods(members, subClass.prototype); // hack for IE8\n\n\t// copy over all class variables/methods to the subclass, such as `extend` and `mixin`\n\tcopyOwnProps(superClass, subClass);\n\n\treturn subClass;\n};\n\n// adds new member variables/methods to the class's prototype.\n// can be called with another class, or a plain object hash containing new members.\nClass.mixin = function(members) {\n\tcopyOwnProps(members.prototype || members, this.prototype);\n};\n;;\n\n/* A rectangular panel that is absolutely positioned over other content\n------------------------------------------------------------------------------------------------------------------------\nOptions:\n\t- className (string)\n\t- content (HTML string or jQuery element set)\n\t- parentEl\n\t- top\n\t- left\n\t- right (the x coord of where the right edge should be. not a \"CSS\" right)\n\t- autoHide (boolean)\n\t- show (callback)\n\t- hide (callback)\n*/\n\nvar Popover = Class.extend({\n\n\tisHidden: true,\n\toptions: null,\n\tel: null, // the container element for the popover. generated by this object\n\tdocumentMousedownProxy: null, // document mousedown handler bound to `this`\n\tmargin: 10, // the space required between the popover and the edges of the scroll container\n\n\n\tconstructor: function(options) {\n\t\tthis.options = options || {};\n\t},\n\n\n\t// Shows the popover on the specified position. Renders it if not already\n\tshow: function() {\n\t\tif (this.isHidden) {\n\t\t\tif (!this.el) {\n\t\t\t\tthis.render();\n\t\t\t}\n\t\t\tthis.el.show();\n\t\t\tthis.position();\n\t\t\tthis.isHidden = false;\n\t\t\tthis.trigger('show');\n\t\t}\n\t},\n\n\n\t// Hides the popover, through CSS, but does not remove it from the DOM\n\thide: function() {\n\t\tif (!this.isHidden) {\n\t\t\tthis.el.hide();\n\t\t\tthis.isHidden = true;\n\t\t\tthis.trigger('hide');\n\t\t}\n\t},\n\n\n\t// Creates `this.el` and renders content inside of it\n\trender: function() {\n\t\tvar _this = this;\n\t\tvar options = this.options;\n\n\t\tthis.el = $('')\n\t\t\t.addClass(options.className || '')\n\t\t\t.css({\n\t\t\t\t// position initially to the top left to avoid creating scrollbars\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0\n\t\t\t})\n\t\t\t.append(options.content)\n\t\t\t.appendTo(options.parentEl);\n\n\t\t// when a click happens on anything inside with a 'fc-close' className, hide the popover\n\t\tthis.el.on('click', '.fc-close', function() {\n\t\t\t_this.hide();\n\t\t});\n\n\t\tif (options.autoHide) {\n\t\t\t$(document).on('mousedown', this.documentMousedownProxy = proxy(this, 'documentMousedown'));\n\t\t}\n\t},\n\n\n\t// Triggered when the user clicks *anywhere* in the document, for the autoHide feature\n\tdocumentMousedown: function(ev) {\n\t\t// only hide the popover if the click happened outside the popover\n\t\tif (this.el && !$(ev.target).closest(this.el).length) {\n\t\t\tthis.hide();\n\t\t}\n\t},\n\n\n\t// Hides and unregisters any handlers\n\tdestroy: function() {\n\t\tthis.hide();\n\n\t\tif (this.el) {\n\t\t\tthis.el.remove();\n\t\t\tthis.el = null;\n\t\t}\n\n\t\t$(document).off('mousedown', this.documentMousedownProxy);\n\t},\n\n\n\t// Positions the popover optimally, using the top/left/right options\n\tposition: function() {\n\t\tvar options = this.options;\n\t\tvar origin = this.el.offsetParent().offset();\n\t\tvar width = this.el.outerWidth();\n\t\tvar height = this.el.outerHeight();\n\t\tvar windowEl = $(window);\n\t\tvar viewportEl = getScrollParent(this.el);\n\t\tvar viewportTop;\n\t\tvar viewportLeft;\n\t\tvar viewportOffset;\n\t\tvar top; // the \"position\" (not \"offset\") values for the popover\n\t\tvar left; //\n\n\t\t// compute top and left\n\t\ttop = options.top || 0;\n\t\tif (options.left !== undefined) {\n\t\t\tleft = options.left;\n\t\t}\n\t\telse if (options.right !== undefined) {\n\t\t\tleft = options.right - width; // derive the left value from the right value\n\t\t}\n\t\telse {\n\t\t\tleft = 0;\n\t\t}\n\n\t\tif (viewportEl.is(window) || viewportEl.is(document)) { // normalize getScrollParent's result\n\t\t\tviewportEl = windowEl;\n\t\t\tviewportTop = 0; // the window is always at the top left\n\t\t\tviewportLeft = 0; // (and .offset() won't work if called here)\n\t\t}\n\t\telse {\n\t\t\tviewportOffset = viewportEl.offset();\n\t\t\tviewportTop = viewportOffset.top;\n\t\t\tviewportLeft = viewportOffset.left;\n\t\t}\n\n\t\t// if the window is scrolled, it causes the visible area to be further down\n\t\tviewportTop += windowEl.scrollTop();\n\t\tviewportLeft += windowEl.scrollLeft();\n\n\t\t// constrain to the view port. if constrained by two edges, give precedence to top/left\n\t\tif (options.viewportConstrain !== false) {\n\t\t\ttop = Math.min(top, viewportTop + viewportEl.outerHeight() - height - this.margin);\n\t\t\ttop = Math.max(top, viewportTop + this.margin);\n\t\t\tleft = Math.min(left, viewportLeft + viewportEl.outerWidth() - width - this.margin);\n\t\t\tleft = Math.max(left, viewportLeft + this.margin);\n\t\t}\n\n\t\tthis.el.css({\n\t\t\ttop: top - origin.top,\n\t\t\tleft: left - origin.left\n\t\t});\n\t},\n\n\n\t// Triggers a callback. Calls a function in the option hash of the same name.\n\t// Arguments beyond the first `name` are forwarded on.\n\t// TODO: better code reuse for this. Repeat code\n\ttrigger: function(name) {\n\t\tif (this.options[name]) {\n\t\t\tthis.options[name].apply(this, Array.prototype.slice.call(arguments, 1));\n\t\t}\n\t}\n\n});\n\n;;\n\n/* A \"coordinate map\" converts pixel coordinates into an associated cell, which has an associated date\n------------------------------------------------------------------------------------------------------------------------\nCommon interface:\n\n\tCoordMap.prototype = {\n\t\tbuild: function() {},\n\t\tgetCell: function(x, y) {}\n\t};\n\n*/\n\n/* Coordinate map for a grid component\n----------------------------------------------------------------------------------------------------------------------*/\n\nvar GridCoordMap = Class.extend({\n\n\tgrid: null, // reference to the Grid\n\trowCoords: null, // array of {top,bottom} objects\n\tcolCoords: null, // array of {left,right} objects\n\n\tcontainerEl: null, // container element that all coordinates are constrained to. optionally assigned\n\tbounds: null,\n\n\n\tconstructor: function(grid) {\n\t\tthis.grid = grid;\n\t},\n\n\n\t// Queries the grid for the coordinates of all the cells\n\tbuild: function() {\n\t\tthis.rowCoords = this.grid.computeRowCoords();\n\t\tthis.colCoords = this.grid.computeColCoords();\n\t\tthis.computeBounds();\n\t},\n\n\n\t// Clears the coordinates data to free up memory\n\tclear: function() {\n\t\tthis.rowCoords = null;\n\t\tthis.colCoords = null;\n\t},\n\n\n\t// Given a coordinate of the document, gets the associated cell. If no cell is underneath, returns null\n\tgetCell: function(x, y) {\n\t\tvar rowCoords = this.rowCoords;\n\t\tvar rowCnt = rowCoords.length;\n\t\tvar colCoords = this.colCoords;\n\t\tvar colCnt = colCoords.length;\n\t\tvar hitRow = null;\n\t\tvar hitCol = null;\n\t\tvar i, coords;\n\t\tvar cell;\n\n\t\tif (this.inBounds(x, y)) {\n\n\t\t\tfor (i = 0; i < rowCnt; i++) {\n\t\t\t\tcoords = rowCoords[i];\n\t\t\t\tif (y >= coords.top && y < coords.bottom) {\n\t\t\t\t\thitRow = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (i = 0; i < colCnt; i++) {\n\t\t\t\tcoords = colCoords[i];\n\t\t\t\tif (x >= coords.left && x < coords.right) {\n\t\t\t\t\thitCol = i;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (hitRow !== null && hitCol !== null) {\n\n\t\t\t\tcell = this.grid.getCell(hitRow, hitCol); // expected to return a fresh object we can modify\n\t\t\t\tcell.grid = this.grid; // for CellDragListener's isCellsEqual. dragging between grids\n\n\t\t\t\t// make the coordinates available on the cell object\n\t\t\t\t$.extend(cell, rowCoords[hitRow], colCoords[hitCol]);\n\n\t\t\t\treturn cell;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t},\n\n\n\t// If there is a containerEl, compute the bounds into min/max values\n\tcomputeBounds: function() {\n\t\tthis.bounds = this.containerEl ?\n\t\t\tgetClientRect(this.containerEl) : // area within scrollbars\n\t\t\tnull;\n\t},\n\n\n\t// Determines if the given coordinates are in bounds. If no `containerEl`, always true\n\tinBounds: function(x, y) {\n\t\tvar bounds = this.bounds;\n\n\t\tif (bounds) {\n\t\t\treturn x >= bounds.left && x < bounds.right && y >= bounds.top && y < bounds.bottom;\n\t\t}\n\n\t\treturn true;\n\t}\n\n});\n\n\n/* Coordinate map that is a combination of multiple other coordinate maps\n----------------------------------------------------------------------------------------------------------------------*/\n\nvar ComboCoordMap = Class.extend({\n\n\tcoordMaps: null, // an array of CoordMaps\n\n\n\tconstructor: function(coordMaps) {\n\t\tthis.coordMaps = coordMaps;\n\t},\n\n\n\t// Builds all coordMaps\n\tbuild: function() {\n\t\tvar coordMaps = this.coordMaps;\n\t\tvar i;\n\n\t\tfor (i = 0; i < coordMaps.length; i++) {\n\t\t\tcoordMaps[i].build();\n\t\t}\n\t},\n\n\n\t// Queries all coordMaps for the cell underneath the given coordinates, returning the first result\n\tgetCell: function(x, y) {\n\t\tvar coordMaps = this.coordMaps;\n\t\tvar cell = null;\n\t\tvar i;\n\n\t\tfor (i = 0; i < coordMaps.length && !cell; i++) {\n\t\t\tcell = coordMaps[i].getCell(x, y);\n\t\t}\n\n\t\treturn cell;\n\t},\n\n\n\t// Clears all coordMaps\n\tclear: function() {\n\t\tvar coordMaps = this.coordMaps;\n\t\tvar i;\n\n\t\tfor (i = 0; i < coordMaps.length; i++) {\n\t\t\tcoordMaps[i].clear();\n\t\t}\n\t}\n\n});\n\n;;\n\n/* Tracks a drag's mouse movement, firing various handlers\n----------------------------------------------------------------------------------------------------------------------*/\n\nvar DragListener = fc.DragListener = Class.extend({\n\n\toptions: null,\n\n\tisListening: false,\n\tisDragging: false,\n\n\t// coordinates of the initial mousedown\n\toriginX: null,\n\toriginY: null,\n\n\t// handler attached to the document, bound to the DragListener's `this`\n\tmousemoveProxy: null,\n\tmouseupProxy: null,\n\n\t// for IE8 bug-fighting behavior, for now\n\tsubjectEl: null, // the element being draged. optional\n\tsubjectHref: null,\n\n\tscrollEl: null,\n\tscrollBounds: null, // { top, bottom, left, right }\n\tscrollTopVel: null, // pixels per second\n\tscrollLeftVel: null, // pixels per second\n\tscrollIntervalId: null, // ID of setTimeout for scrolling animation loop\n\tscrollHandlerProxy: null, // this-scoped function for handling when scrollEl is scrolled\n\n\tscrollSensitivity: 30, // pixels from edge for scrolling to start\n\tscrollSpeed: 200, // pixels per second, at maximum speed\n\tscrollIntervalMs: 50, // millisecond wait between scroll increment\n\n\n\tconstructor: function(options) {\n\t\toptions = options || {};\n\t\tthis.options = options;\n\t\tthis.subjectEl = options.subjectEl;\n\t},\n\n\n\t// Call this when the user does a mousedown. Will probably lead to startListening\n\tmousedown: function(ev) {\n\t\tif (isPrimaryMouseButton(ev)) {\n\n\t\t\tev.preventDefault(); // prevents native selection in most browsers\n\n\t\t\tthis.startListening(ev);\n\n\t\t\t// start the drag immediately if there is no minimum distance for a drag start\n\t\t\tif (!this.options.distance) {\n\t\t\t\tthis.startDrag(ev);\n\t\t\t}\n\t\t}\n\t},\n\n\n\t// Call this to start tracking mouse movements\n\tstartListening: function(ev) {\n\t\tvar scrollParent;\n\n\t\tif (!this.isListening) {\n\n\t\t\t// grab scroll container and attach handler\n\t\t\tif (ev && this.options.scroll) {\n\t\t\t\tscrollParent = getScrollParent($(ev.target));\n\t\t\t\tif (!scrollParent.is(window) && !scrollParent.is(document)) {\n\t\t\t\t\tthis.scrollEl = scrollParent;\n\n\t\t\t\t\t// scope to `this`, and use `debounce` to make sure rapid calls don't happen\n\t\t\t\t\tthis.scrollHandlerProxy = debounce(proxy(this, 'scrollHandler'), 100);\n\t\t\t\t\tthis.scrollEl.on('scroll', this.scrollHandlerProxy);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t$(document)\n\t\t\t\t.on('mousemove', this.mousemoveProxy = proxy(this, 'mousemove'))\n\t\t\t\t.on('mouseup', this.mouseupProxy = proxy(this, 'mouseup'))\n\t\t\t\t.on('selectstart', this.preventDefault); // prevents native selection in IE<=8\n\n\t\t\tif (ev) {\n\t\t\t\tthis.originX = ev.pageX;\n\t\t\t\tthis.originY = ev.pageY;\n\t\t\t}\n\t\t\telse {\n\t\t\t\t// if no starting information was given, origin will be the topleft corner of the screen.\n\t\t\t\t// if so, dx/dy in the future will be the absolute coordinates.\n\t\t\t\tthis.originX = 0;\n\t\t\t\tthis.originY = 0;\n\t\t\t}\n\n\t\t\tthis.isListening = true;\n\t\t\tthis.listenStart(ev);\n\t\t}\n\t},\n\n\n\t// Called when drag listening has started (but a real drag has not necessarily began)\n\tlistenStart: function(ev) {\n\t\tthis.trigger('listenStart', ev);\n\t},\n\n\n\t// Called when the user moves the mouse\n\tmousemove: function(ev) {\n\t\tvar dx = ev.pageX - this.originX;\n\t\tvar dy = ev.pageY - this.originY;\n\t\tvar minDistance;\n\t\tvar distanceSq; // current distance from the origin, squared\n\n\t\tif (!this.isDragging) { // if not already dragging...\n\t\t\t// then start the drag if the minimum distance criteria is met\n\t\t\tminDistance = this.options.distance || 1;\n\t\t\tdistanceSq = dx * dx + dy * dy;\n\t\t\tif (distanceSq >= minDistance * minDistance) { // use pythagorean theorem\n\t\t\t\tthis.startDrag(ev);\n\t\t\t}\n\t\t}\n\n\t\tif (this.isDragging) {\n\t\t\tthis.drag(dx, dy, ev); // report a drag, even if this mousemove initiated the drag\n\t\t}\n\t},\n\n\n\t// Call this to initiate a legitimate drag.\n\t// This function is called internally from this class, but can also be called explicitly from outside\n\tstartDrag: function(ev) {\n\n\t\tif (!this.isListening) { // startDrag must have manually initiated\n\t\t\tthis.startListening();\n\t\t}\n\n\t\tif (!this.isDragging) {\n\t\t\tthis.isDragging = true;\n\t\t\tthis.dragStart(ev);\n\t\t}\n\t},\n\n\n\t// Called when the actual drag has started (went beyond minDistance)\n\tdragStart: function(ev) {\n\t\tvar subjectEl = this.subjectEl;\n\n\t\tthis.trigger('dragStart', ev);\n\n\t\t// remove a mousedown'd 's href so it is not visited (IE8 bug)\n\t\tif ((this.subjectHref = subjectEl ? subjectEl.attr('href') : null)) {\n\t\t\tsubjectEl.removeAttr('href');\n\t\t}\n\t},\n\n\n\t// Called while the mouse is being moved and when we know a legitimate drag is taking place\n\tdrag: function(dx, dy, ev) {\n\t\tthis.trigger('drag', dx, dy, ev);\n\t\tthis.updateScroll(ev); // will possibly cause scrolling\n\t},\n\n\n\t// Called when the user does a mouseup\n\tmouseup: function(ev) {\n\t\tthis.stopListening(ev);\n\t},\n\n\n\t// Called when the drag is over. Will not cause listening to stop however.\n\t// A concluding 'cellOut' event will NOT be triggered.\n\tstopDrag: function(ev) {\n\t\tif (this.isDragging) {\n\t\t\tthis.stopScrolling();\n\t\t\tthis.dragStop(ev);\n\t\t\tthis.isDragging = false;\n\t\t}\n\t},\n\n\n\t// Called when dragging has been stopped\n\tdragStop: function(ev) {\n\t\tvar _this = this;\n\n\t\tthis.trigger('dragStop', ev);\n\n\t\t// restore a mousedown'd 's href (for IE8 bug)\n\t\tsetTimeout(function() { // must be outside of the click's execution\n\t\t\tif (_this.subjectHref) {\n\t\t\t\t_this.subjectEl.attr('href', _this.subjectHref);\n\t\t\t}\n\t\t}, 0);\n\t},\n\n\n\t// Call this to stop listening to the user's mouse events\n\tstopListening: function(ev) {\n\t\tthis.stopDrag(ev); // if there's a current drag, kill it\n\n\t\tif (this.isListening) {\n\n\t\t\t// remove the scroll handler if there is a scrollEl\n\t\t\tif (this.scrollEl) {\n\t\t\t\tthis.scrollEl.off('scroll', this.scrollHandlerProxy);\n\t\t\t\tthis.scrollHandlerProxy = null;\n\t\t\t}\n\n\t\t\t$(document)\n\t\t\t\t.off('mousemove', this.mousemoveProxy)\n\t\t\t\t.off('mouseup', this.mouseupProxy)\n\t\t\t\t.off('selectstart', this.preventDefault);\n\n\t\t\tthis.mousemoveProxy = null;\n\t\t\tthis.mouseupProxy = null;\n\n\t\t\tthis.isListening = false;\n\t\t\tthis.listenStop(ev);\n\t\t}\n\t},\n\n\n\t// Called when drag listening has stopped\n\tlistenStop: function(ev) {\n\t\tthis.trigger('listenStop', ev);\n\t},\n\n\n\t// Triggers a callback. Calls a function in the option hash of the same name.\n\t// Arguments beyond the first `name` are forwarded on.\n\ttrigger: function(name) {\n\t\tif (this.options[name]) {\n\t\t\tthis.options[name].apply(this, Array.prototype.slice.call(arguments, 1));\n\t\t}\n\t},\n\n\n\t// Stops a given mouse event from doing it's native browser action. In our case, text selection.\n\tpreventDefault: function(ev) {\n\t\tev.preventDefault();\n\t},\n\n\n\t/* Scrolling\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Computes and stores the bounding rectangle of scrollEl\n\tcomputeScrollBounds: function() {\n\t\tvar el = this.scrollEl;\n\n\t\tthis.scrollBounds = el ? getOuterRect(el) : null;\n\t\t\t// TODO: use getClientRect in future. but prevents auto scrolling when on top of scrollbars\n\t},\n\n\n\t// Called when the dragging is in progress and scrolling should be updated\n\tupdateScroll: function(ev) {\n\t\tvar sensitivity = this.scrollSensitivity;\n\t\tvar bounds = this.scrollBounds;\n\t\tvar topCloseness, bottomCloseness;\n\t\tvar leftCloseness, rightCloseness;\n\t\tvar topVel = 0;\n\t\tvar leftVel = 0;\n\n\t\tif (bounds) { // only scroll if scrollEl exists\n\n\t\t\t// compute closeness to edges. valid range is from 0.0 - 1.0\n\t\t\ttopCloseness = (sensitivity - (ev.pageY - bounds.top)) / sensitivity;\n\t\t\tbottomCloseness = (sensitivity - (bounds.bottom - ev.pageY)) / sensitivity;\n\t\t\tleftCloseness = (sensitivity - (ev.pageX - bounds.left)) / sensitivity;\n\t\t\trightCloseness = (sensitivity - (bounds.right - ev.pageX)) / sensitivity;\n\n\t\t\t// translate vertical closeness into velocity.\n\t\t\t// mouse must be completely in bounds for velocity to happen.\n\t\t\tif (topCloseness >= 0 && topCloseness <= 1) {\n\t\t\t\ttopVel = topCloseness * this.scrollSpeed * -1; // negative. for scrolling up\n\t\t\t}\n\t\t\telse if (bottomCloseness >= 0 && bottomCloseness <= 1) {\n\t\t\t\ttopVel = bottomCloseness * this.scrollSpeed;\n\t\t\t}\n\n\t\t\t// translate horizontal closeness into velocity\n\t\t\tif (leftCloseness >= 0 && leftCloseness <= 1) {\n\t\t\t\tleftVel = leftCloseness * this.scrollSpeed * -1; // negative. for scrolling left\n\t\t\t}\n\t\t\telse if (rightCloseness >= 0 && rightCloseness <= 1) {\n\t\t\t\tleftVel = rightCloseness * this.scrollSpeed;\n\t\t\t}\n\t\t}\n\n\t\tthis.setScrollVel(topVel, leftVel);\n\t},\n\n\n\t// Sets the speed-of-scrolling for the scrollEl\n\tsetScrollVel: function(topVel, leftVel) {\n\n\t\tthis.scrollTopVel = topVel;\n\t\tthis.scrollLeftVel = leftVel;\n\n\t\tthis.constrainScrollVel(); // massages into realistic values\n\n\t\t// if there is non-zero velocity, and an animation loop hasn't already started, then START\n\t\tif ((this.scrollTopVel || this.scrollLeftVel) && !this.scrollIntervalId) {\n\t\t\tthis.scrollIntervalId = setInterval(\n\t\t\t\tproxy(this, 'scrollIntervalFunc'), // scope to `this`\n\t\t\t\tthis.scrollIntervalMs\n\t\t\t);\n\t\t}\n\t},\n\n\n\t// Forces scrollTopVel and scrollLeftVel to be zero if scrolling has already gone all the way\n\tconstrainScrollVel: function() {\n\t\tvar el = this.scrollEl;\n\n\t\tif (this.scrollTopVel < 0) { // scrolling up?\n\t\t\tif (el.scrollTop() <= 0) { // already scrolled all the way up?\n\t\t\t\tthis.scrollTopVel = 0;\n\t\t\t}\n\t\t}\n\t\telse if (this.scrollTopVel > 0) { // scrolling down?\n\t\t\tif (el.scrollTop() + el[0].clientHeight >= el[0].scrollHeight) { // already scrolled all the way down?\n\t\t\t\tthis.scrollTopVel = 0;\n\t\t\t}\n\t\t}\n\n\t\tif (this.scrollLeftVel < 0) { // scrolling left?\n\t\t\tif (el.scrollLeft() <= 0) { // already scrolled all the left?\n\t\t\t\tthis.scrollLeftVel = 0;\n\t\t\t}\n\t\t}\n\t\telse if (this.scrollLeftVel > 0) { // scrolling right?\n\t\t\tif (el.scrollLeft() + el[0].clientWidth >= el[0].scrollWidth) { // already scrolled all the way right?\n\t\t\t\tthis.scrollLeftVel = 0;\n\t\t\t}\n\t\t}\n\t},\n\n\n\t// This function gets called during every iteration of the scrolling animation loop\n\tscrollIntervalFunc: function() {\n\t\tvar el = this.scrollEl;\n\t\tvar frac = this.scrollIntervalMs / 1000; // considering animation frequency, what the vel should be mult'd by\n\n\t\t// change the value of scrollEl's scroll\n\t\tif (this.scrollTopVel) {\n\t\t\tel.scrollTop(el.scrollTop() + this.scrollTopVel * frac);\n\t\t}\n\t\tif (this.scrollLeftVel) {\n\t\t\tel.scrollLeft(el.scrollLeft() + this.scrollLeftVel * frac);\n\t\t}\n\n\t\tthis.constrainScrollVel(); // since the scroll values changed, recompute the velocities\n\n\t\t// if scrolled all the way, which causes the vels to be zero, stop the animation loop\n\t\tif (!this.scrollTopVel && !this.scrollLeftVel) {\n\t\t\tthis.stopScrolling();\n\t\t}\n\t},\n\n\n\t// Kills any existing scrolling animation loop\n\tstopScrolling: function() {\n\t\tif (this.scrollIntervalId) {\n\t\t\tclearInterval(this.scrollIntervalId);\n\t\t\tthis.scrollIntervalId = null;\n\n\t\t\t// when all done with scrolling, recompute positions since they probably changed\n\t\t\tthis.scrollStop();\n\t\t}\n\t},\n\n\n\t// Get called when the scrollEl is scrolled (NOTE: this is delayed via debounce)\n\tscrollHandler: function() {\n\t\t// recompute all coordinates, but *only* if this is *not* part of our scrolling animation\n\t\tif (!this.scrollIntervalId) {\n\t\t\tthis.scrollStop();\n\t\t}\n\t},\n\n\n\t// Called when scrolling has stopped, whether through auto scroll, or the user scrolling\n\tscrollStop: function() {\n\t}\n\n});\n\n;;\n\n/* Tracks mouse movements over a CoordMap and raises events about which cell the mouse is over.\n------------------------------------------------------------------------------------------------------------------------\noptions:\n- subjectEl\n- subjectCenter\n*/\n\nvar CellDragListener = DragListener.extend({\n\n\tcoordMap: null, // converts coordinates to date cells\n\torigCell: null, // the cell the mouse was over when listening started\n\tcell: null, // the cell the mouse is over\n\tcoordAdjust: null, // delta that will be added to the mouse coordinates when computing collisions\n\n\n\tconstructor: function(coordMap, options) {\n\t\tDragListener.prototype.constructor.call(this, options); // call the super-constructor\n\n\t\tthis.coordMap = coordMap;\n\t},\n\n\n\t// Called when drag listening starts (but a real drag has not necessarily began).\n\t// ev might be undefined if dragging was started manually.\n\tlistenStart: function(ev) {\n\t\tvar subjectEl = this.subjectEl;\n\t\tvar subjectRect;\n\t\tvar origPoint;\n\t\tvar point;\n\n\t\tDragListener.prototype.listenStart.apply(this, arguments); // call the super-method\n\n\t\tthis.computeCoords();\n\n\t\tif (ev) {\n\t\t\torigPoint = { left: ev.pageX, top: ev.pageY };\n\t\t\tpoint = origPoint;\n\n\t\t\t// constrain the point to bounds of the element being dragged\n\t\t\tif (subjectEl) {\n\t\t\t\tsubjectRect = getOuterRect(subjectEl); // used for centering as well\n\t\t\t\tpoint = constrainPoint(point, subjectRect);\n\t\t\t}\n\n\t\t\tthis.origCell = this.getCell(point.left, point.top);\n\n\t\t\t// treat the center of the subject as the collision point?\n\t\t\tif (subjectEl && this.options.subjectCenter) {\n\n\t\t\t\t// only consider the area the subject overlaps the cell. best for large subjects\n\t\t\t\tif (this.origCell) {\n\t\t\t\t\tsubjectRect = intersectRects(this.origCell, subjectRect) ||\n\t\t\t\t\t\tsubjectRect; // in case there is no intersection\n\t\t\t\t}\n\n\t\t\t\tpoint = getRectCenter(subjectRect);\n\t\t\t}\n\n\t\t\tthis.coordAdjust = diffPoints(point, origPoint); // point - origPoint\n\t\t}\n\t\telse {\n\t\t\tthis.origCell = null;\n\t\t\tthis.coordAdjust = null;\n\t\t}\n\t},\n\n\n\t// Recomputes the drag-critical positions of elements\n\tcomputeCoords: function() {\n\t\tthis.coordMap.build();\n\t\tthis.computeScrollBounds();\n\t},\n\n\n\t// Called when the actual drag has started\n\tdragStart: function(ev) {\n\t\tvar cell;\n\n\t\tDragListener.prototype.dragStart.apply(this, arguments); // call the super-method\n\n\t\tcell = this.getCell(ev.pageX, ev.pageY); // might be different from this.origCell if the min-distance is large\n\n\t\t// report the initial cell the mouse is over\n\t\t// especially important if no min-distance and drag starts immediately\n\t\tif (cell) {\n\t\t\tthis.cellOver(cell);\n\t\t}\n\t},\n\n\n\t// Called when the drag moves\n\tdrag: function(dx, dy, ev) {\n\t\tvar cell;\n\n\t\tDragListener.prototype.drag.apply(this, arguments); // call the super-method\n\n\t\tcell = this.getCell(ev.pageX, ev.pageY);\n\n\t\tif (!isCellsEqual(cell, this.cell)) { // a different cell than before?\n\t\t\tif (this.cell) {\n\t\t\t\tthis.cellOut();\n\t\t\t}\n\t\t\tif (cell) {\n\t\t\t\tthis.cellOver(cell);\n\t\t\t}\n\t\t}\n\t},\n\n\n\t// Called when dragging has been stopped\n\tdragStop: function() {\n\t\tthis.cellDone();\n\t\tDragListener.prototype.dragStop.apply(this, arguments); // call the super-method\n\t},\n\n\n\t// Called when a the mouse has just moved over a new cell\n\tcellOver: function(cell) {\n\t\tthis.cell = cell;\n\t\tthis.trigger('cellOver', cell, isCellsEqual(cell, this.origCell), this.origCell);\n\t},\n\n\n\t// Called when the mouse has just moved out of a cell\n\tcellOut: function() {\n\t\tif (this.cell) {\n\t\t\tthis.trigger('cellOut', this.cell);\n\t\t\tthis.cellDone();\n\t\t\tthis.cell = null;\n\t\t}\n\t},\n\n\n\t// Called after a cellOut. Also called before a dragStop\n\tcellDone: function() {\n\t\tif (this.cell) {\n\t\t\tthis.trigger('cellDone', this.cell);\n\t\t}\n\t},\n\n\n\t// Called when drag listening has stopped\n\tlistenStop: function() {\n\t\tDragListener.prototype.listenStop.apply(this, arguments); // call the super-method\n\n\t\tthis.origCell = this.cell = null;\n\t\tthis.coordMap.clear();\n\t},\n\n\n\t// Called when scrolling has stopped, whether through auto scroll, or the user scrolling\n\tscrollStop: function() {\n\t\tDragListener.prototype.scrollStop.apply(this, arguments); // call the super-method\n\n\t\tthis.computeCoords(); // cells' absolute positions will be in new places. recompute\n\t},\n\n\n\t// Gets the cell underneath the coordinates for the given mouse event\n\tgetCell: function(left, top) {\n\n\t\tif (this.coordAdjust) {\n\t\t\tleft += this.coordAdjust.left;\n\t\t\ttop += this.coordAdjust.top;\n\t\t}\n\n\t\treturn this.coordMap.getCell(left, top);\n\t}\n\n});\n\n\n// Returns `true` if the cells are identically equal. `false` otherwise.\n// They must have the same row, col, and be from the same grid.\n// Two null values will be considered equal, as two \"out of the grid\" states are the same.\nfunction isCellsEqual(cell1, cell2) {\n\n\tif (!cell1 && !cell2) {\n\t\treturn true;\n\t}\n\n\tif (cell1 && cell2) {\n\t\treturn cell1.grid === cell2.grid &&\n\t\t\tcell1.row === cell2.row &&\n\t\t\tcell1.col === cell2.col;\n\t}\n\n\treturn false;\n}\n\n;;\n\n/* Creates a clone of an element and lets it track the mouse as it moves\n----------------------------------------------------------------------------------------------------------------------*/\n\nvar MouseFollower = Class.extend({\n\n\toptions: null,\n\n\tsourceEl: null, // the element that will be cloned and made to look like it is dragging\n\tel: null, // the clone of `sourceEl` that will track the mouse\n\tparentEl: null, // the element that `el` (the clone) will be attached to\n\n\t// the initial position of el, relative to the offset parent. made to match the initial offset of sourceEl\n\ttop0: null,\n\tleft0: null,\n\n\t// the initial position of the mouse\n\tmouseY0: null,\n\tmouseX0: null,\n\n\t// the number of pixels the mouse has moved from its initial position\n\ttopDelta: null,\n\tleftDelta: null,\n\n\tmousemoveProxy: null, // document mousemove handler, bound to the MouseFollower's `this`\n\n\tisFollowing: false,\n\tisHidden: false,\n\tisAnimating: false, // doing the revert animation?\n\n\tconstructor: function(sourceEl, options) {\n\t\tthis.options = options = options || {};\n\t\tthis.sourceEl = sourceEl;\n\t\tthis.parentEl = options.parentEl ? $(options.parentEl) : sourceEl.parent(); // default to sourceEl's parent\n\t},\n\n\n\t// Causes the element to start following the mouse\n\tstart: function(ev) {\n\t\tif (!this.isFollowing) {\n\t\t\tthis.isFollowing = true;\n\n\t\t\tthis.mouseY0 = ev.pageY;\n\t\t\tthis.mouseX0 = ev.pageX;\n\t\t\tthis.topDelta = 0;\n\t\t\tthis.leftDelta = 0;\n\n\t\t\tif (!this.isHidden) {\n\t\t\t\tthis.updatePosition();\n\t\t\t}\n\n\t\t\t$(document).on('mousemove', this.mousemoveProxy = proxy(this, 'mousemove'));\n\t\t}\n\t},\n\n\n\t// Causes the element to stop following the mouse. If shouldRevert is true, will animate back to original position.\n\t// `callback` gets invoked when the animation is complete. If no animation, it is invoked immediately.\n\tstop: function(shouldRevert, callback) {\n\t\tvar _this = this;\n\t\tvar revertDuration = this.options.revertDuration;\n\n\t\tfunction complete() {\n\t\t\tthis.isAnimating = false;\n\t\t\t_this.destroyEl();\n\n\t\t\tthis.top0 = this.left0 = null; // reset state for future updatePosition calls\n\n\t\t\tif (callback) {\n\t\t\t\tcallback();\n\t\t\t}\n\t\t}\n\n\t\tif (this.isFollowing && !this.isAnimating) { // disallow more than one stop animation at a time\n\t\t\tthis.isFollowing = false;\n\n\t\t\t$(document).off('mousemove', this.mousemoveProxy);\n\n\t\t\tif (shouldRevert && revertDuration && !this.isHidden) { // do a revert animation?\n\t\t\t\tthis.isAnimating = true;\n\t\t\t\tthis.el.animate({\n\t\t\t\t\ttop: this.top0,\n\t\t\t\t\tleft: this.left0\n\t\t\t\t}, {\n\t\t\t\t\tduration: revertDuration,\n\t\t\t\t\tcomplete: complete\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcomplete();\n\t\t\t}\n\t\t}\n\t},\n\n\n\t// Gets the tracking element. Create it if necessary\n\tgetEl: function() {\n\t\tvar el = this.el;\n\n\t\tif (!el) {\n\t\t\tthis.sourceEl.width(); // hack to force IE8 to compute correct bounding box\n\t\t\tel = this.el = this.sourceEl.clone()\n\t\t\t\t.css({\n\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\tvisibility: '', // in case original element was hidden (commonly through hideEvents())\n\t\t\t\t\tdisplay: this.isHidden ? 'none' : '', // for when initially hidden\n\t\t\t\t\tmargin: 0,\n\t\t\t\t\tright: 'auto', // erase and set width instead\n\t\t\t\t\tbottom: 'auto', // erase and set height instead\n\t\t\t\t\twidth: this.sourceEl.width(), // explicit height in case there was a 'right' value\n\t\t\t\t\theight: this.sourceEl.height(), // explicit width in case there was a 'bottom' value\n\t\t\t\t\topacity: this.options.opacity || '',\n\t\t\t\t\tzIndex: this.options.zIndex\n\t\t\t\t})\n\t\t\t\t.appendTo(this.parentEl);\n\t\t}\n\n\t\treturn el;\n\t},\n\n\n\t// Removes the tracking element if it has already been created\n\tdestroyEl: function() {\n\t\tif (this.el) {\n\t\t\tthis.el.remove();\n\t\t\tthis.el = null;\n\t\t}\n\t},\n\n\n\t// Update the CSS position of the tracking element\n\tupdatePosition: function() {\n\t\tvar sourceOffset;\n\t\tvar origin;\n\n\t\tthis.getEl(); // ensure this.el\n\n\t\t// make sure origin info was computed\n\t\tif (this.top0 === null) {\n\t\t\tthis.sourceEl.width(); // hack to force IE8 to compute correct bounding box\n\t\t\tsourceOffset = this.sourceEl.offset();\n\t\t\torigin = this.el.offsetParent().offset();\n\t\t\tthis.top0 = sourceOffset.top - origin.top;\n\t\t\tthis.left0 = sourceOffset.left - origin.left;\n\t\t}\n\n\t\tthis.el.css({\n\t\t\ttop: this.top0 + this.topDelta,\n\t\t\tleft: this.left0 + this.leftDelta\n\t\t});\n\t},\n\n\n\t// Gets called when the user moves the mouse\n\tmousemove: function(ev) {\n\t\tthis.topDelta = ev.pageY - this.mouseY0;\n\t\tthis.leftDelta = ev.pageX - this.mouseX0;\n\n\t\tif (!this.isHidden) {\n\t\t\tthis.updatePosition();\n\t\t}\n\t},\n\n\n\t// Temporarily makes the tracking element invisible. Can be called before following starts\n\thide: function() {\n\t\tif (!this.isHidden) {\n\t\t\tthis.isHidden = true;\n\t\t\tif (this.el) {\n\t\t\t\tthis.el.hide();\n\t\t\t}\n\t\t}\n\t},\n\n\n\t// Show the tracking element after it has been temporarily hidden\n\tshow: function() {\n\t\tif (this.isHidden) {\n\t\t\tthis.isHidden = false;\n\t\t\tthis.updatePosition();\n\t\t\tthis.getEl().show();\n\t\t}\n\t}\n\n});\n\n;;\n\n/* A utility class for rendering rows.\n----------------------------------------------------------------------------------------------------------------------*/\n// It leverages methods of the subclass and the View to determine custom rendering behavior for each row \"type\"\n// (such as highlight rows, day rows, helper rows, etc).\n\nvar RowRenderer = Class.extend({\n\n\tview: null, // a View object\n\tisRTL: null, // shortcut to the view's isRTL option\n\tcellHtml: ' | ', // plain default HTML used for a cell when no other is available\n\n\n\tconstructor: function(view) {\n\t\tthis.view = view;\n\t\tthis.isRTL = view.opt('isRTL');\n\t},\n\n\n\t// Renders the HTML for a row, leveraging custom cell-HTML-renderers based on the `rowType`.\n\t// Also applies the \"intro\" and \"outro\" cells, which are specified by the subclass and views.\n\t// `row` is an optional row number.\n\trowHtml: function(rowType, row) {\n\t\tvar renderCell = this.getHtmlRenderer('cell', rowType);\n\t\tvar rowCellHtml = '';\n\t\tvar col;\n\t\tvar cell;\n\n\t\trow = row || 0;\n\n\t\tfor (col = 0; col < this.colCnt; col++) {\n\t\t\tcell = this.getCell(row, col);\n\t\t\trowCellHtml += renderCell(cell);\n\t\t}\n\n\t\trowCellHtml = this.bookendCells(rowCellHtml, rowType, row); // apply intro and outro\n\n\t\treturn ' ' + rowCellHtml + ' ';\n\t},\n\n\n\t// Applies the \"intro\" and \"outro\" HTML to the given cells.\n\t// Intro means the leftmost cell when the calendar is LTR and the rightmost cell when RTL. Vice-versa for outro.\n\t// `cells` can be an HTML string of 's or a jQuery | element\n\t// `row` is an optional row number.\n\tbookendCells: function(cells, rowType, row) {\n\t\tvar intro = this.getHtmlRenderer('intro', rowType)(row || 0);\n\t\tvar outro = this.getHtmlRenderer('outro', rowType)(row || 0);\n\t\tvar prependHtml = this.isRTL ? outro : intro;\n\t\tvar appendHtml = this.isRTL ? intro : outro;\n\n\t\tif (typeof cells === 'string') {\n\t\t\treturn prependHtml + cells + appendHtml;\n\t\t}\n\t\telse { // a jQuery element\n\t\t\treturn cells.prepend(prependHtml).append(appendHtml);\n\t\t}\n\t},\n\n\n\t// Returns an HTML-rendering function given a specific `rendererName` (like cell, intro, or outro) and a specific\n\t// `rowType` (like day, eventSkeleton, helperSkeleton), which is optional.\n\t// If a renderer for the specific rowType doesn't exist, it will fall back to a generic renderer.\n\t// We will query the View object first for any custom rendering functions, then the methods of the subclass.\n\tgetHtmlRenderer: function(rendererName, rowType) {\n\t\tvar view = this.view;\n\t\tvar generalName; // like \"cellHtml\"\n\t\tvar specificName; // like \"dayCellHtml\". based on rowType\n\t\tvar provider; // either the View or the RowRenderer subclass, whichever provided the method\n\t\tvar renderer;\n\n\t\tgeneralName = rendererName + 'Html';\n\t\tif (rowType) {\n\t\t\tspecificName = rowType + capitaliseFirstLetter(rendererName) + 'Html';\n\t\t}\n\n\t\tif (specificName && (renderer = view[specificName])) {\n\t\t\tprovider = view;\n\t\t}\n\t\telse if (specificName && (renderer = this[specificName])) {\n\t\t\tprovider = this;\n\t\t}\n\t\telse if ((renderer = view[generalName])) {\n\t\t\tprovider = view;\n\t\t}\n\t\telse if ((renderer = this[generalName])) {\n\t\t\tprovider = this;\n\t\t}\n\n\t\tif (typeof renderer === 'function') {\n\t\t\treturn function() {\n\t\t\t\treturn renderer.apply(provider, arguments) || ''; // use correct `this` and always return a string\n\t\t\t};\n\t\t}\n\n\t\t// the rendered can be a plain string as well. if not specified, always an empty string.\n\t\treturn function() {\n\t\t\treturn renderer || '';\n\t\t};\n\t}\n\n});\n\n;;\n\n/* An abstract class comprised of a \"grid\" of cells that each represent a specific datetime\n----------------------------------------------------------------------------------------------------------------------*/\n\nvar Grid = fc.Grid = RowRenderer.extend({\n\n\tstart: null, // the date of the first cell\n\tend: null, // the date after the last cell\n\n\trowCnt: 0, // number of rows\n\tcolCnt: 0, // number of cols\n\trowData: null, // array of objects, holding misc data for each row\n\tcolData: null, // array of objects, holding misc data for each column\n\n\tel: null, // the containing element\n\tcoordMap: null, // a GridCoordMap that converts pixel values to datetimes\n\telsByFill: null, // a hash of jQuery element sets used for rendering each fill. Keyed by fill name.\n\n\texternalDragStartProxy: null, // binds the Grid's scope to externalDragStart (in DayGrid.events)\n\n\t// derived from options\n\tcolHeadFormat: null, // TODO: move to another class. not applicable to all Grids\n\teventTimeFormat: null,\n\tdisplayEventTime: null,\n\tdisplayEventEnd: null,\n\n\t// if all cells are the same length of time, the duration they all share. optional.\n\t// when defined, allows the computeCellRange shortcut, as well as improved resizing behavior.\n\tcellDuration: null,\n\n\t// if defined, holds the unit identified (ex: \"year\" or \"month\") that determines the level of granularity\n\t// of the date cells. if not defined, assumes to be day and time granularity.\n\tlargeUnit: null,\n\n\n\tconstructor: function() {\n\t\tRowRenderer.apply(this, arguments); // call the super-constructor\n\n\t\tthis.coordMap = new GridCoordMap(this);\n\t\tthis.elsByFill = {};\n\t\tthis.externalDragStartProxy = proxy(this, 'externalDragStart');\n\t},\n\n\n\t/* Options\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Generates the format string used for the text in column headers, if not explicitly defined by 'columnFormat'\n\t// TODO: move to another class. not applicable to all Grids\n\tcomputeColHeadFormat: function() {\n\t\t// subclasses must implement if they want to use headHtml()\n\t},\n\n\n\t// Generates the format string used for event time text, if not explicitly defined by 'timeFormat'\n\tcomputeEventTimeFormat: function() {\n\t\treturn this.view.opt('smallTimeFormat');\n\t},\n\n\n\t// Determines whether events should have their end times displayed, if not explicitly defined by 'displayEventTime'.\n\t// Only applies to non-all-day events.\n\tcomputeDisplayEventTime: function() {\n\t\treturn true;\n\t},\n\n\n\t// Determines whether events should have their end times displayed, if not explicitly defined by 'displayEventEnd'\n\tcomputeDisplayEventEnd: function() {\n\t\treturn true;\n\t},\n\n\n\t/* Dates\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Tells the grid about what period of time to display. Grid will subsequently compute dates for cell system.\n\tsetRange: function(range) {\n\t\tvar view = this.view;\n\t\tvar displayEventTime;\n\t\tvar displayEventEnd;\n\n\t\tthis.start = range.start.clone();\n\t\tthis.end = range.end.clone();\n\n\t\tthis.rowData = [];\n\t\tthis.colData = [];\n\t\tthis.updateCells();\n\n\t\t// Populate option-derived settings. Look for override first, then compute if necessary.\n\t\tthis.colHeadFormat = view.opt('columnFormat') || this.computeColHeadFormat();\n\n\t\tthis.eventTimeFormat =\n\t\t\tview.opt('eventTimeFormat') ||\n\t\t\tview.opt('timeFormat') || // deprecated\n\t\t\tthis.computeEventTimeFormat();\n\n\t\tdisplayEventTime = view.opt('displayEventTime');\n\t\tif (displayEventTime == null) {\n\t\t\tdisplayEventTime = this.computeDisplayEventTime(); // might be based off of range\n\t\t}\n\n\t\tdisplayEventEnd = view.opt('displayEventEnd');\n\t\tif (displayEventEnd == null) {\n\t\t\tdisplayEventEnd = this.computeDisplayEventEnd(); // might be based off of range\n\t\t}\n\n\t\tthis.displayEventTime = displayEventTime;\n\t\tthis.displayEventEnd = displayEventEnd;\n\t},\n\n\n\t// Responsible for setting rowCnt/colCnt and any other row/col data\n\tupdateCells: function() {\n\t\t// subclasses must implement\n\t},\n\n\n\t// Converts a range with an inclusive `start` and an exclusive `end` into an array of segment objects\n\trangeToSegs: function(range) {\n\t\t// subclasses must implement\n\t},\n\n\n\t// Diffs the two dates, returning a duration, based on granularity of the grid\n\tdiffDates: function(a, b) {\n\t\tif (this.largeUnit) {\n\t\t\treturn diffByUnit(a, b, this.largeUnit);\n\t\t}\n\t\telse {\n\t\t\treturn diffDayTime(a, b);\n\t\t}\n\t},\n\n\n\t/* Cells\n\t------------------------------------------------------------------------------------------------------------------*/\n\t// NOTE: columns are ordered left-to-right\n\n\n\t// Gets an object containing row/col number, misc data, and range information about the cell.\n\t// Accepts row/col values, an object with row/col properties, or a single-number offset from the first cell.\n\tgetCell: function(row, col) {\n\t\tvar cell;\n\n\t\tif (col == null) {\n\t\t\tif (typeof row === 'number') { // a single-number offset\n\t\t\t\tcol = row % this.colCnt;\n\t\t\t\trow = Math.floor(row / this.colCnt);\n\t\t\t}\n\t\t\telse { // an object with row/col properties\n\t\t\t\tcol = row.col;\n\t\t\t\trow = row.row;\n\t\t\t}\n\t\t}\n\n\t\tcell = { row: row, col: col };\n\n\t\t$.extend(cell, this.getRowData(row), this.getColData(col));\n\t\t$.extend(cell, this.computeCellRange(cell));\n\n\t\treturn cell;\n\t},\n\n\n\t// Given a cell object with index and misc data, generates a range object\n\t// If the grid is leveraging cellDuration, this doesn't need to be defined. Only computeCellDate does.\n\t// If being overridden, should return a range with reference-free date copies.\n\tcomputeCellRange: function(cell) {\n\t\tvar date = this.computeCellDate(cell);\n\n\t\treturn {\n\t\t\tstart: date,\n\t\t\tend: date.clone().add(this.cellDuration)\n\t\t};\n\t},\n\n\n\t// Given a cell, returns its start date. Should return a reference-free date copy.\n\tcomputeCellDate: function(cell) {\n\t\t// subclasses can implement\n\t},\n\n\n\t// Retrieves misc data about the given row\n\tgetRowData: function(row) {\n\t\treturn this.rowData[row] || {};\n\t},\n\n\n\t// Retrieves misc data baout the given column\n\tgetColData: function(col) {\n\t\treturn this.colData[col] || {};\n\t},\n\n\n\t// Retrieves the element representing the given row\n\tgetRowEl: function(row) {\n\t\t// subclasses should implement if leveraging the default getCellDayEl() or computeRowCoords()\n\t},\n\n\n\t// Retrieves the element representing the given column\n\tgetColEl: function(col) {\n\t\t// subclasses should implement if leveraging the default getCellDayEl() or computeColCoords()\n\t},\n\n\n\t// Given a cell object, returns the element that represents the cell's whole-day\n\tgetCellDayEl: function(cell) {\n\t\treturn this.getColEl(cell.col) || this.getRowEl(cell.row);\n\t},\n\n\n\t/* Cell Coordinates\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Computes the top/bottom coordinates of all rows.\n\t// By default, queries the dimensions of the element provided by getRowEl().\n\tcomputeRowCoords: function() {\n\t\tvar items = [];\n\t\tvar i, el;\n\t\tvar top;\n\n\t\tfor (i = 0; i < this.rowCnt; i++) {\n\t\t\tel = this.getRowEl(i);\n\t\t\ttop = el.offset().top;\n\t\t\titems.push({\n\t\t\t\ttop: top,\n\t\t\t\tbottom: top + el.outerHeight()\n\t\t\t});\n\t\t}\n\n\t\treturn items;\n\t},\n\n\n\t// Computes the left/right coordinates of all rows.\n\t// By default, queries the dimensions of the element provided by getColEl(). Columns can be LTR or RTL.\n\tcomputeColCoords: function() {\n\t\tvar items = [];\n\t\tvar i, el;\n\t\tvar left;\n\n\t\tfor (i = 0; i < this.colCnt; i++) {\n\t\t\tel = this.getColEl(i);\n\t\t\tleft = el.offset().left;\n\t\t\titems.push({\n\t\t\t\tleft: left,\n\t\t\t\tright: left + el.outerWidth()\n\t\t\t});\n\t\t}\n\n\t\treturn items;\n\t},\n\n\n\t/* Rendering\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Sets the container element that the grid should render inside of.\n\t// Does other DOM-related initializations.\n\tsetElement: function(el) {\n\t\tvar _this = this;\n\n\t\tthis.el = el;\n\n\t\t// attach a handler to the grid's root element.\n\t\t// jQuery will take care of unregistering them when removeElement gets called.\n\t\tel.on('mousedown', function(ev) {\n\t\t\tif (\n\t\t\t\t!$(ev.target).is('.fc-event-container *, .fc-more') && // not an an event element, or \"more..\" link\n\t\t\t\t!$(ev.target).closest('.fc-popover').length // not on a popover (like the \"more..\" events one)\n\t\t\t) {\n\t\t\t\t_this.dayMousedown(ev);\n\t\t\t}\n\t\t});\n\n\t\t// attach event-element-related handlers. in Grid.events\n\t\t// same garbage collection note as above.\n\t\tthis.bindSegHandlers();\n\n\t\tthis.bindGlobalHandlers();\n\t},\n\n\n\t// Removes the grid's container element from the DOM. Undoes any other DOM-related attachments.\n\t// DOES NOT remove any content before hand (doens't clear events or call destroyDates), unlike View\n\tremoveElement: function() {\n\t\tthis.unbindGlobalHandlers();\n\n\t\tthis.el.remove();\n\n\t\t// NOTE: we don't null-out this.el for the same reasons we don't do it within View::removeElement\n\t},\n\n\n\t// Renders the basic structure of grid view before any content is rendered\n\trenderSkeleton: function() {\n\t\t// subclasses should implement\n\t},\n\n\n\t// Renders the grid's date-related content (like cells that represent days/times).\n\t// Assumes setRange has already been called and the skeleton has already been rendered.\n\trenderDates: function() {\n\t\t// subclasses should implement\n\t},\n\n\n\t// Unrenders the grid's date-related content\n\tdestroyDates: function() {\n\t\t// subclasses should implement\n\t},\n\n\n\t/* Handlers\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Binds DOM handlers to elements that reside outside the grid, such as the document\n\tbindGlobalHandlers: function() {\n\t\t$(document).on('dragstart sortstart', this.externalDragStartProxy); // jqui\n\t},\n\n\n\t// Unbinds DOM handlers from elements that reside outside the grid\n\tunbindGlobalHandlers: function() {\n\t\t$(document).off('dragstart sortstart', this.externalDragStartProxy); // jqui\n\t},\n\n\n\t// Process a mousedown on an element that represents a day. For day clicking and selecting.\n\tdayMousedown: function(ev) {\n\t\tvar _this = this;\n\t\tvar view = this.view;\n\t\tvar isSelectable = view.opt('selectable');\n\t\tvar dayClickCell; // null if invalid dayClick\n\t\tvar selectionRange; // null if invalid selection\n\n\t\t// this listener tracks a mousedown on a day element, and a subsequent drag.\n\t\t// if the drag ends on the same day, it is a 'dayClick'.\n\t\t// if 'selectable' is enabled, this listener also detects selections.\n\t\tvar dragListener = new CellDragListener(this.coordMap, {\n\t\t\t//distance: 5, // needs more work if we want dayClick to fire correctly\n\t\t\tscroll: view.opt('dragScroll'),\n\t\t\tdragStart: function() {\n\t\t\t\tview.unselect(); // since we could be rendering a new selection, we want to clear any old one\n\t\t\t},\n\t\t\tcellOver: function(cell, isOrig, origCell) {\n\t\t\t\tif (origCell) { // click needs to have started on a cell\n\t\t\t\t\tdayClickCell = isOrig ? cell : null; // single-cell selection is a day click\n\t\t\t\t\tif (isSelectable) {\n\t\t\t\t\t\tselectionRange = _this.computeSelection(origCell, cell);\n\t\t\t\t\t\tif (selectionRange) {\n\t\t\t\t\t\t\t_this.renderSelection(selectionRange);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tdisableCursor();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tcellOut: function(cell) {\n\t\t\t\tdayClickCell = null;\n\t\t\t\tselectionRange = null;\n\t\t\t\t_this.destroySelection();\n\t\t\t\tenableCursor();\n\t\t\t},\n\t\t\tlistenStop: function(ev) {\n\t\t\t\tif (dayClickCell) {\n\t\t\t\t\tview.trigger('dayClick', _this.getCellDayEl(dayClickCell), dayClickCell.start, ev);\n\t\t\t\t}\n\t\t\t\tif (selectionRange) {\n\t\t\t\t\t// the selection will already have been rendered. just report it\n\t\t\t\t\tview.reportSelection(selectionRange, ev);\n\t\t\t\t}\n\t\t\t\tenableCursor();\n\t\t\t}\n\t\t});\n\n\t\tdragListener.mousedown(ev); // start listening, which will eventually initiate a dragStart\n\t},\n\n\n\t/* Event Helper\n\t------------------------------------------------------------------------------------------------------------------*/\n\t// TODO: should probably move this to Grid.events, like we did event dragging / resizing\n\n\n\t// Renders a mock event over the given range\n\trenderRangeHelper: function(range, sourceSeg) {\n\t\tvar fakeEvent = this.fabricateHelperEvent(range, sourceSeg);\n\n\t\tthis.renderHelper(fakeEvent, sourceSeg); // do the actual rendering\n\t},\n\n\n\t// Builds a fake event given a date range it should cover, and a segment is should be inspired from.\n\t// The range's end can be null, in which case the mock event that is rendered will have a null end time.\n\t// `sourceSeg` is the internal segment object involved in the drag. If null, something external is dragging.\n\tfabricateHelperEvent: function(range, sourceSeg) {\n\t\tvar fakeEvent = sourceSeg ? createObject(sourceSeg.event) : {}; // mask the original event object if possible\n\n\t\tfakeEvent.start = range.start.clone();\n\t\tfakeEvent.end = range.end ? range.end.clone() : null;\n\t\tfakeEvent.allDay = null; // force it to be freshly computed by normalizeEventRange\n\t\tthis.view.calendar.normalizeEventRange(fakeEvent);\n\n\t\t// this extra className will be useful for differentiating real events from mock events in CSS\n\t\tfakeEvent.className = (fakeEvent.className || []).concat('fc-helper');\n\n\t\t// if something external is being dragged in, don't render a resizer\n\t\tif (!sourceSeg) {\n\t\t\tfakeEvent.editable = false;\n\t\t}\n\n\t\treturn fakeEvent;\n\t},\n\n\n\t// Renders a mock event\n\trenderHelper: function(event, sourceSeg) {\n\t\t// subclasses must implement\n\t},\n\n\n\t// Unrenders a mock event\n\tdestroyHelper: function() {\n\t\t// subclasses must implement\n\t},\n\n\n\t/* Selection\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Renders a visual indication of a selection. Will highlight by default but can be overridden by subclasses.\n\trenderSelection: function(range) {\n\t\tthis.renderHighlight(range);\n\t},\n\n\n\t// Unrenders any visual indications of a selection. Will unrender a highlight by default.\n\tdestroySelection: function() {\n\t\tthis.destroyHighlight();\n\t},\n\n\n\t// Given the first and last cells of a selection, returns a range object.\n\t// Will return something falsy if the selection is invalid (when outside of selectionConstraint for example).\n\t// Subclasses can override and provide additional data in the range object. Will be passed to renderSelection().\n\tcomputeSelection: function(firstCell, lastCell) {\n\t\tvar dates = [\n\t\t\tfirstCell.start,\n\t\t\tfirstCell.end,\n\t\t\tlastCell.start,\n\t\t\tlastCell.end\n\t\t];\n\t\tvar range;\n\n\t\tdates.sort(compareNumbers); // sorts chronologically. works with Moments\n\n\t\trange = {\n\t\t\tstart: dates[0].clone(),\n\t\t\tend: dates[3].clone()\n\t\t};\n\n\t\tif (!this.view.calendar.isSelectionRangeAllowed(range)) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn range;\n\t},\n\n\n\t/* Highlight\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Renders an emphasis on the given date range. `start` is inclusive. `end` is exclusive.\n\trenderHighlight: function(range) {\n\t\tthis.renderFill('highlight', this.rangeToSegs(range));\n\t},\n\n\n\t// Unrenders the emphasis on a date range\n\tdestroyHighlight: function() {\n\t\tthis.destroyFill('highlight');\n\t},\n\n\n\t// Generates an array of classNames for rendering the highlight. Used by the fill system.\n\thighlightSegClasses: function() {\n\t\treturn [ 'fc-highlight' ];\n\t},\n\n\n\t/* Fill System (highlight, background events, business hours)\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Renders a set of rectangles over the given segments of time.\n\t// Returns a subset of segs, the segs that were actually rendered.\n\t// Responsible for populating this.elsByFill. TODO: better API for expressing this requirement\n\trenderFill: function(type, segs) {\n\t\t// subclasses must implement\n\t},\n\n\n\t// Unrenders a specific type of fill that is currently rendered on the grid\n\tdestroyFill: function(type) {\n\t\tvar el = this.elsByFill[type];\n\n\t\tif (el) {\n\t\t\tel.remove();\n\t\t\tdelete this.elsByFill[type];\n\t\t}\n\t},\n\n\n\t// Renders and assigns an `el` property for each fill segment. Generic enough to work with different types.\n\t// Only returns segments that successfully rendered.\n\t// To be harnessed by renderFill (implemented by subclasses).\n\t// Analagous to renderFgSegEls.\n\trenderFillSegEls: function(type, segs) {\n\t\tvar _this = this;\n\t\tvar segElMethod = this[type + 'SegEl'];\n\t\tvar html = '';\n\t\tvar renderedSegs = [];\n\t\tvar i;\n\n\t\tif (segs.length) {\n\n\t\t\t// build a large concatenation of segment HTML\n\t\t\tfor (i = 0; i < segs.length; i++) {\n\t\t\t\thtml += this.fillSegHtml(type, segs[i]);\n\t\t\t}\n\n\t\t\t// Grab individual elements from the combined HTML string. Use each as the default rendering.\n\t\t\t// Then, compute the 'el' for each segment.\n\t\t\t$(html).each(function(i, node) {\n\t\t\t\tvar seg = segs[i];\n\t\t\t\tvar el = $(node);\n\n\t\t\t\t// allow custom filter methods per-type\n\t\t\t\tif (segElMethod) {\n\t\t\t\t\tel = segElMethod.call(_this, seg, el);\n\t\t\t\t}\n\n\t\t\t\tif (el) { // custom filters did not cancel the render\n\t\t\t\t\tel = $(el); // allow custom filter to return raw DOM node\n\n\t\t\t\t\t// correct element type? (would be bad if a non-TD were inserted into a table for example)\n\t\t\t\t\tif (el.is(_this.fillSegTag)) {\n\t\t\t\t\t\tseg.el = el;\n\t\t\t\t\t\trenderedSegs.push(seg);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\treturn renderedSegs;\n\t},\n\n\n\tfillSegTag: 'div', // subclasses can override\n\n\n\t// Builds the HTML needed for one fill segment. Generic enought o work with different types.\n\tfillSegHtml: function(type, seg) {\n\n\t\t// custom hooks per-type\n\t\tvar classesMethod = this[type + 'SegClasses'];\n\t\tvar cssMethod = this[type + 'SegCss'];\n\n\t\tvar classes = classesMethod ? classesMethod.call(this, seg) : [];\n\t\tvar css = cssToStr(cssMethod ? cssMethod.call(this, seg) : {});\n\n\t\treturn '<' + this.fillSegTag +\n\t\t\t(classes.length ? ' class=\"' + classes.join(' ') + '\"' : '') +\n\t\t\t(css ? ' style=\"' + css + '\"' : '') +\n\t\t\t' />';\n\t},\n\n\n\t/* Generic rendering utilities for subclasses\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Renders a day-of-week header row.\n\t// TODO: move to another class. not applicable to all Grids\n\theadHtml: function() {\n\t\treturn '' +\n\t\t\t'' +\n\t\t\t\t' ' +\n\t\t\t\t\t'' +\n\t\t\t\t\t\tthis.rowHtml('head') + // leverages RowRenderer\n\t\t\t\t\t'' +\n\t\t\t\t' ' +\n\t\t\t' ';\n\t},\n\n\n\t// Used by the `headHtml` method, via RowRenderer, for rendering the HTML of a day-of-week header cell\n\t// TODO: move to another class. not applicable to all Grids\n\theadCellHtml: function(cell) {\n\t\tvar view = this.view;\n\t\tvar date = cell.start;\n\n\t\treturn '' +\n\t\t\t'';\n\t},\n\n\n\t// Renders the HTML for a single-day background cell\n\tbgCellHtml: function(cell) {\n\t\tvar view = this.view;\n\t\tvar date = cell.start;\n\t\tvar classes = this.getDayClasses(date);\n\n\t\tclasses.unshift('fc-day', view.widgetContentClass);\n\n\t\treturn ' | ';\n\t},\n\n\n\t// Computes HTML classNames for a single-day cell\n\tgetDayClasses: function(date) {\n\t\tvar view = this.view;\n\t\tvar today = view.calendar.getNow().stripTime();\n\t\tvar classes = [ 'fc-' + dayIDs[date.day()] ];\n\n\t\tif (\n\t\t\tview.intervalDuration.as('months') == 1 &&\n\t\t\tdate.month() != view.intervalStart.month()\n\t\t) {\n\t\t\tclasses.push('fc-other-month');\n\t\t}\n\n\t\tif (date.isSame(today, 'day')) {\n\t\t\tclasses.push(\n\t\t\t\t'fc-today',\n\t\t\t\tview.highlightStateClass\n\t\t\t);\n\t\t}\n\t\telse if (date < today) {\n\t\t\tclasses.push('fc-past');\n\t\t}\n\t\telse {\n\t\t\tclasses.push('fc-future');\n\t\t}\n\n\t\treturn classes;\n\t}\n\n});\n\n;;\n\n/* Event-rendering and event-interaction methods for the abstract Grid class\n----------------------------------------------------------------------------------------------------------------------*/\n\nGrid.mixin({\n\n\tmousedOverSeg: null, // the segment object the user's mouse is over. null if over nothing\n\tisDraggingSeg: false, // is a segment being dragged? boolean\n\tisResizingSeg: false, // is a segment being resized? boolean\n\tisDraggingExternal: false, // jqui-dragging an external element? boolean\n\tsegs: null, // the event segments currently rendered in the grid\n\n\n\t// Renders the given events onto the grid\n\trenderEvents: function(events) {\n\t\tvar segs = this.eventsToSegs(events);\n\t\tvar bgSegs = [];\n\t\tvar fgSegs = [];\n\t\tvar i, seg;\n\n\t\tfor (i = 0; i < segs.length; i++) {\n\t\t\tseg = segs[i];\n\n\t\t\tif (isBgEvent(seg.event)) {\n\t\t\t\tbgSegs.push(seg);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfgSegs.push(seg);\n\t\t\t}\n\t\t}\n\n\t\t// Render each different type of segment.\n\t\t// Each function may return a subset of the segs, segs that were actually rendered.\n\t\tbgSegs = this.renderBgSegs(bgSegs) || bgSegs;\n\t\tfgSegs = this.renderFgSegs(fgSegs) || fgSegs;\n\n\t\tthis.segs = bgSegs.concat(fgSegs);\n\t},\n\n\n\t// Unrenders all events currently rendered on the grid\n\tdestroyEvents: function() {\n\t\tthis.triggerSegMouseout(); // trigger an eventMouseout if user's mouse is over an event\n\n\t\tthis.destroyFgSegs();\n\t\tthis.destroyBgSegs();\n\n\t\tthis.segs = null;\n\t},\n\n\n\t// Retrieves all rendered segment objects currently rendered on the grid\n\tgetEventSegs: function() {\n\t\treturn this.segs || [];\n\t},\n\n\n\t/* Foreground Segment Rendering\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Renders foreground event segments onto the grid. May return a subset of segs that were rendered.\n\trenderFgSegs: function(segs) {\n\t\t// subclasses must implement\n\t},\n\n\n\t// Unrenders all currently rendered foreground segments\n\tdestroyFgSegs: function() {\n\t\t// subclasses must implement\n\t},\n\n\n\t// Renders and assigns an `el` property for each foreground event segment.\n\t// Only returns segments that successfully rendered.\n\t// A utility that subclasses may use.\n\trenderFgSegEls: function(segs, disableResizing) {\n\t\tvar view = this.view;\n\t\tvar html = '';\n\t\tvar renderedSegs = [];\n\t\tvar i;\n\n\t\tif (segs.length) { // don't build an empty html string\n\n\t\t\t// build a large concatenation of event segment HTML\n\t\t\tfor (i = 0; i < segs.length; i++) {\n\t\t\t\thtml += this.fgSegHtml(segs[i], disableResizing);\n\t\t\t}\n\n\t\t\t// Grab individual elements from the combined HTML string. Use each as the default rendering.\n\t\t\t// Then, compute the 'el' for each segment. An el might be null if the eventRender callback returned false.\n\t\t\t$(html).each(function(i, node) {\n\t\t\t\tvar seg = segs[i];\n\t\t\t\tvar el = view.resolveEventEl(seg.event, $(node));\n\n\t\t\t\tif (el) {\n\t\t\t\t\tel.data('fc-seg', seg); // used by handlers\n\t\t\t\t\tseg.el = el;\n\t\t\t\t\trenderedSegs.push(seg);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\treturn renderedSegs;\n\t},\n\n\n\t// Generates the HTML for the default rendering of a foreground event segment. Used by renderFgSegEls()\n\tfgSegHtml: function(seg, disableResizing) {\n\t\t// subclasses should implement\n\t},\n\n\n\t/* Background Segment Rendering\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Renders the given background event segments onto the grid.\n\t// Returns a subset of the segs that were actually rendered.\n\trenderBgSegs: function(segs) {\n\t\treturn this.renderFill('bgEvent', segs);\n\t},\n\n\n\t// Unrenders all the currently rendered background event segments\n\tdestroyBgSegs: function() {\n\t\tthis.destroyFill('bgEvent');\n\t},\n\n\n\t// Renders a background event element, given the default rendering. Called by the fill system.\n\tbgEventSegEl: function(seg, el) {\n\t\treturn this.view.resolveEventEl(seg.event, el); // will filter through eventRender\n\t},\n\n\n\t// Generates an array of classNames to be used for the default rendering of a background event.\n\t// Called by the fill system.\n\tbgEventSegClasses: function(seg) {\n\t\tvar event = seg.event;\n\t\tvar source = event.source || {};\n\n\t\treturn [ 'fc-bgevent' ].concat(\n\t\t\tevent.className,\n\t\t\tsource.className || []\n\t\t);\n\t},\n\n\n\t// Generates a semicolon-separated CSS string to be used for the default rendering of a background event.\n\t// Called by the fill system.\n\t// TODO: consolidate with getEventSkinCss?\n\tbgEventSegCss: function(seg) {\n\t\tvar view = this.view;\n\t\tvar event = seg.event;\n\t\tvar source = event.source || {};\n\n\t\treturn {\n\t\t\t'background-color':\n\t\t\t\tevent.backgroundColor ||\n\t\t\t\tevent.color ||\n\t\t\t\tsource.backgroundColor ||\n\t\t\t\tsource.color ||\n\t\t\t\tview.opt('eventBackgroundColor') ||\n\t\t\t\tview.opt('eventColor')\n\t\t};\n\t},\n\n\n\t// Generates an array of classNames to be used for the rendering business hours overlay. Called by the fill system.\n\tbusinessHoursSegClasses: function(seg) {\n\t\treturn [ 'fc-nonbusiness', 'fc-bgevent' ];\n\t},\n\n\n\t/* Handlers\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Attaches event-element-related handlers to the container element and leverage bubbling\n\tbindSegHandlers: function() {\n\t\tvar _this = this;\n\t\tvar view = this.view;\n\n\t\t$.each(\n\t\t\t{\n\t\t\t\tmouseenter: function(seg, ev) {\n\t\t\t\t\t_this.triggerSegMouseover(seg, ev);\n\t\t\t\t},\n\t\t\t\tmouseleave: function(seg, ev) {\n\t\t\t\t\t_this.triggerSegMouseout(seg, ev);\n\t\t\t\t},\n\t\t\t\tclick: function(seg, ev) {\n\t\t\t\t\treturn view.trigger('eventClick', this, seg.event, ev); // can return `false` to cancel\n\t\t\t\t},\n\t\t\t\tmousedown: function(seg, ev) {\n\t\t\t\t\tif ($(ev.target).is('.fc-resizer') && view.isEventResizable(seg.event)) {\n\t\t\t\t\t\t_this.segResizeMousedown(seg, ev, $(ev.target).is('.fc-start-resizer'));\n\t\t\t\t\t}\n\t\t\t\t\telse if (view.isEventDraggable(seg.event)) {\n\t\t\t\t\t\t_this.segDragMousedown(seg, ev);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tfunction(name, func) {\n\t\t\t\t// attach the handler to the container element and only listen for real event elements via bubbling\n\t\t\t\t_this.el.on(name, '.fc-event-container > *', function(ev) {\n\t\t\t\t\tvar seg = $(this).data('fc-seg'); // grab segment data. put there by View::renderEvents\n\n\t\t\t\t\t// only call the handlers if there is not a drag/resize in progress\n\t\t\t\t\tif (seg && !_this.isDraggingSeg && !_this.isResizingSeg) {\n\t\t\t\t\t\treturn func.call(this, seg, ev); // `this` will be the event element\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t);\n\t},\n\n\n\t// Updates internal state and triggers handlers for when an event element is moused over\n\ttriggerSegMouseover: function(seg, ev) {\n\t\tif (!this.mousedOverSeg) {\n\t\t\tthis.mousedOverSeg = seg;\n\t\t\tthis.view.trigger('eventMouseover', seg.el[0], seg.event, ev);\n\t\t}\n\t},\n\n\n\t// Updates internal state and triggers handlers for when an event element is moused out.\n\t// Can be given no arguments, in which case it will mouseout the segment that was previously moused over.\n\ttriggerSegMouseout: function(seg, ev) {\n\t\tev = ev || {}; // if given no args, make a mock mouse event\n\n\t\tif (this.mousedOverSeg) {\n\t\t\tseg = seg || this.mousedOverSeg; // if given no args, use the currently moused-over segment\n\t\t\tthis.mousedOverSeg = null;\n\t\t\tthis.view.trigger('eventMouseout', seg.el[0], seg.event, ev);\n\t\t}\n\t},\n\n\n\t/* Event Dragging\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Called when the user does a mousedown on an event, which might lead to dragging.\n\t// Generic enough to work with any type of Grid.\n\tsegDragMousedown: function(seg, ev) {\n\t\tvar _this = this;\n\t\tvar view = this.view;\n\t\tvar calendar = view.calendar;\n\t\tvar el = seg.el;\n\t\tvar event = seg.event;\n\t\tvar dropLocation;\n\n\t\t// A clone of the original element that will move with the mouse\n\t\tvar mouseFollower = new MouseFollower(seg.el, {\n\t\t\tparentEl: view.el,\n\t\t\topacity: view.opt('dragOpacity'),\n\t\t\trevertDuration: view.opt('dragRevertDuration'),\n\t\t\tzIndex: 2 // one above the .fc-view\n\t\t});\n\n\t\t// Tracks mouse movement over the *view's* coordinate map. Allows dragging and dropping between subcomponents\n\t\t// of the view.\n\t\tvar dragListener = new CellDragListener(view.coordMap, {\n\t\t\tdistance: 5,\n\t\t\tscroll: view.opt('dragScroll'),\n\t\t\tsubjectEl: el,\n\t\t\tsubjectCenter: true,\n\t\t\tlistenStart: function(ev) {\n\t\t\t\tmouseFollower.hide(); // don't show until we know this is a real drag\n\t\t\t\tmouseFollower.start(ev);\n\t\t\t},\n\t\t\tdragStart: function(ev) {\n\t\t\t\t_this.triggerSegMouseout(seg, ev); // ensure a mouseout on the manipulated event has been reported\n\t\t\t\t_this.segDragStart(seg, ev);\n\t\t\t\tview.hideEvent(event); // hide all event segments. our mouseFollower will take over\n\t\t\t},\n\t\t\tcellOver: function(cell, isOrig, origCell) {\n\n\t\t\t\t// starting cell could be forced (DayGrid.limit)\n\t\t\t\tif (seg.cell) {\n\t\t\t\t\torigCell = seg.cell;\n\t\t\t\t}\n\n\t\t\t\tdropLocation = _this.computeEventDrop(origCell, cell, event);\n\n\t\t\t\tif (dropLocation && !calendar.isEventRangeAllowed(dropLocation, event)) {\n\t\t\t\t\tdisableCursor();\n\t\t\t\t\tdropLocation = null;\n\t\t\t\t}\n\n\t\t\t\t// if a valid drop location, have the subclass render a visual indication\n\t\t\t\tif (dropLocation && view.renderDrag(dropLocation, seg)) {\n\t\t\t\t\tmouseFollower.hide(); // if the subclass is already using a mock event \"helper\", hide our own\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tmouseFollower.show(); // otherwise, have the helper follow the mouse (no snapping)\n\t\t\t\t}\n\n\t\t\t\tif (isOrig) {\n\t\t\t\t\tdropLocation = null; // needs to have moved cells to be a valid drop\n\t\t\t\t}\n\t\t\t},\n\t\t\tcellOut: function() { // called before mouse moves to a different cell OR moved out of all cells\n\t\t\t\tview.destroyDrag(); // unrender whatever was done in renderDrag\n\t\t\t\tmouseFollower.show(); // show in case we are moving out of all cells\n\t\t\t\tdropLocation = null;\n\t\t\t},\n\t\t\tcellDone: function() { // Called after a cellOut OR before a dragStop\n\t\t\t\tenableCursor();\n\t\t\t},\n\t\t\tdragStop: function(ev) {\n\t\t\t\t// do revert animation if hasn't changed. calls a callback when finished (whether animation or not)\n\t\t\t\tmouseFollower.stop(!dropLocation, function() {\n\t\t\t\t\tview.destroyDrag();\n\t\t\t\t\tview.showEvent(event);\n\t\t\t\t\t_this.segDragStop(seg, ev);\n\n\t\t\t\t\tif (dropLocation) {\n\t\t\t\t\t\tview.reportEventDrop(event, dropLocation, this.largeUnit, el, ev);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t},\n\t\t\tlistenStop: function() {\n\t\t\t\tmouseFollower.stop(); // put in listenStop in case there was a mousedown but the drag never started\n\t\t\t}\n\t\t});\n\n\t\tdragListener.mousedown(ev); // start listening, which will eventually lead to a dragStart\n\t},\n\n\n\t// Called before event segment dragging starts\n\tsegDragStart: function(seg, ev) {\n\t\tthis.isDraggingSeg = true;\n\t\tthis.view.trigger('eventDragStart', seg.el[0], seg.event, ev, {}); // last argument is jqui dummy\n\t},\n\n\n\t// Called after event segment dragging stops\n\tsegDragStop: function(seg, ev) {\n\t\tthis.isDraggingSeg = false;\n\t\tthis.view.trigger('eventDragStop', seg.el[0], seg.event, ev, {}); // last argument is jqui dummy\n\t},\n\n\n\t// Given the cell an event drag began, and the cell event was dropped, calculates the new start/end/allDay\n\t// values for the event. Subclasses may override and set additional properties to be used by renderDrag.\n\t// A falsy returned value indicates an invalid drop.\n\tcomputeEventDrop: function(startCell, endCell, event) {\n\t\tvar calendar = this.view.calendar;\n\t\tvar dragStart = startCell.start;\n\t\tvar dragEnd = endCell.start;\n\t\tvar delta;\n\t\tvar dropLocation;\n\n\t\tif (dragStart.hasTime() === dragEnd.hasTime()) {\n\t\t\tdelta = this.diffDates(dragEnd, dragStart);\n\n\t\t\t// if an all-day event was in a timed area and it was dragged to a different time,\n\t\t\t// guarantee an end and adjust start/end to have times\n\t\t\tif (event.allDay && durationHasTime(delta)) {\n\t\t\t\tdropLocation = {\n\t\t\t\t\tstart: event.start.clone(),\n\t\t\t\t\tend: calendar.getEventEnd(event), // will be an ambig day\n\t\t\t\t\tallDay: false // for normalizeEventRangeTimes\n\t\t\t\t};\n\t\t\t\tcalendar.normalizeEventRangeTimes(dropLocation);\n\t\t\t}\n\t\t\t// othewise, work off existing values\n\t\t\telse {\n\t\t\t\tdropLocation = {\n\t\t\t\t\tstart: event.start.clone(),\n\t\t\t\t\tend: event.end ? event.end.clone() : null,\n\t\t\t\t\tallDay: event.allDay // keep it the same\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tdropLocation.start.add(delta);\n\t\t\tif (dropLocation.end) {\n\t\t\t\tdropLocation.end.add(delta);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t// if switching from day <-> timed, start should be reset to the dropped date, and the end cleared\n\t\t\tdropLocation = {\n\t\t\t\tstart: dragEnd.clone(),\n\t\t\t\tend: null, // end should be cleared\n\t\t\t\tallDay: !dragEnd.hasTime()\n\t\t\t};\n\t\t}\n\n\t\treturn dropLocation;\n\t},\n\n\n\t// Utility for apply dragOpacity to a jQuery set\n\tapplyDragOpacity: function(els) {\n\t\tvar opacity = this.view.opt('dragOpacity');\n\n\t\tif (opacity != null) {\n\t\t\tels.each(function(i, node) {\n\t\t\t\t// Don't use jQuery (will set an IE filter), do it the old fashioned way.\n\t\t\t\t// In IE8, a helper element will disappears if there's a filter.\n\t\t\t\tnode.style.opacity = opacity;\n\t\t\t});\n\t\t}\n\t},\n\n\n\t/* External Element Dragging\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Called when a jQuery UI drag is initiated anywhere in the DOM\n\texternalDragStart: function(ev, ui) {\n\t\tvar view = this.view;\n\t\tvar el;\n\t\tvar accept;\n\n\t\tif (view.opt('droppable')) { // only listen if this setting is on\n\t\t\tel = $((ui ? ui.item : null) || ev.target);\n\n\t\t\t// Test that the dragged element passes the dropAccept selector or filter function.\n\t\t\t// FYI, the default is \"*\" (matches all)\n\t\t\taccept = view.opt('dropAccept');\n\t\t\tif ($.isFunction(accept) ? accept.call(el[0], el) : el.is(accept)) {\n\t\t\t\tif (!this.isDraggingExternal) { // prevent double-listening if fired twice\n\t\t\t\t\tthis.listenToExternalDrag(el, ev, ui);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\n\n\t// Called when a jQuery UI drag starts and it needs to be monitored for cell dropping\n\tlistenToExternalDrag: function(el, ev, ui) {\n\t\tvar _this = this;\n\t\tvar meta = getDraggedElMeta(el); // extra data about event drop, including possible event to create\n\t\tvar dragListener;\n\t\tvar dropLocation; // a null value signals an unsuccessful drag\n\n\t\t// listener that tracks mouse movement over date-associated pixel regions\n\t\tdragListener = new CellDragListener(this.coordMap, {\n\t\t\tlistenStart: function() {\n\t\t\t\t_this.isDraggingExternal = true;\n\t\t\t},\n\t\t\tcellOver: function(cell) {\n\t\t\t\tdropLocation = _this.computeExternalDrop(cell, meta);\n\t\t\t\tif (dropLocation) {\n\t\t\t\t\t_this.renderDrag(dropLocation); // called without a seg parameter\n\t\t\t\t}\n\t\t\t\telse { // invalid drop cell\n\t\t\t\t\tdisableCursor();\n\t\t\t\t}\n\t\t\t},\n\t\t\tcellOut: function() {\n\t\t\t\tdropLocation = null; // signal unsuccessful\n\t\t\t\t_this.destroyDrag();\n\t\t\t\tenableCursor();\n\t\t\t},\n\t\t\tdragStop: function() {\n\t\t\t\t_this.destroyDrag();\n\t\t\t\tenableCursor();\n\n\t\t\t\tif (dropLocation) { // element was dropped on a valid date/time cell\n\t\t\t\t\t_this.view.reportExternalDrop(meta, dropLocation, el, ev, ui);\n\t\t\t\t}\n\t\t\t},\n\t\t\tlistenStop: function() {\n\t\t\t\t_this.isDraggingExternal = false;\n\t\t\t}\n\t\t});\n\n\t\tdragListener.startDrag(ev); // start listening immediately\n\t},\n\n\n\t// Given a cell to be dropped upon, and misc data associated with the jqui drag (guaranteed to be a plain object),\n\t// returns start/end dates for the event that would result from the hypothetical drop. end might be null.\n\t// Returning a null value signals an invalid drop cell.\n\tcomputeExternalDrop: function(cell, meta) {\n\t\tvar dropLocation = {\n\t\t\tstart: cell.start.clone(),\n\t\t\tend: null\n\t\t};\n\n\t\t// if dropped on an all-day cell, and element's metadata specified a time, set it\n\t\tif (meta.startTime && !dropLocation.start.hasTime()) {\n\t\t\tdropLocation.start.time(meta.startTime);\n\t\t}\n\n\t\tif (meta.duration) {\n\t\t\tdropLocation.end = dropLocation.start.clone().add(meta.duration);\n\t\t}\n\n\t\tif (!this.view.calendar.isExternalDropRangeAllowed(dropLocation, meta.eventProps)) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn dropLocation;\n\t},\n\n\n\n\t/* Drag Rendering (for both events and an external elements)\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Renders a visual indication of an event or external element being dragged.\n\t// `dropLocation` contains hypothetical start/end/allDay values the event would have if dropped. end can be null.\n\t// `seg` is the internal segment object that is being dragged. If dragging an external element, `seg` is null.\n\t// A truthy returned value indicates this method has rendered a helper element.\n\trenderDrag: function(dropLocation, seg) {\n\t\t// subclasses must implement\n\t},\n\n\n\t// Unrenders a visual indication of an event or external element being dragged\n\tdestroyDrag: function() {\n\t\t// subclasses must implement\n\t},\n\n\n\t/* Resizing\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Called when the user does a mousedown on an event's resizer, which might lead to resizing.\n\t// Generic enough to work with any type of Grid.\n\tsegResizeMousedown: function(seg, ev, isStart) {\n\t\tvar _this = this;\n\t\tvar view = this.view;\n\t\tvar calendar = view.calendar;\n\t\tvar el = seg.el;\n\t\tvar event = seg.event;\n\t\tvar eventEnd = calendar.getEventEnd(event);\n\t\tvar dragListener;\n\t\tvar resizeLocation; // falsy if invalid resize\n\n\t\t// Tracks mouse movement over the *grid's* coordinate map\n\t\tdragListener = new CellDragListener(this.coordMap, {\n\t\t\tdistance: 5,\n\t\t\tscroll: view.opt('dragScroll'),\n\t\t\tsubjectEl: el,\n\t\t\tdragStart: function(ev) {\n\t\t\t\t_this.triggerSegMouseout(seg, ev); // ensure a mouseout on the manipulated event has been reported\n\t\t\t\t_this.segResizeStart(seg, ev);\n\t\t\t},\n\t\t\tcellOver: function(cell, isOrig, origCell) {\n\t\t\t\tresizeLocation = isStart ?\n\t\t\t\t\t_this.computeEventStartResize(origCell, cell, event) :\n\t\t\t\t\t_this.computeEventEndResize(origCell, cell, event);\n\n\t\t\t\tif (resizeLocation) {\n\t\t\t\t\tif (!calendar.isEventRangeAllowed(resizeLocation, event)) {\n\t\t\t\t\t\tdisableCursor();\n\t\t\t\t\t\tresizeLocation = null;\n\t\t\t\t\t}\n\t\t\t\t\t// no change? (TODO: how does this work with timezones?)\n\t\t\t\t\telse if (resizeLocation.start.isSame(event.start) && resizeLocation.end.isSame(eventEnd)) {\n\t\t\t\t\t\tresizeLocation = null;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (resizeLocation) {\n\t\t\t\t\tview.hideEvent(event);\n\t\t\t\t\t_this.renderEventResize(resizeLocation, seg);\n\t\t\t\t}\n\t\t\t},\n\t\t\tcellOut: function() { // called before mouse moves to a different cell OR moved out of all cells\n\t\t\t\tresizeLocation = null;\n\t\t\t},\n\t\t\tcellDone: function() { // resets the rendering to show the original event\n\t\t\t\t_this.destroyEventResize();\n\t\t\t\tview.showEvent(event);\n\t\t\t\tenableCursor();\n\t\t\t},\n\t\t\tdragStop: function(ev) {\n\t\t\t\t_this.segResizeStop(seg, ev);\n\n\t\t\t\tif (resizeLocation) { // valid date to resize to?\n\t\t\t\t\tview.reportEventResize(event, resizeLocation, this.largeUnit, el, ev);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tdragListener.mousedown(ev); // start listening, which will eventually lead to a dragStart\n\t},\n\n\n\t// Called before event segment resizing starts\n\tsegResizeStart: function(seg, ev) {\n\t\tthis.isResizingSeg = true;\n\t\tthis.view.trigger('eventResizeStart', seg.el[0], seg.event, ev, {}); // last argument is jqui dummy\n\t},\n\n\n\t// Called after event segment resizing stops\n\tsegResizeStop: function(seg, ev) {\n\t\tthis.isResizingSeg = false;\n\t\tthis.view.trigger('eventResizeStop', seg.el[0], seg.event, ev, {}); // last argument is jqui dummy\n\t},\n\n\n\t// Returns new date-information for an event segment being resized from its start\n\tcomputeEventStartResize: function(startCell, endCell, event) {\n\t\treturn this.computeEventResize('start', startCell, endCell, event);\n\t},\n\n\n\t// Returns new date-information for an event segment being resized from its end\n\tcomputeEventEndResize: function(startCell, endCell, event) {\n\t\treturn this.computeEventResize('end', startCell, endCell, event);\n\t},\n\n\n\t// Returns new date-information for an event segment being resized from its start OR end\n\t// `type` is either 'start' or 'end'\n\tcomputeEventResize: function(type, startCell, endCell, event) {\n\t\tvar calendar = this.view.calendar;\n\t\tvar delta = this.diffDates(endCell[type], startCell[type]);\n\t\tvar range;\n\t\tvar defaultDuration;\n\n\t\t// build original values to work from, guaranteeing a start and end\n\t\trange = {\n\t\t\tstart: event.start.clone(),\n\t\t\tend: calendar.getEventEnd(event),\n\t\t\tallDay: event.allDay\n\t\t};\n\n\t\t// if an all-day event was in a timed area and was resized to a time, adjust start/end to have times\n\t\tif (range.allDay && durationHasTime(delta)) {\n\t\t\trange.allDay = false;\n\t\t\tcalendar.normalizeEventRangeTimes(range);\n\t\t}\n\n\t\trange[type].add(delta); // apply delta to start or end\n\n\t\t// if the event was compressed too small, find a new reasonable duration for it\n\t\tif (!range.start.isBefore(range.end)) {\n\n\t\t\tdefaultDuration = event.allDay ?\n\t\t\t\tcalendar.defaultAllDayEventDuration :\n\t\t\t\tcalendar.defaultTimedEventDuration;\n\n\t\t\t// between the cell's duration and the event's default duration, use the smaller of the two.\n\t\t\t// example: if year-length slots, and compressed to one slot, we don't want the event to be a year long\n\t\t\tif (this.cellDuration && this.cellDuration < defaultDuration) {\n\t\t\t\tdefaultDuration = this.cellDuration;\n\t\t\t}\n\n\t\t\tif (type == 'start') { // resizing the start?\n\t\t\t\trange.start = range.end.clone().subtract(defaultDuration);\n\t\t\t}\n\t\t\telse { // resizing the end?\n\t\t\t\trange.end = range.start.clone().add(defaultDuration);\n\t\t\t}\n\t\t}\n\n\t\treturn range;\n\t},\n\n\n\t// Renders a visual indication of an event being resized.\n\t// `range` has the updated dates of the event. `seg` is the original segment object involved in the drag.\n\trenderEventResize: function(range, seg) {\n\t\t// subclasses must implement\n\t},\n\n\n\t// Unrenders a visual indication of an event being resized.\n\tdestroyEventResize: function() {\n\t\t// subclasses must implement\n\t},\n\n\n\t/* Rendering Utils\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Compute the text that should be displayed on an event's element.\n\t// `range` can be the Event object itself, or something range-like, with at least a `start`.\n\t// If event times are disabled, or the event has no time, will return a blank string.\n\t// If not specified, formatStr will default to the eventTimeFormat setting,\n\t// and displayEnd will default to the displayEventEnd setting.\n\tgetEventTimeText: function(range, formatStr, displayEnd) {\n\n\t\tif (formatStr == null) {\n\t\t\tformatStr = this.eventTimeFormat;\n\t\t}\n\n\t\tif (displayEnd == null) {\n\t\t\tdisplayEnd = this.displayEventEnd;\n\t\t}\n\n\t\tif (this.displayEventTime && range.start.hasTime()) {\n\t\t\tif (displayEnd && range.end) {\n\t\t\t\treturn this.view.formatRange(range, formatStr);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn range.start.format(formatStr);\n\t\t\t}\n\t\t}\n\n\t\treturn '';\n\t},\n\n\n\t// Generic utility for generating the HTML classNames for an event segment's element\n\tgetSegClasses: function(seg, isDraggable, isResizable) {\n\t\tvar event = seg.event;\n\t\tvar classes = [\n\t\t\t'fc-event',\n\t\t\tseg.isStart ? 'fc-start' : 'fc-not-start',\n\t\t\tseg.isEnd ? 'fc-end' : 'fc-not-end'\n\t\t].concat(\n\t\t\tevent.className,\n\t\t\tevent.source ? event.source.className : []\n\t\t);\n\n\t\tif (isDraggable) {\n\t\t\tclasses.push('fc-draggable');\n\t\t}\n\t\tif (isResizable) {\n\t\t\tclasses.push('fc-resizable');\n\t\t}\n\n\t\treturn classes;\n\t},\n\n\n\t// Utility for generating event skin-related CSS properties\n\tgetEventSkinCss: function(event) {\n\t\tvar view = this.view;\n\t\tvar source = event.source || {};\n\t\tvar eventColor = event.color;\n\t\tvar sourceColor = source.color;\n\t\tvar optionColor = view.opt('eventColor');\n\n\t\treturn {\n\t\t\t'background-color':\n\t\t\t\tevent.backgroundColor ||\n\t\t\t\teventColor ||\n\t\t\t\tsource.backgroundColor ||\n\t\t\t\tsourceColor ||\n\t\t\t\tview.opt('eventBackgroundColor') ||\n\t\t\t\toptionColor,\n\t\t\t'border-color':\n\t\t\t\tevent.borderColor ||\n\t\t\t\teventColor ||\n\t\t\t\tsource.borderColor ||\n\t\t\t\tsourceColor ||\n\t\t\t\tview.opt('eventBorderColor') ||\n\t\t\t\toptionColor,\n\t\t\tcolor:\n\t\t\t\tevent.textColor ||\n\t\t\t\tsource.textColor ||\n\t\t\t\tview.opt('eventTextColor')\n\t\t};\n\t},\n\n\n\t/* Converting events -> ranges -> segs\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Converts an array of event objects into an array of event segment objects.\n\t// A custom `rangeToSegsFunc` may be given for arbitrarily slicing up events.\n\t// Doesn't guarantee an order for the resulting array.\n\teventsToSegs: function(events, rangeToSegsFunc) {\n\t\tvar eventRanges = this.eventsToRanges(events);\n\t\tvar segs = [];\n\t\tvar i;\n\n\t\tfor (i = 0; i < eventRanges.length; i++) {\n\t\t\tsegs.push.apply(\n\t\t\t\tsegs,\n\t\t\t\tthis.eventRangeToSegs(eventRanges[i], rangeToSegsFunc)\n\t\t\t);\n\t\t}\n\n\t\treturn segs;\n\t},\n\n\n\t// Converts an array of events into an array of \"range\" objects.\n\t// A \"range\" object is a plain object with start/end properties denoting the time it covers. Also an event property.\n\t// For \"normal\" events, this will be identical to the event's start/end, but for \"inverse-background\" events,\n\t// will create an array of ranges that span the time *not* covered by the given event.\n\t// Doesn't guarantee an order for the resulting array.\n\teventsToRanges: function(events) {\n\t\tvar _this = this;\n\t\tvar eventsById = groupEventsById(events);\n\t\tvar ranges = [];\n\n\t\t// group by ID so that related inverse-background events can be rendered together\n\t\t$.each(eventsById, function(id, eventGroup) {\n\t\t\tif (eventGroup.length) {\n\t\t\t\tranges.push.apply(\n\t\t\t\t\tranges,\n\t\t\t\t\tisInverseBgEvent(eventGroup[0]) ?\n\t\t\t\t\t\t_this.eventsToInverseRanges(eventGroup) :\n\t\t\t\t\t\t_this.eventsToNormalRanges(eventGroup)\n\t\t\t\t);\n\t\t\t}\n\t\t});\n\n\t\treturn ranges;\n\t},\n\n\n\t// Converts an array of \"normal\" events (not inverted rendering) into a parallel array of ranges\n\teventsToNormalRanges: function(events) {\n\t\tvar calendar = this.view.calendar;\n\t\tvar ranges = [];\n\t\tvar i, event;\n\t\tvar eventStart, eventEnd;\n\n\t\tfor (i = 0; i < events.length; i++) {\n\t\t\tevent = events[i];\n\n\t\t\t// make copies and normalize by stripping timezone\n\t\t\teventStart = event.start.clone().stripZone();\n\t\t\teventEnd = calendar.getEventEnd(event).stripZone();\n\n\t\t\tranges.push({\n\t\t\t\tevent: event,\n\t\t\t\tstart: eventStart,\n\t\t\t\tend: eventEnd,\n\t\t\t\teventStartMS: +eventStart,\n\t\t\t\teventDurationMS: eventEnd - eventStart\n\t\t\t});\n\t\t}\n\n\t\treturn ranges;\n\t},\n\n\n\t// Converts an array of events, with inverse-background rendering, into an array of range objects.\n\t// The range objects will cover all the time NOT covered by the events.\n\teventsToInverseRanges: function(events) {\n\t\tvar view = this.view;\n\t\tvar viewStart = view.start.clone().stripZone(); // normalize timezone\n\t\tvar viewEnd = view.end.clone().stripZone(); // normalize timezone\n\t\tvar normalRanges = this.eventsToNormalRanges(events); // will give us normalized dates we can use w/o copies\n\t\tvar inverseRanges = [];\n\t\tvar event0 = events[0]; // assign this to each range's `.event`\n\t\tvar start = viewStart; // the end of the previous range. the start of the new range\n\t\tvar i, normalRange;\n\n\t\t// ranges need to be in order. required for our date-walking algorithm\n\t\tnormalRanges.sort(compareNormalRanges);\n\n\t\tfor (i = 0; i < normalRanges.length; i++) {\n\t\t\tnormalRange = normalRanges[i];\n\n\t\t\t// add the span of time before the event (if there is any)\n\t\t\tif (normalRange.start > start) { // compare millisecond time (skip any ambig logic)\n\t\t\t\tinverseRanges.push({\n\t\t\t\t\tevent: event0,\n\t\t\t\t\tstart: start,\n\t\t\t\t\tend: normalRange.start\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tstart = normalRange.end;\n\t\t}\n\n\t\t// add the span of time after the last event (if there is any)\n\t\tif (start < viewEnd) { // compare millisecond time (skip any ambig logic)\n\t\t\tinverseRanges.push({\n\t\t\t\tevent: event0,\n\t\t\t\tstart: start,\n\t\t\t\tend: viewEnd\n\t\t\t});\n\t\t}\n\n\t\treturn inverseRanges;\n\t},\n\n\n\t// Slices the given event range into one or more segment objects.\n\t// A `rangeToSegsFunc` custom slicing function can be given.\n\teventRangeToSegs: function(eventRange, rangeToSegsFunc) {\n\t\tvar segs;\n\t\tvar i, seg;\n\n\t\tif (rangeToSegsFunc) {\n\t\t\tsegs = rangeToSegsFunc(eventRange);\n\t\t}\n\t\telse {\n\t\t\tsegs = this.rangeToSegs(eventRange); // defined by the subclass\n\t\t}\n\n\t\tfor (i = 0; i < segs.length; i++) {\n\t\t\tseg = segs[i];\n\t\t\tseg.event = eventRange.event;\n\t\t\tseg.eventStartMS = eventRange.eventStartMS;\n\t\t\tseg.eventDurationMS = eventRange.eventDurationMS;\n\t\t}\n\n\t\treturn segs;\n\t}\n\n});\n\n\n/* Utilities\n----------------------------------------------------------------------------------------------------------------------*/\n\n\nfunction isBgEvent(event) { // returns true if background OR inverse-background\n\tvar rendering = getEventRendering(event);\n\treturn rendering === 'background' || rendering === 'inverse-background';\n}\n\n\nfunction isInverseBgEvent(event) {\n\treturn getEventRendering(event) === 'inverse-background';\n}\n\n\nfunction getEventRendering(event) {\n\treturn firstDefined((event.source || {}).rendering, event.rendering);\n}\n\n\nfunction groupEventsById(events) {\n\tvar eventsById = {};\n\tvar i, event;\n\n\tfor (i = 0; i < events.length; i++) {\n\t\tevent = events[i];\n\t\t(eventsById[event._id] || (eventsById[event._id] = [])).push(event);\n\t}\n\n\treturn eventsById;\n}\n\n\n// A cmp function for determining which non-inverted \"ranges\" (see above) happen earlier\nfunction compareNormalRanges(range1, range2) {\n\treturn range1.eventStartMS - range2.eventStartMS; // earlier ranges go first\n}\n\n\n// A cmp function for determining which segments should take visual priority\n// DOES NOT WORK ON INVERTED BACKGROUND EVENTS because they have no eventStartMS/eventDurationMS\nfunction compareSegs(seg1, seg2) {\n\treturn seg1.eventStartMS - seg2.eventStartMS || // earlier events go first\n\t\tseg2.eventDurationMS - seg1.eventDurationMS || // tie? longer events go first\n\t\tseg2.event.allDay - seg1.event.allDay || // tie? put all-day events first (booleans cast to 0/1)\n\t\t(seg1.event.title || '').localeCompare(seg2.event.title); // tie? alphabetically by title\n}\n\nfc.compareSegs = compareSegs; // export\n\n\n/* External-Dragging-Element Data\n----------------------------------------------------------------------------------------------------------------------*/\n\n// Require all HTML5 data-* attributes used by FullCalendar to have this prefix.\n// A value of '' will query attributes like data-event. A value of 'fc' will query attributes like data-fc-event.\nfc.dataAttrPrefix = '';\n\n// Given a jQuery element that might represent a dragged FullCalendar event, returns an intermediate data structure\n// to be used for Event Object creation.\n// A defined `.eventProps`, even when empty, indicates that an event should be created.\nfunction getDraggedElMeta(el) {\n\tvar prefix = fc.dataAttrPrefix;\n\tvar eventProps; // properties for creating the event, not related to date/time\n\tvar startTime; // a Duration\n\tvar duration;\n\tvar stick;\n\n\tif (prefix) { prefix += '-'; }\n\teventProps = el.data(prefix + 'event') || null;\n\n\tif (eventProps) {\n\t\tif (typeof eventProps === 'object') {\n\t\t\teventProps = $.extend({}, eventProps); // make a copy\n\t\t}\n\t\telse { // something like 1 or true. still signal event creation\n\t\t\teventProps = {};\n\t\t}\n\n\t\t// pluck special-cased date/time properties\n\t\tstartTime = eventProps.start;\n\t\tif (startTime == null) { startTime = eventProps.time; } // accept 'time' as well\n\t\tduration = eventProps.duration;\n\t\tstick = eventProps.stick;\n\t\tdelete eventProps.start;\n\t\tdelete eventProps.time;\n\t\tdelete eventProps.duration;\n\t\tdelete eventProps.stick;\n\t}\n\n\t// fallback to standalone attribute values for each of the date/time properties\n\tif (startTime == null) { startTime = el.data(prefix + 'start'); }\n\tif (startTime == null) { startTime = el.data(prefix + 'time'); } // accept 'time' as well\n\tif (duration == null) { duration = el.data(prefix + 'duration'); }\n\tif (stick == null) { stick = el.data(prefix + 'stick'); }\n\n\t// massage into correct data types\n\tstartTime = startTime != null ? moment.duration(startTime) : null;\n\tduration = duration != null ? moment.duration(duration) : null;\n\tstick = Boolean(stick);\n\n\treturn { eventProps: eventProps, startTime: startTime, duration: duration, stick: stick };\n}\n\n\n;;\n\n/* A component that renders a grid of whole-days that runs horizontally. There can be multiple rows, one per week.\n----------------------------------------------------------------------------------------------------------------------*/\n\nvar DayGrid = Grid.extend({\n\n\tnumbersVisible: false, // should render a row for day/week numbers? set by outside view. TODO: make internal\n\tbottomCoordPadding: 0, // hack for extending the hit area for the last row of the coordinate grid\n\tbreakOnWeeks: null, // should create a new row for each week? set by outside view\n\n\tcellDates: null, // flat chronological array of each cell's dates\n\tdayToCellOffsets: null, // maps days offsets from grid's start date, to cell offsets\n\n\trowEls: null, // set of fake row elements\n\tdayEls: null, // set of whole-day elements comprising the row's background\n\thelperEls: null, // set of cell skeleton elements for rendering the mock event \"helper\"\n\n\n\tconstructor: function() {\n\t\tGrid.apply(this, arguments);\n\n\t\tthis.cellDuration = moment.duration(1, 'day'); // for Grid system\n\t},\n\n\n\t// Renders the rows and columns into the component's `this.el`, which should already be assigned.\n\t// isRigid determins whether the individual rows should ignore the contents and be a constant height.\n\t// Relies on the view's colCnt and rowCnt. In the future, this component should probably be self-sufficient.\n\trenderDates: function(isRigid) {\n\t\tvar view = this.view;\n\t\tvar rowCnt = this.rowCnt;\n\t\tvar colCnt = this.colCnt;\n\t\tvar cellCnt = rowCnt * colCnt;\n\t\tvar html = '';\n\t\tvar row;\n\t\tvar i, cell;\n\n\t\tfor (row = 0; row < rowCnt; row++) {\n\t\t\thtml += this.dayRowHtml(row, isRigid);\n\t\t}\n\t\tthis.el.html(html);\n\n\t\tthis.rowEls = this.el.find('.fc-row');\n\t\tthis.dayEls = this.el.find('.fc-day');\n\n\t\t// trigger dayRender with each cell's element\n\t\tfor (i = 0; i < cellCnt; i++) {\n\t\t\tcell = this.getCell(i);\n\t\t\tview.trigger('dayRender', null, cell.start, this.dayEls.eq(i));\n\t\t}\n\t},\n\n\n\tdestroyDates: function() {\n\t\tthis.destroySegPopover();\n\t},\n\n\n\trenderBusinessHours: function() {\n\t\tvar events = this.view.calendar.getBusinessHoursEvents(true); // wholeDay=true\n\t\tvar segs = this.eventsToSegs(events);\n\n\t\tthis.renderFill('businessHours', segs, 'bgevent');\n\t},\n\n\n\t// Generates the HTML for a single row. `row` is the row number.\n\tdayRowHtml: function(row, isRigid) {\n\t\tvar view = this.view;\n\t\tvar classes = [ 'fc-row', 'fc-week', view.widgetContentClass ];\n\n\t\tif (isRigid) {\n\t\t\tclasses.push('fc-rigid');\n\t\t}\n\n\t\treturn '' +\n\t\t\t'' +\n\t\t\t\t' ' +\n\t\t\t\t\t' ' +\n\t\t\t\t\t\tthis.rowHtml('day', row) + // leverages RowRenderer. calls dayCellHtml()\n\t\t\t\t\t' ' +\n\t\t\t\t' ' +\n\t\t\t\t' ' +\n\t\t\t\t\t' ' +\n\t\t\t\t\t\t(this.numbersVisible ?\n\t\t\t\t\t\t\t'' +\n\t\t\t\t\t\t\t\tthis.rowHtml('number', row) + // leverages RowRenderer. View will define render method\n\t\t\t\t\t\t\t'' :\n\t\t\t\t\t\t\t''\n\t\t\t\t\t\t\t) +\n\t\t\t\t\t' ' +\n\t\t\t\t' ' +\n\t\t\t' ';\n\t},\n\n\n\t// Renders the HTML for a whole-day cell. Will eventually end up in the day-row's background.\n\t// We go through a 'day' row type instead of just doing a 'bg' row type so that the View can do custom rendering\n\t// specifically for whole-day rows, whereas a 'bg' might also be used for other purposes (TimeGrid bg for example).\n\tdayCellHtml: function(cell) {\n\t\treturn this.bgCellHtml(cell);\n\t},\n\n\n\t/* Options\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Computes a default column header formatting string if `colFormat` is not explicitly defined\n\tcomputeColHeadFormat: function() {\n\t\tif (this.rowCnt > 1) { // more than one week row. day numbers will be in each cell\n\t\t\treturn 'ddd'; // \"Sat\"\n\t\t}\n\t\telse if (this.colCnt > 1) { // multiple days, so full single date string WON'T be in title text\n\t\t\treturn this.view.opt('dayOfMonthFormat'); // \"Sat 12/10\"\n\t\t}\n\t\telse { // single day, so full single date string will probably be in title text\n\t\t\treturn 'dddd'; // \"Saturday\"\n\t\t}\n\t},\n\n\n\t// Computes a default event time formatting string if `timeFormat` is not explicitly defined\n\tcomputeEventTimeFormat: function() {\n\t\treturn this.view.opt('extraSmallTimeFormat'); // like \"6p\" or \"6:30p\"\n\t},\n\n\n\t// Computes a default `displayEventEnd` value if one is not expliclty defined\n\tcomputeDisplayEventEnd: function() {\n\t\treturn this.colCnt == 1; // we'll likely have space if there's only one day\n\t},\n\n\n\t/* Cell System\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Initializes row/col information\n\tupdateCells: function() {\n\t\tvar cellDates;\n\t\tvar firstDay;\n\t\tvar rowCnt;\n\t\tvar colCnt;\n\n\t\tthis.updateCellDates(); // populates cellDates and dayToCellOffsets\n\t\tcellDates = this.cellDates;\n\n\t\tif (this.breakOnWeeks) {\n\t\t\t// count columns until the day-of-week repeats\n\t\t\tfirstDay = cellDates[0].day();\n\t\t\tfor (colCnt = 1; colCnt < cellDates.length; colCnt++) {\n\t\t\t\tif (cellDates[colCnt].day() == firstDay) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\trowCnt = Math.ceil(cellDates.length / colCnt);\n\t\t}\n\t\telse {\n\t\t\trowCnt = 1;\n\t\t\tcolCnt = cellDates.length;\n\t\t}\n\n\t\tthis.rowCnt = rowCnt;\n\t\tthis.colCnt = colCnt;\n\t},\n\n\n\t// Populates cellDates and dayToCellOffsets\n\tupdateCellDates: function() {\n\t\tvar view = this.view;\n\t\tvar date = this.start.clone();\n\t\tvar dates = [];\n\t\tvar offset = -1;\n\t\tvar offsets = [];\n\n\t\twhile (date.isBefore(this.end)) { // loop each day from start to end\n\t\t\tif (view.isHiddenDay(date)) {\n\t\t\t\toffsets.push(offset + 0.5); // mark that it's between offsets\n\t\t\t}\n\t\t\telse {\n\t\t\t\toffset++;\n\t\t\t\toffsets.push(offset);\n\t\t\t\tdates.push(date.clone());\n\t\t\t}\n\t\t\tdate.add(1, 'days');\n\t\t}\n\n\t\tthis.cellDates = dates;\n\t\tthis.dayToCellOffsets = offsets;\n\t},\n\n\n\t// Given a cell object, generates its start date. Returns a reference-free copy.\n\tcomputeCellDate: function(cell) {\n\t\tvar colCnt = this.colCnt;\n\t\tvar index = cell.row * colCnt + (this.isRTL ? colCnt - cell.col - 1 : cell.col);\n\n\t\treturn this.cellDates[index].clone();\n\t},\n\n\n\t// Retrieves the element representing the given row\n\tgetRowEl: function(row) {\n\t\treturn this.rowEls.eq(row);\n\t},\n\n\n\t// Retrieves the element representing the given column\n\tgetColEl: function(col) {\n\t\treturn this.dayEls.eq(col);\n\t},\n\n\n\t// Gets the whole-day element associated with the cell\n\tgetCellDayEl: function(cell) {\n\t\treturn this.dayEls.eq(cell.row * this.colCnt + cell.col);\n\t},\n\n\n\t// Overrides Grid's method for when row coordinates are computed\n\tcomputeRowCoords: function() {\n\t\tvar rowCoords = Grid.prototype.computeRowCoords.call(this); // call the super-method\n\n\t\t// hack for extending last row (used by AgendaView)\n\t\trowCoords[rowCoords.length - 1].bottom += this.bottomCoordPadding;\n\n\t\treturn rowCoords;\n\t},\n\n\n\t/* Dates\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Slices up a date range by row into an array of segments\n\trangeToSegs: function(range) {\n\t\tvar isRTL = this.isRTL;\n\t\tvar rowCnt = this.rowCnt;\n\t\tvar colCnt = this.colCnt;\n\t\tvar segs = [];\n\t\tvar first, last; // inclusive cell-offset range for given range\n\t\tvar row;\n\t\tvar rowFirst, rowLast; // inclusive cell-offset range for current row\n\t\tvar isStart, isEnd;\n\t\tvar segFirst, segLast; // inclusive cell-offset range for segment\n\t\tvar seg;\n\n\t\trange = this.view.computeDayRange(range); // make whole-day range, considering nextDayThreshold\n\t\tfirst = this.dateToCellOffset(range.start);\n\t\tlast = this.dateToCellOffset(range.end.subtract(1, 'days')); // offset of inclusive end date\n\n\t\tfor (row = 0; row < rowCnt; row++) {\n\t\t\trowFirst = row * colCnt;\n\t\t\trowLast = rowFirst + colCnt - 1;\n\n\t\t\t// intersect segment's offset range with the row's\n\t\t\tsegFirst = Math.max(rowFirst, first);\n\t\t\tsegLast = Math.min(rowLast, last);\n\n\t\t\t// deal with in-between indices\n\t\t\tsegFirst = Math.ceil(segFirst); // in-between starts round to next cell\n\t\t\tsegLast = Math.floor(segLast); // in-between ends round to prev cell\n\n\t\t\tif (segFirst <= segLast) { // was there any intersection with the current row?\n\n\t\t\t\t// must be matching integers to be the segment's start/end\n\t\t\t\tisStart = segFirst === first;\n\t\t\t\tisEnd = segLast === last;\n\n\t\t\t\t// translate offsets to be relative to start-of-row\n\t\t\t\tsegFirst -= rowFirst;\n\t\t\t\tsegLast -= rowFirst;\n\n\t\t\t\tseg = { row: row, isStart: isStart, isEnd: isEnd };\n\t\t\t\tif (isRTL) {\n\t\t\t\t\tseg.leftCol = colCnt - segLast - 1;\n\t\t\t\t\tseg.rightCol = colCnt - segFirst - 1;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tseg.leftCol = segFirst;\n\t\t\t\t\tseg.rightCol = segLast;\n\t\t\t\t}\n\t\t\t\tsegs.push(seg);\n\t\t\t}\n\t\t}\n\n\t\treturn segs;\n\t},\n\n\n\t// Given a date, returns its chronolocial cell-offset from the first cell of the grid.\n\t// If the date lies between cells (because of hiddenDays), returns a floating-point value between offsets.\n\t// If before the first offset, returns a negative number.\n\t// If after the last offset, returns an offset past the last cell offset.\n\t// Only works for *start* dates of cells. Will not work for exclusive end dates for cells.\n\tdateToCellOffset: function(date) {\n\t\tvar offsets = this.dayToCellOffsets;\n\t\tvar day = date.diff(this.start, 'days');\n\n\t\tif (day < 0) {\n\t\t\treturn offsets[0] - 1;\n\t\t}\n\t\telse if (day >= offsets.length) {\n\t\t\treturn offsets[offsets.length - 1] + 1;\n\t\t}\n\t\telse {\n\t\t\treturn offsets[day];\n\t\t}\n\t},\n\n\n\t/* Event Drag Visualization\n\t------------------------------------------------------------------------------------------------------------------*/\n\t// TODO: move to DayGrid.event, similar to what we did with Grid's drag methods\n\n\n\t// Renders a visual indication of an event or external element being dragged.\n\t// The dropLocation's end can be null. seg can be null. See Grid::renderDrag for more info.\n\trenderDrag: function(dropLocation, seg) {\n\n\t\t// always render a highlight underneath\n\t\tthis.renderHighlight(\n\t\t\tthis.view.calendar.ensureVisibleEventRange(dropLocation) // needs to be a proper range\n\t\t);\n\n\t\t// if a segment from the same calendar but another component is being dragged, render a helper event\n\t\tif (seg && !seg.el.closest(this.el).length) {\n\n\t\t\tthis.renderRangeHelper(dropLocation, seg);\n\t\t\tthis.applyDragOpacity(this.helperEls);\n\n\t\t\treturn true; // a helper has been rendered\n\t\t}\n\t},\n\n\n\t// Unrenders any visual indication of a hovering event\n\tdestroyDrag: function() {\n\t\tthis.destroyHighlight();\n\t\tthis.destroyHelper();\n\t},\n\n\n\t/* Event Resize Visualization\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Renders a visual indication of an event being resized\n\trenderEventResize: function(range, seg) {\n\t\tthis.renderHighlight(range);\n\t\tthis.renderRangeHelper(range, seg);\n\t},\n\n\n\t// Unrenders a visual indication of an event being resized\n\tdestroyEventResize: function() {\n\t\tthis.destroyHighlight();\n\t\tthis.destroyHelper();\n\t},\n\n\n\t/* Event Helper\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\t// Renders a mock \"helper\" event. `sourceSeg` is the associated internal segment object. It can be null.\n\trenderHelper: function(event, sourceSeg) {\n\t\tvar helperNodes = [];\n\t\tvar segs = this.eventsToSegs([ event ]);\n\t\tvar rowStructs;\n\n\t\tsegs = this.renderFgSegEls(segs); // assigns each seg's el and returns a subset of segs that were rendered\n\t\trowStructs = this.renderSegRows(segs);\n\n\t\t// inject each new event skeleton into each associated row\n\t\tthis.rowEls.each(function(row, rowNode) {\n\t\t\tvar rowEl = $(rowNode); // the .fc-row\n\t\t\tvar skeletonEl = $(''); // will be absolutely positioned\n\t\t\tvar skeletonTop;\n\n\t\t\t// If there is an original segment, match the top position. Otherwise, put it at the row's top level\n\t\t\tif (sourceSeg && sourceSeg.row === row) {\n\t\t\t\tskeletonTop = sourceSeg.el.position().top;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tskeletonTop = rowEl.find('.fc-content-skeleton tbody').position().top;\n\t\t\t}\n\n\t\t\tskeletonEl.css('top', skeletonTop)\n\t\t\t\t.find('table')\n\t\t\t\t\t.append(rowStructs[row].tbodyEl);\n\n\t\t\trowEl.append(skeletonEl);\n\t\t\thelperNodes.push(skeletonEl[0]);\n\t\t});\n\n\t\tthis.helperEls = $(helperNodes); // array -> jQuery set\n\t},\n\n\n\t// Unrenders any visual indication of a mock helper event\n\tdestroyHelper: function() {\n\t\tif (this.helperEls) {\n\t\t\tthis.helperEls.remove();\n\t\t\tthis.helperEls = null;\n\t\t}\n\t},\n\n\n\t/* Fill System (highlight, background events, business hours)\n\t------------------------------------------------------------------------------------------------------------------*/\n\n\n\tfillSegTag: 'td', // override the default tag name\n\n\n\t// Renders a set of rectangles over the given segments of days.\n\t// Only returns segments that successfully rendered.\n\trenderFill: function(type, segs, className) {\n\t\tvar nodes = [];\n\t\tvar i, seg;\n\t\tvar skeletonEl;\n\n\t\tsegs = this.renderFillSegEls(type, segs); // assignes `.el` to each seg. returns successfully rendered segs\n\n\t\tfor (i = 0; i < segs.length; i++) {\n\t\t\tseg = segs[i];\n\t\t\tskeletonEl = this.renderFillRow(type, seg, className);\n\t\t\tthis.rowEls.eq(seg.row).append(skeletonEl);\n\t\t\tnodes.push(skeletonEl[0]);\n\t\t}\n\n\t\tthis.elsByFill[type] = $(nodes);\n\n\t\treturn segs;\n\t},\n\n\n\t// Generates the HTML needed for one row of a fill. Requires the seg's el to be rendered.\n\trenderFillRow: function(type, seg, className) {\n\t\tvar colCnt = this.colCnt;\n\t\tvar startCol = seg.leftCol;\n\t\tvar endCol = seg.rightCol + 1;\n\t\tvar skeletonEl;\n\t\tvar trEl;\n\n\t\tclassName = className || type.toLowerCase();\n\n\t\tskeletonEl = $(\n\t\t\t'' +\n\t\t\t\t' ' +\n\t\t\t' '\n\t\t);\n\t\ttrEl = skeletonEl.find('tr');\n\n\t\tif (startCol > 0) {\n\t\t\ttrEl.append(' | ');\n\t\t}\n\n\t\ttrEl.append(\n\t\t\tseg.el.attr('colspan', endCol - startCol)\n\t\t);\n\n\t\tif (endCol < colCnt) {\n\t\t\ttrEl.append(' | ');\n\t\t}\n\n\t\tthis.bookendCells(trEl, type);\n\n\t\treturn skeletonEl;\n\t}\n\n});\n\n;;\n\n/* Event-rendering methods for the DayGrid class\n----------------------------------------------------------------------------------------------------------------------*/\n\nDayGrid.mixin({\n\n\trowStructs: null, // an array of objects, each holding information about a row's foreground event-rendering\n\n\n\t// Unrenders all events currently rendered on the grid\n\tdestroyEvents: function() {\n\t\tthis.destroySegPopover(); // removes the \"more..\" events popover\n\t\tGrid.prototype.destroyEvents.apply(this, arguments); // calls the super-method\n\t},\n\n\n\t// Retrieves all rendered segment objects currently rendered on the grid\n\tgetEventSegs: function() {\n\t\treturn Grid.prototype.getEventSegs.call(this) // get the segments from the super-method\n\t\t\t.concat(this.popoverSegs || []); // append the segments from the \"more...\" popover\n\t},\n\n\n\t// Renders the given background event segments onto the grid\n\trenderBgSegs: function(segs) {\n\n\t\t// don't render timed background events\n\t\tvar allDaySegs = $.grep(segs, function(seg) {\n\t\t\treturn seg.event.allDay;\n\t\t});\n\n\t\treturn Grid.prototype.renderBgSegs.call(this, allDaySegs); // call the super-method\n\t},\n\n\n\t// Renders the given foreground event segments onto the grid\n\trenderFgSegs: function(segs) {\n\t\tvar rowStructs;\n\n\t\t// render an `.el` on each seg\n\t\t// returns a subset of the segs. segs that were actually rendered\n\t\tsegs = this.renderFgSegEls(segs);\n\n\t\trowStructs = this.rowStructs = this.renderSegRows(segs);\n\n\t\t// append to each row's content skeleton\n\t\tthis.rowEls.each(function(i, rowNode) {\n\t\t\t$(rowNode).find('.fc-content-skeleton > table').append(\n\t\t\t\trowStructs[i].tbodyEl\n\t\t\t);\n\t\t});\n\n\t\treturn segs; // return only the segs that were actually rendered\n\t},\n\n\n\t// Unrenders all currently rendered foreground event segments\n\tdestroyFgSegs: function() {\n\t\tvar rowStructs = this.rowStructs || [];\n\t\tvar rowStruct;\n\n\t\twhile ((rowStruct = rowStructs.pop())) {\n\t\t\trowStruct.tbodyEl.remove();\n\t\t}\n\n\t\tthis.rowStructs = null;\n\t},\n\n\n\t// Uses the given events array to generate elements that should be appended to each row's content skeleton.\n\t// Returns an array of rowStruct objects (see the bottom of `renderSegRow`).\n\t// PRECONDITION: each segment shoud already have a rendered and assigned `.el`\n\trenderSegRows: function(segs) {\n\t\tvar rowStructs = [];\n\t\tvar segRows;\n\t\tvar row;\n\n\t\tsegRows = this.groupSegRows(segs); // group into nested arrays\n\n\t\t// iterate each row of segment groupings\n\t\tfor (row = 0; row < segRows.length; row++) {\n\t\t\trowStructs.push(\n\t\t\t\tthis.renderSegRow(row, segRows[row])\n\t\t\t);\n\t\t}\n\n\t\treturn rowStructs;\n\t},\n\n\n\t// Builds the HTML to be used for the default element for an individual segment\n\tfgSegHtml: function(seg, disableResizing) {\n\t\tvar view = this.view;\n\t\tvar event = seg.event;\n\t\tvar isDraggable = view.isEventDraggable(event);\n\t\tvar isResizableFromStart = !disableResizing && event.allDay &&\n\t\t\tseg.isStart && view.isEventResizableFromStart(event);\n\t\tvar isResizableFromEnd = !disableResizing && event.allDay &&\n\t\t\tseg.isEnd && view.isEventResizableFromEnd(event);\n\t\tvar classes = this.getSegClasses(seg, isDraggable, isResizableFromStart || isResizableFromEnd);\n\t\tvar skinCss = cssToStr(this.getEventSkinCss(event));\n\t\tvar timeHtml = '';\n\t\tvar timeText;\n\t\tvar titleHtml;\n\n\t\tclasses.unshift('fc-day-grid-event', 'fc-h-event');\n\n\t\t// Only display a timed events time if it is the starting segment\n\t\tif (seg.isStart) {\n\t\t\ttimeText = this.getEventTimeText(event);\n\t\t\tif (timeText) {\n\t\t\t\ttimeHtml = '' + htmlEscape(timeText) + '';\n\t\t\t}\n\t\t}\n\n\t\ttitleHtml =\n\t\t\t'' +\n\t\t\t\t(htmlEscape(event.title || '') || ' ') + // we always want one line of height\n\t\t\t'';\n\t\t\n\t\treturn '' +\n\t\t\t\t'' +\n\t\t\t\t\t(this.isRTL ?\n\t\t\t\t\t\ttitleHtml + ' ' + timeHtml : // put a natural space in between\n\t\t\t\t\t\ttimeHtml + ' ' + titleHtml //\n\t\t\t\t\t\t) +\n\t\t\t\t' ' +\n\t\t\t\t(isResizableFromStart ?\n\t\t\t\t\t'' :\n\t\t\t\t\t''\n\t\t\t\t\t) +\n\t\t\t\t(isResizableFromEnd ?\n\t\t\t\t\t'' :\n\t\t\t\t\t''\n\t\t\t\t\t) +\n\t\t\t'';\n\t},\n\n\n\t// Given a row # and an array of segments all in the same row, render a element, a skeleton that contains\n\t// the segments. Returns object with a bunch of internal data about how the render was calculated.\n\t// NOTE: modifies rowSegs\n\trenderSegRow: function(row, rowSegs) {\n\t\tvar colCnt = this.colCnt;\n\t\tvar segLevels = this.buildSegLevels(rowSegs); // group into sub-arrays of levels\n\t\tvar levelCnt = Math.max(1, segLevels.length); // ensure at least one level\n\t\tvar tbody = $('');\n\t\tvar segMatrix = []; // lookup for which segments are rendered into which level+col cells\n\t\tvar cellMatrix = []; // lookup for all elements of the level+col matrix\n\t\tvar loneCellMatrix = []; // lookup for | elements that only take up a single column\n\t\tvar i, levelSegs;\n\t\tvar col;\n\t\tvar tr;\n\t\tvar j, seg;\n\t\tvar td;\n\n\t\t// populates empty cells from the current column (`col`) to `endCol`\n\t\tfunction emptyCellsUntil(endCol) {\n\t\t\twhile (col < endCol) {\n\t\t\t\t// try to grab a cell from the level above and extend its rowspan. otherwise, create a fresh cell\n\t\t\t\ttd = (loneCellMatrix[i - 1] || [])[col];\n\t\t\t\tif (td) {\n\t\t\t\t\ttd.attr(\n\t\t\t\t\t\t'rowspan',\n\t\t\t\t\t\tparseInt(td.attr('rowspan') || 1, 10) + 1\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttd = $(' | | ');\n\t\t\t\t\ttr.append(td);\n\t\t\t\t}\n\t\t\t\tcellMatrix[i][col] = td;\n\t\t\t\tloneCellMatrix[i][col] = td;\n\t\t\t\tcol++;\n\t\t\t}\n\t\t}\n\n\t\tfor (i = 0; i < levelCnt; i++) { // iterate through all levels\n\t\t\tlevelSegs = segLevels[i];\n\t\t\tcol = 0;\n\t\t\ttr = $(' |
');\n\n\t\t\tsegMatrix.push([]);\n\t\t\tcellMatrix.push([]);\n\t\t\tloneCellMatrix.push([]);\n\n\t\t\t// levelCnt might be 1 even though there are no actual levels. protect against this.\n\t\t\t// this single empty row is useful for styling.\n\t\t\tif (levelSegs) {\n\t\t\t\tfor (j = 0; j < levelSegs.length; j++) { // iterate through segments in level\n\t\t\t\t\tseg = levelSegs[j];\n\n\t\t\t\t\temptyCellsUntil(seg.leftCol);\n\n\t\t\t\t\t// create a container that occupies or more columns. append the event element.\n\t\t\t\t\ttd = $(' ').append(seg.el);\n\t\t\t\t\tif (seg.leftCol != seg.rightCol) {\n\t\t\t\t\t\ttd.attr('colspan', seg.rightCol - seg.leftCol + 1);\n\t\t\t\t\t}\n\t\t\t\t\telse { // a single-column segment\n\t\t\t\t\t\tloneCellMatrix[i][col] = td;\n\t\t\t\t\t}\n\n\t\t\t\t\twhile (col <= seg.rightCol) {\n\t\t\t\t\t\tcellMatrix[i][col] = td;\n\t\t\t\t\t\tsegMatrix[i][col] = seg;\n\t\t\t\t\t\tcol++;\n\t\t\t\t\t}\n\n\t\t\t\t\ttr.append(td);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\temptyCellsUntil(colCnt); // finish off the row\n\t\t\tthis.bookendCells(tr, 'eventSkeleton');\n\t\t\ttbody.append(tr);\n\t\t}\n\n\t\treturn { // a \"rowStruct\"\n\t\t\trow: row, // the row number\n\t\t\ttbodyEl: tbody,\n\t\t\tcellMatrix: cellMatrix,\n\t\t\tsegMatrix: segMatrix,\n\t\t\tsegLevels: segLevels,\n\t\t\tsegs: rowSegs\n\t\t};\n\t},\n\n\n\t// Stacks a flat array of segments, which are all assumed to be in the same row, into subarrays of vertical levels.\n\t// NOTE: modifies segs\n\tbuildSegLevels: function(segs) {\n\t\tvar levels = [];\n\t\tvar i, seg;\n\t\tvar j;\n\n\t\t// Give preference to elements with certain criteria, so they have\n\t\t// a chance to be closer to the top.\n\t\tsegs.sort(compareSegs);\n\t\t\n\t\tfor (i = 0; i < segs.length; i++) {\n\t\t\tseg = segs[i];\n\n\t\t\t// loop through levels, starting with the topmost, until the segment doesn't collide with other segments\n\t\t\tfor (j = 0; j < levels.length; j++) {\n\t\t\t\tif (!isDaySegCollision(seg, levels[j])) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// `j` now holds the desired subrow index\n\t\t\tseg.level = j;\n\n\t\t\t// create new level array if needed and append segment\n\t\t\t(levels[j] || (levels[j] = [])).push(seg);\n\t\t}\n\n\t\t// order segments left-to-right. very important if calendar is RTL\n\t\tfor (j = 0; j < levels.length; j++) {\n\t\t\tlevels[j].sort(compareDaySegCols);\n\t\t}\n\n\t\treturn levels;\n\t},\n\n\n\t// Given a flat array of segments, return an array of sub-arrays, grouped by each segment's row\n\tgroupSegRows: function(segs) {\n\t\tvar segRows = [];\n\t\tvar i;\n\n\t\tfor (i = 0; i < this.rowCnt; i++) {\n\t\t\tsegRows.push([]);\n\t\t}\n\n\t\tfor (i = 0; i < segs.length; i++) {\n\t\t\tsegRows[segs[i].row].push(segs[i]);\n\t\t}\n\n\t\treturn segRows;\n\t}\n\n});\n\n\n// Computes whether two segments' columns collide. They are assumed to be in the same row.\nfunction isDaySegCollision(seg, otherSegs) {\n\tvar i, otherSeg;\n\n\tfor (i = 0; i < otherSegs.length; i++) {\n\t\totherSeg = otherSegs[i];\n\n\t\tif (\n\t\t\totherSeg.leftCol <= seg.rightCol &&\n\t\t\totherSeg.rightCol >= seg.leftCol\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n\n// A cmp function for determining the leftmost event\nfunction compareDaySegCols(a, b) {\n\treturn a.leftCol - b.leftCol;\n}\n\n;;\n\n/* Methods relate to limiting the number events for a given day on a DayGrid\n----------------------------------------------------------------------------------------------------------------------*/\n// NOTE: all the segs being passed around in here are foreground segs\n\nDayGrid.mixin({\n\n\tsegPopover: null, // the Popover that holds events that can't fit in a cell. null when not visible\n\tpopoverSegs: null, // an array of segment objects that the segPopover holds. null when not visible\n\n\n\tdestroySegPopover: function() {\n\t\tif (this.segPopover) {\n\t\t\tthis.segPopover.hide(); // will trigger destruction of `segPopover` and `popoverSegs`\n\t\t}\n\t},\n\n\n\t// Limits the number of \"levels\" (vertically stacking layers of events) for each row of the grid.\n\t// `levelLimit` can be false (don't limit), a number, or true (should be computed).\n\tlimitRows: function(levelLimit) {\n\t\tvar rowStructs = this.rowStructs || [];\n\t\tvar row; // row #\n\t\tvar rowLevelLimit;\n\n\t\tfor (row = 0; row < rowStructs.length; row++) {\n\t\t\tthis.unlimitRow(row);\n\n\t\t\tif (!levelLimit) {\n\t\t\t\trowLevelLimit = false;\n\t\t\t}\n\t\t\telse if (typeof levelLimit === 'number') {\n\t\t\t\trowLevelLimit = levelLimit;\n\t\t\t}\n\t\t\telse {\n\t\t\t\trowLevelLimit = this.computeRowLevelLimit(row);\n\t\t\t}\n\n\t\t\tif (rowLevelLimit !== false) {\n\t\t\t\tthis.limitRow(row, rowLevelLimit);\n\t\t\t}\n\t\t}\n\t},\n\n\n\t// Computes the number of levels a row will accomodate without going outside its bounds.\n\t// Assumes the row is \"rigid\" (maintains a constant height regardless of what is inside).\n\t// `row` is the row number.\n\tcomputeRowLevelLimit: function(row) {\n\t\tvar rowEl = this.rowEls.eq(row); // the containing \"fake\" row div\n\t\tvar rowHeight = rowEl.height(); // TODO: cache somehow?\n\t\tvar trEls = this.rowStructs[row].tbodyEl.children();\n\t\tvar i, trEl;\n\t\tvar trHeight;\n\n\t\tfunction iterInnerHeights(i, childNode) {\n\t\t\ttrHeight = Math.max(trHeight, $(childNode).outerHeight());\n\t\t}\n\n\t\t// Reveal one level | at a time and stop when we find one out of bounds\n\t\tfor (i = 0; i < trEls.length; i++) {\n\t\t\ttrEl = trEls.eq(i).removeClass('fc-limited'); // reset to original state (reveal)\n\n\t\t\t// with rowspans>1 and IE8, trEl.outerHeight() would return the height of the largest cell,\n\t\t\t// so instead, find the tallest inner content element.\n\t\t\ttrHeight = 0;\n\t\t\ttrEl.find('> td > :first-child').each(iterInnerHeights);\n\n\t\t\tif (trEl.position().top + trHeight > rowHeight) {\n\t\t\t\treturn i;\n\t\t\t}\n\t\t}\n\n\t\treturn false; // should not limit at all\n\t},\n\n\n\t// Limits the given grid row to the maximum number of levels and injects \"more\" links if necessary.\n\t// `row` is the row number.\n\t// `levelLimit` is a number for the maximum (inclusive) number of levels allowed.\n\tlimitRow: function(row, levelLimit) {\n\t\tvar _this = this;\n\t\tvar rowStruct = this.rowStructs[row];\n\t\tvar moreNodes = []; // array of \"more\" links and DOM nodes\n\t\tvar col = 0; // col #, left-to-right (not chronologically)\n\t\tvar cell;\n\t\tvar levelSegs; // array of segment objects in the last allowable level, ordered left-to-right\n\t\tvar cellMatrix; // a matrix (by level, then column) of all | jQuery elements in the row\n\t\tvar limitedNodes; // array of temporarily hidden level | and segment DOM nodes\n\t\tvar i, seg;\n\t\tvar segsBelow; // array of segment objects below `seg` in the current `col`\n\t\tvar totalSegsBelow; // total number of segments below `seg` in any of the columns `seg` occupies\n\t\tvar colSegsBelow; // array of segment arrays, below seg, one for each column (offset from segs's first column)\n\t\tvar td, rowspan;\n\t\tvar segMoreNodes; // array of \"more\" | cells that will stand-in for the current seg's cell\n\t\tvar j;\n\t\tvar moreTd, moreWrap, moreLink;\n\n\t\t// Iterates through empty level cells and places \"more\" links inside if need be\n\t\tfunction emptyCellsUntil(endCol) { // goes from current `col` to `endCol`\n\t\t\twhile (col < endCol) {\n\t\t\t\tcell = _this.getCell(row, col);\n\t\t\t\tsegsBelow = _this.getCellSegs(cell, levelLimit);\n\t\t\t\tif (segsBelow.length) {\n\t\t\t\t\ttd = cellMatrix[levelLimit - 1][col];\n\t\t\t\t\tmoreLink = _this.renderMoreLink(cell, segsBelow);\n\t\t\t\t\tmoreWrap = $('').append(moreLink);\n\t\t\t\t\ttd.append(moreWrap);\n\t\t\t\t\tmoreNodes.push(moreWrap[0]);\n\t\t\t\t}\n\t\t\t\tcol++;\n\t\t\t}\n\t\t}\n\n\t\tif (levelLimit && levelLimit < rowStruct.segLevels.length) { // is it actually over the limit?\n\t\t\tlevelSegs = rowStruct.segLevels[levelLimit - 1];\n\t\t\tcellMatrix = rowStruct.cellMatrix;\n\n\t\t\tlimitedNodes = rowStruct.tbodyEl.children().slice(levelLimit) // get level | elements past the limit\n\t\t\t\t.addClass('fc-limited').get(); // hide elements and get a simple DOM-nodes array\n\n\t\t\t// iterate though segments in the last allowable level\n\t\t\tfor (i = 0; i < levelSegs.length; i++) {\n\t\t\t\tseg = levelSegs[i];\n\t\t\t\temptyCellsUntil(seg.leftCol); // process empty cells before the segment\n\n\t\t\t\t// determine *all* segments below `seg` that occupy the same columns\n\t\t\t\tcolSegsBelow = [];\n\t\t\t\ttotalSegsBelow = 0;\n\t\t\t\twhile (col <= seg.rightCol) {\n\t\t\t\t\tcell = this.getCell(row, col);\n\t\t\t\t\tsegsBelow = this.getCellSegs(cell, levelLimit);\n\t\t\t\t\tcolSegsBelow.push(segsBelow);\n\t\t\t\t\ttotalSegsBelow += segsBelow.length;\n\t\t\t\t\tcol++;\n\t\t\t\t}\n\n\t\t\t\tif (totalSegsBelow) { // do we need to replace this segment with one or many \"more\" links?\n\t\t\t\t\ttd = cellMatrix[levelLimit - 1][seg.leftCol]; // the segment's parent cell\n\t\t\t\t\trowspan = td.attr('rowspan') || 1;\n\t\t\t\t\tsegMoreNodes = [];\n\n\t\t\t\t\t// make a replacement for each column the segment occupies. will be one for each colspan\n\t\t\t\t\tfor (j = 0; j < colSegsBelow.length; j++) {\n\t\t\t\t\t\tmoreTd = $(' | ').attr('rowspan', rowspan);\n\t\t\t\t\t\tsegsBelow = colSegsBelow[j];\n\t\t\t\t\t\tcell = this.getCell(row, seg.leftCol + j);\n\t\t\t\t\t\tmoreLink = this.renderMoreLink(cell, [ seg ].concat(segsBelow)); // count seg as hidden too\n\t\t\t\t\t\tmoreWrap = $('').append(moreLink);\n\t\t\t\t\t\tmoreTd.append(moreWrap);\n\t\t\t\t\t\tsegMoreNodes.push(moreTd[0]);\n\t\t\t\t\t\tmoreNodes.push(moreTd[0]);\n\t\t\t\t\t}\n\n\t\t\t\t\ttd.addClass('fc-limited').after($(segMoreNodes)); // hide original | and inject replacements\n\t\t\t\t\tlimitedNodes.push(td[0]);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\temptyCellsUntil(this.colCnt); // finish off the level\n\t\t\trowStruct.moreEls = $(moreNodes); // for easy undoing later\n\t\t\trowStruct.limitedEls = $(limitedNodes); // for easy undoing later\n\t\t}\n\t},\n\n\n\t// Reveals all levels and removes all \"more\"-related elements for a grid's row.\n\t// `row` is a row number.\n\tunlimitRow: function(row) {\n\t\tvar rowStruct = this.rowStructs[row];\n\n\t\tif (rowStruct.moreEls) {\n\t\t\trowStruct.moreEls.remove();\n\t\t\trowStruct.moreEls = null;\n\t\t}\n\n\t\tif (rowStruct.limitedEls) {\n\t\t\trowStruct.limitedEls.removeClass('fc-limited');\n\t\t\trowStruct.limitedEls = null;\n\t\t}\n\t},\n\n\n\t// Renders an element that represents hidden event element for a cell.\n\t// Responsible for attaching click handler as well.\n\trenderMoreLink: function(cell, hiddenSegs) {\n\t\tvar _this = this;\n\t\tvar view = this.view;\n\n\t\treturn $('')\n\t\t\t.text(\n\t\t\t\tthis.getMoreLinkText(hiddenSegs.length)\n\t\t\t)\n\t\t\t.on('click', function(ev) {\n\t\t\t\tvar clickOption = view.opt('eventLimitClick');\n\t\t\t\tvar date = cell.start;\n\t\t\t\tvar moreEl = $(this);\n\t\t\t\tvar dayEl = _this.getCellDayEl(cell);\n\t\t\t\tvar allSegs = _this.getCellSegs(cell);\n\n\t\t\t\t// rescope the segments to be within the cell's date\n\t\t\t\tvar reslicedAllSegs = _this.resliceDaySegs(allSegs, date);\n\t\t\t\tvar reslicedHiddenSegs = _this.resliceDaySegs(hiddenSegs, date);\n\n\t\t\t\tif (typeof clickOption === 'function') {\n\t\t\t\t\t// the returned value can be an atomic option\n\t\t\t\t\tclickOption = view.trigger('eventLimitClick', null, {\n\t\t\t\t\t\tdate: date,\n\t\t\t\t\t\tdayEl: dayEl,\n\t\t\t\t\t\tmoreEl: moreEl,\n\t\t\t\t\t\tsegs: reslicedAllSegs,\n\t\t\t\t\t\thiddenSegs: reslicedHiddenSegs\n\t\t\t\t\t}, ev);\n\t\t\t\t}\n\n\t\t\t\tif (clickOption === 'popover') {\n\t\t\t\t\t_this.showSegPopover(cell, moreEl, reslicedAllSegs);\n\t\t\t\t}\n\t\t\t\telse if (typeof clickOption === 'string') { // a view name\n\t\t\t\t\tview.calendar.zoomTo(date, clickOption);\n\t\t\t\t}\n\t\t\t});\n\t},\n\n\n\t// Reveals the popover that displays all events within a cell\n\tshowSegPopover: function(cell, moreLink, segs) {\n\t\tvar _this = this;\n\t\tvar view = this.view;\n\t\tvar moreWrap = moreLink.parent(); // the wrapper around the \n\t\tvar topEl; // the element we want to match the top coordinate of\n\t\tvar options;\n\n\t\tif (this.rowCnt == 1) {\n\t\t\ttopEl = view.el; // will cause the popover to cover any sort of header\n\t\t}\n\t\telse {\n\t\t\ttopEl = this.rowEls.eq(cell.row); // will align with top of row\n\t\t}\n\n\t\toptions = {\n\t\t\tclassName: 'fc-more-popover',\n\t\t\tcontent: this.renderSegPopoverContent(cell, segs),\n\t\t\tparentEl: this.el,\n\t\t\ttop: topEl.offset().top,\n\t\t\tautoHide: true, // when the user clicks elsewhere, hide the popover\n\t\t\tviewportConstrain: view.opt('popoverViewportConstrain'),\n\t\t\thide: function() {\n\t\t\t\t// destroy everything when the popover is hidden\n\t\t\t\t_this.segPopover.destroy();\n\t\t\t\t_this.segPopover = null;\n\t\t\t\t_this.popoverSegs = null;\n\t\t\t}\n\t\t};\n\n\t\t// Determine horizontal coordinate.\n\t\t// We use the moreWrap instead of the to avoid border confusion.\n\t\tif (this.isRTL) {\n\t\t\toptions.right = moreWrap.offset().left + moreWrap.outerWidth() + 1; // +1 to be over cell border\n\t\t}\n\t\telse {\n\t\t\toptions.left = moreWrap.offset().left - 1; // -1 to be over cell border\n\t\t}\n\n\t\tthis.segPopover = new Popover(options);\n\t\tthis.segPopover.show();\n\t},\n\n\n\t// Builds the inner DOM contents of the segment popover\n\trenderSegPopoverContent: function(cell, segs) {\n\t\tvar view = this.view;\n\t\tvar isTheme = view.opt('theme');\n\t\tvar title = cell.start.format(view.opt('dayPopoverFormat'));\n\t\tvar content = $(\n\t\t\t' | | |