Files
nairobi/app/assets/javascripts/markdown_editor.js.coffee
Javi Martín b27855c1cf Use double quotes in CoffeeScript files
As we do in the rest of the application.

Note we cannot add a rule enforcing double quotes because CoffeeScript
Lint does not have such rule.
2019-03-06 11:41:21 +01:00

46 lines
1.5 KiB
CoffeeScript

App.MarkdownEditor =
refresh_preview: (element, md) ->
textarea_content = App.MarkdownEditor.find_textarea(element).val()
result = md.render(textarea_content)
element.find(".markdown-preview").html(result)
# Multi-locale (translatable) form fields work by hiding inputs of locales
# which are not "active".
find_textarea: (editor) ->
editor.find("textarea")
initialize: ->
$(".markdown-editor").each ->
md = window.markdownit({
html: true,
breaks: true,
typographer: true,
})
editor = $(this)
editor.on "input", ->
App.MarkdownEditor.refresh_preview($(this), md)
$(".legislation-draft-versions-edit .warning").show()
return
editor.find("textarea").on "scroll", ->
editor.find(".markdown-preview").scrollTop($(this).scrollTop())
editor.find(".fullscreen-toggle").on "click", ->
editor.toggleClass("fullscreen")
$(".fullscreen-container").toggleClass("medium-8", "medium-12")
span = $(this).find("span")
current_html = span.html()
if(current_html == span.data("open-text"))
span.html(span.data("closed-text"))
else
span.html(span.data("open-text"))
if editor.hasClass("fullscreen")
App.MarkdownEditor.find_textarea(editor).height($(window).height() - 100)
App.MarkdownEditor.refresh_preview(editor, md)
else
App.MarkdownEditor.find_textarea(editor).height("10em")