/*! * Yox YouTube plugin * http://yoxigen.com/yoxview/ * * Copyright (c) 2010 Yossi Kolesnicov * * Licensed under the MIT license. * http://www.opensource.org/licenses/mit-license.php * * Date: 13th November, 2010 * Version : 1.0 */ function yox_youtube() { var $ = jQuery, youtubeRegex = /^http:\/\/(?:www\.)?youtube.com\//, self = this, ytRegex = { singleVideo: /^http:\/\/(?:www\.)?youtube.com\/watch\?v=([^\&]+)(.*)?/, playlist: /^http:\/\/(?:www\.)?youtube.com\/(?:view_play_list|my_playlists)\?p=([^\&]+)(.*)?/, user: /^http:\/\/(?:www\.)?youtube.com\/user\/([^\?]+)(?:\?(.*))?/, search: /^http:\/\/(?:www\.)?youtube.com\/results\?(.*)/ }; this.getImagesData = function(options, callback) { var defaults = { url: "http://gdata.youtube.com/feeds/api/videos", setThumbnails: true, setSingleAlbumThumbnails: true, alt: 'jsonc', thumbsize: 64, v: 2, format: 5, hqThumbnails: false, aspectRatio: "auto" }, isSingleVideo = false, datasourceOptions = jQuery.extend({}, defaults, options.dataSourceOptions); function getDimensionsCalc(){ var widescreenDimensions, defaultDimensions, widescreenAspectRatio = 16/9, defaultIsWidescreen = false; if (!datasourceOptions.width && !datasourceOptions.height) datasourceOptions.width = 720; if ((datasourceOptions.height && !datasourceOptions.width) || (datasourceOptions.width && !datasourceOptions.height)){ if (typeof(datasourceOptions.aspectRatio) === "string"){ if (datasourceOptions.aspectRatio === "auto") datasourceOptions.aspectRatio = 4/3; else{ var ratioValues = datasourceOptions.aspectRatio.split(":"); datasourceOptions.aspectRatio = parseInt(ratioValues[0], 10) / parseInt(ratioValues[1], 10); } } defaultIsWidescreen = datasourceOptions.aspectRatio === 16/9; if (datasourceOptions.height){ widescreenDimensions = { height: datasourceOptions.height, width: datasourceOptions.height * widescreenAspectRatio }; if (!defaultIsWidescreen) defaultDimensions = { height: datasourceOptions.height, width: datasourceOptions.height * datasourceOptions.aspectRatio }; } else{ widescreenDimensions = { width: datasourceOptions.width, height: datasourceOptions.width / widescreenAspectRatio }; if (!defaultIsWidescreen) defaultDimensions = { width: datasourceOptions.width, height: datasourceOptions.width / datasourceOptions.aspectRatio }; } } var getDimensions = function(isWidescreen){ return isWidescreen ? widescreenDimensions : defaultDimensions; } return getDimensions; } var feedType; if (options.dataUrl) { var urlMatch; for (regexType in ytRegex){ urlMatch = options.dataUrl.match(ytRegex[regexType]); if (urlMatch) { feedType = regexType; break; } } if (urlMatch){ switch(feedType){ case "singleVideo": isSingleVideo = true; datasourceOptions.url += "/" + urlMatch[1]; break; case "playlist": datasourceOptions.url = "http://gdata.youtube.com/feeds/api/playlists/" + urlMatch[1]; break; case "user": datasourceOptions.url = "http://gdata.youtube.com/feeds/api/users/" + urlMatch[1] + "/uploads"; break; default: break; } var queryData = Yox.queryToJson(urlMatch.length == 2 ? urlMatch[1] : urlMatch[2]); if (queryData){ if (queryData.search_query){ queryData.q = queryData.search_query; delete queryData.search_query; } $.extend(datasourceOptions, queryData); } } } var getDimensions = getDimensionsCalc(); function getEmbedObject(embedUrl){ var videoPanel = $("