source: ether_statistics/web/resources/js/classesForJQuery/PrintContent.js @ 662

Last change on this file since 662 was 662, checked in by vmipsl, 12 years ago

print ok pour mozilla

File size: 8.0 KB
Line 
1//********************************************************
2// Class PrintContent
3// Print  a Content
4//
5// use jQuery
6//********************************************************
7
8var PrintContent = Class.create( {
9
10    // Public functions ********************************************************
11
12    initialize: function()
13    {
14        this.divWrapper = $( '<div id="printWrapper"></div>' );
15        this.divButtons = $( '<div id="printButtons"></div>' );
16        this.divContent = $( '<div id="printContent"></div>' );
17
18//        this.print_frame = $( '<iframe id="print-modal-content" scrolling="no" border="0" frameborder="0" name="print-frame" />' );
19        this.divContent.append( $( "#title" ).clone() );
20        this.divContent.append( $( "#leftTop" ).clone().animate( {'marginLeft' : "+=80px"} ) );
21        this.divContent.append( $( "#leftMiddleSlide" ).clone().animate( {'marginLeft' : "+=80px"} ) );
22        this.divContent.append( $( "#leftBottomSlide" ).clone().animate( {'marginLeft' : "+=80px"} ) );
23        this.divContent.append( $( "#middle" ).clone().animate( {'marginLeft' : "+=120px"} ) );
24    },
25
26    displayPrintPreview: function()
27    {
28        this.divWrapper.hide();
29        this.divWrapper.append( this.divButtons );
30        this.divWrapper.append( this.divContent );
31//        this.divWrapper.append( this.print_frame );
32        $( 'body' ).append( this.divWrapper );
33
34        // The frame lives
35//        for( var i = 0; i < window.frames.length; i++ )
36//        {
37//            if( window.frames[i].name == "print-frame" )
38//            {
39//                this.print_frame_ref = window.frames[i].document;
40//                break;
41//            }
42//        }
43
44//        this.print_frame_ref.open();
45//        this.print_frame_ref.write( '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
46//                '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">' +
47//                '<head><title>zzzzzzzzzzz</title></head>' +
48//                '<body></body>' +
49//                '</html>' );
50//        this.print_frame_ref.close();
51
52//        if( !$.browser.msie && !($.browser.version < 7) )
53//        {
54//            $( 'head', this.print_frame_ref ).append( "headhhhhh" );
55//            $( 'body', this.print_frame_ref ).append( this.content );
56//        }
57//        else
58//        {
59//            $( 'body > *:not(#printWrapper):not(script)' ).clone().each( function()
60//            {
61//                $( 'body', this.print_frame_ref ).append( this.outerHTML );
62//            } );
63//            $( 'head link[media*=print], head link[media=all]' ).each( function()
64//            {
65//                $( 'head', this.print_frame_ref ).append( $( this ).clone().attr( 'media', 'all' )[0].outerHTML );
66//            } );
67//        }
68
69        this.loadMask();
70
71        // Disable scrolling
72//        $( 'body' ).css( {overflowY: 'hidden', height: '100%'} );
73//        $( 'img', this.print_frame_ref ).load( function()
74//        {
75//            this.print_frame.height( $( 'body', this.print_frame.contents() )[0].scrollHeight );
76//        } );
77
78        // Position modal
79        var starting_position = $( window ).height() + $( window ).scrollTop();
80        var css = {
81            top:         starting_position,
82            height:      '100%',
83            overflowY:   'auto',
84            zIndex:      10000,
85            display:     'block'
86        }
87
88        this.divWrapper.css( css ).animate( { top: $( window ).scrollTop()}, 400, 'linear', jQuery.proxy( function()
89        {
90            this.divButtons.fadeIn( 'slow' ).focus();
91        }, this ) );
92
93//        this.print_frame.height( $( 'body', this.print_frame.contents() )[0].scrollHeight );
94//        this.print_frame.height( $( 'body', this.print_frame.contents() )[0].scrollHeight );
95        this.createButtons();
96    },
97
98    createButtons: function()
99    {
100        this.oldContent = window.document.body.innerHTML;
101        this.printButton = $( document.createElement( "div" ) );
102        this.printButton.addClass( "print" );
103        this.printButton.bind( "click", jQuery.proxy( function()
104        {
105//            this.mask.animate( { opacity: 1}, 400, jQuery.proxy( function()
106//            {
107            window.print();
108//            }, this ) );
109
110//            var thePopup = window.open( '', "Customer Listing", "menubar=0,location=0,height=700,width=700" );
111//            thePopup.document.body.innerHTML = this.content;
112//            this.divWrapper.clone().appendTo( thePopup.document.body );
113//            thePopup.print();
114//            window.open()
115//            window.document.body.innerHTML = "paf";
116//            document.location.href = "";
117        }, this ) );
118        this.divButtons.append( this.printButton );
119
120        this.closeButton = $( document.createElement( "div" ) );
121        this.closeButton.addClass( "close" );
122        this.closeButton.bind( "click", jQuery.proxy( function()
123        {
124            this.distroyPrintPreview();
125        }, this ) );
126        this.divButtons.append( this.closeButton );
127    },
128
129//    printdiv: function( printpage )
130//    {
131//        var headstr = "<html><head><title></title></head><body>";
132//        var footstr = "</body>";
133//        var newstr = document.all.item( printpage ).innerHTML;
134//        var newstr = "<div>qsdqmsdkqsmdkqsd</div>";
135//        var oldstr = document.body.innerHTML;
136//        document.body.innerHTML = headstr + newstr + footstr;
137//        window.print();
138//        document.body.innerHTML = oldstr;
139//        return false;
140//    },
141
142    distroyPrintPreview: function()
143    {
144        this.divButtons.fadeOut( 100 );
145        this.divWrapper.animate( { top: $( window ).scrollTop() - $( window ).height(), opacity: 1}, 400, 'linear', jQuery.proxy( function()
146        {
147            this.divWrapper.remove();
148            $( 'body' ).css( {overflowY: 'auto', height: 'auto'} );
149        }, this ) );
150        this.mask.fadeOut( 'slow', jQuery.proxy( function()
151        {
152            this.mask.remove();
153        }, this ) );
154
155        $( document ).unbind( "keydown.printPreview.mask" );
156        this.mask.unbind( "click.printPreview.mask" );
157        $( window ).unbind( "resize.printPreview.mask" );
158    },
159
160    loadMask: function()
161    {
162        this.size = this.getMaskSize();
163        this.mask = $( '<div id="divMask" />' ).appendTo( $( 'body' ) );
164        this.mask.css( {
165            position:           'absolute',
166            top:                0,
167            left:               0,
168            width:              this.size[0],
169            height:             this.size[1],
170            display:            'none',
171            opacity:            0,
172            zIndex:             9999,
173            backgroundColor:    '#000'
174        } );
175
176        this.mask.css( {display: 'block'} ).fadeTo( '400', 0.75 );
177
178        $( window ).bind( "resize.printPreview.mask", jQuery.proxy( function()
179        {
180            this.updateMaskSize();
181        }, this ) );
182
183        this.mask.bind( "click.printPreview.mask", jQuery.proxy( function( e )
184        {
185            this.distroyPrintPreview();
186        }, this ) );
187
188        $( document ).bind( "keydown.printPreview.mask", jQuery.proxy( function( e )
189        {
190            if( e.keyCode == 27 )
191            {
192                this.distroyPrintPreview();
193            }
194        }, this ) );
195    },
196
197    getMaskSize: function()
198    {
199        if( $.browser.msie )
200        {
201            // if there are no scrollbars then use window.height
202            var d = $( document ).height(), w = $( window ).height();
203            return [
204                window.innerWidth || // ie7+
205                        document.documentElement.clientWidth || // ie6
206                        document.body.clientWidth,                     // ie6 quirks mode
207                d - w < 20 ? w : d
208            ];
209        }
210        else
211            return [$( document ).width(), $( document ).height()];
212    },
213
214    updateMaskSize: function()
215    {
216        this.size = this.getMaskSize();
217        this.mask.css( {width: this.size[0], height: this.size[1]} );
218    }
219} );
Note: See TracBrowser for help on using the repository browser.