1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 08:22:35 +01:00
Sonarr/NzbDrone.Web/Scripts/jquery.unobtrusive-ajax.min.js
Mark McDowall 5220de5c66 Lazy load exisitng series
New: Existing series will be lazy loaded on Add Series page
2012-10-28 12:08:37 -07:00

1 line
2.7 KiB
JavaScript

(function(n){function i(n,t){for(var i=window,r=(n||"").split(".");i&&r.length;)i=i[r.shift()];return typeof i=="function"?i:(t.push(n),Function.constructor.apply(null,t))}function u(n){return n==="GET"||n==="POST"}function e(n,t){u(t)||n.setRequestHeader("X-HTTP-Method-Override",t)}function o(t,i,r){var u;r.indexOf("application/x-javascript")===-1&&(u=(t.getAttribute("data-ajax-mode")||"").toUpperCase(),n(t.getAttribute("data-ajax-update")).each(function(t,r){var f;switch(u){case"BEFORE":f=r.firstChild,n("<div />").html(i).contents().each(function(){r.insertBefore(this,f)});break;case"AFTER":n("<div />").html(i).contents().each(function(){r.appendChild(this)});break;default:n(r).html(i)}}))}function r(t,r){var s,h,f,c;(s=t.getAttribute("data-ajax-confirm"),!s||window.confirm(s))&&(h=n(t.getAttribute("data-ajax-loading")),c=t.getAttribute("data-ajax-loading-duration")||0,n.extend(r,{type:t.getAttribute("data-ajax-method")||undefined,url:t.getAttribute("data-ajax-url")||undefined,beforeSend:function(n){var r;return e(n,f),r=i(t.getAttribute("data-ajax-begin"),["xhr"]).apply(this,arguments),r!==!1&&h.show(c),r},complete:function(){h.hide(c),i(t.getAttribute("data-ajax-complete"),["xhr","status"]).apply(this,arguments)},success:function(n,r,u){o(t,n,u.getResponseHeader("Content-Type")||"text/html"),i(t.getAttribute("data-ajax-success"),["data","status","xhr"]).apply(this,arguments)},error:i(t.getAttribute("data-ajax-failure"),["xhr","status","error"])}),r.data.push({name:"X-Requested-With",value:"XMLHttpRequest"}),f=r.type.toUpperCase(),u(f)||(r.type="POST",r.data.push({name:"X-HTTP-Method-Override",value:f})),n.ajax(r))}function s(t){var i=n(t).data(f);return!i||!i.validate||i.validate()}var t="unobtrusiveAjaxClick",f="unobtrusiveValidation";n("a[data-ajax=true]").live("click",function(n){n.preventDefault(),r(this,{url:this.href,type:"GET",data:[]})}),n("form[data-ajax=true] input[type=image]").live("click",function(i){var r=i.target.name,u=n(i.target),f=u.parents("form")[0],e=u.offset();n(f).data(t,[{name:r+".x",value:Math.round(i.pageX-e.left)},{name:r+".y",value:Math.round(i.pageY-e.top)}]),setTimeout(function(){n(f).removeData(t)},0)}),n("form[data-ajax=true] :submit").live("click",function(i){var r=i.target.name,u=n(i.target).parents("form")[0];n(u).data(t,r?[{name:r,value:i.target.value}]:[]),setTimeout(function(){n(u).removeData(t)},0)}),n("form[data-ajax=true]").live("submit",function(i){var u=n(this).data(t)||[];(i.preventDefault(),s(this))&&r(this,{url:this.action,type:this.method||"GET",data:u.concat(n(this).serializeArray())})}),n(document).ready(function(){n("div[data-ajax-action-link=true]").each(function(){r(this,{url:n(this).attr("data-href"),type:"GET",data:[]})})})})(jQuery)