tagsinput-rails 1.3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Roman Greshny
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,45 @@
1
+ # tagsinput-rails
2
+
3
+ tagsinput-rails wraps the [jQuery-Tags-Input](http://xoxco.com/projects/code/tagsinput/) plugin in a rails engine for simple
4
+ use with the asset pipeline provided by rails 3.1. The gem includes the development (non-minified)
5
+ source for ease of exploration. The asset pipeline will minify in production.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'tagsinput-rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install tagsinput-rails
20
+
21
+ ## Usage
22
+
23
+ Add the following directive to your Javascript manifest file (application.js):
24
+
25
+ //= require jquery.tagsinput
26
+
27
+ Add to your app/assets/stylesheets/application.css
28
+
29
+ *= require jquery.tagsinput
30
+
31
+ ## Versioning
32
+
33
+ tagsinput-rails 1.3.3.1 == jQuery-Tags-Input 1.3.3
34
+
35
+ Every attempt is made to mirror the currently shipping jQuery-Tags-Input version number wherever possible.
36
+ The major, minor, and patch version numbers will always represent the jQuery-Tags-Input version. Should a gem
37
+ bug be discovered, a 4th version identifier will be added and incremented.
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require 'tagsinput-rails/version'
2
+
3
+ module Tagsinput
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Tagsinput
2
+ module Rails
3
+ VERSION = '1.3.3.1'
4
+ end
5
+ end
@@ -0,0 +1,354 @@
1
+ /*
2
+
3
+ jQuery Tags Input Plugin 1.3.3
4
+
5
+ Copyright (c) 2011 XOXCO, Inc
6
+
7
+ Documentation for this plugin lives here:
8
+ http://xoxco.com/clickable/jquery-tags-input
9
+
10
+ Licensed under the MIT license:
11
+ http://www.opensource.org/licenses/mit-license.php
12
+
13
+ ben@xoxco.com
14
+
15
+ */
16
+
17
+ (function($) {
18
+
19
+ var delimiter = new Array();
20
+ var tags_callbacks = new Array();
21
+ $.fn.doAutosize = function(o){
22
+ var minWidth = $(this).data('minwidth'),
23
+ maxWidth = $(this).data('maxwidth'),
24
+ val = '',
25
+ input = $(this),
26
+ testSubject = $('#'+$(this).data('tester_id'));
27
+
28
+ if (val === (val = input.val())) {return;}
29
+
30
+ // Enter new content into testSubject
31
+ var escaped = val.replace(/&/g, '&amp;').replace(/\s/g,' ').replace(/</g, '&lt;').replace(/>/g, '&gt;');
32
+ testSubject.html(escaped);
33
+ // Calculate new width + whether to change
34
+ var testerWidth = testSubject.width(),
35
+ newWidth = (testerWidth + o.comfortZone) >= minWidth ? testerWidth + o.comfortZone : minWidth,
36
+ currentWidth = input.width(),
37
+ isValidWidthChange = (newWidth < currentWidth && newWidth >= minWidth)
38
+ || (newWidth > minWidth && newWidth < maxWidth);
39
+
40
+ // Animate width
41
+ if (isValidWidthChange) {
42
+ input.width(newWidth);
43
+ }
44
+
45
+
46
+ };
47
+ $.fn.resetAutosize = function(options){
48
+ // alert(JSON.stringify(options));
49
+ var minWidth = $(this).data('minwidth') || options.minInputWidth || $(this).width(),
50
+ maxWidth = $(this).data('maxwidth') || options.maxInputWidth || ($(this).closest('.tagsinput').width() - options.inputPadding),
51
+ val = '',
52
+ input = $(this),
53
+ testSubject = $('<tester/>').css({
54
+ position: 'absolute',
55
+ top: -9999,
56
+ left: -9999,
57
+ width: 'auto',
58
+ fontSize: input.css('fontSize'),
59
+ fontFamily: input.css('fontFamily'),
60
+ fontWeight: input.css('fontWeight'),
61
+ letterSpacing: input.css('letterSpacing'),
62
+ whiteSpace: 'nowrap'
63
+ }),
64
+ testerId = $(this).attr('id')+'_autosize_tester';
65
+ if(! $('#'+testerId).length > 0){
66
+ testSubject.attr('id', testerId);
67
+ testSubject.appendTo('body');
68
+ }
69
+
70
+ input.data('minwidth', minWidth);
71
+ input.data('maxwidth', maxWidth);
72
+ input.data('tester_id', testerId);
73
+ input.css('width', minWidth);
74
+ };
75
+
76
+ $.fn.addTag = function(value,options) {
77
+ options = jQuery.extend({focus:false,callback:true},options);
78
+ this.each(function() {
79
+ var id = $(this).attr('id');
80
+
81
+ var tagslist = $(this).val().split(delimiter[id]);
82
+ if (tagslist[0] == '') {
83
+ tagslist = new Array();
84
+ }
85
+
86
+ value = jQuery.trim(value);
87
+
88
+ if (options.unique) {
89
+ var skipTag = $(this).tagExist(value);
90
+ if(skipTag == true) {
91
+ //Marks fake input as not_valid to let styling it
92
+ $('#'+id+'_tag').addClass('not_valid');
93
+ }
94
+ } else {
95
+ var skipTag = false;
96
+ }
97
+
98
+ if (value !='' && skipTag != true) {
99
+ $('<span>').addClass('tag').append(
100
+ $('<span>').text(value).append('&nbsp;&nbsp;'),
101
+ $('<a>', {
102
+ href : '#',
103
+ title : 'Removing tag',
104
+ text : 'x'
105
+ }).click(function () {
106
+ return $('#' + id).removeTag(escape(value));
107
+ })
108
+ ).insertBefore('#' + id + '_addTag');
109
+
110
+ tagslist.push(value);
111
+
112
+ $('#'+id+'_tag').val('');
113
+ if (options.focus) {
114
+ $('#'+id+'_tag').focus();
115
+ } else {
116
+ $('#'+id+'_tag').blur();
117
+ }
118
+
119
+ $.fn.tagsInput.updateTagsField(this,tagslist);
120
+
121
+ if (options.callback && tags_callbacks[id] && tags_callbacks[id]['onAddTag']) {
122
+ var f = tags_callbacks[id]['onAddTag'];
123
+ f.call(this, value);
124
+ }
125
+ if(tags_callbacks[id] && tags_callbacks[id]['onChange'])
126
+ {
127
+ var i = tagslist.length;
128
+ var f = tags_callbacks[id]['onChange'];
129
+ f.call(this, $(this), tagslist[i-1]);
130
+ }
131
+ }
132
+
133
+ });
134
+
135
+ return false;
136
+ };
137
+
138
+ $.fn.removeTag = function(value) {
139
+ value = unescape(value);
140
+ this.each(function() {
141
+ var id = $(this).attr('id');
142
+
143
+ var old = $(this).val().split(delimiter[id]);
144
+
145
+ $('#'+id+'_tagsinput .tag').remove();
146
+ str = '';
147
+ for (i=0; i< old.length; i++) {
148
+ if (old[i]!=value) {
149
+ str = str + delimiter[id] +old[i];
150
+ }
151
+ }
152
+
153
+ $.fn.tagsInput.importTags(this,str);
154
+
155
+ if (tags_callbacks[id] && tags_callbacks[id]['onRemoveTag']) {
156
+ var f = tags_callbacks[id]['onRemoveTag'];
157
+ f.call(this, value);
158
+ }
159
+ });
160
+
161
+ return false;
162
+ };
163
+
164
+ $.fn.tagExist = function(val) {
165
+ var id = $(this).attr('id');
166
+ var tagslist = $(this).val().split(delimiter[id]);
167
+ return (jQuery.inArray(val, tagslist) >= 0); //true when tag exists, false when not
168
+ };
169
+
170
+ // clear all existing tags and import new ones from a string
171
+ $.fn.importTags = function(str) {
172
+ id = $(this).attr('id');
173
+ $('#'+id+'_tagsinput .tag').remove();
174
+ $.fn.tagsInput.importTags(this,str);
175
+ }
176
+
177
+ $.fn.tagsInput = function(options) {
178
+ var settings = jQuery.extend({
179
+ interactive:true,
180
+ defaultText:'add a tag',
181
+ minChars:0,
182
+ width:'300px',
183
+ height:'100px',
184
+ autocomplete: {selectFirst: false },
185
+ 'hide':true,
186
+ 'delimiter':',',
187
+ 'unique':true,
188
+ removeWithBackspace:true,
189
+ placeholderColor:'#666666',
190
+ autosize: true,
191
+ comfortZone: 20,
192
+ inputPadding: 6*2
193
+ },options);
194
+
195
+ this.each(function() {
196
+ if (settings.hide) {
197
+ $(this).hide();
198
+ }
199
+ var id = $(this).attr('id');
200
+ if (!id || delimiter[$(this).attr('id')]) {
201
+ id = $(this).attr('id', 'tags' + new Date().getTime()).attr('id');
202
+ }
203
+
204
+ var data = jQuery.extend({
205
+ pid:id,
206
+ real_input: '#'+id,
207
+ holder: '#'+id+'_tagsinput',
208
+ input_wrapper: '#'+id+'_addTag',
209
+ fake_input: '#'+id+'_tag'
210
+ },settings);
211
+
212
+ delimiter[id] = data.delimiter;
213
+
214
+ if (settings.onAddTag || settings.onRemoveTag || settings.onChange) {
215
+ tags_callbacks[id] = new Array();
216
+ tags_callbacks[id]['onAddTag'] = settings.onAddTag;
217
+ tags_callbacks[id]['onRemoveTag'] = settings.onRemoveTag;
218
+ tags_callbacks[id]['onChange'] = settings.onChange;
219
+ }
220
+
221
+ var markup = '<div id="'+id+'_tagsinput" class="tagsinput"><div id="'+id+'_addTag">';
222
+
223
+ if (settings.interactive) {
224
+ markup = markup + '<input id="'+id+'_tag" value="" data-default="'+settings.defaultText+'" />';
225
+ }
226
+
227
+ markup = markup + '</div><div class="tags_clear"></div></div>';
228
+
229
+ $(markup).insertAfter(this);
230
+
231
+ $(data.holder).css('width',settings.width);
232
+ $(data.holder).css('min-height',settings.height);
233
+ $(data.holder).css('height','100%');
234
+
235
+ if ($(data.real_input).val()!='') {
236
+ $.fn.tagsInput.importTags($(data.real_input),$(data.real_input).val());
237
+ }
238
+ if (settings.interactive) {
239
+ $(data.fake_input).val($(data.fake_input).attr('data-default'));
240
+ $(data.fake_input).css('color',settings.placeholderColor);
241
+ $(data.fake_input).resetAutosize(settings);
242
+
243
+ $(data.holder).bind('click',data,function(event) {
244
+ $(event.data.fake_input).focus();
245
+ });
246
+
247
+ $(data.fake_input).bind('focus',data,function(event) {
248
+ if ($(event.data.fake_input).val()==$(event.data.fake_input).attr('data-default')) {
249
+ $(event.data.fake_input).val('');
250
+ }
251
+ $(event.data.fake_input).css('color','#000000');
252
+ });
253
+
254
+ if (settings.autocomplete_url != undefined) {
255
+ autocomplete_options = {source: settings.autocomplete_url};
256
+ for (attrname in settings.autocomplete) {
257
+ autocomplete_options[attrname] = settings.autocomplete[attrname];
258
+ }
259
+
260
+ if (jQuery.Autocompleter !== undefined) {
261
+ $(data.fake_input).autocomplete(settings.autocomplete_url, settings.autocomplete);
262
+ $(data.fake_input).bind('result',data,function(event,data,formatted) {
263
+ if (data) {
264
+ $('#'+id).addTag(data[0] + "",{focus:true,unique:(settings.unique)});
265
+ }
266
+ });
267
+ } else if (jQuery.ui.autocomplete !== undefined) {
268
+ $(data.fake_input).autocomplete(autocomplete_options);
269
+ $(data.fake_input).bind('autocompleteselect',data,function(event,ui) {
270
+ $(event.data.real_input).addTag(ui.item.value,{focus:true,unique:(settings.unique)});
271
+ return false;
272
+ });
273
+ }
274
+
275
+
276
+ } else {
277
+ // if a user tabs out of the field, create a new tag
278
+ // this is only available if autocomplete is not used.
279
+ $(data.fake_input).bind('blur',data,function(event) {
280
+ var d = $(this).attr('data-default');
281
+ if ($(event.data.fake_input).val()!='' && $(event.data.fake_input).val()!=d) {
282
+ if( (event.data.minChars <= $(event.data.fake_input).val().length) && (!event.data.maxChars || (event.data.maxChars >= $(event.data.fake_input).val().length)) )
283
+ $(event.data.real_input).addTag($(event.data.fake_input).val(),{focus:true,unique:(settings.unique)});
284
+ } else {
285
+ $(event.data.fake_input).val($(event.data.fake_input).attr('data-default'));
286
+ $(event.data.fake_input).css('color',settings.placeholderColor);
287
+ }
288
+ return false;
289
+ });
290
+
291
+ }
292
+ // if user types a comma, create a new tag
293
+ $(data.fake_input).bind('keypress',data,function(event) {
294
+ if (event.which==event.data.delimiter.charCodeAt(0) || event.which==13 ) {
295
+ event.preventDefault();
296
+ if( (event.data.minChars <= $(event.data.fake_input).val().length) && (!event.data.maxChars || (event.data.maxChars >= $(event.data.fake_input).val().length)) )
297
+ $(event.data.real_input).addTag($(event.data.fake_input).val(),{focus:true,unique:(settings.unique)});
298
+ $(event.data.fake_input).resetAutosize(settings);
299
+ return false;
300
+ } else if (event.data.autosize) {
301
+ $(event.data.fake_input).doAutosize(settings);
302
+
303
+ }
304
+ });
305
+ //Delete last tag on backspace
306
+ data.removeWithBackspace && $(data.fake_input).bind('keydown', function(event)
307
+ {
308
+ if(event.keyCode == 8 && $(this).val() == '')
309
+ {
310
+ event.preventDefault();
311
+ var last_tag = $(this).closest('.tagsinput').find('.tag:last').text();
312
+ var id = $(this).attr('id').replace(/_tag$/, '');
313
+ last_tag = last_tag.replace(/[\s]+x$/, '');
314
+ $('#' + id).removeTag(escape(last_tag));
315
+ $(this).trigger('focus');
316
+ }
317
+ });
318
+ $(data.fake_input).blur();
319
+
320
+ //Removes the not_valid class when user changes the value of the fake input
321
+ if(data.unique) {
322
+ $(data.fake_input).keydown(function(event){
323
+ if(event.keyCode == 8 || String.fromCharCode(event.which).match(/\w+|[áéíóúÁÉÍÓÚñÑ,/]+/)) {
324
+ $(this).removeClass('not_valid');
325
+ }
326
+ });
327
+ }
328
+ } // if settings.interactive
329
+ });
330
+
331
+ return this;
332
+
333
+ };
334
+
335
+ $.fn.tagsInput.updateTagsField = function(obj,tagslist) {
336
+ var id = $(obj).attr('id');
337
+ $(obj).val(tagslist.join(delimiter[id]));
338
+ };
339
+
340
+ $.fn.tagsInput.importTags = function(obj,val) {
341
+ $(obj).val('');
342
+ var id = $(obj).attr('id');
343
+ var tags = val.split(delimiter[id]);
344
+ for (i=0; i<tags.length; i++) {
345
+ $(obj).addTag(tags[i],{focus:false,callback:false});
346
+ }
347
+ if(tags_callbacks[id] && tags_callbacks[id]['onChange'])
348
+ {
349
+ var f = tags_callbacks[id]['onChange'];
350
+ f.call(obj, obj, tags[i]);
351
+ }
352
+ };
353
+
354
+ })(jQuery);
@@ -0,0 +1,7 @@
1
+ div.tagsinput { border:1px solid #CCC; background: #FFF; padding:5px; width:300px; height:100px; overflow-y: auto;}
2
+ div.tagsinput span.tag { border: 1px solid #a5d24a; -moz-border-radius:2px; -webkit-border-radius:2px; display: block; float: left; padding: 5px; text-decoration:none; background: #cde69c; color: #638421; margin-right: 5px; margin-bottom:5px;font-family: helvetica; font-size:13px;}
3
+ div.tagsinput span.tag a { font-weight: bold; color: #82ad2b; text-decoration:none; font-size: 11px; }
4
+ div.tagsinput input { width:80px; margin:0px; font-family: helvetica; font-size: 13px; border:1px solid transparent; padding:5px; background: transparent; color: #000; outline:0px; margin-right:5px; margin-bottom:5px; }
5
+ div.tagsinput div { display:block; float: left; }
6
+ .tags_clear { clear: both; width: 100%; height: 0px; }
7
+ .not_valid {background: #FBD8DB !important; color: #90111A !important;}
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tagsinput-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.3.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Roman Greshny
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-10 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
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
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: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! " Magically convert a simple text input into a cool tag list with
63
+ this jQuery plugin.\n This gem allows for its easy inclusion into the rails asset
64
+ pipeline.\n"
65
+ email:
66
+ - greshny@gmail.com
67
+ executables: []
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - lib/tagsinput-rails/version.rb
72
+ - lib/tagsinput-rails.rb
73
+ - vendor/assets/javascripts/jquery.tagsinput.js
74
+ - vendor/assets/stylesheets/jquery.tagsinput.css
75
+ - LICENSE.txt
76
+ - README.md
77
+ homepage: http://github.com/greshny/tagsinput-rails/
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
+ segments:
91
+ - 0
92
+ hash: -3390716336510145408
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: -3390716336510145408
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.24
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: The jQuery-Tags-Input jQuery plugin ready to play with the Rails Asset Pipeline
108
+ test_files: []