[pLog-svn] r4469 - plog/trunk/js/tinymce/plugins/more

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Wed Jan 3 02:37:25 GMT 2007


Author: jondaley
Date: 2007-01-03 02:37:24 +0000 (Wed, 03 Jan 2007)
New Revision: 4469

Modified:
   plog/trunk/js/tinymce/plugins/more/editor_plugin.js
Log:
removed duplicate code.  Added LifeTypeMoreTag constant instead of hard-coded values and string lengths.  Only one 'more' tag is allowed - currently works on switch-to-html mode and save-post, ie. not immediately, still working on that part.

Modified: plog/trunk/js/tinymce/plugins/more/editor_plugin.js
===================================================================
--- plog/trunk/js/tinymce/plugins/more/editor_plugin.js	2007-01-02 22:10:41 UTC (rev 4468)
+++ plog/trunk/js/tinymce/plugins/more/editor_plugin.js	2007-01-03 02:37:24 UTC (rev 4469)
@@ -78,15 +78,15 @@
         return attributes;
     },
 
+    _getAttrib : function(elm, name) {
+       return elm.getAttribute(name) ? elm.getAttribute(name) : "";
+    },
+
     execCommand : function(editor_id, element, command, user_interface, value){
         var inst = tinyMCE.getInstanceById(editor_id);
         var focusElm = inst.getFocusElement();
         var doc = inst.getDoc();
 
-        function getAttrib(elm, name) {
-            return elm.getAttribute(name) ? elm.getAttribute(name) : "";
-        }
-
             // Handle commands
         switch (command) {
 			case "mcemoremore":
@@ -96,7 +96,7 @@
 
 				// Is selection a image
             if (focusElm != null && focusElm.nodeName.toLowerCase() == "img"){
-                flag = getAttrib(focusElm, 'class');
+                flag = _getAttrib(focusElm, 'class');
 	
                 if (flag != 'mce_plugin_more_more') // Not a more
                     return true;
@@ -120,46 +120,59 @@
     },
 
     cleanup : function(type, content) {
+        var LifeTypeMoreTag = "[@more@]";
+
         switch (type) {
                 // move from html editor to wysiwyg editor
-            case "insert_to_editor":
+          case "insert_to_editor":
+            var bFound = 0;
 			var startPos = 0;
 			var altMore = tinyMCE.getLang('lang_more_more_alt');
 
-                // Parse all [@more@] tags and replace them with images
-			while ((startPos = content.indexOf('[@more@]', startPos)) != -1) {
+                // Parse all tags and replace them with images
+			while((startPos=content.indexOf(LifeTypeMoreTag,startPos)) != -1)
+            {
+              var contentAfter = content.substring(startPos + 
+                                                   LifeTypeMoreTag.length);
+              content = content.substring(0, startPos);
+              if(!bFound){
                     // Insert image
-				var contentAfter = content.substring(startPos + 8);
-				content = content.substring(0, startPos);
 				content += '<img src="' + (tinyMCE.getParam("theme_href") + 
                                            "/images/spacer.gif") + '" ';
 				content += ' width="100%" height="10px" ';
 				content += 'alt="'+altMore+'" title="'+altMore+'" ';
                 content += 'class="mce_plugin_more_more" />';
-				content += contentAfter;
-
-				startPos++;
+              }
+              content += contentAfter;
+              startPos++;
+              bFound = 1;
 			}
 			break;
 
                 // move from wysiwyg editor to html editor
-            case "get_from_editor":
-                // Parse all img tags and replace the "more" image with [@more@]
-			var startPos = -1;
-			while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
+          case "get_from_editor":
+            var bFound = 0;
+              // Parse all img tags and replace the
+              // first "more" image with tag
+            var startPos = -1;
+            while((startPos = content.indexOf('<img', startPos+1)) != -1)
+            {
 				var endPos = content.indexOf('/>', startPos);
 				var attribs = this._parseAttributes(
                     content.substring(startPos + 4, endPos));
 
 				if (attribs['class'] == "mce_plugin_more_more") {
-					endPos += 2;
+                    endPos += 2;
 	
-					var embedHTML = '[@more@]';
-	
                         // Insert embed/object chunk
 					chunkBefore = content.substring(0, startPos);
 					chunkAfter = content.substring(endPos);
-					content = chunkBefore + embedHTML + chunkAfter;
+
+                    content = chunkBefore;
+					if(!bFound)
+                      content += LifeTypeMoreTag;
+                    content += chunkAfter;
+                    bFound = 1;
 				}
 			}
 			break;
@@ -170,9 +183,6 @@
     },
 
     handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
-        function getAttrib(elm, name) {
-            return elm.getAttribute(name) ? elm.getAttribute(name) : "";
-        }
 
         tinyMCE.switchClass(editor_id + '_more_more', 'mceButtonNormal');
 
@@ -181,7 +191,7 @@
 
         do {
             if (node.nodeName.toLowerCase() == "img" && 
-                getAttrib(node, 'class').indexOf('mce_plugin_more_more') == 0)
+                _getAttrib(node, 'class').indexOf('mce_plugin_more_more') == 0)
             {
                 tinyMCE.switchClass(editor_id + '_more_more', 
                                     'mceButtonSelected');



More information about the pLog-svn mailing list