Blame view

src/Common/Common.js 1.95 KB
3a3ecabe   Imshann   init
1
2
  import baseStyle from "antd/lib/style/index.css";
  
1b6f912f   Imshann   优化
3
  angular.module("esNgAntd").service("esNgAntd", ["$compile", function ($compile) {
3a3ecabe   Imshann   init
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
      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];
1b6f912f   Imshann   优化
29
              if (rule.selectorText && rule.selectorText.indexOf(name) !== -1) {
3a3ecabe   Imshann   init
30
                  rule.selectorText = rule.selectorText.replace(
061629e7   Imshann   add
31
                      /\.ant\-/g,
1b6f912f   Imshann   优化
32
                      ".disabled-ant-"
3a3ecabe   Imshann   init
33
                  );
061629e7   Imshann   add
34
                  console.log(rule.selectorText);
3a3ecabe   Imshann   init
35
36
37
38
39
40
41
42
43
44
45
46
              }
          }
      };
  
      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;
              }
          }
      };
1b6f912f   Imshann   优化
47
48
49
50
51
52
53
54
  
      this.createLayer = function (content, scope) {
          let div = document.createElement("div");
          div.innerHTML = content;
          document.body.appendChild(div);
          $compile(div)(scope);
      };
  }]);