index.js 19 KB

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