UNPKG

api-console-assets

Version:

This repo only exists to publish api console components to npm

117 lines (104 loc) 3.89 kB
<!doctype html> <!-- @license Copyright (c) 2015 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt --> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes"> <title>web-unzip demo</title> <script src="../../webcomponentsjs/webcomponents-lite.js"></script> <link rel="import" href="../../file-drop/file-drop.html"> <link rel="import" href="../../iron-demo-helpers/demo-pages-shared-styles.html"> <link rel="import" href="../../iron-demo-helpers/demo-snippet.html"> <link rel="import" href="../../paper-styles/paper-styles.html"> <link rel="import" href="../../paper-spinner/paper-spinner.html"> <link rel="import" href="../web-unzip.html"> <link rel="import" href="folder-browser.html"> <style is="custom-style" include="demo-pages-shared-styles"> .vertical-section-container { max-width: 600px; } h1 { @apply --paper-font-title; } </style> </head> <body unresolved> <template is="dom-bind" id="app"> <div class="vertical-section-container centered"> <h1>Drop a file here.</h1> <file-drop multiple file="{{file}}" on-file-accepted="fileListChanged"></file-drop> <web-unzip id="unzip" file-structure="{{fileStructure}}"></web-unzip> <template is="dom-if" if="[[file]]"> <paper-spinner active="[[isLoading]]">Loading</paper-spinner> <p hidden$="[[!isMultiple]]">Multiple files are not supported</p> <p hidden$="[[isZip]]">File is not a zip file</p> <folder-browser files="[[fileStructure]]" on-download-file="_handleDownload"></folder-browser> </template> </div> </template> <script> (function(scope) { var URL = window.mozURL || window.URL; scope.file = undefined; scope.isZip = true; scope.isLoading = false; scope.isMultiple = false; scope.fileStructure = undefined; function reset() { scope.isZip = true; scope.isLoading = false; scope.isMultiple = false; } scope.fileListChanged = function(e) { reset(); var file = e.detail.file; if (!file) { return; } if (file.length > 1) { scope.isMultiple = true; return; } if (!file[0].name || file[0].name.indexOf('.zip') === -1) { scope.isZip = false; return; } scope.isLoading = true; document.querySelector('web-unzip').file = file; }; scope._onFileStructureRead = function() { scope.isLoading = false; }; scope._handleDownload = function(e) { var filename = e.detail.filename; scope.$.unzip.getFileContent(filename) .then(function(file) { var url = URL.createObjectURL(file); var a = document.createElement('a'); a.href = url; a.download = file.name; Polymer.dom(scope.root).appendChild(a); var clickEvent = document.createEvent('MouseEvent'); clickEvent.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); a.dispatchEvent(clickEvent); Polymer.dom(scope.root).removeChild(a); }) .catch(function(cause) { console.error(cause); }); }; window.addEventListener('web-unzip-file-structure', scope._onFileStructureRead); })(document.querySelector('#app')); </script> </body> </html>