index-list-mb.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. let userAgent;
  2. let isSafari = false;
  3. let browserName;
  4. let num_per_page = 9;
  5. let n = 0;
  6. let totalPages = {
  7. intro: 0,
  8. video: 0,
  9. columns: 0,
  10. vr360: 0,
  11. company: 0,
  12. };
  13. let filter;
  14. $('.likeSee__views').click(function() {
  15. window.location.href = './index_designerList_mb.html'
  16. })
  17. $('.likeSee__sort').click(function() {
  18. window.location.href = './index_designerList_mb.html?q=dateSort'
  19. })
  20. function getpathId(){
  21. let query = window.location.search.split('?').pop();
  22. return query.split('=')[1];
  23. }
  24. function getQuery() {
  25. let query = getpathId();
  26. console.log(query);
  27. if(query == 'dateSort'){
  28. filter = 'dateSort';
  29. } else {
  30. filter = 'views';
  31. }
  32. }
  33. window.onload = function(){
  34. //window.scrollBy(0, 1);
  35. if(screen.width >= 901){
  36. window.location.href = "../index_designerList.html";
  37. }
  38. userAgent = navigator.userAgent;
  39. detectBrowser(userAgent);
  40. detectDirection ();
  41. let result;
  42. let designer;
  43. let id = 0;
  44. $.ajax({
  45. method: "GET",
  46. url: "./json/designers.json",
  47. dataType: "json",
  48. }).done(function (msg) {
  49. getQuery();
  50. designer = [...msg][id];
  51. console.log(designer['Content']);
  52. designer['Content'][0]['Carddata'].sort(function (a, b){
  53. return a[filter] > b[filter]? -1:1;
  54. })
  55. renderinfoCard(designer);
  56. renderTab(designer['Content']);
  57. renderTabContent(designer['Content']);
  58. console.log(filter);
  59. console.log(designer['Content'][0]['Carddata']);
  60. });
  61. }
  62. let over = document.querySelector('.infoContent__navBlock').offsetTop+ 60;
  63. function detectBrowser(agent){
  64. if(userAgent.match(/chrome|chromium|crios/i)){
  65. browserName = "chrome";
  66. }else if(userAgent.match(/firefox|fxios/i)){
  67. browserName = "firefox";
  68. } else if(userAgent.match(/safari/i)){
  69. browserName = "safari";
  70. }else if(userAgent.match(/opr\//i)){
  71. browserName = "opera";
  72. } else if(userAgent.match(/edg/i)){
  73. browserName = "edge";
  74. }else{
  75. browserName="No browser detection";
  76. }
  77. if(browserName === 'safari'){
  78. isSafari = true;
  79. }
  80. console.log(isSafari);
  81. }
  82. function detectDirection () {
  83. let height = (window.screen.width * 2) / 3;
  84. $('.sec-02 .slide-item').css('height', `${height}px`);
  85. let topHeight = (window.screen.width * 30) / 131;
  86. $('.sec-00 .slide-item').css('height', `${topHeight}px`);
  87. $('.sec-00 .container-fluid').css('height', `${topHeight}px`);
  88. }
  89. function renderinfoCard(designer) {
  90. $('.mb__hero__bgImg').attr('backgroundImage', `url(${designer['BannerImg']})`);
  91. $('.mb__infoCard__avatar').css('backgroundImage', `url(${designer['Designerimg']})`)
  92. $('.mb__infoCard__name').text(designer['DesignerName']);
  93. $('.mb__infoCard__seo').text(designer['Description']);
  94. $('.mb__infoCard__cmy').text(designer['CompanyName']);
  95. if(designer['Approve'] !== '') {
  96. $('.mb__infoCard__approve').text(designer['Approve']);
  97. }
  98. // Basics
  99. let str = '';
  100. for(let i = 0;i < designer['Basics'].length; i ++) {
  101. str += `<aside class="d-flex">
  102. <div class="mb__infoCard__detail__l">
  103. <div>${designer['Basics'][i].title}</div>
  104. </div>
  105. <div class="mb__infoCard__detail__r">
  106. <a href="${designer['Basics'][i].link}">${designer['Basics'][i].data}</a>
  107. </div>
  108. </aside>`
  109. }
  110. $('.mb__infoCard__basics').html(str);
  111. // Branches
  112. let otherStr = '';
  113. for(let i = 0;i < designer['Branches'].length; i ++) {
  114. otherStr += `<aside class="d-flex">
  115. <div class="mb__infoCard__detail__l">
  116. <div>${designer['Branches'][i].title}</div>
  117. </div>
  118. <div class="mb__infoCard__detail__r">
  119. <a href="${designer['Branches'][i].link}" >${designer['Branches'][i].data}</a>
  120. </div>
  121. </aside>`
  122. }
  123. $('.mb__infoCard__branches').html(otherStr);
  124. // scMedia
  125. let mediaStr = '';
  126. for(let i = 0;i < designer['scMedia'].length; i ++) {
  127. if(i === 4) {
  128. mediaStr += `<span>
  129. <img src="${designer['scMedia'][i].img}" class="dislike" alt="">
  130. <img src="https://hhh.com.tw/assets/images/rv_web/like.svg" class="like" alt="">
  131. </span>`;
  132. } else {
  133. mediaStr += `<a href="${designer['scMedia'][i].link}">
  134. <img src="${designer['scMedia'][i].img}" alt="">
  135. </a>`;
  136. }
  137. }
  138. $('.scMedia').html(mediaStr);
  139. document.querySelector('.dislike').addEventListener('click', function() {
  140. $('.dislike').css('display', 'none');
  141. $('.like').css('display', 'block');
  142. })
  143. document.querySelector('.like').addEventListener('click', function() {
  144. $('.dislike').css('display', 'block');
  145. $('.like').css('display', 'none');
  146. })
  147. // term condition
  148. let termStr = '';
  149. for(let i = 0;i < designer['Terms'].length; i ++) {
  150. termStr += `<aside class="d-flex">
  151. <div class="mb__infoCard__detail__l">
  152. <div>${designer['Terms'][i].title}</div>
  153. </div>
  154. <div class="mb__infoCard__detail__r">
  155. <div>${designer['Terms'][i].data}</div>
  156. </div>
  157. </aside>`
  158. }
  159. $('.mb__infoCard__terms').html(termStr);
  160. }
  161. function renderTab(content) {
  162. let tabTitleStr = '';
  163. for(let i = 0;i < content.length; i ++) {
  164. if(i == 0) {
  165. tabTitleStr += `<li class="nav-item p-0 active" role="presentation">
  166. <a class="nav-item-link nav-item-active bg-transparent active" id="pills-${content[i]['Tabtag']}-tab"
  167. data-bs-toggle="pill" data-bs-target="#pills-${content[i]['Tabtag']}" type="button" role="tab"
  168. aria-controls="pills-${content[i]['Tabtag']}" aria-selected="false" data-link="https://hhh.com.tw/videos/lists/">${content[i]['mb_title']}</a>
  169. </li>`
  170. } else if(content[i]['Display_mb']) {
  171. tabTitleStr += `<li class="nav-item p-0" role="presentation">
  172. <a class="nav-item-link nav-item-active bg-transparent" id="pills-${content[i]['Tabtag']}-tab"
  173. data-bs-toggle="pill" data-bs-target="#pills-${content[i]['Tabtag']}" type="button" role="tab"
  174. aria-controls="pills-${content[i]['Tabtag']}" aria-selected="false" data-link="https://hhh.com.tw/videos/lists/">${content[i]['mb_title']}</a>
  175. </li>`
  176. }
  177. }
  178. $('#pills-tab').html(tabTitleStr);
  179. $('.pill-aside').html(tabTitleStr);
  180. }
  181. function renderTabContent(content) {
  182. let tabStr = '';
  183. for(let i = 0;i < content.length; i ++) {
  184. let cardData = ''
  185. if(content[i].info) {
  186. for(let j = 0;j < content[i].info.length; j ++) {
  187. cardData += `<div class="company__block">
  188. <h4 class="company__title">${content[i].info[j].title}</h4>
  189. <div class="company__text">
  190. ${content[i].info[j].data}
  191. </div>
  192. </div>`
  193. }
  194. tabStr += `<div class="tab-pane fade " id="pills-${content[i]['Tabtag']}" role="tabpanel"
  195. aria-labelledby="pills-${content[i]['Tabtag']}-tab">
  196. <div class="row justfy-content-between">
  197. <div class="col-md-8">
  198. <article class="company__article">
  199. ${cardData}
  200. </article>
  201. </div>
  202. </div>
  203. </div>`
  204. } else {
  205. for(let j = 0;j < content[i].Carddata.length; j ++) {
  206. cardData += `<div class="col-6 col-md-4">
  207. <a href="" target="_blank">
  208. <div class="card">
  209. <div class="card__bgImg" style="background-image: url(${content[i].Carddata[j]['imgURL']});">
  210. </div>
  211. <div class="card-body">
  212. <h5 class="card-title card__title mt-0">${content[i].Carddata[j]['title']}</h5>
  213. <p class="card-text mb-0">
  214. <a href="" class="card__tag" target="_blank">混搭風</a>
  215. <a href="" class="card__tag" target="_blank">混搭風</a>
  216. <a href="" class="card__tag" target="_blank">混搭風</a>
  217. </p>
  218. </div>
  219. </div>
  220. </a>
  221. </div>`
  222. }
  223. if(content[i].Display_mb) {
  224. tabStr += `<div class="tab-pane fade " id="pills-${content[i]['Tabtag']}" role="tabpanel"
  225. aria-labelledby="pills-${content[i]['Tabtag']}-tab">
  226. <div class="row work__row">
  227. ${cardData}
  228. </div>
  229. </div>`
  230. let key = content[i]['Tabtag'];
  231. totalPages[key] = content[i].Carddata.length;
  232. }
  233. }
  234. }
  235. console.log(tabStr);
  236. //console.log(totalPages);
  237. $('#pills-tabContent').html(tabStr);
  238. $('#pills-tabContent').append('<div style="padding: 40px;"></div>');
  239. $('#pills-intro').addClass('active');
  240. $('#pills-intro').addClass('show');
  241. $('#pills-video .card__bgImg').append('<img src="https://hhh.com.tw/assets/images/rv_web/play.svg" alt="" width="50" height="50">')
  242. $('.infoContent .nav-item-link').click(checkTab);
  243. checkTab();
  244. }
  245. window.addEventListener('scroll', fixedOnScroll);
  246. const navBlock = document.querySelector('.infoContent__navBlock');
  247. function fixedOnScroll() {
  248. if(window.innerHeight < window.innerWidth){
  249. } else {
  250. detectDirection ();
  251. }
  252. if(window.pageYOffset >= over){
  253. navBlock.classList.add('tab_sticky');
  254. } else if(window.pageYOffset < over) {
  255. navBlock.classList.remove('tab_sticky');
  256. }
  257. }
  258. $('.navbar-toggler').click(function(){
  259. $(".sec-menu").css('display', 'block');
  260. $(".wholeBody").css('overflow-y', 'hidden');
  261. $('.sec-menu-block').addClass('slidein');
  262. $('.sec-menu-block').removeClass('slideout');
  263. });
  264. $('.navbar-back').click(function(){
  265. $(".sec-menu").css('display', 'none');
  266. $(".wholeBody").css('overflow-y', 'scroll');
  267. $('.sec-menu-block').removeClass('slidein');
  268. $('.sec-menu-block').addClass('slideout');
  269. });
  270. $('.subexpand').click(function(){
  271. $(this).parent().next().toggleClass('show');
  272. $(this).parent().toggleClass('show');
  273. });
  274. $('.navbar-search').click(function(){
  275. $(".sec-search").css('display', 'block');
  276. $(".wholeBody").css('overflow-y', 'hidden');
  277. })
  278. $('.navbar-backs').click(function(){
  279. $(".sec-search").css('display', 'none');
  280. $(".wholeBody").css('overflow-y', 'scroll');
  281. });
  282. $('.navbar-back-fav').click(function(){
  283. $(".sec-favor").css('display', 'none');
  284. })
  285. $('.btn-gotop').click(function () {
  286. $('html, body').animate({
  287. scrollTop: 0
  288. }, 500)
  289. });
  290. $(window).scroll(function() {
  291. if ( $(this).scrollTop() > 500 ){
  292. $('.fixed-btn').fadeIn(222);
  293. $('.freeCall').fadeIn(222);
  294. } else {
  295. $('.fixed-btn').stop().fadeOut(222);
  296. $('.freeCall').stop().fadeOut(222);
  297. }
  298. }).scroll();
  299. const searchBtn = document.querySelector('.searchBtn');
  300. const searchBar = document.querySelector('.searchBar');
  301. const searchHotLink = document.querySelectorAll('.sec-search-hots__link');
  302. searchBtn.addEventListener('click', search);
  303. searchBar.addEventListener('keyup', pressSearch);
  304. function search() {
  305. if(searchBar.value == '') {
  306. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  307. } else {
  308. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  309. }
  310. }
  311. function pressSearch(e) {
  312. if (e.keyCode === 13) {
  313. e.preventDefault();
  314. search();
  315. }
  316. }
  317. searchHotLink.forEach((item, i) => {
  318. item.addEventListener('click', function() {
  319. window.location.href = `https://m.hhh.com.tw/search/lists/case/${this.textContent}-keyword/`;
  320. })
  321. })
  322. document.addEventListener('lazybeforeunveil', function(e){
  323. var bg = e.target.getAttribute('data-bg');
  324. if(bg){
  325. e.target.style.backgroundImage = 'url(' + bg + ')';
  326. }
  327. });
  328. $('.mb__infoCard__more').click(function() {
  329. $(this).hide();
  330. $('.other').css('display', 'block');
  331. over = document.querySelector('.infoContent__navBlock').offsetTop;
  332. })
  333. checkTab()
  334. $('.infoContent .nav-item-link').click(checkTab);
  335. function checkTab() {
  336. if($('#pills-intro-tab').hasClass('active')) {
  337. $('.likeSee').attr('hidden', false)
  338. } else {
  339. $('.likeSee').attr('hidden', true)
  340. }
  341. }