mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-22 05:03:16 +02:00
rename tabs to tab - clean up lots of api stuff make href acceptable target val
This commit is contained in:
@@ -67,14 +67,14 @@ All events should have an infinitive and past participle form. The infinitive is
|
||||
Data attributes should take the following form:
|
||||
|
||||
data-*(verb)* - defines main interaction
|
||||
data-target - defined on controller element (if element interacts with an element other than self)
|
||||
data-target || href^=# - defined on controller element (if element interacts with an element other than self)
|
||||
data-*(noun)* - defines options for element invocation
|
||||
|
||||
examples:
|
||||
|
||||
// control other targets
|
||||
data-toggle="modal" data-target="#foo"
|
||||
data-toggle="view" data-target="#foo"
|
||||
data-toggle="collapse" data-target="#foo" data-parent="#foo"
|
||||
|
||||
// defined on element they control
|
||||
data-spy="scroll"
|
||||
|
4
js/bootstrap-collapse.js
vendored
4
js/bootstrap-collapse.js
vendored
@@ -117,9 +117,9 @@
|
||||
$(function () {
|
||||
$('body').delegate('[data-toggle=collapse]', 'click.collapse.data-api', function ( e ) {
|
||||
var $this = $(this)
|
||||
, target = $this.attr('data-target')
|
||||
, target = $this.attr('data-target') || $this.attr('href')
|
||||
, option = $(target).data('collapse') ? 'toggle' : $this.data()
|
||||
e.preventDefault()
|
||||
e.preventDefault()
|
||||
$(target).collapse(option)
|
||||
})
|
||||
})
|
||||
|
2
js/bootstrap-modal.js
vendored
2
js/bootstrap-modal.js
vendored
@@ -192,7 +192,7 @@
|
||||
$(document).ready(function () {
|
||||
$('body').delegate('[data-toggle="modal"]', 'click.modal.data-api', function ( e ) {
|
||||
var $this = $(this)
|
||||
, target = $this.attr('data-target')
|
||||
, target = $this.attr('data-target') || $this.attr('href')
|
||||
, option = $(target).data('modal') ? 'toggle' : $this.data()
|
||||
e.preventDefault()
|
||||
$(target).modal(option)
|
||||
|
4
js/bootstrap-scrollspy.js
vendored
4
js/bootstrap-scrollspy.js
vendored
@@ -28,7 +28,9 @@
|
||||
var process = $.proxy(this.process, this)
|
||||
|
||||
this.$scrollElement = $(element).bind('scroll.scroll.data-api', process)
|
||||
this.selector = (this.$scrollElement.attr('data-target') || '') + ' .nav li > a'
|
||||
this.selector = (this.$scrollElement.attr('data-target')
|
||||
|| this.$scrollElement.attr('href')
|
||||
|| '') + ' .nav li > a'
|
||||
this.$body = $('body').delegate(this.selector, 'click.scroll.data-api', process)
|
||||
|
||||
this.refresh()
|
||||
|
102
js/bootstrap-tab.js
vendored
Normal file
102
js/bootstrap-tab.js
vendored
Normal file
@@ -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 )
|
80
js/bootstrap-tabs.js
vendored
80
js/bootstrap-tabs.js
vendored
@@ -1,80 +0,0 @@
|
||||
/* ========================================================
|
||||
* 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"
|
||||
|
||||
function activate ( 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')
|
||||
}
|
||||
}
|
||||
|
||||
function tab( e ) {
|
||||
var $this = $(this)
|
||||
, $ul = $this.closest('ul:not(.dropdown-menu)')
|
||||
, href = $this.attr('href')
|
||||
, previous
|
||||
, $href
|
||||
|
||||
if ( /^#\w+/.test(href) ) {
|
||||
e.preventDefault()
|
||||
|
||||
if ( $this.parent('li').hasClass('active') ) {
|
||||
return
|
||||
}
|
||||
|
||||
previous = $ul.find('.active a').last()[0]
|
||||
$href = $(href)
|
||||
|
||||
activate($this.parent('li'), $ul)
|
||||
activate($href, $href.parent())
|
||||
|
||||
$this.trigger({
|
||||
type: 'change'
|
||||
, relatedTarget: previous
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* TABS/PILLS PLUGIN DEFINITION
|
||||
* ============================ */
|
||||
|
||||
$.fn.tabs = $.fn.pills = function ( selector ) {
|
||||
return this.each(function () {
|
||||
$(this).delegate(selector || '.tabs li > a, .pills > li > a', 'click', tab)
|
||||
})
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$('body').tabs('ul[data-tabs] li > a, ul[data-pills] > li > a')
|
||||
})
|
||||
|
||||
}( window.jQuery || window.ender )
|
Reference in New Issue
Block a user