-
Notifications
You must be signed in to change notification settings - Fork 6
/
disqus-comments.html
187 lines (168 loc) · 4.21 KB
/
disqus-comments.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<link rel="import" href="../polymer/polymer.html">
<!--
Add a Disqus comment thread to your Shadow DOM.
##### Example
<disqus-comments shortname="divshot"></disqus-comments>
To style paragraphs and links, use the following CSS in a global stylesheet:
#disqus_thread p {
color: #333;
}
#disqus_thread a {
color: hotpink;
}
@element disqus-comments
@blurb Add a Disqus comment thread to your Shadow DOM.
@status alpha
@homepage http://elements.divshot.io/disqus-comments
-->
<dom-module name="disqus-comments">
<style>
:host {
display: block;
}
</style>
<template>
<div id="disqus">
<div id="disqus_thread"></div>
</div>
</template>
</dom-module>
<script>
(function () {
'use strict';
Polymer({
is: 'disqus-comments',
properties: {
/**
* A shortname is the unique identifier assigned to a Disqus site.
* All the comments posted to a site are referenced with the shortname.
*
* @attribute shortname
* @type string
* @default 'text'
*/
shortname: {
type: String,
value: '',
notify: true
},
/**
* A Disqus identifier is a unique string which is used to look up a page's
* thread in the Disqus system.
*
* @attribute identifier
* @type string
* @default 'text'
*/
identifier: {
type: String,
value: '',
notify: true
},
/**
* Tells the Disqus service the title of the current page.
* This is used when creating the thread on Disqus for the first time.
*
* @attribute title
* @type string
* @default 'text'
*/
title: {
type: String,
value: '',
notify: true
},
/**
* Tells the Disqus service the URL of the current page.
* If undefined, Disqus will take the window.location.href.
*
* @attribute url
* @type string
* @default 'text'
*/
url: {
type: String,
value: '',
notify: true
},
/**
* Tells the Disqus service the category to be used for the current page.
* This is used when creating the thread on Disqus for the first time.
*
* @attribute categoryId
* @type string
* @default 'text'
*/
categoryId: {
type: String,
value: '',
notify: true
},
/**
* Force HTTPS when loading Disqus embed script.
*
* @attribute https
* @type boolean
* @default false
*/
https: {
type: Boolean,
value: false,
notify: true
}
},
attached: function() {
if (window.DISQUS) {
this.reset();
return;
}
if (this.shortname) {
var disqus_shortname = this.shortname;
} else {
return console.error('Required: Please provide a Disqus shortname.');
}
var el = this;
var disq = this.root.querySelector('#disqus');
var clone = document.createTextNode("");
if(disq)
clone = disq.cloneNode(true);
window.disqus_config = function() {
if (el.identifier) this.page.identifier = el.identifier;
if (el.title) this.page.title = el.title;
if (el.url) this.page.url = el.url;
if (el.categoryId) this.page.category_id = el.categoryId;
this.callbacks.onReady = [function() {
el.root.appendChild(clone);
}];
};
var dsq = document.createElement('script');
var http = (this.https) ? 'https' : 'http';
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = http + '://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
},
reset: function() {
if (window.DISQUS) {
var el = this;
var disq = this.root.querySelector('#disqus');
var clone = document.createTextNode("");
if(disq)
clone = disq.cloneNode(true);
DISQUS.reset({
reload: true,
config: function() {
if (el.identifier) this.page.identifier = el.identifier;
if (el.title) this.page.title = el.title;
if (el.url) this.page.url = el.url;
if (el.categoryId) this.page.category_id = el.categoryId;
this.callbacks.onReady = [function() {
el.root.appendChild(clone);
}];
}
});
}
}
});
})();
</script>