source: ether_statistics/web/resources/js/library/jquery-ui-1.9.0.custom/development-bundle/demos/tabs/manipulation.html @ 653

Last change on this file since 653 was 653, checked in by vmipsl, 12 years ago

jquery

File size: 3.8 KB
Line 
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.8.2.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'>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 span.ui-icon-close" ).live( "click", function() {
79                        var panelId = $( this ).closest( "li" ).remove().attr( "aria-controls" );
80                        $( "#" + panelId ).remove();
81                        tabs.tabs( "refresh" );
82                });
83        });
84        </script>
85</head>
86<body>
87
88<div id="dialog" title="Tab data">
89        <form>
90                <fieldset class="ui-helper-reset">
91                        <label for="tab_title">Title</label>
92                        <input type="text" name="tab_title" id="tab_title" value="" class="ui-widget-content ui-corner-all" />
93                        <label for="tab_content">Content</label>
94                        <textarea name="tab_content" id="tab_content" class="ui-widget-content ui-corner-all"></textarea>
95                </fieldset>
96        </form>
97</div>
98
99<button id="add_tab">Add Tab</button>
100
101<div id="tabs">
102        <ul>
103                <li><a href="#tabs-1">Nunc tincidunt</a> <span class="ui-icon ui-icon-close">Remove Tab</span></li>
104        </ul>
105        <div id="tabs-1">
106                <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>
107        </div>
108</div>
109
110<div class="demo-description">
111<p>Simple tabs adding and removing.</p>
112</div>
113</body>
114</html>
Note: See TracBrowser for help on using the repository browser.