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

Errors after ajax page load #19

Open
chrise86 opened this issue Jun 10, 2013 · 3 comments
Open

Errors after ajax page load #19

chrise86 opened this issue Jun 10, 2013 · 3 comments

Comments

@chrise86
Copy link

When using this with Rails with turbolinks (standard in Rails 4) you get an endless loop of:

Uncaught TypeError: Cannot read property 'offsetWidth' of null

@microspino
Copy link

same for me: RoR 4.0.3 on Chrome 34.0.1847.131

@licatajustin
Copy link

+1. Any fixes yet?

@jameshibbard
Copy link

jameshibbard commented Feb 28, 2017

This is caused by the fact that turbolinks is replacing the body contents, but not reloading the widearea plugin. Consequently the call to setInterval persists across page views, causing the error you describe when the user navigates away from a page containing one or more elements with a data-widearea="enable" attribute, to a page containing none.

Disabling turbolinks solves the problem, although this is not a great solution.

Another workaround is as follows. Change this line:

this._timer = window.setInterval(function() {

to:

_wideAreaTimer = window.setInterval(function() {

This makes the reference to the timer global. It can then be cancelled in the plugins constructor function, before re-initializing it (or not).

function WideArea(obj) {
  if(window._wideAreaTimer) clearInterval(window._wideAreaTimer);

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

No branches or pull requests

4 participants