aw-front-helpers 2.5.11 → 2.5.13

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.
Files changed (42) hide show
  1. package/.prettierrc.json +15 -0
  2. package/bootstraper/Readme.md +3 -2
  3. package/bootstraper/index.js +2 -2
  4. package/bootstraper/maps.js +1 -1
  5. package/bootstraper/youtube.js +1 -1
  6. package/classes/Readme.md +4 -3
  7. package/classes/formControl.js +82 -43
  8. package/classes/globalParallax.js +55 -32
  9. package/classes/index.js +1 -1
  10. package/classes/nearby.js +49 -33
  11. package/classes/sticky.js +44 -25
  12. package/package.json +2 -2
  13. package/stylesheets/Readme.md +9 -0
  14. package/stylesheets/_functions.scss +3 -3
  15. package/stylesheets/_medias.scss +62 -22
  16. package/stylesheets/_mixins.scss +33 -26
  17. package/stylesheets/_reset.scss +116 -24
  18. package/stylesheets/_sticky.scss +1 -1
  19. package/stylesheets/_variables.scss +29 -29
  20. package/utils/array/combine.js +2 -2
  21. package/utils/array/max.js +2 -2
  22. package/utils/array/merge-deep.js +2 -2
  23. package/utils/array/min.js +2 -2
  24. package/utils/array/slice.js +2 -2
  25. package/utils/array/without.js +2 -2
  26. package/utils/dom/each.js +4 -5
  27. package/utils/dom/getClosest.js +2 -2
  28. package/utils/dom/next.js +1 -1
  29. package/utils/dom/resize.js +2 -2
  30. package/utils/dom/retina.js +7 -8
  31. package/utils/dom/scroll.js +10 -6
  32. package/utils/func/isTouch.js +1 -1
  33. package/utils/func/once.js +6 -6
  34. package/utils/helpers.js +37 -20
  35. package/utils/image/detectVerticalSquash.js +3 -4
  36. package/utils/image/drawImage.js +1 -1
  37. package/utils/image/resize.js +6 -6
  38. package/utils/image/thumbnail.js +27 -8
  39. package/utils/math/clamp.js +2 -2
  40. package/utils/math/hypo.js +2 -2
  41. package/utils/media/autoplay.js +3 -2
  42. package/utils/regex/email.js +2 -1
@@ -0,0 +1,15 @@
1
+ {
2
+ "trailingComma": "es5",
3
+ "tabWidth": 2,
4
+ "useTabs": false,
5
+ "semi": true,
6
+ "singleQuote": true,
7
+ "bracketSpacing": true,
8
+ "singleAttributePerLine": false,
9
+ "bracketSameLine": false,
10
+ "editor.formatOnSave": false,
11
+ "editor.defaultFormatter": "<another formatter>",
12
+ "[javascript]": {
13
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
14
+ }
15
+ }
@@ -21,8 +21,9 @@ BootstraperMaps.load('{googleKeyApi}', library[]).then( initMap ).catch(console.
21
21
  - visualization
22
22
 
23
23
  ## Youtube
24
+
24
25
  ```js
25
26
  import { BootstraperYoutube } from 'aw-front-helpers';
26
27
 
27
- BootstraperYoutube.load().then( initPlayer ).catch(console.error);
28
- ```
28
+ BootstraperYoutube.load().then(initPlayer).catch(console.error);
29
+ ```
@@ -1,4 +1,4 @@
1
1
  module.exports = {
2
2
  bootstraperMaps: require('./maps').default,
3
- bootstraperYoutube: require('./youtube').default
4
- }
3
+ bootstraperYoutube: require('./youtube').default,
4
+ };
@@ -46,4 +46,4 @@ class bootstraperMaps {
46
46
  return this._promise;
47
47
  }
48
48
  }
49
- export default bootstraperMaps.getInstance();
49
+ export default bootstraperMaps.getInstance();
@@ -43,4 +43,4 @@ class bootstraperYoutube {
43
43
  return this._promise;
44
44
  }
45
45
  }
46
- export default bootstraperYoutube.getInstance();
46
+ export default bootstraperYoutube.getInstance();
package/classes/Readme.md CHANGED
@@ -7,12 +7,13 @@
7
7
  </div>
8
8
 
9
9
  ## formControl
10
+
10
11
  Based on HTML5 basic options for inputs (required, type...).
11
12
 
12
13
  ```js
13
14
  import { FormControl } from 'aw-front-helpers';
14
15
 
15
- new FormControl(this._el, {options})
16
+ new FormControl(this._el, { options });
16
17
  ```
17
18
 
18
19
  ## globalParallax
@@ -33,7 +34,7 @@ GParallax.start();
33
34
  ```js
34
35
  import { Nearby } from 'aw-front-helpers';
35
36
 
36
- new Nearby(this._el, {options});
37
+ new Nearby(this._el, { options });
37
38
  ```
38
39
 
39
40
  ## sticky
@@ -41,7 +42,7 @@ new Nearby(this._el, {options});
41
42
  ```js
42
43
  import { Sticky } from 'aw-front-helpers';
43
44
 
44
- new Sticky({options});
45
+ new Sticky({ options });
45
46
  ```
46
47
 
47
48
  - need to define `[data-attributes]`
@@ -9,14 +9,28 @@ const defaultOptions = {
9
9
  classIsError: 'is-error',
10
10
  animateToFirstError: false,
11
11
  i18n: {
12
- required: Translator ? Translator.trans('form_errors.pattern') : 'Ce champs est obligatoire',
13
- same: Translator ? Translator.trans('form_errors.same') : 'Les champs ne correspondent pas.',
14
- email: Translator ? Translator.trans('form_errors.email') : 'Merci de renseigner un email valide.',
15
- empty: Translator ? Translator.trans('form_errors.empty') : 'Ce champs est obligatoire.',
16
- checkbox: Translator ? Translator.trans('form_errors.checkbox') : 'Veuillez accepter les conditions.',
17
- radio: Translator ? Translator.trans('form_errors.radio') : 'Veuillez sélectionner au moins un choix.',
18
- pattern: Translator ? Translator.trans('form_errors.pattern') : 'La donnée saisie ne respecte pas les règles énoncées.',
19
- }
12
+ required: window.Translator
13
+ ? window.Translator.trans('form_errors.pattern')
14
+ : 'Ce champs est obligatoire',
15
+ same: window.Translator
16
+ ? window.Translator.trans('form_errors.same')
17
+ : 'Les champs ne correspondent pas.',
18
+ email: window.Translator
19
+ ? window.Translator.trans('form_errors.email')
20
+ : 'Merci de renseigner un email valide.',
21
+ empty: window.Translator
22
+ ? window.Translator.trans('form_errors.empty')
23
+ : 'Ce champs est obligatoire.',
24
+ checkbox: window.Translator
25
+ ? window.Translator.trans('form_errors.checkbox')
26
+ : 'Veuillez accepter les conditions.',
27
+ radio: window.Translator
28
+ ? window.Translator.trans('form_errors.radio')
29
+ : 'Veuillez sélectionner au moins un choix.',
30
+ pattern: window.Translator
31
+ ? window.Translator.trans('form_errors.pattern')
32
+ : 'La donnée saisie ne respecte pas les règles énoncées.',
33
+ },
20
34
  };
21
35
 
22
36
  export default class FormControl {
@@ -47,7 +61,7 @@ export default class FormControl {
47
61
  /** @private */
48
62
  this._options = {
49
63
  ...defaultOptions,
50
- ...options
64
+ ...options,
51
65
  };
52
66
 
53
67
  this._form.setAttribute('novalidate', 'novalidate');
@@ -59,7 +73,7 @@ export default class FormControl {
59
73
  set options(options) {
60
74
  this._options = {
61
75
  ...this._options,
62
- options
76
+ options,
63
77
  };
64
78
  }
65
79
 
@@ -86,10 +100,10 @@ export default class FormControl {
86
100
  // -
87
101
  destroy() {
88
102
  this._form.removeEventListener('submit', this._onFormSubmit);
89
- this._domForm.inputs.forEach(input => {
103
+ this._domForm.inputs.forEach((input) => {
90
104
  input.removeEventListener('keyup', this._onChange);
91
105
  });
92
- this._domForm.choices.forEach(input => {
106
+ this._domForm.choices.forEach((input) => {
93
107
  input.removeEventListener('change', this._onChange);
94
108
  });
95
109
  }
@@ -107,24 +121,24 @@ export default class FormControl {
107
121
  if (parent === null) return;
108
122
  let error = parent.querySelector(`.${this._options.classErrorElement}`);
109
123
  parent.classList.add(this._options.classIsError);
110
- const id = `error-${[...Array(6)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')}`;
124
+ const id = `error-${[...Array(6)]
125
+ .map(() => Math.floor(Math.random() * 16).toString(16))
126
+ .join('')}`;
111
127
  if (!error) {
112
- error = Object.assign(
113
- document.createElement('p'), {
114
- id,
115
- className: this._options.classErrorElement,
116
- innerHTML: message
128
+ error = Object.assign(document.createElement('p'), {
129
+ id,
130
+ className: this._options.classErrorElement,
131
+ innerHTML: message,
117
132
  });
118
133
  element.setAttribute('aria-describedby', id);
119
134
  parent.appendChild(error);
120
135
  } else {
121
136
  if (error.tagName === 'P') {
122
137
  if (message === error.innerHTML) return;
123
- const newError = Object.assign(
124
- document.createElement('ul'), {
125
- id,
126
- className: this._options.classErrorElement,
127
- innerHTML: `<li>${error.innerHTML}</li>`
138
+ const newError = Object.assign(document.createElement('ul'), {
139
+ id,
140
+ className: this._options.classErrorElement,
141
+ innerHTML: `<li>${error.innerHTML}</li>`,
128
142
  });
129
143
  element.setAttribute('aria-describedby', id);
130
144
  parent.appendChild(newError);
@@ -169,8 +183,9 @@ export default class FormControl {
169
183
  // -
170
184
  /** @private */
171
185
  _formCreateBound() {
172
- ['_onChange', '_onFormSubmit', 'onFormSubmit']
173
- .forEach((fn) => this[fn] = this[fn].bind(this));
186
+ ['_onChange', '_onFormSubmit', 'onFormSubmit'].forEach(
187
+ (fn) => (this[fn] = this[fn].bind(this))
188
+ );
174
189
  }
175
190
 
176
191
  /** @private */
@@ -179,22 +194,28 @@ export default class FormControl {
179
194
  const group = el.closest(this._options.selectorGroup);
180
195
  if (group === null) return;
181
196
  group.classList.remove(this._options.classIsError);
182
- const currentErrors = [...group.querySelectorAll(`.${this._options.classErrorElement}`)];
183
- currentErrors.forEach(error => {
197
+ const currentErrors = [
198
+ ...group.querySelectorAll(`.${this._options.classErrorElement}`),
199
+ ];
200
+ currentErrors.forEach((error) => {
184
201
  error.classList.remove(this._options.classIsError);
185
202
  error.parentNode.removeChild(error);
186
203
  });
187
204
  el.removeAttribute('aria-describedby');
188
205
  } else {
189
- const isErrors = [...this._form.querySelectorAll(`${this._options.classIsError}`)];
190
- const currentErrors = [...this._form.querySelectorAll(`.${this._options.classErrorElement}`)];
191
- currentErrors.forEach(error => {
206
+ const isErrors = [
207
+ ...this._form.querySelectorAll(`${this._options.classIsError}`),
208
+ ];
209
+ const currentErrors = [
210
+ ...this._form.querySelectorAll(`.${this._options.classErrorElement}`),
211
+ ];
212
+ currentErrors.forEach((error) => {
192
213
  error.parentNode.removeChild(error);
193
214
  });
194
- isErrors.forEach(error => {
215
+ isErrors.forEach((error) => {
195
216
  error.classList.remove(this._options.classIsError);
196
217
  });
197
- this._domForm.els.forEach( input => {
218
+ this._domForm.els.forEach((input) => {
198
219
  input.removeAttribute('aria-describedby');
199
220
  });
200
221
  }
@@ -211,7 +232,8 @@ export default class FormControl {
211
232
  invalid = true;
212
233
  const type = el.getAttribute('type');
213
234
  if (type === 'radio') this.setError(el, this._options.i18n.radio);
214
- else if (type === 'checkbox') this.setError(el, this._options.i18n.checkbox);
235
+ else if (type === 'checkbox')
236
+ this.setError(el, this._options.i18n.checkbox);
215
237
  else if (type !== 'hidden') this.setError(el, this._options.i18n.empty);
216
238
  }
217
239
  if (!testEmail(el, this._form)) {
@@ -248,9 +270,12 @@ export default class FormControl {
248
270
  firstErrorElement.focus();
249
271
  if (this._options.animateToFirstError) {
250
272
  gsap.to(window, {
251
- duration: .6,
252
- scrollTo: (window.pageYOffset + firstErrorElement.getBoundingClientRect().top - 150)
253
- })
273
+ duration: 0.6,
274
+ scrollTo:
275
+ window.scrollY +
276
+ firstErrorElement.getBoundingClientRect().top -
277
+ 150,
278
+ });
254
279
  }
255
280
  }
256
281
  return isValid;
@@ -260,18 +285,26 @@ export default class FormControl {
260
285
  _formGrabDom() {
261
286
  /** @private */
262
287
  this._domForm = {};
263
- this._domForm.inputs = [...this._form.querySelectorAll('input[type=text],input[type=number],input[type=password],input[type=hidden],input[type=search],input[type=email],input[type=tel],textarea')];
264
- this._domForm.choices = [...this._form.querySelectorAll('select, input[type=radio],input[type=checkbox],input[type=file]')];
288
+ this._domForm.inputs = [
289
+ ...this._form.querySelectorAll(
290
+ 'input[type=text],input[type=number],input[type=password],input[type=hidden],input[type=search],input[type=email],input[type=tel],textarea'
291
+ ),
292
+ ];
293
+ this._domForm.choices = [
294
+ ...this._form.querySelectorAll(
295
+ 'select, input[type=radio],input[type=checkbox],input[type=file]'
296
+ ),
297
+ ];
265
298
  this._domForm.els = [...this._domForm.inputs, ...this._domForm.choices];
266
299
  }
267
300
 
268
301
  /** @private */
269
302
  _formAddEvents() {
270
303
  this._form.addEventListener('submit', this._onFormSubmit);
271
- this._domForm.inputs.forEach(input => {
304
+ this._domForm.inputs.forEach((input) => {
272
305
  input.addEventListener('keyup', this._onChange);
273
306
  });
274
- this._domForm.choices.forEach(input => {
307
+ this._domForm.choices.forEach((input) => {
275
308
  input.addEventListener('change', this._onChange);
276
309
  });
277
310
  }
@@ -289,7 +322,11 @@ export function testRequired(el, form) {
289
322
 
290
323
  const type = el.getAttribute('type');
291
324
  if (type === 'radio') {
292
- const radios = [...form.querySelectorAll(`input[type="radio"][name="${el.getAttribute('name')}"]`)];
325
+ const radios = [
326
+ ...form.querySelectorAll(
327
+ `input[type="radio"][name="${el.getAttribute('name')}"]`
328
+ ),
329
+ ];
293
330
  for (let i = 0; i < radios.length; i++) {
294
331
  if (radios[i].checked) return true;
295
332
  }
@@ -319,7 +356,9 @@ export function testEmail(el, form) {
319
356
  export function testSame(el, form) {
320
357
  const hasSame = el.getAttribute('data-formvalidate-same');
321
358
  if (hasSame === null) return true;
322
- const twinEl = form.querySelector(`[data-formvalidate-same=${el.getAttribute('data-formvalidate-same')}]`);
359
+ const twinEl = form.querySelector(
360
+ `[data-formvalidate-same=${el.getAttribute('data-formvalidate-same')}]`
361
+ );
323
362
  return twinEl.value === el.value;
324
363
  }
325
364
 
@@ -334,4 +373,4 @@ export function testPattern(el, form) {
334
373
  if (pattern === null || el.value === '') return true;
335
374
  const rgx = new RegExp(pattern);
336
375
  return rgx.test(el.value);
337
- }
376
+ }
@@ -4,7 +4,7 @@ import EventEmitter from 'events';
4
4
  // singleton
5
5
  let singleton = Symbol();
6
6
  let singletonEnforcer = Symbol();
7
- const SIMPLE_REFENCE = .5;
7
+ const SIMPLE_REFENCE = 0.5;
8
8
  const TABLET_WIDTH = 768;
9
9
 
10
10
  class GParallax extends EventEmitter {
@@ -36,7 +36,7 @@ class GParallax extends EventEmitter {
36
36
  height: 0,
37
37
  width: 0,
38
38
  scrollY: 0,
39
- ease: 1
39
+ ease: 1,
40
40
  };
41
41
 
42
42
  this._onGrab();
@@ -53,9 +53,11 @@ class GParallax extends EventEmitter {
53
53
  _onResize() {
54
54
  this._isResizing = true;
55
55
 
56
- this._vars.scrollY = window.pageYOffset;
57
- this._vars.width = document.documentElement.clientWidth || window.innerWidth;
58
- this._vars.height = document.documentElement.clientHeight || window.innerHeight;
56
+ this._vars.scrollY = window.scrollY;
57
+ this._vars.width =
58
+ document.documentElement.clientWidth || window.innerWidth;
59
+ this._vars.height =
60
+ document.documentElement.clientHeight || window.innerHeight;
59
61
 
60
62
  this._resetItemsCached();
61
63
  this._resetBgCached();
@@ -66,7 +68,7 @@ class GParallax extends EventEmitter {
66
68
  }
67
69
 
68
70
  _onScroll() {
69
- this._vars.scrollY = window.pageYOffset;
71
+ this._vars.scrollY = window.scrollY;
70
72
  window.requestAnimationFrame(this._update);
71
73
  }
72
74
 
@@ -78,11 +80,17 @@ class GParallax extends EventEmitter {
78
80
  }
79
81
 
80
82
  _onGrab() {
81
- const items = Array.prototype.slice.call(document.body.querySelectorAll('[data-prllx-item]', 0));
82
- const itemsSimple = Array.prototype.slice.call(document.body.querySelectorAll('[data-prllx-aw]', 0));
83
+ const items = Array.prototype.slice.call(
84
+ document.body.querySelectorAll('[data-prllx-item]', 0)
85
+ );
86
+ const itemsSimple = Array.prototype.slice.call(
87
+ document.body.querySelectorAll('[data-prllx-aw]', 0)
88
+ );
83
89
 
84
90
  this._domItems = [...items, ...itemsSimple];
85
- this._domBgItems = Array.prototype.slice.call(document.body.querySelectorAll('[data-prllx-bg]', 0));
91
+ this._domBgItems = Array.prototype.slice.call(
92
+ document.body.querySelectorAll('[data-prllx-bg]', 0)
93
+ );
86
94
 
87
95
  const countImage = this._domItems.length;
88
96
  let imgCount = 0;
@@ -105,8 +113,13 @@ class GParallax extends EventEmitter {
105
113
  // -
106
114
 
107
115
  _createBound() {
108
- ['_onResize', '_onScroll', '_calculateViewport', '_update', '_onGrab']
109
- .forEach((fn) => this[fn] = this[fn].bind(this));
116
+ [
117
+ '_onResize',
118
+ '_onScroll',
119
+ '_calculateViewport',
120
+ '_update',
121
+ '_onGrab',
122
+ ].forEach((fn) => (this[fn] = this[fn].bind(this)));
110
123
  }
111
124
 
112
125
  _addListeners() {
@@ -127,7 +140,8 @@ class GParallax extends EventEmitter {
127
140
  el.style.transform =
128
141
  el.style['-moz-transform'] =
129
142
  el.style['-ms-transform'] =
130
- el.style['-webkit-transform'] = `translate3d(0, 0, 0)`;
143
+ el.style['-webkit-transform'] =
144
+ `translate3d(0, 0, 0)`;
131
145
  el.classList.remove('u-hidden');
132
146
  });
133
147
  }
@@ -137,7 +151,8 @@ class GParallax extends EventEmitter {
137
151
  el.style.transform =
138
152
  el.style['-moz-transform'] =
139
153
  el.style['-ms-transform'] =
140
- el.style['-webkit-transform'] = `translate3d(0, 0, 0)`;
154
+ el.style['-webkit-transform'] =
155
+ `translate3d(0, 0, 0)`;
141
156
  el.style.height = '100%';
142
157
  el.style.top = '0%';
143
158
  });
@@ -146,12 +161,14 @@ class GParallax extends EventEmitter {
146
161
  _getCache() {
147
162
  this._cachedItems = [];
148
163
  this._cachedBackgrounds = [];
149
- this._domItems.forEach((el) => { this._cachedItems.push(this._createCacheItem(el)); });
164
+ this._domItems.forEach((el) => {
165
+ this._cachedItems.push(this._createCacheItem(el));
166
+ });
150
167
  this._domBgItems.forEach((el) => {
151
168
  const cache = this._createCacheItem(el);
152
- let delta = (cache.deltaEnd - cache.deltaStart) * 100 / 2;
153
- let top = (cache.deltaStart * 100 / 2).toFixed(0);
154
- (delta < 0) && (delta = -delta, top = -top);
169
+ let delta = ((cache.deltaEnd - cache.deltaStart) * 100) / 2;
170
+ let top = ((cache.deltaStart * 100) / 2).toFixed(0);
171
+ delta < 0 && ((delta = -delta), (top = -top));
155
172
  const height = 100 + delta;
156
173
  cache.el.style.height = `${height}%`;
157
174
  cache.el.style.top = `${top}%`;
@@ -161,7 +178,9 @@ class GParallax extends EventEmitter {
161
178
 
162
179
  _getCacheForSpecialCases() {
163
180
  this._cachedSpecialCases = [];
164
- this._specialCases.forEach((el) => { this._cachedSpecialCases.push(this._createCacheItem(el)); });
181
+ this._specialCases.forEach((el) => {
182
+ this._cachedSpecialCases.push(this._createCacheItem(el));
183
+ });
165
184
  }
166
185
 
167
186
  _createCacheItem(domEl) {
@@ -176,8 +195,8 @@ class GParallax extends EventEmitter {
176
195
  deltaStart: domEl.getAttribute('data-delta-start') || 0,
177
196
  deltaEnd: domEl.getAttribute('data-delta-end') || 0,
178
197
  invert: domEl.hasAttribute('data-invert') || false,
179
- state: true
180
- }
198
+ state: true,
199
+ };
181
200
 
182
201
  const elSimple = domEl.getAttribute('data-prllx-aw');
183
202
  if (elSimple !== null) {
@@ -202,7 +221,10 @@ class GParallax extends EventEmitter {
202
221
  cacheItem.el.style.transform =
203
222
  cacheItem.el.style['-moz-transform'] =
204
223
  cacheItem.el.style['-ms-transform'] =
205
- cacheItem.el.style['-webkit-transform'] = testo.type === 'hz' ? `translate3d(${testo.value}px, 0, 0)` : `translate3d(0, ${testo.value}px, 0)`;
224
+ cacheItem.el.style['-webkit-transform'] =
225
+ testo.type === 'hz'
226
+ ? `translate3d(${testo.value}px, 0, 0)`
227
+ : `translate3d(0, ${testo.value}px, 0)`;
206
228
  } else if (cacheItem.state) {
207
229
  cacheItem.el.classList.add('u-hidden');
208
230
  }
@@ -219,7 +241,8 @@ class GParallax extends EventEmitter {
219
241
  cacheItem.el.style.transform =
220
242
  cacheItem.el.style['-moz-transform'] =
221
243
  cacheItem.el.style['-ms-transform'] =
222
- cacheItem.el.style['-webkit-transform'] = `translate3d(0, ${testo.value}px, 0)`;
244
+ cacheItem.el.style['-webkit-transform'] =
245
+ `translate3d(0, ${testo.value}px, 0)`;
223
246
  }
224
247
  });
225
248
  }
@@ -238,25 +261,25 @@ class GParallax extends EventEmitter {
238
261
  const fullHeight = hh + this._vars.height;
239
262
 
240
263
  const scrollY = this._vars.scrollY;
241
- const itemScrollY = (top - scrollY);
264
+ const itemScrollY = top - scrollY;
242
265
 
243
266
  const min = this._vars.height;
244
267
 
245
- const max = - hh;
246
- const ratio = (itemScrollY - min) / (max - min) * speed;
268
+ const max = -hh;
269
+ const ratio = ((itemScrollY - min) / (max - min)) * speed;
247
270
 
248
- const value = (deltaStart + delta * ratio) + (- fullHeight + fullHeight / speed) * ratio;
271
+ const value =
272
+ deltaStart + delta * ratio + (-fullHeight + fullHeight / speed) * ratio;
249
273
  const isVisible = ratio > -1 && ratio < 2;
250
274
 
251
275
  return { isVisible: isVisible, value: value.toFixed(2) };
252
276
  }
253
277
 
254
278
  _calculateBgViewport(cache) {
255
-
256
279
  const speed = cache.speed;
257
280
 
258
- const deltaStart = cache.height * cache.deltaStart / 2;
259
- const deltaEnd = cache.height * cache.deltaEnd / 2;
281
+ const deltaStart = (cache.height * cache.deltaStart) / 2;
282
+ const deltaEnd = (cache.height * cache.deltaEnd) / 2;
260
283
  const delta = deltaEnd - deltaStart;
261
284
 
262
285
  const top = cache.top;
@@ -264,14 +287,14 @@ class GParallax extends EventEmitter {
264
287
  const hh = bottom - top;
265
288
 
266
289
  const scrollY = this._vars.scrollY;
267
- const itemScrollY = (top - scrollY);
290
+ const itemScrollY = top - scrollY;
268
291
 
269
292
  const min = this._vars.height;
270
- const max = - hh;
293
+ const max = -hh;
271
294
 
272
295
  const ratio = (itemScrollY - min) / (max - min);
273
296
  const isVisible = ratio > -1 && ratio < 2;
274
- const value = cache.invert ? (scrollY * speed) : (deltaStart + delta * ratio);
297
+ const value = cache.invert ? scrollY * speed : deltaStart + delta * ratio;
275
298
 
276
299
  return { isVisible: isVisible, value: value.toFixed(0) };
277
300
  }
package/classes/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  module.exports.GParallax = require('./globalParallax').default;
2
2
  module.exports.Nearby = require('./nearby').default;
3
3
  module.exports.FormControl = require('./formControl').default;
4
- module.exports.Sticky = require('./sticky').default;
4
+ module.exports.Sticky = require('./sticky').default;
package/classes/nearby.js CHANGED
@@ -12,21 +12,26 @@
12
12
  /**
13
13
  * Distance between two points P1 (x1,y1) and P2 (x2,y2).
14
14
  */
15
- const distancePoints = (x1, y1, x2, y2) => Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
15
+ const distancePoints = (x1, y1, x2, y2) =>
16
+ Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
16
17
 
17
18
  // from http://www.quirksmode.org/js/events_properties.html#position
18
19
  const getMousePos = (e) => {
19
- var posx = 0, posy = 0;
20
+ var posx = 0,
21
+ posy = 0;
20
22
  if (!e) var e = window.event;
21
23
  if (e.pageX || e.pageY) {
22
24
  posx = e.pageX;
23
25
  posy = e.pageY;
26
+ } else if (e.clientX || e.clientY) {
27
+ posx =
28
+ e.clientX +
29
+ document.body.scrollLeft +
30
+ document.documentElement.scrollLeft;
31
+ posy =
32
+ e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
24
33
  }
25
- else if (e.clientX || e.clientY) {
26
- posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
27
- posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
28
- }
29
- return { x: posx, y: posy }
34
+ return { x: posx, y: posy };
30
35
  };
31
36
 
32
37
  export default class Nearby {
@@ -36,33 +41,44 @@ export default class Nearby {
36
41
  this.init();
37
42
  }
38
43
  init() {
39
- this.mousemoveFn = (ev) => requestAnimationFrame(() => {
40
- const mousepos = getMousePos(ev);
41
- const docScrolls = { left: document.body.scrollLeft + document.documentElement.scrollLeft, top: document.body.scrollTop + document.documentElement.scrollTop };
42
- const elRect = this.DOM.el.getBoundingClientRect();
43
- const elCoords = {
44
- x1: elRect.left + docScrolls.left, x2: elRect.width + elRect.left + docScrolls.left,
45
- y1: elRect.top + docScrolls.top, y2: elRect.height + elRect.top + docScrolls.top
46
- };
47
- const closestPoint = { x: mousepos.x, y: mousepos.y };
44
+ this.mousemoveFn = (ev) =>
45
+ requestAnimationFrame(() => {
46
+ const mousepos = getMousePos(ev);
47
+ const docScrolls = {
48
+ left: document.body.scrollLeft + document.documentElement.scrollLeft,
49
+ top: document.body.scrollTop + document.documentElement.scrollTop,
50
+ };
51
+ const elRect = this.DOM.el.getBoundingClientRect();
52
+ const elCoords = {
53
+ x1: elRect.left + docScrolls.left,
54
+ x2: elRect.width + elRect.left + docScrolls.left,
55
+ y1: elRect.top + docScrolls.top,
56
+ y2: elRect.height + elRect.top + docScrolls.top,
57
+ };
58
+ const closestPoint = { x: mousepos.x, y: mousepos.y };
48
59
 
49
- if (mousepos.x < elCoords.x1) {
50
- closestPoint.x = elCoords.x1;
51
- }
52
- else if (mousepos.x > elCoords.x2) {
53
- closestPoint.x = elCoords.x2;
54
- }
55
- if (mousepos.y < elCoords.y1) {
56
- closestPoint.y = elCoords.y1;
57
- }
58
- else if (mousepos.y > elCoords.y2) {
59
- closestPoint.y = elCoords.y2;
60
- }
61
- if (this.options.onProgress) {
62
- this.options.onProgress(distancePoints(mousepos.x, mousepos.y, closestPoint.x, closestPoint.y))
63
- }
64
- });
60
+ if (mousepos.x < elCoords.x1) {
61
+ closestPoint.x = elCoords.x1;
62
+ } else if (mousepos.x > elCoords.x2) {
63
+ closestPoint.x = elCoords.x2;
64
+ }
65
+ if (mousepos.y < elCoords.y1) {
66
+ closestPoint.y = elCoords.y1;
67
+ } else if (mousepos.y > elCoords.y2) {
68
+ closestPoint.y = elCoords.y2;
69
+ }
70
+ if (this.options.onProgress) {
71
+ this.options.onProgress(
72
+ distancePoints(
73
+ mousepos.x,
74
+ mousepos.y,
75
+ closestPoint.x,
76
+ closestPoint.y
77
+ )
78
+ );
79
+ }
80
+ });
65
81
 
66
82
  window.addEventListener('mousemove', this.mousemoveFn);
67
83
  }
68
- }
84
+ }