changeset 14:c2a468e9f3ac

Add lightbox support \o/
author edogawaconan <me@myconan.net>
date Wed, 22 Oct 2014 01:12:55 +0900
parents b6b65a5b9c1a
children 3dbddf76760a
files index.php
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/index.php	Wed Oct 22 00:08:07 2014 +0900
+++ b/index.php	Wed Oct 22 01:12:55 2014 +0900
@@ -42,7 +42,14 @@
   // BEGIN UTILITY
   function h($string) { return htmlspecialchars($string, ENT_QUOTES, "UTF-8"); }
   function a($string) { return preg_replace("#(%2F)+#", "/", rawurlencode($string)); }
-  function link_to($target, $title) { return('<a href="' . a($target) . '">' . h($title) . "</a>"); }
+  function link_to($target, $title) {
+    $lightbox = "";
+    if (substr($target, -1) !== "/" && preg_match("/(jpe?g|gif|png|webp)$/i", pathinfo($target, PATHINFO_EXTENSION)) === 1) {
+      $lightbox = ' data-lightbox="aa" ';
+    }
+
+    return('<a href="' . a($target) . '"' . $lightbox . ">" . h($title) . "</a>");
+  }
 
   function human_size($size) {
     $thousand_units = array("ko", "Mo", "Go", "To", "Po");
@@ -119,6 +126,7 @@
   <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
   <title>Index of <?php echo h($prefix . $path); ?></title>
   <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
+  <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/css/lightbox.css">
   <style type="text/css">
     * { box-sizing: border-box; }
     body {
@@ -192,4 +200,7 @@
       Running <a href="https://bitbucket.org/edogawaconan/dirlist-php">dirlist-php</a>.
       Powered by PHP <?php echo phpversion(); ?>.
     </em>
+
+  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+  <script src="//cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/js/lightbox.min.js"></script>
 </body>