Supercharged Local Directory File Browser

Makes file:/// directory ("Index of...") pages (and many server-generated index pages) actually useful. Adds navigation links, file preview pane, keyboard navigation, user-defined shortcuts, filtering, more.

当前为 2018-04-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Supercharged Local Directory File Browser
  3. // @version 2.3.0
  4. // @description Makes file:/// directory ("Index of...") pages (and many server-generated index pages) actually useful. Adds navigation links, file preview pane, keyboard navigation, user-defined shortcuts, filtering, more.
  5. // @author Gaspar Schott
  6. // @license GPL-3.0
  7. // @match file:///*
  8. // @require http://code.jquery.com/jquery-latest.min.js
  9.  
  10. // This script was developed in Vivaldi, running on Mac OS High Sierra. It has been tested in various Chrome and Gecko-based browsers. It has only been minimally tested on Windows, however. It should work, but please report any issues.
  11. // It does not work in Safari because Safari does not allow local directories to be browsed.
  12.  
  13. // NOTE: By default, Greasemonkey and Tampermonkey will not run scripts on file:/// urls, so for this script to work, you will have to enable it first.
  14. // For Greasemonkey, open about:config and change greasemonkey.fileIsGreaseable to true.
  15. // For Tampermonkey, go to Chrome extension page, and tick the 'Allow access to file URLs' checkbox at the Tampermonkey extension section.
  16.  
  17. // CHANGELOG:
  18.  
  19. // 2.3.0
  20. // Added: New user settings: default grid image and font sizes. Don't delete them when pasting in your old exported settings!
  21. // Added: Scale grid image items.
  22. // Improved: Better image zooming. Zoomed images now scroll to the area clicked.
  23. // Fixed: Keybinding to toggle invisibles wasn't working.
  24. // Fixed: Image zoom not working.
  25. // Fixed: Hovered background for grid items in dark mode.
  26. // Fixed: Font scaling in dual grids.
  27. // Other bug fixes.
  28.  
  29. // 2.2.0
  30. // Added: Export settings menu item. This will make it easier to save your user settings before updating the script. (Remember, scripts running on local files cannot set cookies or use localStorage, which would make it possible to save user settings automatic.) Unfortunately, there is no mechanism for importing the settings: you'll still have to open the script editor and paste in the exported data.
  31. // Fixed: File extensions were case sensitive, so some valid files wouldn't load if the extension contained capital letters.
  32. // Fixed: File and Dir names were also being lowercased.
  33.  
  34. // v. 2.1.1
  35. // Fixed: Can't type "r" in font previews.
  36. // Other minor bug fixes.
  37.  
  38. // v. 2.1.0
  39. // Added: Toggle Default/Dark modes menu item while browsing current directory; mode reverts to saved setting on dir change.
  40. // Added: White background for images so that images with transparency are visible against the grey background
  41. // Removed trailing "/" from directory display names.
  42. // Fixed an issue where font and image grid display got confused about what content to display.
  43. // Fixed directory names display in dark mode in server pages that use lists instead of tables.
  44. // Better styling for grid button.
  45. // Better styling for grid items in dark mode.
  46. // Bug fixes.
  47. // Remember to copy your user settings before updating!
  48.  
  49. // v. 2.0.2
  50. // Various fixes suggested by "Zorg":
  51. // Dark mode now ignores html files (and media files), but inverts all plain text files. This solution is not perfect: there is a flash of inverted content when navigating from an html or media file to a non-html or media file; will look for a fix.
  52. // Fixed display of non-Latin characters in sidebar header.
  53. // Add support for linux "home" directory for user profile shortcuts
  54. // Made entire up directory button clickable.
  55.  
  56. // v. 2.0.1
  57. // Fixed wonky font preview scaling.
  58.  
  59. // v. 2.0
  60. // NEW! Not just for local directories anymore! Added support for *many* server-generated directory index pages (It's impossible to check every server configuration, needless to say, so it might not work in every case; let me know if you encounter problems.// NEW! Preview font files (otf, ttf, woff, woff2). Great for designers: preview fonts without installing them. Hint: To install previewed fonts, just type Cmd/Ctrl + O or right-click the link and save it to your fonts folder. Font preview pane is content-editable.
  61. // NEW! Preview font files (otf, ttf, woff, woff2). Great for designers: preview fonts without installing them. Hint: To install previewed fonts, just type Cmd/Ctrl + Shift + O or right-click the link and save it to your fonts folder. Font preview pane is content-editable.
  62. // Added: Now use the Left and Right arrow keys to navigate through images and fonts in a folder, skipping other files. Use up and down arrow keys to navigate all files normally.
  63. // Added: Basic dark mode user setting.
  64. // Added: Wrap-around keyboard navigation.
  65. // Added: Cmd/Ctr-D to toggle details.
  66. // Added: Cmd/Ctr-Shift-. and Cmd/Ctr-Shift-, to scale font previews text size.
  67. // Changed: Moved dynamically-added in-line styles to appended stylesheet.
  68. // Changed: Extensive refactoring of code for better separation of concerns. (More needs to be done.... Sigh.)
  69. // Removed: ScrollIntoView for Grid views. Scrolling didn't work reliably when the sidebar was also being scrolled. Will restore when bug fixed.
  70. // Many small bug fixes.
  71.  
  72. // v. 1.4
  73. // Added: Initial support for Firefox. Tested in Firefox 59, Waterfox 56.
  74. // Changed: Use SVG for menu icons
  75. // Changed: Code cleanup, reorganization
  76. // Renamed script to "Supercharged Local Directory File Browser"
  77.  
  78. // v. 1.3
  79. // Fixed: Keyboard navigation of ignored or invisible items fails if "Hide Invisibles" is toggled off after loading a directory.
  80. // Added: Also hide ignored files if "Hide Invisibles" is checked.
  81. // Added: Content reload button.
  82. // Changed: Reorganized settings to reduce confusion about how ignored files are treated.
  83.  
  84. // v. 1.2
  85. // Click to show menus instead of hover.
  86. // Added Cmd/Crl+Shift+O keybinding to open selected item in new window
  87. // Arrow navigation bugfixes
  88.  
  89. // TO-DO:
  90. // Fix grid scrollIntoView
  91. // if invisible item is selected when "hide invisibles" is unchecked, select nearest previous visible item when hide invisible is checked agagin?
  92. // Sort by file extension?
  93. // Select two items for split pane view?
  94.  
  95. // @namespace https://greasyfork.org/users/16170
  96. // ==/UserScript==
  97.  
  98. (function() {
  99. 'use strict';
  100. var $ = jQuery;
  101.  
  102. // ***** USER SETTINGS ***** //
  103.  
  104. var $settings = {
  105.  
  106. // Paste your exported settings between these two lines:
  107. //----------------------------------------------------//
  108.  
  109. user_name: // Your computer user name
  110. 'MacBookPro',
  111. // Shortcuts: add directories and files here. (You can use your browser's bookmarks, of course.)
  112. root_shortcuts: // Root directories: add or remove as you please (but at leave empty brackets). These defaults are applicable to Mac OS.
  113. ['Applications','Library','Users','Volumes'],
  114. // ['C:/Users','C:/Program Files','C:/Windows'],
  115. user_shortcuts: // User directories; you must enter your user_name above.
  116. ['Documents','Downloads','Library','Movies','Music','Pictures'],
  117. file_shortcuts: // Add specific file paths, e.g.: 'Users/MyUserName/Documents/MyDocument.html'
  118. // These files will be selected (loaded) automatically when their containing directory is loaded
  119. // Limitations: only works for one file per directory; if more than one file per directory is listed, the last item will be selected.
  120. ['path/to/file.ext','path/to/another/file.ext'],
  121. ignore_files: // If true, ignored files (see below) will be greyed-out (default) in the file list and will not be loaded in the content pane when selected;
  122. // If false, they will be treated as normal files, so if they are selected, the browser will attempt to download any file types it can't handle (which makes keyboard navigation inconvenient).
  123. true,
  124. ignore_file_types: // ignore files with these extensions:
  125. ['exe','.doc','.docx','ppt','pptx','xls','xlsx','odt','odp','.csv','msi','dll','rtf','indd','idml','.pages','.tif','tiff','.eps','.psd','.ai','.afm','.pfb','.pfm','.tfm','.zip','pkg','.swf','.pls','.ics','.ds_store','ds_store','alias','.dmg','.gz','.qxp','icon.jpg','thumbs.db'], // lowercase
  126. hide_ignored_files: // If true, ignored files will be hidden in the file list;
  127. // if false (default), they will appear greyed-out.
  128. false,
  129. hide_invisibles: // Mac OS only: If true (default), files or directories beginning with a "." will be hidden.
  130. true,
  131. apps_as_dirs: // Mac OS only: if true, treat apps as directories; allows app contents to be browsed. This is the default behavior for Chrome.
  132. // If false (default), treat apps as ignored files.
  133. false,
  134. dark_mode: // If true, gives the content pane a dark background, and inverts html and text content.
  135. false,
  136. grid_image_size: // Default = 150
  137. 150,
  138. grid_font_size: // Default = 1
  139. 1
  140.  
  141. //----------------------------------------------------//
  142. // Paste your exported settings between these two lines.
  143.  
  144. };
  145.  
  146. // ***** END USER SETTINGS ***** //
  147.  
  148. // ***** SETUP ***** //
  149.  
  150. var $userAgent = navigator.userAgent;
  151.  
  152. function platformIsMac() {
  153. return navigator.platform.indexOf('Mac') > -1;
  154. }
  155. function platformIsWin() {
  156. return navigator.platform.indexOf('Win') > -1;
  157. }
  158. function platformIsLinux() {
  159. return navigator.platform.indexOf('Linux') > -1;
  160. }
  161.  
  162. // Don't run script in iframes or files (only directories)
  163. // if ( window.top != window.self ) {
  164. if ( window.frameElement !== null ) {
  165. return;
  166. }
  167. if ( window.location.pathname.slice(-1) != '/') {
  168. // $('body').attr('contentEditable','true');
  169. return;
  170. }
  171.  
  172. var $body = $('body');
  173. // add lang attr, remove some unneeded default elements
  174. $body.attr('lang','en').find('> h1:contains("Index of"),> #parentDirLinkBox,> #UI_goUp,#UI_showHidden').remove();
  175.  
  176. var $location = decodeURIComponent(window.location.pathname);
  177. var $current_dir_path = $location.replace(/%20/g,' ').replace(/\//g,'/<wbr>').replace(/_/g,'_<wbr>').replace(/—/g,'—<wbr>').replace(/\\/g,'/');
  178. var $current_dir_name = $location.replace(/%20/g,' ').slice(0,-1);
  179. $current_dir_name = $current_dir_name.slice($current_dir_name.lastIndexOf('/') + 1);
  180. var $location_arr = $location.split('/');
  181. var $parent_dir_link = $location_arr.slice(0,-2).join('/') + '/';
  182.  
  183. var e, i, n;
  184. var $this_link;
  185.  
  186. var $dir_table;
  187. var $dir_table_type;
  188. var $dir_table_head;
  189. var $dir_table_head_cell;
  190. var $dir_table_head_name;
  191. var $dir_table_head_details;
  192. var $dir_table_body;
  193. var $dir_table_row;
  194. var $dir_table_cell;
  195. var $dir_table_item_name;
  196. var $dir_table_details;
  197. var $dir_table_item_icon;
  198. var $dir_table_link;
  199. var $dir_table_rule;
  200. var $selected;
  201.  
  202. if ( $body.find('> table').length > 0 ) {
  203. $dir_table = $body.find('> table');
  204. $dir_table.addClass('table');
  205. } else {
  206. $dir_table = $body.find('> ul');
  207. $dir_table.add('body').addClass('list');
  208. }
  209.  
  210. // ***** BUILD UI ELEMENTS ***** //
  211.  
  212. // ***** SIDEBAR ELEMENTS ***** //
  213.  
  214. // 1. Parent Directory Menu
  215. var $parent_dir_menu = $('<nav id="parent_dir_menu"><a href="">&nbsp;</a></nav>');
  216. $parent_dir_menu.find('a').attr('href',$parent_dir_link);
  217. // 2. Current Directory Name and Parents Directory Menu
  218. var $parents_dir_menu = $('<nav id="parents_dir_menu"><div></div></nav><ul class="menu"></ul>');
  219. $parents_dir_menu.find('div').append( $current_dir_path );
  220. // 3. Shortcuts Menu
  221. var $divider = $('<li><hr></li>');
  222. var $shortcuts_menu = $('<nav id="shortcuts_menu"><div>&nbsp;</div></nav><ul class="menu"></ul>');
  223. // 3.B Other Menu Items
  224. var $toggle_dark_mode = $('<li id="toggle_dark_mode_menu_item"><a href="#"><span id="dark_theme">Dark Theme</span><span id="default_theme">Default Theme</span></a></li>');
  225. var $export_settings = $('<li><a id="export_settings" href="#">Export Settings</a></li>');
  226. // 4. Details Button
  227. var $details_btn = $('<button id="details_btn" tabindex="-1"><span>Show details</span><span>Hide details</span></button>');
  228. // 5. Invisibles Checkbox
  229. var $inv_checkbox = $('<label ><input type="checkbox" id="inv_checkbox" for="inv_checkbox" name="inv_checkbox" tabindex="-1" />Hide Invisibles</label>');
  230. // 6. Image Grid Button
  231. var $grid_btn = $('<div id="grid_btn" tabindex="-1" title="Show Grid"><ul class="menu"><li id="show_image_grid">Show Image Grid</li><li id="show_font_grid">Show Font Grid</li></ul></div>');
  232. // 7. Sidebar Header Element
  233. var $sidebar_header = $('<table id="sidebar_header"><thead><tr><th colspan="3">INDEX OF</th></tr></thead><tbody><tr><td></td><td></td><td></td></tr><tr><td colspan="3"></td></tr></tbody></table>');
  234. $sidebar_header.find('tbody tr:nth-child(1)').find('td').first().append( $parent_dir_menu ).next().append( $parents_dir_menu ).next().append( $shortcuts_menu );
  235. $sidebar_header.find('tbody tr:last-child td').append( $details_btn, $inv_checkbox, $grid_btn );
  236.  
  237. var $dir_table_wrapper = $('<div id="dir_table_wrapper"></div>');
  238. // 8. Sidebar
  239. var $sidebar = $('<div id="sidebar"></div>');
  240. $sidebar.append($sidebar_header);
  241. // 9. Resize Handle
  242. var $handle = $('<div id="handle"></div>');
  243. // 10. Assemble Sidebar Elements
  244. var $sidebar_wrapper = $('<td id="sidebar_wrapper"></td>');
  245. $sidebar_wrapper.append( $sidebar, $handle );
  246.  
  247. // ***** END SIDEBAR ELEMENTS ***** //
  248.  
  249. // ***** CONTENT PANE ELEMENTS ***** //
  250.  
  251. // 1. Reload Button Element
  252. var $content_reload_btn = $('<td><button id="reload_btn" tabindex="-1">Reload</button></td>');
  253. // 2. Title Element
  254. var $content_title = $('<td id="content_title"></td>');
  255. // 3. Close Button Element
  256. var $content_close_btn = $('<td><button id="close_btn" tabindex="-1">Close</button></td>');
  257. // 4. Content Header Element
  258. var $content_header = $('<header id="content_header"><table><tbody><tr></tr></tbody></table></header>');
  259. $content_header.find('tr').append($content_reload_btn, $content_title, $content_close_btn);
  260. // 5. Content Mask Element
  261. var $content_mask = $('<div id="content_mask""></div>');
  262. // 6. Image Grid Element
  263. var $content_grid = $('<div id="content_grid" data-grid-scale-factor="0"></div>');
  264. // 7. Content grid items
  265. var $image_grid_item_el = $('<div class="image_grid_item"><a href=""><img src="" /></a></div>');
  266. var $font_grid_item_el = $('<div class="font_grid_item"></div>');
  267. var $content_font_size = $('<div id="font_size"><span id="increase"></span><span id="decrease"></span></div>');
  268. // 8. Image Element
  269. var $image = $('<img src="" class="" />');
  270. var $content_image = $('<div id="content_image"></div>');
  271. $content_image.append($image);
  272. // 9. Pdf (embed) Element
  273. var $content_embed = $('<embed id="content_embed" name="plugin" type="application/pdf" tabindex="0"></embed>');
  274. // 10. Iframe Element
  275. var $content_iframe = $('<iframe id="content_iframe" sandbox="allow-scripts allow-same-origin allow-modals" tabindex="0"></iframe>');
  276. // 11. Font Element
  277. var $sample_string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ<br />abcdefghijklmnopqrstuvwxyz<br />0123456789 [(!@#$%^&*;:)]';
  278. var $lorem_string = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
  279. var $specimen;
  280. // function specimen() {
  281. // var $specimen_arr = [];
  282. // for ( i = 0; i < 4; i+=1 ) {
  283. // $specimen = '<div class="specimen" style="font-size:'+ (i * 12) +'pt;">'+ $sample_string +'</div><div class="lorem_first" style="font-size:'+ (i * 6) +'pt;">'+ $lorem_string +'</div><div class="lorem" style="font-size:'+ (i * 6) +'pt;">'+ $lorem_string +'</div><div class="lorem" style="font-size:'+ (i * 6) +'pt;">'+ $lorem_string +'</div>';
  284. // $specimen_arr.push($specimen);
  285. // }
  286. // $specimen_arr = $specimen_arr.reverse().join().replace(/,/g,'');
  287. // return $specimen_arr;
  288. // }
  289. // Use specimen() in $content_font in place of $specimen for 5 different sizes of $sample_string.
  290. $specimen = '<div class="specimen" style="font-size:3em;">'+ $sample_string +'</div><hr><div class="lorem first" style="font-size:1em;">'+ $lorem_string +'</div><div class="lorem" style="font-size:1em;">'+ $lorem_string +'</div><div class="lorem" style="font-size:1em;">'+ $lorem_string +'</div>';
  291. var $lorem = $('.lorem');
  292. var $content_font = $('<div id="content_font" spellcheck="false" contenteditable="true">'+ $specimen +'</div>');
  293.  
  294. // 12. Next/Prev Elements
  295. var $prev_btn = $('<div id="prev_btn"></div>');
  296. var $next_btn = $('<div id="next_btn"></div>');
  297. // 13. Content container
  298. var $content_container = $('<section id="content_container"></section>');
  299. $content_container.append( $content_header, $content_font_size, $content_mask, $content_grid, $content_image, $content_embed, $content_iframe, $content_font );
  300.  
  301. // 14. Assemble Content Pane Elements
  302. var $content_pane = $('<td id="content_pane"></td>');
  303. $content_pane.append( $content_container, $prev_btn, $next_btn );
  304.  
  305. // ***** END BUILD UI ELEMENTS ***** //
  306.  
  307. // ***** STYLES ***** //
  308.  
  309. var $custom_font_styles = document.createElement('style');
  310. $custom_font_styles.appendChild(document.createTextNode(""));
  311. document.head.append($custom_font_styles);
  312.  
  313. var $font_styles = '';
  314. $custom_font_styles.append( $font_styles );
  315.  
  316. var $custom_styles = document.createElement("style");
  317. $custom_styles.appendChild(document.createTextNode(""));
  318.  
  319. var $grid_image_size = $settings.grid_image_size ? $settings.grid_image_size : 150;
  320. var $grid_font_size = $settings.grid_font_size ? $settings.grid_font_size : 1;
  321.  
  322. var $up_arrow = 'url("data:image/svg+xml;utf8,<svg version=\'1.1\' id=\'Layer_1\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\' x=\'0px\' y=\'0px\' width=\'12.728px\' height=\'7.779px\' viewBox=\'0 0 12.728 7.779\' enable-background=\'new 0 0 12.728 7.779\' xml:space=\'preserve\'><path fill=\'%23444444\' d=\'M6.364,2.828l4.95,4.949l1.414-1.414L6.364,0l0,0L0,6.363l1.413,1.416L6.364,2.828\'/></svg>")';
  323. var $svg_arrow = 'url("data:image/svg+xml;utf8,<svg version=\'1.1\' id=\'Layer_1\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\' x=\'0px\' y=\'0px\' width=\'11px\' height=\'16px\' viewBox=\'234.5 248 11 16\' enable-background=\'new 234.5 248 11 16\' xml:space=\'preserve\'><path d=\'M245.5,261l-3,3l-8-8l8-8l3,3l-5,5L245.5,261z\'/></svg>")';
  324. var $menu_icon = 'url("data:image/svg+xml;utf8,<svg version=\'1.1\' id=\'Layer_1\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\' x=\'0px\' y=\'0px\' width=\'13px\' height=\'10px\' viewBox=\'0 0 13 10\' enable-background=\'new 0 0 13 10\' xml:space=\'preserve\'><rect fill=\'%23444444\' width=\'13\' height=\'2\'/><rect y=\'4\' fill=\'%23444444\' width=\'13\' height=\'2\'/><rect y=\'8\' fill=\'%23444444\' width=\'13\' height=\'2\'/></svg>")';
  325. var $grid_icon = 'url("data:image/svg+xml;utf8,<svg version=\'1.1\' id=\'Layer_1\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\' x=\'0px\' y=\'0px\' width=\'16px\' height=\'16px\' viewBox=\'0 0 16 16\' enable-background=\'new 0 0 16 16\' xml:space=\'preserve\'><g><path fill=\'%23666666\' d=\'M5,2v3H2V2H5 M7,0H0v7h7V0L7,0z\'/></g><g><path fill=\'%23666666\' d=\'M14,2v3h-3V2H14 M16,0H9v7h7V0L16,0z\'/></g><g><path fill=\'%23666666\' d=\'M5,11v3H2v-3H5 M7,9H0v7h7V9L7,9z\'/></g><g><path fill=\'%23666666\' d=\'M14,11v3h-3v-3H14 M16,9H9v7h7V9L16,9z\'/></g></svg>")';
  326. var $plus_sign = 'url("data:image/svg+xml;utf8,<svg version=\'1.1\' baseProfile=\'basic\' id=\'Layer_1\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\' x=\'0px\' y=\'0px\' width=\'16px\' height=\'16px\' viewBox=\'0 0 16 16\' xml:space=\'preserve\'><polygon points=\'16,6.5 9.5,6.5 9.5,0 6.5,0 6.5,6.5 0,6.5 0,9.5 6.5,9.5 6.5,16 9.5,16 9.5,9.5 16,9.5 \'/></svg>")';
  327. var $minus_sign = 'url("data:image/svg+xml;utf8,<svg version=\'1.1\' baseProfile=\'basic\' id=\'Layer_1\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\' x=\'0px\' y=\'0px\' width=\'16px\' height=\'16px\' viewBox=\'0 0 16 16\' xml:space=\'preserve\'> <rect x=\'1\' y=\'6.499\' width=\'14\' height=\'3.001\'/> </svg>")';
  328.  
  329. var $styles = '';
  330.  
  331. $styles += 'html, body, :root { margin:0; padding:0; max-width:100%; height:100%; font-family:lucidagrande,"fira sans",helvetica,sans-serif; font-size:13px !important; hyphens:auto; overflow:hidden; border-radius:0; box-sizing:border-box; }';
  332. $styles += 'ul { -webkit-margin-before:0em !important; -webkit-margin-after:0em !important; -webkit-padding-start:0em; }';
  333. $styles += 'hr { margin:0; border-bottom:0; }';
  334.  
  335. // SIDEBAR
  336. $styles += '#sidebar_wrapper { width:25%; min-width:220px; will-change:width; padding:0; position:relative; border:0; background:lightgray; overflow:hidden; }';
  337. $styles += '#sidebar { background-color:lightgray; height:'+ window.innerHeight +'px; min-height:100%; overflow-wrap:break-word; box-sizing:border-box; border-right:solid 1px gray; font-size:0.875em; color:#333; overflow:hidden; }';
  338. $styles += '#handle { width:8px; position:absolute; top:0; right:-4px; bottom:0; z-index:1000; cursor:col-resize; }';
  339.  
  340. // Sidebar Header
  341. $styles += '#sidebar_header { width:100%; height:auto; position:relative; border:0; user-select:none; border-collapse:collapse; font-size:0.875rem; }';
  342. $styles += '#sidebar_header thead tr, #sidebar_header tbody tr:first-of-type { border-bottom:solid 1px grey; background-color:#BBB; }';
  343. $styles += '#sidebar_header thead th { padding:4px; font-weight:normal; font-size:0.875em; letter-spacing:0.5em; cursor:default; }';
  344. $styles += '#sidebar_header tbody tr { position:relative; }';
  345. $styles += '#sidebar_header tbody tr:first-of-type td:hover { cursor:pointer; }';
  346. $styles += '#sidebar_header tbody tr:first-of-type td:first-of-type { position:relative; }';
  347. $styles += '#sidebar_header tbody tr:first-of-type td:nth-of-type(odd) { width:24px; max-width:24px; min-width:24px; padding:0; }';
  348. $styles += '#sidebar_header tbody tr:first-of-type td:nth-of-type(even) { width:100%; padding:0; border-left:solid 1px grey; border-right:solid 1px grey; }';
  349. $styles += '#sidebar_header tbody tr:last-of-type td { padding:1em 0; vertical-align:middle; position:relative; white-space:normal; }';
  350.  
  351. // Menus
  352. $styles += '#parent_dir_menu { margin:0; padding:0; display:block; position:absolute; top:0; right:0; bottom:0; left:0; }';
  353. $styles += '#parent_dir_menu a { width:100%; height:100%; padding:0; display:block; text-align:center; vertical-align:middle; text-decoration:none; opacity:0.7; background:' + $up_arrow + 'center no-repeat; }';
  354.  
  355. $styles += '#parents_dir_menu { margin:0; padding:0; height:auto; text-align:center; }';
  356. $styles += '#parents_dir_menu div { padding:4px 6px; height:auto; display:inline-block; text-align:center; vertical-align:middle; overflow:hidden; cursor:pointer; hyphens:none; white-space:normal; }';
  357. $styles += '#parents_dir_menu + ul { display:none; margin:0; padding:0; position:absolute; right:0; left:0; z-index:100; text-indent:0; text-align:left; background:lightgray; border-top:solid 1px gray; border-bottom:solid 1px gray; list-style-type:none; box-shadow: 0px 2px 3px -2px #888; }';
  358. $styles += '#parents_dir_menu + ul li:hover, #shortcuts_menu + ul li:hover { background:#BBB; }';
  359. $styles += '#parents_dir_menu + ul li a, #shortcuts_menu + ul li a { margin:0; padding:4px 6px; display:block; text-indent:0; text-decoration:none; color:#333; white-space:normal; }';
  360.  
  361. $styles += '#shortcuts_menu { margin:0; padding:0; }';
  362. $styles += '#shortcuts_menu div { width:6em; display:table-cell; text-align:center; vertical-align:middle; font-size:18px; cursor:pointer; opacity:0.7; background:'+ $menu_icon + 'center no-repeat; }';
  363. $styles += '#shortcuts_menu + ul { margin:0; padding:0; -webkit-margin-before:0em !important; -webkit-margin-after:0em !important; -webkit-padding-start:0em; position:absolute; right:0; left:0; z-index:100; text-indent:0; text-align:left; background:lightgray; border-top:solid 1px gray; border-bottom:solid 1px gray; list-style-type:none; box-shadow: 0px 2px 3px -2px #888; display:none; }';
  364. $styles += '#shortcuts_menu div, #parent_dir_menu, #prev_btn, #next_btn { opacity:0.7; }';
  365. $styles += '#dark_theme { display:block; }';
  366. $styles += '#default_theme { display:none; }';
  367.  
  368. // Details Button
  369. $styles += '#details_btn { margin:0 0.5em; }';
  370. $styles += '#details_btn span:last-of-type { display:none; }';
  371. $styles += 'body.list #details_btn { color:#999; background:#EEE; outline:none; }';
  372.  
  373. // Grid Button
  374. $styles += '#grid_btn { margin:0; width:28px; height:18px; display:none; float:right; cursor:pointer; outline:0; background:'+ $grid_icon +' no-repeat center 100%; }';
  375. $styles += '#grid_btn .menu { padding-right:29px; padding-left:0; position:absolute; top:-1px; right:0; border:solid grey; border-width: 1px 0 1px 1px; display:none; }';
  376. $styles += '#grid_btn .menu li { width:100%; padding:4px 6px; background:#CCC; display:block; float:right; clear:both; text-align:right; list-style:none; border-right:solid 1px grey; box-sizing:border-box; white-space:pre;}';
  377. $styles += '#grid_btn .menu li:first-of-type { border-bottom:solid 1px grey; }';
  378. $styles += '#grid_btn:hover, #sidebar_header tbody tr:first-of-type td:last-of-type:hover div, #parent_dir_menu:hover, #prev_btn:hover, #next_btn:hover { opacity:1; }';
  379. $styles += '#grid_btn.has_images, #grid_btn.has_fonts { display:inline-block; }';
  380. $styles += '#grid_btn.has_images.has_fonts:hover ul.menu { display:block !important; }';
  381. $styles += '#grid_btn.has_images.has_fonts:hover ul.menu li:hover { background:#BBB; }';
  382.  
  383. // Sidebar dir_table
  384. $styles += '#dir_table.table { width:100%; min-wdth:100px; border:0; position:relative; overflow:hidden; table-layout:fixed; border-collapse:collapse; font-size:0.875rem; }';
  385. $styles += '#dir_table.table thead { width:100%; position:absolute; left:0; right:0; text-align:left; }';
  386. $styles += '#dir_table.table thead th { padding:0 24px 4px; }';
  387. $styles += '#dir_table.table thead .name { padding-left:2em; display:block; }';
  388. $styles += '#dir_table.table > tbody { width:100%; position:absolute; right:0; bottom:0; left:0; overflow-y:auto; outline:0; }';
  389. $styles += '#dir_table.table tbody .name { display:block; clear:right; text-align:left; }';
  390. $styles += '#dir_table.table tbody tr { display:block; margin-inline-start:0; clear:both; }';
  391. $styles += '#dir_table.table tbody a { margin:0; display:block; background-size:auto 13px; -webkit-padding-start:2m; padding: 4px 6px 4px 24px; color:#333; text-decoration:none; outline:none; overflow:hidden; background-position:6px 4px; white-space:normal; }';
  392. $styles += '#dir_table.table #thead .name a { padding:0; }';
  393. $styles += '#dir_table.table .icon img { margin-left:1rem; height:16px; }';
  394. $styles += '#dir_table.table .icon + td.name a { -webkit-padding-start:1em; padding-left:6px; }';
  395. $styles += '#dir_table.table .details, #dir_table.table.firefox #tbody > tr > td:not(:first-of-type) { display:none; padding:0 0 4px 24px; font-size:0.875em; text-align:left; vertical-align:top; float:left; }';
  396. $styles += '#dir_table.table .details a { padding:0; }';
  397. $styles += '#dir_table.table .rule { display:none; }';
  398. $styles += '#dir_table.table.show_details .details, #dir_table.table.firefox.show_details #tbody > tr > td:not(:first-of-type) { display:block; }';
  399. $styles += '#dir_table.table.headless > tbody { top:0 !important; }';
  400. $styles += '#dir_table.table.headless .icon { vertical-align:middle; float:left; }';
  401. $styles += '#dir_table.table.firefox #tbody > tr > td:not(:first-of-type) { padding:0 24px 4px; }';
  402. $styles += '#dir_table.table.firefox #tbody > tr > td:last-of-type { text-indent:6px; }';
  403.  
  404. // dir_table.list
  405. $styles += '#dir_table_wrapper { width:100%; min-width:100px; border:0; position:relative; overflow-y:auto; }';
  406. $styles += '#dir_table.list #dir_table_wrapper { padding-top:6px; }';
  407. $styles += '#dir_table.list { width:100%; position:absolute; overflow-y:auto; list-style:none; -webkit-margin-before:0; -webkit-margin-after:0; -webkit-padding-start:0; font-size:0.875rem; line-height:1.4; }';
  408. $styles += '#dir_table.list li a { display:block; padding:3px 1rem; text-decoration:none; color:#333; }';
  409. $styles += '#dir_table.list li.dir a { padding-left:24px; background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAd5JREFUeNqMU79rFUEQ/vbuodFEEkzAImBpkUabFP4ldpaJhZXYm/RiZWsv/hkWFglBUyTIgyAIIfgIRjHv3r39MePM7N3LcbxAFvZ2b2bn22/mm3XMjF+HL3YW7q28YSIw8mBKoBihhhgCsoORot9d3/ywg3YowMXwNde/PzGnk2vn6PitrT+/PGeNaecg4+qNY3D43vy16A5wDDd4Aqg/ngmrjl/GoN0U5V1QquHQG3q+TPDVhVwyBffcmQGJmSVfyZk7R3SngI4JKfwDJ2+05zIg8gbiereTZRHhJ5KCMOwDFLjhoBTn2g0ghagfKeIYJDPFyibJVBtTREwq60SpYvh5++PpwatHsxSm9QRLSQpEVSd7/TYJUb49TX7gztpjjEffnoVw66+Ytovs14Yp7HaKmUXeX9rKUoMoLNW3srqI5fWn8JejrVkK0QcrkFLOgS39yoKUQe292WJ1guUHG8K2o8K00oO1BTvXoW4yasclUTgZYJY9aFNfAThX5CZRmczAV52oAPoupHhWRIUUAOoyUIlYVaAa/VbLbyiZUiyFbjQFNwiZQSGl4IDy9sO5Wrty0QLKhdZPxmgGcDo8ejn+c/6eiK9poz15Kw7Dr/vN/z6W7q++091/AQYA5mZ8GYJ9K0AAAAAASUVORK5CYII= ") 6px 4px no-repeat; background-size:auto 13px; }';
  410. $styles += '#dir_table.list li.file a { padding-left:24px; background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAABHUlEQVR42o2RMW7DIBiF3498iHRJD5JKHurL+CRVBp+i2T16tTynF2gO0KSb5ZrBBl4HHDBuK/WXACH4eO9/CAAAbdvijzLGNE1TVZXfZuHg6XCAQESAZXbOKaXO57eiKG6ft9PrKQIkCQqFoIiQFBGlFIB5nvM8t9aOX2Nd18oDzjnPgCDpn/BH4zh2XZdlWVmWiUK4IgCBoFMUz9eP6zRN75cLgEQhcmTQIbl72O0f9865qLAAsURAAgKBJKEtgLXWvyjLuFsThCSstb8rBCaAQhDYWgIZ7myM+TUBjDHrHlZcbMYYk34cN0YSLcgS+wL0fe9TXDMbY33fR2AYBvyQ8L0Gk8MwREBrTfKe4TpTzwhArXWi8HI84h/1DfwI5mhxJamFAAAAAElFTkSuQmCC") 6px 4px no-repeat; background-size:auto 13px; }';
  411.  
  412. $styles += '#dir_table tr, #dir_table li { background:transparent; }';
  413. $styles += '#dir_table > tbody tr:hover, #dir_table li:hover, #dir_table .hovered { background:#BBB; }';
  414.  
  415. $styles += '#dir_table tr.selected, #dir_table li.selected { background:lightsteelblue; }';
  416. $styles += '#dir_table tr.selected a, #dir_table li.selected a { font-weight:bold; color:#333; }';
  417. $styles += 'body.blur_sidebar tr.selected { background-color:#BBB; }';
  418. $styles += 'body.blur_sidebar tr.selected a { font-weight:normal; color:#444; }';
  419.  
  420. $styles += '#dir_table tr.ignore a, #dir_table tr.ignore.app a { color:#888; }';
  421. $styles += '#dir_table.hide_invisibles .invisible { display:none !important; }';
  422. $styles += '#dir_table.hide_ignored tr.ignore { display:none !important; }';
  423.  
  424. // CONTENT PANE STYLES
  425. $styles += '#content_pane { width:75%; will-change:width; padding:0; border:0; background:#FFF; position:relative; }';
  426. $styles += '#content_container { width:100%; height:100%; top:0; overflow:visible; }';
  427. // Content pane header
  428. $styles += '#content_header { width:100%; display:none; position:absolute; top:0; right:0; left:0; z-index:200; background:lightgray; border-bottom:solid 1px #AAA; font-size:0.875em; color:#333; text-align:center; }';
  429. $styles += '#content_header table { width:100%; padding:7px 12px 5px; border-collapse:collapse; font-size:0.875rem; }';
  430. $styles += '#content_header td:first-of-type, #content_header td:last-of-type { width:6em; padding:4px 6px 3px; vertical-align:middle; }';
  431. $styles += '#content_header td:first-of-type { float:left; text-align:left; }';
  432. $styles += '#content_header td:last-of-type { float:right; text-align:right; }';
  433. $styles += '#content_header td button { word-break:none; hyphens:none; }';
  434. $styles += '#content_title { padding:4px 1em 3px; vertical-align:middle; word-break:break-word; text-align:center; }';
  435. $styles += '#content_pane[class*="content"] #content_header { display:block !important; }';
  436. // Content mask style
  437. $styles += '#content_mask { height:'+ window.innerHeight + 'px; position:absolute; top:0; right:0; bottom:0; left:0; display:none; z-index:9998; }';
  438. // Font size button
  439. $styles += '#font_size { background:rgba(128,128,128,0.3); position:absolute; right:1rem; opacity:0; transition:opacity 1s ease-in-out; display:block; z-index:10; }';
  440. $styles += '#font_size span { width:2rem; height:2rem; font-size:2rem; display:block; text-align:center; cursor:pointer; }';
  441. $styles += '#font_size span:first-of-type { opacity:0.3; background:'+ $plus_sign +' center no-repeat; }';
  442. $styles += '#font_size span:last-of-type { opacity:0.3; background:'+ $minus_sign +' center no-repeat; }';
  443. $styles += '#font_size span:hover { opacity:0.5; filter:invert(100%); background-color:#666; }';
  444. $styles += '#content_pane.has_font_content:hover #font_size, #content_pane.has_grid_content:hover #font_size { display:block; opacity:1; }';
  445. // Image preview styles
  446. $styles += '#content_image {padding:2em; position:absolute; top:0; right:0; bottom:0;left:0; display:none; background:#333; overflow:auto; text-align:center;}';
  447. $styles += '#content_image img:not(.zoom_img) {width:auto; height:auto; max-width:100%; max-height:100%; max-height:calc(100% - 3px); cursor:zoom-in; -webkit-user-select:none; position:relative; top:50%; transform:translateY(-50%); background:#FFF; };';
  448. $styles += '#content_image img.zoom_img { max-width:none; max-height:none; cursor:zoom-out; top:0; transform:translateY(0); }';
  449. // Embed (pdf) and iframe styles
  450. $styles += '#content_embed, #content_iframe { width:100%; height:100%; padding:0; position:absolute; top:0; right:0; bottom:0; left:0; border:0; display:none; }';
  451. // Grid styels
  452. $styles += '#content_grid { width:auto; display:none; position:absolute; right:0; bottom:0; left:0; overflow:auto; font-size:1em; background:#333; grid-gap:0; grid-template-columns:repeat(auto-fit, minmax('+ $grid_image_size +'px, 1fr)); grid-template-rows:repeat(auto, minmax('+ $grid_image_size +'px, 1fr)); z-index:1; }';
  453. $styles += '#content_grid .image_grid_item { display:inline-block; width:'+ $grid_image_size +'px; height:'+ $grid_image_size +'px; float:left; text-align:center; vertical-align:middle; }';
  454. $styles += '#content_grid.not(.has_grid) .image_grid_item.selected { background:#666; }';
  455. $styles += '#content_grid div img { width:auto; height:auto; max-width:'+ ($grid_image_size - $grid_image_size/8) +'px; max-height:'+ ($grid_image_size - $grid_image_size/8) +'px; position:relative; top:50%; transform:translateY(-50%); opacity:0.8; } ';
  456. $styles += '#content_grid:not(.has_grid) .image_grid_item:hover, #content_grid:not(.has_grid) div.image_grid_item.hovered { background:#555; }';
  457. $styles += '#content_grid .font_grid_item { width:calc(100% - 2rem); padding:0rem 1rem 0.5rem; display:block; font-size:'+ $grid_font_size * 3 +'em; text-align:left; outline:none; clear:both; }';
  458. $styles += 'body #content_grid .font_grid_item:hover, body #content_grid div.font_grid_item.hovered { background:#DDD; }';
  459. $styles += 'body #content_grid .font_grid_item.selected { background:#CCC; }';
  460. $styles += 'body #content_grid div.selected { background:#CCC; }';
  461. $styles += 'body #content_grid div:hover, body #content_grid div.hovered { background:#DDD; }';
  462. // Font preview styles
  463. $styles += '#content_font { padding:1rem; display:none; position:absolute; right:0; bottom:0; left:0; overflow:auto; font-size:'+ $grid_font_size +'em; word-break:break-all; overflow-wrap:break-word; hyphens:none; outline:none; }';
  464. $styles += '.specimen { padding-bottom:0.25em; white-space:normal; text-align:left; }';
  465. $styles += '.lorem { margin-bottom:1em; text-align:justify; word-break:normal; white-space:normal; overflow-wrap:normal; hyphens:auto; line-height: 1.4; }';
  466. $styles += '.lorem.first { margin-top:0.5em; }';
  467. $styles += '.lorem.first:first-line { letter-spacing:1pt; font-variant:small-caps; font-size:'+ $grid_font_size*1.33 +'em; }';
  468. $styles += '.lorem + .lorem { columns:2; column-gap:1em;}';
  469. $styles += '.lorem + .lorem + .lorem { margin-bottom:2em; columns:3; }';
  470. // Prev and Next buttons
  471. $styles += '#prev_btn, #next_btn { padding:0 1em; display:none; position:absolute; top:0; bottom:0; z-index:100; opacity:0.6; filter:invert(50%); background: ' + $svg_arrow + ' no-repeat center; }';
  472. $styles += '#prev_btn { left:0 !important; }';
  473. $styles += '#next_btn { right:0; transform:rotate(180deg); }';
  474. $styles += '#content_pane.has_image_content #prev_btn, #content_pane.has_image_content #next_btn { display:block !important; }';
  475. // Display preview content
  476. $styles += '#content_pane.has_font_content #content_font { display:block; }';
  477. $styles += '#content_pane.has_image_content #content_image { display:block; }';
  478. $styles += '#content_pane.has_pdf_content #content_embed { display:block; }';
  479. $styles += '#content_pane.has_file_content #content_iframe { display:block; }';
  480. $styles += '#content_grid.has_image_grid { padding-bottom:1rem; display:grid !important; }';
  481. $styles += '#content_grid.has_font_grid, #content_grid.has_grid { background:#FFF; display:block !important; }';
  482. $styles += '#content_pane[class*="hidden"] #content_grid { display:none !important; z-index:auto; }';
  483.  
  484. // DARK THEME STYLES
  485. $styles += 'body.dark_mode #sidebar, body.dark_mode #content_header { background:#555; }';
  486. $styles += 'body.dark_mode #sidebar ul.menu { background:#444; box-shadow-color:#111; }';
  487. $styles += 'body.dark_mode #sidebar ul.menu li:hover { background:#666; }';
  488. $styles += 'body.dark_mode #sidebar { border-right-color:#111; }';
  489. $styles += 'body.dark_mode #sidebar_header thead tr, body.dark_mode #sidebar_header tbody tr:first-of-type { border-bottom:solid 1px black; background-color:#444; }';
  490. $styles += 'body.dark_mode #sidebar_header tbody tr:first-of-type td:nth-of-type(even) { border-left-color:#111; border-right-color:#111; }';
  491. $styles += 'body.dark_mode #sidebar_header .menu { border-top-color:#111; }';
  492. $styles += 'body.dark_mode #sidebar_header .menu, body.dark_mode #content_header { border-bottom-color:#111; }';
  493. $styles += 'body.dark_mode #sidebar tr *, body.dark_mode #sidebar li, body.dark_mode #sidebar li a, body.dark_mode #content_header tr { color:#EEE !important; }';
  494. $styles += 'body.dark_mode #details_btn span { color:#333 !important; }';
  495. $styles += 'body.dark_mode #dark_theme { display:none; }';
  496. $styles += 'body.dark_mode #default_theme { display:block; }';
  497.  
  498. $styles += 'body.dark_mode #sidebar #grid_btn, body.dark_mode #grid_btn .menu, body.dark_mode #parent_dir_menu, body.dark_mode #shortcuts_menu { filter:invert(100%); }';
  499. $styles += 'body.dark_mode #sidebar #grid_btn ul.menu { background:transparent; border: solid #111; border-width: 1px 0 1px 1px; box-shadow:none !important; }';
  500. $styles += 'body.dark_mode #sidebar #grid_btn .menu li { background:#555; border-right-color: #111; }';
  501. $styles += 'body.dark_mode #sidebar #grid_btn .menu li:first-of-type { border-bottom-color: #111; }';
  502. $styles += 'body.dark_mode #sidebar #grid_btn .menu li:hover { background:#777; }';
  503.  
  504. $styles += 'body.dark_mode #dir_table tr.selected,body.dark_mode #dir_table li.selected { background:slategray !important; }';
  505. $styles += 'body.dark_mode #dir_table tr:hover,body.dark_mode #dir_table li:hover { background:#777 !important; }';
  506.  
  507. $styles += 'body.dark_mode #content_pane, body.dark_mode #content_grid { background:#333; }';
  508. $styles += 'body.dark_mode #content_font, body.dark_mode .font_grid_item { color:#CCC; }';
  509. $styles += 'body.dark_mode #content_grid .font_grid_item.selected, body.dark_mode #content_grid .image_grid_item.selected { background:#666 !important }';
  510. $styles += 'body.dark_mode .font_grid_item:hover, body.dark_mode .font_grid_item.hovered, body.dark_mode .image_grid_item:hover, body.dark_mode .image_grid_item.hovered { background:#555 !important; }';
  511. $styles += 'body.dark_mode #content_pane.has_font_content hr { border-bottom-color:#CCC; }';
  512. $styles += 'body.dark_mode #content_iframe { filter:invert(87.5%); }';
  513. // Files with these extensions in iframes should not be inverted in dark mode:
  514. var $excluded = ['.htm','.xhtm','.mp3','.m4a','.m4v','.mp4','.ogg','.ogm','.oga','.webm','.wav','.mpeg','.flac'];
  515. for ( i = 0, n = $excluded.length; i < n; i += 1) {
  516. $styles += 'body.dark_mode #content_iframe[src*="'+ $excluded[i] +'" i] { background:white; filter:unset; }';
  517. }
  518.  
  519. $styles += '#main_content { width:100%; height:100%; border:0; border-collapse:collapse; overflow:hidden; }';
  520.  
  521. $custom_styles.append($styles);
  522. document.head.appendChild($custom_styles);
  523.  
  524. // Conditional Styles:
  525. var $gecko_styles = document.createElement("style");
  526. var $custom_gecko_styles = '';
  527. $custom_gecko_styles += '<style type="text/css">html, body { border: solid 1px gray !important; } button { padding:0; } #grid_btn .menu {top:-24px;} thead {font-size:100%;} #dir_table .dir::before {position:absolute;} </style>';
  528. $gecko_styles.append($custom_gecko_styles);
  529.  
  530. // for scrollIntoView
  531. var $block = '';
  532.  
  533. if( $userAgent.indexOf('Firefox') > -1 ){
  534. document.head.appendChild($gecko_styles);
  535. $block = 'start';
  536. } else {
  537. $block = 'nearest';
  538. }
  539. // if( $userAgent.indexOf('Chrome') > -1 ){
  540. // Do something
  541. // }
  542.  
  543. // Sidebar Header: Hide invisibles checkbox user setting
  544. if ( $settings.hide_invisibles === true ) {
  545. $inv_checkbox.find('input').prop('checked',true);
  546. $dir_table.addClass('hide_invisibles');
  547. }
  548. // Sidebar Header: Toggle Invisibles checkbox
  549. $inv_checkbox.on('click','input', function(e){
  550. $dir_table.toggleClass('hide_invisibles');
  551. $('.selected').removeClass('selected');
  552. });
  553.  
  554. // Hide Ignored Files
  555. if ( $settings.hide_ignored_files === true ) {
  556. $dir_table.addClass('hide_ignored');
  557. }
  558.  
  559. // Dark Mode
  560. if ( $settings.dark_mode === true ) {
  561. $body.addClass('dark_mode');
  562. }
  563. $toggle_dark_mode.on('click',function(e) {
  564. e.preventDefault();
  565. $body.toggleClass('dark_mode');
  566. });
  567.  
  568.  
  569. // Hide hide invisibles chceckbox
  570. if ( platformIsWin() || window.location.href.indexOf('file:') < 0 ) {
  571. $inv_checkbox.hide();
  572. }
  573.  
  574. // ***** END STYLES ***** //
  575.  
  576. // ***** BUILD MENUS ***** //
  577.  
  578. // MENUS: Parents Link Menu Items
  579.  
  580. var parentLinksArr = function() {
  581. var $paths_arr = [];
  582. for ( i = 1, n = $location_arr.length; i < n - 1; i+=1 ) {
  583. $paths_arr[0] = ''; // root
  584. $paths_arr[i] = $paths_arr[i - 1] + $location_arr[i] + '/';
  585. }
  586. return $paths_arr;
  587. };
  588.  
  589. // MENUS: function to build menu list items
  590. var menuItems = function(x,y,i) { // (link, name, count)
  591. var $menu_item = '<li><a href="file:///' + x[i] + '">' + y[i] + '</a></li>';
  592. return $menu_item;
  593. };
  594. // MENUS: Parents Directory Menu Items
  595. var parents_dir_menu_arr = function() {
  596. var $parents_dir_menu_items = [];
  597. for ( var i = 1, n = parentLinksArr().length; i < n; i+=1 ) {
  598. $parents_dir_menu_items[0] = menuItems('/','/',0); // root
  599. $parents_dir_menu_items[i] = menuItems( parentLinksArr(), parentLinksArr(), i);
  600. }
  601. $parents_dir_menu_items.pop(); // remove current directory
  602. $parents_dir_menu_items = $parents_dir_menu_items.reverse().join('').replace(/%20/g,' ');
  603. return $parents_dir_menu_items;
  604. };
  605. $parents_dir_menu.siblings('ul').append( parents_dir_menu_arr() );
  606.  
  607. // MENUS: Root Shortcuts Menu Items
  608. $settings.root_shortcuts = $settings.root_shortcuts.map(i => i + '/'); // append '/' to directory name
  609.  
  610. var root_shortcuts_menu_arr = function() {
  611. if ( $settings.root_shortcuts.length ) {
  612. var $root_shortcut_items = [];
  613. for ( i = 0, n = $settings.root_shortcuts.length; i < n; i+=1 ) {
  614. $root_shortcut_items[i] = menuItems($settings.root_shortcuts,$settings.root_shortcuts,i);
  615. }
  616. $root_shortcut_items = $root_shortcut_items.join('');
  617. return $root_shortcut_items;
  618. }
  619. };
  620.  
  621. // MENUS: User Shortcuts Menu Items
  622. var $working_user_shortcuts = $settings.user_shortcuts;
  623.  
  624. var $user_shortcuts_display_name = $working_user_shortcuts.map(i => $settings.user_name + '/' + i + '/' ); // build display names
  625. var $home = '';
  626. if ( platformIsLinux() ) {
  627. $home = 'home/';
  628. } else {
  629. $home = 'users/';
  630. }
  631. $working_user_shortcuts = $working_user_shortcuts.map(i => $home + $settings.user_name + '/' + i + '/'); // build link fragments
  632.  
  633. var userShortcutsMenuArr = function() {
  634. if ( $settings.user_name && $working_user_shortcuts.length ) {
  635. var $user_shortcut_items = [];
  636. for ( i = 0, n = $working_user_shortcuts.length; i < n; i+=1 ) {
  637. $user_shortcut_items[i] = menuItems($working_user_shortcuts,$user_shortcuts_display_name,i);
  638. }
  639. $user_shortcut_items = $user_shortcut_items.join('');
  640. return $user_shortcut_items;
  641. }
  642. };
  643.  
  644. // MENUS: File Shortcuts Menu Items
  645. var $file_shortcuts_display_name = $settings.file_shortcuts.map(i => i.split('/').pop()); // get file names from paths
  646.  
  647. var fileShortcutsMenuArr = function() {
  648. if ( $settings.file_shortcuts.length ) {
  649. var $file_shortcut_items = [];
  650. for ( i = 0, n = $settings.file_shortcuts.length; i < n; i+=1 ) {
  651. $file_shortcut_items[i] = menuItems($settings.file_shortcuts,$file_shortcuts_display_name,i);
  652. }
  653. $file_shortcut_items = $file_shortcut_items.join('').replace(/\/<\/a>/g,'<\/a>').replace(/<a\s/g,'<a class="file_shortcut" ').replace(/%20/g,' ');
  654. return $file_shortcut_items;
  655. }
  656. };
  657. $shortcuts_menu.siblings('ul').append( root_shortcuts_menu_arr(), $divider, userShortcutsMenuArr(), $divider.clone(), fileShortcutsMenuArr(), $divider.clone() );
  658.  
  659. // Additional Menu Items
  660. $shortcuts_menu.siblings('ul').append($toggle_dark_mode, $export_settings);
  661.  
  662. // MENUS: Show Menu on click
  663. function showMenus(el) {
  664. var $position = $(el).position();
  665. $(el).find('ul').css({'top':$position.top + $(el).innerHeight() + 'px'}).toggle().parent('td').siblings('td').find('.menu').hide();
  666. }
  667. $parents_dir_menu.add($shortcuts_menu).parent('td').on('click',function(e) {
  668. e.stopPropagation();
  669. showMenus(this);
  670. });
  671.  
  672. // ***** END BUILD MENUS ***** //
  673.  
  674. // ***** END BUILD UI ***** //
  675.  
  676. // ***** SIDEBAR ***** //
  677.  
  678. // DIRECTORY TABLE
  679.  
  680. // DIRECTORY TABLE VARIABLES
  681. if ( $dir_table.hasClass('table') ) {
  682.  
  683. $dir_table_head = $dir_table.find('> thead').length ? $dir_table.find('> thead') : $dir_table.addClass('headless').find('> tbody > tr:first-of-type') ;
  684. $dir_table_head.attr('id','thead');
  685. $dir_table_head_cell = $dir_table_head.find('th');
  686. $dir_table_head_name = $dir_table_head.find('th:contains("Name")');
  687. $dir_table_head_name.addClass('name');
  688. $dir_table_head_details = $dir_table_head_name.nextAll();
  689. $dir_table_head_details.addClass('details');
  690.  
  691. $dir_table_body = $dir_table.find('> tbody');
  692. $dir_table_body.attr('id','tbody');
  693. $dir_table_rule = $dir_table_body.find('hr').closest('tr');
  694. $dir_table_rule.addClass('rule');
  695. $dir_table_row = $dir_table_body.find('> tr').not('#thead').not('.rule');
  696. $dir_table_cell = $dir_table_row.find('td');
  697. $dir_table_link = $dir_table_cell.find('a');
  698. $dir_table_item_name = $dir_table_link.parent('td');
  699. $dir_table_item_name.addClass('name');
  700. $dir_table_item_icon = $dir_table_item_name.add($dir_table_head_name).prev();
  701. $dir_table_item_icon.addClass('icon'); // for directory lists with separate td for icons
  702. $dir_table_details = $dir_table_item_name.nextAll();
  703. $dir_table_details.addClass('details');
  704. }
  705. if( $userAgent.indexOf('Firefox') > -1 ) {
  706. $dir_table.addClass('firefox');
  707. }
  708. if ( $dir_table.hasClass('list') ) { // Apache server
  709. $dir_table_wrapper.addClass('headless');
  710. $dir_table_head = '';
  711. $dir_table_head_cell = '';
  712. $dir_table_head_name = '';
  713. $dir_table_head_details = '';
  714. $dir_table_body = '';
  715. $dir_table_row = $dir_table.find('li');
  716. $dir_table_cell = '';
  717. $dir_table_details = '';
  718. $dir_table_link = $dir_table_row.find('a');
  719. // $dir_table_link.addClass('name');
  720. $dir_table_item_name = $dir_table_link.text();
  721. $sidebar.append($dir_table_wrapper);
  722. }
  723. $dir_table.detach().attr('id','dir_table');
  724.  
  725. // ***** DIR_TABLE SETUP ***** //
  726.  
  727. // Sidebar Header: Show details button click function
  728. function detailsButton() {
  729. $dir_table.toggleClass('show_details');
  730. $dir_table_body.css({'top':$dir_table_head.height() + 1 +'px'});
  731. $details_btn.find('span').toggle();
  732. }
  733. $details_btn.on('click', detailsButton );
  734.  
  735. // Dir_table: Row hover effects
  736. $dir_table_row.hover(function() {
  737. // Highlight corresponding grid item
  738. if ( $content_grid.is(':visible') ) {
  739. $this_link = $(this).find('a').attr('href');
  740. $content_grid.find('[href="' + $this_link + '"]').closest('div').addClass('hovered');
  741. }
  742. }, function() {
  743. if ( $content_grid.is(':visible') ) {
  744. $content_grid.find('.hovered').removeClass('hovered');
  745. }
  746. });
  747.  
  748. // Dir_table: create link arrays
  749. var $dir_table_dir_link_arr = [];
  750. var $dir_table_file_link_arr = [];
  751. var $dir_table_file_ext_arr = [];
  752. $dir_table_row.not('.ignore,.invisible').find('a').each(function() {
  753. $this_link = $(this).attr('href').toLowerCase();
  754. if ( $this_link.endsWith('/') ) {
  755. $dir_table_dir_link_arr.push($this_link);
  756. return $dir_table_dir_link_arr;
  757. } else {
  758. var $this_link_ext = $this_link.slice($this_link.lastIndexOf('.'));
  759. $dir_table_file_link_arr.push($this_link);
  760. if ( $dir_table_file_ext_arr.indexOf($this_link_ext) < 0 ) {
  761. $dir_table_file_ext_arr.push($this_link_ext);
  762. }
  763. return $dir_table_file_link_arr, $dir_table_file_ext_arr;
  764. }
  765. });
  766. // Dir_table: array of all dir_table links
  767. var $dir_table_link_arr = [];
  768. $dir_table_link_arr = $dir_table_dir_link_arr.concat($dir_table_file_link_arr);
  769.  
  770. // Dir_table: array of supported image types
  771. var $image_ext_arr = ['.jpg','.jpeg','.png','apng','.gif','.bmp','webp'];
  772. var $font_ext_arr = ['.otf','.ttf','.woff','.woff2'];
  773. var $font_family_arr = [];
  774. var $this_text;
  775. var $this_ext;
  776.  
  777. // Dir_table: Classify items
  778. $dir_table_row.each(function() {
  779.  
  780. $this_link = $(this).find('a').attr('href');
  781. $this_text = $(this).find('a').text();
  782. $this_ext = $this_text.toLowerCase().slice($this_text.lastIndexOf('.'));
  783.  
  784. if ( $this_link !== undefined ) {
  785.  
  786. $this_link = $this_link.toString().toLowerCase();
  787.  
  788. // Directories or files
  789. if ( $this_link.endsWith('/') ) {
  790. $(this).addClass('dir');
  791. } else {
  792. $(this).addClass('file');
  793. }
  794. // pdf
  795. if ( $this_link.endsWith('.pdf') ) {
  796. $(this).addClass('pdf');
  797. } else if ( $.inArray( $this_ext, $image_ext_arr ) != -1 ) {
  798. $(this).addClass('img');
  799. } else if ( $.inArray( $this_ext, $font_ext_arr ) != -1 ) {
  800. $(this).addClass('font');
  801. }
  802. // invisibles
  803. if ( $this_link.slice($this_link.lastIndexOf('/') + 1 ) === '.' || $this_link.startsWith('.') || $(this).find('a').text().startsWith('.') ) {
  804. $(this).addClass('invisible');
  805. }
  806. // ignored
  807. if ( $settings.ignore_files === true ) {
  808. for ( i = 0, n = $settings.ignore_file_types.length; i < n; i+=1 ) {
  809. if ( $this_link.endsWith( $settings.ignore_file_types[i] ) ) {
  810. $(this).closest('#dir_table > tbody > tr').addClass('ignore');
  811. }
  812. }
  813. }
  814.  
  815. // directories as Files and hide ignored files
  816. if ( $this_text.indexOf('.app') ) {
  817. $(this).addClass('app');
  818. if ( $settings.apps_as_dirs === false ) {
  819. $(this).addClass('ignore');
  820. }
  821. }
  822.  
  823. if ( $(this).hasClass('dir') && $(this).hasClass('app') && $this_text.endsWith('/') ) {
  824. $(this).find('a').text($this_text.slice(0,$this_text.lastIndexOf('/')));
  825. }
  826. }
  827. }); // end classify dir_table items
  828.  
  829. if ( $dir_table.hasClass('table') ) {
  830. $dir_table.appendTo($sidebar);
  831. } else {
  832. $dir_table.appendTo($dir_table_wrapper);
  833. }
  834.  
  835. // Show grid button if images or fonts are found
  836. if ( $dir_table.find('.img').length ) {
  837. $dir_table.add($grid_btn).addClass('has_images');
  838. }
  839. if ( $dir_table.find('.font').length ) {
  840. $dir_table.add($grid_btn).addClass('has_fonts');
  841. }
  842.  
  843. // ***** End dir_table setup ***** //
  844.  
  845. // ***** APPEND MAIN CONTENT ***** //
  846.  
  847. var $main_content = $('<table id="main_content"><tbody><tr></tr></tbody></table>');
  848. $main_content.find('tr').append( $sidebar_wrapper, $content_pane );
  849.  
  850. $body.prepend($main_content);
  851.  
  852. // ***************************** //
  853.  
  854. // ***** SHOW/HIDE CONTENT ***** //
  855.  
  856. // MENUS: Hide Menu function
  857. function hideMenu() {
  858. $('.menu').hide();
  859. }
  860. $(document).on('click', hideMenu );
  861.  
  862. // Set content height
  863. function setContentHeight() {
  864. var $dir_table_head_height = $dir_table_head.length ? $dir_table_head.height() : 0;
  865. var $content_headerHeight = $content_header.outerHeight();
  866. $dir_table.add($dir_table_wrapper).css({'height':window.innerHeight - $sidebar_header.outerHeight() });
  867. $dir_table.find($dir_table_body).css({'top': $dir_table_head_height });
  868. $content_image.css({'top':$content_headerHeight });
  869. $content_grid.add($content_embed).add($content_iframe).add($content_font).css({'height':window.innerHeight - $content_headerHeight,'top':$content_headerHeight });
  870. $content_font_size.css({'top':$content_headerHeight + 13 });
  871. }
  872. setContentHeight();
  873.  
  874. $('window').on('resize', setContentHeight );
  875.  
  876. function setContentTitle() {
  877. if ( $content_pane.hasClass('has_grid_content') && $content_grid.hasClass('has_grid') ) {
  878. $content_title.empty().prepend('Images and Fonts from: ' + $current_dir_name);
  879. } else if ( $content_pane.hasClass('has_grid_content') && $content_grid.hasClass('has_image_grid') ) {
  880. $content_title.empty().prepend('Images from: ' + $current_dir_name);
  881. } else if ( $content_pane.hasClass('has_grid_content') && $content_grid.hasClass('has_font_grid') ) {
  882. $content_title.empty().prepend('Fonts from: ' + $current_dir_name);
  883. } else {
  884. $content_title.empty().prepend( $('.selected').find('a').text() );
  885. }
  886. if ( $('.selected').hasClass('ignore') ) {
  887. $content_title.append(' (Ignored content)' );
  888. }
  889. }
  890.  
  891. // Get image dimensions
  892. function getDimensions(link, callback) {
  893. var img = new Image();
  894. img.src = link;
  895. img.onload = function() { callback( this.width, this.height ); };
  896. }
  897.  
  898. function scrollSidebar(row) {
  899. row[0].scrollIntoView({ behavior:'smooth', block:$block, inline:'nearest' });
  900. }
  901. function scrollGrid(item) {
  902. item[0].scrollIntoView({ behavior:'smooth', block:$block, inline:'nearest' });
  903. }
  904.  
  905. // Select row on click and set classes for $content_pane
  906. function selectThis(row) {
  907. row.addClass('selected').siblings().removeClass('selected');
  908. $selected = $dir_table.find('.selected');
  909. scrollSidebar($selected);
  910. if ( row.hasClass('dir') ) {
  911. closeThis(); // empty content pane
  912. setContentTitle();
  913. $content_pane.removeClass().addClass('has_dir_content');
  914. }
  915. var $grid_selected = $content_grid.find('div.font_grid_item[href="'+ row.find('a').attr('href') +'"]').add('div a[href="'+ row.find('a').attr('href') +'"]').parent('div').addBack();
  916. if ( $content_pane.hasClass('has_grid_content') ) {
  917. $grid_selected.addClass('selected').siblings().removeClass('selected');
  918. $grid_selected = $content_grid.find('.selected');
  919. // scrollGrid($grid_selected); // grid scroll is not working reliably
  920. }
  921. }
  922.  
  923. function showIgnored() {
  924. closeThis();
  925. $content_pane.addClass('has_ignored_content');
  926. $content_title.append(' (Ignored content)' );
  927. }
  928.  
  929. function showImage(row,link) {
  930. $content_pane.addClass('has_image_content');
  931. $content_image.find('img').removeClass('zoom_img').attr('src',link);
  932. getDimensions( link, function( width, height ) {
  933. $content_title.append(' <span style="text-transform:lowercase;">(' + width + 'px &times; ' + height + 'px</span>)' );
  934. });
  935. $content_grid.find('a[href="' + row.find('a').attr('href') + '"]').parent('div').addClass('selected').siblings().removeClass('selected');
  936. }
  937.  
  938. function showPdf(link) {
  939. $content_pane.addClass('has_pdf_content');
  940. $content_embed.attr('type','application/pdf').attr('src',link + '?#zoom=100&scrollbar=1&toolbar=1&navpanes=1');
  941. }
  942.  
  943. function showFile(link) {
  944. $content_pane.addClass('has_file_content');
  945. $content_iframe.attr('src',link);
  946. }
  947.  
  948. function showFont(row,link) {
  949. var $font_family = row.find('.name').text();
  950.  
  951. addCustomStyle($font_family,link);
  952.  
  953. $content_pane.addClass('has_font_content');
  954. $content_font.css({ 'font-family':'"'+ $font_family +'"' });
  955. }
  956.  
  957. function addCustomStyle(font_family,link) {
  958. if ( $font_family_arr.indexOf(font_family) == -1 ) {
  959. $font_family_arr.push(font_family);
  960. $custom_font_styles.append('@font-face { font-family: "'+ font_family +'"; src: url("'+ link +'"); }'); // only add style if it doesn't exist
  961. }
  962. }
  963.  
  964. // Show selected content
  965. function showThis(row,link) {
  966.  
  967. if ( $content_pane.hasClass('has_grid_content') ) {
  968. $content_pane.removeClass().addClass('has_hidden_grid'); // hide grid when showing new content
  969. } else
  970. if ( $content_pane.hasClass('has_hidden_grid') ) {
  971. $content_pane.removeClass().addClass('has_hidden_grid'); // keep grid hidden when showing new content
  972. } else {
  973. $content_pane.removeClass();
  974. }
  975.  
  976. if ( row.hasClass('ignore') ) {
  977. showIgnored();
  978. return;
  979. }
  980. if ( row.hasClass('img') ) {
  981. showImage(row,link);
  982. return;
  983. }
  984. if ( row.hasClass('pdf') ) {
  985. showPdf(link);
  986. return;
  987. }
  988. if ( row.hasClass('font') ) {
  989. showFont(row,link);
  990. return;
  991. }
  992. if ( row.hasClass('file') ) {
  993. showFile(link);
  994. return;
  995. }
  996. }
  997.  
  998. // ***** MAIN CLICK FUNCTION FOR SHOWING CONTENT ***** //
  999.  
  1000. function clickDirTableLink(link) {
  1001. var $this_row = link.closest('#dir_table > tbody > tr, #dir_table > li');
  1002. $this_link = link.attr('href');
  1003.  
  1004. if ( $this_row.hasClass('dir') ) {
  1005. window.location = $this_link;
  1006. }
  1007. hideMenu();
  1008. showThis($this_row,$this_link);
  1009. selectThis($this_row);
  1010. setContentTitle();
  1011. setContentHeight();
  1012. }
  1013. $dir_table_row.on('click','a',function(e) {
  1014. e.preventDefault();
  1015. closeContent();
  1016. clickDirTableLink($(this));
  1017. });
  1018.  
  1019. // Auto-select file from file shortcut list;
  1020. // Limitations: only loads last file from list found in directory, doesn't know anything about which actual file shortcut was selected
  1021. function autoSelectFile() {
  1022. if ( $settings.file_shortcuts.length ) {
  1023. for ( i = 0, n = $settings.file_shortcuts.length; i < n; i+=1 ) {
  1024. if ( $.inArray($settings.file_shortcuts[i], $dir_table_link_arr ) ) {
  1025. $dir_table.find( 'a[href*="/' + $settings.file_shortcuts[i] + '"]').click();
  1026. }
  1027. }
  1028. }
  1029. }
  1030. autoSelectFile();
  1031.  
  1032. // File shortcuts: load directory then auto-select file
  1033. function showFileShortcut(item) {
  1034. e.preventDefault();
  1035. $this_link = item.attr('href');
  1036. var $this_dir = $this_link.slice(0,$this_link.lastIndexOf('/') );
  1037. window.location = $this_dir;
  1038. }
  1039. $('.file_shortcut').on('click',showFileShortcut );
  1040.  
  1041. // Reload Button
  1042. function reloadThis() {
  1043. if ( $content_pane.hasClass('has_grid_content') ) {
  1044. $grid_btn.click();
  1045. $content_grid.css({'font-size':'1em','grid-template-columns':'repeat(auto-fit, minmax(150px, 1fr))'});
  1046. return;
  1047. }
  1048. if ( $content_pane.is('[class*="content"]') ) {
  1049. $('.selected').find('a').click();
  1050. $content_font.css({'font-size':'1em'});
  1051. } else {
  1052. return;
  1053. }
  1054. }
  1055. $content_reload_btn.on('click', reloadThis );
  1056.  
  1057. function closeContent() {
  1058. $content_image.find('img').removeAttr('src');
  1059. $content_embed.removeAttr('src');
  1060. $content_iframe.removeAttr('src');
  1061. $content_font.css({'font-family':''});
  1062. }
  1063.  
  1064. function closeThis() {
  1065. hideMenu();
  1066. if ( $content_pane.hasClass('has_grid_content') ) {
  1067. $content_pane.removeClass('has_grid_content');
  1068. $content_grid.removeClass().empty().css({'font-size':'1em'});
  1069. } else if ( $content_pane.hasClass('has_hidden_grid') ) {
  1070. $content_pane.removeClass().addClass('has_grid_content');
  1071. closeContent();
  1072. } else {
  1073. $content_pane.removeClass();
  1074. closeContent();
  1075. }
  1076. setContentTitle();
  1077. }
  1078. // Close content button
  1079. $content_close_btn.on( 'click', closeThis );
  1080.  
  1081.  
  1082. // ***** KEYBOARD EVENTS ***** //
  1083. function navigateToThis(row) {
  1084. if ( $content_pane.hasClass('has_grid_content') ) {
  1085. selectThis(row);
  1086. } else {
  1087. row.find('a').click();
  1088. }
  1089. }
  1090.  
  1091. $body.on('keydown',$dir_table,function(e) {
  1092.  
  1093. var $selected = $dir_table_row.filter('.selected');
  1094. var $selected_href = $selected.find('a').attr('href');
  1095. var $first_item = $dir_table_row.filter(':visible').first();
  1096. var $last_item = $dir_table_row.filter(':visible').last();
  1097. var $prev_item = $selected.prevAll(':visible').first();
  1098. var $next_item = $selected.nextAll(':visible').first();
  1099. var $first_image = $dir_table_row.filter('.img:visible').first();
  1100. var $last_image = $dir_table_row.filter('.img:visible').last();
  1101. var $prev_image = $selected.prevAll('.img:visible').first();
  1102. var $next_image = $selected.nextAll('.img:visible').first();
  1103. var $first_font = $dir_table_row.filter('.font:visible').first();
  1104. var $last_font = $dir_table_row.filter('.font:visible').last();
  1105. var $prev_font = $selected.prevAll('.font:visible').first();
  1106. var $next_font = $selected.nextAll('.font:visible').first();
  1107.  
  1108. switch ( e.key ) {
  1109.  
  1110. case 'ArrowUp':
  1111.  
  1112. // Go to parent folder
  1113. if ( (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) ) {
  1114. window.location = $parent_dir_link;
  1115. break;
  1116. }
  1117. // Allow arrow navigation within
  1118. if ( $('*[contentEditable="true"').is(':focus') ) {
  1119. return;
  1120. }
  1121. e.preventDefault();
  1122. if ( $first_item.hasClass('selected') || $selected.length < 1 ) {
  1123. $last_item.hasClass('dir') ? selectThis($last_item) : $last_item.find('a').click();
  1124. } else {
  1125. $prev_item.hasClass('dir') ? selectThis($prev_item) : $prev_item.find('a').click();
  1126. }
  1127. break;
  1128.  
  1129. case 'ArrowDown':
  1130.  
  1131. if ( (e.ctrl || e.metaKey) && $selected.hasClass('app') && $settings.apps_as_dirs === false ) {
  1132. return;
  1133. } else if ( $('*[contentEditable="true"').is(':focus') ) {
  1134. return;
  1135. } else if ( (e.ctrl || e.metaKey) && $selected.hasClass('dir') ) {
  1136. window.location = $selected_href;
  1137. break;
  1138. }
  1139.  
  1140. e.preventDefault();
  1141. if ( $last_item.hasClass('selected') || $selected.length < 1 ) {
  1142. $first_item.hasClass('dir') ? selectThis($first_item) : $first_item.find('a').click();
  1143. } else {
  1144. $next_item.hasClass('dir') ? selectThis($next_item) : $next_item.find('a').click();
  1145. }
  1146. break;
  1147.  
  1148. case 'ArrowLeft':
  1149.  
  1150. if ( (e.ctrl || e.metaKey) || ( e.ctrl && e.metaKey ) ) {
  1151. return;
  1152. } else if ( $('*[contentEditable="true"').is(':focus') ) {
  1153. return;
  1154. }
  1155. // Navigate Grid or Images
  1156. if ( $selected.length < 1 ) {
  1157. $last_image.length ? navigateToThis($last_image) : navigateToThis($last_font);
  1158. } else if ( $first_image.hasClass('selected') || $selected.length < 1 ) {
  1159. $last_font.length ? navigateToThis($last_font) : navigateToThis($last_image);
  1160. } else if ( $first_font.hasClass('selected') || $selected.length < 1 ) {
  1161. $last_image.length ? navigateToThis($last_image) : navigateToThis($last_font);
  1162. } else if ( $selected.hasClass('img') && $prev_image.length ) {
  1163. navigateToThis($prev_image);
  1164. } else {
  1165. navigateToThis($prev_font);
  1166. }
  1167. break;
  1168.  
  1169. case 'ArrowRight':
  1170.  
  1171. if ( (e.ctrl || e.metaKey) || ( e.ctrl && e.metaKey ) ) {
  1172. return;
  1173. } else if ( $('*[contentEditable="true"').is(':focus') || $selected.hasClass('dir ignore') ) {
  1174. return;
  1175. }
  1176. // Navigate Grid or Images
  1177. if ( $selected.hasClass('dir') ) {
  1178. window.location = $selected_href; // Open directory
  1179. }
  1180. if ( $selected.length < 1 ) {
  1181. $first_image.length ? navigateToThis($first_image) : navigateToThis($first_font);
  1182. } else if ( $last_image.hasClass('selected') || $selected.length < 1 ) {
  1183. $first_font.length ? navigateToThis($first_font) : navigateToThis($first_image);
  1184. } else if ( $last_font.hasClass('selected') || $selected.length < 1 ) {
  1185. $first_image.length ? navigateToThis($first_image) : navigateToThis($first_font);
  1186. } else if ( $selected.hasClass('img') && $next_image.length ) {
  1187. navigateToThis($next_image);
  1188. } else {
  1189. navigateToThis($next_font);
  1190. }
  1191. break;
  1192.  
  1193. case 'Enter':
  1194. // Open directories (or ignore)
  1195. if ( $selected.hasClass('app') && $settings.apps_as_dirs === false ) {
  1196. break;
  1197. } else {
  1198. $selected.find('a').click();
  1199. }
  1200. break;
  1201.  
  1202. case 'd':
  1203. // Toggle Invisibles with Command-i
  1204. if ( (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) ) {
  1205. e.preventDefault();
  1206. e.stopPropagation();
  1207. $details_btn.click();
  1208. }
  1209. break;
  1210.  
  1211. case 'g':
  1212. // Show image Grid
  1213. if ( (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) ) {
  1214. e.preventDefault();
  1215. e.stopPropagation();
  1216. $grid_btn.click();
  1217. }
  1218. break;
  1219.  
  1220. case 'i':
  1221. // Toggle Invisibles with Command-i
  1222. if ( (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) ) {
  1223. e.preventDefault();
  1224. e.stopPropagation();
  1225. $inv_checkbox.find('input').click();
  1226. }
  1227. break;
  1228.  
  1229. case 'o':
  1230. // Cmd/Ctrl + Shift + O: Open selected item in new window
  1231. if ( (navigator.platform.match("Mac") ? e.metaKey && e.shiftKey : e.ctrlKey && e.shiftKey ) ) {
  1232. window.open($selected_href);
  1233. }
  1234. break;
  1235.  
  1236. case 'r':
  1237. // Cmd/Ctrl + Shift + R: Refresh
  1238. if ( (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) ) {
  1239. if ( $content_pane.is('[class*="has_"]') ) {
  1240. e.preventDefault();
  1241. $content_reload_btn.click();
  1242. } else {
  1243. return;
  1244. }
  1245. }
  1246. break;
  1247.  
  1248. case 'w':
  1249. // Close content pane if Close button visible with Command-w
  1250. // Doesn't work in Firefox: can't override default keybinding
  1251. if ( (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) && ($content_pane.is('[class*="has_"]')) ) {
  1252. e.preventDefault();
  1253. e.stopPropagation();
  1254. $content_close_btn.click();
  1255. }
  1256. break;
  1257.  
  1258. case '.':
  1259. // Increase font preview size
  1260. if ( (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) && e.shiftKey ) {
  1261. $('#increase').click();
  1262. }
  1263. break;
  1264.  
  1265. case ',':
  1266. // Dencrease font preview size
  1267. if ( (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) && e.shiftKey ) {
  1268. $('#decrease').click();
  1269. }
  1270. break;
  1271.  
  1272. case 'tab':
  1273. break;
  1274.  
  1275. } // end switch
  1276.  
  1277. });
  1278.  
  1279. // ***** END KEYBOARD EVENTS ***** //
  1280.  
  1281. // ***** IMAGE NAVIGATION ***** //
  1282.  
  1283. $prev_btn.on( 'click', function(event) {
  1284. e = $.Event("keydown");
  1285. e.key = 'ArrowLeft';
  1286. $dir_table.trigger(e);
  1287. });
  1288.  
  1289. $next_btn.on( 'click', function(event) {
  1290. e = $.Event("keydown");
  1291. e.key = 'ArrowRight';
  1292. $dir_table.trigger(e);
  1293. });
  1294.  
  1295. // Zoom Images
  1296. $content_image.find('img').on('click',function(e) {
  1297. $this_link = $(this).attr('src');
  1298. var $offset = $(this).offset();
  1299. var $this_width = $(this).width();
  1300. var $this_height = $(this).height();
  1301.  
  1302. $(this).toggleClass('zoom_img');
  1303.  
  1304. getDimensions( $this_link, function( width, height ) {
  1305. $content_image.scrollLeft( (e.pageX - $offset.left) * width/($this_width + 13) - ( e.pageX - $offset.left ) - 52 ) ;
  1306. $content_image.scrollTop( (e.pageY - $offset.top) * height/($this_height + 13) - ( e.pageY - $offset.top ) - 52 );
  1307. });
  1308.  
  1309. });
  1310.  
  1311. // ***** GRIDS ***** //
  1312.  
  1313. var $font_family;
  1314.  
  1315. var imageGridItems = function() {
  1316. var $image_grid_items_arr = [];
  1317. $dir_table_row.filter('.img').each(function() {
  1318.  
  1319. $this_link = $(this).find('a').attr('href');
  1320. $this_ext = $this_link.toLowerCase().slice($this_link.lastIndexOf('.'));
  1321.  
  1322. if ( $.inArray( $this_ext, $image_ext_arr ) != -1 ) { // if this row file ext is in the image extension array
  1323. $image_grid_item_el.find('a').attr('href',$this_link).find('img').attr('src',$this_link);
  1324. $image_grid_items_arr.push( $image_grid_item_el.clone() );
  1325. }
  1326. });
  1327. return $image_grid_items_arr;
  1328. };
  1329.  
  1330. var fontGridItems = function() {
  1331. var $font_grid_items_arr = [];
  1332. $dir_table_row.filter('.font').each(function() {
  1333.  
  1334. $this_link = $(this).find('a').attr('href');
  1335. $font_family = $(this).find('.name').text();
  1336.  
  1337. addCustomStyle( $font_family, $this_link );
  1338.  
  1339. $font_grid_item_el.attr('href',$this_link).css({ 'font-family':'"'+ $font_family +'"' }).empty().append( $font_family.slice( 0,$font_family.lastIndexOf('.') ) );
  1340. $font_grid_items_arr.push($font_grid_item_el.clone());
  1341. });
  1342. return $font_grid_items_arr;
  1343. };
  1344.  
  1345. // Grid Button Click
  1346. function showGrid() {
  1347. $content_pane.removeClass('has_hidden_grid').addClass('has_grid_content');
  1348.  
  1349. if ( $dir_table.hasClass('has_images') && ( $dir_table.hasClass('has_fonts') ) ) {
  1350. $content_grid.empty().append( imageGridItems() ).append( fontGridItems() );
  1351. $content_grid.removeClass().addClass('has_grid');
  1352. } else if ( $dir_table.hasClass('has_images') ) {
  1353. $content_grid.empty().append( imageGridItems() );
  1354. $content_grid.removeClass().addClass('has_image_grid');
  1355. } else {
  1356. $content_grid.empty().append( fontGridItems() );
  1357. $content_grid.removeClass().addClass('has_font_grid');
  1358. }
  1359. setContentTitle();
  1360. setContentHeight();
  1361. }
  1362. $grid_btn.on('click', showGrid );
  1363.  
  1364. $('#show_image_grid').on('click',function(e) {
  1365. e.stopPropagation();
  1366. $content_pane.removeClass('has_hidden_grid').addClass('has_grid_content');
  1367. $content_grid.empty().append( imageGridItems() );
  1368. $content_grid.removeClass().addClass('has_image_grid');
  1369. setContentTitle();
  1370. setContentHeight();
  1371. });
  1372.  
  1373. $('#show_font_grid').on('click',function(e) {
  1374. e.stopPropagation();
  1375. $content_pane.removeClass('has_hidden_grid').addClass('has_grid_content');
  1376. $content_grid.empty().append( fontGridItems() );
  1377. $content_grid.removeClass().addClass('has_font_grid');
  1378. setContentTitle();
  1379. setContentHeight();
  1380. });
  1381.  
  1382. // GRID ITEMS
  1383. var thisGridItemLink = function(el) {
  1384. $this_link = el.find('a').attr('href') ? el.find('a').attr('href') : el.attr('href');
  1385. return $this_link;
  1386. };
  1387.  
  1388. // Grid Item Hover
  1389. $content_grid.on('mouseenter','> div:not(".selected")',function() {
  1390. $dir_table.find('a[href="' + thisGridItemLink($(this)) + '"]').addClass('hovered');
  1391. }).on('mouseleave','> div:not(".selected")',function() {
  1392. $dir_table.find('a[href="' + thisGridItemLink($(this)) + '"]').removeClass('hovered');
  1393. });
  1394.  
  1395. // Grid Item Click
  1396. $content_grid.on('click','> div[class*="item"]',function(e) {
  1397. e.preventDefault();
  1398. $dir_table.find('a[href="' + thisGridItemLink($(this)) + '"]').click();
  1399. });
  1400.  
  1401. // ***** FONT PREVIEWS ***** //
  1402.  
  1403. var fontSize = function(el) {
  1404. return parseFloat(el.css('font-size'));
  1405. };
  1406. function setFontSize(el,x) {
  1407. el.css({'font-size':( fontSize(el)/$em * x ) +'em'});
  1408. }
  1409. var $em = parseInt(getComputedStyle(document.body).fontSize); // pts/em
  1410. var $factor = 1.125;
  1411.  
  1412. // Scale Image Grid Items
  1413. var $image_grid_item_size;
  1414. var $grid_scale_factor;
  1415. function setImageSize(x) {
  1416. $image_grid_item_size = parseInt($('.image_grid_item').width()) + x;
  1417. $grid_scale_factor = parseInt($content_grid.attr('data-grid-scale-factor'));
  1418. $content_grid.attr('data-grid-scale-factor',parseInt($grid_scale_factor) + x).css({'grid-template-columns':'repeat(auto-fit, minmax('+ ($image_grid_item_size) +'px, 1fr))', 'grid-template-rows':'repeat(auto, minmax('+ ($image_grid_item_size) +'px))' });
  1419. $content_grid.find('.image_grid_item').css({'width':$image_grid_item_size +'px', 'height':$image_grid_item_size +'px'});
  1420. $content_grid.find('img').css({'max-width':($image_grid_item_size - $image_grid_item_size/8) +'px', 'max-height':($image_grid_item_size - $image_grid_item_size/8) +'px'});
  1421. }
  1422.  
  1423. function enlargeGridItems() {
  1424. if ( $content_pane.is('.has_grid_content') && $content_grid.is('.has_font_grid') || $content_pane.is('.has_grid_content') && $content_grid.is('.has_grid') ) {
  1425. setFontSize($content_grid,$factor);
  1426. setImageSize(25);
  1427. return;
  1428. }
  1429.  
  1430. if ( $content_pane.is('.has_hidden_grid.has_font_content') ) {
  1431. setFontSize($content_font,$factor);
  1432. return;
  1433. }
  1434. if ( $content_pane.is('.has_font_content') ) {
  1435. setFontSize($content_font,$factor);
  1436. return;
  1437. }
  1438. if ( $content_pane.is('.has_grid_content') && $content_grid.is('.has_image_grid') ) {
  1439. setImageSize(25);
  1440. return;
  1441. }
  1442. }
  1443.  
  1444. function reduceGridItems() {
  1445. if ( $content_pane.is('.has_grid_content') && $content_grid.is('.has_font_grid') || $content_pane.is('.has_grid_content') && $content_grid.is('.has_grid') ) {
  1446. setFontSize($content_grid,1/$factor);
  1447. setImageSize(-25);
  1448. return;
  1449. }
  1450. if ( $content_pane.is('.has_hidden_grid.has_font_content') ) {
  1451. setFontSize($content_font,1/$factor);
  1452. return;
  1453. }
  1454. if ( $content_pane.is('.has_font_content') ) {
  1455. setFontSize($content_font,1/$factor);
  1456. return;
  1457. }
  1458. if ( $content_pane.is('.has_grid_content') && $content_grid.is('.has_image_grid') ) {
  1459. setImageSize(-25);
  1460. return;
  1461. }
  1462. }
  1463.  
  1464. $('#font_size').on('click','span',function() {
  1465. if ( $(this).attr('id') === 'increase' ) {
  1466. enlargeGridItems();
  1467. }
  1468. if ( $(this).attr('id') === 'decrease' ) {
  1469. reduceGridItems();
  1470. }
  1471. });
  1472.  
  1473. // ***** END FONT PREVIEWS ***** //
  1474.  
  1475. // Resize Sidebar/Content Pane
  1476. $handle.on('mousedown',function(f) {
  1477. f.stopPropagation();
  1478. var $startX = f.pageX;
  1479. var $sidebar_width = $sidebar_wrapper.width();
  1480. var $window_width = window.innerWidth;
  1481. $content_mask.show(); // needed to prevent interactions with iframe
  1482. $sidebar_wrapper.css({'-webkit-user-select':'none','-moz-user-select':'none','user-select':'none'});
  1483.  
  1484. $(document).on('mousemove',function(e) {
  1485. e.stopPropagation();
  1486. var $deltaX = e.pageX - $startX;
  1487. if ( e.pageX > 200 && e.pageX < $window_width - 200 ) {
  1488. $sidebar_wrapper.css({'width':$sidebar_width + $deltaX + 'px'});
  1489. $content_pane.css({'width':($window_width - $sidebar_width) - $deltaX + 'px'});
  1490. }
  1491. setContentHeight();
  1492. });
  1493. $(document).on('mouseup',function() {
  1494. $content_mask.hide();
  1495. $sidebar_wrapper.css({'-webkit-user-select':'auto','-moz-user-select':'auto','user-select':'auto'});
  1496. $(document).off('mousemove');
  1497. });
  1498. });
  1499.  
  1500.  
  1501. // Export Settings
  1502. var $settings_string = unescape( $settings.toSource() );
  1503. $settings_string = $settings_string.replace('JSON.parse\(unescape\("\{','').replace('\}"))','').replace(/\/",/g,'",').replace(/\/"],/g,'"],').replace(/"(\w+?)":/g,'\n\n$1:\t');
  1504.  
  1505. var save = function(filename, data) {
  1506. var blob = new Blob([data], {type: 'text/html'});
  1507. if(window.navigator.msSaveOrOpenBlob) {
  1508. window.navigator.msSaveBlob(blob, filename);
  1509. }
  1510. else{
  1511. var elem = window.document.createElement('a');
  1512. elem.href = window.URL.createObjectURL(blob);
  1513. elem.download = filename;
  1514. document.body.appendChild(elem);
  1515. elem.click();
  1516. document.body.removeChild(elem);
  1517. URL.revokeObjectURL(blob);
  1518. }
  1519. };
  1520.  
  1521. $export_settings.on('click','a',function(e) {
  1522. e.preventDefault();
  1523. save("settings.txt",$settings_string);
  1524. });
  1525.  
  1526.  
  1527.  
  1528. })();