summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Thomas <matt@betweenbrain.com>2013-05-14 20:09:39 -0400
committerMatt Thomas <matt@betweenbrain.com>2013-05-14 20:09:39 -0400
commitab692d216110d2e5d6ebab53e3f982c5925d6590 (patch)
tree570799e350343f0d13e754160c77ac838bc9e379
parentcca79d3ef9f6580aaf0cec92cf218827a036274c (diff)
downloadjQuery.equalHeights-ab692d216110d2e5d6ebab53e3f982c5925d6590.zip
jQuery.equalHeights-ab692d216110d2e5d6ebab53e3f982c5925d6590.tar.gz
jQuery.equalHeights-ab692d216110d2e5d6ebab53e3f982c5925d6590.tar.bz2
Add support for initializing the plugin with data attributes data-heights="equal" and targets data-targets="div"
-rw-r--r--example/example.html15
-rw-r--r--jquery.equalheights.js20
2 files changed, 26 insertions, 9 deletions
diff --git a/example/example.html b/example/example.html
index 216137e..1351b5d 100644
--- a/example/example.html
+++ b/example/example.html
@@ -46,8 +46,21 @@
</div>
</div>
+ <div data-heights="equal" data-targets="div" class="clearfix">
+ <h3>Using equal heights with <pre>data-heights="equal" data-target="div"</pre></h3>
+ <div class="column1">
+ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
+ </div>
+ <div class="column2">
+ <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
+ </div>
+ <div class="column3">
+ <p>Lorem ipsum dolor sit amet</p>
+ </div>
+ </div>
+
<script src="jquery-1.7.2.min.js"></script>
- <script src="../jquery.equalheights.min.js"></script>
+ <script src="../jquery.equalheights.js"></script>
<script>
$('#equalheight div').equalHeights();
</script>
diff --git a/jquery.equalheights.js b/jquery.equalheights.js
index f21303c..560fd64 100644
--- a/jquery.equalheights.js
+++ b/jquery.equalheights.js
@@ -10,17 +10,21 @@
*/
(function($) {
- $.fn.equalHeights = function() {
- var maxHeight = 0,
+ $.fn.equalHeights = function() {
+ var maxHeight = 0,
$this = $(this);
- $this.each( function() {
- var height = $(this).innerHeight();
+ $this.each( function() {
+ var height = $(this).innerHeight();
- if ( height > maxHeight ) { maxHeight = height; }
- });
+ if ( height > maxHeight ) { maxHeight = height; }
+ });
- return $this.height(maxHeight);
- };
+ return $this.height(maxHeight);
+ };
+
+ // auto-initialize plugin
+ var target = $('[data-heights="equal"]').attr('data-targets'), init = '[data-heights="equal"] ' + target;
+ $(init).equalHeights();
})(jQuery);