index-list-mb.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. let userAgent;
  2. let isSafari = false;
  3. let browserName;
  4. // pagination variables
  5. let num_per_page = 10;
  6. let n = 0;
  7. let n_video = 0;
  8. let n_columns = 0;
  9. let totalPages = {
  10. intro: 0,
  11. video: 0,
  12. columns: 0,
  13. vr360: 0,
  14. company: 0,
  15. };
  16. let filter;
  17. const urlParams = new URLSearchParams(window.location.search);
  18. let getfilter = urlParams.get('q');
  19. let cid = urlParams.get('cid');
  20. console.log(getfilter, cid);
  21. $('.likeSee__views').click(function() {
  22. window.location.href = `./index_designerList_mb.html?q=views&cid=${cid}`
  23. $(this).css('color', '#EE7800');
  24. })
  25. $('.likeSee__sort').click(function() {
  26. window.location.href = `./index_designerList_mb.html?cid=${cid}`
  27. $(this).css('color', '#EE7800');
  28. })
  29. function getpathId(){
  30. let query = window.location.search.split('?').pop();
  31. return query.split('=')[1];
  32. }
  33. function getQuery() {
  34. let query = getfilter;
  35. console.log(query);
  36. if(query == 'views'){
  37. filter = 'views';
  38. $('.likeSee__views').css('color', '#EE7800');
  39. } else {
  40. filter = 'dateSort';
  41. $('.likeSee__sort').css('color', '#EE7800');
  42. }
  43. }
  44. window.onload = function(){
  45. //window.scrollBy(0, 1);
  46. if(screen.width >= 901){
  47. window.location.href = `../index_designerList.html?cid=${cid}`;
  48. }
  49. userAgent = navigator.userAgent;
  50. detectBrowser(userAgent);
  51. detectDirection ();
  52. let result;
  53. let designer;
  54. let id = 0;
  55. $.ajax({
  56. method: "GET",
  57. url: `./json/designers-${cid}.json`,
  58. dataType: "json",
  59. }).done(function (msg) {
  60. getQuery();
  61. designer = [...msg][id];
  62. console.log(designer['Content']);
  63. if(filter == 'views'){
  64. designer['Content'][0]['Carddata'].sort(function (a, b){
  65. return a[filter] > b[filter]? -1:1;
  66. })
  67. } else {
  68. designer['Content'][0]['Carddata'].sort(function (a, b){
  69. return a[filter] > b[filter]? 1:-1;
  70. })
  71. }
  72. renderinfoCard(designer);
  73. renderTab(designer['Content']);
  74. renderTabContent(designer['Content'], designer);
  75. renderModalTitle(designer['CompanyName']);
  76. console.log(filter);
  77. console.log(designer['Content'][0]['Carddata']);
  78. $(window).scroll(function() {
  79. loadMore(designer);
  80. })
  81. });
  82. }
  83. let over = document.querySelector('.infoContent__navBlock').offsetTop;
  84. function detectBrowser(agent){
  85. if(userAgent.match(/chrome|chromium|crios/i)){
  86. browserName = "chrome";
  87. }else if(userAgent.match(/firefox|fxios/i)){
  88. browserName = "firefox";
  89. } else if(userAgent.match(/safari/i)){
  90. browserName = "safari";
  91. }else if(userAgent.match(/opr\//i)){
  92. browserName = "opera";
  93. } else if(userAgent.match(/edg/i)){
  94. browserName = "edge";
  95. }else{
  96. browserName="No browser detection";
  97. }
  98. if(browserName === 'safari'){
  99. isSafari = true;
  100. }
  101. console.log(isSafari);
  102. }
  103. function detectDirection () {
  104. let height = (window.screen.width * 2) / 3;
  105. $('.sec-02 .slide-item').css('height', `${height}px`);
  106. let topHeight = (window.screen.width * 30) / 131;
  107. $('.sec-00 .slide-item').css('height', `${topHeight}px`);
  108. $('.sec-00 .container-fluid').css('height', `${topHeight}px`);
  109. }
  110. function renderinfoCard(designer) {
  111. $('.mb__hero__bgImg').attr('backgroundImage', `url(${designer['BannerImg']})`);
  112. $('.mb__infoCard__avatar').css('backgroundImage', `url(${designer['Designerimg']})`)
  113. $('.mb__infoCard__name').text(designer['DesignerName']);
  114. $('.mb__infoCard__seo').text(designer['Description']);
  115. $('.mb__infoCard__cmy').text(designer['CompanyName']);
  116. if(designer['Approve'] !== '') {
  117. $('.mb__infoCard__approve').text(designer['Approve']);
  118. }
  119. // Basics
  120. let str = '';
  121. for(let i = 0;i < designer['Basics'].length; i ++) {
  122. str += `<aside class="d-flex">
  123. <div class="mb__infoCard__detail__l">
  124. <div>${designer['Basics'][i].title}</div>
  125. </div>
  126. <div class="mb__infoCard__detail__r">
  127. <a href="${designer['Basics'][i].link}">${designer['Basics'][i].data}</a>
  128. </div>
  129. </aside>`
  130. }
  131. $('.mb__infoCard__basics').html(str);
  132. // Branches
  133. let otherStr = '';
  134. for(let i = 0;i < designer['Branches'].length; i ++) {
  135. otherStr += `<aside class="d-flex">
  136. <div class="mb__infoCard__detail__l">
  137. <div>${designer['Branches'][i].title}</div>
  138. </div>
  139. <div class="mb__infoCard__detail__r">
  140. <a href="${designer['Branches'][i].link}" >${designer['Branches'][i].data}</a>
  141. </div>
  142. </aside>`
  143. }
  144. $('.mb__infoCard__branches').html(otherStr);
  145. // scMedia
  146. let mediaStr = '';
  147. for(let i = 0;i < designer['scMedia'].length; i ++) {
  148. if(i === 4) {
  149. mediaStr += `<span>
  150. <img src="${designer['scMedia'][i].img}" class="dislike" alt="">
  151. <img src="https://hhh.com.tw/assets/images/rv_web/like.svg" class="like" alt="">
  152. </span>`;
  153. } else if (i === 3) {
  154. mediaStr += `<span class="send" data-bs-toggle="modal" data-bs-target="#emailModal">
  155. <img src="${designer['scMedia'][i].img}" alt="">
  156. </span>`;
  157. } else {
  158. mediaStr += `<a href="${designer['scMedia'][i].link}">
  159. <img src="${designer['scMedia'][i].img}" alt="">
  160. </a>`;
  161. }
  162. }
  163. $('.scMedia').html(mediaStr);
  164. document.querySelector('.dislike').addEventListener('click', function() {
  165. $('.dislike').css('display', 'none');
  166. $('.like').css('display', 'block');
  167. })
  168. document.querySelector('.like').addEventListener('click', function() {
  169. $('.dislike').css('display', 'block');
  170. $('.like').css('display', 'none');
  171. })
  172. // term condition
  173. let termStr = '';
  174. for(let i = 0;i < designer['Terms'].length; i ++) {
  175. termStr += `<aside class="d-flex">
  176. <div class="mb__infoCard__detail__l">
  177. <div>${designer['Terms'][i].title}</div>
  178. </div>
  179. <div class="mb__infoCard__detail__r">
  180. <div>${designer['Terms'][i].data}</div>
  181. </div>
  182. </aside>`
  183. }
  184. $('.mb__infoCard__terms').html(termStr);
  185. }
  186. function renderTab(content) {
  187. let tabTitleStr = '';
  188. for(let i = 0;i < content.length; i ++) {
  189. if(i == 0) {
  190. tabTitleStr += `<li class="nav-item p-0 active" role="presentation">
  191. <a class="nav-item-link nav-item-active bg-transparent active" id="pills-${content[i]['Tabtag']}-tab"
  192. data-bs-toggle="pill" data-bs-target="#pills-${content[i]['Tabtag']}" type="button" role="tab"
  193. aria-controls="pills-${content[i]['Tabtag']}" aria-selected="false" data-link="https://hhh.com.tw/videos/lists/">${content[i]['mb_title']}</a>
  194. </li>`
  195. } else if(content[i]['Display_mb']) {
  196. tabTitleStr += `<li class="nav-item p-0" role="presentation">
  197. <a class="nav-item-link nav-item-active bg-transparent" id="pills-${content[i]['Tabtag']}-tab"
  198. data-bs-toggle="pill" data-bs-target="#pills-${content[i]['Tabtag']}" type="button" role="tab"
  199. aria-controls="pills-${content[i]['Tabtag']}" aria-selected="false" data-link="https://hhh.com.tw/videos/lists/">${content[i]['mb_title']}</a>
  200. </li>`
  201. }
  202. }
  203. $('#pills-tab').html(tabTitleStr);
  204. $('.pill-aside').html(tabTitleStr);
  205. }
  206. function renderTabContent(content, meta) {
  207. let tabStr = '';
  208. for(let i = 0;i < content.length; i ++) {
  209. let cardData = ''
  210. if(content[i].info) {
  211. for(let j = 0;j < content[i].info.length; j ++) {
  212. cardData += `<div class="company__block">
  213. <h4 class="company__title">${content[i].info[j].title}</h4>
  214. <div class="company__text">
  215. ${content[i].info[j].data}
  216. </div>
  217. </div>`
  218. }
  219. tabStr += `<div class="tab-pane fade " id="pills-${content[i]['Tabtag']}" role="tabpanel"
  220. aria-labelledby="pills-${content[i]['Tabtag']}-tab">
  221. <div class="row justfy-content-between">
  222. <div class="col-md-8">
  223. <article class="company__article">
  224. ${cardData}
  225. </article>
  226. </div>
  227. </div>
  228. </div>`
  229. } else {
  230. for(let j = 0;j < (content[i].Carddata.length < num_per_page? content[i].Carddata.length: num_per_page); j ++) {
  231. // for(let j = 0;j < content[i].Carddata.length; j ++) {
  232. cardData += `<div class="col-6 col-md-4">
  233. <a href="" target="_blank">
  234. <div class="card">
  235. <div class="card__bgImg" style="background-image: url(${content[i].Carddata[j]['imgURL']});">
  236. </div>
  237. <div class="card-body">
  238. <h5 class="card-title card__title mt-0">${content[i].Carddata[j]['title']}</h5>
  239. <p class="card-text mb-0">
  240. <a href="" class="card__tag" target="_blank">混搭風</a>
  241. <a href="" class="card__tag" target="_blank">混搭風</a>
  242. <a href="" class="card__tag" target="_blank">混搭風</a>
  243. </p>
  244. </div>
  245. </div>
  246. </a>
  247. </div>`
  248. }
  249. if(content[i].Display_mb) {
  250. tabStr += `<div class="tab-pane fade " id="pills-${content[i]['Tabtag']}" role="tabpanel"
  251. aria-labelledby="pills-${content[i]['Tabtag']}-tab">
  252. <div class="row work__row">
  253. ${cardData}
  254. </div>
  255. </div>`
  256. let key = content[i]['Tabtag'];
  257. totalPages[key] = content[i].Carddata.length;
  258. }
  259. }
  260. }
  261. console.log(tabStr);
  262. //console.log(totalPages);
  263. $('#pills-tabContent').html(tabStr);
  264. $('#pills-tabContent').append('<div style="padding: 60px;"></div>');
  265. $('#pills-intro').addClass('active');
  266. $('#pills-intro').addClass('show');
  267. $('#pills-video .card__bgImg').append('<img src="https://hhh.com.tw/assets/images/rv_web/play.svg" alt="" width="50" height="50">')
  268. $('.infoContent .nav-item-link').click(checkTab);
  269. checkTab();
  270. $(`<div id="fb-container" style="width: 320px;" class="mx-auto">
  271. <div class="fb-page" data-href="${meta['FB_link']}" data-tabs="timeline" data-width="320" data-height="700" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true">
  272. <blockquote cite="${meta['FB_link']}" class="fb-xfbml-parse-ignore">
  273. <a href="${meta['FB_link']}">${meta['CompanyName']}</a>
  274. </blockquote>
  275. </div>
  276. </div>
  277. <script async defer crossorigin="anonymous" src="https://connect.facebook.net/zh_TW/sdk.js#xfbml=1&version=v9.0" nonce="7TsDzQN7"></script>
  278. `).insertAfter($('.company__article > .company__block:nth-of-type(1)'));
  279. }
  280. window.addEventListener('scroll', fixedOnScroll);
  281. const navBlock = document.querySelector('.infoContent__navBlock');
  282. function fixedOnScroll() {
  283. if(window.innerHeight < window.innerWidth){
  284. } else {
  285. detectDirection ();
  286. }
  287. if(window.pageYOffset >= over){
  288. navBlock.classList.add('tab_sticky');
  289. } else if(window.pageYOffset < over) {
  290. navBlock.classList.remove('tab_sticky');
  291. }
  292. }
  293. $('.navbar-toggler').click(function(){
  294. $(".sec-menu").css('display', 'block');
  295. $(".wholeBody").css('overflow-y', 'hidden');
  296. $('.sec-menu-block').addClass('slidein');
  297. $('.sec-menu-block').removeClass('slideout');
  298. });
  299. $('.navbar-back').click(function(){
  300. $(".sec-menu").css('display', 'none');
  301. $(".wholeBody").css('overflow-y', 'scroll');
  302. $('.sec-menu-block').removeClass('slidein');
  303. $('.sec-menu-block').addClass('slideout');
  304. });
  305. $('.subexpand').click(function(){
  306. $(this).parent().next().toggleClass('show');
  307. $(this).parent().toggleClass('show');
  308. });
  309. $('.navbar-search').click(function(){
  310. $(".sec-search").css('display', 'block');
  311. $(".wholeBody").css('overflow-y', 'hidden');
  312. })
  313. $('.navbar-backs').click(function(){
  314. $(".sec-search").css('display', 'none');
  315. $(".wholeBody").css('overflow-y', 'scroll');
  316. });
  317. $('.navbar-back-fav').click(function(){
  318. $(".sec-favor").css('display', 'none');
  319. })
  320. $('.btn-gotop').click(function () {
  321. $('html, body').animate({
  322. scrollTop: 0
  323. }, 500)
  324. });
  325. $(window).scroll(function() {
  326. if ( $(this).scrollTop() > 500 ){
  327. $('.fixed-btn').fadeIn(222);
  328. $('.freeCall').fadeIn(222);
  329. } else {
  330. $('.fixed-btn').stop().fadeOut(222);
  331. $('.freeCall').stop().fadeOut(222);
  332. }
  333. }).scroll();
  334. const searchBtn = document.querySelector('.searchBtn');
  335. const searchBar = document.querySelector('.searchBar');
  336. const searchHotLink = document.querySelectorAll('.sec-search-hots__link');
  337. searchBtn.addEventListener('click', search);
  338. searchBar.addEventListener('keyup', pressSearch);
  339. function search() {
  340. if(searchBar.value == '') {
  341. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  342. } else {
  343. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  344. }
  345. }
  346. function pressSearch(e) {
  347. if (e.keyCode === 13) {
  348. e.preventDefault();
  349. search();
  350. }
  351. }
  352. searchHotLink.forEach((item, i) => {
  353. item.addEventListener('click', function() {
  354. window.location.href = `https://m.hhh.com.tw/search/lists/case/${this.textContent}-keyword/`;
  355. })
  356. })
  357. document.addEventListener('lazybeforeunveil', function(e){
  358. var bg = e.target.getAttribute('data-bg');
  359. if(bg){
  360. e.target.style.backgroundImage = 'url(' + bg + ')';
  361. }
  362. });
  363. $('.mb__infoCard__more').click(function() {
  364. $(this).hide();
  365. $('.other').css('display', 'block');
  366. over = document.querySelector('.infoContent__navBlock').offsetTop;
  367. })
  368. checkTab()
  369. $('.infoContent .nav-item-link').click(checkTab);
  370. function checkTab() {
  371. if($('#pills-intro-tab').hasClass('active')) {
  372. $('.likeSee').attr('hidden', false)
  373. } else {
  374. $('.likeSee').attr('hidden', true)
  375. }
  376. }
  377. function renderModalTitle(title) {
  378. $('#emailModal #title').val(title);
  379. }
  380. function loadMore(designer) {
  381. let nowTab = document.querySelector('.infoContent .tab-pane.show');
  382. if(nowTab === document.querySelector('#pills-intro')) {
  383. let last = document.querySelector('#pills-intro .work__row>div:last-child');
  384. let pageNum = Math.ceil(totalPages.intro / 10) - 1;
  385. if ($(window).scrollTop() + $(window).height() >= ($(document).height() - 100)) {
  386. console.log('over');
  387. if(n >= pageNum) {
  388. n = pageNum;
  389. return;
  390. } else {
  391. n ++;
  392. let append = '';
  393. let d = designer['Content'][0].Carddata.slice(10*n, (10*n)+10);
  394. for(let j = 0;j < d.length; j ++) {
  395. append += `<div class="col-6 col-md-4">
  396. <a href="" target="_blank">
  397. <div class="card">
  398. <div style="overflow: hidden;">
  399. <div class="card__bgImg" style="background-image: url(${d[j]['imgURL']});">
  400. </div>
  401. </div>
  402. <div class="card-body">
  403. <h5 class="card-title card__title mt-0">${d[j]['title']}</h5>
  404. <p class="card-text mb-0">
  405. <a href="" class="card__tag" target="_blank">混搭風</a>
  406. <a href="" class="card__tag" target="_blank">混搭風</a>
  407. <a href="" class="card__tag" target="_blank">混搭風</a>
  408. </p>
  409. </div>
  410. </div>
  411. </a>
  412. </div>`
  413. }
  414. $('#pills-intro .work__row').append(append);
  415. }
  416. }
  417. } else if (nowTab === document.querySelector('#pills-video')) {
  418. let pageNum = Math.ceil(totalPages.video / 10) - 1;
  419. console.log(totalPages.video);
  420. let last = document.querySelector('#pills-video .work__row>div:last-child');
  421. if ($(window).scrollTop() + $(window).height() >= ($(document).height() - 100)) {
  422. if(n_video >= pageNum) {
  423. n_video = pageNum;
  424. console.log('n-video:', n_video);
  425. console.log('pageNum', pageNum);
  426. return;
  427. } else {
  428. console.log('pass-video');
  429. n_video ++;
  430. console.log('test');
  431. let append = '';
  432. let d = designer['Content'][1].Carddata.slice(10*n_video, (10*n_video)+10);
  433. for(let j = 0;j < d.length; j ++) {
  434. append += `<div class="col-6 col-md-4">
  435. <a href="" target="_blank">
  436. <div class="card">
  437. <div style="overflow: hidden;">
  438. <div class="card__bgImg" style="background-image: url(${d[j]['imgURL']});">
  439. <img src="https://hhh.com.tw/assets/images/rv_web/play.svg" alt="" width="50" height="50">
  440. </div>
  441. </div>
  442. <div class="card-body">
  443. <h5 class="card-title card__title mt-0">${d[j]['title']}</h5>
  444. <p class="card-text mb-0">
  445. <a href="" class="card__tag" target="_blank">混搭風</a>
  446. <a href="" class="card__tag" target="_blank">混搭風</a>
  447. <a href="" class="card__tag" target="_blank">混搭風</a>
  448. </p>
  449. </div>
  450. </div>
  451. </a>
  452. </div>`
  453. }
  454. $('#pills-video .work__row').append(append);
  455. }
  456. }
  457. } else if (nowTab === document.querySelector('#pills-columns')) {
  458. let last = document.querySelector('#pills-columns .work__row>div:last-child');
  459. let pageNum = Math.ceil(totalPages.columns / 10) - 1;
  460. if ($(window).scrollTop() + $(window).height() >= ($(document).height() - 100)) {
  461. if(n_columns >= pageNum) {
  462. n_columns = pageNum;
  463. return;
  464. } else {
  465. n_columns ++;
  466. console.log('test');
  467. let append = '';
  468. let d = designer['Content'][2].Carddata.slice(10*n_columns, (10*n_columns)+10);
  469. for(let j = 0;j < d.length; j ++) {
  470. append += `<div class="col-6 col-md-4">
  471. <a href="" target="_blank">
  472. <div class="card">
  473. <div style="overflow: hidden;">
  474. <div class="card__bgImg" style="background-image: url(${d[j]['imgURL']});">
  475. </div>
  476. </div>
  477. <div class="card-body">
  478. <h5 class="card-title card__title mt-0">${d[j]['title']}</h5>
  479. <p class="card-text mb-0">
  480. <a href="" class="card__tag" target="_blank">混搭風</a>
  481. <a href="" class="card__tag" target="_blank">混搭風</a>
  482. <a href="" class="card__tag" target="_blank">混搭風</a>
  483. </p>
  484. </div>
  485. </div>
  486. </a>
  487. </div>`
  488. }
  489. $('#pills-columns .work__row').append(append);
  490. }
  491. }
  492. }
  493. }
  494. function putEmail() {
  495. const emailPattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  496. if($('#email').val() !== null && emailPattern.test($('#email').val())) {
  497. $('#error').hide();
  498. $('#putEmail_hidden').css('display', 'block');
  499. $('#add_email').text($('#email').val());
  500. $('#email').val('');
  501. } else {
  502. $('#error').show();
  503. $('#error').text('email 格式有誤');
  504. }
  505. }