script_msg.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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('http://'+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: `${suc_data.msg}`,
  77. confirmButtonColor: '#3085d6',
  78. });
  79. },
  80. //data:JSON.stringify({n1:"12",n2:"22"}),
  81. error: function (error) {
  82. console.error(error)
  83. }
  84. });
  85. });
  86. $(".gen_avatar").click(function () {
  87. dataOBJ = { "imgurl": $('.img_src').val() }
  88. objstr = JSON.stringify(dataOBJ);
  89. console.log(dataOBJ)
  90. //alert('資料已送出! 請耐心等候')
  91. $.ajax({
  92. url: 'http://www.choozmo.com:8888/swapFace',
  93. dataType: 'json', // 預期從server接收的資料型態
  94. contentType: 'application/json; charset=utf-8', // 要送到server的資料型態
  95. type: 'post',
  96. data: objstr,
  97. success: function (suc_data) {
  98. alert(suc_data.msg)
  99. },
  100. //data:JSON.stringify({n1:"12",n2:"22"}),
  101. error: function (error) {
  102. console.error(error)
  103. }
  104. });
  105. });
  106. var loaded_data = ''
  107. function openNav() {
  108. document.getElementById("mySidenav").style.width = "250px";
  109. document.querySelector('.loader').style.display = "block";
  110. $.get("http://www.choozmo.com:8888/history_input", function (data, status) {
  111. console.log(data)
  112. loaded_data = data
  113. for (var obj of data) {
  114. var historyList = document.querySelector('.historyList');
  115. var list = document.createElement('li')
  116. var message = document.createElement('a')
  117. list.classList.add("historyList-item");
  118. message.classList.add("historyList-link");
  119. var content = document.createTextNode(obj.name)
  120. message.id = obj.id
  121. message.setAttribute('href', "#")
  122. message.setAttribute('onclick', "load_data()")
  123. message.appendChild(content)
  124. list.appendChild(message);
  125. historyList.appendChild(list);
  126. }
  127. document.querySelector('.loader').style.display = "none";
  128. });
  129. }
  130. var myModal = new bootstrap.Modal(document.getElementById('history'), {
  131. keyboard: false
  132. })
  133. function closeNav() {
  134. document.getElementById("mySidenav").style.width = "250px";
  135. }
  136. function load_data() {
  137. var title = document.getElementById("title");
  138. var linker = document.getElementById("linker");
  139. myModal.hide()
  140. tid = event.srcElement.id
  141. console.log(tid);
  142. linker.setAttribute('href', loaded_data.find(item => item.id == tid).link)
  143. $("#linker").html(loaded_data.find(item => item.id == tid).link)
  144. $("#linker").show()
  145. $(".title_new").val(loaded_data.find(item => item.id == tid).name)
  146. var step;
  147. for (step = 1; step <= 10; step++) {
  148. $(".txtsrc" + step).val(loaded_data.find(item => item.id == tid).text_content[step - 1])
  149. }
  150. var step2;
  151. for (step2 = 1; step2 <= 10; step2++) {
  152. $(".imgsrc" + step2).val(loaded_data.find(item => item.id == tid).image_urls[step2 - 1])
  153. }
  154. }
  155. var err = [];
  156. function listenToimg() {
  157. }
  158. validate();
  159. function validate() {
  160. let imgsrc = document.querySelectorAll('.imgsrc');
  161. imgsrc = [...imgsrc];
  162. for (let i = 0; i < 10; i++) {
  163. imgsrc[i].addEventListener('blur', function () {
  164. let srcArray = $(this).val().split('.');
  165. console.log(srcArray);
  166. if (srcArray.includes('png') || srcArray.includes('jpg')) {
  167. $(this).removeClass('error');
  168. $(this).next().remove('p');
  169. err.pop();
  170. } else if (srcArray.length <= 1) {
  171. $(this).removeClass('error');
  172. $(this).next().remove('p');
  173. err.pop();
  174. } else {
  175. $(this).addClass('error');
  176. if (this.nextSibling.nodeName !== 'P') {
  177. $(this).after('<p class="error-text">未支援該格式</p>');
  178. }
  179. err.push('svg');
  180. console.log(err);
  181. }
  182. });
  183. }
  184. }