hexo-theme-shokax 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,11 +9,11 @@ $dom.all = (selector, element = document) => {
9
9
  return element.querySelectorAll(selector);
10
10
  };
11
11
  $dom.each = (selector, callback, element) => {
12
- return $dom.all(selector, element).forEach(callback);
12
+ $dom.all(selector, element).forEach(callback);
13
13
  };
14
14
  $dom.asyncify = async (selector, element = document) => {
15
- if (selector.indexOf('#') === 0) {
16
- return element.getElementById(selector.replace('#', ''));
15
+ if (selector[0] === '#') {
16
+ return element.getElementById(selector.substring(1));
17
17
  }
18
18
  return element.querySelector(selector);
19
19
  };
@@ -21,7 +21,7 @@ $dom.asyncifyEach = (selector, callback, element) => {
21
21
  $dom.all(selector, element).forEach(callback);
22
22
  };
23
23
  Object.assign(HTMLElement.prototype, {
24
- createChild: function (tag, obj, positon) {
24
+ createChild(tag, obj, positon) {
25
25
  const child = document.createElement(tag);
26
26
  Object.assign(child, obj);
27
27
  switch (positon) {
@@ -37,32 +37,32 @@ Object.assign(HTMLElement.prototype, {
37
37
  }
38
38
  return child;
39
39
  },
40
- wrapObject: function (obj) {
40
+ wrapObject(obj) {
41
41
  const box = document.createElement('div');
42
42
  Object.assign(box, obj);
43
43
  this.parentNode.insertBefore(box, this);
44
44
  this.parentNode.removeChild(this);
45
45
  box.appendChild(this);
46
46
  },
47
- changeOrGetHeight: function (h) {
47
+ changeOrGetHeight(h) {
48
48
  if (h) {
49
49
  this.style.height = typeof h === 'number' ? h + 'rem' : h;
50
50
  }
51
51
  return this.getBoundingClientRect().height;
52
52
  },
53
- changeOrGetWidth: function (w) {
53
+ changeOrGetWidth(w) {
54
54
  if (w) {
55
55
  this.style.width = typeof w === 'number' ? w + 'rem' : w;
56
56
  }
57
57
  return this.getBoundingClientRect().width;
58
58
  },
59
- getTop: function () {
59
+ getTop() {
60
60
  return this.getBoundingClientRect().top;
61
61
  },
62
- left: function () {
62
+ left() {
63
63
  return this.getBoundingClientRect().left;
64
64
  },
65
- attr: function (type, value) {
65
+ attr(type, value) {
66
66
  if (value === null) {
67
67
  return this.removeAttribute(type);
68
68
  }
@@ -74,7 +74,7 @@ Object.assign(HTMLElement.prototype, {
74
74
  return this.getAttribute(type);
75
75
  }
76
76
  },
77
- insertAfter: function (element) {
77
+ insertAfter(element) {
78
78
  const parent = this.parentNode;
79
79
  if (parent.lastChild === this) {
80
80
  parent.appendChild(element);
@@ -83,7 +83,7 @@ Object.assign(HTMLElement.prototype, {
83
83
  parent.insertBefore(element, this.nextSibling);
84
84
  }
85
85
  },
86
- display: function (d) {
86
+ display(d) {
87
87
  if (d == null) {
88
88
  return this.style.display;
89
89
  }
@@ -92,13 +92,13 @@ Object.assign(HTMLElement.prototype, {
92
92
  return this;
93
93
  }
94
94
  },
95
- child: function (selector) {
95
+ child(selector) {
96
96
  return $dom(selector, this);
97
97
  },
98
- find: function (selector) {
98
+ find(selector) {
99
99
  return $dom.all(selector, this);
100
100
  },
101
- _class: function (type, className, display) {
101
+ _class(type, className, display) {
102
102
  const classNames = className.indexOf(' ') ? className.split(' ') : [className];
103
103
  classNames.forEach((name) => {
104
104
  if (type === 'toggle') {
@@ -109,34 +109,34 @@ Object.assign(HTMLElement.prototype, {
109
109
  }
110
110
  });
111
111
  },
112
- addClass: function (className) {
112
+ addClass(className) {
113
113
  this._class('add', className);
114
114
  return this;
115
115
  },
116
- removeClass: function (className) {
116
+ removeClass(className) {
117
117
  this._class('remove', className);
118
118
  return this;
119
119
  },
120
- toggleClass: function (className, display) {
120
+ toggleClass(className, display) {
121
121
  this._class('toggle', className, display);
122
122
  return this;
123
123
  },
124
- hasClass: function (className) {
124
+ hasClass(className) {
125
125
  return this.classList.contains(className);
126
126
  }
127
127
  });
128
128
  const $storage = {
129
- set: (key, value) => {
129
+ set(key, value) {
130
130
  localStorage.setItem(key, value);
131
131
  },
132
- get: (key) => {
132
+ get(key) {
133
133
  return localStorage.getItem(key);
134
134
  },
135
- del: (key) => {
135
+ del(key) {
136
136
  localStorage.removeItem(key);
137
137
  }
138
138
  };
139
- const getScript = function (url, callback, condition) {
139
+ const getScript = (url, callback, condition) => {
140
140
  if (condition) {
141
141
  callback();
142
142
  }
@@ -155,27 +155,27 @@ const getScript = function (url, callback, condition) {
155
155
  document.head.appendChild(script);
156
156
  }
157
157
  };
158
- const assetUrl = function (asset, type) {
158
+ const assetUrl = (asset, type) => {
159
159
  const str = CONFIG[asset][type];
160
- if (str.indexOf('gh') > -1 || str.indexOf('combine') > -1) {
160
+ if (str.includes('gh') || str.includes('combine')) {
161
161
  return `https://cdn.jsdelivr.net/${str}`;
162
162
  }
163
- if (str.indexOf('npm') > -1) {
163
+ if (str.includes('npm')) {
164
164
  return `https://cdn.jsdelivr.net/${str}`;
165
165
  }
166
- if (str.indexOf('http') > -1) {
166
+ if (str.includes('http')) {
167
167
  return str;
168
168
  }
169
169
  return `/${str}`;
170
170
  };
171
- const vendorJs = function (type, callback, condition) {
171
+ const vendorJs = (type, callback, condition) => {
172
172
  if (LOCAL[type]) {
173
173
  getScript(assetUrl('js', type), callback || function () {
174
174
  window[type] = true;
175
175
  }, condition || window[type]);
176
176
  }
177
177
  };
178
- const vendorCss = function (type, condition) {
178
+ const vendorCss = (type, condition) => {
179
179
  if (window['css' + type]) {
180
180
  return;
181
181
  }
@@ -200,7 +200,7 @@ const transition = (target, type, complete, begin) => {
200
200
  break;
201
201
  case 'bounceUpIn':
202
202
  animation = {
203
- begin: function (anim) {
203
+ begin(anim) {
204
204
  target.display('block');
205
205
  },
206
206
  translateY: [
@@ -215,7 +215,7 @@ const transition = (target, type, complete, begin) => {
215
215
  break;
216
216
  case 'shrinkIn':
217
217
  animation = {
218
- begin: function (anim) {
218
+ begin(anim) {
219
219
  target.display('block');
220
220
  },
221
221
  scale: [
@@ -228,7 +228,7 @@ const transition = (target, type, complete, begin) => {
228
228
  break;
229
229
  case 'slideRightIn':
230
230
  animation = {
231
- begin: function (anim) {
231
+ begin(anim) {
232
232
  target.display('block');
233
233
  },
234
234
  translateX: ['100%', '0%'],
@@ -251,16 +251,16 @@ const transition = (target, type, complete, begin) => {
251
251
  targets: target,
252
252
  duration: 200,
253
253
  easing: 'linear',
254
- begin: function () {
254
+ begin() {
255
255
  begin && begin();
256
256
  },
257
- complete: function () {
257
+ complete() {
258
258
  target.display(display);
259
259
  complete && complete();
260
260
  }
261
261
  }, animation)).play();
262
262
  };
263
- const pjaxScript = function (element) {
263
+ const pjaxScript = (element) => {
264
264
  const { text, parentNode, id, className, type, src, dataset } = element;
265
265
  const code = text || element.textContent || element.innerHTML || '';
266
266
  parentNode.removeChild(element);
@@ -286,13 +286,13 @@ const pjaxScript = function (element) {
286
286
  }
287
287
  parentNode.appendChild(script);
288
288
  };
289
- const pageScroll = function (target, offset, complete) {
289
+ const pageScroll = (target, offset, complete) => {
290
290
  const opt = {
291
291
  targets: typeof offset === 'number' ? target.parentNode : document.scrollingElement,
292
292
  duration: 500,
293
293
  easing: 'easeInOutQuad',
294
294
  scrollTop: offset || (typeof target === 'number' ? target : (target ? target.getTop() + document.documentElement.scrollTop - siteNavHeight : 0)),
295
- complete: function () {
295
+ complete() {
296
296
  complete && complete();
297
297
  }
298
298
  };