impress/public/assets/wardrobe.js

1 line
No EOL
21 KiB
JavaScript

function arraysMatch(e,t){var n;if(!$.isArray(e)||!$.isArray(t))return e==t;n=[];if(e.length!=t.length)return!1;for(var r=0;r<e.length;r++)key=typeof e[r]+"~"+e[r],n[key]?n[key]++:n[key]=1;for(var r=0;r<t.length;r++){key=typeof t[r]+"~"+t[r];if(!n[key])return!1;if(n[key]==0)return!1;n[key]--}return!0}function DeepObject(){}function Wardrobe(){function r(){var e,t;this.restricted_zones=[];while((t=this.zones_restrict.indexOf(1,t)+1)!=0)this.restricted_zones.push(t)}function i(e){function n(e){return e[0]+"x"+e[1]}var t=this;this.image_urls_by_size_key={};var r;for(var i=0;i<e.images.length;i++)r=e.images[i],this.image_urls_by_size_key[n(r.size)]=r.url;this.imageURL=function(e){return this.image_urls_by_size_key[n(e)]},this.update=function(e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},this.update(e)}function t(e){i.apply(this,[e]),r.apply(this)}function n(e){i.apply(this,[e])}function s(e){function n(){return t.name.toLowerCase().replace(/ /g,"-").replace(/[^a-z0-9\-]/i,"")}function i(){var e=t.id.toString();return t.hasOwnProperty("name")&&(e+="-"+n()),e}var t=this;this.id=e,this.assets_by_body_id={},this.load_started=!1,this.loaded=!1,this.getAssetsFitting=function(e){return this.assets_by_body_id[e.body_id]||[]},this.hasAssetsFitting=function(e){return typeof t.assets_by_body_id[e.body_id]!="undefined"&&t.assets_by_body_id[e.body_id].length>0},this.couldNotLoadAssetsFitting=function(e){return typeof t.assets_by_body_id[e.body_id]!="undefined"&&t.assets_by_body_id[e.body_id].length==0},this.update=function(e){for(var n in e)e.hasOwnProperty(n)&&n!="id"&&(t[n]=e[n]);r.apply(this),this.loaded=!0},this.getURL=function(){return"/items/"+i()},s.cache[e]=this}function u(e){this.name=e}function a(e){function u(e){t.color_id=e.color_id,t.id=e.id,t.name=e.name,t.pet_state_id=e.pet_state_id,t.starred=e.starred,t.species_id=e.species_id,t.image_versions=e.image_versions,t.image_enqueued=e.image_enqueued,t.image_layers_hash=e.image_layers_hash,t.setWornAndUnwornItemIds(e.worn_and_unworn_item_ids),o=!1}function f(){var e={};return e.name=t.name,e.starred=t.starred,e.worn_and_unworn_item_ids=t.getWornAndUnwornItemIds(),t.pet_state&&(e.pet_state_id=t.pet_state.id),e.anonymous=t.anonymous,e}function h(){var e=[],n=t.worn_items;return t.pet_state&&(n=n.concat(t.pet_state.assets)),$.each(n,function(){e=e.concat(this.restricted_zones)}),e}function p(e){return $.inArray(e,t.closet_items)!=-1}function d(e){return $.inArray(e,t.worn_items)!=-1}function v(e,n,i){var s,o,u,a,f,l=[],c=[];if(e){s=e.getAssetsFitting(t.pet_type).mapProperty("zone_id"),o=s.length;for(var h=0;h<t.worn_items.length;h++){u=t.worn_items[h],a=u.getAssetsFitting(t.pet_type).mapProperty("zone_id"),f=!0;if(u!=e)for(var p=0;p<o;p++)if($.inArray(s[p],a)!=-1){f=!1;break}f&&(l.push(u),c.push(u.id))}t.worn_items=l,r=c,n(t.worn_items)}i()}function m(e,n,r,i,s){(!t.pet_state||!e.ownsPetState(t.pet_state))&&t.setPetStateById(null,r),n(e),g(null,i,s)}function g(e,n,i){t.pet_type&&t.pet_type.loaded&&r.length&&t.pet_type.loadItemAssets(r,function(){v(e,n,i)})}function y(e){t.id=e.id,t.image_versions=e.image_versions,t.image_enqueued=e.image_enqueued,t.image_layers_hash=e.image_layers_hash}function b(e,n,r){$.ajax({url:"/outfits/"+t.id,type:"post",data:{_method:"put",outfit:e},dataType:"json",success:function(e){y(e),a.cache[t.id]=t,n(t)},error:function(e){typeof r!="undefined"&&r(t,$.parseJSON(e.responseText))}})}var t=this,n,r=[],i=[],o=!0;this.setWornAndUnwornItemIds=function(e){this.worn_and_unworn_item_ids=e,r=e.worn,i=e.unworn.concat(e.worn)},typeof e!="undefined"&&u(e),this.closet_items=[],this.worn_items=[],this.anonymous=!1,this.getWornItemIds=function(){return r},this.getClosetItemIds=function(){return i},this.closetItem=function(e,t){p(e)||(this.closet_items.push(e),i.push(e.id),t(this.closet_items))},this.getPetStateId=function(){return typeof t.pet_state_id=="undefined"&&(t.pet_state_id=t.pet_state.id),t.pet_state_id},this.getVisibleAssets=function(){var e,n=h(),r=[];e=this.pet_state?this.pet_state.assets:[];for(var i=0;i<t.worn_items.length;i++)e=e.concat(t.worn_items[i].getAssetsFitting(t.pet_type));return $.each(e,function(){$.inArray(this.zone_id,n)==-1&&r.push(this)}),r},this.isIdenticalTo=function(e){return e&&this.constructor==e.constructor&&this.getPetStateId()==e.getPetStateId()&&arraysMatch(this.getWornItemIds(),e.getWornItemIds())&&arraysMatch(this.getClosetItemIds(),e.getClosetItemIds())},this.rename=function(e,t,n){this.updateAttributes({name:e},t,n)},this.setClosetItemsByIds=function(e,n){e&&(i=e),e&&e.length?s.loadByIds(e,function(e){t.closet_items=e,n(e)}):(this.closet_items=[],n(this.closet_items))},this.setPetStateById=function(e,t){!e&&this.pet_type&&(e=this.pet_type.pet_states[0].id),e&&(this.pet_state=l.find(e),this.pet_state_id=e,this.pet_state.loadAssets(t))},this.setPetTypeByColorAndSpecies=function(e,t,n,r,i,s,o,u){this.pet_type=c.findOrCreateByColorAndSpecies(e,t),this.color_id=e,this.species_id=t,n(this.pet_type),this.pet_type.load(function(e){m(e,r,s,o,u)},i)},this.setWornItemsByIds=function(e,t,n){e&&(r=e),e&&e.length?this.worn_items=s.loadByIds(e,t):(this.worn_items=[],t(this.worn_items)),g(null,t,n)},this.toggleStar=function(e){this.updateAttributes({starred:!t.starred},e)},this.unclosetItem=function(e,t,n){var r=$.inArray(e,this.closet_items),s;r!=-1&&(this.closet_items.splice(r,1),s=$.inArray(e.id,i),i.splice(s,1),t(this.closet_items),this.unwearItem(e,n))},this.unwearItem=function(e,t){var n=$.inArray(e,this.worn_items),i;n!=-1&&(this.worn_items.splice(n,1),i=$.inArray(e.id,r),r.splice(i,1),t(this.worn_items))},this.update=function(e,t){b(f(),e,t)},this.wearItem=function(e,t,n,i){d(e)||(this.worn_items.push(e),r.push(e.id),this.closetItem(e,n),i&&g(e,t,i),t(this.worn_items))},this.getWornAndUnwornItemIds=function(){var e=[],n;for(var s=0;s<i.length;s++)n=i[s],$.inArray(n,r)===-1&&e.push(n);return t.worn_and_unworn_item_ids={worn:r,unworn:e},t.worn_and_unworn_item_ids},this.clone=function(){var e=new a;return e.cloneAttributesFrom(t),e.id=t.id,e.name=t.name,e.starred=t.starred,e.image_enqueued=t.image_enqueued,e.image_versions=t.image_versions,e.image_layers_hash=t.image_layers_hash,e},this.cloneAttributesFrom=function(e){var n=e.getWornAndUnwornItemIds(),r={};t.color_id=e.color_id,t.species_id=e.species_id,t.pet_state_id=e.getPetStateId(),t.pet_state=e.pet_state,t.pet_type=e.pet_type,t.closet_items=e.closet_items.slice(0),t.worn_items=e.worn_items.slice(0),r.worn=n.worn.slice(0),r.unworn=n.unworn.slice(0),t.setWornAndUnwornItemIds(r)},this.destroy=function(e){$.ajax({url:"/outfits/"+t.id+".json",type:"post",data:{_method:"delete"},success:function(){e(t)}})},this.create=function(e,n){$.ajax({url:"/outfits",type:"post",data:{outfit:f()},dataType:"json",success:function(n){o=!1,y(n),a.cache[t.id]=t,e(t)},error:function(e){n(t,$.parseJSON(e.responseText))}})},this.reload=function(e){a.load(this.id,function(n){u(n),e(t)})},this.updateAttributes=function(e,n,r){var i={};for(var s in e)e.hasOwnProperty(s)&&(i[s]=t[s]=e[s]);b(i,n,r)}}function f(){}function l(e){var n=this,r=!1;this.id=e,this.gender_mood_description="",this.assets=[],this.loadAssets=function(e){var i;r?e(n):$.getJSON("/pet_states/"+n.id+"/swf_assets.json",function(i){n.assets=$.map(i,function(e){return new t(e)}),r=!0,e(n)})},this.update=function(e){this.gender_mood_description=e.gender_mood_description},l.cache[e]=this}function c(){var e=this;this.loaded=!1,this.pet_states=[],this.load=function(t,n){e.loaded?t(e):$.getJSON("/species/"+e.species_id+"/color/"+e.color_id+"/pet_type.json",{"for":"wardrobe"},function(r){if(r){e.id=r.id,e.body_id=r.body_id;var i;for(var s=0;s<r.pet_states.length;s++)i=l.buildOrUpdate(r.pet_states[s]),e.pet_states.push(i);c.cache_by_color_and_species.deepSet(e.color_id,e.species_id,e),e.loaded=!0,t(e)}else n(e)})},this.loadItemAssets=function(t,r){var i=[];for(var o=0;o<t.length;o++){var u=t[o],a=s.find(u);a.hasAssetsFitting(e)||i.push(u)}i.length?$.getJSON("/pet_types/"+e.id+"/items/swf_assets.json",{item_ids:i},function(i){var o;$.each(i,function(){var t=s.find(this.parent_id),r=new n(this);typeof t.assets_by_body_id[e.body_id]=="undefined"&&(t.assets_by_body_id[e.body_id]=[]),t.assets_by_body_id[e.body_id].push(r)});for(var u=0,a=t.length;u<a;u++)o=s.find(t[u]),o.hasAssetsFitting(e)||(o.assets_by_body_id[e.body_id]=[]);r()}):r()},this.toString=function(){return"PetType{color_id: "+this.color_id+", species_id: "+this.species_id+"}"},this.ownsPetState=function(e){for(var t=0;t<this.pet_states.length;t++)if(this.pet_states[t]==e)return!0;return!1}}function h(){function t(t,n){var r=e.events[t];if(typeof r!="undefined")for(var i=0;i<r.length;i++)r[i].apply(e,n)}var e=this;this.events={},this.bind=function(e,t){typeof this.events[e]=="undefined"&&(this.events[e]=[]),this.events[e].push(t)},this.event=function(e){return function(){t(e,arguments)}},this.events.trigger=function(n){var r,i;e.events[n]&&(r=Array.prototype.slice.apply(arguments,[1]),t(n,r))}}var e=this,t,n;s.find=function(e){var t=s.cache[e];return t||(t=new s(e)),t};var o=[];s.loadByIds=function(e,t){var n=[],r=[],i=$.map(e,function(e){var t=s.find(e);return t.load_started||(n.push(e),t.load_started=!0),t.loaded||r.push(e),t});return n.length?$.getJSON("/items.json",{ids:n},function(e){var n,r,u,a,f,l=[];$.each(e,function(){l.push(+this.id),s.find(this.id).update(this)});for(var c=0;c<o.length;c++){n=o[c],r=n[0],u=n[1],a=n[2],f=!0;for(var h=0;h<u.length;h++)if($.inArray(u[h],l)==-1){f=!1;break}f&&a(r)}t(i)}):r.length?o.push([i,r,t]):t(i),i},s.PER_PAGE=21,s.loadByQuery=function(e,t,n,r){var i=Math.round(t/s.PER_PAGE)+1;$.ajax({url:"/items.json",data:{q:e,per_page:s.PER_PAGE,page:i},dataType:"json",success:function(e){var t=[],o,u;if(e.items){for(var a=0;a<e.items.length;a++)u=e.items[a],o=s.find(u.id),o.update(u),t.push(o);n(t,e.total_pages,i)}else e.error&&r(e.error)},error:function(e){try{var t=$.parseJSON(e.responseText)}catch(n){return $.jGrowl("There was an error running that search, probably on our end. Try again?"),!1}t.error&&r(t.error)}})},s.cache={},u.loadAll=function(e){$.getJSON("/item_zone_sets.json",function(t){for(var n=0,r=t.length;n<r;n++)u.all.push(new u(t[n]));e(u.all)})},u.all=[],a.cache={},a.find=function(e,t){typeof a.cache[e]!="undefined"?t(a.cache[e]):a.load(e,t)},a.load=function(e,t){$.ajax({url:"/outfits/"+e+".json",success:function(n){var r=new a(n);a.cache[e]=r,t(r)},error:function(){t(null)}})},a.loadForCurrentUser=function(e){var t=[];$.getJSON("/users/current-user/outfits.json",function(n){var r,i,s;for(var s=0;s<n.length;s++)r=n[s],i=new a(r),t.push(i),a.cache[r.id]=i;e(t)})},f.loadAll=function(e){$.getJSON("/pet_attributes.json",function(t){e(t)})},l.find=function(e){var t=l.cache[e];return t||(t=new l(e)),t},l.buildOrUpdate=function(e){var t=l.find(e.id);return t.update(e),t},l.cache={},c.cache_by_color_and_species=new DeepObject,c.findOrCreateByColorAndSpecies=function(e,t){var n=c.cache_by_color_and_species.deepGet(e,t);return n||(n=new c,n.color_id=e,n.species_id=t),n},h.all={},h.all.Outfits=function(){function i(e){n=e,t.in_transaction=!0,t.setPetStateById(n.pet_state_id),t.setPetTypeByColorAndSpecies(n.color_id,n.species_id),t.setClosetItemsByIds(n.getClosetItemIds()),t.setWornItemsByIds(n.getWornItemIds()),t.events.trigger("setOutfit",n),t.in_transaction=!1,t.events.trigger("loadOutfit",n)}function s(e){e.cloneAttributesFrom(n),n=e}function f(e,t){if(e.starred){if(!t.starred)return-1}else if(t.starred)return 1;return e.name<t.name?-1:e.name==t.name?0:1}function l(e){for(var n=0;n<o.length;n++)if(f(e,o[n])<0){o.splice(n,0,e),t.events.trigger("addOutfit",e,n);return}t.events.trigger("addOutfit",e,o.length),o.push(e)}function c(e){e.sort(f)}function h(e){var n;for(n=0;n<o.length;n++)if(e.id==o[n].id){o.splice(n,1);break}t.events.trigger("removeOutfit",e,n)}function p(e){for(var t=0;t<o.length;t++)if(o[t].id==e.id){o[t]=e.clone();break}}var t=this,n=new a,r=null;this.in_transaction=!1,this.closetItem=function(e){n.closetItem(e,t.event("updateClosetItems"))},this.getClosetItems=function(){return n.closet_items},this.getId=function(){return n.id},this.getOutfit=function(){return n},this.getPetState=function(){return n.pet_state},this.getPetType=function(){return n.pet_type},this.getVisibleAssets=function(){return n.getVisibleAssets()},this.getWornItems=function(){return n.worn_items},this.load=function(e){a.find(e,function(e){i(e.clone())})},this.loadData=function(e){i(new a(e))},this.create=function(e){e&&(n.starred=e.starred,n.name=e.name),n.create(function(e){l(e),t.events.trigger("saveSuccess",e),t.events.trigger("createSuccess",e),t.events.trigger("setOutfit",e)},t.event("saveFailure"))},this.setClosetItemsByIds=function(e){n.setClosetItemsByIds(e,t.event("updateClosetItems"))},this.setId=function(e){e?a.find(e,function(e){e?(s(e),t.events.trigger("setOutfit",n)):t.events.trigger("outfitNotFound",n)}):(s(new a),t.events.trigger("setOutfit",n))},this.setPetStateById=function(e){n.setPetStateById(e,t.event("updatePetState"))},this.setPetTypeByColorAndSpecies=function(e,r){n.setPetTypeByColorAndSpecies(e,r,t.event("updatePetType"),t.event("petTypeLoaded"),t.event("petTypeNotFound"),t.event("updatePetState"),t.event("updateWornItems"),t.event("updateItemAssets"))},this.setWornItemsByIds=function(e){n.setWornItemsByIds(e,t.event("updateWornItems"),t.event("updateItemAssets"))},this.share=function(){n.id?t.events.trigger("shareSkipped",n):n.isIdenticalTo(r)?t.events.trigger("shareSkipped",r):(r=n.clone(),r.anonymous=!0,r.create(t.event("shareSuccess"),t.event("shareFailure")))},this.unclosetItem=function(e){n.unclosetItem(e,t.event("updateClosetItems"),t.event("updateWornItems"))},this.unwearItem=function(e){n.unwearItem(e,t.event("updateWornItems"))},this.update=function(){n.update(function(e){p(e),t.events.trigger("saveSuccess",e),t.events.trigger("updateSuccess",e)},t.event("saveFailure"))},this.wearItem=function(e){n.wearItem(e,t.event("updateWornItems"),t.event("updateClosetItems"),t.event("updateItemAssets"))};var o=[],u=!1;this.destroyOutfit=function(e){e.destroy(function(){h(e)})},this.loadOutfits=function(){u||a.loadForCurrentUser(function(e){o=e,u=!0,c(o),t.events.trigger("outfitsLoaded",o)})},this.renameOutfit=function(e,n){var r=e.name;e.rename(n,function(){h(e),l(e),t.events.trigger("outfitRenamed",e)},function(n,i){e.name=r,t.events.trigger("saveFailure",n,i)})},this.toggleOutfitStar=function(e){e.toggleStar(function(){h(e),l(e),t.events.trigger("outfitStarToggled",e)})}},h.all.ImageSubscriptions=function(){function i(e){a.find(e,function(s){log("Checking image for",s),s.reload(function(){t[e]>0?s.image_enqueued?(log("Outfit image still enqueued; will try again soon",s),setTimeout(function(){i(e)},n)):(delete t[e],r.events.trigger("imageReady",s)):(log("Outfit was unsubscribed",s),delete t[e])})})}var t={},n=5e3,r=this;this.subscribe=function(e){return e.image_enqueued?(e.id in t?t[e.id]+=1:(t[e.id]=1,i(e.id)),r.events.trigger("imageEnqueued",e)):setTimeout(function(){r.events.trigger("imageReady",e)},0),e},this.unsubscribe=function(e){e&&e.id in t&&(t[e.id]>1?t[e.id]-=1:delete t[e.id])}},h.all.BasePet=function(){var t=this;this.setName=function(e){t.name=e,t.events.trigger("updateName",e)}},h.all.PetAttributes=function(){function n(e){t.events.trigger("update",e)}var t=this;this.load=function(){f.loadAll(n)}},h.all.ItemZoneSets=function(){function n(e){t.events.trigger("update",e)}var t=this;this.load=function(){u.loadAll(n)}},h.all.Search=function(){function n(e,n,r){t.events.trigger("updateItems",e),t.events.trigger("updatePagination",r,n)}function r(e){t.events.trigger("error",e)}var t=this;this.request={},this.setItemsByQuery=function(e,i){var o=typeof i.offset!="undefined"?i.offset:s.PER_PAGE*(i.page-1);t.request={query:e,offset:o},t.events.trigger("updateRequest",t.request),e?(s.loadByQuery(e,o,n,r),t.events.trigger("startRequest")):(t.events.trigger("updateItems",[]),t.events.trigger("updatePagination",0,0))},this.setPerPage=function(e){s.PER_PAGE=e}};var p;for(var d in h.all)h.all.hasOwnProperty(d)&&(p=d.replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").toLowerCase(),e[p]=new h.all[d],h.apply(e[p]));this.initialize=function(){var t;for(var n in e.views)e.views.hasOwnProperty(n)&&(t=e.views[n],typeof t.initialize=="function"&&t.initialize())},this.registerViews=function(t){e.views={},$.each(t,function(t){e.views[t]=new this(e)})}}window.log=window.SWFLog=$.noop,Array.prototype.mapProperty=function(e){return $.map(this,function(t){return t[e]})},DeepObject.prototype.deepGet=function(){var e=this,t;return $.each(arguments,function(){e=e[this];if(typeof e=="undefined")return!1}),e},DeepObject.prototype.deepSet=function(){var e=$.proxy(Array.prototype.pop,"apply"),t=e(arguments),n=e(arguments),r=this;$.each(arguments,function(){typeof r[this]=="undefined"&&(r[this]={}),r=r[this]}),r[n]=t},Wardrobe.IMAGE_CONFIG={base_url:"https://s3.amazonaws.com/impress-asset-images/",sizes:[[600,600],[300,300],[150,150]]},Wardrobe.StandardPreview={views_by_swf_id:{}},Wardrobe.getStandardView=function(e){function n(){var t,n=[],r=e;for(var i=0;i<arguments.length;i++){t=arguments[i],n.push(t),r=r[t];if(typeof r=="undefined")throw"Options for Wardrobe.getStandardView must include "+n.join(".")}}var t={};return n("Preview","swf_url"),n("Preview","wrapper"),n("Preview","placeholder"),document.location.search.substr(0,6)=="?debug"&&(t.Console=function(e){typeof console!="undefined"&&typeof console.log=="function"&&(window.log=$.proxy(console,"log")),this.initialize=function(){log("Welcome to the Wardrobe!")};var t=["updateWornItems","updateClosetItems","updateItemAssets","updatePetType","updatePetState"];for(var n=0;n<t.length;n++)(function(t){e.outfits.bind(t,function(e){log(t,e)})})(t[n]);e.outfits.bind("petTypeNotFound",function(e){log(e.toString()+" not found")})}),t.Preview=function(t){function o(){n.adapter.updateAssets()}function u(e){n.adapter=new s[e],o();var t=new Date;t.setTime(t.getTime()+31536e6),document.cookie="previewAdapter="+e+"; expires="+t.toGMTString()}var n=this,r=$(e.Preview.wrapper),i=$(e.Preview.placeholder),s={};s.SWF=function(){var n=i.attr("id"),s,o=!1;r.removeClass("image-adapter").addClass("swf-adapter"),swfobject.embedSWF(e.Preview.swf_url,n,"100%","100%","9","/assets/js/swfobject/expressInstall.swf",{id:n},{wmode:"transparent"}),Wardrobe.StandardPreview.views_by_swf_id[n]=this,this.previewSWFIsReady=function(){s=document.getElementById(n),o&&(o=!1,this.updateAssets())},this.updateAssets=function(){var e,n;if(o)return!1;s&&s.setAssets?(e=t.outfits.getVisibleAssets(),s.setAssets(e)):o=!0}},s.Image=function(){function h(e){var t=e.depth,n;a.children("img").each(function(){var e=$(this);if(e.css("zIndex")>t)return n=e,!1});var r=$("<img/>",{css:{zIndex:t},src:e.imageURL(b())});n?r.insertBefore(n):r.appendTo(a)}function b(){var e=d,t=r.width(),n=r.height();for(var i in e)if(e[i][0]>t&&e[i][1]>n)return y=e[i];return y=e[e.length-1]}function w(){a.children("img").remove()}function E(){var e={biology:[],object:[]},t;for(var r in n)n.hasOwnProperty(r)&&e[n[r].type].push(n[r].id);$.getJSON("/swf_assets.json",{ids:e},function(e){var t,r;for(var i in e)t=e[i],t.has_image&&n.hasOwnProperty(t.id)&&(r=n[t.id],r.update(t),delete n[t.id],o--,h(r));T()})}function S(){o?s==null&&(s=setInterval(E,f)):s!=null&&(clearInterval(s),s=null)}function x(){u.text("Waiting on "+o+" images").attr("className","waiting-on-"+o)}function T(){S(),x()}var n={},i=[],s,o=0,u=$("<span/>",{id:"preview-images-pending"}),a=$(e.Preview.image_container),f=5e3;r.removeClass("swf-adapter").addClass("image-adapter"),u.appendTo(a);var l=this,c=$("#preview-export-iframe");c.length==0&&(c=$("<iframe/>",{id:"preview-export-iframe",src:"about:blank",css:{left:-1e3,position:"absolute",top:-1e3,width:300,height:300}}).appendTo(document.body)),this.saveImage=function(e){var n=Wardrobe.IMAGE_CONFIG.base_url+"preview_export.html?"+e[0]+","+e[1],r=t.outfits.getVisibleAssets().slice(0);r.sort(function(e,t){return e.depth-t.depth}),console.log(r.mapProperty("id"));return},this.updateAssets=function(){var e=t.outfits.getVisibleAssets(),r,i=[];n={},o=0,w();for(var s in e){if(!e.hasOwnProperty(s))continue;r=e[s],r.has_image?h(r):(n[r.id]=r,o++)}T()};var p=Wardrobe.IMAGE_CONFIG.sizes,d=[],v,m;for(var g in p){if(!p.hasOwnProperty(g))continue;v=p[g],m=!1;for(var g in d)if(d[g][0]*d[g][1]>v[0]*v[1]){d.splice(g,0,v),m=!0;break}m||(d[d.length]=v)}var y;$(window).resize(function(){y!=b()&&l.updateAssets()})},typeof e.Preview.image_container=="undefined"||document.cookie.indexOf("previewAdapter=Image")==-1?this.adapter=new s.SWF:this.adapter=new s.Image,t.outfits.bind("updateWornItems",o),t.outfits.bind("updateItemAssets",o),t.outfits.bind("updatePetState",o),this.useSWFAdapter=function(){u("SWF")},this.useImageAdapter=function(){u("Image")},this.toggleAdapter=function(){var e=n.adapter.constructor=="SWF"?"Image":"SWF";u(e)},this.usingSWFAdapter=function(){return n.adapter.constructor==s.SWF},this.usingImageAdapter=function(){return n.adapter.constructor==s.Image}},window.previewSWFIsReady=function(e){Wardrobe.StandardPreview.views_by_swf_id[e].previewSWFIsReady()},t};