• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Awaiting feedback scope problem in xenforo.js Tooltip function

Dan

Well-known member
#1
Code:
XenForo.Tooltip = function($element)
   {
     var tipClass = String($element.data('tipclass') || ''),
       isFlipped = /(\s|^)flipped(\s|$)/.test(tipClass),
       offsetY = parseInt($element.data('offsety'), 10) || -6,
       innerWidth = $element.is(':visible') ? $element.innerWidth() : 0,
       dataOffsetX = parseInt($element.data('offsetx'), 10) || 0,
       offsetX = dataOffsetX + innerWidth * (isFlipped ? 1 : -1),
       title = XenForo.htmlspecialchars($element.attr('title'));

     var onBeforeShow = null;

     if (innerWidth <= 0)
     {
       var positionUpdated = false;
       onBeforeShow = function()
       {
         if (positionUpdated)
         {
           return;
         }

         var width = $element.innerWidth();
         if (width <= 0)
         {
           return;
         }
         positionUpdated = true;

         offsetX = dataOffsetX + width * (isFlipped ? 1 : -1);
  
         $element.data('tooltip').getConf().offset = XenForo.switchOffsetRTL([ offsetY, offsetX ]);
       };
     }
needs to be changed to
Code:
XenForo.Tooltip = function($element)
   {
     var tipClass = String($element.data('tipclass') || ''),
       isFlipped = /(\s|^)flipped(\s|$)/.test(tipClass),
       offsetY = parseInt($element.data('offsety'), 10) || -6,
       innerWidth = $element.is(':visible') ? $element.innerWidth() : 0,
       dataOffsetX = parseInt($element.data('offsetx'), 10) || 0,
       offsetX = dataOffsetX + innerWidth * (isFlipped ? 1 : -1),
       title = XenForo.htmlspecialchars($element.attr('title'));

     var onBeforeShow = null;

     if (innerWidth <= 0)
     {
       var positionUpdated = false;
       onBeforeShow = function()
       {
         if (positionUpdated)
         {
           return;
         }

         var width = $element.innerWidth();
         if (width <= 0)
         {
           return;
         }
         positionUpdated = true;

         offsetX = dataOffsetX + width * (isFlipped ? 1 : -1);
  
         this.getConf().offset = XenForo.switchOffsetRTL([ offsetY, offsetX ]);
       };
     }


$element.data('tooltip') will throw following js error:
TypeError: $element.data(...) is undefined
 

Mike

XenForo developer
Staff member
#2
I'm unclear as to the reason this change is needed. $element is available there and is indeed used immediately before this line. It's not evident why this function would be called without there being a tooltip API already registered and thus fetchable.

Can you include code to reproduce the issue?