Commit c1ea6cc6f799896301ec562c4f7d5d4e81d086dc
1 parent
ea70d84a
Exists in
master
Fix some bugs
Showing
5 changed files
with
54 additions
and
39 deletions
Show diff stats
.gitignore
VLibrasWeb/vlibras-player.js
VLibrasWeb/vlibras-web.css
| ... | ... | @@ -67,25 +67,23 @@ |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | .vlibras-widget .vw-player { |
| 70 | - visibility: hidden; | |
| 71 | - width: 0; | |
| 70 | + display: none; | |
| 71 | + width: 320px; | |
| 72 | 72 | height: 100%; |
| 73 | 73 | float: right; |
| 74 | 74 | |
| 75 | 75 | background-color: #ebebeb; |
| 76 | 76 | |
| 77 | - display: -webkit-flex; | |
| 78 | - display: flex; | |
| 79 | - flex-direction: column; | |
| 80 | - | |
| 81 | 77 | -webkit-box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75); |
| 82 | 78 | -moz-box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75); |
| 83 | 79 | box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75); |
| 84 | 80 | } |
| 85 | 81 | |
| 86 | 82 | .vlibras-widget .vw-player.active { |
| 87 | - width: 320px; | |
| 88 | - visibility: visible; | |
| 83 | + display: -webkit-flex; | |
| 84 | + display: flex; | |
| 85 | + flex-direction: column; | |
| 86 | + -webkit-flex-direction: column; | |
| 89 | 87 | } |
| 90 | 88 | |
| 91 | 89 | .vw-player .vw-canvas-wrapper { |
| ... | ... | @@ -103,7 +101,7 @@ |
| 103 | 101 | display: none; |
| 104 | 102 | } |
| 105 | 103 | |
| 106 | -.vw-player.loaded .vw-subtitle { | |
| 104 | +.vw-player.loaded:not(.error) .vw-subtitle { | |
| 107 | 105 | display: block; |
| 108 | 106 | } |
| 109 | 107 | |
| ... | ... | @@ -187,7 +185,7 @@ |
| 187 | 185 | -webkit-align-items: center; |
| 188 | 186 | } |
| 189 | 187 | |
| 190 | -.vw-player.loaded .vw-controls { | |
| 188 | +.vw-player.loaded:not(.error) .vw-controls { | |
| 191 | 189 | visibility: visible; |
| 192 | 190 | } |
| 193 | 191 | |
| ... | ... | @@ -226,6 +224,8 @@ |
| 226 | 224 | |
| 227 | 225 | .vw-window { |
| 228 | 226 | cursor: pointer; |
| 227 | + flex-shrink: 0; | |
| 228 | + -webkit-flex-shrink: 0; | |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | .vw-window .vw-maximize, .vw-window.active .vw-minimize { |
| ... | ... | @@ -275,6 +275,7 @@ |
| 275 | 275 | height: 50px; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | -.vw-loading.active, .vw-error.active { | |
| 278 | +.vw-player:not(.error) .vw-loading.active, | |
| 279 | +.vw-player.error .vw-error { | |
| 279 | 280 | display: block; |
| 280 | 281 | } | ... | ... |
VLibrasWeb/vlibras-web.js
| ... | ... | @@ -40,9 +40,8 @@ |
| 40 | 40 | var vwPlay = vwControls.querySelector('.vw-play'); |
| 41 | 41 | |
| 42 | 42 | VLibrasPlayer.addProgressListener(function (progress) { |
| 43 | - var vwText = document.querySelector('.vw-text.active'); | |
| 44 | - if (progress >= 1 && vwText) { | |
| 45 | - vwText.classList.remove('active'); | |
| 43 | + if (progress >= 1) { | |
| 44 | + deactivateAll() | |
| 46 | 45 | progress = 0; |
| 47 | 46 | } |
| 48 | 47 | |
| ... | ... | @@ -71,7 +70,7 @@ |
| 71 | 70 | |
| 72 | 71 | VLibrasPlayer.addErrorListener(function (err) { |
| 73 | 72 | var vwError = vwCanvas.querySelector('.vw-error'); |
| 74 | - vwError.classList.add('active'); | |
| 73 | + vwPlayer.classList.add('error'); | |
| 75 | 74 | switch(err) { |
| 76 | 75 | case 'unsupported': |
| 77 | 76 | vwError.innerHTML = 'O seu navegador não é compatível com este widget.'; |
| ... | ... | @@ -83,8 +82,7 @@ |
| 83 | 82 | vwError.innerHTML = 'Por favor, instale o <a href="http://unity3d.com/webplayer/" target="_blank">Unity WebPlayer</a>.'; |
| 84 | 83 | break; |
| 85 | 84 | default: |
| 86 | - vwError.innerHTML = 'Ocorreu um erro. Por favor, recarregue a página.' | |
| 87 | - break; | |
| 85 | + vwError.innerHTML = 'Ocorreu um erro. Por favor, entre em contato com o administrador da página.' | |
| 88 | 86 | } |
| 89 | 87 | }); |
| 90 | 88 | |
| ... | ... | @@ -92,9 +90,10 @@ |
| 92 | 90 | e.preventDefault(); |
| 93 | 91 | |
| 94 | 92 | if (VLibrasWeb.lastTextElement) { |
| 95 | - VLibrasWeb.lastTextElement.dispatchEvent( | |
| 96 | - new MouseEvent('click') | |
| 97 | - ); | |
| 93 | + var span = VLibrasWeb.lastTextElement.querySelector('span'); | |
| 94 | + span.classList.add('vw-text-active'); | |
| 95 | + | |
| 96 | + vwProgress.style.width = 0; | |
| 98 | 97 | } |
| 99 | 98 | |
| 100 | 99 | VLibrasPlayer.play(); |
| ... | ... | @@ -117,11 +116,11 @@ |
| 117 | 116 | vwSpeed.addEventListener('click', function (e) { |
| 118 | 117 | e.preventDefault(); |
| 119 | 118 | |
| 120 | - var actualSpeed = vwSpeed.innerText; | |
| 119 | + var actualSpeed = vwSpeed.textContent; | |
| 121 | 120 | var newSpeed = (actualSpeed % 4) + 1; |
| 122 | 121 | |
| 123 | 122 | VLibrasPlayer.setSpeed(newSpeed * 0.5); |
| 124 | - this.innerText = newSpeed; | |
| 123 | + this.textContent = newSpeed; | |
| 125 | 124 | }); |
| 126 | 125 | |
| 127 | 126 | vwAccess.addEventListener('click', function () { |
| ... | ... | @@ -141,10 +140,7 @@ |
| 141 | 140 | vw.classList.remove('left'); |
| 142 | 141 | |
| 143 | 142 | minimize(); |
| 144 | - | |
| 145 | - removeTagsTexts(); | |
| 146 | - VLibrasPlayer.stop(); | |
| 147 | - vwProgress.style.width = 0; | |
| 143 | + close(); | |
| 148 | 144 | }); |
| 149 | 145 | |
| 150 | 146 | vwSide.addEventListener('click', function () { |
| ... | ... | @@ -166,14 +162,12 @@ |
| 166 | 162 | e.preventDefault(); |
| 167 | 163 | |
| 168 | 164 | vwProgress.style.width = 0; |
| 165 | + VLibrasWeb.lastTextElement = this.parentNode; | |
| 169 | 166 | |
| 170 | - VLibrasWeb.lastTextElement = this; | |
| 167 | + window.VLibrasPlayer.stop(); | |
| 171 | 168 | window.VLibrasPlayer.translate(this.textContent); |
| 172 | 169 | |
| 173 | - var actives = document.querySelector('.vw-text.vw-text-active'); | |
| 174 | - if (actives) { | |
| 175 | - actives.classList.remove('vw-text-active'); | |
| 176 | - } | |
| 170 | + deactivateAll(); | |
| 177 | 171 | |
| 178 | 172 | this.classList.add('vw-text-active'); |
| 179 | 173 | }); |
| ... | ... | @@ -182,21 +176,25 @@ |
| 182 | 176 | |
| 183 | 177 | function removeTagsTexts() { |
| 184 | 178 | var tagsTexts = document.querySelectorAll('.vw-text'); |
| 185 | - for (var i = 0; i < tagsTexts; i++) { | |
| 186 | - var span = tagsTexts[i].querySelector('span'); | |
| 187 | - tagsTexts[i].innerHTML = span.innerHTML; | |
| 188 | - tagsTexts[i].classList.remove('.vw-text'); | |
| 189 | - tagsTexts[i].classList.remove('.vw-text-active'); | |
| 179 | + for (var i = 0; i < tagsTexts.length; i++) { | |
| 180 | + var parent = tagsTexts[i].parentNode; | |
| 181 | + parent.innerHTML = tagsTexts[i].innerHTML; | |
| 190 | 182 | } |
| 191 | 183 | } |
| 192 | 184 | |
| 193 | 185 | function getAllNodeTexts(root, callback) { |
| 194 | 186 | var noop = function () {}; |
| 187 | + var headElements = ['SCRIPT', 'TITLE', 'META', 'STYLE', 'LINK', 'BASE']; | |
| 195 | 188 | |
| 196 | 189 | for(var i = 0; i < root.childNodes.length; i++) { |
| 197 | 190 | var node = root.childNodes[i]; |
| 198 | 191 | var anyText = false; |
| 199 | - for(var j = 0; j < node.childNodes.length && node.tagName != 'SCRIPT'; j++) { | |
| 192 | + | |
| 193 | + if (headElements.indexOf(node.tagName) != -1) { | |
| 194 | + continue; | |
| 195 | + } | |
| 196 | + | |
| 197 | + for(var j = 0; j < node.childNodes.length; j++) { | |
| 200 | 198 | var child = node.childNodes[j]; |
| 201 | 199 | if (child.nodeType == Node.TEXT_NODE && child.nodeValue.trim() != '') { |
| 202 | 200 | anyText = true; |
| ... | ... | @@ -216,5 +214,18 @@ |
| 216 | 214 | vw.classList.remove('maximize'); |
| 217 | 215 | vwWindow.classList.remove('active'); |
| 218 | 216 | } |
| 217 | + | |
| 218 | + function close() { | |
| 219 | + removeTagsTexts(); | |
| 220 | + VLibrasPlayer.stop(); | |
| 221 | + vwProgress.style.width = 0; | |
| 222 | + } | |
| 223 | + | |
| 224 | + function deactivateAll() { | |
| 225 | + var active = document.querySelector('.vw-text.vw-text-active'); | |
| 226 | + if (active) { | |
| 227 | + active.classList.remove('vw-text-active'); | |
| 228 | + } | |
| 229 | + } | |
| 219 | 230 | }; |
| 220 | 231 | })(window, document); | ... | ... |