| 259 | |
| 260 | // attach event handler function to beforePrint event |
| 261 | function attachOnBeforePrintEvent($iframe, beforePrintHandler) { |
| 262 | var win = $iframe.get(0); |
| 263 | win = win.contentWindow || win.contentDocument || win; |
| 264 | |
| 265 | if (typeof beforePrintHandler === "function") { |
| 266 | if ('matchMedia' in win) { |
| 267 | win.matchMedia('print').addListener(function(mql) { |
| 268 | if(mql.matches) beforePrintHandler(); |
| 269 | }); |
| 270 | } else { |
| 271 | win.onbeforeprint = beforePrintHandler; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | attachOnBeforePrintEvent($iframe, opt.beforePrint); |
| 276 | |
| 277 | setTimeout(function() { |