138 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			138 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
namespace nur\v\plugins;
 | 
						|
 | 
						|
use nur\v\BasePlugin;
 | 
						|
use nur\v\v;
 | 
						|
use nur\v\vo;
 | 
						|
 | 
						|
/**
 | 
						|
 * Class showmorePlugin: un outil pour masquer par défaut un panneau de détails
 | 
						|
 * et donner la possibilité à l'utilisateur de l'afficher
 | 
						|
 *
 | 
						|
 * s'utilise de cette façon:
 | 
						|
 * <pre>
 | 
						|
 * $sm = new showmorePlugin();
 | 
						|
 * // le tout doit être dans le container startc-endc
 | 
						|
 * $sm->printStartc();
 | 
						|
 * // l'invite contient un lien pour afficher le panneau caché
 | 
						|
 * $sm->printInvite();
 | 
						|
 * // le panneau caché est dans le container startp-endp
 | 
						|
 * $sm->printStartp();
 | 
						|
 * $sm->printEndp();
 | 
						|
 * $sm->printEndc();
 | 
						|
 * </pre>
 | 
						|
 */
 | 
						|
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";
 | 
						|
 | 
						|
  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;
 | 
						|
 | 
						|
  protected bool $initialShow = false;
 | 
						|
 | 
						|
  function show(bool $show=true): self {
 | 
						|
    $this->initialShow = $show;
 | 
						|
    return $this;
 | 
						|
  }
 | 
						|
 | 
						|
  function startc(): array {
 | 
						|
    return v::sdiv(["class" => $this->containerClass]);
 | 
						|
  }
 | 
						|
  
 | 
						|
  function invite($vs=null): array {
 | 
						|
    $vs ??= $this->inviteContent;
 | 
						|
    return v::a([
 | 
						|
      "class" => [
 | 
						|
        $this->inviteClass,
 | 
						|
        "hidden" => $this->initialShow,
 | 
						|
      ],
 | 
						|
      "href" => "#",
 | 
						|
      $vs,
 | 
						|
    ]);
 | 
						|
  }
 | 
						|
  
 | 
						|
  function startp(): array {
 | 
						|
    return v::sdiv([
 | 
						|
      "class" => [
 | 
						|
        $this->panelClass,
 | 
						|
        "hidden" => !$this->initialShow,
 | 
						|
      ],
 | 
						|
    ]);
 | 
						|
  }
 | 
						|
  
 | 
						|
  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");
 | 
						|
    let $container = $this.closest(".<?=self::CONTAINER_CLASS?>");
 | 
						|
    let $panel = $container.find(".<?=self::PANEL_CLASS?>");
 | 
						|
    $panel.removeClass("hidden");
 | 
						|
    <?=$this->onShow?>
 | 
						|
    return false;
 | 
						|
  });
 | 
						|
});
 | 
						|
</script>
 | 
						|
<?php
 | 
						|
  }
 | 
						|
}
 |