Skip to content

Commit

Permalink
Releasing 3.3.0, picture width and height to img
Browse files Browse the repository at this point in the history
Releasing 3.3.0, which copies picture's width and height attributes to
the resulting image
  • Loading branch information
verlok committed Apr 26, 2014
1 parent 7602455 commit 089963f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function(grunt) {
grunt.initConfig({
// Metadata.
meta: {
version: '3.2.1'
version: '3.3.0'
},
banner: '/*! picturePolyfill - v<%= meta.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picturePolyfill",
"version": "3.2.1",
"version": "3.3.0",
"main": "picturePolyfill.js",
"ignore": [
".idea",
Expand Down
4 changes: 2 additions & 2 deletions dist/picturePolyfill.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion src/picturePolyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,24 @@ var picturePolyfill = (function(w) {
* @param attributes
*/
_setImg: function(pictureElement, attributes) {
var imageElements = pictureElement.getElementsByTagName('img');
var pictureAttributesToCopy, attributeName, attributeValue,
imageElements = pictureElement.getElementsByTagName('img');

// If image already exists, use it
if (imageElements.length) {
imageElements[0].setAttribute('src', attributes.src);
}
// Else create the image
else {
// Adding picture's attributes to the image (e.g. width, height)
pictureAttributesToCopy = ['width', 'height'];
for (var i = 0, len = pictureAttributesToCopy.length; i<len; i+=1) {
attributeName = pictureAttributesToCopy[i];
attributeValue = pictureElement.getAttribute(attributeName);
if (attributeValue) {
attributes[attributeName] = attributeValue;
}
}
if (this._appendSupport) {
this._appendImg(pictureElement, attributes);
}
Expand Down
18 changes: 17 additions & 1 deletion test/picturePolyfill.qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ test("_replacePicture creates a picture and the right image", function() {

test("_setImg should first create then update an image", function() {
var testContainer, images;
$('body').append('<div id="testContainer"></div>');

$('body').append('<div id="testContainer"></div>');
testContainer = document.getElementById('testContainer');

// No images at start
Expand All @@ -385,6 +385,22 @@ test("_setImg should first create then update an image", function() {

});

test("_setImg() should copy picture's width and height attributes to image", function() {
var testContainer, images;

$('body').append('<picture id="testContainer" width="666" height="69"></picture>');
testContainer = document.getElementById('testContainer');

// Check img width and height
picturePolyfill._setImg(testContainer, {src: 'http://placehold.it/1x1', alt: 'An image'});
testContainer = document.getElementById('testContainer');
images = testContainer.getElementsByTagName('img');
strictEqual(images.length, 1);

strictEqual(images[0].getAttribute('width'), '666');
strictEqual(images[0].getAttribute('height'), '69');
});

test("parse() is called at DOM ready", function() {
if (!document.createEvent) {
ok(true);
Expand Down

0 comments on commit 089963f

Please sign in to comment.