---
---
var inputFile = '{{ site.github.url}}/201541349349307794_public.xml';
var templateFile = '{{ site.github.url}}/form_template.xml';
var inputDom;
var templateDom;

$(function() {
    gatherInputXML();
});

function gatherInputXML() {
    loadXML(inputFile).then(function(response) {
        inputDom = response;
        $('#input-filename').text('Loaded: ' + inputFile.substring(inputFile.lastIndexOf('/')+1));

        // Chain and request the next file
        return loadXML(templateFile);
    }).then(function(response) {
        templateDom = response;
    }).catch(function(error) {
        console.log(error);
    })
}

// A Promise that requests and returns a parsed XML Dom
function loadXML(url) {
    return new Promise (function(resolve, reject) {
        var request = new XMLHttpRequest();
        request.open('GET', url);
        request.responseType = 'document';
        request.onload = function() {
            if(request.status === 200) {
                resolve(request.responseXML);
            } else {
                reject(Error('XML didn\'t load successfully; error code: ' + request.status + ' (' + request.statusText + ')'));
            }
        };
        request.onerror = function() {
            reject(Error('There was a network error.'));
        };
        request.send();
    });
}

@@ -242,25 +242,85 @@
     
-loadXML(inputFile
+Promise.all(%5B%0A        loadXML(inputFile),%0A        loadXML(templateFile)%0A    %5D
 ).th
@@ -331,32 +331,33 @@
 unction(response
+s
 ) %7B%0A        inpu
@@ -367,26 +367,67 @@
 m = response
+s%5B0%5D
 ;%0A
+        templateDom = responses%5B1%5D;%0A%0A
         $('#
@@ -517,153 +517,32 @@
 ));%0A
-%0A        // Chain and request the next file%0A        return loadXML(templateFile);%0A    %7D).then(function(response) %7B%0A        templateDom = response
+        return responses
 ;%0A  
@@ -604,16 +604,17 @@
 ;%0A    %7D)
+;
 %0A%7D%0A%0A// A

reformat Promise to gather input XML in parallel