Skip to content

Instantly share code, notes, and snippets.

@jkrehm
Last active August 29, 2015 14:20
Show Gist options
  • Save jkrehm/86000f234ba52ca38a2c to your computer and use it in GitHub Desktop.
Save jkrehm/86000f234ba52ca38a2c to your computer and use it in GitHub Desktop.
DraggableJiraDialogs.js
// Requires Chrome and the Control Freak (https://chrome.google.com/webstore/detail/control-freak/jgnchehlaggacipokckdlbdemfeohdhc) extension
/* Libs:
- https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
- https://cdnjs.cloudflare.com/ajax/libs/draggabilly/1.2.0/draggabilly.pkgd.min.js
- https://cdn.rawgit.com/meetselva/attrchange/d3f8524374b0ad11f320b51f7b188ae940314dba/js/attrchange.js
*/
// Make dialogs draggable
$(function () {
$('body').css('position', 'relative');
$('#create_link, .toolbar-item a').click(function () {
setTimeout(function () {
$('.jira-dialog').each(function () {
var $dialog = $(this);
var isDraggable = ($dialog.data('draggabilly') !== undefined);
var top = Math.floor($(window).height()/2 + $(document).scrollTop() - $dialog.height()/2 - 1);
$dialog.css({
'margin-top' : 0,
'overflow-y' : 'auto',
'top' : top,
});
if (!isDraggable) {
$dialog
.draggabilly({
handle : '.jira-dialog-heading'
})
.css('position', 'absolute')
.attrchange({
trackValues : true,
callback : attributeChanged,
});
}
});
}, 250);
});
});
function attributeChanged(event) {
if (event.attributeName === 'style' && event.newValue.indexOf('margin-top') > -1) {
var margin = event.newValue.match(/margin-top: (.+?)px/);
// Intentionally do non-strict check of margin value
if (margin !== null && margin[1] != 0) {
$(event.target).css('margin-top', 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment