Created
January 13, 2015 13:33
-
-
Save johnie/efb325cda7e57cfe8c2e to your computer and use it in GitHub Desktop.
browsealoud.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $bajq, domUrl, browsealoud = { | |
CAPTURE_ANALYTICS: false, | |
BASE_ADDRESS: "babm.texthelp.com", | |
URL_INFO_ADDRESS: "babm.texthelp.com", | |
COOKIE_NAME: "__ba_plus", | |
ELEMENT_PREFIX: "_ba_", | |
GA_PROPERTY_ID: "UA-4669579-7", | |
LIGHTBOX_WIDTH: 450, | |
LIGHTBOX_HEIGHT: 160, | |
LANG_MAP: [{ | |
ttsid: 0, | |
lang: 0, | |
reg: "uk" | |
}, { | |
ttsid: 10, | |
lang: 1, | |
reg: "us" | |
}, { | |
ttsid: 11, | |
lang: 1 | |
}, { | |
ttsid: 12, | |
lang: 0 | |
}, { | |
ttsid: 13, | |
lang: 0 | |
}, { | |
ttsid: 14, | |
lang: 8, | |
reg: "nl" | |
}, { | |
ttsid: 15, | |
lang: 17, | |
reg: "uk-sc" | |
}, { | |
ttsid: 16, | |
lang: 10, | |
reg: "au" | |
}, { | |
ttsid: 17, | |
lang: 2, | |
reg: "es" | |
}, { | |
ttsid: 18, | |
lang: 4, | |
reg: "fr" | |
}, { | |
ttsid: 19, | |
lang: 5, | |
reg: "fr-ca" | |
}, { | |
ttsid: 20, | |
lang: 14, | |
reg: "fl" | |
}, { | |
ttsid: 21, | |
lang: 3, | |
reg: "es-mx" | |
}, { | |
ttsid: 22, | |
lang: 7, | |
reg: "it" | |
}, { | |
ttsid: 23, | |
lang: 6, | |
reg: "de" | |
}, { | |
ttsid: 24, | |
lang: 9, | |
reg: "se" | |
}, { | |
ttsid: 25, | |
lang: 16, | |
reg: "uk-ie" | |
}, { | |
ttsid: 26, | |
lang: 9 | |
}, { | |
ttsid: 27, | |
lang: 15, | |
reg: "cy" | |
}, { | |
ttsid: 28, | |
lang: 12, | |
reg: "no" | |
}, { | |
ttsid: 29, | |
lang: 11, | |
reg: "pt" | |
}, { | |
ttsid: 30, | |
lang: 13, | |
reg: "pl" | |
}, { | |
ttsid: 31, | |
lang: 18, | |
reg: "fi" | |
}, { | |
ttsid: 32, | |
lang: 0 | |
}, { | |
ttsid: 33, | |
lang: 10 | |
}, { | |
ttsid: 34, | |
lang: 7 | |
}, { | |
ttsid: 35, | |
lang: 5 | |
}, { | |
ttsid: 36, | |
lang: 6 | |
}, { | |
ttsid: 37, | |
lang: 4 | |
}, { | |
ttsid: 38, | |
lang: 11 | |
}, { | |
ttsid: 39, | |
lang: 11 | |
}, { | |
ttsid: 43, | |
lang: 0 | |
}, { | |
ttsid: 45, | |
lang: 6 | |
}, { | |
ttsid: 46, | |
lang: 13 | |
}, { | |
ttsid: 47, | |
lang: 1 | |
}, { | |
ttsid: 48, | |
lang: 18 | |
}, { | |
ttsid: 49, | |
lang: 19, | |
reg: "pt-br" | |
}, { | |
ttsid: 50, | |
lang: 1 | |
}, { | |
ttsid: 51, | |
lang: 1 | |
}, { | |
ttsid: 52, | |
lang: 52 | |
}, { | |
ttsid: 53, | |
lang: 64 | |
}, { | |
ttsid: 54, | |
lang: 77 | |
}, { | |
ttsid: 55, | |
lang: 79 | |
}, { | |
ttsid: 56, | |
lang: 7 | |
}, { | |
ttsid: 57, | |
lang: 7 | |
}, { | |
ttsid: 58, | |
lang: 12 | |
}, { | |
ttsid: 59, | |
lang: 13 | |
}, { | |
ttsid: 60, | |
lang: 19 | |
}, { | |
ttsid: 61, | |
lang: 95 | |
}, { | |
ttsid: 62, | |
lang: 96 | |
}, { | |
ttsid: 63, | |
lang: 96 | |
}, { | |
ttsid: 64, | |
lang: 98 | |
}, { | |
ttsid: 66, | |
lang: 2 | |
}, { | |
ttsid: 67, | |
lang: 2 | |
}, { | |
ttsid: 70, | |
lang: 2 | |
}, { | |
ttsid: 71, | |
lang: 2 | |
}, { | |
ttsid: 72, | |
lang: 2 | |
}, { | |
ttsid: 73, | |
lang: 103 | |
}, { | |
ttsid: 74, | |
lang: 104 | |
}, { | |
ttsid: 75, | |
lang: 81 | |
}, { | |
ttsid: 76, | |
lang: 50 | |
}], | |
useBarCookies: typeof(_baUseCookies) === "boolean" ? _baUseCookies : false, | |
showBar: typeof(_baHiddenMode) === "boolean" ? !_baHiddenMode : true, | |
autoHideOnToolbarLoad: typeof(_baHideOnLoad) === "boolean" ? _baHideOnLoad : false, | |
localeId: typeof(_baLocale) === "undefined" ? (typeof(locale) === "undefined" ? 0 : locale) : _baLocale, | |
displayMode: typeof(_baMode) === "undefined" ? (typeof(mode) === "undefined" ? "" : mode) : _baMode, | |
localeArrayIdx: -1, | |
isBarShown: false, | |
visCheckTimer: null, | |
protocol: window.location.href.indexOf("https") === 0 ? "https" : "http", | |
isSecure: window.location.href.indexOf("https") === 0, | |
bookmarkletUrl: "", | |
bookmarkletUrlForLightbox: "", | |
currentZoomLevel: 1, | |
jQueryImported: false, | |
isToolbarLoading: false, | |
reducedPanelMode: false, | |
imgSuffix: "", | |
jsFilesList: [location.hostname], | |
targetJQVersion: "1.11.1", | |
jqWaitCounter: 0, | |
init: function() { | |
browsealoud.debug("init"); | |
browsealoud.debug("Panel Settings:\n\nLocale: " + browsealoud.localeId + "\nCookies: " + browsealoud.useBarCookies + "\nHide on Load: " + this.autoHideOnToolbarLoad + "\nHidden Mode: " + browsealoud.showBar + "\nMode: " + browsealoud.displayMode); | |
var b = ["se", "no", "fi", 9, 12, 18]; | |
for (var a = 0; a < b.length; a++) { | |
if (b[a] === browsealoud.localeId) { | |
browsealoud.useBarCookies = true; | |
break | |
} | |
} | |
this.browserDetect.init(); | |
if (this.displayMode !== "") { | |
this.reducedPanelMode = true; | |
this.imgSuffix = this.displayMode === "logo" ? "_" + this.displayMode : "_" | |
} | |
if (window.addEventListener) { | |
window.addEventListener("load", function() { | |
browsealoud.checkBAServices() | |
}, false) | |
} else { | |
if (window.attachEvent) { | |
window.attachEvent("onload", function() { | |
browsealoud.checkBAServices() | |
}) | |
} | |
} | |
return '<div id="__ba_panel"' + (this.reducedPanelMode ? "" : ' style="width:120px;height:52px;"') + "></div>" | |
}, | |
checkBAServices: function() { | |
var a = document.body.appendChild(document.createElement("img")); | |
a.setAttribute("width", "1"); | |
a.setAttribute("height", "1"); | |
a.setAttribute("alt", "BrowseAloud Status Check"); | |
a.setAttribute("style", "display: none;"); | |
try { | |
a.style.setAttribute("cssText", "display: none;") | |
} catch (b) {} | |
a.onload = function() { | |
browsealoud.doPageLoaded() | |
}; | |
a.src = "//" + this.BASE_ADDRESS + "/images/spacer.gif?t=" + new Date().getTime() | |
}, | |
getJQVersionOK: function() { | |
var a = typeof(jQuery) !== "undefined", | |
b = a ? jQuery().jquery.split(".") : ["0", "0", "0"], | |
c = this.targetJQVersion.split("."); | |
return b[0] === c[0] && b[1] === c[1] | |
}, | |
appendGoogleAnalytics: function() { | |
if (browsealoud.CAPTURE_ANALYTICS) { | |
var a = document.createElement("script"); | |
a.type = "text/javascript"; | |
a.text = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','_baga');\n"; | |
a.text += "_baga('create', '" + browsealoud.GA_PROPERTY_ID + "', 'auto', {'name': '_batracker', 'allowAnchor': false, 'cookieName': '_baga'});_baga('_batracker.send', 'pageview', {'page':'/bapanel'});_baga('_batracker.set', 'dimension1', 'Cookies: " + browsealoud.useBarCookies + ", Hide on Load: " + browsealoud.autoHideOnToolbarLoad + ", Mode: " + browsealoud.displayMode + "');_baga('_batracker.send', 'event', 'Panel', 'Load', window.location.hostname);"; | |
document.getElementsByTagName("body")[0].appendChild(a) | |
} | |
}, | |
gaTrackEvent: function(a, b) { | |
if (browsealoud.CAPTURE_ANALYTICS && typeof(_baga) !== "undefined") { | |
_baga("_batracker.send", "event", a, b, window.location.hostname) | |
} | |
}, | |
doPageLoaded: function() { | |
browsealoud.debug("doPageLoaded"); | |
this.appendGoogleAnalytics(); | |
if (typeof(locale) === "string" && typeof(_baLocale) === "undefined") { | |
browsealoud.localeId = locale | |
} | |
var a = typeof(jQuery) !== "undefined" && typeof(jQuery.easing) !== "undefined" && typeof(jQuery.easing.jswing) !== "undefined"; | |
if (a) { | |
this.targetJQVersion = "1.8.3" | |
} | |
if (!this.getJQVersionOK()) { | |
this.debug("Importing jQuery " + this.targetJQVersion + " for BA+"); | |
browsealoud.jQueryImported = true; | |
this.appendJQuery() | |
} | |
var b; | |
try { | |
this.getUrlInfo(0) | |
} catch (c) { | |
this.debug("ERROR: init: " + c); | |
return | |
} | |
}, | |
getUrlInfo: function(a) { | |
if (browsealoud.jsFilesList.length === 1) { | |
var b = document.URL.substring(7, document.URL.indexOf("/", 7)), | |
f = b.split("."), | |
e = f.length - 1; | |
while (e > 1) { | |
siteHostName = f.slice(e * -1).join("."); | |
browsealoud.jsFilesList.push(siteHostName); | |
e-- | |
} | |
browsealoud.jsFilesList.push(location.hostname.indexOf("www") === 0 ? location.hostname.substring(location.hostname.indexOf(".") + 1) : "www." + location.hostname) | |
} | |
if (browsealoud.jsFilesList.length > a) { | |
var c = window.XDomainRequest ? new XDomainRequest() : new XMLHttpRequest(), | |
d = "//" + this.URL_INFO_ADDRESS + "/js/urlinfo/" + browsealoud.jsFilesList[a] + ".js"; | |
c.onprogress = function() {}; | |
c.onerror = function() { | |
browsealoud.getUrlInfo(a + 1) | |
}; | |
c.onload = function() { | |
if (c.status) { | |
if (c.status === 200) { | |
domUrl = browsealoud.jsFilesList[a]; | |
var g = document.createElement("script"); | |
g.src = d; | |
g.onload = function() { | |
browsealoud.getDesiredLocale(0) | |
}; | |
document.getElementsByTagName("body")[0].appendChild(g) | |
} else { | |
if (c.status === 404 && a < browsealoud.jsFilesList.length - 1) { | |
browsealoud.getUrlInfo(a + 1) | |
} | |
} | |
} else { | |
if (c.responseText.indexOf("BrowseAloudUrl") > -1) { | |
domUrl = browsealoud.jsFilesList[a]; | |
var g = document.createElement("script"); | |
g.src = d; | |
if (browsealoud.browserDetect.browser === "IE" && browsealoud.browserDetect.version <= 8) { | |
g.onreadystatechange = function() { | |
if (g.readyState === "loaded" || g.readyState === "complete") { | |
browsealoud.getDesiredLocale(0) | |
} | |
} | |
} else { | |
g.onload = function() { | |
browsealoud.getDesiredLocale(0) | |
} | |
} | |
document.getElementsByTagName("body")[0].appendChild(g) | |
} | |
} | |
}; | |
c.open("GET", d, false); | |
c.send() | |
} | |
}, | |
getDesiredLocale: function(b) { | |
var e = 15; | |
if (typeof(BrowseAloudUrl) === "undefined" && b < e) { | |
setTimeout(function() { | |
browsealoud.getDesiredLocale(b + 1) | |
}, 100) | |
} else { | |
if (b >= e) { | |
browsealoud.constructPanelHTML() | |
} else { | |
if (!(BrowseAloudUrl.lang === 0 && BrowseAloudUrl.voice === "")) { | |
browsealoud.localeId = BrowseAloudUrl.lang | |
} | |
var f = BrowseAloudUrl.speechrules; | |
if (f.length > 0) { | |
var c = 0, | |
g; | |
for (c = 0; c < f.length; c++) { | |
g = new RegExp(f[c].p.replace(/\*/g, "(.+)")); | |
if (document.URL.match(g)) { | |
browsealoud.localeId = f[c].t; | |
break | |
} | |
} | |
} | |
browsealoud.localeId = browsealoud.localeId === "" ? (_baLocale && _baLocale.length > 0 ? _baLocale : 0) : browsealoud.localeId; | |
if (typeof(browsealoud.localeId) !== "number") { | |
var a = 0; | |
for (a = 0; a < this.LANG_MAP.length; a++) { | |
if (this.LANG_MAP[a].reg && browsealoud.localeId === this.LANG_MAP[a].reg) { | |
browsealoud.localeId = this.LANG_MAP[a].lang; | |
break | |
} | |
} | |
} | |
var d = document.createElement("script"); | |
d.src = "//" + this.URL_INFO_ADDRESS + "/js/locales/" + browsealoud.localeId + ".min.js"; | |
if (this.browserDetect.browser === "IE" && this.browserDetect.version <= 8) { | |
d.onreadystatechange = function() { | |
if (d.readyState === "loaded" || d.readyState === "complete") { | |
browsealoud.constructPanelHTML() | |
} | |
} | |
} else { | |
d.onload = function() { | |
browsealoud.constructPanelHTML() | |
} | |
} | |
document.getElementsByTagName("body")[0].appendChild(d) | |
} | |
} | |
}, | |
constructPanelHTML: function() { | |
this.bookmarkletUrl = "//" + this.BASE_ADDRESS + "/Bookmarklet.ashx?l=" + browsealoud.localeId + "&p=true"; | |
this.bookmarkletUrlForLightbox = "javascript:(function(){document.getElementsByTagName('body')[0].appendChild(document.createElement('script')).src='//" + this.BASE_ADDRESS + "/Bookmarklet.ashx?l=" + browsealoud.localeId + "&p=true';})();"; | |
var o = this.isSecure ? "browsealoud.secureToggleBar()" : "browsealoud.toggleBar()", | |
q = "", | |
r = "", | |
p = ""; | |
var t = "http://www.browsealoud.com/page.asp?pg_id=", | |
s = this.ELEMENT_PREFIX, | |
k = "#FFF", | |
j = 80004, | |
i = false, | |
m = "browsealoud.showMoreLightbox();", | |
b = "", | |
a = 0, | |
u = this.protocol + "://" + this.BASE_ADDRESS + "/images"; | |
switch (browsealoud.localeId) { | |
case "us": | |
case 1: | |
j = 80641; | |
a = 1; | |
break; | |
case "es": | |
case 3: | |
j = 80067; | |
a = 2; | |
break; | |
case "mx": | |
case "es-mx": | |
case 2: | |
j = 80319; | |
a = 3; | |
break; | |
case "fr": | |
case 4: | |
j = 80239; | |
a = 4; | |
break; | |
case "ca": | |
case "fr-ca": | |
case 5: | |
j = 80648; | |
a = 5; | |
break; | |
case "de": | |
case 6: | |
j = 80245; | |
a = 6; | |
break; | |
case "it": | |
case 7: | |
j = 80063; | |
a = 7; | |
break; | |
case "nl": | |
case 8: | |
j = ""; | |
a = 8; | |
t = "http://www.browsealoud.nl"; | |
break; | |
case "se": | |
case 9: | |
j = ""; | |
a = 9; | |
t = "http://www.funkaportalen.se/Tema/Ljud/Sa-funkar-Talande-Webb-Plus/"; | |
break; | |
case "au": | |
case 10: | |
j = 80687; | |
a = 10; | |
break; | |
case "pt": | |
case 19: | |
case "pt-br": | |
case 11: | |
j = 80035; | |
a = 11; | |
break; | |
case "no": | |
case 12: | |
j = ""; | |
a = 12; | |
t = "http://www.funkanu.com/no/Universell-utformning/Brukerveiledning-Talende-Web/"; | |
break; | |
case "pl": | |
case 13: | |
j = 80046; | |
a = 13; | |
break; | |
case "fl": | |
case 14: | |
j = 80199; | |
a = 14; | |
break; | |
case "cy": | |
case 15: | |
j = 80468; | |
a = 15; | |
break; | |
case "uk-ie": | |
case 16: | |
j = 80658; | |
a = 16; | |
break; | |
case "uk-sc": | |
case 17: | |
a = 17; | |
break; | |
case "fi": | |
case 18: | |
a = 18; | |
break | |
} | |
this.localeArrayIdx = a; | |
if (i) { | |
m = t + j | |
} | |
var g = BrowseAloudLocale.id === 9 ? "Talande Webb" : BrowseAloudLocale.id === 12 ? "Talende Web" : "BrowseAloud", | |
n = " " + BrowseAloudLocale.users + "</b><br />" + BrowseAloudLocale.panel_drag_drop + '<br /><br /><a href="' + this.bookmarkletUrlForLightbox + '">' + g + "</a>"; | |
switch (this.browserDetect.OS) { | |
case "Windows": | |
case "Mac": | |
case "Linux": | |
b = this.browserDetect.browser == "IE" ? this.browserDetect.browser + this.browserDetect.version : this.browserDetect.browser; | |
break; | |
case "iPad": | |
case "Android": | |
case "iPhone": | |
case "iPod": | |
b = this.browserDetect.OS; | |
n = " " + BrowseAloudLocale.users + "</b><br />" + BrowseAloudLocale.panel_visit_site + (",8,9,12,14,".indexOf("," + browsealoud.localeId + ",") === -1 ? ' <a href="' + t + j + '" target="_blank">browsealoud.com</a>' : ""); | |
break | |
} | |
var e = "", | |
v = ""; | |
if (this.useBarCookies && this.getCookie(this.COOKIE_NAME) === "on" && this.autoHideOnToolbarLoad) { | |
e = this.reducedPanelMode ? "opacity:0;" : "display:none;" | |
} | |
q += '<style type="text/css">body{margin:0;padding:0;background-color:transparent;}#' + s + "_button *,#" + s + "_lb_content{font-family:'Calibri',sans-serif;font-size:12px;color:" + k + ";line-height:normal;}#" + s + "_button{" + e + "}</style>"; | |
r += "#" + s + "_lb_overlay{display:none;position:fixed;top:0;left:0;width:100%;height:100%;background-color:black;z-index:10001;-moz-opacity:0.7;opacity:.70;filter:alpha(opacity=70);}#" + s + "_lb_content{display:none;position:fixed;padding:16px;background-color:white;z-index:10002;overflow:auto;border-radius:10px;box-shadow:5px 5px 10px #b2b2b2;overflow:auto;font-size:11pt;color:#000;}#" + s + "_lb_content a{color:#00F !important;}#" + s + "_close_btn{display:none;z-index:10005;position:fixed;}#" + s + "_close_btn img{padding:0;background:none;}"; | |
v = BrowseAloudLocale.panel_more_intro.replace("{0}", BrowseAloudLocale.id === 9 ? "<b>Talande Webb</b>" : BrowseAloudLocale.id === 12 ? "<b>Talende Web</b>" : "<b>BrowseAloud</b>"); | |
if (!document.getElementById(s + "_lb_overlay")) { | |
p += '<div id="' + s + '_lb_overlay" style="display:none;"></div><div id="' + s + '_lb_content" style="display:none;">' + v + "<br /><br /><b>" + this.browserDetect.browser + n + '</div><div id="' + s + '_close_btn" style="display:none;"><a href="javascript:parent.browsealoud.hideLightbox();"><img src="' + u + '/lb_close.png" alt="" style="border: 0;" /></a></div>' | |
} | |
if (this.reducedPanelMode) { | |
var c = this.displayMode === "logo" ? u + "/ba" + this.imgSuffix + ".png" : this.displayMode; | |
var d = this.displayMode === "logo" || this.displayMode.indexOf("http") === 0; | |
this.debug("Display Mode: " + this.displayMode + "; Is Images? " + d); | |
q = '<div id="' + s + "_button" + (d ? "" : "_link") + '"><a id="' + s + '_link" href="javascript:;" onclick="' + o + ';return false;" title="' + BrowseAloudLocale.panel_try_now + '">'; | |
if (d) { | |
q += '<img src="' + c + '" alt="' + BrowseAloudLocale.panel_try_now + '" />' | |
} else { | |
q += c | |
} | |
q += "</a></div>" | |
} else { | |
q += '<div id="' + s + '_button" style="height:51px;padding:1px 0 0 4px;background:url(' + u + "/ba_button_bg" + this.imgSuffix + '.png) no-repeat top;"><a class="_ba_logo" href="javascript:;" onclick="parent.' + o + ';return false;" title="' + BrowseAloudLocale.panel_try_now + '" style="display:inline-block;float:left;margin:4px 2px 0 0;width:42px;height:42px;vertical-align:middle;"></a><div id="' + s + '_title" style="font-family:Calibri,sans-serif;font-size:14px;font-weight:bold;margin:0 4px 8px 0;text-align:center;width:68px;height:13px;float:right;color:' + k + '">' + BrowseAloudLocale.panel_listen + "</div>"; | |
q += '<a href="javascript:;" onclick="parent.' + o + ';return false;" style="display:inline-block;width:24px;height:24px;vertical-align:middle;margin:0 0 0 6px;outline:0;">'; | |
if (this.useBarCookies && this.getCookie(this.COOKIE_NAME) === "on") { | |
q += '<img src="' + u + "/ba_stop" + this.imgSuffix + '.png" alt="' + BrowseAloudLocale.panel_off + '" title="' + BrowseAloudLocale.panel_off + '" id="' + s + 'icon" style="border: 0;" />' | |
} else { | |
q += '<img src="' + u + "/ba_play" + this.imgSuffix + '.png" alt="' + BrowseAloudLocale.panel_try_now + '" title="' + BrowseAloudLocale.panel_try_now + '" id="' + s + 'icon" style="border: 0;" />' | |
} | |
q += '</a><a href="javascript:;" onclick="parent.' + m + ';return false;" target="_blank" style="display:inline-block;width:24px;height:24px;vertical-align:middle;margin:0 0 0 6px;outline:0;"><img src="' + u + "/ba_more" + this.imgSuffix + '.png" alt="' + BrowseAloudLocale.panel_more + '" title="' + BrowseAloudLocale.panel_more + '" style="border: 0;" /></a></div>' | |
} | |
q += '<div id="' + s + '_zoom" style="display:none;position:absolute;border:2px solid #081c73;width:0px;height:0px;background-color:#ece9d8;border-top-left-radius:10px;"></div>'; | |
if (this.showBar) { | |
var l = document.getElementById("__ba_panel"); | |
if (this.browserDetect.browser === "IE" && this.browserDetect.version <= 8) { | |
var f = document.createElement("style"); | |
f.setAttribute("type", "text/css"); | |
f.styleSheet.cssText = r; | |
document.getElementsByTagName("head")[0].appendChild(f) | |
} else { | |
l.innerHTML += "<style>" + r + "</style>" | |
} | |
l.innerHTML += p; | |
if (!this.reducedPanelMode) { | |
var h = document.createElement("iframe"); | |
h.setAttribute("id", "__ba_frame"); | |
h.setAttribute("frameBorder", "0"); | |
h.setAttribute("border", "0"); | |
h.setAttribute("width", "120"); | |
h.setAttribute("height", "52"); | |
h.setAttribute("scrolling", "no"); | |
h.setAttribute("allowTransparency", "true"); | |
h.setAttribute("style", "width:120px;height:52px;border:0;overflow:hidden;"); | |
document.getElementById("__ba_panel").appendChild(h); | |
h.contentWindow.document.open(); | |
h.contentWindow.document.write(q); | |
h.contentWindow.document.close() | |
} else { | |
l.innerHTML += q | |
} | |
} | |
this.checkForAutoLoad() | |
}, | |
appendJQuery: function() { | |
setTimeout(function() { | |
var a = document.createElement("script"); | |
a.src = "//ajax.googleapis.com/ajax/libs/jquery/" + browsealoud.targetJQVersion + "/jquery.min.js"; | |
document.getElementsByTagName("body")[0].appendChild(a) | |
}, 2000) | |
}, | |
checkForAutoLoad: function() { | |
browsealoud.debug("checkForAutoLoad"); | |
if (!this.getJQVersionOK()) { | |
window.setTimeout(function() { | |
browsealoud.checkForAutoLoad() | |
}, 250) | |
} else { | |
if (browsealoud.jQueryImported) { | |
$bajq = jQuery.noConflict(true) | |
} else { | |
$bajq = jQuery | |
} | |
if (navigator.userAgent.indexOf("Android") > -1) { | |
browsealoud.myInterval = setInterval(browsealoud.checkZoomLevel, 500) | |
} | |
if (this.useBarCookies && this.getCookie(this.COOKIE_NAME) === "on") { | |
this.loadBrowsealoudPlus(false) | |
} | |
$bajq(window).bind("resize touchend", browsealoud.repositionLightbox) | |
} | |
}, | |
getCookie: function(c) { | |
browsealoud.debug("getCookie"); | |
var d, b, a; | |
d = document.cookie.indexOf(c + "="); | |
a = d + c.length + 1; | |
if (!d && c !== document.cookie.substring(0, c.length)) { | |
return null | |
} | |
if (d === -1) { | |
return null | |
} | |
b = document.cookie.indexOf(";", a); | |
if (b === -1) { | |
b = document.cookie.length | |
} | |
return unescape(document.cookie.substring(a, b)) | |
}, | |
setCookie: function(b, d, a, f, c, e) { | |
browsealoud.debug("setCookie"); | |
if (this.useBarCookies) { | |
document.cookie = b + "=" + escape(d) + (a ? ";expires=" + a.toGMTString() : "") + (f ? ";path=" + f : "") + (c ? ";domain=" + c : "") + (e ? ";secure" : "") | |
} | |
}, | |
deleteCookie: function(a, c, b) { | |
browsealoud.debug("deleteCookie"); | |
if (this.getCookie(a)) { | |
document.cookie = a + "=" + (c ? ";path=" + c : "") + (b ? ";domain=" + b : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT" | |
} | |
}, | |
browserDetect: { | |
init: function() { | |
this.browser = this.searchString(this.dataBrowser) || "Unknown"; | |
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version"; | |
this.OS = this.searchString(this.dataOS) || "an unknown OS" | |
}, | |
searchString: function(d) { | |
for (var a = 0; a < d.length; a++) { | |
var b = d[a].string; | |
var c = d[a].prop; | |
this.versionSearchString = d[a].versionSearch || d[a].identity; | |
if (b) { | |
if (b.indexOf(d[a].subString) != -1) { | |
return d[a].identity | |
} | |
} else { | |
if (c) { | |
return d[a].identity | |
} | |
} | |
} | |
}, | |
searchVersion: function(c) { | |
var b = c.indexOf(this.versionSearchString); | |
if (b == -1) { | |
return | |
} | |
var a = parseFloat(c.substring(b + this.versionSearchString.length + 1)); | |
if (document.documentMode) { | |
if (document.documentMode != "undefined") { | |
a = parseFloat(document.documentMode) | |
} | |
} | |
return a | |
}, | |
dataBrowser: [{ | |
string: navigator.userAgent, | |
subString: "Chrome", | |
identity: "Chrome" | |
}, { | |
string: navigator.vendor, | |
subString: "Apple", | |
identity: "Safari", | |
versionSearch: "Version" | |
}, { | |
string: navigator.userAgent, | |
subString: "Firefox", | |
identity: "Firefox" | |
}, { | |
string: navigator.userAgent, | |
subString: "MSIE", | |
identity: "IE", | |
versionSearch: "MSIE" | |
}, { | |
string: navigator.userAgent, | |
subString: "Trident/", | |
identity: "IE", | |
versionSearch: "rv:" | |
}], | |
dataOS: [{ | |
string: navigator.platform, | |
subString: "Win", | |
identity: "Windows" | |
}, { | |
string: navigator.platform, | |
subString: "Mac", | |
identity: "Mac" | |
}, { | |
string: navigator.userAgent, | |
subString: "iPad", | |
identity: "iPad" | |
}, { | |
string: navigator.userAgent, | |
subString: "iPod", | |
identity: "iPod" | |
}, { | |
string: navigator.userAgent, | |
subString: "iPhone", | |
identity: "iPhone" | |
}, { | |
string: navigator.userAgent, | |
subString: "Android", | |
identity: "Android" | |
}] | |
}, | |
zoomToolbar: function() { | |
browsealoud.debug("zoomToolbar"); | |
var d = this, | |
a = (window.outerWidth - 163), | |
e = (5 + $bajq(document).scrollTop()); | |
if ($bajq("#" + this.ELEMENT_PREFIX + "icon").length > 0) { | |
var f = $bajq("#" + this.ELEMENT_PREFIX + "icon").eq(0); | |
$bajq("#" + this.ELEMENT_PREFIX + "_zoom").css({ | |
left: f.position().left, | |
top: f.position().top | |
}) | |
} | |
var c = parseInt(this.getCookie("rwebooks-x") * 100), | |
b = parseInt(this.getCookie("rwebooks-y") * 100); | |
if (c > 1 && b > 1) { | |
a = parseInt($bajq(window).width() / 100 * c); | |
e = parseInt($bajq(window).height() / 100 * b) | |
} | |
setTimeout(function() { | |
if ($bajq("#ba_message_box") && $bajq("#ba_message_box").length === 0 && d.browserDetect.browser !== "IE") { | |
$bajq("#" + d.ELEMENT_PREFIX + "_zoom").show().animate({ | |
width: "199px", | |
left: a + "px", | |
height: "56px", | |
top: e + "px" | |
}, 750, function() { | |
d.hideZoom() | |
}) | |
} | |
}, 500) | |
}, | |
hideZoom: function() { | |
browsealoud.debug("hideZoom"); | |
var a = this.ELEMENT_PREFIX; | |
if (typeof($rw_isPageLoaded) != "undefined" && $rw_isPageLoaded()) { | |
$bajq("#" + a + "_zoom").fadeOut() | |
} else { | |
setTimeout(function() { | |
$bajq("#" + a + "_zoom").fadeOut() | |
}, 1000) | |
} | |
}, | |
setIconImg: function(b) { | |
browsealoud.debug("setIconImg"); | |
if (this.useBarCookies) { | |
var a = this.localeArrayIdx; | |
$bajq("#__ba_frame").contents().find("#" + this.ELEMENT_PREFIX + "icon").attr("src", b ? this.protocol + "://" + this.BASE_ADDRESS + "/images/ba_stop.png" : "http://" + this.BASE_ADDRESS + "/images/ba_play.png").attr("alt", b ? BrowseAloudLocale.panel_off : BrowseAloudLocale.panel_try_now).attr("title", b ? BrowseAloudLocale.panel_off : BrowseAloudLocale.panel_try_now) | |
} | |
}, | |
loadBrowsealoudPlus: function(a) { | |
browsealoud.debug("loadBrowsealoudPlus"); | |
browsealoud.gaTrackEvent("Panel", "Load Toolbar"); | |
document.getElementsByTagName("BODY")[0].appendChild(document.createElement("script")).src = this.bookmarkletUrl; | |
this.isToolbarLoading = true; | |
this.isBarShown = true; | |
this.setPanelVisibility(); | |
this.setElementsDisplay(); | |
if (this.useBarCookies) { | |
this.setBAPlusCookie() | |
} | |
if (a) { | |
this.zoomToolbar() | |
} | |
this.startTimer() | |
}, | |
startTimer: function() { | |
browsealoud.debug("startTimer"); | |
if (!browsealoud.isToolbarLoading && $bajq("#rwDrag").is(":visible")) { | |
browsealoud.checkBarVisibility() | |
} else { | |
browsealoud.isToolbarLoading = !$bajq("#rwDrag").is(":visible"); | |
setTimeout(browsealoud.startTimer, 250) | |
} | |
}, | |
toggleBar: function() { | |
browsealoud.debug("toggleBar"); | |
if (typeof($bajq) === "undefined" && this.jqWaitCounter < 20) { | |
this.debug("$bajq not set / jQuery not loaded / waited " + this.jqWaitCounter + " times"); | |
this.jqWaitCounter++; | |
setTimeout(function() { | |
browsealoud.toggleBar() | |
}, 250) | |
} else { | |
this.isBarShown = !this.isBarShown; | |
var a = this.useBarCookies || this.autoHideOnToolbarLoad; | |
if (this.browserDetect.browser === "IE" && this.browserDetect.version < 8) { | |
if (navigator.userAgent.toLowerCase().indexOf("trident") > -1) { | |
alert(BrowseAloudLocale.ie_compatibility_view) | |
} else { | |
alert(BrowseAloudLocale.ie7_incompatible) | |
} | |
} else { | |
if ($bajq("#texthelpspeechstream").length === 0) { | |
this.loadBrowsealoudPlus(arguments.length === 0) | |
} else { | |
setTimeout(function() { | |
browsealoud.checkBarVisibility() | |
}, 500); | |
$rw_setBarVisibility(a ? this.isBarShown : true); | |
$rw_enableClickToSpeak(!this.isBarShown ? false : (typeof($g_rememberedHoverState) !== "undefined" ? $g_rememberedHoverState : true)); | |
if (this.useBarCookies && this.isBarShown) { | |
this.setBAPlusCookie() | |
} | |
this.setPanelVisibility(); | |
this.setElementsDisplay() | |
} | |
} | |
} | |
}, | |
setElementsDisplay: function() { | |
browsealoud.debug("setElementsDisplay"); | |
this.setIconImg(this.isBarShown); | |
if (!this.isBarShown) { | |
this.deleteCookie(this.COOKIE_NAME, "/") | |
} | |
}, | |
setBAPlusCookie: function() { | |
var a = new Date(); | |
a.setTime(a.getTime() + (1000 * 60 * 60 * 24 * 365)); | |
this.setCookie(this.COOKIE_NAME, "on", a, "/") | |
}, | |
setPanelVisibility: function() { | |
browsealoud.debug("setPanelVisibility"); | |
if (this.autoHideOnToolbarLoad && this.showBar) { | |
var a = this.reducedPanelMode ? $bajq("#" + this.ELEMENT_PREFIX + "_button,#" + this.ELEMENT_PREFIX + "_button_link") : $bajq("#__ba_frame").contents().find("#" + this.ELEMENT_PREFIX + "_button,#" + this.ELEMENT_PREFIX + "_button_link"); | |
if (this.isBarShown) { | |
this.reducedPanelMode ? a.animate({ | |
opacity: 0 | |
}, 500) : a.fadeOut(500) | |
} else { | |
this.reducedPanelMode ? a.animate({ | |
opacity: 1 | |
}, 500) : a.fadeIn(500) | |
} | |
} | |
}, | |
checkBarVisibility: function() { | |
browsealoud.debug("checkBarVisibility"); | |
if (this.useBarCookies || this.autoHideOnToolbarLoad) { | |
if (typeof($bajq) !== "undefined") { | |
if ($bajq("#rwDrag") && !$bajq("#rwDrag").is(":visible") && !$bajq("#rwBackgroundOverlay").is(":visible")) { | |
window.clearInterval(this.visCheckTimer); | |
this.visCheckTimer = null; | |
if (this.isBarShown) { | |
this.toggleBar() | |
} | |
} else { | |
if (!this.visCheckTimer) { | |
this.visCheckTimer = setInterval(function() { | |
browsealoud.checkBarVisibility() | |
}, 500) | |
} | |
} | |
} | |
} | |
}, | |
getLightboxTopLeft: function() { | |
browsealoud.debug("getTopLeft"); | |
var c = 0, | |
b = 0, | |
a = window.innerWidth ? window.innerWidth : $bajq(window).width(); | |
b = parseInt((a / 2) - (this.LIGHTBOX_WIDTH / 2), 10), y = window.innerHeight ? window.innerHeight : $bajq(window).height(), c = parseInt((y / 2) - (this.LIGHTBOX_HEIGHT / 2), 10); | |
return { | |
top: c >= 21 ? c : 21, | |
left: b >= 23 ? b : 23 | |
} | |
}, | |
showMoreLightbox: function() { | |
browsealoud.debug("showMoreLightbox"); | |
browsealoud.gaTrackEvent("Panel", "Load More Info"); | |
var c = this.LIGHTBOX_WIDTH, | |
b = this.LIGHTBOX_HEIGHT, | |
a = this.getLightboxTopLeft(); | |
browsealoud.debug("TL: " + a.left + "; " + a.top); | |
$bajq("#" + this.ELEMENT_PREFIX + "_lb_content").css({ | |
width: c + "px", | |
height: b + "px", | |
left: a.left + "px", | |
top: a.top + "px" | |
}); | |
$bajq("#" + this.ELEMENT_PREFIX + "_close_btn").css({ | |
left: (a.left - 22) + "px", | |
top: (a.top - 20) + "px" | |
}); | |
$bajq("div[id*=" + this.ELEMENT_PREFIX + "_lb],#" + this.ELEMENT_PREFIX + "_close_btn").fadeIn() | |
}, | |
hideLightbox: function() { | |
browsealoud.debug("hideLightbox"); | |
$bajq("div[id*=" + this.ELEMENT_PREFIX + "_lb],#" + this.ELEMENT_PREFIX + "_close_btn").fadeOut() | |
}, | |
checkZoomLevel: function() { | |
browsealoud.debug("checkZoomLevel"); | |
var a = (window.outerWidth - 8) / window.innerWidth; | |
if (a !== browsealoud.currentZoomLevel) { | |
browsealoud.currentZoomLevel = a; | |
browsealoud.repositionLightbox() | |
} | |
}, | |
repositionLightbox: function() { | |
if ($bajq("div[id*=lb_content]").length > 0) { | |
var a = browsealoud.getLightboxTopLeft(); | |
$bajq("#" + browsealoud.ELEMENT_PREFIX + "_lb_content").css({ | |
left: a.left + "px", | |
top: a.top + "px" | |
}); | |
$bajq("#" + browsealoud.ELEMENT_PREFIX + "_close_btn").css({ | |
left: (a.left - 22) + "px", | |
top: (a.top - 20) + "px" | |
}) | |
} | |
}, | |
secureToggleBar: function() { | |
browsealoud.debug("secureToggleBar"); | |
document.getElementsByTagName("BODY")[0].appendChild(document.createElement("script")).src = this.bookmarkletUrl; | |
window.setTimeout(function() { | |
browsealoud.waitForSecurityApproval() | |
}, 3000) | |
}, | |
waitCounter: 0, | |
waitForSecurityApproval: function() { | |
browsealoud.debug("waitForSecurityApproval"); | |
if (this.waitCounter > 60) { | |
return | |
} | |
if ($bajq("#ba_message_box").length === 1) { | |
this.waitCounter++; | |
window.setTimeout(function() { | |
browsealoud.waitForSecurityApproval() | |
}, 500) | |
} else { | |
window.setTimeout(function() { | |
var a = $bajq("#texthelpspeechstream").length > 0; | |
browsealoud.isBarShown = a; | |
browsealoud.setElementsDisplay(a); | |
browsealoud.setPanelVisibility(); | |
browsealoud.checkBarVisibility(); | |
if (a) { | |
$bajq("#" + browsealoud.ELEMENT_PREFIX + "icon").parent().attr("href", "javascript:;").attr("onclick", "browsealoud.toggleBar();return false;"); | |
if (browsealoud.useBarCookies) { | |
browsealoud.setBAPlusCookie() | |
} | |
} | |
}, 1000) | |
} | |
}, | |
debug: function(a) { | |
if (document.URL.indexOf("badebug=true") > -1 && window.console) { | |
console.log(a) | |
} | |
} | |
}; | |
document.write(browsealoud.init()); | |
function $rw_toolbarLoadedCallback() { | |
if (browsealoud.autoHideOnToolbarLoad) { | |
browsealoud.debug("[TOOLBAR LOADED]"); | |
setTimeout(function() { | |
browsealoud.checkBarVisibility() | |
}, 3000) | |
} | |
} | |
function toggleBar() { | |
browsealoud.toggleBar(false) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment