Skip to content

Conversation

@bpierre
Copy link
Contributor

@bpierre bpierre commented Nov 24, 2011

Useful for containers without explicit dimensions, e.g. :

$(window).resize(function(){
    $myElement.data('antiscroll').rebuild();
});

@bpierre
Copy link
Contributor Author

bpierre commented Nov 24, 2011

I forgot to precise that I call the constructor as a function, but the CSS / Scrollbars part of the constructor could be moved in another method.

@rauchg
Copy link
Contributor

rauchg commented Nov 27, 2011

Is there a reason we need to cache the styles of inner ?

@bpierre
Copy link
Contributor Author

bpierre commented Nov 27, 2011

It’s a precaution, in order to reset the styles to their previous values before calling the Antiscroll constructor.

If we replace it with inner.attr('style', ''):

var containers = $('.container');
containers.find('.antiscroll-inner').css('background', 'red'); // The background is red
containers.antiscroll();
containers.each(function(){
  $(this).data('antiscroll').rebuild(); // The red background is removed
});

But if we assume that:

  • It is an expensive operation
  • <div class="antiscroll-inner"> is supposed to be dedicated to antiscroll
  • Styles can still be added between the calls to antiscroll() and rebuild(), and will not be cached

I think it’s relatively safe to remove it. I will add another commit.

Style caching was a precaution, in order to reset the styles to their previous values
before calling the Antiscroll constructor.

Now, this will not work anymore:

    var containers = $('.container');
    containers.find('.antiscroll-inner').css('background', 'red');
    // The background is red
    containers.antiscroll();
    containers.each(function(){
      $(this).data('antiscroll').rebuild();
    });
    // The red background is removed

But if we assume that:

 - It is an expensive operation
 - <div class="antiscroll-inner"> is supposed to be dedicated to
   antiscroll
 - Styles can still be added between the calls to antiscroll() and
   rebuild(), and will not be cached

It’s relatively safe to remove it.
rauchg added a commit that referenced this pull request Feb 18, 2012
@rauchg rauchg merged commit 686ce85 into Automattic:master Feb 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants