Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export as 'universal module' #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions printThis.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,33 @@
* Notes:
* - the loadCSS will load additional css (with or without @media print) into the iframe, adjusting layout
*/
;
(function($) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = function( root, jQuery ) {
if ( jQuery === undefined ) {
// require('jQuery') returns a factory that requires window to
// build a jQuery instance, we normalize how we use modules
// that require this pattern but the window provided is a noop
// if it's defined (how jquery works)
if ( typeof window !== 'undefined' ) {
jQuery = require('jquery');
}
else {
jQuery = require('jquery')(root);
}
}
factory(jQuery);
return jQuery;
};
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {

function appendContent($el, content) {
if (!content) return;
Expand Down Expand Up @@ -100,7 +125,7 @@
top: "-600px"
});

// $iframe.ready() and $iframe.load were inconsistent between browsers
// $iframe.ready() and $iframe.load were inconsistent between browsers
setTimeout(function() {

// Add doctype to fix the style difference between printing and render
Expand Down Expand Up @@ -146,7 +171,7 @@
$head.append("<link type='text/css' rel='stylesheet' href='" + href + "' media='" + media + "'>");
}
});

// import style tags
if (opt.importStyle) $("style").each(function() {
$(this).clone().appendTo($head);
Expand Down Expand Up @@ -301,4 +326,4 @@
doctypeString: '<!DOCTYPE html>', // html doctype
removeScripts: false // remove script tags before appending
};
})(jQuery);
}));