Skip to content

Commit 0fdb982

Browse files
committed
emojiPicker('destroy')
1 parent f369414 commit 0fdb982

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ The color of the smiley image that appears on the picker button. Acceptable valu
8282
The background color of the picker button. Any hex value is acceptable. Defaults to '#eee' if no iconBackgroundColor is specified.
8383

8484
### recentCount (int) ###
85-
The number of emojis that should show in the 'Recently Used' section. Defaults to 36 if no recentCount is specified.
85+
The number of emojis that should show in the 'Recently Used' section. Defaults to 36 if no recentCount is specified.
8686

8787
Note: 'Recently Used' will only show for the user if their browser supports HTML5 Local Storage.
8888

@@ -121,6 +121,18 @@ $('#question').emojiPicker('toggle');
121121

122122
You can see an example of this in the [demo](http://wedgies.github.io/jquery-emoji-picker/demo.html).
123123

124+
## Destroying the Emoji Picker ##
125+
126+
To remove the the emoji picker html and event listeners, simply call the emoji picker function with the `destroy` option:
127+
128+
```javascript
129+
$('#question').emojiPicker('destroy');
130+
```
131+
132+
An example of this can be found in the [demo](http://wedgies.github.io/jquery-emoji-picker/demo.html).
133+
134+
135+
124136
## Notes ##
125137

126138
jQuery Emoji Picker is disabled for mobile devices, which already support the emoji keyboard.

demo.html

+21-9
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
<script type="text/javascript">
1414
$(document).ready(function(e) {
1515

16-
$('#text-custom-trigger').emojiPicker({
17-
width: '300px',
18-
height: '200px',
19-
button: false
20-
});
21-
2216
$('#input-default').emojiPicker();
2317

2418
$('#input-custom-size').emojiPicker({
@@ -30,12 +24,26 @@
3024
position: 'left'
3125
});
3226

33-
$('#trigger').click(function(e) {
27+
$('#create').click(function(e) {
28+
e.preventDefault();
29+
$('#text-custom-trigger').emojiPicker({
30+
width: '300px',
31+
height: '200px',
32+
button: false
33+
});
34+
});
35+
36+
$('#toggle').click(function(e) {
3437
e.preventDefault();
3538
$('#text-custom-trigger').emojiPicker('toggle');
3639
});
3740

38-
// keyup event is fired
41+
$('#destroy').click(function(e) {
42+
e.preventDefault();
43+
$('#text-custom-trigger').emojiPicker('destroy');
44+
})
45+
46+
// keyup event is fired
3947
$(".emojiable-question, .emojiable-option").on("keyup", function () {
4048
//console.log("emoji added, input val() is: " + $(this).val());
4149
});
@@ -58,7 +66,11 @@
5866
<!-- &#x1F335; -->
5967
<form>
6068

61-
<button id="trigger">Custom emoji trigger</button>
69+
<button id="create">create</button>
70+
71+
<button id="toggle">toggle</button>
72+
73+
<button id="destroy">destroy</button>
6274

6375
<div class="field">
6476
<textarea id="text-custom-trigger" class="emojiable-question" placeholder="Your Question"></textarea>

js/jquery.emojipicker.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@
127127

128128
},
129129

130+
destroyPicker: function() {
131+
this.$picker.unbind('mouseover');
132+
this.$picker.unbind('mouseout');
133+
this.$picker.unbind('click');
134+
this.$picker.remove();
135+
136+
$.removeData(this.$el.get(0), 'emojiPicker');
137+
138+
return this;
139+
},
140+
130141
listen: function() {
131142
// If the button is being used, wrapper has not been set,
132143
// and will not need a listener
@@ -392,7 +403,10 @@
392403
switch(options) {
393404
case 'toggle':
394405
plugin.iconClicked();
395-
break;
406+
break;
407+
case 'destroy':
408+
plugin.destroyPicker();
409+
break;
396410
}
397411
});
398412
return this;

0 commit comments

Comments
 (0)