forked from djpate/jTag
/
jquery.tag.min.js
11 lines (11 loc) · 4.74 KB
/
jquery.tag.min.js
1
2
3
4
5
6
7
8
9
10
11
var g=null;
(function(a){a.extend(a.J,{P:function(b){b=a.extend({minWidth:100,minHeight:100,o:100,m:100,maxHeight:g,maxWidth:g,save:g,remove:g,v:!0,k:!0,u:!1,j:g,n:g,l:!0,draggable:!0,r:!0,d:"hover",h:!0,H:!1},b);return this.z(function(){var c=a(this);c.data("options",b);a(window).load(function(){c.F('<div class="jTagContainer" />');c.F('<div class="jTagArea" />');a("<div class='jTagLabels'><div style='clear:both'></div></div>").K(c.parent());a('<div class="jTagOverlay"></div>').insertBefore(c);container=c.parent().parent();
overlay=c.g();c.parent().a("backgroundImage","url("+c.b("src")+")");c.parent().width(c.width());c.parent().height(c.height());c.parent().parent().width(c.width());c.c();b.u&&c.s();container.e(".jTagTag","mouseenter",function(){a(".jTagDrag",container).length==0&&(a(this).a("opacity",1),a(".jTagDeleteTag",this).show(),a(this).find("span").show(),c.p())});container.e(".jTagTag","mouseleave",function(){a(".jTagDrag",container).length==0&&(b.d=="hover"&&(a(this).a("opacity",0),a(".jTagDeleteTag",this).c(),
a(this).find("span").c()),c.f())});b.h&&b.d!="always"&&(container.e(".jTagLabels label","mouseenter",function(){a("#"+a(this).b("rel"),container).a("opacity",1).find("span").show();a(".jTagDeleteTag",container).show()}),container.e(".jTagLabels label","mouseleave",function(){a("#"+a(this).b("rel"),container).a("opacity",0).find("span").c();a(".jTagDeleteTag",container).c()}));b.k&&container.e(".jTagDeleteTag","click",function(){b.remove&&b.remove(a(this).parent().parent().A());b.h&&a(".jTagLabels",
container).find('label[rel="'+a(this).parent().parent().b("id")+'"]').remove();a(this).parent().parent().remove();c.f()});b.n&&a.z(b.n,function(a,b){c.i(b.width,b.height,b.top,b.left,b.label,b.id)});c.f()})})},q:function(){var b=a(this),c=b.data("options");b.g().N("jTagPngOverlay");b.parent().parent().find(".jTagDrag").remove();c.d=="always"&&b.parent().parent().find(".jTagTag").show();b.f()},s:function(b){function c(b){b=a(".jTagDrag",b);border=parseInt(b.a("borderTopWidth"));left_pos=parseInt(b.b("offsetLeft"))+
border;top_pos=parseInt(b.b("offsetTop"))+border;return"-"+left_pos+"px -"+top_pos+"px"}var e=a(this),h=e.parent().parent(),f=e.g();e.p();var d=e.data("options");a(".jTagDrag",f).length!=1&&d.v&&(d.d=="always"&&a(".jTagTag",f).c(),a('<div style="width:'+d.o+"px;height:"+d.m+'px"class="jTagDrag"><div class="jTagSave"><div class="jTagInput"><input type="text" id="jTagLabel"></div><div class="jTagSaveClose"></div><div class="jTagSaveBtn"></div><div style="clear:both"></div></div>').t(f),f.G("jTagPngOverlay"),
jtagdrag=a(".jTagDrag",f),jtagdrag.a("backgroundImage","url("+e.b("src")+")"),b?(pos=function(a){var b=curtop=0;if(a.offsetParent){do b+=a.offsetLeft,curtop+=a.offsetTop;while(a=a.offsetParent);return[b,curtop]}}(e.parent()[0]),x=Math.max(0,b.pageX-pos[0]-d.o/2),y=Math.max(0,b.pageY-pos[1]-d.m/2),x+jtagdrag.width()>e.parent().width()&&(x=e.parent().width()-jtagdrag.width()-2),y+jtagdrag.height()>e.parent().height()&&(y=e.parent().height()-jtagdrag.height()-2)):y=x=0,jtagdrag.a("top",y).a("left",x),
d.j&&a("#jTagLabel",h).autocomplete({source:d.j}),a(".jTagSaveBtn",h).click(function(){label=a("#jTagLabel",h).Q();label==""?alert("The label cannot be empty"):(height=a(this).parent().parent().height(),width=a(this).parent().parent().width(),top_pos=a(this).parent().parent().b("offsetTop"),left=a(this).parent().parent().b("offsetLeft"),tagobj=e.i(width,height,top_pos,left,label),d.save&&d.save(width,height,top_pos,left,label,tagobj))}),a(".jTagSaveClose",h).click(function(){e.q()}),d.r&&jtagdrag.r({w:e.parent(),
minWidth:d.minWidth,minHeight:d.minHeight,L:d.maxWidth,maxHeight:d.maxHeight,O:function(){jtagdrag.a({backgroundPosition:c(f)})},stop:function(){jtagdrag.a({backgroundPosition:c(f)})}}),d.draggable&&jtagdrag.draggable({w:e.parent(),I:function(){jtagdrag.a({backgroundPosition:c(f)})},stop:function(){jtagdrag.a({backgroundPosition:c(f)})}}),jtagdrag.a({backgroundPosition:c(f)}))},i:function(b,c,e,h,f,d){var i=a(this),j=i.data("options"),k=a(".jTagTag").length+1;tag=a('<div class="jTagTag" id="tag'+
k+'"style="width:'+b+"px;height:"+c+"px;top:"+e+"px;left:"+h+'px;"><div style="width:100%;height:100%"><div class="jTagDeleteTag"></div><span>'+f+"</span></div></div>").t(i.g());d&&tag.C(d);j.k&&i.parent().find(".jTagDeleteTag").show();j.d=="always"&&a(".jTagTag").a("opacity",1);j.h&&a("<label rel='tag"+k+"'>"+f+"</label>").insertBefore(a(".jTagLabels div:last"));i.q();return tag},C:function(b){a(this).B("jTagTag")?a(this).data("tagid",b):alert("Wrong object")},A:function(){if(a(this).B("jTagTag"))return a(this).data("tagid");
else alert("Wrong object")},f:function(){var b=a(this);b.data("options").l&&b.parent().M(function(a){b.s(a);b.parent().D("mousedown")})},p:function(){var b=a(this);b.data("options").l&&b.parent().D("mousedown")}})})(jQuery);