2010-05-16 13:37:55 -07:00
|
|
|
var PREVIEW_SWF_ID = 'item-preview-swf',
|
2010-05-16 17:45:30 -07:00
|
|
|
PREVIEW_SWF = document.getElementById(PREVIEW_SWF_ID),
|
|
|
|
IMPRESS_HOST = PREVIEW_SWF.getAttribute('data-impress-host'),
|
2010-05-20 18:16:35 -07:00
|
|
|
speciesList = $('#item-preview a'),
|
|
|
|
MainWardrobe;
|
|
|
|
|
|
|
|
if(console === undefined || console.log === undefined) {
|
|
|
|
function log() {}
|
|
|
|
} else {
|
|
|
|
log = $.proxy(console, 'log');
|
|
|
|
}
|
2010-05-16 13:37:55 -07:00
|
|
|
|
2010-05-16 17:45:30 -07:00
|
|
|
function impressUrl(path) {
|
|
|
|
return 'http://' + IMPRESS_HOST + path;
|
|
|
|
}
|
|
|
|
|
2010-05-16 13:37:55 -07:00
|
|
|
function PetType() {}
|
|
|
|
|
|
|
|
PetType.prototype.load = function () {
|
2010-05-20 18:16:35 -07:00
|
|
|
var url = '/species/' + this.species_id + '/color/' + this.color_id + '/pet_type.json',
|
|
|
|
pet_type = this;
|
2010-05-16 13:37:55 -07:00
|
|
|
$.getJSON(url, function (data) {
|
2010-05-20 18:16:35 -07:00
|
|
|
pet_type.id = data.id;
|
|
|
|
pet_type.body_id = data.body_id;
|
2010-05-20 18:55:09 -07:00
|
|
|
Item.current.load();
|
2010-05-20 18:16:35 -07:00
|
|
|
$.getJSON('/pet_types/' + data.id + '/swf_assets.json', function (assets) {
|
2010-05-20 18:55:09 -07:00
|
|
|
log('pet type assets loaded');
|
2010-05-20 18:16:35 -07:00
|
|
|
pet_type.assets = assets;
|
|
|
|
Preview.update();
|
|
|
|
});
|
2010-05-16 13:37:55 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
PetType.prototype.setAsCurrent = function () {
|
|
|
|
PetType.current = this;
|
|
|
|
speciesList.filter('.current').removeClass('current');
|
|
|
|
this.link.addClass('current');
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
|
2010-05-20 18:55:09 -07:00
|
|
|
PetType.createFromLink = function (link) {
|
2010-05-16 13:37:55 -07:00
|
|
|
var pet_type = new PetType();
|
|
|
|
pet_type.color_id = link.attr('data-color-id');
|
|
|
|
pet_type.species_id = link.attr('data-species-id');
|
|
|
|
pet_type.link = link;
|
|
|
|
return pet_type;
|
|
|
|
}
|
2010-05-16 12:01:38 -07:00
|
|
|
|
2010-05-20 18:55:09 -07:00
|
|
|
function Item() {
|
|
|
|
this.load = function () {
|
|
|
|
var url = '/' + this.id + '/swf_assets.json?body_id=' + PetType.current.body_id,
|
|
|
|
item = this;
|
|
|
|
$.getJSON(url, function (data) {
|
|
|
|
log('item assets loaded');
|
|
|
|
item.assets = data;
|
|
|
|
Preview.update();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setAsCurrent = function () {
|
|
|
|
Item.current = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Item.createFromLocation = function () {
|
|
|
|
var item = new Item();
|
|
|
|
item.id = parseInt(document.location.pathname.substr(1));
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2010-05-20 18:16:35 -07:00
|
|
|
Preview = new function Preview() {
|
|
|
|
var assets = [], swf_id, swf, updateWhenFlashReady = false;
|
|
|
|
|
|
|
|
this.setFlashIsReady = function () {
|
|
|
|
log('flash ready');
|
|
|
|
swf = document.getElementById(swf_id);
|
|
|
|
if(updateWhenFlashReady) this.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.update = function (assets) {
|
2010-05-20 18:55:09 -07:00
|
|
|
var assets = [];
|
2010-05-20 18:16:35 -07:00
|
|
|
log('want to update');
|
|
|
|
if(swf) {
|
|
|
|
log('got to update');
|
2010-05-20 18:55:09 -07:00
|
|
|
log(assets);
|
|
|
|
$.each([PetType, Item], function () {
|
|
|
|
if(this.current.assets) assets = assets.concat(this.current.assets);
|
|
|
|
});
|
|
|
|
log(assets);
|
|
|
|
assets = $.each(assets, function () {
|
2010-05-20 18:16:35 -07:00
|
|
|
this.local_path = this.local_url;
|
|
|
|
});
|
|
|
|
log(assets);
|
|
|
|
swf.setAssets(assets);
|
|
|
|
} else {
|
|
|
|
updateWhenFlashReady = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.embed = function (id) {
|
|
|
|
swf_id = id;
|
|
|
|
swfobject.embedSWF(
|
|
|
|
impressUrl('/assets/swf/preview.swf'), // URL
|
|
|
|
id, // ID
|
2010-05-20 19:05:13 -07:00
|
|
|
'100%', // width
|
|
|
|
'100%', // height
|
2010-05-20 18:16:35 -07:00
|
|
|
'9', // required version
|
|
|
|
impressUrl('/assets/js/swfobject/expressInstall.swf'), // express install URL
|
|
|
|
{'swf_assets_path': impressUrl('/assets')}, // flashvars
|
|
|
|
{'wmode': 'transparent', 'allowscriptaccess': 'always'} // params
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Preview.embed(PREVIEW_SWF_ID);
|
2010-05-16 13:37:55 -07:00
|
|
|
|
2010-05-20 18:55:09 -07:00
|
|
|
PetType.createFromLink(speciesList.eq(Math.floor(Math.random()*speciesList.length))).setAsCurrent();
|
|
|
|
|
|
|
|
Item.createFromLocation().setAsCurrent();
|
2010-05-16 13:37:55 -07:00
|
|
|
|
|
|
|
speciesList.click(function (e) {
|
|
|
|
e.preventDefault();
|
2010-05-20 18:55:09 -07:00
|
|
|
PetType.createFromLink($(this)).setAsCurrent();
|
2010-05-16 13:37:55 -07:00
|
|
|
});
|
2010-05-20 18:16:35 -07:00
|
|
|
|
|
|
|
MainWardrobe = { View: { Outfit: Preview } };
|