Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Support options.separator and external jQuery #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

qraynaud
Copy link

  • if select2.options.separator is used, then act accordingly
  • if angular is loaded with jQlite (probably because jQuery was loaded after angular), keep things working

- if select2.options.separator is used, then act accordingly
- if angular is loaded with jQlite (ptobably because jQuery
  was loaded after angular), keep things working
@GFoley83
Copy link

Closed #156 as this merge provides a better fix.

@ProLoser
Copy link
Member

ProLoser commented Aug 1, 2014

@qraynaud you shouldn't be loading jquery in the wrong order to begin with

@qraynaud
Copy link
Author

qraynaud commented Aug 3, 2014

@ProLoser: there are multiple reasons to do so
1/ On my project loading jQuery before angular breaks other plugins because jQlite is not 100% compatible with all versions of jQuery (above all being event objects that might be very different in some instances)
2/ On my project, replacing jQlite by jQuery is forbidden

I believe others might have issues related to this.

If I do rebase this, is it likely it will be accepted?

I remind you that the changes that I had to make to allow jQuery to be loaded after angular are VERY small.

@ProLoser
Copy link
Member

ProLoser commented Aug 3, 2014

Loading jquery first causes AngularJS to use jquery instead of jqlite. Your
entire theory defeats the purpose of loading jquery at all.
On Aug 3, 2014 10:28 AM, "Quentin Raynaud" [email protected] wrote:

@ProLoser https://github.com/ProLoser: there are multiple reasons to do
so
1/ On my project loading jQuery before angular breaks other plugins
because jQlite is not 100% compatible with all versions of jQuery (above
all being event objects that might be very different in some instances)
2/ On my project, replacing jQlite by jQuery is forbidden

I believe others might have issues related to this.

If I do rebase this, is it likely it will be accepted?

I remind you that the changes that I had to make to allow jQuery to be
loaded after angular are VERY small.


Reply to this email directly or view it on GitHub
#213 (comment).

@qraynaud
Copy link
Author

qraynaud commented Aug 3, 2014

@ProLoser: I'm probably stupid but I don't understand why.

Where are the cons of preventing angular from using jQuery but letting directives do so in a controlled and limited way? Why make angular use jQuery a required thing and not an optional thing if it's possible?

What I do know at least is that replacing jqlite by jquery in angular breaks some of the angular directives I'm using.

@ProLoser
Copy link
Member

ProLoser commented Aug 3, 2014

That should not happen unless you or they are doing something wrong
considering jquery is a superset of jqlite.
On Aug 3, 2014 12:23 PM, "Quentin Raynaud" [email protected] wrote:

@ProLoser https://github.com/ProLoser: I'm probably stupid but I don't
understand why.

Where are the cons of preventing angular from using jQuery but letting
directives do so in a controlled and limited way? Why make angular use
jQuery a required thing and not an optional thing if it's possible?

What I do know at least is that replacing jqlite by jquery in angular
breaks some of the angular directives I'm using.


Reply to this email directly or view it on GitHub
#213 (comment).

@qraynaud
Copy link
Author

qraynaud commented Aug 3, 2014

As I just said before, this is not true. Because jQuery is replacing the event objects, sometime some properties of the browser's event object are not copied over the the jquery object. jqlite does not do this and expose the browser event object directly. Some of the directives I'm using are requiring some attributes that are trimmed by jQuery but not jqlite.

@ProLoser
Copy link
Member

ProLoser commented Aug 3, 2014

Open an issue on the AngularJS lib
On Aug 3, 2014 12:30 PM, "Quentin Raynaud" [email protected] wrote:

As I just said before, this is not true. Because jQuery is replacing the
event objects, sometime some properties of the browser's event object are
not copied over the the jquery object. jqlite does not do this and expose
the browser event object directly. Some of the directives I'm using are
requiring some attributes that are trimmed by jQuery but not jqlite.


Reply to this email directly or view it on GitHub
#213 (comment).

@qraynaud
Copy link
Author

qraynaud commented Aug 3, 2014

@douglasduteil, I believe we need another point of view Douglas. Can you give us yours about this? I believed the angular-ui team spirit was to make ui components as independent from jQuery as possible (and to even remove jquery dependency as much as possible).

I don't understand why making jquery in angular optional would be a bad thing at all. This won't change how it works when jquery is loaded before angular but it will also work when it is loaded after. This seems like a good thing to me. This is allowing devs to have more flexible webapps at no cost.

In my case, it would allow me to load jquery + select2 libs only for admins while trimming all this from my app for normal users that won't ever have access to select2 forms in my app (I can load jquery on demand because I don't have other components requiring jQuery)

@douglasduteil
Copy link
Contributor

Hi @qraynaud

I believed the angular-ui team spirit was to make ui components as independent from jQuery as possible (and to even remove jquery dependency as much as possible).

True for me, however this https://github.com/angular-ui/ui-select2 directive is depending on jQuery. If you're looking for a pure AngularJS version of it (working with or without jQurey) check https://github.com/angular-ui/ui-select


I don't understand why making jquery in angular optional would be a bad thing at all. This won't change how it works when jquery is loaded before angular but it will also work when it is loaded after. This seems like a good thing to me. This is allowing devs to have more flexible webapps at no cost.

I don't have special opinion about that. Just feels like having AngularJS handling the jQuery switch is enough to freely plugin components made with jQuery.


What I do know at least is that replacing jqlite by jquery in angular breaks some of the angular directives I'm using.

I'm more concern about this. I find the problem is those other directives that aren't jQuery compatible... I think you should open a issue to them saying some thing like :

« You Angular support is bad and You Should Feel Bad »

Or you can fix them with PRs. Even more helpful ! 👍

@efolio
Copy link

efolio commented Aug 4, 2014

I'm also interested on the question: is loading jQuery after Angular really a bad thing?

Performance-wise, it seems a very good approach as jqLite is faster than jQuery:

  • the app would entirely use the fastest library between the two: jqLite
  • jQuery would be used explicitly only where it is absolutely necessary, using $(angular.element(my_elt)).

About ui-select2, maybe looking at angular-ui/ui-select would be a good alternative.

In any case, I don't see why this PR would not be merged…

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants