blob: 3a51ffcecb9a1f856c75a95d884cfe7743835003 (
plain)
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
|
function Markdown() {
}
Markdown.prototype.showPreview = function(e) {
e.preventDefault();
var link = $(this);
var nav = $(this).closest("ul");
var write = $(".write-area");
var preview = $(".preview-area");
var textarea = $("textarea");
var request = $.ajax({
url: "?controller=app&action=preview", // TODO: remoe harcoded url
contentType: "application/json",
type: "POST",
processData: false,
dataType: "html",
data: JSON.stringify({
"text": textarea.val()
})
});
request.done(function(data) {
nav.find("li").removeClass("form-tab-selected");
link.parent().addClass("form-tab-selected");
preview.find(".markdown").html(data)
preview.css("height", textarea.css("height"));
preview.css("width", textarea.css("width"));
write.hide();
preview.show();
});
};
Markdown.prototype.showWriter = function(e) {
e.preventDefault();
$(this).closest("ul").find("li").removeClass("form-tab-selected")
$(this).parent().addClass("form-tab-selected");
$(".write-area").show();
$(".preview-area").hide();
};
Markdown.prototype.listen = function() {
$(document).on("click", "#markdown-preview", this.showPreview.bind(this));
$(document).on("click", "#markdown-write", this.showWriter.bind(this));
};
|