Commit fb741cbd8db1eaad223142880bcb17fde4be60fa
1 parent
ca196a72
优化divider组件
Showing
5 changed files
with
87 additions
and
14 deletions
Show diff stats
build/Common/Common.js
| 1 | 1 | import baseStyle from "antd/lib/style/index.css"; |
| 2 | -angular.module("esNgAntd").directive(function () { | |
| 3 | - return { | |
| 4 | - restrict: "E", | |
| 5 | - replace: true, | |
| 6 | - transclude: true | |
| 2 | +angular.module("esNgAntd").service("esNgAntd", ["$compile", function ($compile) { | |
| 3 | + this.styleSheets = null; | |
| 4 | + this.conflictType = null; | |
| 5 | + | |
| 6 | + this.createStyle = function (key, style) { | |
| 7 | + if (!document.querySelector("#antd")) { | |
| 8 | + let styleElement = document.createElement("style"); | |
| 9 | + styleElement.setAttribute("id", "antd"); | |
| 10 | + styleElement.setAttribute("type", "text/css"); | |
| 11 | + styleElement.innerHTML = baseStyle.toString(); | |
| 12 | + document.head.appendChild(styleElement); | |
| 13 | + | |
| 14 | + if (this.styleSheets) { | |
| 15 | + this.disableStyle("anticon"); | |
| 16 | + } | |
| 17 | + } | |
| 18 | + | |
| 19 | + if (!document.querySelector("#" + key)) { | |
| 20 | + let styleElement = document.createElement("style"); | |
| 21 | + styleElement.setAttribute("id", key); | |
| 22 | + styleElement.setAttribute("type", "text/css"); | |
| 23 | + styleElement.innerHTML = style.toString(); | |
| 24 | + document.head.appendChild(styleElement); | |
| 25 | + | |
| 26 | + if (this.styleSheets) { | |
| 27 | + this.disableStyle(key); | |
| 28 | + } | |
| 29 | + } | |
| 7 | 30 | }; |
| 8 | -}); | |
| 9 | 31 | \ No newline at end of file |
| 32 | + | |
| 33 | + this.disableStyle = function (name) { | |
| 34 | + for (let i = 0; i < this.styleSheets.cssRules.length; i++) { | |
| 35 | + let rule = this.styleSheets.cssRules[i]; | |
| 36 | + | |
| 37 | + if (rule.selectorText && rule.selectorText.indexOf(name) !== -1 && rule.selectorText.indexOf("ant3") === -1) { | |
| 38 | + rule.selectorText = rule.selectorText.split(",").map(function (item) { | |
| 39 | + return ".ant3 " + item; | |
| 40 | + }).join(","); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + }; | |
| 44 | + | |
| 45 | + this.conflict = function (filename, type) { | |
| 46 | + this.conflictType = type; | |
| 47 | + | |
| 48 | + for (let i = 0; i < document.styleSheets.length; i++) { | |
| 49 | + const element = document.styleSheets[i]; | |
| 50 | + | |
| 51 | + if (element.href && element.href.indexOf(filename) !== -1) { | |
| 52 | + this.styleSheets = element; | |
| 53 | + } | |
| 54 | + } | |
| 55 | + }; | |
| 56 | + | |
| 57 | + this.clearAttribute = function (element, attrs) { | |
| 58 | + for (const attr of attrs) { | |
| 59 | + element.removeAttribute(attr); | |
| 60 | + } | |
| 61 | + }; | |
| 62 | + | |
| 63 | + this.createLayer = function (content, scope) { | |
| 64 | + let div = document.createElement("div"); | |
| 65 | + div.innerHTML = content; | |
| 66 | + document.body.appendChild(div); | |
| 67 | + $compile(div)(scope); | |
| 68 | + }; | |
| 69 | + | |
| 70 | + this.getOffset = function (ele) { | |
| 71 | + if (!ele || ele.nodeType != 1) { | |
| 72 | + return; | |
| 73 | + } | |
| 74 | + | |
| 75 | + let rect = ele.getBoundingClientRect(); | |
| 76 | + let doc = ele.ownerDocument.documentElement; | |
| 77 | + return { | |
| 78 | + top: rect.top + window.pageYOffset - doc.clientTop, | |
| 79 | + left: rect.left + window.pageXOffset - doc.clientLeft | |
| 80 | + }; | |
| 81 | + }; | |
| 82 | +}]); | |
| 10 | 83 | \ No newline at end of file | ... | ... |
build/Divider/Divider.js
dist/ng-antd.js
| ... | ... | @@ -104,7 +104,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Col |
| 104 | 104 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
| 105 | 105 | |
| 106 | 106 | "use strict"; |
| 107 | -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var antd_lib_style_index_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! antd/lib/style/index.css */ \"./node_modules/antd/lib/style/index.css\");\n\nangular.module(\"esNgAntd\").directive(function () {\n return {\n restrict: \"E\",\n replace: true,\n transclude: true\n };\n});\n\n//# sourceURL=webpack://ng-antd/./build/Common/Common.js?"); | |
| 107 | +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var antd_lib_style_index_css__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! antd/lib/style/index.css */ \"./node_modules/antd/lib/style/index.css\");\n\nangular.module(\"esNgAntd\").service(\"esNgAntd\", [\"$compile\", function ($compile) {\n this.styleSheets = null;\n this.conflictType = null;\n\n this.createStyle = function (key, style) {\n if (!document.querySelector(\"#antd\")) {\n let styleElement = document.createElement(\"style\");\n styleElement.setAttribute(\"id\", \"antd\");\n styleElement.setAttribute(\"type\", \"text/css\");\n styleElement.innerHTML = antd_lib_style_index_css__WEBPACK_IMPORTED_MODULE_0__[\"default\"].toString();\n document.head.appendChild(styleElement);\n\n if (this.styleSheets) {\n this.disableStyle(\"anticon\");\n }\n }\n\n if (!document.querySelector(\"#\" + key)) {\n let styleElement = document.createElement(\"style\");\n styleElement.setAttribute(\"id\", key);\n styleElement.setAttribute(\"type\", \"text/css\");\n styleElement.innerHTML = style.toString();\n document.head.appendChild(styleElement);\n\n if (this.styleSheets) {\n this.disableStyle(key);\n }\n }\n };\n\n this.disableStyle = function (name) {\n for (let i = 0; i < this.styleSheets.cssRules.length; i++) {\n let rule = this.styleSheets.cssRules[i];\n\n if (rule.selectorText && rule.selectorText.indexOf(name) !== -1 && rule.selectorText.indexOf(\"ant3\") === -1) {\n rule.selectorText = rule.selectorText.split(\",\").map(function (item) {\n return \".ant3 \" + item;\n }).join(\",\");\n }\n }\n };\n\n this.conflict = function (filename, type) {\n this.conflictType = type;\n\n for (let i = 0; i < document.styleSheets.length; i++) {\n const element = document.styleSheets[i];\n\n if (element.href && element.href.indexOf(filename) !== -1) {\n this.styleSheets = element;\n }\n }\n };\n\n this.clearAttribute = function (element, attrs) {\n for (const attr of attrs) {\n element.removeAttribute(attr);\n }\n };\n\n this.createLayer = function (content, scope) {\n let div = document.createElement(\"div\");\n div.innerHTML = content;\n document.body.appendChild(div);\n $compile(div)(scope);\n };\n\n this.getOffset = function (ele) {\n if (!ele || ele.nodeType != 1) {\n return;\n }\n\n let rect = ele.getBoundingClientRect();\n let doc = ele.ownerDocument.documentElement;\n return {\n top: rect.top + window.pageYOffset - doc.clientTop,\n left: rect.left + window.pageXOffset - doc.clientLeft\n };\n };\n}]);\n\n//# sourceURL=webpack://ng-antd/./build/Common/Common.js?"); | |
| 108 | 108 | |
| 109 | 109 | /***/ }), |
| 110 | 110 | |
| ... | ... | @@ -115,7 +115,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var antd |
| 115 | 115 | /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
| 116 | 116 | |
| 117 | 117 | "use strict"; |
| 118 | -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Divider_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Divider.html */ \"./build/Divider/Divider.html\");\n/* harmony import */ var antd_lib_divider_style_index_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! antd/lib/divider/style/index.css */ \"./node_modules/antd/lib/divider/style/index.css\");\n\n\nangular.module(\"esNgAntd\").directive(\"antdDivider\", function (esNgAntd) {\n return {\n controllerAs: \"antdDivider\",\n restrict: \"E\",\n transclude: true,\n replace: true,\n template: _Divider_html__WEBPACK_IMPORTED_MODULE_0__[\"default\"],\n link: function ($scope, $element, $attrs, $controllers, $transclude) {\n esNgAntd.createStyle(\"ant-divider\", antd_lib_divider_style_index_css__WEBPACK_IMPORTED_MODULE_1__[\"default\"]);\n },\n };\n});\n\n\n//# sourceURL=webpack://ng-antd/./build/Divider/Divider.js?"); | |
| 118 | +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _Divider_html__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Divider.html */ \"./build/Divider/Divider.html\");\n/* harmony import */ var antd_lib_divider_style_index_css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! antd/lib/divider/style/index.css */ \"./node_modules/antd/lib/divider/style/index.css\");\n\n\nangular.module(\"esNgAntd\").directive(\"antdDivider\", [\"esNgAntd\", function (esNgAntd) {\n return {\n template: _Divider_html__WEBPACK_IMPORTED_MODULE_0__[\"default\"],\n restrict: \"E\",\n replace: true,\n transclude: true,\n link: function ($scope) {\n esNgAntd.createStyle(\"ant-divider\", antd_lib_divider_style_index_css__WEBPACK_IMPORTED_MODULE_1__[\"default\"]);\n }\n };\n}]);\n\n//# sourceURL=webpack://ng-antd/./build/Divider/Divider.js?"); | |
| 119 | 119 | |
| 120 | 120 | /***/ }), |
| 121 | 121 | ... | ... |
package.json
yarn.lock
| ... | ... | @@ -1320,10 +1320,10 @@ babel-plugin-polyfill-regenerator@^0.2.3: |
| 1320 | 1320 | dependencies: |
| 1321 | 1321 | "@babel/helper-define-polyfill-provider" "^0.2.4" |
| 1322 | 1322 | |
| 1323 | -beanboom@^0.9.8: | |
| 1324 | - version "0.9.8" | |
| 1325 | - resolved "https://registry.npmmirror.com/beanboom/-/beanboom-0.9.8.tgz#1b6512af484e2e302da9a1d4d48428a0c2bc7763" | |
| 1326 | - integrity sha512-liLptwNuZqFxsCjkmQ0AByvQ30mmKqrUYn++DoyErnxKuvfYutWeloXcd3abW3BN6eHlxycrr7ft4Ha+qlXNcw== | |
| 1323 | +beanboom@^0.9.9: | |
| 1324 | + version "0.9.9" | |
| 1325 | + resolved "https://registry.npmmirror.com/beanboom/-/beanboom-0.9.9.tgz#a055a5d404cba9e50ada5862bec0bc7f3ae3d427" | |
| 1326 | + integrity sha512-hEkZ2IcEXT50T20OeZiaGUjQwlGTY3vMAqVOfKd/HqRzZIXD05Jv6xeimoW43HnFs5QDOveK5n9kahimURvf3w== | |
| 1327 | 1327 | dependencies: |
| 1328 | 1328 | "@babel/core" "^7.12.10" |
| 1329 | 1329 | "@babel/plugin-proposal-class-properties" "^7.13.0" | ... | ... |