1
0
Fork 0
forked from OpenNeo/impress
impress/public/assets/rails.js

1 line
2.3 KiB
JavaScript
Raw Normal View History

document.observe("dom:loaded",function(){function i(e){var t,n,r;e.tagName.toLowerCase()=="form"?(t=e.readAttribute("method")||"post",n=e.readAttribute("action"),r=e.serialize(!0)):(t=e.readAttribute("data-method")||"get",n=e.readAttribute("href"),r={});var i=e.fire("ajax:before");if(i.stopped)return!1;new Ajax.Request(n,{method:t,parameters:r,asynchronous:!0,evalScripts:!0,onLoading:function(t){e.fire("ajax:loading",{request:t})},onLoaded:function(t){e.fire("ajax:loaded",{request:t})},onInteractive:function(t){e.fire("ajax:interactive",{request:t})},onComplete:function(t){e.fire("ajax:complete",{request:t})},onSuccess:function(t){e.fire("ajax:success",{request:t})},onFailure:function(t){e.fire("ajax:failure",{request:t})}}),e.fire("ajax:after")}var e=$$("meta[name=csrf-token]").first().readAttribute("content"),t=$$("meta[name=csrf-param]").first().readAttribute("content"),n='<form method="#{method}" action="#{action}"> #{realmethod}<input name="#{param}" value="#{token}" type="hidden"> </form>',r='<input name="_method" value="#{method}" type="hidden">';$(document.body).observe("click",function(s){var o=s.element().readAttribute("data-confirm");if(o&&!confirm(o))return s.stop(),!1;var u=s.findElement("a[data-remote=true]");u&&(i(u),s.stop());var u=s.findElement("a[data-method]");if(u&&u.readAttribute("data-remote")!="true"){var a=u.readAttribute("data-method"),f=a.toLowerCase()!="post",l=n.interpolate({method:"POST",realmethod:f?r.interpolate({method:a}):"",action:u.readAttribute("href"),token:e,param:t}),c=(new Element("div")).update(l).down().hide();this.insert({bottom:c}),c.submit(),s.stop()}}),$(document.body).observe("submit",function(e){var t=e.element().readAttribute("data-confirm");if(t&&!confirm(t))return e.stop(),!1;var n=e.element().select("input[type=submit][data-disable-with]");n.each(function(e){e.disabled=!0,e.writeAttribute("data-original-value",e.value),e.value=e.readAttribute("data-disable-with")});var r=e.findElement("form[data-remote=true]");r&&(i(r),e.stop())}),$(document.body).observe("ajax:complete",function(e){var t=e.element();if(t.tagName.toLowerCase()=="form"){var n=t.select("input[type=submit][disabled=true][data-disable-with]");n.each(function(e){e.value=e.readAttribute("data-original-value"),e.writeAttribute("data-original-value",null),e.disabled=!1})}})});