|
@@ -121,7 +121,7 @@ function ClassContext(q) {
|
|
|
if (!this.class) {
|
|
|
window.location.assign("");
|
|
|
}
|
|
|
- console.log("Class page", this.class);
|
|
|
+ console.log("Class page(" + this.class + ")");
|
|
|
for (klass in category) {
|
|
|
if (category.hasOwnProperty(klass)) {
|
|
|
if (category[klass].name === this.class) {
|
|
@@ -159,12 +159,57 @@ function HomeContext() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Species context
|
|
|
+ *
|
|
|
+ * @param {Object} q
|
|
|
+ * - class
|
|
|
+ * - species
|
|
|
+ * @constructor
|
|
|
+ */
|
|
|
function SpeciesContext(q) {
|
|
|
- this.species = q.species ? q.species : null;
|
|
|
- if (!this.species) {
|
|
|
+ var category = animals_data.category;
|
|
|
+ var klass = null;
|
|
|
+ var speciesArray = null;
|
|
|
+ var species;
|
|
|
+ var speciesIndex;
|
|
|
+ var prop;
|
|
|
+
|
|
|
+ if (!q.class || !q.species) {
|
|
|
+ console.error("Missing class or species parameter.");
|
|
|
+ window.location.assign("");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.log("Species page(" + q.class + ", " + q.species + ")");
|
|
|
+ this.class = q.class ? q.class : null;
|
|
|
+
|
|
|
+ for (klass in category) {
|
|
|
+ if (category.hasOwnProperty(klass)) {
|
|
|
+ if (category[klass].name === this.class) {
|
|
|
+ speciesArray = category[klass].animals;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // No species means class was not found.
|
|
|
+ if (!speciesArray) {
|
|
|
+ console.warn("No species found for class ", this.class);
|
|
|
window.location.assign("");
|
|
|
}
|
|
|
- console.log("Species page", this.species);
|
|
|
+
|
|
|
+ for (speciesIndex in speciesArray) {
|
|
|
+ if (speciesArray.hasOwnProperty(speciesIndex)) {
|
|
|
+ species = speciesArray[speciesIndex];
|
|
|
+ if (species.name === q.species) {
|
|
|
+ for (prop in species) {
|
|
|
+ if (species.hasOwnProperty(prop)) {
|
|
|
+ this[prop] = species[prop];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// ======== Route binding ======================================================
|