Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

added option to disable container resize #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ function resize (gardrPluginApi) {
var resizeVertical = !!item.options.resizeVertical;
var container = item.options.container;
var rendered = item.rendered;
var disableContainerResize = item.options.disableContainerResize || false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be named enabled and flipped so the if statements are more readable.

var iframe = item.iframe;

var width = resizeHorizontal ? rendered.width : null;
var height = resizeVertical ? rendered.height : null;


if(width) {
if(width && !disableContainerResize) {
container.style.width = width + 'px';
}
if(height) {
if(height && !disableContainerResize) {
container.style.height = height + 'px';
}
if(width || height) {
Expand Down
29 changes: 22 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ describe('resize-host', function () {
beforeEach(function () {
pluginApi = new PluginApi();
});

it('should be a function', function () {
assert.equal(typeof resize, 'function');
});

it('should not resize anything if both item.options.resizeHorizontal and item.options.resizeVertical are not true', function () {
var item = mockItem();
resize(pluginApi);
Expand All @@ -44,12 +44,12 @@ describe('resize-host', function () {
height: 120
};
pluginApi.trigger('item:afterrender', item);

assert.equal(item.options.container.style.width, '100px');
assert.equal(item.options.container.style.height, '100px');
assert(!item.iframe.resize.called, 'item resize called');
});

it('should only resize horizontal if item.options.resizeHorizontal is true, leaving vertical unchanged', function () {
var item = mockItem();
item.options.resizeHorizontal = true;
Expand All @@ -59,7 +59,7 @@ describe('resize-host', function () {
height: 120
};
pluginApi.trigger('item:afterrender', item);

assert.equal(item.options.container.style.width, '120px');
assert.equal(item.options.container.style.height, '100px');
assert(item.iframe.resize.calledOnce, 'item resize called');
Expand All @@ -75,7 +75,7 @@ describe('resize-host', function () {
height: 120
};
pluginApi.trigger('item:afterrender', item);

assert.equal(item.options.container.style.width, '100px');
assert.equal(item.options.container.style.height, '120px');
assert(item.iframe.resize.calledOnce, 'item resize called');
Expand All @@ -92,10 +92,25 @@ describe('resize-host', function () {
height: 120
};
pluginApi.trigger('item:afterrender', item);

assert.equal(item.options.container.style.width, '120px');
assert.equal(item.options.container.style.height, '120px');
assert(item.iframe.resize.calledOnce, 'item resize called');
assert(item.iframe.resize.calledWith(item.rendered.width, item.rendered.height), 'called with new width and height');
});

it('shoud not resize container if items.options.disableContainerResize is true', function () {
var item = mockItem();
resize(pluginApi);
item.options.disableContainerResize = true;
item.rendered = {
width: 120,
height: 120
};
pluginApi.trigger('item:afterrender', item);

assert.equal(item.options.container.style.width, '100px');
assert.equal(item.options.container.style.height, '100px');
assert(!item.iframe.resize.called, 'item resize called');
});
});