Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a jQueryUI 1.8 Button menu

Now that jQueryUI 1.8 is out, I was browsing through the updates and came across the new Button widget, and in particular one of the demos with the SplitButton with a dropdown. This demo seems to suggest that the Button widget could be used to create a dropdown menu here.

As a matter of discussion, I was wondering what ways there are to go about creating a dropdown menu with this new Button widget.

Cheers.

like image 240
Brian M. Hunt Avatar asked Apr 14 '10 21:04

Brian M. Hunt


2 Answers

You would have to drop a list below the button, in a manner similar to the demo provided here for autocomplete: http://jqueryui.com/demos/autocomplete/.

Essentially, you would replace the code in the button demo that displays the alert "could display a menu with a selected action" with code that does just that. This code can fire off one of the many jQuery Menu plugins out there, like this one.

<div class="demo">

    <div>
        <button id="rerun">Run last action</button>
        <button id="select">Select an action</button>
    </div>

</div>

<script type="text/javascript">
$(function() {
    $("#rerun").button().click(function() {
        alert("Running the last action");
    })
    .next()
    .button({
        text: false,
        icons: {
            primary: "ui-icon-triangle-1-s"
        }
    })
    .click(function() {
        // Code to display menu goes here. <<<<<<<<<<<<
    })
    .parent()
    .buttonset();
});
like image 110
Robert Harvey Avatar answered Sep 28 '22 09:09

Robert Harvey


You could also tell it to create the menu using the built-in button events:

//...
<script type="text/javascript">
$(document).ready(function(){  
    $("#yourButtonsID").click(function(){  
       $("#yourDropDown").show();    
    });
});  
</script>  
</head>  

<body>  
<button id="leftButtonSection">Do Something</button>  
<button id="yourButtonsID">Open Menu</button>  
<div id="yourDropDown">  
    <ul>  
      <li>Option One</li>  
      <li>Option Two</li>    
    </ul>
</div>
</body>  
like image 20
Trafalmadorian Avatar answered Sep 28 '22 08:09

Trafalmadorian