Skip to content

Commit

Permalink
Added a blob-href directive.
Browse files Browse the repository at this point in the history
Added a blob-href directive to allow Angular to assign
attachment blob: URLs to <a href>.
  • Loading branch information
koto authored and kbsriram committed Aug 29, 2016
1 parent 3a17b4a commit 6a128d7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chrome/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ goog.require('e2email.components.appinfo.module');
goog.require('e2email.components.auth.module');
goog.require('e2email.components.autocomplete.module');
goog.require('e2email.components.autocompletedirective.module');
goog.require('e2email.components.blobhrefdirective.module');
goog.require('e2email.components.contacts.module');
goog.require('e2email.components.gmail.module');
goog.require('e2email.components.openpgp.module');
Expand Down Expand Up @@ -144,6 +145,7 @@ e2email.application.module = angular.module('e2email.application', [
e2email.components.translatefilter.module.name,
e2email.components.userinfo.module.name,
e2email.components.userlist.module.name,
e2email.components.blobhrefdirective.module.name,
'ngAnimate',
'ngAria',
'ngRoute'
Expand Down
40 changes: 40 additions & 0 deletions chrome/components/blobhref/blobhref-directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
goog.provide('e2email.components.blobhrefdirective');
goog.provide('e2email.components.blobhrefdirective.module');

goog.require('goog.string');


goog.scope(function() {


/**
* Directive that puts a blob: URL into an href attribute.
* Directive has to be used as blob: URLs are untrusted by Angular.
* See https://docs.angularjs.org/api/ng/provider/$compileProvider
* @return {!angular.Directive}
*/
e2email.components.blobhrefdirective.Directive =
function() {
return {
link: function(scope, element, attrs) {
if (goog.string.startsWith(attrs['blobHref'], 'blob:')) {
angular.element(element[0]).attr('href', attrs['blobHref']);
}
},
restrict: 'A',
};
};


/**
* Angular module.
* @type {!angular.Module}
*/
e2email.components.blobhrefdirective.module = angular
.module(
'e2email.components.blobhrefdirective.FixDownloadLinkDirective',
[])
.directive(
'blobHref',
e2email.components.blobhrefdirective.Directive);
}); // goog.scope

0 comments on commit 6a128d7

Please sign in to comment.