-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagedown_init.js
executable file
·71 lines (62 loc) · 1.9 KB
/
pagedown_init.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
var DjangoPagedown = DjangoPagedown | {};
DjangoPagedown = (function() {
var converter,
editors,
elements;
var that = this;
var isPagedownable = function(el) {
if ( (' ' + el.className + ' ').indexOf(' wmd-input ') > -1 ) {
return true;
}
return false;
};
var createEditor = function(el) {
if ( isPagedownable(el) ) {
if ( ! that.editors.hasOwnProperty(el.id) ) {
var selectors = {
input : el.id,
button : el.id + "_wmd_button_bar",
preview : el.id + "_wmd_preview",
};
that.editors[el.id] = new Markdown.Editor(that.converter, "", selectors);
that.editors[el.id].run();
return true;
} else {
console.log("Pagedown editor already attached to element: <#" + el.id + ">");
}
}
return false;
};
var destroyEditor = function(el) {
if ( that.editors.hasOwnProperty(el.id)) {
delete that.editors[el.id];
return true;
}
return false;
};
var init = function() {
that.converter = Markdown.getSanitizingConverter();
Markdown.Extra.init(that.converter, {
extensions: "all"
});
that.elements = document.getElementsByTagName("textarea");
that.editors = {};
for (var i = 0; i < that.elements.length; ++i){
if ( isPagedownable(that.elements[i]) ) {
createEditor(that.elements[i]);
}
}
};
return {
init: function() {
return init();
},
createEditor: function(el) {
return createEditor(el);
},
destroyEditor: function(el) {
return destroyEditor(el);
},
};
})();
window.onload = DjangoPagedown.init;