| OLD | NEW |
| (Empty) |
| 1 #!mojo mojo:sky_viewer | |
| 2 <!-- | |
| 3 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 4 // Use of this source code is governed by a BSD-style license that can be | |
| 5 // found in the LICENSE file. | |
| 6 --> | |
| 7 <import src="../framework/sky-element/sky-element.sky" as="SkyElement" /> | |
| 8 <import src="../framework/xmlhttprequest.sky" as="XMLHttpRequest" /> | |
| 9 | |
| 10 <sky-element name="file-browser"> | |
| 11 <template> | |
| 12 <style> | |
| 13 heading { | |
| 14 font-size: 16px; | |
| 15 } | |
| 16 </style> | |
| 17 <heading>File browser for {{ url }}</heading> | |
| 18 <template repeat="{{ directories }}"> | |
| 19 <a href="{{}}">{{}}</a> | |
| 20 </template> | |
| 21 <template repeat="{{ files }}"> | |
| 22 <a href="{{}}">{{}}</a> | |
| 23 </template> | |
| 24 </template> | |
| 25 <script> | |
| 26 module.exports = class extends SkyElement { | |
| 27 created() { | |
| 28 this.url = ''; | |
| 29 this.files = []; | |
| 30 this.directories = []; | |
| 31 } | |
| 32 attached() { | |
| 33 this.url = this.ownerDocument.URL; | |
| 34 var xhr = new XMLHttpRequest(); | |
| 35 xhr.open('GET', this.url + '?format=json'); | |
| 36 xhr.onload = (function() { | |
| 37 var listing = JSON.parse(xhr.responseText); | |
| 38 this.files = listing.files; | |
| 39 this.directories = listing.directories; | |
| 40 }).bind(this); | |
| 41 xhr.send(); | |
| 42 } | |
| 43 }.register(); | |
| 44 </script> | |
| 45 </sky-element> | |
| OLD | NEW |