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

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