Skip to content

Commit

Permalink
Merge pull request #83 from jasonday/arbitrary-base
Browse files Browse the repository at this point in the history
Add base URL support and increment version
  • Loading branch information
jasonday authored Dec 15, 2016
2 parents f4a8ba2 + cbbcf92 commit 2c4fb35
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ really 'Issues'
removeInline: false, * remove all inline styles from print elements
printDelay: 333, * variable print delay; depending on complexity a higher value may be necessary
header: null, * prefix to html
base: false * preserve the BASE tag
base: false * preserve the BASE tag, or accept a string for the URL
formValues: true * preserve input/form values
});
```
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
12/14/2016 Added support for arbitrary BASE urls.
Bumped to 1.7.0, following semver (new feature).

12/13/2016 Incremented to 1.6.0 for new base setting.

11/23/2016 added new base option. Preserves the BASE tag from the parent page.

11/07/2014 Fixed bug; Recent versions of Firefox are not applying the parent document domain to
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "print-this",
"version": "1.6.0",
"version": "1.7.0",
"description": "Printing plug-in for jQuery",
"main": "printThis.js",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion printThis.jquery.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "printThis",
"version": "1.6.0",
"version": "1.7.0",
"title": "printThis",
"description": "Printing plug-in for jQuery. Print specific page elements, add print options, maintain or add new styling using jQuery.",
"author": {
Expand Down
33 changes: 20 additions & 13 deletions printThis.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* printThis v1.6.0
* printThis v1.7.0
* @desc Printing plug-in for jQuery
* @author Jason Day
*
Expand All @@ -25,7 +25,7 @@
* removeInline: false, * remove all inline styles from print elements
* printDelay: 333, * variable print delay
* header: null, * prefix to html
* base: false, * preserve the BASE tag
* base: false, * preserve the BASE tag, or accept a string for the URL
* formValues: true * preserve input/form values
* });
*
Expand Down Expand Up @@ -90,16 +90,24 @@

var $doc = $iframe.contents(),
$head = $doc.find("head"),
$body = $doc.find("body");
$body = $doc.find("body"),
$base = $('base'),
baseURL;

// add base tag to ensure elements use the parent domain
if (opt.base && $('base').length > 0) {
if (opt.base === true && $base.length > 0) {
// take the base tag from the original page
$head.append('<base href="' + $('base').attr('href') + '">');
baseURL = $base.attr('href');
} else if (typeof opt.base === 'string') {
// An exact base string is provided
baseURL = opt.base;
} else {
$head.append('<base href="' + document.location.protocol + '//' + document.location.host + '">');
// Use the page URL as the base
baseURL = document.location.protocol + '//' + document.location.host;
}

$head.append('<base href="' + baseURL + '">');

// import page stylesheets
if (opt.importCSS) $("link[rel=stylesheet]").each(function() {
var href = $(this).attr("href");
Expand All @@ -112,10 +120,9 @@
// import style tags
if (opt.importStyle) $("style").each(function() {
$(this).clone().appendTo($head);
//$head.append($(this));
});

//add title of the page
// add title of the page
if (opt.pageTitle) $head.append("<title>" + opt.pageTitle + "</title>");

// import additional stylesheet(s)
Expand Down Expand Up @@ -152,7 +159,7 @@
$iframeInput = $doc.find('input[name="' + $name + '"]'),
$value = $this.val();

//order matters here
// order matters here
if (!$checker) {
$iframeInput.val($value);
} else if ($this.is(':checked')) {
Expand All @@ -166,7 +173,7 @@
});
}

//loop through selects
// loop through selects
var $select = $element.find('select');
if ($select.length) {
$select.each(function() {
Expand All @@ -177,7 +184,7 @@
});
}

//loop through textareas
// loop through textareas
var $textarea = $element.find('textarea');
if ($textarea.length) {
$textarea.each(function() {
Expand Down Expand Up @@ -215,7 +222,7 @@
}
}

//remove iframe after print
// remove iframe after print
if (!opt.debug) {
setTimeout(function() {
$iframe.remove();
Expand All @@ -240,7 +247,7 @@
printDelay: 333, // variable print delay
header: null, // prefix to html
formValues: true, // preserve input/form values
base: false, // preserve the base tag (if available)
base: false, // preserve the BASE tag, or accept a string for the URL
doctypeString: '<!DOCTYPE html>' // html doctype
};

Expand Down

0 comments on commit 2c4fb35

Please sign in to comment.