Skip to content

Instantly share code, notes, and snippets.

View valueof's full-sized avatar
👋

Anton valueof

👋
View GitHub Profile
@valueof
valueof / gist:404220
Created May 17, 2010 20:59
This function hides Disqus if thread is closed and no comments were posted.
/*
* This function hides Disqus if thread is closed and no comments were posted.
* It is better to place this function in HEAD.
*
* IMPORTANT: Please note, that this example uses internal APIs that might change in future.
* We will not provide any prior announcement before changing or removing any internal APIs.
*/
var disqus_callback = function () {
if (DISQUS.jsonData.thread.closed && DISQUS.jsonData.thread.total_posts === 0) {
def to_unicode(f):
if isinstance(f, dict):
for k, v in f.iteritems():
f[str(k)] = to_unicode(v)
elif isinstance(f, (list, tuple)):
f = [to_unicode(f) for f in f]
elif isinstance(f, str):
f = f.decode('utf-8')
else:
f = unicode(f)
@valueof
valueof / comments-count-sample.html
Created July 8, 2010 08:37
Comments count code example
<html>
<head>
<title>Comments count code example</title>
<!--
Note: Disqus uses custom data- attributes to specify thread identifiers.
Those attributes are part of the HTML5 specs and already supported by all browsers.
For more information, see:
* http://ejohn.org/blog/html-5-data-attributes/
@valueof
valueof / disqus_events.js
Created July 12, 2010 18:24
Description and examples for Disqus events
var disqus_config = function () {
var config = this; // Access to the config object
/*
All currently supported events:
* preData — fires just before we request for initial data
* preInit - fires after we get initial data but before we load any dependencies
* onInit - fires when all dependencies are resolved but before dtpl template is rendered
* afterRender - fires when template is rendered but before we show it
* onReady - everything is done
You will need to locate a block with name "postbox_login_options_horizontal".
There, you will see that we create an unordered list (UL) with login buttons as
its items.
You will want to put your buttons just after the FOR loop (i.e. immediately
after the closing { /for }). Just make sure that your LI tag has class
"dsq-login-button".
<ul class="dsq-login-buttons">
{ for option in loginOptions }
{ block commentMessage :cls }
<div class="{= cls }" id="dsq-comment-message-{= comment.id }">
{ if comment.killed }
<em>{ "Comment removed." }</em>
{ elif !comment.approved }
<em>{ "This comment was flagged for review." }</em>
{ else }
{= comment.message }
{ if comment.last_modified_by == 'moderator' }
{ block editArea }
<div class="dsq-textarea-wrapper">
<textarea class="dsq-edit-textarea" id="dsq-edit-textarea-{= comment.id }">{= comment.message }</textarea>
</div>
<div class="dsq-save-edit">
<button type="button"
onclick="DISQUS.dtpl.actions.fire('comments.edit.send', {= comment.id }, this);">{ "Save edit" }</button>
</div>
function outer() {
var a = true;
function inner() {
// Does compiler keep a reference to outer for this function?
}
}
outer();
<!DOCTYPE html>
<html lang="en">
<head>
<title>DISQUS JavaScript Tests</title>
<!-- Hiro files -->
<link rel="stylesheet" href="css/tests/hiro.css">
<script src="js/tests/ender.js"></script>
<script src="js/tests/hiro.js"></script>
@valueof
valueof / gist:1201958
Created September 7, 2011 22:14
Internet Explorer 8 doesn't have querySelector inside of an iframe
<iframe id="hey"></iframe>
<script>
var hey = document.getElementById("hey");
alert(document.querySelector);
hey.contentWindow.document.write('<html><scr' + 'ipt>alert(document.querySelector);</scr' + 'ipt></html>');
hey.contentWindow.document.close();
</script>