[pLog-svn] r4475 - plog/trunk/js/editor

oscar at devel.lifetype.net oscar at devel.lifetype.net
Wed Jan 3 22:06:20 GMT 2007


Author: oscar
Date: 2007-01-03 22:06:19 +0000 (Wed, 03 Jan 2007)
New Revision: 4475

Modified:
   plog/trunk/js/editor/plogeditor.js
Log:
Support for adding/removing the "more" tag in the post edit window, and many thanks to Jon and his work in the tinymce plugin that allowed me to copy most of the code for the logic :)

Modified: plog/trunk/js/editor/plogeditor.js
===================================================================
--- plog/trunk/js/editor/plogeditor.js	2007-01-03 21:16:22 UTC (rev 4474)
+++ plog/trunk/js/editor/plogeditor.js	2007-01-03 22:06:19 UTC (rev 4475)
@@ -334,6 +334,63 @@
 }
 
 /**
+ * special button that adds/removes the "[@more@]" separator
+ *
+ * @param id
+ * @param display
+ * @param icon
+ */
+edButtonMore = function(id, display, icon) 
+{
+	//
+	// strange javascript thingies used for object inheritance...
+	//
+	this.prototype = new edButton(id, display, '', '', icon, -1 );
+	this.prototype.constructor = edButton;
+	this.superclass = edButton;
+	
+	this.superclass(id, display, '', '', icon, -1 );
+	
+	/**
+	 * @private
+	 */
+	this._getMoreTag = function()
+	{
+		return( "[@more@]" );
+	}
+	
+	this.execute = function( txtId, param ) 
+	{
+		var txtArea = document.getElementById( txtId );
+		var content = txtArea.value;
+	    var bFound = 0;
+		var startPos = 0;
+		var returnValue = '';
+	    
+		// Parse all img tags and remove any 'more' tags
+		while((startPos = content.indexOf(this._getMoreTag(), startPos)) != -1) {
+	       var contentAfter = content.substring(startPos + this._getMoreTag().length);
+	       content = content.substring(0, startPos) + contentAfter;
+	       startPos++;
+	       bFound = 1;
+		}
+		
+	    if(bFound ) {
+			// the tag is already there and should be removed, we can use a regular expression
+			// to easily remove it
+			returnValue = '';
+			txtArea.value = content;
+	     }
+	     else {
+			// the tag is not there and can be safely added
+			returnValue = '\n' + this._getMoreTag() + '\n'; 
+	    }
+	
+		return( returnValue );
+	}
+}
+
+/**
  * special button that only adds an image
  *
  * @param id
@@ -563,6 +620,7 @@
   this.toolBar['5_but_a']  = new edButtonLink( '5_but_a', 'anchor', 'ed_link.gif' );
   this.toolBar['6_but_img']= new edButtonImage( '6_but_img', 'image', 'ed_image.gif' );
   this.toolBar['7_but_res']= new edButtonResource ('7_but_res', 'resource', 'ed_resource.gif' );
+  this.toolBar['8_but_more']= new edButtonMore ('8_but_more', 'more', 'ed_more.gif' );
   
   /**
    * returns whether our browser supports the features that we are going



More information about the pLog-svn mailing list