I dig into Bootstrap on Twitter and now I want to try adding some features to the plugins, but I cannot figure out how to do this. Using the modal plugin as an example ( http://twitter.github.com/bootstrap/javascript.html#modals ), I would like to add a new function to the plugin that can be called, like the standard plugin methods. The closest I think is I came up with the following code, but all I get when I try to access is that the function is not part of the object.
Any suggestions? This is what I tried, which seems to be closest to what I need to do:
$.extend($.fn.modal, { showFooterMessage: function (message) { alert("Hey"); } });
Then I would like to call it as follows:
$(this).closest(".modal").modal("showFooterMessage");
EDIT: Ok, I figured out how to do this:
(function ($) { var extensionMethods = { displayFooterMessage: function ($msg) { var args = arguments[0] var that = this;
The problem with the existing set of Bootstrap plugins is that if someone wants to extend them, none of the new methods can accept arguments. My attempt to “fix” this was to add the reception of arguments to the plugin function call.
$.fn.modal = function (option) { var args = arguments[1] || {}; return this.each(function () { var $this = $(this) , data = $this.data('modal') , options = typeof option == 'object' && option if (!data) $this.data('modal', (data = new Modal(this, options))) if (typeof option == 'string') data[option](args) else data.show() })
jquery jquery-plugins twitter-bootstrap
AlexGad Feb 04 2018-12-12T00: 00Z
source share