index_match.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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. let matchData;
  13. $.ajax({
  14. method: "GET",
  15. url: "./json/realtime.json",
  16. dataType: "json",
  17. }).done(function (msg) {
  18. result = [...msg];
  19. renderSec00(result);
  20. renderSec02(result);
  21. renderSec05(result);
  22. renderSec06(result);
  23. renderSec07(result);
  24. renderSec08(result);
  25. renderSec09(result);
  26. renderSec10(result);
  27. //renderSec11(result);
  28. renderVideo(result);
  29. renderTrending(result);
  30. });
  31. $.ajax({
  32. method: "GET",
  33. url: "./json/match.json",
  34. dataType: "json",
  35. }).done(function (msg) {
  36. matchData = [...msg];
  37. renderMatch(matchData);
  38. });
  39. }
  40. function renderMatch(matchData){
  41. let str = '';
  42. for(let i = 0; i < matchData.length; i++){
  43. str += `<div class="row align-items-center py-3 justify-content-center text-center container__row">
  44. <div class="col">
  45. <div class="sec-match__imgfr mx-auto" style="background-image: url('${matchData[i].WorkImg}');"></div>
  46. </div>
  47. <div class="col">
  48. <div class="sec-match__designer mx-auto" style="background-image: url('${matchData[i].DesignerImg}');">
  49. </div>
  50. </div>
  51. <div class="col">
  52. <div style="width: 100%;" class="text-start mx-auto">
  53. <p>${matchData[i].Name} 設計師</p>
  54. <p class="mb-2">${matchData[i].CompanyName}</p>
  55. <p>擅長風格 ${matchData[i].CompanyName}</p>
  56. <p>接案坪數 ${matchData[i].Square} </p>
  57. <p>接案地區 ${matchData[i].Area}</p>
  58. </div>
  59. </div>
  60. <div class="col">
  61. <p>${matchData[i].Consulting} 人正在諮詢</p>
  62. </div>
  63. <div class="col">
  64. <button class="btn-match">我有興趣</button>
  65. </div>
  66. </div>`
  67. }
  68. $('.container__match').html(str);
  69. }
  70. $(document).on("click", ".btn-match", function (event) {
  71. Swal.fire({
  72. icon: 'success',
  73. text: '我們已收到您的訊息,將有幸福經紀人與您聯繫',
  74. confirmButtonText: '關閉',
  75. })
  76. });
  77. function detectDirection () {
  78. let height = (window.screen.width * 5) / 12;
  79. console.log(height);
  80. $('.sec-02 .slide-item').css('height', `${height}px`);
  81. }
  82. function detectBrowser(agent){
  83. if(userAgent.match(/chrome|chromium|crios/i)){
  84. browserName = "chrome";
  85. }else if(userAgent.match(/firefox|fxios/i)){
  86. browserName = "firefox";
  87. } else if(userAgent.match(/safari/i)){
  88. browserName = "safari";
  89. }else if(userAgent.match(/opr\//i)){
  90. browserName = "opera";
  91. } else if(userAgent.match(/edg/i)){
  92. browserName = "edge";
  93. }else{
  94. browserName="No browser detection";
  95. }
  96. if(browserName === 'safari'){
  97. isSafari = true;
  98. }
  99. console.log(isSafari);
  100. }
  101. function renderSec00(data) {
  102. let temp = data[0]['data'];
  103. renderBannerStr('sec-00__slider', temp);
  104. $(".sec-00__slider").slick({
  105. dots: false,
  106. speed: 800,
  107. autoplay: true,
  108. autoplaySpeed: 5000,
  109. arrows: true,
  110. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
  111. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>'
  112. });
  113. }
  114. function renderSec02(data) {
  115. let temp = data[1]['data'];
  116. renderBannerStr('sec-02__slider', temp);
  117. $(".sec-02__slider").slick({
  118. dots: false,
  119. autoplay: true,
  120. arrows: true,
  121. fade: true,
  122. autoplaySpeed: 4000,
  123. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 33px;color: white;transform: translateY(-10px);"></i></button>',
  124. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 33px;color: white;transform: translateY(-10px);"></i></button>'
  125. });
  126. }
  127. function renderBannerStr(sec, data) {
  128. let str = '';
  129. for(let i = 0; i < data.length; i++){
  130. if(data[i]['Dwebp'] && !isSafari) {
  131. str+= `<div class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['Dwebp']}');" data-bg="${data[i]['Dwebp']}"></div>`
  132. } else {
  133. str+= `<div class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['DimgUrl']}');" data-bg="${data[i]['DimgUrl']}"></div>`
  134. }
  135. }
  136. $(`.${sec}`).html(str);
  137. }
  138. function renderSec05(data) {
  139. let randomIdx = Math.floor(Math.random()*3);
  140. const ran = $('.sec-05__tabdiv .nav-pills li').eq(randomIdx);
  141. const ranDiv = $('.sec-05tab-content>div').eq(randomIdx);
  142. $('.sec-05tab-content>div').hide();
  143. ranDiv.show();
  144. ran.addClass('active');
  145. ran.children().addClass('active');
  146. $('.sec-05 .morelink').attr('href', $('.sec-05__tabdiv .nav-item-link.active').data('link'));
  147. let temp = data[2]['data'];
  148. for(let i = 0; i < temp.length; i++){
  149. if(temp[i]["tab"] == '最夯設計'){
  150. let str = '';
  151. let sub = temp[i]["data"];
  152. for(let j = 0; j < sub.length; j++){
  153. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}');">
  154. <div class="tabpar__card__imgfr mb-2" style="background-image: url('${sub[j]['imgUrl']}');" data-bg="${sub[j]['imgUrl']}"></div>
  155. <h5 class="mb-2 me-2">${sub[j]['title']}</h5>
  156. <p class="mt-2">${sub[j]['description']}</p>
  157. </div>`;
  158. }
  159. $('#pills-hot-tab .tabpar').html(str);
  160. }
  161. if(temp[i]["tab"] == '影音實錄'){
  162. let str = '';
  163. let sub = temp[i]["data"];
  164. for(let j = 0; j < sub.length; j++){
  165. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}');">
  166. <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>
  167. <h5 class="mb-2 me-2">${sub[j]['title']}</h5>
  168. <p class="mt-2">${sub[j]['description']}</p>
  169. </div>`;
  170. }
  171. $('#pills-video-tab .tabpar').html(str);
  172. }
  173. if(temp[i]["tab"] == '專欄文章'){
  174. let str = '';
  175. let sub = temp[i]["data"];
  176. for(let j = 0; j < sub.length; j++){
  177. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}');">
  178. <div class="tabpar__card__imgfr mb-2" style="background-image: url('${sub[j]['imgUrl']}');" data-bg="${sub[j]['imgUrl']}"></div>
  179. <h5 class="mb-2 me-2">${sub[j]['title']}</h5>
  180. <p class="mt-2">${sub[j]['description']}</p>
  181. </div>`;
  182. }
  183. $('#pills-blog-tab .tabpar').html(str);
  184. }
  185. }
  186. const cardText = document.querySelectorAll('.tabpar__card p');
  187. cardText.forEach((item, i) => {
  188. let len = item.textContent.length;
  189. if(len > 18) {
  190. let str = item.textContent.substring(0, 18) + '...';
  191. item.textContent = str;
  192. }
  193. })
  194. $('.sec-05__tabdiv .nav-pills button').on('click', function(event){
  195. event.preventDefault();
  196. $('.sec-05__tabdiv .nav-pills li').removeClass('active');
  197. $('.sec-05__tabdiv .nav-pills li button').removeClass('active');
  198. $(this).addClass('active');
  199. $(this).parent().addClass('active');
  200. $('.sec-05tab-content>div').hide();
  201. var target = $(this).attr('id');
  202. $(`#pills-tab #${target}`).show();
  203. $('.sec-05tab-content .tabpar').slick('setPosition');
  204. });
  205. $(`.sec-05tab-content .tabpar`).slick({
  206. arrows: true,
  207. slidesToShow: 3,
  208. infinite: false,
  209. dots: false,
  210. slidesToScroll: 1,
  211. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 35px;color: black;"></i></button>',
  212. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 35px;color: black;"></i></button>'
  213. });
  214. $('.sec-05__tabdiv .nav-item-link').click(function() {
  215. $('.sec-05 .morelink').attr('href',$('.sec-05__tabdiv .nav-item-link.active').data('link'));
  216. });
  217. }
  218. function renderSec06(data) {
  219. let temp = data[3]['data'];
  220. let str = '';
  221. for(let i = 0; i < temp.length; i++){
  222. if(temp[i].video == 'true'){
  223. str+= `<div class="sec-06__card" onclick="window.open('${temp[i]['link']}');">
  224. <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>
  225. <h5 class="mb-2 mt-2">${temp[i]['title']}</h5>
  226. <p class="mt-2">${temp[i]['description']}</p>
  227. </div>`;
  228. } else {
  229. str+= `<div class="sec-06__card" onclick="window.open('${temp[i]['link']}');">
  230. <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>
  231. <h5 class="mb-2 mt-2">${temp[i]['title']}</h5>
  232. <p class="mt-2">${temp[i]['description']}</p>
  233. </div>`;
  234. }
  235. }
  236. $('.sec-06 .sec-06__slider').html(str);
  237. $('.sec-06__slider').slick({
  238. arrows: true,
  239. dots: false,
  240. speed: 800,
  241. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 30px;color: white;"></i></button>',
  242. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 30px;color: white;"></i></button>'
  243. });
  244. const cardText = document.querySelectorAll('.sec-06__card p');
  245. cardText.forEach((item, i) => {
  246. let len = item.textContent.length;
  247. if(len > 20) {
  248. let str = item.textContent.substring(0, 40) + '...';
  249. item.textContent = str;
  250. }
  251. });
  252. }
  253. function renderSec07(data) {
  254. let temp = data[5]['data'];
  255. let str = '';
  256. for(let i = 0; i < temp.length; i++){
  257. 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>`
  258. }
  259. $(`.sec-07__slider`).html(str);
  260. $(".sec-07__slider").slick({
  261. dots: false,
  262. autoplay: true,
  263. arrows: false,
  264. slidesToShow: 4,
  265. slidesToScroll: 1,
  266. autoplaySpeed: 7000,
  267. initialSlide: 0,
  268. infinite: true,
  269. });
  270. }
  271. function renderSec08(data) {
  272. let temp = data[4]['data'];
  273. let str = '';
  274. for(let i = 0; i < temp.length; i++){
  275. if(temp[i].video == 'true'){
  276. str+= `<div class="sec-08__slider-${i+1} sec-08__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  277. <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>
  278. <h5 class="mb-2 me-2">${temp[i]['title']}</h5>
  279. <p class="mb-2 me-2">${temp[i]['description']}</p>
  280. </div>`;
  281. } else {
  282. str+= `<div class="sec-08__slider-${i+1} sec-08__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  283. <div class="sec-08__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}"></div>
  284. <h5 class="mb-2 me-2">${temp[i]['title']}</h5>
  285. <p class="mb-2 me-2">${temp[i]['description']}</p>
  286. </div>`;
  287. }
  288. }
  289. $('.sec-08__slider').html(str);
  290. $(".sec-08__slider").slick({
  291. arrows: true,
  292. slidesToShow: 1,
  293. infinite: false,
  294. dots: false,
  295. slidesToShow: 3,
  296. centerPadding: '12px',
  297. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 35px;color: black;"></i></button>',
  298. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 35px;color: black;"></i></button>'
  299. });
  300. const cardText = document.querySelectorAll('.sec-08__card p');
  301. cardText.forEach((item, i) => {
  302. let len = item.textContent.length;
  303. if(len > 20) {
  304. let str = item.textContent.substring(0, 20) + '...';
  305. item.textContent = str;
  306. }
  307. })
  308. }
  309. function renderSec09(data) {
  310. let temp = data[6]['data'];
  311. let str = '';
  312. for(let i = 0; i < temp.length; i++){
  313. if(temp[i].video !== 'false') {
  314. str+= `<div class="sec-09__slider-1 sec-09__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  315. <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>
  316. <p class="sec-09__cardtxt">${temp[i]['title']}</p>
  317. </div>`
  318. } else {
  319. str+= `<div class="sec-09__slider-1 sec-09__card col-12 mx-2" onclick="window.open('${temp[i]['link']}');">
  320. <div class="sec-09__imgfr mb-2" style="background-image: url('${temp[i]['imgUrl']}');" data-bg="${temp[i]['imgUrl']}"></div>
  321. <p class="sec-09__cardtxt">${temp[i]['title']}</p>
  322. </div>`
  323. }
  324. }
  325. $('.sec-09__slider').html(str);
  326. $(".sec-09__slider").slick({
  327. autoplay: true,
  328. autoplaySpeed: 7000,
  329. arrows: true,
  330. slidesToShow: 4,
  331. infinite: true,
  332. dots: false,
  333. slidesToScroll: 1,
  334. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 35px;color: black;"></i></button>',
  335. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 35px;color: black;"></i></button>'
  336. });
  337. }
  338. function renderSec10(data) {
  339. renderRecStr("sec-10", data[7]['data'].slice(0, 6));
  340. renderRecStr("sec-11", data[8]['data'].slice(0, 6));
  341. }
  342. function renderRecStr(sec, data) {
  343. let str = '';
  344. for(let i = 0; i < data.length; i++){
  345. //console.log(data[i]['description'].length);
  346. if(data[i]['description'].length > 0) {
  347. data[i]['description'].split(',');
  348. data[i]['description'] = data[i]['description'].split(',').slice(1).join("");
  349. }
  350. if(data[i].video !== 'false') {
  351. str+= `<div class="${sec}__card col-4 mb-3" onclick="window.open('${data[i]['link']}');">
  352. <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>
  353. <h5 class="me-2">${data[i]['title']}</h5>
  354. <p class="${sec}__cardtxt me-2">${data[i]['description']}</p>
  355. </div>`
  356. } else {
  357. str+= `<div class="${sec}__card col-4 mb-3" onclick="window.open('${data[i]['link']}');">
  358. <div class="${sec}__card-img mb-2" style="background-image: url('${data[i]['imgUrl']}');" data-bg="${data[i]['imgUrl']}"></div>
  359. <h5 class="me-2">${data[i]['title']}</h5>
  360. <p class="${sec}__cardtxt me-2">${data[i]['description']}</p>
  361. </div>`
  362. }
  363. }
  364. $(`.${sec} .row`).html(str);
  365. const cardText = document.querySelectorAll(`.${sec}__card p`);
  366. cardText.forEach((item, i) => {
  367. let len = item.textContent.length;
  368. if(len > 18) {
  369. let str = item.textContent.substring(0, 18) + '...';
  370. item.textContent = str;
  371. }
  372. })
  373. }
  374. function renderVideo(data) {
  375. let temp = data[9];
  376. console.log(data[9]);
  377. $('.sec-06__videotxt').text(temp['title']);
  378. console.log('test');
  379. $('.sec-06__video__imgfr').css('background-image', `url(https://img.youtube.com/vi/${temp['yt']}/hqdefault.jpg)`);
  380. $('#videoModal').on('shown.bs.modal', function () {
  381. $('#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`);
  382. });
  383. $('#videoModal').on('hidden.bs.modal', function () {
  384. $('#videoModal iframe').removeAttr('src');
  385. });
  386. }
  387. function renderTrending(result){
  388. let temp = result[10]['data'];
  389. let str = '';
  390. for(let i = 0; i < temp.length; i++){
  391. str += `<a class="dropbox__hots__link" href="https://hhh.com.tw/search/lists/case/${temp[i]}-keyword/">${temp[i]}</a>`
  392. }
  393. $('.dropbox__hots').html(`<strong class="dropbox__hots__title">熱搜關鍵字:</strong>${str}`);
  394. }
  395. function tab2 () {
  396. if(('.dropbox__tabdiv').length){
  397. // Show the first tab by default
  398. $('.dropbox-tab-content>div').hide();
  399. $('.dropbox-tab-content>div:first').show();
  400. $('.dropbox__tabdiv .nav-pills li:first').addClass('active');
  401. $('.dropbox__tabdiv .nav-pills li:first button').addClass('active');
  402. // Change tab class and display content
  403. $('.dropbox__tabdiv .nav-pills button').on('click', function(event){
  404. event.preventDefault();
  405. $('.dropbox__tabdiv .nav-pills li').removeClass('active');
  406. $('.dropbox__tabdiv .nav-pills li button').removeClass('active');
  407. $(this).addClass('active');
  408. $(this).parent().addClass('active');
  409. $('.dropbox-tab-content>div').hide();
  410. var target = $(this).attr('id');
  411. $(`#pills-tab-2 #${target}`).show();
  412. });
  413. }
  414. }
  415. tab2();
  416. window.addEventListener('scroll', fixedOnScroll);
  417. const navbar = document.querySelector('.navbar-main');
  418. function fixedOnScroll() {
  419. }
  420. $(window).scroll(function() {
  421. if ( $(this).scrollTop() > 800 ){
  422. $('.fixed-btn').fadeIn(222);
  423. } else {
  424. $('.fixed-btn').stop().fadeOut(222);
  425. }
  426. }).scroll();
  427. $('.btn-gotop').click(function () {
  428. $('html, body').animate({
  429. scrollTop: 0
  430. }, 500)
  431. });
  432. $('.navbar-search img').click(function(){
  433. $('.navbar-search .dropbox').toggleClass('open');
  434. if($('.navbar-search .dropbox').hasClass('open')) {
  435. $('.navbar-nav .nav-item>.dropbox').addClass('d-none');
  436. } else {
  437. $('.navbar-nav .nav-item>.dropbox').removeClass('d-none');
  438. }
  439. });
  440. $('.sec-00__close').click(function(){
  441. $(this).css('display', 'none');
  442. $('.sec-00').addClass('bannerClose');
  443. //$('.sec-02').css('padding-top', '53px');
  444. sticky = 0;
  445. });
  446. // search
  447. const imageSearch = document.querySelector('.image-search');
  448. const imagesSelect = document.querySelectorAll('#pills-img-tab select');
  449. imageSearch.addEventListener("click", function() {
  450. searchQueryStr(imagesSelect, 'photos');
  451. })
  452. const newsSearch = document.querySelector('.news-search');
  453. const newsSelect = document.querySelectorAll('#pills-news-tab select');
  454. newsSearch.addEventListener("click", function() {
  455. searchQueryStr(newsSelect, 'builder');
  456. });
  457. const caseSearch= document.querySelector('.case-search');
  458. const caseSelect = document.querySelectorAll('#pills-case-tab select');
  459. caseSearch.addEventListener("click", function() {
  460. let query = ''
  461. let str = 'https://hhh.com.tw/cases/lists/1-page/new-sort/';
  462. if($('#case-shui').val() == '風水') {
  463. caseSelect.forEach((item, i) => {
  464. if(i < 2) {
  465. if(item.value !== ''){
  466. query += `/${item.value}`;
  467. }
  468. }
  469. });
  470. str = `https://hhh.com.tw/cases/lists${query}/風水-keyword/1-page/`;
  471. window.open(str);
  472. return;
  473. }
  474. caseSelect.forEach((item, i) => {
  475. if(item.value !== ''){
  476. query += `/${item.value}`;
  477. }
  478. });
  479. str = `https://hhh.com.tw/cases/lists${query}/1-page/`;
  480. window.open(str);
  481. })
  482. const designerSearch = document.querySelector('.designer-search');
  483. const designerSelect = document.querySelectorAll('#pills-designer-tab select');
  484. designerSearch.addEventListener("click", function() {
  485. searchQueryStr(designerSelect, 'designers');
  486. })
  487. function searchQueryStr(block, link){
  488. let query = ''
  489. let str = `https://hhh.com.tw/${link}/lists/1-page/`;
  490. block.forEach((item, i) => {
  491. if(item.value !== ''){
  492. query += `/${item.value}`;
  493. }
  494. });
  495. str = `https://hhh.com.tw/${link}/lists${query}/1-page/`;
  496. window.location.href = str;
  497. }
  498. const searchBtn = document.querySelector('.dropbox__searchBar__submit');
  499. const searchBar = document.querySelector('.dropbox__searchBar__input');
  500. searchBtn.addEventListener('click', search);
  501. searchBar.addEventListener('keyup', pressSearch);
  502. function search() {
  503. if(searchBar.value == '') {
  504. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  505. } else {
  506. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  507. console.log(`https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`)
  508. }
  509. }
  510. function pressSearch(e) {
  511. if (e.keyCode === 13) {
  512. e.preventDefault();
  513. search();
  514. }
  515. }
  516. function todayTV() {
  517. var utc = new Date().toJSON().slice(0,10).replace(/-/g,'-');
  518. window.location.href=`https://hhh.com.tw/program/?tv=gstv&date=${utc}&type=tv`;
  519. }
  520. document.addEventListener('lazybeforeunveil', function(e){
  521. var bg = e.target.getAttribute('data-bg');
  522. if(bg){
  523. e.target.style.backgroundImage = 'url(' + bg + ')';
  524. }
  525. });
  526. $('.container_match2').hide();
  527. $('.match__next').click(function() {
  528. $('.container_match').fadeOut(0);
  529. $('.container_match2').fadeIn(500);
  530. })
  531. // city result
  532. let cityResult;
  533. $.ajax({
  534. method: "GET",
  535. url: "../json/taiwan_districts.json",
  536. dataType: "json",
  537. }).done(function (msg) {
  538. cityResult = [...msg];
  539. let str = '';
  540. for(let i = 0; i < cityResult.length; i++){
  541. str += `<option value="${cityResult[i]['zip']}-city">${cityResult[i]['name']}</option>`;
  542. }
  543. $('#designer-city').html(`<option value="" selected="selected" disabled>所在縣市</option>${str}`);
  544. $('#designer-city').on('change', function() {
  545. let selected = $(this).val().split('-')[0];
  546. let countyStr = '';
  547. for(let i = 0; i < cityResult.length; i++){
  548. if(cityResult[i]['zip'] == selected) {
  549. for(let j = 0; j < cityResult[i]['districts'].length; j++){
  550. countyStr += `<option value="${cityResult[i]['districts'][j]['zip']}-county">${cityResult[i]['districts'][j]['name']}</option>`;
  551. }
  552. }
  553. }
  554. $('#designer-country').html(`<option value="" selected="selected" disabled>所在地區</option>${countyStr}`);
  555. });
  556. });
  557. //jQuery time
  558. var current_fs, next_fs, previous_fs; //fieldsets
  559. var left, opacity, scale; //fieldset properties which we will animate
  560. var animating; //flag to prevent quick multi-click glitches
  561. $(".next").click(function(){
  562. if(animating) return false;
  563. animating = true;
  564. current_fs = $(this).parent().parent();
  565. next_fs = $(this).parent().parent().next();
  566. //activate next step on progressbar using the index of next_fs
  567. $(".form-progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  568. //show the next fieldset
  569. next_fs.animate({opacity: 1}, {
  570. step: function(now, mx) {
  571. //as the opacity of current_fs reduces to 0 - stored in "now"
  572. //1. scale current_fs down to 80%
  573. scale = 0 + (1 + now) * .5 ;
  574. //2. bring next_fs from the right(50%)
  575. left = (now * 50)+"%";
  576. //3. increase opacity of next_fs to 1 as it moves in
  577. opacity = 0 + now;
  578. next_fs.css({
  579. 'transform': 'scale('+scale+')',
  580. });
  581. next_fs.css({'opacity': opacity});
  582. },
  583. duration: 400,
  584. complete: function(){
  585. next_fs.show();
  586. animating = false;
  587. },
  588. //this comes from the custom easing plugin
  589. easing: 'easeInOutBack'
  590. });
  591. //hide the current fieldset with style
  592. current_fs.animate({opacity: 0}, {
  593. step: function(now, mx) {
  594. //as the opacity of current_fs reduces to 0 - stored in "now"
  595. //1. scale current_fs down to 80%
  596. scale = 1 - (1 - now) * 0.2;
  597. //2. bring next_fs from the right(50%)
  598. left = (now * 50)+"%";
  599. //3. increase opacity of next_fs to 1 as it moves in
  600. opacity = 1 - now;
  601. current_fs.css({
  602. 'transform': 'scale('+scale+')',
  603. });
  604. next_fs.css({'opacity': opacity});
  605. },
  606. duration: 400,
  607. complete: function(){
  608. current_fs.hide();
  609. animating = false;
  610. },
  611. //this comes from the custom easing plugin
  612. easing: 'easeInOutBack'
  613. });
  614. });
  615. $('.close').click(function () {
  616. window.close();
  617. })