-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.js
78 lines (62 loc) · 1.85 KB
/
file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* global app, importFile */
openFile = function (url, first) {
var img = new Image();
img.onload = function () {
var n = (first ? 0 : app.layers.length); //If first== true then n = 0 else n == app.layers.length
if (first) app.layers = [];
app.layers[n] = new createjs.Bitmap(img);
app.layers[n].x = 0;
app.layers[n].y = 0;
app.activateLayer(n);
};
img.src = url;
this.undoBuffer = [];
this.redoBuffer = [];
};
openURL = function (self, url) {
$(self).attr('disabled', true);
openFile(url, !importFile);
hideDialog('#dialog-openurl');
};
saveFile = function () {
window.open(app.stage.toDataURL());
};
printFile = function () {
window.print();
};
app.callbacks.openFile = function (e) {
var file = e.target.files[0],
self = this;
if (!file.type.match('image.*')) return false;
var reader = new FileReader();
reader.onload = function(e) {
openFile(e.target.result, true);
};
reader.readAsDataURL(file);
};
app.callbacks.openURL = function (e) {
switch (e.type) {
case "click":
openURL($('#dialog-openurl input'), $('#dialog-openurl input').val());
break;
case "keydown":
if (e.keyCode === 13) openURL(this, $(this).val());
break;
}
};
app.callbacks.importFile = function (e) {
for (var i = 0, file; file = e.target.files[i]; i++) {
if (!file.type.match('image.*')) continue;
var reader = new FileReader();
reader.onload = function(e) {
openFile(e.target.result, false);
};
reader.readAsDataURL(file);
}
};
app.callbacks.saveFile = function () {
saveFile();
};
app.callbacks.printFile = function () {
printFile();
};