diff --git a/wire/modules/Fieldtype/FieldtypeComments/Comment.php b/wire/modules/Fieldtype/FieldtypeComments/Comment.php index e5c4fae3..ddb556a5 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/Comment.php +++ b/wire/modules/Fieldtype/FieldtypeComments/Comment.php @@ -34,6 +34,7 @@ * @property-read int $depth Current comment depth (since 3.0.149) * @property-read bool $loaded True when comment is fully loaded from DB (since 3.0.149) * @property-read int $numChildren Number of children with no exclusions. See and use numChildren() method for more options. (since 3.0.154) + * @property-read User $createdUser User that created the comment * */ diff --git a/wire/modules/Fieldtype/FieldtypeComments/CommentFormCustom.php b/wire/modules/Fieldtype/FieldtypeComments/CommentFormCustom.php index 1b642682..70ce8646 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/CommentFormCustom.php +++ b/wire/modules/Fieldtype/FieldtypeComments/CommentFormCustom.php @@ -111,20 +111,20 @@ class CommentFormCustom extends CommentForm {
{endif.notify} diff --git a/wire/modules/Fieldtype/FieldtypeComments/comments.js b/wire/modules/Fieldtype/FieldtypeComments/comments.js index 75a075df..4c7b8eb4 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/comments.js +++ b/wire/modules/Fieldtype/FieldtypeComments/comments.js @@ -129,23 +129,28 @@ function CommentActionReplyClick() { // clone the main CommentForm $form = jQuery('#CommentForm form').clone().removeAttr('id'); $form.addClass('CommentForm' + commentID); - $form.hide().find('.CommentFormParent').val($(this).attr('data-comment-id')); - var $formPlaceholder = $item.find('form:eq(0)'); + $form.hide().find('.CommentFormParent').val(commentID); + var $formPlaceholder = $item.find('form:not(.CommentFormReply):eq(0)'); if($formPlaceholder.length) { // use existing placed in there as optional target for reply form $formPlaceholder.replaceWith($form); } else { $this.parent().after($form); } + $form.addClass('CommentFormReply'); if($form.is('form[hidden]')) { $form.removeAttr('hidden'); } else if(!$form.is(':visible')) { $form.slideDown(); } + $form.trigger('CommentFormReplyAdd'); + $form.trigger('CommentFormReplyShow'); } else if(!$form.is(':visible')) { $form.slideDown(); + $form.trigger('CommentFormReplyShow'); } else { $form.slideUp(); + $form.trigger('CommentFormReplyHide'); } return false; diff --git a/wire/modules/Fieldtype/FieldtypeComments/comments.min.js b/wire/modules/Fieldtype/FieldtypeComments/comments.min.js index e2e19f92..1e4f4f63 100644 --- a/wire/modules/Fieldtype/FieldtypeComments/comments.min.js +++ b/wire/modules/Fieldtype/FieldtypeComments/comments.min.js @@ -1 +1 @@ -function CommentFormSetCookie(name,value,days){var cookieValue=name+"="+escape(value)+";path=/";if(days==null)days=0;if(days>0){var today=new Date;var expire=new Date;expire.setTime(today.getTime()+36e5*24*days);document.cookie=cookieValue+";expires="+expire.toGMTString()}else{document.cookie=cookieValue}}function CommentFormGetCookie(name){var regex=new RegExp("[; ]"+name+"=([^\\s;]*)");var match=(" "+document.cookie).match(regex);if(name&&match)return unescape(match[1]);return""}function CommentFormStars(){function decodeEntities(encodedString){if(encodedString.indexOf("&")==-1)return encodedString;var textarea=document.createElement("textarea");textarea.innerHTML=encodedString;return textarea.value}function setStars($parent,star){var onClass,offClass,starOn,starOff;onClass=$parent.attr("data-onclass");offClass=$parent.attr("data-offclass");starOn=$parent.attr("data-on");if(typeof onClass=="undefined")onClass="CommentStarOff";if(typeof offClass=="undefined")offClass="CommentStarOff";if(typeof starOn!="undefined"){starOff=$parent.attr("data-off");starOn=decodeEntities(starOn);starOff=decodeEntities(starOff)}else{starOn="";starOff=""}$parent.children("span").each(function(){var val=parseInt(jQuery(this).attr("data-value"));if(val<=star){if(starOn.length)jQuery(this).html(starOn);jQuery(this).addClass(onClass).removeClass(offClass)}else{if(starOff.length)jQuery(this).html(starOff);jQuery(this).removeClass(onClass).addClass(offClass)}})}jQuery(".CommentFormStars input").hide();jQuery(document).on("click",".CommentStarsInput span",function(e){var value=parseInt(jQuery(this).attr("data-value"));var $parent=jQuery(this).parent();var $input=$parent.prev("input");$input.val(value).attr("value",value);setStars($parent,value);$input.change();return false})}function CommentActionReplyClick(){var $this=jQuery(this);var $item=$this.closest(".CommentListItem");var $form=$this.parent().next("form.CommentForm");var commentID=$item.attr("data-comment");if($form.length==0){$form=$item.find(".CommentForm"+commentID)}if($form.length==0){$form=jQuery("#CommentForm form").clone().removeAttr("id");$form.addClass("CommentForm"+commentID);$form.hide().find(".CommentFormParent").val($(this).attr("data-comment-id"));var $formPlaceholder=$item.find("form:eq(0)");if($formPlaceholder.length){$formPlaceholder.replaceWith($form)}else{$this.parent().after($form)}if($form.is("form[hidden]")){$form.removeAttr("hidden")}else if(!$form.is(":visible")){$form.slideDown()}}else if(!$form.is(":visible")){$form.slideDown()}else{$form.slideUp()}return false}function CommentActionRepliesClick(){var $this=jQuery(this);var href=$this.attr("href");var $list=$this.closest(".CommentListItem").find(href);if($list.is(":hidden")){$list.removeAttr("hidden")}else{$list.attr("hidden",true)}return false}function CommentFormSubmitClick(){var $this=jQuery(this);var $form=$this.closest("form.CommentForm");var $wrapStars=$form.find(".CommentFormStarsRequired");if($wrapStars.length){var stars=parseInt($wrapStars.find("input").val());if(!stars){alert($wrapStars.attr("data-note"));return false}}var cite=$form.find(".CommentFormCite input").val();var email=$form.find(".CommentFormEmail input").val();var $website=$form.find(".CommentFormWebsite input");var website=$website.length>0?$website.val():"";var $notify=$form.find(".CommentFormNotify :checked");var notify=$notify.length>0?$notify.val():"";if(cite.indexOf("|")>-1)cite="";if(email.indexOf("|")>-1)email="";if(website.indexOf("|")>-1)website="";var cookieValue=cite+"|"+email+"|"+website+"|"+notify;CommentFormSetCookie("CommentForm",cookieValue,0)}function CommentFormCookies(){var $form=jQuery("form.CommentForm");if(!$form.length)return;var cookieValue=CommentFormGetCookie("CommentForm");if(cookieValue.length<1)return;var values=cookieValue.split("|");$form.find(".CommentFormCite input").val(values[0]);$form.find(".CommentFormEmail input").val(values[1]);$form.find(".CommentFormWebsite input").val(values[2]);$form.find(".CommentFormNotify :input[value='"+values[3]+"']").prop("checked",true)}function CommentFormUpvoteDownvote(){var voting=false;jQuery(".CommentActionUpvote, .CommentActionDownvote").on("click",function(){if(voting)return false;voting=true;var $a=jQuery(this);jQuery.getJSON($a.attr("data-url"),function(data){if("success"in data){if(data.success){var $votes=$a.closest(".CommentVotes");$votes.find(".CommentUpvoteCnt").text(data.upvotes);$votes.find(".CommentDownvoteCnt").text(data.downvotes);$a.addClass("CommentVoted")}else if(data.message.length){alert(data.message)}}else{voting=false;return true}voting=false});return false})}function CommentFormInit(){jQuery(".CommentActionReply").on("click",CommentActionReplyClick);jQuery(".CommentActionReplies").on("click",CommentActionRepliesClick);jQuery(".CommentFormSubmit button").on("click",CommentFormSubmitClick);CommentFormCookies();CommentFormUpvoteDownvote();if(jQuery(".CommentStarsInput").length)CommentFormStars()}jQuery(document).ready(function(){CommentFormInit()}); \ No newline at end of file +function CommentFormSetCookie(name,value,days){var cookieValue=name+"="+escape(value)+";path=/";if(days==null)days=0;if(days>0){var today=new Date;var expire=new Date;expire.setTime(today.getTime()+36e5*24*days);document.cookie=cookieValue+";expires="+expire.toGMTString()}else{document.cookie=cookieValue}}function CommentFormGetCookie(name){var regex=new RegExp("[; ]"+name+"=([^\\s;]*)");var match=(" "+document.cookie).match(regex);if(name&&match)return unescape(match[1]);return""}function CommentFormStars(){function decodeEntities(encodedString){if(encodedString.indexOf("&")==-1)return encodedString;var textarea=document.createElement("textarea");textarea.innerHTML=encodedString;return textarea.value}function setStars($parent,star){var onClass,offClass,starOn,starOff;onClass=$parent.attr("data-onclass");offClass=$parent.attr("data-offclass");starOn=$parent.attr("data-on");if(typeof onClass=="undefined")onClass="CommentStarOff";if(typeof offClass=="undefined")offClass="CommentStarOff";if(typeof starOn!="undefined"){starOff=$parent.attr("data-off");starOn=decodeEntities(starOn);starOff=decodeEntities(starOff)}else{starOn="";starOff=""}$parent.children("span").each(function(){var val=parseInt(jQuery(this).attr("data-value"));if(val<=star){if(starOn.length)jQuery(this).html(starOn);jQuery(this).addClass(onClass).removeClass(offClass)}else{if(starOff.length)jQuery(this).html(starOff);jQuery(this).removeClass(onClass).addClass(offClass)}})}jQuery(".CommentFormStars input").hide();jQuery(document).on("click",".CommentStarsInput span",function(e){var value=parseInt(jQuery(this).attr("data-value"));var $parent=jQuery(this).parent();var $input=$parent.prev("input");$input.val(value).attr("value",value);setStars($parent,value);$input.change();return false})}function CommentActionReplyClick(){var $this=jQuery(this);var $item=$this.closest(".CommentListItem");var $form=$this.parent().next("form.CommentForm");var commentID=$item.attr("data-comment");if($form.length==0){$form=$item.find(".CommentForm"+commentID)}if($form.length==0){$form=jQuery("#CommentForm form").clone().removeAttr("id");$form.addClass("CommentForm"+commentID);$form.hide().find(".CommentFormParent").val(commentID);var $formPlaceholder=$item.find("form:not(.CommentFormReply):eq(0)");if($formPlaceholder.length){$formPlaceholder.replaceWith($form)}else{$this.parent().after($form)}$form.addClass("CommentFormReply");if($form.is("form[hidden]")){$form.removeAttr("hidden")}else if(!$form.is(":visible")){$form.slideDown()}$form.trigger("CommentFormReplyAdd");$form.trigger("CommentFormReplyShow")}else if(!$form.is(":visible")){$form.slideDown();$form.trigger("CommentFormReplyShow")}else{$form.slideUp();$form.trigger("CommentFormReplyHide")}return false}function CommentActionRepliesClick(){var $this=jQuery(this);var href=$this.attr("href");var $list=$this.closest(".CommentListItem").find(href);if($list.is(":hidden")){$list.removeAttr("hidden")}else{$list.attr("hidden",true)}return false}function CommentFormSubmitClick(){var $this=jQuery(this);var $form=$this.closest("form.CommentForm");var $wrapStars=$form.find(".CommentFormStarsRequired");if($wrapStars.length){var stars=parseInt($wrapStars.find("input").val());if(!stars){alert($wrapStars.attr("data-note"));return false}}var cite=$form.find(".CommentFormCite input").val();var email=$form.find(".CommentFormEmail input").val();var $website=$form.find(".CommentFormWebsite input");var website=$website.length>0?$website.val():"";var $notify=$form.find(".CommentFormNotify :checked");var notify=$notify.length>0?$notify.val():"";if(cite.indexOf("|")>-1)cite="";if(email.indexOf("|")>-1)email="";if(website.indexOf("|")>-1)website="";var cookieValue=cite+"|"+email+"|"+website+"|"+notify;CommentFormSetCookie("CommentForm",cookieValue,0)}function CommentFormCookies(){var $form=jQuery("form.CommentForm");if(!$form.length)return;var cookieValue=CommentFormGetCookie("CommentForm");if(cookieValue.length<1)return;var values=cookieValue.split("|");$form.find(".CommentFormCite input").val(values[0]);$form.find(".CommentFormEmail input").val(values[1]);$form.find(".CommentFormWebsite input").val(values[2]);$form.find(".CommentFormNotify :input[value='"+values[3]+"']").prop("checked",true)}function CommentFormUpvoteDownvote(){var voting=false;jQuery(".CommentActionUpvote, .CommentActionDownvote").on("click",function(){if(voting)return false;voting=true;var $a=jQuery(this);jQuery.getJSON($a.attr("data-url"),function(data){if("success"in data){if(data.success){var $votes=$a.closest(".CommentVotes");$votes.find(".CommentUpvoteCnt").text(data.upvotes);$votes.find(".CommentDownvoteCnt").text(data.downvotes);$a.addClass("CommentVoted")}else if(data.message.length){alert(data.message)}}else{voting=false;return true}voting=false});return false})}function CommentFormInit(){jQuery(".CommentActionReply").on("click",CommentActionReplyClick);jQuery(".CommentActionReplies").on("click",CommentActionRepliesClick);jQuery(".CommentFormSubmit button").on("click",CommentFormSubmitClick);CommentFormCookies();CommentFormUpvoteDownvote();if(jQuery(".CommentStarsInput").length)CommentFormStars()}jQuery(document).ready(function(){CommentFormInit()}); \ No newline at end of file