123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
-
- /* utlis */
-
- // if (typeof console == "undefined") {
- // window.console = {
- // log: function () {}
- // };
- // }
-
- // window.console = {
- // log: function () {}
- // };
-
- isLIVE = false;
-
- switch (window.location.host.toLowerCase()) {
-
- case 'infra.cecmartech.com:8077':
- isLIVE = false;
- break;
-
- case 'line.maltssociety.com.tw':
- isLIVE = true;
- break;
-
- case 'www.mortlach.com.tw':
- isLIVE = true;
- break;
- }
-
- console.log('isLIVE : ' + isLIVE);
-
- function gtag_pageView(_key) {
- //console.log("gtag_pageView: " + _key);
- }
-
- function gtag_ButtonClick(_key) {
- console.log("gtag_ButtonClick: " + _key);
-
- window.dataLayer = window.dataLayer || [];
- window.dataLayer.push({
- 'event': 'customEvent',
- 'eventCategory': 'Button',
- 'eventAction': 'Click',
- 'eventLabel': _key
- });
- }
-
- function setDefault(_textbox, _value) { // depend on jQuery
- $(_textbox).val(_value).css({ opacity: .4 });
- $(_textbox).focus(
- function () {
- if ($(this).val() == _value) {
- $(this).val('').css({ opacity: 1 });
- }
- })
- .blur(function () {
- if ($(this).val() == '') {
- $(this).val(_value).css({ opacity: .4 });
- }
- });
- }
-
- function getParameterByName(name, url) {
- if (!url) url = window.location.href;
- name = name.replace(/[\[\]]/g, "\\$&");
- var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
- results = regex.exec(url);
- if (!results) return null;
- if (!results[2]) return '';
- return decodeURIComponent(results[2].replace(/\+/g, " "));
- }
-
- function setParameterByName(name, value, url) {
- if (!url) url = window.location.href;
- var re = new RegExp("([?|&])" + name + "=.*?(&|$)", "i");
- separator = url.indexOf('?') !== -1 ? "&" : "?";
- if (url.match(re)) {
- return url.replace(re, '$1' + name + "=" + value + '$2');
- }
- else {
- return url + separator + name + "=" + value;
- }
- }
-
- function loadAnimate(_namespace, $container, _callback) {
- var $canvas, stage, exportRoot, anim_container, dom_overlay_container, fnStartAnimation;
-
- var key = Object.keys(this[_namespace].compositions)[0];
- var comp = this[_namespace].getComposition(key);
- var lib = comp.getLibrary();
-
- $canvas = $('<canvas></canvas>').attr({
- width: lib.properties.width,
- height: lib.properties.height
- }).appendTo($container);
-
- var loader = new createjs.LoadQueue(false);
- loader.addEventListener("fileload", function (evt) { handleFileLoad(evt, comp) });
- loader.addEventListener("complete", function (evt) { handleComplete(evt, comp) });
- loader.loadManifest(lib.properties.manifest);
-
- function handleFileLoad(evt, comp) {
- var images = comp.getImages();
- if (evt && (evt.item.type == "image")) { images[evt.item.id] = evt.result; }
- }
- function handleComplete(evt, comp) {
- var lib = comp.getLibrary();
- var ss = comp.getSpriteSheet();
- var queue = evt.target;
- var ssMetadata = lib.ssMetadata;
- for (i = 0; i < ssMetadata.length; i++) {
- ss[ssMetadata[i].name] = new createjs.SpriteSheet({ "images": [queue.getResult(ssMetadata[i].name)], "frames": ssMetadata[i].frames })
- }
- exportRoot = new lib[_namespace]();
- stage = new lib.Stage($canvas[0]);
- fnStartAnimation = function () {
- stage.addChild(exportRoot);
- createjs.Ticker.setFPS(lib.properties.fps);
- createjs.Ticker.addEventListener("tick", stage);
- exportRoot.stop();
- if (_callback != null) {
- _callback(exportRoot);
- }
- }
-
- this[_namespace].compositionLoaded(lib.properties.id);
- fnStartAnimation();
- }
- }
-
- function setCookie(name,value,days) {
- var expires = "";
- if (days) {
- var date = new Date();
- date.setTime(date.getTime() + (days*24*60*60*1000));
- expires = "; expires=" + date.toUTCString();
- }
- document.cookie = name + "=" + (value || "") + expires + "; path=/";
- }
- function getCookie(name) {
- var nameEQ = name + "=";
- var ca = document.cookie.split(';');
- for(var i=0;i < ca.length;i++) {
- var c = ca[i];
- while (c.charAt(0)==' ') c = c.substring(1,c.length);
- if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
- }
- return null;
- }
- function eraseCookie(name) {
- document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
- }
-
- function POST(theUrl, theData) {
- const _url = API__DOMAIN + theUrl;
- // console.log(JSON.stringify(theData))
- return fetch(_url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(theData)
- })
- .then((response) => {
- return response.json();
- }).then((jsonData) => {
- // const { success, msg } = jsonData;
- // if (!success) {
- // throw new Error(msg);
- // }
- console.log(jsonData)
- return jsonData;
- })
- // .catch((err) => {
- // throw new Error(err);
- // });
- }
-
- function GET(theUrl) {
- const _url = API__DOMAIN + theUrl;
- return fetch(_url, {})
- .then((response) => {
- return response.json();
- }).then((jsonData) => {
- console.log(jsonData)
- return jsonData;
- })
- // .catch((err) => {
- // throw new Error(err);
- // });
- }
-
- const PRE__LIFFID = '2000769399-lGpVNobN'; // 測試liffId待定
- const PRO__LIFFID = '2000844179-J80gOzVP'; // 正式liffId待定
- const LIFFID = (isLIVE) ? PRO__LIFFID : PRE__LIFFID;
-
- function liffInit() {
- return new Promise((resolve, reject) => {
- liff.init({
- liffId: LIFFID,
- }).then(() => {
- if (!liff.isLoggedIn() && !liff.isInClient()) {
- liff.login();
- } else {
- liff.getProfile().then((profile) => {
- resolve(profile);
- })
- .catch((err)=>{
- console.log(err)
- });
- }
- }).catch((err) => {
- reject(new Error(err));
- });
- });
- }
-
- function sleep(seconds) {
- return new Promise((resolve, reject) => {
- let _t = setTimeout(() => {
- clearTimeout(_t);
- _t - null;
- resolve();
- }, seconds);
- });
- }
-
- const _PRE__HOST = 'infra.cecmartech.com:8077';
- const _PRO__HOST = 'line.maltssociety.com.tw';
- const _URL = location.hostname;
- const _host = (_URL.indexOf(_PRO__HOST) != -1) ? _PRO__HOST : _PRE__HOST;
- const API__DOMAIN = location.protocol+'//' + _host;
-
-
- var isIE = false;
-
- utlis = function () {
-
- //private menbers
-
-
- //private methods
- function init() {
- console.log('all is loaded.');
- }
-
- //constructor
-
- {
- if ($('html').is('.ie6, .ie7, .ie8')) {
- isIE = true;
- // alert('.ie6, .ie7, .ie8');
- }
-
- $(document).ready(function () {
- init();
- });
- }
-
- //public
-
- return {
-
- }
- }
-
- utlis = new utlis();
|