-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtil.js
57 lines (41 loc) · 1.52 KB
/
Util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var Util = function Util() {
};
Util.prototype.reFormatNumeric = function reFormatNumeric(e) {
var value = e.target.value;
return value.replace(/\D/g, '');
};
Util.prototype.restrictNumeric = function restrictNumeric(e) {
console.log('restrictNumeric');
console.log(this);
// console.log(e.target.value);
// # Key event is for a browser shortcut
if(e.metaKey || e.ctrlKey) return true;
// # If keycode is a space
if(e.which == 32) return true;
// # If keycode is a special char (WebKit)
if(e.which == 0) return true;
// # If char is a special char (Firefox)
if(e.which < 33) return true;
var input = String.fromCharCode(e.which);
// # Char is a number or a space
if(!/[\d\s]/.test(input)) {
e.preventDefault();
return false;
}
return true;
};
Util.prototype.hasTextSelected = function hasTextSelected(target) {
console.log('hasTextSelected', (target.selectionStart != null &&
target.selectionStart != target.selectionEnd));
console.log('target.selectionStart != null', target.selectionStart != null);
console.log('target.selectionEnd', target.selectionEnd);
console.log('target.selectionStart != target.selectionEnd', target.selectionStart != target.selectionEnd);
// # If some text is selected
return (target.selectionStart != null &&
target.selectionStart != target.selectionEnd);
// # If some text is selected in IE
// if document?.selection?.createRange?
// return true if document.selection.createRange().text
// return false;
};
module.exports = Util;