1 | <!DOCTYPE html> |
---|
2 | <html lang="en"> |
---|
3 | <head> |
---|
4 | <title>Tabs - Add/Remove</title> |
---|
5 | <meta charset="utf-8" /> |
---|
6 | <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> |
---|
7 | <meta name="description" content="Add or remove tabs by code." /> |
---|
8 | <meta name="keywords" content="" /> |
---|
9 | <meta name="author" content="ComponentOne" /> |
---|
10 | <link href="../../themes/rocket/jquery-wijmo.css" rel="stylesheet" type="text/css" /> |
---|
11 | <script src="../../external/jquery-1.8.0.min.js" type="text/javascript"></script> |
---|
12 | <script src="../../external/jquery-ui-1.8.23.custom.min.js" type="text/javascript"></script> |
---|
13 | <link href="../../themes/wijmo/jquery.wijmo.wijdialog.css" rel="stylesheet" type="text/css" /> |
---|
14 | <link href="../../themes/wijmo/jquery.wijmo.wijtabs.css" rel="stylesheet" type="text/css" /> |
---|
15 | <script src="../../wijmo/jquery.wijmo.wijdialog.js" type="text/javascript"></script> |
---|
16 | <script src="../../wijmo/jquery.wijmo.wijtabs.js" type="text/javascript"></script> |
---|
17 | <script type="text/javascript"> |
---|
18 | $(function () { |
---|
19 | $("#tabs").wijtabs({ scrollable: true }); |
---|
20 | }); |
---|
21 | |
---|
22 | $(function () { |
---|
23 | var $tab_title_input = $('#tab_title'), $tab_content_input = $('#tab_content'); |
---|
24 | var tab_counter = 2; |
---|
25 | |
---|
26 | // tabs init with a custom tab template and an "add" callback filling in the content |
---|
27 | var $tabs = $('#tabs').wijtabs({ |
---|
28 | tabTemplate: '<li><a href="#{href}">#{label}</a> <span class="ui-icon ui-icon-close">Remove Tab</span></li>', |
---|
29 | add: function (event, ui) { |
---|
30 | var tab_content = $tab_content_input.val() || 'Tab ' + tab_counter + ' content.'; |
---|
31 | $(ui.panel).append('<p>' + tab_content + '</p>'); |
---|
32 | } |
---|
33 | }); |
---|
34 | |
---|
35 | // modal dialog init: custom buttons and a "close" callback reseting the form inside |
---|
36 | var $dialog = $('#dialog').wijdialog({ |
---|
37 | showStatus: false, |
---|
38 | showControlBox: false, |
---|
39 | autoOpen: false, |
---|
40 | modal: true, |
---|
41 | buttons: { |
---|
42 | 'Add': function () { |
---|
43 | addTab(); |
---|
44 | $(this).wijdialog('close'); |
---|
45 | }, |
---|
46 | 'Cancel': function () { |
---|
47 | $(this).wijdialog('close'); |
---|
48 | } |
---|
49 | }, |
---|
50 | open: function () { |
---|
51 | $tab_title_input.focus(); |
---|
52 | }, |
---|
53 | close: function () { |
---|
54 | $form.find('input').val("").end() |
---|
55 | .find('textarea').val(""); |
---|
56 | } |
---|
57 | }); |
---|
58 | |
---|
59 | // addTab form: calls addTab function on submit and closes the dialog |
---|
60 | var $form = $('fieldset', $dialog).submit(function () { |
---|
61 | addTab(); |
---|
62 | $dialog.wijdialog('close'); |
---|
63 | return false; |
---|
64 | }); |
---|
65 | |
---|
66 | // actual addTab function: adds new tab using the title input from the form above |
---|
67 | function addTab() { |
---|
68 | var tab_title = $tab_title_input.val() || 'Tab ' + tab_counter; |
---|
69 | $tabs.wijtabs('add', '#tabs-' + tab_counter, tab_title); |
---|
70 | tab_counter++; |
---|
71 | } |
---|
72 | |
---|
73 | // addTab button: just opens the dialog |
---|
74 | $('#add_tab') |
---|
75 | .button() |
---|
76 | .click(function () { |
---|
77 | $dialog.wijdialog('open'); |
---|
78 | }); |
---|
79 | |
---|
80 | // close icon: removing the tab on click |
---|
81 | // note: closable tabs gonna be an option in the future - see http://dev.jqueryui.com/ticket/3924 |
---|
82 | $('#tabs span.ui-icon-close').live('click', function () { |
---|
83 | var index = $('li', $tabs).index($(this).parent()); |
---|
84 | $tabs.wijtabs('remove', index); |
---|
85 | }); |
---|
86 | }); |
---|
87 | |
---|
88 | </script> |
---|
89 | <style type="text/css"> |
---|
90 | #dialog label, #dialog input |
---|
91 | { |
---|
92 | display: block; |
---|
93 | } |
---|
94 | #dialog label |
---|
95 | { |
---|
96 | margin-top: 0.5em; |
---|
97 | } |
---|
98 | #dialog input, #dialog textarea |
---|
99 | { |
---|
100 | width: 95%; |
---|
101 | } |
---|
102 | #tabs |
---|
103 | { |
---|
104 | margin-top: 1em; |
---|
105 | } |
---|
106 | #tabs li .ui-icon-close |
---|
107 | { |
---|
108 | float: left; |
---|
109 | margin: 0.4em 0.2em 0 0; |
---|
110 | cursor: pointer; |
---|
111 | } |
---|
112 | #add_tab |
---|
113 | { |
---|
114 | cursor: pointer; |
---|
115 | } |
---|
116 | </style> |
---|
117 | </head> |
---|
118 | <body class="demo-single"> |
---|
119 | <div class="container"> |
---|
120 | <div class="header"> |
---|
121 | <h2> |
---|
122 | Add/Remove</h2> |
---|
123 | </div> |
---|
124 | <div class="main demo"> |
---|
125 | <!-- Begin demo markup --> |
---|
126 | <div id="tabs"> |
---|
127 | <ul> |
---|
128 | <li><a href="#tabs-1">Nunc tincidunt</a> <span class="ui-icon ui-icon-close">Remove |
---|
129 | Tab</span></li> |
---|
130 | </ul> |
---|
131 | <div id="tabs-1"> |
---|
132 | <p> |
---|
133 | Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec |
---|
134 | arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. |
---|
135 | Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper |
---|
136 | leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales |
---|
137 | tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel |
---|
138 | pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. |
---|
139 | Nunc tristique tempus lectus.</p> |
---|
140 | </div> |
---|
141 | </div> |
---|
142 | <!-- End demo markup --> |
---|
143 | <div class="demo-options"> |
---|
144 | <!-- Begin options markup --> |
---|
145 | <div id="dialog" title="Add tab"> |
---|
146 | <fieldset class="ui-helper-reset"> |
---|
147 | <label for="tab_title"> |
---|
148 | Title</label> |
---|
149 | <input type="text" name="tab_title" id="tab_title" value="" class="ui-widget-content ui-corner-all" /> |
---|
150 | <label for="tab_content"> |
---|
151 | Content</label> |
---|
152 | <textarea name="tab_content" id="tab_content" class="ui-widget-content ui-corner-all" |
---|
153 | cols="" rows=""></textarea> |
---|
154 | </fieldset> |
---|
155 | </div> |
---|
156 | <input id="add_tab" type="button" value="Add Tab" /> |
---|
157 | <!-- End options markup --> |
---|
158 | </div> |
---|
159 | </div> |
---|
160 | <div class="footer demo-description"> |
---|
161 | <p> |
---|
162 | This sample illustrates how to dynamically add tabs using the addTab function. In |
---|
163 | addition, the sample includes a function that will allow each tab to close by clicking |
---|
164 | on an 'x' on the tabs. |
---|
165 | </p> |
---|
166 | </div> |
---|
167 | </div> |
---|
168 | </body> |
---|
169 | </html> |
---|