/** @jsx React.DOM */
(function($) {
// Console-polyfill. MIT license.
// https://github.com/paulmillr/console-polyfill
// Make it safe to do console.log() always.
var console = (function (con) {
'use strict';
var prop, method;
var empty = {};
var dummy = function() {};
var properties = 'memory'.split(',');
var methods = ('assert,count,debug,dir,dirxml,error,exception,group,' +
'groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,' +
'time,timeEnd,trace,warn').split(',');
while (prop = properties.pop()) con[prop] = con[prop] || empty;
while (method = methods.pop()) con[method] = con[method] || dummy;
return con;
})(window.console || {});
var Neopia = {
User: {
get: function(id) {
return Neopia.getJSON("/users/" + id).then(function(response) {
return response.users[0];
});
}
},
Customization: {
get: function(petId) {
return Neopia.getJSON("/pets/" + petId + "/customization").then(function(response) {
return response.custom_pet;
});
}
},
getJSON: function(path) {
return $.getJSON(Neopia.API_URL + path);
},
init: function() {
var hostEl = $('meta[name=neopia-host]');
if (!hostEl.length) {
throw "missing neopia-host meta tag";
}
var host = hostEl.attr('content');
if (!host) {
throw "neopia-host meta tag exists, but is empty";
}
Neopia.API_URL = "http://" + host + "/api/1";
}
};
var Modeling = {
_customizationsByPetId: {},
_customizations: [],
_items: [],
_addCustomization: function(customization) {
this._customizationsByPetId[customization.name] = customization;
this._customizations = this._buildCustomizations();
this._update();
},
_buildCustomizations: function() {
var modelCustomizationsByPetId = this._customizationsByPetId;
return Object.keys(modelCustomizationsByPetId).map(function(petId) {
return modelCustomizationsByPetId[petId];
});
},
_createItems: function($) {
this._items = $('#newest-unmodeled-items li').map(function() {
var el = $(this);
return {
component: React.renderComponent(