Assistants.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. Assistant = function (startUrl) {
  2. this.startUrl = startUrl;
  3. this.frame = document.getElementById("frame");
  4. this.screen = document.getElementById("screen");
  5. this.mouseenter = jQuery.proxy(this.mouseenter, this);
  6. this.mouseleave = jQuery.proxy(this.mouseleave, this);
  7. this.mousemove = jQuery.proxy(this.mousemove, this);
  8. this.click = jQuery.proxy(this.click, this);
  9. this.dblclick = jQuery.proxy(this.dblclick, this);
  10. this.init = jQuery.proxy(this.init, this);
  11. this.frameFocusChanged = jQuery.proxy(this.frameFocusChanged, this);
  12. this.enable = jQuery.proxy(this.enable, this);
  13. this.disable = jQuery.proxy(this.disable, this);
  14. this.adjust = jQuery.proxy(this.adjust, this);
  15. this.historyChanged = jQuery.proxy(this.historyChanged, this);
  16. this.focusChanged = jQuery.proxy(this.focusChanged, this);
  17. this.screenFocus = jQuery.proxy(this.screenFocus, this);
  18. this.readerFocus = jQuery.proxy(this.readerFocus, this);
  19. this.split = jQuery.proxy(this.split, this);
  20. this.isSeparator = jQuery.proxy(this.isSeparator, this);
  21. this.initReader = jQuery.proxy(this.initReader, this);
  22. this.frameLoad = jQuery.proxy(this.frameLoad, this);
  23. this.toolFocus = jQuery.proxy(this.toolFocus, this);
  24. this.cmd_reset = jQuery.proxy(this.cmd_reset, this);
  25. this.cmd_back = jQuery.proxy(this.cmd_back, this);
  26. this.cmd_forward = jQuery.proxy(this.cmd_forward, this);
  27. this.cmd_refresh = jQuery.proxy(this.cmd_refresh, this);
  28. this.cmd_screen = jQuery.proxy(this.cmd_screen, this);
  29. this.cmd_zoomout = jQuery.proxy(this.cmd_zoomout, this);
  30. this.cmd_zoomin = jQuery.proxy(this.cmd_zoomin, this);
  31. this.cmd_fontplus = jQuery.proxy(this.cmd_fontplus, this);
  32. this.cmd_fontminus = jQuery.proxy(this.cmd_fontminus, this);
  33. this.cmd_cross = jQuery.proxy(this.cmd_cross, this);
  34. this.cmd_colors = jQuery.proxy(this.cmd_colors, this);
  35. this.cmd_text = jQuery.proxy(this.cmd_text, this);
  36. this.cmd_read = jQuery.proxy(this.cmd_read, this);
  37. this.cmd_readon = jQuery.proxy(this.cmd_readon, this);
  38. this.cmd_volumeplus = jQuery.proxy(this.cmd_volumeplus, this);
  39. this.cmd_volumeminus = jQuery.proxy(this.cmd_volumeminus, this);
  40. this.vAScreen = new VAScreen(this.screen, false, this.frame.contentWindow);
  41. this.vAZoom = new VAZoom(this.frame.contentWindow);
  42. this.vAFont = [new VAFont(this.frame.contentWindow, "auto")];
  43. this.vACross = new VACross(this.frame.contentWindow, false);
  44. this.vAColor = [new VAColor(this.frame.contentWindow)];
  45. this.vAText = new VAText(this.frame.contentWindow);
  46. this.vAHistory = new VAHistory(this.frame.contentWindow, this.historyChanged);
  47. this.vAFocus = [new VAFocus(this.frame.contentWindow, this.focusChanged)];
  48. this.vAScroll = new VAScroll(this.frame.contentWindow);
  49. this.vATarget = new VATarget(this.frame.contentWindow);
  50. this.mask = new Mask(this.frame.contentWindow, "loading");
  51. this.init();
  52. }
  53. Assistant.prototype = {
  54. init: function () {
  55. jQuery("#ribbon .bigtool, #ribbon .listitem")
  56. .bind("mouseenter", this.mouseenter)
  57. .bind("mouseleave", this.mouseleave)
  58. .bind("click", this.click)
  59. .bind("dblclick", this.dblclick);
  60. jQuery.cookie("ess.ss", '1', { path: '/' });
  61. jQuery.cookie("EasySite.SpeechAssistant", null, { path: '/' });
  62. jQuery(window).resize(this.adjust);
  63. jQuery(document.body).click(function (e) {
  64. jQuery(".dropdownlist").parent(".bigtool[cmd=colors]").removeClass("selected");
  65. jQuery(".dropdownlist").hide();
  66. });
  67. jQuery("#ribbon").mousedown(function (e) { e.preventDefault(); });
  68. jQuery(this.frame).bind("load", this.frameLoad);
  69. var reader=this.reader = new EasyReader({ speed: "slow", playerPath: Host.playerPath });
  70. this.initReader();
  71. this.adjust();
  72. this.mask.show();
  73. this.frame.src = this.startUrl;
  74. var me=this;
  75. $(document).keydown(this.shortcuts);
  76. setTimeout(function(){
  77. me.readerFocus('欢迎使用无障碍系统,按住shift+1打开显示屏,再次按下关闭显示屏,按住shift+2打开指读功能,再次按下关闭',me.vAFocus[0],true);
  78. },1000);
  79. },
  80. initReader: function () {
  81. this.disable(jQuery(".bigtool[cmd=read]")[0]);
  82. this.disable(jQuery(".bigtool[cmd=readon]")[0]);
  83. this.disable(jQuery(".bigtool[cmd=volumeplus]")[0]);
  84. this.disable(jQuery(".bigtool[cmd=volumeminus]")[0]);
  85. this.canRead = false;
  86. this.canReadon = false;
  87. if (this.reader.isEnable()) {
  88. this.enable(jQuery(".bigtool[cmd=read]")[0]);
  89. this.reader.volume(1);
  90. if (this.reader.canVolumePlus()) {
  91. this.enable(jQuery(".bigtool[cmd=volumeplus]")[0]);
  92. }
  93. if (this.reader.canVolumeMinus()) {
  94. this.enable(jQuery(".bigtool[cmd=volumeminus]")[0]);
  95. }
  96. }
  97. },
  98. frameLoad: function (e) {
  99. document.title = this.frame.contentWindow.document.title;
  100. this.reader._reader._args.mp3Path = Host.getCurrent(this.frame.contentWindow).mp3Path;
  101. this.vAFont.length=1;
  102. this.vAColor.length=1;
  103. this.vAFocus.length=1;
  104. this.vAHistory.active();
  105. this.vACross.active();
  106. this.vAZoom.active();
  107. this.vAFont[0].active();
  108. this.vAColor[0].active();
  109. this.vAText.active();
  110. this.vAFocus[0].active();
  111. this.vAScroll.active();
  112. this.vATarget.active();
  113. this.mask.active();
  114. var win=this.frame.contentWindow;
  115. $(win.document).keydown(this.shortcuts);
  116. var winframes=win.frames;
  117. for(var i=0,l=winframes.length;i<l;i++){
  118. try{
  119. $(winframes[i].document).keydown(this.shortcuts);
  120. var focus = new VAFocus(winframes[i].window, this.frameFocusChanged),
  121. font = new VAFont(winframes[i].window, "auto"),
  122. color = new VAColor(winframes[i].window);
  123. this.vAFont.push(font);
  124. this.vAColor.push(color);
  125. this.vAFocus.push(focus);
  126. focus.active();
  127. font.active();
  128. color.active();
  129. }catch(e){}
  130. }
  131. },
  132. frameFocusChanged:function(Focus){
  133. var text = Focus.getText();
  134. if (text.length > 0) {
  135. if (this.canRead) {
  136. this.readerFocus(text,Focus);
  137. }
  138. else {
  139. if (this.vAScreen.isShow) {
  140. this.screenFocus(text,Focus);
  141. }
  142. }
  143. }
  144. else {
  145. if (this.canReadon) {
  146. Focus.focusNext();
  147. }
  148. }
  149. },
  150. shortcuts: function(e){
  151. var cmd="";
  152. e.preventDefault();
  153. if(e.shiftKey){
  154. switch(e.keyCode){
  155. case 49:
  156. cmd="screen";
  157. break;
  158. case 50:
  159. cmd="read";
  160. break;
  161. }
  162. $("#ribbon .bigtool[cmd='"+cmd+"']",window.top.document).trigger("click");
  163. }
  164. },
  165. toolFocus: function (tool) {
  166. var title = jQuery("span:nth(0)", tool).text();
  167. var cmd = jQuery(tool).attr("cmd");
  168. switch (cmd) {
  169. case "screen":
  170. if (this.vAScreen.isShow) {
  171. title += "【开】";
  172. }
  173. else {
  174. title += "【关】";
  175. }
  176. break;
  177. case "text":
  178. if (this.vAText.isText) {
  179. title += "【开】";
  180. }
  181. else {
  182. title += "【关】";
  183. }
  184. break;
  185. case "cross":
  186. if (this.vACross.isShow) {
  187. title += "【开】";
  188. }
  189. else {
  190. title += "【关】";
  191. }
  192. break;
  193. case "read":
  194. if (this.canRead) {
  195. title += "【开】";
  196. }
  197. else {
  198. title += "【关】";
  199. }
  200. break;
  201. case "readon":
  202. if (this.canReadon) {
  203. title += "【开】";
  204. }
  205. else {
  206. title += "【关】";
  207. }
  208. break;
  209. case "fontminus":
  210. case "fontplus":
  211. var l=this.vAFont.length,
  212. tag=true;
  213. for(var i=0;i<l;i++){
  214. tag=(this.vAFont[i].size() != "auto")&&tag
  215. }
  216. if (tag) {
  217. title += "【" + this.vAFont[0].size() + "】";
  218. }
  219. else {
  220. title += "【正常】";
  221. }
  222. break;
  223. case "zoomin":
  224. case "zoomout":
  225. title += "【" + parseInt(this.vAZoom.ratio() * 100) + "%】";
  226. break;
  227. case "volumeplus":
  228. case "volumeminus":
  229. title += "【" + parseInt(this.reader.volume().toFixed(1) * 100) + "%】";
  230. break;
  231. }
  232. this.focusChanged(title);
  233. },
  234. mouseenter: function (e) {
  235. jQuery(e.currentTarget).addClass("active");
  236. this.toolFocus(e.currentTarget);
  237. },
  238. mouseleave: function (e) {
  239. jQuery(e.currentTarget).removeClass("active");
  240. this.vAScreen.showText("");
  241. },
  242. click: function (e) {
  243. var cmd = jQuery(e.currentTarget).attr("cmd");
  244. switch (cmd) {
  245. case "reset":
  246. this.cmd_reset(e);
  247. break;
  248. case "back":
  249. this.cmd_back(e);
  250. break;
  251. case "forward":
  252. this.cmd_forward(e);
  253. break;
  254. case "refresh":
  255. this.cmd_refresh(e);
  256. break;
  257. case "screen":
  258. this.cmd_screen(e);
  259. break;
  260. case "zoomout":
  261. this.cmd_zoomout(e);
  262. break;
  263. case "zoomin":
  264. this.cmd_zoomin(e);
  265. break;
  266. case "fontplus":
  267. this.cmd_fontplus(e);
  268. break;
  269. case "fontminus":
  270. this.cmd_fontminus(e);
  271. break;
  272. case "cross":
  273. this.cmd_cross(e);
  274. break;
  275. case "colors":
  276. case "white-black-blue":
  277. case "blue-yellow-white":
  278. case "yellow-black-blue":
  279. case "black-yellow-white":
  280. case "normal-colors":
  281. this.cmd_colors(e, cmd);
  282. break;
  283. case "text":
  284. this.cmd_text(e);
  285. break;
  286. case "read":
  287. this.cmd_read(e);
  288. break;
  289. case "readon":
  290. this.cmd_readon(e);
  291. break;
  292. case "read":
  293. this.cmd_read(e);
  294. break;
  295. case "volumeplus":
  296. this.cmd_volumeplus(e);
  297. break;
  298. case "volumeminus":
  299. this.cmd_volumeminus(e);
  300. break;
  301. }
  302. this.toolFocus(e.currentTarget);
  303. },
  304. dblclick: function (e) {
  305. var cmd = jQuery(e.currentTarget).attr("cmd");
  306. switch (cmd) {
  307. case "zoomout":
  308. case "zoomin":
  309. this.vAZoom.ratio(1);
  310. break;
  311. case "fontplus":
  312. case "fontminus":
  313. var l=this.vAFont.length;
  314. for(var i=0;i<l;i++){
  315. this.vAFont[i].size("auto");
  316. }
  317. break;
  318. }
  319. this.toolFocus(e.currentTarget);
  320. },
  321. cmd_reset: function () {
  322. jQuery("#ribbon .bigtool, #ribbon .listitem").removeClass("selected");
  323. this.vAZoom.zoom = 1;
  324. //this.vAFont.fontSize = "";
  325. this.vAText.isText = false;
  326. //this.vAColor.color = "";
  327. jQuery(this.screen).css({ "background-color": "", "color": "" });
  328. this.vAScreen.hide();
  329. this.vACross.hide();
  330. //this.vAFocus.reset();
  331. this.adjust();
  332. this.initReader();
  333. this.frame.contentWindow.location.reload();
  334. var l=this.vAFont.length;
  335. for(var i=0;i<l;i++){
  336. this.vAFont[i].fontSize = "";
  337. this.vAColor[i].color = "";
  338. this.vAFocus[i].reset();
  339. }
  340. },
  341. cmd_back: function (e) {
  342. this.vAHistory.back();
  343. },
  344. cmd_forward: function (e) {
  345. this.vAHistory.forward();
  346. },
  347. cmd_refresh: function () {
  348. this.vAHistory.isRefresh = true;
  349. this.frame.contentWindow.location.reload();
  350. },
  351. cmd_screen: function (e) {
  352. var tool = jQuery(e.currentTarget);
  353. if (tool.hasClass("selected")) {
  354. tool.removeClass("selected").removeClass("active");
  355. this.vAScreen.hide();
  356. }
  357. else {
  358. tool.addClass("selected");
  359. this.vAScreen.show();
  360. }
  361. this.adjust();
  362. },
  363. cmd_zoomout: function (e) {
  364. if (this.vAZoom.zoomOut()) {
  365. this.enable(jQuery(".bigtool[cmd=zoomin]")[0]);
  366. }
  367. else {
  368. this.disable(e.currentTarget);
  369. }
  370. },
  371. cmd_zoomin: function (e) {
  372. if (this.vAZoom.zoomIn()) {
  373. this.enable(jQuery(".bigtool[cmd=zoomout]")[0]);
  374. }
  375. else {
  376. this.disable(e.currentTarget);
  377. }
  378. },
  379. cmd_fontplus: function (e) {
  380. var l=this.vAFont.length,
  381. tag=true;
  382. for(var i=0;i<l;i++){
  383. tag=this.vAFont[i].fontPlus()&&tag
  384. }
  385. if (tag) {
  386. this.enable(jQuery(".bigtool[cmd=fontminus]")[0]);
  387. }
  388. else {
  389. this.disable(e.currentTarget);
  390. }
  391. },
  392. cmd_fontminus: function (e) {
  393. var l=this.vAFont.length,
  394. tag=true;
  395. for(var i=0;i<l;i++){
  396. tag=this.vAFont[i].fontMinus()&&tag
  397. }
  398. if (tag) {
  399. this.enable(jQuery(".bigtool[cmd=fontplus]")[0]);
  400. }
  401. else {
  402. this.disable(e.currentTarget);
  403. }
  404. },
  405. cmd_cross: function (e) {
  406. var tool = jQuery(e.currentTarget);
  407. if (tool.hasClass("selected")) {
  408. tool.removeClass("selected").removeClass("active");
  409. this.vACross.hide();
  410. }
  411. else {
  412. tool.addClass("selected");
  413. this.vACross.show();
  414. }
  415. },
  416. cmd_colors: function (e, cmd) {
  417. e.stopPropagation();
  418. var tool = jQuery(e.currentTarget);
  419. if (cmd == "colors") {
  420. var list = jQuery(".dropdownlist", e.currentTarget);
  421. if (tool.hasClass("selected")) {
  422. list.hide();
  423. tool.removeClass("selected").removeClass("active");
  424. }
  425. else {
  426. list.css({ top: "80px", left: "566px" }).show();
  427. tool.addClass("selected");
  428. }
  429. }
  430. else {
  431. jQuery(tool[0].parentNode).hide();
  432. jQuery(tool[0].parentNode.parentNode).removeClass("selected").removeClass("active");
  433. jQuery(".listitem", tool[0].parentNode).removeClass("selected");
  434. switch (cmd) {
  435. case "white-black-blue":
  436. jQuery(this.screen).css({ "background-color": "White", "color": "Black" });
  437. var l=this.vAColor.length;
  438. for(var i=0;i<l;i++){
  439. this.vAColor[i].paint("Black", "Blue", "White");
  440. this.vAFocus[i].paint("Black", "Blue", "White");
  441. }
  442. //this.vAFocus.paint("Black", "Blue", "White");
  443. break;
  444. case "blue-yellow-white":
  445. jQuery(this.screen).css({ "background-color": "Blue", "color": "Yellow" });
  446. var l=this.vAColor.length;
  447. for(var i=0;i<l;i++){
  448. this.vAColor[i].paint("Yellow", "White", "Blue");
  449. this.vAFocus[i].paint("Yellow", "White", "Blue");
  450. }
  451. //this.vAColor.paint("Yellow", "White", "Blue");
  452. //this.vAFocus.paint("Yellow", "White", "Blue");
  453. break;
  454. case "yellow-black-blue":
  455. jQuery(this.screen).css({ "background-color": "Yellow", "color": "Black" });
  456. var l=this.vAColor.length;
  457. for(var i=0;i<l;i++){
  458. this.vAColor[i].paint("Black", "Blue", "Yellow");
  459. this.vAFocus[i].paint("Black", "Blue", "Yellow");
  460. //console.log(this.vAFocus[i].color+this.vAFocus[i].linkColor+this.vAFocus[i].bgColor);
  461. }
  462. //this.vAColor.paint("Black", "Blue", "Yellow");
  463. //this.vAFocus.paint("Black", "Blue", "Yellow");
  464. break;
  465. case "black-yellow-white":
  466. jQuery(this.screen).css({ "background-color": "Black", "color": "Yellow" });
  467. var l=this.vAColor.length;
  468. for(var i=0;i<l;i++){
  469. this.vAColor[i].paint("Yellow", "White", "Black");
  470. this.vAFocus[i].paint("Yellow", "White", "Black");
  471. }
  472. //this.vAColor.paint("Yellow", "White", "Black");
  473. //this.vAFocus.paint("Yellow", "White", "Black");
  474. break;
  475. default:
  476. jQuery(this.screen).css({ "background-color": "", "color": "" });
  477. var l=this.vAColor.length;
  478. for(var i=0;i<l;i++){
  479. this.vAColor[i].reset();
  480. this.vAFocus[i].reset();
  481. }
  482. //this.vAColor.reset();
  483. //this.vAFocus.reset();
  484. return;
  485. }
  486. tool.addClass("selected");
  487. }
  488. },
  489. cmd_text: function (e) {
  490. var tool = jQuery(e.currentTarget);
  491. if (tool.hasClass("selected")) {
  492. tool.removeClass("selected").removeClass("active");
  493. this.vAText.reset();
  494. }
  495. else {
  496. tool.addClass("selected");
  497. this.vAText.text();
  498. }
  499. },
  500. cmd_read: function (e) {
  501. var tool = jQuery(e.currentTarget);
  502. if (tool.hasClass("selected")) {
  503. tool.removeClass("selected").removeClass("active");
  504. this.canRead = false;
  505. if (this.canReadon) {
  506. this.canReadon = false;
  507. jQuery(".bigtool[cmd=readon]").removeClass("selected").removeClass("active");
  508. }
  509. this.disable(jQuery(".bigtool[cmd=readon]")[0]);
  510. }
  511. else {
  512. tool.addClass("selected");
  513. this.canRead = true;
  514. this.enable(jQuery(".bigtool[cmd=readon]")[0]);
  515. }
  516. },
  517. cmd_readon: function (e) {
  518. if (this.canRead) {
  519. var tool = jQuery(e.currentTarget);
  520. if (tool.hasClass("selected")) {
  521. tool.removeClass("selected").removeClass("active");
  522. this.canReadon = false;
  523. var l=this.vAColor.length;
  524. for(var i=0;i<l;i++){
  525. this.vAFocus[i].clearFocusNext();
  526. }
  527. }
  528. else {
  529. tool.addClass("selected");
  530. this.canReadon = true;
  531. }
  532. }
  533. },
  534. cmd_volumeplus: function (e) {
  535. this.reader.volumePlus();
  536. if (this.reader.canVolumePlus()) {
  537. this.enable(jQuery(".bigtool[cmd=volumeminus]")[0]);
  538. }
  539. else {
  540. this.disable(e.currentTarget);
  541. }
  542. },
  543. cmd_volumeminus: function (e) {
  544. this.reader.volumeMinus();
  545. if (this.reader.canVolumeMinus()) {
  546. this.enable(jQuery(".bigtool[cmd=volumeplus]")[0]);
  547. }
  548. else {
  549. this.disable(e.currentTarget);
  550. }
  551. },
  552. disable: function (tool) {
  553. tool = jQuery(tool);
  554. if (!tool.hasClass("disabled")) {
  555. var cmd = tool.attr("cmd");
  556. tool
  557. .unbind("mouseenter", this.mouseenter)
  558. .unbind("mouseleave", this.mouseleave)
  559. .unbind("click", this.click)
  560. .unbind("dblclick", this.dblclick)
  561. .removeClass("selected")
  562. .removeClass("active")
  563. .addClass("disabled")
  564. .find("img")
  565. .each(function (i) {
  566. jQuery(this).attr("src", jQuery(this).attr("src").replace(cmd + ".", cmd + "_disabled."));
  567. });
  568. }
  569. },
  570. enable: function (tool) {
  571. tool = jQuery(tool);
  572. if (tool.hasClass("disabled")) {
  573. var cmd = tool.attr("cmd");
  574. tool
  575. .bind("mouseenter", this.mouseenter)
  576. .bind("mouseleave", this.mouseleave)
  577. .bind("click", this.click)
  578. .bind("dblclick", this.dblclick)
  579. .removeClass("disabled")
  580. .find("img").each(function (i) {
  581. jQuery(this).attr("src", jQuery(this).attr("src").replace(cmd + "_disabled.", cmd + "."));
  582. });
  583. }
  584. },
  585. adjust: function () {
  586. var h;
  587. if (window.innerHeight) {
  588. h = window.innerHeight;
  589. }
  590. else if (document.documentElement.clientHeight) {
  591. h = document.documentElement.clientHeight;
  592. }
  593. else {
  594. h = document.body.clientHeight;
  595. }
  596. if (jQuery(".bigtool[cmd=screen]").hasClass("selected")) {
  597. jQuery(this.frame).css("height", h - 102 - 80);
  598. }
  599. else {
  600. jQuery(this.frame).css("height", h - 102);
  601. }
  602. },
  603. historyChanged: function () {
  604. if (this.vAHistory.canBack()) {
  605. this.enable(jQuery(".bigtool[cmd=back]")[0]);
  606. }
  607. else {
  608. this.disable(jQuery(".bigtool[cmd=back]")[0]);
  609. }
  610. if (this.vAHistory.canForward()) {
  611. this.enable(jQuery(".bigtool[cmd=forward]")[0]);
  612. }
  613. else {
  614. this.disable(jQuery(".bigtool[cmd=forward]")[0]);
  615. }
  616. },
  617. focusChanged: function (text) {
  618. if (typeof text!='string') {
  619. text = this.vAFocus[0].getText();
  620. }
  621. if (text.length > 0) {
  622. if (this.canRead) {
  623. this.readerFocus(text,this.vAFocus[0]);
  624. }
  625. else {
  626. if (this.vAScreen.isShow) {
  627. this.screenFocus(text);
  628. }
  629. }
  630. }
  631. else {
  632. if (this.canReadon) {
  633. this.vAFocus[0].focusNext();
  634. }
  635. }
  636. },
  637. screenFocus: function (text,vAFocus) {
  638. var strs = this.split(text, 30);
  639. var i = 0;
  640. clearTimeout(this.vAScreen.timer);
  641. var action = jQuery.proxy(function () {
  642. clearTimeout(this.vAScreen.timer);
  643. if (i < strs.length) {
  644. this.vAScreen.showText(strs[i]);
  645. this.vAScreen.timer = setTimeout(action, strs[i].length * 200);
  646. }
  647. i++;
  648. if (i == strs.length + 1) {
  649. if (this.canReadon) {
  650. vAFocus.focusNext();
  651. }
  652. return;
  653. }
  654. }, this);
  655. action();
  656. },
  657. readerFocus: function (text,vAFocus) {
  658. var strs = this.split(text, 30),
  659. arg=!!arguments[2];
  660. strs.i = 0;
  661. var action = jQuery.proxy(function () {
  662. if (strs.i < strs.length) {
  663. this.reader.stop();
  664. if (this.vAScreen.isShow) {
  665. this.vAScreen.showText(strs[strs.i]);
  666. }
  667. if (this.reader.readable(strs[strs.i])) {
  668. this.reader.finish = action;
  669. this.reader.read(strs[strs.i]);
  670. }
  671. else {
  672. strs.i++;
  673. action();
  674. }
  675. }
  676. strs.i++;
  677. if ((strs.i == strs.length + 1)&&!arg) {
  678. if (this.canReadon) {
  679. vAFocus.focusNext();
  680. }
  681. return;
  682. }
  683. }, this);
  684. action();
  685. },
  686. split: function (str, max) {
  687. var length = str.length;
  688. if (length < max) {
  689. return [str];
  690. }
  691. else {
  692. var result = [];
  693. var i = 0;
  694. var start = 0;
  695. var last = 0;
  696. while (i < length) {
  697. if (i - start == max - 1) {
  698. if (last == 0) {
  699. result.push(str.substring(start, start + max));
  700. i = start + max;
  701. start = i;
  702. continue;
  703. }
  704. else {
  705. result.push(str.substring(start, last + 1));
  706. i = last + 1;
  707. start = i;
  708. last = 0;
  709. continue;
  710. }
  711. }
  712. if (this.isSeparator(str[i])) {
  713. if (i > start) {
  714. last = i;
  715. }
  716. else {
  717. start = i + 1;
  718. }
  719. }
  720. i++;
  721. }
  722. if (start < length) {
  723. result.push(str.substring(start))
  724. }
  725. }
  726. return result;
  727. },
  728. isSeparator: function (c) {
  729. switch (c) {
  730. case ',':
  731. case '。':
  732. case '!':
  733. case '?':
  734. case ';':
  735. case '“':
  736. case '”':
  737. case ':':
  738. case '、':
  739. case ',':
  740. case '.':
  741. case '!':
  742. case '?':
  743. case ';':
  744. case '"':
  745. case ':':
  746. case '\n':
  747. case '-':
  748. case ' ':
  749. return true;
  750. default:
  751. return false;
  752. }
  753. }
  754. };