5
5
// This is a port of "Reading Files in JavaScript Using the File APIs" to Dart.
6
6
// See: http://www.html5rocks.com/en/tutorials/file/dndfiles/
7
7
8
+ import 'dart:convert' show HtmlEscape;
8
9
import 'dart:html' ;
9
- import 'package:dart_samples/htmlescape.dart' ;
10
+
10
11
11
12
class DndFiles {
12
13
FormElement _readForm;
13
14
InputElement _fileInput;
14
15
Element _dropZone;
15
16
OutputElement _output;
17
+ HtmlEscape sanitizer = new HtmlEscape ();
16
18
17
19
DndFiles () {
18
- _output = document.query ('#list' );
19
- _readForm = document.query ('#read' );
20
- _fileInput = document.query ('#files' );
20
+ _output = document.querySelector ('#list' );
21
+ _readForm = document.querySelector ('#read' );
22
+ _fileInput = document.querySelector ('#files' );
21
23
_fileInput.onChange.listen ((e) => _onFileInputChange ());
22
24
23
- _dropZone = document.query ('#drop-zone' );
25
+ _dropZone = document.querySelector ('#drop-zone' );
24
26
_dropZone.onDragOver.listen (_onDragOver);
25
27
_dropZone.onDragEnter.listen ((e) => _dropZone.classes.add ('hover' ));
26
28
_dropZone.onDragLeave.listen ((e) => _dropZone.classes.remove ('hover' ));
@@ -58,7 +60,7 @@ class DndFiles {
58
60
reader.onLoad.listen ((e) {
59
61
var thumbnail = new ImageElement (src: reader.result);
60
62
thumbnail.classes.add ('thumb' );
61
- thumbnail.title = htmlEscape (file.name);
63
+ thumbnail.title = sanitizer. convert (file.name);
62
64
thumbHolder.nodes.add (thumbnail);
63
65
});
64
66
reader.readAsDataUrl (file);
@@ -68,9 +70,9 @@ class DndFiles {
68
70
// For all file types, display some properties.
69
71
var properties = new Element .tag ('span' );
70
72
properties.innerHtml = (new StringBuffer ('<strong>' )
71
- ..write (htmlEscape (file.name))
73
+ ..write (sanitizer. convert (file.name))
72
74
..write ('</strong> (' )
73
- ..write (file.type != null ? htmlEscape (file.type) : 'n/a' )
75
+ ..write (file.type != null ? sanitizer. convert (file.type) : 'n/a' )
74
76
..write (') ' )
75
77
..write (file.size)
76
78
..write (' bytes' )
0 commit comments