Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is just a function to call the quote into TinyMCE
- 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;}}
- //This is the main function
- function quote(postid, author, commentarea, commentID, textile, mce) {
- try {
- // If you don't want quotes begin with "<author>:", uncomment the next line
- //author = null;
- textile = false; // comment this line out, if you want quote comments to use bq.'s instead of use blockquote tags.
- // begin code
- var posttext = '';
- if (window.getSelection){
- posttext = window.getSelection();
- }
- else if (document.getSelection){
- posttext = document.getSelection();
- }
- else if (document.selection){
- posttext = document.selection.createRange().text;
- }
- else {
- return true;
- }
- if (posttext=='') { // quoting entire comment
- // quoteing the entire thing
- var selection = false;
- // quote entire comment as html
- var q = "q-"+commentID.split("div-comment-")[1];
- var posttext = document.getElementById(q).innerHTML;
- // remove nested divs
- var posttext = posttext.replace(/<div(.*?)>((.|\n)*?)(<\/div>)/ig, "");
- // remove nested blockquotes
- var posttext = posttext.replace(/<blockquote(.*?)>((.|\n)*?)(<\/blockquote>)/ig, "");
- var posttext = posttext.replace(/<blockquote(.*?)>((.|\n)*?)(<\/blockquote>)/ig, "");
- /*
- var posttext = posttext.replace(/<blockquote>[^>]*<\/\s*blockquote>/g, "");
- var posttext = posttext.replace(/<blockquote>[^>]*<\/\s*blockquote>/g, "");
- */
- // do basic cleanups
- var posttext = posttext.replace(/ /g, "");
- var posttext = posttext.replace(/<p>/g, "\n");
- var posttext = posttext.replace(/<\/\s*p>/g, "");
- var posttext = posttext.replace(/<br>/g, "")
- // remove superfluous linebreaks
- var posttext = posttext.replace(/\s\s/gm, "");
- // remove nested spans
- var posttext = posttext.replace(/<span(.*?)>((.|\n)*?)(<\/span>)/ig, "");
- // remove nested blockquotes
- while (posttext != (posttext = posttext.replace(/<blockquote>[^>]*<\/\s*blockquote>/g, "")));
- }
- // build quote
- if (textile && selection != false) {
- if (author) {
- var quote='\n\nbq. *'+author+'*: '+posttext+'\n\n';
- } else {
- var quote='\n\nbq. '+posttext+'\n\n';
- }
- } else {
- if (author) {
- 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';
- } else {
- var quote='\n\n<blockquote cite="comment-'+postid+'">\n\n'+posttext+'\n</blockquote>\n\n';
- }
- }
- // send quoted content
- if (mce == true) { // TinyMCE detected
- //addQuoteMCE(post_content,quote);
- insertHTML(quote);
- } else { // No TinyMCE detected
- var post_content=document.getElementById(commentarea);
- addQuote(post_content,quote);
- }
- return false;
- } catch (e) {
- alert("Something went wrong! Perhaps your theme is incompatible?")
- }
- }
- function addQuote(post_content,quote){
- /*
- Derived from Alex King's JS Quicktags code (http://www.alexking.org/)
- Released under LGPL license
- */
- // IE support
- if (document.selection) {
- post_content.focus();
- sel = document.selection.createRange();
- sel.text = quote;
- post_content.focus();
- }
- // Mozilla support
- else if (post_content.selectionStart || post_content.selectionStart == '0') {
- var startPos = post_content.selectionStart;
- var endPos = post_content.selectionEnd;
- var cursorPos = endPos;
- var scrollTop = post_content.scrollTop;
- if (startPos != endPos) {
- post_.value = post_content.value.substring(0, startPos)
- + quote
- + post_content.value.substring(endPos, post_content.value.length);
- cursorPos = startPos + quote.length
- }
- else {
- post_content.value = post_content.value.substring(0, startPos)
- + quote
- + post_content.value.substring(endPos, post_content.value.length);
- cursorPos = startPos + quote.length;
- }
- post_content.focus();
- post_content.selectionStart = cursorPos;
- post_content.selectionEnd = cursorPos;
- post_content.scrollTop = scrollTop;
- }
- else {
- post_content.value += quote;
- }
- // If Live Preview Plugin is installed, refresh preview
- try {
- ReloadTextDiv();
- }
- catch ( e ) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement