2011-07-17 08:05:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2010-11-12 23:16:33 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc directive
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.directive:ngHref
|
2012-03-09 23:12:48 +00:00
|
|
|
* @restrict A
|
2013-12-10 21:35:12 +00:00
|
|
|
* @priority 99
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
2013-09-22 20:03:05 +00:00
|
|
|
* Using Angular markup like `{{hash}}` in an href attribute will
|
|
|
|
|
* make the link go to the wrong URL if the user clicks it before
|
|
|
|
|
* Angular has a chance to replace the `{{hash}}` markup with its
|
|
|
|
|
* value. Until Angular replaces the markup the link will be broken
|
|
|
|
|
* and will most likely return a 404 error.
|
|
|
|
|
*
|
2012-04-06 23:35:17 +00:00
|
|
|
* The `ngHref` directive solves this problem.
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
2013-09-22 20:03:05 +00:00
|
|
|
* The wrong way to write it:
|
2010-11-12 23:16:33 +00:00
|
|
|
* <pre>
|
|
|
|
|
* <a href="http://www.gravatar.com/avatar/{{hash}}"/>
|
|
|
|
|
* </pre>
|
2011-01-19 23:42:11 +00:00
|
|
|
*
|
2010-11-12 23:16:33 +00:00
|
|
|
* The correct way to write it:
|
|
|
|
|
* <pre>
|
2012-03-09 08:00:05 +00:00
|
|
|
* <a ng-href="http://www.gravatar.com/avatar/{{hash}}"/>
|
2010-11-12 23:16:33 +00:00
|
|
|
* </pre>
|
|
|
|
|
*
|
2012-03-09 23:12:48 +00:00
|
|
|
* @element A
|
2012-04-06 23:35:17 +00:00
|
|
|
* @param {template} ngHref any string which can contain `{{}}` markup.
|
2011-05-31 12:51:47 +00:00
|
|
|
*
|
|
|
|
|
* @example
|
2013-09-22 20:03:05 +00:00
|
|
|
* This example shows various combinations of `href`, `ng-href` and `ng-click` attributes
|
|
|
|
|
* in links and their different behaviors:
|
2011-05-31 12:51:47 +00:00
|
|
|
<doc:example>
|
|
|
|
|
<doc:source>
|
2012-03-09 08:00:05 +00:00
|
|
|
<input ng-model="value" /><br />
|
|
|
|
|
<a id="link-1" href ng-click="value = 1">link 1</a> (link, don't reload)<br />
|
|
|
|
|
<a id="link-2" href="" ng-click="value = 2">link 2</a> (link, don't reload)<br />
|
2012-04-12 06:46:23 +00:00
|
|
|
<a id="link-3" ng-href="/{{'123'}}">link 3</a> (link, reload!)<br />
|
2012-03-09 08:00:05 +00:00
|
|
|
<a id="link-4" href="" name="xx" ng-click="value = 4">anchor</a> (link, don't reload)<br />
|
|
|
|
|
<a id="link-5" name="xxx" ng-click="value = 5">anchor</a> (no link)<br />
|
2012-04-12 06:46:23 +00:00
|
|
|
<a id="link-6" ng-href="{{value}}">link</a> (link, change location)
|
2011-05-31 12:51:47 +00:00
|
|
|
</doc:source>
|
|
|
|
|
<doc:scenario>
|
2012-03-09 08:00:05 +00:00
|
|
|
it('should execute ng-click but not reload when href without value', function() {
|
2011-05-31 12:51:47 +00:00
|
|
|
element('#link-1').click();
|
2011-06-08 18:18:41 +00:00
|
|
|
expect(input('value').val()).toEqual('1');
|
2011-05-31 12:51:47 +00:00
|
|
|
expect(element('#link-1').attr('href')).toBe("");
|
|
|
|
|
});
|
|
|
|
|
|
2012-03-09 08:00:05 +00:00
|
|
|
it('should execute ng-click but not reload when href empty string', function() {
|
2011-05-31 12:51:47 +00:00
|
|
|
element('#link-2').click();
|
2011-06-08 18:18:41 +00:00
|
|
|
expect(input('value').val()).toEqual('2');
|
2011-05-31 12:51:47 +00:00
|
|
|
expect(element('#link-2').attr('href')).toBe("");
|
|
|
|
|
});
|
|
|
|
|
|
2012-03-09 08:00:05 +00:00
|
|
|
it('should execute ng-click and change url when ng-href specified', function() {
|
2011-08-30 09:47:24 +00:00
|
|
|
expect(element('#link-3').attr('href')).toBe("/123");
|
|
|
|
|
|
2011-05-31 12:51:47 +00:00
|
|
|
element('#link-3').click();
|
2011-10-24 22:22:34 +00:00
|
|
|
expect(browser().window().path()).toEqual('/123');
|
2011-05-31 12:51:47 +00:00
|
|
|
});
|
|
|
|
|
|
2012-03-09 08:00:05 +00:00
|
|
|
it('should execute ng-click but not reload when href empty string and name specified', function() {
|
2011-05-31 12:51:47 +00:00
|
|
|
element('#link-4').click();
|
2011-06-08 18:18:41 +00:00
|
|
|
expect(input('value').val()).toEqual('4');
|
2012-04-12 06:46:23 +00:00
|
|
|
expect(element('#link-4').attr('href')).toBe('');
|
2011-05-31 12:51:47 +00:00
|
|
|
});
|
|
|
|
|
|
2012-03-09 08:00:05 +00:00
|
|
|
it('should execute ng-click but not reload when no href but name specified', function() {
|
2011-05-31 12:51:47 +00:00
|
|
|
element('#link-5').click();
|
2011-06-08 18:18:41 +00:00
|
|
|
expect(input('value').val()).toEqual('5');
|
2013-02-14 23:13:50 +00:00
|
|
|
expect(element('#link-5').attr('href')).toBe(undefined);
|
2011-05-31 12:51:47 +00:00
|
|
|
});
|
|
|
|
|
|
2012-03-09 08:00:05 +00:00
|
|
|
it('should only change url when only ng-href', function() {
|
2011-05-31 12:51:47 +00:00
|
|
|
input('value').enter('6');
|
2012-04-12 06:46:23 +00:00
|
|
|
expect(element('#link-6').attr('href')).toBe('6');
|
2011-08-30 09:47:24 +00:00
|
|
|
|
2011-05-31 12:51:47 +00:00
|
|
|
element('#link-6').click();
|
2012-04-12 06:46:23 +00:00
|
|
|
expect(browser().location().url()).toEqual('/6');
|
2011-05-31 12:51:47 +00:00
|
|
|
});
|
|
|
|
|
</doc:scenario>
|
|
|
|
|
</doc:example>
|
2010-11-12 23:16:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc directive
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.directive:ngSrc
|
2012-03-09 23:12:48 +00:00
|
|
|
* @restrict A
|
2013-12-10 21:35:12 +00:00
|
|
|
* @priority 99
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
2012-04-06 23:35:17 +00:00
|
|
|
* Using Angular markup like `{{hash}}` in a `src` attribute doesn't
|
2011-01-19 23:42:11 +00:00
|
|
|
* work right: The browser will fetch from the URL with the literal
|
2012-04-06 23:35:17 +00:00
|
|
|
* text `{{hash}}` until Angular replaces the expression inside
|
|
|
|
|
* `{{hash}}`. The `ngSrc` directive solves this problem.
|
2010-11-12 23:16:33 +00:00
|
|
|
*
|
|
|
|
|
* The buggy way to write it:
|
|
|
|
|
* <pre>
|
|
|
|
|
* <img src="http://www.gravatar.com/avatar/{{hash}}"/>
|
|
|
|
|
* </pre>
|
2011-01-19 23:42:11 +00:00
|
|
|
*
|
2010-11-12 23:16:33 +00:00
|
|
|
* The correct way to write it:
|
|
|
|
|
* <pre>
|
2012-03-09 08:00:05 +00:00
|
|
|
* <img ng-src="http://www.gravatar.com/avatar/{{hash}}"/>
|
2010-11-12 23:16:33 +00:00
|
|
|
* </pre>
|
|
|
|
|
*
|
2012-03-09 23:12:48 +00:00
|
|
|
* @element IMG
|
2012-04-06 23:35:17 +00:00
|
|
|
* @param {template} ngSrc any string which can contain `{{}}` markup.
|
2010-11-12 23:16:33 +00:00
|
|
|
*/
|
|
|
|
|
|
2013-05-07 16:45:28 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc directive
|
|
|
|
|
* @name ng.directive:ngSrcset
|
|
|
|
|
* @restrict A
|
2013-12-10 21:35:12 +00:00
|
|
|
* @priority 99
|
2013-05-07 16:45:28 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* Using Angular markup like `{{hash}}` in a `srcset` 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 `ngSrcset` directive solves this problem.
|
|
|
|
|
*
|
|
|
|
|
* The buggy way to write it:
|
|
|
|
|
* <pre>
|
|
|
|
|
* <img srcset="http://www.gravatar.com/avatar/{{hash}} 2x"/>
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* The correct way to write it:
|
|
|
|
|
* <pre>
|
|
|
|
|
* <img ng-srcset="http://www.gravatar.com/avatar/{{hash}} 2x"/>
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
|
|
|
|
* @element IMG
|
|
|
|
|
* @param {template} ngSrcset any string which can contain `{{}}` markup.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-06-06 19:13:07 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc directive
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.directive:ngDisabled
|
2012-03-09 23:12:48 +00:00
|
|
|
* @restrict A
|
2013-12-10 21:35:12 +00:00
|
|
|
* @priority 100
|
2011-06-06 19:13:07 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
*
|
|
|
|
|
* The following markup will make the button enabled on Chrome/Firefox but not on IE8 and older IEs:
|
|
|
|
|
* <pre>
|
2012-03-09 08:00:05 +00:00
|
|
|
* <div ng-init="scope = { isDisabled: false }">
|
2011-06-06 19:13:07 +00:00
|
|
|
* <button disabled="{{scope.isDisabled}}">Disabled</button>
|
|
|
|
|
* </div>
|
|
|
|
|
* </pre>
|
|
|
|
|
*
|
2013-10-13 00:33:45 +00:00
|
|
|
* The HTML specification does not require browsers to preserve the values of boolean attributes
|
|
|
|
|
* such as disabled. (Their presence means true and their absence means false.)
|
2013-11-19 17:34:19 +00:00
|
|
|
* If we put an Angular interpolation expression into such an attribute then the
|
|
|
|
|
* binding information would be lost when the browser removes the attribute.
|
2013-10-13 00:33:45 +00:00
|
|
|
* The `ngDisabled` directive solves this problem for the `disabled` attribute.
|
2013-11-19 17:34:19 +00:00
|
|
|
* This complementary directive is not removed by the browser and so provides
|
|
|
|
|
* a permanent reliable place to store the binding information.
|
2011-06-06 19:13:07 +00:00
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
<doc:example>
|
|
|
|
|
<doc:source>
|
2012-03-09 08:00:05 +00:00
|
|
|
Click me to toggle: <input type="checkbox" ng-model="checked"><br/>
|
2012-03-23 22:53:04 +00:00
|
|
|
<button ng-model="button" ng-disabled="checked">Button</button>
|
2011-06-06 19:13:07 +00:00
|
|
|
</doc:source>
|
|
|
|
|
<doc:scenario>
|
|
|
|
|
it('should toggle button', function() {
|
2011-09-15 22:09:33 +00:00
|
|
|
expect(element('.doc-example-live :button').prop('disabled')).toBeFalsy();
|
2011-06-06 19:13:07 +00:00
|
|
|
input('checked').check();
|
2011-09-15 22:09:33 +00:00
|
|
|
expect(element('.doc-example-live :button').prop('disabled')).toBeTruthy();
|
2011-06-06 19:13:07 +00:00
|
|
|
});
|
|
|
|
|
</doc:scenario>
|
|
|
|
|
</doc:example>
|
|
|
|
|
*
|
2012-03-09 23:12:48 +00:00
|
|
|
* @element INPUT
|
2013-09-05 12:16:16 +00:00
|
|
|
* @param {expression} ngDisabled If the {@link guide/expression expression} is truthy,
|
|
|
|
|
* then special attribute "disabled" will be set on the element
|
2011-06-06 19:13:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc directive
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.directive:ngChecked
|
2012-03-09 23:12:48 +00:00
|
|
|
* @restrict A
|
2013-12-10 21:35:12 +00:00
|
|
|
* @priority 100
|
2011-06-06 19:13:07 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
2013-10-13 00:33:45 +00:00
|
|
|
* The HTML specification does not require browsers to preserve the values of boolean attributes
|
|
|
|
|
* such as checked. (Their presence means true and their absence means false.)
|
2013-11-19 17:34:19 +00:00
|
|
|
* If we put an Angular interpolation expression into such an attribute then the
|
|
|
|
|
* binding information would be lost when the browser removes the attribute.
|
2013-10-13 00:33:45 +00:00
|
|
|
* The `ngChecked` directive solves this problem for the `checked` attribute.
|
2013-11-19 17:34:19 +00:00
|
|
|
* This complementary directive is not removed by the browser and so provides
|
|
|
|
|
* a permanent reliable place to store the binding information.
|
2011-06-06 19:13:07 +00:00
|
|
|
* @example
|
|
|
|
|
<doc:example>
|
|
|
|
|
<doc:source>
|
2012-03-09 08:00:05 +00:00
|
|
|
Check me to check both: <input type="checkbox" ng-model="master"><br/>
|
2012-03-23 22:53:04 +00:00
|
|
|
<input id="checkSlave" type="checkbox" ng-checked="master">
|
2011-06-06 19:13:07 +00:00
|
|
|
</doc:source>
|
|
|
|
|
<doc:scenario>
|
|
|
|
|
it('should check both checkBoxes', function() {
|
2011-09-15 22:09:33 +00:00
|
|
|
expect(element('.doc-example-live #checkSlave').prop('checked')).toBeFalsy();
|
2011-06-06 19:13:07 +00:00
|
|
|
input('master').check();
|
2011-09-15 22:09:33 +00:00
|
|
|
expect(element('.doc-example-live #checkSlave').prop('checked')).toBeTruthy();
|
2011-06-06 19:13:07 +00:00
|
|
|
});
|
|
|
|
|
</doc:scenario>
|
|
|
|
|
</doc:example>
|
|
|
|
|
*
|
2012-03-09 23:12:48 +00:00
|
|
|
* @element INPUT
|
2013-09-05 12:16:16 +00:00
|
|
|
* @param {expression} ngChecked If the {@link guide/expression expression} is truthy,
|
|
|
|
|
* then special attribute "checked" will be set on the element
|
2011-06-06 19:13:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc directive
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.directive:ngReadonly
|
2012-03-09 23:12:48 +00:00
|
|
|
* @restrict A
|
2013-12-10 21:35:12 +00:00
|
|
|
* @priority 100
|
2011-06-06 19:13:07 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
2013-10-13 00:33:45 +00:00
|
|
|
* The HTML specification does not require browsers to preserve the values of boolean attributes
|
|
|
|
|
* such as readonly. (Their presence means true and their absence means false.)
|
2013-11-19 17:34:19 +00:00
|
|
|
* If we put an Angular interpolation expression into such an attribute then the
|
|
|
|
|
* binding information would be lost when the browser removes the attribute.
|
2013-10-13 00:33:45 +00:00
|
|
|
* The `ngReadonly` directive solves this problem for the `readonly` attribute.
|
2013-11-19 17:34:19 +00:00
|
|
|
* This complementary directive is not removed by the browser and so provides
|
|
|
|
|
* a permanent reliable place to store the binding information.
|
2011-06-06 19:13:07 +00:00
|
|
|
* @example
|
|
|
|
|
<doc:example>
|
|
|
|
|
<doc:source>
|
2012-03-09 08:00:05 +00:00
|
|
|
Check me to make text readonly: <input type="checkbox" ng-model="checked"><br/>
|
2012-03-23 22:53:04 +00:00
|
|
|
<input type="text" ng-readonly="checked" value="I'm Angular"/>
|
2011-06-06 19:13:07 +00:00
|
|
|
</doc:source>
|
|
|
|
|
<doc:scenario>
|
|
|
|
|
it('should toggle readonly attr', function() {
|
2011-09-15 22:09:33 +00:00
|
|
|
expect(element('.doc-example-live :text').prop('readonly')).toBeFalsy();
|
2011-06-06 19:13:07 +00:00
|
|
|
input('checked').check();
|
2011-09-15 22:09:33 +00:00
|
|
|
expect(element('.doc-example-live :text').prop('readonly')).toBeTruthy();
|
2011-06-06 19:13:07 +00:00
|
|
|
});
|
|
|
|
|
</doc:scenario>
|
|
|
|
|
</doc:example>
|
|
|
|
|
*
|
2012-03-09 23:12:48 +00:00
|
|
|
* @element INPUT
|
2013-09-05 12:16:16 +00:00
|
|
|
* @param {expression} ngReadonly If the {@link guide/expression expression} is truthy,
|
|
|
|
|
* then special attribute "readonly" will be set on the element
|
2011-06-06 19:13:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-03-09 23:12:48 +00:00
|
|
|
* @ngdoc directive
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.directive:ngSelected
|
2012-03-09 23:12:48 +00:00
|
|
|
* @restrict A
|
2013-12-10 21:35:12 +00:00
|
|
|
* @priority 100
|
2012-03-09 23:12:48 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
2013-10-13 00:33:45 +00:00
|
|
|
* The HTML specification does not require browsers to preserve the values of boolean attributes
|
|
|
|
|
* such as selected. (Their presence means true and their absence means false.)
|
2013-11-19 17:34:19 +00:00
|
|
|
* If we put an Angular interpolation expression into such an attribute then the
|
|
|
|
|
* binding information would be lost when the browser removes the attribute.
|
2013-10-13 00:33:45 +00:00
|
|
|
* The `ngSelected` directive solves this problem for the `selected` atttribute.
|
2013-11-19 17:34:19 +00:00
|
|
|
* This complementary directive is not removed by the browser and so provides
|
|
|
|
|
* a permanent reliable place to store the binding information.
|
2013-12-10 21:35:12 +00:00
|
|
|
*
|
2012-03-09 23:12:48 +00:00
|
|
|
* @example
|
|
|
|
|
<doc:example>
|
|
|
|
|
<doc:source>
|
2012-03-23 22:53:04 +00:00
|
|
|
Check me to select: <input type="checkbox" ng-model="selected"><br/>
|
2012-03-09 23:12:48 +00:00
|
|
|
<select>
|
|
|
|
|
<option>Hello!</option>
|
2012-03-23 22:53:04 +00:00
|
|
|
<option id="greet" ng-selected="selected">Greetings!</option>
|
2012-03-09 23:12:48 +00:00
|
|
|
</select>
|
|
|
|
|
</doc:source>
|
|
|
|
|
<doc:scenario>
|
|
|
|
|
it('should select Greetings!', function() {
|
|
|
|
|
expect(element('.doc-example-live #greet').prop('selected')).toBeFalsy();
|
2012-03-23 22:53:04 +00:00
|
|
|
input('selected').check();
|
2012-03-09 23:12:48 +00:00
|
|
|
expect(element('.doc-example-live #greet').prop('selected')).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
</doc:scenario>
|
|
|
|
|
</doc:example>
|
2012-03-23 22:53:04 +00:00
|
|
|
*
|
2012-03-09 23:12:48 +00:00
|
|
|
* @element OPTION
|
2013-09-05 12:16:16 +00:00
|
|
|
* @param {expression} ngSelected If the {@link guide/expression expression} is truthy,
|
|
|
|
|
* then special attribute "selected" will be set on the element
|
2012-03-09 23:12:48 +00:00
|
|
|
*/
|
2012-03-08 23:00:38 +00:00
|
|
|
|
2013-01-18 04:08:27 +00:00
|
|
|
/**
|
|
|
|
|
* @ngdoc directive
|
|
|
|
|
* @name ng.directive:ngOpen
|
|
|
|
|
* @restrict A
|
2013-12-10 21:35:12 +00:00
|
|
|
* @priority 100
|
2013-01-18 04:08:27 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
2013-10-13 00:33:45 +00:00
|
|
|
* The HTML specification does not require browsers to preserve the values of boolean attributes
|
|
|
|
|
* such as open. (Their presence means true and their absence means false.)
|
2013-11-19 17:34:19 +00:00
|
|
|
* If we put an Angular interpolation expression into such an attribute then the
|
|
|
|
|
* binding information would be lost when the browser removes the attribute.
|
2013-10-13 00:33:45 +00:00
|
|
|
* The `ngOpen` directive solves this problem for the `open` attribute.
|
2013-11-19 17:34:19 +00:00
|
|
|
* This complementary directive is not removed by the browser and so provides
|
|
|
|
|
* a permanent reliable place to store the binding information.
|
2013-01-18 04:08:27 +00:00
|
|
|
* @example
|
|
|
|
|
<doc:example>
|
|
|
|
|
<doc:source>
|
|
|
|
|
Check me check multiple: <input type="checkbox" ng-model="open"><br/>
|
|
|
|
|
<details id="details" ng-open="open">
|
|
|
|
|
<summary>Show/Hide me</summary>
|
|
|
|
|
</details>
|
|
|
|
|
</doc:source>
|
|
|
|
|
<doc:scenario>
|
|
|
|
|
it('should toggle open', function() {
|
|
|
|
|
expect(element('#details').prop('open')).toBeFalsy();
|
|
|
|
|
input('open').check();
|
|
|
|
|
expect(element('#details').prop('open')).toBeTruthy();
|
|
|
|
|
});
|
|
|
|
|
</doc:scenario>
|
|
|
|
|
</doc:example>
|
|
|
|
|
*
|
|
|
|
|
* @element DETAILS
|
2013-09-05 12:16:16 +00:00
|
|
|
* @param {expression} ngOpen If the {@link guide/expression expression} is truthy,
|
|
|
|
|
* then special attribute "open" will be set on the element
|
2013-01-18 04:08:27 +00:00
|
|
|
*/
|
2012-03-08 23:00:38 +00:00
|
|
|
|
|
|
|
|
var ngAttributeAliasDirectives = {};
|
2012-03-23 22:53:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// boolean attrs are evaluated
|
|
|
|
|
forEach(BOOLEAN_ATTR, function(propName, attrName) {
|
2013-07-24 23:42:52 +00:00
|
|
|
// binding to multiple is not supported
|
|
|
|
|
if (propName == "multiple") return;
|
|
|
|
|
|
2012-03-23 22:53:04 +00:00
|
|
|
var normalized = directiveNormalize('ng-' + attrName);
|
|
|
|
|
ngAttributeAliasDirectives[normalized] = function() {
|
|
|
|
|
return {
|
2012-03-28 20:47:57 +00:00
|
|
|
priority: 100,
|
2014-01-07 13:25:46 +00:00
|
|
|
link: function(scope, element, attr) {
|
|
|
|
|
scope.$watch(attr[normalized], function ngBooleanAttrWatchAction(value) {
|
|
|
|
|
attr.$set(attrName, !!value);
|
|
|
|
|
});
|
2012-03-23 22:53:04 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2013-05-07 16:45:28 +00:00
|
|
|
// ng-src, ng-srcset, ng-href are interpolated
|
|
|
|
|
forEach(['src', 'srcset', 'href'], function(attrName) {
|
2012-03-23 22:53:04 +00:00
|
|
|
var normalized = directiveNormalize('ng-' + attrName);
|
|
|
|
|
ngAttributeAliasDirectives[normalized] = function() {
|
|
|
|
|
return {
|
2012-04-03 22:03:27 +00:00
|
|
|
priority: 99, // it needs to run after the attributes are interpolated
|
2012-06-04 22:06:02 +00:00
|
|
|
link: function(scope, element, attr) {
|
|
|
|
|
attr.$observe(normalized, function(value) {
|
2012-07-14 09:40:24 +00:00
|
|
|
if (!value)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-06-04 22:06:02 +00:00
|
|
|
attr.$set(attrName, value);
|
2012-05-06 23:30:24 +00:00
|
|
|
|
2012-06-04 22:06:02 +00:00
|
|
|
// on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist
|
|
|
|
|
// then calling element.setAttribute('src', 'foo') doesn't do anything, so we need
|
2013-02-19 17:55:05 +00:00
|
|
|
// to set the property as well to achieve the desired effect.
|
|
|
|
|
// we use attr[attrName] value since $set can sanitize the url.
|
|
|
|
|
if (msie) element.prop(attrName, attr[attrName]);
|
2012-06-04 22:06:02 +00:00
|
|
|
});
|
2012-03-23 22:53:04 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
});
|