Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added additional check for jquery script, updated scroller for preven… #7

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
};
}