1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-01 14:05:07 +03:00

fix комментариев

This commit is contained in:
Mzhelskiy Maxim 2011-08-15 08:51:37 +00:00
parent f8038179ed
commit f3847bbd2e
2 changed files with 88 additions and 44 deletions

View file

@ -32,6 +32,8 @@ ls.comments = (function ($) {
}; };
this.iCurrentShowFormComment=0; this.iCurrentShowFormComment=0;
this.iCurrentViewComment=null;
this.aCommentNew=[];
// Добавляет комментарий // Добавляет комментарий
this.add = function(formObj, targetId, targetType) { this.add = function(formObj, targetId, targetType) {
@ -67,7 +69,7 @@ ls.comments = (function ($) {
// Активирует форму // Активирует форму
this.enableFormComment = function() { this.enableFormComment = function() {
$('#form_comment_text').removeClass(this.options.classes.form_loader).attr('readonly',false); $('#form_comment_text').removeClass(this.options.classes.form_loader).attr('readonly',false);
}, }
// Показывает/скрывает форму комментирования // Показывает/скрывает форму комментирования
@ -84,12 +86,13 @@ ls.comments = (function ($) {
$('#form_comment_text').val(''); $('#form_comment_text').val('');
if (!bNoFocus) $('#form_comment_text').focus(); if (!bNoFocus) $('#form_comment_text').focus();
$('#form_comment_reply').val(idComment); $('#form_comment_reply').val(idComment);
$("#reply_"+idComment).css('display','block'); $('.reply').hide();
$('#reply_'+idComment).css('display','block');
this.iCurrentShowFormComment=idComment; this.iCurrentShowFormComment=idComment;
if (this.options.wysiwyg) { if (this.options.wysiwyg) {
tinyMCE.execCommand('mceAddControl',true,'form_comment_text'); tinyMCE.execCommand('mceAddControl',true,'form_comment_text');
} }
}, }
// Подгружает новые комментарии // Подгружает новые комментарии
@ -128,22 +131,33 @@ ls.comments = (function ($) {
ls.blocks.load($('#block_stream_item_comment'), 'block_stream'); ls.blocks.load($('#block_stream_item_comment'), 'block_stream');
} }
} }
var iCountOld=0;
if (bNotFlushNew) {
iCountOld=this.aCommentNew.length;
} else {
this.aCommentNew=[];
}
if (selfIdComment) { if (selfIdComment) {
this.toggleCommentForm(0, true); this.toggleCommentForm(0, true);
this.setCountNewComment(aCmt.length-1+iCountOld);
} else { } else {
this.setCountNewComment(aCmt.length); this.setCountNewComment(aCmt.length+iCountOld);
} }
$.each(aCmt, function(index, item) { $.each(aCmt, function(index, item) {
if (!(selfIdComment && selfIdComment==item.id)) {
this.aCommentNew.push(item.id);
}
this.inject(item.idParent, item.id, item.html); this.inject(item.idParent, item.id, item.html);
}.bind(this)); }.bind(this));
if (selfIdComment && $('#comment_id_'+selfIdComment).length) { if (selfIdComment && $('#comment_id_'+selfIdComment).length) {
this.scrollToComment(selfIdComment); this.scrollToComment(selfIdComment);
} }
//this.checkFolding();
} }
}.bind(this)); }.bind(this));
}, }
// Вставка комментария // Вставка комментария
@ -154,7 +168,7 @@ ls.comments = (function ($) {
} else { } else {
$('#comments').append(newComment); $('#comments').append(newComment);
} }
}, }
// Удалить/восстановить комментарий // Удалить/восстановить комментарий
@ -175,7 +189,7 @@ ls.comments = (function ($) {
$(obj).text(result.sTextToggle); $(obj).text(result.sTextToggle);
} }
}.bind(this)); }.bind(this));
}, }
// Предпросмотр комментария // Предпросмотр комментария
@ -186,7 +200,7 @@ ls.comments = (function ($) {
if ($("#form_comment_text").val() == '') return; if ($("#form_comment_text").val() == '') return;
$("#comment_preview_"+this.iCurrentShowFormComment).css('display', 'block'); $("#comment_preview_"+this.iCurrentShowFormComment).css('display', 'block');
ls.tools.textPreview('form_comment_text', false, 'comment_preview_'+this.iCurrentShowFormComment); ls.tools.textPreview('form_comment_text', false, 'comment_preview_'+this.iCurrentShowFormComment);
}, }
// Устанавливает число новых комментариев // Устанавливает число новых комментариев
@ -196,33 +210,41 @@ ls.comments = (function ($) {
} else { } else {
$('#new_comments_counter').text(0).hide(); $('#new_comments_counter').text(0).hide();
} }
}, }
// Вычисляет кол-во новых комментариев // Вычисляет кол-во новых комментариев
this.calcNewComments = function() { this.calcNewComments = function() {
this.setCountNewComment($('.'+this.options.classes.comment+'.'+this.options.classes.comment_new).length); var aCommentsNew = $('.'+this.options.classes.comment+'.'+this.options.classes.comment_new);
}, this.setCountNewComment(aCommentsNew.length);
$.each(aCommentsNew,function(k,v){
this.aCommentNew.push(parseInt($(v).attr('id').replace('comment_id_','')));
}.bind(this));
}
// Переход к следующему комментарию // Переход к следующему комментарию
this.goToNextComment = function() { this.goToNextComment = function() {
var aCommentsNew = $('.'+this.options.classes.comment+'.'+this.options.classes.comment_new); if (this.aCommentNew[0]) {
if ($('#comment_id_'+this.aCommentNew[0]).length) {
$.scrollTo($(aCommentsNew[0]), 1000, {offset: -250}); this.scrollToComment(this.aCommentNew[0]);
$('[id^=comment_id_]').removeClass(this.options.classes.comment_current); }
$(aCommentsNew[0]).removeClass(this.options.classes.comment_new).addClass(this.options.classes.comment_current); this.aCommentNew.shift();
}
this.setCountNewComment(aCommentsNew.length - 1); this.setCountNewComment(this.aCommentNew.length);
}, }
// Прокрутка к комментарию // Прокрутка к комментарию
this.scrollToComment = function(idComment) { this.scrollToComment = function(idComment) {
$.scrollTo('#comment_id_'+idComment, 1000, {offset: -250}); $.scrollTo('#comment_id_'+idComment, 1000, {offset: -250});
$('[id^=comment_id_]').removeClass(this.options.classes.comment_current);
if (this.iCurrentViewComment) {
$('#comment_id_'+this.iCurrentViewComment).removeClass(this.options.classes.comment_current);
}
$('#comment_id_'+idComment).addClass(this.options.classes.comment_current); $('#comment_id_'+idComment).addClass(this.options.classes.comment_current);
}, this.iCurrentViewComment=idComment;
}
// Прокрутка к родительскому комментарию // Прокрутка к родительскому комментарию
@ -239,6 +261,7 @@ ls.comments = (function ($) {
return false; return false;
} }
// Сворачивание комментариев // Сворачивание комментариев
this.checkFolding = function() { this.checkFolding = function() {
$(".folding").each(function(index, element){ $(".folding").each(function(index, element){
@ -274,6 +297,7 @@ ls.comments = (function ($) {
this.init = function() { this.init = function() {
this.initEvent(); this.initEvent();
this.calcNewComments(); this.calcNewComments();
//this.checkFolding();
if (typeof(this.options.wysiwyg)!='number') { if (typeof(this.options.wysiwyg)!='number') {
this.options.wysiwyg = Boolean(BLOG_USE_TINYMCE && tinyMCE); this.options.wysiwyg = Boolean(BLOG_USE_TINYMCE && tinyMCE);

View file

@ -32,6 +32,8 @@ ls.comments = (function ($) {
}; };
this.iCurrentShowFormComment=0; this.iCurrentShowFormComment=0;
this.iCurrentViewComment=null;
this.aCommentNew=[];
// Добавляет комментарий // Добавляет комментарий
this.add = function(formObj, targetId, targetType) { this.add = function(formObj, targetId, targetType) {
@ -67,7 +69,7 @@ ls.comments = (function ($) {
// Активирует форму // Активирует форму
this.enableFormComment = function() { this.enableFormComment = function() {
$('#form_comment_text').removeClass(this.options.classes.form_loader).attr('readonly',false); $('#form_comment_text').removeClass(this.options.classes.form_loader).attr('readonly',false);
}, }
// Показывает/скрывает форму комментирования // Показывает/скрывает форму комментирования
@ -90,7 +92,7 @@ ls.comments = (function ($) {
if (this.options.wysiwyg) { if (this.options.wysiwyg) {
tinyMCE.execCommand('mceAddControl',true,'form_comment_text'); tinyMCE.execCommand('mceAddControl',true,'form_comment_text');
} }
}, }
// Подгружает новые комментарии // Подгружает новые комментарии
@ -129,13 +131,23 @@ ls.comments = (function ($) {
ls.blocks.load($('#block_stream_item_comment'), 'block_stream'); ls.blocks.load($('#block_stream_item_comment'), 'block_stream');
} }
} }
var iCountOld=0;
if (bNotFlushNew) {
iCountOld=this.aCommentNew.length;
} else {
this.aCommentNew=[];
}
if (selfIdComment) { if (selfIdComment) {
this.toggleCommentForm(0, true); this.toggleCommentForm(0, true);
this.setCountNewComment(aCmt.length-1+iCountOld);
} else { } else {
this.setCountNewComment(aCmt.length); this.setCountNewComment(aCmt.length+iCountOld);
} }
$.each(aCmt, function(index, item) { $.each(aCmt, function(index, item) {
if (!(selfIdComment && selfIdComment==item.id)) {
this.aCommentNew.push(item.id);
}
this.inject(item.idParent, item.id, item.html); this.inject(item.idParent, item.id, item.html);
}.bind(this)); }.bind(this));
@ -145,7 +157,7 @@ ls.comments = (function ($) {
this.checkFolding(); this.checkFolding();
} }
}.bind(this)); }.bind(this));
}, }
// Вставка комментария // Вставка комментария
@ -156,7 +168,7 @@ ls.comments = (function ($) {
} else { } else {
$('#comments').append(newComment); $('#comments').append(newComment);
} }
}, }
// Удалить/восстановить комментарий // Удалить/восстановить комментарий
@ -177,7 +189,7 @@ ls.comments = (function ($) {
$(obj).text(result.sTextToggle); $(obj).text(result.sTextToggle);
} }
}.bind(this)); }.bind(this));
}, }
// Предпросмотр комментария // Предпросмотр комментария
@ -188,7 +200,7 @@ ls.comments = (function ($) {
if ($("#form_comment_text").val() == '') return; if ($("#form_comment_text").val() == '') return;
$("#comment_preview_"+this.iCurrentShowFormComment).css('display', 'block'); $("#comment_preview_"+this.iCurrentShowFormComment).css('display', 'block');
ls.tools.textPreview('form_comment_text', false, 'comment_preview_'+this.iCurrentShowFormComment); ls.tools.textPreview('form_comment_text', false, 'comment_preview_'+this.iCurrentShowFormComment);
}, }
// Устанавливает число новых комментариев // Устанавливает число новых комментариев
@ -198,33 +210,41 @@ ls.comments = (function ($) {
} else { } else {
$('#new_comments_counter').text(0).hide(); $('#new_comments_counter').text(0).hide();
} }
}, }
// Вычисляет кол-во новых комментариев // Вычисляет кол-во новых комментариев
this.calcNewComments = function() { this.calcNewComments = function() {
this.setCountNewComment($('.'+this.options.classes.comment+'.'+this.options.classes.comment_new).length); var aCommentsNew = $('.'+this.options.classes.comment+'.'+this.options.classes.comment_new);
}, this.setCountNewComment(aCommentsNew.length);
$.each(aCommentsNew,function(k,v){
this.aCommentNew.push(parseInt($(v).attr('id').replace('comment_id_','')));
}.bind(this));
}
// Переход к следующему комментарию // Переход к следующему комментарию
this.goToNextComment = function() { this.goToNextComment = function() {
var aCommentsNew = $('.'+this.options.classes.comment+'.'+this.options.classes.comment_new); if (this.aCommentNew[0]) {
if ($('#comment_id_'+this.aCommentNew[0]).length) {
$.scrollTo($(aCommentsNew[0]), 1000, {offset: -250}); this.scrollToComment(this.aCommentNew[0]);
$('[id^=comment_id_]').removeClass(this.options.classes.comment_current); }
$(aCommentsNew[0]).removeClass(this.options.classes.comment_new).addClass(this.options.classes.comment_current); this.aCommentNew.shift();
}
this.setCountNewComment(aCommentsNew.length - 1); this.setCountNewComment(this.aCommentNew.length);
}, }
// Прокрутка к комментарию // Прокрутка к комментарию
this.scrollToComment = function(idComment) { this.scrollToComment = function(idComment) {
$.scrollTo('#comment_id_'+idComment, 1000, {offset: -250}); $.scrollTo('#comment_id_'+idComment, 1000, {offset: -250});
$('[id^=comment_id_]').removeClass(this.options.classes.comment_current);
if (this.iCurrentViewComment) {
$('#comment_id_'+this.iCurrentViewComment).removeClass(this.options.classes.comment_current);
}
$('#comment_id_'+idComment).addClass(this.options.classes.comment_current); $('#comment_id_'+idComment).addClass(this.options.classes.comment_current);
}, this.iCurrentViewComment=idComment;
}
// Прокрутка к родительскому комментарию // Прокрутка к родительскому комментарию
@ -239,7 +259,7 @@ ls.comments = (function ($) {
}); });
this.scrollToComment(pid); this.scrollToComment(pid);
return false; return false;
}, }
// Сворачивание комментариев // Сворачивание комментариев