##// END OF EJS Templates
Refactoring of the scripts accessing textarea
neko259 -
r1769:30b6f53c default
parent child Browse files
Show More
@@ -1,190 +1,194 b''
1 var ITEM_FILE_SOURCE = 'fileSource';
1 var ITEM_FILE_SOURCE = 'fileSource';
2 var URL_STICKERS = '/api/stickers';
2 var URL_STICKERS = '/api/stickers';
3 var MIN_INPUT_LENGTH = 3;
3 var MIN_INPUT_LENGTH = 3;
4 var URL_DELIMITER = '\n';
4 var URL_DELIMITER = '\n';
5
5
6 $('input[name=image]').wrap($('<div class="file_wrap"></div>'));
6 $('input[name=image]').wrap($('<div class="file_wrap"></div>'));
7
7
8 $('body').on('change', 'input[name=image]', function(event) {
8 $('body').on('change', 'input[name=image]', function(event) {
9 var file = event.target.files[0];
9 var file = event.target.files[0];
10
10
11 if(file.type.match('image.*')) {
11 if(file.type.match('image.*')) {
12 var fileReader = new FileReader();
12 var fileReader = new FileReader();
13
13
14 fileReader.addEventListener("load", function(event) {
14 fileReader.addEventListener("load", function(event) {
15 var wrapper = $('.file_wrap');
15 var wrapper = $('.file_wrap');
16
16
17 wrapper.find('.file-thumb').remove();
17 wrapper.find('.file-thumb').remove();
18 wrapper.append(
18 wrapper.append(
19 $('<div class="file-thumb" style="background-image: url('+event.target.result+')"></div>')
19 $('<div class="file-thumb" style="background-image: url('+event.target.result+')"></div>')
20 );
20 );
21 });
21 });
22
22
23 fileReader.readAsDataURL(file);
23 fileReader.readAsDataURL(file);
24 }
24 }
25 });
25 });
26
26
27 var form = $('#form');
27 var form = $('#form');
28 $('textarea').keypress(function(event) {
28 $('textarea').keypress(function(event) {
29 if ((event.which == 10 || event.which == 13) && event.ctrlKey) {
29 if ((event.which == 10 || event.which == 13) && event.ctrlKey) {
30 form.find('input[type=submit]').click();
30 form.find('input[type=submit]').click();
31 }
31 }
32 });
32 });
33
33
34 $('#preview-button').click(function() {
34 $('#preview-button').click(function() {
35 var data = {
35 var data = {
36 raw_text: $('textarea#id_text').val()
36 raw_text: $('textarea#id_text').val()
37 }
37 }
38
38
39 var diffUrl = '/api/preview/';
39 var diffUrl = '/api/preview/';
40
40
41 $.post(diffUrl,
41 $.post(diffUrl,
42 data,
42 data,
43 function(data) {
43 function(data) {
44 var previewTextBlock = $('#preview-text');
44 var previewTextBlock = $('#preview-text');
45 previewTextBlock.html(data);
45 previewTextBlock.html(data);
46 previewTextBlock.show();
46 previewTextBlock.show();
47
47
48 addScriptsToPost(previewTextBlock);
48 addScriptsToPost(previewTextBlock);
49 })
49 })
50 });
50 });
51
51
52 /**
52 /**
53 * Show text in the errors row of the form.
53 * Show text in the errors row of the form.
54 * @param form
54 * @param form
55 * @param text
55 * @param text
56 */
56 */
57 function showAsErrors(form, text) {
57 function showAsErrors(form, text) {
58 form.children('.form-errors').remove();
58 form.children('.form-errors').remove();
59
59
60 if (text.length > 0) {
60 if (text.length > 0) {
61 var errorList = $('<div class="form-errors">' + text + '<div>');
61 var errorList = $('<div class="form-errors">' + text + '<div>');
62 errorList.appendTo(form);
62 errorList.appendTo(form);
63 }
63 }
64 }
64 }
65
65
66 function addHiddenInput(form, name, value) {
66 function addHiddenInput(form, name, value) {
67 form.find('input[name=' + name + ']').val(value);
67 form.find('input[name=' + name + ']').val(value);
68 }
68 }
69
69
70 function selectFileChoice() {
70 function selectFileChoice() {
71 var file_input = $('#id_file');
71 var file_input = $('#id_file');
72 var url_input = $('#id_file_url');
72 var url_input = $('#id_file_url');
73
73
74 var file_input_row = file_input.parent().parent();
74 var file_input_row = file_input.parent().parent();
75 var url_input_row = url_input.parent().parent();
75 var url_input_row = url_input.parent().parent();
76
76
77 file_input_row.toggle();
77 file_input_row.toggle();
78 url_input_row.toggle();
78 url_input_row.toggle();
79 url_input.val('');
79 url_input.val('');
80 file_input.val('');
80 file_input.val('');
81
81
82 var source;
82 var source;
83 if (file_input_row.is(':visible')) {
83 if (file_input_row.is(':visible')) {
84 source = 'file';
84 source = 'file';
85 } else {
85 } else {
86 source = 'url';
86 source = 'url';
87 }
87 }
88 localStorage.setItem(ITEM_FILE_SOURCE, source);
88 localStorage.setItem(ITEM_FILE_SOURCE, source);
89 }
89 }
90
90
91 function getPostTextarea() {
92 return $('textarea#id_text');
93 }
94
91 $(document).ready(function() {
95 $(document).ready(function() {
92 var powDifficulty = parseInt($('body').attr('data-pow-difficulty'));
96 var powDifficulty = parseInt($('body').attr('data-pow-difficulty'));
93 if (powDifficulty > 0 && typeof SharedWorker != 'undefined') {
97 if (powDifficulty > 0 && typeof SharedWorker != 'undefined') {
94 var worker = new SharedWorker($('.post-form').attr('data-pow-script'));
98 var worker = new SharedWorker($('.post-form').attr('data-pow-script'));
95 worker.port.onmessage = function(e) {
99 worker.port.onmessage = function(e) {
96 var form = $('#form');
100 var form = $('#form');
97 addHiddenInput(form, 'timestamp', e.data.timestamp);
101 addHiddenInput(form, 'timestamp', e.data.timestamp);
98 addHiddenInput(form, 'iteration', e.data.iteration);
102 addHiddenInput(form, 'iteration', e.data.iteration);
99 addHiddenInput(form, 'guess', e.data.guess);
103 addHiddenInput(form, 'guess', e.data.guess);
100
104
101 form.submit();
105 form.submit();
102 $('.post-form-w').unblock();
106 $('.post-form-w').unblock();
103 };
107 };
104 worker.onerror = function(event){
108 worker.onerror = function(event){
105 throw new Error(event.message + " (" + event.filename + ":" + event.lineno + ")");
109 throw new Error(event.message + " (" + event.filename + ":" + event.lineno + ")");
106 };
110 };
107 worker.port.start();
111 worker.port.start();
108
112
109 var form = $('#form');
113 var form = $('#form');
110 var submitButton = form.find('input[type=submit]');
114 var submitButton = form.find('input[type=submit]');
111 submitButton.click(function() {
115 submitButton.click(function() {
112 showAsErrors(form, gettext('Computing PoW...'));
116 showAsErrors(form, gettext('Computing PoW...'));
113 $('.post-form-w').block({ message: gettext('Computing PoW...') })
117 $('.post-form-w').block({ message: gettext('Computing PoW...') })
114
118
115 var msg = $('textarea#id_text').val().trim();
119 var msg = $('textarea#id_text').val().trim();
116
120
117 var data = {
121 var data = {
118 msg: msg,
122 msg: msg,
119 difficulty: parseInt($('body').attr('data-pow-difficulty')),
123 difficulty: parseInt($('body').attr('data-pow-difficulty')),
120 hasher: $('.post-form').attr('data-hasher')
124 hasher: $('.post-form').attr('data-hasher')
121 };
125 };
122 worker.port.postMessage(data);
126 worker.port.postMessage(data);
123
127
124 return false;
128 return false;
125 });
129 });
126 }
130 }
127
131
128 var $fileSourceButton = $('#file-source-button');
132 var $fileSourceButton = $('#file-source-button');
129 if (window.localStorage) {
133 if (window.localStorage) {
130 var source = localStorage.getItem(ITEM_FILE_SOURCE);
134 var source = localStorage.getItem(ITEM_FILE_SOURCE);
131 if (source == null) {
135 if (source == null) {
132 source = 'file';
136 source = 'file';
133 }
137 }
134 if (source == 'file') {
138 if (source == 'file') {
135 $('#id_file_url').parent().parent().hide();
139 $('#id_file_url').parent().parent().hide();
136 } else {
140 } else {
137 $('#id_file').parent().parent().hide();
141 $('#id_file').parent().parent().hide();
138 }
142 }
139
143
140 $fileSourceButton.click(function() {
144 $fileSourceButton.click(function() {
141 selectFileChoice();
145 selectFileChoice();
142 });
146 });
143 } else {
147 } else {
144 $fileSourceButton.hide();
148 $fileSourceButton.hide();
145 }
149 }
146
150
147 // Stickers autocomplete
151 // Stickers autocomplete
148 function split( val ) {
152 function split( val ) {
149 return val.split(URL_DELIMITER);
153 return val.split(URL_DELIMITER);
150 }
154 }
151
155
152 function extractLast( term ) {
156 function extractLast( term ) {
153 return split(term).pop();
157 return split(term).pop();
154 }
158 }
155
159
156 $('#id_file_1').autocomplete({
160 $('#id_file_1').autocomplete({
157 source: function( request, response ) {
161 source: function( request, response ) {
158 $.getJSON(URL_STICKERS, {
162 $.getJSON(URL_STICKERS, {
159 term: extractLast( request.term )
163 term: extractLast( request.term )
160 }, response);
164 }, response);
161 },
165 },
162 search: function() {
166 search: function() {
163 // custom minLength
167 // custom minLength
164 var term = extractLast( this.value );
168 var term = extractLast( this.value );
165 if (term.length < MIN_INPUT_LENGTH) {
169 if (term.length < MIN_INPUT_LENGTH) {
166 return false;
170 return false;
167 }
171 }
168 },
172 },
169 focus: function() {
173 focus: function() {
170 // prevent value inserted on focus
174 // prevent value inserted on focus
171 return false;
175 return false;
172 },
176 },
173 select: function( event, ui ) {
177 select: function( event, ui ) {
174 var terms = split( this.value );
178 var terms = split( this.value );
175 // remove the current input
179 // remove the current input
176 terms.pop();
180 terms.pop();
177 // add the selected item
181 // add the selected item
178 terms.push( ui.item.alias );
182 terms.push( ui.item.alias );
179 // add placeholder to get the comma-and-space at the end
183 // add placeholder to get the comma-and-space at the end
180 terms.push("");
184 terms.push("");
181 this.value = terms.join(URL_DELIMITER);
185 this.value = terms.join(URL_DELIMITER);
182 return false;
186 return false;
183 }
187 }
184 })
188 })
185 .autocomplete( "instance" )._renderItem = function( ul, item ) {
189 .autocomplete( "instance" )._renderItem = function( ul, item ) {
186 return $( "<li>" )
190 return $( "<li>" )
187 .append( "<div>" + '<img src="' + item.thumb + '">' + '<br />' + item.alias + "</div>" )
191 .append( "<div>" + '<img src="' + item.thumb + '">' + '<br />' + item.alias + "</div>" )
188 .appendTo( ul );
192 .appendTo( ul );
189 };
193 };
190 });
194 });
@@ -1,60 +1,60 b''
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 /**
26 /**
27 * Add the desired characters to the start and end of selection.
27 * Add the desired characters to the start and end of selection.
28 *
28 *
29 * @param start Start (left) text
29 * @param start Start (left) text
30 * @param end End (right) text
30 * @param end End (right) text
31 */
31 */
32 function addMarkToMsg(start, end) {
32 function addMarkToMsg(start, end) {
33 var textareas = $('textarea#id_text');
33 var textareas = getPostTextarea();
34
34
35 for (var i = 0; i < textareas.length; i++) {
35 for (var i = 0; i < textareas.length; i++) {
36 var textarea = textareas[i];
36 var textarea = textareas[i];
37
37
38 if (document.selection) {
38 if (document.selection) {
39 textarea.focus();
39 textarea.focus();
40
40
41 var sel = document.selection.createRange();
41 var sel = document.selection.createRange();
42 sel.text = start + sel.text + end;
42 sel.text = start + sel.text + end;
43 } else if (textarea.selectionStart || textarea.selectionStart == '0') {
43 } else if (textarea.selectionStart || textarea.selectionStart == '0') {
44 textarea.focus();
44 textarea.focus();
45
45
46 var startPos = textarea.selectionStart;
46 var startPos = textarea.selectionStart;
47 var endPos = textarea.selectionEnd;
47 var endPos = textarea.selectionEnd;
48
48
49 var oldValue = textarea.value;
49 var oldValue = textarea.value;
50 textarea.value = oldValue.substring(0, startPos) + start +
50 textarea.value = oldValue.substring(0, startPos) + start +
51 oldValue.substring(startPos, endPos) + end +
51 oldValue.substring(startPos, endPos) + end +
52 oldValue.substring(endPos, oldValue.length);
52 oldValue.substring(endPos, oldValue.length);
53 } else {
53 } else {
54 textarea.value += start + end;
54 textarea.value += start + end;
55 }
55 }
56 }
56 }
57
57
58 return false;
58 return false;
59 }
59 }
60
60
@@ -1,168 +1,168 b''
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#id_text');
71 var textAreaJq = getPostTextarea();
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 var postText = textAreaJq.val();
80 var postText = textAreaJq.val();
81 if (!post.is(':first-child') && postText.indexOf(postLinkRaw) < 0) {
81 if (!post.is(':first-child') && postText.indexOf(postLinkRaw) < 0) {
82 // Insert line break if none is present.
82 // Insert line break if none is present.
83 if (postText.length > 0 && !postText.endsWith('\n') && !postText.endsWith('\r')) {
83 if (postText.length > 0 && !postText.endsWith('\n') && !postText.endsWith('\r')) {
84 textToAdd += '\n';
84 textToAdd += '\n';
85 }
85 }
86 textToAdd += postLinkRaw + '\n';
86 textToAdd += postLinkRaw + '\n';
87 }
87 }
88
88
89 textAreaJq.val(textAreaJq.val()+ textToAdd);
89 textAreaJq.val(textAreaJq.val()+ textToAdd);
90 blockToInsert = post;
90 blockToInsert = post;
91 } else {
91 } else {
92 blockToInsert = $('.thread');
92 blockToInsert = $('.thread');
93 }
93 }
94 showFormAfter(blockToInsert);
94 showFormAfter(blockToInsert);
95
95
96 textAreaJq.focus();
96 textAreaJq.focus();
97
97
98 var textarea = document.getElementsByTagName('textarea')[0];
98 var textarea = document.getElementsByTagName('textarea')[0];
99 moveCaretToEnd(textarea);
99 moveCaretToEnd(textarea);
100 }
100 }
101 }
101 }
102
102
103 function addQuickQuote() {
103 function addQuickQuote() {
104 var textAreaJq = $('textarea#id_text');
104 var textAreaJq = getPostTextarea();
105
105
106 var quoteButton = $("#quote-button");
106 var quoteButton = $("#quote-button");
107 var postId = quoteButton.attr('data-post-id');
107 var postId = quoteButton.attr('data-post-id');
108 if (postId != null && getForm().prev().attr('id') != postId) {
108 if (postId != null && getForm().prev().attr('id') != postId) {
109 addQuickReply(postId);
109 addQuickReply(postId);
110 }
110 }
111
111
112 var textToAdd = '';
112 var textToAdd = '';
113 var selection = window.getSelection().toString();
113 var selection = window.getSelection().toString();
114 if (selection.length == 0) {
114 if (selection.length == 0) {
115 selection = quoteButton.attr('data-text');
115 selection = quoteButton.attr('data-text');
116 }
116 }
117 if (selection.length > 0) {
117 if (selection.length > 0) {
118 textToAdd += '[quote]' + selection + '[/quote]\n';
118 textToAdd += '[quote]' + selection + '[/quote]\n';
119 }
119 }
120
120
121 textAreaJq.val(textAreaJq.val() + textToAdd);
121 textAreaJq.val(textAreaJq.val() + textToAdd);
122
122
123 textAreaJq.focus();
123 textAreaJq.focus();
124
124
125 var textarea = document.getElementsByTagName('textarea')[0];
125 var textarea = document.getElementsByTagName('textarea')[0];
126 moveCaretToEnd(textarea);
126 moveCaretToEnd(textarea);
127 }
127 }
128
128
129 function scrollToBottom() {
129 function scrollToBottom() {
130 $html.animate({scrollTop: $html.height()}, "fast");
130 $html.animate({scrollTop: $html.height()}, "fast");
131 }
131 }
132
132
133 function showQuoteButton() {
133 function showQuoteButton() {
134 var selection = window.getSelection().getRangeAt(0).getBoundingClientRect();
134 var selection = window.getSelection().getRangeAt(0).getBoundingClientRect();
135 var quoteButton = $("#quote-button");
135 var quoteButton = $("#quote-button");
136 if (selection.width > 0) {
136 if (selection.width > 0) {
137 // quoteButton.offset({ top: selection.top - selection.height, left: selection.left });
137 // quoteButton.offset({ top: selection.top - selection.height, left: selection.left });
138 quoteButton.css({top: selection.top + $(window).scrollTop() - 30, left: selection.left});
138 quoteButton.css({top: selection.top + $(window).scrollTop() - 30, left: selection.left});
139 quoteButton.show();
139 quoteButton.show();
140
140
141 var text = window.getSelection().toString();
141 var text = window.getSelection().toString();
142 quoteButton.attr('data-text', text);
142 quoteButton.attr('data-text', text);
143
143
144 var rect = window.getSelection().getRangeAt(0).getBoundingClientRect();
144 var rect = window.getSelection().getRangeAt(0).getBoundingClientRect();
145 var element = $(document.elementFromPoint(rect.x, rect.y));
145 var element = $(document.elementFromPoint(rect.x, rect.y));
146 var postId = null;
146 var postId = null;
147 if (element.hasClass('post')) {
147 if (element.hasClass('post')) {
148 postId = element.attr('id');
148 postId = element.attr('id');
149 } else {
149 } else {
150 var postParent = element.parents('.post');
150 var postParent = element.parents('.post');
151 if (postParent.length > 0) {
151 if (postParent.length > 0) {
152 postId = postParent.attr('id');
152 postId = postParent.attr('id');
153 }
153 }
154 }
154 }
155 quoteButton.attr('data-post-id', postId);
155 quoteButton.attr('data-post-id', postId);
156 } else {
156 } else {
157 quoteButton.hide();
157 quoteButton.hide();
158 }
158 }
159 }
159 }
160
160
161 $(document).ready(function() {
161 $(document).ready(function() {
162 $('body').on('mouseup', function() {
162 $('body').on('mouseup', function() {
163 showQuoteButton();
163 showQuoteButton();
164 });
164 });
165 $("#quote-button").click(function() {
165 $("#quote-button").click(function() {
166 addQuickQuote();
166 addQuickQuote();
167 })
167 })
168 });
168 });
General Comments 0
You need to be logged in to leave comments. Login now