diff options
author | XhmikosR <xhmikosr@gmail.com> | 2017-12-16 15:00:38 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@gmail.com> | 2018-01-11 19:48:46 +0300 |
commit | 80d0943b95984bfaf4997d2198d467876d294bd8 (patch) | |
tree | fa2eb4c869753b6e20c771a928da460587f38fdf /js/src/tooltip.js | |
parent | 6d336502c7e26c4cc5b35f1d7a19c067b774cb1f (diff) |
Comply to the new rules.
Diffstat (limited to 'js/src/tooltip.js')
-rw-r--r-- | js/src/tooltip.js | 87 |
1 files changed, 36 insertions, 51 deletions
diff --git a/js/src/tooltip.js b/js/src/tooltip.js index c26cdc387e..403f7e5b16 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -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 |