-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.quicktag.min.js
22 lines (22 loc) · 2.53 KB
/
jquery.quicktag.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*************************************************
** jQuery Quicktag, Version 1.0
** Copyright Milos Sutanovac, licensed MIT
** http://twitter.com/mixn
**************************************************/
(function(a){a.fn.quickTag=function(c){c=a.extend({limitation:30,triggerKey:13,allowedTags:5,focus:false,coloring:false,colors:["yellow","orange","red"],fade:false,isForm:undefined,img:undefined,counter:undefined,tagList:a("#taglist"),notice:undefined,tagClass:"tag",closeClass:"close"},c);
var e=a(this),g=undefined,d=0,f=undefined,b=undefined;return e.each(function(){var h={init:function(){a(c.notice).hide();
if(a(c.counter)){f=a(c.counter).css("color")}if(c.counter&&c.limitation){this.keyUp();a(e).attr("maxlength",c.limitation);
a(c.counter).text(c.limitation)}if(c.img){c.img='<img src="'+c.img+'" alt="Close this tag" />'}c.isForm&&this.secureSubmit();
if(c.coloring){c.colors.reverse()}if(c.counter&&c.coloring){b=this.setColoring()}this.keyDown();this.deleteTag()
},keyDown:function(){a(e).keydown(function(i){if(i.keyCode===c.triggerKey){if(a(c.tagList).children().length<c.allowedTags){if(a(e).val()!=""){h.addTag();
a(c.counter).text(c.limitation);a(e).val("")}if(c.isForm){return false}}else{h.displayErr();return false
}}else{if(c.counter&&d>=c.limitation&&i.keyCode!==c.triggerKey&&i.keyCode!==8){return false}}})},keyUp:function(){a(e).keyup(function(m){d=a(this).val().length;
if(m.keyCode!==c.triggerKey&&c.counter){a(c.counter).text(c.limitation-d)}if(b){var n=undefined,j=b.length-1,l=c.limitation-d;
for(var k=j;k>=0;k--){if(l<=b[k]){n=c.colors[k]}}if(l>b[j]){n=f}a(c.counter).css("color",n)}})},addTag:function(){g=a(e).val();
if(a(c.tagList).is("ul")){a(c.tagList).append('<li class="'+c.tagClass+'"><a class="'+c.closeClass+'">'+(c.img||"x")+"</a> "+g+"</li>")
}else{if(a(c.tagList).is("div")){a(c.tagList).append('<div class="'+c.tagClass+'"><a class="'+c.closeClass+'">'+(c.img||"x")+"</a> "+g+"</div>")
}}},deleteTag:function(){a("."+c.closeClass).live("click",function(){a(this).parent().remove();(a(c.notice).is(":visible")&&c.fade)?a(c.notice).stop(true,true).fadeOut(c.fade):a(c.notice).hide();
c.focus&&a(e).focus();return false})},displayErr:function(){(c.fade)?a(c.notice).stop(true,true).fadeIn(c.fade):a(c.notice).show()
},secureSubmit:function(){if(a(c.isForm+":has(input=[type=submit])")){a(c.isForm).find("input[type=submit]").click(function(){return true
})}},setColoring:function(){var l=Math.round(c.limitation),j=[];for(var k=0,m=1;k<c.colors.length;k++){l=Math.round(l/2);
while(l%5!=0){l+=m}j.unshift(l)}return j}};h.init()})}})(jQuery);