Skip to content

Commit

Permalink
First round of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
starfishmod committed Jul 12, 2011
1 parent edcd860 commit 6362120
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 117 deletions.
42 changes: 42 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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 [email protected])
* 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
78 changes: 36 additions & 42 deletions README
Original file line number Diff line number Diff line change
@@ -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 [email protected])
* 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
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


173 changes: 99 additions & 74 deletions jquery.oembed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 + "?";
Expand All @@ -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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -239,8 +243,8 @@
var oembedContainer = container.next();
if (oembedContainer == null || !oembedContainer.hasClass("oembed-container")) {
oembedContainer = container
.after('<div class="oembed-container"></div>')
.next(".oembed-container");
.after('<div class="oembed-container"></div>')
.next(".oembed-container");
if (oembedData != null && oembedData.provider_name != null)
oembedContainer.toggleClass("oembed-container-" + oembedData.provider_name);
}
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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))
Expand All @@ -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 : '<iframe width="425" height="349" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>'}), // "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 : '<iframe src="http://gigapan.org/gigapans/$1/options/nosnapshots/iframe/flash.html" frameborder="0" height="400" scrolling="no" width="100%"></iframe>'}),
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);
})(jQuery);
Loading

0 comments on commit 6362120

Please sign in to comment.