var Print = { disabled: [], added: [], params: {}, init: function($trigger, params){ var self = this; self.params = params; $trigger.click(function(){ self.open(); return false; }); }, addPrintButton: function(){ var self = this; var out = '
'; out += '
'; out += this.params.print; out += ' '; out += this.params.close; out += '
'; $(out).prependTo('body'); $('.__jsPrintOk').click(function(){ window.print(); return false; }); $('.__jsPrintCancel').click(function(){ self.close(); return false; }); }, removePrintButton: function(){ $('div#printtools').remove(); $(window).trigger("resize"); }, open: function(){ var self = this; var s = $('style'); var l = $('link[rel=stylesheet]'); var a = []; $.each(s, function(i,n){a.push(n);}); $.each(l, function(i,n){a.push(n);}); $.each(a, function(i, n){ var media = $(n).attr('media'); if(media) switch(media.toLowerCase()) { case 'print': var o = n.cloneNode(false); o.media = 'screen'; self.added.push(o); n.parentNode.insertBefore(o, n); break; default: if(!n.disabled) { n.disabled = true; self.disabled.push(n); } break; } }); self.addPrintButton(); }, close: function(){ var self = this; $.each(self.disabled, function(i,n){n.disabled = false;}); $.each(self.added, function(i,n){ n.disabled = true; n.parentNode.removeChild(n); }); self.disabled = []; self.added = []; self.removePrintButton(); } };