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

Add media attribute to link tag #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
49 changes: 23 additions & 26 deletions angular-css-injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,36 @@ angular.module('angular.css.injector', [])
};

// Used to add a CSS files in the head tag of the page
var addStylesheet = function(href)
{
_initScope();
var addStylesheet = function (href, media){
_initScope();

if(scope.injectedStylesheets === undefined)
{
scope.injectedStylesheets = [];
head.append($compile("<link data-ng-repeat='stylesheet in injectedStylesheets' data-ng-href='" + $interpolateProvider.startSymbol() + "stylesheet.href" + $interpolateProvider.endSymbol() + "' rel='stylesheet' />")(scope)); // Found here : http://stackoverflow.com/a/11913182/1662766
}
else
{
for(var i in scope.injectedStylesheets)
{
if(scope.injectedStylesheets[i].href == href) // An url can't be added more than once. I use a loop FOR, not the function indexOf to make the code IE < 9 compatible
return;
media = media || 'screen';

if (scope.injectedStylesheets === undefined){
scope.injectedStylesheets = [];
head.append($compile("<link data-ng-repeat='stylesheet in injectedStylesheets' media='{{stylesheet.media}}' data-ng-href='{{stylesheet.href}}' rel='stylesheet' />")(scope)); // Found here : http://stackoverflow.com/a/11913182/1662766
}
else{
for (var i in scope.injectedStylesheets){
if (scope.injectedStylesheets[i].href == href && scope.injectedStylesheets[i].media == media) // An url can't be added more than once for given media. I use a loop FOR, not the function indexOf to make the code IE < 9 compatible
return;
}
}
}

scope.injectedStylesheets.push({href: href});
scope.injectedStylesheets.push({href: href, media: media});
};

var remove = function(href){
_initScope();

if(scope.injectedStylesheets){
for(var i = 0; i < scope.injectedStylesheets.length; i++){
if(scope.injectedStylesheets[i].href === href){
scope.injectedStylesheets.splice(i, 1);
return;
}
var remove = function(href){
_initScope();
if(scope.injectedStylesheets){
for(var i = 0; i < scope.injectedStylesheets.length; i++){
if(scope.injectedStylesheets[i].href === href){
scope.injectedStylesheets.splice(i, 1);
return;
}
}
};
}
};

// Used to remove all of the CSS files added with the function `addStylesheet`
var removeAll = function()
Expand Down