Advertisement
arun_sparx

bbpress-quotes fix for wp_editor

May 30th, 2012
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function quote(postid, author, commentarea, commentID) {
  2.     try {
  3.            
  4.             var editor_html = document.getElementById('bbp_reply_content-html');
  5.                 switchEditors.switchto(editor_html);
  6.         // If you don't want quotes begin with "<author>:", uncomment the next line
  7.         //author = null;
  8.  
  9.         // begin code
  10.         var posttext = '';
  11.  
  12.         if (window.getSelection){
  13.             posttext = window.getSelection();
  14.         }
  15.  
  16.         else if (document.getSelection){
  17.             posttext = document.getSelection();
  18.         }
  19.  
  20.         else if (document.selection){
  21.             posttext = document.selection.createRange().text;
  22.         }
  23.  
  24.         else {
  25.             return true;
  26.         }
  27.  
  28.         if (posttext=='') {     // quoting entire comment
  29.  
  30.             // quoteing the entire thing
  31.             var selection = false;
  32.             var commentID = commentID.split("q-")[1];
  33.             //var commentID = "bbp-reply-content";
  34.  
  35.             // quote entire comment as html
  36.             var theQuote = "q-"+commentID;
  37.             //var theQuote = "div-comment-"+commentID;
  38.             var posttext = document.getElementById(theQuote).innerHTML;
  39.  
  40.             // remove nested divs
  41.             var posttext = posttext.replace(/<div(.*?)>((.|\n)*?)(<\/div>)/ig, "");
  42.  
  43.             // remove nested blockquotes
  44.             var posttext = posttext.replace(/<blockquote(.*?)>((.|\n)*?)(<\/blockquote>)/ig, "");
  45.             var posttext = posttext.replace(/<blockquote(.*?)>((.|\n)*?)(<\/blockquote>)/ig, "");
  46.  
  47.             // remove superfluous linebreaks
  48.             var posttext = posttext.replace(/\s\s/gm, "");
  49.  
  50.             // do basic cleanups
  51.             var posttext = posttext.replace(/   /g, "");
  52.             //var posttext = posttext.replace(/<p>/g, "\n");
  53.             //var posttext = posttext.replace(/<\/\s*p>/g, "");
  54.             var posttext = posttext.replace(/<p>/g, "");
  55.             var posttext = posttext.replace(/<\/\s*p>/g, "\n\n");
  56.             var posttext = posttext.replace(/<br>/g, "")
  57.  
  58.             // remove nonbreaking space
  59.             var posttext = posttext.replace(/&nbsp;/g, " ");
  60.  
  61.             // remove nested spans
  62.             var posttext = posttext.replace(/<span(.*?)>((.|\n)*?)(<\/span>)/ig, "");
  63.  
  64.             // remove nested blockquotes
  65.             while (posttext != (posttext = posttext.replace(/<blockquote>[^>]*<\/\s*blockquote>/g, "")));
  66.  
  67.             // remove nested quote links
  68.             var posttext = posttext.replace(/<a class="bbpress_quotes__link"(.*?)>((.|\n)*?)(<\/a>)/ig, "");
  69.             //var posttext = posttext.replace(/<a class="comment_reply_link"(.*?)>((.|\n)*?)(<\/a>)/ig, "");
  70.  
  71.         }
  72.  
  73.         // build quote
  74.         //if (author) {
  75.            
  76.             // prevent xss stuff
  77.             author = jsEncode(author);
  78.            
  79.             var quote='\n<blockquote cite="comment-'+postid+'">\n\n<strong><a href="#comment-'+postid+'">'+unescape(author)+'</a></strong>: '+posttext+'</blockquote>&nbsp;\n';
  80.  
  81.         //} else {
  82.  
  83.             //var quote='\n<blockquote cite="comment-'+postid+'">\n\n'+posttext+'</blockquote>\n';
  84.  
  85.         //}
  86.  
  87.         // send quoted content
  88.         //if (mce == true) {        // TinyMCE detected
  89.  
  90.             //addQuoteMCE(comment,quote);
  91.             //insertHTML(quote);
  92.             //insertHTML("<p>&nbsp;</p>");
  93.  
  94.         //} else {              // No TinyMCE detected
  95.  
  96.             var comment=document.getElementById(commentarea);
  97.             addQuote(comment,quote);
  98.  
  99.         //}
  100.                 var editor_html = document.getElementById('bbp_reply_content-tmce');
  101.                 switchEditors.switchto(editor_html);
  102.         return false;
  103.  
  104.     } catch (e) {
  105.  
  106.         alert("Uh Oh! Something went wrong!")
  107.  
  108.     }
  109.  
  110.    
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement