index-list-mb.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. let userAgent;
  2. let isSafari = false;
  3. let browserName;
  4. $('.likeSee__views').click(function() {
  5. window.location.href = './index_designerList.html'
  6. })
  7. $('.likeSee__sort').click(function() {
  8. window.location.href = './index_designerList.html?q=dateSort'
  9. })
  10. function getpathId(){
  11. let query = window.location.search.split('?').pop();
  12. return query.split('=')[1];
  13. }
  14. function getQuery() {
  15. let query = getpathId();
  16. if(query == 'dateSort'){
  17. filter = 'dateSort';
  18. } else {
  19. filter = 'views';
  20. }
  21. }
  22. window.onload = function(){
  23. //window.scrollBy(0, 1);
  24. if(screen.width >= 901){
  25. window.location.href = "../index_designerList.html";
  26. }
  27. userAgent = navigator.userAgent;
  28. detectBrowser(userAgent);
  29. detectDirection ();
  30. let result;
  31. let designer;
  32. let id = 0;
  33. $.ajax({
  34. method: "GET",
  35. url: "./json/designers.json",
  36. dataType: "json",
  37. }).done(function (msg) {
  38. designer = [...msg][id];
  39. console.log(designer)
  40. renderinfoCard(designer)
  41. // renderTab(designer['Content'])
  42. // renderTabContent(designer['Content'])
  43. });
  44. }
  45. let over = document.querySelector('.infoContent__navBlock').offsetTop;
  46. function detectBrowser(agent){
  47. if(userAgent.match(/chrome|chromium|crios/i)){
  48. browserName = "chrome";
  49. }else if(userAgent.match(/firefox|fxios/i)){
  50. browserName = "firefox";
  51. } else if(userAgent.match(/safari/i)){
  52. browserName = "safari";
  53. }else if(userAgent.match(/opr\//i)){
  54. browserName = "opera";
  55. } else if(userAgent.match(/edg/i)){
  56. browserName = "edge";
  57. }else{
  58. browserName="No browser detection";
  59. }
  60. if(browserName === 'safari'){
  61. isSafari = true;
  62. }
  63. console.log(isSafari);
  64. }
  65. function detectDirection () {
  66. let height = (window.screen.width * 2) / 3;
  67. $('.sec-02 .slide-item').css('height', `${height}px`);
  68. let topHeight = (window.screen.width * 30) / 131;
  69. $('.sec-00 .slide-item').css('height', `${topHeight}px`);
  70. $('.sec-00 .container-fluid').css('height', `${topHeight}px`);
  71. }
  72. function renderinfoCard(designer) {
  73. $('.mb__hero__bgImg').attr('backgroundImage', `url(${designer['BannerImg']})`);
  74. $('.mb__infoCard__avatar').css('backgroundImage', `url(${designer['Designerimg']})`)
  75. $('.mb__infoCard__name').text(designer['DesignerName']);
  76. $('.mb__infoCard__seo').text(designer['Description']);
  77. $('.mb__infoCard__cmy').text(designer['CompanyName']);
  78. if(designer['Approve'] !== '') {
  79. $('.mb__infoCard__approve').text(designer['Approve']);
  80. }
  81. // Basics
  82. let str = '';
  83. for(let i = 0;i < designer['Basics'].length; i ++) {
  84. str += `<aside class="d-flex">
  85. <div class="mb__infoCard__detail__l">
  86. <div>${designer['Basics'][i].title}</div>
  87. </div>
  88. <div class="mb__infoCard__detail__r">
  89. <a href="${designer['Basics'][i].link}">${designer['Basics'][i].data}</a>
  90. </div>
  91. </aside>`
  92. }
  93. $('.mb__infoCard__basics').html(str);
  94. // Branches
  95. let otherStr = '';
  96. for(let i = 0;i < designer['Branches'].length; i ++) {
  97. otherStr += `<aside class="d-flex">
  98. <div class="mb__infoCard__detail__l">
  99. <div>${designer['Branches'][i].title}</div>
  100. </div>
  101. <div class="mb__infoCard__detail__r">
  102. <a href="${designer['Branches'][i].link}" >${designer['Branches'][i].data}</a>
  103. </div>
  104. </aside>`
  105. }
  106. $('.mb__infoCard__branches').html(otherStr);
  107. // scMedia
  108. let mediaStr = '';
  109. for(let i = 0;i < designer['scMedia'].length; i ++) {
  110. if(i === 4) {
  111. mediaStr += `<span>
  112. <img src="${designer['scMedia'][i].img}" class="dislike" alt="">
  113. <img src="https://hhh.com.tw/assets/images/rv_web/like.svg" class="like" alt="">
  114. </span>`;
  115. } else {
  116. mediaStr += `<a href="${designer['scMedia'][i].link}">
  117. <img src="${designer['scMedia'][i].img}" alt="">
  118. </a>`;
  119. }
  120. }
  121. $('.scMedia').html(mediaStr);
  122. document.querySelector('.dislike').addEventListener('click', function() {
  123. $('.dislike').css('display', 'none');
  124. $('.like').css('display', 'block');
  125. })
  126. document.querySelector('.like').addEventListener('click', function() {
  127. $('.dislike').css('display', 'block');
  128. $('.like').css('display', 'none');
  129. })
  130. // term condition
  131. let termStr = '';
  132. for(let i = 0;i < designer['Terms'].length; i ++) {
  133. termStr += `<aside class="d-flex">
  134. <div class="mb__infoCard__detail__l">
  135. <div>${designer['Terms'][i].title}</div>
  136. </div>
  137. <div class="mb__infoCard__detail__r">
  138. <div>${designer['Terms'][i].data}</div>
  139. </div>
  140. </aside>`
  141. }
  142. $('.mb__infoCard__terms').html(termStr);
  143. }
  144. window.addEventListener('scroll', fixedOnScroll);
  145. const navBlock = document.querySelector('.infoContent__navBlock');
  146. function fixedOnScroll() {
  147. if(window.innerHeight < window.innerWidth){
  148. } else {
  149. detectDirection ();
  150. }
  151. if(window.pageYOffset >= over){
  152. navBlock.classList.add('tab_sticky');
  153. } else if(window.pageYOffset < over) {
  154. navBlock.classList.remove('tab_sticky');
  155. }
  156. }
  157. $('.navbar-toggler').click(function(){
  158. $(".sec-menu").css('display', 'block');
  159. $(".wholeBody").css('overflow-y', 'hidden');
  160. $('.sec-menu-block').addClass('slidein');
  161. $('.sec-menu-block').removeClass('slideout');
  162. });
  163. $('.navbar-back').click(function(){
  164. $(".sec-menu").css('display', 'none');
  165. $(".wholeBody").css('overflow-y', 'scroll');
  166. $('.sec-menu-block').removeClass('slidein');
  167. $('.sec-menu-block').addClass('slideout');
  168. });
  169. $('.subexpand').click(function(){
  170. $(this).parent().next().toggleClass('show');
  171. $(this).parent().toggleClass('show');
  172. });
  173. $('.navbar-search').click(function(){
  174. $(".sec-search").css('display', 'block');
  175. $(".wholeBody").css('overflow-y', 'hidden');
  176. })
  177. $('.navbar-backs').click(function(){
  178. $(".sec-search").css('display', 'none');
  179. $(".wholeBody").css('overflow-y', 'scroll');
  180. });
  181. $('.navbar-back-fav').click(function(){
  182. $(".sec-favor").css('display', 'none');
  183. })
  184. $('.btn-gotop').click(function () {
  185. $('html, body').animate({
  186. scrollTop: 0
  187. }, 500)
  188. });
  189. $(window).scroll(function() {
  190. if ( $(this).scrollTop() > 500 ){
  191. $('.fixed-btn').fadeIn(222);
  192. $('.freeCall').fadeIn(222);
  193. } else {
  194. $('.fixed-btn').stop().fadeOut(222);
  195. $('.freeCall').stop().fadeOut(222);
  196. }
  197. }).scroll();
  198. const searchBtn = document.querySelector('.searchBtn');
  199. const searchBar = document.querySelector('.searchBar');
  200. const searchHotLink = document.querySelectorAll('.sec-search-hots__link');
  201. searchBtn.addEventListener('click', search);
  202. searchBar.addEventListener('keyup', pressSearch);
  203. function search() {
  204. if(searchBar.value == '') {
  205. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  206. } else {
  207. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  208. }
  209. }
  210. function pressSearch(e) {
  211. if (e.keyCode === 13) {
  212. e.preventDefault();
  213. search();
  214. }
  215. }
  216. searchHotLink.forEach((item, i) => {
  217. item.addEventListener('click', function() {
  218. window.location.href = `https://m.hhh.com.tw/search/lists/case/${this.textContent}-keyword/`;
  219. })
  220. })
  221. document.addEventListener('lazybeforeunveil', function(e){
  222. var bg = e.target.getAttribute('data-bg');
  223. if(bg){
  224. e.target.style.backgroundImage = 'url(' + bg + ')';
  225. }
  226. });
  227. $('.mb__infoCard__more').click(function() {
  228. $(this).hide();
  229. $('.other').css('display', 'block');
  230. over = document.querySelector('.infoContent__navBlock').offsetTop;
  231. })
  232. checkTab()
  233. $('.infoContent .nav-item-link').click(checkTab);
  234. function checkTab() {
  235. if($('#pills-intro-tab').hasClass('active')) {
  236. $('.likeSee').attr('hidden', false)
  237. } else {
  238. $('.likeSee').attr('hidden', true)
  239. }
  240. }