add logging

This commit is contained in:
fat 2013-08-17 19:04:41 -07:00
parent a39cb4be90
commit 00d2986858
2 changed files with 21 additions and 19 deletions

View File

@ -1,6 +1,17 @@
window.onload = function () { // wait for load in a dumb way because B-0 window.onload = function () { // wait for load in a dumb way because B-0
var cw = '/*!\n * Bootstrap v3.0.0-rc.2\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.0-rc.2\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'
function showError (msg, err) {
$('<div id="bsCustomizerAlert" class="bs-customizer-alert">\
<div class="container">\
<a href="#bsCustomizerAlert" data-dismiss="alert" class="close pull-right">&times;</a>\
<p class="bs-customizer-alert-text">' + msg + '</p>' +
(err.extract ? '<pre class="bs-customizer-alert-extract">' + err.extract.join('\n') + '</pre>' : '') + '\
</div>\
</div>').appendTo('body').alert()
throw err
}
function getQueryParam(key) { function getQueryParam(key) {
key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars
var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)")); var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)"));
@ -23,11 +34,11 @@ window.onload = function () { // wait for load in a dumb way because B-0
dataType: 'json', dataType: 'json',
data: JSON.stringify(data) data: JSON.stringify(data)
}) })
.success( function(e) { .success(function(err) {
history.replaceState(false, document.title, window.location.origin + window.location.pathname + '?id=' + e.id) history.replaceState(false, document.title, window.location.origin + window.location.pathname + '?id=' + e.id)
}) })
.error( function(e) { .error(function(err) {
console.warn("gist save error", e); showError('<strong>Error</strong> Could not save gist file, configuration not saved.', err)
}) })
} }
@ -78,13 +89,13 @@ window.onload = function () { // wait for load in a dumb way because B-0
} }
} }
}) })
.error(function(result) { .error(function(err) {
console.warn("gist save error", e) showError('Error fetching bootstrap config file', err)
}) })
} }
function generateZip(css, js, complete) { function generateZip(css, js, complete) {
if (!css && !js) return console.warn('you want to build nothing… o_O') if (!css && !js) return showError('<strong>Error</strong> No Bootstrap files selected.', new Error('no Bootstrap'))
var zip = new JSZip() var zip = new JSZip()
@ -149,15 +160,16 @@ window.onload = function () { // wait for load in a dumb way because B-0
, optimization: 0 , optimization: 0
, filename: 'bootstrap.css' , filename: 'bootstrap.css'
}).parse(css, function (err, tree) { }).parse(css, function (err, tree) {
if (err) return console.warn(err) if (err) {
return showError('<strong>Error</strong> Could not parse less files.', err)
}
result = { result = {
'bootstrap.css' : cw + tree.toCSS(), 'bootstrap.css' : cw + tree.toCSS(),
'bootstrap.min.css' : cw + tree.toCSS({ compress: true }) 'bootstrap.min.css' : cw + tree.toCSS({ compress: true })
} }
}) })
} catch (err) { } catch (err) {
return console.warn(err) return showError('<strong>Error</strong> Could not parse less files.', err)
} }
return result return result

View File

@ -6,16 +6,6 @@ lead: Customize Bootstrap's components, LESS variables, and jQuery plugins to ge
base_url: "../" base_url: "../"
--- ---
<!-- Customizer errors -->
<div class="bs-customizer-alert" style="display: none;">
<div class="container">
<button type="button" class="close pull-right">&times;</button>
<p class="bs-customizer-alert-text"></p>
</div>
</div>
<!-- Customizer form --> <!-- Customizer form -->
<form class="bs-customizer" role="form"> <form class="bs-customizer" role="form">
<div class="bs-docs-section" id="less-section"> <div class="bs-docs-section" id="less-section">