PrintArea.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="jquery-1.10.2.js" type="text/JavaScript" language="javascript"></script>
  5. <script src="jquery-ui-1.10.4.custom.js"></script>
  6. <script src="jquery.PrintArea.js" type="text/JavaScript" language="javascript"></script>
  7. <link type="text/css" rel="stylesheet" href="css/ui-lightness/jquery-ui-1.10.4.custom.css" />
  8. <link type="text/css" rel="stylesheet" href="PrintArea.css" /> <!-- Y : rel is stylesheet and media is in [all,print,empty,undefined] -->
  9. <link type="text/css" rel="stylesheet" href="media_all.css" media="all" /> <!-- Y : rel is stylesheet and media is in [all,print,empty,undefined] -->
  10. <link type="text/css" rel="" href="empty.css" /> <!-- N : rel is not stylesheet -->
  11. <link type="text/css" rel="noPrint" href="noPrint.css" /> <!-- N : rel is not stylesheet -->
  12. <link type="text/css" rel="stylesheet" href="media_none.css" media="xyz" /> <!-- N : media not in [all,print,empty,undefined] -->
  13. <link type="text/css" href="no_rel.css" media="print" /> <!-- N : no rel attribute -->
  14. <link type="text/css" href="no_rel_no_media.css" /> <!-- N : no rel, no media attributes -->
  15. </head>
  16. <body>
  17. <div style="border: solid 2px #999fff; float: left; padding: 5px; margin-bottom: 5px;">
  18. <div style="text-align: center;">
  19. <span style="font-weight: bold;">Contains content that I want to print</span>
  20. <br>
  21. This is just a sample page to demonstrate this plugin.
  22. </div>
  23. <div class="PrintArea area1 all" id="Retain">
  24. <div>Print Area 1</div>
  25. <span style="color: #000777;">print me</span>
  26. <span class="test">xyz</span>
  27. <br>
  28. <input name="chkTest1" value="1" type="checkbox">
  29. <input name="chkTest2" value="2" type="checkbox">
  30. <br>
  31. <input value="3" name="rdoTest3" type="radio">
  32. <input value="4" name="rdoTest3" type="radio">
  33. <br>
  34. <input value="" name="textTest5" type="text">
  35. <br>
  36. <select name="selTest6">
  37. <option value="A">A</option>
  38. <option value="B">B</option>
  39. <option value="C">C</option>
  40. </select>
  41. <select name="selTest7" multiple="">
  42. <option value="a">a</option>
  43. <option value="b">b</option>
  44. <option value="c">c</option>
  45. </select>
  46. <br>
  47. <textarea name="textareaTest8"></textarea>
  48. <br>
  49. <img src="FoesEnd.jpg" id="img2" alt="test" width="200">
  50. </div>
  51. <div style="border: solid 1px #999; margin: 20px 5px; padding: 20px;">
  52. I don't want this to print.
  53. </div>
  54. <div class="PrintArea area2 all" style="border-color: #999;">
  55. <div>Print Area 2</div>
  56. <span style="color: #000777;">print me</span>
  57. <span class="test">xyz</span>
  58. <br>
  59. <input name="chkTest3" value="1" type="checkbox">
  60. <input name="chkTest4" value="2" type="checkbox">
  61. <br>
  62. <input value="3" name="rdoTest4" type="radio">
  63. <input value="4" name="rdoTest4" type="radio">
  64. <br>
  65. <input value="" name="textTest6" type="text">
  66. <br>
  67. <select name="selTest7">
  68. <option value="A">A</option>
  69. <option value="B">B</option>
  70. <option value="C">C</option>
  71. </select>
  72. <select name="selTest8" multiple="">
  73. <option value="a">a</option>
  74. <option value="b">b</option>
  75. <option value="c">c</option>
  76. </select>
  77. <br>
  78. <textarea name="textareaTest9"></textarea>
  79. <br>
  80. <img src="FoesEnd.jpg" id="img2" alt="test" width="200">
  81. </div>
  82. </div>
  83. <div class="testDialog">
  84. <div class="PrintArea area3 all">
  85. This is Print Area 3
  86. </div>
  87. </div>
  88. <div style="border: solid 2px #999fff; float: left; margin-left: 20px;" class="SettingsBox">
  89. <div style="width: 400px; padding: 20px;">
  90. <div style="padding: 0 10px 10px;" class="buttonBar">
  91. <div class="button b1">Print</div>
  92. <div class="toggleDialog">open dialog</div>
  93. </div>
  94. <div style="font-weight: bold; border-top: solid 1px #999fff; padding-top: 10px;">Settings</div>
  95. <table>
  96. <tbody>
  97. <tr>
  98. <td><input value="popup" name="mode" id="popup" checked="" type="radio"> Popup</td>
  99. </tr>
  100. <tr>
  101. <td style="padding-left: 20px;"><input value="popup" name="popup" id="closePop" type="checkbox"> Close popup</td>
  102. </tr>
  103. <tr>
  104. <td><input value="iframe" name="mode" id="iFrame" type="radio"> IFrame</td>
  105. </tr>
  106. <tr>
  107. <td>Extra css: <input type="text" name="extraCss" size="50" /></td>
  108. </tr>
  109. <tr>
  110. <td><div class="settingName">Print area:</div>
  111. <div class="settingVals">
  112. <input type="checkbox" class="selPA" value="area1" checked /> Area 1<br>
  113. <input type="checkbox" class="selPA" value="area2" checked /> Area 2<br>
  114. <input type="checkbox" class="selPA" value="area3" checked /> Area 3<br>
  115. </div>
  116. </td>
  117. </tr>
  118. <tr>
  119. <td><div class="settingName">Retain Attributes:</div>
  120. <div class="settingVals">
  121. <input type="checkbox" checked name="retainCss" id="retainCss" class="chkAttr" value="class" /> Class
  122. <br>
  123. <input type="checkbox" checked name="retainId" id="retainId" class="chkAttr" value="id" /> ID
  124. <br>
  125. <input type="checkbox" checked name="retainStyle" id="retainId" class="chkAttr" value="style" /> Style
  126. </div>
  127. </td>
  128. </tr>
  129. <tr>
  130. <td><div style="padding: 3px; border: solid 1px #ddd;">Add to head :
  131. <input type="checkbox" checked name="addElements" id="addElements" class="chkAttr" />
  132. <pre>&lt;meta charset="utf-8" /&gt;<br>&lt;http-equiv="X-UA-Compatible" content="IE=edge"/&gt;</pre>
  133. </div>
  134. </td>
  135. </tr>
  136. </tbody></table>
  137. </div>
  138. </div>
  139. <script>
  140. $(document).ready(function(){
  141. var dialog = $("div.testDialog").dialog({position : { my : "left top", at : "left bottom+50", of : ".SettingsBox" }, width: "600", title: "Print Dialog Box Contents"});
  142. $(".toggleDialog").click(function(){
  143. dialog.dialog("open");
  144. });
  145. $("div.b1").click(function(){
  146. var mode = $("input[name='mode']:checked").val();
  147. var close = mode == "popup" && $("input#closePop").is(":checked");
  148. var extraCss = $("input[name='extraCss']").val();
  149. var print = "";
  150. $("input.selPA:checked").each(function(){
  151. print += (print.length > 0 ? "," : "") + "div.PrintArea." + $(this).val();
  152. });
  153. var keepAttr = [];
  154. $(".chkAttr").each(function(){
  155. if ($(this).is(":checked") == false )
  156. return;
  157. keepAttr.push( $(this).val() );
  158. });
  159. var headElements = $("input#addElements").is(":checked") ? '<meta charset="utf-8" />,<meta http-equiv="X-UA-Compatible" content="IE=edge"/>' : '';
  160. var options = { mode : mode, popClose : close, extraCss : extraCss, retainAttr : keepAttr, extraHead : headElements };
  161. $( print ).printArea( options );
  162. });
  163. $("input[name='mode']").click(function(){
  164. if ( $(this).val() == "iframe" ) $("#closePop").attr( "checked", false );
  165. });
  166. });
  167. </script>
  168. </body>
  169. </html>