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

44 lines
1.2 KiB
CoffeeScript
Raw Normal View History

2015-01-26 23:57:42 -05:00
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()
2015-01-27 01:39:48 -05:00
@editor = editor
2015-01-26 23:57:42 -05:00
if ace_mode
editor.getSession().setMode "ace/mode/" + ace_mode
$(".js-commit-button").click ->
$("#file-content").val editor.getValue()
$(".file-editor form").submit()
2015-03-04 12:56:41 -05:00
return false
2015-01-26 23:57:42 -05:00
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
return
else
currentPane.fadeIn 200
editor.focus()
return
2015-01-27 01:39:48 -05:00
editor: ->
return @editor