Skip to content

Instantly share code, notes, and snippets.

@balupton
Last active December 6, 2017 05:38
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save balupton/919358 to your computer and use it in GitHub Desktop.
Save balupton/919358 to your computer and use it in GitHub Desktop.
History.js It! A bookmark for trialing History.js on your own website.

ScreenCast

See it in action here: http://vimeo.com/22396598

Usage

  1. Click the raw link for the bookmark.js file, and copy the contents into your clipboard: ctrl+a, ctrl+c for windows or cmd+a, cmd+c for mac
  2. Right click your browsers bookmark bar and select add new page, for the title use History.js It! for the url press ctrl+v for windows or cmd+v for mac

Notes

It loads in all History.js dependencies and History.js if it needs to, then it loads in the gist https://gist.github.com/854622 - if it doesn't work, evaluate that gist

Todo

  1. Support forms
  2. Support sub-pages
(function(window,undefined){
// Load Helpers
var
intervalScript, intervalJquery,
loadScript = function(scriptUrl){
var e = document.createElement('script');
e.setAttribute('src',scriptUrl);
window.document.body.appendChild(e);
return e;
};
// Load In Basic Dependencies
if ( typeof window.jQuery === 'undefined' || /^1\.[0-3]/.test(window.jQuery.fn.jquery) ) {
loadScript('https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js');
}
// Load In Advanced Dependencies
intervalJquery = setInterval(function(){
if ( typeof window.jQuery !== 'undefined' ) {
clearInterval(intervalJquery);
loadScript('http://balupton.github.com/history.js/scripts/bundled/html4+html5/jquery.history.js');
loadScript('https://raw.github.com/balupton/jquery-scrollto/master/scripts/jquery.scrollto.min.js');
}
},500);
// Load In Script
intervalScript = setInterval(function(){
if ( typeof window.jQuery !== 'undefined' && typeof window.History !== 'undefined' && typeof window.History.initHtml4 !== 'undefined' ) {
if ( window.console ) {
window.console.log('Loading in script');
}
$(loadScript('https://raw.github.com/gist/854622/ajaxify-html5.js')).bind('load',function(){
if ( typeof window.historyjsitNoAlert === 'undefined' ) {
alert('History.js It! Is ready for action!');
}
});
clearInterval(intervalScript);
}
else if ( window.console ) {
window.console.log('Waiting for dependencies to load');
}
},500);
})(window);
javascript:var%20e=document.createElement('script');e.setAttribute('src','https://raw.github.com/gist/919358/bookmark-helper.js');document.body.appendChild(e);void(0);
@chrisjacob
Copy link

Suggest using Github Pages for scripts/resources (not /raw/).

@fidanov
Copy link

fidanov commented Oct 22, 2011

@balupton
Copy link
Author

@fidanov fixed

@guidobouman
Copy link

It breaks the HTML5 boilerplate jQuery fallback:

<script>
window.jQuery || document.write('<script src="/js/jquery.js"><\/script>')
</script>

Example:
http://guidobouman.com/dev/blog/

@balupton
Copy link
Author

balupton commented Jul 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment