efcf011e88fc0f1f6554bfee90d017eae41d9d00
[myslice.git] / third-party / jquery-ui-1.10.2 / demos / tabs / manipulation.html
1 <!doctype html>
2 <html lang="en">
3 <head>
4         <meta charset="utf-8">
5         <title>jQuery UI Tabs - Simple manipulation</title>
6         <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
7         <script src="../../jquery-1.9.1.js"></script>
8         <script src="../../ui/jquery.ui.position.js"></script>
9         <script src="../../ui/jquery.ui.core.js"></script>
10         <script src="../../ui/jquery.ui.widget.js"></script>
11         <script src="../../ui/jquery.ui.button.js"></script>
12         <script src="../../ui/jquery.ui.tabs.js"></script>
13         <script src="../../ui/jquery.ui.dialog.js"></script>
14         <link rel="stylesheet" href="../demos.css">
15         <style>
16         #dialog label, #dialog input { display:block; }
17         #dialog label { margin-top: 0.5em; }
18         #dialog input, #dialog textarea { width: 95%; }
19         #tabs { margin-top: 1em; }
20         #tabs li .ui-icon-close { float: left; margin: 0.4em 0.2em 0 0; cursor: pointer; }
21         #add_tab { cursor: pointer; }
22         </style>
23         <script>
24         $(function() {
25                 var tabTitle = $( "#tab_title" ),
26                         tabContent = $( "#tab_content" ),
27                         tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close' role='presentation'>Remove Tab</span></li>",
28                         tabCounter = 2;
29
30                 var tabs = $( "#tabs" ).tabs();
31
32                 // modal dialog init: custom buttons and a "close" callback reseting the form inside
33                 var dialog = $( "#dialog" ).dialog({
34                         autoOpen: false,
35                         modal: true,
36                         buttons: {
37                                 Add: function() {
38                                         addTab();
39                                         $( this ).dialog( "close" );
40                                 },
41                                 Cancel: function() {
42                                         $( this ).dialog( "close" );
43                                 }
44                         },
45                         close: function() {
46                                 form[ 0 ].reset();
47                         }
48                 });
49
50                 // addTab form: calls addTab function on submit and closes the dialog
51                 var form = dialog.find( "form" ).submit(function( event ) {
52                         addTab();
53                         dialog.dialog( "close" );
54                         event.preventDefault();
55                 });
56
57                 // actual addTab function: adds new tab using the input from the form above
58                 function addTab() {
59                         var label = tabTitle.val() || "Tab " + tabCounter,
60                                 id = "tabs-" + tabCounter,
61                                 li = $( tabTemplate.replace( /#\{href\}/g, "#" + id ).replace( /#\{label\}/g, label ) ),
62                                 tabContentHtml = tabContent.val() || "Tab " + tabCounter + " content.";
63
64                         tabs.find( ".ui-tabs-nav" ).append( li );
65                         tabs.append( "<div id='" + id + "'><p>" + tabContentHtml + "</p></div>" );
66                         tabs.tabs( "refresh" );
67                         tabCounter++;
68                 }
69
70                 // addTab button: just opens the dialog
71                 $( "#add_tab" )
72                         .button()
73                         .click(function() {
74                                 dialog.dialog( "open" );
75                         });
76
77                 // close icon: removing the tab on click
78                 tabs.delegate( "span.ui-icon-close", "click", function() {
79                         var panelId = $( this ).closest( "li" ).remove().attr( "aria-controls" );
80                         $( "#" + panelId ).remove();
81                         tabs.tabs( "refresh" );
82                 });
83
84                 tabs.bind( "keyup", function( event ) {
85                         if ( event.altKey && event.keyCode === $.ui.keyCode.BACKSPACE ) {
86                                 var panelId = tabs.find( ".ui-tabs-active" ).remove().attr( "aria-controls" );
87                                 $( "#" + panelId ).remove();
88                                 tabs.tabs( "refresh" );
89                         }
90                 });
91         });
92         </script>
93 </head>
94 <body>
95
96 <div id="dialog" title="Tab data">
97         <form>
98                 <fieldset class="ui-helper-reset">
99                         <label for="tab_title">Title</label>
100                         <input type="text" name="tab_title" id="tab_title" value="" class="ui-widget-content ui-corner-all" />
101                         <label for="tab_content">Content</label>
102                         <textarea name="tab_content" id="tab_content" class="ui-widget-content ui-corner-all"></textarea>
103                 </fieldset>
104         </form>
105 </div>
106
107 <button id="add_tab">Add Tab</button>
108
109 <div id="tabs">
110         <ul>
111                 <li><a href="#tabs-1">Nunc tincidunt</a> <span class="ui-icon ui-icon-close" role="presentation">Remove Tab</span></li>
112         </ul>
113         <div id="tabs-1">
114                 <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
115         </div>
116 </div>
117
118 <div class="demo-description">
119 <p>Simple tabs adding and removing.</p>
120 </div>
121 </body>
122 </html>