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

Commit f2e7f87

Browse files
committed
feat($$jqLite): export jqLite as a private service
This makes it easy to use jqLite's nicer class API (compared to jQuery) in modules like ngAnimate.
1 parent 40a537c commit f2e7f87

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

src/AngularPublic.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383
$TimeoutProvider,
8484
$$RAFProvider,
8585
$$AsyncCallbackProvider,
86-
$WindowProvider
86+
$WindowProvider,
87+
$$jqLiteProvider
8788
*/
8889

8990

@@ -236,7 +237,8 @@ function publishExternalAPI(angular) {
236237
$timeout: $TimeoutProvider,
237238
$window: $WindowProvider,
238239
$$rAF: $$RAFProvider,
239-
$$asyncCallback: $$AsyncCallbackProvider
240+
$$asyncCallback: $$AsyncCallbackProvider,
241+
$$jqLite: $$jqLiteProvider
240242
});
241243
}
242244
]);

src/jqLite.js

+21
Original file line numberDiff line numberDiff line change
@@ -1003,3 +1003,24 @@ forEach({
10031003
JQLite.prototype.bind = JQLite.prototype.on;
10041004
JQLite.prototype.unbind = JQLite.prototype.off;
10051005
});
1006+
1007+
1008+
// Provider for private $$jqLite service
1009+
function $$jqLiteProvider() {
1010+
this.$get = function $$jqLite() {
1011+
return extend(JQLite, {
1012+
hasClass: function(node, classes) {
1013+
if (node.attr) node = node[0];
1014+
return jqLiteHasClass(node, classes);
1015+
},
1016+
addClass: function(node, classes) {
1017+
if (node.attr) node = node[0];
1018+
return jqLiteAddClass(node, classes);
1019+
},
1020+
removeClass: function(node, classes) {
1021+
if (node.attr) node = node[0];
1022+
return jqLiteRemoveClass(node, classes);
1023+
}
1024+
});
1025+
};
1026+
}

src/ngAnimate/animate.js

+25-22
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,12 @@ angular.module('ngAnimate', ['ng'])
473473
function isMatchingElement(elm1, elm2) {
474474
return extractElementNode(elm1) == extractElementNode(elm2);
475475
}
476-
477-
var $coreAnimate;
478-
476+
var $$jqLite;
479477
$provide.decorator('$animate',
480-
['$delegate', '$$q', '$injector', '$sniffer', '$rootElement', '$$asyncCallback', '$rootScope', '$document', '$templateRequest',
481-
function($delegate, $$q, $injector, $sniffer, $rootElement, $$asyncCallback, $rootScope, $document, $templateRequest) {
482-
$coreAnimate = $delegate;
478+
['$delegate', '$$q', '$injector', '$sniffer', '$rootElement', '$$asyncCallback', '$rootScope', '$document', '$templateRequest', '$$jqLite',
479+
function($delegate, $$q, $injector, $sniffer, $rootElement, $$asyncCallback, $rootScope, $document, $templateRequest, $$$jqLite) {
480+
481+
$$jqLite = $$$jqLite;
483482
$rootElement.data(NG_ANIMATE_STATE, rootAnimateState);
484483

485484
// Wait until all directive and route-related templates are downloaded and
@@ -1382,9 +1381,11 @@ angular.module('ngAnimate', ['ng'])
13821381

13831382
//the ng-animate class does nothing, but it's here to allow for
13841383
//parent animations to find and cancel child animations when needed
1385-
$delegate.$$addClassImmediately(element, NG_ANIMATE_CLASS_NAME);
1384+
$$jqLite.addClass(element, NG_ANIMATE_CLASS_NAME);
13861385
if (options && options.tempClasses) {
1387-
$delegate.$$addClassImmediately(element, options.tempClasses);
1386+
forEach(options.tempClasses, function(className) {
1387+
$$jqLite.addClass(element, className);
1388+
});
13881389
}
13891390

13901391
var localAnimationCount = globalAnimationCounter++;
@@ -1460,7 +1461,9 @@ angular.module('ngAnimate', ['ng'])
14601461

14611462
closeAnimation.hasBeenRun = true;
14621463
if (options && options.tempClasses) {
1463-
$delegate.$$removeClassImmediately(element, options.tempClasses);
1464+
forEach(options.tempClasses, function(className) {
1465+
$$jqLite.removeClass(element, className);
1466+
});
14641467
}
14651468

14661469
var data = element.data(NG_ANIMATE_STATE);
@@ -1521,7 +1524,7 @@ angular.module('ngAnimate', ['ng'])
15211524
}
15221525

15231526
if (removeAnimations || !data.totalActive) {
1524-
$delegate.$$removeClassImmediately(element, NG_ANIMATE_CLASS_NAME);
1527+
$$jqLite.removeClass(element, NG_ANIMATE_CLASS_NAME);
15251528
element.removeData(NG_ANIMATE_STATE);
15261529
}
15271530
}
@@ -1762,22 +1765,22 @@ angular.module('ngAnimate', ['ng'])
17621765
var staggerCacheKey = cacheKey + ' ' + staggerClassName;
17631766
var applyClasses = !lookupCache[staggerCacheKey];
17641767

1765-
applyClasses && $coreAnimate.$$addClassImmediately(element, staggerClassName);
1768+
applyClasses && $$jqLite.addClass(element, staggerClassName);
17661769

17671770
stagger = getElementAnimationDetails(element, staggerCacheKey);
17681771

1769-
applyClasses && $coreAnimate.$$removeClassImmediately(element, staggerClassName);
1772+
applyClasses && $$jqLite.removeClass(element, staggerClassName);
17701773
}
17711774

1772-
$coreAnimate.$$addClassImmediately(element, className);
1775+
$$jqLite.addClass(element, className);
17731776

17741777
var formerData = element.data(NG_ANIMATE_CSS_DATA_KEY) || {};
17751778
var timings = getElementAnimationDetails(element, eventCacheKey);
17761779
var transitionDuration = timings.transitionDuration;
17771780
var animationDuration = timings.animationDuration;
17781781

17791782
if (structural && transitionDuration === 0 && animationDuration === 0) {
1780-
$coreAnimate.$$removeClassImmediately(element, className);
1783+
$$jqLite.removeClass(element, className);
17811784
return false;
17821785
}
17831786

@@ -1849,7 +1852,7 @@ angular.module('ngAnimate', ['ng'])
18491852
}
18501853

18511854
if (!staggerTime) {
1852-
$coreAnimate.$$addClassImmediately(element, activeClassName);
1855+
$$jqLite.addClass(element, activeClassName);
18531856
if (elementData.blockTransition) {
18541857
blockTransitions(node, false);
18551858
}
@@ -1859,7 +1862,7 @@ angular.module('ngAnimate', ['ng'])
18591862
var timings = getElementAnimationDetails(element, eventCacheKey);
18601863
var maxDuration = Math.max(timings.transitionDuration, timings.animationDuration);
18611864
if (maxDuration === 0) {
1862-
$coreAnimate.$$removeClassImmediately(element, activeClassName);
1865+
$$jqLite.removeClass(element, activeClassName);
18631866
animateClose(element, className);
18641867
activeAnimationComplete();
18651868
return;
@@ -1894,7 +1897,7 @@ angular.module('ngAnimate', ['ng'])
18941897

18951898
var staggerTimeout;
18961899
if (staggerTime > 0) {
1897-
$coreAnimate.$$addClassImmediately(element, pendingClassName);
1900+
$$jqLite.addClass(element, pendingClassName);
18981901
staggerTimeout = $timeout(function() {
18991902
staggerTimeout = null;
19001903

@@ -1905,8 +1908,8 @@ angular.module('ngAnimate', ['ng'])
19051908
blockAnimations(node, false);
19061909
}
19071910

1908-
$coreAnimate.$$addClassImmediately(element, activeClassName);
1909-
$coreAnimate.$$removeClassImmediately(element, pendingClassName);
1911+
$$jqLite.addClass(element, activeClassName);
1912+
$$jqLite.removeClass(element, pendingClassName);
19101913

19111914
if (styles) {
19121915
if (timings.transitionDuration === 0) {
@@ -1933,8 +1936,8 @@ angular.module('ngAnimate', ['ng'])
19331936
// timeout done method.
19341937
function onEnd() {
19351938
element.off(css3AnimationEvents, onAnimationProgress);
1936-
$coreAnimate.$$removeClassImmediately(element, activeClassName);
1937-
$coreAnimate.$$removeClassImmediately(element, pendingClassName);
1939+
$$jqLite.removeClass(element, activeClassName);
1940+
$$jqLite.removeClass(element, pendingClassName);
19381941
if (staggerTimeout) {
19391942
$timeout.cancel(staggerTimeout);
19401943
}
@@ -2022,7 +2025,7 @@ angular.module('ngAnimate', ['ng'])
20222025
}
20232026

20242027
function animateClose(element, className) {
2025-
$coreAnimate.$$removeClassImmediately(element, className);
2028+
$$jqLite.removeClass(element, className);
20262029
var data = element.data(NG_ANIMATE_CSS_DATA_KEY);
20272030
if (data) {
20282031
if (data.running) {

0 commit comments

Comments
 (0)