From f3cd556099950b7f7ce70cb82fb804deb5d0055e Mon Sep 17 00:00:00 2001 From: Roel Walraven Date: Fri, 24 Feb 2017 14:10:16 +0100 Subject: [PATCH] Add method to load JSON from file --- src/LightDMMock.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/LightDMMock.js b/src/LightDMMock.js index 85afd72..2182653 100644 --- a/src/LightDMMock.js +++ b/src/LightDMMock.js @@ -529,6 +529,33 @@ window.checkForUpdate = function(currentVersion) { request.send(); }; +/** + * global helper loadJSON + * Loads JSON from a path. Removes the need to b64 encode them in this file. + * + * @param {String} url [path to JSON file] + * @param {Function} callback [callback function] + */ +window.loadJSON = function(url, callback) { + var request = new XMLHttpRequest(); + + var onSuccess = function() { + this.callback.apply(request, request.arguments); + }; + + var onFailure = function() { + window.console.error(this.statusText); + }; + + request.callback = callback; + request.arguments = Array.prototype.slice.call(arguments, 2); + request.onload = onSuccess; + request.onerror = onFailure; + + request.open("get", url, true); + request.send(null); +}; + /****************************************************************************** * Object.watch shim *