taggingform 0.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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
data/README.md ADDED
File without changes
@@ -0,0 +1,18 @@
1
+ require "taggingform"
2
+ require "rails"
3
+ require "action_controller"
4
+
5
+ module TaggingForm
6
+ module Rails
7
+ class Engine < ::Rails::Engine
8
+
9
+ initializer "taggingform.helper_and_builder" do
10
+ ActiveSupport.on_load :action_view do
11
+ ActionView::Base.send(:include, TaggingForm::Helper)
12
+ ActionView::Helpers::FormBuilder.send(:include, TaggingForm::Builder)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ module RailsKindeditor
2
+ module Helper
3
+ def kindeditor_tag(name, content = nil, options = {})
4
+ id = sanitize_to_id(name)
5
+ input_html = { :id => id }.merge(options.delete(:input_html) || {})
6
+ output = ActiveSupport::SafeBuffer.new
7
+ output << text_area_tag(name, content, input_html)
8
+ end
9
+
10
+ def kindeditor(name, method, options = {})
11
+ input_html = (options.delete(:input_html) || {})
12
+ hash = input_html.stringify_keys
13
+ instance_tag = ActionView::Base::InstanceTag.new(name, method, self, options.delete(:object))
14
+ instance_tag.send(:add_default_name_and_id, hash)
15
+ output_buffer = ActiveSupport::SafeBuffer.new
16
+ output_buffer << instance_tag.to_text_area_tag(input_html)
17
+ end
18
+
19
+ end
20
+
21
+ module Builder
22
+ def kindeditor(method, options = {})
23
+ @template.send("kindeditor", @object_name, method, objectify_options(options))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module TaggingForm
2
+ module Rails
3
+ VERSION = "0.0.9"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'taggingform/engine'
2
+ require 'taggingform/helper'
3
+
4
+ module TaggingForm
5
+
6
+ def self.setup
7
+ yield self
8
+ end
9
+
10
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "taggingform/version"
4
+
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'taggingform'
8
+ gem.version = '0.0.0'
9
+ gem.date = '2013-04-16'
10
+ gem.summary = "a plugin with jquery plug tagging!"
11
+ gem.description = "a plugin with jquery plug tagging http://aehlke.github.io/tag-it/"
12
+ gem.authors = ["bydmm"]
13
+ gem.email = 'miku@maimoe.com'
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.homepage = 'http://rubygemgem.org/gems/taggingform'
16
+ end
@@ -0,0 +1,539 @@
1
+ /*
2
+ * jQuery UI Tag-it!
3
+ *
4
+ * @version v2.0 (06/2011)
5
+ *
6
+ * Copyright 2011, Levy Carneiro Jr.
7
+ * Released under the MIT license.
8
+ * http://aehlke.github.com/tag-it/LICENSE
9
+ *
10
+ * Homepage:
11
+ * http://aehlke.github.com/tag-it/
12
+ *
13
+ * Authors:
14
+ * Levy Carneiro Jr.
15
+ * Martin Rehfeld
16
+ * Tobias Schmidt
17
+ * Skylar Challand
18
+ * Alex Ehlke
19
+ *
20
+ * Maintainer:
21
+ * Alex Ehlke - Twitter: @aehlke
22
+ *
23
+ * Dependencies:
24
+ * jQuery v1.4+
25
+ * jQuery UI v1.8+
26
+ */
27
+ (function($) {
28
+
29
+ $.widget('ui.tagit', {
30
+ options: {
31
+ allowDuplicates : false,
32
+ caseSensitive : true,
33
+ fieldName : 'tags',
34
+ placeholderText : null, // Sets `placeholder` attr on input field.
35
+ readOnly : false, // Disables editing.
36
+ removeConfirmation: false, // Require confirmation to remove tags.
37
+ tagLimit : null, // Max number of tags allowed (null for unlimited).
38
+
39
+ // Used for autocomplete, unless you override `autocomplete.source`.
40
+ availableTags : [],
41
+
42
+ // Use to override or add any options to the autocomplete widget.
43
+ //
44
+ // By default, autocomplete.source will map to availableTags,
45
+ // unless overridden.
46
+ autocomplete: {},
47
+
48
+ // Shows autocomplete before the user even types anything.
49
+ showAutocompleteOnFocus: false,
50
+
51
+ // When enabled, quotes are unneccesary for inputting multi-word tags.
52
+ allowSpaces: false,
53
+
54
+ // The below options are for using a single field instead of several
55
+ // for our form values.
56
+ //
57
+ // When enabled, will use a single hidden field for the form,
58
+ // rather than one per tag. It will delimit tags in the field
59
+ // with singleFieldDelimiter.
60
+ //
61
+ // The easiest way to use singleField is to just instantiate tag-it
62
+ // on an INPUT element, in which case singleField is automatically
63
+ // set to true, and singleFieldNode is set to that element. This
64
+ // way, you don't need to fiddle with these options.
65
+ singleField: false,
66
+
67
+ // This is just used when preloading data from the field, and for
68
+ // populating the field with delimited tags as the user adds them.
69
+ singleFieldDelimiter: ',',
70
+
71
+ // Set this to an input DOM node to use an existing form field.
72
+ // Any text in it will be erased on init. But it will be
73
+ // populated with the text of tags as they are created,
74
+ // delimited by singleFieldDelimiter.
75
+ //
76
+ // If this is not set, we create an input node for it,
77
+ // with the name given in settings.fieldName.
78
+ singleFieldNode: null,
79
+
80
+ // Whether to animate tag removals or not.
81
+ animate: true,
82
+
83
+ // Optionally set a tabindex attribute on the input that gets
84
+ // created for tag-it.
85
+ tabIndex: null,
86
+
87
+ // Event callbacks.
88
+ beforeTagAdded : null,
89
+ afterTagAdded : null,
90
+
91
+ beforeTagRemoved : null,
92
+ afterTagRemoved : null,
93
+
94
+ onTagClicked : null,
95
+ onTagLimitExceeded : null,
96
+
97
+
98
+ // DEPRECATED:
99
+ //
100
+ // /!\ These event callbacks are deprecated and WILL BE REMOVED at some
101
+ // point in the future. They're here for backwards-compatibility.
102
+ // Use the above before/after event callbacks instead.
103
+ onTagAdded : null,
104
+ onTagRemoved: null,
105
+ // `autocomplete.source` is the replacement for tagSource.
106
+ tagSource: null
107
+ // Do not use the above deprecated options.
108
+ },
109
+
110
+ _create: function() {
111
+ // for handling static scoping inside callbacks
112
+ var that = this;
113
+
114
+ // There are 2 kinds of DOM nodes this widget can be instantiated on:
115
+ // 1. UL, OL, or some element containing either of these.
116
+ // 2. INPUT, in which case 'singleField' is overridden to true,
117
+ // a UL is created and the INPUT is hidden.
118
+ if (this.element.is('input')) {
119
+ this.tagList = $('<ul></ul>').insertAfter(this.element);
120
+ this.options.singleField = true;
121
+ this.options.singleFieldNode = this.element;
122
+ this.element.css('display', 'none');
123
+ } else {
124
+ this.tagList = this.element.find('ul, ol').andSelf().last();
125
+ }
126
+
127
+ this.tagInput = $('<input type="text" />').addClass('ui-widget-content');
128
+
129
+ if (this.options.readOnly) this.tagInput.attr('disabled', 'disabled');
130
+
131
+ if (this.options.tabIndex) {
132
+ this.tagInput.attr('tabindex', this.options.tabIndex);
133
+ }
134
+
135
+ if (this.options.placeholderText) {
136
+ this.tagInput.attr('placeholder', this.options.placeholderText);
137
+ }
138
+
139
+ if (!this.options.autocomplete.source) {
140
+ this.options.autocomplete.source = function(search, showChoices) {
141
+ var filter = search.term.toLowerCase();
142
+ var choices = $.grep(this.options.availableTags, function(element) {
143
+ // Only match autocomplete options that begin with the search term.
144
+ // (Case insensitive.)
145
+ return (element.toLowerCase().indexOf(filter) === 0);
146
+ });
147
+ showChoices(this._subtractArray(choices, this.assignedTags()));
148
+ };
149
+ }
150
+
151
+ if (this.options.showAutocompleteOnFocus) {
152
+ this.tagInput.focus(function(event, ui) {
153
+ that._showAutocomplete();
154
+ });
155
+
156
+ if (typeof this.options.autocomplete.minLength === 'undefined') {
157
+ this.options.autocomplete.minLength = 0;
158
+ }
159
+ }
160
+
161
+ // Bind autocomplete.source callback functions to this context.
162
+ if ($.isFunction(this.options.autocomplete.source)) {
163
+ this.options.autocomplete.source = $.proxy(this.options.autocomplete.source, this);
164
+ }
165
+
166
+ // DEPRECATED.
167
+ if ($.isFunction(this.options.tagSource)) {
168
+ this.options.tagSource = $.proxy(this.options.tagSource, this);
169
+ }
170
+
171
+ this.tagList
172
+ .addClass('tagit')
173
+ .addClass('ui-widget ui-widget-content ui-corner-all')
174
+ // Create the input field.
175
+ .append($('<li class="tagit-new"></li>').append(this.tagInput))
176
+ .click(function(e) {
177
+ var target = $(e.target);
178
+ if (target.hasClass('tagit-label')) {
179
+ var tag = target.closest('.tagit-choice');
180
+ if (!tag.hasClass('removed')) {
181
+ that._trigger('onTagClicked', e, {tag: tag, tagLabel: that.tagLabel(tag)});
182
+ }
183
+ } else {
184
+ // Sets the focus() to the input field, if the user
185
+ // clicks anywhere inside the UL. This is needed
186
+ // because the input field needs to be of a small size.
187
+ that.tagInput.focus();
188
+ }
189
+ });
190
+
191
+ // Single field support.
192
+ var addedExistingFromSingleFieldNode = false;
193
+ if (this.options.singleField) {
194
+ if (this.options.singleFieldNode) {
195
+ // Add existing tags from the input field.
196
+ var node = $(this.options.singleFieldNode);
197
+ var tags = node.val().split(this.options.singleFieldDelimiter);
198
+ node.val('');
199
+ $.each(tags, function(index, tag) {
200
+ that.createTag(tag, null, true);
201
+ addedExistingFromSingleFieldNode = true;
202
+ });
203
+ } else {
204
+ // Create our single field input after our list.
205
+ this.options.singleFieldNode = $('<input type="hidden" style="display:none;" value="" name="' + this.options.fieldName + '" />');
206
+ this.tagList.after(this.options.singleFieldNode);
207
+ }
208
+ }
209
+
210
+ // Add existing tags from the list, if any.
211
+ if (!addedExistingFromSingleFieldNode) {
212
+ this.tagList.children('li').each(function() {
213
+ if (!$(this).hasClass('tagit-new')) {
214
+ that.createTag($(this).text(), $(this).attr('class'), true);
215
+ $(this).remove();
216
+ }
217
+ });
218
+ }
219
+
220
+ // Events.
221
+ this.tagInput
222
+ .keydown(function(event) {
223
+ // Backspace is not detected within a keypress, so it must use keydown.
224
+ if (event.which == $.ui.keyCode.BACKSPACE && that.tagInput.val() === '') {
225
+ var tag = that._lastTag();
226
+ if (!that.options.removeConfirmation || tag.hasClass('remove')) {
227
+ // When backspace is pressed, the last tag is deleted.
228
+ that.removeTag(tag);
229
+ } else if (that.options.removeConfirmation) {
230
+ tag.addClass('remove ui-state-highlight');
231
+ }
232
+ } else if (that.options.removeConfirmation) {
233
+ that._lastTag().removeClass('remove ui-state-highlight');
234
+ }
235
+
236
+ // Comma/Space/Enter are all valid delimiters for new tags,
237
+ // except when there is an open quote or if setting allowSpaces = true.
238
+ // Tab will also create a tag, unless the tag input is empty,
239
+ // in which case it isn't caught.
240
+ if (
241
+ event.which === $.ui.keyCode.COMMA ||
242
+ event.which === $.ui.keyCode.ENTER ||
243
+ (
244
+ event.which == $.ui.keyCode.TAB &&
245
+ that.tagInput.val() !== ''
246
+ ) ||
247
+ (
248
+ event.which == $.ui.keyCode.SPACE &&
249
+ that.options.allowSpaces !== true &&
250
+ (
251
+ $.trim(that.tagInput.val()).replace( /^s*/, '' ).charAt(0) != '"' ||
252
+ (
253
+ $.trim(that.tagInput.val()).charAt(0) == '"' &&
254
+ $.trim(that.tagInput.val()).charAt($.trim(that.tagInput.val()).length - 1) == '"' &&
255
+ $.trim(that.tagInput.val()).length - 1 !== 0
256
+ )
257
+ )
258
+ )
259
+ ) {
260
+ // Enter submits the form if there's no text in the input.
261
+ if (!(event.which === $.ui.keyCode.ENTER && that.tagInput.val() === '')) {
262
+ event.preventDefault();
263
+ }
264
+
265
+ that.createTag(that._cleanedInput());
266
+
267
+ // The autocomplete doesn't close automatically when TAB is pressed.
268
+ // So let's ensure that it closes.
269
+ that.tagInput.autocomplete('close');
270
+ }
271
+ }).blur(function(e){
272
+ // Create a tag when the element loses focus.
273
+ // If autocomplete is enabled and suggestion was clicked, don't add it.
274
+ if (!that.tagInput.data('autocomplete-open')) {
275
+ that.createTag(that._cleanedInput());
276
+ }
277
+ });
278
+
279
+ // Autocomplete.
280
+ if (this.options.availableTags || this.options.tagSource || this.options.autocomplete.source) {
281
+ var autocompleteOptions = {
282
+ select: function(event, ui) {
283
+ that.createTag(ui.item.value);
284
+ // Preventing the tag input to be updated with the chosen value.
285
+ return false;
286
+ }
287
+ };
288
+ $.extend(autocompleteOptions, this.options.autocomplete);
289
+
290
+ // tagSource is deprecated, but takes precedence here since autocomplete.source is set by default,
291
+ // while tagSource is left null by default.
292
+ autocompleteOptions.source = this.options.tagSource || autocompleteOptions.source;
293
+
294
+ this.tagInput.autocomplete(autocompleteOptions).bind('autocompleteopen', function(event, ui) {
295
+ that.tagInput.data('autocomplete-open', true);
296
+ }).bind('autocompleteclose', function(event, ui) {
297
+ that.tagInput.data('autocomplete-open', false)
298
+ });
299
+ }
300
+ },
301
+
302
+ _cleanedInput: function() {
303
+ // Returns the contents of the tag input, cleaned and ready to be passed to createTag
304
+ return $.trim(this.tagInput.val().replace(/^"(.*)"$/, '$1'));
305
+ },
306
+
307
+ _lastTag: function() {
308
+ return this.tagList.find('.tagit-choice:last:not(.removed)');
309
+ },
310
+
311
+ _tags: function() {
312
+ return this.tagList.find('.tagit-choice:not(.removed)');
313
+ },
314
+
315
+ assignedTags: function() {
316
+ // Returns an array of tag string values
317
+ var that = this;
318
+ var tags = [];
319
+ if (this.options.singleField) {
320
+ tags = $(this.options.singleFieldNode).val().split(this.options.singleFieldDelimiter);
321
+ if (tags[0] === '') {
322
+ tags = [];
323
+ }
324
+ } else {
325
+ this._tags().each(function() {
326
+ tags.push(that.tagLabel(this));
327
+ });
328
+ }
329
+ return tags;
330
+ },
331
+
332
+ _updateSingleTagsField: function(tags) {
333
+ // Takes a list of tag string values, updates this.options.singleFieldNode.val to the tags delimited by this.options.singleFieldDelimiter
334
+ $(this.options.singleFieldNode).val(tags.join(this.options.singleFieldDelimiter)).trigger('change');
335
+ },
336
+
337
+ _subtractArray: function(a1, a2) {
338
+ var result = [];
339
+ for (var i = 0; i < a1.length; i++) {
340
+ if ($.inArray(a1[i], a2) == -1) {
341
+ result.push(a1[i]);
342
+ }
343
+ }
344
+ return result;
345
+ },
346
+
347
+ tagLabel: function(tag) {
348
+ // Returns the tag's string label.
349
+ if (this.options.singleField) {
350
+ return $(tag).find('.tagit-label:first').text();
351
+ } else {
352
+ return $(tag).find('input:first').val();
353
+ }
354
+ },
355
+
356
+ _showAutocomplete: function() {
357
+ this.tagInput.autocomplete('search', '');
358
+ },
359
+
360
+ _findTagByLabel: function(name) {
361
+ var that = this;
362
+ var tag = null;
363
+ this._tags().each(function(i) {
364
+ if (that._formatStr(name) == that._formatStr(that.tagLabel(this))) {
365
+ tag = $(this);
366
+ return false;
367
+ }
368
+ });
369
+ return tag;
370
+ },
371
+
372
+ _isNew: function(name) {
373
+ return !this._findTagByLabel(name);
374
+ },
375
+
376
+ _formatStr: function(str) {
377
+ if (this.options.caseSensitive) {
378
+ return str;
379
+ }
380
+ return $.trim(str.toLowerCase());
381
+ },
382
+
383
+ _effectExists: function(name) {
384
+ return Boolean($.effects && ($.effects[name] || ($.effects.effect && $.effects.effect[name])));
385
+ },
386
+
387
+ createTag: function(value, additionalClass, duringInitialization) {
388
+ var that = this;
389
+
390
+ value = $.trim(value);
391
+
392
+ if(this.options.preprocessTag) {
393
+ value = this.options.preprocessTag(value);
394
+ }
395
+
396
+ if (value === '') {
397
+ return false;
398
+ }
399
+
400
+ if (!this.options.allowDuplicates && !this._isNew(value)) {
401
+ var existingTag = this._findTagByLabel(value);
402
+ if (this._trigger('onTagExists', null, {
403
+ existingTag: existingTag,
404
+ duringInitialization: duringInitialization
405
+ }) !== false) {
406
+ if (this._effectExists('highlight')) {
407
+ existingTag.effect('highlight');
408
+ }
409
+ }
410
+ return false;
411
+ }
412
+
413
+ if (this.options.tagLimit && this._tags().length >= this.options.tagLimit) {
414
+ this._trigger('onTagLimitExceeded', null, {duringInitialization: duringInitialization});
415
+ return false;
416
+ }
417
+
418
+ var label = $(this.options.onTagClicked ? '<a class="tagit-label"></a>' : '<span class="tagit-label"></span>').text(value);
419
+
420
+ // Create tag.
421
+ var tag = $('<li></li>')
422
+ .addClass('tagit-choice ui-widget-content ui-state-default ui-corner-all')
423
+ .addClass(additionalClass)
424
+ .append(label);
425
+
426
+ if (this.options.readOnly){
427
+ tag.addClass('tagit-choice-read-only');
428
+ } else {
429
+ tag.addClass('tagit-choice-editable');
430
+ // Button for removing the tag.
431
+ var removeTagIcon = $('<span></span>')
432
+ .addClass('ui-icon ui-icon-close');
433
+ var removeTag = $('<a><span class="text-icon">\xd7</span></a>') // \xd7 is an X
434
+ .addClass('tagit-close')
435
+ .append(removeTagIcon)
436
+ .click(function(e) {
437
+ // Removes a tag when the little 'x' is clicked.
438
+ that.removeTag(tag);
439
+ });
440
+ tag.append(removeTag);
441
+ }
442
+
443
+ // Unless options.singleField is set, each tag has a hidden input field inline.
444
+ if (!this.options.singleField) {
445
+ var escapedValue = label.html();
446
+ tag.append('<input type="hidden" style="display:none;" value="' + escapedValue + '" name="' + this.options.fieldName + '" />');
447
+ }
448
+
449
+ if (this._trigger('beforeTagAdded', null, {
450
+ tag: tag,
451
+ tagLabel: this.tagLabel(tag),
452
+ duringInitialization: duringInitialization
453
+ }) === false) {
454
+ return;
455
+ }
456
+
457
+ if (this.options.singleField) {
458
+ var tags = this.assignedTags();
459
+ tags.push(value);
460
+ this._updateSingleTagsField(tags);
461
+ }
462
+
463
+ // DEPRECATED.
464
+ this._trigger('onTagAdded', null, tag);
465
+
466
+ this.tagInput.val('');
467
+
468
+ // Insert tag.
469
+ this.tagInput.parent().before(tag);
470
+
471
+ this._trigger('afterTagAdded', null, {
472
+ tag: tag,
473
+ tagLabel: this.tagLabel(tag),
474
+ duringInitialization: duringInitialization
475
+ });
476
+
477
+ if (this.options.showAutocompleteOnFocus && !duringInitialization) {
478
+ setTimeout(function () { that._showAutocomplete(); }, 0);
479
+ }
480
+ },
481
+
482
+ removeTag: function(tag, animate) {
483
+ animate = typeof animate === 'undefined' ? this.options.animate : animate;
484
+
485
+ tag = $(tag);
486
+
487
+ // DEPRECATED.
488
+ this._trigger('onTagRemoved', null, tag);
489
+
490
+ if (this._trigger('beforeTagRemoved', null, {tag: tag, tagLabel: this.tagLabel(tag)}) === false) {
491
+ return;
492
+ }
493
+
494
+ if (this.options.singleField) {
495
+ var tags = this.assignedTags();
496
+ var removedTagLabel = this.tagLabel(tag);
497
+ tags = $.grep(tags, function(el){
498
+ return el != removedTagLabel;
499
+ });
500
+ this._updateSingleTagsField(tags);
501
+ }
502
+
503
+ if (animate) {
504
+ tag.addClass('removed'); // Excludes this tag from _tags.
505
+ var hide_args = this._effectExists('blind') ? ['blind', {direction: 'horizontal'}, 'fast'] : ['fast'];
506
+
507
+ var thisTag = this;
508
+ hide_args.push(function() {
509
+ tag.remove();
510
+ thisTag._trigger('afterTagRemoved', null, {tag: tag, tagLabel: thisTag.tagLabel(tag)});
511
+ });
512
+
513
+ tag.fadeOut('fast').hide.apply(tag, hide_args).dequeue();
514
+ } else {
515
+ tag.remove();
516
+ this._trigger('afterTagRemoved', null, {tag: tag, tagLabel: this.tagLabel(tag)});
517
+ }
518
+
519
+ },
520
+
521
+ removeTagByLabel: function(tagLabel, animate) {
522
+ var toRemove = this._findTagByLabel(tagLabel);
523
+ if (!toRemove) {
524
+ throw "No such tag exists with the name '" + tagLabel + "'";
525
+ }
526
+ this.removeTag(toRemove, animate);
527
+ },
528
+
529
+ removeAll: function() {
530
+ // Removes all tags.
531
+ var that = this;
532
+ this._tags().each(function(index, tag) {
533
+ that.removeTag(tag, false);
534
+ });
535
+ }
536
+
537
+ });
538
+ })(jQuery);
539
+
@@ -0,0 +1,16 @@
1
+ (function(b){b.widget("ui.tagit",{options:{allowDuplicates:!1,caseSensitive:!0,fieldName:"tags",placeholderText:null,readOnly:!1,removeConfirmation:!1,tagLimit:null,availableTags:[],autocomplete:{},showAutocompleteOnFocus:!1,allowSpaces:!1,singleField:!1,singleFieldDelimiter:",",singleFieldNode:null,animate:!0,tabIndex:null,beforeTagAdded:null,afterTagAdded:null,beforeTagRemoved:null,afterTagRemoved:null,onTagClicked:null,onTagLimitExceeded:null,onTagAdded:null,onTagRemoved:null,tagSource:null},_create:function(){var a=
2
+ this;this.element.is("input")?(this.tagList=b("<ul></ul>").insertAfter(this.element),this.options.singleField=!0,this.options.singleFieldNode=this.element,this.element.css("display","none")):this.tagList=this.element.find("ul, ol").andSelf().last();this.tagInput=b('<input type="text" />').addClass("ui-widget-content");this.options.readOnly&&this.tagInput.attr("disabled","disabled");this.options.tabIndex&&this.tagInput.attr("tabindex",this.options.tabIndex);this.options.placeholderText&&this.tagInput.attr("placeholder",
3
+ this.options.placeholderText);this.options.autocomplete.source||(this.options.autocomplete.source=function(a,c){var d=a.term.toLowerCase(),e=b.grep(this.options.availableTags,function(a){return 0===a.toLowerCase().indexOf(d)});c(this._subtractArray(e,this.assignedTags()))});this.options.showAutocompleteOnFocus&&(this.tagInput.focus(function(){a._showAutocomplete()}),"undefined"===typeof this.options.autocomplete.minLength&&(this.options.autocomplete.minLength=0));b.isFunction(this.options.autocomplete.source)&&
4
+ (this.options.autocomplete.source=b.proxy(this.options.autocomplete.source,this));b.isFunction(this.options.tagSource)&&(this.options.tagSource=b.proxy(this.options.tagSource,this));this.tagList.addClass("tagit").addClass("ui-widget ui-widget-content ui-corner-all").append(b('<li class="tagit-new"></li>').append(this.tagInput)).click(function(c){var d=b(c.target);d.hasClass("tagit-label")?(d=d.closest(".tagit-choice"),d.hasClass("removed")||a._trigger("onTagClicked",c,{tag:d,tagLabel:a.tagLabel(d)})):
5
+ a.tagInput.focus()});var d=!1;if(this.options.singleField)if(this.options.singleFieldNode){var c=b(this.options.singleFieldNode),e=c.val().split(this.options.singleFieldDelimiter);c.val("");b.each(e,function(b,c){a.createTag(c,null,!0);d=!0})}else this.options.singleFieldNode=b('<input type="hidden" style="display:none;" value="" name="'+this.options.fieldName+'" />'),this.tagList.after(this.options.singleFieldNode);d||this.tagList.children("li").each(function(){b(this).hasClass("tagit-new")||(a.createTag(b(this).text(),
6
+ b(this).attr("class"),!0),b(this).remove())});this.tagInput.keydown(function(c){if(c.which==b.ui.keyCode.BACKSPACE&&""===a.tagInput.val()){var d=a._lastTag();!a.options.removeConfirmation||d.hasClass("remove")?a.removeTag(d):a.options.removeConfirmation&&d.addClass("remove ui-state-highlight")}else a.options.removeConfirmation&&a._lastTag().removeClass("remove ui-state-highlight");if(c.which===b.ui.keyCode.COMMA||c.which===b.ui.keyCode.ENTER||c.which==b.ui.keyCode.TAB&&""!==a.tagInput.val()||c.which==
7
+ b.ui.keyCode.SPACE&&!0!==a.options.allowSpaces&&('"'!=b.trim(a.tagInput.val()).replace(/^s*/,"").charAt(0)||'"'==b.trim(a.tagInput.val()).charAt(0)&&'"'==b.trim(a.tagInput.val()).charAt(b.trim(a.tagInput.val()).length-1)&&0!==b.trim(a.tagInput.val()).length-1))c.which===b.ui.keyCode.ENTER&&""===a.tagInput.val()||c.preventDefault(),a.createTag(a._cleanedInput()),a.tagInput.autocomplete("close")}).blur(function(){a.tagInput.data("autocomplete-open")||a.createTag(a._cleanedInput())});if(this.options.availableTags||
8
+ this.options.tagSource||this.options.autocomplete.source)c={select:function(b,c){a.createTag(c.item.value);return!1}},b.extend(c,this.options.autocomplete),c.source=this.options.tagSource||c.source,this.tagInput.autocomplete(c).bind("autocompleteopen",function(){a.tagInput.data("autocomplete-open",!0)}).bind("autocompleteclose",function(){a.tagInput.data("autocomplete-open",!1)})},_cleanedInput:function(){return b.trim(this.tagInput.val().replace(/^"(.*)"$/,"$1"))},_lastTag:function(){return this.tagList.find(".tagit-choice:last:not(.removed)")},
9
+ _tags:function(){return this.tagList.find(".tagit-choice:not(.removed)")},assignedTags:function(){var a=this,d=[];this.options.singleField?(d=b(this.options.singleFieldNode).val().split(this.options.singleFieldDelimiter),""===d[0]&&(d=[])):this._tags().each(function(){d.push(a.tagLabel(this))});return d},_updateSingleTagsField:function(a){b(this.options.singleFieldNode).val(a.join(this.options.singleFieldDelimiter)).trigger("change")},_subtractArray:function(a,d){for(var c=[],e=0;e<a.length;e++)-1==
10
+ b.inArray(a[e],d)&&c.push(a[e]);return c},tagLabel:function(a){return this.options.singleField?b(a).find(".tagit-label:first").text():b(a).find("input:first").val()},_showAutocomplete:function(){this.tagInput.autocomplete("search","")},_findTagByLabel:function(a){var d=this,c=null;this._tags().each(function(){if(d._formatStr(a)==d._formatStr(d.tagLabel(this)))return c=b(this),!1});return c},_isNew:function(a){return!this._findTagByLabel(a)},_formatStr:function(a){return this.options.caseSensitive?
11
+ a:b.trim(a.toLowerCase())},_effectExists:function(a){return Boolean(b.effects&&(b.effects[a]||b.effects.effect&&b.effects.effect[a]))},createTag:function(a,d,c){var e=this;a=b.trim(a);this.options.preprocessTag&&(a=this.options.preprocessTag(a));if(""===a)return!1;if(!this.options.allowDuplicates&&!this._isNew(a))return a=this._findTagByLabel(a),!1!==this._trigger("onTagExists",null,{existingTag:a,duringInitialization:c})&&this._effectExists("highlight")&&a.effect("highlight"),!1;if(this.options.tagLimit&&
12
+ this._tags().length>=this.options.tagLimit)return this._trigger("onTagLimitExceeded",null,{duringInitialization:c}),!1;var g=b(this.options.onTagClicked?'<a class="tagit-label"></a>':'<span class="tagit-label"></span>').text(a),f=b("<li></li>").addClass("tagit-choice ui-widget-content ui-state-default ui-corner-all").addClass(d).append(g);this.options.readOnly?f.addClass("tagit-choice-read-only"):(f.addClass("tagit-choice-editable"),d=b("<span></span>").addClass("ui-icon ui-icon-close"),d=b('<a><span class="text-icon">\u00d7</span></a>').addClass("tagit-close").append(d).click(function(){e.removeTag(f)}),
13
+ f.append(d));this.options.singleField||(g=g.html(),f.append('<input type="hidden" style="display:none;" value="'+g+'" name="'+this.options.fieldName+'" />'));!1!==this._trigger("beforeTagAdded",null,{tag:f,tagLabel:this.tagLabel(f),duringInitialization:c})&&(this.options.singleField&&(g=this.assignedTags(),g.push(a),this._updateSingleTagsField(g)),this._trigger("onTagAdded",null,f),this.tagInput.val(""),this.tagInput.parent().before(f),this._trigger("afterTagAdded",null,{tag:f,tagLabel:this.tagLabel(f),
14
+ duringInitialization:c}),this.options.showAutocompleteOnFocus&&!c&&setTimeout(function(){e._showAutocomplete()},0))},removeTag:function(a,d){d="undefined"===typeof d?this.options.animate:d;a=b(a);this._trigger("onTagRemoved",null,a);if(!1!==this._trigger("beforeTagRemoved",null,{tag:a,tagLabel:this.tagLabel(a)})){if(this.options.singleField){var c=this.assignedTags(),e=this.tagLabel(a),c=b.grep(c,function(a){return a!=e});this._updateSingleTagsField(c)}if(d){a.addClass("removed");var c=this._effectExists("blind")?
15
+ ["blind",{direction:"horizontal"},"fast"]:["fast"],g=this;c.push(function(){a.remove();g._trigger("afterTagRemoved",null,{tag:a,tagLabel:g.tagLabel(a)})});a.fadeOut("fast").hide.apply(a,c).dequeue()}else a.remove(),this._trigger("afterTagRemoved",null,{tag:a,tagLabel:this.tagLabel(a)})}},removeTagByLabel:function(a,b){var c=this._findTagByLabel(a);if(!c)throw"No such tag exists with the name '"+a+"'";this.removeTag(c,b)},removeAll:function(){var a=this;this._tags().each(function(b,c){a.removeTag(c,
16
+ !1)})}})})(jQuery);
@@ -0,0 +1,67 @@
1
+ ul.tagit {
2
+ padding: 1px 5px;
3
+ overflow: auto;
4
+ margin-left: inherit; /* usually we don't want the regular ul margins. */
5
+ margin-right: inherit;
6
+ }
7
+ ul.tagit li {
8
+ display: block;
9
+ float: left;
10
+ margin: 2px 5px 2px 0;
11
+ }
12
+ ul.tagit li.tagit-choice {
13
+ position: relative;
14
+ line-height: inherit;
15
+ }
16
+
17
+ ul.tagit li.tagit-choice-read-only {
18
+ padding: .2em .5em .2em .5em;
19
+ }
20
+
21
+ ul.tagit li.tagit-choice-editable {
22
+ padding: .2em 18px .2em .5em;
23
+ }
24
+
25
+ ul.tagit li.tagit-new {
26
+ padding: .25em 4px .25em 0;
27
+ }
28
+
29
+ ul.tagit li.tagit-choice a.tagit-label {
30
+ cursor: pointer;
31
+ text-decoration: none;
32
+ }
33
+ ul.tagit li.tagit-choice .tagit-close {
34
+ cursor: pointer;
35
+ position: absolute;
36
+ right: .1em;
37
+ top: 50%;
38
+ margin-top: -8px;
39
+ line-height: 17px;
40
+ }
41
+
42
+ /* used for some custom themes that don't need image icons */
43
+ ul.tagit li.tagit-choice .tagit-close .text-icon {
44
+ display: none;
45
+ }
46
+
47
+ ul.tagit li.tagit-choice input {
48
+ display: block;
49
+ float: left;
50
+ margin: 2px 5px 2px 0;
51
+ }
52
+ ul.tagit input[type="text"] {
53
+ -moz-box-sizing: border-box;
54
+ -webkit-box-sizing: border-box;
55
+ box-sizing: border-box;
56
+
57
+ -moz-box-shadow: none;
58
+ -webkit-box-shadow: none;
59
+ box-shadow: none;
60
+
61
+ border: none;
62
+ margin: 0;
63
+ padding: 0;
64
+ width: inherit;
65
+ background-color: inherit;
66
+ outline: none;
67
+ }
@@ -0,0 +1,56 @@
1
+
2
+ /* Optional scoped theme for tag-it which mimics the zendesk widget. */
3
+
4
+
5
+ ul.tagit {
6
+ border-style: solid;
7
+ border-width: 1px;
8
+ border-color: #C6C6C6;
9
+ background: inherit;
10
+ }
11
+ ul.tagit li.tagit-choice {
12
+ -moz-border-radius: 6px;
13
+ border-radius: 6px;
14
+ -webkit-border-radius: 6px;
15
+ border: 1px solid #CAD8F3;
16
+
17
+ background: none;
18
+ background-color: #DEE7F8;
19
+
20
+ font-weight: normal;
21
+ }
22
+ ul.tagit li.tagit-choice .tagit-label:not(a) {
23
+ color: #555;
24
+ }
25
+ ul.tagit li.tagit-choice a.tagit-close {
26
+ text-decoration: none;
27
+ }
28
+ ul.tagit li.tagit-choice .tagit-close {
29
+ right: .4em;
30
+ }
31
+ ul.tagit li.tagit-choice .ui-icon {
32
+ display: none;
33
+ }
34
+ ul.tagit li.tagit-choice .tagit-close .text-icon {
35
+ display: inline;
36
+ font-family: arial, sans-serif;
37
+ font-size: 16px;
38
+ line-height: 16px;
39
+ color: #777;
40
+ }
41
+ ul.tagit li.tagit-choice:hover, ul.tagit li.tagit-choice.remove {
42
+ background-color: #bbcef1;
43
+ border-color: #6d95e0;
44
+ }
45
+ ul.tagit li.tagit-choice a.tagLabel:hover,
46
+ ul.tagit li.tagit-choice a.tagit-close .text-icon:hover {
47
+ color: #222;
48
+ }
49
+ ul.tagit input[type="text"] {
50
+ color: #333333;
51
+ background: none;
52
+ }
53
+ .ui-widget {
54
+ font-size: 1.1em;
55
+ }
56
+
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taggingform
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - bydmm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-16 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: a plugin with jquery plug tagging http://aehlke.github.io/tag-it/
15
+ email: miku@maimoe.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - Gemfile
22
+ - README.md
23
+ - lib/taggingform.rb
24
+ - lib/taggingform/engine.rb
25
+ - lib/taggingform/helper.rb
26
+ - lib/taggingform/version.rb
27
+ - taggingform.gemspec
28
+ - vendor/assets/javascripts/taggingform/tag-it.js
29
+ - vendor/assets/javascripts/taggingform/tag-it.min.js
30
+ - vendor/assets/stylesheets/taggingform/jquery.tagit.css
31
+ - vendor/assets/stylesheets/taggingform/tagit.ui-zendesk.css
32
+ homepage: http://rubygemgem.org/gems/taggingform
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.25
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: a plugin with jquery plug tagging!
56
+ test_files: []