Common.js
1.9 KB
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
import baseStyle from "antd/lib/style/index.css";
angular.module("esNgAntd").service("esNgAntd", ["$compile", function ($compile) {
this.styleSheets = null;
this.createStyle = function (key, style) {
if (!document.querySelector("#antd")) {
let styleElement = document.createElement("style");
styleElement.setAttribute("id", "antd");
styleElement.setAttribute("type", "text/css");
styleElement.innerHTML = baseStyle.toString();
document.head.appendChild(styleElement);
}
if (!document.querySelector("#" + key)) {
let styleElement = document.createElement("style");
styleElement.setAttribute("id", key);
styleElement.setAttribute("type", "text/css");
styleElement.innerHTML = style.toString();
document.head.appendChild(styleElement);
if (this.styleSheets) {
this.disableStyle(key);
}
}
};
this.disableStyle = function (name) {
for (let i = 0; i < this.styleSheets.cssRules.length; i++) {
let rule = this.styleSheets.cssRules[i];
if (rule.selectorText && rule.selectorText.indexOf(name) !== -1) {
rule.selectorText = rule.selectorText.replace(
/\.ant-/g,
".disabled-ant-"
);
}
}
};
this.conflict = function (filename) {
for (let i = 0; i < document.styleSheets.length; i++) {
const element = document.styleSheets[i];
if (element.href && element.href.indexOf(filename) !== -1) {
this.styleSheets = element;
}
}
};
this.createLayer = function (content, scope) {
let div = document.createElement("div");
div.innerHTML = content;
document.body.appendChild(div);
$compile(div)(scope);
};
}]);