index-designer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. let userAgent;
  2. let isSafari = false;
  3. let browserName;
  4. let filter;
  5. const urlParams = new URLSearchParams(window.location.search);
  6. let getfilter = urlParams.get('q');
  7. let cid = urlParams.get('cid');
  8. console.log(getfilter, cid);
  9. $('.likeSee__views').click(function() {
  10. window.location.href = `./index_designerList.html?q=views&cid=${cid}`
  11. $(this).css('color', '#EE7800');
  12. })
  13. $('.likeSee__sort').click(function() {
  14. window.location.href = `./index_designerList.html?cid=${cid}`
  15. $(this).css('color', '#EE7800');
  16. })
  17. function getQuery() {
  18. let query = getfilter;
  19. if(query == 'views'){
  20. filter = 'views';
  21. $('.likeSee__views').css('color', '#EE7800');
  22. } else {
  23. filter = 'dateSort';
  24. $('.likeSee__sort').css('color', '#EE7800');
  25. }
  26. }
  27. getQuery();
  28. // group data
  29. function group(data) {
  30. var result = [];
  31. var groupItem;
  32. for (var i = 0; i < data.length; i++ ) {
  33. if (i % 18 == 0) {
  34. groupItem != null && result.push(groupItem);
  35. groupItem = [];
  36. }
  37. groupItem.push(data[i]);
  38. }
  39. result.push(groupItem);
  40. return result;
  41. }
  42. // pagination variables
  43. let num_per_page = 9;
  44. let n = 0;
  45. let totalPages = {
  46. intro: 0,
  47. video: 0,
  48. columns: 0,
  49. vr360: 0,
  50. company: 0,
  51. };
  52. window.onload = function(){
  53. if(screen.width < 900){
  54. window.location.href = "../index_designerList_mb.html";
  55. }
  56. userAgent = navigator.userAgent;
  57. detectBrowser(userAgent);
  58. detectDirection ();
  59. let result;
  60. let designer;
  61. let id = 0;
  62. $.ajax({
  63. method: "GET",
  64. url: "./json/realtime.json",
  65. dataType: "json",
  66. }).done(function (msg) {
  67. result = [...msg];
  68. renderSec00(result);
  69. });
  70. $.ajax({
  71. method: "GET",
  72. url: `./json/designers-${cid}.json`,
  73. dataType: "json",
  74. }).done(function (msg) {
  75. designer = [...msg][0];
  76. console.log(designer)
  77. if(filter == 'views'){
  78. designer['Content'][0]['Carddata'].sort(function (a, b){
  79. return a[filter] > b[filter]? -1:1;
  80. })
  81. } else {
  82. designer['Content'][0]['Carddata'].sort(function (a, b){
  83. return a[filter] > b[filter]? 1:-1;
  84. })
  85. }
  86. for(let i = 0; i < designer['Content'].length; i++){
  87. let testArr = group(designer['Content'][i]['Carddata']);
  88. console.log(testArr);
  89. }
  90. console.log(designer['Content'][0]['Carddata']);
  91. renderinfoCard(designer);
  92. renderTab(designer['Content']);
  93. renderTabContent(designer['Content']);
  94. // $(window).scroll(function() {
  95. // loadMore(designer);
  96. // })
  97. });
  98. }
  99. function detectDirection () {
  100. let height = (window.screen.width * 5) / 12;
  101. console.log(height);
  102. $('.sec-02 .slide-item').css('height', `${height}px`);
  103. }
  104. function detectBrowser(agent){
  105. if(userAgent.match(/chrome|chromium|crios/i)){
  106. browserName = "chrome";
  107. }else if(userAgent.match(/firefox|fxios/i)){
  108. browserName = "firefox";
  109. } else if(userAgent.match(/safari/i)){
  110. browserName = "safari";
  111. }else if(userAgent.match(/opr\//i)){
  112. browserName = "opera";
  113. } else if(userAgent.match(/edg/i)){
  114. browserName = "edge";
  115. }else{
  116. browserName="No browser detection";
  117. }
  118. if(browserName === 'safari'){
  119. isSafari = true;
  120. }
  121. console.log(isSafari);
  122. }
  123. function renderSec00(data) {
  124. let temp = data[0]['data'];
  125. renderBullet(temp);
  126. renderBannerStr('sec-00__slider', temp);
  127. $(".sec-00__slider").slick({
  128. dots: false,
  129. speed: 500,
  130. autoplay: true,
  131. autoplaySpeed: 4000,
  132. arrows: true,
  133. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
  134. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>'
  135. });
  136. $('.sec-00__bullet').removeClass('bullet-active');
  137. $('.sec-00__bullet').eq($('.slick-active').data('slick-index')).addClass('bullet-active');
  138. // $('.sec-00__slider').on('beforeChange', function(event, slick, currentSlide, nextSlide){
  139. // console.log(currentSlide);
  140. // console.log($('.slick-active').data('slick-index'));
  141. // });
  142. $('.sec-00__slider').on('afterChange', function(event, slick, currentSlide){
  143. console.log(currentSlide);
  144. console.log($('.slick-active').data('slick-index'));
  145. $('.sec-00__bullet').removeClass('bullet-active');
  146. $('.sec-00__bullet').eq(currentSlide).addClass('bullet-active');
  147. });
  148. }
  149. function renderBullet(data) {
  150. let str = '';
  151. for(let i = 0; i < data.length; i++){
  152. str += '<div class="sec-00__bullet"></div>'
  153. }
  154. console.log('bullet');
  155. $('.sec-00__bulletList').html(str);
  156. }
  157. function renderBannerStr(sec, data) {
  158. let str = '';
  159. for(let i = 0; i < data.length; i++){
  160. if(data[i]['Dwebp'] && !isSafari) {
  161. 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>`
  162. } else {
  163. 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>`
  164. }
  165. }
  166. $(`.${sec}`).html(str);
  167. }
  168. function renderinfoCard(designer) {
  169. $('.hero__img').attr('src', designer['BannerImg']);
  170. $('.infoCard__avatar').css('backgroundImage', `url(${designer['Designerimg']})`)
  171. $('.infoCard__name').text(designer['DesignerName']);
  172. $('.infoCard__seo').text(designer['Description']);
  173. $('.infoCard__company').text(designer['CompanyName']);
  174. if(designer['Approve'] !== '') {
  175. $('.infoCard__approve').text(designer['Approve']);
  176. }
  177. // Basics
  178. let str = '';
  179. for(let i = 0;i < designer['Basics'].length; i ++) {
  180. str += `<aside class="d-flex">
  181. <div class="infoCard__detail__l">
  182. <div>${designer['Basics'][i].title}</div>
  183. </div>
  184. <div class="infoCard__detail__r">
  185. <a href="${designer['Basics'][i].link}">${designer['Basics'][i].data}</a>
  186. </div>
  187. </aside>`
  188. }
  189. $('.infoCard__basics').html(str);
  190. // Branches
  191. let otherStr = '';
  192. for(let i = 0;i < designer['Branches'].length; i ++) {
  193. otherStr += `<aside class="d-flex">
  194. <div class="infoCard__detail__l">
  195. <div>${designer['Branches'][i].title}</div>
  196. </div>
  197. <div class="infoCard__detail__r">
  198. <a href="${designer['Branches'][i].link}" >${designer['Branches'][i].data}</a>
  199. </div>
  200. </aside>`
  201. }
  202. $('.infoCard__branches').html(otherStr);
  203. // scMedia
  204. let mediaStr = '';
  205. for(let i = 0;i < designer['scMedia'].length; i ++) {
  206. if(i === 4) {
  207. mediaStr += `<span>
  208. <img src="${designer['scMedia'][i].img}" class="dislike" alt="">
  209. <img src="https://hhh.com.tw/assets/images/rv_web/like.svg" class="like" alt="">
  210. </span>`;
  211. } else if (i === 3) {
  212. mediaStr += `<span class="send" data-bs-toggle="modal" data-bs-target="#emailModal">
  213. <img src="${designer['scMedia'][i].img}" alt="">
  214. </span>`;
  215. }
  216. else {
  217. mediaStr += `<a href="${designer['scMedia'][i].link}">
  218. <img src="${designer['scMedia'][i].img}" alt="">
  219. </a>`;
  220. }
  221. }
  222. $('.scMedia').html(mediaStr);
  223. document.querySelector('.dislike').addEventListener('click', function() {
  224. $('.dislike').css('display', 'none');
  225. $('.like').css('display', 'block');
  226. })
  227. document.querySelector('.like').addEventListener('click', function() {
  228. $('.dislike').css('display', 'block');
  229. $('.like').css('display', 'none');
  230. })
  231. // term condition
  232. let termStr = '';
  233. for(let i = 0;i < designer['Terms'].length; i ++) {
  234. termStr += `<aside class="d-flex">
  235. <div class="infoCard__detail__l">
  236. <div>${designer['Terms'][i].title}</div>
  237. </div>
  238. <div class="infoCard__detail__r">
  239. <div>${designer['Terms'][i].data}</div>
  240. </div>
  241. </aside>`
  242. }
  243. $('.infoCard__terms').html(termStr);
  244. }
  245. function renderTab(content) {
  246. let tabTitleStr = '';
  247. for(let i = 0;i < content.length; i ++) {
  248. if(i == 0) {
  249. tabTitleStr += `<li class="nav-item p-0 " role="presentation">
  250. <a class="nav-item-link nav-item-active bg-transparent active" id="pills-${content[i]['Tabtag']}-tab"
  251. data-bs-toggle="pill" data-bs-target="#pills-${content[i]['Tabtag']}" type="button" role="tab"
  252. aria-controls="pills-${content[i]['Tabtag']}" aria-selected="false" data-link="https://hhh.com.tw/videos/lists/">${content[i]['Title']}</a>
  253. </li>`
  254. } else if (content[i]['isActive']) {
  255. tabTitleStr += `<li class="nav-item p-0" role="presentation">
  256. <a class="nav-item-link nav-item-active bg-transparent" id="pills-${content[i]['Tabtag']}-tab"
  257. data-bs-toggle="pill" data-bs-target="#pills-${content[i]['Tabtag']}" type="button" role="tab"
  258. aria-controls="pills-${content[i]['Tabtag']}" aria-selected="false" data-link="https://hhh.com.tw/videos/lists/">${content[i]['Title']}</a>
  259. </li>`
  260. }
  261. }
  262. $('#pills-tab').html(tabTitleStr);
  263. $('.pill-aside').html(tabTitleStr);
  264. }
  265. function renderCard(content, i = 0){
  266. let cardData = '';
  267. let data = content[i];
  268. for(let j = 0;j < data.length; j ++) {
  269. cardData += `<div class="col-md-4">
  270. <a href="" target="_blank">
  271. <div class="card">
  272. <div class="card__bgImg" style="background-image: url(${data[i]['imgURL']});">
  273. </div>
  274. <div class="card-body">
  275. <h5 class="card-title card__title mt-0">${data[i]['title']}</h5>
  276. <p class="card-text mb-0">
  277. <a href="" class="card__tag" target="_blank">混搭風</a>
  278. <a href="" class="card__tag" target="_blank">混搭風</a>
  279. <a href="" class="card__tag" target="_blank">混搭風</a>
  280. </p>
  281. </div>
  282. </div>
  283. </a>
  284. </div>`
  285. $('#pills-intro .work__row').append(cardData);
  286. }
  287. }
  288. function renderTabContent(content) {
  289. let tabStr = '';
  290. for(let i = 0;i < content.length; i ++) {
  291. let cardData = ''
  292. if(content[i].info) {
  293. for(let j = 0;j < content[i].info.length; j ++) {
  294. cardData += `<div class="company__block">
  295. <h4 class="company__title">${content[i].info[j].title}</h4>
  296. <div class="company__text">
  297. ${content[i].info[j].data}
  298. </div>
  299. </div>`
  300. }
  301. tabStr += `<div class="tab-pane fade " id="pills-${content[i]['Tabtag']}" role="tabpanel"
  302. aria-labelledby="pills-${content[i]['Tabtag']}-tab">
  303. <div class="row justfy-content-between">
  304. <div class="col-md-8">
  305. <article class="company__article">
  306. ${cardData}
  307. </article>
  308. </div>
  309. </div>
  310. </div>`
  311. } else {
  312. // for(let j = 0;j < (content[i].Carddata.length < num_per_page? content[i].Carddata.length: num_per_page); j ++) {
  313. for(let j = 0;j < content[i].Carddata.length; j ++) {
  314. let tagStr = '';
  315. for(let k = 0;k < content[i].Carddata[j].tags.length; k ++) {
  316. tagStr += `<a href="${content[i].Carddata[j].tags[k]['link']}" class="card__tag" target="_blank">${content[i].Carddata[j].tags[k]['name']}</a>`
  317. }
  318. cardData += `<div class="col-md-4">
  319. <a href="" target="_blank">
  320. <div class="card">
  321. <div class="card__bgImg" style="background-image: url(${content[i].Carddata[j]['imgURL']});">
  322. </div>
  323. <div class="card-body">
  324. <h5 class="card-title card__title mt-0">${content[i].Carddata[j]['title']}</h5>
  325. <p class="card-text mb-0">
  326. ${tagStr}
  327. </p>
  328. </div>
  329. </div>
  330. </a>
  331. </div>`
  332. }
  333. tabStr += `<div class="tab-pane fade " id="pills-${content[i]['Tabtag']}" role="tabpanel"
  334. aria-labelledby="pills-${content[i]['Tabtag']}-tab">
  335. <div class="row work__row">
  336. ${cardData}
  337. </div>
  338. </div>`
  339. // let key = content[i]['Tabtag'];
  340. // totalPages[key] = content[i].Carddata.length;
  341. }
  342. }
  343. console.log(tabStr);
  344. console.log(totalPages);
  345. $('#pills-tabContent').html(tabStr);
  346. $('#pills-tabContent').append('<div style="padding: 40px;"></div>');
  347. $('#pills-intro').addClass('active');
  348. $('#pills-intro').addClass('show');
  349. $('#pills-video .card__bgImg').append('<img src="https://hhh.com.tw/assets/images/rv_web/play.svg" alt="" width="50" height="50">')
  350. $('.infoContent .nav-item-link').click(checkTab);
  351. checkTab();
  352. }
  353. function checkTab() {
  354. if($('#pills-intro-tab').hasClass('active')) {
  355. $('.likeSee').attr('hidden', false)
  356. } else {
  357. $('.likeSee').attr('hidden', true)
  358. }
  359. }
  360. $(document).on("click","#pills-tab .nav-item-link",function() {
  361. console.log($(this));
  362. console.log($(this).attr('id'));
  363. let className = $(this).attr('id');
  364. $(`#pills-tab .nav-item-link`).removeClass('active');
  365. $(`#${className}`).addClass('active');
  366. $(`.pill-aside #${className}`).addClass('active');
  367. });
  368. let sticky = document.querySelector('.sec-00').offsetHeight;
  369. window.addEventListener('scroll', fixedOnScroll);
  370. const navbar = document.querySelector('.navbar-main');
  371. function fixedOnScroll() {
  372. if(window.pageYOffset >= 344){
  373. navbar.classList.add('sticky');
  374. } else {
  375. navbar.classList.remove('sticky');
  376. }
  377. }
  378. $(window).scroll(function() {
  379. if ( $(this).scrollTop() > 800 ){
  380. $('.fixed-btn').fadeIn(222);
  381. } else {
  382. $('.fixed-btn').stop().fadeOut(222);
  383. }
  384. }).scroll();
  385. function loadMore(designer) {
  386. let nowTab = document.querySelector('.infoContent .tab-pane.show');
  387. if(nowTab === document.querySelector('#pills-intro')) {
  388. let last = document.querySelector('#pills-intro .work__row>div:last-child');
  389. let pageNum = Math.ceil(totalPages.intro / 9);
  390. if ($(this).scrollTop() > last.offsetTop) {
  391. if(n >= pageNum) {
  392. n = pageNum;
  393. return;
  394. } else {
  395. n ++;
  396. console.log('test');
  397. let append = '';
  398. let d = designer['Content'][0].Carddata.slice(9*n, (9*n)+9);
  399. for(let j = 0;j < d.length; j ++) {
  400. append += `<div class="col-md-4">
  401. <a href="" target="_blank">
  402. <div class="card">
  403. <div class="card__bgImg" style="background-image: url(${d[j]['imgURL']});">
  404. </div>
  405. <div class="card-body">
  406. <h5 class="card-title card__title mt-0">${d[j]['title']}</h5>
  407. <p class="card-text mb-0">
  408. <a href="" class="card__tag" target="_blank">混搭風</a>
  409. <a href="" class="card__tag" target="_blank">混搭風</a>
  410. <a href="" class="card__tag" target="_blank">混搭風</a>
  411. </p>
  412. </div>
  413. </div>
  414. </a>
  415. </div>`
  416. }
  417. $('#pills-intro .work__row').append(append);
  418. }
  419. }
  420. } else if (nowTab === document.querySelector('#pills-video')) {
  421. let pageNum = Math.ceil(totalPages.intro / 9);
  422. let last = document.querySelector('#pills-video .work__row>div:last-child');
  423. console.log(last);
  424. if ($(this).scrollTop() > last.offsetTop) {
  425. if(n >= pageNum) {
  426. n = pageNum;
  427. return;
  428. } else {
  429. n ++;
  430. console.log('test');
  431. let append = '';
  432. let d = designer['Content'][0].Carddata.slice(9*n, (9*n)+9);
  433. for(let j = 0;j < d.length; j ++) {
  434. append += `<div class="col-md-4">
  435. <a href="" target="_blank">
  436. <div class="card">
  437. <div class="card__bgImg" style="background-image: url(${d[j]['imgURL']});">
  438. <img src="https://hhh.com.tw/assets/images/rv_web/play.svg" alt="" width="50" height="50">
  439. </div>
  440. <div class="card-body">
  441. <h5 class="card-title card__title mt-0">${d[j]['title']}</h5>
  442. <p class="card-text mb-0">
  443. <a href="" class="card__tag" target="_blank">混搭風</a>
  444. <a href="" class="card__tag" target="_blank">混搭風</a>
  445. <a href="" class="card__tag" target="_blank">混搭風</a>
  446. </p>
  447. </div>
  448. </div>
  449. </a>
  450. </div>`
  451. }
  452. $('#pills-video .work__row').append(append);
  453. }
  454. }
  455. } else if (nowTab === document.querySelector('#pills-columns')) {
  456. let last = document.querySelector('#pills-columns .work__row>div:last-child');
  457. let pageNum = Math.ceil(totalPages.intro / 9);
  458. if ($(this).scrollTop() > last) {
  459. if(n >= pageNum) {
  460. n = pageNum;
  461. return;
  462. } else {
  463. n ++;
  464. console.log('test');
  465. let append = '';
  466. let d = designer['Content'][0].Carddata.slice(9*n, (9*n)+9);
  467. for(let j = 0;j < d.length; j ++) {
  468. append += `<div class="col-md-4">
  469. <a href="" target="_blank">
  470. <div class="card">
  471. <div class="card__bgImg" style="background-image: url(${d[j]['imgURL']});">
  472. </div>
  473. <div class="card-body">
  474. <h5 class="card-title card__title mt-0">${d[j]['title']}</h5>
  475. <p class="card-text mb-0">
  476. <a href="" class="card__tag" target="_blank">混搭風</a>
  477. <a href="" class="card__tag" target="_blank">混搭風</a>
  478. <a href="" class="card__tag" target="_blank">混搭風</a>
  479. </p>
  480. </div>
  481. </div>
  482. </a>
  483. </div>`
  484. }
  485. $('#pills-columns .work__row').append(append);
  486. }
  487. }
  488. }
  489. }
  490. $('.btn-gotop').click(function () {
  491. $('html, body').animate({
  492. scrollTop: 0
  493. }, 500)
  494. });
  495. $('.sec-00__close').click(function(){
  496. $(this).css('display', 'none');
  497. $('.sec-00').addClass('bannerClose');
  498. //$('.sec-02').css('padding-top', '53px');
  499. sticky = 0;
  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. });