Advertisement
Guest User

anandasama

a guest
Jul 26th, 2009
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This is just a function to call the quote into TinyMCE
  2. function insertHTML(html) {tinyMCE.execCommand("mceInsertContent",false, html);}tinyMCE.init({mode : "advanced",elements : "post_content",theme : "advanced",theme_advanced_buttons1 : "blockquote,bold,italic,underline,bullist,indent,undo,redo,link,unlink",theme_advanced_buttons2 : "",theme_advanced_buttons3 : "",theme_advanced_toolbar_location : "top",theme_advanced_toolbar_align : "left",theme_advanced_statusbar_location : "none",theme_advanced_resizing : false,theme_advanced_resize_horizontal : false,force_p_newlines : false,force_br_newlines : true,forced_root_block : "",gecko_spellcheck : true,content_css : "http://matsuri.moai.se/my-templates/scoun/style.css",directionality : "ltr",save_callback : "brstonewline",entity_encoding : "raw",plugins : "media",extended_valid_elements : "a[name|href|title],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],blockquote[cite],div[],img[alt|src],cite[],br[]",language : ""});var subBtn = document.getElementById("submit");if (subBtn != null) {subBtn.onclick=function() {var inst = tinyMCE.getInstanceById("post_content");document.getElementById("post_content").value = inst.getContent();document.getElementById("postform").submit();return false;}}
  3. //This is the main function
  4. function quote(postid, author, commentarea, commentID, textile, mce) {
  5.    
  6.     try {
  7.        
  8.         // If you don't want quotes begin with "<author>:", uncomment the next line
  9.         //author = null;
  10.         textile = false;    // comment this line out, if you want quote comments to use bq.'s instead of use blockquote tags.
  11.    
  12.         // begin code
  13.         var posttext = '';
  14.         if (window.getSelection){
  15.             posttext = window.getSelection();
  16.         }
  17.         else if (document.getSelection){
  18.             posttext = document.getSelection();
  19.         }
  20.         else if (document.selection){
  21.             posttext = document.selection.createRange().text;
  22.         }
  23.         else {
  24.             return true;
  25.         }
  26.        
  27.         if (posttext=='') {     // quoting entire comment
  28.        
  29.             // quoteing the entire thing
  30.             var selection = false;
  31.        
  32.             // quote entire comment as html
  33.             var q = "q-"+commentID.split("div-comment-")[1];
  34.             var posttext = document.getElementById(q).innerHTML;
  35.            
  36.            
  37.             // remove nested divs
  38.             var posttext = posttext.replace(/<div(.*?)>((.|\n)*?)(<\/div>)/ig, "");
  39.  
  40.             // remove nested blockquotes
  41.             var posttext = posttext.replace(/<blockquote(.*?)>((.|\n)*?)(<\/blockquote>)/ig, "");
  42.             var posttext = posttext.replace(/<blockquote(.*?)>((.|\n)*?)(<\/blockquote>)/ig, "");
  43.  
  44.             /*
  45.             var posttext = posttext.replace(/<blockquote>[^>]*<\/\s*blockquote>/g, "");
  46.             var posttext = posttext.replace(/<blockquote>[^>]*<\/\s*blockquote>/g, "");
  47.             */
  48.  
  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(/<br>/g, "")
  55.            
  56.            
  57.             // remove superfluous linebreaks
  58.             var posttext = posttext.replace(/\s\s/gm, "");
  59.    
  60.             // remove nested spans
  61.             var posttext = posttext.replace(/<span(.*?)>((.|\n)*?)(<\/span>)/ig, "");
  62.  
  63.             // remove nested blockquotes
  64.             while (posttext != (posttext = posttext.replace(/<blockquote>[^>]*<\/\s*blockquote>/g, "")));
  65.            
  66.         }
  67.            
  68.         // build quote
  69.         if (textile && selection != false) {
  70.             if (author) {
  71.                 var quote='\n\nbq. *'+author+'*: '+posttext+'\n\n';
  72.             } else {
  73.                 var quote='\n\nbq. '+posttext+'\n\n';
  74.             }
  75.         } else {
  76.             if (author) {
  77.                 var quote='\n\n<blockquote cite="comment-'+postid+'">\n\n<span><a href="#comment-'+postid+'">'+author+'</a> said:</span>\n<br /> '+posttext+'\n</blockquote>\n\n';
  78.             } else {
  79.                 var quote='\n\n<blockquote cite="comment-'+postid+'">\n\n'+posttext+'\n</blockquote>\n\n';
  80.             }
  81.         }
  82.        
  83.        
  84.  
  85.        
  86.         // send quoted content
  87.         if (mce == true) {      // TinyMCE detected
  88.        
  89.             //addQuoteMCE(post_content,quote);
  90.             insertHTML(quote);
  91.            
  92.         } else {                // No TinyMCE detected
  93.  
  94.             var post_content=document.getElementById(commentarea);
  95.             addQuote(post_content,quote);
  96.            
  97.         }
  98.            
  99.         return false;
  100.        
  101.     } catch (e) {
  102.         alert("Something went wrong! Perhaps your theme is incompatible?")
  103.     }
  104.    
  105. }
  106.  
  107. function addQuote(post_content,quote){
  108.     /*
  109.    
  110.         Derived from Alex King's JS Quicktags code (http://www.alexking.org/)
  111.         Released under LGPL license
  112.        
  113.     */ 
  114.    
  115.     // IE support
  116.     if (document.selection) {
  117.         post_content.focus();
  118.         sel = document.selection.createRange();
  119.         sel.text = quote;
  120.         post_content.focus();
  121.     }
  122.     // Mozilla support
  123.     else if (post_content.selectionStart || post_content.selectionStart == '0') {
  124.         var startPos = post_content.selectionStart;
  125.         var endPos = post_content.selectionEnd;
  126.         var cursorPos = endPos;
  127.         var scrollTop = post_content.scrollTop;
  128.         if (startPos != endPos) {
  129.             post_.value = post_content.value.substring(0, startPos)
  130.                           + quote
  131.                           + post_content.value.substring(endPos, post_content.value.length);
  132.             cursorPos = startPos + quote.length
  133.         }
  134.         else {
  135.             post_content.value = post_content.value.substring(0, startPos)
  136.                               + quote
  137.                               + post_content.value.substring(endPos, post_content.value.length);
  138.             cursorPos = startPos + quote.length;
  139.         }
  140.         post_content.focus();
  141.         post_content.selectionStart = cursorPos;
  142.         post_content.selectionEnd = cursorPos;
  143.         post_content.scrollTop = scrollTop;
  144.     }
  145.     else {
  146.         post_content.value += quote;
  147.     }
  148.  
  149.     // If Live Preview Plugin is installed, refresh preview
  150.     try {
  151.         ReloadTextDiv();
  152.     }
  153.     catch ( e ) {
  154.     }
  155.    
  156. }
  157.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement