Skip to content

Commit

Permalink
fix esm destroy function
Browse files Browse the repository at this point in the history
  • Loading branch information
tholman committed Nov 15, 2022
1 parent b1ae89d commit 6f530ff
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cursor-effects",
"type": "module",
"description": "Old-school cursor effects for your browser built in modern JavaScript.",
"version": "1.0.6",
"version": "1.0.7",
"main": "./dist/cjs.cjs",
"module": "./dist/esm.js",
"exports": {
Expand Down
9 changes: 7 additions & 2 deletions src/bubbleCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function bubbleCursor(options) {
// Re-initialise or destroy the cursor when the prefers-reduced-motion setting changes
prefersReducedMotion.onchange = () => {
if (prefersReducedMotion.matches) {
this.destroy();
destroy();
} else {
init();
}
Expand Down Expand Up @@ -126,7 +126,7 @@ export function bubbleCursor(options) {
animationFrame = requestAnimationFrame(loop);
}

this.destroy = () => {
function destroy() {
canvas.remove();
cancelAnimationFrame(animationFrame);
element.removeEventListener("mousemove", onMouseMove);
Expand Down Expand Up @@ -177,4 +177,9 @@ export function bubbleCursor(options) {
}

init();


return {
destroy: destroy
}
}
10 changes: 7 additions & 3 deletions src/clockCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function clockCursor(options) {
// Re-initialise or destroy the cursor when the prefers-reduced-motion setting changes
prefersReducedMotion.onchange = () => {
if (prefersReducedMotion.matches) {
this.destroy();
destroy();
} else {
init();
}
Expand Down Expand Up @@ -343,14 +343,18 @@ export function clockCursor(options) {
animationFrame = requestAnimationFrame(loop);
}

this.destroy = () => {
function destroy() {
canvas.remove();
cancelAnimationFrame(animationFrame);
element.removeEventListener("mousemove", onMouseMove);
element.removeEventListener("touchmove", onTouchMove);
element.removeEventListener("touchstart", onTouchMove);
window.addEventListener("resize", onWindowResize);
};
}

init();

return {
destroy: destroy,
};
}
8 changes: 6 additions & 2 deletions src/emojiCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function emojiCursor(options) {
// Re-initialise or destroy the cursor when the prefers-reduced-motion setting changes
prefersReducedMotion.onchange = () => {
if (prefersReducedMotion.matches) {
this.destroy();
destroy();
} else {
init();
}
Expand Down Expand Up @@ -174,7 +174,7 @@ export function emojiCursor(options) {
animationFrame = requestAnimationFrame(loop);
}

this.destroy = () => {
function destroy() {
canvas.remove();
cancelAnimationFrame(animationFrame);
element.removeEventListener("mousemove", onMouseMove);
Expand Down Expand Up @@ -218,4 +218,8 @@ export function emojiCursor(options) {
}

init();

return {
destroy: destroy
}
}
8 changes: 6 additions & 2 deletions src/fairyDustCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function fairyDustCursor(options) {
// Re-initialise or destroy the cursor when the prefers-reduced-motion setting changes
prefersReducedMotion.onchange = () => {
if (prefersReducedMotion.matches) {
this.destroy();
destroy();
} else {
init();
}
Expand Down Expand Up @@ -175,7 +175,7 @@ export function fairyDustCursor(options) {
animationFrame = requestAnimationFrame(loop);
}

this.destroy = () => {
function destroy() {
canvas.remove();
cancelAnimationFrame(animationFrame);
element.removeEventListener("mousemove", onMouseMove);
Expand Down Expand Up @@ -215,4 +215,8 @@ export function fairyDustCursor(options) {
}

init();

return {
destroy: destroy
}
}
8 changes: 6 additions & 2 deletions src/followingDotCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function followingDotCursor(options) {
// Re-initialise or destroy the cursor when the prefers-reduced-motion setting changes
prefersReducedMotion.onchange = () => {
if (prefersReducedMotion.matches) {
this.destroy();
destroy();
} else {
init();
}
Expand Down Expand Up @@ -94,7 +94,7 @@ export function followingDotCursor(options) {
animationFrame = requestAnimationFrame(loop);
}

this.destroy = () => {
function destroy() {
canvas.remove();
cancelAnimationFrame(loop);
element.removeEventListener("mousemove", onMouseMove);
Expand All @@ -119,4 +119,8 @@ export function followingDotCursor(options) {
}

init();

return {
destroy: destroy
}
}
8 changes: 6 additions & 2 deletions src/ghostCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function ghostCursor(options) {
// Re-initialise or destroy the cursor when the prefers-reduced-motion setting changes
prefersReducedMotion.onchange = () => {
if (prefersReducedMotion.matches) {
this.destroy();
destroy();
} else {
init();
}
Expand Down Expand Up @@ -123,7 +123,7 @@ export function ghostCursor(options) {
animationFrame = requestAnimationFrame(loop);
}

this.destroy = () => {
function destroy() {
canvas.remove();
cancelAnimationFrame(animationFrame);
element.removeEventListener("mousemove", onMouseMove);
Expand Down Expand Up @@ -158,4 +158,8 @@ export function ghostCursor(options) {
}

init();

return {
destroy: destroy
}
}
8 changes: 6 additions & 2 deletions src/rainbowCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function rainbowCursor(options) {
// Re-initialise or destroy the cursor when the prefers-reduced-motion setting changes
prefersReducedMotion.onchange = () => {
if (prefersReducedMotion.matches) {
this.destroy();
destroy();
} else {
init();
}
Expand Down Expand Up @@ -155,7 +155,7 @@ export function rainbowCursor(options) {
animationFrame = requestAnimationFrame(loop);
}

this.destroy = () => {
function destroy() {
canvas.remove();
cancelAnimationFrame(animationFrame);
element.removeEventListener("mousemove", onMouseMove);
Expand All @@ -167,4 +167,8 @@ export function rainbowCursor(options) {
}

init();

return {
destroy: destroy
}
}
8 changes: 6 additions & 2 deletions src/snowflakeCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function snowflakeCursor(options) {
// Re-initialise or destroy the cursor when the prefers-reduced-motion setting changes
prefersReducedMotion.onchange = () => {
if (prefersReducedMotion.matches) {
this.destroy();
destroy();
} else {
init();
}
Expand Down Expand Up @@ -155,7 +155,7 @@ export function snowflakeCursor(options) {
animationFrame = requestAnimationFrame(loop);
}

this.destroy = () => {
function destroy() {
canvas.remove();
cancelAnimationFrame(animationFrame);
element.removeEventListener("mousemove", onMouseMove);
Expand Down Expand Up @@ -209,4 +209,8 @@ export function snowflakeCursor(options) {
}

init();

return {
destroy: destroy
}
}
8 changes: 6 additions & 2 deletions src/springyEmojiCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function springyEmojiCursor(options) {
// Re-initialise or destroy the cursor when the prefers-reduced-motion setting changes
prefersReducedMotion.onchange = () => {
if (prefersReducedMotion.matches) {
this.destroy();
destroy();
} else {
init();
}
Expand Down Expand Up @@ -222,7 +222,7 @@ export function springyEmojiCursor(options) {
animationFrame = requestAnimationFrame(loop);
}

this.destroy = () => {
function destroy() {
canvas.remove();
cancelAnimationFrame(animationFrame);
element.removeEventListener("mousemove", onMouseMove);
Expand Down Expand Up @@ -268,4 +268,8 @@ export function springyEmojiCursor(options) {
}

init();

return {
destroy: destroy
}
}
8 changes: 6 additions & 2 deletions src/trailingCursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function trailingCursor(options) {
// Re-initialise or destroy the cursor when the prefers-reduced-motion setting changes
prefersReducedMotion.onchange = () => {
if (prefersReducedMotion.matches) {
this.destroy();
destroy();
} else {
init();
}
Expand Down Expand Up @@ -125,7 +125,7 @@ export function trailingCursor(options) {
animationFrame = requestAnimationFrame(loop);
}

this.destroy = () => {
function destroy() {
canvas.remove();
cancelAnimationFrame(animationFrame);
element.removeEventListener("mousemove", onMouseMove);
Expand All @@ -150,4 +150,8 @@ export function trailingCursor(options) {
}

init();

return {
destroy: destroy
}
}

0 comments on commit 6f530ff

Please sign in to comment.