Results 1 to 2 of 2

Thread: Programmaticly expand a menu

  1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    90

    Default Programmaticly expand a menu

    Hi,

    I have been trying to write some javascript to expand a menu and select based on an menu item. I have tried several things, most seem to almost work.

    Sorry for the code quality, it started very clean but many iterations has added complexity. The goal is to have a reference to any menu item and fully expand the menu from the toolbar -> sub menus -> to the items parent menu and then select the menu item.

    Code:
    function getMenuParent(root){
        var parentItem = null;
    
        function findParent(cmp) {
            if (cmp.isMenuItem) {
                var parentMenu = cmp.parentMenu;
                var parentMenuItem = parentMenu.parentItem || parentMenu.ownerItem;        
    
                if (!parentMenuItem) {
                    parentItem = parentMenu.up();
                } else {
                    findParent(parentMenuItem);
                }
            }
        }
    
        findParent(root);
        return parentItem;
    }    
    
    function expandMenu(rootMenuButton, stopAt) {
        function _doExpand(menu){
            Ext.each(menu.items.items, function(item){
                if (item == stopAt) {
                    menu.setActiveItem(item);
                    return false;
                }
    
                if (item.menu) {
                    menu.setActiveItem(item);
                    item.expandMenu();
                    item.menu.on('show', function() {
                        _doExpand(item.menu);
                    }, this, {'single': true});
    
                }
            });
        }
        rootMenuButton.showMenu();
        _doExpand(rootMenuButton.menu);
    }        
    
    function openMenu(root){
        var actions = [];
        var parentItem = null;
    
        var rootAction = null;
    
        function getActions(cmp) {
            if (cmp.isMenuItem) {
                var parentMenu = cmp.parentMenu;
                var parentMenuItem = parentMenu.parentItem || parentMenu.ownerItem;         
    
                if (!parentMenuItem) {
                    parentItem = parentMenu.up();
                    rootAction = function () {
                        parentMenu.up().menu.on('show', function() {
                            if (actions.length > 0) {
                                console.log(['FIRING SHOW FOR PARENT MENU', actions]);
                                var nextAction = actions.pop()
                                nextAction();
                            }
                        }, this, {'single': true});
                        parentMenu.up().el.dom.click();
                    }
                } else {
                    actions.push(function() {
                        parentMenuItem.menu.on('show', function() {
                            if (actions.length > 0) {
                                console.log(['FIRING SHOW FOR SUB MENU', actions]);
                                var nextAction = actions.pop()
                                nextAction();
                            }
                        }, this, {'single': true});
                        parentMenu.setActiveItem(parentMenuItem);
                        parentMenuItem.expandMenu();                    
                    });
                    getActions(parentMenuItem);
                }
            }
        }
    
        getActions(root);
        return rootAction
    }
    

  2. #2
    Sencha User
    Join Date
    Jul 2012
    Posts
    236
    Answers
    45

    Default

    A little hacky but doable:

    https://fiddle.sencha.com/#fiddle/1fcq

Similar Threads

  1. [FIXED] Button Menu: First menu item does not expand sub menu
    By lmastrodicasa in forum Ext 5: Bugs
    Replies: 1
    Last Post: 26 Nov 2014, 9:52 AM
  2. Replies: 9
    Last Post: 25 Jan 2013, 10:16 AM
  3. Replies: 1
    Last Post: 8 Aug 2012, 8:08 AM
  4. Add circles to line chart programmaticly
    By taberg in forum Ext: Q&A
    Replies: 4
    Last Post: 11 Mar 2012, 2:44 PM
  5. How to open the iPad keyboard programmaticly
    By bgauthier in forum Sencha Touch 1.x: Discussion
    Replies: 8
    Last Post: 9 Apr 2011, 3:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •