diff --git a/bower.json b/bower.json index 90a1912..cc12f4d 100644 --- a/bower.json +++ b/bower.json @@ -1,12 +1,12 @@ { - "name": "jquery-tag-editor", + "name": "jquery-tag-editor-mj", "description": "A powerful and lightweight tag editor plugin for jQuery.", "version": "1.0.18", "dependencies": { "jquery": ">=1.7", "caret": null }, - "homepage": "https://github.com/Pixabay/jQuery-tagEditor", + "homepage": "https://github.com/marekjasinski/jQuery-tagEditor", "authors": [{ "name": "Simon Steinberger", "url": "https://pixabay.com/users/Simon/", diff --git a/delete.png b/delete.png index 492c9f4..be63b0b 100644 Binary files a/delete.png and b/delete.png differ diff --git a/jquery.tag-editor.js b/jquery.tag-editor.js index 8c6dbd0..b75dd19 100644 --- a/jquery.tag-editor.js +++ b/jquery.tag-editor.js @@ -1,5 +1,5 @@ /* - jQuery tagEditor v1.0.18 + jQuery tagEditor v1.0.18 modified by Marek Jasinski Copyright (c) 2014 Simon Steinberger / Pixabay GitHub: https://github.com/Pixabay/jQuery-tagEditor License: http://www.opensource.org/licenses/mit-license.php @@ -17,6 +17,46 @@ return tag.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); } + // helper - check first/second character + function typeOfTag(tag) { + switch(tag.substr(0,1)) { + case '@': + tag = tag.substring(1); + break; + case '$': + if (tag.substr(1,1) === '#') tag = tag.substring(2); + else tag = tag.substring(1); + break; + case '#': + if ((tag.substr(1,3) === 'vj:') || (tag.substr(1,3) === 'vJ:') || (tag.substr(1,3) === 'Vj:') || (tag.substr(1,3) === 'VJ:')) tag = tag.substring(4); + break; + default: + break; + } + return tag; + } + + // helper - set img in case of special characters + function typeOfTagThumb(tag) { + switch(tag.substr(0,1)) { + case '@': + tag = 'fa-at'; + break; + case '$': + if (tag.substr(1,1) === '#') tag = 'fa-globe'; + else tag = 'fa-user'; + break; + case '#': + if ((tag.substr(1,3) === 'vj:') || (tag.substr(1,3) === 'vJ:') || (tag.substr(1,3) === 'Vj:') || (tag.substr(1,3) === 'VJ:')) tag = 'visual vj'; + else tag = ''; + break; + default: + tag = ''; + break; + } + return tag; + } + // build options dictionary with default values var blur_result, o = $.extend({}, $.fn.tagEditor.defaults, options), selector = this; @@ -36,12 +76,12 @@ if (o.maxTags && ed.data('tags').length >= o.maxTags) return false; // insert new tag $('
  •  '+o.delimiter[0]+'
  • ').appendTo(ed).find('.tag-editor-tag') - .html('').addClass('active').find('input').val(val).blur(); + .html('').addClass('active').find('input').val(typeOfTag(val)).attr('data-tag', val).blur(); if (!blur) ed.click(); else $('.placeholder', ed).remove(); } else if (options == 'removeTag') { // trigger delete on matching tag, then click editor to create a new tag - $('.tag-editor-tag', ed).filter(function(){return $(this).html()==val;}).closest('li').find('.tag-editor-delete').click(); + $('.tag-editor-tag', ed).filter(function(){return $(this).attr('data-tag')==val;}).closest('li').find('.tag-editor-delete').click(); if (!blur) ed.click(); } else if (options == 'destroy') { el.removeClass('tag-editor-hidden-src').removeData('options').off('focus.tag-editor').next('.tag-editor').remove(); @@ -60,7 +100,7 @@ var tags = [], splits = sel.toString().split(el.prev().data('options').dregex); for (i=0; i
    '+o.placeholder+'
    '); } @@ -94,7 +134,7 @@ function update_globals(init){ var old_tags = tag_list.toString(); tag_list = $('.tag-editor-tag:not(.deleted)', ed).map(function(i, e) { - var val = $.trim($(this).hasClass('active') ? $(this).find('input').val() : $(e).text()); + var val = $.trim($(this).hasClass('active') ? $(this).find('input').val() : $(e).attr('data-tag')); if (val) return val; }).get(); ed.data('tags', tag_list); @@ -147,8 +187,8 @@ if ($(this).prev().hasClass('active')) { $(this).closest('li').find('input').caret(-1); return false; } var li = $(this).closest('li'), tag = li.find('.tag-editor-tag'); - if (o.beforeTagDelete(el, ed, tag_list, tag.html()) === false) return false; - tag.addClass('deleted').animate({width: 0}, o.animateDelete, function(){ li.remove(); set_placeholder(); }); + if (o.beforeTagDelete(el, ed, tag_list, tag.text()) === false) return false; + tag.addClass('deleted').animate({width: 0}, o.animateDelete, function(){ li.remove(); set_placeholder(); o.afterTagDelete(el, ed, tag_list, tag.text());}); update_globals(); return false; }); @@ -158,7 +198,7 @@ ed.on('mousedown', '.tag-editor-tag', function(e){ if (e.ctrlKey || e.which > 1) { var li = $(this).closest('li'), tag = li.find('.tag-editor-tag'); - if (o.beforeTagDelete(el, ed, tag_list, tag.html()) === false) return false; + if (o.beforeTagDelete(el, ed, tag_list, tag.text()) === false) return false; tag.addClass('deleted').animate({width: 0}, o.animateDelete, function(){ li.remove(); set_placeholder(); }); update_globals(); return false; @@ -171,10 +211,12 @@ if (!$(this).hasClass('active')) { var tag = $(this).html(); + var tagName = $(this).attr('data-tag'); + if (!tagName) tagName = ''; // guess cursor position in text input var left_percent = Math.abs(($(this).offset().left - e.pageX)/$(this).width()), caret_pos = parseInt(tag.length*left_percent), - input = $(this).html('').addClass('active').find('input'); - input.data('old_tag', tag).tagEditorInput().focus().caret(caret_pos); + input = $(this).html('').addClass('active').find('input'); + input.data('old_tag', tagName).tagEditorInput().focus().caret(caret_pos); if (o.autocomplete) { var aco = $.extend({}, o.autocomplete); // extend user provided autocomplete select method @@ -190,8 +232,8 @@ // helper: split into multiple tags, e.g. after paste function split_cleanup(input){ - var li = input.closest('li'), sub_tags = input.val().replace(/ +/, ' ').split(o.dregex), - old_tag = input.data('old_tag'), old_tags = tag_list.slice(0), exceeded = false, cb_val; // copy tag_list + var li = input.closest('li'), sub_tags = input.val().replace(/ +/, ' ').split(o.dregex), old_tag = input.data('old_tag'); + var old_tags = tag_list.slice(0), exceeded = false, cb_val; // copy tag_list for (var i=0; i
     '+o.delimiter[0]+'
    '+escape(tag)+'
    '); + li.before('
  •  '+o.delimiter[0]+'
    '+typeOfTag(escape(tag))+'
  • '); if (o.maxTags && old_tags.length >= o.maxTags) { exceeded = true; break; } } input.attr('maxlength', o.maxLength).removeData('old_tag').val('') @@ -221,7 +263,9 @@ return; } try { input.closest('li').remove(); } catch(e){} - if (old_tag) update_globals(); + if (old_tag) { + update_globals(); + } } else if (tag.indexOf(o.delimiter[0])>=0) { split_cleanup(input); return; } else if (tag != old_tag) { @@ -239,11 +283,15 @@ if (old_tag) update_globals(); } // remove duplicates - else if (o.removeDuplicates) - $('.tag-editor-tag:not(.active)', ed).each(function(){ if ($(this).html() == tag) $(this).closest('li').remove(); }); + else if (o.removeDuplicates) { + $('.tag-editor-tag:not(.active)', ed).each(function(){ if ($(this).text() == tag) $(this).closest('li').remove(); }); + + } + } + input.parent().text(typeOfTag(escape(tag))).attr('data-tag', escape(tag)).removeClass('active').prepend(''); + if (tag != old_tag) { + update_globals(); } - input.parent().html(escape(tag)).removeClass('active'); - if (tag != old_tag) update_globals(); set_placeholder(); }); @@ -313,6 +361,7 @@ // enter key else if (e.which == 13) { ed.trigger('click', [$t.closest('li').next('li').find('.tag-editor-tag')]); + o.afterClickEnter(); return false; } // pos1 @@ -334,7 +383,7 @@ if (tag) { if (o.forceLowercase) tag = tag.toLowerCase(); tag_list.push(tag); - ed.append('
  •  '+o.delimiter[0]+'
    '+escape(tag)+'
  • '); + ed.append('
  •  '+o.delimiter[0]+'
    '+typeOfTag(escape(tag))+'
  • '); } } update_globals(true); // true -> no onChange callback @@ -363,6 +412,8 @@ // callbacks onChange: function(){}, beforeTagSave: function(){}, - beforeTagDelete: function(){} + beforeTagDelete: function(){}, + afterTagDelete: function(){}, + afterClickEnter: function(){} }; }(jQuery)); diff --git a/jquery.tag-editor.min.js b/jquery.tag-editor.min.js index 68c9896..f12441c 100644 --- a/jquery.tag-editor.min.js +++ b/jquery.tag-editor.min.js @@ -1,3 +1,7 @@ -// jQuery tagEditor v1.0.18 -// https://github.com/Pixabay/jQuery-tagEditor -!function(t){t.fn.tagEditorInput=function(){var e=" ",i=t(this),a=parseInt(i.css("fontSize")),l=t("").css({position:"absolute",top:-9999,left:-9999,width:"auto",fontSize:i.css("fontSize"),fontFamily:i.css("fontFamily"),fontWeight:i.css("fontWeight"),letterSpacing:i.css("letterSpacing"),whiteSpace:"nowrap"}),r=function(){if(e!==(e=i.val())){l.html(e.replace(/&/g,"&").replace(/\s/g," ").replace(//g,">"));var t=l.width()+a;20>t&&(t=20),t!=i.width()&&i.width(t)}};return l.insertAfter(i),i.bind("keyup keydown focus",r)},t.fn.tagEditor=function(e,a,l){function r(t){return t.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function n(e){if(8==e.which||46==e.which||e.ctrlKey&&88==e.which){try{var a=getSelection(),l=t(a.getRangeAt(0).commonAncestorContainer)}catch(e){l=0}if(l&&l.hasClass("tag-editor")){var r=[],n=a.toString().split(l.prev().data("options").dregex);for(i=0;i=r.maxTags)return!1;t('
  •  '+r.delimiter[0]+'
  • ').appendTo(n).find(".tag-editor-tag").html('').addClass("active").find("input").val(a).blur(),l?t(".placeholder",n).remove():n.click()}else"removeTag"==e?(t(".tag-editor-tag",n).filter(function(){return t(this).html()==a}).closest("li").find(".tag-editor-delete").click(),l||n.click()):"destroy"==e&&i.removeClass("tag-editor-hidden-src").removeData("options").off("focus.tag-editor").next(".tag-editor").remove()}),"getTags"==e?d:this}return window.getSelection&&t(document).off("keydown.tag-editor").on("keydown.tag-editor",n),s.each(function(){function e(){!c.placeholder||n.length||t(".deleted, .placeholder, input",s).length||s.append('
  • '+c.placeholder+"
  • ")}function i(i){var a=n.toString();n=t(".tag-editor-tag:not(.deleted)",s).map(function(e,i){var a=t.trim(t(this).hasClass("active")?t(this).find("input").val():t(i).text());return a?a:void 0}).get(),s.data("tags",n),l.val(n.join(c.delimiter[0])),i||a!=n.toString()&&c.onChange(l,s,n),e()}function a(e){for(var a,o=e.closest("li"),d=e.val().replace(/ +/," ").split(c.dregex),g=e.data("old_tag"),f=n.slice(0),h=!1,u=0;u
     '+c.delimiter[0]+'
    '+r(p)+'
    '),c.maxTags&&f.length>=c.maxTags)){h=!0;break}e.attr("maxlength",c.maxLength).removeData("old_tag").val(""),h?e.blur():e.focus(),i()}var l=t(this),n=[],s=t("
      ').insertAfter(l);l.addClass("tag-editor-hidden-src").data("options",c).on("focus.tag-editor",function(){s.click()}),s.append('
    •  
    • ');var d='
    •  '+c.delimiter[0]+'
    • ';s.click(function(e,i){var a,l,r=99999;if(!window.getSelection||""==getSelection())return c.maxTags&&s.data("tags").length>=c.maxTags?(s.find("input").blur(),!1):(o=!0,t("input:focus",s).blur(),o?(o=!0,t(".placeholder",s).remove(),i&&i.length?l="before":t(".tag-editor-tag",s).each(function(){var n=t(this),o=n.offset(),c=o.left,s=o.top;e.pageY>=s&&e.pageY<=s+n.height()&&(e.pageXa&&(r=a,i=n))}),"before"==l?t(d).insertBefore(i.closest("li")).find(".tag-editor-tag").click():"after"==l?t(d).insertAfter(i.closest("li")).find(".tag-editor-tag").click():t(d).appendTo(s).find(".tag-editor-tag").click(),!1):!1)}),s.on("click",".tag-editor-delete",function(a){if(t(this).prev().hasClass("active"))return t(this).closest("li").find("input").caret(-1),!1;var r=t(this).closest("li"),o=r.find(".tag-editor-tag");return c.beforeTagDelete(l,s,n,o.html())===!1?!1:(o.addClass("deleted").animate({width:0},c.animateDelete,function(){r.remove(),e()}),i(),!1)}),c.clickDelete&&s.on("mousedown",".tag-editor-tag",function(a){if(a.ctrlKey||a.which>1){var r=t(this).closest("li"),o=r.find(".tag-editor-tag");return c.beforeTagDelete(l,s,n,o.html())===!1?!1:(o.addClass("deleted").animate({width:0},c.animateDelete,function(){r.remove(),e()}),i(),!1)}}),s.on("click",".tag-editor-tag",function(e){if(c.clickDelete&&(e.ctrlKey||e.which>1))return!1;if(!t(this).hasClass("active")){var i=t(this).html(),a=Math.abs((t(this).offset().left-e.pageX)/t(this).width()),l=parseInt(i.length*a),n=t(this).html('').addClass("active").find("input");if(n.data("old_tag",i).tagEditorInput().focus().caret(l),c.autocomplete){var o=t.extend({},c.autocomplete),d="select"in o?c.autocomplete.select:"";o.select=function(e,i){d&&d(e,i),setTimeout(function(){s.trigger("click",[t(".active",s).find("input").closest("li").next("li").find(".tag-editor-tag")])},20)},n.autocomplete(o)}}return!1}),s.on("blur","input",function(d){d.stopPropagation();var g=t(this),f=g.data("old_tag"),h=t.trim(g.val().replace(/ +/," ").replace(c.dregex,c.delimiter[0]));if(h){if(h.indexOf(c.delimiter[0])>=0)return void a(g);if(h!=f)if(c.forceLowercase&&(h=h.toLowerCase()),cb_val=c.beforeTagSave(l,s,n,f,h),h=cb_val||h,cb_val===!1){if(f)return g.val(f).focus(),o=!1,void i();try{g.closest("li").remove()}catch(d){}f&&i()}else c.removeDuplicates&&t(".tag-editor-tag:not(.active)",s).each(function(){t(this).html()==h&&t(this).closest("li").remove()})}else{if(f&&c.beforeTagDelete(l,s,n,f)===!1)return g.val(f).focus(),o=!1,void i();try{g.closest("li").remove()}catch(d){}f&&i()}g.parent().html(r(h)).removeClass("active"),h!=f&&i(),e()});var g;s.on("paste","input",function(e){t(this).removeAttr("maxlength"),g=t(this),setTimeout(function(){a(g)},30)});var f;s.on("keypress","input",function(e){c.delimiter.indexOf(String.fromCharCode(e.which))>=0&&(f=t(this),setTimeout(function(){a(f)},20))}),s.on("keydown","input",function(e){var i=t(this);if((37==e.which||!c.autocomplete&&38==e.which)&&!i.caret()||8==e.which&&!i.val()){var a=i.closest("li").prev("li").find(".tag-editor-tag");return a.length?a.click().find("input").caret(-1):!i.val()||c.maxTags&&s.data("tags").length>=c.maxTags||t(d).insertBefore(i.closest("li")).find(".tag-editor-tag").click(),!1}if((39==e.which||!c.autocomplete&&40==e.which)&&i.caret()==i.val().length){var r=i.closest("li").next("li").find(".tag-editor-tag");return r.length?r.click().find("input").caret(0):i.val()&&s.click(),!1}if(9==e.which){if(e.shiftKey){var a=i.closest("li").prev("li").find(".tag-editor-tag");if(a.length)a.click().find("input").caret(0);else{if(!i.val()||c.maxTags&&s.data("tags").length>=c.maxTags)return l.attr("disabled","disabled"),void setTimeout(function(){l.removeAttr("disabled")},30);t(d).insertBefore(i.closest("li")).find(".tag-editor-tag").click()}return!1}var r=i.closest("li").next("li").find(".tag-editor-tag");if(r.length)r.click().find("input").caret(0);else{if(!i.val())return;s.click()}return!1}if(!(46!=e.which||t.trim(i.val())&&i.caret()!=i.val().length)){var r=i.closest("li").next("li").find(".tag-editor-tag");return r.length?r.click().find("input").caret(0):i.val()&&s.click(),!1}if(13==e.which)return s.trigger("click",[i.closest("li").next("li").find(".tag-editor-tag")]),!1;if(36!=e.which||i.caret()){if(35==e.which&&i.caret()==i.val().length)s.find(".tag-editor-tag").last().click();else if(27==e.which)return i.val(i.data("old_tag")?i.data("old_tag"):"").blur(),!1}else s.find(".tag-editor-tag").first().click()});for(var h=c.initialTags.length?c.initialTags:l.val().split(c.dregex),u=0;u=c.maxTags);u++){var p=t.trim(h[u].replace(/ +/," "));p&&(c.forceLowercase&&(p=p.toLowerCase()),n.push(p),s.append('
    •  '+c.delimiter[0]+'
      '+r(p)+'
    • '))}i(!0),c.sortable&&t.fn.sortable&&s.sortable({distance:5,cancel:".tag-editor-spacer, input",helper:"clone",update:function(){i()}})})},t.fn.tagEditor.defaults={initialTags:[],maxTags:0,maxLength:50,delimiter:",;",placeholder:"",forceLowercase:!0,removeDuplicates:!0,clickDelete:!1,animateDelete:175,sortable:!0,autocomplete:null,onChange:function(){},beforeTagSave:function(){},beforeTagDelete:function(){}}}(jQuery); \ No newline at end of file +/* + jQuery tagEditor v1.0.18 modified by Marek Jasinski + Copyright (c) 2014 Simon Steinberger / Pixabay + GitHub: https://github.com/Pixabay/jQuery-tagEditor + License: http://www.opensource.org/licenses/mit-license.php +*/ +!function(a){a.fn.tagEditorInput=function(){var b=" ",c=a(this),d=parseInt(c.css("fontSize")),e=a("").css({position:"absolute",top:-9999,left:-9999,width:"auto",fontSize:c.css("fontSize"),fontFamily:c.css("fontFamily"),fontWeight:c.css("fontWeight"),letterSpacing:c.css("letterSpacing"),whiteSpace:"nowrap"}),f=function(){if(b!==(b=c.val())){e.html(b.replace(/&/g,"&").replace(/\s/g," ").replace(//g,">"));var a=e.width()+d;20>a&&(a=20),a!=c.width()&&c.width(a)}};return e.insertAfter(c),c.bind("keyup keydown focus",f)},a.fn.tagEditor=function(b,c,d){function e(a){return a.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")}function f(a){switch(a.substr(0,1)){case"@":a=a.substring(1);break;case"$":a="#"===a.substr(1,1)?a.substring(2):a.substring(1);break;case"#":("vj:"===a.substr(1,3)||"vJ:"===a.substr(1,3)||"Vj:"===a.substr(1,3)||"VJ:"===a.substr(1,3))&&(a=a.substring(4))}return a}function g(a){switch(a.substr(0,1)){case"@":a="fa-at";break;case"$":a="#"===a.substr(1,1)?"fa-globe":"fa-user";break;case"#":a="vj:"===a.substr(1,3)||"vJ:"===a.substr(1,3)||"Vj:"===a.substr(1,3)||"VJ:"===a.substr(1,3)?"visual vj":"";break;default:a=""}return a}function m(b){if(8==b.which||46==b.which||b.ctrlKey&&88==b.which){try{var c=getSelection(),d=a(c.getRangeAt(0).commonAncestorContainer)}catch(b){d=0}if(d&&d.hasClass("tag-editor")){var e=[],f=c.toString().split(d.prev().data("options").dregex);for(i=0;i=g.maxTags)return!1;a('
    •  '+g.delimiter[0]+'
    • ').appendTo(h).find(".tag-editor-tag").html('').addClass("active").find("input").val(f(c)).attr("data-tag",c).blur(),d?a(".placeholder",h).remove():h.click()}else"removeTag"==b?(a(".tag-editor-tag",h).filter(function(){return a(this).attr("data-tag")==c}).closest("li").find(".tag-editor-delete").click(),d||h.click()):"destroy"==b&&e.removeClass("tag-editor-hidden-src").removeData("options").off("focus.tag-editor").next(".tag-editor").remove()}),"getTags"==b?l:this}return window.getSelection&&a(document).off("keydown.tag-editor").on("keydown.tag-editor",m),k.each(function(){function k(){j.placeholder&&!a(".deleted, .placeholder, input",d).length&&d.append('
    • '+j.placeholder+"
    • ")}function l(e){var f=c.toString();c=a(".tag-editor-tag:not(.deleted)",d).map(function(b,c){var d=a.trim(a(this).hasClass("active")?a(this).find("input").val():a(c).attr("data-tag"));return d?d:void 0}).get(),d.data("tags",c),b.val(c.join(j.delimiter[0])),e||f!=c.toString()&&j.onChange(b,d,c),k()}function m(h){for(var p,i=h.closest("li"),k=h.val().replace(/ +/," ").split(j.dregex),m=h.data("old_tag"),n=c.slice(0),o=!1,q=0;q
       '+j.delimiter[0]+'
      '+f(e(r))+'
      '),j.maxTags&&n.length>=j.maxTags)){o=!0;break}h.attr("maxlength",j.maxLength).removeData("old_tag").val(""),o?h.blur():h.focus(),l()}var b=a(this),c=[],d=a("
        ').insertAfter(b);b.addClass("tag-editor-hidden-src").data("options",j).on("focus.tag-editor",function(){d.click()}),d.append('
      •  
      • ');var i='
      •  '+j.delimiter[0]+'
      • ';d.click(function(b,c){var e,g,f=99999;if(!window.getSelection||""==getSelection())return j.maxTags&&d.data("tags").length>=j.maxTags?(d.find("input").blur(),!1):(h=!0,a("input:focus",d).blur(),h?(h=!0,a(".placeholder",d).remove(),c&&c.length?g="before":a(".tag-editor-tag",d).each(function(){var d=a(this),h=d.offset(),i=h.left,j=h.top;b.pageY>=j&&b.pageY<=j+d.height()&&(b.pageXe&&(f=e,c=d))}),"before"==g?a(i).insertBefore(c.closest("li")).find(".tag-editor-tag").click():"after"==g?a(i).insertAfter(c.closest("li")).find(".tag-editor-tag").click():a(i).appendTo(d).find(".tag-editor-tag").click(),!1):!1)}),d.on("click",".tag-editor-delete",function(e){if(a(this).prev().hasClass("active"))return a(this).closest("li").find("input").caret(-1),!1;var f=a(this).closest("li"),g=f.find(".tag-editor-tag");return j.beforeTagDelete(b,d,c,g.text())===!1?!1:(g.addClass("deleted").animate({width:0},j.animateDelete,function(){f.remove(),k(),j.afterTagDelete(b,d,c,g.text())}),l(),!1)}),j.clickDelete&&d.on("mousedown",".tag-editor-tag",function(e){if(e.ctrlKey||e.which>1){var f=a(this).closest("li"),g=f.find(".tag-editor-tag");return j.beforeTagDelete(b,d,c,g.text())===!1?!1:(g.addClass("deleted").animate({width:0},j.animateDelete,function(){f.remove(),k()}),l(),!1)}}),d.on("click",".tag-editor-tag",function(b){if(j.clickDelete&&(b.ctrlKey||b.which>1))return!1;if(!a(this).hasClass("active")){var c=a(this).html(),e=a(this).attr("data-tag");e||(e="");var f=Math.abs((a(this).offset().left-b.pageX)/a(this).width()),g=parseInt(c.length*f),h=a(this).html('').addClass("active").find("input");if(h.data("old_tag",e).tagEditorInput().focus().caret(g),j.autocomplete){var i=a.extend({},j.autocomplete),k="select"in i?j.autocomplete.select:"";i.select=function(b,c){k&&k(b,c),setTimeout(function(){d.trigger("click",[a(".active",d).find("input").closest("li").next("li").find(".tag-editor-tag")])},20)},h.autocomplete(i)}}return!1}),d.on("blur","input",function(i){i.stopPropagation();var n=a(this),o=n.data("old_tag"),p=a.trim(n.val().replace(/ +/," ").replace(j.dregex,j.delimiter[0]));if(p){if(p.indexOf(j.delimiter[0])>=0)return void m(n);if(p!=o)if(j.forceLowercase&&(p=p.toLowerCase()),cb_val=j.beforeTagSave(b,d,c,o,p),p=cb_val||p,cb_val===!1){if(o)return n.val(o).focus(),h=!1,void l();try{n.closest("li").remove()}catch(i){}o&&l()}else j.removeDuplicates&&a(".tag-editor-tag:not(.active)",d).each(function(){a(this).text()==p&&a(this).closest("li").remove()})}else{if(o&&j.beforeTagDelete(b,d,c,o)===!1)return n.val(o).focus(),h=!1,void l();try{n.closest("li").remove()}catch(i){}o&&l()}n.parent().text(f(e(p))).attr("data-tag",e(p)).removeClass("active").prepend(''),p!=o&&l(),k()});var n;d.on("paste","input",function(b){a(this).removeAttr("maxlength"),n=a(this),setTimeout(function(){m(n)},30)});var o;d.on("keypress","input",function(b){j.delimiter.indexOf(String.fromCharCode(b.which))>=0&&(o=a(this),setTimeout(function(){m(o)},20))}),d.on("keydown","input",function(c){var e=a(this);if((37==c.which||!j.autocomplete&&38==c.which)&&!e.caret()||8==c.which&&!e.val()){var f=e.closest("li").prev("li").find(".tag-editor-tag");return f.length?f.click().find("input").caret(-1):!e.val()||j.maxTags&&d.data("tags").length>=j.maxTags||a(i).insertBefore(e.closest("li")).find(".tag-editor-tag").click(),!1}if((39==c.which||!j.autocomplete&&40==c.which)&&e.caret()==e.val().length){var g=e.closest("li").next("li").find(".tag-editor-tag");return g.length?g.click().find("input").caret(0):e.val()&&d.click(),!1}if(9==c.which){if(c.shiftKey){var f=e.closest("li").prev("li").find(".tag-editor-tag");if(f.length)f.click().find("input").caret(0);else{if(!e.val()||j.maxTags&&d.data("tags").length>=j.maxTags)return b.attr("disabled","disabled"),void setTimeout(function(){b.removeAttr("disabled")},30);a(i).insertBefore(e.closest("li")).find(".tag-editor-tag").click()}return!1}var g=e.closest("li").next("li").find(".tag-editor-tag");if(g.length)g.click().find("input").caret(0);else{if(!e.val())return;d.click()}return!1}if(!(46!=c.which||a.trim(e.val())&&e.caret()!=e.val().length)){var g=e.closest("li").next("li").find(".tag-editor-tag");return g.length?g.click().find("input").caret(0):e.val()&&d.click(),!1}if(13==c.which)return d.trigger("click",[e.closest("li").next("li").find(".tag-editor-tag")]),j.afterClickEnter(),!1;if(36!=c.which||e.caret()){if(35==c.which&&e.caret()==e.val().length)d.find(".tag-editor-tag").last().click();else if(27==c.which)return e.val(e.data("old_tag")?e.data("old_tag"):"").blur(),!1}else d.find(".tag-editor-tag").first().click()});for(var p=j.initialTags.length?j.initialTags:b.val().split(j.dregex),q=0;q=j.maxTags);q++){var r=a.trim(p[q].replace(/ +/," "));r&&(j.forceLowercase&&(r=r.toLowerCase()),c.push(r),d.append('
      •  '+j.delimiter[0]+'
        '+f(e(r))+'
      • '))}l(!0),j.sortable&&a.fn.sortable&&d.sortable({distance:5,cancel:".tag-editor-spacer, input",helper:"clone",update:function(){l()}})})},a.fn.tagEditor.defaults={initialTags:[],maxTags:0,maxLength:50,delimiter:",;",placeholder:"",forceLowercase:!0,removeDuplicates:!0,clickDelete:!1,animateDelete:175,sortable:!0,autocomplete:null,onChange:function(){},beforeTagSave:function(){},beforeTagDelete:function(){},afterTagDelete:function(){},afterClickEnter:function(){}}}(jQuery); \ No newline at end of file