Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace useless style in js by css classes #129

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
@use 'signalement.css';
@use 'landmark.css';
@use 'location.css';
@use 'elevationLine.css';
@use 'mapboxgl-accessibility.css';
@use 'action-sheet.css';
@use 'media-queries.css';
@use 'media-queries.css';
13 changes: 13 additions & 0 deletions src/css/elevationLine.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.elevationLineLoadingDom {
width: 100%;
aspect-ratio: 2 / 1;
position: sticky;
flex-shrink: 0;
margin-bottom: -50%;
transform: translate(0, -100%);
background-color: #3F4A5555;
background-image: url(assets/loading-darkgrey.svg);
background-position: center;
background-repeat: no-repeat;
background-size: 50px;
}
6 changes: 5 additions & 1 deletion src/css/isochrone.css
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
background-size: 22px;
}

.btnIsochroneCompute.loading {
background-image: url(assets/loading-white.svg);
}

/*
* transport / mode
*/
Expand Down Expand Up @@ -335,4 +339,4 @@ input#isochroneValueDistanceInput[type=number]
.divIsochroneDisplayOption > .toggleSwitch {
flex-shrink: 0;
margin-left: 20px;
}
}
5 changes: 5 additions & 0 deletions src/css/map-buttons.css
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@
pointer-events: none;
}

#mapCenter.loading {
background-image: url("assets/loading-green.svg");
background-size: 75px;
}

#mapCenterMenu {
color: var(--dark-grey);
display: flex;
Expand Down
22 changes: 22 additions & 0 deletions src/css/map.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@
flex-direction: column;
}

/* Marker icons */
.myPositionIcon {
width: 51px;
height: 51px;
background-size: contain;
background-image: url(assets/position.svg);
}

.myPositionIconGrey {
width: 51px;
height: 51px;
background-size: contain;
background-image: url(assets/position-grey.svg);
}

.searchResultIcon {
width: 36px;
height: 36px;
background-size: contain;
background-image: url(assets/map-center.svg);
}

@media screen and (min-aspect-ratio: 1/1) and (min-width:400px) {
#map {
height: 100vh;
Expand Down
3 changes: 3 additions & 0 deletions src/css/mapboxgl-accessibility.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ ISC License
border-radius: 0;
border: none;
position: fixed;
display: block;
width: 24px;
height: 24px;
}
6 changes: 6 additions & 0 deletions src/css/signalement.css
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,9 @@
background-size: 22px;
margin-top: 10px;
}

.signalement-submit.inactive {
pointer-events: none;
background-image: url(assets/loading-white.svg);
color: #0000;
}
1 change: 1 addition & 0 deletions src/css/tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@

.elevationLineCanvas {
touch-action: none;
width: 100%;
}
2 changes: 0 additions & 2 deletions src/js/directions/directions-results-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ let DirectionsResultsDOM = {
var canvasProfile = document.createElement("canvas");
canvasProfile.id = "directions-elevationline";
canvasProfile.className = "elevationLineCanvas";
// FIXME: STYLE: passer par une classe et style CSS
canvasProfile.style.width = "100%";
divList.appendChild(canvasProfile);
}

Expand Down
23 changes: 4 additions & 19 deletions src/js/elevation-line-control/elevation-line-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ import Location from "../services/location";

import { Toast } from "@capacitor/toast";

import LoadingDark from "../../css/assets/loading-darkgrey.svg";


/**
* Interface sur le contrôle profil altimétrique
* @module ElevationLineControl
Expand Down Expand Up @@ -65,19 +62,8 @@ class ElevationLineControl {
this.chart = null;

this.loadingDom = document.createElement("div"); // div de la patience
// FIXME: STYLE: passer par une classe et style CSS
this.loadingDom.style.width = "100%";
this.loadingDom.style.aspectRatio = "2 / 1";
this.loadingDom.style.position = "sticky";
this.loadingDom.style.flexShrink = "0";
this.loadingDom.style.marginBottom = "-50%";
this.loadingDom.style.transform = "translate(0, -100%)";
this.loadingDom.style.backgroundColor = "#3F4A5555";
this.loadingDom.style.backgroundImage = "url(" + LoadingDark + ")";
this.loadingDom.style.backgroundPosition = "center";
this.loadingDom.style.backgroundRepeat = "no-repeat";
this.loadingDom.style.backgroundSize = "50px";
this.loadingDom.style.display = "none";
this.loadingDom.className = "elevationLineLoadingDom";
this.loadingDom.classList.add("d-none");
this.loadingDomInDocument = false;

return this;
Expand Down Expand Up @@ -397,16 +383,15 @@ Distance du départ : ${distanceText} ${this.unit}`;
this.target.after(this.loadingDom);
this.loadingDomInDocument = true;
}
// FIXME: STYLE: passer par une classe et style CSS
this.loadingDom.style.removeProperty("display");
this.loadingDom.classList.remove("d-none");
}

/**
* Désactive la patience
* @private
*/
#unsetLoading() {
this.loadingDom.style.display = "none";
this.loadingDom.classList.add("d-none");
}

/**
Expand Down
26 changes: 3 additions & 23 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ import "@maplibre/maplibre-gl-compare/dist/maplibre-gl-compare.css";
import "maplibre-gl/dist/maplibre-gl.css";
import "../css/app.scss";

// fichiers SVG
import PositionImg from "../css/assets/position.svg";
import PositionImgGrey from "../css/assets/position-grey.svg";
import MapCenterImg from "../css/assets/map-center.svg";

// Affichage des éléments PWA en mode WE (Toast et ActionSheet)
import { defineCustomElements } from "@ionic/pwa-elements/loader";
defineCustomElements(window);
Expand Down Expand Up @@ -119,28 +114,13 @@ function app() {

// Définition des icones
Globals.myPositionIcon = document.createElement("div");
Globals.myPositionIcon.class = "myPositionIcon";
// FIXME: STYLE: passer par une classe et style CSS
Globals.myPositionIcon.style.width = "51px";
Globals.myPositionIcon.style.height = "51px";
Globals.myPositionIcon.style.backgroundSize = "contain";
Globals.myPositionIcon.style.backgroundImage = "url(" + PositionImg + ")";
Globals.myPositionIcon.className = "myPositionIcon";

Globals.myPositionIconGrey = document.createElement("div");
Globals.myPositionIconGrey.class = "myPositionIconGrey";
// FIXME: STYLE: passer par une classe et style CSS
Globals.myPositionIconGrey.style.width = "51px";
Globals.myPositionIconGrey.style.height = "51px";
Globals.myPositionIconGrey.style.backgroundSize = "contain";
Globals.myPositionIconGrey.style.backgroundImage = "url(" + PositionImgGrey + ")";
Globals.myPositionIconGrey.className = "myPositionIconGrey";

Globals.searchResultIcon = document.createElement("div");
Globals.searchResultIcon.class = "searchResultIcon";
// FIXME: STYLE: passer par une classe et style CSS
Globals.searchResultIcon.style.width = "36px";
Globals.searchResultIcon.style.height = "36px";
Globals.searchResultIcon.style.backgroundSize = "contain";
Globals.searchResultIcon.style.backgroundImage = "url(" + MapCenterImg + ")";
Globals.searchResultIcon.className = "searchResultIcon";

// Main map
const map = new maplibregl.Map({
Expand Down
6 changes: 2 additions & 4 deletions src/js/isochrone/isochrone-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import DomUtils from "../utils/dom-utils";
import LoadingWhite from "../../css/assets/loading-white.svg";

import { Toast } from "@capacitor/toast";

Expand Down Expand Up @@ -366,8 +365,7 @@ let IsochroneDOM = {
__setComputeButtonLoading () {
this.dom.isochroneCompute.value = "";
this.dom.isochroneCompute.disabled = true;
// FIXME: STYLE: passer par une classe et style CSS
this.dom.isochroneCompute.style.backgroundImage = "url(" + LoadingWhite + ")";
this.dom.isochroneCompute.classList.add("loading");
document.querySelectorAll("#isochroneLocationContainer").forEach((el) => {
el.classList.add("disabled");
});
Expand All @@ -380,7 +378,7 @@ let IsochroneDOM = {
__unsetComputeButtonLoading () {
this.dom.isochroneCompute.value = "Calculer";
this.dom.isochroneCompute.disabled = false;
this.dom.isochroneCompute.style.removeProperty("background-image");
this.dom.isochroneCompute.classList.remove("loading");
document.querySelectorAll("#isochroneLocationContainer").forEach((el) => {
el.classList.remove("disabled");
});
Expand Down
21 changes: 10 additions & 11 deletions src/js/map-interactivity/interactivity-indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import PopupUtils from "../utils/popup-utils";
class InteractivityIndicator {

/**
* constructeur
* @param {*} map
* @param {*} options
*/
* constructeur
* @param {*} map
* @param {*} options
*/
constructor(map, options) {
this.options = options || {
id: "PLAN.IGN.INTERACTIF$GEOPORTAIL:GPP:TMS"
Expand Down Expand Up @@ -137,12 +137,11 @@ class InteractivityIndicator {
}

/**
* Active l'indicateur d'activité
*/
* Active l'indicateur d'activité
*/
active () {
this.hardDisabled = false;
DOM.$interactivityBtn.classList.remove("d-none");
// FIXME: STYLE: passer par une classe et style CSS
DOM.$interactivityBtn.style.removeProperty("opacity");
DOM.$interactivityBtn.style.removeProperty("color");
document.getElementById("interactivityBtnText").innerText = "La carte est interactive";
Expand Down Expand Up @@ -197,16 +196,16 @@ class InteractivityIndicator {
}

/**
* Desactive l'indicateur d'activité jusqu'à nouvel ordre
*/
* Desactive l'indicateur d'activité jusqu'à nouvel ordre
*/
hardDisable() {
this.hardDisabled = true;
this.disable();
}

/**
* Réactive l'indicateur après désactivation forcée
*/
* Réactive l'indicateur après désactivation forcée
*/
enable() {
this.hardDisabled = false;
this.map.fire("zoom");
Expand Down
16 changes: 4 additions & 12 deletions src/js/map-interactivity/map-interactivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import Buffer from "@turf/buffer";
import proj4 from "proj4";
import Legend from "./legend-plan-ign";

import LoadingGreen from "../../css/assets/loading-green.svg";


/**
* Interface sur l'interaction avec la carte
* @module MapInteractivity
Expand Down Expand Up @@ -191,9 +188,7 @@ class MapInteractivity {
this.#multipleGFI(layersForGFI)
.then(async (resp) => {
this.loading = false;
// FIXME: STYLE: passer par une classe et style CSS
DOM.$mapCenter.style.removeProperty("background-image");
DOM.$mapCenter.style.removeProperty("background-size");
DOM.$mapCenter.classList.remove("loading");
DOM.$mapCenter.classList.add("d-none");
try {
this.#highlightGFI(resp.geometry);
Expand All @@ -211,8 +206,7 @@ class MapInteractivity {
return;
}).catch(async () => {
this.loading = false;
DOM.$mapCenter.style.removeProperty("background-image");
DOM.$mapCenter.style.removeProperty("background-size");
DOM.$mapCenter.classList.remove("loading");
DOM.$mapCenter.classList.add("d-none");
if (featureHTML !== null) {
this.#clearSources();
Expand Down Expand Up @@ -299,8 +293,7 @@ class MapInteractivity {

async #multipleGFI(layerArray) {
this.loading = true;
DOM.$mapCenter.style.backgroundImage = `url(${LoadingGreen})`;
DOM.$mapCenter.style.backgroundSize = "75px";
DOM.$mapCenter.classList.add("loading");
DOM.$mapCenter.classList.remove("d-none");

let GFIArray = layerArray.filter(layer => layer[1].visibility === true);
Expand Down Expand Up @@ -542,8 +535,7 @@ class MapInteractivity {
this.controller.abort();
this.controller = new AbortController();
this.loading = false;
DOM.$mapCenter.style.removeProperty("background-image");
DOM.$mapCenter.style.removeProperty("background-size");
DOM.$mapCenter.classList.remove("loading");
DOM.$mapCenter.classList.add("d-none");
}
this.#clearSources();
Expand Down
6 changes: 1 addition & 5 deletions src/js/poi-accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,13 @@ class MapboxAccessibility {
feature.marker = document.createElement("button");
feature.marker.setAttribute("title", label);
feature.marker.setAttribute("tabindex", 0);
// FIXME: STYLE: passer par une classe et style CSS
feature.marker.style.display = "block";
feature.marker.className = "mapboxgl-accessibility-marker";

let position;
if (feature.geometry.type === "Point") {
position = this.map.project(feature.geometry.coordinates);
}
feature.marker.style.width = "24px";
feature.marker.style.height = "24px";
feature.marker.style.transform = `translate(-50%, -50%) translate(${position.x}px, ${position.y}px)`;
feature.marker.className = "mapboxgl-accessibility-marker";

this.map.getCanvasContainer().appendChild(feature.marker);
return feature;
Expand Down
2 changes: 0 additions & 2 deletions src/js/route-draw/route-draw-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ let RouteDrawDOM = {
var canvasProfile = document.createElement("canvas");
canvasProfile.id = "routedraw-elevationline";
canvasProfile.className = "elevationLineCanvas";
// FIXME: STYLE: passer par une classe et style CSS
canvasProfile.style.width = "100%";
div.appendChild(canvasProfile);

var detailsHeader = document.createElement("p");
Expand Down
Loading