/* * Sugar Library v1.2.1 * * Freely distributable and licensed under the MIT-style license. * Copyright (c) 2012 Andrew Plummer * http://sugarjs.com/ * * ---------------------------- */ (function(context){var i=true,j=false;function k(a){return function(){return a}}var l=Object,o=Array,r=RegExp,s=Date,t=String,u=Number,aa=l.defineProperty&&l.defineProperties;function v(a,b,c,d){var f=b?a.prototype:a;w(d,function(g,h){if(typeof c==="function")y(f,g,ba(f[g],h,c));else if(c===i||!f[g])y(f,g,h)})}function ba(a,b,c){return function(){return a&&(c===i||c.apply(this,arguments))?a.apply(this,arguments):b.apply(this,arguments)}} function y(a,b,c){if(aa)l.defineProperty(a,b,{value:c,configurable:i,enumerable:j,writable:i});else a[b]=c}function w(a,b){var c=0,d;for(d in a)if(a.hasOwnProperty(d)){b.call(a,d,a[d],c);c++}}function z(a,b,c,d){return a===b?i:l.isRegExp(b)?r(b).test(a):l.isFunction(b)?b.apply(c,[a].concat(d)):l.equal(b,a)}function A(a,b,c,d){return B(b)?a:l.isFunction(b)?b.apply(c,d||[]):l.isFunction(a[b])?a[b].call(a):a[b]}function da(a,b,c,d){a=Array.prototype.slice.call(a,void 0);if(c!==j)a=C(a);D(a,b,d)} function B(a){return a===void 0}function E(a){return a!==void 0}function F(a,b,c,d){typeof b=="object"&&w(b,function(f,g){var h=a[f],e=E(h),m=l.isArray(g);if(c===i&&(m||l.isObject(g))){h||(h=m?[]:{});F(h,g,c)}else if(e&&l.isFunction(d))h=d.call(b,f,a[f],b[f]);else if(!e||e&&d!==j)h=b[f];if(E(h))a[f]=h});return a} v(l,j,j,{isObject:function(a){return a===null||B(a)?j:l.prototype.toString.call(a)==="[object Object]"&&a.constructor===l},each:function(a,b){b&&w(a,function(c,d){b.call(a,c,d,a)});return a},merge:function(a,b,c){return F(a,b,i,c)}});function D(a,b,c,d){var f;G(b);if(c<0)c=a.length+c;c=isNaN(c)?0:parseInt(c>>0);for(d=d===i?a.length+c:a.length;c>0);if(c<0)c=f+c;if(!g&&c<0||g&&c>=f)c=h;for(;g&&c>=0||!g&&c0;g&&a<=b||!g&&a>=b;){f.push(a);c&&c.call(this,a);a+=d}return f} v(u,i,j,{toNumber:function(){return parseFloat(this,10)},ordinalize:function(){var a;if(this>=11&&this<=13)a="th";else switch(this%10){case 1:a="st";break;case 2:a="nd";break;case 3:a="rd";break;default:a="th"}return this.toString()+a},pad:function(a,b,c){c=c||10;var d=this.toNumber()===0?"":this.toString(c).replace(/^-/,"");c=d;a=a-d.replace(/\.\d+$/,"").length;d=0;var f=String("0");if(f!="0")f="";l.isNumber(a)||(a=1);l.isNumber(d)||(d=1);d=f.repeat(a)+c+f.repeat(d);if(b||this<0)d=(this<0?"-":"+")+ d;return d}});function fa(a,b){function c(){return K(this*b)}function d(){return L(arguments)[g](this)}function f(){return L(arguments)[g](-this)}var g="add"+a.capitalize()+"s";y(u.prototype,a,c);y(u.prototype,a+"s",c);y(u.prototype,a+"Before",f);y(u.prototype,a+"sBefore",f);y(u.prototype,a+"Ago",f);y(u.prototype,a+"sAgo",f);y(u.prototype,a+"After",d);y(u.prototype,a+"sAfter",d);y(u.prototype,a+"FromNow",d);y(u.prototype,a+"sFromNow",d)} function M(){return"\t\n\u000b\u000c\r \u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u2028\u2029\u3000\ufeff"} v(t,i,j,{capitalize:function(a){return this.toLowerCase().replace(a?/\b[a-z]/g:/^[a-z]/,function(b){return b.toUpperCase()})},repeat:function(a){var b="",c=0;if(l.isNumber(a)&&a>0)for(;c=m[1]&&ca<=(m[2]||m[1]))x.push(pa)});p=x}p=p.compact().join("|")}if(q)return"(?:"+p+")?";else{f.push(n);return"("+p+")"+(e?"?":"")}});b(d,f,c)});a.l=i}}function X(a,b,c){if(b&&(!l.isString(a)||!a))a=Date.currentLocale;a&&!W[a]&&la(a,c);return W[a]} function la(a,b){function c(g,h){g=g.split("+").map(function(e){return e.replace(/(.+):(.+)$/,function(m,q,n){return n.split("|").map(function(p){return q+p}).join("|")})}).join("|");return D(g.split("|"),h)}function d(g,h,e){var m=[];if(b[g]){D(b[g],function(q,n){c(q,function(p,x){m[x*e+n]=p.toLowerCase()})});if(h)m=m.concat(b[g].map(function(q){return q.slice(0,3).toLowerCase()}));return b[g]=m}}function f(g,h){var e="[0-9\uff10-\uff19]"+(g?"{"+g+","+h+"}":"+");if(b.digits)e+="|["+b.digits+"]+"; return e}b=b||ma(a);if(!b)throw Error("Invalid locale.");d("months",i,12);d("weekdays",i,7);d("units",j,8);d("numbers",j,10);b.code=a;b.date=f(1,2);b.year=f(4,4);b.num=function(){var g=[f()].concat(b.articles);b.digits||(g=g.concat(b.numbers));return g.compact().join("|")}();(function(){var g=[];b.f={};D(b.modifiers,function(h){c(h.text,function(e){b.f[e]=h;g.push({name:h.name,text:e,value:h.value})})});g.groupBy("name",function(h,e){e=e.map("text");if(h==="day")e=e.concat(b.weekdays);b[h]=e.join("|")}); b.modifiers=g})();if(b.monthSuffix){b.month=f(1,2);b.months=ea(1,12,null,1).map(function(g){return g+b.monthSuffix})}W[a]=new na(b)} function ma(a){function b(f){return!!(d[0]&Math.pow(2,f-1))}if(a.slice(0,3)=="en-")a="en";if(!ja[a])return null;var c={modifiers:[]},d=ja[a].split(";");D(["months","weekdays","units","numbers","articles","optionals","formats"],function(f,g){c[f]=d[g+2]?d[g+2].split(","):[]});c.outputFormat=d[9];D(["day","sign","shift","edge"],function(f,g){d[g+10]&&D(d[g+10].split(","),function(h,e){h&&c.modifiers.push({name:f,text:h,value:e-2})})});if(b(1)){c.digits=Q+R;if(c.numbers.length>0)c.digits+=c.numbers.join(""); else c.numbers=Q.split("");c.monthSuffix=d[1]}c.capitalizeUnit=a=="de";c.hasPlural=b(2);c.pastRelativeFormat=c.formats[0];c.futureRelativeFormat=c.formats[b(3)?1:0];return c}function oa(a){a||(a=Date.currentLocale);return a!="en"&&a!="en-US"}function na(a){l.merge(this,a)} v(na,i,j,{getMonth:function(a){return l.isNumber(a)?a-1:H(this.months,r(a,"i"),0,j,i)%12},k:function(a){return H(this.weekdays,r(a,"i"),0,j,i)%7},j:function(a){var b;return l.isNumber(a)?a:a&&(b=this.numbers.indexOf(a))!==-1?(b+1)%10:1},n:function(a){var b=this;return a.replace(this.numbers[9],"").replace(/./g,function(c){return b.j(c)})},m:function(a){return English.units[this.units.indexOf(a)%8]},q:function(a,b,c){var d,f;d=c>0?this.futureRelativeFormat:this.pastRelativeFormat;if(this.code=="ru"){f= a.toString().slice(-1);switch(i){case f==1:f=1;break;case f>=2&&f<=4:f=2;break;default:f=3}}else f=this.hasPlural&&a>1?1:0;f=this.units[f*8+b]||this.units[b];if(this.capitalizeUnit)f=f.capitalize();b=H(this.modifiers,function(g){return g.name=="sign"&&g.value==(c>0?1:-1)});return d.assign({num:a,unit:f,sign:b.text})}});function Y(a){var b;if(typeof a[0]=="object")return a;else if(a.length==1&&l.isNumber(a[0]))return[a[0]];b={};D(T,function(c,d){b[c.a]=a[d]});return[b]} function ra(a,b){a=a.replace(/[\uff11\uff12\uff13\uff14\uff15\uff16\uff17\uff18\uff19\uff10]/g,function(c){return String.fromCharCode(c.charCodeAt(0)-65248)});if(b!="date"&&b!="month"&&b!="year")return a;return a.replace(ga,function(c){return Q.indexOf(c)+1||""})}function sa(a,b){var c={},d,f;D(b,function(g,h){d=a[h+1];if(!(B(d)||d==="")){d=ra(d,g);if(g==="year")c.s=d;if(g==="millisecond")d*=Math.pow(10,3-d.length);f=parseFloat(d);c[g]=!isNaN(f)?f:d.toLowerCase()}});return c} function ta(a,b){var c=new s,d=j,f,g,h,e,m,q,n;if(l.isDate(a))c=a;else if(l.isNumber(a))c=new s(a);else if(l.isObject(a)){c=(new s).set(a,i);e=a}else if(l.isString(a)){ka(X(b,i));g=oa(b);a=a.trim().replace(/\.+$/,"").replace(/^now$/,"");D(S,function(p){var x=a.match(p.p);if(x){h=p;e=sa(x,h.to);f=X(h.o,i);if(e.timestamp){c.setTime(0);e={milliseconds:e.timestamp};return j}if(h.h&&!l.isString(e.month)&&(l.isString(e.date)||g)){n=e.month;e.month=e.date;e.date=n}if(e.year&&e.s.length===2)e.year=K((new s).getFullYear()/ 100)*100-K(e.year/100)*100+e.year;if(e.month){e.month=f.getMonth(e.month);if(e.shift&&!e.unit)e.unit="year"}if(e.weekday&&e.date)delete e.weekday;else if(e.weekday){e.weekday=f.k(e.weekday);if(e.shift&&!e.unit)e.unit="week"}if(e.day&&(n=f.f[e.day])){e.day=n.value;c.resetTime();d=i}else if(e.day&&(n=f.k(e.day))>-1){delete e.day;e.weekday=n}if(e.date&&!l.isNumber(e.date))e.date=f.n(e.date);if(e.meridian)if(e.meridian==="pm"&&e.hour<12)e.hour+=12;if(e.offset_hours||e.offset_minutes){e.utc=i;e.offset_minutes= e.offset_minutes||0;e.offset_minutes+=e.offset_hours*60;if(e.offset_sign==="-")e.offset_minutes*=-1;e.minute-=e.offset_minutes}if(e.unit){d=i;q=f.j(e.num);m=f.m(e.unit);if(e.shift||e.edge){q*=(n=f.f[e.shift])?n.value:0;if(m==="month"&&E(e.date)){c.set({day:e.date},i);delete e.date}if(m==="year"&&E(e.month)){c.set({month:e.month,day:e.date},i);delete e.month;delete e.date}}if(e.sign&&(n=f.f[e.sign]))q*=n.value;if(E(e.weekday)){c.set({weekday:e.weekday},i);delete e.weekday}e[m]=(e[m]||0)+q}if(e.year_sign=== "-")e.year*=-1;return j}});if(h)if(d)c.advance(e);else e.utc?c.setUTC(e,i):c.set(e,i);else c=a?new s(a):new s;if(e&&e.edge){n=f.f[e.edge];D(U.slice(4),function(p){if(E(e[p.a])){m=p.a;return j}});if(m==="year")e.d="month";else if(m==="month"||m==="week")e.d="day";c[(n.value<0?"endOf":"beginningOf")+m.capitalize()]();n.value===-2&&c.resetTime()}}return{e:c,set:e}} function Z(a,b,c,d){var f,g=X(d,i),h=r(/^[A-Z]/);if(a.isValid())if(Date[b])b=Date[b];else{if(l.isFunction(b)){f=ua(a);b=b.apply(a,f.concat(g))}}else return"Invalid Date";if(!b&&!c)b=g.outputFormat;else if(!b&&c){f=f||ua(a);if(f[1]===0){f[1]=1;f[0]=1}return g.q(f[0],f[1],f[2])}D(ia,function(e){b=b.replace(r("\\{("+e.b+")(\\d)?\\}",e.i?"i":""),function(m,q,n){m=e.format(a,g,n||1,q);n=q.length;var p=q.match(/^(.)\1+$/);if(e.i){if(n===3)m=m.slice(0,3);if(p||q.match(h))m=m.capitalize()}else if(p&&!e.text)m= (l.isNumber(m)?m.pad(n):m.toString()).last(n);return m})});return b}function va(a,b,c){var d=ta(b),f=0,g=b=0,h;if(c>0){b=g=c;h=i}if(!d.e.isValid())return j;if(d.set&&d.set.d){D(V,function(m){if(m.a===d.set.d)f=m.c(d.e,a-d.e)-1});if(d.set.edge||d.set.shift)d.e["beginningOf"+d.set.d.capitalize()]();if(!h&&d.set.sign&&d.set.d!="millisecond"){b=50;g=-50}}c=a.getTime();h=d.e.getTime();var e=h+f;if(d.set&&d.set.d=="week"&&(new Date(e+1)).getHours()!=0)e-=s.DSTOffset;return c>=h-b&&c<=e+g} function $(a,b,c,d,f){if(l.isNumber(b)&&f)b={milliseconds:b};else if(l.isNumber(b)){a.setTime(b);return a}if(b.date)b.day=b.date;if(!f&&B(b.day)&&E(b.weekday)){a["set"+(d?"UTC":"")+"Weekday"](b.weekday);b.day=a["get"+(d?"UTC":"")+"Date"](void 0);delete b.weekday}D(U,function(g){if(E(b[g.a])||E(b[g.a+"s"])){b.d=g.a;return j}else if(c&&g.a!=="week"&&g.a!=="year")a["set"+(d?"UTC":"")+g.method](g.a==="day"?1:0)});D(V,function(g){var h=g.a;g=g.method;var e=E(b[h])?b[h]:b[h+"s"];if(!B(e)){if(f){if(h=== "week"){e=(b.day||0)+e*7;g="Date"}e=e*f+a["get"+g](void 0)}a["set"+(d?"UTC":"")+g](e);if(h==="month"){h=e;if(h<0)h+=12;h%12!=a.getMonth()&&a.setDate(0)}}});return a}function wa(a){a.addDays(4-(a.getDay()||7)).resetTime();return 1+(a.daysSince(a.clone().beginningOfYear())/7|0)}function ua(a){var b;a=a.millisecondsFromNow();var c=Math.abs(a),d=c,f=0;D(U.slice(1),function(g,h){b=K(c/g.c(),1)|0;if(b>=1){d=b;f=h+1}});return[d,f,a]} function L(a){var b;b=l.isNumber(a[1])?Y(a)[0]:a[0];return ta(b,a[1]).e}v(s,j,j,{create:function(){return L(arguments)},now:function(){return(new s).getTime()},setLocale:function(a,b){var c=X(a,j,b);if(c){Date.currentLocale=a;ka(c);return c}},getLocale:function(a){return X(a,i)},addFormat:function(a,b,c,d){S.push({h:d,o:c,p:r("^"+a+"$","i"),to:b})}}); v(s,i,j,{set:function(){var a=Y(arguments);return $(this,a[0],a[1])},setUTC:function(){var a=Y(arguments);return $(this,a[0],a[1],i)},setWeekday:function(a){B(a)||this.setDate(this.getDate()+a-this.getDay())},setUTCWeekday:function(a){B(a)||this.setDate(this.getUTCDate()+a-this.getDay())},setWeek:function(a){if(!B(a)){this.setMonth(0);this.setDate(a*7+1)}},setUTCWeek:function(a){if(!B(a)){this.setMonth(0);this.setUTCDate(a*7+1)}},getWeek:function(){return wa(this)},getUTCWeek:function(){return wa(this.toUTC())}, getUTCOffset:function(a){var b=this.g?0:this.getTimezoneOffset(),c=a===i?":":"";if(!b&&a)return"Z";return K(-b/60).pad(2,i)+c+(b%60).pad(2)},toUTC:function(){if(this.g)return this;var a=this.clone().addMinutes(this.getTimezoneOffset());a.g=i;return a},isUTC:function(){return this.g||this.getTimezoneOffset()===0},advance:function(){var a=Y(arguments);return $(this,a[0],j,j,1,i)},rewind:function(){var a=Y(arguments);return $(this,a[0],j,j,-1)},isValid:function(){return!isNaN(this.getTime())},isAfter:function(a, b){return this.getTime()>s.create(a).getTime()-(b||0)},isBefore:function(a,b){return this.getTime()d},isLeapYear:function(){var a=this.getFullYear();return a%4===0&&a%100!==0||a%400===0},daysInMonth:function(){return 32-(new s(this.getFullYear(),this.getMonth(),32)).getDate()},format:function(a,b){return Z(this,a, j,b)},relative:function(a,b){if(l.isString(a)){b=a;a=null}return Z(this,a,i,b)},is:function(a,b){var c;if(l.isString(a)){a=a.trim().toLowerCase();switch(i){case a==="future":return this.getTime()>(new s).getTime();case a==="past":return this.getTime()<(new s).getTime();case a==="weekday":return this.getDay()>0&&this.getDay()<6;case a==="weekend":return this.getDay()===0||this.getDay()===6;case (c=English.weekdays.indexOf(a)%7)>-1:return this.getDay()===c;case (c=English.months.indexOf(a)%12)>-1:return this.getMonth()=== c}}return va(this,a,b)},resetTime:function(){return this.set({hour:0,minute:0,second:0,millisecond:0})},clone:function(){return new s(this.getTime())},compare:function(){return this-L(arguments)}});v(s,i,j,{getWeekday:s.prototype.getDay,getUTCWeekday:s.prototype.getUTCDay});(function(){var a={};D(["Array","Boolean","Date","Function","Number","String","RegExp"],function(b){a["is"+b]=function(c){return l.prototype.toString.call(c)==="[object "+b+"]"}});v(Object,j,j,a)})(); (function(){var a=M().match(/^\s+$/);try{t.prototype.trim.call([1])}catch(b){a=j}var c=r("^["+M()+"]+"),d=r("["+M()+"]+$");v(t,i,!a,{trim:function(){return this.toString().trimLeft().trimRight()},trimLeft:function(){return this.replace(c,"")},trimRight:function(){return this.replace(d,"")}})})();English=s.setLocale("en"); D(V,function(a,b){var c=a.a,d=c.capitalize(),f=a.c();y(s.prototype,c+"sSince",function(g,h){return K((this.getTime()-s.create(g,h).getTime())/f)});y(s.prototype,c+"sUntil",function(g,h){return K((s.create(g,h).getTime()-this.getTime())/f)});y(s.prototype,c+"sAgo",s.prototype[c+"sUntil"]);y(s.prototype,c+"sFromNow",s.prototype[c+"sSince"]);y(s.prototype,"add"+d+"s",function(g){var h={};h[c]=g;return this.advance(h)});fa(c,f);b<3&&D(["Last","This","Next"],function(g){y(s.prototype,"is"+g+d,function(){return this.is(g+ " "+c)})});if(b<4){y(s.prototype,"beginningOf"+d,function(){var g={};switch(c){case "year":g.year=this.getFullYear();break;case "month":g.month=this.getMonth();break;case "day":g.day=this.getDate();break;case "week":g.weekday=0}return this.set(g,i)});y(s.prototype,"endOf"+d,function(){var g={hours:23,minutes:59,seconds:59,milliseconds:999};switch(c){case "year":g.month=11;g.day=31;break;case "month":g.day=this.daysInMonth();break;case "week":g.weekday=6}return this.set(g,i)})}}); (function(){T=V.concat();T.splice(2,1);U=V.concat().reverse();var a="\\d{1,2}|"+English.months.join("|");D(ha,function(b){s.addFormat(b.src.replace(/\{month\}/,a)+(b.r===j?"":P),b.to.concat(N),"en",b.h)});s.addFormat(O,N)})();(function(){var a=English.weekdays.slice(0,7),b=English.months.slice(0,12);D(["today","yesterday","tomorrow","weekday","weekend","future","past"].concat(a).concat(b),function(c){y(s.prototype,"is"+c.capitalize(),function(){return this.is(c)})})})(); v(s,j,i,{DSTOffset:((new s(2E3,6,1)).getTimezoneOffset()-(new s(2E3,0,1)).getTimezoneOffset())*60*1E3,INTERNATIONAL_TIME:"{h}:{mm}:{ss}",RFC1123:"{Dow}, {dd} {Mon} {yyyy} {HH}:{mm}:{ss} {tz}",RFC1036:"{Weekday}, {dd}-{Mon}-{yy} {HH}:{mm}:{ss} {tz}",ISO8601_DATE:"{yyyy}-{MM}-{dd}",ISO8601_DATETIME:"{yyyy}-{MM}-{dd}T{HH}:{mm}:{ss}.{fff}{isotz}"}); (function(){var a=new s(s.UTC(1999,11,31));if(!a.toISOString||a.toISOString()!=="1999-12-31T00:00:00.000Z")v(s,i,i,{toISOString:function(){return Z(this.toUTC(),s.ISO8601_DATETIME)}});if(!a.toJSON||a.toJSON()!=="1999-12-31T00:00:00.000Z")v(s,i,i,{toJSON:s.prototype.toISOString});v(s,i,j,{iso:s.prototype.toISOString})})();})(this);