ios-checkboxes icon indicating copy to clipboard operation
ios-checkboxes copied to clipboard

Don't require jQuery

Open coryschires opened this issue 12 years ago • 2 comments

I understand it's built on jQuery and so it has a jQuery dependency. In case there's any confusion, I'm not advocating changing that.

Instead, I'm suggesting that ios-checkboxes should not explicitly require jQuery in the manifest file (i.e. lib/assets/javascripts/ios-checkboxes.js.coffee). In all likelihood, anyone using this gem will already have required jQuery elsewhere in their project, and so re-requiring it is at best unnecessary and at worst can cause problems. In my case, it was causing name collision issues.

I just removed that one line and all the tests seemed to pass just fine.

Thanks for this gem!

coryschires avatar Oct 15 '12 22:10 coryschires

If the query is already require it won't matter, if jquery is required as a separate resource (CDN), then sprockets has stub processor just for that.

What kind of naming collisions was it causing for you?

dnagir avatar Oct 15 '12 23:10 dnagir

Ah. I didn't know sprockets was so smart!

A little back story: I've been using iso-checkboxes without incident for some time and loading the various jquery libraries thru the jquery-rails gem. Due to a totally different concern, I decided to move away from the jquery-rails gem and instead pull those libraries from static files. After making that change, $.ui started returning undefined. After some investigation, I discovered that ios-checkboxes was the culprit. Removing that require jquery line form your gem fixed the issue.

Incidentally, I've since made some improvements which has allowed me to bring back the jquery-rails (using static files was sort of a hack). So I bet I could now stop using my fork. So to recap, my problem was based on (1) a hack and (2) ignorance about how sprockets requires files. And in all likelihood, it's now a moot issue.

All that said, I still think requiring jquery is unnecessary and a little unconventional. I suppose it could save someone one line of code if they had not already included jquery in their manifest. But it seems like everyone has jquery nowadays. And if (for whatever reason) you're not requiring jquery through the jquery-rails gem, it seems to cause problems.

Thanks again for this gem! Cory

On Monday, October 15, 2012 at 6:21 PM, Dmytrii Nagirniak wrote:

If the query is already require it won't matter, if jquery is required as a separate resource (CDN), then sprockets has stub processor just for that. What kind of naming collisions was it causing for you?

— Reply to this email directly or view it on GitHub (https://github.com/dnagir/ios-checkboxes/pull/10#issuecomment-9465843).

coryschires avatar Oct 16 '12 00:10 coryschires