From 7916ed7c783f6535a608fcc78e72633ce2e43b4e Mon Sep 17 00:00:00 2001 From: Bengt Brodersen Date: Sun, 17 May 2015 02:21:14 +0200 Subject: [PATCH] add option for multiple Column and Rows --- bookmarklet.js | 192 ++++++++++++++++++++++++++++--------------------- 1 file changed, 111 insertions(+), 81 deletions(-) diff --git a/bookmarklet.js b/bookmarklet.js index f7f8cab..bd9ca79 100644 --- a/bookmarklet.js +++ b/bookmarklet.js @@ -3,30 +3,26 @@ console.log("Version: " + version); try { + // load jQuery + if (window.jQuery === undefined) { + appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'); + } + 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 appFunctions = null; + var printScopeDeviderToken = "Attachment"; 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'); - } + var resourceOrigin = hostOrigin + "resources/"; // wait untill all scripts loaded appendScript('https://qoomon.github.io/void', function() { - init(); main(); }); @@ -41,22 +37,26 @@ } 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 } + + 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(); + } } function main() { + init(); + //preconditions if (jQuery("#card-print-overlay").length > 0) { alert("Print Card already opened!"); @@ -64,7 +64,6 @@ } var issueKeyList = appFunctions.getSelectedIssueKeyList(); - if (issueKeyList.length <= 0) { alert("Please select at least one issue."); return; @@ -74,6 +73,13 @@ jQuery("body").append(printOverlayHTML); jQuery("#card-print-overlay").prepend(printOverlayStyle); + jQuery("#rowCount").val(readCookie("card_printer_row_count",2)); + jQuery("#columnCount").val(readCookie("card_printer_column_count",1)); + jQuery("#card-scale-range").val(readCookie("card_printer_card_scale",1)); + jQuery("#multi-card-page-checkbox").attr('checked',readCookie("card_printer_multi_card_page",false) != 'false'); + jQuery("#hide-description-checkbox").attr('checked',readCookie("card_printer_hide_description",false) != 'false'); + + if (isProd) { ga('send', 'pageview'); } @@ -81,61 +87,55 @@ jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues..."); renderCards(issueKeyList, function() { jQuery("#card-print-dialog-title").text("Card Print"); - print(); + // print(); }); } function print() { + var rowCount = jQuery("#rowCount").val(); + var columnCount = jQuery("#columnCount").val(); + var scale = jQuery("#card-scale-range").val(); + var multiCard = jQuery("#multi-card-page-checkbox").is(':checked'); + var hideDescription = jQuery("#hide-description-checkbox").is(':checked'); + + writeCookie("card_printer_row_count", rowCount); + writeCookie("card_printer_column_count",columnCount); + writeCookie("card_printer_card_scale",scale); + writeCookie("card_printer_multi_card_page",multiCard); + writeCookie("card_printer_hide_description",hideDescription); + 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); - + var currentScale = jQuery("html", printDocument).css("font-size").replace("px", ""); 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", ""); + jQuery("html", printDocument).css("font-size",currentScale +"px"); + jQuery(".page", printDocument).css("height", "calc( 100% / " + rowCount + " )"); + jQuery(".page", printDocument).css("width", "calc( 100% / " + columnCount + " )"); - var cardScale = htmlWidth / cardMinWidth; + var pageWidth = jQuery(".page", printDocument).width(); + var cardWidth = jQuery(".card", printDocument).width(); - console.log("htmlWidth: " + htmlWidth); - console.log("cardMinWidth: " + cardMinWidth); - console.log("cardScale: " + cardScale); + var newScale = currentScale * pageWidth / cardWidth; - jQuery("html", printDocument).css("font-size",cardScale+"cm"); + jQuery("html", printDocument).css("font-size",newScale +"px"); - jQuery(".page", printDocument).each(function(position, page) { + jQuery(".card", printDocument).each(function(position, element) { - 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 + ""); + var height = jQuery(element).height() + - jQuery(element).find(".card-header").height() + - jQuery(element).find(".card-footer").height() + - jQuery(element).find(".content-header").height() + - 40; + jQuery(element).find(".description").css("max-height", height + "px"); }); }); - 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(); + jQuery("html", printDocument).css("font-size",currentScale +"px"); } function hideDescription(hide) { @@ -273,7 +273,6 @@ //############################################################################################################################ //############################################################################################################################ - // http://www.cssdesk.com/T9hXg function printOverlayHTML() { @@ -296,9 +295,11 @@