이런 글이 안개 골목 > 개발이야기 게시판에 어울리는지 모르겠습니다.
안개 골목은 처음인지라 무섭..ㅎㅎ
- 이 글과 관련된 문제의식은 여기( https://www.xetown.com/square/582193 )를 참조!
- 스케치북 게시판 스킨 기준이에요~
- 개인적으로 '새로고침 없는 댓글'과 '대댓글 ajax 호출'을 적용한 상태여서, 일반 스케치북 게시판 스킨에서도 제대로 작동할지는 좀 더 봐야겠구요;;;
1. _comment.html 맨 위에 스크립트 구문을 넣어줌
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | jQuery( function ($){ var target_id = location.hash.replace(/ #comment_/,''), container = '#cmtPosition' ; if (target_id != '' ) { $.cookie( 'target_id' ,target_id); if (target_id != '{$_COOKIE["target_id"]}' ) { setCookieNReload(); } } else { $.cookie( 'target_id' , '' ); '{@ if(isset($_COOKIE["target_id"])) ' +setCookieNReload()+ '; }' ; } function setCookieNReload() { $.ajax({ global: false , cache: false , url: location.href, dataType: 'html' , success: function (data) { var content = $(data), selectedContent = content.find(container).html(); $(container).html(selectedContent); }, complete: function () { if (location.href.indexOf( '#comment_' )!=-1) $(document).scrollTop($(location.hash).offset().top); } }); }; }); |
2. 스크립트 구문이 끝나면 이어지는 곳에 다음과 같이 php 구문의 xe 템플릿 문법을 적용함
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | {@ if (isset( $_COOKIE [ 'target_id' ])): $oModuleModel = getModel( 'module' ); $comment_config = $oModuleModel ->getModulePartConfig( 'comment' , $module_info ->module_srl); $cmt_lst_count = $comment_config ->comment_count; $args = new stdClass(); $args ->document_srl = $oDocument ->document_srl; $cl = executeQuery( 'comment.getCommentList' , $args ); foreach ( $cl ->data as $key => $val ): if ( $val ->comment_srl == $_COOKIE [ 'target_id' ]): $cpage = ceil (( $oDocument ->getCommentcount()- $key )/ $cmt_lst_count ); break ; endif ; endforeach ; endif ; if (Context::get( 'cpage' )) $cpage = Context::get( 'cpage' ); } |
아직 손봐야 할 것이 적지 않은 것 같지만, 대강 이런 식으로 하면 되는 듯합니다.
암튼, 그래도 cpage 자동 감지의 단초를 찾은 거 같아요.
테스트는 여기: http://bit.ly/2pF5a8V
(주소 링크의 파라미터에 cpage는 없지만, 댓글번호를 보고 자동으로 cpage를 감지해서 해당 댓글 페이지로 넘어갈 거예요)
3. 덧붙여, _comment.html을 include하고 있는 _read.html에 다음과 같은 hashchange 이벤트를 붙여주면 더 완벽한 작동이 가능합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ( function ($) { if (location.href.indexOf( '#comment_' )!=-1) { var container = '#cmtPosition' ; $(window).on( 'hashchange' , function (){ $.ajax({ global: false , cache: false , url: location.href, dataType: 'html' , success: function (data) { var content = $(data), selectedContent = content.find(container).html(); $(container).html(selectedContent); } }); }); } })(jQuery); |