index_match.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. Swal.fire({
  98. icon: 'success',
  99. text: '我們已收到您的訊息,將有幸福經紀人與您聯繫',
  100. confirmButtonText: '關閉',
  101. })
  102. });
  103. function detectDirection () {
  104. let height = (window.screen.width * 5) / 12;
  105. console.log(height);
  106. $('.sec-02 .slide-item').css('height', `${height}px`);
  107. }
  108. function detectBrowser(agent){
  109. if(userAgent.match(/chrome|chromium|crios/i)){
  110. browserName = "chrome";
  111. }else if(userAgent.match(/firefox|fxios/i)){
  112. browserName = "firefox";
  113. } else if(userAgent.match(/safari/i)){
  114. browserName = "safari";
  115. }else if(userAgent.match(/opr\//i)){
  116. browserName = "opera";
  117. } else if(userAgent.match(/edg/i)){
  118. browserName = "edge";
  119. }else{
  120. browserName="No browser detection";
  121. }
  122. if(browserName === 'safari'){
  123. isSafari = true;
  124. }
  125. console.log(isSafari);
  126. }
  127. window.addEventListener('scroll', fixedOnScroll);
  128. const navbar = document.querySelector('.navbar-main');
  129. function fixedOnScroll() {
  130. }
  131. $(window).scroll(function() {
  132. if ( $(this).scrollTop() > 800 ){
  133. $('.fixed-btn').fadeIn(222);
  134. } else {
  135. $('.fixed-btn').stop().fadeOut(222);
  136. }
  137. }).scroll();
  138. $('.btn-gotop').click(function () {
  139. $('html, body').animate({
  140. scrollTop: 0
  141. }, 500)
  142. });
  143. $('.navbar-search img').click(function(){
  144. $('.navbar-search .dropbox').toggleClass('open');
  145. if($('.navbar-search .dropbox').hasClass('open')) {
  146. $('.navbar-nav .nav-item>.dropbox').addClass('d-none');
  147. } else {
  148. $('.navbar-nav .nav-item>.dropbox').removeClass('d-none');
  149. }
  150. });
  151. $('.sec-00__close').click(function(){
  152. $(this).css('display', 'none');
  153. $('.sec-00').addClass('bannerClose');
  154. //$('.sec-02').css('padding-top', '53px');
  155. sticky = 0;
  156. });
  157. // search
  158. const imageSearch = document.querySelector('.image-search');
  159. const imagesSelect = document.querySelectorAll('#pills-img-tab select');
  160. imageSearch.addEventListener("click", function() {
  161. searchQueryStr(imagesSelect, 'photos');
  162. })
  163. const newsSearch = document.querySelector('.news-search');
  164. const newsSelect = document.querySelectorAll('#pills-news-tab select');
  165. newsSearch.addEventListener("click", function() {
  166. searchQueryStr(newsSelect, 'builder');
  167. });
  168. const caseSearch= document.querySelector('.case-search');
  169. const caseSelect = document.querySelectorAll('#pills-case-tab select');
  170. caseSearch.addEventListener("click", function() {
  171. let query = ''
  172. let str = 'https://hhh.com.tw/cases/lists/1-page/new-sort/';
  173. if($('#case-shui').val() == '風水') {
  174. caseSelect.forEach((item, i) => {
  175. if(i < 2) {
  176. if(item.value !== ''){
  177. query += `/${item.value}`;
  178. }
  179. }
  180. });
  181. str = `https://hhh.com.tw/cases/lists${query}/風水-keyword/1-page/`;
  182. window.open(str);
  183. return;
  184. }
  185. caseSelect.forEach((item, i) => {
  186. if(item.value !== ''){
  187. query += `/${item.value}`;
  188. }
  189. });
  190. str = `https://hhh.com.tw/cases/lists${query}/1-page/`;
  191. window.open(str);
  192. })
  193. const designerSearch = document.querySelector('.designer-search');
  194. const designerSelect = document.querySelectorAll('#pills-designer-tab select');
  195. designerSearch.addEventListener("click", function() {
  196. searchQueryStr(designerSelect, 'designers');
  197. })
  198. function searchQueryStr(block, link){
  199. let query = ''
  200. let str = `https://hhh.com.tw/${link}/lists/1-page/`;
  201. block.forEach((item, i) => {
  202. if(item.value !== ''){
  203. query += `/${item.value}`;
  204. }
  205. });
  206. str = `https://hhh.com.tw/${link}/lists${query}/1-page/`;
  207. window.location.href = str;
  208. }
  209. const searchBtn = document.querySelector('.dropbox__searchBar__submit');
  210. const searchBar = document.querySelector('.dropbox__searchBar__input');
  211. searchBtn.addEventListener('click', search);
  212. searchBar.addEventListener('keyup', pressSearch);
  213. function search() {
  214. if(searchBar.value == '') {
  215. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  216. } else {
  217. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  218. console.log(`https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`)
  219. }
  220. }
  221. function pressSearch(e) {
  222. if (e.keyCode === 13) {
  223. e.preventDefault();
  224. search();
  225. }
  226. }
  227. function todayTV() {
  228. var utc = new Date().toJSON().slice(0,10).replace(/-/g,'-');
  229. window.location.href=`https://hhh.com.tw/program/?tv=gstv&date=${utc}&type=tv`;
  230. }
  231. document.addEventListener('lazybeforeunveil', function(e){
  232. var bg = e.target.getAttribute('data-bg');
  233. if(bg){
  234. e.target.style.backgroundImage = 'url(' + bg + ')';
  235. }
  236. });
  237. $('.container_match2').hide();
  238. $('.match__next').click(function() {
  239. $('.container_match').fadeOut(0);
  240. $('.container_match2').fadeIn(500);
  241. })
  242. $('.close').click(function () {
  243. window.close();
  244. })
  245. console.log('hii');