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-05 提交的版本。查看 最新版本

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