summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Banks <mjbanks@gmail.com>2013-08-05 07:28:17 -0700
committerMatt Banks <mjbanks@gmail.com>2013-08-05 07:28:17 -0700
commit4d647f34c9d4188268784f0b5950aa9ef0fe1a64 (patch)
tree5c904a4055e6d5023259e360459bcf99382e038f
parentcca79d3ef9f6580aaf0cec92cf218827a036274c (diff)
parenta7c967f7cdcb66746b5a67576e0e0b82ce4d07b0 (diff)
downloadjQuery.equalHeights-4d647f34c9d4188268784f0b5950aa9ef0fe1a64.zip
jQuery.equalHeights-4d647f34c9d4188268784f0b5950aa9ef0fe1a64.tar.gz
jQuery.equalHeights-4d647f34c9d4188268784f0b5950aa9ef0fe1a64.tar.bz2
Merge pull request #3 from betweenbrain/develop
Add support for initializing the plugin with data attributes
-rw-r--r--example/example.html15
-rw-r--r--jquery.equalheights.js20
-rw-r--r--jquery.equalheights.min.js2
3 files changed, 27 insertions, 10 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);
diff --git a/jquery.equalheights.min.js b/jquery.equalheights.min.js
index f2bd89b..660349e 100644
--- a/jquery.equalheights.min.js
+++ b/jquery.equalheights.min.js
@@ -8,4 +8,4 @@
*
* @version 1.3
*/
-(function(a){a.fn.equalHeights=function(){var b=0,c=a(this);return c.each(function(){var c=a(this).innerHeight();c>b&&(b=c)}),c.height(b)}})(jQuery);
+(function($){$.fn.equalHeights=function(){var maxHeight=0,$this=$(this);$this.each(function(){var height=$(this).innerHeight();if(height>maxHeight){maxHeight=height}});return $this.height(maxHeight)};var target=$('[data-heights="equal"]').attr('data-targets'),init='[data-heights="equal"] '+target;$(init).equalHeights()})(jQuery);