[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] maps: Only include map files once per page
"Jonny Bradley \(@jonnybradley\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a201ec71fdf5_384bb902889271@gitlab-sidekiq-low-urgency-cpu-bound-v2-dd68975fd-rfwxv.mail> |
Jonny Bradley pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
b0a3dffa by Jonny Bradley at 2026-06-03T12:13:33+00:00
[FIX] maps: Only include map files once per page
---
* [FIX] maps: Plugin Map was including tiki-maps-ol3.js again, as a late ranked file as it was included already in tiki-setup.php, so add a flad in Headerlib and use the same code to load all the files (and add the initialising js) together
See merge request tikiwiki/tiki!10431
- - - - -
3 changed files:
- lib/headerlib.php
- lib/wiki-plugins/wikiplugin_map.php
- tiki-setup.php
Changes:
=====================================
lib/headerlib.php
=====================================
@@ -154,6 +154,9 @@ class HeaderLib
private ?string $outputHeadersWasStartedBy = null;
private ?string $outputStaticJSFooterWasStartedBy = null;
+ /** Tracks if `add_map` has been called, only needed once */
+ private bool $mapAdded = false;
+
private $outputHasBeenCalledCount = 0;
public function __construct()
@@ -1275,6 +1278,12 @@ class HeaderLib
public function add_map()
{
+ if ($this->mapAdded) {
+ return $this;
+ }
+
+ $this->mapAdded = true;
+
global $prefs;
$tikilib = TikiLib::lib('tiki');
@@ -1313,21 +1322,20 @@ window.onload = loadScript;');
}
*/
+ $mapsJs = "\$(\".map-container:not(.done)\").addClass(\"done\").visible(function() {\$(this).createMap();});\n";
+
+ // Set the zoom option after searching for a location
+ $zoomToFoundLocation = $_REQUEST['geo_zoomlevel_to_found_location'] ?? $prefs['geo_zoomlevel_to_found_location'] ?? 'street';
+ $mapsJs .= 'var zoomToFoundLocation = "' . addslashes($zoomToFoundLocation) . "\";\n";
+
$this->add_jsfile_external(OL_PATH . '/dist/ol.js', true)
->add_cssfile(OL_PATH . '/ol.css')
->add_jsfile_external(OL_LAYERSWITCHER_DIST_PATH . '/ol-layerswitcher.js')
->add_cssfile(OL_LAYERSWITCHER_DIST_PATH . '/ol-layerswitcher.css')
- ->add_js(
- ''
- );
-
- $this->add_js(
- '$(".map-container:not(.done)")
- .addClass("done")
- .visible(function() {
- $(this).createMap();
- });'
- );
+ ->add_jsfile(JS_ASSETS_PATH . "/jquery-tiki/tiki-maps-ol3.js")
+ ->add_js($mapsJs);
+
+ $this->mapAdded = true;
return $this;
}
=====================================
lib/wiki-plugins/wikiplugin_map.php
=====================================
@@ -221,13 +221,8 @@ function wikiplugin_map($data, $params)
$center = $geolib->get_default_center();
}
- TikiLib::lib('header')
- ->add_cssfile(OL_PATH . '/ol.css')
- ->add_jsfile(JS_ASSETS_PATH . "/jquery-tiki/tiki-maps-ol3.js")
- ->add_jsfile(OL_PATH . '/dist/ol.js')
- ->add_cssfile(OL_LAYERSWITCHER_DIST_PATH . '/ol-layerswitcher.css')
- ->add_jsfile(OL_LAYERSWITCHER_DIST_PATH . '/ol-layerswitcher.js')
- ;
+ TikiLib::lib('header')->add_map();
+
$scope = smarty_modifier_escape(wp_map_getscope($params));
$output = "<div class=\"map-container\" data-marker-filter=\"$scope\" data-map-controls=\"$controls\" data-popup-style=\"$popupStyle\"" .
=====================================
tiki-setup.php
=====================================
@@ -612,13 +612,6 @@ if ($prefs['error_tracking_enabled_js'] == 'y' && ! empty($prefs['error_tracking
$headerlib->add_jsfile(JS_ASSETS_PATH . '/jquery-tiki/tiki-menu.js');
$headerlib->add_jsfile('lib/tiki-js.js'); //This depends on tiki-jquery.js in at least one place, so must load after - benoitg - 2023-11-21
-$zoomToFoundLocation = $_REQUEST['geo_zoomlevel_to_found_location'] ?? $prefs['geo_zoomlevel_to_found_location'] ?? 'street';
-$headerlib->add_js('var zoomToFoundLocation = "' . addslashes($zoomToFoundLocation) . '";'); // Set the zoom option after searching for a location
-
-if ($prefs['geo_enabled'] === 'y') {
- $headerlib->add_jsfile(JS_ASSETS_PATH . "/jquery-tiki/tiki-maps-ol3.js");
-}
-
if ($prefs['feature_jquery_zoom'] === 'y') {
$headerlib->add_jsfile(NODE_PUBLIC_DIST_PATH . '/jquery-zoom/jquery.zoom.js')
->add_css('
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/b0a3dffa22e4a104e3e2fb9302508679eb0a6989
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/b0a3dffa22e4a104e3e2fb9302508679eb0a6989
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs