Completed
Push — master ( 395a8a...5b5be3 )
by greg
02:00
created

src/server/public/abejs/scripts/utils/smiley-picker.js   A

Size

Lines of Code 49

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
nc 1
dl 0
loc 49
rs 10
noi 3

1 Function

Rating   Name   Duplication   Size   Complexity  
B smiley-picker.js ➔ ??? 0 27 2
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){
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

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:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
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) {
0 ignored issues
show
Bug introduced by
The variable countSmiley is changed as part of the for-each loop for example by 0 on line 11. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
18
          smileyHTML += '</tr><tr>'
0 ignored issues
show
Bug introduced by
The variable smileyHTML is changed as part of the for-each loop for example by `<div class="smiley-subt... <tr>` on line 12. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
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(`&nbsp;${target.getAttribute('data-smiley')}&nbsp;`)
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