Mercurial > dirlist-php
comparison index.php @ 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 |
comparison
equal
deleted
inserted
replaced
16:3c0b3a38a7fc | 17:8b222e3ffe25 |
---|---|
40 sort($dirs); | 40 sort($dirs); |
41 | 41 |
42 // BEGIN UTILITY | 42 // BEGIN UTILITY |
43 function h($string) { return htmlspecialchars($string, ENT_QUOTES, "UTF-8"); } | 43 function h($string) { return htmlspecialchars($string, ENT_QUOTES, "UTF-8"); } |
44 function a($string) { return preg_replace("#(%2F)+#", "/", rawurlencode($string)); } | 44 function a($string) { return preg_replace("#(%2F)+#", "/", rawurlencode($string)); } |
45 function link_to($target, $title) { | 45 function link_to($target, $title) { return('<a href="' . a($target) . '">' . h($title) . "</a>"); } |
46 $lightbox = ""; | |
47 if (substr($target, -1) !== "/" && preg_match("/(jpe?g|gif|png|webp)$/i", pathinfo($target, PATHINFO_EXTENSION)) === 1) { | |
48 $lightbox = ' data-lightbox="aa" data-title="' . h('<a href="' . a($target) . '">' . h($target) . "</a>") . '" '; | |
49 } | |
50 | |
51 return('<a href="' . a($target) . '"' . $lightbox . ">" . h($title) . "</a>"); | |
52 } | |
53 | 46 |
54 function human_size($size) { | 47 function human_size($size) { |
55 $thousand_units = array("ko", "Mo", "Go", "To", "Po"); | 48 $thousand_units = array("ko", "Mo", "Go", "To", "Po"); |
56 | 49 |
57 $return_format = "%d %s"; | 50 $return_format = "%d %s"; |
203 Running <a href="https://bitbucket.org/edogawaconan/dirlist-php">dirlist-php</a>. | 196 Running <a href="https://bitbucket.org/edogawaconan/dirlist-php">dirlist-php</a>. |
204 Powered by PHP <?php echo phpversion(); ?>. | 197 Powered by PHP <?php echo phpversion(); ?>. |
205 </em> | 198 </em> |
206 | 199 |
207 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | 200 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> |
201 | |
202 <script> | |
203 $("table > tbody > tr > td > a").each(function() { | |
204 if (!this.href.match(/\.(jpe?g|png|gif|webp)$/i)) return | |
205 var title = this.outerHTML | |
206 this.setAttribute("data-title", title) | |
207 this.setAttribute("data-lightbox", "aa") | |
208 }) | |
209 </script> | |
210 | |
208 <script src="//cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/js/lightbox.min.js"></script> | 211 <script src="//cdnjs.cloudflare.com/ajax/libs/lightbox2/2.7.1/js/lightbox.min.js"></script> |
209 </body> | 212 </body> |