jquery-elastic-rails 1.6.11

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Devin Zhang
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,31 @@
1
+ # Jquery-Elastic-Rails
2
+
3
+ A gem to automate using jQuery Elastic plugin with Rails 3.
4
+
5
+ See (http://www.unwrongest.com/projects/elastic) for more info.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'jquery-elastic-rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install jquery-elastic-rails
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require "jquery-elastic-rails/version"
2
+
3
+ module Jquery
4
+ module Elastic
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module Elastic
3
+ module Rails
4
+ VERSION = "1.6.11"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,164 @@
1
+ /**
2
+ * @name Elastic
3
+ * @descripton Elastic is jQuery plugin that grow and shrink your textareas automatically
4
+ * @version 1.6.11
5
+ * @requires jQuery 1.2.6+
6
+ *
7
+ * @author Jan Jarfalk
8
+ * @author-email jan.jarfalk@unwrongest.com
9
+ * @author-website http://www.unwrongest.com
10
+ *
11
+ * @licence MIT License - http://www.opensource.org/licenses/mit-license.php
12
+ */
13
+
14
+ (function($){
15
+ jQuery.fn.extend({
16
+ elastic: function() {
17
+
18
+ // We will create a div clone of the textarea
19
+ // by copying these attributes from the textarea to the div.
20
+ var mimics = [
21
+ 'paddingTop',
22
+ 'paddingRight',
23
+ 'paddingBottom',
24
+ 'paddingLeft',
25
+ 'fontSize',
26
+ 'lineHeight',
27
+ 'fontFamily',
28
+ 'width',
29
+ 'fontWeight',
30
+ 'border-top-width',
31
+ 'border-right-width',
32
+ 'border-bottom-width',
33
+ 'border-left-width',
34
+ 'borderTopStyle',
35
+ 'borderTopColor',
36
+ 'borderRightStyle',
37
+ 'borderRightColor',
38
+ 'borderBottomStyle',
39
+ 'borderBottomColor',
40
+ 'borderLeftStyle',
41
+ 'borderLeftColor'
42
+ ];
43
+
44
+ return this.each( function() {
45
+
46
+ // Elastic only works on textareas
47
+ if ( this.type !== 'textarea' ) {
48
+ return false;
49
+ }
50
+
51
+ var $textarea = jQuery(this),
52
+ $twin = jQuery('<div />').css({
53
+ 'position' : 'absolute',
54
+ 'display' : 'none',
55
+ 'word-wrap' : 'break-word',
56
+ 'white-space' :'pre-wrap'
57
+ }),
58
+ lineHeight = parseInt($textarea.css('line-height'),10) || parseInt($textarea.css('font-size'),'10'),
59
+ minheight = parseInt($textarea.css('height'),10) || lineHeight*3,
60
+ maxheight = parseInt($textarea.css('max-height'),10) || Number.MAX_VALUE,
61
+ goalheight = 0;
62
+
63
+ // Opera returns max-height of -1 if not set
64
+ if (maxheight < 0) { maxheight = Number.MAX_VALUE; }
65
+
66
+ // Append the twin to the DOM
67
+ // We are going to meassure the height of this, not the textarea.
68
+ $twin.appendTo($textarea.parent());
69
+
70
+ // Copy the essential styles (mimics) from the textarea to the twin
71
+ var i = mimics.length;
72
+ while(i--){
73
+ $twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString()));
74
+ }
75
+
76
+ // Updates the width of the twin. (solution for textareas with widths in percent)
77
+ function setTwinWidth(){
78
+ var curatedWidth = Math.floor(parseInt($textarea.width(),10));
79
+ if($twin.width() !== curatedWidth){
80
+ $twin.css({'width': curatedWidth + 'px'});
81
+
82
+ // Update height of textarea
83
+ update(true);
84
+ }
85
+ }
86
+
87
+ // Sets a given height and overflow state on the textarea
88
+ function setHeightAndOverflow(height, overflow){
89
+
90
+ var curratedHeight = Math.floor(parseInt(height,10));
91
+ if($textarea.height() !== curratedHeight){
92
+ $textarea.css({'height': curratedHeight + 'px','overflow':overflow});
93
+ }
94
+ }
95
+
96
+ // This function will update the height of the textarea if necessary
97
+ function update(forced) {
98
+
99
+ // Get curated content from the textarea.
100
+ var textareaContent = $textarea.val().replace(/&/g,'&amp;').replace(/ {2}/g, '&nbsp;').replace(/<|>/g, '&gt;').replace(/\n/g, '<br />');
101
+
102
+ // Compare curated content with curated twin.
103
+ var twinContent = $twin.html().replace(/<br>/ig,'<br />');
104
+
105
+ if(forced || textareaContent+'&nbsp;' !== twinContent){
106
+
107
+ // Add an extra white space so new rows are added when you are at the end of a row.
108
+ $twin.html(textareaContent+'&nbsp;');
109
+
110
+ // Change textarea height if twin plus the height of one line differs more than 3 pixel from textarea height
111
+ if(Math.abs($twin.height() + lineHeight - $textarea.height()) > 3){
112
+
113
+ var goalheight = $twin.height()+lineHeight;
114
+ if(goalheight >= maxheight) {
115
+ setHeightAndOverflow(maxheight,'auto');
116
+ } else if(goalheight <= minheight) {
117
+ setHeightAndOverflow(minheight,'hidden');
118
+ } else {
119
+ setHeightAndOverflow(goalheight,'hidden');
120
+ }
121
+
122
+ }
123
+
124
+ }
125
+
126
+ }
127
+
128
+ // Hide scrollbars
129
+ $textarea.css({'overflow':'hidden'});
130
+
131
+ // Update textarea size on keyup, change, cut and paste
132
+ $textarea.bind('keyup change cut paste', function(){
133
+ update();
134
+ });
135
+
136
+ // Update width of twin if browser or textarea is resized (solution for textareas with widths in percent)
137
+ $(window).bind('resize', setTwinWidth);
138
+ $textarea.bind('resize', setTwinWidth);
139
+ $textarea.bind('update', update);
140
+
141
+ // Compact textarea on blur
142
+ /*
143
+ $textarea.bind('blur',function(){
144
+ if($twin.height() < maxheight){
145
+ if($twin.height() > minheight) {
146
+ $textarea.height($twin.height());
147
+ } else {
148
+ $textarea.height(minheight);
149
+ }
150
+ }
151
+ });
152
+ */
153
+
154
+ // And this line is to catch the browser paste event
155
+ $textarea.bind('input paste',function(e){ setTimeout( update, 250); });
156
+
157
+ // Run update once when elastic is initialized
158
+ update();
159
+
160
+ });
161
+
162
+ }
163
+ });
164
+ })(jQuery);
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-elastic-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.11
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Devin Zhang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ description: A gem to automate using jQuery Elastic plugin with Rails 3
31
+ email:
32
+ - daqing1986@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/jquery-elastic-rails/version.rb
38
+ - lib/jquery-elastic-rails.rb
39
+ - vendor/assets/javascripts/jquery_elastic.js
40
+ - LICENSE
41
+ - README.md
42
+ homepage: https://github.com/daqing/jquery-elastic-rails
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ segments:
55
+ - 0
56
+ hash: 350166257484904985
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ segments:
64
+ - 0
65
+ hash: 350166257484904985
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Elastic makes your textareas grow and shrink to fit it’s content.
72
+ test_files: []