 behaviorConfig = null
 behaviorConfigEditor = null
 behaviorEditorEl = document.getElementById 'behaviorConfigEditor'
-behaviorEditorEl.addEventListener 'keydown', (evt) -> confirmChange evt, behaviorConfigEditor, behaviorConfig
+behaviorEditorEl.addEventListener 'keydown', (evt) -> confirmChange evt, behaviorConfig
+
+confirmChange = (evt, config) ->
+	if evt.keyCode is 13 # enter key
+		evt.preventDefault()
+		json = behaviorConfigEditor.get()
+		activeBehavior = behaviorList.getActiveBehavior()
+		activeBehavior.setConfig json
 
 # fill category select
 categoryList = ['action', 'condition', 'other']


exports.disableEditor = ->
	behaviorConfigEditor.setMode 'view'

confirmChange = (evt, editor, config) ->
	if evt.keyCode is 13 # enter key
		evt.preventDefault()
		json = editor.get()
		activeBehavior = behaviorList.getActiveBehavior()
		activeBehavior.setConfig json

	alertify.success 'Image changed'

handleConfigChange = (data) ->
	json = behaviorConfigEditor.get()
	unless json.hasOwnProperty('')
		activeBehavior = behaviorList.getActiveBehavior()
		activeBehavior.setConfig json

getCategory = (behavior) ->
	category = behavior.getMeta()?.category
