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