GMOD / jbrowse

JBrowse 1, a full-featured genome browser built with JavaScript and HTML5. For JBrowse 2, see https://github.com/GMOD/jbrowse-components.
http://jbrowse.org
Other
460 stars 199 forks source link

Callbacks for jBrowse after init #646

Closed terrymun closed 8 years ago

terrymun commented 8 years ago

Is there a standardized (namespaced) event emission from jBrowse? It would be nice that jBrowse would emit custom events during/after initialization.

Listening on these events are extremely useful because they allow developers to manipulate certain DOM elements that are only created during/after initialization.

nathandunn commented 8 years ago

:+1:

To get around this right now (we are looking for populated browser tracks) we delay our check and then call into the code repeatedly every few hundred ms until it is there. An event callback would be nice.

cmdcolin commented 8 years ago

There are milestone functions that can help. I.e. in your code

 JBrowse.afterMilestone(milestoneName, function() { /* your function */ });
cmdcolin commented 8 years ago

Also I would generally recommend against manually manipulating JBrowse DOM elements. There are possiblilities of stepping on each others toes (?)

If you have specific use case that might help

enuggetry commented 8 years ago

This plugin illustrates how to trap various jbrowse Publish and Milestone events: https://github.com/GMOD/jbrowse/tree/master/plugins/DebugEvents

On Mon, Nov 2, 2015 at 9:31 AM, Nathan Dunn notifications@github.com wrote:

[image: :+1:]

To get around this right now (we are looking for populated browser tracks) we delay our check and then call into the code repeatedly every few hundred ms until it is there. An event callback would be nice.

— Reply to this email directly or view it on GitHub https://github.com/GMOD/jbrowse/issues/646#issuecomment-153093844.

nathandunn commented 8 years ago

:+1: Great plugin!

terrymun commented 8 years ago

@cmdcolin I understand that extensive DOM manipulation with jBrowse will probably break a lot of things. I'm not trying to go that far, actually ;)

Sometimes jBrowse takes awhile to initialise completely—and I would like to display an overlay, or a loading message, to the user when this is happening, and remove/hide it when initialisation is complete. This is one of the use cases where listening to an emitted custom event from jBrowse would be extremely useful.

I am only familiar with authoring jQuery plugins, so it's probably difficult for me to work out how things works for jBrowse. If I could offer by two cents, an event can be emitted from any child element which can bubble up the DOM tree. One can then capture these bubbling events at the wrapping container, and act on it accordingly.

Thanks for taking your time to respond. I really appreciate how responsive you guys are :+1:

p/s: And jBrowse is amazing as it is :)

cmdcolin commented 8 years ago

@terrymun No worries!

The loading screen is actually a good use case. There's a little example of how you can create a loading screen just by modifying the html here https://github.com/GMOD/jbrowse/issues/576#issuecomment-114947648

It just adds a "afterMilestone" call to the index.html

I also like the debug plugin!

hexylena commented 8 years ago

http://gmod.org/wiki/JBrowse_Configuration_Guide#Configure_a_Loading_Page documented this on the wiki since we use it as well.

cmdcolin commented 8 years ago

Thanks @erasche !

I guess we can close this issue now. Feel free to reopen though if any thing else is needed

The bubbling idea might come in handy too if we figure out how to componentize it more (i keep waiting for web components to become more popular....)