2015-01-26 23:57:42 -05:00
|
|
|
class @EditBlob
|
2016-04-11 09:49:25 -04:00
|
|
|
constructor: (assets_path, ace_mode = null) ->
|
|
|
|
ace.config.set "modePath", "#{assets_path}/ace"
|
2015-01-26 23:57:42 -05:00
|
|
|
ace.config.loadModule "ace/ext/searchbox"
|
2016-04-11 09:49:25 -04:00
|
|
|
@editor = ace.edit("editor")
|
|
|
|
@editor.focus()
|
|
|
|
@editor.getSession().setMode "ace/mode/#{ace_mode}" if ace_mode
|
2015-01-26 23:57:42 -05:00
|
|
|
|
2015-10-31 11:06:06 -04:00
|
|
|
# Before a form submission, move the content from the Ace editor into the
|
|
|
|
# submitted textarea
|
2016-04-11 09:49:25 -04:00
|
|
|
$('form').submit =>
|
|
|
|
$("#file-content").val(@editor.getValue())
|
|
|
|
|
|
|
|
@initModePanesAndLinks()
|
|
|
|
new BlobLicenseSelector(@editor)
|
2016-05-13 11:57:03 -04:00
|
|
|
new BlobGitignoreSelectors(editor: @editor)
|
2015-01-26 23:57:42 -05:00
|
|
|
|
2016-04-11 09:49:25 -04:00
|
|
|
initModePanesAndLinks: ->
|
|
|
|
@$editModePanes = $(".js-edit-mode-pane")
|
|
|
|
@$editModeLinks = $(".js-edit-mode a")
|
|
|
|
@$editModeLinks.click @editModeLinkClickHandler
|
2015-01-26 23:57:42 -05:00
|
|
|
|
2016-04-11 09:49:25 -04:00
|
|
|
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-01-27 01:39:48 -05:00
|
|
|
|
2016-04-11 09:49:25 -04:00
|
|
|
else
|
|
|
|
@editor.focus()
|