var busy = false, key, cmtEnds, lastPoint = 0; var msgComments = {"confirm":"\u0412\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439?","posted":"\u0412\u0430\u0448 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d","failed":"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f"}; $(document).ready(function(){ cmtEnds = eval("(" + $('#ends').val() + ")"); for (key in cmtEnds) { cmtEnds[key] = parseInt(cmtEnds[key]); } if ($('#fText0').length) { $('#fText0').keydown(function(e){ if (e.which == 13 && e.ctrlKey) { $('#cmtButton0').click(); } }); } if ($('div[id^="root"]').length) { $('div[id^="root"]:last').addClass('padd_bot1'); } }); function getLastPoint(id) { if (array_key_exists(id, cmtEnds)) { lastPoint = cmtEnds[id]; getLastPoint(lastPoint); } return; } function reqCommentReply(comment) { if (busy) return; busy = true; $('#run').show(); var postData = ['act=commentReply', 'comment=' + comment]; $.ajax({ type: 'post', url: '/ajax/user.comments.ajax.php', data: postData.join('&'), dataType: 'html', success: function(html) { $('#cmtForm' + comment).html(html); $('#fText' + comment).focus(); $('#fText' + comment).keydown(function(e){ if (e.which == 13 && e.ctrlKey) { $('#cmtButton' + comment).click(); } }); $('#run').hide(); busy = false; } }); return; } function reqCommentCancel(comment) { if (busy) return; $('#cmtForm' + comment).empty(); return; } function reqCommentDelete(comment) { if (busy) return; if (confirm(msgComments.confirm)) { busy = true; $('#run').show(); var postData = ['act=commentDelete', 'comment=' + comment]; a = $.ajax({ type: 'post', url: '/ajax/user.comments.ajax.php', data: postData.join('&'), dataType: 'json', success: function(data) { if (data.ok) { $('#cmtText' + comment).html(data.response); } $('#run').hide(); busy = false; } }); } return; } function reqCommentReport(comment, user) { if (busy) return; busy = true; $('#run').show(); var postData = ['act=commentReport', 'comment=' + comment, 'user=' + user]; a = $.ajax({ type: 'post', url: '/ajax/user.comments.ajax.php', data: postData.join('&'), dataType: 'json', success: function(data) { if (data.ok) { $('#lnkReport' + comment).replaceWith(data.response); } $('#run').hide(); busy = false; } }); return; } function reqCommentPost(user, project, parent, page) { var val = encodeURIComponent($('#fText' + parent).val()); if (busy || !val.length) return; busy = true; $('#run').show(); var postData = ['act=commentPost', 'user=' + user, 'project=' + project, 'page=' + page, 'parent=' + parent, 'text=' + val]; $.ajax({ type: 'post', url: '/ajax/user.comments.ajax.php', data: postData.join('&'), dataType: 'json', success: function(data) { $('#run').hide(); busy = false; if (data.ok) { if (user) { $.jGrowl(msgComments.posted, jGrowlOpts.yes); $('#fText' + parent).val(''); if (parent) { $('#cmtForm' + parent).empty(); } reqCommentGet(data.comment, parent); } else { if (data.user) { document.location.href = '/registration/comment/' + data.user + '/'; } else { document.location.href = '/registration/comment/'; } } } else { $.jGrowl(msgComments.failed, jGrowlOpts.not); } } }); return; } function reqCommentGet(comment, parent) { if (busy) return; busy = true; $('#run').show(); var postData = ['act=commentGet', 'comment=' + comment]; $.ajax({ type: 'post', url: '/ajax/user.comments.ajax.php', data: postData.join('&'), dataType: 'html', success: function(html) { if (parent == 0) { if ($('div[id^="root"]').length) { $('div[id^="root"]:last').removeClass('padd_bot1'); $('#root' + cmtEnds[parent]).after(html); $('div[id^="root"]:last').addClass('padd_bot1'); } else { $('#divNoComms').remove(); $('#divCommForm').before(html); $('#divCommForm').addClass('left'); } } else { lastPoint = parent; getLastPoint(parent); $('#cmt' + lastPoint).after(html); } cmtEnds[parent] = comment; document.location.href = '#cmt' + comment; $('#run').hide(); busy = false; } }); return; }