For example, to play around with this widget, I added a context menu to each tab in a tabs widget, that allows the user to remove the tab.
And here is the context manu Javascript in action.
$(function() {
$( "#tabs" ).tabs();
$( ".ui-tabs" ).contextmenu({
// We're telling the context menu widget to display
// each time a tab is right clicked.
delegate: ".ui-tabs-anchor",
// The context menu widget takes care of assembling
// the interanl menu widget for us.
menu: [
{
title: "Close",
cmd: "close",
uiIcon: "ui-icon-close"
}
],
// Fires when a context menu item is selected.
select: function( event, ui ) {
// This is how we know which menu item was
// selected.
if ( ui.cmd !== "close" ) {
return;
}
// The ui object has our target tab anchor that
// was right-clicked. Now we can remove the
// tab, the panel, and refresh the tabs widget.
var $target = ui.target,
panel = $target.closest( "li" )
.remove()
.attr( "aria-controls" );
$( "#" + panel ).remove();
$( "#tabs" ).tabs( "refresh" );
}
});
});
No comments :
Post a Comment