index_match.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. let userAgent;
  2. let isSafari = false;
  3. let browserName;
  4. window.onload = function(){
  5. userAgent = navigator.userAgent;
  6. detectBrowser(userAgent);
  7. detectDirection ();
  8. let result;
  9. let matchData;
  10. $.ajax({
  11. method: "GET",
  12. url: "./json/realtime.json",
  13. dataType: "json",
  14. }).done(function (msg) {
  15. result = [...msg];
  16. });
  17. $.ajax({
  18. method: "GET",
  19. url: "./json/match.json",
  20. dataType: "json",
  21. }).done(function (msg) {
  22. matchData = [...msg];
  23. renderMatch(matchData);
  24. renderMatchMb(matchData);
  25. });
  26. }
  27. function renderMatch(matchData){
  28. let str = '';
  29. for(let i = 0; i < matchData.length; i++){
  30. str += `<div class="row align-items-center py-3 justify-content-center text-center container__row">
  31. <div class="col">
  32. <div style="overflow: hidden;">
  33. <div class="sec-match__imgfr mx-auto" style="background-image: url('${matchData[i].WorkImg}');"
  34. onclick="window.open('${matchData[i].DesignerLink}');"></div>
  35. </div>
  36. </div>
  37. <div class="col">
  38. <div class="sec-match__designer mx-auto" style="background-image: url('${matchData[i].DesignerImg}');">
  39. </div>
  40. </div>
  41. <div class="col">
  42. <div style="width: 100%;" class="text-start mx-auto">
  43. <p>${matchData[i].Name} 設計師</p>
  44. <p class="mb-2">${matchData[i].CompanyName}</p>
  45. <p>擅長風格 ${matchData[i].CompanyName}</p>
  46. <p>接案坪數 ${matchData[i].Square} </p>
  47. <p>接案地區 ${matchData[i].Area}</p>
  48. </div>
  49. </div>
  50. <div class="col sec-match__consult d-none d-md-block">
  51. <p>${matchData[i].Consulting} 人正在諮詢</p>
  52. </div>
  53. <div class="col sec-match__like d-none d-md-block">
  54. <button class="btn-match">我有興趣</button>
  55. </div>
  56. <div class="col sec-match__like d-block d-md-none">
  57. <p class="mb-3">${matchData[i].Consulting} 人正在諮詢</p>
  58. <button class="btn-match">我有興趣</button>
  59. </div>
  60. </div>`
  61. }
  62. $('.container__match').html(str);
  63. }
  64. function renderMatchMb(matchData) {
  65. let str = '';
  66. for(let i = 0; i < matchData.length; i++){
  67. str += `<div class="row align-items-center py-4 justify-content-center text-center container__row" style="border-bottom: 1px solid #B2B2B2;">
  68. <div class="col-12 mb-4">
  69. <div class="sec-result__imgfr mx-auto" style="background-image: url('${matchData[i].WorkImg}');"
  70. onclick="window.open('${matchData[i].DesignerLink}');"></div>
  71. </div>
  72. <div class="row">
  73. <div class="col-5">
  74. <div class="sec-result__designer mx-auto mb-4" style="background-image: url('${matchData[i].DesignerImg}');">
  75. </div>
  76. </div>
  77. <div class="col-7">
  78. <div class="text-start mx-auto">
  79. <p>${matchData[i].Name} 設計師</p>
  80. <p class="mb-2">${matchData[i].CompanyName}</p>
  81. <p>擅長風格 ${matchData[i].Style}</p>
  82. <p>接案坪數 ${matchData[i].Square}</p>
  83. <p class="mb-2">接案地區 ${matchData[i].Area}</p>
  84. <span class="sec-result__consulting"><strong class="sec-result__num">${matchData[i].Consulting}</strong> 人正在諮詢</span>
  85. </div>
  86. </div>
  87. <div class="col-12 mt-4">
  88. <button class="btn-match">我有興趣</button>
  89. </div>
  90. </div>
  91. </div>
  92. `
  93. }
  94. $('.container__mb').html(str);
  95. }
  96. $(document).on("click", ".btn-match", function (event) {
  97. if(!$(this).hasClass('clicked')) {
  98. Swal.fire({
  99. icon: 'success',
  100. text: '我們已收到您的訊息,將有幸福經紀人與您聯繫',
  101. confirmButtonText: '關閉',
  102. })
  103. }
  104. $(this).addClass('clicked');
  105. });
  106. function detectDirection () {
  107. let height = (window.screen.width * 5) / 12;
  108. console.log(height);
  109. $('.sec-02 .slide-item').css('height', `${height}px`);
  110. }
  111. function detectBrowser(agent){
  112. if(userAgent.match(/chrome|chromium|crios/i)){
  113. browserName = "chrome";
  114. }else if(userAgent.match(/firefox|fxios/i)){
  115. browserName = "firefox";
  116. } else if(userAgent.match(/safari/i)){
  117. browserName = "safari";
  118. }else if(userAgent.match(/opr\//i)){
  119. browserName = "opera";
  120. } else if(userAgent.match(/edg/i)){
  121. browserName = "edge";
  122. }else{
  123. browserName="No browser detection";
  124. }
  125. if(browserName === 'safari'){
  126. isSafari = true;
  127. }
  128. console.log(isSafari);
  129. }
  130. window.addEventListener('scroll', fixedOnScroll);
  131. const navbar = document.querySelector('.navbar-main');
  132. function fixedOnScroll() {
  133. }
  134. $(window).scroll(function() {
  135. if ( $(this).scrollTop() > 800 ){
  136. $('.fixed-btn').fadeIn(222);
  137. } else {
  138. $('.fixed-btn').stop().fadeOut(222);
  139. }
  140. }).scroll();
  141. $('.btn-gotop').click(function () {
  142. $('html, body').animate({
  143. scrollTop: 0
  144. }, 500)
  145. });
  146. $('.navbar-search img').click(function(){
  147. $('.navbar-search .dropbox').toggleClass('open');
  148. if($('.navbar-search .dropbox').hasClass('open')) {
  149. $('.navbar-nav .nav-item>.dropbox').addClass('d-none');
  150. } else {
  151. $('.navbar-nav .nav-item>.dropbox').removeClass('d-none');
  152. }
  153. });
  154. $('.sec-00__close').click(function(){
  155. $(this).css('display', 'none');
  156. $('.sec-00').addClass('bannerClose');
  157. //$('.sec-02').css('padding-top', '53px');
  158. sticky = 0;
  159. });
  160. // search
  161. const imageSearch = document.querySelector('.image-search');
  162. const imagesSelect = document.querySelectorAll('#pills-img-tab select');
  163. imageSearch.addEventListener("click", function() {
  164. searchQueryStr(imagesSelect, 'photos');
  165. })
  166. const newsSearch = document.querySelector('.news-search');
  167. const newsSelect = document.querySelectorAll('#pills-news-tab select');
  168. newsSearch.addEventListener("click", function() {
  169. searchQueryStr(newsSelect, 'builder');
  170. });
  171. const caseSearch= document.querySelector('.case-search');
  172. const caseSelect = document.querySelectorAll('#pills-case-tab select');
  173. caseSearch.addEventListener("click", function() {
  174. let query = ''
  175. let str = 'https://hhh.com.tw/cases/lists/1-page/new-sort/';
  176. if($('#case-shui').val() == '風水') {
  177. caseSelect.forEach((item, i) => {
  178. if(i < 2) {
  179. if(item.value !== ''){
  180. query += `/${item.value}`;
  181. }
  182. }
  183. });
  184. str = `https://hhh.com.tw/cases/lists${query}/風水-keyword/1-page/`;
  185. window.open(str);
  186. return;
  187. }
  188. caseSelect.forEach((item, i) => {
  189. if(item.value !== ''){
  190. query += `/${item.value}`;
  191. }
  192. });
  193. str = `https://hhh.com.tw/cases/lists${query}/1-page/`;
  194. window.open(str);
  195. })
  196. const designerSearch = document.querySelector('.designer-search');
  197. const designerSelect = document.querySelectorAll('#pills-designer-tab select');
  198. designerSearch.addEventListener("click", function() {
  199. searchQueryStr(designerSelect, 'designers');
  200. })
  201. function searchQueryStr(block, link){
  202. let query = ''
  203. let str = `https://hhh.com.tw/${link}/lists/1-page/`;
  204. block.forEach((item, i) => {
  205. if(item.value !== ''){
  206. query += `/${item.value}`;
  207. }
  208. });
  209. str = `https://hhh.com.tw/${link}/lists${query}/1-page/`;
  210. window.location.href = str;
  211. }
  212. const searchBtn = document.querySelector('.dropbox__searchBar__submit');
  213. const searchBar = document.querySelector('.dropbox__searchBar__input');
  214. searchBtn.addEventListener('click', search);
  215. searchBar.addEventListener('keyup', pressSearch);
  216. function search() {
  217. if(searchBar.value == '') {
  218. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  219. } else {
  220. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  221. console.log(`https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`)
  222. }
  223. }
  224. function pressSearch(e) {
  225. if (e.keyCode === 13) {
  226. e.preventDefault();
  227. search();
  228. }
  229. }
  230. function todayTV() {
  231. var utc = new Date().toJSON().slice(0,10).replace(/-/g,'-');
  232. window.location.href=`https://hhh.com.tw/program/?tv=gstv&date=${utc}&type=tv`;
  233. }
  234. document.addEventListener('lazybeforeunveil', function(e){
  235. var bg = e.target.getAttribute('data-bg');
  236. if(bg){
  237. e.target.style.backgroundImage = 'url(' + bg + ')';
  238. }
  239. });
  240. $('.container_match2').hide();
  241. $('.match__next').click(function() {
  242. $('.container_match').fadeOut(0);
  243. $('.container_match2').fadeIn(500);
  244. })
  245. $('.close').click(function () {
  246. window.close();
  247. })