(function() {
var version = "3.5.0";
console.log("Version: " + version);
try {
var isDev = /.*jira.atlassian.com\/secure\/RapidBoard.jspa\?.*projectKey=ANERDS.*/g.test(document.URL) // Jira
|| /.*pivotaltracker.com\/n\/projects\/510733.*/g.test(document.URL); // PivotTracker
var isProd = !isDev;
if (isProd){
//cors = "https://cors-anywhere.herokuapp.com/";
//$("#card").load("https://cors-anywhere.herokuapp.com/"+"https://qoomon.github.io/Jira-Issue-Card-Printer/card.html");
initGoogleAnalytics();
}
var hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/";
if (isDev) {
console.log("DEVELOPMENT");
hostOrigin = "https://rawgit.com/qoomon/Jira-Issue-Card-Printer/develop/";
}
// load jQuery
if (window.jQuery === undefined) {
appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js');
}
// wait untill all scripts loaded
appendScript('https://qoomon.github.io/void', function() {
init();
main();
});
} catch (err) {
console.log(err.message);
if (isProd) {
ga('send', 'exception', {
'exDescription': err.message,
'exFatal': true
});
}
}
function init() {
addStringFunctions();
addDateFunctions();
var printScopeDeviderToken = "Attachment";
var resourceOrigin = hostOrigin + "resources/";
var appFunctions = {};
if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) {
appFunctions = jiraFunctions;
} else if (/.*\pivotaltracker.com\/.*/g.test(document.URL)) {
appFunctions = pivotalTrackerFunctions
}
}
function main() {
//preconditions
if (jQuery("#card-print-overlay").length > 0) {
alert("Print Card already opened!");
return;
}
var issueKeyList = appFunctions.getSelectedIssueKeyList();
if (issueKeyList.length <= 0) {
alert("Please select at least one issue.");
return;
}
// open print preview
jQuery("body").append(printOverlayHTML);
jQuery("#card-print-overlay").prepend(printOverlayStyle);
if (isProd) {
ga('send', 'pageview');
}
jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues...");
renderCards(issueKeyList, function() {
jQuery("#card-print-dialog-title").text("Card Print");
print();
});
}
function print() {
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
if (isProd) {
ga('send', 'event', 'button', 'click', 'print', jQuery(".card", printDocument).length);
}
//jQuery("html", printDocument).css("font-size", + 0.5 +"cm");
var orientationCSS = jQuery('')
// jQuery("head",printDocument).append(orientationCSS);
printWindow.matchMedia("print").addListener(function() {
var htmlWidth = jQuery("html", printDocument).css("font-size").replace("cm", "") * jQuery("html", printDocument).width() / 2;
var cardMinWidth = jQuery(".card", printDocument).css("min-width").replace("px", "");
var cardScale = htmlWidth / cardMinWidth;
console.log("htmlWidth: " + htmlWidth);
console.log("cardMinWidth: " + cardMinWidth);
console.log("cardScale: " + cardScale);
jQuery("html", printDocument).css("font-size",cardScale+"cm");
jQuery(".page", printDocument).each(function(position, page) {
jQuery(page).css("width", "calc( 50% - 1cm )");
jQuery(page).css("height", "calc( 50% - 1cm )");
jQuery(page).css("float", "left");
var height = jQuery(page).height() - jQuery(page).find(".card-header").outerHeight() - jQuery(page).find(".card-footer").outerHeight() - jQuery(page).find(".content-header").outerHeight() - 40;
jQuery(page).find(".description").css("max-height", height + "px");
var lineHeight = jQuery(page).find(".description").css("line-height");
lineHeight = lineHeight.substring(0, lineHeight.length - 2);
var lineClamp = Math.floor(height / lineHeight);
jQuery(page).find(".description").css("-webkit-line-clamp", lineClamp + "");
});
});
jQuery(".page:odd", printDocument).each(function(position, page) {
jQuery(page).css("margin-left", "2cm");
});
jQuery(".page:nth-child(4n+3)", printDocument).each(function(position, page) {
jQuery(page).css("margin-top", "2cm");
});
jQuery(".page:nth-child(4n+4)", printDocument).each(function(position, page) {
jQuery(page).css("margin-top", "2cm");
});
printWindow.print();
}
function hideDescription(hide) {
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
if (hide) {
jQuery(".description", printDocument).hide();
} else {
jQuery(".description", printDocument).show();
}
resizeIframe(printFrame);
}
function endableMultiCardPage(enable) {
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
if (enable) {
jQuery(".page", printDocument).addClass("multiCardPage");
} else {
jQuery(".page", printDocument).removeClass("multiCardPage");
}
}
function renderCards(issueKeyList, callback) {
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
printDocument.open();
printDocument.write("