1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-30 16:50:00 +02:00

popover passing as well

This commit is contained in:
fat
2015-05-12 14:28:11 -07:00
parent 3452e8dc83
commit a58febf71a
19 changed files with 728 additions and 1032 deletions

189
js/dist/popover.js vendored Normal file
View File

@@ -0,0 +1,189 @@
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0): popover.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var Popover = (function ($) {
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
var NAME = 'popover';
var VERSION = '4.0.0';
var DATA_KEY = 'bs.popover';
var JQUERY_NO_CONFLICT = $.fn[NAME];
var Default = $.extend({}, Tooltip.Default, {
placement: 'right',
trigger: 'click',
content: '',
template: '<div class="popover" role="tooltip">' + '<div class="popover-arrow"></div>' + '<h3 class="popover-title"></h3>' + '<div class="popover-content"></div></div>'
});
var ClassName = {
FADE: 'fade',
IN: 'in'
};
var Selector = {
TITLE: '.popover-title',
CONTENT: '.popover-content',
ARROW: '.popover-arrow'
};
var Event = {
HIDE: 'hide.bs.popover',
HIDDEN: 'hidden.bs.popover',
SHOW: 'show.bs.popover',
SHOWN: 'shown.bs.popover',
INSERTED: 'inserted.bs.popover',
CLICK: 'click.bs.popover',
FOCUSIN: 'focusin.bs.popover',
FOCUSOUT: 'focusout.bs.popover',
MOUSEENTER: 'mouseenter.bs.popover',
MOUSELEAVE: 'mouseleave.bs.popover'
};
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
var Popover = (function (_Tooltip) {
function Popover() {
_classCallCheck(this, Popover);
if (_Tooltip != null) {
_Tooltip.apply(this, arguments);
}
}
_inherits(Popover, _Tooltip);
_createClass(Popover, [{
key: 'isWithContent',
// overrides
value: function isWithContent() {
return this.getTitle() || this._getContent();
}
}, {
key: 'getTipElement',
value: function getTipElement() {
return this.tip = this.tip || $(this.config['template'])[0];
}
}, {
key: 'setContent',
value: function setContent() {
var tip = this.getTipElement();
var title = this.getTitle();
var content = this._getContent();
var titleElement = $(tip).find(Selector.TITLE)[0];
if (titleElement) {
titleElement[this.config.html ? 'innerHTML' : 'innerText'] = title;
}
// we use append for html objects to maintain js events
$(tip).find(Selector.CONTENT).children().detach().end()[this.config.html ? typeof content === 'string' ? 'html' : 'append' : 'text'](content);
$(tip).removeClass(ClassName.FADE).removeClass(ClassName.IN);
this.cleanupTether();
}
}, {
key: '_getContent',
// private
value: function _getContent() {
return this.element.getAttribute('data-content') || (typeof this.config.content == 'function' ? this.config.content.call(this.element) : this.config.content);
}
}], [{
key: 'VERSION',
// getters
get: function () {
return VERSION;
}
}, {
key: 'Default',
get: function () {
return Default;
}
}, {
key: 'NAME',
get: function () {
return NAME;
}
}, {
key: 'DATA_KEY',
get: function () {
return DATA_KEY;
}
}, {
key: 'Event',
get: function () {
return Event;
}
}, {
key: '_jQueryInterface',
// static
value: function _jQueryInterface(config) {
return this.each(function () {
var data = $(this).data(DATA_KEY);
var _config = typeof config === 'object' ? config : null;
if (!data && /destroy|hide/.test(config)) {
return;
}
if (!data) {
data = new Popover(this, _config);
$(this).data(DATA_KEY, data);
}
if (typeof config === 'string') {
data[config]();
}
});
}
}]);
return Popover;
})(Tooltip);
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = Popover._jQueryInterface;
$.fn[NAME].Constructor = Popover;
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT;
return Popover._jQueryInterface;
};
return Popover;
})(jQuery);
//# sourceMappingURL=popover.js.map

1
js/dist/popover.js.map vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -57,7 +57,7 @@ var ScrollSpy = (function ($) {
_classCallCheck(this, ScrollSpy);
this._scrollElement = element.tagName === 'BODY' ? window : element;
this._config = $.extend({}, Defaults, config);
this._config = $.extend({}, Default, config);
this._selector = '' + (this._config.target || '') + ' .nav li > a';
this._offsets = [];
this._targets = [];

File diff suppressed because one or more lines are too long

221
js/dist/tooltip.js vendored
View File

@@ -6,12 +6,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0): alert.js
* Bootstrap (v4.0.0): tooltip.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* --------------------------------------------------------------------------
*/
var ToolTip = (function ($) {
var Tooltip = (function ($) {
/**
* ------------------------------------------------------------------------
@@ -34,33 +34,16 @@ var ToolTip = (function ($) {
delay: 0,
html: false,
selector: false,
attachment: 'top',
placement: 'top',
offset: '0 0',
constraints: null
};
var HorizontalMirror = {
LEFT: 'right',
CENTER: 'center',
RIGHT: 'left'
};
var VerticalMirror = {
TOP: 'bottom',
MIDDLE: 'middle',
BOTTOM: 'top'
};
var VerticalDefault = {
LEFT: 'middle',
CENTER: 'bottom',
RIGHT: 'middle'
};
var HorizontalDefault = {
TOP: 'center',
MIDDLE: 'left',
BOTTOM: 'center'
var AttachmentMap = {
TOP: 'bottom center',
RIGHT: 'middle left',
BOTTOM: 'top center',
LEFT: 'middle right'
};
var HoverState = {
@@ -88,13 +71,18 @@ var ToolTip = (function ($) {
var Selector = {
TOOLTIP: '.tooltip',
TOOLTIP_INNER: '.tooltip-inner',
TOOLTIP_ARROW: '.tooltip-arrow'
};
TOOLTIP_INNER: '.tooltip-inner' };
var TetherClass = {
'element': false,
'enabled': false
element: false,
enabled: false
};
var Trigger = {
HOVER: 'hover',
FOCUS: 'focus',
CLICK: 'click',
MANUAL: 'manual'
};
/**
@@ -112,12 +100,12 @@ var ToolTip = (function ($) {
this._timeout = 0;
this._hoverState = '';
this._activeTrigger = {};
this._tether = null;
// protected
this.element = element;
this.config = this._getConfig(config);
this.tip = null;
this.tether = null;
this._setListeners();
}
@@ -144,13 +132,14 @@ var ToolTip = (function ($) {
key: 'toggle',
value: function toggle(event) {
var context = this;
var dataKey = this.constructor.DATA_KEY;
if (event) {
context = $(event.currentTarget).data(DATA_KEY);
context = $(event.currentTarget).data(dataKey);
if (!context) {
context = new this.constructor(event.currentTarget, this._getDelegateConfig());
$(event.currentTarget).data(DATA_KEY, context);
$(event.currentTarget).data(dataKey, context);
}
context._activeTrigger.click = !context._activeTrigger.click;
@@ -171,7 +160,13 @@ var ToolTip = (function ($) {
clearTimeout(this._timeout);
this.hide(function () {
$(_this.element).off(Selector.TOOLTIP).removeData(DATA_KEY);
$(_this.element).off('.' + _this.constructor.NAME).removeData(_this.constructor.DATA_KEY);
if (_this.tip) {
$(_this.tip).detach();
}
_this.tip = null;
});
}
}, {
@@ -179,7 +174,7 @@ var ToolTip = (function ($) {
value: function show() {
var _this2 = this;
var showEvent = $.Event(Event.SHOW);
var showEvent = $.Event(this.constructor.Event.SHOW);
if (this.isWithContent() && this._isEnabled) {
$(this.element).trigger(showEvent);
@@ -191,7 +186,7 @@ var ToolTip = (function ($) {
}
var tip = this.getTipElement();
var tipId = Util.getUID(NAME);
var tipId = Util.getUID(this.constructor.NAME);
tip.setAttribute('id', tipId);
this.element.setAttribute('aria-describedby', tipId);
@@ -202,17 +197,16 @@ var ToolTip = (function ($) {
$(tip).addClass(ClassName.FADE);
}
var attachment = typeof this.config.attachment === 'function' ? this.config.attachment.call(this, tip, this.element) : this.config.attachment;
var placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this.element) : this.config.placement;
attachment = this.getAttachment(attachment);
var attachment = this._getAttachment(placement);
$(tip).data(DATA_KEY, this);
$(tip).data(this.constructor.DATA_KEY, this).appendTo(document.body);
this.element.parentNode.insertBefore(tip, this.element.nextSibling);
$(this.element).trigger(Event.INSERTED);
$(this.element).trigger(this.constructor.Event.INSERTED);
this.tether = new Tether({
element: this.tip,
this._tether = new Tether({
element: tip,
target: this.element,
attachment: attachment,
classes: TetherClass,
@@ -222,7 +216,7 @@ var ToolTip = (function ($) {
});
Util.reflow(tip);
this.tether.position();
this._tether.position();
$(tip).addClass(ClassName.IN);
@@ -230,7 +224,7 @@ var ToolTip = (function ($) {
var prevHoverState = _this2._hoverState;
_this2._hoverState = null;
$(_this2.element).trigger(Event.SHOWN);
$(_this2.element).trigger(_this2.constructor.Event.SHOWN);
if (prevHoverState === HoverState.OUT) {
_this2._leave(null, _this2);
@@ -246,14 +240,14 @@ var ToolTip = (function ($) {
var _this3 = this;
var tip = this.getTipElement();
var hideEvent = $.Event(Event.HIDE);
var hideEvent = $.Event(this.constructor.Event.HIDE);
var complete = function complete() {
if (_this3._hoverState !== HoverState.IN && tip.parentNode) {
tip.parentNode.removeChild(tip);
}
_this3.element.removeAttribute('aria-describedby');
$(_this3.element).trigger(Event.HIDDEN);
$(_this3.element).trigger(_this3.constructor.Event.HIDDEN);
_this3.cleanupTether();
if (callback) {
@@ -291,63 +285,6 @@ var ToolTip = (function ($) {
value: function getTipElement() {
return this.tip = this.tip || $(this.config.template)[0];
}
}, {
key: 'getAttachment',
value: function getAttachment(attachmentString) {
var attachmentArray = attachmentString.split(' ');
var normalizedAttachment = {};
if (!attachmentArray.length) {
throw new Error('Tooltip requires attachment');
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = attachmentArray[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var attachment = _step.value;
attachment = attachment.toUpperCase();
if (HorizontalMirror[attachment]) {
normalizedAttachment.horizontal = HorizontalMirror[attachment];
}
if (VerticalMirror[attachment]) {
normalizedAttachment.vertical = VerticalMirror[attachment];
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
if (!normalizedAttachment.horizontal && !normalizedAttachment.vertical) {
throw new Error('Tooltip requires valid attachment');
}
if (!normalizedAttachment.horizontal) {
normalizedAttachment.horizontal = HorizontalDefault[normalizedAttachment.vertical.toUpperCase()];
}
if (!normalizedAttachment.vertical) {
normalizedAttachment.vertical = VerticalDefault[normalizedAttachment.horizontal.toUpperCase()];
}
return [normalizedAttachment.vertical, normalizedAttachment.horizontal].join(' ');
}
}, {
key: 'setContent',
value: function setContent() {
@@ -372,29 +309,29 @@ var ToolTip = (function ($) {
return title;
}
}, {
key: 'removeTetherClasses',
value: function removeTetherClasses(i, css) {
return ((css.baseVal || css).match(new RegExp('(^|\\s)' + CLASS_PREFIX + '-\\S+', 'g')) || []).join(' ');
}
}, {
key: 'cleanupTether',
value: function cleanupTether() {
if (this.tether) {
this.tether.destroy();
if (this._tether) {
this._tether.destroy();
// clean up after tether's junk classes
// remove after they fix issue
// (https://github.com/HubSpot/tether/issues/36)
$(this.element).removeClass(this.removeTetherClasses);
$(this.tip).removeClass(this.removeTetherClasses);
$(this.element).removeClass(this._removeTetherClasses);
$(this.tip).removeClass(this._removeTetherClasses);
}
}
}, {
key: '_setListeners',
key: '_getAttachment',
// private
value: function _getAttachment(placement) {
return AttachmentMap[placement.toUpperCase()];
}
}, {
key: '_setListeners',
value: function _setListeners() {
var _this4 = this;
@@ -402,10 +339,10 @@ var ToolTip = (function ($) {
triggers.forEach(function (trigger) {
if (trigger === 'click') {
$(_this4.element).on(Event.CLICK, _this4.config.selector, _this4.toggle.bind(_this4));
} else if (trigger !== 'manual') {
var eventIn = trigger == 'hover' ? Event.MOUSEENTER : Event.FOCUSIN;
var eventOut = trigger == 'hover' ? Event.MOUSELEAVE : Event.FOCUSOUT;
$(_this4.element).on(_this4.constructor.Event.CLICK, _this4.config.selector, _this4.toggle.bind(_this4));
} else if (trigger !== Trigger.MANUAL) {
var eventIn = trigger == Trigger.HOVER ? _this4.constructor.Event.MOUSEENTER : _this4.constructor.Event.FOCUSIN;
var eventOut = trigger == Trigger.HOVER ? _this4.constructor.Event.MOUSELEAVE : _this4.constructor.Event.FOCUSOUT;
$(_this4.element).on(eventIn, _this4.config.selector, _this4._enter.bind(_this4)).on(eventOut, _this4.config.selector, _this4._leave.bind(_this4));
}
@@ -420,6 +357,11 @@ var ToolTip = (function ($) {
this._fixTitle();
}
}
}, {
key: '_removeTetherClasses',
value: function _removeTetherClasses(i, css) {
return ((css.baseVal || css).match(new RegExp('(^|\\s)' + CLASS_PREFIX + '-\\S+', 'g')) || []).join(' ');
}
}, {
key: '_fixTitle',
value: function _fixTitle() {
@@ -432,19 +374,21 @@ var ToolTip = (function ($) {
}, {
key: '_enter',
value: function _enter(event, context) {
context = context || $(event.currentTarget).data(DATA_KEY);
var dataKey = this.constructor.DATA_KEY;
context = context || $(event.currentTarget).data(dataKey);
if (!context) {
context = new this.constructor(event.currentTarget, this._getDelegateConfig());
$(event.currentTarget).data(DATA_KEY, context);
$(event.currentTarget).data(dataKey, context);
}
if (event) {
context._activeTrigger[event.type == 'focusin' ? 'focus' : 'hover'] = true;
context._activeTrigger[event.type == 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
}
if ($(context.getTipElement()).hasClass('in') || context._hoverState === 'in') {
context._hoverState = 'in';
if ($(context.getTipElement()).hasClass(ClassName.IN) || context._hoverState === HoverState.IN) {
context._hoverState = HoverState.IN;
return;
}
@@ -466,15 +410,17 @@ var ToolTip = (function ($) {
}, {
key: '_leave',
value: function _leave(event, context) {
context = context || $(event.currentTarget).data(DATA_KEY);
var dataKey = this.constructor.DATA_KEY;
context = context || $(event.currentTarget).data(dataKey);
if (!context) {
context = new this.constructor(event.currentTarget, this._getDelegateConfig());
$(event.currentTarget).data(DATA_KEY, context);
$(event.currentTarget).data(dataKey, context);
}
if (event) {
context._activeTrigger[event.type == 'focusout' ? 'focus' : 'hover'] = false;
context._activeTrigger[event.type == 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false;
}
if (context._isWithActiveTrigger()) {
@@ -510,12 +456,12 @@ var ToolTip = (function ($) {
}, {
key: '_getConfig',
value: function _getConfig(config) {
config = $.extend({}, Default, $(this.element).data(), config);
config = $.extend({}, this.constructor.Default, $(this.element).data(), config);
if (config.delay && typeof config.delay === 'number') {
config.delay = {
'show': config.delay,
'hide': config.delay
show: config.delay,
hide: config.delay
};
}
@@ -529,7 +475,7 @@ var ToolTip = (function ($) {
if (this.config) {
for (var key in this.config) {
var value = this.config[key];
if (Default[key] !== value) {
if (this.constructor.Default[key] !== value) {
config[key] = value;
}
}
@@ -550,6 +496,21 @@ var ToolTip = (function ($) {
get: function () {
return Default;
}
}, {
key: 'NAME',
get: function () {
return NAME;
}
}, {
key: 'DATA_KEY',
get: function () {
return DATA_KEY;
}
}, {
key: 'Event',
get: function () {
return Event;
}
}, {
key: '_jQueryInterface',

File diff suppressed because one or more lines are too long