// ////////////////////////////////// // jquery is this cool: // var you; var ids; // more(nl,t) {{{ function more(nl, t) { t.find("div.more").html("reloading..."); $.getJSON("/comments/", { ts: (new Date()).getTime(), mode: 'more', nl: nl }, function(o) { draw(t, nl, o.comments, true, $(t.find("div.carea")).height()); }); } // }}} // send(c,nl,t) {{{ function send(c, nl, t) { var cv = c.val(); t.find("div.more").html(cv.length ? "posting..." : "reloading..."); $.getJSON("/comments/", { ts: (new Date()).getTime(), mode: 'post', c:cv, nl: nl }, function(o) { if( o.e ) alert(o.e); if( o.ids ) ids = o.ids; draw(t, nl, o.comments, true); }); } // }}} // draw(t,nl,ca) {{{ function draw(t, nl, ca, focus, force_height) { t.html(""); if( ca && ca.length ) { t.append('— comments ———'); t.append('
'); var x = $( t.find("div.carea") ); if( force_height ) x.css({height: force_height + "px", overflow: 'auto' }); for(var i=0; i' + '
' + c.comment + ' (' + c.bd + ' ago)
' ); } if( force_height ) x[0].scrollTop = x[0].scrollHeight; /* ** from #jquery!freenode ** ** [22:19] JohnResig!!: jettero: $("#foo")[0].scrollTop = $("#foo")[0].scrollHeight; ** [22:25] jettero: JohnResig wow, thanks ** [22:26] _fil_: JohnResig: you could animate() it :p ** [22:26] _fil_: too easy lol ** [22:26] JohnResig: _fil_: with jQuery 1.2, you can: $("#foo").animate({ scrollTop: $("#foo")[0].scrollHeight }, "slow"); ** [22:26] _fil_: hey :p ** [22:26] jettero: that's too much black magic ** [22:26] JohnResig: if you were to check jQuery out of SVN you could do that anow ** [22:26] JohnResig: *now */ x.find("div.mbtn").click(function(){ more(nl, t); return false; }); } var cid = ""; var selfh = t.find("div.self").html(); if( selfh && selfh.match("incognito") ) cid = "
(change your identity by clicking \"your identity\" under site navagation on the right)
"; t.append('
' + ids + cid + '
'); var c = t.find("input[type=text]"); t.find("input").keypress(function(e) { if( e.keyCode != 13 ) return; send(c, nl, t); }); t.find("input[type=submit]").click(function() { send(c, nl, t); }); if( focus ) t.find("input[type=text]")[0].focus(); } // }}} // scrollta {{{ function scrollta(e) { var y = 0; for(var node = e; node; node=node.offsetParent) y += node.offsetTop; return y; } // }}} // document ready {{{ $(document).ready(function() { $("div.commentstub").each(function() { $(this).html("loading..."); }); // we can find archive_of with $("archive_of").text(); // but we don't need it... $.getJSON("/comments/", { ts: (new Date()).getTime(), mode: 'init' }, function(o) { $("div.commentstub").each(function() { var t = $(this); var nl = t.attr("class").replace(/commentstub /,''); var ca = o.comments[nl]; you = o.you; ids = o.ids; draw(t, nl, ca); // re-jump to named location if neccessary: /* var m = location.href.match("#.*"); if( m ) { var t = $("a[name=" + m[0].replace("#","") + "]"); if( t ) window.scrollTo(0, scrollta(t[0])); } */ }) }); }); // }}}