mirror of
https://codeberg.org/nobody/LocalCDN.git
synced 2024-12-28 02:49:58 +01:00
1 line
8.6 KiB
JavaScript
1 line
8.6 KiB
JavaScript
|
!function(){"use strict";function t(s,l){var u;s.rails!==l&&s.error("jquery-ujs has already been loaded!");var t=s(document);s.rails=u={linkClickSelector:"a[data-confirm], a[data-method], a[data-remote]:not([disabled]), a[data-disable-with], a[data-disable]",buttonClickSelector:"button[data-remote]:not([form]):not(form button), button[data-confirm]:not([form]):not(form button)",inputChangeSelector:"select[data-remote], input[data-remote], textarea[data-remote]",formSubmitSelector:"form:not([data-turbo=true])",formInputClickSelector:"form:not([data-turbo=true]) input[type=submit], form:not([data-turbo=true]) input[type=image], form:not([data-turbo=true]) button[type=submit], form:not([data-turbo=true]) button:not([type]), input[type=submit][form], input[type=image][form], button[type=submit][form], button[form]:not([type])",disableSelector:"input[data-disable-with]:enabled, button[data-disable-with]:enabled, textarea[data-disable-with]:enabled, input[data-disable]:enabled, button[data-disable]:enabled, textarea[data-disable]:enabled",enableSelector:"input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled, input[data-disable]:disabled, button[data-disable]:disabled, textarea[data-disable]:disabled",requiredInputSelector:"input[name][required]:not([disabled]), textarea[name][required]:not([disabled])",fileInputSelector:"input[name][type=file]:not([disabled])",linkDisableSelector:"a[data-disable-with], a[data-disable]",buttonDisableSelector:"button[data-remote][data-disable-with], button[data-remote][data-disable]",csrfToken:function(){return s("meta[name=csrf-token]").attr("content")},csrfParam:function(){return s("meta[name=csrf-param]").attr("content")},CSRFProtection:function(t){var e=u.csrfToken();e&&t.setRequestHeader("X-CSRF-Token",e)},refreshCSRFTokens:function(){s('form input[name="'+u.csrfParam()+'"]').val(u.csrfToken())},fire:function(t,e,a){e=s.Event(e);return t.trigger(e,a),!1!==e.result},confirm:function(t){return confirm(t)},ajax:function(t){return s.ajax(t)},href:function(t){return t[0].href},isRemote:function(t){return t.data("remote")!==l&&!1!==t.data("remote")},handleRemote:function(n){if(u.fire(n,"ajax:before")){var t,e,a,o,r=n.data("with-credentials")||null,i=n.data("type")||s.ajaxSettings&&s.ajaxSettings.dataType;return n.is("form")?(t=n.data("ujs:submit-button-formmethod")||n.attr("method"),e=n.data("ujs:submit-button-formaction")||n.attr("action"),a=s(n[0]).serializeArray(),(o=n.data("ujs:submit-button"))&&(a.push(o),n.data("ujs:submit-button",null)),n.data("ujs:submit-button-formmethod",null),n.data("ujs:submit-button-formaction",null)):n.is(u.inputChangeSelector)?(t=n.data("method"),e=n.data("url"),a=n.serialize(),n.data("params")&&(a=a+"&"+n.data("params"))):n.is(u.buttonClickSelector)?(t=n.data("method")||"get",e=n.data("url"),a=n.serialize(),n.data("params")&&(a=a+"&"+n.data("params"))):(t=n.data("method"),e=u.href(n),a=n.data("params")||null),i={type:t||"GET",data:a,dataType:i,beforeSend:function(t,e){if(e.dataType===l&&t.setRequestHeader("accept","*/*;q=0.5, "+e.accepts.script),!u.fire(n,"ajax:beforeSend",[t,e]))return!1;n.trigger("ajax:send",t)},success:function(t,e,a){n.trigger("ajax:success",[t,e,a])},complete:function(t,e){n.trigger("ajax:complete",[t,e])},error:function(t,e,a){n.trigger("ajax:error",[t,e,a])},crossDomain:u.isCrossDomain(e)},r&&(i.xhrFields={withCredentials:r}),e&&(i.url=e),u.ajax(i)}return!1},isCrossDomain:function(t){var e=document.createElement("a");e.href=location.href;var a=document.createElement("a");try{return a.href=t,a.href=a.href,!((!a.protocol||":"===a.protocol)&&!a.host||e.protocol+"//"+e.host==a.protocol+"//"+a.host)}catch(t){return!0}},handleMethod:function(t){var e=u.href(t),a=t.data("method"),n=t.attr("target"),o=u.csrfToken(),r=u.csrfParam(),t=s('<form method="post" action="'+e+'"></form>'),a='<input name="_method" value="'+a+'" type="hidden" />';r===l||o===l||u.isCrossDomain(e)||(a+='<input name="'+r+'" value="'+o+'" type="hidden" />'),n&&t.attr("target",n),t.hide().append(a).appendTo("body"),t.submit()}
|