Skip to content

Commit

Permalink
Images carrying the class "reel", which aren't Reel instance yet, a…
Browse files Browse the repository at this point in the history
…re picked up, have their data payload taken off and fed to `.reel()` as the usual options hash. #193
  • Loading branch information
pisi committed May 20, 2013
1 parent 32b27a9 commit 1a7e167
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion jquery.reel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,11 @@ jQuery.reel || (function($, window, document, undefined){

scan: function(){
$(dot(klass)).each(function(ix, image){
if ($(image).parent().is(dot(overlay_klass))) return;
if ($(image).parent().hasClass(overlay_klass)) return;
var
$image= $(image),
options= $image.data()
$image.removeData().reel(options);
});
},

Expand Down
28 changes: 28 additions & 0 deletions test/unit/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,32 @@
});
});

test( 'Data-configured `<img>` tags are turned into Reel instances upon scan', function(){
expect(7);
var
options= {
image: 'image2.jpg',
frames: 15,
frame: 5
},
$img= $('<img>').attr({
src: 'image.jpg',
width: 300,
height: 200,
id: 'my_data_configured_image',
'class': 'reel',
'data-image': options.image,
'data-frames': options.frames,
'data-frame': options.frame
}).appendTo('#Body');

$.reel.scan();

ok( $img.parent().is('.reel-overlay'), 'Image is nested inside the Reel overlay (`.reel-overlay`)' );
$.each(options, function(option, value){
equal( $img.reel('options')[option], value, 'Tested `'+option+'` value picked up.');
equal( $img.reel(option), value, 'Tested `'+option+'` actually used.');
});
});

})(jQuery);

0 comments on commit 1a7e167

Please sign in to comment.