index.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. let result;
  2. $.ajax({
  3. method: "GET",
  4. url: "../json/realtime.json",
  5. dataType: "json",
  6. }).done(function (msg) {
  7. result = [...msg];
  8. renderSec00(result);
  9. renderSec02(result);
  10. renderSec05(result);
  11. renderSec06(result);
  12. renderSec07(result);
  13. renderSec08(result);
  14. renderSec09(result);
  15. renderSec10(result);
  16. renderVideo(result);
  17. renderTrending(result);
  18. });
  19. function renderSec00(data) {
  20. let temp = data[0]['data'];
  21. renderBannerStr('sec-00__slider', temp);
  22. $(".sec-00__slider").slick({
  23. dots: false,
  24. speed: 800,
  25. autoplay: true,
  26. autoplaySpeed: 5000
  27. });
  28. }
  29. function renderSec02(data) {
  30. let temp = data[1]['data'];
  31. renderBannerStr('sec-02__slider', temp);
  32. $(".sec-02__slider").slick({
  33. dots: false,
  34. autoplay: true,
  35. arrows: true,
  36. fade: true,
  37. autoplaySpeed: 4000,
  38. });
  39. }
  40. function renderBannerStr(sec, data) {
  41. let str = '';
  42. for(let i = 0; i < data.length; i++){
  43. str+= `<div class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['DimgUrl']}');"></div>`
  44. }
  45. $(`.${sec}`).html(str);
  46. }
  47. function renderSec05(data) {
  48. let randomIdx = Math.floor(Math.random()*3);
  49. const ran = $('.sec-05__tabdiv .nav-pills li').eq(randomIdx);
  50. const ranDiv = $('.sec-05tab-content>div').eq(randomIdx);
  51. $('.sec-05tab-content>div').hide();
  52. ranDiv.show();
  53. ran.addClass('active');
  54. ran.children().addClass('active');
  55. $('.sec-05 .morelink').attr('href', $('.sec-05__tabdiv .nav-item-link.active').data('link'));
  56. let temp = data[2]['data'];
  57. for(let i = 0; i < temp.length; i++){
  58. if(temp[i]["tab"] == '最夯設計'){
  59. let str = '';
  60. let sub = temp[i]["data"];
  61. for(let j = 0; j < sub.length; j++){
  62. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}');">
  63. <div class="tabpar__card__imgfr mb-2" style="background-image: url('${sub[j]['imgUrl']}');"></div>
  64. <h5 class="mb-2 me-2">${sub[j]['description']}</h5>
  65. <p class="mt-2">${sub[j]['description']}</p>
  66. </div>`;
  67. }
  68. $('#pills-hot-tab .tabpar').html(str);
  69. }
  70. if(temp[i]["tab"] == '影音實錄'){
  71. let str = '';
  72. let sub = temp[i]["data"];
  73. for(let j = 0; j < sub.length; j++){
  74. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}');">
  75. <div class="tabpar__card__imgfr mb-2" style="background-image: url('${sub[j]['imgUrl']}');"><img src="images/Play-Button.png" alt="" class="tabpar__card__play"></div>
  76. <h5 class="mb-2 me-2">${sub[j]['description']}</h5>
  77. <p class="mt-2">${sub[j]['description']}</p>
  78. </div>`;
  79. }
  80. $('#pills-video-tab .tabpar').html(str);
  81. }
  82. if(temp[i]["tab"] == '專欄文章'){
  83. let str = '';
  84. let sub = temp[i]["data"];
  85. for(let j = 0; j < sub.length; j++){
  86. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}');">
  87. <div class="tabpar__card__imgfr mb-2" style="background-image: url('${sub[j]['imgUrl']}');"></div>
  88. <h5 class="mb-2 me-2">${sub[j]['description']}</h5>
  89. <p class="mt-2">${sub[j]['description']}</p>
  90. </div>`;
  91. }
  92. $('#pills-blog-tab .tabpar').html(str);
  93. }
  94. }
  95. const cardText = document.querySelectorAll('.tabpar__card p');
  96. cardText.forEach((item, i) => {
  97. let len = item.textContent.length;
  98. if(len > 20) {
  99. let str = item.textContent.substring(0, 20) + '...';
  100. item.textContent = str;
  101. }
  102. })
  103. $('.sec-05__tabdiv .nav-pills button').on('click', function(event){
  104. event.preventDefault();
  105. $('.sec-05__tabdiv .nav-pills li').removeClass('active');
  106. $('.sec-05__tabdiv .nav-pills li button').removeClass('active');
  107. $(this).addClass('active');
  108. $(this).parent().addClass('active');
  109. $('.sec-05tab-content>div').hide();
  110. var target = $(this).attr('id');
  111. $(`#pills-tab #${target}`).show();
  112. $('.sec-05tab-content .tabpar').slick('setPosition');
  113. });
  114. $(`.sec-05tab-content .tabpar`).slick({
  115. arrows: true,
  116. slidesToShow: 3,
  117. infinite: false,
  118. dots: false,
  119. slidesToScroll: 1,
  120. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 35px;color: black;"></i></button>',
  121. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 35px;color: black;"></i></button>'
  122. });
  123. $('.sec-05__tabdiv .nav-item-link').click(function() {
  124. $('.sec-05 .morelink').attr('href',$('.sec-05__tabdiv .nav-item-link.active').data('link'));
  125. });
  126. }
  127. function renderSec06(data) {
  128. let temp = data[3]['data'];
  129. let str = '';
  130. for(let i = 0; i < temp.length; i++){
  131. if(temp[i].video == 'true'){
  132. str+= `<div class="sec-06__card" onclick="window.open('${temp[i]['link']}');">
  133. <div class="sec-06__card__outer"><div class="sec-06__card__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');"><img class="sec-06__card__play" src="images/Play-Button.png"></div></div>
  134. <h5 class="mb-2">${temp[i]['title']}</h5>
  135. <p class="mt-2">${temp[i]['description']}</p>
  136. </div>`;
  137. } else {
  138. str+= `<div class="sec-06__card" onclick="window.open('${temp[i]['link']}');">
  139. <div class="sec-06__card__outer"><div class="sec-06__card__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');"></div></div>
  140. <h5 class="mb-2">${temp[i]['title']}</h5>
  141. <p class="mt-2">${temp[i]['description']}</p>
  142. </div>`;
  143. }
  144. }
  145. $('.sec-06 .sec-06__slider').html(str);
  146. $('.sec-06__slider').slick({
  147. arrows: true,
  148. dots: false,
  149. speed: 800,
  150. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 30px;color: white;"></i></button>',
  151. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 30px;color: white;"></i></button>'
  152. });
  153. const cardText = document.querySelectorAll('.sec-06__card p');
  154. cardText.forEach((item, i) => {
  155. let len = item.textContent.length;
  156. if(len > 20) {
  157. let str = item.textContent.substring(0, 40) + '...';
  158. item.textContent = str;
  159. }
  160. });
  161. }
  162. function renderSec07(data) {
  163. let temp = data[5]['data'];
  164. let str = '';
  165. for(let i = 0; i < temp.length; i++){
  166. str+= `<div class="sec-07__slider-${i+1} slide-item" onclick="window.open('${temp[i]['link']}');" style="background-image: url('${temp[i]['imgUrl']}');"></div>`
  167. }
  168. $(`.sec-07__slider`).html(str);
  169. $(".sec-07__slider").slick({
  170. dots: false,
  171. autoplay: true,
  172. arrows: false,
  173. slidesToShow: 4,
  174. slidesToScroll: 1,
  175. autoplaySpeed: 7000,
  176. initialSlide: 0,
  177. infinite: true,
  178. });
  179. }
  180. function renderSec08(data) {
  181. let temp = data[4]['data'];
  182. let str = '';
  183. for(let i = 0; i < temp.length; i++){
  184. if(temp[i].video == 'true'){
  185. str+= `<div class="sec-08__slider-${i+1} sec-08__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  186. <div class="sec-08__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');"><img class="sec-08__card__play" src="images/Play-Button.png"></div>
  187. <h5 class="mb-2 me-2">${temp[i]['description']}</h5>
  188. </div>`;
  189. } else {
  190. str+= `<div class="sec-08__slider-${i+1} sec-08__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  191. <div class="sec-08__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');"></div>
  192. <h5 class="mb-2 me-2">${temp[i]['description']}</h5>
  193. </div>`;
  194. }
  195. }
  196. $('.sec-08__slider').html(str);
  197. $(".sec-08__slider").slick({
  198. arrows: true,
  199. slidesToShow: 1,
  200. infinite: false,
  201. dots: false,
  202. slidesToShow: 3,
  203. centerPadding: '12px',
  204. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 35px;color: black;"></i></button>',
  205. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 35px;color: black;"></i></button>'
  206. });
  207. const cardText = document.querySelectorAll('.sec-08__cardtxt');
  208. cardText.forEach((item, i) => {
  209. let len = item.textContent.length;
  210. if(len > 20) {
  211. let str = item.textContent.substring(0, 25) + '...';
  212. item.textContent = str;
  213. }
  214. })
  215. }
  216. function renderSec09(data) {
  217. let temp = data[6]['data'];
  218. let str = '';
  219. for(let i = 0; i < temp.length; i++){
  220. str+= `<div class="sec-09__slider-1 sec-09__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  221. <div class="sec-09__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');"></div>
  222. <p class="sec-09__cardtxt">${temp[i]['description']}</p>
  223. </div>`
  224. }
  225. $('.sec-09__slider').html(str);
  226. $(".sec-09__slider").slick({
  227. autoplay: true,
  228. autoplaySpeed: 7000,
  229. arrows: true,
  230. slidesToShow: 4,
  231. infinite: true,
  232. dots: false,
  233. slidesToScroll: 1,
  234. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 35px;color: black;"></i></button>',
  235. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 35px;color: black;"></i></button>'
  236. });
  237. }
  238. function renderSec10(data) {
  239. renderRecStr("sec-10", data[7]['data'].slice(0, 6));
  240. renderRecStr("sec-11", data[8]['data'].slice(0, 6));
  241. }
  242. function renderRecStr(sec, data) {
  243. let str = '';
  244. for(let i = 0; i < data.length; i++){
  245. if(data[i].video == 'true') {
  246. str+= `<div class="${sec}__card col-4 mb-3" onclick="window.open('${data[i]['link']}');">
  247. <div class="${sec}__card-img mb-2" style="background-image: url('${data[i]['imgUrl']}');"><img class="${sec}__card__play" src="images/Play-Button.png"></div>
  248. <h5 class="me-2">${data[i]['description']}</h5>
  249. <p class="${sec}__cardtxt me-2">${data[i]['description']}</p>
  250. </div>`
  251. } else {
  252. str+= `<div class="${sec}__card col-4 mb-3" onclick="window.open('${data[i]['link']}');">
  253. <div class="${sec}__card-img mb-2" style="background-image: url('${data[i]['imgUrl']}');"></div>
  254. <h5 class="me-2">${data[i]['description']}</h5>
  255. <p class="${sec}__cardtxt me-2">${data[i]['description']}</p>
  256. </div>`
  257. }
  258. }
  259. $(`.${sec} .row`).html(str);
  260. }
  261. function renderVideo(data) {
  262. let temp = data[9];
  263. console.log(data[9]);
  264. $('.sec-06__videotxt').text(temp['title']);
  265. console.log('test');
  266. $('.sec-06__video__imgfr').css('background-image', `url(https://img.youtube.com/vi/${temp['yt']}/hqdefault.jpg)`);
  267. $('#videoModal').on('shown.bs.modal', function () {
  268. $('#videoModal iframe').attr('src', `https://www.youtube.com/embed/${temp['yt']}?controls=0&autoplay=1&amp;enablejsapi=1&amp;origin=https%3A%2F%2Fm.hhh.com.tw&amp;widgetid=1`);
  269. });
  270. $('#videoModal').on('hidden.bs.modal', function () {
  271. $('#videoModal iframe').removeAttr('src');
  272. });
  273. }
  274. function renderTrending(result){
  275. let temp = result[10]['data'];
  276. let str = '';
  277. for(let i = 0; i < temp.length; i++){
  278. str += `<a class="dropbox__hots__link" href="https://hhh.com.tw/search/lists/case/${temp[i]}-keyword/">${temp[i]}</a>`
  279. }
  280. $('.dropbox__hots').html(`<strong class="dropbox__hots__title">熱搜關鍵字:</strong>${str}`);
  281. }
  282. function tab2 () {
  283. if(('.dropbox__tabdiv').length){
  284. // Show the first tab by default
  285. $('.dropbox-tab-content>div').hide();
  286. $('.dropbox-tab-content>div:first').show();
  287. $('.dropbox__tabdiv .nav-pills li:first').addClass('active');
  288. $('.dropbox__tabdiv .nav-pills li:first button').addClass('active');
  289. // Change tab class and display content
  290. $('.dropbox__tabdiv .nav-pills button').on('click', function(event){
  291. event.preventDefault();
  292. $('.dropbox__tabdiv .nav-pills li').removeClass('active');
  293. $('.dropbox__tabdiv .nav-pills li button').removeClass('active');
  294. $(this).addClass('active');
  295. $(this).parent().addClass('active');
  296. $('.dropbox-tab-content>div').hide();
  297. var target = $(this).attr('id');
  298. $(`#pills-tab-2 #${target}`).show();
  299. });
  300. }
  301. }
  302. tab2();
  303. window.addEventListener('scroll', fixedOnScroll);
  304. const navbar = document.querySelector('.navbar-main');
  305. function fixedOnScroll() {
  306. const sticky = 250;
  307. if(window.pageYOffset >= sticky){
  308. navbar.classList.add('sticky');
  309. } else {
  310. navbar.classList.remove('sticky');
  311. }
  312. }
  313. $(window).scroll(function() {
  314. if ( $(this).scrollTop() > 800 ){
  315. $('.fixed-btn').fadeIn(222);
  316. } else {
  317. $('.fixed-btn').stop().fadeOut(222);
  318. }
  319. }).scroll();
  320. $('.btn-gotop').click(function () {
  321. $('html, body').animate({
  322. scrollTop: 0
  323. }, 500)
  324. });
  325. $('.navbar-search img').click(function(){
  326. $('.navbar-search .dropbox').toggleClass('open');
  327. });
  328. // search
  329. const searchBtn = document.querySelector('.dropbox__searchBar__submit');
  330. const searchBar = document.querySelector('.dropbox__searchBar__input');
  331. searchBtn.addEventListener('click', search);
  332. searchBar.addEventListener('keyup', pressSearch);
  333. function search() {
  334. if(searchBar.value == '') {
  335. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  336. } else {
  337. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  338. console.log(`https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`)
  339. }
  340. }
  341. function pressSearch(e) {
  342. if (e.keyCode === 13) {
  343. e.preventDefault();
  344. search();
  345. }
  346. }
  347. function todayTV() {
  348. var utc = new Date().toJSON().slice(0,10).replace(/-/g,'-');
  349. window.open(`https://hhh.com.tw/program/?tv=gstv&date=${utc}&type=tv`);
  350. }
  351. // city result
  352. //jQuery time
  353. var current_fs, next_fs, previous_fs; //fieldsets
  354. var left, opacity, scale; //fieldset properties which we will animate
  355. var animating; //flag to prevent quick multi-click glitches
  356. $(".next").click(function(){
  357. if(animating) return false;
  358. animating = true;
  359. current_fs = $(this).parent().parent();
  360. next_fs = $(this).parent().parent().next();
  361. //activate next step on progressbar using the index of next_fs
  362. $(".form-progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  363. //show the next fieldset
  364. next_fs.animate({opacity: 1}, {
  365. step: function(now, mx) {
  366. //as the opacity of current_fs reduces to 0 - stored in "now"
  367. //1. scale current_fs down to 80%
  368. scale = 0 + (1 + now) * .5 ;
  369. //2. bring next_fs from the right(50%)
  370. left = (now * 50)+"%";
  371. //3. increase opacity of next_fs to 1 as it moves in
  372. opacity = 0 + now;
  373. next_fs.css({
  374. 'transform': 'scale('+scale+')',
  375. });
  376. next_fs.css({'opacity': opacity});
  377. },
  378. duration: 400,
  379. complete: function(){
  380. next_fs.show();
  381. animating = false;
  382. },
  383. //this comes from the custom easing plugin
  384. easing: 'easeInOutBack'
  385. });
  386. //hide the current fieldset with style
  387. current_fs.animate({opacity: 0}, {
  388. step: function(now, mx) {
  389. //as the opacity of current_fs reduces to 0 - stored in "now"
  390. //1. scale current_fs down to 80%
  391. scale = 1 - (1 - now) * 0.2;
  392. //2. bring next_fs from the right(50%)
  393. left = (now * 50)+"%";
  394. //3. increase opacity of next_fs to 1 as it moves in
  395. opacity = 1 - now;
  396. current_fs.css({
  397. 'transform': 'scale('+scale+')',
  398. });
  399. next_fs.css({'opacity': opacity});
  400. },
  401. duration: 400,
  402. complete: function(){
  403. current_fs.hide();
  404. animating = false;
  405. },
  406. //this comes from the custom easing plugin
  407. easing: 'easeInOutBack'
  408. });
  409. });
  410. /* const sec = document.querySelectorAll('.sec');
  411. const title = document.querySelectorAll('.title');
  412. const cover = document.querySelectorAll('.cover');
  413. const test_content = document.querySelectorAll('.test_content');
  414. function checkSlide() {
  415. console.log('pass');
  416. sec.forEach((block, i) => {
  417. // half way through the image
  418. //const test = document.querySelector('.test');
  419. const slideInAt = window.scrollY + window.innerHeight;
  420. console.log(slideInAt);
  421. //console.log(test.offsetTop);
  422. // bottom of the image
  423. const isHalfShown = slideInAt > block.offsetTop;
  424. if (isHalfShown) {
  425. console.log('active');
  426. title[i].style.bottom = '0em';
  427. cover[i].classList.add('slidein');
  428. test_content[i].classList.add('fadein');
  429. }
  430. })
  431. };
  432. window.addEventListener('scroll', checkSlide); */