$(document).ready(function () {
if (folderFromVideoPlay != "") {
initList(folderFromVideoPlay);
} else {
initList("videos");
}
});
function initList(dir) {
$.ajax({
url: "./script/php/video/getDir.php",
type: "POST",
data: {
dir: dir,
},
dataType: "json"
}).done(function (result) {
if (result["parent"] != undefined) {
$("#video-list").empty();
dir_names = result["dir_names"];
file_tables = result["file_tables"];
parent = result["parent"];
//directory
for (i = 0; i < dir_names.length; i++) {
$("#video-list").append('
');
}
//video
for (j = 0; j < file_tables.length; j++) {
if (file_tables[j]["file_path"].includes(".m3u8")) {
$("#video-list").append('');
} else if (file_tables[j]["file_path"].includes(".pdf")) {
if ($("#description").length <= 0) {
$("#video-list").prepend('' +
'
' +
'' +
'
課程簡介
' +
'' +
'' +
'' +
'
');
getVideoInfo(file_tables[j]["id"]);
}
$("#video-list").append('');
}
}
}
}).error(function (error) {
console.log(error);
});
}
function getVideo(id, folder) {
$.redirect('./video-play.php', {
'id': id,
'folder': folder
});
}
function getVideoInfo(id) {
$.ajax({
url: "./script/php/video/getInfo.php",
type: "POST",
data: {
id: id,
},
dataType: "json"
}).done(function (result) {
if (result[0].description == null) {
result[0].description = "暫無描述";
}
$("#description").text(result[0].description);
}).error(function (error) {
console.log(error);
});
}
function search_video(search_word) {
$.ajax({
url: "./script/php/video/get_video_search.php",
type: "POST",
data: {
search: search_word,
},
dataType: "json"
}).done(function (result) {
file_tables = result["file_tables"];
if(!file_tables.length) {
$("#video-list").append('無符合選項
')
return
}
for (j = 0; j < file_tables.length; j++) {
if (file_tables[j]["file_path"].includes(".m3u8")) {
$("#video-list").append('');
} else if (file_tables[j]["file_path"].includes(".pdf")) {
$("#video-list").append('');
}
}
}).error(function (error) {
console.log(error);
});
}