jquery.oembed.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. /*!
  2. * jquery oembed plugin
  3. *
  4. * Copyright (c) 2009 Richard Chamorro
  5. * Licensed under the MIT license
  6. *
  7. * Orignal Author: Richard Chamorro
  8. * Forked by Andrew Mee to Provide a slightly diffent kind of embedding
  9. * experience
  10. */
  11. (function($) {
  12. $.fn.oembed = function(url, options, embedAction) {
  13. settings = $.extend(true, $.fn.oembed.defaults, options);
  14. var shortURLList = ["0rz.tw","1link.in","1url.com","2.gp","2big.at","2tu.us","3.ly","307.to","4ms.me","4sq.com","4url.cc","6url.com","7.ly","a.gg","a.nf","aa.cx","abcurl.net",
  15. "ad.vu","adf.ly","adjix.com","afx.cc","all.fuseurl.com","alturl.com","amzn.to","ar.gy","arst.ch","atu.ca","azc.cc","b23.ru","b2l.me","bacn.me","bcool.bz","binged.it",
  16. "bit.ly","bizj.us","bloat.me","bravo.ly","bsa.ly","budurl.com","canurl.com","chilp.it","chzb.gr","cl.lk", "cl.ly", "clck.ru", "cli.gs", "cliccami.info",
  17. "clickthru.ca", "clop.in", "conta.cc", "cort.as", "cot.ag", "crks.me", "ctvr.us", "cutt.us", "dai.ly", "decenturl.com", "dfl8.me", "digbig.com",
  18. "http:\/\/digg\.com\/[^\/]+$", "disq.us", "dld.bz", "dlvr.it", "do.my", "doiop.com", "dopen.us", "easyuri.com", "easyurl.net", "eepurl.com", "eweri.com",
  19. "fa.by", "fav.me", "fb.me", "fbshare.me", "ff.im", "fff.to", "fire.to", "firsturl.de", "firsturl.net", "flic.kr", "flq.us", "fly2.ws", "fon.gs", "freak.to",
  20. "fuseurl.com", "fuzzy.to", "fwd4.me", "fwib.net", "g.ro.lt", "gizmo.do", "gl.am", "go.9nl.com", "go.ign.com", "go.usa.gov", "goo.gl", "goshrink.com", "gurl.es",
  21. "hex.io", "hiderefer.com", "hmm.ph", "href.in", "hsblinks.com", "htxt.it", "huff.to", "hulu.com", "hurl.me", "hurl.ws", "icanhaz.com", "idek.net", "ilix.in", "is.gd",
  22. "its.my", "ix.lt", "j.mp", "jijr.com", "kl.am", "klck.me", "korta.nu", "krunchd.com", "l9k.net", "lat.ms", "liip.to", "liltext.com", "linkbee.com", "linkbun.ch",
  23. "liurl.cn", "ln-s.net", "ln-s.ru", "lnk.gd", "lnk.ms", "lnkd.in", "lnkurl.com", "lru.jp", "lt.tl", "lurl.no", "macte.ch", "mash.to", "merky.de", "migre.me", "miniurl.com",
  24. "minurl.fr", "mke.me", "moby.to", "moourl.com", "mrte.ch", "myloc.me", "myurl.in", "n.pr", "nbc.co", "nblo.gs", "nn.nf", "not.my", "notlong.com", "nsfw.in",
  25. "nutshellurl.com", "nxy.in", "nyti.ms", "o-x.fr", "oc1.us", "om.ly", "omf.gd", "omoikane.net", "on.cnn.com", "on.mktw.net", "onforb.es", "orz.se", "ow.ly", "ping.fm",
  26. "pli.gs", "pnt.me", "politi.co", "post.ly", "pp.gg", "profile.to", "ptiturl.com", "pub.vitrue.com", "qlnk.net", "qte.me", "qu.tc", "qy.fi", "r.ebay.com", "r.im", "rb6.me", "read.bi",
  27. "readthis.ca", "reallytinyurl.com", "redir.ec", "redirects.ca", "redirx.com", "retwt.me", "ri.ms", "rickroll.it", "riz.gd", "rt.nu", "ru.ly", "rubyurl.com", "rurl.org",
  28. "rww.tw", "s4c.in", "s7y.us", "safe.mn", "sameurl.com", "sdut.us", "shar.es", "shink.de", "shorl.com", "short.ie", "short.to", "shortlinks.co.uk", "shorturl.com",
  29. "shout.to", "show.my", "shrinkify.com", "shrinkr.com", "shrt.fr", "shrt.st", "shrten.com", "shrunkin.com", "simurl.com", "slate.me", "smallr.com", "smsh.me", "smurl.name",
  30. "sn.im", "snipr.com", "snipurl.com", "snurl.com", "sp2.ro", "spedr.com", "srnk.net", "srs.li", "starturl.com","stks.co", "su.pr", "surl.co.uk", "surl.hu", "t.cn", "t.co", "t.lh.com",
  31. "ta.gd", "tbd.ly", "tcrn.ch", "tgr.me", "tgr.ph", "tighturl.com", "tiniuri.com", "tiny.cc", "tiny.ly", "tiny.pl", "tinylink.in", "tinyuri.ca", "tinyurl.com", "tk.", "tl.gd",
  32. "tmi.me", "tnij.org", "tnw.to", "tny.com", "to.ly", "togoto.us", "totc.us", "toysr.us", "tpm.ly", "tr.im", "tra.kz", "trunc.it", "twhub.com", "twirl.at",
  33. "twitclicks.com", "twitterurl.net", "twitterurl.org", "twiturl.de", "twurl.cc", "twurl.nl", "u.mavrev.com", "u.nu", "u76.org", "ub0.cc", "ulu.lu", "updating.me", "ur1.ca",
  34. "url.az", "url.co.uk", "url.ie", "url360.me", "url4.eu", "urlborg.com", "urlbrief.com", "urlcover.com", "urlcut.com", "urlenco.de", "urli.nl", "urls.im",
  35. "urlshorteningservicefortwitter.com", "urlx.ie", "urlzen.com", "usat.ly", "use.my", "vb.ly", "vevo.ly", "vgn.am", "vl.am", "vm.lc", "w55.de", "wapo.st", "wapurl.co.uk", "wipi.es",
  36. "wp.me", "x.vu", "xr.com", "xrl.in", "xrl.us", "xurl.es", "xurl.jp", "y.ahoo.it", "yatuc.com", "ye.pe", "yep.it", "yfrog.com", "yhoo.it", "yiyd.com", "youtu.be", "yuarel.com",
  37. "z0p.de", "zi.ma", "zi.mu", "zipmyurl.com", "zud.me", "zurl.ws", "zz.gd", "zzang.kr", "›.ws", "✩.ws", "✿.ws", "❥.ws", "➔.ws", "➞.ws", "➡.ws", "➨.ws", "➯.ws", "➹.ws", "➽.ws"];
  38. if ($('#jqoembeddata').length === 0) $('<span id="jqoembeddata"></span>').appendTo('body');
  39. return this.each(function() {
  40. var container = $(this),
  41. resourceURL = (url && (!url.indexOf('http://') || !url.indexOf('https://'))) ? url : container.attr("href"),
  42. provider;
  43. if (embedAction) {
  44. settings.onEmbed = embedAction;
  45. }
  46. else if (!settings.onEmbed){
  47. settings.onEmbed = function(oembedData) {
  48. $.fn.oembed.insertCode(this, settings.embedMethod, oembedData);
  49. };
  50. }
  51. if (resourceURL !== null && resourceURL !== undefined) {
  52. //Check if shorten URL
  53. for (var j = 0, l =shortURLList.length; j < l; j++) {
  54. var regExp = new RegExp('://'+shortURLList[j]+'/', "i");
  55. if (resourceURL.match(regExp) !== null) {
  56. //AJAX to http://api.longurl.org/v2/expand?url=http://bit.ly/JATvIs&format=json&callback=hhh
  57. var ajaxopts = $.extend({
  58. url: "http://api.longurl.org/v2/expand",
  59. dataType: 'jsonp',
  60. data: {
  61. url: resourceURL,
  62. format: "json"
  63. //callback: "?"
  64. },
  65. success: function(data) {
  66. //this = $.fn.oembed;
  67. resourceURL = data['long-url'];
  68. provider = $.fn.oembed.getOEmbedProvider(data['long-url']);
  69. if (provider !== null) {
  70. provider.params = getNormalizedParams(settings[provider.name]) || {};
  71. provider.maxWidth = settings.maxWidth;
  72. provider.maxHeight = settings.maxHeight;
  73. embedCode(container, resourceURL, provider);
  74. } else {
  75. settings.onProviderNotFound.call(container, resourceURL);
  76. }
  77. }
  78. }, settings.ajaxOptions || {});
  79. $.ajax(ajaxopts);
  80. return container;
  81. }
  82. }
  83. provider = $.fn.oembed.getOEmbedProvider(resourceURL);
  84. if (provider !== null) {
  85. provider.params = getNormalizedParams(settings[provider.name]) || {};
  86. provider.maxWidth = settings.maxWidth;
  87. provider.maxHeight = settings.maxHeight;
  88. embedCode(container, resourceURL, provider);
  89. } else {
  90. settings.onProviderNotFound.call(container, resourceURL);
  91. }
  92. }
  93. return container;
  94. });
  95. };
  96. var settings;
  97. // Plugin defaults
  98. $.fn.oembed.defaults = {
  99. maxWidth: null,
  100. maxHeight: null,
  101. useResponsiveResize: false,
  102. includeHandle: true,
  103. embedMethod: 'auto',
  104. // "auto", "append", "fill"
  105. onProviderNotFound: function() {},
  106. beforeEmbed: function() {},
  107. afterEmbed: function() {},
  108. onEmbed: false,
  109. onError: function() {},
  110. ajaxOptions: { timeout: 2000 }
  111. };
  112. /*
  113. * check protocol
  114. * @return The protocol correct.
  115. */
  116. function checkProtocol() {
  117. var protocol = window.location.protocol;
  118. // fix local
  119. if (protocol === "file:") {
  120. return "http://";
  121. } else {
  122. protocol += "//";
  123. }
  124. return protocol;
  125. }
  126. /* Private functions */
  127. function rand(length,current){ //Found on http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript
  128. current = current ? current : '';
  129. return length ? rand( --length , "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".charAt( Math.floor( Math.random() * 60 ) ) + current ) : current;
  130. }
  131. function getRequestUrl(provider, externalUrl) {
  132. var url = provider.apiendpoint,
  133. qs = "",
  134. i;
  135. url += (url.indexOf("?") <= 0) ? "?" : "&";
  136. url = url.replace('#','%23');
  137. if (provider.maxWidth !== null && (typeof provider.params.maxwidth === 'undefined' || provider.params.maxwidth === null)) {
  138. provider.params.maxwidth = provider.maxWidth;
  139. }
  140. if (provider.maxHeight !== null && (typeof provider.params.maxheight === 'undefined' || provider.params.maxheight === null)) {
  141. provider.params.maxheight = provider.maxHeight;
  142. }
  143. for (i in provider.params) {
  144. // We don't want them to jack everything up by changing the callback parameter
  145. if (i == provider.callbackparameter) continue;
  146. // allows the options to be set to null, don't send null values to the server as parameters
  147. if (provider.params[i] !== null) qs += "&" + escape(i) + "=" + provider.params[i];
  148. }
  149. url += "format=" + provider.format + "&url=" + escape(externalUrl) + qs;
  150. if(provider.dataType!='json') url += "&" + provider.callbackparameter + "=?";
  151. return url;
  152. }
  153. function success(oembedData, externalUrl, container) {
  154. $('#jqoembeddata').data(externalUrl, oembedData.code);
  155. settings.beforeEmbed.call(container, oembedData);
  156. settings.onEmbed.call(container, oembedData);
  157. settings.afterEmbed.call(container, oembedData);
  158. }
  159. function embedCode(container, externalUrl, embedProvider) {
  160. if ($('#jqoembeddata').data(externalUrl)!=undefined && embedProvider.embedtag.tag!='iframe'){
  161. var oembedData = {code: $('#jqoembeddata').data(externalUrl)};
  162. success(oembedData, externalUrl, container);
  163. }else if (embedProvider.yql) {
  164. var from = embedProvider.yql.from || 'htmlstring';
  165. var url = embedProvider.yql.url ? embedProvider.yql.url(externalUrl) : externalUrl;
  166. var query = 'SELECT * FROM '
  167. + from
  168. + ' WHERE url="' + (url) + '"'
  169. + " and " + (/html/.test(from) ? 'xpath' : 'itemPath') + "='" + (embedProvider.yql.xpath || '/')+"'" ;
  170. if(from=='html') query += " and compat='html5'";
  171. var ajaxopts = $.extend({
  172. url: checkProtocol() + "query.yahooapis.com/v1/public/yql",
  173. dataType: 'jsonp',
  174. data: {
  175. q: query,
  176. format: "json",
  177. env: 'store://datatables.org/alltableswithkeys',
  178. callback: "?"
  179. },
  180. success: function(data) {
  181. var result;
  182. if(embedProvider.yql.xpath && embedProvider.yql.xpath=='//meta|//title|//link'){
  183. var meta={};
  184. if (data.query.results == null) {
  185. data.query.results = {"meta": []};
  186. }
  187. for(var i=0, l=data.query.results.meta.length; i<l; i++){
  188. var name = data.query.results.meta[i].name||data.query.results.meta[i].property||null;
  189. if(name==null)continue;
  190. meta[name.toLowerCase()]=data.query.results.meta[i].content;
  191. }
  192. if (!meta.hasOwnProperty("title") || !meta.hasOwnProperty("og:title") ) {
  193. if ( data.query.results.title != null ) {
  194. meta.title = data.query.results.title;
  195. }
  196. }
  197. if (!meta.hasOwnProperty("og:image") && data.query.results.hasOwnProperty("link")) {
  198. for ( var i=0, l=data.query.results.link.length; i<l; i++){
  199. if ( data.query.results.link[i].hasOwnProperty("rel") ) {
  200. if (data.query.results.link[i].rel == "apple-touch-icon") {
  201. if ( data.query.results.link[i].href.charAt(0) == "/" ) {
  202. meta["og:image"] = url.match(/^(([a-z]+:)?(\/\/)?[^\/]+\/).*$/)[1] + data.query.results.link[i].href;
  203. } else {
  204. meta["og:image"] = data.query.results.link[i].href;
  205. }
  206. }
  207. }
  208. }
  209. }
  210. result = embedProvider.yql.datareturn(meta);
  211. }else{
  212. result = embedProvider.yql.datareturn ? embedProvider.yql.datareturn(data.query.results) : data.query.results.result;
  213. }
  214. if(result===false)return;
  215. var oembedData = $.extend({}, result);
  216. oembedData.code = result;
  217. success(oembedData, externalUrl, container);
  218. },
  219. error: function () {
  220. settings.onError.call(container, externalUrl, embedProvider);
  221. }
  222. }, settings.ajaxOptions || {});
  223. $.ajax(ajaxopts);
  224. }else if (embedProvider.templateRegex) {
  225. if(embedProvider.embedtag.tag!==''){
  226. var flashvars = embedProvider.embedtag.flashvars || '';
  227. var tag = embedProvider.embedtag.tag || 'embed';
  228. var width = embedProvider.embedtag.width || 'auto';
  229. var nocache = embedProvider.embedtag.nocache || 0;
  230. var height = embedProvider.embedtag.height || 'auto';
  231. var src =externalUrl.replace(embedProvider.templateRegex,embedProvider.apiendpoint);
  232. if(!embedProvider.nocache) src += '&jqoemcache='+rand(5);
  233. if (embedProvider.apikey) src = src.replace('_APIKEY_', settings.apikeys[embedProvider.name]);
  234. if (settings.maxHeight && settings.maxWidth) {
  235. if (settings.useResponsiveResize) {
  236. var ratio = 0; // Used for aspect ratio
  237. var newWidth = width;
  238. var newHeight = height;
  239. // Check if the current width is larger than the max
  240. if (width > settings.maxWidth) {
  241. ratio = settings.maxWidth / width;
  242. newWidth = settings.maxWidth;
  243. newHeight = height * ratio;
  244. // reset
  245. height = height * ratio;
  246. width = width * ratio;
  247. }
  248. // Check if current height is larger than max
  249. if (height > settings.maxHeight) {
  250. ratio = settings.maxHeight / height;
  251. newHeight = settings.maxHeight;
  252. newWidth = width * ratio;
  253. // reset
  254. width = width * ratio;
  255. }
  256. height = newHeight;
  257. width = newWidth;
  258. } else {
  259. height = settings.maxHeight;
  260. width = settings.maxWidth;
  261. }
  262. }
  263. var code = $('<'+tag+'/>')
  264. .attr('src',src)
  265. .attr('width',width)
  266. .attr('height',height)
  267. .attr('allowfullscreen',embedProvider.embedtag.allowfullscreen || 'true')
  268. .attr('allowscriptaccess',embedProvider.embedtag.allowfullscreen || 'always')
  269. .css('max-height', settings.maxHeight || 'auto' )
  270. .css('max-width', settings.maxWidth || 'auto' );
  271. if(tag=='embed')
  272. code
  273. .attr('type',embedProvider.embedtag.type || "application/x-shockwave-flash")
  274. .attr('flashvars',externalUrl.replace(embedProvider.templateRegex,flashvars));
  275. if(tag=='iframe')
  276. code
  277. .attr('scrolling',embedProvider.embedtag.scrolling || "no")
  278. .attr('frameborder',embedProvider.embedtag.frameborder || "0");
  279. var oembedData = {code: code};
  280. success(oembedData, externalUrl,container);
  281. }else if (embedProvider.apiendpoint) {
  282. //Add APIkey if true
  283. if (embedProvider.apikey) embedProvider.apiendpoint = embedProvider.apiendpoint.replace('_APIKEY_', settings.apikeys[embedProvider.name]);
  284. ajaxopts = $.extend({
  285. url: externalUrl.replace(embedProvider.templateRegex, embedProvider.apiendpoint),
  286. dataType: 'jsonp',
  287. success: function(data) {
  288. var oembedData = $.extend({}, data);
  289. oembedData.code = embedProvider.templateData(data);
  290. success(oembedData, externalUrl, container);
  291. },
  292. error: function () {
  293. settings.onError.call(container, externalUrl, embedProvider);
  294. }
  295. }, settings.ajaxOptions || {});
  296. $.ajax( ajaxopts );
  297. }else {
  298. var oembedData = {code: externalUrl.replace(embedProvider.templateRegex,embedProvider.template)};
  299. success(oembedData, externalUrl,container);
  300. }
  301. } else {
  302. var requestUrl = getRequestUrl(embedProvider, externalUrl),
  303. ajaxopts = $.extend({
  304. url: requestUrl,
  305. dataType: embedProvider.dataType || 'jsonp',
  306. success: function(data) {
  307. var oembedData = $.extend({}, data);
  308. switch (oembedData.type) {
  309. case "file": //Deviant Art has this
  310. case "photo":
  311. oembedData.code = $.fn.oembed.getPhotoCode(externalUrl, oembedData);
  312. break;
  313. case "video":
  314. case "rich":
  315. oembedData.code = $.fn.oembed.getRichCode(externalUrl, oembedData);
  316. break;
  317. default:
  318. oembedData.code = $.fn.oembed.getGenericCode(externalUrl, oembedData);
  319. break;
  320. }
  321. success(oembedData, externalUrl, container);
  322. },
  323. error: function () {
  324. settings.onError.call(container, externalUrl, embedProvider);
  325. }
  326. }, settings.ajaxOptions || {});
  327. $.ajax(ajaxopts);
  328. }
  329. };
  330. function getNormalizedParams(params) {
  331. if (params === null) return null;
  332. var key, normalizedParams = {};
  333. for (key in params) {
  334. if (key !== null) normalizedParams[key.toLowerCase()] = params[key];
  335. }
  336. return normalizedParams;
  337. }
  338. /* Public functions */
  339. $.fn.oembed.insertCode = function(container, embedMethod, oembedData) {
  340. if (oembedData === null) return;
  341. if(embedMethod=='auto' && container.attr("href") !== null) embedMethod='append';
  342. else if(embedMethod=='auto') embedMethod='replace';
  343. switch (embedMethod) {
  344. case "replace":
  345. container.replaceWith(oembedData.code);
  346. break;
  347. case "fill":
  348. container.html(oembedData.code);
  349. break;
  350. case "append":
  351. container.wrap('<div class="oembedall-container"></div>');
  352. var oembedContainer = container.parent();
  353. if (settings.includeHandle) {
  354. $('<span class="oembedall-closehide">&darr;</span>').insertBefore(container).click(function() {
  355. var encodedString = encodeURIComponent($(this).text());
  356. $(this).html((encodedString == '%E2%86%91') ? '&darr;' : '&uarr;');
  357. $(this).parent().children().last().toggle();
  358. });
  359. }
  360. oembedContainer.append('<br/>');
  361. try {
  362. oembedData.code.clone().appendTo(oembedContainer);
  363. } catch(e) {
  364. oembedContainer.append(oembedData.code);
  365. }
  366. /* Make videos semi-responsive
  367. * If parent div width less than embeded iframe video then iframe gets shrunk to fit smaller width
  368. * If parent div width greater thans embed iframe use the max widht
  369. * - works on youtubes and vimeo
  370. */
  371. /*if (settings.maxWidth) {
  372. var post_width = oembedContainer.parent().width();
  373. if (post_width < settings.maxWidth && settings.useResponsiveResize)
  374. {
  375. var iframe_width_orig = $('iframe',oembedContainer).width();
  376. var iframe_height_orig = $('iframe',oembedContainer).height();
  377. var ratio = iframe_width_orig / post_width;
  378. $('iframe',oembedContainer).width(iframe_width_orig / ratio);
  379. $('iframe',oembedContainer).height(iframe_height_orig / ratio);
  380. } else {
  381. if(settings.maxWidth){
  382. $('iframe',oembedContainer).width(settings.maxWidth);
  383. }
  384. if(settings.maxHeight){
  385. $('iframe',oembedContainer).height(settings.maxHeight);
  386. }
  387. }
  388. }*/
  389. break;
  390. }
  391. };
  392. $.fn.oembed.getPhotoCode = function (url, oembedData) {
  393. var code, alt = oembedData.title ? oembedData.title : '';
  394. alt += oembedData.author_name ? ' - ' + oembedData.author_name : '';
  395. alt += oembedData.provider_name ? ' - ' + oembedData.provider_name : '';
  396. if (oembedData.url) {
  397. code = '<div><a href="' + url + '" target=\'_blank\'><img src="' + oembedData.url + '" alt="' + alt + '"/></a></div>';
  398. } else if (oembedData.thumbnail_url) {
  399. var newURL = oembedData.thumbnail_url.replace('_s', '_b');
  400. code = '<div><a href="' + url + '" target=\'_blank\'><img src="' + newURL + '" alt="' + alt + '"/></a></div>';
  401. } else {
  402. code = '<div>Error loading this picture</div>';
  403. }
  404. if (oembedData.html) code += "<div>" + oembedData.html + "</div>";
  405. return code;
  406. };
  407. $.fn.oembed.getRichCode = function(url, oembedData) {
  408. var code = oembedData.html;
  409. return code;
  410. };
  411. $.fn.oembed.getGenericCode = function(url, oembedData) {
  412. var title = (oembedData.title !== null) ? oembedData.title : url,
  413. code = '<a href="' + url + '">' + title + '</a>';
  414. if (oembedData.html) code += "<div>" + oembedData.html + "</div>";
  415. return code;
  416. };
  417. $.fn.oembed.getOEmbedProvider = function(url) {
  418. for (var i = 0; i < $.fn.oembed.providers.length; i++) {
  419. for (var j = 0, l =$.fn.oembed.providers[i].urlschemes.length; j < l; j++) {
  420. var regExp = new RegExp($.fn.oembed.providers[i].urlschemes[j], "i");
  421. if (url.match(regExp) !== null) return $.fn.oembed.providers[i];
  422. }
  423. }
  424. return null;
  425. };
  426. $.fn.oembed.OEmbedProvider = function(name, type, urlschemesarray, apiendpoint, extraSettings) {
  427. this.name = name;
  428. this.type = type; // "photo", "video", "link", "rich", null
  429. this.urlschemes = urlschemesarray;
  430. this.apiendpoint = apiendpoint;
  431. this.maxWidth = 500;
  432. this.maxHeight = 400;
  433. extraSettings =extraSettings ||{};
  434. if(extraSettings.useYQL){
  435. if(extraSettings.useYQL=='xml'){
  436. extraSettings.yql = {xpath:"//oembed/html", from:'xml'
  437. , apiendpoint: this.apiendpoint
  438. , url: function(externalurl){return this.apiendpoint+'?format=xml&url='+externalurl; }
  439. , datareturn:function(results){return results.html.replace(/.*\[CDATA\[(.*)\]\]>$/,'$1') || ''; }
  440. };
  441. }else{
  442. extraSettings.yql = {from:'json'
  443. , apiendpoint: this.apiendpoint
  444. , url: function(externalurl){return this.apiendpoint+'?format=json&url='+externalurl; }
  445. , datareturn: function (results) {
  446. if (results.json.type != 'video' && (results.json.url || results.json.thumbnail_url)) {
  447. return '<img src="' + (results.json.url || results.json.thumbnail_url) + '" />';
  448. } else if (results.json.html.indexOf("iframe")) {
  449. // Quick fix to handle attribute less html5 properties in ckeditor
  450. if (results.json.html.indexOf("allowfullscreen>")) {
  451. results.json.html = results.json.html.replace('allowfullscreen>', 'allowfullscreen="false">');
  452. }
  453. var html = $.parseHTML(results.json.html);
  454. var width = html[0].width;
  455. var height = html[0].height;
  456. if (settings.maxHeight && settings.maxWidth) {
  457. if (settings.useResponsiveResize) {
  458. var ratio;
  459. var newWidth = width;
  460. var newHeight = height;
  461. // Check if the current width is larger than the max
  462. if (width > settings.maxWidth) {
  463. ratio = settings.maxWidth / width;
  464. newWidth = settings.maxWidth;
  465. newHeight = height * ratio;
  466. // reset
  467. height = height * ratio;
  468. width = width * ratio;
  469. }
  470. // Check if current height is larger than max
  471. if (height > settings.maxHeight) {
  472. ratio = settings.maxHeight / height;
  473. newHeight = settings.maxHeight;
  474. newWidth = width * ratio;
  475. }
  476. height = newHeight;
  477. width = newWidth;
  478. } else {
  479. height = settings.maxHeight;
  480. width = settings.maxWidth;
  481. }
  482. }
  483. html[0].width = width;
  484. html[0].height = height;
  485. return html[0].outerHTML;
  486. }
  487. return results.json.html || '';
  488. }
  489. };
  490. }
  491. this.apiendpoint = null;
  492. }
  493. for (var property in extraSettings) {
  494. this[property] = extraSettings[property];
  495. }
  496. this.format = this.format || 'json';
  497. this.callbackparameter = this.callbackparameter || "callback";
  498. this.embedtag = this.embedtag || {tag:""};
  499. };
  500. /*
  501. * Function to update existing providers
  502. *
  503. * @param {String} name The name of the provider
  504. * @param {String} type The type of the provider can be "file", "photo", "video", "rich"
  505. * @param {String} urlshemesarray Array of url of the provider
  506. * @param {String} apiendpoint The endpoint of the provider
  507. * @param {String} extraSettings Extra settings of the provider
  508. */
  509. $.fn.updateOEmbedProvider = function (name, type, urlschemesarray, apiendpoint, extraSettings) {
  510. for (var i = 0; i < $.fn.oembed.providers.length; i++) {
  511. if ($.fn.oembed.providers[i].name === name) {
  512. if (type !== null) {
  513. $.fn.oembed.providers[i].type = type;
  514. }
  515. if (urlschemesarray !== null) {
  516. $.fn.oembed.providers[i].urlschemes = urlschemesarray;
  517. }
  518. if (apiendpoint !== null) {
  519. $.fn.oembed.providers[i].apiendpoint = apiendpoint;
  520. }
  521. if (extraSettings !== null) {
  522. $.fn.oembed.providers[i].extraSettings = extraSettings;
  523. for (var property in extraSettings) {
  524. if (extraSettings[property] !== null) {
  525. $.fn.oembed.providers[i][property] = extraSettings[property];
  526. }
  527. }
  528. }
  529. }
  530. }
  531. };
  532. /* Native & common providers */
  533. $.fn.oembed.providers = [
  534. //Video
  535. //new $.fn.oembed.OEmbedProvider("youtube", "video", ["youtube\\.com/watch.+v=[\\w-]+&?", "youtu\\.be/[\\w-]+", "youtube.com/embed"], checkProtocol() + 'www.youtube.com/embed/$1?wmode=transparent', {
  536. // templateRegex: /.*(?:v\=|be\/|embed\/)([\w\-]+)&?.*/,embedtag: {tag: 'iframe',width: '425',height: '349'}
  537. //}),
  538. new $.fn.oembed.OEmbedProvider("youtube", "video", ["youtube\\.com/watch.+v=[\\w-]+&?", "youtu\\.be/[\\w-]+"], checkProtocol() + 'www.youtube.com/oembed', {useYQL:'json'}),
  539. new $.fn.oembed.OEmbedProvider("youtubeiframe", "video", ["youtube.com/embed"], "$1?wmode=transparent",
  540. {templateRegex:/(.*)/,embedtag : {tag: 'iframe', width:'425',height: '349'}}),
  541. new $.fn.oembed.OEmbedProvider("wistia", "video", ["wistia.com/m/.+", "wistia.com/embed/.+","wi.st/m/.+","wi.st/embed/.+"], 'http://fast.wistia.com/oembed', {useYQL:'json'}),
  542. new $.fn.oembed.OEmbedProvider("xtranormal", "video", ["xtranormal\\.com/watch/.+"], "http://www.xtranormal.com/xtraplayr/$1/$2", {
  543. templateRegex: /.*com\/watch\/([\w\-]+)\/([\w\-]+).*/,embedtag: {tag: 'iframe',width: '320',height: '269'}}),
  544. new $.fn.oembed.OEmbedProvider("scivee", "video", ["scivee.tv/node/.+"], "http://www.scivee.tv/flash/embedCast.swf?", {
  545. templateRegex: /.*tv\/node\/(.+)/,embedtag: {width: '480',height: '400',flashvars:"id=$1&type=3"}}),
  546. new $.fn.oembed.OEmbedProvider("veoh", "video", ["veoh.com/watch/.+"], "http://www.veoh.com/swf/webplayer/WebPlayer.swf?version=AFrontend.5.7.0.1337&permalinkId=$1&player=videodetailsembedded&videoAutoPlay=0&id=anonymous", {
  547. templateRegex: /.*watch\/([^\?]+).*/,embedtag: {width: '410',height: '341'}}),
  548. new $.fn.oembed.OEmbedProvider("gametrailers", "video", ["gametrailers\\.com/video/.+"], "http://media.mtvnservices.com/mgid:moses:video:gametrailers.com:$2", {
  549. templateRegex: /.*com\/video\/([\w\-]+)\/([\w\-]+).*/,embedtag: {width: '512',height: '288' }}),
  550. new $.fn.oembed.OEmbedProvider("funnyordie", "video", ["funnyordie\\.com/videos/.+"], "http://player.ordienetworks.com/flash/fodplayer.swf?", {
  551. templateRegex: /.*videos\/([^\/]+)\/([^\/]+)?/,embedtag: {width: 512,height: 328,flashvars: "key=$1"}}),
  552. new $.fn.oembed.OEmbedProvider("colledgehumour", "video", ["collegehumor\\.com/video/.+"],"http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=$1&use_node_id=true&fullscreen=1",
  553. {templateRegex:/.*video\/([^\/]+).*/ , embedtag : {width:600,height: 338}}),
  554. new $.fn.oembed.OEmbedProvider("metacafe", "video", ["metacafe\\.com/watch/.+"],"http://www.metacafe.com/fplayer/$1/$2.swf",
  555. {templateRegex:/.*watch\/(\d+)\/(\w+)\/.*/ , embedtag : {width:400,height: 345}}),
  556. new $.fn.oembed.OEmbedProvider("bambuser", "video", ["bambuser\\.com\/channel\/.*\/broadcast\/.*"],"http://static.bambuser.com/r/player.swf?vid=$1",
  557. {templateRegex:/.*bambuser\.com\/channel\/.*\/broadcast\/(\w+).*/ , embedtag : {width:512,height: 339 }}),
  558. new $.fn.oembed.OEmbedProvider("twitvid", "video", ["twitvid\\.com/.+"],"http://www.twitvid.com/embed.php?guid=$1&autoplay=0",
  559. {templateRegex:/.*twitvid\.com\/(\w+).*/ , embedtag : {tag:'iframe',width:480,height: 360 }}),
  560. new $.fn.oembed.OEmbedProvider("aniboom", "video", ["aniboom\\.com/animation-video/.+"],"http://api.aniboom.com/e/$1",
  561. {templateRegex:/.*animation-video\/(\d+).*/ , embedtag : {width:594,height: 334}}),
  562. new $.fn.oembed.OEmbedProvider("vzaar", "video", ["vzaar\\.com/videos/.+","vzaar.tv/.+"],"http://view.vzaar.com/$1/player?",
  563. {templateRegex:/.*\/(\d+).*/, embedtag : {tag:'iframe',width:576,height: 324 }}),
  564. new $.fn.oembed.OEmbedProvider("snotr", "video", ["snotr\\.com/video/.+"],"http://www.snotr.com/embed/$1",
  565. {templateRegex:/.*\/(\d+).*/, embedtag : {tag:'iframe',width:400,height: 330, nocache:1 }}),
  566. new $.fn.oembed.OEmbedProvider("youku", "video", ["v.youku.com/v_show/id_.+"],"http://player.youku.com/player.php/sid/$1/v.swf",
  567. {templateRegex:/.*id_(.+)\.html.*/, embedtag : {width:480,height:400, nocache:1 }}),
  568. new $.fn.oembed.OEmbedProvider("tudou", "video", ["tudou.com/programs/view/.+\/"],"http://www.tudou.com/v/$1/v.swf",
  569. {templateRegex:/.*view\/(.+)\//, embedtag : {width:480,height:400, nocache:1 }}),
  570. new $.fn.oembed.OEmbedProvider("embedr", "video", ["embedr\\.com/playlist/.+"],"http://embedr.com/swf/slider/$1/425/520/default/false/std?",
  571. {templateRegex:/.*playlist\/([^\/]+).*/, embedtag : {width:425,height: 520}}),
  572. new $.fn.oembed.OEmbedProvider("blip", "video", ["blip\\.tv/.+"], "http://blip.tv/oembed/"),
  573. new $.fn.oembed.OEmbedProvider("minoto-video", "video", ["http://api.minoto-video.com/publishers/.+/videos/.+","http://dashboard.minoto-video.com/main/video/details/.+","http://embed.minoto-video.com/.+"], "http://api.minoto-video.com/services/oembed.json",{useYQL:'json'}),
  574. new $.fn.oembed.OEmbedProvider("animoto", "video", ["animoto.com/play/.+"], "http://animoto.com/services/oembed"),
  575. new $.fn.oembed.OEmbedProvider("hulu", "video", ["hulu\\.com/watch/.*"], "http://www.hulu.com/api/oembed.json"),
  576. new $.fn.oembed.OEmbedProvider("ustream", "video", ["ustream\\.tv/recorded/.*"], "http://www.ustream.tv/oembed",{useYQL:'json'}),
  577. new $.fn.oembed.OEmbedProvider("videojug", "video", ["videojug\\.com/(film|payer|interview).*"], "http://www.videojug.com/oembed.json",{useYQL:'json'}),
  578. new $.fn.oembed.OEmbedProvider("sapo", "video", ["videos\\.sapo\\.pt/.*"], "http://videos.sapo.pt/oembed",{useYQL:'json'}),
  579. new $.fn.oembed.OEmbedProvider("vodpod", "video", ["vodpod.com/watch/.*"], "http://vodpod.com/oembed.js",{useYQL:'json'}),
  580. new $.fn.oembed.OEmbedProvider("vimeo", "video", ["www\.vimeo\.com\/groups\/.*\/videos\/.*", "www\.vimeo\.com\/.*", "vimeo\.com\/groups\/.*\/videos\/.*", "vimeo\.com\/.*"], "//vimeo.com/api/oembed.json"),
  581. new $.fn.oembed.OEmbedProvider("dailymotion", "video", ["dailymotion\\.com/.+"],'http://www.dailymotion.com/services/oembed'),
  582. new $.fn.oembed.OEmbedProvider("5min", "video", ["www\\.5min\\.com/.+"], 'http://api.5min.com/oembed.xml',{useYQL:'xml'}),
  583. new $.fn.oembed.OEmbedProvider("National Film Board of Canada", "video", ["nfb\\.ca/film/.+"],'http://www.nfb.ca/remote/services/oembed/',{useYQL:'json'}),
  584. new $.fn.oembed.OEmbedProvider("qik", "video", ["qik\\.com/\\w+"], 'http://qik.com/api/oembed.json',{useYQL:'json'}),
  585. new $.fn.oembed.OEmbedProvider("revision3", "video", ["revision3\\.com"], "http://revision3.com/api/oembed/"),
  586. new $.fn.oembed.OEmbedProvider("dotsub", "video", ["dotsub\\.com/view/.+"], "http://dotsub.com/services/oembed",{useYQL:'json'}),
  587. new $.fn.oembed.OEmbedProvider("clikthrough", "video", ["clikthrough\\.com/theater/video/\\d+"], "http://clikthrough.com/services/oembed"),
  588. new $.fn.oembed.OEmbedProvider("Kinomap", "video", ["kinomap\\.com/.+"], "http://www.kinomap.com/oembed"),
  589. new $.fn.oembed.OEmbedProvider("VHX", "video", ["vhx.tv/.+"], "http://vhx.tv/services/oembed.json"),
  590. new $.fn.oembed.OEmbedProvider("bambuser", "video", ["bambuser.com/.+"], "http://api.bambuser.com/oembed/iframe.json"),
  591. new $.fn.oembed.OEmbedProvider("justin.tv", "video", ["justin.tv/.+"], 'http://api.justin.tv/api/embed/from_url.json',{useYQL:'json'}),
  592. //Audio
  593. new $.fn.oembed.OEmbedProvider("official.fm", "rich", ["official.fm/.+"], 'http://official.fm/services/oembed',{useYQL:'json'}),
  594. new $.fn.oembed.OEmbedProvider("chirbit", "rich", ["chirb.it/.+"], 'http://chirb.it/oembed.json',{useYQL:'json'}),
  595. new $.fn.oembed.OEmbedProvider("Huffduffer", "rich", ["huffduffer.com/[-.\\w@]+/\\d+"], "http://huffduffer.com/oembed"),
  596. new $.fn.oembed.OEmbedProvider("Spotify", "rich", ["open.spotify.com/(track|album|user)/"], "https://embed.spotify.com/oembed/"),
  597. new $.fn.oembed.OEmbedProvider("shoudio", "rich", ["shoudio.com/.+","shoud.io/.+"], "http://shoudio.com/api/oembed"),
  598. new $.fn.oembed.OEmbedProvider("mixcloud", "rich", ["mixcloud.com/.+"], checkProtocol() + 'www.mixcloud.com/oembed/', { useYQL: 'json' }),
  599. new $.fn.oembed.OEmbedProvider("rdio.com", "rich", ["rd.io/.+", "rdio.com"], checkProtocol() + "www.rdio.com/api/oembed/"),
  600. new $.fn.oembed.OEmbedProvider("Soundcloud", "rich", ["soundcloud.com/.+", "snd.sc/.+"], checkProtocol() + "soundcloud.com/oembed", { format: 'js' }),
  601. new $.fn.oembed.OEmbedProvider("bandcamp", "rich", ["bandcamp\\.com/album/.+"], null,
  602. {yql:{xpath:"//meta[contains(@content, \\'EmbeddedPlayer\\')]", from:'html'
  603. , datareturn:function(results){
  604. return results.meta ?'<iframe width="400" height="100" src="'+results.meta.content+'" allowtransparency="true" frameborder="0"></iframe>':false;
  605. }
  606. }
  607. }),
  608. //Photo
  609. new $.fn.oembed.OEmbedProvider("deviantart", "photo", ["deviantart.com/.+","fav.me/.+","deviantart.com/.+"], "http://backend.deviantart.com/oembed",{format:'jsonp'}),
  610. new $.fn.oembed.OEmbedProvider("skitch", "photo", ["skitch.com/.+"], null,
  611. {yql:{xpath:"json", from:'json'
  612. , url: function(externalurl){return 'http://skitch.com/oembed/?format=json&url='+externalurl; }
  613. , datareturn:function(data){return $.fn.oembed.getPhotoCode( data.json.url, data.json);}
  614. }
  615. }),
  616. new $.fn.oembed.OEmbedProvider("mobypicture", "photo", ["mobypicture.com/user/.+/view/.+","moby.to/.+"], "http://api.mobypicture.com/oEmbed"),
  617. new $.fn.oembed.OEmbedProvider("flickr", "photo", ["flickr\\.com/photos/.+"], "http://flickr.com/services/oembed",{callbackparameter:'jsoncallback'}),
  618. new $.fn.oembed.OEmbedProvider("photobucket", "photo", ["photobucket\\.com/(albums|groups)/.+"], checkProtocol() + "photobucket.com/oembed/"),
  619. new $.fn.oembed.OEmbedProvider("instagram", "photo", ["instagr\\.?am(\\.com)?/.+"], checkProtocol() + "api.instagram.com/oembed"),
  620. //new $.fn.oembed.OEmbedProvider("yfrog", "photo", ["yfrog\\.(com|ru|com\\.tr|it|fr|co\\.il|co\\.uk|com\\.pl|pl|eu|us)/.+"], checkProtocol() + "www.yfrog.com/api/oembed",{useYQL:"json"}),
  621. new $.fn.oembed.OEmbedProvider("SmugMug", "photo", ["smugmug.com/[-.\\w@]+/.+"], "http://api.smugmug.com/services/oembed/"),
  622. new $.fn.oembed.OEmbedProvider("dribbble", "photo", ["dribbble.com/shots/.+"], "http://api.dribbble.com/shots/$1?callback=?",
  623. { templateRegex:/.*shots\/([\d]+).*/,
  624. templateData : function(data){if(!data.image_teaser_url)return false;
  625. return '<img src="'+data.image_teaser_url+'"/>';
  626. }
  627. }),
  628. new $.fn.oembed.OEmbedProvider("chart.ly", "photo", ["chart\\.ly/[a-z0-9]{6,8}"],"http://chart.ly/uploads/large_$1.png",
  629. {templateRegex:/.*ly\/([^\/]+).*/ , embedtag : {tag:'img'},nocache:1}),
  630. //new $.fn.oembed.OEmbedProvider("stocktwits.com", "photo", ["stocktwits\\.com/message/.+"], "http://charts.stocktwits.com/production/original_$1.png?",
  631. // { templateRegex: /.*message\/([^\/]+).*/, embedtag: { tag: 'img'},nocache:1 }),
  632. new $.fn.oembed.OEmbedProvider("circuitlab", "photo", ["circuitlab.com/circuit/.+"],"https://www.circuitlab.com/circuit/$1/screenshot/540x405/",
  633. {templateRegex:/.*circuit\/([^\/]+).*/ , embedtag : {tag:'img'},nocache:1}),
  634. new $.fn.oembed.OEmbedProvider("23hq", "photo", ["23hq.com/[-.\\w@]+/photo/.+"],"http://www.23hq.com/23/oembed",{useYQL:"json"}),
  635. new $.fn.oembed.OEmbedProvider("img.ly", "photo", ["img\\.ly/.+"],"http://img.ly/show/thumb/$1",
  636. {templateRegex:/.*ly\/([^\/]+).*/ , embedtag : {tag:'img'},nocache:1
  637. }),
  638. new $.fn.oembed.OEmbedProvider("twitgoo.com", "photo", ["twitgoo\\.com/.+"],"http://twitgoo.com/show/thumb/$1",
  639. {templateRegex:/.*com\/([^\/]+).*/ , embedtag : {tag:'img'},nocache:1}),
  640. new $.fn.oembed.OEmbedProvider("imgur.com", "photo", ["imgur\\.com/gallery/.+"], checkProtocol() + "imgur.com/$1l.jpg",
  641. {templateRegex:/.*gallery\/([^\/]+).*/ , embedtag : {tag:'img'},nocache:1}),
  642. new $.fn.oembed.OEmbedProvider("visual.ly", "rich", ["visual\\.ly/.+"], null,
  643. {yql:{xpath:"//a[@id=\\'gc_article_graphic_image\\']/img", from:'htmlstring'}
  644. }),
  645. new $.fn.oembed.OEmbedProvider("gravtar", "photo", ["mailto:.+"],null,
  646. {templateRegex:/mailto:([^\/]+).*/
  647. , template : function(wm,email){
  648. return '<img src="http://gravatar.com/avatar/'+email.md5()+'.jpg" alt="on Gravtar" class="jqoaImg">';
  649. }
  650. }),
  651. //Rich
  652. new $.fn.oembed.OEmbedProvider("twitter", "rich", ["twitter.com/.+"], "https://api.twitter.com/1/statuses/oembed.json"),
  653. new $.fn.oembed.OEmbedProvider("gmep", "rich", ["gmep.imeducate.com/.*","gmep.org/.*"], "http://gmep.org/oembed.json"),
  654. new $.fn.oembed.OEmbedProvider("urtak", "rich", ["urtak.com/(u|clr)/.+"], "http://oembed.urtak.com/1/oembed"),
  655. new $.fn.oembed.OEmbedProvider("cacoo", "rich", ["cacoo.com/.+"], "http://cacoo.com/oembed.json"),
  656. new $.fn.oembed.OEmbedProvider("dailymile", "rich", ["dailymile.com/people/.*/entries/.*"], "http://api.dailymile.com/oembed"),
  657. new $.fn.oembed.OEmbedProvider("dipity", "rich", ["dipity.com/timeline/.+"],'http://www.dipity.com/oembed/timeline/',{useYQL:'json'}),
  658. new $.fn.oembed.OEmbedProvider("sketchfab", "rich", ["sketchfab.com/show/.+"],'http://sketchfab.com/oembed',{useYQL:'json'}),
  659. new $.fn.oembed.OEmbedProvider("speakerdeck", "rich", ["speakerdeck.com/.+"],'http://speakerdeck.com/oembed.json',{useYQL:'json'}),
  660. new $.fn.oembed.OEmbedProvider("popplet", "rich", ["popplet.com/app/.*"],"http://popplet.com/app/Popplet_Alpha.swf?page_id=$1&em=1",
  661. {templateRegex:/.*#\/([^\/]+).*/,embedtag : {width:460,height: 460} }),
  662. new $.fn.oembed.OEmbedProvider("pearltrees", "rich", ["pearltrees.com/.*"],"http://cdn.pearltrees.com/s/embed/getApp?",
  663. {templateRegex:/.*N-f=1_(\d+).*N-p=(\d+).*/, embedtag : {width:460,height: 460,
  664. flashvars : "lang=en_US&amp;embedId=pt-embed-$1-693&amp;treeId=$1&amp;pearlId=$2&amp;treeTitle=Diagrams%2FVisualization&amp;site=www.pearltrees.com%2FF"}
  665. }),
  666. new $.fn.oembed.OEmbedProvider("prezi", "rich", ["prezi.com/.*"],"http://prezi.com/bin/preziloader.swf?",
  667. {templateRegex:/.*com\/([^\/]+)\/.*/,embedtag : {width:550,height: 400,
  668. flashvars : "prezi_id=$1&amp;lock_to_path=0&amp;color=ffffff&amp;autoplay=no&amp;autohide_ctrls=0"
  669. }
  670. }),
  671. new $.fn.oembed.OEmbedProvider("tourwrist", "rich", ["tourwrist.com/tours/.+"], null,
  672. { templateRegex:/.*tours.([\d]+).*/,
  673. template : function(wm,tourid){
  674. setTimeout(function(){if(loadEmbeds)loadEmbeds();},2000);
  675. return "<div id='"+tourid+"' class='tourwrist-tour-embed direct'></div> <script type='text/javascript' src='http://tourwrist.com/tour_embed.js'></script>";
  676. }
  677. }),
  678. new $.fn.oembed.OEmbedProvider("meetup", "rich", ["meetup\\.(com|ps)/.+"], checkProtocol() + "api.meetup.com/oembed"),
  679. new $.fn.oembed.OEmbedProvider("ebay", "rich", ["ebay\\.*"], checkProtocol() + "togo.ebay.com/togo/togo.swf?2008013100",
  680. {templateRegex:/.*\/([^\/]+)\/(\d{10,13}).*/, embedtag : {width:355,height: 300,
  681. flashvars : "base=http://togo.ebay.com/togo/&lang=en-us&mode=normal&itemid=$2&query=$1"
  682. }
  683. }),
  684. new $.fn.oembed.OEmbedProvider("wikipedia", "rich", ["wikipedia.org/wiki/.+"], "http://$1.wikipedia.org/w/api.php?action=parse&page=$2&format=json&section=0&callback=?",{
  685. templateRegex:/.*\/\/([\w]+).*\/wiki\/([^\/]+).*/,
  686. templateData : function(data){if(!data.parse)return false;
  687. var text = data.parse['text']['*'].replace(/href="\/wiki/g,'href="http://en.wikipedia.org/wiki');
  688. return '<div id="content"><h3><a class="nav-link" href="http://en.wikipedia.org/wiki/'+data.parse['displaytitle']+'">'+data.parse['displaytitle']+'</a></h3>'+text+'</div>';
  689. }
  690. }),
  691. new $.fn.oembed.OEmbedProvider("imdb", "rich", ["imdb.com/title/.+"], "http://www.imdbapi.com/?i=$1&callback=?",
  692. {templateRegex:/.*\/title\/([^\/]+).*/,
  693. templateData : function(data){if(!data.Title)return false;
  694. return '<div id="content"><h3><a class="nav-link" href="http://imdb.com/title/'+data.ID+'/">'+data.Title+'</a> ('+data.Year+')</h3><p>Starring: '+data.Actors+'</p><div id="photo-wrap" style="margin: auto;width:600px;height:450px;"><img class="photo" id="photo-display" src="'+data.Poster+'" alt="'+data.Title+'"></div> <div id="view-photo-caption">'+data.Plot+'</div></div>';
  695. }
  696. }),
  697. new $.fn.oembed.OEmbedProvider("livejournal", "rich", ["livejournal.com/"], "http://ljpic.seacrow.com/json/$2$4?jsonp=?"
  698. ,{templateRegex:/(http:\/\/(((?!users).)+)\.livejournal\.com|.*users\.livejournal\.com\/([^\/]+)).*/,
  699. templateData : function(data){if(!data.username)return false;
  700. return '<div><img src="'+data.image+'" align="left" style="margin-right: 1em;" /><span class="oembedall-ljuser"><a href="http://'+data.username+'.livejournal.com/profile"><img src="http://www.livejournal.com/img/userinfo.gif" alt="[info]" width="17" height="17" /></a><a href="http://'+data.username+'.livejournal.com/">'+data.username+'</a></span><br />'+data.name+'</div>';
  701. }
  702. }),
  703. new $.fn.oembed.OEmbedProvider("circuitbee", "rich", ["circuitbee\\.com/circuit/view/.+"],"http://c.circuitbee.com/build/r/schematic-embed.html?id=$1",
  704. {templateRegex:/.*circuit\/view\/(\d+).*/ ,embedtag : {tag: 'iframe', width:'500',height: '350'}
  705. }),
  706. new $.fn.oembed.OEmbedProvider("googlecalendar", "rich", ["www.google.com/calendar/embed?.+"],"$1",
  707. {templateRegex:/(.*)/ ,embedtag : {tag: 'iframe', width:'800',height: '600' }
  708. }),
  709. new $.fn.oembed.OEmbedProvider("jsfiddle", "rich", ["jsfiddle.net/[^/]+/?"],"http://jsfiddle.net/$1/embedded/result,js,resources,html,css/?",
  710. {templateRegex:/.*net\/([^\/]+).*/ ,embedtag : {tag: 'iframe', width:'100%',height: '300' }
  711. }),
  712. new $.fn.oembed.OEmbedProvider("jsbin", "rich", ["jsbin.com/.+"],"http://jsbin.com/$1/?",
  713. {templateRegex:/.*com\/([^\/]+).*/ ,embedtag : {tag: 'iframe', width:'100%',height: '300' }
  714. }),
  715. new $.fn.oembed.OEmbedProvider("jotform", "rich", ["form.jotform.co/form/.+"],"$1?",
  716. {templateRegex:/(.*)/ ,embedtag : {tag: 'iframe', width:'100%',height: '507' }
  717. }),
  718. new $.fn.oembed.OEmbedProvider("reelapp", "rich", ["reelapp\\.com/.+"],"http://www.reelapp.com/$1/embed",
  719. {templateRegex:/.*com\/(\S{6}).*/ ,embedtag : {tag: 'iframe', width:'400',height: '338'}
  720. }),
  721. new $.fn.oembed.OEmbedProvider("linkedin", "rich", ["linkedin.com/pub/.+"],"https://www.linkedin.com/cws/member/public_profile?public_profile_url=$1&format=inline&isFramed=true",
  722. {templateRegex:/(.*)/ ,embedtag : {tag: 'iframe', width:'368px',height: 'auto'}
  723. }),
  724. new $.fn.oembed.OEmbedProvider("timetoast", "rich", ["timetoast.com/timelines/[0-9]+"],"http://www.timetoast.com/flash/TimelineViewer.swf?passedTimelines=$1",
  725. {templateRegex:/.*timelines\/([0-9]*)/ ,embedtag : { width:550,height: 400,nocache:1}
  726. }),
  727. new $.fn.oembed.OEmbedProvider("pastebin", "rich", ["pastebin\\.com/[\\S]{8}"],"http://pastebin.com/embed_iframe.php?i=$1",
  728. {templateRegex:/.*\/(\S{8}).*/ ,embedtag : {tag: 'iframe', width:'100%',height: 'auto'}
  729. }),
  730. new $.fn.oembed.OEmbedProvider("mixlr", "rich", ["mixlr.com/.+"],"http://mixlr.com/embed/$1?autoplay=ae",
  731. {templateRegex:/.*com\/([^\/]+).*/ ,embedtag : {tag: 'iframe', width:'100%',height: 'auto' }
  732. }),
  733. new $.fn.oembed.OEmbedProvider("pastie", "rich", ["pastie\\.org/pastes/.+"],null,{yql:{xpath:'//pre[@class="textmate-source"]'}}),
  734. new $.fn.oembed.OEmbedProvider("github", "rich", ["gist.github.com/.+"], "https://github.com/api/oembed"),
  735. new $.fn.oembed.OEmbedProvider("github", "rich", ["github.com/[-.\\w@]+/[-.\\w@]+"], "https://api.github.com/repos/$1/$2?callback=?"
  736. ,{templateRegex:/.*\/([^\/]+)\/([^\/]+).*/,
  737. templateData : function(data){ if(!data.data.html_url)return false;
  738. return '<div class="oembedall-githubrepos"><ul class="oembedall-repo-stats"><li>'+data.data.language+'</li><li class="oembedall-watchers"><a title="Watchers" href="'+data.data.html_url+'/watchers">&#x25c9; '+data.data.watchers+'</a></li>'
  739. +'<li class="oembedall-forks"><a title="Forks" href="'+data.data.html_url+'/network">&#x0265; '+data.data.forks+'</a></li></ul><h3><a href="'+data.data.html_url+'">'+data.data.name+'</a></h3><div class="oembedall-body"><p class="oembedall-description">'+data.data.description+'</p>'
  740. +'<p class="oembedall-updated-at">Last updated: '+data.data.pushed_at+'</p></div></div>';
  741. }
  742. }),
  743. new $.fn.oembed.OEmbedProvider("facebook", "rich", ["facebook.com/(people/[^\\/]+/\\d+|[^\\/]+$)"], "https://graph.facebook.com/$2$3/?callback=?"
  744. ,{templateRegex:/.*facebook.com\/(people\/[^\/]+\/(\d+).*|([^\/]+$))/,
  745. templateData : function(data){ if(!data.id)return false;
  746. var out = '<div class="oembedall-facebook1"><div class="oembedall-facebook2"><a href="http://www.facebook.com/">facebook</a> ';
  747. if(data.from) out += '<a href="http://www.facebook.com/'+data.from.id+'">'+data.from.name+'</a>';
  748. else if(data.link) out += '<a href="'+data.link+'">'+data.name+'</a>';
  749. else if(data.username) out += '<a href="http://www.facebook.com/'+data.username+'">'+data.name+'</a>';
  750. else out += '<a href="http://www.facebook.com/'+data.id+'">'+data.name+'</a>';
  751. out += '</div><div class="oembedall-facebookBody"><div class="contents">';
  752. if(data.picture) out += '<a href="'+data.link+'"><img src="'+data.picture+'"></a>';
  753. else out += '<img src="https://graph.facebook.com/'+data.id+'/picture">';
  754. if(data.from) out += '<a href="'+data.link+'">'+data.name+'</a>';
  755. if(data.founded) out += 'Founded: <strong>'+data.founded+'</strong><br>';
  756. if(data.category) out += 'Category: <strong>'+data.category+'</strong><br>';
  757. if(data.website) out += 'Website: <strong><a href="'+data.website+'">'+data.website+'</a></strong><br>';
  758. if(data.gender) out += 'Gender: <strong>'+data.gender+'</strong><br>';
  759. if(data.description) out += data.description + '<br>';
  760. out += '</div></div>';
  761. return out;
  762. }
  763. }),
  764. new $.fn.oembed.OEmbedProvider("stackoverflow", "rich", ["stackoverflow.com/questions/[\\d]+"], "http://api.stackoverflow.com/1.1/questions/$1?body=true&jsonp=?"
  765. ,{templateRegex:/.*questions\/([\d]+).*/,
  766. templateData : function(data){
  767. if(!data.questions)return false;
  768. var q = data.questions[0];
  769. var body = $(q.body).text();
  770. var out = '<div class="oembedall-stoqembed"><div class="oembedall-statscontainer"><div class="oembedall-statsarrow"></div><div class="oembedall-stats"><div class="oembedall-vote"><div class="oembedall-votes">'
  771. +'<span class="oembedall-vote-count-post"><strong>'+ (q.up_vote_count - q.down_vote_count)+ '</strong></span><div class="oembedall-viewcount">vote(s)</div></div>'
  772. +'</div><div class="oembedall-status"><strong>'+q.answer_count+'</strong>answer</div></div><div class="oembedall-views">'+q.view_count+' view(s)</div></div>'
  773. +'<div class="oembedall-summary"><h3><a class="oembedall-question-hyperlink" href="http://stackoverflow.com/questions/'+q.question_id+'/">'+q.title+'</a></h3>'
  774. +'<div class="oembedall-excerpt">'+ body.substring(0,100)+'...</div><div class="oembedall-tags">';
  775. for(i in q.tags)
  776. out += '<a title="" class="oembedall-post-tag" href="http://stackoverflow.com/questions/tagged/'+q.tags[i]+'">'+q.tags[i]+'</a>';
  777. out += '</div><div class="oembedall-fr"><div class="oembedall-user-info"><div class="oembedall-user-gravatar32"><a href="http://stackoverflow.com/users/'+q.owner.user_id+'/'+q.owner.display_name+'">'
  778. +'<img width="32" height="32" alt="" src="http://www.gravatar.com/avatar/'+q.owner.email_hash+'?s=32&amp;d=identicon&amp;r=PG"></a></div><div class="oembedall-user-details">'
  779. +'<a href="http://stackoverflow.com/users/'+q.owner.user_id+'/'+q.owner.display_name+'">'+q.owner.display_name+'</a><br><span title="reputation score" class="oembedall-reputation-score">'
  780. +q.owner.reputation+'</span></div></div></div></div></div>';
  781. return out;
  782. }
  783. }),
  784. new $.fn.oembed.OEmbedProvider("wordpress", "rich", ["wordpress\\.com/.+","blogs\\.cnn\\.com/.+","techcrunch\\.com/.+","wp\\.me/.+"], "http://public-api.wordpress.com/oembed/1.0/?for=jquery-oembed-all"),
  785. new $.fn.oembed.OEmbedProvider("screenr", "rich", ["screenr\.com"], "http://www.screenr.com/embed/$1",
  786. {templateRegex:/.*\/([^\/]+).*/
  787. ,embedtag : {tag: 'iframe', width:'650',height: 396}
  788. }) ,
  789. new $.fn.oembed.OEmbedProvider("gigpans", "rich", ["gigapan\\.org/[-.\\w@]+/\\d+"],"http://gigapan.org/gigapans/$1/options/nosnapshots/iframe/flash.html",
  790. {templateRegex:/.*\/(\d+)\/?.*/,
  791. embedtag : {tag: 'iframe', width:'100%',height: 400 }
  792. }),
  793. new $.fn.oembed.OEmbedProvider("scribd", "rich", ["scribd\\.com/.+"], checkProtocol() + "www.scribd.com/embeds/$1/content?start_page=1&view_mode=list",
  794. {templateRegex:/.*doc\/([^\/]+).*/ ,
  795. embedtag : {tag: 'iframe', width:'100%',height: 600}
  796. }),
  797. new $.fn.oembed.OEmbedProvider("kickstarter", "rich", ["kickstarter\\.com/projects/.+"], "$1/widget/card.html",
  798. {templateRegex:/([^\?]+).*/ ,
  799. embedtag : {tag: 'iframe', width:'220',height: 380}
  800. }),
  801. new $.fn.oembed.OEmbedProvider("amazon", "rich", ["amzn.com/B+", "amazon.com.*/(B\\S+)($|\\/.*)"], checkProtocol() + "rcm.amazon.com/e/cm?t=_APIKEY_&o=1&p=8&l=as1&asins=$1&ref=qf_br_asin_til&fc1=000000&IS2=1&lt1=_blank&m=amazon&lc1=0000FF&bc1=000000&bg1=FFFFFF&f=ifr"
  802. ,{apikey: true,templateRegex:/.*\/(B[0-9A-Z]+)($|\/.*)/,
  803. embedtag : {tag: 'iframe', width:'120px',height: '240px'}
  804. }),
  805. new $.fn.oembed.OEmbedProvider("slideshare", "rich", ["slideshare\.net"], checkProtocol() + "www.slideshare.net/api/oembed/2", { format: 'jsonp' }),
  806. new $.fn.oembed.OEmbedProvider("roomsharejp", "rich", ["roomshare\\.jp/(en/)?post/.*"], "http://roomshare.jp/oembed.json"),
  807. new $.fn.oembed.OEmbedProvider("lanyard", "rich", ["lanyrd.com/\\d+/.+"], null,
  808. {yql:{xpath:'(//div[@class="primary"])[1]', from: 'htmlstring'
  809. , datareturn:function(results){
  810. if(!results.result) return false;
  811. return '<div class="oembedall-lanyard">'+results.result+'</div>';
  812. }
  813. }
  814. }),
  815. new $.fn.oembed.OEmbedProvider("asciiartfarts", "rich", ["asciiartfarts.com/\\d+.html"], null,
  816. {yql:{xpath:'//pre/font', from: 'htmlstring'
  817. , datareturn:function(results){
  818. if(!results.result) return false;
  819. return '<pre style="background-color:000;">'+results.result+'</div>';
  820. }
  821. }
  822. }),
  823. //Use Open Graph Where applicable
  824. new $.fn.oembed.OEmbedProvider("opengraph", "rich", [".*"], null,
  825. {yql:{xpath:"//meta|//title|//link", from:'html'
  826. , datareturn:function(results){
  827. if(!results['og:title'] && results['title'] &&results['description'])results['og:title']=results['title'];
  828. if(!results['og:title'] && !results['title'])return false;
  829. var code = $('<p/>');
  830. if(results['og:video']) {
  831. var embed = $('<embed src="'+results['og:video']+'"/>');
  832. embed
  833. .attr('type',results['og:video:type'] || "application/x-shockwave-flash")
  834. .css('max-height', settings.maxHeight || 'auto' )
  835. .css('max-width', settings.maxWidth || 'auto' );
  836. if(results['og:video:width']) embed.attr('width',results['og:video:width']);
  837. if(results['og:video:height']) embed.attr('height',results['og:video:height']);
  838. code.append(embed);
  839. }else if(results['og:image']) {
  840. var img = $('<img src="'+results['og:image']+'">');
  841. img.css('max-height', settings.maxHeight || 'auto' ).css('max-width', settings.maxWidth || 'auto' );
  842. if(results['og:image:width']) img.attr('width',results['og:image:width']);
  843. if(results['og:image:height']) img.attr('height',results['og:image:height']);
  844. code.append(img);
  845. }
  846. if(results['og:title']) code.append('<b>'+results['og:title']+'</b><br/>');
  847. if(results['og:description'])
  848. code.append(results['og:description']+'<br/>');
  849. else if(results['description'])
  850. code.append(results['description']+'<br/>');
  851. return code;
  852. }
  853. }
  854. })
  855. ];
  856. })(jQuery);
  857. //This is needed for gravatar :(
  858. String.prototype.md5=function(){var a=function(a,b){var c=(a&65535)+(b&65535);var d=(a>>16)+(b>>16)+(c>>16);return d<<16|c&65535;
  859. };var b=function(a,b){return a<<b|a>>>32-b; };var c=function(c,d,e,f,g,h){return a(b(a(a(d,c),a(f,h)),g),e); };var d=function(a,b,d,e,f,g,h){return c(b&d|~b&e,a,b,f,g,h); };var e=function(a,b,d,e,f,g,h){return c(b&e|d&~e,a,b,f,g,h); };var f=function(a,b,d,e,f,g,h){return c(b^d^e,a,b,f,g,h); };var g=function(a,b,d,e,f,g,h){return c(d^(b|~e),a,b,f,g,h); };var h=function(b){var c,h,i,j,k,l=b.length;var m=1732584193;var n=-271733879;var o=-1732584194;var p=271733878;for(k=0;k<l;k+=16){c=m;h=n;i=o;j=p;m=d(m,n,o,p,b[k+0],7,-680876936);p=d(p,m,n,o,b[k+1],12,-389564586);o=d(o,p,m,n,b[k+2],17,606105819);n=d(n,o,p,m,b[k+3],22,-1044525330);m=d(m,n,o,p,b[k+4],7,-176418897);p=d(p,m,n,o,b[k+5],12,1200080426);o=d(o,p,m,n,b[k+6],17,-1473231341);n=d(n,o,p,m,b[k+7],22,-45705983);m=d(m,n,o,p,b[k+8],7,1770035416);p=d(p,m,n,o,b[k+9],12,-1958414417);o=d(o,p,m,n,b[k+10],17,-42063);n=d(n,o,p,m,b[k+11],22,-1990404162);m=d(m,n,o,p,b[k+12],7,1804603682);p=d(p,m,n,o,b[k+13],12,-40341101);o=d(o,p,m,n,b[k+14],17,-1502002290);n=d(n,o,p,m,b[k+15],22,1236535329);m=e(m,n,o,p,b[k+1],5,-165796510);p=e(p,m,n,o,b[k+6],9,-1069501632);o=e(o,p,m,n,b[k+11],14,643717713);n=e(n,o,p,m,b[k+0],20,-373897302);m=e(m,n,o,p,b[k+5],5,-701558691);p=e(p,m,n,o,b[k+10],9,38016083);o=e(o,p,m,n,b[k+15],14,-660478335);n=e(n,o,p,m,b[k+4],20,-405537848);m=e(m,n,o,p,b[k+9],5,568446438);p=e(p,m,n,o,b[k+14],9,-1019803690);o=e(o,p,m,n,b[k+3],14,-187363961);n=e(n,o,p,m,b[k+8],20,1163531501);m=e(m,n,o,p,b[k+13],5,-1444681467);p=e(p,m,n,o,b[k+2],9,-51403784);o=e(o,p,m,n,b[k+7],14,1735328473);n=e(n,o,p,m,b[k+12],20,-1926607734);m=f(m,n,o,p,b[k+5],4,-378558);p=f(p,m,n,o,b[k+8],11,-2022574463);o=f(o,p,m,n,b[k+11],16,1839030562);n=f(n,o,p,m,b[k+14],23,-35309556);m=f(m,n,o,p,b[k+1],4,-1530992060);p=f(p,m,n,o,b[k+4],11,1272893353);o=f(o,p,m,n,b[k+7],16,-155497632);n=f(n,o,p,m,b[k+10],23,-1094730640);m=f(m,n,o,p,b[k+13],4,681279174);p=f(p,m,n,o,b[k+0],11,-358537222);o=f(o,p,m,n,b[k+3],16,-722521979);n=f(n,o,p,m,b[k+6],23,76029189);m=f(m,n,o,p,b[k+9],4,-640364487);p=f(p,m,n,o,b[k+12],11,-421815835);o=f(o,p,m,n,b[k+15],16,530742520);n=f(n,o,p,m,b[k+2],23,-995338651);m=g(m,n,o,p,b[k+0],6,-198630844);p=g(p,m,n,o,b[k+7],10,1126891415);o=g(o,p,m,n,b[k+14],15,-1416354905);n=g(n,o,p,m,b[k+5],21,-57434055);m=g(m,n,o,p,b[k+12],6,1700485571);p=g(p,m,n,o,b[k+3],10,-1894986606);o=g(o,p,m,n,b[k+10],15,-1051523);n=g(n,o,p,m,b[k+1],21,-2054922799);m=g(m,n,o,p,b[k+8],6,1873313359);p=g(p,m,n,o,b[k+15],10,-30611744);o=g(o,p,m,n,b[k+6],15,-1560198380);n=g(n,o,p,m,b[k+13],21,1309151649);m=g(m,n,o,p,b[k+4],6,-145523070);p=g(p,m,n,o,b[k+11],10,-1120210379);o=g(o,p,m,n,b[k+2],15,718787259);n=g(n,o,p,m,b[k+9],21,-343485551);m=a(m,c);n=a(n,h);o=a(o,i);p=a(p,j);
  860. }return[m,n,o,p];
  861. };var i=function(a){var b="0123456789abcdef",c="",d,e=a.length*4;for(d=0;d<e;d++){c+=b.charAt(a[d>>2]>>d%4*8+4&15)+b.charAt(a[d>>2]>>d%4*8&15);
  862. }return c;
  863. };var j=function(a){var b=(a.length+8>>6)+1;var c=[],d,e=b*16,f,g=a.length;for(d=0;d<e;d++){c.push(0);
  864. }for(f=0;f<g;f++){c[f>>2]|=(a.charCodeAt(f)&255)<<f%4*8;
  865. }c[f>>2]|=128<<f%4*8;c[b*16-2]=g*8;return c;
  866. };return i(h(j(this)));
  867. };