roojs-core.js
[roojs1] / roojs-core.js
index 051147b..5b5b74e 100644 (file)
@@ -37,16 +37,17 @@ Roo.applyIf(Array.prototype,{indexOf:function(o){for(var i=0,A=this.length;i<A;i
 }var C=new Array(B);var D=arguments[1];for(var i=0;i<B;i++){if(i in this){C[i]=A.call(D,this[i],i,this);}}return C;},equals:function(b){if(this===b){return true;}if(b==null){return false;}if(this.length!==b.length){return false;}for(var i=0;i<this.length;
 ++i){if(this[i]!==b[i]){return false;}}return true;}});Roo.applyIf(Array,{from:function(o){var A=[];for(var i=0;i<o.length;i++){A[i]=o[i];}return A;}});
 // Date.js
-Date.prototype.getElapsed=function(A){return Math.abs((A||new Date()).getTime()-this.getTime());};Date.parseFunctions={count:0};Date.parseRegexes=[];Date.formatFunctions={count:0};Date.prototype.dateFormat=function(A){if(Date.formatFunctions[A]==null){Date.createNewFormat(A);
-}var B=Date.formatFunctions[A];return this[B]();};Date.prototype.format=Date.prototype.dateFormat;Date.createNewFormat=function(A){var B="format"+Date.formatFunctions.count++;Date.formatFunctions[A]=B;var C="Date.prototype."+B+" = function(){return ";var D=false;
-var ch='';for(var i=0;i<A.length;++i){ch=A.charAt(i);if(!D&&ch=="\\"){D=true;}else if(D){D=false;C+="'"+String.escape(ch)+"' + ";}else{C+=Date.getFormatCode(ch);}}eval(C.substring(0,C.length-3)+";}");};Date.getFormatCode=function(A){switch(A){case "d":return "String.leftPad(this.getDate(), 2, '0') + ";
-case "D":return "Date.dayNames[this.getDay()].substring(0, 3) + ";case "j":return "this.getDate() + ";case "l":return "Date.dayNames[this.getDay()] + ";case "S":return "this.getSuffix() + ";case "w":return "this.getDay() + ";case "z":return "this.getDayOfYear() + ";
-case "W":return "this.getWeekOfYear() + ";case "F":return "Date.monthNames[this.getMonth()] + ";case "m":return "String.leftPad(this.getMonth() + 1, 2, '0') + ";case "M":return "Date.monthNames[this.getMonth()].substring(0, 3) + ";case "n":return "(this.getMonth() + 1) + ";
-case "t":return "this.getDaysInMonth() + ";case "L":return "(this.isLeapYear() ? 1 : 0) + ";case "Y":return "this.getFullYear() + ";case "y":return "('' + this.getFullYear()).substring(2, 4) + ";case "a":return "(this.getHours() < 12 ? 'am' : 'pm') + ";case "A":return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
-case "g":return "((this.getHours() % 12) ? this.getHours() % 12 : 12) + ";case "G":return "this.getHours() + ";case "h":return "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0') + ";case "H":return "String.leftPad(this.getHours(), 2, '0') + ";
-case "i":return "String.leftPad(this.getMinutes(), 2, '0') + ";case "s":return "String.leftPad(this.getSeconds(), 2, '0') + ";case "O":return "this.getGMTOffset() + ";case "P":return "this.getGMTColonOffset() + ";case "T":return "this.getTimezone() + ";case "Z":return "(this.getTimezoneOffset() * -60) + ";
-default:return "'"+String.escape(A)+"' + ";}};Date.parseDate=function(A,B){if(Date.parseFunctions[B]==null){Date.createParser(B);}var C=Date.parseFunctions[B];return Date[C](A);};Date.createParser=function(A){var B="parse"+Date.parseFunctions.count++;var C=Date.parseRegexes.length;
-var D=1;Date.parseFunctions[A]=B;var E="Date."+B+" = function(input){\n"+"var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, o, z, v;\n"+"var d = new Date();\n"+"y = d.getFullYear();\n"+"m = d.getMonth();\n"+"d = d.getDate();\n"+"if (typeof(input) !== 'string') { input = input.toString(); }\n"+"var results = input.match(Date.parseRegexes["+C+"]);\n"+"if (results && results.length > 0) {";
+Date.prototype.getElapsed=function(A,B){A=A||new Date();var C=Math.abs(A.getTime()-this.getTime());switch(B){case Date.SECOND:return Math.floor(C/(1000));case Date.MINUTE:return Math.floor(C/(1000*60));case Date.HOUR:return Math.floor(C/(1000*60*60));case Date.DAY:return Math.floor(C/(1000*60*60*24));
+case Date.MONTH:return ((A.format("Y")-this.format("Y"))*12)+(A.format("m")-this.format("m"));case Date.YEAR:return (A.format("Y")-this.format("Y"));case Date.MILLI:default:return C;}};Date.parseFunctions={count:0};Date.parseRegexes=[];Date.formatFunctions={count:0}
+;Date.prototype.dateFormat=function(A){if(Date.formatFunctions[A]==null){Date.createNewFormat(A);}var B=Date.formatFunctions[A];return this[B]();};Date.prototype.format=Date.prototype.dateFormat;Date.createNewFormat=function(A){var B="format"+Date.formatFunctions.count++;
+Date.formatFunctions[A]=B;var C="Date.prototype."+B+" = function(){return ";var D=false;var ch='';for(var i=0;i<A.length;++i){ch=A.charAt(i);if(!D&&ch=="\\"){D=true;}else if(D){D=false;C+="'"+String.escape(ch)+"' + ";}else{C+=Date.getFormatCode(ch);}}eval(C.substring(0,C.length-3)+";}");
+};Date.getFormatCode=function(A){switch(A){case "d":return "String.leftPad(this.getDate(), 2, '0') + ";case "D":return "Date.dayNames[this.getDay()].substring(0, 3) + ";case "j":return "this.getDate() + ";case "l":return "Date.dayNames[this.getDay()] + ";
+case "S":return "this.getSuffix() + ";case "w":return "this.getDay() + ";case "z":return "this.getDayOfYear() + ";case "W":return "this.getWeekOfYear() + ";case "F":return "Date.monthNames[this.getMonth()] + ";case "m":return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
+case "M":return "Date.monthNames[this.getMonth()].substring(0, 3) + ";case "n":return "(this.getMonth() + 1) + ";case "t":return "this.getDaysInMonth() + ";case "L":return "(this.isLeapYear() ? 1 : 0) + ";case "Y":return "this.getFullYear() + ";case "y":return "('' + this.getFullYear()).substring(2, 4) + ";
+case "a":return "(this.getHours() < 12 ? 'am' : 'pm') + ";case "A":return "(this.getHours() < 12 ? 'AM' : 'PM') + ";case "g":return "((this.getHours() % 12) ? this.getHours() % 12 : 12) + ";case "G":return "this.getHours() + ";case "h":return "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0') + ";
+case "H":return "String.leftPad(this.getHours(), 2, '0') + ";case "i":return "String.leftPad(this.getMinutes(), 2, '0') + ";case "s":return "String.leftPad(this.getSeconds(), 2, '0') + ";case "O":return "this.getGMTOffset() + ";case "P":return "this.getGMTColonOffset() + ";
+case "T":return "this.getTimezone() + ";case "Z":return "(this.getTimezoneOffset() * -60) + ";default:return "'"+String.escape(A)+"' + ";}};Date.parseDate=function(A,B){if(Date.parseFunctions[B]==null){Date.createParser(B);}var C=Date.parseFunctions[B];return Date[C](A);
+};Date.createParser=function(A){var B="parse"+Date.parseFunctions.count++;var C=Date.parseRegexes.length;var D=1;Date.parseFunctions[A]=B;var E="Date."+B+" = function(input){\n"+"var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, o, z, v;\n"+"var d = new Date();\n"+"y = d.getFullYear();\n"+"m = d.getMonth();\n"+"d = d.getDate();\n"+"if (typeof(input) !== 'string') { input = input.toString(); }\n"+"var results = input.match(Date.parseRegexes["+C+"]);\n"+"if (results && results.length > 0) {";
 var F="";var G=false;var ch='';for(var i=0;i<A.length;++i){ch=A.charAt(i);if(!G&&ch=="\\"){G=true;}else if(G){G=false;F+=String.escape(ch);}else{var H=Date.formatCodeToRegex(ch,D);D+=H.g;F+=H.s;if(H.g&&H.c){E+=H.c;}}}E+="if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"+"{v = new Date(y, m, d, h, i, s); v.setFullYear(y);}\n"+"else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"+"{v = new Date(y, m, d, h, i); v.setFullYear(y);}\n"+"else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n"+"{v = new Date(y, m, d, h); v.setFullYear(y);}\n"+"else if (y >= 0 && m >= 0 && d > 0)\n"+"{v = new Date(y, m, d); v.setFullYear(y);}\n"+"else if (y >= 0 && m >= 0)\n"+"{v = new Date(y, m); v.setFullYear(y);}\n"+"else if (y >= 0)\n"+"{v = new Date(y); v.setFullYear(y);}\n"+"}return (v && (z || o))?\n"+"    ((z)? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n"+"        v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n"+";}";
 Date.parseRegexes[C]=new RegExp("^"+F+"$");eval(E);};Date.formatCodeToRegex=function(A,B){switch(A){case "D":return {g:0,c:null,s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};case "j":return {g:1,c:"d = parseInt(results["+B+"], 10);\n",s:"(\\d{1,2})"};case "d":return {g:1,c:"d = parseInt(results["+B+"], 10);\n",s:"(\\d{2})"}
 ;case "l":return {g:0,c:null,s:"(?:"+Date.dayNames.join("|")+")"};case "S":return {g:0,c:null,s:"(?:st|nd|rd|th)"};case "w":return {g:0,c:null,s:"\\d"};case "z":return {g:0,c:null,s:"(?:\\d{1,3})"};case "W":return {g:0,c:null,s:"(?:\\d{2})"};case "F":return {g:1,c:"m = parseInt(Date.monthNumbers[results["+B+"].substring(0, 3)], 10);\n",s:"("+Date.monthNames.join("|")+")"}