Skip to content

Instantly share code, notes, and snippets.

@jackbaty
Created August 14, 2010 14:44
Show Gist options
  • Save jackbaty/524359 to your computer and use it in GitHub Desktop.
Save jackbaty/524359 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name dumpbox
// @namespace http://fluidapp.com
// @description dumps JIRA issue content into a div for easy copy/paste action
// @include *
// @author Karl Swedberg
// ==/UserScript==
(function($) {
if (window.fluid) {
/** =Change these settings to your heart's content
************************************************************/
var settings = {
// action that will trigger the content dump
event: 'dblclick',
// These "elements" are all CSS selectors used by jQuery to locate the elements
elements: {
// "container" element must be the same as, or an ancestor of, the "trigger" element.
// When the appropriate event occurs on the trigger element,
// the script looks for the "text" elements that are within the same
// "container" element as the "trigger" element
container: 'div.gh-issue-inner',
// this is the element that the event is bound to.
trigger: 'div.gh-subhead',
// array of elements (within the same container as the trigger element) from which to grab and dump text
text: ['.gh-issue-key', '.gh-issue-field div[title=Summary]']
},
// each set of text dumped into the dumpbx will be wrapped in a div.
// the following "contents" settings apply to each set of text.
contents: {
before: '* [',
between: '] ',
after: '',
idPrefix: 'dump-'
},
// settings for the dumpbox element itself
box: {
wrapper: '<div></div>',
id: 'dump-issues',
styles: {
position: 'fixed',
zIndex: 1200,
padding: '2px 10px 10px',
bottom: '0',
right: '0',
minHeight: '40px',
minWidth: '250px',
backgroundColor: '#ffc'
}
},
// settings for a "close" button in the dumpbox.
// you can set its value to null (rather than the {...}) if you don't want it
closeButton: {
wrapper: '<a href="#">X</a>',
id: 'close-dump',
styles: {
display: 'block',
'textAlign': 'right'
}
}
};
/** =The grunt work starts here
************************************************************/
var dumpBox = function(opts) {
$(opts.elements.trigger).live(opts.event, function() {
var $issue = $(this).closest(opts.elements.container),
key = $issue.find('.gh-issue-key').eq(0).text();
var msgParts = [];
$.each(opts.elements.text, function(index, val) {
msgParts.push( $issue.find(val).text() );
});
var msg = opts.contents.before + msgParts.join(opts.contents.between) + opts.contents.after;
if (!document.getElementById(opts.box.id)) {
$(opts.box.wrapper)
.attr('id', opts.box.id)
.css(opts.box.styles)
.appendTo('body');
if (opts.closeButton && opts.closeButton.wrapper) {
$(opts.closeButton.wrapper)
.attr('id', opts.closeButton.id)
.css(opts.closeButton.styles)
.prependTo('#' + opts.box.id)
.click(function(event) {
event.preventDefault();
$('#' + opts.box.id).fadeOut();
});
}
} else {
$('#' + opts.box.id).fadeIn();
}
if ($('#' + opts.contents.idPrefix + key).length) {
$(opts.contents.idPrefix + key).html(msg);
} else {
$('<div class="dump-contents"></div>').attr('id', opts.contents.idPrefix + key).html(msg).appendTo('#' + opts.box.id);
}
});
};
$(document).ready(function() {
dumpBox(settings);
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment