1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.get = get;
|
7 | exports.getClientSize = getClientSize;
|
8 | exports.getDocSize = getDocSize;
|
9 | exports.getOffset = getOffset;
|
10 | exports.getOuterHeight = getOuterHeight;
|
11 | exports.getOuterWidth = getOuterWidth;
|
12 | exports.getScroll = getScroll;
|
13 | exports.set = set;
|
14 | /* eslint-disable no-nested-ternary */
|
15 | var PIXEL_PATTERN = /margin|padding|width|height|max|min|offset/;
|
16 | var removePixel = {
|
17 | left: true,
|
18 | top: true
|
19 | };
|
20 | var floatMap = {
|
21 | cssFloat: 1,
|
22 | styleFloat: 1,
|
23 | float: 1
|
24 | };
|
25 | function getComputedStyle(node) {
|
26 | return node.nodeType === 1 ? node.ownerDocument.defaultView.getComputedStyle(node, null) : {};
|
27 | }
|
28 | function getStyleValue(node, type, value) {
|
29 | type = type.toLowerCase();
|
30 | if (value === 'auto') {
|
31 | if (type === 'height') {
|
32 | return node.offsetHeight;
|
33 | }
|
34 | if (type === 'width') {
|
35 | return node.offsetWidth;
|
36 | }
|
37 | }
|
38 | if (!(type in removePixel)) {
|
39 | removePixel[type] = PIXEL_PATTERN.test(type);
|
40 | }
|
41 | return removePixel[type] ? parseFloat(value) || 0 : value;
|
42 | }
|
43 | function get(node, name) {
|
44 | var length = arguments.length;
|
45 | var style = getComputedStyle(node);
|
46 | name = floatMap[name] ? 'cssFloat' in node.style ? 'cssFloat' : 'styleFloat' : name;
|
47 | return length === 1 ? style : getStyleValue(node, name, style[name] || node.style[name]);
|
48 | }
|
49 | function set(node, name, value) {
|
50 | var length = arguments.length;
|
51 | name = floatMap[name] ? 'cssFloat' in node.style ? 'cssFloat' : 'styleFloat' : name;
|
52 | if (length === 3) {
|
53 | if (typeof value === 'number' && PIXEL_PATTERN.test(name)) {
|
54 | value = "".concat(value, "px");
|
55 | }
|
56 | node.style[name] = value;
|
57 | return value;
|
58 | }
|
59 | for (var x in name) {
|
60 | if (name.hasOwnProperty(x)) {
|
61 | set(node, x, name[x]);
|
62 | }
|
63 | }
|
64 | return getComputedStyle(node);
|
65 | }
|
66 | function getOuterWidth(el) {
|
67 | if (el === document.body) {
|
68 | return document.documentElement.clientWidth;
|
69 | }
|
70 | return el.offsetWidth;
|
71 | }
|
72 | function getOuterHeight(el) {
|
73 | if (el === document.body) {
|
74 | return window.innerHeight || document.documentElement.clientHeight;
|
75 | }
|
76 | return el.offsetHeight;
|
77 | }
|
78 | function getDocSize() {
|
79 | var width = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
|
80 | var height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
|
81 | return {
|
82 | width: width,
|
83 | height: height
|
84 | };
|
85 | }
|
86 | function getClientSize() {
|
87 | var width = document.documentElement.clientWidth;
|
88 | var height = window.innerHeight || document.documentElement.clientHeight;
|
89 | return {
|
90 | width: width,
|
91 | height: height
|
92 | };
|
93 | }
|
94 | function getScroll() {
|
95 | return {
|
96 | scrollLeft: Math.max(document.documentElement.scrollLeft, document.body.scrollLeft),
|
97 | scrollTop: Math.max(document.documentElement.scrollTop, document.body.scrollTop)
|
98 | };
|
99 | }
|
100 | function getOffset(node) {
|
101 | var box = node.getBoundingClientRect();
|
102 | var docElem = document.documentElement;
|
103 |
|
104 |
|
105 | return {
|
106 | left: box.left + (window.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || document.body.clientLeft || 0),
|
107 | top: box.top + (window.pageYOffset || docElem.scrollTop) - (docElem.clientTop || document.body.clientTop || 0)
|
108 | };
|
109 | } |
\ | No newline at end of file |