impress/public/assets/pets/bulk-fd50dfb06d835663a7c0d28f9ad801d9.js

1 line
2.5 KiB
JavaScript
Raw Normal View History

var DEBUG=document.location.search.substr(0,6)=="?debug";(function(){function n(e){t=$.ajax(e)}function r(){DEBUG&&console.log("Canceling request",t),t.abort()}function s(t){r(),n({url:e.form.attr("action")+".json",dataType:"json",data:{name:t},error:u,success:function(e){a(e,t)},complete:o}),e.form.removeClass("failed").addClass("loading-pet")}function o(){e.form.removeClass("loading-pet")}function u(t){e.alert.text(t.responseText),e.form.addClass("failed")}function a(t,n){i=n,e.pet_thumbnail.attr("src",f(n)),e.pet_header.empty(),$("#needed-items-pet-header-template").tmpl({pet_name:n}).appendTo(e.pet_header),l(t.query)}function f(e){return"http://pets.neopets.com/cpn/"+e+"/1/1.png"}function l(t){e.form.addClass("loading-items"),n({url:"/items/needed.json",dataType:"json",data:t,success:c})}function c(t){DEBUG&&(t=t.slice(0,100)),e.pet_items.empty(),e.item_template.tmpl(t).appendTo(e.pet_items),e.form.removeClass("loading-items").addClass("loaded")}var e={};e.form=$("#needed-items-form"),e.alert=$("#needed-items-alert"),e.pet_name_field=$("#needed-items-pet-name-field"),e.pet_thumbnail=$("#needed-items-pet-thumbnail"),e.pet_header=$("#needed-items-pet-header"),e.reload=$("#needed-items-reload"),e.pet_items=$("#needed-items-pet-items"),e.item_template=$("#item-template");var t={abort:function(){}},i=null;e.form.submit(function(t){t.preventDefault(),s(e.pet_name_field.val())}),e.reload.click(function(e){e.preventDefault(),s(i)})})(),function(){var e=$("#bulk-pets-form"),t=e.find("ul"),n=e.find("textarea"),r=$("#bulk-pets-form-add"),i=$("#bulk-pets-form-clear"),s;$(document.body).addClass("js"),s=new function(){function s(e){var n=$("#bulk-pets-submission-template").tmpl({pet_name:e}).appendTo(t);this.load=function(){n.removeClass("waiting").addClass("loading");var t=n.find("span.response");$.ajax({complete:function(e){r.shift(),r.length&&r[0].load()},data:{name:e},dataType:"json",error:function(e){n.removeClass("loading").addClass("failed"),t.text(e.responseText)},success:function(e){var r=e.points;n.removeClass("loading").addClass("loaded"),$("#bulk-pets-submission-success-template").tmpl({points:r}).appendTo(t)},type:"post",url:i})}}var r=[],i=e.attr("action")+".json";this.add=function(e){e=e.replace(/^\s+|\s+$/g,"");if(e.length){var t=new s(e);r.push(t),r.length==1&&t.load()}}},n.keyup(function(){var e=this.value.split("\n"),t=e.length-1,n,r;for(n=0;n<t;n++)s.add(e[n]);this.value=t>=0?e[t]:""}),r.click(function(){s.add(n.val()),n.val("")}),i.click(function(){t.children("li.loaded, li.failed").remove()})}();