Package com.helger.css.tools
Class MediaQueryTools
- java.lang.Object
-
- com.helger.css.tools.MediaQueryTools
-
@Immutable public final class MediaQueryTools extends Object
A small utility class to wrap an existingCascadingStyleSheet
within a specific media, if possible.CascadingStyleSheet
can only be wrapped, if they don't contain a media rule themselves.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
canWrapInMediaQuery(CascadingStyleSheet aCSS, boolean bAllowNestedMediaQueries)
Check if the passed CSS can be wrapped in an external media rule.static CascadingStyleSheet
getWrappedInMediaQuery(CascadingStyleSheet aCSS, CSSMediaQuery aMediaQuery, boolean bAllowNestedMediaQueries)
Get the CSS wrapped in the specified media query.static CascadingStyleSheet
getWrappedInMediaQuery(CascadingStyleSheet aCSS, Iterable<? extends CSSMediaQuery> aMediaQueries, boolean bAllowNestedMediaQueries)
Get the CSS wrapped in the specified media query.static com.helger.commons.collection.impl.ICommonsList<CSSMediaQuery>
parseToMediaQuery(String sMediaQuery, ECSSVersion eVersion)
Utility method to convert a media query string to a structured list ofCSSMediaQuery
objects.
-
-
-
Method Detail
-
parseToMediaQuery
@Nullable public static com.helger.commons.collection.impl.ICommonsList<CSSMediaQuery> parseToMediaQuery(@Nullable String sMediaQuery, @Nonnull ECSSVersion eVersion)
Utility method to convert a media query string to a structured list ofCSSMediaQuery
objects.- Parameters:
sMediaQuery
- The media query string to parse. May benull
.eVersion
- The CSS version to use. May not benull
.- Returns:
null
if the passed media query isnull
or empty or not parsable.
-
canWrapInMediaQuery
public static boolean canWrapInMediaQuery(@Nullable CascadingStyleSheet aCSS, boolean bAllowNestedMediaQueries)
Check if the passed CSS can be wrapped in an external media rule.- Parameters:
aCSS
- The CSS to be checked for wrapping. May benull
.bAllowNestedMediaQueries
- iftrue
nested media queries are allowed,false
if they are prohibited.- Returns:
true
if the CSS can be wrapped,false
if it can't be wrapped.
-
getWrappedInMediaQuery
@Nullable public static CascadingStyleSheet getWrappedInMediaQuery(@Nonnull CascadingStyleSheet aCSS, @Nonnull CSSMediaQuery aMediaQuery, boolean bAllowNestedMediaQueries)
Get the CSS wrapped in the specified media query. Note: all existing rule objects are reused, so modifying them also modifies the original CSS!- Parameters:
aCSS
- The CSS to be wrapped. May not benull
.aMediaQuery
- The media query to use.bAllowNestedMediaQueries
- iftrue
nested media queries are allowed,false
if they are prohibited.- Returns:
null
if out CSS cannot be wrapped, the newly createdCascadingStyleSheet
object otherwise.
-
getWrappedInMediaQuery
@Nullable public static CascadingStyleSheet getWrappedInMediaQuery(@Nonnull CascadingStyleSheet aCSS, @Nonnull @Nonempty Iterable<? extends CSSMediaQuery> aMediaQueries, boolean bAllowNestedMediaQueries)
Get the CSS wrapped in the specified media query. Note: all existing rule objects are reused, so modifying them also modifies the original CSS!- Parameters:
aCSS
- The CSS to be wrapped. May not benull
.aMediaQueries
- The media queries to use. May neither benull
nor empty nor may it containnull
elements.bAllowNestedMediaQueries
- iftrue
nested media queries are allowed,false
if they are prohibited.- Returns:
null
if out CSS cannot be wrapped, the newly createdCascadingStyleSheet
object otherwise.
-
-