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

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