These are chat archives for fansoro/fansoro

30th
Apr 2016
xxwebplus
@xxwebplus
Apr 30 2016 06:45
@/all
Happy Easter
Moncho Varela
@nakome
Apr 30 2016 08:44
Gallery Shortcode easy
// Add {gallery folder=public} shortcode
Shortcode::add('gallery', function ($attributes) {
  // Extract attributes
  extract($attributes);
  if (isset($folder)){$folder=$folder;}else{$folder = '';}

  $files = File::scan(ROOT.'/'.$folder);
  $i=0;
  $col = 3;
  $html = '<style>.img-full-container{position:fixed;z-index:999997;top:0;right:0;bottom:0;left:0;display:none;padding:10px;cursor:pointer;text-align:center;border-radius:5px;background-color:#000}.img-full-container img{position:fixed;z-index:999998;top:0;right:0;bottom:0;left:0;overflow:auto;max-width:100%;max-height:100%;margin:auto}.img-full-container .close{font-size:2em;line-height:2em;position:absolute;z-index:999999;top:0;right:0;width:2em;height:2em;cursor:pointer;text-align:center;color:#fff;background-color:#000;opacity:1;}.show-lightbox{display:block}</style>';

  foreach($files as $file){
    $img = Website::url().'/public/'.File::name($file).'.'.File::ext($file);
    if ($i%$col==0) {$html .= '<div class="row">';}
    $i++;
    $html .= '
      <div class="col-md-4">
        <div class="expand">
          <img class="img-responsive" src="'.$img.'" alt="'.File::name($img).'">
        </div><!-- end expand -->
      </div><!-- end col -->
    ';
    if ($i%$col==0) {$html .= '</div><!-- end row -->';}
  }

  $html .='<div class="img-full-container"><img src=""><div class="close">&times;</div></div>
  <script>window.addEventListener("DOMContentLoaded",function(){var e=document.querySelectorAll(".expand img"),t=Array.prototype.slice.call(e),r=document.querySelector(".img-full-container");Array.prototype.forEach.call(t,function(e,t){e.addEventListener("click",function(t){t.preventDefault();var c=e.getAttribute("src");r.classList.add("show-lightbox"),r.querySelector("img").setAttribute("src",c)})}),r.addEventListener("click",function(e){r.classList.remove("show-lightbox"),r.querySelector("img").setAttribute("src","")})});</script>';

  return $html;
});