Skip to content

sj-js/menuman

Repository files navigation

MenuMan

📃

Build Status Coverage Status All Download Release License

1. Getting Started

  1. Load

    • Browser
      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@sj-js/menuman/dist/css/menuman.min.css">
      <script src="https://cdn.jsdelivr.net/npm/@sj-js/crossman/dist/js/crossman.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/@sj-js/menuman/dist/js/menuman.min.js"></script>
      <script>
           var menuman = new MenuMan();
      </script>
    • ES6+
      npm install @sj-js/menuman
      require('@sj-js/menuman/dist/css/menuman.css');
      const MenuMan = require('@sj-js/menuman');
      const menuman = new MenuMan();
  2. .setTheme(CODE)

    menuman.setTheme('default');
  3. .addMenu(ID, LABEL, EVENT)

    menuman.addMenu();
    menuman.addMenu('MENU_ID_1', 'MENU_LABEL', function(element){
        //SOMETHING TO DO
    });
    menuman.addMenu('MENU_ID_2', 'MENU_LABEL', function(element){
       //SOMETHING TO DO 
    });
  4. .addMenuBoard(ID, CONDITION, MENU_ID_LIST)

    menuman.addMenuBoard('BOARD_ID_1', {'id':'icon-*'}, ['MENU_ID_1', 'MENU_ID_2']);
  5. Simple Example

    <!DOCTYPE html>
    <HTML>
        <head>
            <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@sj-js/menuman/dist/css/menuman.min.css">
            <script src="https://cdn.jsdelivr.net/npm/@sj-js/crossman/dist/js/crossman.min.js"></script>
            <script src="https://cdn.jsdelivr.net/npm/@sj-js/menuman/dist/js/menuman.min.js"></script>
            <script>
                var menuman = new MenuMan();
            </script>
        </head>
        <style>
            .test-style { 
                display:inline-block; min-width:50px; height:30px; border:2px solid black; cursor:pointer; background:pink;
                -moz-user-select: none; -webkit-user-select: none; -ms-user-select:none; user-select:none;-o-user-select:none; 
            }
        </style>
    
        <body>
            <div class="test-style icon">Right Click - 1</div>
            <div class="test-style icon">Right Click - 2</div>
            <div id="test001" class="test-style">Right Click - 3</div>
            <div id="test002" class="test-style">Right Click - 4</div>
        </body>
    
        <script>
            menuman.setTheme('test-1');
            menuman.addMenu('menu-console', 'Console', function(element){
                console.log('Hello  ' + element.innerHTML);
            });
            menuman.addMenu('menu-alert', 'Alert', function(element){
                alert('Hello  ' + element.innerHTML);
            });
            menuman.addMenu('menu-nothing', 'Nothing', function(element){
                //None
            });
            menuman.addMenu('menu-1', 'Print', function(element){
                console.log('Print', element);
            });
            menuman.addMenuBoard('board-a', [{'class':'*icon*'}], ['menu-console', 'menu-alert']);
            menuman.addMenuBoard('board-b', [{'id':'test001'}], ['menu-nothing']);
            menuman.addMenuBoard('board-c', [{'id':'*02'}], ['menu-1']);
        </script>
    </HTML>