Zitat von
Bennie
wie hast Du das mit dem "zum aktuellen Monat springen.." umgesetzt?
cal_default.html5
PHP-Code:
<?php
$nowUrl = preg_replace('/\?.*$/', '', Environment::get('request'));
$nowMonth = $this->parseDate('F Y', $this->time);
$nowLYear = $this->parseDate('Y', $this->time);
$nowLMonth = $this->parseDate('m', $this->time);
$toCurMonth = $nowUrl . '?month=' . $nowLYear . $nowLMonth;
?>
<table class="calendar">
<thead>
<tr>
<th colspan="2" class="head previous"><?php if ($this->prevHref): ?><a class="calendar__prev" href="<?= $this->prevHref ?>" title="<?= $this->prevTitle ?>"><?= $this->prevLink ?></a><?php else: ?> <?php endif; ?></th>
<th colspan="3" class="head current">
<?= $this->current ?>
<?php if ($nowMonth !== ($this->current)): ?>
<a class="calendar__now" href="<?= $toCurMonth ?>"><?= ' (zum aktuellen Monat ' . $nowMonth . ' springen)' ?></a>
<?php endif; ?>
</th>
<th colspan="2" class="head next"><?php if ($this->nextHref): ?><a class="calendar__next" href="<?= $this->nextHref ?>" title="<?= $this->nextTitle ?>"><?= $this->nextLink ?></a><?php else: ?> <?php endif; ?></th>
</tr>
<tr>
<?php foreach ($this->days as $day): ?>
<th class="label<?= $day['class'] ?>"><?= Patchwork\Utf8::substr($day['name'], 0, $this->substr) ?><span><?= Patchwork\Utf8::substr($day['name'], $this->substr) ?></span></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($this->weeks as $class => $week): ?>
<tr class="<?= $class ?>">
<?php foreach ($week as $day): ?>
<td class="<?= $day['class'] ?>">
<div class="header"><?= $day['label'] ?></div>
<?php foreach ($day['events'] as $event): ?>
<div class="event cal_<?= $event['parent'] ?><?= $event['class'] ?>" itemscope itemtype="http://schema.org/Event">
<a href="<?= $event['href'] ?>" title="<?= $event['title'] ?> (<?php if ($event['day']): ?><?= $event['day'] ?>, <?php endif; ?><?= $event['date'] ?><?php if ($event['time']): ?> <?= $event['time']?><?php endif; ?>)"<?= $event['target'] ?> itemprop="url"><span itemprop="name"><?= $event['link'] ?></span></a>
</div>
<?php endforeach; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script>
$(".calendar__next, .calendar__prev, .calendar__now").click(function (event) {
var element;
//Get url of next Month
var $url = window.location.origin + '/' + $(this).attr('href');
// Don't follow the link
event.preventDefault();
// This is the elements div container like ".mod_my_module". "Allow ajax reload" has to be ticket for this element in the backend
element = $(this).closest('[class^="ce_"],[class^="mod_"]');
// Add a css class to this element. An overlay and spinning icon can be set via css
element.addClass('ajax-reload-element-overlay');
$.ajax({
method: 'POST',
url: $url,
data: {
// The data- attribute is set automatically
ajax_reload_element: element.attr('data-ajax-reload-element')
}
})
.done(function (response, status, xhr) {
if ('ok' === response.status) {
// Replace the DOM
element.replaceWith(response.html);
} else {
// Reload the page as fallback
location.reload();
}
});
});
</script>
• Zeile 15 bis 17 eine Abfrage ob aktueller Monat - falls nein, dann erzeuge einen Link
• und in <script> dann nochmals 'calendar__now' mit in den click-event gepackt, damit auch hier sauber nachgeladen wird