script_util_copy.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. checkRoute();
  2. let userBasics = JSON.parse(localStorage.getItem('user_profile')) || [];
  3. if(userBasics !== []){
  4. $('.userName').html(`<h2 class="user-name text-white mt-4 fw-bold">Hi ${userBasics.user_info.userName}</h2>`);
  5. }
  6. function checkRoute() {
  7. let jwt_token = get_jwt_token();
  8. if(jwt_token == undefined) {
  9. window.location.replace("login.html");
  10. }
  11. axios({
  12. method: 'post',
  13. url: 'https://www.choozmo.com:8887/user_profile',
  14. headers: {
  15. 'accept': 'text/html',
  16. 'Authorization': `Bearer ${jwt_token}`
  17. }
  18. }).then(res => {
  19. console.log(res.data);
  20. if(res.status !== 200) {
  21. window.location.replace("login.html");
  22. }
  23. var userName='';
  24. userName+=' <h2 class="user-name text-white mt-4 fw-bold">Hi '+res.data.user_info.userName+'</h2>';
  25. $('.userName').html(userName);
  26. }).catch(err => {
  27. console.log(err);
  28. });
  29. }
  30. const btnLoginPage = document.querySelector('.btn-login');
  31. const btnUserProfile = document.querySelector('.btn-userProfile');
  32. const btnLogout = document.querySelector('.btn-logout');
  33. function loginControl() {
  34. btnLoginPage.style.display = 'none';
  35. btnLogout.style.display = 'block';
  36. btnUserProfile.style.display = 'block';
  37. }
  38. loginControl();
  39. var client_id = Date.now()
  40. var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
  41. var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  42. return new bootstrap.Tooltip(tooltipTriggerEl)
  43. });
  44. var myModal = new bootstrap.Modal(document.getElementById('history'), {
  45. keyboard: false
  46. })
  47. var avatarModal = new bootstrap.Modal(document.getElementById('avatarmega'), {
  48. keyboard: false
  49. })
  50. var modalImg = document.querySelector("#avatarmega .modal-img");
  51. var modalTitle = document.querySelector("#avatarmega .modal-title");
  52. var avatarSelector = document.getElementById("avatar");
  53. var card = document.getElementsByClassName('card');
  54. card = [...card];
  55. avatarSelector.addEventListener('change', avatarChange);
  56. avatarChange();
  57. function addCardListener() {
  58. for (let i = 0; i < card.length; i++) {
  59. card[i].addEventListener('click', openavatarModel);
  60. }
  61. }
  62. addCardListener();
  63. function avatarChange() {
  64. var value = avatarSelector.options[avatarSelector.selectedIndex].text;
  65. $('.owl-carousel').trigger('to.owl.carousel', avatarSelector.selectedIndex);
  66. for (let i = 0; i < card.length; i++) {
  67. card[i].classList.remove('active');
  68. if (card[i].dataset.avatar == value) {
  69. card[i].classList.add('active');
  70. }
  71. }
  72. }
  73. function openavatarModel() {
  74. console.log(this.dataset.img);
  75. modalImg.setAttribute("src", `static/img/${this.dataset.img}.webp`);
  76. modalTitle.textContent = `${this.dataset.avatar}`;
  77. avatarModal.show();
  78. }
  79. $('input[type=file]').on('change', prepareUpload);
  80. function prepareUpload(event) {
  81. files = event.target.files;
  82. var data = new FormData();
  83. //data.append('file', $('.img_up1').prop('files')[0]);
  84. data.append('file', files[0]);
  85. // append other variables to data if you want: data.append('field_name_x', field_value_x);
  86. $(this).next().text('');
  87. $(this).next().html('<img src="static/img/Spinner-1s-181px.gif">');
  88. $.ajax({
  89. type: 'POST',
  90. processData: false, // important
  91. contentType: false, // important
  92. data: data,
  93. url: 'https://www.choozmo.com:8887/uploadfile',
  94. dataType: 'json',
  95. success: function (jsonData) {
  96. event.target.previousSibling.value = jsonData.msg;
  97. console.log(event.target.previousSibling.value);
  98. event.target.nextSibling.innerHTML = '';
  99. event.target.nextSibling.textContent = '上傳檔案';
  100. //console.log($(this).next());
  101. //$(this).next().html('上傳檔案');
  102. //$(this).next().text('上傳檔案');
  103. },
  104. error: function (error) {
  105. event.target.nextSibling.innerHTML = '';
  106. event.target.nextSibling.textContent = '上傳檔案';
  107. alert('圖片錯誤');
  108. }
  109. });
  110. }
  111. const button = document.querySelector('.next');
  112. $(".next").click(function () {
  113. button.setAttribute('disabled', '');
  114. setTimeout(function () {
  115. button.removeAttribute('disabled')
  116. }, 4000);
  117. avatar = $('.avatar').val();
  118. name_title = $('.title_new').val();
  119. txtARR = [];
  120. imgARR = [];
  121. var step;
  122. let contentIdx = document.querySelectorAll(".txtsrc").length;
  123. for (let i = 1; i < (contentIdx + 1); i++) {
  124. if ($(`.txtsrc${i}`).val() != "") {
  125. txtARR.push($(`.txtsrc${i}`).val())
  126. }
  127. }
  128. let imgIdx = document.querySelectorAll(".imgsrc").length;
  129. for (let i = 1; i < (imgIdx + 1); i++) {
  130. if ($(`.imgsrc${i}`).val() != "") {
  131. imgARR.push($(`.imgsrc${i}`).val())
  132. }
  133. }
  134. multiLang = 0
  135. if ($('#multiLang').prop("checked")) {multiLang = 1;}
  136. dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar,"multiLang":multiLang, "client_id": client_id }
  137. objstr = JSON.stringify(dataOBJ);
  138. console.log(dataOBJ)
  139. jwt_token = get_jwt_token()
  140. var xhr = new XMLHttpRequest();
  141. xhr.open("POST", "https://www.choozmo.com:8887/make_anchor_video");
  142. xhr.setRequestHeader("accept", "application/json");
  143. xhr.setRequestHeader("Authorization","Bearer "+jwt_token)
  144. xhr.setRequestHeader("Content-Type", "application/json");
  145. xhr.onreadystatechange = function () {
  146. if (xhr.readyState === 4) {
  147. responseOBJ = JSON.parse(xhr.responseText)
  148. if (responseOBJ.msg=='ok')
  149. {
  150. Swal.fire({
  151. title: "資料已送出",
  152. icon: 'success',
  153. text: '資料已傳送,請耐心等候',
  154. confirmButtonColor: '#3085d6',
  155. });
  156. }
  157. else{
  158. Swal.fire({
  159. title: "發生錯誤",
  160. icon: 'error',
  161. text: responseOBJ.msg,
  162. confirmButtonColor: '#3085d6',
  163. });
  164. }
  165. }
  166. };
  167. var data = renderXHR_data(dataOBJ)
  168. console.log(data)
  169. result = xhr.send(objstr);
  170. });
  171. const buttonSend = document.querySelector('#sendBTN');
  172. $("#sendBTN").click(function () {
  173. buttonSend.setAttribute('disabled', '');
  174. setTimeout(function () {
  175. buttonSend.removeAttribute('disabled')
  176. }, 4000);
  177. avatar = $('.avatar').val();
  178. name_title = $('.title_new').val();
  179. txtARR = [];
  180. imgARR = [];
  181. var step;
  182. let contentIdx = document.querySelectorAll(".txtsrc").length;
  183. for (let i = 1; i < (contentIdx + 1); i++) {
  184. if ($(`.txtsrc${i}`).val() != "") {
  185. txtARR.push($(`.txtsrc${i}`).val())
  186. }
  187. }
  188. let imgIdx = document.querySelectorAll(".imgsrc").length;
  189. for (let i = 1; i < (imgIdx + 1); i++) {
  190. if ($(`.imgsrc${i}`).val() != "") {
  191. imgARR.push($(`.imgsrc${i}`).val())
  192. }
  193. }
  194. multiLang = 0
  195. if ($('#multiLang').prop("checked")) {multiLang = 1;}
  196. dataOBJ = { "name": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar,"multiLang":multiLang, "client_id": client_id }
  197. objstr = JSON.stringify(dataOBJ);
  198. console.log(dataOBJ)
  199. jwt_token = get_jwt_token()
  200. var xhr = new XMLHttpRequest();
  201. xhr.open("POST", "https://www.choozmo.com:8887/make_anchor_video_long");
  202. xhr.setRequestHeader("accept", "application/json");
  203. xhr.setRequestHeader("Authorization","Bearer "+jwt_token)
  204. xhr.setRequestHeader("Content-Type", "application/json");
  205. xhr.onreadystatechange = function () {
  206. if (xhr.readyState === 4) {
  207. responseOBJ = JSON.parse(xhr.responseText)
  208. if (responseOBJ.msg=='ok')
  209. {
  210. Swal.fire({
  211. title: "資料已送出",
  212. icon: 'success',
  213. text: '資料已傳送,請耐心等候',
  214. confirmButtonColor: '#3085d6',
  215. });
  216. }
  217. else{
  218. Swal.fire({
  219. title: "發生錯誤",
  220. icon: 'error',
  221. text: responseOBJ.msg,
  222. confirmButtonColor: '#3085d6',
  223. });
  224. }
  225. }
  226. };
  227. var data = renderXHR_data(dataOBJ)
  228. console.log(data)
  229. result = xhr.send(objstr);
  230. });
  231. const slide_button = document.querySelector('#send_slide');
  232. $("#send_slide").click(function () {
  233. slide_button.setAttribute('disabled', '');
  234. setTimeout(function () {
  235. slide_button.removeAttribute('disabled')
  236. }, 4000);
  237. avatar = $('.avatar').val();
  238. var step;
  239. multiLang = 0
  240. if ($('#multiLang').prop("checked")) {multiLang = 1;}
  241. dataOBJ = {'slide_url':$('#slide_raw_url').val(),"avatar": avatar,"multiLang":multiLang, "client_id": client_id }
  242. objstr = JSON.stringify(dataOBJ);
  243. jwt_token = get_jwt_token()
  244. var xhr = new XMLHttpRequest();
  245. xhr.open("POST", "https://www.choozmo.com:8887/make_anchor_video_gSlide");
  246. xhr.setRequestHeader("accept", "application/json");
  247. xhr.setRequestHeader("Authorization","Bearer "+jwt_token);
  248. xhr.setRequestHeader("Content-Type", "application/json");
  249. xhr.onreadystatechange = function () {
  250. if (xhr.readyState === 4) {
  251. Swal.fire({
  252. title: "資料已送出",
  253. icon: 'success',
  254. text: '資料已傳送,請耐心等候',
  255. confirmButtonColor: '#3085d6',
  256. });
  257. }
  258. };
  259. var data = renderXHR_data(dataOBJ)
  260. console.log(data)
  261. result = xhr.send(objstr);
  262. });
  263. $(".gen_avatar").click(function () {
  264. dataOBJ = { "imgurl": $('.img_src').val() }
  265. objstr = JSON.stringify(dataOBJ);
  266. console.log(dataOBJ)
  267. //alert('資料已送出! 請耐心等候')
  268. $.ajax({
  269. url: 'https://www.choozmo.com:8887/swapFace',
  270. dataType: 'json', // 預期從server接收的資料型態
  271. contentType: 'application/json; charset=utf-8', // 要送到server的資料型態
  272. type: 'post',
  273. data: objstr,
  274. success: function (suc_data) {
  275. alert(suc_data.msg)
  276. },
  277. //data:JSON.stringify({n1:"12",n2:"22"}),
  278. error: function (error) {
  279. console.error(error)
  280. }
  281. });
  282. });
  283. var loaded_data = ''
  284. function openNav() {
  285. document.getElementById("mySidenav").style.width = "250px";
  286. document.querySelector('.loader').style.display = "block";
  287. let jwt_token = get_jwt_token();
  288. axios({
  289. method: 'post',
  290. url: 'https://www.choozmo.com:8887/history_input',
  291. headers: {
  292. 'accept': 'application/json',
  293. 'Authorization': `Bearer ${jwt_token}`
  294. }
  295. }).then(res => {
  296. console.log(res.data);
  297. loaded_data = res.data;
  298. for (var obj of loaded_data) {
  299. var historyList = document.querySelector('.historyList');
  300. var list = document.createElement('li');
  301. list.id = obj.id;
  302. // div-imgfr
  303. var divImgfr = document.createElement('div');
  304. divImgfr.classList.add('item_imgfr');
  305. var img = document.createElement('img');
  306. img.setAttribute('src', obj['image_urls'][0]);
  307. divImgfr.appendChild(img);
  308. // div-content
  309. var contentBox = document.createElement('div');
  310. contentBox.classList.add('content-box');
  311. var boxTitle = document.createElement('p');
  312. boxTitle.classList.add('box-title');
  313. boxTitle.textContent = obj.name;
  314. boxTitle.id = obj.id;
  315. console.log(loaded_data);
  316. boxTitle.setAttribute('onclick', `direct(${obj.id})`);
  317. var boxLink = document.createElement('span');
  318. boxLink.classList.add('box-link');
  319. boxLink.setAttribute("data-url", obj.link);
  320. boxLink.setAttribute('onclick', 'view()');
  321. boxLink.innerHTML = '<i class="fas fa-play-circle me-1"></i>觀看影片';
  322. contentBox.appendChild(boxTitle);
  323. contentBox.appendChild(boxLink);
  324. list.classList.add("historyList-item");
  325. list.setAttribute('onclick', `direct(${obj.id})`);
  326. list.appendChild(divImgfr);
  327. list.appendChild(contentBox);
  328. historyList.appendChild(list);
  329. }
  330. document.querySelector('.loader').style.display = "none";
  331. }).catch(err => {
  332. console.log(err);
  333. });
  334. }
  335. function closeNav() {
  336. document.getElementById("mySidenav").style.width = "250px";
  337. }
  338. function view() {
  339. event.stopPropagation();
  340. console.log(event.target);
  341. if (event.target.nodeName === 'I') {
  342. return;
  343. } else {
  344. window.open(`http://${event.target.dataset.url}`, '_blank');
  345. }
  346. }
  347. function renderXHR_data(jsonObj) {
  348. XHRstring = ''
  349. for (const [key, value] of Object.entries(jsonObj)) {
  350. console.log(value)
  351. if (typeof (value) == "object") {
  352. XHRstring += (key+'=['+value.join(',')+']&')
  353. }
  354. else {
  355. XHRstring += (key + '=' + value + '&')
  356. }
  357. }
  358. XHRstring = XHRstring.substring(0, XHRstring.length - 1);
  359. return XHRstring
  360. }
  361. function get_jwt_token(){
  362. jwt_raw = document.cookie.split(';').filter(s=>s.includes('jwt_token'))[0];
  363. if(!jwt_raw) {return}
  364. return jwt_raw.split('=')[1];
  365. }
  366. function direct(id) {
  367. location.href = `make_video.html?id=${id}`;
  368. }
  369. function load_data(tid, loaded_data, draft = false) {
  370. if(!tid) {
  371. return;
  372. }
  373. var title = document.getElementById("title");
  374. var linker = document.getElementById("linker");
  375. myModal.hide();
  376. if(!draft) {
  377. linker.setAttribute('href', `http://${loaded_data.find(item => item.id == tid).link}`)
  378. linker.setAttribute('target', '_blank')
  379. $("#linker").html(`http://${loaded_data.find(item => item.id == tid).link}`)
  380. $("#linker").show();
  381. $(".linker__box").show();
  382. }
  383. console.log(loaded_data);
  384. let historyItem = loaded_data.filter(item => item.id == tid)[0];
  385. console.log(historyItem.title);
  386. if(draft) {
  387. $(".title_new").val(historyItem.title);
  388. $("#avatar").val(historyItem.avatar);
  389. } else {
  390. $(".title_new").val(loaded_data.find(item => item.id == tid).name);
  391. //$("#avatar").val(historyItem.avatar);
  392. }
  393. let txtlength = historyItem.text_content.length;
  394. let imglength = historyItem.image_urls.length;
  395. subtitleInputs.innerHTML = '';
  396. imgInputs.innerHTML = '';
  397. for (let i = 0; i < txtlength; i++) {
  398. var txtinput = document.createElement("input");
  399. txtinput.setAttribute('type', 'text');
  400. txtinput.setAttribute('name', `t${i + 1}`);
  401. txtinput.value = historyItem.text_content[i];
  402. txtinput.setAttribute('placeholder', `${i + 1}`);
  403. txtinput.classList.add('txtsrc', `txtsrc${i + 1}`)
  404. subtitleInputs.appendChild(txtinput);
  405. }
  406. for (let i = 0; i < imglength; i++) {
  407. var imginput = document.createElement("input");
  408. imginput.setAttribute('type', 'text');
  409. imginput.setAttribute('name', `m${i + 1}`);
  410. imginput.classList.add('imgsrc', `imgsrc${i + 1}`);
  411. imginput.value = historyItem.image_urls[i];
  412. imginput.setAttribute('placeholder', `${i + 1}`);
  413. imgInputs.appendChild(imginput);
  414. var imgupload = document.createElement("input");
  415. imgupload.setAttribute('id', `img${i + 1}`);
  416. imgupload.setAttribute('type', `file`);
  417. imgupload.classList.add('img_uploader', 'img_up');
  418. imgInputs.appendChild(imgupload);
  419. var imguploadlabel = document.createElement("label");
  420. imguploadlabel.setAttribute('for', `img${i + 1}`);
  421. imguploadlabel.classList.add('upload-btn');
  422. imguploadlabel.textContent = '上傳檔案';
  423. imguploadlabel.setAttribute('set-lan', `html:upload_file`);
  424. imgInputs.appendChild(imguploadlabel);
  425. }
  426. setTimeout(() => {
  427. JsLoadingOverlay.hide();
  428. }, 0);
  429. }
  430. getpathId();
  431. function getMode() {
  432. let id = window.location.search.split('?').pop();
  433. let mode = id.split('=')[0];
  434. if(mode == 'draftid') {
  435. JsLoadingOverlay.show({
  436. "overlayBackgroundColor": "#FFFFFF",
  437. "overlayOpacity": "0.9",
  438. "spinnerIcon": "ball-circus",
  439. "spinnerColor": "#B9DDF3",
  440. "spinnerSize": "2x",
  441. "overlayIDName": "overlay",
  442. "spinnerIDName": "spinner",
  443. "offsetX": 0,
  444. "offsetY": 0,
  445. "containerID": null,
  446. "lockScroll": false,
  447. "overlayZIndex": 9998,
  448. "spinnerZIndex": 9999
  449. });
  450. getDraftData();
  451. } else if(mode == 'id') {
  452. JsLoadingOverlay.show({
  453. "overlayBackgroundColor": "#FFFFFF",
  454. "overlayOpacity": "0.9",
  455. "spinnerIcon": "ball-circus",
  456. "spinnerColor": "#B9DDF3",
  457. "spinnerSize": "2x",
  458. "overlayIDName": "overlay",
  459. "spinnerIDName": "spinner",
  460. "offsetX": 0,
  461. "offsetY": 0,
  462. "containerID": null,
  463. "lockScroll": false,
  464. "overlayZIndex": 9998,
  465. "spinnerZIndex": 9999
  466. });
  467. getData();
  468. }
  469. return id.split('=')[1];
  470. //load_data(id);
  471. }
  472. getMode();
  473. function getpathId(){
  474. let id = window.location.search.split('?').pop();
  475. return id.split('=')[1];
  476. }
  477. function getData() {
  478. let jwt_token = get_jwt_token();
  479. axios({
  480. method: 'post',
  481. url: 'https://www.choozmo.com:8887/history_input',
  482. headers: {
  483. 'accept': 'application/json',
  484. 'Authorization': `Bearer ${jwt_token}`
  485. }
  486. }).then(res => {
  487. loaded_data = res.data;
  488. console.log(loaded_data);
  489. const id = getpathId();
  490. load_data(id, loaded_data);
  491. }).catch(err => {
  492. console.log(err);
  493. });
  494. }
  495. var subtitleInputs = document.querySelector(".subtitle-inputs");
  496. var imgInputs = document.querySelector(".img-inputs");
  497. let length = 5;
  498. function initial() {
  499. for (let i = 0; i < length; i++) {
  500. rendertxtBlock(i + 1);
  501. //renderimgBlock(i + 1);
  502. }
  503. console.log(document.querySelectorAll(".txtsrc").length + 1);
  504. }
  505. initial();
  506. var addbtn = document.querySelector(".add");
  507. var addimgbtn = document.querySelector(".addimg");
  508. addbtn.addEventListener('click', addtxtBlock);
  509. addimgbtn.addEventListener('click', addimgBlock);
  510. function addtxtBlock() {
  511. let newIdx = document.querySelectorAll(".txtsrc").length + 1;
  512. rendertxtBlock(newIdx);
  513. }
  514. function addimgBlock() {
  515. let newimgIdx = document.querySelectorAll(".imgsrc").length + 1;
  516. renderimgBlock(newimgIdx);
  517. }
  518. function rendertxtBlock(i) {
  519. var txtinput = document.createElement("input");
  520. txtinput.setAttribute('type', 'text');
  521. txtinput.setAttribute('name', `t${i}`);
  522. txtinput.value = "";
  523. txtinput.setAttribute('placeholder', `${i}`);
  524. txtinput.classList.add('txtsrc', `txtsrc${i}`)
  525. subtitleInputs.appendChild(txtinput);
  526. }
  527. function renderimgBlock(i) {
  528. var imginput = document.createElement("input");
  529. imginput.setAttribute('type', 'text');
  530. imginput.setAttribute('name', `m${i}`);
  531. imginput.classList.add('imgsrc', `imgsrc${i}`);
  532. imginput.value = "";
  533. imginput.setAttribute('placeholder', `${i}`);
  534. imgInputs.appendChild(imginput);
  535. var imgupload = document.createElement("input");
  536. imgupload.setAttribute('id', `img${i}`);
  537. imgupload.setAttribute('type', `file`);
  538. imgupload.classList.add('img_uploader', 'img_up');
  539. imgInputs.appendChild(imgupload);
  540. var imguploadlabel = document.createElement("label");
  541. imguploadlabel.setAttribute('for', `img${i}`);
  542. imguploadlabel.classList.add('upload-btn');
  543. imguploadlabel.textContent = '上傳檔案';
  544. imguploadlabel.setAttribute('set-lan', `html:upload_file`);
  545. imgInputs.appendChild(imguploadlabel);
  546. $('input[type=file]').on('change', prepareUpload);
  547. }
  548. $('.owl-carousel').owlCarousel({
  549. loop: true,
  550. margin: 10,
  551. nav: false,
  552. mouseDrag: true,
  553. touchDrag: true,
  554. smartSpeed: 1000,
  555. autoplay: true,
  556. autoplayTimeout: 8000,
  557. autoplayHoverPause: false,
  558. responsive: {
  559. 0: {
  560. items: 1
  561. },
  562. 600: {
  563. items: 2
  564. },
  565. 1000: {
  566. items: 4
  567. }
  568. }
  569. });
  570. $('.draft-btn').click(() => {
  571. $('.draft-btn').text('Loading...');
  572. let jwt_token = get_jwt_token();
  573. let avatar = $('.avatar').val();
  574. let name_title = $('.title_new').val();
  575. let txtARR = [];
  576. let imgARR = [];
  577. var step;
  578. let contentIdx = document.querySelectorAll(".txtsrc").length;
  579. for (let i = 1; i < (contentIdx + 1); i++) {
  580. if ($(`.txtsrc${i}`).val() != "") {
  581. txtARR.push($(`.txtsrc${i}`).val())
  582. }
  583. }
  584. let imgIdx = document.querySelectorAll(".imgsrc").length;
  585. for (let i = 1; i < (imgIdx + 1); i++) {
  586. if ($(`.imgsrc${i}`).val() != "") {
  587. imgARR.push($(`.imgsrc${i}`).val())
  588. }
  589. }
  590. let multiLang = 0
  591. if ($('#multiLang').prop("checked")) {multiLang = 1;}
  592. let id = window.location.search.split('?').pop();
  593. let mode = id.split('=')[0];
  594. if(mode == 'draftid') {
  595. id = Number(id.split('=')[1]);
  596. } else {
  597. id = -1;
  598. }
  599. let dataOBJ = { "id": id, "title": name_title, "text_content": txtARR, "image_urls": imgARR, "avatar": avatar,"multiLang":multiLang }
  600. console.log(dataOBJ);
  601. axios({
  602. method: 'post',
  603. url: 'https://www.choozmo.com:8887/save_draft',
  604. headers: {
  605. 'accept': 'application/json',
  606. 'Authorization': `Bearer ${jwt_token}`,
  607. 'Content-Type': 'application/json',
  608. },
  609. data: dataOBJ
  610. }).then(res => {
  611. console.log(res.data);
  612. $('.draft-btn').text('存為草稿');
  613. Swal.fire({
  614. title: "儲存完成",
  615. icon: 'success',
  616. confirmButtonColor: '#3085d6',
  617. });
  618. }).catch(err => {
  619. console.log(err);
  620. });
  621. });
  622. function getDraftData() {
  623. let token = get_jwt_token();
  624. axios({
  625. method: 'post',
  626. url: 'https://www.choozmo.com:8887/draft_list',
  627. headers: {
  628. 'accept': 'application/json',
  629. 'Authorization': `Bearer ${token}`
  630. }
  631. }).then(res => {
  632. console.log(res.data);
  633. let result = [...res.data];
  634. let id = getpathId();
  635. load_data(id, result, true);
  636. }).catch(err => {
  637. console.log(err);
  638. });
  639. }
  640. $(".copy").click(function(){
  641. const copyStr = $(this).next().text();
  642. copyToClipboard(copyStr);
  643. });
  644. const copyToClipboard = str => {
  645. const el = document.createElement('textarea');
  646. el.value = str;
  647. el.setAttribute('readonly', '');
  648. el.style.position = 'absolute';
  649. el.style.left = '-9999px';
  650. document.body.appendChild(el);
  651. el.select();
  652. document.execCommand('copy');
  653. document.body.removeChild(el);
  654. Swal.fire({
  655. toast: true,
  656. icon: 'success',
  657. position: 'top-end',
  658. title: 'Link copied!',
  659. timerProgressBar: true,
  660. showConfirmButton: false,
  661. timer: 1000,
  662. backdrop: false
  663. })
  664. };
  665. $('.img-toggle').click(function(){
  666. $('.img-box').toggle(100);
  667. })