54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
|
<?php
|
||
|
namespace nur\v\plugins;
|
||
|
|
||
|
use nur\v\BasePlugin;
|
||
|
|
||
|
class autorefreshPlugin extends BasePlugin {
|
||
|
const HAVE_JQUERY = true;
|
||
|
|
||
|
const CHECKED = true;
|
||
|
|
||
|
const TEXT = "Rafraîchir cette page automatiquement";
|
||
|
|
||
|
function __construct(?array $params=null) {
|
||
|
$this->checked = $params["checked"] ?? static::CHECKED;
|
||
|
$this->text = $params["text"] ?? static::TEXT;
|
||
|
}
|
||
|
|
||
|
protected bool $checked;
|
||
|
protected string $text;
|
||
|
|
||
|
function printJquery(): void {
|
||
|
?>
|
||
|
<script type="text/javascript">
|
||
|
jQuery.noConflict()(function($) {
|
||
|
var autorefreshTimeout = null;
|
||
|
function autorefreshUpdate(enabled) {
|
||
|
if (enabled && autorefreshTimeout == null) {
|
||
|
autorefreshTimeout = setTimeout(function() { location.reload(); }, 15000);
|
||
|
} else if (!enabled && autorefreshTimeout != null) {
|
||
|
clearTimeout(autorefreshTimeout);
|
||
|
autorefreshTimeout = null;
|
||
|
}
|
||
|
}
|
||
|
if ($("#autorefresh").length > 0) {
|
||
|
$("#autorefresh").click(function() {
|
||
|
autorefreshUpdate($(this).is(":checked"));
|
||
|
});
|
||
|
autorefreshUpdate($("#autorefresh").is(":checked"));
|
||
|
}
|
||
|
});
|
||
|
</script>
|
||
|
<?php
|
||
|
}
|
||
|
|
||
|
function print(): void {
|
||
|
?>
|
||
|
<label>
|
||
|
<input type="checkbox" id="autorefresh"<?=$this->checked? " checked": false?>/>
|
||
|
<?=htmlspecialchars($this->text)?>
|
||
|
</label>
|
||
|
<?php
|
||
|
}
|
||
|
}
|