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.

282 lines
11 KiB

2 years ago
  1. $(function () {
  2. 'use strict';
  3. var sLang = $('[http-equiv="content-language"]').attr('content') || 'zh-TW',
  4. win = $(window),
  5. iExhibitionTopCount = 5,
  6. iNewsTopCount = 4,
  7. org = null,
  8. bMobile = navigator.userAgent.match(/mobile/i),
  9. /*
  10. * 目的 初始化輪播圖片
  11. */
  12. fnSwiper = function () {
  13. var iLen = $(".bannerslide ul li").size();//抓數量
  14. var iRand_no = Math.floor(Math.random() * iLen);//避免零
  15. if ($(window).width() > 801) {
  16. var mySwiper = new Swiper('.bannerslide', {
  17. paginationClickable: true,
  18. slidesPerView: 'auto',
  19. loop: true,
  20. centeredSlides: true,
  21. spaceBetween: 0,
  22. initialSlide: 0,
  23. navigation: {
  24. nextEl: '.banner-next',
  25. prevEl: '.banner-prev'
  26. },
  27. autoplay: {
  28. delay: 5000
  29. },
  30. pagination: {
  31. el: '.swiper-pagination',
  32. clickable: true
  33. }
  34. });
  35. }
  36. else {
  37. var swiperBanner = new Swiper('.bannerslide', {
  38. autoplay: {
  39. delay: 5000
  40. },
  41. pagination: {
  42. el: '.swiper-pagination',
  43. clickable: true
  44. },
  45. loop: true,
  46. initialSlide: iRand_no
  47. });
  48. }
  49. },
  50. /*
  51. * 目的 抓去輪播
  52. */
  53. fnGetBanners = function (org) {
  54. return fnGetWebSiteSetting(function (saRes) {
  55. var sHtml = $('#temp_banner').render(saRes);
  56. if (saRes.length > 0) {
  57. $('.swiper-wrapper').html(sHtml);
  58. }
  59. fnSwiper();
  60. }, 'Carousel', sLang);
  61. },
  62. /*
  63. * 目的 抓去服務項目
  64. */
  65. fnGetService = function () {
  66. return fnGetWebSiteSetting(function (saRes) {
  67. var sHtml = $('#temp_service').render(saRes);
  68. if (saRes.length > 0) {
  69. $('#listservice').html(sHtml + '<p class="clear">&nbsp;</p>');
  70. }
  71. }, 'ServiceItems', sLang);
  72. },
  73. /*
  74. * 目的 抓去經典案例
  75. */
  76. fnGetClassicCase = function () {
  77. return fnGetWebSiteSetting(function (saRes) {
  78. if (saRes.length > 0) {
  79. var sHtmlTab = $('#temp_classiccasetab').render(saRes),
  80. sHtmlDiv = $('#temp_classiccasediv').render(saRes),
  81. iTabHeight = 320 / saRes.length + 'px';
  82. $('#tabsNav').html(sHtmlTab).find('li a');
  83. $('.tab_contentr').html(sHtmlDiv);
  84. // 預設顯示第一個 Tab
  85. var elTabFirst = $('#tabsNav li').eq(0);
  86. elTabFirst.addClass('active');
  87. if (!bMobile) {
  88. $('#tabsNav').find('li a').css({ height: iTabHeight, 'line-height': iTabHeight });
  89. elTabFirst.find('a').css('background-image', elTabFirst.attr('data-activeicon'));
  90. }
  91. else {
  92. $('#tabsNav li').find('a').css('background-image', 'none');
  93. }
  94. $('.tab_content').hide().eq(0).show();
  95. // 當 li 頁籤被點擊時...
  96. // 若要改成滑鼠移到 li 頁籤就切換時, 把 click 改成 mouseover
  97. $('#tabsNav li').click(function () {
  98. // 找出 li 中的超連結 href(#id)
  99. var $this = $(this),
  100. _clickTab = $this.find('a').attr('href');
  101. // 把目前點擊到的 li 頁籤加上 .active
  102. // 並把兄弟元素中有 .active 的都移除 class
  103. if (!bMobile) {
  104. }
  105. if (!bMobile) {
  106. $this.siblings('.active').each(function () {
  107. $(this).find('a').css('background-image', $(this).attr('data-icon'));
  108. });
  109. $this.find('a').css('background-image', $this.attr('data-activeicon'));
  110. }
  111. else {
  112. $this.siblings('.active').each(function () {
  113. $(this).find('a').css('background-image', 'none');
  114. });
  115. $this.find('a').css('background-image', 'none');
  116. }
  117. $this.addClass('active').siblings('.active').removeClass('active');
  118. // 淡入相對應的內容並隱藏兄弟元素
  119. $(_clickTab).stop(false, true).fadeIn(0).siblings().hide();
  120. return false;
  121. });
  122. }
  123. }, 'ClassicCase', sLang);
  124. },
  125. /*
  126. * 目的 設置視頻專區
  127. */
  128. fnGetVideo = function (org) {
  129. var sVideoUrl = { 'zh-TW': org.VideoUrl, 'zh': org.VideoUrl_CN, 'en': org.VideoUrl_EN }[sLang] || '';//_wyZT3laq8c,ztg_uJgfysU
  130. if (sVideoUrl) {
  131. $('#videoPlay').YTPlayer({
  132. fitToBackground: false,
  133. videoId: sVideoUrl,
  134. playerVars: {
  135. autoplay: 1,
  136. controls: 0,
  137. showinfo: 0,
  138. branding: 0,
  139. rel: 0,
  140. autohide: 1
  141. }
  142. });
  143. if (sLang === 'zh') {
  144. setTimeout(function () {
  145. var iframeVideo = $('<iframe frameborder=0 allow="autoplay; encrypted-media" allowfullscreen class="video" style="width: 623px; height: 350px; left: -13px; top: 0px;" src="' + sVideoUrl + '"/>');
  146. $('[id^="ytplayer-container"]').html('').append(iframeVideo);
  147. }, 2000);
  148. }
  149. }
  150. else {
  151. $('#videoPlay').css('background-image', 'url(' + (sLang === 'zh-TW' ? '' : '../') + 'images/comingsoon.jpg)');
  152. }
  153. },
  154. /*
  155. * 目的 設置最新消息圖檔
  156. */
  157. fnNewPic = function () {
  158. return g_api.ConnectLite(Service.apiwebcom, ComFn.GetNewsPage, {
  159. pageIndex: 1,
  160. pageSize: 1,
  161. NewsType: '01'
  162. }, function (res) {
  163. if (res.RESULT) {
  164. var oRes = res.DATA.rel,
  165. sNews_PicPath = oRes.DataList[0].News_PicPath || '';
  166. $('#newsbox').css('background-image', 'url(' + gServerUrl + '/' + sNews_PicPath.replace(/\\/g, "\/") + ')');
  167. }
  168. });
  169. },
  170. /*
  171. * 目的 設置展會花絮圖檔
  172. */
  173. fnPhotoPic = function () {
  174. return g_api.ConnectLite(Service.apiwebcom, ComFn.GetNewsPage, {
  175. pageIndex: 1,
  176. pageSize: 1,
  177. NewsType: '02'
  178. }, function (res) {
  179. if (res.RESULT) {
  180. var oRes = res.DATA.rel,
  181. sNews_PicPath = oRes.DataList[0].News_PicPath || '';
  182. $('#photobox').css('background-image', 'url(' + gServerUrl + '/' + sNews_PicPath.replace(/\\/g, "\/") + ')');
  183. }
  184. });
  185. },
  186. /*
  187. * 目的 抓去服務花絮前n筆
  188. */
  189. fnGetNewsTop = function () {
  190. return g_api.ConnectLite(Service.apiwebcom, ComFn.GetNewsPage, {
  191. pageIndex: 1,
  192. pageSize: iNewsTopCount,
  193. NewsType: '02'
  194. }, function (res) {
  195. if (res.RESULT) {
  196. var oRes = res.DATA.rel,
  197. sHtml = $('#temp_news').render(oRes.DataList);
  198. $('.news-box').html(sHtml);
  199. $(".rectThumb").imgLiquid({ fill: true });
  200. }
  201. });
  202. },
  203. /*
  204. * 目的 抓去展覽資訊前n筆
  205. */
  206. fnGetExhibitionsTop = function () {
  207. return g_api.ConnectLite(Service.apiwebcom, ComFn.GetExhibitionPage, {
  208. pageIndex: 1,
  209. pageSize: iExhibitionTopCount,
  210. IsShowWebSim: "Y",
  211. Top: true
  212. }, function (res) {
  213. debugger
  214. if (res.RESULT) {
  215. var oRes = res.DATA.rel,
  216. sHtml = $('#temp_expo').render(oRes.DataList);
  217. $('.expo-box').html(sHtml);
  218. $(".squareThumb").imgLiquid({ fill: false });
  219. }
  220. });
  221. },
  222. init = function () {
  223. var myHelpers = {
  224. setDate: function (date) {
  225. return new Date(date).formate('yyyy/MM/dd');
  226. },
  227. setRangeDate: function (date1, date2) {
  228. var r1 = new Date(date1).formate('yyyy/MM/dd'),
  229. r2 = new Date(date2).formate('MM/dd');
  230. return r1 + '-' + r2;
  231. },
  232. setFilePath: function (val) {
  233. val = val || '';
  234. return gServerUrl + '/' + val.replace(/\\/g, "\/");
  235. },
  236. setFileName: function (val) {
  237. return val.split('.')[0] || '';
  238. },
  239. setContent: function (val) {
  240. val = val || '';
  241. return val.length > 66 ? val.substr(0, 66) + '...' : val;
  242. }
  243. };
  244. $.views.helpers(myHelpers);
  245. // ani
  246. if (win.width() > 801) {
  247. win.scroll(function () {
  248. //service
  249. var getSerTop = $("#indexService").offset().top - 300;
  250. if ($(this).scrollTop() > getSerTop) {
  251. $(".indexServiceLeft").addClass("leftFlyIn");
  252. $(".indexServiceRight").addClass("rightFlyIn");
  253. }
  254. //indexCase
  255. var getCaseTop = $(".indexCaseLeft").offset().top - 300;
  256. if ($(this).scrollTop() > getCaseTop) {
  257. $(".indexCaseLeft, .indexCaseRight").addClass("fadeIn");
  258. }
  259. //indexlink
  260. var getLinkTop = $(".serviceLink").offset().top - 300;
  261. if ($(this).scrollTop() > getLinkTop) {
  262. $(".serviceLink").addClass("fadeIn");
  263. }
  264. });
  265. }
  266. runByOrgInfo(fnGetBanners, true);
  267. fnGetService();
  268. fnGetClassicCase();
  269. runByOrgInfo(fnGetVideo);
  270. fnNewPic();
  271. fnPhotoPic();
  272. //fnGetNewsTop();
  273. //fnGetExhibitionsTop();
  274. };
  275. init();
  276. });