[TikiWiki-commits] [Git][tikiwiki/tiki][30.x] [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 <6a36616ea68e5_381a28181876e@gitlab-sidekiq-low-urgency-cpu-bound-v2-8cc648f49-fpf9d.mail>

Jonny Bradley pushed to branch 30.x at Tiki Wiki CMS Groupware / Tiki


Commits:
9623b129 by Jonny Bradley at 2026-06-20T09:40:48+00:00
[FIX] maps: Only include map files once per page
---
* [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


(cherry picked from commit b0a3dffa22e4a104e3e2fb9302508679eb0a6989)

8b7529f3 [FIX] maps: Plugin Map was including tiki-maps-ol3.js again, as a late ranked...

Co-authored-by: Jonny Bradley <[email protected]>

See merge request tikiwiki/tiki!10563

- - - - -


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()
@@ -1477,6 +1480,12 @@ class HeaderLib
 
     public function add_map()
     {
+        if ($this->mapAdded) {
+            return $this;
+        }
+
+        $this->mapAdded = true;
+
         global $prefs;
 
         $tikilib = TikiLib::lib('tiki');
@@ -1515,21 +1524,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
=====================================
@@ -222,13 +222,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
=====================================
@@ -607,13 +607,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/9623b1296a03ff2abe23cb174989c0f7f8409330

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/9623b1296a03ff2abe23cb174989c0f7f8409330
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.