|
2278 | 2278 | if (typeof cueId === 'undefined') { |
2279 | 2279 | cueId = state.cues.length + 1; |
2280 | 2280 | } |
2281 | | - |
2282 | 2281 | state.cues.push({ |
2283 | 2282 | id: cueId, |
2284 | 2283 | start: startTime, |
|
2308 | 2307 | if (nextLine.indexOf('-->') !== -1 || /^\s*$/.test(nextLine)) { |
2309 | 2308 | break; // Handle empty cues |
2310 | 2309 | } |
2311 | | - |
2312 | 2310 | // Have to separately detect double-lines ending cue due to our non-standard parsing. |
2313 | 2311 | // TODO: Redo outer algorithm to conform to W3 spec? |
2314 | 2312 | if (state.text.length >= 2 && state.text[0] === '\n' && state.text[1] === '\n') { |
|
2323 | 2321 | } |
2324 | 2322 | else if (token.type === 'startTag') { |
2325 | 2323 | token.type = token.tagName; |
2326 | | - // Define token.parent; added by Terrill to fix bug on Line 296 |
| 2324 | + // Define token.parent; added by Terrill to fix bug end 'endTag' loop |
2327 | 2325 | token.parent = current; |
2328 | | - if ($.inArray(token.tagName, ['c', 'i', 'b', 'u', 'ruby']) !== -1) { |
| 2326 | + if ($.inArray(token.tagName, ['i', 'b', 'u', 'ruby']) !== -1) { |
2329 | 2327 | if (languageStack.length > 0) { |
2330 | 2328 | current.language = languageStack[languageStack.length - 1]; |
2331 | 2329 | } |
|
2339 | 2337 | current.children.push(token); |
2340 | 2338 | current = token; |
2341 | 2339 | } |
| 2340 | + else if (token.tagName === 'c') { |
| 2341 | + token.value = token.annotation; |
| 2342 | + if (languageStack.length > 0) { |
| 2343 | + current.language = languageStack[languageStack.length - 1]; |
| 2344 | + } |
| 2345 | + current.children.push(token); |
| 2346 | + current = token; |
| 2347 | + } |
2342 | 2348 | else if (token.tagName === 'v') { |
2343 | 2349 | token.value = token.annotation; |
2344 | 2350 | if (languageStack.length > 0) { |
|
2359 | 2365 | else if (token.type === 'endTag') { |
2360 | 2366 | if (token.tagName === current.type && $.inArray(token.tagName, ['c', 'i', 'b', 'u', 'ruby', 'rt', 'v']) !== -1) { |
2361 | 2367 | // NOTE from Terrill: This was resulting in an error because current.parent was undefined |
2362 | | - // Fixed (I think) by assigning current token to token.parent on Line 260 |
| 2368 | + // Fixed (I think) by assigning current token to token.parent in 'startTag' loop |
2363 | 2369 | current = current.parent; |
2364 | 2370 | } |
2365 | 2371 | else if (token.tagName === 'lang' && current.type === 'lang') { |
|
8215 | 8221 | // Takes a cue and returns the caption text to display for it. |
8216 | 8222 | AblePlayer.prototype.flattenCueForCaption = function (cue) { |
8217 | 8223 |
|
| 8224 | + // Support for 'i' and 'b' tags added in 2.3.66 |
| 8225 | + // TODO: Add support for 'c' (class) and 'ruby' |
| 8226 | + |
| 8227 | + // c (class): <c.myClass1.myClass2>Some text</c> |
| 8228 | + // Classes can be used to modify other tags too (e.g., <v.loud>) |
| 8229 | + // If <c> tag, should be rendered as a <span> |
| 8230 | + |
| 8231 | + // ruby: http://www.w3schools.com/tags/tag_ruby.asp |
| 8232 | + |
| 8233 | + // WebVTT also supports 'u' (underline) |
| 8234 | + // I see no reason to support that in Able Player. |
| 8235 | + // If it's available authors are likely to use it incorrectly |
| 8236 | + // where <i> or <b> should be used instead |
| 8237 | + // Here are the rare use cases where an underline is appropriate on the web: |
| 8238 | + // http://html5doctor.com/u-element/ |
| 8239 | + |
8218 | 8240 | var result = []; |
8219 | 8241 |
|
8220 | 8242 | var flattenComponent = function (component) { |
|
8228 | 8250 | result.push(flattenComponent(component.children[ii])); |
8229 | 8251 | } |
8230 | 8252 | } |
| 8253 | + else if (component.type === 'i') { |
| 8254 | + result.push('<em>'); |
| 8255 | + for (var ii in component.children) { |
| 8256 | + result.push(flattenComponent(component.children[ii])); |
| 8257 | + } |
| 8258 | + result.push('</em>'); |
| 8259 | + } |
| 8260 | + else if (component.type === 'b') { |
| 8261 | + result.push('<strong>'); |
| 8262 | + for (var ii in component.children) { |
| 8263 | + result.push(flattenComponent(component.children[ii])); |
| 8264 | + } |
| 8265 | + result.push('</strong>'); |
| 8266 | + } |
8231 | 8267 | else { |
8232 | 8268 | for (var ii in component.children) { |
8233 | 8269 | result.push(flattenComponent(component.children[ii])); |
|
9041 | 9077 | }; |
9042 | 9078 |
|
9043 | 9079 | var addCaption = function(div, cap) { |
| 9080 | + |
9044 | 9081 | var capSpan = $('<span class="able-transcript-seekpoint able-transcript-caption"></span>'); |
9045 | 9082 |
|
9046 | 9083 | var flattenComponentForCaption = function(comp) { |
| 9084 | + |
9047 | 9085 | var result = []; |
| 9086 | + |
9048 | 9087 | var flattenString = function (str) { |
| 9088 | + |
9049 | 9089 | var result = []; |
9050 | 9090 | if (str === '') { |
9051 | 9091 | return result; |
|
9087 | 9127 | } |
9088 | 9128 | } |
9089 | 9129 | } |
| 9130 | + else if (comp.type === 'b' || comp.type === 'i') { |
| 9131 | + if (comp.type === 'b') { |
| 9132 | + var $tag = $('<strong>'); |
| 9133 | + } |
| 9134 | + else if (comp.type === 'i') { |
| 9135 | + var $tag = $('<em>'); |
| 9136 | + } |
| 9137 | + for (var ii in comp.children) { |
| 9138 | + var subResults = flattenComponentForCaption(comp.children[ii]); |
| 9139 | + for (var jj in subResults) { |
| 9140 | + $tag.append(subResults[jj]); |
| 9141 | + } |
| 9142 | + } |
| 9143 | + if (comp.type === 'b' || comp.type == 'i') { |
| 9144 | + result.push($tag); |
| 9145 | + } |
| 9146 | + } |
9090 | 9147 | else { |
9091 | 9148 | for (var ii in comp.children) { |
9092 | 9149 | result = result.concat(flattenComponentForCaption(comp.children[ii])); |
|
9106 | 9163 | capSpan.append(result); |
9107 | 9164 | } |
9108 | 9165 | } |
9109 | | - |
9110 | 9166 | capSpan.attr('data-start', cap.start.toString()); |
9111 | 9167 | capSpan.attr('data-end', cap.end.toString()); |
9112 | 9168 | div.append(capSpan); |
|
0 commit comments