clicktone 0.0.1 → 0.0.3
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.
- package/README.md +7 -3
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +7 -5
- package/dist/index.module.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +10 -6
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
12
|
<p align="center">A simple class to create elements that play audio when clicked.</p>
|
|
13
|
-
<p align="center"><a href="https://
|
|
13
|
+
<p align="center"><a href="https://n2q8x8.csb.app/">Demo</a></p>
|
|
14
14
|
<br>
|
|
15
15
|
|
|
16
16
|
➤ **Install**
|
|
@@ -30,10 +30,14 @@ import ClickTone from 'clicktone';
|
|
|
30
30
|
|
|
31
31
|
➤ **Usage**
|
|
32
32
|
|
|
33
|
+
<sup>You can pass type, class, or ID selectors, as well as the DOM element itself, as parameters for 'el'.</sup>
|
|
33
34
|
```javascript
|
|
34
|
-
const clickTone = new ClickTone(
|
|
35
|
+
const clickTone = new ClickTone({
|
|
36
|
+
el: '#button',
|
|
37
|
+
sound: 'sound.mp3',
|
|
38
|
+
});
|
|
35
39
|
|
|
36
|
-
clickTone.init(
|
|
40
|
+
clickTone.init();
|
|
37
41
|
```
|
|
38
42
|
<br>
|
|
39
43
|
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,9 @@ $parcel$defineInteropFlag(module.exports);
|
|
|
11
11
|
|
|
12
12
|
$parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
|
|
13
13
|
class $4fa36e821943b400$var$ClickTone {
|
|
14
|
-
constructor(){
|
|
14
|
+
constructor({ el: el = "", sound: sound = "" } = {}){
|
|
15
|
+
this.el = el;
|
|
16
|
+
this.sound = sound;
|
|
15
17
|
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
|
16
18
|
this.setupIOSAudioContextFix();
|
|
17
19
|
}
|
|
@@ -35,10 +37,10 @@ class $4fa36e821943b400$var$ClickTone {
|
|
|
35
37
|
source.start(0);
|
|
36
38
|
}).catch();
|
|
37
39
|
}
|
|
38
|
-
init(
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
this.playAudio(
|
|
40
|
+
init() {
|
|
41
|
+
const targetElement = typeof this.el === "string" ? document.querySelector(this.el) : this.el;
|
|
42
|
+
targetElement.addEventListener("click", ()=>{
|
|
43
|
+
this.playAudio(this.sound);
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA,MAAM;IACJ,
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA,MAAM;IACJ,YAAY,MAAE,KAAK,WAAI,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAE;QACxC,IAAI,CAAC,EAAE,GAAG;QACV,IAAI,CAAC,KAAK,GAAG;QAEb,IAAI,CAAC,YAAY,GAAG,IAAK,CAAA,OAAO,YAAY,IACvC,OAAO,kBAAkB,AAAD;QAC7B,IAAI,CAAC,uBAAuB;IAC9B;IAEA,0BAA0B;QACxB,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,eAAe,kBAAkB,QAAQ;YACvE,MAAM,SAAS;gBACb,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;oBAC9B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;oBAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,YAAY;gBAChD;YACF;YAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc,QAAQ;YACrD,SAAS,IAAI,CAAC,gBAAgB,CAAC,YAAY,QAAQ;QACrD;IACF;IAEA,UAAU,GAAG,EAAE;QACb,MAAM,KACH,IAAI,CAAC,CAAC,WAAa,SAAS,WAAW,IACvC,IAAI,CAAC,CAAC,SAAW,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SACnD,IAAI,CAAC,CAAC;YACL,MAAM,SAAS,IAAI,CAAC,YAAY,CAAC,kBAAkB;YACnD,OAAO,MAAM,GAAG;YAChB,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW;YAC5C,OAAO,KAAK,CAAC;QACf,GACC,KAAK;IACV;IAEA,OAAO;QACL,MAAM,gBAAgB,OAAO,IAAI,CAAC,EAAE,KAAK,WAAW,SAAS,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE;QAE7F,cAAc,gBAAgB,CAAC,SAAS;YACtC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK;QAC3B;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class ClickTone {\n constructor({ el = '', sound = '' } = {}) {\n this.el = el;\n this.sound = sound;\n\n this.audioContext = new (window.AudioContext\n || window.webkitAudioContext)();\n this.setupIOSAudioContextFix();\n }\n\n setupIOSAudioContextFix() {\n if (this.audioContext.state === 'suspended' && 'ontouchstart' in window) {\n const unlock = () => {\n this.audioContext.resume().then(() => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n });\n };\n\n document.body.addEventListener('touchstart', unlock, false);\n document.body.addEventListener('touchend', unlock, false);\n }\n }\n\n playAudio(url) {\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((buffer) => this.audioContext.decodeAudioData(buffer))\n .then((audioData) => {\n const source = this.audioContext.createBufferSource();\n source.buffer = audioData;\n source.connect(this.audioContext.destination);\n source.start(0);\n })\n .catch();\n }\n\n init() {\n const targetElement = typeof this.el === 'string' ? document.querySelector(this.el) : this.el;\n\n targetElement.addEventListener('click', () => {\n this.playAudio(this.sound);\n });\n }\n}\n\nexport default ClickTone;\n"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
class $cf838c15c8b009ba$var$ClickTone {
|
|
2
|
-
constructor(){
|
|
2
|
+
constructor({ el: el = "", sound: sound = "" } = {}){
|
|
3
|
+
this.el = el;
|
|
4
|
+
this.sound = sound;
|
|
3
5
|
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
|
4
6
|
this.setupIOSAudioContextFix();
|
|
5
7
|
}
|
|
@@ -23,10 +25,10 @@ class $cf838c15c8b009ba$var$ClickTone {
|
|
|
23
25
|
source.start(0);
|
|
24
26
|
}).catch();
|
|
25
27
|
}
|
|
26
|
-
init(
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
this.playAudio(
|
|
28
|
+
init() {
|
|
29
|
+
const targetElement = typeof this.el === "string" ? document.querySelector(this.el) : this.el;
|
|
30
|
+
targetElement.addEventListener("click", ()=>{
|
|
31
|
+
this.playAudio(this.sound);
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
34
|
}
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,MAAM;IACJ,
|
|
1
|
+
{"mappings":"AAAA,MAAM;IACJ,YAAY,MAAE,KAAK,WAAI,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAE;QACxC,IAAI,CAAC,EAAE,GAAG;QACV,IAAI,CAAC,KAAK,GAAG;QAEb,IAAI,CAAC,YAAY,GAAG,IAAK,CAAA,OAAO,YAAY,IACvC,OAAO,kBAAkB,AAAD;QAC7B,IAAI,CAAC,uBAAuB;IAC9B;IAEA,0BAA0B;QACxB,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,eAAe,kBAAkB,QAAQ;YACvE,MAAM,SAAS;gBACb,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;oBAC9B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;oBAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,YAAY;gBAChD;YACF;YAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc,QAAQ;YACrD,SAAS,IAAI,CAAC,gBAAgB,CAAC,YAAY,QAAQ;QACrD;IACF;IAEA,UAAU,GAAG,EAAE;QACb,MAAM,KACH,IAAI,CAAC,CAAC,WAAa,SAAS,WAAW,IACvC,IAAI,CAAC,CAAC,SAAW,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SACnD,IAAI,CAAC,CAAC;YACL,MAAM,SAAS,IAAI,CAAC,YAAY,CAAC,kBAAkB;YACnD,OAAO,MAAM,GAAG;YAChB,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW;YAC5C,OAAO,KAAK,CAAC;QACf,GACC,KAAK;IACV;IAEA,OAAO;QACL,MAAM,gBAAgB,OAAO,IAAI,CAAC,EAAE,KAAK,WAAW,SAAS,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE;QAE7F,cAAc,gBAAgB,CAAC,SAAS;YACtC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK;QAC3B;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class ClickTone {\n constructor({ el = '', sound = '' } = {}) {\n this.el = el;\n this.sound = sound;\n\n this.audioContext = new (window.AudioContext\n || window.webkitAudioContext)();\n this.setupIOSAudioContextFix();\n }\n\n setupIOSAudioContextFix() {\n if (this.audioContext.state === 'suspended' && 'ontouchstart' in window) {\n const unlock = () => {\n this.audioContext.resume().then(() => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n });\n };\n\n document.body.addEventListener('touchstart', unlock, false);\n document.body.addEventListener('touchend', unlock, false);\n }\n }\n\n playAudio(url) {\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((buffer) => this.audioContext.decodeAudioData(buffer))\n .then((audioData) => {\n const source = this.audioContext.createBufferSource();\n source.buffer = audioData;\n source.connect(this.audioContext.destination);\n source.start(0);\n })\n .catch();\n }\n\n init() {\n const targetElement = typeof this.el === 'string' ? document.querySelector(this.el) : this.el;\n\n targetElement.addEventListener('click', () => {\n this.playAudio(this.sound);\n });\n }\n}\n\nexport default ClickTone;\n"],"names":[],"version":3,"file":"index.module.js.map"}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
class ClickTone {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.
|
|
2
|
+
constructor({ el = '', sound = '' } = {}) {
|
|
3
|
+
this.el = el;
|
|
4
|
+
this.sound = sound;
|
|
5
|
+
|
|
6
|
+
this.audioContext = new (window.AudioContext
|
|
7
|
+
|| window.webkitAudioContext)();
|
|
4
8
|
this.setupIOSAudioContextFix();
|
|
5
9
|
}
|
|
6
10
|
|
|
@@ -31,11 +35,11 @@ class ClickTone {
|
|
|
31
35
|
.catch();
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
init(
|
|
35
|
-
const
|
|
38
|
+
init() {
|
|
39
|
+
const targetElement = typeof this.el === 'string' ? document.querySelector(this.el) : this.el;
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
this.playAudio(
|
|
41
|
+
targetElement.addEventListener('click', () => {
|
|
42
|
+
this.playAudio(this.sound);
|
|
39
43
|
});
|
|
40
44
|
}
|
|
41
45
|
}
|