1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00
twbs--bootstrap/docs/assets/js/application.js

144 lines
3.5 KiB
JavaScript
Raw Normal View History

2011-05-03 21:12:43 -04:00
$(document).ready(function(){
2011-07-02 00:37:12 -04:00
// scroll spy logic
// ================
var activeTarget,
$window = $(window),
position = {},
nav = $('body > .topbar li a'),
targets = nav.map(function () {
return $(this).attr('href');
}),
offsets = $.map(targets, function (id) {
return $(id).offset().top;
});
function setButton(id) {
nav.parent("li").removeClass('active');
$(nav[$.inArray(id, targets)]).parent("li").addClass('active');
}
function processScroll(e) {
var scrollTop = $window.scrollTop() + 10, i;
for (i = offsets.length; i--;) {
if (activeTarget != targets[i] && scrollTop >= offsets[i] && (!offsets[i + 1] || scrollTop <= offsets[i + 1])) {
activeTarget = targets[i];
setButton(activeTarget);
}
}
}
nav.click(function () {
processScroll();
});
processScroll();
$window.scroll(processScroll);
// Dropdown example for topbar nav
// ===============================
2011-05-03 21:12:43 -04:00
$("body").bind("click", function(e) {
$("ul.menu-dropdown").hide();
$('a.menu').parent("li").removeClass("open").children("ul.menu-dropdown").hide();
});
2011-06-30 16:57:29 -04:00
2011-05-03 21:12:43 -04:00
$("a.menu").click(function(e) {
var $target = $(this);
var $parent = $target.parent("li");
var $siblings = $target.siblings("ul.menu-dropdown");
var $parentSiblings = $parent.siblings("li");
if ($parent.hasClass("open")) {
$parent.removeClass("open");
$siblings.hide();
} else {
$parent.addClass("open");
$siblings.show();
}
$parentSiblings.children("ul.menu-dropdown").hide();
$parentSiblings.removeClass("open");
return false;
});
2011-07-02 00:37:12 -04:00
// table sort example
2011-07-02 00:37:12 -04:00
// ==================
$("#sortTableExample").tablesorter( {sortList: [[1,0]]} );
2011-07-02 00:37:12 -04:00
// add on logic
// ============
$('.add-on :checkbox').click(function() {
if ($(this).attr('checked')) {
$(this).parents('.add-on').addClass('active');
} else {
$(this).parents('.add-on').removeClass('active');
}
});
2011-07-02 00:30:12 -04:00
2011-07-02 00:37:12 -04:00
// Disable certain links in docs
2011-07-02 00:37:12 -04:00
// =============================
2011-07-02 01:15:16 -04:00
$('ul.tabs a, ul.pills a, .pagination a, .well .btn, .actions .btn, .alert-message .btn, a.close').click(function(e) {
e.preventDefault();
});
// Copy code blocks in docs
$(".copy-code").focus(function() {
$(this).select();
});
$(".copy-code").mouseup(function(e) {
e.preventDefault();
});
2011-07-02 00:30:12 -04:00
// POSITION TWIPSIES
// =================
2011-07-02 00:30:12 -04:00
$('.twipsies.well a').each(function () {
var type = this.title
, $anchor = $(this)
, $twipsy = $('.twipsy.' + type)
2011-07-02 00:30:12 -04:00
, twipsy = {
width: $twipsy.width() + 10
, height: $twipsy.height() + 10
}
2011-07-02 00:30:12 -04:00
, anchor = {
position: $anchor.position()
, width: $anchor.width()
, height: $anchor.height()
}
, offset = {
above: {
top: anchor.position.top - twipsy.height
, left: anchor.position.left + (anchor.width/2) - (twipsy.width/2)
}
, below: {
top: anchor.position.top + anchor.height
, left: anchor.position.left + (anchor.width/2) - (twipsy.width/2)
}
, left: {
top: anchor.position.top + (anchor.height/2) - (twipsy.height/2)
, left: anchor.position.left - twipsy.width - 5
}
, right: {
top: anchor.position.top + (anchor.height/2) - (twipsy.height/2)
, left: anchor.position.left + anchor.width + 5
}
}
2011-07-02 00:30:12 -04:00
$twipsy.css(offset[type])
2011-07-02 00:30:12 -04:00
});
2011-05-03 21:12:43 -04:00
});