6

I have defined a JQfactory plugin like this

(function($, window, document) {
    $.jqfactory('my.tooltip', {

      /* My tooltip code */         

    }, false);
}(jQuery, window, document));

Now assuming I have included Bootstrap framework also in my page, and I want to call my version of tooltip() only, not the bootstrap version. How do I achieve using the namespace $.my.tooltip?

4
  • 1
    try like this.. stackoverflow.com/a/19247955/2567813 Commented Sep 27, 2014 at 6:22
  • you can use Jquery's noConflict() function Commented Sep 30, 2014 at 16:02
  • @KarthikGanesan jQuery noConflict doesn't solve this issue, because it only separates the different jQuery versions. The tooltip function isn't part of the original jQuery code, so it doesn't make sense to use jQuery noConflict, unless you want to load 2 different jQuery versions and use 2 different jQuery objects "$" and "$$" for instance. This would definitely cause many problems later on because the developer will have a spaghetti code Commented Oct 2, 2014 at 12:54
  • @CJRamki the solution you provided works only when there's a conflict between jQuery UI and Bootstrap because the solution is based on the jQuery Widget Bridge which is part of jQuery UI (api.jqueryui.com/jQuery.widget.bridge) Commented Oct 2, 2014 at 12:56

2 Answers 2

1

As mentioned on the Bootstrap website:

http://getbootstrap.com/javascript/#js-noconflict

// return $.fn.tooltip to previously assigned value
var bootstrapTooltip = $.fn.tooltip.noConflict();

// give $().bootstrapBtn the Bootstrap functionality
$.fn.bootstrapTooltip = bootstrapTooltip;

You would use $.bootstrapTooltip to call the Bootstrap tooltip (if you ever want to use it). You'll be able to use $.tooltip for something else.

jQuery noConflict doesn't solve this issue, because it only separates the different jQuery versions. The tooltip function isn't part of the original jQuery code, so it doesn't make sense to use jQuery noConflict, unless you want to load 2 different jQuery versions and use 2 different jQuery objects "$" and "$$" for instance. This would definitely cause many problems later on because the developer will have a spaghetti code.

Sign up to request clarification or add additional context in comments.

Comments

0

you can either use $.widget.bridge like this

$.widget.bridge( "my_tooltip", $.my.tooltip );
$('#myTooltip').my_tooltip({});

or do this

$.my.tooltip(null, $('#myTooltip2'));

check more details here

1 Comment

$.widget.bridge is part of jQuery UI. The OP mentioned that he's using Bootstrap and jQuery, but he didn't mentioned anything related to jQuery UI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.