Local variables are one of the things CoffeeScript doesn't compile to modern JavaScript automatically: it uses `var` instead of `const` or `let`. Besides, using `$this = $(this)` is usually done to reference the current object in another function where the current object is a different one. Here we were using it with no clear purpose.
48 lines
1.5 KiB
CoffeeScript
48 lines
1.5 KiB
CoffeeScript
"use strict"
|
|
|
|
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")
|
|
|
|
if(span.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")
|