-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax-navigator.min.js
1 lines (1 loc) · 1.39 KB
/
ajax-navigator.min.js
1
(function($){jQuery.fn.internal_links=function(){var siteURL="http://"+top.location.host.toString();var $internalLinks=$("a[href^='"+siteURL+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']");$internalLinks.each(function(e){if($(this).attr("rel")===undefined&&$(this).attr("download")===undefined){$(this).attr("rel","internal");}});};jQuery.ajax_navigator=function(options,callback){var settings=$.extend({page_container:".content",fadeOut:true,fadeOutDuration:1000,fadeIn:true,fadeInDuration:1000},options);var ajax_content_change=function(url){$.ajax({url:url,success:function(html){var content=$(html).filter(settings.page_container).contents(),title=$(html).filter("title").text();document.title=title;window.history.pushState(null,"",url);if(!settings.fadeOut){settings.fadeOutDuration=0;}if(!settings.fadeIn){settings.fadeInDuration=0;}$(settings.page_container).fadeOut(settings.fadeOutTimer,function(e){$(this).empty().append(content).fadeIn(settings.fadeInTimer,function(e){if(typeof callback=="function"){callback.call(this);}});$(document).internal_links();});}});};$(document).ready(function(){$(this).internal_links();$(document).on("click",'a[rel="internal"]',function(e){e.preventDefault();var url=$(this).attr("href");ajax_content_change(url);});$(window).on("popstate",function(){this._popStateEventCount++;console.log("popstate");ajax_content_change(window.location);});});};})(jQuery);