rails-jquery-tags-input 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d62239966f571f2b3fae5893145353799c9af29d
4
+ data.tar.gz: f9bc2e46288f20c194dab2f5e3a0df586abf7aa4
5
+ SHA512:
6
+ metadata.gz: 151ac50ea0731d06b556986bc3704846548ebf8321da99e6a9f1b1dd136be723e751d2d2d226afe90aa8b85f476372917b85edb3cdd01793a670b9242166fd07
7
+ data.tar.gz: 43a18d64b1919a976f9ab1905ae16ef69090c0fb039acd82d2d472237420e20ce0c470ba381f24fad2b14a8937887e6cc057c8e5dd5bd42cf83330a5f5af19b0
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Buford Taylor
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,23 @@
1
+ # rails-jquery-tags-input
2
+
3
+ rails-jquery-tags-input inserts the [jQuery-Tags-Input](http://xoxco.com/projects/code/tagsinput/) plugin in the rails asset pipeline.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rails-jquery-tags-input'
10
+
11
+ ## Usage
12
+
13
+ js
14
+ //= require jquery.tagsinput
15
+
16
+
17
+ css
18
+ *= require jquery.tagsinput
19
+
20
+ ## Versioning
21
+
22
+ rails-jquery-tags-input 1.0.0 == jQuery-Tags-Input 1.3.3
23
+
@@ -0,0 +1,8 @@
1
+ require 'rails-jquery-tags-input/version'
2
+
3
+ module RailsJqueryTagsInput
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module RailsJqueryTagsInput
2
+ module Rails
3
+ VERSION = '1.0.0'
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,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-jquery-tags-input
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Buford Taylor
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: |2
56
+ Delimit input text into nice looking tags for your form input
57
+ email:
58
+ - bufordtaylor@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - LICENSE.txt
64
+ - README.md
65
+ - lib/rails-jquery-tags-input.rb
66
+ - lib/rails-jquery-tags-input/version.rb
67
+ - vendor/assets/javascripts/jquery.tagsinput.js
68
+ - vendor/assets/stylesheets/jquery.tagsinput.css
69
+ homepage: http://github.com/bufordtaylor/rails-jquery-tags-input/
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.2.2
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: The jQuery-Tags-Input jQuery plugin ready to play with the Rails Asset Pipeline
93
+ test_files: []
94
+ has_rdoc: