1.1 --- a/bootstrap-source/bootstrap-3.0.3/docs-assets/js/customizer.js Sat Jan 18 12:34:36 2014 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,332 +0,0 @@
1.4 -/*!
1.5 - * Copyright 2013 Twitter, Inc.
1.6 - *
1.7 - * Licensed under the Creative Commons Attribution 3.0 Unported License. For
1.8 - * details, see http://creativecommons.org/licenses/by/3.0/.
1.9 - */
1.10 -
1.11 -
1.12 -window.onload = function () { // wait for load in a dumb way because B-0
1.13 - var cw = '/*!\n * Bootstrap v3.0.3\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'
1.14 -
1.15 - function showError(msg, err) {
1.16 - $('<div id="bsCustomizerAlert" class="bs-customizer-alert">\
1.17 - <div class="container">\
1.18 - <a href="#bsCustomizerAlert" data-dismiss="alert" class="close pull-right">×</a>\
1.19 - <p class="bs-customizer-alert-text"><span class="glyphicon glyphicon-warning-sign"></span>' + msg + '</p>' +
1.20 - (err.extract ? '<pre class="bs-customizer-alert-extract">' + err.extract.join('\n') + '</pre>' : '') + '\
1.21 - </div>\
1.22 - </div>').appendTo('body').alert()
1.23 - throw err
1.24 - }
1.25 -
1.26 - function showCallout(msg, showUpTop) {
1.27 - var callout = $('<div class="bs-callout bs-callout-danger">\
1.28 - <h4>Attention!</h4>\
1.29 - <p>' + msg + '</p>\
1.30 - </div>')
1.31 -
1.32 - if (showUpTop) {
1.33 - callout.appendTo('.bs-docs-container')
1.34 - } else {
1.35 - callout.insertAfter('.bs-customize-download')
1.36 - }
1.37 - }
1.38 -
1.39 - function getQueryParam(key) {
1.40 - key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars
1.41 - var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)"));
1.42 - return match && decodeURIComponent(match[1].replace(/\+/g, " "));
1.43 - }
1.44 -
1.45 - function createGist(configJson) {
1.46 - var data = {
1.47 - "description": "Bootstrap Customizer Config",
1.48 - "public": true,
1.49 - "files": {
1.50 - "config.json": {
1.51 - "content": configJson
1.52 - }
1.53 - }
1.54 - }
1.55 - $.ajax({
1.56 - url: 'https://api.github.com/gists',
1.57 - type: 'POST',
1.58 - dataType: 'json',
1.59 - data: JSON.stringify(data)
1.60 - })
1.61 - .success(function(result) {
1.62 - var origin = window.location.protocol + "//" + window.location.host
1.63 - history.replaceState(false, document.title, origin + window.location.pathname + '?id=' + result.id)
1.64 - })
1.65 - .error(function(err) {
1.66 - showError('<strong>Ruh roh!</strong> Could not save gist file, configuration not saved.', err)
1.67 - })
1.68 - }
1.69 -
1.70 - function getCustomizerData() {
1.71 - var vars = {}
1.72 -
1.73 - $('#less-variables-section input')
1.74 - .each(function () {
1.75 - $(this).val() && (vars[ $(this).prev().text() ] = $(this).val())
1.76 - })
1.77 -
1.78 - var data = {
1.79 - vars: vars,
1.80 - css: $('#less-section input:checked') .map(function () { return this.value }).toArray(),
1.81 - js: $('#plugin-section input:checked').map(function () { return this.value }).toArray()
1.82 - }
1.83 -
1.84 - if ($.isEmptyObject(data.vars) && !data.css.length && !data.js.length) return
1.85 -
1.86 - return data
1.87 - }
1.88 -
1.89 - function parseUrl() {
1.90 - var id = getQueryParam('id')
1.91 -
1.92 - if (!id) return
1.93 -
1.94 - $.ajax({
1.95 - url: 'https://api.github.com/gists/' + id,
1.96 - type: 'GET',
1.97 - dataType: 'json'
1.98 - })
1.99 - .success(function(result) {
1.100 - var data = JSON.parse(result.files['config.json'].content)
1.101 - if (data.js) {
1.102 - $('#plugin-section input').each(function () {
1.103 - $(this).prop('checked', ~$.inArray(this.value, data.js))
1.104 - })
1.105 - }
1.106 - if (data.css) {
1.107 - $('#less-section input').each(function () {
1.108 - $(this).prop('checked', ~$.inArray(this.value, data.css))
1.109 - })
1.110 - }
1.111 - if (data.vars) {
1.112 - for (var i in data.vars) {
1.113 - $('input[data-var="' + i + '"]').val(data.vars[i])
1.114 - }
1.115 - }
1.116 - })
1.117 - .error(function(err) {
1.118 - showError('Error fetching bootstrap config file', err)
1.119 - })
1.120 - }
1.121 -
1.122 - function generateZip(css, js, fonts, config, complete) {
1.123 - if (!css && !js) return showError('<strong>Ruh roh!</strong> No Bootstrap files selected.', new Error('no Bootstrap'))
1.124 -
1.125 - var zip = new JSZip()
1.126 -
1.127 - if (css) {
1.128 - var cssFolder = zip.folder('css')
1.129 - for (var fileName in css) {
1.130 - cssFolder.file(fileName, css[fileName])
1.131 - }
1.132 - }
1.133 -
1.134 - if (js) {
1.135 - var jsFolder = zip.folder('js')
1.136 - for (var fileName in js) {
1.137 - jsFolder.file(fileName, js[fileName])
1.138 - }
1.139 - }
1.140 -
1.141 - if (fonts) {
1.142 - var fontsFolder = zip.folder('fonts')
1.143 - for (var fileName in fonts) {
1.144 - fontsFolder.file(fileName, fonts[fileName], {base64: true})
1.145 - }
1.146 - }
1.147 -
1.148 - if (config) {
1.149 - zip.file('config.json', config)
1.150 - }
1.151 -
1.152 - var content = zip.generate({type:"blob"})
1.153 -
1.154 - complete(content)
1.155 - }
1.156 -
1.157 - function generateCustomCSS(vars) {
1.158 - var result = ''
1.159 -
1.160 - for (var key in vars) {
1.161 - result += key + ': ' + vars[key] + ';\n'
1.162 - }
1.163 -
1.164 - return result + '\n\n'
1.165 - }
1.166 -
1.167 - function generateFonts() {
1.168 - var glyphicons = $('#less-section [value="glyphicons.less"]:checked')
1.169 - if (glyphicons.length) {
1.170 - return __fonts
1.171 - }
1.172 - }
1.173 -
1.174 - // Returns an Array of @import'd filenames from 'bootstrap.less' in the order
1.175 - // in which they appear in the file.
1.176 - function bootstrapLessFilenames() {
1.177 - var IMPORT_REGEX = /^@import \"(.*?)\";$/
1.178 - var bootstrapLessLines = __less['bootstrap.less'].split('\n')
1.179 -
1.180 - for (var i = 0, imports = []; i < bootstrapLessLines.length; i++) {
1.181 - var match = IMPORT_REGEX.exec(bootstrapLessLines[i])
1.182 - if (match) imports.push(match[1])
1.183 - }
1.184 -
1.185 - return imports
1.186 - }
1.187 -
1.188 - function generateCSS() {
1.189 - var oneChecked = false
1.190 - var lessFileIncludes = {}
1.191 - $('#less-section input').each(function() {
1.192 - var $this = $(this)
1.193 - var checked = $this.is(':checked')
1.194 - lessFileIncludes[$this.val()] = checked
1.195 -
1.196 - oneChecked = oneChecked || checked
1.197 - })
1.198 -
1.199 - if (!oneChecked) return false
1.200 -
1.201 - var result = {}
1.202 - var vars = {}
1.203 - var css = ''
1.204 -
1.205 - $('#less-variables-section input')
1.206 - .each(function () {
1.207 - $(this).val() && (vars[ $(this).prev().text() ] = $(this).val())
1.208 - })
1.209 -
1.210 - $.each(bootstrapLessFilenames(), function(index, filename) {
1.211 - var fileInclude = lessFileIncludes[filename]
1.212 -
1.213 - // Files not explicitly unchecked are compiled into the final stylesheet.
1.214 - // Core stylesheets like 'normalize.less' are not included in the form
1.215 - // since disabling them would wreck everything, and so their 'fileInclude'
1.216 - // will be 'undefined'.
1.217 - if (fileInclude || (fileInclude == null)) css += __less[filename]
1.218 -
1.219 - // Custom variables are added after Bootstrap variables so the custom
1.220 - // ones take precedence.
1.221 - if (('variables.less' === filename) && vars) css += generateCustomCSS(vars)
1.222 - })
1.223 -
1.224 - css = css.replace(/@import[^\n]*/gi, '') //strip any imports
1.225 -
1.226 - try {
1.227 - var parser = new less.Parser({
1.228 - paths: ['variables.less', 'mixins.less']
1.229 - , optimization: 0
1.230 - , filename: 'bootstrap.css'
1.231 - }).parse(css, function (err, tree) {
1.232 - if (err) {
1.233 - return showError('<strong>Ruh roh!</strong> Could not parse less files.', err)
1.234 - }
1.235 - result = {
1.236 - 'bootstrap.css' : cw + tree.toCSS(),
1.237 - 'bootstrap.min.css' : cw + tree.toCSS({ compress: true }).replace(/\n/g, '') // FIXME: remove newline hack once less.js upgraded to v1.4
1.238 - }
1.239 - })
1.240 - } catch (err) {
1.241 - return showError('<strong>Ruh roh!</strong> Could not parse less files.', err)
1.242 - }
1.243 -
1.244 - return result
1.245 - }
1.246 -
1.247 - function generateJavascript() {
1.248 - var $checked = $('#plugin-section input:checked')
1.249 - if (!$checked.length) return false
1.250 -
1.251 - var js = $checked
1.252 - .map(function () { return __js[this.value] })
1.253 - .toArray()
1.254 - .join('\n')
1.255 -
1.256 - return {
1.257 - 'bootstrap.js': js,
1.258 - 'bootstrap.min.js': cw + uglify(js)
1.259 - }
1.260 - }
1.261 -
1.262 - var inputsComponent = $('#less-section input')
1.263 - var inputsPlugin = $('#plugin-section input')
1.264 - var inputsVariables = $('#less-variables-section input')
1.265 -
1.266 - $('#less-section .toggle').on('click', function (e) {
1.267 - e.preventDefault()
1.268 - inputsComponent.prop('checked', !inputsComponent.is(':checked'))
1.269 - })
1.270 -
1.271 - $('#plugin-section .toggle').on('click', function (e) {
1.272 - e.preventDefault()
1.273 - inputsPlugin.prop('checked', !inputsPlugin.is(':checked'))
1.274 - })
1.275 -
1.276 - $('#less-variables-section .toggle').on('click', function (e) {
1.277 - e.preventDefault()
1.278 - inputsVariables.val('')
1.279 - })
1.280 -
1.281 - $('[data-dependencies]').on('click', function () {
1.282 - if (!$(this).is(':checked')) return
1.283 - var dependencies = this.getAttribute('data-dependencies')
1.284 - if (!dependencies) return
1.285 - dependencies = dependencies.split(',')
1.286 - for (var i = 0; i < dependencies.length; i++) {
1.287 - var dependency = $('[value="' + dependencies[i] + '"]')
1.288 - dependency && dependency.prop('checked', true)
1.289 - }
1.290 - })
1.291 -
1.292 - $('[data-dependents]').on('click', function () {
1.293 - if ($(this).is(':checked')) return
1.294 - var dependents = this.getAttribute('data-dependents')
1.295 - if (!dependents) return
1.296 - dependents = dependents.split(',')
1.297 - for (var i = 0; i < dependents.length; i++) {
1.298 - var dependent = $('[value="' + dependents[i] + '"]')
1.299 - dependent && dependent.prop('checked', false)
1.300 - }
1.301 - })
1.302 -
1.303 - var $compileBtn = $('#btn-compile')
1.304 - var $downloadBtn = $('#btn-download')
1.305 -
1.306 - $compileBtn.on('click', function (e) {
1.307 - var configData = getCustomizerData()
1.308 - var configJson = JSON.stringify(configData, null, 2)
1.309 -
1.310 - e.preventDefault()
1.311 -
1.312 - $compileBtn.attr('disabled', 'disabled')
1.313 -
1.314 - generateZip(generateCSS(), generateJavascript(), generateFonts(), configJson, function (blob) {
1.315 - $compileBtn.removeAttr('disabled')
1.316 - saveAs(blob, "bootstrap.zip")
1.317 - createGist(configJson)
1.318 - })
1.319 - })
1.320 -
1.321 - // browser support alerts
1.322 - if (!window.URL && navigator.userAgent.toLowerCase().indexOf('safari') != -1) {
1.323 - showCallout("Looks like you're using safari, which sadly doesn't have the best support\
1.324 - for HTML5 blobs. Because of this your file will be downloaded with the name <code>\"untitled\"</code>.\
1.325 - However, if you check your downloads folder, just rename this <code>\"untitled\"</code> file\
1.326 - to <code>\"bootstrap.zip\"</code> and you should be good to go!")
1.327 - } else if (!window.URL && !window.webkitURL) {
1.328 - $('.bs-docs-section, .bs-sidebar').css('display', 'none')
1.329 -
1.330 - showCallout("Looks like your current browser doesn't support the Bootstrap Customizer. Please take a second\
1.331 - to <a href=\"https://www.google.com/intl/en/chrome/browser/\"> upgrade to a more modern browser</a>.", true)
1.332 - }
1.333 -
1.334 - parseUrl()
1.335 -}