I'm looking for a way to set a default numerical value to my defaults parameters of my plugin or have the option to retrieve the default value via an ajax call. In other words:
var defaults = {
param1: 1000,
totalTime : null // the default value i'm looking for 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 only recently started playing with plugins and found this an interesting concept but am having a little trouble with it. Here's what my plugin looks like now (the basic set up for 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();
return this;
};
})(jQuery);