Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update minified JS

  • Loading branch information...
commit f09cfd65cea55ca11a760abde5c4f86122f7466f 1 parent e5b0210
@aehlke authored
Showing with 16 additions and 1 deletion.
  1. +16 −1 js/tag-it.min.js
View
17 js/tag-it.min.js
@@ -1 +1,16 @@
-(function($){$.widget("ui.tagit",{options:{allowDuplicates:false,caseSensitive:true,fieldName:"tags",placeholderText:null,readOnly:false,removeConfirmation:false,tagLimit:null,availableTags:[],autocomplete:{},showAutocompleteOnFocus:false,allowSpaces:false,singleField:false,singleFieldDelimiter:",",singleFieldNode:null,animate:true,tabIndex:null,beforeTagAdded:null,afterTagAdded:null,beforeTagRemoved:null,afterTagRemoved:null,onTagClicked:null,onTagLimitExceeded:null,onTagAdded:null,onTagRemoved:null,tagSource:null},_create:function(){var that=this;if(this.element.is("input")){this.tagList=$("<ul></ul>").insertAfter(this.element);this.options.singleField=true;this.options.singleFieldNode=this.element;this.element.css("display","none")}else{this.tagList=this.element.find("ul, ol").andSelf().last()}this.tagInput=$('<input type="text" />').addClass("ui-widget-content");if(this.options.readOnly)this.tagInput.attr("disabled","disabled");if(this.options.tabIndex){this.tagInput.attr("tabindex",this.options.tabIndex)}if(this.options.placeholderText){this.tagInput.attr("placeholder",this.options.placeholderText)}if(!this.options.autocomplete.source){this.options.autocomplete.source=function(search,showChoices){var filter=search.term.toLowerCase();var choices=$.grep(this.options.availableTags,function(element){return element.toLowerCase().indexOf(filter)===0});showChoices(this._subtractArray(choices,this.assignedTags()))}}if(this.options.showAutocompleteOnFocus){this.tagInput.focus(function(event,ui){that._showAutocomplete()});if(typeof this.options.autocomplete.minLength==="undefined"){this.options.autocomplete.minLength=0}}if($.isFunction(this.options.autocomplete.source)){this.options.autocomplete.source=$.proxy(this.options.autocomplete.source,this)}if($.isFunction(this.options.tagSource)){this.options.tagSource=$.proxy(this.options.tagSource,this)}this.tagList.addClass("tagit").addClass("ui-widget ui-widget-content ui-corner-all").append($('<li class="tagit-new"></li>').append(this.tagInput)).click(function(e){var target=$(e.target);if(target.hasClass("tagit-label")){var tag=target.closest(".tagit-choice");if(!tag.hasClass("removed")){that._trigger("onTagClicked",e,{tag:tag,tagLabel:that.tagLabel(tag)})}}else{that.tagInput.focus()}});var addedExistingFromSingleFieldNode=false;if(this.options.singleField){if(this.options.singleFieldNode){var node=$(this.options.singleFieldNode);var tags=node.val().split(this.options.singleFieldDelimiter);node.val("");$.each(tags,function(index,tag){that.createTag(tag,null,true);addedExistingFromSingleFieldNode=true})}else{this.options.singleFieldNode=$('<input type="hidden" style="display:none;" value="" name="'+this.options.fieldName+'" />');this.tagList.after(this.options.singleFieldNode)}}if(!addedExistingFromSingleFieldNode){this.tagList.children("li").each(function(){if(!$(this).hasClass("tagit-new")){that.createTag($(this).text(),$(this).attr("class"),true);$(this).remove()}})}this.tagInput.keydown(function(event){if(event.which==$.ui.keyCode.BACKSPACE&&that.tagInput.val()===""){var tag=that._lastTag();if(!that.options.removeConfirmation||tag.hasClass("remove")){that.removeTag(tag)}else if(that.options.removeConfirmation){tag.addClass("remove ui-state-highlight")}}else if(that.options.removeConfirmation){that._lastTag().removeClass("remove ui-state-highlight")}if(event.which===$.ui.keyCode.COMMA||event.which===$.ui.keyCode.ENTER||event.which==$.ui.keyCode.TAB&&that.tagInput.val()!==""||event.which==$.ui.keyCode.SPACE&&that.options.allowSpaces!==true&&($.trim(that.tagInput.val()).replace(/^s*/,"").charAt(0)!='"'||$.trim(that.tagInput.val()).charAt(0)=='"'&&$.trim(that.tagInput.val()).charAt($.trim(that.tagInput.val()).length-1)=='"'&&$.trim(that.tagInput.val()).length-1!==0)){if(!(event.which===$.ui.keyCode.ENTER&&that.tagInput.val()==="")){event.preventDefault()}that.createTag(that._cleanedInput());that.tagInput.autocomplete("close")}}).blur(function(e){if(!that.tagInput.data("autocomplete-open")){that.createTag(that._cleanedInput())}});if(this.options.availableTags||this.options.tagSource||this.options.autocomplete.source){var autocompleteOptions={select:function(event,ui){that.createTag(ui.item.value);return false}};$.extend(autocompleteOptions,this.options.autocomplete);autocompleteOptions.source=this.options.tagSource||autocompleteOptions.source;this.tagInput.autocomplete(autocompleteOptions).bind("autocompleteopen",function(event,ui){that.tagInput.data("autocomplete-open",true)}).bind("autocompleteclose",function(event,ui){that.tagInput.data("autocomplete-open",false)})}},_cleanedInput:function(){return $.trim(this.tagInput.val().replace(/^"(.*)"$/,"$1"))},_lastTag:function(){return this.tagList.find(".tagit-choice:last:not(.removed)")},_tags:function(){return this.tagList.find(".tagit-choice:not(.removed)")},assignedTags:function(){var that=this;var tags=[];if(this.options.singleField){tags=$(this.options.singleFieldNode).val().split(this.options.singleFieldDelimiter);if(tags[0]===""){tags=[]}}else{this._tags().each(function(){tags.push(that.tagLabel(this))})}return tags},_updateSingleTagsField:function(tags){$(this.options.singleFieldNode).val(tags.join(this.options.singleFieldDelimiter)).trigger("change")},_subtractArray:function(a1,a2){var result=[];for(var i=0;i<a1.length;i++){if($.inArray(a1[i],a2)==-1){result.push(a1[i])}}return result},tagLabel:function(tag){if(this.options.singleField){return $(tag).find(".tagit-label:first").text()}else{return $(tag).find("input:first").val()}},_showAutocomplete:function(){this.tagInput.autocomplete("search","")},_findTagByLabel:function(name){var that=this;var tag=null;this._tags().each(function(i){if(that._formatStr(name)==that._formatStr(that.tagLabel(this))){tag=$(this);return false}});return tag},_isNew:function(name){return!this._findTagByLabel(name)},_formatStr:function(str){if(this.options.caseSensitive){return str}return $.trim(str.toLowerCase())},_effectExists:function(name){return Boolean($.effects&&($.effects[name]||$.effects.effect&&$.effects.effect[name]))},createTag:function(value,additionalClass,duringInitialization){var that=this;value=$.trim(value);if(this.options.preprocessTag){value=this.options.preprocessTag(value)}if(value===""){return false}if(!this.options.allowDuplicates&&!this._isNew(value)){var existingTag=this._findTagByLabel(value);if(this._trigger("onTagExists",null,{existingTag:existingTag,duringInitialization:duringInitialization})!==false){if(this._effectExists("highlight")){existingTag.effect("highlight")}}return false}if(this.options.tagLimit&&this._tags().length>=this.options.tagLimit){this._trigger("onTagLimitExceeded",null,{duringInitialization:duringInitialization});return false}var label=$(this.options.onTagClicked?'<a class="tagit-label"></a>':'<span class="tagit-label"></span>').text(value);var tag=$("<li></li>").addClass("tagit-choice ui-widget-content ui-state-default ui-corner-all").addClass(additionalClass).append(label);if(this.options.readOnly){tag.addClass("tagit-choice-read-only")}else{tag.addClass("tagit-choice-editable");var removeTagIcon=$("<span></span>").addClass("ui-icon ui-icon-close");var removeTag=$('<a><span class="text-icon">×</span></a>').addClass("tagit-close").append(removeTagIcon).click(function(e){that.removeTag(tag)});tag.append(removeTag)}if(!this.options.singleField){var escapedValue=label.html();tag.append('<input type="hidden" style="display:none;" value="'+escapedValue+'" name="'+this.options.fieldName+'" />')}if(this._trigger("beforeTagAdded",null,{tag:tag,tagLabel:this.tagLabel(tag),duringInitialization:duringInitialization})===false){return}if(this.options.singleField){var tags=this.assignedTags();tags.push(value);this._updateSingleTagsField(tags)}this._trigger("onTagAdded",null,tag);this.tagInput.val("");this.tagInput.parent().before(tag);this._trigger("afterTagAdded",null,{tag:tag,tagLabel:this.tagLabel(tag),duringInitialization:duringInitialization});if(this.options.showAutocompleteOnFocus&&!duringInitialization){setTimeout(function(){that._showAutocomplete()},0)}},removeTag:function(tag,animate){animate=typeof animate==="undefined"?this.options.animate:animate;tag=$(tag);this._trigger("onTagRemoved",null,tag);if(this._trigger("beforeTagRemoved",null,{tag:tag,tagLabel:this.tagLabel(tag)})===false){return}if(this.options.singleField){var tags=this.assignedTags();var removedTagLabel=this.tagLabel(tag);tags=$.grep(tags,function(el){return el!=removedTagLabel});this._updateSingleTagsField(tags)}if(animate){tag.addClass("removed");var hide_args=this._effectExists("blind")?["blind",{direction:"horizontal"},"fast"]:["fast"];hide_args.push(function(){tag.remove()});tag.fadeOut("fast").hide.apply(tag,hide_args).dequeue()}else{tag.remove()}this._trigger("afterTagRemoved",null,{tag:tag,tagLabel:this.tagLabel(tag)})},removeTagByLabel:function(tagLabel,animate){var toRemove=this._findTagByLabel(tagLabel);if(!toRemove){throw"No such tag exists with the name '"+tagLabel+"'"}this.removeTag(toRemove,animate)},removeAll:function(){var that=this;this._tags().each(function(index,tag){that.removeTag(tag,false)})}})})(jQuery);
+(function(b){b.widget("ui.tagit",{options:{allowDuplicates:!1,caseSensitive:!0,fieldName:"tags",placeholderText:null,readOnly:!1,removeConfirmation:!1,tagLimit:null,availableTags:[],autocomplete:{},showAutocompleteOnFocus:!1,allowSpaces:!1,singleField:!1,singleFieldDelimiter:",",singleFieldNode:null,animate:!0,tabIndex:null,beforeTagAdded:null,afterTagAdded:null,beforeTagRemoved:null,afterTagRemoved:null,onTagClicked:null,onTagLimitExceeded:null,onTagAdded:null,onTagRemoved:null,tagSource:null},_create:function(){var a=
+this;this.element.is("input")?(this.tagList=b("<ul></ul>").insertAfter(this.element),this.options.singleField=!0,this.options.singleFieldNode=this.element,this.element.css("display","none")):this.tagList=this.element.find("ul, ol").andSelf().last();this.tagInput=b('<input type="text" />').addClass("ui-widget-content");this.options.readOnly&&this.tagInput.attr("disabled","disabled");this.options.tabIndex&&this.tagInput.attr("tabindex",this.options.tabIndex);this.options.placeholderText&&this.tagInput.attr("placeholder",
+this.options.placeholderText);this.options.autocomplete.source||(this.options.autocomplete.source=function(a,c){var d=a.term.toLowerCase(),e=b.grep(this.options.availableTags,function(a){return 0===a.toLowerCase().indexOf(d)});c(this._subtractArray(e,this.assignedTags()))});this.options.showAutocompleteOnFocus&&(this.tagInput.focus(function(){a._showAutocomplete()}),"undefined"===typeof this.options.autocomplete.minLength&&(this.options.autocomplete.minLength=0));b.isFunction(this.options.autocomplete.source)&&
+(this.options.autocomplete.source=b.proxy(this.options.autocomplete.source,this));b.isFunction(this.options.tagSource)&&(this.options.tagSource=b.proxy(this.options.tagSource,this));this.tagList.addClass("tagit").addClass("ui-widget ui-widget-content ui-corner-all").append(b('<li class="tagit-new"></li>').append(this.tagInput)).click(function(c){var d=b(c.target);d.hasClass("tagit-label")?(d=d.closest(".tagit-choice"),d.hasClass("removed")||a._trigger("onTagClicked",c,{tag:d,tagLabel:a.tagLabel(d)})):
+a.tagInput.focus()});var d=!1;if(this.options.singleField)if(this.options.singleFieldNode){var c=b(this.options.singleFieldNode),e=c.val().split(this.options.singleFieldDelimiter);c.val("");b.each(e,function(b,c){a.createTag(c,null,!0);d=!0})}else this.options.singleFieldNode=b('<input type="hidden" style="display:none;" value="" name="'+this.options.fieldName+'" />'),this.tagList.after(this.options.singleFieldNode);d||this.tagList.children("li").each(function(){b(this).hasClass("tagit-new")||(a.createTag(b(this).text(),
+b(this).attr("class"),!0),b(this).remove())});this.tagInput.keydown(function(c){if(c.which==b.ui.keyCode.BACKSPACE&&""===a.tagInput.val()){var d=a._lastTag();!a.options.removeConfirmation||d.hasClass("remove")?a.removeTag(d):a.options.removeConfirmation&&d.addClass("remove ui-state-highlight")}else a.options.removeConfirmation&&a._lastTag().removeClass("remove ui-state-highlight");if(c.which===b.ui.keyCode.COMMA||c.which===b.ui.keyCode.ENTER||c.which==b.ui.keyCode.TAB&&""!==a.tagInput.val()||c.which==
+b.ui.keyCode.SPACE&&!0!==a.options.allowSpaces&&('"'!=b.trim(a.tagInput.val()).replace(/^s*/,"").charAt(0)||'"'==b.trim(a.tagInput.val()).charAt(0)&&'"'==b.trim(a.tagInput.val()).charAt(b.trim(a.tagInput.val()).length-1)&&0!==b.trim(a.tagInput.val()).length-1))c.which===b.ui.keyCode.ENTER&&""===a.tagInput.val()||c.preventDefault(),a.createTag(a._cleanedInput()),a.tagInput.autocomplete("close")}).blur(function(){a.tagInput.data("autocomplete-open")||a.createTag(a._cleanedInput())});if(this.options.availableTags||
+this.options.tagSource||this.options.autocomplete.source)c={select:function(b,c){a.createTag(c.item.value);return!1}},b.extend(c,this.options.autocomplete),c.source=this.options.tagSource||c.source,this.tagInput.autocomplete(c).bind("autocompleteopen",function(){a.tagInput.data("autocomplete-open",!0)}).bind("autocompleteclose",function(){a.tagInput.data("autocomplete-open",!1)})},_cleanedInput:function(){return b.trim(this.tagInput.val().replace(/^"(.*)"$/,"$1"))},_lastTag:function(){return this.tagList.find(".tagit-choice:last:not(.removed)")},
+_tags:function(){return this.tagList.find(".tagit-choice:not(.removed)")},assignedTags:function(){var a=this,d=[];this.options.singleField?(d=b(this.options.singleFieldNode).val().split(this.options.singleFieldDelimiter),""===d[0]&&(d=[])):this._tags().each(function(){d.push(a.tagLabel(this))});return d},_updateSingleTagsField:function(a){b(this.options.singleFieldNode).val(a.join(this.options.singleFieldDelimiter)).trigger("change")},_subtractArray:function(a,d){for(var c=[],e=0;e<a.length;e++)-1==
+b.inArray(a[e],d)&&c.push(a[e]);return c},tagLabel:function(a){return this.options.singleField?b(a).find(".tagit-label:first").text():b(a).find("input:first").val()},_showAutocomplete:function(){this.tagInput.autocomplete("search","")},_findTagByLabel:function(a){var d=this,c=null;this._tags().each(function(){if(d._formatStr(a)==d._formatStr(d.tagLabel(this)))return c=b(this),!1});return c},_isNew:function(a){return!this._findTagByLabel(a)},_formatStr:function(a){return this.options.caseSensitive?
+a:b.trim(a.toLowerCase())},_effectExists:function(a){return Boolean(b.effects&&(b.effects[a]||b.effects.effect&&b.effects.effect[a]))},createTag:function(a,d,c){var e=this;a=b.trim(a);this.options.preprocessTag&&(a=this.options.preprocessTag(a));if(""===a)return!1;if(!this.options.allowDuplicates&&!this._isNew(a))return a=this._findTagByLabel(a),!1!==this._trigger("onTagExists",null,{existingTag:a,duringInitialization:c})&&this._effectExists("highlight")&&a.effect("highlight"),!1;if(this.options.tagLimit&&
+this._tags().length>=this.options.tagLimit)return this._trigger("onTagLimitExceeded",null,{duringInitialization:c}),!1;var g=b(this.options.onTagClicked?'<a class="tagit-label"></a>':'<span class="tagit-label"></span>').text(a),f=b("<li></li>").addClass("tagit-choice ui-widget-content ui-state-default ui-corner-all").addClass(d).append(g);this.options.readOnly?f.addClass("tagit-choice-read-only"):(f.addClass("tagit-choice-editable"),d=b("<span></span>").addClass("ui-icon ui-icon-close"),d=b('<a><span class="text-icon">\u00d7</span></a>').addClass("tagit-close").append(d).click(function(){e.removeTag(f)}),
+f.append(d));this.options.singleField||(g=g.html(),f.append('<input type="hidden" style="display:none;" value="'+g+'" name="'+this.options.fieldName+'" />'));!1!==this._trigger("beforeTagAdded",null,{tag:f,tagLabel:this.tagLabel(f),duringInitialization:c})&&(this.options.singleField&&(g=this.assignedTags(),g.push(a),this._updateSingleTagsField(g)),this._trigger("onTagAdded",null,f),this.tagInput.val(""),this.tagInput.parent().before(f),this._trigger("afterTagAdded",null,{tag:f,tagLabel:this.tagLabel(f),
+duringInitialization:c}),this.options.showAutocompleteOnFocus&&!c&&setTimeout(function(){e._showAutocomplete()},0))},removeTag:function(a,d){d="undefined"===typeof d?this.options.animate:d;a=b(a);this._trigger("onTagRemoved",null,a);if(!1!==this._trigger("beforeTagRemoved",null,{tag:a,tagLabel:this.tagLabel(a)})){if(this.options.singleField){var c=this.assignedTags(),e=this.tagLabel(a),c=b.grep(c,function(a){return a!=e});this._updateSingleTagsField(c)}if(d){a.addClass("removed");var c=this._effectExists("blind")?
+["blind",{direction:"horizontal"},"fast"]:["fast"],g=this;c.push(function(){a.remove();g._trigger("afterTagRemoved",null,{tag:a,tagLabel:g.tagLabel(a)})});a.fadeOut("fast").hide.apply(a,c).dequeue()}else a.remove(),this._trigger("afterTagRemoved",null,{tag:a,tagLabel:this.tagLabel(a)})}},removeTagByLabel:function(a,b){var c=this._findTagByLabel(a);if(!c)throw"No such tag exists with the name '"+a+"'";this.removeTag(c,b)},removeAll:function(){var a=this;this._tags().each(function(b,c){a.removeTag(c,
+!1)})}})})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.