[pLog-svn] r5654 - plog/branches/lifetype-1.2/js/tinymce/plugins/insertvideo
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Sat Jul 14 08:10:04 EDT 2007
Author: oscar
Date: 2007-07-14 08:10:04 -0400 (Sat, 14 Jul 2007)
New Revision: 5654
Modified:
plog/branches/lifetype-1.2/js/tinymce/plugins/insertvideo/editor_plugin.js
plog/branches/lifetype-1.2/js/tinymce/plugins/insertvideo/functions.js
Log:
Added support for adding links from localized youtube sites (i.e. from http://es.youtube.com)
Modified: plog/branches/lifetype-1.2/js/tinymce/plugins/insertvideo/editor_plugin.js
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertvideo/editor_plugin.js 2007-07-14 10:58:47 UTC (rev 5653)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertvideo/editor_plugin.js 2007-07-14 12:10:04 UTC (rev 5654)
@@ -284,25 +284,34 @@
return( html );
}
-
function getVideoType( url )
{
- if( url.substring( 0, 24 ) == "http://video.google.com/" )
- return 1;
- else if( url.substring( 0, 23 ) == "http://www.youtube.com/" )
- return 2;
- else if( url.substring( 0, 24 ) == "http://www.metacafe.com/" )
- return 3;
- else if( url.substring( 0, 21 ) == "http://www.ifilm.com/" )
- return 4;
- else if( url.substring( 0, 21 ) == "http://www.goear.com/" )
- return 5;
- else if( url.substring( 0, 21 ) == "http://www.grouper.com/" )
- return 6;
- else if( url.substring( 0, 27 ) == "http://www.dailymotion.com/" )
- return 7;
- else
- return 0;
+ /**
+ * this method now uses regular expressions for more precise matching, please
+ * remember to escape strings properly for their usage as regular expressions
+ * when attempting to add new sites
+ */
+ var sites = {
+ 1: /^http:\/\/video\.google\.com\//,
+ 2: /^http:\/\/.{2,3}\.youtube\.com\//,
+ 3: /^http:\/\/www\.metacafe\.com\//,
+ 4: /^http:\/\/www\.ifilm\.com\//,
+ 5: /^http:\/\/www\.goear.com\//,
+ 6: /^http:\/\/www\.grouper\.com\//,
+ 7: /^http:\/\/www\.dailymotion\.com\//
+ };
+
+ var found = false;
+ var siteId = 0;
+ for( var id in sites ) {
+ if( url.match( sites[id] )) {
+ found = true;
+ siteId = id;
+ break;
+ }
+ }
+
+ return( siteId );
}
tinyMCE.addPlugin("insertvideo", TinyMCE_insertvideoPlugin );
Modified: plog/branches/lifetype-1.2/js/tinymce/plugins/insertvideo/functions.js
===================================================================
--- plog/branches/lifetype-1.2/js/tinymce/plugins/insertvideo/functions.js 2007-07-14 10:58:47 UTC (rev 5653)
+++ plog/branches/lifetype-1.2/js/tinymce/plugins/insertvideo/functions.js 2007-07-14 12:10:04 UTC (rev 5654)
@@ -11,11 +11,12 @@
function getYouTubeLink( url )
{
// check if this is a URL pointing to a youtube link or to a youtube video
- if( url.substring( 0, 31 ) == "http://www.youtube.com/watch?v=" ) {
+ //if( url.substring( 0, 31 ) == "http://www.youtube.com/watch?v=" ) {
+ if( url.match( /http:\/\/.{2,3}\.youtube.com\//i )) {
// and if it's a link to a normal youtube page, build the right link to the video player
- var regexp = /http:\/\/www.youtube.com\/.*?v=([\-0-9a-zA-z_]*).*/i;
+ var regexp = /http:\/\/.{2,3}\.youtube.com\/.*?v=([\-0-9a-zA-z_]*).*/i;
result = regexp.exec( url );
- if( result ) {
+ if( result ) {
videoId = result[1];
}
else {
@@ -25,21 +26,28 @@
url = "http://www.youtube.com/v/" + videoId;
}
-
- // Checks if the URL is missing WWW.
else if ( url.substring( 0, 27 ) == "http://youtube.com/watch?v=" ) {
- // and if it's a link to a normal youtube page, build the right link to the video player
- var regexp = /http:\/\/youtube.com\/.*?v=([\-0-9a-zA-z_]*).*/i;
- result = regexp.exec( url );
- if( result ) {
- videoId = result[1];
- }
- else {
- // let's try to make a best guess...
- videoId = url.substring( 27, url.length );
- }
+ // Checks if the URL is missing WWW.
+ // and if it's a link to a normal youtube page, build the right link to the video player
+ var regexp = /http:\/\/youtube.com\/.*?v=([\-0-9a-zA-z_]*).*/i;
+ result = regexp.exec( url );
+ if( result ) {
+ videoId = result[1];
+ }
+ else {
+ // let's try to make a best guess...
+ videoId = url.substring( 27, url.length );
+ }
+ url = "http://www.youtube.com/v/" + videoId;
+ }
+ else {
+ var regexp = /.*?v=([\-0-9a-zA-z_]*).*/i;
+ result = regexp.exec( url );
+ if( result ) {
+ videoId = result[1];
url = "http://www.youtube.com/v/" + videoId;
+ }
}
return( url );
@@ -171,7 +179,6 @@
goear = document.getElementById("goear");
grouper = document.getElementById("grouper");
dailymot = document.getElementById("dailymot");
-
// bolt = document.getElementById("bolt");
if( youtube.checked==false && gvideo.checked==false && metacafe.checked==false && ifilm.checked==false && goear.checked==false && grouper.checked==false && dailymot.checked==false ) {
More information about the pLog-svn
mailing list