summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Sartun <sartun@dievision.de>2015-11-12 10:47:51 +0100
committerOliver Sartun <sartun@dievision.de>2015-11-12 10:47:51 +0100
commit023bec101b27e2732bdd07aa072f36c8a6c51564 (patch)
tree7212477cee12cea22143e2e857401f95f3d05cd5
parent758d985ec529de9ef50b96914a22fc98e33354b6 (diff)
downloadjQuery.equalHeights-023bec101b27e2732bdd07aa072f36c8a6c51564.zip
jQuery.equalHeights-023bec101b27e2732bdd07aa072f36c8a6c51564.tar.gz
jQuery.equalHeights-023bec101b27e2732bdd07aa072f36c8a6c51564.tar.bz2
Testing & Refactoring + data-options
+ Tested the `watch` option function and refactored accordingly + Put the Auto initialization in document ready + Supporting options with data attributes
-rw-r--r--jquery.equalheights.js22
1 files changed, 13 insertions, 9 deletions
diff --git a/jquery.equalheights.js b/jquery.equalheights.js
index 8d4b41f..3e23d2d 100644
--- a/jquery.equalheights.js
+++ b/jquery.equalheights.js
@@ -9,12 +9,12 @@
* @version 1.5.1
*/
(function($) {
-
+
var watched = [];
- $(window).on("resize", function () {
+ $(window).on('resize', function () {
for (var i = 0, l = watched.length; i < l; i++) {
if (watched[i]) {
- $(watched[i]).css("height", "auto").equalHeights()
+ $(watched[i]).css('height', 'auto').equalHeights()
}
}
})
@@ -24,13 +24,17 @@
$this = $(this),
equalHeightsFn = function() {
var height = $(this).innerHeight();
-
+
if ( height > maxHeight ) { maxHeight = height; }
};
options = options || {};
$this.each(equalHeightsFn);
+ if (options.watch) {
+ watched.push(this)
+ }
+
if (options.wait) {
var loop = setInterval(function() {
if(maxHeight > 0) {
@@ -39,20 +43,20 @@
}
$this.each(equalHeightsFn);
}, 100);
- } else if (options.watch) {
- watched.push(this)
} else {
return $this.css('height', maxHeight);
}
};
// auto-initialize plugin
- $(document).on("ready", function() {
+ $(document).on('ready', function() {
$('[data-equal]').each(function(){
var $this = $(this),
+ wait = $this.data('equal-wait'),
+ watch = $this.data('equal-watch'),
target = $this.data('equal');
- $this.find(target).equalHeights();
- });
+ $this.find(target).equalHeights({'wait': wait, 'watch': watch});
+ });
});
})(jQuery);