diff --git a/README.md b/README.md index 6837771..f8132ea 100644 --- a/README.md +++ b/README.md @@ -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 }); ``` diff --git a/changelog.txt b/changelog.txt index d823510..54d9235 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/package.json b/package.json index 8164d59..b58e22f 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/printThis.jquery.json b/printThis.jquery.json index 500c3ca..42e3848 100644 --- a/printThis.jquery.json +++ b/printThis.jquery.json @@ -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": { diff --git a/printThis.js b/printThis.js index 6fe03bb..183f9c8 100644 --- a/printThis.js +++ b/printThis.js @@ -1,5 +1,5 @@ /* - * printThis v1.6.0 + * printThis v1.7.0 * @desc Printing plug-in for jQuery * @author Jason Day * @@ -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 * }); * @@ -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(''); + baseURL = $base.attr('href'); + } else if (typeof opt.base === 'string') { + // An exact base string is provided + baseURL = opt.base; } else { - $head.append(''); + // Use the page URL as the base + baseURL = document.location.protocol + '//' + document.location.host; } + $head.append(''); + // import page stylesheets if (opt.importCSS) $("link[rel=stylesheet]").each(function() { var href = $(this).attr("href"); @@ -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("" + opt.pageTitle + ""); // import additional stylesheet(s) @@ -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')) { @@ -166,7 +173,7 @@ }); } - //loop through selects + // loop through selects var $select = $element.find('select'); if ($select.length) { $select.each(function() { @@ -177,7 +184,7 @@ }); } - //loop through textareas + // loop through textareas var $textarea = $element.find('textarea'); if ($textarea.length) { $textarea.each(function() { @@ -215,7 +222,7 @@ } } - //remove iframe after print + // remove iframe after print if (!opt.debug) { setTimeout(function() { $iframe.remove(); @@ -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: '' // html doctype };