Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Use provider to configure single page application mode. #6

Merged
merged 4 commits into from
Mar 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ How to use ?
cssInjector.add("/path/to/your/css/file.css");
}
```
4. To remove all added CSS files when the page change (in a single page application), set the single page mode :
4. To remove all added CSS files when the page change (in a single page application), configure the `cssInjectorProvider`:
```javascript
function MyCtrl($scope, cssInjector)
{
cssInjector.setSinglePageMode(true);
}
myApp.config(function(cssInjectorProvider){
cssInjectorProvider.setSinglePageMode(true);
});
```

5. To remove manually all added CSS files, call the function removeAll :
Expand Down
36 changes: 17 additions & 19 deletions angular-css-injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* https://github.com/Yappli/angular-css-injector/
*/
angular.module('angular.css.injector', [])
.service('cssInjector', [
'$compile',
'$rootScope',
function($compile, $rootScope)
{
.provider('cssInjector', function() {
var singlePageMode = false;

function CssInjector($compile, $rootScope){
// Variables
var singlePageMode = false,
head = angular.element(typeof jQuery == "undefined" ? document.querySelector('head') : 'head'), // TO make the code IE < 8 compatible, include jQuery in your page
Expand Down Expand Up @@ -59,20 +58,19 @@ angular.module('angular.css.injector', [])
if(scope.injectedStylesheets !== undefined)
scope.injectedStylesheets = []; // Make it empty
};

// Used to set the boolean `singlePageMode`. If singlePageMode===TRUE, the function `removeAll` will be call every time the page change (based on the angular event `$locationChangeStart`)
var setSinglePageMode = function(bool)
{
if(bool !== true && bool !== false)
throw("Angular service `cssInjector` : function `setSinglePageMode` : Error parameter, boolean required.");

singlePageMode = bool;
};


return {
add: addStylesheet,
removeAll: removeAll,
setSinglePageMode: setSinglePageMode,
removeAll: removeAll
};
}
]);
}

this.$get = function($compile, $rootScope){
return new CssInjector($compile, $rootScope);
};

this.setSinglePageMode = function(mode){
singlePageMode = mode;
return this;
}
});
3 changes: 1 addition & 2 deletions angular-css-injector.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.