X-Git-Url: http://git.roojs.org/?p=roojs1;a=blobdiff_plain;f=roojs-core-debug.js;h=73e26b3337abac782af0466068522afde7506ce8;hp=b9be269386a170c14a5b6d50e363743ec0ee1d6a;hb=fc32d3336ffe6a4ac93549dab21fd04b7d7056d3;hpb=223cc214da1215b8ba858232052abb2bb7211d77 diff --git a/roojs-core-debug.js b/roojs-core-debug.js index b9be269386..73e26b3337 100644 --- a/roojs-core-debug.js +++ b/roojs-core-debug.js @@ -19,7 +19,7 @@ window["undefined"] = window["undefined"]; /** * @class Roo * Roo core utilities and functions. - * @singleton + * @static */ var Roo = {}; /** @@ -57,6 +57,7 @@ Roo.apply = function(o, c, defaults){ isIE = ua.indexOf("msie") > -1, isIE7 = ua.indexOf("msie 7") > -1, isIE11 = /trident.*rv\:11\./.test(ua), + isEdge = ua.indexOf("edge") > -1, isGecko = !isSafari && ua.indexOf("gecko") > -1, isBorderBox = isIE && !isStrict, isWindows = (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1), @@ -64,6 +65,7 @@ Roo.apply = function(o, c, defaults){ isLinux = (ua.indexOf("linux") != -1), isSecure = window.location.href.toLowerCase().indexOf("https") === 0, isIOS = /iphone|ipad/.test(ua), + isAndroid = /android/.test(ua), isTouch = (function() { try { if (ua.indexOf('chrome') != -1 && ua.indexOf('android') == -1) { @@ -340,8 +342,8 @@ Roo.factory(conf, Roo.data); if ((typeof(console) == 'undefined') || (typeof(console.log) == 'undefined')) { return; // alerT? } - console.log(s); + console.log(s); }, /** * Takes an object and converts it to an encoded URL. e.g. Roo.urlEncode({foo: 1, bar: 2}); would return "foo=1&bar=2". Optionally, property values can be arrays, instead of keys and the resulting string that's returned will contain a name/value pair for each array value. @@ -628,6 +630,8 @@ Roo.factory(conf, Roo.data); /** @type Boolean */ isIE11 : isIE11, /** @type Boolean */ + isEdge : isEdge, + /** @type Boolean */ isGecko : isGecko, /** @type Boolean */ isBorderBox : isBorderBox, @@ -640,6 +644,8 @@ Roo.factory(conf, Roo.data); /** @type Boolean */ isIOS : isIOS, /** @type Boolean */ + isAndroid : isAndroid, + /** @type Boolean */ isTouch : isTouch, /** @@ -662,7 +668,30 @@ Roo.factory(conf, Roo.data); { var node = Roo.DomQuery.selectNode(selector,root); return node ? Roo.get(node) : new Roo.Element(false); - } + }, + /** + * Find the current bootstrap width Grid size + * Note xs is the default for smaller.. - this is currently used by grids to render correct columns + * @returns {String} (xs|sm|md|lg|xl) + */ + + getGridSize : function() + { + var w = Roo.lib.Dom.getViewWidth(); + switch(true) { + case w > 1200: + return 'xl'; + case w > 992: + return 'lg'; + case w > 768: + return 'md'; + case w > 576: + return 'sm'; + default: + return 'xs' + } + + } }); @@ -671,9 +700,8 @@ Roo.factory(conf, Roo.data); Roo.namespace("Roo", "Roo.util", "Roo.grid", "Roo.dd", "Roo.tree", "Roo.data", "Roo.form", "Roo.menu", "Roo.state", "Roo.lib", "Roo.layout", - "Roo.app", "Roo.ux", - "Roo.bootstrap", - "Roo.bootstrap.dash"); + "Roo.app", "Roo.ux" + ); /* * Based on: * Ext JS Library 1.1.1 @@ -879,6 +907,8 @@ var s = String.format('
{1}
', cls, text); return Roo.util.Format.htmlEncode(args[i]); }); } + + }); /** @@ -900,7 +930,41 @@ sort = (sort == 'ASC' ? 'DESC' : 'ASC'); String.prototype.toggle = function(value, other){ return this == value ? other : value; -};/* +}; + + +/** + * Remove invalid unicode characters from a string + * + * @return {String} The clean string + */ +String.prototype.unicodeClean = function () { + return this.replace(/[\s\S]/g, + function(character) { + if (character.charCodeAt()< 256) { + return character; + } + try { + encodeURIComponent(character); + } catch(e) { + return ''; + } + return character; + } + ); +}; + + +/** + * Make the first letter of a string uppercase + * + * @return {String} The new string. + */ +String.prototype.toUpperCaseFirst = function () { + return this.charAt(0).toUpperCase() + this.slice(1); +}; + +/* * Based on: * Ext JS Library 1.1.1 * Copyright(c) 2006-2007, Ext JS, LLC. @@ -983,12 +1047,58 @@ Roo.applyIf(Array.prototype, { } return res; - } + }, + /** + * equals + * @param {Array} o The array to compare to + * @returns {Boolean} true if the same + */ + equals : function(b) + { + // https://stackoverflow.com/questions/3115982/how-to-check-if-two-arrays-are-equal-with-javascript + if (this === b) { + return true; + } + if (b == null) { + return false; + } + if (this.length !== b.length) { + return false; + } + + // sort?? a.sort().equals(b.sort()); + + for (var i = 0; i < this.length; ++i) { + if (this[i] !== b[i]) { + return false; + } + } + return true; + } + + + }); - - +Roo.applyIf(Array, { + /** + * from + * @static + * @param {Array} o Or Array like object (eg. nodelist) + * @returns {Array} + */ + from : function(o) + { + var ret= []; + + for (var i =0; i < o.length; i++) { + ret[i] = o[i]; + } + return ret; + + } +}); /* * Based on: * Ext JS Library 1.1.1 @@ -1095,12 +1205,35 @@ document.write(dt.format(Date.patterns.ShortDate)); /** Returns the number of milliseconds between this date and date @param {Date} date (optional) Defaults to now - @return {Number} The diff in milliseconds + @param {String} interval (optional) Default Date.MILLI, A valid date interval enum value (eg. Date.DAY) + @return {Number} The diff in milliseconds or units of interval @member Date getElapsed */ -Date.prototype.getElapsed = function(date) { - return Math.abs((date || new Date()).getTime()-this.getTime()); +Date.prototype.getElapsed = function(date, interval) +{ + date = date || new Date(); + var ret = Math.abs(date.getTime()-this.getTime()); + switch (interval) { + + case Date.SECOND: + return Math.floor(ret / (1000)); + case Date.MINUTE: + return Math.floor(ret / (1000*60)); + case Date.HOUR: + return Math.floor(ret / (1000*60*60)); + case Date.DAY: + return Math.floor(ret / (1000*60*60*24)); + case Date.MONTH: // this does not give exact number...?? + return ((date.format("Y") - this.format("Y")) * 12) + (date.format("m") - this.format("m")); + case Date.YEAR: // this does not give exact number...?? + return (date.format("Y") - this.format("Y")); + + case Date.MILLI: + default: + return ret; + } }; + // was in date file.. @@ -1292,17 +1425,17 @@ Date.createParser = function(format) { } code += "if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n" - + "{v = new Date(y, m, d, h, i, s);}\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);}\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);}\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);}\n" + + "{v = new Date(y, m, d); v.setFullYear(y);}\n" + "else if (y >= 0 && m >= 0)\n" - + "{v = new Date(y, m);}\n" + + "{v = new Date(y, m); v.setFullYear(y);}\n" + "else if (y >= 0)\n" - + "{v = new Date(y);}\n" + + "{v = new Date(y); v.setFullYear(y);}\n" + "}return (v && (z || o))?\n" // favour UTC offset over GMT offset + " ((z)? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n" // reset to UTC, then add offset + " v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n" // reset to GMT, then add offset @@ -1362,7 +1495,7 @@ Date.formatCodeToRegex = function(character, currentGroup) { s:"(\\d{1,2})"}; // Numeric representation of a month, without leading zeros case "m": return {g:1, - c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n", + c:"m = Math.max(0,parseInt(results[" + currentGroup + "], 10) - 1);\n", s:"(\\d{2})"}; // Numeric representation of a month, with leading zeros case "t": return {g:0, @@ -1797,22 +1930,13 @@ Date.prototype.add = function(interval, value){ } return d; }; -/* - * Based on: - * Ext JS Library 1.1.1 - * Copyright(c) 2006-2007, Ext JS, LLC. - * - * Originally Released Under LGPL - original licence link has changed is not relivant. - * - * Fork - LGPL - *