-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.ajaxlinks.min.js
1 lines (1 loc) · 4.24 KB
/
jquery.ajaxlinks.min.js
1
(function(e){e.fn.ajaxlinks=function(t){var n={load_to:"#content",load_from:null,loader:"<span>Loading...</span>",callback:null,use_sammy:false,prefix:"",smooth_height:true,goto_top:false,fix_forms:true,add_scripts:false,ajaxify_content:false,base_url:"",ignore:".no-al",ignore_paths:""};var r=e.extend(n,t);if(r.ignore!=""){if(typeof r.ignore=="string"){r.ignore=[r.ignore," a, a",r.ignore].join("")}else{var s="";for(i=0,ln=r.ignore.length;i<ln;i++){s=[s,i>0?", ":"",r.ignore[i]," a, a",r.ignore[i]].join("")}r.ignore=s}}var o=function(e){var t="a[href";if(e.substr(0,1)=="*"){if(e.substr(e.length-1,1)=="*"){t=[t,"*="].join("")}else{t=[t,"$="].join("")}}else if(e.substr(e.length-1,1)=="*"){t=[t,"^="].join("")}else{t=[t,"="].join("")}return[t,e.replace(/\*/g,"").replace(/[#;&,.+~':"!^$[\]()=>|\/]/g,"\\$&"),"]"].join("")};if(r.ignore_paths!=null&&r.ignore_paths!=""){if(typeof r.ignore_paths=="string"){r.ignore_paths=o(r.ignore_paths)}else{var s="";for(i=0,ln=r.ignore_paths.length;i<ln;i++){s=[s,i>0?", ":"",o(r.ignore_paths[i])].join("")}r.ignore_paths=s}}var u=function(e){if(r.ignore==""){if(r.ignore_paths==""){return e}else{return e.filter(":not('"+r.ignore_paths+"')")}}else if(r.ignore_paths==""){return e.filter(":not('"+r.ignore+"')")}else{return e.filter(":not('"+r.ignore+", "+r.ignore_paths+"')")}};r.links=u(e(this));var a="";var f=function(t){if(r.goto_top){window.scrollTo(0,0)}var n={};if(typeof e.sammy=="function"&&r.use_sammy==true){var i=t.split("|");for(var s=0,o=i.length;s<o;s++){var f=i[s].split("=");if(f.length>2){var c=f[1];for(s=2;s<f.length;s++){var c=[c,"=",f[s]].join("")}n[f[0]]=c}else{n[f[0]]=f[1]}}}else{n.path=t}var h=function(e){var t=new Array;while(e.indexOf("<script")>-1||e.indexOf("</script")>-1){var n=e.indexOf("<script");var r=e.indexOf(">",n);var i=e.indexOf("</script",n);var s=e.indexOf(">",i);t.push(e.substring(r+1,i));e=e.substring(0,n)+e.substring(s+1)}return t};var p=function(i,s,o){e(r.load_to).addClass("ajax-loaded");if(r.smooth_height){v.height("auto")}var a=e(this).html();if(r.load_from&&i){if(e(this).find(r.load_from).length>0){a=e(this).find(r.load_from).html();v.html(a)}else{a=i;v.html(a)}}if(r.fix_forms){e('[action="."]').attr("action",t.replace("path=",""))}if(r.add_scripts){var c=new Array,p=i,d=function(e){setTimeout([e,"();"].join(""),100)},m=function(e,t){if(e===t){return true}if(e.length!=t.length){return false}for(key in e){if(e[key]!==t[key]){return false}}return true},g=function(e){f=new Array;for(k=0;k<e.length;k++){if(!y(f,e[k])){f.length+=1;f[f.length-1]=e[k]}}return f},y=function(e,t){for(j=0;j<e.length;j++){if(m(e[j],t)){return true}}return false};while(p.indexOf("<script ")>-1&&p.indexOf("></script>")>-1){var b=p.indexOf("<script ");var w=p.indexOf("</script>",b);if(p.substring(b,w).indexOf("src=")>-1){var E=p.indexOf("src=",b)+5;var S=p.substring(E-1,E);var x=p.indexOf(S,E);var T=p.substring(E,x);if(p.substring(b,w).indexOf("data-callback=")>-1){var N=p.indexOf("data-callback=",b)+15;var S=p.substring(N-1,N);var C=p.indexOf(S,N);var T=[T,p.substring(N,C)]}c.push(T)}p=p.substring(0,b)+p.substring(w+9)}g(c);for(var k=0,L=c.length;k<L;k++){if(typeof c[k]!="string"){var A=c[k][0];var O=c[k][1]}else{var A=c[k];var O=false}if(e(['head script[src*="',A,'"]'].join("")).length==0){e.ajax({url:A,dataType:"script",cache:true,async:false})}else if(O){d(O)}}}if(r.ajaxify_content){l(u(e(r.load_to).find("a")))}if(r.callback){var M=r.links.filter('[href*="'+t+'"]');var c=h(i);r.callback(a,M,n,c)}};a=n.path;var d=r.load_from?[n.path,r.load_from].join(" "):n.path,v=e(r.load_to);if(r.smooth_height){v.height(v.height())}v.html(e(r.loader)).load(d,p)};var l=function(t){var n=function(e){return!(e.indexOf(location.href.replace("http://","").replace("https://","").split("/")[0])>-1)};if(r.use_sammy){t.each(function(t,i){var s=e(i).attr("href");if(s!=undefined&&s.indexOf("#!")==-1&&!n(e(i)[0].href)){e(i).attr("href",[r.base_url,r.prefix,"#!path=",s].join(""))}})}else{t.each(function(t,r){if(!n(e(r)[0].href)){e(r).data("al","true");e(r).bind("click",function(){f(e(this).attr("href"));return false})}})}};if(typeof e.sammy=="function"&&r.use_sammy==true){if(e.sammy.apps==undefined){var c=e.sammy(function(){this.get(/\#!(.*)/,function(e){f(window.location.href.split("#!")[1])})});e(function(){c.run()})}l(r.links)}else{l(r.links)}}})(jQuery)