I" (function() { window.xhr2 || (window.xhr2 = function() { return !!window.ProgressEvent && !!window.FormData; }); window.alexandrie = { load: function() { return $("#dorsale-attachments").map(function() { var container, url; container = $(this); url = this.dataset.url; return $.ajax({ url: url, success: function(data) { container.html(data); setupUploadInputs(container); alexandrie.setupCreateForm(); alexandrie.setupEditButtons(); return alexandrie.setupDeleteButtons(); } }); }); }, reload: function() { return alexandrie.load(); }, setupCreateForm: function() { if (xhr2()) { return $("#new_attachment").submit(function() { var data, form, xhr; form = $(this); xhr = new XMLHttpRequest(); data = new FormData(this); xhr.upload.addEventListener("progress", function(e) { var bar, percentComplete; if (e.lengthComputable) { percentComplete = Math.round(e.loaded * 100 / e.total); if (percentComplete === 0) { percentComplete = 1; } if (percentComplete === 100) { percentComplete = 99; } bar = form.find(".progress-bar"); bar.html(percentComplete + "%"); bar.css({ "width": percentComplete + "%" }); return bar.attr({ "aria-valuenow": percentComplete }); } }); xhr.addEventListener("load", function(e) { return alexandrie.reload(); }); xhr.addEventListener("error", function(e) { alert("Error"); return alexandrie.reload(); }); xhr.open("POST", this.action, true); xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xhr.send(data); return false; }); } }, setupEditForm: function() { return $("#edit_attachment").on("ajax:success", alexandrie.reload); }, setupEditButtons: function() { return $("#dorsale-attachments [href$=edit]").click(function() { var li, url; li = $(this).parents("li"); url = this.href; $.ajax({ url: url, success: function(data) { li.html(data); return alexandrie.setupEditForm(); } }); return false; }); }, setupDeleteButtons: function() { return $("#dorsale-attachments [data-method=delete]").map(function() { return $(this).on("ajax:success", alexandrie.reload); }); } }; }).call(this); :ET