Difference between revisions of "Core"
From CCIL
(→Maven) |
|||
Line 5: | Line 5: | ||
==== Maven ==== | ==== Maven ==== | ||
<pre> | <pre> | ||
− | + | <dependency> | |
+ | <groupId>net.ccil</groupId> | ||
+ | <version>${ccil.version}</version> | ||
+ | <artifactId>ccil-ui-web</artifactId> | ||
+ | <scope>runtime</scope> | ||
+ | <type>war</type> | ||
+ | </dependency> | ||
</pre> | </pre> | ||
Revision as of 08:46, 15 April 2017
Contents
Include
Maven
<dependency> <groupId>net.ccil</groupId> <version>${ccil.version}</version> <artifactId>ccil-ui-web</artifactId> <scope>runtime</scope> <type>war</type> </dependency>
API
String Prototypes
contains
String.prototype.contains = function(str, ignoreCase) { return (ignoreCase ? this.toUpperCase() : this) .indexOf(ignoreCase ? str.toUpperCase() : str) >= 0; };
endsWith
String.prototype.endsWith = function(suffix) { return this.indexOf(suffix, this.length - suffix.length) !== -1; };
replaceAll
String.prototype.replaceAll = function(search, replacement) { var target = this; return target.replace(new RegExp(search, 'g'), replacement); };
Utils
General
isFunction
CCIL.utils.isFunction = function(functionToCheck) { var getType = {}; return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]'; }
isDefined
CCIL.utils.isDefined = function(val) { return !CCIL.utils.isUndefined(val); }
isUndefined
CCIL.utils.isUndefined = function(val) { return (typeof val === 'undefined'); }
isNull
CCIL.utils.isNull = function(val) { return url === null; }
isVal
CCIL.utils.isVal = function(val) { return CCIL.utils.isDefined(val) && (!CCIL.utils.isNull(val)); }
Color
randomColor
CCIL.utils.randomColor = function() { var letters = '0123456789ABCDEF'.split(''); var color = '#'; for (var i = 0; i < 6; i++) { color += letters[Math.floor(Math.random() * 16)]; } return color; }
System
parentFolder =
CCIL.utils.parentFolder = function(targetFile) { var index = targetFile.lastIndexOf('/'); if (index > 0) { var parentFolder = targetFile.substring(0, index); // , // targetFile.length return parentFolder; } else { return ''; } }
getParam
CCIL.utils.getParam = function(val) { var result = null, tmp = []; location.search // .replace ( "?", "" ) // this is better, there might be a question mark inside .substr(1).split("&").forEach(function(item) { tmp = item.split("="); if (tmp[0] === val) result = decodeURIComponent(tmp[1]); }); return result; }
JSON
toJSON
CCIL.utils.toJSON = function(val) { // convert to JSON string var json = JSON.stringify(val); // patch if (!(typeof json == 'undefined')) { json = json.split('&').join('__AMP__'); json = json.split('%').join('__PERCENT__'); } else { json = 'null'; } return json; }
fromJSON
CCIL.utils.fromJSON = function(val) { val = val.split('__AMP__').join('&'); val = val.split('__PERCENT__').join('%'); return JSON.parse(val); }
General
humanFileSize
CCIL.utils.humanFileSize = function(bytes) { return CCIL.utils.humanFileSize(bytes, false); } CCIL.utils.humanFileSize = function(bytes, si) { var thresh = si ? 1000 : 1024; if (Math.abs(bytes) < thresh) { return bytes + ' B'; } var units = si ? [ 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ] : [ 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB' ]; var u = -1; do { bytes /= thresh; ++u; } while (Math.abs(bytes) >= thresh && u < units.length - 1); return bytes.toFixed(1) + ' ' + units[u]; }
Shurtcuts
shortcutChars
CCIL.utils.shortcutChars = '1234567890qwertyuiop[]asdfghjkl;zxcvbnm';
shortuctIndex
CCIL.utils.shortuctIndex = function(_char) { var res = String.fromCharCode(_char); var index = CCIL.utils.shortcutChars.indexOf(res); if (index == -1) { CCIL.log('ERROR: unknown charecter (' + _char + ').'); return null; } return index; }
shortcutSymbol =
CCIL.utils.shortcutSymbol = function(index) { if (index >= CCIL.utils.shortcutChars.length) { CCIL.log('ERROR: index is greater than the vailable charecters (' + index + ').'); return null; } return CCIL.utils.shortcutChars.charAt(index); }