Skip to content

Commit

Permalink
Merge pull request #7 from lemehovskiy/release/v2.0.1
Browse files Browse the repository at this point in the history
added additional check for jquery script, updated scroller for preven…
  • Loading branch information
lemehovskiy authored Dec 14, 2023
2 parents 87866ee + 8297d9e commit 7541f8e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pullRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ jobs:
- name: Install dependencies
run: npm install
- name: Run linter
run: npm run lint
run: npm run lint
- name: Run build
run: npm run build
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parallax_background",
"version": "2.0.0",
"version": "2.0.1",
"description": "VanillaJS parallax background plugin",
"types": "./dist/index.d.ts",
"main": "./dist/parallaxBackground.umd.js",
Expand All @@ -13,7 +13,7 @@
}
},
"devDependencies": {
"@lemehovskiy/scroller": "^0.2.2",
"@lemehovskiy/scroller": "^0.2.4",
"@types/jquery": "^3.5.29",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
Expand Down
51 changes: 29 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ declare global {
}
}

declare global {
interface Window {
$: JQuery;
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare let gsap: any;

Expand Down Expand Up @@ -53,7 +59,7 @@ export default class ParallaxBackground {
doubleShift: number;
deviceOrientation: DeviceOrientationTypes | undefined;

constructor(element: HTMLElement, options: Partial<OptionsType>) {
constructor(element: HTMLElement, options?: Partial<OptionsType>) {
this.settings = {
events: [EventTypes.Scroll],
animationType: AnimationTypes.Shift,
Expand Down Expand Up @@ -237,7 +243,6 @@ export default class ParallaxBackground {
private subscribeScrollEvent() {
const scroller = new Scroller(this.element, {
autoAdjustScrollOffset: true,
scrollTriggerOffset: { start: 0, end: 0 },
});

scroller.progressChanged.on((progress) => {
Expand All @@ -246,24 +251,26 @@ export default class ParallaxBackground {
}
}

$.fn.parallaxBackground = function (
...params: [Partial<OptionsType>] | Array<string>
) {
const opt = params[0];
const args = Array.prototype.slice.call(params, 1);
const length = this.length;
let ret = undefined;
for (let i = 0; i < length; i++) {
if (typeof opt === "object" || typeof opt === "undefined") {
this[i].parallaxBackground = new ParallaxBackground(this[i], opt);
} else {
// eslint-disable-next-line prefer-spread
ret = this[i].parallaxBackground[opt].apply(
this[i].parallaxBackground,
args,
);
if (window.$ !== undefined) {
$.fn.parallaxBackground = function (
...params: [Partial<OptionsType>] | Array<string>
) {
const opt = params[0];
const args = Array.prototype.slice.call(params, 1);
const length = this.length;
let ret = undefined;
for (let i = 0; i < length; i++) {
if (typeof opt === "object" || typeof opt === "undefined") {
this[i].parallaxBackground = new ParallaxBackground(this[i], opt);
} else {
// eslint-disable-next-line prefer-spread
ret = this[i].parallaxBackground[opt].apply(
this[i].parallaxBackground,
args,
);
}
if (typeof ret !== "undefined") return ret;
}
if (typeof ret !== "undefined") return ret;
}
return this;
};
return this;
};
}

0 comments on commit 7541f8e

Please sign in to comment.