forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprivateMocks.js
79 lines (64 loc) · 1.91 KB
/
privateMocks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict';
/* globals xit */
function assertCompareNodes(a,b,not) {
a = a[0] ? a[0] : a;
b = b[0] ? b[0] : b;
expect(a === b).toBe(!not);
}
function baseThey(msg, vals, spec, itFn) {
var valsIsArray = angular.isArray(vals);
angular.forEach(vals, function(val, key) {
var m = msg.split('$prop').join(angular.toJson(valsIsArray ? val : key));
itFn(m, function() {
spec.call(this, val);
});
});
}
function they(msg, vals, spec) {
baseThey(msg, vals, spec, it);
}
function fthey(msg, vals, spec) {
baseThey(msg, vals, spec, fit);
}
function xthey(msg, vals, spec) {
baseThey(msg, vals, spec, xit);
}
function browserSupportsCssAnimations() {
// Support: IE < 10
// Only IE10+ support keyframes / transitions
return !(window.document.documentMode < 10);
}
function createMockStyleSheet(doc) {
doc = doc ? doc[0] : window.document;
var node = doc.createElement('style');
var head = doc.getElementsByTagName('head')[0];
head.appendChild(node);
var ss = doc.styleSheets[doc.styleSheets.length - 1];
return {
addRule: function(selector, styles) {
try {
ss.insertRule(selector + '{ ' + styles + '}', 0);
} catch (e) {
try {
ss.addRule(selector, styles);
} catch (e2) { /* empty */ }
}
},
addPossiblyPrefixedRule: function(selector, styles) {
// Support: Android <5, Blackberry Browser 10, default Chrome in Android 4.4.x
// Mentioned browsers need a -webkit- prefix for transitions & animations.
var prefixedStyles = styles.split(/\s*;\s*/g)
.filter(function(style) {
return style && /^(?:transition|animation)\b/.test(style);
})
.map(function(style) {
return '-webkit-' + style;
}).join('; ');
this.addRule(selector, prefixedStyles);
this.addRule(selector, styles);
},
destroy: function() {
head.removeChild(node);
}
};
}