jquery.oembed.js 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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. } else if (!settings.onEmbed) {
  46. settings.onEmbed = function(oembedData) {
  47. $.fn.oembed.insertCode(this, settings.embedMethod, oembedData);
  48. };
  49. }
  50. if (resourceURL !== null && resourceURL !== undefined) {
  51. //Check if shorten URL
  52. for (var j = 0, l = shortURLList.length; j < l; j++) {
  53. var regExp = new RegExp('://' + shortURLList[j] + '/', "i");
  54. if (resourceURL.match(regExp) !== null) {
  55. //AJAX to http://api.longurl.org/v2/expand?url=http://bit.ly/JATvIs&format=json&callback=hhh
  56. var ajaxopts = $.extend({
  57. url: "http://api.longurl.org/v2/expand",
  58. dataType: 'jsonp',
  59. data: {
  60. url: resourceURL,
  61. format: "json"
  62. //callback: "?"
  63. },
  64. success: function(data) {
  65. //this = $.fn.oembed;
  66. resourceURL = data['long-url'];
  67. provider = $.fn.oembed.getOEmbedProvider(data['long-url']);
  68. if (provider !== null) {
  69. provider.params = getNormalizedParams(settings[provider.name]) || {};
  70. provider.maxWidth = settings.maxWidth;
  71. provider.maxHeight = settings.maxHeight;
  72. embedCode(container, resourceURL, provider);
  73. } else {
  74. settings.onProviderNotFound.call(container, resourceURL);
  75. }
  76. }
  77. }, settings.ajaxOptions || {});
  78. $.ajax(ajaxopts);
  79. return container;
  80. }
  81. }
  82. provider = $.fn.oembed.getOEmbedProvider(resourceURL);
  83. if (provider !== null) {
  84. provider.params = getNormalizedParams(settings[provider.name]) || {};
  85. provider.maxWidth = settings.maxWidth;
  86. provider.maxHeight = settings.maxHeight;
  87. embedCode(container, resourceURL, provider);
  88. } else {
  89. settings.onProviderNotFound.call(container, resourceURL);
  90. }
  91. }
  92. return container;
  93. });
  94. };
  95. var settings;
  96. // Plugin defaults
  97. $.fn.oembed.defaults = {
  98. maxWidth: null,
  99. maxHeight: null,
  100. useResponsiveResize: false,
  101. includeHandle: true,
  102. embedMethod: 'auto',
  103. // "auto", "append", "fill"
  104. onProviderNotFound: function() {
  105. },
  106. beforeEmbed: function() {
  107. },
  108. afterEmbed: function() {
  109. },
  110. onEmbed: false,
  111. onError: function() {
  112. },
  113. ajaxOptions: { timeout: 2000 }
  114. };
  115. function checkProtocol() {
  116. var protocol = window.location.protocol;
  117. // fix local
  118. if (protocol === "file:") {
  119. return "http://";
  120. } else {
  121. return "//";
  122. }
  123. }
  124. /* Private functions */
  125. function rand(length, current) { //Found on http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript
  126. current = current ? current : '';
  127. return length ? rand(--length, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz".charAt(Math.floor(Math.random() * 60)) + current) : current;
  128. }
  129. function getRequestUrl(provider, externalUrl) {
  130. var url = provider.apiendpoint,
  131. qs = "",
  132. i;
  133. url += (url.indexOf("?") <= 0) ? "?" : "&";
  134. url = url.replace('#', '%23');
  135. if (provider.maxWidth !== null && (typeof provider.params.maxwidth === 'undefined' || provider.params.maxwidth === null)) {
  136. provider.params.maxwidth = provider.maxWidth;
  137. }
  138. if (provider.maxHeight !== null && (typeof provider.params.maxheight === 'undefined' || provider.params.maxheight === null)) {
  139. provider.params.maxheight = provider.maxHeight;
  140. }
  141. for (i in provider.params) {
  142. // We don't want them to jack everything up by changing the callback parameter
  143. if (i == provider.callbackparameter) continue;
  144. // allows the options to be set to null, don't send null values to the server as parameters
  145. if (provider.params[i] !== null) qs += "&" + escape(i) + "=" + provider.params[i];
  146. }
  147. url += "format=" + provider.format + "&url=" + escape(externalUrl) + qs;
  148. if (provider.dataType != 'json') {
  149. url += "&" + provider.callbackparameter + "=?";
  150. }
  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') {
  171. query += " and compat='html5'";
  172. }
  173. var ajaxopts = $.extend({
  174. url: checkProtocol() + "query.yahooapis.com/v1/public/yql",
  175. dataType: 'jsonp',
  176. data: {
  177. q: query,
  178. format: "json",
  179. env: 'store://datatables.org/alltableswithkeys',
  180. callback: "?"
  181. },
  182. success: function(data) {
  183. var result;
  184. if (embedProvider.yql.xpath && embedProvider.yql.xpath == '//meta|//title|//link') {
  185. var meta = {};
  186. if (data.query.results == null) {
  187. data.query.results = { "meta": [] };
  188. }
  189. for (var i = 0, l = data.query.results.meta.length; i < l; i++) {
  190. var name = data.query.results.meta[i].name || data.query.results.meta[i].property || null;
  191. if (name == null) {
  192. continue;
  193. }
  194. meta[name.toLowerCase()] = data.query.results.meta[i].content;
  195. }
  196. if (!meta.hasOwnProperty("title") || !meta.hasOwnProperty("og:title")) {
  197. if (data.query.results.title != null) {
  198. meta.title = data.query.results.title;
  199. }
  200. }
  201. if (!meta.hasOwnProperty("og:image") && data.query.results.hasOwnProperty("link")) {
  202. for (var i = 0, l = data.query.results.link.length; i < l; i++) {
  203. if (data.query.results.link[i].hasOwnProperty("rel")) {
  204. if (data.query.results.link[i].rel == "apple-touch-icon") {
  205. if (data.query.results.link[i].href.charAt(0) == "/") {
  206. meta["og:image"] = url.match(/^(([a-z]+:)?(\/\/)?[^\/]+\/).*$/)[1] + data.query.results.link[i].href;
  207. } else {
  208. meta["og:image"] = data.query.results.link[i].href;
  209. }
  210. }
  211. }
  212. }
  213. }
  214. result = embedProvider.yql.datareturn(meta);
  215. } else {
  216. result = embedProvider.yql.datareturn ? embedProvider.yql.datareturn(data.query.results) : data.query.results.result;
  217. }
  218. if (result === false) {
  219. return;
  220. }
  221. var oembedData = $.extend({}, result);
  222. oembedData.code = result;
  223. success(oembedData, externalUrl, container);
  224. },
  225. error: function() {
  226. settings.onError.call(container, externalUrl, embedProvider);
  227. }
  228. }, settings.ajaxOptions || {});
  229. $.ajax(ajaxopts);
  230. } else if (embedProvider.templateRegex) {
  231. if (embedProvider.embedtag.tag !== '') {
  232. var flashvars = embedProvider.embedtag.flashvars || '';
  233. var tag = embedProvider.embedtag.tag || 'embed';
  234. var width = embedProvider.embedtag.width || 'auto';
  235. var nocache = embedProvider.embedtag.nocache || 0;
  236. var height = embedProvider.embedtag.height || 'auto';
  237. var src = externalUrl.replace(embedProvider.templateRegex, embedProvider.apiendpoint);
  238. if (!embedProvider.nocache) {
  239. src += '&jqoemcache=' + rand(5);
  240. }
  241. if (embedProvider.apikey) {
  242. src = src.replace('_APIKEY_', settings.apikeys[embedProvider.name]);
  243. }
  244. if (settings.maxHeight && settings.maxWidth) {
  245. if (settings.useResponsiveResize) {
  246. var ratio = 0; // Used for aspect ratio
  247. var newWidth = width;
  248. var newHeight = height;
  249. // Check if the current width is larger than the max
  250. if (width > settings.maxWidth) {
  251. ratio = settings.maxWidth / width;
  252. newWidth = settings.maxWidth;
  253. newHeight = height * ratio;
  254. // reset
  255. height = height * ratio;
  256. width = width * ratio;
  257. }
  258. // Check if current height is larger than max
  259. if (height > settings.maxHeight) {
  260. ratio = settings.maxHeight / height;
  261. newHeight = settings.maxHeight;
  262. newWidth = width * ratio;
  263. // reset
  264. width = width * ratio;
  265. }
  266. height = newHeight;
  267. width = newWidth;
  268. } else {
  269. height = settings.maxHeight;
  270. width = settings.maxWidth;
  271. }
  272. }
  273. var code = $('<' + tag + '/>')
  274. .attr('src', src)
  275. .attr('width', width)
  276. .attr('height', height)
  277. .attr('allowfullscreen', embedProvider.embedtag.allowfullscreen || 'true')
  278. .attr('allowscriptaccess', embedProvider.embedtag.allowfullscreen || 'always')
  279. .css('max-height', settings.maxHeight || 'auto')
  280. .css('max-width', settings.maxWidth || 'auto');
  281. if (tag == 'embed') {
  282. code
  283. .attr('type', embedProvider.embedtag.type || "application/x-shockwave-flash")
  284. .attr('flashvars', externalUrl.replace(embedProvider.templateRegex, flashvars));
  285. }
  286. if (tag == 'iframe') {
  287. code
  288. .attr('scrolling', embedProvider.embedtag.scrolling || "no")
  289. .attr('frameborder', embedProvider.embedtag.frameborder || "0");
  290. }
  291. var oembedData = { code: code };
  292. success(oembedData, externalUrl, container);
  293. } else if (embedProvider.apiendpoint) {
  294. //Add APIkey if true
  295. if (embedProvider.apikey) embedProvider.apiendpoint = embedProvider.apiendpoint.replace('_APIKEY_', settings.apikeys[embedProvider.name]);
  296. ajaxopts = $.extend({
  297. url: externalUrl.replace(embedProvider.templateRegex, embedProvider.apiendpoint),
  298. dataType: 'jsonp',
  299. success: function(data) {
  300. var oembedData = $.extend({}, data);
  301. oembedData.code = embedProvider.templateData(data);
  302. success(oembedData, externalUrl, container);
  303. },
  304. error: function() {
  305. settings.onError.call(container, externalUrl, embedProvider);
  306. }
  307. }, settings.ajaxOptions || {});
  308. $.ajax(ajaxopts);
  309. } else {
  310. var oembedData = { code: externalUrl.replace(embedProvider.templateRegex, embedProvider.template) };
  311. success(oembedData, externalUrl, container);
  312. }
  313. } else {
  314. var requestUrl = getRequestUrl(embedProvider, externalUrl),
  315. ajaxopts = $.extend({
  316. url: requestUrl,
  317. dataType: embedProvider.dataType || 'jsonp',
  318. success: function(data) {
  319. var oembedData = $.extend({}, data);
  320. switch (oembedData.type) {
  321. case "file":
  322. //Deviant Art has this
  323. case "photo":
  324. oembedData.code = $.fn.oembed.getPhotoCode(externalUrl, oembedData);
  325. break;
  326. case "video":
  327. case "rich":
  328. oembedData.code = $.fn.oembed.getRichCode(externalUrl, oembedData);
  329. break;
  330. default:
  331. oembedData.code = $.fn.oembed.getGenericCode(externalUrl, oembedData);
  332. break;
  333. }
  334. success(oembedData, externalUrl, container);
  335. },
  336. error: function() {
  337. settings.onError.call(container, externalUrl, embedProvider);
  338. }
  339. }, settings.ajaxOptions || {});
  340. $.ajax(ajaxopts);
  341. }
  342. }
  343. ;
  344. function getNormalizedParams(params) {
  345. if (params === null) return null;
  346. var key, normalizedParams = {};
  347. for (key in params) {
  348. if (key !== null) {
  349. normalizedParams[key.toLowerCase()] = params[key];
  350. }
  351. }
  352. return normalizedParams;
  353. }
  354. /* Public functions */
  355. $.fn.oembed.insertCode = function(container, embedMethod, oembedData) {
  356. if (oembedData === null) return;
  357. if (embedMethod == 'auto' && container.attr("href") !== null) {
  358. embedMethod = 'append';
  359. } else if (embedMethod == 'auto') {
  360. embedMethod = 'replace';
  361. }
  362. switch (embedMethod) {
  363. case "replace":
  364. container.replaceWith(oembedData.code);
  365. break;
  366. case "fill":
  367. container.html(oembedData.code);
  368. break;
  369. case "append":
  370. container.wrap('<div class="oembedall-container"></div>');
  371. var oembedContainer = container.parent();
  372. if (settings.includeHandle) {
  373. $('<span class="oembedall-closehide">&darr;</span>').insertBefore(container).click(function() {
  374. var encodedString = encodeURIComponent($(this).text());
  375. $(this).html((encodedString == '%E2%86%91') ? '&darr;' : '&uarr;');
  376. $(this).parent().children().last().toggle();
  377. });
  378. }
  379. oembedContainer.append('<br/>');
  380. try {
  381. oembedData.code.clone().appendTo(oembedContainer);
  382. } catch(e) {
  383. oembedContainer.append(oembedData.code);
  384. }
  385. /* Make videos semi-responsive
  386. * If parent div width less than embeded iframe video then iframe gets shrunk to fit smaller width
  387. * If parent div width greater thans embed iframe use the max widht
  388. * - works on youtubes and vimeo
  389. */
  390. /*if (settings.maxWidth) {
  391. var post_width = oembedContainer.parent().width();
  392. if (post_width < settings.maxWidth && settings.useResponsiveResize)
  393. {
  394. var iframe_width_orig = $('iframe',oembedContainer).width();
  395. var iframe_height_orig = $('iframe',oembedContainer).height();
  396. var ratio = iframe_width_orig / post_width;
  397. $('iframe',oembedContainer).width(iframe_width_orig / ratio);
  398. $('iframe',oembedContainer).height(iframe_height_orig / ratio);
  399. } else {
  400. if(settings.maxWidth){
  401. $('iframe',oembedContainer).width(settings.maxWidth);
  402. }
  403. if(settings.maxHeight){
  404. $('iframe',oembedContainer).height(settings.maxHeight);
  405. }
  406. }
  407. }*/
  408. break;
  409. }
  410. };
  411. $.fn.oembed.getPhotoCode = function(url, oembedData) {
  412. var code, alt = oembedData.title ? oembedData.title : '';
  413. alt += oembedData.author_name ? ' - ' + oembedData.author_name : '';
  414. alt += oembedData.provider_name ? ' - ' + oembedData.provider_name : '';
  415. if (oembedData.url) {
  416. code = '<div><a href="' + url + '" target=\'_blank\'><img src="' + oembedData.url + '" alt="' + alt + '"/></a></div>';
  417. } else if (oembedData.thumbnail_url) {
  418. var newURL = oembedData.thumbnail_url.replace('_s', '_b');
  419. code = '<div><a href="' + url + '" target=\'_blank\'><img src="' + newURL + '" alt="' + alt + '"/></a></div>';
  420. } else {
  421. code = '<div>Error loading this picture</div>';
  422. }
  423. if (oembedData.html) code += "<div>" + oembedData.html + "</div>";
  424. return code;
  425. };
  426. $.fn.oembed.getRichCode = function(url, oembedData) {
  427. var code = oembedData.html;
  428. return code;
  429. };
  430. $.fn.oembed.getGenericCode = function(url, oembedData) {
  431. var title = (oembedData.title !== null) ? oembedData.title : url,
  432. code = '<a href="' + url + '">' + title + '</a>';
  433. if (oembedData.html) code += "<div>" + oembedData.html + "</div>";
  434. return code;
  435. };
  436. $.fn.oembed.getOEmbedProvider = function(url) {
  437. for (var i = 0; i < $.fn.oembed.providers.length; i++) {
  438. for (var j = 0, l = $.fn.oembed.providers[i].urlschemes.length; j < l; j++) {
  439. var regExp = new RegExp($.fn.oembed.providers[i].urlschemes[j], "i");
  440. if (url.match(regExp) !== null) return $.fn.oembed.providers[i];
  441. }
  442. }
  443. return null;
  444. };
  445. $.fn.oembed.OEmbedProvider = function(name, type, urlschemesarray, apiendpoint, extraSettings) {
  446. this.name = name;
  447. this.type = type; // "photo", "video", "link", "rich", null
  448. this.urlschemes = urlschemesarray;
  449. this.apiendpoint = apiendpoint;
  450. this.maxWidth = 500;
  451. this.maxHeight = 400;
  452. extraSettings = extraSettings || {};
  453. if (extraSettings.useYQL) {
  454. if (extraSettings.useYQL == 'xml') {
  455. extraSettings.yql = {
  456. xpath: "//oembed/html",
  457. from: 'xml',
  458. apiendpoint: this.apiendpoint,
  459. url: function(externalurl) { return this.apiendpoint + '?format=xml&url=' + externalurl; },
  460. datareturn: function(results) { return results.html.replace(/.*\[CDATA\[(.*)\]\]>$/, '$1') || ''; }
  461. };
  462. } else {
  463. extraSettings.yql = {
  464. from: 'json',
  465. apiendpoint: this.apiendpoint,
  466. url: function(externalurl) { return this.apiendpoint + '?format=json&url=' + externalurl; },
  467. datareturn: function(results) {
  468. if (results.json.type != 'video' && (results.json.url || results.json.thumbnail_url)) {
  469. return '<img src="' + (results.json.url || results.json.thumbnail_url) + '" />';
  470. } else if (results.json.html.indexOf("iframe")) {
  471. // Quick fix to handle attribute less html5 properties in ckeditor
  472. if (results.json.html.indexOf("allowfullscreen>")) {
  473. results.json.html = results.json.html.replace('allowfullscreen>', 'allowfullscreen="false">');
  474. }
  475. var html = $.parseHTML(results.json.html);
  476. var width = html[0].width;
  477. var height = html[0].height;
  478. if (settings.maxHeight && settings.maxWidth) {
  479. if (settings.useResponsiveResize) {
  480. var ratio;
  481. var newWidth = width;
  482. var newHeight = height;
  483. // Check if the current width is larger than the max
  484. if (width > settings.maxWidth) {
  485. ratio = settings.maxWidth / width;
  486. newWidth = settings.maxWidth;
  487. newHeight = height * ratio;
  488. // reset
  489. height = height * ratio;
  490. width = width * ratio;
  491. }
  492. // Check if current height is larger than max
  493. if (height > settings.maxHeight) {
  494. ratio = settings.maxHeight / height;
  495. newHeight = settings.maxHeight;
  496. newWidth = width * ratio;
  497. }
  498. height = newHeight;
  499. width = newWidth;
  500. } else {
  501. height = settings.maxHeight;
  502. width = settings.maxWidth;
  503. }
  504. }
  505. html[0].width = width;
  506. html[0].height = height;
  507. return html[0].outerHTML;
  508. }
  509. return results.json.html || '';
  510. }
  511. };
  512. }
  513. this.apiendpoint = null;
  514. }
  515. for (var property in extraSettings) {
  516. this[property] = extraSettings[property];
  517. }
  518. this.format = this.format || 'json';
  519. this.callbackparameter = this.callbackparameter || "callback";
  520. this.embedtag = this.embedtag || { tag: "" };
  521. };
  522. /*
  523. * Function to update existing providers
  524. *
  525. * @param {String} name The name of the provider
  526. * @param {String} type The type of the provider can be "file", "photo", "video", "rich"
  527. * @param {String} urlshemesarray Array of url of the provider
  528. * @param {String} apiendpoint The endpoint of the provider
  529. * @param {String} extraSettings Extra settings of the provider
  530. */
  531. $.fn.updateOEmbedProvider = function(name, type, urlschemesarray, apiendpoint, extraSettings) {
  532. for (var i = 0; i < $.fn.oembed.providers.length; i++) {
  533. if ($.fn.oembed.providers[i].name === name) {
  534. if (type !== null) {
  535. $.fn.oembed.providers[i].type = type;
  536. }
  537. if (urlschemesarray !== null) {
  538. $.fn.oembed.providers[i].urlschemes = urlschemesarray;
  539. }
  540. if (apiendpoint !== null) {
  541. $.fn.oembed.providers[i].apiendpoint = apiendpoint;
  542. }
  543. if (extraSettings !== null) {
  544. $.fn.oembed.providers[i].extraSettings = extraSettings;
  545. for (var property in extraSettings) {
  546. if (extraSettings[property] !== null) {
  547. $.fn.oembed.providers[i][property] = extraSettings[property];
  548. }
  549. }
  550. }
  551. }
  552. }
  553. };
  554. /* Native & common providers */
  555. $.fn.oembed.providers = [
  556. //Video
  557. 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', {
  558. templateRegex: /.*(?:v\=|be\/|embed\/)([\w\-]+)&?.*/,embedtag: {tag: 'iframe',width: '425',height: '349'}}),
  559. /*new $.fn.oembed.OEmbedProvider("youtube", "video", ["youtube\\.com/watch.+v=[\\w-]+&?", "youtu\\.be/[\\w-]+"], checkProtocol() + 'www.youtube.com/oembed', { useYQL: 'json' }),*/
  560. new $.fn.oembed.OEmbedProvider("youtubeiframe", "video", ["youtube.com/embed"], "$1?wmode=transparent",
  561. { templateRegex: /(.*)/, embedtag: { tag: 'iframe', width: '425', height: '349' } }),
  562. 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' }),
  563. new $.fn.oembed.OEmbedProvider("xtranormal", "video", ["xtranormal\\.com/watch/.+"], "http://www.xtranormal.com/xtraplayr/$1/$2", {
  564. templateRegex: /.*com\/watch\/([\w\-]+)\/([\w\-]+).*/,
  565. embedtag: { tag: 'iframe', width: '320', height: '269' }
  566. }),
  567. new $.fn.oembed.OEmbedProvider("scivee", "video", ["scivee.tv/node/.+"], "http://www.scivee.tv/flash/embedCast.swf?", {
  568. templateRegex: /.*tv\/node\/(.+)/,
  569. embedtag: { width: '480', height: '400', flashvars: "id=$1&type=3" }
  570. }),
  571. 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", {
  572. templateRegex: /.*watch\/([^\?]+).*/,
  573. embedtag: { width: '410', height: '341' }
  574. }),
  575. new $.fn.oembed.OEmbedProvider("gametrailers", "video", ["gametrailers\\.com/video/.+"], "http://media.mtvnservices.com/mgid:moses:video:gametrailers.com:$2", {
  576. templateRegex: /.*com\/video\/([\w\-]+)\/([\w\-]+).*/,
  577. embedtag: { width: '512', height: '288' }
  578. }),
  579. new $.fn.oembed.OEmbedProvider("funnyordie", "video", ["funnyordie\\.com/videos/.+"], "http://player.ordienetworks.com/flash/fodplayer.swf?", {
  580. templateRegex: /.*videos\/([^\/]+)\/([^\/]+)?/,
  581. embedtag: { width: 512, height: 328, flashvars: "key=$1" }
  582. }),
  583. 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",
  584. { templateRegex: /.*video\/([^\/]+).*/, embedtag: { width: 600, height: 338 } }),
  585. new $.fn.oembed.OEmbedProvider("metacafe", "video", ["metacafe\\.com/watch/.+"], "http://www.metacafe.com/fplayer/$1/$2.swf",
  586. { templateRegex: /.*watch\/(\d+)\/(\w+)\/.*/, embedtag: { width: 400, height: 345 } }),
  587. new $.fn.oembed.OEmbedProvider("bambuser", "video", ["bambuser\\.com\/channel\/.*\/broadcast\/.*"], "http://static.bambuser.com/r/player.swf?vid=$1",
  588. { templateRegex: /.*bambuser\.com\/channel\/.*\/broadcast\/(\w+).*/, embedtag: { width: 512, height: 339 } }),
  589. new $.fn.oembed.OEmbedProvider("twitvid", "video", ["twitvid\\.com/.+"], "http://www.twitvid.com/embed.php?guid=$1&autoplay=0",
  590. { templateRegex: /.*twitvid\.com\/(\w+).*/, embedtag: { tag: 'iframe', width: 480, height: 360 } }),
  591. new $.fn.oembed.OEmbedProvider("aniboom", "video", ["aniboom\\.com/animation-video/.+"], "http://api.aniboom.com/e/$1",
  592. { templateRegex: /.*animation-video\/(\d+).*/, embedtag: { width: 594, height: 334 } }),
  593. new $.fn.oembed.OEmbedProvider("vzaar", "video", ["vzaar\\.com/videos/.+", "vzaar.tv/.+"], "http://view.vzaar.com/$1/player?",
  594. { templateRegex: /.*\/(\d+).*/, embedtag: { tag: 'iframe', width: 576, height: 324 } }),
  595. new $.fn.oembed.OEmbedProvider("snotr", "video", ["snotr\\.com/video/.+"], "http://www.snotr.com/embed/$1",
  596. { templateRegex: /.*\/(\d+).*/, embedtag: { tag: 'iframe', width: 400, height: 330, nocache: 1 } }),
  597. new $.fn.oembed.OEmbedProvider("youku", "video", ["v.youku.com/v_show/id_.+"], "http://player.youku.com/player.php/sid/$1/v.swf",
  598. { templateRegex: /.*id_(.+)\.html.*/, embedtag: { width: 480, height: 400, nocache: 1 } }),
  599. new $.fn.oembed.OEmbedProvider("tudou", "video", ["tudou.com/programs/view/.+\/"], "http://www.tudou.com/v/$1/v.swf",
  600. { templateRegex: /.*view\/(.+)\//, embedtag: { width: 480, height: 400, nocache: 1 } }),
  601. new $.fn.oembed.OEmbedProvider("embedr", "video", ["embedr\\.com/playlist/.+"], "http://embedr.com/swf/slider/$1/425/520/default/false/std?",
  602. { templateRegex: /.*playlist\/([^\/]+).*/, embedtag: { width: 425, height: 520 } }),
  603. new $.fn.oembed.OEmbedProvider("blip", "video", ["blip\\.tv/.+"], "http://blip.tv/oembed/"),
  604. 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' }),
  605. new $.fn.oembed.OEmbedProvider("animoto", "video", ["animoto.com/play/.+"], "http://animoto.com/services/oembed"),
  606. new $.fn.oembed.OEmbedProvider("hulu", "video", ["hulu\\.com/watch/.*"], "http://www.hulu.com/api/oembed.json"),
  607. new $.fn.oembed.OEmbedProvider("ustream", "video", ["ustream\\.tv/recorded/.*"], "http://www.ustream.tv/oembed", { useYQL: 'json' }),
  608. new $.fn.oembed.OEmbedProvider("videojug", "video", ["videojug\\.com/(film|payer|interview).*"], "http://www.videojug.com/oembed.json", { useYQL: 'json' }),
  609. new $.fn.oembed.OEmbedProvider("sapo", "video", ["videos\\.sapo\\.pt/.*"], "http://videos.sapo.pt/oembed", { useYQL: 'json' }),
  610. new $.fn.oembed.OEmbedProvider("vodpod", "video", ["vodpod.com/watch/.*"], "http://vodpod.com/oembed.js", { useYQL: 'json' }),
  611. 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"),
  612. new $.fn.oembed.OEmbedProvider("dailymotion", "video", ["dailymotion\\.com/.+"], 'http://www.dailymotion.com/services/oembed'),
  613. new $.fn.oembed.OEmbedProvider("5min", "video", ["www\\.5min\\.com/.+"], 'http://api.5min.com/oembed.xml', { useYQL: 'xml' }),
  614. new $.fn.oembed.OEmbedProvider("National Film Board of Canada", "video", ["nfb\\.ca/film/.+"], 'http://www.nfb.ca/remote/services/oembed/', { useYQL: 'json' }),
  615. new $.fn.oembed.OEmbedProvider("qik", "video", ["qik\\.com/\\w+"], 'http://qik.com/api/oembed.json', { useYQL: 'json' }),
  616. new $.fn.oembed.OEmbedProvider("revision3", "video", ["revision3\\.com"], "http://revision3.com/api/oembed/"),
  617. new $.fn.oembed.OEmbedProvider("dotsub", "video", ["dotsub\\.com/view/.+"], "http://dotsub.com/services/oembed", { useYQL: 'json' }),
  618. new $.fn.oembed.OEmbedProvider("clikthrough", "video", ["clikthrough\\.com/theater/video/\\d+"], "http://clikthrough.com/services/oembed"),
  619. new $.fn.oembed.OEmbedProvider("Kinomap", "video", ["kinomap\\.com/.+"], "http://www.kinomap.com/oembed"),
  620. new $.fn.oembed.OEmbedProvider("VHX", "video", ["vhx.tv/.+"], "http://vhx.tv/services/oembed.json"),
  621. new $.fn.oembed.OEmbedProvider("bambuser", "video", ["bambuser.com/.+"], "http://api.bambuser.com/oembed/iframe.json"),
  622. new $.fn.oembed.OEmbedProvider("justin.tv", "video", ["justin.tv/.+"], 'http://api.justin.tv/api/embed/from_url.json', { useYQL: 'json' }),
  623. //Audio
  624. new $.fn.oembed.OEmbedProvider("official.fm", "rich", ["official.fm/.+"], 'http://official.fm/services/oembed', { useYQL: 'json' }),
  625. new $.fn.oembed.OEmbedProvider("chirbit", "rich", ["chirb.it/.+"], 'http://chirb.it/oembed.json', { useYQL: 'json' }),
  626. new $.fn.oembed.OEmbedProvider("Huffduffer", "rich", ["huffduffer.com/[-.\\w@]+/\\d+"], "http://huffduffer.com/oembed"),
  627. new $.fn.oembed.OEmbedProvider("Spotify", "rich", ["open.spotify.com/(track|album|user)/"], "https://embed.spotify.com/oembed/"),
  628. new $.fn.oembed.OEmbedProvider("shoudio", "rich", ["shoudio.com/.+", "shoud.io/.+"], "http://shoudio.com/api/oembed"),
  629. new $.fn.oembed.OEmbedProvider("mixcloud", "rich", ["mixcloud.com/.+"], checkProtocol() + 'www.mixcloud.com/oembed/', { useYQL: 'json' }),
  630. new $.fn.oembed.OEmbedProvider("rdio.com", "rich", ["rd.io/.+", "rdio.com"], checkProtocol() + "www.rdio.com/api/oembed/"),
  631. new $.fn.oembed.OEmbedProvider("Soundcloud", "rich", ["soundcloud.com/.+", "snd.sc/.+"], checkProtocol() + "soundcloud.com/oembed", { format: 'js' }),
  632. new $.fn.oembed.OEmbedProvider("bandcamp", "rich", ["bandcamp\\.com/album/.+"], null,
  633. {
  634. yql: {
  635. xpath: "//meta[contains(@content, \\'EmbeddedPlayer\\')]",
  636. from: 'html',
  637. datareturn: function(results) {
  638. return results.meta ? '<iframe width="400" height="100" src="' + results.meta.content + '" allowtransparency="true" frameborder="0"></iframe>' : false;
  639. }
  640. }
  641. }),
  642. //Photo
  643. new $.fn.oembed.OEmbedProvider("deviantart", "photo", ["deviantart.com/.+", "fav.me/.+", "deviantart.com/.+"], "http://backend.deviantart.com/oembed", { format: 'jsonp' }),
  644. new $.fn.oembed.OEmbedProvider("skitch", "photo", ["skitch.com/.+"], null,
  645. {
  646. yql: {
  647. xpath: "json",
  648. from: 'json',
  649. url: function(externalurl) { return 'http://skitch.com/oembed/?format=json&url=' + externalurl; },
  650. datareturn: function(data) { return $.fn.oembed.getPhotoCode(data.json.url, data.json); }
  651. }
  652. }),
  653. new $.fn.oembed.OEmbedProvider("mobypicture", "photo", ["mobypicture.com/user/.+/view/.+", "moby.to/.+"], "http://api.mobypicture.com/oEmbed"),
  654. new $.fn.oembed.OEmbedProvider("flickr", "photo", ["flickr\\.com/photos/.+"], "http://flickr.com/services/oembed", { callbackparameter: 'jsoncallback' }),
  655. new $.fn.oembed.OEmbedProvider("photobucket", "photo", ["photobucket\\.com/(albums|groups)/.+"], checkProtocol() + "photobucket.com/oembed/"),
  656. new $.fn.oembed.OEmbedProvider("instagram", "photo", ["instagr\\.?am(\\.com)?/.+"], checkProtocol() + "api.instagram.com/oembed"),
  657. //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"}),
  658. new $.fn.oembed.OEmbedProvider("SmugMug", "photo", ["smugmug.com/[-.\\w@]+/.+"], "http://api.smugmug.com/services/oembed/"),
  659. new $.fn.oembed.OEmbedProvider("dribbble", "photo", ["dribbble.com/shots/.+"], "http://api.dribbble.com/shots/$1?callback=?",
  660. {
  661. templateRegex: /.*shots\/([\d]+).*/,
  662. templateData: function(data) {
  663. if (!data.image_teaser_url) {
  664. return false;
  665. }
  666. return '<img src="' + data.image_teaser_url + '"/>';
  667. }
  668. }),
  669. new $.fn.oembed.OEmbedProvider("chart.ly", "photo", ["chart\\.ly/[a-z0-9]{6,8}"], "http://chart.ly/uploads/large_$1.png",
  670. { templateRegex: /.*ly\/([^\/]+).*/, embedtag: { tag: 'img' }, nocache: 1 }),
  671. //new $.fn.oembed.OEmbedProvider("stocktwits.com", "photo", ["stocktwits\\.com/message/.+"], "http://charts.stocktwits.com/production/original_$1.png?",
  672. // { templateRegex: /.*message\/([^\/]+).*/, embedtag: { tag: 'img'},nocache:1 }),
  673. new $.fn.oembed.OEmbedProvider("circuitlab", "photo", ["circuitlab.com/circuit/.+"], "https://www.circuitlab.com/circuit/$1/screenshot/540x405/",
  674. { templateRegex: /.*circuit\/([^\/]+).*/, embedtag: { tag: 'img' }, nocache: 1 }),
  675. new $.fn.oembed.OEmbedProvider("23hq", "photo", ["23hq.com/[-.\\w@]+/photo/.+"], "http://www.23hq.com/23/oembed", { useYQL: "json" }),
  676. new $.fn.oembed.OEmbedProvider("img.ly", "photo", ["img\\.ly/.+"], "http://img.ly/show/thumb/$1",
  677. {
  678. templateRegex: /.*ly\/([^\/]+).*/,
  679. embedtag: { tag: 'img' },
  680. nocache: 1
  681. }),
  682. new $.fn.oembed.OEmbedProvider("twitgoo.com", "photo", ["twitgoo\\.com/.+"], "http://twitgoo.com/show/thumb/$1",
  683. { templateRegex: /.*com\/([^\/]+).*/, embedtag: { tag: 'img' }, nocache: 1 }),
  684. new $.fn.oembed.OEmbedProvider("imgur.com", "photo", ["imgur\\.com/gallery/.+"], checkProtocol() + "imgur.com/$1l.jpg",
  685. { templateRegex: /.*gallery\/([^\/]+).*/, embedtag: { tag: 'img' }, nocache: 1 }),
  686. new $.fn.oembed.OEmbedProvider("visual.ly", "rich", ["visual\\.ly/.+"], null,
  687. {
  688. yql: { xpath: "//a[@id=\\'gc_article_graphic_image\\']/img", from: 'htmlstring' }
  689. }),
  690. new $.fn.oembed.OEmbedProvider("gravtar", "photo", ["mailto:.+"], null,
  691. {
  692. templateRegex: /mailto:([^\/]+).*/,
  693. template: function(wm, email) {
  694. return '<img src="http://gravatar.com/avatar/' + email.md5() + '.jpg" alt="on Gravtar" class="jqoaImg">';
  695. }
  696. }),
  697. //Rich
  698. new $.fn.oembed.OEmbedProvider("twitter", "rich", ["twitter.com/.+"], "https://api.twitter.com/1/statuses/oembed.json"),
  699. new $.fn.oembed.OEmbedProvider("gmep", "rich", ["gmep.imeducate.com/.*", "gmep.org/.*"], "http://gmep.org/oembed.json"),
  700. new $.fn.oembed.OEmbedProvider("urtak", "rich", ["urtak.com/(u|clr)/.+"], "http://oembed.urtak.com/1/oembed"),
  701. new $.fn.oembed.OEmbedProvider("cacoo", "rich", ["cacoo.com/.+"], "http://cacoo.com/oembed.json"),
  702. new $.fn.oembed.OEmbedProvider("dailymile", "rich", ["dailymile.com/people/.*/entries/.*"], "http://api.dailymile.com/oembed"),
  703. new $.fn.oembed.OEmbedProvider("dipity", "rich", ["dipity.com/timeline/.+"], 'http://www.dipity.com/oembed/timeline/', { useYQL: 'json' }),
  704. new $.fn.oembed.OEmbedProvider("sketchfab", "rich", ["sketchfab.com/show/.+"], 'http://sketchfab.com/oembed', { useYQL: 'json' }),
  705. new $.fn.oembed.OEmbedProvider("speakerdeck", "rich", ["speakerdeck.com/.+"], 'http://speakerdeck.com/oembed.json', { useYQL: 'json' }),
  706. new $.fn.oembed.OEmbedProvider("popplet", "rich", ["popplet.com/app/.*"], "http://popplet.com/app/Popplet_Alpha.swf?page_id=$1&em=1",
  707. { templateRegex: /.*#\/([^\/]+).*/, embedtag: { width: 460, height: 460 } }),
  708. new $.fn.oembed.OEmbedProvider("pearltrees", "rich", ["pearltrees.com/.*"], "http://cdn.pearltrees.com/s/embed/getApp?",
  709. {
  710. templateRegex: /.*N-f=1_(\d+).*N-p=(\d+).*/,
  711. embedtag: {
  712. width: 460,
  713. height: 460,
  714. 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"
  715. }
  716. }),
  717. new $.fn.oembed.OEmbedProvider("prezi", "rich", ["prezi.com/.*"], "http://prezi.com/bin/preziloader.swf?",
  718. {
  719. templateRegex: /.*com\/([^\/]+)\/.*/,
  720. embedtag: {
  721. width: 550,
  722. height: 400,
  723. flashvars: "prezi_id=$1&amp;lock_to_path=0&amp;color=ffffff&amp;autoplay=no&amp;autohide_ctrls=0"
  724. }
  725. }),
  726. new $.fn.oembed.OEmbedProvider("tourwrist", "rich", ["tourwrist.com/tours/.+"], null,
  727. {
  728. templateRegex: /.*tours.([\d]+).*/,
  729. template: function(wm, tourid) {
  730. setTimeout(function() {
  731. if (loadEmbeds) {
  732. loadEmbeds();
  733. }
  734. }, 2000);
  735. return "<div id='" + tourid + "' class='tourwrist-tour-embed direct'></div> <script type='text/javascript' src='http://tourwrist.com/tour_embed.js'></script>";
  736. }
  737. }),
  738. new $.fn.oembed.OEmbedProvider("meetup", "rich", ["meetup\\.(com|ps)/.+"], checkProtocol() + "api.meetup.com/oembed"),
  739. new $.fn.oembed.OEmbedProvider("ebay", "rich", ["ebay\\.*"], checkProtocol() + "togo.ebay.com/togo/togo.swf?2008013100",
  740. {
  741. templateRegex: /.*\/([^\/]+)\/(\d{10,13}).*/,
  742. embedtag: {
  743. width: 355,
  744. height: 300,
  745. flashvars: "base=http://togo.ebay.com/togo/&lang=en-us&mode=normal&itemid=$2&query=$1"
  746. }
  747. }),
  748. 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=?", {
  749. templateRegex: /.*\/\/([\w]+).*\/wiki\/([^\/]+).*/,
  750. templateData: function(data) {
  751. if (!data.parse) {
  752. return false;
  753. }
  754. var text = data.parse['text']['*'].replace(/href="\/wiki/g, 'href="http://en.wikipedia.org/wiki');
  755. 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>';
  756. }
  757. }),
  758. new $.fn.oembed.OEmbedProvider("imdb", "rich", ["imdb.com/title/.+"], "http://www.imdbapi.com/?i=$1&callback=?",
  759. {
  760. templateRegex: /.*\/title\/([^\/]+).*/,
  761. templateData: function(data) {
  762. if (!data.Title) {
  763. return false;
  764. }
  765. 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>';
  766. }
  767. }),
  768. new $.fn.oembed.OEmbedProvider("livejournal", "rich", ["livejournal.com/"], "http://ljpic.seacrow.com/json/$2$4?jsonp=?", {
  769. templateRegex: /(http:\/\/(((?!users).)+)\.livejournal\.com|.*users\.livejournal\.com\/([^\/]+)).*/,
  770. templateData: function(data) {
  771. return !!data.username && '<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>';
  772. }
  773. }),
  774. new $.fn.oembed.OEmbedProvider("circuitbee", "rich", ["circuitbee\\.com/circuit/view/.+"], "http://c.circuitbee.com/build/r/schematic-embed.html?id=$1",
  775. {
  776. templateRegex: /.*circuit\/view\/(\d+).*/,
  777. embedtag: { tag: 'iframe', width: '500', height: '350' }
  778. }),
  779. new $.fn.oembed.OEmbedProvider("googlecalendar", "rich", ["www.google.com/calendar/embed?.+"], "$1",
  780. {
  781. templateRegex: /(.*)/,
  782. embedtag: { tag: 'iframe', width: '800', height: '600' }
  783. }),
  784. new $.fn.oembed.OEmbedProvider("jsfiddle", "rich", ["jsfiddle.net/[^/]+/?"], "http://jsfiddle.net/$1/embedded/result,js,resources,html,css/?",
  785. {
  786. templateRegex: /.*net\/([^\/]+).*/,
  787. embedtag: { tag: 'iframe', width: '100%', height: '300' }
  788. }),
  789. new $.fn.oembed.OEmbedProvider("jsbin", "rich", ["jsbin.com/.+"], "http://jsbin.com/$1/?",
  790. {
  791. templateRegex: /.*com\/([^\/]+).*/,
  792. embedtag: { tag: 'iframe', width: '100%', height: '300' }
  793. }),
  794. new $.fn.oembed.OEmbedProvider("jotform", "rich", ["form.jotform.co/form/.+"], "$1?",
  795. {
  796. templateRegex: /(.*)/,
  797. embedtag: { tag: 'iframe', width: '100%', height: '507' }
  798. }),
  799. new $.fn.oembed.OEmbedProvider("reelapp", "rich", ["reelapp\\.com/.+"], "http://www.reelapp.com/$1/embed",
  800. {
  801. templateRegex: /.*com\/(\S{6}).*/,
  802. embedtag: { tag: 'iframe', width: '400', height: '338' }
  803. }),
  804. 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",
  805. {
  806. templateRegex: /(.*)/,
  807. embedtag: { tag: 'iframe', width: '368px', height: 'auto' }
  808. }),
  809. new $.fn.oembed.OEmbedProvider("timetoast", "rich", ["timetoast.com/timelines/[0-9]+"], "http://www.timetoast.com/flash/TimelineViewer.swf?passedTimelines=$1",
  810. {
  811. templateRegex: /.*timelines\/([0-9]*)/,
  812. embedtag: { width: 550, height: 400, nocache: 1 }
  813. }),
  814. new $.fn.oembed.OEmbedProvider("pastebin", "rich", ["pastebin\\.com/[\\S]{8}"], "http://pastebin.com/embed_iframe.php?i=$1",
  815. {
  816. templateRegex: /.*\/(\S{8}).*/,
  817. embedtag: { tag: 'iframe', width: '100%', height: 'auto' }
  818. }),
  819. new $.fn.oembed.OEmbedProvider("mixlr", "rich", ["mixlr.com/.+"], "http://mixlr.com/embed/$1?autoplay=ae",
  820. {
  821. templateRegex: /.*com\/([^\/]+).*/,
  822. embedtag: { tag: 'iframe', width: '100%', height: 'auto' }
  823. }),
  824. new $.fn.oembed.OEmbedProvider("pastie", "rich", ["pastie\\.org/pastes/.+"], null, { yql: { xpath: '//pre[@class="textmate-source"]' } }),
  825. new $.fn.oembed.OEmbedProvider("github", "rich", ["gist.github.com/.+"], "https://github.com/api/oembed"),
  826. new $.fn.oembed.OEmbedProvider("github", "rich", ["github.com/[-.\\w@]+/[-.\\w@]+"], "https://api.github.com/repos/$1/$2?callback=?", {
  827. templateRegex: /.*\/([^\/]+)\/([^\/]+).*/,
  828. templateData: function(data) {
  829. if (!data.data.html_url) {
  830. return false;
  831. }
  832. 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>'
  833. + '<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>'
  834. + '<p class="oembedall-updated-at">Last updated: ' + data.data.pushed_at + '</p></div></div>';
  835. }
  836. }),
  837. new $.fn.oembed.OEmbedProvider("facebook", "rich", ["facebook.com/(people/[^\\/]+/\\d+|[^\\/]+$)"], "https://graph.facebook.com/$2$3/?callback=?", {
  838. templateRegex: /.*facebook.com\/(people\/[^\/]+\/(\d+).*|([^\/]+$))/,
  839. templateData: function(data) {
  840. if (!data.id) {
  841. return false;
  842. }
  843. var out = '<div class="oembedall-facebook1"><div class="oembedall-facebook2"><a href="http://www.facebook.com/">facebook</a> ';
  844. if (data.from) {
  845. out += '<a href="http://www.facebook.com/' + data.from.id + '">' + data.from.name + '</a>';
  846. } else if (data.link) {
  847. out += '<a href="' + data.link + '">' + data.name + '</a>';
  848. } else if (data.username) {
  849. out += '<a href="http://www.facebook.com/' + data.username + '">' + data.name + '</a>';
  850. } else {
  851. out += '<a href="http://www.facebook.com/' + data.id + '">' + data.name + '</a>';
  852. }
  853. out += '</div><div class="oembedall-facebookBody"><div class="contents">';
  854. if (data.picture) {
  855. out += '<a href="' + data.link + '"><img src="' + data.picture + '"></a>';
  856. } else {
  857. out += '<img src="https://graph.facebook.com/' + data.id + '/picture">';
  858. }
  859. if (data.from) {
  860. out += '<a href="' + data.link + '">' + data.name + '</a>';
  861. }
  862. if (data.founded) {
  863. out += 'Founded: <strong>' + data.founded + '</strong><br>';
  864. }
  865. if (data.category) {
  866. out += 'Category: <strong>' + data.category + '</strong><br>';
  867. }
  868. if (data.website) {
  869. out += 'Website: <strong><a href="' + data.website + '">' + data.website + '</a></strong><br>';
  870. }
  871. if (data.gender) {
  872. out += 'Gender: <strong>' + data.gender + '</strong><br>';
  873. }
  874. if (data.description) {
  875. out += data.description + '<br>';
  876. }
  877. out += '</div></div>';
  878. return out;
  879. }
  880. }),
  881. new $.fn.oembed.OEmbedProvider("stackoverflow", "rich", ["stackoverflow.com/questions/[\\d]+"], "http://api.stackoverflow.com/1.1/questions/$1?body=true&jsonp=?", {
  882. templateRegex: /.*questions\/([\d]+).*/,
  883. templateData: function(data) {
  884. if (!data.questions) {
  885. return false;
  886. }
  887. var q = data.questions[0];
  888. var body = $(q.body).text();
  889. 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">'
  890. + '<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>'
  891. + '</div><div class="oembedall-status"><strong>' + q.answer_count + '</strong>answer</div></div><div class="oembedall-views">' + q.view_count + ' view(s)</div></div>'
  892. + '<div class="oembedall-summary"><h3><a class="oembedall-question-hyperlink" href="http://stackoverflow.com/questions/' + q.question_id + '/">' + q.title + '</a></h3>'
  893. + '<div class="oembedall-excerpt">' + body.substring(0, 100) + '...</div><div class="oembedall-tags">';
  894. for (i in q.tags)
  895. out += '<a title="" class="oembedall-post-tag" href="http://stackoverflow.com/questions/tagged/' + q.tags[i] + '">' + q.tags[i] + '</a>';
  896. 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 + '">'
  897. + '<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">'
  898. + '<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">'
  899. + q.owner.reputation + '</span></div></div></div></div></div>';
  900. return out;
  901. }
  902. }),
  903. 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"),
  904. new $.fn.oembed.OEmbedProvider("screenr", "rich", ["screenr\.com"], "http://www.screenr.com/embed/$1",
  905. {
  906. templateRegex: /.*\/([^\/]+).*/,
  907. embedtag: { tag: 'iframe', width: '650', height: 396 }
  908. }),
  909. new $.fn.oembed.OEmbedProvider("gigpans", "rich", ["gigapan\\.org/[-.\\w@]+/\\d+"], "http://gigapan.org/gigapans/$1/options/nosnapshots/iframe/flash.html",
  910. {
  911. templateRegex: /.*\/(\d+)\/?.*/,
  912. embedtag: { tag: 'iframe', width: '100%', height: 400 }
  913. }),
  914. new $.fn.oembed.OEmbedProvider("scribd", "rich", ["scribd\\.com/.+"], checkProtocol() + "www.scribd.com/embeds/$1/content?start_page=1&view_mode=list",
  915. {
  916. templateRegex: /.*doc\/([^\/]+).*/,
  917. embedtag: { tag: 'iframe', width: '100%', height: 600 }
  918. }),
  919. new $.fn.oembed.OEmbedProvider("kickstarter", "rich", ["kickstarter\\.com/projects/.+"], "$1/widget/card.html",
  920. {
  921. templateRegex: /([^\?]+).*/,
  922. embedtag: { tag: 'iframe', width: '220', height: 380 }
  923. }),
  924. 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", {
  925. apikey: true,
  926. templateRegex: /.*\/(B[0-9A-Z]+)($|\/.*)/,
  927. embedtag: { tag: 'iframe', width: '120px', height: '240px' }
  928. }),
  929. new $.fn.oembed.OEmbedProvider("slideshare", "rich", ["slideshare\.net"], checkProtocol() + "www.slideshare.net/api/oembed/2", { format: 'jsonp' }),
  930. new $.fn.oembed.OEmbedProvider("roomsharejp", "rich", ["roomshare\\.jp/(en/)?post/.*"], "http://roomshare.jp/oembed.json"),
  931. new $.fn.oembed.OEmbedProvider("lanyard", "rich", ["lanyrd.com/\\d+/.+"], null,
  932. {
  933. yql: {
  934. xpath: '(//div[@class="primary"])[1]',
  935. from: 'htmlstring',
  936. datareturn: function(results) {
  937. if (!results.result) {
  938. return false;
  939. }
  940. return '<div class="oembedall-lanyard">' + results.result + '</div>';
  941. }
  942. }
  943. }),
  944. new $.fn.oembed.OEmbedProvider("asciiartfarts", "rich", ["asciiartfarts.com/\\d+.html"], null,
  945. {
  946. yql: {
  947. xpath: '//pre/font',
  948. from: 'htmlstring',
  949. datareturn: function(results) {
  950. if (!results.result) {
  951. return false;
  952. }
  953. return '<pre style="background-color:000;">' + results.result + '</div>';
  954. }
  955. }
  956. }),
  957. //Use Open Graph Where applicable
  958. new $.fn.oembed.OEmbedProvider("opengraph", "rich", [".*"], null,
  959. {
  960. yql: {
  961. xpath: "//meta|//title|//link",
  962. from: 'html',
  963. datareturn: function(results) {
  964. if (!results['og:title'] && results['title'] && results['description']) {
  965. results['og:title'] = results['title'];
  966. }
  967. if (!results['og:title'] && !results['title']) {
  968. return false;
  969. }
  970. var code = $('<p/>');
  971. if (results['og:video']) {
  972. var embed = $('<embed src="' + results['og:video'] + '"/>');
  973. embed
  974. .attr('type', results['og:video:type'] || "application/x-shockwave-flash")
  975. .css('max-height', settings.maxHeight || 'auto')
  976. .css('max-width', settings.maxWidth || 'auto');
  977. if (results['og:video:width']) {
  978. embed.attr('width', results['og:video:width']);
  979. }
  980. if (results['og:video:height']) {
  981. embed.attr('height', results['og:video:height']);
  982. }
  983. code.append(embed);
  984. } else if (results['og:image']) {
  985. var img = $('<img src="' + results['og:image'] + '">');
  986. img.css('max-height', settings.maxHeight || 'auto').css('max-width', settings.maxWidth || 'auto');
  987. if (results['og:image:width']) {
  988. img.attr('width', results['og:image:width']);
  989. }
  990. if (results['og:image:height']) {
  991. img.attr('height', results['og:image:height']);
  992. }
  993. code.append(img);
  994. }
  995. if (results['og:title']) {
  996. code.append('<b>' + results['og:title'] + '</b><br/>');
  997. }
  998. if (results['og:description']) {
  999. code.append(results['og:description'] + '<br/>');
  1000. } else if (results['description']) {
  1001. code.append(results['description'] + '<br/>');
  1002. }
  1003. return code;
  1004. }
  1005. }
  1006. })
  1007. ];
  1008. })(jQuery);
  1009. //This is needed for gravatar :(
  1010. String.prototype.md5 = function() {
  1011. var a = function(a, b) {
  1012. var c = (a & 65535) + (b & 65535);
  1013. var d = (a >> 16) + (b >> 16) + (c >> 16);
  1014. return d << 16 | c & 65535;
  1015. };
  1016. var b = function(a, b) { return a << b | a >>> 32 - b; };
  1017. var c = function(c, d, e, f, g, h) { return a(b(a(a(d, c), a(f, h)), g), e); };
  1018. var d = function(a, b, d, e, f, g, h) { return c(b & d | ~b & e, a, b, f, g, h); };
  1019. var e = function(a, b, d, e, f, g, h) { return c(b & e | d & ~e, a, b, f, g, h); };
  1020. var f = function(a, b, d, e, f, g, h) { return c(b ^ d ^ e, a, b, f, g, h); };
  1021. var g = function(a, b, d, e, f, g, h) { return c(d ^ (b | ~e), a, b, f, g, h); };
  1022. var h = function(b) {
  1023. var c, h, i, j, k, l = b.length;
  1024. var m = 1732584193;
  1025. var n = -271733879;
  1026. var o = -1732584194;
  1027. var p = 271733878;
  1028. for (k = 0; k < l; k += 16) {
  1029. c = m;
  1030. h = n;
  1031. i = o;
  1032. j = p;
  1033. m = d(m, n, o, p, b[k + 0], 7, -680876936);
  1034. p = d(p, m, n, o, b[k + 1], 12, -389564586);
  1035. o = d(o, p, m, n, b[k + 2], 17, 606105819);
  1036. n = d(n, o, p, m, b[k + 3], 22, -1044525330);
  1037. m = d(m, n, o, p, b[k + 4], 7, -176418897);
  1038. p = d(p, m, n, o, b[k + 5], 12, 1200080426);
  1039. o = d(o, p, m, n, b[k + 6], 17, -1473231341);
  1040. n = d(n, o, p, m, b[k + 7], 22, -45705983);
  1041. m = d(m, n, o, p, b[k + 8], 7, 1770035416);
  1042. p = d(p, m, n, o, b[k + 9], 12, -1958414417);
  1043. o = d(o, p, m, n, b[k + 10], 17, -42063);
  1044. n = d(n, o, p, m, b[k + 11], 22, -1990404162);
  1045. m = d(m, n, o, p, b[k + 12], 7, 1804603682);
  1046. p = d(p, m, n, o, b[k + 13], 12, -40341101);
  1047. o = d(o, p, m, n, b[k + 14], 17, -1502002290);
  1048. n = d(n, o, p, m, b[k + 15], 22, 1236535329);
  1049. m = e(m, n, o, p, b[k + 1], 5, -165796510);
  1050. p = e(p, m, n, o, b[k + 6], 9, -1069501632);
  1051. o = e(o, p, m, n, b[k + 11], 14, 643717713);
  1052. n = e(n, o, p, m, b[k + 0], 20, -373897302);
  1053. m = e(m, n, o, p, b[k + 5], 5, -701558691);
  1054. p = e(p, m, n, o, b[k + 10], 9, 38016083);
  1055. o = e(o, p, m, n, b[k + 15], 14, -660478335);
  1056. n = e(n, o, p, m, b[k + 4], 20, -405537848);
  1057. m = e(m, n, o, p, b[k + 9], 5, 568446438);
  1058. p = e(p, m, n, o, b[k + 14], 9, -1019803690);
  1059. o = e(o, p, m, n, b[k + 3], 14, -187363961);
  1060. n = e(n, o, p, m, b[k + 8], 20, 1163531501);
  1061. m = e(m, n, o, p, b[k + 13], 5, -1444681467);
  1062. p = e(p, m, n, o, b[k + 2], 9, -51403784);
  1063. o = e(o, p, m, n, b[k + 7], 14, 1735328473);
  1064. n = e(n, o, p, m, b[k + 12], 20, -1926607734);
  1065. m = f(m, n, o, p, b[k + 5], 4, -378558);
  1066. p = f(p, m, n, o, b[k + 8], 11, -2022574463);
  1067. o = f(o, p, m, n, b[k + 11], 16, 1839030562);
  1068. n = f(n, o, p, m, b[k + 14], 23, -35309556);
  1069. m = f(m, n, o, p, b[k + 1], 4, -1530992060);
  1070. p = f(p, m, n, o, b[k + 4], 11, 1272893353);
  1071. o = f(o, p, m, n, b[k + 7], 16, -155497632);
  1072. n = f(n, o, p, m, b[k + 10], 23, -1094730640);
  1073. m = f(m, n, o, p, b[k + 13], 4, 681279174);
  1074. p = f(p, m, n, o, b[k + 0], 11, -358537222);
  1075. o = f(o, p, m, n, b[k + 3], 16, -722521979);
  1076. n = f(n, o, p, m, b[k + 6], 23, 76029189);
  1077. m = f(m, n, o, p, b[k + 9], 4, -640364487);
  1078. p = f(p, m, n, o, b[k + 12], 11, -421815835);
  1079. o = f(o, p, m, n, b[k + 15], 16, 530742520);
  1080. n = f(n, o, p, m, b[k + 2], 23, -995338651);
  1081. m = g(m, n, o, p, b[k + 0], 6, -198630844);
  1082. p = g(p, m, n, o, b[k + 7], 10, 1126891415);
  1083. o = g(o, p, m, n, b[k + 14], 15, -1416354905);
  1084. n = g(n, o, p, m, b[k + 5], 21, -57434055);
  1085. m = g(m, n, o, p, b[k + 12], 6, 1700485571);
  1086. p = g(p, m, n, o, b[k + 3], 10, -1894986606);
  1087. o = g(o, p, m, n, b[k + 10], 15, -1051523);
  1088. n = g(n, o, p, m, b[k + 1], 21, -2054922799);
  1089. m = g(m, n, o, p, b[k + 8], 6, 1873313359);
  1090. p = g(p, m, n, o, b[k + 15], 10, -30611744);
  1091. o = g(o, p, m, n, b[k + 6], 15, -1560198380);
  1092. n = g(n, o, p, m, b[k + 13], 21, 1309151649);
  1093. m = g(m, n, o, p, b[k + 4], 6, -145523070);
  1094. p = g(p, m, n, o, b[k + 11], 10, -1120210379);
  1095. o = g(o, p, m, n, b[k + 2], 15, 718787259);
  1096. n = g(n, o, p, m, b[k + 9], 21, -343485551);
  1097. m = a(m, c);
  1098. n = a(n, h);
  1099. o = a(o, i);
  1100. p = a(p, j);
  1101. }
  1102. return [m, n, o, p];
  1103. };
  1104. var i = function(a) {
  1105. var b = "0123456789abcdef", c = "", d, e = a.length * 4;
  1106. for (d = 0; d < e; d++) {
  1107. c += b.charAt(a[d >> 2] >> d % 4 * 8 + 4 & 15) + b.charAt(a[d >> 2] >> d % 4 * 8 & 15);
  1108. }
  1109. return c;
  1110. };
  1111. var j = function(a) {
  1112. var b = (a.length + 8 >> 6) + 1;
  1113. var c = [], d, e = b * 16, f, g = a.length;
  1114. for (d = 0; d < e; d++) {
  1115. c.push(0);
  1116. }
  1117. for (f = 0; f < g; f++) {
  1118. c[f >> 2] |= (a.charCodeAt(f) & 255) << f % 4 * 8;
  1119. }
  1120. c[f >> 2] |= 128 << f % 4 * 8;
  1121. c[b * 16 - 2] = g * 8;
  1122. return c;
  1123. };
  1124. return i(h(j(this)));
  1125. };