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?

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
spal
  • 731
  • 3
  • 9
  • 20
  • 1
    try like this.. http://stackoverflow.com/a/19247955/2567813 – CJ Ramki Sep 27 '14 at 06:22
  • you can use Jquery's noConflict() function – Karthik Ganesan Sep 30 '14 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 – Wissam El-Kik Oct 02 '14 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 (http://api.jqueryui.com/jQuery.widget.bridge/) – Wissam El-Kik Oct 02 '14 at 12:56

2 Answers2

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.

Wissam El-Kik
  • 2,469
  • 1
  • 17
  • 21
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

Mr. Pumpkin
  • 6,212
  • 6
  • 44
  • 60
  • `$.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. – Wissam El-Kik Oct 10 '14 at 09:48