-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
105 lines (80 loc) · 2.61 KB
/
index.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var files = document.getElementById('files');
function updateDocList() {
var fragment = document.createDocumentFragment();
var sdcard = navigator.getDeviceStorage('sdcard');
var request = sdcard.enumerate('shared_docs');
request.addEventListener('success', function() {
var file = this.result;
console.log(file, this.done);
if(file) {
var name = file.name.split('/').pop();
var elm = document.createElement('div');
elm.className = 'file';
elm.textContent = name;
elm.addEventListener('click', function() {
sdcard.addEventListener('change', function(change) {
if(change.reason === 'modified' && change.path === file.name) {
document.body.appendChild(document.createTextNode('changed ' + file.name));
document.body.appendChild(document.createElement('br'));
}
});
var activity = new MozActivity({
name: 'open',
data: {
/* Firetext and Files */
'type': file.type,
/* Firetext */
'url': file.name,
/* Files */
'name': file.name,
'filename': name,
'blob': file
}
});
activity.addEventListener('success', function() {
//alert('success');
});
activity.addEventListener('error', function() {
if(activity.error.name === 'NO_PROVIDER') {
alert('No app could be found to edit this file. For .html and .txt documents, please install Firetext or Files.');
} else {
console.error(this.error);
alert('An error occurred editing this file: ' + this.error.name);
}
});
});
fragment.appendChild(elm);
}
if(this.done) {
files.innerHTML = '';
files.appendChild(fragment);
} else {
this.continue();
}
});
request.addEventListener('error', function() {
files.textContent = 'No shared files found. Select "Share live" in Firetext or another app to share a file.';
});
}
updateDocList();
if(0) {
navigator.requestWakeLock('cpu'); // Ask Airborn to keep the process open even if the user closes the window.
// Firefox OS does this anyway, but this increases the priority of the process.
navigator.requestWakeLock('high-priority'); // For a future in Firefox OS
/* Airborn OS opens one instance of collabActivity.html per collab request,
* so we don't have to keep track of files as we would have to in Firefox OS.
*/
storage.addEventListener('change', function(change) {
if(change.path === path) {
}
});
var activity = new MozActivity({
name: 'edit',
data: data
});
activity.addEventListener('success', function() {
});
activity.addEventListener('error', function() {
alert(this.error);
});
}