Last change
on this file since 20726 was 20726, checked in by dlcheng, 9 years ago |
ADD (javascript): Adding io/download.js for saving arbitrarily model/variable data. CHG (javascript): Added to Makefile. Minor code cleanup. Starting documentation for js specific code.
|
File size:
893 bytes
|
Rev | Line | |
---|
[20726] | 1 | //DOWNLOAD - save model/variable data to file
|
---|
| 2 | //
|
---|
| 3 | // Usage:
|
---|
| 4 | // download=download('id','slr-download');
|
---|
| 5 | // download=download('id','slr-download','data',md.geometry.thickness,'data',md.results.Stressbalance.Vel);
|
---|
| 6 |
|
---|
| 7 | function download() {
|
---|
| 8 | //Convert arguments to options
|
---|
| 9 | var args = Array.prototype.slice.call(arguments);
|
---|
| 10 | //var options = new pairoptions(args.slice());
|
---|
| 11 |
|
---|
| 12 | //Recover option values:
|
---|
| 13 | // var id = options.getfieldvalue('id','');
|
---|
| 14 | // document.getElementById(id).addEventListener('click', function() {
|
---|
| 15 | // });
|
---|
| 16 |
|
---|
| 17 | var data = {'elements':md.mesh.elements,'x':md.mesh.x,'y':md.mesh.y,'z':md.mesh.z};
|
---|
| 18 | for (var i=2; i < args.length; i+=2) {
|
---|
| 19 | try {
|
---|
| 20 | data[args[i]] = args[i+1];
|
---|
| 21 | }
|
---|
| 22 | catch (e) {
|
---|
| 23 | console.log(e);
|
---|
| 24 | }
|
---|
| 25 | }
|
---|
| 26 | string = JSONfn.stringify(data);
|
---|
| 27 |
|
---|
| 28 | var url='data:text/json:charset=utf8,' + encodeURIComponent(string);
|
---|
| 29 | window.open(url, '_blank');
|
---|
| 30 | window.focus();
|
---|
| 31 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.