Is there a way to close Angular UI tooltip by clicking it?

To get this opportunity, I have an advanced tool tip.

function customTooltip($document, $tooltip) {
    var tooltip = $tooltip('customTooltip', 'customTooltip', 'click'),
        parentCompile = angular.copy(tooltip.compile);

    tooltip.compile = function (element, attrs) {
        var parentLink = parentCompile(element, attrs);

        return function postLink(scope, element, attrs) {
            var firstTime = true;

            parentLink(scope, element, attrs);

            var onDocumentClick = function () {
                if (firstTime) {
                    firstTime = false;
                } else {
                    element.triggerHandler('documentClick');
                }
            };

            var bindDocumentClick = function () {
                $document.on('click', onDocumentClick);
            };

            var unbindDocumentClick = function () {
                $document.off('click', onDocumentClick);
            };

            scope.$watch('tt_isOpen', function (newValue) {
                firstTime = true;

                if (newValue) {
                    bindDocumentClick();
                } else {
                    unbindDocumentClick();
                }
            });

            scope.$on('$destroy', function onTooltipDestroy() {
                unbindDocumentClick();
            });
        };
    };

    return tooltip;
}

But this approach does not work already because now there is no tt_isOpen property in scope. In fact, I don't see any tooltip properties just for my parent area. I assume this was due to changes to tooltip.js 124 line https://github.com/angular-ui/bootstrap/blob/master/src/tooltip/tooltip.js#L124 . Is there a way to close the tooltip by clicking on it, or at least get the isOpen flag?

+4
source share
3

pull, outsideClick . angular -ui 1.0.0, , , . , tooltip-trigger="outsideClick" .

+1

open pull . , , - , , :

        attrs.$observe( 'disabled', function ( val ) {
          if (val && ttScope.isOpen ) {
            hide();
          }
        });
0

angular 1.3.15 angular -ui 0.13

function customTooltip($document, $tooltip) {
    var tooltip = $tooltip('customTooltip', 'customTooltip', 'click'),
        parentCompile = angular.copy(tooltip.compile);

    tooltip.compile = function (element, attrs) {

        var parentLink = parentCompile(element, attrs);

        return function postLink(scope, element, attrs) {

            parentLink(scope, element, attrs);

            var isOpened = false;

            element.bind('click', function () {
                bindDocumentClick();
            });

            var onDocumentClick = function () {
                if (!isOpened) {
                    isOpened = true;
                } else {
                    element.triggerHandler('documentClick');
                    unbindDocumentClick();
                    isOpened = false;
                }
            };

            var bindDocumentClick = function () {
                $document.on('click', onDocumentClick);
            };

            var unbindDocumentClick = function () {
                $document.off('click', onDocumentClick);
            };

            scope.$on('$destroy', function onTooltipDestroy() {
                unbindDocumentClick();
            });
        };
    };

    return tooltip;
}
0

All Articles