Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8613747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:57:28+00:00 2026-06-12T04:57:28+00:00

I am digging into Twitter’s Bootstrap and now want to try and add some

  • 0

I am digging into Twitter’s Bootstrap and now want to try and add some functionality to the plugins, but I can’t figure out how to do so. Using the modal plugin as an example (http://twitter.github.com/bootstrap/javascript.html#modals), I’d like to add a new function to the plugin that can be called as one would the standard plugin methods. THe closest I think I have come is 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 have tried that seems to be the closest to what I need to do:

 $.extend($.fn.modal, { 
    showFooterMessage: function (message) { 
        alert("Hey"); 
    } 
}); 

Then I would want 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;

            // do stuff here
        }
    }

    $.extend(true, $.fn.modal.Constructor.prototype, extensionMethods);
})(jQuery);

The problem with the existing set of Bootstrap plugins is that if anyone wants to extend them, none of the new methods can accept arguments. My attempt to “fix” this was to add the acceptance of arguments in the plugins 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()

    }) // end each
} // end $.fn.modal
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:57:30+00:00Added an answer on June 12, 2026 at 4:57 am

    This is an old thread, but I just made some custom extensions to modal using the following pattern:

    // save the original function object
    var _super = $.fn.modal;
    
    // add custom defaults
    $.extend( _super.defaults, {
        foo: 'bar',
        john: 'doe'
    });
    
    // create a new constructor
    var Modal = function(element, options) {
    
        // do custom constructor stuff here
    
         // call the original constructor
        _super.Constructor.apply( this, arguments );
    
    }
    
    // extend prototypes and add a super function
    Modal.prototype = $.extend({}, _super.Constructor.prototype, {
        constructor: Modal,
        _super: function() {
            var args = $.makeArray(arguments);
            _super.Constructor.prototype[args.shift()].apply(this, args);
        },
        show: function() {
    
            // do custom method stuff
    
            // call the original method
            this._super('show');
        }
    });
    
    // override the old initialization with the new constructor
    $.fn.modal = $.extend(function(option) {
    
        var args = $.makeArray(arguments),
            option = args.shift();
    
        return this.each(function() {
    
            var $this = $(this);
            var data = $this.data('modal'),
                options = $.extend({}, _super.defaults, $this.data(), typeof option == 'object' && option);
    
            if ( !data ) {
                $this.data('modal', (data = new Modal(this, options)));
            }
            if (typeof option == 'string') {
                data[option].apply( data, args );
            }
            else if ( options.show ) {
                data.show.apply( data, args );
            }
        });
    
    }, $.fn.modal);
    

    This way you can

    1) add your own default options

    2) create new methods with custom arguments and access to original (super) functions

    3) do stuff in the constructor before and/or after the original constructor is called

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently started digging into C# but I can't by my life figure out
I've been digging into Sublime's snippets, plugins and macros, but I can't seem to
I'm digging into Node.js now and the whole idea seems brilliant to me. But
I'm digging into ejabberd but I can't find a way to inspect its Mnesia
I was digging into some source code I am working on. I found a
I'm just digging into the gcc manual and some things are still unclear to
So I'm digging into tombstoning of WP7 but haven't found sufficient information on when
I'm just digging into d3 and learning a lot, but I'm sure I'm missing/misunderstanding
I've been digging into ASP.net MVC for a little while now. It seems that
This question has been asked before, but digging into the documentation for the various

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.