2023-10-12 22:30:16 -07:00
|
|
|
(function () {
|
2024-02-18 20:31:21 -08:00
|
|
|
function petImage(id, size) {
|
|
|
|
return "https://pets.neopets.com/" + id + "/1/" + size + ".png";
|
|
|
|
}
|
|
|
|
|
|
|
|
var PetQuery = {},
|
|
|
|
query_string = document.location.hash || document.location.search;
|
|
|
|
|
|
|
|
$.each(query_string.substr(1).split("&"), function () {
|
|
|
|
var split_piece = this.split("=");
|
|
|
|
if (split_piece.length == 2) {
|
|
|
|
PetQuery[split_piece[0]] = split_piece[1];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (PetQuery.name) {
|
|
|
|
if (PetQuery.species && PetQuery.color) {
|
|
|
|
$("#pet-query-notice-template")
|
|
|
|
.tmpl({
|
|
|
|
pet_name: PetQuery.name,
|
|
|
|
pet_image_url: petImage("cpn/" + PetQuery.name, 1),
|
|
|
|
})
|
|
|
|
.prependTo("#container");
|
|
|
|
}
|
|
|
|
}
|
2010-11-05 15:45:05 -07:00
|
|
|
|
2023-10-12 22:30:16 -07:00
|
|
|
var preview_el = $("#pet-preview"),
|
|
|
|
img_el = preview_el.find("img"),
|
|
|
|
response_el = preview_el.find("span");
|
2010-11-05 15:45:05 -07:00
|
|
|
|
2023-10-12 22:30:16 -07:00
|
|
|
var defaultPreviewUrl = img_el.attr("src");
|
2014-09-10 13:38:26 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
preview_el.click(function () {
|
|
|
|
Preview.Job.current.visit();
|
|
|
|
});
|
2010-11-05 15:45:05 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
var Preview = {
|
|
|
|
clear: function () {
|
2023-10-12 22:30:16 -07:00
|
|
|
if (typeof Preview.Job.fallback != "undefined")
|
|
|
|
Preview.Job.fallback.setAsCurrent();
|
2015-08-05 17:11:08 -07:00
|
|
|
},
|
|
|
|
displayLoading: function () {
|
2023-10-12 22:30:16 -07:00
|
|
|
preview_el.addClass("loading");
|
|
|
|
response_el.text("Loading...");
|
2015-08-05 17:11:08 -07:00
|
|
|
},
|
|
|
|
failed: function () {
|
2023-10-12 22:30:16 -07:00
|
|
|
preview_el.addClass("hidden");
|
2015-08-05 17:11:08 -07:00
|
|
|
},
|
|
|
|
notFound: function (key, options) {
|
|
|
|
Preview.failed();
|
|
|
|
response_el.empty();
|
2023-10-12 22:30:16 -07:00
|
|
|
$("#preview-" + key + "-template")
|
|
|
|
.tmpl(options)
|
|
|
|
.appendTo(response_el);
|
2015-08-05 17:11:08 -07:00
|
|
|
},
|
|
|
|
updateWithName: function (name_el) {
|
2023-10-12 22:30:16 -07:00
|
|
|
var name = name_el.val(),
|
|
|
|
job;
|
|
|
|
if (name) {
|
2015-08-05 17:11:08 -07:00
|
|
|
currentName = name;
|
2023-10-12 22:30:16 -07:00
|
|
|
if (!Preview.Job.current || name != Preview.Job.current.name) {
|
2015-08-05 17:11:08 -07:00
|
|
|
job = new Preview.Job.Name(name);
|
|
|
|
job.setAsCurrent();
|
|
|
|
Preview.displayLoading();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Preview.clear();
|
2010-11-05 15:45:05 -07:00
|
|
|
}
|
2023-10-12 22:30:16 -07:00
|
|
|
},
|
|
|
|
};
|
2010-11-05 15:45:05 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
function loadNotable() {
|
|
|
|
// TODO: add HTTPS to notables
|
2023-10-25 15:16:46 -07:00
|
|
|
// $.getJSON('https://notables.openneo.net/api/1/days/ago/1?callback=?', function (response) {
|
2015-08-05 17:11:08 -07:00
|
|
|
// var notables = response.notables;
|
|
|
|
// var i = Math.floor(Math.random() * notables.length);
|
|
|
|
// Preview.Job.fallback = new Preview.Job.Name(notables[i].petName);
|
|
|
|
// if(!Preview.Job.current) {
|
|
|
|
// Preview.Job.fallback.setAsCurrent();
|
|
|
|
// }
|
|
|
|
// });
|
2023-10-12 22:30:16 -07:00
|
|
|
if (!Preview.Job.current) {
|
2014-09-10 13:38:26 -07:00
|
|
|
Preview.Job.fallback.setAsCurrent();
|
|
|
|
}
|
2015-08-05 17:11:08 -07:00
|
|
|
}
|
2014-09-10 13:38:26 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
function loadFeature() {
|
2023-10-12 22:30:16 -07:00
|
|
|
$.getJSON("/donations/features", function (features) {
|
2015-08-05 17:11:08 -07:00
|
|
|
if (features.length > 0) {
|
|
|
|
var feature = features[Math.floor(Math.random() * features.length)];
|
|
|
|
Preview.Job.fallback = new Preview.Job.Feature(feature);
|
|
|
|
if (!Preview.Job.current) {
|
|
|
|
Preview.Job.fallback.setAsCurrent();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
loadNotable();
|
2014-09-10 13:38:26 -07:00
|
|
|
}
|
2015-08-05 17:11:08 -07:00
|
|
|
});
|
|
|
|
}
|
2014-09-10 13:38:26 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
loadFeature();
|
2010-11-05 15:45:05 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
Preview.Job = function (key, base) {
|
|
|
|
var job = this,
|
|
|
|
quality = 2;
|
|
|
|
job.loading = false;
|
2023-10-12 22:30:16 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
function getImageSrc() {
|
2023-10-12 22:30:16 -07:00
|
|
|
if (key.substr(0, 3) === "a:-") {
|
2015-08-05 17:11:08 -07:00
|
|
|
// lol lazy code for prank image :P
|
|
|
|
// TODO: HTTPS?
|
2023-10-12 22:30:16 -07:00
|
|
|
return (
|
2023-10-25 15:16:46 -07:00
|
|
|
"https://swfimages.impress.openneo.net" +
|
2023-10-12 22:30:16 -07:00
|
|
|
"/biology/000/000/0-2/" +
|
|
|
|
key.substr(2) +
|
|
|
|
"/300x300.png"
|
|
|
|
);
|
2024-09-09 06:06:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key.substr(0, 1) === "@") {
|
|
|
|
// support hashed pets
|
|
|
|
base = "cp";
|
|
|
|
key = key.substr(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base === "cp" || base === "cpn") {
|
2023-10-12 22:30:16 -07:00
|
|
|
return petImage(base + "/" + key, quality);
|
|
|
|
} else if (base === "url") {
|
2015-08-05 17:11:08 -07:00
|
|
|
return key;
|
|
|
|
} else {
|
|
|
|
throw new Error("unrecognized image base " + base);
|
|
|
|
}
|
2014-03-27 22:12:18 -07:00
|
|
|
}
|
2023-10-12 22:30:16 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
function load() {
|
|
|
|
job.loading = true;
|
2023-10-12 22:30:16 -07:00
|
|
|
img_el.attr("src", getImageSrc());
|
2015-08-05 17:11:08 -07:00
|
|
|
}
|
2023-10-12 22:30:16 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
this.increaseQualityIfPossible = function () {
|
2023-10-12 22:30:16 -07:00
|
|
|
if (quality == 2) {
|
2015-08-05 17:11:08 -07:00
|
|
|
quality = 4;
|
|
|
|
load();
|
|
|
|
}
|
2023-10-12 22:30:16 -07:00
|
|
|
};
|
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
this.setAsCurrent = function () {
|
|
|
|
Preview.Job.current = job;
|
2010-11-05 15:45:05 -07:00
|
|
|
load();
|
2023-10-12 22:30:16 -07:00
|
|
|
};
|
2014-09-10 13:38:26 -07:00
|
|
|
|
2023-10-12 22:30:16 -07:00
|
|
|
this.notFound = function () {
|
|
|
|
Preview.notFound("pet-not-found");
|
|
|
|
};
|
|
|
|
};
|
2010-11-05 15:45:05 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
Preview.Job.Name = function (name) {
|
|
|
|
this.name = name;
|
2023-10-12 22:30:16 -07:00
|
|
|
Preview.Job.apply(this, [name, "cpn"]);
|
2014-03-31 21:07:55 -07:00
|
|
|
|
2023-10-12 22:30:16 -07:00
|
|
|
this.visit = function () {
|
|
|
|
$(".main-pet-name").val(this.name).closest("form").submit();
|
|
|
|
};
|
|
|
|
};
|
2010-11-05 15:45:05 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
Preview.Job.Hash = function (hash, form) {
|
2023-10-12 22:30:16 -07:00
|
|
|
Preview.Job.apply(this, [hash, "cp"]);
|
|
|
|
|
|
|
|
this.visit = function () {
|
|
|
|
window.location =
|
|
|
|
"/wardrobe?color=" +
|
|
|
|
form.find(".color").val() +
|
|
|
|
"&species=" +
|
|
|
|
form.find(".species").val();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
Preview.Job.Feature = function (feature) {
|
|
|
|
Preview.Job.apply(this, [feature.outfit_image_url, "url"]);
|
2015-08-05 17:11:08 -07:00
|
|
|
this.name = "Thanks for donating, " + feature.donor_name + "!"; // TODO: i18n
|
2014-09-10 13:38:26 -07:00
|
|
|
|
2023-10-12 22:30:16 -07:00
|
|
|
this.visit = function () {
|
|
|
|
window.location = "/donate";
|
|
|
|
};
|
2014-09-10 13:38:26 -07:00
|
|
|
|
2023-10-12 22:30:16 -07:00
|
|
|
this.notFound = function () {
|
2015-08-05 17:11:08 -07:00
|
|
|
// The outfit thumbnail hasn't generated or is missing or something.
|
|
|
|
// Let's fall back to a boring image for now.
|
|
|
|
var boring = new Preview.Job.Feature({
|
|
|
|
donor_name: feature.donor_name,
|
2023-10-12 22:30:16 -07:00
|
|
|
outfit_image_url: defaultPreviewUrl,
|
2015-08-05 17:11:08 -07:00
|
|
|
});
|
|
|
|
boring.setAsCurrent();
|
2023-10-12 22:30:16 -07:00
|
|
|
};
|
|
|
|
};
|
2010-11-05 15:45:05 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
$(function () {
|
|
|
|
var previewWithNameTimeout;
|
2023-10-12 22:30:16 -07:00
|
|
|
|
|
|
|
var name_el = $(".main-pet-name");
|
2015-08-05 17:11:08 -07:00
|
|
|
name_el.val(PetQuery.name);
|
|
|
|
Preview.updateWithName(name_el);
|
2023-10-12 22:30:16 -07:00
|
|
|
|
2015-08-05 17:11:08 -07:00
|
|
|
name_el.keyup(function () {
|
2024-03-13 21:26:22 -07:00
|
|
|
if (previewWithNameTimeout && Preview.Job.current) {
|
2015-08-05 17:11:08 -07:00
|
|
|
clearTimeout(previewWithNameTimeout);
|
|
|
|
Preview.Job.current.loading = false;
|
|
|
|
}
|
|
|
|
var name_el = $(this);
|
2023-10-12 22:30:16 -07:00
|
|
|
previewWithNameTimeout = setTimeout(function () {
|
2015-08-05 17:11:08 -07:00
|
|
|
Preview.updateWithName(name_el);
|
|
|
|
}, 250);
|
2010-11-05 15:45:05 -07:00
|
|
|
});
|
2023-10-12 22:30:16 -07:00
|
|
|
|
|
|
|
img_el
|
|
|
|
.load(function () {
|
|
|
|
if (Preview.Job.current.loading) {
|
|
|
|
Preview.Job.loading = false;
|
|
|
|
Preview.Job.current.increaseQualityIfPossible();
|
|
|
|
preview_el
|
|
|
|
.removeClass("loading")
|
|
|
|
.removeClass("hidden")
|
|
|
|
.addClass("loaded");
|
|
|
|
response_el.text(Preview.Job.current.name);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.error(function () {
|
|
|
|
if (Preview.Job.current.loading) {
|
|
|
|
Preview.Job.loading = false;
|
|
|
|
Preview.Job.current.notFound();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".species, .color").change(function () {
|
|
|
|
var type = {},
|
|
|
|
nameComponents = {};
|
|
|
|
var form = $(this).closest("form");
|
|
|
|
form.find("select").each(function () {
|
|
|
|
var el = $(this),
|
|
|
|
selectedEl = el.children(":selected"),
|
|
|
|
key = el.attr("name");
|
2015-08-05 17:11:08 -07:00
|
|
|
type[key] = selectedEl.val();
|
|
|
|
nameComponents[key] = selectedEl.text();
|
|
|
|
});
|
2023-10-12 22:30:16 -07:00
|
|
|
name = nameComponents.color + " " + nameComponents.species;
|
2015-08-05 17:11:08 -07:00
|
|
|
Preview.displayLoading();
|
|
|
|
$.ajax({
|
2023-10-12 22:30:16 -07:00
|
|
|
url:
|
|
|
|
"/species/" +
|
|
|
|
type.species +
|
2023-11-11 16:09:58 -08:00
|
|
|
"/colors/" +
|
2023-10-12 22:30:16 -07:00
|
|
|
type.color +
|
|
|
|
"/pet_type.json",
|
|
|
|
dataType: "json",
|
2015-08-05 17:11:08 -07:00
|
|
|
success: function (data) {
|
|
|
|
var job;
|
2023-10-12 22:30:16 -07:00
|
|
|
if (data) {
|
2015-08-05 17:11:08 -07:00
|
|
|
job = new Preview.Job.Hash(data.image_hash, form);
|
|
|
|
job.name = name;
|
|
|
|
job.setAsCurrent();
|
|
|
|
} else {
|
2023-10-12 22:30:16 -07:00
|
|
|
Preview.notFound("pet-type-not-found", {
|
2015-08-05 17:11:08 -07:00
|
|
|
color_name: nameComponents.color,
|
2023-10-12 22:30:16 -07:00
|
|
|
species_name: nameComponents.species,
|
2015-08-05 17:11:08 -07:00
|
|
|
});
|
|
|
|
}
|
2023-10-12 22:30:16 -07:00
|
|
|
},
|
2015-08-05 17:11:08 -07:00
|
|
|
});
|
2013-02-06 08:59:25 -08:00
|
|
|
});
|
2015-08-05 17:11:08 -07:00
|
|
|
|
2023-10-12 22:30:16 -07:00
|
|
|
$(".load-pet-to-wardrobe").submit(function (e) {
|
|
|
|
if ($(this).find(".main-pet-name").val() === "" && Preview.Job.current) {
|
2015-08-05 17:11:08 -07:00
|
|
|
e.preventDefault();
|
|
|
|
Preview.Job.current.visit();
|
2013-02-06 08:59:25 -08:00
|
|
|
}
|
2015-08-05 17:11:08 -07:00
|
|
|
});
|
2014-04-16 09:02:44 -07:00
|
|
|
});
|
2015-07-14 21:09:17 -07:00
|
|
|
|
2023-10-12 22:30:16 -07:00
|
|
|
$("#latest-contribution-created-at").timeago();
|
2010-11-05 15:45:05 -07:00
|
|
|
})();
|