Skip to content

Repository files navigation

Bootstrap Tags

Bootstrap Tags is a jQuery plugin meant to extend Twitter Bootstrap to include tagging functionality. It supports Bootstrap 2.3.2 and ≥ 3.0.

Build Status

Demo

http://maxwells.github.com/bootstrap-tags.html

Installation

$ bower install bootstrap-tags

or

$ git clone https://github.com/maxwells/bootstrap-tags.git
--> js files are located in dist/js, CSS in dist/css

Features

  • Support for Bootstrap 2.3.2 and 3+
  • Autosuggest (for typing or activated by pressing the down key when empty)
  • Bootstrap Popovers (for extended information on a tag)
  • Exclusions (denial of a specified list)
  • Filters (allowance of only a specified list)
  • Placeholder prompts
  • Uses bootstrap button-[type] class styling (customizing your bootstrap will change tag styles accordingly)
  • Extensible with custom functions (eg, before/after tag addition/deletion, key presses, exclusions)

Usage

<!-- include bootstrap tags js, css files -->
<script src='path/to/bootstrap-tags/dist/js/bootstrap-tags.min.js'></script>
<link rel="stylesheet" type="text/css" href="path/to/bootstrap-tags/dist/css/bootstrap-tags.css" />
<div id="my-tag-list" class="tag-list"></div>
<script>
$(function() {
// If using Bootstrap 2, be sure to include:
// Tags.bootstrapVersion = "2";
$('#my-tag-list').tags({
tagData:["boilerplate", "tags"],
suggestions:["basic", "suggestions"],
excludeList:["not", "these", "words"]
});
});
</script>

Documentation

Settings

The following options are supported. Pass them as a javascript object to the tags jQuery function:

$('selector').tags({readOnly: true,tagData: ["a","prepopulated","list","of",tags],beforeAddingTag: function(tag){console.log(tag);}});
optiontypedescriptiondefault
bootstrapVersionStringspecify which version of bootstrap to format generated HTML for. Acceptable values are "2", "3"3
tagDataArraya list of tags to initialize the tagging interface with[]
tagSizeStringdescribes what size input to use. Acceptable values are "lg", "md", or "sm"md
readOnlybooleanwhether or not to disable user inputfalse
suggestionsArraya list of terms that will populate the autosuggest feature when a user types in the first character.[]
caseInsensitiveBooleanwhether or not autosuggest should ignore case sensitivityfalse
restrictToArraya list of allowed tags (will be combined with suggestions, if provided). User inputted tags that aren't included in this list will be ignored[]
excludeArraya list of case insensitive disallowed tags. Supports wildcarding (eg. ['*offensive*'] will ignore any word that has offensive in it)[]
popoverDataArraya list of popover data. The index of each element should match the index of corresponding tag in tagData arraynull
popoversBooleanwhether or not to enable bootstrap popovers on tag mouseoverwhether popoverData was provided
popoverTriggerStringindicates how popovers should be triggered. Acceptable values are 'click', 'hover', 'hoverShowClickHide'hover
tagClassStringwhich class the tag div will have for stylingbtn-info
promptTextStringplaceholder string when there are no tags and nothing typed inEnter tags…
maxNumTagsIntegerMaximum number of allowable (user-added) tags. All tags that are initialized in the tagData property are retained. If set, then input is disabled when the number of tags exceeds this value.-1 (no limit)
readOnlyEmptyMessageStringtext to be displayed if there are no tags in readonly mode. Can be HTMLNo tags to display...
beforeAddingTagfunction(String tag)anything external you'd like to do with the tag before adding it. Returning false will stop tag from being addednull
afterAddingTagfunction(String tag)anything external you'd like to do with the tag after adding itnull
beforeDeletingTagfunction(String tag)find out which tag is about to be deleted. Returning false will stop tag from being deletednull
afterDeletingTagfunction(String tag)find out which tag was removed by either pressing delete key or clicking the (x)null
definePopoverfunction(String tag)must return the popover content for the tag that is being added. (eg "Content for [tag]")null
excludesfunction(String tag)return true if you want the tag to be excluded, false if allowednull

Controlling tags

Some functions are chainable (returns a Tagger object), and can be used to move the data around outside of the plugin.

functionreturn typedescription
hasTag(tag:string)Booleanwhether tag is in tag list
getTags()Arraya list of tags currently in the interface
getTagsWithContent()Arraya list of javascript objects with a tag property and content property
getTag(tag:string)Stringreturns tag as string
getTagWithContent(tag:string)Objectreturns object with tag and content property (popover)
addTag(tag:string)Taggeradd a tag
renameTag(tag:string, newTag:string)Taggerrename one tag to another value
removeLastTag()Taggerremoves last tag if it exists
removeTag(tag:string)Taggerremoves tag specified by string if it exists
addTagWithContent(tag:string, popoverContent:string)TaggerAdd a tag with associated popover content
setPopover(tag:string, popoverContent:string)Taggerupdate a tag's associated popover content, if that tag exists

Example:

vartags=$('#one').tags({suggestions : ["here","are","some","suggestions"],popoverData : ["What a wonderful day","to make some stuff","up so that I","can show it works"],tagData: ["tag a","tag b","tag c","tag d"],excludeList : ["excuse","my","vulgarity"],});tags.addTag("tag e!!").removeTag("tag b").setPopover("tag c","Changed popover content");console.log(tags.getTags());

To reference a tags instance that you've already attached to a selector, (eg. $(selector).tags(options)) you can use $(selector).tags() or $(selector).tags(index)

Building

For a one off:

$ grunt build

To build continuously:

$ grunt watch

Testing

$ grunt test

Contributing

If you spot a bug, experience browser incompatibility, or have feature requests, please submit them here.

If you want to hack away to provide a new feature/bug-fix, please follow these guidelines:

  • Make changes to the coffeescript and sass files, not js/css. This is to ensure that the next person who comes in and edits upstream from js/css will not overwrite your changes.
  • Create a pull request for your feature branch, updating README documentation if necessary

License

This project rocks and uses the MIT-LICENSE.

Author

Max Lahey

About

Bootstrap-themed jquery tag interface

Resources

Stars

2 stars

Watchers

15 watching

Forks

Releases

Packages

Contributors

Languages