1.0.2 • Published 5 years ago

@mantixd/easymenu v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

easyMenu

Bootstrap Navbar only with JQuery

Getting Started

This is a way to create a Navbar only using JQuery.

Prerequisites

  • JQuery
  • Bootstrap

Installing

First, you need to put the JQuery and the Bootstrap references on the head of your HTML.

Then you need to create a div tag, like this:

<div class="testNav"></div>

Then, create a javascript file, and reference it in your html head too, under the other references, and call your div with the easyMenu method.

$('.testNav').easyMenu();

This will show you a message on you page, like this:

This is your blank Navbar.

And maybe you said, thats all?, but this is only the beginning.

This plugin has a main object to configure all the Nav, this object has other objects inside to tell the Nav what to do.

This are all the objects inside the easyMenu method:

CommandDescription
optionsThis is the main object.
separatorIn this variable you specify the main character you will use to separate a text.
search_buttonIs a boolean variable that says if you going to add a search button on your Navbar or not.
logoThis is an object that specify the logo that you are going to use, this object contain two variables haslogo and src.
logo > haslogoThis variable is declared inside the logo object, is a boolean that specify if your Navbar is going to have a logo or not.
logo > srcThis variable is declared inside the logo object, is a string that contains the route of your logo.
tittleThis is an object that contains the tittle variables of your Navbar, this object contain two variables hastittle and .
tittle > hastittleThis is a variable inside the tittle object, is a boolean variable that specify if the Navbar is going to have tittle or not.
tittle > textThis is a variable inside the tittle object, is a string variable that specify the tittle text.
mainThis is an object that contains the name of the main elements on the menu, this object contains a string variable called .
main > textThis variable has the main elements on the menu, you need to put the elements separate by your , for example, if your separator is ; you need to put your elements like this Element1;Element2;Element3,Element4.
childsThis object contains the attributes of the elements on your Navbar.
childs > data_childsThis object contains the attributes of the elements on your Navbar, contains an object that have four variables, type, objetive, text and value .
childs > data_childs > navbar element nameThis object has the individually variables for each element.
childs > data_childs > navbar element name > typeThis variable is a string, that specify if the elemen is going to be a link or a dropdown.
childs > data_childs > navbar element name > objetiveThis variable is a string, that specify which element has this configuration.
childs > data_childs > navbar element name > textThis is a variable used only if the element type is a dropdown, this specify the child names of the element, you need to put the names separated by your separator.
childs > data_childs > navbar element name > valueThis specify the url of the element, in case that the element is a dropdown, you need to put the urls separated by your separator and need to match to the names specified.
styleThis is an object to apply styles to your Navbar.
style > iscustomThis variable specify if your style is custom or not, this value is a boolean.
style > themeIf the iscustom variable is false, you can choose a theme for your Navbar.
style > menuIf the iscustom variable is true, this object has the menu style options, that you can set to your main elements on the Navbar.
style > menu > background_colorThis variable sets a background color to your Navbar.
style > menu > textcolorThis variable sets a font color on your main Navbar elements.
style > menu > fontsizeThis variable sets a font size on your main Navbar elements.
style > menu > fontweightThis variable sets a font weight on your main Navbar elements.
style > submenuIf the iscustom variable is true, this object has the submenu style options, that you can set to your child elemnts on the Navbar
style > submenu > background_colorThis variable sets a background color to the child elements of your Navbar.
style > submenu > textcolorThis variable sets a font color on your child Navbar elements.
style > submenu > fontsizeThis variable sets a font size on your child Navbar elements.
style > submenu > fontweightThis variable sets a font weight on your child Navbar elements.
style > submenu > item_active_background_colorThis variable sets a background color to the child elements of your Navbar when this is focused.
style > tittle > background_colorThis variable sets a background color to the tittle of your Navbar.
style > tittle > textcolorThis variable sets a font color to your Navbar tittle.
style > tittle > fontsizeThis variable sets a font size to your Navbar tittle.
style > tittle > fontweightThis variable sets a font weight to your Navbar tittle.
style > searchIf the iscustom variable is true, this object has the search element style options.
style > search > btnThis element has the search button style options.
style > search > btn > background_colorThis variable sets a background color to the search button.
style > search > btn > textcolorThis variable sets a font color to your child search button.
style > search > btn > fontsizeThis variable sets a font size to your search button.
style > search > btn > fontweightThis variable sets a font weight to your search button.
style > search > btn > borderThis variable sets a border to your search button.
style > search > btn > border_radiusThis variable sets a border radius to your search button.
style > search > inputThis element has the search input style options.
style > search > input > background_colorThis variable sets a background color to the search input.
style > search > input > textcolorThis variable sets a font color to your child search input.
style > search > input > fontsizeThis variable sets a font size to your search input.
style > search > input > fontweightThis variable sets a font weight to your search input.
style > search > input > borderThis variable sets a border to your search input.
style > search > input > border_radiusThis variable sets a border radius to your search input.

Creating a standard navbar

This is the way to create a standard navbar with four elements, two dropdowns and two links, this navbar has a logo and a tittle:

$('.testNav').easyMenu({
    options: {
        separator: ";",
        search_button: true,
        logo: {
            haslogo: true,
            src: 'https://getbootstrap.com/docs/4.0/assets/brand/bootstrap-solid.svg'
        },
        tittle: {
            hastittle: true,
            text: "easyMenu"
        },
        main: {                                
            text: "Main1;Main2;Main3;Main4"
        },
        childs: {
            data_childs: {
                "Main1": {
                    type: "dropdown",
                    objetive:"Main1",
                    text: "Child1;Child2",
                    value: "http://child1.com/;http://child2.com/"
                },
                "Main2": {
                    type: "dropdown",
                    objetive:"Main2",
                    text: "Child3;Child4",
                    value: "http://child3.com/;http://child4.com/"
                },
                "Main3": {
                    type: "link",
                    objetive:"Main3",
                    value: "http://main5.com"
                },                                    
                "Main4": {
                    type: "link",
                    objetive:"Main4",
                    value: "http://main6.com"
                }
            }
        }
    }
});

Remember that the number of the main elements that you put on the main object has to be the same on the child object, also the same name and the same objetive, to make a reference from the main to the child.

Styling the navbar

This plugin has a style object, to apply themes to your navbar or if you want to customize your theme, you can do it too, like this:

$('.testNav').easyMenu({
    options: {
        separator: ";",
        search_button: true,
        logo: {
            haslogo: true,
            src: 'https://getbootstrap.com/docs/4.0/assets/brand/bootstrap-solid.svg'
        },
        tittle: {
            hastittle: true,
            text: "easyMenu"
        },
        main: {                                
            text: "Main1;Main2;Main3;Main4"
        },
        childs: {
            data_childs: {
                "Main1": {
                    type: "dropdown",
                    objetive:"Main1",
                    text: "Child1;Child2",
                    value: "http://child1.com/;http://child2.com/"
                },
                "Main2": {
                    type: "dropdown",
                    objetive:"Main2",
                    text: "Child3;Child4",
                    value: "http://child3.com/;http://child4.com/"
                },
                "Main3": {
                    type: "link",
                    objetive:"Main3",
                    value: "http://main5.com"
                },                                    
                "Main4": {
                    type: "link",
                    objetive:"Main4",
                    value: "http://main6.com"
                }
            }
        },
        style: {
            iscustom: false,
            theme: "dark"
        }
    }
});

With the style object you can set a theme for your navbar, there are three theme options(for now) that you can set, this are dark, blue and the default, this default theme will be set if you set the theme variable empty for example: theme: "", or simply if you don't create the style object.

Custom styling

This navbar has a custom styling, you only need to set the iscustom variable to true and then apply your configuration, for example:

$('.testNav').easyMenu({
    options: {
        separator: ";",
        search_button: true,
        logo: {
            haslogo: true,
            src: 'https://getbootstrap.com/docs/4.0/assets/brand/bootstrap-solid.svg'
        },
        tittle: {
            hastittle: true,
            text: "easyMenu"
        },
        main: {                                
            text: "Main1;Main2;Main3;Main4"
        },
        childs: {
            data_childs: {
                "Main1": {
                    type: "dropdown",
                    objetive:"Main1",
                    text: "Child1;Child2",
                    value: "http://child1.com/;http://child2.com/"
                },
                "Main2": {
                    type: "dropdown",
                    objetive:"Main2",
                    text: "Child3;Child4",
                    value: "http://child3.com/;http://child4.com/"
                },
                "Main3": {
                    type: "link",
                    objetive:"Main3",
                    value: "http://main5.com"
                },                                    
                "Main4": {
                    type: "link",
                    objetive:"Main4",
                    value: "http://main6.com"
                }
            }
        },
        style: {
          iscustom: true,
          menu: {                                    
              background_color: "#000000",
              textcolor: "#FFFFFF",
              fontsize: "16px",
              fontweight: "bold"
          },
          submenu: {
              background_color: "#000000",
              textcolor: "#007bff",
              fontsize: "18px",
              fontweight: "bold",
              item_active_background_color: "#000000"
          },
          tittle: {
              background_color: "#000000",
              textcolor: "red",
              fontsize: "18px",
              fontweight: "bold"
          },
          search: {
              btn: {
                  fontsize:"16px",
                  textcolor: "#007bff",
                  background_color: "#000000",
                  fontweight: "bold",
                  border: "1px solid #ced4da",
                  border_radius: ".25rem"                                  
              },
              input: {
                  fontsize:"16px",
                  textcolor: "#007bff",
                  background_color: "#000000",
                  fontweight: "bold",
                  border: "1px solid #ced4da",
                  border_radius: ".25rem"
              }
          }
       }
    }
});

You need to put the element styles individually, first the main elements, then the childs and then the tittle and the search element, remember that this configurations are optional, you can only set a configuration to your main elements and set the other elements by default, is your choice.

Deployment

This is a complete example of the navbar working, you only need to set the jquery and bootstrap cdn on your head, and then put the easyMenu.js.

<html>
    <head>
    <script src="components/jquery/jquery-3.4.1.min.js"></script>
    <link rel="stylesheet" href="components/bootstrap/css/bootstrap.min.css">
    <script src="components/bootstrap/js/bootstrap.min.js"></script>
    <script src="components/easymenu/easyMenu.min.js"></script>
    <script>
    $(document).ready(function() {
        $('.testNav').easyMenu({
            options: {
                separator: ";",
                search_button: true,
                logo: {
                    haslogo: true,
                    src: 'https://getbootstrap.com/docs/4.0/assets/brand/bootstrap-solid.svg'
                },
                tittle: {
                    hastittle: true,
                    text: "easyMenu"
                },
                main: {                                
                    text: "Main1;Main2;Main3;Main4"
                },
                childs: {
                    data_childs: {
                        "Main1": {
                            type: "dropdown",
                            objetive:"Main1",
                            text: "Child1;Child2",
                            value: "http://child1.com/;http://child2.com/"
                        },
                        "Main2": {
                            type: "dropdown",
                            objetive:"Main2",
                            text: "Child3;Child4",
                            value: "http://child3.com/;http://child4.com/"
                        },
                        "Main3": {
                            type: "link",
                            objetive:"Main3",
                            value: "http://main5.com"
                        },                                    
                        "Main4": {
                            type: "link",
                            objetive:"Main4",
                            value: "http://main6.com"
                        }
                    }
                },
                style: {
                iscustom: true,
                menu: {                                    
                    background_color: "#000000",
                    textcolor: "#FFFFFF",
                    fontsize: "16px",
                    fontweight: "bold"
                },
                submenu: {
                    background_color: "#000000",
                    textcolor: "#007bff",
                    fontsize: "18px",
                    fontweight: "bold",
                    item_active_background_color: "#000000"
                },
                tittle: {
                    background_color: "#000000",
                    textcolor: "red",
                    fontsize: "18px",
                    fontweight: "bold"
                },
                search: {
                    btn: {
                        fontsize:"16px",
                        textcolor: "#007bff",
                        background_color: "#000000",
                        fontweight: "bold",
                        border: "1px solid #ced4da",
                        border_radius: ".25rem"                                  
                    },
                    input: {
                        fontsize:"16px",
                        textcolor: "#007bff",
                        background_color: "#000000",
                        fontweight: "bold",
                        border: "1px solid #ced4da",
                        border_radius: ".25rem"
                    }
                }
            }
            }
        });
    });
    </script>
    </head>
    <body>
          <div class="testNav"></div>
    </body>
</html>

Built With

Contributing

If you detect any problem, please let me know, any comments will be welcome.

Versioning

See the tags on this repository.

Authors

  • Ricardo Pérez - Initial work - Mantixd

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Donation

If my work likes you or helps you a little, i will apreciate it your help with this project and others coming:

Paypal me