forked from patternfly/angular-patternfly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
54 lines (49 loc) · 1.51 KB
/
Copy pathutils.js
File metadata and controls
54 lines (49 loc) · 1.51 KB
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
(function () {
'use strict';
angular.module('patternfly.utils').constant('pfUtils', {
merge: function (source1, source2) {
var retValue;
if (typeof angular.merge === 'function') {
retValue = this.angularMerge(source1, source2);
} else if (typeof _.merge === 'function') {
retValue = this._merge(source1, source2);
} else if (typeof $.extend === 'function') {
retValue = this.$extend(source1, source2);
} else {
retValue = this.mergeDeep(source1, source2);
}
return retValue;
},
angularMerge: function (source1, source2) {
return angular.merge({}, source1, source2);
},
_merge: function (source1, source2) {
return _.merge({}, source1, source2);
},
$extend: function (source1, source2) {
return $.extend(true, angular.copy(source1), source2);
},
mergeDeep: function (source1, source2) {
return mergeDeep({}, angular.copy(source1), angular.copy(source2));
},
colorPalette: patternfly.pfPaletteColors
});
})();
/* This function does not merge/concat Arrays.
* It replaces the earlier Array with any latter Array.
*/
function mergeDeep (dst) {
'use strict';
angular.forEach(arguments, function (obj) {
if (obj !== dst) {
angular.forEach(obj, function (value, key) {
if (dst[key] && dst[key].constructor && dst[key].constructor === Object) {
mergeDeep(dst[key], value);
} else {
dst[key] = value;
}
});
}
});
return dst;
}