index.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?PHP
  2. include "../pcdl/html_head.php";
  3. ?>
  4. <body>
  5. <?php
  6. require_once("../pcdl/head_bar.php");
  7. ?>
  8. <style>
  9. #main_video_win iframe{
  10. width:100%;
  11. height:100%;
  12. }
  13. #main_tag span{
  14. margin: 2px;
  15. padding: 2px 12px;
  16. font-weight: 500;
  17. transition-duration: 0.2s;
  18. cursor: pointer;
  19. display: inline-flex;
  20. align-items: center;
  21. flex-wrap: nowrap;
  22. justify-content: center;
  23. font-size:110%;
  24. border: unset;
  25. border-radius: 0;
  26. border-bottom: 2px solid var(--nocolor);
  27. }
  28. #main_tag span:hover{
  29. background-color:unset;
  30. color:unset;
  31. border-color: var(--link-hover-color);
  32. }
  33. #main_tag .select{
  34. border-bottom: 2px solid var(--link-color);
  35. }
  36. </style>
  37. <?php
  38. //
  39. require_once "../path.php";
  40. require_once "../public/_pdo.php";
  41. require_once '../media/function.php';
  42. require_once '../public/function.php';
  43. echo "<div id='course_head_bar' style='background-color:var(--tool-bg-color1);padding:1em 10px 10px 10px;'>";
  44. echo "<div class='index_inner '>";
  45. echo "<div style='font-size:140%'>";
  46. echo "</div>";
  47. echo '<div id="main_tag" style="">';
  48. echo '<span tag="sutta">Sutta</span><span tag="vinaya">Vinaya</span><span tag="abhidhamma">Abhidhamma</span>';
  49. echo '<span tag="mula">Mula</span><span tag="atthakatha">Aṭṭhakathā</span><span tag="tika">ṭīkā</span><span tag="anna">anna</span>';
  50. echo '</div>';
  51. echo '<div id="tag_selected" class="summary" style="padding-bottom:5px;"></div>';
  52. echo '<div id="tag_others" class="summary" style="padding-bottom:5px;"></div>';
  53. echo "</div>";
  54. echo '</div>';
  55. ?>
  56. <div id ="book_list" class='index_inner' style='display: flex;flex-wrap: wrap;'>
  57. </div>
  58. <script>
  59. var main_tag="";
  60. var list_tag=new Array();
  61. $("span[tag]").click(function(){
  62. $(this).siblings().removeClass("select");
  63. $(this).addClass("select");
  64. main_tag = $(this).attr("tag");
  65. list_tag=new Array();
  66. tag_changed();
  67. render_tag_list();
  68. /*
  69. const tagSelected = document.getElementsByClassName("select");
  70. if(tagSelected){
  71. let tagList = new Array();
  72. for (const iterator of tagSelected) {
  73. tagList.push(iterator.getAttributeNode("tag").value);
  74. }
  75. main_tag = tagList[0];
  76. tag_changed();
  77. }
  78. */
  79. });
  80. function tag_changed(){
  81. let strTags = "";
  82. if(list_tag.length>0){
  83. strTags = main_tag + "," + list_tag.join();
  84. }
  85. else{
  86. strTags = main_tag;
  87. }
  88. console.log(strTags);
  89. $.get("book_tag.php",
  90. {
  91. tag:strTags
  92. },
  93. function(data,status){
  94. let arrBookList = JSON.parse(data);
  95. let html="";
  96. let allTags = new Array();
  97. for (const iterator of arrBookList) {
  98. html += "<div style='width:25%;padding:0.5em;'>";
  99. html += "<div class='card' style='padding:10px;'>";
  100. html += "<div style='font-weight:700'>"+iterator[0].title+"</div>";
  101. html += "</div>";
  102. html += "</div>";
  103. let tags = iterator[0].tag.split("::");
  104. let currTag = new Array();
  105. currTag[main_tag] = 1;
  106. for (const scondTag of list_tag) {
  107. currTag[scondTag] = 1;
  108. }
  109. for (let tag of tags) {
  110. if(tag.slice(0,1)==":"){
  111. tag = tag.slice(1);
  112. }
  113. if(tag.slice(-1)==":"){
  114. tag = tag.slice(0,-1);
  115. }
  116. if(!currTag.hasOwnProperty(tag)){
  117. if(allTags.hasOwnProperty(tag) ){
  118. allTags[tag] += 1;
  119. }
  120. else{
  121. allTags[tag] = 1;
  122. }
  123. }
  124. }
  125. }
  126. $("#book_list").html(html);
  127. let strOthersTag = "";
  128. for (const key in allTags) {
  129. if (allTags.hasOwnProperty(key)) {
  130. strOthersTag += "<button onclick =\"tag_click('"+key+"')\" >"+key+"</button>";
  131. }
  132. }
  133. $("#tag_others").html(strOthersTag);
  134. });
  135. }
  136. function tag_click(tag){
  137. list_tag.push(tag);
  138. render_tag_list();
  139. let strTag = main_tag + "," + list_tag.join();
  140. tag_changed();
  141. }
  142. function render_tag_list(){
  143. let strListTag = "已经选择:";
  144. for (const iterator of list_tag) {
  145. strListTag +="<button >"+iterator+"<span onclick =\"tag_remove('"+iterator+"')\">X</span></button>";
  146. }
  147. $("#tag_selected").html(strListTag);
  148. }
  149. function tag_remove(tag){
  150. for(let i=0; i<list_tag.length;i++){
  151. if(list_tag[i]==tag){
  152. list_tag.splice(i,1);
  153. }
  154. }
  155. render_tag_list();
  156. tag_changed();
  157. }
  158. </script>
  159. <?php
  160. include "../pcdl/html_foot.php";
  161. ?>