Blame view

build/Common/Common.js 3.05 KB
3a3ecabe   Imshann   init
1
  import baseStyle from "antd/lib/style/index.css";
f886eef1   Imshann   优化Alert、Breadcrumb
2
  
1b6f912f   Imshann   优化
3
4
5
6
  angular.module("esNgAntd").service("esNgAntd", [
      "$compile",
      function ($compile) {
          this.styleSheets = null;
f886eef1   Imshann   优化Alert、Breadcrumb
7
  
fe17acf4   Imshann   优化组件
8
          this.conflictType = null;
1b6f912f   Imshann   优化
9
10
11
12
13
14
15
16
  
          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);
fe17acf4   Imshann   优化组件
17
18
19
                  if (this.styleSheets) {
                      this.disableStyle("anticon");
                  }
3a3ecabe   Imshann   init
20
              }
1b6f912f   Imshann   优化
21
22
23
24
25
26
              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);
1b6f912f   Imshann   优化
27
28
29
                  if (this.styleSheets) {
                      this.disableStyle(key);
                  }
3a3ecabe   Imshann   init
30
              }
1b6f912f   Imshann   优化
31
          };
3a3ecabe   Imshann   init
32
  
1b6f912f   Imshann   优化
33
34
35
          this.disableStyle = function (name) {
              for (let i = 0; i < this.styleSheets.cssRules.length; i++) {
                  let rule = this.styleSheets.cssRules[i];
1b6f912f   Imshann   优化
36
37
                  if (
                      rule.selectorText &&
fe17acf4   Imshann   优化组件
38
39
                      rule.selectorText.indexOf(name) !== -1 &&
                      rule.selectorText.indexOf("ant3") === -1
1b6f912f   Imshann   优化
40
                  ) {
fe17acf4   Imshann   优化组件
41
42
43
44
45
46
                      rule.selectorText = rule.selectorText
                          .split(",")
                          .map(function (item) {
                              return ".ant3 " + item;
                          })
                          .join(",");
1b6f912f   Imshann   优化
47
                  }
3a3ecabe   Imshann   init
48
              }
1b6f912f   Imshann   优化
49
50
          };
  
fe17acf4   Imshann   优化组件
51
52
          this.conflict = function (filename, type) {
              this.conflictType = type;
1b6f912f   Imshann   优化
53
54
              for (let i = 0; i < document.styleSheets.length; i++) {
                  const element = document.styleSheets[i];
1b6f912f   Imshann   优化
55
56
57
58
59
60
                  if (element.href && element.href.indexOf(filename) !== -1) {
                      this.styleSheets = element;
                  }
              }
          };
  
f886eef1   Imshann   优化Alert、Breadcrumb
61
62
63
64
65
66
          this.clearAttribute = function (element, attrs) {
              for (const attr of attrs) {
                  element.removeAttribute(attr)
              }
          }
  
1b6f912f   Imshann   优化
67
68
69
70
71
72
          this.createLayer = function (content, scope) {
              let div = document.createElement("div");
              div.innerHTML = content;
              document.body.appendChild(div);
              $compile(div)(scope);
          };
6fcf6aec   Imshann   feat(popover): 优化组件
73
74
75
76
77
  
          this.getOffset = function (ele) {
              if (!ele || ele.nodeType != 1) {
                  return;
              }
6fcf6aec   Imshann   feat(popover): 优化组件
78
79
80
81
82
83
84
              let rect = ele.getBoundingClientRect();
              let doc = ele.ownerDocument.documentElement;
              return {
                  top: rect.top + window.pageYOffset - doc.clientTop,
                  left: rect.left + window.pageXOffset - doc.clientLeft,
              };
          };
1b6f912f   Imshann   优化
85
86
      },
  ]);