Permalink
Browse files

Content cleanup hook for plugins

  • Loading branch information...
1 parent fa93871 commit bec025955f3849fb40cc642285c7ea8bb7478414 Szaby Grünwald committed Mar 29, 2012
Showing with 58 additions and 45 deletions.
  1. +2 −2 examples/hallo-min.js
  2. +31 −23 examples/hallo.js
  3. +5 −1 src/hallo.coffee
  4. +20 −19 src/plugins/annotate.coffee
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -227,7 +227,11 @@ Hallo may be freely distributed under the MIT license
# Get contents of an editable as HTML string
getContents: ->
- @element.html()
+ # clone
+ contentClone = @element.clone()
+ for plugin of @options.plugins
+ jQuery(@element)[plugin] 'cleanupContentClone', contentClone
+ contentClone.html()
# Set the contents of an editable
setContents: (contents) ->
@@ -30,7 +30,7 @@
# states are off, working, on
@state = 'off'
- buttonHolder = jQuery "<span class=\"#{widget.widgetName}\"></span>"
+ buttonHolder = jQuery '<span class="#{widget.widgetName}"></span>'
@button = buttonHolder.hallobutton
label: ''
icon: 'icon-tags'
@@ -50,22 +50,16 @@
@options.toolbar.append @button
@instantiate()
+ turnOffAnnotate = ->
+ editable = @
+ jQuery(editable).halloannotate 'done'
editableElement = @options.editable.element
- queryState = (event) =>
- if document.queryCommandState @options.command
- @button.attr 'checked', true
- @button.next('label').addClass 'ui-state-clicked'
- @button.button 'refresh'
- return
- @button.attr 'checked', false
- @button.next('label').removeClass 'ui-state-clicked'
- @button.button 'refresh'
-
- editableElement.bind 'halloenabled', =>
- editableElement.bind 'keyup paste change mouseup hallomodified', queryState
- editableElement.bind 'hallodisabled', =>
- editableElement.unbind 'keyup paste change mouseup hallomodified', queryState
+ editableElement.bind 'hallodisabled', turnOffAnnotate
+ cleanupContentClone: (el) ->
+ if @state is 'on'
+ el.find(".entity:not([about])").each () ->
+ jQuery(@).replaceWith jQuery(@).html()
instantiate: ->
@options.editable.element.annotate
@@ -76,21 +70,28 @@
remove: @options.remove
success: @options.success
error: @options.error
- # @buttons.acceptAll.hide()
+ .bind 'annotateselect', ->
+ jQuery.noop()
+ # console.info @, arguments
+ .bind 'annotateremove', ->
+ jQuery.noop()
+ # console.info @, arguments
+
enhance: ->
widget = @
- @button.hallobutton "disable"
+ @button.hallobutton 'disable'
try
@options.editable.element.annotate 'enable', (success) =>
if success
- @state = "on"
- @button.hallobutton "enable"
+ @state = 'on'
+ @button.hallobutton 'enable'
else
@buttons.enhance.show()
.button('enable')
.button 'option', 'label', 'error, see the log.. Try to enhance again!'
catch e
alert e
+
done: ->
@options.editable.element.annotate 'disable'
@state = 'off'

0 comments on commit bec0259

Please sign in to comment.