Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The no-conflict mode should be the default behaviour #12395

Closed
thewebdreamer opened this issue Jan 26, 2014 · 12 comments
Closed

The no-conflict mode should be the default behaviour #12395

thewebdreamer opened this issue Jan 26, 2014 · 12 comments
Labels

Comments

@thewebdreamer
Copy link

The no-conflict mode should be the default behaviour. Why would a Bootstrap client need to implement this?

@cvrebert
Copy link
Collaborator

I believe no-conflict-is-not-the-default is the norm for jQuery plugins?

@thewebdreamer
Copy link
Author

It is true that it is the norm for jQuery plugins.

Couldn't there be a clash with other jQuery plugins with the current implementation of Bootstrap though?

@hnrch02
Copy link
Collaborator

hnrch02 commented Jan 26, 2014

Couldn't there be a clash with other jQuery plugins with the current implementation of Bootstrap though?

That is precisely what noConflict was made for.

@cvrebert
Copy link
Collaborator

Indeed, we know for a fact that such clashes exist (e.g. with jQuery UI). One could equally ask why jQuery UI isn't no-conflict-by-default.

However, other than providing a working .noConflict, we explicitly don't officially support using 3rd-party libraries; see the warning box under http://getbootstrap.com/javascript/#js-events . Resolving inter-library conflicts is something the user must deal with themselves.

@thewebdreamer
Copy link
Author

My understanding was that jQueryUI is already by default non clashing by using a "ui" prefix in their CSS and by using namespaces in their plugins.

Anyway, it doesn't mean that Bootstrap must do what others are doing. Otherwise, you can close this.

@cvrebert
Copy link
Collaborator

jQuery UI doesn't seem to be using no-conflict in their JS by default; e.g. the example on http://jqueryui.com/tooltip/ simply does

$(function() {
  $( document ).tooltip();
});

un-namespaced, same as Bootstrap.

@hnrch02
Copy link
Collaborator

hnrch02 commented Jan 26, 2014

Well, I suppose you could namespace Bootstrap's JavaScript plugins by assigning them to $.fn.bootstrap.<something> or $.fn.bs.<something> but as this is a de facto non-existent pattern and—as @cvrebert stated—Bootstrap doesn't officially support any third party libraries, I see no reason for Bootstrap to adopt it.

@thewebdreamer
Copy link
Author

@cvrebert: I've downloaded the latest jQueryUI located at http://jqueryui.com/download/all/ to validate this.

What, I've found is that each plugin is within a closure and the non conflicting jQuery variable is passed as a parameter. The $ is only an alias within the context of the closure. You can find a very old bug ticket confirming this: http://bugs.jquery.com/ticket/1686.

From what I see Bootstrap is also doing this, but nothing is namespaced. The difference that I see is that jQueryUI is namespaced and they use a helper function called "widget" to add their plugins. They pass the name of the plugin to "widget" as well as jQueryUI's version, some options and some private functions. For the tooltip, the name is "ui.tooltip".

Little example snippet below taken from the file jquery.ui.tooltip.js:

(function( $ ) {
  /**  Some functions here (redacted for easier reading).  **/
  $.widget( "ui.tooltip", {
    version: "1.10.4",
    options: {
      /**  List of options would be here (redacted for easier reading).  **/
    },
    /**  List of private functions (redacted for easier reading).  **/
  });
}( jQuery ) );

It might also be worth noting that this is the case in their latest development version located here (although there are some changes): https://github.com/jquery/jquery-ui/blob/master/ui/tooltip.js.

@thewebdreamer
Copy link
Author

Nevermind, misread something for a moment there. They do directly inject into $. :(

@cvrebert
Copy link
Collaborator

Also, even if we wanted to do this, we couldn't do it until v4 due to backward-compatibility constraints.

@cvrebert
Copy link
Collaborator

@fat I assume that we're not gonna go this route? If so, then can we close as WontFix?

@fat
Copy link
Member

fat commented Apr 25, 2014

yep wont fix

@fat fat closed this as completed Apr 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants