Commit c1ea6cc6f799896301ec562c4f7d5d4e81d086dc

Authored by David Guilherme
1 parent ea70d84a
Exists in master

Fix some bugs

@@ -6,6 +6,7 @@ VLibrasWeb/Player/WebPlayer/* @@ -6,6 +6,7 @@ VLibrasWeb/Player/WebPlayer/*
6 6
7 *.zip 7 *.zip
8 **/*.DS_Store 8 **/*.DS_Store
  9 +.idea
9 10
10 bower_components 11 bower_components
11 node_modules 12 node_modules
VLibrasWeb/vlibras-player.js
@@ -13,8 +13,6 @@ @@ -13,8 +13,6 @@
13 var self = this; 13 var self = this;
14 text = encodeURI(text); 14 text = encodeURI(text);
15 15
16 - this.stop();  
17 -  
18 (self.onTranslateStart || noop)(); 16 (self.onTranslateStart || noop)();
19 get(ENDPOINT, { texto: text }, 17 get(ENDPOINT, { texto: text },
20 function (status, response) { 18 function (status, response) {
VLibrasWeb/vlibras-web.css
@@ -67,25 +67,23 @@ @@ -67,25 +67,23 @@
67 } 67 }
68 68
69 .vlibras-widget .vw-player { 69 .vlibras-widget .vw-player {
70 - visibility: hidden;  
71 - width: 0; 70 + display: none;
  71 + width: 320px;
72 height: 100%; 72 height: 100%;
73 float: right; 73 float: right;
74 74
75 background-color: #ebebeb; 75 background-color: #ebebeb;
76 76
77 - display: -webkit-flex;  
78 - display: flex;  
79 - flex-direction: column;  
80 -  
81 -webkit-box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75); 77 -webkit-box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75);
82 -moz-box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75); 78 -moz-box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75);
83 box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75); 79 box-shadow: 0px 0px 9px 0px rgba(0,0,0,0.75);
84 } 80 }
85 81
86 .vlibras-widget .vw-player.active { 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 .vw-player .vw-canvas-wrapper { 89 .vw-player .vw-canvas-wrapper {
@@ -103,7 +101,7 @@ @@ -103,7 +101,7 @@
103 display: none; 101 display: none;
104 } 102 }
105 103
106 -.vw-player.loaded .vw-subtitle { 104 +.vw-player.loaded:not(.error) .vw-subtitle {
107 display: block; 105 display: block;
108 } 106 }
109 107
@@ -187,7 +185,7 @@ @@ -187,7 +185,7 @@
187 -webkit-align-items: center; 185 -webkit-align-items: center;
188 } 186 }
189 187
190 -.vw-player.loaded .vw-controls { 188 +.vw-player.loaded:not(.error) .vw-controls {
191 visibility: visible; 189 visibility: visible;
192 } 190 }
193 191
@@ -226,6 +224,8 @@ @@ -226,6 +224,8 @@
226 224
227 .vw-window { 225 .vw-window {
228 cursor: pointer; 226 cursor: pointer;
  227 + flex-shrink: 0;
  228 + -webkit-flex-shrink: 0;
229 } 229 }
230 230
231 .vw-window .vw-maximize, .vw-window.active .vw-minimize { 231 .vw-window .vw-maximize, .vw-window.active .vw-minimize {
@@ -275,6 +275,7 @@ @@ -275,6 +275,7 @@
275 height: 50px; 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 display: block; 280 display: block;
280 } 281 }
VLibrasWeb/vlibras-web.js
@@ -40,9 +40,8 @@ @@ -40,9 +40,8 @@
40 var vwPlay = vwControls.querySelector('.vw-play'); 40 var vwPlay = vwControls.querySelector('.vw-play');
41 41
42 VLibrasPlayer.addProgressListener(function (progress) { 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 progress = 0; 45 progress = 0;
47 } 46 }
48 47
@@ -71,7 +70,7 @@ @@ -71,7 +70,7 @@
71 70
72 VLibrasPlayer.addErrorListener(function (err) { 71 VLibrasPlayer.addErrorListener(function (err) {
73 var vwError = vwCanvas.querySelector('.vw-error'); 72 var vwError = vwCanvas.querySelector('.vw-error');
74 - vwError.classList.add('active'); 73 + vwPlayer.classList.add('error');
75 switch(err) { 74 switch(err) {
76 case 'unsupported': 75 case 'unsupported':
77 vwError.innerHTML = 'O seu navegador não é compatível com este widget.'; 76 vwError.innerHTML = 'O seu navegador não é compatível com este widget.';
@@ -83,8 +82,7 @@ @@ -83,8 +82,7 @@
83 vwError.innerHTML = 'Por favor, instale o <a href="http://unity3d.com/webplayer/" target="_blank">Unity WebPlayer</a>.'; 82 vwError.innerHTML = 'Por favor, instale o <a href="http://unity3d.com/webplayer/" target="_blank">Unity WebPlayer</a>.';
84 break; 83 break;
85 default: 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,9 +90,10 @@
92 e.preventDefault(); 90 e.preventDefault();
93 91
94 if (VLibrasWeb.lastTextElement) { 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 VLibrasPlayer.play(); 99 VLibrasPlayer.play();
@@ -117,11 +116,11 @@ @@ -117,11 +116,11 @@
117 vwSpeed.addEventListener('click', function (e) { 116 vwSpeed.addEventListener('click', function (e) {
118 e.preventDefault(); 117 e.preventDefault();
119 118
120 - var actualSpeed = vwSpeed.innerText; 119 + var actualSpeed = vwSpeed.textContent;
121 var newSpeed = (actualSpeed % 4) + 1; 120 var newSpeed = (actualSpeed % 4) + 1;
122 121
123 VLibrasPlayer.setSpeed(newSpeed * 0.5); 122 VLibrasPlayer.setSpeed(newSpeed * 0.5);
124 - this.innerText = newSpeed; 123 + this.textContent = newSpeed;
125 }); 124 });
126 125
127 vwAccess.addEventListener('click', function () { 126 vwAccess.addEventListener('click', function () {
@@ -141,10 +140,7 @@ @@ -141,10 +140,7 @@
141 vw.classList.remove('left'); 140 vw.classList.remove('left');
142 141
143 minimize(); 142 minimize();
144 -  
145 - removeTagsTexts();  
146 - VLibrasPlayer.stop();  
147 - vwProgress.style.width = 0; 143 + close();
148 }); 144 });
149 145
150 vwSide.addEventListener('click', function () { 146 vwSide.addEventListener('click', function () {
@@ -166,14 +162,12 @@ @@ -166,14 +162,12 @@
166 e.preventDefault(); 162 e.preventDefault();
167 163
168 vwProgress.style.width = 0; 164 vwProgress.style.width = 0;
  165 + VLibrasWeb.lastTextElement = this.parentNode;
169 166
170 - VLibrasWeb.lastTextElement = this; 167 + window.VLibrasPlayer.stop();
171 window.VLibrasPlayer.translate(this.textContent); 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 this.classList.add('vw-text-active'); 172 this.classList.add('vw-text-active');
179 }); 173 });
@@ -182,21 +176,25 @@ @@ -182,21 +176,25 @@
182 176
183 function removeTagsTexts() { 177 function removeTagsTexts() {
184 var tagsTexts = document.querySelectorAll('.vw-text'); 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 function getAllNodeTexts(root, callback) { 185 function getAllNodeTexts(root, callback) {
194 var noop = function () {}; 186 var noop = function () {};
  187 + var headElements = ['SCRIPT', 'TITLE', 'META', 'STYLE', 'LINK', 'BASE'];
195 188
196 for(var i = 0; i < root.childNodes.length; i++) { 189 for(var i = 0; i < root.childNodes.length; i++) {
197 var node = root.childNodes[i]; 190 var node = root.childNodes[i];
198 var anyText = false; 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 var child = node.childNodes[j]; 198 var child = node.childNodes[j];
201 if (child.nodeType == Node.TEXT_NODE && child.nodeValue.trim() != '') { 199 if (child.nodeType == Node.TEXT_NODE && child.nodeValue.trim() != '') {
202 anyText = true; 200 anyText = true;
@@ -216,5 +214,18 @@ @@ -216,5 +214,18 @@
216 vw.classList.remove('maximize'); 214 vw.classList.remove('maximize');
217 vwWindow.classList.remove('active'); 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 })(window, document); 231 })(window, document);
@@ -47,6 +47,10 @@ @@ -47,6 +47,10 @@
47 <img class="vw-minimize" src="VLibrasWeb/Images/minimize.png" /> 47 <img class="vw-minimize" src="VLibrasWeb/Images/minimize.png" />
48 </span> 48 </span>
49 </div> 49 </div>
  50 +
  51 + <div class="vw-links">
  52 + <ul></ul>
  53 + </div>
50 </div> 54 </div>
51 </div> 55 </div>
52 56