Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This is a <a href="http://en.wikipedia.org/wiki/Bookmarklet">bookmarklet</a> you
- FogBugz cases
- JIRA issues
- GitHub issues and commits
- UserVoice tickets
- The selected text from an arbitrary URL
- ... more? I'm happy to take pull requests that add support for other websites!

Expand Down
82 changes: 52 additions & 30 deletions trello_bookmarklet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
(function(window){
var $;
var jQuery_page;
var jQuery_trello_bookmarklet;

// Keep track of the jQuery included in the page
$ = window.$ = jQuery_page = window.jQuery;

var get_est_jira_time = function() {
var jira_time = $('#tt_single_values_orig').text().trim();
Expand Down Expand Up @@ -58,6 +63,15 @@
// we're looking at an email in Gmail
name = $('h1 .hP').text().trim();

} else if ($('body[uv-sheet-container]').length) {

// We're looking at UserVoice tickets
var ticket_number_regex = /.*\/admin\/tickets\/(\d+).*/;
var ticket_number = ticket_number_regex.exec(location.href);
name = "#" + ticket_number[1] + " " + $('h1.ticket-subject-header').text().trim();
desc = "Link to Ticket: " + location.href;
desc += "\nReported by: " + window.currentSupportAgent.displayName;

}

else {
Expand Down Expand Up @@ -101,33 +115,37 @@

// Create the card
if(name) {
Trello.post("lists/" + idList + "/cards", {
name: name,
desc: desc
}, function(card){
// Display a little notification in the upper-left corner with a link to the card
// that was just created
var $cardLink = $("<a>")
.attr({
href: card.url,
target: "card"
})
.text("Created a Trello Card")
.css({
position: "absolute",
left: 0,
top: 0,
padding: "4px",
border: "1px solid #000",
background: "#fff",
"z-index": 1e3
})
.appendTo("body")
// Use newer (2.x) jQuery version to avoid CORS errors
(function(jQuery) {
Trello.post("lists/" + idList + "/cards", {
name: name,
desc: desc
}, function(card){
// Display a little notification in the upper-left corner with a link to the card
// that was just created
var $cardLink = $("<a>")
.attr({
href: card.url,
target: "card"
})
.text("Created a Trello Card")
.css({
position: "absolute",
left: 0,
top: 0,
padding: "4px",
border: "1px solid #000",
background: "#fff",
"z-index": 1e3
})
.appendTo("body")

setTimeout(function(){
$cardLink.fadeOut(3000);
}, 5000)
})
setTimeout(function(){
$cardLink.fadeOut(3000);
}, 5000)
})
$ = window.$ = window.jQuery = jQuery_page;
}(jQuery_trello_bookmarklet))
}
}

Expand Down Expand Up @@ -232,19 +250,21 @@
waterfall([
// Load jQuery
function(next) {
if(window.jQuery) {
if (parseInt(window.jQuery.fn.jquery.split(".")[0]) >= 2) {
jQuery_trello_bookmarklet = $;
next(null);
} else {
var script = document.createElement("script");
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js";
script.onload = next;
script.onreadystatechange = next;
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName("head")[0].appendChild(script);

jQuery_trello_bookmarklet = jQuery.noConflict(true);
}
},
// Get the user's App Key, either from local storage, or by prompting them to retrieve it
function(ev, next) {
$ = window.jQuery;

var appKey = store(appKeyName) || window[appKeyName];
if(appKey && appKey.length == 32) {
next(appKey);
Expand Down Expand Up @@ -314,4 +334,6 @@
// Run the user portion
run
]);
// Reset jQuery to the version included in the page
$ = window.$ = window.jQuery = jQuery_page;
})(window);