utlis.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* utlis */
  2. // if (typeof console == "undefined") {
  3. // window.console = {
  4. // log: function () {}
  5. // };
  6. // }
  7. // window.console = {
  8. // log: function () {}
  9. // };
  10. isLIVE = false;
  11. switch (window.location.host.toLowerCase()) {
  12. case 'infra.cecmartech.com:8077':
  13. isLIVE = false;
  14. break;
  15. case 'event.leecy.org.tw':
  16. isLIVE = true;
  17. break;
  18. }
  19. console.log('isLIVE : ' + isLIVE);
  20. function gtag_pageView(_key) {
  21. //console.log("gtag_pageView: " + _key);
  22. }
  23. function gtag_ButtonClick(_key) {
  24. console.log("gtag_ButtonClick: " + _key);
  25. window.dataLayer = window.dataLayer || [];
  26. window.dataLayer.push({
  27. 'event': 'customEvent',
  28. 'eventCategory': 'Button',
  29. 'eventAction': 'Click',
  30. 'eventLabel': _key
  31. });
  32. }
  33. function setDefault(_textbox, _value) { // depend on jQuery
  34. $(_textbox).val(_value).css({ opacity: .4 });
  35. $(_textbox).focus(
  36. function () {
  37. if ($(this).val() == _value) {
  38. $(this).val('').css({ opacity: 1 });
  39. }
  40. })
  41. .blur(function () {
  42. if ($(this).val() == '') {
  43. $(this).val(_value).css({ opacity: .4 });
  44. }
  45. });
  46. }
  47. function getParameterByName(name, url) {
  48. if (!url) url = window.location.href;
  49. name = name.replace(/[\[\]]/g, "\\$&");
  50. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  51. results = regex.exec(url);
  52. if (!results) return null;
  53. if (!results[2]) return '';
  54. return decodeURIComponent(results[2].replace(/\+/g, " "));
  55. }
  56. function setParameterByName(name, value, url) {
  57. if (!url) url = window.location.href;
  58. var re = new RegExp("([?|&])" + name + "=.*?(&|$)", "i");
  59. separator = url.indexOf('?') !== -1 ? "&" : "?";
  60. if (url.match(re)) {
  61. return url.replace(re, '$1' + name + "=" + value + '$2');
  62. }
  63. else {
  64. return url + separator + name + "=" + value;
  65. }
  66. }
  67. function loadAnimate(_namespace, $container, _callback) {
  68. var $canvas, stage, exportRoot, anim_container, dom_overlay_container, fnStartAnimation;
  69. var key = Object.keys(this[_namespace].compositions)[0];
  70. var comp = this[_namespace].getComposition(key);
  71. var lib = comp.getLibrary();
  72. $canvas = $('<canvas></canvas>').attr({
  73. width: lib.properties.width,
  74. height: lib.properties.height
  75. }).appendTo($container);
  76. var loader = new createjs.LoadQueue(false);
  77. loader.addEventListener("fileload", function (evt) { handleFileLoad(evt, comp) });
  78. loader.addEventListener("complete", function (evt) { handleComplete(evt, comp) });
  79. loader.loadManifest(lib.properties.manifest);
  80. function handleFileLoad(evt, comp) {
  81. var images = comp.getImages();
  82. if (evt && (evt.item.type == "image")) { images[evt.item.id] = evt.result; }
  83. }
  84. function handleComplete(evt, comp) {
  85. var lib = comp.getLibrary();
  86. var ss = comp.getSpriteSheet();
  87. var queue = evt.target;
  88. var ssMetadata = lib.ssMetadata;
  89. for (i = 0; i < ssMetadata.length; i++) {
  90. ss[ssMetadata[i].name] = new createjs.SpriteSheet({ "images": [queue.getResult(ssMetadata[i].name)], "frames": ssMetadata[i].frames })
  91. }
  92. exportRoot = new lib[_namespace]();
  93. stage = new lib.Stage($canvas[0]);
  94. fnStartAnimation = function () {
  95. stage.addChild(exportRoot);
  96. createjs.Ticker.setFPS(lib.properties.fps);
  97. createjs.Ticker.addEventListener("tick", stage);
  98. exportRoot.stop();
  99. if (_callback != null) {
  100. _callback(exportRoot);
  101. }
  102. }
  103. this[_namespace].compositionLoaded(lib.properties.id);
  104. fnStartAnimation();
  105. }
  106. }
  107. function setCookie(name,value,days) {
  108. var expires = "";
  109. if (days) {
  110. var date = new Date();
  111. date.setTime(date.getTime() + (days*24*60*60*1000));
  112. expires = "; expires=" + date.toUTCString();
  113. }
  114. document.cookie = name + "=" + (value || "") + expires + "; path=/";
  115. }
  116. function getCookie(name) {
  117. var nameEQ = name + "=";
  118. var ca = document.cookie.split(';');
  119. for(var i=0;i < ca.length;i++) {
  120. var c = ca[i];
  121. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  122. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  123. }
  124. return null;
  125. }
  126. function eraseCookie(name) {
  127. document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
  128. }
  129. function POST(theUrl, theData) {
  130. console.log("API__DOMAIN: "+API__DOMAIN)
  131. const _url = API__DOMAIN + theUrl;
  132. // console.log(JSON.stringify(theData))
  133. return fetch(_url, {
  134. method: 'POST',
  135. headers: {
  136. 'Content-Type': 'application/json'
  137. },
  138. body: JSON.stringify(theData)
  139. })
  140. .then((response) => {
  141. return response.json();
  142. }).then((jsonData) => {
  143. // const { success, msg } = jsonData;
  144. // if (!success) {
  145. // throw new Error(msg);
  146. // }
  147. console.log(jsonData)
  148. return jsonData;
  149. })
  150. // .catch((err) => {
  151. // throw new Error(err);
  152. // });
  153. }
  154. function GET(theUrl) {
  155. // console.log("theUrl: "+theUrl)
  156. const _url = API__DOMAIN + theUrl;
  157. console.log("_url: "+_url)
  158. return fetch(_url, {})
  159. .then((response) => {
  160. return response.json();
  161. }).then((jsonData) => {
  162. console.log(jsonData)
  163. return jsonData;
  164. })
  165. // .catch((err) => {
  166. // throw new Error(err);
  167. // });
  168. }
  169. const PRE__LIFFID = '2000769399-lGpVNobN'; // 測試liffId
  170. const PRO__LIFFID = '2000844179-J80gOzVP'; // 正式liffId
  171. const LIFFID = (isLIVE) ? PRO__LIFFID : PRE__LIFFID;
  172. function liffInit() {
  173. return new Promise((resolve, reject) => {
  174. liff.init({
  175. liffId: LIFFID,
  176. }).then(() => {
  177. if (!liff.isLoggedIn() && !liff.isInClient()) {
  178. liff.login();
  179. } else {
  180. liff.getProfile().then((profile) => {
  181. resolve(profile);
  182. })
  183. .catch((err)=>{
  184. console.log(err)
  185. });
  186. }
  187. }).catch((err) => {
  188. reject(new Error(err));
  189. });
  190. });
  191. }
  192. function sleep(seconds) {
  193. return new Promise((resolve, reject) => {
  194. let _t = setTimeout(() => {
  195. clearTimeout(_t);
  196. _t - null;
  197. resolve();
  198. }, seconds);
  199. });
  200. }
  201. const _PRE__HOST = 'infra.cecmartech.com:8077';
  202. const _PRO__HOST = 'event.leecy.org.tw';
  203. const _URL = location.hostname;
  204. const _host = (_URL.indexOf(_PRO__HOST) != -1) ? 'https://' + _PRO__HOST : 'http://' + _PRE__HOST;
  205. const API__DOMAIN = _host;
  206. console.log(API__DOMAIN)
  207. var isIE = false;
  208. utlis = function () {
  209. //private menbers
  210. //private methods
  211. function init() {
  212. console.log('all is loaded.');
  213. }
  214. //constructor
  215. {
  216. if ($('html').is('.ie6, .ie7, .ie8')) {
  217. isIE = true;
  218. // alert('.ie6, .ie7, .ie8');
  219. }
  220. $(document).ready(function () {
  221. init();
  222. });
  223. }
  224. //public
  225. return {
  226. }
  227. }
  228. utlis = new utlis();