barra-brasil.coffee
2.89 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
divBarra = document.getElementById("barra-brasil")
if divBarra
divBarra.removeAttribute "style"
# conteudoBarra definido no barra-brasil-1.yaml e atribuido pelo assetgen
divBarra.innerHTML = conteudoBarra
head = document.getElementsByTagName("head")[0]
!((window) ->
$q = (q, res) ->
if document.querySelectorAll
res = document.querySelectorAll(q)
else
d = document
a = d.styleSheets[0] or d.createStyleSheet()
a.addRule q, 'f:b'
l = d.all
b = 0
c = []
f = l.length
while b < f
l[b].currentStyle.f and c.push(l[b])
b++
a.removeRule 0
res = c
res
addEventListener = (evt, fn) ->
if window.addEventListener then document.getElementById("logovlibras").addEventListener(evt, fn, false) else if window.attachEvent then document.getElementById("logovlibras").attachEvent('on' + evt, fn) else (@['on' + evt] = fn)
return
_has = (obj, key) ->
Object::hasOwnProperty.call obj, key
images = new Array
query = $q('img.barralazy')
processScroll = ->
i = 0
while i < images.length
if elementInViewport(images[i])
loadImage images[i], ->
images.splice i, i
return
i++
return
loadImage = (el, fn) ->
img = new Image
src = el.getAttribute('data-src')
img.onload = ->
if ! !el.parent
el.parent.replaceChild img, el
else
el.src = src
if fn then fn() else null
return
img.src = src
return
elementInViewport = (el) ->
rect = el.getBoundingClientRect()
rect.top >= 0 and rect.left >= 0 and rect.top <= (window.innerHeight or document.documentElement.clientHeight)
i = 0
while i < query.length
images.push query[i]
i++
addEventListener 'click', processScroll
addEventListener 'mouseover', processScroll
addEventListener 'focus', processScroll
return
)(this)
loadVlibras = ->
window.VLibras.Widget 'https://vlibras.gov.br/app2', 'https://vlibras.gov.br/config/default_logo.json'
divLibras = document.createElement 'div'
divLibras.innerHTML = '<div vw class=\"enabled\"><div vw-access-button class=\"active\"></div><div vw-plugin-wrapper><div class=\"vw-plugin-top-wrapper\"></div><div class=\"vw-links\"><ul></ul></div></div></div>'
document.body.appendChild divLibras
script = document.createElement 'script'
script.setAttribute 'src', 'https://vlibras.gov.br/app2/vlibras-plugin.js'
script.type = "text/javascript"
script.onload = loadVlibras
document.body.appendChild script
window._barrabrasil =
insere_css: (css) ->
style = document.createElement("style")
style.setAttribute "type","text/css"
style.setAttribute "media","all"
style.appendChild document.createTextNode(css)
head.appendChild style