From 7ca77e22ed201c859ac6d3ed7a97624a9c965ea9 Mon Sep 17 00:00:00 2001 From: Leif Johansson Date: Fri, 4 Mar 2011 19:37:32 +0100 Subject: tagging works now --- site-media/js/tag-it.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'site-media') diff --git a/site-media/js/tag-it.js b/site-media/js/tag-it.js index 040cef4..9930a05 100644 --- a/site-media/js/tag-it.js +++ b/site-media/js/tag-it.js @@ -1,5 +1,10 @@ (function($) { + /** Available options are: + * availableTags (Array) -- Used as tag suggestions + * existingTags (Array) *optional -- Used to prefill the tag selector with tags + * namePrefix (String) *optional -- Used as input name attribute, default to "item[tags]" + */ $.fn.tagit = function(options) { var el = this; @@ -17,6 +22,12 @@ el.html (html_input_field); tag_input = el.children(".tagit-new").children(".tagit-input"); + + if (typeof options.existingTags != 'undefined' && typeof options.existingTags == 'object') { + for(var i in options.existingTags) { + create_choice(options.existingTags[i]); + } + } $(this).click(function(e){ if (e.target.tagName == 'A') { @@ -48,7 +59,7 @@ if (typed != "") { if (is_new (typed)) { - create_choice (typed); + create_choice(typed); } // Cleaning the input. tag_input.val(""); @@ -81,11 +92,12 @@ return is_new; } function create_choice (value){ + name_prefix = (typeof(options.namePrefix) == 'undefined') ? 'item[tags]' : options.namePrefix; var el = ""; el = "
  • \n"; el += value + "\n"; el += "x\n"; - el += "\n"; + el += "\n"; el += "
  • \n"; var li_search_tags = this.tag_input.parent(); $(el).insertBefore (li_search_tags); -- cgit v1.1