/* * printThis v1.3 * @desc Printing plug-in for jQuery * @author Jason Day * * Resources (based on) : * jPrintArea: http://plugins.jquery.com/project/jPrintArea * jqPrint: https://github.com/permanenttourist/jquery.jqprint * Ben Nadal: http://www.bennadel.com/blog/1591-Ask-Ben-Print-Part-Of-A-Web-Page-With-jQuery.htm * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * (c) Jason Day 2013 * * Usage: * * $("#mySelector").printThis({ * debug: false, * show the iframe for debugging * importCSS: true, * import page CSS * printContainer: true, * grab outer container as well as the contents of the selector * loadCSS: "path/to/my.css", * path to additional css file * pageTitle: "", * add title to print page * removeInline: false, * remove all inline styles from print elements * printDelay: 333, * variable print delay S. Vance * header: null * prefix to html * }); * * Notes: * - the loadCSS will load additional css (with or without @media print) into the iframe, adjusting layout */ /* jshint onevar: false, smarttabs: true, devel: true */ ;(function ($) { var opt; $.fn.printThis = function (options) { opt = $.extend({}, $.fn.printThis.defaults, options); var $element = this instanceof jQuery ? this : $(this); var strFrameName = 'printThis-' + (new Date()).getTime(); if(window.location.hostname !== document.domain && navigator.userAgent.match(/msie/i)){ // Ugly IE hacks due to IE not inheriting document.domain from parent // checks if document.domain is set by comparing the host name against document.domain var iframeContents = '
'; var iframeSrc = 'data:text/html;charset=utf-8,' + encodeURI(iframeContents); var printI= document.createElement('iframe'); printI.name = 'printIframe'; printI.id = strFrameName; printI.className = 'MSIE'; document.body.appendChild(printI); printI.src = iframeSrc; } else { // other browsers inherit document.domain, and IE works if document.domain is not explicitly set var $frame = $(''); $frame.appendTo('body'); } var $iframe = $('#' + strFrameName); // show frame if in debug mode if (!opt.debug) { $iframe.css({ position: 'absolute', width: '0px', height: '0px', left: '-600px', top: '-600px' }); } // $iframe.ready() and $iframe.load were inconsistent between browsers setTimeout ( function () { var $doc = $iframe.contents(); // import page stylesheets if (opt.importCSS) { $('link[rel=stylesheet]').each(function () { var href = $(this).attr('href'); if (href) { var media = $(this).attr('media') || 'all'; $doc.find('head').append(''); } }); } //add title of the page if (opt.pageTitle) { $doc.find('head').append('