Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(function() {
- var lastSelection = false;
- var getSelection = function(element) {
- var range;
- if ('undefined' != typeof(window.getSelection)) {
- range = "" + window.getSelection();
- } else if ('undefined' != typeof(document.getSelection)) {
- range = "" + document.getSelection();
- } else if ('undefined' != document.selection) {
- range = "" + document.selection.createRange().text;
- }
- return range.length ? range : false;
- };
- var addQuoteToReply = function(selection) {
- var quoteText = '[quote', elReplyArea = $('#ctrl_message');
- if (selection.elReplyTo) {
- quoteText += '="' + selection.elReplyTo.attr('id').replace('post-', selection.elReplyTo.attr('data-author')+', post:').replace('"', '') + '"';
- }
- quoteText += ']' + selection.text + '[/quote]';
- elReplyArea.val(elReplyArea.val() + quoteText);
- };
- jQuery('.messageContent article').mouseup(function() {
- var selection = getSelection();
- lastSelection = selection == false ? false : {
- text: selection,
- elReplyTo: jQuery(this).closest('.message')
- };
- });
- jQuery(window).keypress(function(event) {
- if (event.which == 13 && event.ctrlKey && lastSelection) {
- addQuoteToReply(lastSelection);
- lastSelection = false;
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement