[pLog-svn] r1549 - plog/trunk/js/ui

oscar at devel.plogworld.net oscar at devel.plogworld.net
Fri Mar 18 19:22:06 GMT 2005


Author: oscar
Date: 2005-03-18 19:22:06 +0000 (Fri, 18 Mar 2005)
New Revision: 1549

Modified:
   plog/trunk/js/ui/common.js
Log:
fixed issue 339 (http://bugs.plogworld.net/view.php?id=339)

Modified: plog/trunk/js/ui/common.js
===================================================================
--- plog/trunk/js/ui/common.js	2005-03-18 16:54:03 UTC (rev 1548)
+++ plog/trunk/js/ui/common.js	2005-03-18 19:22:06 UTC (rev 1549)
@@ -274,7 +274,7 @@
 	previewPost( "editPost" );
 }
 	
-function previewPost( formId )
+function previewPost_old( formId )
 {
 	form = document.getElementById( formId );
 	
@@ -289,6 +289,67 @@
 	return true;
 }
 
+// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode( )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = document.URLForm.F1.value;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	document.URLForm.F2.value = encoded;
	return false;
};
+
+function previewPost( formId )
+{
+    form = document.getElementById( formId )
+    
+    if( submitNewPost( form )) {
+        preview = window.open( 'about:blank', '', 'scrollbars=yes,resizable=yes,toolbar=no' );
+        
+        // write the contents as a form with hidden fields
+        preview.document.write( '<html><body><div style="display:none">' +
+                                '<form name="previewForm" method="post" action="admin.php">' +
+                                '<input type="hidden" name="op" value="previewPost">' );
+        // post text, slug and topic... if we put everything in textareas, we avoid the need to escape things
+        // also we should keep in mind whether we're using htmlarea or not, since then we should use a different method
+        // to get the value out of the textareas
+        if( htmlAreaEnabled ) {
+        	postText = postTextEditor.getHTML();
+        	postExtendedText = postExtendedTextEditor.getHTML();
+		}
+        else {
+        	postText = form.postText.value;
+        	postExtendedText = form.postExtendedText.value;
+    	}
+        preview.document.write( '<textarea name="postText">' + postText + '</textarea>' +
+                                '<textarea name="postTopic">' + form.postTopic.value + '</textarea>' +
+                                '<textarea name="postExtendedText">' + postExtendedText + '</textarea>' +
+                                '<input type="hidden" name="postSlug" value="' + form.postSlug.value + '" />' );
+        // post date and time
+        preview.document.write( '<input type="hidden" name="postDateTime" value="' + form.postDateTime.value + '" /> ' );
+        
+        // article categories
+        preview.document.write( '<select name="postCategories[]" multiple="multiple">' );
+        for( var i = 0; i < form.postCategories.options.length; i++ ) {
+            if( form.postCategories.options[i].selected )
+                preview.document.write( '<option selected="selected" value="' + form.postCategories.options[i].value + '">test</option>' );
+        }
+        preview.document.write( '</select>' );        
+        // custom fields -- since we don't know their exact names and amount, we need to loop through the whole form to find them!        
+        for(var i = 0; i < form.elements.length; i++ ) {
+            var itemName = form.elements[i].name;
+            if( itemName ) {
+                if( itemName.substr(0,11) == "customField" ) {
+                    if( form.elements[i].type == "checkbox" ) 
+                        preview.document.write( '<input type="hidden" name="' + itemName + '" value="' + form.elements[i].value + '" />' );
+                    else
+                        preview.document.write( '<textarea name="' + itemName + '">' + form.elements[i].value + '</textarea>' );
+                }
+            }
+        }
+                                
+        // footer
+        preview.document.write( '</form></div>' +
+                                '<b>Loading preview, please wait...</b>' +
+                                '</body></html>' );
+    
+        // and submit the form
+        preview.document.previewForm.submit();        
+    }
+}
+
 /*****
  *
  * functions for dealing with the "edit blog" screen




More information about the pLog-svn mailing list