From ecf4da91026db0ba27c9e242b4120090a166b9e4 Mon Sep 17 00:00:00 2001 From: Diogo Ribeiro Date: Sat, 29 Nov 2014 20:40:35 -0200 Subject: [PATCH] adding flags for compatibility w/ full https websites --- angular-embedly.js | 15 +++++++++++++-- em-minified/angular-embedly.min.js | 2 +- src/services/embedlyService.js | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/angular-embedly.js b/angular-embedly.js index 7fd86a5..0505b6c 100755 --- a/angular-embedly.js +++ b/angular-embedly.js @@ -10,6 +10,7 @@ var angularEmbedly = angular.module('angular-embedly', []); (function (module) { module.provider('embedlyService', function () { var key; + var secure; this.setKey = function(userKey) { key = userKey; return key; @@ -17,11 +18,21 @@ var angularEmbedly = angular.module('angular-embedly', []); this.getKey = function() { return key; } + this.secure = function(value) { + if (!value) { + return secure; + } + secure = value; + } + + function getProtocol() { + return secure ? 'https' : 'https' ; + } function embedly($http) { this.embed = function(inputUrl, maxwidth) { var escapedUrl = encodeURI(inputUrl); - var embedlyRequest = 'http://api.embed.ly/1/oembed?key=' + key + '&url=' + escapedUrl; + var embedlyRequest = getProtocol() + '://api.embed.ly/1/oembed?key=' + key + '&url=' + escapedUrl; if(typeof maxwidth !== 'undefined'){ embedlyRequest = embedlyRequest + '&maxwidth=' + maxwidth; @@ -31,7 +42,7 @@ var angularEmbedly = angular.module('angular-embedly', []); }; this.extract = function(inputUrl) { var escapedUrl = encodeURI(inputUrl); - var embedlyRequest = 'http://api.embed.ly/1/extract?key=' + key + '&url=' + escapedUrl; + var embedlyRequest = getProtocol + '://api.embed.ly/1/extract?key=' + key + '&url=' + escapedUrl; return $http({method: 'GET', url: embedlyRequest}); }; } diff --git a/em-minified/angular-embedly.min.js b/em-minified/angular-embedly.min.js index 4298745..e636d92 100755 --- a/em-minified/angular-embedly.min.js +++ b/em-minified/angular-embedly.min.js @@ -1 +1 @@ -var angularEmbedly=angular.module("angular-embedly",[]);!function(e){e.provider("embedlyService",function(){function e(e){this.embed=function(d,n){var o=encodeURI(d),r="http://api.embed.ly/1/oembed?key="+t+"&url="+o;return"undefined"!=typeof n&&(r=r+"&maxwidth="+n),e({method:"GET",url:r})},this.extract=function(d){var n=encodeURI(d),o="http://api.embed.ly/1/extract?key="+t+"&url="+n;return e({method:"GET",url:o})}}var t;this.setKey=function(e){return t=e},this.getKey=function(){return t},this.$get=["$http",function(t){return new e(t)}]})}(angularEmbedly),function(e){e.controller("emEmbedCtrl",["$scope",function(e){e.embedCode=""}])}(angularEmbedly),function(e){e.directive("emEmbed",["embedlyService",function(e){return{restrict:"E",scope:{urlsearch:"@",maxwidth:"@",onempty:"&"},controller:"emEmbedCtrl",link:function(t,d){function n(){void 0!=t.onempty&&"function"==typeof t.onempty&&t.onempty()}t.$parent.loading_embedly=!1,t.$watch("urlsearch",function(o){var r=t.embedCode;o&&(t.$parent.loading_embedly=!0,e.embed(o,t.maxwidth).then(function(e){switch(t.$parent.loading_embedly=!1,e.data.type){case"video":void 0==e.data.html?n():t.embedCode=e.data.html;break;case"photo":void 0==e.data.url?n():t.embedCode='';break;default:n(),t.embedCode=""}r!==t.embedCode&&d.html("
"+t.embedCode+"
")},function(){t.$parent.loading_embedly=!1;var e=t.embedCode;t.embedCode="",e!==t.embedCode&&d.html("
"+t.embedCode+"
")}))})}}}])}(angularEmbedly); \ No newline at end of file +var angularEmbedly=angular.module("angular-embedly",[]);!function(e){e.provider("embedlyService",function(){function e(){return d?"https":"https"}function t(t){this.embed=function(d,o){var r=encodeURI(d),i=e()+"://api.embed.ly/1/oembed?key="+n+"&url="+r;return"undefined"!=typeof o&&(i=i+"&maxwidth="+o),t({method:"GET",url:i})},this.extract=function(d){var o=encodeURI(d),r=e+"://api.embed.ly/1/extract?key="+n+"&url="+o;return t({method:"GET",url:r})}}var n,d;this.setKey=function(e){return n=e},this.getKey=function(){return n},this.secure=function(e){return e?(d=e,void 0):d},this.$get=["$http",function(e){return new t(e)}]})}(angularEmbedly),function(e){e.controller("emEmbedCtrl",["$scope",function(e){e.embedCode=""}])}(angularEmbedly),function(e){e.directive("emEmbed",["embedlyService",function(e){return{restrict:"E",scope:{urlsearch:"@",maxwidth:"@",onempty:"&"},controller:"emEmbedCtrl",link:function(t,n){function d(){void 0!=t.onempty&&"function"==typeof t.onempty&&t.onempty()}t.$parent.loading_embedly=!1,t.$watch("urlsearch",function(o){var r=t.embedCode;o&&(t.$parent.loading_embedly=!0,e.embed(o,t.maxwidth).then(function(e){switch(t.$parent.loading_embedly=!1,e.data.type){case"video":void 0==e.data.html?d():t.embedCode=e.data.html;break;case"photo":void 0==e.data.url?d():t.embedCode='';break;default:d(),t.embedCode=""}r!==t.embedCode&&n.html("
"+t.embedCode+"
")},function(){t.$parent.loading_embedly=!1;var e=t.embedCode;t.embedCode="",e!==t.embedCode&&n.html("
"+t.embedCode+"
")}))})}}}])}(angularEmbedly); \ No newline at end of file diff --git a/src/services/embedlyService.js b/src/services/embedlyService.js index c0b15da..2bdf741 100644 --- a/src/services/embedlyService.js +++ b/src/services/embedlyService.js @@ -5,6 +5,7 @@ (function (module) { module.provider('embedlyService', function () { var key; + var secure; this.setKey = function(userKey) { key = userKey; return key; @@ -12,11 +13,21 @@ this.getKey = function() { return key; } + this.secure = function(value) { + if (!value) { + return secure; + } + secure = value; + } + + function getProtocol() { + return secure ? 'https' : 'https' ; + } function embedly($http) { this.embed = function(inputUrl, maxwidth) { var escapedUrl = encodeURI(inputUrl); - var embedlyRequest = 'http://api.embed.ly/1/oembed?key=' + key + '&url=' + escapedUrl; + var embedlyRequest = getProtocol() + '://api.embed.ly/1/oembed?key=' + key + '&url=' + escapedUrl; if(typeof maxwidth !== 'undefined'){ embedlyRequest = embedlyRequest + '&maxwidth=' + maxwidth; @@ -26,7 +37,7 @@ }; this.extract = function(inputUrl) { var escapedUrl = encodeURI(inputUrl); - var embedlyRequest = 'http://api.embed.ly/1/extract?key=' + key + '&url=' + escapedUrl; + var embedlyRequest = getProtocol + '://api.embed.ly/1/extract?key=' + key + '&url=' + escapedUrl; return $http({method: 'GET', url: embedlyRequest}); }; }