script_eng.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. checkRoute();
  2. let userBasics = JSON.parse(localStorage.getItem('user_profile')) || [];
  3. $('.loading').hide();
  4. //userBasics = JSON.parse(userBasics);
  5. if(userBasics.length > 0 || typeof(userBasics) !== 'string'){
  6. $('.userName').html(`<h2 class="user-name text-white mt-lg-3 mt-xl-1 fw-bold">Hi ${userBasics.user_info.userName}</h2>`);
  7. }
  8. function checkRoute() {
  9. let jwt_token = get_jwt_token();
  10. if(jwt_token == undefined) {
  11. window.location.replace("login.html");
  12. }
  13. axios({
  14. method: 'post',
  15. url: 'https://www.choozmo.com:8887/user_profile',
  16. headers: {
  17. 'accept': 'text/html',
  18. 'Authorization': `Bearer ${jwt_token}`
  19. }
  20. }).then(res => {
  21. console.log(res.data);
  22. // if(res.status !== 200) {
  23. // window.location.replace("login.html");
  24. // }
  25. var userName='';
  26. userName+=' <h2 class="user-name text-white mt-4 fw-bold">Hi '+res.data.user_info.userName+'</h2>';
  27. $('.userName').html(userName);
  28. }).catch(err => {
  29. console.log(err);
  30. window.location.replace("login.html");
  31. });
  32. }
  33. const btnLoginPage = document.querySelector('.btn-login');
  34. const btnUserProfile = document.querySelector('.btn-userProfile');
  35. const btnLogout = document.querySelector('.btn-logout');
  36. function loginControl() {
  37. btnLoginPage.style.display = 'none';
  38. btnLogout.style.display = 'block';
  39. btnUserProfile.style.display = 'block';
  40. }
  41. loginControl();
  42. // Check lan
  43. let lan = localStorage.getItem('lan');
  44. $('.dropdown-toggle').click(() => {
  45. lan = localStorage.getItem('lan');
  46. checkLan();
  47. });
  48. checkLan();
  49. function checkLan() {
  50. if(lan == 'en') {
  51. $('.btn-makev').css('display', 'none');
  52. $('.btn-makelong').css('display', 'none');
  53. } else {
  54. $('.btn-makev').css('display', 'block');
  55. $('.btn-makelong').css('display', 'block');
  56. $('.title_new').attr('placeholder', '標題')
  57. }
  58. }
  59. var client_id = Date.now();
  60. var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
  61. var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  62. return new bootstrap.Tooltip(tooltipTriggerEl)
  63. });
  64. var myModal = new bootstrap.Modal(document.getElementById('history'), {
  65. keyboard: false
  66. })
  67. var avatarModal = new bootstrap.Modal(document.getElementById('avatarmega'), {
  68. keyboard: false
  69. })
  70. var modalImg = document.querySelector("#avatarmega .modal-img");
  71. var modalTitle = document.querySelector("#avatarmega .modal-title");
  72. var avatarSelector = document.getElementById("avatar");
  73. var card = document.querySelectorAll('.avatar-cards .card');
  74. var draftsModal = new bootstrap.Modal(document.getElementById('draftModal'), {
  75. keyboard: false
  76. })
  77. card = [...card];
  78. avatarSelector.addEventListener('change', avatarChange);
  79. avatarChange();
  80. function addCardListener() {
  81. for (let i = 0; i < card.length; i++) {
  82. card[i].addEventListener('click', openavatarModel);
  83. }
  84. }
  85. addCardListener();
  86. function avatarChange() {
  87. var value = avatarSelector.options[avatarSelector.selectedIndex].text;
  88. $('.owl-carousel').trigger('to.owl.carousel', avatarSelector.selectedIndex);
  89. for (let i = 0; i < card.length; i++) {
  90. card[i].classList.remove('active');
  91. if (card[i].dataset.avatar == value) {
  92. card[i].classList.add('active');
  93. }
  94. }
  95. }
  96. function openavatarModel() {
  97. console.log(this.dataset.img);
  98. modalImg.setAttribute("src", `static/img/${this.dataset.img}.webp`);
  99. modalTitle.textContent = `${this.dataset.avatar}`;
  100. avatarModal.show();
  101. }
  102. $('input[type=file]').on('change', prepareUpload);
  103. function prepareUpload(event) {
  104. files = event.target.files;
  105. var data = new FormData();
  106. //data.append('file', $('.img_up1').prop('files')[0]);
  107. data.append('file', files[0]);
  108. // append other variables to data if you want: data.append('field_name_x', field_value_x);
  109. $(this).next().text('');
  110. $(this).next().html('<img src="static/img/Spinner-1s-181px.gif">');
  111. $.ajax({
  112. type: 'POST',
  113. processData: false, // important
  114. contentType: false, // important
  115. data: data,
  116. url: 'https://www.choozmo.com:8887/uploadfile',
  117. dataType: 'json',
  118. success: function (jsonData) {
  119. event.target.previousSibling.value = jsonData.msg;
  120. $(this).prev().val(jsonData.msg);
  121. event.target.nextSibling.innerHTML = '';
  122. event.target.nextSibling.textContent = 'Upload';
  123. //console.log($(this).next());
  124. //$(this).next().html('上傳檔案');
  125. //$(this).next().text('上傳檔案');
  126. },
  127. error: function (error) {
  128. event.target.nextSibling.innerHTML = '';
  129. event.target.nextSibling.textContent = '上傳檔案';
  130. alert('圖片錯誤');
  131. }
  132. });
  133. }
  134. const button = document.querySelector('.next');
  135. // Drafts
  136. function getDraft() {
  137. JsLoadingOverlay.show({
  138. "overlayBackgroundColor": "#FFFFFF",
  139. "overlayOpacity": "1",
  140. "spinnerIcon": "ball-circus",
  141. "spinnerColor": "#B9DDF3",
  142. "spinnerSize": "1x",
  143. "overlayIDName": "overlay",
  144. "spinnerIDName": "spinner",
  145. "offsetX": 0,
  146. "offsetY": 0,
  147. "containerID": "draft-table",
  148. "lockScroll": false,
  149. "overlayZIndex": 9998,
  150. "spinnerZIndex": 9999
  151. });
  152. let token = get_jwt_token();
  153. axios({
  154. method: 'post',
  155. url: 'https://www.choozmo.com:8887/draft_list',
  156. headers: {
  157. 'accept': 'application/json',
  158. 'Authorization': `Bearer ${token}`
  159. }
  160. }).then(res => {
  161. console.log(res.data);
  162. let result = [...res.data];
  163. let str = '';
  164. let draftStr = '';
  165. let nodraftTxt = '目前沒有草稿喔';
  166. if(lan == 'en') {
  167. titleTxt = 'Video Title';
  168. editTxt = 'Edit';
  169. nodraftTxt = 'no_draft';
  170. }
  171. if(result.length > 0){
  172. for(let i = 0;i < result.length; i++) {
  173. draftStr += `<tr>
  174. <td>${result[i].title}</td>
  175. <td>
  176. <span class="me-md-3 draft-content-icon" id="${result[i].id}" onclick="gotoDraft(${result[i].id})">
  177. <i class="fas fa-edit"></i>
  178. </span>
  179. <span class="ms-md-3 draft-content-icon draft-content-delete" id="${result[i].id}" onclick="deleteDraft(${result[i].id})">
  180. <i class="fas fa-trash-alt"></i>
  181. </span>
  182. </td>
  183. </tr>`
  184. }
  185. let titleTxt = '標題';
  186. let editTxt = '編輯';
  187. str = `<table class="table text-center">
  188. <thead>
  189. <tr>
  190. <th scope="col" set-lan="html:video_title">${titleTxt}</th>
  191. <th class="px-0" scope="col" set-lan="html:draft_edit">${editTxt}</th>
  192. </tr>
  193. </thead>
  194. <tbody class="draft-content">${draftStr}</tbody>
  195. </table>`
  196. $('.draft-table .card').html(str);
  197. JsLoadingOverlay.hide();
  198. } else {
  199. str = `<div>
  200. <h5 set-lan="html:no_draft">${nodraftTxt}</h5>
  201. <img src="static/img/undraw_void_3ggu.svg" width="80">
  202. </div>`;
  203. $('.draft-table .card').html(str);
  204. JsLoadingOverlay.hide();
  205. }
  206. }).catch(err => {
  207. console.log(err);
  208. });
  209. }
  210. getDraft();
  211. function openDrafts() {
  212. draftsModal.show()
  213. document.querySelector('#draftModal .loader').style.display = "block";
  214. $('#draftModal #draft-table').show();
  215. getDraft();
  216. document.querySelector('#draftModal .loader').style.display = "none";
  217. }
  218. function gotoDraft (id) {
  219. location.href = `make_video2.html?draftid=${id}`;
  220. }
  221. function deleteDraft(id) {
  222. let token = get_jwt_token();
  223. JsLoadingOverlay.show({
  224. "overlayBackgroundColor": "#FFFFFF",
  225. "overlayOpacity": "1",
  226. "spinnerIcon": "ball-circus",
  227. "spinnerColor": "#B9DDF3",
  228. "spinnerSize": "1x",
  229. "overlayIDName": "overlay",
  230. "spinnerIDName": "spinner",
  231. "offsetX": 0,
  232. "offsetY": 0,
  233. "containerID": "draft-table",
  234. "lockScroll": false,
  235. "overlayZIndex": 9998,
  236. "spinnerZIndex": 9999
  237. });
  238. axios({
  239. method: 'post',
  240. url: 'https://www.choozmo.com:8887/del_draft',
  241. headers: {
  242. 'accept': 'application/json',
  243. 'Authorization': `Bearer ${token}`,
  244. 'Content-Type': 'application/json'
  245. },
  246. data: { "id": id }
  247. }).then(res => {
  248. console.log(res.data);
  249. //$('.draft-content-delete').html('<i class="fas fa-trash-alt"></i>');
  250. JsLoadingOverlay.hide();
  251. getDraft();
  252. draftsModal.show();
  253. avatarModal.hide();
  254. }).catch(err => {
  255. console.log(err);
  256. });
  257. }
  258. // Make eng video
  259. $(".next").click(function () {
  260. $('.loading').show();
  261. button.setAttribute('disabled', '');
  262. setTimeout(function () {
  263. button.removeAttribute('disabled')
  264. }, 15000);
  265. avatar = $('.avatar').val();
  266. name_title = $('.title_new').val();
  267. txtARR = [];
  268. imgARR = [];
  269. sublineARR = [];
  270. var step;
  271. let contentIdx = document.querySelectorAll(".txtsrc").length;
  272. for (let i = 1; i < (contentIdx + 1); i++) {
  273. if ($(`.txtsrc${i}`).val() != "") {
  274. txtARR.push($(`.txtsrc${i}`).val())
  275. }
  276. }
  277. let sublineIdx = document.querySelectorAll(".subsrc").length;
  278. for (let i = 1; i < (sublineIdx + 1); i++) {
  279. if ($(`.subsrc${i}`).val() != "") {
  280. sublineARR.push($(`.subsrc${i}`).val())
  281. }
  282. }
  283. let imgIdx = document.querySelectorAll(".imgsrc").length;
  284. for (let i = 1; i < (imgIdx + 1); i++) {
  285. if ($(`.imgsrc${i}`).val() != "") {
  286. imgARR.push($(`.imgsrc${i}`).val())
  287. }
  288. }
  289. dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "sub_titles": sublineARR, "avatar": avatar };
  290. objstr = JSON.stringify(dataOBJ);
  291. console.log(dataOBJ);
  292. jwt_token = get_jwt_token();
  293. var xhr = new XMLHttpRequest();
  294. xhr.open("POST", "https://www.choozmo.com:8887/make_anchor_video_eng");
  295. xhr.setRequestHeader("accept", "application/json");
  296. xhr.setRequestHeader("Authorization","Bearer "+jwt_token)
  297. xhr.setRequestHeader("Content-Type", "application/json");
  298. xhr.onreadystatechange = function () {
  299. if (xhr.readyState === 4) {
  300. $('.loading').hide();
  301. responseOBJ = JSON.parse(xhr.responseText);
  302. console.log(responseOBJ);
  303. Swal.fire({
  304. icon: 'info',
  305. text: responseOBJ.msg.eng,
  306. confirmButtonColor: '#3085d6',
  307. });
  308. } else {
  309. $('.loading').hide();
  310. }
  311. };
  312. var data = renderXHR_data(dataOBJ)
  313. console.log(data)
  314. result = xhr.send(objstr);
  315. });
  316. var loaded_data = ''
  317. function openNav() {
  318. document.getElementById("mySidenav").style.width = "250px";
  319. document.querySelector('.loader').style.display = "block";
  320. let jwt_token = get_jwt_token();
  321. axios({
  322. method: 'post',
  323. url: 'https://www.choozmo.com:8887/history_input',
  324. headers: {
  325. 'accept': 'application/json',
  326. 'Authorization': `Bearer ${jwt_token}`
  327. }
  328. }).then(res => {
  329. console.log(res.data);
  330. loaded_data = res.data;
  331. var historyList = document.querySelector('.historyList');
  332. historyList.innerHTML = '';
  333. for (var obj of loaded_data) {
  334. var list = document.createElement('li');
  335. list.id = obj.id;
  336. // div-imgfr
  337. var divImgfr = document.createElement('div');
  338. divImgfr.classList.add('item_imgfr');
  339. var img = document.createElement('img');
  340. img.setAttribute('src', obj['image_urls'][0]);
  341. divImgfr.appendChild(img);
  342. // div-content
  343. var contentBox = document.createElement('div');
  344. contentBox.classList.add('content-box');
  345. var boxTitle = document.createElement('p');
  346. boxTitle.classList.add('box-title');
  347. boxTitle.textContent = obj.name;
  348. boxTitle.id = obj.id;
  349. boxTitle.setAttribute('onclick', 'load_data()');
  350. var boxLink = document.createElement('span');
  351. boxLink.classList.add('box-link');
  352. boxLink.setAttribute("data-url", obj.link);
  353. boxLink.setAttribute('onclick', 'view()');
  354. boxLink.innerHTML = '<i class="fas fa-play-circle me-1"></i>觀看影片';
  355. contentBox.appendChild(boxTitle);
  356. contentBox.appendChild(boxLink);
  357. list.classList.add("historyList-item");
  358. list.setAttribute('onclick', 'load_data()');
  359. list.appendChild(divImgfr);
  360. list.appendChild(contentBox);
  361. historyList.appendChild(list);
  362. }
  363. document.querySelector('.loader').style.display = "none";
  364. }).catch(err => {
  365. console.log(err);
  366. });
  367. }
  368. function closeNav() {
  369. document.getElementById("mySidenav").style.width = "250px";
  370. }
  371. function view() {
  372. event.stopPropagation();
  373. console.log(event.target);
  374. if (event.target.nodeName === 'I') {
  375. return;
  376. } else {
  377. window.open(`http://${event.target.dataset.url}`, '_blank');
  378. }
  379. }
  380. function renderXHR_data(jsonObj) {
  381. XHRstring = ''
  382. for (const [key, value] of Object.entries(jsonObj)) {
  383. console.log(value)
  384. if (typeof (value) == "object") {
  385. XHRstring += (key+'=['+value.join(',')+']&')
  386. }
  387. else {
  388. XHRstring += (key + '=' + value + '&')
  389. }
  390. }
  391. XHRstring = XHRstring.substring(0, XHRstring.length - 1);
  392. return XHRstring
  393. }
  394. function get_jwt_token(){
  395. jwt_raw = document.cookie.split(';').filter(s=>s.includes('jwt_token'))[0];
  396. if(!jwt_raw) {return}
  397. return jwt_raw.split('=')[1];
  398. }
  399. function load_data() {
  400. var title = document.getElementById("title");
  401. var linker = document.getElementById("linker");
  402. myModal.hide()
  403. tid = event.srcElement.id
  404. console.log(tid);
  405. linker.setAttribute('href', `http://${loaded_data.find(item => item.id == tid).link}`)
  406. linker.setAttribute('target', '_blank')
  407. $("#linker").html(`http://${loaded_data.find(item => item.id == tid).link}`)
  408. $("#linker").show();
  409. $(".linker__box").show();
  410. let historyItem = loaded_data.filter(item => item.id == tid)[0];
  411. console.log(historyItem);
  412. $(".title_new").val(loaded_data.find(item => item.id == tid).name);
  413. let txtlength = historyItem.text_content.length;
  414. let imglength = historyItem.image_urls.length;
  415. let sublinelength = historyItem.sub_titles.length;
  416. subtitleInputs.innerHTML = '';
  417. imgInputs.innerHTML = '';
  418. sublineInputs.innerHTML = '';
  419. for (let i = 0; i < txtlength; i++) {
  420. var txtinput = document.createElement("input");
  421. txtinput.setAttribute('type', 'text');
  422. txtinput.setAttribute('name', `t${i + 1}`);
  423. txtinput.value = historyItem.text_content[i];
  424. txtinput.setAttribute('placeholder', `${i + 1}`);
  425. txtinput.classList.add('txtsrc', `txtsrc${i + 1}`)
  426. subtitleInputs.appendChild(txtinput);
  427. }
  428. for (let i = 0; i < sublinelength; i++) {
  429. var txtinput = document.createElement("input");
  430. txtinput.setAttribute('type', 'text');
  431. txtinput.setAttribute('name', `s${i + 1}`);
  432. txtinput.value = historyItem.sub_titles[i];
  433. txtinput.setAttribute('placeholder', `${i + 1}`);
  434. txtinput.classList.add('subsrc', `subsrc${i + 1}`)
  435. sublineInputs.appendChild(txtinput);
  436. }
  437. for (let i = 0; i < imglength; i++) {
  438. var imginput = document.createElement("input");
  439. imginput.setAttribute('type', 'text');
  440. imginput.setAttribute('name', `m${i + 1}`);
  441. imginput.classList.add('imgsrc', `imgsrc${i + 1}`);
  442. imginput.value = historyItem.image_urls[i];
  443. imginput.setAttribute('placeholder', `${i + 1}`);
  444. imgInputs.appendChild(imginput);
  445. var imgupload = document.createElement("input");
  446. imgupload.setAttribute('id', `img${i + 1}`);
  447. imgupload.setAttribute('type', `file`);
  448. imgupload.classList.add('img_uploader', 'img_up');
  449. imgInputs.appendChild(imgupload);
  450. var imguploadlabel = document.createElement("label");
  451. imguploadlabel.setAttribute('for', `img${i + 1}`);
  452. imguploadlabel.classList.add('upload-btn');
  453. imguploadlabel.textContent = 'Upload';
  454. imgInputs.appendChild(imguploadlabel);
  455. }
  456. }
  457. // var subtitleInputs = document.querySelector(".subtitle-inputs");
  458. // var sublineInputs = document.querySelector(".subline-inputs");
  459. // var imgInputs = document.querySelector(".img-inputs");
  460. let length = 5;
  461. function initial() {
  462. for (let i = 0; i < length; i++) {
  463. // rendertxtBlock(i + 1);
  464. // renderimgBlock(i + 1);
  465. // renderSublineBlock(i +1);
  466. renderInputSec(i+1);
  467. }
  468. console.log(document.querySelectorAll(".txtsrc").length + 1);
  469. }
  470. initial();
  471. /* var addbtn = document.querySelector(".add");
  472. var addimgbtn = document.querySelector(".addimg");
  473. var addSubline = document.querySelector('.add-subline');
  474. addbtn.addEventListener('click', addtxtBlock);
  475. addimgbtn.addEventListener('click', addimgBlock);
  476. addSubline.addEventListener('click', addsubBlock); */
  477. var addsecbtn = document.querySelector(".addsec");
  478. addsecbtn.addEventListener('click', addsecBlock);
  479. function addsecBlock() {
  480. let newsecIdx = document.querySelectorAll(".input-sec").length + 1;
  481. renderInputSec(newsecIdx);
  482. }
  483. /* function addtxtBlock() {
  484. let newIdx = document.querySelectorAll(".txtsrc").length + 1;
  485. rendertxtBlock(newIdx);
  486. }
  487. function addsubBlock() {
  488. let newIdx = document.querySelectorAll(".subsrc").length + 1;
  489. renderSublineBlock(newIdx);
  490. }
  491. function addimgBlock() {
  492. let newimgIdx = document.querySelectorAll(".imgsrc").length + 1;
  493. renderimgBlock(newimgIdx);
  494. } */
  495. function rendertxtBlock(i) {
  496. var txtinput = document.createElement("input");
  497. txtinput.setAttribute('type', 'text');
  498. txtinput.setAttribute('name', `t${i}`);
  499. txtinput.value = "";
  500. txtinput.setAttribute('placeholder', `${i}`);
  501. txtinput.classList.add('txtsrc', `txtsrc${i}`)
  502. subtitleInputs.appendChild(txtinput);
  503. }
  504. function renderSublineBlock(i) {
  505. var txtinput = document.createElement("input");
  506. txtinput.setAttribute('type', 'text');
  507. txtinput.setAttribute('name', `s${i}`);
  508. txtinput.value = "";
  509. txtinput.setAttribute('placeholder', `${i}`);
  510. txtinput.classList.add('subsrc', `subsrc${i}`)
  511. sublineInputs.appendChild(txtinput);
  512. }
  513. function renderimgBlock(i) {
  514. var imginput = document.createElement("input");
  515. imginput.setAttribute('type', 'text');
  516. imginput.setAttribute('name', `m${i}`);
  517. imginput.classList.add('imgsrc', `imgsrc${i}`);
  518. imginput.value = "";
  519. imginput.setAttribute('placeholder', `${i}`);
  520. imgInputs.appendChild(imginput);
  521. var imgupload = document.createElement("input");
  522. imgupload.setAttribute('id', `img${i}`);
  523. imgupload.setAttribute('type', `file`);
  524. imgupload.classList.add('img_uploader', 'img_up');
  525. imgInputs.appendChild(imgupload);
  526. var imguploadlabel = document.createElement("label");
  527. imguploadlabel.setAttribute('for', `img${i}`);
  528. imguploadlabel.classList.add('upload-btn');
  529. imguploadlabel.textContent = 'Upload';
  530. imgInputs.appendChild(imguploadlabel);
  531. $('input[type=file]').on('change', prepareUpload);
  532. }
  533. function renderInputSec(i) {
  534. var input_sec = document.createElement('div');
  535. var img_box = document.createElement('div');
  536. input_sec.classList.add('input-sec', `input-sec${i}`, 'p-3', 'mb-3', 'text-end');
  537. img_box.classList.add('img-box');
  538. // subtitle input
  539. var subtitleinput = document.createElement("input");
  540. subtitleinput.setAttribute('type', 'text');
  541. subtitleinput.setAttribute('name', `s${i}`);
  542. subtitleinput.classList.add('subsrc', `subsrc${i}`);
  543. subtitleinput.value = "";
  544. subtitleinput.setAttribute('placeholder', `Subtitle`);
  545. if(lan == 'zh') {
  546. subtitleinput.setAttribute('placeholder', '副標題');
  547. }
  548. input_sec.appendChild(subtitleinput);
  549. // text input
  550. var txtinput = document.createElement("input");
  551. txtinput.setAttribute('type', 'text');
  552. txtinput.setAttribute('name', `t${i}`);
  553. txtinput.classList.add('txtsrc', `txtsrc${i}`);
  554. txtinput.value = "";
  555. txtinput.setAttribute('placeholder', `Line`);
  556. if(lan == 'zh') {
  557. txtinput.setAttribute('placeholder', `台詞`);
  558. }
  559. input_sec.appendChild(txtinput);
  560. // img url input
  561. var imginput = document.createElement("input");
  562. imginput.setAttribute('type', 'text');
  563. imginput.setAttribute('name', `m${i}`);
  564. imginput.classList.add('imgsrc', `imgsrc${i}`);
  565. imginput.value = "";
  566. imginput.setAttribute('placeholder', 'Type in image link or upload image');
  567. if(lan == 'zh') {
  568. imginput.setAttribute('placeholder', '輸入圖片網址或上傳圖片');
  569. }
  570. img_box.appendChild(imginput);
  571. // img upload input
  572. var imgupload = document.createElement("input");
  573. imgupload.setAttribute('id', `img${i}`);
  574. imgupload.setAttribute('type', `file`);
  575. imgupload.classList.add('img_uploader', 'img_up');
  576. imgupload.style.display = "none";
  577. img_box.appendChild(imgupload);
  578. // img upload label
  579. var imguploadlabel = document.createElement("label");
  580. imguploadlabel.setAttribute('for', `img${i}`);
  581. imguploadlabel.classList.add('upload-btn');
  582. // imguploadlabel.textContent = 'Upload';
  583. imguploadlabel.setAttribute('set-lan', `html:upload_file`);
  584. img_box.appendChild(imguploadlabel);
  585. imgupload.addEventListener('change', prepareUpload);
  586. // preview image
  587. // var imgPreBox = document.createElement("div");
  588. // imgPreBox.classList.add('upload-cta');
  589. // img_box.appendChild(imgPreBox);
  590. input_sec.appendChild(img_box);
  591. document.querySelector('.img-inputTest').append(input_sec);
  592. }