jquery-anystretch icon indicating copy to clipboard operation
jquery-anystretch copied to clipboard

Add support for iterating across groups of jQuery objects

Open miketierney opened this issue 11 years ago • 0 comments

The current implementation only allows the following use cases:

$('#my_node').anystretch('path/to/image');

and

$.anystretch('path/to/image');

I have a scenario where I'd like to have this work like a proper module, grabbing a collection of nodes and then applying the anystretch function to them:

<div class="js-stretch-image" data-img-src="/path/to/img01"></div>
<div class="js-stretch-image" data-img-src="/path/to/img02"></div>
<div class="js-stretch-image" data-img-src="/path/to/img03"></div>

Which I could enable by doing something like this:

$('.js-stretch-image').anystretch($(this).data('imgSrc')); // ideal, but not really functional

or

$('.js-stretch-image').each(function(i, el){ // less than ideal, but more flexible
  $(el).anystretch($(el).data('imgSrc'));
});

The problem lies with the use of this.selector as the toggle for whether or not the isBody Boolean is true or not. My patch changes it to check for whether or not this.context is undefined (true when executed from $.anystretch() and false when $('.selector').anystretch()).

miketierney avatar Apr 08 '13 19:04 miketierney