script_msg.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. const button = document.querySelector('.next');
  18. $(".next").click(function(){
  19. button.setAttribute('disabled', '');
  20. setTimeout(function(){
  21. button.removeAttribute('disabled')
  22. }, 4000);
  23. avatar = $('.avatar').val();
  24. name_title = $('.title_new').val();
  25. txtARR=[];
  26. imgARR=[];
  27. var step;
  28. for (step = 1; step <= 10; step++) {
  29. if($(".txtsrc"+step).val()!=""){
  30. txtARR.push($(".txtsrc"+step).val())
  31. }
  32. }
  33. var step2;
  34. for (step2 = 1; step2 <= 10; step2++) {
  35. if($(".imgsrc"+step2).val()!=""){
  36. imgARR.push($(".imgsrc"+step2).val())
  37. }
  38. }
  39. dataOBJ = {"name":name_title,"text_content":txtARR,"image_urls":imgARR,"avatar":avatar,"client_id":client_id}
  40. objstr = JSON.stringify(dataOBJ);
  41. console.log(dataOBJ)
  42. //alert('資料已送出! 請耐心等候')
  43. $.ajax({
  44. url: 'http://www.choozmo.com:8888/make_anchor_video_v2',
  45. //url: 'http://www.choozmo.com:8888/qqreq',
  46. dataType : 'json', // 預期從server接收的資料型態
  47. contentType : 'application/json; charset=utf-8', // 要送到server的資料型態
  48. type: 'post',
  49. data: objstr,
  50. success: function(suc_data) {
  51. Swal.fire({
  52. title: `${suc_data.msg}`,
  53. confirmButtonColor: '#3085d6',
  54. });
  55. },
  56. //data:JSON.stringify({n1:"12",n2:"22"}),
  57. error: function (error) {
  58. console.error(error)
  59. }
  60. });
  61. });
  62. $(".gen_avatar").click(function(){
  63. dataOBJ = {"imgurl":$('.img_src').val()}
  64. objstr = JSON.stringify(dataOBJ);
  65. console.log(dataOBJ)
  66. //alert('資料已送出! 請耐心等候')
  67. $.ajax({
  68. url: 'http://www.choozmo.com:8888/swapFace',
  69. dataType : 'json', // 預期從server接收的資料型態
  70. contentType : 'application/json; charset=utf-8', // 要送到server的資料型態
  71. type: 'post',
  72. data: objstr,
  73. success: function(suc_data) {
  74. alert(suc_data.msg)
  75. },
  76. //data:JSON.stringify({n1:"12",n2:"22"}),
  77. error: function (error) {
  78. console.error(error)
  79. }
  80. });
  81. });
  82. var loaded_data = ''
  83. function openNav() {
  84. document.getElementById("mySidenav").style.width = "250px";
  85. document.querySelector('.loader').style.display = "block";
  86. $.get("http://www.choozmo.com:8888/history_input", function(data, status){
  87. console.log(data)
  88. loaded_data = data
  89. for (var obj of data) {
  90. var historyList = document.querySelector('.historyList');
  91. var list = document.createElement('li')
  92. var message = document.createElement('a')
  93. list.classList.add("historyList-item");
  94. message.classList.add("historyList-link");
  95. var content = document.createTextNode(obj.name)
  96. message.id = obj.id
  97. message.setAttribute('href', "#")
  98. message.setAttribute('onclick', "load_data()")
  99. message.appendChild(content)
  100. list.appendChild(message);
  101. historyList.appendChild(list);
  102. }
  103. document.querySelector('.loader').style.display = "none";
  104. });
  105. }
  106. var myModal = new bootstrap.Modal(document.getElementById('history'), {
  107. keyboard: false
  108. })
  109. function closeNav() {
  110. document.getElementById("mySidenav").style.width = "250px";
  111. }
  112. function load_data(){
  113. var title = document.getElementById("title");
  114. var linker = document.getElementById("linker");
  115. myModal.hide()
  116. tid = event.srcElement.id
  117. console.log(tid);
  118. linker.setAttribute('href', loaded_data.find(item => item.id == tid).link)
  119. $("#linker").html(loaded_data.find(item => item.id == tid).link)
  120. $("#linker").show()
  121. $(".title_new").val(loaded_data.find(item => item.id == tid).name)
  122. var step;
  123. for (step = 1; step <= 10; step++) {
  124. $(".txtsrc"+step).val(loaded_data.find(item => item.id == tid).text_content[step-1])
  125. }
  126. var step2;
  127. for (step2 = 1; step2 <= 10; step2++) {
  128. $(".imgsrc"+step2).val(loaded_data.find(item => item.id == tid).image_urls[step2-1])
  129. }
  130. }
  131. var err = [];
  132. function listenToimg() {
  133. }
  134. validate();
  135. function validate(){
  136. let imgsrc = document.querySelectorAll('.imgsrc');
  137. imgsrc = [...imgsrc];
  138. for(let i = 0; i < 10; i++){
  139. imgsrc[i].addEventListener('blur', function(){
  140. let srcArray = $(this).val().split('.');
  141. console.log(srcArray);
  142. if(srcArray.includes('png') || srcArray.includes('jpg')){
  143. $(this).removeClass('error');
  144. $(this).next().remove('p');
  145. err.pop();
  146. }else if(srcArray.length <= 1){
  147. $(this).removeClass('error');
  148. $(this).next().remove('p');
  149. err.pop();
  150. }else {
  151. $(this).addClass('error');
  152. if( this.nextSibling.nodeName !== 'P') {
  153. $(this).after('<p class="error-text">未支援該格式</p>');
  154. }
  155. err.push('svg');
  156. console.log(err);
  157. }
  158. });
  159. }
  160. }