nur-sery/nur_src/v/plugins/showmorePlugin.php

108 lines
2.4 KiB
PHP
Raw Normal View History

2024-06-10 16:46:28 +04:00
<?php
namespace nur\v\plugins;
use nur\v\BasePlugin;
use nur\v\v;
use nur\v\vo;
class showmorePlugin extends BasePlugin {
const HAVE_JQUERY = true;
/** @var string classe du conteneur */
const CONTAINER_CLASS = "showmore-container";
/** @var string classe de l'invite à en savoir plus */
const INVITE_CLASS = "showmore-invite";
/** @var string classe du panneau caché par défaut */
const INVITE_CONTENT = "En savoir plus...";
const PANEL_CLASS = "showmore-panel";
2024-06-26 18:14:20 +04:00
function __construct(?array $params=null) {
$this->containerClass = $params["container_class"] ?? static::CONTAINER_CLASS;
$this->inviteClass = $params["invite_class"] ?? self::INVITE_CLASS;
$this->inviteContent = $params["invite_content"] ?? self::INVITE_CONTENT;
$this->panelClass = $params["panel_class"] ?? self::PANEL_CLASS;
$this->onShow = $params["on_show"] ?? null;
}
protected string $containerClass;
protected string $inviteClass, $inviteContent;
protected string $panelClass;
protected ?string $onShow;
2024-06-10 16:46:28 +04:00
function startc(): array {
2024-06-26 18:14:20 +04:00
return v::sdiv(["class" => $this->containerClass]);
2024-06-10 16:46:28 +04:00
}
function invite($vs=null): array {
2024-06-26 18:14:20 +04:00
$vs ??= $this->inviteContent;
2024-06-10 16:46:28 +04:00
return v::a([
2024-06-26 18:14:20 +04:00
"class" => $this->inviteClass,
2024-06-10 16:46:28 +04:00
"href" => "#",
$vs,
]);
}
function startp(): array {
2024-06-26 18:14:20 +04:00
return v::sdiv([
"class" => [$this->panelClass, "hidden"],
]);
2024-06-10 16:46:28 +04:00
}
function endp(): array {
return ["</div>"];
}
function endc(): array {
return ["</div>"];
}
function end(): array {
return ["</div></div>"];
}
function printStartc(): void {
vo::print($this->startc());
}
function printInvite($vs=null): void {
vo::print($this->invite($vs));
}
function printStartp(): void {
vo::print($this->startp());
}
function printEndp(): void {
vo::print($this->endp());
}
function printEndc(): void {
vo::print($this->endc());
}
function printEnd(): void {
vo::print($this->end());
}
function printJquery(): void {
?>
<script type="text/javascript">
jQuery.noConflict()(function($) {
$(".<?=self::INVITE_CLASS?>").click(function() {
let $this = $(this);
$this.addClass("hidden");
2024-06-26 18:14:20 +04:00
let $container = $this.closest(".<?=self::CONTAINER_CLASS?>");
let $panel = $container.find(".<?=self::PANEL_CLASS?>");
$panel.removeClass("hidden");
<?=$this->onShow?>
2024-06-10 16:46:28 +04:00
return false;
});
});
</script>
<?php
}
}