bookdetail.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. let beginWid = window.innerWidth;
  2. //移动设备的高度
  3. // let deviceHeight = document.documentElement.clientHeight;
  4. // $('.container').css('height', deviceHeight+'px')
  5. var Dom = {
  6. font_Pop: $("#font_Pop"),
  7. extra_Pop: $("#extra_Pop"),
  8. nav_top: $("#nav_top"),
  9. nav_bottom: $("#nav_bottom"),
  10. icon_Aa: $("#icon_Aa"),
  11. icon_extra: $("#icon_extra"),
  12. body: $("body"),
  13. win: $(window),
  14. slider: $("#slider"),
  15. icon_mulu: $("#icon_mulu"),
  16. mulu_Box: $("#mulu_Box"),
  17. mulu_Dialog: $("#mulu_Dialog"),
  18. mulu_Mask: $("mulu_Mask"),
  19. mulu_Cons: $("#mulu_Cons"),
  20. muluList: $("#muluList"),
  21. bkList: $("#bk-list"),
  22. header: $("#header"),
  23. ChapterDialog: $("#ChapterDialog")
  24. }
  25. var Util = (function() { //封装的本地存储和json数据解析
  26. var prefix = 'function_reader_';
  27. var StorageGetter = function(key) {
  28. return localStorage.getItem(prefix + key);
  29. }
  30. var StorageSetter = function(key, val) {
  31. return localStorage.setItem(prefix + key, val);
  32. }
  33. //通过url来获取加密信息,并解密
  34. var getJsonp = function(url, callback) {
  35. return $.jsonp({
  36. url: url,
  37. cache: true,
  38. callback: 'duokan_fiction_chapter',
  39. success: function(result) {
  40. //获取加密信息,解码、转json
  41. var data = $.base64.decode(result);
  42. var json = decodeURIComponent(escape(data));
  43. callback(json);
  44. }
  45. })
  46. }
  47. return {
  48. getJsonp: getJsonp,
  49. StorageGetter: StorageGetter,
  50. StorageSetter: StorageSetter
  51. }
  52. })();
  53. /***** 存储记录 *****/
  54. //背景颜色
  55. var bgColor = Util.StorageGetter("bgColor") || "rgb(233, 223, 199)"; //默认”纸张“背景颜色
  56. //字体颜色
  57. var fontColor = bgColor === 'rgb(40, 53, 72)' ? "#f8f8f8" : "#000000"; //默认黑色
  58. //字号大小
  59. let size = Util.StorageGetter("font_size") ? parseInt(Util.StorageGetter("font_size")) : 18;
  60. var fontSize = size / 16;
  61. //数据层的初始化
  62. var readerUIFrame = ReaderBaseFrame($('.Content'));
  63. var readerMuluFrame = ReaderMuluFrame($('#muluList'), '初始化')
  64. var File_id = 0;
  65. var Chapter_id = 0;
  66. var ChapterTotal = 0;
  67. var ChapterList = [];
  68. var readerm = ReaderModel();
  69. readerm.init(function(data, mulu) {
  70. readerUIFrame(data);
  71. ChapterList = mulu;
  72. readerMuluFrame(mulu, '2');
  73. $("#ChapterTitle").text(data.ct);
  74. setHtmlStyle()
  75. });
  76. //业务事件的初始化
  77. EventHandler();
  78. function ReaderBaseFrame(container) { //UI渲染层
  79. function ParseChapterData(jsonData) { //生成要展示的 html文本
  80. let jsonObj = jsonData;
  81. let size = Util.StorageGetter("font_size");
  82. size = size ? parseInt(size) : 18;
  83. fontSize = size / 16;
  84. let fontSizeAdd6 = (size + 6) / 16;
  85. let fontSizeAdd2 = (size + 2) / 16;
  86. let html = "";
  87. if (!!jsonObj.introduction && jsonObj.introduction.length > 0) {
  88. html += "<br/><br/><br/>";
  89. for (let i = 0; i < jsonObj.introduction.length; i++) {
  90. html +=
  91. `<p class="colorStyle" style="font-size:${fontSize}rem;color:${fontColor}">${jsonObj.introduction[i]}</p>`;
  92. }
  93. }
  94. // 封面-0,扉页-1 不需要展示章节名称
  95. if (!['0', '1'].includes(Chapter_id + '')) {
  96. html += `<br/><br/><br/>`;
  97. if (jsonObj.ct && jsonObj.ct !== jsonObj.t) {
  98. html += `<h3 style=font-size:${fontSizeAdd6};color:${fontColor}">${jsonObj.ct}</h3><br/>`;
  99. }
  100. html += `<h4 style=font-size:${fontSizeAdd6};color:${fontColor}">${jsonObj.t}</h4>`;
  101. }
  102. //正文内容
  103. for (let i = 0; i < jsonObj.p.length; i++) {
  104. if (Chapter_id == 0) {
  105. html += "<div>" + jsonObj.p[i] + "</div>";
  106. } else {
  107. if (/^##.*/.test(jsonObj.p[i])) {
  108. html +=
  109. `<h6 class="colorStyle" style="line-height: 2.0625rem; padding: 1.25rem 0 0.3125rem; font-weight: bold; font-size:${fontSize}rem;color:${fontColor}">${jsonObj.p[i].replace('##', '')}</h6>`;
  110. } else if (/^#.*/.test(jsonObj.p[i])) {
  111. html +=
  112. `<h5 class="colorStyle" style="line-height: 2.1875rem; padding: 0.625rem 0; font-weight: bold; font-size:${fontSizeAdd2}rem;color:${fontColor}">${jsonObj.p[i].replace('#', '')}</h5>`;
  113. } else if (/^\<img.*/.test(jsonObj.p[i])) {
  114. html +=
  115. `<div style="margin-bottom:1.25rem;">${jsonObj.p[i]}</div>`;
  116. } else if (/^&tableTemp.*/.test(jsonObj.p[i])) {
  117. let tableTemp = jsonObj.p[i].split("-")[1];
  118. if (!tableTemp) {
  119. continue;
  120. }
  121. if (!jsonObj[tableTemp]) {
  122. continue;
  123. }
  124. let tableObj = jsonObj[tableTemp];
  125. if (JSON.stringify(tableObj) === '{}') {
  126. continue;
  127. }
  128. html +=
  129. `<table class="table ${tableObj.className||''}" style="${tableObj.style||''}" cellpadding="0" cellspacing="0">`;
  130. if (!!tableObj.tableTitle) {
  131. html += `<caption class="caption">${tableObj.tableTitle}</caption>`;
  132. }
  133. if (!!tableObj.cTitle) {
  134. html += `<caption class="caption secCaption cTitle">${tableObj.cTitle}</caption>`;
  135. }
  136. if (tableObj.tableHead.length) {
  137. html += `<thead class="thead">`;
  138. tableObj.tableHead.map((tr, trIndex) => {
  139. html += `<tr class="tr">`;
  140. let thList = tr.th;
  141. thList.map((item, index) => {
  142. html +=
  143. `<th class="th ${item instanceof Array ? 'slash-wrap':''}" style="${tr.style && tr.style[index]||''}" colspan="${tr.colSpan&&tr.colSpan[index]||1}" rowspan="${tr.rowSpan&&tr.rowSpan[index]||1}">`;
  144. if (item instanceof Array) {
  145. item.map((itemLi, liIndex) => {
  146. if (itemLi === "|") {
  147. html += `<span class="slash"></span>`
  148. } else {
  149. html +=
  150. `<span class="${liIndex===0?'left':'right'}" style="${liIndex===0?tr.slash&&tr.slash.leftText||'':tr.slash&&tr.slash.rightText||''}">${itemLi}</span>`
  151. }
  152. })
  153. } else {
  154. html += `${item}`;
  155. }
  156. html += '</th>';
  157. })
  158. html += `</tr>`;
  159. })
  160. html += `</thead>`;
  161. }
  162. if (tableObj.tableBody.length) {
  163. html += `<tbody class="tbody">`;
  164. tableObj.tableBody.map(tr => {
  165. let tdList = tr.td;
  166. html += `<tr class="tr">`;
  167. tdList.length && tdList.map((liDom, index) => {
  168. html +=
  169. `<td class="td" style="${tr.style&&tr.style[index]||''}" colspan="${tr.colSpan&&tr.colSpan[index]||1}" rowspan="${tr.rowSpan&&tr.rowSpan[index]||1}">${liDom}</td>`;
  170. })
  171. html += "</tr>"
  172. })
  173. html += `</tbody>`
  174. }
  175. html += `</table>`;
  176. } else {
  177. html +=
  178. `<p class="colorStyle" style="font-size:${fontSize}rem;color:${fontColor};text-align:${jsonObj.p[i].substr(0, 6) === 'pStart' ? 'start' : 'justify'}">${jsonObj.p[i].replace("pStart", '')}</p>`;
  179. }
  180. }
  181. }
  182. html = html.replace("##", )
  183. return html;
  184. }
  185. return function(data) { //返回 渲染后的结果data:解密后的json数据
  186. container.html(ParseChapterData(data));
  187. //设置斜线
  188. setSlash()
  189. }
  190. }
  191. function ReaderMuluFrame(container, flag) { //目录UI渲染层
  192. function ParseChapterMuluData(jsonData) { //生成要展示的 html文本
  193. let mulu = '';
  194. for (let i = 0; i < jsonData.length; i++) {
  195. let jsonObj = jsonData[i];
  196. if (jsonObj.children) {
  197. mulu +=
  198. `<li class="mui-table-view-cell mui-collapse parentLi"><a class="mui-navigate-right list-li-a" data-cid="${jsonObj.chapter_id}" data-fid="${jsonObj.file_id}" href="#">${jsonObj.title}</a><ul class="mui-table-view mui-table-view-chevron">`;
  199. for (let k = 0; k < jsonObj.children.length; k++) {
  200. mulu += `<li class="mui-table-view-cell"><a class="mui-navigate-right list-li-a" data-cid="${jsonObj.children[k].chapter_id}" data-fid="${jsonObj.children[k].file_id}" href="#">
  201. ${jsonObj.children[k].title}</a></li>`;
  202. }
  203. mulu += '</ul></li>';
  204. } else {
  205. mulu += `<li class="mui-table-view-cell parentLi"><a class="mui-navigate-right list-li-a" data-cid="${jsonObj.chapter_id}" data-cid="${jsonObj.file_id}" href="#">${jsonObj.title}
  206. </a></li>`;
  207. }
  208. }
  209. mulu = mulu.replace("##", );
  210. return mulu;
  211. }
  212. return function(data) { //返回 渲染后的结果data:解密后的json数据
  213. container.html(ParseChapterMuluData(data));
  214. }
  215. }
  216. function ReaderModel() { //数据交互层
  217. //todo 获取章节信息
  218. var init = function(Uicallback) { //初始化 信息
  219. getFictionInfo(function(mulu) {
  220. getCurChaptInfo(Chapter_id, function(data) {
  221. //todo
  222. Uicallback && Uicallback(data, mulu);
  223. })
  224. })
  225. };
  226. var getFictionInfo = function(callback) { //获取所有章节摘要信息
  227. $.get('data/chapter.json', function(data) {
  228. //todo 获取章节信息之后的回调
  229. Chapter_id = parseInt(Util.StorageGetter("ChapterId"));
  230. File_id = parseInt(Util.StorageGetter("FileId"));
  231. //选择是否从头阅读
  232. if (Chapter_id !== 0) {
  233. if (confirm('您要继续上次的阅读么?')) {} else {
  234. Chapter_id = 0;
  235. }
  236. }
  237. let list = data.chapters;
  238. for (let i = 0; i < list.length; i++) {
  239. if (!isFinite(Chapter_id) && list[i].type !== 'file') {
  240. Chapter_id = list[i].chapter_id;
  241. File_id = list[i].file_id;
  242. }
  243. if (list[i].children) {
  244. ChapterTotal += list[i].children.length;
  245. if (!isFinite(Chapter_id)) {
  246. Chapter_id = list[i].children[0].chapter_id;
  247. File_id = list[i].children[0].file_id;
  248. }
  249. } else if (list[i].type === 'chapter') {
  250. ChapterTotal += 1;
  251. }
  252. }
  253. callback && callback(list);
  254. }, 'json');
  255. };
  256. var getCurChaptInfo = function(Chapter_id, callback) { //获取当前Chapter_id章节详细信息
  257. // $.get('data/data' + Chapter_id + '.json', function(data,status) {
  258. // //todo 获取详细信息之后的回调
  259. // console.log(status,'status')
  260. // if (data.result == 0) {
  261. // // var url=data.jsonp;
  262. // // Util.getJsonp(url,function(data){
  263. // callback && callback(data);
  264. // $("#ChapterTitle").text(data.ct);
  265. // // });//通过url来获取加密信息,并解密
  266. // }
  267. // }, 'json');
  268. $.getJSON('data/data' + Chapter_id + '.json')
  269. .done(function(data) {
  270. // 请求成功,文件存在
  271. // console.log("文件存在", data);
  272. if (data.result == 0) {
  273. callback && callback(data);
  274. }
  275. })
  276. .fail(function(jqXHR, textStatus, errorThrown) {
  277. // console.log("文件不存在",jqXHR);
  278. callback && callback({
  279. p: [],
  280. t: "",
  281. result: 0
  282. });
  283. // 请求出错,文件不存在
  284. // if (jqXHR.status === 404) {
  285. // console.log("文件不存在");
  286. // } else {
  287. // console.log("请求出错");
  288. // }
  289. });
  290. };
  291. var prveChapter = function() { //上一页
  292. Chapter_id = parseInt(Chapter_id);
  293. if (Chapter_id == 0) {
  294. return;
  295. }
  296. Chapter_id -= 1;
  297. //调用方法获取 Chapter_id章节信息
  298. getCurChaptInfo(Chapter_id, function(data) {
  299. readerUIFrame(data); //渲染html数据
  300. });
  301. Util.StorageSetter("ChapterId", Chapter_id);
  302. //
  303. updateFileId()
  304. };
  305. var nextChapter = function() { //下一页
  306. Chapter_id = parseInt(Chapter_id);
  307. if (Chapter_id == ChapterTotal - 1) {
  308. return;
  309. }
  310. Chapter_id += 1;
  311. //调用方法获取 Chapter_id章节信息
  312. getCurChaptInfo(Chapter_id, function(data) {
  313. readerUIFrame(data);
  314. });
  315. Util.StorageSetter("ChapterId", Chapter_id);
  316. //
  317. updateFileId()
  318. };
  319. var jumpChapter = function() { //跳页
  320. Chapter_id = parseInt(Chapter_id);
  321. File_id = parseInt(File_id);
  322. //调用方法获取 Chapter_id章节信息
  323. getCurChaptInfo(Chapter_id, function(data) {
  324. readerUIFrame(data); //渲染html数据
  325. });
  326. Util.StorageSetter("ChapterId", Chapter_id);
  327. updateFileId()
  328. };
  329. var updateFileId = function() { //更新目录一级 file_id
  330. for (let item of ChapterList) {
  331. if (item.type === 'file') {
  332. let obj = item.children.find(child => child.chapter_id == Chapter_id);
  333. if (obj) {
  334. File_id = obj.file_id;
  335. $("#ChapterTitle").text(obj.cTitle);
  336. break;
  337. }
  338. continue;
  339. }
  340. if (Chapter_id === item.chapter_id) {
  341. File_id = item.file_id;
  342. $("#ChapterTitle").text(item.cTitle);
  343. break;
  344. }
  345. }
  346. Util.StorageSetter("FileId", File_id);
  347. }
  348. return {
  349. init: init,
  350. prveChapter: prveChapter,
  351. nextChapter: nextChapter,
  352. jumpChapter: jumpChapter,
  353. }
  354. }
  355. function EventHandler() { //业务事件处理层
  356. //点击主体中间事件
  357. // $("#action_mid").click(function() {
  358. // if (Dom.nav_top.css('display') == "none") {
  359. // actNavDialog(true)
  360. // } else {
  361. // actAllDialog(false)
  362. // }
  363. // });
  364. //=============
  365. let upperElement = document.getElementById('upperElement')
  366. upperElement.addEventListener('click', function(event) {
  367. var target = event.target;
  368. if (['btn_next', 'btn_prev'].includes(target.id)) {
  369. } else {
  370. if (Dom.nav_top.css('display') == "none") {
  371. actNavDialog(true)
  372. } else {
  373. actAllDialog(false)
  374. }
  375. }
  376. // 判断事件触发的源元素是上层元素还是下层元素
  377. // if (target.id === 'lowerElement') {
  378. // // 如果是下层元素,则触发下层元素的事件
  379. // console.log('下层元素的事件被触发');
  380. // // 实现下层元素的事件处理逻辑
  381. // } else {
  382. // // 如果是上层元素,则触发上层元素的事件
  383. // console.log('上层元素的事件被触发');
  384. // // 实现上层元素的事件处理逻辑
  385. // }
  386. });
  387. //=============
  388. //点击返回事件
  389. $(".nav_back_book").click(function() {
  390. Chapter_id = parseInt(Chapter_id);
  391. if (Chapter_id == 0) {
  392. return;
  393. }
  394. if (Dom.nav_top.css('display') == "none") {
  395. return;
  396. }
  397. Chapter_id = 0;
  398. readerm.jumpChapter();
  399. });
  400. //点击目录事件--顶部浮窗
  401. $("#topMulu").click(function() {
  402. muluShow("top")
  403. });
  404. //点击目录事件--底部导航
  405. $("#icon_mulu").click(function() {
  406. muluShow()
  407. });
  408. var muluShow = function(type) {
  409. Dom.icon_extra.removeClass("act");
  410. if (Dom.mulu_Box.css('display') == 'none') {
  411. $('body,html').addClass('notScroll');
  412. Dom.mulu_Box.show();
  413. if (type === 'top') {
  414. Dom.mulu_Box.css("bottom", 0)
  415. } else {
  416. Dom.mulu_Box.css("bottom", 70)
  417. }
  418. Dom.nav_top.hide();
  419. Dom.mulu_Mask.show();
  420. Dom.mulu_Cons.show();
  421. //章节总数赋值
  422. $('#ChapterTotal').text(ChapterTotal)
  423. //给当前选中章节高亮
  424. $(".mui-active").removeClass("mui-active");
  425. $(".highChapter").removeClass("highChapter");
  426. let optDom = $(".parentLi")[File_id];
  427. $(optDom).addClass("mui-active");
  428. $($(optDom).find("a")).each((i, aNode) => {
  429. if ($(aNode).data('cid') == Chapter_id) {
  430. $(aNode).addClass("highChapter")
  431. }
  432. })
  433. } else {
  434. muluUpdateActive();
  435. actMuluDialog(false);
  436. }
  437. $("#muluList,#muluList .mui-table-view,.list-li-a,.mui-table-view-cell>a:not(.mui-btn).mui-active").css(
  438. 'background-color', bgColor);
  439. actFontDialog(false)
  440. actExtraDialog(false);
  441. }
  442. //点击目录列表进行指定跳转
  443. Dom.muluList.on("click", function(e) {
  444. let cid = $(e.target).data('cid');
  445. if (cid === undefined || cid === null || cid === "") {
  446. return
  447. }
  448. Chapter_id = cid;
  449. File_id = $(e.target).data('fid');
  450. let cSpan = $(e.target).parent().parent("ul").prev();
  451. let cTitle = cSpan[0] ? cSpan[0].text : e.target.text;
  452. $("#ChapterTitle").text(cTitle);
  453. muluUpdateActive();
  454. readerm.jumpChapter();
  455. actAllDialog(false)
  456. window.scrollTo(0, 0);
  457. })
  458. // 点击弹窗内容以外的地方关闭弹窗
  459. $("#mulu_Mask").on('click', function(e) {
  460. // if ($(e.target).closest('#mui-content').length > 0) {
  461. // console.log('弹出框内部被点击了');
  462. // } else {
  463. // console.log('弹出框以外的部分被点击了');
  464. // 关闭弹框
  465. actAllDialog(false)
  466. // }
  467. });
  468. //点击字号事件
  469. $(".btn_Aa").click(function() {
  470. Dom.icon_extra.removeClass("act");
  471. if (Dom.font_Pop.css('display') == 'none') {
  472. Dom.font_Pop.show();
  473. Dom.slider.val(fontSize);
  474. } else {
  475. Dom.font_Pop.hide();
  476. }
  477. actMuluDialog(false);
  478. actExtraDialog(false);
  479. });
  480. //滚动条事件
  481. Dom.win.scroll(function() {
  482. actAllDialog(false)
  483. })
  484. //点击字体大小事件
  485. Dom.slider.change(function() {
  486. let NowFontSize = Number($(this).val());
  487. if (NowFontSize > 24 || NowFontSize < 16) {
  488. return;
  489. }
  490. $("p").css('font-size', NowFontSize / 16 + 'rem');
  491. $("h6").css('font-size', NowFontSize / 16 + 'rem');
  492. $("h4").css('font-size', (NowFontSize + 6) / 16 + 'rem');
  493. $("h5").css('font-size', (NowFontSize + 2) / 16 + 'rem');
  494. Util.StorageSetter("font_size", NowFontSize);
  495. });
  496. //点击其他事件
  497. $(".btn-extra").click(function() {
  498. Dom.icon_extra.addClass("act");
  499. if (Dom.extra_Pop.css('display') == 'none') {
  500. Dom.extra_Pop.show();
  501. if (bgColor) {
  502. $(".bk-item").each((i, liDom) => {
  503. let nodeSpan = $($(liDom).find(".bk-container"));
  504. nodeSpan.removeClass("bk-container-current")
  505. let itembg = nodeSpan[0].style.backgroundColor;
  506. if (itembg === bgColor) {
  507. nodeSpan.addClass("bk-container-current")
  508. }
  509. })
  510. }
  511. } else {
  512. Dom.extra_Pop.hide();
  513. }
  514. actMuluDialog(false);
  515. actFontDialog(false);
  516. });
  517. //点击背景颜色切换
  518. Dom.bkList.on("click", function(e) {
  519. if (!$(e.target).hasClass("bk-container")) {
  520. return
  521. }
  522. bgColor = $(e.target)[0].style.backgroundColor;
  523. updateBgColor($(e.target), "bgCheck")
  524. })
  525. //更新颜色设置的选中效果
  526. var updateBgColor = function(target, type) {
  527. $(target).addClass("bk-container-current");
  528. let optDom = $(target).parent(".bk-item").siblings();
  529. $(optDom).each((i, liDom) => {
  530. $($(liDom).find(".bk-container")).removeClass("bk-container-current")
  531. })
  532. let isDark = bgColor === 'rgb(40, 53, 72)';
  533. fontColor = isDark ? "#f8f8f8" : "#000000";
  534. setHtmlStyle();
  535. Util.StorageSetter("bgColor", bgColor);
  536. //更新图标
  537. Dom.icon_extra.removeClass().addClass(
  538. `bottom-icon act ${isDark ? "dark-icon-extra" : "light-icon-extra"}`);
  539. Dom.icon_Aa.removeClass().addClass(`bottom-icon ${isDark ? "dark-icon-Aa" : "light-icon-Aa"}`);
  540. Dom.icon_mulu.removeClass().addClass(`bottom-icon ${isDark ? "dark-icon-mulu" : "light-icon-mulu"}`);
  541. }
  542. $("#btn_prev").click(function() {
  543. window.scrollTo(0, 0);
  544. readerm.prveChapter();
  545. });
  546. $("#btn_next").click(function() {
  547. window.scrollTo(0, 0);
  548. readerm.nextChapter();
  549. });
  550. }
  551. //设置文本样式
  552. function setHtmlStyle() {
  553. Dom.body.css({
  554. 'background-color': bgColor,
  555. 'color': fontColor
  556. });
  557. $(".bgStyle").css('background-color', bgColor);
  558. $(".colorStyle").css('color', fontColor);
  559. let isDark = bgColor === 'rgb(40, 53, 72)';
  560. $("#topLeftIcon").removeClass().addClass(`top_left_icon ${isDark ? "dark-icon-mulu" : "light-icon-mulu"}`);
  561. $("#nav_icon").removeClass().addClass(
  562. `nav_return nav_back_book ${isDark ? "dark-icon-navleft" : "light-icon-navleft"}`);
  563. }
  564. //整体弹窗 展示控制
  565. function actAllDialog(flag) {
  566. actLightDialog(flag);
  567. actFontDialog(flag);
  568. actMuluDialog(flag);
  569. actNavDialog(flag);
  570. actExtraDialog(flag);
  571. }
  572. //光亮设置 展示控制
  573. function actLightDialog(flag) {
  574. //展示
  575. if (flag) {
  576. return
  577. }
  578. //隐藏
  579. }
  580. //字号设置 展示控制
  581. function actFontDialog(flag) {
  582. //展示
  583. if (flag) {
  584. let iconClass = bgColor === 'rgb(40, 53, 72)' ? "dark-icon-Aa" : "light-icon-Aa";
  585. Dom.icon_Aa.addClass(iconClass);
  586. return
  587. }
  588. //隐藏
  589. Dom.font_Pop.hide();
  590. }
  591. //目录设置 展示控制
  592. function actMuluDialog(flag) {
  593. //展示
  594. if (flag) {
  595. let iconClass = bgColor === 'rgb(40, 53, 72)' ? "dark-icon-mulu" : "light-icon-mulu";
  596. Dom.icon_mulu.addClass(iconClass);
  597. return
  598. }
  599. //隐藏
  600. Dom.mulu_Box.hide();
  601. Dom.mulu_Mask.hide();
  602. Dom.mulu_Cons.hide();
  603. $('body,html').removeClass('notScroll');
  604. }
  605. //其他设置 展示控制
  606. function actExtraDialog(flag) {
  607. //展示
  608. if (flag) {
  609. return
  610. }
  611. //隐藏
  612. Dom.extra_Pop.hide();
  613. }
  614. //顶部导航+底部导航 展示控制
  615. function actNavDialog(flag) {
  616. //展示
  617. if (flag) {
  618. Dom.nav_top.show();
  619. Dom.nav_bottom.show();
  620. let isDark = bgColor === 'rgb(40, 53, 72)';
  621. Dom.icon_extra.addClass(`${isDark ? "dark-icon-extra" : "light-icon-extra"}`);
  622. Dom.icon_Aa.addClass(`${isDark ? "dark-icon-Aa" : "light-icon-Aa"}`);
  623. Dom.icon_mulu.addClass(`${isDark ? "dark-icon-mulu" : "light-icon-mulu"}`);
  624. return
  625. }
  626. //隐藏
  627. Dom.nav_top.hide();
  628. Dom.nav_bottom.hide();
  629. Dom.icon_extra.removeClass().addClass("bottom-icon");
  630. Dom.icon_Aa.removeClass().addClass("bottom-icon");
  631. Dom.icon_mulu.removeClass().addClass("bottom-icon");
  632. }
  633. //给当前选中章节高亮,去掉其他
  634. function muluUpdateActive() {
  635. $(".parentLi").each((i, liDom) => {
  636. $($(liDom).find("a")).each((i, aNode) => {
  637. if ($(aNode).data('fid') == File_id) {
  638. $(liDom).addClass("mui-active")
  639. } else {
  640. $(liDom).removeClass("mui-active")
  641. }
  642. if ($(aNode).data('cid') == Chapter_id) {
  643. $(aNode).addClass("highChapter")
  644. } else {
  645. $(aNode).removeClass("highChapter")
  646. }
  647. })
  648. })
  649. }
  650. //设置斜线
  651. function setSlash() {
  652. let hasSlash = $('span').is(".slash");
  653. if (!hasSlash) return;
  654. //
  655. $('.slash-wrap').each((i, ele) => {
  656. /* 斜边边长 */
  657. /* Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) */
  658. let width = $(ele).outerWidth();
  659. let height = $(ele).parents('.thead').outerHeight();
  660. let slashWidth = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
  661. /* 旋转角度计算公式 */
  662. /* Math.atan(height / width) * 180 / Math.PI */
  663. let transformRole = Math.atan(height / width) * 180 / Math.PI;
  664. $(ele).find(".slash").css({
  665. width: slashWidth,
  666. transform: `rotate(${transformRole}deg)`
  667. })
  668. })
  669. }
  670. //监听屏幕宽度
  671. const getWindowInfo = () => {
  672. const windowInfo = {
  673. width: window.innerWidth,
  674. hight: window.innerHeight
  675. }
  676. // console.log(windowInfo,'===========上次的',beginWid);
  677. if (windowInfo.width !== beginWid) {
  678. setSlash()
  679. }
  680. };
  681. //防抖
  682. const debounce = (fn, delay) => {
  683. let timer;
  684. return function() {
  685. if (timer) {
  686. clearTimeout(timer);
  687. }
  688. timer = setTimeout(() => {
  689. fn();
  690. }, delay);
  691. }
  692. };
  693. const cancalDebounce = debounce(getWindowInfo, 500);
  694. window.addEventListener('resize', cancalDebounce);