bookdetail.html 26 KB

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