aboutsummaryrefslogtreecommitdiff
path: root/docs-assets/js/customizer.js
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2013-12-14 15:38:21 -0800
committerMark Otto <[email protected]>2013-12-14 15:38:21 -0800
commita54dbfdf2a08ff04fc65f8e4f77ee5dc76bf4ef3 (patch)
tree9b1c5697a731543a86711b016e1986ec1e81dad4 /docs-assets/js/customizer.js
parent80e86442308b2cc86ba948de87e854057933e3ab (diff)
parentf1869771bc8b8e8a6c7a98385ec58e0bf0d2d98e (diff)
downloadbootstrap-a54dbfdf2a08ff04fc65f8e4f77ee5dc76bf4ef3.tar.xz
bootstrap-a54dbfdf2a08ff04fc65f8e4f77ee5dc76bf4ef3.zip
Merge branch 'master' into pr/10951
Conflicts: dist/css/bootstrap.min.css less/modals.less
Diffstat (limited to 'docs-assets/js/customizer.js')
-rw-r--r--docs-assets/js/customizer.js129
1 files changed, 86 insertions, 43 deletions
diff --git a/docs-assets/js/customizer.js b/docs-assets/js/customizer.js
index 5abfe4228..b6e78bd2b 100644
--- a/docs-assets/js/customizer.js
+++ b/docs-assets/js/customizer.js
@@ -1,5 +1,14 @@
+/*!
+ * Copyright 2013 Twitter, Inc.
+ *
+ * Licensed under the Creative Commons Attribution 3.0 Unported License. For
+ * details, see http://creativecommons.org/licenses/by/3.0/.
+ */
+
+/* jshint multistr:true */
+
window.onload = function () { // wait for load in a dumb way because B-0
- var cw = '/*!\n * Bootstrap v3.0.0\n *\n * Copyright 2013 Twitter, Inc\n * Licensed under the Apache License v2.0\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Designed and built with all the love in the world @twitter by @mdo and @fat.\n */\n\n'
+ var cw = '/*!\n * Bootstrap v3.0.3 (http://getbootstrap.com)\n\n *\n * Copyright 2013 Twitter, Inc\n * Licensed under the Apache License v2.0\n * http://www.apache.org/licenses/LICENSE-2.0\n */\n\n'
function showError(msg, err) {
$('<div id="bsCustomizerAlert" class="bs-customizer-alert">\
@@ -26,18 +35,18 @@ window.onload = function () { // wait for load in a dumb way because B-0
}
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, " "));
+ 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(configData) {
+ function createGist(configJson) {
var data = {
- "description": "Bootstrap Customizer Config",
- "public": true,
- "files": {
- "config.json": {
- "content": JSON.stringify(configData, null, 2)
+ 'description': 'Bootstrap Customizer Config',
+ 'public': true,
+ 'files': {
+ 'config.json': {
+ 'content': configJson
}
}
}
@@ -47,10 +56,11 @@ window.onload = function () { // wait for load in a dumb way because B-0
dataType: 'json',
data: JSON.stringify(data)
})
- .success(function(result) {
- history.replaceState(false, document.title, window.location.origin + window.location.pathname + '?id=' + result.id)
+ .success(function (result) {
+ var origin = window.location.protocol + '//' + window.location.host
+ history.replaceState(false, document.title, origin + window.location.pathname + '?id=' + result.id)
})
- .error(function(err) {
+ .error(function (err) {
showError('<strong>Ruh roh!</strong> Could not save gist file, configuration not saved.', err)
})
}
@@ -60,7 +70,7 @@ window.onload = function () { // wait for load in a dumb way because B-0
$('#less-variables-section input')
.each(function () {
- $(this).val() && (vars[ $(this).prev().text() ] = $(this).val())
+ $(this).val() && (vars[$(this).prev().text()] = $(this).val())
})
var data = {
@@ -84,7 +94,7 @@ window.onload = function () { // wait for load in a dumb way because B-0
type: 'GET',
dataType: 'json'
})
- .success(function(result) {
+ .success(function (result) {
var data = JSON.parse(result.files['config.json'].content)
if (data.js) {
$('#plugin-section input').each(function () {
@@ -102,12 +112,12 @@ window.onload = function () { // wait for load in a dumb way because B-0
}
}
})
- .error(function(err) {
+ .error(function (err) {
showError('Error fetching bootstrap config file', err)
})
}
- function generateZip(css, js, fonts, complete) {
+ 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()
@@ -121,19 +131,23 @@ window.onload = function () { // wait for load in a dumb way because B-0
if (js) {
var jsFolder = zip.folder('js')
- for (var fileName in js) {
- jsFolder.file(fileName, js[fileName])
+ for (var jsFileName in js) {
+ jsFolder.file(jsFileName, js[jsFileName])
}
}
if (fonts) {
var fontsFolder = zip.folder('fonts')
- for (var fileName in fonts) {
- fontsFolder.file(fileName, fonts[fileName])
+ for (var fontsFileName in fonts) {
+ fontsFolder.file(fontsFileName, fonts[fontsFileName], {base64: true})
}
}
- var content = zip.generate({type:"blob"})
+ if (config) {
+ zip.file('config.json', config)
+ }
+
+ var content = zip.generate({ type: 'blob' })
complete(content)
}
@@ -155,10 +169,32 @@ window.onload = function () { // wait for load in a dumb way because B-0
}
}
+ // Returns an Array of @import'd filenames from 'bootstrap.less' in the order
+ // in which they appear in the file.
+ function bootstrapLessFilenames() {
+ var IMPORT_REGEX = /^@import \"(.*?)\";$/
+ var bootstrapLessLines = __less['bootstrap.less'].split('\n')
+
+ for (var i = 0, imports = []; i < bootstrapLessLines.length; i++) {
+ var match = IMPORT_REGEX.exec(bootstrapLessLines[i])
+ if (match) imports.push(match[1])
+ }
+
+ return imports
+ }
+
function generateCSS() {
- var $checked = $('#less-section input:checked')
+ 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 (!$checked.length) return false
+ if (!oneChecked) return false
var result = {}
var vars = {}
@@ -166,18 +202,22 @@ window.onload = function () { // wait for load in a dumb way because B-0
$('#less-variables-section input')
.each(function () {
- $(this).val() && (vars[ $(this).prev().text() ] = $(this).val())
+ $(this).val() && (vars[$(this).prev().text()] = $(this).val())
})
- css += __less['variables.less']
- if (vars) css += generateCustomCSS(vars)
- css += __less['mixins.less']
- css += __less['normalize.less']
- css += __less['scaffolding.less']
- css += $checked
- .map(function () { return __less[this.value] })
- .toArray()
- .join('\n')
+ $.each(bootstrapLessFilenames(), 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)) css += __less[filename]
+
+ // Custom variables are added after Bootstrap variables so the custom
+ // ones take precedence.
+ if (('variables.less' === filename) && vars) css += generateCustomCSS(vars)
+ })
css = css.replace(/@import[^\n]*/gi, '') //strip any imports
@@ -262,28 +302,31 @@ window.onload = function () { // wait for load in a dumb way because B-0
var $downloadBtn = $('#btn-download')
$compileBtn.on('click', function (e) {
+ var configData = getCustomizerData()
+ var configJson = JSON.stringify(configData, null, 2)
+
e.preventDefault()
$compileBtn.attr('disabled', 'disabled')
- generateZip(generateCSS(), generateJavascript(), generateFonts(), function (blob) {
+ generateZip(generateCSS(), generateJavascript(), generateFonts(), configJson, function (blob) {
$compileBtn.removeAttr('disabled')
- saveAs(blob, "bootstrap.zip")
- createGist(getCustomizerData())
+ saveAs(blob, 'bootstrap.zip')
+ createGist(configJson)
})
})
// browser support alerts
if (!window.URL && navigator.userAgent.toLowerCase().indexOf('safari') != -1) {
- showCallout("Looks like you're using safari, which sadly doesn't have the best support\
- for HTML5 blobs. Because of this your file will be downloaded with the name <code>\"untitled\"</code>.\
- However, if you check your downloads folder, just rename this <code>\"untitled\"</code> file\
- to <code>\"bootstrap.zip\"</code> and you should be good to go!")
+ showCallout('Looks like you\'re using safari, which sadly doesn\'t have the best support\
+ for HTML5 blobs. Because of this your file will be downloaded with the name <code>"untitled"</code>.\
+ However, if you check your downloads folder, just rename this <code>"untitled"</code> file\
+ to <code>"bootstrap.zip"</code> and you should be good to go!')
} else if (!window.URL && !window.webkitURL) {
$('.bs-docs-section, .bs-sidebar').css('display', 'none')
- showCallout("Looks like your current browser doesn't support the Bootstrap Customizer. Please take a second\
- to <a href=\"https://www.google.com/intl/en/chrome/browser/\"> upgrade to a more modern browser</a>.", true)
+ showCallout('Looks like your current browser doesn\'t support the Bootstrap Customizer. Please take a second\
+ to <a href="https://www.google.com/intl/en/chrome/browser/"> upgrade to a more modern browser</a>.', true)
}
parseUrl()