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
Foundation.js 5 MUST be included in BODY tag. #3643
Foundation.js 5 MUST be included in BODY tag. #3643
Conversation
I use Foundation in a require.js context. I attempted to upgrade from 4, and I'm seeing some very odd behavior that I'm fairly certain is related to this issue. (Require.js appends all scripts to the HEAD asynchronously, thus the issue.) |
I've confirmed this bug. I'd recommend avoiding Foundation 5 with Rails until this issue is resolved. This bug means Foundation 5 is fundamentally incompatible with Rails 4.0. Since Rails 3.2, accepted best practice is to use the Rails asset pipeline, which means incorporating all JavaScript in the application.js file and referencing a single application.js file in the page HEAD section. I didn't encounter any problem with this practice with Foundation 4. Here are the relevant files from a simple Rails application to reproduce the issue.
The failure can be observed by clicking on the menu icon. Nothing happens (a dropdown menu should appear). The JavaScript console shows many errors:
|
Foundation now initializes immediately from wherever you load the file (i.e. it's not wrapped in some Two fixes for now:
|
I tried wrapping
I get errors in the JavaScript console:
Have you tried it with success? |
You actually have to wrap _all of the Foundation code_ in a closure for that method to work. (Ridiculous, I know.) It's more reasonable to remove the FastClick code and load it later if you wish. The rest of Foundation doesn't depend on it at all, so nothing else should break. In my experience everything has been working just fine without it, and no other part of the JS requires being placed at the end of the body. This really needs to be fixed at the framework level. Who knows why Zurb decided to shove a minified, third-party library in a production release of Foundation... 😑 |
I'm using the gem 'foundation-rails'. So as far as I know, there's no possible way to remove the FastClick code. Is there? I'm instructing beginners to use Foundation in a book I've written for Rails newcomers (here: http://learn-rails.com/learn-ruby-on-rails.html). So these workarounds are not realistic. Either it gets fixed or I rewrite the book to recommend another front-end framework that is compatible with Rails recommended practices. |
Hey all, the attached pull request will ensure that FastClick doesn't attempt to initialize until document ready which will resolve the issue with document.body not being available. @DanielKehoe, this pull request or a similar fix will land shortly, so don't be too concerned with this defect in a brand new release. Fixes are coming in quickly... |
I'm happy to see the rapid iteration and the commitment to Rails users. That's why I've recommended the framework. |
Many thanks for the rapid update. 😄 |
Merged! |
…load Foundation.js 5 MUST be included in BODY tag.
The gem on Rubygems is still not updated with this change. And I agree with @fny that including a minified version of a third party library within your own library is questionable. |
Especially when the third party library isn't a real dependency... I've submitted a pull request (#3706) that handles FastClick more wisely. |
still not working however, waiting for foundation/foundation-sites#3643 to land in zurb gem
Please release a new gem version with this change soon, I'm also experiencing this issue. |
When is this going to get updated? Still can't use requireJs without hacking the foundation.min.js file because of this FastClick issue. |
Apparently whenever they decide to release 5.0.3... On Sun, Jan 5, 2014 at 5:01 PM, avisra notifications@github.com wrote:
|
Waiting on this as well :-/ |
Some transparency from Zurb would be welcome. If there's a reason 5.0.3 can't be released, let us know. |
I'm waiting on this too, it's quite an annoying issue for new projects that are using Foundation 5 and Rails 4. |
Mark from Zurb has just told me to expect the update to 5.0.3 next week. They've been extremely busy. |
I'm expecting the fix as well! ;) |
This issue should be reopened. It seems the problem was fixed in foundation-rails 5.0.3 and broke again in foundation-rails 5.1. See #4456 |
+1 ^ |
+1^ |
+1^ Foundations' javascript isn't behaving well with Rails 4 at all, despite the fact that I've disabled Turbolinks. |
Maybe the Zurb team is not aware of this issue? I've opened a new issue: |
+1 - Dropdown not working. |
+1 Dropdown not working |
+1 |
1 similar comment
+1 |
+1 reveal modals acting a bit funky on rails 4.1 |
+1 |
+1 Topbar Dropdown not working. |
+1, it seems that with turbolinks or not, I can't put my JS in HEAD. |
The gem foundation-rails version 5.2.0.0 (released March 6, 2014) resolves the issue. |
Sweet! Sorry it took us so long to get this resolved for you guys. |
@mrsweaters thanks... have you got a process in place to test this before release, for the future? Would be nice to know we don't have to worry about regression. |
I am using rails 4.0.3 and foundation-rails 5.2.0.0, but still not getting dropdowns to work. Is this a confirmed fix? |
I too updated foundation to 5.2 in my Gemfile as well as the bower.json and dropdown menu in the topbar is still not working for me. Any advice? |
I've got an example app anyone can try: https://github.com/RailsApps/rails-foundation It worked for me but comment here if you encounter problems. |
Found a dropdown fix in a different thread. If you are using haml, add the data-topbar attribute to your top-bar like this: %nav.top-bar{'data-topbar' => ''} |
@DanielKehoe's demo app solved my problem and it's now working with Turbolinks, but I had to do this to initialize foundation in application.coffee: ready = -> $(document).ready(ready) |
Anyone else having trouble with the off-canvas menu links not activating turbolinks with foundation-rails 5.2.0.0? Any links outside the off-canvas will activate turbolinks. Those in the off-canvas menu are ignored. Reverting back to foundation-rails 5.1.1.0 fixes the issue. |
Yeah I notice that on iPhone turbolinks doesn't seem to work for any of the off canvas links - the whole page gets reloaded. |
I am having issues with the orbit slider not working with Foundation 5.2.1.0 and Rails 4.0.4 Page reloads and then slider breaks -tried jquery-turbolinks but the problem is not fixed. I am wondering if I should just move to Foundation 4 instead? |
Foundation 4 works fine -guess I will avoid 5 for some time. |
I updated to 5.2.2, the issue is still there. so I used @Matt888 method to fix it. |
@ryankc33 I believe that setup will result in the turbolinks library not being included. See the note here:
Which means that it was turbolinks that was causing you problems. And I see why! 😊 Turbolinks MUST be included in the
|
@ryankc33 sorry, I've never used jQuery.turbolinks. I quickly spotted your previous error and figured I'd chip in. (I'm wondering how related this bug was to your current problem. Maybe StackOverflow or a new bug report in which you help track down the cause would be a better use of your energies?) |
@chadoh you're right! It's a bug in my code, and unrelated to foundation and turbolinks. Will delete my other posts. |
This is a bug IMHO. Worked in 4 in HEAD, why not 5?