I'm getting the following JavaScript error in the console on a form page:
Uncaught TypeError: $(...).tooltip is not a function
If I reload the page, then it works fine. If I navigate to the page from elsewhere, then it gives the error. The CoffeeScript which initializes the tooltips is
$(document).on 'turbolinks:load', ->
# copy all placeholders to title
$('[data-toggle="tooltip"]').each ->
$(this).attr 'title', $(this).attr('placeholder')
$('[data-toggle="tooltip"]').tooltip()
I don't include JQuery twice.
= javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
%script{:crossorigin => "anonymous", :src => "https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js", :integrity => "sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"}
%script{:crossorigin => "anonymous", :src => "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js", :integrity => "sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn"}
/ UIkit JS
%script{:src => "https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.30/js/uikit.min.js"}
%script{:src => "https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.30/js/uikit-icons.min.js"}
...
%body
...
= yield
= render 'layouts/footer'
-# PureChat
<script type='text/javascript' data-cfasync='false'>window.purechatApi = { l: [], t: [], on: function () { this.l.push(arguments); } }; (function () { var done = false; var script = document.createElement('script'); script.async = true; script.type = 'text/javascript'; script.src = 'https://app.purechat.com/VisitorWidget/WidgetScript'; document.getElementsByTagName('HEAD').item(0).appendChild(script); script.onreadystatechange = script.onload = function (e) { if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) { var w = new PCWidget({c: 'fffff-ffff-ffff-fffffffff', f: true }); done = true; } }; })();</script>
The Bootstrap docs are here. The Turbolinks docs are here.
I believe the problem may be with Turbolinks or PureChat. For some reason, the .tooltip()
function is not available, even though the call to it is wrapped in the event turbolinks:load
. Also, I cannot reproduce the problem if I exclude PureChat from the bottom of the body. When I do include PureChat, the first error in the console is a .tooltip()
error, but only sometimes, and only when I navigate from one page to another. Sometimes it works. It still always works if I reload the page with the tooltips.
None of the similar questions (link, link, link) mention Turbolinks. I am not using JQueryUI. I am not including JQuery twice.
How do I fix this error?
Rails 5.0.6.