Show More
@@ -1,120 +1,122 b'' | |||
|
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 CLOSE_BUTTON = '#form-close-button'; |
|
27 | 27 | var REPLY_TO_MSG = '.reply-to-message'; |
|
28 | 28 | var REPLY_TO_MSG_ID = '#reply-to-message-id'; |
|
29 | 29 | |
|
30 | 30 | var $html = $("html, body"); |
|
31 | 31 | |
|
32 | 32 | function moveCaretToEnd(el) { |
|
33 | 33 | if (typeof el.selectionStart == "number") { |
|
34 | 34 | el.selectionStart = el.selectionEnd = el.value.length; |
|
35 | 35 | } else if (typeof el.createTextRange != "undefined") { |
|
36 | 36 | el.focus(); |
|
37 | 37 | var range = el.createTextRange(); |
|
38 | 38 | range.collapse(false); |
|
39 | 39 | range.select(); |
|
40 | 40 | } |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | function getForm() { |
|
44 | 44 | return $('.post-form-w'); |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | function resetFormPosition() { |
|
48 | 48 | var form = getForm(); |
|
49 | 49 | form.insertAfter($('.thread')); |
|
50 | 50 | |
|
51 | 51 | $(CLOSE_BUTTON).hide(); |
|
52 | 52 | $(REPLY_TO_MSG).hide(); |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | function showFormAfter(blockToInsertAfter) { |
|
56 | 56 | var form = getForm(); |
|
57 | 57 | form.insertAfter(blockToInsertAfter); |
|
58 | 58 | |
|
59 | 59 | $(CLOSE_BUTTON).show(); |
|
60 | 60 | form.show(); |
|
61 | 61 | $(REPLY_TO_MSG_ID).text(blockToInsertAfter.attr('id')); |
|
62 | 62 | $(REPLY_TO_MSG).show(); |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | function addQuickReply(postId) { |
|
66 | 66 | // If we click "reply" on the same post, it means "cancel" |
|
67 | 67 | if (getForm().prev().attr('id') == postId) { |
|
68 | 68 | resetFormPosition(); |
|
69 | 69 | } else { |
|
70 | 70 | var blockToInsert = null; |
|
71 | 71 | var textAreaJq = $('textarea'); |
|
72 | 72 | var postLinkRaw = '[post]' + postId + '[/post]' |
|
73 | 73 | var textToAdd = ''; |
|
74 | 74 | |
|
75 | 75 | if (postId != null) { |
|
76 | 76 | var post = $('#' + postId); |
|
77 | 77 | |
|
78 | 78 | // If this is not OP, add reflink to the post. If there already is |
|
79 | 79 | // the same reflink, don't add it again. |
|
80 | 80 | if (!post.is(':first-child') && textAreaJq.val().indexOf(postLinkRaw) < 0) { |
|
81 | 81 | textToAdd += postLinkRaw + '\n'; |
|
82 | 82 | } |
|
83 | 83 | |
|
84 | 84 | textAreaJq.val(textAreaJq.val()+ textToAdd); |
|
85 | 85 | blockToInsert = post; |
|
86 | 86 | } else { |
|
87 | 87 | blockToInsert = $('.thread'); |
|
88 | 88 | } |
|
89 | 89 | showFormAfter(blockToInsert); |
|
90 |
|
|
|
90 | ||
|
91 | textAreaJq.focus(); | |
|
91 | 92 | |
|
92 | var textarea = document.getElementsByTagName('textarea')[0]; | |
|
93 | moveCaretToEnd(textarea); | |
|
93 | var textarea = document.getElementsByTagName('textarea')[0]; | |
|
94 | moveCaretToEnd(textarea); | |
|
95 | } | |
|
94 | 96 | } |
|
95 | 97 | |
|
96 | 98 | function addQuickQuote(postId) { |
|
97 | 99 | if (getForm().prev().attr('id') != postId) { |
|
98 | 100 | addQuickReply(postId); |
|
99 | 101 | } |
|
100 | 102 | |
|
101 | 103 | var textToAdd = ''; |
|
102 | 104 | var textAreaJq = $('textarea'); |
|
103 | 105 | var postLinkRaw = '[post]' + postId + '[/post]' |
|
104 | 106 | var selection = window.getSelection().toString(); |
|
105 | 107 | if (selection.length > 0) { |
|
106 | 108 | textToAdd += '[quote]' + selection + '[/quote]\n'; |
|
107 | 109 | } |
|
108 | 110 | |
|
109 | 111 | textAreaJq.val(textAreaJq.val()+ textToAdd); |
|
110 | 112 | |
|
111 | 113 | textAreaJq.focus(); |
|
112 | 114 | |
|
113 | 115 | var textarea = document.getElementsByTagName('textarea')[0]; |
|
114 | 116 | moveCaretToEnd(textarea); |
|
115 | 117 | } |
|
116 | 118 | |
|
117 | 119 | function scrollToBottom() { |
|
118 | 120 | $html.animate({scrollTop: $html.height()}, "fast"); |
|
119 | 121 | } |
|
120 | 122 |
General Comments 0
You need to be logged in to leave comments.
Login now