[pLog-svn] r4316 - in plog/branches/lifetype-1.1.3/js/tinymce/plugins: . more more/images more/langs

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Thu Nov 16 14:12:59 GMT 2006


Author: jondaley
Date: 2006-11-16 14:12:59 +0000 (Thu, 16 Nov 2006)
New Revision: 4316

Added:
   plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/
   plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/editor_plugin.js
   plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/images/
   plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/images/help.gif
   plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/images/more.gif
   plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/images/more_bug.gif
   plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/langs/
   plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/langs/en.js
   plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/more.css
Log:
'more' plugin ported from wordpress.  works, but currently has the added 'feature' of messing up the " et al.  Feel free to fix it if you can get it done before me...

Added: plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/editor_plugin.js
===================================================================
--- plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/editor_plugin.js	2006-11-16 14:09:04 UTC (rev 4315)
+++ plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/editor_plugin.js	2006-11-16 14:12:59 UTC (rev 4316)
@@ -0,0 +1,224 @@
+/* Import plugin specific language pack */
+tinyMCE.importPluginLanguagePack('more');
+
+var TinyMCE_MorePlugin = {
+	getInfo : function() {
+		return {
+			longname : 'More',
+			author : 'Jon Daley (based on the WordPress plugin)',
+			authorurl : 'http://jon.limedaley.com',
+			infourl : 'N/A',
+			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
+		};
+	},
+
+    initInstance : function(inst) {
+        if (!tinyMCE.settings['more_skip_plugin_css']){
+            tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL +  
+                              "/plugins/more/more.css");
+        }
+    },
+
+    getControlHTML : function(control_name) {
+        switch (control_name) {
+            case "more":
+            return tinyMCE.getButtonHTML(control_name, 
+                                         'lang_more_more_button', 
+                                         '{$pluginurl}/images/more.gif', 
+                                         'mcemoremore');
+        }
+
+        return '';
+    },
+
+    _parseAttributes : function(attribute_string) {
+        var attributeName = "";
+        var attributeValue = "";
+        var withInName;
+        var withInValue;
+        var attributes = new Array();
+        var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
+
+        if (attribute_string == null || attribute_string.length < 2)
+		return null;
+
+        withInName = withInValue = false;
+
+        for (var i=0; i<attribute_string.length; i++) {
+            var chr = attribute_string.charAt(i);
+
+            if ((chr == '"' || chr == "'") && !withInValue)
+                withInValue = true;
+            else if ((chr == '"' || chr == "'") && withInValue) {
+                withInValue = false;
+
+                var pos = attributeName.lastIndexOf(' ');
+                if (pos != -1)
+                    attributeName = attributeName.substring(pos+1);
+
+                attributes[attributeName.toLowerCase()] = 
+                    attributeValue.substring(1).toLowerCase();
+
+                attributeName = "";
+                attributeValue = "";
+            } else if (!whiteSpaceRegExp.test(chr) && 
+                       !withInName && !withInValue)
+                withInName = true;
+
+            if (chr == '=' && withInName)
+                withInName = false;
+
+            if (withInName)
+                attributeName += chr;
+
+            if (withInValue)
+                attributeValue += chr;
+        }
+
+        return attributes;
+    },
+
+    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":
+            var flag = "";
+            var template = new Array();
+            var altMore = tinyMCE.getLang('lang_more_more_alt');
+
+				// Is selection a image
+            if (focusElm != null && focusElm.nodeName.toLowerCase() == "img"){
+                flag = getAttrib(focusElm, 'class');
+	
+                if (flag != 'mce_plugin_more_more') // Not a more
+                    return true;
+	
+                action = "update";
+            }
+	
+            html = ''
+            + '<img src="' + (tinyMCE.getParam("theme_href") + 
+                              "/images/spacer.gif") + '" '
+            + ' width="100%" height="10px" '
+            + 'alt="'+altMore+'" title="'+altMore+'" '
+            + 'class="mce_plugin_more_more" name="mce_plugin_more_more" />';
+            tinyMCE.execCommand("mceInsertContent",true,html);
+            tinyMCE.selectedInstance.repaint();
+            return true;
+        }
+
+            // Pass to next handler in chain
+        return false;
+    },
+
+    cleanup : function(type, content) {
+        switch (type) {
+	
+            case "insert_to_editor":
+			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) {
+                    // Insert image
+				var contentAfter = content.substring(startPos + 11);
+				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++;
+			}
+
+                // It's supposed to be WYSIWYG, right?
+			content = content.replace(new RegExp('&', 'g'), '&amp;');
+
+			break;
+
+            case "get_from_editor":
+                // Parse all img tags and replace them with [@more@]
+			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;
+	
+					var embedHTML = '[@more@]';
+	
+                        // Insert embed/object chunk
+					chunkBefore = content.substring(0, startPos);
+					chunkAfter = content.substring(endPos);
+					content = chunkBefore + embedHTML + chunkAfter;
+				}
+			}
+
+                // If it says & in the WYSIWYG editor, 
+                // it should say &amp; in the html.
+			content = content.replace(new RegExp('&', 'g'), '&amp;');
+			content = content.replace(new RegExp('&amp;nbsp;', 'g'), '&nbsp;');
+
+                // Remove anonymous, empty paragraphs.
+			content = content.replace(new RegExp('<p>(\\s|&nbsp;)*</p>', 'mg'), '');
+
+                // Handle table badness.
+			content = content.replace(new RegExp('<(table( [^>]*)?)>.*?<((tr|thead)( [^>]*)?)>', 'mg'), '<$1><$3>');
+			content = content.replace(new RegExp('<(tr|thead|tfoot)>.*?<((td|th)( [^>]*)?)>', 'mg'), '<$1><$2>');
+			content = content.replace(new RegExp('</(td|th)>.*?<(td( [^>]*)?|th( [^>]*)?|/tr|/thead|/tfoot)>', 'mg'), '</$1><$2>');
+			content = content.replace(new RegExp('</tr>.*?<(tr|/table)>', 'mg'), '</tr><$1>');
+			content = content.replace(new RegExp('<(/?(table|tbody|tr|th|td)[^>]*)>(\\s*|(<br ?/?>)*)*', 'g'), '<$1>');
+
+                // Pretty it up for the source editor.
+			var blocklist = 'blockquote|ul|ol|li|table|thead|tr|th|td|div|h\\d|pre|p';
+			content = content.replace(new RegExp('\\s*</('+blocklist+')>\\s*', 'mg'), '</$1>\n');
+			content = content.replace(new RegExp('\\s*<(('+blocklist+')[^>]*)>\\s*', 'mg'), '\n<$1>');
+			content = content.replace(new RegExp('<((li|/?tr|/?thead|/?tfoot)( [^>]*)?)>', 'g'), '\t<$1>');
+			content = content.replace(new RegExp('<((td|th)( [^>]*)?)>', 'g'), '\t\t<$1>');
+			content = content.replace(new RegExp('\\s*<br ?/?>\\s*', 'mg'), '<br />\n');
+			content = content.replace(new RegExp('^\\s*', ''), '');
+			content = content.replace(new RegExp('\\s*$', ''), '');
+
+			break;
+        }
+
+            // Pass through to next handler in chain
+        return content;
+    },
+
+    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');
+
+        if (node == null)
+		return;
+
+        do {
+            if (node.nodeName.toLowerCase() == "img" && 
+                getAttrib(node, 'class').indexOf('mce_plugin_more_more') == 0)
+            {
+                tinyMCE.switchClass(editor_id + '_more_more', 
+                                    'mceButtonSelected');
+            }
+        } while ((node = node.parentNode));
+
+        return true;
+    }
+};
+
+tinyMCE.addPlugin("more", TinyMCE_MorePlugin);

Added: plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/images/help.gif
===================================================================
(Binary files differ)


Property changes on: plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/images/help.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/images/more.gif
===================================================================
(Binary files differ)


Property changes on: plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/images/more.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/images/more_bug.gif
===================================================================
(Binary files differ)


Property changes on: plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/images/more_bug.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/langs/en.js
===================================================================
--- plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/langs/en.js	2006-11-16 14:09:04 UTC (rev 4315)
+++ plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/langs/en.js	2006-11-16 14:12:59 UTC (rev 4316)
@@ -0,0 +1,6 @@
+// EN lang variables
+
+tinyMCE.addToLang('',{
+more_more_button : 'Split post with More tag',
+more_more_alt : 'More...',
+});

Added: plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/more.css
===================================================================
--- plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/more.css	2006-11-16 14:09:04 UTC (rev 4315)
+++ plog/branches/lifetype-1.1.3/js/tinymce/plugins/more/more.css	2006-11-16 14:12:59 UTC (rev 4316)
@@ -0,0 +1,10 @@
+.mce_plugin_more_more {
+	border: 0px;
+	border-top: 1px dotted #aaa;
+	display:block;
+	background-color: #ffffff;
+	margin-top:15px;
+	background-image: url(images/more_bug.gif);
+	background-repeat: no-repeat;
+	background-position: right top;
+}



More information about the pLog-svn mailing list