Skip to content

Instantly share code, notes, and snippets.

@exonen
Forked from balupton/README.md
Created January 12, 2012 00:44
Show Gist options
  • Select an option

  • Save exonen/1597745 to your computer and use it in GitHub Desktop.

Select an option

Save exonen/1597745 to your computer and use it in GitHub Desktop.

Revisions

  1. @balupton balupton revised this gist Nov 13, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -153,7 +153,7 @@

    // Add the scripts
    $scripts.each(function(){
    var $script = $(this), scriptText = $script.html(), scriptNode = document.createElement('script');
    var $script = $(this), scriptText = $script.text(), scriptNode = document.createElement('script');
    scriptNode.appendChild(document.createTextNode(scriptText));
    contentNode.appendChild(scriptNode);
    });
  2. @balupton balupton revised this gist Oct 4, 2011. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -11,9 +11,7 @@ This gist will ajaxify your website with the HTML5 History API using History.js
    <script defer src="http://balupton.github.com/jquery-scrollto/scripts/jquery.scrollto.min.js"></script>

    <!-- History.js -->
    <script defer src="http://balupton.github.com/history.js/scripts/compressed/history.adapter.jquery.js"></script>
    <script defer src="http://balupton.github.com/history.js/scripts/compressed/history.js"></script>
    <script defer src="http://gist.github.com/raw/854622/ajaxify-html5.js"></script>
    <script defer src="http://balupton.github.com/history.js/scripts/bundled/html4+html5/jquery.history.js"></script>
    ```

    ## Explanation
    @@ -22,8 +20,7 @@ This gist will ajaxify your website with the HTML5 History API using History.js

    1. Load in jQuery
    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
    1. Load in the jQuery History.js Adapter
    1. Load in [History.js](https://github.com/balupton/history.js)
    1. Load in [History.js](https://github.com/balupton/history.js) with support for jQuery, HTML4 and HTML5
    1. Load in this gist :-)

    ### What does this gist do?
  3. @balupton balupton revised this gist Sep 3, 2011. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -8,11 +8,11 @@ This gist will ajaxify your website with the HTML5 History API using History.js
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

    <!-- jQuery ScrollTo Plugin -->
    <script defer src="http://github.com/balupton/jquery-scrollto/raw/master/scripts/jquery.scrollto.min.js"></script>
    <script defer src="http://balupton.github.com/jquery-scrollto/scripts/jquery.scrollto.min.js"></script>

    <!-- History.js -->
    <script defer src="http://github.com/balupton/history.js/raw/master/scripts/compressed/history.adapter.jquery.js"></script>
    <script defer src="http://github.com/balupton/history.js/raw/master/scripts/compressed/history.js"></script>
    <script defer src="http://balupton.github.com/history.js/scripts/compressed/history.adapter.jquery.js"></script>
    <script defer src="http://balupton.github.com/history.js/scripts/compressed/history.js"></script>
    <script defer src="http://gist.github.com/raw/854622/ajaxify-html5.js"></script>
    ```

  4. @balupton balupton revised this gist Aug 18, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,7 @@ This gist will ajaxify your website with the HTML5 History API using History.js

    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.

    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.
    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.

    1. When a page state change occurs, we will:

  5. @balupton balupton revised this gist Aug 18, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -71,7 +71,7 @@
    var $this = $(this);

    // Ajaxify
    $this.find('a:internal').click(function(event){
    $this.find('a:internal:not(.no-ajaxy)').click(function(event){
    // Prepare
    var
    $this = $(this),
  6. @balupton balupton revised this gist Aug 15, 2011. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,12 @@ This gist will ajaxify your website with the HTML5 History API using History.js
    <!-- jQuery -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

    <!-- jQuery ScrollTo Plugin -->
    <script defer src="http://github.com/balupton/jquery-scrollto/raw/master/scripts/jquery.scrollto.min.js"></script>

    <!-- History.js -->
    <script defer src="http://github.com/balupton/history.js/raw/master/scripts/compressed/history.adapter.jquery.js"></script>
    <script defer src="http://github.com/balupton/history.js/raw/master/scripts/compressed/history.js"></script>
    <script defer src="http://github.com/balupton/jquery-scrollto/raw/master/scripts/jquery.scrollto.min.js"></script>
    <script defer src="http://github.com/balupton/history.js/raw/master/scripts/compressed/history.js"></script>
    <script defer src="http://gist.github.com/raw/854622/ajaxify-html5.js"></script>
    ```

    @@ -19,10 +21,10 @@ This gist will ajaxify your website with the HTML5 History API using History.js
    ### What do the installation instructions do?

    1. Load in jQuery
    2. Load in the jQuery History.js Adapter
    3. Load in [History.js](https://github.com/balupton/history.js)
    4. 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
    5. Load in this gist :-)
    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
    1. Load in the jQuery History.js Adapter
    1. Load in [History.js](https://github.com/balupton/history.js)
    1. Load in this gist :-)

    ### What does this gist do?

  7. @balupton balupton revised this gist Aug 11, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@
    isInternalLink;

    // Check link
    isInternalLink = url.substring(0,rootUrl.length) === rootUrl || (/[^\:]/).test(url);
    isInternalLink = url.substring(0,rootUrl.length) === rootUrl || url.indexOf(':') === -1;

    // Ignore or Keep
    return isInternalLink;
  8. @balupton balupton revised this gist Jul 22, 2011. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -28,17 +28,17 @@ This gist will ajaxify your website with the HTML5 History API using History.js

    1. Check if History.js is enabled for our current browser, if it isn't then skip this gist.

    1. Create a way to detect our pages root url, so we can compare our links against it.
    1. Create a way to detect our page's root url, so we can compare our links against it.

    1. Create a way to convert the ajax repsonses 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.
    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.

    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.

    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.

    1. When a page state change occurs, we will:

    1. Determine the absolute and relative urls from the passed url
    1. Determine the absolute and relative urls from the new url

    1. Use our content selector to find our current page's content and fade it out

  9. @balupton balupton revised this gist Jul 22, 2011. 1 changed file with 41 additions and 2 deletions.
    43 changes: 41 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -14,17 +14,56 @@ This gist will ajaxify your website with the HTML5 History API using History.js
    <script defer src="http://gist.github.com/raw/854622/ajaxify-html5.js"></script>
    ```


    ## Explanation

    This will:
    ### What do the installation instructions do?

    1. Load in jQuery
    2. Load in the jQuery History.js Adapter
    3. Load in [History.js](https://github.com/balupton/history.js)
    4. 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
    5. Load in this gist :-)

    ### What does this gist do?

    1. Check if History.js is enabled for our current browser, if it isn't then skip this gist.

    1. Create a way to detect our pages root url, so we can compare our links against it.

    1. Create a way to convert the ajax repsonses 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.

    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.

    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.

    1. When a page state change occurs, we will:

    1. Determine the absolute and relative urls from the passed url

    1. Use our content selector to find our current page's content and fade it out

    1. Send off an ajax request to the absolute url

    1. Convert the response into one we can undertand

    1. Extract the response's title and set `document.title` and the title element to it

    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

    1. Finish the current content's fadeout animation

    1. Use our menu selector to find the new page's content, and replace the current content with the new page's content

    1. Fade the new content in

    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

    1. Inform Google Analytics and other tracking software about the page change


    ## Using this Gist?

    [Post your website in the showcase here!](https://github.com/balupton/history.js/wiki/Showcase)

    ## Further Reading

  10. @balupton balupton revised this gist Jul 17, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ This will:
    2. Load in the jQuery History.js Adapter
    3. Load in [History.js](https://github.com/balupton/history.js)
    4. 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
    5. Load in our Ajaxify gist :-)
    5. Load in this gist :-)


    ## Further Reading
  11. @balupton balupton revised this gist Jul 17, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -29,5 +29,5 @@ This will:
    ## Further Reading

    - [The History.js Readme: Your guide to History.js](https://github.com/balupton/history.js)
    - [Intelligent State Handling: The evolution from hashes, to hashbangs to the HTML5 History API]
    - [Intelligent State Handling: The evolution from hashes, to hashbangs to the HTML5 History API](https://github.com/balupton/history.js/wiki/Intelligent-State-Handling)
    - [The state of the HTML5 History API, why it isn't good enough and why we need History.js](https://github.com/balupton/history.js/wiki/The-State-of-the-HTML5-History-API)
  12. @balupton balupton revised this gist Jul 17, 2011. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -23,4 +23,11 @@ This will:
    2. Load in the jQuery History.js Adapter
    3. Load in [History.js](https://github.com/balupton/history.js)
    4. 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
    5. Load in our Ajaxify gist :-)
    5. Load in our Ajaxify gist :-)


    ## Further Reading

    - [The History.js Readme: Your guide to History.js](https://github.com/balupton/history.js)
    - [Intelligent State Handling: The evolution from hashes, to hashbangs to the HTML5 History API]
    - [The state of the HTML5 History API, why it isn't good enough and why we need History.js](https://github.com/balupton/history.js/wiki/The-State-of-the-HTML5-History-API)
  13. @balupton balupton revised this gist Jul 17, 2011. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    ## Welcome

    This gist will ajaxify your website with the HTML5 History API using History.js and ScrollTo.


  14. @balupton balupton revised this gist Jul 17, 2011. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    # Ajaxify your Website with the HTML5 History API and History.js
    ## Welcome

    This gist will ajaxify your website with the HTML5 History API using History.js and ScrollTo.


    ## Installation

    @@ -13,6 +16,7 @@
    <script defer src="http://gist.github.com/raw/854622/ajaxify-html5.js"></script>
    ```


    ## Explanation

    This will:
  15. @balupton balupton revised this gist Jul 17, 2011. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    Stick the following into your website:
    # Ajaxify your Website with the HTML5 History API and History.js

    ## Installation

    ``` html
    <!-- jQuery -->
    @@ -11,10 +13,12 @@ Stick the following into your website:
    <script defer src="http://gist.github.com/raw/854622/ajaxify-html5.js"></script>
    ```

    ## Explanation

    This will:

    1. Load in jQuery
    2. Load in the jQuery History.js Adapter
    3. Load in History.js
    4. Load in the jQuery ScrollTo Plugin allowing our ajaxify gist to scroll nicely and smoothly to the new loaded in content
    3. Load in [History.js](https://github.com/balupton/history.js)
    4. 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
    5. Load in our Ajaxify gist :-)
  16. @balupton balupton revised this gist Jul 17, 2011. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    Stick the following into your website:

    ``` html
    <!-- jQuery -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

    <!-- History.js -->
    <script defer src="http://github.com/balupton/history.js/raw/master/scripts/compressed/history.adapter.jquery.js"></script>
    <script defer src="http://github.com/balupton/history.js/raw/master/scripts/compressed/history.js"></script>
    <script defer src="http://github.com/balupton/jquery-scrollto/raw/master/scripts/jquery.scrollto.min.js"></script>
    <script defer src="http://gist.github.com/raw/854622/ajaxify-html5.js"></script>
    ```

    This will:

    1. Load in jQuery
    2. Load in the jQuery History.js Adapter
    3. Load in History.js
    4. Load in the jQuery ScrollTo Plugin allowing our ajaxify gist to scroll nicely and smoothly to the new loaded in content
    5. Load in our Ajaxify gist :-)
  17. @balupton balupton revised this gist Jul 12, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -57,8 +57,8 @@
    // Prepare
    var result = String(html)
    .replace(/<\!DOCTYPE[^>]*>/i, '')
    .replace(/<(html|head|body|title|meta|script)/gi,'<div class="document-$1"')
    .replace(/<\/(html|head|body|title|meta|script)/gi,'</div')
    .replace(/<(html|head|body|title|meta|script)([\s\>])/gi,'<div class="document-$1"$2')
    .replace(/<\/(html|head|body|title|meta|script)\>/gi,'</div>')
    ;

    // Return
  18. @balupton balupton revised this gist Jul 7, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -145,11 +145,11 @@
    $content.html(contentHtml).ajaxify().css('opacity',100).show(); /* you could fade in here if you'd like */

    // Update the title
    document.title = $data.find('.document-title:first').text();
    try {
    document.getElementsByTagName('title')[0].innerHTML = title.replace('<','&lt;').replace('>','&gt;').replace(' & ',' &amp; ');
    document.getElementsByTagName('title')[0].innerHTML = document.title.replace('<','&lt;').replace('>','&gt;').replace(' & ',' &amp; ');
    }
    catch ( Exception ) { }
    document.title = $data.find('.document-title:first').text();

    // Add the scripts
    $scripts.each(function(){
  19. @balupton balupton revised this gist Jul 7, 2011. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -145,6 +145,10 @@
    $content.html(contentHtml).ajaxify().css('opacity',100).show(); /* you could fade in here if you'd like */

    // Update the title
    try {
    document.getElementsByTagName('title')[0].innerHTML = title.replace('<','&lt;').replace('>','&gt;').replace(' & ',' &amp; ');
    }
    catch ( Exception ) { }
    document.title = $data.find('.document-title:first').text();

    // Add the scripts
  20. @balupton balupton revised this gist Jul 7, 2011. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -162,6 +162,12 @@
    if ( typeof window.pageTracker !== 'undefined' ) {
    window.pageTracker._trackPageview(relativeUrl);
    }

    // Inform ReInvigorate of a state change
    if ( typeof window.reinvigorate !== 'undefined' && typeof window.reinvigorate.ajax_track !== 'undefined' ) {
    reinvigorate.ajax_track(url);
    // ^ we use the full url here as that is what reinvigorate supports
    }
    },
    error: function(jqXHR, textStatus, errorThrown){
    document.location.href = url;
  21. @balupton balupton revised this gist Jul 6, 2011. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    // https://gist.github.com/854622
    (function(window,undefined){

    // Prepare our Variables
    @@ -121,7 +122,10 @@
    $menuChildren, contentHtml, $scripts;

    // Fetch the scripts
    $scripts = $dataContent.find('.document-script').detach();
    $scripts = $dataContent.find('.document-script');
    if ( $scripts.length ) {
    $scripts.detach();
    }

    // Fetch the content
    contentHtml = $dataContent.html()||$data.html();
    @@ -139,6 +143,9 @@
    // Update the content
    $content.stop(true,true);
    $content.html(contentHtml).ajaxify().css('opacity',100).show(); /* you could fade in here if you'd like */

    // Update the title
    document.title = $data.find('.document-title:first').text();

    // Add the scripts
    $scripts.each(function(){
  22. @balupton balupton revised this gist May 12, 2011. 1 changed file with 19 additions and 6 deletions.
    25 changes: 19 additions & 6 deletions ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,7 @@
    /* Application Specific Variables */
    contentSelector = '#content,article:first,.article:first,.post:first',
    $content = $(contentSelector).filter(':first'),
    contentNode = $content.get(0),
    $menu = $('#menu,#nav,nav:first,.nav:first').filter(':first'),
    activeClass = 'active selected current youarehere',
    activeSelector = '.active,.selected,.current,.youarehere',
    @@ -55,8 +56,8 @@
    // Prepare
    var result = String(html)
    .replace(/<\!DOCTYPE[^>]*>/i, '')
    .replace(/<(html|head|body|title|meta)/gi,'<div id="document-$1"')
    .replace(/<\/(html|head|body|title|meta)/gi,'</div')
    .replace(/<(html|head|body|title|meta|script)/gi,'<div class="document-$1"')
    .replace(/<\/(html|head|body|title|meta|script)/gi,'</div')
    ;

    // Return
    @@ -114,11 +115,16 @@
    success: function(data, textStatus, jqXHR){
    // Prepare
    var
    $data = $(documentHtml(data)).find('#document-body'),
    $menuChildren, contentHtml;
    $data = $(documentHtml(data)),
    $dataBody = $data.find('.document-body:first'),
    $dataContent = $dataBody.find(contentSelector).filter(':first'),
    $menuChildren, contentHtml, $scripts;

    // Fetch the scripts
    $scripts = $dataContent.find('.document-script').detach();

    // Fetch the content
    contentHtml = $data.find(contentSelector).filter(':first').html()||$data.html();
    contentHtml = $dataContent.html()||$data.html();
    if ( !contentHtml ) {
    document.location.href = url;
    return false;
    @@ -129,11 +135,18 @@
    $menuChildren.filter(activeSelector).removeClass(activeClass);
    $menuChildren = $menuChildren.has('a[href^="'+relativeUrl+'"],a[href^="/'+relativeUrl+'"],a[href^="'+url+'"]');
    if ( $menuChildren.length === 1 ) { $menuChildren.addClass(activeClass); }

    // Update the content
    $content.stop(true,true);
    $content.html(contentHtml).ajaxify().css('opacity',100).show(); /* you could fade in here if you'd like */

    // Add the scripts
    $scripts.each(function(){
    var $script = $(this), scriptText = $script.html(), scriptNode = document.createElement('script');
    scriptNode.appendChild(document.createTextNode(scriptText));
    contentNode.appendChild(scriptNode);
    });

    // Complete the change
    if ( $body.ScrollTo||false ) { $body.ScrollTo(scrollOptions); } /* http://balupton.com/projects/jquery-scrollto */
    $body.removeClass('loading');
  23. @balupton balupton revised this gist May 12, 2011. 1 changed file with 0 additions and 11 deletions.
    11 changes: 0 additions & 11 deletions ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -142,17 +142,6 @@
    if ( typeof window.pageTracker !== 'undefined' ) {
    window.pageTracker._trackPageview(relativeUrl);
    }

    // Inform Disqus of the change
    if ( typeof DISQUS !== 'undefined' ) {
    DISQUS.reset({
    reload: true,
    config: function () {
    this.page.identifier = window.disqus_identifier||undefined;
    this.page.url = window.disqus_url||url;
    }
    });
    }
    },
    error: function(jqXHR, textStatus, errorThrown){
    document.location.href = url;
  24. @balupton balupton revised this gist May 12, 2011. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -142,6 +142,17 @@
    if ( typeof window.pageTracker !== 'undefined' ) {
    window.pageTracker._trackPageview(relativeUrl);
    }

    // Inform Disqus of the change
    if ( typeof DISQUS !== 'undefined' ) {
    DISQUS.reset({
    reload: true,
    config: function () {
    this.page.identifier = window.disqus_identifier||undefined;
    this.page.url = window.disqus_url||url;
    }
    });
    }
    },
    error: function(jqXHR, textStatus, errorThrown){
    document.location.href = url;
  25. @balupton balupton revised this gist May 12, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -135,7 +135,7 @@
    $content.html(contentHtml).ajaxify().css('opacity',100).show(); /* you could fade in here if you'd like */

    // Complete the change
    if ( $content.ScrollTo||false ) { $content.ScrollTo(scrollOptions); } /* http://balupton.com/projects/jquery-scrollto */
    if ( $body.ScrollTo||false ) { $body.ScrollTo(scrollOptions); } /* http://balupton.com/projects/jquery-scrollto */
    $body.removeClass('loading');

    // Inform Google Analytics of the change
  26. @balupton balupton revised this gist Apr 14, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -109,7 +109,8 @@
    $content.animate({opacity:0},800);

    // Ajax Request the Traditional Page
    $.ajax(url,{
    $.ajax({
    url: url,
    success: function(data, textStatus, jqXHR){
    // Prepare
    var
  27. @balupton balupton revised this gist Apr 14, 2011. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -50,6 +50,19 @@
    return isInternalLink;
    };

    // HTML Helper
    var documentHtml = function(html){
    // Prepare
    var result = String(html)
    .replace(/<\!DOCTYPE[^>]*>/i, '')
    .replace(/<(html|head|body|title|meta)/gi,'<div id="document-$1"')
    .replace(/<\/(html|head|body|title|meta)/gi,'</div')
    ;

    // Return
    return result;
    };

    // Ajaxify Helper
    $.fn.ajaxify = function(){
    // Prepare
    @@ -100,7 +113,7 @@
    success: function(data, textStatus, jqXHR){
    // Prepare
    var
    $data = $(data),
    $data = $(documentHtml(data)).find('#document-body'),
    $menuChildren, contentHtml;

    // Fetch the content
  28. @balupton balupton revised this gist Apr 14, 2011. 1 changed file with 28 additions and 16 deletions.
    44 changes: 28 additions & 16 deletions ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -35,12 +35,33 @@
    $content = $body;
    }

    // Internal Helper
    $.expr[':'].internal = function(obj, index, meta, stack){
    // Prepare
    var
    $this = $(obj),
    url = $this.attr('href')||'',
    isInternalLink;

    // Check link
    isInternalLink = url.substring(0,rootUrl.length) === rootUrl || (/[^\:]/).test(url);

    // Ignore or Keep
    return isInternalLink;
    };

    // Ajaxify Helper
    $.fn.ajaxify = function(){
    // Add the onclick handler
    return $(this).click(function(event){
    // Prepare
    var $this = $(this);

    // Ajaxify
    $this.find('a:internal').click(function(event){
    // Prepare
    var $this = $(this), url = $this.attr('href'), title = $this.attr('title')||null;
    var
    $this = $(this),
    url = $this.attr('href'),
    title = $this.attr('title')||null;

    // Continue as normal for cmd clicks etc
    if ( event.which == 2 || event.metaKey ) { return true; }
    @@ -50,22 +71,13 @@
    event.preventDefault();
    return false;
    });

    // Chain
    return $this;
    };

    // Ajaxify our Internal Links
    $body.find('a').filter(function(){
    // Prepare
    var
    $this = $(this),
    url = $this.attr('href')||'',
    isInternalLink;

    // Check link
    isInternalLink = url.substring(0,rootUrl.length) === rootUrl || (/[^\:]/).test(url);

    // Ignore
    return isInternalLink;
    }).ajaxify();
    $body.ajaxify();

    // Hook into State Changes
    $(window).bind('statechange',function(){
  29. @balupton balupton revised this gist Apr 14, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -61,7 +61,7 @@
    isInternalLink;

    // Check link
    isInternalLink = url.substring(0,rootUrl.length) === rootUrl || !(/\:/).test(url);
    isInternalLink = url.substring(0,rootUrl.length) === rootUrl || (/[^\:]/).test(url);

    // Ignore
    return isInternalLink;
  30. @balupton balupton revised this gist Apr 14, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ajaxify-html5.js
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,7 @@
    // Ajaxify Helper
    $.fn.ajaxify = function(){
    // Add the onclick handler
    return $(this).click(function(){
    return $(this).click(function(event){
    // Prepare
    var $this = $(this), url = $this.attr('href'), title = $this.attr('title')||null;