bookdetail.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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. // 封面-0,扉页-1 不需要展示章节名称
  235. if(!['0','1'].includes(Chapter_id+'')){
  236. html += `<br/><br/><br/>`;
  237. if (jsonObj.ct && jsonObj.ct !== jsonObj.t) {
  238. html += `<h3 style=font-size:${fontSizeAdd6};color:${fontColor}">${jsonObj.ct}</h3><br/>`;
  239. }
  240. html += `<h4 style=font-size:${fontSizeAdd6};color:${fontColor}">${jsonObj.t}</h4>`;
  241. }
  242. //正文内容
  243. for (let i = 0; i < jsonObj.p.length; i++) {
  244. if (Chapter_id == 0) {
  245. html += "<div>" + jsonObj.p[i] + "</div>";
  246. } else {
  247. if (/^##.*/.test(jsonObj.p[i])) {
  248. html +=
  249. `<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>`;
  250. } else if (/^#.*/.test(jsonObj.p[i])) {
  251. html +=
  252. `<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>`;
  253. } else if (/^\<img.*/.test(jsonObj.p[i])) {
  254. html +=
  255. `<div style="margin-bottom:1.25rem;">${jsonObj.p[i]}</div>`;
  256. } else if (/^&tableTemp.*/.test(jsonObj.p[i])) {
  257. let tableTemp = jsonObj.p[i].split("-")[1];
  258. if(!tableTemp){
  259. continue;
  260. }
  261. if(!jsonObj[tableTemp]){
  262. continue;
  263. }
  264. let tableObj = jsonObj[tableTemp];
  265. if (JSON.stringify(tableObj) === '{}') {
  266. continue;
  267. }
  268. html +=
  269. `<table class="table ${tableObj.className||''}" style="${tableObj.style||''}" cellpadding="0" cellspacing="0">`;
  270. if (!!tableObj.tableTitle) {
  271. html += `<caption class="caption">${tableObj.tableTitle}</caption>`;
  272. }
  273. if (!!tableObj.cTitle) {
  274. html += `<caption class="caption secCaption cTitle">${tableObj.cTitle}</caption>`;
  275. }
  276. if (tableObj.tableHead.length) {
  277. html += `<thead class="thead">`;
  278. tableObj.tableHead.map((tr, trIndex) => {
  279. html += `<tr class="tr">`;
  280. let thList = tr.th;
  281. thList.map((item, index) => {
  282. html +=
  283. `<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}">`;
  284. if (item instanceof Array) {
  285. item.map((itemLi, liIndex) => {
  286. if (itemLi === "|") {
  287. html += `<span class="slash"></span>`
  288. } else {
  289. html +=
  290. `<span class="${liIndex===0?'left':'right'}" style="${liIndex===0?tr.slash&&tr.slash.leftText||'':tr.slash&&tr.slash.rightText||''}">${itemLi}</span>`
  291. }
  292. })
  293. } else {
  294. html += `${item}`;
  295. }
  296. html += '</th>';
  297. })
  298. html += `</tr>`;
  299. })
  300. html += `</thead>`;
  301. }
  302. if (tableObj.tableBody.length) {
  303. html += `<tbody class="tbody">`;
  304. tableObj.tableBody.map(tr => {
  305. let tdList = tr.td;
  306. html += `<tr class="tr">`;
  307. tdList.length && tdList.map((liDom, index) => {
  308. html +=
  309. `<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>`;
  310. })
  311. html += "</tr>"
  312. })
  313. html += `</tbody>`
  314. }
  315. html += `</table>`;
  316. } else {
  317. html +=
  318. `<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>`;
  319. }
  320. }
  321. }
  322. html = html.replace("##", )
  323. return html;
  324. }
  325. return function(data) { //返回 渲染后的结果data:解密后的json数据
  326. container.html(ParseChapterData(data));
  327. //设置斜线
  328. let hasSlash = $('span').is(".slash");
  329. if (!hasSlash) return;
  330. //
  331. $('.slash-wrap').each((i, ele) => {
  332. /* 斜边边长 */
  333. /* Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) */
  334. let width = $(ele).outerWidth();
  335. let height = $(ele).parents('.thead').outerHeight();
  336. let slashWidth = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
  337. /* 旋转角度计算公式 */
  338. /* Math.atan(height / width) * 180 / Math.PI */
  339. let transformRole = Math.atan(height / width) * 180 / Math.PI;
  340. $(ele).find(".slash").css({
  341. width: slashWidth,
  342. transform: `rotate(${transformRole}deg)`
  343. })
  344. })
  345. }
  346. }
  347. function ReaderMuluFrame(container, flag) { //目录UI渲染层
  348. function ParseChapterMuluData(jsonData) { //生成要展示的 html文本
  349. let mulu = '';
  350. for (let i = 0; i < jsonData.length; i++) {
  351. let jsonObj = jsonData[i];
  352. if (jsonObj.children) {
  353. mulu +=
  354. `<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">`;
  355. for (let k = 0; k < jsonObj.children.length; k++) {
  356. 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="#">
  357. ${jsonObj.children[k].title}</a></li>`;
  358. }
  359. mulu += '</ul></li>';
  360. } else {
  361. 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}
  362. </a></li>`;
  363. }
  364. }
  365. mulu = mulu.replace("##", );
  366. return mulu;
  367. }
  368. return function(data) { //返回 渲染后的结果data:解密后的json数据
  369. container.html(ParseChapterMuluData(data));
  370. }
  371. }
  372. function ReaderModel() { //数据交互层
  373. //todo 获取章节信息
  374. var init = function(Uicallback) { //初始化 信息
  375. getFictionInfo(function(mulu) {
  376. getCurChaptInfo(Chapter_id, function(data) {
  377. //todo
  378. Uicallback && Uicallback(data, mulu);
  379. })
  380. })
  381. };
  382. var getFictionInfo = function(callback) { //获取所有章节摘要信息
  383. $.get('data/chapter.json', function(data) {
  384. //todo 获取章节信息之后的回调
  385. Chapter_id = parseInt(Util.StorageGetter("ChapterId"));
  386. File_id = parseInt(Util.StorageGetter("FileId"));
  387. //选择是否从头阅读
  388. if (Chapter_id !== 0) {
  389. if (confirm('您要继续上次的阅读么?')) {} else {
  390. Chapter_id = 0;
  391. }
  392. }
  393. let list = data.chapters;
  394. for (let i = 0; i < list.length; i++) {
  395. if (!isFinite(Chapter_id) && list[i].type !== 'file') {
  396. Chapter_id = list[i].chapter_id;
  397. File_id = list[i].file_id;
  398. }
  399. if (list[i].children) {
  400. ChapterTotal += list[i].children.length;
  401. if (!isFinite(Chapter_id)) {
  402. Chapter_id = list[i].children[0].chapter_id;
  403. File_id = list[i].children[0].file_id;
  404. }
  405. } else if (list[i].type === 'chapter') {
  406. ChapterTotal += 1;
  407. }
  408. }
  409. callback && callback(list);
  410. }, 'json');
  411. };
  412. var getCurChaptInfo = function(Chapter_id, callback) { //获取当前Chapter_id章节详细信息
  413. // $.get('data/data' + Chapter_id + '.json', function(data,status) {
  414. // //todo 获取详细信息之后的回调
  415. // console.log(status,'status')
  416. // if (data.result == 0) {
  417. // // var url=data.jsonp;
  418. // // Util.getJsonp(url,function(data){
  419. // callback && callback(data);
  420. // $("#ChapterTitle").text(data.ct);
  421. // // });//通过url来获取加密信息,并解密
  422. // }
  423. // }, 'json');
  424. $.getJSON('data/data' + Chapter_id + '.json')
  425. .done(function(data) {
  426. // 请求成功,文件存在
  427. // console.log("文件存在", data);
  428. if (data.result == 0) {
  429. callback && callback(data);
  430. }
  431. })
  432. .fail(function(jqXHR, textStatus, errorThrown) {
  433. // console.log("文件不存在",jqXHR);
  434. callback && callback({
  435. p: [],
  436. t: "",
  437. result: 0
  438. });
  439. // 请求出错,文件不存在
  440. // if (jqXHR.status === 404) {
  441. // console.log("文件不存在");
  442. // } else {
  443. // console.log("请求出错");
  444. // }
  445. });
  446. };
  447. var prveChapter = function() { //上一页
  448. Chapter_id = parseInt(Chapter_id);
  449. if (Chapter_id == 0) {
  450. return;
  451. }
  452. Chapter_id -= 1;
  453. //调用方法获取 Chapter_id章节信息
  454. getCurChaptInfo(Chapter_id, function(data) {
  455. readerUIFrame(data); //渲染html数据
  456. });
  457. Util.StorageSetter("ChapterId", Chapter_id);
  458. //
  459. updateFileId()
  460. };
  461. var nextChapter = function() { //下一页
  462. Chapter_id = parseInt(Chapter_id);
  463. if (Chapter_id == ChapterTotal - 1) {
  464. return;
  465. }
  466. Chapter_id += 1;
  467. //调用方法获取 Chapter_id章节信息
  468. getCurChaptInfo(Chapter_id, function(data) {
  469. readerUIFrame(data);
  470. });
  471. Util.StorageSetter("ChapterId", Chapter_id);
  472. //
  473. updateFileId()
  474. };
  475. var jumpChapter = function() { //跳页
  476. Chapter_id = parseInt(Chapter_id);
  477. File_id = parseInt(File_id);
  478. //调用方法获取 Chapter_id章节信息
  479. getCurChaptInfo(Chapter_id, function(data) {
  480. readerUIFrame(data); //渲染html数据
  481. });
  482. Util.StorageSetter("ChapterId", Chapter_id);
  483. updateFileId()
  484. };
  485. var updateFileId = function() { //更新目录一级 file_id
  486. for (let item of ChapterList) {
  487. if (item.type === 'file') {
  488. let obj = item.children.find(child => child.chapter_id == Chapter_id);
  489. if (obj) {
  490. File_id = obj.file_id;
  491. $("#ChapterTitle").text(obj.cTitle);
  492. break;
  493. }
  494. continue;
  495. }
  496. if (Chapter_id === item.chapter_id) {
  497. File_id = item.file_id;
  498. $("#ChapterTitle").text(item.cTitle);
  499. break;
  500. }
  501. }
  502. Util.StorageSetter("FileId", File_id);
  503. }
  504. return {
  505. init: init,
  506. prveChapter: prveChapter,
  507. nextChapter: nextChapter,
  508. jumpChapter: jumpChapter,
  509. }
  510. }
  511. function EventHandler() { //业务事件处理层
  512. //点击主体中间事件
  513. $("#action_mid").click(function() {
  514. if (Dom.nav_top.css('display') == "none") {
  515. actNavDialog(true)
  516. } else {
  517. actAllDialog(false)
  518. }
  519. });
  520. //点击返回事件
  521. $(".nav_back_book").click(function() {
  522. Chapter_id = parseInt(Chapter_id);
  523. if (Chapter_id == 0) {
  524. return;
  525. }
  526. if (Dom.nav_top.css('display') == "none") {
  527. return;
  528. }
  529. Chapter_id = 0;
  530. readerm.jumpChapter();
  531. });
  532. //点击目录事件--顶部浮窗
  533. $("#topMulu").click(function() {
  534. muluShow("top")
  535. });
  536. //点击目录事件--底部导航
  537. $("#icon_mulu").click(function() {
  538. muluShow()
  539. });
  540. var muluShow = function(type) {
  541. Dom.icon_extra.removeClass("act");
  542. if (Dom.mulu_Box.css('display') == 'none') {
  543. $('body,html').addClass('notScroll');
  544. Dom.mulu_Box.show();
  545. if (type === 'top') {
  546. Dom.mulu_Box.css("bottom", 0)
  547. } else {
  548. Dom.mulu_Box.css("bottom", 70)
  549. }
  550. Dom.nav_top.hide();
  551. Dom.mulu_Mask.show();
  552. Dom.mulu_Cons.show();
  553. //章节总数赋值
  554. $('#ChapterTotal').text(ChapterTotal)
  555. //给当前选中章节高亮
  556. $(".mui-active").removeClass("mui-active");
  557. $(".highChapter").removeClass("highChapter");
  558. let optDom = $(".parentLi")[File_id];
  559. $(optDom).addClass("mui-active");
  560. $($(optDom).find("a")).each((i, aNode) => {
  561. if ($(aNode).data('cid') == Chapter_id) {
  562. $(aNode).addClass("highChapter")
  563. }
  564. })
  565. } else {
  566. muluUpdateActive();
  567. actMuluDialog(false);
  568. }
  569. $("#muluList,#muluList .mui-table-view,.list-li-a,.mui-table-view-cell>a:not(.mui-btn).mui-active").css(
  570. 'background-color', bgColor);
  571. actFontDialog(false)
  572. actExtraDialog(false);
  573. }
  574. //点击目录列表进行指定跳转
  575. Dom.muluList.on("click", function(e) {
  576. let cid = $(e.target).data('cid');
  577. if (cid === undefined || cid === null || cid === "") {
  578. return
  579. }
  580. Chapter_id = cid;
  581. File_id = $(e.target).data('fid');
  582. let cSpan = $(e.target).parent().parent("ul").prev();
  583. let cTitle = cSpan[0] ? cSpan[0].text : e.target.text;
  584. $("#ChapterTitle").text(cTitle);
  585. muluUpdateActive();
  586. readerm.jumpChapter();
  587. actAllDialog(false)
  588. window.scrollTo(0, 0);
  589. })
  590. // 点击弹窗内容以外的地方关闭弹窗
  591. $("#mulu_Mask").on('click', function(e) {
  592. // if ($(e.target).closest('#mui-content').length > 0) {
  593. // console.log('弹出框内部被点击了');
  594. // } else {
  595. // console.log('弹出框以外的部分被点击了');
  596. // 关闭弹框
  597. actAllDialog(false)
  598. // }
  599. });
  600. //点击字号事件
  601. $(".btn_Aa").click(function() {
  602. Dom.icon_extra.removeClass("act");
  603. if (Dom.font_Pop.css('display') == 'none') {
  604. Dom.font_Pop.show();
  605. Dom.slider.val(fontSize);
  606. } else {
  607. Dom.font_Pop.hide();
  608. }
  609. actMuluDialog(false);
  610. actExtraDialog(false);
  611. });
  612. //滚动条事件
  613. Dom.win.scroll(function() {
  614. actAllDialog(false)
  615. })
  616. //点击字体大小事件
  617. Dom.slider.change(function() {
  618. let NowFontSize = Number($(this).val());
  619. if (NowFontSize > 24 || NowFontSize < 16) {
  620. return;
  621. }
  622. $("p").css('font-size', NowFontSize / 16 + 'rem');
  623. $("h6").css('font-size', NowFontSize / 16 + 'rem');
  624. $("h4").css('font-size', (NowFontSize + 6) / 16 + 'rem');
  625. $("h5").css('font-size', (NowFontSize + 2) / 16 + 'rem');
  626. Util.StorageSetter("font_size", NowFontSize);
  627. });
  628. //点击其他事件
  629. $(".btn-extra").click(function() {
  630. Dom.icon_extra.addClass("act");
  631. if (Dom.extra_Pop.css('display') == 'none') {
  632. Dom.extra_Pop.show();
  633. if (bgColor) {
  634. $(".bk-item").each((i, liDom) => {
  635. let nodeSpan = $($(liDom).find(".bk-container"));
  636. nodeSpan.removeClass("bk-container-current")
  637. let itembg = nodeSpan[0].style.backgroundColor;
  638. if (itembg === bgColor) {
  639. nodeSpan.addClass("bk-container-current")
  640. }
  641. })
  642. }
  643. } else {
  644. Dom.extra_Pop.hide();
  645. }
  646. actMuluDialog(false);
  647. actFontDialog(false);
  648. });
  649. //点击背景颜色切换
  650. Dom.bkList.on("click", function(e) {
  651. if (!$(e.target).hasClass("bk-container")) {
  652. return
  653. }
  654. bgColor = $(e.target)[0].style.backgroundColor;
  655. updateBgColor($(e.target), "bgCheck")
  656. })
  657. //更新颜色设置的选中效果
  658. var updateBgColor = function(target, type) {
  659. $(target).addClass("bk-container-current");
  660. let optDom = $(target).parent(".bk-item").siblings();
  661. $(optDom).each((i, liDom) => {
  662. $($(liDom).find(".bk-container")).removeClass("bk-container-current")
  663. })
  664. let isDark = bgColor === 'rgb(40, 53, 72)';
  665. fontColor = isDark ? "#f8f8f8" : "#000000";
  666. setHtmlStyle();
  667. Util.StorageSetter("bgColor", bgColor);
  668. //更新图标
  669. Dom.icon_extra.removeClass().addClass(
  670. `bottom-icon act ${isDark ? "dark-icon-extra" : "light-icon-extra"}`);
  671. Dom.icon_Aa.removeClass().addClass(`bottom-icon ${isDark ? "dark-icon-Aa" : "light-icon-Aa"}`);
  672. Dom.icon_mulu.removeClass().addClass(`bottom-icon ${isDark ? "dark-icon-mulu" : "light-icon-mulu"}`);
  673. }
  674. $("#btn_prev").click(function() {
  675. window.scrollTo(0, 0);
  676. readerm.prveChapter();
  677. });
  678. $("#btn_next").click(function() {
  679. window.scrollTo(0, 0);
  680. readerm.nextChapter();
  681. });
  682. }
  683. //设置文本样式
  684. function setHtmlStyle() {
  685. Dom.body.css({
  686. 'background-color': bgColor,
  687. 'color': fontColor
  688. });
  689. $(".bgStyle").css('background-color', bgColor);
  690. $(".colorStyle").css('color', fontColor);
  691. let isDark = bgColor === 'rgb(40, 53, 72)';
  692. $("#topLeftIcon").removeClass().addClass(`top_left_icon ${isDark ? "dark-icon-mulu" : "light-icon-mulu"}`);
  693. $("#nav_icon").removeClass().addClass(
  694. `nav_return nav_back_book ${isDark ? "dark-icon-navleft" : "light-icon-navleft"}`);
  695. }
  696. //整体弹窗 展示控制
  697. function actAllDialog(flag) {
  698. actLightDialog(flag);
  699. actFontDialog(flag);
  700. actMuluDialog(flag);
  701. actNavDialog(flag);
  702. actExtraDialog(flag);
  703. }
  704. //光亮设置 展示控制
  705. function actLightDialog(flag) {
  706. //展示
  707. if (flag) {
  708. return
  709. }
  710. //隐藏
  711. }
  712. //字号设置 展示控制
  713. function actFontDialog(flag) {
  714. //展示
  715. if (flag) {
  716. let iconClass = bgColor === 'rgb(40, 53, 72)' ? "dark-icon-Aa" : "light-icon-Aa";
  717. Dom.icon_Aa.addClass(iconClass);
  718. return
  719. }
  720. //隐藏
  721. Dom.font_Pop.hide();
  722. }
  723. //目录设置 展示控制
  724. function actMuluDialog(flag) {
  725. //展示
  726. if (flag) {
  727. let iconClass = bgColor === 'rgb(40, 53, 72)' ? "dark-icon-mulu" : "light-icon-mulu";
  728. Dom.icon_mulu.addClass(iconClass);
  729. return
  730. }
  731. //隐藏
  732. Dom.mulu_Box.hide();
  733. Dom.mulu_Mask.hide();
  734. Dom.mulu_Cons.hide();
  735. $('body,html').removeClass('notScroll');
  736. }
  737. //其他设置 展示控制
  738. function actExtraDialog(flag) {
  739. //展示
  740. if (flag) {
  741. return
  742. }
  743. //隐藏
  744. Dom.extra_Pop.hide();
  745. }
  746. //顶部导航+底部导航 展示控制
  747. function actNavDialog(flag) {
  748. //展示
  749. if (flag) {
  750. Dom.nav_top.show();
  751. Dom.nav_bottom.show();
  752. let isDark = bgColor === 'rgb(40, 53, 72)';
  753. Dom.icon_extra.addClass(`${isDark ? "dark-icon-extra" : "light-icon-extra"}`);
  754. Dom.icon_Aa.addClass(`${isDark ? "dark-icon-Aa" : "light-icon-Aa"}`);
  755. Dom.icon_mulu.addClass(`${isDark ? "dark-icon-mulu" : "light-icon-mulu"}`);
  756. return
  757. }
  758. //隐藏
  759. Dom.nav_top.hide();
  760. Dom.nav_bottom.hide();
  761. Dom.icon_extra.removeClass().addClass("bottom-icon");
  762. Dom.icon_Aa.removeClass().addClass("bottom-icon");
  763. Dom.icon_mulu.removeClass().addClass("bottom-icon");
  764. }
  765. //给当前选中章节高亮,去掉其他
  766. function muluUpdateActive() {
  767. $(".parentLi").each((i, liDom) => {
  768. $($(liDom).find("a")).each((i, aNode) => {
  769. if ($(aNode).data('fid') == File_id) {
  770. $(liDom).addClass("mui-active")
  771. } else {
  772. $(liDom).removeClass("mui-active")
  773. }
  774. if ($(aNode).data('cid') == Chapter_id) {
  775. $(aNode).addClass("highChapter")
  776. } else {
  777. $(aNode).removeClass("highChapter")
  778. }
  779. })
  780. })
  781. }
  782. </script>
  783. </body>
  784. </html>