2 lines
4.3 KiB
JavaScript
2 lines
4.3 KiB
JavaScript
|
// FIXME: pick a consistent javascript style! underscores for vars or camelCase?
|
||
|
function impressUrl(e){return"http://"+IMPRESS_HOST+e}function PetType(){function r(){n?e.onUpdate():$.getJSON("/pet_types/"+e.id+"/swf_assets.json",function(t){e.assets=t,n=!0,e.onUpdate()})}function i(){Preview.disable(e.deactivation_msg)}var e=this,t=!1,n=!1;this.activated=!0,this.assets=[],this.deactivate=function(){var e;this.activated=!1,this.deactivation_msg=$("#swf-assets-not-found-template").tmpl({color_name:this.color_name.capitalize(),species_name:this.species_name.capitalize()}),this==PetType.current&&i();var t=this.link.children("img").get(0);this.link.addClass("deactivated"),t.src=t.src.replace("/1/","/2/")},this.load=function(){Item.current.load(this),r()},this.setAsCurrent=function(){PetType.current=this,speciesList.filter(".current").removeClass("current"),this.link.addClass("current"),customize_more_el.attr("href","http://impress.openneo.net/wardrobe?species="+this.species_id+"&color="+this.color_id+"&objects[]="+Item.current.id),this.activated?(Preview.enable(),this.load()):i()},this.onUpdate=function(){e==PetType.current&&Preview.update()}}function Item(e){this.assets_by_body_id={},this.id=e,this.load=function(t){var n="/items/"+e+"/bodies/"+t.body_id+"/swf_assets.json",r=this;this.getAssetsForPetType(t).length?t.onUpdate():$.getJSON(n,function(e){r.setAssetsForPetType(e,t)})},this.loadAllStandard=function(){var t=this;$.getJSON("/items/"+e+"/swf_assets.json",function(e){$.each(e,function(e){t.assets_by_body_id[parseInt(e)]=this}),$.each(PetType.all,function(){t.getAssetsForPetType(this).length==0&&this.deactivate()})})},this.getAssetsForPetType=function(e){return this.assets_by_body_id[e.body_id]||this.assets_by_body_id[0]||[]},this.setAsCurrent=function(){Item.current=this},this.setAssetsForPetType=function(e,t){e.length?(this.assets_by_body_id[t.body_id]=e,t.onUpdate()):t.deactivate()}}var PREVIEW_SWF_ID="item-preview-swf",PREVIEW_SWF=document.getElementById(PREVIEW_SWF_ID),speciesList=$("#item-preview a"),customize_more_el=$("#customize-more"),MainWardrobe;if(typeof console=="undefined"||typeof console.log=="undefined")function log(){}else log=$.proxy(console,"log");String.prototype.capitalize=function(){return this.charAt(0).toUpperCase()+this.substr(1)},PetType.all={},PetType.DASH_REGEX=/-/g,PetType.createFromLink=function(e){var t=new PetType;return $.each(e.get(0).attributes,function(){this.name.substr(0,5)=="data-"&&(t[this.name.substr(5).replace(PetType.DASH_REGEX,"_")]=this.value)}),t.link=e,PetType.all[t.id]=t,t},Item.createFromLocation=function(){var e=new Item(parseInt(document.location.pathname.substr(7),10)),t=CURRENT_ITEM_ZONES_RESTRICT,n=t.length;e.restricted_zones=[];for(i=0;i<n;i++)t.charAt(i)=="1"&&e.restricted_zones.push(i+1);return e},Preview=new function(){var t=this,n,r,i=!1;window.previewSWFIsReady=function(){log("preview SWF is ready"),r=document.getElementById(n),i&&t.update()},this.update=function(e){var e;r&&typeof r.setAssets=="function"?(log("now doing update"),e=PetType.current.assets.concat(Item.current.getAssetsForPetType(PetType.current)),e=$.grep(e,function(e){var t=$.inArray(e.zone_id,Item.current.restricted_zones)==-1;return t&&(e.local_path=e.local_url),t}),r.setAssets(e)):(log("putting off update"),i=!0)},this.embed=function(e){n=e,swfobject.embedSWF("/swfs/preview.swf?v=2",e,"100%","100%","9",impressUrl("/assets/js/swfobject/expressInstall.swf"),{},{wmode:"transparent",allowscriptaccess:"always"})},this.disable=function(e){$("#"+n).hide(),$("#item-preview-error").empty().append(e).show()},this.enable=function(){$("#item-preview-error").hide(),$("#"+n).show()}},Preview.embed(PREVIEW_SWF_ID),Item.createFromLocation().setAsCurrent(),Item.current.name=$("#item-name").text(),PetType.createFromLink(speciesList.eq(Math.floor(Math.random()*speciesList.length))).setAsCurrent(),speciesList.each(function(){var e=$(this);PetType.createFromLink(e)}).live("click",function(e){e.preventDefault(),PetType.all[$(this).data("id")].setAsCurrent()}),setTimeout($.proxy(Item.current,"loadAllStandard"),5e3),window.MainWardrobe={View:{Outfit:{setFlashIsReady:previewSWFIsReady}}};var S
|