app/assets/javascripts/locomotive/views/inputs/rte_view.js.coffee.erb in locomotivecms-3.0.0.pre.alpha.2 vs app/assets/javascripts/locomotive/views/inputs/rte_view.js.coffee.erb in locomotivecms-3.0.0.pre.alpha.3
- old
+ new
@@ -4,18 +4,24 @@
events:
'click a.style': 'open_styles_dialog'
initialize: ->
+ _.bindAll(@, 'register_keydown_event', 'on_content_change')
+
$textarea = @$('textarea')
@editor = new wysihtml5.Editor $textarea.attr('id'),
toolbar: "wysihtml5-toolbar-#{$textarea.attr('id')}"
useLineBreaks: false
parserRules: wysihtml5ParserRules
stylesheets: ['<%= stylesheet_path("locomotive/wysihtml5_editor") %>']
+ @editor.on 'load', @register_keydown_event
+ @editor.on 'change', @on_content_change
+ @editor.on 'aftercommand:composer', @on_content_change
+
that = @
setTimeout(
->
that.create_link_view()
that.create_file_view()
@@ -44,11 +50,23 @@
el: @$('a[data-wysihtml5-command=insertFile]')
editor: @editor
@file_view.render()
+ register_keydown_event: ->
+ @$('.wysihtml5-sandbox').contents().find('body').on 'keyup', =>
+ @on_content_change()
+
+ on_content_change: ->
+ PubSub.publish 'inputs.text_changed',
+ view: @
+ content: @editor.getValue()
+
remove: ->
@link_view.remove()
@file_view.remove()
+
+ @editor.stopObserving('onLoad', @register_keydown_event)
+ @editor.stopObserving('onChange', @on_content_change)
super