clicktone 0.0.2 → 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.map +1 -1
- package/dist/index.module.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +3 -4
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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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
|
@@ -3,8 +3,8 @@ class ClickTone {
|
|
|
3
3
|
this.el = el;
|
|
4
4
|
this.sound = sound;
|
|
5
5
|
|
|
6
|
-
this.audioContext = new (window.AudioContext
|
|
7
|
-
window.webkitAudioContext)();
|
|
6
|
+
this.audioContext = new (window.AudioContext
|
|
7
|
+
|| window.webkitAudioContext)();
|
|
8
8
|
this.setupIOSAudioContextFix();
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -36,8 +36,7 @@ class ClickTone {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
init() {
|
|
39
|
-
const targetElement =
|
|
40
|
-
typeof this.el === 'string' ? document.querySelector(this.el) : this.el;
|
|
39
|
+
const targetElement = typeof this.el === 'string' ? document.querySelector(this.el) : this.el;
|
|
41
40
|
|
|
42
41
|
targetElement.addEventListener('click', () => {
|
|
43
42
|
this.playAudio(this.sound);
|