Setting default parameters in jQuery plugin -
Setting default parameters in jQuery plugin -
i'm looking way set default numerical value defaults parameters of plugin or have alternative retrieve default value via ajax call. in other words:
var defaults = { param1: 1000, totaltime : null // default value i'm looking in seconds }
so that:
$('.test').myplugin({ param1: 1000, totaltime: function () { $.ajax({ url: 'totaltime.php', type: 'post', success: function(data) { // retrieve value here } }); } }); or $('.test').myplugin({ param1: 1000, totaltime: 200 // numerical });
i started playing plugins , found interesting concept having little problem it. here's plugin looks (the basic set new plugin).
(function($) { $.fn.myplugin = function(options) { var plugin = this; var defaults = { param1: 1000, totaltime : null } plugin.init = function() { plugin.settings = $.extend({}, defaults, options); plugin.timer(); } plugin.settings = {} plugin.timer = function() { } plugin.init(); homecoming this; }; })(jquery);
just define defaults this:
var defaults =$.extend( { param1: 1000, totaltime : null },options);
and can utilize defaults.param1
or defaults.totaltime
update:
the above illustration how can set totaltime value numerically default.
if wanna alter during plugin can this:
defaults.totaltime=500;
or
defaults.totaltime=givenval; //givenval variable contains value
also in jquery code, can set totaltime this:
$('#test').myplugin({ totaltime:500 });
or
$('#test').myplugin({ totaltime:givenval });
so should value ajax, set in variable, , pass plugin mentioned above!
jquery jquery-plugins
Comments
Post a Comment