Skip to content

Commit

Permalink
Add an OSM.isDarkMap() function
Browse files Browse the repository at this point in the history
This follows the logic from openstreetmap#5328
  • Loading branch information
hlfan authored Dec 12, 2024
1 parent 1bee96e commit a03ef2b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/assets/javascripts/osm.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,13 @@ OSM = {
Math.pow(Math.sin(latdiff / 2), 2) +
Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)
));
},

isDarkMap: function() {
var siteTheme = $('html').attr('data-bs-theme');
var mapTheme = $('html').attr('data-map-theme');
if (mapTheme) return mapTheme === 'dark';
if (siteTheme) return siteTheme === 'dark';
return window.matchMedia('(prefers-color-scheme: dark)').matches
}
};

0 comments on commit a03ef2b

Please sign in to comment.