| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Plugin Name: Live Preview: Admin Panel, Comments
|
|---|
| 4 | Plugin URI: http://chrisjdavis.org/index/category/wp-hacks/
|
|---|
| 5 | Description: A plugin that creates a live preview for you comments and post/edit forms.
|
|---|
| 6 | Version: .65 RC1
|
|---|
| 7 | Author: Chris J. Davis
|
|---|
| 8 | Author URI: http://chrisjdavis.org/
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /*
|
|---|
| 12 | Just a quick note, the first two functions control how the preview div is refreshed. The first function previewScript(); is for your post/edit files in /wp-admin/; this function does not understand carriage returns, only <p></p> tags. That is how I write my entries. The second function commentScript(); is for your comment page so it DOES understand carriage returns, not many people put in <p></p>'s and such in a comment box. So if you are one of those non-tagging while blogging people, call the commentScript(); function for your post/edit page; you will be much happier. One quick caveat, if you are editing an entry, you must make some change in the content container before the preview will be generated, since it uses onkeyup().
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 | //-- Call this function in your admin-header.php file
|
|---|
| 17 | function previewScript() {
|
|---|
| 18 | $javascript= "<script type=\"text/javascript\">\n<!--\nfunction ReloadTextDiv()\n{\nvar NewText = document.getElementById(\"DynamicText\").value;\nsplitText = NewText.split(/\/n/).join(\"<br />\");\nvar DivElement = document.getElementById(\"TextDisplay\");\nDivElement.innerHTML = splitText;\n}\n//-->\n</script>\n";
|
|---|
| 19 | echo $javascript;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | //-- You need to add onkeyup="ReloadTextDiv();" to the form content textbox in both of the following pages:
|
|---|
| 23 |
|
|---|
| 24 | //-- Call this function in your root page (usually index.php)
|
|---|
| 25 | function commentScript() {
|
|---|
| 26 | $javascript = "<script type=\"text/javascript\">\n<!--\nfunction ReloadTextDiv()\n{\nvar NewText = document.getElementById(\"DynamicText\").value;\nsplitText = NewText.split(/\\n/).join(\"<br />\");\nvar DivElement = document.getElementById(\"TextDisplay\");\nDivElement.innerHTML = splitText;\n}\n//-->\n</script>\n";
|
|---|
| 27 | echo $javascript;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | //-- Call this function in your edit-form.php or your edit-form-advanced.php file directly under the content <textarea>, around line 112
|
|---|
| 31 | function preview_Div() {
|
|---|
| 32 | $previewdiv = "<fieldset id=\"previewdiv\">\n<legend><a href=\"http://wordpress.org/docs/reference/post/#post\" title=\"Help with post field\">\nPreview</a></legend>\n<p id=\"TextDisplay\"></p>\n</fieldset>";
|
|---|
| 33 | echo $previewdiv;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | //-- Call this function in your wp-comments.php or wp-comments-popup.php file where you want your preview to show up.
|
|---|
| 37 | function comments_Div() {
|
|---|
| 38 | $commentdiv = "<p id=\"TextDisplay\"></p>";
|
|---|
| 39 | echo $commentdiv;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | //-- And that is it, just insert what you want where, and then activate this plugin in the plugin control center.
|
|---|
| 43 |
|
|---|
| 44 | add_action('wp_head','commentScript');
|
|---|
| 45 | ?> |
|---|