-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.printPreview.js
118 lines (100 loc) · 3.23 KB
/
jquery.printPreview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
(function( $ ) {
$.fn.printPreview = function() {
close_button = $("<div>").attr("id","print_preview_clouse_btn");
print_button = $("<div>").attr("id","print_preview_print_btn");
this.click(function(e){
e.preventDefault();
$("body").prepend(close_button);
$("body").prepend(print_button);
container = $("<div>").attr("id", "print_preview_container").load($(this).attr("href"));
background = $("<div>").attr("id", "print_preview_background");
border = $("<div>").attr("id", "print_preview_border");
border.append(container);
$("body").prepend(border.fadeTo('slow', 1, function(){
close_button.fadeTo(100, 0.8, function(){
print_button.fadeTo(100, 0.8);
});
}));
$("body").prepend(background.fadeTo('slow', 0.5, function(){
border.show('slow');
}));
});
print_button.click(function(e){
$("#print_preview_container").attr("style", "margin:0px;")
$("#edit_symbol").hide();
print_frame = $("#print_preview_container");
if (print_frame.size() > 1){
print_frame.eq( 0 ).print();
return;
} else if (!print_frame.size()){
return;
}
var strFrameName = ("printer-" + (new Date()).getTime());
var jFrame = $( "<iframe name='" + strFrameName + "'>" );
jFrame
.css( "width", "1px" )
.css( "height", "1px" )
.css( "position", "absolute" )
.css( "left", "-9999px" )
.appendTo( $( "body:first" ) )
;
var objFrame = window.frames[ strFrameName ];
var objDoc = objFrame.document;
var jStyleDiv = $( "<div>" ).append(
$( "style" ).clone()
);
objDoc.open();
objDoc.write( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">" );
objDoc.write( "<html>" );
objDoc.write( "<body>" );
objDoc.write( "<head>" );
objDoc.write( "<title>" );
objDoc.write( document.title );
objDoc.write( "</title>" );
objDoc.write( jStyleDiv.html() );
objDoc.write( "</head>" );
objDoc.write( print_frame.html() );
objDoc.write( "</body>" );
objDoc.write( "</html>" );
objDoc.close();
objFrame.focus();
objFrame.print();
setTimeout( function(){
jFrame.remove();
}, (60 * 1000));
$("#edit_symbol").show();
});
close_button.click(function(e) {
background.fadeTo('slow', 0, function(){
background.remove();
});
$("body").prepend(background.fadeTo('slow', 0.5));
border.fadeTo('slow', 0, function(){
border.remove();
print_button.fadeTo(100, 0, function(){
close_button.fadeTo(100, 0, function(){
// empty
});
});
});
});
};
$.fn.editSingleLine = function(e) {
edit_symbol = $("<img>").attr("id", "edit_symbol");
this.append(edit_symbol);
clicked = false;
this.click(function(){
if(!clicked) {
$("#edit_symbol").remove();
$(this).html("<input id='print_input' type='text' value='"+$(this).text()+"' />");
$("#print_input").focus();
clicked = true;
}
});
this.focusout(function(e){
$(this).text($("#print_input").val());
$(this).append(edit_symbol);
clicked = false;
});
};
})( jQuery );