aboutsummaryrefslogtreecommitdiff
path: root/docs/assets/js/src
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2014-08-02 18:30:59 -0700
committerMark Otto <[email protected]>2014-08-02 18:30:59 -0700
commit089d434895fbe901d838e4dfb29cdb5941c47ab6 (patch)
treedac25fa32c4420bfb3b1199c61898f04b71eaebe /docs/assets/js/src
parentf200c39657c5011e12bace716c59b2242d48c077 (diff)
parent033f1654b07f7764a54e5b290e5cf36f688b95a3 (diff)
downloadbootstrap-089d434895fbe901d838e4dfb29cdb5941c47ab6.tar.xz
bootstrap-089d434895fbe901d838e4dfb29cdb5941c47ab6.zip
Merge branch 'master' into derp
Conflicts: _config.yml dist/css/bootstrap-theme.css.map dist/css/bootstrap.css dist/css/bootstrap.css.map dist/css/bootstrap.min.css docs/_includes/components/glyphicons.html docs/_includes/css/forms.html docs/_includes/css/tables.html docs/_includes/getting-started/browser-device-support.html docs/_includes/header.html docs/_includes/js/affix.html docs/_includes/js/alerts.html docs/_includes/js/buttons.html docs/_includes/js/dropdowns.html docs/_includes/js/overview.html docs/_includes/js/popovers.html docs/_includes/js/tooltips.html docs/_includes/nav/javascript.html docs/assets/css/docs.min.css docs/assets/css/src/docs.css docs/assets/js/customize.min.js docs/assets/js/docs.min.js docs/assets/js/raw-files.min.js docs/browser-bugs.html docs/dist/css/bootstrap-theme.css.map docs/dist/css/bootstrap.css docs/dist/css/bootstrap.css.map docs/dist/css/bootstrap.min.css docs/examples/blog/index.html docs/examples/carousel/index.html docs/examples/cover/index.html docs/examples/dashboard/index.html docs/examples/grid/index.html docs/examples/jumbotron-narrow/index.html docs/examples/jumbotron/index.html docs/examples/justified-nav/index.html docs/examples/navbar-fixed-top/index.html docs/examples/navbar-static-top/index.html docs/examples/navbar/index.html docs/examples/non-responsive/index.html docs/examples/offcanvas/index.html docs/examples/signin/index.html docs/examples/starter-template/index.html docs/examples/sticky-footer-navbar/index.html docs/examples/sticky-footer/index.html docs/examples/theme/index.html docs/examples/tooltip-viewport/index.html less/code.less less/panels.less less/variables.less
Diffstat (limited to 'docs/assets/js/src')
-rw-r--r--docs/assets/js/src/application.js3
-rw-r--r--docs/assets/js/src/customizer.js100
2 files changed, 85 insertions, 18 deletions
diff --git a/docs/assets/js/src/application.js b/docs/assets/js/src/application.js
index 214857243..5d07489e8 100644
--- a/docs/assets/js/src/application.js
+++ b/docs/assets/js/src/application.js
@@ -73,9 +73,8 @@
$('.tooltip-test').tooltip()
$('.popover-test').popover()
- // Default & dismissible popover demos
+ // Popover demos
$('.bs-docs-popover').popover()
- $('.bs-docs-popover-dismiss').popover({ trigger: 'focus' })
// Button state demo
$('#loading-example-btn').click(function () {
diff --git a/docs/assets/js/src/customizer.js b/docs/assets/js/src/customizer.js
index c3a212f2c..7340f1668 100644
--- a/docs/assets/js/src/customizer.js
+++ b/docs/assets/js/src/customizer.js
@@ -16,6 +16,9 @@ window.onload = function () { // wait for load in a dumb way because B-0
' * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\n' +
' */\n\n'
+ var supportsFile = (window.File && window.FileReader && window.FileList && window.Blob)
+ var importDropTarget = $('#import-drop-target')
+
function showError(msg, err) {
$('<div id="bsCustomizerAlert" class="bs-customizer-alert">' +
'<div class="container">' +
@@ -46,6 +49,11 @@ window.onload = function () { // wait for load in a dumb way because B-0
}
}
+ function showAlert(type, msg, insertAfter) {
+ $('<div class="alert alert-' + type + '">' + msg + '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button></div>')
+ .insertAfter(insertAfter)
+ }
+
function getQueryParam(key) {
key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, '\\$&') // escape RegEx meta chars
var match = location.search.match(new RegExp('[?&]' + key + '=([^&]+)(&|$)'))
@@ -106,6 +114,24 @@ window.onload = function () { // wait for load in a dumb way because B-0
return data
}
+ function updateCustomizerFromJson(data) {
+ 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])
+ }
+ }
+ }
+
function parseUrl() {
var id = getQueryParam('id')
@@ -118,21 +144,7 @@ window.onload = function () { // wait for load in a dumb way because B-0
})
.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])
- }
- }
+ updateCustomizerFromJson(data)
})
.error(function (err) {
showError('Error fetching bootstrap config file', err)
@@ -324,6 +336,61 @@ window.onload = function () { // wait for load in a dumb way because B-0
}
}
+ function removeImportAlerts() {
+ importDropTarget.nextAll('.alert').remove()
+ }
+
+ function handleConfigFileSelect(e) {
+ e.stopPropagation()
+ e.preventDefault()
+
+ var file = (e.originalEvent.hasOwnProperty('dataTransfer')) ? e.originalEvent.dataTransfer.files[0] : e.originalEvent.target.files[0]
+
+ if (!file.type.match('application/json')) {
+ return showAlert('danger', '<strong>Ruh roh.</strong> We can only read <code>.json</code> files. Please try again.', importDropTarget)
+ }
+
+ var reader = new FileReader()
+
+ reader.onload = (function () {
+ return function (e) {
+ var text = e.target.result
+
+ try {
+ var json = JSON.parse(text)
+
+ if (typeof json != 'object') {
+ throw new Error('JSON data from config file is not an object.')
+ }
+
+ updateCustomizerFromJson(json)
+ showAlert('success', '<strong>Woohoo!</strong> Your configuration was successfully uploaded. Tweak your settings, then hit Download.', importDropTarget)
+ } catch (err) {
+ return showAlert('danger', '<strong>Shucks.</strong> We can only read valid <code>.json</code> files. Please try again.', importDropTarget)
+ }
+ }
+ })(file)
+
+ reader.readAsText(file)
+ }
+
+ function handleConfigDragOver(e) {
+ e.stopPropagation()
+ e.preventDefault()
+ e.originalEvent.dataTransfer.dropEffect = 'copy'
+
+ removeImportAlerts()
+ }
+
+ if (supportsFile) {
+ importDropTarget
+ .on('dragover', handleConfigDragOver)
+ .on('drop', handleConfigFileSelect)
+ }
+
+ $('#import-file-select').on('select', handleConfigFileSelect)
+ $('#import-manual-trigger').on('click', removeImportAlerts)
+
var inputsComponent = $('#less-section input')
var inputsPlugin = $('#plugin-section input')
var inputsVariables = $('#less-variables-section input')
@@ -410,7 +477,8 @@ window.onload = function () { // wait for load in a dumb way because B-0
{ type: 'image/svg+xml;charset=utf-8' }
)
var objectUrl = url.createObjectURL(svg);
- if (/^blob:/.exec(objectUrl) === null) {
+
+ if (/^blob:/.exec(objectUrl) === null || !supportsFile) {
// `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.