changeset 17:8b222e3ffe25

Set lightbox attributes through javascript instead of php.
author edogawaconan <me@myconan.net>
date Wed, 22 Oct 2014 02:37:18 +0900
parents 3c0b3a38a7fc
children 9a4ac2d53a36
files index.php
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/index.php	Wed Oct 22 01:36:37 2014 +0900
+++ b/index.php	Wed Oct 22 02:37:18 2014 +0900
@@ -42,14 +42,7 @@
   // 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) {
-    $lightbox = "";
-    if (substr($target, -1) !== "/" && preg_match("/(jpe?g|gif|png|webp)$/i", pathinfo($target, PATHINFO_EXTENSION)) === 1) {
-      $lightbox = ' data-lightbox="aa" data-title="' . h('<a href="' . a($target) . '">' . h($target) . "</a>") . '" ';
-    }
-
-    return('<a href="' . a($target) . '"' . $lightbox . ">" . h($title) . "</a>");
-  }
+  function link_to($target, $title) { return('<a href="' . a($target) . '">' . h($title) . "</a>"); }
 
   function human_size($size) {
     $thousand_units = array("ko", "Mo", "Go", "To", "Po");
@@ -205,5 +198,15 @@
     </em>
 
   <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+
+  <script>
+    $("table > tbody > tr > td > a").each(function() {
+      if (!this.href.match(/\.(jpe?g|png|gif|webp)$/i)) return
+      var title = this.outerHTML
+      this.setAttribute("data-title", title)
+      this.setAttribute("data-lightbox", "aa")
+    })
+  </script>
+
   <script src="//cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/js/lightbox.min.js"></script>
 </body>