diff --git a/README.md b/README.md index f8c30e3..cde0ba6 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,12 @@ $('.parent-element').sameHeight({ //this option by default is false. If set to true css height will be //used instead of min-height to change height of elements. - useCSSHeight: true + useCSSHeight: true, + + //this function will be called every time height is adjusted + callback: function() { + //do something here... + } }); ``` diff --git a/bower.json b/bower.json index 4295923..0e2a6e7 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery.sameHeight", - "version": "0.0.7", + "version": "0.0.8", "homepage": "https://github.com/smohadjer/sameHeight", "authors": [ "Saeid Mohadjer " diff --git a/jquery.sameHeight.js b/jquery.sameHeight.js index dc09e06..abce3ee 100644 --- a/jquery.sameHeight.js +++ b/jquery.sameHeight.js @@ -3,7 +3,7 @@ * @link https://github.com/smohadjer/jquery.sameHeight * @license http://opensource.org/licenses/MIT * -* @version 0.0.7 +* @version 0.0.8 * * based on: http://jqueryboilerplate.com/ * jQuery plugin for making adjacent elements the same height. By default elements @@ -55,21 +55,25 @@ $(window).on('resize.' + pluginName, function() { //remove previously set height or min-height self.$elms.css(self.cssProperty, ''); - - //if there are adjacent elements - if (self.getRow(0).length > 1) { - self.setMinHeight(0); - } + initSameHeight(); }); //use setTimeout to make sure any code in stack is executed before //calculating height setTimeout(function() { + initSameHeight(); + }, 0); + + function initSameHeight() { //if there are adjacent elements if (self.getRow(0).length > 1) { self.setMinHeight(0); + + if (self.options.callback) { + self.options.callback(); + } } - }, 0); + } }, setMinHeight: function(index){ diff --git a/jquery.sameHeight.min.js b/jquery.sameHeight.min.js index a11c548..96cc769 100644 --- a/jquery.sameHeight.min.js +++ b/jquery.sameHeight.min.js @@ -1 +1 @@ -!function(t,e,i,n){"use strict";function s(e,i){this.$element=t(e),this.options=t.extend({},h,i),this.init()}var o="sameHeight",h={oneHeightForAll:!1,useCSSHeight:!1},r=function(e){var i=0;return t.each(e,function(){var e=t(this).outerHeight();e>i&&(i=e)}),i},u={init:function(){var i=this;i.index=0,i.$elms=i.$element.children(),i.cssProperty=i.options.useCSSHeight?"height":"min-height",t(e).on("resize."+o,function(){i.$elms.css(i.cssProperty,""),i.getRow(0).length>1&&i.setMinHeight(0)}),setTimeout(function(){i.getRow(0).length>1&&i.setMinHeight(0)},0)},setMinHeight:function(e){var i=this,n=i.options.oneHeightForAll?i.$elms:i.getRow(e),s=r(n);t.each(n,function(){t(this).css(i.cssProperty,s)}),!i.options.oneHeightForAll&&i.indexi&&(i=e)}),i},c={init:function(){function i(){n.getRow(0).length>1&&(n.setMinHeight(0),n.options.callback&&n.options.callback())}var n=this;n.index=0,n.$elms=n.$element.children(),n.cssProperty=n.options.useCSSHeight?"height":"min-height",t(e).on("resize."+o,function(){n.$elms.css(n.cssProperty,""),i()}),setTimeout(function(){i()},0)},setMinHeight:function(e){var i=this,n=i.options.oneHeightForAll?i.$elms:i.getRow(e),s=r(n);t.each(n,function(){t(this).css(i.cssProperty,s)}),!i.options.oneHeightForAll&&i.index