-
Notifications
You must be signed in to change notification settings - Fork 35
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
Rails 4 - Turbolinks - MathJax #16
Comments
Would this work? Remove the script tag add this to your JS: $ ->
$(document).on 'page:load', ->
window.MathJax = null
$.getScript "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" I did a small test and it worked for me. Let me know. |
Hi Reed, |
Sorry, that's my mistake. Try this: $ ->
loadMathJax()
$(document).on 'page:load', loadMathJax
loadMathJax = ->
if page is Math/New or Physics/Show # optional check
window.MathJax = null
$.getScript "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" If you have a way of checking what page you're on, that optional check is ideal since it will reduce the number of times you fetch and load the MathJax library. |
Hi Reed, Now, would you please help me with any of the following 3 questions:
How should I implement this in my .js.coffeescript file now? Thanks again for your help. |
|
Thanks reed, I really appreciate it. If I don't move the |
Ah, I thought your config script tag was in the body. Regardless, this works for me: $ ->
loadMathJax()
$(document).on 'page:load', loadMathJax
loadMathJax = ->
if page is Math/New or Physics/Show # optional check
window.MathJax = null
$.getScript "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML", ->
MathJax.Hub.Config
showMathMenu: false Or, if you feel like going overboard with it, like I apparently did, you can use this: class MathJax
constructor: (@options) ->
@bind()
load: =>
window.MathJax = null
@_fetch().done =>
window.MathJax.Hub.Config @options
bind: ->
$ => @load()
$(document).on 'page:load', @load
unbind: ->
$(document).off 'page:load', @load
# private
_fetch: ->
$.ajax
dataType: 'script'
cache: true
url: "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=AM_HTMLorMML"
# usage
new MathJax
showMathMenu: false This solution takes advantage of jQuery's ajax caching, so you'll only be downloading the script once. |
Wow, Awesome. You really made my day. Thanks a lot. |
Glad I could help. I posted the solution to the site: |
Just a quick update: In Turbolinks 5, you have to use |
for caching behavior, cache must be disabled, by adding |
Hi, I have a Rails4 app which uses MathJax. I use MathJax CDN by placing the following line in the
<head>
section of my app/views/layouts/application.html.erb file:More information on: http://docs.mathjax.org/en/latest/start.html#mathjax-cdn
Because of Turbolinks, MathJax loads only on the homepage and won't load on other pages unless I refresh the page (which is not desirable). Instead I want MathJax to load only on /Math/New and Physics/Show pages. What should I do?
Thanks a lot for your help.
The text was updated successfully, but these errors were encountered: