diff options
author | fahim-oscad | 2016-07-20 11:55:57 +0530 |
---|---|---|
committer | fahim-oscad | 2016-07-20 11:55:57 +0530 |
commit | 04d16332ffa76380245dae743fc8dd59817253a4 (patch) | |
tree | f5b9dae2a00aa4be48c0873e74b86c2edb6563c6 | |
parent | cb0b1432543ae88f387a9c77b327fa8f1ac219ea (diff) | |
download | eSimWebApp-04d16332ffa76380245dae743fc8dd59817253a4.tar.gz eSimWebApp-04d16332ffa76380245dae743fc8dd59817253a4.tar.bz2 eSimWebApp-04d16332ffa76380245dae743fc8dd59817253a4.zip |
Subject: Download netlist functinality
Description: User can download the netlist.
-rw-r--r-- | views/script/savenetlist.js | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/views/script/savenetlist.js b/views/script/savenetlist.js index 28b6f90..9b3441a 100644 --- a/views/script/savenetlist.js +++ b/views/script/savenetlist.js @@ -18,8 +18,47 @@ jQuery(document).ready(function(){ ------------------------------------------------------------------------------------------------------------------------------------------------*/ jQuery("#webtronics_netlist_text_download").click(function(){ - console.log("button clicked"); - + var netlist = jQuery("#webtronics_netlist_text_area").val(); + // create a new Blob (html5 magic) that conatins the data from your form feild + var textFileAsBlob = new Blob([netlist], {type:'text/plain'}); + + var netListFileName = prompt('Enter name of netlist file to be saved'); + if(!netListFileName){ + alert("Please give the proper name"); + } + + // create a link for our script to 'click' + var downloadLink = document.createElement("a"); + + downloadLink.download = netListFileName+'.cir'; + + // Link Name + downloadLink.innerHTML = "Netlist Download Link"; + + // allow our code to work in webkit & Gecko based browsers + // without the need for a if / else block. + window.URL = window.URL || window.webkitURL; + + // Create the link Object. + downloadLink.href = window.URL.createObjectURL(textFileAsBlob); + // when link is clicked call a function to remove it from + // the DOM in case user wants to save a second file. + downloadLink.onclick = destroyClickedElement; + // make sure the link is hidden. + downloadLink.style.display = "none"; + // add the link to the DOM + document.body.appendChild(downloadLink); + + // click the new link + downloadLink.click(); + + function destroyClickedElement(event) + { + // remove the link from the DOM + document.body.removeChild(event.target); + } + + }); /*------------------------------------------------------------------------------------------------------------------------------------------------ |