Skip to content

Commit

Permalink
html audio: reveal too
Browse files Browse the repository at this point in the history
  • Loading branch information
kapouer committed Feb 13, 2020
1 parent 4a4ac13 commit f0ab787
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/html/elements/audio.js
Expand Up @@ -38,7 +38,7 @@ exports.audio = {
default: false
}
},
html: `<audio is="element-audio"
html: `<audio is="element-audio" data-src="[url]"
preload="metadata" autoplay="[autoplay]" loop="[loop]" controls="[controls]"></audio>`,
scripts: [
'../ui/audio.js'
Expand Down
34 changes: 32 additions & 2 deletions packages/html/ui/audio.js
@@ -1,9 +1,39 @@
class HTMLElementAudio extends HTMLAudioElement {
static get defaults() {
return {
dataSrc: null
};
}

patch(state) {
this.classList.remove('error', 'loading');
var loc = Page.parse(this.options.src);
var meta = state.scope.$hrefs && state.scope.$hrefs[loc.pathname] || {};
if (!meta || !meta.width || !meta.height) return;
this.width = meta.width;
this.height = meta.height;
}
reveal(state) {
var curSrc = this.options.src;
if (curSrc != this.currentSrc) {
try {
this.currentSrc = curSrc;
} catch(e) {
// pass
}
this.setAttribute('src', curSrc);
}
if (this.isContentEditable) this.pause();
}
handleClick(e) {
if (this.isContentEditable) e.preventDefault();
}
setup(state) {
if (this.isContentEditable) this.pause();
captureLoad() {
this.classList.remove('loading');
}
captureError() {
this.classList.remove('loading');
this.classList.add('error');
}
}

Expand Down

0 comments on commit f0ab787

Please sign in to comment.