diff --git a/crouton.php b/crouton.php index 4fcd42c2..139ffb64 100644 --- a/crouton.php +++ b/crouton.php @@ -56,6 +56,7 @@ class Crouton "root_server" => '', "service_body" => '', "service_body_parent" => '', + "jsInFooter" => true, "venue_types" => '', "formats" => '', "has_tabs" => '1', @@ -304,14 +305,25 @@ private function sharedRender() return $output; } - + private function inlineScript($s) + { + wp_add_inline_script('croutonjs', $s); + } + private function outputScript($s) + { + if ($this->options['jsInFooter']) { + wp_add_inline_script('croutonjs', $s); + $s = ""; + } + return $this->waitMsg.sprintf('%s
%s
', $this->sharedRender(), $s); + } public function tabbedUi($atts, $content = null) { $this->hasMap = true; if (isset($_GET['meeting-id'])) { return do_shortcode($this->getDefaultMeetingDetailsPageContents()); } - return $this->waitMsg.sprintf('%s
%s
', $this->sharedRender(), $this->renderTable($atts)); + return $this->outputScript($this->renderTable($atts)); } public function bmltHandlebar($atts, $template = null) { @@ -327,7 +339,7 @@ public function bmltHandlebar($atts, $template = null) } } if (!$this->has_handlebars) { - add_action("wp_footer", [$this,'handlebarFooter']); + $this->handlebarFooter(); } $this->has_handlebars = true; return sprintf('%sFetching...', htmlspecialchars($template)); @@ -338,7 +350,7 @@ public function croutonMap($atts, $content = null) if (isset($_GET['meeting-id'])) { return do_shortcode($this->getDefaultMeetingDetailsPageContents()); } - return sprintf('%s
%s
', $this->sharedRender(), $this->renderMap($atts)); + return $this->outputScript($this->renderMap($atts)); } public function meetingMap($atts, $content = null) { @@ -351,7 +363,7 @@ public function meetingMap($atts, $content = null) } else { $atts = ["has_venues" => "0"]; } - return sprintf('%s
%s
', $this->sharedRender(), $this->renderMap($atts, false)); + return $this->outputScript($this->renderMap($atts, false)); } private function getMapInitialization($mapConfig) { @@ -437,16 +449,9 @@ public function handlebarFooter() 'strict_datafields' => false]; [$config, $mapConfig] = $this->getCroutonJsConfig($attr); $croutonMap = $this->getMapInitialization($mapConfig); - ?> - - inlineScript($ret); } /** * @desc Adds the options sub-panel @@ -511,6 +516,7 @@ public function adminOptionsPage() } $this->options['root_server'] = $_POST['root_server']; $this->options['service_body_1'] = $_POST['service_body_1']; + $this->options['jsInFooter'] = isset($_POST['jsInFooter']); $this->options['time_format'] = $_POST['time_format']; $this->options['language'] = $_POST['language']; $this->options['strict_datafields'] = isset($_POST['strict_datafields']); @@ -569,6 +575,9 @@ public function adminOptionsPage() } else { $this->options['extra_meetings_enabled'] = 1; } + if (!isset($this->options['jsInFooter'])) { + $this->options['jsInFooter'] = true; + } ?>
@@ -699,6 +708,13 @@ public function adminOptionsPage()
+
+

Advanced Options

+

Should the generated Javascript be placed in the footer or in the body.

+
+ options['jsInFooter'] == 1 ? 'checked' : '') ?> />Place Javascript in Footer +
+
@@ -1040,13 +1056,12 @@ private function getAllFields($root_server) private function templateToParameter($atts, $name) { if (isset($atts[$name]) && $atts[$name] !== null && $atts[$name] !== "") { - $template = $atts[$name]; + return $atts[$name]; } elseif (isset($this->options[$name])) { - $template = $this->options[$name]; + return $this->options[$name]; } else { - $template = ""; + return ""; } - return html_entity_decode($template); } private function getAllMeetings($root_server) { diff --git a/croutonjs/meetingMap/js/meeting_map.js b/croutonjs/meetingMap/js/meeting_map.js index 08db2367..20e6c37e 100644 --- a/croutonjs/meetingMap/js/meeting_map.js +++ b/croutonjs/meetingMap/js/meeting_map.js @@ -303,7 +303,7 @@ function MeetingMap(inConfig) { showGeocodingDialog(); } } else if (config.goto) { - gDelegate.callGeocoder(goto, filterMeetingsAndBounds); + gDelegate.callGeocoder(config.goto, filterMeetingsAndBounds); } } function createCityHash(allMeetings) { @@ -363,6 +363,7 @@ function MeetingMap(inConfig) { const newTop = -window.scrollY+'px'; body.style.overflowX = 'hidden'; body.style.position = 'fixed'; + body.style.width="100%"; body.style.setProperty('top', newTop, 'important'); } } diff --git a/croutonjs/meetingMap/meeting_map.php b/croutonjs/meetingMap/meeting_map.php index a6cee1b2..314b6679 100644 --- a/croutonjs/meetingMap/meeting_map.php +++ b/croutonjs/meetingMap/meeting_map.php @@ -188,48 +188,42 @@ private function hsc($field) } private function createJavascriptConfig($options) { - $ret = '{'; + $ret = []; //$ret .= 'BMLTPlugin_files_uri:\''.$this->hsc($this->getPluginPath()).'?\',' . (defined('_DEBUG_MODE_') ? "\n" : ''); - $ret .= "BMLTPlugin_images:'".$this->hsc(plugin_dir_url(__FILE__)."map_images")."'," . (defined('_DEBUG_MODE_') ? "\n" : ''); - $ret .= "BMLTPlugin_lang_dir:'".$this->hsc(plugin_dir_url(__FILE__)."lang")."'," . (defined('_DEBUG_MODE_') ? "\n" : ''); - $ret .= "BMLTPlugin_throbber_img_src:'".$this->hsc(plugin_dir_url(__FILE__)."map_images/Throbber.gif")."'," . (defined('_DEBUG_MODE_') ? "\n" : ''); - $ret .= 'region:"'.$options['region_bias'].'",'; - $ret .= 'bounds:{'; - $ret .= ' "north": "'.$options['bounds_north'].'",'; - $ret .= ' "east": "'.$options['bounds_east'].'",'; - $ret .= ' "south": "'.$options['bounds_south'].'",'; - $ret .= ' "west": "'.$options['bounds_west'].'"'; - $ret .= '},'; - $ret .= 'tileUrl:"'.$options['tile_url'].'",'; - $ret .= 'clustering:"'.$options['clustering'].'",'; - $ret .= 'nominatimUrl:"'.$options['nominatim_url'].'",'; - $ret .= 'tileOptions:{'; - foreach ($options['tile_params'] as $key => $value) { - $ret .= " '".$key."': '".$value."',"; - } - $ret .= '},'; - $ret .= 'api_key:"'.$options['api_key'].'",'; - $ret .= 'lat:"'.$options['lat'].'",'; - $ret .= 'lng:"'.$options['lng'].'",'; - $ret .= 'zoom:"'.$options['zoom'].'",'; - $ret .= 'minZoom:"'.$options['min_zoom'].'",'; - $ret .= 'maxZoom:"'.$options['max_zoom'].'",'; + $ret["BMLTPlugin_images"] = $this->hsc(plugin_dir_url(__FILE__)."map_images"); + $ret["BMLTPlugin_lang_dir"] = $this->hsc(plugin_dir_url(__FILE__)."lang"); + $ret["BMLTPlugin_throbber_img_src"] = $this->hsc(plugin_dir_url(__FILE__)."map_images/Throbber.gif"); + $ret['region'] = $options['region_bias']; + $ret['bounds'] = [ + "north" => $options['bounds_north'], + "east" => $options['bounds_east'], + "south" => $options['bounds_south'], + "west" => $options['bounds_west'] + ]; + $ret['tileUrl'] = $options['tile_url']; + $ret['clustering'] = $options['clustering']; + $ret['nominatimUrl'] = $options['nominatim_url']; + $ret['tileOptions'] = $options['tile_params']; + $ret['api_key'] = $options['api_key']; + $ret['lat'] = $options['lat']; + $ret['lng'] = $options['lng']; + $ret['zoom'] = $options['zoom']; + $ret['minZoom'] = $options['min_zoom']; + $ret['maxZoom'] = $options['max_zoom']; if (!empty($options['center_me'])) { - $ret .= 'centerMe:"'.$options['center_me'].'",'; + $ret['centerMe'] = $options['center_me']; } if (!empty($options['goto'])) { - $ret .= 'goto:"'.$options['goto'].'",'; + $ret['goto'] = $options['goto']; + if (isset($_GET['goto'])) { + $ret['centerMe'] = ''; + } } if (isset($options['map_search'])) { - $ret .= 'map_search: {'; - foreach ($options['map_search'] as $key => $value) { - $ret .= $key.':"'.$value.'",'; - } - $ret .= '},'; + $ret['map_search'] = $options['map_search']; } - $ret .= '"marker_contents_template":'.json_encode($options['marker_contents_template']); - $ret .= '},'; - return $ret; + $ret["marker_contents_template"] = $options['marker_contents_template']; + return json_encode($ret); } public function adminSection() { diff --git a/js/bmlt_tabs_admin.js b/js/bmlt_tabs_admin.js index 6dc49eb6..aea8a127 100644 --- a/js/bmlt_tabs_admin.js +++ b/js/bmlt_tabs_admin.js @@ -36,7 +36,6 @@ function numbersonly(myfield, e, dec) return false; }; function resetCodemirrorToDefault(textAreaId) { - console.log("in Function"); let cm = jQuery('#'+textAreaId).next()[0].CodeMirror; cm.setValue(croutonDefaultTemplates[textAreaId]); } diff --git a/readme.txt b/readme.txt index cc4eb9a3..19a33a17 100644 --- a/readme.txt +++ b/readme.txt @@ -37,7 +37,8 @@ https://demo.bmlt.app/crouton == Changelog == = 3.19.5 = -* Fix InfoWindow close button on GoogleMaps +* Fix InfoWindow close button on GoogleMaps +* Add option to place generated JavaScript in footer = 3.19.4 = * Bug fix