forked from jeromegn/DocumentUp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumentup.js
More file actions
31 lines (27 loc) · 779 Bytes
/
Copy pathdocumentup.js
File metadata and controls
31 lines (27 loc) · 779 Bytes
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
this.DocumentUp = {};
DocumentUp.document = function (opts) {
var repo;
if ("string" === typeof opts) {
repo = opts;
opts = null;
} else {
repo = opts.repo;
delete opts.repo;
}
window.callback = function (resp) {
if (resp.status === 200) {
document.open();
document.write(resp.html);
document.close();
if (opts && opts.afterRender && typeof opts.afterRender === "function")
opts.afterRender()
}
}
var script = document.createElement('script');
script.src = 'http://documentup.com/'+repo
if (opts)
script.src += "?config="+encodeURIComponent(JSON.stringify(opts))+'&callback=callback';
else
script.src += "?callback=callback";
document.getElementsByTagName('head')[0].appendChild(script);
}