@@ -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 ) ;
0 commit comments