-
Notifications
You must be signed in to change notification settings - Fork 200
/
wmd.js
76 lines (70 loc) · 2.63 KB
/
wmd.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
var Attacklab = Attacklab || {};
Attacklab.wmd_env = {};
Attacklab.account_options = {};
Attacklab.wmd_defaults = {version: 1, output: "HTML", lineLength: 40, delayLoad: false};
if (!Attacklab.wmd) {
Attacklab.wmd = function () {
Attacklab.loadEnv = function () {
var mergeEnv = function (env) {
if (!env) {
return;
}
for (var key in env) {
Attacklab.wmd_env[key] = env[key];
}
};
mergeEnv(Attacklab.wmd_defaults);
mergeEnv(Attacklab.account_options);
mergeEnv(top["wmd_options"]);
Attacklab.full = true;
var buttons = "bold italic | link blockquote code image | ol ul heading hr";
Attacklab.wmd_env.buttons = Attacklab.wmd_env.buttons || buttons;
};
Attacklab.loadEnv();
var files = ["showdown.js", "wmd-base.js", "wmd-plus.js"];
Attacklab.fileLoaded = function (name) {
arguments.callee.count = arguments.callee.count || 0;
if (++arguments.callee.count >= files.length) {
var go = function () {
Attacklab.wmdBase();
Attacklab.Util.startEditor();
};
if (Attacklab.wmd_env.delayLoad) {
window.setTimeout(go, 0);
} else {
go();
}
}
};
Attacklab.editorInit = function () {
Attacklab.wmdPlus();
};
var addScript = function (name, nocache) {
var url = Attacklab.basePath + name;
if (nocache) {
url += "?nocache=" + (new Date()).getTime();
}
var element = document.createElement("script");
element.src = url;
top.document.documentElement.firstChild.appendChild(element);
};
var prefixOf = function (name) {
var re = RegExp("(.*)" + name + "(\\?(.+))?$", "g");
var scriptEls = document.getElementsByTagName("script");
for (var i = 0; i < scriptEls.length; i++) {
if (re.test(scriptEls[i].src)) {
var match = RegExp.$1;
if (/wmd-editor.com/.test(scriptEls[i].src)) {
return null;
}
return match;
}
}
};
Attacklab.basePath = prefixOf("wmd.js") || "http://static.wmd-editor.com/v2/";
for (var f, i = 0; f = files[i]; i++) {
addScript(f, false);
}
};
Attacklab.wmd();
}