简体   繁体   中英

Bootstrap Tooltip / Popover Dismissal Causing HTML element to be hidden

For some reason in one of my projects the following Bootstrap.js Tooltip/Popover code in the Tooltip.prototype.leave function is causing my icon to disappear (be set to display: none) upon dismissing the tip/popover.

if (!self.options.delay || !self.options.delay.hide) return self.hide()

self.timeout = setTimeout(function () {
    if (self.hoverState == 'out') self.hide()
}, self.options.delay.hide)

I'm implementing the popover as recommended:

<script type="text/javascript" charset="utf-8">
    $j(document).ready(function() {
        console.log($j('.help-popover'));
        $j('.help-popover').popover({
            placement: 'top'
        });
    });
</script>

<a tabindex="0" class="help-popover glyphicon glyphicon-question-sign" role="button" data-toggle="popover" data-trigger="focus" title="Help" data-content="Lorem ipsum dolor sit amet consetetur sadipscing elitr sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat sed."></a>

Some guesses I have as to the cause are that its related to the project also needing to use an old copy of Prototype.js and therefore also using js_noconflict.js, This is why in the html sample above you see the $j syntax representing jQuery.

I've already attempted replacing all $ calls to $j calls in a local copy of the bootstrap.js without fixing the issue. Any help to resolve this would be much appreciated.

Replace Bootstrap.js line 1404 as below

//if (obj instanceof $.Event) {
    //  self.inState[obj.type == 'focusout' ? 'focus' : 'hover'] = false
    //}

To

//09-04-2016 Jay Bhavsar Changed condition if it is hover out then set instate as true
    //if (obj instanceof $.Event) {
    //  self.inState[obj.type == 'focusout' ? 'focus' : 'hover'] = false
    //}
    if (obj instanceof $.Event) {
        if (obj.type == 'focusout') {
            self.inState['focus'] = false;
        }
        else {
            self.inState['hover'] = true;
        }
    }

Basically it was setting "inState" to "false" so when hover out happened it was continuing on other code instead of returning. the continuing code was to set tooltip hide.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM