Fix bug with screenshot dropdown: scroll down on the board view and focus lost when clicking on the drop zone

This commit is contained in:
Frederic Guillot
2015-07-18 15:48:37 -04:00
parent 1891258acd
commit 649c14789e
4 changed files with 96 additions and 45 deletions

View File

@@ -15,3 +15,5 @@
<?= $this->url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?> <?= $this->url->link(t('cancel'), 'task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), false, 'close-popover') ?>
</div> </div>
</form> </form>
<p class="alert alert-info"><?= t('This feature does not work with all browsers.') ?></p>

File diff suppressed because one or more lines are too long

View File

@@ -39,7 +39,7 @@ var Kanboard = (function() {
$("body").append('<div id="popover-container"><div id="popover-content">' + content + '</div></div>'); $("body").append('<div id="popover-container"><div id="popover-content">' + content + '</div></div>');
$("#popover-container").click(function() { $("#popover-container").click(function() {
$(this).remove(); Kanboard.ClosePopover();
}); });
$("#popover-content").click(function(e) { $("#popover-content").click(function(e) {
@@ -48,11 +48,11 @@ var Kanboard = (function() {
$(".close-popover").click(function(e) { $(".close-popover").click(function(e) {
e.preventDefault(); e.preventDefault();
$('#popover-container').remove(); Kanboard.ClosePopover();
}); });
Mousetrap.bindGlobal("esc", function() { Mousetrap.bindGlobal("esc", function() {
$('#popover-container').remove(); Kanboard.ClosePopover();
}); });
if (callback) { if (callback) {
@@ -61,6 +61,11 @@ var Kanboard = (function() {
}); });
}, },
ClosePopover: function() {
$('#popover-container').remove();
Kanboard.Screenshot.Destroy();
},
// Return true if the page is visible // Return true if the page is visible
IsVisible: function() { IsVisible: function() {

View File

@@ -5,22 +5,59 @@ Kanboard.Screenshot = (function() {
// Setup event listener and workarounds // Setup event listener and workarounds
function init() function init()
{ {
destroy();
if (! window.Clipboard) { if (! window.Clipboard) {
// Create a contenteditable element // Create a contenteditable element
pasteCatcher = document.createElement("div"); pasteCatcher = document.createElement("div");
pasteCatcher.setAttribute("contenteditable", ""); pasteCatcher.id = "screenshot-pastezone";
pasteCatcher.style.opacity = 0; pasteCatcher.contentEditable = "true";
document.body.appendChild(pasteCatcher);
// Make sure it is always in focus // Insert the content editable at the top to avoid scrolling down in the board view
pasteCatcher.style.opacity = 0;
pasteCatcher.style.position = "fixed";
pasteCatcher.style.top = 0;
pasteCatcher.style.right = 0;
pasteCatcher.style.width = 0;
document.body.insertBefore(pasteCatcher, document.body.firstChild);
// Set focus on the contenteditable element
pasteCatcher.focus(); pasteCatcher.focus();
document.addEventListener("click", function() { pasteCatcher.focus(); });
// Set the focus when clicked anywhere in the document
document.addEventListener("click", setFocus);
// Set the focus when clicked in screenshot dropzone (popover)
document.getElementById("screenshot-zone").addEventListener("click", setFocus);
} }
window.addEventListener("paste", pasteHandler); window.addEventListener("paste", pasteHandler);
} }
// Set focus on the contentEditable element
function setFocus()
{
if (pasteCatcher !== null) {
pasteCatcher.focus();
}
}
// Destroy contenteditable
function destroy()
{
if (pasteCatcher != null) {
document.body.removeChild(pasteCatcher);
}
else if (document.getElementById("screenshot-pastezone")) {
document.body.removeChild(document.getElementById("screenshot-pastezone"));
}
document.removeEventListener("click", setFocus);
pasteCatcher = null;
}
// Paste event callback // Paste event callback
function pasteHandler(e) function pasteHandler(e)
{ {
@@ -60,7 +97,6 @@ Kanboard.Screenshot = (function() {
function checkInput() function checkInput()
{ {
var child = pasteCatcher.childNodes[0]; var child = pasteCatcher.childNodes[0];
pasteCatcher.innerHTML = "";
if (child) { if (child) {
// If the user pastes an image, the src attribute // If the user pastes an image, the src attribute
@@ -69,6 +105,8 @@ Kanboard.Screenshot = (function() {
createImage(child.src); createImage(child.src);
} }
} }
pasteCatcher.innerHTML = "";
} }
// Creates a new image from a given source // Creates a new image from a given source
@@ -84,9 +122,13 @@ Kanboard.Screenshot = (function() {
$("input[name=screenshot]").val(sourceString); $("input[name=screenshot]").val(sourceString);
}; };
document.getElementById("screenshot-inner").style.display = "none"; var zone = document.getElementById("screenshot-zone");
document.getElementById("screenshot-zone").className = "screenshot-pasted"; zone.innerHTML = "";
document.getElementById("screenshot-zone").appendChild(pastedImage); zone.className = "screenshot-pasted";
zone.appendChild(pastedImage);
destroy();
init();
} }
jQuery(document).ready(function() { jQuery(document).ready(function() {
@@ -97,6 +139,7 @@ Kanboard.Screenshot = (function() {
}); });
return { return {
Init: init Init: init,
Destroy: destroy
}; };
})(); })();