Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Set markup id to the Theme's CSS resource reference
  • Loading branch information
martin-g authored and reiern70 committed Jun 2, 2017
1 parent b81d7ea commit 52f2dee
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
package de.agilecoders.wicket.core.markup.html.themes.bootstrap;

import de.agilecoders.wicket.core.Bootstrap;
import de.agilecoders.wicket.core.settings.IBootstrapSettings;
import de.agilecoders.wicket.core.settings.Theme;
import org.apache.wicket.Application;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.HeaderItem;
import org.apache.wicket.request.resource.ResourceReference;

import java.util.ArrayList;
import java.util.List;

/**
* #### Description
*
* Bootstrap theme that uses the css resource reference from bootstrap settings.
*
* #### Caution
*
* There's a constructor which is deprecated and will be removed before 1.0 is released. Please
* use {@link de.agilecoders.wicket.core.markup.html.themes.bootstrap.BootstrapTheme#BootstrapTheme(de.agilecoders.wicket.core.settings.IBootstrapSettings)}
* instead.
*
* @author Michael Haitz <[email protected]>
*/
public class BootstrapTheme extends Theme {

/**
* Construct.
*
* @param settings the bootstrap settings
*/
public BootstrapTheme(final IBootstrapSettings settings) {
super("bootstrap", settings.getCssResourceReference());
}

/**
* Construct.
*/
@Deprecated
public BootstrapTheme() {
super("bootstrap", BootstrapCssReference.instance());
super("bootstrap");
}

@Override
public List<HeaderItem> getDependencies() {
List<HeaderItem> references = new ArrayList<>();
ResourceReference cssResourceReference;
if (Application.exists()) {
IBootstrapSettings settings = Bootstrap.getSettings();
cssResourceReference = settings.getCssResourceReference();
} else {
cssResourceReference = BootstrapCssReference.instance();
}
references.add(CssHeaderItem.forReference(cssResourceReference).setId(BOOTSTRAP_THEME_MARKUP_ID));
return references;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public ActiveThemeProvider getActiveThemeProvider() {
public ThemeProvider getThemeProvider() {
ThemeProvider provider = themeProvider;

return provider != null ? provider : (themeProvider = new DefaultThemeProvider(this));
return provider != null ? provider : (themeProvider = new DefaultThemeProvider());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,9 @@ public class DefaultThemeProvider implements ThemeProvider {
private final List<ITheme> themes = Generics2.newArrayList();
private ITheme defaultTheme;

/**
* Construct.
*
* @param settings the bootstrap settings
*/
public DefaultThemeProvider(IBootstrapSettings settings) {
addDefaultTheme(new BootstrapTheme(settings));
}

/**
* Construct.
*/
@Deprecated
public DefaultThemeProvider() {
addDefaultTheme(new BootstrapTheme());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
*/
public interface ITheme {

/**
* The markup id to use for the CSS resource reference.
* If the theme is changed in an Ajax response wicket-ajax.js will properly
* remove the old &lt;link&gt; and add the new one.
*/
String BOOTSTRAP_THEME_MARKUP_ID = "wb-theme";

/**
* @return The unique name of this theme.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public BootstrapThemeTheme() {

@Override
public List<HeaderItem> getDependencies() {
return Collections.<HeaderItem>singletonList(CssHeaderItem.forReference(BootstrapThemeThemeCssReference.instance()));
HeaderItem headerItem = CssHeaderItem.forReference(BootstrapThemeThemeCssReference.instance()).setId(BOOTSTRAP_THEME_MARKUP_ID);
return Collections.singletonList(headerItem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Iterable<String> getCdnUrls() {

@Override
public List<HeaderItem> getDependencies() {
return Collections.<HeaderItem>singletonList(CssHeaderItem.forReference(reference));
return Collections.<HeaderItem>singletonList(CssHeaderItem.forReference(reference).setId(BOOTSTRAP_THEME_MARKUP_ID));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public GoogleTheme() {

@Override
public List<HeaderItem> getDependencies() {
return Collections.<HeaderItem>singletonList(CssHeaderItem.forReference(GoogleCssReference.instance()));
HeaderItem headerItem = CssHeaderItem.forReference(GoogleCssReference.instance()).setId(BOOTSTRAP_THEME_MARKUP_ID);
return Collections.singletonList(headerItem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public MaterialDesignTheme() {

@Override
public List<HeaderItem> getDependencies() {
List<HeaderItem> references = new ArrayList<HeaderItem>();
references.add(CssHeaderItem.forReference(new MaterialDesignCssReference()));
List<HeaderItem> references = new ArrayList<>();
references.add(CssHeaderItem.forReference(new MaterialDesignCssReference()).setId(BOOTSTRAP_THEME_MARKUP_ID));
references.add(JavaScriptHeaderItem.forReference(new JQueryPluginResourceReference(MaterialDesignTheme.class, "js/ripples.js")));
references.add(JavaScriptHeaderItem.forReference(new JQueryPluginResourceReference(MaterialDesignTheme.class, "js/material.js")));
references.add(OnDomReadyHeaderItem.forScript("$.material.init()"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.agilecoders.wicket.themes.markup.html.metro;

import de.agilecoders.wicket.core.markup.html.themes.bootstrap.BootstrapCssReference;
import de.agilecoders.wicket.core.settings.Theme;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.HeaderItem;
Expand Down Expand Up @@ -34,8 +33,7 @@ public MetroTheme() {
public List<HeaderItem> getDependencies() {
List<HeaderItem> references = new ArrayList<HeaderItem>();
references.addAll(super.getDependencies());
references.add(CssHeaderItem.forReference(BootstrapCssReference.instance()));
references.add(CssHeaderItem.forReference(MetroCssReference.instance()));
references.add(CssHeaderItem.forReference(MetroCssReference.instance()).setId(BOOTSTRAP_THEME_MARKUP_ID));
return references;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private VegibitTheme() {

@Override
public List<HeaderItem> getDependencies() {
return Collections.<HeaderItem>singletonList(CssHeaderItem.forReference(reference));
return Collections.<HeaderItem>singletonList(CssHeaderItem.forReference(reference).setId(BOOTSTRAP_THEME_MARKUP_ID));
}

@Override
Expand Down

0 comments on commit 52f2dee

Please sign in to comment.