common.js.下载 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var toArray = function (obj) {
  2. return Array.prototype.slice.call(obj)
  3. }
  4. ; (function () {
  5. document.addEventListener('DOMContentLoaded', function () {
  6. function throttle(fn, threshhold) {
  7. var last
  8. var timer
  9. threshhold || (threshhold = 250)
  10. return function () {
  11. var context = this
  12. var args = arguments
  13. var now = +new Date()
  14. if (last && now < last + threshhold) {
  15. clearTimeout(timer)
  16. timer = setTimeout(function () {
  17. last = now
  18. fn.apply(context, args)
  19. }, threshhold)
  20. } else {
  21. last = now
  22. fn.apply(context, args)
  23. }
  24. }
  25. }
  26. // Scroll window, active navbar bottom border
  27. var space = document.getElementById('space')
  28. if (space) {
  29. window.onscroll = throttle(function () {
  30. window.scrollY ? space.classList.add('scrolled') : space.classList.remove('scrolled')
  31. }, 200)
  32. }
  33. // Select navbar
  34. var navbarLinks = toArray(document.querySelectorAll('.navbar-link'))
  35. var currentURL = window.location.href
  36. if (navbarLinks) {
  37. navbarLinks.forEach(function (item) {
  38. if (currentURL.indexOf(item.href) !== -1) {
  39. item.classList.add('active')
  40. } else {
  41. item.classList.remove('acitve')
  42. }
  43. })
  44. }
  45. // Click navbar mobile menu
  46. var navbarMobileContainer = document.getElementById('navbar-mobile-container')
  47. var navbarMobileMenuBtn = document.getElementById('navbar-mobile-menu-btn')
  48. if (navbarMobileContainer && navbarMobileMenuBtn) {
  49. navbarMobileMenuBtn.onclick = function () {
  50. var isActive = navbarMobileContainer.classList.contains('active')
  51. if (isActive) {
  52. navbarMobileMenuBtn.classList.remove('is-active')
  53. navbarMobileContainer.classList.remove('active')
  54. } else {
  55. navbarMobileMenuBtn.classList.add('is-active')
  56. navbarMobileContainer.classList.add('active')
  57. }
  58. }
  59. }
  60. })
  61. })()
  62. ; (function () {
  63. function getUA() {
  64. return window.navigator.userAgent.toLowerCase()
  65. }
  66. function isWeixinBrowser() {
  67. return /micromessenger/.test(getUA())
  68. }
  69. function isAndroid() {
  70. return getUA().indexOf('android') !== -1
  71. }
  72. function isIOS() {
  73. return /ipad|iphone|ipod/.test(getUA())
  74. }
  75. function showHideDownloadItemsHelper(domArr, addClass, removeClass1, removeClass2) {
  76. domArr.forEach(function (dom) {
  77. addClass && dom.classList.add(addClass)
  78. removeClass1 && dom.classList.remove(removeClass1)
  79. removeClass2 && dom.classList.remove(removeClass2)
  80. })
  81. }
  82. function trackDownload() {
  83. var downloadBtns = toArray(document.querySelectorAll('.js_download'))
  84. downloadBtns.forEach(function (item) {
  85. item.onclick = function (e) {
  86. // download event tracking
  87. var { source, link } = this.dataset;
  88. var track = function (category) {
  89. ga && ga('send', 'event', 'downloads', 'click', category, 0)
  90. }
  91. if (!!link) {
  92. track(`${source}: ${link}`)
  93. return
  94. }
  95. track(source)
  96. }
  97. })
  98. }
  99. function trackHelpScout() {
  100. var helpScoutBlock = document.querySelector("#beacon-container .BeaconFabButtonFrame iframe")
  101. helpScoutBlock.contentDocument.onclick = function () {
  102. ga && ga('send', 'event', 'help_scout', 'click', window.location.pathname, 0)
  103. }
  104. }
  105. function addGATrack() {
  106. trackDownload()
  107. if (isWeixinBrowser()) {
  108. wechatBg.onclick = function () {
  109. wechatBg.classList.remove('active')
  110. }
  111. }
  112. }
  113. addGATrack();
  114. window.Beacon('on', 'ready', trackHelpScout)
  115. document.addEventListener('DOMContentLoaded', addGATrack);
  116. })();