A jQuery plugin for printing specific selection/element with customization.
- Select specific
HTMLelement. - Load body
CSSwith extraCSS. - Hide specific element during print.
- Customize document page.
- Wrap element with specific HTML
- Override
HTMLattribute (replace). - Auto reponsive.
clone divjs repo or download it in your project directory.
git clone https://github.com/zxalif/divjs.gitAdd divjs.js after jQuery
<script src="http://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<script type="text/javascript" src="divjs/divjs.js"></script>Just select an element to print it. example
$('#example').printElement();- title: The title of the print document.
- css: Loading internal
css. - ecss: Loading customize sytles for print.
- lcss: List of local
cssto be add. - keepHide: Hide this selection in document page (no need to print this).
- wrapper: Wrap html element within it.
To change the document title
$('#example').printElement({
title: 'New title for Window' // default is page title
});Loading page css.
css: options are 3 types.
extendto load all thecss(links and styles) ofthispage.styleto load onlycssinstyletag.linkloads only linkscss.
Example (extend)
It will load all kind of styles.
$('#example').printElement({
title: 'Loading all styles in this page.',
css: 'extend' // it will load all `css`
});Example (style) It will load only styles in style tag.
$('#example').printElement({
title: 'Loading only css of style tag.',
css: 'style'
});Example (link)
To load link css use link.
$('#example').printElement({
title: 'Loading link css',
css: 'link'
});The options ecss used to perform loading customize of some style.
Example
$('#example').printElement({
title: 'Loading link css',
css: 'link',
ecss: '.active{background-color: red;} #counter{background-color: #000; color: #fff;}'
});Loading link extra css.
lcss: [] // lcss is an array to used load extarnal or cdn.
Example
$('#example').printElement({
title: 'Loading link css',
css: 'link',
ecss: '.active{background-color: red;} #counter{background-color: #000; color: #fff;}',
lcss: ['example.css', '/local/css/print.css']
});To wrap element with specific element just select the element with jQuery or use it as string.
Example
<p id="contacts">All the contacts are going to be print.<p>
<button id="printer">Print</button>
<div>
<h1>Somethig goes before the printer element</h1>
<div id="wrapper"></div>
<p>Footer after the wrapper</p>
</div>jQuery('#printer').on('click', function(event){
event.preventDefault();
jQuery('#contacts').printElement({
wrapper: {
wrapper: $('#selector'), // the element that going to be wrap `#contacts`
selector: '#wrapper', // inside the `#wrapper` id it will wrap
}
});
});Example
<p id="contacts">All the contacts are going to be print.<p>
<button id="printer">Print</button>jQuery('#printer').on('click', function(event){
event.preventDefault();
jQuery('#contacts').printElement({
wrapper: {
wrapper: '<div><h1>Somethig goes before the printer element</h1><div id="wrapper"></div><p>Footer after the wrapper</p></div>', // the element that going to be wrap `#contacts`
selector: '#wrapper', // inside the `#wrapper` id it will wrap
}
});
});Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Free Software, Hell Yeah!
