[Info Bubble] Fix display issues

Intermediary commit; fix some display issues with info bubbles,
add some delay. WTD-884.
This commit is contained in:
Victor Woeltjen 2015-05-22 12:28:58 -07:00
parent 05a78f70e3
commit 35f4032ae8
4 changed files with 50 additions and 19 deletions

View File

@ -39,7 +39,11 @@
{ {
"key": "info", "key": "info",
"implementation": "gestures/InfoGesture.js", "implementation": "gestures/InfoGesture.js",
"depends": [ "infoService" ] "depends": [
"$timeout",
"infoService",
"INFO_HOVER_DELAY"
]
} }
], ],
"services": [ "services": [
@ -53,6 +57,12 @@
"$rootScope" "$rootScope"
] ]
} }
],
"constants": [
{
"key": "INFO_HOVER_DELAY",
"value": 500
}
] ]
} }
} }

View File

@ -1,9 +1,9 @@
<div class="t-infobubble s-infobubble l-infobubble-wrapper {{bubble.bubbleLayout}}"> <div class="t-infobubble s-infobubble l-infobubble-wrapper {{bubble.bubbleLayout}}">
<div class="l-infobubble"> <div class="l-infobubble">
<div ng-show="bubble.mctTitle.length > 0" <div ng-show="bubble.bubbleTitle.length > 0"
class="title"> class="title">
{{bubble.bubbleTitle}} {{bubble.bubbleTitle}}
</div> </div>
<ng-transclude></ng-transclude> <span ng-transclude></span>
</div> </div>
</div> </div>

View File

@ -5,8 +5,10 @@ define(
function () { function () {
"use strict"; "use strict";
function InfoGesture(infoService, element, domainObject) { function InfoGesture($timeout, infoService, DELAY, element, domainObject) {
var dismissBubble; var dismissBubble,
pendingBubble,
mousePosition;
function hideBubble() { function hideBubble() {
if (dismissBubble) { if (dismissBubble) {
@ -14,20 +16,36 @@ define(
element.off('mouseleave', hideBubble); element.off('mouseleave', hideBubble);
dismissBubble = undefined; dismissBubble = undefined;
} }
if (pendingBubble) {
$timeout.cancel(pendingBubble);
pendingBubble = undefined;
}
mousePosition = undefined;
}
function trackPosition(event) {
mousePosition = [ event.clientX, event.clientY ];
} }
function showBubble(event) { function showBubble(event) {
dismissBubble = infoService.display( trackPosition(event);
"info-table",
domainObject.getName(), pendingBubble = $timeout(function () {
[ dismissBubble = infoService.display(
{ name: "ID", value: domainObject.getId() } "info-table",
], domainObject.getModel().name,
[ event.clientX, event.clientY ] [
); { name: "ID", value: domainObject.getId() }
],
mousePosition
);
pendingBubble = undefined;
}, DELAY);
element.on('mouseleave', hideBubble); element.on('mouseleave', hideBubble);
} }
element.on('mousemove', trackPosition);
element.on('mouseenter', showBubble); element.on('mouseenter', showBubble);
return { return {

View File

@ -5,20 +5,19 @@ define(
function () { function () {
"use strict"; "use strict";
var BUBBLE_TEMPLATE = "<mct-container key=\"'bubble'\" " + var BUBBLE_TEMPLATE = "<div><mct-container key=\"bubble\" " +
"bubble-title=\"{{bubbleTitle}}\" " + "bubble-title=\"{{bubbleTitle}}\" " +
"bubble-layout=\"{{bubbleLayout}}\" " + "bubble-layout=\"{{bubbleLayout}}\">" +
"<mct-include key=\"'info-table'\" " + "<mct-include key=\"bubbleTemplate\" ng-model=\"bubbleModel\">" +
"ng-model=\"bubbleModel\">" +
"</mct-include>" + "</mct-include>" +
"</mct-container>"; "</mct-container></div>";
/** /**
* Displays informative content ("info bubbles") for the user. * Displays informative content ("info bubbles") for the user.
* @constructor * @constructor
*/ */
function InfoService($compile, $document, $window, $rootScope) { function InfoService($compile, $document, $window, $rootScope) {
var template = $compile(BUBBLE_TEMPLATE); var template;
function display(templateKey, title, content, position) { function display(templateKey, title, content, position) {
var body = $document.find('body'), var body = $document.find('body'),
@ -28,8 +27,12 @@ define(
goUp = position[1] > (window[1] / 2), goUp = position[1] > (window[1] / 2),
bubble; bubble;
// Lazily initialize template
template = template || $compile(BUBBLE_TEMPLATE);
// Pass model & container parameters into the scope // Pass model & container parameters into the scope
scope.bubbleModel = content; scope.bubbleModel = content;
scope.bubbleTemplate = templateKey;
scope.bubbleLayout = (goUp ? 'arw-btm' : 'arw-top') + ' ' + scope.bubbleLayout = (goUp ? 'arw-btm' : 'arw-top') + ' ' +
(goLeft ? 'arw-right' : 'arw-left'); (goLeft ? 'arw-right' : 'arw-left');
scope.bubbleTitle = title; scope.bubbleTitle = title;