123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872 |
- let userAgent;
- let isSafari = false;
- let browserName;
- // pagination variables
- let num_per_page = 9;
- let n = 0;
- let totalPages = {
- intro: 0,
- video: 0,
- columns: 0,
- vr360: 0,
- company: 0,
- };
- window.onload = function () {
- // hhh_user_api();
- if (screen.width < 991) {
- window.location.href = `https://m.hhh.com.tw/`;
- }
- userAgent = navigator.userAgent;
- detectBrowser(userAgent);
- // detectDirection();
- // let result;
- // $.ajax({
- // method: "GET",
- // url: "./hhh_index/json/realtime.json",
- // dataType: "json",
- // }).done(function (msg) {
- // result = [...msg];
- // console.log('result', result);
- // renderTopCarousel(result);
- // // renderBanner(result);
- // });
- // $('#navbar').load('https://hhh.com.tw/hhh-test/template/navbar.html');
- // $('#footer').load('https://hhh.com.tw/hhh-test/template/footer.html');
- // $('#btn-box').load('https://hhh.com.tw/hhh-test/template/button.html');
- // $('#topCarousel').load('https://hhh.com.tw/hhh-test/template/top_carousel.html');
- };
- function hhh_user_api_login() {
- window.location.href = `https://hhh.com.tw/users`;
- }
- let user_data = [];
- function hhh_user_api() {
- $.ajax({
- method: "post",
- url: "https://hhh.com.tw/adapter/index?http_method=GET&api_url=/base/v1/member/index",
- // async: false,
- dataType: "json",
- }).done(function (msg) {
- user_data = msg;
- let app_user = "";
- console.log('hhh_user_msg', msg);
- if (msg.status == "Success") {
- app_user += `
- <div class="dropdown">
- <button class="btn dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false" onclick="hhh_user_api_login()">
- <div class="d-flex align-items-center">
- <img src="${msg.data["user_avatar"]}" alt="" style="height: 32px; width: 32px;border-radius: 100px;">
- <p class="ms-2">${msg.data["name"]}</p>
- </div>
- </button>
- <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
- <li><a class="dropdown-item" href="https://hhh.com.tw/users">會員專區</a></li>
- </ul>
- </div>`;
- } else {
- app_user += `
- <a class="nav-link" href="javascript:;" onclick="hhh_user_api_login()">
- <section class="d-flex align-items-center">
- <img src="./img/icon/material-people.svg" alt="login" class="me-2" style="padding-top: 2px;" />
- <span class="pt-1">登入</span>
- </section>
- </a>`;
- }
- $("#app_user").html(app_user);
- }).fail(function (err) {
- console.log('err', err);
- });
- }
- hhh_user_api();
- // function detectDirection() {
- // let height = (window.screen.width * 5) / 12;
- // $(".sec-02 .slide-item").css("height", `${height}px`);
- // }
- function detectBrowser(agent) {
- if (userAgent.match(/chrome|chromium|crios/i)) {
- browserName = "chrome";
- } else if (userAgent.match(/firefox|fxios/i)) {
- browserName = "firefox";
- } else if (userAgent.match(/safari/i)) {
- browserName = "safari";
- } else if (userAgent.match(/opr\//i)) {
- browserName = "opera";
- } else if (userAgent.match(/edg/i)) {
- browserName = "edge";
- } else {
- browserName = "No browser detection";
- }
- if (browserName === "safari") {
- isSafari = true;
- }
- }
- // 範圍內取隨機整數(0-8)
- function getRandomInt(max) {
- return Math.floor(Math.random() * max);
- }
- function renderBanner(data) {
- let temp = data[1]["data"];
- // renderBullet(temp);
- // renderBannerStr("banner-slider", temp);
- let str = "";
- let img = "";
- if (window.innerWidth < 767) {
- // 手機版
- img = "imgUrl";
- } else {
- // 電腦版
- img = "Dwebp";
- }
- let adNamesMain = [];
- for (let i = 0; i < temp.length; i++) {
- let adNameMain = `${temp[i]["id"]}${temp[i]["alt"]}`;
- adNamesMain.push(adNameMain);
- str += `
- <a href="${temp[i]["link"]}" target="_blank" data-ga4="${temp[i]["id"]}${temp[i]["alt"]}">
- <section class="info-item">
- <span class="logo-img">
- <img class="img-${temp[i].logo_icon} ${temp[i].logo_icon === "" ? "d-none" : ""}" src="./img/index/banner_logo/${temp[i].logo_icon}.png">
- </span>
- <section class="${temp[i].index_char_1 === "" || temp[i].index_char_2_1 === "" || temp[i].index_char_2_2 === "" ? "d-none" : ""}">
- <h3>${temp[i].index_char_1}</h3>
- <div>
- <h2>${temp[i].index_char_2_1}</h2>
- <h2>
- ${temp[i].index_char_2_2}
- <small>${temp[i].index_char_2_3}</small>
- </h2>
- </div>
- </section>
- </section>
- <img class="banner-slider-${i + 1} slide-item img-fluid" src="${temp[i][`${img}`]}" data-bg="${temp[i][`${img}`]}" alt="${temp[i]["alt"]}" data_id="${temp[i]["id"]}${temp[i]["alt"]}">
- </a>`;
- }
- $(`.banner-slider`).html(str);
- //ga4-banners
- adNamesMain.forEach((adNameMain) => {
- document.querySelectorAll(`a[data-ga4="${adNameMain}"]`).forEach((element) => {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Banner_Click',
- 'ad_name': adNameMain,
- 'ad_location': '首頁大Banner'
- });
- });
- });
- });
- let randomInt = getRandomInt(8);
- let list_Top_Banner;
- let ad_first;
- //首頁大Banner ga4(一開始近來先送)剩下輪播送
- list_Top_Banner = document.querySelectorAll('.banner-slider .slide-item');
- //console.log('list_TOP:',list_Top_Banner[randomInt].getAttribute('data_id'))
- try {
- ad_first = list_Top_Banner[randomInt].getAttribute('data_id');
- } catch (e) {
- ad_first = '加載問題,所以請無視';
- console.log(ad_first);
- }
- dataLayer.push({
- 'event': 'Banner_Impression',
- 'ad_name': ad_first,
- 'ad_location': '首頁大Banner'
- });
- // 輪播設定
- $('.banner-slider').slick({
- dots: true,
- infinite: true,
- speed: 300,
- arrows: true,
- autoplay: true,
- autoplaySpeed: 4000,
- slidesToShow: 1,
- slidesToScroll: 1,
- centerMode: true,
- variableWidth: true,
- initialSlide: randomInt, // 起始順序
- prevArrow:
- '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="color: white;transform: translateY(-10px);"></i></button>',
- nextArrow:
- '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="color: white;transform: translateY(-10px);"></i></button>',
- responsive: [
- {
- breakpoint: 575,
- settings: {
- dots: false,
- arrows: false,
- }
- }
- ]
- });
- // 初始輪播外層新增 className
- try {
- list_Top_Banner[randomInt].parentNode.classList.add("slick-now");
- } catch (e) {
- console.log(e);
- }
- // On before slide change
- $('.banner-slider').on('beforeChange', function (event, { slideCount: count }, currentSlide, nextSlide) {
- let selectors = [nextSlide, nextSlide - count, nextSlide + count].map(n => `[data-slick-index="${n}"]`).join(', ');
- $('.slick-now').removeClass('slick-now');
- $(selectors).addClass('slick-now');
- });
- $('[data-slick-index="0"]').addClass('slick-now');
- }
- function renderBannerStr(sec, data) {
- let adNamesTop = [];
- let str = "";
- for (let i = 0; i < data.length; i++) {
- let adNameTop = `${data[i]["id"]}${data[i]["alt"]}`;
- adNamesTop.push(adNameTop);
- if (data[i]["Dwebp"]) {
- str += `
- <a href="${data[i]["link"]}" data-ga4="${data[i]["id"]}${data[i]["alt"]}">
- <img class="${sec}-${i + 1} slide-item img-fluid" src="${data[i]["Dwebp"]}" data-bg="${data[i]["Dwebp"]}" alt="${data[i]["alt"]}" data_id="${data[i]["id"]}${data[i]["alt"]}">
- </a>`;
- } else {
- str += `
- <a href="${data[i]["link"]}" data-ga4="${data[i]["id"]}${data[i]["alt"]}">
- <img class="${sec}-${i + 1} slide-item img-fluid" src="${data[i]["DimgUrl"]}" data-bg="${data[i]["DimgUrl"]}" alt="${data[i]["alt"]}" data_id="${data[i]["id"]}${data[i]["alt"]}">
- </a>`;
- }
- }
- $(`.${sec}`).html(str);
- //ga4-banners
- adNamesTop.forEach((adNameTop) => {
- document.querySelectorAll(`a[data-ga4="${adNameTop}"]`).forEach((element) => {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Banner_Click',
- 'ad_name': adNameTop,
- 'ad_location': '新刊頭'
- });
- });
- });
- });
- }
- $(window)
- .scroll(function () {
- if ($(this).scrollTop() > 800) {
- $(".fixed-btn").fadeIn(222);
- } else {
- $(".fixed-btn").stop().fadeOut(222);
- }
- })
- .scroll();
- $("#top-btn").click(function () {
- $("html, body").animate(
- {
- scrollTop: 0,
- },
- 500
- );
- });
- $(".slider-close-btn").click(function () {
- $(this).css("display", "none");
- sticky = 0;
- });
- document.addEventListener("lazybeforeunveil", function (e) {
- var bg = e.target.getAttribute("data-bg");
- if (bg) {
- e.target.style.backgroundImage = "url(" + bg + ")";
- }
- });
- function addToFavorite(cid) {
- if (user_data.data["uid"] == undefined) {
- Swal.fire({
- title: "請先登入",
- showConfirmButton: false,
- });
- $.ajax({
- url: "https://hhh.com.tw/hhhajax/save_http_referer",
- type: "post",
- datatype: "json",
- data: { http_referer: location.href },
- success: function () {
- location.href = "/login/index";
- },
- });
- }
- $.ajax({
- url: `https://hhh.com.tw/favorite/set?type=column&id=${cid}`,
- }).done(function (data) {
- if (data == 1) {
- $(".like").css("display", "block");
- $(".like-o").css("display", "none");
- } else {
- $(".like").css("display", "none");
- $(".like-o").css("display", "block");
- }
- });
- }
- function putEmail() {
- const emailPattern =
- /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
- if ($("#email").val() !== null && emailPattern.test($("#email").val())) {
- $("#error").hide();
- $("#putEmail_hidden").css("display", "block");
- $("#add_email").text($("#email").val());
- $("#email").val("");
- } else {
- $("#error").show();
- $("#error").text("email 格式有誤");
- }
- }
- $(".fm-close").click(() => {
- $("#putEmail_hidden").css("display", "none");
- $("#add_email").text("");
- });
- $("#putEmail").click(function (event) {
- $("#putEmail_hidden").show();
- const vm = $("#email").val();
- const emailPattern =
- /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
- if (vm.length == 0) {
- $("#error").show();
- $("#error").text("請輸入Email");
- $("#email").addClass("border-revise");
- $("#button-fm").addClass("fm-btn-border");
- $("#email").focus();
- return false;
- } else if (!emailPattern.test(vm)) {
- $("#error").show();
- $("#error").text("email 格式有誤");
- $("#email").addClass("border-revise");
- $("#button-fm").addClass("fm-btn-border");
- $("#email").focus();
- return false;
- // } else if (vm.length >= 5) {
- // $('#error').show();
- // $('#error').text('最多一次轉寄 5 封');
- // $('#email').addClass('border-revise');
- // $('#button-fm').addClass('fm-btn-border');
- //
- // $('#email').focus();
- // return false;
- } else {
- $("#email").removeClass("border-revise");
- $("#button-fm").removeClass("fm-btn-border");
- $("#error").hide();
- $("#add_email").text($("#email").val());
- $("#email").val("");
- }
- });
- $("#doSend").click(function (event) {
- stop = 0;
- var emailPattern =
- /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
- let this_url = window.location.href;
- // 如果 uid 為空代表沒登入(由於此寄信功能需要 uid 故需要先登入)
- if (user_data.data["uid"] == undefined) {
- $("#error").text("請先登錄/註冊會員帳號");
- stop = 1;
- } else if ($("#email").val() == "") {
- $("#error").text("收件人不得為空");
- stop = 1;
- } else {
- if (!emailPattern.test($("#email").val())) {
- $("#error").text("請以 email 格式填寫");
- stop = 1;
- }
- }
- if (stop == 0) {
- $("#error").text();
- $.ajax({
- url: "https://hhh.com.tw/adapter/index?http_method=POST&api_url=/base/v1/member/forward",
- type: "post",
- datatype: "json",
- data: {
- data: JSON.stringify({
- uid: user_data.data["uid"],
- sender: user_data.data["email"],
- recipient: $("#email").val(),
- url: this_url,
- subject: $("#title").val(),
- content: $("#content").val(),
- }),
- },
- success: function (result) {
- $("#forward_modal").modal("hide");
- Swal.fire({
- title: "發送成功",
- showConfirmButton: false,
- });
- $("#emailModal").modal("hide");
- },
- });
- }
- });
- /* 手機版輪播進度條 */
- //ga4-頂部廣告banner參數
- let adTop_count = []
- let time_top_count = 0
- $('.banner-slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) { // 頂部輪播(首頁大Banner)
- let list = document.querySelectorAll('.banner-slider .slide-item');
- //console.log(list[nextSlide+2].getAttribute('data_id'))
- let ad1 = list[nextSlide + 2].getAttribute('data_id');
- //由於剛進來就會送首頁大Banner的ga4,所以之後輪播時就不再送出
- if (time_top_count == 0) {
- let ad2 = list[nextSlide + 1].getAttribute('data_id');
- adTop_count.push(ad2);
- time_top_count = 1
- }
- //送dataLayer(要看得到廣告才送(電腦手機板不一樣))
- if ($('.banner-slider .slide-item').offset().top - $(window).scrollTop() > -330) {
- if (!adTop_count.includes(ad1)) {
- dataLayer.push({
- 'event': 'Banner_Impression',
- 'ad_name': ad1,
- 'ad_location': '首頁大Banner'
- });
- adTop_count.push(ad1);
- }
- }
- // 以下才是輪播
- let calc = ((nextSlide) / (slick.slideCount - 1)) * 100;
- $('.banner-content .progress')
- .css('background-size', calc + '% 100%')
- .attr('aria-valuenow', calc);
- });
- //ga4-中間廣告banner參數
- let ad_count = []
- $('.sub-banner-slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) { // 廣告區塊
- //ga4-送參數(電腦手機不一樣)
- let list = document.querySelectorAll('.sub-banner-slider .slide-item');
- let max_v = (list.length - 2) / 2
- let ad1 = list[currentSlide > 0 ? currentSlide - 1 : max_v - 1].getAttribute('data_id')
- let ad2 = list[currentSlide].getAttribute('data_id')
- //console.log(currentSlide-1,currentSlide)
- //console.log(ad1,ad2)
- //廣告位置(電腦手機不一樣)
- if ($('.container-fluid.py-4.sub-banner-content').offset().top - $(window).scrollTop() < 800 && $('.container-fluid.py-4.sub-banner-content').offset().top - $(window).scrollTop() > -154) {
- //送dataLayer
- if (!ad_count.includes(ad1)) {
- dataLayer.push({
- 'event': 'Banner_Impression',
- 'ad_name': ad1,
- 'ad_location': '首頁列表'
- });
- ad_count.push(ad1);
- }
- if (!ad_count.includes(ad2)) {
- dataLayer.push({
- 'event': 'Banner_Impression',
- 'ad_name': ad2,
- 'ad_location': '首頁列表'
- });
- ad_count.push(ad2);
- }
- }
- // 以下才是輪播
- let calc = ((nextSlide) / (slick.slideCount - 1)) * 100;
- $('.sub-banner-content .progress')
- .css('background-size', calc + '% 100%')
- .attr('aria-valuenow', calc);
- });
- let optionsSliderList = document.querySelectorAll('.options-slider'); // 廣告上方列表
- for (let i = 0; i < optionsSliderList.length; i++) {
- let count;
- let element;
- const progressBar = $(`.progress.item-0${i}`);
- const progressBarLabel = $('.slider-label');
- if (i === 0) {
- count = 2;
- element = $(`.space-slider.slider-0${i}`);
- } else {
- window.innerWidth < 415 ? count = 2 : count = 3;
- element = $(`.options-slider.slider-0${i}`);
- }
- element.on('beforeChange', function (event, slick, currentSlide, nextSlide) {
- let calc = ((nextSlide) / (slick.slideCount - count)) * 100;
- progressBar
- .css('background-size', calc + '% 100%')
- .attr('aria-valuenow', calc);
- progressBarLabel.text(calc + '% completed');
- });
- }
- let mainSliderList = document.querySelectorAll('.main-content .slider'); // 廣告下方列表
- let count;
- window.innerWidth < 415 ? count = 1 : count = 2;
- for (let i = 0; i < mainSliderList.length; i++) {
- let element = $(`.main-content .slider.item-0${i}`);
- const progressBar = $(`.main-content .progress.item-0${i}`);
- const progressBarLabel = $('.main-content .slider-label');
- element.on('beforeChange', function (event, slick, currentSlide, nextSlide) {
- let calc = ((nextSlide) / (slick.slideCount - count)) * 100;
- progressBar
- .css('background-size', calc + '% 100%')
- .attr('aria-valuenow', calc);
- progressBarLabel.text(calc + '% completed');
- });
- }
- /* 2024/02/21關閉 */
- // 廣告彈跳視窗 Modal
- /*
- (function createModal() {
- const newDiv = document.createElement("div");
- let str = `
- <div class="modal fade" id="adModal" tabindex="-1" aria-labelledby="adModalLabel" aria-hidden="true">
- <div class="modal-dialog modal-dialog-centered" style="max-width: 900px;">
- <div class="modal-content">
- <div class="modal-header">
- <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
- </div>
- <div class="modal-body p-0">
- <a href="https://hhh.style/hh12fMF7i" target="_blank">
- <img src="./img/20240207year.jpg" alt="" class="img-fluid">
- </a>
- </div>
- </div>
- </div>
- </div>`;
- newDiv.innerHTML = str;
- document.body.appendChild(newDiv);
- })();
- */
- /* 判斷閒置 */
- let defaultNum = 60; // 60 秒
- let maxTime = defaultNum;
- let intervalId;
- let time = maxTime;
- $('body').on('keydown mousemove mousedown', function (e) {
- maxTime = defaultNum; // Seconds
- time = maxTime; // Reset
- });
- runSetInterval();
- function runSetInterval() {
- intervalId = setInterval(function () {
- time--;
- if (time <= 0) {
- ShowInvalidLoginMessage();
- clearInterval(intervalId);
- }
- }, 1000)
- }
- $('#adModal').on('hide.bs.modal', function () {
- dialogTimeclose();
- runSetInterval();
- $('body').addClass('scrollable');
- });
- function dialogTimeclose() {
- time = maxTime;
- }
- function ShowInvalidLoginMessage() {
- $('#adModal').modal('show');
- }
- /* genjson_new 新版首頁 */
- let result;
- $.ajax({
- method: "get",
- url: "./json/data_index.json",
- // url: "https://m3.hhh.com.tw:18689/genjson_new?filename=realtime.json",
- dataType: "json",
- }).done((data) => {
- result = [...data];
- // 隱藏 loading
- $('body').removeClass('unscrollable');
- $('.loading-item').addClass('loading-hide');
- let ad = localStorage.getItem('ad');
- if (!ad) {
- localStorage.setItem('ad', true);
- $('#adModal').modal('show');
- } else {
- $('#adModal').modal('hide');
- $('body').addClass('scrollable');
- }
- // renderTopCarousel(result);
- renderBanner(result);
- renderData(result); // 廣告上方列表
- renderEventAd(result); // 廣告輪播
- renderTopic(); // 主題企劃
- renderDesigner(result); // 推薦設計師
- renderTabContent(result); // 最夯設計, 影音實錄, 專欄文章
- //ga4_Click
- document.querySelectorAll('a[data-ga4="By_Style"]').forEach(function (element) {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Inner_Click',
- 'section_name': '依照風格瀏覽設計'
- });
- });
- });
- document.querySelectorAll('a[data-ga4="By_Space"]').forEach(function (element) {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Inner_Click',
- 'section_name': '依照空間瀏覽設計'
- });
- });
- });
- document.querySelectorAll('a[data-ga4="By_Specialty"]').forEach(function (element) {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Inner_Click',
- 'section_name': '依照專長尋找專家'
- });
- });
- });
- document.querySelectorAll('a[data-ga4="By_Topic"]').forEach(function (element) {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Inner_Click',
- 'section_name': '主題企劃'
- });
- });
- });
- document.querySelectorAll('a[data-ga4="By_Designer"]').forEach(function (element) {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Inner_Click',
- 'section_name': '本週推薦設計師'
- });
- });
- });
- document.querySelectorAll('a[data-ga4="By_Editor"]').forEach(function (element) {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Inner_Click',
- 'section_name': '編輯精選'
- });
- });
- });
- document.querySelectorAll('a[data-ga4="Best_Design"]').forEach(function (element) {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Inner_Click',
- 'section_name': '最夯設計'
- });
- });
- });
- document.querySelectorAll('a[data-ga4="Latest_Video"]').forEach(function (element) {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Inner_Click',
- 'section_name': '最新影音實錄'
- });
- });
- });
- }).fail((error) => {
- console.log('genjson_new error', error);
- });
- $.ajax({
- method: "get",
- url: "./json/index-slider.json",
- async: false,
- dataType: "json",
- }).done((data) => {
- renderJsonData(data); // 依照空間尋找商品, 依照專長尋找設計師
- }).fail((error) => {
- console.log('error', error);
- });
- function renderJsonData(data) {
- data.map(e => {
- if (e.tab === "依照空間尋找商品") {
- let str = "";
- let SpaceProducts = [];
- for (let i = 0; i < e.data.length; i++) {
- let item = e.data[i];
- let SpaceProduct = `${item.name}`;
- SpaceProducts.push(SpaceProduct);
- str += `
- <div>
- <section>
- <span class="slide-img">
- <a href="${item.url}" target="_blank" data-ga4="${item.name}">
- <img class="slide-item img-fluid" src="${item.image}" alt="${item.name}">
- <h3>${item.name}</h3>
- </a>
- </span>
- </section>
- </div>`
- }
- $(".space-slider").html(str);
- //ga4-banners
- SpaceProducts.forEach((SpaceProduct) => {
- document.querySelectorAll(`a[data-ga4="${SpaceProduct}"]`).forEach((element) => {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'ShopBanner_Click',
- 'product_name': SpaceProduct
- });
- });
- });
- });
- // 輪播設定
- $('.space-slider').slick({
- infinite: false,
- slidesToShow: 4,
- slidesToScroll: 1,
- variableWidth: false,
- prevArrow:
- '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- nextArrow:
- '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- responsive: [
- {
- breakpoint: 991,
- settings: {
- slidesToShow: 3,
- slidesToScroll: 1
- }
- },
- {
- breakpoint: 767,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 1,
- }
- },
- {
- breakpoint: 575,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 1,
- variableWidth: true,
- arrows: false,
- }
- }
- ]
- });
- } else {
- let str = "";
- for (let i = 0; i < e.data.length; i++) {
- let item = e.data[i];
- str += `
- <div>
- <section>
- <span class="slide-img">
- <a href="${item.url}" target="_blank" data-ga4="By_Specialty">
- <img class="slide-item img-fluid" src="${item.image}" alt="${item.name}">
- <h3>${item.name}</h3>
- </a>
- </span>
- </section>
- </div>`
- }
- $(".options-slider.designer").html(str);
- }
- hideSlickArrow();
- })
- }
- let locationUrl = '';
- window.innerWidth > 767 ? locationUrl = "https://hhh.com.tw" : locationUrl = "https://m.hhh.com.tw";
- // 首頁廣告上方列表
- function renderData(data) {
- data.map((e) => {
- if (e._comment === "加好物商品") {
- renderDom("slider-01", e.data);
- } else if (e._comment === "首頁photo頁") {
- e.data.map((list, index) => {
- renderDom(`slider-0${index + 2}`, list.data);
- // $(`.slider-0${index + 1}-title`).text(list.tab);
- })
- }
- })
- // 輪播設定
- $('.options-slider').slick({
- infinite: false,
- slidesToShow: 6,
- slidesToScroll: 6,
- variableWidth: false,
- prevArrow:
- '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- nextArrow:
- '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- responsive: [
- {
- breakpoint: 1200,
- settings: {
- slidesToShow: 5,
- slidesToScroll: 5,
- }
- },
- {
- breakpoint: 991,
- settings: {
- slidesToShow: 4,
- slidesToScroll: 4
- }
- },
- {
- breakpoint: 767,
- settings: {
- slidesToShow: 3,
- slidesToScroll: 1,
- }
- },
- {
- breakpoint: 575,
- settings: {
- slidesToShow: 3,
- slidesToScroll: 1,
- variableWidth: true,
- arrows: false,
- }
- },
- {
- breakpoint: 415,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 1,
- variableWidth: true,
- arrows: false,
- }
- }
- ]
- });
- hideSlickArrow();
- }
- function renderDom(sec, data) {
- if (sec !== "slider-01" && sec == "slider-02") {
- data = data.sort((a, b) => a.order - b.order);
- let str = "";
- for (let i = 0; i < data.length; i++) {
- str += `
- <div>
- <section>
- <span class="slide-img">
- <a href="${locationUrl + data[i]["url"]}" target="_blank" data-ga4="By_Style">
- <img class="${sec}-${i + 1} slide-item img-fluid" src="${locationUrl + data[i]["image"]}" alt="${data[i]["name"]}">
- <h3>${data[i]["name"]}</h3>
- </a>
- </span>
- </section>
- </div>`
- }
- $(`.${sec}`).html(str);
- }
- else if (sec !== "slider-01" && sec == "slider-03") {
- data = data.sort((a, b) => a.order - b.order);
- let str = "";
- for (let i = 0; i < data.length; i++) {
- str += `
- <div>
- <section>
- <span class="slide-img">
- <a href="${locationUrl + data[i]["url"]}" target="_blank" data-ga4="By_Space">
- <img class="${sec}-${i + 1} slide-item img-fluid" src="${locationUrl + data[i]["image"]}" alt="${data[i]["name"]}">
- <h3>${data[i]["name"]}</h3>
- </a>
- </span>
- </section>
- </div>`
- }
- $(`.${sec}`).html(str);
- }
- else {
- data = data.sort(() => Math.random() - 0.5); // 隨機排序
- data = data.slice(0, 12); // 取前 12 筆
- let str = "";
- ShopProducts = [];
- for (let i = 0; i < data.length; i++) {
- let ShopProduct = `${data[i]["title"]}`;
- ShopProducts.push(ShopProduct);
- str += `
- <div>
- <section>
- <span class="slide-img">
- <a href="${data[i]["link"]}" target="_blank" data-ga4="${data[i]["title"]}">
- <img class="${sec}-${i + 1} slide-item img-fluid" src="${data[i]["imgUrl"]}" alt="${data[i]["title"]}">
- <h3>
- <strong>${data[i]["title"]}</strong>
- </h3>
- </a>
- </span>
- </section>
- </div>`
- }
- $(`.${sec}`).html(str);
- //ga4-banners
- ShopProducts.forEach((ShopProduct) => {
- document.querySelectorAll(`a[data-ga4="${ShopProduct}"]`).forEach((element) => {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'ShopBanner_Click',
- 'product_name': ShopProduct
- });
- });
- });
- });
- }
- }
- // let timer;
- // $(window).resize(function () {
- // // 延遲縮放
- // window.clearTimeout(timer);
- // timer = window.setTimeout(() => {
- // renderTopic();
- // }, 100);
- // })
- // 首頁主題企劃
- function renderTopic() {
- if (result) {
- result.map(list => {
- if (list._comment === "主題企劃區") {
- let webData = [];
- let mobileData = [];
- list.data.filter(e => {
- if (e.tab === "web") {
- webData = e.data;
- } else {
- mobileData = e.data;
- }
- });
- let arr;
- let str = "";
- // 固定取手機版第一筆
- let linkHref = `https://m.hhh.com.tw${mobileData[0].link}`;
- window.innerWidth > 767 ? arr = webData : arr = mobileData;
- let topicLink = document.querySelector(".topic-content .more-link");
- topicLink.setAttribute("href", linkHref);
- for (let i = 0; i < arr.length; i++) {
- str += `
- <div>
- <section>
- <span class="slide-img">
- <a href="${locationUrl + arr[i]["link"]}" target="_blank" data-ga4="By_Topic">
- <div class="img-box slide-img"> <img src="${arr[i]["imgUrl"]}" alt="${arr[i]["title"]}" class="img-fluid"></div>
- </a>
- </span>
- <a href="${locationUrl + arr[i]["link"]}" target="_blank" data-ga4="By_Topic">
- <h3 class="mt-2 ellipsis-title">${arr[i]["title"]}</h3>
- </a>
- </section>
- </div>`;
- }
- $('.topic-slider').html(str);
- // 輪播設定
- $('.topic-slider').slick({
- infinite: false,
- slidesToShow: 4,
- slidesToScroll: 4,
- variableWidth: false,
- prevArrow:
- '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- nextArrow:
- '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- responsive: [
- {
- breakpoint: 991,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 2,
- }
- },
- {
- breakpoint: 767,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 1,
- // variableWidth: true,
- // arrows: false,
- }
- },
- {
- breakpoint: 575,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 1,
- variableWidth: true,
- arrows: false,
- }
- },
- {
- breakpoint: 415,
- settings: {
- slidesToShow: 1,
- slidesToScroll: 1,
- variableWidth: true,
- arrows: false,
- }
- }
- ]
- });
- }
- });
- }
- }
- // 按鈕 hover
- $(function () {
- $('.top-card a, .center-card a')
- .on('mouseenter', function (e) {
- var parentOffset = $(this).offset(),
- relX = e.pageX - parentOffset.left,
- relY = e.pageY - parentOffset.top;
- $(this).find('span').css({ top: relY, left: relX })
- })
- .on('mouseout', function (e) {
- var parentOffset = $(this).offset(),
- relX = e.pageX - parentOffset.left,
- relY = e.pageY - parentOffset.top;
- $(this).find('span').css({ top: relY, left: relX })
- });
- });
- // 首頁廣告輪播
- function renderEventAd(data) {
- let adNames = [];
- data.map(list => {
- if (list._comment === "活動頁banners區") {
- let str = "";
- list.data = list.data.sort(() => Math.random() - 0.5); // 隨機排序
- for (let i = 0; i < list.data.length; i++) {
- let adName = `${list.data[i]["id"]}${list.data[i]["alt"]}`;
- adNames.push(adName);
- str += `
- <div>
- <a href="${list.data[i]["link"]}" target="_blank" data-ga4="${list.data[i]["id"]}${list.data[i]["alt"]}">
- <img class="slide-item img-fluid" src="${list.data[i]["webp"]}" alt="${list.data[i]["alt"]}" data_id="${list.data[i]["id"]}${list.data[i]["alt"]}">
- </a>
- </div>`
- }
- $('.sub-banner-content .sub-banner-slider').html(str);
- //ga4-banners
- adNames.forEach((adName) => {
- document.querySelectorAll(`a[data-ga4="${adName}"]`).forEach((element) => {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Banner_Click',
- 'ad_name': adName,
- 'ad_location': '首頁列表'
- });
- });
- });
- });
- }
- });
- // 輪播設定
- $('.sub-banner-content .sub-banner-slider').slick({
- dots: false,
- infinite: true,
- speed: 300,
- arrows: true,
- autoplay: true,
- autoplaySpeed: 4000,
- slidesToShow: 2,
- slidesToScroll: 1,
- prevArrow:
- '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- nextArrow:
- '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- responsive: [
- {
- breakpoint: 767,
- settings: {
- slidesToShow: 1,
- slidesToScroll: 1,
- }
- },
- {
- breakpoint: 575,
- settings: {
- slidesToShow: 1,
- slidesToScroll: 1,
- arrows: false
- }
- }
- ]
- });
- }
- // 隨機對調前後順序(e.g. 5678 1234)
- function randomArr(ary, num = 4) {
- // 取得隨機整數
- let randomVal;
- (Math.random() > 0.5) ? randomVal = 1 : randomVal = 0;
- let data = [...ary]; // 深拷貝
- let list = [];
- // index < 拆分的次數
- // 如陣列長度為 8 跟 12,拆分次數即為 2 跟 3
- // 例如:[8] => [4,4] or [12] => [4,4,4]
- for (let index = 0; index < 1; index++) {
- list.push(data.splice(num, num));
- // list.push(test.splice(4, 4));
- }
- list = list.sort(() => Math.random() - 0.5); // 隨機排序
- let finalData = [];
- if (randomVal) {
- finalData = data.concat(list);
- } else {
- finalData = list.concat(data);
- }
- return finalData.flat(Infinity) // 展開陣列
- }
- function renderDesigner(data) {
- data.map(list => {
- if (list._comment === "推薦設計師") {
- let randomData = randomArr(list.data, 6);
- let str = "";
- for (let i = 0; i < randomData.length; i++) {
- const item = randomData[i];
- str += `
- <div>
- <section>
- <span class="slide-img">
- <a href="${locationUrl + item.link}" target="_blank" data-ga4="By_Designer">
- <img class="slide-item img-fluid" src="${item.imgUrl}" alt="${item.name}|${item.designers_name}">
- <span class="img-border"></span>
- </a>
- </span>
- <a href="${locationUrl + item.link}" target="_blank" data-ga4="By_Designer">
- <h3 class="ellipsis-title">
- ${item.name}
- </h3>
- <h3 class="name">
- ${item.designers_name}
- <small>設計師</small>
- </h3>
- </a>
- </section>
- </div>`;
- }
- $('.designer-slider').html(str);
- // 輪播設定
- $('.designer-slider').slick({
- infinite: false,
- slidesToShow: 6,
- slidesToScroll: 6,
- variableWidth: false,
- prevArrow:
- '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- nextArrow:
- '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- responsive: [
- {
- breakpoint: 1200,
- settings: {
- slidesToShow: 4,
- slidesToScroll: 4,
- }
- },
- {
- breakpoint: 767,
- settings: {
- slidesToShow: 3,
- slidesToScroll: 3,
- }
- },
- {
- breakpoint: 575,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 1,
- variableWidth: true,
- arrows: false,
- }
- },
- ]
- });
- hideSlickArrow();
- $(".designer-content h3").hover(
- function () {
- $(this).parent().prev().children().children('.img-border').css('opacity', '1');
- }, function () {
- $(this).parent().prev().children().children('.img-border').css('opacity', '0');
- }
- );
- }
- });
- }
- function renderTabContent(data) {
- data.map(list => {
- if (list._comment === "tab區塊-最夯設計, 影音實錄, 專欄文章") {
- list.data.map(item => {
- if (item.tab === "編輯精選") {
- let randomData = randomArr(item.data);
- let str = "";
- let tagList = [];
- for (let i = 0; i < randomData.length; i++) {
- const item = randomData[i];
- str += `
- <div>
- <section>
- <span class="slide-img">
- <a href="${locationUrl + item.link}" target="_blank" data-ga4="By_Editor">
- <img class="slide-item img-fluid" src="${item.imgUrl}" alt="${item.title}">
- </a>
- </span>
- <a href="${locationUrl + item.link}" target="_blank" class="title" data-ga4="By_Editor">
- <h3 class="mb-0 ellipsis-title">${item.title}</h3>
- </a>
- <div class="tab-block tag-list-${i}"></div>
- </section>
- </div>`;
- tagList.push(item.ctag);
- }
- $('.featured-slider').html(str);
- // 輪播設定
- $('.featured-slider').slick({
- infinite: false,
- slidesToShow: 4,
- slidesToScroll: 4,
- variableWidth: false,
- prevArrow:
- '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- nextArrow:
- '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- responsive: [
- {
- breakpoint: 991,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 2,
- }
- },
- {
- breakpoint: 767,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 2,
- // variableWidth: true,
- // arrows: false,
- }
- },
- {
- breakpoint: 575,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 2,
- variableWidth: true,
- arrows: false,
- }
- },
- {
- breakpoint: 415,
- settings: {
- slidesToShow: 1,
- slidesToScroll: 1,
- variableWidth: true,
- arrows: false,
- }
- }
- ]
- });
- hideSlickArrow(); // 判斷輪播按鈕顯示
- randomTag(randomData, tagList, "featured-content"); // 渲染標籤
- } else if (item.tab === "最夯設計") {
- let randomData = randomArr(item.data);
- let str = "";
- let tagList = [];
- for (let i = 0; i < randomData.length; i++) {
- const item = randomData[i];
- str += `
- <div>
- <section>
- <span class="slide-img">
- <a href="${locationUrl + item.link}" target="_blank" data-ga4="Best_Design">
- <img class="slide-item img-fluid" src="${item.imgUrl}" alt="${item.title}">
- </a>
- <a href="${locationUrl + item.link}" target="_blank" class="designer-item" data-ga4="Best_Design">
- <img class="slide-item img-fluid" src="${item.img_designer}" alt="${item.title_designer}">
- <h2>${item.title_designer}</h2>
- </a>
- <a href="${locationUrl + item.link}" target="_blank" class="title" data-ga4="Best_Design">
- <h3 class="mb-0 ellipsis-title">${item.title}</h3>
- </a>
- </span>
- <div class="tab-block tag-list-${i}"></div>
- </section>
- </div>`;
- tagList.push(item.ctag);
- }
- $('.popular-slider').html(str);
- // 輪播設定
- $('.popular-slider').slick({
- infinite: false,
- slidesToShow: 4,
- slidesToScroll: 4,
- variableWidth: false,
- prevArrow:
- '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- nextArrow:
- '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- responsive: [
- {
- breakpoint: 991,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 2,
- }
- },
- {
- breakpoint: 767,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 2,
- // variableWidth: true,
- // arrows: false,
- }
- },
- {
- breakpoint: 575,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 2,
- variableWidth: true,
- arrows: false,
- }
- },
- {
- breakpoint: 415,
- settings: {
- slidesToShow: 1,
- slidesToScroll: 1,
- variableWidth: true,
- arrows: false,
- }
- },
- ]
- });
- hideSlickArrow(); // 判斷輪播按鈕顯示
- randomTag(randomData, tagList, "popular-content"); // 渲染標籤
- } else if (item.tab === "最新影音實錄") {
- let randomData = randomArr(item.data);
- let str = "";
- for (let i = 0; i < randomData.length; i++) {
- const item = randomData[i];
- // <a href="javascript:;" onclick="videoSet('${item.link}','${item.description}')" data-bs-toggle="modal" data-src="${item.link}" data-bs-target="#youtubeModal">
- // <img class="slide-item img-fluid" src="${item.imgUrl}" alt="">
- // </a>
- str += `
- <div>
- <section>
- <span class="slide-img">
- <a href="${item.link}" target="_blank" data-ga4="Latest_Video">
- <img class="slide-item img-fluid" src="${item.imgUrl}" alt="${item.description}">
- <span class="play-btn">
- <img class="slide-item img-fluid" src="./img/icon/material-play-circle-outline.svg" alt="">
- </span>
- </a>
- </span>
- <a href="${item.link}" target="_blank" class="title" data-ga4="Latest_Video">
- <h3 class="mb-0 mt-3 ellipsis-title">${item.description}</h3>
- </a>
- </section>
- </div>`;
- }
- $('.video-slider').html(str);
- // 輪播設定
- $('.video-slider').slick({
- infinite: false,
- slidesToShow: 4,
- slidesToScroll: 4,
- variableWidth: false,
- prevArrow:
- '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- nextArrow:
- '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- responsive: [
- {
- breakpoint: 991,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 2,
- }
- },
- {
- breakpoint: 767,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 2,
- }
- },
- {
- breakpoint: 575,
- settings: {
- slidesToShow: 2,
- slidesToScroll: 1,
- variableWidth: true,
- arrows: false,
- }
- },
- {
- breakpoint: 415,
- settings: {
- slidesToShow: 1,
- slidesToScroll: 1,
- variableWidth: true,
- arrows: false,
- }
- }
- ]
- });
- hideSlickArrow(); // 判斷輪播按鈕顯示
- }
- })
- }
- })
- // hover 事件
- $(".main-content h3").hover(
- function () {
- $(this).parent().parent().addClass('img-scale');
- }, function () {
- $(this).parent().parent().removeClass('img-scale');
- }
- );
- $(".main-content .slide-img").hover(
- function () {
- $(this).parent().parent().find('h3').css('color', '#ee751b');
- }, function () {
- ;
- $(this).parent().parent().find('h3').css('color', '#727272');
- }
- );
- }
- // 參數需帶入 (隨機排序清單, 標籤陣列, 外層 className)
- function randomTag(randomData, tagList, content) {
- let tagLink;
- if (content === "featured-content") {
- // 編輯精選
- tagLink = "column";
- } else {
- // 最夯設計
- tagLink = "case";
- }
- for (let index = 0; index < tagList.length; index++) {
- const element = tagList[index];
- randomData.map((e, i) => {
- if (i === index) {
- let list = [];
- for (let i = 0; i < element.length; i++) {
- const item = element[i];
- if (item !== "") {
- let tag = `
- <a href=https://hhh.com.tw/search/lists/${tagLink}/${item}-keyword/" target="_blank">
- <h4>${item}</h4>
- </a>
- `;
- list.push(tag);
- }
- }
- $(`.${content} .tag-list-${index}`).html(list);
- }
- })
- }
- }
- function hideSlickArrow() {
- // 隱藏輪播 disabled 按鈕,後續改為點擊判斷
- $('.slick-arrow.slick-disabled').css('display', 'none');
- $('.slick-arrow').click(function () {
- $('.slick-arrow').css('display', 'block');
- $('.slick-arrow.slick-disabled').css('display', 'none');
- });
- }
- // 影音實錄 Modal
- function videoSet(src, title) {
- let url = new URL(src);
- let id = url.searchParams.get('v');
- $("#video").attr('src', `https://www.youtube-nocookie.com/embed/${id}`);
- $("#youtubeModal h2").text(`${title}`);
- }
- // Back to top
- $(window).scroll(function () {
- if ($(this).scrollTop()) {
- $('.btn-box').fadeIn();
- } else {
- $('.btn-box').fadeOut();
- }
- });
- // 上方輪播
- $.ajax({
- method: "get",
- url: "./json/data_index.json",
- // url: "https://m3.hhh.com.tw:18689/genjson_new?filename=realtime.json",
- dataType: "json",
- }).done((data) => {
- result = [...data];
- renderTopCarousel(result);
- console.log('result', result);
- }).fail((error) => {
- console.log('genjson_new error', error);
- });
- // 渲染頂部輪播
- function renderTopCarousel(data) {
- let temp = data[0]["data"];
- console.log('temp', temp);
- renderBullet(temp);
- renderBannerStr("slider-content", temp);
- let randomInt = getRandomInt(7);
- let adTopup_count = []
- // 新刊頭 Banner ga4 (一開始進來先送,剩下輪播送)
- setTimeout(() => {
- let list_Topup_Banner = document.querySelectorAll('.slider-content .slide-item');
- let ad_first;
- try {
- ad_first = list_Topup_Banner[randomInt].getAttribute('data_id');
- } catch (e) {
- ad_first = '加載問題,請無視';
- console.log(ad_first);
- }
- dataLayer.push({
- 'event': 'Banner_Impression',
- 'ad_name': ad_first,
- 'ad_location': '新刊頭Banner'
- });
- adTopup_count.push(ad_first)
- }, 1000);
- $(".slider-content").slick({
- dots: false,
- infinite: true,
- speed: 500,
- autoplay: true,
- autoplaySpeed: 3000,
- slidesToScroll: 1,
- arrows: true,
- initialSlide: randomInt, // 起始順序
- prevArrow:
- '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- nextArrow:
- '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
- });
- $(".bullet").removeClass("bullet-active");
- $(".bullet")
- .eq($(".slick-active").data("slick-index"))
- .addClass("bullet-active");
- $(".slider-content").on("afterChange", function (event, slick, currentSlide) {
- // 輪播
- $(".bullet").removeClass("bullet-active");
- $(`.bullet.item-${currentSlide}`).addClass("bullet-active");
- });
- }
- function renderBannerStr(sec, data) {
- let adNamesTop = [];
- let str = "";
- for (let i = 0; i < data.length; i++) {
- let adNameTop = `${data[i]["id"]}${data[i]["alt"]}`;
- adNamesTop.push(adNameTop);
- if (data[i]["Dwebp"]) {
- str += `
- <a href="${data[i]["link"]}" data-ga4="${data[i]["id"]}${data[i]["alt"]}">
- <img class="${sec}-${i + 1} slide-item img-fluid" src="${data[i]["Dwebp"]}" data-bg="${data[i]["Dwebp"]}" alt="${data[i]["alt"]}" data_id="${data[i]["id"]}${data[i]["alt"]}">
- </a>`;
- } else {
- str += `
- <a href="${data[i]["link"]}" data-ga4="${data[i]["id"]}${data[i]["alt"]}">
- <img class="${sec}-${i + 1} slide-item img-fluid" src="${data[i]["DimgUrl"]}" data-bg="${data[i]["DimgUrl"]}" alt="${data[i]["alt"]}" data_id="${data[i]["id"]}${data[i]["alt"]}">
- </a>`;
- }
- }
- $(`.${sec}`).html(str);
- // ga4-banners
- adNamesTop.forEach((adNameTop) => {
- document.querySelectorAll(`a[data-ga4="${adNameTop}"]`).forEach((element) => {
- element.addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Banner_Click',
- 'ad_name': adNameTop,
- 'ad_location': '新刊頭'
- });
- });
- });
- });
- }
- function renderBullet(data) {
- let str = "";
- for (let i = 0; i < data.length; i++) {
- str += `<div class="bullet item-${i}"></div>`;
- }
- $(".bullet-list").html(str);
- }
- // 範圍內取隨機整數 (0-8)
- function getRandomInt(max) {
- return Math.floor(Math.random() * max);
- }
- $(".top-carousel .close-btn").click(function () {
- $(this).css("display", "none");
- $(".top-carousel").addClass("banner-close");
- sticky = 0;
- });
- // 右下按鈕
- $(".gotop-btn").click(() => {
- $("html, body").animate(
- {
- scrollTop: 0,
- }, 0
- );
- });
- // 右下按鈕滑入顯示
- $(".calculator-btn").hover(function () {
- $(".calculator-btn").addClass("show");
- }, function () {
- $(".calculator-btn").removeClass("show");
- });
- $(".shop-btn").hover(function () {
- $(".shop-btn").addClass("show");
- }, function () {
- $(".shop-btn").removeClass("show");
- });
- // 判斷按鈕顯示 or 隱藏
- $(window).scroll(function () {
- if ($(this).scrollTop()) {
- $('#btn-box').fadeIn();
- } else {
- $('#btn-box').fadeOut();
- }
- });
- document.querySelector('button[data-ga="Go_To_Calculator"]').addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Go_To_Calculator',
- 'btn_location': 'FixedBTN'
- });
- });
- document.querySelector('button[data-ga="Go_To_Shop"]').addEventListener('click', function () {
- dataLayer.push({
- 'event': 'Go_To_Shop',
- 'btn_location': 'FixedBTN'
- });
- });
- // Footer
- $(".follow-list a").on({
- mouseenter: function () {
- // $(this).find(".media-item.before").hide();
- // $(this).find(".media-item.after").show();
- $(this).find(".media-item.before").css("opacity", "0");
- $(this).find(".media-item.after").css("opacity", "1");
- },
- mouseleave: function () {
- // $(this).find(".media-item.before").show();
- // $(this).find(".media-item.after").hide();
- $(this).find(".media-item.before").css("opacity", "1");
- $(this).find(".media-item.after").css("opacity", "0");
- }
- });
- let formData = {
- email: ""
- };
- // 訂閱
- $('.subscriber-btn, .subscriber-mb-btn').on('click', function () {
- let parent = $(this).closest('.subscriber-item'); // 對應父元素
- parent.find('.spinner-border').addClass('show');
- let mail = parent.find('input').val();
- console.log("Input value:", mail);
- let regex = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;
- let validate = regex.test(mail); // 判斷 mail 格式
- if (!validate) {
- parent.addClass('input-error');
- parent.find('.spinner-border').removeClass('show');
- parent.find('button p').text('email 格式錯誤');
- } else {
- parent.removeClass('input-error');
- let formData = { email: mail };
- let email = JSON.stringify(formData);
- $.ajax({
- method: "post",
- url: "https://hhh.com.tw/adapter/index?http_method=POST&api_url=/third/v1/edm/subscriber",
- contentType: "application/json",
- data: email
- }).done((data) => {
- parent.find('.spinner-border').removeClass('show');
- parent.find('button p').text('已完成訂閱!');
- }).fail((error) => {
- parent.find('.spinner-border').removeClass('show');
- parent.find('button p').text('訂閱失敗,請稍後再試');
- });
- }
- });
- $('.subscriber-item input').on('focusin', function () {
- console.log('focusin');
- let parent = $(this).closest('.subscriber-item');
- parent.addClass('input-focus');
- let buttonText = parent.find('button p').text();
- if (buttonText !== "訂閱") {
- parent.find('button p').text('訂閱');
- parent.removeClass('input-error');
- }
- }).on('focusout', function () {
- $(this).closest('.subscriber-item').removeClass('input-focus');
- });
|