All "edit.js" development has moved to a new repository
"Code-Blocks.javascript-utils"
This commit is contained in:
@@ -206,29 +206,57 @@ function __(string)
|
|||||||
if (!String.prototype.format) {
|
if (!String.prototype.format) {
|
||||||
String.prototype.format = function()
|
String.prototype.format = function()
|
||||||
{
|
{
|
||||||
var args = arguments;
|
console.error('[DEPRECATED] use formatString');
|
||||||
return this.replace(/{(\d+)}/g, function(match, number)
|
return formatString(this, arguments);
|
||||||
{
|
|
||||||
return typeof args[number] != 'undefined' ?
|
|
||||||
args[number] :
|
|
||||||
match
|
|
||||||
;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* simple sprintf formater for replace
|
||||||
|
* usage: "{0} is cool, {1} is not".format("Alpha", "Beta");
|
||||||
|
* First, checks if it isn't implemented yet.
|
||||||
|
* @param {String} string String with {..} entries
|
||||||
|
* @param {...any} args List of replacement
|
||||||
|
* @returns {String} Escaped string
|
||||||
|
*/
|
||||||
|
function formatString(string, ...args)
|
||||||
|
{
|
||||||
|
return string.replace(/{(\d+)}/g, function(match, number)
|
||||||
|
{
|
||||||
|
return typeof args[number] != 'undefined' ?
|
||||||
|
args[number] :
|
||||||
|
match
|
||||||
|
;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* round to digits (float)
|
* round to digits (float)
|
||||||
* @param {Float} Number.prototype.round Float type number to round
|
* @param {Number} Number.prototype.round Float type number to round
|
||||||
* @param {Number} prec Precision to round to
|
* @param {Number} prec Precision to round to
|
||||||
* @return {Float} Rounded number
|
* @return {Float} Rounded number
|
||||||
*/
|
*/
|
||||||
if (Number.prototype.round) {
|
if (Number.prototype.round) {
|
||||||
Number.prototype.round = function (prec) {
|
Number.prototype.round = function (prec) {
|
||||||
return Math.round(this * Math.pow(10, prec)) / Math.pow(10, prec);
|
console.error('[DEPRECATED] use roundPrecision');
|
||||||
|
return roundPrecision(this, prec);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* round to digits (float)
|
||||||
|
* @param {Number} number Float type number to round
|
||||||
|
* @param {Number} precision Precision to round to
|
||||||
|
* @return {Number} Rounded number
|
||||||
|
*/
|
||||||
|
function roundPrecision(number, precision)
|
||||||
|
{
|
||||||
|
if (!isNaN(number) || !isNaN(precision)) {
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
return Math.round(number * Math.pow(10, precision)) / Math.pow(10, precision);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* formats flat number 123456 to 123,456
|
* formats flat number 123456 to 123,456
|
||||||
* @param {Number} x number to be formated
|
* @param {Number} x number to be formated
|
||||||
@@ -253,48 +281,70 @@ function convertLBtoBR(string) // eslint-disable-line no-unused-vars
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* escape HTML string
|
* escape HTML string
|
||||||
* @param {String} !String.prototype.escapeHTML HTML data string to be escaped
|
* @param {String} String.prototype.escapeHTML HTML data string to be escaped
|
||||||
* @return {String} escaped string
|
* @return {String} escaped string
|
||||||
*/
|
*/
|
||||||
if (!String.prototype.escapeHTML) {
|
if (!String.prototype.escapeHTML) {
|
||||||
String.prototype.escapeHTML = function() {
|
String.prototype.escapeHTML = function() {
|
||||||
return this.replace(/[&<>"'/]/g, function (s) {
|
console.error('[DEPRECATED] use escapeHtml');
|
||||||
var entityMap = {
|
return escapeHtml(this);
|
||||||
'&': '&',
|
|
||||||
'<': '<',
|
|
||||||
'>': '>',
|
|
||||||
'"': '"',
|
|
||||||
'\'': ''',
|
|
||||||
'/': '/'
|
|
||||||
};
|
|
||||||
|
|
||||||
return entityMap[s];
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unescape a HTML encoded string
|
* unescape a HTML encoded string
|
||||||
* @param {String} !String.prototype.unescapeHTML data with escaped entries
|
* @param {String} String.prototype.unescapeHTML data with escaped entries
|
||||||
* @return {String} HTML formated string
|
* @return {String} HTML formated string
|
||||||
*/
|
*/
|
||||||
if (!String.prototype.unescapeHTML) {
|
if (!String.prototype.unescapeHTML) {
|
||||||
String.prototype.unescapeHTML = function() {
|
String.prototype.unescapeHTML = function() {
|
||||||
return this.replace(/&[#\w]+;/g, function (s) {
|
console.error('[DEPRECATED] use unescapeHtml');
|
||||||
var entityMap = {
|
return unescapeHtml(this);
|
||||||
'&': '&',
|
|
||||||
'<': '<',
|
|
||||||
'>': '>',
|
|
||||||
'"': '"',
|
|
||||||
''': '\'',
|
|
||||||
'/': '/'
|
|
||||||
};
|
|
||||||
|
|
||||||
return entityMap[s];
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escapes HTML in string
|
||||||
|
* @param {String} string Text to escape HTML in
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
function escapeHtml(string)
|
||||||
|
{
|
||||||
|
return string.replace(/[&<>"'/]/g, function (s) {
|
||||||
|
var entityMap = {
|
||||||
|
'&': '&',
|
||||||
|
'<': '<',
|
||||||
|
'>': '>',
|
||||||
|
'"': '"',
|
||||||
|
'\'': ''',
|
||||||
|
'/': '/'
|
||||||
|
};
|
||||||
|
|
||||||
|
return entityMap[s];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unescape a HTML encoded string
|
||||||
|
* @param {String} string Text to unescape HTML in
|
||||||
|
* @returns {String}
|
||||||
|
*/
|
||||||
|
function unescapeHtml(string)
|
||||||
|
{
|
||||||
|
return string.replace(/&[#\w]+;/g, function (s) {
|
||||||
|
var entityMap = {
|
||||||
|
'&': '&',
|
||||||
|
'<': '<',
|
||||||
|
'>': '>',
|
||||||
|
'"': '"',
|
||||||
|
''': '\'',
|
||||||
|
'/': '/'
|
||||||
|
};
|
||||||
|
|
||||||
|
return entityMap[s];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns current timestamp (unix timestamp)
|
* returns current timestamp (unix timestamp)
|
||||||
* @return {Number} timestamp (in milliseconds)
|
* @return {Number} timestamp (in milliseconds)
|
||||||
|
|||||||
5
www/admin/layout/javascript/translateTest-ja_JP.UTF-8.js
Normal file
5
www/admin/layout/javascript/translateTest-ja_JP.UTF-8.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
var i18n = {
|
||||||
|
"Original": "Translated"
|
||||||
|
};
|
||||||
|
|
||||||
|
// __END__
|
||||||
1540
www/admin/layout/javascript/utils.js
Normal file
1540
www/admin/layout/javascript/utils.js
Normal file
File diff suppressed because it is too large
Load Diff
3
www/admin/layout/javascript/utils.min.js
vendored
Normal file
3
www/admin/layout/javascript/utils.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
7
www/admin/layout/javascript/utils.min.js.map
Normal file
7
www/admin/layout/javascript/utils.min.js.map
Normal file
File diff suppressed because one or more lines are too long
37
www/admin/test.javascript.html
Normal file
37
www/admin/test.javascript.html
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<head>
|
||||||
|
<title>JavaScript Test</title>
|
||||||
|
<script type="text/javascript" src="layout/javascript/jquery.min.js"></script>
|
||||||
|
<script type="text/javascript" src="layout/javascript/translateTest-ja_JP.UTF-8.js"></script>
|
||||||
|
<script type="text/javascript" src="layout/javascript/utils.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
<h1>JavaScript tests</h1>
|
||||||
|
<div id="test-div">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
<script languagae="JavaScript">
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
console.log('MAIN PAGE LOADED');
|
||||||
|
// console.log('Random: %o', mh.randomIdF());
|
||||||
|
console.log('Random: %o', randomIdF());
|
||||||
|
console.log("GW: %o", getWindowSize());
|
||||||
|
let bytes = 1021152;
|
||||||
|
console.log('FB: %o', formatBytes(bytes));
|
||||||
|
console.log('FBL: %o', formatBytesLong(bytes));
|
||||||
|
console.log('TR: %s', l10n.__('Original'));
|
||||||
|
console.log('TR: %s', l10n.__('Not exists'));
|
||||||
|
|
||||||
|
setCenter('test-div', true, true);
|
||||||
|
ClearCall();
|
||||||
|
overlayBoxShow();
|
||||||
|
actionIndicatorShow('testSmarty');
|
||||||
|
setTimeout(function() {
|
||||||
|
console.log('Waiting dummy ...');
|
||||||
|
actionIndicatorHide('testSmarty');
|
||||||
|
ClearCall();
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user