bootstrap/docs/assets/js/_src/application.js

161 lines
4.2 KiB
JavaScript
Raw Normal View History

// NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
// IT'S ALL JUST JUNK FOR OUR DOCS!
// ++++++++++++++++++++++++++++++++++++++++++
/*!
* JavaScript for Bootstrap's docs (http://getbootstrap.com)
* Copyright 2011-2014 Twitter, Inc.
* Licensed under the Creative Commons Attribution 3.0 Unported License. For
* details, see http://creativecommons.org/licenses/by/3.0/.
*/
/* global ZeroClipboard */
!function ($) {
2014-03-17 15:12:55 +08:00
'use strict';
$(function () {
2012-01-25 09:13:02 +08:00
2014-02-11 16:04:53 +08:00
// Scrollspy
var $window = $(window)
2013-07-29 13:23:20 +08:00
var $body = $(document.body)
2013-07-29 13:23:20 +08:00
$body.scrollspy({
2014-03-02 00:19:50 +08:00
target: '.bs-docs-sidebar'
2013-07-27 10:25:45 +08:00
})
2013-08-12 06:03:48 +08:00
$window.on('load', function () {
$body.scrollspy('refresh')
})
2014-02-11 16:04:53 +08:00
// Kill links
2013-07-29 13:14:43 +08:00
$('.bs-docs-container [href=#]').click(function (e) {
2012-01-24 06:14:16 +08:00
e.preventDefault()
})
2014-02-11 16:04:53 +08:00
// Sidenav affixing
setTimeout(function () {
var $sideBar = $('.bs-docs-sidebar')
2013-07-26 14:30:13 +08:00
$sideBar.affix({
offset: {
2013-07-26 14:30:13 +08:00
top: function () {
var offsetTop = $sideBar.offset().top
var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10)
var navOuterHeight = $('.bs-docs-nav').height()
return (this.top = offsetTop - navOuterHeight - sideBarMargin)
},
bottom: function () {
return (this.bottom = $('.bs-docs-footer').outerHeight(true))
2013-07-26 14:30:13 +08:00
}
}
})
}, 100)
2013-03-31 09:41:26 +08:00
setTimeout(function () {
2013-05-09 13:52:48 +08:00
$('.bs-top').affix()
2013-03-31 09:41:26 +08:00
}, 100)
// theme toggler
;(function () {
var stylesheetLink = $('#bs-theme-stylesheet')
2014-05-23 09:38:43 +08:00
var themeBtn = $('.bs-docs-theme-toggle')
themeBtn.click(function () {
2014-04-30 06:56:18 +08:00
var href = stylesheetLink.attr('href');
if (!href || href.indexOf('data') === 0) {
stylesheetLink.attr('href', stylesheetLink.attr('data-href'))
2014-05-23 09:38:43 +08:00
themeBtn.text('Disable theme preview')
}
2014-04-30 06:56:18 +08:00
else {
stylesheetLink.attr('href', '')
2014-05-23 09:38:43 +08:00
themeBtn.text('Preview theme')
2014-04-30 06:56:18 +08:00
}
})
})();
2014-02-11 16:04:53 +08:00
// Tooltip and popover demos
$('.tooltip-demo').tooltip({
selector: '[data-toggle="tooltip"]',
2013-09-19 00:50:02 +08:00
container: 'body'
2012-01-28 16:46:04 +08:00
})
$('.tooltip-test').tooltip()
$('.popover-test').popover()
2012-01-28 16:46:04 +08:00
2013-03-28 14:33:45 +08:00
$('.bs-docs-navbar').tooltip({
selector: 'a[data-toggle="tooltip"]',
2013-09-19 00:50:02 +08:00
container: '.bs-docs-navbar .nav'
2013-03-28 14:33:45 +08:00
})
2014-02-11 16:04:53 +08:00
// Default popover demo
2014-02-11 13:34:05 +08:00
$('.bs-docs-popover').popover()
2014-02-11 16:04:53 +08:00
// Button state demo
$('#loading-example-btn').click(function () {
var btn = $(this)
btn.button('loading')
setTimeout(function () {
btn.button('reset')
}, 3000)
2014-02-11 13:34:05 +08:00
})
2012-01-28 16:46:04 +08:00
2014-02-11 16:04:53 +08:00
// Config ZeroClipboard
ZeroClipboard.config({
moviePath: '/assets/flash/ZeroClipboard.swf',
2014-02-11 16:04:53 +08:00
hoverClass: 'btn-clipboard-hover'
})
// Insert copy to clipboard button before .highlight or .bs-example
$('.highlight').each(function () {
2014-02-11 16:04:53 +08:00
var highlight = $(this)
var previous = highlight.prev()
var btnHtml = '<div class="zero-clipboard"><span class="btn-clipboard">Copy</span></div>'
if (previous.hasClass('bs-example')) {
previous.before(btnHtml.replace(/btn-clipboard/, 'btn-clipboard with-example'))
} else {
highlight.before(btnHtml)
}
})
var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
var htmlBridge = $('#global-zeroclipboard-html-bridge')
// Handlers for ZeroClipboard
zeroClipboard.on('load', function () {
htmlBridge
2014-02-11 16:04:53 +08:00
.data('placement', 'top')
.attr('title', 'Copy to clipboard')
.tooltip()
})
// Copy to clipboard
zeroClipboard.on('dataRequested', function (client) {
var highlight = $(this).parent().nextAll('.highlight').first()
client.setText(highlight.text())
})
// Notify copy success and reset tooltip title
zeroClipboard.on('complete', function () {
htmlBridge
2014-02-11 16:04:53 +08:00
.attr('title', 'Copied!')
.tooltip('fixTitle')
.tooltip('show')
2014-06-10 14:29:44 +08:00
.attr('title', 'Copy to clipboard')
.tooltip('fixTitle')
})
// Notify copy failure
zeroClipboard.on('noflash wrongflash', function () {
htmlBridge
2014-02-11 16:04:53 +08:00
.attr('title', 'Flash required')
.tooltip('fixTitle')
.tooltip('show')
})
})
2013-11-26 15:43:26 +08:00
}(jQuery)