You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
6.4 KiB

2 years ago
  1. $(function () {
  2. var win = $(window),
  3. sLang = $('[http-equiv="content-language"]').attr('content') || 'zh-TW',
  4. bEn = sLang === 'en',
  5. mobile_menu = $("h4.openMenu"),
  6. mobile_submenu = $("ul#menu"),
  7. mobile_content = $("footer, header, article"),
  8. a_logo = $("#headerWrapper>header>h1>a"),
  9. h1_bg = $("#innerTitle.addBG"),
  10. menu = $("#left h4"),
  11. submenu = $("#left ul"),
  12. content = $("#right,h1"),
  13. rand_no = Math.floor((Math.random() * 3) + 1),//避免零
  14. paths = window.location.pathname.split(/[\/]/),
  15. pname = paths[paths.length - 1].split('.')[0],
  16. open = function () {
  17. submenu.toggle(200);
  18. content.bind("click", close);
  19. menu.toggleClass("gray");
  20. win.bind("scroll", close);
  21. },
  22. close = function () {
  23. submenu.fadeOut(200);
  24. content.unbind("click");
  25. menu.removeClass("gray");
  26. win.unbind("scroll");
  27. },
  28. mobile_open = function () {
  29. mobile_submenu.toggle(200);
  30. mobile_content.bind("click", mobile_close);
  31. mobile_menu.toggleClass("changColor");
  32. //win.bind("scroll",close);
  33. },
  34. mobile_close = function () {
  35. mobile_submenu.fadeOut(200);
  36. mobile_content.unbind("click");
  37. mobile_menu.removeClass("changColor");
  38. //win.unbind("scroll");
  39. },
  40. /*
  41. * 目的 設置logo
  42. */
  43. fnSetLogo = function (org) {
  44. g_api.ConnectLite(Service.apiappcom, ComFn.GetFileList, {
  45. ParentID: bEn ? org.WebsiteLgoId_EN : org.WebsiteLgoId
  46. }, function (res) {
  47. if (res.RESULT) {
  48. var saRes = res.DATA.rel;
  49. if (saRes.length > 0 && saRes[0].FilePath) {
  50. a_logo.attr('style', 'background-image: url(' + gServerUrl + '/' + saRes[0].FilePath.replace(/\\/g, "\/") + ');');
  51. }
  52. }
  53. });
  54. },
  55. /*
  56. * 目的 設置菜單
  57. */
  58. fnSetMenu = function (org) {
  59. return $.whenArray([
  60. fnGetWebSiteSetting(function (saRes) {
  61. var sHtml = $('<script />', { type: 'text/x-jsrender', html: '<li><a href="service.html?Id={{:Guid}}">{{:Title}}</a></li>' }).render(saRes);
  62. if (saRes.length > 0) {
  63. $('#service>ul').html(sHtml);
  64. }
  65. }, 'ServiceItems', sLang),
  66. fnGetWebSiteSetting(function (saRes) {
  67. var sHtml = $('<script />', { type: 'text/x-jsrender', html: '<li><a href="{{:Link}}?T={{:Guid}}">{{:Title}}</a></li>' }).render(saRes);
  68. if (saRes.length > 0) {
  69. $('#case>ul').html(sHtml);
  70. }
  71. }, 'ClassicCase', sLang)])
  72. .done(function () {
  73. //menu 效果
  74. $('#menu li').hover(function () {
  75. if (win.width() > 801) {
  76. $(this).css({ backgroundColor: "#333F48" });
  77. } else {
  78. $(this).css({ backgroundColor: "#cccccc" });
  79. $(this).siblings().children("ul").slideUp(400);//若選別的子選項關閉
  80. $(this).siblings().removeClass("selected");//若選別的則移除樣式
  81. }
  82. $(this).children('ul').stop(true, true).slideDown(200);
  83. }, function () {
  84. $(this).css({ backgroundColor: "" }).children('ul').stop(true, true).slideUp(400);
  85. });
  86. });
  87. },
  88. fnGetNewsCount = function () {
  89. g_api.ConnectLite(Service.apite, ComFn.GetNewsCount, {
  90. Lang: sLang
  91. }, function (res) {
  92. if (res.RESULT) {
  93. var iNewsCount = res.DATA.rel;
  94. if (iNewsCount > 0) {
  95. $('.news-tips').show();
  96. }
  97. else {
  98. $('.news-tips').hide();
  99. }
  100. }
  101. });
  102. };
  103. g_ul.SetLang(sLang);
  104. if (pname === "index" || pname === "") { $("li#index").addClass("selected"); }
  105. if (pname.match('about')) { $("li#about").addClass("selected"); } //只要檔名包含press就抓出來
  106. if (pname.match('online')) { $("li#online").addClass("selected"); }
  107. if (pname.match('video')) { $("li#video").addClass("selected"); }
  108. if (pname.match('news')) { $("li#news").addClass("selected"); }
  109. if (pname.match('service')) { $("li#service").addClass("selected"); }
  110. if (pname.match('case')) { $("li#case").addClass("selected"); }
  111. if (pname.match('contact')) { $("li#contact").addClass("selected"); }
  112. //手機板選中時子選項要打開
  113. if (win.width() < 801) {
  114. $('#menu li.selected').children("ul").show();
  115. }
  116. // to top
  117. if (win.width() > 800) {
  118. win.scroll(function () {
  119. if ($(this).scrollTop() > 500) {
  120. $('#toTop').fadeIn(300);
  121. }
  122. else {
  123. $('#toTop').fadeOut(200);
  124. }
  125. });
  126. }
  127. $("#toTop").click(function () {
  128. $('html, body').animate({
  129. scrollTop: $("body").offset().top
  130. }, 1000);
  131. });
  132. $('.wechat').on('click', function () {
  133. $.fancybox.open({
  134. src: (sLang === 'zh-TW' ? '' : '../') + 'images/wx_euro.jpg',
  135. padding: 5,
  136. closeBtn: true
  137. });
  138. });
  139. fnSetMenu();
  140. fnGetNewsCount();
  141. window.scrollTo(0, 1);
  142. //menu for mobile
  143. mobile_menu.bind("click", mobile_open);
  144. //sub menu
  145. menu.bind("click", open);
  146. if (h1_bg.length > 0) {
  147. h1_bg.addClass("BG" + rand_no);
  148. }
  149. if (a_logo.length > 0 && typeof runByOrgInfo === 'function') {
  150. runByOrgInfo(fnSetLogo);
  151. }
  152. (function (i, s, o, g, r, a, m) {
  153. i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o),
  154. m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m);
  155. })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
  156. ga('create', 'UA-97376330-1', 'auto');
  157. ga('send', 'pageview');
  158. });