Skip to content
This repository

namespace the events for popover/tooltip #4104

Merged
merged 4 commits into from over 1 year ago

3 participants

Jon Stevens Don't Add Me To Your Organization a.k.a The Travis Bot Jacob
Jon Stevens

namespace the events for popover/tooltip so that they can be cleanly removed.

references issue #3880

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 2ee9b27 into 40ab928).

Jon Stevens

I wasn't sure what you wanted for the config key name... ns seemed short and sweet, but i'm open to changing it however you want.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 117f65d into 40ab928).

Jacob
Owner
fat commented July 22, 2012

Hey @lookfirst,

Thanks for opening this pull-request! Unfotunately, it looks like it fails to pass the tests neccessary for submitting to bootstrap. The following tests are currently failing:

  • should always include a unit test if changing js files

For a full list of issue filing guidelines, please refer to the bootstrap issue filing guidelines.

thanks!

Jacob fat closed this July 22, 2012
Jon Stevens

@fat umm... I did include tests.

Jacob fat reopened this July 22, 2012
Jacob
Owner
fat commented July 22, 2012

weird, sorry about that

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 117f65d into 40ab928).

js/bootstrap-popover.js
@@ -72,7 +72,8 @@
72 72
     }
73 73
 
74 74
   , destroy: function () {
75  
-      this.$element.off().removeData('popover')
  75
+      this.hide()
  76
+      this.$element.off(this.options.ns).removeData('popover')
2
Jon Stevens
lookfirst added a note July 22, 2012

just realized that this could be combined into this.hide().off(this.options.ns)... if you like.

Jacob Owner
fat added a note July 22, 2012

yes pls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Jacob
Owner
fat commented July 22, 2012

any reason not to just always use the prefix .tooltip and .popover? Not super crazy about adding an option for that

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged 393f4a7 into 40ab928).

Jon Stevens

i'm not super crazy about the option either, but i could easily see a generic word like those being used by other plugins.

how about something a bit less generic like bs-popover/bs-tooltip?

Jacob
Owner
fat commented July 22, 2012

well... everywhere else we just use "modal" or "button". I don't think it's too big of a deal. If you have two different tooltip plugins instantiated on the same element you probably have bigger problems ;)

In the future we'll probably namespace everything with bootstrap (data-attrs and events - but that will be a 3.0.0 thing, because it's breaks backwards compatibility)

Jon Stevens

ok, i'll hardcode it then.

Jacob
Owner
fat commented July 22, 2012

cool thanks :)

Jon Stevens

Oh, looking at that more closely now, I know why I did that... popover extends tooltip and tooltip.init() is where the .on() is... I needed to define the name of the plugin somewhere...

Jacob
Owner
fat commented July 22, 2012

this.type will equal 'popover' or 'tooltip' - it's assigned in the init method

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged d76c899 into 40ab928).

Jon Stevens

ah, missed that. should be good now. all tests pass.

Jacob fat merged commit 48fc0ad into from July 22, 2012
Jacob fat closed this July 22, 2012
Jacob
Owner
fat commented July 22, 2012

great - thanks man!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4  docs/templates/pages/javascript.mustache
@@ -780,7 +780,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
780 780
         <p>{{_i}}Toggles an element's tooltip.{{/i}}</p>
781 781
         <pre class="prettyprint linenums">$('#element').tooltip('toggle')</pre>
782 782
         <h4>.tooltip('destroy')</h4>
783  
-        <p>{{_i}}Destroys an element's tooltip.{{/i}}</p>
  783
+        <p>{{_i}}Hides and destroys an element's tooltip.{{/i}}</p>
784 784
         <pre class="prettyprint linenums">$('#element').tooltip('destroy')</pre>
785 785
       </section>
786 786
 
@@ -935,7 +935,7 @@ $('a[data-toggle="tab"]').on('shown', function (e) {
935 935
         <p>{{_i}}Toggles an elements popover.{{/i}}</p>
936 936
         <pre class="prettyprint linenums">$('#element').popover('toggle')</pre>
937 937
         <h4>.popover('destroy')</h4>
938  
-        <p>{{_i}}Destroys an element's popover.{{/i}}</p>
  938
+        <p>{{_i}}Hides and destroys an element's popover.{{/i}}</p>
939 939
         <pre class="prettyprint linenums">$('#element').popover('destroy')</pre>
940 940
       </section>
941 941
 
2  js/bootstrap-popover.js
@@ -72,7 +72,7 @@
72 72
     }
73 73
 
74 74
   , destroy: function () {
75  
-      this.$element.off().removeData('popover')
  75
+      this.hide().$element.off('.' + this.type).removeData(this.type)
76 76
     }
77 77
 
78 78
   })
8  js/bootstrap-tooltip.js
@@ -47,8 +47,8 @@
47 47
       if (this.options.trigger != 'manual') {
48 48
         eventIn  = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
49 49
         eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
50  
-        this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
51  
-        this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
  50
+        this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
  51
+        this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
52 52
       }
53 53
 
54 54
       this.options.selector ?
@@ -176,6 +176,8 @@
176 176
       $.support.transition && this.$tip.hasClass('fade') ?
177 177
         removeWithAnimation() :
178 178
         $tip.remove()
  179
+        
  180
+      return this
179 181
     }
180 182
 
181 183
   , fixTitle: function () {
@@ -236,7 +238,7 @@
236 238
     }
237 239
 
238 240
   , destroy: function () {
239  
-      this.$element.off().removeData('tooltip')
  241
+      this.hide().$element.off('.' + this.type).removeData(this.type)
240 242
     }
241 243
 
242 244
   }
8  js/tests/unit/bootstrap-popover.js
@@ -92,12 +92,16 @@ $(function () {
92 92
       })
93 93
 
94 94
       test("should destroy popover", function () {
95  
-        var popover = $('<div/>').popover()
  95
+        var popover = $('<div/>').popover().on('click.foo', function(){})
96 96
         ok(popover.data('popover'), 'popover has data')
97 97
         ok(popover.data('events').mouseover && popover.data('events').mouseout, 'popover has hover event')
  98
+        ok(popover.data('events').click[0].namespace == 'foo', 'popover has extra click.foo event')
  99
+        popover.popover('show')
98 100
         popover.popover('destroy')
  101
+        ok(!popover.hasClass('in'), 'popover is hidden')
99 102
         ok(!popover.data('popover'), 'popover does not have data')
100  
-        ok(!popover.data('events'), 'popover does not have any events')
  103
+        ok(popover.data('events').click[0].namespace == 'foo', 'popover still has click.foo')
  104
+        ok(!popover.data('events').mouseover && !popover.data('events').mouseout, 'popover does not have any events')
101 105
       })
102 106
       
103 107
 })
8  js/tests/unit/bootstrap-tooltip.js
@@ -129,12 +129,16 @@ $(function () {
129 129
       })
130 130
 
131 131
       test("should destroy tooltip", function () {
132  
-        var tooltip = $('<div/>').tooltip()
  132
+        var tooltip = $('<div/>').tooltip().on('click.foo', function(){})
133 133
         ok(tooltip.data('tooltip'), 'tooltip has data')
134 134
         ok(tooltip.data('events').mouseover && tooltip.data('events').mouseout, 'tooltip has hover event')
  135
+        ok(tooltip.data('events').click[0].namespace == 'foo', 'tooltip has extra click.foo event')
  136
+        tooltip.tooltip('show')
135 137
         tooltip.tooltip('destroy')
  138
+        ok(!tooltip.hasClass('in'), 'tooltip is hidden')
136 139
         ok(!tooltip.data('tooltip'), 'tooltip does not have data')
137  
-        ok(!tooltip.data('events'), 'tooltip does not have any events')
  140
+        ok(tooltip.data('events').click[0].namespace == 'foo', 'tooltip still has click.foo')
  141
+        ok(!tooltip.data('events').mouseover && !tooltip.data('events').mouseout, 'tooltip does not have any events')
138 142
       })
139 143
 
140 144
 })
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.