source: extensions/gally/gally-default/js/simpleTip.min.js @ 10736

Last change on this file since 10736 was 10736, checked in by grum, 13 years ago

bug:2291 ; compatibility with piwigo 2.2

  • Property svn:executable set to *
File size: 5.7 KB
Line 
1/* file: simpleTip.js - v1.0.1 | minified on 2011/05/01 with http://jscompress.com/ */
2function tipItem(item,index,options)
3{this.item=item;this.content=item.title;this.index=index;this.options=jQuery.extend({targetPos:'bottom-middle',tipPos:'top-middle',drawArrow:false,offsetX:0,offsetY:0,classes:'',arrowImgDir:'',arrowWidth:12,arrowHeight:12},options);}
4function simpleTip()
5{var items=new Array(),itemIndexInc=0,options={name:''};if(arguments.length>=1)
6{options.name=arguments[0];}
7this.doAction=function(fct)
8{switch(fct)
9{case'add':if(arguments.length==2)
10{add(arguments[1],{});}
11else
12{add(arguments[1],arguments[2]);}
13break;case'remove':if(arguments.length==2)
14{remove(arguments[1]);}
15break;case'clear':clear();break;case'hide':hide();break;case'show':show();break;case'prepare':if(arguments.length==4)
16{prepare(arguments[1],arguments[2],arguments[3]);}
17break;}};var add=function(item,options)
18{index=getIndex(item);if(index==-1&item.title!='')
19{tip=new tipItem(item,itemIndexInc,options);$(item).attr({title:'',simpleTip:tip.index}).bind('mouseover',{index:tip.index},function(event)
20{prepare($(this).offset().left,$(this).offset().top,$(this).innerWidth(),$(this).innerHeight(),event.data.index);show();}).bind('mouseout',function(event)
21{hide();});items.push(tip);itemIndexInc++;}};var remove=function(item)
22{index=getIndex(item);if(index!=-1)
23{$(item).attr({title:items[index].content,simpleTip:''}).unbind('mouseover').unbind('mouseout');items[index].item=null;items.splice(index,1);}};var clear=function()
24{hide();while(items.length>0)
25{if(items[0].item!=null)
26{$(items[0].item).attr({title:items[0].content,simpleTip:''}).unbind('mouseover').unbind('mouseout');items[0].item=null;}
27items.shift();}
28itemIndexInc=0;};var getIndex=function(item)
29{searched=$(item).attr('simpleTip');for(i=0;i<items.length;i++)
30{if(items[i].index==searched)return(i);}
31return(-1);};var prepare=function(posX,posY,width,height,index)
32{itemIndex=index;arrowX=0;arrowY=0;$('#iSimpleTipContent'+options.name).html(items[itemIndex].content);$('#iSimpleTip'+options.name).css({left:'-1500px',top:'-1500px',display:'block'});switch(items[itemIndex].options.targetPos)
33{case'top-left':x=posX;y=posY;break;case'top-middle':x=posX+width/2;y=posY;break;case'top-right':x=posX+width;y=posY;break;case'middle-left':x=posX;y=posY+height/2;break;case'middle-middle':x=posX+width/2;y=posY+height/2;break;case'middle-right':x=posX+width;y=posY+height/2;break;case'bottom-left':x=posX;y=posY+height;break;case'bottom-middle':x=posX+width/2;y=posY+height;break;case'bottom-right':x=posX+width;y=posY+height;break;}
34stWidth=$('#iSimpleTipContent'+options.name).outerWidth();stHeight=$('#iSimpleTipContent'+options.name).outerHeight();stWidthI=$('#iSimpleTipContent'+options.name).innerWidth();stHeightI=$('#iSimpleTipContent'+options.name).innerHeight();bwX=(stWidth-stWidthI)/2;bwY=(stHeight-stHeightI)/2;arrowModel='';switch(items[itemIndex].options.tipPos)
35{case'top-left':x+=items[itemIndex].options.offsetX;y+=items[itemIndex].options.offsetY;arrowX=-bwX;arrowY=-items[itemIndex].options.arrowHeight+bwY;arrowModel='up';break;case'top-middle':x-=stWidth/2;y+=items[itemIndex].options.offsetY;arrowX=(stWidthI-items[itemIndex].options.arrowWidth)/2;arrowY=-items[itemIndex].options.arrowHeight+bwY;arrowModel='up';break;case'top-right':x-=stWidth+items[itemIndex].options.offsetX;y+=items[itemIndex].options.offsetY;arrowX=stWidthI-items[itemIndex].options.arrowWidth+bwX;arrowY=-items[itemIndex].options.arrowHeight+bwY;arrowModel='up';break;case'middle-left':x+=items[itemIndex].options.offsetX;y-=stHeight/2;arrowX=-items[itemIndex].options.arrowWidth+bwX;arrowY=(stHeightI-items[itemIndex].options.arrowHeight)/2+bwY;arrowModel='left';break;case'middle-middle':x-=stWidth/2;y-=stHeight/2;break;case'middle-right':x-=stWidth+items[itemIndex].options.offsetX;y-=stHeight/2;arrowX=stWidthI+bwX;arrowY=(stHeightI-items[itemIndex].options.arrowHeight)/2+bwY;arrowModel='right';break;case'bottom-left':x+=items[itemIndex].options.offsetX;y-=stHeight+items[itemIndex].options.offsetY;arrowX=-bwX;arrowY=stHeightI+bwY;arrowModel='down';break;case'bottom-middle':x-=stWidth/2;y-=stHeight+items[itemIndex].options.offsetY;arrowX=(stWidthI-items[itemIndex].options.arrowWidth)/2+bwX;arrowY=stHeightI+bwY;arrowModel='down';break;case'bottom-right':x-=stWidth+items[itemIndex].options.offsetX;y-=stHeight+items[itemIndex].options.offsetY;arrowX=stWidthI-items[itemIndex].options.arrowWidth+bwX;arrowY=stHeightI+bwY;arrowModel='down';break;}
36if(items[itemIndex].options.drawArrow&arrowModel!='')
37{$('#iSimpleTipArrow'+options.name).css({display:'block',background:'url("'+items[itemIndex].options.arrowImgDir+'/arrow_'+arrowModel+'.png") no-repeat scroll 0 0 transparent',marginLeft:arrowX+'px',marginTop:arrowY+'px',width:items[itemIndex].options.arrowWidth+'px',height:items[itemIndex].options.arrowHeight+'px'});}
38else
39{$('#iSimpleTipArrow'+options.name).css('display','none');}
40$('#iSimpleTip'+options.name).css({left:x+'px',top:y+'px',display:'none'}).removeClass().addClass(items[itemIndex].options.classes);};var show=function()
41{$('#iSimpleTip'+options.name).css('display','block');};var hide=function()
42{$('#iSimpleTip'+options.name).css('display','none');};var init=function()
43{if($('#iSimpleTip'+options.name).length==0)
44{text="<div id='iSimpleTip"+options.name+"' style='z-index:15000;display:none;position:absolute;left:0px;top:0px;'><div id='iSimpleTipShadow"+options.name+"' style='position:absolute;width:100%;height:100%;background:#000000;opacity:0.4;filter:alpha(opacity:40);display:block;z-index:-1;margin-left:2px;margin-top:2px;'></div><div id='iSimpleTipArrow"+options.name+"' style='position:absolute;'></div><div id='iSimpleTipContent"+options.name+"'></div></div>";$('body').append(text);}};init();}
Note: See TracBrowser for help on using the repository browser.