Lines of Code | 49 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | import on from 'on' |
||
2 | import Popup from './popup' |
||
3 | import SmileyData from './smileys' // @Source: http://apps.timwhitlock.info/emoji/tables/unicode |
||
4 | |||
5 | export default class SmileyPicker { |
||
6 | constructor(wrapper) { |
||
7 | this.popup = new Popup(wrapper) |
||
8 | this.wrapper = wrapper |
||
9 | var smileyHTML = '<div class="smiley-title">Emoji</div>' |
||
10 | for(var smileys in SmileyData){ |
||
|
|||
11 | var countSmiley = 0; |
||
12 | smileyHTML += `<div class="smiley-subtitle">${smileys} :</div> |
||
13 | <table cellpadding="0" cellspacing="0"> |
||
14 | <tbody> |
||
15 | <tr>` |
||
16 | SmileyData[smileys].forEach((smiley) => { |
||
17 | if(countSmiley > 9) { |
||
18 | smileyHTML += '</tr><tr>' |
||
19 | countSmiley = 0 |
||
20 | } |
||
21 | smileyHTML += `<td class="wysiwyg-toolbar-smiley" data-smiley="${smiley.icon}"> |
||
22 | <span class="" title="${smiley.desc}" data-smiley="${smiley.icon}">${smiley.icon}</span> |
||
23 | </td>` |
||
24 | countSmiley++ |
||
25 | }) |
||
26 | smileyHTML += `</tr> |
||
27 | </tbody> |
||
28 | </table>` |
||
29 | } |
||
30 | this.wrapper.innerHTML = smileyHTML |
||
31 | this.bindEvt() |
||
32 | } |
||
33 | |||
34 | bindEvt(){ |
||
35 | this.onSmiley = on(this) |
||
36 | this.wrapper.addEventListener('click', (e) => { |
||
37 | var target = e.target |
||
38 | if(target.getAttribute('data-smiley') != null){ |
||
39 | this.onSmiley._fire(` ${target.getAttribute('data-smiley')} `) |
||
40 | this.popup.close() |
||
41 | } |
||
42 | }) |
||
43 | } |
||
44 | |||
45 | show(el){ |
||
46 | var elBounds = el.getBoundingClientRect() |
||
47 | this.popup.open(elBounds.left, (elBounds.top + elBounds.height + 5)) |
||
48 | } |
||
49 | } |
||
50 |
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: