diff --git a/README.md b/README.md index bd0dcb5..84455d0 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ option to false. 'onAddTag':callback_function, 'onRemoveTag':callback_function, 'onChange' : callback_function, + 'delimiter': [',',';'], 'removeWithBackspace' : true, 'minChars' : 0, 'maxChars' : 0 //if not provided there is no limit, diff --git a/example.html b/example.html index 2dea0a5..d2057af 100644 --- a/example.html +++ b/example.html @@ -1,7 +1,7 @@ - + - + - - + +
\ No newline at end of file + + diff --git a/jquery.tagsinput.js b/jquery.tagsinput.js index dd39357..cdff353 100644 --- a/jquery.tagsinput.js +++ b/jquery.tagsinput.js @@ -1,12 +1,12 @@ /* jQuery Tags Input Plugin 1.3.3 - + Copyright (c) 2011 XOXCO, Inc - + Documentation for this plugin lives here: http://xoxco.com/clickable/jquery-tags-input - + Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php @@ -24,9 +24,9 @@ val = '', input = $(this), testSubject = $('#'+$(this).data('tester_id')); - + if (val === (val = input.val())) {return;} - + // Enter new content into testSubject var escaped = val.replace(/&/g, '&').replace(/\s/g,' ').replace(//g, '>'); testSubject.html(escaped); @@ -36,7 +36,7 @@ currentWidth = input.width(), isValidWidthChange = (newWidth < currentWidth && newWidth >= minWidth) || (newWidth > minWidth && newWidth < maxWidth); - + // Animate width if (isValidWidthChange) { input.width(newWidth); @@ -72,19 +72,19 @@ input.data('tester_id', testerId); input.css('width', minWidth); }; - + $.fn.addTag = function(value,options) { options = jQuery.extend({focus:false,callback:true},options); - this.each(function() { + this.each(function() { var id = $(this).attr('id'); var tagslist = $(this).val().split(delimiter[id]); - if (tagslist[0] == '') { + if (tagslist[0] == '') { tagslist = new Array(); } value = jQuery.trim(value); - + if (options.unique) { var skipTag = $(this).tagExist(value); if(skipTag == true) { @@ -92,10 +92,10 @@ $('#'+id+'_tag').addClass('not_valid'); } } else { - var skipTag = false; + var skipTag = false; } - - if (value !='' && skipTag != true) { + + if (value !='' && skipTag != true) { $('').addClass('tag').append( $('').text(value).append(' '), $('', { @@ -108,16 +108,16 @@ ).insertBefore('#' + id + '_addTag'); tagslist.push(value); - + $('#'+id+'_tag').val(''); if (options.focus) { $('#'+id+'_tag').focus(); - } else { + } else { $('#'+id+'_tag').blur(); } - + $.fn.tagsInput.updateTagsField(this,tagslist); - + if (options.callback && tags_callbacks[id] && tags_callbacks[id]['onAddTag']) { var f = tags_callbacks[id]['onAddTag']; f.call(this, value); @@ -127,29 +127,29 @@ var i = tagslist.length; var f = tags_callbacks[id]['onChange']; f.call(this, $(this), tagslist[i-1]); - } + } } - - }); - + + }); + return false; }; - - $.fn.removeTag = function(value) { + + $.fn.removeTag = function(value) { value = unescape(value); - this.each(function() { + this.each(function() { var id = $(this).attr('id'); - + var old = $(this).val().split(delimiter[id]); - + $('#'+id+'_tagsinput .tag').remove(); str = ''; - for (i=0; i< old.length; i++) { - if (old[i]!=value) { + for (i=0; i< old.length; i++) { + if (old[i]!=value) { str = str + delimiter[id] +old[i]; } } - + $.fn.tagsInput.importTags(this,str); if (tags_callbacks[id] && tags_callbacks[id]['onRemoveTag']) { @@ -157,24 +157,24 @@ f.call(this, value); } }); - + return false; }; - + $.fn.tagExist = function(val) { var id = $(this).attr('id'); var tagslist = $(this).val().split(delimiter[id]); return (jQuery.inArray(val, tagslist) >= 0); //true when tag exists, false when not }; - + // clear all existing tags and import new ones from a string $.fn.importTags = function(str) { id = $(this).attr('id'); $('#'+id+'_tagsinput .tag').remove(); $.fn.tagsInput.importTags(this,str); } - - $.fn.tagsInput = function(options) { + + $.fn.tagsInput = function(options) { var settings = jQuery.extend({ interactive:true, defaultText:'add a tag', @@ -182,9 +182,9 @@ width:'300px', height:'100px', autocomplete: {selectFirst: false }, - 'hide':true, - 'delimiter':',', - 'unique':true, + hide:true, + delimiter:[',',';'], + unique:true, removeWithBackspace:true, placeholderColor:'#666666', autosize: true, @@ -192,15 +192,15 @@ inputPadding: 6*2 },options); - this.each(function() { - if (settings.hide) { - $(this).hide(); + this.each(function() { + if (settings.hide) { + $(this).hide(); } var id = $(this).attr('id'); if (!id || delimiter[$(this).attr('id')]) { id = $(this).attr('id', 'tags' + new Date().getTime()).attr('id'); } - + var data = jQuery.extend({ pid:id, real_input: '#'+id, @@ -208,55 +208,55 @@ input_wrapper: '#'+id+'_addTag', fake_input: '#'+id+'_tag' },settings); - + delimiter[id] = data.delimiter; - + if (settings.onAddTag || settings.onRemoveTag || settings.onChange) { tags_callbacks[id] = new Array(); tags_callbacks[id]['onAddTag'] = settings.onAddTag; tags_callbacks[id]['onRemoveTag'] = settings.onRemoveTag; tags_callbacks[id]['onChange'] = settings.onChange; } - + var markup = '