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

Commit af3c6a7

Browse files
author
Yappli
committed
Create angularDynamicStylesheets.js
Initial release
1 parent 25c50bf commit af3c6a7

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

angularDynamicStylesheets.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* angularDynamicStylesheets v0.1.0
3+
* Copyleft 2013 Yappli
4+
*
5+
* This program is free software. It comes without any warranty, to
6+
* the extent permitted by applicable law. You can redistribute it
7+
* and/or modify it under the terms of the Do What The Fuck You Want
8+
* To Public License, Version 2, as published by Sam Hocevar. See
9+
* http://sam.zoy.org/wtfpl/COPYING for more details.
10+
*/
11+
var angularDynamicStylesheets = angular.module('DynamicStylesheets', []); // Specific module. Optional
12+
13+
// Add the service to the module
14+
angularDynamicStylesheets.service('dynamicStylesheets', [
15+
'$rootScope',
16+
'$compile',
17+
function($rootScope, $compile) {
18+
19+
var scope = angular.element('head').scope();
20+
21+
var addStylesheet = function(href)
22+
{
23+
if(scope.stylesheets_service_dynamicStylesheets === undefined)
24+
{
25+
angular.element('head').scope().stylesheets_service_dynamicStylesheets = [];
26+
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
27+
}
28+
else
29+
{
30+
for(var i in scope.stylesheets_service_dynamicStylesheets)
31+
{
32+
if(scope.stylesheets_service_dynamicStylesheets[i].href == href) // Unique
33+
return;
34+
}
35+
}
36+
37+
scope.stylesheets_service_dynamicStylesheets.push({href: href});
38+
};
39+
40+
return {
41+
add: addStylesheet,
42+
};
43+
}
44+
]);

0 commit comments

Comments
 (0)