Skip to content

Commit

Permalink
Fix click-to-seek for audios which are not spanning the entire canvas (
Browse files Browse the repository at this point in the history
  • Loading branch information
whenov committed Mar 31, 2016
1 parent b0d8457 commit c500aba
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,25 @@ WaveSurfer.Drawer = {

handleEvent: function (e) {
e.preventDefault();

var bbox = this.wrapper.getBoundingClientRect();
return ((e.clientX - bbox.left + this.wrapper.scrollLeft) / this.wrapper.scrollWidth) || 0;

var nominalWidth = this.width;
var parentWidth = this.getWidth();

var progress;

if (!this.params.fillParent && nominalWidth < parentWidth) {
progress = ((e.clientX - bbox.left) * this.params.pixelRatio / nominalWidth) || 0;

if (progress > 1) {
progress = 1;
}
} else {
progress = ((e.clientX - bbox.left + this.wrapper.scrollLeft) / this.wrapper.scrollWidth) || 0;
}

return progress;
},

setupWrapperEvents: function () {
Expand Down

0 comments on commit c500aba

Please sign in to comment.