diff --git a/app/assets/javascripts/modeling.js.jsx b/app/assets/javascripts/modeling.js.jsx
index 002ef774..78582d31 100644
--- a/app/assets/javascripts/modeling.js.jsx
+++ b/app/assets/javascripts/modeling.js.jsx
@@ -1,37 +1,37 @@
-/** @jsx React.DOM */
-
-var Neopia = (function($, I18n) {
+var Neopia = (function ($, I18n) {
// Console-polyfill. MIT license.
// https://github.com/paulmillr/console-polyfill
// Make it safe to do console.log() always.
var console = (function (con) {
- 'use strict';
+ "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;
+ 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) {
+ get: function (id) {
return $.ajax({
dataType: "json",
url: Neopia.API_URL + "/users/" + id,
- useCSRFProtection: false
- }).then(function(response) {
+ useCSRFProtection: false,
+ }).then(function (response) {
return response.users[0];
});
- }
+ },
},
Customization: {
- request: function(petId, type) {
+ request: function (petId, type) {
var data = {};
if (ImpressUser.id) {
data.impress_user = ImpressUser.id;
@@ -41,80 +41,91 @@ var Neopia = (function($, I18n) {
type: type,
url: Neopia.API_URL + "/pets/" + petId + "/customization",
useCSRFProtection: false,
- data: data
+ data: data,
});
},
- get: function(petId) {
+ get: function (petId) {
return this.request(petId, "GET");
},
- post: function(petId) {
+ post: function (petId) {
return this.request(petId, "POST");
- }
+ },
},
Status: {
- get: function() {
+ get: function () {
return $.ajax({
dataType: "json",
url: Neopia.API_URL + "/status",
- useCSRFProtection: false
+ useCSRFProtection: false,
});
- }
+ },
},
- init: function() {
- var hostEl = $('meta[name=neopia-host]');
+ init: function () {
+ var hostEl = $("meta[name=neopia-host]");
if (!hostEl.length) {
throw "missing neopia-host meta tag";
}
- var host = hostEl.attr('content');
+ var host = hostEl.attr("content");
if (!host) {
throw "neopia-host meta tag exists, but is empty";
}
Neopia.API_URL = "//" + host + "/api/1";
- }
+ },
};
- var ImpressUser = (function() {
- var userSignedIn = ($('meta[name=user-signed-in]').attr('content') === 'true');
+ var ImpressUser = (function () {
+ var userSignedIn =
+ $("meta[name=user-signed-in]").attr("content") === "true";
if (userSignedIn) {
- var currentUserId = $('meta[name=current-user-id]').attr('content');
+ var currentUserId = $("meta[name=current-user-id]").attr("content");
return {
- addNeopetsUsername: function(username) {
+ addNeopetsUsername: function (username) {
return $.ajax({
- url: '/user/' + currentUserId + '/neopets-connections',
- type: 'POST',
- data: {neopets_connection: {neopets_username: username}}
+ url: "/user/" + currentUserId + "/neopets-connections",
+ type: "POST",
+ data: { neopets_connection: { neopets_username: username } },
});
},
- removeNeopetsUsername: function(username) {
+ removeNeopetsUsername: function (username) {
return $.ajax({
- url: '/user/' + currentUserId + '/neopets-connections/' + encodeURIComponent(username),
- type: 'POST',
- data: {_method: 'DELETE'}
+ url:
+ "/user/" +
+ currentUserId +
+ "/neopets-connections/" +
+ encodeURIComponent(username),
+ type: "POST",
+ data: { _method: "DELETE" },
});
},
- getNeopetsUsernames: function() {
- return JSON.parse($('#modeling-neopets-users').attr('data-usernames'));
+ getNeopetsUsernames: function () {
+ return JSON.parse(
+ $("#modeling-neopets-users").attr("data-usernames")
+ );
},
- id: currentUserId
+ id: currentUserId,
};
} else {
return {
_key: "guestNeopetsUsernames",
- _setNeopetsUsernames: function(usernames) {
+ _setNeopetsUsernames: function (usernames) {
localStorage.setItem(this._key, JSON.stringify(usernames));
},
- addNeopetsUsername: function(username) {
- this._setNeopetsUsernames(this.getNeopetsUsernames().concat([username]));
+ addNeopetsUsername: function (username) {
+ this._setNeopetsUsernames(
+ this.getNeopetsUsernames().concat([username])
+ );
},
- removeNeopetsUsername: function(username) {
- this._setNeopetsUsernames(this.getNeopetsUsernames().filter(function(u) {
- return u !== username;
- }));
+ removeNeopetsUsername: function (username) {
+ this._setNeopetsUsernames(
+ this.getNeopetsUsernames().filter(function (u) {
+ return u !== username;
+ })
+ );
},
- getNeopetsUsernames: function() {
+ getNeopetsUsernames: function () {
return JSON.parse(localStorage.getItem(this._key)) || [];
},
- id: null
+ id: null,
};
}
})();
@@ -124,121 +135,135 @@ var Neopia = (function($, I18n) {
_customizations: [],
_itemsById: {},
_items: [],
- _usersComponent: {setState: function() {}},
+ _usersComponent: { setState: function () {} },
_neopetsUsernamesPresenceMap: {},
- _addCustomization: function(customization) {
+ _addCustomization: function (customization) {
// Set all equipped, interesting items' statuses as success and cross
// them off the list.
var itemsById = this._itemsById;
var equippedByZone = customization.custom_pet.equipped_by_zone;
var closetItems = customization.closet_items;
- Object.keys(equippedByZone).forEach(function(zoneId) {
+ Object.keys(equippedByZone).forEach(function (zoneId) {
var equippedClosetId = equippedByZone[zoneId].closet_obj_id;
var equippedObjectId = closetItems[equippedClosetId].obj_info_id;
if (itemsById.hasOwnProperty(equippedObjectId)) {
customization.statusByItemId[equippedObjectId] = "success";
- itemsById[equippedObjectId].el.find("span[data-body-id=" +
- customization.custom_pet.body_id + "]").addClass("modeled")
+ itemsById[equippedObjectId].el
+ .find("span[data-body-id=" + customization.custom_pet.body_id + "]")
+ .addClass("modeled")
.attr("title", I18n.modeledBodyTitle);
}
});
- this._customizationsByPetId[customization.custom_pet.name] = customization;
+ this._customizationsByPetId[customization.custom_pet.name] =
+ customization;
this._customizations = this._buildCustomizations();
this._updateCustomizations();
},
- _addNewCustomization: function(customization) {
+ _addNewCustomization: function (customization) {
customization.loadingForItemId = null;
customization.statusByItemId = {};
this._addCustomization(customization);
},
- _buildCustomizations: function() {
+ _buildCustomizations: function () {
var modelCustomizationsByPetId = this._customizationsByPetId;
- return Object.keys(modelCustomizationsByPetId).map(function(petId) {
+ return Object.keys(modelCustomizationsByPetId).map(function (petId) {
return modelCustomizationsByPetId[petId];
});
},
- _createItems: function($) {
+ _createItems: function ($) {
var itemsById = this._itemsById;
- this._items = $('#newest-unmodeled-items li').map(function() {
- var el = $(this);
- var item = {
- el: el,
- id: el.attr('data-item-id'),
- name: el.find('h2').text(),
- missingBodyIdsPresenceMap: el.find('span[data-body-id]').toArray().reduce(function(map, node) {
- map[$(node).attr('data-body-id')] = true;
- return map;
- }, {})
- };
- item.component = React.renderComponent(