views:

23

answers:

2

Inside of fullCalendar(), a jQuery plugin, I can get the value of view.visStart. Outside of the function view.visStart is not available. How can I either get view.visStart out (and is this bad because it is Global?) or how do I insert a click function within the plugin call? thanks.

$('#calendar').fullCalendar({
    events: "js/events.json"
    console.log(view.visStart); //value is returned
});

$('.fc-button-next').click(function() {
    console.log(view.visStart); //view is not defined
});
+1  A: 

The simplest is using a variable from a parent scope.

You have to pay attention to how and when you change that variable of course.

You could also return the variable somehow. Or if you wanted it write protected, you could return a function that returns the variable. But I'm not sure how return calls would affect .fullCalendar(), since I don't know how it works.

(function() {                      // <== Scope for your stuff
    var myVis;                     // myVis is available everywhere in your scope
                                   //   but it is not global

    $(function() {                                               // <== Doc ready
        $('#calendar').fullCalendar({
            events: "js/events.json"
            cmyVis = view.visStart; //set myVis
        });

        $('.fc-button-next').click(function() {
            console.log(myVis);                             //view is not defined
        });
    });
}());
Peter Ajtai
This is what I was looking for.
orolo
+1  A: 

Maybe this is not what you are asking for but if you want to bind a click function within a jquery plugin you can use live():

First inspect the rendered html and see what the plugin has inserted- find the id or the class of the html element you are trying to bind the click function to. The live() will bind any element even after the line has been called and the element is created later.

$('.pluginlink').live('click', function() {
  //code
});

I dont know if this is what you are looking for but part of the question is how to insert a click function inside a plugin. Good luck!

Mouhannad
+1 thanks. OK. I'll try live() to see if I can get the click to work correctly.
orolo