Skip to content

Commit

Permalink
Resolves #362 - apply css to hidden els on resize when duration speci…
Browse files Browse the repository at this point in the history
…fied
  • Loading branch information
techfg committed Jan 30, 2021
1 parent 507f9de commit 93fe264
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
easing: 'linear'
});
});
els.filter(':hidden').css(newsize);

p = u.defer();
promises.push(p);
Expand Down
13 changes: 3 additions & 10 deletions tests/imagemapster-test-runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,9 @@
enableTestLink();
});

// Zepto returns height/width of 0/0 when image is not visible
// so force image to be displayed
if (window.Zepto) {
$('#testElements').toggle(true);
$('#toggleTestImage').hide();
} else {
$('#toggleTestImage').on('click', function () {
$('#testElements').toggle('fast');
});
}
$('#toggleTestImage').on('click', function () {
$('#testElements').toggle('fast');
});

enableTestLink();

Expand Down
Binary file added tests/images/usa_map_720_alt_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/usa_map_720_alt_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/usa_map_720_alt_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/usa_map_720_alt_4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/images/usa_map_720_alt_5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 74 additions & 10 deletions tests/resize.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,98 @@ this.tests.push(
'use strict';

var img = $('img'),
map = img.mapster(),
x = img.width(),
y = img.height();
altImages = {
img1: 'images/usa_map_720_alt_1.jpg',
img2: 'images/usa_map_720_alt_2.jpg',
img3: 'images/usa_map_720_alt_3.jpg',
img4: 'images/usa_map_720_alt_4.jpg',
img5: 'images/usa_map_720_alt_5.jpg'
},
map = img.mapster({
altImages: altImages
}),
x = parseInt(img.css('width').replace('px', ''), 10),
y = parseInt(img.css('height').replace('px', ''), 10),
newWidth = x + 200;

this.when(function (cb) {
map.mapster('resize', 200, 0, cb);
map.mapster('resize', newWidth, 0, cb);
}).then(function () {
var expectedHeight = Math.round((200 / x) * y);
a.equals(200, img.width(), 'image width is correct after resize');
var expectedWidth = newWidth + 'px',
expectedHeight = Math.round((newWidth / x) * y) + 'px';
a.equals(
img.css('width'),
expectedWidth,
'image width is correct after resize'
);
a.equals(
img.css('height'),
expectedHeight,
img.height(),
'image height is correct after resize'
);

var wrapper = img.closest('div');

a.equals(
'mapster_wrap',
wrapper.attr('id').substring(0, 12),
'mapster_wrap',
'sanity check - we have the wrapper element'
);
a.equals(200, wrapper.width(), 'wrapper width matches image width');
a.equals(
wrapper.css('width'),
expectedWidth,
'wrapper width matches image width'
);
a.equals(
wrapper.css('height'),
expectedHeight,
wrapper.height(),
'wrapper height matches image height'
);
Object.values(altImages).map(function (ai) {
var selector = 'img[src="' + ai + '"]',
altImg = $(wrapper).children(selector);
a.equals(
altImg.css('width'),
expectedWidth,
'altimage ' + ai + ' width matches image width'
);
a.equals(
altImg.css('height'),
expectedHeight,
'altimage ' + ai + ' height matches image height'
);
a.equals(
altImg.css('display'),
'none',
'altimage ' + ai + ' has display of none'
);
});
});
})
);

this.tests.push(
iqtest
.create('autoresize', 'autoresize feature')
.add('wrapper does not have width/height', function (a) {
'use strict';

var img = $('img');
this.when(function (cb) {
img.mapster({ enableAutoResizeSupport: true, onConfigured: cb });
}).then(function () {
var wrapper = img.closest('div');
a.equals(
wrapper.attr('id').substring(0, 12),
'mapster_wrap',
'sanity check - we have the wrapper element'
);
a.equals(wrapper[0].style.width, '', 'wrapper width is not specified');
a.equals(
wrapper[0].style.height,
'',
'wrapper height is not specified'
);
});
})
);

0 comments on commit 93fe264

Please sign in to comment.