Ver Fonte

[svn r17393] FS#2867 - FCKEditor, embedding movies (not FLV): adding fake image, double-click and context menu support.

Ivan Tcholakov há 16 anos atrás
pai
commit
b9f79c5115

+ 182 - 73
main/inc/lib/fckeditor/editor/plugins/customizations/fckplugin.js

@@ -361,6 +361,29 @@ var FCKDialog = ( function()
  **************************************************************************************
  */
 
+// This is a modification of the original function.
+FCKDocumentProcessor_CreateFakeImage = function( fakeClass, realElement )
+{
+	var real = FCKTools.GetElementDocument( realElement ) ;
+	var oImg = real.createElement( 'IMG' ) ;
+	oImg.className = fakeClass ;
+	oImg.src = FCKConfig.BasePath + 'images/spacer.gif' ;
+	oImg.setAttribute( '_fckfakelement', 'true', 0 ) ;
+	oImg.setAttribute( '_fckrealelement', FCKTempBin.AddElement( realElement ), 0 ) ;
+	if ( fakeClass == 'FCK__Video' )
+	{
+		if ( real.width )
+		{
+			oImg.style.width = FCKTools.ConvertHtmlSizeToStyle( real.width ) ;
+		}
+		if ( real.height )
+		{
+			oImg.style.height = FCKTools.ConvertHtmlSizeToStyle( real.height ) ;
+		}
+	}
+	return oImg ;
+}
+
 // A custom handler for audio files when a new tag has been added.
 FCKEmbedAndObjectProcessor.AddCustomHandler( function ( el, fakeImg )
 	{
@@ -369,7 +392,7 @@ FCKEmbedAndObjectProcessor.AddCustomHandler( function ( el, fakeImg )
 			return ;
 		}
 
-		fakeImg.className = 'FCK__MP3';
+		fakeImg.className = 'FCK__MP3' ;
 		fakeImg.setAttribute( '_fckmp3', 'true', 0 ) ;
 	} ) ;
 
@@ -399,7 +422,7 @@ FCKEmbedAndObjectProcessor.AddCustomHandler( function ( el, fakeImg )
 			return ;
 		}
 
-		fakeImg.className = 'FCK__Video';
+		fakeImg.className = 'FCK__Video' ;
 		fakeImg.setAttribute( '_fckvideo', 'true', 0 ) ;
 	} ) ;
 
@@ -421,77 +444,6 @@ FCKDocumentProcessor.AppendNew().ProcessDocument = function ( document )
 		}
 	} ;
 
-// Checking for audio file reference which is to be used by a flash player.
-FCK.is_audio = function ( tag )
-	{
-		if ( tag.nodeName.IEquals( 'embed' ) )
-		{
-			if ( !tag.src )
-			{
-				return false ;
-			}
-
-			if ( tag.type == 'application/x-shockwave-flash' || /\.swf($|#|\?|&)?/i.test( tag.src ) )
-			{
-				// Possible way of detection for other players.
-				if ( /\.mp3/i.test( tag.src ) )
-				{
-					return true ;
-				}
-
-				// Specific to mediaplayer detection.
-				var flashvars = FCKDomTools.GetAttributeValue( tag, 'flashvars' ) ;
-				flashvars = flashvars ? flashvars.toLowerCase() : '' ;
-
-				if ( /\.mp3/i.test( flashvars ) )
-				{
-					return true ;
-				}
-			}
-		}
-
-		return false ;
-	} ;
-
-//Checking for video file reference within an embedded object.
-FCK.is_video = function ( tag )
-	{
-		if ( tag.nodeName.IEquals( 'embed' ) )
-		{
-			if ( !tag.src )
-			{
-				return false ;
-			}
-
-			// There are three plugins dealing with video content. Detection looks a bit messy.
-			if ( tag.type == 'application/x-shockwave-flash' || /\.swf($|#|\?|&)?/i.test( tag.src ) )
-			{
-				// Youtube.
-				if ( /\.youtube\.com/i.test( tag.src ) )
-				{
-					return true ;
-				}
-
-				// "Embed video" + "FLV player".
-				if ( /\.(mpg|mpeg|avi|wmv|mov|asf|flv)/i.test( tag.src ) )
-				{
-					return true ;
-				}
-
-				// All above that is supported by mediaplayer, it uses flashvars attribute.
-				var flashvars = FCKDomTools.GetAttributeValue( tag, 'flashvars' ) ;
-				flashvars = flashvars ? flashvars.toLowerCase() : '' ;
-
-				if ( /\.(mpg|mpeg|avi|wmv|mov|asf|flv)/i.test( flashvars ) )
-				{
-					return true ;
-				}
-			}
-		}
-
-		return false ;
-	} ;
-
 
 /*
  **************************************************************************************
@@ -576,6 +528,24 @@ FCK.ContextMenu.RegisterListener( {
 	} }
 ) ;
 
+// Video-related commands.
+FCK.ContextMenu.RegisterListener( {
+	AddItems : function ( menu, tag, tagName )
+	{
+		if ( tagName == 'IMG' && tag.getAttribute( '_fckvideo' ) )
+		{
+			switch ( FCK.get_video_type( tag ) )
+			{
+				case 'embedded_video' :
+					menu.AddSeparator() ;
+					menu.AddItem( 'EmbedMovies', FCKLang.DlgMP3Title, FCKConfig.PluginsPath + 'fckEmbedMovies/embedmovies.gif' ) ;
+					break ;
+				default :
+					break ;
+			}
+		}
+	} }
+) ;
 
 /*
  **************************************************************************************
@@ -607,6 +577,24 @@ FCK.RegisterDoubleClickHandler(
 	}, 'IMG'
 ) ;	
 
+// Video-related commands.
+FCK.RegisterDoubleClickHandler(
+	function ( tag )
+	{
+		if ( tag.tagName == 'IMG' && tag.getAttribute( '_fckvideo' ) )
+		{
+			switch ( FCK.get_video_type( tag ) )
+			{
+				case 'embedded_video' :
+					FCKCommands.GetCommand( 'EmbedMovies' ).Execute() ;
+					break ;
+				default :
+					break ;
+			}
+		}
+	}, 'IMG'
+) ;	
+
 
 /*
  **************************************************************************************
@@ -614,6 +602,127 @@ FCK.RegisterDoubleClickHandler(
  **************************************************************************************
  */
 
+// Checking for audio file reference which is to be used by a flash player.
+FCK.is_audio = function ( tag )
+	{
+		if ( tag.nodeName.IEquals( 'embed' ) )
+		{
+			if ( !tag.src )
+			{
+				return false ;
+			}
+
+			if ( tag.type == 'application/x-shockwave-flash' || /\.swf($|#|\?|&)?/i.test( tag.src ) )
+			{
+				// Possible way of detection for other players.
+				if ( /\.mp3/i.test( tag.src ) )
+				{
+					return true ;
+				}
+
+				// Specific to mediaplayer detection.
+				var flashvars = FCKDomTools.GetAttributeValue( tag, 'flashvars' ) ;
+				flashvars = flashvars ? flashvars.toLowerCase() : '' ;
+
+				if ( /\.mp3/i.test( flashvars ) )
+				{
+					return true ;
+				}
+			}
+		}
+
+		return false ;
+	} ;
+
+// Checking for video file reference within an embedded object.
+FCK.is_video = function ( tag )
+	{
+		if ( tag.nodeName.IEquals( 'embed' ) )
+		{
+			if ( !tag.src )
+			{
+				return false ;
+			}
+
+			// There are three plugins dealing with video content. Detection looks a bit messy.
+
+			// Embedded video.
+			if ( /\.(mpg|mpeg|avi|wmv|mov|asf)/i.test( tag.src ) )
+			{
+				return true ;
+			}
+
+			if ( tag.type == 'application/x-shockwave-flash' || /\.swf($|#|\?|&)?/i.test( tag.src ) )
+			{
+				// Youtube.
+				if ( /\.youtube\.com/i.test( tag.src ) )
+				{
+					return true ;
+				}
+
+				// FLV player.
+				if ( /\.flv/i.test( tag.src ) )
+				{
+					return true ;
+				}
+
+				var flashvars = FCKDomTools.GetAttributeValue( tag, 'flashvars' ) ;
+				flashvars = flashvars ? flashvars.toLowerCase() : '' ;
+
+				if ( /\.flv/i.test( flashvars ) )
+				{
+					return true ;
+				}
+			}
+		}
+
+		return false ;
+	} ;
+
+// Returns specific type/source of embedded video.
+FCK.get_video_type = function ( img )
+{
+	var tag = FCK.GetRealElement( img ) ;
+
+	if ( !tag )
+	{
+		return false ;
+	}
+
+	if ( !tag.src )
+	{
+		return false ;
+	}
+
+	// Embedded video.
+	if ( /\.(mpg|mpeg|avi|wmv|mov|asf)/i.test( tag.src ) )
+	{
+		return 'embedded_video' ;
+	}
+
+	// Youtube.
+	if ( /\.youtube\.com/i.test( tag.src ) )
+	{
+		return 'youtube' ;
+	}
+
+	// FLV player.
+	if ( /\.flv/i.test( tag.src ) )
+	{
+		return 'flv' ;
+	}
+
+	var flashvars = FCKDomTools.GetAttributeValue( tag, 'flashvars' ) ;
+	flashvars = flashvars ? flashvars.toLowerCase() : '' ;
+
+	if ( /\.flv/i.test( flashvars ) )
+	{
+		return 'flv' ;
+	}
+
+	return false ;
+}
+
 // This is a utility for debugging purposes.
 function var_dump( variable, level )
 {

+ 28 - 30
main/inc/lib/fckeditor/editor/plugins/fckEmbedMovies/fck_embedmovies.js

@@ -25,7 +25,7 @@ var is_gecko = !is_ie; // FCKBrowserInfo.IsGecko
 
 if ( oFakeImage )
 {
-	if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckflash') )
+	if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckvideo') )
 		oEmbed = FCK.GetRealElement( oFakeImage ) ;
 	else
 		oFakeImage = null ;
@@ -134,7 +134,7 @@ function CreateEmbeddedMovie(e, url)
 		{
 			pluginspace = "http://www.microsoft.com/Windows/MediaPlayer/";
 			codebase    = "http://www.microsoft.com/Windows/MediaPlayer/";
-			classid     = 'CLASSID="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"';
+			classid     = 'classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"';
 		}
 		else
 		{
@@ -146,26 +146,26 @@ function CreateEmbeddedMovie(e, url)
 		var html;
 		if (EmbedInObject)
 		{
-			html  = '<OBJECT '+ classid +'>';
-			html += '<PARAM name="url" value="'+ url +'" />';
-			html += '<PARAM name="filename" value="'+ url +'" />';
-			html += '<PARAM name="autostart" value="'+ (GetE('chkAutostart').checked?"true":"false") +'" />';
-			html += '<PARAM name="showcontrols" value="'+ (GetE('chkShowcontrols').checked?"true":"false") +'" />';
-			html += '<PARAM name="showpositioncontrols" value="'+ (GetE('chkShowpositioncontrols').checked?"true":"false") +'" />';
-			html += '<PARAM name="showtracker" value="'+ (GetE('chkShowtracker').checked?"true":"false") +'" />';
-			html += '<PARAM name="showaudiocontrols" value="'+ (GetE('chkShowaudiocontrols').checked?"true":"false") +'" />';
-			html += '<PARAM name="showgotobar" value="'+ (GetE('chkShowgotobar').checked?"true":"false") +'" />';
-			html += '<PARAM name="showstatusbar" value="'+ (GetE('chkShowstatusbar').checked?"true":"false") +'" />';
-			html += '<PARAM name="standby" value="Loading Video..." />';
-			html += '<PARAM name="pluginspace" value="'+ pluginspace +'" />';
-			html += '<PARAM name="codebase" value="'+ codebase +'" />'; 
-			html += '<EMBED type="'+ sType +'" src="'+ url +'"></EMBED>';
-			html += '<NOEMBED>Download movie: <A HREF="'+ url +'">'+ url +'</A></NOEMBED>';
-			html += '</OBJECT>';
+			html  = '<object '+ classid +'>';
+			html += '<param name="url" value="'+ url +'" />';
+			html += '<param name="filename" value="'+ url +'" />';
+			html += '<param name="autostart" value="'+ (GetE('chkAutostart').checked?"true":"false") +'" />';
+			html += '<param name="showcontrols" value="'+ (GetE('chkShowcontrols').checked?"true":"false") +'" />';
+			html += '<param name="showpositioncontrols" value="'+ (GetE('chkShowpositioncontrols').checked?"true":"false") +'" />';
+			html += '<param name="showtracker" value="'+ (GetE('chkShowtracker').checked?"true":"false") +'" />';
+			html += '<param name="showaudiocontrols" value="'+ (GetE('chkShowaudiocontrols').checked?"true":"false") +'" />';
+			html += '<param name="showgotobar" value="'+ (GetE('chkShowgotobar').checked?"true":"false") +'" />';
+			html += '<param name="showstatusbar" value="'+ (GetE('chkShowstatusbar').checked?"true":"false") +'" />';
+			html += '<param name="standby" value="Loading Video..." />';
+			html += '<param name="pluginspace" value="'+ pluginspace +'" />';
+			html += '<param name="codebase" value="'+ codebase +'" />'; 
+			html += '<embed type="'+ sType +'" src="'+ url +'"></embed>';
+			html += '<noembed>Download movie: <a href="'+ url +'">'+ url +'</a></noembed>';
+			html += '</object>';
 		}
 		else
 		{
-			html = '<EMBED type="'+ sType +'" src="'+ url +'" '+
+			html = '<embed type="'+ sType +'" src="'+ url +'" '+
 			       'autosize="'+ (GetE('chkAutosize').checked?"true":"false") +'" '+
 			       'autostart="'+ (GetE('chkAutostart').checked?"true":"false") +'" '+
 			       'showcontrols="'+ (GetE('chkShowcontrols').checked?"true":"false") +'" '+
@@ -178,7 +178,7 @@ function CreateEmbeddedMovie(e, url)
 			       'codebase="'+ codebase +'"';
 			if (!GetE('chkAutosize').checked)	
 				html += 'width="'+ GetE('txtWidth').value +'" height="'+ GetE('txtHeight').value +'"';
-			html += '></EMBED>';
+			html += '></embed>';
 		}			
 		//e.innerHTML = html;
 		//FCK.InsertHtml(html);
@@ -199,7 +199,7 @@ function setVideoUrl(url)
 	{		
 		if (FCKConfig.CreateDocumentDir == '/')
 		{	
-			return_url = url; // // FCKConfig.CreateDocumentDir variable is defined in create_document.php		
+			return_url = url; // FCKConfig.CreateDocumentDir variable is defined in create_document.php		
 		}
 		else
 		{	
@@ -225,15 +225,13 @@ function Ok()
 		return false ;
 	}
 
-	if (!oContainerDiv)
-	{
-		oContainerDiv = FCK.CreateElement('DIV');
-	}
+	// Disabled by Ivan Tcholakov.
+	//if (!oContainerDiv)
+	//{
+	//	oContainerDiv = FCK.CreateElement('DIV');
+	//}
 	
-	//if ( )
-	//{	
-		// code that makes posible the fake image
-		
+	// code that makes posible the fake image
 	if ( !oEmbed )
 	{
 		oEmbed		= FCK.EditorDocument.createElement( 'embed' ) ;		
@@ -255,4 +253,4 @@ function Ok()
 		
 	oEditor.FCKUndo.SaveUndoStep();
 	return true;	
-}
+}

+ 1 - 1
main/inc/lib/fckeditor/editor/plugins/fckEmbedMovies/fckplugin.js

@@ -7,7 +7,7 @@ FCKCommands.RegisterCommand(
 		'Embed movies',
 		FCKPlugins.Items['fckEmbedMovies'].Path + 'fck_embedmovies.html',
 		450,
-		370
+		400
 	)
 );
 // Create the "EmbedMovies" toolbar button.