wordpress ajax代码 【记事本】

//定义所需变量
var ajaxhome= window.location.host; // 填入主页地址
var ajaxcontent = 'wrapper'; // 为Ajax加载部分的id,一般的主题主体都是content
var ajaxsearch_class = 'search-form'; // 搜索表单的class,同样,一般都是类似于searchform这种的
var ajaxignore_string = new String('#, /wp-, .pdf, .zip, .rar, /goto, /feed'); // 不需要Ajax加载的链接格式
var ajaxignore = ajaxignore_string.split(', ');// 字符分割
var ajaxloading_code = '<div id="circle"></div><div id="circle1"></div>';
var ajaxloading_error_code = '<div class="e404"><h1>404 . Not Found</h1><p>沒有找到你要的内容!</p></div>'; // 加载失败动画

var ajaxreloadDocumentReady = true; //重新加载
var ajaxtrack_analytics = false
var ajaxscroll_top = true // 定位返回锚点
var ajaxisLoad = false; // ajax加载开关
var ajaxstarted = false; // ajax开始确认
var ajaxsearchPath = null; // 搜索路径


// 初始化载入
$(document).ready(function() { 
 ajaxloadPageInit(""); 
});
// 函数:搜索提交
function submitSearch(param){
 if (!ajaxisLoad){
 ajaxloadPage(ajaxsearchPath, 0, param);
 }
}
// 函数:过滤链接
function ajaxcheck_ignore(url) {
 for (var i in ajaxignore) {
 if (url.indexOf(ajaxignore[i]) >= 0) {
 return false;
 }
 }
 return true;
}
// 函数:需要重新加载的js,比如灯箱、代码高亮等
function ajaxreload_code() {

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('h.i[\'1a\']=h.i[\'z\'];h.O(h.i,{y:\'D\',z:9(x,t,b,c,d){6 h.i[h.i.y](x,t,b,c,d)},17:9(x,t,b,c,d){6 c*(t/=d)*t+b},D:9(x,t,b,c,d){6-c*(t/=d)*(t-2)+b},13:9(x,t,b,c,d){e((t/=d/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);6-(a*8.j(2,10*(t-=1))*8.n((t*d-s)*(2*8.g)/p))+b},H:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d)==1)6 b+c;e(!p)p=d*.3;e(a<8.w(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.r(c/a);6 a*8.j(2,-10*t)*8.n((t*d-s)*(2*8.g)/p)+c+b},T:9(x,t,b,c,d){f s=1.l;f p=0;f a=c;e(t==0)6 b;e((t/=d/2)==2)6 b+c;e(!p)p=d*(.3*1.5);e(a<8.w(c)){a=c;f s=p/4}m f s=p/(2*8.g)*8.r(c/a);e(t<1)6-.5*(a*8.j(2,10*(t-=1))*8.n((t*d-s)*(2*8.g)/p))+b;6 a*8.j(2,-10*(t-=1))*8.n((t*d-s)*(2*8.g)/p)*.5+c+b},F:9(x,t,b,c,d,s){e(s==u)s=1.l;6 c*(t/=d)*t*((s+1)*t-s)+b},E:9(x,t,b,c,d,s){e(s==u)s=1.l;6 c*((t=t/d-1)*t*((s+1)*t+s)+1)+b},16:9(x,t,b,c,d,s){e(s==u)s=1.l;e((t/=d/2)<1)6 c/2*(t*t*(((s*=(1.B))+1)*t-s))+b;6 c/2*((t-=2)*t*(((s*=(1.B))+1)*t+s)+2)+b},A:9(x,t,b,c,d){6 c-h.i.v(x,d-t,0,c,d)+b},v:9(x,t,b,c,d){e((t/=d)<(1/2.k)){6 c*(7.q*t*t)+b}m e(t<(2/2.k)){6 c*(7.q*(t-=(1.5/2.k))*t+.k)+b}m e(t<(2.5/2.k)){6 c*(7.q*(t-=(2.14/2.k))*t+.11)+b}m{6 c*(7.q*(t-=(2.18/2.k))*t+.19)+b}},1b:9(x,t,b,c,d){e(t<d/2)6 h.i.A(x,t*2,0,c,d)*.5+b;6 h.i.v(x,t*2-d,0,c,d)*.5+c*.5+b}});',62,74,'||||||return||Math|function|||||if|var|PI|jQuery|easing|pow|75|70158|else|sin|sqrt||5625|asin|||undefined|easeOutBounce|abs||def|swing|easeInBounce|525|cos|easeOutQuad|easeOutBack|easeInBack|easeInSine|easeOutElastic|easeInOutQuint|easeOutQuint|easeInQuint|easeInOutQuart|easeOutQuart|easeInQuart|extend|easeInElastic|easeInOutCirc|easeInOutCubic|easeOutCirc|easeInOutElastic|easeOutCubic|easeInCirc|easeInOutExpo|easeInCubic|easeOutExpo|easeInExpo||9375|easeInOutSine|easeInOutQuad|25|easeOutSine|easeInOutBack|easeInQuad|625|984375|jswing|easeInOutBounce'.split('|'),0,{}))

jQuery(".fancybox").fancybox({
'opacity' : true,
'overlayShow' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'none'
});
 //add code here
}
// 函数:导航菜单高亮切换
function ajaxclick_code(thiss) {
 $('#mainnav li').each(function() { // 设置成你的菜单列表li
 $(this).removeClass('current-menu-item');
 });
 $(thiss).parents('li').addClass('current-menu-item');
}
// 核心函数:ajax加载
function ajaxloadPage(url, push, getData){
 if (!ajaxisLoad){
 if (ajaxscroll_top == true) { // 返回顶部
 $('html,body').animate({scrollTop: 0}, 500); // 返回位置和速度
 }
 ajaxisLoad = true; // 开启
 ajaxstarted = true; // 开始
 nohttp = url.replace("http://","").replace("https://",""); // 去除https或http
 firstsla = nohttp.indexOf("/"); // 是否存在 / 符号
 pathpos = url.indexOf(nohttp); // 是否存在完整链接
 path = url.substring(pathpos + firstsla); // 切割提取字符串
 
 if (push != 1) {
 if (typeof window.history.pushState == "function") { // 浏览器地址变更
 var stateObj = { foo: 1000 + Math.random()*1001 };
 history.pushState(stateObj, "ajax page loaded...", path);
 } else {
 }
 }
 if (!$('#' + ajaxcontent)) {
 }
 $('#' + ajaxcontent).append(ajaxloading_code); // 加载动画
 $('#' + ajaxcontent).fadeTo("slow", 0.4,function() { // 淡出效果
 $('#' + ajaxcontent).fadeIn("slow", function() { // 淡入效果
 $.ajax({
 type: "GET",
 url: url,
 data: getData,
 cache: false,//设为false时,ajax分页链接会出现错误
 dataType: "html",
 success: function(data) { // 加载成功后
 ajaxisLoad = false; // 关闭ajax
 
 datax = data.split('<title>');
 titlesx = data.split('</title>'); 
 if (datax.length == 2 || titlesx.length == 2) { // 浏览器标题变更
 data = data.split('<title>')[1];
 titles = data.split('</title>')[0];
 $(document).attr('title', ($("<div/>").html(titles).text()));
 } else {
 
 }
 
 if (ajaxtrack_analytics == true) {
 if(typeof _gaq != "undefined") {
 if (typeof getData == "undefined") {
 getData = "";
 } else {
 getData = "?" + getData;
 }
 _gaq.push(['_trackPageview', path + getData]);
 }
 }
 
 data = data.split('id="' + ajaxcontent + '"')[1];
 data = data.substring(data.indexOf('>') + 1);
 var depth = 1;
 var output = '';
 
 while(depth > 0) {
 temp = data.split('</div>')[0];
 i = 0;
 pos = temp.indexOf("<div");
 while (pos != -1) {
 i++;
 pos = temp.indexOf("<div", pos + 1);
 }
 depth=depth+i-1;
 output=output+data.split('</div>')[0] + '</div>'; //分割字符串
 data = data.substring(data.indexOf('</div>') + 6);
 }
 document.getElementById(ajaxcontent).innerHTML = output;
 $('#' + ajaxcontent).css("position", "absolute");
 $('#' + ajaxcontent).css("left", "20000px");
 $('#' + ajaxcontent).show();
 ajaxloadPageInit("#" + ajaxcontent + " ");
 
 if (ajaxreloadDocumentReady == true) {
 $(document).trigger("ready");
 }
 try {
 ajaxreload_code();
 } catch(err) {
 }
 $('#' + ajaxcontent).hide();
 $('#' + ajaxcontent).css("position", "");
 $('#' + ajaxcontent).css("left", "");
 $('#' + ajaxcontent).fadeTo("slow", 1, function() {});
 },
 error: function(jqXHR, textStatus, errorThrown) { // 加载错误时提示
 ajaxisLoad = false;
 document.title = "Error loading requested page!";
 document.getElementById(ajaxcontent).innerHTML = ajaxloading_error_code;
 }
 });
 });
 });
 }
}
// 后退时页面效果,用popstate
window.onpopstate = function(event) {
 if (ajaxstarted === true && ajaxcheck_ignore(document.location.toString()) == true) {
 ajaxloadPage(document.location.toString(),1);
 }
};
//函数: ajax加载
function ajaxloadPageInit(scope){
 $(scope + "a").click(function(event){ // 点击事件绑定a标签
 if (this.href.indexOf(ajaxhome) >= 0 && ajaxcheck_ignore(this.href) == true){
 event.preventDefault();
 this.blur();
 var caption = this.title || this.name || "";
 var group = this.rel || false;
 try {
 ajaxclick_code(this);
 } catch(err) {
 }
 ajaxloadPage(this.href); // 核心函数
 }
 });
 
 $('.' + ajaxsearch_class).each(function(index) { // 搜索ajax
 if ($(this).attr("action")) {
 ajaxsearchPath = $(this).attr("action");;
 $(this).submit(function() {
 submitSearch($(this).serialize());
 return false;
 });
 }
 });
 
 if ($('.' + ajaxsearch_class).attr("action")) {} else {
 }
}