1 // NOTICE!! DO NOT USE ANY OF THIS JAVASCRIPT
2 // IT'S ALL JUST JUNK FOR OUR DOCS!
3 // ++++++++++++++++++++++++++++++++++++++++++
6 * JavaScript for Bootstrap's docs (http://getbootstrap.com)
7 * Copyright 2011-2014 Twitter, Inc.
8 * Licensed under the Creative Commons Attribution 3.0 Unported License. For
9 * details, see http://creativecommons.org/licenses/by/3.0/.
12 /* global ZeroClipboard, addAnchors */
20 var $window = $(window)
21 var $body = $(document.body)
24 target: '.bs-docs-sidebar'
26 $window.on('load', function () {
27 $body.scrollspy('refresh')
31 $('.bs-docs-container [href=#]').click(function (e) {
36 setTimeout(function () {
37 var $sideBar = $('.bs-docs-sidebar')
42 var offsetTop = $sideBar.offset().top
43 var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10)
44 var navOuterHeight = $('.bs-docs-nav').height()
46 return (this.top = offsetTop - navOuterHeight - sideBarMargin)
49 return (this.bottom = $('.bs-docs-footer').outerHeight(true))
55 setTimeout(function () {
61 var stylesheetLink = $('#bs-theme-stylesheet')
62 var themeBtn = $('.bs-docs-theme-toggle')
64 var activateTheme = function () {
65 stylesheetLink.attr('href', stylesheetLink.attr('data-href'))
66 themeBtn.text('Disable theme preview')
67 localStorage.setItem('previewTheme', true)
70 if (localStorage.getItem('previewTheme')) {
74 themeBtn.click(function () {
75 var href = stylesheetLink.attr('href')
76 if (!href || href.indexOf('data') === 0) {
79 stylesheetLink.attr('href', '')
80 themeBtn.text('Preview theme')
81 localStorage.removeItem('previewTheme')
86 // Tooltip and popover demos
87 $('.tooltip-demo').tooltip({
88 selector: '[data-toggle="tooltip"]',
91 $('.popover-demo').popover({
92 selector: '[data-toggle="popover"]',
96 // Demos within modals
97 $('.tooltip-test').tooltip()
98 $('.popover-test').popover()
101 $('.bs-docs-popover').popover()
104 $('#loading-example-btn').on('click', function () {
106 btn.button('loading')
107 setTimeout(function () {
112 // Modal relatedTarget demo
113 $('#exampleModal').on('show.bs.modal', function (event) {
114 var button = $(event.relatedTarget) // Button that triggered the modal
115 var recipient = button.data('whatever') // Extract info from data-* attributes
116 // If necessary, you could initiate an AJAX request here (and then do the updating in a callback).
117 // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead.
119 modal.find('.modal-title').text('New message to ' + recipient)
120 modal.find('.modal-body input').val(recipient)
123 // Activate animated progress bar
124 $('.bs-docs-activate-animated-progressbar').on('click', function () {
125 $(this).siblings('.progress').find('.progress-bar-striped').toggleClass('active')
128 // Config ZeroClipboard
129 ZeroClipboard.config({
130 moviePath: '/assets/flash/ZeroClipboard.swf',
131 hoverClass: 'btn-clipboard-hover'
134 // Insert copy to clipboard button before .highlight
135 $('.highlight').each(function () {
136 var btnHtml = '<div class="zero-clipboard"><span class="btn-clipboard">Copy</span></div>'
137 $(this).before(btnHtml)
139 var zeroClipboard = new ZeroClipboard($('.btn-clipboard'))
140 var htmlBridge = $('#global-zeroclipboard-html-bridge')
142 // Handlers for ZeroClipboard
143 zeroClipboard.on('load', function () {
145 .data('placement', 'top')
146 .attr('title', 'Copy to clipboard')
151 zeroClipboard.on('dataRequested', function (client) {
152 var highlight = $(this).parent().nextAll('.highlight').first()
153 client.setText(highlight.text())
156 // Notify copy success and reset tooltip title
157 zeroClipboard.on('complete', function () {
159 .attr('title', 'Copied!')
162 .attr('title', 'Copy to clipboard')
166 // Notify copy failure
167 zeroClipboard.on('noflash wrongflash', function () {
169 .attr('title', 'Flash required')
180 addAnchors('.bs-docs-container h1, .bs-docs-container h2, .bs-docs-container h3, .bs-docs-container h4, .bs-docs-container h5');