aboutsummaryrefslogtreecommitdiff
path: root/js/bootstrap-tab.js
diff options
context:
space:
mode:
authorJacob Thornton <[email protected]>2011-11-27 17:04:55 -0800
committerJacob Thornton <[email protected]>2011-11-27 17:04:55 -0800
commit46fe38386afce7149810b1feb534726735ce28b2 (patch)
treec6a8b8e5c27a0aa30491f95505d7ed431845c5c7 /js/bootstrap-tab.js
parent3925ea9986e70f5a87883563c47c8ecd3d631c02 (diff)
downloadbootstrap-46fe38386afce7149810b1feb534726735ce28b2.tar.xz
bootstrap-46fe38386afce7149810b1feb534726735ce28b2.zip
rename tabs to tab - clean up lots of api stuff make href acceptable target val
Diffstat (limited to 'js/bootstrap-tab.js')
-rw-r--r--js/bootstrap-tab.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/js/bootstrap-tab.js b/js/bootstrap-tab.js
new file mode 100644
index 000000000..ba956cbe8
--- /dev/null
+++ b/js/bootstrap-tab.js
@@ -0,0 +1,102 @@
+/* ========================================================
+ * bootstrap-tabs.js v2.0.0
+ * http://twitter.github.com/bootstrap/javascript.html#tabs
+ * ========================================================
+ * Copyright 2011 Twitter, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ======================================================== */
+
+
+!function( $ ){
+
+ "use strict"
+
+ /* TAB CLASS DEFINITION
+ * ==================== */
+
+ var Tab = function ( element ) {
+ this.element = $(element)
+ }
+
+ Tab.prototype = {
+
+ show: function () {
+ var $this = this.element
+ , $ul = $this.closest('ul:not(.dropdown-menu)')
+ , href = $this.attr('data-target') || $this.attr('href')
+ , previous
+ , $href
+
+ if ( $this.parent('li').hasClass('active') ) return
+
+ previous = $ul.find('.active a').last()[0]
+
+ $this.trigger({
+ type: 'show'
+ , relatedTarget: previous
+ })
+
+ $href = $(href)
+
+ this.activate($this.parent('li'), $ul)
+ this.activate($href, $href.parent())
+
+ $this.trigger({
+ type: 'shown'
+ , relatedTarget: previous
+ })
+ }
+
+ , activate: function ( element, container ) {
+ container
+ .find('> .active')
+ .removeClass('active')
+ .find('> .dropdown-menu > .active')
+ .removeClass('active')
+
+ element.addClass('active')
+
+ if ( element.parent('.dropdown-menu') ) {
+ element.closest('li.dropdown').addClass('active')
+ }
+ }
+ }
+
+
+ /* TAB PLUGIN DEFINITION
+ * ===================== */
+
+ $.fn.tab = function (option) {
+ return this.each(function () {
+ var $this = $(this)
+ , data = $this.data('tab')
+ if (!data) $this.data('tab', (data = new Tab(this)))
+ if (typeof option == 'string') data[option]()
+ })
+ }
+
+ $.fn.tab.Tab = Tab
+
+
+ /* TAB DATA-API
+ * ============ */
+
+ $(document).ready(function () {
+ $('body').delegate('[data-toggle="tab"], [data-toggle="pill"]', 'click.tab.data-api', function (e) {
+ e.preventDefault()
+ $(this).tab('show')
+ })
+ })
+
+}( window.jQuery || window.ender ) \ No newline at end of file