/******************************************************************************* jquery.mb.components Copyright (c) 2001-2010. Matteo Bicocchi (Pupunzi); Open lab srl, Firenze - Italy email: info@pupunzi.com site: http://pupunzi.com Licences: MIT, GPL ******************************************************************************/ /* * jQuery.mb.components: mb.mediaEmbedder * version: 1.0- 23-gen-2010 - 55 * © 2001 - 2010 Matteo Bicocchi (pupunzi), Open Lab * */ (function ($) { $.mb_videoEmbedder = { name:"jquery.mb.videoEmbedder", version:1.0, author:"Matteo Bicocchi", defaults: { width:450, youtube:{ showTitle:false }, called: false }, regEx:/\[(.*?)\]/g, mb_setMovie:function (context, pat, embedString) { // console.debug(context); // console.debug(pat); // console.debug(embedString); function findMovieAndEmbed(node, pat, embedString) { var skip = 0; if (pat.indexOf("&") != -1) pat = pat.replace(/&/g, "&"); if (node.nodeType == 3) { var pos = node.data.toUpperCase().indexOf(pat); if (pos >= 0) { // teoros //var embed = $('').addClass("mb_video"); var embed = $('').addClass("mb_video"); var middlebit = node.splitText(pos); middlebit.splitText(pat.length); embed.append(embedString); middlebit.parentNode.replaceChild(embed.get(0), middlebit); skip = 1; } } else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) { for (var i = 0; i < node.childNodes.length; ++i) i += findMovieAndEmbed(node.childNodes[i], pat.toUpperCase(), embedString); } return skip; } return context.each(function () { findMovieAndEmbed(this, pat.toUpperCase(), embedString); }); }, mb_embedMovies:function (opt) { var context = $(this); this.options = {}; $.extend(this.options, $.mb_videoEmbedder.defaults, opt); var html = context.html(); if(!html) return; var movies = html.match($.mb_videoEmbedder.regEx); if (!movies) return; $(movies).each(function (i) { var pat = movies[i]; var isYoutube = pat.indexOf("youtube=http://") != -1 || pat.indexOf("youtube=https://") != -1 ; var isYoutubeChannel = pat.indexOf("youtube=http://www.youtube.com/user/") != -1 || pat.indexOf("youtube=https://www.youtube.com/user/") != -1 ; var isVimeo = pat.indexOf("vimeo=http://") != -1 || pat.indexOf("vimeo=https://") != -1; // for CORS call var isVimeoExternal = pat.indexOf("vimeoext=http://")!= -1 || pat.indexOf("vimeoext=https://") != -1; var isUstream = pat.indexOf("ustream=http://") != -1; var isLivestream = pat.indexOf("livestream=http://") != -1; var isFlickr= pat.indexOf("flickr=http://")!=-1; var isDailyMotion = pat.indexOf("dailymotion=http://") != -1; var isFacebook = pat.indexOf("facebook=http://") != -1 || pat.indexOf("facebook=https://") != -1; // FROM: https://youtu.be/ELGNcMSaKJk // TO: https://www.youtube.com/watch?v=ELGNcMSaKJk if(isYoutube) pat = pat.replace('youtu.be/', 'youtube.com/watch?v='); var stringToParse = pat.replace(/\[/g, "").replace(/\]/g, ""); //console.log("stringToParse", stringToParse); var showTitle = !$.mb_videoEmbedder.defaults.youtube.showTitle ? 0 : 1; var vidId = isYoutubeChannel ? stringToParse.split("/")[stringToParse.split("/").length - 1] : isYoutube || isFacebook ? (stringToParse.match(/[\\?&]v=([^]*)/) )[1] : isVimeo ? (stringToParse.match(/\d+/))[0] : isVimeoExternal ? stringToParse.replace('vimeoext=', '') : isUstream ? (stringToParse.match(/\d+/))[0] : isFlickr?(stringToParse.match(/\d+/))[0] : isLivestream ? (stringToParse.replace("livestream=http://www.livestream.com/", "").toLowerCase()) : isDailyMotion ? (stringToParse.substring(stringToParse.lastIndexOf("/")+1, stringToParse.length)) : null; // [facebook=https://www.facebook.com/watch/?v=1080442295448572] var embedString = ''; if(isVimeoExternal) { //embedString = ''; var data = { videoSrc : vidId }; $.ajax({ async:false, data:data, url: contextPath + '/applications/webwork/layout/vimeoExternalViewer.jsp', dataType:'html', cache:false, success: function (html) { embedString = html; $.mb_videoEmbedder.mb_setMovie(context, pat, embedString); } }); } else { //var ratio=isYoutube?(showTitle==1?80.5:68) : (isVimeo ? 57.5 : 65); var ratio = 65; var width = $.mb_videoEmbedder.defaults.width; var height = Math.ceil((width * ratio) / 100); var param = isYoutube ? "&fs=1&rel=0&hd=1&showsearch=0&showinfo=" + showTitle : isVimeo ? "&server=vimeo.com&show_title=" + showTitle + "&show_byline=1&show_portrait=0&color=&fullscreen=1" : isUstream ? "?disabledComment=true&autoplay=false" : isLivestream ? "&color=0xe8e8e8&autoPlay=false&mute=false" : ""; vidId = vidId && vidId!='null' ? vidId : ""; if (isVimeo) { //embedString = ''; embedString = ''; } else if(isYoutube) { embedString = "" } else if(isFacebook) { // embedString = "" var fbScript = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.2"; if(!scriptLoaded(fbScript)) { var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.2"; head.appendChild(script); } embedString = "
" + "