Merge pull request #4 from qoomon/develop

Google Analytix
This commit is contained in:
Bengt Brodersen 2015-01-28 01:13:18 +01:00
commit de3e3e6100

View File

@ -1,28 +1,36 @@
var qoomon_dev; version = "3.1.7";
var isDev = qoomon_dev; console.logInfo("Version: " + version);
// <GoogleAnalytics> // <GoogleAnalytics>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (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), (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) 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'); })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-50840116-3', 'auto', {'alwaysSendReferrer': true}); ga('create', 'UA-50840116-3', 'auto');
ga('send', {'hitType': 'pageview', 'page': '/jiracardprinter/Bookmarklet.js'}); ga('set', 'location', window.location.protocol + '//' + window.location.host + window.location.pathname);
ga('set', 'hostname', window.location.hostname);
ga('set', 'page', '/cardprinter');
ga('set', 'title', document.title);
//ga('set', 'campaignSource', '(direct)');
//ga('set', 'campaignMedium', '(none)');
// </GoogleAnalytics> // </GoogleAnalytics>
// load jQuery try {
if (window.jQuery === undefined) { var qoomon_dev;
appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'); var isDev = qoomon_dev;
}
// wait untill all scripts loaded // load jQuery
appendScript('https://qoomon.github.io/void', function(){ 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(); init();
main(); main();
}); });
function init(){ function init(){
addJQueryFunctions(); addJQueryFunctions();
addConsoleFunctions(); addConsoleFunctions();
addStringFunctions(); addStringFunctions();
@ -41,9 +49,9 @@ function init(){
//$("#card").load("https://cors-anywhere.herokuapp.com/"+"https://qoomon.github.io/Jira-Issue-Card-Printer/card.html"); //$("#card").load("https://cors-anywhere.herokuapp.com/"+"https://qoomon.github.io/Jira-Issue-Card-Printer/card.html");
console.logLevel = console.INFO; console.logLevel = console.INFO;
} }
function main(){ function main(){
//preconditions //preconditions
if(jQuery("#card-print-overlay").length > 0){ if(jQuery("#card-print-overlay").length > 0){
alert("Print Card already opened!"); alert("Print Card already opened!");
@ -51,6 +59,7 @@ function main(){
} }
var issueKeyList = getSelectedIssueKeyList(); var issueKeyList = getSelectedIssueKeyList();
if(issueKeyList.length <= 0){ if(issueKeyList.length <= 0){
alert("Please select at least one issue."); alert("Please select at least one issue.");
return; return;
@ -60,14 +69,21 @@ function main(){
jQuery("body").append(printOverlayHTML); jQuery("body").append(printOverlayHTML);
jQuery("#card-print-overlay").prepend(printOverlayStyle); jQuery("#card-print-overlay").prepend(printOverlayStyle);
ga('send', 'pageview');
jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues..."); jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues...");
renderCards(issueKeyList, function(){ renderCards(issueKeyList, function(){
jQuery("#card-print-dialog-title").text("Card Print"); jQuery("#card-print-dialog-title").text("Card Print");
jQuery('#card-print-dialog-content-iframe')[0].contentWindow.print(); print();
}); });
} }
function renderCards(issueKeyList, callback) { function print(){
ga('send', 'event', 'button', 'click', 'print', $(".card").length );
jQuery('#card-print-dialog-content-iframe')[0].contentWindow.print();
}
function renderCards(issueKeyList, callback) {
var printFrame = jQuery("#card-print-dialog-content-iframe"); var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow; var printWindow = printFrame[0].contentWindow;
@ -107,15 +123,15 @@ function renderCards(issueKeyList, callback) {
printDocument.close(); printDocument.close();
console.logInfo("wait for resources loaded..."); console.logInfo("wait for resources loaded...");
}); });
} }
function closePrintPreview(){ function closePrintPreview(){
jQuery("#card-print-overlay").remove(); jQuery("#card-print-overlay").remove();
jQuery("#card-print-overlay-style").remove(); jQuery("#card-print-overlay-style").remove();
} }
function getSelectedIssueKeyList() { function getSelectedIssueKeyList() {
//JIRA //JIRA
if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) { if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) {
@ -135,9 +151,9 @@ function getSelectedIssueKeyList() {
} }
return []; return [];
} }
function fillCardWithJSONData(card, data) { function fillCardWithJSONData(card, data) {
//Key //Key
var key = data.key; var key = data.key;
console.logDebug("key: " + key); console.logDebug("key: " + key);
@ -281,21 +297,21 @@ function fillCardWithJSONData(card, data) {
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
// http://www.cssdesk.com/T9hXg // http://www.cssdesk.com/T9hXg
function printOverlayHTML(){ function printOverlayHTML(){
var result = jQuery(document.createElement('div')) var result = jQuery(document.createElement('div'))
.attr("id","card-print-overlay") .attr("id","card-print-overlay")
.html(multilineString(function() { .html(multilineString(function() {
/*! /*!
<div id="card-print-dialog"> <div id="card-print-dialog">
<div id="card-print-dialog-header"> <div id="card-print-dialog-header">
<div id="card-print-dialog-title">Card Print</div> <div id="card-print-dialog-title">Card Print</div>
<div id="info"> <div id="info">
@ -311,8 +327,8 @@ function printOverlayHTML(){
<iframe id="card-print-dialog-content-iframe"></iframe> <iframe id="card-print-dialog-content-iframe"></iframe>
</div> </div>
<div id="card-print-dialog-footer"></div> <div id="card-print-dialog-footer"></div>
</div> </div>
*/ */
})); }));
// info // info
@ -332,7 +348,7 @@ function printOverlayHTML(){
result.find("#card-print-dialog-print") result.find("#card-print-dialog-print")
.click(function(event){ .click(function(event){
jQuery('#card-print-dialog-content-iframe')[0].contentWindow.print(); print();
return false; return false;
}); });
@ -363,15 +379,15 @@ function printOverlayHTML(){
}); });
return result; return result;
} }
function printOverlayStyle(){ function printOverlayStyle(){
var result = jQuery(document.createElement('style')) var result = jQuery(document.createElement('style'))
.attr("id", "card-print-overlay-style") .attr("id", "card-print-overlay-style")
.attr("type", "text/css") .attr("type", "text/css")
.html(multilineString(function() { .html(multilineString(function() {
/*! /*!
#card-print-overlay { #card-print-overlay {
position: fixed; position: fixed;
height: 100%; height: 100%;
width: 100%; width: 100%;
@ -383,9 +399,9 @@ function printOverlayStyle(){
word-wrap:break-word; word-wrap:break-word;
z-index: 99999; z-index: 99999;
} }
#card-print-dialog { #card-print-dialog {
position: relative; position: relative;
top: 60px; top: 60px;
@ -404,9 +420,9 @@ function printOverlayStyle(){
border-radius: 4px; border-radius: 4px;
overflow: hidden; overflow: hidden;
} }
#card-print-dialog-header { #card-print-dialog-header {
position: relative; position: relative;
background: #f0f0f0; background: #f0f0f0;
height: 25px; height: 25px;
@ -414,50 +430,50 @@ function printOverlayStyle(){
border-bottom: 1px solid #cccccc; border-bottom: 1px solid #cccccc;
padding: 15px 20px 15px 20px; padding: 15px 20px 15px 20px;
} }
#card-print-dialog-content { #card-print-dialog-content {
position: relative; position: relative;
background: white; background: white;
height: calc(100% - 106px); + height: 100px; height: calc(100% - 106px); + height: 100px;
width: 100%; width: 100%;
overflow-y: scroll; overflow-y: scroll;
} }
#card-print-dialog-content-iframe { #card-print-dialog-content-iframe {
position: relative; position: relative;
height: 100%; height: 100%;
width: 100%; width: 100%;
border:none; border:none;
} }
#card-print-dialog-footer { #card-print-dialog-footer {
position: relative; position: relative;
background: #f0f0f0; background: #f0f0f0;
border-top: 1px solid #cccccc; border-top: 1px solid #cccccc;
height: 30px; height: 30px;
padding: 10px; padding: 10px;
text-align: right; text-align: right;
} }
#buttons { #buttons {
position: relative; position: relative;
float: right; float: right;
display: inline-block; display: inline-block;
height 30px; height 30px;
} }
#info { #info {
position: absolute; position: absolute;
right: 400px; right: 400px;
float: left; float: left;
display: inline-block; display: inline-block;
height 30px; height 30px;
} }
#card-print-dialog-title{ #card-print-dialog-title{
position: relative; position: relative;
float: left; float: left;
color: rgb(51, 51, 51); color: rgb(51, 51, 51);
@ -467,14 +483,14 @@ height: calc(100% - 106px); + height: 100px;
font-weight: normal; font-weight: normal;
height: 30px; height: 30px;
line-height: 30px; line-height: 30px;
} }
*/ */
})); }));
return result; return result;
} }
function printPanelPageCSS(){ function printPanelPageCSS(){
var result = jQuery(document.createElement('style')) var result = jQuery(document.createElement('style'))
.attr("id", "printPanelPageStyle") .attr("id", "printPanelPageStyle")
@ -530,28 +546,28 @@ function printPanelPageCSS(){
-webkit-filter:opacity(1.0); -webkit-filter:opacity(1.0);
filter:opacity(1.0); filter:opacity(1.0);
} }
.page:last-of-type { .page:last-of-type {
page-break-after: auto; page-break-after: auto;
} }
} }
*/ */
})); }));
return result; return result;
} }
// http://www.cssdesk.com/scHcP // http://www.cssdesk.com/scHcP
function newPage(issueKey){ function newPage(issueKey){
var page = jQuery(document.createElement('div')) var page = jQuery(document.createElement('div'))
.attr("id",issueKey) .attr("id",issueKey)
.addClass("page") .addClass("page")
.html(multilineString(function() { .html(multilineString(function() {
/*! /*!
<div class="card"> <div class="card">
<div class="author">Bengt Brodersen - qoomon.com</div> <div class="author">Bengt Brodersen - qoomon.com</div>
<div class="card-border"></div> <div class="card-border"></div>
<div class="card-header"> <div class="card-header">
@ -578,38 +594,38 @@ function newPage(issueKey){
<span class="epic-name" contenteditable="true"></span> <span class="epic-name" contenteditable="true"></span>
</div> </div>
</div> </div>
</div> </div>
*/ */
})); }));
return page; return page;
} }
function printPanelCardCSS(){ function printPanelCardCSS(){
var result = jQuery(document.createElement('style')) var result = jQuery(document.createElement('style'))
.attr("type", "text/css") .attr("type", "text/css")
.html(multilineString(function() { .html(multilineString(function() {
/*! /*!
* { * {
color: black; color: black;
font-family:"Droid Serif"; font-family:"Droid Serif";
} }
body { body {
margin: 0; margin: 0;
} }
.hidden { .hidden {
visibility: hidden; visibility: hidden;
} }
.card-header:after, .card-header:after,
.card-footer:after { .card-footer:after {
content:" "; content:" ";
display: block; display: block;
clear: both; clear: both;
height:0 height:0
} }
.card-border, .card-border,
.badge, .badge,
.shadow { .shadow {
border-style: solid; border-style: solid;
border-color: #2f2f2f; border-color: #2f2f2f;
border-top-width: 0.14cm; border-top-width: 0.14cm;
@ -619,24 +635,24 @@ body {
-webkit-border-radius: 0.25cm; -webkit-border-radius: 0.25cm;
border-radius: 0.25cm; border-radius: 0.25cm;
// -webkit-filter: drop-shadow(0px 5px 10px black) // -webkit-filter: drop-shadow(0px 5px 10px black)
} }
.circular { .circular {
-moz-border-radius: 50%; -moz-border-radius: 50%;
-webkit-border-radius: 50%; -webkit-border-radius: 50%;
border-radius: 50%; border-radius: 50%;
} }
.badge { .badge {
width: 3.2cm; width: 3.2cm;
height: 3.2cm; height: 3.2cm;
background: #d0d0d0; background: #d0d0d0;
} }
.card { .card {
position: relative; position: relative;
min-width: 21.0cm; min-width: 21.0cm;
} }
.author { .author {
z-index: 999; z-index: 999;
position: absolute; position: absolute;
top:3.1cm; top:3.1cm;
@ -647,8 +663,8 @@ body {
transform: rotate(-90deg); transform: rotate(-90deg);
font-size: 0.4cm; font-size: 0.4cm;
color: DARKGREY; color: DARKGREY;
} }
.card-border { .card-border {
position: absolute; position: absolute;
top:2.0cm; top:2.0cm;
left:0.4cm; left:0.4cm;
@ -656,37 +672,37 @@ body {
height: calc(100% - 4.0cm); height: calc(100% - 4.0cm);
background: #ffffff; background: #ffffff;
} }
.card-header { .card-header {
position: relative; position: relative;
} }
.card-content { .card-content {
position: relative; position: relative;
margin-top: 0.3cm; margin-top: 0.3cm;
margin-left: 1.0cm; margin-left: 1.0cm;
margin-right: 1.1cm; margin-right: 1.1cm;
margin-bottom: 0.2cm; margin-bottom: 0.2cm;
min-height: 3.0cm; min-height: 3.0cm;
} }
.content-header { .content-header {
position: relative; position: relative;
font-size: 1.1cm; font-size: 1.1cm;
line-height: 1.1cm; line-height: 1.1cm;
margin-bottom: 0.6cm; margin-bottom: 0.6cm;
} }
.card-footer { .card-footer {
position: relative; position: relative;
page-break-inside: avoid; page-break-inside: avoid;
} }
.summary { .summary {
font-weight: bold; font-weight: bold;
} }
.description { .description {
min-height: 3.0cm; min-height: 3.0cm;
font-size: 0.6cm; font-size: 0.6cm;
line-height: 0.6cm; line-height: 0.6cm;
} }
.key { .key {
position: absolute; position: absolute;
float: left; float: left;
width: auto; width: auto;
@ -700,8 +716,8 @@ body {
font-weight: bold; font-weight: bold;
font-size: 1.0cm; font-size: 1.0cm;
line-height: 1.6cm; line-height: 1.6cm;
} }
.type-icon { .type-icon {
position: relative; position: relative;
float: left; float: left;
background-color: GREENYELLOW; background-color: GREENYELLOW;
@ -711,22 +727,22 @@ body {
background-size: 70%; background-size: 70%;
background-position: center; background-position: center;
z-index: 1; z-index: 1;
} }
.card[type="story"] .type-icon { .card[type="story"] .type-icon {
background-color: GOLD; background-color: GOLD;
background-image: url(https://googledrive.com/host/0Bwgd0mVaLU_KU0N5b3JyRnJaNTA/resources/icons/Bulb.png); background-image: url(https://googledrive.com/host/0Bwgd0mVaLU_KU0N5b3JyRnJaNTA/resources/icons/Bulb.png);
} }
.card[type="bug"] .type-icon { .card[type="bug"] .type-icon {
background-color: CRIMSON; background-color: CRIMSON;
background-image: url(https://googledrive.com/host/0Bwgd0mVaLU_KU0N5b3JyRnJaNTA/resources/icons/Bug.png); background-image: url(https://googledrive.com/host/0Bwgd0mVaLU_KU0N5b3JyRnJaNTA/resources/icons/Bug.png);
} }
.card[type="epic"] .type-icon { .card[type="epic"] .type-icon {
background-color: ROYALBLUE; background-color: ROYALBLUE;
background-image: url(https://googledrive.com/host/0Bwgd0mVaLU_KU0N5b3JyRnJaNTA/resources/icons/Flash.png); background-image: url(https://googledrive.com/host/0Bwgd0mVaLU_KU0N5b3JyRnJaNTA/resources/icons/Flash.png);
} }
.estimate { .estimate {
position: relative; position: relative;
float: left; float: left;
left: -0.65cm; left: -0.65cm;
@ -739,13 +755,13 @@ body {
line-height: 1.15cm; line-height: 1.15cm;
margin-top:1.5cm; margin-top:1.5cm;
z-index: 999; z-index: 999;
} }
.due { .due {
position: relative; position: relative;
float: right; float: right;
} }
.due-icon { .due-icon {
position: relative; position: relative;
float:right; float:right;
width: 2.5cm; width: 2.5cm;
@ -758,8 +774,8 @@ body {
background-size: 65%; background-size: 65%;
background-position: center; background-position: center;
z-index: 1; z-index: 1;
} }
.due-date { .due-date {
position: relative; position: relative;
float: right; float: right;
right: -0.6cm; right: -0.6cm;
@ -775,8 +791,8 @@ body {
font-weight: bold; font-weight: bold;
font-size: 0.7cm; font-size: 0.7cm;
line-height: 0.7cm; line-height: 0.7cm;
} }
.attachment { .attachment {
position: relative; position: relative;
float: left; float: left;
margin-left: 0.6cm; margin-left: 0.6cm;
@ -789,8 +805,8 @@ body {
background-size: 70%; background-size: 70%;
background-position: center; background-position: center;
} }
.assignee { .assignee {
position: relative; position: relative;
float: right; float: right;
width: 2.1cm; width: 2.1cm;
@ -808,8 +824,8 @@ body {
-webkit-filter: contrast(150%) grayscale(100%); -webkit-filter: contrast(150%) grayscale(100%);
filter: contrast(150%) grayscale(100%); filter: contrast(150%) grayscale(100%);
background-position: center; background-position: center;
} }
.qr-code { .qr-code {
position: relative; position: relative;
float: left; float: left;
width: 2.1cm; width: 2.1cm;
@ -819,8 +835,8 @@ body {
-webkit-background-size: cover; -webkit-background-size: cover;
background-size: cover; background-size: cover;
background-position: center; background-position: center;
} }
.epic { .epic {
width: auto; width: auto;
height: auto; height: auto;
position: relative; position: relative;
@ -834,22 +850,22 @@ body {
font-size: 0.7cm; font-size: 0.7cm;
line-height: 0.7cm; line-height: 0.7cm;
max-width: calc( 100% - 10.2cm); max-width: calc( 100% - 10.2cm);
} }
.epic-key { .epic-key {
} }
.epic-name { .epic-name {
font-weight: bold; font-weight: bold;
} }
*/ */
}).replace(/{RESOURCE_ORIGIN}/g, resourceOrigin)); }).replace(/{RESOURCE_ORIGIN}/g, resourceOrigin));
return result; return result;
} }
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
function appendScript(url, callback){ function appendScript(url, callback){
var head = document.getElementsByTagName('head')[0]; var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script'); var script = document.createElement('script');
@ -861,36 +877,36 @@ function appendScript(url, callback){
script.onload = callback; script.onload = callback;
head.appendChild(script); head.appendChild(script);
} }
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
function addDeferred(deferredList){ function addDeferred(deferredList){
var deferred = new jQuery.Deferred() var deferred = new jQuery.Deferred()
deferredList.push(deferred); deferredList.push(deferred);
return deferred; return deferred;
} }
function applyDeferred(deferredList, callback){ function applyDeferred(deferredList, callback){
jQuery.when.apply(jQuery, deferredList).done(callback); jQuery.when.apply(jQuery, deferredList).done(callback);
} }
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
function addJQueryFunctions() { function addJQueryFunctions() {
//jQuery Extention //jQuery Extention
jQuery.expr[':']['is'] = function(node, index, props){ jQuery.expr[':']['is'] = function(node, index, props){
return node.textContent == props[3]; return node.textContent == props[3];
} }
} }
function addConsoleFunctions() { function addConsoleFunctions() {
console.ERROR = 0; console.ERROR = 0;
console.WARN = 1; console.WARN = 1;
@ -929,9 +945,9 @@ function addConsoleFunctions() {
console.log("TRACE: " + msg); console.log("TRACE: " + msg);
} }
} }
} }
function addStringFunctions() { function addStringFunctions() {
//trim string - remove leading and trailing whitespaces //trim string - remove leading and trailing whitespaces
if (!String.prototype.trim) { if (!String.prototype.trim) {
@ -968,9 +984,9 @@ function addStringFunctions() {
return s; return s;
} }
} }
} }
function addDateFunctions() { function addDateFunctions() {
Date.prototype.format = function(format) { Date.prototype.format = function(format) {
var returnStr = ''; var returnStr = '';
@ -985,9 +1001,9 @@ function addDateFunctions() {
} }
} }
return returnStr; return returnStr;
}; };
Date.replaceChars = { Date.replaceChars = {
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
@ -1048,15 +1064,23 @@ Date.replaceChars = {
r: function() { return this.toString(); }, r: function() { return this.toString(); },
U: function() { return this.getTimep() / 1000; } U: function() { return this.getTimep() / 1000; }
}; };
} }
function multilineString(commentFunction) { function multilineString(commentFunction) {
return commentFunction.toString() return commentFunction.toString()
.replace(/^[^\/]+\/\*!?/, '') .replace(/^[^\/]+\/\*!?/, '')
.replace(/\*\/[^\/]+$/, ''); .replace(/\*\/[^\/]+$/, '');
} }
function resizeIframe(iframe) { function resizeIframe(iframe) {
iframe.height(iframe[0].contentWindow.document.body.scrollHeight); iframe.height(iframe[0].contentWindow.document.body.scrollHeight);
}
} catch (err) {
console.logError(err.message);
ga('send', 'exception', {
'exDescription': err.message,
'exFatal': true
});
} }