-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.js
45 lines (39 loc) · 1.24 KB
/
output.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
const _READ=opera.io.filemode.READ;
var output=
{
file:function(file, response, mime, closeConn)
{
if(file.exists)
{
response.setResponseHeader('content-type', mime);
response.writeFile(file);
}
if(closeConn){ response.close(); }
},
page:function(r, file, template)
{
template=template||{};
template.content=this.template(appDir.resolve('templates/'+file+'.xhtml'), template);
r.setResponseHeader('content-type','application/xhtml+xml');
r.write( this.template(appDir.resolve('templates/page.xhtml'), template) );
r.close();
},
template:function(file, t)
{
var text=file.open(null, _READ).read(file.fileSize, 'utf-8');
for(var k in t){ text=text.replace('{{'+k+'}}', t[k]); }
return text;
},
widget:function(r, filename)
{
var widg=dir.resolve(filename);
if(widg.exists)
{
r.setResponseHeader('content-disposition', 'attachment;filename='+filename);
output.file(widg, r, 'application/x-opera-widgets', 1);
}
r.close();
/* give the user 2 minutes to click through the installation dialogues before deleting the widget installer */
window.setTimeout(function(){ dir.deleteFile(widg); }, 120000);
}
};