I'm trying to implement the simple manipulation functionality from jQuery UI Tabs.
But instead of having the code outside the widget, I want to have it inside the widget itself.
The "add new tab" is working properly, but I'm having trouble with the click on the close icon inside the tab. I'm not sure how to handle that event using the widget factory.
This is what I've done so far:
JS:
$.widget("ui.tabs", $.ui.tabs,
{
_create: function(event, ui)
{
this._super();
this._on($("span.ui-icon-close"), {
click: function()
{
var panelId = $( this ).closest( "li" ).remove().attr( "aria-controls" );
$( "#" + panelId ).remove();
this.refresh();
}});
},
addTab: function(text, id)
{
var tab = "<li><a href='#" + id + "'>" + text + "</a><span class='ui-icon ui-icon-close' role='presentation'>Remove Tab</span></li>";
var panel = "<div id='" + id + "'>This is new content! </div>";
this.tabs.parent().append(tab);
this.panels.parent().append(panel);
this.refresh();
},
});
$( "#tabs" ).tabs();
$("#tabs").tabs("addTab", "New Tab", 3);
$("#tabs").tabs("addTab", "Other Tab", 15);
FIDDLE: https://jsfiddle.net/drpcgx0f/2/
If all you need is an actual click event where you can perform your magic, then this can be done by changing this line:
to this: