1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00
This commit is contained in:
fat 2015-05-13 13:43:56 -07:00
parent 7ef0e52fd0
commit b0d142334f
7 changed files with 95 additions and 14 deletions

5
js/dist/modal.js vendored
View file

@ -31,6 +31,7 @@ var Modal = (function ($) {
var Default = {
backdrop: true,
keyboard: true,
focus: true,
show: true
};
@ -206,14 +207,14 @@ var Modal = (function ($) {
$(this._element).addClass(ClassName.IN);
this._enforceFocus();
if (this._config.focus) this._enforceFocus();
var shownEvent = $.Event(Event.SHOWN, {
relatedTarget: relatedTarget
});
var transitionComplete = function transitionComplete() {
_this2._element.focus();
if (_this2._config.focus) _this2._element.focus();
$(_this2._element).trigger(shownEvent);
};

File diff suppressed because one or more lines are too long

28
js/dist/scrollspy.js vendored
View file

@ -28,7 +28,8 @@ var ScrollSpy = (function ($) {
var Default = {
offset: 10,
method: 'auto'
method: 'auto',
target: ''
};
var Event = {
@ -45,8 +46,9 @@ var ScrollSpy = (function ($) {
var Selector = {
DATA_SPY: '[data-spy="scroll"]',
ACTIVE: '.active',
LI: 'li',
LI_DROPDOWN: 'li.dropdown',
LI: 'li'
NAV_ANCHORS: '.nav li > a'
};
var OffsetMethod = {
@ -66,8 +68,8 @@ var ScrollSpy = (function ($) {
this._element = element;
this._scrollElement = element.tagName === 'BODY' ? window : element;
this._config = $.extend({}, Default, config);
this._selector = '' + (this._config.target || '') + ' .nav li > a';
this._config = this._getConfig(config);
this._selector = '' + this._config.target + ' ' + Selector.NAV_ANCHORS;
this._offsets = [];
this._targets = [];
this._activeTarget = null;
@ -137,10 +139,26 @@ var ScrollSpy = (function ($) {
this._scrollHeight = null;
}
}, {
key: '_getScrollTop',
key: '_getConfig',
// private
value: function _getConfig(config) {
config = $.extend({}, Default, config);
if (typeof config.target !== 'string') {
var id = $(config.target).attr('id');
if (!id) {
id = Util.getUID(NAME);
$(config.target).attr('id', id);
}
config.target = '#' + id;
}
return config;
}
}, {
key: '_getScrollTop',
value: function _getScrollTop() {
return this._scrollElement === window ? this._scrollElement.scrollY : this._scrollElement.scrollTop;
}

File diff suppressed because one or more lines are too long

View file

@ -217,7 +217,7 @@ const Modal = (($) => {
$(this._element).addClass(ClassName.IN)
this._enforceFocus()
if (this._config.focus) this._enforceFocus()
let shownEvent = $.Event(Event.SHOWN, {
relatedTarget: relatedTarget

View file

@ -26,7 +26,8 @@ const ScrollSpy = (($) => {
const Default = {
offset : 10,
method : 'auto'
method : 'auto',
target : ''
}
const Event = {
@ -43,8 +44,9 @@ const ScrollSpy = (($) => {
const Selector = {
DATA_SPY : '[data-spy="scroll"]',
ACTIVE : '.active',
LI : 'li',
LI_DROPDOWN : 'li.dropdown',
LI : 'li'
NAV_ANCHORS : '.nav li > a'
}
const OffsetMethod = {
@ -64,8 +66,8 @@ const ScrollSpy = (($) => {
constructor(element, config) {
this._element = element
this._scrollElement = element.tagName === 'BODY' ? window : element
this._config = $.extend({}, Default, config)
this._selector = `${this._config.target || ''} .nav li > a`
this._config = this._getConfig(config)
this._selector = `${this._config.target} ${Selector.NAV_ANCHORS}`
this._offsets = []
this._targets = []
this._activeTarget = null
@ -150,6 +152,21 @@ const ScrollSpy = (($) => {
// private
_getConfig(config) {
config = $.extend({}, Default, config)
if (typeof config.target !== 'string') {
let id = $(config.target).attr('id')
if (!id) {
id = Util.getUID(NAME)
$(config.target).attr('id', id)
}
config.target = `#${id}`
}
return config
}
_getScrollTop() {
return this._scrollElement === window ?
this._scrollElement.scrollY : this._scrollElement.scrollTop

View file

@ -77,6 +77,51 @@ $(function () {
$scrollspy.scrollTop(350)
})
QUnit.test('should only switch "active" class on current target specified w element', function (assert) {
assert.expect(1)
var done = assert.async()
var sectionHTML = '<div id="root" class="active">'
+ '<div class="topbar">'
+ '<div class="topbar-inner">'
+ '<div class="container" id="ss-target">'
+ '<ul class="nav">'
+ '<li><a href="#masthead">Overview</a></li>'
+ '<li><a href="#detail">Detail</a></li>'
+ '</ul>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '<div id="scrollspy-example" style="height: 100px; overflow: auto;">'
+ '<div style="height: 200px;">'
+ '<h4 id="masthead">Overview</h4>'
+ '<p style="height: 200px">'
+ 'Ad leggings keytar, brunch id art party dolor labore.'
+ '</p>'
+ '</div>'
+ '<div style="height: 200px;">'
+ '<h4 id="detail">Detail</h4>'
+ '<p style="height: 200px">'
+ 'Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard.'
+ '</p>'
+ '</div>'
+ '</div>'
+ '</div>'
var $section = $(sectionHTML).appendTo('#qunit-fixture')
var $scrollspy = $section
.show()
.find('#scrollspy-example')
.bootstrapScrollspy({ target: $('#ss-target') })
$scrollspy.on('scroll.bs.scrollspy', function () {
assert.ok($section.hasClass('active'), '"active" class still on root node')
done()
})
$scrollspy.scrollTop(350)
})
QUnit.test('should correctly select middle navigation option when large offset is used', function (assert) {
assert.expect(3)
var done = assert.async()