├── README.md ├── ajaxify-bookmarklet-helper.js └── ajaxify-html5.js /README.md: -------------------------------------------------------------------------------- 1 | # Ajaxify 2 | Ajaxify your entire website instantly with this simple drop-in script using the HTML5 History API with History.js and jQuery ScrollTo. 3 | 4 | 5 | ## Installation 6 | 7 | ### Direct 8 | 9 | ``` html 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | ``` 22 | 23 | 24 | ### Bookmarklet 25 | 26 | ``` javascript 27 | javascript:var%20e=document.createElement('script');e.setAttribute('src','//rawgithub.com/browserstate/ajaxify/master/ajaxify-bookmarklet-helper.js');document.body.appendChild(e);void(0); 28 | ``` 29 | 30 | ### Extension 31 | 32 | [Install the Ajaxify History.js It! Google Chrome Extension](https://github.com/browserstate/historyjsit.crx) 33 | 34 | 35 | 36 | ## Explanation 37 | 38 | ### What do the installation instructions do? 39 | 40 | 1. Load in jQuery 41 | 1. Load in the [jQuery ScrollTo Plugin](https://github.com/balupton/jquery-scrollto) allowing our ajaxify gist to scroll nicely and smoothly to the new loaded in content 42 | 1. Load in [History.js](https://github.com/browserstate/history.js) with support for jQuery, HTML4 and HTML5 43 | 1. Load in this gist :-) 44 | 45 | ### What does this gist do? 46 | 47 | 1. Check if History.js is enabled for our current browser, if it isn't then skip this gist. 48 | 49 | 1. Create a way to detect our page's root url, so we can compare our links against it. 50 | 51 | 1. Create a way to convert the ajax repsonse into a format jQuery will understand - as jQuery is only made to handle elements which go inside the body element, not elements made for the head element. 52 | 53 | 1. Define our content and menu selectors, these are using when we load in new pages. We use our content selector to find our new content within the response, and replace the existing content on our current page. We use our menu selector to update the active navigation link in our menu when the page changes. 54 | 55 | 1. Discover our internal links on our website, and upgrade them so when they are clicked it instead of changing the page to the new page, it will change our page's state to the new page. Links with the class `no-ajaxy` will not be upgraded. 56 | 57 | 1. When a page state change occurs, we will: 58 | 59 | 1. Determine the absolute and relative urls from the new url 60 | 61 | 1. Use our content selector to find our current page's content and fade it out 62 | 63 | 1. Send off an ajax request to the absolute url 64 | 65 | 1. Convert the response into one we can undertand 66 | 67 | 1. Extract the response's title and set `document.title` and the title element to it 68 | 69 | 1. Use our menu selector to find our page's menu, then scan for new page's url in the menu, and make that the active menu item and mark other menu items inactive 70 | 71 | 1. Finish the current content's fadeout animation 72 | 73 | 1. Use our menu selector to find the new page's content, and replace the current content with the new page's content 74 | 75 | 1. Fade the new content in 76 | 77 | 1. Scroll to the new current content so the user is directed to the right place - rather than them ending up looking at the footer or something instead of your page's content due to the height shift with the content change 78 | 79 | 1. Inform Google Analytics and other tracking software about the page change 80 | 81 | 82 | ## Using this Gist? 83 | 84 | [Post your website in the showcase here!](https://github.com/browserstate/history.js/wiki/Showcase) 85 | 86 | 87 | ## Further Reading 88 | 89 | - [The History.js Readme: Your guide to History.js](https://github.com/browserstate/history.js) 90 | - [Intelligent State Handling: The evolution from hashes, to hashbangs to the HTML5 History API](https://github.com/browserstate/history.js/wiki/Intelligent-State-Handling) 91 | - [The state of the HTML5 History API, why it isn't good enough and why we need History.js](https://github.com/browserstate/history.js/wiki/The-State-of-the-HTML5-History-API) 92 | 93 | 94 | ## History 95 | 96 | - v1.0.1 - 30 September, 2012 97 | - Added completion event (customisable via `completedEventName` defaults to `statechangecomplete`) 98 | - Updated for new Google Analytics code - [credits to](https://gist.github.com/854622#gistcomment-294951) [aspiziri](https://github.com/aspiziri) 99 | 100 | 101 | ## License 102 | 103 | Licensed under the [New BSD License](http://opensource.org/licenses/BSD-3-Clause) 104 | -------------------------------------------------------------------------------- /ajaxify-bookmarklet-helper.js: -------------------------------------------------------------------------------- 1 | (function (window, undefined) { 2 | "use strict"; 3 | 4 | // jQuery 5 | window.jQuery || document.write('