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-16 13:37:55 -07:00
|
|
|
speciesList = $('#item-preview a');
|
|
|
|
|
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 () {
|
|
|
|
var url = '/species/' + this.species_id + '/color/' + this.color_id + '/pet_type.json';
|
|
|
|
$.getJSON(url, function (data) {
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
PetType.prototype.setAsCurrent = function () {
|
|
|
|
PetType.current = this;
|
|
|
|
speciesList.filter('.current').removeClass('current');
|
|
|
|
this.link.addClass('current');
|
|
|
|
this.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
PetType.create_from_link = function (link) {
|
|
|
|
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
|
|
|
|
|
|
|
swfobject.embedSWF(
|
2010-05-16 17:45:30 -07:00
|
|
|
impressUrl('/assets/swf/preview.swf'), // URL
|
2010-05-16 12:01:38 -07:00
|
|
|
PREVIEW_SWF_ID, // ID
|
|
|
|
400, // width
|
|
|
|
400, // height
|
2010-05-16 13:37:55 -07:00
|
|
|
'9', // required version
|
2010-05-16 17:45:30 -07:00
|
|
|
impressUrl('/assets/js/swfobject/expressInstall.swf'), // express install URL
|
|
|
|
{'swf_assets_path': impressUrl('/assets')}, // flashvars
|
|
|
|
{'wmode': 'transparent', 'allowscriptaccess': 'always'} // params
|
2010-05-16 12:01:38 -07:00
|
|
|
)
|
2010-05-16 13:37:55 -07:00
|
|
|
|
|
|
|
PetType.create_from_link(speciesList.eq(Math.floor(Math.random()*speciesList.length))).setAsCurrent();
|
|
|
|
|
|
|
|
speciesList.click(function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
PetType.create_from_link($(this)).setAsCurrent();
|
|
|
|
});
|