Ruby on rails 带有TurboLink的Rails 4,嵌入式GIST不起作用
当试图嵌入一个要点,然后通过turbolinks访问一个页面时,它只是空的,没有显示任何内容 当以完全重新加载的方式访问同一页面时,它会工作Ruby on rails 带有TurboLink的Rails 4,嵌入式GIST不起作用,ruby-on-rails,github,pjax,gist,turbolinks,Ruby On Rails,Github,Pjax,Gist,Turbolinks,当试图嵌入一个要点,然后通过turbolinks访问一个页面时,它只是空的,没有显示任何内容 当以完全重新加载的方式访问同一页面时,它会工作 关于如何实现这一点有什么想法吗?来自TurboLink的文档: TurboLink将评估其访问的页面中的任何脚本标记(如果有) 标记没有类型,或者类型是text/javascript。所有其他 脚本标记将被忽略 因此,通过将放入返回的html中,TurboLink会尝试对其进行评估,而不仅仅是显示其内容。 尝试将其嵌入另一个链接(https://gist.
关于如何实现这一点有什么想法吗?来自TurboLink的文档: TurboLink将评估其访问的页面中的任何脚本标记(如果有) 标记没有类型,或者类型是text/javascript。所有其他 脚本标记将被忽略 因此,通过将
放入返回的html中,TurboLink会尝试对其进行评估,而不仅仅是显示其内容。
尝试将其嵌入另一个链接(
https://gist.github.com/xxx/yyyyy
)来自TurboLink的文档:
TurboLink将评估其访问的页面中的任何脚本标记(如果有)
标记没有类型,或者类型是text/javascript。所有其他
脚本标记将被忽略
因此,通过将
放入返回的html中,TurboLink会尝试对其进行评估,而不仅仅是显示其内容。
尝试将其嵌入另一个链接(
https://gist.github.com/xxx/yyyyy
)创建一个新文件,例如gist.js.coffee
并在其中添加以下coffee脚本
$ ->
loadGists()
$(document).on 'page:load', loadGists
loadGists = ->
$('.gist').each ->
loadGist $(this)
loadGist = ($gist) ->
callbackName = 'c' + Math.random().toString(36).substring(7)
window[callbackName] = (gistData) ->
delete window[callbackName]
html = '<link rel="stylesheet" href="' + encodeURI(gistData.stylesheet) + '"></link>'
html += gistData.div
$gist.html html
script.parentNode.removeChild script
script = document.createElement 'script'
script.setAttribute 'src', [
$gist.data('src'),
$.param(
callback: callbackName
file: $gist.data('file') || ''
)
].join '?'
document.body.appendChild script
$->
装载员()
$(文档)。在“页面:加载”上,加载注册表
loadGists=->
$('.gist')。每个->
loadGist$(此)
loadGist=($gist)->
callbackName='c'+Math.random().toString(36).子字符串(7)
窗口[callbackName]=(gistData)->
删除窗口[callbackName]
html=“”
html+=gistData.div
$gist.html
script.parentNode.removeChild脚本
script=document.createElement“script”
script.setAttribute“src”[
$gist.data('src'),
$.param(
回调:callbackName
文件:$gist.data('file')||“”
)
].加入“?”
document.body.appendChild脚本
接下来,将所有gist脚本标记更改为div,其中包含gist类以及URL和文件名的数据属性。另外,使用.json扩展名而不是.js
<!-- before -->
<script src="https://gist.github.com/username/gist_id.js"></script>
<script src="https://gist.github.com/username/gist_id.js?file=file_name"></script>
<!-- after -->
<div class="gist" data-src="https://gist.github.com/username/gist_id.json"></div>
<div class="gist" data-src="https://gist.github.com/username/gist_id.json" data-file="file_name"></div>
这应该能解决你的问题。查看我写的完整教程创建一个新文件,例如
gist.js.coffee
,并在其中添加以下咖啡脚本
$ ->
loadGists()
$(document).on 'page:load', loadGists
loadGists = ->
$('.gist').each ->
loadGist $(this)
loadGist = ($gist) ->
callbackName = 'c' + Math.random().toString(36).substring(7)
window[callbackName] = (gistData) ->
delete window[callbackName]
html = '<link rel="stylesheet" href="' + encodeURI(gistData.stylesheet) + '"></link>'
html += gistData.div
$gist.html html
script.parentNode.removeChild script
script = document.createElement 'script'
script.setAttribute 'src', [
$gist.data('src'),
$.param(
callback: callbackName
file: $gist.data('file') || ''
)
].join '?'
document.body.appendChild script
$->
装载员()
$(文档)。在“页面:加载”上,加载注册表
loadGists=->
$('.gist')。每个->
loadGist$(此)
loadGist=($gist)->
callbackName='c'+Math.random().toString(36).子字符串(7)
窗口[callbackName]=(gistData)->
删除窗口[callbackName]
html=“”
html+=gistData.div
$gist.html
script.parentNode.removeChild脚本
script=document.createElement“script”
script.setAttribute“src”[
$gist.data('src'),
$.param(
回调:callbackName
文件:$gist.data('file')||“”
)
].加入“?”
document.body.appendChild脚本
接下来,将所有gist脚本标记更改为div,其中包含gist类以及URL和文件名的数据属性。另外,使用.json扩展名而不是.js
<!-- before -->
<script src="https://gist.github.com/username/gist_id.js"></script>
<script src="https://gist.github.com/username/gist_id.js?file=file_name"></script>
<!-- after -->
<div class="gist" data-src="https://gist.github.com/username/gist_id.json"></div>
<div class="gist" data-src="https://gist.github.com/username/gist_id.json" data-file="file_name"></div>
这应该能解决你的问题。看到我写的关于的完整教程了吗?介意显示一些代码吗?实际上没有代码可显示。这只是一个指向要点的脚本。该url由github在“嵌入要点”快捷方式中提供。我还尝试手动提供数据标记,以便在脚本中启用TurboLink,但我非常确定,只有当脚本标记位于文档的头部时,数据标记才会起作用。例如,我只是在我的文章中放了这个url(当然用实际值替换foobar和123):gist.github.com/foobar/123.js“>然后它无法加载摘要,因为它没有显示在页面上,并且控制台中没有警告或错误。介意显示一些代码吗?确实没有代码可显示。这只是一个指向要点的脚本。该url由github在“嵌入要点”快捷方式中提供。我还尝试手动提供数据标记,以便在脚本中启用TurboLink,但我非常确定,只有当脚本标记位于文档的头部时,数据标记才会起作用。例如,我只是在我的文章中放了这个url(当然用实际值替换foobar和123):gist.github.com/foobar/123.js“>然后它无法加载摘要,因为它没有显示在页面上,并且控制台中没有警告或错误。将其嵌入其他链接是什么意思?不带脚本标签的url不只是作为标准html链接链接到要点吗?你把它嵌入另一个链接是什么意思?不带脚本标记的url不只是作为标准html链接链接到要点吗?