forked from GabrielDelepine/angular-css-injector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angularDynamicStylesheets.js
44 lines (39 loc) · 1.63 KB
/
angularDynamicStylesheets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* angularDynamicStylesheets v0.1.0
* Copyleft 2013 Yappli
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/
var angularDynamicStylesheets = angular.module('DynamicStylesheets', []); // Specific module. Optional
// Add the service to the module
angularDynamicStylesheets.service('dynamicStylesheets', [
'$rootScope',
'$compile',
function($rootScope, $compile) {
var scope = angular.element('head').scope();
var addStylesheet = function(href)
{
if(scope.stylesheets_service_dynamicStylesheets === undefined)
{
angular.element('head').scope().stylesheets_service_dynamicStylesheets = [];
angular.element('head').append($compile("<link data-ng-repeat='stylesheet in stylesheets_service_dynamicStylesheets' data-ng-href='{{stylesheet.href}}' rel='stylesheet' />")(scope)); // Found here : http://stackoverflow.com/a/11913182/1662766
}
else
{
for(var i in scope.stylesheets_service_dynamicStylesheets)
{
if(scope.stylesheets_service_dynamicStylesheets[i].href == href) // Unique
return;
}
}
scope.stylesheets_service_dynamicStylesheets.push({href: href});
};
return {
add: addStylesheet,
};
}
]);