// Javascript library for memoirs function remove_tag(tag_id, url) { event.preventDefault(); var ajxReq = $.ajax(url, {type: 'DELETE'}); ajxReq.success( function(data, status, jqXhr) { $('#chip_'+tag_id).remove(); $('#rect_'+tag_id).remove(); } ); ajxReq.error( function(jqXhr, textStatus, errorMessage) { alert('Got an error while deleting this tag:' + '\nHTTP status ' + textStatus + '\n' + errorMessage); } ); } function zoom_gallery_item(url, div_id, event) { thediv = document.getElementById(div_id); var themodal = $(thediv); $.ajax({ type: "GET", url: url, success: function(returnedData) { themodal.html(returnedData); } }); themodal.openModal(); /* Override what MaterializeCSS does to the div ... */ thediv.style.display = "flex"; thediv.style.removeProperty('top'); if (event) { event.preventDefault(); } } function setup_basic_map(div_id, center_lat, center_lng, zoom) { // Initialise the map map = L.map(div_id, {zoomSnap: 0.25, zoomDelta: 0.25}); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© OpenStreetMap contributors', maxNativeZoom: 19, maxZoom: 25 }).addTo(map); if (center_lat != null && center_lng != null && zoom != null) { map.setView(L.latLng(center_lat, center_lng), zoom); } else { map.fitWorld(); } return map; } function set_map_cookie() { document.cookie = "map_center_lat=" + map.getCenter().lat + ';path=/'; document.cookie = "map_center_lon=" + map.getCenter().lng + ';path=/'; document.cookie = "map_zoom=" + map.getZoom() + ';path=/'; } /* window.requestIdleCallback() does not work on Safari... */ function x_requestIdleCallback(func) { if ('requestIdleCallback' in window) { window.requestIdleCallback(func); } else { func(); } } /* Whether the element is visible _now_ */ function in_view(element) { var bounding = element.getBoundingClientRect(); if ((bounding.top > 0) && (bounding.top < window.innerHeight)) { return true; } else { return false; } } /* Whether the element is 'on the horizon' 'horizon' is defined as "within a reasonable distance of being visible" */ horizon_screens = 1.5; /* # of screenfulls above and below to consider */ function on_horizon(element) { var bounding = element.getBoundingClientRect(); if ((bounding.top > -(horizon_screens * window.innerHeight)) && (bounding.top < ((1+horizon_screens) * window.innerHeight))) { return true; } else { return false; } } function click_action_menu(event) { const content = event.target.parentElement.getElementsByClassName("local-menu-content")[0]; if (content) { if (content.style.display =='block') { // Clicking on the menu button while the menu is showing: hide the menu again. content.style.display = ''; } else { content.style.display = 'block'; } } event.preventDefault(); } function hide_action_menu(event) { const content = event.target.parentElement.getElementsByClassName("local-menu-content")[0]; if (content) { window.setTimeout( function() { content.style.display = ''; }, 200 ); } } /* Shorthand for creating a new gallery; no need to specify URLs */ function newGallery(reference, container, scrollToFocus=false) { return new Gallery(reference, "/gallery/item", container=container, initial_load=20, next_loca=20, scrollToFocus=scrollToFocus); }