Subversion Repositories Sites.obs-saisons.fr

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
40 aurelien 1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
	<meta charset="UTF-8" />
5
	<title>jQuery UI Tabs - Simple manipulation</title>
6
	<link type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" />
7
	<script type="text/javascript" src="../../jquery-1.4.2.js"></script>
8
	<script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
9
	<script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
10
	<script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
11
	<script type="text/javascript" src="../../ui/jquery.ui.button.js"></script>
12
	<script type="text/javascript" src="../../ui/jquery.ui.tabs.js"></script>
13
	<script type="text/javascript" src="../../ui/jquery.ui.dialog.js"></script>
14
	<link type="text/css" href="../demos.css" rel="stylesheet" />
15
	<style type="text/css">
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 type="text/javascript">
24
	$(function() {
25
		var $tab_title_input = $('#tab_title'), $tab_content_input = $('#tab_content');
26
		var tab_counter = 2;
27
 
28
		// tabs init with a custom tab template and an "add" callback filling in the content
29
		var $tabs = $('#tabs').tabs({
30
			tabTemplate: '<li><a href="#{href}">#{label}</a> <span class="ui-icon ui-icon-close">Remove Tab</span></li>',
31
			add: function(event, ui) {
32
				var tab_content = $tab_content_input.val() || 'Tab '+tab_counter+' content.';
33
				$(ui.panel).append('<p>'+tab_content+'</p>');
34
			}
35
		});
36
 
37
		// modal dialog init: custom buttons and a "close" callback reseting the form inside
38
		var $dialog = $('#dialog').dialog({
39
			autoOpen: false,
40
			modal: true,
41
			buttons: {
42
				'Add': function() {
43
					addTab();
44
					$(this).dialog('close');
45
				},
46
				'Cancel': function() {
47
					$(this).dialog('close');
48
				}
49
			},
50
			open: function() {
51
				$tab_title_input.focus();
52
			},
53
			close: function() {
54
				$form[0].reset();
55
			}
56
		});
57
 
58
		// addTab form: calls addTab function on submit and closes the dialog
59
		var $form = $('form',$dialog).submit(function() {
60
			addTab();
61
			$dialog.dialog('close');
62
			return false;
63
		});
64
 
65
		// actual addTab function: adds new tab using the title input from the form above
66
		function addTab() {
67
			var tab_title = $tab_title_input.val() || 'Tab '+tab_counter;
68
			$tabs.tabs('add', '#tabs-'+tab_counter, tab_title);
69
			tab_counter++;
70
		}
71
 
72
		// addTab button: just opens the dialog
73
		$('#add_tab')
74
			.button()
75
			.click(function() {
76
				$dialog.dialog('open');
77
			});
78
 
79
		// close icon: removing the tab on click
80
		// note: closable tabs gonna be an option in the future - see http://dev.jqueryui.com/ticket/3924
81
		$('#tabs span.ui-icon-close').live('click', function() {
82
			var index = $('li',$tabs).index($(this).parent());
83
			$tabs.tabs('remove', index);
84
		});
85
	});
86
	</script>
87
</head>
88
<body>
89
 
90
<div class="demo">
91
 
92
	<div id="dialog" title="Tab data">
93
		<form>
94
			<fieldset class="ui-helper-reset">
95
				<label for="tab_title">Title</label>
96
				<input type="text" name="tab_title" id="tab_title" value="" class="ui-widget-content ui-corner-all" />
97
				<label for="tab_content">Content</label>
98
				<textarea name="tab_content" id="tab_content" class="ui-widget-content ui-corner-all"></textarea>
99
			</fieldset>
100
		</form>
101
	</div>
102
 
103
	<button id="add_tab">Add Tab</button>
104
 
105
	<div id="tabs">
106
		<ul>
107
			<li><a href="#tabs-1">Nunc tincidunt</a> <span class="ui-icon ui-icon-close">Remove Tab</span></li>
108
		</ul>
109
		<div id="tabs-1">
110
			<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>
111
		</div>
112
	</div>
113
 
114
</div><!-- End demo -->
115
 
116
<div class="demo-description">
117
	<p>Simple tabs adding and removing.</p>
118
</div><!-- End demo-description -->
119
 
120
</body>
121
</html>