/**
 * Open the browser print dialog when ?autoprint=1, and on Print button click.
 */
(function () {
	'use strict';

	function bindPrint() {
		var printBtn = document.getElementById('wpdude-dc-print');
		if (printBtn) {
			printBtn.addEventListener('click', function () {
				window.print();
			});
		}
		if (window.location.search.indexOf('autoprint=1') !== -1) {
			window.print();
		}
	}

	if (document.readyState === 'loading') {
		document.addEventListener('DOMContentLoaded', bindPrint);
	} else {
		bindPrint();
	}
})();
