Show More
@@ -1,142 +1,143 | |||
|
1 | 1 | /* |
|
2 | 2 | @licstart The following is the entire license notice for the |
|
3 | 3 | JavaScript code in this page. |
|
4 | 4 | |
|
5 | 5 | |
|
6 | 6 | Copyright (C) 2013 neko259 |
|
7 | 7 | |
|
8 | 8 | The JavaScript code in this page is free software: you can |
|
9 | 9 | redistribute it and/or modify it under the terms of the GNU |
|
10 | 10 | General Public License (GNU GPL) as published by the Free Software |
|
11 | 11 | Foundation, either version 3 of the License, or (at your option) |
|
12 | 12 | any later version. The code is distributed WITHOUT ANY WARRANTY; |
|
13 | 13 | without even the implied warranty of MERCHANTABILITY or FITNESS |
|
14 | 14 | FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. |
|
15 | 15 | |
|
16 | 16 | As additional permission under GNU GPL version 3 section 7, you |
|
17 | 17 | may distribute non-source (e.g., minimized or compacted) forms of |
|
18 | 18 | that code without the copy of the GNU GPL normally required by |
|
19 | 19 | section 4, provided you include this license notice and a URL |
|
20 | 20 | through which recipients can access the Corresponding Source. |
|
21 | 21 | |
|
22 | 22 | @licend The above is the entire license notice |
|
23 | 23 | for the JavaScript code in this page. |
|
24 | 24 | */ |
|
25 | 25 | |
|
26 | 26 | var REPLY_TO_MSG = '.reply-to-message'; |
|
27 | 27 | var REPLY_TO_MSG_ID = '#reply-to-message-id'; |
|
28 | 28 | |
|
29 | 29 | var $html = $("html, body"); |
|
30 | var $quoteButton = $("#quote-button"); | |
|
30 | 31 | |
|
31 | 32 | function moveCaretToEnd(el) { |
|
32 | 33 | var newPos = el.val().length; |
|
33 | 34 | el[0].setSelectionRange(newPos, newPos); |
|
34 | 35 | } |
|
35 | 36 | |
|
36 | 37 | |
|
37 | 38 | function showFormAfter(blockToInsertAfter) { |
|
38 | 39 | var form = getForm(); |
|
39 | 40 | form.insertAfter(blockToInsertAfter); |
|
40 | 41 | |
|
41 | 42 | form.show(); |
|
42 | 43 | $(REPLY_TO_MSG_ID).text(blockToInsertAfter.attr('id')); |
|
43 | 44 | $(REPLY_TO_MSG).show(); |
|
44 | 45 | } |
|
45 | 46 | |
|
46 | 47 | function addQuickReply(postId) { |
|
47 | 48 | var blockToInsert = null; |
|
48 | 49 | var textAreaJq = getPostTextarea(); |
|
49 | 50 | var postLinkRaw = '[post]' + postId + '[/post]' |
|
50 | 51 | var textToAdd = ''; |
|
51 | 52 | |
|
52 | 53 | if (postId != null) { |
|
53 | 54 | var post = $('#' + postId); |
|
54 | 55 | |
|
55 | 56 | // If this is not OP, add reflink to the post. If there already is |
|
56 | 57 | // the same reflink, don't add it again. |
|
57 | 58 | var postText = textAreaJq.val(); |
|
58 | 59 | if (!post.is(':first-child') && postText.indexOf(postLinkRaw) < 0) { |
|
59 | 60 | // Insert line break if none is present. |
|
60 | 61 | if (postText.length > 0 && !postText.endsWith('\n') && !postText.endsWith('\r')) { |
|
61 | 62 | textToAdd += '\n'; |
|
62 | 63 | } |
|
63 | 64 | textToAdd += postLinkRaw + '\n'; |
|
64 | 65 | } |
|
65 | 66 | |
|
66 | 67 | textAreaJq.val(textAreaJq.val()+ textToAdd); |
|
67 | 68 | blockToInsert = post; |
|
68 | 69 | } else { |
|
69 | 70 | blockToInsert = $('.thread'); |
|
70 | 71 | } |
|
71 | 72 | showFormAfter(blockToInsert); |
|
72 | 73 | |
|
73 | 74 | textAreaJq.focus(); |
|
74 | 75 | |
|
75 | 76 | moveCaretToEnd(textAreaJq); |
|
76 | 77 | } |
|
77 | 78 | |
|
78 | 79 | function addQuickQuote() { |
|
79 | 80 | var textAreaJq = getPostTextarea(); |
|
80 | 81 | |
|
81 | var quoteButton = $("#quote-button"); | |
|
82 | var postId = quoteButton.attr('data-post-id'); | |
|
82 | var postId = $quoteButton.attr('data-post-id'); | |
|
83 | 83 | if (postId != null) { |
|
84 | 84 | addQuickReply(postId); |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | var textToAdd = ''; |
|
88 | 88 | var selection = window.getSelection().toString(); |
|
89 | 89 | if (selection.length == 0) { |
|
90 | selection = quoteButton.attr('data-text'); | |
|
90 | selection = $quoteButton.attr('data-text'); | |
|
91 | 91 | } |
|
92 | 92 | if (selection.length > 0) { |
|
93 | 93 | textToAdd += '[quote]' + selection + '[/quote]\n'; |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | textAreaJq.val(textAreaJq.val() + textToAdd); |
|
97 | 97 | |
|
98 | 98 | textAreaJq.focus(); |
|
99 | 99 | |
|
100 | 100 | moveCaretToEnd(textAreaJq); |
|
101 | ||
|
102 | $quoteButton.hide(); | |
|
101 | 103 | } |
|
102 | 104 | |
|
103 | 105 | function scrollToBottom() { |
|
104 | 106 | $html.animate({scrollTop: $html.height()}, "fast"); |
|
105 | 107 | } |
|
106 | 108 | |
|
107 | 109 | function showQuoteButton() { |
|
108 | 110 | var selection = window.getSelection().getRangeAt(0).getBoundingClientRect(); |
|
109 | var quoteButton = $("#quote-button"); | |
|
110 | 111 | if (selection.width > 0) { |
|
111 | 112 | // quoteButton.offset({ top: selection.top - selection.height, left: selection.left }); |
|
112 | quoteButton.css({top: selection.top + $(window).scrollTop() - 30, left: selection.left}); | |
|
113 | quoteButton.show(); | |
|
113 | $quoteButton.css({top: selection.top + $(window).scrollTop() - 30, left: selection.left}); | |
|
114 | $quoteButton.show(); | |
|
114 | 115 | |
|
115 | 116 | var text = window.getSelection().toString(); |
|
116 | quoteButton.attr('data-text', text); | |
|
117 | $quoteButton.attr('data-text', text); | |
|
117 | 118 | |
|
118 | 119 | var rect = window.getSelection().getRangeAt(0).getBoundingClientRect(); |
|
119 | 120 | var element = $(document.elementFromPoint(rect.x, rect.y)); |
|
120 | 121 | var postId = null; |
|
121 | 122 | if (element.hasClass('post')) { |
|
122 | 123 | postId = element.attr('id'); |
|
123 | 124 | } else { |
|
124 | 125 | var postParent = element.parents('.post'); |
|
125 | 126 | if (postParent.length > 0) { |
|
126 | 127 | postId = postParent.attr('id'); |
|
127 | 128 | } |
|
128 | 129 | } |
|
129 | quoteButton.attr('data-post-id', postId); | |
|
130 | $quoteButton.attr('data-post-id', postId); | |
|
130 | 131 | } else { |
|
131 | quoteButton.hide(); | |
|
132 | $quoteButton.hide(); | |
|
132 | 133 | } |
|
133 | 134 | } |
|
134 | 135 | |
|
135 | 136 | $(document).ready(function() { |
|
136 | 137 | $('body').on('mouseup', function() { |
|
137 | 138 | showQuoteButton(); |
|
138 | 139 | }); |
|
139 | 140 | $("#quote-button").click(function() { |
|
140 | 141 | addQuickQuote(); |
|
141 | 142 | }) |
|
142 | 143 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now