Add support for wrapping image in anchor element #52

Closed
wants to merge 2 commits into
from
View
@@ -17,7 +17,7 @@
<p>For more info: <a href="http://github.com/scottjehl/picturefill">see project home.</a></p>
- <div data-picture data-alt="A giant stone face at The Bayon temple in Angkor Thom, Cambodia">
+ <div data-picture data-alt="A giant stone face at The Bayon temple in Angkor Thom, Cambodia" data-href="http://en.wikipedia.org/wiki/Bayon">
<div data-src="external/imgs/small.jpg"></div>
<div data-src="external/imgs/medium.jpg" data-media="(min-width: 400px)"></div>
<div data-src="external/imgs/large.jpg" data-media="(min-width: 800px)"></div>
View
@@ -31,7 +31,17 @@
if( !picImg ){
picImg = w.document.createElement( "img" );
picImg.alt = ps[ i ].getAttribute( "data-alt" );
- ps[ i ].appendChild( picImg );
+
+ // if we have an href to apply to the image
+ if( ps[ i ].getAttribute( "data-href" ) ){
+ picUrl = w.document.createElement( "a" );
+ picUrl.setAttribute( "href" , ps[ i ].getAttribute( "data-href" ) );
+ picUrl.appendChild( picImg );
+ ps[ i ].appendChild( picUrl );
+ }
+ else{
+ ps[ i ].appendChild( picImg );
+ }
}
picImg.src = matches.pop().getAttribute( "data-src" );
@@ -57,4 +67,4 @@
w.attachEvent( "onload", w.picturefill );
}
-}( this ));
+}( this ));