(function($){
$.fn.commentpicker = function (){
return this.each(function(){
var _this = $(this);
var _id = '#'+$(this).attr('id');
var _attr = '-'+$(this).attr('id');
var _pCode = $(this).attr('data-pcode');
var _opt = $(this).attr('data-opt') ? $(this).attr('data-opt') : "";
var _editor = $(this).attr('data-editor') ? $(this).attr('data-editor') : 'N';
var _no = $(this).attr('data-no') ? $(this).attr('data-no') : 0;
var _login = $(this).attr('data-login') ? $(this).attr('data-login') : "";
var _title = $(this).attr('data-title') ? $(this).attr('data-title') : "´ñ±Û";
var _param = '&editor='+_editor+'&opt='+_opt+'&commentTitle='+_title;
if(_opt == 'w'){
$.get( '/run.html',
'&c=bbs&f=getComment&pcode='+_pCode+_param,
function (data){
_this.html(""+_title+"
" + data);
}
);
}
else {
$.get( '/run.html',
'&c=bbs&f=comment_list&pcode='+_pCode+_param,
function (data){
_this.html(""+_title+"
" + data);
}
);
}
$(document).on('click', _id+' .confirm-close-btn', function(){
$(this).parent().remove();
});
$(document).on('click', _id+' .confirm-win-btn', function(){
var __pCode = $(this).attr('data-pcode');
var __no = $(this).attr('data-no');
var __opt = $(this).attr('data-opt');
var __pwd = $(this).prev('.pwd-data').val();
if(__pwd == ''){
alert('ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇϼ¼¿ä');
$(this).prev('.pwd-data').focus();
return;
}
if(__opt == 'delete'){
if(confirm('»èÁ¦ÇϽðڽÀ´Ï±î')){
var __param = '&c=bbs&f=comment_del&pcode='+__pCode+'&no='+__no+'&pwd='+__pwd;
$(this).parent().remove();
$.post( '/run.html',
__param,
function(data){
if(data == "FAILED"){
alert('ºñ¹Ð¹øÈ£¸¦ È®ÀÎÇϼ¼¿ä');
}
else{
$('#comment-list'+_attr).html(data);
}
}
);
}
else {
$(this).parent().remove();
}
}
else if(__opt == "modify"){
openWin('/win.html?c=bbs&f=comment_mod&no='+__no+'&pwd='+__pwd, 'bbs_mod', 'width=900, height=300, scrollbars=yes');
$(this).parent().remove();
}
});
});
}
$(document).on('keyup focusout', '.comment-editor', function(){
$(this).next("textarea").val($(this).html());
});
$(document).on('click', '.comment-save-btn', function(){
var _form = $(this).closest('form');
var _formId = $(this).closest('form').attr('id');;
var _target = _form.parent().attr('data-target');
if(_form.find('[name=wname]').val() == ''){
alert('ÀÛ¼ºÀÚ¸¦ ÀÔ·ÂÇϼ¼¿ä');
_form.find('[name=wname]').focus();
reutrn;
}
if(_form.find('[name=pwd]').val().trim() == ''){
alert('ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇϼ¼¿ä');
_form.find('[name=pwd]').focus();
return;
}
if(_form.find('[name=comment]').val().trim() == ''){
_form.find('[name=comment]').focus();
alert('´ñ±Û ³»¿ëÀ» ÀÔ·ÂÇϼ¼¿ä');
return;
}
_form.find('[name=comment]').val(encodeURIComponent(_form.find('[name=comment]').val()));
$.post( '/run.html',
$('#'+_formId).serialize(),
function (data){
$('#'+_target).html(data);
_form.find('[name=comment]').val('');
_form.find('.comment-editor').html('');
//if(_login == '') $(_id+' #comment-pwd').val('');
//if(_editors[_no]) _editors[_no].setData('');
}
);
});
$(document).on('click', ' .comment-reply-btn', function(){
var _pCode = $(this).attr('data-pcode');
var _formDiv = $(this).parents("div").find("[data-pcode="+_pCode+"]").children("div:first");
var _formClone = _formDiv.clone();
var _pno = $(this).attr('data-pno');
_formClone.find('form').attr('id', 'reply'+_pno);
_formClone.attr('id', 'form-reply'+_pno);
_formClone.find('[name=pno]').val(_pno);
_formClone.find('.comment-title').text('¦¦ ´ä±Û');
$(this).parent().parent().append("