forked from divshot/disqus-comments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
disqus-comments.html
158 lines (139 loc) · 4.49 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
<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
-->
<polymer-element name="disqus-comments" attributes="shortname identifier title url categoryId https">
<template>
<style>
:host {
display: block;
}
</style>
<div id="disqus">
<div id="disqus_thread"></div>
</div>
</template>
<script>
(function () {
'use strict';
Polymer({
/**
* 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: '',
/**
* 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: '',
/**
* 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: '',
/**
* 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: '',
/**
* 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: '',
/**
* Force HTTPS when loading Disqus embed script.
*
* @attribute https
* @type boolean
* @default false
*/
https: false,
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.shadowRoot.querySelector('#disqus');
var clone = document.importNode(disq, true);
document.body.appendChild(clone);
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.shadowRoot.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.shadowRoot.querySelector('#disqus');
var clone = document.importNode(disq, true);
document.body.appendChild(clone);
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.shadowRoot.appendChild(clone);
}];
}
});
}
}
});
})();
</script>
</polymer-element>