npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ui-navbar

v0.5.2

Published

Angular responsive navigation with recursive menu and sub-menu construction

Downloads

17

Readme

ui-navbar - Responsive navigation bar with submenu in AngularJS

Bower NPM Build Status devDependency Status

Introduction

Build a responsive navigation menu bar with sub-menu in a recursive fashion using ui-router to load partials.

The directive can now be used in 3 different ways: buttons or icons, navbar with separated drop-down menu or single tree structure.

Plunkr live demo

  • version < 0.14.x Live demo at Plunkr
  • version > 2.2.0 Live demo at Plunkr

1. Installation

Via npm

npm install ui-navbar --save

or via Bower

bower install ui-navbar --save

2. Configure routing in your module adding required dependencies

angular.module('App', ['ui.bootstrap', 'ui.router', 'ui.navbar'])

    .config(function ($stateProvider, $urlRouterProvider) {

        // For any unmatched url, redirect to /state1
        $urlRouterProvider.otherwise("/home");

        // Now set up the states
        $stateProvider
            .state('home', {
                url: "/home",
                templateUrl: "home.html"
            })
            .state('metal-gear', {
                url: "/metal-gear",
                templateUrl: "metal-gear.html"
            })
            .state('metal-gear2', {
                url: "/metal-gear2",
                templateUrl: "metal-gear2.html"
            })
            .state('metal-gear-solid', {
                url: "/metal-gear-solid",
                templateUrl: "metal-gear-solid.html"
            });
    });

3. Configure the controller

angular.module('App').controller('NavigationController', function ($scope) {
    
    $scope.konami = [{
        name: "Konami",
        link: "#",
        subtree: [{
            name: "Metal Gear",
            link: "#",
            subtree: [{
                name: "Metal Gear",
                link: "metal-gear"
            }, {
                name: "Metal Gear 2: Solid Snake",
                link: "metal-gear2"
            }, {
                name: "Metal Gear Solid: The Twin Snakes",
                link: "metal-gear-solid"
            }]
        }]
    }];

    $scope.trees = [{
        name: "Konami",
        link: "#",
        subtree: [{
            name: "Metal Gear",
            link: "#",
            subtree: [{
                name: "Metal Gear",
                link: "metal-gear"
            }, {
                name: "Metal Gear 2: Solid Snake",
                link: "#"
            }, {
                name: "Metal Gear Solid: The Twin Snakes",
                link: "#"
            }]
        }, {
            name: "divider",
            link: "#"
        }, {
            name: "Castlevania",
            link: "#",
            subtree: [{
                ...
            }]
        }]
    }]
}

4. Html parts

Add ui-view to attach the partials.

<!-- Hook here the partials -->
<div ui-view=""></div>

Button

Add a multi-level menu to a drop down button rendering the previously introduced items:

<div btn-group="" uib-dropdown="">
    <button uib-dropdown-toggle="" type="button" class="btn btn-primary">
        Dropdown <b class="caret"></b>
    </button>
    <tree tree="konami"></tree>
</div>

Navigation bar with separated multi-level dropdown menu.

Specify an array of states for each menu item in the navigation bar:

<div ng-controller="NavigationController">
    <nav class="navbar navbar-default" role="navigation">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" ng-init="navCollapsed = true" ng-click="navCollapsed = !navCollapsed">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" ui-sref="home">Konami</a>
        </div>
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" ng-class="!navCollapsed && 'in'">
            <ul class="nav navbar-nav">
                <li uib-dropdown="">
                    <a href="#" uib-dropdown-toggle="">
                        Dropdown<b class="caret"></b>
                    </a>
                    <tree tree="konami"></tree>
                </li>
                <li uib-dropdown="">
                    <a href="#" uib-dropdown-toggle="">
                        Just a clone
                        <span class="caret"></span>
                    </a>
                    <tree tree="konami"></tree>
                </li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li uib-dropdown="">
                    <a href="#" uib-dropdown-toggle="">
                        Dropdown right<b class="caret"></b>
                    </a>
                    <tree tree="konami"></tree>
                </li>
                <li uib-dropdown="">
                    <a href="#" uib-dropdown-toggle="">
                        Just a clone right<span class="caret"></span>
                    </a>
                    <tree tree="konami"></tree>
                </li>
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </nav>
</div>

Navigation bar with a single tree structure

Specify an array representing the all tree, with all the states and subtree for of each state if required.

<div ng-controller="NavigationController">
    <nav class="navbar navbar-default" role="navigation">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" ng-init="navCollapsed = true" ng-click="navCollapsed = !navCollapsed">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">Games</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" ng-class="!navCollapsed && 'in'">
            <ul class="nav navbar-nav">
                <trees trees="allGames"></trees>
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </nav>
</div>

Features

  • Recursive item menu definition in json format.
  • Easy way to define a divider between items.
  • Unlimited level of nesting.
  • Responsive.
  • Fully compatible with AngularJS.
  • Standard Html5 with AngularJS Bootstrap attributes such as dropdown.
  • Support tag navbar-right from Bootstrap with submenu opening on the left.
  • No jquery required to manage responsivness and dropdown actions.

Dependencies

  • AngularJS, required 1.5.x, tested with 1.5.8.
  • UI Boostrap, required 1.1.1, tested with 2.2.0.
  • ui-router, required 0.2.15, tested with 0.3.1.
  • Twitter Bootstrap, required 3.3.6, tested with 3.3.7.

Update

  • Introduced the directive <trees> to specify the navigation bar in a all-in-one fashion.
  • Updated the documentation, demo and plunker.

Prefix

  • Prefixed angular-ui-bootstrap components in the index.html demo page according to the migration guide.

Demo

From the folder demo type

npm install
node server.js

then type in a browser http://localhost:5000 to get the demo page working.