diff --git a/bookmarklet.js b/bookmarklet.js
index 73484dc..4e4752a 100644
--- a/bookmarklet.js
+++ b/bookmarklet.js
@@ -1,1089 +1,925 @@
- (function () {
- var version = "3.4.0";
+(function() {
+ var version = "3.5.0";
console.log("Version: " + version);
- 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 global = {};
+ global.isDev = /.*jira.atlassian.com\/secure\/RapidBoard.jspa\?.*projectKey=ANERDS.*/g.test(document.URL) // Jira
+ || /.*pivotaltracker.com\/n\/projects\/510733.*/g.test(document.URL) // PivotTracker
+ || ( /.*trello.com\/.*/g.test(document.URL) && jQuery("span.js-member-name").text() =='Bengt Brodersen'); // Trello
+ global.isProd = !global.isDev;
- 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/";
- } else {
- //cors = "https://cors-anywhere.herokuapp.com/";
- //$("#card").load("https://cors-anywhere.herokuapp.com/"+"https://qoomon.github.io/Jira-Issue-Card-Printer/card.html");
+ window.addEventListener("error", function(event) {
+ var error = event.error;
+ console.log("ERROR: " + error.stack);
+ if (global.isProd) {
+ ga('send', 'exception', {
+ 'exDescription': error.message,
+ 'exFatal': true
+ });
+ }
+ });
- //
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
-
- ga('create', 'UA-50840116-3', {'alwaysSendReferrer': true});
- ga('set', 'page', '/cardprinter');
- }
-
- try {
- // load jQuery
- if (window.jQuery === undefined) {
+ // 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();
+ // wait untill all scripts loaded
+ appendScript('https://qoomon.github.io/void', function() {
main();
- });
- } catch (err) {
- console.log(err.message);
- if(!isDev){
- ga('send', 'exception', {
- 'exDescription': err.message,
- 'exFatal': true
+ });
+
+ function main() {
+ init();
+
+ // determine application
+ if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) {
+ console.log("App: " + "Jira");
+ global.appFunctions = jiraFunctions;
+ } else if (/.*pivotaltracker.com\/.*/g.test(document.URL)) {
+ console.log("App: " + "PivotalTracker");
+ global.appFunctions = pivotalTrackerFunctions;
+ } else if (/.*trello.com\/.*/g.test(document.URL)) {
+ console.log("App: " + "Trello");
+ global.appFunctions = trelloFunctions;
+ } else {
+ alert("Unsupported app.Please create an issue at https://github.com/qoomon/Jira-Issue-Card-Printer");
+ return;
+ }
+
+ //preconditions
+ if (jQuery("#card-print-overlay").length > 0) {
+ alert("Print Card already opened!");
+ return;
+ }
+
+ // collect selcted issues
+ var issueKeyList = global.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());
+
+ var printFrame = jQuery("#card-print-dialog-content-iframe");
+ var printWindow = printFrame[0].contentWindow;
+ printWindow.addEventListener("resize", function(){redrawCards;});
+ printWindow.matchMedia("print").addListener(function(){redrawCards;});
+
+ jQuery("#rowCount").val(readCookie("card_printer_row_count",2));
+ jQuery("#columnCount").val(readCookie("card_printer_column_count",1));
+ jQuery("#font-scale-range").val(readCookie("card_printer_font_scale",1));
+ jQuery("#single-card-page-checkbox").attr('checked',readCookie("card_printer_single_card_page",false) != 'false');
+ jQuery("#hide-description-checkbox").attr('checked',readCookie("card_printer_hide_description",false) != 'false');
+
+ jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues...");
+ renderCards(issueKeyList, function() {
+ jQuery("#card-print-dialog-title").text("Card Print");
+ //print();
});
- }
+
+ if (global.isProd) {
+ ga('send', 'pageview');
+ }
}
- function init(){
- addJQueryFunctions();
- addConsoleFunctions();
- addStringFunctions();
- addDateFunctions();
+ function init() {
+ addStringFunctions();
+ addDateFunctions();
- printScopeDeviderToken = "Attachment";
+ global.hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/";
+ if (global.isDev) {
+ console.log("DEVELOPMENT");
+ global.hostOrigin = "https://rawgit.com/qoomon/Jira-Issue-Card-Printer/develop/";
+ }
+ global.resourceOrigin = global.hostOrigin + "resources/";
- console.logLevel = console.INFO;
-
- resourceOrigin = hostOrigin+ "resources/";
-
- APP_JIRA='APP_JIRA'
- APP_PIVOTAL_TRACKER='APP_PIVOTAL_TRACKER'
- issueTracker = 'UNKNOWN'
- if( jQuery("meta[name='application-name'][ content='JIRA']").length > 0){
- issueTracker = APP_JIRA
- } else if( /.*\pivotaltracker.com\/.*/g.test(document.URL)){
- issueTracker = APP_PIVOTAL_TRACKER
- }
+ if (global.isProd){
+ initGoogleAnalytics();
+ }
}
- function main(){
- //preconditions
- if(jQuery("#card-print-overlay").length > 0){
- alert("Print Card already opened!");
- return;
- }
+ function print() {
+ if (global.isProd) {
+ ga('send', 'event', 'button', 'click', 'print', jQuery(".card", printDocument).length);
+ }
- var issueKeyList = 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(!isDev){
- 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");
- });
- }
-
- function print(){
- var printFrame = jQuery("#card-print-dialog-content-iframe");
- var printWindow = printFrame[0].contentWindow;
- var printDocument = printWindow.document;
- if(!isDev){
- ga('send', 'event', 'button', 'click', 'print', jQuery(".card", printDocument).length );
- }
-
- //jQuery("html", printDocument).css("font-size", + 0.5 +"cm");
-
- printWindow.matchMedia("print").addListener(function() {
- jQuery(".page",printDocument).each(function(position, page) {
- // jQuery(page).css("width","50%");
- // jQuery(page).css("height","50%");
- // 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+"");
- });
- });
- 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");
- }
+ var printFrame = jQuery("#card-print-dialog-content-iframe");
+ var printWindow = printFrame[0].contentWindow;
+ printWindow.print();
}
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("
");
+
+ jQuery("head", printDocument).append(cardCss());
+ jQuery("body", printDocument).append("");
+ jQuery("#preload", printDocument).append("");
+
+ console.log("load " + issueKeyList.length + " issues...");
+
+ var deferredList = [];
+ jQuery.each(issueKeyList, function(index, issueKey) {
+ var page = cardHtml(issueKey);
+ page.attr("index", index);
+ page.hide();
+ page.find('.issue-id').text(issueKey);
+ jQuery("body", printDocument).append(page);
+ var deferred = addDeferred(deferredList);
+ global.appFunctions.getCardData(issueKey, function(cardData) {
+ //console.log("cardData: " + cardData);
+ if (global.isProd) {
+ ga('send', 'event', 'task', 'generate', 'card', cardData.type);
+ }
+ fillCard(page, cardData);
+ page.show();
+ redrawCards();
+ deferred.resolve();
+ });
+ });
+ console.log("wait for issues loaded...");
+
+ applyDeferred(deferredList, function() {
+ console.log("...all issues loaded.");
+ jQuery(printWindow).load(function() {
+ console.log("...all resources loaded.");
+ callback();
+ })
+ printDocument.close();
+ console.log("wait for resources loaded...");
+ });
+ }
+
+ function redrawCards() {
+
+ var printFrame = jQuery("#card-print-dialog-content-iframe");
+ var printWindow = printFrame[0].contentWindow;
+ var printDocument = printWindow.document;
+
+ // hide/show description
+ jQuery("#styleHideDescription", printDocument).remove();
+ if(jQuery("#hide-description-checkbox")[0].checked){
+ var style= document.createElement('style');
+ style.id = 'styleHideDescription';
+ style.type ='text/css';
+ style.innerHTML = ".issue-description { display: none; }"
+ jQuery("head", printDocument).append(style);
+ }
+
+ // enable/disable single card page
+ jQuery("#styleSingleCardPage", printDocument).remove();
+ if(jQuery("#single-card-page-checkbox")[0].checked){
+ var style= document.createElement('style');
+ style.id = 'styleSingleCardPage';
+ style.type ='text/css';
+ style.innerHTML = ".card { page-break-after: always; float: none; }"
+ jQuery("head", printDocument).append(style);
+ }
+
+ scaleCards();
+
+ cropCards();
+
+ var printFrame = jQuery("#card-print-dialog-content-iframe");
+ resizeIframe(printFrame);
+ }
+
+
+ function fillCard(card, data) {
+ //Key
+ card.find('.issue-id').text(data.key);
+
+ //Type
+ card.find(".issue-icon").attr("type", data.type);
+
+ //Summary
+ card.find('.issue-summary').text(data.summary);
+
+ //Description
+ if (data.description) {
+ card.find('.issue-description').html(data.description);
+ } else {
+ card.find(".issue-description").addClass("hidden");
+ }
+
+ //Assignee
+ if (data.assignee) {
+ if (data.avatarUrl) {
+ card.find(".issue-assignee").css("background-image", "url('" + data.avatarUrl + "')");
+ } else {
+ card.find(".issue-assignee").text(data.assignee[0].toUpperCase());
+ }
+ } else {
+ card.find(".issue-assignee").addClass("hidden");
+ }
+
+ //Due-Date
+ if (data.dueDate) {
+ card.find(".issue-due-date").text(data.dueDate);
+ } else {
+ card.find(".issue-due-box").addClass("hidden");
+ }
+
+ //Attachment
+ if (data.hasAttachment) {} else {
+ card.find('.issue-attachment').addClass('hidden');
+ }
+
+ //Story Points
+ if (data.storyPoints) {
+ card.find(".issue-estimate").text(data.storyPoints);
+ } else {
+ card.find(".issue-estimate").addClass("hidden");
+ }
+
+ //Epic
+ if (data.epicKey) {
+ card.find(".issue-epic-id").text(data.epicKey);
+ card.find(".issue-epic-name").text(data.epicName);
+ } else {
+ card.find(".issue-epic-box").addClass("hidden");
+ }
+
+ //QR-Code
+ var qrCodeUrl = 'https://chart.googleapis.com/chart?cht=qr&chs=256x256&chld=L|1&chl=' + encodeURIComponent(data.url);
+ card.find(".issue-qr-code").css("background-image", "url('" + qrCodeUrl + "')");
+ }
+
+ function scaleCards(){
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
- printDocument.open();
- printDocument.write("