bpr318.js 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  1. version = 'v3.1.8';
  2. function splitRGB(color) //îáðàáîòêà öâåòà
  3. {
  4. var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i);
  5. if (!matches)
  6. return false;
  7. for (var i=1, rgb = new Array(3); i<=3; i++)
  8. rgb[i-1] = parseInt(matches[i],16);
  9. return rgb;
  10. }
  11. function rgb2hex(r,g,b)
  12. {
  13. if(r>255) r=255; //0_o áûäëîêîäèíã òàêîé áûäëîêîäèíã
  14. if(g>255) g=255;
  15. if(b>255) b=255;
  16. return '#'+Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
  17. Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
  18. Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1');
  19. }
  20. function base64color(arr) //öâåò îáðàìëåíèÿ
  21. {
  22. var r=arr[0];
  23. var g=arr[1];
  24. var b=arr[2];
  25. if(r>63) r=63; //0_o áûäëîêîäèíã òàêîé áûäëîêîäèíã
  26. if(g>63) g=63;
  27. if(b>63) b=63;
  28. var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
  29. var enc1 = r >> 2;
  30. var enc2 = ((r & 3) << 4) | (g >> 4);
  31. var enc3 = ((g & 15) << 2) | (b >> 6);
  32. var enc4 = b & 63;
  33. return keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
  34. }
  35. function setColors() {
  36. var fc = splitRGB(cfg.fontcolor);
  37. var bg = splitRGB(cfg.bgcolor);
  38. var Q=[Math.round((fc[0]+3*bg[0])/16),Math.round((fc[1]+3*bg[1])/16),Math.round((fc[2]+3*bg[2])/16)];
  39. var M=[Math.round((fc[0]+bg[0])/8),Math.round((fc[1]+bg[1])/8),Math.round((fc[2]+bg[2])/8)];
  40. var middlecolor=rgb2hex(M[0]*4,M[1]*4,M[2]*4);
  41. colorMiddleB64=base64color(M);
  42. colorQuarterB64=base64color(Q);;
  43. if (fc[0]+fc[0]+fc[0]>bg[0]+bg[1]+bg[2]) {
  44. linkcolor=rgb2hex(Math.round(3*(fc[0]+bg[0])/4),Math.round(3*(fc[1]+bg[1])/4),Math.round(3*(fc[2]+bg[2])/4));
  45. } else {
  46. linkcolor=rgb2hex(Math.round((fc[0]+bg[0])/4),Math.round((fc[1]+bg[1])/4),Math.round((fc[2]+bg[2])/4));
  47. }
  48. document.body.link=document.body.vLink=
  49. document.body.aLink=
  50. gdb('comm').style.color=
  51. gdb('footer').style.color=linkcolor;
  52. document.body.style.color=gdb('book').style.color=gdb('main').style.color=
  53. gdb('pageGoto').style.color=
  54. gdb('cross').style.backgroundColor=
  55. gdb('mcross').style.backgroundColor=gdb('clrdiv').style.color=
  56. gdb('clrdiv2').style.color=
  57. gdb('btnOk').style.color=
  58. cfg.fontcolor;
  59. document.body.style.backgroundColor='#000000';
  60. gdb('win').style.backgroundColor=gdb('comm').style.backgroundColor=
  61. gdb('cross').style.color=
  62. gdb('mcross').style.color=
  63. gdb('clrdiv').style.backgroundColor=gdb('clrdiv2').style.backgroundColor=
  64. cfg.bgcolor;
  65. var hr=document.getElementsByTagName('HR');
  66. gdb('colorSelect').children[2].style.borderColor=gdb('colorSelect').children[2].children[1].style.borderColor=
  67. gdb('colorSelect').children[2].children[2].style.borderColor=hr[0].style.color=hr[0].style.backgroundColor=
  68. gdb('comm').style.borderColor=middlecolor;
  69. hr=null;
  70. //
  71. handlerAdd(gdb('cross'),'mouseover',function() {gdb('cross').style.color=middlecolor;});
  72. handlerAdd(gdb('cross'),'mouseout',function() {gdb('cross').style.color=cfg.bgcolor;});
  73. handlerAdd(gdb('mcross'),'mouseover',function() {gdb('mcross').style.color=middlecolor;});
  74. handlerAdd(gdb('mcross'),'mouseout',function() {gdb('mcross').style.color=cfg.bgcolor;});
  75. }
  76. function handlerAdd(object, event, handler) {
  77. if (object.addEventListener)
  78. object.addEventListener(event, handler, false);
  79. else
  80. if (object.attachEvent)
  81. object.attachEvent('on' + event, handler);
  82. else
  83. object['on' + event] = handler;
  84. }
  85. function handlerRemove(object, event, handler) {
  86. if (object.removeEventListener)
  87. object.removeEventListener(event, handler, false);
  88. else
  89. if (object.detachEvent)
  90. object.detachEvent('on' + event, handler);
  91. }
  92. //íèæå: ëîâèì êëàâó
  93. function key(event) {
  94. if (!event) event = window.event;
  95. var thekey=event.keyCode ? event.keyCode + 32 : event.charCode;
  96. tM(event.shiftKey,event.ctrlKey,thekey, event);
  97. }
  98. var m_legend = {
  99. 40: {30: 'PgUp', 100: 'PgDown'},
  100. 60: {40: 'Up', 60: 'Menu', 100: 'Down'},
  101. 100: {30: 'PgUp', 100: 'PgDown'}
  102. };
  103. function processClick(w, h) {
  104. var e = '';
  105. if (typeof(event) == 'string') {
  106. e = event;
  107. } else {
  108. loops: {
  109. for (var perx in m_legend) {
  110. for (var pery in m_legend[perx]) {
  111. if (w < perx && h < pery) {
  112. e = m_legend[perx][pery];
  113. break loops;
  114. }
  115. }
  116. }
  117. }
  118. if (e != '')
  119. button = 1;
  120. }
  121. switch (e) {
  122. case 'Down' ://Down
  123. setTop(null, cfg.step);
  124. break;
  125. case 'Up' ://Up
  126. setTop(null, -cfg.step);
  127. break;
  128. case 'PgDown' ://PgDown
  129. setTop(null, phei - cfg.step);
  130. break;
  131. case 'PgUp' ://PgUp
  132. setTop(null, -(phei - cfg.step));
  133. break;
  134. case 'Menu' ://M
  135. menu();
  136. break;
  137. default :
  138. // Nothing
  139. break;
  140. }
  141. if (doRepeatClick && e != '' && e != 'Menu') {
  142. if (mTimer > 20)
  143. mTimer = mTimer*0.5;
  144. processClickTimeout=setTimeout('processClick('+w+','+h+')', mTimer);
  145. }
  146. }
  147. function mClick(event) {
  148. if (cfg.by_click) {
  149. var win = gdb('win');
  150. var w = event.clientX/win.offsetWidth*100;
  151. var h = event.clientY/win.offsetHeight*100;
  152. doRepeatClick = 1;
  153. mTimer = 1000;
  154. processClick(w, h);
  155. ie8SafePreventEvent(event);
  156. }
  157. }
  158. function mClickUp(event) {
  159. mTouchEnd(event);
  160. }
  161. function mTouchStart(event) {
  162. if (cfg.by_click) {
  163. if (event.touches.length == 1) {
  164. event.preventDefault();
  165. e = event.touches[0];
  166. var win = gdb('win');
  167. var w = e.clientX/win.offsetWidth*100;
  168. var h = e.clientY/win.offsetHeight*100;
  169. doRepeatClick = 1;
  170. mTimer = 1000;
  171. processClick(w, h);
  172. }
  173. }
  174. }
  175. function mTouchEnd(event) {
  176. doRepeatClick = 0;
  177. if (processClickTimeout != null)
  178. clearTimeout(processClickTimeout);
  179. }
  180. function openLink(event, obj, target) {
  181. if (target == null)
  182. target = '_blank';
  183. window.open(obj.href, target);
  184. ie8SafePreventEvent(event);
  185. return false;
  186. }
  187. function toggleFullScreen() {
  188. if ((document.fullScreenElement && document.fullScreenElement !== null) ||
  189. (!document.mozFullScreen && !document.webkitIsFullScreen)) {
  190. if (document.documentElement.requestFullScreen) {
  191. document.documentElement.requestFullScreen();
  192. } else if (document.documentElement.mozRequestFullScreen) {
  193. document.documentElement.mozRequestFullScreen();
  194. } else if (document.documentElement.webkitRequestFullScreen) {
  195. document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  196. }
  197. } else {
  198. if (document.cancelFullScreen) {
  199. document.cancelFullScreen();
  200. } else if (document.mozCancelFullScreen) {
  201. document.mozCancelFullScreen();
  202. } else if (document.webkitCancelFullScreen) {
  203. document.webkitCancelFullScreen();
  204. }
  205. }
  206. }
  207. function ie8SafePreventEvent(e) {
  208. if (e.preventDefault) {
  209. e.preventDefault()
  210. } else
  211. if (e.stop)
  212. e.stop();
  213. e.returnValue = false;
  214. if (e.stopPropagation)
  215. e.stopPropagation();
  216. }
  217. //íèæå: ëîâèì íàæàòèÿ êëàâèø
  218. function tM(shift,ctrl,key, event) {
  219. var srcEl = event.srcElement? event.srcElement : event.target;
  220. //alert(srcEl.tagName);
  221. //alert(key);
  222. if (!ctrl && (srcEl.tagName == 'BODY' || srcEl.tagName == 'DIV'))
  223. switch (key)
  224. {
  225. case 72 ://Down
  226. if (shift)
  227. toggleScroll();
  228. else
  229. setTop(null, cfg.step);
  230. ie8SafePreventEvent(event);
  231. break;
  232. case 70 ://Up
  233. setTop(null, -cfg.step);
  234. ie8SafePreventEvent(event);
  235. break;
  236. case 66 ://PgDown
  237. case 45 ://Enter
  238. setTop(null, phei - cfg.step);
  239. ie8SafePreventEvent(event);
  240. break;
  241. case 64 ://Space
  242. shift ? setTop(null, -(phei - cfg.step)) : setTop(null, phei - cfg.step);
  243. ie8SafePreventEvent(event);
  244. break;
  245. case 65 ://PgUp
  246. case 40 ://BackSpace
  247. setTop(null, -(phei - cfg.step));
  248. ie8SafePreventEvent(event);
  249. break;
  250. case 67 ://End
  251. setTop(clih - phei);
  252. ie8SafePreventEvent(event);
  253. break;
  254. case 68 ://Home
  255. setTop(0);
  256. ie8SafePreventEvent(event);
  257. break;
  258. case 109: //M
  259. menu();
  260. ie8SafePreventEvent(event);
  261. break;
  262. case 97: //A
  263. shift ? incFont(-1) : incFont(1);
  264. ie8SafePreventEvent(event);
  265. break;
  266. case 115: //S
  267. gdb('id_scroll').checked = !gdb('id_scroll').checked;
  268. showScroll();
  269. ie8SafePreventEvent(event);
  270. break;
  271. case 116: //T
  272. gdb('id_by_click').checked = !gdb('id_by_click').checked;
  273. byClick();
  274. ie8SafePreventEvent(event);
  275. break;
  276. case 224://`
  277. case 102://F
  278. toggleFullScreen();
  279. ie8SafePreventEvent(event);
  280. break;
  281. case 122://Z
  282. toggleScroll();
  283. ie8SafePreventEvent(event);
  284. break;
  285. case 59://Escape
  286. if (sti) {
  287. toggleScroll();
  288. ie8SafePreventEvent(event);
  289. }
  290. break;
  291. case 71://Right
  292. if (shift) {
  293. gdb('id_sc_int').value = cfg.sc_int - 1;
  294. scrollInterval();
  295. } else {
  296. setTop(null, phei - cfg.step);
  297. ie8SafePreventEvent(event);
  298. }
  299. break;
  300. case 69://Left
  301. if (shift) {
  302. gdb('id_sc_int').value = cfg.sc_int + 1;
  303. scrollInterval();
  304. } else {
  305. setTop(null, -(phei - cfg.step));
  306. ie8SafePreventEvent(event);
  307. }
  308. break;
  309. case 114:
  310. reloadBook();
  311. break;
  312. default :
  313. // Nothing
  314. break;
  315. }
  316. return false;
  317. }
  318. //êîëåñî
  319. function wheel(event) {
  320. var delta = 0;
  321. if (!event)
  322. event = window.event;
  323. if (event.wheelDelta)
  324. delta = event.wheelDelta/120;
  325. else
  326. if (event.detail)
  327. delta = -event.detail/3;
  328. if (delta)
  329. handle(delta);
  330. return false;
  331. }
  332. function handle(delta) {
  333. if (delta < 0)
  334. setTop(null, cfg.step);
  335. else
  336. setTop(null, -cfg.step);
  337. }
  338. //íèæå: óïðîøàåìñ, â ôèíàëüíîé âåðñèè íàáî áû óáðàòü
  339. function gdb(id)
  340. {
  341. return document.getElementById(id);
  342. }
  343. function supports_html5_storage() {
  344. try {
  345. return 'localStorage' in window && window['localStorage'] !== null;
  346. } catch (e) {
  347. return false;
  348. }
  349. }
  350. function saveLocalValue(key, value, expires_days, no_escape) {
  351. if (value != null) {
  352. if (no_escape == null)
  353. localStorage[key] = escape(value);
  354. else
  355. localStorage[key] = value;
  356. if (expires_days == null)
  357. expires_days = 0;
  358. localStorage[key+'=timestamp'] = (new Date()) + ';' + expires_days;
  359. }
  360. else {
  361. localStorage.removeItem(key);
  362. localStorage.removeItem(key+'=timestamp');
  363. }
  364. }
  365. //êóêèñû è localStorage
  366. function saveValue(name, value, expires_days, no_escape) {
  367. var key = escape(name);
  368. if (is_storage) {
  369. try {
  370. saveLocalValue(key, value, expires_days, no_escape);
  371. } catch (e) {
  372. //alert('LocalStorage, îøèáêà: ' + e.message);
  373. var size = 0;
  374. //Ñ íà÷àëà - õîòü êàêîé-òî ìåõàíèçì î÷åðåäè
  375. for ( var i = 0; i < localStorage.length; i++ ) {
  376. var lkey = localStorage.key( i );
  377. var v = localStorage[lkey];
  378. //lkeys = lkeys + unescape(lkey) + ":" + (v != null ? v.length : 0) + "\n";
  379. if (v != null && v.length > 10000) {
  380. size += v.length;
  381. localStorage.removeItem(lkey);
  382. localStorage.removeItem(lkey+'=timestamp');
  383. i = 0;
  384. if (size > value.length)
  385. break;
  386. }
  387. }
  388. //×èñòêà ïðîòóõøèõ, ñ êîíöà
  389. for ( var i = localStorage.length; i >= 0 ; i-- ) {
  390. var lkey = unescape(localStorage.key( i ));
  391. loadValue(lkey);
  392. }
  393. try { saveLocalValue(key, value, expires_days, no_escape) } catch(e) {};
  394. //alert(size);
  395. //LocalStorage.clear();
  396. }
  397. if (document.cookie != '')
  398. document.cookie = '';
  399. } else {
  400. var exp = new Date();
  401. if (expires_days)
  402. exp.setHours(exp.getHours() + 24*expires_days);
  403. document.cookie = key + "=" + escape(value) +
  404. ((expires_days) ? "; expires=" + exp.toUTCString() : "") +
  405. "; path=/";
  406. }
  407. }
  408. function getCookie(name) {
  409. var setStr = null;
  410. var cookie = " " + document.cookie;
  411. var search = " " + name + "=";
  412. var offset = 0;
  413. var end = 0;
  414. if (cookie.length > 0) {
  415. offset = cookie.indexOf(search);
  416. if (offset != -1) {
  417. offset += search.length;
  418. end = cookie.indexOf(";", offset)
  419. if (end == -1)
  420. end = cookie.length;
  421. setStr = unescape(cookie.substring(offset, end));
  422. }
  423. }
  424. return(setStr);
  425. }
  426. function loadValue(name, no_escape) {
  427. var value = null;
  428. if (is_storage) {
  429. var key = escape(name);
  430. value = localStorage[key];
  431. var ts = localStorage[key+'=timestamp'];
  432. if (value != null && no_escape == null)
  433. value = unescape(value);
  434. if (ts != null) {
  435. ts = ts.split(";");
  436. var exp = new Date(ts[0]);
  437. exp.setHours(exp.getHours() + 24*ts[1]);
  438. if (exp < new Date()) {
  439. value = null;
  440. localStorage.removeItem(key);
  441. localStorage.removeItem(key+'=timestamp');
  442. }
  443. } else {
  444. localStorage.removeItem(key);
  445. localStorage.removeItem(key+'=timestamp');
  446. }
  447. }
  448. if (value == null)
  449. value = getCookie(escape(name));
  450. if (value == null)
  451. value = getCookie(name);
  452. return(value);
  453. }
  454. //ñ÷¸ò÷èê ñòðàíèö è ïðîöåíòîâ
  455. function tMh() {
  456. if (!sti || gdb('main').scrollTop%cfg.step == 0) {
  457. var top = Math.round(gdb('main').scrollTop/cfg.step)*cfg.step;
  458. gdb('main').scrollTop = top;
  459. pcount = Math.ceil( clih / (phei-cfg.step) );
  460. if (clih == phei)
  461. pcount = 1;
  462. var page = Math.floor((top - cfg.step) / (phei-cfg.step) + 2);
  463. percent = Math.round(top / (clih-phei) * 10000) / 100; //(top==0) ? 0 :
  464. if (clih == phei)
  465. percent = 100;
  466. gdb('pagePercent').innerHTML='&nbsp;&nbsp;[ ' + percent.toFixed(2) + '%' + ' ]&nbsp;&nbsp;&nbsp;';
  467. gdb('pageCount').children[1].innerHTML=page + '/' + pcount;
  468. gdb('pageGoto').value=page;
  469. if (stadc == null)
  470. stadc = setTimeout('addCook()', 300);
  471. };
  472. if (sttmh != null) {
  473. clearTimeout(sttmh);
  474. sttmh = null;
  475. }
  476. }
  477. //ïåðåõîä íà ñòðàíèöó
  478. function goTo() {
  479. var gpage=parseInt(gdb('pageGoto').value);
  480. setTop((((gpage-2)*(phei-cfg.step) + cfg.step)/cfg.step).toFixed(0)*cfg.step);
  481. }
  482. function pageGoto(gpag) {
  483. if (gpa) {
  484. var gpage=parseInt(gdb('pageGoto').value);
  485. gpage = gpag ? (gpage > 1 ? gpage-1 : 1) : (gpage<pcount ? gpage+1 : pcount);
  486. gdb('pageGoto').value=gpage;
  487. var t=setTimeout('pageGoto('+gpag+')',timer);
  488. if (timer>20)
  489. timer=timer/2;
  490. } else
  491. timer=300;
  492. }
  493. function pageMove(arrow) {
  494. handlerAdd(document,'mouseup',pageMoveClear);
  495. if (timer>20) timer=timer*0.9;
  496. setTop(null, (arrow ? cfg.step-phei : phei-cfg.step));
  497. pageMoveTimeout=setTimeout('pageMove('+arrow+')',timer);
  498. }
  499. function pageMoveShow(pS,nS) {
  500. pageMoveTemp = pageMoveTemp ? 0 : 1;
  501. gdb('pageCount').children[0].style.visibility=
  502. gdb('pageCount').children[2].style.visibility=
  503. pageMoveTemp ? 'visible' : 'hidden';
  504. }
  505. function pageMoveClear() {
  506. if (timer<300) {
  507. clearTimeout(pageMoveTimeout);
  508. handlerRemove(document,'mouseup',pageMoveClear);
  509. timer=300;
  510. }
  511. }
  512. //âðåìÿ
  513. function showTime()
  514. {
  515. var tmN=new Date();
  516. var dH=''+tmN.getHours();dH=dH.length<2?'0'+dH:dH;
  517. var dM=''+tmN.getMinutes();dM=dM.length<2?'0'+dM:dM;
  518. var tmp=dH+':'+dM;
  519. if (bookloaded)
  520. gdb('tm').innerHTML=tmp;
  521. else
  522. gdb('tm').innerHTML=version;
  523. var t=setTimeout('showTime()',60000);
  524. }
  525. function setSelectedFontItem() {
  526. if (colorFontTemp == 0) {
  527. gdb('fontItemBack').style.color = 'green';
  528. gdb('fontItemBack').style.textDecoration = 'underline';
  529. gdb('fontItemText').style.color = 'black';
  530. gdb('fontItemText').style.textDecoration = 'none';
  531. } else {
  532. gdb('fontItemText').style.color = 'green';
  533. gdb('fontItemText').style.textDecoration = 'underline';
  534. gdb('fontItemBack').style.color = 'black';
  535. gdb('fontItemBack').style.textDecoration = 'none';
  536. }
  537. }
  538. //ìåíþ âûáîðà íàñòðîåê øðèôòà
  539. function colorMenu() {
  540. handlerAdd(document,'mousemove', mouseMoved);
  541. colorFontTemp=0;
  542. setSelectedFontItem();
  543. colorFont=cfg.fontcolor;
  544. colorBg=cfg.bgcolor;
  545. colorSize=Math.round(cfg.step*0.8);
  546. gdb('fcolor').value=colorFont;
  547. gdb('bcolor').value=colorBg;
  548. gdb('fsize').value=colorSize;
  549. gdb('ffamily').value=cfg.fontfamily;
  550. if (gdb('ffamily').value != cfg.fontfamily)
  551. gdb('ffamily2').value=cfg.fontfamily;
  552. else
  553. gdb('ffamily2').value='';
  554. colorAddary=new Array(255,1,1);
  555. colorClrary=new Array(360);
  556. for(i=0;i<6;i++) {
  557. for(j=0;j<60;j++) {
  558. colorClrary[60*i+j]=new Array(3);
  559. for(k=0;k<3;k++) {
  560. colorClrary[60*i+j][k]=colorAddary[k];
  561. colorAddary[k]+=((Math.floor(65049010/Math.pow(3,i*3+k))%3)-1)*4;
  562. }
  563. }
  564. }
  565. gdb('colorSelect').style.display='block';
  566. }
  567. function mouseMoved(e) {
  568. var sy = e.pageX-parseInt(gdb('colorSelect').style.left)-454;
  569. var sx = e.pageY-parseInt(gdb('colorSelect').style.top)-300;
  570. //alert(sy+'lk'+sx);
  571. if (sy>-256&&sx>-256&&sx<256&&sy<256) {
  572. var quad=new Array(-180,360,180,0);
  573. var xa=Math.abs(sx);
  574. var ya=Math.abs(sy);
  575. var d=ya*45/xa;
  576. if (ya>xa)
  577. d=90-(xa*45/ya);
  578. var deg=Math.floor(Math.abs(quad[2*((sy<0)?0:1)+((sx<0)?0:1)]-d));
  579. var n=0;
  580. var c="000000";
  581. var r=Math.sqrt((xa*xa)+(ya*ya));
  582. if(sx!=0 || sy!=0) {
  583. for(i=0;i<3;i++) {
  584. r2=colorClrary[deg][i]*r/128;
  585. if (r>128)
  586. r2+=Math.floor(r-128)*2;
  587. if (r2>255)
  588. r2=255;
  589. n=256*n+Math.floor(r2);
  590. }
  591. c=(n.toString(16)).toUpperCase();
  592. while (c.length<6)
  593. c="0"+c;
  594. }
  595. gdb('clrdiv').style.backgroundColor=colorFontTemp ? colorBg : "#"+c;
  596. gdb('clrdiv').style.color=colorFontTemp ? "#"+c : colorFont;
  597. tempColor="#"+c;
  598. }
  599. return false;
  600. }
  601. function colorSet() {
  602. var clrdiv2=gdb('clrdiv2').style;
  603. if (colorFontTemp)
  604. clrdiv2.color=gdb('fcolor').value=colorFont=tempColor;
  605. else
  606. clrdiv2.backgroundColor=gdb('bcolor').value=colorBg=tempColor;
  607. }
  608. function colorChange(type, value) { //íàâåñòè ìàðàôåò
  609. var value=value.toUpperCase();
  610. if(type==2 || type==1) {
  611. if (value.charAt(0)!='#')
  612. value='#'+value;
  613. value=value.length==7 ? value :
  614. (value.length==4 ?
  615. value.substr(0,2)+value.substr(1,1)+value.substr(2,1)+value.substr(2,1)+value.substr(3,1)+value.substr(3,1) :
  616. (type==2 ? cfg.bgcolor : cfg.fontcolor)
  617. ); //ñäåëàòü ÷åëîâå÷åñêè
  618. if (type==2)
  619. gdb('bcolor').value = value;
  620. else
  621. gdb('fcolor').value = value;
  622. }
  623. var clrdiv2=gdb('clrdiv2').style;
  624. var clrdiv=gdb('clrdiv').style;
  625. if (type == 4)
  626. clrdiv2.fontFamily = value;
  627. if (type==3 && parseInt(value) > 4 && parseInt(value) < 201)
  628. clrdiv2.fontSize=clrdiv.fontSize=parseInt(value)+'px';
  629. if (type==2)
  630. clrdiv2.backgroundColor=clrdiv.backgroundColor=value;
  631. if (type==1)
  632. clrdiv2.color=clrdiv.color=value;
  633. return false;
  634. }
  635. function saveSettings() {
  636. saveValue('colorSetting', cfg.fontcolor+'|'+cfg.bgcolor+'|'+cfg.step+'|'+cfg.fontfamily+'|'+cfg.scroller+'|'+cfg.sp_size+'|'+cfg.sc_int+'|'+cfg.by_click, 36500);
  637. }
  638. function colorSubmit() {
  639. cfg.fontcolor=gdb('fcolor').value;
  640. cfg.bgcolor=gdb('bcolor').value;
  641. cfg.step=Math.round(parseInt(gdb('fsize').value)/0.8);
  642. cfg.fontfamily=gdb('ffamily2').value;
  643. if (!cfg.fontfamily)
  644. cfg.fontfamily = gdb('ffamily').value;
  645. gdb('main').style.font=Math.round(cfg.step*0.8)+"px/"+cfg.step+"px Trebuchet Ms";
  646. gdb('main').style.fontFamily=cfg.fontfamily;
  647. saveSettings();
  648. setColors();
  649. onRes();
  650. }
  651. function colorClose() {
  652. handlerRemove(document,'mousemove', mouseMoved);
  653. gdb('colorSelect').style.display='none';
  654. tempColor=null;
  655. colorFontTemp=null;
  656. colorFont=null;
  657. colorBg=null;
  658. colorSize=null;
  659. colorAddary=null;
  660. colorClrary=null;
  661. }
  662. function incFont(i) {
  663. foSize=Math.round(cfg.step*0.8);
  664. foSize += i;
  665. if (foSize < 5 || foSize > 200)
  666. return;
  667. cfg.step=Math.round(foSize/0.8);
  668. gdb('main').style.fontSize = foSize + 'px';
  669. gdb('main').style.lineHeight = cfg.step + 'px';
  670. saveSettings();
  671. onRes();
  672. }
  673. function mainScroll() {
  674. if (sttmh == null)
  675. sttmh = setTimeout('tMh()', 500);
  676. }
  677. //íèæå: â êóêèñû
  678. function addCook() {
  679. saveValue('bpr-book-' + tit, gdb('main').scrollTop + '|' + gdb('main').scrollHeight + '|' + gdb('main').innerHTML.length, 36500);
  680. if (stadc) {
  681. clearTimeout(stadc);
  682. stadc = null;
  683. }
  684. }
  685. //íèæå: ìåíþ
  686. function menu() {
  687. if (gdb('comm').style.display != 'block')
  688. gdb('comm').style.display="block";
  689. else {
  690. gdb('leg').style.display="none";
  691. gdb('comm').style.display="none";
  692. }
  693. }
  694. //íèæå: ëåãåíäà
  695. function legend(ca) {
  696. if (ca) {
  697. gdb('leg').style.display="block";
  698. gdb('leg').style.left=Math.round((widt-((widt/100)*60))/2) + 'px';
  699. gdb('leg').style.top=Math.round((hei-((hei/100)*60))/2) + 'px';
  700. } else {
  701. gdb('leg').style.display="none";
  702. }
  703. }
  704. function setScroll(u) {
  705. u = (u == null) ? true : u;
  706. gdb('id_scroll').checked = cfg.scroller;
  707. if (cfg.scroller)
  708. gdb('main').style.overflowY = 'auto';
  709. else
  710. gdb('main').style.overflowY = 'hidden';
  711. if (u)
  712. onRes();
  713. }
  714. function showScroll() {
  715. cfg.scroller = gdb('id_scroll').checked;
  716. setScroll();
  717. saveSettings();
  718. return true;
  719. }
  720. function setSPSize(u) {
  721. u = (u == null) ? true : u;
  722. gdb('id_sp_size').value = cfg.sp_size;
  723. gdb('footer').style.height = cfg.sp_size + 'px';
  724. gdb('fhr').style.bottom = cfg.sp_size + 'px';
  725. if (cfg.sp_size == 0)
  726. gdb('fhr').style.display = 'none';
  727. else
  728. gdb('fhr').style.display = 'block';
  729. if (cfg.sp_size > 2)
  730. gdb('footer').style.font=(cfg.sp_size - 3)+"px/"+(cfg.sp_size-1)+"px 'Trebuchet Ms', Sans-Serif";
  731. if (u)
  732. onRes();
  733. }
  734. function statusPanel() {
  735. var s = parseInt(gdb('id_sp_size').value);
  736. if (s >= 0 && s <= 200)
  737. cfg.sp_size = s;
  738. setSPSize();
  739. saveSettings();
  740. return false;
  741. }
  742. function setTop(v, i) {
  743. if (i != null)
  744. gdb('main').scrollTop += i;
  745. else
  746. gdb('main').scrollTop = v;
  747. tMh();
  748. p_top = gdb('main').scrollTop;
  749. }
  750. function scrollText() {
  751. setTop(null, 1);
  752. }
  753. function toggleScroll(u) {
  754. u = (u == null) ? true : u;
  755. //alert('ok');
  756. if (sti) {
  757. clearTimeout(sti);
  758. sti = null;
  759. if (u)
  760. tMh();
  761. } else
  762. sti = setInterval('scrollText()', cfg.sc_int);
  763. return false;
  764. }
  765. function setScrollInt(u) {
  766. u = (u == null) ? true : u;
  767. gdb('id_sc_int').value = cfg.sc_int;
  768. toggleScroll(u);
  769. toggleScroll(u);
  770. }
  771. function scrollInterval() {
  772. var s = parseInt(gdb('id_sc_int').value);
  773. if (s > 0 && s <= 999)
  774. cfg.sc_int = s;
  775. setScrollInt(false);
  776. saveSettings();
  777. return false;
  778. }
  779. function setByClick() {
  780. gdb('id_by_click').checked = cfg.by_click;
  781. }
  782. function byClick() {
  783. cfg.by_click = gdb('id_by_click').checked;
  784. setByClick();
  785. saveSettings();
  786. return true;
  787. }
  788. function reloadBook() {
  789. if (is_storage) {
  790. saveValue('bpr-link-' + tit, null);
  791. saveValue('bpr-cached-book-'+tit, null);
  792. }
  793. window.location.href = window.location.href;
  794. return false;
  795. }
  796. function blinkReloadButton() {
  797. blinkCount++;
  798. if (blinkCount%2 == 1)
  799. gdb('reload').style.color = cfg.bgcolor;
  800. else
  801. gdb('reload').style.color = linkcolor;
  802. if (blinkCount > 30) {
  803. gdb('reload').style.color = linkcolor;
  804. if (stblinkRB != null) {
  805. clearTimeout(stblinkRB);
  806. stblinkRB == null;
  807. }
  808. }
  809. }
  810. //íèæå: ëîâèì èçìåíåíèå ðàçìåðîâ îêíà
  811. //íèæå: ëîâèì ðàçìåðû ðàáî÷åé îáëàñòè
  812. function gerT() {
  813. var w, h, hh;
  814. w = Math.round(window.innerWidth ?
  815. window.innerWidth :
  816. (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
  817. h = Math.round(window.innerHeight ?
  818. window.innerHeight :
  819. (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
  820. hh = Math.floor((h - (cfg.sp_size + 8)) / cfg.step) * cfg.step;
  821. return {w:w, h:h, hh:hh};
  822. }
  823. function onRes(u) {
  824. var focused = document.activeElement;
  825. //alert(focused.tagName);
  826. if (focused == null || focused.tagName != 'INPUT') {
  827. var g = gerT();
  828. hei = g.h;
  829. phei = g.hh;
  830. widt = g.w;
  831. gdb('header').style.height = Math.round((hei - (cfg.sp_size + 3) - phei)/2)+'px';
  832. gdb('main').style.height=phei+'px';
  833. gdb('win').style.height=hei+'px';
  834. //alert(widt + '/' +gdb('tr').style.width +gdb('main').style.width+gdb('tr').style.width)
  835. clih = gdb('main').scrollHeight;
  836. gdb('colorSelect').style.top=Math.round((hei-600)/2)+'px';
  837. gdb('colorSelect').style.left=Math.round((widt-300)/2)+'px'; //754
  838. gdb('comm').style.left=Math.round((widt-264)/2) + 'px';
  839. gdb('comm').style.top=Math.round((hei-264)/2) + 'px';
  840. if (u || u == null) {
  841. if (pclih != clih && pclih > 0) {
  842. var n_top = Math.round(p_top/pclih*clih);
  843. setTop(n_top);
  844. } else
  845. tMh();
  846. pclih = clih;
  847. }
  848. ow = widt - (gdb('id_lp').clientWidth + gdb('id_rp').clientWidth) - 10;
  849. if (ow < 0)
  850. ow = 0;
  851. gdb('orig').style.width = ow + 'px';
  852. gdb('orig').style.left = gdb('id_lp').clientWidth + 'px';
  853. } else
  854. setTimeout('onRes()', 500);
  855. }
  856. //--------------------------------------------------------------------------------------------------
  857. //çàãðóçêà
  858. function loadBook(book) {
  859. gdb('main').innerHTML = book;
  860. //íèæå: äîáûâàåì òàéòë
  861. var book_author = loadValue('bpr-author-' + tit);
  862. book_author = (book_author == null ? '' : book_author);
  863. var book_title = loadValue('bpr-title-' + tit);
  864. book_title = (book_title == null ? '' : book_title);
  865. var doc_title = tit;
  866. if (book_author + book_title != '')
  867. doc_title = book_author + (book_author != '' ? ' - ' : '') + book_title;
  868. if (tit != '')
  869. document.title = doc_title;
  870. bookloaded = true;
  871. gdb('win').style.display = gdb('footer').style.display = 'block';
  872. onRes(false);
  873. setTimeout('handlerAdd(window,"resize",onRes)',1); //åù¸ îäíî ÷óäî îò îñëà !!ïðîâåðèòü
  874. gdb('orig_href').href = tit;
  875. gdb('orig_href').innerHTML = doc_title;
  876. showTime();
  877. pclih = gdb('main').scrollHeight;
  878. var s_top = 0;
  879. var lv = loadValue('bpr-book-' + tit);
  880. if (lv) {
  881. // Âîññòàíîâèì ïîçèöèþ â òåêñòå
  882. var cpos = lv.split('|');
  883. var ntl = gdb('main').innerHTML.length;
  884. if (cpos[0]) {
  885. if (cpos[1] > 0 && ntl > 0) {
  886. var tp = cpos[0]/cpos[1]*cpos[2];
  887. s_top = Math.round(tp/ntl*pclih);
  888. }
  889. else
  890. s_top = cpos[0]; // Ñòàðûé âàðèàíò
  891. }
  892. }
  893. setTop(s_top);
  894. onRes(false);
  895. gdb('loading').style.display='none';
  896. }
  897. function parseBook(book, cached, save_to_cache) {
  898. var meta_sign = '<<<bpr5A432688AB0467AA396E5A144830248Abpr>>>';
  899. var meta_idx = book.indexOf(meta_sign);
  900. if (meta_idx >= 0) {
  901. var meta_info = book.substr(0, meta_idx).split('|');
  902. var book_link = meta_info[0];
  903. var book_author = meta_info[1];
  904. var book_title = meta_info[2];
  905. if (book_link != null) {
  906. book = book.substr(meta_idx + meta_sign.length);
  907. if (is_storage) {
  908. if (book_link != 'no_file') {
  909. saveValue('bpr-link-' + tit, book_link, 10);
  910. }
  911. if (save_to_cache) {
  912. saveValue('bpr-cached-book-'+tit, book, 30, 1);
  913. }
  914. saveValue('bpr-author-' + tit, book_author, 10);
  915. saveValue('bpr-title-' + tit, book_title, 10);
  916. }
  917. }
  918. }
  919. loadBook(book);
  920. if (cached != null) {
  921. blinkCount = 0;
  922. stblinkRB = setInterval('blinkReloadButton()', 500);
  923. }
  924. }
  925. function getDefaultSettings() {
  926. var def = {};
  927. def.bgcolor='#ebe2c9';
  928. def.fontcolor='#000000';
  929. def.step = 26;
  930. def.fontfamily = 'Trebuchet Ms';
  931. def.scroller = true;
  932. def.sp_size = 22;
  933. def.sc_int = 50;
  934. def.by_click = true;
  935. return def;
  936. }
  937. function loadSettings() {
  938. if (location.hash == '#RestoreDefaults') {
  939. saveSettings();
  940. } else {
  941. var lv = loadValue('colorSetting');
  942. if (lv) {
  943. var colorSetting=lv.split('|');
  944. cfg.fontcolor=colorSetting[0];
  945. cfg.bgcolor=colorSetting[1];
  946. cfg.step=parseInt(colorSetting[2]);
  947. if (colorSetting[3])
  948. cfg.fontfamily=colorSetting[3];
  949. if (colorSetting[4] != null)
  950. cfg.scroller = colorSetting[4].toLowerCase() == 'true';
  951. if (colorSetting[5] != null)
  952. cfg.sp_size = parseInt(colorSetting[5]);
  953. if (colorSetting[6] != null)
  954. cfg.sc_int = parseInt(colorSetting[6]);
  955. if (colorSetting[7] != null)
  956. cfg.by_click = colorSetting[7].toLowerCase() == 'true';
  957. }
  958. }
  959. }
  960. function applySettings() {
  961. setScroll(false);
  962. setSPSize(false);
  963. setScrollInt(false);
  964. setByClick();
  965. gdb('main').style.font=Math.round(cfg.step*0.8)+"px/"+cfg.step+"px "+cfg.fontfamily;
  966. gdb('clrdiv2').style.fontSize=Math.round(cfg.step*0.8)+'px';
  967. setColors();
  968. }
  969. function parseQuery(qry) {
  970. var params = {};
  971. var a = qry.split('&');
  972. for (var i = 0; i < a.length; i++) {
  973. var b = a[i].split('=');
  974. params[decodeURIComponent(b[0])] = decodeURIComponent(b[1]);
  975. }
  976. return params;
  977. }
  978. function objectEquals(obj1, obj2) {
  979. for (var i in obj1) {
  980. if (obj1.hasOwnProperty(i)) {
  981. if (!obj2.hasOwnProperty(i)) return false;
  982. if (obj1[i] != obj2[i]) return false;
  983. }
  984. }
  985. for (var i in obj2) {
  986. if (obj2.hasOwnProperty(i)) {
  987. if (!obj1.hasOwnProperty(i)) return false;
  988. if (obj1[i] != obj2[i]) return false;
  989. }
  990. }
  991. return true;
  992. }
  993. function checkRedirect() {
  994. if (typeof doRedirect == 'string' && doRedirect != '') {
  995. var settings = JSON.stringify(cfg);
  996. window.location.href = doRedirect + '?sets=' + btoa(settings) + '&' + window.location.search.substr(1);
  997. return true;
  998. }
  999. var qry = location.search.substr(1);
  1000. var params = parseQuery(qry);
  1001. if ('sets' in params) {
  1002. var settings = atob(params.sets);
  1003. var newCfg = JSON.parse(settings);
  1004. if (objectEquals(cfg, getDefaultSettings())) {
  1005. cfg = newCfg;
  1006. saveSettings();
  1007. applySettings();
  1008. }
  1009. var qry = location.search.substr(1);
  1010. var url = qry.split('url=')[1] || '';
  1011. if (url != '')
  1012. window.location.href = siteroot + '?url=' + url;
  1013. else
  1014. window.location.href = siteroot;
  1015. return true;
  1016. }
  1017. return false;
  1018. }
  1019. function onLoa() {
  1020. DOM = document.getElementById;
  1021. Netscape4 = document.layer;
  1022. Netscape6 = Mozilla = (navigator.appName == "Netscape") && DOM;
  1023. Netscape7 = navigator.userAgent.indexOf("Netscape/7") >= 0;
  1024. Opera5 = window.opera && DOM;
  1025. Opera6 = Opera5 && window.print;
  1026. Opera7 = Opera5 && navigator.userAgent.indexOf("Opera 7") >= 0;
  1027. Opera8 = navigator.userAgent.indexOf("Opera/8") >= 0;
  1028. Opera9 = navigator.userAgent.indexOf("Opera/9") >= 0;
  1029. IE = document.all && !Opera5;
  1030. Firefox = navigator.userAgent.indexOf("Firefox") >= 0;
  1031. is_storage = supports_html5_storage();
  1032. bookloaded = false;
  1033. handlerAdd(document,'keydown', key); //ëîâèì íàæàòèå êíîïêè
  1034. if (window.addEventListener)
  1035. window.addEventListener('DOMMouseScroll', wheel, false);
  1036. window.onmousewheel = document.onmousewheel = wheel;
  1037. sti = null;
  1038. sttmh = null;
  1039. stadc = null;
  1040. blinkCount = 0;
  1041. stblinkRB = null;
  1042. gdb('main').onscroll = mainScroll;
  1043. pageMoveTemp=0; //èíäèêàòîð ñêðûòîñòè ñòðåëî÷åê
  1044. cfg = getDefaultSettings();
  1045. loadSettings();
  1046. applySettings();
  1047. link = '';
  1048. flink = '';
  1049. percent = 0.00;
  1050. gpa = 1;
  1051. timer=300;
  1052. doRepeatClick = 0;
  1053. processClickTimeout = null;
  1054. pcount = 1;
  1055. clih = 0;
  1056. pclih = 0;
  1057. p_top = 0;
  1058. tit='';
  1059. if (checkRedirect())
  1060. return;
  1061. try {
  1062. var qry = location.search.substr(1);
  1063. var url = qry.split('url=')[1] || '';
  1064. var furl = siteroot + 'f.php?url=' + url;
  1065. gdb('loading').style.display='block';
  1066. if (url.length > 0) {
  1067. if ('ontouchstart' in document.documentElement) {
  1068. handlerAdd(gdb('win'),'touchstart', mTouchStart); //ëîâèì òà÷ïàä
  1069. handlerAdd(gdb('win'),'touchend', mTouchEnd); //ëîâèì òà÷ïàä
  1070. } else {
  1071. handlerAdd(gdb('win'),'mousedown', mClick); //ëîâèì íàæàòèå ìûøè
  1072. handlerAdd(gdb('win'),'mouseup', mClickUp); //ëîâèì íàæàòèå ìûøè
  1073. }
  1074. }
  1075. if(url.length > 0) {
  1076. tit = url;
  1077. var cached = loadValue('bpr-link-' + tit);
  1078. if (cached != null && is_storage) {
  1079. furl = siteroot + cached;
  1080. }
  1081. var cached_book = loadValue('bpr-cached-book-'+tit, 1);
  1082. if (cached_book != null) {
  1083. parseBook(cached_book, 1, 0);
  1084. } else {
  1085. var request = new XMLHttpRequest();
  1086. request.open('GET', furl, true);
  1087. request.onreadystatechange = function() {
  1088. if (request.readyState == 4) {
  1089. if(request.status == 200) {
  1090. parseBook(request.responseText, cached, 1);
  1091. } else {
  1092. if (cached != null)
  1093. reloadBook();
  1094. else {
  1095. tit = 'http error';
  1096. loadBook('Îøèáêà çàãðóçêè êíèãè: ' + request.status + ' ' + request.statusText);
  1097. }
  1098. }
  1099. }
  1100. };
  1101. request.send(null);
  1102. }
  1103. } else {
  1104. loadBook(gdb('dop').innerHTML + gdb('leg').innerHTML);
  1105. bookloaded = false;
  1106. setTop(0);
  1107. gdb('top100').style.display = 'none';
  1108. gdb('id_add').style.height = (cfg.step - gdb('main').scrollHeight%cfg.step) + 'px';
  1109. gdb('book').focus();
  1110. }
  1111. } catch (e) {
  1112. tit = '';
  1113. loadBook('Îøèáêà çàãðóçêè êíèãè: ' + e.message);
  1114. }
  1115. showTime();
  1116. }