-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pushstate functionality: includes redone routes, difference cache…
…s based on template and layout, and JS to handle pushstate
- Loading branch information
1 parent
2db7466
commit 069f0eb
Showing
14 changed files
with
213 additions
and
103 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,158 @@ | |||
var Site = {}; | |||
(function($) { | |||
|
|||
var hasHistory = function() { | |||
return !!(window.history && history.pushState); | |||
}; | |||
|
|||
Site.Wufoo = { | |||
'base': { | |||
'userName':'meltmedia', | |||
'autoResize':true, | |||
'header':'show', | |||
'ssl':true | |||
}, | |||
'/register' : { | |||
'formHash':'z7x0w7', | |||
'height':'520' | |||
}, | |||
'/register/sponsor' : { | |||
'formHash':'z7x0r3', | |||
'height':'576' | |||
}, | |||
'/register/speaker' : { | |||
'formHash':'z7x1z5', | |||
'height':'746' | |||
}, | |||
'/register/volunteer' : { | |||
'formHash':'z7x0k1', | |||
'height':'703' | |||
} | |||
}; | |||
|
|||
document.write = function() { | |||
Site.currentFormHolder.append($(arguments[0])); | |||
}; | |||
|
|||
$(function() { | |||
var $contentArea = $('#content .section-content'), | |||
$initForm = $contentArea.find('.wufoo-form-holder'), | |||
rootUrl = History.getRootUrl(), | |||
$body = $('body'), | |||
$title = $('title'), | |||
$scrollTo = $('#navigation'), | |||
addForm = function($c, pageUrl) { | |||
var formSpecifics = Site.Wufoo['/'+pageUrl.replace(rootUrl, '')], | |||
$formHolder = $c.find('.wufoo-form-holder'); | |||
|
|||
if (typeof formSpecifics !== 'undefined' && $formHolder.length > 0) { | |||
var formObj = $.extend(Site.Wufoo.base, formSpecifics); | |||
Site.currentForm = new WufooForm(); | |||
Site.currentForm.initialize(formObj); | |||
Site.currentFormHolder = $formHolder; | |||
$formHolder.append("<scr"+"ipt>Site.currentForm.display();</scr"+"ipt>"); | |||
} | |||
}; | |||
|
|||
addForm($contentArea, window.location.href); | |||
|
|||
if (!hasHistory()) { | |||
return; | |||
} | |||
|
|||
$.expr[':'].internal = function(obj, index, meta, stack) { | |||
// Prepare | |||
var $link = $(obj), | |||
url = $link.attr('href') || ''; | |||
|
|||
// It is internal if it begins with the root url or if it has no :, also ignore named anchors | |||
return ((url.substring(0, rootUrl.length) === rootUrl || url.indexOf(':') === -1) && url.charAt(0) !== "#"); | |||
}; | |||
|
|||
// Ajaxify Helper | |||
$.fn.ajaxify = function() { | |||
// Prepare | |||
var $this = $(this); | |||
|
|||
// Ajaxify | |||
$this.find('a:internal').click(function(event) { | |||
// Prepare | |||
var $link = $(this), | |||
url = $link.attr('href'); | |||
|
|||
// Continue as normal for cmd clicks etc | |||
if (event.which == 2 || event.metaKey) { | |||
return true; | |||
} | |||
|
|||
// Ajaxify this link | |||
History.pushState(null, null, url); | |||
event.preventDefault(); | |||
return false; | |||
}); | |||
|
|||
// Chain | |||
return $this; | |||
}; | |||
|
|||
$body.ajaxify(); | |||
|
|||
$(window).bind('statechange', function() { | |||
|
|||
var State = History.getState(), | |||
url = State.url, | |||
relativeUrl = '/' + url.replace(rootUrl, ''), | |||
successFn = function(data) { | |||
var $data = $(data), | |||
$content = $data.filter('section.section-content').ajaxify(), | |||
title = "NotConf - " + $content.data('title'); | |||
|
|||
// Append any wufoo scripts back into their rightful parent | |||
addForm($content, url); | |||
|
|||
$contentArea.fadeOut(400, function() { | |||
$(this).replaceWith($content).fadeIn(400); | |||
$contentArea = $content; | |||
}); | |||
|
|||
$title.text(title); | |||
_gaq.push(['_trackPageview', relativeUrl]); | |||
|
|||
var currentTopPx = $body.scrollTop(), | |||
scrollTopPx = $scrollTo.offset().top, | |||
distance = (currentTopPx > scrollTopPx) ? currentTopPx - scrollTopPx : 0; | |||
|
|||
if (distance > $scrollTo.outerHeight()) { | |||
$('html, body').animate({ | |||
scrollTop: scrollTopPx | |||
}, distance * 2); | |||
} | |||
}, | |||
errorFn = function(jqXHR, textStatus, errorThrown) { | |||
document.location.href = url; | |||
return false; | |||
}; | |||
|
|||
$.ajax({ | |||
url: '/_' + relativeUrl, | |||
dataType: 'html', | |||
success: successFn, | |||
error: function(jqXHR, textStatus, errorThrown) { | |||
if (jqXHR.status === 404) { | |||
$.ajax({ | |||
url: '/_/404', | |||
dataType: 'html', | |||
success: successFn, | |||
error: errorFn | |||
}); | |||
} else { | |||
document.location.href = url; | |||
} | |||
} | |||
}); | |||
|
|||
return false; | |||
}); | |||
|
|||
}); | |||
})(jQuery); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.