textfill_rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a09da61355a5b3f18068049407b9a3d336624bcd
4
+ data.tar.gz: fe3027d5247d7e9eb7c5484f2efbfe819e910385
5
+ SHA512:
6
+ metadata.gz: 8e29ab11a0ce3820ace39e44dc85314de519be78488b3a64e980ef3a33cb9dd627fe9fa9373c4411ac8ff6d5f017cb26fb1f6525ee3f8c11891a205c130fc6c6
7
+ data.tar.gz: a3e6fc83f2ff6bae6d3897c49c9ca7af15d53d30833683173ba2f772e89a38acd4dbc7f582fd5f8d67c5998b36eb91d49509fee2a6c5339fd8345da594a28e2e
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ .config
4
+ Gemfile.lock
5
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in textfill_rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Steven Spiel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # TextfillRails
2
+
3
+ textfill_rails wraps the [textfill.js](http://jquery-textfill.github.io/) library in a rails engine for simple use with the asset pipeline provided by rails 3.1 and up. The gem includes the development (non-minified) source for ease of exploration. the asset pipleline will do the heavy lifting and minify it for you in production.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'textfill_rails'
11
+
12
+ Add the following directive to your Javascript manifest file below the jquery directive (application.js):
13
+
14
+ //= require textfill
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install textfill_rails
23
+
24
+ ## Usage
25
+
26
+ just use it as your would normally would
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
35
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,324 @@
1
+ /**
2
+ * @preserve textfill
3
+ * @name jquery.textfill.js
4
+ * @author Russ Painter
5
+ * @author Yu-Jie Lin
6
+ * @author Alexandre Dantas
7
+ * @version 0.6.0
8
+ * @date 2014-08-19
9
+ * @copyright (c) 2014 Alexandre Dantas
10
+ * @copyright (c) 2012-2013 Yu-Jie Lin
11
+ * @copyright (c) 2009 Russ Painter
12
+ * @license MIT License
13
+ * @homepage https://github.com/jquery-textfill/jquery-textfill
14
+ * @example http://jquery-textfill.github.io/jquery-textfill/index.html
15
+ */
16
+ ; (function($) {
17
+
18
+ /**
19
+ * Resizes an inner element's font so that the
20
+ * inner element completely fills the outer element.
21
+ *
22
+ * @param {Object} options User options that take
23
+ * higher precedence when
24
+ * merging with the default ones.
25
+ *
26
+ * @return All outer elements processed
27
+ */
28
+ $.fn.textfill = function(options) {
29
+
30
+ // ______ _______ _______ _______ _ _ _______ _______
31
+ // | \ |______ |______ |_____| | | | | |______
32
+ // |_____/ |______ | | | |_____| |_____ | ______|
33
+ //
34
+ // Merging user options with the default values
35
+
36
+ var defaults = {
37
+ debug : false,
38
+ maxFontPixels : 40,
39
+ minFontPixels : 4,
40
+ innerTag : 'span',
41
+ widthOnly : false,
42
+ success : null, // callback when a resizing is done
43
+ callback : null, // callback when a resizing is done (deprecated, use success)
44
+ fail : null, // callback when a resizing is failed
45
+ complete : null, // callback when all is done
46
+ explicitWidth : null,
47
+ explicitHeight : null,
48
+ changeLineHeight : false
49
+ };
50
+
51
+ var Opts = $.extend(defaults, options);
52
+
53
+ // _______ _ _ __ _ _______ _______ _____ _____ __ _ _______
54
+ // |______ | | | \ | | | | | | | \ | |______
55
+ // | |_____| | \_| |_____ | __|__ |_____| | \_| ______|
56
+ //
57
+ // Predefining the awesomeness
58
+
59
+ // Output arguments to the Debug console
60
+ // if "Debug Mode" is enabled
61
+ function _debug() {
62
+ if (!Opts.debug
63
+ || typeof console == 'undefined'
64
+ || typeof console.debug == 'undefined') {
65
+ return;
66
+ }
67
+ console.debug.apply(console, arguments);
68
+ }
69
+
70
+ // Output arguments to the Warning console
71
+ function _warn() {
72
+ if (typeof console == 'undefined' ||
73
+ typeof console.warn == 'undefined') {
74
+ return;
75
+ }
76
+ console.warn.apply(console, arguments);
77
+ }
78
+
79
+ // Outputs all information on the current sizing
80
+ // of the font.
81
+ function _debug_sizing(prefix, ourText, maxHeight, maxWidth, minFontPixels, maxFontPixels) {
82
+
83
+ function _m(v1, v2) {
84
+
85
+ var marker = ' / ';
86
+
87
+ if (v1 > v2)
88
+ marker = ' > ';
89
+
90
+ else if (v1 == v2)
91
+ marker = ' = ';
92
+
93
+ return marker;
94
+ }
95
+
96
+ _debug(
97
+ '[TextFill] ' + prefix + ' { ' +
98
+ 'font-size: ' + ourText.css('font-size') + ',' +
99
+ 'Height: ' + ourText.height() + 'px ' + _m(ourText.height(), maxHeight) + maxHeight + 'px,' +
100
+ 'Width: ' + ourText.width() + _m(ourText.width() , maxWidth) + maxWidth + ',' +
101
+ 'minFontPixels: ' + minFontPixels + 'px, ' +
102
+ 'maxFontPixels: ' + maxFontPixels + 'px }'
103
+ );
104
+ }
105
+
106
+ /**
107
+ * Calculates which size the font can get resized,
108
+ * according to constrains.
109
+ *
110
+ * @param {String} prefix Gets shown on the console before
111
+ * all the arguments, if debug mode is on.
112
+ * @param {Object} ourText The DOM element to resize,
113
+ * that contains the text.
114
+ * @param {function} func Function called on `ourText` that's
115
+ * used to compare with `max`.
116
+ * @param {number} max Maximum value, that gets compared with
117
+ * `func` called on `ourText`.
118
+ * @param {number} minFontPixels Minimum value the font can
119
+ * get resized to (in pixels).
120
+ * @param {number} maxFontPixels Maximum value the font can
121
+ * get resized to (in pixels).
122
+ *
123
+ * @return Size (in pixels) that the font can be resized.
124
+ */
125
+ function _sizing(prefix, ourText, func, max, maxHeight, maxWidth, minFontPixels, maxFontPixels) {
126
+
127
+ _debug_sizing(
128
+ prefix, ourText,
129
+ maxHeight, maxWidth,
130
+ minFontPixels, maxFontPixels
131
+ );
132
+
133
+ // The kernel of the whole plugin, take most attention
134
+ // on this part.
135
+ //
136
+ // This is a loop that keeps increasing the `font-size`
137
+ // until it fits the parent element.
138
+ //
139
+ // - Start from the minimal allowed value (`minFontPixels`)
140
+ // - Guesses an average font size (in pixels) for the font,
141
+ // - Resizes the text and sees if its size is within the
142
+ // boundaries (`minFontPixels` and `maxFontPixels`).
143
+ // - If so, keep guessing until we break.
144
+ // - If not, return the last calculated size.
145
+ //
146
+ // I understand this is not optimized and we should
147
+ // consider implementing something akin to
148
+ // Daniel Hoffmann's answer here:
149
+ //
150
+ // http://stackoverflow.com/a/17433451/1094964
151
+ //
152
+
153
+ while (minFontPixels < (maxFontPixels - 1)) {
154
+
155
+ var fontSize = Math.floor((minFontPixels + maxFontPixels) / 2);
156
+ ourText.css('font-size', fontSize);
157
+
158
+ if (func.call(ourText) <= max) {
159
+ minFontPixels = fontSize;
160
+
161
+ if (func.call(ourText) == max)
162
+ break;
163
+ }
164
+ else
165
+ maxFontPixels = fontSize;
166
+
167
+ _debug_sizing(
168
+ prefix, ourText,
169
+ maxHeight, maxWidth,
170
+ minFontPixels, maxFontPixels
171
+ );
172
+ }
173
+
174
+ ourText.css('font-size', maxFontPixels);
175
+
176
+ if (func.call(ourText) <= max) {
177
+ minFontPixels = maxFontPixels;
178
+
179
+ _debug_sizing(
180
+ prefix + '* ', ourText,
181
+ maxHeight, maxWidth,
182
+ minFontPixels, maxFontPixels
183
+ );
184
+ }
185
+ return minFontPixels;
186
+ }
187
+
188
+ // _______ _______ _______ ______ _______
189
+ // |______ | |_____| |_____/ |
190
+ // ______| | | | | \_ |
191
+ //
192
+ // Let's get it started (yeah)!
193
+
194
+ _debug('[TextFill] Start Debug');
195
+
196
+ this.each(function() {
197
+
198
+ // Contains the child element we will resize.
199
+ // $(this) means the parent container
200
+ var ourText = $(Opts.innerTag + ':visible:first', this);
201
+
202
+ // Will resize to this dimensions.
203
+ // Use explicit dimensions when specified
204
+ var maxHeight = Opts.explicitHeight || $(this).height();
205
+ var maxWidth = Opts.explicitWidth || $(this).width();
206
+
207
+ var oldFontSize = ourText.css('font-size');
208
+
209
+ var lineHeight = parseFloat(ourText.css('line-height')) / parseFloat(oldFontSize);
210
+
211
+ _debug('[TextFill] Inner text: ' + ourText.text());
212
+ _debug('[TextFill] All options: ', Opts);
213
+ _debug('[TextFill] Maximum sizes: { ' +
214
+ 'Height: ' + maxHeight + 'px, ' +
215
+ 'Width: ' + maxWidth + 'px' + ' }'
216
+ );
217
+
218
+ var minFontPixels = Opts.minFontPixels;
219
+
220
+ // Remember, if this `maxFontPixels` is negative,
221
+ // the text will resize to as long as the container
222
+ // can accomodate
223
+ var maxFontPixels = (Opts.maxFontPixels <= 0 ?
224
+ maxHeight :
225
+ Opts.maxFontPixels);
226
+
227
+
228
+ // Let's start it all!
229
+
230
+ // 1. Calculate which `font-size` would
231
+ // be best for the Height
232
+ var fontSizeHeight = undefined;
233
+
234
+ if (! Opts.widthOnly)
235
+ fontSizeHeight = _sizing(
236
+ 'Height', ourText,
237
+ $.fn.height, maxHeight,
238
+ maxHeight, maxWidth,
239
+ minFontPixels, maxFontPixels
240
+ );
241
+
242
+ // 2. Calculate which `font-size` would
243
+ // be best for the Width
244
+ var fontSizeWidth = undefined;
245
+
246
+ fontSizeWidth = _sizing(
247
+ 'Width', ourText,
248
+ $.fn.width, maxWidth,
249
+ maxHeight, maxWidth,
250
+ minFontPixels, maxFontPixels
251
+ );
252
+
253
+ // 3. Actually resize the text!
254
+
255
+ if (Opts.widthOnly) {
256
+ ourText.css({
257
+ 'font-size' : fontSizeWidth,
258
+ 'white-space': 'nowrap'
259
+ });
260
+
261
+ if (Opts.changeLineHeight)
262
+ ourText.parent().css(
263
+ 'line-height',
264
+ (lineHeight * fontSizeWidth + 'px')
265
+ );
266
+ }
267
+ else {
268
+ var fontSizeFinal = Math.min(fontSizeHeight, fontSizeWidth);
269
+
270
+ ourText.css('font-size', fontSizeFinal);
271
+
272
+ if (Opts.changeLineHeight)
273
+ ourText.parent().css(
274
+ 'line-height',
275
+ (lineHeight * fontSizeFinal) + 'px'
276
+ );
277
+ }
278
+
279
+ _debug(
280
+ '[TextFill] Finished { ' +
281
+ 'Old font-size: ' + oldFontSize + ', ' +
282
+ 'New font-size: ' + ourText.css('font-size') + ' }'
283
+ );
284
+
285
+ // Oops, something wrong happened!
286
+ // We weren't supposed to exceed the original size
287
+ if ((ourText.width() > maxWidth) ||
288
+ (ourText.height() > maxHeight && !Opts.widthOnly)) {
289
+
290
+ ourText.css('font-size', oldFontSize);
291
+
292
+ // Failure callback
293
+ if (Opts.fail)
294
+ Opts.fail(this);
295
+
296
+ _debug(
297
+ '[TextFill] Failure { ' +
298
+ 'Current Width: ' + ourText.width() + ', ' +
299
+ 'Maximum Width: ' + maxWidth + ', ' +
300
+ 'Current Height: ' + ourText.height() + ', ' +
301
+ 'Maximum Height: ' + maxHeight + ' }'
302
+ );
303
+ }
304
+ else if (Opts.success) {
305
+ Opts.success(this);
306
+ }
307
+ else if (Opts.callback) {
308
+ _warn('callback is deprecated, use success, instead');
309
+
310
+ // Success callback
311
+ Opts.callback(this);
312
+ }
313
+ });
314
+
315
+ // Complete callback
316
+ if (Opts.complete)
317
+ Opts.complete(this);
318
+
319
+ _debug('[TextFill] End Debug');
320
+ return this;
321
+ };
322
+
323
+ })(window.jQuery);
324
+
@@ -0,0 +1,8 @@
1
+ require "textfill_rails/version"
2
+
3
+ module TextfillRails
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module TextfillRails
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'textfill_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "textfill_rails"
8
+ spec.version = TextfillRails::VERSION
9
+ spec.authors = ["Steven Spiel"]
10
+ spec.description = "TextfillRails as a gem for Rails 3.1+,4"
11
+ spec.summary = "Textfill is awesome"
12
+ spec.homepage = "https://github.com/stevenspiel/textfill_rails"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_dependency "railties", ">=3.1"
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: textfill_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Steven Spiel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ description: TextfillRails as a gem for Rails 3.1+,4
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - Gemfile
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - app/assets/javascripts/textfill.js
67
+ - lib/textfill_rails.rb
68
+ - lib/textfill_rails/version.rb
69
+ - textfill_rails.gemspec
70
+ homepage: https://github.com/stevenspiel/textfill_rails
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.2.1
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Textfill is awesome
94
+ test_files: []