/*UID: 2524*//*UIV: *//*CS: *//*css/2524/ *//*scripts: VA *//* 2524 */ /** * @author Michael Chippington */ /** * Creates DomUtil object. Handles DOM manipulation * * @constructor * @this {DomUtil} */ function DomUtil(){ this.DOM = new Array(); this.browser = new Array(); this.br = {}; this.clientinfo = {}; /** * Adds a Javascript script to the head * * @param script script path */ this.addScript = function(script, id){ var d = document; var h = d.getElementsByTagName("head")[0]; var s = d.createElement("SCRIPT"); var p = (script.indexOf('http://')==-1 && script.indexOf('https://')==-1)?window.location.protocol:''; if(id) s.id = id; s.src = p + script; s.type = "text/javascript"; h.appendChild(s); return s; } /** * Removes a Javascript from the head by id * * @param id script id */ this.removeScriptById = function(id){ var d = document; var h = d.getElementsByTagName("head")[0]; var s = d.getElementById(id); h.removeChild(s); } /** * Removes a Javascript from the head * * @param id script element */ this.removeScript = function(el){ var d = document; var h = d.getElementsByTagName("head")[0]; h.removeChild(el); } /** * Adds a stylesheet to the head * * @param css stylesheet path * @param doc target document */ this.addCSS = function(css, doc){ var d = (doc == undefined)?document: doc; var h = d.getElementsByTagName("head")[0]; var s = d.createElement("LINK"); protocol = ( css.indexOf("http:") || css.indexOf("https:") )?"":window.location.protocol; s.href = protocol + css; s.type = "text/css"; s.rel = "stylesheet" h.appendChild(s); return s; } /** * Creates element object. * * @constructor * @this {element} */ this.element = function(tag, name){ if(name != undefined){ try{ this.el = document.createElement('<'+tag+' name="'+name+'">'); }catch(e){ this.el = document.createElement(tag); } }else{ this.el = document.createElement(tag); } /** * Sets element property. * * @param name stylesheet path */ this.setProperty = function(name, value){ try{ this.el.setAttribute(name, value); }catch(e){ this.el[name] = value; } } this.setStyle = function(name, value){ this.el.style[name] = value; } this.create = function(rootel){ if(!rootel){ document.body.appendChild(this.el) }else{ rootel.appendChild(this.el) } } this.clearContent = function(){ this.el.innerHTML = "" } this.setContent = function(content){ try{ this.el.innerHTML = content }catch(e){ //alert(e) } } this.addElement = function(tag, name){ var newel = new this.constructor(tag, name) this.el.appendChild(newel.el) return newel } this.hideAllContents = function(){ var children = this.el.childNodes; for(var i=0;i=0){ this.browser['type'] = "IE"; if( navigator.appVersion.indexOf("6")){ this.browser['version'] = '6' } if( navigator.appVersion.indexOf("6")){ this.browser['version'] = '7' } if( navigator.appVersion.indexOf("6")){ this.browser['version'] = '8' } } } this.getClientInfo = function(){ if(navigator.appVersion.indexOf("MSIE")>=0){ this.br.name = "IE"; var appv = navigator.appVersion; if( appv.indexOf("MSIE 6") > 0){ this.br.version = 6 } if( appv.indexOf("MSIE 7") > 0){ this.br.version = 7 } if( appv.indexOf("MSIE 8") > 0){ this.br.version = 8 } if( appv.indexOf("MSIE 9") > 0){ this.br.version = 9 } } if(navigator.userAgent.indexOf("mozilla")>=0){ this.br.name = "Mozilla"; } if(navigator.userAgent.indexOf("Chrome")>=0){ this.br.name = "chrome"; } if(navigator.userAgent.indexOf("Safari")>=0){ this.br.name = "Safari"; } if(navigator.userAgent.indexOf("Opera")>=0){ this.br.name = "Opera"; } if(navigator.userAgent.indexOf("iPad") >=0){ this.clientinfo.useragent = "iPad"; } if(navigator.userAgent.indexOf("iPhone") >=0){ this.clientinfo.useragent = "iPhone"; } } this.xhr = function(url, cb){ var xmlhttp; if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else{// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ //if (xmlhttp.readyState==4){ var result = xmlhttp.responseText; cb(result); } } xmlhttp.open("GET", url, true); xmlhttp.send(); } this.toggle = function(ob, state, func1, func2, cookie){ ob[state].value = !ob[state].value; if(ob[state].value){ func1(); }else{ func2(); } if(cookie != 'undefined') this.createCookie(ob[state].cookie, ob[state].value); } this.bind = function(scope, fn){ return function () { fn.apply(scope, arguments) } } this.setStateFromCookie = function(ob, state, func){ var stateval = ob.domutility.readCookie(ob[state].cookie); stateval = (stateval == "true") ? true : false; ob[state].value = stateval; if(ob[state].value) this.bind(ob, ob[func]).call();; } this.overide = function(f, g){ return function(){ return g(f, arguments); } } } /** * @author Michael Chippington */ /** * Creates Events object. Handles all event functions x browser * * @constructor * @this {Events} */ function Events(){ var me = this; this.elContainers = Array(); this.counter1 = 0; this.domutil = new DomUtil(); this.domutil.getClientInfo(); /** * Creates elContainer object. Holds references to DOM elements and their * event functions * * @param el DOM element * @param func function to associate with dom element * @param args arguments to be passed to function */ this.elContainer = function(el, func, args){ this.el = el; this.f = func /** * Calls associated function with applied arguments and prevents event * propagation and event bubbling * * @param e event object instigating function */ this.fnCallback = function( e ){ if(window.addEventListener){ //stop event propagating through document try{ e.stopPropagation(); }catch(e){} }else{ try{ e = window.event e.cancelBubble = true; }catch(e){ } } try{ func.call( window, args ); }catch(e){ // i need to look at this as it throws an error in FF sometimes // although nothing breaks } //this.f.call( window, args ); }; } /** * Adds event and associated function to DOM element * * @param el DOM element * @param ev event to add to DOM element * @param func function to associate with event */ this.addEvent = function(el, ev, func){ elCont = new this.elContainer( el, func, el) //addEventListener is not working in IE9, but present?? if(window.addEventListener && this.domutil.br.name != 'IE'){ elCont.el.addEventListener(ev, elCont.fnCallback, false) }else{//IE ev = "on"+ev elCont.el.attachEvent( ev, elCont.fnCallback ); } this.elContainers.push(elCont); } this.attachEventX = function(el, ev, func, capture){ capture = (capture == undefined)? false: capture; //addEventListener is not working in IE9, but present?? if(window.addEventListener){ el.addEventListener(ev, func, capture) }else{//IE ev = "on"+ev el.attachEvent( ev, func); } } /** * Removes event and associated function from DOM element * * @param el DOM element * @param ev event to add to DOM element * @param func function to associate with event */ this.removeEvent = function(el, ev, func){ if(window.attachEvent && this.domutil.br.name == 'IE'){ ev = "on"+ev } for(i in this.elContainers){ if( this.elContainers[i].el === el ){ if( this.elContainers[i].f === func ){ if(window.addEventListener){ //alert("removing: " + el + " : " + ev + " : " + func) this.elContainers[i].el.removeEventListener(ev, this.elContainers[i].fnCallback, false) }else{ //IE this.elContainers[i].el.detachEvent( ev, this.elContainers[i].fnCallback ); } this.elContainers.splice(i,1); } } } } /** * Add event by tagname * * @param tag DOM element tag * @param ev event to add to DOM element * @param func function to associate with event */ this.addEventByTagname = function(tag, ev, func){ var els = document.getElementsByTagName(tag); for( var i = 0, numels = els.length; i < numels; i++ ){ this.addEvent(els[i], ev, func) } } /** * Remove event by tagname * * @param tag DOM element tag * @param ev event to add to DOM element * @param func function to associate with event */ this.removeEventByTagname = function(tag, ev, func){ var els = document.getElementsByTagName(tag); for( var i = 0, numels = els.length; i < numels; i++ ){ this.removeEvent(els[i], ev, func) } } /** * Add event by id (add child nodes option?) * * @param id DOM element id * @param ev event to add to DOM element * @param func function to associate with event */ this.addEventById = function(id, ev, func){ var el = document.getElementById(id); this.addEvent(el, ev, func) } /** * remove event by id (add child nodes option?) * * @param id DOM element id * @param ev event to add to DOM element * @param func function to associate with event */ this.removeEventById = function(id, ev, func){ var el = document.getElementById(id); this.removeEvent(el, ev, func) } } function Translate(engine){ this.translateArray = new Array(); this.translatePointer = 0; this.sentenceArray = new Array() this.enc = '' this.langOut = '' this.textIn = '' this.textOut = '' this.translation = '' this.callback this.engine = engine this.engineReady = false; this.reqid = null; var me = this var utility = new DomUtil() this.engineReady = function(){ me.engineReady = true; } //privileged method this.googleTranslateSentence = function(result){ try{ var text = result.translation text = me.HTMLEntityToChar(text) me.translateArray.push(text) }catch(e){ } me.translatePointer++ if (me.translateArray.length >= me.sentenceArray.length) { me.translation = me.translateArray.join(". ") me.translateFinished() }else{ me.googleTranslate() } } this.innit = function(){ switch(this.engine.toLowerCase()){ case "google": this.googleDocWrite() utility.addScript("//www.google.com/jsapi") this.loadGoogle() break; case "googleurl": //no setup break; } } this.googleURLTranslate = function(args){ try{ utility.removeScriptById('googleurl'); }catch(e){ } var sl=(!this.langIn)?'':this.langIn; var tl = this.langOut; var q = this.textIn; var e = this.enc; this.reqid = new Date().getTime(); var apppath = args['apppath']; GoogleURLResult.cb = this.transdone; GoogleURLResult.callingob = me; //var q = encodeURIComponent(q); var q = escape(q); var googleurltransscript = apppath + "googleurltrans/googleurltrans.php?e="+e+"&q="+q+"&sl="+sl+"&tl="+tl+"&cb="+this.transdone+"&reqid="+this.reqid; utility.addScript(googleurltransscript, 'googleurl'); //var googleurltransscript = apppath + "googleurltrans/googleurltrans.php?q="+q+"&sl="+sl+"&tl="+tl; //var googleurltransscript = "http://79.98.243.102/TTSapp/" + "googleurltrans/googleurltrans2.php?q="+q+"&sl="+sl+"&tl="+tl; /* utility.xhr(googleurltransscript, function(){ me.translation = arguments[0]; cb(); } ); */ } this.transdone = function(){ if(GoogleURLResult.reqid != this.reqid){ return; } this.translation = unescape( GoogleURLResult.translation ); this.callback(); } } Translate.prototype.translate = function(enc, textIn, langOut, langIn, callback, args){ this.enc = enc this.langOut = langOut this.textIn = textIn this.callback = callback switch(this.engine.toLowerCase()){ case "google": this.googleTranslate(); break; case "googleurl": this.googleURLTranslate(args); break; } } Translate.prototype.loadGoogle = function(){ try{ google.load("language", "1"); google.setOnLoadCallback(this.engineReady) }catch(e){ try{ setTimeout(this.loadGoogle, 500) }catch(e){ } } } Translate.prototype.googleTranslate = function(){ this.sentenceArray = new Array() this.sentenceArray = this.textIn.split(". "); try{ google.language.translate(this.sentenceArray[this.translatePointer], "", this.langOut, this.googleTranslateSentence ) }catch(e){ } } Translate.prototype.translateFinished = function(){ this.translateArray = new Array(); this.translatePointer = 0; this.sentenceArray = new Array() this.callback() } Translate.prototype.HTMLEntityToChar = function(text){ var div = document.createElement('div'); div.innerHTML = text; return div.innerHTML; } Translate.prototype.googleDocWrite = function(){ docWrite = document.write document.write = function(text){ if (text.indexOf("www.google.com/uds/api/language") > 1){ overide = true var d = document; var h = d.getElementsByTagName("head")[0]; var s = d.createElement("SCRIPT"); s.src = window.location.protocol + "//www.google.com/uds/api/language/1.0//default+en_GB.I.js"; s.type = "text/javascript"; h.appendChild(s); return; } if (text.indexOf("www.google.com/uds/") > 1 && text.indexOf("language&v=1") > 1){ overide = true var d = document; var h = d.getElementsByTagName("head")[0]; var s = d.createElement("SCRIPT"); s.src = window.location.protocol + "//www.google.com/uds/?file=language&v=1"; s.type = "text/javascript"; h.appendChild(s); return; } docWrite.apply(this, arguments); } docWrite = document.writeln document.writeln = function(text){ if (text.indexOf("www.google.com/uds/api/language") > 1){ var d = document; var h = d.getElementsByTagName("head")[0]; var s = d.createElement("SCRIPT"); s.src = window.location.protocol + "//www.google.com/uds/api/language/1.0//default+en_GB.I.js"; s.type = "text/javascript"; h.appendChild(s); return; } docWrite.apply(this, arguments); } } /** * Singleton object for cross domain communication * * @GoogleURLResult * @this {GoogleURLResult} */ var GoogleURLResult = { translation : "", reqid : null, cb : null, callingob : null, callcb : function(){ this.cb.call(this.callingob) } } function TTSapp(obname){ /*reading*/ var me = this; var domUtility = new DomUtil(); var eventsUtil = new Events(); this.TTReeadingSpeed = 100; this.hostprotocol = window.location.protocol; this.scripthost = this.hostprotocol+"//r3.talklets-secure.com/"; this.flashhost = this.hostprotocol+'//r3.talklets-secure.com/'; this.windowID = Math.random() + "ID"; this.isIE = (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1); this.basescriptdir = 'TTSapp/'; this.baseflashdir = 'TTSapp/flash/'; this.readSWF = 'TTSapp.swf'; this.curtext = ''; this.apppath = this.scripthost + this.basescriptdir; this.flashpath = this.flashhost + this.baseflashdir; this.obname = obname; this.counter1 = 0; this.counter2 = 0; this.eventsInit = false; this.eventsAttached = false; this.lastel = false; this.curel = null; //captions this.captionscontainer = new domUtility.element("div"); this.captionsposition = "bottom"; //states this.eventson = false; this.stateevents = false; this.captionson = false; //cookienames this.eventscookie this.captionscookie //hmmm - where should this be, here, domutil, events?? this.htmlElements = new Array(); this.htmlElements.push("p"); this.htmlElements.push("a"); this.htmlElements.push("div"); this.htmlElements.push("ul"); this.htmlElements.push("ol"); this.htmlElements.push("li"); this.htmlElements.push("span"); this.htmlElements.push("h1"); this.htmlElements.push("h2"); this.htmlElements.push("h3"); this.htmlElements.push("h4"); this.htmlElements.push("th"); this.htmlElements.push("tr"); this.htmlElements.push("td"); this.htmlElements.push("img"); this.htmlElements.push("select"); this.htmlElements.push("option"); this.htmlElements.push("label"); this.htmlElements.push("input"); this.htmlElementsIgnore = new Array(); this.htmlElementsIgnore.push("body"); this.htmlElementsIgnore.push("script"); this.htmlElementsIgnore.push("iframe"); this.ElementsIdIgnore = new Array(); //delia online this.ElementsIdIgnore.push("tb_overlay"); this.handleselecttext = " is selected. Your options are:. "; this.textboxselection = ""; var translator = new Translate("googleurl"); translator.innit(); this.languages = { english: { ln : 1,isocode : "en",ietfcode : "en-GB",speedfactor : "1",male : "Daniel",female : "Serena" } ,french: { ln : 4,isocode : "fr",ietfcode : "fr-FR",speedfactor : "1",male : "",female : "Virginie" } ,german: { ln : 5,isocode : "de",ietfcode : "de-DE",speedfactor : "1",male : "Steffi",female : "Steffi" } ,greek: { ln : 29,isocode : "el",ietfcode : "el-GR",speedfactor : "1",male : "Alexandros",female : "Alexandros" } ,hindi: { ln : 25,isocode : "hi",ietfcode : "hi-IN",speedfactor : "1",male : "",female : "Lekha" } ,polish: { ln : 9,isocode : "pl",ietfcode : "pl-PL",speedfactor : "1",male : "",female : "Agata" } ,romanian: { ln : 28,isocode : "ro",ietfcode : "ro-RO",speedfactor : "1",male : "",female : "Simona" } ,russian: { ln : 11,isocode : "ru",ietfcode : "ru-RU",speedfactor : "1",male : "",female : "Milena" } ,spanish: { ln : 3,isocode : "es",ietfcode : "es-ES",speedfactor : "0.8",male : "Monica",female : "Monica" } } this.language = this.languages.english; this.ln = this.language.ln; this.defaultlg = 1; this.lg = 1; // 1 = female this.translateTo = this.languages.english; /*css for highlighting and captions*/ domUtility.addCSS(this.apppath+"/css/main.css"); this.setTranslateTo = function(lang){ me.translateTo = me.languages[lang]; domUtility.createCookie('translateto', lang); me.getGender(); } this.getTranslateTo = function(){ var lang = domUtility.readCookie('translateto'); if(lang != null) me.translateTo = me.languages[lang]; } this.captureElement = function(e){ var ignore = false; if(!me.eventson) return; var el; var args = arguments if(!e.target){ el = window.event.srcElement; }else{ el = e.target; } if((me.curel!=me.lastel) && me.curel!=null){ me.lastel = me.curel; me.curel = el; }else{ me.curel = el; } if(me.curel==me.lastel){ return; } for(var j=0;j0){ var el = tagEls[me.counter2] //console.log(me.htmlElements[me.counter1] + " " + me.counter1 + " " + me.counter2 + " " + el.innerHTML) /* eventsUtil.addEventByTagname(me.htmlElements[i], 'mouseover', me.highlight); eventsUtil.addEventByTagname(me.htmlElements[i], 'mouseover', me.read); eventsUtil.addEventByTagname(me.htmlElements[i], 'mouseout', me.unHighlight); eventsUtil.addEventByTagname(me.htmlElements[i], 'mouseout', me.stopReading); */ eventsUtil.addEvent(el, 'mouseover', me.highlight); eventsUtil.addEvent(el, 'mouseover', me.read); eventsUtil.addEvent(el, 'mouseout', me.unHighlight); eventsUtil.addEvent(el, 'mouseout', me.stopReading); } //next element from tag group if(me.counter2=me.htmlElements.length-1){ //console.log(me.counter1 + " : "+me.htmlElements.length-1) //console.log(me.counter2 + " : "+tagEls.length-1) if( (me.counter1 == me.htmlElements.length-1) && (me.counter2>=tagEls.length-1) ){ this.eventsInit = true; } me.counter1 = 0; return; } me.counter2 = 0; me.counter1++; setTimeout(me.addEvent, 0); //console.log("NXT TAG "+me.counter1 +" "+(me.htmlElements.length-1)); } } this.removeEvents = function(){ //me.removeEvent(); /* for(var i=0;i0){ var el = tagEls[me.counter2] //console.log(me.htmlElements[me.counter1] + " " + me.counter1 + " " + me.counter2 + " " + el.innerHTML) eventsUtil.removeEvent(el, 'mouseover', me.highlight) eventsUtil.removeEvent(el, 'mouseover', me.read) eventsUtil.removeEvent(el, 'mouseout', me.unHighlight); eventsUtil.removeEvent(el, 'mouseout', me.stopReading); } //next element from tag group if(me.counter2=me.htmlElements.length-1){ me.counter1 = 0; return; } me.counter2 = 0; me.counter1++; setTimeout(me.removeEvent, 0); //console.log("NXT TAG "+me.counter1 +" "+(me.htmlElements.length-1)); } } this.createFlashCont = function(){ this.apcont = new domUtility.element("div") this.apcont.setProperty("id", "flashTT") this.apcont.setStyle("position", "absolute") this.apcont.setStyle("left", "-100px") this.apcont.create() } this.read = function( e ){ if(!me.eventson) return; var text=''; var args = arguments element = args[0] switch(element.tagName.toLowerCase()){ default: text = element.innerHTML; break; case "area": text = me.handleImageText(element); break; case "img": text = me.handleImageText(element); break; case "select": text = me.handleSelectText(element); break; case "ul": case "ol": text = me.handleListText(element); break; case "textarea": case "input": text = me.handleInputText(element); break; } if(text==undefined) text=''; //HTML entities cause problem for google url translate //cant remove tags here as then cant punctuate from HTML text = this.punctuateFromHTMLTags(text); text = this.cleanString(text); if(me.language != me.translateTo){ me.ln = me.translateTo.ln //clear ob?? if(navigator.appVersion.indexOf("MSIE")>0) translator = new Translate("googleurl") else translator = new Translate("googleurl") args = Array(); args['apppath'] = this.apppath; //translator.translate(text, me.translateTo.isocode, function(){ translator.translate(document.inputEncoding, text, me.translateTo.isocode, '', function(){ me.curtext = translator.translation; me.setCaptionsText(me.curtext); //console.log( "curtxt: " + me.curtext ); text = me.encodeTxt(me.curtext); me.sendTextToFlash(text) }, args) }else{ me.ln = me.language.ln /* me.startReading(text) */ //clear ob?? if(navigator.appVersion.indexOf("MSIE")>0) translator = new Translate("googleurl") else translator = new Translate("googleurl") args = Array(); args['apppath'] = this.apppath; //translator.translate(text, me.translateTo.isocode, function(){ translator.translate(document.inputEncoding, text, me.translateTo.isocode, '', function(){ if( !translator.translation ){ me.ln = me.language.ln me.startReading(text) }else{ me.startReading(translator.translation) } }, args) } } this.handleImageText = function(element){ var text=''; if(element.alt) var alttext = element.alt if(element.title) var titletext = element.title; if(alttext==titletext) text = alttext; else text = alttext + '. ' + titletext; return text; } this.handleSelectText = function(element){ var options=''; var text=''; selectedoption = element.options[element.selectedIndex].innerHTML; for (i=0;i < element.options.length;i++){ options += element.options[i].innerHTML + ". "; } text = selectedoption + this.handleselecttext + options; return text; } this.handleListText = function(element){ var text=''; for(var i in element.childNodes){ //why are there undefined elements in here? if(element.childNodes[i].tagName != undefined) text += element.childNodes[i].innerHTML+". "; } return text; } this.handleInputText = function(element){ text = element.value; if(text.length<=0){ if(element.placeholder){ text=element.placeholder; } } return text; } this.sendTextToFlash = function(readtext){ this.apcont.clearContent(); //create with DomUtil? var swfPath = this.flashpath + this.readSWF; flashobject = ""+ ""+ ""+ ""+ ""+ ""+ "" if (this.apcont) { this.apcont.setContent(flashobject); } try{ //console.log(readtext) }catch(e){ } } this.encodeTxt = function(txt){ var txtIn = ""; var txtOut = ""; txtIn=""+txt; voiceSpeedFactor = (me.language != me.translateTo)? me.translateTo.speedfactor : this.language.speedfactor var sp = this.TTReeadingSpeed; sp = parseInt(sp) * parseFloat(voiceSpeedFactor); txt=txt.replace(/\. /g,". \\!\\rate="+sp+"\\"); txtIn = "\\!\\rate="+sp+"\\" + txt; for (var x = 0; x <= txtIn.length - 1; x++) { try { txtOut = txtOut + "_" + txtIn.charCodeAt(x); } catch (err) { txtOut = txtOut + "_0"; } } return "_enc" + txtOut; } this.punctuateFromHTMLTags = function(text){ text +=''; text = text.replace(/<\/li>/ig, ". "); text = text.replace(/<\/h1>/ig, ". "); text = text.replace(/<\/h2>/ig, ". "); text = text.replace(/<\/h3>/ig, ". "); text = text.replace(/<\/h4>/ig, ". "); return text; } this.removeHTMLTags = function(text){ var mydiv = document.createElement("div"); mydiv.innerHTML = text; if (document.all){ return mydiv.innerText; }else{ return mydiv.textContent; } } this.removeHTMLTagContent = function(text, opentag, closetag){ //why did i put this here?? //text = text.replace("\"", "\"?\'?") myregexp = new RegExp(''+opentag+'.*'+closetag+'', "gi") return text.replace(myregexp, "") } this.removeHTMLTagsContent = function(text){ //text = this.removeHTMLTagContent(text, '') text = this.removeHTMLTagContent(text, '', ''); text = this.removeHTMLTagContent(text, ''); text = this.removeHTMLTagContent(text, ''); return text; } this.removeLineBreaks = function(text){ return text.replace(/[\r\n]+/g, " "); } this.stripText = function(text){ return text.replace(/^\s+|\s+$/g,'').replace(/\s+/g,' '); } /* this.removeHTMLTagContent = function(text, tag){ //why did i put this here?? //text = text.replace("\"", "\"?\'?") myregexp = new RegExp( "((<[\s\/]*"+tag+"\b[^>]*>)([^>]*)(<\/"+tag+">))" , "gi") return text.replace(myregexp, "") } this.removeHTMLTagsContent = function(text){ text = this.removeHTMLTagContent(text, 'script') text = this.removeHTMLTagContent(text, 'style') text = this.removeHTMLTagContent(text, 'noscript') return text; } */ this.cleanString = function(text){ text = this.removeLineBreaks(text) text = this.removeHTMLTagsContent(text) text = this.removeHTMLTags(text) text = this.stripText(text) return text } this.startReading = function(text){ if(!text){ return; } //text = this.punctuateFromHTMLTags(text); //text = this.cleanString(text); me.curtext = text me.setCaptionsText(text) text = this.encodeTxt(text); this.sendTextToFlash(text) } this.createCaptions = function(){ this.captionscontainer.setProperty("id", "captions") domUtility.addClass(this.captionscontainer.el, "captions-bottom") domUtility.addClass(this.captionscontainer.el, "TTSapp-hidden") //remove all events will remove this eventsUtil.addEvent(this.captionscontainer.el, "mouseover", function(){me.toggleCaptionsPosition()}, false) this.captionscontainer.create() } this.showCaptions = function(text){ me.setCaptionsText(text) domUtility.addClass(me.captionscontainer.el, "TTSapp-visible") domUtility.removeClass(me.captionscontainer.el, "TTSapp-hidden") } this.hideCaptions = function(){ domUtility.addClass(me.captionscontainer.el, "TTSapp-hidden") domUtility.removeClass(me.captionscontainer.el, "TTSapp-visible") } this.setCaptionsState = function(state){ me.captionson = state; //console.log("captionon:" + this.captionson) } this.setCaptionsText = function(text){ if(text != undefined){ me.captionscontainer.setContent(text) } } this.toggleCaptionsPosition = function(){ me.captionsposition = (me.captionsposition == "top") ? "bottom" : "top"; if(me.captionsposition == "top"){ newClass = "captions-top"; oldClass = "captions-bottom"; } else if(me.captionsposition == "bottom"){ newClass = "captions-bottom"; oldClass = "captions-top"; } domUtility.addClass(me.captionscontainer.el, newClass) domUtility.removeClass(me.captionscontainer.el, oldClass) } this.readSelectText = function(){ if(me.language != me.translateTo){ me.ln = me.translateTo.ln; //clear ob?? if(navigator.appVersion.indexOf("MSIE")>0) translator = new Translate("googleurl") else translator = new Translate("googleurl") args = Array(); args['apppath'] = me.apppath; //var text = me.setSelectText(); var text = me.getSelectionHtml(); text = me.punctuateFromHTMLTags(text); text = me.cleanString(text); //translator.translate(text, me.translateTo.isocode, function(){ translator.translate(document.inputEncoding, text, me.translateTo.isocode, '', function(){ me.curtext = translator.translation; me.setCaptionsText(me.curtext); text = me.encodeTxt(me.curtext); me.sendTextToFlash(text) }, args) }else{ me.ln = me.language.ln; /* me.startReading(me.setSelectText()); */ //clear ob?? translator = new Translate("googleurl") args = Array(); args['apppath'] = me.apppath; //var text = me.setSelectText(); var text = me.getSelectionHtml(); text = me.punctuateFromHTMLTags(text); text = me.cleanString(text); //translator.translate(text, me.translateTo.isocode, function(){ translator.translate(document.inputEncoding, text, me.translateTo.isocode, '', function(){ me.curtext = translator.translation; me.setCaptionsText(me.curtext); text = me.encodeTxt(me.curtext); me.sendTextToFlash(text) }, args) } } this.saveMp3 = function(){ //var text = me.setSelectText(); var text = me.getSelectionHtml(); text = me.punctuateFromHTMLTags(text); text = me.cleanString(text); me.curtext = text; me.submitAjaxForm(me.curtext) } this.stopReading = function(){ me.apcont.clearContent(); if(me.captionson == true) me.hideCaptions(); } this.decodeTxt = function(txt){ //txt = txt.replace("_enc_", ""); txt = txt.replace("_enc", ""); txt = txt.replace(". ",''); var txtOut = " "; var txtIn = "" + txt; var txtOutArray; txtOutArray = txtIn.split("_"); for (var i = 0; i <= txtOutArray.length - 1; i++) { if(txtOutArray[i].length>=1){ theChar = String.fromCharCode(txtOutArray[i]) txtOut += theChar; } } //remove TTS info in escape sequence from string //txtOut = txtOut.replace(/rate/g, "") txtOut = txtOut.replace(/\\\!\\[a-zA-Z=0-9]*\\/g, "") return txtOut; } this.submitAjaxForm = function(text){ text = me.cleanString(text) me.TTSform.t.setProperty("value", text) me.TTSform.l.setProperty("value", this.ln) me.TTSform.g.setProperty("value", this.lg) me.TTSform.el.submit(); } //user preference this.toggle = function(state, func1, func2, cookie){ me[state] = !me[state]; if(me[state]){ func1(); }else{ func2(); } if(cookie != 'undefined') domUtility.createCookie(state, me[state].toString() ); } //domutil? this.setStateFromCookie = function(cookie, func){ state = domUtility.readCookie(cookie); state = (state == "true") ? true : false; me[cookie] = state; if(state) func(state); } this.setUserPreferences = function(){ this.setStateFromCookie('stateevents', this.addEvents); this.setStateFromCookie('captions', this.setCaptionsState); this.getTranslateTo(); this.getGender(); } this.getGender = function(){ var gender = domUtility.readCookie('gender'); //if no gender cookie, use the default if(gender==null){ gender = this.defaultlg; } //check voice has available gender gendercheck = this.checkGenderAvailable(gender); //if checkGenderAvailable returned a new voice id, use it if(typeof gendercheck != 'boolean'){ gender = gendercheck; } this.lg = parseInt(gender); } this.checkGenderAvailable = function(gender){ if(gender=='2' && !this.translateTo.male.length) gender='1'; else if(gender=='1' && !this.translateTo.female.length) gender='2'; else gender = true; return gender; } this.setGender = function(gender, store){ this.lg = gender; if(store) domUtility.createCookie('gender', gender) } this.toggleEvents = function(){ me.toggle('stateevents', me.addEvents, me.removeEvents); } this.highlight = function(){ if(!me.eventson) return; var args = arguments var domUtility = new DomUtil(); element = args[0] domUtility.addClass(element, 'TTShighlight') } this.unHighlight = function(){ var args = arguments var domUtility = new DomUtil(); element = args[0] //console.log( args[0] ) domUtility.removeClass(element, 'TTShighlight') } this.addTextboxCaptureEvents = function(){ var inputs = document.getElementsByTagName("input"); for(i=0;i0) { var container = document.createElement("div"); for (var i = 0, len = sel.rangeCount; i < len; ++i) { container.appendChild(sel.getRangeAt(i).cloneContents()); } html = container.innerHTML; } } else if (typeof document.selection != "undefined") { if (document.selection.type == "Text") { html = document.selection.createRange().htmlText; } } //use text box selection if available if(typeof html == "undefined" && this.textboxselection.length>0){ html = this.textboxselection; } return html; } TTSapp.prototype.createAjaxForm = function(){ var domUtility = new DomUtil(); this.TTSiframe = new domUtility.element("iframe") this.TTSiframe.setProperty("id", "TTSiframe") this.TTSiframe.setProperty("name", "TTSiframe") this.TTSiframe.setStyle("position", "absolute") this.TTSiframe.setStyle("left", "-1000px") this.TTSiframe.setStyle("visibility", "hidden") this.TTSiframe.create() this.TTSform = new domUtility.element("form") this.TTSform.setProperty("id", "TTSform") this.TTSform.setProperty("name", "TTSform") this.TTSform.setProperty("target", "TTSiframe") this.TTSform.setStyle("position", "absolute") this.TTSform.setStyle("left", "-1000px") this.TTSform.create() this.TTSform.t = this.TTSform.addElement('input') this.TTSform.t.setProperty("name", "t") this.TTSform.l = this.TTSform.addElement('input') this.TTSform.l.setProperty("name", "l") this.TTSform.g = this.TTSform.addElement('input') this.TTSform.g.setProperty("name", "g") this.TTSform.setProperty("action", this.scripthost+"/"+this.basescriptdir+"/") } TTSapp.prototype.soundFinished = function(){ this.hideCaptions(); } TTSapp.prototype.soundStarted = function(text){ var dtext = this.decodeTxt(text); if( this.captionson == true ){ this.showCaptions(dtext); } } /* gender */ function UI(ttsob, visob){ var me = this; var domutility = new DomUtil(); var eventsutil = new Events(); this.ttsob = ttsob; this.visob = visob; this.stateevents = false; this.interfacecont = new domutility.element('div'); this.interfacecontid = 'barholder'; this.menucont = new domutility.element('div'); this.designid = 225; this.helplink = 'http://www.roktalk.co.uk/user-guide.html'; this.server = this.ttsob.apppath; this.barvisible = false; this.uitext = TTSUiText = {"logo":"ROKTALK","play":"Play: Highlight text with mouse and press Play to listen","en-GB":"English","mouseover-off":"Auto reading is off, click to turn on","es-ES":"Spanish","translation-captions":"Captions","en-US":"American","fr-FR":"French","de-DE":"German","ar-WW":"Arabic","it-IT":"Italian","en-IE":"Irish","pl-PL":"Polish","ru-RU":"Russian","zh-HK":"Mandarin","fi-FI":"Finnish","pt-PT":"Portuguese","sv-SE":"Swedish","ja-JP":"Japanese","ca-ES":"Catalan","pt-BR":"Brazilian","cs-CZ":"Czech","no-NO":"Norwegian","zh-TW":"Cantonese","tr-TR":"Turkish","es-MX":"Mexican","sk-SK":"Slovak","hi-IN":"Hindi","nl-NL":"Dutch","fr-CA":"Canadian","ro-RO":"Romanian","el-GR":"Greek","ko-KR":"Korean","stop":"Stop","mp3":"MP3: Highlight text with mouse and press Save as MP3","mouseover-on":"Auto reading is on, click to turn Off","translation-menu":"Translate: Listen to the page text in selected language","font-size-reset":"click AAA: Reset font size","font-size-increase":"click + to Increase font size","font-size-decrease":"click - to Decrease font size","highlight-menu":"Change page background background colour","help":"Information","eu-ES":"Basque ","hu-HU":"Hungarian","bn-IN":"Bengali","zh-CN":"MandarinCN"};; this.create = function(){ domutility.addCSS(this.server + "/css/ui.css"); this.interfacecont.setProperty('id', this.interfacecontid); this.interfacecont.setStyle('display', 'none'); this.logo = this.interfacecont.addElement('img'); this.logo.el.src = this.server + '/images/'+this.designid+'/logo_left_small.gif'; this.logo.el.alt = this.uitext.logo; this.logo.el.title = this.uitext.logo; this.logo.setStyle('display', 'inline'); this.speakimg = this.interfacecont.addElement('img'); this.speakimg.el.src = this.server + '/images/'+this.designid+'/speak.gif'; this.speakimg.el.alt = ""; this.speakimg.setStyle('display', 'inline'); this.play = this.interfacecont.addElement('a'); this.play.el.href = 'javascript:void(0);'; this.playimg = this.play.addElement('img'); this.playimg.setStyle('border', '0px'); this.playimg.el.src = this.server + '/images/'+this.designid+'/play.gif'; this.playimg.el.onclick = this.readSelectText this.playimg.el.alt = this.uitext.play; this.playimg.el.title = this.uitext.play; this.playimg.setStyle('display', 'inline'); this.stop = this.interfacecont.addElement('a'); this.stop.el.href = 'javascript:void(0);'; this.stopimg = this.stop.addElement('img'); this.stopimg.setStyle('border', '0px'); this.stopimg.el.src = this.server + '/images/'+this.designid+'/stop.gif'; this.stopimg.el.onclick = this.stopReading this.stopimg.el.alt = this.uitext.stop; this.stopimg.el.title = this.uitext.stop; this.stopimg.setStyle('display', 'inline'); this.mp3 = this.interfacecont.addElement('a'); this.mp3.el.href = 'javascript:void(0);'; this.mp3img = this.mp3.addElement('img'); this.mp3img.setStyle('border', '0px'); this.mp3img.el.src = this.server + '/images/'+this.designid+'/mp3.gif'; this.mp3img.el.onclick = this.saveMp3; this.mp3img.el.alt = this.uitext.mp3; this.mp3img.el.title = this.uitext.mp3; this.mp3img.setStyle('display', 'inline'); this.eventtoggle = this.interfacecont.addElement('a'); this.eventtoggle.el.href = 'javascript:void(0);'; this.eventtoggleimg = this.eventtoggle.addElement('img'); this.eventtoggleimg.setStyle('border', '0px'); this.eventtoggleimg.el.src = this.server + '/images/'+this.designid+'/off.gif'; this.eventtoggleimg.el.onclick = this.toggleEvents; this.eventtoggleimg.el.alt = this.uitext['mouseover-off']; this.eventtoggleimg.el.title = this.uitext['mouseover-off']; this.eventtoggleimg.setStyle('display', 'inline'); this.translation = this.interfacecont.addElement('a'); this.translation.el.href = 'javascript:void(0);'; this.translationimg = this.translation.addElement('img'); this.translationimg.setStyle('border', '0px'); this.translationimg.el.src = this.server + '/images/'+this.designid+'/translation.jpg'; this.translationimg.el.onclick = this.toggleTranslationMenu; this.translationimg.el.alt = this.uitext['translation-menu']; this.translationimg.el.title = this.uitext['translation-menu']; this.translationimg.setStyle('display', 'inline'); this.translationMenu = this.interfacecont.addElement('ul'); this.translationMenu.setProperty('id', "translationoptions"); domutility.addClass(me.translationMenu.el, "TTSapp-hidden"); this.buildLanguageOptions(); this.fontsizeimg = this.interfacecont.addElement('img'); this.fontsizeimg.setStyle('border', '0px'); this.fontsizeimg.el.src = this.server + '/images/'+this.designid+'/text_size.gif'; this.fontsizeimg.setProperty('useMap', '#fontsizemap'); this.fontsizeimg.el.alt = this.uitext['font-size-reset']; this.fontsizeimg.setStyle('display', 'inline'); this.customstyle = this.interfacecont.addElement('a'); this.customstyle.el.href = 'javascript:void(0);'; this.customstyleimg = this.customstyle.addElement('img'); this.customstyleimg.setStyle('border', '0px'); this.customstyleimg.el.src = this.server + '/images/'+this.designid+'/highlight.jpg'; this.customstyleimg.el.onclick = this.toggleCustomStyleMenu; this.customstyleimg.el.alt = this.uitext['highlight-menu']; this.customstyleimg.el.title = this.uitext['highlight-menu']; this.customstyleimg.setStyle('display', 'inline'); this.customstylemenu = this.interfacecont.addElement('div'); this.customstylemenu.setProperty('id', "customstyleoptions"); domutility.addClass(me.customstylemenu.el, "TTSapp-hidden"); this.buildCustomStyleOptions(); this.gendertoggle = this.interfacecont.addElement('a'); this.gendertoggle.el.href = 'javascript:void(0);'; this.gendertoggleimg = this.gendertoggle.addElement('img'); this.gendertoggleimg.setStyle('border', '0px'); this.gendertoggleimg.el.src = this.server + '/images/'+this.designid+'/gender_female.gif'; this.gendertoggleimg.el.onclick = this.toggleGender; this.help = this.interfacecont.addElement('a'); this.help.el.href = 'javascript:void(0);'; this.help.el.onclick = this.showHelp; this.helpimg = this.help.addElement('img'); this.helpimg.setStyle('border', '0px'); this.helpimg.el.src = this.server + '/images/'+this.designid+'/help.jpg'; //this.helpimg.el.onclick = this.showHelp; this.helpimg.el.alt = this.uitext.help; this.helpimg.el.title = this.uitext.help; this.helpimg.setStyle('display', 'inline'); this.fontsizemap = this.interfacecont.addElement('map', 'fontsizemap'); this.fontsizemap.setProperty('name', 'fontsizemap'); this.fontsizemaparea = this.fontsizemap.addElement('area'); this.fontsizemaparea.setProperty('shape', 'rect'); this.fontsizemaparea.setProperty('coords', '0,0,61,66'); this.fontsizemaparea.setProperty('href', 'javascript: void(0);'); this.fontsizemaparea.setProperty('alt', this.uitext['font-size-reset']); this.fontsizemaparea.setProperty('title', this.uitext['font-size-reset']); this.fontsizemaparea.el.onclick = this.resetFontSize; this.fontsizemaparea2 = this.fontsizemap.addElement('area'); this.fontsizemaparea2.setProperty('shape', 'rect'); this.fontsizemaparea2.setProperty('coords', '62,0,95,41'); this.fontsizemaparea2.setProperty('href', 'javascript:void(0);'); this.fontsizemaparea2.setProperty('alt', this.uitext['font-size-increase']); this.fontsizemaparea2.setProperty('title', this.uitext['font-size-increase']); this.fontsizemaparea2.el.onclick = this.increaseFontSize; this.fontsizemaparea3 = this.fontsizemap.addElement('area'); this.fontsizemaparea3.setProperty('shape', 'rect'); this.fontsizemaparea3.setProperty('coords', '64,46,98,67'); this.fontsizemaparea3.setProperty('href', 'javascript:void(0);'); this.fontsizemaparea3.setProperty('alt', this.uitext['font-size-derease']); this.fontsizemaparea3.setProperty('title', this.uitext['font-size-decrease']); this.fontsizemaparea3.el.onclick = this.decreaseFontSize; this.interfacecont.create(); } this.showHelp = function(){ window.location.assign(me.helplink); } this.readSelectText = function(){ me.ttsob.readSelectText(); } this.stopReading = function(){ me.ttsob.stopReading(); } this.saveMp3 = function(){ me.ttsob.saveMp3(); } this.increaseFontSize = function(){ me.visob.changeFontSize('increase'); me.setLockBar(); } this.decreaseFontSize = function(){ me.visob.changeFontSize('decrease'); me.setLockBar(); } this.resetFontSize = function(){ me.visob.changeFontSize('reset'); me.setLockBar(); } this.lockEl = function(id, xin, yin){ isIE = (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1); var ns = !isIE; var d = document; //if (document.getElementById(id).style.display != "none") { var xout; var yout; var el = d.getElementById(id) var px = document.layers ? "" : "px"; var scrWidth = ns ? innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth; var scrscrlHeight = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop; var scrHeight = ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight; yout = scrHeight - yin; xout = (scrWidth / 2 ) - xin; el.style.left = (xout) + px; if (document.compatMode == 'CSS1Compat'){ if (navigator.appVersion.indexOf('IE 6.0') >= 1) { TTbarfixed = "0"; yout += scrscrlHeight; el.style.top = yout + px; }else { TTbarfixed = "1"; el.style.position = "fixed"; el.style.top = yout + px; } }else { //quirks mode if (isIE && !document.getElementById("fixhack")){ //IE TTbarfixed = "1"; el.style.position = "fixed"; var d = document; var h = d.getElementsByTagName('head')[0]; var s = d.createElement('link'); s.rel = 'stylesheet'; s.href = this.server + '/css/fixhack.css'; s.type = 'text/css'; s.id="fixhack"; h.appendChild(s); //this.style.zindex = '6000'; }else{ //FF TTbarfixed = "1"; el.style.position = "fixed"; el.style.top = yout + px; } } var parstr = "FloatDiv('" + id + "', " + xin + ", " + yin + ");"; if (TTbarfixed == "0"){ var ret = setTimeout(parstr, 30); }else{ // var ret = setTimeout(parstr, 1000); } //} } this.setLockBar = function(){ me.lockEl(me.interfacecontid, 505, 69); } this.doLockBar = function(){ eventsutil.addEvent(window, 'load', me.setLockBar()) eventsutil.addEvent(window, 'resize', me.setLockBar) //eventsutil.addEvent(window, 'scroll', me.setLockDiv) } this.toggleEvents = function(){ me.ttsob.toggle('stateevents', me.eventReadingOn, me.eventReadingOff); } this.toggleCaptions = function(){ me.ttsob.toggle('captions', me.showCaptions, me.hideCaptions ); } this.toggleGender = function(){ switch(me.ttsob.lg){ case 2: me.genderFemale(); break; case 1: me.genderMale(); break; } } this.genderMale = function(store){ store = (typeof store === "undefined") ? true: store; if(!me.ttsob.translateTo.male.length) return; me.ttsob.setGender(2, store); me.gendertoggleimg.el.src = me.server + '/images/'+me.designid+'/gender_male.gif'; } this.genderFemale = function(store){ store = (typeof store === "undefined") ? true: store; if(!me.ttsob.translateTo.female.length) return; me.ttsob.setGender(1, store); me.gendertoggleimg.el.src = me.server + '/images/'+me.designid+'/gender_female.gif'; } this.eventReadingOn = function(){ me.eventtoggleimg.el.src = me.server + '/images/'+me.designid+'/on.gif'; me.eventtoggleimg.el.alt = me.uitext['mouseover-on']; me.eventtoggleimg.el.title = me.uitext['mouseover-on'];; me.ttsob.addEvents(); } this.eventReadingOff = function(){ me.eventtoggleimg.el.src = me.server + '/images/'+me.designid+'/off.gif'; me.eventtoggleimg.el.alt = me.uitext['mouseover-off']; me.eventtoggleimg.el.title = me.uitext['mouseover-off'];; me.ttsob.removeEvents(); me.ttsob.stopReading(); } this.showCaptions = function(){ //me.ttsob.showCaptions(); me.ttsob.setCaptionsState(true); domutility.addClass(me.captionsoptionholder.el, 'TTlanguageon'); domutility.removeClass(me.captionsoptionholder.el, 'TTlanguageoff'); } this.hideCaptions = function(){ //me.ttsob.hideCaptions(); me.ttsob.setCaptionsState(false); domutility.addClass(me.captionsoptionholder.el, 'TTlanguageoff'); domutility.removeClass(me.captionsoptionholder.el, 'TTlanguageon'); } this.toggleBar = function(){ me.ttsob.toggle('bardisplay', me.showBar, me.hideBar); } this.showTranslationMenu = function(){ domutility.addClass(me.translationMenu.el, "TTSapp-visible"); domutility.removeClass(me.translationMenu.el, "TTSapp-hidden"); } this.hideTranslationMenu = function(){ domutility.addClass(me.translationMenu.el, "TTSapp-hidden"); domutility.removeClass(me.translationMenu.el, "TTSapp-visible"); } this.toggleTranslationMenu = function(){ me.ttsob.toggle('translationmenu', me.showTranslationMenu, me.hideTranslationMenu); } this.showCustomStyleMenu = function(){ domutility.addClass(me.customstylemenu.el, "TTSapp-visible"); domutility.removeClass(me.customstylemenu.el, "TTSapp-hidden"); } this.hideCustomStyleMenu = function(){ domutility.addClass(me.customstylemenu.el, "TTSapp-hidden"); domutility.removeClass(me.customstylemenu.el, "TTSapp-visible"); } this.toggleCustomStyleMenu = function(){ me.ttsob.toggle('customstylemenu', me.showCustomStyleMenu, me.hideCustomStyleMenu); } this.showBar = function(){ //need x broswer check position function inplace = me.interfacecont.getStyle('position'); //alert( inplace ) if(inplace!='fixed'){ setTimeout(me.showBar, 50) }else{ //me.interfacecont.showAllContents(); me.interfacecont.setStyle('display', 'inline'); } me.barvisible = true; } this.hideBar = function(){ //me.interfacecont.hideAllContents(); me.interfacecont.setStyle('display', 'none'); me.barvisible = false; } this.buildLanguageOptions = function(){ for(var lang in me.ttsob.languages){ name = lang; isocode = me.ttsob.languages[lang].isocode; optionholder = this.translationMenu.addElement('li'); optionlink = optionholder.addElement('a'); optionlink.setContent(this.uitext[me.ttsob.languages[lang].ietfcode]+" "); optionlink.el.href = 'javascript: void(0)'; //closure optionlink.el.onclick = (function(name, optionholder){ return function(){ me.ttsob.setTranslateTo(name); me.setGender(); //clear existing language on var children = me.translationMenu.el.childNodes; for(var i=0;i0){ this.domarray[i].style['fontSize'] = (size * factor) + unit; } }catch(e){ } } } } this.setFontSizeStatic = function(factor){ if(this.currentstaticfontcss!=null){ var h = document.getElementsByTagName("head")[0]; h.removeChild(this.currentstaticfontcss); } this.currentstaticfontcss = domutility.addCSS(this.apppath+"/css/font"+(factor-1)+".css"); } this.setZoom = function(factor){ var base = 1; var html = document.getElementsByTagName('html')[0]; html.style.width = "101%"; if(factor == this.defaultfontfactor){ document.body.style.zoom = 0; html.style.width = "100%"; } base = (document.body.style.zoom || document.body.style.zoom==0)?base:1; document.body.style.zoom = base * factor; } this.handleZoomType = function(factor){ switch( this.zoomtype){ case "font": this.setFontSize(factor); break; case "zoom": this.setZoom(factor); break; case "fontstatic": this.setFontSizeStatic(factor); break; } } this.setFontSizePreference = function(){ var ff; if(domutility.readCookie(this.fontsizecookie)!=undefined){ ff = domutility.readCookie(this.fontsizecookie) this.currentfontfactor = ff; }else{ ff = this.currentfontfactor; } this.handleZoomType(ff); } this.changeFontSize = function(dir){ var factor; switch(dir){ case "increase": switch(this.zoomtype){ case "fontstatic": if(this.currentfontfactor < this.staticfontcsslimit){ factor = parseInt(this.currentfontfactor) + parseInt(this.increasestaticfontfactor); }else{ factor = parseInt(this.currentfontfactor) } break; default: factor = this.currentfontfactor *= this.increasefontfactor; break; } break; case "decrease": switch(this.zoomtype){ case "fontstatic": if(this.currentfontfactor > this.defaultfontfactor){ factor = this.currentfontfactor - this.increasestaticfontfactor; }else factor = parseInt(this.currentfontfactor) break; default: factor = this.currentfontfactor /= this.increasefontfactor; break; } break; case "reset": factor = this.currentfontfactor = this.defaultfontfactor; break; } this.currentfontfactor = factor; this.handleZoomType(factor); domutility.createCookie(this.fontsizecookie, factor); } this.customStyleSwitch = function(value){ this.customStyleRemove(); switch(value){ case "reset": break; default: var csshref = this.cssbasedir + value + '.css'; //alert(csshref) try{ //if(document.createStyleSheet){ // document.createStyleSheet(csshref); //} //else{ //alert('add css') //settimeout = IE6 fix setTimeout(function(){domutility.addCSS(csshref)}, 0); //} }catch(e){ } this.customstylesheets.push(csshref); domutility.createCookie(this.customstylecookie, value); break; } } this.customStyleRemove = function(){ var ss = document.getElementsByTagName("link"); for(var i = 0;i0){ links[j].setAttribute("oldtarget",links[j].target); } links[j].target = "_blank"; }else{} j++; } }, reinstatePdfLinks : function(){ var links = document.getElementsByTagName("a"); var regex = /(^.*(\.|\/)(?!(pdf)$)(?![^\.\/]*(\.|\/)))|(^[^\.]+$)/; var j = 0; while (j < links.length) { if ( !(res = regex.test(links[j])) ){ var pdf = links[j].getAttribute("pdf"); links[j].href = pdf; if(links[j].getAttribute("oldtarget")!=null){ links[j].setAttribute("target",links[j].getAttribute("oldtarget")); links[j].removeAttribute("oldtarget"); } }else{} j++; } }, getPdfLink : function(pdf){ return p + this.host + "pdfviewer.php?f=" + pdf; }, enable : function(){ this.replacePdfLinks(); this.enabled.value = true; this.domutility.createCookie(this.enabled.cookie, 'true'); }, disable : function(){ this.reinstatePdfLinks(); this.enabled.value = false; this.domutility.createCookie(this.enabled.cookie, 'false'); }, setUserPreferences : function(){ this.domutility.setStateFromCookie(this, 'enabled', 'enable'); }, init : function(){ this.domutility = new DomUtil(); this.setUserPreferences(); } } Frames = { ttsob : null, domutil : null, eventsutil : null, framesarray : [], htmlElements : [], count : 0, getFrames : function(){ for(var i=0;i0 ){ var myIframeWin = myDom[i].contentWindow || myDom[i].contentDocument //console.log("ADD NESTED FRAME: "+ this.count + " " + (myIframeWin.location) + " " + id); this.count++; this.traverseFrame(myIframeWin); } for(var j = 0;j < this.htmlElements.length;j++){ //console.log("CHECK: "+this.domutil.DOM[i].tagName.toLowerCase() + " " + this.htmlElements[j].toLowerCase() + " " + (this.domutil.DOM[i].tagName.toLowerCase() == this.htmlElements[j].toLowerCase()) ) if(myDom[i].tagName.toLowerCase() == this.htmlElements[j].toLowerCase() ){ //if(this.domutil.DOM[i].tagName.toLowerCase() == 'script') //console.log("ADD: "+myDom[i].tagName.toLowerCase() + " " + myDom[i].innerHTML ) this.eventsutil.addEvent(myDom[i], 'mouseover', this.domutil.bind(this, this.mouseOver) ); this.eventsutil.addEvent(myDom[i], 'mouseout', this.domutil.bind(this, this.mouseOut) ); } //this.domutil.addCSS(this.ttsob.apppath+"/css/main.css", frame.document); } } }, mouseOver : function(e){ try{ //console.log(e); }catch(e){} parent[this.ttsob.obname].highlight(e); parent[this.ttsob.obname].read(e); }, mouseOut : function(e){ parent[this.ttsob.obname].unHighlight(e); parent[this.ttsob.obname].stopReading(e); }, initHtmlElements : function(){ this.htmlElements.push("p"); this.htmlElements.push("a"); this.htmlElements.push("div"); this.htmlElements.push("ul"); this.htmlElements.push("ol"); this.htmlElements.push("li"); this.htmlElements.push("span"); this.htmlElements.push("h1"); this.htmlElements.push("h2"); this.htmlElements.push("h3"); this.htmlElements.push("h4"); this.htmlElements.push("th"); this.htmlElements.push("tr"); this.htmlElements.push("td"); this.htmlElements.push("img"); this.htmlElements.push("select"); this.htmlElements.push("option"); this.htmlElements.push("label"); this.htmlElements.push("input"); }, init : function(ttsob){ this.ttsob = ttsob; this.domutil = new DomUtil(); this.eventsutil = new Events(); this.initHtmlElements() //this.traverseFrames(); var that = this; setTimeout(function(){that.traverseFrames()}, 6000); } } function initTTS(){ ROKTalkTTS = new TTSapp('ROKTalkTTS'); ROKTalkTTS.innit(); ROKTalkVis = new Visualapp(); ROKTalkVis.innit('ROKTalkVis'); ROKTalkUI = new UI(ROKTalkTTS, ROKTalkVis); ROKTalkUI.innit(); Pdfreader.init(); Frames.init(ROKTalkTTS); } eventsutil = new Events(); eventsutil.addEvent(window, 'load', initTTS())