tag_it 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in arun-tag-it.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Levy Carneiro Jr.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,217 @@
1
+ # Tag-it: a jQuery UI plugin
2
+
3
+ Tag-it was originally inspired by the "tag suggestion" form field in ZenDesk.com. Now it is a full jQuery UI widget, supporting various configurations and themes.
4
+
5
+
6
+ ## Demo
7
+
8
+ ![Screenshot](http://aehlke.github.com/tag-it/screenshot.png)
9
+
10
+ Check the [example.html](http://aehlke.github.com/tag-it/example.html) for several demos.
11
+
12
+
13
+ ## Usage
14
+
15
+ First, load [jQuery](http://jquery.com/) (v1.4 or greater), [jQuery UI](http://jqueryui.com/) (v1.8 or greater), and the plugin:
16
+
17
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
18
+ <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
19
+ <script src="js/tag-it.js" type="text/javascript" charset="utf-8"></script>
20
+
21
+ The plugin requires a jQuery UI theme to be present, as well as its own included base CSS file ([jquery.tagit.css](http://github.com/aehlke/tag-it/raw/master/css/jquery.tagit.css)). Here we use the Flick theme as an example:
22
+
23
+ <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/flick/jquery-ui.css">
24
+ <link href="css/jquery.tagit.css" rel="stylesheet" type="text/css">
25
+
26
+ Now, let's attach it to an existing `<ul>` box:
27
+
28
+ <script type="text/javascript">
29
+ $(document).ready(function() {
30
+ $("#mytags").tagit();
31
+ });
32
+ </script>
33
+
34
+ <ul id="mytags">
35
+ <!-- Existing list items will be pre-added to the tags -->
36
+ <li>Tag1</li>
37
+ <li>Tag2</li>
38
+ </ul>
39
+
40
+ This will turn the list into a tag-it list:
41
+
42
+ <ul id="mytags" class="tagit ui-widget ui-widget-content ui-corner-all">
43
+ <!-- Existing list items will be pre-added to the tags. -->
44
+ <li class="tagit-choice ui-widget-content ui-state-default ui-corner-all">
45
+ <span class="tagit-label">Tag1</span>
46
+ <a class="close"><span class="ui-icon ui-icon-close"></span></a>
47
+ <input type="hidden" style="display:none;" value="Tag1" name="item[tags][]">
48
+ </li>
49
+ <li class="tagit-choice ui-widget-content ui-state-default ui-corner-all">
50
+ <span class="tagit-label">Tag2</span>
51
+ <a class="close"><span class="ui-icon ui-icon-close"></span></a>
52
+ <input type="hidden" style="display:none;" value="Tag2" name="item[tags][]">
53
+ </li>
54
+ <li class="tagit-new">
55
+ <input type="text" class="ui-widget-content ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
56
+ </li>
57
+ </ul>
58
+
59
+ There are several other possible configurations and ways to instantiate the widget, including one that uses a single comma-delimited `input` field rather than one per tag, so see the **Options** documentation below as well as the [examples page](http://aehlke.github.com/tag-it/examples.html) which demonstrates most of them.
60
+
61
+
62
+ ## Theming
63
+
64
+ Tag-it is as easily themeable as any jQuery UI widget, using your own theme made with [Themeroller](http://jqueryui.com/themeroller/), or one of the jQuery UI [premade themes](http://jqueryui.com/themeroller/#themeGallery). The old ZenDesk-like theme is included as an optional CSS file ([tagit.ui-zendesk.css](http://github.com/aehlke/tag-it/raw/master/css/tagit.ui-zendesk.css)).
65
+
66
+
67
+ ## Options
68
+
69
+ Tag-it accepts several options to customize the behaviour:
70
+
71
+ ### itemName (String)
72
+
73
+ Used to build the name of the hidden input field: `itemName[fieldName][]`.
74
+
75
+ $("#mytags").tagit({
76
+ itemName: "user"
77
+ });
78
+
79
+ Defaults to *item*.
80
+
81
+ ### fieldName (String)
82
+
83
+ Used to build the name of the hidden input field: `itemName[fieldName][]`.
84
+
85
+ $("#mytags").tagit({
86
+ fieldName: "skills"
87
+ });
88
+
89
+ Defaults to *tags*.
90
+
91
+ ### availableTags (Array)
92
+
93
+ Used as source for the autocompletion.
94
+
95
+ $("#mytags").tagit({
96
+ availableTags: ["c++", "java", "php", "javascript", "ruby", "python", "c"]
97
+ });
98
+
99
+ Defaults to an empty array *[]*.
100
+
101
+ ### tagSource (function)
102
+
103
+ Can be overwritten in order to use custom autocompletion sources like Ajax requests.
104
+ The default function filters the strings in **availableTags** and subtracts the already assigned tags.
105
+
106
+ ### removeConfirmation (boolean)
107
+
108
+ When removeConfirmation is enabled the user has to press the backspace key twice to remove the last tag.
109
+ After the first keypress the last tag receives a *remove* css class which can be used to visually highlight the tag.
110
+
111
+ Defaults to *false*.
112
+
113
+ ### caseSensitive (boolean)
114
+
115
+ whether the duplication check should do a case sensitive check or not.
116
+
117
+ Defaults to *true*.
118
+
119
+ ### allowSpaces (boolean)
120
+
121
+ When allowSpaces is enabled the user is not required to wrap multi-word tags in quotation marks.
122
+ For example, the user can enter `John Smith` instead of `"John Smith"`.
123
+
124
+ Defaults to *false*.
125
+
126
+ ### singleField (boolean)
127
+
128
+ When enabled, will use a single hidden field for the form, rather than one per tag.
129
+ It will delimit tags in the field with **singleFieldDelimiter**.
130
+
131
+ Defaults to *false*, unless Tag-it was created on an `input` element, in which case **singleField** will be overridden as true.
132
+
133
+ ### singleFieldDelimiter (String)
134
+
135
+ Defaults to *","*
136
+
137
+ ### singleFieldNode (DomNode)
138
+
139
+ Set this to an input DOM node to use an existing form field.
140
+ Any text in it will be erased on init. But it will be populated with the text of tags as they are created, delimited by **singleFieldDelimiter**.
141
+ If this is not set, we create an input node for it, with the name given in **fieldName**, ignoring **itemName**.
142
+
143
+ Defaults to *null*, unless Tag-it was created on an `input` element, in which case **singleFieldNode** will be overridden with that element.
144
+
145
+ ### tabIndex (integer)
146
+ Optionally set a *tabindex* attribute on the `input` that gets created for tag-it user input.
147
+
148
+ Defaults to *null*
149
+
150
+
151
+ ## Events
152
+
153
+ ### onTagAdded (function, Callback)
154
+
155
+ Can be used to add custom behaviour before the Tag is added to the DOM.
156
+ The function receives an empty event, and the tag as parameters.
157
+
158
+ $("#mytags").tagit({
159
+ onTagAdded: function(event, tag) {
160
+ // do something special
161
+ }
162
+ });
163
+
164
+ ### onTagRemoved (function, Callback)
165
+
166
+ Can be used to add custom behaviour before the Tag is removed from the DOM.
167
+ The function receives an empty event, and the tag as parameters.
168
+
169
+ $("#mytags").tagit({
170
+ onTagRemoved: function(event, tag) {
171
+ // do something special
172
+ }
173
+ });
174
+
175
+ ### onTagClicked (function, Callback)
176
+
177
+ Can be used to add custom behaviour when the Tag is clicked from the DOM.
178
+ The function receives the click event and the tag as parameters.
179
+
180
+ $("#mytags").tagit({
181
+ onTagClicked: function(event, tag) {
182
+ // do something special
183
+ }
184
+ });
185
+
186
+
187
+ ## Methods
188
+
189
+ ### assignedTags()
190
+ Returns an array of the text values of all the tags currently in the widget.
191
+
192
+ $("#mytags").tagit("assignedTags");
193
+
194
+ ### createTag(tagName, additionalClass)
195
+ Adds new tag to the list. The `additionalClass` parameter is an optional way to add classes to the tag element.
196
+
197
+ $("#mytags").tagit("createTag", "brand-new-tag");
198
+
199
+ ### removeAll()
200
+ Clears the widget of all tags -- removes each tag it contains, so the onTagRemoved event callback (if set in the options) will be called for each.
201
+
202
+ $("#mytags").tagit("removeAll");
203
+
204
+
205
+ ## Authors
206
+
207
+ * [Levy Carneiro Jr.](http://github.com/levycarneiro) *original author*
208
+ * [Martin Rehfeld](http://github.com/martinrehfeld)
209
+ * [Tobias Schmidt](http://github.com/grobie)
210
+ * [Skylar Challand](http://github.com/sskylar)
211
+ * [Alex Ehlke](http://github.com/aehlke) *current maintainer*
212
+
213
+
214
+ ## License
215
+
216
+ tag-it is released under the [MIT license](http://github.com/aehlke/tag-it/raw/master/LICENSE).
217
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/TODO ADDED
@@ -0,0 +1,14 @@
1
+ * Update the autocomplete to use the new jQuery UI autocomplete widget. The
2
+ current one is deprecated, though still functional.
3
+
4
+ * Add keyboard shortcuts for highlighting tags to remove them upon backspace.
5
+
6
+ * minLength for autocomplete
7
+
8
+ * hide the singleFieldNode
9
+
10
+ * add quotesAllowed option (or quotedSpacesAllowed)
11
+
12
+ * autogrow the input (http://stackoverflow.com/questions/931207/is-there-a-jquery-autogrow-plugin-for-text-fields)
13
+
14
+
data/examples.html ADDED
@@ -0,0 +1,237 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Tag-it! example</title>
6
+
7
+ <!-- These few CSS files are just to make this example page look nice. You can ignore them. -->
8
+ <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.9.0/build/reset-fonts/reset-fonts.css">
9
+ <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.9.0/build/base/base-min.css">
10
+ <link href='http://fonts.googleapis.com/css?family=Brawler' rel='stylesheet' type='text/css'>
11
+ <link href="css/master.css" rel="stylesheet" type="text/css">
12
+ <link href="css/examples.css" rel="stylesheet" type="text/css">
13
+ <!-- /ignore -->
14
+
15
+
16
+ <!-- These 2 CSS files are required: any 1 jQuery UI theme CSS, plus the Tag-it base CSS. -->
17
+ <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/flick/jquery-ui.css">
18
+ <link rel="stylesheet" type="text/css" href="css/jquery.tagit.css">
19
+
20
+ <!-- This is an optional CSS theme that only applies to this widget. Use it in addition to the jQuery UI theme. -->
21
+ <link href="css/tagit.ui-zendesk.css" rel="stylesheet" type="text/css">
22
+
23
+ <!-- jQuery and jQuery UI are required dependencies. -->
24
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script>
25
+ <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
26
+
27
+ <!-- The real deal -->
28
+ <script src="js/tag-it.js" type="text/javascript" charset="utf-8"></script>
29
+
30
+ <script>
31
+ $(function(){
32
+ var sampleTags = ['c++', 'java', 'php', 'coldfusion', 'javascript', 'asp', 'ruby', 'python', 'c', 'scala', 'groovy', 'haskell', 'perl', 'erlang', 'apl', 'cobol', 'go', 'lua'];
33
+
34
+ //-------------------------------
35
+ // Minimal
36
+ //-------------------------------
37
+ $('#myTags').tagit();
38
+
39
+ //-------------------------------
40
+ // Single field
41
+ //-------------------------------
42
+ $('#singleFieldTags').tagit({
43
+ availableTags: sampleTags,
44
+ // This will make Tag-it submit a single form value, as a comma-delimited field.
45
+ singleField: true,
46
+ singleFieldNode: $('#mySingleField')
47
+ });
48
+
49
+ // singleFieldTags2 is an INPUT element, rather than a UL as in the other
50
+ // examples, so it automatically defaults to singleField.
51
+ $('#singleFieldTags2').tagit({
52
+ availableTags: sampleTags
53
+ });
54
+
55
+
56
+ //-------------------------------
57
+ // Preloading data in markup
58
+ //-------------------------------
59
+ $('#myULTags').tagit({
60
+ availableTags: sampleTags, // this param is of course optional. it's for autocomplete.
61
+ // configure the name of the input field (will be submitted with form), default: item[tags]
62
+ itemName: 'item',
63
+ fieldName: 'tags'
64
+ });
65
+
66
+ //-------------------------------
67
+ // Tag events
68
+ //-------------------------------
69
+ var eventTags = $('#eventTags');
70
+ eventTags.tagit({
71
+ availableTags: sampleTags,
72
+ onTagRemoved: function(evt, tag) {
73
+ console.log(evt);
74
+ alert('This tag is being removed: ' + eventTags.tagit('tagLabel', tag));
75
+ },
76
+ onTagClicked: function(evt, tag) {
77
+ console.log(tag);
78
+ alert('This tag was clicked: ' + eventTags.tagit('tagLabel', tag));
79
+ }
80
+ }).tagit('option', 'onTagAdded', function(evt, tag) {
81
+ // Add this callbackafter we initialize the widget,
82
+ // so that onTagAdded doesn't get called on page load.
83
+ alert('This tag is being added: ' + eventTags.tagit('tagLabel', tag));
84
+ });
85
+
86
+ //-------------------------------
87
+ // Tag-it methods
88
+ //-------------------------------
89
+ $('#methodTags').tagit({
90
+ availableTags: sampleTags
91
+ });
92
+
93
+ //-------------------------------
94
+ // Allow spaces without quotes.
95
+ //-------------------------------
96
+ $('#allowSpacesTags').tagit({
97
+ availableTags: sampleTags,
98
+ allowSpaces: true
99
+ });
100
+
101
+ //-------------------------------
102
+ // Remove confirmation
103
+ //-------------------------------
104
+ $('#removeConfirmationTags').tagit({
105
+ availableTags: sampleTags,
106
+ removeConfirmation: true
107
+ });
108
+
109
+ });
110
+ </script>
111
+
112
+ </head>
113
+ <body>
114
+
115
+ <a href="http://github.com/aehlke/tag-it"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub" /></a>
116
+
117
+ <div id="wrapper">
118
+ <div id="header">
119
+ <h2>Tag-it! Usage Examples</h2>
120
+
121
+ <ul id="nav">
122
+ <li><a href="http://aehlke.github.com/tag-it">&laquo; back to widget home</a></li>
123
+ </ul>
124
+ </div>
125
+
126
+ <div id="content">
127
+ <p>These demo various features of Tag-it. View the source to see how each works.</p>
128
+
129
+ <hr>
130
+ <h3>Minimal</h3>
131
+ <form>
132
+ <p>
133
+ Vanilla example &mdash; the absolute minimum amount of code required, no configuration. No autocomplete, either. See the other examples for that.
134
+ </p>
135
+ <ul id="myTags"></ul>
136
+ <input type="submit" value="Submit">
137
+ </form>
138
+
139
+ <hr>
140
+ <h3>Single Input Field</h3>
141
+ <form>
142
+ <p>
143
+ Example using a single input form field to hold all the tag values, instead of one per tag (see settings.singleField).
144
+ This method is particularly useful if you have a form with one input field for comma-delimited tags that you want to trivially "upgrade" to this fancy jQuery UI widget.
145
+ This configuration will also degrade nicely as well for browsers without JS &mdash; the default behavior is to have one input per tag, which does not degrade as well as one comma-delimited input.
146
+ </p>
147
+ <p>
148
+ Normally this input field will be hidden &mdash; we leave it visible here so you can see how it is manipulated by the widget:
149
+ <input name="tags" id="mySingleField" value="Apple, Orange" disabled="true"> <!-- only disabled for demonstration purposes -->
150
+ </p>
151
+ <ul id="singleFieldTags"></ul>
152
+ <input type="submit" value="Submit">
153
+ </form>
154
+
155
+ <hr>
156
+ <h3><a name="graceful-degredation"></a>Single Input Field (2)</h3>
157
+ <form>
158
+ <p>
159
+ If you instantiate Tag-it on an INPUT element, it will default to being singleField, with that INPUT element as the singleFieldNode. This is the simplest way to have a gracefully-degrading tag widget.
160
+ </p>
161
+ <input name="tags" id="singleFieldTags2" value="Apple, Orange">
162
+ <input type="submit" value="Submit">
163
+ </form>
164
+
165
+ <hr>
166
+ <h3>Spaces Allowed Without Quotes</h3>
167
+ <p>You can already do multiword tags with spaces in them by default, but those must be wrapped in quotes. This option lets you use spaces without requiring the user to quote the input.</p>
168
+ <p>There are normally 5 ways to insert a tag after inputting some text: space, comma, enter, selecting an autocomplete option, or defocusing the widget. With the "allowSpaces" option set to true, space no longer inserts a tag, it just adds a space to the current tag input.</p>
169
+ <form>
170
+ <p></p>
171
+ <ul id="allowSpacesTags"></ul>
172
+ <input type="submit" value="Submit">
173
+ </form>
174
+
175
+ <hr>
176
+ <h3>Preloading Data in Markup</h3>
177
+ <form>
178
+ <p>
179
+ Using a UL in HTML to prefill the widget with some tags.
180
+ </p>
181
+ <ul id="myULTags">
182
+ <!-- Existing list items will be pre-added to the tags. -->
183
+ <li>Tag1</li>
184
+ <li>Tag2</li>
185
+ </ul>
186
+ <input type="submit" value="Submit">
187
+ </form>
188
+
189
+ <hr>
190
+ <h3>Events</h3>
191
+ <form>
192
+ <p>Example of tag events. Try adding or removing a tag, or clicking on a tag's label.</p>
193
+ <ul id="eventTags">
194
+ <li>Click my label</li>
195
+ <li>Remove me</li>
196
+ </ul>
197
+ <input type="submit" value="Submit">
198
+ </form>
199
+
200
+ <hr>
201
+ <h3>Methods</h3>
202
+ <form>
203
+ <p>Demos the available widget methods. Click the links below the widget to try them.</p>
204
+ <ul id="methodTags"></ul>
205
+ <p><a href="#" onclick="var inp=prompt('Enter a tag value to test the createTag method.');$('#methodTags').tagit('createTag', inp);return false;">Create tag</a></p>
206
+ <p><a href="#" onclick="$('#methodTags').tagit('removeAll');return false;">Clear tags</a></p>
207
+ <input type="submit" value="Submit">
208
+ </form>
209
+
210
+ <hr>
211
+ <h3>Remove Confirmation</h3>
212
+ <form>
213
+ <p>
214
+ When removeConfirmation is enabled the user has to press the backspace key twice to remove the last tag.
215
+ </p>
216
+ <ul id="removeConfirmationTags">
217
+ <li>backspace me</li>
218
+ <li>me too</li>
219
+ </ul>
220
+ <input type="submit" value="Submit">
221
+ </form>
222
+
223
+ </div>
224
+
225
+
226
+
227
+ <div id="footer">
228
+ <div class="left">
229
+ <p>Built with <a href="http://jquery.com/" target="_blank">jQuery</a> and <a href="http://jqueryui.com/" target="_blank">jQuery UI</a>.</p>
230
+ <p>Originally created by <a href="http://levycarneiro.com/">Levy Carneiro Jr</a>. Currently maintained by <a href="http://github.com/aehlke">Alex Ehlke</a>.</p>
231
+ </div>
232
+ <p class="right weak">Template adopted from <a href="http://orderedlist.com/demos/fancy-zoom-jquery/">orderedlist.com</a></p>
233
+ <br class="clear"/>
234
+ </div>
235
+ </div>
236
+ </body>
237
+ </html>