Update bookmarklet.js
replace $ with jQuery
This commit is contained in:
parent
4c573d3035
commit
38c8621481
@ -1,5 +1,7 @@
|
|||||||
loadScripts(function(){
|
loadScripts(function(){
|
||||||
appendScript("//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js", false);
|
if (window.jQuery === undefined) {
|
||||||
|
appendScript("//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js", false);
|
||||||
|
}
|
||||||
},function(){
|
},function(){
|
||||||
addGoogleAnalytics();
|
addGoogleAnalytics();
|
||||||
init();
|
init();
|
||||||
@ -13,7 +15,7 @@ function main(){
|
|||||||
printScopeDeviderToken1 = "~~~~~";
|
printScopeDeviderToken1 = "~~~~~";
|
||||||
printScopeDeviderToken2 = "<b>Attachment</b>"
|
printScopeDeviderToken2 = "<b>Attachment</b>"
|
||||||
|
|
||||||
if($("#card-print-overlay").length > 0){
|
if(jQuery("#card-print-overlay").length > 0){
|
||||||
alert("Print Card already opened!");
|
alert("Print Card already opened!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -37,47 +39,47 @@ function main(){
|
|||||||
|
|
||||||
function open(issueKeyList) {
|
function open(issueKeyList) {
|
||||||
|
|
||||||
$(document).keyup(function(e) {
|
jQuery(document).keyup(function(e) {
|
||||||
if (e.keyCode == 27) { // esc
|
if (e.keyCode == 27) { // esc
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("head").append(newPrintOverlayStyle);
|
jQuery("head").append(newPrintOverlayStyle);
|
||||||
$("body").append(newPrintOverlayHTML);
|
jQuery("body").append(newPrintOverlayHTML);
|
||||||
|
|
||||||
var printFrame = $("#card-print-dialog-content-iframe");
|
var printFrame = jQuery("#card-print-dialog-content-iframe");
|
||||||
var printWindow = printFrame[0].contentWindow;
|
var printWindow = printFrame[0].contentWindow;
|
||||||
var printDocument = printWindow.document;
|
var printDocument = printWindow.document;
|
||||||
|
|
||||||
printDocument.open();
|
printDocument.open();
|
||||||
printDocument.write("<head/><body/>");
|
printDocument.write("<head/><body/>");
|
||||||
|
|
||||||
$("head", printDocument).append(newPrintPanelPageCSS());
|
jQuery("head", printDocument).append(newPrintPanelPageCSS());
|
||||||
$("head", printDocument).append(newPrintPanelCardCSS());
|
jQuery("head", printDocument).append(newPrintPanelCardCSS());
|
||||||
|
|
||||||
console.logInfo("load " + issueKeyList.length + " issues...");
|
console.logInfo("load " + issueKeyList.length + " issues...");
|
||||||
$("#card-print-dialog-title").text("Card Print - Loading... " + 0 + " / " + issueKeyList.length);
|
jQuery("#card-print-dialog-title").text("Card Print - Loading... " + 0 + " / " + issueKeyList.length);
|
||||||
var deferredList = [];
|
var deferredList = [];
|
||||||
issueKeyList.each(function(position, issueKey) {
|
issueKeyList.each(function(position, issueKey) {
|
||||||
var card = newCardHTML(issueKey);
|
var card = newCardHTML(issueKey);
|
||||||
card.hide();
|
card.hide();
|
||||||
$("body", printDocument).append(card);
|
jQuery("body", printDocument).append(card);
|
||||||
var deferred = new $.Deferred()
|
var deferred = new jQuery.Deferred()
|
||||||
deferredList.push(deferred);
|
deferredList.push(deferred);
|
||||||
loadCardDataJSON(issueKey, function(responseData) {
|
loadCardDataJSON(issueKey, function(responseData) {
|
||||||
fillCardWithJSONData(card, responseData);
|
fillCardWithJSONData(card, responseData);
|
||||||
card.show();
|
card.show();
|
||||||
resizeIframe(printFrame);
|
resizeIframe(printFrame);
|
||||||
$("#card-print-dialog-title").text("Card Print - Loading... " + (position + 1) + " / " + issueKeyList.length);
|
jQuery("#card-print-dialog-title").text("Card Print - Loading... " + (position + 1) + " / " + issueKeyList.length);
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
console.logInfo("wait for issues loaded...");
|
console.logInfo("wait for issues loaded...");
|
||||||
|
|
||||||
$.when.apply($, deferredList).done(function() {
|
jQuery.when.apply(jQuery, deferredList).done(function() {
|
||||||
$(printWindow).load(function(){
|
jQuery(printWindow).load(function(){
|
||||||
$("#card-print-dialog-title").text("Card Print");
|
jQuery("#card-print-dialog-title").text("Card Print");
|
||||||
console.logInfo("everything loaded!");
|
console.logInfo("everything loaded!");
|
||||||
printWindow.print();
|
printWindow.print();
|
||||||
})
|
})
|
||||||
@ -88,26 +90,26 @@ function open(issueKeyList) {
|
|||||||
|
|
||||||
function close(){
|
function close(){
|
||||||
console.logInfo("close overlay");
|
console.logInfo("close overlay");
|
||||||
$("#card-print-overlay").remove();
|
jQuery("#card-print-overlay").remove();
|
||||||
$("#card-print-overlay-style").remove();
|
jQuery("#card-print-overlay-style").remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getSelectedIssueKeyList() {
|
function getSelectedIssueKeyList() {
|
||||||
|
|
||||||
//JIRA
|
//JIRA
|
||||||
if ($("meta[name='application-name'][ content='JIRA']").length > 0) {
|
if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) {
|
||||||
//Browse
|
//Browse
|
||||||
if (/.*\/browse\/.*/g.test(document.URL)) {
|
if (/.*\/browse\/.*/g.test(document.URL)) {
|
||||||
return $("a[data-issue-key][id='key-val']").map(function() {
|
return jQuery("a[data-issue-key][id='key-val']").map(function() {
|
||||||
return $(this).attr('data-issue-key');
|
return jQuery(this).attr('data-issue-key');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// RapidBoard
|
// RapidBoard
|
||||||
if (/.*\/secure\/RapidBoard.jspa.*/g.test(document.URL)) {
|
if (/.*\/secure\/RapidBoard.jspa.*/g.test(document.URL)) {
|
||||||
return $('div[data-issue-key].ghx-selected').map(function() {
|
return jQuery('div[data-issue-key].ghx-selected').map(function() {
|
||||||
return $(this).attr('data-issue-key');
|
return jQuery(this).attr('data-issue-key');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,14 +240,14 @@ function loadCardDataJSON(issueKey, callback, async) {
|
|||||||
var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names';
|
var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names';
|
||||||
console.logInfo("IssueUrl: " + window.location.hostname + url);
|
console.logInfo("IssueUrl: " + window.location.hostname + url);
|
||||||
console.logDebug("Issue: " + issueKey + " Loading...");
|
console.logDebug("Issue: " + issueKey + " Loading...");
|
||||||
return $.ajax({
|
return jQuery.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
url: url,
|
url: url,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(responseData){
|
success: function(responseData){
|
||||||
fields = responseData.fields;
|
fields = responseData.fields;
|
||||||
// add custom fields with field names
|
// add custom fields with field names
|
||||||
$.each(responseData.names, function(key, value) {
|
jQuery.each(responseData.names, function(key, value) {
|
||||||
if(key.startsWith("customfield_")){
|
if(key.startsWith("customfield_")){
|
||||||
var newFieldId = value.toCamelCase();
|
var newFieldId = value.toCamelCase();
|
||||||
console.logTrace("add new field: " + newFieldId +" with value from "+ key);
|
console.logTrace("add new field: " + newFieldId +" with value from "+ key);
|
||||||
@ -270,7 +272,7 @@ function loadCardDataJSON(issueKey, callback, async) {
|
|||||||
// http://www.cssdesk.com/T9hXg
|
// http://www.cssdesk.com/T9hXg
|
||||||
|
|
||||||
function newPrintOverlayHTML(){
|
function newPrintOverlayHTML(){
|
||||||
var result = $(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() {
|
||||||
/*!
|
/*!
|
||||||
@ -292,7 +294,7 @@ function newPrintOverlayHTML(){
|
|||||||
|
|
||||||
result.find("#card-print-dialog-print")
|
result.find("#card-print-dialog-print")
|
||||||
.click(function(event){
|
.click(function(event){
|
||||||
$('#card-print-dialog-content-iframe')[0].contentWindow.print();
|
jQuery('#card-print-dialog-content-iframe')[0].contentWindow.print();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -316,7 +318,7 @@ function newPrintOverlayHTML(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function newPrintOverlayStyle(){
|
function newPrintOverlayStyle(){
|
||||||
var result = $(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() {
|
||||||
@ -417,7 +419,7 @@ function newPrintOverlayStyle(){
|
|||||||
|
|
||||||
function newPrintPanelPageCSS(){
|
function newPrintPanelPageCSS(){
|
||||||
|
|
||||||
var result = $(document.createElement('style'))
|
var result = jQuery(document.createElement('style'))
|
||||||
.attr("id", "printPanelPageStyle")
|
.attr("id", "printPanelPageStyle")
|
||||||
.attr("type", "text/css")
|
.attr("type", "text/css")
|
||||||
.html(multilineString(function() {
|
.html(multilineString(function() {
|
||||||
@ -487,7 +489,7 @@ function newPrintPanelPageCSS(){
|
|||||||
// http://www.cssdesk.com/scHcP
|
// http://www.cssdesk.com/scHcP
|
||||||
|
|
||||||
function newCardHTML(issueKey){
|
function newCardHTML(issueKey){
|
||||||
var card = $(document.createElement('div'))
|
var card = jQuery(document.createElement('div'))
|
||||||
.attr("id",issueKey)
|
.attr("id",issueKey)
|
||||||
.addClass("page")
|
.addClass("page")
|
||||||
.html(multilineString(function() {
|
.html(multilineString(function() {
|
||||||
@ -528,7 +530,7 @@ function newCardHTML(issueKey){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function newPrintPanelCardCSS(){
|
function newPrintPanelCardCSS(){
|
||||||
var result = $(document.createElement('style'))
|
var result = jQuery(document.createElement('style'))
|
||||||
.attr("type", "text/css")
|
.attr("type", "text/css")
|
||||||
.html(multilineString(function() {
|
.html(multilineString(function() {
|
||||||
/*!
|
/*!
|
||||||
@ -817,14 +819,14 @@ function appendScript(src, async) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
loadLoggingFunctions();
|
//jQuery Extention
|
||||||
loadStringFunctions();
|
jQuery.expr[':']['is'] = function(node, index, props){
|
||||||
|
|
||||||
|
|
||||||
$.expr[':']['is'] = function(node, index, props){
|
|
||||||
return node.textContent == props[3];
|
return node.textContent == props[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadLoggingFunctions();
|
||||||
|
loadStringFunctions();
|
||||||
|
|
||||||
Date.prototype.format = function(format) {
|
Date.prototype.format = function(format) {
|
||||||
var returnStr = '';
|
var returnStr = '';
|
||||||
var replace = Date.replaceChars;
|
var replace = Date.replaceChars;
|
||||||
@ -1019,11 +1021,11 @@ function generateHTMLWithAbsolutePathes(html) {
|
|||||||
return (link.protocol + "//" + link.host + link.pathname + link.search + link.hash);
|
return (link.protocol + "//" + link.host + link.pathname + link.search + link.hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
$(html).find('[href]').not('[href^="http"],[href^="https"],[href^="mailto:"],[href^="#"]').each(function() {
|
jQuery(html).find('[href]').not('[href^="http"],[href^="https"],[href^="mailto:"],[href^="#"]').each(function() {
|
||||||
$(this).attr('href', absoultePath);
|
jQuery(this).attr('href', absoultePath);
|
||||||
});
|
});
|
||||||
$(html).find('[src]').not('[src^="http"],[src^="https"]').each(function() {
|
jQuery(html).find('[src]').not('[src^="http"],[src^="https"]').each(function() {
|
||||||
$(this).attr('src', absoultePath);
|
jQuery(this).attr('src', absoultePath);
|
||||||
});
|
});
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user