Supercharged Local Directory File Browser

Makes file:/// directory ("Index of...") pages (and many server-generated index pages) actually useful. Adds sidebar and preview pane; keyboard navigation and sorting; media playback with shuffle, loop, and playlist (m3u) support; preview, edit, and save markdown/plain text files; preview images and fonts, with grid view; user-defined bookmarks; more.

当前为 2019-09-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Supercharged Local Directory File Browser
  3. // @version 4.1.4
  4. // @description Makes file:/// directory ("Index of...") pages (and many server-generated index pages) actually useful. Adds sidebar and preview pane; keyboard navigation and sorting; media playback with shuffle, loop, and playlist (m3u) support; preview, edit, and save markdown/plain text files; preview images and fonts, with grid view; user-defined bookmarks; more.
  5. // @author gaspar_schot
  6. // @license GPL-3.0-or-later
  7. // @homepageURL https://openuserjs.org/scripts/gaspar_schot/Supercharged_Local_Directory_File_Browser
  8. // @contributionURL https://paypal.me/mschrauzer
  9. // @include file://*
  10. // @include about:blank
  11.  
  12. // @require https://code.jquery.com/jquery-latest.min.js
  13.  
  14. // @require https://cdnjs.cloudflare.com/ajax/libs/markdown-it/9.0.1/markdown-it.js
  15. // @require https://cdnjs.cloudflare.com/ajax/libs/markdown-it-footnote/3.0.2/markdown-it-footnote.min.js
  16. // @require https://cdn.jsdelivr.net/npm/markdown-it-toc-done-right@2.1.0/dist/markdown-it-toc-made-right.min.js
  17. // @require https://cdn.jsdelivr.net/npm/markdown-it-sub@1.0.0/dist/markdown-it-sub.min.js
  18. // @require https://cdn.jsdelivr.net/npm/markdown-it-sup@1.0.0/dist/markdown-it-sup.min.js
  19. // @require https://cdn.jsdelivr.net/npm/markdown-it-deflist@2.0.3/dist/markdown-it-deflist.min.js
  20. // @require https://cdn.jsdelivr.net/npm/markdown-it-multimd-table@3.2.3/dist/markdown-it-multimd-table.min.js
  21. // @require https://cdn.jsdelivr.net/npm/markdown-it-center-text@1.0.4/dist/markdown-it-center-text.min.js
  22.  
  23. // @require https://cdn.jsdelivr.net/npm/opentype.js@latest/dist/opentype.min.js
  24.  
  25. // UPDATE URL
  26.  
  27. // NOTE: This script was developed in Vivaldi, running on Mac OS High Sierra. It has been tested in various Chrome and Gecko-based browsers.
  28. // It has been minimally tested on Windows and not at all on other OSes. It should work, but please report any issues.
  29. // The script does not work on local directories in Safari because Safari does not allow local directories to be browsed, but it will work on remote directories (or on local directories through a local server).
  30.  
  31. // 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.
  32. // For Tampermonkey, go to Chrome extension page, and tick the 'Allow access to file URLs' checkbox at the Tampermonkey extension section.
  33. // For Greasemonkey, open about:config and change greasemonkey.fileIsGreaseable to true.
  34.  
  35. // @namespace https://greasyfork.org/users/16170
  36. // ==/UserScript==
  37.  
  38. (function() {
  39. 'use strict';
  40. const $ = window.jQuery;
  41.  
  42. // ***** USER SETTINGS ***** //
  43.  
  44. const $settings = {
  45. // Paste your exported settings between the two lines below:
  46. //--------------------------------------------------------//
  47.  
  48. bookmarks: // N.B.: Directory links must end with "/", file links must end with another character.
  49. // You may add as many menus and links as you like; just copy the example below and edit as needed.
  50. // Local directory bookmarks must begin with "file:///"; external bookmarks must begin with the correct protocol ("http://" or "ftp://", etc.).
  51. // Note that because of same-origin security concerns, the browser will not allow you to navigate from an external webpage to a local directory.
  52. // But see this page for possible workarounds: https://stackoverflow.com/questions/39007243/cannot-open-local-file-chrome-not-allowed-to-load-local-resource
  53. [
  54. {
  55. "menu_title":"My Sample Menu",
  56. "links":
  57. [
  58. { "link_name":"My Directory Link 1", "link":"file:///Path/To/My/Directory/" },
  59. { "link_name":"My Directory Link 2", "link":"file:///Path/To/My/Directory_2/" },
  60. { "link_name":"My External Link", "link":"https://www.mywebpage.com/" },
  61. { "link_name":"My File Link", "link":"file:///Path/To/My/File.ext" },
  62. ]
  63. },
  64. {
  65. "menu_title":"My Second Sample Menu",
  66. "links":
  67. [
  68. { "link_name":"My Directory Link 1", "link":"file:///Path/To/My/Directory/" },
  69. { "link_name":"My Directory Link 2", "link":"file:///Path/To/My/Directory_2/" },
  70. { "link_name":"My External Link", "link":"https://www.mywebpage.com/" },
  71. { "link_name":"My File Link", "link":"file:///Path/To/My/File.ext" },
  72. ]
  73. },
  74. ],
  75. // GENERAL USER SETTINGS
  76. alternate_background: true, // If true (default true), alternate sidebar row background color.
  77. apps_as_dirs: false, // Un*x/Mac OS only: if true, treat apps as directories; allows app contents to be browsed. This is the default behavior for Chrome.
  78. // If false (default), treat apps as ignored files.
  79. autoload_media: true, // If true (default: true), the first audio or video file found in a directory will be automatically selected and loaded for playback; also, cover art (if any, will be loaded in the preview pane).
  80. autoload_index_files: false, // If true (default: false), automatically select first "index.xxx" (.xxx !== .htm) file found in directory.
  81. // Note: the browser will automatically load any index.html files it finds in the directory, so the script will not work properly in such cases.
  82. theme: 'light', // Options: 'light' or 'dark'
  83. sort_by: 'default', // Choose from: 'name', 'size', 'date', 'kind', 'ext', 'default'.
  84. // default = Chrome sorting: dirs on top, files alphabetical.
  85. dirs_on_top: false, // If true, directories will always be listed firs except when sorting by "name" (since otherwise sorting by "name" would equal "default").
  86. // If false (default), directories and files will be sorted together. (In practice, dirs will typically still be separated when sorting by size, kind, and extension.)
  87. grid_font_size: 1, // Default = 1
  88. grid_image_size: 184, // Default = 184 (200px - 16px)
  89. show_details: true, // If true (default), hide file and directory details; if false, show them.
  90. show_ignored_files: false, // If true, ignored files will appear greyed-out.
  91. // If false (default), ignored files will be completely hidden from the file list;
  92. ignore_ignored_files: true, // If true (default), ignored files (see "$row_settings" below, after Keybindings and Changelog) will be greyed-out (default) in the file list and will not be loaded in the content pane when selected;
  93. // If false, ignored files will be treated like 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 but may be useful in some circumstances).
  94. show_invisibles: true, // Un*x/Mac OS only: If true (default), files or directories beginning with a "." will be hidden.
  95. show_numbers: true, // If true (default true), number index items
  96. UI_font: 'system-ui, sans-serif', // Choose an installed font for the UI; if undefined, use browser defaults instead.
  97. UI_font_size: '13px', // Choose a default UI font size; use any standard CSS units.
  98. use_custom_icons: true, // if true (default), use custom icons for dirs and files
  99. // if false, use browser/server default icons
  100. // TEXT EDITING SETTINGS
  101. enable_text_editing: true, // If true (default), allow plain text files to be edited.
  102. default_text_view: 'preview_text', // Options: 'source_text' or 'preview_text' for text editor.
  103. // Note that split_view = true overrides this setting.
  104. split_view: true, // If true, show split view on plain text file load.
  105. // if true (default), use default preview_text setting.
  106. sync_scroll: true // If true (default: true), show split view on plain text file load
  107. // if false, use default preview_text setting.
  108. //--------------------------------------------------------//
  109. // Paste your exported settings between the above two lines.
  110. };
  111.  
  112. // $ROW_TYPES:
  113. // DO NOT DELETE ANY EXISTING CATEGORIES!
  114. // Add file extensions for sorting and custom icon display to the existing categories.
  115. // You can also define your own new categories, but do not add an extension to more than one row_type category.
  116. // Do not add leading "." to the extensions.
  117. const $row_types = {
  118. // myRowType: ['ext1','ext2'],
  119. dir: ['/'],
  120. app: ['app/','app','bat','cgi','com','exe','jar','msi','wsf'],
  121. alias: ['alias','desktop','directory','lnk','symlink'],
  122. archive: ['7z','archive','b6z','bin','bzip','bz2','cbr','dmg','gz','iso','mpkg','pkg','rar','sit','sitx','tar','tar.gz','zip','zipx'],
  123. audio: ['aac','aif','aiff','ape','flac','m4a','mp3','ogg','opus','wav'],
  124. bin: ['a','dll','dylib','icc','msi','o'],
  125. code: ['bak','bash','bash_profile','bashrc','c','cfg','cnf','codes','coffee','conf','csh','cshrc','cson','css','custom_aliases','default','dist','editorconfig','emacs','example','gemspec','gitconfig','gitignore','gitignore_global','h','hd','ini','js','json','jsx','less','list','local','login','logout','lua','mkshrc','old','php','pl','plist','pre-oh-my-zsh','profile','pth','py','rb','rc','rdoc','sass','settings','sh','strings','taskrc','tcl','viminfo','vimrc','vue','xml','yaml','yml','zlogin','zlogout','zpreztorc','zprofile','zsh','zshenv','zshrc'],
  126. database: ['accdb','db','dbf','mdb','pdb','sql', 'sqlite','sqlitedb','sqlite3'],
  127. ebook: ['azw','azw1','azw3','azw4','epub','ibook','kfx','mobi','tpz'],
  128. font: ['otf','ttf','woff','woff2','afm','pfb','pfm','tfm'],
  129. graphics: ['afdesign','ai','book','dtp','eps','fm','icml','idml','indd','indt','inx','mif','pmd','pub','qxb','qxd','qxp','sla','swf'],
  130. htm: ['htm','html','xhtm','xhtml'],
  131. image: ['apng','bmp','gif','ico','jpeg','jpg','png','svg','webp'],
  132. ignored_image: ['ai','arw','cr2','dng','eps','jpf','nef','psd','psd','raw','tif','tiff'],
  133. markdown: ['md','markdown','mdown','mkdn','mkd','mdwn','mdtxt','mdtext'],
  134. office: ['csv','doc','docx','epub','key','numbers','odf','ods','odt','pages','rtf','scriv','wpd','wps','xlr','xls','xlsx','xlm'],
  135. pdf: ['pdf'],
  136. system: ['DS_Store','ds_store','icon','ics'],
  137. text: ['log','nfo','txt','m3u'],
  138. video: ['m4v','mov','mp4','mpeg','webm']
  139. };
  140.  
  141. // $ROW_SETTINGS: Ignore or Exclude files by extension
  142. const $row_settings = {
  143. // Ignore: $row_types or files with extensions added here will not be loaded if selected in the sidebar (prevents the browser from attempting to download the file).
  144. ignore: $row_types.archive.concat( 'alias', $row_types.bin, $row_types.database, $row_types.graphics, $row_types.ignored_image, $row_types.office, $row_types.system),
  145. // Exclude: Files with these exensions will not be inverted in dark mode
  146. exclude: ['htm','html','xhtm','xhtml']
  147. };
  148.  
  149. // ***** END USER SETTINGS ***** //
  150.  
  151. // ## FEATURES INCLUDE:
  152. // - Resizable sidebar and directory/file preview pane.
  153. // - Arrow navigation in sidebar:
  154. // - Up and Down Arrows select next/prev item.
  155. // - Left and Right Arrows select next/prev item of same type.
  156. // - Navigate sidebar by typed string.
  157. // - Show/Hide file details (size (if avail), date modified (if avail), kind, extension).
  158. // - Sort sidebar items by name or file details.
  159. // - Default sort = sort by name with folders on top.
  160. // - Preview all file types supported by browser (html, text, images, pdf, audio, video, etc.) and preview fonts.
  161. // - Preview and edit markdown and plain text files, with option to save files locally.
  162. // - Markdown rendered with markdownit.js ( https://github.com/markdown-it/markdown-it ).
  163. // - Uses Github Markdown styles for preview ( https://github.com/sindresorhus/github-markdown-css ), with a few customizations.
  164. // - Support for:
  165. // - TOC creation ( `${toc}` ) ( https://github.com/nagaozen/markdown-it-toc-done-right )
  166. // - Multimarkdown table syntax ( https://github.com/RedBug312/markdown-it-multimd-table )
  167. // - Live checkboxes ( `\[ ], [x]` ), allowed in lists and deflists.
  168. // - Superscript ( `^sup^` ) ( https://github.com/markdown-it/markdown-it-sup )
  169. // - Subscript ( `~sub~` ) ( https://github.com/markdown-it/markdown-it-sub )
  170. // - Definition lists ( https://github.com/markdown-it/markdown-it-deflist; for syntax, see http://pandoc.org/MANUAL.html#definition-lists )
  171. // - Centered text ( `->centered<-` ) ( https://github.com/jay-hodgson/markdown-it-center-text )
  172. // - Footnotes ( https://github.com/markdown-it/markdown-it-footnote )
  173. // - View source text, preview, or split pane with proportional sync scroll.
  174. // - Save edited source text or previewed HTML.
  175. // - Create and edit text in separate text editor.
  176. // - Audio and video playback, with shuffle, loop, skip audio +/- 10 or 30 sec via keyboard.
  177. // - Preview other files (e.g., lyrics or cover art) in same directory while playing audio.
  178. // - User setting to autoload cover art (if any images in directory, load "cover.ext" or first image found)
  179. // - Grid view for images and fonts.
  180. // - User settings (see $settings in code; some settings can be changed via the main menu in the UI and will be remembered in URL query):
  181. // - Light or Dark theme.
  182. // - Bookmarks for local or remote directories.
  183. // - Default image grid size.
  184. // - Default UI font size and font-family.
  185. // - Default UI font and font-size.
  186. // - Default file sorting.
  187. // - Sort with directories on top.
  188. // - Treat apps as directories (MacOS and *nix only)
  189. // - Show or hide invisible files.
  190. // - Show or hide ignored files in the ignored files list (see $row_settings in code below $settings).
  191. // - Show or hide file details.
  192. // - Use custom file icons or browser defaults.
  193. // - Autoload index.ext files.
  194. // - Autoload cover art in directories with audio files.
  195. // - Text editing default view: split, source, or preview.
  196. // - Text editing sync scroll: on or off.
  197.  
  198. // ## KEYBINDINGS (These don't work in all browsers):
  199.  
  200. // - <kbd>Arrow Up/Down</kbd>: Select prev/next item.
  201. // - If audio is playing, and prev/next file is also audio, it will be highlighted but not loaded in the audio player; press return to load it.
  202. // - <kbd>Arrow Left/Right</kbd>: Select prev/next row of the same kind as the current selection.
  203. // - If current selection is a media file, select and begin playback of the next media item.
  204. // - <kbd>Opt/Alt + Arrow Left/Right</kbd>: Skip audio ±10s
  205. // - <kbd>Opt/Alt + Shift + Arrow Left/Right</kbd>: Skip audio ±30s
  206. // - <kbd>Cmd/Ctrl + Arrow Up</kbd>: Go to parent directory
  207. // - <kbd>Cmd/Ctrl + Arrow Down</kbd>: Open selected directory
  208. // - <kbd>Return</kbd>: Open selected directory, select file, or pause/play media.
  209. // - <kbd>Space</kbd>: Pause/Play media files
  210. // - <kbd>Cmd/Ctrl + D</kbd>: Toggle file details (size, date modified) in some index page types.
  211. // - <kbd>Cmd/Ctrl + E</kbd>: Show text editor.
  212. // - <kbd>Cmd/Ctrl + G</kbd>: Show or Reset Grid.
  213. // - <kbd>Cmd/Ctrl + I</kbd>: Toggle Invisibles.
  214. // - <kbd>Cmd/Ctrl + Shift + O</kbd>: Open selected item in new window/tab.
  215. // - <kbd>Cmd/Ctrl + R</kbd>: Reload grids and previewed content, reset scaled images/fonts, reset media files to beginning.
  216. // - <kbd>Cmd/Ctrl + W</kbd>: Close previewed content (doesn't work in all browsers; use close button instead), or close window if no content is being previewed.
  217. // - <kbd>Cmd/Ctrl + Shift + < or ></kbd>: Scale preview items and grids.
  218.  
  219. // CHANGELOG:
  220.  
  221. // **VERSION 4.1.4** A little more spit and polish....
  222. // **FIXED:** _Really_ fixed Up/Down arrow navigation for images with hidden grid.
  223. // **FIXED:** Arrow navigation with glyph grids.
  224. // **IMPROVED:** File and directory navigation from within the content preview pane. (This is actually pretty cool.)
  225. // - Added "Open in Sidebar" link.
  226. // - Audio, video, font, image, and pdf files will open in their default preview container.
  227. // - Note that you can now play audio opened from one directory and navigate to another directory without interruption.
  228. // - Sidebar dims when you click a directory or the "Parent Directory" link to let you know it is no longer synced with the content pane.
  229. // - Changed "Close" button behavior:
  230. // - If you have opened a file from the content pane, the close button will restore its container directory.
  231. // - If you have navigated into different directory from the content pane, the close button will reload the currently selected directory in the sidebar.
  232. // - Clicking the close button again will load the selected sidebar directory.
  233. // - "Reload" button takes you back to the selected sidebar directory.
  234. // Yet more small bugfixes and style adjustments.
  235.  
  236. // **VERSION 4.1.3.2**
  237. // **FIXED:** Image grid didn't show SVG files if width and height were set to 100%.
  238. // FIXED: Up/Down arrow navigation didn't work for images with hidden grid.
  239. // Added custom folder favicon for local directories.
  240. // Other small style tweaks.
  241.  
  242. // **VERSION 4.1.3.1**
  243. // **FIXED:** Images couldn't be scaled to less than 24 x 24px.
  244.  
  245. // **VERSION 4.1.3**
  246. // **FIXED:** _Finally_ fixed image scaling and zooming. Sorry for the delay.
  247. // **IMPROVED:** Allow image scaling > 100%.
  248. // **IMPROVED:** Show image scale percentage in the content title bar.
  249. // **IMPROVED:** Show custom file icons in content title bar.
  250. // **IMPROVED:** Highlight grid button when grid is loaded (or hidden).
  251. // **FIXED:** Invisible files were being selected even if "Show invisibles" was unchecked.
  252. // Various other small fixes and style tweaks.
  253.  
  254. // **VERSION 4.1.2**
  255. // **FIXED, CHANGED, & IMPROVED:** Image, font, and font glyph grids.
  256. // - Added up/down arrow navigation. This is a change from the previous behavior, where up/down arrows always navigated the sidebar. This will also work if the grid is hidden after selecting an image or font glyph.
  257. // - Also added arrow navigation for font glyphs, and :hover and selected styles.
  258. // - Fixed a deeply-buried bug that prevented the selected grid item from scrolling into view with arrow navigation.
  259. // - Fixed a stupid bug that prevented the first font in the directory from being included in the grid.
  260. // - Fixed some problems with normal font file browsing after viewing font glyphs.
  261. // - Improved styling for previewed and zoomed images.
  262. //
  263. // **FIXED and IMPROVED:** Playlists.
  264. // - Window title and sidebar head are now reset to indicate presence of playlist.
  265. // - First track wasn't being selected when "autoload_media" = true.
  266. // - Directory stats weren't being reset after closing a playlist.
  267. // - Grid button and "show invisibles" checkbox are hidden with open playlist.
  268. //
  269. // **IMPROVED:** Currently selected sidebar item will now scroll into view after various events, like sorting change, showing/hiding details, resizing sidebar, etc.
  270. // **FIXED:** Several menu items weren't working: Default User Settings, Export User settings, Contact, and [Donate](https://paypal.me/mschrauzer) (that might explain a few things...).
  271. // **FIXED:** Document title didn't include entire path.
  272. // Many other small bug fixes and style tweaks, including some specifically for Firefox and Safari.
  273.  
  274. // **VERSION 4.1.1**
  275. // A few small fixes and style tweaks.
  276.  
  277. // **VERSION 4.1.0**
  278. // **NEW:** Basic support for media playlists (.m3u and .m3u8).
  279. // - Added "Open Playlist..." item to the main menu.
  280. // - Playlist items will replace the current directory items in the sidebar. Times (if available) will be displayed in the "size" column. "Default" sorting = original playlist sort.
  281. // - Playlist can be closed via the "Close" button or shortcut, and the previous directory contents will be loaded.
  282. // - Streaming links are not supported.
  283. // - Beware of cross-origin limitations. For example, if your playlist includes locally-hosted media files, you will need to load it from a file:/// page in your browser.
  284. // - For remote files, if you are using a javascript-blocker (like uMatrix or NoScript), you may have to allow scripts from the hosting site (e.g., archive.org) in order for playback to work.
  285. // **NEW:** Open local fonts directly and view font information and complete glyph repertoire. (The previous ability to browse fonts in the directory list is unchanged.)
  286. // - Added "Open Font..." item in the menu item.
  287. // - View individual glyphs and save as SVG.
  288. // **FIXED:** Apps weren't being properly classified in the index.
  289. // **FIXED:** An issue with formatting the current directory name in the sidebar header.
  290. // **IMPROVED:** Refreshed UI colors and icons; added icons for more file types.
  291. // **IMPROVED:** Many styling adjustments, including setting numbers (for sizes and date, etc.) to tabular spacing.
  292. // **CHANGED:** Renamed "shortcuts" user setting to "bookmarks"; if you use exported settings, you'll have to change this in your code.
  293. // **INTERNALS:** Prettified and modularized some code. Removed some newly-unnecessary functions. Began to prune CSS.
  294. // - Updated markdown-it to 9.1.0.
  295.  
  296. // ************ J + M + J ************* //
  297. // ************************************ //
  298. // DON'T EDIT ANYTHING BELOW THIS LINE. //
  299. // ************************************ //
  300.  
  301. // ***** GENERAL SETUP ***** //
  302.  
  303. // PATHS
  304. // Fix "%" error in file name; see https://stackoverflow.com/questions/7449588/why-does-decodeuricomponent-lock-up-my-browser
  305. function decodeURIComponentSafe(s) {
  306. if ( !s ) { return s; }
  307. return decodeURIComponent(s.replace(/%(?![0-9a-fA-F]{2})/g, '%25') ); // replace % with %25 if not followed by two a-f/number
  308. }
  309. const $protocol = window.location.protocol;
  310. const $origin = $protocol +'//'+ window.location.host;
  311. const $location = decodeURIComponentSafe( [location.protocol, '//', location.host, location.pathname].join('') );
  312. const $current_dir_path = $location.replace(/([\/|_|—])/g,'$1<wbr>').replace(/\\/g,'/'); // URL w/o query string for display
  313.  
  314. function escapeStr(str) { str = str.replace(/([\^\$\|\?\*\+\(\)\[])/g,'\$1'); }
  315.  
  316. // if URL is a file, change window location to parent dir, add querystring of file name; then autoload file.
  317. function loadFile() {
  318. if ( $location.slice($location.lastIndexOf('/')).indexOf('.') !== -1 && !$location.endsWith('/') && window.top === window.self ) {
  319. let $query_prefs = getQueryPrefs();
  320. $query_prefs.set( 'file', $location.slice($location.lastIndexOf('/') + 1) );
  321. window.location = $location.slice(0,$location.lastIndexOf('/') + 1) +'?'+ $query_prefs;
  322. return;
  323. }
  324. }
  325. loadFile();
  326.  
  327. // QUERY PREFS
  328. function getQueryPrefs() { return new URL(window.location).searchParams; }
  329. // const initialQueryPrefs = getQueryPrefs();
  330. // set query key/value
  331. function setQuery(key, value) {
  332. let $query_prefs = getQueryPrefs();
  333. $query_prefs.set( key, value );
  334. updateQuery($query_prefs);
  335. }
  336. // get query value
  337. function getQuery(key) {
  338. let $query_prefs = getQueryPrefs();
  339. let value = '';
  340. if ( key === 'width' ) {
  341. value = ( !$query_prefs.has(key) ? 30 : Math.round(100 * Number.parseInt($query_prefs.get('width'))/window.innerWidth) ); // number string
  342. } else {
  343. value = ( $query_prefs.has(key) ? $query_prefs.get(key) : $settings[key] !== undefined ? $settings[key].toString() : '' );
  344. value = value.replace('%2F','').replace('/',''); // some servers add a '/' to end of query string
  345. }
  346. return value;
  347. }
  348. // toggle query key
  349. function toggleQuery(key) {
  350. let $query_prefs = getQueryPrefs();
  351. let nonBoolPrefs = {
  352. 'theme_light': {'theme':'dark'},
  353. 'theme_dark': {'theme':'light'},
  354. 'source_text': {'default_text_view':'preview_text'},
  355. 'preview_text': {'default_text_view':'source_text'},
  356. 'sort_by_default': {'sort_by':'default'},
  357. 'sort_by_name': {'sort_by':'name'},
  358. 'sort_by_size': {'sort_by':'size'},
  359. 'sort_by_date': {'sort_by':'date'},
  360. 'sort_by_kind': {'sort_by':'kind'},
  361. 'sort_by_ext': {'sort_by':'ext'}
  362. };
  363. var value, queryValue, settingsValue;
  364. if ( nonBoolPrefs[key] !== undefined ) {
  365. value = Object.values(nonBoolPrefs[key]).toString();
  366. key = Object.keys(nonBoolPrefs[key]).toString(); // must come after value: i.e., don't redefine key before getting value
  367. if ( $settings[key] === value ) { $query_prefs.delete( key ); } else { $query_prefs.set( key, value ); }
  368. } else {
  369. queryValue = $query_prefs.get(key);
  370. settingsValue = $settings[key];
  371. value = ( queryValue === null ? settingsValue.toString() : queryValue.toString() );
  372. value = ( value === 'true' ? 'false' : 'true' );
  373. if ( ( queryValue !== null && queryValue !== settingsValue ) ) {
  374. $query_prefs.delete( key );
  375. } else {
  376. $query_prefs.set( key, value );
  377. }
  378. }
  379. updateQuery($query_prefs);
  380. }
  381. // remove query key
  382. function removeQuery(key) {
  383. let $query_prefs = getQueryPrefs();
  384. $query_prefs.delete(key);
  385. updateQuery($query_prefs);
  386. }
  387. // update query string
  388. function updateQuery(querystr) {
  389. querystr = querystr.toString().replace('%2F','').replace('/','');
  390. window.history.replaceState({}, document.title, window.location.pathname +'?'+ querystr);
  391. updateParentLinks();
  392. }
  393.  
  394. // ***** SET UP UI ELEMENTS ***** //
  395.  
  396. // SIDEBAR ELEMENTS
  397. // ***** BUILD MENUS ***** //
  398. // Parent and Parents Menus
  399. function updateQueryStr(str) {
  400. str = str.replace(/([^\?]*)selected=[^&]*(.*)$/m,'$1$2') // delete current selected query, if any
  401. .replace(/([^\?]*)history=(\d+)\+*([^&]*)(&*)(.*)/m,'$1$4$5&selected=$2&history=$3').replace(/&{2,}/g,'&').replace(/\?&/m,'\?'); // format query with selected and history at end
  402. if ( str.endsWith('&history=') ) { str = str.replace(/(.+)&history=$/m,'$1'); } // if no history, delete query
  403. return str;
  404. }
  405. // create links
  406. function createParentLinks() {
  407. let $links = [];
  408. let str = decodeURIComponentSafe(window.location.search);
  409. str = str.replace('/','').replace('%2F','');
  410. let $linkPieces = $location.split('/');
  411. $linkPieces = $linkPieces.slice(2,-2); // remove beginning and ending empty elements and current directory
  412. while ( $linkPieces.length > 0 ) { // while there are link pieces...
  413. str = updateQueryStr(str); // update selected and history
  414. let link = $protocol +'//'+ $linkPieces.join('/') +'/'+ str; // assemble link
  415. $links.push(link); // add to link array
  416. $linkPieces.pop(); // remove last link piece and repeat...
  417. }
  418. return $links;
  419. }
  420. // create menu items
  421. function createParentLinkItems() {
  422. let $parent_link_menu_items = [];
  423. let $links = createParentLinks();
  424. $('#parent_dir_menu').find('a').attr( 'href', $links[0] ); // set parent link
  425. for ( let i = 0; i < $links.length; i++ ) {
  426. let display_name = $links[i].slice(0,$links[i].lastIndexOf('?') - 1);
  427. display_name = display_name.replace(/\//g,'\/<wbr>');
  428. let menu_item = '<li><a href="'+ $links[i] +'">' + display_name + '/</a></li>';
  429. $parent_link_menu_items.push(menu_item);
  430. }
  431. return $parent_link_menu_items; // return parents link items
  432. }
  433. function updateParentLinks() { $('#parents_dir_menu').siblings('ul').empty().append( createParentLinkItems() ); }
  434.  
  435. // MENUS: User bookmarks
  436. function bookmarksMenuItems() {
  437. const $bookmarks = $settings.bookmarks;
  438. let menu_items = [];
  439. let $links_arr = [];
  440. let $links_arr_str = '';
  441. let $links;
  442. if ( $bookmarks.length > 0 ) {
  443. for ( let i = 0; i < $bookmarks.length; i+=1 ) {
  444. $links = $bookmarks[i].links;
  445. // make array of links
  446. for ( let j = 0; j < $links.length; j+=1 ) {
  447. if ( !$links[j].link.endsWith('/') ) {
  448. $links[j].link = $links[j].link.slice(0,$links[j].link.lastIndexOf('/') + 1) + '?file=' + $links[j].link.slice($links[j].link.lastIndexOf('/') + 1) ;
  449. }
  450. $links[j].link_name = $links[j].link_name.split('/').join('/<wbr>');
  451. $links_arr[j] = '<li><a href="'+ $links[j].link +'">' + $links[j].link_name + '</a></li>';
  452. }
  453. $links_arr_str = $links_arr.join('');
  454. menu_items[i] = '<li class="bookmarks has_submenu"><a>'+ $bookmarks[i].menu_title +'</a><ul>'+ $links_arr_str +'</ul></li>';
  455. }
  456. menu_items = menu_items.join('');
  457. }
  458. return menu_items;
  459. }
  460. // MENUS: Other menu items
  461. const MenuItems = function() {
  462. let sort_by = '<li class="has_submenu rule" id="sort_by"><span>Sort by&hellip;</span><ul id="sort_menu"><li id="name"><span>Name</span></li><li id="size"><span>Size</span></li><li id="date"><span>Date</span></li><li id="kind"><span>Kind</span></li><li id="ext"><span>Extension</span></li><li id="default"><span>Default</span></li></ul>';
  463. let autoload_media = '<li class="toggle_UI_pref rule" id="autoload_media"><span id="autoload_media_menu">Autoload Media</span></li>';
  464. let theme = '<li><span id="theme" class="toggle_UI_pref"><span id="theme_dark">Dark Theme</span><span id="theme_light">Light Theme</span></span></li>';
  465. let alternate_background = '<li class="toggle_UI_pref" id="alternate_background"><span>Alternate Backgrounds</span></li>';
  466. let show_numbers = '<li class="toggle_UI_pref rule" id="show_numbers"><span>Show Numbers</span></li>';
  467. let text_editing = '<li class="has_submenu" id="text_editing"><span>Text Editing</span><ul id="text_editing_menu"><li id="text_editor_menu_item" class="rule"><span id="text_editor">Toggle Text Editor</span></li><li id="split_view" class="toggle_UI_pref rule"><span id="toggle_split_view">Split View</span></li><li id="preview_text_menu_item"><span class="toggle_UI_pref" id="source_text">Source Text</span><span class="toggle_UI_pref" id="preview_text">Preview Text</span></li></ul>';
  468. let disable_text_editing = '<li class="rule"><span class="toggle_UI_pref" id="enable_text_editing">Disable Text Editing</span></li>';
  469. let open_playlist = '<li class="rule"><label id="open_playlist_label" for="open_playlist">Open Playlist&hellip;</label><input type="file" id="open_playlist" name="open_playlist" accept=".m3u,.m3u8"></input></li>';
  470. let open_font = '<li class="rule"><label id="open_font_label" for="open_font">Open Font&hellip;</label><input type="file" id="open_font" name="open_font" accept=".otf,.ttf,.woff"></input></li>';
  471. let default_settings = '<li><a href="#" id="default_settings" title="Delete URL query string and reload page.">Default User Settings</a></li>';
  472. let export_settings = '<li class="rule"><a href="#" id="export_settings" title="Export user settings to text file.">Export User Settings</a></li>';
  473. let contact_link = '<li><a id="contact" href="mailto:mshroud@vivaldi.net">Contact</a></li>';
  474. let donate_link = '<li><a id="donate" href="https://paypal.me/mschrauzer" target="_blank" rel="noopener">Donate</a></li>';
  475. return sort_by + theme + alternate_background + show_numbers + autoload_media + text_editing + disable_text_editing + open_playlist + open_font + default_settings + export_settings + contact_link + donate_link;
  476. };
  477. const SidebarHeaderEls = function() {
  478. let parent_link_items = createParentLinkItems();
  479. let parent_link = $(parent_link_items[0]).find('a').attr('href');
  480. parent_link_items = parent_link_items.toString().replace(/<\/li>,<li>/g,'</li><li>');
  481. let parent_dir_menu = '<nav id="parent_dir_menu"><a href="'+ parent_link +'">&nbsp;</a></nav>';
  482. let parents_dir_menu = '<nav id="parents_dir_menu"><div>'+ $current_dir_path +'</div></nav><ul class="menu">'+ parent_link_items +'</ul>';
  483. let bookmarks_menu = '<nav id="bookmarks_menu"><div>&nbsp;</div></nav><ul id="bookmarks" class="menu">'+ bookmarksMenuItems() + MenuItems() +'</ul>';
  484. let show_details = '<button class="toggle_UI_pref" id="show_details" tabindex="-1"><span>Show details</span><span>Hide details</span></button>';
  485. let inv_checkbox = '<label><input class="toggle_UI_pref" type="checkbox" id="show_invisibles" for="inv_checkbox" name="inv_checkbox" tabindex="-1" />Show Invisibles</label>';
  486. let grid_btn = '<td 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></td>';
  487. let sorting = '<tr class="header"><th id="sorting" colspan="4"><div><div class="toggle_UI_pref name sorting" id="sort_by_name" colspan="2"><span><input id="play_toggle" type="checkbox" tabindex="-1" checked="true" />Name</span></div><div class="toggle_UI_pref sorting" id="sort_by_default" colspan="2"><span>Default</span></div><div class="toggle_UI_pref details sorting" id="sort_by_size"><span>Size</span></div><div class="toggle_UI_pref details sorting" id="sort_by_date"><span>Date</span></div><div class="toggle_UI_pref details sorting" id="sort_by_kind"><span>Kind</span></div><div class="toggle_UI_pref details sorting" id="sort_by_ext"><span>Ext</span></div></div></th></tr>';
  488. let text_editor_row = '<tr id="text_editor_row"><th colspan="4"><a href="#" title="Toggle Text Editor">Text Editor</a></th></tr>';
  489. let sidebar_header = '<table id="sidebar_header"><thead><tr id="sidebar_title"><th colspan="4"></th></tr></thead><tbody><tr id="sidebar_menus"><td>'+ parent_dir_menu +'</td><td colspan="2">'+ parents_dir_menu +'</td><td id="bookmarks_menu_container">'+ bookmarks_menu +'</td></tr><tr id="sidebar_buttons"><td colspan="3">'+ show_details + inv_checkbox +'</td>'+ grid_btn +'</tr>'+ sorting + text_editor_row +'</tbody></table>';
  490. let sidebar_header_els = sidebar_header;
  491. return sidebar_header_els;
  492. };
  493. // Dir List Elements
  494. const SidebarDirListEls = function() {
  495. let dir_list_body = '<tbody id="tbody"></tbody>';
  496. let dir_list_foot = '<tfoot id="tfoot"><tr id="index_stats"><td id="stats"></td><td id="toggle_info" data-kind="info" title="View current directory index source">&nbsp;</td></tr></tfoot>';
  497. let sidebar_dir_list_els = '<table id="dir_list">'+ dir_list_body + dir_list_foot +'</table>';
  498. return sidebar_dir_list_els;
  499. };
  500. // CONTENT PANE ELEMENTS
  501. const ContentHeaderEls = function() {
  502. let title_buttons_left = '<td id="title_buttons_left"><button id="reload_btn" tabindex="-1"><span>Reload</span></button><button id="prev_next_btns" class="split_btn"><span id="prev_btn"><span>&nbsp;</span></span><span id="next_btn"><span>&nbsp;</span></span></button></td>';
  503. let title = '<td id="title"><span></span></td>';
  504. let title_buttons_right = '<td id="title_buttons_right"><button id="scale" class="split_btn"><span id="decrease">&nbsp;</span><span id="increase">&nbsp;</span></button><button id="close_btn" tabindex="-1"><span>Close</span></button></td>';
  505. let content_title = '<tr id="content_title">'+ title_buttons_left + title + title_buttons_right +'</tr>';
  506. let content_header_els = '<header id="content_header"><table><tbody>'+ content_title + ContentAudioEls() +'</tbody></table></header>';
  507. return content_header_els;
  508. };
  509. // Content containers
  510. const ContentEls = function() {
  511. let content_grid = '<div id="content_grid" data-grid-scale-factor="1" data-kind="grid"></div>';
  512. let content_text = '<div id="content_text"></div>';
  513. let content_font = '<div id="content_font" class="content" spellcheck="false" data-kind="font">'+ ContentFontEls() +'</div>';
  514. let content_image = '<div id="content_image" class="content" data-kind="image"><img /></div>';
  515. let content_video = '<video id="content_video" class="content media" controls data-kind="video">Your browser does not support the video tag.</video>';
  516. let content_pdf = '<embed id="content_pdf" class="content" name="plugin" tabindex="0" data-kind="pdf"></embed>';
  517. let content_iframe = '<iframe id="content_iframe" class="content" name="content_iframe" sandbox="allow-scripts allow-same-origin allow-modals" tabindex="0" data-kind="file"></iframe>';
  518. let content_els = '<section id="content_container">'+ content_grid + content_text + content_font + content_image + content_pdf + content_video + content_iframe +'</section>';
  519. return content_els;
  520. };
  521. // Content Audio Els
  522. const ContentAudioEls = function() {
  523. let prev_track = '<div id="prev_track" class="prev_next_track_btn" title="Previous track">&nbsp;</div>';
  524. let next_track = '<div id="next_track" class="prev_next_track_btn" title="Next track">&nbsp;</div>';
  525. let audio_player = '<audio id="audio" preload="auto" tabindex="0" controls >Sorry, your browser does not support HTML5 audio.</audio>';
  526. let loop = '<label><input type="checkbox" id="loop" for="loop" name="loop" tabindex="0" />Loop</label>';
  527. let shuffle = '<label><input type="checkbox" id="shuffle" for="shuffle" name="shuffle" tabindex="0" />Shuffle</label>';
  528. let checkbox_cont = '<div id="checkbox_div">'+ loop + shuffle +'</div>';
  529. let close_audio = '<div id="close_audio" title="Close audio"></div>';
  530. let content_audio_title = '<tr id="content_audio_title"><td colspan="3"></td></tr>';
  531. let content_audio_els = content_audio_title +'<tr id="content_audio"><td colspan="3"><div id="audio_container">'+ prev_track + next_track + audio_player + close_audio +'</div>'+ checkbox_cont +'</td></tr>';
  532. return content_audio_els;
  533. };
  534. // Content Font Els
  535. const ContentFontEls = function() {
  536. let sample_string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ<br />abcdefghijklmnopqrstuvwxyz<br />0123456789 [(!@#$%^&*;:)]';
  537. let specimen = '<div class="specimen" contenteditable="true" style="font-size:4em;word-break: break-all;line-height: 1.2;">'+ sample_string +'</div>';
  538. let hamburger_string = '<h1 style="font-size:8em">Typography</h1><h4 style="font-size:1.618em">The art of using types to produce impressions on paper, vellum, &amp;c.</h4><h2 style="font-size:6em;text-align:justify;">S P E C I M E N</h2><h3 style="font-size:2em">Typography is the work of typesetters (also known as compositors), typographers, graphic designers, art directors, manga artists, comic book artists, graffiti artists, and, now, anyone who arranges words, letters, numbers, and symbols for publication, display, or distribution.</h3>';
  539. let 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.';
  540. let lorem = '<div class="lorem" style="text-align:justify;font-size:1em;line-height: 1.4;column-gap:1.5em;overflow-wrap: normal;word-break: normal;" contenteditable="true">'+ lorem_string +'</div>';
  541. let lorem2 = lorem.replace('style="','style="columns:2;');
  542. let lorem3 = lorem.replace('style="','style="columns:3;');
  543. let hamburger = '<div class="hamburger" style="text-align:justify" contenteditable="true">'+ hamburger_string +'</div>'+ lorem + lorem2 + lorem3 +'</div>';
  544. let font_specimen = '<div id="font_specimen">'+ specimen + hamburger + ContentFontViewer() +'</div>';
  545. return font_specimen;
  546. };
  547. const ContentFontViewer = function() {
  548. let glyphs_container = '<div id="glyphs_container"></div>';
  549. let glyph_viewer = '<div id="glyph_viewer"><div id="glyph_viewer_info" style="height:18px;line-height:1.6;"><button id="save_svg_hidden" style="visibility:hidden;float:left;">Save SVG</button><div></div><button id="save_svg" style="float:right;">Save SVG</button></div></div>';
  550. let font_viewer = '<div id="font_viewer" style="font-family:unset">'+ glyphs_container + glyph_viewer +'</div>';
  551. return font_viewer;
  552. };
  553. // ASSEMBLE SIBEBAR & CONTENT PANE ELEMENTS
  554. const MainContent = function() {
  555. let handle = '<div id="handle"></div>';
  556. let toggle_sidebar = '<div id="toggle_sidebar"></div>';
  557. let warnings = '<div id="warnings"><h3>Warning:</h3><p id="warning_unsaved">You have unsaved changes.</p><p id="warning_clear">Are you sure you want to clear all your text?</p><p id="warning_local">Can\'t load local directories or files from non-local web pages. Use your browser\'s bookmarks or enter the URL manually.</p><div><button id="warning_ignore_btn">Don\'t Save</button><button id="warning_cancel_btn" >Cancel</button><button id="warning_clear_btn">Clear</button><button id="warning_save_btn">Save</button><button id="warning_ok_btn">OK</button></div></div>';
  558. let overlay = '<div id="overlay"></div>';
  559. let sidebar = '<div id="sidebar">'+ SidebarHeaderEls() + SidebarDirListEls() +'</div>';
  560. let sidebar_wrapper = '<td id="sidebar_wrapper">'+ sidebar + handle + toggle_sidebar +'</td>';
  561. let content_pane = '<td id="content_pane" class="">'+ ContentHeaderEls() + ContentEls() +'</td>';
  562.  
  563. let main_head = '<thead><tr><th>'+ warnings + overlay +'</th></tr></thead>';
  564. let main_body = '<tbody><tr>'+ sidebar_wrapper + content_pane +'</tr></tbody>';
  565. let main_foot = '<tfoot></tfoot>';
  566. let main_content = '<table id="main_content">'+ main_head + main_body + main_foot +'</table>';
  567. return $(main_content);
  568. };
  569. // DEFINE Content Elements
  570. const $main_content = MainContent();
  571. // DIR LIST
  572. const $dir_list_body = $main_content.find('#tbody');
  573. const $dir_list = $main_content.find('#dir_list');
  574. // CONTENT
  575. const $content_pane = $main_content.find('#content_pane');
  576. const $audio_player = $main_content.find('#audio');
  577. const $content_text = $main_content.find('#content_text');
  578. const $content_grid = $main_content.find('#content_grid');
  579. const $content_font = $main_content.find('#content_font');
  580. const $content_image = $main_content.find('#content_image');
  581. const $content_pdf = $main_content.find('#content_pdf');
  582. const $content_video = $main_content.find('#content_video');
  583. const $content_iframe = $main_content.find('#content_iframe');
  584.  
  585. // SVG UI ICONS
  586. function SVG_UI_Icon(icon_name) {
  587. let svg = '';
  588. if ( icon_name.endsWith('_dark') ) {
  589. icon_name = icon_name.slice(0,-5);
  590. svg = SVG_UI_Icons[icon_name];
  591. svg = svg.replace(/4{6}/g,'BBBBBB');
  592. } else {
  593. svg = SVG_UI_Icons[icon_name];
  594. }
  595. return 'url("data:image/svg+xml;utf8,'+ svg +'")';
  596. }
  597. const SVG_UI_Icons = {
  598. 'arrow': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M4 4l12 6-12 6z\' /></svg>',
  599. 'bookmark': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M2 2c0-1.1.9-2 2-2h12a2 2 0 0 1 2 2v18l-8-4-8 4V2zm2 0v15l6-3 6 3V2H4z\' /></svg>',
  600. 'check_mark': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 12 09\'><g transform=\'matrix(0.55,5.55112e-17,-5.55112e-17,0.55,0.578932,-1.01245)\'><path d=\'M-0.071,10.929L2.5,8.358L7,12.857L17.285,2.572L19.856,5.144L7,18L-0.071,10.929Z\' style=\'fill:rgb(68,68,68);fill-rule:nonzero;\'/></g></svg>',
  601. 'chevron_up': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 12 08\'><g transform=\'matrix(1,0,0,1,-3.843,-5.843)\'><path d=\'M10.707,7.05L10,6.343L4.343,12L5.757,13.414L10,9.172L14.243,13.414L15.657,12L10.707,7.05Z\' style=\'fill:rgb(68,68,68);fill-rule:nonzero;\'/></g></svg>',
  602. 'chevron_right': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 08 12\'><g transform=\'matrix(1,0,0,1,-6.086,-4)\'><path d=\'M12.95,10.707L13.657,10L8,4.343L6.586,5.757L10.828,10L6.586,14.243L8,15.657L12.95,10.707Z\' style=\'fill:rgb(68,68,68);fill-rule:nonzero;\'/></g></svg>',
  603. 'chevron_down': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 12 08\'><g transform=\'matrix(1,0,0,1,-4,-6.157)\'><path d=\'M9.293,12.95L10,13.657L15.657,8L14.243,6.586L10,10.828L5.757,6.586L4.343,8L9.293,12.95Z\' style=\'fill:rgb(68,68,68);fill-rule:nonzero;\'/></g></svg>',
  604. 'chevron_left': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 08 12\'><g transform=\'matrix(1,0,0,1,-5.843,-4)\'><path d=\'M7.05,9.293L6.343,10L12,15.657L13.414,14.243L9.172,10L13.414,5.757L12,4.343L7.05,9.293Z\' style=\'fill:rgb(68,68,68);fill-rule:nonzero;\'/></g></svg>',
  605. 'document': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M4 18h12V6h-4V2H4v16zm-2 1V0h12l4 4v16H2v-1z\' /></svg>',
  606. 'error': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23FFB636\' id=\'Layer_2\' d=\'M1.075,18.05l8.146,-16.683c0.236,-0.484 0.924,-0.491 1.169,-0.011l8.537,16.683c0.223,0.435 -0.093,0.952 -0.582,0.952l-16.683,0c-0.483,0 -0.799,-0.507 -0.587,-0.941Z\' style=\'fill-opacity:0.75;fill-rule:nonzero;\'/><path id=\'Layer_3\' d=\'M11.055,7.131l-0.447,6.003c-0.034,0.45 -0.425,0.787 -0.874,0.753c-0.408,-0.03 -0.724,-0.356 -0.753,-0.753l-0.447,-6.003c-0.052,-0.696 0.47,-1.302 1.167,-1.354c0.696,-0.052 1.302,0.47 1.354,1.166c0.005,0.061 0.004,0.129 0,0.188Zm-1.26,8.037c-0.641,0 -1.159,0.518 -1.159,1.158c0,0.641 0.518,1.159 1.159,1.159c0.64,0 1.158,-0.518 1.158,-1.159c0,-0.64 -0.518,-1.158 -1.158,-1.158Z\' style=\'fill:%23444;fill-opacity:0.75;fill-rule:nonzero;\'/></svg>',
  607. 'folder': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M0 4c0-1.1.9-2 2-2h7l2 2h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V4zm2 2v10h16V6H2z\' /></svg>',
  608. 'grid': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M0 0h9v9H0V0zm2 2v5h5V2H2zm-2 9h9v9H0v-9zm2 2v5h5v-5H2zm9-13h9v9h-9V0zm2 2v5h5V2h-5zm-2 9h9v9h-9v-9zm2 2v5h5v-5h-5z\' /></svg>',
  609. 'grid_loaded': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23118888\' d=\'M0 0h9v9H0V0zm2 2v5h5V2H2zm-2 9h9v9H0v-9zm2 2v5h5v-5H2zm9-13h9v9h-9V0zm2 2v5h5V2h-5zm-2 9h9v9h-9v-9zm2 2v5h5v-5h-5z\' /></svg>',
  610. 'grid_loaded_dark': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23AA4444\' d=\'M0 0h9v9H0V0zm2 2v5h5V2H2zm-2 9h9v9H0v-9zm2 2v5h5v-5H2zm9-13h9v9h-9V0zm2 2v5h5V2h-5zm-2 9h9v9h-9v-9zm2 2v5h5v-5h-5z\' /></svg>',
  611. 'ignored': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M0 10a10 10 0 1 1 20 0 10 10 0 0 1-20 0zm16.32-4.9L5.09 16.31A8 8 0 0 0 16.32 5.09zm-1.41-1.42A8 8 0 0 0 3.68 14.91L14.91 3.68z\' opacity=\'0.25\' /></svg>',
  612. 'ignored_dark': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M0 10a10 10 0 1 1 20 0 10 10 0 0 1-20 0zm16.32-4.9L5.09 16.31A8 8 0 0 0 16.32 5.09zm-1.41-1.42A8 8 0 0 0 3.68 14.91L14.91 3.68z\' opacity=\'0.66\' /></svg>',
  613. 'menu': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z\' /></svg>',
  614. 'minus': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><rect fill=\'%23444444\' x=\'1\' y=\'8\' width=\'18\' height=\'4\' /></svg>',
  615. 'multiply': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M10,7l6,-6l3,3l-6,6l6,6l-3,3l-6,-6l-6,6l-3,-3l6,-6l-6,-6l3,-3l6,6Z\'/></svg>',
  616. 'music': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23888888\' d=\'M15.987,13.982c0,0.906 -0.413,1.664 -1.239,2.274c-0.757,0.554 -1.604,0.831 -2.541,0.831c-0.548,0 -0.998,-0.129 -1.348,-0.388c-0.389,-0.295 -0.583,-0.708 -0.583,-1.238c0,-0.838 0.398,-1.574 1.192,-2.209c0.752,-0.597 1.559,-0.896 2.421,-0.896c0.727,0 1.257,0.145 1.59,0.434l0,-9.489l-6.755,1.82l0,10.774c0,0.906 -0.413,1.663 -1.238,2.273c-0.758,0.555 -1.605,0.832 -2.541,0.832c-0.549,0 -0.998,-0.13 -1.35,-0.388c-0.388,-0.296 -0.582,-0.709 -0.582,-1.238c0,-0.838 0.398,-1.574 1.192,-2.209c0.752,-0.597 1.559,-0.896 2.421,-0.896c0.727,0 1.257,0.145 1.589,0.434l0,-11.605l7.772,-2.098l0,12.982Z\' style=\'fill-opacity:0.4;fill-rule:nonzero;\'/></svg>',
  617. 'plus': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M8.001,1l3.999,0l0,7l7,0l0,4l-7,0l-0.001,7l-3.999,0l0,-7l-7,0l0,-4l7,0l0.001,-7Z\'/></svg>',
  618. 'prev_next_track': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M13,5l2,0l0,10l-2,0l0,-10Zm-8,0l8,5l-8,5l0,-10Z\'/></svg>',
  619. 'prev_next_track_ff': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23FFFFFF\' d=\'M12.8,14l-10.8,-7l10.8,-7l0,14Z\'\'/><rect x=\'0\' y=\'0\' width=\'2\' height=\'14\' style=\'fill:%23fff;\'/></svg>',
  620. 'spinner': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 40 40\'><g><g transform=\'translate(1 1)\'><circle style=\'fill:none;stroke:%23666666;stroke-width:4;stroke-opacity:0.5;\' cx=\'18\' cy=\'18\' r=\'18\'/><path style=\'fill:none;stroke:%23AAAAAA;stroke-width:4;\' d=\'M36,18c0-9.94-8.061-18-18-18 \'><animateTransform type=\'rotate\' fill=\'remove\' repeatCount=\'indefinite\' attributeName=\'transform\' restart=\'always\' dur=\'1s\' from=\'0 18 18\' calcMode=\'linear\' to=\'360 18 18\' accumulate=\'none\' additive=\'replace\'></animateTransform></path></g></g></svg>',
  621. 'toggle': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M10.207,9.293l-0.707,0.707l5.657,5.657l1.414,-1.414l-4.242,-4.243l4.242,-4.243l-1.414,-1.414l-4.95,4.95Z\' /><path fill=\'%23444444\' d=\'M4.207,9.293l-0.707,0.707l5.657,5.657l1.414,-1.414l-4.242,-4.243l4.242,-4.243l-1.414,-1.414l-4.95,4.95Z\'/></svg>',
  622. };
  623.  
  624. function SVG_UI_File_Icon(icon_name) {
  625. if ( icon_name === 'file_icon_dir_default' ) { // default chrome icons
  626. return '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= ")';
  627. } else if ( icon_name === 'file_icon_file_default' ) {
  628. return 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAABHUlEQVR42o2RMW7DIBiF3498iHRJD5JKHurL+CRVBp+i2T16tTynF2gO0KSb5ZrBBl4HHDBuK/WXACH4eO9/CAAAbdvijzLGNE1TVZXfZuHg6XCAQESAZXbOKaXO57eiKG6ft9PrKQIkCQqFoIiQFBGlFIB5nvM8t9aOX2Nd18oDzjnPgCDpn/BH4zh2XZdlWVmWiUK4IgCBoFMUz9eP6zRN75cLgEQhcmTQIbl72O0f9865qLAAsURAAgKBJKEtgLXWvyjLuFsThCSstb8rBCaAQhDYWgIZ7myM+TUBjDHrHlZcbMYYk34cN0YSLcgS+wL0fe9TXDMbY33fR2AYBvyQ8L0Gk8MwREBrTfKe4TpTzwhArXWi8HI84h/1DfwI5mhxJamFAAAAAElFTkSuQmCC ")';
  629. } else { // custom icons
  630. return 'url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons[icon_name] +'")';
  631. }
  632. }
  633. const SVG_UI_File_Icons = {
  634. 'file_icon_alias': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><rect x=\'0\' y=\'0\' width=\'14\' height=\'14\' style=\'fill:%23808080;fill-rule:nonzero;\'/><path d=\'M3,12.5c0,-3.863 2.253,-7.5 6.259,-7.5\' style=\'fill:none;stroke:%23fc6;stroke-width:3px;\'/><path d=\'M13,5l-4,-4l0,8l4,-4Z\' style=\'fill:%23fc6;\'/></svg>',
  635. 'file_icon_archive': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M11,8.5l0,-1l2,0l0,2l-5,1l-2,0l0,1.5l4,0l0,1l-4,0l0,1l-3,0l0,-1l-2,0l0,-1l2,0l0,-1.5l-2,0l0,-2l2,0l0,-6.5l-2,0l0,-2l7,0l5,1l0,2l-2,0l0,-1l-5,0l0,6.5l5,0Z\' style=\'fill:%23999;\'/></svg>',
  636. 'file_icon_app': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path id=\'rect6894\' d=\'M6.125,0l-0.292,1.859c-0.587,0.135 -1.146,0.38 -1.64,0.693l0,-0.018l-1.532,-1.094l-1.221,1.221l1.094,1.532l0.018,0c-0.313,0.495 -0.559,1.051 -0.693,1.64l-1.859,0.292l0,1.75l1.859,0.292c0.134,0.589 0.38,1.145 0.693,1.64l-0.018,0l-1.094,1.532l1.221,1.221l1.532,-1.094l0,-0.018c0.494,0.313 1.053,0.558 1.64,0.693l0.292,1.859l1.75,0l0.292,-1.859c0.596,-0.137 1.14,-0.372 1.64,-0.693l1.532,1.112l1.221,-1.221l-1.112,-1.532c0.309,-0.492 0.523,-1.057 0.656,-1.64l1.896,-0.292l0,-1.75l-1.896,-0.292c-0.133,-0.583 -0.347,-1.148 -0.656,-1.64l0.018,0l1.094,-1.532l-1.221,-1.221l-1.532,1.094l0,0.018c-0.5,-0.321 -1.044,-0.556 -1.64,-0.693l-0.292,-1.859l-1.75,0Zm0.875,4.667c1.288,0 2.333,1.036 2.333,2.333c0,1.297 -1.045,2.333 -2.333,2.333c-1.288,0 -2.333,-1.036 -2.333,-2.333c0,-1.297 1.045,-2.333 2.333,-2.333Z\' style=\'fill:%237a7ab8;\'/></svg>',
  637. 'file_icon_audio': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><g id=\'Layer1\'><circle cx=\'7\' cy=\'7\' r=\'7\' style=\'fill:%230f8a8a;\'/></g><path d=\'M11,9.5l0,0c-0.019,0.681 -0.796,1.339 -1.75,1.475c-0.966,0.138 -1.75,-0.31 -1.75,-1c0,-0.69 0.784,-1.362 1.75,-1.5c0.268,-0.038 0.523,-0.031 0.75,0.013l0,-4.488l-4,0l0,6.5l0,0c-0.019,0.681 -0.796,1.339 -1.75,1.475c-0.966,0.138 -1.75,-0.31 -1.75,-1c0,-0.69 0.784,-1.362 1.75,-1.5c0.268,-0.038 0.523,-0.031 0.75,0.013l0,-6.488l6,-1l0,7.5Z\' style=\'fill:%23fff;\'/><path d=\'M11,2l-6,1l0,2l6,-1l0,-2Z\' style=\'fill:%23fff;\'/></svg>',
  638. 'file_icon_binary': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><rect x=\'0\' y=\'0\' width=\'14\' height=\'14\' style=\'fill:%23808080;fill-rule:nonzero;\'/><g><path d=\'M1.247,6.495l3.263,0l0,-1.067l-0.881,0l0,-3.835l-0.974,0c-0.371,0.232 -0.727,0.371 -1.284,0.479l0,0.82l0.928,0l0,2.536l-1.052,0l0,1.067Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/><path d=\'M7,6.588c1.082,0 1.825,-0.89 1.825,-2.567c0,-1.67 -0.743,-2.521 -1.825,-2.521c-1.082,0 -1.825,0.843 -1.825,2.521c0,1.677 0.743,2.567 1.825,2.567Zm0,-1.021c-0.309,0 -0.572,-0.247 -0.572,-1.546c0,-1.299 0.263,-1.5 0.572,-1.5c0.309,0 0.572,0.201 0.572,1.5c0,1.299 -0.263,1.546 -0.572,1.546Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/><path d=\'M9.598,6.495l3.263,0l0,-1.067l-0.882,0l0,-3.835l-0.974,0c-0.371,0.232 -0.727,0.371 -1.283,0.479l0,0.82l0.927,0l0,2.536l-1.051,0l0,1.067Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/><path d=\'M2.825,12.588c1.082,0 1.824,-0.89 1.824,-2.567c0,-1.67 -0.742,-2.521 -1.824,-2.521c-1.083,0 -1.825,0.843 -1.825,2.521c0,1.677 0.742,2.567 1.825,2.567Zm0,-1.021c-0.31,0 -0.572,-0.247 -0.572,-1.546c0,-1.299 0.262,-1.5 0.572,-1.5c0.309,0 0.572,0.201 0.572,1.5c0,1.299 -0.263,1.546 -0.572,1.546Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/><path d=\'M5.423,12.495l3.263,0l0,-1.067l-0.882,0l0,-3.835l-0.974,0c-0.371,0.232 -0.727,0.371 -1.284,0.479l0,0.82l0.928,0l0,2.536l-1.051,0l0,1.067Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/><path d=\'M11.175,12.588c1.083,0 1.825,-0.89 1.825,-2.567c0,-1.67 -0.742,-2.521 -1.825,-2.521c-1.082,0 -1.824,0.843 -1.824,2.521c0,1.677 0.742,2.567 1.824,2.567Zm0,-1.021c-0.309,0 -0.572,-0.247 -0.572,-1.546c0,-1.299 0.263,-1.5 0.572,-1.5c0.31,0 0.572,0.201 0.572,1.5c0,1.299 -0.262,1.546 -0.572,1.546Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/></g></svg>',
  639. 'file_icon_code': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M14,0l-14,0l0,14l14,0l0,-14Z\' style=\'fill:%2372d;fill-rule:nonzero;\'/><g><path d=\'M5.923,12.965c-1.049,0 -1.784,-0.161 -2.209,-0.48c-0.425,-0.317 -0.638,-0.82 -0.638,-1.503l0,-2.067c0,-0.446 -0.146,-0.764 -0.438,-0.95c-0.292,-0.188 -0.709,-0.281 -1.256,-0.281l0,-1.368c0.547,0 0.967,-0.094 1.259,-0.28c0.292,-0.186 0.438,-0.5 0.438,-0.938l0,-2.092c0,-0.675 0.217,-1.172 0.65,-1.491c0.432,-0.32 1.164,-0.479 2.195,-0.479l0,1.312c-0.401,0.01 -0.718,0.09 -0.952,0.24c-0.233,0.15 -0.348,0.426 -0.348,0.827l0,1.985c0,0.876 -0.511,1.396 -1.532,1.559l0,0.083c1.021,0.154 1.532,0.67 1.532,1.544l0,1.997c0,0.41 0.116,0.688 0.349,0.835c0.233,0.146 0.55,0.223 0.951,0.232l-0.001,1.315Z\' style=\'fill:%23fff;fill-rule:nonzero;\'/><path d=\'M8.076,12.965l0,-1.313c0.392,-0.009 0.706,-0.089 0.944,-0.239c0.236,-0.15 0.355,-0.426 0.355,-0.829l0,-1.996c0,-0.867 0.511,-1.382 1.531,-1.545l0,-0.084c-1.02,-0.164 -1.53,-0.679 -1.53,-1.546l0,-1.997c0,-0.41 -0.116,-0.688 -0.349,-0.834c-0.232,-0.146 -0.549,-0.224 -0.951,-0.233l0,-1.313c1.049,0 1.785,0.159 2.21,0.479c0.423,0.319 0.637,0.821 0.637,1.505l0,2.065c0,0.447 0.146,0.765 0.438,0.951c0.292,0.187 0.711,0.28 1.257,0.28l0,1.367c-0.546,0.012 -0.967,0.107 -1.259,0.287c-0.293,0.183 -0.438,0.5 -0.438,0.945l0,2.08c0,0.674 -0.217,1.172 -0.65,1.491c-0.432,0.319 -1.165,0.479 -2.195,0.479Z\' style=\'fill:%23fff;fill-rule:nonzero;\'/></g></svg>',
  640. 'file_icon_database': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M14,2.5l0,9c0,1.38 -3.137,2.5 -7,2.5c-3.863,0 -7,-1.12 -7,-2.5l0,-9\' style=\'fill:%23808080;\'/><path d=\'M13,2.5l0,9c0,0.828 -2.689,1.5 -6,1.5c-3.311,0 -6,-0.672 -6,-1.5l0,-9\' style=\'fill:%23b4b4b4;\'/><path d=\'M14,8.5c0,1.38 -3.137,2.5 -7,2.5c-3.863,0 -7,-1.12 -7,-2.5\' style=\'fill:%23808080;\'/><path d=\'M13,8.5c0,0.828 -2.689,1.5 -6,1.5c-3.311,0 -6,-0.672 -6,-1.5\' style=\'fill:%23b4b4b4;\'/><path d=\'M14,5.5c0,1.38 -3.137,2.5 -7,2.5c-3.863,0 -7,-1.12 -7,-2.5\' style=\'fill:%23808080;\'/><path d=\'M13,5.5c0,0.828 -2.689,1.5 -6,1.5c-3.311,0 -6,-0.672 -6,-1.5\' style=\'fill:%23b4b4b4;\'/><ellipse cx=\'7\' cy=\'2.5\' rx=\'7\' ry=\'2.5\' style=\'fill:%23808080;\'/><ellipse cx=\'7\' cy=\'2.5\' rx=\'5.5\' ry=\'1.5\' style=\'fill:%23b4b4b4;\'/></svg>',
  641. 'file_icon_dir': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M6,2.5l-1,-1.5l-5,0l0,12l14,0l0,-10.5l-8,0Z\' style=\'fill:%2339f;fill-rule:nonzero;\'/><rect x=\'1.5\' y=\'4\' width=\'11\' height=\'7.5\' style=\'fill:%239cf;\'/></svg>',
  642. 'file_icon_dir_invisible': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M6,2.5l-1,-1.5l-5,0l0,12l14,0l0,-10.5l-8,0Z\' style=\'fill:%23888;fill-rule:nonzero;\'/><rect x=\'1.5\' y=\'4\' width=\'11\' height=\'7.5\' style=\'fill:%23bbb;\'/><circle cx=\'7\' cy=\'7.5\' r=\'1.5\' style=\'fill:%23888;\'/></svg>',
  643. 'file_icon_ebook': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M2.668,-0.001c1.705,0.001 3.492,0.35 4.332,1.257c0.84,-0.908 2.627,-1.256 4.332,-1.257l2.668,0c0,4.112 0,8.43 0,12.541c-0.818,0 -2.181,0.005 -3,0.023c-1.184,0.026 -3.008,0.42 -3,1.437l-1,-0.017l-1,0.017c0.008,-1.017 -2,-1.437 -3,-1.437c-0.819,0 -2.182,-0.023 -3,-0.023l0,-12.541l2.668,0Z\' style=\'fill:%23808080;\'/><path d=\'M1.5,1.499l0,9.501l1.286,0c1.086,0.025 2.213,0.081 3.204,0.568l0.01,0.006c0,-2.859 0,-5.717 0,-8.576c0,-1.136 -1.49,-1.398 -2.336,-1.47c-0.708,-0.059 -1.438,-0.029 -2.164,-0.029Z\' style=\'fill:%23cdcdcd;\'/><path d=\'M12.5,1.499l0,9.501l-1.286,0c-1.086,0.025 -2.213,0.081 -3.204,0.568l-0.01,0.006c0,-2.859 0,-5.717 0,-8.576c0,-1.136 1.49,-1.398 2.336,-1.47c0.708,-0.059 1.438,-0.029 2.164,-0.029Z\' style=\'fill:%23cdcdcd;\'/></svg>',
  644. 'file_icon_file': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><g><path d=\'M8.3,0l-6.8,0l0,14l11,0l0,-9.8l-4.2,-4.2Z\' style=\'fill:%23888;fill-rule:nonzero;\'/><path d=\'M11,12.5l-8,0l0,-11l3.8,0l0,4.2l4.2,0l0,6.8Z\' style=\'fill:%23fff;fill-rule:nonzero;\'/><path d=\'M8.3,4.2l1.9,0l-1.9,-2l0,2Z\' style=\'fill:%23fff;fill-rule:nonzero;\'/></g></svg>',
  645. 'file_icon_invisible': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><g><path d=\'M8.3,0l-6.8,0l0,14l11,0l0,-9.8l-4.2,-4.2Z\' style=\'fill:%23888;fill-rule:nonzero;\'/><path d=\'M11,12.5l-8,0l0,-11l3.8,0l0,4.2l4.2,0l0,6.8Z\' style=\'fill:%23bbb;fill-rule:nonzero;\'/><path d=\'M8.3,4.2l1.9,0l-1.9,-2l0,2Z\' style=\'fill:%23bbb;fill-rule:nonzero;\'/></g><circle cx=\'7\' cy=\'9\' r=\'1.5\' style=\'fill:%23878787;\'/></svg>',
  646. 'file_icon_font': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M14,0l-14,0l0,14l14,0l0,-14Z\' style=\'fill:%23709;fill-rule:nonzero;\'/><path d=\'M4.678,11.179l1.393,0l0,-8.266l-2.616,0l0,1.052l-1.455,0l0,-2.553l10,0l0,2.554l-1.456,0l0,-1.053l-2.599,0l0,8.266l1.347,0l0,1.409l-4.614,0l0,-1.409Z\' style=\'fill:%23fff;fill-rule:nonzero;\'/></svg>',
  647. 'file_icon_graphics': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><rect x=\'0\' y=\'0\' width=\'14\' height=\'14\' style=\'fill:%23808080;fill-rule:nonzero;\'/><path d=\'M7.774,8.285l4.726,4.715l-8,-3.525l-1.5,-4.975l-2,0l0,-3.5l3.525,0l-0.025,2l5,1.5l3.5,8l-4.7,-4.752c0.127,-0.22 0.2,-0.476 0.2,-0.748c0,-0.828 -0.672,-1.5 -1.5,-1.5c-0.828,0 -1.5,0.672 -1.5,1.5c0,0.828 0.672,1.5 1.5,1.5c0.283,0 0.548,-0.079 0.774,-0.215Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/></svg>',
  648. 'file_icon_htm': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M6.967,0.5c-3.553,0.018 -6.467,2.947 -6.467,6.5c0,3.566 2.934,6.5 6.5,6.5c3.566,0 6.5,-2.934 6.5,-6.5c0,-3.553 -2.914,-6.482 -6.467,-6.5l-0.066,0Zm0.033,0l0,13m6.5,-6.5l-13,0m1.467,-4c3.004,2.143 7.062,2.143 10.066,0m0,8c-3.004,-2.143 -7.062,-2.143 -10.066,0m4.533,-10.333c-1.874,1.582 -2.957,3.914 -2.957,6.366c0,2.453 1.083,4.785 2.957,6.367m1,0c1.874,-1.582 2.957,-3.914 2.957,-6.367c0,-2.452 -1.083,-4.784 -2.957,-6.366\' style=\'fill:%23fff;fill-rule:nonzero;stroke:%23E44D26;stroke-width:1px;\'/></svg>',
  649. 'file_icon_ignored': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M7,0c-3.9,0 -7,3.1 -7,7c0,3.9 3.1,7 7,7c3.9,0 7,-3.1 7,-7c0,-3.9 -3.1,-7 -7,-7Z\' style=\'fill:%23999;fill-rule:nonzero;\'/><path d=\'M7,2c2.8,0 5,2.2 5,5c0,2.8 -2.2,5 -5,5c-2.8,0 -5,-2.2 -5,-5c0,-2.8 2.2,-5 5,-5\' style=\'fill:%23ddd;fill-rule:nonzero;\'/><path d=\'M10.695,1.774l-8.839,8.839l1.626,1.626l8.839,-8.839l-1.626,-1.626Z\' style=\'fill:%23999;\'/></svg>',
  650. 'file_icon_image': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M0.369,9.141c-0.252,-0.678 -0.369,-1.396 -0.369,-2.141c0,-3.863 3.137,-7 7,-7c3.863,0 7,3.137 7,7l-0.137,1.353l-3.853,-3.853l-3.5,3.5l-2.5,-2.5l-3.641,3.641Z\' style=\'fill:%238080ff;\'/><path d=\'M0.839,10.151l-0.47,-1.01l3.641,-3.641l2.5,2.5l3.5,-3.5l3.853,3.853c-0.076,0.395 -0.201,0.778 -0.341,1.147l-10.371,3.345c-0.293,-0.194 -0.579,-0.416 -0.838,-0.651l-1.474,-2.043Z\' style=\'fill:%23fff;\'/><g><path d=\'M13.522,9.5c-0.99,2.64 -3.539,4.5 -6.522,4.5c-1.426,0 -2.753,-0.421 -3.849,-1.155l6.859,-6.866l3.512,3.521Z\' style=\'fill:%2333c;\'/><path d=\'M0.839,10.151l3.171,-3.172l1.761,1.761l-3.459,3.454c-0.591,-0.632 -1.079,-1.313 -1.473,-2.043Z\' style=\'fill:%2333c;\'/></g><circle cx=\'6\' cy=\'3.5\' r=\'1.5\' style=\'fill:%23fff;\'/></svg>',
  651. 'file_icon_ignored_image': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M0.369,9.141c-0.252,-0.678 -0.369,-1.396 -0.369,-2.141c0,-3.863 3.137,-7 7,-7c3.863,0 7,3.137 7,7l-0.137,1.353l-3.853,-3.853l-3.5,3.5l-2.5,-2.5l-3.641,3.641Z\' style=\'fill:%23808080;\'/><path d=\'M0.839,10.151l-0.47,-1.01l3.641,-3.641l2.5,2.5l3.5,-3.5l3.853,3.853c-0.076,0.395 -0.201,0.778 -0.341,1.147l-10.371,3.345c-0.293,-0.194 -0.579,-0.416 -0.838,-0.651l-1.474,-2.043Z\' style=\'fill:%23fff;\'/><g><path d=\'M13.522,9.5c-0.99,2.64 -3.539,4.5 -6.522,4.5c-1.426,0 -2.753,-0.421 -3.849,-1.155l6.859,-6.866l3.512,3.521Z\' style=\'fill:%23808080;\'/><path d=\'M0.839,10.151l3.171,-3.172l1.761,1.761l-3.459,3.454c-0.591,-0.632 -1.079,-1.313 -1.473,-2.043Z\' style=\'fill:%23808080;\'/></g><circle cx=\'6\' cy=\'3.5\' r=\'1.5\' style=\'fill:%23fff;\'/></svg>',
  652. 'file_icon_markdown': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M14,0l-14,0l0,14l14,0l0,-14Z\' style=\'fill:%236a6a95;fill-rule:nonzero;\'/><path d=\'M12,11.5l-2.5,0l0,-5.143l-2.5,2.948l-2.5,-2.948l0,5.143l-2.5,0l0,-9l2.273,0l2.721,3.377l2.733,-3.377l2.273,0l0,9Z\' style=\'fill:%23DDD;fill-rule:nonzero;\'/></svg>',
  653. 'file_icon_office': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><rect x=\'0\' y=\'0\' width=\'14\' height=\'14\' style=\'fill:%23808080;fill-rule:nonzero;\'/><rect x=\'10\' y=\'1.5\' width=\'2.5\' height=\'1\' style=\'fill:%23cdcdcd;\'/><rect x=\'10\' y=\'4\' width=\'2.5\' height=\'1\' style=\'fill:%23cdcdcd;\'/><rect x=\'10\' y=\'6.5\' width=\'2.5\' height=\'1\' style=\'fill:%23cdcdcd;\'/><rect x=\'10\' y=\'9\' width=\'2.5\' height=\'1\' style=\'fill:%23cdcdcd;\'/><rect x=\'10\' y=\'11.5\' width=\'2.5\' height=\'1\' style=\'fill:%23cdcdcd;\'/><rect x=\'6.5\' y=\'1.5\' width=\'2.5\' height=\'1\' style=\'fill:%23cdcdcd;\'/><rect x=\'6.5\' y=\'4\' width=\'2.5\' height=\'1\' style=\'fill:%23cdcdcd;\'/><rect x=\'6.5\' y=\'6.5\' width=\'2.5\' height=\'1\' style=\'fill:%23cdcdcd;\'/><rect x=\'6.5\' y=\'9\' width=\'2.5\' height=\'1\' style=\'fill:%23cdcdcd;\'/><rect x=\'6.5\' y=\'11.5\' width=\'2.5\' height=\'1\' style=\'fill:%23cdcdcd;\'/><rect x=\'1.5\' y=\'1.5\' width=\'4\' height=\'11\' style=\'fill:%23cdcdcd;\'/></svg>',
  654. 'file_icon_pdf': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><rect x=\'0\' y=\'0\' width=\'14\' height=\'14\' style=\'fill:%23d20000;fill-rule:nonzero;\'/><path d=\'M12.69,9.115c-0.075,0.048 -0.291,0.076 -0.428,0.076c-0.443,0 -0.99,-0.204 -1.762,-0.534c0.297,-0.022 0.568,-0.031 0.811,-0.031c0.446,0 0.575,0 1.012,0.109c0.433,0.108 0.438,0.333 0.367,0.38Zm-7.72,0.069c0.172,-0.303 0.349,-0.622 0.526,-0.961c0.44,-0.83 0.719,-1.484 0.923,-2.017c0.413,0.749 0.926,1.383 1.525,1.894c0.077,0.063 0.157,0.125 0.242,0.189c-1.224,0.246 -2.283,0.539 -3.216,0.895Zm1.428,-7.856c0.244,0 0.384,0.612 0.395,1.191c0.011,0.573 -0.121,0.974 -0.29,1.277c-0.141,-0.445 -0.205,-1.14 -0.205,-1.596c0,-0.001 -0.01,-0.872 0.1,-0.872Zm-4.788,11.025c0.142,-0.378 0.687,-1.124 1.494,-1.788c0.051,-0.038 0.177,-0.157 0.292,-0.266c-0.843,1.35 -1.412,1.885 -1.786,2.054Zm11.312,-4.029c-0.242,-0.241 -0.789,-0.367 -1.615,-0.377c-0.56,-0.008 -1.23,0.041 -1.942,0.139c-0.315,-0.184 -0.641,-0.381 -0.9,-0.622c-0.689,-0.646 -1.262,-1.539 -1.621,-2.521c0.021,-0.095 0.044,-0.173 0.062,-0.256c0,0 0.387,-2.208 0.283,-2.954c-0.015,-0.105 -0.021,-0.132 -0.051,-0.212l-0.033,-0.089c-0.104,-0.243 -0.313,-0.502 -0.639,-0.488l-0.19,-0.006l-0.003,0c-0.362,0 -0.661,0.186 -0.736,0.461c-0.236,0.872 0.007,2.171 0.448,3.856l-0.114,0.275c-0.315,0.768 -0.711,1.542 -1.058,2.225l-0.048,0.09c-0.365,0.717 -0.7,1.328 -1,1.843l-0.313,0.167c-0.021,0.014 -0.556,0.294 -0.681,0.37c-1.064,0.634 -1.77,1.356 -1.887,1.929c-0.037,0.181 -0.009,0.414 0.18,0.525l0.302,0.15c0.13,0.064 0.272,0.097 0.41,0.097c0.757,0 1.637,-0.941 2.845,-3.053c1.4,-0.457 2.994,-0.836 4.39,-1.045c1.062,0.6 2.369,1.015 3.194,1.015c0.147,0 0.274,-0.013 0.377,-0.042c0.156,-0.04 0.29,-0.13 0.372,-0.256c0.158,-0.238 0.193,-0.569 0.148,-0.91c-0.01,-0.1 -0.093,-0.226 -0.18,-0.311Z\' style=\'fill:%23fff;fill-rule:nonzero;\'/></svg>',
  655. 'file_icon_system': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><rect x=\'0\' y=\'0\' width=\'14\' height=\'14\' style=\'fill:%23808080;fill-rule:nonzero;\'/><g><path d=\'M1.247,6.495l3.263,0l0,-1.067l-0.881,0l0,-3.835l-0.974,0c-0.371,0.232 -0.727,0.371 -1.284,0.479l0,0.82l0.928,0l0,2.536l-1.052,0l0,1.067Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/><path d=\'M7,6.588c1.082,0 1.825,-0.89 1.825,-2.567c0,-1.67 -0.743,-2.521 -1.825,-2.521c-1.082,0 -1.825,0.843 -1.825,2.521c0,1.677 0.743,2.567 1.825,2.567Zm0,-1.021c-0.309,0 -0.572,-0.247 -0.572,-1.546c0,-1.299 0.263,-1.5 0.572,-1.5c0.309,0 0.572,0.201 0.572,1.5c0,1.299 -0.263,1.546 -0.572,1.546Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/><path d=\'M9.598,6.495l3.263,0l0,-1.067l-0.882,0l0,-3.835l-0.974,0c-0.371,0.232 -0.727,0.371 -1.283,0.479l0,0.82l0.927,0l0,2.536l-1.051,0l0,1.067Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/><path d=\'M2.825,12.588c1.082,0 1.824,-0.89 1.824,-2.567c0,-1.67 -0.742,-2.521 -1.824,-2.521c-1.083,0 -1.825,0.843 -1.825,2.521c0,1.677 0.742,2.567 1.825,2.567Zm0,-1.021c-0.31,0 -0.572,-0.247 -0.572,-1.546c0,-1.299 0.262,-1.5 0.572,-1.5c0.309,0 0.572,0.201 0.572,1.5c0,1.299 -0.263,1.546 -0.572,1.546Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/><path d=\'M5.423,12.495l3.263,0l0,-1.067l-0.882,0l0,-3.835l-0.974,0c-0.371,0.232 -0.727,0.371 -1.284,0.479l0,0.82l0.928,0l0,2.536l-1.051,0l0,1.067Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/><path d=\'M11.175,12.588c1.083,0 1.825,-0.89 1.825,-2.567c0,-1.67 -0.742,-2.521 -1.825,-2.521c-1.082,0 -1.824,0.843 -1.824,2.521c0,1.677 0.742,2.567 1.824,2.567Zm0,-1.021c-0.309,0 -0.572,-0.247 -0.572,-1.546c0,-1.299 0.263,-1.5 0.572,-1.5c0.31,0 0.572,0.201 0.572,1.5c0,1.299 -0.262,1.546 -0.572,1.546Z\' style=\'fill:%23CCC;fill-rule:nonzero;\'/></g></svg>',
  656. 'file_icon_text': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><path d=\'M14,0l-14,0l0,14l14,0l0,-14Z\' style=\'fill:%236A6A95;fill-rule:nonzero;\'/><rect x=\'6.5\' y=\'1.5\' width=\'6\' height=\'1\' style=\'fill:%23fff;\'/><rect x=\'1.5\' y=\'1.5\' width=\'3.5\' height=\'3.5\' style=\'fill:%23fff;\'/><rect x=\'1.5\' y=\'6.5\' width=\'11\' height=\'1\' style=\'fill:%23fff;\'/><rect x=\'6.5\' y=\'4\' width=\'6\' height=\'1\' style=\'fill:%23fff;\'/><rect x=\'1.5\' y=\'11.5\' width=\'8\' height=\'1\' style=\'fill:%23fff;\'/><rect x=\'1.5\' y=\'9\' width=\'11\' height=\'1\' style=\'fill:%23fff;\'/></svg>',
  657. 'file_icon_video': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 14 14\'><g id=\'Layer1\'><path d=\'M14,14l0,-14l-14,0l0,14l14,0Z\'/><path d=\'M9.5,3l0,-2l-2,0l0,2l2,0Z\' style=\'fill:%23fff;\'/><path d=\'M3.5,3l0,-2l-2,0l0,2l2,0Z\' style=\'fill:%23fff;\'/><path d=\'M6.5,3l0,-2l-2,0l0,2l2,0Z\' style=\'fill:%23fff;\'/><path d=\'M12.5,3l0,-2l-2,0l0,2l2,0Z\' style=\'fill:%23fff;\'/><path d=\'M9.5,13l0,-2l-2,0l0,2l2,0Z\' style=\'fill:%23fff;\'/><path d=\'M3.5,13l0,-2l-2,0l0,2l2,0Z\' style=\'fill:%23fff;\'/><path d=\'M6.5,13l0,-2l-2,0l0,2l2,0Z\' style=\'fill:%23fff;\'/><path d=\'M12.5,13l0,-2l-2,0l0,2l2,0Z\' style=\'fill:%23fff;\'/><path d=\'M12.5,10l0,-6l-11,0l0,6l11,0Z\' style=\'fill:%23eda412;\'/></g></svg>',
  658. };
  659. // Programatically add File icon CSS rules
  660. function CSS_UI_Icon_Rules(el) {
  661. let class_name;
  662. let selector;
  663. let kinds = ['dir','dir_invisible','file','alias','code','font','audio','video','htm','image','pdf','text','markdown','app','invisible','ignore','archive','bin','database','ebook','graphics','ignored_image','office','system'];
  664. let rules = '';
  665. if ( el === 'body' ) {
  666. rules += '#bookmarks ul a { background-image:'+ SVG_UI_File_Icon('file_icon_file') +'; }';
  667. rules += '#bookmarks ul a[href^="file"] { background-image:'+ SVG_UI_File_Icon('file_icon_dir') +'; }';
  668. rules += '#bookmarks ul a[href^="http"] { background-image:'+ SVG_UI_File_Icon('file_icon_htm') +'; }';
  669. rules += 'body:not(.use_custom_icons) #dir_list tr.dir a.icon span { background-image:'+ SVG_UI_File_Icon('file_icon_dir_default') + '; background-size:auto 13px; }';
  670. rules += 'body:not(.use_custom_icons) #dir_list tr.file:not(.app) a.icon span { background-image:'+ SVG_UI_File_Icon('file_icon_file_default') + '; background-size:auto 13px; }';
  671. } else {
  672. rules += '#iframe_body:not(.use_custom_icons) #dir_list tr.dir td.name a::before { background:'+ SVG_UI_File_Icon('file_icon_dir_default') +'; }';
  673. rules += '#iframe_body:not(.use_custom_icons) #dir_list tr.file td.name a::before { background:'+ SVG_UI_File_Icon('file_icon_file_default') +'; }';
  674. }
  675. for ( let kind of kinds ) {
  676. class_name = kind;
  677. switch(kind) {
  678. case 'dir': class_name = 'dir:not(.app)'; break;
  679. case 'dir_invisible': class_name = 'dir.invisible'; break;
  680. }
  681. if ( el === 'body' ) {
  682. selector = el +'.use_custom_icons #dir_list tr.'+ class_name +':not(.media) a.icon span ';
  683. // selectors for iframe content kinds, icons in content titlebar
  684. if ( kind !== undefined && !['audio','dir','font','ignored','image','pdf','video'].includes(kind) ) {
  685. selector += ', #content_pane.has_iframe #title span.has_'+ kind +'::before, #content_pane.has_ignored #title span.has_'+ kind +'::before';
  686. }
  687. } else {
  688. selector = el +'.use_custom_icons #dir_list tr.'+ class_name +' td.name a::before ';
  689. }
  690. let background_image = '{ background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons['file_icon_'+kind] +'"); }' ;
  691. let rule = selector + background_image;
  692. rules += rule;
  693. }
  694. return rules;
  695. }
  696. //***** STYLES *****//
  697.  
  698. // DEFINE STYLES
  699. var $main_style_rules =
  700. '#content_pane.has_image #content_image { align-items: center; justify-content: center; }' +
  701. '.image_grid_item a { align-self: center; justify-self: center; }' +
  702. '#sidebar_wrapper, body.theme_light #sidebar, body.theme_light #sidebar ul, body.theme_light #preview_text, body.theme_light #source_text, body.theme_light #content_header' +
  703. '{ background-color: lightgray; }' +
  704. // light non-media ("light cyan")
  705. 'body.theme_light #dir_list tr.selected:not(.playing), body.theme_light #dir_list tr.selected.loaded:not(.playing), body.theme_light #dir_list tr.selected.loaded:hover'+
  706. '{ background-color: rgba(172,202,235,1.00) !important; }' +
  707. 'body.theme_light #dir_list tr.loaded:not(.selected), body.theme_light #dir_list tbody tr:not(.media):hover, body.theme_light.alternate_background #dir_list #tbody tr:not(.media):hover, body.theme_light #dir_list .hovered:not(.media), body.theme_light.alternate_background #dir_list #tbody tr.hovered:not(.media)'+
  708. '{ background-color: rgba(172,202,235,0.60); }' +
  709. // light media ("light aqua")
  710. 'body.theme_light #dir_list tr.media.playing { background-color: rgba(130,196,196,1); }' + // #82C4C4
  711. 'body.theme_light #dir_list tr.media.selected:not(.playing)'+
  712. '{ background-color: rgba(116,190,190,0.60) !important; }' +
  713. 'body.theme_light #dir_list tr.media.selected:not(.playing):hover, body.theme_light #dir_list tr.media:not(.selected):hover'+
  714. '{ background-color: rgba(116,190,190,0.40) !important; }' +
  715. // dark non-media ("dark cyan")
  716. 'body.theme_dark #dir_list tr.selected:not(.playing), body.theme_dark #dir_list tr.selected.loaded:not(.playing), body.theme_dark #dir_list tr.selected.loaded:hover'+
  717. '{ background-color: rgba(101,140,179,1.00) !important; }' + //#658CB3
  718. 'body.theme_dark #dir_list tr.loaded:not(.selected), body.theme_dark #dir_list tbody tr:not(.media):hover, body.theme_dark.alternate_background #dir_list #tbody tr:not(.media):hover, body.theme_dark #dir_list .hovered:not(.media), body.theme_dark.alternate_background #dir_list #tbody tr.hovered:not(.media)'+
  719. '{ background-color: rgba(101,140,179,0.66) !important; }' +
  720. // dark media ("dark aqua")
  721. 'body.theme_dark #dir_list tr.media.playing { background-color: rgba(076,143,143,1.00) !important; }' +
  722. 'body.theme_dark #dir_list tr.media.selected:not(.playing)'+
  723. '{ background-color: rgba(076,143,143,0.70) !important; }' +
  724. 'body.theme_dark #dir_list tr.media.selected:not(.playing):hover, body.theme_dark #dir_list tr.media:not(.selected):hover'+
  725. '{ background-color: rgba(076,143,143,0.45) !important; }' +
  726. // text editor row ("purple")
  727. 'body.theme_light.has_text #text_editor_row, body.theme_light.edited #text_editor_row' +
  728. '{ background-color: rgba(160,160,230,1.00); }' + // #A0A0E6
  729. 'body.theme_dark.has_text #text_editor_row, body.theme_dark.edited #text_editor_row' +
  730. '{ background-color: rgba(100,100,160,1.00); }' + // #6464A0
  731. // other UI elements
  732. 'body.theme_dark #content_pane.has_grid #content_container, body.theme_dark #content_grid > div:hover, body.theme_dark #content_grid > div.hovered, body.theme_dark #content_grid > div.selected, body.theme_dark .glyph_container:hover, body.theme_dark .glyph_container.selected' +
  733. '{ background-color: #262626; }' +
  734. 'body.theme_dark #content_pane, body.theme_dark #content_pane.has_image, body.theme_dark #content_pane.has_grid #content_grid::after, body.theme_dark #content_grid > div, body.theme_dark #content_font, .split_btn::after' +
  735. '{ background-color: #333; }' +
  736. 'body.theme_dark #sidebar ul, body.theme_dark #preview_text_menu_item span, body.theme_dark #sidebar_header thead, body.theme_dark #sidebar_menus, body.theme_dark #preview_text, body.theme_dark #source_text, body.theme_dark.alternate_background #dir_list tbody tr:nth-of-type(odd):not(.selected):not(.playing):not(.loaded), body.theme_dark.alternate_background #dir_list tbody tr:nth-of-type(odd):not(.loaded), body.theme_dark #tfoot, body.theme_dark .playlist_item:nth-of-type(odd), body.theme_dark #font_info, body.theme_dark #glyph_viewer_info' +
  737. '{ background-color: #444; }' +
  738. 'body.theme_dark #sidebar, body.theme_dark #dir_list #tbody, body.theme_dark #content_header, body.theme_dark .font_grid_item:hover, body.theme_dark .font_grid_item.hovered, body.theme_dark .image_grid_item:hover, body.theme_dark .image_grid_item.hovered' +
  739. '{ background-color: #555; }' +
  740. 'body.theme_dark #sidebar ul li:not(#preview_text_menu_item):hover, body.theme_dark li.has_submenu:hover, body.theme_dark #preview_text_menu_item span:hover, body.theme_dark #preview_text:hover, body.theme_dark #source_text:hover' +
  741. '{ background-color: #666; }' +
  742. 'body.theme_dark #sidebar .hovered, body.theme_dark #dir_list tbody tr:hover, body.theme_dark.alternate_background #dir_list #tbody tr:hover, body.theme_dark.alternate_background #dir_list #tbody tr:nth-of-type(odd).hovered, body.theme_dark #content_iframe[href^="/"]' +
  743. '{ background-color: #777; }' +
  744. 'body.theme_dark #grid_btn .menu li:hover { background-color: #888 !important; }' +
  745. 'body.theme_dark #grid_btn .menu, body.theme_dark #grid_btn .menu li' +
  746. '{ background-color: #AAA; }' +
  747. 'body.theme_light #sidebar_header thead tr, body.theme_light #sidebar_menus, #parents_dir_menu + ul li:hover, #bookmarks li:hover, body.theme_light #preview_text_menu_item span:hover, body.theme_light #preview_text:hover, body.theme_light #source_text:hover, body.theme_light #grid_btn .menu li:hover' +
  748. '{ background-color: #BBB; }' +
  749. 'body.theme_light #grid_btn .menu li, body.theme_light.alternate_background #dir_list tbody tr:nth-of-type(odd):not(.selected):not(.playing):not(.loaded), body.theme_light #tfoot, body.theme_light .playlist_item:nth-of-type(odd), body.theme_dark #glyph_viewer' +
  750. '{ background-color: #CCC; }' +
  751. 'body.theme_light #dir_list tbody { background-color: #DFDFDF !important; }' +
  752. 'body.theme_light #content_grid > div, #warnings, body.theme_light #content_pane.has_grid #content_grid::after, body.theme_light #content_font.has_font_viewer, body.theme_light #font_info, body.theme_light #glyph_viewer_info' +
  753. '{ background-color: #EEE; }' +
  754. 'body.theme_light #content_pane, body.theme_light #content_grid, body.theme_light #content_grid div.selected, body.theme_light #content_pane.has_image, #content_font:not(.has_font_viewer), #content_iframe, #scale, body.theme_light #content_grid div:hover, body.theme_light #content_grid div.hovered, body.theme_light #glyph_viewer, body.is_safari button, body.theme_light .glyph_container:hover, body.theme_light .glyph_container.selected' +
  755. '{ background-color: #FFF; }' +
  756. 'body.is_chrome #audio_container { background-color: rgb(241, 243, 244); }' +
  757. '#warnings button:focus,#warnings button.focus { background-color: #0E4399; }' +
  758. '#bookmarks_menu div { background-image:'+ SVG_UI_Icon('menu') + '; }' +
  759. 'body.theme_light .bookmarks > a::before { background-image:'+ SVG_UI_Icon('bookmark') +'; }' +
  760. 'body.theme_dark .bookmarks > a::before { background-image:'+ SVG_UI_Icon('bookmark_dark') +'; }' +
  761. 'body.theme_light li.has_submenu { background-image:'+ SVG_UI_Icon('arrow') +'; }' +
  762. 'body.theme_dark li.has_submenu { background-image:'+ SVG_UI_Icon('arrow_dark') +'; }' +
  763. '#theme::before, body.sort_by_default #default span::before, body.sort_by_name #name span::before, body.sort_by_size #size span::before, body.sort_by_date #date span::before, body.sort_by_kind #kind span::before, body.sort_by_ext #ext span::before, body.alternate_background #alternate_background span::before, body.show_numbers #show_numbers span::before, body.autoload_media #autoload_media span::before, body.split_view #split_view_menu_item, body.split_view #split_view span::before, body:not(.enable_text_editing) #enable_text_editing::before, body.source_text:not(.preview_text) #source_text::before, body.preview_text:not(.source_text) #preview_text::before, body.sort_by_default #sort_by_default span::before, body.sort_by_name #sort_by_name span::before, body.sort_by_size #sort_by_size span::before, body.sort_by_date #sort_by_date span::before, body.sort_by_kind #sort_by_kind span::before, body.sort_by_ext #sort_by_ext span::before'+
  764. '{ background-image:'+ SVG_UI_Icon('check_mark') +'; }' +
  765. '#parent_dir_menu a, body.sort_by_default #sort_by_default span::after, body.sort_by_name #sort_by_name span::after, body.sort_by_size #sort_by_size span::after, body.sort_by_date #sort_by_date span::after, body.sort_by_kind #sort_by_kind span::after, body.sort_by_ext #sort_by_ext span::after'+
  766. '{ background-image:'+ SVG_UI_Icon('chevron_up') +'; }' +
  767. '#prev_btn { background-image:'+ SVG_UI_Icon('chevron_left') + '; }' +
  768. '#next_btn { background-image:'+ SVG_UI_Icon('chevron_right') + '; }' +
  769. 'body.is_error #content_container, #warnings h3::before { background-image:'+ SVG_UI_Icon('error') +'; }' +
  770. 'body.has_fonts #grid_btn, body.has_images #grid_btn, #grid_btn .menu'+
  771. '{ background-image:'+ SVG_UI_Icon('grid') +'; }' +
  772. 'body.theme_light #content_pane.has_ignored:not(.has_grid) #content_container'+
  773. '{ background-image:'+ SVG_UI_Icon('ignored') +'; }' +
  774. 'body.theme_dark #content_pane.has_ignored:not(.has_grid) #content_container'+
  775. '{ background-image:'+ SVG_UI_Icon('ignored_dark') +'; }' +
  776. 'body.theme_dark #content_container.has_ignored:not(.has_grid){ background-image:'+SVG_UI_Icon('ignored_dark') +'; }' +
  777. '#decrease { background-image:'+ SVG_UI_Icon('minus') +'; }' +
  778. '#close_audio { background-image:'+ SVG_UI_Icon('multiply') +'; }' +
  779. 'body.has_audio #content_pane:not(.has_image):not(.has_video):not(.has_ignored):not(.has_grid):not(.has_zoom_image) #content_container'+
  780. '{ background-image:'+ SVG_UI_Icon('music') +'; }' +
  781. '#increase { background-image:'+ SVG_UI_Icon('plus') +'; }' +
  782. '#prev_track, #next_track { background-image:'+ SVG_UI_Icon('prev_next_track') +'; }' +
  783. '#toggle_sidebar, #toggle_info { background-image:'+ SVG_UI_Icon('toggle') +'; }' +
  784.  
  785. CSS_UI_Icon_Rules('body') + // FILE & DIR ICONS, plus additions:
  786. '#content_pane #title span::before { width:14px; height:14px; display:inline-block; margin:0 5px -3px 2px; }' +
  787. '#content_pane.has_dir #title span::before, #content_pane.has_grid #title span::before, #content_pane.has_font_grid #title span::before, #content_pane.has_image_grid #title span::before'+
  788. '{ background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons.file_icon_dir +'"); }' +
  789. '#content_pane.has_font #title span::before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons.file_icon_font +'"); }' +
  790. '#content_pane.has_image #title span::before, #content_pane.has_zoom_image #title span::before'+
  791. '{ background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons.file_icon_image +'"); }' +
  792. '#content_pane.has_ignored #title span::before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons.file_icon_ignored +'"); }' +
  793. '#content_pane.has_iframe #title span.has_other::before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons.file_icon_file +'"); }' +
  794. '#content_audio_title td:before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons.file_icon_audio +'"); height:14px !important; }' +
  795. '#content_pane.has_pdf #title span::before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons.file_icon_pdf +'"); }' +
  796. '#content_pane.has_video #title span::before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons.file_icon_video +'"); }' +
  797. 'body.theme_light #grid_btn.has_grid, body.theme_light #grid_btn.has_grid:hover ul'+
  798. '{ background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_Icons.grid_loaded +'") !important; opacity:1 !important; }' +
  799. 'body.theme_dark #grid_btn.has_grid, body.theme_dark #grid_btn.has_grid:hover ul'+
  800. '{ background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_Icons.grid_loaded_dark +'") !important; opacity:1 !important; }' +
  801.  
  802. '#parent_dir_menu a, #bookmarks_menu div, #bookmarks li a::before, #bookmarks li.toggle_UI_pref span::before, #theme::before, #enable_text_editing::before, #sort_menu span::before, #preview_text_menu_item span::before, #sorting div span::before, #sorting div span::after, #toggle_sidebar, #toggle_info, #close_audio, #prev_track, #next_track, #glyph_viewer, #content_container, #content_pane' +
  803. '{ background-position: center; }' +
  804. '#prev_next_btns span, #scale span { background-position: center 36%; }' +
  805. '.toggle_UI_pref, .bookmarks > a { background-position: 5px center; }' +
  806. '#dir_list tbody a { background-position: 6px 4px; }' +
  807. '#dir_list a.icon span { background-position: 6px 0; }' +
  808. '#bookmarks ul a { background-position: 8px center; }' +
  809. '#bookmarks > li { background-position: right 6px center; }' +
  810. '#grid_btn,#grid_btn .menu { background-position: right 5px top 6px; }' +
  811. '#content_audio_title td:before { background-position: right 4px center; }' +
  812. '#bookmarks li a::before, .toggle_UI_pref, #toggle_sidebar, #grid_btn, #grid_btn .menu, #toggle_info, #main_content a, a, div, li, span, span::before, span::after, #dir_list a.icon span, #content_pane, #content_container, #glyph_viewer, #warnings h3::before, #content_audio_title td:before'+
  813. '{ background-repeat: no-repeat; }' +
  814. '#glyph_viewer { background-size: contain; }' +
  815. '.toggle_UI_pref, th .sorting, #scale span { background-size: 10px; }' +
  816. '.bookmarks > a, li.has_submenu, #parent_dir_menu a { background-size: 12px; }' +
  817. '#dir_list tbody a, #dir_list a.icon span, #bookmarks ul a, #close_audio, #grid_btn, #grid_btn .menu'+
  818. '{ background-size: 14px; }' +
  819. '#toggle_sidebar, #toggle_info { background-size: 18px; }' +
  820. '#warnings h3::before { background-size: 24px; }' +
  821. '#prev_next_btns span { background-size: 33%; }' +
  822. '#content_pane, #content_container { background-size: 50%; }' +
  823. ':root, html, body, #sidebar_wrapper, #sidebar_header, #dir_list, #main_content, #content_pane, #content_pdf, #content_iframe' +
  824. '{ border: 0 !important; }' +
  825. 'body.theme_dark ul { border: solid 1px #222; }' +
  826. 'button { border: solid 1px #333; }' +
  827. 'body.theme_light #sidebar ul { border: solid 1px gray; }' +
  828. 'body.theme_dark #sidebar_header .menu, body.theme_dark #text_editor_row, body.theme_dark:not(.is_error) #dir_list #tbody, body.theme_dark #tfoot' +
  829. '{ border-top: solid 1px #111; }' +
  830. 'body.theme_light #dir_list tbody, #grid_btn .menu, body.theme_light #bookmarks, body.theme_light #text_editor_row, #tfoot, .font_grid_item:not(:first-of-type), .image_grid_item + .font_grid_item, #font_info th, #font_info td' +
  831. '{ border-top: solid 1px grey; }' +
  832. '#sort_by, tr.sorted, tr:not(.invisible) ~ tr.invisible + tr:not(.invisible)' + // , tr.dir ~ tr:not(.dir,.invisible,.ignore)
  833. '{ border-top: solid 1px #999; }' +
  834. 'body.theme_dark #grid_btn ul.menu { border-top: solid 1px #EEE; }' +
  835. '#parents_dir_menu + ul, #bookmarks_menu + ul, #grid_btn ul.menu'+
  836. '{ border-right: 0 !important; }' +
  837. 'body.theme_dark #parents_dir_menu, body.theme_dark #sidebar, body.theme_dark #warnings' +
  838. '{ border-right: solid 1px #111; }' +
  839. '#sidebar, body.theme_light #parents_dir_menu, body.theme_light #grid_btn .menu li, .image_grid_item, div.glyph_container, #font_info td:first-of-type' +
  840. '{ border-right: solid 1px grey; }' +
  841. 'body.theme_dark #grid_btn .menu li { border-right: solid 1px #EEE; }' +
  842. 'body.theme_dark #sidebar_title, body.theme_dark #sidebar_menus, body.theme_dark #sidebar_header .menu, body.theme_dark #content_header, body.theme_dark #content_pane.has_audio #content_title, body.theme_dark #warnings' +
  843. '{ border-bottom: solid 1px #111; }' +
  844. 'body.theme_light #sidebar_header thead tr, body.theme_light #bookmarks, body.theme_light #sidebar_menus, body.theme_light #grid_btn .menu li#show_image_grid, #grid_btn .menu, .specimen, .font_grid_item:last-of-type, .image_grid_item, div.glyph_container, #glyph_viewer_info' +
  845. '{ border-bottom: solid 1px grey; }' +
  846. 'body.theme_light #content_title, body.theme_light #content_pane.has_audio #content_header' +
  847. '{ border-bottom: solid 1px #888; }' +
  848. '#bookmarks_menu + ul > li.has_submenu.ruled, .rule { border-bottom: solid 1px #999; }' +
  849. 'body.theme_dark #content_pane.has_font #content_font hr, .hamburger h4'+
  850. '{ border-bottom: solid 1px #CCC; }' +
  851. 'body.theme_dark #grid_btn ul.menu, body.theme_dark #grid_btn .menu li#show_image_grid'+
  852. '{ border-bottom: solid 1px #EEE; }' +
  853. '#parents_dir_menu + ul, #bookmarks_menu + ul { border-left:0; }' +
  854. 'body.theme_dark #parents_dir_menu, body.theme_dark #grid_btn ul.menu, body.theme_dark #warnings' +
  855. '{ border-left: solid 1px #111; }' +
  856. 'body.theme_light #parents_dir_menu, #grid_btn .menu { border-left: solid 1px grey; }' +
  857. 'body.theme_dark #grid_btn ul.menu { border-left: solid 1px #EEE; }' +
  858. 'table { border-collapse: collapse; }' +
  859. 'html, body, :root { border-radius: 0; }' +
  860. 'button { border-radius: 3px; }' +
  861. '#warnings { border-radius: 0 0 3px 3px; }' +
  862. 'body.theme_light #sidebar ul { box-shadow: 0px 2px 3px -2px #888; }' +
  863. 'body.theme_dark #sidebar ul { box-shadow: 0px 2px 3px -2px #111; }' +
  864. '#warnings { box-shadow: 0px 2px 12px 0 #111; }' +
  865. 'body.theme_dark #grid_btn ul.menu { box-shadow: none; }' +
  866. 'html, body, :root, #sidebar, #grid_btn .menu li, #content_container, #content_source, #content_preview' +
  867. '{ box-sizing: border-box; }' +
  868. '#checkbox_div label, #grid_btn .menu li, #content_grid .font_grid_item'+
  869. '{ clear: both; }' +
  870. '#dir_list tbody .name { clear: right; }' +
  871. 'body.theme_light #sidebar, body.theme_light #sidebar a, #content_header, body.theme_light #content_font, body.theme_light .font_grid_item a, body.theme_light .image_grid_item p, body.theme_light #content_font, body.theme_light .font_grid_item p, body.theme_light .font_grid_item a, body.theme_light .image_grid_item p, .split_btn span, body #warnings, body.theme_dark #grid_btn .menu li' +
  872. '{ color: #111 }' +
  873. 'body.theme_light #sidebar #tfoot tr { color: #444 }' +
  874. 'body.theme_light #dir_list tr.ignore a, body.theme_light #dir_list tr.ignore.app a, .glyph_info' +
  875. '{ color: #777 }' +
  876. '#sort_menu .disabled span, #dir_list th.disabled { color: #999 }' +
  877. 'body.theme_dark #dir_list tr.ignore td, body.theme_dark #dir_list tr.file.ignore a, body.theme_dark #sidebar #tfoot td' +
  878. '{ color: #BBB }' +
  879. 'body.theme_dark #sidebar th:not(.disabled), body.theme_dark #sidebar td, body.theme_dark #sidebar a, body.theme_dark #error_message *, body.theme_dark #content_header tr, body.theme_dark #content_header tr a, body.theme_dark #content_font, body.theme_dark .font_grid_item p, body.theme_dark .font_grid_item a, body.theme_dark .image_grid_item p, #warnings button:focus, #warnings button.focus' +
  880. '{ color: #EEE }' +
  881. '#warnings h3::before, #bookmarks li > a::before, #bookmarks li > span::before, #preview_text_menu_item span::before, #sorting div span::before, #sorting div span::after, body.has_hidden_sidebar #handle, #dir_list tr:empty, #dir_list .audio td.icon, #dir_list .video td.icon, tr.invisible, body.hide_ignored .ignore, .split_btn::after, #content_pane.has_grid #content_grid::after, #title span::before' +
  882. '{ content: "" }' +
  883. '#content_pane.has_image:not(.has_grid) #title::after, #content_pane.has_zoom_image:not(.has_grid) #title::after'+
  884. '{ content: attr(data-after) }' +
  885. '#content_pane.has_font #title::before { content: "Font: " }' + // font and image grid
  886. '#content_pane.has_grid:not(.has_ignored) #title::before{ content: "Fonts and Images from: " }' + // font and image grid
  887. 'body:not(.has_images) #content_pane.has_grid:not(.has_ignored) #title::before, #content_pane.has_grid #title.font_grid::before' +
  888. '{ content: "Fonts from: " }' + // font grid
  889. '#glyph_viewer_info div::before { content: "Glyph " }' +
  890. '#content_pane.has_ignored:not(.has_grid) #title::before{ content: "Ignored content: " }' + // .ignored
  891. 'body:not(.has_fonts) #content_pane.has_grid:not(.has_ignored) #title::before, #content_pane.has_grid #title.image_grid::before' +
  892. '{ content: "Images from: " }' + // image grid
  893. '#content_pane.has_dir:not(.has_grid) #title::before { content: "Index of: " }' + // .dir
  894. 'body:not(.has_playlist) #sidebar_title th:before { content: "INDEX OF"; }' +
  895. '#content_pane.has_audio #content_audio_title td::before, body #content_pane.has_video #title::before' +
  896. '{ content: "Playing: " }' + // .audio, .video
  897. 'body.has_playlist #sidebar_title th:before { content: "PLAYLIST"; }' +
  898. 'body#top.edited #warnings.unloading h3::before { content: "Text Editor: " }' +
  899. 'body#top.edited #text_editor_row a:after { content: " (edited)"; }' +
  900. 'body.edited.has_text #title::after, body.iframe_edited:not(.has_text) #content_pane.has_iframe #title::after' +
  901. '{ content: " (edited)"; }' + // .ignored
  902. 'body.show_numbers #tbody { counter-reset: row; }' +
  903. 'body.show_numbers #tbody tr td.name a::before { counter-increment: row; content:counter(row);}' +
  904. '#sidebar_title th, #sort_menu .disabled span, #dir_list .disabled'+
  905. '{ cursor: default; }' +
  906. '#sidebar_menus td:hover, #parents_dir_menu div, #bookmarks_menu div, .menu label, #grid_btn, #sorting .toggle_UI_pref, #toggle_info, .split_btn span' +
  907. '{ cursor: pointer; }' +
  908. '#handle { cursor: col-resize; }' +
  909. '#content_pane:not(.has_zoom_image) #content_image img { cursor: zoom-in; }' +
  910. '#content_pane.has_zoom_image #content_image img { cursor: zoom-out; }' +
  911. '#sidebar_menus ul, #show_details span, body.has_playlist #grid_btn, body.has_playlist #sidebar_buttons td > label, #grid_btn .menu, body:not(.has_media) #sorting .name input, #bookmarks li#theme span span, #preview_text::before, #source_text::before, #sidebar_buttons td.up::before, body:not(.show_details) #sorting .details.sorting, #dir_list tr::before, #tbody tr td:not(.name), #text_editor_row, body.has_hidden_sidebar #handle, body.has_hidden_sidebar #sidebar, #dir_list tr:empty, #dir_list tr.audio td.icon, #dir_list tr.video td.icon, tr.invisible, body.hide_ignored #tbody tr.ignore, #content_title::before, #content_pane #content_audio_title, .split_btn, #content_pane #content_audio, #content_pane #content_text, #content_pane .content, #content_pane.has_grid .content, #content_pane:not(.has_hidden_grid) #content_grid, #content_pane.has_grid.has_zoom_image #content_image, #font_specimen, #font_viewer, body.has_text .content:not(#content_text), body.theme_light #theme_dark, body.theme_dark #theme_light, body.use_custom_icons #dir_list img, #dir_list tr.file.audio a img, #dir_list tr.file.video a img, #warnings, #warnings p, #warnings button, #clear_warning, #overlay, #glyph_viewer, #font_info tbody' +
  912. '{ display: none; }' +
  913. 'body.is_error #sorting, body.is_error #sidebar_buttons, body.is_error #text_editor_row, body.is_error #content_pane.has_iframe #content_iframe.has_content' +
  914. '{ display: none !important; }' +
  915. '#sidebar li, #parent_dir_menu, #parent_dir_menu a, #parents_dir_menu + ul li a, #bookmarks_menu + ul li a, #bookmarks_menu + ul li > span, #bookmarks_menu + ul > li:hover > ul, #bookmarks_menu + ul > li > ul:hover, .menu label, body.show_details #show_details span:last-of-type, body:not(.show_details) #show_details span:first-of-type, #sort_by_default, #dir_list tbody a, #dir_list tfoot tr, #content_header, #content_pane.has_font:not(.has_grid) #content_font, #content_pane.has_font:not(.has_grid) #content_font:not(.has_font_viewer) #font_specimen, #content_pane.has_font:not(.has_grid) #content_font.has_font_viewer #font_viewer, #content_pane.has_pdf:not(.has_grid) #content_pdf, body.has_text #content_pane:not(.has_grid) #content_text, #content_pane.has_video:not(.has_grid) #content_video, body:not(.has_text) #content_pane.has_iframe:not(.has_grid) #content_iframe, #content_pane.has_dir:not(.has_grid) #content_iframe, #content_pane.has_grid #content_grid.has_grid, #content_pane.has_grid #content_grid.has_font_grid, #content_pane.has_grid .nav_btn, #content_pane.has_font .nav_btn, .font_grid_item a, .image_grid_item a, #checkbox_div label, body.theme_dark #theme_dark, body.theme_light #theme_light, body:not(.has_hidden_sidebar) #dir_list .name, body.has_warning #warnings, body.has_warning #warnings.unloading p#warning_unsaved, body.has_warning #warnings.clear #warning_clear, body.has_warning #warnings.local p#warning_local, body.has_warning #overlay' +
  916. '{ display: block; }' +
  917. '#parents_dir_menu div, body.has_images.has_fonts #grid_btn:hover ul.menu, #font_info:hover tbody' +
  918. '{ display:block !important; }' +
  919. '#parents_dir_menu div, #bookmarks li > a::before, #bookmarks li > span::before, #bookmarks li#theme > span::before, body.theme_dark #bookmarks #theme_dark, body:not(.theme_dark) #bookmarks #theme_light, body.preview_text #preview_text::before, body.source_text #source_text::before, #sorting div span::before, #enable_text_editing::before, #sorting div span::after, body.show_details #dir_list td.details:not(.name):not(.ext), body.show_numbers #tbody tr td.name a::before, #title, #checkbox_div, #audio_container, #prev_track, #next_track, #close_audio, #warnings h3::before, body.has_warning #warnings.unloading #warning_ignore_btn, body.has_warning #warnings.unloading #warning_cancel_btn, body.has_warning #warnings.unloading #warning_save_btn, body.has_warning #warnings.clear #warning_clear_btn, body.has_warning #warnings.clear #warning_cancel_btn, body.has_warning #warnings.local #warning_ok_btn, #glyph_viewer_info div' +
  920. '{ display: inline-block; }' +
  921. 'body:not(.is_gecko) #dir_list tr td.name span, #content_pane.has_image:not(.has_grid) #content_container, #content_pane.has_video:not(.has_grid) #content_container, #content_pane.has_image:not(.has_grid) #content_image, #content_pane.has_zoom_image #content_image, #font_info tbody tr' +
  922. '{ display: flex; }' +
  923. '#content_pane.has_grid .split_btn, #content_pane.has_image .split_btn, #content_pane.has_zoom_image .split_btn, #content_pane.has_font .split_btn, .split_btn span' +
  924. '{ display: inline-flex; }' +
  925. 'body.is_gecko #dir_list tr td.name span { display: flow-root; }' +
  926. 'body.has_text #text_editor_row, body.show_details #text_editor_row, body.has_hidden_text #text_editor_row, #content_pane.has_audio #content_audio_title, #content_pane.has_audio #content_audio' +
  927. '{ display: table-row !important; }' +
  928. '#bookmarks_menu div, #content_pane, #content_pane.has_audio #content_audio td' +
  929. '{ display: table-cell; }' +
  930. '#sorting > div { display: grid; grid-gap:0; grid-template-columns: 1fr 1fr 1fr 1fr; }' +
  931. '#sort_by_name { grid-column: 1 / span 2; }' +
  932. '#sort_by_default { grid-column: 3 / span 2; }' +
  933. // display grid: dir_list rows and cells
  934. '#dir_list #tbody tr:not(.invisible), body.show_invisibles #tbody tr.invisible, body.show_details #dir_list tr td.details' +
  935. '{ display: grid; grid-gap:0; grid-template-columns: minmax(auto,7rem) 1fr minmax(auto,8rem); }' +
  936. 'td.name { grid-column: 1 / span 3; }' +
  937. 'td.size { grid-column: 1; grid-row: 2; }' +
  938. 'td.date { grid-column: 2; grid-row: 2; }' +
  939. 'td.kind { grid-column: 3; grid-row: 2; }' +
  940. // display grid: content pane grids
  941. '#content_pane.has_grid #content_grid, #content_pane.has_hidden_grid #content_grid { display: grid !important; grid-gap:0; grid-template-columns: repeat(auto-fill, minmax('+ ( $settings.grid_image_size + 16) +'px, auto)); grid-auto-rows: minmax(min-content, max-content); }' +
  942. '#content_grid .image_grid_item { grid-column: auto; display:flex; align-items: center; justify-content: center; }' +
  943. '#content_grid .font_grid_item { grid-column: 1 / -1; }' +
  944. // glyphs container
  945. '#content_font div#glyphs_container { display:grid; grid-gap:0; grid-template-columns:repeat(auto-fill, minmax(120px,auto)); }' +
  946. 'body.theme_dark #bookmarks li > span::before, body.theme_dark #grid_btn, body.theme_dark #parent_dir_menu, body.theme_dark #bookmarks_menu, body.theme_dark #toggle_sidebar, body.theme_dark #toggle_info, body.theme_dark .glyph_container canvas, body.theme_dark #glyph_viewer:not(#glyph_viewer_info), body.theme_dark #glyph_viewer #glyph_viewer_info, body.theme_dark #sorting span::before, body.theme_dark #sorting span::after, body.is_gecko.theme_dark #prev_track, body.is_gecko.theme_dark #next_track, body.is_gecko.theme_dark #close_audio, body.is_safari.theme_dark #prev_track, body.is_safari.theme_dark #next_track, body.is_safari.theme_dark #close_audio ' +
  947. '{ filter:invert(1); }' +
  948. '.menu input, #dir_list tr td.name a::before, #title_buttons_left button, #checkbox_div label, #prev_track, #next_track, #scale, #close_btn, #save_svg, #warnings h3::before, #warnings h3::before' +
  949. '{ float: left; }' +
  950. 'html, body, :root { font-family:'+ $settings.UI_font +'; }' +
  951. 'body, :root, #content_text { font-size: '+ $settings.UI_font_size +'; }' +
  952. '#sidebar, #sidebar_header, #dir_list, #tfoot, #content_header, #content_header table, #warnings, #font_info td, #font_info th, #glyph_viewer_info' +
  953. '{ font-size: 0.875rem; }' +
  954. '#content_grid, .font_grid_item p, #error_message h1, #error_message h2' +
  955. '{ font-size: 1rem; }' +
  956. '#content_grid .font_grid_item h2 { font-size: '+ $settings.grid_font_size * 4 +'em; }' +
  957. '#content_font { font-size: '+ $settings.grid_font_size +'em; }' +
  958. '.lorem.first:first-line { font-size: '+ $settings.grid_font_size * 1.33 +'em; }' +
  959. 'td.name, td.name a::before, td.size, td.date { font-variant-numeric: tabular-nums; }'+
  960. '.lorem.first:first-line { font-variant: small-caps }' +
  961. '#sidebar_title th, h1, h2, h3, h4, h5, h6, #font_info th'+
  962. '{ font-weight: normal }' +
  963. '#dir_list .selected a, body.has_text #text_editor_row, body.edited:not(.has_hidden_text) #text_editor_row, #font_info td:first-of-type' +
  964. '{ font-weight: bold }' +
  965. 'html, body, :root, #parent_dir_menu a, #dir_list, #toggle_info, #main_content, #content_pane, #content_pdf, #content_text, #content_iframe, #content_grid img[src$=".svg"]' +
  966. '{ height: 100%; }' +
  967. '#sidebar_header, #parents_dir_menu, #parents_dir_menu div, #content_pane:not(.has_zoom_image) #content_image img, #content_grid img' +
  968. '{ height: auto; }' +
  969. '.menu input,#content_pane.has_hidden_grid #content_grid{ height: 0; }' +
  970. '#sorting div span::after { height: 8px; }' +
  971. '#bookmarks .toggle_UI_pref span::before, #theme::before, #sort_menu span::before, #preview_text_menu_item span::before, #sorting div span::before, #enable_text_editing::before'+
  972. '{ height: 9px; }' +
  973. '#bookmarks li.bookmarks a::before { height: 12px; }' +
  974. '#toggle_sidebar, #toggle_info { height: 14px; }' +
  975. '#grid_btn, button, #prev_next_btns span, #scale span { height: 18px; }' +
  976. '#warnings h3::before { height: 24px; }' +
  977. '#audio { height: 32px; }' +
  978. '#main_content { height: '+ window.innerHeight +'px; }' +
  979. '#content_pane:not(.has_zoom_image) #content_image img { max-height: calc(100% - 4em); }' +
  980. '#font_info tbody { max-height: '+ (window.innerHeight * 0.75) +'px; }' +
  981. '!#content_pane.has_zoom_image #content_image img { max-height: none; }' +
  982. '#content_grid img { max-height: '+ ($settings.grid_image_size) +'px; }' +
  983. '#title { min-height: 18px; }' +
  984. '#sidebar { min-height: 100%; }' +
  985. '#parents_dir_menu div, #content_header td button, #content_font'+
  986. '{ hyphens: none; }' +
  987. 'html, body, :root, .hamburger h3, .lorem { hyphens: auto; }' +
  988. '#content_container { justify-content: center; }' +
  989. '.lorem.first:first-line, .font_grid_item p, #font_info th'+
  990. '{ letter-spacing: 0.1em; text-indent:0.1em; }' +
  991. '#sidebar_title th { letter-spacing: 0.5em; text-indent:0.5em; }' +
  992. '.image_grid_item a, button { line-height: 0; }' +
  993. '.split_btn span, .font_grid_item p { line-height: 1; }' +
  994. '#dir_list tr a, #title { line-height: 1.4; }' +
  995. '#warnings h3 { line-height: 2; }' +
  996. '#sidebar ul, #grid_btn .menu li { list-style-type: none; }' +
  997. 'html, body, :root, #sidebar ul, #parent_dir_menu, #parent_dir_menu, #parents_dir_menu, #parents_dir_menu + ul li a, #bookmarks_menu + ul li a, #bookmarks_menu + ul li > span, #bookmarks_menu, #grid_btn, #dir_list tbody a, #content_font .hamburger *, #content_font canvas, #content_grid p, #content_grid h2, #content_text, #warnings h3' +
  998. '{ margin: 0; }' +
  999. '#content_image, #content_image img { margin-left: auto; margin-right: auto; }' +
  1000. '.image_grid_item + .font_grid_item { margin-top: -1px; }' +
  1001. '#checkbox_div label input, #show_details, body.is_error #tbody h1'+
  1002. '{ margin-top: 0; }' +
  1003. 'body.has_audio #dir_list input { margin-top: 1px; }' +
  1004. '#increase { margin-right: -4px; }' +
  1005. 'th input, tr.media input, #scale { margin-right: 8px; }' +
  1006. '#show_details { margin-right: 0.5em; }' +
  1007. '#warning_ignore_btn { margin-right: 2em; }' +
  1008. '#checkbox_div { margin-right: calc(-6em - 4px); }' +
  1009. '#bookmarks li a::before { margin-bottom: -2px; }' +
  1010. '#show_details { margin-bottom: 0; }' +
  1011. 'body.has_audio #dir_list input { margin-bottom: 1px; }' +
  1012. '#content_grid.has_image_grid { margin-bottom: 1rem; }' +
  1013. '#decrease { margin-left: -4px; }' +
  1014. 'th input { margin-left: 2px; }' +
  1015. 'tr.media input { margin-left: 7px; }' +
  1016. '#prev_next_btns { margin-left: 8px; }' +
  1017. '#show_details, #warnings button { margin-left: 0.5em; }' +
  1018. '#warnings { margin-left: -12em; }' +
  1019. '#dir_list tbody tr { margin-inline-start: 0; }' +
  1020. '#sidebar ul { -webkit-margin-before: 0em !important; -webkit-margin-after: 0em !important; -webkit-padding-start:0em; }' +
  1021. '#open_font { opacity: 0.0; }' +
  1022. '#content_pane.has_ignored::before, #close_audio::after { opacity: 0.3; }' +
  1023. '#close_audio:hover::after, body.theme_light #dir_list.has_dir:not(:hover)' +
  1024. '{ opacity: 0.6; }' +
  1025. '#sidebar_menus td:last-of-type:hover > div, #bookmarks_menu_container #bookmarks_menu, #parent_dir_menu, #toggle_sidebar, #grid_btn, #toggle_info, body.use_custom_icons #dir_list tr.file.ignore a.icon::before, .split_btn span, body.theme_dark #dir_list.has_dir:not(:hover)' +
  1026. '{ opacity: 0.7; }' +
  1027. '#grid_btn:hover, #parent_dir_menu:hover, #bookmarks_menu_container:hover #bookmarks_menu, #prev_next_btns span:hover, #toggle_sidebar:hover, #grid_btn:hover, #toggle_info:hover, .split_btn span:hover' +
  1028. '{ opacity: 1.0; }' +
  1029. '#grid_btn, #dir_list tbody, #dir_list tbody a, #audio:focus, #content_grid .font_grid_item, #content_font, #warnings button:focus, #content_video' +
  1030. '{ outline: none; }' +
  1031. 'html, body, :root, #parents_dir_menu div, #bookmarks_menu, #dir_list, #dir_list tbody a, #dir_list .details.kind, #main_content, #close_audio, .hamburger h1, .hamburger h2, .hamburger h4' +
  1032. '{ overflow: hidden; }' +
  1033. '#dir_list tbody, #next_track, #prev_track, #content_container, #content_font, #content_grid, #font_info tbody' +
  1034. '{ overflow: auto; }' +
  1035. '#sidebar, #content_font { overflow-wrap: break-word; }' +
  1036. 'html, body, :root, #main_content > thead th, #sidebar_wrapper, #sidebar ul, #sidebar_menus > td, #parent_dir_menu, #parent_dir_menu, #parent_dir_menu a, #parents_dir_menu, #bookmarks_menu, #grid_btn, #dir_list .details a, #tfoot, #title_buttons_left button, #content_pane, #reload_btn, #close_btn, #audio_container > div, #content_pdf, #content_iframe, #content_text, audio::-webkit-media-controls-panel' +
  1037. '{ padding: 0; }' +
  1038. 'div#glyphs_container, div.glyph_container, #glyph_viewer, #glyph_viewer_info div'+
  1039. '{ padding: 0 !important; }' +
  1040. '#show_details, #prev_next_btns, #scale { padding-top: 0; }' +
  1041. '#sidebar_title th, #parents_dir_menu div, #parents_dir_menu + ul li a, #grid_btn .menu li, #dir_list tbody a, #stats, #title_buttons_left, #title_buttons_right, #title, body #content_audio_title td, #content_audio td, #content_font div#glyph_viewer_info, #font_info td' +
  1042. '{ padding-top: 4px; }' +
  1043. '#sidebar_header tbody tr:last-of-type td, #bookmarks_menu + ul li a, #bookmarks_menu + ul li > span, #bookmarks_menu + ul li div span, .menu label, #sorting .toggle_UI_pref, #sidebar_buttons td, #text_editor_row th, .image_grid_item, .hamburger h4' +
  1044. '{ padding-top: 6px; }' +
  1045. '#content_grid .font_grid_item, .font_grid_item p, #content_font div.lorem' +
  1046. '{ padding-top: 0.5rem; }' +
  1047. '#error_message, #warnings { padding-top: 1rem; }' +
  1048. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #content_font div.specimen' +
  1049. '{ padding-top: 2rem; }' +
  1050. '#sidebar_header tbody tr:last-of-type td { padding-right: 0; }' +
  1051. 'div.glyph_container div.glyph_info { padding-right: 2px; }' +
  1052. '#sidebar_title th, #scale { padding-right: 4px; }' +
  1053. '#parents_dir_menu div, #grid_btn .menu li, #stats, #title_buttons_left, #title_buttons_right, #content_audio td, #audio_container, #content_font div#glyph_viewer_info, #font_info td, .image_grid_item' +
  1054. '{ padding-right: 6px; }' +
  1055. '#bookmarks_menu + ul li a, #bookmarks_menu + ul li > span, #bookmarks_menu + ul li div span, .menu label, body.show_numbers #tbody tr td.name a::before, #dir_list tbody a' +
  1056. '{ padding-right: 8px; }' +
  1057. '#parents_dir_menu + ul li a, #title, #content_audio_title td'+
  1058. '{ padding-right: 12px; }' +
  1059. '#dir_list td.details { padding-right: 16px; }' +
  1060. '#content_audio_title td:before { padding-right: 18px; }' +
  1061. '#grid_btn .menu { padding-right: 24px; }' +
  1062. '#error_message, #warnings { padding-right: 1rem; }' +
  1063. '.font_grid_item p, .font_grid_item a { padding-right: 2rem; }' +
  1064. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #font_specimen' +
  1065. '{ padding-right: 2.5rem; }' +
  1066. '#show_details, #prev_next_btns, #scale { padding-bottom: 0; }' +
  1067. 'body.is_dirs_on_top #dir_list tbody tr.sorted:not(:last-of-type), div.glyph_container div.glyph_info' +
  1068. '{ padding-bottom: 2px; }' +
  1069. '#sorting, #title, body #content_audio_title td, #title_buttons_left, #title_buttons_right' +
  1070. '{ padding-bottom: 3px;}' +
  1071. '#sidebar_title th, #parents_dir_menu div, #parents_dir_menu + ul li a, #grid_btn .menu li, #dir_list tbody a, #sidebar .details, #content_font div#glyph_viewer_info, #font_info td' +
  1072. '{ padding-bottom: 4px; }' +
  1073. '#sidebar_header tbody tr:last-of-type td, #parents_dir_menu + ul li:last-of-type a, #bookmarks_menu + ul li a, #bookmarks_menu + ul li > span, #bookmarks_menu + ul li div span, .menu label, body:not(.show_details) #sorting, #text_editor_row th, #dir_list tfoot td, #content_audio td, .image_grid_item' +
  1074. '{ padding-bottom: 6px; }' +
  1075. '.hamburger h4 { padding-bottom: 9px; }' +
  1076. '.specimen, .font_grid_item p, .font_grid_item a { padding-bottom: 0.5rem; }' +
  1077. '#error_message, #warnings { padding-bottom: 1rem; }' +
  1078. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #content_font > div.specimen, #content_font .lorem:last-of-type' +
  1079. '{ padding-bottom: 2rem; }' +
  1080. '#dir_list #tbody td.name a.icon, #dir_list td.details, #grid_btn .menu, #sidebar_header tbody tr:last-of-type td, #prev_next_btns' +
  1081. '{ padding-left: 0px; }' +
  1082. 'div.glyph_container div.glyph_info { padding-left: 2px; }' +
  1083. '#sidebar_title th, #bookmarks ul li a, #dir_list .audio a, #dir_list .video a, #checkbox_div, #scale' +
  1084. '{ padding-left: 4px; }' +
  1085. '#parents_dir_menu div, #dir_list th#name, #dir_list td.icon, #dir_list .icon + td.name a, #dir_list tfoot td:not(#toggle_info), #checkbox_div #parents_dir_menu div, #grid_btn .menu li, #title_buttons_left, #title_buttons_right, #content_audio td, #audio_container, #content_font div#glyph_viewer_info, #font_info td, .image_grid_item' +
  1086. '{ padding-left: 6px; }' +
  1087. '#parents_dir_menu + ul a, #title, #content_audio_title td'+
  1088. '{ padding-left: 12px; }' +
  1089. '#text_editor_row a { padding-left: 18px; }' +
  1090. '.menu label, body.has_hidden_sidebar #title_buttons_left'+
  1091. '{ padding-left: 24px; }' +
  1092. '#dir_list #tbody tr:not(.media) a span { padding-left: 27px; -webkit-padding-start: 27px; }' +
  1093. '#bookmarks .bookmarks ul li a { padding-left: 28px; }' +
  1094. '#dir_list #tbody td.details.size, tr.media a.icon { padding-left: 30px; }' +
  1095. '#error_message, #warnings { padding-left: 1rem; }' +
  1096. '.font_grid_item p, .font_grid_item a { padding-left: 2rem; }' +
  1097. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #font_specimen' +
  1098. '{ padding-left: 2.5rem; }' +
  1099. '#dir_list td.name a { -webkit-padding-start: 0; }' +
  1100. '#dir_list .icon + td.name a { -webkit-padding-start: 1em; }' +
  1101. '#sidebar_wrapper, #sidebar_header, #sidebar_buttons, #sidebar_menus td:first-of-type, #grid_btn, #dir_list, body.show_numbers #tbody tr td.name a::before, #dir_list tr.ignore a, #dir_list tr.ignore.app a, #dir_list tr.ignore td.details, #bookmarks_menu + ul > li.has_submenu, #content_pane, #content_header, #content_text, .glyph_container, #content_pdf, #content_iframe, #close_audio, #content_grid div img, #content_text, .split_btn, #content_pane.has_zoom_image #content_image, #content_image img' +
  1102. '{ position: relative; }' +
  1103. '#sidebar ul, #handle, #parent_dir_menu, #toggle_sidebar, #toggle_info, body.has_hidden_sidebar #sidebar_wrapper, #dir_list tbody, #close_audio::after, .split_btn::after, #content_container, #content_grid, #warnings, #overlay, #content_pane.has_grid #content_grid::after, .glyph_info' +
  1104. '{ position: absolute; }' +
  1105. '#tfoot, #glyph_viewer, #font_info, #content_pane.has_image #content_image'+
  1106. '{ position: fixed; }' +
  1107. '#parent_dir_menu, #overlay, #glyph_viewer, #content_pane.has_zoom_image #content_image, #content_image'+
  1108. '{ top: 0; right: 0; bottom: 0; left: 0; }' +
  1109. '#dir_list, #handle, #content_pane.has_grid #content_grid::after, .split_btn::after'+
  1110. '{ top: 0; bottom: 0; }' +
  1111. '#sidebar ul, #tbody, .glyph_info, #tfoot { left: 0; right: 0; }' +
  1112. '#tbody, #toggle_info, #warnings { top: 0 !important; }' +
  1113. '#bookmarks_menu + ul > li > ul, #grid_btn .menu { top: -1px !important; }' +
  1114. 'body.has_hidden_sidebar #sidebar_wrapper { top: 2px; }' +
  1115. '#toggle_sidebar { top: 4px; }' +
  1116. '#grid_btn .menu, #content_grid, #content_pane.has_grid #content_grid::after, #toggle_info'+
  1117. '{ right: 0; }' +
  1118. '#handle { right: -4px; }' +
  1119. '#toggle_sidebar { right: 4px; }' +
  1120. '#dir_list tbody, #tfoot, #content_container, .glyph_info, #font_info'+
  1121. '{ bottom: 0; }' +
  1122. 'body.has_hidden_sidebar #toggle_sidebar, #content_grid { left: 0; }' +
  1123. '#grid_btn ul.menu { left: unset; }' +
  1124. 'body.has_hidden_sidebar #sidebar_wrapper { left: 3px; }' +
  1125. 'body.show_numbers #tbody tr td.name a::before { left: 6px; }' +
  1126. '#warnings, .split_btn::after { left: 50%; }' +
  1127. '#bookmarks_menu + ul > li > ul { left: 100%; }' +
  1128. '#sidebar ul, #dir_list tbody, #sort_by_name, #sort_by_size, #text_editor_row, #dir_list tbody .name, #dir_list tr.details, #title_buttons_left, #warnings' +
  1129. '{ text-align: left; }' +
  1130. '#parent_dir_menu a, #parents_dir_menu, #parents_dir_menu div, #bookmarks_menu div, #content_header, #content_title, #content_audio_title, #content_audio td, .glyph_container, #glyph_viewer_info, #content_image' +
  1131. '{ text-align: center; }' +
  1132. '#grid_btn .menu li, body.show_numbers #tbody tr td.name a::before, #sort_by_default, #sort_by_ext, #dir_list .size, #dir_list .date, #dir_list .kind, #title_buttons_right, #warnings div, .playlist_time, #font_info td:first-of-type' +
  1133. '{ text-align: right; }' +
  1134. 'a, a:hover { text-decoration: none !important; }' +
  1135. '#bookmarks .bookmarks ul li a { text-indent: -24px; }' +
  1136. '#dir_list .details.kind { text-overflow: ellipsis; }' +
  1137. '#dir_list, #content_pane { transform: scale(1); }' + // needed to establish #dir_list as containing block for thead and tfoot position fixed.
  1138. 'body.has_hidden_sidebar #toggle_sidebar, #sorting div.up span::after, #prev_track, #toggle_info' +
  1139. '{ transform:rotate(180deg) !important; }' +
  1140. '#sidebar_header, #content_pane:not(.has_zoom_image) #content_image' +
  1141. '{ user-select:none; -webkit-user-select:none; }' +
  1142. '#content_pane, #title_buttons_left, #title_buttons_right, #title'+
  1143. '{ vertical-align:top; }' +
  1144. '#sidebar_header tbody tr:last-of-type td, #parents_dir_menu div, #parents_dir_menu + ul li a, #bookmarks_menu + ul li a, #bookmarks_menu + ul li > span, #dir_list tbody a, .specimen, .lorem' +
  1145. '{ white-space: normal; }' +
  1146. '#sorting span, #tbody td:not(.name), #grid_btn .menu li, .hamburger h1, .hamburger h2, .hamburger h4' +
  1147. '{ white-space: pre; }' +
  1148. 'html, body, :root, table, #parent_dir_menu a, #tbody, #tbody tr, #bookmarks_menu + ul > li > ul, #grid_btn .menu li, #content_container, #content_header, #content_grid, #content_text, #content_font svg, #content_pdf, #content_iframe, #content_grid img[src$=".svg"]' +
  1149. '{ width: 100%; }' +
  1150. '#sidebar_menus td:nth-of-type(2), #dir_list .date, #title, #content_pane:not(.has_zoom_image) #content_image img, #content_grid img' +
  1151. '{ width: auto; }' +
  1152. '.split_btn span { width: 2em; }' +
  1153. '#content_pane.has_grid #content_grid::after, .split_btn::after' +
  1154. '{ width: 1px; }' +
  1155. '#handle { width: 8px; }' +
  1156. '#sorting div span::before, #sorting div span::after, #toggle_sidebar, #toggle_info' +
  1157. '{ width: 18px; }' +
  1158. '#sidebar_menus td:nth-of-type(odd), #bookmarks li a::before, #bookmarks li > span::before, #sort_menu span::before, #preview_text_menu_item span::before, #grid_btn'+
  1159. '{ width: 24px; }' +
  1160. '#warnings h3::before { width: 32px; }' +
  1161. '#prev_track, #next_track, #close_audio { width: 2rem; }' +
  1162. '#content_pane:not(.has_image) #title_buttons_left, #content_pane:not(.has_image) #title_buttons_right, #content_pane:not(.has_zoom_image) #title_buttons_left, #content_pane:not(.has_zoom_image) #title_buttons_right' +
  1163. '{ width: 4rem; }' +
  1164. '#bookmarks_menu div, #checkbox_div { width: 6em; }' +
  1165. '#content_pane.has_image #title_buttons_left, #content_pane.has_image #title_buttons_right, #content_pane.has_zoom_image #title_buttons_left, #content_pane.has_zoom_image #title_buttons_right, #content_pane.has_grid #title_buttons_left, #content_pane.has_grid #title_buttons_right, #content_pane.has_font #title_buttons_left, #content_pane.has_font #title_buttons_right' +
  1166. '{ width: 9.5em; }' +
  1167. '#warnings { width: 26em; }' +
  1168. 'body.has_hidden_sidebar #sidebar_wrapper, .menu input { width: 0 !important; }' +
  1169. '#reload_btn, #close_btn { width: 52px; }' +
  1170. '#font_info td:first-of-type { width: 33.33%; }' +
  1171. '#font_info td:last-of-type { width: 66.66%; }' +
  1172. 'body.has_hidden_sidebar #content_pane, #font_info { width: 100% !important; }' +
  1173. 'body:not(.has_hidden_sidebar) #sidebar_wrapper { width:'+ getQuery('width').toString() +'%; }' +
  1174. 'body:not(.has_hidden_sidebar) #content_pane { width:'+ (100 - getQuery('width')).toString() +'%; }' +
  1175. '#content_video { width: calc(100% - 2rem); }' +
  1176. 'html, body, :root { max-width: 100%; }' +
  1177. '#content_pane:not(.has_zoom_image) #content_image img { max-width: calc(100% - 5rem); }' +
  1178. '!#content_pane.has_zoom_image #content_image img { max-width: none; }' +
  1179. '#sidebar_menus td:nth-of-type(odd) { max-width: 24px; }' +
  1180. '#content_grid img { max-width:'+ ($settings.grid_image_size).toString() +'px; }' +
  1181. 'body.show_numbers #tbody tr td.name a::before { min-width: 17px; }' +
  1182. 'body:not(.has_hidden_sidebar) #sidebar_menus td:nth-of-type(odd)'+
  1183. '{ min-width: 24px; }' +
  1184. 'body:not(.has_hidden_sidebar) #dir_list { min-width: 100px; }' +
  1185. 'body:not(.has_hidden_sidebar) #sidebar_wrapper { min-width: 220px; }' +
  1186. '#sidebar_wrapper, #content_pane { will-change: width }' +
  1187. '#content_header td button { word-break: none; }' +
  1188. '#title { word-break: break-word; }' +
  1189. '#content_pane { z-index: 0; }' +
  1190. '#handle, #sidebar_wrapper, #glyph_viewer, #font_info { z-index: 1; }' +
  1191. '#parents_dir_menu + ul, #content_header { z-index: 2; }' +
  1192. '#sidebar_header { z-index: 3; }' +
  1193. '#toggle_sidebar, #grid_btn { z-index: 9997; }' +
  1194. '#overlay, #bookmarks { z-index: 9998; }' +
  1195. '#warnings { z-index: 9999; }' +
  1196. 'body.has_hidden_sidebar #sidebar_header { z-index:unset; }'
  1197. ;
  1198. // Gecko Styles:
  1199. const $gecko_style_rules =
  1200. 'html, body.is_gecko { border: solid 1px gray !important; }' +
  1201. 'body.is_gecko button { padding:revert; }' +
  1202. 'body.is_gecko #grid_btn .menu { top:-7px; left:-120px; }' +
  1203. 'body.is_gecko thead { font-size:100%; }' +
  1204. 'body.is_gecko #dir_list .dir::before { position:absolute; }' +
  1205. 'body.is_gecko.use_default_icons:not(.is_converted_list) #dir_list .file .name .icon'+
  1206. '{ padding-left:4px; background:none; }' +
  1207. 'body.is_gecko.use_default_icons #dir_list .file .name .icon img'+
  1208. '{ margin-right:6px; height:14px; }' +
  1209. 'body.is_gecko #tbody > tr > td:not(:first-of-type) { float:left }' +
  1210. 'body.is_gecko #content_audio_title td { padding-top: 6px; }' +
  1211. 'body.is_gecko #content_audio_title td { padding-bottom: 0; }' +
  1212. 'body.is_gecko #audio, body.is_gecko #audio_container { background-color: transparent; }'
  1213. ;
  1214. var $text_editing_style_rules =
  1215. 'html, body, #iframe_body { margin:0; padding:0; }' +
  1216. // toolbar
  1217. '#toolbar { margin:0; padding:0; height:32px; display:block; position:relative; left:0; right:0; z-index:100; background:#EEE; border:0; border-bottom: solid 1px #999; font-family:'+ $settings.UI_font +'; font-size:'+ parseFloat($settings.UI_font_size) * 0.875 + $settings.UI_font_size.replace(/\d*/,'') +'; -webkit-user-select: none; -moz-user-select: none; user-select:none; }' +
  1218. '#toolbar li { margin:4px; padding:4px; width:3.5em; display:block; opacity:0.5; list-style-type:none; cursor:pointer; }' +
  1219. '#toolbar li:hover, .preview_text:not(.split) #toolbar li#show_preview, body.source_text #show_source, .split_view #toolbar li#toggle_split, .edited #save_btn'+
  1220. '{ opacity:1; }' +
  1221. '#toolbar li#toggle_split { float:left; width:16px; height: 16px; margin: 4px 0 4px 4px; background: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\'><path fill=\'%23333333\' d=\'M0,0v16h16V0H0z M15,15H8.5V1H15V15z M7.5,15H1V1h6.5V15z\'/></svg>") center no-repeat; }' +
  1222. '#toolbar li#sync_scroll { width:8em; float:left; opacity:1; }' +
  1223. '#toolbar li#sync_scroll input { float:left; }' +
  1224. '#toolbar li#sync_scroll label { width:8em; display:block; font-size:inherit; line-height:1.5; }' +
  1225. '#toolbar li#clear_text { height:16px; float:right; text-align:center; }' +
  1226. '#toolbar li#save_btn { float:right; width:20px; height:16px; background: 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=\'%23333333\' d=\'M16,0v10.02h-1.33V1.33H1.33v8.69H0V0H16z\'/> <path fill=\'%23333333\' d=\'M8.47,16h-0.7l-3.08-3.08l0.94-0.94l1.83,1.83V4.28h1.33v9.53l1.81-1.82l0.94,0.93L8.47,16z\'/></g></svg>") 8px 4px no-repeat; position:relative; }' +
  1227. '#toolbar li#show_source { float:left; width:16px; height: 16px; margin: 4px 0 4px 12px; background: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=\'42px\' height=\'16px\' viewBox=\'0 0 42 16\' enable-background=\'new 0 0 42 16\' xml:space=\'preserve\'><g> <path fill=\'%23333333\' d=\'M0.08,7.02L5.94,3.9l0.43,0.78L1.18,7.42l5.19,2.74l-0.43,0.78L0.08,7.82V7.02z\'/> <path fill=\'%23333333\' d=\'M7.84,16.01H6.82L13.78,0h1.02L7.84,16.01z\'/> <path fill=\'%23444444\' d=\'M21.75,7.87l-5.86,3.12l-0.43-0.78l5.19-2.74l-5.19-2.74l0.43-0.78l5.86,3.12V7.87z\'/> <path fill=\'%23333333\' d=\'M30.98,2.65h-3.63V1.58h8.55v1.07h-3.63v9.65h-1.28V2.65z\'/> <path fill=\'%23333333\' d=\'M36.38,4.71h1.3l0.42-2h0.8v2h2.45v0.99h-2.45v4.63c0,0.74,0.27,1.15,0.96,1.15c0.43,0,1.09-0.21,1.39-0.35 l0.18,0.95c-0.42,0.26-1.18,0.45-1.81,0.45c-1.36,0-1.94-0.7-1.94-2.19V5.71h-1.3V4.71z\'/></g></svg>") left 5px no-repeat; }' +
  1228. '#toolbar li#show_preview { float:left; width:16px; height: 16px; margin: 4px 0 4px 4px; background: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=\'42px\' height=\'16px\' viewBox=\'0 0 42 16\' enable-background=\'new 0 0 42 16\' xml:space=\'preserve\'><g> <path fill=\'%23333333\' d=\'M0.08,7.02L5.94,3.9l0.43,0.78L1.18,7.42l5.19,2.74l-0.43,0.78L0.08,7.82V7.02z\'/> <path fill=\'%23333333\' d=\'M7.84,16.01H6.82L13.78,0h1.02L7.84,16.01z\'/> <path fill=\'%23444444\' d=\'M21.75,7.87l-5.86,3.12l-0.43-0.78l5.19-2.74l-5.19-2.74l0.43-0.78l5.86,3.12V7.87z\'/> <path fill=\'%23333333\' d=\'M30.98,2.65h-3.63V1.58h8.55v1.07h-3.63v9.65h-1.28V2.65z\'/> <path fill=\'%23333333\' d=\'M36.38,4.71h1.3l0.42-2h0.8v2h2.45v0.99h-2.45v4.63c0,0.74,0.27,1.15,0.96,1.15c0.43,0,1.09-0.21,1.39-0.35 l0.18,0.95c-0.42,0.26-1.18,0.45-1.81,0.45c-1.36,0-1.94-0.7-1.94-2.19V5.71h-1.3V4.71z\'/></g></svg>") -24px 5px no-repeat; }' +
  1229. '.edited #toolbar li#save_btn { background: 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=\'%23DD2222\' d=\'M16,0v10.02h-1.33V1.33H1.33v8.69H0V0H16z\'/> <path fill=\'%23DD2222\' d=\'M8.47,16h-0.7l-3.08-3.08l0.94-0.94l1.83,1.83V4.28h1.33v9.53l1.81-1.82l0.94,0.93L8.47,16z\'/></g></svg>") 8px 4px no-repeat; position:relative; }' +
  1230. '#toolbar li#save_btn div { display:none; position:relative; top:-9px; left:-24px; color:#999; text-align:right; }' +
  1231. '#toolbar li#save_btn:hover div { display:block; }' +
  1232. '#toolbar li#save_btn span { width:6rem; padding:4px 6px; background: #EEE; float:right; display:block; border:solid 1px #999; position:relative; z-index:1; }' +
  1233. '#toolbar li#save_btn span:first-of-type { border-bottom-width:0px; }' +
  1234. '#toolbar li#save_btn span:hover { color:#444; }' +
  1235. // resize handle
  1236. '.split_view #text_editing_handle { width:9px; position:absolute; top:0; bottom:0; left:calc(50% - 4px); cursor:col-resize; z-index:11; }' +
  1237. '#text_editing_handle { z-index:-1; }' +
  1238. // source
  1239. '#content_source { margin:0; padding: 14px; width:100%; height:calc(100% - 32px); display:block; line-height:1.2; box-sizing:border-box; z-index:1; border:0; overflow-y:scroll; background:#EEE; resize:none; font-family:monospace; font-size:'+ parseFloat($settings.UI_font_size) + $settings.UI_font_size.replace(/\d*/,'') +'; }' +
  1240. '#content_source, #content_preview { position:absolute; top:32px; right:0; bottom:0; left:0; }' +
  1241. '#content_source:focus { outline:none; background:#FFF; box-shadow: inset 0 0 4px #888; }' +
  1242. // preview
  1243. '#content_preview { margin:0; padding: 14px; box-sizing:border-box; z-index:1; border:0; overflow-y:scroll; background:#FFF; font-size:'+ parseFloat($settings.UI_font_size) + $settings.UI_font_size.replace(/\d*/,'') +'; }' +
  1244. // split views
  1245. '.preview_text:not(.split_view) #content_source, .source_text:not(.split_view) #content_preview, li#save_btn div, .comment'+
  1246. '{ display:none; }' +
  1247. '.split_view #content_preview { border-left:solid 1px #999; }' +
  1248. '.split_view #content_source { width:50%; }' +
  1249. '.split_view #content_preview { left:50%; }' +
  1250. // preview styles
  1251. '#content_preview pre { border:solid 1px #CCC; border-radius:3px; white-space:pre-wrap; word-break:break-word; font-size:'+ parseFloat($settings.UI_font_size) + $settings.UI_font_size.replace(/\d*/,'') +'; }' +
  1252. '#content_preview .no_list { list-style:none; }' +
  1253. '#content_preview > .no_list { padding:0; }' +
  1254. '#content_preview .text-align-center { text-align:center; }' +
  1255. '#content_preview th, #content_preview td { vertical-align:top; }' +
  1256. '#content_preview blockquote { margin-top:1em; margin-bottom:1em; color: #555; }' +
  1257. '#content_preview blockquote + blockquote { margin-top:0; }' +
  1258. '.markdown-body input[type="checkbox"] { margin-top:0.375em; margin-right:6px; float:left; }' +
  1259. 'h1 .uplink,h2 .uplink,h3 .uplink,h4 .uplink,h5 .uplink,h6 .uplink'+
  1260. '{ margin:0; padding:0; display:inline-block; font-size:0.875em; cursor:pointer; transition: opacity 0.25s; opacity:0; }' +
  1261. 'h1:hover .uplink,h2:hover .uplink,h3:hover .uplink,h4:hover .uplink,h5:hover .uplink,h6:hover .uplink'+
  1262. '{ transition: opacity 0.25s; opacity:0.5; }' +
  1263. '#content_preview table { font-size:inherit; }' +
  1264. '#content_preview table th { background-color:#EEE; }' +
  1265. '.markdown-body::before, .markdown-body::after { display:none !important; background:transparent; }' +
  1266. // edited warning
  1267. '#iframe_body #warnings p, #iframe_body #warnings button { display:none; }' +
  1268. '#iframe_body #warnings { width:22em; margin-left:-12.5em; padding:1rem; font-size:0.75rem; border-radius:0 0 3px 3px; display:none; position:absolute; top:0; left:50%; z-index:9999; background:#EEE; box-shadow: 0px 2px 12px 0 #111; }' +
  1269. '#iframe_body #warnings h3 { margin:0; font-weight:normal; }' +
  1270. '#iframe_body #warnings div { text-align:right; }' +
  1271. '#iframe_body #warnings button { margin-left:0.5em; }' +
  1272. '#iframe_body #warnings #warning_ignore_btn { margin-right:2em; }' +
  1273. '#iframe_body.has_warning #warnings, #iframe_body.has_warning #warnings.unsaved p#warning_unsaved, #iframe_body.has_warning #warnings.clear p#warning_clear'+
  1274. '{ display:block; }' +
  1275. '#iframe_body.has_warning #warnings.clear #warning_clear_btn, #iframe_body.has_warning #warnings.clear #warning_cancel_btn, #iframe_body.has_warning #warnings.unloading p#warning_unsaved, #iframe_body.has_warning #warnings.unloading #warning_ignore_btn, #iframe_body.has_warning #warnings.unloading #warning_cancel_btn, #iframe_body.has_warning #warnings.unloading #warning_save_btn'+
  1276. '{ display:inline-block; }' +
  1277. // disabled text editing
  1278. '#iframe_body.enable_text_editing #toolbar, #iframe_body.enable_text_editing #preview_text, #iframe_body.enable_text_editing #text_editing_handle'+
  1279. '{ display:none; }' +
  1280. '#iframe_body.enable_text_editing #content_source.disabled'+
  1281. '{ top:0; background:white; }'
  1282. ;
  1283. var $iframe_styles =
  1284. '#iframe_body a.up, #iframe_body #dir_list { background: transparent; }' +
  1285. '#iframe_body :root, html, body { background-color: #BBB; }' +
  1286. '#iframe_body #thead, #tbody tr { background-color: rgba(221,221,221,0.5); }' +
  1287. '#iframe_body #change_dirs { background-color: rgba(144,144,144,0.33); }' +
  1288. '#iframe_body #tbody tr:nth-of-type(odd) { background-color: rgba(221,221,221,1); }' +
  1289. '#iframe_body #tbody tr:not(.media):hover { background-color: rgba(172,202,235,0.75) !important; }' +
  1290. '#iframe_body #tbody tr.media:hover { background-color: rgba(116,190,190,0.5) !important; }' +
  1291. '#iframe_body #dir_list tr td.name a::before { content:""; width:14px; height:14px; margin-right:4px; bottom:-1px; background-position:center; background-repeat:no-repeat; background-size:contain; }' +
  1292. CSS_UI_Icon_Rules('#iframe_body') + // background icons
  1293. '#iframe_body #dir_list.sort_by_default #sort_by_default span::before, #iframe_body #dir_list.sort_by_name #sort_by_name span::before, #iframe_body #dir_list.sort_by_size #sort_by_size span::before, #iframe_body #dir_list.sort_by_date #sort_by_date span::before, #iframe_body #dir_list.sort_by_kind #sort_by_kind span::before, #iframe_body #dir_list.sort_by_ext #sort_by_ext span::before'+
  1294. '{ background-image:'+ SVG_UI_Icon('check_mark') +'; background-repeat: no-repeat; background-size:10px; background-position: center; }' +
  1295. '#iframe_body #dir_list.sort_by_default #sort_by_default span::after, #iframe_body #dir_list.sort_by_name #sort_by_name span::after, #iframe_body #dir_list.sort_by_size #sort_by_size span::after, #iframe_body #dir_list.sort_by_date #sort_by_date span::after, #iframe_body #dir_list.sort_by_kind #sort_by_kind span::after, #iframe_body #dir_list.sort_by_ext #sort_by_ext span::after'+
  1296. '{ background-image:'+ SVG_UI_Icon('chevron_up') +'; background-repeat: no-repeat; background-size:10px; background-position: center; }' +
  1297. '#iframe_body .sorting.down span::after { transform:rotate(180deg) }' +
  1298. ':root, html, #iframe_body { border:0 !important; }' + // border
  1299. 'html, #iframe_body { border-radius:0; }' +
  1300. '#iframe_body #dir_list { border-collapse:collapse; }' +
  1301. '#iframe_body #dir_list thead th { border-bottom:solid 1px #999; }' +
  1302. '#iframe_body, iframe_body td.name, iframe_body td.details'+
  1303. '{ box-sizing:border-box; }' + // box-sizing
  1304. '#iframe_body a { color:#111111; }' + // color
  1305. '#iframe_body a:hover { color:#000000; }' +
  1306. '#iframe_body tr.ignore, #iframe_body tr.ignore a { color:grey; }' +
  1307. '.sorting span::before,.sorting span::after { content:""; width:16px; height:8px; display:inline-block; position:relative; }' +// content
  1308. '#iframe_body tbody { counter-reset: row; }' + // counter
  1309. '#iframe_body.show_numbers tr td.name::before { counter-increment: row; content:counter(row); margin-right:6px; min-width:1.25em; text-align:right;}' +
  1310. '#iframe_body #dir_list td.name::before, #iframe_body #dir_list a::before, td.size, td.date'+
  1311. '{font-variant-numeric: tabular-nums; }'+
  1312. '#iframe_body #dir_list th.sorting { cursor: pointer; }' + // cursor
  1313. '#iframe_body #dir_list tr::before, #iframe_body #dir_list td.name input, #iframe_body td.ext'+
  1314. '{ display:none; }' + // display
  1315. '#change_dirs span { display:inline-block; }' +
  1316. '#iframe_body a { display:block; }' +
  1317. '#sorting { display: grid; grid-gap:0; grid-template-columns: 50% 50%; }' +
  1318. '#iframe_body #dir_list #tbody tr, #sorting_row { display: grid; grid-gap:0; grid-template-columns: minmax(200px,100%) minmax(auto,6em) minmax(auto,14em) minmax(auto,7em); }' +
  1319. '#iframe_body td.name, #iframe_body #sort_by_name, #iframe_body #sort_by_ext'+
  1320. '{ grid-column: 1; }' +
  1321. '#iframe_body td.size, #iframe_body #sort_by_default, #iframe_body #sort_by_size'+
  1322. '{ grid-column: 2; }' +
  1323. '#iframe_body td.date, #iframe_body #sort_by_date { grid-column: 3; }' +
  1324. '#iframe_body td.kind, #iframe_body #sort_by_kind { grid-column: 4; }' +
  1325. '#iframe_body #dir_list td.name::before, #iframe_body #dir_list a::before, #iframe_body #parent'+
  1326. '{ float:left; }' + // float
  1327. '#iframe_body #open_in_sidebar { float:right; }' +
  1328. '#iframe_body { font-family:'+ $settings.UI_font +'; }' + // fonts
  1329. '#iframe_body { font-size:'+ parseFloat($settings.UI_font_size) * 0.875 + $settings.UI_font_size.replace(/\d*/,'') +'; }' +
  1330. '#iframe_body #dir_list, #iframe_body #thead { font-size: 1em; }' +
  1331. 'td.name, td.name a::before, td.size, td.date { font-variant-numeric: tabular-nums; }'+
  1332. '#iframe_body, #iframe_body #dir_list { height:100%; }' + // height
  1333. '#iframe_body #content_source { height:inherit; }' +
  1334. '#iframe_body #thead { height:2em; max-height:2em; }' +
  1335. '#iframe_body #tbody tr { line-height:1.5; }' + // line-height
  1336. 'html, body, #iframe_body { margin:0; }' + // margin
  1337. '#iframe_body .dir::before, #iframe_body .file > img{ margin-inline-end: 6px; }' +
  1338. '#iframe_body #dir_list tr, #iframe_body #tbody tr:hover { outline:0; }' + // outline
  1339. '#iframe_body, #iframe_body #dir_list, .details.date, .details.kind'+
  1340. '{ overflow:hidden; text-overflow: ellipsis; }' + // overflow
  1341. '#iframe_body #dir_list #tbody { overflow:auto; }' +
  1342. 'html, :root, #iframe_body, body { padding:0; }' + // padding
  1343. '#iframe_body #tbody tr td,#iframe_body #thead tr th{ padding-top:3px; }' +
  1344. '#iframe_body #tbody tr td { padding-right: 6px; }' +
  1345. '#iframe_body #tbody tr td,#iframe_body #thead tr th{ padding-bottom:3px; }' +
  1346. '#change_dirs span a, #iframe_body #tbody tr td.details.kind { padding-right: 16px; }' +
  1347. '#iframe_body td.details { padding-left: 6px; }' +
  1348. '#change_dirs span a { padding-left: 16px; }' +
  1349. '#parent th, #tbody tr td.name { padding-left:1em; }' +
  1350. '#iframe_body #dir_list, #iframe_body #dir_list tr td.name a::before'+
  1351. '{ position:relative; }' + // position
  1352. '#iframe_body, #iframe_body #dir_list #tbody { position:absolute; right:0; bottom:0; left:0; }' +
  1353. '#iframe_body th { text-align:center; }' + // text-align
  1354. '#iframe_body th:last-of-type, #iframe_body td.details { text-align:right; }' +
  1355. '#iframe_body th:first-of-type { text-align:left; }' +
  1356. '#iframe_body #open_in_sidebar { text-align:right; }' +
  1357. '#iframe_body a, #iframe_body a:hover, #iframe_body td:hover'+
  1358. '{ text-decoration:none !important; }' + // text-decoration
  1359. '#iframe_body a.icon { text-indent:2px; }' + // text-indent
  1360. '#iframe_body #thead { user-select:none; -webkit-user-select:none; }' +
  1361. '#iframe_body td.details { vertical-align:top; }' +
  1362. '#change_dirs span { width:50%; }' +
  1363. 'html, #iframe_body, #iframe_body #dir_list, #iframe_body #dir_list tr'+
  1364. '{ width:100%; max-width:100%; min-width:100%; }' +
  1365. '#iframe_body #dir_list td:not(:first-child) { width:unset; }' +
  1366. '#iframe_body td:not(.name) { white-space:pre; }'
  1367. ;
  1368.  
  1369. // ADD STYLES
  1370. const $font_styles = document.createElement('style');
  1371. const $font_grid_styles = document.createElement('style');
  1372.  
  1373. function addStyles(el) {
  1374. el.find('style, link[rel="stylesheet"], link[href$="css"]').remove(); // remove any existing stylesheets
  1375. el.append('<style>'+ $main_style_rules +'</style>');
  1376. el.append('<style>'+ $gecko_style_rules +'</style>');
  1377. el.append($font_styles); // empty until font is previewed
  1378. el.append($font_grid_styles); // empty until font grid is made
  1379. el.append('<style>'+ $text_editing_style_rules +'</style>');
  1380. el.append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css"></link>');
  1381. }
  1382. // ***** END STYLES ***** //
  1383.  
  1384. // ***** INDEX PREP ***** //
  1385. //
  1386. function getIndexType() {
  1387. // Try to determine index type from parent directory link container,
  1388. // with fallbacks for indexes that don't have parent directories,
  1389. // or for parent directory links that aren't siblings or ancestors of the index itself.
  1390. let parentLinkParent; // Possible elements: pre, li, td, th, div -- used to determine index type
  1391. // Try to find parent directory link:
  1392. let parentLink = $('a:contains("Parent Directory"), a:contains("parent directory"), a[href="../"], a[href="/"], a[href^="?"], img[alt*="PARENTDIR"]');
  1393. if ( parentLink.length === 0 ) {
  1394. parentLinkParent = $('body').find('> ul li, > pre, > table:last-of-type tr td');
  1395. } else {
  1396. parentLinkParent = parentLink.parent(); // use original found parentLink
  1397. }
  1398. // If no parentLinkParent found, type = error; else return parent node name
  1399. let nodeName = ( parentLinkParent[0] !== undefined ? parentLinkParent[0].nodeName.toLowerCase() : '');
  1400. if ( parentLinkParent.length === 0 ) {
  1401. nodeName = 'error';
  1402. } else if ( $protocol.startsWith('file') ) {
  1403. if ( navigator.userAgent.indexOf('Firefox') > 0 ) {
  1404. nodeName = 'gecko';
  1405. }
  1406. }
  1407. let types = {'gecko':'gecko','li':'list','pre':'pre','th':'table','td':'table','div':'default','error':'error'};
  1408. let type = types[nodeName];
  1409.  
  1410. if ( type === 'table' ) {
  1411. parentLinkParent.closest('table').addClass('PARENTTABLE');
  1412. }
  1413. if ( type === 'list' ) {
  1414. parentLink.closest('ul').addClass('PARENTLIST');
  1415. }
  1416. return type;
  1417. }
  1418.  
  1419. // Return Index items, Index type, remove parent directory link, and add body class.
  1420. function getIndexItems(el) {
  1421. const type = getIndexType();
  1422. let items;
  1423.  
  1424. switch(type) {
  1425. case 'gecko':
  1426. $(el).addClass('is_converted_gecko');
  1427. items = $('body').find('> table > tbody');
  1428. break;
  1429. case 'list':
  1430. $(el).addClass('is_converted_list');
  1431. items = $('body').find('> ul');
  1432. break;
  1433. case 'pre':
  1434. $(el).addClass('is_converted_pre');
  1435. items = $('body').find('> pre').html();
  1436. break;
  1437. case 'table':
  1438. case 'td':
  1439. $(el).addClass('is_converted_table');
  1440. if ( $('table.PARENTTABLE > tbody').length === 1 ) {
  1441. items = $('table.PARENTTABLE > tbody');
  1442. } else {
  1443. items = $('table.PARENTTABLE'); // tables without tbody
  1444. }
  1445. break;
  1446. case 'default': // local chrome default
  1447. $(el).addClass('is_default');
  1448. items = $('body').find('> table').find('> tbody');
  1449. break;
  1450. case 'error': // error
  1451. $(el).addClass('is_error');
  1452. items = $('body').html();
  1453. break;
  1454. }
  1455. return [items,type];
  1456. }
  1457.  
  1458. // Index Prep: convert rows and return array of rows, with link, size, date-modified
  1459. function convertIndexItems(type,items) {
  1460. let converted = [];
  1461. switch(type) {
  1462. case 'gecko':
  1463. converted = convertGeckoType(items);
  1464. break;
  1465. case 'list':
  1466. converted = convertListType(items);
  1467. break;
  1468. case 'pre':
  1469. converted = convertPreType(items);
  1470. break;
  1471. case 'table':
  1472. case 'default': // local chrome indexes
  1473. converted = convertTableType(type,items);
  1474. break;
  1475. case 'error':
  1476. converted = convertErrorType(items);
  1477. break;
  1478. }
  1479. return converted;
  1480. }
  1481. // Index Prep: convert list type function
  1482. function convertGeckoType(items) {
  1483. let preppedIndex = [];
  1484. const rows = Array.from(items.find('> tr'));
  1485. for ( let row of rows ) {
  1486. let preppedRow = [];
  1487. let cellContents = '';
  1488. let cells = Array.from( $(row).find('> td') );
  1489. let link = ($(cells).find('a').attr('href'));
  1490. for ( let cell of cells ) {
  1491. cellContents = cell.innerText;
  1492. cellContents = ( cellContents !== undefined ? cellContents.trim() : '');
  1493. preppedRow.push(cellContents);
  1494. }
  1495. preppedRow[1] = preppedRow[1].replace(' KB','000'); // convert reported size in KB to total bytes
  1496. preppedRow[2] = preppedRow[2] + ' '+ preppedRow[3];
  1497. preppedRow = preppedRow.slice(1,-1);
  1498. if ( link.length > 0 && link !== '/' && link !== '../' ) {
  1499. preppedRow.unshift(link);
  1500. }
  1501. if ( preppedRow.length > 0 ) { preppedIndex.push(preppedRow); }
  1502. }
  1503. return preppedIndex;
  1504. }
  1505. // Index Prep: convert list type function
  1506. function convertListType(items) {
  1507. let preppedIndex = [];
  1508. const rows = Array.from(items.find('li'));
  1509. for ( let row of rows ) {
  1510. if ( row.innerHTML.indexOf('Parent Directory') === -1 ) {
  1511. let preppedRow = [];
  1512. let link = $(row).find('a').attr('href');
  1513. row = row.innerHTML.replace(/<a .+?<\/a>\s*/,'');
  1514. let cells = row.split(' ');
  1515. for ( let cell of cells ) {
  1516. if ( cell.trim().length > 0 ) {
  1517. preppedRow.push(cell);
  1518. }
  1519. }
  1520. if ( link.length > 0 && link !== '/' && link !== '../' ) {
  1521. preppedRow.unshift(link);
  1522. }
  1523. if ( preppedRow.length > 0 ) {
  1524. preppedIndex.push(preppedRow);
  1525. }
  1526. }
  1527. }
  1528. return preppedIndex;
  1529. }
  1530. // Index Prep: convert pre type function
  1531. function convertPreType(items) {
  1532. let preppedIndex = [];
  1533. items = items.replace(/<a /g,' <a ').replace(/<\/a>/g,'</a> ') // ensure two spaces after file links
  1534. .replace(/\[\s*?\]/g,'[]'); // remove empty 'alt=[ ]'
  1535. const rows = items.split('\n');
  1536. const spaces = /\s{2,}/; // assumes pre type only uses spaces between "columns"
  1537.  
  1538. for ( let row of rows ) {
  1539. let preppedRow = [];
  1540. row = row.replace(/(<a[^>]+?>).+?<\/a>/g,'$1'); // remove link display name because some have 2+ spaces, leading to incorrect split for cells array
  1541. let cells = row.split(spaces);
  1542. let link;
  1543. for ( let cell of cells ) {
  1544. if ( cell.trim().length > 0 ) {
  1545. if ( cell.indexOf('href="') > 0 && cell.search(/href="[?|\/"]|Parent Directory/) === -1 ) {
  1546. link = $(cell).attr('href');
  1547. } else {
  1548. if ( cell.search(/href="|<img |<hr>/) === -1 ) {
  1549. preppedRow.push(cell);
  1550. }
  1551. }
  1552. }
  1553. }
  1554. if ( link !== undefined ) { preppedRow.unshift(link); } // add link to front of preppedRow
  1555. if ( preppedRow.length > 1 ) { preppedIndex.push(preppedRow); }
  1556. }
  1557. return preppedIndex;
  1558. }
  1559. // Index Prep: convert table type function
  1560. function convertTableType(type,items) { // for local chrome indexes and server-generated table-type indexes
  1561. let preppedIndex = [];
  1562. const rows = Array.from(items.find('> tr:not(.PARENT)'));
  1563. for ( let row of rows ) {
  1564. if (row.innerText.search(/Parent Directory/) === -1 ) {
  1565. let preppedRow = [];
  1566. let cells = Array.from( $(row).find('td') );
  1567. let link = $(cells).find('a').attr('href');
  1568. for ( let cell of cells ) {
  1569. cell = cell.innerHTML.trim();
  1570. if ( cell.length > 0 && cell.search(/^&nbsp;$|href="|<img /m) === -1 ) {
  1571. preppedRow.push( cell );
  1572. }
  1573. }
  1574. if ( link !== undefined ) { preppedRow.unshift(link); }
  1575. if ( preppedRow.length > 1 ) { preppedIndex.push(preppedRow); } // preppedRow.length > 2 in order to omit parent directory row
  1576. }
  1577. }
  1578. return preppedIndex;
  1579. }
  1580. // Index Prep: convert error pages (page not found, etc.)
  1581. function convertErrorType(items) {
  1582. items = items.replace(/ style="[^"]*?"/g,'').replace(/<hr>/g,'');
  1583. items = '<div id="error_message"><div id="error_message_icon"></div>'+ items +'</div>';
  1584. return items;
  1585. }
  1586.  
  1587. // Index Prep: Build new Index from prepped rows
  1588. function buildNewIndex(preppedIndex,sort) {
  1589. let newIndexItems = [];
  1590. let i = 0;
  1591. for ( let row of preppedIndex ) {
  1592. // Get row attrs and text
  1593. const rowLink = row[0] !== undefined ? row[0].replace(/&amp;/g,'&') : '';//.replace(//,''); // decode some reserved characters
  1594. const rowName = getItemName(rowLink).replace(/^\s/m,'\&nbsp;').replace(/^\//m,'').replace(/([-_——])/g,'$1<wbr>'); // display name, with word breaks added after unbreakable chars
  1595. const rowSortName = getItemName(rowLink).replace(/^\//m,'').replace('/','').toLocaleLowerCase();
  1596. const sizesAndDates = getItemSizeAndDate(row);
  1597. const rowSize = sizesAndDates[0];
  1598. const rowSortSize = sizesAndDates[1];
  1599. const rowDate = sizesAndDates[2];
  1600. const rowSortDate = sizesAndDates[3];
  1601. const rowExt = getItemExt(rowLink);
  1602. const rowSortKind = getItemKind(rowExt);
  1603. const rowKind = rowSortKind.slice(0,1).toUpperCase() + rowSortKind.slice(1);
  1604. const rowClasses = getItemClasses(rowName,rowSortKind,rowExt);
  1605. // Assemble row elements
  1606. let newRow = $('<tr></tr>').attr('id','rowid-'+ i).addClass(rowClasses).attr('data-kind',rowSortKind).attr('data-ext',rowExt);
  1607. const checkbox = ( rowClasses.indexOf('media') > 0 ? $('<input type="checkbox" tabindex="-1" checked="true" />') : '' );
  1608. const nameSpan = $('<span></span>').append(checkbox, rowName);
  1609. const cellLink = $('<a></a>').addClass('icon').attr('href',rowLink).append(nameSpan);
  1610. const cellName = $('<td></td>').addClass('name').attr('data-name',rowSortName).append(cellLink);
  1611. const cellSize = $('<td></td>').addClass('size details').attr('data-size',rowSortSize).append(rowSize);
  1612. const cellDate = $('<td></td>').addClass('date details').attr('data-date',rowSortDate).append(rowDate);
  1613. const cellKind = $('<td></td>').addClass('kind details').attr('data-kind',rowSortKind).append(rowKind);
  1614. const cellExt = $('<td></td>').addClass('ext details').attr('data-ext',rowExt);
  1615. // Assemble row
  1616. newRow.append(cellName, cellSize, cellDate, cellKind, cellExt);
  1617. newIndexItems.push(newRow[0]);
  1618. i++;
  1619. }
  1620. if ( sort === undefined ) { sort = getQuery('sort_by'); }
  1621. let sortedIndexItems = sortDirList($(newIndexItems), 'sort_by_'+ sort, 1); // initial sort
  1622. return sortedIndexItems;
  1623. }
  1624. // Index Prep: get row name
  1625. function getItemName(link) {
  1626. let name;
  1627. try { name = decodeURIComponentSafe(link); }
  1628. catch (error) { name = link.replace(/%20/g,' ').replace(/\s{2,}/,' '); }
  1629.  
  1630. if ( name.split('/').length > 2 ) { // get name only if x = full path
  1631. let arr = name.split('/');
  1632. if ( name.startsWith('/') && name.endsWith('/') ) { // dirs
  1633. name = arr[arr.length - 2] + '/';
  1634. } else {
  1635. name = arr[arr.length - 1]; // files
  1636. }
  1637. }
  1638. return name;
  1639. }
  1640. // Index Prep: get row classes
  1641. function getItemClasses(name,kind,ext) {
  1642. let itemClasses = [];
  1643. itemClasses.push(kind);
  1644. if ( ext.search(/dir|app/) === -1 ) {
  1645. itemClasses.push('file');
  1646. }
  1647. if ( ext === 'app' ) {
  1648. if ( $settings.apps_as_dirs === false ) {
  1649. itemClasses.push('file');
  1650. } else {
  1651. itemClasses.push('dir');
  1652. }
  1653. }
  1654. if ( name.endsWith('symlink') || name.endsWith('alias') || name.endsWith('symbolic link') ) {
  1655. itemClasses.push('alias');
  1656. }
  1657. if ( name.indexOf('.') === 0 ) {
  1658. itemClasses.push('invisible');
  1659. }
  1660. if ( !JSON.stringify($row_types).match( escapeStr(ext) ) ) { // else classify as "other" if extension is not in $row_types.
  1661. itemClasses.push('other'); //itemType = 'Other'; itemKind = 'other';
  1662. } else if ( kind === '' ) {
  1663. // itemClasses.push('code'); //itemType = 'Code'; itemKind = 'code';
  1664. } else {
  1665. itemClasses.push(ext);
  1666. }
  1667. if ( $row_settings.ignore.includes( ext ) ) {
  1668. itemClasses.push('ignore');
  1669. }
  1670. if ( $row_settings.exclude.includes( ext ) ) {
  1671. itemClasses.push('exclude');
  1672. }
  1673. if ( kind === 'audio' || kind === 'video' ) {
  1674. itemClasses.push('media');
  1675. }
  1676. itemClasses = Array.from(new Set(itemClasses)); // remove dupe classes
  1677. return itemClasses.join(' ');
  1678. }
  1679. // Index Prep: get formatted row size and date
  1680. function getItemSizeAndDate(cells) {
  1681. let sizesAndDates = [];
  1682. let rowDisplaySize, rowSortSize, rowDisplayDate, rowSortDate;
  1683. if ( cells.length > 1 ) {
  1684. if ( cells[1].search(/[-:\/]/) !== -1 ) { // test for typical date/time separators.
  1685. rowDisplayDate = cells[1];
  1686. rowDisplaySize = cells[2];
  1687. } else {
  1688. rowDisplayDate = cells[2];
  1689. rowDisplaySize = cells[1];
  1690. }
  1691. }
  1692. // size
  1693. let sizeUnits = /[BYTES|B|K|KB|MB|GB|TB|PB|EB|ZB|YB]/;
  1694. if ( rowDisplaySize === undefined || rowDisplaySize === '' || rowDisplaySize === '-' || rowDisplaySize === ',' ) {
  1695. rowDisplaySize = '&mdash;'; rowSortSize = '0'; // if no size supplied, use these defaults
  1696. } else {
  1697. rowSortSize = getItemSortSize(rowDisplaySize);
  1698. rowDisplaySize = ( rowDisplaySize.toUpperCase().endsWith('B') ? rowDisplaySize : rowDisplaySize + 'B');
  1699. if ( !rowDisplaySize.toUpperCase().match(sizeUnits) ) { // if provided size is only numeric
  1700. rowDisplaySize = formatBytes(rowDisplaySize,1);
  1701. } else {
  1702. rowDisplaySize = rowDisplaySize.replace('K','k').replace(/(\d+)\s*([A-z])/,'$1 $2');
  1703. }
  1704. }
  1705. // date
  1706. if ( rowDisplayDate === undefined || rowDisplayDate === '' || rowDisplayDate === '-' ) {
  1707. rowDisplayDate = '&mdash;'; rowSortDate = '0';
  1708. } else {
  1709. rowSortDate = getItemDate(rowDisplayDate);
  1710. }
  1711. sizesAndDates.push(rowDisplaySize,rowSortSize,rowDisplayDate,rowSortDate);
  1712. return sizesAndDates;
  1713. }
  1714. // Index Prep: get row size for sorting
  1715. function getItemSortSize(val) {
  1716. let sortSize;
  1717. let values = val.replace(/(\d+)\s*([A-z])/,'$1 $2').split(' ');
  1718. let size = values[0];
  1719. let unit = values[1];
  1720. if ( unit !== undefined ) { unit = unit.toUpperCase(); }
  1721. const factor = { '':1, B:1, K:1000, KB:1000, M:1000000, MB:1000000, G:1000000000, GB:1000000000, T:1000000000000, TB:1000000000000, P:1000000000000000, PB:1000000000000000, E:1000000000000000000, EB:1000000000000000000, Z:1000000000000000000000, ZB:1000000000000000000000 }; // unit to file size
  1722. sortSize = size * factor[unit]; // convert byte size to multiplication factor
  1723. return sortSize;
  1724. }
  1725. // convert numeric sizes to display format
  1726. function formatBytes(val, decimals) {
  1727. if (val === 0) return '0 Bytes';
  1728. const k = 1024;
  1729. const dm = decimals < 0 ? 0 : decimals;
  1730. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  1731. const i = Math.floor(Math.log(val) / Math.log(k));
  1732. return parseFloat((val / Math.pow(k, i)).toFixed(dm)) +' '+ sizes[i];
  1733. }
  1734. // process date
  1735. function processDate(match,p1,p2,p3) { //date formats: 2017-10-09 13:12 || 2015-07-25T02:02:57.000Z || 12-Mon-2017 21:11
  1736. const mo = 'JanFebMarAprMayJunJulAugSepOctNovDec'.indexOf(p2)/3 + 1; // e.g., convert month into number, or use number
  1737. return p3 +'-'+ mo +'-'+ p1;
  1738. }
  1739. // Index Prep: get row date 2015-07-25T02:22:00.000Z
  1740. function getItemDate(val) {
  1741. let sortDate = val.replace(/^(\d{2})-(\w{3})-(\d{4})/m, processDate) // convert Month to number
  1742. .replace(/\b(\d{1})[-:\/]/g,'0$1/') // add leading 0 for single digit numbers
  1743. .replace(/(\d{2})\/(\d{2})\/(\d{2}),/,'$3$1$2') // reorder MM/DD/YY dates
  1744. .replace(/-|:|\s+|\//g,''); // remove spacing characters
  1745. return sortDate;
  1746. }
  1747. // Index Prep: get row kind
  1748. function getItemKind(ext) {
  1749. let kind = '';
  1750. if ( ext === 'dir' || ext === 'app' ) {
  1751. kind = ext;
  1752. } else {
  1753. for ( let types in $row_types ) {
  1754. if ( $row_types[types].includes( ext ) ) {
  1755. kind = types;
  1756. return kind;
  1757. }
  1758. }
  1759. }
  1760. if ( kind === '' ) { kind = 'other'; }
  1761. return kind;
  1762. }
  1763. // Index Prep: get row extension
  1764. function getItemExt(link) {
  1765. let ext = '';
  1766. if ( link.endsWith('app/') || link.endsWith('exe') ) {
  1767. ext = 'app';
  1768. } else if ( link.endsWith('/') ) {
  1769. ext = 'dir';
  1770. } else if ( link.indexOf('.') < 0 ) { // if no '.' in link, ...
  1771. ext = link.slice(link.lastIndexOf('/') + 1).toLowerCase();
  1772. } else { // find the last . and get the remaining characters
  1773. ext = link.slice(link.lastIndexOf('.') + 1).toLowerCase();
  1774. }
  1775. return ext;
  1776. }
  1777. // END INDEX PREP
  1778. // ***** MAKE NEW INDEX ***** //
  1779. function makeNewIndex(el,sort) {
  1780. const indexItems = getIndexItems(el);
  1781. const items = indexItems[0];
  1782. const type = indexItems[1];
  1783. const convertedIndex = convertIndexItems( type, items ); // = array of rows: ["link","date","size"]
  1784. if ( type === 'error' ) {
  1785. return [convertedIndex];
  1786. } else {
  1787. let newIndex = buildNewIndex( convertedIndex, sort );
  1788. return [newIndex];
  1789. }
  1790. }
  1791. function appendNewIndex(body_top) { // setUpUI();
  1792. const newIndex = makeNewIndex(body_top);
  1793. $dir_list_body.empty().append( newIndex);
  1794. $dir_list.find('#stats').html(getIndexStats($dir_list.find('#tbody tr')));
  1795. }
  1796. // get and set index stats
  1797. function getIndexStats(el) {
  1798. const total = el.length;
  1799. const dirs = el.filter('.dir').length;
  1800. const files = el.filter('.file').length;
  1801. const stats = total +' items: '+ dirs +' directories, '+ files +' files';
  1802. return stats;
  1803. }
  1804. // ***** END DIR_LIST SETUP ***** //
  1805.  
  1806. // ***** UI SETUP ***** //
  1807. // Build UI: Append all assembled elements to $body
  1808. function buildUI() {
  1809. if ( window.self === window.top ) { // if it's an iframe...
  1810. $('head').prepend('<meta charset="utf-8">');
  1811. let prefix = 'data:image/png;base64,';
  1812. // let favicon = 'iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAgMAAADXB5lNAAAACVBMVEUmRckzmf+ZzP9yAsYbAAAAAXRSTlMAQObYZgAAADhJREFUeAFjoAYIBQEMAQd0gQB0gRB0gVAMAQd0gQB0gRB0AQSgkUDUKiSwFFlgVGBUgE6pcJAAANNZhFSKf6iqAAAAAElFTkSuQmCC';
  1813. let favicon = 'iVBORw0KGgoAAAANSUhEUgAAAIAAAACAAgMAAAC+UIlYAAAACVBMVEUmRcmZzP8zmf8pVcWPAAAAAXRSTlMAQObYZgAAAFBJREFUeF7tyqERwDAMBEE3mX5UiqDmqwwziTPHjG7xrmzrLFtRaApDIRiKQlMYCsFQFJrCUAiGotAU5hTA1WB4fhkMBsOJwWAwgHvB8CHpBcTbpxy4RZNvAAAAAElFTkSuQmCC';
  1814. if ( $location.startsWith('file') ) { $('head').prepend('<link href="'+ prefix + favicon +'" rel="icon" sizes="16x16" />'); }
  1815. $('head #title').removeAttr('id'); // not sure where this id is being added, but it must be removed...
  1816. $('body').attr('id','top').attr('lang','en').find('script').remove();
  1817. addStyles( $('head') );
  1818. appendNewIndex($('body'));
  1819. $('body').empty().append($main_content);
  1820. } else {
  1821. $('body').attr('id','iframe_body');
  1822. }
  1823. }
  1824. buildUI();
  1825.  
  1826. // Define additional UI Element refs
  1827. const $body = $('body#top');
  1828. const $iframe_body = $('body#iframe_body');
  1829. const $iFrame_head = $iframe_body.prev('head');
  1830. const $dir_list_row = $dir_list_body.find('> tr');
  1831. const $audio_files = $dir_list_body.find('.audio');
  1832. const $font_files = $dir_list_body.find('.font');
  1833. const $image_files = $dir_list_body.find('.image');
  1834. const $media_files = $dir_list_body.find('.media');
  1835. const $video_files = $dir_list_body.find('.video');
  1836. function $selected_file() { return $dir_list_body.find('.selected'); }
  1837. function $playing_file() { return $dir_list_body.find('.playing'); }
  1838.  
  1839. // UI Setup: build UI and add body classes and other initial settings
  1840. function setupUIprefs() {
  1841. for ( let key in $settings ) {
  1842. if ( getQuery(key) === 'true' ) {
  1843. $body.addClass(key);
  1844. } else { // non-boolean settings and others
  1845. if ( key === 'theme' ) { $body.addClass( 'theme_'+ getQuery('theme') ); }
  1846. if ( key === 'sort_by' ) {
  1847. $body.addClass( 'sort_by_'+ getQuery(key) );
  1848. $('#sorting').find('th[id="sort_by_'+ getQuery(key) +'"]').addClass('up');
  1849. }
  1850. if ( key === 'default_text_view' ) {
  1851. if ( getQuery(key) === 'source_text' ) { $body.addClass('source_text'); } else { $body.addClass('preview_text'); }
  1852. }
  1853. if ( getQuery('toggle_sidebar') === 'true' ) { $body.addClass( 'has_hidden_sidebar' ); }
  1854. }
  1855. }
  1856. if ( navigator.vendor.indexOf('Google') > -1 ) { $body.addClass('is_chrome'); }
  1857. if ( navigator.userAgent.indexOf('Firefox') > -1 ) { $body.addClass('is_gecko'); }
  1858. if ( navigator.vendor.indexOf('Apple') === 0 ) { $body.addClass('is_safari'); }
  1859. if ( $audio_files.length > 0 ) { $body.add($dir_list).addClass('has_audio has_media'); }
  1860. if ( $font_files.length > 0 ) { $body.addClass('has_fonts'); }
  1861. if ( $image_files.length > 0 ) { $body.addClass('has_images'); }
  1862. if ( $video_files.length > 0 ) { $body.add($dir_list).addClass('has_video has_media'); }
  1863. // UI Setup: show invisibles
  1864. if ( navigator.platform.indexOf('Win') > -1 || $location.indexOf('file:') < 0 ) {
  1865. $('#show_invisibles').closest('label').hide();
  1866. } else if ( $body.hasClass('show_invisibles') ) {
  1867. $('#show_invisibles').attr('checked','checked');
  1868. }
  1869. }
  1870. // Get DOMTokenList of body classes
  1871. function getClassList(id) { return document.getElementById(id).classList; }
  1872. //
  1873. function setUpUI() {
  1874. if ( window.self === window.top) {
  1875. setupUIprefs();
  1876. initMedia();
  1877. autoSelectFile();
  1878. autoLoadCoverArt();
  1879. setContentTitle();
  1880. setContentHeight();
  1881. } else {
  1882. setUpIframeUI( getQuery('enable_text_editing') );
  1883. }
  1884. document.title = 'Index of: '+ $location;
  1885. }
  1886. setUpUI();
  1887.  
  1888. // SET UI TO DEFAULT SETTINGS: remove queries;
  1889. function defaultSettings() {
  1890. let $location = window.location.href;
  1891. $location = $location.slice(0,$location.lastIndexOf('?'));
  1892. window.location.assign($location);
  1893. }
  1894. $('#default_settings').on('click', function(e) {
  1895. e.preventDefault();
  1896. e.stopPropagation();
  1897. $('#bookmarks').hide();
  1898. if (window.confirm( 'Are you sure you want to reset all your temporary UI settings to the defaults in your user_settings?\nThis action cannot be undone.' ) ) {
  1899. defaultSettings();
  1900. }
  1901. });
  1902. // EXPORT SETTINGS
  1903. function saveSettings(filename, data) {
  1904. const blob = new Blob([data], {type: 'text/html'});
  1905. const elem = window.document.createElement('a');
  1906. elem.href = window.URL.createObjectURL(blob);
  1907. elem.download = filename;
  1908. document.body.appendChild(elem);
  1909. elem.click();
  1910. document.body.removeChild(elem);
  1911. URL.revokeObjectURL(blob);
  1912. }
  1913. $('#export_settings').on('click',function(e) {
  1914. e.preventDefault();
  1915. e.stopPropagation();
  1916. $('#bookmarks').hide();
  1917. const $settings_string = ( JSON.stringify($settings,null,'\t'));
  1918. saveSettings('settings.txt',$settings_string);
  1919. });
  1920.  
  1921. // Click Menu Link (with warning)
  1922. function setLocation(link) { window.location = link; }
  1923. $('#parent_dir_menu,#parents_dir_menu + .menu,#bookmarks .bookmark').on('click','a',function(e) {
  1924. e.preventDefault();
  1925. if ( $(this).attr('href').indexOf('file://') > -1 && $protocol !== 'file:' ) {
  1926. $body.addClass('has_warning').find('#warnings').addClass('local');
  1927. } else {
  1928. showWarning( 'setLocation', thisLink($(this)) );
  1929. }
  1930. });
  1931. // Show Menus
  1932. function showMenus(el) {
  1933. let $position = $(el).position();
  1934. $(el).find('> ul').css({'top':$position.top + $(el).innerHeight() + 'px'}).toggle().parent('td').siblings('td').find('.menu').hide();
  1935. }
  1936. $('#parents_dir_menu').add('#bookmarks_menu').parent('td').on('click',function(e) {
  1937. e.stopPropagation();
  1938. showMenus(this);
  1939. });
  1940. // Hide Menus
  1941. $(document).on('click', function() { $('.menu').hide(); });
  1942.  
  1943. // Toggle UI Preferences
  1944. function toggleUIpref(prefID) {
  1945. let prefClass = prefID;
  1946. if ( prefID === 'split_view' ) {
  1947. sendMessage('iframe','split_view');
  1948. }
  1949. if ( prefID.startsWith('sort_by') ) {
  1950. $body.removeClass('sort_by_default sort_by_name sort_by_size sort_by_date sort_by_kind sort_by_ext');
  1951. $('#bookmarks').hide(); // don't hide menus after click?
  1952. }
  1953. if ( prefID.startsWith('theme') ) {
  1954. prefID = ( $body.hasClass('theme_dark') ? 'theme_dark' : 'theme_light' );
  1955. prefClass = 'theme_dark theme_light';
  1956. }
  1957. if ( prefID.endsWith('text') ) {
  1958. prefClass = 'preview_text source_text';
  1959. sendMessage('iframe','default_text_view');
  1960. }
  1961. toggleQuery(prefID);
  1962. $body.toggleClass(prefClass);
  1963. setContentHeight();
  1964. scrollThis('tbody','selected',false); // true = instant scroll
  1965. if ( prefID === 'enable_text_editing' ) {
  1966. $('.selected.text, .selected.markdown').click();
  1967. }
  1968. }
  1969. // Click Toggle UI Pref elements
  1970. $('.toggle_UI_pref').on('click',function(e) {
  1971. if ( !$(this).is('input') ) {
  1972. e.preventDefault(); // allow checkboxes to be checked
  1973. }
  1974. toggleUIpref( $(this).attr('id') );
  1975. });
  1976.  
  1977. // Toggle Sidebar
  1978. function toggleSidebar() {
  1979. $body.toggleClass('has_hidden_sidebar');
  1980. if ( $body.hasClass('has_hidden_sidebar') ) { setQuery('toggle_sidebar','true'); } else { removeQuery('toggle_sidebar'); }
  1981. setContentHeight();
  1982. scrollThis('tbody','selected',true); // true = instant scroll
  1983. }
  1984. $('#toggle_sidebar').on('click', function() {
  1985. toggleSidebar();
  1986. });
  1987.  
  1988. // RESIZE Sidebar/Content Pane
  1989. function resizeSidebar(f) {
  1990. f.stopPropagation();
  1991. const $sidebar_wrapper = $('#sidebar_wrapper');
  1992. const $startX = f.pageX;
  1993. let $window_width = window.innerWidth;
  1994. let $sidebar_width = $sidebar_wrapper.width();
  1995. $('#overlay').css({'display':'block','z-index':'1'});
  1996. $('#handle').css({'z-index':'9999'});
  1997. $body.css({'-webkit-user-select':'none','-moz-user-select':'none','user-select':'none'});
  1998.  
  1999. $(document).on('mousemove',function(e) {
  2000. e.stopPropagation();
  2001. e.preventDefault();
  2002. const $deltaX = e.pageX - $startX;
  2003. if ( e.pageX > 230 && e.pageX < $window_width - 200 ) {
  2004. $sidebar_wrapper.css({'width':$sidebar_width + $deltaX + 'px'});
  2005. $content_pane.css({'width':($window_width - $sidebar_width) - $deltaX + 'px'});
  2006. }
  2007. setContentHeight();
  2008. scrollThis('tbody','selected',false); // true = instant scroll
  2009. });
  2010. $(document).on('mouseup',function() {
  2011. $('#overlay').css({'display':'none','z-index':'unset'});
  2012. $('#handle').css({'z-index':'unset'});
  2013. $body.css({'-webkit-user-select':'unset','-moz-user-select':'unset','user-select':'unset'});
  2014. $(document).off('mousemove');
  2015. $sidebar_width = $sidebar_wrapper.width();
  2016. setQuery('width',$sidebar_width);
  2017. });
  2018. }
  2019. $('#handle').on('mousedown', function(f) {
  2020. f.stopPropagation();
  2021. resizeSidebar(f);
  2022. });
  2023.  
  2024. // ***** BASIC UI FUNCTIONS ***** //
  2025. // Get dir_list item row
  2026. function thisRow(x) {
  2027. return $(x).closest('#dir_list > tbody > tr').length > 0 ? $(x).closest('#dir_list > tbody > tr') : $(x).closest('#dir_list > li');
  2028. }
  2029. function thisID(x) {
  2030. return thisRow(x).attr('id');
  2031. }
  2032. // Get row link
  2033. function thisLink(x) {
  2034. return $(x).find('a').length > 0 ? $(x).find('a').attr('href') : $(x).attr('href');
  2035. }
  2036. // Get row name
  2037. function thisText(x) {
  2038. return $(x).find('a span').length > 0 ? decodeURIComponentSafe( $(x).find('a span').text().toLocaleLowerCase() ) : decodeURIComponentSafe( $(x).text().toLocaleLowerCase() );
  2039. }
  2040. // get row text
  2041. function thisExt(x) {
  2042. let $this_name = thisText(x);
  2043. return $this_name.endsWith('app/') ? 'app' : $this_name.endsWith('/') ? '/' : $this_name.lastIndexOf('.') === -1 ? undefined : $this_name.toLocaleLowerCase().slice( $this_name.lastIndexOf('.') + 1 );
  2044. }
  2045. function getElById(id) {
  2046. return $(document.getElementById(id) );
  2047. }
  2048.  
  2049. // SET CONTENT HEIGHT
  2050. function setContentHeight() {
  2051. let $title = $('#title');
  2052. // accommodate multi-line title names in preview pane
  2053. if ( $title.outerWidth() > ( $('#content_title').innerWidth() - 2 * $('#title_buttons_left').outerWidth() ) ) {
  2054. $title.css({'margin-top':'2em'});
  2055. } else {
  2056. $title.css({'margin-top':'0'});
  2057. }
  2058. let $window_height = window.innerHeight;
  2059. let $content_header_height = $('#content_header').outerHeight();
  2060.  
  2061. $('#sidebar, #main_content, #content_pane').css({'height':$window_height });
  2062. $dir_list.css({'height':$window_height - $('#sidebar_header').outerHeight(), 'max-height':$window_height - $('#sidebar_header').outerHeight() });
  2063. $dir_list_body.css({'bottom': $dir_list.find('tfoot').outerHeight(),'height': $dir_list.innerHeight() - $dir_list.find('tfoot').outerHeight(),'max-height': $dir_list.innerHeight() - $dir_list.find('tfoot').outerHeight() });
  2064. $('#iframe_body').find('#tbody').css({'top':$('#iframe_body').find('#thead').height() + 1 +'px'});
  2065. $content_font.css({'padding-bottom': $('#font_info th').outerHeight() +'px' });
  2066.  
  2067. $('#prev_track, #next_track, #close_audio').css({'height':$('#audio').height() }); // set height of audio controls
  2068. $('#content_container, #glyph_viewer').css({'top':$content_header_height +'px' });
  2069. $('#content_pane.has_image #content_image').css({'top':$('#content_header').height() });
  2070. setImageDimensions();
  2071. }
  2072. window.addEventListener('resize', setContentHeight );
  2073.  
  2074. // SET CONTENT TITLE
  2075. function setContentTitle(kind) {
  2076. let $title = $('#title span');
  2077. let $title_text = '';
  2078. if ( $playing_file().hasClass('audio') ) { // set audio player title
  2079. $('#content_audio_title').find('td').empty().text( $playing_file().find('td.name a').text() );
  2080. }
  2081. if ( $content_pane.hasClass('has_grid') ) { // set main title for other content
  2082. $title_text = $('#parents_dir_menu').find('> div').html().split('<wbr>').reverse()[1];
  2083. } else if ( $('#toggle_info').hasClass('selected') ) {
  2084. $title_text = 'Source of: '+ $current_dir_path;
  2085. } else if ( $body.hasClass('has_text') ) {
  2086. $title_text = 'Text Editor';
  2087. } else if ( $selected_file().hasClass('audio') ) {
  2088. return;
  2089. } else if ( !$selected_file().hasClass('audio') || $content_pane.hasClass('has_hidden_text') ) {
  2090. $title_text = $selected_file().not('.audio').find('td.name a span').text(); // Assemble title
  2091. }
  2092. if ( kind !== undefined && !['audio','dir','font','image','pdf','video'].includes(kind) ) {
  2093. $title.addClass('has_'+ kind); // add class for :before
  2094. }
  2095. $title.removeClass().empty().html($title_text); // set text
  2096. if ( $title.outerWidth() > ( $('#content_title').innerWidth() - 2 * $('#title_buttons_left').outerWidth() ) ) { $title.css({'margin-top':'2em'}); } else { $title.css({'margin-top':'0'}); }
  2097. }
  2098. // Get Image Dimensions
  2099. function getDimensions(link, callback) {
  2100. if ( link !== undefined ) {
  2101. let img = new Image();
  2102. img.src = link;
  2103. img.onload = function() { callback( this.width, this.height ); };
  2104. }
  2105. }
  2106. function setImageDimensions() {
  2107. if ( $content_pane.hasClass('has_image') || $content_pane.hasClass('has_zoom_image') ) {
  2108. let link = $content_image.find('img').attr('src');
  2109. // if ( link === undefined ) { link = thisLink(row); }
  2110. getDimensions( link, function( width, height ) {
  2111. $('#title').attr('data-after',' (' + width + 'px × ' + height + 'px) ('+ ( ($content_image.find('img').width()/width)*100 ).toFixed(1) +'%)');
  2112. });
  2113. } else {
  2114. $('#title').removeAttr('data-after'); // remove image dimensions
  2115. }
  2116. }
  2117. // Scroll Selected Items
  2118. function scrollThis(elID,className,bool) {
  2119. let $behavior = 'smooth';
  2120. if ( bool !== undefined ) { $behavior = 'instant'; }
  2121. let $block = ( $body.hasClass('is_gecko') ? 'start' : 'nearest' );
  2122. if ( document.getElementsByClassName(className).length !== undefined && document.getElementsByClassName(className).length > 0 ) {
  2123. document.getElementById(elID).getElementsByClassName(className)[0].scrollIntoView({ behavior:$behavior, block:$block, inline:'nearest' });
  2124. }
  2125. setContentHeight();
  2126. }
  2127.  
  2128. // ***** SORTING ***** //
  2129. function sortIndex(els,id,sortDirection) { // id = sort type
  2130. let sorted = [];
  2131. const newSort = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }); // needs to be above makeNewIndex()
  2132. sorted = els.removeClass('sorted').sort((a, b) => {
  2133. let aName, bName;
  2134. if ( $('body').hasClass('has_playlist') ) {
  2135. aName = $(a).attr('id');
  2136. bName = $(b).attr('id');
  2137. } else {
  2138. aName = $(a).find('td.name').data('name');
  2139. bName = $(b).find('td.name').data('name');
  2140. }
  2141. let aData = $(a).find('td[data-'+ id +']').data(id);
  2142. let bData = $(b).find('td[data-'+ id +']').data(id);
  2143. if ( sortDirection === 1 ) { // sort by detail data value, then by name (i.e., if data values are the same, sort by name)
  2144. if ( newSort.compare(aData, bData) === 0 ) {
  2145. return newSort.compare(aName, bName);
  2146. } else {
  2147. return newSort.compare(aData, bData);
  2148. }
  2149. } else { // reverse sort
  2150. if ( newSort.compare(bData, aData) === 0 ) {
  2151. return newSort.compare(bName, aName);
  2152. } else {
  2153. return newSort.compare(bData, aData);
  2154. }
  2155. }
  2156. });
  2157. sorted = sorted.sort((a, b) => { // add sorted style (rules between different rows)
  2158. if ( id === 'kind' || id === 'ext' && sortDirection === 1 ) {
  2159. if ( $(a).find('td[data-'+ id +']').data(id) !== $(b).find('td[data-'+ id +']').data(id) ) { $(a).addClass('sorted'); }
  2160. }
  2161. if ( id === 'kind' || id === 'ext' && sortDirection === -1 ) {
  2162. if ( $(b).find('td[data-'+ id +']').data(id) !== $(a).find('td[data-'+ id +']').data(id) ) { $(a).addClass('sorted'); }
  2163. }
  2164.  
  2165. });
  2166. return sorted;
  2167. }
  2168. // Sort the Dir List on click
  2169. function sortDirList(rows, id, sortDirection) {
  2170. const $sort_all = rows;
  2171. const $sort_dirs = $sort_all.filter('.dir:not(.app)');
  2172. const $sort_files = $sort_all.filter('.file,.app');
  2173. const $sort_id = id.slice(8);// === 'default' ? 'name' : id;
  2174. let $sorted = [];
  2175.  
  2176. if ( $sort_id === 'default' || ( $sort_id !== 'name' && $settings.dirs_on_top === true )) {
  2177. const $sorted_dirs = sortIndex($sort_dirs, $sort_id, sortDirection);
  2178. const $sorted_files = sortIndex( $sort_files, $sort_id, sortDirection );
  2179. if (sortDirection === 1) {
  2180. $sorted = $.merge($sorted_dirs,$sorted_files);
  2181. } else {
  2182. $sorted = $.merge($sorted_files,$sorted_dirs);
  2183. }
  2184. } else {
  2185. $sorted = sortIndex( $sort_all, $sort_id, sortDirection );
  2186. }
  2187. return $sorted;
  2188. }
  2189. // Sort on click
  2190. function clickSort(id) {
  2191. const el = $(getElById(id)); // id from th sort item = 'sort_by_xxx'
  2192. let sortDirection = ( el.hasClass('up') ? -1 : 1 ); // Only reverse sort order after clicking a sort column once.
  2193. // SORT EM!
  2194. let rows = ( $body.hasClass('has_playlist') ? $('#tbody').find('tr') : $dir_list_row );
  2195. const $sorted_index = sortDirList( rows, id, sortDirection );
  2196. $dir_list_body.empty().append($sorted_index);
  2197. $('div[id="'+ id +'"]').toggleClass('up').siblings().removeClass('up');
  2198. if ( $content_grid.hasClass('has_font_grid') ) { $('#show_font_grid').click(); }
  2199. if ( $content_grid.hasClass('has_image_grid') ) { $('#show_image_grid').click(); }
  2200. if ( $content_grid.hasClass('has_grid') ) { $('#grid_btn').click(); }
  2201. setContentHeight();
  2202. scrollThis('tbody','selected',false); // true = instant scroll
  2203. }
  2204. // Sort on clicking dir_list sort item
  2205. $('#sorting').on('click','div.sorting:not(.disabled)',function(e) {
  2206. e.preventDefault();
  2207. e.stopPropagation();
  2208. clickSort( $(this).attr('id') );
  2209. });
  2210. // Sort Menu: click the list header that contains the selected menu text.
  2211. $('#sort_menu').on('click','li:not(.disabled)',function(e) {
  2212. e.preventDefault();
  2213. e.stopPropagation();
  2214. $('#sorting div[id="sort_by_'+ $(this).attr('id') +'"]').click(); // click corresponding sidebar sort item
  2215. });
  2216. // ***** END SORTING ***** //
  2217. // ***** END BASIC UI FUNCTIONS ***** //
  2218.  
  2219. // ***** CONTENT PANE ***** //
  2220. // SELECT ROW on click and set classes for $content_pane
  2221. function selectThis(rowID) {
  2222. $('#toggle_info').removeClass('selected');
  2223. let row = $(getElById(rowID));
  2224. const $grid_selected = $content_grid.find('> div[data-id="'+ rowID +'"]');
  2225. if ( $content_pane.hasClass('has_grid') || $content_pane.hasClass('has_hidden_grid') ) { // Select corresponding grid item
  2226. row.addClass('selected').siblings().removeClass('selected hovered');
  2227. $grid_selected.addClass('selected').siblings().removeClass('selected');
  2228. } else { // remove classes from rows, but leave .audio with playing
  2229. if ( row.attr('id') === 'toggle_info' ) {
  2230. row.toggleClass('selected loaded');
  2231. $dir_list.find('#tbody .selected').removeClass('selected');
  2232. } else {
  2233. row.addClass('selected').siblings().removeClass('selected hovered');
  2234. }
  2235. }
  2236. }
  2237.  
  2238. //***** SHOW CONTENT *****//
  2239. function showAudio(rowID) {
  2240. let row = getElById(rowID);
  2241. if ( $content_video.hasClass('has_content') ) { $('#title span').empty(); }
  2242. closeMedia('video');
  2243. if ( row.hasClass('audio') ) { row.addClass('playing selected').siblings('.media').removeClass('playing selected'); }
  2244. $audio_player.attr('src', thisLink( row ) );
  2245. $content_pane.addClass('has_audio');
  2246. $('#content_audio_title').find('td').empty().text( $playing_file().find('td.name a').text() );
  2247. setContentHeight();
  2248. }
  2249.  
  2250. // showTextEditor();
  2251.  
  2252. // Show Grid
  2253. function showGrid() {
  2254. $content_pane.removeClass('has_hidden_grid').addClass('has_grid');
  2255. if ( $body.hasClass('has_text') ) { $body.toggleClass('has_text has_hidden_text'); }
  2256. closeMedia('video');
  2257. setContentTitle();
  2258. setContentHeight();
  2259. selectThis( $selected_file().attr('id') );
  2260. $('#grid_btn').addClass('has_grid');
  2261. }
  2262. // Show Hidden Editor or Grid
  2263. function showHiddenEditorOrGrid() {
  2264. if ( $content_pane.hasClass('has_hidden_grid') && !$body.hasClass('has_hidden_text') || $content_pane.hasClass('has_hidden_grid') && $body.hasClass('has_hidden_text') ) {
  2265. $content_pane.toggleClass('has_grid has_hidden_grid'); // show grid preferentially
  2266. } else if ( !$content_pane.hasClass('has_hidden_grid') && $body.hasClass('has_hidden_text') ) {
  2267. $body.toggleClass('has_text has_hidden_text');
  2268. }
  2269. }
  2270. // Hide Editor or Grid
  2271. function hideEditorOrGrid() {
  2272. if ( $body.hasClass('has_text') ) { $body.toggleClass('has_text has_hidden_text'); }
  2273. if ( $content_pane.hasClass('has_grid') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  2274. }
  2275. // showIndexSource();
  2276.  
  2277. // Show Font (and create font items)
  2278. function showFont(row,bool,sheet) { // bool = true if for show font grid, sheet defined at fontGridItems()
  2279. $content_font.addClass('has_font').removeClass('has_font_viewer');
  2280. let fontStyles = $font_styles.sheet;
  2281. const $font_family = thisText(row);
  2282. const $font_url = thisLink(row);
  2283. const $font_grid_item_el = $('<div class="font_grid_item" data-id="'+ $(row).attr('id') +'"></div>');
  2284. if ( bool === false ) {
  2285. if ( fontStyles.cssRules.length > 0 ) { fontStyles.deleteRule(0); } // delete previous @font-face rule
  2286. fontStyles.insertRule('@font-face { font-family: "'+ $font_family +'"; src: url("'+ $font_url +'"); }');
  2287. $content_font.css({ 'font-family':'"'+ $font_family +'"' }); // set content font style
  2288. } else {
  2289. let grid_item = $font_grid_item_el.clone();
  2290. const $display_name = $font_family;
  2291. sheet.insertRule('@font-face { font-family: "'+ $font_family +'"; src: url("'+ $font_url +'"); }');
  2292. grid_item.append('<p>'+ $display_name.toUpperCase() +'</p><h2 style=\'font-family: "'+ $font_family +'"\'; ><a href="'+ $font_url +'">'+ $display_name.slice(0,$font_family.lastIndexOf('.')) +'</a></h2>' );
  2293. return grid_item;
  2294. }
  2295. }
  2296.  
  2297. // OPEN FONT
  2298. /// opentype.js font parsing
  2299. $('#open_font_label').on('click',function(e) { $('.menu').hide(); });
  2300. // Open font
  2301. $('#bookmarks').on('change','#open_font',function(e) {
  2302. openFont(e);
  2303. });
  2304. function openFont(evt) {
  2305. if (window.File && window.FileReader && window.FileList && window.Blob && window.opentype ) {
  2306. let files = evt.target.files[0];
  2307. let reader = new FileReader();
  2308. reader.readAsArrayBuffer(files);
  2309. reader.onload = function(file) {
  2310. closeOtherContent();
  2311. closeGrid();
  2312. hideEditorOrGrid();
  2313. $content_pane.addClass('has_font');
  2314. $content_font.addClass('has_content has_font_viewer').removeClass('has_font');
  2315. parseFont(reader.result);
  2316. return true;
  2317. };
  2318. $('#open_font').val(''); // reset input to allow same font to be reopened immediately after closing.
  2319. } else {
  2320. alert('File APIs are not fully supported in this browser or opentype.js is not available.');
  2321. }
  2322. }
  2323. // Parse font
  2324. function parseFont(fontblob) {
  2325. let font = window.opentype.parse(fontblob);
  2326. getFontInfo(font);
  2327. let $glyphs_container = $('#glyphs_container');
  2328. $glyphs_container.empty();
  2329. let $glyph_container = $('<div class="glyph_container"></div>');
  2330. let $glyph_canvas = $('<canvas class="glyph" width="120" height="120"></canvas>');
  2331. let $glyph_info = $('<div class="glyph_info" style="font-size:0.75rem"></div>');
  2332. let $glyph_viewer = $('#glyph_viewer');
  2333. $glyph_viewer.data('data-font-name',font.names.fullName.en);
  2334. let glyphs = font.glyphs;
  2335. $content_font.data('data-glyphs',glyphs); // add glyphs data to $content_font
  2336. // Draw glyphs
  2337. for ( let i = 0; i < glyphs.length; i++ ) {
  2338. let glyph = glyphs.glyphs[i];
  2339. // GLyph width
  2340. let boundingBox = glyph.getBoundingBox();
  2341. let glyphWidth = boundingBox.x2 - boundingBox.x1;
  2342. let contextX = (60 - glyphWidth/24);
  2343. // Add glyph info and append elements
  2344. let glyphUnicode = ( glyph.unicode !== undefined ? '#'+ glyph.unicode : glyph.unicode );
  2345. let glyphContainer = $glyph_container.clone();
  2346. let glyphCanvas = $glyph_canvas.clone();
  2347. let glyphInfo = $glyph_info.clone();
  2348. glyphInfo.text(glyph.index +': '+ glyph.name +', '+ glyphUnicode);
  2349. glyphContainer.append( glyphCanvas.clone().attr('id','glyph_'+ glyph.index ) ).append(glyphInfo);
  2350. $glyphs_container.append( glyphContainer );
  2351. // Draw glyph
  2352. let thisGlyph = document.getElementById('glyph_'+ glyph.index);
  2353. $(thisGlyph).data('contextX',contextX);
  2354. let context = thisGlyph.getContext('2d');
  2355. glyph.draw(context, contextX, 84, 72);
  2356. }
  2357. $('#title').removeAttr('data-after').find('span').empty().html(font.names.fullName.en);
  2358. setContentHeight();
  2359. }
  2360. // Get font info
  2361. function getFontInfo(font) {
  2362. let $font_names = font.names;
  2363. let $font_info = $('<table id="font_info"><thead><tr><th colspan=2>FONT INFO: '+ font.names.fullName.en.toUpperCase() +'</th></tr></thead><tbody></tbody></table>');
  2364. for ( let name in $font_names ) {
  2365. let value = $font_names[name].en;
  2366. if ( name.endsWith('URL') ) {
  2367. let href = value;
  2368. if ( !value.startsWith('http') ) {
  2369. href = 'http://'+ value;
  2370. }
  2371. value = '<a href="'+ href +'" target="_blank">'+ value +'</a>';
  2372. }
  2373. $font_info.find('tbody').append('<tr><td>'+ name +': </td><td>'+ value +'</td></tr>');
  2374. }
  2375. let numGlyphs = font.numGlyphs; // glyph count
  2376. $font_info.find('tbody').append('<tr><td>numGlyphs: </td><td>'+ numGlyphs +'</td></tr>');
  2377. $content_font.find('#font_viewer').prepend($font_info);
  2378. }
  2379. // Show glyph viewer
  2380. $content_font.on('click','.glyph',function(e) {
  2381. e.stopPropagation();
  2382. let id = $(this).attr('id');
  2383. $(this).parent('div').addClass('selected').siblings().removeClass('selected');
  2384. showGlyph( id );
  2385. });
  2386. function showGlyph(id) {
  2387. let $glyph_viewer = $('#glyph_viewer');
  2388. let glyphX = $('#'+ id).data('contextX');
  2389. id = id.slice(id.lastIndexOf('_') + 1);
  2390. let glyphs = $content_font.data('data-glyphs'); // get glyphs
  2391. let glyph = glyphs.get(id);
  2392. let glyphName = glyph.name;
  2393. let glyphPath = glyph.getPath(glyphX,84,72);
  2394. let glyphSVG = glyphPath.toSVG().replace(/"/g,'\'');
  2395. // set the background SVG image:
  2396. let SVGprefix = 'url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' x=\'0px\' y=\'0px\' width=\'120px\' height=\'120px\' viewBox=\'0 0 120 120\' style=\'enable-background:new 0 0 120 120;\' xml:space=\'preserve\' ><g>';
  2397. $glyph_viewer.show().css({'background-image': SVGprefix + glyphSVG +'</g></svg>")'});
  2398. $glyph_viewer.data('data-raw-svg',glyphSVG).data('data-glyph-name',glyphName).find('#glyph_viewer_info div').text(id +': '+ glyphName +', #'+ glyph.unicode ); // for saving SVG
  2399. $content_font.addClass('has_glyph');
  2400. setContentHeight();
  2401. }
  2402. // Save glyph svg
  2403. $content_font.on('click','#save_svg',function(e) {
  2404. e.stopPropagation();
  2405. saveGlyph();
  2406. });
  2407. function saveGlyph() {
  2408. let filename = $('#glyph_viewer').data('data-font-name') +'—'+ $('#glyph_viewer').data('data-glyph-name') +'.svg';
  2409. let data_prefix = '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><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="120px" height="120px" viewBox="0 0 120 120" style="enable-background:new 0 0 120 120;" xml:space="preserve" ><g>';
  2410. let data_suffix = '</g></svg>';
  2411. let data = data_prefix + $('#glyph_viewer').data('data-raw-svg') + data_suffix;
  2412. let blob = new Blob([data], {type: 'image/svg+xml'});
  2413. let downloadEl = window.document.createElement('a');
  2414. downloadEl.href = window.URL.createObjectURL(blob);
  2415. downloadEl.download = filename;
  2416. document.body.appendChild(downloadEl);
  2417. downloadEl.click();
  2418. document.body.removeChild(downloadEl);
  2419. URL.revokeObjectURL(blob);
  2420. }
  2421.  
  2422. // Set Content Pane classes
  2423. function setContentClasses(content_el) {
  2424. if ( content_el === 'audio' ) {
  2425. $content_pane.addClass('has_audio');
  2426. } else {
  2427. hideEditorOrGrid();
  2428. $content_pane.addClass( 'has_'+ content_el ); // remove classes, excluding grid and text classes; add content class
  2429. }
  2430. $dir_list.removeClass('has_dir');
  2431. }
  2432. // Set Content Element Sources and row classes
  2433. function setContentSources(row,link,kind,content_el) {
  2434. switch(kind) {
  2435. case 'audio':
  2436. $audio_player.attr('src',link);
  2437. break;
  2438. case 'font':
  2439. showFont(row,false);
  2440. break;
  2441. case 'code':
  2442. case 'markdown':
  2443. case 'text':
  2444. link = thisLink(row) +'?split_view='+ getQuery('split_view') +'&default_text_view='+ getQuery('default_text_view');
  2445. if ( !$body.hasClass('enable_text_editing') ) { link += '&enable_text_editing=false'; } else { link += '&enable_text_editing=true'; }
  2446. break;
  2447. case 'dir':
  2448. $content_pane.toggleClass('has_iframe has_dir');
  2449. link = link + '?sort_by=' + getQuery('sort_by') +'&show_numbers='+ getQuery('show_numbers') +'&use_custom_icons='+ getQuery('use_custom_icons');
  2450. $content_iframe.data('iframe_dir',link);
  2451. break;
  2452. case 'info':
  2453. link = $location + '?sort_by=' + getQuery('sort_by') +'&show_numbers='+ getQuery('show_numbers') +'&view_source=true';
  2454. break;
  2455. case 'pdf':
  2456. link = link + '?#view=fitB&scrollbar=1&toolbar=1&navpanes=1';
  2457. break;
  2458. }
  2459. if ( kind === 'video' ) { row.addClass('playing'); } else { row.addClass('loaded'); }
  2460. // fix for pdfs not being loaded after setting src attribute (hide and then show)
  2461. if ( kind === 'pdf' ) {
  2462. $content_pdf.hide().addClass('has_content').attr('src','').attr('src',link).show().removeAttr('srcdoc');
  2463. } else if ( kind === 'image' ) {
  2464. $('#content_'+ content_el).addClass('has_content').find('img').attr('src',link);
  2465. } else {
  2466. $('#content_'+ content_el).addClass('has_content').attr('src',link).removeAttr('srcdoc');
  2467. }
  2468. }
  2469. // Show Content
  2470. function showContent(id) { // show any content excluding grids on row click
  2471. let row = getElById(id);
  2472. if ( row.length === -1 ) { return; } // needed for left/right arrow nav when there are no valid items (i.e. images or fonts)
  2473. let kind = row.attr('data-kind');
  2474. let link = thisLink(row);
  2475. let content_el = ( row.hasClass('ignore') && $body.hasClass('ignore_ignored_files') ? 'ignored' : !['audio','font','image','pdf','video'].includes(kind) || kind === 'dir' || kind === 'info' ? 'iframe' : kind ); // load dirs and any other kind of content except audio, font, image, pdf, or video into iframe
  2476. if ( row.hasClass('audio') ) {
  2477. showAudio( id );
  2478. } else {
  2479. closeOtherContent(row);
  2480. setContentClasses(content_el);
  2481. setContentSources(row,link,kind,content_el);
  2482. setContentTitle(kind);
  2483. setContentHeight();
  2484. row.siblings().removeClass('loaded');
  2485. }
  2486. }
  2487.  
  2488. //***** CLOSE CONTENT (Close button or Cmd/Ctrl + W) *****//
  2489. // Close Audio/Video
  2490. function closeMedia(type) { // type === audio || video
  2491. let $mediaEl = ( type === 'audio' ? $audio_player : $content_video );
  2492. $mediaEl.trigger('pause').attr('src','');
  2493. $content_pane.removeClass('has_'+ type);
  2494. $('.media.playing, .media.loaded').removeClass('playing loaded');
  2495. if ( type === 'audio' ) {
  2496. $('#content_audio_title td').empty();
  2497. }
  2498. if ( type === 'video' ) {
  2499. $('#content_video').removeClass('has_content');
  2500. }
  2501. setContentHeight();
  2502. }
  2503. // Close Audio button click
  2504. $('#close_audio').on('click',function(e) {
  2505. e.stopPropagation();
  2506. closeMedia('audio');
  2507. $('.audio.selected').removeClass('selected');
  2508. if ( $('.loaded').length === 1 ) { $('.loaded').addClass('selected'); }
  2509. });
  2510. // Close Playlist
  2511. function closePlaylist() {
  2512. $body.removeClass('has_playlist');
  2513. $('head').find('title').text('Index of: '+ $location); // change window title back to default
  2514. $('#parents_dir_menu').find('> div').empty().html($current_dir_path);
  2515. clickSort(getQuery('sort_by'));
  2516. $dir_list.find('#stats').html(getIndexStats($dir_list.find('#tbody tr')));
  2517. if ( $('#tbody').find('.audio').length < 1 ) { $body.removeClass('has_audio'); }
  2518. }
  2519. // Close Text Editor
  2520. function closeTextEditor() {
  2521. if ( $body.hasClass('edited') ) {
  2522. showWarning('closeContent');
  2523. } else {
  2524. $body.removeClass('has_text');
  2525. if ( $content_pane.hasClass('has_hidden_grid') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  2526. }
  2527. }
  2528. // Close Grid
  2529. function closeGrid() {
  2530. $content_pane.removeClass('has_grid');
  2531. $('#grid_btn').removeClass('has_grid');
  2532. $content_grid.empty().removeClass().attr('style','').find('.image_grid_item, img').attr('style','');
  2533. if ( $body.hasClass('has_hidden_text') ) { $body.toggleClass('has_text has_hidden_text'); }
  2534. $dir_list.find('.selected,.hovered').removeClass('selected hovered');
  2535. }
  2536. // Close index source preview
  2537. function closeIndexSource() {
  2538. $('#toggle_info').removeClass('selected loaded');
  2539. $content_pane.removeClass('has_iframe').find('#content_iframe').removeClass('has_content').removeAttr('src');
  2540. if ( $('.loaded:not(.audio)').length === 1 || $('.playing').length > 0 ) {
  2541. $('.loaded:not(.audio)').click();
  2542. $('.playing').addClass('selected');
  2543. }
  2544. if ( $content_pane.hasClass('has_hidden_grid') ) { showGrid(); }
  2545. // setContentTitle();
  2546. }
  2547. // Close .content elements (not #content_audio, #content_text, or #content_grid) when opening new content
  2548. function closeOtherContent(row) {
  2549. if ( $content_pane.hasClass('has_pdf') ) { $('head').find('title').text('Index of: '+ $location); } // change window title back to default
  2550. // close audio/video when opening video/audio
  2551. if ( row !== undefined ) {
  2552. if ( row.hasClass('video') ) {
  2553. closeMedia('audio');
  2554. } else if ( row.hasClass('audio') ) {
  2555. closeMedia('video');
  2556. }
  2557. if ( ( $content_pane.hasClass('has_grid') || $content_pane.hasClass('has_hidden_grid') ) && !row.hasClass('image') && !row.hasClass('font') && !row.hasClass('audio') ) {
  2558. closeGrid();
  2559. }
  2560. }
  2561. // close other content
  2562. if ( $('.content.has_content').length || $content_pane.hasClass('has_ignored') ) {
  2563. let $contentID = $('.content.has_content').attr('id');
  2564. switch($contentID) { // specific cases
  2565. case 'content_font':
  2566. $content_font.attr('style','').find('#font_viewer').remove().end().append(ContentFontViewer());
  2567. break;
  2568. case 'content_image':
  2569. $content_image.removeAttr('style').find('img').removeAttr('style'); // reset image: comment out to retain image scale after loading other content
  2570. break;
  2571. case 'content_video':
  2572. closeMedia('video');
  2573. break;
  2574. }
  2575. // remove content classes and source attribute
  2576. $content_pane.removeClass('has_font has_image has_zoom_image has_pdf has_video has_iframe has_dir has_ignored')
  2577. .find('.content').removeClass('has_content has_font has_font_viewer').removeAttr('src')
  2578. .find('img').removeAttr('src');
  2579. showHiddenEditorOrGrid();
  2580. }
  2581. }
  2582. // Close Button: close any visible content
  2583. function closeContent() {
  2584. window.stop();
  2585. if ( $content_pane.hasClass('has_hidden_dir') ) { // close pdfs or ... navigated to from within content pane
  2586. $content_pane.removeClass().addClass('has_dir').find('.has_content:not(iframe)').removeClass('has_content').removeAttr('src');
  2587. $content_iframe.removeClass('has_file');
  2588. let data = decodeURIComponentSafe($content_iframe.data('iframe_dir'));
  2589. let title = data.slice(0, data.indexOf('/?') + 1);
  2590. $('#title span').empty().text(title);
  2591. } else if ( $content_iframe.hasClass('has_file') ) { // close files navigated to from within content pane
  2592. let data = decodeURIComponentSafe($content_iframe.data('iframe_dir'));
  2593. let title = data.slice(0, data.indexOf('/?') + 1);
  2594. $('#title span').empty().text(title);
  2595. $content_iframe.removeClass('has_file').attr('src', data );//.removeData(); // remove dir link data
  2596. } else if ( $content_iframe.hasClass('has_dir') ) {
  2597. $content_iframe.removeClass('has_dir').data('iframe_dir','').removeData();
  2598. $('tr.dir.selected a').click(); // load selected sidebar dir
  2599. } else if ( $('#toggle_info').hasClass('selected') ) { // close previewed directory source
  2600. closeIndexSource();
  2601. } else if ( $body.hasClass('has_text') ) { // close text editor
  2602. closeTextEditor();
  2603. } else if ( ( $content_pane.hasClass('has_hidden_grid has_image') || $content_pane.hasClass('has_hidden_grid has_zoom_image') ) ) {
  2604. $('.loaded').removeClass('loaded hovered');
  2605. $content_pane.toggleClass('has_hidden_grid has_grid').removeClass('has_image has_zoom_image').find('#content_image').removeClass('has_content').find('img').removeAttr('src');
  2606. scrollThis('content_grid','selected');
  2607. } else if ( $content_pane.hasClass('has_grid') ) { // close grid (i.e., don't just hide)
  2608. closeGrid();
  2609. } else if ($content_font.hasClass('has_glyph') ) { // close previewed font glyph
  2610. $('#glyph_viewer').hide().attr('style','');
  2611. $content_font.addClass('has_content').removeClass('has_glyph');
  2612. scrollThis('glyphs_container','selected');
  2613. } else if ( ['has_font','has_image','has_zoom_image','has_pdf','has_video','has_iframe','has_dir','has_ignored'].some( c => $content_pane.attr('class').split(' ').indexOf( c ) >= 0 ) && !$body.hasClass('iframe_edited') ) {
  2614. $('tr.selected:not(.audio)').removeClass('selected');
  2615. $('.loaded').removeClass('loaded');
  2616. $('#title').removeAttr('data-after').find('span').empty();
  2617. closeOtherContent();
  2618. } else if ( $body.hasClass('iframe_edited') ) { // warn if iframe edited
  2619. showWarning('closeContent');
  2620. } else if ( $content_pane.hasClass('has_audio') ) { // close audio last of all
  2621. closeMedia('audio');
  2622. $('.selected.audio').removeClass('selected');
  2623. } else if ( $body.hasClass('has_playlist') ) { // close playlist, reopen previous dir
  2624. closePlaylist();
  2625. }
  2626. if ( $('#font_info').length < 1 && !$content_iframe.hasClass('has_dir') ) {
  2627. setContentTitle();
  2628. }
  2629. setContentHeight();
  2630. }
  2631. $('#close_btn').on('click', function(e) {
  2632. e.preventDefault();
  2633. closeContent(); // close content unless body.edited or body.iframe_edited
  2634. });
  2635.  
  2636. //***** RESET CONTENT (Reset button or Cmd/Ctrl + R) *****//
  2637. function resetContent() {
  2638. if ( $content_pane.attr('class') === '' ) { window.location = window.location.href; } // reload page
  2639. if ( $content_pane.hasClass('has_audio') ) { $audio_player.prop('currentTime', 0).trigger('pause'); }
  2640. if ( $content_pane.hasClass('has_grid') ) { $('#grid_btn').click(); }
  2641. if ( $content_pane.hasClass('has_font') ) { $content_font.css({'font-size':'1em'}); }
  2642. if ( $content_pane.hasClass('has_image') || $content_pane.hasClass('has_zoom_image') ) { $content_pane.removeClass('has_zoom_image').addClass('has_image').find('#content_image').removeAttr('style').find('img').removeAttr('style'); }
  2643. if ( $content_pane.hasClass('has_video') ) { $content_video.prop('currentTime',0).trigger('pause'); }
  2644. if ( $content_pane.hasClass('has_iframe') || $content_pane.hasClass('has_dir') ) { $selected_file().find('a').click(); }
  2645. setContentHeight();
  2646. }
  2647. $('#reload_btn').on('click', function(e) {
  2648. e.preventDefault();
  2649. showWarning('resetContent');
  2650. });
  2651.  
  2652. //**********************//
  2653. //***** NAVIGATION *****//
  2654. function firstRowID(className) {
  2655. return ( $('#tbody').find(':visible:not(.unchecked)').filter(className).length ? $('#tbody').find('tr:visible:not(.unchecked)').filter(className).first().attr('id') : null );
  2656. }
  2657. function prevRowID(className) {
  2658. let row;
  2659. if ( ['.audio','.video','.media'].includes(className) ) { row = $playing_file(); } else { row = $selected_file(); }
  2660. return ( !row.length || !row.prevAll(':visible:not(.unchecked)').filter(className).length ) ? $('#tbody').find('tr:visible').filter(className).last().attr('id') : row.prevAll(':visible:not(.unchecked)').filter(className).first().attr('id');
  2661. }
  2662. function nextRowID(className) { // if nothing selected, or if no next row with classname, return first row with classname, else return next row with classname
  2663. let row;
  2664. if ( ['.audio','.video','.media'].includes(className) ) { row = $playing_file(); } else { row = $selected_file(); }
  2665. return ( !row.length || !row.nextAll(':visible:not(.unchecked)').filter(className).length ) ? $('#tbody').find('tr:visible').filter(className).first().attr('id') : row.nextAll(':visible:not(.unchecked)').filter(className).first().attr('id');
  2666. }
  2667. // function lastRowID(className) {
  2668. // return ( $('#tbody').find(':visible:not(.unchecked)').filter(className).length ? $('#tbody').find('tr:visible:not(.unchecked)').filter(className).last().attr('id') : null );
  2669. // }
  2670. function selectRowID(className,key) {
  2671. let id = '';
  2672. if ( key === 'ArrowUp' ) { id = prevRowID('.dir,.file'); }
  2673. if ( key === 'ArrowLeft' ) { id = prevRowID(className); }
  2674. if ( key === 'ArrowRight' ) { id = nextRowID(className); }
  2675. if ( key === 'ArrowDown' ) { id = nextRowID('.dir,.file'); }
  2676. return id;
  2677. }
  2678. // NAVIGATION: select GRID items by left/right arrow keys @ arrowNavigation();
  2679. function gridNavigation(key) {
  2680. let id; // = grid item data-id = corresponding dir_list item id.
  2681. let rowLength = 0; // $content_grid.hasClass('has_grid') || $('#content_font').hasClass('has_font_grid')
  2682. if ( $('#content_grid').hasClass('has_image_grid') ) { rowLength = (Math.round( $('#content_grid').innerWidth() / $('.image_grid_item').outerWidth()) - 1 ) ;}
  2683. switch(key) {
  2684. case 'ArrowDown':
  2685. if ( $('#content_grid .selected').nextAll().eq(rowLength).length === 1 ) { id = $('#content_grid .selected').nextAll().eq(rowLength).attr('data-id'); } else { id = $('#content_grid > div').first().attr('data-id'); }
  2686. break;
  2687. case 'ArrowUp':
  2688. if ( $('#content_grid .selected').prevAll().eq(rowLength).length === 1 ) { id = $('#content_grid .selected').prevAll().eq(rowLength).attr('data-id'); } else { id = $('#content_grid > div').last().attr('data-id'); }
  2689. break;
  2690. case 'ArrowLeft':
  2691. if ( $('#content_grid .selected').prev().length === 1 ) { id = $('#content_grid .selected').prev().attr('data-id'); } else { id = $('#content_grid > div').last().attr('data-id'); }
  2692. break;
  2693. case 'ArrowRight':
  2694. if ( $('#content_grid .selected').next().length === 1 ) { id = $('#content_grid .selected').next().attr('data-id'); } else { id = $('#content_grid > div').first().attr('data-id'); }
  2695. break;
  2696. }
  2697. if ( $content_pane.hasClass('has_hidden_grid') ) {
  2698. $('#content_grid > div[data-id="'+ id +'"]').click();
  2699. } else {
  2700. selectThis(id);
  2701. }
  2702. }
  2703. // NAVIGATION: FONTS and IMAGES by prev/next buttons
  2704. $content_pane.on( 'click','#prev_btn, #next_btn', function(e) {
  2705. e.stopPropagation();
  2706. e.preventDefault();
  2707. let key = $(this).attr('id') === 'prev_btn' ? 'ArrowLeft' : 'ArrowRight';
  2708. if ( $('#content_font').hasClass('has_font_viewer') ) {
  2709. glyphNavigation(key);
  2710. } else {
  2711. clickRow( selectRowID('.font,.image',key));
  2712. }
  2713. });
  2714. // glyph navigation
  2715. function glyphNavigation(key) {
  2716. let rowLength = Math.round( $('#glyphs_container').innerWidth() / $('.glyph_container').outerWidth() - 1 );
  2717. if ( $('#glyphs_container > .glyph_container.selected').length === 0 ) {
  2718. if ( key === 'ArrowRight' || key === 'ArrowDown' ) { $('.glyph_container').first().addClass('selected').siblings().removeClass('selected'); }
  2719. if ( key === 'ArrowLeft' || key === 'ArrowUp' ) { $('.glyph_container').last().addClass('selected').siblings().removeClass('selected'); }
  2720. } else if ( $('#glyphs_container > .glyph_container.selected').length === 1 ) {
  2721. if ( key === 'ArrowRight' ) {
  2722. if ( $('.glyph_container.selected').nextAll('.glyph_container').eq(rowLength).length === 1 ) {
  2723. $('.glyph_container.selected').nextAll('.glyph_container').first().addClass('selected').siblings().removeClass('selected');
  2724. } else {
  2725. $('.glyph_container').first().addClass('selected').siblings().removeClass('selected');
  2726. }
  2727. }
  2728. if ( key === 'ArrowLeft' ) {
  2729. if ( $('.glyph_container.selected').prevAll('.glyph_container').eq(rowLength).length === 1 ) {
  2730. $('.glyph_container.selected').prevAll('.glyph_container').first().addClass('selected').siblings().removeClass('selected');
  2731. } else {
  2732. $('.glyph_container').last().addClass('selected').siblings().removeClass('selected');
  2733. }
  2734. }
  2735. if ( key === 'ArrowDown' ) {
  2736. if ( $('.glyph_container.selected').nextAll('.glyph_container').eq(rowLength).length === 1 ) {
  2737. $('.glyph_container.selected').nextAll('.glyph_container').eq(rowLength).addClass('selected').siblings().removeClass('selected');
  2738. } else {
  2739. $('.glyph_container').first().addClass('selected').siblings().removeClass('selected');
  2740. }
  2741. }
  2742. if ( key === 'ArrowUp' ) {
  2743. if ( $('.glyph_container.selected').prevAll('.glyph_container').eq(rowLength).length === 1 ) {
  2744. $('.glyph_container.selected').prevAll('.glyph_container').eq(rowLength).addClass('selected').siblings().removeClass('selected');
  2745. } else {
  2746. $('.glyph_container').last().addClass('selected').siblings().removeClass('selected');
  2747. }
  2748. }
  2749. }
  2750. if ( $('#content_font').hasClass('has_glyph') ) { $('.glyph_container.selected .glyph').click(); } // show the selected glyph
  2751. }
  2752. // NAVIGATION: MEDIA tracks by arrow left/right @ leftRightArrowNavigation() & button click; // handle shuffle or loop play, as well as normal continuous playback after end of track with ArrowRight
  2753. function playPrevNextTrack(key) {
  2754. if ( $('.playing').length === 0 ) { // Arrow L/R selects first/last audio file if nothing selected
  2755. clickRow( selectRowID('.media',key) );
  2756. playMedia('play');
  2757. } else if ( $('.playing').length === 1 ) {
  2758. let mediaClass = ( $('.playing').hasClass('audio') ? '.audio' : '.video' );
  2759. // If shuffle play...
  2760. if ( $body.hasClass('shuffle_audio') ) {
  2761. let trackRowID = $audio_player.data('shufflelist').pop();
  2762. if ( trackRowID !== undefined ) { // if shuffle list is not empty...
  2763. showAudio( trackRowID ); // load audio...
  2764. playMedia('play'); // and play
  2765. } else if ( trackRowID === undefined ) { // if end of shufflelist...
  2766. if ( $body.hasClass('loop_audio') ) { // and if loop audio, update the shufflelist and play
  2767. updateShuffleList();
  2768. playMedia('play');
  2769. } else { // else load the first track
  2770. showAudio( firstRowID( mediaClass ));
  2771. }
  2772. }
  2773. // else if there is another media file selected, play it next
  2774. } else if ( $(mediaClass).filter('.selected').length === 1 && !$('.media.selected').hasClass('playing') ) {
  2775. showAudio( $('.media.selected').attr('id') );
  2776. playMedia('play');
  2777. } else {
  2778. if ( $body.hasClass('loop_audio') || nextRowID( mediaClass ) !== firstRowID( mediaClass ) ) {
  2779. showAudio( selectRowID( mediaClass,key ) );
  2780. playMedia('play');
  2781. } else {
  2782. showAudio( selectRowID( mediaClass,key ) );
  2783. }
  2784. }
  2785. }
  2786. }
  2787. // NAVIGATION: Audio by prev/next audio buttons
  2788. $('.prev_next_track_btn').on('click',function() {
  2789. let key = ( $(this).attr('id') === 'prev_track' ? 'ArrowLeft' : 'ArrowRight' );
  2790. playPrevNextTrack(key);
  2791. });
  2792. // NAVIGATION: Prev/Next Audio or Prev/Next File of same data-kind by arrow left/right
  2793. function leftRightArrowNavigation(className,key) {
  2794. if ( $('.selected').hasClass('audio') && $('.playing').length === 1 ) {
  2795. playPrevNextTrack(key);
  2796. } else if ( $('#toggle_info').hasClass('selected') ) { // if previewing directory source
  2797. if ( $('#tbody .loaded').length > 0 ) { clickRow( $('#tbody .loaded').attr('id') ); } else { clickRow( selectRowID('.dir,.file',key) ); }
  2798. } else {
  2799. if ( $('.selected').length === 0 ) { // else select first/last row
  2800. clickRow( selectRowID('.dir,.file',key) );
  2801. } else { // else select prev/next row of same data-kind
  2802. clickRow( selectRowID('.'+ $('.loaded,.video.playing').attr('data-kind'),key) );
  2803. }
  2804. if (className === 'video') { playMedia('play'); }
  2805. }
  2806. }
  2807. function upDownArrowNavigation(key) {
  2808. let row = $(document.getElementById(selectRowID('.dir,.file',key)));
  2809. if ( row.hasClass('audio') && $('.audio.playing').length === 1 ) { // just select audio file if another audio is playing
  2810. selectThis( row.attr('id') );
  2811. } else if ( $('#toggle_info').hasClass('selected') ) {
  2812. if ( $('#tbody .loaded').length > 0 ) {
  2813. clickRow( $('#tbody .loaded').attr('id') );
  2814. } else {
  2815. clickRow( selectRowID('.dir,.file:visible',key) );
  2816. }
  2817. } else {
  2818. clickRow( selectRowID('.dir,.file',key) );
  2819. }
  2820. }
  2821. // NAVIGATE directory index items by arrow up/down or left/right keys, with/without grid @ indexNavigation()
  2822. function arrowNavigation(className,key) {
  2823. if ( $content_pane.hasClass('has_grid') || $content_pane.hasClass('has_hidden_grid') ) { // Grid navigation: L/R arrow selects images and fonts only
  2824. gridNavigation(key);
  2825. if ( !$content_pane.hasClass('has_hidden_grid') ) { scrollThis('content_grid','selected'); }
  2826. } else if ( $('#content_font').hasClass('has_font_viewer') ) { // if previewing font glyphs
  2827. glyphNavigation(key);
  2828. scrollThis('content_container','selected');
  2829. } else if ( key === 'ArrowUp' || key === 'ArrowDown' ) {
  2830. upDownArrowNavigation(key);
  2831. scrollThis('tbody','selected');
  2832. } else { // key === 'ArrowLeft" || key === 'ArrowRight'
  2833. leftRightArrowNavigation(className,key);
  2834. scrollThis('tbody','selected');
  2835. }
  2836. }
  2837. // NAVIGATION: Main navigation by arrow keys
  2838. function indexNavigation(key) {
  2839. let className = ( $('.selected[data-kind]') === undefined ? $dir_list.find('tbody tr:visible').first().attr('data-kind') : $('.selected[data-kind]').attr('data-kind') );
  2840. arrowNavigation(className,key);
  2841. }
  2842.  
  2843. // NAVIGATE items by typed string
  2844. var str = '';
  2845. function timeoutID() {
  2846. return window.setTimeout( function() { str = ''; }, 1500 );
  2847. }
  2848. function alphaNav(e) { // Select Dir_List row by typed string; Todo: select next row by nearest letter
  2849. let timer = timeoutID();
  2850. if ( typeof timer === 'number' ) {
  2851. window.clearTimeout( timer );
  2852. timer = 0; // id
  2853. }
  2854. timeoutID();
  2855. str += e.key;
  2856. str = str.toLowerCase();
  2857. if ( $('#dir_list').find('td.name[data-name^="'+ str +'"]').length ) {
  2858. $('#dir_list').find('td.name[data-name^="'+ str +'"]').first().find('a').click();
  2859. scrollThis('tbody','selected');
  2860. // } else {
  2861. // null; // replace this with some sort of fuzzy match function? TBD
  2862. }
  2863. }
  2864. //***** END NAVIGATION *****//
  2865.  
  2866. //***** CLICK TO SELECT/SHOW CONTENT *****//
  2867.  
  2868. // CLICK element by id
  2869. function clickThis(id) {
  2870. let el = $(document.getElementById(id));
  2871. if ( el.find('a').length > 0 ) { el.find('a').click(); } else { el.click(); }
  2872. }
  2873. // CLICK Row
  2874. function clickRow(id) {
  2875. selectThis(id);
  2876. showContent(id);
  2877. }
  2878. $body.find('#tbody').on('click','tr', function(e) {
  2879. e.preventDefault();
  2880. e.stopPropagation();
  2881. if ( $(this).hasClass('playing') ) {
  2882. playPauseMedia();
  2883. } else {
  2884. showWarning( 'clickRow', $(this).attr('id') );
  2885. }
  2886. });
  2887. // Show current dir source in $content_iframe
  2888. $('#toggle_info').on('click',function(e) {
  2889. e.stopPropagation();
  2890. if ( $(this).hasClass('selected') ) {
  2891. $('#close_btn').click();
  2892. } else {
  2893. showWarning( 'clickRow', $(this).attr('id') );
  2894. }
  2895. });
  2896.  
  2897. // DOUBLE-CLICK Row to open directory
  2898. function doubleClickRow(id) { // row.dir only
  2899. let row = getElById(id);
  2900. let $query_str = decodeURIComponentSafe(window.location.search);
  2901. if ( $query_str === '' ) { $query_str = '?'; }
  2902. const $current_index = row.prevAll('.dir:visible').length;
  2903. if ( $query_str.indexOf('history') !== -1 ) {
  2904. $query_str = $query_str.replace(/&selected=\d+/,'').replace(/&history=/,'&history='+ $current_index +'+');
  2905. } else {
  2906. $query_str = $query_str.replace(/&selected=\d+/,'') + '&history='+ $current_index;
  2907. }
  2908. window.location = row.find('a').attr('href') + $query_str;
  2909. }
  2910. $('#tbody').find('tr.dir').on('dblclick', function(e) {
  2911. e.preventDefault();
  2912. e.stopPropagation();
  2913. showWarning( 'doubleClickRow', $(this).attr('id') );
  2914. });
  2915. // CLICK grid item
  2916. $content_grid.on('click','div', function(e) {
  2917. e.preventDefault();
  2918. let id = $(this).attr('data-id');
  2919. $(this).addClass('selected').siblings().removeClass('selected');
  2920. getElById(id).click();
  2921. });
  2922.  
  2923. // HOVER Grid Item
  2924. $content_grid.on('mouseenter','> div:not(.selected)',function() {
  2925. thisRow($dir_list.find('a[href*="'+ thisLink(this) +'"]')).addClass('hovered');
  2926. }).on('mouseleave','> div:not(.selected)',function() {
  2927. thisRow($dir_list.find('a[href*="'+ thisLink(this) +'"]')).removeClass('hovered');
  2928. });
  2929. // HOVER Dir_list_row and highlight corresponding grid item
  2930. $dir_list_row.hover(function() {
  2931. if ( $content_grid.is(':visible') ) {
  2932. $content_grid.find('[href*="'+ thisLink(this) +'"]').closest('div').addClass('hovered');
  2933. }
  2934. }, function() {
  2935. if ( $content_grid.is(':visible') ) {
  2936. $content_grid.find('.hovered').removeClass('hovered');
  2937. }
  2938. });
  2939.  
  2940. //***** AUTOLOAD CONTENT: index files or files from the file shortcut list *****//
  2941. function autoSelectFile() {
  2942. let $query_prefs = getQueryPrefs();
  2943. let $UI_pref_selected = ( $query_prefs.get('selected') === null ? '' : $query_prefs.get('selected') );
  2944. if ( getQuery('file') !== undefined && getQuery('file').length > 0 && window.top == window.self ) { // load individual files
  2945. clickRow( $dir_list.find('a[href*="'+ getQuery('file') +'"]').closest('tr').attr('id') );
  2946. removeQuery('file');
  2947. } else if ( $UI_pref_selected !== '' ) {
  2948. clickRow( $dir_list.find('tr.dir:visible').eq($UI_pref_selected).attr('id') );
  2949. } else if ( $body.hasClass('autoload_index_files') && $dir_list.find( 'a[href*="/index."]').length > 0 ) { // else load index file
  2950. clickRow( $dir_list.find('a[href*="/index."]').closest('tr').attr('id') );
  2951. } else if ( !$body.hasClass('has_media') ) { // else select first non-media item
  2952. // clickRow( $dir_list.find('#tbody tr:visible:not(.media):not(.invisible):not(.ignored)').first(0).attr('id') );
  2953. }
  2954. if ( $body.hasClass('autoload_media') && $body.hasClass('has_media') ) { // else if audio and images, load cover art
  2955. clickRow( firstRowID('.audio,.video') );
  2956. if ( $playing_file() ) { scrollThis('tbody','playing'); }
  2957. }
  2958. if ( $selected_file() ) { scrollThis('tbody','selected'); }
  2959. }
  2960.  
  2961. // Autoload Cover Art
  2962. function getImageNames() {
  2963. let image_names = [];
  2964. $image_files.each(function() {
  2965. let name = $(this).find('td.name').attr('data-name');
  2966. name = name.slice(0,name.lastIndexOf('.'));
  2967. image_names.push( name );
  2968. });
  2969. return image_names;
  2970. }
  2971. function getCoverArtID() {
  2972. const cover_names = ['cover','front'];
  2973. const image_names = getImageNames();
  2974. for ( let cover_name of cover_names ) {
  2975. if ( image_names.includes(cover_name) ) { // file name = a cover name
  2976. return $image_files.eq( image_names.indexOf(cover_name) ).attr('id');
  2977. } else if ( image_names.some( name => name.startsWith(cover_name)) ) { // file name starts with a cover name
  2978. return $image_files.find('td.name[data-name^="'+ cover_name +'"]').closest('tr').attr('id');
  2979. } else if ( image_names.some( name => name.indexOf(cover_name) > 0 ) ) { // file name includes a cover name
  2980. return $image_files.find('td.name[data-name*="'+ cover_name +'"]').closest('tr').attr('id');
  2981. } else { // else use first image
  2982. return $image_files.first().attr('id');
  2983. }
  2984. }
  2985. }
  2986. function autoLoadCoverArt() { // autoload cover art for audio if dir contains audio and images, and audio is loaded and non-image content is not loaded
  2987. let bodyClasses = getClassList('top');
  2988. if ( bodyClasses.contains( 'has_audio','has_images','autoload_media' ) && !getElById( firstRowID('.media') ).hasClass('video') ) {
  2989. let $coverID = getCoverArtID();
  2990. if ( $coverID !== undefined ) {
  2991. let row = getElById($coverID);
  2992. showContent($coverID);
  2993. row.addClass('loaded');
  2994. $('#title span').html(row.find('.name').attr('data-name'));
  2995. setImageDimensions();
  2996. }
  2997. }
  2998. }
  2999.  
  3000. //***** KEYBOARD EVENTS *****//
  3001. $body.on('keydown',$dir_list,function(e) {
  3002. const $selected = ( $('#content_font').hasClass('has_font_viewer') ? $('.glyph_container.selected .glyph') : $selected_file() );
  3003.  
  3004. if ( $('#content_source').is(':focus') || $('#content_font div').is(':focus') && e.key !== 'Escape' ) {
  3005. return;
  3006. }
  3007. // Disable all keydown events except return and tab when warning is shown
  3008. if ( $('body').hasClass('has_warning') ) {
  3009. if (e.key !== 'Enter' && e.key !== 'Tab' && e.key !== 'Shift' ) {
  3010. e.preventDefault();
  3011. return false;
  3012. }
  3013. if ( e.key === 'Enter' ) {
  3014. e.preventDefault();
  3015. e.stopPropagation();
  3016. $('#warnings').find('button.focus').click();
  3017. }
  3018. if ( e.key === 'Tab' ) {
  3019. e.preventDefault();
  3020. e.stopPropagation();
  3021. if ( $('#warnings').find('button.focus').length === 0 || $('#warnings').find('button.focus').prev('button').length === 0 ) {
  3022. $('#warnings').find('button').last('button').focus().addClass('focus').siblings().removeClass('focus').blur();
  3023. } else {
  3024. $('#warnings').find('button.focus').prev('button').focus().addClass('focus').siblings().removeClass('focus').blur();
  3025. }
  3026. }
  3027. }
  3028.  
  3029. $(':focus').blur(); // Need this to able to select grid items after clicking close button (or other buttons).
  3030.  
  3031. switch ( e.key ) {
  3032. case 'ArrowUp':
  3033. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) { // Cmd/Ctrl + up arrow = go to parent directory
  3034. if ( $('#parents_dir_menu + ul a').length < 1 ) {
  3035. return;
  3036. } else {
  3037. showWarning( 'clickThis', $('#parent_dir_menu').attr('id') );
  3038. }
  3039. break;
  3040. }
  3041. if ( $('*[contentEditable="true"]').is(':focus') ) { // Allow arrow navigation within content_editable elements
  3042. return;
  3043. }
  3044. e.preventDefault();
  3045. showWarning( 'indexNavigation', 'ArrowUp' );
  3046. break;
  3047. case 'ArrowDown':
  3048. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey && $selected.hasClass('app') && $settings.apps_as_dirs === false ) { // Ignore Cmd/Ctrl + arrow or if focused element is content editable or open dir
  3049. return;
  3050. } else if ( $('*[contentEditable="true"]' ).is(':focus') ) {
  3051. return;
  3052. } else if ( (e.ctrl || e.metaKey) && $selected.hasClass('dir') ) {
  3053. $selected.find('a').trigger('dblclick');
  3054. break;
  3055. }
  3056. e.preventDefault();
  3057. showWarning( 'indexNavigation', 'ArrowDown' );
  3058. break;
  3059. case 'ArrowLeft':
  3060. if ( (e.ctrl || e.metaKey) || (e.ctrl && e.metaKey) ) {
  3061. return;
  3062. } else if ( $('*[contentEditable="true"]').is(':focus') ) { // Ignore Cmd/Ctrl + arrow or if focused element is content editable
  3063. return;
  3064. }
  3065. if ( (e.altKey && e.shiftKey) || e.altKey && !e.metaKey && !e.ctrlKey ) { // Skip audio 30s/10s: Opt-Shift-Arrow/Opt-Arrow
  3066. mediaSkip(e);
  3067. return;
  3068. } else {
  3069. showWarning( 'indexNavigation','ArrowLeft' );
  3070. }
  3071. break;
  3072. case 'ArrowRight':
  3073. if ( e.metaKey && !e.altKey && !e.shiftKey && $selected.hasClass('dir') ) { // Open dir with Cmd/Ctrl + Right Arrow
  3074. $selected.find('a').trigger('dblclick');
  3075. return;
  3076. }
  3077. if ( (e.ctrl || e.metaKey) || (e.ctrl && e.metaKey) ) { // Ignore Cmd/Ctrl + arrow or if focused element is content editable
  3078. return;
  3079. } else if ( $('*[contentEditable="true"]').is(':focus') || $selected.hasClass('dir ignore') ) {
  3080. return;
  3081. }
  3082. if ( (e.altKey && e.shiftKey) || e.altKey && !e.metaKey && !e.ctrlKey ) { // Skip audio 30s/10s: Opt-Shift-Arrow/Opt-Arrow
  3083. mediaSkip(e);
  3084. return;
  3085. } else {
  3086. showWarning( 'indexNavigation','ArrowRight' );
  3087. }
  3088. break;
  3089. case ' ': // space
  3090. if ( $content_pane.hasClass('has_audio') || $content_pane.hasClass('has_video') ) { // Play/pause media (space bar)
  3091. e.preventDefault();
  3092. playPauseMedia();
  3093. } else {
  3094. alphaNav(e);
  3095. }
  3096. break;
  3097. case 'Enter': // Open directories (or ignore)
  3098. if ( $selected.hasClass('app') && $settings.apps_as_dirs === false ) {
  3099. break;
  3100. } else {
  3101. if ( $selected.hasClass('dir') ) {
  3102. $selected.find('a').trigger('dblclick');
  3103. } else if ( $selected.hasClass('playing') || $selected.hasClass('video') ) { // content_audio or content_video
  3104. playPauseMedia();
  3105. } else {
  3106. $selected.click();
  3107. }
  3108. }
  3109. break;
  3110. // Alphabetical navigation
  3111. case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
  3112. case 'a': case 'b': case 'c': case 'f': case 'h': case 'j': case 'k': case 'l': case 'm': case 'n': case 'p': case 'q': case 's': case 't': case 'u': case 'v': case 'x': case 'y': case 'z':
  3113. case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '`': case '~': case '!': case '@': case '#': case '$': case '%': case '^': case '&': case '*': case '(': case ')': case '+': case '[': case ']': case '{': case '}': /*case '\\':*/ case '|': case '/': case '.': case ',': case '?': case '–': case '—': case '\'': case '"': case '“': case '”': case '‘': case '’': case '…': case 'π':
  3114. case '∫': case '∂': case 'ƒ': case '©': case '˙': case '∆': case '˚': case 'µ': case '®': case 'ß': case '†': case '√': case '∑': case '≈': case '¥': case 'Ω': case '¡': case '™': case '£': case '¢': case '∞': case '§': case '¶': case '•': case 'ª': case 'º': case '≠':
  3115. case '⁄': case '€': case '‹': case '›': case 'fl': case '‡': case '°': case '·': case '‚': case '±': case '¯': case '˘': case '¿':
  3116. case 'ı': case '': case '´': case '˝': case 'ˆ': case '': case '˜': case '‰': case 'ˇ': case '¨': case '◊': case '„': case '˛': case '¸':
  3117. // case 'α': case 'β': case 'γ': case 'δ': case 'ε': case 'ζ': case 'η': case 'θ': case 'ι': case 'κ': case 'λ': case 'μ': case 'ν': case 'ξ': case 'ο': case 'π': case 'ρ': case 'ς': case 'σ': case 'τ': case 'υ': case 'φ': case 'χ': case 'ψ': case 'ω': case 'ϑ': case 'ϒ': case 'ϖ':
  3118. // case 'Α': case 'Β': case 'Γ': case 'Δ': case 'Ε': case 'Ζ': case 'Η': case 'Θ': case 'Ι': case 'Κ': case 'Λ': case 'Μ': case 'Ν': case 'Ξ': case 'Ο': case 'Π': case 'Ρ': case 'Σ': case 'Σ': case 'Τ': case 'Υ': case 'Φ': case 'Χ': case 'Ψ': case 'Ω': case 'Θ': case 'ϒ':
  3119. if ( !e.metaKey && !e.ctrlKey && !e.altKey ) {
  3120. alphaNav(e);
  3121. }
  3122. break;
  3123. case 'd': // Cmd/Ctrl + D: Toggle Details
  3124. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3125. e.preventDefault();
  3126. $('#show_details').click();
  3127. } else {
  3128. alphaNav(e);
  3129. }
  3130. break;
  3131. case 'e': // Cmd/Ctrl + E: Show Text Editor
  3132. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3133. e.preventDefault();
  3134. $('#text_editor_row').find('a').click();
  3135. } else {
  3136. alphaNav(e);
  3137. }
  3138. break;
  3139. case 'g': // Cmd/Ctrl + G: Show image Grid
  3140. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3141. e.preventDefault();
  3142. $('#grid_btn').click();
  3143. } else {
  3144. alphaNav(e);
  3145. }
  3146. break;
  3147. case 'i': // Cmd/Ctrl + I: Toggle Invisibles
  3148. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3149. e.preventDefault();
  3150. $('#show_invisibles').find('input').click();
  3151. } else {
  3152. alphaNav(e);
  3153. }
  3154. break;
  3155. case 'o': // Cmd/Ctrl + Shift + O: Open selected item in new window
  3156. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && e.shiftKey && !e.altKey ) {
  3157. window.open( thisLink($selected_file()) );
  3158. } else {
  3159. alphaNav(e);
  3160. }
  3161. break;
  3162. case 'r': // Cmd/Ctrl + Shift + R: Refresh
  3163. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3164. e.preventDefault();
  3165. $('#reload_btn').click();
  3166. } else {
  3167. alphaNav(e);
  3168. }
  3169. break;
  3170. case 'w': // Close content pane if Close button visible with Cmd/Crtl + W
  3171. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3172. if ( $content_pane.attr('class').indexOf('has_') > -1 || $('#toggle_info').hasClass('selected') || $body.hasClass('has_playlist') ) {
  3173. e.preventDefault();
  3174. $('#close_btn').click();
  3175. }
  3176. } else {
  3177. alphaNav(e);
  3178. }
  3179. break;
  3180. case '\\':
  3181. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3182. e.preventDefault();
  3183. $('#toggle_split_view').click();
  3184. } else {
  3185. alphaNav(e);
  3186. }
  3187. break;
  3188. case '=':
  3189. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3190. e.preventDefault();
  3191. $('#increase').click();
  3192. } else {
  3193. alphaNav(e);
  3194. }
  3195. break;
  3196. case '-':
  3197. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3198. e.preventDefault();
  3199. $('#decrease').click();
  3200. } else {
  3201. alphaNav(e);
  3202. }
  3203. break;
  3204. case 'tab':
  3205. break;
  3206. case 'Escape':
  3207. $('*:focus').blur();
  3208. break;
  3209. } // end switch
  3210. });
  3211. // ***** END KEYBOARD EVENTS ***** //
  3212.  
  3213. // ***** GRID SETUP ***** //
  3214. // Create Font Grid Items
  3215. function fontGridItems() {
  3216. let $font_grid_items_arr = [];
  3217. let $font_files = $dir_list_body.find('.font');
  3218. let fontGridStyles = $font_grid_styles.sheet;
  3219. for ( let i = 0; i < $font_files.length; i++ ) {
  3220. let newGridItem = showFont($font_files[i],true,fontGridStyles);
  3221. $font_grid_items_arr.push( newGridItem );
  3222. }
  3223. return $font_grid_items_arr;
  3224. }
  3225. // Create Image Grid Items
  3226. function imageGridItems() {
  3227. let $image_grid_items_arr = [];
  3228. let $image_files = $dir_list_body.find('.image:not(.ignore)');
  3229. for ( let i = 0; i < $image_files.length; i++ ) {
  3230. const id = $image_files.eq(i).attr('id');
  3231. const $this_link = thisLink($image_files[i]);
  3232. const exts = $row_types.image.filter( ext => $.inArray(ext, $row_settings.ignore) == -1 ); // decide which image files can be displayed
  3233. const $title_name = $this_link.slice($this_link.lastIndexOf('/') + 1);
  3234. if ( $.inArray( thisExt($image_files[i]), exts ) > -1 ) { // if this row file ext is in the image extension array
  3235. let item = '<div class="image_grid_item" data-ID="'+ id +'" data-index="'+ i +'"><a href="'+$this_link+'"><img src="'+$this_link+'" title="'+$title_name+'" loading="lazy" /></a></div>';
  3236. $image_grid_items_arr.push( item );
  3237. }
  3238. }
  3239. return $image_grid_items_arr;
  3240. }
  3241. // Make Grids
  3242. function makeGrids(id) {
  3243. closeGrid();
  3244. let $title = $('#title');
  3245. $content_pane.removeClass('has_hidden_grid').addClass('has_grid');
  3246. if ( id === 'show_font_grid' || !$body.hasClass('has_images') ) { // only show font grid
  3247. $title.removeClass().addClass('font_grid');
  3248. $content_grid.addClass('has_font_grid');
  3249. $content_grid.append( fontGridItems() );
  3250. } else if ( id === 'show_image_grid' || !$body.hasClass('has_fonts') ) { // only show image grid
  3251. $title.removeClass().addClass('image_grid');
  3252. $content_grid.addClass('has_image_grid');
  3253. $content_grid.append( imageGridItems() );
  3254. } else { // show grid of both images and fonts
  3255. $title.removeClass();
  3256. if ( $body.hasClass() ) { $content_grid.addClass('has_image_grid'); } else { $content_grid.addClass('has_grid'); }
  3257. $content_grid.append( imageGridItems(), fontGridItems() );
  3258. }
  3259. }
  3260. // Click grid button
  3261. $('#sidebar_header').on('click', '#grid_btn, #show_font_grid, #show_image_grid', function(e) {
  3262. e.stopPropagation();
  3263. makeGrids($(this).attr('id'));
  3264. showGrid();
  3265. });
  3266.  
  3267. // ***** SCALE PREVIEWED IMAGES & FONTS ***** //
  3268. // Scale Fonts
  3269. function scaleFonts(e, incr, id) {
  3270. const $em = parseInt(getComputedStyle(document.body).fontSize); // pts/em
  3271. const getFontSize = function(el) { return parseFloat(el.css('font-size')); };
  3272. if ( id === 'decrease' ) { incr = 1/incr; }
  3273. if ( $content_pane.hasClass('has_grid') && ( $content_grid.hasClass('has_font_grid') || $content_grid.hasClass('has_grid') ) ) {
  3274. $content_grid.css({'font-size':( getFontSize($content_grid)/$em * incr ) +'em'});
  3275. return;
  3276. }
  3277. if ( $content_pane.hasClass('has_font') ) {
  3278. $content_font.css({'font-size':( getFontSize($content_font)/$em * incr ) +'em'});
  3279. return;
  3280. }
  3281. scrollThis('content_container','content_font');
  3282. }
  3283. function scaleGridImages(incr,id) {
  3284. if ( id === 'decrease' ) { incr = 1/incr; }
  3285. const $imageGridItem = $('.image_grid_item img');
  3286. let $image_grid_item_width = Number.parseFloat( $imageGridItem.width(),10) * incr;
  3287. let $image_grid_item_height = Number.parseFloat( $imageGridItem.height(),10) * incr;
  3288. let $image_grid_item_maxwidth = Number.parseFloat( $imageGridItem.css('maxWidth'),10) * incr;
  3289. let $image_grid_item_maxheight = Number.parseFloat( $imageGridItem.css('maxHeight'),10) * incr;
  3290. // prevent reducing grid image size on first scale click:
  3291. if ( $image_grid_item_width < $image_grid_item_maxwidth ) { $image_grid_item_width = $image_grid_item_maxwidth; }
  3292. if ( $image_grid_item_height < $image_grid_item_maxheight ) { $image_grid_item_height = $image_grid_item_maxheight; }
  3293. // set grid properties
  3294. $content_grid.css({'grid-template-columns':'repeat(auto-fill, minmax('+ ($image_grid_item_width +16) +'px, auto ) )'});
  3295. $content_grid.find('img').css({'max-width':( $image_grid_item_width ) +'px', 'max-height':( $image_grid_item_height ) +'px'});
  3296. return;
  3297. }
  3298. // Zoom Images on click
  3299. function scaleImages(e,incr,id) {
  3300. const $this_image = ( $('#iframe_body > img').length === 1 ? $('#iframe_body > img') : $content_image.find('img') );
  3301. const $this_link = $this_image.attr('src');
  3302. const $content_container = ( $('#iframe_body > img').length === 1 ? $('#iframe_body') : $('#content_container') );
  3303. let CC_width = function() { return Math.round($content_container.width()); };
  3304. let CC_height = function() { return Math.round($content_container.height()); };
  3305. const $this_width = Math.round($this_image.width());
  3306. const $this_height = Math.round($this_image.height());
  3307. const $iframe_delta = ( $('#iframe_body > img').length === 1 ? Number.parseInt($('#iframe_body').css('padding')) : 0 );
  3308. // scale grid images
  3309. if ( $content_pane.hasClass('has_grid') && ( $content_grid.hasClass('has_image_grid') || $content_grid.hasClass('has_grid') ) ) {
  3310. scaleGridImages(incr,id);
  3311. } else { // scale single images
  3312. getDimensions( $this_link, function( width, height ) {
  3313. if ( incr !== undefined && id !== undefined ) { // scale images by increment
  3314. $content_pane.addClass('has_zoom_image').removeClass('has_image'); // remove zoom classes in case window resized after zoom
  3315. if ( id === 'increase' ) {// && $this_width < width && $this_height < height) {
  3316. $content_image.add($this_image).css({'width':$this_width * incr, 'height': 'auto', 'max-width':'none', 'max-height':'none' });
  3317. }
  3318. if ( id === 'decrease' && ( $this_width >= 1 && $this_height >= 1 ) ) {
  3319. $content_image.add($this_image).css({'width':$this_width / incr, 'height': 'auto', 'max-width':'none', 'max-height':'none' });
  3320. }
  3321. // keep images centered when scaling
  3322. if ( Math.round($this_image.width()) >= CC_width() ) {
  3323. $content_container.scrollLeft( ( Math.round( ( $this_image.outerWidth(true) ) - CC_width() ) )/2 ) ;
  3324. }
  3325. if ( Math.round($this_image.height()) <= CC_height() ) {
  3326. $content_image.css({ 'top':( CC_height() - Math.round( $this_image.height() ) )/2 });
  3327. } else {
  3328. $content_image.css({ 'top':0 });
  3329. $content_container.scrollTop( ( Math.round($this_image.outerHeight(true)) - CC_height())/2 ) ;
  3330. }
  3331. } else { // else zoom single image on click
  3332. $content_image.removeAttr('style').find('img').removeAttr('style');
  3333. setContentHeight(); // needed to ensure current element positions/dimensions are set (for some reason; w/o, img_offset, etc. are inaccurate)
  3334. // but don't zoom small images:
  3335. if ( width <= CC_width() && height <= CC_height() ) {
  3336. $content_pane.removeClass('has_zoom_image').addClass('has_image');
  3337. $content_image.css({'top':$('#content_header').height()}).find('img').css({'cursor':'pointer'});
  3338. return;
  3339. }
  3340.  
  3341. const $CC_offset = $content_container.offset();
  3342. const $img_offset = $this_image.offset();
  3343. // x,y coordinates of zoom click as percentage of image width/height
  3344. const percentX = (e.pageX - $img_offset.left)/$this_width;
  3345. const percentY = (e.pageY - $img_offset.top)/$this_height;
  3346. // calculate scroll by pixel coordinates of full-size image - click coordinates and content_container offsets
  3347. const scrollX = (width * percentX) - e.pageX + $CC_offset.left - ($iframe_delta * width / $this_width);
  3348. const scrollY = (height * percentY) - e.pageY + $CC_offset.top - ($iframe_delta * height / $this_height);
  3349.  
  3350. $content_pane.toggleClass('has_image has_zoom_image');
  3351. if ( width > CC_width() && height < CC_height() || $this_width < CC_width() ) {
  3352. $content_container.scrollLeft( scrollX );
  3353. $content_image.css({ 'top':( CC_height() - Math.round( $this_image.height() ) )/2 });
  3354. }
  3355. if ( width < CC_width() && height > CC_height() ) {
  3356. $content_image.css({ 'top': 0 });
  3357. $content_container.scrollTop( scrollY );
  3358. }
  3359. if ( width > CC_width() && height > CC_height() ) {
  3360. $content_image.css({ 'top': 0 });
  3361. $content_container.scrollLeft( scrollX ) ;
  3362. $content_container.scrollTop( scrollY );
  3363. }
  3364. if ( $content_pane.hasClass('has_image') ) {
  3365. $content_image.css({'top':$('#content_header').height() });
  3366. }
  3367. }
  3368. setImageDimensions();
  3369. });
  3370. }
  3371. }
  3372.  
  3373. // Soom single image on click
  3374. $content_image.on('click','img', function(e) {
  3375. scaleImages(e);
  3376. });
  3377. // Scale Fonts and Images
  3378. function scalePreviewItems(e,id) { // combine scaling into one function
  3379. scaleImages(e, 1.125, id );
  3380. scaleFonts(e, 1.125, id );
  3381. }
  3382. // Scale Button
  3383. $('#scale').on('click','span',function(e) {
  3384. e.preventDefault();
  3385. e.stopPropagation();
  3386. let id = $(this).attr('id');
  3387. scalePreviewItems(e,id);
  3388. });
  3389. // ***** END SCALE PREVIEW ITEMS ***** //
  3390.  
  3391.  
  3392. // ***** AUDIO CONTENT ***** //
  3393. // Update Playlist
  3394. function updatePlaylist() {
  3395. let playlist = [];
  3396. $audio_files.not('.unchecked').each(function() {
  3397. playlist.push( thisID( $(this) ) );
  3398. });
  3399. return playlist;
  3400. }
  3401. // Randomize Shuffle List
  3402. function shuffleArray(array) {
  3403. for ( let i = array.length - 1; i > 0; i-- ) {
  3404. const j = Math.floor(Math.random() * (i + 1));
  3405. [array[i], array[j]] = [array[j], array[i]];
  3406. }
  3407. return array;
  3408. }
  3409. // Attach Shuffle List data to $audio_player
  3410. function updateShuffleList(id) {
  3411. if ( !$body.hasClass('shuffle_audio') ) {
  3412. return;
  3413. } else if ( id !== undefined ) { // don't include .playing and .unchecked track in shufflelist
  3414. let shuffleList = $audio_player.data('shufflelist');
  3415. if ( $(document.getElementById(id)).hasClass('unchecked') || $(document.getElementById(id)).hasClass('playing') ) {
  3416. shuffleList.splice(shuffleList.indexOf(id), 1);
  3417. $audio_player.data('shufflelist',shuffleList);
  3418. } else {
  3419. shuffleList.push(id);
  3420. shuffleList = shuffleArray( shuffleList );
  3421. }
  3422. } else {
  3423. let shuffleList = shuffleArray( updatePlaylist() );
  3424. $audio_player.data('shufflelist',shuffleList);
  3425. }
  3426. }
  3427. // Check/Uncheck Audio/Video Files
  3428. function toggleChecked(e) {
  3429. e.stopPropagation();
  3430. $(this).blur();
  3431. thisRow(this).toggleClass('unchecked');
  3432. updateShuffleList(thisRow(this).attr('id'));
  3433. }
  3434. $media_files.on('click','input', toggleChecked );
  3435. // Check/Uncheck all Audio/Video Files
  3436. function toggleAllChecked(e) {
  3437. e.stopPropagation();
  3438. $dir_list_row.find('input').trigger('click');
  3439. updateShuffleList();
  3440. }
  3441. $dir_list.find('#play_toggle').on('click', toggleAllChecked );
  3442.  
  3443. // Is Playing
  3444. function isPlaying(el) {
  3445. return (el !== undefined && el.get(0).currentTime > 0 && !el.get(0).paused && !el.get(0).ended); // returns true if all conditions are true
  3446. }
  3447. // Play Media
  3448. function playMedia(task) {
  3449. if ( $playing_file().hasClass('audio') ) { $audio_player.trigger(task); } else { $content_video.trigger(task); }
  3450. }
  3451. // Skip media tracks +/-10/30 seconds
  3452. function mediaSkip(e) {
  3453. const factor = ( e.key === 'ArrowLeft' ? -1 : 1 ); // forward or backward?
  3454. const skip = ( e.altKey && e.shiftKey ? 30 : e.altKey ? 10 : null ); // 30s or 10s?
  3455. const $player = ( $playing_file().hasClass('audio') ? $audio_player : $content_video ); // audio or video?
  3456. const time = $player.prop('currentTime'); // current time
  3457. $player.prop('currentTime', time + factor*(skip)); // set time
  3458. }
  3459.  
  3460. // Play/Pause Audio/Video
  3461. function playPauseMedia() {
  3462. let $player = ( $content_pane.hasClass('has_audio') ? $('#audio') : $('#content_video') );
  3463. if ( isPlaying( $player ) ) { $player.trigger('pause'); } else { $player.trigger('play'); }
  3464. }
  3465. // Play Next Track
  3466. function playPrevNextTrackBtn(el) {
  3467. let key = ( el.attr('id') === 'prev_track' ? 'ArrowLeft' : 'ArrowRight' );
  3468. playPrevNextTrack(key);
  3469. }
  3470. // Prev/Next Track buttons
  3471. $('.prev_next_track_btn').on( 'click', function() { playPrevNextTrackBtn( $(this) ); });
  3472.  
  3473. // Toggle Shuffle Play
  3474. $('#checkbox_div').on('click','#shuffle', function() {
  3475. $body.toggleClass('shuffle_audio');
  3476. updateShuffleList();
  3477. if ( $body.hasClass('shuffle_audio') && $('.playing').length === 0 ) {
  3478. playPrevNextTrack('ArrowRight');
  3479. } else {
  3480. // do nothing: i.e., allow current track to continue playing
  3481. }
  3482. });
  3483. // Toggle Loop Play
  3484. $('#checkbox_div').on('click','#loop', function() {
  3485. $body.toggleClass('loop_audio');
  3486. document.getElementById('audio').toggleAttribute('loop');
  3487. });
  3488.  
  3489. // Initialize Audio
  3490. function initMedia() {
  3491. $('#audio, #content_video').on('ended', function() {
  3492. playPrevNextTrack('ArrowRight');
  3493. scrollThis('tbody','playing');
  3494. });
  3495. }
  3496. // ***** END AUDIO PLAYBACK ***** //
  3497.  
  3498. // ***** IFRAME SETUP ***** //
  3499. // For directory display or editable text files
  3500. // If row is a directory, set up iFrameDirUI(); if it's an editable text document, set up iFrameTextEditingUI().
  3501. function setUpIframeUI(bool) {
  3502. if ( window.self !== window.top ) {
  3503. const $textFiles = $row_types.markdown.concat($row_types.text, $row_types.code); // define which files are editable
  3504. // if selected index item is a directory, set up the directory UI....
  3505. if ( window.location.pathname.endsWith('/') ) {
  3506. iFrameDirUI( $('#iframe_body') );
  3507. }
  3508. if ( JSON.parse(bool) === true && $textFiles.includes( window.location.pathname.slice( window.location.pathname.lastIndexOf('.') + 1 ) ) ) {
  3509. $iFrame_head.append('<style>'+ $text_editing_style_rules +'</style>');
  3510. $iFrame_head.append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css"></link>');
  3511. let splitClass = ( getQuery('split_view') === 'true' ? 'split_view' : '' );
  3512. let viewClass = getQuery('default_text_view');
  3513. let warnings = '<div id="warnings"><h3>Warning:</h3><p id="warning_unsaved">You have unsaved changes.</p><p id="warning_clear">Are you sure you want to clear all your text?</p><p id="warning_local">Can\'t load local directories or files from non-local web pages. Use your browser\'s bookmarks or enter the URL manually.</p><div><button id="warning_ignore_btn">Don\'t Save</button><button id="warning_cancel_btn" >Cancel</button><button id="warning_clear_btn">Clear</button><button id="warning_save_btn">Save</button><button id="warning_ok_btn">OK</button></div></div>';
  3514.  
  3515. TextEditing( '#iframe_body' );
  3516. $('#iframe_body').removeClass().addClass(splitClass).addClass(viewClass).prepend(warnings);
  3517. $('#content_source').removeClass().prop('disabled',false);
  3518. }
  3519. }
  3520. }
  3521. // IFRAME DIRECTORY Prep
  3522. function iFrameDirUI(el) { // el = iframeBody
  3523. let parentLink = decodeURIComponentSafe(window.location.pathname);
  3524. parentLink = parentLink.split('/').slice(0,-2).join('/') +'/'+ window.location.search;
  3525. let queryPrefs = window.location.search;
  3526. queryPrefs = queryPrefs.slice(1).split('&');
  3527. queryPrefs = queryPrefs.map(x => x.split('='));
  3528. let prefs = Object.fromEntries(queryPrefs); // convert query array of arrays to object
  3529. let sortPref = prefs.sort_by; // sort determined by parent's current sorting pref
  3530. let numbersPref = prefs.show_numbers;
  3531. let viewSourcePref = prefs.view_source;
  3532. let iconsPref = prefs.use_custom_icons;
  3533. if ( viewSourcePref === 'true' ) {
  3534. return; // show raw directory index
  3535. } else {
  3536. if ( numbersPref === 'true' ) {
  3537. $('#iframe_body').addClass('show_numbers');
  3538. }
  3539. if ( iconsPref === 'true' ) {
  3540. $('#iframe_body').addClass('use_custom_icons');
  3541. }
  3542. $iFrame_head.find('style').remove();
  3543. $iFrame_head.append('<style>'+ $iframe_styles +'</style>');
  3544.  
  3545. const parentLinkCell = '<tr id="change_dirs"><th colspan=4><span id="parent"><a href="'+ parentLink +'">Parent Directory</a></span><span id="open_in_sidebar"><a href="">Open in Sidebar</a></span></th></tr>';
  3546. const sortingRow = '<tr id="sorting"><th class="sorting" id="sort_by_name" colspan="2"><span>Name</span></th><th class="sorting" id="sort_by_default" colspan="2"><span>Default</span></th></tr><tr id="sorting_row"><th class="sorting" id="sort_by_ext"><span>Ext</span></th><th class="sorting" id="sort_by_size"><span>Size</span></th><th class="sorting" id="sort_by_date"><span>Date</span></th><th class="sorting" id="sort_by_kind"><span>Kind</span></th></tr>';
  3547. const preppedIndex = makeNewIndex($('#iframe_body'),sortPref);
  3548. const iFrameTable = $('<table id="dir_list"><thead id="thead">'+ parentLinkCell + sortingRow +'</thead><tbody id="tbody"></tbody></table>');
  3549. // append prepped index
  3550. el.empty().append(iFrameTable).find('tbody').append(preppedIndex);
  3551. $('#iframe_body').find('#tbody').css({'top':$('#iframe_body').find('#thead').height() +'px'});
  3552. $('#iframe_body').data('sort_direction',1).find('#dir_list').addClass('sort_by_'+ sortPref); // initial directory sort
  3553. }
  3554. }
  3555.  
  3556. // IFRAME Directory sorting
  3557. $('#iframe_body').on('click','.sorting', function() {
  3558. const $dir_list_row = $('#iframe_body').find('#tbody').find('tr');
  3559. const id = $(this).attr('id');
  3560. if ( $('#iframe_body').data('sorting') !== id ) { // if clicking sorting item for the first time
  3561. $('#iframe_body').data('sorting',id);
  3562. $('#iframe_body').data('sorting',id).data('sort_direction', 1 );
  3563. $(this).removeClass('down');
  3564. } else { // clicking the same sorting item again -- reverse sort order
  3565. $('#iframe_body').data('sort_direction', $('#iframe_body').data('sort_direction') * -1 );
  3566. $(this).toggleClass('down');
  3567. }
  3568. const sort_direction = $('#iframe_body').data('sort_direction');
  3569. const $sorted_index = sortDirList( $dir_list_row, id, sort_direction );
  3570. $('#iframe_body').find('#dir_list').removeClass().addClass(id).find('#tbody').empty().append($sorted_index);
  3571. });
  3572. // IFRAME directory and file navigation
  3573. $('#iframe_body').on('click','#dir_list tr a', function(e) {
  3574. e.preventDefault();
  3575. let href = window.location.href;
  3576. let link = $(this).attr('href');
  3577. let kind = $(this).closest('tr').attr('data-kind');
  3578. let dir = href.slice(0,href.lastIndexOf('/') + 1) + window.location.search;
  3579. if ( kind === 'dir' || $(this).parent().attr('id') === 'parent' ) {
  3580. if ( $(this).parent().attr('id') !== 'parent' ) { link += window.location.search; }
  3581. sendMessage('top','iframe_dir','',link);
  3582. window.location = link;
  3583. } else { // display audio, font, image, pdf, video in corresponding content container
  3584. e.preventDefault();
  3585. if ( window.location.protocol.indexOf('file') === -1 ) { link = window.location.protocol +'//'+ window.location.hostname + window.location.pathname + link; } // send full path for non-local files
  3586. let args = [link,kind,dir];
  3587. sendMessage('top','iframe_file','',args);
  3588. if ( !['audio','video','font','image','pdf'].includes(kind) ) {
  3589. window.location = link; // load everything else in iframe
  3590. }
  3591. }
  3592. });
  3593. // Open IFRAME directory in sidebar
  3594. $('#open_in_sidebar').on('click',function(e) {
  3595. e.preventDefault();
  3596. let link = decodeURIComponentSafe(window.location.href.toString());
  3597. sendMessage('top','open_in_sidebar','',link);
  3598. });
  3599.  
  3600. // IFRAME Single Image (after clicking an image link in the content dir list
  3601. $('#iframe_body').ready(function() {
  3602. const $imageFiles = $row_types.image;
  3603. if ( $imageFiles.includes( window.location.pathname.slice( window.location.pathname.lastIndexOf('.') + 1 ).toLowerCase() ) ) {
  3604. const $iframe_image_styles =
  3605. '#iframe_body { padding:1em; position:absolute; top:0; bottom:0; left:0; right:0; box-sizing:border-box; text-align:center}'+
  3606. '#iframe_body > img { max-width:100%; max-height:100%; }'+
  3607. '#iframe_body.zoom { padding:0; }'+
  3608. '#iframe_body.zoom > img { max-width:unset; max-height:unset; }'
  3609. ;
  3610. $iFrame_head.append('<style>'+ $iframe_image_styles +'</style>');
  3611.  
  3612. $('img').on('click',function(e) {
  3613. scaleImages(e);
  3614. $('#iframe_body').toggleClass('zoom');
  3615. });
  3616. }
  3617. });
  3618.  
  3619. //***** TEXT EDITING PANE *****//
  3620. function textEditorUI() { //
  3621. if ( $content_text.children().length === 0 ) { // only add UI once
  3622. $body.addClass('has_text');
  3623. $content_pane.removeClass('has_dir');
  3624. if ( $content_pane.hasClass('has_grid') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  3625. TextEditing('#content_text');
  3626. $content_text.find('#content_preview').html($content_text.find('#content_source').val()); // make sure any source text is also previewed.
  3627. if ( getQuery('split_view') === 'true' || getQuery('default_text_view') === 'source_text' ) { $content_text.find('#content_source').focus(); }
  3628. } else { // show text editor
  3629. if ( !$body.hasClass('has_text') ) {
  3630. $body.addClass('has_text');
  3631. } else if ( $body.hasClass('has_text') || $body.hasClass('has_hidden_text') ) {
  3632. $body.toggleClass('has_text has_hidden_text');
  3633. }
  3634. if ( $content_pane.hasClass('has_grid') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  3635. if ( $content_pane.hasClass('has_hidden_grid ') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  3636. }
  3637. setContentTitle();
  3638. setContentHeight();
  3639. }
  3640. // show text editor pane
  3641. $('#text_editor, #text_editor_row').on('click', function(e) {
  3642. e.preventDefault();
  3643. textEditorUI();
  3644. });
  3645.  
  3646. // Main Text Editing Function
  3647. function TextEditing(id) { // container_el = $content_text or $content_iframe body
  3648. let container_el = $(id);
  3649. const $srctxt = ( container_el.find('> pre').length ? container_el.find('> pre').text() : container_el.html() ); // source text equals file content or nothing
  3650.  
  3651. MDbuildUI(id);
  3652.  
  3653. const $toolbar = container_el.find('#toolbar');
  3654. const $source = container_el.find('#content_source');
  3655. const $preview = container_el.find('#content_preview');
  3656. const $MDhandle = container_el.find('#text_editing_handle');
  3657.  
  3658. MDsetupTextEditingUI(id,$srctxt);
  3659. // Toolbar button functions
  3660. $toolbar.on('click','li,span',function(e) {
  3661. e.stopPropagation();
  3662. MDtoolBarFunctions($(this).attr('id'));
  3663. });
  3664. $(window).on('resize',function() {
  3665. $source.add($preview).add($MDhandle).attr('style','');
  3666. });
  3667. $('body#top').on('input', '#content_source', function() {
  3668. $source.add($preview).css({'height':$('#main_content').height() - $('#content_header').height() - 32 });
  3669. });
  3670.  
  3671. // Resize
  3672. $MDhandle.on('mousedown', function(e) {
  3673. e.stopPropagation();
  3674. MDresizeSplit($MDhandle,$source,$preview);
  3675. });
  3676. // Click labels to toggle checkboxes
  3677. $preview.add($toolbar).on('click','label', function(e) {
  3678. e.stopPropagation();
  3679. $(this).siblings('input').click();
  3680. });
  3681. // Sync scroll
  3682. $source.on('scroll',function() { MDsyncScroll(this); });
  3683. $preview.on('scroll',function() { MDsyncScroll(this); });
  3684.  
  3685. // TEXT EDITING
  3686. // Generate Preview
  3687. const $source_text = ( $source.length === 0 ? '' : $source.val() );
  3688. MDmarkdown( $source_text, $preview );
  3689.  
  3690. // Live preview update, and set edited classes for unsaved warning
  3691. $source.on('input', function() {
  3692. if ( !$('body').hasClass('edited') && $(this).parents('#top').length === 1 ) {
  3693. $('body#top').addClass('edited');
  3694. }
  3695. if ( !$('body').hasClass('edited') && $(this).parents('#iframe_body').length === 1 ) {
  3696. $('body#iframeBody').addClass('edited');
  3697. sendMessage('top','iframe_edited','','');
  3698. }
  3699. MDlivePreview($source,$preview);
  3700. });
  3701. // Checklists
  3702. MDsetChecklistClass();
  3703. // Live checkboxes
  3704. $preview.on('click','.checklist input',function(e) {
  3705. e.stopPropagation();
  3706. MDliveCheckBoxes($(this),$source,$preview);
  3707. });
  3708. // Preview TOC click navigation
  3709. $preview.on('click','.table-of-contents a',function(e) {
  3710. e.preventDefault();
  3711. MDtocClick($(this),$preview);
  3712. });
  3713. $preview.on('click','.uplink',function(e) {
  3714. e.stopPropagation();
  3715. MDheaderClick($preview);
  3716. });
  3717. }
  3718. ///// END MAIN MD FUNCTION
  3719.  
  3720. // MARKDOWN Functions
  3721. // MD Build UI
  3722. function MDbuildUI(id) {
  3723. const toggleSplitBtn = $('<li id="toggle_split" title="Toggle Split"></li>');
  3724. const syncScrollEl = $('<li id="sync_scroll"><input name="sync_scroll" type="checkbox"><label for="sync_scroll">Sync Scroll</label></li>');
  3725. const toggleSrcBtn = $('<li id="show_source" title="Show Source"></li>');
  3726. const togglePreviewBtn = $('<li id="show_preview" title="Show Preview"></li>');
  3727. const clearTextBtn = $('<li id="clear_text" title="Clear Text">Clear</li>');
  3728. const saveBtn = $('<li id="save_btn" title=""><div><span id="save_text"><a target="_blank">Save Source</a></span><span id="save_HTML">Save HTML</span></div></li>');
  3729. const buttonsCont = $('<ul id="toolbar"></ul>');
  3730. buttonsCont.append(toggleSrcBtn, togglePreviewBtn, toggleSplitBtn, syncScrollEl, saveBtn, clearTextBtn);
  3731. const textEditingUI = '<textarea id="content_source"></textarea><div id="content_preview" class="markdown-body"></div><div id="text_editing_handle"></div>';
  3732. // append the UI to the container_el
  3733. $(id).prepend(buttonsCont).append(textEditingUI);
  3734. }
  3735.  
  3736. // MD Set up UI
  3737. function MDsetupTextEditingUI(id,sourceText) {
  3738. $(id).find('pre').first().remove();
  3739. $(id).find('#content_source').val(sourceText); // set source text from pre
  3740. if ( getQuery('split_view') === 'true' ) { $('body').addClass('split_view'); } else { $('body').removeClass('split_view'); }
  3741. if ( getQuery('default_text_view') === 'preview' ) { $('body').addClass('preview_text').removeClass('source_text'); } else { $('body').addClass('source_text').removeClass('preview_text'); }
  3742. if ( getQuery('sync_scroll') === 'true' ) { $('#sync_scroll input').prop({checked:true}); }
  3743. }
  3744. // MD UI Buttons functions
  3745. function MDtoolBarFunctions(id) {
  3746. let $thisFileName;
  3747. let container_el = $(getElById(id)).closest('body');
  3748. let sourceEl = container_el.find('#content_source');
  3749. let previewEl = container_el.find('#content_preview');
  3750. if ( $body.hasClass('has_text') ) {
  3751. $thisFileName = 'untitled';
  3752. } else {
  3753. $thisFileName = decodeURI(window.location.pathname.slice(window.location.pathname.lastIndexOf('/') + 1));
  3754. }
  3755. const $saveHTMLOpen = '<!DOCTYPE html><html><head><title></title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css"></link><style></style><script></script></head><body lang="en" class="markdown-body">';
  3756. const $saveHTMLClose = '</body></html>';
  3757. switch (id) {
  3758. case 'toggle_split':
  3759. $('body').toggleClass('split_view').find('#content_source,#content_preview,#text_editing_handle').attr('style','');
  3760. if ( container_el.hasClass('source_text') ) {
  3761. sourceEl.focus();
  3762. document.getElementById('content_source').setSelectionRange(0,0);
  3763. }
  3764. break;
  3765. case 'show_source':
  3766. container_el.removeClass('split_view preview_text').addClass('source_text').find('#content_source,#content_preview,#text_editing_handle').attr('style',''); // remove styles in case split has been resized
  3767. sourceEl.css({'width':'100%'}).focus();
  3768. document.getElementById('content_source').setSelectionRange(0,0);
  3769. break;
  3770. case 'show_preview':
  3771. container_el.removeClass('split_view source_text').addClass('preview_text').find('#content_source,#content_preview,#text_editing_handle').attr('style','');
  3772. break;
  3773. case 'clear_text':
  3774. container_el.addClass('has_warning').find('#warnings').removeClass().addClass('clear');
  3775. break;
  3776. case 'save_text':
  3777. saveMD( $thisFileName, sourceEl.val() );
  3778. break;
  3779. case 'save_HTML':
  3780. saveMD( $thisFileName.slice(0,$thisFileName.lastIndexOf('.') + 1) + 'html', $saveHTMLOpen + MDprepHTML(previewEl.html()) + $saveHTMLClose );
  3781. break;
  3782. }
  3783. }
  3784. // MD Custom pre- and post-processing for text.
  3785. function MDaddHeaderIDs(match, p1, p2, p3, offset, string) { // create header ids for TOC
  3786. return '<h'+ p1 +' id="'+ p3.toLowerCase().replace(/\s/g,'-') +'" ' + p2 +'>'+ p3;
  3787. }
  3788. function MDcustomPreProcess(src) {
  3789. return src; // we're not doing anything here just yet...
  3790. }
  3791. function MDcustomPostProcess(html) {
  3792. html = html.replace(/<(p|li|dt|dd)>\-*\s*\[\s*x\s*\]\s*(.+?)<\/(p|li|dt|dd)>$/gm,'<$1 class="checklist"><input type="checkbox" checked><label>$2</label></$3>') // checkboxes in p,li,dt,dd
  3793. .replace(/<(p|li|dt|dd)>-*\s*\[\s{1,}\]\s*(.+?)<\/(p|li|dt|dd)>$/gm,'<$1 class="checklist"><input type="checkbox"><label>$2</label></$3>') // checkboxes
  3794. // .replace(/<li><p class="checklist">"/g,'<li class="checklist"><p>')
  3795. .replace(/^<h(\d)([^>]*)>([^<]+)/gm, MDaddHeaderIDs) // add header IDs;
  3796. .replace(/<\/h(\d)>/g,'<span class="uplink">&uarr;</span></h$1>');
  3797. return html;
  3798. }
  3799. //MD Render markdown from preprocessed source text
  3800. function MDmarkdown(sourceText,previewEl) {
  3801. const MDit = window.markdownit({linkify:false,typography:false,html:true})
  3802. .use(window.markdownitMultimdTable, {enableMultilineRows: true})
  3803. .use(window.markdownitSub)
  3804. .use(window.markdownitSup)
  3805. .use(window.markdownitFootnote)
  3806. .use(window.markdownitCentertext)
  3807. .use(window.markdownitDeflist)
  3808. .use(window.markdownitTocDoneRight)
  3809. ;
  3810. let MDpreview = MDit.render( MDcustomPreProcess( sourceText ) );
  3811. previewEl.html( MDcustomPostProcess( MDpreview ) ); // set previewed html
  3812. }
  3813. // MD Live preview, add edited warning
  3814. function MDlivePreview(sourceEl,previewEl) {
  3815. MDmarkdown( sourceEl.val(),previewEl );
  3816. MDsetChecklistClass();
  3817. }
  3818.  
  3819. // MD Live Checkboxes prep: find each instance of [ ] or [x] and replace text in index = to clicked checkbox in Preview.
  3820. function MDreplaceAt(str, replacement, position) {
  3821. str = str.substring(0, position) + replacement + str.substring(position + replacement.length);
  3822. return str;
  3823. }
  3824. function MDreplaceNthSubStr(str,substr,replacement,index) {
  3825. let count = 0;
  3826. let found = substr.exec(str);
  3827. while ( found !== null ) {
  3828. if ( count === index ) {
  3829. return MDreplaceAt(str, replacement, found.index );
  3830. } else {
  3831. count++;
  3832. found = substr.exec(str);
  3833. }
  3834. }
  3835. }
  3836. // MD Live Checkboxes
  3837. function MDliveCheckBoxes(checkbox,sourceEl,previewEl) {
  3838. $('.checklist').removeClass('clicked');
  3839. checkbox.closest('p,li,dt,dd').addClass('clicked');
  3840. const thisIndex = previewEl.find('.checklist').index( $('.clicked') );
  3841. const srctext = sourceEl.val();
  3842. const substr = new RegExp(/\[\s*.\s*\]/g);
  3843. const replacement = ( checkbox.is(':checked') ? '[x]' : '[ ]' );
  3844. sourceEl.val( MDreplaceNthSubStr(srctext, substr, replacement, thisIndex) );
  3845. }
  3846. // MD Checkbox list class: Prevent checkbox lists from having list bullets
  3847. function MDsetChecklistClass() {
  3848. $('input[type="checkbox"]').closest('ul').addClass('no_list');
  3849. }
  3850.  
  3851. // MD Resize Split View
  3852. function MDresizeSplit(handle,sourceEl,previewEl) {
  3853. let $sidebarWidth = $('#sidebar').outerWidth();
  3854. let $pageWidth = window.innerWidth;
  3855.  
  3856. $(document).on('mousemove',function(e) {
  3857. e.stopPropagation();
  3858. e.preventDefault();
  3859. let pageX = e.pageX;
  3860. if ( pageX > $sidebarWidth + 100 && pageX < $pageWidth - 100 ) { // min widths
  3861. handle.css({'left': pageX - $sidebarWidth - 4 + 'px'});
  3862. sourceEl.css({'width': pageX - $sidebarWidth + 'px'});
  3863. previewEl.css({'left': sourceEl.outerWidth() + 'px'});
  3864. }
  3865. });
  3866. handle.on('mouseup',function() {
  3867. $(document).off('mousemove');
  3868. });
  3869. }
  3870. // MD UI Sync Scroll
  3871. function MDpercentage(el) { return (el.scrollTop / (el.scrollHeight - el.offsetHeight)); }
  3872. function MDsyncScroll(el1) {
  3873. let el2 = ( el1.getAttribute('id') === 'content_preview' ? document.getElementById('content_source') : document.getElementById('content_preview') );
  3874. if ( document.querySelector('input[name="sync_scroll"').checked ) {
  3875. el2.scrollTo( 0, (MDpercentage(el1) * (el2.scrollHeight - el2.offsetHeight)).toFixed(0) ); // toFixed(0) prevents scrolling feedback loop
  3876. }
  3877. }
  3878. // click TOC anchors
  3879. function MDtocClick(el,previewEl) {
  3880. let thisId = el.attr('href');
  3881. if ( thisId ) {
  3882. previewEl.scrollTop( $(thisId).offset().top - 48 );
  3883. }
  3884. }
  3885. // click Headers to return to TOC or top
  3886. function MDheaderClick(previewEl) {
  3887. if ( previewEl.find('.table-of-contents').length > 0 ) {
  3888. document.getElementsByClassName('table-of-contents')[0].scrollIntoView(true);
  3889. } else {
  3890. document.getElementById('preview').scroll(0,0);
  3891. }
  3892. }
  3893. // MD Clear text source
  3894. function clearText(container_el) {
  3895. if ( window.top !== window.self ) { // if iframe, send message to top (to remove iframe_edited class)
  3896. sendMessage('top','clear');
  3897. }
  3898. container_el.find('#content_source').show().focus().val('');
  3899. container_el.find('#content_preview').empty();
  3900. container_el.removeClass('edited has_warning');
  3901. }
  3902. // MD SAVE SOURCE or HTML
  3903. function MDprepHTML(data) {
  3904. data = data.replace(/<span\sclass="uplink">.<\/span>/g,'');
  3905. return data;
  3906. }
  3907. function saveMD(filename, data) {
  3908. let blob = new Blob([data], {type: 'text/plain'});
  3909. let downloadEl = window.document.createElement('a');
  3910. downloadEl.href = window.URL.createObjectURL(blob);
  3911. downloadEl.download = filename;
  3912. document.body.appendChild(downloadEl);
  3913. downloadEl.click();
  3914. document.body.removeChild(downloadEl);
  3915. URL.revokeObjectURL(blob);
  3916. if ( window.top !== window.self ) { // if iframe, send message to top
  3917. sendMessage('top','clear');
  3918. }
  3919. $('body,#content_source,#content_text').removeClass('edited');
  3920. }
  3921. // list of functions to remember while sending messages and then execute after warning button click
  3922. function doFunction(funcName,args) {
  3923. var funcDictionary = { 'setLocation':setLocation, 'resetContent':resetContent, 'closeContent':closeContent, 'clickThis':clickThis, 'clickRow':clickRow, 'doubleClickRow':doubleClickRow, 'indexNavigation':indexNavigation, 'clearText':clearText, 'null':null };
  3924. return funcName === 'null' ? null : funcDictionary[funcName](args);
  3925. }
  3926. // Show warning after certain user actions if text editor or iframe has edited text; otherwise do the action.
  3927. function showWarning(funcName,args) {
  3928. // Don't show the warning if func = indexNavigation or clickRow; i.e., just hide text editor;
  3929. // In other words, only show warning when changing directories or if iframe content has been edited
  3930. if ( ( $('body').hasClass('edited') && funcName !== 'indexNavigation' && funcName !== 'clickRow' ) || $('body').hasClass('iframe_edited') ) {
  3931. if ( $('body').hasClass('edited') ) { // show warning and text editor (if hidden)
  3932. $body.addClass('has_warning').find('#warnings').removeClass().addClass('unloading');
  3933. $body.removeClass('has_hidden_text').addClass('has_text');
  3934. }
  3935. if ( $('body').hasClass('iframe_edited') ) { // if iframe is edited, send unloading message
  3936. sendMessage('iframe','unloading',funcName,args); // upon receipt of message, iframe will show its warning message, based on the funcName
  3937. }
  3938. } else {
  3939. doFunction(funcName,args);
  3940. }
  3941. }
  3942. // Send a message to iframe or parent
  3943. function sendMessage(target,message,funcName,args) {
  3944. var messageObj = { 'messageContent': message, 'functionName': funcName, 'arguments': args };
  3945. if ( target === 'iframe' ) {
  3946. let contentIFrame = document.getElementById('content_iframe');
  3947. contentIFrame.contentWindow.postMessage( messageObj, '*' );
  3948. }
  3949. if ( target === 'top' ) {
  3950. window.parent.postMessage( messageObj, '*');
  3951. }
  3952. }
  3953. // Receive a message from iframe or parent, do appropriate action
  3954. function receiveMessage(e) {
  3955. if ( e.origin === 'null' || e.origin === $origin ) {
  3956. let $message = e.data.messageContent;
  3957. let funcName = e.data.functionName;
  3958. let args = e.data.arguments;
  3959.  
  3960. if ( $message === 'split_view' ) {
  3961. $iframe_body.toggleClass('split_view');
  3962. }
  3963. if ( $message === 'default_text_view' ) {
  3964. $iframe_body.toggleClass('preview_text source_text').removeClass('split_view');
  3965. }
  3966. // warn iframe that user wants to change iframes
  3967. if ( $message === 'unloading' && !$iframe_body.hasClass('has_warning') ) {
  3968. $iframe_body.addClass('has_warning').find('#warnings').removeClass().addClass('unloading').attr('data-function_name',funcName).attr('data-args',args);
  3969. }
  3970. // let top know iframe text has been edited
  3971. if ( $message === 'iframe_edited' && !$('body#top').hasClass('iframe_edited') ) {
  3972. $('body#top').addClass('iframe_edited');
  3973. }
  3974. if ( $message === 'ignore' || $message === 'clear' ) {
  3975. $('body#top').removeClass('iframe_edited');
  3976. if ( $message === 'ignore' ) { doFunction(funcName,args); }
  3977. }
  3978. if ( $message === 'iframe_dir' ) {
  3979. $dir_list.addClass('has_dir');
  3980. $content_iframe.addClass('has_dir').data('iframe_dir',args);
  3981. let title = decodeURIComponentSafe(args);
  3982. $('#title span').text(title.slice(0,title.indexOf('?')));
  3983. setContentHeight();
  3984. }
  3985. if ( $message === 'iframe_file' ) {
  3986. let link = args[0];
  3987. let kind = args[1];
  3988. let dir = (args.length === 3 ? args[2] : link );
  3989. let title = decodeURIComponentSafe(link);
  3990. if ( kind === 'audio' ) { // load audio files
  3991. $audio_player.attr('src', link );
  3992. $content_pane.addClass('has_audio');
  3993. closeMedia('video');
  3994. $('#content_audio_title td').empty().text( title );
  3995. } else if ( ['font','image','pdf','video'].includes(kind) ) { // load other non-iframe content
  3996. $content_pane.toggleClass('has_dir has_hidden_dir has_'+ kind );
  3997. if ( kind === 'image' ) {
  3998. $('#content_'+ kind).addClass('has_content').find('img').attr('src',link);
  3999. setImageDimensions();
  4000. } else if ( kind === 'video' ) {
  4001. closeMedia('audio');
  4002. } else {
  4003. $('#content_'+ kind).addClass('has_content').attr('src',link);
  4004. }
  4005. $('#title span').text(title);
  4006. } else { // load iframe content
  4007. $content_iframe.addClass('has_file').data('iframe_dir',dir); // set file container link
  4008. $('#title span').text(title);
  4009. }
  4010. setContentHeight();
  4011. }
  4012. if ( $message === 'open_in_sidebar' ) {
  4013. let $query_str = getQueryPrefs();
  4014. if ($query_str.has('selected') ) { $query_str.delete('selected'); }
  4015. if ($query_str.has('history') ) { $query_str.delete('history'); }
  4016. window.location = args.slice(0,args.lastIndexOf('/?')+1) +'?'+ $query_str.toString();
  4017. }
  4018.  
  4019. }
  4020. }
  4021. window.addEventListener('message',receiveMessage,false);
  4022.  
  4023. // Edited Warning buttons: what to do when the user clicks a warning button
  4024. function editedWarningButtons(id) {
  4025. let btn = $(document.getElementById(id));
  4026. let container_el = btn.closest('body');
  4027. let func = $('#warnings').attr('data-function_name');
  4028. let args = $('#warnings').attr('data-args');
  4029. switch(id) {
  4030. case 'warning_ignore_btn': // do the user initiated func without saving the edited text
  4031. if ( window.self !== window.top ) { // if iframe, send message to top
  4032. sendMessage('top','ignore',func,args);
  4033. }
  4034. container_el.removeClass('edited has_text has_warning');
  4035. clearText(container_el);
  4036. break;
  4037. case 'warning_cancel_btn': // cancel the func
  4038. container_el.removeClass('has_warning').find('#warnings').removeClass();
  4039. break;
  4040. case 'warning_clear_btn': // clear the text editor
  4041. clearText(container_el);
  4042. break;
  4043. case 'warning_save_btn': // save the text
  4044. if ( window.top !== window.self ) { // if iframe, send message to top
  4045. sendMessage('top','clear');
  4046. }
  4047. container_el.removeClass('edited has_warning');
  4048. $('#save_text').click();
  4049. break;
  4050. case 'warning_ok_btn': // clear the text editor
  4051. $('body').removeClass('has_warning').find('#warnings').removeClass('local');
  4052. break;
  4053. }
  4054. }
  4055. $('#warnings').on('click','button',function(e) {
  4056. e.preventDefault();
  4057. editedWarningButtons( $(this).attr('id') );
  4058. });
  4059. // Edited Warning overlay: prevent user clicks on rest of UI
  4060. $('#overlay').on('click mousedown mouseup',function(e) {
  4061. e.preventDefault();
  4062. e.stopPropagation();
  4063. return;
  4064. });
  4065. // END Text Editing
  4066.  
  4067. // PLAYLISTS
  4068. $('#open_playlist_label').on('click',function(e) { $('.menu').hide(); });
  4069. // Open font
  4070. $('#bookmarks').on('change','#open_playlist',function(e) {
  4071. openPlaylist(e);
  4072. });
  4073. function convertPlaylist(items) {
  4074. let preppedIndex = '';
  4075. let preppedRow = '';
  4076. let id = 0, rows, info, title, time = '0', display_time = '—', link, kind = '', display_kind, ext;
  4077. items = items.replace(/\s*#EXTM3U.*\n/,'\n').replace(/^\*\n{2,}/gm,'\n');
  4078. if ( items.indexOf('#EXTINF:') !== -1 ) {
  4079. rows = items.split('#EXTINF:');
  4080. } else {
  4081. rows = items.split('\n');
  4082. }
  4083. for ( let row of rows ) {
  4084. if ( row.indexOf('\n') !== -1 && row.trim().length > 0 ) {
  4085. row = row.trim().split('\n');
  4086. info = row[0];
  4087. time = info.slice(0,info.indexOf(','));
  4088. display_time = new Date(time * 1000).toISOString().substr(11, 8);
  4089. title = info.slice(info.indexOf(',') + 1);
  4090. link = row[1];
  4091. } else {
  4092. title = decodeURIComponentSafe(row.slice(row.lastIndexOf('/') + 1));
  4093. link = row;
  4094. }
  4095. ext = link.slice(link.lastIndexOf('.') + 1);
  4096.  
  4097. if ( $row_types.audio.includes( ext ) ) {
  4098. kind = 'audio';
  4099. display_kind = 'Audio';
  4100. } else if ( $row_types.video.includes( ext ) ) {
  4101. kind = 'video';
  4102. display_kind = 'Video';
  4103. }
  4104. if ( kind !== '' ) { // only allow supported media types
  4105. preppedRow = '<tr id="rowid-'+ id +'" class="file media '+ kind +'" data-ext="'+ ext +'"><td class="name" data-name="'+ title +'"><a class="icon" href="'+ link +'"><span><input type="checkbox" tabindex="-1" checked="true">'+ title +'</span></a></td><td class="size details" data-size="'+ time +'">'+ display_time +'</td><td class="date details" data-date="0">—</td><td class="kind details" data-kind="'+ kind +'">'+ display_kind +'</td><td class="ext details" data-ext="'+ ext +'"></td></tr>';
  4106. preppedIndex += preppedRow;
  4107. }
  4108. id++;
  4109. }
  4110. closeGrid();
  4111. closeContent();
  4112. closeOtherContent();
  4113. $dir_list.find('tbody').empty().addClass('playlist').append(preppedIndex);
  4114. $dir_list.find('#stats').html(getIndexStats($dir_list.find('#tbody tr')));
  4115. $body.addClass('has_playlist has_audio');
  4116. if ( $body.hasClass('autoload_media') ) { $('#rowid-1').click(); }
  4117. setContentTitle();
  4118. setContentHeight();
  4119. scrollThis('tbody','selected',false);
  4120. }
  4121. function openPlaylist(evt) {
  4122. if (window.File && window.FileReader && window.FileList && window.Blob) {
  4123. var files = evt.target.files;
  4124. var reader = new FileReader();
  4125. reader.onload = function(file) {
  4126. convertPlaylist(file.target.result);
  4127. return true;
  4128. };
  4129. reader.readAsText(files[0]);
  4130. document.title = "Playlist: "+ files[0].name;
  4131. $('#parents_dir_menu').find('> div').empty().html( files[0].name );
  4132. $('#open_playlist').val('');
  4133. } else {
  4134. alert('File APIs are not fully supported in this browser.');
  4135. }
  4136. }
  4137.  
  4138. })();
  4139. // FINIS! DEO GRATIAS.