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