Permalink
Browse files

Handle toolbar destruction

  • Loading branch information...
1 parent ab324fc commit f1bffa9ec46e74d38c17d150fc602c78f57bb84c @bergie committed Sep 24, 2012
Showing with 45 additions and 4 deletions.
  1. +2 −2 examples/hallo-min.js
  2. +1 −0 examples/hallo.js
  3. +4 −1 src/hallo.coffee
  4. +35 −1 test/hallo.coffee
  5. +3 −0 test/index.html
Oops, something went wrong.
View
@@ -69,6 +69,7 @@ http://hallojs.org
this.disable();
if (this.toolbar) {
this.toolbar.remove();
+ this.element[this.options.toolbar]('destroy');
}
_ref = this.options.plugins;
for (plugin in _ref) {
View
@@ -132,7 +132,10 @@ http://hallojs.org
destroy: ->
@disable()
- @toolbar.remove() if @toolbar
+
+ if @toolbar
+ @toolbar.remove()
+ @element[@options.toolbar] 'destroy'
for plugin, options of @options.plugins
jQuery(@element)[plugin] 'destroy'
View
@@ -16,8 +16,11 @@ test 'Hallo instantiation and destruction', ->
# Activate to get toolbar
do fixture.focus
- equal jQuery('.hallotoolbar').length, 1
ok fixture.hasClass 'inEditMode'
+ ok fixture.data('halloToolbarContextual')
+ equal jQuery('.hallotoolbar').length, 1
+ # Contextual toolbar shouldn't be visible without a selection
+ equal jQuery('.hallotoolbar:visible').length, 0
# Check also the instance data
instance = fixture.data 'hallo'
@@ -31,6 +34,7 @@ test 'Hallo instantiation and destruction', ->
do stop
fixture.hallo 'destroy'
equal fixture.data('hallo'), undefined
+ equal fixture.data('halloToolbarContextual'), undefined
equal jQuery('.hallotoolbar').length, 0
equal fixture.hasClass('inEditMode'), false
@@ -89,3 +93,33 @@ test 'Hallo modification events', ->
fixture.html 'h'
do stop
fixture.trigger press
+
+test 'Hallo fixed toolbar', ->
+ fixture = jQuery '.hallo-modified p.editable'
+
+ # Instantiate
+ fixture.hallo
+ toolbar: 'halloToolbarFixed'
+ instance = fixture.data 'hallo'
+
+ # We shouldn't have a toolbar before first focus
+ equal fixture.data('halloToolbarFixed'), undefined
+
+ do fixture.focus
+ ok fixture.data('halloToolbarFixed')
+ equal fixture.data('halloToolbarContextual'), undefined
+ equal jQuery('.hallotoolbar:visible').length, 1
+ equal jQuery('.hallotoolbar:hidden').length, 0
+
+ do fixture.blur
+ equal jQuery('.hallotoolbar:visible').length, 0
+ equal jQuery('.hallotoolbar:hidden').length, 1
+ ok fixture.data('halloToolbarFixed')
+
+ do fixture.focus
+ equal jQuery('.hallotoolbar:visible').length, 1
+ equal jQuery('.hallotoolbar:hidden').length, 0
+
+ do fixture.blur
+ equal jQuery('.hallotoolbar:visible').length, 0
+ equal jQuery('.hallotoolbar:hidden').length, 1
View
@@ -36,6 +36,9 @@ <h2 id="qunit-userAgent"></h2>
<div class="hallo-modified">
<p class="editable"></p>
</div>
+ <div class="hallo-toolbar">
+ <p class="editable"></p>
+ </div>
</div>
</body>
</html>

0 comments on commit f1bffa9

Please sign in to comment.