script_anchor_eng copy.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. var client_id = Date.now()
  2. var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
  3. var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  4. return new bootstrap.Tooltip(tooltipTriggerEl)
  5. });
  6. var myModal = new bootstrap.Modal(document.getElementById('history'), {
  7. keyboard: false
  8. })
  9. var avatarModal = new bootstrap.Modal(document.getElementById('avatarmega'), {
  10. keyboard: false
  11. })
  12. var modalImg = document.querySelector("#avatarmega .modal-img");
  13. var modalTitle = document.querySelector("#avatarmega .modal-title");
  14. var avatarSelector = document.getElementById("avatar");
  15. var card = document.getElementsByClassName('card');
  16. card = [... card];
  17. avatarSelector.addEventListener('change', avatarChange);
  18. avatarChange();
  19. function addCardListener() {
  20. for(let i = 0;i < card.length; i++){
  21. card[i].addEventListener('click', openavatarModel);
  22. }
  23. }
  24. addCardListener();
  25. function avatarChange() {
  26. var value = avatarSelector.options[avatarSelector.selectedIndex].text;
  27. console.log(value);
  28. for(let i = 0;i < card.length; i++) {
  29. if(card[i].dataset.avatar == value) {
  30. card[i].classList.add('active');
  31. } else {
  32. card[i].classList.remove('active');
  33. }
  34. }
  35. }
  36. function openavatarModel() {
  37. console.log(this.dataset.img);
  38. modalImg.setAttribute("src", `static/img/${this.dataset.img}.webp`);
  39. modalTitle.textContent = `${this.dataset.avatar}`;
  40. avatarModal.show();
  41. }
  42. $('input[type=file]').on('change', prepareUpload);
  43. // Grab the files and set them to our variable
  44. function prepareUpload(event) {
  45. files = event.target.files;
  46. var data = new FormData();
  47. //data.append('file', $('.img_up1').prop('files')[0]);
  48. data.append('file', files[0]);
  49. // append other variables to data if you want: data.append('field_name_x', field_value_x);
  50. $(this).next().text('');
  51. $(this).next().html('<img src="static/img/Spinner-1s-181px.gif">');
  52. $.ajax({
  53. type: 'POST',
  54. processData: false, // important
  55. contentType: false, // important
  56. data: data,
  57. url: '/uploadfile',
  58. dataType: 'json',
  59. success: function (jsonData) {
  60. event.target.previousSibling.value =jsonData.msg;
  61. $(this).prev().val(jsonData.msg);
  62. event.target.nextSibling.innerHTML = '';
  63. event.target.nextSibling.textContent = '上傳檔案';
  64. //console.log($(this).next());
  65. //$(this).next().html('上傳檔案');
  66. //$(this).next().text('上傳檔案');
  67. },
  68. error: function (error) {
  69. event.target.nextSibling.innerHTML = '';
  70. event.target.nextSibling.textContent = '上傳檔案';
  71. alert('圖片錯誤');
  72. }
  73. });
  74. }
  75. const button = document.querySelector('.next');
  76. $(".next").click(function () {
  77. button.setAttribute('disabled', '');
  78. setTimeout(function () {
  79. button.removeAttribute('disabled')
  80. }, 15000);
  81. avatar = $('.avatar').val();
  82. name_title = $('.title_new').val();
  83. txtARR = [];
  84. imgARR = [];
  85. subtitleARR = [];
  86. var step;
  87. for (step = 1; step <= 10; step++) {
  88. if ($(".txtsrc" + step).val() != "") {
  89. txtARR.push($(".txtsrc" + step).val())
  90. }
  91. }
  92. var step2;
  93. for (step2 = 1; step2 <= 10; step2++) {
  94. if ($(".imgsrc" + step2).val() != "") {
  95. imgARR.push($(".imgsrc" + step2).val())
  96. }
  97. }
  98. for (let i = 0; i < 10; i++) {
  99. var stitles = document.getElementsByClassName('sub_text')[i].value
  100. if (stitles != "") {
  101. subtitleARR.push(stitles)
  102. }
  103. }
  104. dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "sub_titles":subtitleARR, "avatar": avatar, "client_id": client_id }
  105. objstr = JSON.stringify(dataOBJ);
  106. console.log(dataOBJ)
  107. //alert('資料已送出! 請耐心等候')
  108. $.ajax({
  109. url: '/make_anchor_video_eng',
  110. //url: 'http://www.choozmo.com:8888/qqreq',
  111. dataType : 'json', // 預期從server接收的資料型態
  112. contentType : 'application/json; charset=utf-8', // 要送到server的資料型態
  113. type: 'post',
  114. data: objstr,
  115. success: function(suc_data) {
  116. Swal.fire({
  117. title: "資料已送出",
  118. icon: 'success',
  119. text: `${suc_data.msg}`,
  120. confirmButtonColor: '#3085d6',
  121. });
  122. },
  123. //data:JSON.stringify({n1:"12",n2:"22"}),
  124. error: function (error) {
  125. console.error(error)
  126. }
  127. });
  128. });
  129. $(".gen_avatar").click(function () {
  130. dataOBJ = { "imgurl": $('.img_src').val() }
  131. objstr = JSON.stringify(dataOBJ);
  132. console.log(dataOBJ)
  133. //alert('資料已送出! 請耐心等候')
  134. $.ajax({
  135. url: '/swapFace',
  136. dataType: 'json', // 預期從server接收的資料型態
  137. contentType: 'application/json; charset=utf-8', // 要送到server的資料型態
  138. type: 'post',
  139. data: objstr,
  140. success: function (suc_data) {
  141. alert(suc_data.msg)
  142. },
  143. //data:JSON.stringify({n1:"12",n2:"22"}),
  144. error: function (error) {
  145. console.error(error)
  146. }
  147. });
  148. });
  149. var loaded_data = ''
  150. function openNav() {
  151. document.getElementById("mySidenav").style.width = "250px";
  152. document.querySelector('.loader').style.display = "block";
  153. $.get("/history_input", function (data, status) {
  154. console.log(data)
  155. loaded_data = data
  156. for (var obj of data) {
  157. var historyList = document.querySelector('.historyList');
  158. var list = document.createElement('li');
  159. list.id = obj.id;
  160. // div-imgfr
  161. var divImgfr = document.createElement('div');
  162. divImgfr.classList.add('item_imgfr');
  163. var img = document.createElement('img');
  164. img.setAttribute('src', obj['image_urls'][0]);
  165. divImgfr.appendChild(img);
  166. // div-content
  167. var contentBox = document.createElement('div');
  168. contentBox.classList.add('content-box');
  169. var boxTitle = document.createElement('p');
  170. boxTitle.classList.add('box-title');
  171. boxTitle.textContent = obj.name;
  172. boxTitle.id = obj.id;
  173. boxTitle.setAttribute('onclick', 'load_data()');
  174. var boxLink = document.createElement('span');
  175. boxLink.classList.add('box-link');
  176. boxLink.setAttribute("data-url", obj.link);
  177. boxLink.setAttribute('onclick', 'view()');
  178. boxLink.innerHTML = '<i class="fas fa-play-circle me-1"></i>觀看影片';
  179. contentBox.appendChild(boxTitle);
  180. contentBox.appendChild(boxLink);
  181. list.classList.add("historyList-item");
  182. list.setAttribute('onclick', 'load_data()');
  183. list.appendChild(divImgfr);
  184. list.appendChild(contentBox);
  185. historyList.appendChild(list);
  186. }
  187. document.querySelector('.loader').style.display = "none";
  188. });
  189. }
  190. function closeNav() {
  191. document.getElementById("mySidenav").style.width = "250px";
  192. }
  193. function view() {
  194. event.stopPropagation();
  195. console.log(event.target);
  196. if(event.target.nodeName === 'I') {
  197. return;
  198. } else {
  199. window.open(`http://${event.target.dataset.url}`, '_blank');
  200. }
  201. }
  202. function load_data() {
  203. var title = document.getElementById("title");
  204. var linker = document.getElementById("linker");
  205. myModal.hide()
  206. tid = event.srcElement.id
  207. console.log(tid);
  208. linker.setAttribute('href', `http://${loaded_data.find(item => item.id == tid).link}`)
  209. linker.setAttribute('target', '_blank')
  210. $("#linker").html(`http://${loaded_data.find(item => item.id == tid).link}`)
  211. $("#linker").show();
  212. $(".linker__box").show();
  213. $(".title_new").val(loaded_data.find(item => item.id == tid).name)
  214. var step;
  215. for (step = 1; step <= 10; step++) {
  216. $(".txtsrc" + step).val(loaded_data.find(item => item.id == tid).text_content[step - 1])
  217. }
  218. var step2;
  219. for (step2 = 1; step2 <= 10; step2++) {
  220. $(".imgsrc" + step2).val(loaded_data.find(item => item.id == tid).image_urls[step2 - 1])
  221. }
  222. }