현재 eb_threads 게시판 스킨에 활용된 추천하기 코드이다.
list.blade.php
@if($document->getMyVote())
<a href="javascript:;" onclick="do_doc_VoteSubmit('document','procDocumentVoteUpCancel','{$document->document_srl}'); return false;"><i class="like-fill"></i> <span class="cnt">{$document->get('voted_count') ? $document->get('voted_count') : ''}</span></a>
@else
<a href="javascript:;" onclick="do_doc_VoteSubmit('document','procDocumentVoteUp','{$document->document_srl}'); return false;"><i class="like"></i> <span class="cnt">{$document->get('voted_count') ? $document->get('voted_count') : ''}</span></a>
@endif
내가 한 추천이 있는 경우 좋아요 취소를, 추천한 이력이 없으면 추천하기 버튼이 뜬다.
script.js
function do_doc_VoteSubmit(module, action, target_srl) {
saveScrollPosition(); // 스크롤 위치 저장
shouldRestoreScroll = true; // 스크롤 복원을 활성화
const params = { target_srl: target_srl, cur_mid: current_mid };
// Ajax 요청
exec_json(
module + '.' + action,
params,
function () {
location.reload(); // 페이지 리로드
},
function (response) {
console.log(response);
console.log(window.location.pathname);
if(response.error=='-1'){
// 자신의 게시물에는 추천을 할 수 없습니다.
// const mid = window.location.pathname;
// window.location.href = mid + '/login';
// return false;
}
if(response.error=='-2'){
// const mid = window.location.pathname;
const mid = window.location.pathname.replace(/^\/(.*)\/$/, '/$1');
console.log(mid);
// window.location.href = mid + '/login';
window.location.href = mid + '/?act=dispMemberLoginForm';
return false;
}
}
);
}