Created
September 28, 2012 22:47
-
-
Save bluestrike2/3802463 to your computer and use it in GitHub Desktop.
turbolinks bookmarklet
This file contains 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
javascript:void((function()%7Bvar%20e=document.createElement('script');e.setAttribute('src','https://raw.github.com/gist/3802463/fa48c9302283a13e83a9f04c19022c66170aa3db/turbolinks.js');document.body.appendChild(e)%7D)()); |
This file contains 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
(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k;y=[];u=null;d=!1;k=function(e){if(t){n();w(e);return c(e)}return document.location.href=e};c=function(e){var t;C("page:fetch");t=new XMLHttpRequest;t.open("GET",e,!0);t.setRequestHeader("Accept","text/html, application/xhtml+xml, application/xml");t.onload=function(){r.apply(null,f(t.responseText));return C("page:load")};t.onabort=function(){return console.log("Aborted turbolink fetch!")};return t.send()};l=function(e){var t;n();if(t=y[e.position]){r(t.title,t.body.cloneNode(!0));b(t);return C("page:restore")}return c(document.location.href)};n=function(){x();y[u.position]={url:document.location.href,body:document.body,title:document.title,positionY:window.pageYOffset,positionX:window.pageXOffset};return i(10)};i=function(e){if(u.position===window.history.length-1)return delete y[u.position-e]};r=function(e,t){document.title=e;document.documentElement.replaceChild(t,document.body);u=window.history.state;return C("page:change")};w=function(e){if(e!==document.location.href)return window.history.pushState({turbolinks:!0,position:u.position+1},"",e)};S=function(){return window.history.replaceState({turbolinks:!0,position:window.history.length-1},"",document.location.href)};E=function(){return u=window.history.state};x=function(){if(!d){S();E();return d=!0}};b=function(e){return window.scrollTo(e.positionX,e.positionY)};C=function(e){var t;t=document.createEvent("Events");t.initEvent(e,!0,!0);return document.dispatchEvent(t)};f=function(e){var t,n;t=s(e);n=t.querySelector("title");return[n!=null?n.textContent:void 0,t.body]};s=function(){var e,t,n,r;e=function(e){return(new DOMParser).parseFromString(e,"text/html")};t=function(e){var t;t=document.implementation.createHTMLDocument("");t.open("replace");t.write(e);t.close;return t};window.DOMParser&&(n=e("<html><body><p>test"));return(n!=null?(r=n.body)!=null?r.childNodes.length:void 0:void 0)===1?e:t}();h=function(e){var t;t=a(e);if(t.nodeName==="A"&&!p(e,t)){k(t.href);return e.preventDefault()}};a=function(e){var t;t=e.target;while(t!==document&&t.nodeName!=="A")t=t.parentNode;return t};N=function(e){return e.href===document.location.href};o=function(e){return location.protocol!==e.protocol||location.host!==e.host};e=function(e){return(e.hash&&e.href.replace(e.hash,""))===location.href.replace(location.hash,"")||e.href===location.href+"#"};g=function(e){return e.href.match(/\.[a-z]+(\?.*)?$/g)&&!e.href.match(/\.html?(\?.*)?$/g)};T=function(e){return e.getAttribute("data-remote")!=null};m=function(e){return e.getAttribute("data-no-turbolink")!=null};v=function(e){return e.which>1||e.metaKey||e.ctrlKey};p=function(t,n){return N(n)||o(n)||e(n)||g(n)||T(n)||m(n)||v(t)};t=window.history&&window.history.pushState&&window.history.replaceState;if(t){window.addEventListener("popstate",function(e){var t;if((t=e.state)!=null?t.turbolinks:void 0)return l(e.state)});document.addEventListener("click",function(e){return h(e)})}this.Turbolinks={visit:k}}).call(this); |
This file contains 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
(function(){var e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k;y=[];u=null;d=!1;k=function(e){if(t){n();w(e);return c(e)}return document.location.href=e};c=function(e){var t;C("page:fetch");t=new XMLHttpRequest;t.open("GET",e,!0);t.setRequestHeader("Accept","text/html, application/xhtml+xml, application/xml");t.onload=function(){r.apply(null,f(t.responseText));return C("page:load")};t.onabort=function(){return console.log("Aborted turbolink fetch!")};return t.send()};l=function(e){var t;n();if(t=y[e.position]){r(t.title,t.body.cloneNode(!0));b(t);return C("page:restore")}return c(document.location.href)};n=function(){x();y[u.position]={url:document.location.href,body:document.body,title:document.title,positionY:window.pageYOffset,positionX:window.pageXOffset};return i(10)};i=function(e){if(u.position===window.history.length-1)return delete y[u.position-e]};r=function(e,t){document.title=e;document.documentElement.replaceChild(t,document.body);u=window.history.state;return C("page:change")};w=function(e){if(e!==document.location.href)return window.history.pushState({turbolinks:!0,position:u.position+1},"",e)};S=function(){return window.history.replaceState({turbolinks:!0,position:window.history.length-1},"",document.location.href)};E=function(){return u=window.history.state};x=function(){if(!d){S();E();return d=!0}};b=function(e){return window.scrollTo(e.positionX,e.positionY)};C=function(e){var t;t=document.createEvent("Events");t.initEvent(e,!0,!0);return document.dispatchEvent(t)};f=function(e){var t,n;t=s(e);n=t.querySelector("title");return[n!=null?n.textContent:void 0,t.body]};s=function(){var e,t,n,r;e=function(e){return(new DOMParser).parseFromString(e,"text/html")};t=function(e){var t;t=document.implementation.createHTMLDocument("");t.open("replace");t.write(e);t.close;return t};window.DOMParser&&(n=e("<html><body><p>test"));return(n!=null?(r=n.body)!=null?r.childNodes.length:void 0:void 0)===1?e:t}();h=function(e){var t;t=a(e);if(t.nodeName==="A"&&!p(e,t)){k(t.href);return e.preventDefault()}};a=function(e){var t;t=e.target;while(t!==document&&t.nodeName!=="A")t=t.parentNode;return t};N=function(e){return e.href===document.location.href};o=function(e){return location.protocol!==e.protocol||location.host!==e.host};e=function(e){return(e.hash&&e.href.replace(e.hash,""))===location.href.replace(location.hash,"")||e.href===location.href+"#"};g=function(e){return e.href.match(/\.[a-z]+(\?.*)?$/g)&&!e.href.match(/\.html?(\?.*)?$/g)};T=function(e){return e.getAttribute("data-remote")!=null};m=function(e){return e.getAttribute("data-no-turbolink")!=null};v=function(e){return e.which>1||e.metaKey||e.ctrlKey};p=function(t,n){return N(n)||o(n)||e(n)||g(n)||T(n)||m(n)||v(t)};t=window.history&&window.history.pushState&&window.history.replaceState;if(t){window.addEventListener("popstate",function(e){var t;if((t=e.state)!=null?t.turbolinks:void 0)return l(e.state)});document.addEventListener("click",function(e){return h(e)})}this.Turbolinks={visit:k}}).call(this); |
Here's an updated version which loads turbolinks.js from CDNJS:
https://gist.github.com/appel/3b388f2498c1009e3f3a65f71b75addd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bookmarklet.js should be: