For grabbing PDFs from ICRA 2022
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. var loading = false;
  2. $(document).ready(function () {
  3. // make alert button fixed and hide it after a few seconds
  4. $(".alert.msg").addClass("fixed-alert");
  5. setTimeout(function(){ $(".alert.msg").remove(); }, 5000);
  6. // on show replies link click
  7. $(".show-replies").click(function(e){
  8. e.preventDefault();
  9. // check if data is not still loading
  10. if(loading == true) { return false; }
  11. // store self into a var to give it access inside the post
  12. var self = $(this);
  13. // set loading to true and get data from html element attributres
  14. loading = true;
  15. data = $(this).data();
  16. // make an ajax request to get comment replies
  17. $.post("/ajax.php?action=commentReplies&commentId=" + castAsInteger(data.commentid), {})
  18. // data retrieved. try and build the html
  19. .done(function (payload) {
  20. if(payload.error === true) {
  21. // reset loading flag and throw error
  22. loading = false;
  23. throw new Error("Failed to parse ajax payload");
  24. }
  25. // loop data and build replies html
  26. repliesHtml = "";
  27. payload.data.comments.forEach(function(item){
  28. // html data
  29. const commentId = castAsInteger(item.id);
  30. const repliedTo = (item.repliedToUser ? "<a href='/profile?id=" + item.repliedToUserId + "'>@" + item.repliedToUser + "</a> " : "" );
  31. const likeBtnClass = item.hasLiked == 1 ? "class='active'" : "";
  32. const dislikeBtnClass = item.hasDisliked == 1 ? "class='active'" : "";
  33. const profileImg = item.profileImgUrl != false ? `<a href='/profile?id=${item.usersId}' class='comment-profile-image has-image' style='background-image: url(${item.profileImgUrl})'></a>` : `<a href='/profile?id=${item.usersId}' class='comment-profile-image'><i class='fa fa-user' aria-hidden='true'></i></a>`;
  34. //delete form
  35. deleteHtml = "";
  36. if(payload.data.canDelete) {
  37. deleteHtml = `
  38. <form method='post' class='delete-comment' action='#comments'>
  39. <input type='hidden' name='action' value='deleteComment' />
  40. <input type='hidden' name='commentId' value='${commentId}' />
  41. <button type='submit'><i class='fa fa-times' aria-hidden='true'></i></button>
  42. </form>
  43. `;
  44. }
  45. // build replis html (specific to comment type)
  46. repliesHtml += `
  47. <div id='commentRow${commentId}' class='comment-row'>
  48. ${deleteHtml}${profileImg}
  49. <div class='comment-box'>
  50. <p><a href='/profile?id=${item.usersId}'>${item.profileName}</a> &bull; ${item.datePosted}</p>
  51. <p class='user-comment'>
  52. ${repliedTo}
  53. ${item.iv_comment}
  54. </p>
  55. </div>
  56. <div class='score-button-wrapper'>
  57. <div class='score-form like-form'>
  58. <button type='submit' data-object='${data.objectid}' data-type='${item.commentType}' data-commentId='${commentId}' data-like='1' ${likeBtnClass}><i class='fa fa-thumbs-up' aria-hidden='true'></i></button>
  59. <span class='likeCounter'>${item.totalLikes}</span>
  60. </div>
  61. <div class='score-form dislike-form'>
  62. <button type='submit' data-object='${data.objectid}' data-type='${item.commentType}' data-commentId='${commentId}' data-like='0' ${dislikeBtnClass}><i class='fa fa-thumbs-down' aria-hidden='true'></i></button>
  63. <span class='likeCounter'>${item.totalDislikes}</span>
  64. </div>
  65. <a href='#' class='reply reply-button' data-profile='${item.profileName}' data-object='${data.objectid}' data-type='${item.commentType}' data-parent='${item.parentId}' data-author='${item.usersId}' data-reply='${commentId}'>Reply</a>
  66. </div>
  67. </div>
  68. <div id='replyBox${commentId}'></div>
  69. `;
  70. });
  71. // set html and show replies
  72. $('#replies'+ data.commentid).html(repliesHtml);
  73. //check if comment box text is overflowing
  74. limitReplyBoxHeight();
  75. //bind click events
  76. bindReplyButtons();
  77. bindLikesButtons();
  78. // remove link and reset loading
  79. $(self).remove();
  80. loading = false;
  81. })
  82. .fail(function(){
  83. // reset loading flag
  84. loading = false
  85. return false;
  86. })
  87. ;
  88. });
  89. //check if comment box text is overflowing max of 90 height
  90. limitReplyBoxHeight();
  91. //bind click events
  92. bindReplyButtons();
  93. bindLikesButtons();
  94. });
  95. function castAsInteger(number) { return isNaN(parseInt(number)) ? 0 : parseInt(number); }
  96. function limitReplyBoxHeight() {
  97. // check height of comment boxes
  98. $('.comment-box').each(function () {
  99. if ($(this).outerHeight() >= 125) {
  100. $(this).addClass('comment-box-overflow');
  101. }
  102. });
  103. // update box heights
  104. bindHeightHandler();
  105. }
  106. // bind functions
  107. function bindHeightHandler() {
  108. $( ".comment-box-overflow").unbind( "click.show", toggleHeightHandler );
  109. $( ".comment-box-overflow").bind( "click.show", toggleHeightHandler );
  110. }
  111. function bindCancelButtons() {
  112. // bind cancel button
  113. $( ".cancel-reply").unbind( "click.cancel", cancelhandler );
  114. $( ".cancel-reply").bind( "click.cancel", cancelhandler );
  115. }
  116. function bindReplyButtons() {
  117. // bind reply button
  118. $( ".reply-button").unbind( "click.replys", replyhandler );
  119. $( ".reply-button").bind( "click.replys", replyhandler );
  120. }
  121. function bindLikesButtons() {
  122. $(".score-form button").unbind( "click.like", likesHandler );
  123. $(".score-form button").bind( "click.like", likesHandler );
  124. }
  125. function escapeHtml(html){
  126. var text = document.createTextNode(html);
  127. var p = document.createElement('p');
  128. p.appendChild(text);
  129. return p.innerHTML;
  130. }
  131. // bind handlers
  132. var toggleHeightHandler = function() {
  133. $(this).toggleClass("show-overflow");
  134. }
  135. var cancelhandler = function(e) {
  136. // prevent form submit
  137. e.preventDefault();
  138. replyboxId = $(this).data().replybox;
  139. // reset reply box html
  140. $("#replyBox" + replyboxId).html("");
  141. }
  142. var likesHandler = function(e) {
  143. e.preventDefault();
  144. data = $(this).data();
  145. commentId = castAsInteger(data.commentid);
  146. objectId = castAsInteger(data.object);
  147. objectType = castAsInteger(data.type);
  148. liked = castAsInteger(data.like);
  149. if(! (commentId && objectId && objectType )) { return false; }
  150. // make an ajax request to like/dislike a comment
  151. $.post(`/ajax.php?action=likeComment&commentId=${commentId}&objectId=${objectId}&objectType=${objectType}&liked=${liked}`, {})
  152. .done(function(payload){
  153. if(payload.error === true) {
  154. location.reload();
  155. return false;
  156. }
  157. // remove all active classes before proceed
  158. $("#commentRow" + commentId + " button").removeClass("active");
  159. // check which button should be activated
  160. switch(true) {
  161. case payload.data.hasLiked == 1:
  162. $("#commentRow" + commentId + " .like-form button").addClass("active");
  163. break;
  164. case payload.data.hasDisliked == 1:
  165. $("#commentRow" + commentId + " .dislike-form button").addClass("active");
  166. break;
  167. default:
  168. break;
  169. }
  170. // update scores
  171. $("#commentRow" + commentId + " .like-form .likeCounter").html(castAsInteger(payload.data.totalLikes));
  172. $("#commentRow" + commentId + " .dislike-form .likeCounter").html(castAsInteger(payload.data.totalDislikes));
  173. }).fail(function(){ return false; })
  174. ;
  175. }
  176. var replyhandler = function(e) {
  177. e.preventDefault();
  178. data = $(this).data();
  179. // form elements
  180. const subReplyClass = data.reply ? "post-form-subreply" : "";
  181. const dataReplyBox = data.reply ? data.reply : data.parent;
  182. const authorHiddenInput = data.author ? "<input type='hidden' name='authorId' value='" + castAsInteger(data.author) + "'>" : "";
  183. const placeholder = escapeHtml(data.profile);
  184. // build reply box html structure
  185. replyHtml = `
  186. <form method='post' id='postComment' class='post-comment-form post-form-reply ${subReplyClass}' action='#comments'>
  187. <input type='hidden' name='action' value='addComment'>
  188. <input type='hidden' name='commentType' value='${data.type}'>
  189. <input type='hidden' name='parentId' value='${data.parent}'>
  190. <input type='hidden' name='objectId' value='${data.object}'>
  191. ${authorHiddenInput}
  192. <textarea class='form-control' placeholder="Reply to ${placeholder}" name='comment' maxlength='2000'></textarea>
  193. <button type='submit' class='btn btn-success post-comment-btn'>Post</button>
  194. <button class='btn btn-danger cancel-reply' data-replybox='${dataReplyBox}'>Cancel</button>
  195. </form>
  196. `;
  197. // set reply box html
  198. $("#replyBox" + (data.reply ? data.reply : data.parent )).html(replyHtml);
  199. // bind cancel buttons actions
  200. bindCancelButtons();
  201. };