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