From 0d23412fbaa2cc83c80f3b1f1675b1cada88d23b Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Sun, 18 Feb 2024 20:31:21 -0800 Subject: [PATCH] Merge pet_query.js into its only call site --- app/assets/javascripts/outfits/new.js | 25 ++++++++++++++++++++++++- app/assets/javascripts/pet_query.js | 22 ---------------------- app/views/outfits/new.html.haml | 2 +- 3 files changed, 25 insertions(+), 24 deletions(-) delete mode 100644 app/assets/javascripts/pet_query.js diff --git a/app/assets/javascripts/outfits/new.js b/app/assets/javascripts/outfits/new.js index 22c7f716..89827a0e 100644 --- a/app/assets/javascripts/outfits/new.js +++ b/app/assets/javascripts/outfits/new.js @@ -1,5 +1,28 @@ (function () { - // don't need to export anything in here + 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"); + } + } var preview_el = $("#pet-preview"), img_el = preview_el.find("img"), diff --git a/app/assets/javascripts/pet_query.js b/app/assets/javascripts/pet_query.js deleted file mode 100644 index 15eea679..00000000 --- a/app/assets/javascripts/pet_query.js +++ /dev/null @@ -1,22 +0,0 @@ -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'); - } -} diff --git a/app/views/outfits/new.html.haml b/app/views/outfits/new.html.haml index 2d07a2d6..2bba93f5 100644 --- a/app/views/outfits/new.html.haml +++ b/app/views/outfits/new.html.haml @@ -117,4 +117,4 @@ - content_for :javascripts do = include_javascript_libraries :jquery20, :jquery_tmpl - = javascript_include_tag 'ajax_auth', 'react', 'jquery.timeago', 'pet_query', 'outfits/new' \ No newline at end of file + = javascript_include_tag 'ajax_auth', 'react', 'jquery.timeago', 'outfits/new' \ No newline at end of file