/** * jQuery printPage Plugin * @version: 1.0 * @author: Cedric Dugas, http://www.position-absolute.com * @licence: MIT * @desciption: jQuery page print plugin help you print your page in a better way Kiegészítve: myMessageOpen és myMessageClose opciókkal saját üzenetmegjelenítő definiálható, ehhez a sprintf.js is szükséges, mert a myMessageOpen -ben %s helyére kerül a megjelenítendő üzenet. */ (function( $ ){ $.fn.printPage = function(options) { // EXTEND options for this button var pluginOptions = { attr : "href", url : false, showMessage: true, myMessageOpen : "createOverlay('Nyomtatás', '%s', false, false, 6);", myMessageClose : "closeOverlay($j('.overlayContent'));", message: "Türelmét kérem, a nyomtatás előkészületben..." , callback: null, katt: false ,off: false }; $.extend(pluginOptions, options); this.on("click", function(){ loadPrintDocument(this, pluginOptions); if(pluginOptions.off===true) $(this).off('click'); return false; }); /** * Load & show message box, call iframe * @param {jQuery} el - The button calling the plugin * @param {Object} pluginOptions - options for this print button */ function loadPrintDocument(el, pluginOptions){ if(pluginOptions.showMessage){ if(pluginOptions.myMessageOpen!="") { eval(sprintf(pluginOptions.myMessageOpen,pluginOptions.message)); addIframeToPage(el, pluginOptions); } else { $("body").append(components.messageBox(pluginOptions.message)); $("#printMessageBox").css("opacity", 0); $("#printMessageBox").animate({opacity:1}, 300, function() { addIframeToPage(el, pluginOptions); }); } } else { addIframeToPage(el, pluginOptions); } } /** * Inject iframe into document and attempt to hide, it, can't use display:none * You can't print if the element is not dsplayed * @param {jQuery} el - The button calling the plugin * @param {Object} pluginOptions - options for this print button */ function addIframeToPage(el, pluginOptions){ var url = (pluginOptions.url) ? pluginOptions.url : $(el).attr(pluginOptions.attr); if(!$('#printPage')[0]){ $("body").append(components.iframe(url)); $('#printPage').on("load",function() { printit(pluginOptions); }); }else{ $('#printPage').attr("src", url); } } /* * Call the print browser functionnality, focus is needed for IE */ function printit(){ frames.printPage.focus(); frames.printPage.print(); if(pluginOptions.showMessage){ if(pluginOptions.myMessageClose) {eval(pluginOptions.myMessageClose);} else {unloadMessage();} } if($.isFunction(pluginOptions.callback)) { $.call(this,pluginOptions.callback); } } /* * Hide & Delete the message box with a small delay */ function unloadMessage(){ $("#printMessageBox").delay(1000).animate({opacity:0}, 700, function(){ $(this).remove(); }); } /* * Build html compononents for thois plugin */ var components = { iframe: function(url){ return ''; }, messageBox: function(message){ return "
\ "+message+"
"; } }; if(pluginOptions.katt!==false){ this.trigger('click'); } }; })( jQuery );