From c37596456eb4f384f30ce44aa647c2e1ca5ac815 Mon Sep 17 00:00:00 2001 From: kleiinnn Date: Sun, 30 Mar 2014 12:40:36 +0200 Subject: [PATCH 1/4] use a provider to configure if the appliaction is a single page app --- angular-css-injector.js | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/angular-css-injector.js b/angular-css-injector.js index 809ac4a..aac98b7 100644 --- a/angular-css-injector.js +++ b/angular-css-injector.js @@ -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 @@ -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; + } +}); From b42a7e55d103a1c5c04b94246285aff420c815c6 Mon Sep 17 00:00:00 2001 From: kleiinnn Date: Sun, 30 Mar 2014 12:44:56 +0200 Subject: [PATCH 2/4] use the provider to set the single page mode in readme --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c4f9721..6f10fd9 100644 --- a/README.md +++ b/README.md @@ -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){ + cssInjecotrProvider.setSinglePageMode(true); + }); ``` 5. To remove manually all added CSS files, call the function removeAll : From 5d90f726cb7f3cdbd5dda17cde8eeb16690c6a9d Mon Sep 17 00:00:00 2001 From: kleiinnn Date: Sun, 30 Mar 2014 12:45:43 +0200 Subject: [PATCH 3/4] fixed typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f10fd9..3bb6b43 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ How to use ? 4. To remove all added CSS files when the page change (in a single page application), configure the `cssInjectorProvider`: ```javascript myApp.config(function(cssInjectorProvider){ - cssInjecotrProvider.setSinglePageMode(true); + cssInjectorProvider.setSinglePageMode(true); }); ``` From 3c769925d4e74ea17a809bd0e209659ff6cbd448 Mon Sep 17 00:00:00 2001 From: kleiinnn Date: Sun, 30 Mar 2014 15:52:11 +0200 Subject: [PATCH 4/4] added new minifed file --- angular-css-injector.min.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/angular-css-injector.min.js b/angular-css-injector.min.js index cbe0ce3..3d7286a 100644 --- a/angular-css-injector.min.js +++ b/angular-css-injector.min.js @@ -1,2 +1 @@ -/* angular-css-injector - v1.0.1 - https://github.com/Yappli/angular-css-injector/ */ -angular.module("angular.css.injector",[]).service("cssInjector",["$compile","$rootScope",function(e,t){var n=false,r=angular.element(typeof jQuery=="undefined"?document.querySelector("head"):"head"),i;t.$on("$locationChangeStart",function(){if(n===true)u()});var s=function(){if(i===undefined)i=r.scope()};var o=function(t){s();if(i.injectedStylesheets===undefined){i.injectedStylesheets=[];r.append(e("")(i))}else{for(var n in i.injectedStylesheets){if(i.injectedStylesheets[n].href==t)return}}i.injectedStylesheets.push({href:t})};var u=function(){s();if(i.injectedStylesheets!==undefined)i.injectedStylesheets=[]};var a=function(e){if(e!==true&&e!==false)throw"Angular service `cssInjector` : function `setSinglePageMode` : Error parameter, boolean required.";n=e};return{add:o,removeAll:u,setSinglePageMode:a}}]) +angular.module("angular.css.injector",[]).provider("cssInjector",function(){function t(e,t){var n=false,r=angular.element(typeof jQuery=="undefined"?document.querySelector("head"):"head"),i;t.$on("$locationChangeStart",function(){if(n===true)u()});var s=function(){if(i===undefined)i=r.scope()};var o=function(t){s();if(i.injectedStylesheets===undefined){i.injectedStylesheets=[];r.append(e("")(i))}else{for(var n in i.injectedStylesheets){if(i.injectedStylesheets[n].href==t)return}}i.injectedStylesheets.push({href:t})};var u=function(){s();if(i.injectedStylesheets!==undefined)i.injectedStylesheets=[]};return{add:o,removeAll:u}}var e=false;this.$get=["$compile","$rootScope",function(e,n){return new t(e,n)}];this.setSinglePageMode=function(t){e=t;return this}}) \ No newline at end of file