Asset service load now throws for unknown assets. Additionally, now allows optional default asset type to handle unknown assets.
This commit is contained in:
committed by
Sebastiaan Janssen
parent
92c17a853f
commit
0e91bb647d
@@ -250,9 +250,10 @@ angular.module('umbraco.services')
|
||||
*
|
||||
* @param {Array} pathArray string array of paths to the files to load
|
||||
* @param {Scope} scope optional scope to pass into the loader
|
||||
* @param {string} defaultAssetType optional default asset type used to load assets with no extension
|
||||
* @returns {Promise} Promise object which resolves when all the files has loaded
|
||||
*/
|
||||
load: function (pathArray, scope) {
|
||||
load: function (pathArray, scope, defaultAssetType) {
|
||||
var promise;
|
||||
|
||||
if (!angular.isArray(pathArray)) {
|
||||
@@ -294,14 +295,29 @@ angular.module('umbraco.services')
|
||||
promise = $q.all(promises);
|
||||
|
||||
// Split into css and js asset arrays, and use LazyLoad on each array
|
||||
var cssAssets = _.filter(assets,
|
||||
function (asset) {
|
||||
return asset.path.match(/(\.css$|\.css\?)/ig);
|
||||
});
|
||||
var jsAssets = _.filter(assets,
|
||||
function (asset) {
|
||||
return asset.path.match(/(\.js$|\.js\?)/ig);
|
||||
});
|
||||
var cssAssets = [];
|
||||
var jsAssets = [];
|
||||
|
||||
for (var i = 0; i < assets.length; i++) {
|
||||
var asset = assets[i];
|
||||
if (asset.path.match(/(\.css$|\.css\?)/ig)) {
|
||||
cssAssets.push(asset);
|
||||
} else if (asset.path.match(/(\.js$|\.js\?)/ig)) {
|
||||
jsAssets.push(asset);
|
||||
} else {
|
||||
// Handle unknown assets
|
||||
switch (defaultAssetType) {
|
||||
case "css":
|
||||
cssAssets.push(asset);
|
||||
break;
|
||||
case "js":
|
||||
jsAssets.push(asset);
|
||||
break;
|
||||
default:
|
||||
throw "Found unknown asset without a valid defaultAssetType specified";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function assetLoaded(asset) {
|
||||
asset.state = "loaded";
|
||||
|
||||
Reference in New Issue
Block a user