ÿþ/ *   I m a g e   w /   d e s c r i p t i o n   t o o l t i p   v 2 . 0  
 *   C r e a t e d :   A p r i l   2 3 r d ,   2 0 1 0 .   T h i s   n o t i c e   m u s t   s t a y   i n t a c t   f o r   u s a g e    
 *   A u t h o r :   D y n a m i c   D r i v e   a t   h t t p : / / w w w . d y n a m i c d r i v e . c o m /  
 *   V i s i t   h t t p : / / w w w . d y n a m i c d r i v e . c o m /   f o r   f u l l   s o u r c e   c o d e  
 * /  
  
  
 v a r   d d i m g t o o l t i p = {  
  
 	 t i p a r r a y : f u n c t i o n ( ) {  
 	 	 v a r   t o o l t i p s = [ ]  
 	 	 / / d e f i n e   e a c h   t o o l t i p   b e l o w :   t o o l t i p [ i n c ] = [ ' p a t h _ t o _ i m a g e ' ,   ' o p t i o n a l   d e s c ' ,   o p t i o n a l _ C S S _ o b j e c t ]  
 	 	 / / F o r   d e s c   p a r a m e t e r ,   b a c k s l a s h   a n y   s p e c i a l   c h a r a c t e r s   i n s i d e   y o u r   t e x t   s u c h   a s   a p o t r o p h e s   ( ' ) .   E x a m p l e :   " I \ ' m   t h e   k i n g   o f   t h e   w o r l d "  
 	 	 / / F o r   C S S   o b j e c t ,   f o l l o w   t h e   s y n t a x :   { p r o p e r t y 1 : " c s s v a l u e 1 " ,   p r o p e r t y 2 : " c s s v a l u e 2 " ,   e t c }  
  
 	 	 t o o l t i p s [ 0 ] = [ " h t t p : / / k y n g u y e n s o . v n / U p l o a d / I m a g e s / C a c b u o c c h u a n b i . g i f " ]  
 	 	 t o o l t i p s [ 1 ] = [ " h t t p : / / k y n g u y e n s o . v n / U p l o a d / I m a g e s / T h u o n g h i e u . g i f " ]  
 	 	 t o o l t i p s [ 2 ] = [ " h t t p : / / k y n g u y e n s o . v n / U p l o a d / I m a g e s / W e b . g i f " ]  
 	 	  
  
 	 	 r e t u r n   t o o l t i p s   / / d o   n o t   r e m o v e / c h a n g e   t h i s   l i n e  
 	 } ( ) ,  
  
 	 t o o l t i p o f f s e t s :   [ 2 0 ,   - 3 0 ] ,   / / a d d i t i o n a l   x   a n d   y   o f f s e t   f r o m   m o u s e   c u r s o r   f o r   t o o l t i p s  
  
 	 / / * * * * *   N O   N E E D   T O   E D I T   B E Y O N D   H E R E  
  
 	 t i p p r e f i x :   ' i m g t i p ' ,   / / t o o l t i p   I D   p r e f i x e s  
  
 	 c r e a t e t i p : f u n c t i o n ( $ ,   t i p i d ,   t i p i n f o ) {  
 	 	 i f   ( $ ( ' # ' + t i p i d ) . l e n g t h = = 0 ) {   / / i f   t h i s   t o o l t i p   d o e s n ' t   e x i s t   y e t  
 	 	 	 r e t u r n   $ ( ' < d i v   i d = " '   +   t i p i d   +   ' "   c l a s s = " d d i m g t o o l t i p "   / > ' ) . h t m l (  
 	 	 	 	 ' < d i v   s t y l e = " t e x t - a l i g n : c e n t e r " > < i m g   s r c = " '   +   t i p i n f o [ 0 ]   +   ' "   / > < / d i v > '  
 	 	 	 	 +   ( ( t i p i n f o [ 1 ] ) ?   ' < d i v   s t y l e = " t e x t - a l i g n : l e f t ;   m a r g i n - t o p : 5 p x " > ' + t i p i n f o [ 1 ] + ' < / d i v > '   :   ' ' )  
 	 	 	 	 )  
 	 	 	 . c s s ( t i p i n f o [ 2 ]   | |   { } )  
 	 	 	 . a p p e n d T o ( d o c u m e n t . b o d y )  
 	 	 }  
 	 	 r e t u r n   n u l l  
 	 } ,  
  
 	 p o s i t i o n t o o l t i p : f u n c t i o n ( $ ,   $ t o o l t i p ,   e ) {  
 	 	 v a r   x = e . p a g e X + t h i s . t o o l t i p o f f s e t s [ 0 ] ,   y = e . p a g e Y + t h i s . t o o l t i p o f f s e t s [ 1 ]  
 	 	 v a r   t i p w = $ t o o l t i p . o u t e r W i d t h ( ) ,   t i p h = $ t o o l t i p . o u t e r H e i g h t ( ) ,    
 	 	 x = ( x + t i p w > $ ( d o c u m e n t ) . s c r o l l L e f t ( ) + $ ( w i n d o w ) . w i d t h ( ) ) ?   x - t i p w - ( d d i m g t o o l t i p . t o o l t i p o f f s e t s [ 0 ] * 2 )   :   x  
 	 	 y = ( y + t i p h > $ ( d o c u m e n t ) . s c r o l l T o p ( ) + $ ( w i n d o w ) . h e i g h t ( ) ) ?   $ ( d o c u m e n t ) . s c r o l l T o p ( ) + $ ( w i n d o w ) . h e i g h t ( ) - t i p h - 1 0   :   y  
 	 	 $ t o o l t i p . c s s ( { l e f t : x ,   t o p : y } )  
 	 } ,  
 	  
 	 s h o w b o x : f u n c t i o n ( $ ,   $ t o o l t i p ,   e ) {  
 	 	 $ t o o l t i p . s h o w ( )  
 	 	 t h i s . p o s i t i o n t o o l t i p ( $ ,   $ t o o l t i p ,   e )  
 	 } ,  
  
 	 h i d e b o x : f u n c t i o n ( $ ,   $ t o o l t i p ) {  
 	 	 $ t o o l t i p . h i d e ( )  
 	 } ,  
  
  
 	 i n i t : f u n c t i o n ( t a r g e t s e l e c t o r ) {  
 	 	 j Q u e r y ( d o c u m e n t ) . r e a d y ( f u n c t i o n ( $ ) {  
 	 	 	 v a r   t i p a r r a y = d d i m g t o o l t i p . t i p a r r a y  
 	 	 	 v a r   $ t a r g e t s = $ ( t a r g e t s e l e c t o r )  
 	 	 	 i f   ( $ t a r g e t s . l e n g t h = = 0 )  
 	 	 	 	 r e t u r n  
 	 	 	 v a r   t i p i d s = [ ]  
 	 	 	 $ t a r g e t s . e a c h ( f u n c t i o n ( ) {  
 	 	 	 	 v a r   $ t a r g e t = $ ( t h i s )  
 	 	 	 	 $ t a r g e t . a t t r ( ' r e l ' ) . m a t c h ( / \ [ ( \ d + ) \ ] / )   / / m a t c h   d   o f   a t t r i b u t e   r e l = " i m g t i p [ d ] "  
 	 	 	 	 v a r   t i p s u f f i x = p a r s e I n t ( R e g E x p . $ 1 )   / / g e t   d   a s   i n t e g e r  
 	 	 	 	 v a r   t i p i d = t h i s . _ t i p i d = d d i m g t o o l t i p . t i p p r e f i x + t i p s u f f i x   / / c o n s t r u c t   t h i s   t i p ' s   I D   v a l u e   a n d   r e m e m b e r   i t  
 	 	 	 	 v a r   $ t o o l t i p = d d i m g t o o l t i p . c r e a t e t i p ( $ ,   t i p i d ,   t i p a r r a y [ t i p s u f f i x ] )  
 	 	 	 	 $ t a r g e t . m o u s e e n t e r ( f u n c t i o n ( e ) {  
 	 	 	 	 	 v a r   $ t o o l t i p = $ ( " # " + t h i s . _ t i p i d )  
 	 	 	 	 	 d d i m g t o o l t i p . s h o w b o x ( $ ,   $ t o o l t i p ,   e )  
 	 	 	 	 } )  
 	 	 	 	 $ t a r g e t . m o u s e l e a v e ( f u n c t i o n ( e ) {  
 	 	 	 	 	 v a r   $ t o o l t i p = $ ( " # " + t h i s . _ t i p i d )  
 	 	 	 	 	 d d i m g t o o l t i p . h i d e b o x ( $ ,   $ t o o l t i p )  
 	 	 	 	 } )  
 	 	 	 	 $ t a r g e t . m o u s e m o v e ( f u n c t i o n ( e ) {  
 	 	 	 	 	 v a r   $ t o o l t i p = $ ( " # " + t h i s . _ t i p i d )  
 	 	 	 	 	 d d i m g t o o l t i p . p o s i t i o n t o o l t i p ( $ ,   $ t o o l t i p ,   e )  
 	 	 	 	 } )  
 	 	 	 	 i f   ( $ t o o l t i p ) {   / / a d d   m o u s e e n t e r   t o   t h i s   t o o l t i p   ( o n l y   i f   e v e n t   h a s n ' t   a l r e a d y   b e e n   a d d e d )  
 	 	 	 	 	 $ t o o l t i p . m o u s e e n t e r ( f u n c t i o n ( ) {  
 	 	 	 	 	 	 d d i m g t o o l t i p . h i d e b o x ( $ ,   $ ( t h i s ) )  
 	 	 	 	 	 } )  
 	 	 	 	 }  
 	 	 	 } )  
  
 	 	 } )   / / e n d   d o m   r e a d y  
 	 }  
 }  
  
 / / d d i m g t o o l t i p . i n i t ( " t a r g e t E l e m e n t S e l e c t o r " )  
 d d i m g t o o l t i p . i n i t ( " * [ r e l ^ = i m g t i p ] " ) 
