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

Commit 1e00db8

Browse files
committed
fix(directives): make directive names case-insensitive
+ tests + added docs for angular.directive
1 parent aaa0179 commit 1e00db8

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

src/Angular.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ var _undefined = undefined,
105105
/** @name angular.attrMarkup */
106106
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
107107
/** @name angular.directive */
108-
angularDirective = extensionMap(angular, 'directive'),
108+
angularDirective = extensionMap(angular, 'directive', lowercase),
109109
/** @name angular.widget */
110110
angularWidget = extensionMap(angular, 'widget', shivForIE),
111111
/** @name angular.filter */

src/Compiler.js

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ Compiler.prototype = {
287287
});
288288
});
289289
eachAttribute(element, function(value, name){
290+
name = lowercase(name);
290291
fn = directiveFns[name];
291292
if (fn) {
292293
element.addClass('ng-directive');

src/directives.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
/**
4-
* @ngdoc overview
4+
* @ngdoc function
55
* @name angular.directive
66
* @description
77
*
@@ -39,6 +39,24 @@
3939
* For more information about how Angular directives work, and to learn how to create your own
4040
* directives, see {@link guide/dev_guide.compiler.directives Understanding Angular Directives} in
4141
* the Angular Developer Guide.
42+
*
43+
* @param {string} name Directive identifier (case insensitive).
44+
* @param {function(string, Element)} compileFn Also called "template function" is a function called
45+
* during compilation of the template when the compiler comes across the directive being
46+
* registered. The string value of the element attribute representing the directive and
47+
* jQuery/jqLite wrapped DOM element are passed as arguments to this function.
48+
*
49+
* The `compileFn` function may return a linking function also called an instance function.
50+
* This function is called during the linking phase when a Scope is being associated with the
51+
* template or template clone (see repeater notes below). The signature of the linking function
52+
* is: `function(Element)` where Element is jQuery/jqLite wrapped DOM Element that is being
53+
* linked.
54+
*
55+
* The biggest differenciator between the compile and linking functions is how they are being called
56+
* when a directive is present within an {@link angular.widget.@ng:repeat ng:repeat}. In this case,
57+
* the compile function gets called once per occurence of the directive in the template. On the
58+
* other hand the linking function gets called once for each repeated clone of the template (times
59+
* number of occurences of the directive in the repeated template).
4260
*/
4361

4462
/**

test/AngularSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,29 @@ describe('angular', function() {
427427
});
428428
});
429429

430+
431+
describe('directive', function() {
432+
it('should register directives with case-insensitive id', function() {
433+
angularDirective('ALLCAPS', function(val, el) {el.text('+' + val + '+')});
434+
angularDirective('lowercase', function(val, el) {el.text('-' + val + '-')});
435+
436+
var el = jqLite('<div>' +
437+
'<span allcaps="xx1"></span>' +
438+
'<span ALLcaps="xx2"></span>' +
439+
'<span ALLCAPS="xx3"></span>' +
440+
'<span lowerCASE="XX4">xx4</span>' +
441+
'</div>');
442+
compile(el);
443+
expect(lowercase(sortedHtml(el))).toBe('<div>' +
444+
'<span allcaps="xx1">+xx1+</span>' +
445+
'<span allcaps="xx2">+xx2+</span>' +
446+
'<span allcaps="xx3">+xx3+</span>' +
447+
'<span lowercase="xx4">-xx4-</span>' +
448+
'</div>');
449+
});
450+
});
451+
452+
430453
describe('isDate', function() {
431454
it('should return true for Date object', function() {
432455
expect(isDate(new Date())).toBe(true);

0 commit comments

Comments
 (0)