Assistant = function (startUrl) { this.startUrl = startUrl; this.frame = document.getElementById("frame"); this.screen = document.getElementById("screen"); this.mouseenter = jQuery.proxy(this.mouseenter, this); this.mouseleave = jQuery.proxy(this.mouseleave, this); this.mousemove = jQuery.proxy(this.mousemove, this); this.click = jQuery.proxy(this.click, this); this.dblclick = jQuery.proxy(this.dblclick, this); this.init = jQuery.proxy(this.init, this); this.frameFocusChanged = jQuery.proxy(this.frameFocusChanged, this); this.enable = jQuery.proxy(this.enable, this); this.disable = jQuery.proxy(this.disable, this); this.adjust = jQuery.proxy(this.adjust, this); this.historyChanged = jQuery.proxy(this.historyChanged, this); this.focusChanged = jQuery.proxy(this.focusChanged, this); this.screenFocus = jQuery.proxy(this.screenFocus, this); this.readerFocus = jQuery.proxy(this.readerFocus, this); this.split = jQuery.proxy(this.split, this); this.isSeparator = jQuery.proxy(this.isSeparator, this); this.initReader = jQuery.proxy(this.initReader, this); this.frameLoad = jQuery.proxy(this.frameLoad, this); this.toolFocus = jQuery.proxy(this.toolFocus, this); this.cmd_reset = jQuery.proxy(this.cmd_reset, this); this.cmd_back = jQuery.proxy(this.cmd_back, this); this.cmd_forward = jQuery.proxy(this.cmd_forward, this); this.cmd_refresh = jQuery.proxy(this.cmd_refresh, this); this.cmd_screen = jQuery.proxy(this.cmd_screen, this); this.cmd_zoomout = jQuery.proxy(this.cmd_zoomout, this); this.cmd_zoomin = jQuery.proxy(this.cmd_zoomin, this); this.cmd_fontplus = jQuery.proxy(this.cmd_fontplus, this); this.cmd_fontminus = jQuery.proxy(this.cmd_fontminus, this); this.cmd_cross = jQuery.proxy(this.cmd_cross, this); this.cmd_colors = jQuery.proxy(this.cmd_colors, this); this.cmd_text = jQuery.proxy(this.cmd_text, this); this.cmd_read = jQuery.proxy(this.cmd_read, this); this.cmd_readon = jQuery.proxy(this.cmd_readon, this); this.cmd_volumeplus = jQuery.proxy(this.cmd_volumeplus, this); this.cmd_volumeminus = jQuery.proxy(this.cmd_volumeminus, this); this.vAScreen = new VAScreen(this.screen, false, this.frame.contentWindow); this.vAZoom = new VAZoom(this.frame.contentWindow); this.vAFont = [new VAFont(this.frame.contentWindow, "auto")]; this.vACross = new VACross(this.frame.contentWindow, false); this.vAColor = [new VAColor(this.frame.contentWindow)]; this.vAText = new VAText(this.frame.contentWindow); this.vAHistory = new VAHistory(this.frame.contentWindow, this.historyChanged); this.vAFocus = [new VAFocus(this.frame.contentWindow, this.focusChanged)]; this.vAScroll = new VAScroll(this.frame.contentWindow); this.vATarget = new VATarget(this.frame.contentWindow); this.mask = new Mask(this.frame.contentWindow, "loading"); this.init(); } Assistant.prototype = { init: function () { jQuery("#ribbon .bigtool, #ribbon .listitem") .bind("mouseenter", this.mouseenter) .bind("mouseleave", this.mouseleave) .bind("click", this.click) .bind("dblclick", this.dblclick); jQuery.cookie("ess.ss", '1', { path: '/' }); jQuery.cookie("EasySite.SpeechAssistant", null, { path: '/' }); jQuery(window).resize(this.adjust); jQuery(document.body).click(function (e) { jQuery(".dropdownlist").parent(".bigtool[cmd=colors]").removeClass("selected"); jQuery(".dropdownlist").hide(); }); jQuery("#ribbon").mousedown(function (e) { e.preventDefault(); }); jQuery(this.frame).bind("load", this.frameLoad); var reader=this.reader = new EasyReader({ speed: "slow", playerPath: Host.playerPath }); this.initReader(); this.adjust(); this.mask.show(); this.frame.src = this.startUrl; var me=this; $(document).keydown(this.shortcuts); setTimeout(function(){ me.readerFocus('欢迎使用无障碍系统,按住shift+1打开显示屏,再次按下关闭显示屏,按住shift+2打开指读功能,再次按下关闭',me.vAFocus[0],true); },1000); }, initReader: function () { this.disable(jQuery(".bigtool[cmd=read]")[0]); this.disable(jQuery(".bigtool[cmd=readon]")[0]); this.disable(jQuery(".bigtool[cmd=volumeplus]")[0]); this.disable(jQuery(".bigtool[cmd=volumeminus]")[0]); this.canRead = false; this.canReadon = false; if (this.reader.isEnable()) { this.enable(jQuery(".bigtool[cmd=read]")[0]); this.reader.volume(1); if (this.reader.canVolumePlus()) { this.enable(jQuery(".bigtool[cmd=volumeplus]")[0]); } if (this.reader.canVolumeMinus()) { this.enable(jQuery(".bigtool[cmd=volumeminus]")[0]); } } }, frameLoad: function (e) { document.title = this.frame.contentWindow.document.title; this.reader._reader._args.mp3Path = Host.getCurrent(this.frame.contentWindow).mp3Path; this.vAFont.length=1; this.vAColor.length=1; this.vAFocus.length=1; this.vAHistory.active(); this.vACross.active(); this.vAZoom.active(); this.vAFont[0].active(); this.vAColor[0].active(); this.vAText.active(); this.vAFocus[0].active(); this.vAScroll.active(); this.vATarget.active(); this.mask.active(); var win=this.frame.contentWindow; $(win.document).keydown(this.shortcuts); var winframes=win.frames; for(var i=0,l=winframes.length;i 0) { if (this.canRead) { this.readerFocus(text,Focus); } else { if (this.vAScreen.isShow) { this.screenFocus(text,Focus); } } } else { if (this.canReadon) { Focus.focusNext(); } } }, shortcuts: function(e){ var cmd=""; e.preventDefault(); if(e.shiftKey){ switch(e.keyCode){ case 49: cmd="screen"; break; case 50: cmd="read"; break; } $("#ribbon .bigtool[cmd='"+cmd+"']",window.top.document).trigger("click"); } }, toolFocus: function (tool) { var title = jQuery("span:nth(0)", tool).text(); var cmd = jQuery(tool).attr("cmd"); switch (cmd) { case "screen": if (this.vAScreen.isShow) { title += "【开】"; } else { title += "【关】"; } break; case "text": if (this.vAText.isText) { title += "【开】"; } else { title += "【关】"; } break; case "cross": if (this.vACross.isShow) { title += "【开】"; } else { title += "【关】"; } break; case "read": if (this.canRead) { title += "【开】"; } else { title += "【关】"; } break; case "readon": if (this.canReadon) { title += "【开】"; } else { title += "【关】"; } break; case "fontminus": case "fontplus": var l=this.vAFont.length, tag=true; for(var i=0;i 0) { if (this.canRead) { this.readerFocus(text,this.vAFocus[0]); } else { if (this.vAScreen.isShow) { this.screenFocus(text); } } } else { if (this.canReadon) { this.vAFocus[0].focusNext(); } } }, screenFocus: function (text,vAFocus) { var strs = this.split(text, 30); var i = 0; clearTimeout(this.vAScreen.timer); var action = jQuery.proxy(function () { clearTimeout(this.vAScreen.timer); if (i < strs.length) { this.vAScreen.showText(strs[i]); this.vAScreen.timer = setTimeout(action, strs[i].length * 200); } i++; if (i == strs.length + 1) { if (this.canReadon) { vAFocus.focusNext(); } return; } }, this); action(); }, readerFocus: function (text,vAFocus) { var strs = this.split(text, 30), arg=!!arguments[2]; strs.i = 0; var action = jQuery.proxy(function () { if (strs.i < strs.length) { this.reader.stop(); if (this.vAScreen.isShow) { this.vAScreen.showText(strs[strs.i]); } if (this.reader.readable(strs[strs.i])) { this.reader.finish = action; this.reader.read(strs[strs.i]); } else { strs.i++; action(); } } strs.i++; if ((strs.i == strs.length + 1)&&!arg) { if (this.canReadon) { vAFocus.focusNext(); } return; } }, this); action(); }, split: function (str, max) { var length = str.length; if (length < max) { return [str]; } else { var result = []; var i = 0; var start = 0; var last = 0; while (i < length) { if (i - start == max - 1) { if (last == 0) { result.push(str.substring(start, start + max)); i = start + max; start = i; continue; } else { result.push(str.substring(start, last + 1)); i = last + 1; start = i; last = 0; continue; } } if (this.isSeparator(str[i])) { if (i > start) { last = i; } else { start = i + 1; } } i++; } if (start < length) { result.push(str.substring(start)) } } return result; }, isSeparator: function (c) { switch (c) { case ',': case '。': case '!': case '?': case ';': case '“': case '”': case ':': case '、': case ',': case '.': case '!': case '?': case ';': case '"': case ':': case '\n': case '-': case ' ': return true; default: return false; } } };