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

Commit 0243b00

Browse files
Michel Boudreaumboudreau
Michel Boudreau
authored andcommitted
adding other ng prefixes to be added and test to jq(), fixing documentation error by adding @module ng, changing @element to be any
1 parent 279c626 commit 0243b00

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

src/Angular.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,10 @@ var csp = function() {
902902

903903
/**
904904
* @ngdoc directive
905+
* @module ng
905906
* @name ngJq
906907
*
907-
* @element html
908+
* @element ANY
908909
* @param {string=} the name of the library available under `window`
909910
* to be used for angular.element
910911
* @description
@@ -913,7 +914,7 @@ var csp = function() {
913914
* the jquery variable under window (eg. jQuery).
914915
*
915916
* Since this directive is global for the angular library, it is recommended
916-
* that it's added to the top-most HTML element, but it is not mandatory.
917+
* that it's added to the same element as ng-app or the HTML element, but it is not mandatory.
917918
*
918919
* @example
919920
* This example shows how to force jqLite using the `ngJq` directive to the `html` tag.
@@ -937,12 +938,17 @@ var csp = function() {
937938
*/
938939
var jq = function() {
939940
if (isDefined(jq.name_)) return jq.name_;
941+
var el;
942+
var i, ii = ngAttrPrefixes.length;
943+
for (i = 0; i < ii; ++i) {
944+
if (el = document.querySelector('[' + ngAttrPrefixes[i].replace(':', '\\:') + 'jq]')) {
945+
break;
946+
}
947+
}
940948

941-
var el = document.querySelector('[ng-jq]') || document.querySelector('[data-ng-jq]');
942949
var name;
943-
944950
if (el) {
945-
name = el.getAttribute('ng-jq') || el.getAttribute('data-ng-jq') || '';
951+
name = getNgAttribute(el, "jq") || '';
946952
}
947953

948954
return (jq.name_ = name);

test/AngularSpec.js

+40-3
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ describe('angular', function() {
616616

617617

618618
describe('jq', function() {
619-
var element, fakeQuery;
619+
var element;
620620

621621
beforeEach(function() {
622622
element = document.createElement('html');
@@ -648,22 +648,59 @@ describe('angular', function() {
648648
expect(document.querySelector).toHaveBeenCalledWith('[data-ng-jq]');
649649
});
650650

651-
it('should return "jquery" when jq is enabled manually via [ng-jq] with value "jquery"', function() {
651+
it('should return empty string when jq is enabled manually via [x-ng-jq] with empty string', function() {
652+
element.setAttribute('x-ng-jq', '');
653+
spyOn(document, 'querySelector').andCallFake(function(selector) {
654+
if (selector == '[x-ng-jq]') return element;
655+
});
656+
expect(jq()).toBe('');
657+
expect(document.querySelector).toHaveBeenCalledWith('[x-ng-jq]');
658+
});
659+
660+
it('should return empty string when jq is enabled manually via [ng:jq] with empty string', function() {
661+
element.setAttribute('ng:jq', '');
662+
spyOn(document, 'querySelector').andCallFake(function(selector) {
663+
if (selector == '[ng\\:jq]') return element;
664+
});
665+
expect(jq()).toBe('');
666+
expect(document.querySelector).toHaveBeenCalledWith('[ng\\:jq]');
667+
});
668+
669+
it('should return "jquery" when jq is enabled manually via [ng-jq] with value "jQuery"', function() {
652670
element.setAttribute('ng-jq', 'jQuery');
653671
spyOn(document, 'querySelector').andCallFake(function(selector) {
654672
if (selector == '[ng-jq]') return element;
655673
});
656674
expect(jq()).toBe('jQuery');
675+
expect(document.querySelector).toHaveBeenCalledWith('[ng-jq]');
657676
});
658677

659-
it('should return "jquery" when jq is enabled manually via [data-ng-jq] with value "jquery"', function() {
678+
it('should return "jquery" when jq is enabled manually via [data-ng-jq] with value "jQuery"', function() {
660679
element.setAttribute('data-ng-jq', 'jQuery');
661680
spyOn(document, 'querySelector').andCallFake(function(selector) {
662681
if (selector == '[data-ng-jq]') return element;
663682
});
664683
expect(jq()).toBe('jQuery');
665684
expect(document.querySelector).toHaveBeenCalledWith('[data-ng-jq]');
666685
});
686+
687+
it('should return "jquery" when jq is enabled manually via [x-ng-jq] with value "jQuery"', function() {
688+
element.setAttribute('x-ng-jq', 'jQuery');
689+
spyOn(document, 'querySelector').andCallFake(function(selector) {
690+
if (selector == '[x-ng-jq]') return element;
691+
});
692+
expect(jq()).toBe('jQuery');
693+
expect(document.querySelector).toHaveBeenCalledWith('[x-ng-jq]');
694+
});
695+
696+
it('should return "jquery" when jq is enabled manually via [ng:jq] with value "jQuery"', function() {
697+
element.setAttribute('ng:jq', 'jQuery');
698+
spyOn(document, 'querySelector').andCallFake(function(selector) {
699+
if (selector == '[ng\\:jq]') return element;
700+
});
701+
expect(jq()).toBe('jQuery');
702+
expect(document.querySelector).toHaveBeenCalledWith('[ng\\:jq]');
703+
});
667704
});
668705

669706

0 commit comments

Comments
 (0)