-
Notifications
You must be signed in to change notification settings - Fork 292
add bootstrap theme to select2 #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package org.wicketstuff.select2; | ||
|
|
||
| import org.apache.wicket.Component; | ||
| import org.apache.wicket.markup.head.IHeaderResponse; | ||
|
|
||
| /** | ||
| * Defines a select2 theme. | ||
| * | ||
| */ | ||
| public interface ISelect2Theme { | ||
|
|
||
| /** | ||
| * Allows theme to contribute headers (e.g. extra CSS resources) | ||
| * | ||
| * @param component The component | ||
| * @param response The header response | ||
| */ | ||
| void renderHead(final Component component, final IHeaderResponse response); | ||
|
|
||
| /** | ||
| * | ||
| * @return The name of the theme. | ||
| */ | ||
| String name(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package org.wicketstuff.select2; | ||
|
|
||
| import de.agilecoders.wicket.webjars.request.resource.WebjarsCssResourceReference; | ||
| import org.apache.wicket.Component; | ||
| import org.apache.wicket.markup.head.CssHeaderItem; | ||
| import org.apache.wicket.markup.head.IHeaderResponse; | ||
| import org.apache.wicket.request.resource.CssResourceReference; | ||
| import org.apache.wicket.request.resource.ResourceReference; | ||
|
|
||
| /** | ||
| * Select2BootstrapThemeBehavior. Adds bootstrap look and feel to select2, See | ||
| * | ||
| * https://github.com/select2/select2-bootstrap-theme | ||
| * | ||
| * @author Ernesto Reinaldo Barreiro (reirn70@gmail.com) | ||
| * | ||
| */ | ||
| public class Select2BootstrapTheme implements ISelect2Theme { | ||
|
|
||
| private boolean useBootstrapWebJar = false; | ||
|
|
||
| private static final ResourceReference CSS = new CssResourceReference(Select2BootstrapTheme.class, "/res/bootstrap/select2-bootstrap.css"); | ||
|
|
||
|
|
||
| public Select2BootstrapTheme(boolean useBootstrapWebJar) { | ||
| this.useBootstrapWebJar = useBootstrapWebJar; | ||
| } | ||
|
|
||
| public void renderHead(final Component varComponent, final IHeaderResponse response) { | ||
| if(useBootstrapWebJar) { | ||
| response.render(CssHeaderItem.forReference(new WebjarsCssResourceReference("/bootstrap/current/css/bootstrap.css"))); | ||
| } | ||
| response.render(CssHeaderItem.forReference(CSS)); | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return "bootstrap"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,11 @@ | |
|
|
||
| import java.io.Serializable; | ||
|
|
||
| import org.apache.wicket.Component; | ||
| import org.apache.wicket.WicketRuntimeException; | ||
| import org.apache.wicket.ajax.json.JSONException; | ||
| import org.apache.wicket.ajax.json.JSONStringer; | ||
| import org.apache.wicket.markup.head.IHeaderResponse; | ||
| import org.wicketstuff.select2.json.Json; | ||
|
|
||
| /** | ||
|
|
@@ -53,7 +55,6 @@ public static class Widths | |
| private String initSelection; //TODO this will not work | ||
| private String query; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm afraid this change breaks original meaning of 'theme' described here: https://select2.github.io/examples.html#themes-templating-responsive-design
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it wont: there is still a setter receiving an String (the name of the theme). To the end user noting changes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disregard my comment: I need some time to digest info there.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still fail to see how it will break it the only thing I think we don't cover is
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually 'templating' from your last comment is supported by 'templateResult' settings (we are using it in our project) |
||
| private String width; | ||
| private String theme; | ||
| private String containerCss, dropdownCss, containerCssClass, dropdownCssClass; //TODO deprecated | ||
|
|
||
| private AjaxSettings ajax; | ||
|
|
@@ -63,6 +64,10 @@ public static class Widths | |
| private String[] tokenSeparators; | ||
| private boolean selectOnClose; | ||
| private boolean dropdownAutoWidth; | ||
| /** | ||
| * Theme is an interface that might contribute to the headers. | ||
| */ | ||
| private ISelect2Theme theme; | ||
|
|
||
| /** | ||
| * If stateless is set to true then component will not be used as context | ||
|
|
@@ -104,7 +109,7 @@ public CharSequence toJson() | |
| Json.writeFunction(writer, "initSelection", initSelection); | ||
| Json.writeFunction(writer, "query", query); | ||
| Json.writeObject(writer, "width", width); | ||
| Json.writeObject(writer, "theme", theme); | ||
| Json.writeObject(writer, "theme", theme != null? theme.name(): null); | ||
| Json.writeFunction(writer, "containerCss", containerCss); | ||
| Json.writeObject(writer, "containerCssClass", containerCssClass); | ||
| Json.writeFunction(writer, "dropdownCss", dropdownCss); | ||
|
|
@@ -428,17 +433,34 @@ public Settings setWidth(String width) | |
| return this; | ||
| } | ||
|
|
||
| public String getTheme() | ||
| public ISelect2Theme getTheme() | ||
| { | ||
| return theme; | ||
| } | ||
|
|
||
| public Settings setTheme(String theme) | ||
| public Settings setTheme(final String theme) | ||
| { | ||
| this.theme = theme; | ||
| this.theme = new ISelect2Theme() { | ||
|
|
||
| @Override | ||
| public void renderHead(Component varComponent, IHeaderResponse varResponse) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return theme; | ||
| } | ||
| }; | ||
| return this; | ||
| } | ||
|
|
||
|
|
||
| public Settings setTheme(ISelect2Theme theme) { | ||
| this.theme = theme; | ||
| return this; | ||
| } | ||
|
|
||
| public String getContainerCss() | ||
| { | ||
| return containerCss; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whitespaces :(
in whole patch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know :-( See my apologies on wicket list ;-) I should fix my settings.