-
Notifications
You must be signed in to change notification settings - Fork 4
/
monthEvent.js
130 lines (107 loc) · 2.81 KB
/
monthEvent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import templateEngine from '@pluginjs/template'
import { addClass, removeClass, hasClass } from '@pluginjs/classes'
import { setStyle } from '@pluginjs/styled'
import { bindEvent } from '@pluginjs/events'
import { append, parseHTML, query, setData, insertBefore } from '@pluginjs/dom'
class monthEvents {
constructor(element, month) {
this.$element = element
this.month = month
this.classes = month.classes
this.init()
}
init() {
this.length = 0
this.open = false
this.$more = this.month.getElement('more')
this.$wrap = this.month.getElement('eventsWrap')
this.hideMore()
append(this.$more, this.$wrap)
append(this.$wrap, this.$element)
this.events = []
setData('monthEvent', this, this.$element)
// this.$element.data('monthEvent', this)
this.bind()
}
bind() {
bindEvent(
this.month.instance.eventName('click'),
() => {
this.showList()
},
this.$more
)
}
showList() {
// change wrap height and width
addClass(this.classes.MONTHSHOWLIST, this.$wrap)
//
this.month.activeEvent = this
this.open = true
this.events.map(event => { /* eslint-disable-line */
if (hasClass(this.classes.HIDE, event)) {
removeClass(this.classes.HIDE, event)
}
})
this.hideMore()
}
hideList() {
removeClass(this.classes.MONTHSHOWLIST, this.$wrap)
//
for (let i = 1; i < this.events.length; i++) {
if (!hasClass(this.classes.HIDE, this.events[i])) {
addClass(this.classes.HIDE, this.events[i])
}
}
this.showMore()
}
addEvent(data) {
this.length++
const e = this.createHtml(data)
const point = query('span', e)
setStyle('background-color', data.color, point)
this.events.push(e)
insertBefore(e, this.$more)
this.update()
// this.updateMore()
}
createHtml(data) {
const template = this.month.options.templates.monthEvent
let html = ''
html = templateEngine.render(template.call(this), {
class: this.classes,
data
})
return parseHTML(html)
}
update() {
if (this.length === 1) {
addClass(this.classes.MONTHSINGLEEVENT, this.$wrap)
} else {
removeClass(this.classes.MONTHSINGLEEVENT, this.$wrap)
}
if (this.length > 2) {
this.hideList()
}
}
showMore() {
const t = `+${this.length - 1} more`
this.$more.innerHTML = t
if (hasClass(this.classes.HIDE, this.$more)) {
removeClass(this.classes.HIDE, this.$more)
}
}
hideMore() {
if (!hasClass(this.classes.HIDE, this.$more)) {
addClass(this.classes.HIDE, this.$more)
}
}
destroy() {
this.events.map(item => { /* eslint-disable-line */
item.remove()
})
this.$more.remove()
setData('monthEvent', null, this.$element)
}
}
export default monthEvents