bookdetail.js 22 KB

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