index.js 32 KB

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