diff --git a/index.js b/index.js index 8ffd640..79effb2 100644 --- a/index.js +++ b/index.js @@ -7,16 +7,17 @@ function resize (gardrPluginApi) { var resizeVertical = !!item.options.resizeVertical; var container = item.options.container; var rendered = item.rendered; + var enableContainerResize = item.options.enableContainerResize || true; var iframe = item.iframe; var width = resizeHorizontal ? rendered.width : null; var height = resizeVertical ? rendered.height : null; - if(width) { + if(width && enableContainerResize) { container.style.width = width + 'px'; } - if(height) { + if(height && enableContainerResize) { container.style.height = height + 'px'; } if(width || height) { diff --git a/test.js b/test.js index cb02c1c..e23ac59 100644 --- a/test.js +++ b/test.js @@ -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); @@ -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; @@ -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'); @@ -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'); @@ -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.enableContainerResize is false', function () { + var item = mockItem(); + resize(pluginApi); + item.options.enableContainerResize = false; + 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'); + }); });