2015-04-26 12:48:37 +05:30
|
|
|
class @EditBlob
|
|
|
|
constructor: (assets_path, mode)->
|
|
|
|
ace.config.set "modePath", assets_path + '/ace'
|
|
|
|
ace.config.loadModule "ace/ext/searchbox"
|
|
|
|
if mode
|
|
|
|
ace_mode = mode
|
|
|
|
editor = ace.edit("editor")
|
|
|
|
editor.focus()
|
|
|
|
@editor = editor
|
|
|
|
|
|
|
|
if ace_mode
|
|
|
|
editor.getSession().setMode "ace/mode/" + ace_mode
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
# Before a form submission, move the content from the Ace editor into the
|
|
|
|
# submitted textarea
|
|
|
|
$('form').submit ->
|
|
|
|
$("#file-content").val(editor.getValue())
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
editModePanes = $(".js-edit-mode-pane")
|
|
|
|
editModeLinks = $(".js-edit-mode a")
|
|
|
|
editModeLinks.click (event) ->
|
|
|
|
event.preventDefault()
|
|
|
|
currentLink = $(this)
|
|
|
|
paneId = currentLink.attr("href")
|
|
|
|
currentPane = editModePanes.filter(paneId)
|
|
|
|
editModeLinks.parent().removeClass "active hover"
|
|
|
|
currentLink.parent().addClass "active hover"
|
|
|
|
editModePanes.hide()
|
|
|
|
if paneId is "#preview"
|
|
|
|
currentPane.fadeIn 200
|
|
|
|
$.post currentLink.data("preview-url"),
|
|
|
|
content: editor.getValue()
|
|
|
|
, (response) ->
|
|
|
|
currentPane.empty().append response
|
2016-02-05 20:25:01 +05:30
|
|
|
currentPane.syntaxHighlight()
|
2015-04-26 12:48:37 +05:30
|
|
|
return
|
|
|
|
|
|
|
|
else
|
|
|
|
currentPane.fadeIn 200
|
|
|
|
editor.focus()
|
|
|
|
return
|
|
|
|
|
|
|
|
editor: ->
|
|
|
|
return @editor
|