Skip to content

Commit 8e2fdbc

Browse files
committed
🎨 various typo / lint / logic
1 parent 59812c2 commit 8e2fdbc

14 files changed

+130
-124
lines changed

.browserslistrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# Browsers that we support
2+
> 1%

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
browser: true,
44
es6: true
55
},
6-
extends: 'airbnb-base',
6+
extends: ['airbnb-base', 'plugin:prettier/recommended'],
77
globals: {
88
Atomics: 'readonly',
99
SharedArrayBuffer: 'readonly'

.prettierrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"useTabs": false,
3-
"printWidth": 300,
3+
"printWidth": 150,
44
"tabWidth": 4,
55
"singleQuote": true,
66
"trailingComma": "none",
77
"jsxBracketSameLine": false,
8-
"semi": true
8+
"semi": true,
9+
"arrowParens": "always"
910
}

dist/simpleParallax.js

Lines changed: 56 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* simpleParallax - simpleParallax is a simple JavaScript library that gives your website parallax animations on any images or videos,
3-
* @date: 07-06-2020 15:10:5,
3+
* @date: 07-06-2020 15:53:39,
44
* @version: 5.4.1,
55
* @link: https://simpleparallax.com/
66
*/
@@ -112,10 +112,10 @@ __webpack_require__.r(__webpack_exports__);
112112
__webpack_require__.d(__webpack_exports__, "default", function() { return /* binding */ simpleParallax_SimpleParallax; });
113113

114114
// CONCATENATED MODULE: ./src/helpers/isSupportedBrowser.js
115-
//need closest support
116-
//https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
117-
//need Intersection Observer support
118-
//https://github.com/w3c/IntersectionObserver/tree/master/polyfill
115+
// need closest support
116+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
117+
// need Intersection Observer support
118+
// https://github.com/w3c/IntersectionObserver/tree/master/polyfill
119119
var isSupportedBrowser = function isSupportedBrowser() {
120120
return Element.prototype.closest && 'IntersectionObserver' in window;
121121
};
@@ -170,7 +170,7 @@ var Viewport = /*#__PURE__*/function () {
170170
var viewport = new Viewport();
171171

172172
// CONCATENATED MODULE: ./src/helpers/convertToArray.js
173-
// check wether the element is a Node List, a HTML Collection or an array
173+
// check whether the element is a Node List, a HTML Collection or an array
174174
// return an array of nodes
175175
var convertToArray = function convertToArray(elements) {
176176
if (NodeList.prototype.isPrototypeOf(elements) || HTMLCollection.prototype.isPrototypeOf(elements)) return Array.from(elements);
@@ -198,8 +198,8 @@ var cssTransform = function cssTransform() {
198198
// CONCATENATED MODULE: ./src/helpers/isImageLoaded.js
199199
// check if media is fully loaded
200200
var isImageLoaded = function isImageLoaded(media) {
201-
//if the media is a video, return true
202-
if (media.tagName.toLowerCase() == 'video') {
201+
// if the media is a video, return true
202+
if (media.tagName.toLowerCase() === 'video') {
203203
return true;
204204
} // check if media is set as the parameter
205205

@@ -264,7 +264,7 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
264264
this.init();
265265
} else {
266266
this.element.addEventListener('load', function () {
267-
//timeout to ensure the image is fully loaded into the DOM
267+
// timeout to ensure the image is fully loaded into the DOM
268268
setTimeout(function () {
269269
_this.init(true);
270270
}, 50);
@@ -281,8 +281,8 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
281281
if (this.isInit) return;
282282

283283
if (asyncInit) {
284-
//in case the image is lazy loaded, the rangemax should be cleared
285-
//so it will be updated in the next getTranslateValue()
284+
// in case the image is lazy loaded, the rangemax should be cleared
285+
// so it will be updated in the next getTranslateValue()
286286
this.rangeMax = null;
287287
} // check if element has not been already initialized with simpleParallax
288288

@@ -327,8 +327,8 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
327327

328328
var elementToWrap = this.element.closest('picture') || this.element; // create a .simpleParallax wrapper container
329329

330-
var wrapper = document.createElement('div'); //if there is a custom wrapper
331-
//override the wrapper with it
330+
var wrapper = document.createElement('div'); // if there is a custom wrapper
331+
// override the wrapper with it
332332

333333
if (customWrapper) {
334334
wrapper = this.element.closest(this.settings.customWrapper);
@@ -350,7 +350,7 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
350350
value: function unWrapElement() {
351351
var wrapper = this.elementContainer; // get the customWrapper if any
352352

353-
var customWrapper = this.settings.customWrapper && this.element.closest(this.settings.customWrapper); //if there is a custom wrapper, we jusy need to remove the class and style
353+
var customWrapper = this.settings.customWrapper && this.element.closest(this.settings.customWrapper); // if there is a custom wrapper, we jusy need to remove the class and style
354354

355355
if (customWrapper) {
356356
wrapper.classList.remove('simpleParallax');
@@ -436,13 +436,15 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
436436
}, {
437437
key: "intersectionObserverCallback",
438438
value: function intersectionObserverCallback(entries) {
439-
for (var i = entries.length - 1; i >= 0; i--) {
440-
if (entries[i].isIntersecting) {
441-
this.isVisible = true;
439+
var _this3 = this;
440+
441+
entries.forEach(function (entry) {
442+
if (entry.isIntersecting) {
443+
_this3.isVisible = true;
442444
} else {
443-
this.isVisible = false;
445+
_this3.isVisible = false;
444446
}
445-
}
447+
});
446448
} // check if the current element is visible in the Viewport
447449
// for browser that not support Intersection Observer API
448450

@@ -542,14 +544,22 @@ function simpleParallax_toConsumableArray(arr) { return simpleParallax_arrayWith
542544

543545
function simpleParallax_nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
544546

545-
function simpleParallax_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return simpleParallax_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return simpleParallax_arrayLikeToArray(o, minLen); }
546-
547547
function simpleParallax_iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
548548

549549
function simpleParallax_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return simpleParallax_arrayLikeToArray(arr); }
550550

551+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || simpleParallax_unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
552+
553+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
554+
555+
function simpleParallax_unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return simpleParallax_arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return simpleParallax_arrayLikeToArray(o, minLen); }
556+
551557
function simpleParallax_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
552558

559+
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
560+
561+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
562+
553563
function simpleParallax_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
554564

555565
function simpleParallax_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -562,15 +572,14 @@ function simpleParallax_createClass(Constructor, protoProps, staticProps) { if (
562572

563573
var isInit = false;
564574
var instances = [];
565-
var instancesLength;
566575
var frameID;
567576
var resizeID;
568577

569578
var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
570579
function SimpleParallax(elements, options) {
571580
simpleParallax_classCallCheck(this, SimpleParallax);
572581

573-
if (!elements) return; //check if the browser support simpleParallax
582+
if (!elements) return; // check if the browser support simpleParallax
574583

575584
if (!helpers_isSupportedBrowser()) return;
576585
this.elements = helpers_convertToArray(elements);
@@ -587,7 +596,11 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
587596
this.settings = Object.assign(this.defaults, options);
588597

589598
if (this.settings.customContainer) {
590-
this.customContainer = helpers_convertToArray(this.settings.customContainer)[0];
599+
var _convertToArray = helpers_convertToArray(this.settings.customContainer);
600+
601+
var _convertToArray2 = _slicedToArray(_convertToArray, 1);
602+
603+
this.customContainer = _convertToArray2[0];
591604
}
592605

593606
this.lastPosition = -1;
@@ -606,8 +619,8 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
606619
instances = [].concat(simpleParallax_toConsumableArray(this.elements.map(function (element) {
607620
return new parallax(element, _this.settings);
608621
})), simpleParallax_toConsumableArray(instances)); // update the instance length
609-
610-
instancesLength = instances.length; // only if this is the first simpleParallax init
622+
// instancesLength = instances.length;
623+
// only if this is the first simpleParallax init
611624

612625
if (!isInit) {
613626
// init the frame
@@ -629,21 +642,21 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
629642
value: function handleResize() {
630643
// re-get all the viewport positions
631644
viewport.setViewportAll(this.customContainer);
632-
633-
for (var i = instancesLength - 1; i >= 0; i--) {
645+
instances.forEach(function (instance) {
634646
// re-get the current element offset
635-
instances[i].getElementOffset(); // re-get the range if the current element
636-
637-
instances[i].getRangeMax();
638-
} // force the request animation frame to fired
647+
instance.getElementOffset(); // re-get the range if the current element
639648

649+
instance.getRangeMax();
650+
}); // force the request animation frame to fired
640651

641652
this.lastPosition = -1;
642653
} // animation frame
643654

644655
}, {
645656
key: "proceedRequestAnimationFrame",
646657
value: function proceedRequestAnimationFrame() {
658+
var _this2 = this;
659+
647660
// get the offset top of the viewport
648661
viewport.setViewportTop(this.customContainer);
649662

@@ -657,10 +670,9 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
657670

658671
viewport.setViewportBottom(); // proceed with the current element
659672

660-
for (var i = instancesLength - 1; i >= 0; i--) {
661-
this.proceedElement(instances[i]);
662-
} // callback the animationFrame
663-
673+
instances.forEach(function (instance) {
674+
_this2.proceedElement(instance);
675+
}); // callback the animationFrame
664676

665677
frameID = window.requestAnimationFrame(this.proceedRequestAnimationFrame); // store the last position
666678

@@ -692,35 +704,31 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
692704
}, {
693705
key: "destroy",
694706
value: function destroy() {
695-
var _this2 = this;
707+
var _this3 = this;
696708

697709
var instancesToDestroy = []; // remove all instances that need to be destroyed from the instances array
698710

699711
instances = instances.filter(function (instance) {
700-
if (_this2.elements.includes(instance.element)) {
712+
if (_this3.elements.includes(instance.element)) {
701713
// push instance that need to be destroyed into instancesToDestroy
702714
instancesToDestroy.push(instance);
703715
return false;
704716
}
705717

706718
return instance;
707719
});
708-
709-
for (var i = instancesToDestroy.length - 1; i >= 0; i--) {
720+
instancesToDestroy.forEach(function (instance) {
710721
// unset style
711-
instancesToDestroy[i].unSetStyle();
722+
instance.unSetStyle();
712723

713-
if (this.settings.overflow === false) {
724+
if (_this3.settings.overflow === false) {
714725
// if overflow option is set to false
715726
// unwrap the element from .simpleParallax wrapper container
716-
instancesToDestroy[i].unWrapElement();
727+
instance.unWrapElement();
717728
}
718-
} // update the instance length var
719-
720-
721-
instancesLength = instances.length; // if no instances left, remove the raf and resize event = simpleParallax fully destroyed
729+
}); // if no instances left, remove the raf and resize event = simpleParallax fully destroyed
722730

723-
if (!instancesLength) {
731+
if (!instances.length) {
724732
// cancel the animation frame
725733
window.cancelAnimationFrame(frameID); // detach the resize event
726734

0 commit comments

Comments
 (0)