1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-09-26 21:39:08 +02:00

Comply to the new rules.

This commit is contained in:
XhmikosR
2017-12-16 14:00:38 +02:00
parent 6d336502c7
commit 80d0943b95
32 changed files with 1798 additions and 1760 deletions

View File

@@ -2,7 +2,6 @@ import $ from 'jquery'
import Popper from 'popper.js'
import Util from './util'
/**
* --------------------------------------------------------------------------
* Bootstrap (v4.0.0-beta.3): tooltip.js
@@ -11,7 +10,6 @@ import Util from './util'
*/
const Tooltip = (($) => {
/**
* ------------------------------------------------------------------------
* Constants
@@ -52,9 +50,9 @@ const Tooltip = (($) => {
const Default = {
animation : true,
template : '<div class="tooltip" role="tooltip">'
+ '<div class="arrow"></div>'
+ '<div class="tooltip-inner"></div></div>',
template : '<div class="tooltip" role="tooltip">' +
'<div class="arrow"></div>' +
'<div class="tooltip-inner"></div></div>',
trigger : 'hover focus',
title : '',
delay : 0,
@@ -111,14 +109,13 @@ const Tooltip = (($) => {
*/
class Tooltip {
constructor(element, config) {
/**
* Check for Popper dependency
* Popper - https://popper.js.org
*/
if (typeof Popper === 'undefined') {
throw new Error('Bootstrap tooltips require Popper.js (https://popper.js.org)')
throw new TypeError('Bootstrap tooltips require Popper.js (https://popper.js.org)')
}
// private
@@ -128,17 +125,15 @@ const Tooltip = (($) => {
this._activeTrigger = {}
this._popper = null
// protected
// Protected
this.element = element
this.config = this._getConfig(config)
this.tip = null
this._setListeners()
}
// getters
// Getters
static get VERSION() {
return VERSION
@@ -168,8 +163,7 @@ const Tooltip = (($) => {
return DefaultType
}
// public
// Public
enable() {
this._isEnabled = true
@@ -207,9 +201,7 @@ const Tooltip = (($) => {
} else {
context._leave(null, context)
}
} else {
if ($(this.getTipElement()).hasClass(ClassName.SHOW)) {
this._leave(null, this)
return
@@ -275,9 +267,9 @@ const Tooltip = (($) => {
$(tip).addClass(ClassName.FADE)
}
const placement = typeof this.config.placement === 'function' ?
this.config.placement.call(this, tip, this.element) :
this.config.placement
const placement = typeof this.config.placement === 'function'
? this.config.placement.call(this, tip, this.element)
: this.config.placement
const attachment = this._getAttachment(placement)
this.addAttachmentClass(attachment)
@@ -313,14 +305,14 @@ const Tooltip = (($) => {
this._handlePopperPlacementChange(data)
}
},
onUpdate : (data) => {
onUpdate: (data) => {
this._handlePopperPlacementChange(data)
}
})
$(tip).addClass(ClassName.SHOW)
// if this is a touch-enabled device we add extra
// If this is a touch-enabled device we add extra
// empty mouseover listeners to the body's immediate children;
// only needed because of broken event delegation on iOS
// https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
@@ -355,7 +347,7 @@ const Tooltip = (($) => {
hide(callback) {
const tip = this.getTipElement()
const hideEvent = $.Event(this.constructor.Event.HIDE)
const complete = () => {
const complete = () => {
if (this._hoverState !== HoverState.SHOW && tip.parentNode) {
tip.parentNode.removeChild(tip)
}
@@ -380,7 +372,7 @@ const Tooltip = (($) => {
$(tip).removeClass(ClassName.SHOW)
// if this is a touch-enabled device we remove the extra
// If this is a touch-enabled device we remove the extra
// empty mouseover listeners we added for iOS support
if ('ontouchstart' in document.documentElement) {
$('body').children().off('mouseover', null, $.noop)
@@ -392,17 +384,14 @@ const Tooltip = (($) => {
if (Util.supportsTransitionEnd() &&
$(this.tip).hasClass(ClassName.FADE)) {
$(tip)
.one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(TRANSITION_DURATION)
} else {
complete()
}
this._hoverState = ''
}
update() {
@@ -411,7 +400,7 @@ const Tooltip = (($) => {
}
}
// protected
// Protected
isWithContent() {
return Boolean(this.getTitle())
@@ -435,7 +424,7 @@ const Tooltip = (($) => {
setElementContent($element, content) {
const html = this.config.html
if (typeof content === 'object' && (content.nodeType || content.jquery)) {
// content is a DOM node or a jQuery
// Content is a DOM node or a jQuery
if (html) {
if (!$(content).parent().is($element)) {
$element.empty().append(content)
@@ -452,16 +441,15 @@ const Tooltip = (($) => {
let title = this.element.getAttribute('data-original-title')
if (!title) {
title = typeof this.config.title === 'function' ?
this.config.title.call(this.element) :
this.config.title
title = typeof this.config.title === 'function'
? this.config.title.call(this.element)
: this.config.title
}
return title
}
// private
// Private
_getAttachment(placement) {
return AttachmentMap[placement.toUpperCase()]
@@ -477,14 +465,13 @@ const Tooltip = (($) => {
this.config.selector,
(event) => this.toggle(event)
)
} else if (trigger !== Trigger.MANUAL) {
const eventIn = trigger === Trigger.HOVER ?
this.constructor.Event.MOUSEENTER :
this.constructor.Event.FOCUSIN
const eventOut = trigger === Trigger.HOVER ?
this.constructor.Event.MOUSELEAVE :
this.constructor.Event.FOCUSOUT
const eventIn = trigger === Trigger.HOVER
? this.constructor.Event.MOUSEENTER
: this.constructor.Event.FOCUSIN
const eventOut = trigger === Trigger.HOVER
? this.constructor.Event.MOUSELEAVE
: this.constructor.Event.FOCUSOUT
$(this.element)
.on(
@@ -508,8 +495,8 @@ const Tooltip = (($) => {
if (this.config.selector) {
this.config = {
...this.config,
trigger : 'manual',
selector : ''
trigger: 'manual',
selector: ''
}
} else {
this._fixTitle()
@@ -627,8 +614,8 @@ const Tooltip = (($) => {
if (typeof config.delay === 'number') {
config.delay = {
show : config.delay,
hide : config.delay
show: config.delay,
hide: config.delay
}
}
@@ -677,7 +664,7 @@ const Tooltip = (($) => {
}
_fixTransition() {
const tip = this.getTipElement()
const tip = this.getTipElement()
const initConfigAnimation = this.config.animation
if (tip.getAttribute('x-placement') !== null) {
return
@@ -689,11 +676,11 @@ const Tooltip = (($) => {
this.config.animation = initConfigAnimation
}
// static
// Static
static _jQueryInterface(config) {
return this.each(function () {
let data = $(this).data(DATA_KEY)
let data = $(this).data(DATA_KEY)
const _config = typeof config === 'object' && config
if (!data && /dispose|hide/.test(config)) {
@@ -707,7 +694,7 @@ const Tooltip = (($) => {
if (typeof config === 'string') {
if (typeof data[config] === 'undefined') {
throw new Error(`No method named "${config}"`)
throw new TypeError(`No method named "${config}"`)
}
data[config]()
}
@@ -715,22 +702,20 @@ const Tooltip = (($) => {
}
}
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
*/
$.fn[NAME] = Tooltip._jQueryInterface
$.fn[NAME] = Tooltip._jQueryInterface
$.fn[NAME].Constructor = Tooltip
$.fn[NAME].noConflict = function () {
$.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT
return Tooltip._jQueryInterface
}
return Tooltip
})($, Popper)
export default Tooltip