From c39b37bfbd3d4e65e0c6ac8f4572bbf5be929d59 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 12 Oct 2017 03:15:28 -0400 Subject: [PATCH] Switch Playfield to use Fetch instead of XMLHTTPRequest --- js/playfield.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/js/playfield.js b/js/playfield.js index 34ae4b3..5f8c652 100644 --- a/js/playfield.js +++ b/js/playfield.js @@ -11,18 +11,17 @@ document.title = "Playfield|" + window.location.pathname.split('/')[2]; interact.dynamicDrop(true); window.addEventListener('load', () => { - let xhr = new XMLHttpRequest(); - xhr.addEventListener("load", () => { - deckJSON = JSON.parse(xhr.responseText); - deckNum = Object.keys(deckJSON.CustomDeck)[0]; - piles.deck = deckJSON.DeckIDs.map(c => c - deckNum * 100); - cardCount = piles.deck.length; - shuffle(piles.deck); - deckWidth = deckJSON.CustomDeck[deckNum].NumWidth; - deckHeight = deckJSON.CustomDeck[deckNum].NumHeight; - }); - xhr.open("GET", "deck.json"); - xhr.send(); + fetch("deck.json") + .then(data => data.json()) + .then(json => { + deckJSON = json; + deckNum = Object.keys(deckJSON.CustomDeck)[0]; + piles.deck = deckJSON.DeckIDs.map(c => c - deckNum * 100); + cardCount = piles.deck.length; + shuffle(piles.deck); + deckWidth = deckJSON.CustomDeck[deckNum].NumWidth; + deckHeight = deckJSON.CustomDeck[deckNum].NumHeight; + }); window.addEventListener("contextmenu", event => event.preventDefault()); });