From 8b3e98c5e79dca7944f90fc10ea9be1be17d0018 Mon Sep 17 00:00:00 2001 From: Andrew Miner Date: Sun, 18 Aug 2013 17:09:02 -0700 Subject: [PATCH] [#21] Add support for linking to a certain recipe --- html/crafting.js | 34 +++++- html/css/main.css | 1 + html/index.html | 1 + html/purl.js | 268 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 html/purl.js diff --git a/html/crafting.js b/html/crafting.js index 8234ff70a..b3be910ff 100644 --- a/html/crafting.js +++ b/html/crafting.js @@ -14,12 +14,18 @@ $(function() { $("#crafting_selector").change(onCraftingSelectorChanged); $("#crafting_count").change(onCraftingSelectorChanged); - loadRecipebook("data/vanilla.json"); - loadRecipebook("data/buildcraft.json"); + loadRecipebook("data/vanilla.json", function() { + loadRecipebook("data/buildcraft.json", function() { + parseUrlParameters(); + onCraftingSelectorChanged(); + }); + }); }); function onCraftingSelectorChanged() { var recipeName = $("#crafting_selector option:selected").val(); + if (recipeName === undefined) return; + var recipe = findRecipe(recipeName); if (recipe === undefined) { $("#crafting_error").html("Cannot find recipe for " + recipeName); @@ -77,6 +83,30 @@ function loadRecipebook(recipebookUrl, onSuccess) { }); } +function parseUrlParameters() { + var quantity = $.url().param('quantity'); + if (quantity !== undefined) { + $("#crafting_count").val(quantity); + + if ($("#crafting_count option:selected").val() === undefined) { + $("#crafting_count").val(1); + + $("#crafting_error").html("Unsupported quantity: " + quantity); + $("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION); + } + } + + var recipeName = $.url().param('recipeName'); + if (recipeName !== undefined) { + $("#crafting_selector").val(recipeName); + + if ($("#crafting_selector option:selected").val() === undefined) { + $("#crafting_error").html("Cannot find recipe for " + recipeName); + $("#crafting_error").fadeIn(FADE_DURATION).delay(ERROR_DISPLAY_DURATION).fadeOut(FADE_DURATION); + } + } +} + function updateCraftingSelector() { var $selector = $("#crafting_selector"); $selector.html(""); diff --git a/html/css/main.css b/html/css/main.css index 61ffb45a9..126487bd2 100644 --- a/html/css/main.css +++ b/html/css/main.css @@ -15,6 +15,7 @@ p { margin-left: 10px; margin-right: 10px; } #border_grass { background: url("../images/grass_side.png"); height: 32px; box-shadow: 2px 0px 4px #444; } #border_bedrock { background: url("../images/bedrock.png"); height: 32px; box-shadow: 2px 0px 4px #444; } #crafting { margin-bottom: 64px; } +#crafting_error { margin-left: 10px; } #crafting_output { margin-left: 10px; width: 920px; } #crafting_output th { background: #f8f8f8; border-left: 1px solid #bbb; font-weight: bold; padding: 10px; } #crafting_output td { background: #f8f8f8; border-left: 1px solid #bbb; padding: 10px; } diff --git a/html/index.html b/html/index.html index 1122244f0..b7fcb50c8 100644 --- a/html/index.html +++ b/html/index.html @@ -88,6 +88,7 @@ +