[xiph-commits] r4053 - itext/javascript
silvia at svn.annodex.net
silvia at svn.annodex.net
Thu Oct 29 02:03:13 PDT 2009
Author: silvia
Date: 2009-10-29 02:03:13 -0700 (Thu, 29 Oct 2009)
New Revision: 4053
Modified:
itext/javascript/subtitles_v2.js
Log:
Actually fixed the javascript for version 2 itext.
Modified: itext/javascript/subtitles_v2.js
===================================================================
--- itext/javascript/subtitles_v2.js 2009-10-29 09:03:06 UTC (rev 4052)
+++ itext/javascript/subtitles_v2.js 2009-10-29 09:03:13 UTC (rev 4053)
@@ -445,8 +445,8 @@
// adjust for delay and stretch factor
for (var i = 0; i < this.allText.length; i++) {
- this.allText[i].start = (this.allText[i].start * stretch) + delay;
- this.allText[i].end = (this.allText[i].end * stretch) + delay;
+ this.allText[i].start = (this.allText[i].start * (this.stretch/100.0)) + this.delay;
+ this.allText[i].end = (this.allText[i].end * (this.stretch/100.0)) + this.delay;
}
this.fetched = true;
@@ -483,7 +483,8 @@
var ItextList = function (itextlist) {
this.init(itextlist);
};
-ItextList.prototype = {
+ItextList.prototype = {
+ itextlist: null,
category: null,
active: "auto",
name: null,
@@ -492,57 +493,63 @@
onleave: null,
primary_lang: null,
secondary_lang: null,
- fetch_lang: null,
+ fetch_lang: null,
init: function (itextlist) {
+ this.itextlist = itextlist;
this.category = jQuery(itextlist).attr("category");
- this.active = (jQuery(itextlist).attr("active") || "auto");
+ this.active = (jQuery(itextlist).attr("active") || "none");
this.name = jQuery(itextlist).attr("name");
this.onenter = jQuery(itextlist).attr("onenter");
this.onleave = jQuery(itextlist).attr("onleave");
- // parse the itext elements and fetch the appropriate track
- this.parseItexts(itextlist);
+ // parse the itext elements
+ this.load();
+
+ // fetch the appropriate track
+ if (this.primary_lang) {
+ this.fetch_lang = this.primary_lang;
+ } else if (this.secondary_lang) {
+ this.fetch_lang = this.secondary_lang;
+ }
if (this.active != "none") {
- if (this.active != "auto") {
- if (!primary_lang) {
- primary_lang = secondary_lang;
- }
- if (primary_lang && !itexts[primary_lang].fetched) {
- this.fetch_lang = primary_lang;
- }
+ if (this.active != "auto") {
+ if (this.itexts[this.active]) {
+ this.fetch_lang = this.active;
} else {
- if (itexts[this.active]) {
- this.fetch_lang=this.active;
- } else {
- this.active="none";
- }
+ this.active = "none";
}
- itexts[fetch_lang].fetch();
+ }
+ this.itexts[this.fetch_lang].fetch();
}
},
- parseItexts: function(itextlist) {
- var tracks_tmp = itextlist.find('itext');
+ load: function() {
+ var tracks_tmp = this.itextlist.find('itext');
+ var itexts_tmp = {};
+ var primary_lang_tmp = null;
+ var secondary_lang_tmp = null;
tracks_tmp.each(function (i) {
// create the text track and add to the itexts array
- var track = new Itext(this);
- itexts[track.lang] = {};
- itexts[track.lang] = track;
+ var track = new Itext(jQuery(this));
+ itexts_tmp[track.lang] = {};
+ itexts_tmp[track.lang] = track;
// check for appropriate language in this track for later fetching
- if (this.active === "auto") {
- if (track.lang === window.navigator.language) {
- primary_lang = track.lang; // complete lang match
- } else if (track.lang === window.navigator.language.substr(0, 2)) {
- secondary_lang = track.lang; // only main lang match
- }
+ if (track.lang === window.navigator.language) {
+ primary_lang_tmp = track.lang; // complete lang match
+ } else if (track.lang === window.navigator.language.substr(0, 2)) {
+ secondary_lang_tmp = track.lang; // only main lang match
}
});
+ this.itexts = itexts_tmp;
+ this.secondary_lang = secondary_lang_tmp;
+ this.primary_lang = primary_lang_tmp;
}
};
+
// class to parse all itextlists under a media element
// and create a menu
// would need to be implemented inside Browser
@@ -552,7 +559,7 @@
ItextCollection.prototype = {
video: null,
div_id: null,
- itextlist: [],
+ itextlist: {},
init: function (vid, div) {
this.video = vid;
@@ -564,22 +571,23 @@
}
},
load: function () {
-
// go through each itextlist, parse it and add it to itextlist{}
var tracks_tmp = this.video.find('itextlist');
+ var itextlist_tmp={};
tracks_tmp.each(function (i) {
// create the itextlist track
- var ilist = new ItextList(this);
- itextlist[ilist.category] = {};
- itextlist[ilist.category] = ilist;
+ var ilist = new ItextList(jQuery(this));
+ itextlist_tmp[ilist.category] = {};
+ itextlist_tmp[ilist.category] = ilist;
});
+ this.itextlist = itextlist_tmp;
},
itextMenu: function (baseEl, elstring) {
var appendText = '<div class="itextMenu" role="presentation">\n';
appendText += '<ul class="catMenu" role="presentation">\n';
for (var i in this.itextlist) {
- var submenu = i.name || categoryName(i.category);
+ var submenu = i.name || categoryName(i.category);
appendText += '<li role="menuitem" aria-haspopup="true" tabindex="0"> < ' + submenu + '\n';
appendText += '<ul class="langMenu" role="menu" >\n';
for (var j in i.itexts) {
@@ -600,50 +608,64 @@
jQuery(".catMenu").css("visibility", "hidden");
},
show: function (currentTime) {
- // add to correct content container
- var mc_width = jQuery('.mc').css("width").substr(0, jQuery('.mc').css("width").length - 2);
+ // add to correct content container
+ var mc_width = jQuery('.mc').css("width").substr(0, jQuery('.mc').css("width").length - 2);
- for (var i in this.itextlist) {
- if (i.active != "none") {
- // replace content of itext div
- if (jQuery("#" + this.div_id + " > .itext_" + i).html() !== i.itexts[i.fetch_lang]) {
- jQuery("#" + this.div_id + " > .itext_" + i).html(i.itexts[i.fetch_lang]);
- if (i === "CUE") {
- jQuery("#" + this.div_id + " > .itext_" + i + " > .text").prepend("Chapter: ");
- }
- if (i === "TAD") {
- jQuery("#" + this.div_id + " > .itext_TAD").attr("aria-live", "assertive");
- jQuery("#" + this.div_id + " > .itext_TAD").css("max-width", (mc_width) + "px");
- jQuery("#" + this.div_id + " > .itext_TAD").css("bottom", "5px");
- }
- if (i === "LRC") {
- jQuery("#" + this.div_id + " > .itext_LRC").css("max-width", mc_width + "px");
- jQuery("#" + this.div_id + " > .itext_LRC").css("bottom", "38px");
- // somehow the setting of "left" encourages the correct width to be calculated
- // if I don't do that, the width calculation in text_half_length is too short on some elements
- jQuery("#" + this.div_id + " > .itext_LRC").css("left",5);
- var text_half_length = jQuery("#" + this.div_id + " > .itext_LRC > .text").css("width").substr(0, jQuery("#" + this.div_id + " > .itext_LRC > .text").css("width").length - 2) / 2;
- jQuery("#" + this.div_id + " > .itext_LRC").css("left", ((mc_width / 2) - text_half_length - 7) + "px");
- }
- jQuery("#" + this.div_id + " > .itext_" + i).css("visibility", "visible");
- if (i === "CC" ||
- i === "SUB" ||
- i === "KTV" ||
- i === "TRX" ||
- i === "LIN") {
- // anyone with a better idea for how to place the captions bottom center, please speak up
- jQuery("#" + this.div_id + " > .itext_" + i).css("max-width", mc_width + "px");
- jQuery("#" + this.div_id + " > .itext_" + i).css("bottom", "23px");
- // somehow the setting of "left" encourages the correct width to be calculated
- // if I don't do that, the width calculation in text_half_length is too short on some elements
- jQuery("#" + this.div_id + " > .itext_" + i).css("left",5);
- var text_half_length = jQuery("#" + this.div_id + " > .itext_" + i + " > .text").css("width").substr(0, jQuery("#" + this.div_id + " > .itext_" + i + " > .text").css("width").length - 2) / 2;
- jQuery("#" + this.div_id + " > .itext_" + i).css("left", ((mc_width / 2) - text_half_length - 7) + "px");
- }
- }
- } else {
- jQuery("#" + this.div_id + " > .itext_" + i).css("visibility", "hidden");
+ // get content per category, if active, and display it
+ var content = null;
+ for (var i in this.itextlist) {
+ var li = this.itextlist[i];
+
+ // get content for active tracks only
+ if (li.active != "none") {
+ content = li.itexts[li.fetch_lang].currentText(currentTime);
+
+ // update content & styling of itext div if necessary
+ if (content) {
+ if (jQuery("#" + this.div_id + " > .itext_" + i).html() !== content) {
+
+ // update content
+ jQuery("#" + this.div_id + " > .itext_" + i).html(content);
+
+ // update styling dependent on text length
+ if (i === "CUE") {
+ jQuery("#" + this.div_id + " > .itext_" + i + " > .text").prepend("Chapter: ");
+ }
+ if (i === "TAD") {
+ jQuery("#" + this.div_id + " > .itext_TAD").attr("aria-live", "assertive");
+ jQuery("#" + this.div_id + " > .itext_TAD").css("max-width", (mc_width) + "px");
+ jQuery("#" + this.div_id + " > .itext_TAD").css("bottom", "5px");
+ }
+ if (i === "LRC") {
+ jQuery("#" + this.div_id + " > .itext_LRC").css("max-width", mc_width + "px");
+ jQuery("#" + this.div_id + " > .itext_LRC").css("bottom", "38px");
+ // somehow the setting of "left" encourages the correct width to be calculated
+ // if I don't do that, the width calculation in text_half_length is too short on some elements
+ jQuery("#" + this.div_id + " > .itext_LRC").css("left",5);
+ var text_half_length = jQuery("#" + this.div_id + " > .itext_LRC > .text").css("width").substr(0, jQuery("#" + this.div_id + " > .itext_LRC > .text").css("width").length - 2) / 2;
+ jQuery("#" + this.div_id + " > .itext_LRC").css("left", ((mc_width / 2) - text_half_length - 7) + "px");
+ }
+ jQuery("#" + this.div_id + " > .itext_" + i).css("visibility", "visible");
+ if (i === "CC" ||
+ i === "SUB" ||
+ i === "KTV" ||
+ i === "TRX" ||
+ i === "LIN") {
+ // anyone with a better idea for how to place the captions bottom center, please speak up
+ jQuery("#" + this.div_id + " > .itext_" + i).css("max-width", mc_width + "px");
+ jQuery("#" + this.div_id + " > .itext_" + i).css("bottom", "23px");
+ // somehow the setting of "left" encourages the correct width to be calculated
+ // if I don't do that, the width calculation in text_half_length is too short on some elements
+ jQuery("#" + this.div_id + " > .itext_" + i).css("left",5);
+ var text_half_length = jQuery("#" + this.div_id + " > .itext_" + i + " > .text").css("width").substr(0, jQuery("#" + this.div_id + " > .itext_" + i + " > .text").css("width").length - 2) / 2;
+ jQuery("#" + this.div_id + " > .itext_" + i).css("left", ((mc_width / 2) - text_half_length - 7) + "px");
+ }
}
+ }
+
+ } else {
+ jQuery("#" + this.div_id + " > .itext_" + i).css("visibility", "hidden");
}
+ }
}
};
More information about the commits
mailing list