jquery-matchheight-rails 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fbc20c6cbaef094ae787206758d60ea8e997d982
4
+ data.tar.gz: 6a649a9da63bd322d819d026e988410fd2005000
5
+ SHA512:
6
+ metadata.gz: 17eda7a985c79ba3ab32813b33db7d54fc6976c7ba6829481fc23b15373427cbd252ba5655d77ba865cd42ab76bca76e072cb4d1b4a94d5e8d6b482120582d12
7
+ data.tar.gz: 6b4cda254df17ff5909982cc028d8b3a4d2d4c0e5a47e3831f63653b23d10eb5b6741c8b756c972919a1d3baaaa9061f25fe8a3763adca0422558c31ea812495
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery-matchheight-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Liam Brummitt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Jquery::Matchheight::Rails
2
+
3
+ [jquery.matchHeight.js](https://github.com/liabru/jquery-match-height/) for the Rails Asset Pipeline.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'jquery-matchheight-rails'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install jquery-matchheight-rails
21
+
22
+
23
+ ## Usage
24
+
25
+ Add, at least, the following to your JavaScript [manifest file](http://guides.rubyonrails.org/asset_pipeline.html#manifest-files-and-directives):
26
+
27
+ ```js
28
+ //= require jquery.matchHeight
29
+ ```
30
+
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dassump/jquery-matchheight-rails.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jquery/matchheight/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jquery-matchheight-rails"
8
+ spec.version = Jquery::Matchheight::Rails::VERSION
9
+ spec.authors = ["Daniel Dias"]
10
+ spec.email = ["dassump@gmail.com"]
11
+
12
+ spec.summary = %q{jquery.matchHeight.js for the Rails Asset Pipeline}
13
+ spec.description = %q{matchHeight makes the height of all selected elements exactly equal}
14
+ spec.homepage = "https://github.com/dassump/jquery-matchheight-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.require_paths = ["lib"]
22
+ end
@@ -0,0 +1 @@
1
+ require "jquery/matchheight/rails"
@@ -0,0 +1,9 @@
1
+ require "jquery/matchheight/rails/version"
2
+ require "jquery/matchheight/rails/engine" if ::Rails.version >= "3.1"
3
+
4
+ module Jquery
5
+ module Matchheight
6
+ module Rails
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Jquery
2
+ module Matchheight
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module Matchheight
3
+ module Rails
4
+ VERSION = "0.5.0".freeze
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,178 @@
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
+
178
+ })(jQuery);
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-matchheight-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Dias
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: matchHeight makes the height of all selected elements exactly equal
14
+ email:
15
+ - dassump@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE
23
+ - README.md
24
+ - Rakefile
25
+ - jquery-matchheight-rails.gemspec
26
+ - lib/jquery-matchheight-rails.rb
27
+ - lib/jquery/matchheight/rails.rb
28
+ - lib/jquery/matchheight/rails/engine.rb
29
+ - lib/jquery/matchheight/rails/version.rb
30
+ - vendor/assets/javascripts/jquery.matchHeight.js
31
+ homepage: https://github.com/dassump/jquery-matchheight-rails
32
+ licenses:
33
+ - MIT
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.6.10
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: jquery.matchHeight.js for the Rails Asset Pipeline
55
+ test_files: []