index.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  1. let userAgent;
  2. let isSafari = false;
  3. let browserName;
  4. window.onload = function(){
  5. // if(screen.width < 900){
  6. // window.location.href = "https://m3.hhh.com.tw/";
  7. // }
  8. userAgent = navigator.userAgent;
  9. detectBrowser(userAgent);
  10. detectDirection ();
  11. let result;
  12. $.ajax({
  13. method: "GET",
  14. url: "./json/realtime.json",
  15. dataType: "json",
  16. }).done(function (msg) {
  17. result = [...msg];
  18. renderSec00(result);
  19. renderSec02(result);
  20. renderSec05(result);
  21. renderSec06(result);
  22. renderSec07(result);
  23. renderSec08(result);
  24. renderSec09(result);
  25. renderSec10(result);
  26. //renderSec11(result);
  27. renderVideo(result);
  28. renderTrending(result);
  29. });
  30. }
  31. function detectDirection () {
  32. let height = (window.screen.width * 5) / 12;
  33. console.log(height);
  34. $('.sec-02 .slide-item').css('height', `${height}px`);
  35. }
  36. function detectBrowser(agent){
  37. if(userAgent.match(/chrome|chromium|crios/i)){
  38. browserName = "chrome";
  39. }else if(userAgent.match(/firefox|fxios/i)){
  40. browserName = "firefox";
  41. } else if(userAgent.match(/safari/i)){
  42. browserName = "safari";
  43. }else if(userAgent.match(/opr\//i)){
  44. browserName = "opera";
  45. } else if(userAgent.match(/edg/i)){
  46. browserName = "edge";
  47. }else{
  48. browserName="No browser detection";
  49. }
  50. if(browserName === 'safari'){
  51. isSafari = true;
  52. }
  53. console.log(isSafari);
  54. }
  55. var myModal = new bootstrap.Modal(document.getElementById('matchModal'), {
  56. keyboard: false
  57. })
  58. function renderSec00(data) {
  59. let temp = data[0]['data'];
  60. renderBullet(temp);
  61. renderBannerStr('sec-00__slider', temp);
  62. $(".sec-00__slider").slick({
  63. dots: false,
  64. speed: 500,
  65. autoplay: true,
  66. autoplaySpeed: 4000,
  67. arrows: true,
  68. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
  69. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>'
  70. });
  71. $('.sec-00__bullet').removeClass('bullet-active');
  72. $('.sec-00__bullet').eq($('.slick-active').data('slick-index')).addClass('bullet-active');
  73. // $('.sec-00__slider').on('beforeChange', function(event, slick, currentSlide, nextSlide){
  74. // console.log(currentSlide);
  75. // console.log($('.slick-active').data('slick-index'));
  76. // });
  77. $('.sec-00__slider').on('afterChange', function(event, slick, currentSlide){
  78. console.log(currentSlide);
  79. console.log($('.slick-active').data('slick-index'));
  80. $('.sec-00__bullet').removeClass('bullet-active');
  81. $('.sec-00__bullet').eq(currentSlide).addClass('bullet-active');
  82. });
  83. }
  84. function renderSec02(data) {
  85. let temp = data[1]['data'];
  86. renderBannerStr('sec-02__slider', temp);
  87. $(".sec-02__slider").slick({
  88. dots: false,
  89. autoplay: true,
  90. arrows: true,
  91. fade: true,
  92. autoplaySpeed: 4000,
  93. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 33px;color: white;transform: translateY(-10px);"></i></button>',
  94. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 33px;color: white;transform: translateY(-10px);"></i></button>'
  95. });
  96. }
  97. function renderBullet(data) {
  98. let str = '';
  99. for(let i = 0; i < data.length; i++){
  100. str += '<div class="sec-00__bullet"></div>'
  101. }
  102. $('.sec-00__bulletList').html(str);
  103. }
  104. function renderBannerStr(sec, data) {
  105. let str = '';
  106. for(let i = 0; i < data.length; i++){
  107. if(data[i]['Dwebp'] && !isSafari) {
  108. str+= `<img class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['Dwebp']}');" data-bg="${data[i]['Dwebp']}"></img>`
  109. } else {
  110. str+= `<img class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['DimgUrl']}');" data-bg="${data[i]['DimgUrl']}"></img>`
  111. }
  112. }
  113. $(`.${sec}`).html(str);
  114. }
  115. function renderSec05(data) {
  116. let randomIdx = Math.floor(Math.random()*3);
  117. const ran = $('.sec-05__tabdiv .nav-pills li').eq(randomIdx);
  118. const ranDiv = $('.sec-05tab-content>div').eq(randomIdx);
  119. $('.sec-05tab-content>div').hide();
  120. ranDiv.show();
  121. ran.addClass('active');
  122. ran.children().addClass('active');
  123. $('.sec-05 .morelink').attr('href', $('.sec-05__tabdiv .nav-item-link.active').data('link'));
  124. let temp = data[2]['data'];
  125. for(let i = 0; i < temp.length; i++){
  126. if(temp[i]["tab"] == '最夯設計'){
  127. let str = '';
  128. let sub = temp[i]["data"];
  129. for(let j = 0; j < sub.length; j++){
  130. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}');">
  131. <div class="tabpar__card__imgfr mb-2" style="background-image: url('${sub[j]['imgUrl']}');" data-bg="${sub[j]['imgUrl']}"></div>
  132. <h5 class="mb-2 me-2">${sub[j]['title']}</h5>
  133. <p class="mt-2">${sub[j]['description']}</p>
  134. </div>`;
  135. }
  136. $('#pills-hot-tab .tabpar').html(str);
  137. }
  138. if(temp[i]["tab"] == '影音實錄'){
  139. let str = '';
  140. let sub = temp[i]["data"];
  141. for(let j = 0; j < sub.length; j++){
  142. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}');">
  143. <div class="tabpar__card__imgfr mb-2" style="background-image: url('${sub[j]['imgUrl']}');" data-bg="${sub[j]['imgUrl']}"><img data-src="images/Play-Button.webp" alt="" class="tabpar__card__play lazyload"></div>
  144. <h5 class="mb-2 me-2">${sub[j]['title']}</h5>
  145. <p class="mt-2">${sub[j]['description']}</p>
  146. </div>`;
  147. }
  148. $('#pills-video-tab .tabpar').html(str);
  149. }
  150. if(temp[i]["tab"] == '專欄文章'){
  151. let str = '';
  152. let sub = temp[i]["data"];
  153. for(let j = 0; j < sub.length; j++){
  154. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}');">
  155. <div class="tabpar__card__imgfr mb-2" style="background-image: url('${sub[j]['imgUrl']}');" data-bg="${sub[j]['imgUrl']}"></div>
  156. <h5 class="mb-2 me-2">${sub[j]['title']}</h5>
  157. <p class="mt-2">${sub[j]['description']}</p>
  158. </div>`;
  159. }
  160. $('#pills-blog-tab .tabpar').html(str);
  161. }
  162. }
  163. const cardText = document.querySelectorAll('.tabpar__card p');
  164. cardText.forEach((item, i) => {
  165. let len = item.textContent.length;
  166. if(len > 18) {
  167. let str = item.textContent.substring(0, 18) + '...';
  168. item.textContent = str;
  169. }
  170. })
  171. $('.sec-05__tabdiv .nav-pills button').on('click', function(event){
  172. event.preventDefault();
  173. $('.sec-05__tabdiv .nav-pills li').removeClass('active');
  174. $('.sec-05__tabdiv .nav-pills li button').removeClass('active');
  175. $(this).addClass('active');
  176. $(this).parent().addClass('active');
  177. $('.sec-05tab-content>div').hide();
  178. var target = $(this).attr('id');
  179. $(`#pills-tab #${target}`).show();
  180. $('.sec-05tab-content .tabpar').slick('setPosition');
  181. });
  182. $(`.sec-05tab-content .tabpar`).slick({
  183. arrows: true,
  184. slidesToShow: 3,
  185. infinite: false,
  186. dots: false,
  187. slidesToScroll: 1,
  188. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 35px;color: black;"></i></button>',
  189. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 35px;color: black;"></i></button>'
  190. });
  191. $('.sec-05__tabdiv .nav-item-link').click(function() {
  192. $('.sec-05 .morelink').attr('href',$('.sec-05__tabdiv .nav-item-link.active').data('link'));
  193. });
  194. }
  195. function renderSec06(data) {
  196. let temp = data[3]['data'];
  197. let str = '';
  198. for(let i = 0; i < temp.length; i++){
  199. if(temp[i].video == 'true'){
  200. str+= `<div class="sec-06__card" onclick="window.open('${temp[i]['link']}');">
  201. <div class="sec-06__card__outer"><div class="sec-06__card__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}"><img class="sec-06__card__play lazyload" data-src="images/Play-Button.webp"></div></div>
  202. <h5 class="mb-2 mt-2">${temp[i]['title']}</h5>
  203. <p class="mt-2">${temp[i]['description']}</p>
  204. </div>`;
  205. } else {
  206. str+= `<div class="sec-06__card" onclick="window.open('${temp[i]['link']}');">
  207. <div class="sec-06__card__outer"><div class="sec-06__card__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}"></div></div>
  208. <h5 class="mb-2 mt-2">${temp[i]['title']}</h5>
  209. <p class="mt-2">${temp[i]['description']}</p>
  210. </div>`;
  211. }
  212. }
  213. $('.sec-06 .sec-06__slider').html(str);
  214. $('.sec-06__slider').slick({
  215. arrows: true,
  216. dots: false,
  217. speed: 800,
  218. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 30px;color: white;"></i></button>',
  219. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 30px;color: white;"></i></button>'
  220. });
  221. const cardText = document.querySelectorAll('.sec-06__card p');
  222. cardText.forEach((item, i) => {
  223. let len = item.textContent.length;
  224. if(len > 20) {
  225. let str = item.textContent.substring(0, 40) + '...';
  226. item.textContent = str;
  227. }
  228. });
  229. }
  230. function renderSec07(data) {
  231. let temp = data[5]['data'];
  232. let str = '';
  233. for(let i = 0; i < temp.length; i++){
  234. str+= `<div class="sec-07__slider-${i+1} slide-item" onclick="window.open('${temp[i]['link']}');" style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}"></div>`
  235. }
  236. $(`.sec-07__slider`).html(str);
  237. $(".sec-07__slider").slick({
  238. dots: false,
  239. autoplay: true,
  240. arrows: false,
  241. slidesToShow: 4,
  242. slidesToScroll: 1,
  243. autoplaySpeed: 7000,
  244. initialSlide: 0,
  245. infinite: true,
  246. });
  247. }
  248. function renderSec08(data) {
  249. let temp = data[4]['data'];
  250. let str = '';
  251. for(let i = 0; i < temp.length; i++){
  252. if(temp[i].video == 'true'){
  253. str+= `<div class="sec-08__slider-${i+1} sec-08__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  254. <div class="sec-08__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}"><img class="sec-08__card__play lazyload" data-src="images/Play-Button.webp"></div>
  255. <h5 class="mb-2 me-2">${temp[i]['title']}</h5>
  256. <p class="mb-2 me-2">${temp[i]['description']}</p>
  257. </div>`;
  258. } else {
  259. str+= `<div class="sec-08__slider-${i+1} sec-08__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  260. <div class="sec-08__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}"></div>
  261. <h5 class="mb-2 me-2">${temp[i]['title']}</h5>
  262. <p class="mb-2 me-2">${temp[i]['description']}</p>
  263. </div>`;
  264. }
  265. }
  266. $('.sec-08__slider').html(str);
  267. $(".sec-08__slider").slick({
  268. arrows: true,
  269. slidesToShow: 1,
  270. infinite: false,
  271. dots: false,
  272. slidesToShow: 3,
  273. centerPadding: '12px',
  274. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 35px;color: black;"></i></button>',
  275. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 35px;color: black;"></i></button>'
  276. });
  277. const cardText = document.querySelectorAll('.sec-08__card p');
  278. cardText.forEach((item, i) => {
  279. let len = item.textContent.length;
  280. if(len > 20) {
  281. let str = item.textContent.substring(0, 20) + '...';
  282. item.textContent = str;
  283. }
  284. })
  285. }
  286. function renderSec09(data) {
  287. let temp = data[6]['data'];
  288. let str = '';
  289. for(let i = 0; i < temp.length; i++){
  290. if(temp[i].video !== 'false') {
  291. str+= `<div class="sec-09__slider-1 sec-09__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  292. <div class="sec-09__imgfr mb-2" 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>
  293. <p class="sec-09__cardtxt">${temp[i]['title']}</p>
  294. </div>`
  295. } else {
  296. str+= `<div class="sec-09__slider-1 sec-09__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  297. <div class="sec-09__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}"></div>
  298. <p class="sec-09__cardtxt">${temp[i]['title']}</p>
  299. </div>`
  300. }
  301. }
  302. $('.sec-09__slider').html(str);
  303. $(".sec-09__slider").slick({
  304. autoplay: true,
  305. autoplaySpeed: 7000,
  306. arrows: true,
  307. slidesToShow: 4,
  308. infinite: true,
  309. dots: false,
  310. slidesToScroll: 1,
  311. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 35px;color: black;"></i></button>',
  312. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 35px;color: black;"></i></button>'
  313. });
  314. }
  315. function renderSec10(data) {
  316. renderRecStr("sec-10", data[7]['data'].slice(0, 6));
  317. renderRecStr("sec-11", data[8]['data'].slice(0, 6));
  318. }
  319. function renderRecStr(sec, data) {
  320. let str = '';
  321. for(let i = 0; i < data.length; i++){
  322. //console.log(data[i]['description'].length);
  323. if(data[i]['description'].length > 0) {
  324. data[i]['description'].split(',');
  325. data[i]['description'] = data[i]['description'].split(',').slice(1).join("");
  326. }
  327. if(data[i].video !== 'false') {
  328. str+= `<div class="${sec}__card col-4 mb-3" onclick="window.open('${data[i]['link']}');">
  329. <div class="${sec}__card-img mb-2" 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>
  330. <h5 class="me-2">${data[i]['title']}</h5>
  331. <p class="${sec}__cardtxt me-2">${data[i]['description']}</p>
  332. </div>`
  333. } else {
  334. str+= `<div class="${sec}__card col-4 mb-3" onclick="window.open('${data[i]['link']}');">
  335. <div class="${sec}__card-img mb-2" style="background-image: url('${data[i]['imgUrl']}');" data-bg="${data[i]['imgUrl']}"></div>
  336. <h5 class="me-2">${data[i]['title']}</h5>
  337. <p class="${sec}__cardtxt me-2">${data[i]['description']}</p>
  338. </div>`
  339. }
  340. }
  341. $(`.${sec} .row`).html(str);
  342. const cardText = document.querySelectorAll(`.${sec}__card p`);
  343. cardText.forEach((item, i) => {
  344. let len = item.textContent.length;
  345. if(len > 18) {
  346. let str = item.textContent.substring(0, 18) + '...';
  347. item.textContent = str;
  348. }
  349. })
  350. }
  351. function renderVideo(data) {
  352. let temp = data[9];
  353. console.log(data[9]);
  354. $('.sec-06__videotxt').text(temp['title']);
  355. console.log('test');
  356. $('.sec-06__video__imgfr').css('background-image', `url(https://img.youtube.com/vi/${temp['yt']}/hqdefault.jpg)`);
  357. $('#videoModal').on('shown.bs.modal', function () {
  358. $('#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`);
  359. });
  360. $('#videoModal').on('hidden.bs.modal', function () {
  361. $('#videoModal iframe').removeAttr('src');
  362. });
  363. }
  364. function renderTrending(result){
  365. let temp = result[10]['data'];
  366. let str = '';
  367. for(let i = 0; i < temp.length; i++){
  368. str += `<a class="dropbox__hots__link" href="https://hhh.com.tw/search/lists/case/${temp[i]}-keyword/">${temp[i]}</a>`
  369. }
  370. $('.dropbox__hots').html(`<strong class="dropbox__hots__title">熱搜關鍵字:</strong>${str}`);
  371. }
  372. function tab2 () {
  373. if(('.dropbox__tabdiv').length){
  374. // Show the first tab by default
  375. $('.dropbox-tab-content>div').hide();
  376. $('.dropbox-tab-content>div:first').show();
  377. $('.dropbox__tabdiv .nav-pills li:first').addClass('active');
  378. $('.dropbox__tabdiv .nav-pills li:first button').addClass('active');
  379. // Change tab class and display content
  380. $('.dropbox__tabdiv .nav-pills button').on('click', function(event){
  381. event.preventDefault();
  382. $('.dropbox__tabdiv .nav-pills li').removeClass('active');
  383. $('.dropbox__tabdiv .nav-pills li button').removeClass('active');
  384. $(this).addClass('active');
  385. $(this).parent().addClass('active');
  386. $('.dropbox-tab-content>div').hide();
  387. var target = $(this).attr('id');
  388. $(`#pills-tab-2 #${target}`).show();
  389. });
  390. }
  391. }
  392. tab2();
  393. let sticky = document.querySelector('.sec-00').offsetHeight;
  394. console.log(sticky);
  395. window.addEventListener('scroll', fixedOnScroll);
  396. const navbar = document.querySelector('.navbar-main');
  397. function fixedOnScroll() {
  398. if(window.pageYOffset >= 344){
  399. navbar.classList.add('sticky');
  400. } else {
  401. navbar.classList.remove('sticky');
  402. }
  403. }
  404. $(window).scroll(function() {
  405. if ( $(this).scrollTop() > 800 ){
  406. $('.fixed-btn').fadeIn(222);
  407. } else {
  408. $('.fixed-btn').stop().fadeOut(222);
  409. }
  410. }).scroll();
  411. $('.btn-gotop').click(function () {
  412. $('html, body').animate({
  413. scrollTop: 0
  414. }, 500)
  415. });
  416. $('.navbar-search img').click(function(){
  417. $('.navbar-search .dropbox').toggleClass('open');
  418. if($('.navbar-search .dropbox').hasClass('open')) {
  419. $('.navbar-nav .nav-item>.dropbox').addClass('d-none');
  420. } else {
  421. $('.navbar-nav .nav-item>.dropbox').removeClass('d-none');
  422. }
  423. });
  424. $('.sec-00__close').click(function(){
  425. $(this).css('display', 'none');
  426. $('.sec-00').addClass('bannerClose');
  427. //$('.sec-02').css('padding-top', '53px');
  428. sticky = 0;
  429. });
  430. // search
  431. const imageSearch = document.querySelector('.image-search');
  432. const imagesSelect = document.querySelectorAll('#pills-img-tab select');
  433. imageSearch.addEventListener("click", function() {
  434. searchQueryStr(imagesSelect, 'photos');
  435. })
  436. const newsSearch = document.querySelector('.news-search');
  437. const newsSelect = document.querySelectorAll('#pills-news-tab select');
  438. newsSearch.addEventListener("click", function() {
  439. searchQueryStr(newsSelect, 'builder');
  440. });
  441. const caseSearch= document.querySelector('.case-search');
  442. const caseSelect = document.querySelectorAll('#pills-case-tab select');
  443. caseSearch.addEventListener("click", function() {
  444. let query = ''
  445. let str = 'https://hhh.com.tw/cases/lists/1-page/new-sort/';
  446. if($('#case-shui').val() == '風水') {
  447. caseSelect.forEach((item, i) => {
  448. if(i < 2) {
  449. if(item.value !== ''){
  450. query += `/${item.value}`;
  451. }
  452. }
  453. });
  454. str = `https://hhh.com.tw/cases/lists${query}/風水-keyword/1-page/`;
  455. window.open(str);
  456. return;
  457. }
  458. caseSelect.forEach((item, i) => {
  459. if(item.value !== ''){
  460. query += `/${item.value}`;
  461. }
  462. });
  463. str = `https://hhh.com.tw/cases/lists${query}/1-page/`;
  464. window.open(str);
  465. })
  466. const designerSearch = document.querySelector('.designer-search');
  467. const designerSelect = document.querySelectorAll('#pills-designer-tab select');
  468. designerSearch.addEventListener("click", function() {
  469. searchQueryStr(designerSelect, 'designers');
  470. })
  471. function searchQueryStr(block, link){
  472. let query = ''
  473. let str = `https://hhh.com.tw/${link}/lists/1-page/`;
  474. block.forEach((item, i) => {
  475. if(item.value !== ''){
  476. query += `/${item.value}`;
  477. }
  478. });
  479. str = `https://hhh.com.tw/${link}/lists${query}/1-page/`;
  480. window.location.href = str;
  481. }
  482. const searchBtn = document.querySelector('.dropbox__searchBar__submit');
  483. const searchBar = document.querySelector('.dropbox__searchBar__input');
  484. searchBtn.addEventListener('click', search);
  485. searchBar.addEventListener('keyup', pressSearch);
  486. function search() {
  487. if(searchBar.value == '') {
  488. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  489. } else {
  490. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  491. console.log(`https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`)
  492. }
  493. }
  494. function pressSearch(e) {
  495. if (e.keyCode === 13) {
  496. e.preventDefault();
  497. search();
  498. }
  499. }
  500. function todayTV() {
  501. var utc = new Date().toJSON().slice(0,10).replace(/-/g,'-');
  502. window.location.href=`https://hhh.com.tw/program/?tv=gstv&date=${utc}&type=tv`;
  503. }
  504. document.addEventListener('lazybeforeunveil', function(e){
  505. var bg = e.target.getAttribute('data-bg');
  506. if(bg){
  507. e.target.style.backgroundImage = 'url(' + bg + ')';
  508. }
  509. });
  510. var stop = 0;
  511. $('.container_match2').hide();
  512. $('.match__next').click(function() {
  513. console.log($('#area').val());
  514. console.log($('#type').val());
  515. if ($('#area').val() == '' || $('#area').val() == null) {
  516. $('#area-error').text('請選擇地區');
  517. stop = 1;
  518. } else {
  519. $('#area-error').text('');
  520. stop = 0
  521. }
  522. if ($('#type').val() == ''|| $('#type').val() == null) {
  523. $('#type-error').text('請選擇房屋類型');
  524. stop = 1;
  525. } else {
  526. $('#type-error').text('');
  527. stop = 0
  528. }
  529. if ($('#square').val() == ''|| $('#square').val() == null) {
  530. $('#square-error').text('請選擇房屋坪數');
  531. stop = 1;
  532. } else {
  533. $('#square-error').text('');
  534. stop = 0
  535. }
  536. if ($('#pattern').val() == ''|| $('#pattern').val() == null) {
  537. $('#pattern-error').text('請選擇房屋格局');
  538. stop = 1;
  539. } else {
  540. $('#pattern-error').text('');
  541. stop = 0
  542. }
  543. if ($('#style').val() == ''|| $('#style').val() == null) {
  544. $('#style-error').text('請選擇喜愛的風格');
  545. stop = 1;
  546. } else {
  547. $('#style-error').text('');
  548. stop = 0
  549. }
  550. console.log(stop);
  551. if(stop === 0) {
  552. $('.container_match').fadeOut(0);
  553. $('.container_match2').fadeIn(500);
  554. $('.last-step').show();
  555. }
  556. });
  557. $('.last-step').hide();
  558. var name = 0;
  559. var phone = 0;
  560. var sex = 0;
  561. var readPolicy = 0;
  562. $('.match__next2').click(function() {
  563. if ($('#name').val() == ''|| $('#name').val() == null) {
  564. $('#name-error').text('請填寫您的姓名');
  565. name = 1;
  566. } else {
  567. $('#name-error').text('');
  568. name = 0;
  569. }
  570. if ($('#phone').val() == ''|| $('#phone').val() == null || !/^[09]{2}[0-9]{8}$/.test($('#phone').val())) {
  571. $('#phone-error').text('請以手機格式填寫(格式:0987654321)');
  572. phone = 1;
  573. } else {
  574. $('#phone-error').text('');
  575. phone = 0;
  576. }
  577. console.log($('#phone').val());
  578. if ($('#sex').val() == ''|| $('#sex').val() == null) {
  579. $('#sex-error').text('請選擇性別');
  580. sex = 1;
  581. } else {
  582. $('#sex-error').text('');
  583. sex = 0;
  584. }
  585. if(!$('#readPolicy').prop('checked')) {
  586. $('#readPolicy-error').text('必須同意免責聲明與隱私使用政策');
  587. readPolicy = 1;
  588. } else {
  589. $('#readPolicy-error').text('');
  590. readPolicy = 0;
  591. }
  592. var obj = document.getElementsByName("time");
  593. var time = [];
  594. for (k in obj) {
  595. if (obj[k].checked)
  596. time.push(obj[k].value);
  597. }
  598. console.log(time);
  599. if(name== 0 && phone == 0 && sex == 0 && readPolicy == 0) {
  600. myModal.hide();
  601. $.ajax({
  602. type: "POST",
  603. url: "",
  604. data:
  605. {
  606. data: JSON.stringify(
  607. {
  608. name: $('#name').val(),
  609. sex: $('#sex').val(),
  610. phone: $('#phone').val(),
  611. time: $('#datepicker').val(),
  612. area: $('#area').val(),
  613. type: $('#type').val(),
  614. square: $('#square').val(),
  615. pattern: $('#pattern').val(),
  616. style: $('#style').val(),
  617. time: time.toString(),
  618. })
  619. },
  620. success: function (res) {
  621. if (res.status == "Success") {
  622. // gaEvent('功能 - 軟裝需求單 - 送出', '經紀人');
  623. Swal.fire({
  624. html: '<h5 class="text-primary font-weight-bold">' + res.error + '</h5>',
  625. showConfirmButton: true,
  626. confirmButtonText: '確定',
  627. confirmButtonColor: '#EE7800'
  628. }).then(function (result) {
  629. if (result.value) {
  630. location.reload();
  631. }
  632. })
  633. } else {
  634. Swal.fire({
  635. title: '似乎出了什麼問題 請稍後再試',
  636. showConfirmButton: false,
  637. })
  638. }
  639. },
  640. error: function (error) {
  641. console.error(error)
  642. }
  643. })
  644. window.open('./index_match.html');
  645. }
  646. })
  647. $('.last-step').click(function() {
  648. $('.container_match').fadeIn(500);
  649. $('.container_match2').fadeOut(0);
  650. $('.last-step').hide();
  651. });
  652. function submit() {
  653. if ($('#name').val() == '') {
  654. $('#name-error').text('請填寫您的姓名');
  655. stop = 1;
  656. } else {
  657. $('#name-error').text('');
  658. }
  659. if ($('#phone').val() == '' || !/^[09]{2}[0-9]{8}$/.test($('#phone').val())) {
  660. $('#phone-error').text('請以手機格式填寫(格式:0987654321)');
  661. stop = 1;
  662. } else {
  663. $('#phone-error').text('');
  664. }
  665. if ($('#sex').val() == '') {
  666. $('#sex-error').text('請選擇軟裝預算');
  667. stop = 1;
  668. } else {
  669. $('#sex-error').text('');
  670. }
  671. }
  672. // city result
  673. let cityResult;
  674. $.ajax({
  675. method: "GET",
  676. url: "./json/taiwan_districts.json",
  677. dataType: "json",
  678. }).done(function (msg) {
  679. cityResult = [...msg];
  680. let str = '';
  681. for(let i = 0; i < cityResult.length; i++){
  682. str += `<option value="${cityResult[i]['zip']}-city">${cityResult[i]['name']}</option>`;
  683. }
  684. $('#designer-city').html(`<option value="" selected="selected" disabled>所在縣市</option>${str}`);
  685. $('#designer-city').on('change', function() {
  686. let selected = $(this).val().split('-')[0];
  687. let countyStr = '';
  688. for(let i = 0; i < cityResult.length; i++){
  689. if(cityResult[i]['zip'] == selected) {
  690. for(let j = 0; j < cityResult[i]['districts'].length; j++){
  691. countyStr += `<option value="${cityResult[i]['districts'][j]['zip']}-county">${cityResult[i]['districts'][j]['name']}</option>`;
  692. }
  693. }
  694. }
  695. $('#designer-country').html(`<option value="" selected="selected" disabled>所在地區</option>${countyStr}`);
  696. });
  697. });
  698. //jQuery time
  699. var current_fs, next_fs, previous_fs; //fieldsets
  700. var left, opacity, scale; //fieldset properties which we will animate
  701. var animating; //flag to prevent quick multi-click glitches
  702. $(".next").click(function(){
  703. if(animating) return false;
  704. animating = true;
  705. current_fs = $(this).parent().parent();
  706. next_fs = $(this).parent().parent().next();
  707. //activate next step on progressbar using the index of next_fs
  708. $(".form-progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  709. //show the next fieldset
  710. next_fs.animate({opacity: 1}, {
  711. step: function(now, mx) {
  712. //as the opacity of current_fs reduces to 0 - stored in "now"
  713. //1. scale current_fs down to 80%
  714. scale = 0 + (1 + now) * .5 ;
  715. //2. bring next_fs from the right(50%)
  716. left = (now * 50)+"%";
  717. //3. increase opacity of next_fs to 1 as it moves in
  718. opacity = 0 + now;
  719. next_fs.css({
  720. 'transform': 'scale('+scale+')',
  721. });
  722. next_fs.css({'opacity': opacity});
  723. },
  724. duration: 400,
  725. complete: function(){
  726. next_fs.show();
  727. animating = false;
  728. },
  729. //this comes from the custom easing plugin
  730. easing: 'easeInOutBack'
  731. });
  732. //hide the current fieldset with style
  733. current_fs.animate({opacity: 0}, {
  734. step: function(now, mx) {
  735. //as the opacity of current_fs reduces to 0 - stored in "now"
  736. //1. scale current_fs down to 80%
  737. scale = 1 - (1 - now) * 0.2;
  738. //2. bring next_fs from the right(50%)
  739. left = (now * 50)+"%";
  740. //3. increase opacity of next_fs to 1 as it moves in
  741. opacity = 1 - now;
  742. current_fs.css({
  743. 'transform': 'scale('+scale+')',
  744. });
  745. next_fs.css({'opacity': opacity});
  746. },
  747. duration: 400,
  748. complete: function(){
  749. current_fs.hide();
  750. animating = false;
  751. },
  752. //this comes from the custom easing plugin
  753. easing: 'easeInOutBack'
  754. });
  755. });
  756. $('.check-click').click(function(e) {
  757. if($('#2b').is(':checked')) {
  758. $('#2a').prop('checked', false);
  759. }
  760. if($('#2c').is(':checked')) {
  761. $('#2a').prop('checked', false);
  762. }
  763. if($('#2d').is(':checked')) {
  764. $('#2a').prop('checked', false);
  765. }
  766. if($('#2e').is(':checked')) {
  767. $('#2a').prop('checked', false);
  768. }
  769. console.log(e.target.id);
  770. if(e.target.id === '2a') {
  771. $('#2a').prop('checked', true);
  772. $('#2b').prop('checked', false);
  773. $('#2c').prop('checked', false);
  774. $('#2d').prop('checked', false);
  775. $('#2e').prop('checked', false);
  776. }
  777. })