1. 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

Discussion in 'Resolved Bug Reports' started by Dan, Apr 13, 2014.

  1. Dan

    Dan Well-Known Member

    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:
     
    Adam Howard likes this.
  2. Mike

    Mike XenForo Developer Staff Member

    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?
     
  3. Dan

    Dan Well-Known Member

    I wasn't able to reproduce this again.

    I changed the code back to $element.data and it's working. I can't say way we got
    Code:
    TypeError: $element.data(...) is undefined
    :( Maybe a problem with a 3rd party script ( https://github.com/kayahr/jquery-fullscreen-plugin )
     

Share This Page