mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-25 10:38:11 +01:00
f617a2d6d9
Update the comment reply JavaScript to be unobtrusive and use events rather than inline `onclick` attributes. Along with bringing the code into the 2010s this prevents an edge-case in which `addComment.moveForm()` could be called before the JavaScript has loaded. Props peterwilsoncc, bradparbs. Fixes #31590. Built from https://develop.svn.wordpress.org/trunk@42360 git-svn-id: http://core.svn.wordpress.org/trunk@42189 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 line
1.8 KiB
JavaScript
1 line
1.8 KiB
JavaScript
var addComment;addComment=function(a){function b(a){if(!0===o&&(j=g(n.cancelReplyId),k=g(n.commentFormId),j)){j.addEventListener("touchstart",d),j.addEventListener("click",d);for(var b,f=c(a),h=0,i=f.length;h<i;h++)b=f[h],b.addEventListener("touchstart",e),b.addEventListener("click",e)}}function c(a){var b,c=n.commentReplyClass;return a&&a.childNodes||(a=m),b=m.getElementsByClassName?a.getElementsByClassName(c):a.querySelectorAll("."+c)}function d(a){var b=this,c=n.temporaryFormId,d=g(c);d&&l&&(g(n.parentIdFieldId).value="0",d.parentNode.replaceChild(l,d),b.style.display="none",a.preventDefault())}function e(b){var c,d=this,e=f(d,"belowelement"),g=f(d,"commentid"),h=f(d,"respondelement"),i=f(d,"postid");c=a.addComment.moveForm(e,g,h,i),!1===c&&b.preventDefault()}function f(a,b){return p?a.dataset[b]:a.getAttribute("data-"+b)}function g(a){return m.getElementById(a)}function h(b,c,d,e){var f=g(b);l=g(d);var h,o,p,q=g(n.parentIdFieldId),r=g(n.postIdFieldId);if(f&&l&&q){i(l),e&&r&&(r.value=e),q.value=c,j.style.display="",f.parentNode.insertBefore(l,f.nextSibling),j.onclick=function(){return!1};try{for(var s=0;s<k.elements.length;s++)if(h=k.elements[s],o=!1,"getComputedStyle"in a?p=a.getComputedStyle(h):m.documentElement.currentStyle&&(p=h.currentStyle),(h.offsetWidth<=0&&h.offsetHeight<=0||"hidden"===p.visibility)&&(o=!0),"hidden"!==h.type&&!h.disabled&&!o){h.focus();break}}catch(t){}return!1}}function i(a){var b=n.temporaryFormId,c=g(b);c||(c=m.createElement("div"),c.id=b,c.style.display="none",a.parentNode.insertBefore(c,a))}var j,k,l,m=a.document,n={commentReplyClass:"comment-reply-link",cancelReplyId:"cancel-comment-reply-link",commentFormId:"commentform",temporaryFormId:"wp-temp-form-div",parentIdFieldId:"comment_parent",postIdFieldId:"comment_post_ID"},o="querySelector"in m&&"addEventListener"in a,p=!!m.body.dataset;return b(),{init:b,moveForm:h}}(window); |