OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / print / scripts / jquery.PrintArea.js
1
2 (function($) {
3     var printAreaCount = 0;
4
5     $.fn.printArea = function()
6         {
7             var ele = $(this);
8
9             var idPrefix = "printArea_";
10
11             removePrintArea( idPrefix + printAreaCount );
12
13             printAreaCount++;
14
15             var iframeId = idPrefix + printAreaCount;
16             var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
17
18             iframe = document.createElement('IFRAME');
19
20             $(iframe).attr({ style : iframeStyle,
21                              id    : iframeId
22                            });
23
24             document.body.appendChild(iframe);
25
26             var doc = iframe.contentWindow.document;
27
28             $(document).find("link")
29                 .filter(function(){
30                         return $(this).attr("rel").toLowerCase() == "stylesheet";
31                     })
32                 .each(function(){
33                         doc.write('<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >');
34                     });
35
36             doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
37             doc.close();
38
39             var frameWindow = iframe.contentWindow;
40             frameWindow.close();
41             frameWindow.focus();
42             frameWindow.print();
43         }
44
45     var removePrintArea = function(id)
46         {
47             $( "iframe#" + id ).remove();
48         };
49
50 })(jQuery);
51