Avoid error calling addEventListener in browsers that don't support it #174

Merged
merged 1 commit into from Sep 6, 2016

Projects

None yet

2 participants

@javan
Member
javan commented Sep 3, 2016

Fix for #173

@javan javan commented on the diff Sep 3, 2016
src/turbolinks/index.coffee
@@ -7,7 +7,9 @@
@Turbolinks =
supported: do ->
- window.history.pushState? and window.requestAnimationFrame?
+ window.history.pushState? and
+ window.requestAnimationFrame? and
+ window.addEventListener?
@javan
javan Sep 3, 2016 Member

Not technically needed to fix the issue, but seems reasonable to add for clarity.

@javan javan commented on the diff Sep 3, 2016
src/turbolinks/history.coffee
# Private
shouldHandlePopState: ->
# Safari dispatches a popstate event after window's load event, ignore it
- pageLoaded is true
+ @pageIsLoaded()
+
+ pageIsLoaded: ->
+ @pageLoaded or document.readyState is "complete"
@javan
javan Sep 3, 2016 Member

Added an additional check for document.readyState to cover the theoretical case where turbolinks is loaded async after the load event.

@nateberkopec
nateberkopec Sep 3, 2016 Contributor

👍 Similar to what JQuery does.

@javan javan merged commit c73e134 into master Sep 6, 2016
@javan javan deleted the fix-ie8-error branch Sep 6, 2016
@jmckible jmckible referenced this pull request Oct 14, 2016
Open

Minor version bump #197

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment