[pLog-svn] r7059 - in plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource: . langs
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Fri Oct 8 17:49:57 EDT 2010
Author: jondaley
Date: 2010-10-08 17:49:57 -0400 (Fri, 08 Oct 2010)
New Revision: 7059
Modified:
plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin_src.js
plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/langs/en.js
Log:
upgraded to tinymce 3!
Modified: plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin_src.js
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin_src.js 2010-10-08 20:39:31 UTC (rev 7058)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/editor_plugin_src.js 2010-10-08 21:49:57 UTC (rev 7059)
@@ -12,13 +12,27 @@
* @param {string} url Absolute URL to where the plugin is located.
*/
init : function(ed, url) {
- // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('mceInsertResource');
+ var t=this;
+
+ ed.onBeforeSetContent.add(function(ed, o) {
+ o.content = t.edit2html(t, o.content);
+ });
+
+ ed.onPostProcess.add(function(ed, o) {
+ if (o.set){
+ o.content = t.edit2html(t, o.content);
+ }
+ if (o.get){
+ o.content = t.html2edit(t, o.content);
+ }
+ });
+
ed.addCommand('mceInsertResource', function() {
ed.windowManager.open({
- file : '../../../../admin.php?op=resourceList&mode=1'; // Relative to theme
- width : 500 + parseInt(ed.getLang('InsertResource.delta_width', 0)),
- height : 450 + parseInt(ed.getLang('InsertResource.delta_height', 0)),
- inline : 1
+ file : url + '../../../../../admin.php?op=resourceList&mode=1', // Relative to theme
+ width : 500 + parseInt(ed.getLang('InsertResource.delta_width', 0)),
+ height : 450 + parseInt(ed.getLang('InsertResource.delta_height', 0)),
+ inline : 1
}, {
plugin_url : url, // Plugin absolute URL
});
@@ -40,23 +54,9 @@
ed.onNodeChange.add(function(ed, cm, n) {
cm.setActive('insertresource', n.nodeName == 'IMG');
});
- },
+ },
/**
- * Creates control instances based in the incomming name. This method is normally not
- * needed since the addButton method of the tinymce.Editor class is a more easy way of adding buttons
- * but you sometimes need to create more complex controls like listboxes, split buttons etc then this
- * method can be used to create those.
- *
- * @param {String} n Name of the control to create.
- * @param {tinymce.ControlManager} cm Control manager to use inorder to create new control.
- * @return {tinymce.ui.Control} New control instance or null if no control was created.
- */
- createControl : function(n, cm) {
- return null;
- },
-
- /**
* Returns information about the plugin as a name/value array.
* The current keys are longname, author, authorurl, infourl and version.
*
@@ -68,139 +68,152 @@
author : 'LifeType',
authorurl : 'http://lifetype.net',
infourl : '',
- version : "1.0"
+ version : "2.0"
};
- }
- });
-/////////////////////////////////////
+ },
- cleanup : function(type, content) {
- switch (type) {
- case "insert_to_editor_dom":
- // Force relative/absolute
- if (tinyMCE.getParam('convert_urls')) {
- var imgs = content.getElementsByTagName("img");
- for (var i=0; i<imgs.length; i++) {
- if (tinyMCE.getAttrib(imgs[i], "class") == "ltFlashPlayer") {
- var src = tinyMCE.getAttrib(imgs[i], "alt");
+ edit2html : function(t,content){
+ var startPos = 0;
+ var embedList = new Array();
+
+ // Fix the embed and object elements
+ content = content.replace(new RegExp('<[ ]*object','gi'),'<object');
+ content = content.replace(new RegExp('<[ ]*/object[ ]*>','gi'),'</object>');
+
+ // Parse all object tags and replace them with images from the embed data
+ var index = 0;
+ while ((startPos = content.indexOf('<object', startPos)) != -1) {
+
+ // Find end of object
+ endPos = content.indexOf('</object>', startPos);
+ endPos += 9;
+
+ objectTag = content.substring(startPos,endPos);
+
+ /**
+ * NOTE: this method call relies in a bug of the _parseAttributes method.
+ * This method parses a tag and returns a list of its attributes. It works fine
+ * when presented with a single tag but now that we're passing a whole <object>...</object>
+ * block, it will also parse any other tags in the block. This means that it will return the
+ * value we're looking for as long as "FlashVars" is passed as the last parameter
+ * in the <object> block.
+ */
+ attribs = t._parseAttributes( objectTag );
+
+ var cssClass = "";
+ if( !attribs || attribs["value"] == undefined || attribs["class"] != "ltPlayer" ) {
+ startPos++;
+ continue;
+ }
+
+ // find the value in "file=XXX"
+ var regexp = /.*file=([a-zA-Z0-9\-\/:._%]*)/i;
+ result = regexp.exec( attribs["value"] );
+ var fileUrl = "";
+ if( result ) {
+ fileUrl = result[1];
+ }
+
+ // default values for height and width in case they were not defined (for some reason)
+ if( attribs["height"] == undefined )
+ attribs["height"] = 20;
+ if( attribs["width"] == undefined )
+ attribs["width"] = 320;
- if (tinyMCE.getParam('convert_urls'))
- src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
+ // Insert image
+ var contentAfter = content.substring(endPos);
+ content = content.substring(0, startPos);
+ content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"';
+ content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + fileUrl + '"';
+ content += ' alt="' + fileUrl + '" class="ltFlashPlayer" />' + content.substring(endPos);
+ content += contentAfter;
+
+ index++;
+
+ startPos++;
+ }
+ return content;
+ },
- imgs[i].setAttribute('alt', src);
- imgs[i].setAttribute('title', src);
- }
- }
- }
- break;
+ html2edit : function(t,content){
+ // Parse all img[class=ltFlashPlayer] tags and replace them with object+embed
+ var startPos = -1;
+
+ while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
+ var endPos = content.indexOf('/>', startPos);
+ var attribs = t._parseAttributes(content.substring(startPos + 4, endPos));
+
+ // If not flash, skip it
+ if (!attribs || attribs['class'] != "ltFlashPlayer" )
+ continue;
+
+ endPos += 2;
+
+ var embedHTML = '';
+
+ if( attribs["height"] == undefined )
+ attribs["height"] = 20;
+ if( attribs["width"] == undefined )
+ attribs["width"] = 320;
+
+ embedHTML = getFlashPlayerHTML( attribs["alt"], attribs["height"], attribs["width"] );
+
+ // Insert embed/object chunk
+ chunkBefore = content.substring(0, startPos);
+ chunkAfter = content.substring(endPos);
+ content = chunkBefore + embedHTML + chunkAfter;
+ }
+ return content;
+ },
- case "get_from_editor_dom":
- var imgs = content.getElementsByTagName("img");
- for (var i=0; i<imgs.length; i++) {
- if (tinyMCE.getAttrib(imgs[i], "class")== "ltFlashPlayer") {
- var src = tinyMCE.getAttrib(imgs[i], "alt");
+ // Private plugin internal functions
- if (tinyMCE.getParam('convert_urls'))
- src = eval(tinyMCE.settings['urlconverter_callback'] + "(src, null, true);");
-
- imgs[i].setAttribute('alt', src);
- imgs[i].setAttribute('title', src);
- }
- }
- break;
-
- case "insert_to_editor":
- var startPos = 0;
- var embedList = new Array();
-
- // Fix the embed and object elements
- content = content.replace(new RegExp('<[ ]*object','gi'),'<object');
- content = content.replace(new RegExp('<[ ]*/object[ ]*>','gi'),'</object>');
-
- // Parse all object tags and replace them with images from the embed data
- var index = 0;
- while ((startPos = content.indexOf('<object', startPos)) != -1) {
-
- // Find end of object
- endPos = content.indexOf('</object>', startPos);
- endPos += 9;
-
- objectTag = content.substring(startPos,endPos);
-
- /**
- * NOTE: this method call relies in a bug of the _parseAttributes method.
- * This method parses a tag and returns a list of its attributes. It works fine
- * when presented with a single tag but now that we're passing a whole <object>...</object>
- * block, it will also parse any other tags in the block. This means that it will return the
- * value we're looking for as long as "FlashVars" is passed as the last parameter
- * in the <object> block.
- */
- attribs = TinyMCE_insertresourcePlugin._parseAttributes( objectTag );
-
- var cssClass = "";
- if( !attribs || attribs["value"] == undefined || attribs["class"] != "ltPlayer" ) {
- startPos++;
- continue;
- }
-
- // find the value in "file=XXX"
- var regexp = /.*file=([a-zA-Z0-9\-\/:._%]*)/i;
- result = regexp.exec( attribs["value"] );
- var fileUrl = "";
- if( result ) {
- fileUrl = result[1];
- }
- //window.alert("val = " + attribs["value"] + " - " + fileUrl);
-
- // default values for height and width in case they were not defined (for some reason)
- if( attribs["height"] == undefined )
- attribs["height"] = 20;
- if( attribs["width"] == undefined )
- attribs["width"] = 320;
- // Insert image
- var contentAfter = content.substring(endPos);
- content = content.substring(0, startPos);
- content += '<img width="' + attribs["width"] + '" height="' + attribs["height"] + '"';
- content += ' src="' + (tinyMCE.getParam("theme_href") + '/images/spacer.gif') + '" title="' + fileUrl + '"';
- content += ' alt="' + fileUrl + '" class="ltFlashPlayer" />' + content.substring(endPos);
- content += contentAfter;
-
- index++;
-
- startPos++;
- }
-
- break;
-
- case "get_from_editor":
- // Parse all img tags and replace them with object+embed
- var startPos = -1;
-
- while ((startPos = content.indexOf('<img', startPos+1)) != -1) {
- var endPos = content.indexOf('/>', startPos);
- var attribs = TinyMCE_insertresourcePlugin._parseAttributes(content.substring(startPos + 4, endPos));
-
- // If not flash, skip it
- if (!attribs || attribs['class'] != "ltFlashPlayer" )
- continue;
-
- type = attribs['class'];
-
- endPos += 2;
-
- var embedHTML = '';
-
- if( attribs["height"] == undefined )
- attribs["height"] = 20;
- if( attribs["width"] == undefined )
- attribs["width"] = 320;
-
- embedHTML = getFlashPlayerHTML( attribs["alt"], attribs["height"], attribs["width"] );
-
- // Insert embed/object chunk
- chunkBefore = content.substring(0, startPos);
- chunkAfter = content.substring(endPos);
- content = chunkBefore + embedHTML + chunkAfter;
- }
- break;
- }
+ _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 == '"' ) && !withInValue)
+ withInValue = true;
+ else if ((chr == '"' ) && withInValue) {
+ withInValue = false;
+
+ var pos = attributeName.lastIndexOf(' ');
+ if (pos != -1)
+ attributeName = attributeName.substring(pos+1);
+
+ attributes[attributeName.toLowerCase()] = attributeValue.substring(1);
+
+ 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;
+ }
+ });
+ // Register plugin
+ tinymce.PluginManager.add('insertresource', tinymce.plugins.InsertResourcePlugin);
+})();
Modified: plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/langs/en.js
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/langs/en.js 2010-10-08 20:39:31 UTC (rev 7058)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertresource/langs/en.js 2010-10-08 21:49:57 UTC (rev 7059)
@@ -1,3 +1,3 @@
tinyMCE.addI18n('en.insertresource',{
- title : 'Insert Resource/Album'
+ desc : 'Insert Resource/Album'
});
More information about the pLog-svn
mailing list