video-list.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. $(document).ready(function () {
  2. if (folderFromVideoPlay != "") {
  3. initList(folderFromVideoPlay);
  4. } else {
  5. initList("videos");
  6. }
  7. });
  8. function initList(dir) {
  9. $.ajax({
  10. url: "./script/php/video/getDir.php",
  11. type: "POST",
  12. data: {
  13. dir: dir,
  14. },
  15. dataType: "json"
  16. }).done(function (result) {
  17. if (result["parent"] != undefined) {
  18. $("#video-list").empty();
  19. dir_names = result["dir_names"];
  20. file_tables = result["file_tables"];
  21. parent = result["parent"];
  22. //directory
  23. for (i = 0; i < dir_names.length; i++) {
  24. $("#video-list").append('<div class="col-md-3">' +
  25. '<section class="panel">' +
  26. "<a href='#' onclick='initList(\"" + dir_names[i]["dir_name"] + "\")'>" +
  27. '<img class="video-active" src="/Common/assets/images/folder-icon.png">' +
  28. '</a>' +
  29. '<div class="panel-body" id="">' +
  30. '<div class="video-text">' +
  31. "<p style='font-size: 20px;'><i class='fa fa-folder'></i><a class='video-font' href='#' onclick='initList(\"" + dir_names[i]["dir_name"] + "\")'>" + dir_names[i]["dir_name"] + "</a></p>" +
  32. '</div>' +
  33. '</div>' +
  34. '</section>' +
  35. '</div>');
  36. }
  37. //video
  38. for (j = 0; j < file_tables.length; j++) {
  39. if (file_tables[j]["file_path"].includes(".m3u8")) {
  40. $("#video-list").append('<div class="col-md-3">' +
  41. '<section class="panel">' +
  42. "<a href='#' onclick='getVideo(" + file_tables[j]["id"] + ",\"" + file_tables[j]["file_path"].split("/")[file_tables[j]["file_path"].split("/").length - 2] + "\")'>" +
  43. '<img style="aspect-ratio: 4/3;" class="video-static" src="' + file_tables[j]["file_path"].replace("m3u8", "jpg") + '">' +
  44. '<img style="aspect-ratio: 4/3;" class="video-active" src="' + file_tables[j]["file_path"].replace("m3u8", "gif") +
  45. '">' +
  46. '</a>' +
  47. '<div class="panel-body" id="">' +
  48. '<div class="video-text">' +
  49. "<p style='font-size: 20px;'><i class='fa fa-video-camera'></i><a class='video-font' href='#' onclick='getVideo(" + file_tables[j]["id"] + ",\"" + file_tables[j]["file_path"].split("/")[file_tables[j]["file_path"].split("/").length - 2] + "\")'>" + file_tables[j]["title"] + "</a></p>" +
  50. '</div>' +
  51. '</div>' +
  52. '</section>' +
  53. '</div>');
  54. } else if (file_tables[j]["file_path"].includes(".pdf")) {
  55. if ($("#description").length <= 0) {
  56. $("#video-list").prepend('<div class="col-md-12">' +
  57. '<section class="panel" id="video-body">' +
  58. '<div class="panel-body" style="color:black;">' +
  59. '<h4>課程簡介</h4>' +
  60. '<text id="description"></text>' +
  61. '</div>' +
  62. '</section>' +
  63. '</div>');
  64. getVideoInfo(file_tables[j]["id"]);
  65. }
  66. $("#video-list").append('<div class="col-md-3">' +
  67. '<section class="panel">' +
  68. "<a target='_blank' href='" + file_tables[j]["file_path"] + "'>" +
  69. '<img style="aspect-ratio: 4/3;" class="video-active" src="' + file_tables[j]["file_path"].replace("pdf", "jpg") + '">' +
  70. '</a>' +
  71. '<div class="panel-body" id="">' +
  72. '<div class="video-text">' +
  73. "<p style='font-size: 20px;'><i class='fa fa-file-pdf-o'></i><a class='video-font' target='_blank' href='" + file_tables[j]["file_path"] + "'>" + file_tables[j]["title"] + "</a></p>" +
  74. '</div>' +
  75. '</div>' +
  76. '</section>' +
  77. '</div>');
  78. }
  79. }
  80. }
  81. }).error(function (error) {
  82. console.log(error);
  83. });
  84. }
  85. function getVideo(id, folder) {
  86. $.redirect('./video-play.php', {
  87. 'id': id,
  88. 'folder': folder
  89. });
  90. }
  91. function getVideoInfo(id) {
  92. $.ajax({
  93. url: "./script/php/video/getInfo.php",
  94. type: "POST",
  95. data: {
  96. id: id,
  97. },
  98. dataType: "json"
  99. }).done(function (result) {
  100. if (result[0].description == null) {
  101. result[0].description = "暫無描述";
  102. }
  103. $("#description").text(result[0].description);
  104. }).error(function (error) {
  105. console.log(error);
  106. });
  107. }
  108. function search_video(search_word) {
  109. $.ajax({
  110. url: "./script/php/video/get_video_search.php",
  111. type: "POST",
  112. data: {
  113. search: search_word,
  114. },
  115. dataType: "json"
  116. }).done(function (result) {
  117. file_tables = result["file_tables"];
  118. if(!file_tables.length) {
  119. $("#video-list").append('<h2 align="center">無符合選項</h2>')
  120. return
  121. }
  122. for (j = 0; j < file_tables.length; j++) {
  123. if (file_tables[j]["file_path"].includes(".m3u8")) {
  124. $("#video-list").append('<div class="col-md-3">' +
  125. '<section class="panel">' +
  126. "<a href='#' onclick='getVideo(" + file_tables[j]["id"] + ",\"" + file_tables[j]["file_path"].split("/")[file_tables[j]["file_path"].split("/").length - 2] + "\")'>" +
  127. '<img style="aspect-ratio: 4/3;" class="video-static" src="' + file_tables[j]["file_path"].replace("m3u8", "jpg") + '">' +
  128. '<img style="aspect-ratio: 4/3;" class="video-active" src="' + file_tables[j]["file_path"].replace("m3u8", "gif") +
  129. '">' +
  130. '</a>' +
  131. '<div class="panel-body" id="">' +
  132. '<div class="video-text">' +
  133. "<p style='font-size: 20px;'><i class='fa fa-video-camera'></i><a class='video-font' href='#' onclick='getVideo(" + file_tables[j]["id"] + ",\"" + file_tables[j]["file_path"].split("/")[file_tables[j]["file_path"].split("/").length - 2] + "\")'>" + file_tables[j]["title"] + "</a></p>" +
  134. '</div>' +
  135. '</div>' +
  136. '</section>' +
  137. '</div>');
  138. } else if (file_tables[j]["file_path"].includes(".pdf")) {
  139. $("#video-list").append('<div class="col-md-3">' +
  140. '<section class="panel">' +
  141. "<a target='_blank' href='" + file_tables[j]["file_path"] + "'>" +
  142. '<img style="aspect-ratio: 4/3;" class="video-active" src="' + file_tables[j]["file_path"].replace("pdf", "jpg") + '">' +
  143. '</a>' +
  144. '<div class="panel-body" id="">' +
  145. '<div class="video-text">' +
  146. "<p style='font-size: 20px;'><i class='fa fa-file-pdf-o'></i><a class='video-font' target='_blank' href='" + file_tables[j]["file_path"] + "'>" + file_tables[j]["title"] + "</a></p>" +
  147. '</div>' +
  148. '</div>' +
  149. '</section>' +
  150. '</div>');
  151. }
  152. }
  153. }).error(function (error) {
  154. console.log(error);
  155. });
  156. }