1 | import _Object$keys from 'babel-runtime/core-js/object/keys';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | import util from '../ons/util';
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | var prefix = function () {
|
28 | var styles = window.getComputedStyle(document.documentElement, '');
|
29 | var prefix = (Array.prototype.slice.call(styles).join('').match(/-(moz|webkit|ms)-/) || styles.OLink === '' && ['', 'o'])[1];
|
30 |
|
31 | return function (name) {
|
32 | return '-' + prefix + '-' + util.hyphenate(name);
|
33 | };
|
34 | }();
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | var styler = function styler(element, style) {
|
45 | _Object$keys(style).forEach(function (key) {
|
46 | if (key in element.style) {
|
47 | element.style[key] = style[key];
|
48 | } else if (prefix(key) in element.style) {
|
49 | element.style[prefix(key)] = style[key];
|
50 | } else {
|
51 | util.warn('No such style property: ' + key);
|
52 | }
|
53 | });
|
54 | return element;
|
55 | };
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | styler.clear = function (element) {
|
62 | var styles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
63 |
|
64 | var clearlist = styles.split(/\s+/).reduce(function (r, s) {
|
65 | return r.concat([util.hyphenate(s), prefix(s)]);
|
66 | }, []),
|
67 | keys = [];
|
68 |
|
69 | var _loop = function _loop(i) {
|
70 | var key = element.style[i];
|
71 | if (clearlist.length === 0 || clearlist.some(function (s) {
|
72 | return key.indexOf(s) === 0;
|
73 | })) {
|
74 | keys.push(key);
|
75 | }
|
76 | };
|
77 |
|
78 | for (var i = element.style.length - 1; i >= 0; i--) {
|
79 | _loop(i);
|
80 | }
|
81 |
|
82 | keys.forEach(function (key) {
|
83 | return element.style[key] = '';
|
84 | });
|
85 | element.getAttribute('style') === '' && element.removeAttribute('style');
|
86 | };
|
87 |
|
88 | export default styler; |
\ | No newline at end of file |