diff --git a/awx/ui/static/lib/ansible/directives.js b/awx/ui/static/lib/ansible/directives.js index 3a811e8442..4b1abf2845 100644 --- a/awx/ui/static/lib/ansible/directives.js +++ b/awx/ui/static/lib/ansible/directives.js @@ -489,8 +489,7 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job container = (attrs.container !== undefined) ? attrs.container : false, trigger = (attrs.trigger !== undefined) ? attrs.trigger : 'manual', template = '', - id_to_close = "", - body_click_count; + id_to_close = ""; if (element[0].id) { template = ''; @@ -522,7 +521,32 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job }); } $(element).attr('tabindex',-1); - $(element).click(function() { + + $(element).one('click', showPopover); + + $(element).on('shown.bs.popover', function() { + $('body').one('click.popover' + id_to_close, function(e) { + if ($(e.target).parents(id_to_close).length === 0) { + $(element).popover('hide'); + } + }); + + $(document).on('keydown.popover', dismissOnEsc); + + }); + + $(element).on('hidden.bs.popover', function() { + $(element).off('click', dismissPopover); + $(element).off('click', showPopover); + $('body').off('click.popover.' + id_to_close); + $(element).one('click', showPopover); + $(document).off('keydown.popover', dismissOnEsc); + }); + + function showPopover(e) { + console.log(element); + e.stopPropagation(); + var self = $(this); // remove tool-tip @@ -545,6 +569,7 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job } } }); + $('.popover').each(function() { // remove lingering popover
. Seems to be a bug in TB3 RC1 $(this).remove(); @@ -557,50 +582,30 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job // set id_to_close of the actual open element id_to_close = "#" + $(element).attr('id') + "_popover_container"; - // set the number of times the body has been clicked since the popover has been opened - body_click_count = 0; - - if ($._data(document.body, "events")) { - // in the case that the popOver is retriggered (ie: you click the question mark - // again for that popover. tread this as a toggle and do not bind another - // click event. - // PROBLEM NOTE: if things are bound to the body this might break. - $('body').off('click'); - } else { - $('body').on('click', function(e) { - if ($(e.target).parents(id_to_close).length === 0) { - // if you click outside the popover - // increment the body click counter - body_click_count++; - if (body_click_count === 2) { - // if that counter was incremented to 2 - // note this value is 2 because an initial fire - // needs to be taken into account when the modal opens... - // toggle the tooltip because this is actually - // the first click outside of the popOver since it has been open - $(element).popover('toggle'); - $('body').off('click'); - } - } - }); - } + // $(element).one('click', dismissPopover); $(this).popover('toggle'); $('.popover').each(function() { $compile($(this))(scope); //make nested directives work! }); - }); + } - $(document).bind('keydown', function(e) { + function dismissPopover(e) { + e.stopPropagation(); + $(element).popover('hide'); + } + + function dismissOnEsc(e) { if (e.keyCode === 27) { $(element).popover('hide'); $('.popover').each(function() { // remove lingering popover
. Seems to be a bug in TB3 RC1 - $(this).remove(); + // $(this).remove(); }); } - }); + } + }; }])