diff --git a/bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form/checkbox/bootstrapcheckbox/BootstrapCheckBoxPickerConfig.java b/bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form/checkbox/bootstrapcheckbox/BootstrapCheckBoxPickerConfig.java index 782af819a..4dec7f250 100644 --- a/bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form/checkbox/bootstrapcheckbox/BootstrapCheckBoxPickerConfig.java +++ b/bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form/checkbox/bootstrapcheckbox/BootstrapCheckBoxPickerConfig.java @@ -1,6 +1,9 @@ package de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstrapcheckbox; +import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.ICssClassNameProvider; import de.agilecoders.wicket.core.markup.html.bootstrap.button.ButtonGroup; +import de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons.Orientation; +import de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons.Type; import de.agilecoders.wicket.core.markup.html.bootstrap.image.IconType; import de.agilecoders.wicket.jquery.AbstractConfig; import de.agilecoders.wicket.jquery.IKey; @@ -11,65 +14,174 @@ */ public class BootstrapCheckBoxPickerConfig extends AbstractConfig { - private static final IKey Style = newKey("style", null); - private static final IKey DefaultClass = newKey("defaultClass", "btn-secondary"); - private static final IKey DisabledCursor = newKey("disabledCursor", "not-allowed"); - private static final IKey OffClass = newKey("offClass", "btn-danger"); - private static final IKey OnClass = newKey("onClass", "btn-success"); - private static final IKey OffIconCLass = newKey("offIconClass", null); - private static final IKey OnIconCLass = newKey("onIconClass", null); - private static final IKey Reverse = newKey("reverse", false); - private static final IKey ToggleKeyCodes = newKey("toggleKeyCodes", null); + private static final IKey BaseGroupCls = newKey("baseGroupCls", "btn-group"); + private static final IKey BaseCls = newKey("baseCls", "btn"); + private static final IKey GroupCls = newKey("groupCls", null); + private static final IKey Cls = newKey("cls", null); + private static final IKey OffCls = newKey("offCls", "btn-default"); + private static final IKey OnCls = newKey("onCls", "btn-default"); + private static final IKey OffActiveCls = newKey("offActiveCls", "btn-danger"); + private static final IKey OnActiveCls = newKey("onActiveCls", "btn-success"); + private static final IKey OffLabel= newKey("offLabel", "No"); + private static final IKey OnLabel= newKey("onLabel", "Yes"); + private static final IKey DisabledCursor = newKey("disabledCursor", "not-allowed"); + private static final IKey Html = newKey("html", false); + private static final IKey IconCls= newKey("iconCls", "glyphicon"); + private static final IKey OffIconCls = newKey("offIconCls", null); + private static final IKey OnIconCls = newKey("onIconCls", null); + private static final IKey OffTitle = newKey("offTitle", null); + private static final IKey OnTitle = newKey("onTitle", null); + private static final IKey SwitchAlways = newKey("switchAlways", false); + private static final IKey Reverse = newKey("reverse", false); + private static final IKey ToggleKeyCodes = newKey("toggleKeyCodes", new String[] {"13", "32"}); + private static final IKey WarningMessage = newKey("warningMessage", "Please do not use bootstrap-checkbox element in label element."); /** * Default constructor */ public BootstrapCheckBoxPickerConfig() { - withDefaultClass("btn-light"); + } + + public BootstrapCheckBoxPickerConfig withBaseGroupCls(final Orientation value) { + put(BaseGroupCls, cssClassOrNull(value)); + return this; + } + + public BootstrapCheckBoxPickerConfig withBaseCls(final String value) { + put(BaseCls, value); + return this; + } + + public BootstrapCheckBoxPickerConfig withGroupCls(final ButtonGroup.Size value) { + put(GroupCls, cssClassOrNull(value)); + return this; + } + + public BootstrapCheckBoxPickerConfig withCls(final String value) { + put(Cls, value); + return this; + } + + public BootstrapCheckBoxPickerConfig withOffCls(final Type value) { + put(OffCls, cssClassOrNull(value)); + return this; + } + + public BootstrapCheckBoxPickerConfig withOnCls(final Type value) { + put(OnCls, cssClassOrNull(value)); + return this; + } + + public BootstrapCheckBoxPickerConfig withOffActiveCls(final Type value) { + put(OffActiveCls, cssClassOrNull(value)); + return this; + } + + public BootstrapCheckBoxPickerConfig withOnActiveCls(final Type value) { + put(OnActiveCls, cssClassOrNull(value)); + return this; + } + + public BootstrapCheckBoxPickerConfig withOffLabel(final String value) { + put(OffLabel, value); + return this; + } + + public BootstrapCheckBoxPickerConfig withOnLabel(final String value) { + put(OnLabel, value); + return this; + } + + public BootstrapCheckBoxPickerConfig withDisabledCursor(final String value) { + put(DisabledCursor, value); + return this; + } + public BootstrapCheckBoxPickerConfig withHtml(final boolean value) { + put(Html, value); + return this; + } + public BootstrapCheckBoxPickerConfig withIconCls(final String value) { + put(IconCls, value); + return this; + } + public BootstrapCheckBoxPickerConfig withOffIconCls(final IconType value) { + put(OffIconCls, value); + return this; + } + public BootstrapCheckBoxPickerConfig withOnIconCls(final IconType value) { + put(OnIconCls, value); + return this; } - public BootstrapCheckBoxPickerConfig withDefaultClass(final String value) { - put(DefaultClass, value); + public BootstrapCheckBoxPickerConfig withSwitchAlwaysOffTitle(final boolean value) { + put(SwitchAlways, value); + return this; + } + + public BootstrapCheckBoxPickerConfig withReverse(final boolean value) { + put(Reverse, value); + return this; + } + + public BootstrapCheckBoxPickerConfig withToggleKeyCodes(final String[] value) { + put(ToggleKeyCodes, value); return this; } + public BootstrapCheckBoxPickerConfig withOffTitle(final String value) { + put(OffTitle, value); + return this; + } + public BootstrapCheckBoxPickerConfig withOnTitle(final String value) { + put(OnTitle, value); + return this; + } + public BootstrapCheckBoxPickerConfig withWarningMessage(final String value) { + put(WarningMessage, value); + return this; + } + + // **************************************************** + // * Old v1.x methods, used for backwards compatibility + // **************************************************** + - public BootstrapCheckBoxPickerConfig withDisabledCursor(final String value) { - put(DisabledCursor, value); + @Deprecated + public BootstrapCheckBoxPickerConfig withDefaultClass(final String value) { + put(Cls, value); return this; } + @Deprecated public BootstrapCheckBoxPickerConfig withOffClass(final String value) { - put(OffClass, value); + put(OffCls, value); return this; } + @Deprecated public BootstrapCheckBoxPickerConfig withOnClass(final String value) { - put(OnClass, value); + put(OnCls, value); return this; } + @Deprecated public BootstrapCheckBoxPickerConfig withOffIcon(final IconType value) { - put(OffIconCLass, value); - return this; + return withOffIconCls(value); } + @Deprecated public BootstrapCheckBoxPickerConfig withOnIcon(final IconType value) { - put(OnIconCLass, value); - return this; + return withOnIconCls(value); } + @Deprecated public BootstrapCheckBoxPickerConfig withStyle(final ButtonGroup.Size value) { - put(Style, value.cssClassName()); - return this; - } - - public BootstrapCheckBoxPickerConfig withReverse(final boolean value) { - put(Reverse, value); - return this; + return withGroupCls(value); } - public BootstrapCheckBoxPickerConfig withToggleKeyCodes(final String[] value) { - put(ToggleKeyCodes, value); - return this; + private String cssClassOrNull(ICssClassNameProvider provider) { + if(provider == null) + return null; + + return provider.cssClassName(); } } diff --git a/bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form/checkbox/bootstrapcheckbox/js/bootstrap-checkbox.js b/bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form/checkbox/bootstrapcheckbox/js/bootstrap-checkbox.js index 3b6467f2a..a2dcfa8b4 100644 --- a/bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form/checkbox/bootstrapcheckbox/js/bootstrap-checkbox.js +++ b/bootstrap-extensions/src/main/java/de/agilecoders/wicket/extensions/markup/html/bootstrap/form/checkbox/bootstrapcheckbox/js/bootstrap-checkbox.js @@ -1,112 +1,104 @@ -/*! - * Bootstrap-checkbox v1.2.8 (http://vsn4ik.github.io/bootstrap-checkbox) - * Copyright 2013-2015 Vasily A. (https://github.com/vsn4ik) - * Licensed under the MIT license - */ - -/** - * $.inArray: friends with IE8. Use Array.prototype.indexOf in future. - * Use this.element.hidden in future. - * $.proxy: friends with IE8. Use Function.prototype.bind in future. - */ - -'use strict'; - -(function(factory) { - if (typeof define == 'function' && define.amd) { +(function (factory) { + if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module define(['jquery'], factory); - } - else if (typeof exports == 'object') { + } else if (typeof exports === 'object') { // Node/CommonJS module.exports = factory(require('jquery')); - } - else { + } else { // Browser globals factory(jQuery); } -})(function($) { - $.create = function() { - return $($.map(arguments, function(tagName) { - return document.createElement(tagName); - })); - }; +})(function ($) { + function create() { + return $($.map(arguments, $.proxy(document, 'createElement'))); + } - function Checkboxpicker(element, options) { - this.element = element; - this.$element = $(element); + var Checkboxpicker = + /*#__PURE__*/ + function () { + function Checkboxpicker(element, options) { + this.element = element; + this.$element = $(element); + var data = this.$element.data(); // <... data-reverse> - this.options = $.extend({}, $.fn.checkboxpicker.defaults, options, this.$element.data()); + if (data.reverse === '') { + data.reverse = true; + } // <... data-switch-always> - if (this.$element.closest('label').length) { - console.warn(this.options.warningMessage); - return; - } + if (data.switchAlways === '') { + data.switchAlways = true; + } // <... data-html> - this.$group = $.create('div').addClass('btn-group'); - // .btn-group-justified works with elements as the