The problem with my plugin is that i need to expose var chart and maintain chainability. How can i accomplish this? This is the first plugin i wrote and i don’t know if chainability is really important to preserve. Thanks.
Html piece
<div id="chart1" class="chart"></div>
<div id="chart2" class="chart"></div>
Plugin invocation
$("div").chart();
Plugin definition
(function($) {
$.fn.chart = function(options) {
return this.each() // Maintain chainability
{
// Stuff, ajax call and then...
var chart = new Highcharts(options);
// Expose each chart variable for each container (<div>)
}
};
})(jQuery);
EDIT: added clarification about chart variable.
First, you should read Plugins/Authoring if you havent already. There are some good ideas in there.
Second, you can try something like this:
This would then be called normally with
$('#something').charts({});or$('#something').charts('get_charts');