Дайте следующий плагин jQuery:
(function($) {
$.fn.prefCookie = function(method) {
var options = {
cookieName : 'prefs',
actionType : 'click',
key : '',
value : false
}
var $obj;
var methods = {
init : function(config) {
return this.each(function() {
if(config) { $.extend(options, config) }
$obj = $(this);
options.value ?
$obj.bind(options.actionType,helpers.setPref) :
$obj.bind(options.actionType,helpers.togglePref) ;
});
},
anotherFunction : function() {
console.log('you did it!');
}
}
var helpers = {
togglePref : function() {
},
setPref : function() {
}
}
if (methods[method] && method.toLowerCase() != 'init') {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error( 'Method "' + method + '" does not exist in the Pref Cookie plugin!');
}
}
})(jQuery);
Как можно anotherFunction
, не подключая плагин ни к чему.Я хотел бы сделать $.prefCookie.anotherFunction
или что-то, но это не работает.Есть предложения?