diff options
| author | Chris Rebert <[email protected]> | 2014-07-03 13:18:44 -0700 |
|---|---|---|
| committer | Chris Rebert <[email protected]> | 2014-07-03 13:18:44 -0700 |
| commit | 92fd25a2a29dbef6b47ba932e9ba836150b93eeb (patch) | |
| tree | 34f3823fe9e934bc314a5d3f9ed820d56a9f482d /docs/assets/js/src | |
| parent | b793fbb13a8f0cb0fab04de8f7fe732b445e6daf (diff) | |
| download | bootstrap-92fd25a2a29dbef6b47ba932e9ba836150b93eeb.tar.xz bootstrap-92fd25a2a29dbef6b47ba932e9ba836150b93eeb.zip | |
use non-minified docs JS on non-gh-pages
Diffstat (limited to 'docs/assets/js/src')
| -rw-r--r-- | docs/assets/js/src/application.js | 169 | ||||
| -rw-r--r-- | docs/assets/js/src/customizer.js | 429 |
2 files changed, 598 insertions, 0 deletions
diff --git a/docs/assets/js/src/application.js b/docs/assets/js/src/application.js new file mode 100644 index 000000000..792fc9779 --- /dev/null +++ b/docs/assets/js/src/application.js @@ -0,0 +1,169 @@ +// 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 ($) { + 'use strict'; + + $(function () { + + // Scrollspy + var $window = $(window) + var $body = $(document.body) + + $body.scrollspy({ + target: '.bs-docs-sidebar' + }) + $window.on('load', function () { + $body.scrollspy('refresh') + }) + + // Kill links + $('.bs-docs-container [href=#]').click(function (e) { + e.preventDefault() + }) + + // Sidenav affixing + setTimeout(function () { + var $sideBar = $('.bs-docs-sidebar') + + $sideBar.affix({ + offset: { + 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)) + } + } + }) + }, 100) + + setTimeout(function () { + $('.bs-top').affix() + }, 100) + + // theme toggler + ;(function () { + var stylesheetLink = $('#bs-theme-stylesheet') + var themeBtn = $('.bs-docs-theme-toggle') + + var activateTheme = function () { + stylesheetLink.attr('href', stylesheetLink.attr('data-href')) + themeBtn.text('Disable theme preview') + localStorage.setItem('previewTheme', true) + } + + if (localStorage.getItem('previewTheme')) { + activateTheme() + } + + themeBtn.click(function () { + var href = stylesheetLink.attr('href') + if (!href || href.indexOf('data') === 0) { + activateTheme() + } else { + stylesheetLink.attr('href', '') + themeBtn.text('Preview theme') + localStorage.removeItem('previewTheme') + } + }) + })(); + + // Tooltip and popover demos + $('.tooltip-demo').tooltip({ + selector: '[data-toggle="tooltip"]', + container: 'body' + }) + $('.popover-demo').popover({ + selector: '[data-toggle="popover"]', + container: 'body' + }) + + // Demos within modals + $('.tooltip-test').tooltip() + $('.popover-test').popover() + + // Default & dismissible popover demos + $('.bs-docs-popover').popover() + $('.bs-docs-popover-dismiss').popover({ trigger: 'focus' }) + + // Button state demo + $('#loading-example-btn').click(function () { + var btn = $(this) + btn.button('loading') + setTimeout(function () { + btn.button('reset') + }, 3000) + }) + + + // Config ZeroClipboard + ZeroClipboard.config({ + moviePath: '/assets/flash/ZeroClipboard.swf', + hoverClass: 'btn-clipboard-hover' + }) + + // Insert copy to clipboard button before .highlight or .bs-example + $('.highlight').each(function () { + 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 + .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 + .attr('title', 'Copied!') + .tooltip('fixTitle') + .tooltip('show') + .attr('title', 'Copy to clipboard') + .tooltip('fixTitle') + }) + + // Notify copy failure + zeroClipboard.on('noflash wrongflash', function () { + htmlBridge + .attr('title', 'Flash required') + .tooltip('fixTitle') + .tooltip('show') + }) + + }) + +}(jQuery) diff --git a/docs/assets/js/src/customizer.js b/docs/assets/js/src/customizer.js new file mode 100644 index 000000000..c3a212f2c --- /dev/null +++ b/docs/assets/js/src/customizer.js @@ -0,0 +1,429 @@ +/*! + * Bootstrap Customizer (http://getbootstrap.com/customize/) + * 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 JSZip, less, saveAs, UglifyJS, __js, __less, __fonts */ + +window.onload = function () { // wait for load in a dumb way because B-0 + 'use strict'; + var cw = '/*!\n' + + ' * Bootstrap v3.2.0 (http://getbootstrap.com)\n' + + ' * Copyright 2011-2014 Twitter, Inc.\n' + + ' * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n' + + ' */\n\n' + + function showError(msg, err) { + $('<div id="bsCustomizerAlert" class="bs-customizer-alert">' + + '<div class="container">' + + '<a href="#bsCustomizerAlert" data-dismiss="alert" class="close pull-right">×</a>' + + '<p class="bs-customizer-alert-text"><span class="glyphicon glyphicon-warning-sign"></span>' + msg + '</p>' + + (err.extract ? '<pre class="bs-customizer-alert-extract">' + err.extract.join('\n') + '</pre>' : '') + + '</div>' + + '</div>').appendTo('body').alert() + throw err + } + + function showSuccess(msg) { + $('<div class="bs-callout bs-callout-info">' + + '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' + msg + + '</div>').insertAfter('.bs-customize-download') + } + + function showCallout(msg, showUpTop) { + var callout = $('<div class="bs-callout bs-callout-danger">' + + '<h4>Attention!</h4>' + + '<p>' + msg + '</p>' + + '</div>') + + if (showUpTop) { + callout.appendTo('.bs-docs-container') + } else { + callout.insertAfter('.bs-customize-download') + } + } + + function getQueryParam(key) { + key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, '\\$&') // escape RegEx meta chars + var match = location.search.match(new RegExp('[?&]' + key + '=([^&]+)(&|$)')) + return match && decodeURIComponent(match[1].replace(/\+/g, ' ')) + } + + function createGist(configJson, callback) { + var data = { + description: 'Bootstrap Customizer Config', + 'public': true, + files: { + 'config.json': { + content: configJson + } + } + } + $.ajax({ + url: 'https://api.github.com/gists', + type: 'POST', + dataType: 'json', + data: JSON.stringify(data) + }) + .success(function (result) { + var gistUrl = result.html_url; + var origin = window.location.protocol + '//' + window.location.host + var customizerUrl = origin + window.location.pathname + '?id=' + result.id + showSuccess('<strong>Success!</strong> Your configuration has been saved to <a href="' + gistUrl + '">' + gistUrl + '</a> ' + + 'and can be revisited here at <a href="' + customizerUrl + '">' + customizerUrl + '</a> for further customization.') + history.replaceState(false, document.title, customizerUrl) + callback(gistUrl, customizerUrl) + }) + .error(function (err) { + try { + showError('<strong>Ruh roh!</strong> Could not save gist file, configuration not saved.', err) + } catch (sameErr) { + // deliberately ignore the error + } + callback('<none>', '<none>') + }) + } + + function getCustomizerData() { + var vars = {} + + $('#less-variables-section input') + .each(function () { + $(this).val() && (vars[$(this).prev().text()] = $(this).val()) + }) + + var data = { + vars: vars, + css: $('#less-section input:checked') .map(function () { return this.value }).toArray(), + js: $('#plugin-section input:checked').map(function () { return this.value }).toArray() + } + + if ($.isEmptyObject(data.vars) && !data.css.length && !data.js.length) return + + return data + } + + function parseUrl() { + var id = getQueryParam('id') + + if (!id) return + + $.ajax({ + url: 'https://api.github.com/gists/' + id, + type: 'GET', + dataType: 'json' + }) + .success(function (result) { + var data = JSON.parse(result.files['config.json'].content) + if (data.js) { + $('#plugin-section input').each(function () { + $(this).prop('checked', ~$.inArray(this.value, data.js)) + }) + } + if (data.css) { + $('#less-section input').each(function () { + $(this).prop('checked', ~$.inArray(this.value, data.css)) + }) + } + if (data.vars) { + for (var i in data.vars) { + $('input[data-var="' + i + '"]').val(data.vars[i]) + } + } + }) + .error(function (err) { + showError('Error fetching bootstrap config file', err) + }) + } + + function generateZip(css, js, fonts, config, complete) { + if (!css && !js) return showError('<strong>Ruh roh!</strong> No Bootstrap files selected.', new Error('no Bootstrap')) + + var zip = new JSZip() + + if (css) { + var cssFolder = zip.folder('css') + for (var fileName in css) { + cssFolder.file(fileName, css[fileName]) + } + } + + if (js) { + var jsFolder = zip.folder('js') + for (var jsFileName in js) { + jsFolder.file(jsFileName, js[jsFileName]) + } + } + + if (fonts) { + var fontsFolder = zip.folder('fonts') + for (var fontsFileName in fonts) { + fontsFolder.file(fontsFileName, fonts[fontsFileName], { base64: true }) + } + } + + if (config) { + zip.file('config.json', config) + } + + var content = zip.generate({ type: 'blob' }) + + complete(content) + } + + function generateCustomLess(vars) { + var result = '' + + for (var key in vars) { + result += key + ': ' + vars[key] + ';\n' + } + + return result + '\n\n' + } + + function generateFonts() { + var glyphicons = $('#less-section [value="glyphicons.less"]:checked') + if (glyphicons.length) { + return __fonts + } + } + + // Returns an Array of @import'd filenames in the order + // in which they appear in the file. + function includedLessFilenames(lessFilename) { + var IMPORT_REGEX = /^@import \"(.*?)\";$/ + var lessLines = __less[lessFilename].split('\n') + + var imports = [] + $.each(lessLines, function (index, lessLine) { + var match = IMPORT_REGEX.exec(lessLine) + if (match) { + var importee = match[1] + var transitiveImports = includedLessFilenames(importee) + $.each(transitiveImports, function (index, transitiveImportee) { + if ($.inArray(transitiveImportee, imports) === -1) { + imports.push(transitiveImportee) + } + }) + imports.push(importee) + } + }) + + return imports + } + + function generateLESS(lessFilename, lessFileIncludes, vars) { + var lessSource = __less[lessFilename] + + var lessFilenames = includedLessFilenames(lessFilename) + $.each(lessFilenames, function (index, filename) { + var fileInclude = lessFileIncludes[filename] + + // Files not explicitly unchecked are compiled into the final stylesheet. + // Core stylesheets like 'normalize.less' are not included in the form + // since disabling them would wreck everything, and so their 'fileInclude' + // will be 'undefined'. + if (fileInclude || (fileInclude == null)) lessSource += __less[filename] + + // Custom variables are added after Bootstrap variables so the custom + // ones take precedence. + if (('variables.less' === filename) && vars) lessSource += generateCustomLess(vars) + }) + + lessSource = lessSource.replace(/@import[^\n]*/gi, '') // strip any imports + return lessSource + } + + function compileLESS(lessSource, baseFilename, intoResult) { + var parser = new less.Parser({ + paths: ['variables.less', 'mixins.less'], + optimization: 0, + filename: baseFilename + '.css' + }) + + parser.parse(lessSource, function (err, tree) { + if (err) { + return showError('<strong>Ruh roh!</strong> Could not parse less files.', err) + } + intoResult[baseFilename + '.css'] = cw + tree.toCSS() + intoResult[baseFilename + '.min.css'] = cw + tree.toCSS({ compress: true }) + }) + } + + function generateCSS(preamble) { + var oneChecked = false + var lessFileIncludes = {} + $('#less-section input').each(function () { + var $this = $(this) + var checked = $this.is(':checked') + lessFileIncludes[$this.val()] = checked + + oneChecked = oneChecked || checked + }) + + if (!oneChecked) return false + + var result = {} + var vars = {} + + $('#less-variables-section input') + .each(function () { + $(this).val() && (vars[$(this).prev().text()] = $(this).val()) + }) + + var bsLessSource = preamble + generateLESS('bootstrap.less', lessFileIncludes, vars) + var themeLessSource = preamble + generateLESS('theme.less', lessFileIncludes, vars) + + try { + compileLESS(bsLessSource, 'bootstrap', result) + compileLESS(themeLessSource, 'bootstrap-theme', result) + } catch (err) { + return showError('<strong>Ruh roh!</strong> Could not parse less files.', err) + } + + return result + } + + function uglify(js) { + var ast = UglifyJS.parse(js) + ast.figure_out_scope() + + var compressor = UglifyJS.Compressor() + var compressedAst = ast.transform(compressor) + + compressedAst.figure_out_scope() + compressedAst.compute_char_frequency() + compressedAst.mangle_names() + + var stream = UglifyJS.OutputStream() + compressedAst.print(stream) + + return stream.toString() + } + + function generateJS(preamble) { + var $checked = $('#plugin-section input:checked') + var jqueryCheck = 'if (typeof jQuery === "undefined") { throw new Error("Bootstrap\'s JavaScript requires jQuery") }\n\n' + + if (!$checked.length) return false + + var js = $checked + .map(function () { return __js[this.value] }) + .toArray() + .join('\n') + + preamble = cw + preamble + js = jqueryCheck + js + + return { + 'bootstrap.js': preamble + js, + 'bootstrap.min.js': preamble + uglify(js) + } + } + + var inputsComponent = $('#less-section input') + var inputsPlugin = $('#plugin-section input') + var inputsVariables = $('#less-variables-section input') + + $('#less-section .toggle').on('click', function (e) { + e.preventDefault() + inputsComponent.prop('checked', !inputsComponent.is(':checked')) + }) + + $('#plugin-section .toggle').on('click', function (e) { + e.preventDefault() + inputsPlugin.prop('checked', !inputsPlugin.is(':checked')) + }) + + $('#less-variables-section .toggle').on('click', function (e) { + e.preventDefault() + inputsVariables.val('') + }) + + $('[data-dependencies]').on('click', function () { + if (!$(this).is(':checked')) return + var dependencies = this.getAttribute('data-dependencies') + if (!dependencies) return + dependencies = dependencies.split(',') + for (var i = 0; i < dependencies.length; i++) { + var dependency = $('[value="' + dependencies[i] + '"]') + dependency && dependency.prop('checked', true) + } + }) + + $('[data-dependents]').on('click', function () { + if ($(this).is(':checked')) return + var dependents = this.getAttribute('data-dependents') + if (!dependents) return + dependents = dependents.split(',') + for (var i = 0; i < dependents.length; i++) { + var dependent = $('[value="' + dependents[i] + '"]') + dependent && dependent.prop('checked', false) + } + }) + + var $compileBtn = $('#btn-compile') + + $compileBtn.on('click', function (e) { + var configData = getCustomizerData() + var configJson = JSON.stringify(configData, null, 2) + + e.preventDefault() + + $compileBtn.attr('disabled', 'disabled') + + createGist(configJson, function (gistUrl, customizerUrl) { + configData.customizerUrl = customizerUrl + configJson = JSON.stringify(configData, null, 2) + + var preamble = '/*!\n' + + ' * Generated using the Bootstrap Customizer (' + customizerUrl + ')\n' + + ' * Config saved to config.json and ' + gistUrl + '\n' + + ' */\n' + + generateZip(generateCSS(preamble), generateJS(preamble), generateFonts(), configJson, function (blob) { + $compileBtn.removeAttr('disabled') + saveAs(blob, 'bootstrap.zip') + }) + }) + }); + + // browser support alert + (function () { + function failback() { + $('.bs-docs-section, .bs-docs-sidebar').css('display', 'none') + showCallout('Looks like your current browser doesn\'t support the Bootstrap Customizer. Please take a second ' + + 'to <a href="http://browsehappy.com/">upgrade to a more modern browser</a> (other than Safari).', true) + } + /** + * Based on: + * Blob Feature Check v1.1.0 + * https://github.com/ssorallen/blob-feature-check/ + * License: Public domain (http://unlicense.org) + */ + var url = window.webkitURL || window.URL // Safari 6 uses "webkitURL". + var svg = new Blob( + ['<svg xmlns=\'http://www.w3.org/2000/svg\'></svg>'], + { type: 'image/svg+xml;charset=utf-8' } + ) + var objectUrl = url.createObjectURL(svg); + if (/^blob:/.exec(objectUrl) === null) { + // `URL.createObjectURL` created a URL that started with something other + // than "blob:", which means it has been polyfilled and is not supported by + // this browser. + failback() + } else { + $('<img>') + .on('load', function () { + $compileBtn.prop('disabled', false) + }) + .on('error', failback) + .attr('src', objectUrl) + } + })(); + + parseUrl() +} |
