(function () {
'use strict';
angular.module('patternfly.utils').constant('pfUtils', {
merge: function (source1, source2) {
var retValue;
Eif (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;
}
|