Skip to content

Commit a0eba8c

Browse files
committed
Updating child option by simplifying code and adding documentation
1 parent 000cc60 commit a0eba8c

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ $('.parent').equalize({equalize: 'width', reset: true});</pre>
2121

2222
This advanced usage is for dynamic instances where equalize is ran after elements are added or removed to maintain minimum max height or width.
2323

24+
Equalize the .parent's child element. See @larsbo's <a href="http://jsfiddle.net/4QTNP/3/">example</a>.
25+
<pre>$('.parent').equalize({children: 'p'}); // equalize height of paragraphs within .parent</pre>
26+
2427

2528
## Examples
2629

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ <h2>Advanced Usage</h2>
4343

4444
<p>This advanced usage is for dynamic instances where equalize is ran after elements are added or removed to maintain minimum max height or width.</p>
4545

46+
<p>Equalize the .parent's child element. See @larsbo's <a href="http://jsfiddle.net/4QTNP/3/">example</a>.</p>
47+
<pre>$('.parent').equalize({children: 'p'}); // equalize height of paragraphs within .parent</pre>
4648

4749
<h2>Height Example <a id="run-height" href="#height-example">run »</a></h2>
4850
<pre>$('#height-example').equalize(); // defaults to height</pre>

js/equalize.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
* $('.parent').equalize(); // defaults to 'height'
1717
* $('.parent').equalize('width'); // equalize the widths
1818
*
19-
* ADVANCED EXAMPLE
19+
* ADVANCED EXAMPLES
2020
* Get the minimum max dimension by removing the existing height/width
2121
* $('.parent').equalize({reset: true}); // equalize height by default, remove existing height, then determin max
2222
* $('.parent').equalize({equalize: 'width', reset: true}); // equalize width, remove existing width, then determin max
23+
*
24+
* Equalize internal child elements
25+
* From @larsbo : http://jsfiddle.net/4QTNP/3/
26+
* $('.parent').equalize({children: 'p'}); // equalize height of paragraphs within .parent
2327
*/
2428
;(function($) {
2529

@@ -45,9 +49,9 @@
4549
type = (equalize.indexOf('eight') > 0) ? 'height' : 'width';
4650

4751
return $containers.each(function() {
48-
var $children = $(this).children(),
52+
// when children exist, equalize the passed in child elements, otherwise equalize the children
53+
var $children = (children) ? $(this).find(children) : $(this).children(),
4954
max = 0; // reset for each container
50-
if (children) { $children = $(this).find(children); }
5155

5256
$children.each(function() {
5357
var $element = $(this),

js/equalize.min.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
* Page: http://tsvensen.github.com/equalize.js
77
* Repo: https://github.com/tsvensen/equalize.js/
88
*/
9-
;(function(b){b.fn.equalize=function(a){var f=!1,c,d;b.isPlainObject(a)?(c=a.equalize||"height",f=a.reset||!1):c=a||"height";if(!b.isFunction(b.fn[c]))return!1;d=0<c.indexOf("eight")?"height":"width";return this.each(function(){var a=b(this).children(),e=0;a.each(function(){var a=b(this);f&&a.css(d,"");a=a[c]();a>e&&(e=a)});a.css(d,e+"px")})}})(jQuery);
9+
(function(b){b.fn.equalize=function(a){var d=!1,g=!1,c,e;b.isPlainObject(a)?(c=a.equalize||"height",d=a.children||!1,g=a.reset||!1):c=a||"height";if(!b.isFunction(b.fn[c]))return!1;e=0<c.indexOf("eight")?"height":"width";return this.each(function(){var a=d?b(this).find(d):b(this).children(),f=0;a.each(function(){var a=b(this);g&&a.css(e,"");a=a[c]();a>f&&(f=a)});a.css(e,f+"px")})}})(jQuery);

0 commit comments

Comments
 (0)