Skip to content

Commit

Permalink
New JS code to handle window behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Jan 10, 2024
1 parent b899ddb commit 65d3dd7
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 58 deletions.
12 changes: 10 additions & 2 deletions modules/analyze/html/adalanche.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ body {

.window {
pointer-events: auto;
box-sizing: border-box;
display: inline-flex;
flex-direction: column;
}

.window-wrapper {
overflow: auto;
}

.window-content {
}

.window-front {
Expand Down Expand Up @@ -158,8 +168,6 @@ body {
z-index: 40;
}



#outerquery {
position: absolute;
left: 50%;
Expand Down
143 changes: 89 additions & 54 deletions modules/analyze/html/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,75 +73,118 @@ function set_querymode(mode) {
} else if (mode == 'sourcetarget') {
$('#querymode_sourcetarget').prop('checked', true).change();
}
// $('#querymode_normal').prop('checked', mode == 'normal').change();
// $('#querymode_reverse').prop('checked', mode == 'reverse').change();
// $('#querymode_sourcetarget').prop('checked', mode == 'sourcetarget').change();
}

function dragMoveListener(event) {
var target = event.target,
// keep the dragged position in the data-x/data-y attributes
x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;

// translate the element
target.style.webkitTransform =
target.style.transform =
'translate(' + x + 'px, ' + y + 'px)';

// update the posiion attributes
target.setAttribute('data-x', x);
target.setAttribute('data-y', y);

if (!target.classList.contains('window-front')) {
console.log($('.window-front'));
$('.window-front').removeClass('window-front');
console.log($('.window-front'));
target.classList.add('window-front');
}
}

function newwindow(id, title, content, height, width) {
// Other windows are not in from
$('#windows div').removeClass('window-front');
// Other windows are not in front
console.log($('.window-front'));
$('.window-front').removeClass('window-front');
console.log($('.window-front'));

var mywindow = $(`#windows #window_${id}`);
var itsnew = false;

var maxheight = $(window).height() * 0.9;
var maxheight = $(window).height() * 0.8;
var maxwidth = $(window).width() * 0.6;

// add the new one
if (mywindow.length == 0) {
mywindow = $(
`<div class="window bg-dark d-inline-block position-absolute shadow border pointer-events-auto window-front" id="window_${id}">
<div class="s ui-resizable-handle ui-resizable-s"></div>
<div class="e ui-resizable-handle ui-resizable-e"></div>
<div class="se ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se"></div>
<div id='header' class='mb-1 bg-primary text-dark p-1'>
<span id="title" class="col">${title}</span><span id="close" class="border float-end cursor-pointer">X</span>
`<div class="window bg-dark shadow border pointer-events-auto window-front" id="window_${id}">
<div id='header' class='window-header mb-1 bg-primary text-dark p-1'>
<span id="title" class="col">${title}</span><span id="close" class="border float-end cursor-pointer">X</span>
</div>
<div class="window-wrapper">
<div class="window-content p-1" id="contents">${content}</div>
</div>
<div class="overflow-auto p-1" id="contents">${content}</div>
</div>`
);

$('#windows').append(mywindow);

// roll up
// $('#rollup', mywindow).click(function (event) {
// $('#rollup-wrapper', $(this).parents('.window')).slideToggle('slow', 'swing');
// });

// closing
$('#close', mywindow).click(function (event) {
$(this).parents('.window').remove();
});

mywindow.draggable({
scroll: false,
cancel: '#contents',
});

mywindow.resizable({
containment: '#windows',
handles: {
'se': '.se',
'e': '.e',
's': '.s',
},
create: function (event, ui) {
// ui has no data
console.log("window created");
},
resize: function (event, ui) {
console.log(event);
$('#contents', ui.element).width(ui.size.width-12);
$('#contents', ui.element).height(ui.size.height-$('#header', ui.element).height()-24);
},

maxHeight: maxheight,
maxWidth: maxwidth,
minHeight: 150,
minWidth: 200,
});
interact("#window_" + id)
.origin('parent')
.resizable({
edges: { left: true, right: true, bottom: true, top: true },
margin: 5,
listeners: {
move(event) {
var target = event.target
var x = (parseFloat(target.getAttribute('data-x')) || 0)
var y = (parseFloat(target.getAttribute('data-y')) || 0)

// update the element's style
target.style.width = event.rect.width + 'px'
target.style.height = event.rect.height + 'px'

if (!target.classList.contains('window-front')) {
$('.window-front').removeClass('window-front');
target.classList.add('window-front');
}

// translate when resizing from top or left edges
x += event.deltaRect.left
y += event.deltaRect.top

target.style.transform = 'translate(' + x + 'px,' + y + 'px)'

target.setAttribute('data-x', x)
target.setAttribute('data-y', y)
}
},
modifiers: [
// keep the edges inside the parent
interact.modifiers.restrictEdges({
outer: 'parent'
}),

// min and max size
interact.modifiers.restrictSize({
min: { width: 200, height: 150 },
max: { width: maxwidth, height: maxheight },
})
],

inertia: true
})
.draggable({
onmove : window.dragMoveListener,
modifiers: [
interact.modifiers.restrictRect({
restriction: 'parent',
endOnly: true
})
],
allowFrom: '.window-header',
})

if (height) {
mywindow.height(height);
Expand All @@ -157,18 +200,10 @@ function newwindow(id, title, content, height, width) {
mywindow.width(maxwidth)
}

// Fix initial content size

if ($('#contents', mywindow).width() > maxwidth-12) {
$('#contents', mywindow).width(maxwidth-12);
}

if ($('#contents', mywindow).height() > maxheight-$('#header', mywindow).height()-24) {
$('#contents', mywindow).height(maxheight-$('#header', mywindow).height()-24);
}
} else {
$('#title', mywindow).html(title);
$('#contents', mywindow).html(content);
mywindow.addClass('window-front');
}

// Bring to front on mouse down
Expand Down
4 changes: 4 additions & 0 deletions modules/analyze/html/external/interact.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions modules/analyze/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<script src="external/jquery-3.7.1.min.js"></script>
<script src="external/popper.min.js"></script>
<script src="external/tippy.min.js"></script>
<script src="external/jquery-ui-1.13.2.custom/jquery-ui.min.js"></script>
<script src="external/interact.min.js"></script>
<!-- <script src="external/jquery-ui-1.13.2.custom/jquery-ui.min.js"></script> -->
<script src="external/jstree/jstree.min.js"></script>
<script src="external/autosize.js"></script>

Expand Down Expand Up @@ -61,7 +62,7 @@
</head>

<body class="z-0">
<div id="windows" class="position-absolute">
<div id="windows">
<div class="sticky-alerts"></div>
</div>

Expand Down

0 comments on commit 65d3dd7

Please sign in to comment.