Javascript callback for when the user hits 'Post As'?

111 views
Skip to first unread message

William Denniss

unread,
May 19, 2011, 8:05:08 AM5/19/11
to Disqus Developers
Hi All,

The 'disqus_callback()' is great for customising Disqus after is has
loaded.

However, the dialog that appears when the user hits 'Post As' is not
in the DOM, and (AFAIK, correct me if I'm wrong) can't be modified
yet.

Is there a callback that is fired when the user hits "Post As", after
the resulting dialog loads? Or is there any way I can tweak the
elements in this dialog in the 'disqus_callback'?

Is there anywhere that these things are documented? The official
Disqus docs ( http://docs.disqus.com/developers/js/ ) on JavaScript
are pretty lite, I couldn't even find the documentation for that
'disqus_callback' hook.


Here's my situation: My budget won't stretch to afford the SSO
upgrade to Disqus, and yet I have authenticated users in my system.
This creates the silly situation where they have to enter information
that I already have just to comment. In fact this is a bit of a deal-
breaker for me, so I'm basically going to try and address this, or try
to find a new commenting system. My idea is as follows: when the
disqus 'Post As' dialog appears, I inspect the Name/Email/Website
elements. If they are populated, I leave them as is. If however they
are blank/default, then I pre-populate them with data from my system
about the user in question. The user can then edit these if needed.

I can use Firebug to inspect the elements of this form, and I notice
that Disqus has given them good names, ones I am assuming won't be
changing too frequently (e.g. dsq-field-email).

So any ideas on where I can hook my javascript to play with them?


Kind Regards,

Will

William Denniss

unread,
May 24, 2011, 12:17:03 AM5/24/11
to Disqus Developers
I guess (from the silence) that there is no official way to supply
"default guest data" to Disqus, in the event that we know the current
users details already.


I came up with two slightly hacky solutions to this problem.

#1 add a click listener to "Post As"
$("#dsq-post-button").click(disqus_postas_callback);
- May need to add a small delay so it has loaded, then you can fill in
your defaults

#2 (not supported on all browsers, read: IE) Listen for the
DOMNodeInserted event, and then check the dom to see if the elements
exist, then do what you like.

Hope this helps someone.

Cheers,
Will


Ben Vinegar

unread,
May 24, 2011, 12:36:13 AM5/24/11
to disqu...@googlegroups.com
Hi William,

There are two global configuration variables you can use to populate default name and email:

var disqus_def_name = 'John Doe';
var disqus_def_email = 'joh...@example.com';

A lot of these configuration variables are undocumented, and technically, not officially supported. We're working on developing a proper JS API that will better define these things.

Hope this helps. Again, sorry for the late reply.

--
Ben Vinegar
Software Engineer, DISQUS

William Denniss

unread,
May 24, 2011, 1:02:27 AM5/24/11
to disqu...@googlegroups.com
Hi Ben,

Thanks for the reply! This is exactly what I was looking for.  In hindsight my original email was poorly worded, I had already jumped ahead 5 steps trying to solve the problem in javascript and didn't actually ask if what I needed was already in Disqus - which it is!

Is there one for the website field as well?  I took a stab with 'var disqus_def_website' but it didn't seem to work.  If there isn't such an option, then please +1 my support for adding one :)

Can't wait to see your new JS API docs when it's ready too :)

Thanks for your help.

Cheers,
Will

Ben Vinegar

unread,
May 24, 2011, 1:07:09 AM5/24/11
to disqu...@googlegroups.com
Hi William,

We don't have one for website, I'm afraid. It would probably be trivial to add, but like I said, we're going to deprecate these config variables sometime in the future, so we're hesitant to add new ones. Hopefully email and username will suffice.

Cheers,

--
Ben Vinegar
Software Engineer, DISQUS
Reply all
Reply to author
Forward
0 new messages