Skip to content

Commit

Permalink
mobile adaptation 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Lubin Pappalardo committed Oct 3, 2023
1 parent f876080 commit fa312d9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion assets/board.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

padding: 10px;

rotate: 0deg;
transform: rotate(0deg);
}

.component::after {
Expand Down
8 changes: 4 additions & 4 deletions assets/panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@
}

@keyframes pulse {
0% { scale: 1 }
50% { scale: 1.1 }
90% { scale: 0.95 }
100% { scale: 1 }
0% { transform: scale(1) }
50% { transform: scale(1.1) }
90% { transform: scale(0.95) }
100% { transform: scale(1) }
}

/* Clock frequency */
Expand Down
12 changes: 6 additions & 6 deletions assets/scripts/board-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ $(document).on('mousemove', function (e) {
x: BoardLastDraggingDistance.x + distanceX,
y: BoardLastDraggingDistance.y + distanceY,
}
$('.board-container').css('transform', `translate(${BoardDraggingDistance.x}px, ${BoardDraggingDistance.y}px)`);
$('.board-container').css('transform', `translate(${BoardDraggingDistance.x}px, ${BoardDraggingDistance.y}px) scale(${scale})`);
}
});

Expand All @@ -66,7 +66,7 @@ $(document).on('touchmove', function (e) {
x: BoardLastDraggingDistance.x + distanceX,
y: BoardLastDraggingDistance.y + distanceY,
}
$('.board-container').css('transform', `translate(${BoardDraggingDistance.x}px, ${BoardDraggingDistance.y}px)`);
$('.board-container').css('transform', `translate(${BoardDraggingDistance.x}px, ${BoardDraggingDistance.y}px) scale(${scale})`);
}
});

Expand All @@ -80,7 +80,7 @@ $(document).on('touchmove', function (e) {
scale += ZoomSensivity;
scale = Math.round(scale * 10) / 10; // Round to 1 decimal after point
if (scale > 0.2 && scale < 4) {
$('.board-container').css('scale', `${scale}`);
$('.board-container').css('transform', `translate(${BoardDraggingDistance.x}px, ${BoardDraggingDistance.y}px) scale(${scale})`);
}
}

Expand All @@ -89,7 +89,7 @@ $(document).on('touchmove', function (e) {
scale -= ZoomSensivity;
scale = Math.round(scale * 10) / 10; // Round to 1 decimal after point
if (scale > 0.2 && scale < 4) {
$('.board-container').css('scale', `${scale}`);
$('.board-container').css('transform', `translate(${BoardDraggingDistance.x}px, ${BoardDraggingDistance.y}px) scale(${scale})`);
}
}

Expand All @@ -105,15 +105,15 @@ $(document).on('touchmove', function (e) {

function resetWorkspace() {
BoardLastDraggingDistance = {x: 0, y: 0};
$('.board-container').css({'scale': '1', 'transform': 'translate(0px, 0px)', 'transition': 'scale .5s, transform .5s'}).delay(500).queue(function(next) {
$('.board-container').css({'transform': 'translate(0px, 0px) scale(1)', 'transition': 'scale .5s, transform .5s'}).delay(500).queue(function(next) {
$(this).css('transition', 'none');
next();
});
}

$('.board-container').dblclick(function(e) {
if (!$(e.target).hasClass('switch')) {
$('.board-container').css({'scale': '1', 'transition': 'scale .5s'}).delay(500).queue(function(next) {
$('.board-container').css({'transform': `translate(${BoardDraggingDistance.x}px, ${BoardDraggingDistance.y}px) scale(1)`, 'transition': 'scale .5s'}).delay(500).queue(function(next) {
$(this).css('transition', 'none');
next();
});
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/components-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function rotateComponent() {
}
angle += 90;
SelectedComponent.find('.tooltip').css('transform', `translateY(120%) rotate(${360 - angle}deg)`);
SelectedComponent.css('rotate', `${angle}deg`);
SelectedComponent.css('transform', `rotate(${angle}deg)`);
diagram[id].rotation = angle;
autoSave();
};
Expand Down
19 changes: 16 additions & 3 deletions assets/scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ function deleteCookies() {
}
}

function deleteCookie(cookieName) {
// get the cookie with name = cookieName and delete it
document.cookie = cookieName + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/";
}

// get a cookie
function getCookie(cname) {
let name = cname + "=";
Expand Down Expand Up @@ -224,6 +229,7 @@ function getAllCookies() {


function autoSave() {
const saves = getAllCookies();
$('#board-saved').addClass('opened').delay(1000).queue(function(next) {
$(this).removeClass('opened');
next();
Expand All @@ -233,6 +239,10 @@ function autoSave() {
for (let i = 0; i < str.length; i += 2500) {
chunks.push(str.substr(i, 2500));
}
// delete cookies whose index (saveN with 'N' the index) is above the number of chunks
for (let i = chunks.length; i < getAllCookies().length; i++) {
deleteCookie(`save ${i}`);
}
for (let i = 0; i < chunks.length; i++) {
setCookie(`save ${i}`, chunks[i]);
}
Expand All @@ -245,11 +255,14 @@ $(document).ready(function() {

if (autosave === "") { return; }

JsonData = JSON.parse(autosave);
try {
JsonData = JSON.parse(autosave);
} catch (e) {
console.log(e);
return;
}

if (Object.keys(JsonData).length === 0) { return; }

// console.log(autosave);

loadDiagram(JsonData);
});
Expand Down
4 changes: 4 additions & 0 deletions assets/scripts/ui-animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,8 @@ document.getElementById('panel').addEventListener('touchend', function(e) {
scroll(); // Start the animation
}, false);

window.addEventListener('resize', () => {
const browserZoomLevel = Math.round(window.devicePixelRatio * 100);
console.log(browserZoomLevel)
})

0 comments on commit fa312d9

Please sign in to comment.