summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jquery.matchHeight-min.js11
-rw-r--r--jquery.matchHeight.js54
2 files changed, 32 insertions, 33 deletions
diff --git a/jquery.matchHeight-min.js b/jquery.matchHeight-min.js
index 5817cae..f954780 100644
--- a/jquery.matchHeight-min.js
+++ b/jquery.matchHeight-min.js
@@ -3,9 +3,8 @@
* http://brm.io/jquery-match-height/
* License: MIT
*/
-(function(b){var f=-1,e=-1,m=function(a){var d=null,c=[];b(a).each(function(){var a=b(this),h=a.offset().top-g(a.css("margin-top")),k=0<c.length?c[c.length-1]:null;null===k?c.push(a):1>=Math.floor(Math.abs(d-h))?c[c.length-1]=k.add(a):c.push(a);d=h});return c},g=function(b){return parseFloat(b)||0};b.fn.matchHeight=function(a){if("remove"===a){var d=this;this.css("height","");b.each(b.fn.matchHeight._groups,function(b,a){a.elements=a.elements.not(d)});return this}if(1>=this.length)return this;a="undefined"!==
-typeof a?a:!0;b.fn.matchHeight._groups.push({elements:this,byRow:a});b.fn.matchHeight._apply(this,a);return this};b.fn.matchHeight._groups=[];b.fn.matchHeight._throttle=80;b.fn.matchHeight._maintainScroll=!1;b.fn.matchHeight._beforeUpdate=null;b.fn.matchHeight._afterUpdate=null;b.fn.matchHeight._apply=function(a,d){var c=b(a),e=[c],h=b(window).scrollTop(),k=b("html").outerHeight(!0),f=c.parents().filter(":hidden");f.css("display","block");d&&(c.each(function(){var a=b(this),c="inline-block"===a.css("display")?
-"inline-block":"block";a.data("style-cache",a.attr("style"));a.css({display:c,"padding-top":"0","padding-bottom":"0","margin-top":"0","margin-bottom":"0","border-top-width":"0","border-bottom-width":"0",height:"100px"})}),e=m(c),c.each(function(){var a=b(this);a.attr("style",a.data("style-cache")||"").css("height","")}));b.each(e,function(a,c){var e=b(c),f=0;d&&1>=e.length||(e.each(function(){var a=b(this),c="inline-block"===a.css("display")?"inline-block":"block";a.css({display:c,height:""});a.outerHeight(!1)>
-f&&(f=a.outerHeight(!1));a.css("display","")}),e.each(function(){var a=b(this),c=0;"border-box"!==a.css("box-sizing")&&(c+=g(a.css("border-top-width"))+g(a.css("border-bottom-width")),c+=g(a.css("padding-top"))+g(a.css("padding-bottom")));a.css("height",f-c)}))});f.css("display","");b.fn.matchHeight._maintainScroll&&b(window).scrollTop(h/k*b("html").outerHeight(!0));return this};b.fn.matchHeight._applyDataApi=function(){var a={};b("[data-match-height], [data-mh]").each(function(){var d=b(this),c=
-d.attr("data-match-height")||d.attr("data-mh");a[c]=c in a?a[c].add(d):d});b.each(a,function(){this.matchHeight(!0)})};var l=function(a){b.fn.matchHeight._beforeUpdate&&b.fn.matchHeight._beforeUpdate(a,b.fn.matchHeight._groups);b.each(b.fn.matchHeight._groups,function(){b.fn.matchHeight._apply(this.elements,this.byRow)});b.fn.matchHeight._afterUpdate&&b.fn.matchHeight._afterUpdate(a,b.fn.matchHeight._groups)};b.fn.matchHeight._update=function(a,d){if(d&&"resize"===d.type){var c=b(window).width();
-if(c===f)return;f=c}a?-1===e&&(e=setTimeout(function(){l(d);e=-1},b.fn.matchHeight._throttle)):l(d)};b(b.fn.matchHeight._applyDataApi);b(window).bind("load",function(a){b.fn.matchHeight._update(!1,a)});b(window).bind("resize orientationchange",function(a){b.fn.matchHeight._update(!0,a)})})(jQuery); \ No newline at end of file
+(function(d){var g=-1,e=-1,n=function(a){var b=null,c=[];d(a).each(function(){var a=d(this),k=a.offset().top-h(a.css("margin-top")),l=0<c.length?c[c.length-1]:null;null===l?c.push(a):1>=Math.floor(Math.abs(b-k))?c[c.length-1]=l.add(a):c.push(a);b=k});return c},h=function(a){return parseFloat(a)||0},b=d.fn.matchHeight=function(a){if("remove"===a){var f=this;this.css("height","");d.each(b._groups,function(a,b){b.elements=b.elements.not(f)});return this}if(1>=this.length)return this;a="undefined"!==
+typeof a?a:!0;b._groups.push({elements:this,byRow:a});b._apply(this,a);return this};b._groups=[];b._throttle=80;b._maintainScroll=!1;b._beforeUpdate=null;b._afterUpdate=null;b._apply=function(a,f){var c=d(a),e=[c],k=d(window).scrollTop(),l=d("html").outerHeight(!0),g=c.parents().filter(":hidden");g.css("display","block");f&&(c.each(function(){var a=d(this),b="inline-block"===a.css("display")?"inline-block":"block";a.data("style-cache",a.attr("style"));a.css({display:b,"padding-top":"0","padding-bottom":"0",
+"margin-top":"0","margin-bottom":"0","border-top-width":"0","border-bottom-width":"0",height:"100px"})}),e=n(c),c.each(function(){var a=d(this);a.attr("style",a.data("style-cache")||"").css("height","")}));d.each(e,function(a,b){var c=d(b),e=0;f&&1>=c.length||(c.each(function(){var a=d(this),b="inline-block"===a.css("display")?"inline-block":"block";a.css({display:b,height:""});a.outerHeight(!1)>e&&(e=a.outerHeight(!1));a.css("display","")}),c.each(function(){var a=d(this),b=0;"border-box"!==a.css("box-sizing")&&
+(b+=h(a.css("border-top-width"))+h(a.css("border-bottom-width")),b+=h(a.css("padding-top"))+h(a.css("padding-bottom")));a.css("height",e-b)}))});g.css("display","");b._maintainScroll&&d(window).scrollTop(k/l*d("html").outerHeight(!0));return this};b._applyDataApi=function(){var a={};d("[data-match-height], [data-mh]").each(function(){var b=d(this),c=b.attr("data-match-height")||b.attr("data-mh");a[c]=c in a?a[c].add(b):b});d.each(a,function(){this.matchHeight(!0)})};var m=function(a){b._beforeUpdate&&
+b._beforeUpdate(a,b._groups);d.each(b._groups,function(){b._apply(this.elements,this.byRow)});b._afterUpdate&&b._afterUpdate(a,b._groups)};b._update=function(a,f){if(f&&"resize"===f.type){var c=d(window).width();if(c===g)return;g=c}a?-1===e&&(e=setTimeout(function(){m(f);e=-1},b._throttle)):m(f)};d(b._applyDataApi);d(window).bind("load",function(a){b._update(!1,a)});d(window).bind("resize orientationchange",function(a){b._update(!0,a)})})(jQuery); \ No newline at end of file
diff --git a/jquery.matchHeight.js b/jquery.matchHeight.js
index d0679c5..a64ab34 100644
--- a/jquery.matchHeight.js
+++ b/jquery.matchHeight.js
@@ -61,11 +61,11 @@
};
/*
- * $.fn.matchHeight
+ * matchHeight
* plugin definition
*/
- $.fn.matchHeight = function(byRow) {
+ var matchHeight = $.fn.matchHeight = function(byRow) {
// handle matchHeight('remove')
if (byRow === 'remove') {
@@ -75,7 +75,7 @@
this.css('height', '');
// remove selected elements from all groups
- $.each($.fn.matchHeight._groups, function(key, group) {
+ $.each(matchHeight._groups, function(key, group) {
group.elements = group.elements.not(that);
});
@@ -91,13 +91,13 @@
byRow = (typeof byRow !== 'undefined') ? byRow : true;
// keep track of this group so we can re-apply later on load and resize events
- $.fn.matchHeight._groups.push({
+ matchHeight._groups.push({
elements: this,
byRow: byRow
});
// match each element's height to the tallest element in the selection
- $.fn.matchHeight._apply(this, byRow);
+ matchHeight._apply(this, byRow);
return this;
};
@@ -106,18 +106,18 @@
* plugin global options
*/
- $.fn.matchHeight._groups = [];
- $.fn.matchHeight._throttle = 80;
- $.fn.matchHeight._maintainScroll = false;
- $.fn.matchHeight._beforeUpdate = null;
- $.fn.matchHeight._afterUpdate = null;
+ matchHeight._groups = [];
+ matchHeight._throttle = 80;
+ matchHeight._maintainScroll = false;
+ matchHeight._beforeUpdate = null;
+ matchHeight._afterUpdate = null;
/*
- * $.fn.matchHeight._apply
+ * matchHeight._apply
* apply matchHeight to given elements
*/
- $.fn.matchHeight._apply = function(elements, byRow) {
+ matchHeight._apply = function(elements, byRow) {
var $elements = $(elements),
rows = [$elements];
@@ -208,18 +208,18 @@
$hiddenParents.css('display', '');
// restore scroll position if enabled
- if ($.fn.matchHeight._maintainScroll)
+ if (matchHeight._maintainScroll)
$(window).scrollTop((scrollTop / htmlHeight) * $('html').outerHeight(true));
return this;
};
/*
- * $.fn.matchHeight._applyDataApi
+ * matchHeight._applyDataApi
* applies matchHeight to all elements with a data-match-height attribute
*/
- $.fn.matchHeight._applyDataApi = function() {
+ matchHeight._applyDataApi = function() {
var groups = {};
// generate groups by their groupId set by elements using data-match-height
@@ -240,23 +240,23 @@
};
/*
- * $.fn.matchHeight._update
+ * matchHeight._update
* updates matchHeight on all current groups with their correct options
*/
var _update = function(event) {
- if ($.fn.matchHeight._beforeUpdate)
- $.fn.matchHeight._beforeUpdate(event, $.fn.matchHeight._groups);
+ if (matchHeight._beforeUpdate)
+ matchHeight._beforeUpdate(event, matchHeight._groups);
- $.each($.fn.matchHeight._groups, function() {
- $.fn.matchHeight._apply(this.elements, this.byRow);
+ $.each(matchHeight._groups, function() {
+ matchHeight._apply(this.elements, this.byRow);
});
- if ($.fn.matchHeight._afterUpdate)
- $.fn.matchHeight._afterUpdate(event, $.fn.matchHeight._groups);
+ if (matchHeight._afterUpdate)
+ matchHeight._afterUpdate(event, matchHeight._groups);
};
- $.fn.matchHeight._update = function(throttle, event) {
+ matchHeight._update = function(throttle, event) {
// prevent update if fired from a resize event
// where the viewport width hasn't actually changed
// fixes an event looping bug in IE8
@@ -274,7 +274,7 @@
_updateTimeout = setTimeout(function() {
_update(event);
_updateTimeout = -1;
- }, $.fn.matchHeight._throttle);
+ }, matchHeight._throttle);
}
};
@@ -283,16 +283,16 @@
*/
// apply on DOM ready event
- $($.fn.matchHeight._applyDataApi);
+ $(matchHeight._applyDataApi);
// update heights on load and resize events
$(window).bind('load', function(event) {
- $.fn.matchHeight._update(false, event);
+ matchHeight._update(false, event);
});
// throttled update heights on resize events
$(window).bind('resize orientationchange', function(event) {
- $.fn.matchHeight._update(true, event);
+ matchHeight._update(true, event);
});
})(jQuery);