Skip to content

Commit e23062c

Browse files
committed
readyToBind fix
Using boolean for readyToBind wasn't enough for reload, since watch doesn't get triggered if "loaded = true;" was set on angular's routeChangeSuccess event (probably because the value actually doesn't change). Therefore 'isReady & boolean' was replaced with 'loadedOn / DateTime' and since on each call there is a new value, readyToBind gets triggered.
1 parent a5e1a86 commit e23062c

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/directives/disqus/dirDisqus.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Available under the MIT license.
77
*/
88

9-
(function() {
9+
(function () {
1010

1111
/**
1212
* Config
@@ -19,53 +19,53 @@
1919
var module;
2020
try {
2121
module = angular.module(moduleName);
22-
} catch(err) {
22+
} catch (err) {
2323
// named module does not exist, so create one
2424
module = angular.module(moduleName, []);
2525
}
2626

27-
module.directive('dirDisqus', ['$window', function($window) {
27+
module.directive('dirDisqus', ['$window', function ($window) {
2828
return {
2929
restrict: 'E',
3030
scope: {
3131
disqus_shortname: '@disqusShortname',
3232
disqus_identifier: '@disqusIdentifier',
33-
disqus_title: '@disqusTitle',
3433
disqus_url: '@disqusUrl',
34+
disqus_title: '@disqusTitle',
3535
disqus_category_id: '@disqusCategoryId',
3636
disqus_disable_mobile: '@disqusDisableMobile',
37-
disqus_config_language : '@disqusConfigLanguage',
38-
disqus_remote_auth_s3 : '@disqusRemoteAuthS3',
39-
disqus_api_key : '@disqusApiKey',
37+
disqus_config_language: '@disqusConfigLanguage',
38+
disqus_remote_auth_s3: '@disqusRemoteAuthS3',
39+
disqus_api_key: '@disqusApiKey',
4040
disqus_on_ready: "&disqusOnReady",
4141
readyToBind: "@"
4242
},
4343
template: '<div id="disqus_thread"></div><a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>',
44-
link: function(scope) {
44+
link: function (scope) {
4545

4646
// ensure that the disqus_identifier and disqus_url are both set, otherwise we will run in to identifier conflicts when using URLs with "#" in them
4747
// see http://help.disqus.com/customer/portal/articles/662547-why-are-the-same-comments-showing-up-on-multiple-pages-
4848
if (typeof scope.disqus_identifier === 'undefined' || typeof scope.disqus_url === 'undefined') {
4949
throw "Please ensure that the `disqus-identifier` and `disqus-url` attributes are both set.";
5050
}
5151

52-
scope.$watch("readyToBind", function(isReady) {
52+
scope.$watch("readyToBind", function (loadedOn) {
5353

5454
// If the directive has been called without the 'ready-to-bind' attribute, we
55-
// set the default to "true" so that Disqus will be loaded straight away.
56-
if ( !angular.isDefined( isReady ) ) {
57-
isReady = "true";
55+
// set a default value so that Disqus will be loaded straight away.
56+
if (!angular.isDefined(loadedOn)) {
57+
loadedOn = new Date();
5858
}
59-
if (scope.$eval(isReady)) {
60-
console.log('remote'+scope.disqus_remote_auth_s3);
59+
var isReady = typeof scope.$eval(loadedOn) !== 'undefined';
60+
if (isReady) {
6161
// put the config variables into separate global vars so that the Disqus script can see them
6262
$window.disqus_shortname = scope.disqus_shortname;
6363
$window.disqus_identifier = scope.disqus_identifier;
64-
$window.disqus_title = scope.disqus_title;
6564
$window.disqus_url = scope.disqus_url;
65+
$window.disqus_title = scope.disqus_title;
6666
$window.disqus_category_id = scope.disqus_category_id;
6767
$window.disqus_disable_mobile = scope.disqus_disable_mobile;
68-
$window.disqus_config = function () {
68+
$window.disqus_config = function () {
6969
this.language = scope.disqus_config_language;
7070
this.page.remote_auth_s3 = scope.disqus_remote_auth_s3;
7171
this.page.api_key = scope.disqus_api_key;
@@ -88,8 +88,8 @@
8888
this.page.url = scope.disqus_url;
8989
this.page.title = scope.disqus_title;
9090
this.language = scope.disqus_config_language;
91-
this.page.remote_auth_s3=scope.disqus_remote_auth_s3;
92-
this.page.api_key=scope.disqus_api_key;
91+
this.page.remote_auth_s3 = scope.disqus_remote_auth_s3;
92+
this.page.api_key = scope.disqus_api_key;
9393
}
9494
});
9595
}

0 commit comments

Comments
 (0)