This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
disqus.js
190 lines (154 loc) · 7.39 KB
/
disqus.js
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
188
189
190
Type.registerNamespace('MoMATool');
var disqus_developer = 0;
var disqus_url = '';
var disqus_title = '';
var disqus_message = '';
var disqus_container_id = "disqus_thread";
var disqus_identifier = '';
MoMATool.DisqusControl = function(element) {
MoMATool.DisqusControl.initializeBase(this, [element]);
this._disqusForum = null;
}
MoMATool.DisqusControl.prototype = {
initialize: function() {
MoMATool.DisqusControl.callBaseMethod(this, 'initialize');
$addHandlers(this.get_element(),
{},
this);
},
dispose: function() {
$clearHandlers(this.get_element());
MoMATool.DisqusControl.callBaseMethod(this, 'dispose');
},
get_disqusForum: function() {
return this._disqusForum;
},
set_disqusForum: function(value) {
if (this._disqusForum !== value) {
this._disqusForum = value;
this.raisePropertyChanged('disqusForum');
}
},
get_disqusDeveloper: function() {
return disqus_developer;
},
set_disqusDeveloper: function(value) {
if (disqus_developer !== value) {
disqus_developer = value;
this.raisePropertyChanged('disqusDeveloper');
}
},
get_disqusContainerId: function() {
return disqus_container_id;
},
set_disqusContainerId: function(value) {
if (value != null && disqus_container_id !== value) {
disqus_container_id = value;
this.raisePropertyChanged('disqusContainerId');
}
},
get_disqusURL: function() {
return disqus_url;
},
set_disqusURL: function(value) {
if (disqus_url !== value) {
disqus_url = value;
this.raisePropertyChanged('disqusURL');
}
},
get_disqusTitle: function() {
return disqus_title;
},
set_disqusTitle: function(value) {
if (disqus_title !== value) {
disqus_title = value;
this.raisePropertyChanged('disqusTitle');
}
},
get_disqusMessage: function() {
return disqus_message;
},
set_disqusMessage: function(value) {
if (disqus_message !== value) {
disqus_message = value;
this.raisePropertyChanged('disqusMessage');
}
},
get_disqusIdentifier: function() {
return disqus_identifier;
},
set_disqusIdentifier: function(value) {
if (disqus_identifier !== value) {
disqus_identifier = value;
this.raisePropertyChanged('disqusIdentifier');
}
},
get_update: function() {},
set_update: function(value) {
if (disqus_identifier !== null && disqus_message != null && disqus_title != null) {
// call the thread creation proxy service to make sure the correct disqus thread gets
// created on demand, and load the iframe when the proxy returns
var forum = this._disqusForum; // makes it easier to reference in the EnsureThreadCreated closure
DisqusProxy.EnsureThreadCreated(disqus_title, disqus_message, disqus_identifier, function(success) {
var disqus_control_iframe = document.getElementById(value);
var doc = disqus_control_iframe.contentDocument;
if (doc == undefined || doc == null) {
doc = disqus_control_iframe.contentWindow.document;
}
doc.open();
// The doctype is needed for IE to load the stylesheet contained inside embed.js. Except something
// seems to have broken it again. &#@%ing IE. Workaround by ripping the CSS out of embed.js and
// referencing it directly. The 'disqus_no_style' setting is needed for firefox when the CSS is
// directly referenced.
var iframe_html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n' +
'<html xmlns="http://www.w3.org/1999/xhtml">\n' +
'<head>\n' +
'<title>Disqus Comments</title>\n' +
'<link href="disqus.css" type="text/css" rel="stylesheet" media="screen"></link>\n' +
'</head><body>\n' +
'<' + 'script charset="utf-8" type="text/javascript">\n' +
'<!--//--><![CDATA[//><!--\n';
if (disqus_developer) {
iframe_html += 'var disqus_developer = 1;\n';
}
iframe_html += 'var disqus_identifier = "' + disqus_identifier + '";\n' +
'window.disqus_no_style = true;\n' +
'//--><!]]>\n' +
'<' + '/script>\n' +
'<div id="disqus_thread"></div>\n' +
'<' + 'script type="text/javascript" src="http://disqus.com/forums/' + forum + '/embed.js"><' + '/script>\n' +
'<a href="http://disqus.com" class="dsq-brlink">Comments powered by <span class="logo-disqus">Disqus</span></a>\n' +
'</body></html>';
doc.write(iframe_html);
doc.close();
// Resize the iframe whenever Disqus loads its content. The fudge factor is needed to ensure
// scrollbars don't appear when the 'Options' button is toggled.
//
// This doesn't work on IE (surprise!) so I just set the height to 2000px there
if (doc.addEventListener) {
doc.addEventListener("DOMNodeInserted", function() {
disqus_control_iframe.height = disqus_control_iframe.contentDocument.body.offsetHeight + 150;
}, false);
doc.addEventListener("DOMNodeRemoved", function() {
disqus_control_iframe.height = disqus_control_iframe.contentDocument.body.offsetHeight + 150;
}, false);
// This one keeps Google Chrome happier (otherwise it doesn't resize properly on first load)
doc.addEventListener("DOMSubtreeModified", function() {
disqus_control_iframe.height = disqus_control_iframe.contentDocument.body.offsetHeight + 150;
}, false);
} else {
disqus_control_iframe.height = '2000px';
}
// I want to set display=none/display=block to hide and show the comments, but it breaks
// in *%$&ing IE. So I have to fart around setting the height to 0px to hide it
//disqus_control_iframe.style.display = 'block';
}, function() {
//alert("DisqusProxy fail");
});
} else {
//alert("Not updating");
}
}
}
MoMATool.DisqusControl.registerClass('MoMATool.DisqusControl', Sys.UI.Control);
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();