forked from ktquez/vue-disqus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VueDisqus.vue
93 lines (91 loc) · 2.12 KB
/
VueDisqus.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
<div id="disqus_thread"></div>
</template>
<script>
export default {
name: 'vue-disqus',
props: {
shortname: {
type: String,
required: true
},
identifier: {
type: String,
required: false
},
url: {
type: String,
required: false
},
title: {
type: String,
required: false
},
remote_auth_s3: {
type: String,
required: false
},
api_key: {
type: String,
required: false
},
sso_config: {
type: Object,
required: false
}
},
mounted () {
if (window.DISQUS) {
this.reset(window.DISQUS)
return
}
this.init()
},
methods: {
reset (dsq) {
const self = this
dsq.reset({
reload: true,
config: function () {
self.setBaseConfig(this)
}
})
},
init () {
const self = this
window.disqus_config = function() {
self.setBaseConfig(this)
}
setTimeout(() => {
let d = document
, s = d.createElement('script')
s.setAttribute('id', 'embed-disqus')
s.setAttribute('data-timestamp', +new Date())
s.type = 'text/javascript'
s.async = true
s.src = `//${this.shortname}.disqus.com/embed.js`
;(d.head || d.body).appendChild(s)
}, 0)
},
setBaseConfig (disqusConfig){
disqusConfig.page.identifier = (this.identifier || this.$route.path || window.location.pathname)
disqusConfig.page.url = (this.url || this.$el.baseURI)
if (this.title){
disqusConfig.page.title = this.title;
}
if (this.remote_auth_s3){
disqusConfig.page.remote_auth_s3 = this.remote_auth_s3;
}
if (this.key){
disqusConfig.page.api_key = this.key;
}
if (this.sso_config){
disqusConfig.sso = this.sso_config;
}
disqusConfig.callbacks.onReady = [() => {
this.$emit('ready')
}]
}
}
}
</script>