jQuery(document).ready(function () { //Insert the new preview link. //id for the preview action div is - preview-action var previewdiv = jQuery('#preview-action'); //Only do preview logic if you have a valid preview link. if(previewdiv && previewdiv.length != 0) { var additionalbuttonhtml = previewdiv.html().replace("post-preview","post-preview2"); additionalbuttonhtml = additionalbuttonhtml.replace("Preview Changes","Active Preview"); //Chop out any text no associated with the anchor tag. additionalbuttonhtml = additionalbuttonhtml.substring(additionalbuttonhtml.toLowerCase().indexOf('')+4); var actiondiv = jQuery('#minor-publishing-actions'); actiondiv.append("
"+additionalbuttonhtml+"
"); //Because tinyMCE doesn't get initialized all the way when they have the //html editor selected on first page visit. SO lets just hook into the // visual link on the page and initialize if nothing was initialized yet. var previeweditorlink = jQuery('#edButtonPreview'); previeweditorlink.click(function (e) { switchEditors.go('content', 'tinymce'); if(!window.tinyalreadyinit){ //Hook a listener onto the iframe for changes and send the changes to the content div for the post which wordpress puts into the page. //We need to hook into onKeyUp to catch key strokes. tinyMCE.activeEditor.onKeyUp.add(function (ed, l) { var jcommunicator = jQuery(window.communicator.document); var post = jcommunicator.find('.entry'); post.html(ed.getBody().innerHTML); }); //We need to hook into onNodeChange to get changes that aren't necessarily related to key strokes (like changing text color etc) tinyMCE.activeEditor.onNodeChange.add(function (ed, l) { var jcommunicator = jQuery(window.communicator.document); var post = jcommunicator.find('.entry'); post.html(ed.getBody().innerHTML); }); window.tinyalreadyinit = true; } }); //Hook in the onclick to do an open but keep a reference to the window that was opened for update. var activelink = jQuery('#post-preview2'); activelink.click(function (e) { e.preventDefault(); //Don't allow this functionality in IE. It just doesn't work well there. if(jQuery.browser.msie){ //For now do an old school alert. alert("Active Preview does not support IE browsers, to use functionality please use with another browser"); } else { window.communicator = window.open(this.href,'activepreview','menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes'); jQuery('#content').keyup(function() { var jcommunicator = jQuery(window.communicator.document); var post = jcommunicator.find('.entry'); post.html(this.value); }); if(!window.tinyalreadyinit && tinyMCE.activeEditor){ //Hook a listener onto the iframe for changes and send the changes to the content div for the post which wordpress puts into the page. //We need to hook into onKeyUp to catch key strokes. tinyMCE.activeEditor.onKeyUp.add(function (ed, l) { var jcommunicator = jQuery(window.communicator.document); var post = jcommunicator.find('.entry'); post.html(ed.getBody().innerHTML); }); //We need to hook into onNodeChange to get changes that aren't necessarily related to key strokes (like changing text color etc) tinyMCE.activeEditor.onNodeChange.add(function (ed, l) { var jcommunicator = jQuery(window.communicator.document); var post = jcommunicator.find('.entry'); post.html(ed.getBody().innerHTML); }); window.tinyalreadyinit = true; } } return false; }); } });