ÿþ/ * j s l i n t   b r o w s e r :   t r u e   * /   / * g l o b a l   j Q u e r y :   t r u e   * / 
 
 / * * 
   *   j Q u e r y   C o o k i e   p l u g i n 
   * 
   *   C o p y r i g h t   ( c )   2 0 1 0   K l a u s   H a r t l   ( s t i l b u e r o . d e ) 
   *   D u a l   l i c e n s e d   u n d e r   t h e   M I T   a n d   G P L   l i c e n s e s : 
   *   h t t p : / / w w w . o p e n s o u r c e . o r g / l i c e n s e s / m i t - l i c e n s e . p h p 
   *   h t t p : / / w w w . g n u . o r g / l i c e n s e s / g p l . h t m l 
   * 
   * / 
 
 / /   T O D O   J s D o c 
 
 / * * 
   *   C r e a t e   a   c o o k i e   w i t h   t h e   g i v e n   k e y   a n d   v a l u e   a n d   o t h e r   o p t i o n a l   p a r a m e t e r s . 
   * 
   *   @ e x a m p l e   $ . c o o k i e ( ' t h e _ c o o k i e ' ,   ' t h e _ v a l u e ' ) ; 
   *   @ d e s c   S e t   t h e   v a l u e   o f   a   c o o k i e . 
   *   @ e x a m p l e   $ . c o o k i e ( ' t h e _ c o o k i e ' ,   ' t h e _ v a l u e ' ,   {   e x p i r e s :   7 ,   p a t h :   ' / ' ,   d o m a i n :   ' j q u e r y . c o m ' ,   s e c u r e :   t r u e   } ) ; 
   *   @ d e s c   C r e a t e   a   c o o k i e   w i t h   a l l   a v a i l a b l e   o p t i o n s . 
   *   @ e x a m p l e   $ . c o o k i e ( ' t h e _ c o o k i e ' ,   ' t h e _ v a l u e ' ) ; 
   *   @ d e s c   C r e a t e   a   s e s s i o n   c o o k i e . 
   *   @ e x a m p l e   $ . c o o k i e ( ' t h e _ c o o k i e ' ,   n u l l ) ; 
   *   @ d e s c   D e l e t e   a   c o o k i e   b y   p a s s i n g   n u l l   a s   v a l u e .   K e e p   i n   m i n d   t h a t   y o u   h a v e   t o   u s e   t h e   s a m e   p a t h   a n d   d o m a i n 
   *               u s e d   w h e n   t h e   c o o k i e   w a s   s e t . 
   * 
   *   @ p a r a m   S t r i n g   k e y   T h e   k e y   o f   t h e   c o o k i e . 
   *   @ p a r a m   S t r i n g   v a l u e   T h e   v a l u e   o f   t h e   c o o k i e . 
   *   @ p a r a m   O b j e c t   o p t i o n s   A n   o b j e c t   l i t e r a l   c o n t a i n i n g   k e y / v a l u e   p a i r s   t o   p r o v i d e   o p t i o n a l   c o o k i e   a t t r i b u t e s . 
   *   @ o p t i o n   N u m b e r | D a t e   e x p i r e s   E i t h e r   a n   i n t e g e r   s p e c i f y i n g   t h e   e x p i r a t i o n   d a t e   f r o m   n o w   o n   i n   d a y s   o r   a   D a t e   o b j e c t . 
   *                                                           I f   a   n e g a t i v e   v a l u e   i s   s p e c i f i e d   ( e . g .   a   d a t e   i n   t h e   p a s t ) ,   t h e   c o o k i e   w i l l   b e   d e l e t e d . 
   *                                                           I f   s e t   t o   n u l l   o r   o m i t t e d ,   t h e   c o o k i e   w i l l   b e   a   s e s s i o n   c o o k i e   a n d   w i l l   n o t   b e   r e t a i n e d 
   *                                                           w h e n   t h e   t h e   b r o w s e r   e x i t s . 
   *   @ o p t i o n   S t r i n g   p a t h   T h e   v a l u e   o f   t h e   p a t h   a t r i b u t e   o f   t h e   c o o k i e   ( d e f a u l t :   p a t h   o f   p a g e   t h a t   c r e a t e d   t h e   c o o k i e ) . 
   *   @ o p t i o n   S t r i n g   d o m a i n   T h e   v a l u e   o f   t h e   d o m a i n   a t t r i b u t e   o f   t h e   c o o k i e   ( d e f a u l t :   d o m a i n   o f   p a g e   t h a t   c r e a t e d   t h e   c o o k i e ) . 
   *   @ o p t i o n   B o o l e a n   s e c u r e   I f   t r u e ,   t h e   s e c u r e   a t t r i b u t e   o f   t h e   c o o k i e   w i l l   b e   s e t   a n d   t h e   c o o k i e   t r a n s m i s s i o n   w i l l 
   *                                                 r e q u i r e   a   s e c u r e   p r o t o c o l   ( l i k e   H T T P S ) . 
   *   @ t y p e   u n d e f i n e d 
   * 
   *   @ n a m e   $ . c o o k i e 
   *   @ c a t   P l u g i n s / C o o k i e 
   *   @ a u t h o r   K l a u s   H a r t l / k l a u s . h a r t l @ s t i l b u e r o . d e 
   * / 
 
 / * * 
   *   G e t   t h e   v a l u e   o f   a   c o o k i e   w i t h   t h e   g i v e n   k e y . 
   * 
   *   @ e x a m p l e   $ . c o o k i e ( ' t h e _ c o o k i e ' ) ; 
   *   @ d e s c   G e t   t h e   v a l u e   o f   a   c o o k i e . 
   * 
   *   @ p a r a m   S t r i n g   k e y   T h e   k e y   o f   t h e   c o o k i e . 
   *   @ r e t u r n   T h e   v a l u e   o f   t h e   c o o k i e . 
   *   @ t y p e   S t r i n g 
   * 
   *   @ n a m e   $ . c o o k i e 
   *   @ c a t   P l u g i n s / C o o k i e 
   *   @ a u t h o r   K l a u s   H a r t l / k l a u s . h a r t l @ s t i l b u e r o . d e 
   * / 
 j Q u e r y . c o o k i e   =   f u n c t i o n   ( k e y ,   v a l u e ,   o p t i o n s )   { 
 
         / /   k e y   a n d   v a l u e   g i v e n ,   s e t   c o o k i e . . . 
         i f   ( a r g u m e n t s . l e n g t h   >   1   & &   ( v a l u e   = = =   n u l l   | |   t y p e o f   v a l u e   ! = =   " o b j e c t " ) )   { 
                 o p t i o n s   =   j Q u e r y . e x t e n d ( { } ,   o p t i o n s ) ; 
 
                 i f   ( v a l u e   = = =   n u l l )   { 
                         o p t i o n s . e x p i r e s   =   - 1 ; 
                 } 
 
                 i f   ( t y p e o f   o p t i o n s . e x p i r e s   = = =   ' n u m b e r ' )   { 
                         v a r   d a y s   =   o p t i o n s . e x p i r e s ,   t   =   o p t i o n s . e x p i r e s   =   n e w   D a t e ( ) ; 
                         t . s e t D a t e ( t . g e t D a t e ( )   +   d a y s ) ; 
                 } 
 
                 r e t u r n   ( d o c u m e n t . c o o k i e   =   [ 
                         e n c o d e U R I C o m p o n e n t ( k e y ) ,   ' = ' , 
                         o p t i o n s . r a w   ?   S t r i n g ( v a l u e )   :   e n c o d e U R I C o m p o n e n t ( S t r i n g ( v a l u e ) ) , 
                         o p t i o n s . e x p i r e s   ?   ' ;   e x p i r e s = '   +   o p t i o n s . e x p i r e s . t o U T C S t r i n g ( )   :   ' ' ,   / /   u s e   e x p i r e s   a t t r i b u t e ,   m a x - a g e   i s   n o t   s u p p o r t e d   b y   I E 
                         o p t i o n s . p a t h   ?   ' ;   p a t h = '   +   o p t i o n s . p a t h   :   ' ' , 
                         o p t i o n s . d o m a i n   ?   ' ;   d o m a i n = '   +   o p t i o n s . d o m a i n   :   ' ' , 
                         o p t i o n s . s e c u r e   ?   ' ;   s e c u r e '   :   ' ' 
                 ] . j o i n ( ' ' ) ) ; 
         } 
 
         / /   k e y   a n d   p o s s i b l y   o p t i o n s   g i v e n ,   g e t   c o o k i e . . . 
         o p t i o n s   =   v a l u e   | |   { } ; 
         v a r   r e s u l t ,   d e c o d e   =   o p t i o n s . r a w   ?   f u n c t i o n   ( s )   {   r e t u r n   s ;   }   :   d e c o d e U R I C o m p o n e n t ; 
         r e t u r n   ( r e s u l t   =   n e w   R e g E x p ( ' ( ? : ^ | ;   ) '   +   e n c o d e U R I C o m p o n e n t ( k e y )   +   ' = ( [ ^ ; ] * ) ' ) . e x e c ( d o c u m e n t . c o o k i e ) )   ?   d e c o d e ( r e s u l t [ 1 ] )   :   n u l l ; 
 } ; 
 
