Skip to content

Commit ffc9832

Browse files
committed
Tabs: Cleaned up manipulation demo.
1 parent a02e393 commit ffc9832

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

demos/tabs/manipulation.html

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@
2222
</style>
2323
<script>
2424
$(function() {
25-
var tab_title_input = $( "#tab_title"),
26-
tab_content_input = $( "#tab_content" ),
25+
var tabTitle = $( "#tab_title" ),
26+
tabContent = $( "#tab_content" ),
2727
tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>",
28-
tab_counter = 2;
28+
tabCounter = 2;
2929

30-
// tabs init with a custom tab template and an "add" callback filling in the content
31-
var tabs = $( "#tabs").tabs({
32-
add: function( event, ui ) {
33-
var tab_content = tab_content_input.val() || "Tab " + tab_counter + " content.";
34-
$( ui.panel ).append( "<p>" + tab_content + "</p>" );
35-
}
36-
});
30+
var tabs = $( "#tabs" ).tabs();
3731

3832
// modal dialog init: custom buttons and a "close" callback reseting the form inside
3933
var dialog = $( "#dialog" ).dialog({
@@ -48,32 +42,29 @@
4842
$( this ).dialog( "close" );
4943
}
5044
},
51-
open: function() {
52-
tab_title_input.focus();
53-
},
5445
close: function() {
5546
form[ 0 ].reset();
5647
}
5748
});
5849

5950
// addTab form: calls addTab function on submit and closes the dialog
60-
var form = $( "form", dialog ).submit(function() {
51+
var form = dialog.find( "form" ).submit(function( event ) {
6152
addTab();
6253
dialog.dialog( "close" );
63-
return false;
54+
event.preventDefault();
6455
});
6556

66-
// actual addTab function: adds new tab using the title input from the form above
57+
// actual addTab function: adds new tab using the input from the form above
6758
function addTab() {
68-
var label = tab_title_input.val() || "Tab " + tab_counter,
69-
id = "tabs-" + tab_counter,
59+
var label = tabTitle.val() || "Tab " + tabCounter,
60+
id = "tabs-" + tabCounter,
7061
li = $( tabTemplate.replace( /#\{href\}/g, "#" + id ).replace( /#\{label\}/g, label ) ),
71-
tab_content = tab_content_input.val() || "Tab " + tab_counter + " content.";
62+
tabContentHtml = tabContent.val() || "Tab " + tabCounter + " content.";
7263

73-
tabs.find('ul').append( li );
74-
tabs.append( "<div id='" + id + "'><p>" + tab_content + "</p></div>" );
64+
tabs.find( ".ui-tabs-nav" ).append( li );
65+
tabs.append( "<div id='" + id + "'><p>" + tabContentHtml + "</p></div>" );
7566
tabs.tabs( "refresh" );
76-
tab_counter++;
67+
tabCounter++;
7768
}
7869

7970
// addTab button: just opens the dialog
@@ -84,7 +75,6 @@
8475
});
8576

8677
// close icon: removing the tab on click
87-
// note: closable tabs gonna be an option in the future - see http://dev.jqueryui.com/ticket/3924
8878
$( "#tabs span.ui-icon-close" ).live( "click", function() {
8979
$( this ).closest( "li" ).remove();
9080
$( "#" + $( this ).prev().attr( "aria-controls" ) ).remove();

0 commit comments

Comments
 (0)