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-07 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

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