aboutsummaryrefslogtreecommitdiff
path: root/js/util.js
diff options
context:
space:
mode:
authorF A T <[email protected]>2015-02-11 11:36:16 -0800
committerF A T <[email protected]>2015-02-11 11:36:16 -0800
commitf483640378c8dfe7fd41f7743dc43d8ad0ea8b1b (patch)
tree19bfdadb0c140df437e7b7034e5e1f5ce58343cc /js/util.js
parentaed1cd31218113d67d2eca3296edf5d1700b19b8 (diff)
parent834220ea20ce5b7cd31edfb624a28b4bf8b29a6a (diff)
downloadbootstrap-f483640378c8dfe7fd41f7743dc43d8ad0ea8b1b.tar.xz
bootstrap-f483640378c8dfe7fd41f7743dc43d8ad0ea8b1b.zip
Merge pull request #57 from twbs/fat-closure
Bootstrap onto closure v2
Diffstat (limited to 'js/util.js')
-rw-r--r--js/util.js165
1 files changed, 165 insertions, 0 deletions
diff --git a/js/util.js b/js/util.js
new file mode 100644
index 000000000..294a5a960
--- /dev/null
+++ b/js/util.js
@@ -0,0 +1,165 @@
+/** =======================================================================
+ * Bootstrap: util.js v4.0.0
+ * http://getbootstrap.com/javascript/#alerts
+ * ========================================================================
+ * Copyright 2011-2015 Twitter, Inc.
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
+ * ========================================================================
+ * @fileoverview - Bootstrap's private util helper. Adds private util
+ * helpers for things like accesibility and transitions. These methods are
+ * shared across all bootstrap plugins.
+ * ========================================================================
+ */
+
+'use strict';
+
+
+/**
+ * @type {Object}
+ */
+var Bootstrap = {}
+
+
+/**
+ * @const
+ * @type {string}
+ */
+Bootstrap.TRANSITION_END = 'bsTransitionEnd'
+
+
+/**
+ * @const
+ * @type {Object}
+ */
+Bootstrap.TransitionEndEvent = {
+ 'WebkitTransition' : 'webkitTransitionEnd',
+ 'MozTransition' : 'transitionend',
+ 'OTransition' : 'oTransitionEnd otransitionend',
+ 'transition' : 'transitionend'
+}
+
+
+/**
+ * @param {Function} childConstructor
+ * @param {Function} parentConstructor
+ */
+Bootstrap.inherits = function(childConstructor, parentConstructor) {
+ /** @constructor */
+ function tempConstructor() {}
+ tempConstructor.prototype = parentConstructor.prototype
+ childConstructor.prototype = new tempConstructor()
+ /** @override */
+ childConstructor.prototype.constructor = childConstructor
+}
+
+
+/**
+ * @param {Element} element
+ * @return {string|null}
+ */
+Bootstrap.getSelectorFromElement = function (element) {
+ var selector = element.getAttribute('data-target')
+
+ if (!selector) {
+ selector = element.getAttribute('href') || ''
+ selector = /^#[a-z]/i.test(selector) ? selector : null
+ }
+
+ return selector
+}
+
+
+/**
+ * @param {string} prefix
+ * @return {string}
+ */
+Bootstrap.getUID = function (prefix) {
+ do prefix += ~~(Math.random() * 1000000)
+ while (document.getElementById(prefix))
+ return prefix
+}
+
+
+/**
+ * @return {Object}
+ */
+Bootstrap.getSpecialTransitionEndEvent = function () {
+ return {
+ bindType: Bootstrap.transition.end,
+ delegateType: Bootstrap.transition.end,
+ handle: /** @param {jQuery.Event} event */ (function (event) {
+ if ($(event.target).is(this)) {
+ return event.handleObj.handler.apply(this, arguments)
+ }
+ })
+ }
+}
+
+
+/**
+ * @param {Element} element
+ */
+Bootstrap.reflow = function (element) {
+ new Function('bs',"return bs")(element.offsetHeight)
+}
+
+
+/**
+ * @return {Object|boolean}
+ */
+Bootstrap.transitionEndTest = function () {
+ if (window['QUnit']) {
+ return false
+ }
+
+ var el = document.createElement('bootstrap')
+ for (var name in Bootstrap.TransitionEndEvent) {
+ if (el.style[name] !== undefined) {
+ return { end: Bootstrap.TransitionEndEvent[name] }
+ }
+ }
+ return false
+}
+
+
+/**
+ * @param {number} duration
+ * @this {Element}
+ * @return {Object}
+ */
+Bootstrap.transitionEndEmulator = function (duration) {
+ var called = false
+
+ $(this).one(Bootstrap.TRANSITION_END, function () {
+ called = true
+ })
+
+ var callback = function () {
+ if (!called) {
+ $(this).trigger(Bootstrap.transition.end)
+ }
+ }.bind(this)
+
+ setTimeout(callback, duration)
+
+ return this
+}
+
+
+/**
+ * ------------------------------------------------------------------------
+ * jQuery Interface
+ * ------------------------------------------------------------------------
+ */
+
+$.fn.emulateTransitionEnd = Bootstrap.transitionEndEmulator
+
+$(function () {
+ Bootstrap.transition = Bootstrap.transitionEndTest()
+
+ if (!Bootstrap.transition) {
+ return
+ }
+
+ $.event.special[Bootstrap.TRANSITION_END] = Bootstrap.getSpecialTransitionEndEvent()
+})