script_msg.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //jQuery time
  2. var current_fs, next_fs, previous_fs; //fieldsets
  3. var left, opacity, scale; //fieldset properties which we will animate
  4. var animating; //flag to prevent quick multi-click glitasdaches
  5. var client_id = Date.now()
  6. var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
  7. var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  8. return new bootstrap.Tooltip(tooltipTriggerEl)
  9. });
  10. (function () {
  11. $('.imgfr').hover(function () {
  12. $(this).next().css('display', 'block');
  13. }, function () {
  14. $(this).next().css('display', 'none');
  15. })
  16. }());
  17. $('input[type=file]').on('change', prepareUpload);
  18. // Grab the files and set them to our variable
  19. function prepareUpload(event) {
  20. files = event.target.files;
  21. var data = new FormData();
  22. //data.append('file', $('.img_up1').prop('files')[0]);
  23. data.append('file', files[0]);
  24. // append other variables to data if you want: data.append('field_name_x', field_value_x);
  25. $.ajax({
  26. type: 'POST',
  27. processData: false, // important
  28. contentType: false, // important
  29. data: data,
  30. url: 'http://www.choozmo.com:8888/uploadfile',
  31. dataType: 'json',
  32. success: function (jsonData) {
  33. event.target.previousSibling.value =jsonData.msg;
  34. $(this).prev().val(jsonData.msg);
  35. },
  36. error: function (error) {
  37. alert('圖片錯誤');
  38. }
  39. });
  40. }
  41. const button = document.querySelector('.next');
  42. $(".next").click(function () {
  43. button.setAttribute('disabled', '');
  44. setTimeout(function () {
  45. button.removeAttribute('disabled')
  46. }, 4000);
  47. avatar = $('.avatar').val();
  48. name_title = $('.title_new').val();
  49. txtARR = [];
  50. imgARR = [];
  51. var step;
  52. for (step = 1; step <= 10; step++) {
  53. if ($(".txtsrc" + step).val() != "") {
  54. txtARR.push($(".txtsrc" + step).val())
  55. }
  56. }
  57. var step2;
  58. for (step2 = 1; step2 <= 10; step2++) {
  59. if ($(".imgsrc" + step2).val() != "") {
  60. imgARR.push($(".imgsrc" + step2).val())
  61. }
  62. }
  63. dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar, "client_id": client_id }
  64. objstr = JSON.stringify(dataOBJ);
  65. console.log(dataOBJ)
  66. //alert('資料已送出! 請耐心等候')
  67. $.ajax({
  68. url: 'http://www.choozmo.com:8888/make_anchor_video_v2',
  69. //url: 'http://www.choozmo.com:8888/qqreq',
  70. dataType : 'json', // 預期從server接收的資料型態
  71. contentType : 'application/json; charset=utf-8', // 要送到server的資料型態
  72. type: 'post',
  73. data: objstr,
  74. success: function(suc_data) {
  75. Swal.fire({
  76. title: "資料已送出",
  77. icon: 'success',
  78. text: `${suc_data.msg}`,
  79. confirmButtonColor: '#3085d6',
  80. });
  81. },
  82. //data:JSON.stringify({n1:"12",n2:"22"}),
  83. error: function (error) {
  84. console.error(error)
  85. }
  86. });
  87. });
  88. $(".gen_avatar").click(function () {
  89. dataOBJ = { "imgurl": $('.img_src').val() }
  90. objstr = JSON.stringify(dataOBJ);
  91. console.log(dataOBJ)
  92. //alert('資料已送出! 請耐心等候')
  93. $.ajax({
  94. url: 'http://www.choozmo.com:8888/swapFace',
  95. dataType: 'json', // 預期從server接收的資料型態
  96. contentType: 'application/json; charset=utf-8', // 要送到server的資料型態
  97. type: 'post',
  98. data: objstr,
  99. success: function (suc_data) {
  100. alert(suc_data.msg)
  101. },
  102. //data:JSON.stringify({n1:"12",n2:"22"}),
  103. error: function (error) {
  104. console.error(error)
  105. }
  106. });
  107. });
  108. var loaded_data = ''
  109. function openNav() {
  110. document.getElementById("mySidenav").style.width = "250px";
  111. document.querySelector('.loader').style.display = "block";
  112. $.get("http://www.choozmo.com:8888/history_input", function (data, status) {
  113. console.log(data)
  114. loaded_data = data
  115. for (var obj of data) {
  116. var historyList = document.querySelector('.historyList');
  117. var list = document.createElement('li')
  118. var message = document.createElement('a')
  119. list.classList.add("historyList-item");
  120. message.classList.add("historyList-link");
  121. var content = document.createTextNode(obj.name)
  122. message.id = obj.id
  123. message.setAttribute('href', "#")
  124. message.setAttribute('onclick', "load_data()")
  125. message.appendChild(content)
  126. list.appendChild(message);
  127. historyList.appendChild(list);
  128. }
  129. document.querySelector('.loader').style.display = "none";
  130. });
  131. }
  132. var myModal = new bootstrap.Modal(document.getElementById('history'), {
  133. keyboard: false
  134. })
  135. function closeNav() {
  136. document.getElementById("mySidenav").style.width = "250px";
  137. }
  138. function load_data() {
  139. var title = document.getElementById("title");
  140. var linker = document.getElementById("linker");
  141. myModal.hide()
  142. tid = event.srcElement.id
  143. console.log(tid);
  144. linker.setAttribute('href', loaded_data.find(item => item.id == tid).link)
  145. $("#linker").html(loaded_data.find(item => item.id == tid).link)
  146. $("#linker").show()
  147. $(".title_new").val(loaded_data.find(item => item.id == tid).name)
  148. var step;
  149. for (step = 1; step <= 10; step++) {
  150. $(".txtsrc" + step).val(loaded_data.find(item => item.id == tid).text_content[step - 1])
  151. }
  152. var step2;
  153. for (step2 = 1; step2 <= 10; step2++) {
  154. $(".imgsrc" + step2).val(loaded_data.find(item => item.id == tid).image_urls[step2 - 1])
  155. }
  156. }
  157. var err = [];
  158. function listenToimg() {
  159. }
  160. validate();
  161. function validate() {
  162. let imgsrc = document.querySelectorAll('.imgsrc');
  163. imgsrc = [...imgsrc];
  164. for (let i = 0; i < 10; i++) {
  165. imgsrc[i].addEventListener('blur', function () {
  166. let srcArray = $(this).val().split('.');
  167. console.log(srcArray);
  168. if (srcArray.includes('png') || srcArray.includes('jpg')) {
  169. $(this).removeClass('error');
  170. $(this).next().remove('p');
  171. err.pop();
  172. } else if (srcArray.length <= 1) {
  173. $(this).removeClass('error');
  174. $(this).next().remove('p');
  175. err.pop();
  176. } else {
  177. $(this).addClass('error');
  178. if (this.nextSibling.nodeName !== 'P') {
  179. $(this).after('<p class="error-text">未支援該格式</p>');
  180. }
  181. err.push('svg');
  182. console.log(err);
  183. }
  184. });
  185. }
  186. }