[pLog-svn] r5485 - in plog/branches/lifetype-1.2/js/tinymce: . plugins plugins/insertaudio plugins/insertaudio/css plugins/insertaudio/images plugins/insertaudio/langs

jondaley at devel.lifetype.net jondaley at devel.lifetype.net
Mon Jun 4 07:48:38 EDT 2007


Author: jondaley
Date: 2007-06-04 07:48:38 -0400 (Mon, 04 Jun 2007)
New Revision: 5485

Added:
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/audioinput.html
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/css/
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/css/content.css
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/css/flash.css
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/editor_plugin.js
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/functions.js
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/images/
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/images/player.png
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/langs/
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/langs/en.js
   plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/langs/fr.js
Modified:
   plog/branches/lifetype-1.2/js/tinymce/tiny_mce-plog.js
Log:
Not sure if this should be a completely separate plugin or merged with the insertvideo plugin, but this allows for non-resourced mp3 files to be played through our flash mp3 player.  http://bugs.lifetype.net/view.php?id=1320

Added: plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/audioinput.html
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/audioinput.html	                        (rev 0)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/audioinput.html	2007-06-04 11:48:38 UTC (rev 5485)
@@ -0,0 +1,38 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+	<title>{$lang_insertaudio_desc}</title>
+	<script language="javascript" type="text/javascript" src="../../tiny_mce_popup.js"></script>
+	<script language="javascript" type="text/javascript" src="functions.js"></script>	
+	<base target="_self" />
+</head>
+<body style="display: none">
+	<form name="audio" id="audio" method="post" action="#">
+	<div class="tabs">
+	  <ul>
+	   <li id="general_tab" class="current"><span>{$lang_insertaudio_desc}</span></li>
+	  </ul>
+	</div>
+	<div class="panel_wrapper">
+	  <div id="general_panel" class="panel_current">
+	     <legend>{$lang_insertaudio_panellegend}</legend>	     	     
+	     <table border="0" cellpadding="4" cellspacing="0">
+	      <tr>
+	       <td nowrap="nowrap">{$lang_insertaudio_url}</td>
+	       <td><input type="text" id="url" name="url" value="" style="width:300px" /></td>
+	      </tr>		
+		 </table>		    
+		</div>
+		</div>
+		<div class="mceActionPanel">
+		  <div style="float:left">		
+			<input type="button" name="insert" value="{$lang_insert}" onClick="insertAudioCode()" id="insert" />
+		  </div>
+		  <div style="float:right">
+		    <input type="button" name="cancel" value="{$lang_close}" onclick="tinyMCEPopup.close();" id="cancel" />
+		  </div>
+		</div>
+	 </div>
+	</div>				
+	 </form>
+</body>
+</html>

Added: plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/css/content.css
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/css/content.css	                        (rev 0)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/css/content.css	2007-06-04 11:48:38 UTC (rev 5485)
@@ -0,0 +1,7 @@
+.ltFlashPlayer {
+	background-image: url('../images/player.png');	
+	border: 1px dotted #cc0000;
+	background-position: center;
+	background-repeat: no-repeat;
+	background-color: #ffffcc;
+}
\ No newline at end of file

Added: plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/css/flash.css
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/css/flash.css	                        (rev 0)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/css/flash.css	2007-06-04 11:48:38 UTC (rev 5485)
@@ -0,0 +1,11 @@
+.panel_wrapper div.current {
+	height: 100px;
+}
+
+#width, #height {
+	width: 50px;
+}
+
+#file {
+	width: 250px;
+}

Added: plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/editor_plugin.js
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/editor_plugin.js	                        (rev 0)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/editor_plugin.js	2007-06-04 11:48:38 UTC (rev 5485)
@@ -0,0 +1,251 @@
+/* Import plugin specific language pack */
+tinyMCE.importPluginLanguagePack('insertaudio', 'en,fr'); // <- Add a comma separated list of all supported languages
+
+// Singleton class
+var TinyMCE_insertaudioPlugin = {
+	getInfo : function() {
+		return {
+			longname : 'insertaudio plugin',
+			author : 'Gabriel ROUSSEAU',
+			authorurl : 'http://grvg.free.fr',
+			infourl : 'http://grvg.free.fr',
+			version : "0.2"
+		};
+	},
+
+	initInstance : function(inst) {
+		tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/plugins/insertaudio/css/content.css");	
+	},
+
+	getControlHTML : function(cn) {
+		switch (cn) {
+			case "insertaudio":
+				return tinyMCE.getButtonHTML(cn, 'lang_insertaudio_desc', '{$pluginurl}/images/player.png', 'mceinsertaudio', true);
+		}
+
+		return "";
+	},
+
+	/**
+	 * Executes a specific command, this function handles plugin commands.
+	 *
+	 * @param {string} editor_id TinyMCE editor instance id that issued the command.
+	 * @param {HTMLElement} element Body or root element for the editor instance.
+	 * @param {string} command Command name to be executed.
+	 * @param {string} user_interface True/false if a user interface should be presented.
+	 * @param {mixed} value Custom value argument, can be anything.
+	 * @return true/false if the command was executed by this plugin or not.
+	 * @type
+	 */
+	execCommand : function(editor_id, element, command, user_interface, value) {
+		// Handle commands		
+		switch (command) {
+			// Remember to have the "mce" prefix for commands so they don't intersect with built in ones in the browser.
+			case "mceinsertaudio":
+				// Show UI/Popup
+				if (user_interface) {
+					// Open a popup window and send in some custom data in a window argument
+					var insertaudio = new Array();
+
+					insertaudio['file'] = '../../plugins/insertaudio/audioinput.html'; // Relative to theme
+					insertaudio['width'] = 500;
+					insertaudio['height'] = 120;
+
+					tinyMCE.openWindow(insertaudio, {editor_id : editor_id, resizable : "no", scrollbars : "no", inline : "yes"});
+				}
+				return true;
+		}
+
+	   // Pass to next handler in chain
+	   return false;
+	},
+
+	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")== "ltVideoYouTube") {
+						if (tinyMCE.getAttrib(imgs[i], "class").substr(0,6) == "ltFlashPlayer") {							
+							var src = tinyMCE.getAttrib(imgs[i], "alt");
+
+							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 "get_from_editor_dom":
+				var imgs = content.getElementsByTagName("img");
+				for (var i=0; i<imgs.length; i++) {
+					if (tinyMCE.getAttrib(imgs[i], "class").substr(0,6) == "ltAudio") {
+						var src = tinyMCE.getAttrib(imgs[i], "alt");
+
+						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);
+					attribs = TinyMCE_insertaudioPlugin._parseAttributes( objectTag );
+					
+					var cssClass = "";					
+					if( attribs["data"] == undefined )
+					{
+						startPos++;
+						continue;
+					} else {
+						cssClass = "ltFlashPlayer";
+					}
+					
+					// 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="' + attribs["data"] + '"';
+					content += ' alt="' + attribs["data"] + '" class="'+cssClass+'" />' + 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_insertaudioPlugin._parseAttributes(content.substring(startPos + 4, endPos));
+
+					// Is not flash, skip it
+					if (attribs['class'] != "ltFlashPlayer")
+						continue;
+
+					type = attribs['class'];
+
+					endPos += 2;
+
+					var embedHTML = '';
+					
+					embedHTML = getAudioFlashHTML( attribs["title"] );
+
+					// Insert embed/object chunk
+					chunkBefore = content.substring(0, startPos);
+					chunkAfter = content.substring(endPos);
+					content = chunkBefore + embedHTML + chunkAfter;
+				}
+				break;
+		}
+
+		// Pass through to next handler in chain
+		return content;
+	},
+
+	handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
+		if (node == null)
+			return;
+
+		do {
+			if (node.nodeName == "IMG" && tinyMCE.getAttrib(node, 'class').indexOf('ltFlashPlayer') == 0) {
+				tinyMCE.switchClass(editor_id + '_flash', 'mceButtonSelected');
+				return true;
+			}
+		} while ((node = node.parentNode));
+
+		tinyMCE.switchClass(editor_id + '_flash', 'mceButtonNormal');
+
+		return true;
+	},
+
+	// Private plugin internal functions
+
+	_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);
+
+				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;
+	}
+};
+
+function getAudioFlashHTML( url )
+{		
+	var baseUrl = TinyMCE.baseURL.substring(0, TinyMCE.baseURL.indexOf("/js/tinymce",0));
+		
+	var html =	'<object data="'+baseUrl+'/flash/mp3player/mp3player.swf" type="application/x-shockwave-flash" width="320" height="20" class="ltFlashPlayer">'+
+			'<param name="quality" value="best" />'+
+			'<param name="bgcolor" value="#FFFFFF" />'+
+			'<param name="movie" value="http://asaxweb.org/classes/flash/mp3player/mp3player.swf" />'+
+			'<param name="FlashVars" value="&amp;file='+url+'&amp;height=20&amp;width=320" />'+
+			'</object>';
+	
+	return( html );
+}
+
+tinyMCE.addPlugin("insertaudio", TinyMCE_insertaudioPlugin );
\ No newline at end of file

Added: plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/functions.js
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/functions.js	                        (rev 0)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/functions.js	2007-06-04 11:48:38 UTC (rev 5485)
@@ -0,0 +1,41 @@
+function init() {
+	tinyMCEPopup.resizeToInnerSize();
+}
+
+function isValidUrl( url )
+{
+	var regexp = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
+	return regexp.test(url);
+}
+
+function insertAudioCode()
+{
+	// get and check the URL
+	urlField = document.forms[0].url;
+	url = urlField.value;
+	if( url == "" || !isValidUrl( url )) {
+		window.alert( tinyMCE.getLang('lang_insertvideo_badurl', 0) );
+		return( false );
+	}
+
+	css="ltFlashPlayer";
+	width=320;
+	height=20;
+	
+	insertFlash( url, css, width, height );
+}
+
+function insertFlash( file, css, width, height ) {
+
+	var html      = '';
+
+	html += ''
+		+ '<img src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" mce_src="' + (tinyMCE.getParam("theme_href") + "/images/spacer.gif") + '" '
+		+ 'width="' + width + '" height="' + height + '" '
+		+ 'border="0" alt="' + file + '" title="' + file + '" class="'+css+'" />';
+
+	tinyMCEPopup.execCommand("mceInsertContent", true, html);
+	tinyMCE.selectedInstance.repaint();
+
+	tinyMCEPopup.close();
+}
\ No newline at end of file

Added: plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/images/player.png
===================================================================
(Binary files differ)


Property changes on: plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/images/player.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/langs/en.js
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/langs/en.js	                        (rev 0)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/langs/en.js	2007-06-04 11:48:38 UTC (rev 5485)
@@ -0,0 +1,8 @@
+// UK lang variables
+
+tinyMCE.addToLang('',{
+lang_insertaudio_desc : 'Insert Audio',
+lang_insertaudio_panellegend : 'Please provide a link to an mp3 audio file.',
+lang_insertaudio_url : 'Audio URL:',
+lang_insertaudio_badurl : 'Invalid URL',
+});
\ No newline at end of file

Added: plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/langs/fr.js
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/langs/fr.js	                        (rev 0)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertaudio/langs/fr.js	2007-06-04 11:48:38 UTC (rev 5485)
@@ -0,0 +1,8 @@
+// FR lang variables
+
+tinyMCE.addToLang('',{
+lang_insertaudio_desc : 'Ins&eacute;rer audio',
+lang_insertaudio_panellegend : 'Veuillez indiquer un lien vers un fichier audio mp3.',
+lang_insertaudio_url : 'URL du fichier audio :',
+lang_insertaudio_badurl : 'L’URL indiquée n’est pas valide',
+});
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/js/tinymce/tiny_mce-plog.js
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/tiny_mce-plog.js	2007-06-04 11:33:00 UTC (rev 5484)
+++ plog/branches/lifetype-1.2/js/tinymce/tiny_mce-plog.js	2007-06-04 11:48:38 UTC (rev 5485)
@@ -2,14 +2,14 @@
 	mode : "exact",
 	elements : "postText,postExtendedText",
 	theme : "advanced",
-	plugins : "fullscreen,table,inlinepopups,insertdatetime,emotions,insertresource,insertvideo,more",
+	plugins : "fullscreen,table,inlinepopups,insertdatetime,emotions,insertresource,insertvideo,insertaudio,more",
 	relative_urls : false,
     fix_list_elements : true,
 	remove_script_host : false,
 	force_p_newlines : true,
 	cleanup_on_startup : true,	
 	theme_advanced_buttons1 : "fontsizeselect,fontselect,forecolor,backcolor,bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull",
-	theme_advanced_buttons2 : "bullist,numlist,indent,outdent,separator,link,unlink,image,insertresource,insertvideo,emotions,separator,hr,insertdate,inserttime,separator,fullscreen,separator,code,more",
+	theme_advanced_buttons2 : "bullist,numlist,indent,outdent,separator,link,unlink,image,insertresource,insertvideo,insertaudio,emotions,separator,hr,insertdate,inserttime,separator,fullscreen,separator,code,more",
 	theme_advanced_buttons3 : "",
 	fullscreen_settings : {
                 theme_advanced_buttons3 : "tablecontrols"



More information about the pLog-svn mailing list