Changeset 664 for ether_statistics/web
- Timestamp:
- 11/05/12 18:40:09 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ether_statistics/web/resources/js/classesForJQuery/PrintContent.js
r663 r664 1 //******************************************************** 1 //**************************************************************************************************************** 2 2 // Class PrintContent 3 // Print a Content3 // Print a Content (some divs) 4 4 // 5 5 // 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 //**************************************************************************************************************** 7 11 8 12 var PrintContent = Class.create( { … … 12 16 initialize: function() 13 17 { 14 this.div Wrapper= $( '<div id="printWrapper"></div>' );18 this.divPreview = $( '<div id="printWrapper"></div>' ); 15 19 this.divButtons = $( '<div id="printButtons"></div>' ); 16 20 this.divContent = $( '<div id="printContent"></div>' ); 17 21 }, 18 22 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 19 56 displayPrintPreview: function() 20 57 { 21 this.div Wrapper.hide();22 this.div Wrapper.append( this.divButtons );23 this.div Wrapper.append( this.divContent );24 $( 'body' ).append( this.div Wrapper);58 this.divPreview.hide(); 59 this.divPreview.append( this.divButtons ); 60 this.divPreview.append( this.divContent ); 61 $( 'body' ).append( this.divPreview ); 25 62 26 63 // Display mask … … 37 74 } 38 75 39 this.div Wrapper.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() 40 77 { 41 78 this.divButtons.fadeIn( 'slow' ).focus(); … … 45 82 }, 46 83 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() 72 85 { 73 86 this.divButtons.fadeOut( 100 ); 74 this.div Wrapper.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() 75 88 { 76 this.div Wrapper.remove();89 this.divPreview.remove(); 77 90 $( 'body' ).css( {overflowY: 'auto', height: 'auto'} ); 78 91 }, this ) ); … … 112 125 this.mask.bind( "click.printPreview.mask", jQuery.proxy( function( e ) 113 126 { 114 this. distroyPrintPreview();127 this.removePrintPreview(); 115 128 }, this ) ); 116 129 … … 118 131 { 119 132 if( e.keyCode == 27 ) 120 this. distroyPrintPreview();133 this.removePrintPreview(); 121 134 }, this ) ); 122 135 }, … … 143 156 this.size = this.getMaskSize(); 144 157 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 );155 158 } 156 159
Note: See TracChangeset
for help on using the changeset viewer.