diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-11-20 22:37:10 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-11-20 22:37:10 -0500 |
commit | 2a850757ee5f9c1a2119c562cf6caba3eda7ceba (patch) | |
tree | aff444a2fe18249485f84e71c8bf7ea31bc7dda6 /assets/js/base.js | |
parent | 11b6381cc0f0583a11287202463d20a0ac1ebf00 (diff) |
Add Markdown preview for textarea, see #407
Diffstat (limited to 'assets/js/base.js')
-rw-r--r-- | assets/js/base.js | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/assets/js/base.js b/assets/js/base.js index 0a17696e..d6c332f4 100644 --- a/assets/js/base.js +++ b/assets/js/base.js @@ -65,6 +65,54 @@ var Kanboard = (function() { return true; }, + // Generate Markdown preview + MarkdownPreview: 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", + 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(); + }); + }, + + // Show the Markdown textarea + MarkdownWriter: 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(); + }, + // Common init Init: function() { @@ -84,7 +132,11 @@ var Kanboard = (function() { $("#board-selector").change(function() { window.location = $(this).attr("data-board-url").replace(/%d/g, $(this).val()); }); + + // Markdown Preview for textareas + $("#markdown-preview").click(Kanboard.MarkdownPreview); + $("#markdown-write").click(Kanboard.MarkdownWriter); } }; -})();
\ No newline at end of file +})(); |