com.jwebmp.plugins.bootstrap.navbar.toggler.BSNavBarToggler Maven / Gradle / Ivy
Show all versions of jwebmp-bootstrap Show documentation
/*
* Copyright (C) 2017 Marc Magon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.jwebmp.plugins.bootstrap.navbar.toggler;
import com.jwebmp.core.base.html.Button;
import com.jwebmp.core.base.html.Div;
import com.jwebmp.core.base.html.Span;
import com.jwebmp.core.base.html.attributes.ButtonAttributes;
import com.jwebmp.core.base.html.attributes.GlobalAttributes;
import com.jwebmp.plugins.bootstrap.navbar.BSComponentNavBarOptions;
import com.jwebmp.plugins.bootstrap.navbar.BSNavBarChildren;
import com.jwebmp.plugins.bootstrap.navs.BSComponentNavsOptions;
import com.jwebmp.plugins.bootstrap.navs.BSNavs;
import java.util.Objects;
/**
* @author GedMarc
* @since 21 Jan 2017
*/
public class BSNavBarToggler
extends Button
implements BSNavBarChildren, IBSNavBarToggler
{
private static final long serialVersionUID = 1L;
/**
* The specified screen reader aria label to apply when creating the div
*/
private static String AriaLabel = "Toggle Navigation";
private String iconClass = BSComponentNavBarOptions.Navbar_Toggler_Icon.toString();
/**
* Creates 2 new accessible objects for the nav bar
*
* @param togglerAlignment
*/
public BSNavBarToggler(BSNavBarTogglerAlignments togglerAlignment)
{
addClass(BSComponentNavBarOptions.Navbar_Toggler);
addClass(togglerAlignment);
}
/**
* Gets the screen reader aria label
*
* @return
*/
public static String getAriaLabel()
{
return AriaLabel;
}
/**
* sets the screen reader aria label
*/
public static void setAriaLabel(String ariaLabel)
{
BSNavBarToggler.AriaLabel = ariaLabel;
}
/**
* Nav
*
* Navbar navigation links build on our .nav options with their own modifier class and require the use of toggler classes for proper responsive styling.
*
* Navigation in navbars will also grow to occupy as much horizontal space as possible to keep your navbar contents securely aligned.
*
* Active states—with .active—to indicate the current page can be applied directly to .nav-links or their immediate parent .nav-items.
*
* @param
* @param navs
*
* @return
*/
@Override
public T createCollapsingDiv(BSNavs navs)
{
navs.removeClass(BSComponentNavsOptions.Nav);
navs.addClass(BSComponentNavsOptions.Navbar_Nav);
BSNavBarTogglerDiv div = new BSNavBarTogglerDiv();
div.add(navs);
addAttribute(ButtonAttributes.Data_Toggle, "collapse");
addAttribute(ButtonAttributes.Data_Target, div.getID(true));
addAttribute(GlobalAttributes.Aria_Controls, div.getID());
addAttribute(GlobalAttributes.Aria_Expanded, "false");
addAttribute(GlobalAttributes.Aria_Label, AriaLabel);
addAttribute(GlobalAttributes.Type, "button");
return (T) div;
}
/**
* Gets the Icon Class
*
* @return
*/
@Override
public String getIconClass()
{
return iconClass;
}
/**
* Sets the Icon Class
*
* @param iconClass
*/
@Override
public void setIconClass(String iconClass)
{
this.iconClass = iconClass;
}
/**
* A neater view
*
* @return
*/
public IBSNavBarToggler asMe()
{
return this;
}
@Override
public void preConfigure()
{
if (!isConfigured())
{
Span iconSpan = new Span();
iconSpan.addClass(getIconClass());
add(iconSpan);
}
super.preConfigure();
}
@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (!(o instanceof BSNavBarToggler))
{
return false;
}
if (!super.equals(o))
{
return false;
}
BSNavBarToggler that = (BSNavBarToggler) o;
return Objects.equals(getIconClass(), that.getIconClass());
}
@Override
public int hashCode()
{
return Objects.hash(super.hashCode(), getIconClass());
}
}