Use the function <?php live_preview() ?> to display the live preview in a different location. Author: Jeff Minard & Iacovos Constantinou Version: 1.7 */ // Customize this string if you want to modify the preview output // %1 - author's name (as hyperlink if available) // %2 - comment text $previewFormat = "
Preview:
%1:
%2
"; // If you have changed the ID's on your form field elements // You should make them match here $commentFrom_commentID = 'comment'; $commentFrom_authorID = 'author'; $commentFrom_urlID = 'url'; // You shouldn't need to edit anything else. $livePreviewDivAdded == false; if( stristr($_SERVER['REQUEST_URI'], 'commentPreview.js') ) { header('Content-type: text/javascript'); ?> function wptexturize(text) { text = ' '+text+' '; var next = true; var output = ''; var prev = 0; var length = text.length; while ( prev < length ) { var index = text.indexOf('<', prev); if ( index > -1 ) { if ( index == prev ) { index = text.indexOf('>', prev); } index++; } else { index = length; } var s = text.substring(prev, index); prev = index; if ( s.substr(0,1) != '<' && next == true ) { s = s.replace(/---/g, '—'); s = s.replace(/--/g, '–'); s = s.replace(/\.{3}/g, '…'); s = s.replace(/``/g, '“'); s = s.replace(/'s/g, '’s'); s = s.replace(/'(\d\d(?:’|')?s)/g, '’$1'); s = s.replace(/([\s"])'/g, '$1‘'); s = s.replace(/(\d+)"/g, '$1″'); s = s.replace(/(\d+)'/g, '$1′'); s = s.replace(/([^\s])'([^'\s])/g, '$1’$2'); s = s.replace(/(\s)"([^\s])/g, '$1“$2'); s = s.replace(/"(\s)/g, '”$1'); s = s.replace(/'(\s|.)/g, '’$1'); s = s.replace(/\(tm\)/ig, '™'); s = s.replace(/\(c\)/ig, '©'); s = s.replace(/\(r\)/ig, '®'); s = s.replace(/''/g, '”'); s = s.replace(/(\d+)x(\d+)/g, '$1×$2'); } else if ( s.substr(0,5) == ']*>)/g, '\n$1');
p = p.replace(/(<\/blockquote[^>]*>)/g, '$1\n');
p = p.replace(/\r\n/g, '\n');
p = p.replace(/\r/g, '\n');
p = p.replace(/\n\n+/g, '\n\n');
p = p.replace(/\n?(.+?)(?:\n\s*\n)/g, '$1
');
p = p.replace(/\s*?<\/p>/g, '');
p = p.replace(/
\s*(<\/?blockquote[^>]*>)\s*<\/p>/g, '$1');
p = p.replace(/
]*)>/ig, '');
p = p.replace(/<\/blockquote><\/p>/ig, '
');
p = p.replace(/\s*
]*)>/ig, '');
p = p.replace(/<\/blockquote>\s*<\/p>/ig, '
');
p = p.replace(/\s*\n\s*/g, '
');
return p;
}
function updateLivePreview() {
var cmntArea = document.getElementById('');
var pnmeArea = document.getElementById('');
var purlArea = document.getElementById('');
if( cmntArea )
var cmnt = wpautop(wptexturize(cmntArea.value));
if( pnmeArea )
var pnme = pnmeArea.value;
if( purlArea )
var purl = purlArea.value;
if(purl && pnme) {
var name = '' + pnme + ' says';
} else if(!purl && pnme) {
var name = pnme + ' says';
} else if(purl && !pnme) {
var name = 'You say';
} else {
var name = "You say";
}
document.getElementById('commentPreview').innerHTML =
}
function initLivePreview() {
if(!document.getElementById)
return false;
var cmntArea = document.getElementById('');
var pnmeArea = document.getElementById('');
var purlArea = document.getElementById('');
if ( cmntArea )
cmntArea.onkeyup = updateLivePreview;
if ( pnmeArea )
pnmeArea.onkeyup = updateLivePreview;
if ( purlArea )
purlArea.onkeyup = updateLivePreview;
}
//========================================================
// Event Listener by Scott Andrew - http://scottandrew.com
// edited by Mark Wubben, is now set to false
//========================================================
function addEvent(obj, evType, fn){
if(obj.addEventListener){
obj.addEventListener(evType, fn, false);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent('on'+evType, fn);
return r;
} else {
return false;
}
}
addEvent(window, "load", initLivePreview);
'.$after;
$livePreviewDivAdded = true;
}
}
function lcp_add_preview_div($post_id) {
global $commentFrom_commentID, $livePreviewDivAdded;
if($livePreviewDivAdded == false) {
echo '';
$livePreviewDivAdded = true;
}
return $post_id;
}
function lcp_add_js($ret) {
echo('');
return $ret;
}
add_action('comment_form', 'lcp_add_preview_div');
add_action('wp_head', 'lcp_add_js');
?>