allow direct access to 'eventHolder' object for custom events #817

Open
dnschnur opened this Issue Sep 28, 2012 · 0 comments

Comments

Projects
None yet
1 participant
Owner

dnschnur commented Sep 28, 2012

Original author: changos...@gmail.com (August 14, 2012 19:07:51)

feature request:
allow direct, arbitrary access to the 'eventHolder' canvas object

currently, it is a somewhat clumsy task to try to get the 'eventHolder' object:

  1. hack into the flot source code & manually expose it:
    plot.eventHolder=eventHolder;

  2. use the 'bindEvents' hook to 'grab&save' a reference to the object:
    var eHolder=null;
    var pltOpts={};
    ...
    pltOpts.hooks={bindEvents:[function(p,e){eHolder=e;}]};
    ...
    $.plot(obj,data,pltOpts);
    ...
    //do stuff with eHolder, since it should now be defined
    //reason this might be necessary is for 'delayed/postponed event binding&unbinding'
    //i.e., cases where you dont want or cant define event handlers using the 'bindEvents' hooks

  3. manually try to 'select' the eventHolder object (which is ugly & might be unreliable?)
    var eventHolder=$("#plot_div canvas.overlay");

solution:
add a simple 'getter' function that returns the internal 'eventHolder' canvas object;
For event-binding safety, I guess you could do a simple internal test to see 'bindEvents' has already been executed, and return 'false' if not; otherwise, return the canvas obj. But realistically, I dont think this would be a problem. thoughts/feedback?

var eventsDone_=false;

function bindEvents(){
...
executeHooks(hooks.bindEvents,[plot.eventHolder]);
eventsDone_=true;
}
plot.getEventHolder=function(){
return (eventsDone_)?eventHolder:false;
}

Original issue: http://code.google.com/p/flot/issues/detail?id=738

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment