comments_server = 'http://arduino.cc/tools'; $(document).ready (function () { if ($('#commentsbox').length == 0) return; $('head').append (''); $('head').append (''); $.ajax ({ url: comments_server + '/comments/extern/fetch/', data: { url: encodeURIComponent (window.location) }, dataType: 'jsonp', success: function (data) { if (typeof data === 'undefined') return; var full = $('
'); if ($('input[name=comment_box_title]').length != 0) title = $('

' + $('input[name=comment_box_title]').val () + '

'); else title = $('

COMMENTS

'); full.append (title); formatTree (full, data.comments); if (cookieExists('arduino_sso_authorized')) { newpost = writeCommentBox (false); addSubs (full).append (newpost); } else { notify = $('
You must be logged in to post a comment.
'); full.append (notify); } $('#commentsbox').after (full); } }); try { $('.reportcomment').live ('click', function () { return raiseReport ($(this)); }); $('.replycomment').live ('click', function () { return onReplyStart ($(this)); }); } catch (err) { $('body').delegate ('.reportcomment', 'click', function () { return raiseReport ($(this)); }); $('body').delegate ('.replycomment', 'click', function () { return onReplyStart ($(this)); }); } }); function raiseReport (a) { id = $(a).parent ().parent ().parent ().attr ('id'); doReportDialog (id); return false; } function onReplyStart (a) { $(a).parent ().parent ().parent ().find ('.subcomments:first').prepend (writeCommentBox (true)); return false; } function addSubs (parent) { var box = $('
'); parent.append (box); return box; } function formatTree (parent, comments) { var box = addSubs (parent); if (comments.length == 0) return; for (var i = 0; i < comments.length; i++) { var d = comments [i]; var p = formatComment (d); box.append (p); formatTree (p, d.comments); } } function formatComment (data) { var d = new Date (data.timestamp * 1000); if (cookieExists('arduino_sso_authorized')) options = '

Reply | Report

'; else options = '

 

'; return $('
\ \
\

\ \

\

' + data.author.username + ' ' + d.toLocaleDateString () + '

' + options + '
\

' + data.body + '

\
\
'); } function doReportDialog (id) { rep = $('
\ \

Please alert us about unattended contents!

\

Attach a comment to your report:

\

\
'); $('#externalcomments').append (rep); rep.dialog ({ autoOpen: false, modal: true, buttons: { "Send!": function() { $.ajax ({ url: comments_server + '/comments/extern/post_report', data: { body: $('#reportcommentdialog').find ('textarea').val (), url: encodeURIComponent (window.location), id: $('#reportcommentdialog').find ('input[name=commentid]').val () }, dataType: 'jsonp', success: function (data) { /* dummy */ } }); alert ('Thanks for your feedback!'); $(this).dialog ('close'); }, "Cancel": function() { $(this).dialog ('close'); } }, close: function() { $('#reportcommentdialog').find ('textarea').val (''); } }); $('#reportcommentdialog').dialog ('open'); } function writeCommentBox (cancellable) { var newpost = $('
'); newpost.append ('

Leave a message...

'); newpost.append ('

'); var buttons = $('
'); newpost.append (buttons); var submitbutton = $(''); submitbutton.click (function () { commentbox = $(this).parent ().parent (); submitbutton.attr ('disabled', 'disabled'); $.ajax ({ url: comments_server + '/comments/extern/post_comment', data: { body: commentbox.find ('textarea').val (), url: encodeURIComponent (window.location), parentid: $(this).parent ().parent ().parent ().parent ().attr ('id') }, dataType: 'jsonp', success: function (data) { var c = formatComment (data); addSubs (c); commentbox.parent ().append (c); commentbox.remove (); c.effect ("pulsate", { times: 3 }, 800); } }); }); buttons.append (submitbutton); if (cancellable == true) { var cancelbutton = $(''); cancelbutton.click (function () { $(this).parent ().parent ().remove (); }); buttons.append (cancelbutton); } return newpost; }