var dtSearchTitleParam = []; var btnIsClick = true; var ajaxReloadCallBack; window.YT = window.YT || {}; YT.Math = {}; /// /// | Dropdown | 建置dropdown /// /// {btnId = 按鈕element Id ,dropdownId = 下拉選單 element Id} /// [{id = input element id , name = input element name, type = input element type, other = input element other attr, parent = sub parent element id }] $.fn.SetDropDown = function (eleObj, divObj) { let btnEle = $("#" + eleObj.btnId); let strHtml = ``; btnEle.wrap("
"); strHtml += ``; $(".dataTables_wrapper > .selector").append(btnTemp); } } else { if ($("#" + id).length != 0) { $("#" + id).click(); } } }) } /// /// | table Filter | Set Datatable filter tag title on table top /// /// executed datatable /// SearchCol index /// SearchCol value function setDtSearchTitle(dt, index, value) { let title = dt.context[0].aoColumns[index].filterName ?? dt.context[0].aoColumns[index].title; let search = value.sSearch; let filterName = dt.context[0].aoColumns[index].filterName ?? ""; if (filterName.indexOf("__TITLE__") != -1 || filterName.indexOf("__VALUE__") != -1) { filterName = filterName.replace("__TITLE__", title); filterName = filterName.replace("__VALUE__", search); return filterName } else { return title + " : " + search; } } /// /// | table Filter | Set "dtSearchTitleParam" variable, used to set Datatable filter title. /// /// paramter string function setDtSearchTitleParam(colName, param) { param != null ? dtSearchTitleParam.push({ "name": colName, "text": param }) : ""; } /// /// | table Filter | Cleaning Datatable search column when click filter tag icon. /// /// executed Datatable /// closeing filter icon element Id function closeDtSearchCol(dt, id, name) { let col = id.indexOf("dtSearch_") != -1 ? id.split("dtSearch_")[1] : ""; sessionStorage.removeItem(name); localStorage.removeItem(name); dt.column(col).search('').draw(false); } /// /// | table Filter | Load Datatable exists searching column (Session variable). /// function loadSesSearchCol() { $.each(Object.keys(sessionStorage), function (index, value) { if (value.indexOf(window.location.pathname) != -1) { let result = JSON.parse(Object.values(sessionStorage)[index]); let btnTemp = ``; $(".dataTables_wrapper > .selector").append(btnTemp); } }) } /// /// | table Filter | Cleaning Datatable search column when click filter tag icon (Session variable). /// /// executed Datatable /// session name /// tag label element function closeSesSearchCol(dt, name, obj) { sessionStorage.removeItem(name); obj.remove(); dt.ajax.reload(dtReloadFn, false); } function tabVis(dt) { let columnArr = dt.context[0].aoColumns; let strHtml = ``; $.each(columnArr, function (index, value) { strHtml += `
`; }) $("#table_filter").append(`
`) $("body").on("change", "input[id^=tabVis]", function () { let idx = $(this).data("idx"); let chk = $(this).prop("checked"); dt.columns(idx).visible(chk); dt.columns.adjust(); }) } var tabChkArr = []; function tableHeadChkNotSort(tabId) { $(`#${tabId} thead input:checkbox`).each(function (index, value) { $(value).parents("th").removeClass("sorting_asc"); $(value).parents("th").removeClass("sorting_desc"); }) } function loadTabChk(tabId) { $(`#${tabId}_wrapper thead tr th input:checkbox`).prop("checked", false); $.each(tabChkArr, function (index, value) { $(`${tabId} tbody tr td input:checkbox[data-rowid=${value.rowId}]`).prop("checked", true).change(); }) } /// /// | Sidebar | User headshot css adjusts on sidebar collapsing. /// $("html").on("mouseover", "body.sidebar-collapse .main-sidebar", function () { $(this).find(".logo-link").css("width", "250px").css("overflow", "visible"); $(this).find(".logo-link img").css("left", "0px"); $(this).find(".user-panel .info").show(); }).on("mouseleave", "body.sidebar-collapse .main-sidebar", function () { $(this).find(".logo-link").css("width", "37px").css("overflow", "hidden").css("margin", "auto"); $(this).find(".logo-link img").css("left", "-16px"); $(this).find(".user-panel .info").hide(); }) /// /// | Sidebar | User headshot css adjusts on sidebar collapsing. /// $("body").on("click", ".nav-link[data-widget=pushmenu]", function () { let obj = $(this).parents("body").find(".main-sidebar"); if ($(this).parents("body").hasClass("sidebar-collapse")) { obj.find(".logo-link").css("width", "250px").css("overflow", "visible") obj.find(".logo-link img").css("left", "0px"); obj.find(".user-panel .info").show(); } else { obj.find(".logo-link").css("width", "37px").css("overflow", "hidden").css("margin", "auto"); obj.find(".logo-link img").css("left", "-16px"); obj.find(".user-panel .info").hide(); } }) /// /// Set bootstrap modal and show /// /// warning, error ,success /// modal div element id /// modal header h4 tag title /// modal body content /// modal foot button function ShowModal(type = null, id, title, content, btnArr) { let btnHtml = ``, titleHtml = ``, conHtml = ``; //foot按鈕 if ($.isArray(btnArr) == true) { $.each(btnArr, (i, v) => { if (typeof v == "object") { let strData = ''; if (v.dataArr) { $.each(v.dataArr, function (index, value) { strData += "data-" + value.key + "=" + value.value; }) } btnHtml += ``; } }) } else { btnHtml = ``; } //header title if (typeof title == "object") { titleHtml += `` } else { titleHtml = ``; } //body content if (typeof content == "object") { conHtml += `

${content.text}

` } else { conHtml = ``; } let strHtml = ``; $("body").prepend(strHtml); $(`#${id}-Modal`).modal("show"); $("body").on("hidden.bs.modal", `#${id}-Modal`, function () { setTimeout(function () { $(`#${id}-Modal`).remove(); }, 500) }) } /// /// init load select2 on Html after shown Modal /// $("body").on("shown.bs.modal", "div[id$='-Modal']", function () { let table = $($.fn.dataTable.tables(true)).DataTable(); table.columns.adjust(); if ($("div[id$='-Modal'].show").length > 1) { $($("div[id$='-Modal'].show")[0]).css("z-index", parseInt($($("div[id$='-Modal'].show")[1]).css("z-index")) + 2); $(".modal-backdrop:last").css("z-index", parseInt($($("div[id$='-Modal'].show")[1]).css("z-index")) + 1); } select2bs4(); Date_Pic(); }) ///// ///// Modal hide show tip check exit. ///// //$("body").on("hide.bs.modal", "div[id$='-Modal'][aria-mode='noticeMode']:not([aria-close='true'])", function (e) { // console.log(e) // let ariaType = $(this).find(".modal-body").attr("aria-type"); // if (ariaType && ariaType != "read") { // let modalId = $(this).attr("id"); // let btnArr = [{ id: "_modalBackToEdit", text: "繼續編輯", class: "btn-secondary", dismiss: true }, { id: "_modalExit", text: "離開", dismiss:true,dataArr: [{ key: "id", value: modalId }]}] // ShowModal("warning", "closeModalWarning", "資料即將遺失", "資料不會被保存,確認離開此編輯頁面?", btnArr); // return false; // } //}) ///// ///// click modal tip check exit button. ///// //$("body").on("click", "#closeModalWarning-Modal #_modalExit", function (e) { // let modalId = $(this).data("id"); // $("#" + modalId).attr("aria-close", true); // $("#" + modalId).modal("hide"); // setTimeout(function () { // $("#" + modalId).removeAttr("aria-close"); // },1000) //}) /// /// init load select2 on Html after shown Modal /// $("body").on("hidden.bs.modal", "div[id$='-Modal']", function (e) { if ($("body > .modal-backdrop.show").length != 0) { $("body").addClass("modal-open"); } }) /// /// init load select2 on Html after shown Modal /// $("body").on("show.bs.modal", "div[id$='-Modal']", function () { if ($(this).find(".GiCouCode").length != 0) { $(this).find(".GiCouCode").change(); $(this).find(".GiCitCode").change(); } select2bs4(); Date_Pic(); }) /// /// init load select2 /// function select2bs4(selector = null) { selector = selector || ".select2bs4"; if ($(selector).length != 0) { $(selector).each((i, obj) => { let colArr = $(obj).classList().filter(x => x.indexOf("col-") != -1); colArr.length != 0 ? colArr.push("p-0") : ""; let $sel = $(obj).select2({ theme: 'bootstrap4', /* width: 'auto',*/ minimumResultsForSearch: -1, containerCssClass: $(obj).hasClass("form-control-sm") ? "form-control-sm" : "", }); $sel.data().select2.$container.addClass(colArr.join(" ")); //console.log($(obj).select2().data().select2) }) } function memSelFormat(icon) { let fbName = $(icon.element).data("fb"); let lineName = $(icon.element).data("line"); let realName = icon.text; let id = icon.id; return $(`${realName} ${memLineName(lineName, id)}${memFbName(fbName, id)}`); }; statusSelDraHtml(); $(selector).each((index, value) => { let selVal = $(value).data("read-value"); if (selVal !== undefined && selVal !== null && selVal !== "") { $(value).find(`option[value=${selVal}]`).prop("selected", true); $(value).change(); } }) } /// /// Set status select draw to html. /// function statusSelDraHtml() { if (typeof statusArr != "undefined") { let strHtml = ` `; $("select[data-seltype='status']").html(strHtml); } } /// /// Set table Ststus column value style. /// /// column value function setTableStatus(value) { let text = value == 1 ? statusArr[1] : value == 0 ? statusArr[0] : statusArr[9]; return ``; } /// /// | Upload-File | Limit images format on Upload form. /// function imgUploadFormat() { $("div[id^=preview]").parent("div").find("input[type='file']").attr("accept", "image/jpeg, image/png"); } /// /// Using Ajax get image. /// /// SysTabId /// RowId /// FilPurId /// FilKinId /// success callback function getImg(sysTabId, rowId, fpId, fkId, success) { Sccp5Ajax = new SCCP5.Ajax(varApiUrl + `sp_File_Sl/byParams?SysTabId=${sysTabId}&Rowid=${rowId}&FilPurId=${fpId}&FilKinId=${fkId}`, null, success).send(); } /// /// Read image through the path. /// /// imgName function readImg(imgName, thumb = false) { let result = ''; result = varPathImg + "/" + (thumb ? "s" : "") + (imgName || ""); return result; } /// /// Read image through the path. /// /// imgName function imgHtml(src, cls = null, width = 70, height = null) { let result = ''; if (src != null && src != "" && src != undefined) { result = `` } return result; } /// /// Json to base64 put on Url. /// /// Object function utoa(obj) { let result = btoa(unescape(encodeURIComponent(obj))); result = result.split("=")[0]; result = result.replace("+", "-"); result = result.replace("/", "_"); return result } /// /// Base64 convert to string /// /// string function atou(str) { let result = decodeURIComponent(escape(atob(str))); return result } /// /// Protecting the input element value overflows max value. /// /// Object $("body").on("keyup", "input[max]", function () { parseFloat($(this).val()) > parseFloat($(this).attr("max")) ? $(this).val($(this).attr("max")) : ""; }) /// /// Date Time Picker Initial /// function Date_Pic() { if ($.fn.datetimepicker) { $('i.fa-calendar').parents("div.date").datetimepicker({ format: 'YYYY/MM/DD', }); $('i.fa-clock').parents("div.date").datetimepicker({ format: 'HH:mm', }); } } /// /// Form disabled /// /// Object function formDisabled(id) { $(`form#${id} input,form#${id} select,form#${id} textarea`).prop("disabled", true); } /// /// Image full show on click. /// $("body").on("click", "img[data-extname]", function () { let ext = ["jpg", "jpeg", "png", "gif"]; if (ext.indexOf($(this).data("extname")) != -1) { $("body").append("
"); let strhtml = $($(this).clone()).addClass("image-full"); $(".image-full-show").html(strhtml); } }) /// /// Image full hide on click. /// $("body").on("click", ".image-full-show", function () { $(".image-full-show").remove(); }) /// /// decimal place on floor. /// function roundDown(num, decimal) { return Math.floor((num + Number.EPSILON) * Math.pow(10, decimal)) / Math.pow(10, decimal); } function setupSltAddress() { if ($(".GiCouCode,.GiCitCode,.GiPosCode").length != 0) { $(".GiCouCode").html(``); $(".GiCitCode").html(``); $(".GiPosCode").html(``); setupGiCouCode(); setupGiCitCode(); setupGiPosCode(); $(".GiCouCode").each((index, value) => { $(value).change(); }) } } // 0-4 //設定 "國家" 下拉選單 function setupGiCouCode() { //ajax 成功函式 function Success(data) { let htmlStr = ''; $.each(data, function (index, element) { htmlStr += ``; }); $(".GiCouCode").html(htmlStr); } Sccp5Ajax = new SCCP5.Ajax("/Utility/GetGiCountry", null, Success).send(); } // 0-4-1 //設定 "縣市" 下拉選單 function setupGiCitCode() { $("body").on("change", ".GiCouCode", function (e) { e.preventDefault(); let obj = this; let objName = $(obj).data("name"); let selectedText = $(this).find("option:selected").text(); $(this).next("span.select2").find(".select2-selection__rendered").text(selectedText).attr("title", selectedText); //抓國家碼 886 let GiCouCode = $(this).find("option:selected").val(); //判斷選取國家後是否有資料 $(obj).nextAll('.GiCitCode').length == 0 ? $(`select[data-name=${objName}].GiCitCode`).empty() : $(obj).nextAll('.GiCitCode').empty(); $(obj).nextAll('.GiPosCode').length == 0 ? $(`select[data-name=${objName}].GiPosCode`).empty() : $(obj).nextAll('.GiPosCode').empty(); if (GiCouCode == "") { return false } //ajax 成功函式 function Success(data) { let htmlStr = ``; let htmlStr2 = ``; $.each(data, function (index, element) { htmlStr += ``; }); $(obj).nextAll('.GiCitCode').length == 0 ? $(`select[data-name=${objName}].GiCitCode`).html(htmlStr) : $(obj).nextAll('.GiCitCode').html(htmlStr); $(obj).nextAll('.GiPosCode').length == 0 ? $(`select[data-name=${objName}].GiPosCode`).html(htmlStr2) : $(obj).nextAll('.GiPosCode').html(htmlStr2); } Sccp5Ajax = new SCCP5.Ajax("/Utility/GetGiCity?CountryCode=" + GiCouCode, null, Success).send(); }); //$(".GiCouCode").change(); } // 0-4-2 //設定 "鄉鎮區" 下拉選單 function setupGiPosCode() { $("body").on("change", ".GiCitCode", function (e) { e.preventDefault(); let obj = this; let objName = $(obj).data("name"); let htmlStr = ``; let selectedText = $(this).find("option:selected").text(); $(this).next("span.select2").find(".select2-selection__rendered").text(selectedText).attr("title", selectedText); let GiCouCode = $(this).parent("div").find(".GiCouCode option:selected").val(); let GiCitName = $(this).parent("div").find(".GiCitCode option:selected").text().split(" ")[1]; $(obj).nextAll('.GiPosCode').length == 0 ? $(`select[data-name=${objName}].GiPosCode`).html(htmlStr) : $(obj).nextAll('.GiPosCode').html(htmlStr); if (GiCouCode == "" || GiCitName == undefined) { return false } //ajax 成功函式 function Success(data) { //console.log(data); $.each(data, function (index, element) { htmlStr += ``; }); $(obj).nextAll('.GiPosCode').length == 0 ? $(`select[data-name=${objName}].GiPosCode`).html(htmlStr) : $(obj).nextAll('.GiPosCode').html(htmlStr); } Sccp5Ajax = new SCCP5.Ajax("/Utility/GetGiPosCode/byParams?CityName=" + GiCitName, null, Success).send(); }); //$(".GiCitCode").change(); } function chkboxToHtml(id, name, value, text, cls, other, dataArr = []) { let dataStr = ''; $.each(dataArr, function (index, v) { dataStr += `data-${v.key}='${v.value}' `; }) let result = `
${other ?? ""}
`; return result; } $("body").on("change", "input:checkbox[value='_all'],input:checkbox[value='_one']", function () { let togType = $(this).val().split("_")[1]; let chkName = $(this).attr("name"); let chked = $(this).prop("checked"); //相同name屬性 checkbox 皆勾選 $(`input:checkbox[name=${chkName}]`).prop("checked", chked); //觸發勾選 checkbox change事件 $(`input:checkbox[name=${chkName}]:not([value='_${togType}'])`).trigger("change", ["mannual"]); //最後element 觸發 ajax reload 事件 $(`input:checkbox[name=${chkName}]:not([value='_${togType}']):last`).change(); }) $("body").on("change", "input:checkbox[data-bindfilname]", function () { let chkName = $(this).data("bindfilname"); let chked = $(this).prop("checked"); $(`input:checkbox[name=${chkName}]`).prop("checked", chked); $(`input:checkbox[name=${chkName}]:not([value='_all']):last`).trigger("change", ["mannual"]); $(`input:checkbox[name=${chkName}]:not([value='_all']):last`).change(); }) $("body").on("change", "input:checkbox[name]", function () { //當有name的情況時,判斷若有全選checkbox,全部checked後全選checkbox按下。 let chkName = $(this).attr("name"); let chked = $(this).prop("checked"); chkBaseNameAll(chkName); chkBaseNameOne(chkName); chkBindFilNameChked(chkName, chked); }) /// /// | Checkbox | Base on checkbox element name execute all checked. /// function chkBaseNameAll(chkName) { let len = $(`input:checkbox[name=${chkName}]:not([value='_all'])`).length; $(`input:checkbox[value='_all'][name=${chkName}]`).prop("checked", false); $(`input:checkbox[name=${chkName}]:not([value='_all'])`).each((i, v) => { if (!$(v).prop("checked")) { return false; } len == i + 1 ? $(`input:checkbox[value='_all'][name=${chkName}]`).prop("checked", true) : ""; }) } /// /// | Checkbox | Tick If there is one. /// function chkBaseNameOne(chkName) { $(`input:checkbox[value='_one'][name=${chkName}]`).prop("checked", false); if ($(`input:checkbox[name=${chkName}]:not([value='_one']):checked`).length != 0) { $(`input:checkbox[value='_one'][name=${chkName}]`).prop("checked", true); } } /// /// | Checkbox | If the checkbox has 'bindfilname' dataset , auto checked. /// function chkBindFilNameChked(chkName, chked) { if (!chked) { chked = $(`input:checkbox[name=${chkName}]:checked`).length == 0 ? false : true; } $(`input:checkbox[data-bindfilname=${chkName}]`).prop("checked", chked); } function dataReadAttrbuite() { $("[data-read-type='checkbox'][data-read-value]").each(function (index, value) { let val = $(value).data("read-value"); if (val != undefined && val != null && val != "") { //example : 12,22,31,55 if (val.toString().indexOf(",") != -1) { $.each(val.split(","), function (index2, value2) { $(value).find(`input:checkbox[value=${value2}]`).prop("checked", true).change(); }) } //example : 22 else { $(value).find(`input:checkbox[value=${val}]`).prop("checked", true).change(); } } }) $("[data-read-type='text'][data-read-value]").each(function (index, value) { let val = $(value).data("read-value"); if (val != undefined && val != null && val != "") { //example : xxxx,xxxxxx,xxxxxxxxx,xxxxxxx if (val.toString().indexOf(",") != -1) { $.each(val.split(","), function (index2, value2) { $(value).find(`input[type=text]:eq(${index2})`).val(value2).change(); }) } //example : xxxxxx else { $(value).find(`input[type=text]:first`).val(val).change(); } } }) $("[data-read-type='radio'][data-read-value]").each(function (index, value) { let val = $(value).data("read-value"); if (val != undefined && val != null && val != "") { //example : 12,22,31,55 if (val.toString().indexOf(",") != -1) { $.each(val.split(","), function (index2, value2) { $(value).find(`input:radio[value=${value2}]`).prop("checked", true).change(); }) } //example : 22 else { $(value).find(`input:radio[value=${val}]`).prop("checked", true).change(); } } }) $("select[data-read-value]").each(function (index, value) { let selVal = $(value).data("read-value"); if (selVal !== undefined && selVal !== null && selVal !== "") { $(value).find(`option[value=${selVal}]`).prop("selected", true); $(value).change(); } }) } // custom tab // example : // //
$("body").on("click", "[data-tabname][data-target]", function () { let target = $(this).data("target"); let obj = this; let tabName = $(target).data("tabname"); if (tabName) { if ($(target).data("tabrole") == "child") { $(obj).trigger("yt:tab:show"); $(`[data-tabname='${tabName}'][data-tabrole='child']`).css("opacity", 0).hide(); $(target).show().animate({ opacity: 1 }, 200, function () { $(obj).trigger("yt:tab:shown"); }); } } }) function toBool(boolstr) { if (boolstr && typeof boolstr == "string") { return boolstr.toLowerCase() === "true"; } return null; } /** * 下載檔案 * @param {any} url * @param {any} filename */ async function download(url, filename) { let toDataURL = function (url) { return fetch(url).then((response) => { if (!response.ok) { throw new Error("Not 2xx response", { cause: response }); } else { return response.blob(); } }).then(blob => { return URL.createObjectURL(blob); }).catch(function (error) { return null; }); } const a = document.createElement("a"); let href = await toDataURL(url) if (href) { a.href = href; a.download = filename ? filename : ""; document.body.appendChild(a); a.click(); document.body.removeChild(a); return true; } else { return false; } } function onEvent(type, selector, callback) { $("body").off(type, selector); $("body").on(type, selector, callback); } /** * element array sort * @param {any} selector * @param {any} attrName */ function getSorted(selector, attrName) { return $($(selector).sort(function (a, b) { var aVal = parseInt($(a).attr(attrName)), bVal = parseInt($(b).attr(attrName)); return aVal - bVal; })); } //data-tourl $("body").on("click", "[data-tourl]", function () { let url = $(this).data("tourl"); if ($(this).data("target") == "_blank") { window.open(url, "_blank"); } else { location.href = url; } }); /** * * Base64 encode / decode * http://www.webtoolkit.info/ * **/ YT.Base64 = { // private property _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode: function (input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = YT.Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode: function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = YT.Base64._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode: function (string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode: function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } } YT.Url = function (url, ...other) { let paramArr = []; $.each(other, function (index, value) { if (typeof value == "object") { $.each(value, function (index2, value2) { if (value2 != null) { paramArr.push(index2 + "=" + value2); } }) } }) if (paramArr.length == 0) { if (url[url.length - 1] == "?") { url.splice(url.length - 1, 1); } } else { if (url.indexOf("?") == -1) { url += "?"; } else { if (url[url.length - 1] != "?") { url[url.length - 1] != "&" ? url + "&" : ""; } } } url = url + paramArr.join("&"); return url; } YT.Loading = function (type, ele = null, text = null, delay = 0) { if (type == "start") { let html = `
`; $("body").append(html) ele = YTAlert.Tip(text || "資料上傳中,請勿離開頁面。", "show"); return ele; } else if (type == "finish" && ele != null) { $(".yt-page-loading").fadeOut(); $(ele.ele).YTAlert().hide(delay); } }