SankeySheets/scripts/FilePicker.js.html
2015-06-06 09:19:42 +01:00

45 lines
No EOL
1.5 KiB
HTML

// the filepicker
function doIt(data) {
google.load ('picker', '1');
google.setOnLoadCallback( function() {
App.initialize();
// fill with svg code
Utils.el("chart-code-svg").value = data.content;
Utils.el("filename-svg").value = Picker.settings.defaultSVGName;
// kick off picker
Utils.el('save-button').addEventListener('click', function () {
Picker.setToken(data.token)
.setName(Utils.el("filename-svg").value)
.setKey(data.key)
// need to tweak the svg code a little and wrap it in xml
.writeContent(Utils.svgWrap(data.content
.replace(/aria-label\s*=\s*"[^"]*"/m,"")
.replace(/style\s*=\s*"[^"]*"/m,"")
.replace(/svg\s/, 'svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" '
)),
// if success, fill up the text boxes with links to the newly created file
function(success) {
Utils.el('filename-url').href = "https://googledrive.com/host/" + success.result.id;
Utils.el('filename-link').href = success.result.alternateLink;
Utils.el('write-result').style.display = 'inline';
Utils.el('filename-svg').value = success.result.title;
},
// the write failed
function (failure) {
App.showNotification ('Writing to drive failed', failure.statusText);
});
}, false);
});
}