2
Google 번역 위젯은 처음에는 잘로드되지만 새 페이지로 이동하면 Turbolinks가 본문을 제거하고 바꿉니다. 이로 인해 위젯이 사라집니다.Rails Turbolinks에서 Google Translate Javascript 위젯을 어떻게 사용합니까?
%head
/Google Translate
:javascript
function googleTranslateElementInit() { // also called from application.coffee
new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'ar,en,es,fr,zh-CN', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}
%script{type: "text/javascript", src: "//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"}
나는 페이지로드
$(document).on 'turbolinks:load', ->
googleTranslateElementInit()
에 함수를 호출하려고하지만 내가 영구적 인 요소를 표시하기 위해 노력
Uncaught TypeError: Cannot read property 'InlineLayout' of undefined
at googleTranslateElementInit (VM145012 dashboard:101)
at HTMLDocument.<anonymous> (application.self-fc93480f6ec8a603a6b9a1d0d9d34ab41a68ef8e4e2a52c661eb84e2b92c170c.js?body=1:7)
at HTMLDocument.dispatch (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:5227)
at HTMLDocument.elemData.handle (jquery.self-bd7ddd393353a8d2480a622e80342adf488fb6006d667e8b42e4c0073393abee.js?body=1:4879)
at Object.t.dispatch (turbolinks.self-c5acd7a204f5f25ce7a1d8a0e4d92e28d34c9e2df2c7371cd7af88e147e4ad82.js?body=1:6)
at r.t.Controller.r.notifyApplicationAfterPageLoad (turbolinks.self-c5acd7a204f5f25ce7a1d8a0e4d92e28d34c9e2df2c7371cd7af88e147e4ad82.js?body=1:6)
at r.t.Controller.r.pageLoaded (turbolinks.self-c5acd7a204f5f25ce7a1d8a0e4d92e28d34c9e2df2c7371cd7af88e147e4ad82.js?body=1:6)
at turbolinks.self-c5acd7a204f5f25ce7a1d8a0e4d92e28d34c9e2df2c7371cd7af88e147e4ad82.js?body=1:6
브라우저 콘솔에서 예외가 발생
https://github.com/turbolinks/turbolinks#persisting-elements-across-page-loads
%body
...
#google_translate_element{'data-turbolinks-permanent'=>true}
하지만 새로운 페이지로 이동과
element_main.js:419 Uncaught TypeError: Cannot read property 'focus' of null
at ou.u.Ke (element_main.js:419)
at Lh (element_main.js:78)
at HTMLDivElement.Gh (element_main.js:80)
at HTMLDivElement.<anonymous> (element_main.js:76)