javascript - Trouble Understanding jQuery-UI Popup Menu - Stack Overflow

I'm trying to figure out how to make a pop-up menu using the jQuery UI menu widget.After searching

I'm trying to figure out how to make a pop-up menu using the jQuery UI menu widget.

After searching around, I finally found the following demo that does what I want:

.html

However, I am having a little trouble understanding this demo. For example:

  1. What is making the menu hidden before any of the buttons are clicked?
  2. What is causing the menu to close when it's open and I click somewhere else on the page?

Any help appreciated.

I'm trying to figure out how to make a pop-up menu using the jQuery UI menu widget.

After searching around, I finally found the following demo that does what I want:

http://view.jqueryui./menubar/demos/popup/popup-menu.html

However, I am having a little trouble understanding this demo. For example:

  1. What is making the menu hidden before any of the buttons are clicked?
  2. What is causing the menu to close when it's open and I click somewhere else on the page?

Any help appreciated.

Share Improve this question asked Dec 4, 2012 at 4:25 Jonathan WoodJonathan Wood 67.5k82 gold badges304 silver badges532 bronze badges 5
  • What is making the menu hidden Well, of course it is the jQuery UI making it hidden. – Derek 朕會功夫 Commented Dec 4, 2012 at 4:31
  • Was this intended to be helpful? Which jQuery UI function hides it and where does it get called? – Jonathan Wood Commented Dec 4, 2012 at 4:35
  • Line 25: $("#button1").button().next().menu(... It makes #button1 a button, and make the next element the menu. – Derek 朕會功夫 Commented Dec 4, 2012 at 4:42
  • I can see it makes the button a trigger and the list the menu. But I don't see how that's related to what I asked. – Jonathan Wood Commented Dec 4, 2012 at 4:54
  • When you call .menu(), it triggers many things including hiding the menu and adding listeners, for example, it applies class names to the target element line [email protected] ...addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" ) – Derek 朕會功夫 Commented Dec 4, 2012 at 5:00
Add a ment  | 

3 Answers 3

Reset to default 2

That demo uses a modified version of jquery.ui.menu.js along with the popup widget: http://view.jqueryui./menubar/ui/jquery.ui.popup.js

Menu itself, as released in 1.9, doesn't have any code for showing it as a popup. I remend writing some custom code to build a popup menu, until a stable release offers a proper solution.

The jQuery UI Popup - Popup Menu you referenced uses unreleased code as Jörn Zaefferer said. (Notice that Jörn is the same guy that closed the bug)

But there is an almost identical-looking solution in jQuery UI Button's Split Button example that doesn't use .popup() and does all the hiding etc. explicitly.

Perhaps you could use that as a starting point instead. I know I'm going to! ;-)

I believe this may be what you're looking for. When you call .menu(), lots of things are triggered in the _create() function (as Derek said), like setting class names etc. Then, at lines 123-135 in jquery.ui.menu.js, this happens:

    this.refresh();

    // Clicks outside of a menu collapse any open menus
    this._on( this.document, {
        click: function( event ) {
            if ( !$( event.target ).closest( ".ui-menu" ).length ) {
                this.collapseAll( event );
            }

            // Reset the mouseHandled flag
            mouseHandled = false;
        }
    });

The second part makes sure all menus are collapsed when the user clicks on the page (this.document) outside a menu (.ui-menu): this.collapseAll() is called, which calls this._close(), which in turn calls hide(). This should answer your second question.

As for your first question, The first thing the refresh() function does is:

    // Initialize nested menus
    var menus,
        icon = this.options.icons.submenu,
        submenus = this.element.find( this.options.menus + ":not(.ui-menu)" )
            .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
            .hide()
            .attr({
                role: this.options.role,
                "aria-hidden": "true",
                "aria-expanded": "false"
            });

This finds all submenus not previously initialized (in this case all of them since we're ing from _create()) and initializes them, which includes hiding them.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744615317a4584014.html

相关推荐

  • javascript - Trouble Understanding jQuery-UI Popup Menu - Stack Overflow

    I'm trying to figure out how to make a pop-up menu using the jQuery UI menu widget.After searching

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>