uikit 3.11.2-dev.19d26d0f9 → 3.11.2-dev.21a5b7139
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +4 -49
- package/.prettierignore +14 -0
- package/.prettierrc.json +13 -0
- package/.webstorm.js +3 -3
- package/CHANGELOG.md +16 -1
- package/build/.eslintrc.json +1 -3
- package/build/build.js +26 -28
- package/build/icons.js +7 -11
- package/build/less.js +48 -36
- package/build/package.json +2 -2
- package/build/prefix.js +21 -18
- package/build/publishDev.js +6 -8
- package/build/release.js +20 -17
- package/build/scope.js +21 -11
- package/build/scss.js +72 -39
- package/build/util.js +71 -62
- package/build/wrapper/icons.js +0 -2
- package/dist/css/uikit-core-rtl.css +42 -17
- package/dist/css/uikit-core-rtl.min.css +1 -1
- package/dist/css/uikit-core.css +42 -17
- package/dist/css/uikit-core.min.css +1 -1
- package/dist/css/uikit-rtl.css +42 -17
- package/dist/css/uikit-rtl.min.css +1 -1
- package/dist/css/uikit.css +42 -17
- package/dist/css/uikit.min.css +1 -1
- package/dist/js/components/countdown.js +88 -133
- package/dist/js/components/countdown.min.js +1 -1
- package/dist/js/components/filter.js +410 -437
- package/dist/js/components/filter.min.js +1 -1
- package/dist/js/components/lightbox-panel.js +1116 -1305
- package/dist/js/components/lightbox-panel.min.js +1 -1
- package/dist/js/components/lightbox.js +1164 -1383
- package/dist/js/components/lightbox.min.js +1 -1
- package/dist/js/components/notification.js +94 -114
- package/dist/js/components/notification.min.js +1 -1
- package/dist/js/components/parallax.js +294 -345
- package/dist/js/components/parallax.min.js +1 -1
- package/dist/js/components/slider-parallax.js +292 -344
- package/dist/js/components/slider-parallax.min.js +1 -1
- package/dist/js/components/slider.js +724 -846
- package/dist/js/components/slider.min.js +1 -1
- package/dist/js/components/slideshow-parallax.js +292 -344
- package/dist/js/components/slideshow-parallax.min.js +1 -1
- package/dist/js/components/slideshow.js +615 -799
- package/dist/js/components/slideshow.min.js +1 -1
- package/dist/js/components/sortable.js +587 -616
- package/dist/js/components/sortable.min.js +1 -1
- package/dist/js/components/tooltip.js +324 -356
- package/dist/js/components/tooltip.min.js +1 -1
- package/dist/js/components/upload.js +153 -161
- package/dist/js/components/upload.min.js +1 -1
- package/dist/js/uikit-core.js +5293 -6602
- package/dist/js/uikit-core.min.js +1 -1
- package/dist/js/uikit-icons.js +7 -9
- package/dist/js/uikit-icons.min.js +1 -1
- package/dist/js/uikit.js +8114 -9862
- package/dist/js/uikit.min.js +1 -1
- package/jsconfig.json +1 -1
- package/package.json +64 -60
- package/src/js/api/boot.js +25 -32
- package/src/js/api/component.js +23 -27
- package/src/js/api/global.js +6 -12
- package/src/js/api/hooks.js +13 -32
- package/src/js/api/instance.js +7 -15
- package/src/js/api/state.js +80 -101
- package/src/js/components/countdown.js +23 -49
- package/src/js/components/filter.js +71 -66
- package/src/js/components/index.js +13 -13
- package/src/js/components/internal/lightbox-animations.js +11 -23
- package/src/js/components/internal/slider-transitioner.js +65 -44
- package/src/js/components/internal/slideshow-animations.js +42 -61
- package/src/js/components/lightbox-panel.js +135 -109
- package/src/js/components/lightbox.js +17 -38
- package/src/js/components/notification.js +49 -43
- package/src/js/components/parallax.js +16 -30
- package/src/js/components/slider-parallax.js +13 -23
- package/src/js/components/slider.js +73 -61
- package/src/js/components/slideshow-parallax.js +1 -1
- package/src/js/components/slideshow.js +8 -13
- package/src/js/components/sortable.js +121 -102
- package/src/js/components/tooltip.js +41 -31
- package/src/js/components/upload.js +46 -53
- package/src/js/core/accordion.js +54 -49
- package/src/js/core/alert.js +10 -17
- package/src/js/core/core.js +74 -53
- package/src/js/core/cover.js +11 -15
- package/src/js/core/drop.js +107 -93
- package/src/js/core/form-custom.js +20 -25
- package/src/js/core/gif.js +3 -7
- package/src/js/core/grid.js +57 -58
- package/src/js/core/height-match.js +15 -28
- package/src/js/core/height-viewport.js +28 -35
- package/src/js/core/icon.js +38 -50
- package/src/js/core/img.js +57 -58
- package/src/js/core/index.js +39 -39
- package/src/js/core/leader.js +9 -18
- package/src/js/core/margin.js +10 -24
- package/src/js/core/modal.js +50 -36
- package/src/js/core/nav.js +2 -4
- package/src/js/core/navbar.js +112 -84
- package/src/js/core/offcanvas.js +49 -53
- package/src/js/core/overflow-auto.js +13 -17
- package/src/js/core/responsive.js +14 -12
- package/src/js/core/scroll.js +10 -20
- package/src/js/core/scrollspy-nav.js +34 -31
- package/src/js/core/scrollspy.js +34 -51
- package/src/js/core/sticky.js +151 -93
- package/src/js/core/svg.js +60 -79
- package/src/js/core/switcher.js +47 -46
- package/src/js/core/tab.js +7 -10
- package/src/js/core/toggle.js +63 -65
- package/src/js/core/video.js +11 -22
- package/src/js/mixin/animate.js +19 -20
- package/src/js/mixin/class.js +2 -4
- package/src/js/mixin/container.js +7 -11
- package/src/js/mixin/internal/animate-fade.js +73 -30
- package/src/js/mixin/internal/animate-slide.js +61 -41
- package/src/js/mixin/internal/slideshow-animations.js +7 -14
- package/src/js/mixin/internal/slideshow-transitioner.js +10 -17
- package/src/js/mixin/media.js +5 -10
- package/src/js/mixin/modal.js +89 -66
- package/src/js/mixin/parallax.js +53 -48
- package/src/js/mixin/position.js +26 -20
- package/src/js/mixin/slider-autoplay.js +12 -21
- package/src/js/mixin/slider-drag.js +62 -63
- package/src/js/mixin/slider-nav.js +25 -34
- package/src/js/mixin/slider-reactive.js +2 -8
- package/src/js/mixin/slider.js +51 -50
- package/src/js/mixin/slideshow.js +13 -19
- package/src/js/mixin/togglable.js +90 -63
- package/src/js/uikit-core.js +2 -4
- package/src/js/uikit.js +2 -4
- package/src/js/util/ajax.js +27 -43
- package/src/js/util/animation.js +82 -75
- package/src/js/util/attr.js +6 -12
- package/src/js/util/class.js +14 -52
- package/src/js/util/dimensions.js +56 -43
- package/src/js/util/dom.js +36 -54
- package/src/js/util/env.js +7 -12
- package/src/js/util/event.js +60 -59
- package/src/js/util/fastdom.js +1 -6
- package/src/js/util/filter.js +17 -34
- package/src/js/util/index.js +0 -1
- package/src/js/util/lang.js +79 -119
- package/src/js/util/mouse.js +19 -17
- package/src/js/util/options.js +44 -49
- package/src/js/util/player.js +40 -36
- package/src/js/util/position.js +53 -45
- package/src/js/util/promise.js +0 -191
- package/src/js/util/selector.js +39 -48
- package/src/js/util/style.js +36 -46
- package/src/js/util/viewport.js +75 -64
- package/src/less/components/flex.less +0 -9
- package/src/less/components/navbar.less +0 -7
- package/src/less/components/utility.less +22 -0
- package/src/scss/components/flex.scss +0 -9
- package/src/scss/components/form.scss +3 -3
- package/src/scss/components/icon.scss +2 -2
- package/src/scss/components/navbar.scss +0 -7
- package/src/scss/components/search.scss +1 -1
- package/src/scss/components/utility.scss +22 -0
- package/src/scss/variables-theme.scss +6 -6
- package/src/scss/variables.scss +6 -6
- package/tests/js/index.js +114 -85
- package/tests/sticky-parallax.html +44 -41
- package/tests/sticky.html +20 -3
- package/src/js/mixin/flex-bug.js +0 -56
package/src/js/uikit.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import UIkit from './uikit-core';
|
|
2
2
|
import * as components from './components/index';
|
|
3
|
-
import {each} from 'uikit-util';
|
|
3
|
+
import { each } from 'uikit-util';
|
|
4
4
|
|
|
5
|
-
each(components, (component, name) =>
|
|
6
|
-
UIkit.component(name, component)
|
|
7
|
-
);
|
|
5
|
+
each(components, (component, name) => UIkit.component(name, component));
|
|
8
6
|
|
|
9
7
|
export default UIkit;
|
package/src/js/util/ajax.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {on} from './event';
|
|
2
|
-
import {
|
|
3
|
-
import {assign, isString, noop} from './lang';
|
|
1
|
+
import { on } from './event';
|
|
2
|
+
import { assign, noop } from './lang';
|
|
4
3
|
|
|
5
4
|
export function ajax(url, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const env = assign(
|
|
6
|
+
{
|
|
7
|
+
data: null,
|
|
8
|
+
method: 'GET',
|
|
9
|
+
headers: {},
|
|
10
|
+
xhr: new XMLHttpRequest(),
|
|
11
|
+
beforeSend: noop,
|
|
12
|
+
responseType: '',
|
|
13
|
+
},
|
|
14
|
+
options
|
|
15
|
+
);
|
|
15
16
|
|
|
16
17
|
return Promise.resolve()
|
|
17
18
|
.then(() => env.beforeSend(env))
|
|
@@ -20,15 +21,15 @@ export function ajax(url, options) {
|
|
|
20
21
|
|
|
21
22
|
function send(url, env) {
|
|
22
23
|
return new Promise((resolve, reject) => {
|
|
23
|
-
|
|
24
|
+
const { xhr } = env;
|
|
24
25
|
|
|
25
26
|
for (const prop in env) {
|
|
26
27
|
if (prop in xhr) {
|
|
27
28
|
try {
|
|
28
|
-
|
|
29
29
|
xhr[prop] = env[prop];
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
} catch (e) {
|
|
31
|
+
// noop
|
|
32
|
+
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -39,51 +40,34 @@ function send(url, env) {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
on(xhr, 'load', () => {
|
|
42
|
-
|
|
43
|
-
if (xhr.status === 0 || xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
|
|
44
|
-
|
|
45
|
-
// IE 11 does not support responseType 'json'
|
|
46
|
-
if (env.responseType === 'json' && isString(xhr.response)) {
|
|
47
|
-
xhr = assign(copyXhr(xhr), {response: JSON.parse(xhr.response)});
|
|
48
|
-
}
|
|
49
|
-
|
|
43
|
+
if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) {
|
|
50
44
|
resolve(xhr);
|
|
51
|
-
|
|
52
45
|
} else {
|
|
53
|
-
reject(
|
|
54
|
-
xhr,
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
reject(
|
|
47
|
+
assign(Error(xhr.statusText), {
|
|
48
|
+
xhr,
|
|
49
|
+
status: xhr.status,
|
|
50
|
+
})
|
|
51
|
+
);
|
|
57
52
|
}
|
|
58
|
-
|
|
59
53
|
});
|
|
60
54
|
|
|
61
|
-
on(xhr, 'error', () => reject(assign(Error('Network Error'), {xhr})));
|
|
62
|
-
on(xhr, 'timeout', () => reject(assign(Error('Network Timeout'), {xhr})));
|
|
55
|
+
on(xhr, 'error', () => reject(assign(Error('Network Error'), { xhr })));
|
|
56
|
+
on(xhr, 'timeout', () => reject(assign(Error('Network Timeout'), { xhr })));
|
|
63
57
|
|
|
64
58
|
xhr.send(env.data);
|
|
65
59
|
});
|
|
66
60
|
}
|
|
67
61
|
|
|
68
62
|
export function getImage(src, srcset, sizes) {
|
|
69
|
-
|
|
70
63
|
return new Promise((resolve, reject) => {
|
|
71
64
|
const img = new Image();
|
|
72
65
|
|
|
73
|
-
img.onerror = e => reject(e);
|
|
66
|
+
img.onerror = (e) => reject(e);
|
|
74
67
|
img.onload = () => resolve(img);
|
|
75
68
|
|
|
76
69
|
sizes && (img.sizes = sizes);
|
|
77
70
|
srcset && (img.srcset = srcset);
|
|
78
71
|
img.src = src;
|
|
79
72
|
});
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function copyXhr(source) {
|
|
84
|
-
const target = {};
|
|
85
|
-
for (const key in source) {
|
|
86
|
-
target[key] = source[key];
|
|
87
|
-
}
|
|
88
|
-
return target;
|
|
89
73
|
}
|
package/src/js/util/animation.js
CHANGED
|
@@ -1,49 +1,57 @@
|
|
|
1
|
-
import {attr} from './attr';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {addClass, hasClass, removeClass, removeClasses} from './class';
|
|
1
|
+
import { attr } from './attr';
|
|
2
|
+
import { once, trigger } from './event';
|
|
3
|
+
import { css, propName } from './style';
|
|
4
|
+
import { assign, startsWith, toNodes } from './lang';
|
|
5
|
+
import { addClass, hasClass, removeClass, removeClasses } from './class';
|
|
7
6
|
|
|
8
7
|
export function transition(element, props, duration = 400, timing = 'linear') {
|
|
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
|
-
|
|
8
|
+
return Promise.all(
|
|
9
|
+
toNodes(element).map(
|
|
10
|
+
(element) =>
|
|
11
|
+
new Promise((resolve, reject) => {
|
|
12
|
+
for (const name in props) {
|
|
13
|
+
const value = css(element, name);
|
|
14
|
+
if (value === '') {
|
|
15
|
+
css(element, name, value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const timer = setTimeout(() => trigger(element, 'transitionend'), duration);
|
|
20
|
+
|
|
21
|
+
once(
|
|
22
|
+
element,
|
|
23
|
+
'transitionend transitioncanceled',
|
|
24
|
+
({ type }) => {
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
removeClass(element, 'uk-transition');
|
|
27
|
+
css(element, {
|
|
28
|
+
transitionProperty: '',
|
|
29
|
+
transitionDuration: '',
|
|
30
|
+
transitionTimingFunction: '',
|
|
31
|
+
});
|
|
32
|
+
type === 'transitioncanceled' ? reject() : resolve(element);
|
|
33
|
+
},
|
|
34
|
+
{ self: true }
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
addClass(element, 'uk-transition');
|
|
38
|
+
css(
|
|
39
|
+
element,
|
|
40
|
+
assign(
|
|
41
|
+
{
|
|
42
|
+
transitionProperty: Object.keys(props).map(propName).join(','),
|
|
43
|
+
transitionDuration: `${duration}ms`,
|
|
44
|
+
transitionTimingFunction: timing,
|
|
45
|
+
},
|
|
46
|
+
props
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
})
|
|
50
|
+
)
|
|
51
|
+
);
|
|
43
52
|
}
|
|
44
53
|
|
|
45
54
|
export const Transition = {
|
|
46
|
-
|
|
47
55
|
start: transition,
|
|
48
56
|
|
|
49
57
|
stop(element) {
|
|
@@ -57,47 +65,47 @@ export const Transition = {
|
|
|
57
65
|
|
|
58
66
|
inProgress(element) {
|
|
59
67
|
return hasClass(element, 'uk-transition');
|
|
60
|
-
}
|
|
61
|
-
|
|
68
|
+
},
|
|
62
69
|
};
|
|
63
70
|
|
|
64
71
|
const animationPrefix = 'uk-animation-';
|
|
65
72
|
|
|
66
73
|
export function animate(element, animation, duration = 200, origin, out) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
74
|
+
return Promise.all(
|
|
75
|
+
toNodes(element).map(
|
|
76
|
+
(element) =>
|
|
77
|
+
new Promise((resolve, reject) => {
|
|
78
|
+
trigger(element, 'animationcanceled');
|
|
79
|
+
const timer = setTimeout(() => trigger(element, 'animationend'), duration);
|
|
80
|
+
|
|
81
|
+
once(
|
|
82
|
+
element,
|
|
83
|
+
'animationend animationcanceled',
|
|
84
|
+
({ type }) => {
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
|
|
87
|
+
type === 'animationcanceled' ? reject() : resolve(element);
|
|
88
|
+
|
|
89
|
+
css(element, 'animationDuration', '');
|
|
90
|
+
removeClasses(element, `${animationPrefix}\\S*`);
|
|
91
|
+
},
|
|
92
|
+
{ self: true }
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
css(element, 'animationDuration', `${duration}ms`);
|
|
96
|
+
addClass(element, animation, animationPrefix + (out ? 'leave' : 'enter'));
|
|
97
|
+
|
|
98
|
+
if (startsWith(animation, animationPrefix)) {
|
|
99
|
+
origin && addClass(element, `uk-transform-origin-${origin}`);
|
|
100
|
+
out && addClass(element, `${animationPrefix}reverse`);
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
)
|
|
104
|
+
);
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
const inProgress = new RegExp(`${animationPrefix}(enter|leave)`);
|
|
99
108
|
export const Animation = {
|
|
100
|
-
|
|
101
109
|
in: animate,
|
|
102
110
|
|
|
103
111
|
out(element, animation, duration, origin) {
|
|
@@ -110,6 +118,5 @@ export const Animation = {
|
|
|
110
118
|
|
|
111
119
|
cancel(element) {
|
|
112
120
|
trigger(element, 'animationcanceled');
|
|
113
|
-
}
|
|
114
|
-
|
|
121
|
+
},
|
|
115
122
|
};
|
package/src/js/util/attr.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {isFunction, isObject, isUndefined, toNode, toNodes} from './lang';
|
|
1
|
+
import { isFunction, isObject, isUndefined, toNode, toNodes } from './lang';
|
|
2
2
|
|
|
3
3
|
export function attr(element, name, value) {
|
|
4
|
-
|
|
5
4
|
if (isObject(name)) {
|
|
6
5
|
for (const key in name) {
|
|
7
6
|
attr(element, key, name[key]);
|
|
@@ -10,11 +9,9 @@ export function attr(element, name, value) {
|
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
if (isUndefined(value)) {
|
|
13
|
-
|
|
14
|
-
return element && element.getAttribute(name);
|
|
12
|
+
return toNode(element)?.getAttribute(name);
|
|
15
13
|
} else {
|
|
16
|
-
toNodes(element).forEach(element => {
|
|
17
|
-
|
|
14
|
+
toNodes(element).forEach((element) => {
|
|
18
15
|
if (isFunction(value)) {
|
|
19
16
|
value = value.call(element, attr(element, name));
|
|
20
17
|
}
|
|
@@ -26,19 +23,16 @@ export function attr(element, name, value) {
|
|
|
26
23
|
}
|
|
27
24
|
});
|
|
28
25
|
}
|
|
29
|
-
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
export function hasAttr(element, name) {
|
|
33
|
-
return toNodes(element).some(element => element.hasAttribute(name));
|
|
29
|
+
return toNodes(element).some((element) => element.hasAttribute(name));
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
export function removeAttr(element, name) {
|
|
37
33
|
element = toNodes(element);
|
|
38
|
-
name.split(' ').forEach(name =>
|
|
39
|
-
element.forEach(element =>
|
|
40
|
-
element.hasAttribute(name) && element.removeAttribute(name)
|
|
41
|
-
)
|
|
34
|
+
name.split(' ').forEach((name) =>
|
|
35
|
+
element.forEach((element) => element.hasAttribute(name) && element.removeAttribute(name))
|
|
42
36
|
);
|
|
43
37
|
}
|
|
44
38
|
|
package/src/js/util/class.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {attr} from './attr';
|
|
2
|
-
import {isUndefined, toNodes} from './lang';
|
|
1
|
+
import { attr } from './attr';
|
|
2
|
+
import { isUndefined, toNodes } from './lang';
|
|
3
3
|
|
|
4
4
|
export function addClass(element, ...args) {
|
|
5
5
|
apply(element, args, 'add');
|
|
@@ -10,7 +10,7 @@ export function removeClass(element, ...args) {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function removeClasses(element, cls) {
|
|
13
|
-
attr(element, 'class', value => (value || '').replace(new RegExp(`\\b${cls}\\b`, 'g'), ''));
|
|
13
|
+
attr(element, 'class', (value) => (value || '').replace(new RegExp(`\\b${cls}\\b`, 'g'), ''));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function replaceClass(element, ...args) {
|
|
@@ -20,9 +20,8 @@ export function replaceClass(element, ...args) {
|
|
|
20
20
|
|
|
21
21
|
export function hasClass(element, cls) {
|
|
22
22
|
[cls] = getClasses(cls);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
if (cls && nodes[n].classList.contains(cls)) {
|
|
23
|
+
for (const node of toNodes(element)) {
|
|
24
|
+
if (cls && node.classList.contains(cls)) {
|
|
26
25
|
return true;
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -30,64 +29,27 @@ export function hasClass(element, cls) {
|
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
export function toggleClass(element, cls, force) {
|
|
32
|
+
const classes = getClasses(cls);
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
if (!isUndefined(force)) {
|
|
35
|
+
force = !!force;
|
|
36
|
+
}
|
|
35
37
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
for (let i = 0; i < cls.length; i++) {
|
|
40
|
-
if (isUndefined(force)) {
|
|
41
|
-
list.toggle(cls[i]);
|
|
42
|
-
} else if (supports.Force) {
|
|
43
|
-
list.toggle(cls[i], !!force);
|
|
44
|
-
} else {
|
|
45
|
-
list[force ? 'add' : 'remove'](cls[i]);
|
|
46
|
-
}
|
|
38
|
+
for (const node of toNodes(element)) {
|
|
39
|
+
for (const cls of classes) {
|
|
40
|
+
node.classList.toggle(cls, force);
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
44
|
|
|
51
45
|
function apply(element, args, fn) {
|
|
52
|
-
|
|
53
46
|
args = args.reduce((args, arg) => args.concat(getClasses(arg)), []);
|
|
54
47
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
if (supports.Multiple) {
|
|
58
|
-
nodes[n].classList[fn](...args);
|
|
59
|
-
} else {
|
|
60
|
-
args.forEach(cls => nodes[n].classList[fn](cls));
|
|
61
|
-
}
|
|
48
|
+
for (const node of toNodes(element)) {
|
|
49
|
+
node.classList[fn](...args);
|
|
62
50
|
}
|
|
63
51
|
}
|
|
64
52
|
|
|
65
53
|
function getClasses(str) {
|
|
66
54
|
return String(str).split(/\s|,/).filter(Boolean);
|
|
67
55
|
}
|
|
68
|
-
|
|
69
|
-
// IE 11
|
|
70
|
-
let supports = {
|
|
71
|
-
|
|
72
|
-
get Multiple() {
|
|
73
|
-
return this.get('Multiple');
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
get Force() {
|
|
77
|
-
return this.get('Force');
|
|
78
|
-
},
|
|
79
|
-
|
|
80
|
-
get(key) {
|
|
81
|
-
|
|
82
|
-
const {classList} = document.createElement('_');
|
|
83
|
-
classList.add('a', 'b');
|
|
84
|
-
classList.toggle('c', false);
|
|
85
|
-
supports = {
|
|
86
|
-
Multiple: classList.contains('b'),
|
|
87
|
-
Force: !classList.contains('c')
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
return supports[key];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
};
|
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
import {css} from './style';
|
|
2
|
-
import {
|
|
1
|
+
import { css } from './style';
|
|
2
|
+
import {
|
|
3
|
+
each,
|
|
4
|
+
isDocument,
|
|
5
|
+
isElement,
|
|
6
|
+
isString,
|
|
7
|
+
isUndefined,
|
|
8
|
+
isWindow,
|
|
9
|
+
memoize,
|
|
10
|
+
toFloat,
|
|
11
|
+
toNode,
|
|
12
|
+
toWindow,
|
|
13
|
+
ucfirst,
|
|
14
|
+
} from './lang';
|
|
3
15
|
|
|
4
16
|
const dirs = {
|
|
5
17
|
width: ['left', 'right'],
|
|
6
|
-
height: ['top', 'bottom']
|
|
18
|
+
height: ['top', 'bottom'],
|
|
7
19
|
};
|
|
8
20
|
|
|
9
21
|
export function dimensions(element) {
|
|
10
|
-
|
|
11
22
|
const rect = isElement(element)
|
|
12
23
|
? toNode(element).getBoundingClientRect()
|
|
13
|
-
: {height: height(element), width: width(element), top: 0, left: 0};
|
|
24
|
+
: { height: height(element), width: width(element), top: 0, left: 0 };
|
|
14
25
|
|
|
15
26
|
return {
|
|
16
27
|
height: rect.height,
|
|
@@ -18,17 +29,16 @@ export function dimensions(element) {
|
|
|
18
29
|
top: rect.top,
|
|
19
30
|
left: rect.left,
|
|
20
31
|
bottom: rect.top + rect.height,
|
|
21
|
-
right: rect.left + rect.width
|
|
32
|
+
right: rect.left + rect.width,
|
|
22
33
|
};
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
export function offset(element, coordinates) {
|
|
26
|
-
|
|
27
37
|
const currentOffset = dimensions(element);
|
|
28
38
|
|
|
29
39
|
if (element) {
|
|
30
|
-
const {pageYOffset, pageXOffset} = toWindow(element);
|
|
31
|
-
const offsetBy = {height: pageYOffset, width: pageXOffset};
|
|
40
|
+
const { pageYOffset, pageXOffset } = toWindow(element);
|
|
41
|
+
const offsetBy = { height: pageYOffset, width: pageXOffset };
|
|
32
42
|
|
|
33
43
|
for (const dir in dirs) {
|
|
34
44
|
for (const i in dirs[dir]) {
|
|
@@ -44,23 +54,30 @@ export function offset(element, coordinates) {
|
|
|
44
54
|
const pos = css(element, 'position');
|
|
45
55
|
|
|
46
56
|
each(css(element, ['left', 'top']), (value, prop) =>
|
|
47
|
-
css(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
css(
|
|
58
|
+
element,
|
|
59
|
+
prop,
|
|
60
|
+
coordinates[prop] -
|
|
61
|
+
currentOffset[prop] +
|
|
62
|
+
toFloat(pos === 'absolute' && value === 'auto' ? position(element)[prop] : value)
|
|
52
63
|
)
|
|
53
64
|
);
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
export function position(element) {
|
|
68
|
+
let { top, left } = offset(element);
|
|
57
69
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
70
|
+
const {
|
|
71
|
+
ownerDocument: { body, documentElement },
|
|
72
|
+
offsetParent,
|
|
73
|
+
} = toNode(element);
|
|
61
74
|
let parent = offsetParent || documentElement;
|
|
62
75
|
|
|
63
|
-
while (
|
|
76
|
+
while (
|
|
77
|
+
parent &&
|
|
78
|
+
(parent === body || parent === documentElement) &&
|
|
79
|
+
css(parent, 'position') === 'static'
|
|
80
|
+
) {
|
|
64
81
|
parent = parent.parentNode;
|
|
65
82
|
}
|
|
66
83
|
|
|
@@ -72,7 +89,7 @@ export function position(element) {
|
|
|
72
89
|
|
|
73
90
|
return {
|
|
74
91
|
top: top - toFloat(css(element, 'marginTop')),
|
|
75
|
-
left: left - toFloat(css(element, 'marginLeft'))
|
|
92
|
+
left: left - toFloat(css(element, 'marginLeft')),
|
|
76
93
|
};
|
|
77
94
|
}
|
|
78
95
|
|
|
@@ -82,7 +99,6 @@ export function offsetPosition(element) {
|
|
|
82
99
|
element = toNode(element);
|
|
83
100
|
|
|
84
101
|
do {
|
|
85
|
-
|
|
86
102
|
offset[0] += element.offsetTop;
|
|
87
103
|
offset[1] += element.offsetLeft;
|
|
88
104
|
|
|
@@ -92,7 +108,6 @@ export function offsetPosition(element) {
|
|
|
92
108
|
offset[1] += win.pageXOffset;
|
|
93
109
|
return offset;
|
|
94
110
|
}
|
|
95
|
-
|
|
96
111
|
} while ((element = element.offsetParent));
|
|
97
112
|
|
|
98
113
|
return offset;
|
|
@@ -104,9 +119,7 @@ export const width = dimension('width');
|
|
|
104
119
|
function dimension(prop) {
|
|
105
120
|
const propName = ucfirst(prop);
|
|
106
121
|
return (element, value) => {
|
|
107
|
-
|
|
108
122
|
if (isUndefined(value)) {
|
|
109
|
-
|
|
110
123
|
if (isWindow(element)) {
|
|
111
124
|
return element[`inner${propName}`];
|
|
112
125
|
}
|
|
@@ -122,26 +135,27 @@ function dimension(prop) {
|
|
|
122
135
|
value = value === 'auto' ? element[`offset${propName}`] : toFloat(value) || 0;
|
|
123
136
|
|
|
124
137
|
return value - boxModelAdjust(element, prop);
|
|
125
|
-
|
|
126
138
|
} else {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
: +value + boxModelAdjust(element, prop) + 'px'
|
|
139
|
+
return css(
|
|
140
|
+
element,
|
|
141
|
+
prop,
|
|
142
|
+
!value && value !== 0 ? '' : +value + boxModelAdjust(element, prop) + 'px'
|
|
131
143
|
);
|
|
132
|
-
|
|
133
144
|
}
|
|
134
|
-
|
|
135
145
|
};
|
|
136
146
|
}
|
|
137
147
|
|
|
138
148
|
export function boxModelAdjust(element, prop, sizing = 'border-box') {
|
|
139
149
|
return css(element, 'boxSizing') === sizing
|
|
140
|
-
? dirs[prop]
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
150
|
+
? dirs[prop]
|
|
151
|
+
.map(ucfirst)
|
|
152
|
+
.reduce(
|
|
153
|
+
(value, prop) =>
|
|
154
|
+
value +
|
|
155
|
+
toFloat(css(element, `padding${prop}`)) +
|
|
156
|
+
toFloat(css(element, `border${prop}Width`)),
|
|
157
|
+
0
|
|
158
|
+
)
|
|
145
159
|
: 0;
|
|
146
160
|
}
|
|
147
161
|
|
|
@@ -157,7 +171,6 @@ export function flipPosition(pos) {
|
|
|
157
171
|
}
|
|
158
172
|
|
|
159
173
|
export function toPx(value, property = 'width', element = window, offsetDim = false) {
|
|
160
|
-
|
|
161
174
|
if (!isString(value)) {
|
|
162
175
|
return toFloat(value);
|
|
163
176
|
}
|
|
@@ -169,10 +182,10 @@ export function toPx(value, property = 'width', element = window, offsetDim = fa
|
|
|
169
182
|
unit === 'vh'
|
|
170
183
|
? height(toWindow(element))
|
|
171
184
|
: unit === 'vw'
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
185
|
+
? width(toWindow(element))
|
|
186
|
+
: offsetDim
|
|
187
|
+
? element[`offset${ucfirst(property)}`]
|
|
188
|
+
: dimensions(element)[property],
|
|
176
189
|
value
|
|
177
190
|
);
|
|
178
191
|
}
|
|
@@ -182,10 +195,10 @@ export function toPx(value, property = 'width', element = window, offsetDim = fa
|
|
|
182
195
|
}
|
|
183
196
|
|
|
184
197
|
const calcRe = /-?\d+(?:\.\d+)?(?:v[wh]|%|px)?/g;
|
|
185
|
-
const parseCalc = memoize(calc => calc.toString().replace(/\s/g, '').match(calcRe) || []);
|
|
198
|
+
const parseCalc = memoize((calc) => calc.toString().replace(/\s/g, '').match(calcRe) || []);
|
|
186
199
|
const unitRe = /(?:v[hw]|%)$/;
|
|
187
|
-
const parseUnit = memoize(str => (str.match(unitRe) || [])[0]);
|
|
200
|
+
const parseUnit = memoize((str) => (str.match(unitRe) || [])[0]);
|
|
188
201
|
|
|
189
202
|
function percent(base, value) {
|
|
190
|
-
return base * toFloat(value) / 100;
|
|
203
|
+
return (base * toFloat(value)) / 100;
|
|
191
204
|
}
|