summaryrefslogtreecommitdiff
path: root/site-media/js
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2011-03-04 19:37:32 +0100
committerLeif Johansson <leifj@sunet.se>2011-03-04 19:37:32 +0100
commit7ca77e22ed201c859ac6d3ed7a97624a9c965ea9 (patch)
tree30ae9e735561b2dc64bc98786ecdd95fac53d9f5 /site-media/js
parent613ab889ea717c86cda5b61332027581d6eb61e8 (diff)
tagging works now
Diffstat (limited to 'site-media/js')
-rw-r--r--site-media/js/tag-it.js16
1 files changed, 14 insertions, 2 deletions
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 = "<li class=\"tagit-choice\">\n";
el += value + "\n";
el += "<a class=\"close\">x</a>\n";
- el += "<input type=\"hidden\" style=\"display:none;\" value=\""+value+"\" name=\"item[tags][]\">\n";
+ el += "<input type=\"hidden\" style=\"display:none;\" value=\""+value+"\" name=\""+name_prefix+"[]\">\n";
el += "</li>\n";
var li_search_tags = this.tag_input.parent();
$(el).insertBefore (li_search_tags);