jquery-matchheight-rails 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbc20c6cbaef094ae787206758d60ea8e997d982
4
- data.tar.gz: 6a649a9da63bd322d819d026e988410fd2005000
3
+ metadata.gz: dda21a54769de7c41dc9b8bde943b26bf06a91c1
4
+ data.tar.gz: 195c80927b650a26fe39dbc4d0472b6bee97e85c
5
5
  SHA512:
6
- metadata.gz: 17eda7a985c79ba3ab32813b33db7d54fc6976c7ba6829481fc23b15373427cbd252ba5655d77ba865cd42ab76bca76e072cb4d1b4a94d5e8d6b482120582d12
7
- data.tar.gz: 6b4cda254df17ff5909982cc028d8b3a4d2d4c0e5a47e3831f63653b23d10eb5b6741c8b756c972919a1d3baaaa9061f25fe8a3763adca0422558c31ea812495
6
+ metadata.gz: 4f7576692610b4206bd97ffe56ff38112bdd4e61921cf6ee845f7c8121127aef4d31b05b068185267516613e7fd2d4275aec542f11c49f43e9f0bec421625609
7
+ data.tar.gz: 2620efaa8a4466a32971fda0d5b940c896f95b0ba5236c9f56df5414d6f3cc77aa96b535e2b394e60e8d3f408cc55c5a7deb0973d2b70ad6fe22fa68fee9942b
@@ -1,7 +1,7 @@
1
1
  module Jquery
2
2
  module Matchheight
3
3
  module Rails
4
- VERSION = "0.5.0".freeze
4
+ VERSION = "0.5.1".freeze
5
5
  end
6
6
  end
7
7
  end
@@ -1,178 +1,227 @@
1
- /**
2
- * jquery.matchHeight.js v0.5.0
3
- * http://brm.io/jquery-match-height/
4
- * License: MIT
5
- */
6
-
7
- (function($) {
8
-
9
- $.fn.matchHeight = function(byRow) {
10
- if (this.length <= 1)
11
- return this;
12
-
13
- // byRow default to true
14
- byRow = (typeof byRow !== 'undefined') ? byRow : true;
15
-
16
- // keep track of this group so we can re-apply later on load and resize events
17
- $.fn.matchHeight._groups.push({
18
- elements: this,
19
- byRow: byRow
20
- });
21
-
22
- // match each element's height to the tallest element in the selection
23
- $.fn.matchHeight._apply(this, byRow);
24
-
25
- return this;
26
- };
27
-
28
- $.fn.matchHeight._apply = function(elements, byRow) {
29
- var $elements = $(elements),
30
- rows = [$elements];
31
-
32
- // get rows if using byRow, otherwise assume one row
33
- if (byRow) {
34
-
35
- // must first force an arbitrary equal height so floating elements break evenly
36
- $elements.css({
37
- 'display': 'block',
38
- 'padding-top': '0',
39
- 'padding-bottom': '0',
40
- 'border-top': '0',
41
- 'border-bottom': '0',
42
- 'height': '100px'
43
- });
44
-
45
- // get the array of rows (based on element top position)
46
- rows = _rows($elements);
47
-
48
- // revert the temporary forced style
49
- $elements.css({
50
- 'display': '',
51
- 'padding-top': '',
52
- 'padding-bottom': '',
53
- 'border-top': '',
54
- 'border-bottom': '',
55
- 'height': ''
56
- });
57
- }
58
-
59
- $.each(rows, function(key, row) {
60
- var $row = $(row),
61
- maxHeight = 0;
62
-
63
- // iterate the row and find the max height
64
- $row.each(function(){
65
- var $that = $(this);
66
-
67
- // ensure we get the correct actual height (and not a previously set height value)
68
- $that.css({ 'display': 'block', 'height': '' });
69
-
70
- // find the max height (including padding, but not margin)
71
- if ($that.outerHeight(false) > maxHeight)
72
- maxHeight = $that.outerHeight(false);
73
- });
74
-
75
- // iterate the row and apply the height to all elements
76
- $row.each(function(){
77
- var $that = $(this),
78
- verticalPadding = 0;
79
-
80
- // handle padding and border correctly (required when not using border-box)
81
- if ($that.css('box-sizing') !== 'border-box') {
82
- verticalPadding += parseInt($that.css('border-top-width'), 10) + parseInt($that.css('border-bottom-width'), 10);
83
- verticalPadding += parseInt($that.css('padding-top'), 10) + parseInt($that.css('padding-bottom'), 10);
84
- }
85
-
86
- // set the height (accounting for padding and border)
87
- $that.css('height', maxHeight - verticalPadding);
88
- });
89
- });
90
-
91
- return this;
92
- };
93
-
94
- /*
95
- * _applyDataApi will apply matchHeight to all elements with a data-match-height attribute
96
- */
97
-
98
- $.fn.matchHeight._applyDataApi = function() {
99
- var groups = {};
100
-
101
- // generate groups by their groupId set by elements using data-match-height
102
- $('[data-match-height], [data-mh]').each(function() {
103
- var $this = $(this),
104
- groupId = $this.attr('data-match-height');
105
- if (groupId in groups) {
106
- groups[groupId] = groups[groupId].add($this);
107
- } else {
108
- groups[groupId] = $this;
109
- }
110
- });
111
-
112
- // apply matchHeight to each group
113
- $.each(groups, function() {
114
- this.matchHeight(true);
115
- });
116
- };
117
-
118
- /*
119
- * _update function will re-apply matchHeight to all groups with the correct options
120
- */
121
-
122
- $.fn.matchHeight._groups = [];
123
-
124
- $.fn.matchHeight._update = function() {
125
- $.each($.fn.matchHeight._groups, function() {
126
- $.fn.matchHeight._apply(this.elements, this.byRow);
127
- });
128
- };
129
-
130
- /*
131
- * bind events
132
- */
133
-
134
- // apply on DOM ready event
135
- $($.fn.matchHeight._applyDataApi);
136
-
137
- // update heights on load and resize events
138
- $(window).on('load resize orientationchange', $.fn.matchHeight._update);
139
-
140
- /*
141
- * rows utility function
142
- * returns array of jQuery selections representing each row
143
- * (as displayed after float wrapping applied by browser)
144
- */
145
-
146
- var _rows = function(elements) {
147
- var tolerance = 1,
148
- $elements = $(elements),
149
- lastTop = null,
150
- rows = [];
151
-
152
- // group elements by their top position
153
- $elements.each(function(){
154
- var $that = $(this),
155
- top = $that.offset().top - parseInt($that.css('margin-top'), 10),
156
- lastRow = rows.length > 0 ? rows[rows.length - 1] : null;
157
-
158
- if (lastRow === null) {
159
- // first item on the row, so just push it
160
- rows.push($that);
161
- } else {
162
- // if the row top is the same, add to the row group
163
- if (Math.floor(Math.abs(lastTop - top)) <= tolerance) {
164
- rows[rows.length - 1] = lastRow.add($that);
165
- } else {
166
- // otherwise start a new row group
167
- rows.push($that);
168
- }
169
- }
170
-
171
- // keep track of the last row top
172
- lastTop = top;
173
- });
174
-
175
- return rows;
176
- };
177
-
1
+ /**
2
+ * jquery.matchHeight.js v0.5.1
3
+ * http://brm.io/jquery-match-height/
4
+ * License: MIT
5
+ */
6
+
7
+ (function($) {
8
+
9
+ $.fn.matchHeight = function(byRow) {
10
+
11
+ // handle matchHeight('remove')
12
+ if (byRow === 'remove') {
13
+ var that = this;
14
+
15
+ // remove fixed height from all selected elements
16
+ this.css('height', '');
17
+
18
+ // remove selected elements from all groups
19
+ $.each($.fn.matchHeight._groups, function(key, group) {
20
+ group.elements = group.elements.not(that);
21
+ });
22
+
23
+ // TODO: cleanup empty groups
24
+
25
+ return this;
26
+ }
27
+
28
+ if (this.length <= 1)
29
+ return this;
30
+
31
+ // byRow default to true
32
+ byRow = (typeof byRow !== 'undefined') ? byRow : true;
33
+
34
+ // keep track of this group so we can re-apply later on load and resize events
35
+ $.fn.matchHeight._groups.push({
36
+ elements: this,
37
+ byRow: byRow
38
+ });
39
+
40
+ // match each element's height to the tallest element in the selection
41
+ $.fn.matchHeight._apply(this, byRow);
42
+
43
+ return this;
44
+ };
45
+
46
+ $.fn.matchHeight._apply = function(elements, byRow) {
47
+ var $elements = $(elements),
48
+ rows = [$elements];
49
+
50
+ // get rows if using byRow, otherwise assume one row
51
+ if (byRow) {
52
+
53
+ // must first force an arbitrary equal height so floating elements break evenly
54
+ $elements.css({
55
+ 'display': 'block',
56
+ 'padding-top': '0',
57
+ 'padding-bottom': '0',
58
+ 'border-top': '0',
59
+ 'border-bottom': '0',
60
+ 'height': '100px'
61
+ });
62
+
63
+ // get the array of rows (based on element top position)
64
+ rows = _rows($elements);
65
+
66
+ // revert the temporary forced style
67
+ $elements.css({
68
+ 'display': '',
69
+ 'padding-top': '',
70
+ 'padding-bottom': '',
71
+ 'border-top': '',
72
+ 'border-bottom': '',
73
+ 'height': ''
74
+ });
75
+ }
76
+
77
+ $.each(rows, function(key, row) {
78
+ var $row = $(row),
79
+ maxHeight = 0;
80
+
81
+ // iterate the row and find the max height
82
+ $row.each(function(){
83
+ var $that = $(this);
84
+
85
+ // ensure we get the correct actual height (and not a previously set height value)
86
+ $that.css({ 'display': 'block', 'height': '' });
87
+
88
+ // find the max height (including padding, but not margin)
89
+ if ($that.outerHeight(false) > maxHeight)
90
+ maxHeight = $that.outerHeight(false);
91
+
92
+ // revert display block
93
+ $that.css({ 'display': '' });
94
+ });
95
+
96
+ // iterate the row and apply the height to all elements
97
+ $row.each(function(){
98
+ var $that = $(this),
99
+ verticalPadding = 0;
100
+
101
+ // handle padding and border correctly (required when not using border-box)
102
+ if ($that.css('box-sizing') !== 'border-box') {
103
+ verticalPadding += _parse($that.css('border-top-width')) + _parse($that.css('border-bottom-width'));
104
+ verticalPadding += _parse($that.css('padding-top')) + _parse($that.css('padding-bottom'));
105
+ }
106
+
107
+ // set the height (accounting for padding and border)
108
+ $that.css('height', maxHeight - verticalPadding);
109
+ });
110
+ });
111
+
112
+ return this;
113
+ };
114
+
115
+ /*
116
+ * _applyDataApi will apply matchHeight to all elements with a data-match-height attribute
117
+ */
118
+
119
+ $.fn.matchHeight._applyDataApi = function() {
120
+ var groups = {};
121
+
122
+ // generate groups by their groupId set by elements using data-match-height
123
+ $('[data-match-height], [data-mh]').each(function() {
124
+ var $this = $(this),
125
+ groupId = $this.attr('data-match-height');
126
+ if (groupId in groups) {
127
+ groups[groupId] = groups[groupId].add($this);
128
+ } else {
129
+ groups[groupId] = $this;
130
+ }
131
+ });
132
+
133
+ // apply matchHeight to each group
134
+ $.each(groups, function() {
135
+ this.matchHeight(true);
136
+ });
137
+ };
138
+
139
+ /*
140
+ * _update function will re-apply matchHeight to all groups with the correct options
141
+ */
142
+
143
+ $.fn.matchHeight._groups = [];
144
+ $.fn.matchHeight._throttle = 80;
145
+
146
+ var previousResizeWidth = -1,
147
+ updateTimeout = -1;
148
+
149
+ $.fn.matchHeight._update = function(event) {
150
+ // prevent update if fired from a resize event
151
+ // where the viewport width hasn't actually changed
152
+ // fixes an event looping bug in IE8
153
+ if (event && event.type === 'resize') {
154
+ var windowWidth = $(window).width();
155
+ if (windowWidth === previousResizeWidth)
156
+ return;
157
+ previousResizeWidth = windowWidth;
158
+ }
159
+
160
+ // throttle updates
161
+ if (updateTimeout === -1) {
162
+ updateTimeout = setTimeout(function() {
163
+
164
+ $.each($.fn.matchHeight._groups, function() {
165
+ $.fn.matchHeight._apply(this.elements, this.byRow);
166
+ });
167
+
168
+ updateTimeout = -1;
169
+
170
+ }, $.fn.matchHeight._throttle);
171
+ }
172
+ };
173
+
174
+ /*
175
+ * bind events
176
+ */
177
+
178
+ // apply on DOM ready event
179
+ $($.fn.matchHeight._applyDataApi);
180
+
181
+ // update heights on load and resize events
182
+ $(window).bind('load resize orientationchange', $.fn.matchHeight._update);
183
+
184
+ /*
185
+ * rows utility function
186
+ * returns array of jQuery selections representing each row
187
+ * (as displayed after float wrapping applied by browser)
188
+ */
189
+
190
+ var _rows = function(elements) {
191
+ var tolerance = 1,
192
+ $elements = $(elements),
193
+ lastTop = null,
194
+ rows = [];
195
+
196
+ // group elements by their top position
197
+ $elements.each(function(){
198
+ var $that = $(this),
199
+ top = $that.offset().top - _parse($that.css('margin-top')),
200
+ lastRow = rows.length > 0 ? rows[rows.length - 1] : null;
201
+
202
+ if (lastRow === null) {
203
+ // first item on the row, so just push it
204
+ rows.push($that);
205
+ } else {
206
+ // if the row top is the same, add to the row group
207
+ if (Math.floor(Math.abs(lastTop - top)) <= tolerance) {
208
+ rows[rows.length - 1] = lastRow.add($that);
209
+ } else {
210
+ // otherwise start a new row group
211
+ rows.push($that);
212
+ }
213
+ }
214
+
215
+ // keep track of the last row top
216
+ lastTop = top;
217
+ });
218
+
219
+ return rows;
220
+ };
221
+
222
+ var _parse = function(value) {
223
+ // parse value and convert NaN to 0
224
+ return parseFloat(value) || 0;
225
+ };
226
+
178
227
  })(jQuery);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-matchheight-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Dias