Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(function() {
  2.     var lastSelection = false;
  3.     var getSelection = function(element) {
  4.         var range;
  5.         if ('undefined' != typeof(window.getSelection)) {
  6.             range = "" + window.getSelection();
  7.         } else if ('undefined' != typeof(document.getSelection)) {
  8.             range = "" + document.getSelection();
  9.         } else if ('undefined' != document.selection) {
  10.             range = "" + document.selection.createRange().text;
  11.         }
  12.         return range.length ? range : false;
  13.     };
  14.     var addQuoteToReply = function(selection) {
  15.         var quoteText = '[quote', elReplyArea = $('#ctrl_message');
  16.         if (selection.elReplyTo) {
  17.             quoteText += '="' + selection.elReplyTo.attr('id').replace('post-', selection.elReplyTo.attr('data-author')+', post:').replace('"', '') + '"';
  18.         }
  19.         quoteText += ']' + selection.text + '[/quote]';
  20.         elReplyArea.val(elReplyArea.val() + quoteText);
  21.     };
  22.     jQuery('.messageContent article').mouseup(function() {
  23.         var selection = getSelection();
  24.         lastSelection = selection == false ? false : {
  25.             text: selection,
  26.             elReplyTo: jQuery(this).closest('.message')
  27.         };
  28.     });
  29.     jQuery(window).keypress(function(event) {
  30.         if (event.which == 13 && event.ctrlKey && lastSelection) {
  31.             addQuoteToReply(lastSelection);
  32.             lastSelection = false;
  33.         }
  34.     });
  35. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement