|
1 | 1 | <script type="text/javascript">
|
2 | 2 | (function () {
|
| 3 | + 'use strict'; |
3 | 4 |
|
4 |
| - var events = 'DOMContentLoaded load resize scroll'; |
5 |
| - var handler = null; |
6 |
| - var didCallback = false; |
| 5 | + {{> includes/scripts/polyfillElementClosest.js }} |
7 | 6 |
|
8 |
| - $('#reply-control').on('show.bs.collapse', function () { |
9 |
| - // Show spacer div |
10 |
| - $('#show-reply-form-when-visible').css({ |
11 |
| - height: |
12 |
| - {{#paginationRendered}}'210px'{{/paginationRendered}} |
13 |
| - {{^paginationRendered}}'268px'{{/paginationRendered}} |
14 |
| - }); |
15 |
| - }); |
16 |
| - |
17 |
| - $('#reply-control').on('hide.bs.collapse', function () { |
18 |
| - // Hide spacer div |
19 |
| - $('#show-reply-form-when-visible').css({ |
20 |
| - height: '0' |
21 |
| - }); |
22 |
| - |
23 |
| - // Clear text value from reply box |
24 |
| - $('#reply-control textarea[name="comment-content"]').val(''); |
25 |
| - }); |
26 |
| - |
27 |
| - $('.btn-comment-reply').click(function (aE) { |
28 |
| - var $comment = $(aE.target).closest('.topic-post'); |
29 |
| - var $author = $comment.find('.topic-meta-data .names .username').first(); |
30 |
| - var $replyTextarea = $('#reply-control textarea[name="comment-content"]'); |
| 7 | + function onClick(aEv) { |
| 8 | + var commentNode = document.querySelector('textarea[name="comment-content"]'); |
| 9 | + var containerNode = aEv.target.closest('.topic-post'); |
| 10 | + var authorNode = containerNode.querySelector('.topic-meta-data .names .username'); |
31 | 11 | var value = null;
|
32 |
| - var reUrl = null; |
| 12 | + var url = null; |
33 | 13 |
|
34 |
| - $('#reply-control').collapse('show'); |
| 14 | + document.location.hash = containerNode.id; |
35 | 15 |
|
36 |
| - document.location.hash = $comment.attr('id'); |
| 16 | + url = document.location.pathname + document.location.search + document.location.hash; |
| 17 | + url = url.replace(/\(/g, '%28').replace(/\)/g, '%29'); |
37 | 18 |
|
38 |
| - reUrl = document.location.pathname + |
39 |
| - document.location.search + |
40 |
| - document.location.hash; |
41 |
| - reUrl = reUrl.replace(/\(/g, '%28').replace(/\)/g, '%29'); |
| 19 | + value = commentNode.value; |
42 | 20 |
|
43 |
| - value = $replyTextarea.val(); |
44 | 21 | if (!/^\s*$/.test(value)) {
|
45 | 22 | // Add linebreaks if reply already started.
|
46 | 23 | value += '\n\n';
|
47 | 24 | }
|
48 |
| - value += '[Re](' + reUrl + '): '; |
49 |
| - value += '@' + $author.text() + ': '; |
50 |
| - value += ' \n'; |
51 |
| - $replyTextarea.val(value); |
52 |
| - $replyTextarea.focus(); |
53 |
| - }); |
54 | 25 |
|
55 |
| - function callback(aEl) { |
56 |
| - if (!didCallback) { |
57 |
| - didCallback = true; |
| 26 | + value += '[Re](' + url + '): '; |
| 27 | + value += '@' + authorNode.textContent + ': '; |
| 28 | + value += ' \n'; |
58 | 29 |
|
59 |
| - $('#reply-control').collapse('show'); |
60 |
| - $('#reply-control textarea[name="comment-content"]').focus(); |
61 |
| - } |
| 30 | + commentNode.value = value; |
| 31 | + commentNode.focus(); |
62 | 32 | }
|
63 | 33 |
|
64 |
| - {{> includes/scripts/isElementInViewport.js }} |
65 |
| - |
66 |
| - function fireIfElementVisible(aEl, aCallback) { |
67 |
| - return function () { |
68 |
| - if (isElementInViewport(aEl)) { |
69 |
| - $(window).off(events, handler); |
| 34 | + function onDOMContentLoaded(aEv) { |
| 35 | + var i = null; |
| 36 | + var thisNode = null; |
| 37 | + var replyNodes = document.querySelectorAll('.btn-comment-reply'); |
70 | 38 |
|
71 |
| - aCallback(aEl); |
72 |
| - } |
| 39 | + for (i = 0; thisNode = replyNodes[i++];) { |
| 40 | + thisNode.addEventListener('click', onClick); |
73 | 41 | }
|
74 | 42 | }
|
75 | 43 |
|
76 |
| - handler = fireIfElementVisible($('#show-reply-form-when-visible'), callback); |
77 |
| - $(window).on(events, handler); |
| 44 | + document.addEventListener('DOMContentLoaded', onDOMContentLoaded); |
78 | 45 |
|
79 | 46 | })();
|
80 | 47 | </script>
|
0 commit comments