index.js 31 KB

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