Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for map links #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions ajaxify-html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// v1.0.1 - 30 September, 2012
// https://github.com/browserstate/ajaxify
(function(window,undefined){

// Prepare our Variables
var
History = window.History,
Expand Down Expand Up @@ -35,27 +35,27 @@
duration: 800,
easing:'swing'
};

// Ensure Content
if ( $content.length === 0 ) {
$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 || url.indexOf(':') === -1;

// Ignore or Keep
return isInternalLink;
};

// HTML Helper
var documentHtml = function(html){
// Prepare
Expand All @@ -64,40 +64,40 @@
.replace(/<(html|head|body|title|meta|script)([\s\>])/gi,'<div class="document-$1"$2')
.replace(/<\/(html|head|body|title|meta|script)\>/gi,'</div>')
;

// Return
return $.trim(result);
};

// Ajaxify Helper
$.fn.ajaxify = function(){
// Prepare
var $this = $(this);

// Ajaxify
$this.find('a:internal:not(.no-ajaxy)').click(function(event){
$this.find('a:internal:not(.no-ajaxy),area:not(.no-ajaxy)').click(function(event){
// Prepare
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; }

// Ajaxify this link
History.pushState(null,title,url);
event.preventDefault();
return false;
});

// Chain
return $this;
};

// Ajaxify our Internal Links
$body.ajaxify();

// Hook into State Changes
$window.bind('statechange',function(){
// Prepare Variables
Expand All @@ -113,7 +113,7 @@
// Animating to opacity to 0 still keeps the element's height intact
// Which prevents that annoying pop bang issue when loading in new content
$content.animate({opacity:0},800);

// Ajax Request the Traditional Page
$.ajax({
url: url,
Expand All @@ -124,7 +124,7 @@
$dataBody = $data.find('.document-body:first'),
$dataContent = $dataBody.find(contentSelector).filter(':first'),
$menuChildren, contentHtml, $scripts;

// Fetch the scripts
$scripts = $dataContent.find('.document-script');
if ( $scripts.length ) {
Expand All @@ -137,7 +137,7 @@
document.location.href = url;
return false;
}

// Update the menu
$menuChildren = $menu.find(menuChildrenSelector);
$menuChildren.filter(activeSelector).removeClass(activeClass);
Expand All @@ -154,7 +154,7 @@
document.getElementsByTagName('title')[0].innerHTML = document.title.replace('<','&lt;').replace('>','&gt;').replace(' & ',' &amp; ');
}
catch ( Exception ) { }

// Add the scripts
$scripts.each(function(){
var $script = $(this), scriptText = $script.text(), scriptNode = document.createElement('script');
Expand All @@ -170,7 +170,7 @@
if ( $body.ScrollTo||false ) { $body.ScrollTo(scrollOptions); } /* http://balupton.com/projects/jquery-scrollto */
$body.removeClass('loading');
$window.trigger(completedEventName);

// Inform Google Analytics of the change
if ( typeof window._gaq !== 'undefined' ) {
window._gaq.push(['_trackPageview', relativeUrl]);
Expand Down