-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutil.js
82 lines (69 loc) · 2.41 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
Copyright 2014 - 2017 Cognizant Technology Solutions
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
**/
function Util() {
}
Util.isNullOrEmpty = function(value) {
if (value)
return value.toString().trim().length === 0;
return true;
};
Util.isNotNullOrEmpty = function(value) {
return !this.isNullOrEmpty(value);
};
Util.removeWhiteSpace = function(value) {
if(Util.isNotNullOrEmpty(value))
return value.toString().replace(/\s+/g, " ").trim();
return "";
};
Util.highlightElement = function(element) {
if (element) {
element.style.outline = Settings.highlightColor + " solid 2px";
if (!Util.rgbMatch(element.style.backgroundColor))
element.prevbackgroundColor = element.style.backgroundColor;
element.style.backgroundColor = Settings.highlightColorBg;
}
};
Util.deghlightElement = function(element) {
if (element) {
element.style.outline = "none";
element.style.backgroundColor = element.prevbackgroundColor;
}
};
if (typeof String.prototype.startsWith !== 'function') {
String.prototype.startsWith = function(str) {
return this.indexOf(str) === 0;
};
}
Util.rgb2hex = function(rgb) {
if (rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
return rgb;
};
Util.rgbMatch = function(rgb) {
if (rgb) {
rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/);
if (rgb) {
var checkrgb = Settings.highlightColorBg.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/);
for (var i = 1; i < 4; i++)
if (checkrgb[i] !== rgb[i])
return false;
return (rgb[4] && checkrgb[4] === parseFloat(rgb[4]).toPrecision(1));
}
}
return false;
};