Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
conditional_styles
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
conditional_styles
Commits
03489642
Commit
03489642
authored
9 years ago
by
Oleksandr Kuzava
Committed by
nginex
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2220547
by nginex: Drupal 8 version
parent
42ff4ee5
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.txt
+4
-0
4 additions, 0 deletions
CHANGELOG.txt
README.txt
+19
-9
19 additions, 9 deletions
README.txt
conditional_styles.info.yml
+1
-2
1 addition, 2 deletions
conditional_styles.info.yml
conditional_styles.module
+24
-22
24 additions, 22 deletions
conditional_styles.module
with
48 additions
and
33 deletions
CHANGELOG.txt
+
4
−
0
View file @
03489642
Conditional Styles 8.x-1.x, 2016-01-30
------------------------------------------
- #2220547 by nginex: Added Drupal 8 support
Conditional Styles 7.x-2.2, 2013-07-12
------------------------------------------
- #580440 by quicksketch: Add support for Downlevel-revealed Conditional Comments
...
...
This diff is collapsed.
Click to expand it.
README.txt
+
19
−
9
View file @
03489642
...
...
@@ -67,9 +67,12 @@ horribly-difficult-to-remember function calls to your theme's template.php file:
Blech. Who wants to do that?
This module allows you to add "conditional-stylesheets" in a much simpler
manner, by adding lines to your theme's.info file. The syntax for that is:
manner, by adding lines to your theme's.info
.yml
file. The syntax for that is:
stylesheets-conditional[EXPRESSION][MEDIA][] = stylesheet.css
conditional-stylesheets:
EXPRESSION:
MEDIA:
css/style.css
where
EXPRESSION can be any of the "downlevel-hidden" expressions specified in:
...
...
@@ -77,17 +80,24 @@ manner, by adding lines to your theme's.info file. The syntax for that is:
MEDIA can be any of the normal CSS media keywords.
For example, to add a stylesheet that only targets IE 6 and below, use:
stylesheets-conditional[lt IE 7][all][] = ie6-and-below.css
conditional-stylesheets:
lt IE 7:
all:
css/ie6-and-below.css
To add a print stylesheet for IE9 only, use:
stylesheets-conditional[IE 9][print][] = ie9.css
conditional-stylesheets:
IE 9:
print:
css/ie9.css
And to add a print stylesheet for all version of IE, use:
stylesheets-conditional[IE][print][] = ie.css
conditional-stylesheets:
IE:
print:
css/ie9.css
*** IMPORTANT ***
Drupal 7 stores a cache of the data in .info files. If you modify any lines in
your theme's .info file, you MUST refresh Drupal 7's cache by simply visiting
the Appearance page at admin/appearance.
Drupal 8 stores a cache of the data in .info.yml files. If you modify any lines in
your theme's .info.yml file, you MUST rebuild Drupal 8's cache.
This diff is collapsed.
Click to expand it.
conditional_styles.info.yml
+
1
−
2
View file @
03489642
name
:
Conditional Stylesheets
type
:
module
description
:
'
Allows
themes
to
add
conditional
stylesheets.'
package
:
Other
version
:
VERSION
core
:
8.x
package
:
Other
This diff is collapsed.
Click to expand it.
conditional_styles.module
+
24
−
22
View file @
03489642
...
...
@@ -5,31 +5,33 @@
* Adds conditional CSS from the .info file.
*/
use
\Drupal\Component\Utility\Unicode
;
/**
* Implements hook_
page_build
().
* Implements hook_
css_alter
().
*/
function
conditional_styles_
page_build
(
&
$page
)
{
function
conditional_styles_
css_alter
(
&
$css
,
\Drupal\Core\Asset\AttachedAssetsInterface
$assets
)
{
$theme_handler
=
\Drupal
::
service
(
'theme_handler'
);
$
themes
=
$theme_handler
->
listInfo
();
foreach
(
$themes
as
$
theme
)
{
$theme_
path
=
drupal_get_path
(
$theme
->
type
,
$
theme
->
name
)
;
if
(
isset
(
$theme
->
info
[
'stylesheets-conditional'
])
&&
$theme
->
status
)
{
foreach
(
$
theme
->
info
[
'stylesheets-conditional
'
]
as
$
condit
ion
=>
$media
s
)
{
foreach
(
$media
s
as
$
media
=>
$stylesheets
)
{
foreach
(
$stylesheets
as
$stylesheet
)
{
$full_path
=
$theme_path
.
'/'
.
$stylesheet
;
$page
[
'#attached'
][
'css'
][
$full_path
]
=
array
(
'group'
=>
CSS_THEME
,
'weight'
=>
999
,
'media'
=>
$media
,
'every_page'
=>
TRUE
,
'browsers'
=>
array
(
'IE'
=>
$condition
,
'!IE'
=>
strpos
(
$condition
,
'!IE'
)
===
FALSE
?
FALSE
:
TRUE
,
)
,
);
}
}
$
current_theme
=
$theme_handler
->
getDefault
();
$path
=
drupal_get_path
(
'theme'
,
$current_
theme
)
;
$info
=
$theme_
handler
->
getTheme
(
$current_
theme
)
->
info
;
if
(
!
empty
(
$info
[
'conditional-stylesheets'
])
)
{
foreach
(
$
info
[
'conditional-stylesheets
'
]
as
$
vers
ion
=>
$media
)
{
foreach
(
$media
as
$
key
=>
$file_path
)
{
$full_path
=
"
{
$path
}
/
{
$file_path
}
"
;
$css
[
$full_path
]
=
[
'group'
=>
CSS_THEME
,
'weight'
=>
999
,
'type'
=>
'file'
,
'preprocess'
=>
TRUE
,
'data'
=>
$full_path
,
'media'
=>
$key
,
'every_page'
=>
TRUE
,
'browsers'
=>
[
'IE'
=>
$version
,
'!IE'
=>
(
Unicode
::
strpos
(
$version
,
'!IE'
)
!==
FALSE
),
],
];
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment