@@ -376,17 +376,60 @@ function RemoteFunctions(config) {
376376 // Remove existing info box if any
377377 this . remove ( ) ;
378378
379+ // this value decides where we need to show the box in the UI
380+ // we are creating this here, because if the element has IDs and Classes then we need to increase the value
381+ // so that the box doesn't obscure the element
382+ let pushBoxUp = 29 ; // px value
383+
384+ // get the ID and classes for that element, as we need to display it in the box
385+ const id = this . element . id ;
386+ const classes = this . element . className ? this . element . className . split ( / \s + / ) . filter ( Boolean ) : [ ] ;
387+
388+ let content = "" ; // this will hold the main content that will be displayed
389+ // add element tag name
390+ content += "<div style='font-weight: bold;'>" + this . element . tagName . toLowerCase ( ) + "</div>" ;
391+
392+ // Add ID if present
393+ if ( id ) {
394+ content += "<div style='margin-top: 3px;'>#" + id + "</div>" ;
395+ pushBoxUp += 17 ;
396+ }
397+
398+ // Add classes (limit to 3 with dropdown indicator)
399+ if ( classes . length > 0 ) {
400+ content += "<div style='margin-top: 3px;'>" ;
401+ for ( var i = 0 ; i < Math . min ( classes . length , 3 ) ; i ++ ) {
402+ content += "." + classes [ i ] + " " ;
403+ }
404+ if ( classes . length > 3 ) {
405+ content += "<span style='opacity: 0.8;'>+" + ( classes . length - 3 ) + " more</span>" ;
406+ }
407+ content += "</div>" ;
408+
409+ pushBoxUp += 17 ;
410+ }
411+
379412 // compute the position on screen
380413 var offset = _screenOffset ( this . element ) ,
381414 x = offset . left ,
382415 y = offset . top - 30 ; // Position above the element
383416
417+ let elemBounds = this . element . getBoundingClientRect ( ) ;
418+
419+ console . log ( "elemBounds: " , elemBounds ) ;
420+
384421 // create the container
385422 this . body = window . document . createElement ( "div" ) ;
386423 this . body . style . setProperty ( "z-index" , 2147483647 ) ;
387424 this . body . style . setProperty ( "position" , "fixed" ) ;
388425 this . body . style . setProperty ( "left" , ( offset . left ) + "px" ) ;
389- this . body . style . setProperty ( "top" , ( offset . top - 30 < 0 ? offset . top + this . element . offsetHeight + 5 : offset . top - 30 ) + "px" ) ;
426+ this . body . style . setProperty (
427+ "top" ,
428+ // if there's not enough space to show the box above the element,
429+ // we show it below the element
430+ ( elemBounds . top - pushBoxUp < 0 ? elemBounds . top + elemBounds . height + 5 : elemBounds . top - pushBoxUp ) +
431+ "px"
432+ ) ;
390433 this . body . style . setProperty ( "font-size" , "12px" ) ;
391434 this . body . style . setProperty ( "font-family" , "Arial, sans-serif" ) ;
392435
@@ -399,33 +442,6 @@ function RemoteFunctions(config) {
399442 this . body . style . setProperty ( "max-width" , "300px" ) ;
400443 this . body . style . setProperty ( "pointer-events" , "none" ) ; // Make it non-interactive
401444
402- // Get element ID and classes
403- var id = this . element . id ;
404- var classes = this . element . className ? this . element . className . split ( / \s + / ) . filter ( Boolean ) : [ ] ;
405-
406- // Create content for the info box
407- var content = "" ;
408-
409- // Add element tag name
410- content += "<div style='font-weight: bold;'>" + this . element . tagName . toLowerCase ( ) + "</div>" ;
411-
412- // Add ID if present
413- if ( id ) {
414- content += "<div style='margin-top: 3px;'>#" + id + "</div>" ;
415- }
416-
417- // Add classes (limit to 3 with dropdown indicator)
418- if ( classes . length > 0 ) {
419- content += "<div style='margin-top: 3px;'>" ;
420- for ( var i = 0 ; i < Math . min ( classes . length , 3 ) ; i ++ ) {
421- content += "." + classes [ i ] + " " ;
422- }
423- if ( classes . length > 3 ) {
424- content += "<span style='opacity: 0.8;'>+" + ( classes . length - 3 ) + " more</span>" ;
425- }
426- content += "</div>" ;
427- }
428-
429445 this . body . innerHTML = content ;
430446 window . document . body . appendChild ( this . body ) ;
431447 } ,
0 commit comments