bigtextjs_rails 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bigtextjs_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Guy Israeli
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.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # BigtextjsRails
2
+
3
+ BigText Makes Text Big. This gem will help you do it the rails way.
4
+
5
+ See the demo http://www.zachleat.com/bigtext/demo/
6
+
7
+ and see here for docs
8
+ https://github.com/zachleat/BigText
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'bigtextjs_rails'
15
+
16
+ requires jQuery
17
+
18
+ and add
19
+
20
+ //= require bigtext
21
+
22
+ to application.js
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install bigtextjs_rails
31
+
32
+ ## Usage
33
+
34
+ see here for docs
35
+ https://github.com/zachleat/BigText
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,295 @@
1
+ /*! BigText - v0.1.4 - 2013-08-24
2
+ * https://github.com/zachleat/BigText
3
+ * Copyright (c) 2013 @zachleat; Licensed MIT
4
+ */
5
+
6
+ ;(function(window, $) {
7
+ var counter = 0,
8
+ $headCache = $('head'),
9
+ oldBigText = window.BigText,
10
+ oldjQueryMethod = $.fn.bigtext,
11
+ BigText = {
12
+ DEBUG_MODE: false,
13
+ DEFAULT_MIN_FONT_SIZE_PX: null,
14
+ DEFAULT_MAX_FONT_SIZE_PX: 528,
15
+ GLOBAL_STYLE_ID: 'bigtext-style',
16
+ STYLE_ID: 'bigtext-id',
17
+ LINE_CLASS_PREFIX: 'bigtext-line',
18
+ EXEMPT_CLASS: 'bigtext-exempt',
19
+ DEFAULT_CHILD_SELECTOR: '> div',
20
+ childSelectors: {
21
+ div: '> div',
22
+ ol: '> li',
23
+ ul: '> li'
24
+ },
25
+ noConflict: function(restore)
26
+ {
27
+ if(restore) {
28
+ $.fn.bigtext = oldjQueryMethod;
29
+ window.BigText = oldBigText;
30
+ }
31
+ return BigText;
32
+ },
33
+ test: {
34
+ noFractionalFontSize: (function() {
35
+ if( !( 'getComputedStyle' in window ) || !( 'body' in document ) ) {
36
+ return true;
37
+ }
38
+ var test = $('<div/>').css({
39
+ position: 'absolute',
40
+ 'font-size': '14.1px'
41
+ }).appendTo(document.body).get(0),
42
+ computedStyle = window.getComputedStyle( test, null );
43
+
44
+ return computedStyle ? computedStyle.getPropertyValue( 'font-size' ) === '14px' : true;
45
+ })()
46
+ },
47
+ init: function() {
48
+ if(!$('#'+BigText.GLOBAL_STYLE_ID).length) {
49
+ $headCache.append(BigText.generateStyleTag(BigText.GLOBAL_STYLE_ID, ['.bigtext * { white-space: nowrap; } .bigtext > * { display: block; }',
50
+ '.bigtext .' + BigText.EXEMPT_CLASS + ', .bigtext .' + BigText.EXEMPT_CLASS + ' * { white-space: normal; }']));
51
+ }
52
+ },
53
+ bindResize: function(eventName, resizeFunction) {
54
+ if($.throttle) {
55
+ // https://github.com/cowboy/jquery-throttle-debounce
56
+ $(window).unbind(eventName).bind(eventName, $.throttle(100, resizeFunction));
57
+ } else {
58
+ if($.fn.smartresize) {
59
+ // https://github.com/lrbabe/jquery-smartresize/
60
+ eventName = 'smartresize.' + eventName;
61
+ }
62
+ $(window).unbind(eventName).bind(eventName, resizeFunction);
63
+ }
64
+ },
65
+ getStyleId: function(id)
66
+ {
67
+ return BigText.STYLE_ID + '-' + id;
68
+ },
69
+ generateStyleTag: function(id, css)
70
+ {
71
+ return $('<style>' + css.join('\n') + '</style>').attr('id', id);
72
+ },
73
+ clearCss: function(id)
74
+ {
75
+ var styleId = BigText.getStyleId(id);
76
+ $('#' + styleId).remove();
77
+ },
78
+ generateCss: function(id, linesFontSizes, lineWordSpacings, minFontSizes)
79
+ {
80
+ var css = [];
81
+
82
+ BigText.clearCss(id);
83
+
84
+ for(var j=0, k=linesFontSizes.length; j<k; j++) {
85
+ css.push('#' + id + ' .' + BigText.LINE_CLASS_PREFIX + j + ' {' +
86
+ (minFontSizes[j] ? ' white-space: normal;' : '') +
87
+ (linesFontSizes[j] ? ' font-size: ' + linesFontSizes[j] + 'px;' : '') +
88
+ (lineWordSpacings[j] ? ' word-spacing: ' + lineWordSpacings[j] + 'px;' : '') +
89
+ '}');
90
+ }
91
+
92
+ return BigText.generateStyleTag(BigText.getStyleId(id), css);
93
+ },
94
+ jQueryMethod: function(options)
95
+ {
96
+ BigText.init();
97
+
98
+ options = $.extend({
99
+ minfontsize: BigText.DEFAULT_MIN_FONT_SIZE_PX,
100
+ maxfontsize: BigText.DEFAULT_MAX_FONT_SIZE_PX,
101
+ childSelector: '',
102
+ resize: true
103
+ }, options || {});
104
+
105
+ return this.each(function()
106
+ {
107
+ var $t = $(this).addClass('bigtext'),
108
+ childSelector = options.childSelector ||
109
+ BigText.childSelectors[this.tagName.toLowerCase()] ||
110
+ BigText.DEFAULT_CHILD_SELECTOR,
111
+ maxWidth = $t.width(),
112
+ id = $t.attr('id');
113
+
114
+ if(!id) {
115
+ id = 'bigtext-id' + (counter++);
116
+ $t.attr('id', id);
117
+ }
118
+
119
+ if(options.resize) {
120
+ BigText.bindResize('resize.bigtext-event-' + id, function()
121
+ {
122
+ // TODO only call this if the width has changed.
123
+ BigText.jQueryMethod.call($('#' + id), options);
124
+ });
125
+ }
126
+
127
+ BigText.clearCss(id);
128
+
129
+ $t.find(childSelector).addClass(function(lineNumber, className)
130
+ {
131
+ // remove existing line classes.
132
+ return [className.replace(new RegExp('\\b' + BigText.LINE_CLASS_PREFIX + '\\d+\\b'), ''),
133
+ BigText.LINE_CLASS_PREFIX + lineNumber].join(' ');
134
+ });
135
+
136
+ var sizes = calculateSizes($t, childSelector, maxWidth, options.maxfontsize, options.minfontsize);
137
+ $headCache.append(BigText.generateCss(id, sizes.fontSizes, sizes.wordSpacings, sizes.minFontSizes));
138
+ });
139
+ }
140
+ };
141
+
142
+ function testLineDimensions($line, maxWidth, property, size, interval, units, previousWidth)
143
+ {
144
+ var width,
145
+ previousWidth = typeof previousWidth == 'number' ? previousWidth : 0;
146
+ $line.css(property, size + units);
147
+
148
+ width = $line.width();
149
+
150
+ if(width >= maxWidth) {
151
+ // console.log(width, ' previous: ' + previousWidth, property + ' at ' + interval, 'prior: ' + (parseFloat(size) - interval), 'new:' + parseFloat(size));
152
+ $line.css(property, '');
153
+
154
+ if(width == maxWidth) {
155
+ return {
156
+ match: 'exact',
157
+ size: parseFloat((parseFloat(size) - 0.1).toFixed(3))
158
+ };
159
+ }
160
+
161
+ // Since this is an estimate, we calculate how far over the width we went with the new value.
162
+ // If this is word-spacing (our last resort guess) and the over is less than the under, we keep the higher value.
163
+ // Otherwise, we revert to the underestimate.
164
+ var under = maxWidth - previousWidth,
165
+ over = width - maxWidth;
166
+
167
+ return {
168
+ match: 'estimate',
169
+ size: parseFloat((parseFloat(size) - (property === 'word-spacing' && previousWidth && ( over < under ) ? 0 : interval)).toFixed(3))
170
+ };
171
+ }
172
+
173
+ return width;
174
+ }
175
+
176
+ function calculateSizes($t, childSelector, maxWidth, maxFontSize, minFontSize)
177
+ {
178
+ var $c = $t.clone(true)
179
+ .addClass('bigtext-cloned')
180
+ .css({
181
+ fontFamily: $t.css('font-family'),
182
+ textTransform: $t.css('text-transform'),
183
+ wordSpacing: $t.css('word-spacing'),
184
+ letterSpacing: $t.css('letter-spacing'),
185
+ position: 'absolute',
186
+ left: BigText.DEBUG_MODE ? 0 : -9999,
187
+ top: BigText.DEBUG_MODE ? 0 : -9999
188
+ }).appendTo(document.body);
189
+
190
+ // font-size isn't the only thing we can modify, we can also mess with:
191
+ // word-spacing and letter-spacing. WebKit does not respect subpixel
192
+ // letter-spacing, word-spacing, or font-size.
193
+ // TODO try -webkit-transform: scale() as a workaround.
194
+ var fontSizes = [],
195
+ wordSpacings = [],
196
+ minFontSizes = [],
197
+ ratios = [];
198
+
199
+ $c.find(childSelector).css('float', 'left').each(function(lineNumber) {
200
+ var $line = $(this),
201
+ // TODO replace 8, 4 with a proportional size to the calculated font-size.
202
+ intervals = BigText.test.noFractionalFontSize ? [8, 4, 1] : [8, 4, 1, 0.1],
203
+ lineMax;
204
+
205
+ if($line.hasClass(BigText.EXEMPT_CLASS)) {
206
+ fontSizes.push(null);
207
+ ratios.push(null);
208
+ minFontSizes.push(false);
209
+ return;
210
+ }
211
+
212
+ // TODO we can cache this ratio?
213
+ var autoGuessSubtraction = 32, // font size in px
214
+ currentFontSize = parseFloat($line.css('font-size')),
215
+ ratio = ( $line.width() / currentFontSize ).toFixed(6);
216
+
217
+ newFontSize = parseInt( maxWidth / ratio, 10 ) - autoGuessSubtraction;
218
+
219
+ outer: for(var m=0, n=intervals.length; m<n; m++) {
220
+ inner: for(var j=1, k=10; j<=k; j++) {
221
+ if(newFontSize + j*intervals[m] > maxFontSize) {
222
+ newFontSize = maxFontSize;
223
+ break outer;
224
+ }
225
+
226
+ lineMax = testLineDimensions($line, maxWidth, 'font-size', newFontSize + j*intervals[m], intervals[m], 'px', lineMax);
227
+ if(typeof lineMax !== 'number') {
228
+ newFontSize = lineMax.size;
229
+
230
+ if(lineMax.match == 'exact') {
231
+ break outer;
232
+ }
233
+ break inner;
234
+ }
235
+ }
236
+ }
237
+
238
+ ratios.push(maxWidth / newFontSize);
239
+
240
+ if(newFontSize > maxFontSize) {
241
+ fontSizes.push(maxFontSize);
242
+ minFontSizes.push(false);
243
+ } else if(!!minFontSize && newFontSize < minFontSize) {
244
+ fontSizes.push(minFontSize);
245
+ minFontSizes.push(true);
246
+ } else {
247
+ fontSizes.push(newFontSize);
248
+ minFontSizes.push(false);
249
+ }
250
+ }).each(function(lineNumber) {
251
+ var $line = $(this),
252
+ wordSpacing = 0,
253
+ interval = 1,
254
+ maxWordSpacing;
255
+
256
+ if($line.hasClass(BigText.EXEMPT_CLASS)) {
257
+ wordSpacings.push(null);
258
+ return;
259
+ }
260
+
261
+ // must re-use font-size, even though it was removed above.
262
+ $line.css('font-size', fontSizes[lineNumber] + 'px');
263
+
264
+ for(var m=1, n=3; m<n; m+=interval) {
265
+ maxWordSpacing = testLineDimensions($line, maxWidth, 'word-spacing', m, interval, 'px', maxWordSpacing);
266
+ if(typeof maxWordSpacing !== 'number') {
267
+ wordSpacing = maxWordSpacing.size;
268
+ break;
269
+ }
270
+ }
271
+
272
+ $line.css('font-size', '');
273
+ wordSpacings.push(wordSpacing);
274
+ }).removeAttr('style');
275
+
276
+ if( !BigText.DEBUG_MODE ) {
277
+ $c.remove();
278
+ } else {
279
+ $c.css({
280
+ 'background-color': 'rgba(255,255,255,.4)'
281
+ });
282
+ }
283
+
284
+ return {
285
+ fontSizes: fontSizes,
286
+ wordSpacings: wordSpacings,
287
+ ratios: ratios,
288
+ minFontSizes: minFontSizes
289
+ };
290
+ }
291
+
292
+ $.fn.bigtext = BigText.jQueryMethod;
293
+ window.BigText = BigText;
294
+
295
+ })(this, jQuery);
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bigtextjs_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bigtextjs_rails"
8
+ spec.version = BigtextjsRails::VERSION
9
+ spec.authors = ["Guy Israeli"]
10
+ spec.description = %q{This is an asset pipeline wrapper for the awesome bigtext.js}
11
+ spec.summary = %q{BigText Makes Text Big. This gem will help you do it the rails way.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_dependency "railties", ">= 3.1"
23
+
24
+ end
@@ -0,0 +1,3 @@
1
+ module BigtextjsRails
2
+ VERSION = "0.1.4"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "bigtextjs_rails/version"
2
+
3
+ module BigtextjsRails
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bigtextjs_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Guy Israeli
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: railties
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '3.1'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ description: This is an asset pipeline wrapper for the awesome bigtext.js
63
+ email:
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - .gitignore
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - app/assets/javascripts/bigtext.js
74
+ - bigtextjs_rails.gemspec
75
+ - lib/bigtextjs_rails.rb
76
+ - lib/bigtextjs_rails/version.rb
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.24
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: BigText Makes Text Big. This gem will help you do it the rails way.
102
+ test_files: []