Function call using namespace

I defined a JQfactory plugin like this

(function($, window, document) { $.jqfactory('my.tooltip', { /* My tooltip code */ }, false); }(jQuery, window, document)); 

Now, believing that I have included the Bootstrap platform also on my page, and I want to name only my version of tooltip() , and not the bootstrap version. How to achieve using $.my.tooltip ?

+6
source share
2 answers

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 can use $.bootstrapTooltip to call Bootstrap tooltip (if you ever want to use it). You can use $.tooltip for something else.

jQuery noConflict does not solve this problem because it only shares the different versions of jQuery. The tooltip function is not part of jQuery source code, so it makes no sense to use jQuery noConflict if you do not want to load 2 different versions of jQuery and use 2 different jQuery objects "$" and "$$", for example. This will certainly cause a lot of problems later, because the developer will have spaghetti code.

+1
source

you can use $.widget.bridge like this

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

or do it

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

check more here

0
source

Source: https://habr.com/ru/post/975919/


All Articles