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