Szymon Toda
Szymon Toda

Reputation: 4516

How to share DISQUS on different URLs

I load and display DISQUS snipped, reloading it with ease on AJAX provided pages with

var id = this.getIdentifier(),
        disqus_shortname = 'myportal',
        disqus_identifier = id,
        disqus_title = id,
        disqus_url = "http://" + document.domain + "/#!" + id;

if ($('head script[src="http://' + disqus_shortname + '.disqus.com/embed.js"]').length == 0) {
        (function () {
                var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
                (document.getElementsByTagName('head')[0]).appendChild(dsq);
        })();
}

if (typeof DISQUS != "undefined") {
        DISQUS.reset({
                reload: true
        });
}

Yet trying to load same thread in other url (where are identical) yelds blank (new) disqusion.

Trying to loadsimilar thread on both of them with:

var id = "Disqusion about coding";
DISQUS.reset({
        reload: true,
        config: function () {
                this.page.identifier = id;  
                this.page.url = "http://myportal.com/#!" + id;
        }
});

Gives separate new threat.

Upvotes: 1

Views: 1030

Answers (2)

Szymon Toda
Szymon Toda

Reputation: 4516

I've resolved it by myself with timer - am checking for dsq object and as soon it's found I handle it and stop timer. Code for reference:

//
//
//
this.getIdentifier = function () {
    var identifier = $(sel_product).val() + '-' + $(sel_model).val();

    identifier = identifier.replace(/^\s+|\s+$/g, '').split(' ').join('_');

    return identifier;
};

//
//
//
this.loadDisqus = function () {
    var timerID = 'DisqusComments.loadDisqus';

    if ($(__selector_DisqusBox).length > 0) {
        var id = inst.getIdentifier(),
            disqus_shortname = 'shortnameid',
            disqus_identifier = id,
            disqus_title = id,
            disqus_url = "http://" + document.domain + "/#!" + id;

        Utilities.handleTimedEvent(timerID, callself(this, function () { disqusReset(); }), null, 100);

        if ($('body script[src="http://' + disqus_shortname + '.disqus.com/embed.js"]').length == 0) {
            (function () {
                var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = false;
                dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
                (document.getElementsByTagName('body')[0]).appendChild(dsq);
            })();
        }
    }

    function disqusReset() {
        if (typeof DISQUS != 'undefined') {
            DISQUS.reset({
                reload: true,
                config: function () {
                    this.page.identifier = disqus_identifier;
                    this.page.url = disqus_url;
                    this.page.title = disqus_title;
                }
            });

            Utilities.clearTimedEvent(timerID);
        }
    }

    disqusReset();
};

Upvotes: 0

emran
emran

Reputation: 922

This code seems to work if you leave the URL off completely and use only the identifier. Also, disqus_shortname disqus_identifier and disqus_url should probably be part of the window context. (I cant find this documented anywhere, but I'm finding some strange edge cases in modules)

    var disqus_shortname = 'myportal',
    disqus_identifier = 'UNIQUE_IDENTIFER';

    if ($('head script[src="http://' + disqus_shortname + '.disqus.com/embed.js"]').length == 0) {
            (function () {
                    var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                    dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
                    (document.getElementsByTagName('head')[0]).appendChild(dsq);
            })();
    }

    if (typeof DISQUS != "undefined") {
            DISQUS.reset({
                    reload: true
            });
    }

http://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables

http://help.disqus.com/customer/portal/articles/472095-how-do-i-load-the-same-thread-of-comments-on-multiple-pages-

Upvotes: 1

Related Questions