Skip to content

Instantly share code, notes, and snippets.

@berlysia
Created October 23, 2013 14:51
Show Gist options
  • Save berlysia/7120247 to your computer and use it in GitHub Desktop.
Save berlysia/7120247 to your computer and use it in GitHub Desktop.
某プロジェクト用 pushStateしたかっただけ とても雑
(function ($) {
$.fn.setPushState = function (destinationSelector, referenceSelector, appendClass) {
var aC = appendClass || 'ps_active';
var selector = $(this).selector;
this.click(function (e) {
e.preventDefault();
var nextPageUrl = $(this).attr('href');
if (!$(this).hasClass(aC)) {
$('.'+aC).removeClass(aC);
$(this).addClass(aC);
$(destinationSelector).load(nextPageUrl + ' ' + referenceSelector);
window.history.pushState(null,null,nextPageUrl);
}
});
onpopstate = function(e){
var lp = location.pathname;
var filename = lp.substring(lp.lastIndexOf('/')+1,lp.length);
$('.'+aC).removeClass(aC);
$(selector).parent().find('[href*="'+filename+'"]').addClass(aC);
$(destinationSelector).load(lp + ' ' + referenceSelector);
};
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment