function App_convertNLtoBr(content) { return content.replace(/(?:\r\n|\r|\n)/g, "
"); } function App_getScreenHeight() { return $(window).height(); } function App_getScreenWidth() { return $(window).width(); } function App_getDatePickerFormatValue($element, format) { var date = $element.data("DateTimePicker").date(); if(date == null) { return ""; } return date.format(format); } function App_getDatePickerFormatDateValue($element) { return App_getDatePickerFormatValue($element, "YYYY-MM-DD"); } /* function App_getDatePickerFormatDateTimeValue($element) { return App_getDatePickerFormatValue($element, "YYYY-MM-DD kk:mm:ss"); } function App_getDatePickerFormatDateTimeWithTimezoneValue($element) { return App_getDatePickerFormatDateTimeValue($element) + App_getDatePickerFormatValue($element, "ZZ").substr(0 ,3); } */ function App_getDatePickerFormatTimeValue($element) { return App_getDatePickerFormatValue($element, "kk:mm:ss"); } function App_getDatePickerFormatISO8601Value($element) { return App_getDatePickerFormatValue($element, null); } function App_convertISO8601StringToDate(date) { return new moment(date); } function App_convertTimeStringToDate(time) { return new moment(time, 'HH:mm:ssZZ'); } function App_datesDiff(date1, date2) { return date1.diff(date2); } function App_datesDiffHours(date1, date2) { return date1.diff(date2, "hours"); } function App_isDateBetweenDates(date, startDate, endDate) { return date.isBetween(startDate, endDate); } function App_isNowBetweenDates(startDate, endDate) { return new moment(new Date()).isBetween(startDate, endDate); } function App_isNowDiffDate(date) { return new moment(new Date()).diff(date); } function App_getDateWithTimeZoneOffset(timezoneOffset) { return new moment().utcOffset(timezoneOffset); } function App_getFormatDateString(date, format) { return new moment(date).format(format); } function App_getFormatISO8601String(date) { return App_getFormatDateString(date, null); } function App_getFormatLocaleDateString(date) { return App_getFormatDateString(date, "LL"); } function App_getFormatLocaleDateTimeString(date) { return App_getFormatDateString(date, "LLL"); } function App_getFormatLocaleDateTimeStringWithTimezone(date) { return App_getFormatDateString(date, "LLL") + " (GMT" + App_getFormatDateString(date, "ZZ") + ")"; } function App_getFormatLocaleDateTimeWeekString(date) { return App_getFormatDateString(date, "LLLL"); } function App_getFormatSlashDate(date) { return App_getFormatDateString(date, "YYYY/MM/DD"); } function App_getFormatSlashDateHourMinute(date) { return App_getFormatDateString(date, "YYYY/MM/DD HH:mm"); } function App_getFormatSlashDateHourMinuteWithTimezone(date) { return App_getFormatDateString(date, "YYYY/MM/DD HH:mm") + " (GMT" + App_getFormatDateString(date, "ZZ").substr(0 ,3) + ")"; } function App_getFormatSlashDateHourMinuteSecond(date) { return App_getFormatDateString(date, "YYYY/MM/DD HH:mm:ss"); } function App_getFormatSlashDateHourMinuteSecondWithTimezone(date) { return App_getFormatDateString(date, "YYYY/MM/DD HH:mm:ss") + " (GMT" + App_getFormatDateString(date, "ZZ").substr(0 ,3) + ")"; } function App_getFormatDate(date) { return App_getFormatDateString(date, "YYYY-MM-DD"); } function App_getFormatHourMinute(date) { return App_getFormatDateString(date, "HH:mm"); } function App_isDateAfterAnother(date, anotherDate) { return new moment(date).isAfter(new moment(anotherDate)); } function App_isDateBeforeAnother(date, anotherDate) { return new moment(date).isBefore(new moment(anotherDate)); } function App_isDateBetweenAnothers(date, anotherDate1, anotherDate2) { return new moment(date).isBetween(new moment(anotherDate1), new moment(anotherDate2)); } function App_isDateEqualToday(date) { return App_getFormatSlashDate(date) == App_getFormatSlashDate(new Date()); } function App_isDateInEarlyMorning(date) { var momentDate = new moment(date); if(momentDate.hour() == 0 && momentDate.minute() == 0 && momentDate.second() == 0) { return true; } return false } function App_getFormatNumberString(number, format) { return numeral(number).format(format); } function App_getFormatDisplayNumberString(number, fix) { var format = "0,0"; if(fix != null && fix > 0) { format += "."; for(var i = 0; i < fix; ++i) { format += "0"; } } return App_getFormatNumberString(number, format); } function App_getUnformatNumber(number) { return numeral().unformat(number); } function App_getDisplayString(content) { if(!System_checkIsEmptyString(content)) { return content; } return App_getNotDefinedString(); } function App_getNotDefinedString() { return "--"; } function App_mergeStringArray(contents, maxLength, divider) { if(maxLength == undefined) { maxLength = contents.length; } if(divider == undefined) { divider = ", "; } var output = ""; for(var i = 0; i < Math.min(contents.length, maxLength); ++i) { var content = contents[i]; if(content == null) { continue; } if(i > 0) { output += divider; } output += content; } if(contents.length > maxLength) { //output = App_omitString(output, maxLength); output += "..."; } return output; } function App_limitSize(size, limitWidth, limitHeight) { var widthRatio = 1; if(limitWidth != null) { widthRatio = limitWidth / size.width; } var heightRatio = 1; if(limitHeight != null) { heightRatio = limitHeight / size.height; } var ratio = ((widthRatio < heightRatio) ? widthRatio : heightRatio); ratio = Math.min(ratio, 1); return { width:(size.width*ratio), height:(size.height*ratio) }; } function App_checkBrowserIsIOS() { return (/iPhone|iPad|iPod/i.test(navigator.userAgent)); } function App_getAbsolutePosition($element) { var el = $element[0]; var found, left = 0, top = 0, width = 0, height = 0, offsetBase = util.getAbsolutePosition.offsetBase; if (!offsetBase && document.body) { offsetBase = util.getAbsolutePosition.offsetBase = document.createElement('div'); offsetBase.style.cssText = 'position:absolute;left:0;top:0'; document.body.appendChild(offsetBase); } if (el && el.ownerDocument === document && 'getBoundingClientRect' in el && offsetBase) { var boundingRect = el.getBoundingClientRect(); var baseRect = offsetBase.getBoundingClientRect(); found = true; left = boundingRect.left - baseRect.left; top = boundingRect.top - baseRect.top; width = boundingRect.right - boundingRect.left; height = boundingRect.bottom - boundingRect.top; } return { found: found, left: left, top: top, width: width, height: height, right: left + width, bottom: top + height }; } function App_setElementPositionToWindowCenter($dialog) { $dialog.position({ my:"center", at:"center", of: window }); } function App_scrollToBottom($element) { $element.scrollTop($element.prop("scrollHeight")); } function App_scrollToTop($element) { $element.scrollTop(0); } function App_scrollToPosX($element, posX, isAnim) { if(isAnim != null && isAnim == true) { $element.animate({ scrollLeft:posX }, 200); } else { $element.scrollLeft(posX); } } function App_scrollToPosY($element, posY, isAnim) { if(isAnim != null && isAnim == true) { $element.animate({ scrollTop:posY }, 200); } else { $element.scrollTop(posY); } } function App_willScrollToDocumentEnd(action) { $(document).scroll(function() { if ($(document).height() - window.innerHeight <= ($(window).scrollTop() + 10)) { if(action != null) { action(); } } }); } function App_titleAlert(message) { $.titleAlert(message, {stopOnMouseMove:true}); } function App_appendAppOverlay() { if($("#App_overlay") != null) { $("#App_overlay").remove(); } var $overlayElement = $('
'); $("body").append($overlayElement); return $overlayElement; } function App_removeAppOverlay() { $("#App_overlay").remove(); } function App_showDialog(options) { if(options.autoSize == null) { options.autoSize = false; } if(options.hasClose == null) { options.hasClose = true; } if(options.hasMask == null) { options.hasMask = true; } return $("
").dialogBox(options); } function App_relocateDialog($dialog) { $dialog.css({ 'margin-top': function(){ var height; if(type === '' || type === 'normal'){ if(that.settings.autoSize){ height = $(this).height(); }else{ height = that.settings.height; } }else if(type === 'error' || type === 'correct'){ if(that.settings.autoSize){ height = $(this).height(); }else{ height = that.settings.height + 4; } } return -Math.round(height/2) + 'px'; }, 'margin-left': function(){ var width = $(this).width(); return -Math.round(width/2) + 'px'; } }); } function App_toastr(message, title, onShownAction, onHiddenAction, onclickAction) { var options = { "positionClass": "toast-bottom-center" }; if(onShownAction != null) { options.onShown = onShownAction; } if(onHiddenAction != null) { options.onHidden = onHiddenAction; } if(onclickAction != null) { options.onclick = onclickAction; } toastr.success(message, title, options); } function App_horizontalTabs($element) { $element.hide(); $element.pwstabs({ theme:"pws_theme_cga", effect:"none", recordHistory:true }); var $horizontalTabElement = $element.parent(); if($horizontalTabElement != null) { var horizontalTabElementWidth = $horizontalTabElement.width(); $horizontalTabElement.find(".pws_tabs_controll").css("width", "200px"); $horizontalTabElement.find(".pws_tabs_list").css("width", ((horizontalTabElementWidth - 200 - 1) + "px"));//reduce border width "1" from theme "pws_theme_cga" } $element.show(); } function App_verticalTabs($element) { $element.hide(); $element.pwstabs({ theme:"pws_theme_cga", effect:"none", tabsPosition:"vertical", recordHistory:true }); var $verticalTabElement = $element.parent(); if($verticalTabElement != null) { var verticalTabElementWidth = $verticalTabElement.width(); $verticalTabElement.find(".pws_tabs_controll").css("width", "200px"); $verticalTabElement.find(".pws_tabs_list").css("width", ((verticalTabElementWidth - 200 - 1) + "px"));//reduce border width "1" from theme "pws_theme_cga" } $element.show(); } function App_generateElementId() { return "id_" + new Date().getTime() + "_" + Math.floor(Math.random() * 100000000); } function App_generateAutocompleteCellHtml(iconUrl, title, content) { var html = '
  • '; html += App_generateAutocompleteCellContentHtml(iconUrl, title, content); html += '
  • '; return html; } function App_generateAutocompleteCellContentHtml(iconUrl, title, content) { var html = '
    '; html += '
    '; html += ''; html += '
    '; html += '
    '; html += '
    ' + (!System_checkIsEmptyString(title)?title:"") + '
    '; html += '
    ' + (!System_checkIsEmptyString(content)?content:"") + '
    '; html += '
    '; html += '
    '; return html; } function App_dataURItoBlob(dataURI) { // convert base64/URLEncoded data component to raw binary data held in a string var byteString; if (dataURI.split(',')[0].indexOf('base64') >= 0) byteString = atob(dataURI.split(',')[1]); else byteString = unescape(dataURI.split(',')[1]); // separate out the mime component var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]; // write the bytes of the string to a typed array var ia = new Uint8Array(byteString.length); for (var i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } return new Blob([ia], {type:mimeString}); } function App_intlTelInput($input, countries) { if(countries == null) { countries = [ 'hk', 'au', 'at', 'by', 'cn', 'us', 'ar', 'bd', 'kh', 'ca', 'cl', 'co', 'hr', 'dk', 'eg', 'fi', 'fr', 'gr', 'ge', 'hu', 'id', 'ir', 'it', 'in', 'il', 'ie', 'jp', 'kw', 'li', 'lu', 'my', 'mo', 'mu', 'mx', 'nl', 'nz', 'ne', 'ng', 'no', 'pk', 'pa', 'pe', 'ph', 'pl', 'pt', 'sg', 'sa', 'si', 'kr', 'za', 'sb', 'es', 'se', 'ch', 'tw', 'th', 'tr', 'gb', 'ru', 'vn', 'ae', 'zw' ]; } $input.blur(function(e) { $(this).val($(this).val().trim()); }); $input.intlTelInput({ utilsScript: "https://game.abs.io/js/intl-tel-input-master/js/utils.js", onlyCountries: countries, dropdownContainer: "body" }); try { $input.intlTelInput("setCountry", "HK"); } catch(e) { } } function App_createCarousel($parent, itemHtmls, isShownIndicator, isLoop, isAutoScroll) { if(isShownIndicator == null) { isShownIndicator = false; } if(isLoop == null) { isLoop = true; } if(isAutoScroll == null) { isAutoScroll = true; } var carouselId = App_generateElementId(); var html = ''; $carousel = $(html); $parent.append($carousel); var carouselConfig = {"wrap": isLoop}; if(!isAutoScroll) { carouselConfig.interval = false; } $carousel.carousel(carouselConfig); return $carousel; } function App_gotoCarouselItem($carousel, number) { $carousel.carousel(number); } /* function App_createCarouselToShowMultipleElement($parent, itemHtmls, isShownIndicator, isLoop, isAutoScroll, sameTimeMaxElement) { var $carousel = App_createCarousel($parent, itemHtmls, isShownIndicator, isLoop, isAutoScroll); if(sameTimeMaxElement != null && sameTimeMaxElement > 1) { $carousel.find('.item').each(function() { $(this).children(':first-child').css("width", (100 / sameTimeMaxElement) + "%"); $(this).children(':first-child').css("max-width", (100 / sameTimeMaxElement) + "%"); $(this).children(':first-child').css("float", "left"); var next = $(this).next(); if (!next.length) { next = $(this).siblings(':first'); } var $clone = next.children(':first-child').clone(); $clone.css("width", (100 / sameTimeMaxElement) + "%"); $clone.css("max-width", (100 / sameTimeMaxElement) + "%"); $clone.css("float", "left"); $clone.appendTo($(this)); if (next.next().length>0) { $clone = next.next().children(':first-child').clone(); $clone.css("width", (100 / sameTimeMaxElement) + "%"); $clone.css("max-width", (100 / sameTimeMaxElement) + "%"); $clone.css("float", "left"); $clone.appendTo($(this)); } else { $clone = $(this).siblings(':first').children(':first-child').clone(); $clone.css("width", (100 / sameTimeMaxElement) + "%"); $clone.css("max-width", (100 / sameTimeMaxElement) + "%"); $clone.css("float", "left"); $clone.appendTo($(this)); } }); } var specialCss = $carousel.attr("id") + ' .carousel-inner .item.left.active {transform: translateX(-33%);}' + $carousel.attr("id") + ' .carousel-inner .item.right.active {transform: translateX(33%);}' + $carousel.attr("id") + ' .carousel-inner .item.next {transform: translateX(33%)}' + $carousel.attr("id") + ' .carousel-inner .item.prev {transform: translateX(-33%)}' + $carousel.attr("id") + ' .carousel-inner .item.right,.carousel-inner .item.left {transform: translateX(0);}'; $carousel.append(''); return $carousel; } */ function App_createCarousel2($parent, itemHtmls, isShownIndicator, isLoop, isAutoScroll, sameTimeMaxItemDisplayCount) { if(isShownIndicator == null) { isShownIndicator = false; } if(isLoop == null) { isLoop = true; } if(isAutoScroll == null) { isAutoScroll = true; } var finalItemCount = Math.ceil(itemHtmls.length / sameTimeMaxItemDisplayCount); var carouselId = App_generateElementId(); var html = ''; $carousel = $(html); $parent.append($carousel); var carouselConfig = {"wrap": isLoop}; if(!isAutoScroll) { carouselConfig.interval = false; } $carousel.carousel(carouselConfig); $carousel.find(".item > *").css("width", (100 / sameTimeMaxItemDisplayCount) + "%"); $carousel.find(".item > *").css("max-width", (100 / sameTimeMaxItemDisplayCount) + "%"); $carousel.find(".item > *").css("float", "left"); return $carousel; } function App_changeLocale(localeCode, action) { $.ajax({ url: "https://game.abs.io/api/user/set_locale", type: "POST", dataType: "json", data: { "locale":localeCode }, complete: function () { if(action != null) { action(); } else { location.reload(); } } }); } function App_closeDialog($dialog) { $dialog.parent().modal('hide'); } function App_getDialogByDialogButton($button) { return $button.parentsUntil(".modal-dialog").parent(); } function App_showDialogWithoutButton(dialogId, title, content, settings, onOpenAction, onCloseAction) { return App_showDialogWithButtonMaps( dialogId, title, content, settings, null, onOpenAction, onCloseAction); } function App_showDialogWithOkButton(dialogId, title, content, settings, onOpenAction, onCloseAction) { return App_showDialogWithButtonMaps( dialogId, title, content, settings, { "OK": function (e) { App_closeDialog(App_getDialogByDialogButton($(e.target))); } }, onOpenAction, onCloseAction); } function App_showDialogWithButtonMaps(dialogId, title, content, settings, buttonMap, onOpenAction, onCloseAction) { var dialogHtml = ''; var $modal = $(dialogHtml).modal({backdrop: true}); $modal.on('shown.bs.modal', function (event) { if(onOpenAction != null) { onOpenAction(event); } var buttonMapIndex = 0; for(var buttonMapKey in buttonMap) { $modal.find(".button_" + buttonMapIndex).click(function(event) { var $button = $(this); var buttonMapIndex2 = 0; var buttonFunction = null; for(var buttonMapKey2 in buttonMap) { if($button.attr("button-index") == buttonMapIndex2) { buttonFunction = buttonMap[buttonMapKey2]; break; } ++buttonMapIndex2; } if(buttonFunction != null) { buttonFunction(event); } return false; }); ++buttonMapIndex; } }); $modal.on('hidden.bs.modal', function () { $(this).prev(".modal-backdrop").remove(); $(this).remove(); }); if(onCloseAction != null) { $modal.on('hidden.bs.modal', function (event) { onCloseAction(event); }); } return $modal.find(".modal-dialog"); } function App_showDialogWithConfirmAndCancelButton(dialogId, title, content, settings, onConfirmAction, onCancelAction, onOpenAction, onCloseAction) { return App_showDialogWithButtonMaps( dialogId, title, content, settings, { "Confirm": function (e) { if(onConfirmAction != null) { onConfirmAction(e); } }, "\u53d6\u6d88": function (e) { if(onCancelAction != null) { onCancelAction(e); } App_closeDialog(App_getDialogByDialogButton($(e.target))); } }, onOpenAction, onCloseAction); } function App_showDialogWithLoadingAnimationConfirmAndCancelButton(dialogId, title, content, settings, onConfirmAction, onCancelAction, onOpenAction, onCloseAction) { return App_showDialogWithButtonMaps( dialogId, title, content, settings, { 'Confirm': function (e) { if(onConfirmAction != null) { onConfirmAction(e); } }, "\u53d6\u6d88": function (e) { if(onCancelAction != null) { onCancelAction(e); } App_closeDialog(App_getDialogByDialogButton($(e.target))); } }, onOpenAction, onCloseAction); } function App_logout(afterLogoutUrl) { } function System_cloneJson(inputJson) { return JSON.parse(JSON.stringify(inputJson)); } function System_checkIsEmptyString(content) { if(content == null || content.length == 0) { return true; } return false; } function System_historyBack() { history.back(-1); } //input type="email", must use this function to trim in mobile function System_forceTrimElementVal($element) { var backupVal = $element.val().trim(); $element.val(""); $element.val(backupVal); } function System_getFileExtension(path) { return path.split('.').pop(); } function System_getUrlHash(url) { var sharpSignIndex = url.indexOf('#'); if(sharpSignIndex != -1) { return url.substring(sharpSignIndex + 1); } return null; } function System_getUrlWithoutHash(url) { var sharpSignIndex = url.indexOf('#'); if(sharpSignIndex != -1) { return url.substring(0, sharpSignIndex); } return url; } //how to get parameter value: var fType = getUrlVars()["type"]; function System_getUrlParameters(url) { var vars = {}; var parts = url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { vars[key] = value; }); return vars; } function System_setUrlParameter(url, parameterName, parameterValue) { var urlParameters = System_getUrlParameters(url); urlParameters[parameterName] = parameterValue; var urlParameterNames = Object.keys(urlParameters); var newUrl = url.split("?")[0]; for(var i = 0; i < urlParameterNames.length; ++i) { var urlParameterName = urlParameterNames[i]; if(i > 0) { newUrl += "&"; } else { newUrl += "?"; } newUrl += urlParameterName + "=" + urlParameters[urlParameterName]; } return newUrl; } function System_selectValidValue(urlname, id) { return (!System_checkIsEmptyString(urlname) ? urlname : id); } function System_disableContenteditableElement($element, isDisabled) { if(isDisabled) { $element.attr("contenteditable", "false"); $element.attr("disabled", "disabled"); } else { $element.attr("contenteditable", "true"); $element.removeAttr("disabled"); } } function System_selectAllContenteditableElement($element) { if(!$element.is(":focus")) { $element.focus(); } if (document.body.createTextRange) { var range = document.body.createTextRange(); range.moveToElementText($element[0]); range.select(); } else if (window.getSelection) { var selection = window.getSelection(); var range = document.createRange(); range.selectNodeContents($element[0]); selection.removeAllRanges(); selection.addRange(range); } }