var actionSubject; // id of comment used in action var actionSubjectItemId; // id of commented item var actionSubjectItemClassname; // classname of commented item var actionSubjectParent; // id of replyed comment var actionURL = '/get_comments'; var commentsCurrentPage = -1; var highlightComment = ''; var commentsOrder = 'oldest_first'; var tooltipsApplied = false; var currentCommentText; var reloadComments = function(){ Spinner.show(); $('#contextComments').load(actionURL, {itemId: actionSubjectItemId, itemClassname: actionSubjectItemClassname, page: commentsCurrentPage, sort: commentsOrder }, function(){ if(highlightComment) { $(highlightComment).addClass('highlighted').removeClass('highlighted', 10000); highlightComment = ''; } $('#contextCommentsHolder div.commentHolder').each(function(){ $(this).height($(this).actual('height')); }); Spinner.hide(); }); }; var loadSavedComment = function(id, page) { reloadComments(); } jQuery(function($) { var saveComment = function(data) { $.ajax({ url: '/save_comment', data: data, type: 'post', dataType: 'script' }); }; if(actionURL == '/get_comments') reloadComments(); $('#postComment textarea').textareaCount({ 'maxCharacterSize': 500, 'originalStyle': 'originalDisplayInfo', 'displayFormat': '#left' }); $('#dialog-editComment').dialog({ autoOpen: false, width: 'auto', position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false, open: function(){ $('#dialog-editComment .originalDisplayInfo').remove(); var charSize = 1000; var text = $('#comment_text').val(); if (text.indexOf('[quote]') == -1) { charSize = 500; } $('#comment_text').textareaCount({ 'maxCharacterSize': charSize, 'truncate': false, 'warningNumber': -1, 'originalStyle': 'originalDisplayInfo', 'displayFormat': '#left' }); $('#comment_text').bind('isFull', function(){ $('#dialog-editComment a.ok').button( "disable" ); flushSpinnerMessage(Travvi.s('js.message_too_long_please_shorten')); }).bind('isNotFull', function(){ $('#dialog-editComment a.ok').button( "enable" ); }); } }); $('#dialog-commentConfirmDelete').dialog({ autoOpen: false, width: 'auto', position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false, open: function(){ $(document).keydown(function(e){ if (e.keyCode == 13) { $('#dialog-commentConfirmDelete .ok').triggerHandler('click'); return false; } }); } }); $('#dialog-commentQuotation').dialog({ autoOpen: false, width: 470, position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false, open: function(){ if(!tooltipsApplied) { $('#share42 a').tooltip({showURL: false}); tooltipsApplied = true; } $('a.quotationUrl').zclip({ path:'/skin/js/ZeroClipboard.swf', copy:function(){return $(this).attr('href')}, clickAfter: false, setHandCursor: true, afterCopy: function(){ flushSpinnerMessage(Travvi.s('js.code_copied_in_clipboard')); } }); } }); $('#dialog-externalLink').dialog({ autoOpen: false, width: 'auto', position: ['center', 'center'], height: 'auto', modal: true, resizable: false, draggable: false }); $('#subjectPanel a.close').tooltip({showURL: false, positionLeft: true, left: -5}); $('.readAll a').button(); $('#dialog-editComment a.submit').button(); $('#dialog-externalLink a.submit').button(); $('#dialog-editComment a.submit.cancel').click(function(){ $('#dialog-editComment').dialog('close'); return false; }); $('#dialog-editComment a.submit.delete_message').click(function(){ $('#dialog-editComment').dialog('close'); $('#dialog-commentConfirmDelete').dialog('open'); return false; }); $('#dialog-editComment a.submit.ok').click(function(){ $('#dialog-editComment').dialog('close'); saveComment({ id: actionSubject, parentId: actionSubjectParent, itemId: actionSubjectItemId, itemClassname: actionSubjectItemClassname, text: $('#dialog-editComment textarea').val() }); currentCommentText = $('#dialog-editComment textarea').val(); return false; }); $('#dialog-commentConfirmDelete a.submit').button(); $('#dialog-commentConfirmDelete a.submit.cancel').click(function(){ $('#dialog-commentConfirmDelete').dialog('close'); return false; }); $('#dialog-commentConfirmDelete a.submit.ok').click(function(){ $.ajax({ url: '/delete_comment', data: { id: actionSubject, itemId: actionSubjectItemId, itemClassname: actionSubjectItemClassname }, type: 'post', dataType: 'script' }); $('#dialog-commentConfirmDelete').dialog('close'); return false; }); $('div.comment a.edit').live('click', function(){ actionSubject = $(this).data('id'); actionSubjectParent = 'none'; $('#comment_text').val($(this).closest('div.comment').find('div.text').html() .replace(/
(.*?)<\/div>/, '[+]$1[/+]') .replace(/
(.*?)<\/div>/, '[-]$1[/-]') .replace(//mg,"\n") .replace('', '[quote]') .replace('', '[/quote]') .replace(/(<([^>]+)>)/ig,"") ); $('#dialog-editComment').dialog('option', 'title', Travvi.s('js.edit_message')).dialog('open'); if($('#bottom_right span.comments_count').text() == '0') $('#bottom_right span.comments_count').text('1'); return false; }); $('div.editHolder a').click(function(){ actionSubject = $(this).data('id'); actionSubjectParent = 'none'; $('#comment_text').val(''); $('#dialog-editComment').dialog('option', 'title', Travvi.s('js.add_description')).dialog('open'); return false; }); $('div.comment a.reply').live('click', function(){ actionSubject = 'new'; actionSubjectParent = $(this).data('parent_id'); var name = $(this).closest('div.comment').find('div.name a').first().text(); var date = $(this).closest('div.comment').find('div.date').text(); $('#comment_text').val(''); $('#dialog-editComment').dialog('option', 'title', Travvi.s('js.reply_to_message') + ' ' + name + ' ' + Travvi.s('js.reply_date_from') + ' ' + date).dialog('open'); return false; }); $('div.comment a.replyWithQuote').live('click', function(){ actionSubject = 'new'; actionSubjectParent = $(this).data('parent_id'); var name = $(this).closest('div.comment').find('div.name a').first().text(); var date = $(this).closest('div.comment').find('div.date').text(); $('#comment_text').val('[quote]' + $(this).closest('div.comment').find('div.text').html() .replace(/
(.*?)<\/div>/, '[+]$1[/+]') .replace(/
(.*?)<\/div>/, '[-]$1[/-]') .replace(//mg,"\n") .replace(/(<([^>]+)>)/ig,"") + '[/quote]' ); $('#dialog-editComment').dialog('option', 'title', Travvi.s('js.reply_to_message') + ' ' + name + ' ' + Travvi.s('js.reply_date_from') + ' ' + date).dialog('open'); return false; }); $('div.comment a.delete').live('click', function(){ actionSubject = $(this).data('id'); $('#dialog-commentConfirmDelete').dialog('open'); return false; }); $('#postComment textarea').bind('click focus', function(){ $(this).addClass('active'); return false; }).bind('blur', function(){ $(this).removeClass('active'); return false; }); $('#postComment div.nouser textarea').unbind('click focus').bind('click focus', function(){ $('#dialog-loginForm').dialog('open'); return false; }); $('#postComment a').mousedown(function(){ Spinner.show(); $('#postComment textarea').addClass('active'); var text = $.trim($('#postComment textarea').val()); if (text.length < 3) { flushSpinnerMessage(Travvi.s('js.message_too_short')); Spinner.hide(); return false; } saveComment({id: 'new', itemId: actionSubjectItemId, itemClassname: actionSubjectItemClassname, text: text, sort: commentsOrder}); $('#postComment textarea').val(''); $('#postComment textarea').removeClass('active'); return false; Spinner.hide(); }).click(function(){ return false; }); // filter comment external links $('div.comment div.text a').live('click', function(){ var comp = new RegExp(location.host); if(!comp.test($(this).attr('href'))){ $('#dialog-externalLink a.ok').attr('href', $(this).attr('href')); $('#dialog-externalLink').dialog('open'); return false; } }); $('#dialog-externalLink a.cancel').click(function(){ $('#dialog-externalLink').dialog('close'); return false; }) });