# HG changeset patch # User Nicholas Jillings # Date 1433332448 -3600 # Node ID f95a30a25a879464fdf131667b7b0f67a92d3df9 # Parent fa33bf58d8639eb2332b65593a27026408d75c1c create_test: File API to handle dragged in XML file. diff -r fa33bf58d863 -r f95a30a25a87 test_create/test_create.html --- a/test_create/test_create.html Wed Jun 03 12:15:14 2015 +0100 +++ b/test_create/test_create.html Wed Jun 03 12:54:08 2015 +0100 @@ -22,6 +22,12 @@ var setup = document.createElement('div'); setup.id = 'setupTagDiv'; + // Setup drag/drop handles + var dropBody = document.getElementById('dragFile'); + dropBody.addEventListener('dragover', handleDragOver, false); + dropBody.addEventListener('dragenter',handleDragEnter,false); + dropBody.addEventListener('dragleave',handleDragLeave,false); + dropBody.addEventListener('drop', handleDrop,false); }; function attributePair(string, type, mandatory){ @@ -430,6 +436,39 @@ node.appendChild(removeButton); return node; } + + + function handleDragOver(e) { + e.stopPropagation(); + e.preventDefault(); + } + function handleDragEnter(e) { + e.stopPropagation(); + e.preventDefault(); + this.style.backgroundColor = '#AAFFAA'; + } + function handleDragLeave(e) { + e.stopPropagation(); + e.preventDefault(); + this.style.backgroundColor = "#FFFFFF"; + } + function handleDrop(e) { + e.stopPropagation(); + e.preventDefault(); + + var file = e.dataTransfer.files[0]; + + // Uses HTML5 FileAPI - https://w3c.github.io/FileAPI/#filereader-interface + var reader = new FileReader(); + reader.readAsText(file); + var parse = new DOMParser(); + var xml = parse.parseFromString(reader.result,'text/xml'); + importXML(xml); + } + + function importXML(xml) { + console.log(xml); + }

Create Test Setup XML

+
+ Drag and Drop an XML specification file here to auto-load. +