Last active
August 9, 2022 08:18
-
-
Save jittarao/09e834d2e8f77046643d3785604cb3ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Place this code in the <body> tag --> | |
<!-- start Gist JS code--> | |
<script> | |
var hasGistScriptLoaded = false; | |
(function(){ | |
var loadEvent = 'turbolinks:load'; | |
var unloadEvent = 'turbolinks:before-visit'; | |
var loadHandler = function() { | |
document.removeEventListener(loadEvent, loadHandler); | |
document.addEventListener(unloadEvent, unloadHandler); | |
setTimeout(function () { | |
if(!hasGistScriptLoaded) { | |
hasGistScriptLoaded = true; | |
// Replace WORKSPACE_ID text with your Workspace ID | |
gist.setAppId("WORKSPACE_ID"); | |
gist.trackPageView(); | |
} | |
}, 500); | |
}; | |
var unloadHandler = function() { | |
document.removeEventListener(unloadEvent, unloadHandler); | |
delete (window.gist); | |
hasGistScriptLoaded = false; | |
}; | |
document.addEventListener(loadEvent, loadHandler); | |
setTimeout(function() { | |
(function(d,h,w){var gist=w.gist=w.gist||[];gist.methods=['trackPageView','identify','track','setAppId'];gist.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);gist.push(e);return gist;}};for(var i=0;i<gist.methods.length;i++){var c=gist.methods[i];gist[c]=gist.factory(c)}s=d.createElement('script'),s.src="https://widget.getgist.com",s.async=!0,e=d.getElementsByTagName(h)[0],e.appendChild(s),s.addEventListener('load',function(e){},!1)})(document,'head',window); | |
}, 1); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jittarao on rails 6 using turbo instead of turbolink, it could be nice to have the possibility to add in body an empty "#gist-app" div in data-turbo-permanent in order to keep the frame loaded throw navigation. Or defining a div parent ?
The main problem i have is that events on document are stacking on each load...
events come from :
_cfCommonFunctions.prototype.gtAddMultipleListenerToDoc(document, ["touchstart", "touchmove", "touchend", "mouseover", "mousemove", "mousedown", "mouseup", "click", "keydown", "keypress", "keyup", "submit", "change", "scroll", "resize", "dblclick"], _cfCommonFunctions.prototype.gtHandlerOfListener, !1),
see in the profiller after 5-6 pages
