forked from atdrupal/disqus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisqus.js
91 lines (83 loc) · 2.74 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
/**
* @file
* JavaScript for the Disqus Drupal module.
*/
// The Disqus global variables.
var disqus_shortname = '';
var disqus_url = '';
var disqus_title = '';
var disqus_identifier = '';
var disqus_developer = 0;
var disqus_def_name = '';
var disqus_def_email = '';
var disqus_config;
(function ($) {
"use strict";
/**
* Drupal Disqus behavior.
*/
Drupal.behaviors.disqus = {
attach: function (context, settings) {
$('body').once('disqus', function() {
// Load the Disqus comments.
if (settings.disqus || false) {
// Setup the global JavaScript variables for Disqus.
disqus_shortname = settings.disqus.domain;
disqus_url = settings.disqus.url;
disqus_title = settings.disqus.title;
disqus_identifier = settings.disqus.identifier;
disqus_developer = settings.disqus.developer || 0;
disqus_def_name = settings.disqus.name || '';
disqus_def_email = settings.disqus.email || '';
// Language and SSO settings are passed in through disqus_config().
disqus_config = function() {
if (settings.disqus.language || false) {
this.language = settings.disqus.language;
}
if (settings.disqus.remote_auth_s3 || false) {
this.page.remote_auth_s3 = settings.disqus.remote_auth_s3;
}
if (settings.disqus.api_key || false) {
this.page.api_key = settings.disqus.api_key;
}
if (settings.disqus.sso || false) {
this.sso = settings.disqus.sso;
}
if (settings.disqus.callbacks || false) {
for (var key in settings.disqus.callbacks) {
for (var i = 0; i < settings.disqus.callbacks[key].length; i++) {
var callback = settings.disqus.callbacks[key][i].split('.');
var fn = window;
for (var j = 0; j < callback.length; j++) {
fn = fn[callback[j]];
}
if(typeof fn === 'function') {
this.callbacks[key].push(fn);
}
}
}
}
};
// Make the AJAX call to get the Disqus comments.
jQuery.ajax({
type: 'GET',
url: '//' + disqus_shortname + '.disqus.com/embed.js',
dataType: 'script',
cache: false
});
}
// Load the comment numbers JavaScript.
if (settings.disqusComments || false) {
disqus_shortname = settings.disqusComments;
// Make the AJAX call to get the number of comments.
jQuery.ajax({
type: 'GET',
url: '//' + disqus_shortname + '.disqus.com/count.js',
dataType: 'script',
cache: false
});
}
});
}
};
})(jQuery);