github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jquery / jquery-ui

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 676
    • 128
  • Source
  • Commits
  • Network (128)
  • Graphs
  • Tree: f45e2b2

click here to add a description

click here to add a homepage

  • Switch Branches (7)
    • bind
    • devpreview
    • formcontrols
    • master
    • menu
    • panel
    • tooltip
  • Switch Tags (18)
    • 1.9m1
    • 1.8rc3
    • 1.8rc2
    • 1.8rc1
    • 1.8b1
    • 1.8a2
    • 1.8a1
    • 1.8.2
    • 1.8.1
    • 1.8
    • 1.7
    • 1.6rc6
    • 1.6rc5
    • 1.6rc3
    • 1.6rc2
    • 1.6
    • 1.5.2
    • 1.5.1
  • Comments
  • Contributors
Sending Request…

The official jQuery user interface library. — Read more

  Cancel

http://jqueryui.com/

  Cancel
  • HTTP
  • Git Read-Only

This URL has Read+Write access

demos/tabs: added new demo "Simple manipulation", shows simple tabs adding and 
removing
bganicky (author)
Sun Mar 01 09:05:44 -0800 2009
commit  f45e2b2da3467254c2a3
tree    5c8fae6019b78c6e56ad
parent  18171c2f89b87ac61383
M demos/tabs/index.html 5 •••••
A demos/tabs/manipulation.html 119 •••••
Txt demos/tabs/index.html
  • View file @ f45e2b2
... ...
@@ -12,8 +12,9 @@
12 12
     <li class="demo-config-on"><a href="default.html">Default functionality</a></li>
13 13
     <li><a href="ajax.html">Content via Ajax</a></li>
14 14
     <li><a href="mouseover.html">Open on mouseover</a></li>
15  
-    <li><a href="collapsible.html">Collapse content</a></li>    
16  
-    <li><a href="sortable.html">Sortable</a></li>    
  15
+    <li><a href="collapsible.html">Collapse content</a></li>
  16
+    <li><a href="sortable.html">Sortable</a></li>
  17
+    <li><a href="manipulation.html">Simple manipulation</a></li>
17 18
   </ul>
18 19
 </div>
19 20
 
Txt demos/tabs/manipulation.html
  • View file @ f45e2b2
... ...
@@ -0,0 +1,119 @@
  1
+<!doctype html>
  2
+<html lang="en">
  3
+<head>
  4
+  <title>jQuery UI Tabs - Simple manipulation</title>
  5
+  <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
  6
+  <script type="text/javascript" src="../../jquery-1.3.2.js"></script>
  7
+  <script type="text/javascript" src="../../ui/ui.core.js"></script>
  8
+  <script type="text/javascript" src="../../ui/ui.tabs.js"></script>
  9
+  <script type="text/javascript" src="../../ui/ui.dialog.js"></script>
  10
+  <link type="text/css" href="../demos.css" rel="stylesheet" />
  11
+  <style type="text/css">
  12
+    #dialog label, #dialog input { display:block; }
  13
+    #dialog label { margin-top: 0.5em; }
  14
+    #dialog input, #dialog textarea { width: 95%; }
  15
+    #tabs { margin-top: 1em; }
  16
+    #tabs li .ui-icon-close { float: left; margin: 0.4em 0.2em 0 0; cursor: pointer; }
  17
+    #add_tab { cursor: pointer; }
  18
+  </style>
  19
+  <script type="text/javascript">
  20
+  $(function() {
  21
+    var $tab_title_input = $('#tab_title'), $tab_content_input = $('#tab_content');
  22
+    var tab_counter = 2;
  23
+
  24
+    // tabs init with a custom tab template and an "add" callback filling in the content
  25
+    var $tabs = $('#tabs').tabs({
  26
+      tabTemplate: '<li><a href="#{href}">#{label}</a> <span class="ui-icon ui-icon-close">Remove Tab</span></li>',
  27
+      add: function(event, ui) {
  28
+        var tab_content = $tab_content_input.val() || 'Tab '+tab_counter+' content.';
  29
+        $(ui.panel).append('<p>'+tab_content+'</p>');
  30
+      }
  31
+    });
  32
+
  33
+    // modal dialog init: custom buttons and a "close" callback reseting the form inside
  34
+    var $dialog = $('#dialog').dialog({
  35
+      autoOpen: false,
  36
+      modal: true,
  37
+      buttons: {
  38
+        'Add': function() {
  39
+          addTab();
  40
+          $(this).dialog('close');
  41
+        },
  42
+        'Cancel': function() {
  43
+          $(this).dialog('close');
  44
+        }
  45
+      },
  46
+      open: function() {
  47
+        $tab_title_input.focus();
  48
+      },
  49
+      close: function() {
  50
+        $form[0].reset();
  51
+      }
  52
+    });
  53
+
  54
+    // addTab form: calls addTab function on submit and closes the dialog
  55
+    var $form = $('form',$dialog).submit(function() {
  56
+      addTab();
  57
+      $dialog.dialog('close');
  58
+      return false;
  59
+    });
  60
+
  61
+    // actual addTab function: adds new tab using the title input from the form above
  62
+    function addTab() {
  63
+      var tab_title = $tab_title_input.val() || 'Tab '+tab_counter;
  64
+      $tabs.tabs('add', '#tabs-'+tab_counter, tab_title);
  65
+      tab_counter++;
  66
+    }
  67
+
  68
+    // addTab button: just opens the dialog
  69
+    $('#add_tab').click(function() {
  70
+      $dialog.dialog('open');
  71
+    }).hover(function() {
  72
+      $(this).addClass("ui-state-hover");
  73
+    }, function() {
  74
+      $(this).removeClass("ui-state-hover");
  75
+    });
  76
+
  77
+    // close icon: removing the tab on click
  78
+    // note: closable tabs gonna be an option in the future - see http://dev.jqueryui.com/ticket/3924
  79
+    $('#tabs span.ui-icon-close').live('click', function() {
  80
+      var index = $('li',$tabs).index($(this).parent());
  81
+      $tabs.tabs('remove', index);
  82
+    });
  83
+  });
  84
+  </script>
  85
+</head>
  86
+<body>
  87
+
  88
+<div class="demo">
  89
+
  90
+  <div id="dialog" title="Tab data">
  91
+    <form>
  92
+      <fieldset class="ui-helper-reset">
  93
+        <label for="tab_title">Title</label>
  94
+        <input type="text" name="tab_title" id="tab_title" value="" class="ui-widget-content ui-corner-all" />
  95
+        <label for="tab_content">Content</label>
  96
+        <textarea name="tab_content" id="tab_content" class="ui-widget-content ui-corner-all"></textarea>
  97
+      </fieldset>
  98
+    </form>
  99
+  </div>
  100
+
  101
+  <button id="add_tab" class="ui-button ui-state-default ui-corner-all">Add Tab</button>
  102
+
  103
+  <div id="tabs">
  104
+    <ul>
  105
+      <li><a href="#tabs-1">Nunc tincidunt</a> <span class="ui-icon ui-icon-close">Remove Tab</span></li>
  106
+    </ul>
  107
+    <div id="tabs-1">
  108
+      <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>
  109
+    </div>
  110
+  </div>
  111
+
  112
+</div><!-- End demo -->
  113
+
  114
+<div class="demo-description">
  115
+  <p>Simple tabs adding and removing.</p>
  116
+</div><!-- End demo-description -->
  117
+
  118
+</body>
  119
+</html>

0 notes on commit f45e2b2

Please log in to comment.
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server