no message
This commit is contained in:
parent
1c09c951c5
commit
6914311994
153
bookmarklet.js
153
bookmarklet.js
@ -1,44 +1,38 @@
|
|||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
$ = $ || jQuery;
|
|
||||||
// Public Instances
|
// Public Instances
|
||||||
// Jira: https://connect.atlassian.net/browse/NERDS-33286
|
// Jira: https://connect.atlassian.net/browse/NERDS-33286
|
||||||
// PivotTracker: https://www.pivotaltracker.com/n/projects/510733
|
// PivotTracker: https://www.pivotaltracker.com/n/projects/510733
|
||||||
// Trello: https://trello.com/b/8zlPSh70/spike
|
// Trello: https://trello.com/b/8zlPSh70/spike
|
||||||
// YouTrack: http://qoomon.myjetbrains.com/youtrack/dashboard
|
// YouTrack: http://qoomon.myjetbrains.com/youtrack/dashboard
|
||||||
var global = {};
|
var global = {};
|
||||||
global.version = "4.3.6";
|
global.version = "4.4.0";
|
||||||
global.issueTrackingUrl = "https://github.com/qoomon/Jira-Issue-Card-Printer";
|
global.issueTrackingUrl = "https://github.com/qoomon/Jira-Issue-Card-Printer";
|
||||||
global.isDev = document.currentScript == null;
|
global.isDev = document.currentScript == null;
|
||||||
global.isProd = !global.isDev;
|
global.isProd = !global.isDev;
|
||||||
|
|
||||||
window.addEventListener("error", function(event) {
|
if (typeof jQuery == 'undefined') {
|
||||||
var error = event.error;
|
alert("jQuery is required!\n\nPlease create an issue at " + global.issueTrackingUrl);
|
||||||
console.log("ERROR: " + error.stack);
|
return;
|
||||||
if (global.isProd) {
|
}
|
||||||
ga('send', 'exception', {
|
var $ = jQuery;
|
||||||
'exDescription': error.message,
|
|
||||||
'exFatal': true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
init().then(function(){
|
try {
|
||||||
return main();
|
init().then(main).catch(handleError);
|
||||||
}).catch(function(cause){
|
} catch (e) {
|
||||||
console.log("ERROR " + cause.stack);
|
handleError(e);
|
||||||
alert("Sorry something went wrong.\n\nPlease create an issue at " + global.issueTrackingUrl + "\n\n" + cause.stack);
|
}
|
||||||
});
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
|
var promises = [];
|
||||||
|
|
||||||
|
ga('send', 'pageview');
|
||||||
|
|
||||||
//preconditions
|
//preconditions
|
||||||
if ($("#card-printer-iframe").length > 0) {
|
if ($("#card-printer-iframe").length > 0) {
|
||||||
alert("Card Printer already opened!");
|
alert("Card Printer already opened!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var promises = [];
|
|
||||||
|
|
||||||
console.log("Run...")
|
console.log("Run...")
|
||||||
// determine application
|
// determine application
|
||||||
if ($("meta[name='application-name'][ content='JIRA']").length > 0) {
|
if ($("meta[name='application-name'][ content='JIRA']").length > 0) {
|
||||||
@ -68,60 +62,35 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create iFrame
|
// add overlay frame
|
||||||
var appFrame = document.createElement('iframe');
|
var appFrame = createOverlayFrame();
|
||||||
appFrame.id = "card-printer-iframe";
|
|
||||||
$(appFrame).css({
|
|
||||||
'position': 'fixed',
|
|
||||||
'height': '100%',
|
|
||||||
'width': '100%',
|
|
||||||
'top': '0',
|
|
||||||
'left': '0',
|
|
||||||
'background': 'rgba(0, 0, 0, 0.5)',
|
|
||||||
'boxSizing': 'border-box',
|
|
||||||
'wordWrap': 'break-word',
|
|
||||||
'zIndex': '99999'
|
|
||||||
});
|
|
||||||
$("body").append(appFrame);
|
$("body").append(appFrame);
|
||||||
|
// add convinient fields
|
||||||
appFrame.window = appFrame.contentWindow;
|
appFrame.window = appFrame.contentWindow;
|
||||||
appFrame.document = appFrame.window.document;
|
appFrame.document = appFrame.window.document;
|
||||||
global.appFrame = appFrame;
|
global.appFrame = appFrame;
|
||||||
|
|
||||||
// open print preview
|
// add print dialog content
|
||||||
$("head", appFrame.document).prepend(printPreviewElementStyle());
|
$("head", global.appFrame.document).prepend(printPreviewElementStyle());
|
||||||
$("body", appFrame.document).append(printPreviewElement());
|
$("body", global.appFrame.document).append(printPreviewElement());
|
||||||
|
updatePrintDialoge();
|
||||||
|
|
||||||
var printFrame = $("#card-print-dialog-content-iframe", appFrame.document)[0];
|
// get print content frame
|
||||||
|
var printFrame = $("#card-print-dialog-content-iframe", global.appFrame.document)[0];
|
||||||
|
// add convinient fields
|
||||||
printFrame.window = printFrame.contentWindow;
|
printFrame.window = printFrame.contentWindow;
|
||||||
printFrame.document = printFrame.window.document;
|
printFrame.document = printFrame.window.document;
|
||||||
global.printFrame = printFrame;
|
global.printFrame = printFrame;
|
||||||
|
|
||||||
printFrame.contentWindow.addEventListener("resize", redrawCards);
|
// add listeners to redraw crads on print event
|
||||||
printFrame.contentWindow.matchMedia("print").addListener(redrawCards);
|
printFrame.window.addEventListener("resize", redrawCards);
|
||||||
|
printFrame.window.matchMedia("print").addListener(redrawCards);
|
||||||
|
|
||||||
var settings = global.settings;
|
$("#card-print-dialog-title", global.appFrame.document).text("Card Printer " + global.version + " - Loading issues...");
|
||||||
|
|
||||||
// restore UI state
|
|
||||||
$("#scaleRange", appFrame.document).val(settings.scale);
|
|
||||||
$("#scaleRange", appFrame.document).parent().find("output").val(settings.scale);
|
|
||||||
$("#rowCount", appFrame.document).val(settings.rowCount);
|
|
||||||
$("#columnCount", appFrame.document).val(settings.colCount);
|
|
||||||
|
|
||||||
$("#single-card-page-checkbox", appFrame.document).attr('checked', settings.singleCardPage );
|
|
||||||
$("#description-checkbox", appFrame.document).attr('checked', !settings.hideDescription );
|
|
||||||
$("#assignee-checkbox", appFrame.document).attr('checked', !settings.hideAssignee );
|
|
||||||
$("#due-date-checkbox", appFrame.document).attr('checked', !settings.hideDueDate );
|
|
||||||
$("#qr-code-checkbox", appFrame.document).attr('checked', !settings.hideQrCode );
|
|
||||||
|
|
||||||
$("#card-print-dialog-title", appFrame.document).text("Card Printer " + global.version + " - Loading issues...");
|
|
||||||
promises.push(renderCards(issueKeyList).then(function() {
|
promises.push(renderCards(issueKeyList).then(function() {
|
||||||
$("#card-print-dialog-title", appFrame.document).text("Card Printer " + global.version);
|
$("#card-print-dialog-title", global.appFrame.document).text("Card Printer " + global.version);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (global.isProd) {
|
|
||||||
ga('send', 'pageview');
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,8 +98,9 @@
|
|||||||
var promises = [];
|
var promises = [];
|
||||||
|
|
||||||
console.log("Init...")
|
console.log("Init...")
|
||||||
addStringFunctions();
|
initGoogleAnalytics();
|
||||||
|
|
||||||
|
addStringFunctions();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
global.hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/";
|
global.hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/";
|
||||||
@ -140,10 +110,6 @@
|
|||||||
}
|
}
|
||||||
global.resourceOrigin = global.hostOrigin + "resources/";
|
global.resourceOrigin = global.hostOrigin + "resources/";
|
||||||
|
|
||||||
if (global.isProd) {
|
|
||||||
initGoogleAnalytics();
|
|
||||||
}
|
|
||||||
|
|
||||||
promises.push(httpGetCORS(global.hostOrigin + "card.html").then(function(data){
|
promises.push(httpGetCORS(global.hostOrigin + "card.html").then(function(data){
|
||||||
global.cardHtml = data;
|
global.cardHtml = data;
|
||||||
}));
|
}));
|
||||||
@ -163,6 +129,12 @@
|
|||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleError(error){
|
||||||
|
console.log("ERROR " + error.stack);
|
||||||
|
ga('send', 'exception', { 'exDescription': error.message,'exFatal': true });
|
||||||
|
alert("Sorry something went wrong.\n\n" + error.message +"\n\nPlease create an issue at " + global.issueTrackingUrl + "\n\n" + error.stack);
|
||||||
|
}
|
||||||
|
|
||||||
function saveSettings(){
|
function saveSettings(){
|
||||||
var settings = global.settings;
|
var settings = global.settings;
|
||||||
writeCookie("card_printer_scale", settings.scale);
|
writeCookie("card_printer_scale", settings.scale);
|
||||||
@ -179,7 +151,7 @@
|
|||||||
function loadSettings(){
|
function loadSettings(){
|
||||||
var settings = global.settings = global.settings || {};
|
var settings = global.settings = global.settings || {};
|
||||||
settings.scale = parseFloat(readCookie("card_printer_scale")) || 0.0;
|
settings.scale = parseFloat(readCookie("card_printer_scale")) || 0.0;
|
||||||
settings.rowCount = parseInt(readCookie("card_printer_row_count2")) || 2;
|
settings.rowCount = parseInt(readCookie("card_printer_row_count")) || 2;
|
||||||
settings.colCount = parseInt(readCookie("card_printer_column_count")) || 1;
|
settings.colCount = parseInt(readCookie("card_printer_column_count")) || 1;
|
||||||
|
|
||||||
settings.singleCardPage = parseBool(readCookie("card_printer_single_card_page"), true );
|
settings.singleCardPage = parseBool(readCookie("card_printer_single_card_page"), true );
|
||||||
@ -190,13 +162,42 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function print() {
|
function print() {
|
||||||
if (global.isProd) {
|
ga('send', 'event', 'button', 'click', 'print', $(".card", global.printFrame.contentWindow.document).length);
|
||||||
ga('send', 'event', 'button', 'click', 'print', $(".card", global.printFrame.contentWindow.document).length);
|
|
||||||
}
|
|
||||||
|
|
||||||
global.printFrame.contentWindow.print();
|
global.printFrame.contentWindow.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createOverlayFrame(){
|
||||||
|
var appFrame = document.createElement('iframe');
|
||||||
|
appFrame.id = "card-printer-iframe";
|
||||||
|
$(appFrame).css({
|
||||||
|
'position': 'fixed',
|
||||||
|
'height': '100%',
|
||||||
|
'width': '100%',
|
||||||
|
'top': '0',
|
||||||
|
'left': '0',
|
||||||
|
'background': 'rgba(0, 0, 0, 0.5)',
|
||||||
|
'boxSizing': 'border-box',
|
||||||
|
'wordWrap': 'break-word',
|
||||||
|
'zIndex': '99999'
|
||||||
|
});
|
||||||
|
return appFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePrintDialoge(){
|
||||||
|
var appFrameDocument = global.appFrame.document;
|
||||||
|
var settings = global.settings;
|
||||||
|
$("#scaleRange", appFrameDocument).val(settings.scale);
|
||||||
|
$("#scaleRange", appFrameDocument).parent().find("output").val(settings.scale);
|
||||||
|
$("#rowCount", appFrameDocument).val(settings.rowCount);
|
||||||
|
$("#columnCount", appFrameDocument).val(settings.colCount);
|
||||||
|
|
||||||
|
$("#single-card-page-checkbox", appFrameDocument).attr('checked', settings.singleCardPage );
|
||||||
|
$("#description-checkbox", appFrameDocument).attr('checked', !settings.hideDescription );
|
||||||
|
$("#assignee-checkbox", appFrameDocument).attr('checked', !settings.hideAssignee );
|
||||||
|
$("#due-date-checkbox", appFrameDocument).attr('checked', !settings.hideDueDate );
|
||||||
|
$("#qr-code-checkbox", appFrameDocument).attr('checked', !settings.hideQrCode );
|
||||||
|
}
|
||||||
|
|
||||||
function renderCards(issueKeyList) {
|
function renderCards(issueKeyList) {
|
||||||
var promises = [];
|
var promises = [];
|
||||||
|
|
||||||
@ -220,9 +221,7 @@
|
|||||||
|
|
||||||
promises.push(global.appFunctions.getCardData(issueKey).then(function(cardData) {
|
promises.push(global.appFunctions.getCardData(issueKey).then(function(cardData) {
|
||||||
console.log("cardData: " + JSON.stringify(cardData,2,2));
|
console.log("cardData: " + JSON.stringify(cardData,2,2));
|
||||||
if (global.isProd) {
|
ga('send', 'event', 'card', 'generate', cardData.type);
|
||||||
ga('send', 'event', 'card', 'generate', cardData.type);
|
|
||||||
}
|
|
||||||
fillCard(card, cardData);
|
fillCard(card, cardData);
|
||||||
redrawCards();
|
redrawCards();
|
||||||
card.show();
|
card.show();
|
||||||
@ -566,6 +565,10 @@
|
|||||||
//############################################################################################################################
|
//############################################################################################################################
|
||||||
|
|
||||||
function initGoogleAnalytics() {
|
function initGoogleAnalytics() {
|
||||||
|
if (global.isDev) {
|
||||||
|
this.ga = function(){ console.log("GoogleAnalytics: " + Object.keys(arguments).map(key => arguments[key]))}
|
||||||
|
return;
|
||||||
|
}
|
||||||
// <GoogleAnalytics>
|
// <GoogleAnalytics>
|
||||||
(function(i, s, o, g, r, a, m) {
|
(function(i, s, o, g, r, a, m) {
|
||||||
i['GoogleAnalyticsObject'] = r;
|
i['GoogleAnalyticsObject'] = r;
|
||||||
@ -620,7 +623,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function writeCookie(name, value) {
|
function writeCookie(name, value) {
|
||||||
document.cookie = name + "=" + value;
|
document.cookie = name + "=" + value + "; path=/";
|
||||||
}
|
}
|
||||||
|
|
||||||
function httpGetCORS(){
|
function httpGetCORS(){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user