index.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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]['title']}</h5>
  66. <p class="mt-2">${sub[j]['description']}</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]['title']}</h5>
  78. <p class="mt-2">${sub[j]['description']}</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]['title']}</h5>
  90. <p class="mt-2">${sub[j]['description']}</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]['title']}</h5>
  189. <p class="mb-2 me-2">${temp[i]['description']}</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]['title']}</h5>
  195. <p class="mb-2 me-2">${temp[i]['description']}</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. if(temp[i].video !== 'false') {
  224. str+= `<div class="sec-09__slider-1 sec-09__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  225. <div class="sec-09__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');"><img class="sec-09__card__play" src="images/Play-Button.png"></div>
  226. <p class="sec-09__cardtxt">${temp[i]['title']}</p>
  227. </div>`
  228. } else {
  229. str+= `<div class="sec-09__slider-1 sec-09__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  230. <div class="sec-09__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');"></div>
  231. <p class="sec-09__cardtxt">${temp[i]['title']}</p>
  232. </div>`
  233. }
  234. }
  235. $('.sec-09__slider').html(str);
  236. $(".sec-09__slider").slick({
  237. autoplay: true,
  238. autoplaySpeed: 7000,
  239. arrows: true,
  240. slidesToShow: 4,
  241. infinite: true,
  242. dots: false,
  243. slidesToScroll: 1,
  244. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 35px;color: black;"></i></button>',
  245. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 35px;color: black;"></i></button>'
  246. });
  247. }
  248. function renderSec10(data) {
  249. renderRecStr("sec-10", data[7]['data'].slice(0, 6));
  250. renderRecStr("sec-11", data[8]['data'].slice(0, 6));
  251. }
  252. function renderRecStr(sec, data) {
  253. let str = '';
  254. for(let i = 0; i < data.length; i++){
  255. //console.log(data[i]['description'].length);
  256. if(data[i]['description'].length > 0) {
  257. data[i]['description'].split(',');
  258. data[i]['description'] = data[i]['description'].split(',').slice(1).join("");
  259. }
  260. if(data[i].video !== 'false') {
  261. str+= `<div class="${sec}__card col-4 mb-3" onclick="window.open('${data[i]['link']}');">
  262. <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>
  263. <h5 class="me-2">${data[i]['title']}</h5>
  264. <p class="${sec}__cardtxt me-2">${data[i]['description']}</p>
  265. </div>`
  266. } else {
  267. str+= `<div class="${sec}__card col-4 mb-3" onclick="window.open('${data[i]['link']}');">
  268. <div class="${sec}__card-img mb-2" style="background-image: url('${data[i]['imgUrl']}');"></div>
  269. <h5 class="me-2">${data[i]['title']}</h5>
  270. <p class="${sec}__cardtxt me-2">${data[i]['description']}</p>
  271. </div>`
  272. }
  273. }
  274. $(`.${sec} .row`).html(str);
  275. const cardText = document.querySelectorAll(`.${sec}__card p`);
  276. cardText.forEach((item, i) => {
  277. let len = item.textContent.length;
  278. if(len > 20) {
  279. let str = item.textContent.substring(0, 20) + '...';
  280. item.textContent = str;
  281. }
  282. })
  283. }
  284. function renderVideo(data) {
  285. let temp = data[9];
  286. console.log(data[9]);
  287. $('.sec-06__videotxt').text(temp['title']);
  288. console.log('test');
  289. $('.sec-06__video__imgfr').css('background-image', `url(https://img.youtube.com/vi/${temp['yt']}/hqdefault.jpg)`);
  290. $('#videoModal').on('shown.bs.modal', function () {
  291. $('#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`);
  292. });
  293. $('#videoModal').on('hidden.bs.modal', function () {
  294. $('#videoModal iframe').removeAttr('src');
  295. });
  296. }
  297. function renderTrending(result){
  298. let temp = result[10]['data'];
  299. let str = '';
  300. for(let i = 0; i < temp.length; i++){
  301. str += `<a class="dropbox__hots__link" href="https://hhh.com.tw/search/lists/case/${temp[i]}-keyword/">${temp[i]}</a>`
  302. }
  303. $('.dropbox__hots').html(`<strong class="dropbox__hots__title">熱搜關鍵字:</strong>${str}`);
  304. }
  305. function tab2 () {
  306. if(('.dropbox__tabdiv').length){
  307. // Show the first tab by default
  308. $('.dropbox-tab-content>div').hide();
  309. $('.dropbox-tab-content>div:first').show();
  310. $('.dropbox__tabdiv .nav-pills li:first').addClass('active');
  311. $('.dropbox__tabdiv .nav-pills li:first button').addClass('active');
  312. // Change tab class and display content
  313. $('.dropbox__tabdiv .nav-pills button').on('click', function(event){
  314. event.preventDefault();
  315. $('.dropbox__tabdiv .nav-pills li').removeClass('active');
  316. $('.dropbox__tabdiv .nav-pills li button').removeClass('active');
  317. $(this).addClass('active');
  318. $(this).parent().addClass('active');
  319. $('.dropbox-tab-content>div').hide();
  320. var target = $(this).attr('id');
  321. $(`#pills-tab-2 #${target}`).show();
  322. });
  323. }
  324. }
  325. tab2();
  326. let sticky = 250;
  327. window.addEventListener('scroll', fixedOnScroll);
  328. const navbar = document.querySelector('.navbar-main');
  329. function fixedOnScroll() {
  330. if(window.pageYOffset >= sticky){
  331. navbar.classList.add('sticky');
  332. } else {
  333. navbar.classList.remove('sticky');
  334. }
  335. }
  336. $(window).scroll(function() {
  337. if ( $(this).scrollTop() > 800 ){
  338. $('.fixed-btn').fadeIn(222);
  339. } else {
  340. $('.fixed-btn').stop().fadeOut(222);
  341. }
  342. }).scroll();
  343. $('.btn-gotop').click(function () {
  344. $('html, body').animate({
  345. scrollTop: 0
  346. }, 500)
  347. });
  348. $('.navbar-search img').click(function(){
  349. $('.navbar-search .dropbox').toggleClass('open');
  350. });
  351. $('.sec-00__close').click(function(){
  352. $(this).css('display', 'none');
  353. $('.sec-00').addClass('bannerClose');
  354. //$('.sec-02').css('padding-top', '53px');
  355. sticky = 0;
  356. });
  357. // search
  358. const searchBtn = document.querySelector('.dropbox__searchBar__submit');
  359. const searchBar = document.querySelector('.dropbox__searchBar__input');
  360. searchBtn.addEventListener('click', search);
  361. searchBar.addEventListener('keyup', pressSearch);
  362. function search() {
  363. if(searchBar.value == '') {
  364. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  365. } else {
  366. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  367. console.log(`https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`)
  368. }
  369. }
  370. function pressSearch(e) {
  371. if (e.keyCode === 13) {
  372. e.preventDefault();
  373. search();
  374. }
  375. }
  376. function todayTV() {
  377. var utc = new Date().toJSON().slice(0,10).replace(/-/g,'-');
  378. window.open(`https://hhh.com.tw/program/?tv=gstv&date=${utc}&type=tv`);
  379. }
  380. // city result
  381. //jQuery time
  382. var current_fs, next_fs, previous_fs; //fieldsets
  383. var left, opacity, scale; //fieldset properties which we will animate
  384. var animating; //flag to prevent quick multi-click glitches
  385. $(".next").click(function(){
  386. if(animating) return false;
  387. animating = true;
  388. current_fs = $(this).parent().parent();
  389. next_fs = $(this).parent().parent().next();
  390. //activate next step on progressbar using the index of next_fs
  391. $(".form-progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  392. //show the next fieldset
  393. next_fs.animate({opacity: 1}, {
  394. step: function(now, mx) {
  395. //as the opacity of current_fs reduces to 0 - stored in "now"
  396. //1. scale current_fs down to 80%
  397. scale = 0 + (1 + now) * .5 ;
  398. //2. bring next_fs from the right(50%)
  399. left = (now * 50)+"%";
  400. //3. increase opacity of next_fs to 1 as it moves in
  401. opacity = 0 + now;
  402. next_fs.css({
  403. 'transform': 'scale('+scale+')',
  404. });
  405. next_fs.css({'opacity': opacity});
  406. },
  407. duration: 400,
  408. complete: function(){
  409. next_fs.show();
  410. animating = false;
  411. },
  412. //this comes from the custom easing plugin
  413. easing: 'easeInOutBack'
  414. });
  415. //hide the current fieldset with style
  416. current_fs.animate({opacity: 0}, {
  417. step: function(now, mx) {
  418. //as the opacity of current_fs reduces to 0 - stored in "now"
  419. //1. scale current_fs down to 80%
  420. scale = 1 - (1 - now) * 0.2;
  421. //2. bring next_fs from the right(50%)
  422. left = (now * 50)+"%";
  423. //3. increase opacity of next_fs to 1 as it moves in
  424. opacity = 1 - now;
  425. current_fs.css({
  426. 'transform': 'scale('+scale+')',
  427. });
  428. next_fs.css({'opacity': opacity});
  429. },
  430. duration: 400,
  431. complete: function(){
  432. current_fs.hide();
  433. animating = false;
  434. },
  435. //this comes from the custom easing plugin
  436. easing: 'easeInOutBack'
  437. });
  438. });
  439. /* const sec = document.querySelectorAll('.sec');
  440. const title = document.querySelectorAll('.title');
  441. const cover = document.querySelectorAll('.cover');
  442. const test_content = document.querySelectorAll('.test_content');
  443. function checkSlide() {
  444. console.log('pass');
  445. sec.forEach((block, i) => {
  446. // half way through the image
  447. //const test = document.querySelector('.test');
  448. const slideInAt = window.scrollY + window.innerHeight;
  449. console.log(slideInAt);
  450. //console.log(test.offsetTop);
  451. // bottom of the image
  452. const isHalfShown = slideInAt > block.offsetTop;
  453. if (isHalfShown) {
  454. console.log('active');
  455. title[i].style.bottom = '0em';
  456. cover[i].classList.add('slidein');
  457. test_content[i].classList.add('fadein');
  458. }
  459. })
  460. };
  461. window.addEventListener('scroll', checkSlide); */