Repository navigation
Expand file tree
/
Copy pathbulma.coffee
More file actions
105 lines (83 loc) · 2.46 KB
/
Copy pathbulma.coffee
File metadata and controls
105 lines (83 loc) · 2.46 KB
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
# Create a BULMA object only if one does not already exist. We create the
# methods in a closure to avoid creating global variables.
if typeof BULMA isnt "object"
BULMA = {}
do ->
BULMA.hide = (el) ->
display = BULMA.isVisible(el)
if display
el.style.display = 'none'
return
BULMA.show = (el) ->
display = BULMA.isVisible(el)
if !display
el.style.display = 'block'
return
BULMA.toggle = (el) ->
display = BULMA.isVisible(el)
if !display
el.style.display = 'block'
return
else
el.style.display = 'none'
return
BULMA.getElements = (name) ->
document.querySelectorAll('[data-bulma="' + name + '"]')
BULMA.isVisible = (el) ->
if window.getComputedStyle
display = getComputedStyle(el, null).display
else
display = el.currentStyle.display
return display isnt 'none'
BULMA.hasClass = (el, className) ->
if el.classList
el.classList.contains(className)
else
new RegExp('\\b' + className + '\\b').test(el.className)
BULMA.addClass = (el, className) ->
if el.classList
el.classList.add(className)
else if !BULMA.hasClass(el, className)
el.className += ' ' + className
BULMA.removeClass = (el, className) ->
if el.classList
el.classList.remove(className)
else
el.className = el.className
.replace(new RegExp('\\b'+ className+'\\b', 'g'), '')
BULMA.parseOptions = (el) ->
opts = {}
options = el.getAttribute('data-options')
options = (options || '').replace(/\s/g,'').split(';')
for option in options
if option
option = option.split(':')
opts[option[0]] = option[1]
opts
BULMA.click = (el, handler) ->
if !el.eventListener
el.eventListener = true
el.addEventListener 'click', handler
BULMA.unclick = (el, handler) ->
if el.eventListener
el.eventListener = false
el.removeEventListener 'click', handler
# in case the document is already rendered
if document.readyState isnt 'loading'
BULMA.isReady = true
return
# modern browsers
else if document.addEventListener
document.addEventListener 'DOMContentLoaded', () ->
BULMA.isReady = true
return
# IE <= 8
else document.attachEvent 'onreadystatechange', () ->
if document.readyState is 'complete'
BULMA.isReady = true
return
hashCode = (str) ->
hash = 0
for s, i in str
hash = ~~(((hash << 5) - hash) + str.charCodeAt(i))
hash