Browse files

fixed how default/settings values are handled and appended to the req…

…uest URL
  • Loading branch information...
1 parent 14cebfb commit 7b5ef83ee247575d4a4420f47c4b61597ec2fc8b @tboetig tboetig committed Jan 11, 2012
Showing with 33 additions and 31 deletions.
  1. +4 −0 README.rst
  2. +1 −1 examples/videos.html
  3. +27 −29 jquery.embedly.js
  4. +1 −1 jquery.embedly.min.js
View
4 README.rst
@@ -289,6 +289,10 @@ Embedly URLs
Changelog
---------
+2.1.8
+"""""
+* Fixed how default values/settings are handled
+
2.1.7
"""""
* Added secure and frame as a query param
View
2 examples/videos.html
@@ -43,7 +43,7 @@
wrapElement: 'div',
method: "after",
endpoint: 'oembed',
- key : '4d1f889c20ed11e1abb14040d3dc5c07'
+ key : '132409jafq09f3'
})
.css({color:"#ff0033",fontWeight:"bold",display:"block",padding:"2em"})
.animate({left: '+=50', opacity:0.25},
View
56 jquery.embedly.js
@@ -1,5 +1,5 @@
/*
- * Embedly JQuery v2.1.7
+ * Embedly JQuery v2.1.8
* ==============
* This library allows you to easily embed objects on any page.
*
@@ -23,17 +23,25 @@
*
* The Options Are as Follows
*
- * maxWidth : null,
- * maxHeight: null,
- * autoplay: null,
- * chars: null,
- * width: null,
- * urlRe : null,
- * method : 'replace',
- * wrapElement : 'div',
- * className : 'embed',
- * addImageStyles : true,
- * wmode : null} //after
+ * endpoint: 'oembed', // default endpoint is oembed (preview and objectify available too)
+ * chars: null, // Default number of characters in description
+ * words: null, // Default number of words in description
+ * maxWidth: null, // force a maxWidth on all returned media
+ * maxHeight: null, // force a maxHeight on all returned media
+ * secure: false, // use https endpoint vs http
+ * frame: false, // serves all embeds within an iframe to avoid XSS issues
+ * wmode: 'opaque', // for flash elements set a wmode
+ * autoplay: null, // tell videos to autoplay
+ * width: null, // force a width on all video/rich media
+ * method: 'replace', // embed handling option for standard callback
+ * addImageStyles: true, // add style="" attribute to images for maxWidth and maxHeight
+ * wrapElement: 'div', // standard wrapper around all returned embeds
+ * className: 'embed', // class on the wrapper element
+ * urlRe: null, // custom regex function
+ * key: null, // an embed.ly key
+ * elems: [], // array to hold nodes
+ * success: null, // default callback
+ * error: null // error-handling function
*
* http://api.embed.ly/tools/generator - generate your own regex for only sources you want
*
@@ -61,7 +69,7 @@
if (typeof urls === "string"){ urls = new Array(urls); }
if (typeof callback !== "undefined"){ settings.success = callback; }
if (settings.secure){ path = 'https://api.embed.ly/';}
- if (settings.success === null) {
+ if (!settings.success) {
settings.success = function(oembed, dict){
var _a, elem = $(dict.node);
if (! (oembed) ) { return null; }
@@ -71,7 +79,7 @@
else if (_a === 'replaceParent') { return elem.parent().replaceWith(oembed.code); }
};
}
- if (settings.error === null) {
+ if (!settings.error) {
settings.error = function(node, dict){
// we don't by default handle error cases
// node is the jQuery representation of the <a> tag
@@ -84,11 +92,11 @@
var getParams = function(urls){
var _p = "urls="+urls;
- if (settings.maxWidth !== null) {_p += '&maxwidth='+ settings.maxWidth;}
+ if (settings.maxWidth) {_p += '&maxwidth='+ settings.maxWidth;}
else if (typeof dimensions !== "undefined") { _p += '&maxwidth='+ dimensions.width;}
- if (settings.maxHeight !== null) {_p += '&maxheight=' +settings.maxHeight;}
- if (settings.chars !== null) {_p += '&chars='+ settings.chars;}
- if (settings.words !== null) {_p += '&words='+ settings.words;}
+ if (settings.maxHeight) {_p += '&maxheight=' +settings.maxHeight;}
+ if (settings.chars) {_p += '&chars='+ settings.chars;}
+ if (settings.words) {_p += '&words='+ settings.words;}
if (settings.secure) {_p += '&secure=true';}
if (settings.frame) {_p += '&frame=true';}
_p += '&wmode='+ settings.wmode;
@@ -212,24 +220,14 @@
// Once the function is we can add defaults as an attribute
$.embedly.defaults = {
endpoint: 'oembed', // default endpoint is oembed (preview and objectify available too)
- chars: null, // Default number of characters in description
- words: null, // Default number of words in description
- maxWidth: null, // force a maxWidth on all returned media
- maxHeight: null, // force a maxHeight on all returned media
secure: false, // use https endpoint vs http
frame: false, // serves all embeds within an iframe to avoid XSS issues
wmode: 'opaque', // for flash elements set a wmode
- autoplay: null, // tell videos to autoplay
- width: null, // force a width on all video/rich media
method: 'replace', // embed handling option for standard callback
addImageStyles: true, // add style="" attribute to images for maxWidth and maxHeight
wrapElement: 'div', // standard wrapper around all returned embeds
className: 'embed', // class on the wrapper element
- urlRe: null, // custom regex function
- key: null, // an embed.ly key
- elems: [], // array to hold nodes
- success: null, // default callback
- error: null // error-handling function
+ elems: []
};
$.fn.embedly = function(options, callback){
View
2 jquery.embedly.min.js
@@ -1 +1 @@
-(function(a){window.embedlyURLre=/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;a.embedly=a.embedly||{};if(a.embedly.version){return}a.extend({embedly:function(j,p,m){var b=[];var o="http://api.embed.ly/";var c;if(typeof p!=="undefined"){c=a.extend(a.embedly.defaults,p)}else{c=a.embedly.defaults}if(!c.urlRe){c.urlRe=window.embedlyURLre}if(typeof j==="string"){j=new Array(j)}if(typeof m!=="undefined"){c.success=m}if(c.secure){o="https://api.embed.ly/"}if(c.success===null){c.success=function(i,s){var q,r=a(s.node);if(!(i)){return null}if((q=c.method)==="replace"){return r.replaceWith(i.code)}else{if(q==="after"){return r.after(i.code)}else{if(q==="afterParent"){return r.parent().after(i.code)}else{if(q==="replaceParent"){return r.parent().replaceWith(i.code)}}}}}}if(c.error===null){c.error=function(i,q){}}var l=function(i){return c.urlRe.test(i)};var n=function(q){var i="urls="+q;if(c.maxWidth!==null){i+="&maxwidth="+c.maxWidth}else{if(typeof dimensions!=="undefined"){i+="&maxwidth="+dimensions.width}}if(c.maxHeight!==null){i+="&maxheight="+c.maxHeight}if(c.chars!==null){i+="&chars="+c.chars}if(c.words!==null){i+="&words="+c.words}if(c.secure){i+="&secure=true"}if(c.frame){i+="&frame=true"}i+="&wmode="+c.wmode;if(typeof c.key==="string"){i+="&key="+c.key}if(typeof c.autoplay==="string"||typeof c.autoplay==="boolean"){i+="&autoplay="+c.autoplay}if(c.width){i+="&width="+c.width}return i};var h=function(){if(typeof c.key==="string"){if(c.endpoint.search(/objectify/i)>=0){return o+"2/objectify"}else{if(c.endpoint.search(/preview/i)>=0){return o+"1/preview"}}}return o+"1/oembed"};var f=function(u,s){if(c.endpoint!=="oembed"){return c.success(u,s)}var v,r,q,x,t,i,w,y;if((v=u.type)==="photo"){x=u.title||"";q=[];if(c.addImageStyles){if(c.maxWidth){t=isNaN(parseInt(c.maxWidth,10))?"":"px";q.push("max-width: "+(c.maxWidth)+t)}if(c.maxHeight){t=isNaN(parseInt(c.maxHeight,10))?"":"px";q.push("max-height: "+(c.maxHeight)+t)}}q=q.join(";");r="<a href='"+s.url+"' target='_blank'><img style='"+q+"' src='"+u.url+"' alt='"+x+"' /></a>"}else{if(v==="video"){r=u.html}else{if(v==="rich"){r=u.html}else{x=u.title||s.url;i=u.thumbnail_url?'<img src="'+u.thumbnail_url+'" class="thumb" />':"";y=u.description?'<div class="description">'+u.description+"</div>":"";w=u.provider_name?'<a href="'+u.provider_url+'" class="provider">'+u.provider_name+"</a>":"";r=i+"<a href='"+s.url+"'>"+x+"</a>";r+=w;r+=y}}}if(c.wrapElement&&c.wrapElement==="div"&&a.browser.msie&&a.browser.version<9){c.wrapElement="span"}if(c.wrapElement){r="<"+c.wrapElement+' class="'+c.className+'">'+r+"</"+c.wrapElement+">"}u.code=r;if(typeof s.node!=="undefined"){a(s.node).data("oembed",u).trigger("embedly-oembed",[u])}return c.success(u,s)};var d=function(i){var s,u,t,r,q;t=a.map(i,function(w,v){if(v===0){if(w.node!==null){q=a(w.node);r={width:q.parent().width(),height:q.parent().height()}}}return encodeURIComponent(w.url)}).join(",");a.ajax({url:h(),dataType:"jsonp",data:n(t),success:function(v){return a.each(v,function(w,x){return x.type!=="error"?f(x,i[w]):c.error(i[w].node,x)})}})};a.each(j,function(r,q){var t=typeof c.elems!=="undefined"?c.elems[r]:null;if(typeof t!=="undefined"&&!l(q)){a(t).data("oembed",false)}var s={url:q,error_code:400,error_message:"HTTP 400: Bad Request",type:"error"};return(q&&l(q))?b.push({url:q,node:t}):c.error(t,s)});var k=[];var g=b.length;for(var e=0;(0<=g?e<g:e>g);e+=20){k=k.concat(d(b.slice(e,e+20)))}if(c.elems){return c.elems}else{return this}}});a.embedly.version="2.1.7";a.embedly.defaults={endpoint:"oembed",chars:null,words:null,maxWidth:null,maxHeight:null,secure:false,frame:false,wmode:"opaque",autoplay:null,width:null,method:"replace",addImageStyles:true,wrapElement:"div",className:"embed",urlRe:null,key:null,elems:[],success:null,error:null};a.fn.embedly=function(d,g){var e=typeof d!=="undefined"?d:{};if(typeof g!=="undefined"){d.success=g}var f=new Array();var c=new Array();this.each(function(){if(typeof a(this).attr("href")!=="undefined"){f.push(a(this).attr("href"));c.push(a(this))}else{a(this).find("a").each(function(){f.push(a(this).attr("href"));c.push(a(this))})}e.elems=c});var b=a.embedly(f,e);return this}})(jQuery);
+(function(a){window.embedlyURLre=/(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;a.embedly=a.embedly||{};if(a.embedly.version){return}a.extend({embedly:function(j,p,m){var b=[];var o="http://api.embed.ly/";var c;if(typeof p!=="undefined"){c=a.extend(a.embedly.defaults,p)}else{c=a.embedly.defaults}if(!c.urlRe){c.urlRe=window.embedlyURLre}if(typeof j==="string"){j=new Array(j)}if(typeof m!=="undefined"){c.success=m}if(c.secure){o="https://api.embed.ly/"}if(!c.success){c.success=function(i,s){var q,r=a(s.node);if(!(i)){return null}if((q=c.method)==="replace"){return r.replaceWith(i.code)}else{if(q==="after"){return r.after(i.code)}else{if(q==="afterParent"){return r.parent().after(i.code)}else{if(q==="replaceParent"){return r.parent().replaceWith(i.code)}}}}}}if(!c.error){c.error=function(i,q){}}var l=function(i){return c.urlRe.test(i)};var n=function(q){var i="urls="+q;if(c.maxWidth){i+="&maxwidth="+c.maxWidth}else{if(typeof dimensions!=="undefined"){i+="&maxwidth="+dimensions.width}}if(c.maxHeight){i+="&maxheight="+c.maxHeight}if(c.chars){i+="&chars="+c.chars}if(c.words){i+="&words="+c.words}if(c.secure){i+="&secure=true"}if(c.frame){i+="&frame=true"}i+="&wmode="+c.wmode;if(typeof c.key==="string"){i+="&key="+c.key}if(typeof c.autoplay==="string"||typeof c.autoplay==="boolean"){i+="&autoplay="+c.autoplay}if(c.width){i+="&width="+c.width}return i};var h=function(){if(typeof c.key==="string"){if(c.endpoint.search(/objectify/i)>=0){return o+"2/objectify"}else{if(c.endpoint.search(/preview/i)>=0){return o+"1/preview"}}}return o+"1/oembed"};var f=function(u,s){if(c.endpoint!=="oembed"){return c.success(u,s)}var v,r,q,x,t,i,w,y;if((v=u.type)==="photo"){x=u.title||"";q=[];if(c.addImageStyles){if(c.maxWidth){t=isNaN(parseInt(c.maxWidth,10))?"":"px";q.push("max-width: "+(c.maxWidth)+t)}if(c.maxHeight){t=isNaN(parseInt(c.maxHeight,10))?"":"px";q.push("max-height: "+(c.maxHeight)+t)}}q=q.join(";");r="<a href='"+s.url+"' target='_blank'><img style='"+q+"' src='"+u.url+"' alt='"+x+"' /></a>"}else{if(v==="video"){r=u.html}else{if(v==="rich"){r=u.html}else{x=u.title||s.url;i=u.thumbnail_url?'<img src="'+u.thumbnail_url+'" class="thumb" />':"";y=u.description?'<div class="description">'+u.description+"</div>":"";w=u.provider_name?'<a href="'+u.provider_url+'" class="provider">'+u.provider_name+"</a>":"";r=i+"<a href='"+s.url+"'>"+x+"</a>";r+=w;r+=y}}}if(c.wrapElement&&c.wrapElement==="div"&&a.browser.msie&&a.browser.version<9){c.wrapElement="span"}if(c.wrapElement){r="<"+c.wrapElement+' class="'+c.className+'">'+r+"</"+c.wrapElement+">"}u.code=r;if(typeof s.node!=="undefined"){a(s.node).data("oembed",u).trigger("embedly-oembed",[u])}return c.success(u,s)};var d=function(i){var s,u,t,r,q;t=a.map(i,function(w,v){if(v===0){if(w.node!==null){q=a(w.node);r={width:q.parent().width(),height:q.parent().height()}}}return encodeURIComponent(w.url)}).join(",");a.ajax({url:h(),dataType:"jsonp",data:n(t),success:function(v){return a.each(v,function(w,x){return x.type!=="error"?f(x,i[w]):c.error(i[w].node,x)})}})};a.each(j,function(r,q){var t=typeof c.elems!=="undefined"?c.elems[r]:null;if(typeof t!=="undefined"&&!l(q)){a(t).data("oembed",false)}var s={url:q,error_code:400,error_message:"HTTP 400: Bad Request",type:"error"};return(q&&l(q))?b.push({url:q,node:t}):c.error(t,s)});var k=[];var g=b.length;for(var e=0;(0<=g?e<g:e>g);e+=20){k=k.concat(d(b.slice(e,e+20)))}if(c.elems){return c.elems}else{return this}}});a.embedly.version="2.1.7";a.embedly.defaults={endpoint:"oembed",secure:false,frame:false,wmode:"opaque",method:"replace",addImageStyles:true,wrapElement:"div",className:"embed",elems:[]};a.fn.embedly=function(d,g){var e=typeof d!=="undefined"?d:{};if(typeof g!=="undefined"){d.success=g}var f=new Array();var c=new Array();this.each(function(){if(typeof a(this).attr("href")!=="undefined"){f.push(a(this).attr("href"));c.push(a(this))}else{a(this).find("a").each(function(){f.push(a(this).attr("href"));c.push(a(this))})}e.elems=c});var b=a.embedly(f,e);return this}})(jQuery);

0 comments on commit 7b5ef83

Please sign in to comment.