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