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.

171 lines
6.6 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="{{:Link}}?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. if (pname.match('inquiry')){$("li#inquiry").addClass("selected");}else{};
  113. if (pname.match('exhibitions')){$("li#exhibitions").addClass("selected");}else{};
  114. //手機板選中時子選項要打開
  115. if (win.width() < 801) {
  116. $('#menu li.selected').children("ul").show();
  117. }
  118. // to top
  119. if (win.width() > 800) {
  120. win.scroll(function () {
  121. if ($(this).scrollTop() > 500) {
  122. $('#toTop').fadeIn(300);
  123. }
  124. else {
  125. $('#toTop').fadeOut(200);
  126. }
  127. });
  128. }
  129. $("#toTop").click(function () {
  130. $('html, body').animate({
  131. scrollTop: $("body").offset().top
  132. }, 1000);
  133. });
  134. $('.wechat').on('click', function () {
  135. $.fancybox.open({
  136. src: (sLang === 'zh-TW' ? '' : '../') + 'images/wx_euro.jpg',
  137. padding: 5,
  138. closeBtn: true
  139. });
  140. });
  141. fnSetMenu();
  142. fnGetNewsCount();
  143. window.scrollTo(0, 1);
  144. //menu for mobile
  145. mobile_menu.bind("click", mobile_open);
  146. //sub menu
  147. menu.bind("click", open);
  148. if (h1_bg.length > 0) {
  149. h1_bg.addClass("BG" + rand_no);
  150. }
  151. if (a_logo.length > 0 && typeof runByOrgInfo === 'function') {
  152. runByOrgInfo(fnSetLogo);
  153. }
  154. (function (i, s, o, g, r, a, m) {
  155. 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),
  156. m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m);
  157. })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
  158. ga('create', 'UA-97376330-1', 'auto');
  159. ga('send', 'pageview');
  160. $('.CherryBuy').hide();
  161. });