blog-client/plugins/browser.js

70 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-02-07 16:26:17 +08:00
import '~/layouts/common.styl'
2020-07-08 18:13:20 +08:00
import vditor from 'vditor'
import 'vditor/dist/index.css'
2019-02-07 16:26:17 +08:00
const $tags = document.getElementById('tags')
2020-07-10 17:49:51 +08:00
let floatTop = null
if ($tags) {
floatTop = $tags.offsetTop + $tags.scrollHeight + 30
}
2019-02-07 16:26:17 +08:00
2019-12-13 11:46:15 +08:00
function addEvent (obj, type, fn) {
2019-02-07 16:26:17 +08:00
if (obj.attachEvent) {
obj.attachEvent('on' + type, function () {
fn.call(obj)
})
} else {
obj.addEventListener(type, fn, false)
}
}
window.addEvent = addEvent
window.onload = function () {
if (navigator.appName === 'Microsoft Internet Explorer' && parseInt(navigator.appVersion.split(';')[1].replace(/[ ]/g, '').replace('MSIE', '')) <= 9) {
2020-07-08 18:13:20 +08:00
alert('您的浏览器版本过低,继续访问将会出现问题,请升级浏览器版本!') // eslint-disable-line
2019-02-07 16:26:17 +08:00
}
// 底部返回顶部按钮
const top = document.getElementById('gotop')
2020-07-10 17:49:51 +08:00
if (top) {
// 滚动一屏幕时显示回到顶部
addEvent(window, 'scroll', function () {
const currentPosition = document.documentElement.scrollTop || document.body.scrollTop
currentPosition > window.screen.availHeight ? top.style.display = 'block' : top.style.display = 'none'
// 左部导航自动浮动
if (currentPosition > floatTop) {
document.getElementById('navication').style.position = 'fixed'
2019-02-07 16:26:17 +08:00
} else {
2020-07-10 17:49:51 +08:00
document.getElementById('navication').style.position = 'static'
2019-02-07 16:26:17 +08:00
}
2020-07-10 17:49:51 +08:00
})
top.onclick = function () {
var timer = setInterval(function () { // eslint-disable-line
let currentPosition = document.documentElement.scrollTop || document.body.scrollTop
currentPosition -= 100
if (currentPosition > 0) {
window.scrollTo(0, currentPosition)
} else {
window.scrollTo(0, 0)
clearInterval(timer)
}
}, 10)
}
2019-02-07 16:26:17 +08:00
}
let _hmt = _hmt || [] // eslint-disable-line
const hm = document.createElement('script')
hm.src = 'https://hm.baidu.com/hm.js?4c563e5be89b05d4973bbfbb9b8a0aa3'
const s = document.getElementsByTagName('script')[0]
s.parentNode.insertBefore(hm, s)
}
2020-07-08 18:13:20 +08:00
window.Vditor = vditor
2020-07-10 18:01:08 +08:00
2020-07-10 18:01:41 +08:00
window.authSuccess = (data) => { // eslint-disable-line
2020-07-10 18:01:08 +08:00
console.log('授权成功', data)
}