mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-13 02:21:08 +03:30
70 lines
1.8 KiB
JavaScript
Vendored
70 lines
1.8 KiB
JavaScript
Vendored
(function (global, factory) {
|
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
typeof define === 'function' && define.amd ? define(factory) :
|
|
(global = global || self, global.VueHtmlToPaper = factory());
|
|
}(this, function () { 'use strict';
|
|
|
|
function addStyles (win, styles) {
|
|
styles.forEach(style => {
|
|
let link = win.document.createElement('link');
|
|
link.setAttribute('rel', 'stylesheet');
|
|
link.setAttribute('type', 'text/css');
|
|
link.setAttribute('href', style);
|
|
win.document.getElementsByTagName('head')[0].appendChild(link);
|
|
});
|
|
}
|
|
|
|
const VueHtmlToPaper = {
|
|
install (Vue, options) {
|
|
Vue.mixin({
|
|
methods: {
|
|
$htmlToPaper (el, cb) {
|
|
let {
|
|
name,
|
|
specs,
|
|
replace,
|
|
styles
|
|
} = options;
|
|
specs = !!specs.length ? specs.join(',') : '';
|
|
|
|
const element = document.getElementById(el);
|
|
|
|
if(!element) {
|
|
alert(`Element to print #${el} not found!`);
|
|
return;
|
|
}
|
|
|
|
const url = '';
|
|
const win = window.open(url, name, specs, replace);
|
|
|
|
win.document.write(`
|
|
<html>
|
|
<head>
|
|
<title>${document.title}</title>
|
|
</head>
|
|
<body>
|
|
${element.innerHTML}
|
|
</body>
|
|
</html>
|
|
`);
|
|
|
|
addStyles(win, styles);
|
|
|
|
setTimeout(() => {
|
|
win.document.close();
|
|
win.focus();
|
|
win.print();
|
|
win.close();
|
|
cb();
|
|
}, 1000);
|
|
return true;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
return VueHtmlToPaper;
|
|
|
|
}));
|