Browse Source

More fool-proof player adder.

Ralfp 12 years ago
parent
commit
7fb74e870c
1 changed files with 22 additions and 17 deletions
  1. 22 17
      static/cranefly/js/cranefly.js

+ 22 - 17
static/cranefly/js/cranefly.js

@@ -92,14 +92,12 @@ function EnhancePostsMD() {
 		// Automagically turn links into players
 		// Automagically turn links into players
 		var players = new Array();
 		var players = new Array();
 		$('.markdown.js-extra a').each(function() {
 		$('.markdown.js-extra a').each(function() {
-			if (this.href == $.trim($(this).text())) {
-				match = link2player(this);
-				if (match && $.inArray(match, players) == -1) {
-					players.push(match);
-					$(this).replaceWith(match);
-					if (players.length == 10) {
-						return false;
-					}
+			match = link2player($.trim($(this).text()));
+			if (match && $.inArray(match, players) == -1) {
+				players.push(match);
+				$(this).replaceWith(match);
+				if (players.length == 10) {
+					return false;
 				}
 				}
 			}
 			}
 		});
 		});
@@ -107,18 +105,25 @@ function EnhancePostsMD() {
 }
 }
 
 
 // Turn link to player
 // Turn link to player
-function link2player(link) {
+function link2player(link_href) {
 	// Youtube link
 	// Youtube link
 	var re = /watch\?v=((\w|-)+)/;
 	var re = /watch\?v=((\w|-)+)/;
-	if (re.test(link.href)) {
-		media_url = link.href.match(re);
+	if (re.test(link_href)) {
+		media_url = link_href.match(re);
+		return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
+	}
+
+	// Youtube feature=embed
+	var re = /watch\?feature=player_embedded&v=((\w|-)+)/;
+	if (re.test(link_href)) {
+		media_url = link_href.match(re);
 		return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
 		return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
 	}
 	}
 
 
 	// Youtube embed with start time
 	// Youtube embed with start time
 	var re = /youtu.be\/((\w|-)+)\?t=([A-Za-z0-9]+)/;
 	var re = /youtu.be\/((\w|-)+)\?t=([A-Za-z0-9]+)/;
-	if (re.test(link.href)) {
-		media_url = link.href.match(re);
+	if (re.test(link_href)) {
+		media_url = link_href.match(re);
 		media_minutes = media_url[2].match(/([0-9]+)m/);
 		media_minutes = media_url[2].match(/([0-9]+)m/);
 		media_seconds = media_url[2].match(/([0-9]+)s/);
 		media_seconds = media_url[2].match(/([0-9]+)s/);
 		media_url[2] = 0;
 		media_url[2] = 0;
@@ -129,15 +134,15 @@ function link2player(link) {
 	
 	
 	// Youtube embed
 	// Youtube embed
 	var re = /youtu.be\/((\w|-)+)/;
 	var re = /youtu.be\/((\w|-)+)/;
-	if (re.test(link.href)) {
-		media_url = link.href.match(re);
+	if (re.test(link_href)) {
+		media_url = link_href.match(re);
 		return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
 		return '<iframe width="480" height="360" src="http://www.youtube.com/embed/' + media_url[1] + '" frameborder="0" allowfullscreen></iframe>';
 	}
 	}
 
 
 	// Vimeo link
 	// Vimeo link
 	var re = /vimeo.com\/([0-9]+)/;
 	var re = /vimeo.com\/([0-9]+)/;
-	if (re.test(link.href)) {
-		media_url = link.href.match(re);
+	if (re.test(link_href)) {
+		media_url = link_href.match(re);
 		return '<iframe src="http://player.vimeo.com/video/' + media_url[1] + '?color=CF402E" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
 		return '<iframe src="http://player.vimeo.com/video/' + media_url[1] + '?color=CF402E" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
 	}
 	}