Skip to content

Commit

Permalink
feat: Added support for specifying the type of a file.
Browse files Browse the repository at this point in the history
* Use files: [{path: 'path/to/file.x', type: 'type'}] where type is either css, html or js.
* Added support for specifying the type of a file using requireJS style syntax.
* Updated README.md
* Added a test case for loading via these methods.
  • Loading branch information
Ben Blazely authored and ocombe committed Jan 28, 2015
1 parent 11d8dc0 commit a3549ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/ocLazyLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
if(debug) {
$log.info(eventName, params);
}
}
};

/**
* Load a js/css file
Expand Down Expand Up @@ -105,10 +105,10 @@
loaded = 1;
broadcast('ocLazyLoad.fileLoaded', path);
deferred.resolve();
}
};
el.onerror = function(e) {
deferred.reject(new Error('Unable to load ' + path));
}
};
el.async = params.serie ? 0 : 1;

var insertBeforeElem = anchor.lastChild;
Expand Down Expand Up @@ -401,7 +401,7 @@
isLoaded = !!moduleExists(module);
}
return isLoaded;
}
};
if(angular.isString(modulesNames)) {
modulesNames = [modulesNames];
}
Expand Down Expand Up @@ -591,7 +591,7 @@

// Create a wrapper promise to watch the promise list and resolve it once everything is done.
return $q.all(promisesList);
}
};

filesLoader(config, localParams).then(function success() {
if(moduleName === null) {
Expand Down Expand Up @@ -769,7 +769,7 @@
provider[args[1]].apply(provider, args[2]);
}
}
}
};
if(angular.isFunction(args[2][0])) {
callInvoke(args[2][0]);
} else if(angular.isArray(args[2][0])) {
Expand Down Expand Up @@ -850,7 +850,7 @@
newInvoke = true;
regInvokes[moduleName][type].push(invokeName);
broadcast('ocLazyLoad.componentLoaded', [moduleName, type, invokeName]);
}
};
if(angular.isString(invokeList) && regInvokes[moduleName][type].indexOf(invokeList) === -1) {
onInvoke(invokeList);
} else if(angular.isObject(invokeList)) {
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/specs/ocLazyLoad.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ describe('Module: oc.lazyLoad', function() {
testModuleNoExt = {
name: 'testModuleNoExt',
files: [
{type: 'js', file: lazyLoadUrl + 'testModule.NoExtension'},
{type: 'js', path: lazyLoadUrl + 'testModule.NoExtension'},
lazyLoadUrl + 'test.css',
'css!' + lazyLoadUrl + 'test.NoExtCss',
templateUrl
]
Expand Down

0 comments on commit a3549ee

Please sign in to comment.