123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695 |
- let userAgent;
- let isSafari = false;
- let browserName;
- window.onload = function(){
- //window.scrollBy(0, 1);
- /* if(screen.width >= 901){
- window.location.href = "https://www2.hhh.com.tw/";
- } */
- userAgent = navigator.userAgent;
- detectBrowser(userAgent);
- detectDirection ();
- let result;
- $.ajax({
- method: "GET",
- url: "./json/realtime.json",
- dataType: "json",
- }).done(function (msg) {
- result = [...msg];
- renderSec00(result);
- renderSec02(result);
- renderSec03(result);
- renderSec06(result);
- renderSec07(result);
- renderSec08(result);
- renderSec09(result);
- renderSec10(result);
- renderSec11(result);
- renderVideo(result);
- });
-
- }
- 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;
- }
- console.log(isSafari);
- }
- function detectDirection () {
- let height = (window.screen.width * 2) / 3;
-
- $('.sec-02 .slide-item').css('height', `${height}px`);
- let topHeight = (window.screen.width * 30) / 131;
-
- $('.sec-00 .slide-item').css('height', `${topHeight}px`);
- $('.sec-00 .container-fluid').css('height', `${topHeight}px`);
- }
- $(".sec-01__slider").slick({
- dots: true,
- autoplay: false,
- arrows: false,
- });
- function renderSec00(data) {
- let temp = data[0]['data'];
- renderBannerStr('sec-00__slider', temp);
- $(".sec-00__slider").slick({
- dots: false,
- speed: 800,
- autoplay: true,
- });
- }
- function renderSec02(data) {
- let temp = data[1]['data'];
- renderBannerStr('sec-02__slider', temp);
- let str = '';
- $(".sec-02__slider").slick({
- dots: false,
- autoplay: true,
- arrows: true,
- fade: true,
- });
- }
- function renderBannerStr(sec, data) {
- let str = '';
- console.log(isSafari);
- for(let i = 0; i < data.length; i++){
- if(data[i]['webp'] && !isSafari) {
- str+= `<div class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['webp']}');" data-bg="${data[i]['webp']}"></div>`
- } else {
- str+= `<div class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['imgUrl']}');" data-bg="${data[i]['imgUrl']}"></div>`
- }
- }
- $(`.${sec}`).html(str);
- }
- function renderSec03(data) {
- let randomIdx = Math.floor(Math.random()*3);
- let moreLinks = ['https://hhh.com.tw/cases/lists/', 'https://hhh.com.tw/videos/lists/', 'https://hhh.com.tw/columns/lists/'];
- const ran = $('.sec-03__tabdiv .nav-item-link').eq(randomIdx);
- const ranDiv = $('#pills-tabContent .tab-pane').eq(randomIdx);
- ran.addClass('active');
- ranDiv.addClass('active');
- ranDiv.addClass('show');
- $('.sec-03 .morelink').attr('href', $('.sec-03__tabdiv .nav-item-link.active').data('link'));
- let temp = data[2]['data'];
- for(let i = 0; i < temp.length; i++){
- if(temp[i]["tab"] == '最夯設計'){
- let str = '';
- let sub = temp[i]["data"];
- for(let j = 0; j < sub.length; j++){
- str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}')";>
- <div class="tabpar__card__imgfr" style="background-image: url('${sub[j]['imgUrl']}');" data-bg="${sub[j]['imgUrl']}"></div>
- <p class="mt-2 pe-2">${sub[j]['title']}</p>
- </div>`
- }
- $('#pills-hot .tabpar').html(str);
- }
- if(temp[i]["tab"] == '影音實錄'){
- let str = '';
- let sub = temp[i]["data"];
- for(let j = 0; j < sub.length; j++){
- str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}')";>
- <div class="tabpar__card__imgfr" style="background-image: url('${sub[j]['imgUrl']}');" data-bg="${sub[j]['imgUrl']}"><img class="tabpar__card__play lazyload" data-src="images/Play-Button.webp"></div>
- <p class="mt-2 pe-2">${sub[j]['description']}</p>
- </div>`
- }
- $('#pills-video .tabpar').html(str);
- }
- if(temp[i]["tab"] == '專欄文章'){
- let str = '';
- let sub = temp[i]["data"];
- for(let j = 0; j < sub.length; j++){
- str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}')";>
- <div class="tabpar__card__imgfr" style="background-image: url('${sub[j]['imgUrl']}');" data-bg="${sub[j]['imgUrl']}"></div>
- <p class="mt-2 pe-2">${sub[j]['title']}</p>
- </div>`
- }
- $('#pills-blog .tabpar').html(str);
- }
- }
- const cardText = document.querySelectorAll('.tabpar__card p');
- cardText.forEach((item, i) => {
- let len = item.textContent.length;
- if(len > 20) {
- let str = item.textContent.substring(0, 20) + '...';
- item.textContent = str;
- }
- });
- $('.sec-03__tabdiv .nav-item-link').click(function() {
- $('.sec-03 .morelink').attr('href',$('.sec-03__tabdiv .nav-item-link.active').data('link'));
- });
-
- }
- function renderSec06(data) {
- let temp = data[3]['data'];
- let str = '';
- for(let i = 0; i < temp.length; i++){
- if(i === 0) {
- str+= `<div class="carousel-item active" onclick="window.open('${temp[i]['link']}');"
- style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}">
- </div>`
- } else {
- str+= `<div class="carousel-item" onclick="window.open('${temp[i]['link']}');"
- style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}">
- </div>`
- }
- }
- $('.sec-06 .carousel-inner').html(str);
-
- }
- function renderSec07(data) {
- let temp = data[4]['data'];
- let str = '';
- for(let i = 0; i < temp.length; i++){
- str+= `
- <div class="sec-07__slider-${i+1} sec-07__card col-12 mx-1" onclick="window.open('${temp[i]['link']}');">
- <div class="sec-07__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');"></div>
- <p class="sec-07__cardtxt">${temp[i]['description']}</p>
- </div>`
- }
- $('.sec-07__slider').html(str);
- $(".sec-07__slider").slick({
- arrows: false,
- slidesToShow: 3,
- centerMode: true,
- infinite: false,
- dots: false,
- centerPadding: '12px',
- responsive: [
- {
- breakpoint: 480,
- settings: {
- arrows: false,
- slidesToShow: 1,
- centerMode: true,
- infinite: false,
- dots: true,
- centerPadding: '12px',
- }
- }
- ],
- });
- const cardText = document.querySelectorAll('.sec-07__cardtxt');
- cardText.forEach((item, i) => {
- let len = item.textContent.length;
- if(len > 20) {
- let str = item.textContent.substring(0, 25) + '...';
- item.textContent = str;
- }
- })
- }
- function renderSec08(data) {
- let temp = data[5]['data'];
- let str = '';
- for(let i = 0; i < temp.length; i++){
- str+= `<div class="sec-08__slider-${i+1} mx-1 slide-item" style="width: 70vw; background-image: url('${temp[i]['imgUrl']}');" onclick="window.open('${temp[i]['link']}');" data-bg="${temp[i]['imgUrl']}"></div>`
- }
- $('.sec-08__slider').html(str);
- $(".sec-08__slider").slick({
- autoplay: true,
- autoplaySpeed: 8000,
- arrows: false,
- slidesToShow: 3,
- centerMode: true,
- infinite: true,
- dots: false,
- centerPadding: '6px',
- responsive: [
- {
- breakpoint: 480,
- settings: {
- autoplay: true,
- autoplaySpeed: 8000,
- arrows: false,
- slidesToShow: 1,
- centerMode: true,
- infinite: true,
- dots: false,
- centerPadding: '12px',
- }
- }
- ],
- });
- }
- function renderSec09(data) {
- let temp = data[6]['data'];
- let str = '';
- for(let i = 0; i < temp.length; i++){
- if(temp[i].video !== 'false') {
- str+= `<div class="sec-09__card" onclick="window.open('${temp[i]['link']}');">
- <div class="sec-09__card__imgfr" style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}"><img class="sec-09__card__play lazyload" data-src="images/Play-Button.webp"></div>
- <p>${temp[i]['title']}</p>
- </div>`
- } else {
- str+= `<div class="sec-09__card" onclick="window.open('${temp[i]['link']}');">
- <div class="sec-09__card__imgfr" style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}"></div>
- <p>${temp[i]['title']}</p>
- </div>`
- }
- }
- $('.sec-09__cardgrp').html(str);
- $(".sec-09__cardgrp").slick({
- arrows: false,
- slidesToShow: 3,
- slidesToScroll: 1,
- infinite: true,
- dots: false,
- centerPadding: '10px',
- responsive: [
- {
- breakpoint: 480,
- settings: {
- arrows: false,
- slidesToShow: 2,
- slidesToScroll: 1,
- infinite: true,
- dots: false,
- centerPadding: '10px',
- }
- }
- ],
- });
- }
- function renderSec10(data) {
- let temp = data[7]['data'];
- renderRecStr('sec-10', temp);
- }
- function renderSec11(data) {
- let temp = data[8]['data'];
- renderRecStr('sec-11', temp);
- }
- function renderRecStr(sec, data) {
- let str = '';
- for(let i = 0; i < data.length; i++){
- if(data[i].video !== 'false') {
- str+= `<div class="${sec}__card col-12 mx-1" onclick="window.open('${data[i]['link']}');">
- <div class="${sec}__slider-${i+1} mb-2 slide-item" style="background-image: url('${data[i]['imgUrl']}');" data-bg="${data[i]['imgUrl']}"><img class="${sec}__card__play lazyload" data-src="images/Play-Button.webp"></div>
- <p class="${sec}__cardtxt">${data[i]['title']}</p>
- </div>`;
- } else {
- str+= `<div class="${sec}__card col-12 mx-1" onclick="window.open('${data[i]['link']}');">
- <div class="${sec}__slider-${i+1} mb-2 slide-item" style="background-image: url('${data[i]['imgUrl']}');" data-bg="${data[i]['imgUrl']}"></div>
- <p class="${sec}__cardtxt">${data[i]['title']}</p>
- </div>`;
- }
- }
- $(`.${sec}__slider`).html(str);
- $(`.${sec}__slider`).slick({
- arrows: false,
- slidesToShow: 3,
- centerMode: false,
- infinite: false,
- dots: false,
- centerPadding: '12px',
- responsive: [
- {
- breakpoint: 480,
- settings: {
- arrows: false,
- slidesToShow: 1,
- centerMode: true,
- infinite: false,
- dots: false,
- centerPadding: '12px',
- }
- }
- ],
- });
- }
- function renderVideo(data) {
- let temp = data[9];
- $('.sec-05__video__txt').text(temp['title']);
- $('.sec-05__video__imgfr').css('background-image', `url(https://img.youtube.com/vi/${temp['yt']}/hqdefault.jpg)`);
- $('#videoModal').on('shown.bs.modal', function () {
- $('#videoModal iframe').attr('src', `https://www.youtube.com/embed/${temp['yt']}?controls=0&autoplay=1&enablejsapi=1&origin=https%3A%2F%2Fm.hhh.com.tw&widgetid=1`);
- });
- $('#videoModal').on('hidden.bs.modal', function () {
- $('#videoModal iframe').removeAttr('src');
- });
- }
-
- window.addEventListener('scroll', fixedOnScroll);
-
- const navbar = document.querySelector('.navbar-main');
-
- function fixedOnScroll() {
- if(window.innerHeight < window.innerWidth){
- $('.sec-02 .slide-item').css('height', `130vh`);
- $('.sec-00 .slide-item').css('height', `200px`);
- $('.sec-00 .container-fluid').css('height', `200px`);
- } else {
- detectDirection ();
- }
- const sticky = document.querySelector('.sec-00 .container-fluid').offsetHeight;
- if(window.pageYOffset >= sticky){
- navbar.classList.add('sticky');
- } else {
- navbar.classList.remove('sticky');
- }
- }
-
- $('.navbar-toggler').click(function(){
- $(".sec-menu").css('display', 'block');
- $(".wholeBody").css('overflow-y', 'hidden');
- $('.sec-menu-block').addClass('slidein');
- $('.sec-menu-block').removeClass('slideout');
- });
-
- $('.navbar-back').click(function(){
- $(".sec-menu").css('display', 'none');
- $(".wholeBody").css('overflow-y', 'scroll');
- $('.sec-menu-block').removeClass('slidein');
- $('.sec-menu-block').addClass('slideout');
- });
-
- $('.subexpand').click(function(){
- $(this).parent().next().toggleClass('show');
- $(this).parent().toggleClass('show');
- });
-
- $('.navbar-search').click(function(){
- $(".sec-search").css('display', 'block');
- $(".wholeBody").css('overflow-y', 'hidden');
- })
-
- $('.navbar-backs').click(function(){
- $(".sec-search").css('display', 'none');
- $(".wholeBody").css('overflow-y', 'scroll');
- });
- $('.btn-match').click(function(){
- $(".sec-match").css('display', 'block');
- $(".wholeBody").css('overflow-y', 'hidden');
- })
-
- $('.navbar-backs').click(function(){
- $(".sec-match").css('display', 'none');
- $(".wholeBody").css('overflow-y', 'scroll');
- });
- $('.navbar-back-fav').click(function(){
- $(".sec-favor").css('display', 'none');
- })
- $('.btn-gotop').click(function () {
- $('html, body').animate({
- scrollTop: 0
- }, 500)
- });
- $(window).scroll(function() {
- if ( $(this).scrollTop() > 500 ){
- $('.fixed-btn').fadeIn(222);
- } else {
- $('.fixed-btn').stop().fadeOut(222);
- }
- }).scroll();
-
- const searchBtn = document.querySelector('.searchBtn');
- const searchBar = document.querySelector('.searchBar');
- const searchHotLink = document.querySelectorAll('.sec-search-hots__link');
- searchBtn.addEventListener('click', search);
- searchBar.addEventListener('keyup', pressSearch);
- function search() {
- if(searchBar.value == '') {
- window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
- } else {
- window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
- }
- }
- function pressSearch(e) {
- if (e.keyCode === 13) {
- e.preventDefault();
- search();
- }
- }
- searchHotLink.forEach((item, i) => {
- item.addEventListener('click', function() {
- window.location.href = `https://m.hhh.com.tw/search/lists/case/${this.textContent}-keyword/`;
- })
- })
- document.addEventListener('lazybeforeunveil', function(e){
- var bg = e.target.getAttribute('data-bg');
- if(bg){
- e.target.style.backgroundImage = 'url(' + bg + ')';
- }
- });
- //jQuery time
- var current_fs, next_fs, previous_fs; //fieldsets
- var left, opacity, scale; //fieldset properties which we will animate
- var animating; //flag to prevent quick multi-click glitches
- $(".next").click(function(){
- if(animating) return false;
- animating = true;
-
- current_fs = $(this).parent().parent();
- next_fs = $(this).parent().parent().next();
-
- //activate next step on progressbar using the index of next_fs
- $(".form-progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
-
- //show the next fieldset
- next_fs.animate({opacity: 1}, {
- step: function(now, mx) {
- //as the opacity of current_fs reduces to 0 - stored in "now"
- //1. scale current_fs down to 80%
- scale = 0 + (1 + now) * .5 ;
- //2. bring next_fs from the right(50%)
- left = (now * 50)+"%";
- //3. increase opacity of next_fs to 1 as it moves in
- opacity = 0 + now;
- next_fs.css({
- 'transform': 'scale('+scale+')',
- });
- next_fs.css({'opacity': opacity});
- },
- duration: 400,
- complete: function(){
- next_fs.show();
- animating = false;
- },
- //this comes from the custom easing plugin
- easing: 'easeInOutBack'
- });
- //hide the current fieldset with style
- current_fs.animate({opacity: 0}, {
- step: function(now, mx) {
- //as the opacity of current_fs reduces to 0 - stored in "now"
- //1. scale current_fs down to 80%
- scale = 1 - (1 - now) * 0.2;
- //2. bring next_fs from the right(50%)
- left = (now * 50)+"%";
- //3. increase opacity of next_fs to 1 as it moves in
- opacity = 1 - now;
- current_fs.css({
- 'transform': 'scale('+scale+')',
- });
- next_fs.css({'opacity': opacity});
- },
- duration: 400,
- complete: function(){
- current_fs.hide();
- animating = false;
- },
- //this comes from the custom easing plugin
- easing: 'easeInOutBack'
- });
- });
- $('.container_match2').hide();
-
- $('.last-step').click(function() {
- $('.container_match').fadeIn(500);
- $('.container_match2').fadeOut(0);
- });
- $('.match__next').click(function() {
- console.log($('#area').val());
- console.log($('#type').val());
- if ($('#area').val() == '' || $('#area').val() == null) {
- $('#area-error').text('請選擇地區');
- stop = 1;
- } else {
- $('#area-error').text('');
- stop = 0
- }
- if ($('#type').val() == ''|| $('#type').val() == null) {
- $('#type-error').text('請選擇房屋類型');
- stop = 1;
- } else {
- $('#type-error').text('');
- stop = 0
- }
- if ($('#square').val() == ''|| $('#square').val() == null) {
- $('#square-error').text('請選擇房屋坪數');
- stop = 1;
- } else {
- $('#square-error').text('');
- stop = 0
- }
- if ($('#pattern').val() == ''|| $('#pattern').val() == null) {
- $('#pattern-error').text('請選擇房屋格局');
- stop = 1;
- } else {
- $('#pattern-error').text('');
- stop = 0
- }
- if ($('#style').val() == ''|| $('#style').val() == null) {
- $('#style-error').text('請選擇喜愛的風格');
- stop = 1;
- } else {
- $('#style-error').text('');
- stop = 0
- }
- console.log(stop);
- if(stop === 0) {
- $('.container_match').fadeOut(0);
- $('.container_match2').fadeIn(500);
- }
-
- });
- $('.match__next2').click(function() {
- if ($('#name').val() == ''|| $('#name').val() == null) {
- $('#name-error').text('請填寫您的姓名');
- name = 1;
- } else {
- $('#name-error').text('');
- name = 0;
- }
- if ($('#phone').val() == ''|| $('#phone').val() == null || !/^[09]{2}[0-9]{8}$/.test($('#phone').val())) {
- $('#phone-error').text('請以手機格式填寫(格式:0987654321)');
- phone = 1;
- } else {
- $('#phone-error').text('');
- phone = 0;
- }
- console.log($('#phone').val());
- if ($('#sex').val() == ''|| $('#sex').val() == null) {
- $('#sex-error').text('請選擇性別');
- sex = 1;
- } else {
- $('#sex-error').text('');
- sex = 0;
- }
- if(!$('#readPolicy').prop('checked')) {
- $('#readPolicy-error').text('必須同意免責聲明與隱私使用政策');
- readPolicy = 1;
- } else {
- $('#readPolicy-error').text('');
- readPolicy = 0;
- }
- var obj = document.getElementsByName("time");
- var time = [];
- for (k in obj) {
- if (obj[k].checked)
- time.push(obj[k].value);
- }
- console.log(time);
- if(name== 0 && phone == 0 && sex == 0 && readPolicy == 0) {
- $.ajax({
- type: "POST",
- url: "",
- data:
- {
- data: JSON.stringify(
- {
- name: $('#name').val(),
- sex: $('#sex').val(),
- phone: $('#phone').val(),
- time: $('#datepicker').val(),
- area: $('#area').val(),
- type: $('#type').val(),
- square: $('#square').val(),
- pattern: $('#pattern').val(),
- style: $('#style').val(),
- time: time.toString(),
- })
- },
- success: function (res) {
- if (res.status == "Success") {
- // gaEvent('功能 - 軟裝需求單 - 送出', '經紀人');
- Swal.fire({
- html: '<h5 class="text-primary font-weight-bold">' + res.error + '</h5>',
- showConfirmButton: true,
- confirmButtonText: '確定',
- confirmButtonColor: '#EE7800'
- }).then(function (result) {
- if (result.value) {
- location.reload();
- }
- })
- } else {
- Swal.fire({
- title: '似乎出了什麼問題 請稍後再試',
- showConfirmButton: false,
- })
- }
- },
- error: function (error) {
- console.error(error)
- }
- })
- $(".sec-match").css('display', 'none');
- $(".wholeBody").css('overflow-y', 'scroll');
- window.open('./index_match.html');
- }
-
- })
- $('.check-click').click(function(e) {
- if($('#2b').is(':checked')) {
- $('#2a').prop('checked', false);
- }
- if($('#2c').is(':checked')) {
- $('#2a').prop('checked', false);
- }
- if($('#2d').is(':checked')) {
- $('#2a').prop('checked', false);
- }
- if($('#2e').is(':checked')) {
- $('#2a').prop('checked', false);
- }
- console.log(e.target.id);
- if(e.target.id === '2a') {
- $('#2a').prop('checked', true);
- $('#2b').prop('checked', false);
- $('#2c').prop('checked', false);
- $('#2d').prop('checked', false);
- $('#2e').prop('checked', false);
- }
- })
|