-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update wavesurfer.minimap.js #955
Conversation
renders the minimap without the need to resize the window. Changed this.wavesurfer.on('ready', this.render.bind(this)); to this.wavesurfer.on('ready', my.render.bind(this));
added the fixes for the drawPeaks()
plugin/wavesurfer.minimap.js
Outdated
@@ -94,7 +94,7 @@ WaveSurfer.Minimap = WaveSurfer.util.extend({}, WaveSurfer.Drawer, WaveSurfer.Dr | |||
|
|||
bindWaveSurferEvents: function () { | |||
var my = this; | |||
this.wavesurfer.on('ready', this.render.bind(this)); | |||
this.wavesurfer.on('ready', my.render()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is causing errors. I guess you meant my.render.bind(this)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the error i get with my.render()
is:
Uncaught TypeError: Cannot read property 'apply' of undefined
at [...]/wavesurfer.js/dist/wavesurfer.js:736:15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piem what code are you using that it gives the error?
@katspaugh without the change it wouldn't show the minimap on on ready event and the user is required to resize the window for it to work properly or call minimap.render(); right after.
var minimap1 = wavesurfer.initMinimap({
container: document.querySelector('#minimap'),
height: 30,
waveColor: '#ddd',
progressColor: '#999',
cursorColor: '#68A93D'
});
//without calling this it won't render on ready
minimap1.render();
In the resize event it's calling my.render(); which makes it work when resizing the window. On the ready event it's not calling it so it won't render the minimap until you resize the window or call minimap.render() yourself after wavesurfer.initMinimap().
var onResize = function () {
if (prevWidth != my.wrapper.clientWidth) {
prevWidth = my.wrapper.clientWidth;
my.render();
my.progress(my.wavesurfer.backend.getPlayedPercents());
}
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piem @katspaugh happy with @entonbiba's feedback? thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.wavesurfer.on('ready', my.render());
is certainly wrong, since it's calling the render function immediately.
You need to either subscribe like the original code:
this.wavesurfer.on('ready', this.render.bind(this))):
Or simply call this.render()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@katspaugh yes this.render(); will work. I had already updated it to that in the preview code but didn't in this pull. I'll do that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@entonbiba you are missing the point.
this.wavesurfer.on('ready', someCallback)
– that's a subscription. The first parameter is the name of an event, the second parameter is a function.
What you are doing is calling the callback immediately, instead of passing it as a parameter:
this.wavesurfer.on('ready', someCallback())
This is equivalent to
someCallback();
this.wavesurfer.on('ready', undefined)
So if you think the render method should be called immediately, just call it without the on-ready call.
check to see if a parameter called "miniRenderOnLoad" is set to true, if it is render the minimap on load.
@katspaugh what about adding a check to see if a parameter called "miniRenderOnLoad" is set to true? It would make the rending on load optional instead of default. This way this.wavesurfer.on('ready', this.render.bind(this))): remains as default. Something like this ok to add? |
@entonbiba I don't really get why it's needed. How can it render the minimap (which is just a small copy of the waveform) before the main waveform is ready? |
plugin/wavesurfer.minimap.js
Outdated
@@ -94,7 +94,17 @@ WaveSurfer.Minimap = WaveSurfer.util.extend({}, WaveSurfer.Drawer, WaveSurfer.Dr | |||
|
|||
bindWaveSurferEvents: function () { | |||
var my = this; | |||
this.wavesurfer.on('ready', this.render()); | |||
// check if parameter renderOnLoad is definied and set to true to render minimap on load |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo 'definied'
plugin/wavesurfer.minimap.js
Outdated
@@ -94,7 +94,17 @@ WaveSurfer.Minimap = WaveSurfer.util.extend({}, WaveSurfer.Drawer, WaveSurfer.Dr | |||
|
|||
bindWaveSurferEvents: function () { | |||
var my = this; | |||
this.wavesurfer.on('ready', this.render()); | |||
// check if parameter renderOnLoad is definied and set to true to render minimap on load | |||
var miniRenderOnLoad = (this.params.miniRenderOnLoad||false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces around ||
missing
plugin/wavesurfer.minimap.js
Outdated
if (typeof this.params.miniRenderOnLoad !== "undefined") { | ||
if (miniRenderOnLoad) { | ||
this.render(); | ||
} else{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after else
plugin/wavesurfer.minimap.js
Outdated
} else{ | ||
this.wavesurfer.on('ready', this.render.bind(this))): | ||
} | ||
} else{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after else
@katspaugh It will render after the I added the parameter as an option, in case someone doesn't want to render it right away. They will have to resize the window like that, the way it currently works. I still think it should render right away. |
Let's just render it right away unconditionally, maybe? |
will update docs and create example for minimap plugin - minimap should be initialized within the main wavesurfer ready event.
@katspaugh ok updated. I'll update the example and add it to the plugins section. Once the debounce function is added to master, I'll update the resizing event for minimap. debounce pull request #964 |
Merged, thank you! |
renders the minimap without the need to resize the window. #954 #942 #951
Preview:
http://codepen.io/entonbiba/pen/ggeGyG
Changed
to