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

Commit 88c3480

Browse files
matskomhevery
authored andcommittedMay 8, 2013
feat($sniffer): Add support for supportsAnimations flag for detecting CSS Animations browser support
1 parent 0cb04e2 commit 88c3480

11 files changed

+101
-40
lines changed
 

‎src/ng/animator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ var $AnimatorProvider = function() {
241241
if (!parent) {
242242
parent = after ? after.parent() : element.parent();
243243
}
244-
if ((!$sniffer.supportsTransitions && !polyfillSetup && !polyfillStart) ||
244+
if ((!$sniffer.transitions && !polyfillSetup && !polyfillStart) ||
245245
(parent.inheritedData(NG_ANIMATE_CONTROLLER) || noop).running) {
246246
beforeFn(element, parent, after);
247247
afterFn(element, parent, after);

‎src/ng/sniffer.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
*
1010
* @property {boolean} history Does the browser support html5 history api ?
1111
* @property {boolean} hashchange Does the browser support hashchange event ?
12-
* @property {boolean} supportsTransitions Does the browser support CSS transition events ?
12+
* @property {boolean} transitions Does the browser support CSS transition events ?
13+
* @property {boolean} animations Does the browser support CSS animation events ?
1314
*
1415
* @description
1516
* This is very simple implementation of testing browser's features.
@@ -23,6 +24,7 @@ function $SnifferProvider() {
2324
vendorRegex = /^(Moz|webkit|O|ms)(?=[A-Z])/,
2425
bodyStyle = document.body && document.body.style,
2526
transitions = false,
27+
animations = false,
2628
match;
2729

2830
if (bodyStyle) {
@@ -34,6 +36,7 @@ function $SnifferProvider() {
3436
}
3537
}
3638
transitions = !!(('transition' in bodyStyle) || (vendorPrefix + 'Transition' in bodyStyle));
39+
animations = !!(('animation' in bodyStyle) || (vendorPrefix + 'Animation' in bodyStyle));
3740
}
3841

3942

@@ -61,7 +64,8 @@ function $SnifferProvider() {
6164
},
6265
csp: document.securityPolicy ? document.securityPolicy.isActive : false,
6366
vendorPrefix: vendorPrefix,
64-
supportsTransitions : transitions
67+
transitions : transitions,
68+
animations : animations
6569
};
6670
}];
6771
}

‎src/ngScenario/Application.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ angular.scenario.Application.prototype.navigateTo = function(url, loadFn, errorF
7575
// we don't need that for our tests, but it should be done
7676
$window.angular.resumeBootstrap([['$provide', function($provide) {
7777
$provide.decorator('$sniffer', function($delegate) {
78-
$delegate.supportsTransitions = false;
78+
$delegate.transitions = false;
7979
return $delegate;
8080
});
8181
}]]);

‎test/ng/animatorSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ describe("$animator", function() {
216216
it("should assign the ngAnimate string to all events if a string is given",
217217
inject(function($animator, $sniffer, $rootScope) {
218218
$animator.enabled(true);
219-
if (!$sniffer.supportsTransitions) return;
219+
if (!$sniffer.transitions) return;
220220
animator = $animator($rootScope, {
221221
ngAnimate : '"custom"'
222222
});
@@ -328,7 +328,7 @@ describe("$animator", function() {
328328
expect(element.css('display')).toBe('none');
329329

330330
animator.show(element);
331-
if ($sniffer.supportsTransitions) {
331+
if ($sniffer.transitions) {
332332
window.setTimeout.expect(1).process();
333333
window.setTimeout.expect(1000).process();
334334
}

‎test/ng/directive/ngIfSpec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe('ngIf ngAnimate', function () {
120120
expect(element.children().length).toBe(1);
121121
var first = element.children()[0];
122122

123-
if ($sniffer.supportsTransitions) {
123+
if ($sniffer.transitions) {
124124
expect(first.className).toContain('custom-enter-setup');
125125
window.setTimeout.expect(1).process();
126126
expect(first.className).toContain('custom-enter-start');
@@ -147,17 +147,17 @@ describe('ngIf ngAnimate', function () {
147147
expect(element.children().length).toBe(1);
148148
var first = element.children()[0];
149149

150-
if ($sniffer.supportsTransitions) {
150+
if ($sniffer.transitions) {
151151
window.setTimeout.expect(1).process();
152152
window.setTimeout.expect(1000).process();
153153
} else {
154154
expect(window.setTimeout.queue).toEqual([]);
155155
}
156156

157157
$scope.$apply('value = false');
158-
expect(element.children().length).toBe($sniffer.supportsTransitions ? 1 : 0);
158+
expect(element.children().length).toBe($sniffer.transitions ? 1 : 0);
159159

160-
if ($sniffer.supportsTransitions) {
160+
if ($sniffer.transitions) {
161161
expect(first.className).toContain('custom-leave-setup');
162162
window.setTimeout.expect(1).process();
163163
expect(first.className).toContain('custom-leave-start');
@@ -180,7 +180,7 @@ describe('ngIf ngAnimate', function () {
180180
))($scope);
181181
$scope.$apply('value = true');
182182

183-
if ($sniffer.supportsTransitions) {
183+
if ($sniffer.transitions) {
184184
window.setTimeout.expect(1).process();
185185
window.setTimeout.expect(500).process();
186186
} else {

‎test/ng/directive/ngIncludeSpec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ describe('ngInclude ngAnimate', function() {
351351
var child = jqLite(element.children()[0]);
352352
applyCSS(child, 'transition', '1s linear all');
353353

354-
if ($sniffer.supportsTransitions) {
354+
if ($sniffer.transitions) {
355355
expect(child.attr('class')).toContain('custom-enter-setup');
356356
window.setTimeout.expect(1).process();
357357

@@ -384,7 +384,7 @@ describe('ngInclude ngAnimate', function() {
384384
$rootScope.tpl = '';
385385
$rootScope.$digest();
386386

387-
if ($sniffer.supportsTransitions) {
387+
if ($sniffer.transitions) {
388388
expect(child.attr('class')).toContain('custom-leave-setup');
389389
window.setTimeout.expect(1).process();
390390

@@ -417,7 +417,7 @@ describe('ngInclude ngAnimate', function() {
417417
$rootScope.tpl = 'enter';
418418
$rootScope.$digest();
419419

420-
if ($sniffer.supportsTransitions) {
420+
if ($sniffer.transitions) {
421421
window.setTimeout.expect(1).process();
422422
window.setTimeout.expect(500).process();
423423
} else {

‎test/ng/directive/ngRepeatSpec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ describe('ngRepeat ngAnimate', function() {
608608
applyCSS(kids[i], 'transition', '1s linear all');
609609
}
610610

611-
if ($sniffer.supportsTransitions) {
611+
if ($sniffer.transitions) {
612612
angular.forEach(kids, function(kid) {
613613
expect(kid.attr('class')).toContain('custom-enter-setup');
614614
window.setTimeout.expect(1).process();
@@ -654,7 +654,7 @@ describe('ngRepeat ngAnimate', function() {
654654

655655
//the last element gets pushed down when it animates
656656
var kid = jqLite(element.children()[1]);
657-
if ($sniffer.supportsTransitions) {
657+
if ($sniffer.transitions) {
658658
expect(kid.attr('class')).toContain('custom-leave-setup');
659659
window.setTimeout.expect(1).process();
660660
expect(kid.attr('class')).toContain('custom-leave-start');
@@ -696,7 +696,7 @@ describe('ngRepeat ngAnimate', function() {
696696
var left = jqLite(kids[1]);
697697
var right = jqLite(kids[2]);
698698

699-
if ($sniffer.supportsTransitions) {
699+
if ($sniffer.transitions) {
700700
expect(first.attr('class')).toContain('custom-move-setup');
701701
window.setTimeout.expect(1).process();
702702
expect(left.attr('class')).toContain('custom-move-setup');
@@ -743,7 +743,7 @@ describe('ngRepeat ngAnimate', function() {
743743
applyCSS(first, cssProp, cssValue);
744744
applyCSS(second, cssProp, cssValue);
745745

746-
if ($sniffer.supportsTransitions) {
746+
if ($sniffer.transitions) {
747747
window.setTimeout.expect(1).process();
748748
window.setTimeout.expect(1).process();
749749
window.setTimeout.expect(500).process();

‎test/ng/directive/ngShowHideSpec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('ngShow / ngHide - ngAnimate', function() {
8787
))($scope);
8888
$scope.$digest();
8989

90-
if ($sniffer.supportsTransitions) {
90+
if ($sniffer.transitions) {
9191
expect(element.attr('class')).toContain('custom-show-setup');
9292
window.setTimeout.expect(1).process();
9393

@@ -102,7 +102,7 @@ describe('ngShow / ngHide - ngAnimate', function() {
102102

103103
$scope.on = false;
104104
$scope.$digest();
105-
if ($sniffer.supportsTransitions) {
105+
if ($sniffer.transitions) {
106106
expect(element.attr('class')).toContain('custom-hide-setup');
107107
window.setTimeout.expect(1).process();
108108
expect(element.attr('class')).toContain('custom-hide-start');
@@ -133,7 +133,7 @@ describe('ngShow / ngHide - ngAnimate', function() {
133133
$rootElement.controller('ngAnimate').running = false;
134134
$rootScope.val = false;
135135
$rootScope.$digest();
136-
if ($sniffer.supportsTransitions) {
136+
if ($sniffer.transitions) {
137137
window.setTimeout.expect(1).process();
138138
window.setTimeout.expect(0).process();
139139
} else {
@@ -157,7 +157,7 @@ describe('ngShow / ngHide - ngAnimate', function() {
157157
))($scope);
158158
$scope.$digest();
159159

160-
if ($sniffer.supportsTransitions) {
160+
if ($sniffer.transitions) {
161161
expect(element.attr('class')).toContain('custom-hide-setup');
162162
window.setTimeout.expect(1).process();
163163

@@ -173,7 +173,7 @@ describe('ngShow / ngHide - ngAnimate', function() {
173173
$scope.off = false;
174174
$scope.$digest();
175175

176-
if ($sniffer.supportsTransitions) {
176+
if ($sniffer.transitions) {
177177
expect(element.attr('class')).toContain('custom-show-setup');
178178
window.setTimeout.expect(1).process();
179179
expect(element.attr('class')).toContain('custom-show-start');

‎test/ng/directive/ngSwitchSpec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ describe('ngSwitch ngAnimate', function() {
261261
expect(element.children().length).toBe(1);
262262
var first = element.children()[0];
263263

264-
if ($sniffer.supportsTransitions) {
264+
if ($sniffer.transitions) {
265265
expect(first.className).toContain('cool-enter-setup');
266266
window.setTimeout.expect(1).process();
267267

@@ -292,7 +292,7 @@ describe('ngSwitch ngAnimate', function() {
292292
$scope.val = 'two';
293293
$scope.$digest();
294294

295-
if ($sniffer.supportsTransitions) {
295+
if ($sniffer.transitions) {
296296
window.setTimeout.expect(1).process();
297297
window.setTimeout.expect(1000).process();
298298
} else {
@@ -302,11 +302,11 @@ describe('ngSwitch ngAnimate', function() {
302302
$scope.val = 'three';
303303
$scope.$digest();
304304

305-
expect(element.children().length).toBe($sniffer.supportsTransitions ? 2 : 1);
305+
expect(element.children().length).toBe($sniffer.transitions ? 2 : 1);
306306
var first = element.children()[0];
307307

308308

309-
if ($sniffer.supportsTransitions) {
309+
if ($sniffer.transitions) {
310310
expect(first.className).toContain('cool-leave-setup');
311311
window.setTimeout.expect(1).process();
312312
window.setTimeout.expect(1).process();
@@ -315,7 +315,7 @@ describe('ngSwitch ngAnimate', function() {
315315
}
316316

317317

318-
if ($sniffer.supportsTransitions) {
318+
if ($sniffer.transitions) {
319319
expect(first.className).toContain('cool-leave-start');
320320
window.setTimeout.expect(1000).process();
321321
window.setTimeout.expect(1000).process();
@@ -339,7 +339,7 @@ describe('ngSwitch ngAnimate', function() {
339339
$rootScope.val = 'one';
340340
$rootScope.$digest();
341341

342-
if ($sniffer.supportsTransitions) {
342+
if ($sniffer.transitions) {
343343
window.setTimeout.expect(1).process();
344344
window.setTimeout.expect(500).process();
345345
} else {

‎test/ng/directive/ngViewSpec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ describe('ngView', function() {
554554
var child = jqLite(element.children()[0]);
555555
applyCSS(child, 'transition', '1s linear all');
556556

557-
if ($sniffer.supportsTransitions) {
557+
if ($sniffer.transitions) {
558558
expect(child.attr('class')).toContain('custom-enter-setup');
559559
window.setTimeout.expect(1).process();
560560

@@ -583,7 +583,7 @@ describe('ngView', function() {
583583
$location.path('/');
584584
$rootScope.$digest();
585585

586-
if ($sniffer.supportsTransitions) {
586+
if ($sniffer.transitions) {
587587
expect(child.attr('class')).toContain('custom-leave-setup');
588588
window.setTimeout.expect(1).process();
589589

@@ -614,9 +614,9 @@ describe('ngView', function() {
614614
var child = jqLite(element.children()[0]);
615615
applyCSS(child, 'transition', '0.5s linear all');
616616

617-
if($sniffer.supportsTransitions) {
617+
if($sniffer.transitions) {
618618
window.setTimeout.expect(1).process();
619-
window.setTimeout.expect($sniffer.supportsTransitions ? 500 : 0).process();
619+
window.setTimeout.expect($sniffer.transitions ? 500 : 0).process();
620620
} else {
621621
expect(window.setTimeout.queue).toEqual([]);
622622
}
@@ -641,7 +641,7 @@ describe('ngView', function() {
641641

642642
$location.path('/foo');
643643
$rootScope.$digest();
644-
if ($sniffer.supportsTransitions) {
644+
if ($sniffer.transitions) {
645645
$window.setTimeout.expect(1).process();
646646
$window.setTimeout.expect(0).process();
647647
}
@@ -650,7 +650,7 @@ describe('ngView', function() {
650650
$location.path('/bar');
651651
$rootScope.$digest();
652652
expect(n(element.text())).toEqual('1234');
653-
if ($sniffer.supportsTransitions) {
653+
if ($sniffer.transitions) {
654654
$window.setTimeout.expect(1).process();
655655
$window.setTimeout.expect(1).process();
656656
} else {

0 commit comments

Comments
 (0)
This repository has been archived.