gitlab-org--gitlab-foss/app/assets/javascripts/blob/edit_blob.js.coffee

41 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2015-01-26 23:57:42 -05:00
class @EditBlob
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"
@editor = ace.edit("editor")
@editor.focus()
@editor.getSession().setMode "ace/mode/#{ace_mode}" if ace_mode
2015-01-26 23:57:42 -05:00
# Before a form submission, move the content from the Ace editor into the
# submitted textarea
$('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
initModePanesAndLinks: ->
@$editModePanes = $(".js-edit-mode-pane")
@$editModeLinks = $(".js-edit-mode a")
@$editModeLinks.click @editModeLinkClickHandler
2015-01-26 23:57:42 -05: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
else
@editor.focus()