forked from OpenNeo/impress
1 line
No EOL
23 KiB
JavaScript
1 line
No EOL
23 KiB
JavaScript
$.fn.notify=function(){return this.stop(!0,!0).show("slow").delay(5e3).hide("fast")},$.fn.startLoading=function(){return this.delay(1e3).queue(function(e){$(this).addClass("loading"),e()})},$.fn.stopLoading=function(){return this.removeClass("loading").clearQueue()};var Partial={},main_wardrobe,View=Wardrobe.getStandardView({Preview:{swf_url:"/swfs/preview.swf?v=0.12",wrapper:$("#preview-swf"),placeholder:$("#preview-swf-container"),image_container:"#preview-image-container"}});Partial.ItemSet=function(t,n){function h(e){return function(t){var n,r,i;for(var o=0;o<s.length;o++)n=s[o],in_set=$.inArray(n,t)!=-1,i=$("li.object-"+n.id).toggleClass(e,in_set).data("item",n).data(e,in_set)}}function p(e){var n,r,i,s;for(var o=0,u=e.length;o<u;o++)n=e[o],r=n.couldNotLoadAssetsFitting(t.outfits.getPetType()),i=$("li.object-"+n.id).toggleClass("no-assets",r)}var r=this,i=$(n),s=[],o,u,a,f=$("#no-assets-full-message"),l=$("#container"),c=$("#item-template");Partial.ItemSet.setWardrobe(t),o=h("closeted"),a=h("worn"),u=function(e){a(e),p(e)},this.setItems=function(e){var n,r,a,f;s=e,i.children().remove();for(var l=0;l<s.length;l++)n=s[l],r=c.tmpl({id:n.id,name:n.name,description:n.description,thumbnail_url:n.thumbnail_url,url:n.getURL(),nc:typeof n.rarity_index!="undefined"&&(n.rarity_index==500||n.rarity_index==0),owned:n.owned,wanted:n.wanted}),r.appendTo(i);o(t.outfits.getClosetItems()),u(t.outfits.getWornItems())},$("span.no-assets-message").live("mouseover",function(){var e=$(this),t=e.offset();f.css({left:t.left+e.width()/2-f.width()/2-l.offset().left,top:t.top+e.height()+10})}).live("mouseout",function(){f.removeAttr("style")}),t.outfits.bind("updateItemAssets",function(){p(t.outfits.getWornItems())}),t.outfits.bind("updateWornItems",u),t.outfits.bind("updateClosetItems",o)},Partial.ItemSet.CONTROL_SETS={},Partial.ItemSet.setWardrobe=function(e){var t,n,r={},i={worn:{},closeted:{}};i.worn["false"]="wear-item",i.worn["true"]="unwear-item",i.closeted["false"]="closet-item",i.closeted["true"]="uncloset-item";for(t in i)for(toggleKey in i[t]){var n=toggleKey=="true";(function(e,t){$("li."+i[e][t]+" a").live("click",function(n){n.preventDefault();var i=$(this).closest(".object").data("item");log(this,i,e,t,!t),r[e][!t](i)})})(t,n)}r.closeted={},r.closeted[!0]=$.proxy(e.outfits,"closetItem"),r.closeted[!1]=$.proxy(e.outfits,"unclosetItem"),r.worn={},r.worn[!0]=$.proxy(e.outfits,"wearItem"),r.worn[!1]=$.proxy(e.outfits,"unwearItem"),Partial.ItemSet.setWardrobe=$.noop},View.Closet=function(e){var t=new Partial.ItemSet(e,"#preview-closet ul");e.outfits.bind("updateClosetItems",$.proxy(t,"setItems"))},View.Fullscreen=function(e){function h(){if(!c){var e=l.height()>500;e!=t&&(t=e,$(document.body).toggleClass("fullscreen",t),t||(s.removeAttr("style").css("visibility","visible"),r.removeAttr("style"),u.removeAttr("style")))}if(t){s=$("#preview-swf");var n={height:i.offset().top-r.offset().top,width:r.innerWidth()-o.outerWidth()-12},f={},h={},p={old:{height:s.height(),width:s.width()},next:{}},d;n.height>n.width?(f.larger="height",f.smaller="width",h.active="marginTop",h.inactive="marginLeft"):(f.larger="width",f.smaller="height",h.active="marginLeft",h.inactive="marginTop"),p.next[f.smaller]=n[f.smaller],p.next[f.larger]=n[f.smaller],p.next[h.active]=(n[f.larger]-p.next[f.larger])/2,p.next[h.inactive]=0,s.css(p.next),r.height(n.height);var v=n.height-a.outerHeight()-1;u.height(v)}}function p(){setTimeout(h,0)}var t=$(document.body).hasClass("fullscreen"),n=$(window),r=$("#preview"),i=$("#preview-search-form"),s=$("#preview-swf"),o=$("#preview-sidebar"),u=$("#preview-sidebar-content"),a=$("#preview-sidebar-navbar"),f=$("#footer"),l=$(window),c=!1;$("#preview").data("fit",h),n.resize(h).load(h),e.item_zone_sets.bind("update",p),e.pet_attributes.bind("update",p),h()},View.Hash=function(e){function a(){var e=(document.location.hash||document.location.search).substr(1);e!=r&&(f(e),r=e)}function f(n){var r={},u=n.split("&");i=!0;for(var a=0;a<u.length;a++){var f=u[a].split("="),l=decodeURIComponent(f[0]),c=decodeURIComponent(f[1]);c&&(o[l]==s.INTEGER?r[l]=+c:o[l]==s.STRING?r[l]=decodeURIComponent(c).replace(/\+/g," "):l.substr(l.length-2)=="[]"&&(l=l.substr(0,l.length-2),o[l]==s.INTEGER_ARRAY&&(typeof r[l]=="undefined"&&(r[l]=[]),r[l].push(+c))))}(r.color!==t.color||r.species!==t.species)&&e.outfits.setPetTypeByColorAndSpecies(r.color,r.species),r.closet?arraysMatch(r.closet,t.closet)||e.outfits.setClosetItemsByIds(r.closet.slice(0)):r.objects&&!arraysMatch(r.objects,t.closet)?e.outfits.setClosetItemsByIds(r.objects.slice(0)):e.outfits.setClosetItemsByIds([]),r.objects?arraysMatch(r.objects,t.objects)||e.outfits.setWornItemsByIds(r.objects.slice(0)):e.outfits.setWornItemsByIds([]),r.name!=t.name&&r.name&&e.base_pet.setName(r.name),r.state!=t.state&&e.outfits.setPetStateById(r.state),r.outfit!=t.outfit&&e.outfits.setId(r.outfit),(r.search!=t.search||r.search_offset!=t.search_offset)&&e.search.setItemsByQuery(r.search,{offset:r.search_offset}),t=r,i=!1,h()}function l(e){var n;if(!i){for(var r in e)e.hasOwnProperty(r)&&(n=e[r],n===undefined?delete t[r]:t[r]=e[r]);c()}}function c(){var e;e=$.param(t).replace(/%5B%5D/g,"[]"),r=e,document.location.hash="#"+e,h()}function h(){u.each(function(){var e="return_to="+encodeURIComponent(document.location.pathname+document.location.search+document.location.hash);this.href=this.href.replace(/return_to=[^&]+/,e)})}function p(t,n){e.outfits.bind(t,function(){e.outfits.in_transaction||n.apply(this,arguments)})}var t={},n={},r,i=!1,s={INTEGER:1,STRING:2,INTEGER_ARRAY:3},o={closet:s.INTEGER_ARRAY,color:s.INTEGER,name:s.STRING,objects:s.INTEGER_ARRAY,outfit:s.INTEGER,search:s.STRING,search_offset:s.INTEGER,species:s.INTEGER,state:s.INTEGER},u=$("a[href*=return_to]");this.initialize=function(){a(),setInterval(a,100)},p("updateClosetItems",function(e){var n=e.mapProperty("id");arraysMatch(n,t.closet)||l({closet:n})}),p("updateWornItems",function(n){var r=n.mapProperty("id"),i={};arraysMatch(r,t.objects)||(i.objects=r),arraysMatch(r,t.closet)||arraysMatch(r,t.objects)?i.closet=undefined:i.closet=e.outfits.getClosetItems().mapProperty("id"),(i.objects||i.closet)&&l(i)}),p("updatePetType",function(e){(e.color_id!=t.color||e.species_id!=t.species)&&l({color:e.color_id,species:e.species_id,state:undefined})}),p("petTypeNotFound",function(){window.history.back()}),p("updatePetState",function(n){var r=e.outfits.getPetType();n.id!=t.state&&r&&(t.state||n.id!=r.pet_states[0].id)&&l({state:n.id})}),p("setOutfit",function(e){e.id!=t.outfit&&l({outfit:e.id})}),e.outfits.bind("loadOutfit",function(e){l({closet:e.getClosetItemIds(),color:e.pet_type.color_id,objects:e.getWornItemIds(),outfit:e.id,species:e.pet_type.species_id,state:e.pet_state.id})}),e.outfits.bind("outfitNotFound",function(e){var t=e?e.id:undefined;l({outfit:t})}),e.search.bind("updateRequest",function(e){(e.offset!=t.search_offset||e.query!=t.search)&&l({search_offset:e.offset,search:e.query})})},View.Outfits=function(e){function m(e){return $("li.outfit-"+e.id)}function g(e){var t=p.attr("class");t!=e&&(v=t),p.attr("class",e)}function y(){P.onHide(),g("")}function b(){P.onHide(),e.outfits.loadOutfits(),g("viewing-outfits")}function w(){P.onShow(),g("sharing")}function E(){r.val(""),n.removeClass("starred").stopLoading(),f.addClass("saving-outfit"),r.focus()}function S(){f.removeClass("saving-outfit")}function T(t){x[t.id]=e.image_subscriptions.subscribe(t)}function N(t){t.id in x&&(x[t.id]!==null&&e.image_subscriptions.unsubscribe(x[t.id]),delete x[t.id])}function C(){var t=$(this),n=t.tmplItem().data,r=t.val(),i=t.closest("li").removeClass("renaming");r!=n.name&&(i.startLoading(),e.outfits.renameOutfit(n,r))}function k(e){if(e.indexOf("://")==-1){var t=document.location.protocol+"//"+document.location.host;return t+e}return e}function L(e){return k("/outfits/"+e.id)}function A(e,t,n){var r=L(e);t.attr("href",r),n&&n.val(r)}function O(e){A(e,t)}function M(e){s.find("li.active").removeClass("active"),e.id&&(O(e),m(e).addClass("active"),a.text(e.name)),f.toggleClass("active-outfit",e.id?!0:!1)}function _(){M(e.outfits.getOutfit())}function D(e){return i.find("li.outfit-"+e.id)}function H(e){c.text(e).notify()}function B(e){f.stopLoading().addClass("shared-outfit"),P.setOutfit(e),w()}function j(){f.removeClass("shared-outfit")}function F(e,t){typeof t.full_error_messages!="undefined"?H(t.full_error_messages.join(", ")):H("Could not save outfit. Please try again."),n.stopLoading(),m(e).stopLoading()}var t=$("#current-outfit-permalink"),n=$("#save-outfit-form"),r=$("#save-outfit-name"),i=$("#preview-outfits"),s=i.children("ul"),o=$("#outfit-not-found"),u=$("#save-current-outfit"),a=u.children("span"),f=$("#save-outfit-wrapper"),l=$("#save-success"),c=$("#save-error"),h=$("#preview-outfits div.outfit-star"),p=$("#preview-sidebar"),d,v="";d=$("meta[name=user-signed-in]").attr("content")=="true",d?$(document.body).addClass("user-signed-in"):$(document.body).addClass("user-not-signed-in"),$("#preview-sidebar-navbar-closet").click(y),$("#preview-sidebar-navbar-sharing").click(function(){P.startLoading(),e.outfits.share(),w()}),$("#preview-sidebar-navbar-outfits").click(b),$("#save-outfit, #save-outfit-copy").click(E),$("#save-outfit-cancel").click(S),$("#save-outfit-not-signed-in").click(function(){window.location.replace($("#userbar a").attr("href"))});var x={};$("#outfit-template").template("outfitTemplate"),e.outfits.bind("outfitsLoaded",function(e){var t=$.tmpl("outfitTemplate",e);s.html("").append(t).addClass("loaded"),_();for(var n=0;n<e.length;n++)T(e[n])}),e.outfits.bind("addOutfit",function(e,t){var n=s.children().not(".hiding").eq(t),r=$.tmpl("outfitTemplate",e.clone());n.length?r.insertBefore(n):r.appendTo(s),_();var i=r.css("width");log("Natural width is",i,r.width()),r.width(0).animate({width:i},"normal"),T(e)}),e.outfits.bind("removeOutfit",function(e,t){var n=s.children().not(".hiding").eq(t);n.addClass("hiding").stop(!0).animate({width:0},"normal",function(){n.remove()}),N(e)}),$("#preview-outfits li header, #preview-outfits li .outfit-thumbnail-wrapper").live("click",function(){e.outfits.load($(this).tmplItem().data.id)}),$("a.outfit-rename-button").live("click",function(e){e.preventDefault();var t=$(this).closest("li").addClass("renaming"),n=t.find("span.outfit-name").text();t.find("input.outfit-rename-field").val(n).focus()}),$("input.outfit-rename-field").live("blur",C),$("form.outfit-rename-form").live("submit",function(e){e.preventDefault();var t=$(this).find("input");C.apply(t)}),$("input.outfit-url").live("mouseover",function(){this.focus()}).live("mouseout",function(){this.blur()}),$("a.outfit-delete").live("click",function(e){e.stopPropagation(),e.preventDefault(),$(this).closest("li").addClass("confirming-deletion")}),$("a.outfit-delete-confirmation-yes").live("click",function(t){var n=$(this).tmplItem().data;t.preventDefault(),e.outfits.destroyOutfit(n),e.outfits.getOutfit().id==n.id&&e.outfits.setId(null)}),$("a.outfit-delete-confirmation-no").live("click",function(e){e.preventDefault(),$(this).closest("li").removeClass("confirming-deletion")}),h.live("click",function(t){t.stopPropagation();var n=$(this);n.closest("li").startLoading(),e.outfits.toggleOutfitStar(n.tmplItem().data)}),e.outfits.bind("setOutfit",M),e.outfits.bind("outfitNotFound",M),e.outfits.bind("outfitRenamed",function(t){t.id==e.outfits.getId()&&a.text(t.name)}),e.outfits.bind("saveSuccess",function(e){T(e)}),e.image_subscriptions.bind("imageEnqueued",function(e){e.id in x&&(log("List sees imageEnqueued for",e),D(e).removeClass("thumbnail-loaded"))}),e.image_subscriptions.bind("imageReady",function(e){if(e.id in x){log("List sees imageReady for",e),N(e);var t=e.image_versions.small+"?"+(new Date).getTime();D(e).addClass("thumbnail-loaded").addClass("thumbnail-available").find("img.outfit-thumbnail").attr("src",t)}});var P=new function(){function u(e,t){var n=e.tmpl(t),r=n.clone().wrap("<div>").parent().html();return r}function h(){e.image_subscriptions.unsubscribe(c),c=null}function d(t){c=e.image_subscriptions.subscribe(t)}function v(e){e&&p.hasClass("sharing")&&d(e)}function g(){b("small_image"),b("medium_image"),b("large_image"),y("permalink")}function y(e){w(e,f.text(l[e]))}function b(e){w(e,f.image(l[e],l.permalink))}function w(e,t){r[e].val(t)}var n=$("#preview-sharing"),r={permalink:$("#preview-sharing-permalink-url"),large_image:$("#preview-sharing-large-image-url"),medium_image:$("#preview-sharing-medium-image-url"),small_image:$("#preview-sharing-small-image-url")},i=$("#preview-sharing-url-formats li"),s=$("#preview-sharing-thumbnail"),o={html:{image:$("#sharing-html-image-template"),text:$("#sharing-html-text-template")},bbcode:{image:$("#sharing-bbcode-image-template"),text:$("#sharing-bbcode-text-template")}},a={plain:{image:function(e){return e},text:function(e){return e}},html:{image:function(e,t){return u(o.html.image,{image_url:e,permalink:t})},text:function(e){return u(o.html.text,{permalink:e})}},bbcode:{image:function(e,t){return u(o.bbcode.image,{image_url:e,permalink:t})},text:function(e){return u(o.bbcode.text,{permalink:e})}}},f=a.plain,l={permalink:null,small_image:null,medium_image:null,large_image:null};i.click(function(){var e=$(this);i.removeClass("active"),e.addClass("active"),log("Setting sharing URL format:",e.attr("data-format")),f=a[e.attr("data-format")],g()});var c=null,m={id:null};this.setOutfit=function(t){if(!t.id)return P.startLoading(),e.outfits.share(t),!1;t.id!=m.id&&(m=t.clone(),l.permalink=L(t),l.small_image=k(t.image_versions.small),l.medium_image=k(t.image_versions.medium),l.large_image=k(t.image_versions.large),g(),n.removeClass("thumbnail-available"),v(m)),n.addClass("urls-loaded")},this.startLoading=function(){n.removeClass("urls-loaded")},this.onHide=function(){h()},this.onShow=function(){v(e.outfits.getOutfit())},e.image_subscriptions.bind("imageEnqueued",function(e){e.id==m.id&&(log("Sharing thumbnail enqueued for outfit",e),n.removeClass("thumbnail-loaded"))}),e.image_subscriptions.bind("imageReady",function(e){if(e.id==m.id){log("Sharing thumbnail ready for outfit",e);var t=e.image_versions.small+"?"+e.image_layers_hash;s.attr("src",t),n.addClass("thumbnail-loaded"),n.addClass("thumbnail-available"),h(e)}}),e.outfits.bind("updateSuccess",function(e){p.hasClass("sharing")&&d(e)}),e.outfits.bind("setOutfit",function(e){log("Sharing sees the setOutfit signal, and will set",e),P.setOutfit(e)})};u.click(function(){e.outfits.update()}),n.submit(function(t){t.preventDefault(),n.startLoading(),e.outfits.create({starred:n.hasClass("starred"),name:r.val()})}),n.find("div.outfit-star").click(function(){n.toggleClass("starred")}),e.outfits.bind("saveSuccess",function(e){l.notify()}),e.outfits.bind("createSuccess",function(e){b(),S()}),e.outfits.bind("shareSuccess",B),e.outfits.bind("shareSkipped",B),e.outfits.bind("updateClosetItems",j),e.outfits.bind("updateWornItems",j),e.outfits.bind("updatePetState",j),e.outfits.bind("saveFailure",F),e.outfits.bind("saveFailure",F),e.outfits.bind("shareFailure",function(e,t){f.stopLoading(),F(e,t)}),e.outfits.bind("outfitNotFound",function(){o.notify()})},View.PetStateForm=function(e){function s(e){e&&i.val(e.id)}var t="pet_state_id",n="#pet-state-form",r=$(n),i=r.children("select");i.change(function(t){var n=parseInt(i.children(":selected").val(),10);e.outfits.setPetStateById(n)}),e.outfits.bind("petTypeLoaded",function(t){var n=t.pet_states,o,u,a;i.children().remove();if(n.length==1)r.addClass("hidden");else{r.removeClass("hidden");for(var o=0;o<n.length;o++)u="pet-state-button-"+o,a=$("<option/>",{value:n[o].id,text:n[o].gender_mood_description}),a.appendTo(i);s(e.outfits.getPetState())}}),e.outfits.bind("updatePetState",s)},View.PetTypeForm=function(e){function i(e){r&&e&&$.each(n,function(t){n[t].val(e[t+"_id"])})}var t=$("#pet-type-form"),n={},r=!1;t.submit(function(t){t.preventDefault(),e.outfits.setPetTypeByColorAndSpecies(+n.color.val(),+n.species.val())}).children("select").each(function(){n[this.name]=$(this)}),this.initialize=function(){e.pet_attributes.load()},e.pet_attributes.bind("update",function(t){$.each(t,function(e){var t=n[e];$.each(this,function(){var e=$("<option/>",{text:this.name,value:this.id});e.appendTo(t)})}),r=!0,i(e.outfits.getPetType())}),e.outfits.bind("updatePetType",i),e.outfits.bind("petTypeNotFound",function(){$("#pet-type-not-found").show("normal").delay(3e3).hide("fast")})},View.PreviewAdapterForm=function(e){function s(e,t,n){r.removeClass(n+"-active").addClass(t+"-active"),$(e).addClass("active")}var t=e.views.Preview,n=function(){var e={addEvent:function(e,t,n,r){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&(e["e"+t+n]=n,e[t+n]=function(){e["e"+t+n](window.event,r)},e.attachEvent("on"+t,e[t+n]))},input:"",pattern:"3838404037393739666513",load:function(t){this.addEvent(document,"keydown",function(n,r){r&&(e=r),e.input+=n?n.keyCode:event.keyCode,e.input.indexOf(e.pattern)!=-1&&(e.code(t),e.input="")},this),this.iphone.load(t)},code:function(e){window.location=e},iphone:{start_x:0,start_y:0,stop_x:0,stop_y:0,tap:!1,capture:!1,keys:["UP","UP","DOWN","DOWN","LEFT","RIGHT","LEFT","RIGHT","TAP","TAP","TAP"],code:function(t){e.code(t)},load:function(t){e.addEvent(document,"touchmove",function(t){t.touches.length==1&&e.iphone.capture==1&&(t=t.touches[0],e.iphone.stop_x=t.pageX,e.iphone.stop_y=t.pageY,e.iphone.tap=!1,e.iphone.capture=!1,e.iphone.check_direction())}),e.addEvent(document,"touchend",function(){e.iphone.tap==1&&e.iphone.check_direction(t)},!1),e.addEvent(document,"touchstart",function(t){e.iphone.start_x=t.changedTouches[0].pageX,e.iphone.start_y=t.changedTouches[0].pageY,e.iphone.tap=!0,e.iphone.capture=!0})},check_direction:function(e){x_magnitude=Math.abs(this.start_x-this.stop_x),y_magnitude=Math.abs(this.start_y-this.stop_y),x=this.start_x-this.stop_x<0?"RIGHT":"LEFT",y=this.start_y-this.stop_y<0?"DOWN":"UP",result=x_magnitude>y_magnitude?x:y,result=this.tap==1?"TAP":result,result==this.keys[0]&&(this.keys=this.keys.slice(1,this.keys.length)),this.keys.length==0&&this.code(e)}}};return e};konami=new n,konami.code=function(){t.toggleAdapter()},konami.load();var r=$("#preview-mode").addClass("flash-active"),i=$("#preview-mode-toggle li"),o=$("#preview-mode-flash").click(function(){s(this,"flash","image"),t.useSWFAdapter()}),u=$("#preview-mode-image").click(function(){s(this,"image","flash"),t.useImageAdapter()});t.usingImageAdapter()&&s(u,"image","flash")},View.ReportBrokenImage=function(e){function r(){var r=e.outfits.getVisibleAssets(),i=n+"?";for(var s=0;s<r.length;s++)s>0&&(i+="&"),i+="asset_ids["+r[s].type+"][]="+r[s].id;t.attr("href",i)}var t=$("#report-broken-image"),n=t.attr("data-base-url");e.outfits.bind("updateWornItems",r),e.outfits.bind("updateItemAssets",r),e.outfits.bind("updatePetState",r)},View.Search=function(e){function v(){var t=Math.floor(n.width()/p),r,i;$(document.body).hasClass("fullscreen")||(t*=4),t!=h.PER_PAGE&&(h.PER_PAGE=t,e.search.setPerPage(h.PER_PAGE),d&&m(d.offset))}function m(t){e.search.setItemsByQuery(i.val(),{offset:t})}function g(t){e.search.setItemsByQuery(i.val(),{page:t})}function y(){a.stop(!0,!0).hide()}function b(e,t){return function(n){var r=$("span.search-helper[data-search-filter-key="+e+"]"),i=r.attr("data-search-filter-name"),s=$("<select/>",{"class":"search-helper","data-search-filter":i}),o=r.get(0).innerText;n=t(n);for(var u=0,a=n.length;u<a;u++)$("<option/>",{text:n[u].name}).appendTo(s);r.replaceWith(function(){return s.clone().fadeIn("fast")}),$("select.search-helper[data-search-filter="+i+"] option").each(function(){this.innerText==o&&(this.selected="selected")})}}function w(e){return e.species}var t="#preview-search-form",n=$(t),r=new Partial.ItemSet(e,t+" ul"),i=n.find("input[name=query]"),s=$("#preview-search-form-clear"),o=$("#preview-search-form-error"),u=$("#preview-search-form-help"),a=$("#preview-search-form-loading"),f=$("#preview-search-form-no-results"),l=f.children("span"),c=$(".preview-search-form-your-items"),h={INNER_WINDOW:4,OUTER_WINDOW:1,EL_ID:"#preview-search-form-pagination",PER_PAGE:21,TEMPLATE:$("#pagination-template")},p=112,d;h.EL=$(h.EL_ID),$(h.EL_ID+" a").live("click",function(e){e.preventDefault(),g($(this).data("page"))}),this.initialize=$.proxy(e.item_zone_sets,"load"),e.search.setPerPage(h.PER_PAGE),$(window).resize(v).load(v),v(),n.submit(function(e){e.preventDefault(),g(1)}),s.click(function(e){e.preventDefault(),i.val(""),n.submit()}),c.click(function(e){e.preventDefault(),i.val("user:"+this.getAttribute("data-search-value")),n.submit()}),e.search.bind("startRequest",function(){a.delay(1e3).show("slow")}),e.search.bind("updateItems",function(t){var i=$("#preview").data("fit")||$.noop;y(),r.setItems(t),e.search.request.query?t.length||f.show():u.show(),n.toggleClass("has-results",t.length>0),i()}),e.search.bind("updateRequest",function(e){d=e,o.hide("fast"),u.hide(),f.hide(),i.val(e.query||""),l.text(e.query),s.toggle(!!e.query)}),e.search.bind("updatePagination",function(e,t){var n=e-h.INNER_WINDOW,r=e+h.INNER_WINDOW,i=[],s,o,u,a,f=1;r>t&&(n-=r-t,r=t),n<1&&(r+=1-n,n=1,r>t&&(r=t)),s=[2+h.OUTER_WINDOW,n],o=[r+1,t-h.OUTER_WINDOW],u=s[1]-s[0]>1,a=o[1]-o[0]>1;var l=[];while(f<=t)u&&f>=s[0]&&f<s[1]?(l.push("gap"),f=s[1]):a&&f>=o[0]&&f<o[1]?(l.push("gap"),f=o[1]):(l.push(f),f++);h.EL.empty(),h.TEMPLATE.tmpl({current_page:e,total_pages:t,pages:l}).appendTo(h.EL)}),e.search.bind("error",function(e){y(),o.text(e).show("normal")}),u.find("dt").each(function(){var e=$(this);e.children().length||e.wrapInner($("<a/>",{href:"#"}))}).children("span:not(.search-helper)").each(function(){var e=$(this);e.replaceWith($("<a/>",{href:"#",text:e.text()}))}),u.find("dt a").live("click",function(e){var t=$(this),r=t.parent().contents(),s;e.preventDefault(),r.length>1?(s=r.map(function(){var e=$(this);return e[e.is("select")?"val":"text"]()}).get().join(""),s=$.trim(s)):s=t.text(),i.val(s),n.submit()}),$("select.search-helper").live("change",function(){var e=$(this),t=e.attr("data-search-filter");$("select.search-helper[data-search-filter="+t+"]").val(e.val())}),e.item_zone_sets.bind("update",b("occupies",function(e){return e})),e.pet_attributes.bind("update",b("species",w))};var userbar_sessions_link=$("#userbar a:last"),userbar_message_el=$("#userbar-session-message").prependTo("#userbar");userbar_sessions_link.hover(function(){userbar_message_el.stop().fadeTo("normal",.5)},function(){userbar_message_el.stop().fadeOut("fast")});var localeForm=$("#locale-form");localeForm.submit(function(e){var t=document.location.pathname+document.location.search+document.location.hash;localeForm.find("input[name=return_to]").val(t)}),$.ajaxSetup({error:function(e){$.jGrowl("There was an error loading that last resource. Oops. Please try again!")}}),main_wardrobe=new Wardrobe,main_wardrobe.registerViews(View),main_wardrobe.initialize();var TIME_TO_DONATION_REQUEST_IN_MINUTES=10,donationRequestEl=$("#preview-sidebar-donation-request");donationRequestEl.find("a").click(function(e){donationRequestEl.slideUp(250);var t=this.id=="preview-sidebar-donation-request-no-thanks"?0:1;t||e.preventDefault();var n=new Date;n.setTime(n.getTime()+6048e5),document.cookie="previewSidebarDonationResponse="+t+"; expires="+n.toGMTString()}),document.cookie.indexOf("previewSidebarDonationResponse")==-1&&setTimeout(function(){donationRequestEl.slideDown(1e3)},TIME_TO_DONATION_REQUEST_IN_MINUTES*60*1e3); |