Skip to content

Commit

Permalink
timeline: re-render on zoom; resolve #825
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh authored and mspae committed Aug 20, 2017
1 parent 8665f78 commit cf86b2c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions example/zoom/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

<!-- wavesurfer.js -->
<script src="../../dist/wavesurfer.js"></script>
<script src="../../dist/plugin/wavesurfer.timeline.js"></script>
<script src="../../dist/plugin/wavesurfer.regions.js"></script>

<!-- Demo -->
<script src="main.js"></script>
Expand All @@ -35,6 +37,8 @@ <h1 itemprop="name">Zooming Feature Example</h1>
<!-- Here be the waveform -->
</div>

<div id="timeline"></div>

<div class="controls">
<div class="row">
<div class="col-sm-7">
Expand Down
20 changes: 19 additions & 1 deletion example/zoom/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,25 @@ document.addEventListener('DOMContentLoaded', function () {
container: document.querySelector('#waveform'),
waveColor: '#A8DBA8',
progressColor: '#3B8686',
backend: 'MediaElement'
backend: 'MediaElement',
plugins: [
WaveSurfer.regions.create({
regions: [
{
start: 0,
end: 5,
color: 'hsla(400, 100%, 30%, 0.1)'
}, {
start: 10,
end: 100,
color: 'hsla(200, 50%, 70%, 0.1)'
}
]
}),
WaveSurfer.timeline.create({
container: '#timeline'
})
]
});


Expand Down
3 changes: 3 additions & 0 deletions src/plugin/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default class TimelinePlugin {

this.canvases = [];

this._onZoom = () => this.render();
this._onScroll = () => {
if (this.wrapper && this.drawer.wrapper) {
this.wrapper.scrollLeft = this.drawer.wrapper.scrollLeft;
Expand All @@ -142,6 +143,7 @@ export default class TimelinePlugin {
this.render();
ws.drawer.wrapper.addEventListener('scroll', this._onScroll);
ws.on('redraw', this._onRedraw);
ws.on('zoom', this._onZoom);
};
}

Expand All @@ -156,6 +158,7 @@ export default class TimelinePlugin {
destroy() {
this.unAll();
this.wavesurfer.un('redraw', this._onRedraw);
this.wavesurfer.un('zoom', this._onZoom);
this.wavesurfer.un('ready', this._onReady);
this.wavesurfer.drawer.wrapper.removeEventListener('scroll', this._onScroll);
if (this.wrapper && this.wrapper.parentNode) {
Expand Down

0 comments on commit cf86b2c

Please sign in to comment.