Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

add ngPoster directive for VIDEO tag. #4408

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/ng/directive/booleanAttrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@
* @param {template} ngSrc any string which can contain `{{}}` markup.
*/

/**
* @ngdoc directive
* @name ng.directive:ngPoster
* @restrict A
*
* @description
* Using Angular markup like `{{hash}}` in a `poster` attribute doesn't
* work right: The browser will fetch from the URL with the literal
* text `{{hash}}` until Angular replaces the expression inside
* `{{hash}}`. The `ngPoster` directive solves this problem.
*
* The buggy way to write it:
* <pre>
* <video poster="http://www.gravatar.com/avatar/{{hash}}"></video>
* </pre>
*
* The correct way to write it:
* <pre>
* <video ng-poster="http://www.gravatar.com/avatar/{{hash}}"></video>
* </pre>
*
* @element VIDEO
* @param {template} ngPoster any string which can contain `{{}}` markup.
*/

/**
* @ngdoc directive
* @name ng.directive:ngSrcset
Expand Down Expand Up @@ -325,8 +350,8 @@ forEach(BOOLEAN_ATTR, function(propName, attrName) {
});


// ng-src, ng-srcset, ng-href are interpolated
forEach(['src', 'srcset', 'href'], function(attrName) {
// ng-src, ng-srcset, ng-href, ng-poster are interpolated
forEach(['src', 'srcset', 'href', 'poster'], function(attrName) {
var normalized = directiveNormalize('ng-' + attrName);
ngAttributeAliasDirectives[normalized] = function() {
return {
Expand Down
19 changes: 19 additions & 0 deletions test/ng/directive/booleanAttrsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,22 @@ describe('ngHref', function() {
expect(element.attr('href')).toEqual('http://server');
}));
});

describe("ngPoster", function() {
var element;

afterEach(function() {
dealoc(element);
});

it("should interpolate the expression and bind the poster", inject(function($rootScope, $compile){
element = $compile('<video ng-poster="some/{{poster_img}}"></video>')($rootScope)
$rootScope.$digest();
expect(element.attr('poster')).toEqual('some/');

$rootScope.$apply(function() {
$rootScope.poster_img = 1;
});
expect(element.attr('poster')).toEqual('some/1');
}));
});