From 976cfa23a8dc78b02dd921d32f8f06667231a647 Mon Sep 17 00:00:00 2001 From: Rikanishu Date: Wed, 15 Apr 2015 17:31:23 +0300 Subject: [PATCH 1/3] IE fix --- .gitignore | 1 + dist/jquery.printelement.js | 12 ++++++++---- dist/jquery.printelement.min.js | 6 +++--- package.json | 2 +- src/jquery.printelement.js | 8 ++++++-- 5 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/dist/jquery.printelement.js b/dist/jquery.printelement.js index d294f99..c184c96 100644 --- a/dist/jquery.printelement.js +++ b/dist/jquery.printelement.js @@ -1,6 +1,6 @@ -/*! jQuery printElement - v2.0.1 - 2014-08-22 +/*! jQuery printElement - v2.0.1 - 2015-04-15 * https://github.com/erikzaadi/jQuery.printElement -* Copyright (c) 2014 erikzaadi; Licensed MIT, GPL */ +* Copyright (c) 2015 erikzaadi; Licensed MIT, GPL */ /*global window,focus,setTimeout,navigator*/ (function (window, undefined) { var document = window.document; @@ -52,12 +52,16 @@ var popupOrIframe = null; var documentToWriteTo = null; + var currentWindowCounter = $.fn.printElement.windowCounter; + $.fn.printElement.windowCounter++; if (opts.printMode.toLowerCase() === 'popup') { - popupOrIframe = window.open('about:blank', 'printElementWindow', 'width=650,height=440,scrollbars=yes'); + // IE duplication name bug: http://stackoverflow.com/questions/7146767/i-get-access-is-denied-when-i-try-to-print-a-page-using-jquery-printelement-js + var windowName = 'printElementWindow' + currentWindowCounter; + popupOrIframe = window.open('about:blank', windowName, 'width=650,height=440,scrollbars=yes'); documentToWriteTo = popupOrIframe.document; } else { //The random ID is to overcome a safari bug http://www.cjboco.com.sharedcopy.com/post.cfm/442dc92cd1c0ca10a5c35210b8166882.html - var printElementID = "printElement_" + (Math.round(Math.random() * 99999)).toString(); + var printElementID = "printElement_" + currentWindowCounter; //Native creation of the element is faster.. var iframe = document.createElement('IFRAME'); $(iframe).attr({ diff --git a/dist/jquery.printelement.min.js b/dist/jquery.printelement.min.js index 7a29cb9..7b17b18 100644 --- a/dist/jquery.printelement.min.js +++ b/dist/jquery.printelement.min.js @@ -1,4 +1,4 @@ -/*! jQuery printElement - v2.0.1 - 2014-08-22 +/*! jQuery printElement - v2.0.1 - 2015-04-15 * https://github.com/erikzaadi/jQuery.printElement -* Copyright (c) 2014 erikzaadi; Licensed MIT, GPL */ -!function(a){function b(b,d){var e=f(b,d),i=null,j=null;if("popup"===d.printMode.toLowerCase())i=a.open("about:blank","printElementWindow","width=650,height=440,scrollbars=yes"),j=i.document;else{var k="printElement_"+Math.round(99999*Math.random()).toString(),l=g.createElement("IFRAME");h(l).attr({style:d.iframeElementOptions.styleToAdd,id:k,className:d.iframeElementOptions.classNameToAdd,frameBorder:0,scrolling:"no",src:"about:blank"}),g.body.appendChild(l),j=l.contentWindow||l.contentDocument,j.document&&(j=j.document),l=g.frames?g.frames[k]:g.getElementById(k),i=l.contentWindow||l}focus(),j.open(),j.write(e),j.close(),c(i)}function c(a){a&&a.printPage?a.printPage():setTimeout(function(){c(a)},50)}function d(a){var b=h(a);h(":checked",b).each(function(){this.setAttribute("checked","checked")}),h("input[type='text'],input[type='number']",b).each(function(){this.setAttribute("value",h(this).val())}),h("select",b).each(function(){var a=h(this);h("option",a).each(function(){a.val()===h(this).val()&&this.setAttribute("selected","selected")})}),h("textarea",b).each(function(){var a=h(this).attr("value");this.firstChild?this.firstChild.textContent=a:this.innerHTML=a});var c=h("
").append(b.clone()).html();return c}function e(){var b=a.location.port?":"+a.location.port:"";return a.location.protocol+"//"+a.location.hostname+b+a.location.pathname}function f(a,b){var c=h(a),f=d(a),i=[];if(i.push(""+b.pageTitle+""),b.overrideElementCSS){if(b.overrideElementCSS.length>0)for(var j=0;j');else{var l=k.media||"";i.push('')}}}else h("link",g).filter(function(){return"stylesheet"===h(this).attr("rel").toLowerCase()}).each(function(){var a=h(this).attr("media")||"";i.push('')});return i.push(''),i.push(''),i.push('
'+f+"
"),i.push('"),i.push(""),i.join("")}var g=a.document,h=a.jQuery;h.fn.printElement=function(a){var c=h.extend({},h.fn.printElement.defaults,a);return"iframe"===c.printMode&&/chrome/.test(navigator.userAgent.toLowerCase())&&(c.printMode="popup"),h("[id^='printElement_']").remove(),this.each(function(){var a=h.meta?h.extend({},c,h(this).data()):c;b(h(this),a)})},h.fn.printElement.defaults={printMode:"iframe",pageTitle:"",overrideElementCSS:null,printBodyOptions:{styleToAdd:"padding:10px;margin:10px;",classNameToAdd:""},leaveOpen:!1,iframeElementOptions:{styleToAdd:"border:none;position:absolute;width:0px;height:0px;bottom:0px;left:0px;",classNameToAdd:""}},h.fn.printElement.cssElement={href:"",media:""}}(window); \ No newline at end of file +* Copyright (c) 2015 erikzaadi; Licensed MIT, GPL */ +!function(a,b){function c(b,c){var e=g(b,c),f=null,j=null,k=i.fn.printElement.windowCounter;if(i.fn.printElement.windowCounter++,"popup"===c.printMode.toLowerCase()){var l="printElementWindow"+k;f=a.open("about:blank",l,"width=650,height=440,scrollbars=yes"),j=f.document}else{var m="printElement_"+k,n=h.createElement("IFRAME");i(n).attr({style:c.iframeElementOptions.styleToAdd,id:m,className:c.iframeElementOptions.classNameToAdd,frameBorder:0,scrolling:"no",src:"about:blank"}),h.body.appendChild(n),j=n.contentWindow||n.contentDocument,j.document&&(j=j.document),n=h.frames?h.frames[m]:h.getElementById(m),f=n.contentWindow||n}focus(),j.open(),j.write(e),j.close(),d(f)}function d(a){a&&a.printPage?a.printPage():setTimeout(function(){d(a)},50)}function e(a){var b=i(a);i(":checked",b).each(function(){this.setAttribute("checked","checked")}),i("input[type='text'],input[type='number']",b).each(function(){this.setAttribute("value",i(this).val())}),i("select",b).each(function(){var a=i(this);i("option",a).each(function(){a.val()===i(this).val()&&this.setAttribute("selected","selected")})}),i("textarea",b).each(function(){var a=i(this).attr("value");this.firstChild?this.firstChild.textContent=a:this.innerHTML=a});var c=i("
").append(b.clone()).html();return c}function f(){var b=a.location.port?":"+a.location.port:"";return a.location.protocol+"//"+a.location.hostname+b+a.location.pathname}function g(a,b){var c=i(a),d=e(a),g=[];if(g.push(""+b.pageTitle+""),b.overrideElementCSS){if(b.overrideElementCSS.length>0)for(var j=0;j');else{var l=k.media||"";g.push('')}}}else i("link",h).filter(function(){return"stylesheet"===i(this).attr("rel").toLowerCase()}).each(function(){var a=i(this).attr("media")||"";g.push('')});return g.push(''),g.push(''),g.push('
'+d+"
"),g.push('"),g.push(""),g.join("")}var h=a.document,i=a.jQuery;i.fn.printElement=function(a){var b=i.extend({},i.fn.printElement.defaults,a);return"iframe"===b.printMode&&/chrome/.test(navigator.userAgent.toLowerCase())&&(b.printMode="popup"),i("[id^='printElement_']").remove(),this.each(function(){var a=i.meta?i.extend({},b,i(this).data()):b;c(i(this),a)})},i.fn.printElement.defaults={printMode:"iframe",pageTitle:"",overrideElementCSS:null,printBodyOptions:{styleToAdd:"padding:10px;margin:10px;",classNameToAdd:""},leaveOpen:!1,iframeElementOptions:{styleToAdd:"border:none;position:absolute;width:0px;height:0px;bottom:0px;left:0px;",classNameToAdd:""}},i.fn.printElement.cssElement={href:"",media:""}}(window); \ No newline at end of file diff --git a/package.json b/package.json index 05e5fc6..a9214a1 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "jquery.printElement", + "name": "jquery.printelement", "title": "jQuery printElement", "description": "The best jQuery plugin ever.", "version": "2.0.1", diff --git a/src/jquery.printelement.js b/src/jquery.printelement.js index ba0f499..3d40e27 100644 --- a/src/jquery.printelement.js +++ b/src/jquery.printelement.js @@ -63,12 +63,16 @@ var popupOrIframe = null; var documentToWriteTo = null; + var currentWindowCounter = $.fn.printElement.windowCounter; + $.fn.printElement.windowCounter++; if (opts.printMode.toLowerCase() === 'popup') { - popupOrIframe = window.open('about:blank', 'printElementWindow', 'width=650,height=440,scrollbars=yes'); + // IE duplication name bug: http://stackoverflow.com/questions/7146767/i-get-access-is-denied-when-i-try-to-print-a-page-using-jquery-printelement-js + var windowName = 'printElementWindow' + currentWindowCounter; + popupOrIframe = window.open('about:blank', windowName, 'width=650,height=440,scrollbars=yes'); documentToWriteTo = popupOrIframe.document; } else { //The random ID is to overcome a safari bug http://www.cjboco.com.sharedcopy.com/post.cfm/442dc92cd1c0ca10a5c35210b8166882.html - var printElementID = "printElement_" + (Math.round(Math.random() * 99999)).toString(); + var printElementID = "printElement_" + currentWindowCounter; //Native creation of the element is faster.. var iframe = document.createElement('IFRAME'); $(iframe).attr({ From bb2576b189afb9ce8bb8a6e4504c1c6ac95eac8d Mon Sep 17 00:00:00 2001 From: Rikanishu Date: Wed, 15 Apr 2015 17:34:24 +0300 Subject: [PATCH 2/3] IE fix --- src/jquery.printelement.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/jquery.printelement.js b/src/jquery.printelement.js index 3d40e27..606bee9 100644 --- a/src/jquery.printelement.js +++ b/src/jquery.printelement.js @@ -63,16 +63,14 @@ var popupOrIframe = null; var documentToWriteTo = null; - var currentWindowCounter = $.fn.printElement.windowCounter; - $.fn.printElement.windowCounter++; if (opts.printMode.toLowerCase() === 'popup') { // IE duplication name bug: http://stackoverflow.com/questions/7146767/i-get-access-is-denied-when-i-try-to-print-a-page-using-jquery-printelement-js - var windowName = 'printElementWindow' + currentWindowCounter; + var windowName = 'printElementWindow_' + (Math.round(Math.random() * 99999)).toString(); popupOrIframe = window.open('about:blank', windowName, 'width=650,height=440,scrollbars=yes'); documentToWriteTo = popupOrIframe.document; } else { //The random ID is to overcome a safari bug http://www.cjboco.com.sharedcopy.com/post.cfm/442dc92cd1c0ca10a5c35210b8166882.html - var printElementID = "printElement_" + currentWindowCounter; + var printElementID = "printElement_" + (Math.round(Math.random() * 99999)).toString(); //Native creation of the element is faster.. var iframe = document.createElement('IFRAME'); $(iframe).attr({ From 9510e4be3a50d24e2a525b2bb03a53dbf94a0a4b Mon Sep 17 00:00:00 2001 From: Rikanishu Date: Wed, 15 Apr 2015 17:37:03 +0300 Subject: [PATCH 3/3] IE fix --- dist/jquery.printelement.js | 6 ++---- dist/jquery.printelement.min.js | 2 +- src/jquery.printelement.js | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/dist/jquery.printelement.js b/dist/jquery.printelement.js index c184c96..fa9efc5 100644 --- a/dist/jquery.printelement.js +++ b/dist/jquery.printelement.js @@ -52,16 +52,14 @@ var popupOrIframe = null; var documentToWriteTo = null; - var currentWindowCounter = $.fn.printElement.windowCounter; - $.fn.printElement.windowCounter++; if (opts.printMode.toLowerCase() === 'popup') { // IE duplication name bug: http://stackoverflow.com/questions/7146767/i-get-access-is-denied-when-i-try-to-print-a-page-using-jquery-printelement-js - var windowName = 'printElementWindow' + currentWindowCounter; + var windowName = 'printElementWindow_' + (Math.round(Math.random() * 99999)).toString(); popupOrIframe = window.open('about:blank', windowName, 'width=650,height=440,scrollbars=yes'); documentToWriteTo = popupOrIframe.document; } else { //The random ID is to overcome a safari bug http://www.cjboco.com.sharedcopy.com/post.cfm/442dc92cd1c0ca10a5c35210b8166882.html - var printElementID = "printElement_" + currentWindowCounter; + var printElementID = "printElement_" + (Math.round(Math.random() * 99999)).toString(); //Native creation of the element is faster.. var iframe = document.createElement('IFRAME'); $(iframe).attr({ diff --git a/dist/jquery.printelement.min.js b/dist/jquery.printelement.min.js index 7b17b18..f4030f9 100644 --- a/dist/jquery.printelement.min.js +++ b/dist/jquery.printelement.min.js @@ -1,4 +1,4 @@ /*! jQuery printElement - v2.0.1 - 2015-04-15 * https://github.com/erikzaadi/jQuery.printElement * Copyright (c) 2015 erikzaadi; Licensed MIT, GPL */ -!function(a,b){function c(b,c){var e=g(b,c),f=null,j=null,k=i.fn.printElement.windowCounter;if(i.fn.printElement.windowCounter++,"popup"===c.printMode.toLowerCase()){var l="printElementWindow"+k;f=a.open("about:blank",l,"width=650,height=440,scrollbars=yes"),j=f.document}else{var m="printElement_"+k,n=h.createElement("IFRAME");i(n).attr({style:c.iframeElementOptions.styleToAdd,id:m,className:c.iframeElementOptions.classNameToAdd,frameBorder:0,scrolling:"no",src:"about:blank"}),h.body.appendChild(n),j=n.contentWindow||n.contentDocument,j.document&&(j=j.document),n=h.frames?h.frames[m]:h.getElementById(m),f=n.contentWindow||n}focus(),j.open(),j.write(e),j.close(),d(f)}function d(a){a&&a.printPage?a.printPage():setTimeout(function(){d(a)},50)}function e(a){var b=i(a);i(":checked",b).each(function(){this.setAttribute("checked","checked")}),i("input[type='text'],input[type='number']",b).each(function(){this.setAttribute("value",i(this).val())}),i("select",b).each(function(){var a=i(this);i("option",a).each(function(){a.val()===i(this).val()&&this.setAttribute("selected","selected")})}),i("textarea",b).each(function(){var a=i(this).attr("value");this.firstChild?this.firstChild.textContent=a:this.innerHTML=a});var c=i("
").append(b.clone()).html();return c}function f(){var b=a.location.port?":"+a.location.port:"";return a.location.protocol+"//"+a.location.hostname+b+a.location.pathname}function g(a,b){var c=i(a),d=e(a),g=[];if(g.push(""+b.pageTitle+""),b.overrideElementCSS){if(b.overrideElementCSS.length>0)for(var j=0;j');else{var l=k.media||"";g.push('')}}}else i("link",h).filter(function(){return"stylesheet"===i(this).attr("rel").toLowerCase()}).each(function(){var a=i(this).attr("media")||"";g.push('')});return g.push(''),g.push(''),g.push('
'+d+"
"),g.push('"),g.push(""),g.join("")}var h=a.document,i=a.jQuery;i.fn.printElement=function(a){var b=i.extend({},i.fn.printElement.defaults,a);return"iframe"===b.printMode&&/chrome/.test(navigator.userAgent.toLowerCase())&&(b.printMode="popup"),i("[id^='printElement_']").remove(),this.each(function(){var a=i.meta?i.extend({},b,i(this).data()):b;c(i(this),a)})},i.fn.printElement.defaults={printMode:"iframe",pageTitle:"",overrideElementCSS:null,printBodyOptions:{styleToAdd:"padding:10px;margin:10px;",classNameToAdd:""},leaveOpen:!1,iframeElementOptions:{styleToAdd:"border:none;position:absolute;width:0px;height:0px;bottom:0px;left:0px;",classNameToAdd:""}},i.fn.printElement.cssElement={href:"",media:""}}(window); \ No newline at end of file +!function(a,b){function c(b,c){var e=g(b,c),f=null,j=null;if("popup"===c.printMode.toLowerCase()){var k="printElementWindow_"+Math.round(99999*Math.random()).toString();f=a.open("about:blank",k,"width=650,height=440,scrollbars=yes"),j=f.document}else{var l="printElement_"+Math.round(99999*Math.random()).toString(),m=h.createElement("IFRAME");i(m).attr({style:c.iframeElementOptions.styleToAdd,id:l,className:c.iframeElementOptions.classNameToAdd,frameBorder:0,scrolling:"no",src:"about:blank"}),h.body.appendChild(m),j=m.contentWindow||m.contentDocument,j.document&&(j=j.document),m=h.frames?h.frames[l]:h.getElementById(l),f=m.contentWindow||m}focus(),j.open(),j.write(e),j.close(),d(f)}function d(a){a&&a.printPage?a.printPage():setTimeout(function(){d(a)},50)}function e(a){var b=i(a);i(":checked",b).each(function(){this.setAttribute("checked","checked")}),i("input[type='text'],input[type='number']",b).each(function(){this.setAttribute("value",i(this).val())}),i("select",b).each(function(){var a=i(this);i("option",a).each(function(){a.val()===i(this).val()&&this.setAttribute("selected","selected")})}),i("textarea",b).each(function(){var a=i(this).attr("value");this.firstChild?this.firstChild.textContent=a:this.innerHTML=a});var c=i("
").append(b.clone()).html();return c}function f(){var b=a.location.port?":"+a.location.port:"";return a.location.protocol+"//"+a.location.hostname+b+a.location.pathname}function g(a,b){var c=i(a),d=e(a),g=[];if(g.push(""+b.pageTitle+""),b.overrideElementCSS){if(b.overrideElementCSS.length>0)for(var j=0;j');else{var l=k.media||"";g.push('')}}}else i("link",h).filter(function(){return"stylesheet"===i(this).attr("rel").toLowerCase()}).each(function(){var a=i(this).attr("media")||"";g.push('')});return g.push(''),g.push(''),g.push('
'+d+"
"),g.push('"),g.push(""),g.join("")}var h=a.document,i=a.jQuery;i.fn.printElement=function(a){var b=i.extend({},i.fn.printElement.defaults,a);return"iframe"===b.printMode&&/chrome/.test(navigator.userAgent.toLowerCase())&&(b.printMode="popup"),i("[id^='printElement_']").remove(),this.each(function(){var a=i.meta?i.extend({},b,i(this).data()):b;c(i(this),a)})},i.fn.printElement.defaults={printMode:"iframe",pageTitle:"",overrideElementCSS:null,printBodyOptions:{styleToAdd:"padding:10px;margin:10px;",classNameToAdd:""},leaveOpen:!1,iframeElementOptions:{styleToAdd:"border:none;position:absolute;width:0px;height:0px;bottom:0px;left:0px;",classNameToAdd:""}},i.fn.printElement.cssElement={href:"",media:""}}(window); \ No newline at end of file diff --git a/src/jquery.printelement.js b/src/jquery.printelement.js index 606bee9..7bb7eb0 100644 --- a/src/jquery.printelement.js +++ b/src/jquery.printelement.js @@ -70,7 +70,7 @@ documentToWriteTo = popupOrIframe.document; } else { //The random ID is to overcome a safari bug http://www.cjboco.com.sharedcopy.com/post.cfm/442dc92cd1c0ca10a5c35210b8166882.html - var printElementID = "printElement_" + (Math.round(Math.random() * 99999)).toString(); + var printElementID = "printElement_" + (Math.round(Math.random() * 99999)).toString(); //Native creation of the element is faster.. var iframe = document.createElement('IFRAME'); $(iframe).attr({