Skip to content

Commit

Permalink
Merge branch 'Villentrenmerth-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sathvik P committed Sep 15, 2016
2 parents 6ccdbf1 + 3e9462c commit 8b72130
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You can submit the options object like:
prepend: null,
manuallyCopyFormValues: true,
deferred: $.Deferred(),
timeout: 250,
timeout: 750,
title: null,
doctype: '<!doctype html>'
});
Expand Down Expand Up @@ -93,9 +93,9 @@ Currently this plugin supports the following options:
####timeout
- Default: `250`
- Default: `750`
- Acceptable-Values: Time in Milliseconds for `setTimeout`
- Function: To change the amount of time to wait for the content, etc to load before printing the element from the new window/iframe created
- Function: To change the amount of max time to wait for the content, etc to load before printing the element from the new window/iframe created, as a fallback if the [`load` event](https://developer.mozilla.org/en-US/docs/Web/Events/load) for the new window/iframe has not fired yet
####title
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jQuery.print",
"main": "jQuery.print.js",
"version": "1.4.1",
"version": "1.5.0",
"homepage": "https://doersguild.github.io/jQuery.print/",
"authors": [
"Sathvik P <[email protected]>"
Expand Down
25 changes: 23 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h3>Element 2</h3>
Some other random text.
</p>
<button class="print-link no-print">
Print this ($.print("#ele2")) and skip the button
Print this ($.print("#ele2")) and skip the button (.no-print)
</button>
</div>
<div id="ele3" class="a">
Expand All @@ -64,13 +64,34 @@ <h3 class='avoid-this'>Element 4</h3>
<p>
Some really random text.
</p>
<pre><code>
$("#ele4").find('button').on('click', function() {
//Print ele4 with custom options
$("#ele4").print({
//Use Global styles
globalStyles : false,
//Add link with attrbute media=print
mediaPrint : false,
//Custom stylesheet
stylesheet : "http://fonts.googleapis.com/css?family=Inconsolata",
//Print in a hidden iframe
iframe : false,
//Don't print this
noPrintSelector : ".avoid-this",
//Add this at top
prepend : "Hello World!!!<br/>",
//Add this on bottom
append : "<br/>Buh Bye!"
});
});
</code></pre>
<button class="print-link avoid-this">
Print this in a new window, without this button and the title
</button>
</div>
<br/>
<button class="print-link" onclick="jQuery.print()">
Print page
Print page - jQuery.print()
</button>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
Expand Down
17 changes: 13 additions & 4 deletions jQuery.print.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @license
* jQuery.print, version 1.4.0
* jQuery.print, version 1.5.0
* (c) Sathvik Ponangi, Doers' Guild
* Licence: CC-By (http://creativecommons.org/licenses/by/3.0/)
*--------------------------------------------------------------------------*/
Expand Down Expand Up @@ -30,7 +30,11 @@
}
wdoc.write(content);
wdoc.close();
setTimeout(function () {
var printed = false;
function callPrint() {
if(printed) {
return;
}
// Fix for IE : Allow it to render the iframe
frameWindow.focus();
try {
Expand All @@ -43,8 +47,13 @@
frameWindow.print();
}
frameWindow.close();
printed = true;
def.resolve();
}, options.timeout);
}
// Print once the frame window loads - seems to work for the new-window option but unreliable for the iframe
$(frameWindow).on("load", callPrint);
// Fallback to printing directly if the frame doesn't fire the load event for whatever reason
setTimeout(callPrint, options.timeout);
} catch (err) {
def.reject(err);
}
Expand Down Expand Up @@ -151,7 +160,7 @@
prepend: null,
manuallyCopyFormValues: true,
deferred: $.Deferred(),
timeout: 250,
timeout: 750,
title: null,
doctype: '<!doctype html>'
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jQuery.print",
"filename": "jQuery.print.min.js",
"version": "1.4.1",
"version": "1.5.0",
"homepage": "https://doersguild.github.io/jQuery.print/",
"authors": [
"Sathvik P <[email protected]>"
Expand Down

0 comments on commit 8b72130

Please sign in to comment.