parsley/app/assets/javascripts/checkable.js
2016-01-30 17:02:19 -06:00

36 lines
877 B
JavaScript

(function($) {
var pluginName = "checkable";
var defaultOptions = {
childrenSelector: "li",
selectedClass: "checked"
};
var methods = {
initialize: function (opts, sources) {
return this.each(function() {
var options = $.extend({}, defaultOptions, opts);
$(this).on("click", options.childrenSelector, function(evt) {
$(evt.currentTarget).toggleClass(options.selectedClass);
});
});
}
};
var privateMethods = {
};
$.fn[pluginName] = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || ! method) {
return methods.initialize.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.' + pluginName);
}
};
})(jQuery);