Changeset 664 for ether_statistics/web


Ignore:
Timestamp:
11/05/12 18:40:09 (12 years ago)
Author:
vmipsl
Message:

print ok pour mozilla & chrome

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ether_statistics/web/resources/js/classesForJQuery/PrintContent.js

    r663 r664  
    1 //******************************************************** 
     1//**************************************************************************************************************** 
    22// Class PrintContent 
    3 // Print  a Content 
     3// Print a Content (some divs) 
    44// 
    55// use jQuery 
    6 //******************************************************** 
     6// This class allow to print some divs contened in this.divContent 
     7// We must clone the divs we want to print for the preview --> new PrintContent().addContent( divToPrint.clone() ); 
     8// There's no jQuery function to print only a few div, then we have to use the old javascript function window.print() !! 
     9// To hide the window behind the previewDiv, we use a mask with opacity (otherwise, chrome display the entire window's content). 
     10//**************************************************************************************************************** 
    711 
    812var PrintContent = Class.create( { 
     
    1216    initialize: function() 
    1317    { 
    14         this.divWrapper = $( '<div id="printWrapper"></div>' ); 
     18        this.divPreview = $( '<div id="printWrapper"></div>' ); 
    1519        this.divButtons = $( '<div id="printButtons"></div>' ); 
    1620        this.divContent = $( '<div id="printContent"></div>' ); 
    1721    }, 
    1822 
     23    setContent: function( content ) 
     24    { 
     25        this.divContent.append( content ); 
     26    }, 
     27 
     28    addContent: function( content ) 
     29    { 
     30        this.divContent.append( content ); 
     31    }, 
     32 
     33    createButtons: function() 
     34    { 
     35        this.oldContent = window.document.body.innerHTML; 
     36        this.printButton = $( document.createElement( "div" ) ); 
     37        this.printButton.addClass( "print" ); 
     38        this.printButton.bind( "click", jQuery.proxy( function() 
     39        { 
     40            this.mask.animate( { opacity: 1}, 400, jQuery.proxy( function() 
     41            { 
     42                window.print(); 
     43            }, this ) ); 
     44        }, this ) ); 
     45        this.divButtons.append( this.printButton ); 
     46 
     47        this.closeButton = $( document.createElement( "div" ) ); 
     48        this.closeButton.addClass( "close" ); 
     49        this.closeButton.bind( "click", jQuery.proxy( function() 
     50        { 
     51            this.removePrintPreview(); 
     52        }, this ) ); 
     53        this.divButtons.append( this.closeButton ); 
     54    }, 
     55 
    1956    displayPrintPreview: function() 
    2057    { 
    21         this.divWrapper.hide(); 
    22         this.divWrapper.append( this.divButtons ); 
    23         this.divWrapper.append( this.divContent ); 
    24         $( 'body' ).append( this.divWrapper ); 
     58        this.divPreview.hide(); 
     59        this.divPreview.append( this.divButtons ); 
     60        this.divPreview.append( this.divContent ); 
     61        $( 'body' ).append( this.divPreview ); 
    2562 
    2663        // Display mask 
     
    3774        } 
    3875 
    39         this.divWrapper.css( css ).animate( { top: $( window ).scrollTop()}, 400, 'linear', jQuery.proxy( function() 
     76        this.divPreview.css( css ).animate( { top: $( window ).scrollTop()}, 400, 'linear', jQuery.proxy( function() 
    4077        { 
    4178            this.divButtons.fadeIn( 'slow' ).focus(); 
     
    4582    }, 
    4683 
    47     createButtons: function() 
    48     { 
    49         this.oldContent = window.document.body.innerHTML; 
    50         this.printButton = $( document.createElement( "div" ) ); 
    51         this.printButton.addClass( "print" ); 
    52         this.printButton.bind( "click", jQuery.proxy( function() 
    53         { 
    54             this.mask.animate( { opacity: 1}, 400, jQuery.proxy( function() 
    55             { 
    56                 window.print(); 
    57             }, this ) ); 
    58 //            window.print(); 
    59         }, this ) ); 
    60         this.divButtons.append( this.printButton ); 
    61  
    62         this.closeButton = $( document.createElement( "div" ) ); 
    63         this.closeButton.addClass( "close" ); 
    64         this.closeButton.bind( "click", jQuery.proxy( function() 
    65         { 
    66             this.distroyPrintPreview(); 
    67         }, this ) ); 
    68         this.divButtons.append( this.closeButton ); 
    69     }, 
    70  
    71     distroyPrintPreview: function() 
     84    removePrintPreview: function() 
    7285    { 
    7386        this.divButtons.fadeOut( 100 ); 
    74         this.divWrapper.animate( { top: $( window ).scrollTop() - $( window ).height(), opacity: 1}, 400, 'linear', jQuery.proxy( function() 
     87        this.divPreview.animate( { top: $( window ).scrollTop() - $( window ).height(), opacity: 1}, 400, 'linear', jQuery.proxy( function() 
    7588        { 
    76             this.divWrapper.remove(); 
     89            this.divPreview.remove(); 
    7790            $( 'body' ).css( {overflowY: 'auto', height: 'auto'} ); 
    7891        }, this ) ); 
     
    112125        this.mask.bind( "click.printPreview.mask", jQuery.proxy( function( e ) 
    113126        { 
    114             this.distroyPrintPreview(); 
     127            this.removePrintPreview(); 
    115128        }, this ) ); 
    116129 
     
    118131        { 
    119132            if( e.keyCode == 27 ) 
    120                 this.distroyPrintPreview(); 
     133                this.removePrintPreview(); 
    121134        }, this ) ); 
    122135    }, 
     
    143156        this.size = this.getMaskSize(); 
    144157        this.mask.css( {width: this.size[0], height: this.size[1]} ); 
    145     }, 
    146  
    147     setContent: function( content ) 
    148     { 
    149         this.divContent.append( content ); 
    150     }, 
    151  
    152     addContent: function( content ) 
    153     { 
    154         this.divContent.append( content ); 
    155158    } 
    156159 
Note: See TracChangeset for help on using the changeset viewer.