diff --git a/.gitignore b/.gitignore index a8b8cb6..5cf11b6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,9 +18,6 @@ app/static/*.js test/*.jtl test/resultado.txt test-reports.xml -recipes/*/assets/barra-brasil.coffee -recipes/*/assets/conteudo-barra.html -recipes/*/assets/conteudo-barra-*.html # Vagrant files # ################# diff --git a/recipes/barra_versao_2/assets/barra-brasil.coffee b/recipes/barra_versao_2/assets/barra-brasil.coffee new file mode 100755 index 0000000..a6cae3c --- /dev/null +++ b/recipes/barra_versao_2/assets/barra-brasil.coffee @@ -0,0 +1,109 @@ + 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) + + script = document.createElement 'script' + script.setAttribute 'src', 'vlibras-plugin.js' + document.body.appendChild script + + script = document.createElement 'script' + script.innerHTML = "function checkVlibrasWidget() { + if (typeof window.VLibras != 'undefined') { + console.log('criando2'); + new window.VLibras.Widget('https://vlibras.gov.br/app'); + console.log('criado'); + } + else { + console.log('tentando novamente'); + window.setTimeout( checkVlibrasWidget, 50 ); + } + } + var divLibras = document.createElement('div'); + divLibras.innerHTML ='