Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geolocation_div.php: Rexstan-Überarbeitung, Code-Style #62

Merged
merged 1 commit into from
Sep 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions docs/example/geolocation_div.php
Original file line number Diff line number Diff line change
@@ -1,64 +1,76 @@
<?php
/*
Fragment zum Aufbau des rex-map-HTML
/**
* Fragment zum Aufbau des rex-map-HTML als <div>.
*
* Es finden nur formale Prüfungen statt. Fehlende Werte werden nicht durch Defaults ersetzt.
* Hier wird aus Eingangsdaten HTML gebaut, mehr nicht.
*
* <div rex-map dataset="..." mapset="..." map="..."></div>
*/

Es finden nur formale Prüfungen statt. Fehlende Werte werden nicht durch Defaults ersetzt.
Hier wird aus Eingangsdaten HTML gebaut, mehr nicht.
namespace Geolocation;

/**
* @var \rex_fragment $this
*/

<rex-map dataset="..." mapset="..." map="..."></rex-map>
*/
$classes = [];
$attributes = [];

// dataset muss ein Array sein
if( isset($this->dataset) && is_array($this->dataset) ) {
if (isset($this->dataset) && \is_array($this->dataset)) {
$attributes['dataset'] = json_encode($this->dataset);
}

// mapset muss ein Array sein
if( isset($this->mapset) && is_array($this->mapset) ) {
if (isset($this->mapset) && \is_array($this->mapset)) {
$attributes['mapset'] = json_encode($this->mapset);
}

// map (Kartenoptionen) muss ein Array sein
if( isset($this->map) && is_array($this->map) ) {
if (isset($this->map) && \is_array($this->map)) {
$attributes['map'] = json_encode($this->map);
}

// Klassen hinzufügen (string oder array)
if( isset($this->class) ) {
if (isset($this->class)) {
$class = $this->class;
if( is_string($class) && $class) $class = explode(' ',$class);
if( is_array($class) && $class ) $classes = array_merge($classes,$class);
if (\is_string($class)) {
$class = explode(' ', $class);
}
if (\is_array($class)) {
$classes = array_merge($classes, $class);
}
}
if( $classes ) {
$classes = array_filter($classes, 'trim');
if (0 < \count($classes)) {
$attributes['class'] = array_unique($classes);
}

// Schript-Code für Events einfügen
if( isset($this->events) && is_array($this->events) && count($this->events) ) {
if (isset($this->events) && \is_array($this->events) && 0 < \count($this->events)) {
$code = '';
$id = 'rm'.md5( microtime() );
foreach( $this->events as $k=>$v ) {
$id = 'rm'.md5(microtime());
foreach ($this->events as $k => $v) {
$exit = 'if( !e.detail.container.hasAttribute(\''.$id.'\') ) return;';
$code .= 'document.addEventListener(\'geolocation.'.$k.'\', function(e){'.$exit.'console.log(e);'.$v.'});';
}
if( $code ) {
if ('' < $code) {
echo '<script type="text/javascript">',$code,'</script>';
$attributes[$id] = 1;
}
}

// sonstige Attribute hinzufügen (class,dataset,mapset,map ignorieren)
if( isset($this->attributes) && is_array($this->attributes) && count($this->attributes) ) {
if (isset($this->attributes) && \is_array($this->attributes) && 0 < \count($this->attributes)) {
$attributes = array_merge(
$attributes,
array_diff_key($this->attributes,['mapset'=>null,'dataset'=>null,'map'=>null,'class'=>null])
array_diff_key($this->attributes, ['mapset' => null, 'dataset' => null, 'map' => null, 'class' => null])
);
}

// HTML-Tag generieren
$id = 'rm-' . md5(time());
$id = 'rm-' . md5(microtime());
?>
<script>
document.addEventListener('DOMContentLoaded', (event) => {
Expand Down