diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..a471283 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,42 @@ +== jquery-oembed ChangeLog == + +== 1.1.0 RC == +* Slideshare native oembed API support (patch by jaipandya) +* Photobucket native oembed API support +* Blip.tv native oembed API support +* Removed providers that are not working (myspace, screenr, qik, revision3) +* Use regex to detect URLs using the regular expressions provided by http://oohembed.com/static/endpoints.json +* Added callback function when specific provider is not found +* Added beforeEmbed and afterEmbed functions +* Support to embed.ly generic oembed provider. +* Support to jquery up to version 1.5 +* Added features examples +* Added supported providers tests +* Allow user to specify ajax options (patch by corneliu...@gmail.com) +* Added onError callback +* BugFix: Incorrect use of $.extend (recommended by rformato) + +Special thanks to Sam Cole, Jai Pandy, Steve and Sean for their patches. + +== 1.0.5 == +* BugFix: Fixed slideshare & revision3 providers +* BugFix: Problem with the "auto" insert method. + +== 1.0.4 == +* Added support for screenr.com videos +* Added support for vids.myspace.com videos +* Fixed a little bug with providers that already have query string parameters + +== 1.0.3 == +* Bugfixes + +== 1.0.2 == +* Added alt attribute to flickr images with image title and author +* New default behavior when executing plug-in. Now it replaces the original element with the oembed code. +* Added three new behaviors for inserting code + +== 1.0.1 == +* Bugfixes + +== 1.0.0 == +* Initial release \ No newline at end of file diff --git a/README b/README index a471283..15bd39c 100644 --- a/README +++ b/README @@ -1,42 +1,36 @@ -== jquery-oembed ChangeLog == - -== 1.1.0 RC == -* Slideshare native oembed API support (patch by jaipandya) -* Photobucket native oembed API support -* Blip.tv native oembed API support -* Removed providers that are not working (myspace, screenr, qik, revision3) -* Use regex to detect URLs using the regular expressions provided by http://oohembed.com/static/endpoints.json -* Added callback function when specific provider is not found -* Added beforeEmbed and afterEmbed functions -* Support to embed.ly generic oembed provider. -* Support to jquery up to version 1.5 -* Added features examples -* Added supported providers tests -* Allow user to specify ajax options (patch by corneliu...@gmail.com) -* Added onError callback -* BugFix: Incorrect use of $.extend (recommended by rformato) - -Special thanks to Sam Cole, Jai Pandy, Steve and Sean for their patches. - -== 1.0.5 == -* BugFix: Fixed slideshare & revision3 providers -* BugFix: Problem with the "auto" insert method. - -== 1.0.4 == -* Added support for screenr.com videos -* Added support for vids.myspace.com videos -* Fixed a little bug with providers that already have query string parameters - -== 1.0.3 == -* Bugfixes - -== 1.0.2 == -* Added alt attribute to flickr images with image title and author -* New default behavior when executing plug-in. Now it replaces the original element with the oembed code. -* Added three new behaviors for inserting code - -== 1.0.1 == -* Bugfixes - -== 1.0.0 == -* Initial release \ No newline at end of file +Jquery-Oembed +============ + +This is a fork of the jquery-oembed located at [jqoembed][http://code.google.com/p/jquery-oembed/]. + +Instead of using oohembed or other such services it tries to embed the object natively. +This project while it will happily use the the oembed framework it is not against using other types of embedding where ever possible. + +Current 3rd party sources include: +* Video + * Youtube + * Blip + * Hulu + * Vimeo + * 5min + * National film board of Canada + * Qik + * Dotsub + * Clickthrough + * Kino Map +* Audio + * Soundcloud + * HuffDuffer +* Photo + * flickr + * photobucket + * instgram + * yfrog + * 23HQ + * Smugmug +* Rich + * Meetup + * gigapans + * Slideshare + + diff --git a/jquery.oembed.js b/jquery.oembed.js index 10d6906..656fa7d 100644 --- a/jquery.oembed.js +++ b/jquery.oembed.js @@ -17,8 +17,8 @@ return this.each(function () { var container = $(this), - resourceURL = (url != null) ? url : container.attr("href"), - provider; + resourceURL = (url != null) ? url : container.attr("href"), + provider; if (embedAction) { settings.onEmbed = embedAction; @@ -64,14 +64,14 @@ beforeEmbed: function () { }, afterEmbed: function () { }, onEmbed: function () { }, - onError: function() {}, - ajaxOptions: {} + onError: function() {}, + ajaxOptions: {} }; /* Private functions */ function getRequestUrl(provider, externalUrl) { - var url = provider.apiendpoint, qs = "", callbackparameter = provider.callbackparameter || "callback", i; + var url = provider.apiendpoint, qs = "", i; if (url.indexOf("?") <= 0) url = url + "?"; @@ -94,45 +94,51 @@ qs += "&" + escape(i) + "=" + provider.params[i]; } - url += "format=json&url=" + escape(externalUrl) + + url += "format="+provider.format+"&url=" + escape(externalUrl) + qs + - "&" + callbackparameter + "=?"; + "&" + provider.callbackparameter + "=?"; return url; }; function embedCode(container, externalUrl, embedProvider) { + if(embedProvider.templateRegex){ + var oembedData = {code: externalUrl.replace(embedProvider.templateRegex,embedProvider.template)}; + settings.beforeEmbed.call(container, oembedData); + settings.onEmbed.call(container, oembedData); + settings.afterEmbed.call(container, oembedData); + + }else{ var requestUrl = getRequestUrl(embedProvider, externalUrl), - ajaxopts = $.extend({ - url: requestUrl, - type: 'get', - dataType: 'json', - // error: jsonp request doesnt' support error handling - success: function (data) { - var oembedData = $.extend({}, data); - switch (oembedData.type) { - case "photo": - oembedData.code = $.fn.oembed.getPhotoCode(externalUrl, oembedData); - break; - case "video": - oembedData.code = $.fn.oembed.getVideoCode(externalUrl, oembedData); - break; - case "rich": - oembedData.code = $.fn.oembed.getRichCode(externalUrl, oembedData); - break; - default: - oembedData.code = $.fn.oembed.getGenericCode(externalUrl, oembedData); - break; - } - settings.beforeEmbed.call(container, oembedData); - settings.onEmbed.call(container, oembedData); - settings.afterEmbed.call(container, oembedData); - }, - error: settings.onError.call(container, externalUrl, embedProvider) - }, settings.ajaxOptions || { } ); - - $.ajax( ajaxopts ); + ajaxopts = $.extend({ + url: requestUrl, + type: 'get', + dataType: 'json', + // error: jsonp request doesnt' support error handling + success: function (data) { + var oembedData = $.extend({}, data); + switch (oembedData.type) { + case "photo": + oembedData.code = $.fn.oembed.getPhotoCode(externalUrl, oembedData); + break; + case "video": + case "rich": + oembedData.code = $.fn.oembed.getRichCode(externalUrl, oembedData); + break; + default: + oembedData.code = $.fn.oembed.getGenericCode(externalUrl, oembedData); + break; + } + settings.beforeEmbed.call(container, oembedData); + settings.onEmbed.call(container, oembedData); + settings.afterEmbed.call(container, oembedData); + }, + error: settings.onError.call(container, externalUrl, embedProvider) + }, settings.ajaxOptions || { } ); + + $.ajax( ajaxopts ); + } }; function initializeProviders() { @@ -181,10 +187,12 @@ activeProviders.push(defaultProvider); } // If any provider has no apiendpoint, we use the default provider endpoint - for (i = 0; i < activeProviders.length; i++) { + /*for (i = 0; i < activeProviders.length; i++) { if (activeProviders[i].apiendpoint == null) activeProviders[i].apiendpoint = defaultProvider.apiendpoint; - } + if (activeProviders[i].format == null) + activeProviders[i].format ='json'; + }*/ } function getDefaultOEmbedProvider(defaultOEmbedProvider) { @@ -206,11 +214,7 @@ } function isNullOrEmpty(object) { - if (typeof object == "undefined") - return true; - if (object == null) - return true; - if ($.isArray(object) && object.length == 0) + if (typeof object == "undefined" || object == null || ($.isArray(object) && object.length == 0)) return true; return false; } @@ -239,8 +243,8 @@ var oembedContainer = container.next(); if (oembedContainer == null || !oembedContainer.hasClass("oembed-container")) { oembedContainer = container - .after('
') - .next(".oembed-container"); + .after('') + .next(".oembed-container"); if (oembedData != null && oembedData.provider_name != null) oembedContainer.toggleClass("oembed-container-" + oembedData.provider_name); } @@ -259,12 +263,6 @@ return code; }; - $.fn.oembed.getVideoCode = function (url, oembedData) { - var code = oembedData.html; - - return code; - }; - $.fn.oembed.getRichCode = function (url, oembedData) { var code = oembedData.html; return code; @@ -291,14 +289,29 @@ return null; }; - $.fn.oembed.OEmbedProvider = function (name, type, urlschemesarray, apiendpoint, callbackparameter) { + $.fn.oembed.OEmbedProvider = function (name, type, urlschemesarray, apiendpoint, extraSettings){//callbackparameter,format) { this.name = name; this.type = type; // "photo", "video", "link", "rich", null this.urlschemes = getUrlSchemes(urlschemesarray); - this.apiendpoint = apiendpoint; - this.callbackparameter = callbackparameter; + this.apiendpoint = apiendpoint ;//|| $.fn.oembed.getDefaultOEmbedProvider($.fn.oembed.defaults.defaultOEmbedProvider); this.maxWidth = 500; this.maxHeight = 400; + + this.fromJSON = function (json) { + for (property in json) { + if (property != "urlschemes") + this[property] = json[property]; + else + this[property] = getUrlSchemes(json[property]); + } + return true; + }; + + if(!isNullOrEmpty(extraSettings))this.fromJSON(extraSettings); + + this.format = this.format || 'json'; + this.callbackparameter = this.callbackparameter || "callback"; + var i, property, regExp; this.matches = function (externalUrl) { @@ -310,15 +323,7 @@ return false; }; - this.fromJSON = function (json) { - for (property in json) { - if (property != "urlschemes") - this[property] = json[property]; - else - this[property] = getUrlSchemes(json[property]); - } - return true; - }; + function getUrlSchemes(urls) { if (isNullOrEmpty(urls)) @@ -331,19 +336,39 @@ /* Native & common providers */ $.fn.oembed.providers = [ - new $.fn.oembed.OEmbedProvider("youtube", "video", ["youtube\\.com/watch.+v=[\\w-]+&?"]), // "http://www.youtube.com/oembed" (no jsonp) - new $.fn.oembed.OEmbedProvider("flickr", "photo", ["flickr\\.com/photos/[-.\\w@]+/\\d+/?"], "http://flickr.com/services/oembed", "jsoncallback"), - new $.fn.oembed.OEmbedProvider("viddler", "video", ["viddler\.com"]), // "http://lab.viddler.com/services/oembed/" (no jsonp) - new $.fn.oembed.OEmbedProvider("blip", "video", ["blip\\.tv/.+"], "http://blip.tv/oembed/"), - new $.fn.oembed.OEmbedProvider("hulu", "video", ["hulu\\.com/watch/.*"], "http://www.hulu.com/api/oembed.json"), + //Video + new $.fn.oembed.OEmbedProvider("youtube", "video", ["youtube\\.com/watch.+v=[\\w-]+&?"],null,{templateRegex:/.*v\=([\w-]+)&?.*/ , template : ''}), // "http://www.youtube.com/oembed" (no jsonp) + new $.fn.oembed.OEmbedProvider("viddler", "video", ["viddler\.com"]), // "http://lab.viddler.com/services/oembed/" (no jsonp) + new $.fn.oembed.OEmbedProvider("blip", "video", ["blip\\.tv/.+"], "http://blip.tv/oembed/"), + new $.fn.oembed.OEmbedProvider("hulu", "video", ["hulu\\.com/watch/.*"], "http://www.hulu.com/api/oembed.json"), new $.fn.oembed.OEmbedProvider("vimeo", "video", ["http:\/\/www\.vimeo\.com\/groups\/.*\/videos\/.*", "http:\/\/www\.vimeo\.com\/.*", "http:\/\/vimeo\.com\/groups\/.*\/videos\/.*", "http:\/\/vimeo\.com\/.*"], "http://vimeo.com/api/oembed.json"), - new $.fn.oembed.OEmbedProvider("dailymotion", "video", ["dailymotion\\.com/.+"]), // "http://www.dailymotion.com/api/oembed/" (callback parameter does not return jsonp) + new $.fn.oembed.OEmbedProvider("dailymotion", "video", ["dailymotion\\.com/.+"],'http://www.dailymotion.com/services/oembed'), + new $.fn.oembed.OEmbedProvider("5min", "video", ["www\\.5min\\.com/.+"], "http://api.5min.com/oembed.json"), + new $.fn.oembed.OEmbedProvider("National Film Board of Canada", "video", ["nfb\\.ca/film/.+"], "http://www.nfb.ca/remote/services/oembed/"), + new $.fn.oembed.OEmbedProvider("qik", "video", ["qik\\.com/\\w+"], "http://qik.com/api/oembed.json"), + new $.fn.oembed.OEmbedProvider("revision3", "video", ["revision3\\.com"], "http://revision3.com/api/oembed/"), + new $.fn.oembed.OEmbedProvider("dotsub", "video", ["dotsub\\.com/view/.+"], "http://dotsub.com/services/oembed"), + new $.fn.oembed.OEmbedProvider("clickthrough", "video", ["clikthrough\\.com/theater/video/\\d+"], "http://clikthrough.com/services/oembed"), + new $.fn.oembed.OEmbedProvider("Kinomap", "video", ["kinomap\\.com/.+"], "http://www.kinomap.com/oembed"), + //Audio + new $.fn.oembed.OEmbedProvider("Huffduffer", "rich", ["huffduffer.com/[-.\\w@]+/\\d+"], "http://huffduffer.com/oembed"), + new $.fn.oembed.OEmbedProvider("Soundcloud", "rich", ["soundcloud.com/.+"], "http://soundcloud.com/oembed",{format:'js'}), + //Photo + new $.fn.oembed.OEmbedProvider("flickr", "photo", ["flickr\\.com/photos/[-.\\w@]+/\\d+/?"], "http://flickr.com/services/oembed"), + new $.fn.oembed.OEmbedProvider("photobucket", "photo", ["photobucket\\.com/(albums|groups)/.+"], "http://photobucket.com/oembed/"), + new $.fn.oembed.OEmbedProvider("instagram", "photo", ["instagr\\.?am(\\.com)?/.+"], "http://api.instagram.com/oembed"), + new $.fn.oembed.OEmbedProvider("yfrog", "photo", ["yfrog\\.(com|ru|com\\.tr|it|fr|co\\.il|co\\.uk|com\\.pl|pl|eu|us)/.+"], "http://www.yfrog.com/api/oembed"), + new $.fn.oembed.OEmbedProvider("23hq", "photo", ["23hq.com/[-.\\w@]/photo/.+"], "http://www.23hq.com/23/oembed"), + new $.fn.oembed.OEmbedProvider("SmugMug", "photo", ["smugmug.com/[-.\\w@]/.+"], "http://api.smugmug.com/services/oembed/"), + //Rich + new $.fn.oembed.OEmbedProvider("meetup", "rich", ["meetup\\.(com|ps)/.+"], "http://api.meetup.com/oembed"), new $.fn.oembed.OEmbedProvider("scribd", "rich", ["scribd\\.com/.+"]), // ", "http://www.scribd.com/services/oembed"" (no jsonp) - new $.fn.oembed.OEmbedProvider("slideshare", "rich", ["slideshare\.net"], "http://www.slideshare.net/api/oembed/1"), - new $.fn.oembed.OEmbedProvider("photobucket", "photo", ["photobucket\\.com/(albums|groups)/.*"], "http://photobucket.com/oembed/") + new $.fn.oembed.OEmbedProvider("gigpans", "rich", ["gigapan\\.org/[-.\\w@]+/\\d+"],null,{templateRegex:/.*\/(\d+)\/?.*/ , template : ''}), + new $.fn.oembed.OEmbedProvider("slideshare", "rich", ["slideshare\.net"], "http://www.slideshare.net/api/oembed/2",{format:'jsonp'}) + // new $.fn.oembed.OEmbedProvider("vids.myspace.com", "video", ["vids\.myspace\.com"]), // "http://vids.myspace.com/index.cfm?fuseaction=oembed" (not working) // new $.fn.oembed.OEmbedProvider("screenr", "rich", ["screenr\.com"], "http://screenr.com/api/oembed.json") (error) - // new $.fn.oembed.OEmbedProvider("qik", "video", ["qik\\.com/\\w+"], "http://qik.com/api/oembed.json"), - // new $.fn.oembed.OEmbedProvider("revision3", "video", ["revision3\.com"], "http://revision3.com/api/oembed/") + // , + // ]; -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/jquery.oembed.min.js b/jquery.oembed.min.js deleted file mode 100644 index b82e30a..0000000 --- a/jquery.oembed.min.js +++ /dev/null @@ -1 +0,0 @@ -(function(d){d.fn.oembed=function(l,k,j){b=d.extend(true,d.fn.oembed.defaults,k);g();return this.each(function(){var m=d(this),n=(l!=null)?l:m.attr("href"),o;if(j){b.onEmbed=j}else{b.onEmbed=function(p){d.fn.oembed.insertCode(this,b.embedMethod,p)}}if(n!=null){o=d.fn.oembed.getOEmbedProvider(n);if(o!=null){o.params=h(b[o.name])||{};o.maxWidth=b.maxWidth;o.maxHeight=b.maxHeight;a(m,n,o)}else{b.onProviderNotFound.call(m,n)}}return m})};var b,e=[];d.fn.oembed.defaults={maxWidth:null,maxHeight:null,embedMethod:"replace",defaultOEmbedProvider:"oohembed",allowedProviders:null,disallowedProviders:null,customProviders:null,defaultProvider:null,greedy:true,onProviderNotFound:function(){},beforeEmbed:function(){},afterEmbed:function(){},onEmbed:function(){},onError:function(){},ajaxOptions:{}};function i(o,n){var k=o.apiendpoint,j="",m=o.callbackparameter||"callback",l;if(k.indexOf("?")<=0){k=k+"?"}else{k=k+"&"}if(o.maxWidth!=null&&o.params.maxwidth==null){o.params.maxwidth=o.maxWidth}if(o.maxHeight!=null&&o.params.maxheight==null){o.params.maxheight=o.maxHeight}for(l in o.params){if(l==o.callbackparameter){continue}if(o.params[l]!=null){j+="&"+escape(l)+"="+o.params[l]}}k+="format=json&url="+escape(n)+j+"&"+m+"=?";return k}function a(j,n,l){var m=i(l,n),k=d.extend({url:m,type:"get",dataType:"json",success:function(p){var o=d.extend({},p);switch(o.type){case"photo":o.code=d.fn.oembed.getPhotoCode(n,o);break;case"video":o.code=d.fn.oembed.getVideoCode(n,o);break;case"rich":o.code=d.fn.oembed.getRichCode(n,o);break;default:o.code=d.fn.oembed.getGenericCode(n,o);break}b.beforeEmbed.call(j,o);b.onEmbed.call(j,o);b.afterEmbed.call(j,o)},error:b.onError.call(j,n,l)},b.ajaxOptions||{});d.ajax(k)}function g(){e=[];var m,j=[],k,l;if(!c(b.allowedProviders)){for(k=0;k