1
0
Fork 0
forked from OpenNeo/impress

Add better support for hashed pet names

Closes #2, after making some tweaks to the PR to fit how JS templating
works here. Thanks @dice!!

I had to move `petThumbnailUrl` out of the closure, because this script
does a cute thing of having separate variable scopes for the separate
areas of the page—but this is used by two of them. Arguably it could
make sense to like, put this all in one larger shared IIFE closure that
wraps both of them, to preserve some of this code's intention of
avoiding adding to the global namespace on this page, but like.
*It's fine.*

Co-Authored-By: Steve C <diceroll123@gmail.com>
This commit is contained in:
Emi Matchu 2024-08-31 12:07:52 -07:00
parent 04ffc30e92
commit af8dd42830
2 changed files with 11 additions and 6 deletions

View file

@ -1,5 +1,14 @@
var DEBUG = document.location.search.substr(0, 6) == "?debug";
function petThumbnailUrl(pet_name) {
// if first character is "@", use the hash url
if (pet_name[0] == "@") {
return "https://pets.neopets.com/cp/" + pet_name.substr(1) + "/1/1.png";
}
return "https://pets.neopets.com/cpn/" + pet_name + "/1/1.png";
}
/* Needed items form */
(function () {
var UI = {};
@ -65,10 +74,6 @@ var DEBUG = document.location.search.substr(0, 6) == "?debug";
loadItems(data.query);
}
function petThumbnailUrl(pet_name) {
return "https://pets.neopets.com/cpn/" + pet_name + "/1/1.png";
}
/* Items */
function loadItems(query) {
@ -127,7 +132,7 @@ var DEBUG = document.location.search.substr(0, 6) == "?debug";
function Pet(name) {
var el = $("#bulk-pets-submission-template")
.tmpl({ pet_name: name })
.tmpl({ pet_name: name, pet_thumbnail: petThumbnailUrl(name) })
.appendTo(queue_el);
this.load = function () {

View file

@ -68,7 +68,7 @@
%script#bulk-pets-submission-template{:type => 'text/x-jquery/tmpl'}
%li.waiting
%img{:src => 'https://pets.neopets.com/cpn/${pet_name}/1/1.png'}
%img{:src => '${pet_thumbnail}'}
%span.name ${pet_name}
%span.waiting-message= t '.bulk_pets.waiting'
%span.loading-message= t '.bulk_pets.loading'