mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-02 02:51:53 +08:00
refactoring + some tools
This commit is contained in:
@@ -64,6 +64,17 @@ export var tools = new function() {
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
self.escape = function(text) {
|
||||
return text.replace(
|
||||
/[^0-9A-Za-z ]/g,
|
||||
ch => "&#" + ch.charCodeAt(0) + ";"
|
||||
);
|
||||
};
|
||||
|
||||
self.makeClosure = function(func, ...args) {
|
||||
return () => func(...args);
|
||||
};
|
||||
|
||||
self.upperFirst = function(text) {
|
||||
return text[0].toUpperCase() + text.slice(1);
|
||||
};
|
||||
@@ -87,6 +98,10 @@ export var tools = new function() {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
};
|
||||
|
||||
self.formatHex = function(value) {
|
||||
return `0x${value.toString(16).toUpperCase()}`;
|
||||
};
|
||||
|
||||
self.formatSize = function(size) {
|
||||
if (size > 0) {
|
||||
let index = Math.floor( Math.log(size) / Math.log(1024) );
|
||||
@@ -283,9 +298,9 @@ export var tools = new function() {
|
||||
option.className = "comment";
|
||||
el.add(option);
|
||||
},
|
||||
"addSeparator": function(el) {
|
||||
"addSeparator": function(el, repeat=30) {
|
||||
if (!self.browser.is_mobile) {
|
||||
self.selector.addComment(el, "\u2500".repeat(30));
|
||||
self.selector.addComment(el, "\u2500".repeat(repeat));
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user