Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 1dbf460

Browse files
committed
Merge pull request #4485 from adobe/nj/animate-quick-view
Animate quick view popup
2 parents 22959e4 + 046ed7a commit 1dbf460

4 files changed

Lines changed: 64 additions & 42 deletions

File tree

src/extensions/default/QuickView/QuickView.css

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
#quick-view-container {
22
display: none;
3-
3+
4+
-webkit-transition: opacity 0.125s ease-in, -webkit-transform 0.125s;
5+
transition: opacity 0.125s ease-in, transform 0.125s;
6+
7+
-webkit-transform: scale(0);
8+
transform: scale(0);
9+
opacity: 0;
10+
411
background: #e0e1e3;
512
position: absolute;
613
z-index: 5000;
7-
left: 200px;
8-
top: 40px;
914
pointer-events: none;
1015

11-
padding: 15px;
16+
padding: 8px;
1217
text-align: center;
1318

14-
border-radius: 5px;
19+
border-radius: 4px;
1520
box-shadow: 0 4px 15px rgba(0,0,0,0.25), inset 0 0 0 1px #a6a6a6, inset 0 0 0 2px #ebedec;
1621
}
1722

23+
#quick-view-container.active {
24+
-webkit-transform: scale(1);
25+
transform: scale(1);
26+
opacity: 1;
27+
}
28+
1829
#quick-view-container .preview-content {
1930
background-image: url(preview_bg.png);
2031
border-radius: 2px;
@@ -23,8 +34,8 @@
2334

2435

2536
#quick-view-container .color-swatch {
26-
width: 100px;
27-
height: 100px;
37+
width: 40px;
38+
height: 40px;
2839
background-size: 100%;
2940
}
3041

@@ -49,6 +60,10 @@
4960
text-shadow: 0 1px 0px #e8e8e8;
5061
}
5162

63+
#quick-view-container.preview-bubble-above {
64+
-webkit-transform-origin: center bottom;
65+
}
66+
5267
#quick-view-container.preview-bubble-above:before {
5368
display: none;
5469
}
@@ -66,6 +81,9 @@
6681
display: block;
6782
}
6883

84+
#quick-view-container.preview-bubble-below {
85+
-webkit-transform-origin: center top;
86+
}
6987

7088
#quick-view-container.preview-bubble-below:before {
7189
width: 24px;

src/extensions/default/QuickView/main.js

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ define(function (require, exports, module) {
5151
// Constants
5252
var CMD_ENABLE_QUICK_VIEW = "view.enableQuickView",
5353
HOVER_DELAY = 350, // Time (ms) mouse must remain over a provider's matched text before popover appears
54-
POSITION_OFFSET = 38, // Distance between the bottom of the line and the bottom of the preview container
55-
POINTER_LEFT_OFFSET = 17, // Half of the pointer width, used to find the center of the pointer
56-
POINTER_TOP_OFFSET = 7, // Pointer height, used to shift popover above pointer
57-
POSITION_BELOW_OFFSET = 16, // Amount to adjust to top position when the preview bubble is below the text
54+
POINTER_HEIGHT = 15, // Pointer height, used to shift popover above pointer (plus a little bit of space)
5855
POPOVER_HORZ_MARGIN = 5; // Horizontal margin
5956

6057
/**
@@ -72,7 +69,8 @@ define(function (require, exports, module) {
7269
* start: !{line, ch}, - start of matched text range
7370
* end: !{line, ch}, - end of matched text range
7471
* content: !string, - HTML content to display in popover
75-
* onShow: ?function():void, - called once popover content added to the DOM (may never be called)
72+
* onShow: ?function():void, - called once popover content added to the DOM (may never be called)
73+
* - if specified, must call positionPreview()
7674
* xpos: number, - x of center of popover
7775
* ytop: number, - y of top of matched text (when popover placed above text, normally)
7876
* ybot: number, - y of bottom of matched text (when popover moved below text, avoiding window top)
@@ -99,40 +97,39 @@ define(function (require, exports, module) {
9997

10098
$previewContent.empty();
10199
$previewContainer.hide();
102-
100+
$previewContainer.removeClass("active");
103101
} else {
104102
window.clearTimeout(popoverState.hoverTimer);
105103
}
106-
107104
popoverState = null;
108105
}
109106

110107
function positionPreview(xpos, ypos, ybot) {
111-
var previewWidth = $previewContainer.width(),
112-
top = ypos - $previewContainer.height() - POSITION_OFFSET,
113-
left = xpos - previewWidth / 2 - POINTER_LEFT_OFFSET,
108+
var previewWidth = $previewContainer.outerWidth(),
109+
top = ypos - $previewContainer.outerHeight() - POINTER_HEIGHT,
110+
left = xpos - previewWidth / 2,
114111
$editorHolder = $("#editor-holder"),
115112
editorLeft = $editorHolder.offset().left;
116113

117114
left = Math.max(left, editorLeft + POPOVER_HORZ_MARGIN);
118115
left = Math.min(left, editorLeft + $editorHolder.width() - previewWidth - POPOVER_HORZ_MARGIN);
119116

120117
if (top < 0) {
121-
$previewContainer.removeClass("preview-bubble-above");
122-
$previewContainer.addClass("preview-bubble-below");
123-
top = ybot + POSITION_BELOW_OFFSET;
124-
$previewContainer.offset({
125-
left: left,
126-
top: top
127-
});
118+
top = ybot + POINTER_HEIGHT;
119+
$previewContainer
120+
.removeClass("preview-bubble-above")
121+
.addClass("preview-bubble-below");
128122
} else {
129-
$previewContainer.removeClass("preview-bubble-below");
130-
$previewContainer.addClass("preview-bubble-above");
131-
$previewContainer.offset({
132-
left: left,
133-
top: top - POINTER_TOP_OFFSET
134-
});
123+
$previewContainer
124+
.removeClass("preview-bubble-below")
125+
.addClass("preview-bubble-above");
135126
}
127+
$previewContainer
128+
.css({
129+
left: left,
130+
top: top
131+
})
132+
.addClass("active");
136133
}
137134

138135
/**
@@ -155,9 +152,9 @@ define(function (require, exports, module) {
155152

156153
if (popoverState.onShow) {
157154
popoverState.onShow();
155+
} else {
156+
positionPreview(popoverState.xpos, popoverState.ytop, popoverState.ybot);
158157
}
159-
160-
positionPreview(popoverState.xpos, popoverState.ytop, popoverState.ybot);
161158
}
162159

163160
function divContainsMouse($div, event) {
@@ -433,10 +430,11 @@ define(function (require, exports, module) {
433430
var showHandler = function () {
434431
// Hide the preview container until the image is loaded.
435432
$previewContainer.hide();
433+
436434

437435
$previewContainer.find(".image-preview > img").on("load", function () {
438436
$previewContent
439-
.append("<div class='img-size'>" +
437+
.append("<div class='img-size'>" +
440438
this.naturalWidth + " x " + this.naturalHeight + " " + Strings.UNIT_PIXELS +
441439
"</div>"
442440
);

src/extensions/default/QuickView/unittests.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,18 +289,24 @@ define(function (require, exports, module) {
289289
QuickView._forceShow(popoverInfo);
290290
}
291291

292-
function getBounds(object) {
292+
function getBounds(object, useOffset) {
293+
var left = (useOffset ? object.offset().left : parseInt(object.css("left"), 10)),
294+
top = (useOffset ? object.offset().top : parseInt(object.css("top"), 10));
293295
return {
294-
left: object.offset().left,
295-
top: object.offset().top,
296-
right: object.offset().left + object.width(),
297-
bottom: object.offset().top + object.height()
296+
left: left,
297+
top: top,
298+
right: left + object.outerWidth(),
299+
bottom: top + object.outerHeight()
298300
};
299301
}
300302

301303
function boundsInsideWindow(object) {
302-
var bounds = getBounds(object),
303-
editorBounds = getBounds(testWindow.$("#editor-holder"));
304+
// For the popover, we can't use offset(), because jQuery gets confused by the
305+
// scale factor and transform origin that the animation uses. Instead, we rely
306+
// on the fact that its offset parent is body, and just test its explicit left/top
307+
// values.
308+
var bounds = getBounds(object, false),
309+
editorBounds = getBounds(testWindow.$("#editor-holder"), true);
304310
return bounds.left >= editorBounds.left &&
305311
bounds.right <= editorBounds.right &&
306312
bounds.top >= editorBounds.top &&

src/styles/brackets.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ a, img {
565565
-webkit-transform: translateZ(0);
566566
transform: translateZ(0);
567567

568-
-webkit-transition: height 0.15s ease-out;
569-
transition: height 0.15s ease-out;
568+
-webkit-transition: height 0.125s ease-out;
569+
transition: height 0.125s ease-out;
570570
}
571571

572572
.CodeMirror {

0 commit comments

Comments
 (0)