video-list.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. (function ($) {
  2. $(document).ready(function () {
  3. if (folderFromVideoPlay != "") {
  4. initList(folderFromVideoPlay);
  5. } else {
  6. initList("videos");
  7. }
  8. });
  9. function initList(dir) {
  10. $.ajax({
  11. url: "./script/php/video/getDir.php",
  12. type: "POST",
  13. data: {
  14. dir: dir,
  15. },
  16. dataType: "json"
  17. }).done(function (result) {
  18. $("#video-list").empty();
  19. dir_names = result["dir_names"];
  20. file_tables = result["file_tables"];
  21. if (result["parent"] != undefined)
  22. parent = result["parent"];
  23. //directory
  24. for (i = 0; i < dir_names.length; i++) {
  25. $("#video-list").append('<div class="col-md-3">' +
  26. '<section class="panel">' +
  27. "<a href='#' onclick='initList(\"" + dir_names[i]["dir_name"] + "\")'>" +
  28. '<img class="video-active" src="./assets/images/folder-icon.png">' +
  29. '</a>' +
  30. '<div class="panel-body" id="">' +
  31. '<div class="video-text">' +
  32. "<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>" +
  33. '</div>' +
  34. '</div>' +
  35. '</section>' +
  36. '</div>');
  37. }
  38. //video
  39. for (j = 0; j < file_tables.length; j++) {
  40. if (file_tables[j]["file_path"].includes(".m3u8")) {
  41. $("#video-list").append('<div class="col-md-3">' +
  42. '<section class="panel">' +
  43. "<a href='#' onclick='getVideo(" + file_tables[j]["id"] + ",\"" + file_tables[j]["file_path"].split("/")[file_tables[j]["file_path"].split("/").length - 2] + "\")'>" +
  44. '<img style="aspect-ratio: 4/3;" class="video-static" src="' + file_tables[j]["file_path"].replace("m3u8", "jpg") + '">' +
  45. '<img style="aspect-ratio: 4/3;" class="video-active" src="' + file_tables[j]["file_path"].replace("m3u8", "gif") +
  46. '">' +
  47. '</a>' +
  48. '<div class="panel-body" id="">' +
  49. '<div class="video-text">' +
  50. "<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>" +
  51. '</div>' +
  52. '</div>' +
  53. '</section>' +
  54. '</div>');
  55. } else if (file_tables[j]["file_path"].includes(".pdf")) {
  56. if ($("#description").length <= 0) {
  57. $("#video-list").prepend('<div class="col-md-12">' +
  58. '<section class="panel" id="video-body">' +
  59. '<div class="panel-body" style="color:black;">' +
  60. '<h4>課程簡介</h4>' +
  61. '<text id="description"></text>' +
  62. '</div>' +
  63. '</section>' +
  64. '</div>');
  65. getVideoInfo(file_tables[j]["id"]);
  66. }
  67. $("#video-list").append('<div class="col-md-3">' +
  68. '<section class="panel">' +
  69. "<a target='_blank' href='" + file_tables[j]["file_path"] + "'>" +
  70. '<img style="aspect-ratio: 4/3;" class="video-active" src="' + file_tables[j]["file_path"].replace("pdf", "jpg") + '">' +
  71. '</a>' +
  72. '<div class="panel-body" id="">' +
  73. '<div class="video-text">' +
  74. "<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>" +
  75. '</div>' +
  76. '</div>' +
  77. '</section>' +
  78. '</div>');
  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. })(jQuery);