impress/public/javascripts/items/show.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

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'),
speciesList = $('#item-preview a');
2010-05-16 17:45:30 -07:00
function impressUrl(path) {
return 'http://' + IMPRESS_HOST + path;
}
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;
}
swfobject.embedSWF(
2010-05-16 17:45:30 -07:00
impressUrl('/assets/swf/preview.swf'), // URL
PREVIEW_SWF_ID, // ID
400, // width
400, // height
'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
)
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();
});