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

  1. // ==UserScript==
  2. // @name Supercharged Local Directory File Browser
  3. // @version 4.1.3
  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','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.3**
  222. // **FIXED:** _Finally_ fixed image scaling and zooming. Sorry for the delay.
  223. // **IMPROVED:** Allow image scaling > 100%.
  224. // **IMPROVED:** Show image scale percentage in the content title bar.
  225. // **IMPROVED:** Show custom file icons in content title bar.
  226. // **IMPROVED:** Highlight grid button when grid is loaded (or hidden).
  227. // **FIXED:** Invisible files were being selected even if "Show invisibles" was unchecked.
  228. // Various other small fixes and style tweaks.
  229.  
  230. // **VERSION 4.1.2**
  231. // **FIXED, CHANGED, & IMPROVED:** Image, font, and font glyph grids.
  232. // - 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.
  233. // - Also added arrow navigation for font glyphs, and :hover and selected styles.
  234. // - Fixed a deeply-buried bug that prevented the selected grid item from scrolling into view with arrow navigation.
  235. // - Fixed a stupid bug that prevented the first font in the directory from being included in the grid.
  236. // - Fixed some problems with normal font file browsing after viewing font glyphs.
  237. // - Improved styling for previewed and zoomed images.
  238. //
  239. // **FIXED and IMPROVED:** Playlists.
  240. // - Window title and sidebar head are now reset to indicate presence of playlist.
  241. // - First track wasn't being selected when "autoload_media" = true.
  242. // - Directory stats weren't being reset after closing a playlist.
  243. // - Grid button and "show invisibles" checkbox are hidden with open playlist.
  244. //
  245. // **IMPROVED:** Currently selected sidebar item will now scroll into view after various events, like sorting change, showing/hiding details, resizing sidebar, etc.
  246. // **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...).
  247. // **FIXED:** Document title didn't include entire path.
  248. // Many other small bug fixes and style tweaks, including some specifically for Firefox and Safari.
  249.  
  250. // **VERSION 4.1.1**
  251. // A few small fixes and style tweaks.
  252.  
  253. // **VERSION 4.1.0**
  254. // **NEW:** Basic support for media playlists (.m3u and .m3u8).
  255. // - Added "Open Playlist..." item to the main menu.
  256. // - 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.
  257. // - Playlist can be closed via the "Close" button or shortcut, and the previous directory contents will be loaded.
  258. // - Streaming links are not supported.
  259. // - 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.
  260. // - 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.
  261. // **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.)
  262. // - Added "Open Font..." item in the menu item.
  263. // - View individual glyphs and save as SVG.
  264. // **FIXED:** Apps weren't being properly classified in the index.
  265. // **FIXED:** An issue with formatting the current directory name in the sidebar header.
  266. // **IMPROVED:** Refreshed UI colors and icons; added icons for more file types.
  267. // **IMPROVED:** Many styling adjustments, including setting numbers (for sizes and date, etc.) to tabular spacing.
  268. // **CHANGED:** Renamed "shortcuts" user setting to "bookmarks"; if you use exported settings, you'll have to change this in your code.
  269. // **INTERNALS:** Prettified and modularized some code. Removed some newly-unnecessary functions. Began to prune CSS.
  270. // - Updated markdown-it to 9.1.0.
  271.  
  272. // ***** GENERAL SETUP ***** //
  273.  
  274. // ************************************ //
  275. // DON'T EDIT ANYTHING BELOW THIS LINE. //
  276. // ************************************ //
  277.  
  278. // PATHS
  279. // Fix "%" error in file name; see https://stackoverflow.com/questions/7449588/why-does-decodeuricomponent-lock-up-my-browser
  280. function decodeURIComponentSafe(s) {
  281. if ( !s ) { return s; }
  282. return decodeURIComponent(s.replace(/%(?![0-9a-fA-F]{2})/g, '%25') ); // replace % with %25 if not followed by two a-f/number
  283. }
  284.  
  285. const $protocol = window.location.protocol;
  286. const $origin = $protocol +'//'+ window.location.host;
  287. const $location = decodeURIComponentSafe( [location.protocol, '//', location.host, location.pathname].join('') );
  288. const $current_dir_path = $location.replace(/([\/|_|—])/g,'$1<wbr>').replace(/\\/g,'/'); // URL w/o query string for display
  289.  
  290. function escapeStr(str) { str = str.replace(/([\^\$\|\?\*\+\(\)\[])/g,'\$1'); }
  291.  
  292. // if URL is a file, change window location to parent dir, add querystring of file name; then autoload file.
  293. function loadFile() {
  294. if ( $location.slice($location.lastIndexOf('/')).indexOf('.') !== -1 && !$location.endsWith('/') && window.top === window.self ) {
  295. let $query_prefs = getQueryPrefs();
  296. $query_prefs.set( 'file', $location.slice($location.lastIndexOf('/') + 1) );
  297. window.location = $location.slice(0,$location.lastIndexOf('/') + 1) +'?'+ $query_prefs;
  298. return;
  299. }
  300. }
  301. loadFile();
  302.  
  303. // QUERY PREFS
  304. function getQueryPrefs() { return new URL(window.location).searchParams; }
  305. // const initialQueryPrefs = getQueryPrefs();
  306. // set query key/value
  307. function setQuery(key, value) {
  308. let $query_prefs = getQueryPrefs();
  309. $query_prefs.set( key, value );
  310. updateQuery($query_prefs);
  311. }
  312. // get query value
  313. function getQuery(key) {
  314. let $query_prefs = getQueryPrefs();
  315. let value = '';
  316. if ( key === 'width' ) {
  317. value = ( !$query_prefs.has(key) ? 30 : Math.round(100 * Number.parseInt($query_prefs.get('width'))/window.innerWidth) ); // number string
  318. } else {
  319. value = ( $query_prefs.has(key) ? $query_prefs.get(key) : $settings[key] !== undefined ? $settings[key].toString() : '' );
  320. value = value.replace('%2F','').replace('/',''); // some servers add a '/' to end of query string
  321. }
  322. return value;
  323. }
  324. // toggle query key
  325. function toggleQuery(key) {
  326. let $query_prefs = getQueryPrefs();
  327. let nonBoolPrefs = {
  328. 'theme_light': {'theme':'dark'},
  329. 'theme_dark': {'theme':'light'},
  330. 'source_text': {'default_text_view':'preview_text'},
  331. 'preview_text': {'default_text_view':'source_text'},
  332. 'sort_by_default': {'sort_by':'default'},
  333. 'sort_by_name': {'sort_by':'name'},
  334. 'sort_by_size': {'sort_by':'size'},
  335. 'sort_by_date': {'sort_by':'date'},
  336. 'sort_by_kind': {'sort_by':'kind'},
  337. 'sort_by_ext': {'sort_by':'ext'}
  338. };
  339. var value, queryValue, settingsValue;
  340. if ( nonBoolPrefs[key] !== undefined ) {
  341. value = Object.values(nonBoolPrefs[key]).toString();
  342. key = Object.keys(nonBoolPrefs[key]).toString(); // must come after value: i.e., don't redefine key before getting value
  343. if ( $settings[key] === value ) { $query_prefs.delete( key ); } else { $query_prefs.set( key, value ); }
  344. } else {
  345. queryValue = $query_prefs.get(key);
  346. settingsValue = $settings[key];
  347. value = ( queryValue === null ? settingsValue.toString() : queryValue.toString() );
  348. value = ( value === 'true' ? 'false' : 'true' );
  349. if ( ( queryValue !== null && queryValue !== settingsValue ) ) {
  350. $query_prefs.delete( key );
  351. } else {
  352. $query_prefs.set( key, value );
  353. }
  354. }
  355. updateQuery($query_prefs);
  356. }
  357. // remove query key
  358. function removeQuery(key) {
  359. let $query_prefs = getQueryPrefs();
  360. $query_prefs.delete(key);
  361. updateQuery($query_prefs);
  362. }
  363. // update query string
  364. function updateQuery(querystr) {
  365. querystr = querystr.toString().replace('%2F','').replace('/','');
  366. window.history.replaceState({}, document.title, window.location.pathname +'?'+ querystr);
  367. updateParentLinks();
  368. }
  369.  
  370. // ***** SET UP UI ELEMENTS ***** //
  371.  
  372. // SIDEBAR ELEMENTS
  373. // ***** BUILD MENUS ***** //
  374. // Parent and Parents Menus
  375. function updateQueryStr(str) {
  376. str = str.replace(/([^\?]*)selected=[^&]*(.*)$/m,'$1$2') // delete current selected query, if any
  377. .replace(/([^\?]*)history=(\d+)\+*([^&]*)(&*)(.*)/m,'$1$4$5&selected=$2&history=$3').replace(/&{2,}/g,'&').replace(/\?&/m,'\?'); // format query with selected and history at end
  378. if ( str.endsWith('&history=') ) { str = str.replace(/(.+)&history=$/m,'$1'); } // if no history, delete query
  379. return str;
  380. }
  381. // create links
  382. function createParentLinks() {
  383. let $links = [];
  384. let str = decodeURIComponentSafe(window.location.search);
  385. str = str.replace('/','').replace('%2F','');
  386. let $linkPieces = $location.split('/');
  387. $linkPieces = $linkPieces.slice(2,-2); // remove beginning and ending empty elements and current directory
  388. while ( $linkPieces.length > 0 ) { // while there are link pieces...
  389. str = updateQueryStr(str); // update selected and history
  390. let link = $protocol +'//'+ $linkPieces.join('/') +'/'+ str; // assemble link
  391. $links.push(link); // add to link array
  392. $linkPieces.pop(); // remove last link piece and repeat...
  393. }
  394. return $links;
  395. }
  396. // create menu items
  397. function createParentLinkItems() {
  398. let $parent_link_menu_items = [];
  399. let $links = createParentLinks();
  400. $('#parent_dir_menu').find('a').attr( 'href', $links[0] ); // set parent link
  401. for ( let i = 0; i < $links.length; i++ ) {
  402. let display_name = $links[i].slice(0,$links[i].lastIndexOf('?') - 1);
  403. display_name = display_name.replace(/\//g,'\/<wbr>');
  404. let menu_item = '<li><a href="'+ $links[i] +'">' + display_name + '/</a></li>';
  405. $parent_link_menu_items.push(menu_item);
  406. }
  407. return $parent_link_menu_items; // return parents link items
  408. }
  409. function updateParentLinks() { $('#parents_dir_menu').siblings('ul').empty().append( createParentLinkItems() ); }
  410.  
  411. // MENUS: User bookmarks
  412. function bookmarksMenuItems() {
  413. const $bookmarks = $settings.bookmarks;
  414. let menu_items = [];
  415. let $links_arr = [];
  416. let $links_arr_str = '';
  417. let $links;
  418. if ( $bookmarks.length > 0 ) {
  419. for ( let i = 0; i < $bookmarks.length; i+=1 ) {
  420. $links = $bookmarks[i].links;
  421. // make array of links
  422. for ( let j = 0; j < $links.length; j+=1 ) {
  423. if ( !$links[j].link.endsWith('/') ) {
  424. $links[j].link = $links[j].link.slice(0,$links[j].link.lastIndexOf('/') + 1) + '?file=' + $links[j].link.slice($links[j].link.lastIndexOf('/') + 1) ;
  425. }
  426. $links[j].link_name = $links[j].link_name.split('/').join('/<wbr>');
  427. $links_arr[j] = '<li><a href="'+ $links[j].link +'">' + $links[j].link_name + '</a></li>';
  428. }
  429. $links_arr_str = $links_arr.join('');
  430. menu_items[i] = '<li class="bookmarks has_submenu"><a>'+ $bookmarks[i].menu_title +'</a><ul>'+ $links_arr_str +'</ul></li>';
  431. }
  432. menu_items = menu_items.join('');
  433. }
  434. return menu_items;
  435. }
  436. // MENUS: Other menu items
  437. const MenuItems = function() {
  438. 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>';
  439. let autoload_media = '<li class="toggle_UI_pref rule" id="autoload_media"><span id="autoload_media_menu">Autoload Media</span></li>';
  440. 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>';
  441. let alternate_background = '<li class="toggle_UI_pref" id="alternate_background"><span>Alternate Backgrounds</span></li>';
  442. let show_numbers = '<li class="toggle_UI_pref rule" id="show_numbers"><span>Show Numbers</span></li>';
  443. 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>';
  444. let disable_text_editing = '<li class="rule"><span class="toggle_UI_pref" id="enable_text_editing">Disable Text Editing</span></li>';
  445. 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>';
  446. 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>';
  447. let default_settings = '<li><a href="#" id="default_settings" title="Delete URL query string and reload page.">Default User Settings</a></li>';
  448. let export_settings = '<li class="rule"><a href="#" id="export_settings" title="Export user settings to text file.">Export User Settings</a></li>';
  449. let contact_link = '<li><a id="contact" href="mailto:mshroud@vivaldi.net">Contact</a></li>';
  450. let donate_link = '<li><a id="donate" href="https://paypal.me/mschrauzer" target="_blank" rel="noopener">Donate</a></li>';
  451. 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;
  452. };
  453. const SidebarHeaderEls = function() {
  454. let parent_link_items = createParentLinkItems();
  455. let parent_link = $(parent_link_items[0]).find('a').attr('href');
  456. parent_link_items = parent_link_items.toString().replace(/<\/li>,<li>/g,'</li><li>');
  457. let parent_dir_menu = '<nav id="parent_dir_menu"><a href="'+ parent_link +'">&nbsp;</a></nav>';
  458. let parents_dir_menu = '<nav id="parents_dir_menu"><div>'+ $current_dir_path +'</div></nav><ul class="menu">'+ parent_link_items +'</ul>';
  459. let bookmarks_menu = '<nav id="bookmarks_menu"><div>&nbsp;</div></nav><ul id="bookmarks" class="menu">'+ bookmarksMenuItems() + MenuItems() +'</ul>';
  460. let show_details = '<button class="toggle_UI_pref" id="show_details" tabindex="-1"><span>Show details</span><span>Hide details</span></button>';
  461. 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>';
  462. 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>';
  463. 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>';
  464. let text_editor_row = '<tr id="text_editor_row"><th colspan="4"><a href="#" title="Toggle Text Editor">Text Editor</a></th></tr>';
  465. 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>';
  466. let sidebar_header_els = sidebar_header;
  467. return sidebar_header_els;
  468. };
  469. // Dir List Elements
  470. const SidebarDirListEls = function() {
  471. let dir_list_body = '<tbody id="tbody"></tbody>';
  472. 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>';
  473. let sidebar_dir_list_els = '<table id="dir_list">'+ dir_list_body + dir_list_foot +'</table>';
  474. return sidebar_dir_list_els;
  475. };
  476. // CONTENT PANE ELEMENTS
  477. const ContentHeaderEls = function() {
  478. 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>';
  479. let title = '<td id="title"><span></span></td>';
  480. 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>';
  481. let content_title = '<tr id="content_title">'+ title_buttons_left + title + title_buttons_right +'</tr>';
  482. let content_header_els = '<header id="content_header"><table><tbody>'+ content_title + ContentAudioEls() +'</tbody></table></header>';
  483. return content_header_els;
  484. };
  485. // Content containers
  486. const ContentEls = function() {
  487. let content_grid = '<div id="content_grid" data-grid-scale-factor="1" data-kind="grid"></div>';
  488. let content_text = '<div id="content_text"></div>';
  489. let content_font = '<div id="content_font" class="content" spellcheck="false" data-kind="font">'+ ContentFontEls() +'</div>';
  490. let content_image = '<div id="content_image" class="content" data-kind="image"><img /></div>';
  491. let content_video = '<video id="content_video" class="content media" controls data-kind="video">Your browser does not support the video tag.</video>';
  492. let content_pdf = '<embed id="content_pdf" class="content" name="plugin" tabindex="0" data-kind="pdf"></embed>';
  493. 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>';
  494. let content_els = '<section id="content_container">'+ content_grid + content_text + content_font + content_image + content_pdf + content_video + content_iframe +'</section>';
  495. return content_els;
  496. };
  497. // Content Audio Els
  498. const ContentAudioEls = function() {
  499. let prev_track = '<div id="prev_track" class="prev_next_track_btn" title="Previous track">&nbsp;</div>';
  500. let next_track = '<div id="next_track" class="prev_next_track_btn" title="Next track">&nbsp;</div>';
  501. let audio_player = '<audio id="audio" preload="auto" tabindex="0" controls >Sorry, your browser does not support HTML5 audio.</audio>';
  502. let loop = '<label><input type="checkbox" id="loop" for="loop" name="loop" tabindex="0" />Loop</label>';
  503. let shuffle = '<label><input type="checkbox" id="shuffle" for="shuffle" name="shuffle" tabindex="0" />Shuffle</label>';
  504. let checkbox_cont = '<div id="checkbox_div">'+ loop + shuffle +'</div>';
  505. let close_audio = '<div id="close_audio" title="Close audio"></div>';
  506. let content_audio_title = '<tr id="content_audio_title"><td colspan="3"></td></tr>';
  507. 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>';
  508. return content_audio_els;
  509. };
  510. // Content Font Els
  511. const ContentFontEls = function() {
  512. let sample_string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ<br />abcdefghijklmnopqrstuvwxyz<br />0123456789 [(!@#$%^&*;:)]';
  513. let specimen = '<div class="specimen" contenteditable="true" style="font-size:4em;word-break: break-all;line-height: 1.2;">'+ sample_string +'</div>';
  514. 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>';
  515. 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.';
  516. 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>';
  517. let lorem2 = lorem.replace('style="','style="columns:2;');
  518. let lorem3 = lorem.replace('style="','style="columns:3;');
  519. let hamburger = '<div class="hamburger" style="text-align:justify" contenteditable="true">'+ hamburger_string +'</div>'+ lorem + lorem2 + lorem3 +'</div>';
  520. let font_specimen = '<div id="font_specimen">'+ specimen + hamburger + ContentFontViewer() +'</div>';
  521. return font_specimen;
  522. };
  523. const ContentFontViewer = function() {
  524. let glyphs_container = '<div id="glyphs_container"></div>';
  525. 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>';
  526. let font_viewer = '<div id="font_viewer" style="font-family:unset">'+ glyphs_container + glyph_viewer +'</div>';
  527. return font_viewer;
  528. }
  529. // ASSEMBLE SIBEBAR & CONTENT PANE ELEMENTS
  530. const MainContent = function() {
  531. let handle = '<div id="handle"></div>';
  532. let toggle_sidebar = '<div id="toggle_sidebar"></div>';
  533. 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>';
  534. let overlay = '<div id="overlay"></div>';
  535. let sidebar = '<div id="sidebar">'+ SidebarHeaderEls() + SidebarDirListEls() +'</div>';
  536. let sidebar_wrapper = '<td id="sidebar_wrapper">'+ sidebar + handle + toggle_sidebar +'</td>';
  537. let content_pane = '<td id="content_pane" class="">'+ ContentHeaderEls() + ContentEls() +'</td>';
  538.  
  539. let main_head = '<thead><tr><th>'+ warnings + overlay +'</th></tr></thead>';
  540. let main_body = '<tbody><tr>'+ sidebar_wrapper + content_pane +'</tr></tbody>';
  541. let main_foot = '<tfoot></tfoot>';
  542. let main_content = '<table id="main_content">'+ main_head + main_body + main_foot +'</table>';
  543. return $(main_content);
  544. };
  545. // DEFINE Content Elements
  546. const $main_content = MainContent();
  547. // DIR LIST
  548. const $dir_list_body = $main_content.find('#tbody');
  549. const $dir_list = $main_content.find('#dir_list');
  550. // CONTENT
  551. const $content_pane = $main_content.find('#content_pane');
  552. const $audio_player = $main_content.find('#audio');
  553. const $content_text = $main_content.find('#content_text');
  554. const $content_grid = $main_content.find('#content_grid');
  555. const $content_font = $main_content.find('#content_font');
  556. const $content_image = $main_content.find('#content_image');
  557. const $content_pdf = $main_content.find('#content_pdf');
  558. const $content_video = $main_content.find('#content_video');
  559. const $content_iframe = $main_content.find('#content_iframe');
  560.  
  561. // SVG UI ICONS
  562. function SVG_UI_Icon(icon_name) {
  563. let svg = '';
  564. if ( icon_name.endsWith('_dark') ) {
  565. icon_name = icon_name.slice(0,-5);
  566. svg = SVG_UI_Icons[icon_name];
  567. svg = svg.replace(/4{6}/g,'BBBBBB');
  568. } else {
  569. svg = SVG_UI_Icons[icon_name];
  570. }
  571. return 'url("data:image/svg+xml;utf8,'+ svg +'")';
  572. }
  573. const SVG_UI_Icons = {
  574. 'arrow': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M4 4l12 6-12 6z\' /></svg>',
  575. '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>',
  576. '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>',
  577. '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>',
  578. '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>',
  579. '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>',
  580. '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>',
  581. '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>',
  582. '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>',
  583. '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>',
  584. '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>',
  585. '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>',
  586. '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>',
  587. '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>',
  588. 'menu': '<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 20 20\'><path fill=\'%23444444\' d=\'M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z\' /></svg>',
  589. '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>',
  590. '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>',
  591. '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>',
  592. '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>',
  593. '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>',
  594. '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>',
  595. '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>',
  596. '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>',
  597. };
  598.  
  599. function SVG_UI_File_Icon(icon_name) {
  600. if ( icon_name === 'file_icon_dir_default' ) { // default chrome icons
  601. 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= ")';
  602. } else if ( icon_name === 'file_icon_file_default' ) {
  603. return 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAABHUlEQVR42o2RMW7DIBiF3498iHRJD5JKHurL+CRVBp+i2T16tTynF2gO0KSb5ZrBBl4HHDBuK/WXACH4eO9/CAAAbdvijzLGNE1TVZXfZuHg6XCAQESAZXbOKaXO57eiKG6ft9PrKQIkCQqFoIiQFBGlFIB5nvM8t9aOX2Nd18oDzjnPgCDpn/BH4zh2XZdlWVmWiUK4IgCBoFMUz9eP6zRN75cLgEQhcmTQIbl72O0f9865qLAAsURAAgKBJKEtgLXWvyjLuFsThCSstb8rBCaAQhDYWgIZ7myM+TUBjDHrHlZcbMYYk34cN0YSLcgS+wL0fe9TXDMbY33fR2AYBvyQ8L0Gk8MwREBrTfKe4TpTzwhArXWi8HI84h/1DfwI5mhxJamFAAAAAElFTkSuQmCC ")';
  604. } else { // custom icons
  605. return 'url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons[icon_name] +'")';
  606. }
  607. }
  608. const SVG_UI_File_Icons = {
  609. '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>',
  610. '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>',
  611. '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>',
  612. '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>',
  613. '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>',
  614. '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>',
  615. '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>',
  616. '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>',
  617. '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>',
  618. '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>',
  619. '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>',
  620. '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>',
  621. '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>',
  622. '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>',
  623. '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>',
  624. '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>',
  625. '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>',
  626. '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>',
  627. '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>',
  628. '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>',
  629. '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>',
  630. '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>',
  631. '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>',
  632. '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>',
  633. };
  634. // Programatically add File icon CSS rules
  635. function CSS_UI_Icon_Rules(el) {
  636. let class_name;
  637. let selector;
  638. 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'];
  639. let rules = '';
  640. if ( el === 'body' ) {
  641. rules += '#bookmarks ul a { background-image:'+ SVG_UI_File_Icon('file_icon_file') +'; }';
  642. rules += '#bookmarks ul a[href^="file"] { background-image:'+ SVG_UI_File_Icon('file_icon_dir') +'; }';
  643. rules += '#bookmarks ul a[href^="http"] { background-image:'+ SVG_UI_File_Icon('file_icon_htm') +'; }';
  644. 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; }';
  645. 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; }';
  646. } else {
  647. rules += '#iframe_body:not(.use_custom_icons) #dir_list tr.dir td.name a::before { background:'+ SVG_UI_File_Icon('file_icon_dir_default') +'; }';
  648. rules += '#iframe_body:not(.use_custom_icons) #dir_list tr.file td.name a::before { background:'+ SVG_UI_File_Icon('file_icon_file_default') +'; }';
  649. }
  650. for ( let kind of kinds ) {
  651. class_name = kind;
  652. switch(kind) {
  653. case 'dir': class_name = 'dir:not(.app)'; break;
  654. case 'dir_invisible': class_name = 'dir.invisible'; break;
  655. }
  656. if ( el === 'body' ) {
  657. selector = el +'.use_custom_icons #dir_list tr.'+ class_name +':not(.media) a.icon span ';
  658. // selectors for iframe content kinds, icons in content titlebar
  659. if ( kind !== undefined && !['audio','dir','font','ignored','image','pdf','video'].includes(kind) ) {
  660. selector += ', #content_pane.has_iframe #title span.has_'+ kind +'::before, #content_pane.has_ignored #title span.has_'+ kind +'::before'
  661. }
  662. } else {
  663. selector = el +'.use_custom_icons #dir_list tr.'+ class_name +' td.name a::before ';
  664. }
  665. let background_image = '{ background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons['file_icon_'+kind] +'"); }' ;
  666. let rule = selector + background_image;
  667. rules += rule;
  668. }
  669. return rules;
  670. }
  671. //***** STYLES *****//
  672.  
  673. // DEFINE STYLES
  674. var $main_style_rules =
  675. '#content_pane.has_image #content_image { align-items: center; justify-content: center; }' +
  676. '.image_grid_item a { align-self: center; justify-self: center; }' +
  677. '#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' +
  678. '{ background-color: lightgray; }' +
  679. // light non-media ("light cyan")
  680. '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'+
  681. '{ background-color: rgba(172,202,235,1.00) !important; }' +
  682. '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)'+
  683. '{ background-color: rgba(172,202,235,0.60); }' +
  684. // light media ("light aqua")
  685. 'body.theme_light #dir_list tr.media.playing { background-color: rgba(130,196,196,1); }' + // #82C4C4
  686. 'body.theme_light #dir_list tr.media.selected:not(.playing)'+
  687. '{ background-color: rgba(116,190,190,0.60) !important; }' +
  688. 'body.theme_light #dir_list tr.media.selected:not(.playing):hover, body.theme_light #dir_list tr.media:not(.selected):hover'+
  689. '{ background-color: rgba(116,190,190,0.40) !important; }' +
  690. // dark non-media ("dark cyan")
  691. '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'+
  692. '{ background-color: rgba(101,140,179,1.00) !important; }' + //#658CB3
  693. '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)'+
  694. '{ background-color: rgba(101,140,179,0.66); }' +
  695. // dark media ("dark aqua")
  696. 'body.theme_dark #dir_list tr.media.playing { background-color: rgba(076,143,143,1.00) !important; }' +
  697. 'body.theme_dark #dir_list tr.media.selected:not(.playing)'+
  698. '{ background-color: rgba(076,143,143,0.70) !important; }' +
  699. 'body.theme_dark #dir_list tr.media.selected:not(.playing):hover, body.theme_dark #dir_list tr.media:not(.selected):hover'+
  700. '{ background-color: rgba(076,143,143,0.45) !important; }' +
  701. // text editor row ("purple")
  702. 'body.theme_light.has_text #text_editor_row, body.theme_light.edited #text_editor_row' +
  703. '{ background-color: rgba(160,160,230,1.00); }' + // #A0A0E6
  704. 'body.theme_dark.has_text #text_editor_row, body.theme_dark.edited #text_editor_row' +
  705. '{ background-color: rgba(100,100,160,1.00); }' + // #6464A0
  706. // other UI elements
  707. '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' +
  708. '{ background-color: #262626; }' +
  709. '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' +
  710. '{ background-color: #333; }' +
  711. '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' +
  712. '{ background-color: #444; }' +
  713. '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' +
  714. '{ background-color: #555; }' +
  715. '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' +
  716. '{ background-color: #666; }' +
  717. '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^="/"]' +
  718. '{ background-color: #777; }' +
  719. 'body.theme_dark #grid_btn .menu li:hover { background-color: #888 !important; }' +
  720. 'body.theme_dark #grid_btn .menu, body.theme_dark #grid_btn .menu li' +
  721. '{ background-color: #AAA; }' +
  722. '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' +
  723. '{ background-color: #BBB; }' +
  724. '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' +
  725. '{ background-color: #CCC; }' +
  726. 'body.theme_light #dir_list tbody { background-color: #DFDFDF !important; }' +
  727. 'body.theme_light #content_grid > div, #warnings, body.theme_light #content_pane.has_grid #content_grid::after, body.theme_light #font_info, body.theme_light #glyph_viewer_info' +
  728. '{ background-color: #EEE; }' +
  729. '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, #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' +
  730. '{ background-color: #FFF; }' +
  731. 'body.is_chrome #audio_container { background-color: rgb(241, 243, 244); }' +
  732. '#warnings button:focus,#warnings button.focus { background-color: #0E4399; }' +
  733. '#bookmarks_menu div { background-image:'+ SVG_UI_Icon('menu') + '; }' +
  734. 'body.theme_light .bookmarks > a::before { background-image:'+ SVG_UI_Icon('bookmark') +'; }' +
  735. 'body.theme_dark .bookmarks > a::before { background-image:'+ SVG_UI_Icon('bookmark_dark') +'; }' +
  736. 'body.theme_light li.has_submenu { background-image:'+ SVG_UI_Icon('arrow') +'; }' +
  737. 'body.theme_dark li.has_submenu { background-image:'+ SVG_UI_Icon('arrow_dark') +'; }' +
  738. '#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'+
  739. '{ background-image:'+ SVG_UI_Icon('check_mark') +'; }' +
  740. '#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'+
  741. '{ background-image:'+ SVG_UI_Icon('chevron_up') +'; }' +
  742. '#prev_btn { background-image:'+ SVG_UI_Icon('chevron_left') + '; }' +
  743. '#next_btn { background-image:'+ SVG_UI_Icon('chevron_right') + '; }' +
  744. 'body.is_error #content_pane, #warnings h3::before { background-image:'+ SVG_UI_Icon('error') +'; }' +
  745. 'body.has_fonts #grid_btn, body.has_images #grid_btn, #grid_btn .menu'+
  746. '{ background-image:'+ SVG_UI_Icon('grid') +'; }' +
  747. 'body #content_pane.has_ignored:not(.has_grid) { background-image:'+ SVG_UI_Icon('ignored') +'; }' +
  748. 'body.theme_dark #content_pane.has_ignored:not(.has_grid){ background-image:'+SVG_UI_Icon('ignored_dark') +'; }' +
  749. '#decrease { background-image:'+ SVG_UI_Icon('minus') +'; }' +
  750. '#close_audio { background-image:'+ SVG_UI_Icon('multiply') +'; }' +
  751. 'body.has_audio #content_pane:not(.has_image):not(.has_video):not(.has_ignored):not(.has_grid):not(.has_zoom_image)'+
  752. '{ background-image:'+ SVG_UI_Icon('music') +'; }' +
  753. '#increase { background-image:'+ SVG_UI_Icon('plus') +'; }' +
  754. '#prev_track, #next_track { background-image:'+ SVG_UI_Icon('prev_next_track') +'; }' +
  755. '#toggle_sidebar, #toggle_info { background-image:'+ SVG_UI_Icon('toggle') +'; }' +
  756.  
  757. CSS_UI_Icon_Rules('body') + // FILE & DIR ICONS, plus additions:
  758. '#content_pane #title span::before { width:14px; height:14px; display:inline-block; margin:0 5px -3px 2px; }' +
  759. '#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'+
  760. '{ background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons['file_icon_dir'] +'"); }' +
  761. '#content_pane.has_font #title span::before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons['file_icon_font'] +'"); }' +
  762. '#content_pane.has_image #title span::before, #content_pane.has_zoom_image #title span::before'+
  763. '{ background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons['file_icon_image'] +'"); }' +
  764. '#content_pane.has_ignored #title span::before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons['file_icon_ignored'] +'"); }' +
  765. '#content_pane.has_iframe #title span.has_other::before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons['file_icon_file'] +'"); }' +
  766. '#content_audio_title td:before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons['file_icon_audio'] +'"); height:14px !important; }' +
  767. '#content_pane.has_pdf #title span::before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons['file_icon_pdf'] +'"); }' +
  768. '#content_pane.has_video #title span::before { background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_File_Icons['file_icon_video'] +'"); }' +
  769. 'body.theme_light #grid_btn.has_grid, body.theme_light #grid_btn.has_grid:hover ul'+
  770. '{ background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_Icons['grid_loaded'] +'") !important; opacity:1 !important; }' +
  771. 'body.theme_dark #grid_btn.has_grid, body.theme_dark #grid_btn.has_grid:hover ul'+
  772. '{ background-image: url("data:image/svg+xml;utf8,'+ SVG_UI_Icons['grid_loaded_dark'] +'") !important; opacity:1 !important; }' +
  773.  
  774. '#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, #content_pane, #close_audio, #prev_track, #next_track, #glyph_viewer' +
  775. '{ background-position: center; }' +
  776. '#prev_next_btns span, #scale span { background-position: center 36%; }' +
  777. '.toggle_UI_pref, .bookmarks > a { background-position: 5px center; }' +
  778. '#dir_list tbody a { background-position: 6px 4px; }' +
  779. '#dir_list a.icon span { background-position: 6px 0; }' +
  780. '#bookmarks ul a { background-position: 8px center; }' +
  781. '#bookmarks > li { background-position: right 6px center; }' +
  782. '#grid_btn,#grid_btn .menu { background-position: right 5px top 6px; }' +
  783. '#content_audio_title td:before { background-position: right 4px center; }' +
  784. '#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, #glyph_viewer, #warnings h3::before, #content_audio_title td:before'+
  785. '{ background-repeat: no-repeat; }' +
  786. '#glyph_viewer { background-size: contain; }' +
  787. '.toggle_UI_pref, th .sorting, #scale span { background-size: 10px; }' +
  788. '.bookmarks > a, li.has_submenu, #parent_dir_menu a { background-size: 12px; }' +
  789. '#dir_list tbody a, #dir_list a.icon span, #bookmarks ul a, #close_audio, #grid_btn, #grid_btn .menu'+
  790. '{ background-size: 14px; }' +
  791. '#toggle_sidebar, #toggle_info { background-size: 18px; }' +
  792. '#warnings h3::before { background-size: 24px; }' +
  793. '#prev_next_btns span { background-size: 33%; }' +
  794. '#content_pane { background-size: 50%; }' +
  795. ':root, html, body, #sidebar_wrapper, #sidebar_header, #dir_list, #main_content, #content_pane, #content_pdf, #content_iframe' +
  796. '{ border: 0 !important; }' +
  797. 'body.theme_dark ul { border: solid 1px #222; }' +
  798. 'button { border: solid 1px #333; }' +
  799. 'body.theme_light #sidebar ul { border: solid 1px gray; }' +
  800. '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' +
  801. '{ border-top: solid 1px #111; }' +
  802. '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' +
  803. '{ border-top: solid 1px grey; }' +
  804. '#sort_by, tr.sorted, tr:not(.invisible) ~ tr.invisible + tr:not(.invisible)' + // , tr.dir ~ tr:not(.dir,.invisible,.ignore)
  805. '{ border-top: solid 1px #999; }' +
  806. 'body.theme_dark #grid_btn ul.menu { border-top: solid 1px #EEE; }' +
  807. '#parents_dir_menu + ul, #bookmarks_menu + ul, #grid_btn ul.menu'+
  808. '{ border-right: 0 !important; }' +
  809. 'body.theme_dark #parents_dir_menu, body.theme_dark #sidebar, body.theme_dark #warnings' +
  810. '{ border-right: solid 1px #111; }' +
  811. '#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' +
  812. '{ border-right: solid 1px grey; }' +
  813. 'body.theme_dark #grid_btn .menu li { border-right: solid 1px #EEE; }' +
  814. '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' +
  815. '{ border-bottom: solid 1px #111; }' +
  816. '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' +
  817. '{ border-bottom: solid 1px grey; }' +
  818. 'body.theme_light #content_title, body.theme_light #content_pane.has_audio #content_header' +
  819. '{ border-bottom: solid 1px #888; }' +
  820. '#bookmarks_menu + ul > li.has_submenu.ruled, .rule { border-bottom: solid 1px #999; }' +
  821. 'body.theme_dark #content_pane.has_font #content_font hr, .hamburger h4'+
  822. '{ border-bottom: solid 1px #CCC; }' +
  823. 'body.theme_dark #grid_btn ul.menu, body.theme_dark #grid_btn .menu li#show_image_grid'+
  824. '{ border-bottom: solid 1px #EEE; }' +
  825. '#parents_dir_menu + ul, #bookmarks_menu + ul { border-left:0; }' +
  826. 'body.theme_dark #parents_dir_menu, body.theme_dark #grid_btn ul.menu, body.theme_dark #warnings' +
  827. '{ border-left: solid 1px #111; }' +
  828. 'body.theme_light #parents_dir_menu, #grid_btn .menu { border-left: solid 1px grey; }' +
  829. 'body.theme_dark #grid_btn ul.menu { border-left: solid 1px #EEE; }' +
  830. 'table { border-collapse: collapse; }' +
  831. 'html, body, :root { border-radius: 0; }' +
  832. 'button { border-radius: 3px; }' +
  833. '#warnings { border-radius: 0 0 3px 3px; }' +
  834. 'body.theme_light #sidebar ul { box-shadow: 0px 2px 3px -2px #888; }' +
  835. 'body.theme_dark #sidebar ul { box-shadow: 0px 2px 3px -2px #111; }' +
  836. '#warnings { box-shadow: 0px 2px 12px 0 #111; }' +
  837. 'body.theme_dark #grid_btn ul.menu { box-shadow: none; }' +
  838. 'html, body, :root, #sidebar, #grid_btn .menu li, #content_container, #content_source, #content_preview' +
  839. '{ box-sizing: border-box; }' +
  840. '#checkbox_div label, #grid_btn .menu li, #content_grid .font_grid_item'+
  841. '{ clear: both; }' +
  842. '#dir_list tbody .name { clear: right; }' +
  843. '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' +
  844. '{ color: #111 }' +
  845. 'body.theme_light #sidebar #tfoot tr { color: #444 }' +
  846. 'body.theme_light #dir_list tr.ignore a, body.theme_light #dir_list tr.ignore.app a, .glyph_info' +
  847. '{ color: #777 }' +
  848. '#sort_menu .disabled span, #dir_list th.disabled { color: #999 }' +
  849. 'body.theme_dark #dir_list tr.ignore td, body.theme_dark #dir_list tr.file.ignore a, body.theme_dark #sidebar #tfoot td' +
  850. '{ color: #BBB }' +
  851. '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' +
  852. '{ color: #EEE }' +
  853. '#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' +
  854. '{ content: "" }' +
  855. '#content_pane.has_image:not(.has_grid) #title::after, #content_pane.has_zoom_image:not(.has_grid) #title::after'+
  856. '{ content: attr(data-after) }' +
  857. '#content_pane.has_font #title::before { content: "Font: " }' + // font and image grid
  858. '#content_pane.has_grid:not(.has_ignored) #title::before{ content: "Fonts and Images from: " }' + // font and image grid
  859. 'body:not(.has_images) #content_pane.has_grid:not(.has_ignored) #title::before, #content_pane.has_grid #title.font_grid::before' +
  860. '{ content: "Fonts from: " }' + // font grid
  861. '#glyph_viewer_info div::before { content: "Glyph " }' +
  862. '#content_pane.has_ignored:not(.has_grid) #title::before{ content: "Ignored content: " }' + // .ignored
  863. 'body:not(.has_fonts) #content_pane.has_grid:not(.has_ignored) #title::before, #content_pane.has_grid #title.image_grid::before' +
  864. '{ content: "Images from: " }' + // image grid
  865. '#content_pane.has_dir:not(.has_grid) #title::before { content: "Index of: " }' + // .dir
  866. 'body:not(.has_playlist) #sidebar_title th:before { content: "INDEX OF"; }' +
  867. '#content_pane.has_audio #content_audio_title td::before, body #content_pane.has_video #title::before' +
  868. '{ content: "Playing: " }' + // .audio, .video
  869. 'body.has_playlist #sidebar_title th:before { content: "PLAYLIST"; }' +
  870. 'body#top.edited #warnings.unloading h3::before { content: "Text Editor: " }' +
  871. 'body#top.edited #text_editor_row a:after { content: " (edited)"; }' +
  872. 'body.edited.has_text #title::after, body.iframe_edited:not(.has_text) #content_pane.has_iframe #title::after' +
  873. '{ content: " (edited)"; }' + // .ignored
  874. 'body.show_numbers #tbody { counter-reset: row; }' +
  875. 'body.show_numbers #tbody tr td.name a::before { counter-increment: row; content:counter(row);}' +
  876. '#sidebar_title th, #sort_menu .disabled span, #dir_list .disabled'+
  877. '{ cursor: default; }' +
  878. '#sidebar_menus td:hover, #parents_dir_menu div, #bookmarks_menu div, .menu label, #grid_btn, #sorting .toggle_UI_pref, #toggle_info, .split_btn span' +
  879. '{ cursor: pointer; }' +
  880. '#handle { cursor: col-resize; }' +
  881. '#content_pane:not(.has_zoom_image) #content_image img { cursor: zoom-in; }' +
  882. '#content_pane.has_zoom_image #content_image img { cursor: zoom-out; }' +
  883. '#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_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' +
  884. '{ display: none; }' +
  885. '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' +
  886. '{ display: none !important; }' +
  887. '#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' +
  888. '{ display: block; }' +
  889. 'body.has_images.has_fonts #grid_btn:hover ul.menu, #font_info:hover tbody' +
  890. '{ display:block !important; }' +
  891. '#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' +
  892. '{ display: inline-block; }' +
  893. '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' +
  894. '{ display: flex; }' +
  895. '#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' +
  896. '{ display: inline-flex; }' +
  897. 'body.is_gecko #dir_list tr td.name span { display: flow-root; }' +
  898. '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' +
  899. '{ display: table-row !important; }' +
  900. '#bookmarks_menu div, #content_pane, #content_pane.has_audio #content_audio td' +
  901. '{ display: table-cell; }' +
  902. '#sorting > div { display: grid; grid-gap:0; grid-template-columns: 1fr 1fr 1fr 1fr; }' +
  903. '#sort_by_name { grid-column: 1 / span 2; }' +
  904. '#sort_by_default { grid-column: 3 / span 2; }' +
  905. // display grid: dir_list rows and cells
  906. '#dir_list #tbody tr:not(.invisible), body.show_invisibles #tbody tr.invisible, body.show_details #dir_list tr td.details' +
  907. '{ display: grid; grid-gap:0; grid-template-columns: minmax(auto,7rem) 1fr minmax(auto,8rem); }' +
  908. 'td.name { grid-column: 1 / span 3; }' +
  909. 'td.size { grid-column: 1; grid-row: 2; }' +
  910. 'td.date { grid-column: 2; grid-row: 2; }' +
  911. 'td.kind { grid-column: 3; grid-row: 2; }' +
  912. // display grid: content pane grids
  913. '#content_pane.has_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); }' +
  914. '#content_grid .image_grid_item { grid-column: auto; display:flex; align-items: center; justify-content: center; }' +
  915. '#content_grid .font_grid_item { grid-column: 1 / -1; }' +
  916. // glyphs container
  917. '#content_font div#glyphs_container { display:grid; grid-gap:0; grid-template-columns:repeat(auto-fill, minmax(120px,auto)); }' +
  918. '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 ' +
  919. '{ filter:invert(1); }' +
  920. '.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' +
  921. '{ float: left; }' +
  922. 'html, body, :root { font-family:'+ $settings.UI_font +'; }' +
  923. 'body, :root, #content_text { font-size: '+ $settings.UI_font_size +'; }' +
  924. '#sidebar, #sidebar_header, #dir_list, #tfoot, #content_header, #content_header table, #warnings, #font_info td, #font_info th, #glyph_viewer_info' +
  925. '{ font-size: 0.875rem; }' +
  926. '#content_grid, .font_grid_item p, #error_message h1, #error_message h2' +
  927. '{ font-size: 1rem; }' +
  928. '#content_grid .font_grid_item h2 { font-size: '+ $settings.grid_font_size * 4 +'em; }' +
  929. '#content_font { font-size: '+ $settings.grid_font_size +'em; }' +
  930. '.lorem.first:first-line { font-size: '+ $settings.grid_font_size * 1.33 +'em; }' +
  931. 'td.name, td.name a::before, td.size, td.date { font-variant-numeric: tabular-nums; }'+
  932. '.lorem.first:first-line { font-variant: small-caps }' +
  933. '#sidebar_title th, h1, h2, h3, h4, h5, h6, #font_info th'+
  934. '{ font-weight: normal }' +
  935. '#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' +
  936. '{ font-weight: bold }' +
  937. 'html, body, :root, #parent_dir_menu a, #dir_list, #toggle_info, #main_content, #content_pane, #content_pdf, #content_text, #content_iframe' +
  938. '{ height: 100%; }' +
  939. '#sidebar_header, #parents_dir_menu, #parents_dir_menu div, #content_pane:not(.has_zoom_image) #content_image img, #content_grid div img' +
  940. '{ height: auto; }' +
  941. '.menu input { height: 0; }' +
  942. '#sorting div span::after { height: 8px; }' +
  943. '#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'+
  944. '{ height: 9px; }' +
  945. '#bookmarks li.bookmarks a::before { height: 12px; }' +
  946. '#toggle_sidebar, #toggle_info { height: 14px; }' +
  947. '#grid_btn, button, #prev_next_btns span, #scale span { height: 18px; }' +
  948. '#warnings h3::before { height: 24px; }' +
  949. '#audio { height: 32px; }' +
  950. '#main_content { height: '+ window.innerHeight +'px; }' +
  951. '#content_pane:not(.has_zoom_image) #content_image img { max-height: calc(100% - 4em); }' +
  952. '#font_info tbody { max-height: '+ (window.innerHeight * 0.75) +'px; }' +
  953. '!#content_pane.has_zoom_image #content_image img { max-height: none; }' +
  954. '#content_grid div img { max-height: '+ ($settings.grid_image_size) +'px; }' +
  955. '#title { min-height: 18px; }' +
  956. '#sidebar { min-height: 100%; }' +
  957. '#parents_dir_menu div, #content_header td button, #content_font'+
  958. '{ hyphens: none; }' +
  959. 'html, body, :root, .hamburger h3, .lorem { hyphens: auto; }' +
  960. '#content_container { justify-content: center; }' +
  961. '.lorem.first:first-line, .font_grid_item p, #font_info th'+
  962. '{ letter-spacing: 0.1em; text-indent:0.1em; }' +
  963. '#sidebar_title th { letter-spacing: 0.5em; text-indent:0.5em; }' +
  964. '.image_grid_item a, button { line-height: 0; }' +
  965. '.split_btn span, .font_grid_item p { line-height: 1; }' +
  966. '#dir_list tr a, #title { line-height: 1.4; }' +
  967. '#warnings h3 { line-height: 2; }' +
  968. '#sidebar ul, #grid_btn .menu li { list-style-type: none; }' +
  969. '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' +
  970. '{ margin: 0; }' +
  971. '#content_image, #content_image img { margin-left: auto; margin-right: auto; }' +
  972. '.image_grid_item + .font_grid_item { margin-top: -1px; }' +
  973. '#checkbox_div label input, #show_details, body.is_error #tbody h1'+
  974. '{ margin-top: 0; }' +
  975. 'body.has_audio #dir_list input { margin-top: 1px; }' +
  976. '#increase { margin-right: -4px; }' +
  977. 'th input, tr.media input, #scale { margin-right: 8px; }' +
  978. '#show_details { margin-right: 0.5em; }' +
  979. '#warning_ignore_btn { margin-right: 2em; }' +
  980. '#checkbox_div { margin-right: calc(-6em - 4px); }' +
  981. '#bookmarks li a::before { margin-bottom: -2px; }' +
  982. '#show_details { margin-bottom: 0; }' +
  983. 'body.has_audio #dir_list input { margin-bottom: 1px; }' +
  984. '#content_grid.has_image_grid { margin-bottom: 1rem; }' +
  985. '#decrease { margin-left: -4px; }' +
  986. 'th input { margin-left: 2px; }' +
  987. 'tr.media input { margin-left: 7px; }' +
  988. '#prev_next_btns { margin-left: 8px; }' +
  989. '#show_details, #warnings button { margin-left: 0.5em; }' +
  990. '#warnings { margin-left: -12em; }' +
  991. '#dir_list tbody tr { margin-inline-start: 0; }' +
  992. '#sidebar ul { -webkit-margin-before: 0em !important; -webkit-margin-after: 0em !important; -webkit-padding-start:0em; }' +
  993. '#open_font { opacity: 0.0; }' +
  994. '#content_pane.has_ignored::before, #close_audio::after { opacity: 0.3; }' +
  995. '#close_audio:hover::after { opacity: 0.6; }' +
  996. '#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' +
  997. '{ opacity: 0.7; }' +
  998. '#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' +
  999. '{ opacity: 1.0; }' +
  1000. '#grid_btn, #dir_list tbody, #dir_list tbody a, #audio:focus, #content_grid .font_grid_item, #content_font, #warnings button:focus, #content_video' +
  1001. '{ outline: none; }' +
  1002. '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' +
  1003. '{ overflow: hidden; }' +
  1004. '#dir_list tbody, #next_track, #prev_track, #content_container, #content_font, #content_grid, #font_info tbody' +
  1005. '{ overflow: auto; }' +
  1006. '#sidebar, #content_font { overflow-wrap: break-word; }' +
  1007. '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' +
  1008. '{ padding: 0; }' +
  1009. 'div#glyphs_container, div.glyph_container, #glyph_viewer, #glyph_viewer_info div'+
  1010. '{ padding: 0 !important; }' +
  1011. '#show_details, #prev_next_btns, #scale { padding-top: 0; }' +
  1012. '#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' +
  1013. '{ padding-top: 4px; }' +
  1014. '#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' +
  1015. '{ padding-top: 6px; }' +
  1016. '#content_grid .font_grid_item, .font_grid_item p, #content_font div.lorem' +
  1017. '{ padding-top: 0.5rem; }' +
  1018. '#error_message, #warnings { padding-top: 1rem; }' +
  1019. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #content_font div.specimen' +
  1020. '{ padding-top: 2rem; }' +
  1021. '#sidebar_header tbody tr:last-of-type td { padding-right: 0; }' +
  1022. 'div.glyph_container div.glyph_info { padding-right: 2px; }' +
  1023. '#sidebar_title th, #scale { padding-right: 4px; }' +
  1024. '#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' +
  1025. '{ padding-right: 6px; }' +
  1026. '#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' +
  1027. '{ padding-right: 8px; }' +
  1028. '#parents_dir_menu + ul li a, #dir_list td.details, #title, #content_audio_title td'+
  1029. '{ padding-right: 12px; }' +
  1030. '#content_audio_title td:before { padding-right: 18px; }' +
  1031. '#grid_btn .menu { padding-right: 24px; }' +
  1032. '#error_message, #warnings { padding-right: 1rem; }' +
  1033. '.font_grid_item p, .font_grid_item a { padding-right: 2rem; }' +
  1034. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #font_specimen' +
  1035. '{ padding-right: 2.5rem; }' +
  1036. '#show_details, #prev_next_btns, #scale { padding-bottom: 0; }' +
  1037. 'body.is_dirs_on_top #dir_list tbody tr.sorted:not(:last-of-type), div.glyph_container div.glyph_info' +
  1038. '{ padding-bottom: 2px; }' +
  1039. '#sorting, #title, body #content_audio_title td, #title_buttons_left, #title_buttons_right' +
  1040. '{ padding-bottom: 3px;}' +
  1041. '#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' +
  1042. '{ padding-bottom: 4px; }' +
  1043. '#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' +
  1044. '{ padding-bottom: 6px; }' +
  1045. '.hamburger h4 { padding-bottom: 9px; }' +
  1046. '.specimen, .font_grid_item p, .font_grid_item a { padding-bottom: 0.5rem; }' +
  1047. '#error_message, #warnings { padding-bottom: 1rem; }' +
  1048. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #content_font > div.specimen, #content_font .lorem:last-of-type' +
  1049. '{ padding-bottom: 2rem; }' +
  1050. '#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' +
  1051. '{ padding-left: 0px; }' +
  1052. 'div.glyph_container div.glyph_info { padding-left: 2px; }' +
  1053. '#sidebar_title th, #bookmarks ul li a, #dir_list .audio a, #dir_list .video a, #checkbox_div, #scale' +
  1054. '{ padding-left: 4px; }' +
  1055. '#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' +
  1056. '{ padding-left: 6px; }' +
  1057. '#parents_dir_menu + ul a, #title, #content_audio_title td'+
  1058. '{ padding-left: 12px; }' +
  1059. '#text_editor_row a { padding-left: 18px; }' +
  1060. '.menu label, body.has_hidden_sidebar #title_buttons_left'+
  1061. '{ padding-left: 24px; }' +
  1062. '#dir_list #tbody tr:not(.media) a span { padding-left: 27px; -webkit-padding-start: 27px; }' +
  1063. '#bookmarks .bookmarks ul li a { padding-left: 28px; }' +
  1064. '#dir_list #tbody td.details.size, tr.media a.icon { padding-left: 30px; }' +
  1065. '#error_message, #warnings { padding-left: 1rem; }' +
  1066. '.font_grid_item p, .font_grid_item a { padding-left: 2rem; }' +
  1067. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #font_specimen' +
  1068. '{ padding-left: 2.5rem; }' +
  1069. '#dir_list td.name a { -webkit-padding-start: 0; }' +
  1070. '#dir_list .icon + td.name a { -webkit-padding-start: 1em; }' +
  1071. '#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' +
  1072. '{ position: relative; }' +
  1073. '#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' +
  1074. '{ position: absolute; }' +
  1075. '#tfoot, #glyph_viewer, #font_info, #content_pane.has_image #content_image'+
  1076. '{ position: fixed; }' +
  1077. '#parent_dir_menu, #overlay, #glyph_viewer, #content_pane.has_zoom_image #content_image, #content_image'+
  1078. '{ top: 0; right: 0; bottom: 0; left: 0; }' +
  1079. '#dir_list, #handle, #content_pane.has_grid #content_grid::after, .split_btn::after'+
  1080. '{ top: 0; bottom: 0; }' +
  1081. '#sidebar ul, #tbody, .glyph_info, #tfoot { left: 0; right: 0; }' +
  1082. '#tbody, #toggle_info, #warnings { top: 0 !important; }' +
  1083. '#bookmarks_menu + ul > li > ul, #grid_btn .menu { top: -1px !important; }' +
  1084. 'body.has_hidden_sidebar #sidebar_wrapper { top: 2px; }' +
  1085. '#toggle_sidebar { top: 4px; }' +
  1086. '#grid_btn .menu, #content_grid, #content_pane.has_grid #content_grid::after, #toggle_info'+
  1087. '{ right: 0; }' +
  1088. '#handle { right: -4px; }' +
  1089. '#toggle_sidebar { right: 4px; }' +
  1090. '#dir_list tbody, #tfoot, #content_container, .glyph_info, #font_info'+
  1091. '{ bottom: 0; }' +
  1092. 'body.has_hidden_sidebar #toggle_sidebar, #content_grid { left: 0; }' +
  1093. '#grid_btn ul.menu { left: unset; }' +
  1094. 'body.has_hidden_sidebar #sidebar_wrapper { left: 3px; }' +
  1095. 'body.show_numbers #tbody tr td.name a::before { left: 6px; }' +
  1096. '#warnings, .split_btn::after { left: 50%; }' +
  1097. '#bookmarks_menu + ul > li > ul { left: 100%; }' +
  1098. '#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' +
  1099. '{ text-align: left; }' +
  1100. '#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' +
  1101. '{ text-align: center; }' +
  1102. '#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' +
  1103. '{ text-align: right; }' +
  1104. 'a, a:hover { text-decoration: none !important; }' +
  1105. '#bookmarks .bookmarks ul li a { text-indent: -24px; }' +
  1106. '#dir_list .details.kind { text-overflow: ellipsis; }' +
  1107. '#dir_list, #content_pane { transform: scale(1); }' + // needed to establish #dir_list as containing block for thead and tfoot position fixed.
  1108. 'body.has_hidden_sidebar #toggle_sidebar, #sorting div.up span::after, #prev_track, #toggle_info' +
  1109. '{ transform:rotate(180deg) !important; }' +
  1110. '#sidebar_header, #content_pane:not(.has_zoom_image) #content_image' +
  1111. '{ user-select:none; -webkit-user-select:none; }' +
  1112. '#content_pane, #title_buttons_left, #title_buttons_right, #title'+
  1113. '{ vertical-align:top; }' +
  1114. '#content_pane:not(.has_grid) #content_grid { visibility:hidden; }' +
  1115. '#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' +
  1116. '{ white-space: normal; }' +
  1117. '#sorting span, #tbody td:not(.name), #grid_btn .menu li, .hamburger h1, .hamburger h2, .hamburger h4' +
  1118. '{ white-space: pre; }' +
  1119. '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' +
  1120. '{ width: 100%; }' +
  1121. '#sidebar_menus td:nth-of-type(2), #dir_list .date, #title, #content_pane:not(.has_zoom_image) #content_image img, #content_grid div img' +
  1122. '{ width: auto; }' +
  1123. '.split_btn span { width: 2em; }' +
  1124. '#content_pane.has_grid #content_grid::after, .split_btn::after' +
  1125. '{ width: 1px; }' +
  1126. '#handle { width: 8px; }' +
  1127. '#sorting div span::before, #sorting div span::after, #toggle_sidebar, #toggle_info' +
  1128. '{ width: 18px; }' +
  1129. '#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'+
  1130. '{ width: 24px; }' +
  1131. '#warnings h3::before { width: 32px; }' +
  1132. '#prev_track, #next_track, #close_audio { width: 2rem; }' +
  1133. '#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' +
  1134. '{ width: 4rem; }' +
  1135. '#bookmarks_menu div, #checkbox_div { width: 6em; }' +
  1136. '#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' +
  1137. '{ width: 9.5em; }' +
  1138. '#warnings { width: 26em; }' +
  1139. 'body.has_hidden_sidebar #sidebar_wrapper, .menu input { width: 0 !important; }' +
  1140. '#reload_btn, #close_btn { width: 52px; }' +
  1141. '#font_info td:first-of-type { width: 33.33%; }' +
  1142. '#font_info td:last-of-type { width: 66.66%; }' +
  1143. 'body.has_hidden_sidebar #content_pane, #font_info { width: 100% !important; }' +
  1144. 'body:not(.has_hidden_sidebar) #sidebar_wrapper { width:'+ getQuery('width').toString() +'%; }' +
  1145. 'body:not(.has_hidden_sidebar) #content_pane { width:'+ (100 - getQuery('width')).toString() +'%; }' +
  1146. '#content_video { width: calc(100% - 2rem); }' +
  1147. 'html, body, :root { max-width: 100%; }' +
  1148. '#content_pane:not(.has_zoom_image) #content_image img { max-width: calc(100% - 5rem); }' +
  1149. '!#content_pane.has_zoom_image #content_image img { max-width: none; }' +
  1150. '#sidebar_menus td:nth-of-type(odd) { max-width: 24px; }' +
  1151. '#content_grid div img { max-width:'+ ($settings.grid_image_size).toString() +'px; }' +
  1152. 'body.show_numbers #tbody tr td.name a::before { min-width: 17px; }' +
  1153. 'body:not(.has_hidden_sidebar) #sidebar_menus td:nth-of-type(odd)'+
  1154. '{ min-width: 24px; }' +
  1155. 'body:not(.has_hidden_sidebar) #dir_list { min-width: 100px; }' +
  1156. 'body:not(.has_hidden_sidebar) #sidebar_wrapper { min-width: 220px; }' +
  1157. '#sidebar_wrapper, #content_pane { will-change: width }' +
  1158. '#content_header td button { word-break: none; }' +
  1159. '#title { word-break: break-word; }' +
  1160. '#content_pane { z-index: 0; }' +
  1161. '#handle, #sidebar_wrapper, #glyph_viewer, #font_info { z-index: 1; }' +
  1162. '#parents_dir_menu + ul, #content_header { z-index: 2; }' +
  1163. '#sidebar_header { z-index: 3; }' +
  1164. '#toggle_sidebar, #grid_btn { z-index: 9997; }' +
  1165. '#overlay, #bookmarks { z-index: 9998; }' +
  1166. '#warnings { z-index: 9999; }' +
  1167. 'body.has_hidden_sidebar #sidebar_header { z-index:unset; }'
  1168. ;
  1169. // Gecko Styles:
  1170. const $gecko_style_rules =
  1171. 'html, body.is_gecko { border: solid 1px gray !important; }' +
  1172. 'body.is_gecko button { padding:revert; }' +
  1173. 'body.is_gecko #grid_btn .menu { top:-7px; left:-120px; }' +
  1174. 'body.is_gecko thead { font-size:100%; }' +
  1175. 'body.is_gecko #dir_list .dir::before { position:absolute; }' +
  1176. 'body.is_gecko.use_default_icons:not(.is_converted_list) #dir_list .file .name .icon'+
  1177. '{ padding-left:4px; background:none; }' +
  1178. 'body.is_gecko.use_default_icons #dir_list .file .name .icon img'+
  1179. '{ margin-right:6px; height:14px; }' +
  1180. 'body.is_gecko #tbody > tr > td:not(:first-of-type) { float:left }' +
  1181. 'body.is_gecko #content_audio_title td { padding-top: 6px; }' +
  1182. 'body.is_gecko #content_audio_title td { padding-bottom: 0; }' +
  1183. 'body.is_gecko #audio, body.is_gecko #audio_container { background-color: transparent; }'
  1184. ;
  1185. var $text_editing_style_rules =
  1186. 'html, body, #iframe_body { margin:0; padding:0; }' +
  1187. // toolbar
  1188. '#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; }' +
  1189. '#toolbar li { margin:4px; padding:4px; width:3.5em; display:block; opacity:0.5; list-style-type:none; cursor:pointer; }' +
  1190. '#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'+
  1191. '{ opacity:1; }' +
  1192. '#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; }' +
  1193. '#toolbar li#sync_scroll { width:8em; float:left; opacity:1; }' +
  1194. '#toolbar li#sync_scroll input { float:left; }' +
  1195. '#toolbar li#sync_scroll label { width:8em; display:block; font-size:inherit; line-height:1.5; }' +
  1196. '#toolbar li#clear_text { height:16px; float:right; text-align:center; }' +
  1197. '#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; }' +
  1198. '#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; }' +
  1199. '#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; }' +
  1200. '.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; }' +
  1201. '#toolbar li#save_btn div { display:none; position:relative; top:-9px; left:-24px; color:#999; text-align:right; }' +
  1202. '#toolbar li#save_btn:hover div { display:block; }' +
  1203. '#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; }' +
  1204. '#toolbar li#save_btn span:first-of-type { border-bottom-width:0px; }' +
  1205. '#toolbar li#save_btn span:hover { color:#444; }' +
  1206. // resize handle
  1207. '.split_view #text_editing_handle { width:9px; position:absolute; top:0; bottom:0; left:calc(50% - 4px); cursor:col-resize; z-index:11; }' +
  1208. '#text_editing_handle { z-index:-1; }' +
  1209. // source
  1210. '#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*/,'') +'; }' +
  1211. '#content_source, #content_preview { position:absolute; top:32px; right:0; bottom:0; left:0; }' +
  1212. '#content_source:focus { outline:none; background:#FFF; box-shadow: inset 0 0 4px #888; }' +
  1213. // preview
  1214. '#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*/,'') +'; }' +
  1215. // split views
  1216. '.preview_text:not(.split_view) #content_source, .source_text:not(.split_view) #content_preview, li#save_btn div, .comment'+
  1217. '{ display:none; }' +
  1218. '.split_view #content_preview { border-left:solid 1px #999; }' +
  1219. '.split_view #content_source { width:50%; }' +
  1220. '.split_view #content_preview { left:50%; }' +
  1221. // preview styles
  1222. '#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*/,'') +'; }' +
  1223. '#content_preview .no_list { list-style:none; }' +
  1224. '#content_preview > .no_list { padding:0; }' +
  1225. '#content_preview .text-align-center { text-align:center; }' +
  1226. '#content_preview th, #content_preview td { vertical-align:top; }' +
  1227. '#content_preview blockquote { margin-top:1em; margin-bottom:1em; color: #555; }' +
  1228. '#content_preview blockquote + blockquote { margin-top:0; }' +
  1229. '.markdown-body input[type="checkbox"] { margin-top:0.375em; margin-right:6px; float:left; }' +
  1230. 'h1 .uplink,h2 .uplink,h3 .uplink,h4 .uplink,h5 .uplink,h6 .uplink'+
  1231. '{ margin:0; padding:0; display:inline-block; font-size:0.875em; cursor:pointer; transition: opacity 0.25s; opacity:0; }' +
  1232. 'h1:hover .uplink,h2:hover .uplink,h3:hover .uplink,h4:hover .uplink,h5:hover .uplink,h6:hover .uplink'+
  1233. '{ transition: opacity 0.25s; opacity:0.5; }' +
  1234. '#content_preview table { font-size:inherit; }' +
  1235. '#content_preview table th { background-color:#EEE; }' +
  1236. '.markdown-body::before, .markdown-body::after { display:none !important; background:transparent; }' +
  1237. // edited warning
  1238. '#iframe_body #warnings p, #iframe_body #warnings button { display:none; }' +
  1239. '#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; }' +
  1240. '#iframe_body #warnings h3 { margin:0; font-weight:normal; }' +
  1241. '#iframe_body #warnings div { text-align:right; }' +
  1242. '#iframe_body #warnings button { margin-left:0.5em; }' +
  1243. '#iframe_body #warnings #warning_ignore_btn { margin-right:2em; }' +
  1244. '#iframe_body.has_warning #warnings, #iframe_body.has_warning #warnings.unsaved p#warning_unsaved, #iframe_body.has_warning #warnings.clear p#warning_clear'+
  1245. '{ display:block; }' +
  1246. '#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'+
  1247. '{ display:inline-block; }' +
  1248. // disabled text editing
  1249. '#iframe_body.enable_text_editing #toolbar, #iframe_body.enable_text_editing #preview_text, #iframe_body.enable_text_editing #text_editing_handle'+
  1250. '{ display:none; }' +
  1251. '#iframe_body.enable_text_editing #content_source.disabled'+
  1252. '{ top:0; background:white; }'
  1253. ;
  1254. var $iframe_styles =
  1255. '#iframe_body a.up, #iframe_body #dir_list { background: transparent; }' +
  1256. '#iframe_body :root, html, body { background-color: #BBB; }' +
  1257. '#iframe_body #thead, #tbody tr { background-color: rgba(221,221,221,0.5); }' +
  1258. '#iframe_body #thead tr#parent { background-color: rgba(144,144,144,0.33); }' +
  1259. '#iframe_body #tbody tr:nth-of-type(odd) { background-color: rgba(221,221,221,1); }' +
  1260. '#iframe_body #tbody tr:not(.media):hover { background-color: rgba(172,202,235,0.75) !important; }' +
  1261. '#iframe_body #tbody tr.media:hover { background-color: rgba(116,190,190,0.5) !important; }' +
  1262. '#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; }' +
  1263. CSS_UI_Icon_Rules('#iframe_body') + // background icons
  1264. '#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'+
  1265. '{ background-image:'+ SVG_UI_Icon('check_mark') +'; background-repeat: no-repeat; background-size:10px; background-position: center; }' +
  1266. '#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'+
  1267. '{ background-image:'+ SVG_UI_Icon('chevron_up') +'; background-repeat: no-repeat; background-size:10px; background-position: center; }' +
  1268. '#iframe_body .sorting.down span::after { transform:rotate(180deg) }' +
  1269. ':root, html, #iframe_body { border:0 !important; }' + // border
  1270. 'html, #iframe_body { border-radius:0; }' +
  1271. '#iframe_body #dir_list { border-collapse:collapse; }' +
  1272. '#iframe_body #dir_list thead th { border-bottom:solid 1px #999; }' +
  1273. '#iframe_body, iframe_body td.name, iframe_body td.details'+
  1274. '{ box-sizing:border-box; }' + // box-sizing
  1275. '#iframe_body a { color:#111111; }' + // color
  1276. '#iframe_body a:hover { color:#000000; }' +
  1277. '#iframe_body tr.ignore, #iframe_body tr.ignore a { color:grey; }' +
  1278. '.sorting span::before,.sorting span::after { content:""; width:16px; height:8px; display:inline-block; position:relative; }' +// content
  1279. '#iframe_body tbody { counter-reset: row; }' + // counter
  1280. '#iframe_body.show_numbers tr td.name::before { counter-increment: row; content:counter(row); margin-right:6px; min-width:1.25em; text-align:right;}' +
  1281. '#iframe_body #dir_list td.name::before, #iframe_body #dir_list a::before, td.size, td.date'+
  1282. '{font-variant-numeric: tabular-nums; }'+
  1283. '#iframe_body #dir_list th.sorting { cursor: pointer; }' + // cursor
  1284. '#iframe_body #dir_list tr::before, #iframe_body #dir_list td.name input, #iframe_body td.ext'+
  1285. '{ display:none; }' + // display
  1286. '#iframe_body a { display:block; }' +
  1287. '#parent + tr { display: grid; grid-gap:0; grid-template-columns: 50% 50%; }' +
  1288. '#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); }' +
  1289. '#iframe_body td.name, #iframe_body #sort_by_name, #iframe_body #sort_by_ext'+
  1290. '{ grid-column: 1; }' +
  1291. '#iframe_body td.size, #iframe_body #sort_by_default, #iframe_body #sort_by_size'+
  1292. '{ grid-column: 2; }' +
  1293. '#iframe_body td.date, #iframe_body #sort_by_date { grid-column: 3; }' +
  1294. '#iframe_body td.kind, #iframe_body #sort_by_kind { grid-column: 4; }' +
  1295. '#iframe_body #dir_list td.name::before, #iframe_body #dir_list a::before'+
  1296. '{ float:left; }' + // float
  1297. '#iframe_body { font-family:'+ $settings.UI_font +'; }' + // fonts
  1298. '#iframe_body { font-size:'+ parseFloat($settings.UI_font_size) * 0.875 + $settings.UI_font_size.replace(/\d*/,'') +'; }' +
  1299. '#iframe_body #dir_list, #iframe_body #thead { font-size: 1em; }' +
  1300. 'td.name, td.name a::before, td.size, td.date { font-variant-numeric: tabular-nums; }'+
  1301. '#iframe_body, #iframe_body #dir_list { height:100%; }' + // height
  1302. '#iframe_body #content_source { height:inherit; }' +
  1303. '#iframe_body #thead { height:2em; max-height:2em; }' +
  1304. '#iframe_body #tbody tr { line-height:1.5; }' + // line-height
  1305. 'html, body, #iframe_body { margin:0; }' + // margin
  1306. '#iframe_body .dir::before, #iframe_body .file > img{ margin-inline-end: 6px; }' +
  1307. '#iframe_body #dir_list tr, #iframe_body #tbody tr:hover { outline:0; }' + // outline
  1308. '#iframe_body, #iframe_body #dir_list, .details.date, .details.kind'+
  1309. '{ overflow:hidden; text-overflow: ellipsis; }' + // overflow
  1310. '#iframe_body #dir_list #tbody { overflow:auto; }' +
  1311. 'html, :root, #iframe_body, body { padding:0; }' + // padding
  1312. '#iframe_body #tbody tr td, #iframe_body #thead tr th { padding-top:3px; }' +
  1313. '#iframe_body #tbody tr td { padding-right: 6px; }' +
  1314. '#iframe_body #tbody tr td, #iframe_body #thead tr th { padding-bottom:3px; }' +
  1315. '#parent th, #iframe_body #tbody tr td.details.kind { padding-right: 1em; }' +
  1316. '#iframe_body td.details { padding-left: 6px; }' +
  1317. '#parent th, #tbody tr td.name { padding-left:1em; }' +
  1318. '#iframe_body #dir_list, #iframe_body #dir_list tr td.name a::before'+
  1319. '{ position:relative; }' + // position
  1320. '#iframe_body, #iframe_body #dir_list #tbody { position:absolute; right:0; bottom:0; left:0; }' +
  1321. '#iframe_body th { text-align:center; }' + // text-align
  1322. '#iframe_body th:last-of-type, #iframe_body td.details { text-align:right; }' +
  1323. '#iframe_body th:first-of-type { text-align:left; }' +
  1324. '#iframe_body a, #iframe_body a:hover, #iframe_body td:hover'+
  1325. '{ text-decoration:none !important; }' + // text-decoration
  1326. '#iframe_body a.icon { text-indent:2px; }' + // text-indent
  1327. '#iframe_body #thead { user-select:none; -webkit-user-select:none; }' +
  1328. '#iframe_body td.details { vertical-align:top; }' +
  1329. 'html, #iframe_body, #iframe_body #dir_list, #iframe_body #dir_list tr'+
  1330. '{ width:100%; max-width:100%; min-width:100%; }' +
  1331. '#iframe_body #dir_list td:not(:first-child) { width:unset; }' +
  1332. '#iframe_body td:not(.name) { white-space:pre; }'
  1333. ;
  1334.  
  1335. // ADD STYLES
  1336. const $font_styles = document.createElement('style');
  1337. const $font_grid_styles = document.createElement('style');
  1338.  
  1339. function addStyles(el) {
  1340. el.find('style, link[rel="stylesheet"], link[href$="css"]').remove(); // remove any existing stylesheets
  1341. el.append('<style>'+ $main_style_rules +'</style>');
  1342. el.append('<style>'+ $gecko_style_rules +'</style>');
  1343. el.append($font_styles); // empty until font is previewed
  1344. el.append($font_grid_styles); // empty until font grid is made
  1345. el.append('<style>'+ $text_editing_style_rules +'</style>');
  1346. el.append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css"></link>');
  1347. }
  1348. // ***** END STYLES ***** //
  1349.  
  1350. // ***** INDEX PREP ***** //
  1351. //
  1352. function getIndexType() {
  1353. // Try to determine index type from parent directory link container,
  1354. // with fallbacks for indexes that don't have parent directories,
  1355. // or for parent directory links that aren't siblings or ancestors of the index itself.
  1356. let parentLinkParent; // Possible elements: pre, li, td, th, div -- used to determine index type
  1357. // Try to find parent directory link:
  1358. let parentLink = $('a:contains("Parent Directory"), a:contains("parent directory"), a[href="../"], a[href="/"], a[href^="?"], img[alt*="PARENTDIR"]');
  1359. if ( parentLink.length === 0 ) {
  1360. parentLinkParent = $('body').find('> ul li, > pre, > table:last-of-type tr td');
  1361. } else {
  1362. parentLinkParent = parentLink.parent(); // use original found parentLink
  1363. }
  1364. // If no parentLinkParent found, type = error; else return parent node name
  1365. let nodeName = ( parentLinkParent[0] !== undefined ? parentLinkParent[0].nodeName.toLowerCase() : '');
  1366. if ( parentLinkParent.length === 0 ) {
  1367. nodeName = 'error';
  1368. } else if ( $protocol.startsWith('file') ) {
  1369. if ( navigator.userAgent.indexOf('Firefox') > 0 ) {
  1370. nodeName = 'gecko';
  1371. }
  1372. }
  1373. let types = {'gecko':'gecko','li':'list','pre':'pre','th':'table','td':'table','div':'default','error':'error'};
  1374. let type = types[nodeName];
  1375.  
  1376. if ( type === 'table' ) {
  1377. parentLinkParent.closest('table').addClass('PARENTTABLE');
  1378. }
  1379. if ( type === 'list' ) {
  1380. parentLink.closest('ul').addClass('PARENTLIST');
  1381. }
  1382. return type;
  1383. }
  1384.  
  1385. // Return Index items, Index type, remove parent directory link, and add body class.
  1386. function getIndexItems(el) {
  1387. const type = getIndexType();
  1388. let items;
  1389.  
  1390. switch(type) {
  1391. case 'gecko':
  1392. $(el).addClass('is_converted_gecko');
  1393. items = $('body').find('> table > tbody');
  1394. break;
  1395. case 'list':
  1396. $(el).addClass('is_converted_list');
  1397. items = $('body').find('> ul');
  1398. break;
  1399. case 'pre':
  1400. $(el).addClass('is_converted_pre');
  1401. items = $('body').find('> pre').html();
  1402. break;
  1403. case 'table':
  1404. case 'td':
  1405. $(el).addClass('is_converted_table');
  1406. if ( $('table.PARENTTABLE > tbody').length === 1 ) {
  1407. items = $('table.PARENTTABLE > tbody');
  1408. } else {
  1409. items = $('table.PARENTTABLE'); // tables without tbody
  1410. }
  1411. break;
  1412. case 'default': // local chrome default
  1413. $(el).addClass('is_default');
  1414. items = $('body').find('> table').find('> tbody');
  1415. break;
  1416. case 'error': // error
  1417. $(el).addClass('is_error');
  1418. items = $('body').html();
  1419. break;
  1420. }
  1421. return [items,type];
  1422. }
  1423.  
  1424. // Index Prep: convert rows and return array of rows, with link, size, date-modified
  1425. function convertIndexItems(type,items) {
  1426. let converted = [];
  1427. switch(type) {
  1428. case 'gecko':
  1429. converted = convertGeckoType(items);
  1430. break;
  1431. case 'list':
  1432. converted = convertListType(items);
  1433. break;
  1434. case 'pre':
  1435. converted = convertPreType(items);
  1436. break;
  1437. case 'table':
  1438. case 'default': // local chrome indexes
  1439. converted = convertTableType(type,items);
  1440. break;
  1441. case 'error':
  1442. converted = convertErrorType(items);
  1443. break;
  1444. }
  1445. return converted;
  1446. }
  1447. // Index Prep: convert list type function
  1448. function convertGeckoType(items) {
  1449. let preppedIndex = [];
  1450. const rows = Array.from(items.find('> tr'));
  1451. for ( let row of rows ) {
  1452. let preppedRow = [];
  1453. let cellContents = '';
  1454. let cells = Array.from( $(row).find('> td') );
  1455. let link = ($(cells).find('a').attr('href'));
  1456. for ( let cell of cells ) {
  1457. cellContents = cell.innerText;
  1458. cellContents = ( cellContents !== undefined ? cellContents.trim() : '');
  1459. preppedRow.push(cellContents);
  1460. }
  1461. preppedRow[1] = preppedRow[1].replace(' KB','000'); // convert reported size in KB to total bytes
  1462. preppedRow[2] = preppedRow[2] + ' '+ preppedRow[3];
  1463. preppedRow = preppedRow.slice(1,-1);
  1464. if ( link.length > 0 && link !== '/' && link !== '../' ) {
  1465. preppedRow.unshift(link);
  1466. }
  1467. if ( preppedRow.length > 0 ) { preppedIndex.push(preppedRow); }
  1468. }
  1469. return preppedIndex;
  1470. }
  1471. // Index Prep: convert list type function
  1472. function convertListType(items) {
  1473. let preppedIndex = [];
  1474. const rows = Array.from(items.find('li'));
  1475. for ( let row of rows ) {
  1476. if ( row.innerHTML.indexOf('Parent Directory') === -1 ) {
  1477. let preppedRow = [];
  1478. let link = $(row).find('a').attr('href');
  1479. row = row.innerHTML.replace(/<a .+?<\/a>\s*/,'');
  1480. let cells = row.split(' ');
  1481. for ( let cell of cells ) {
  1482. if ( cell.trim().length > 0 ) {
  1483. preppedRow.push(cell);
  1484. }
  1485. }
  1486. if ( link.length > 0 && link !== '/' && link !== '../' ) {
  1487. preppedRow.unshift(link);
  1488. }
  1489. if ( preppedRow.length > 0 ) {
  1490. preppedIndex.push(preppedRow);
  1491. }
  1492. }
  1493. }
  1494. return preppedIndex;
  1495. }
  1496. // Index Prep: convert pre type function
  1497. function convertPreType(items) {
  1498. let preppedIndex = [];
  1499. items = items.replace(/<a /g,' <a ').replace(/<\/a>/g,'</a> ') // ensure two spaces after file links
  1500. .replace(/\[\s*?\]/g,'[]'); // remove empty 'alt=[ ]'
  1501. const rows = items.split('\n');
  1502. const spaces = /\s{2,}/; // assumes pre type only uses spaces between "columns"
  1503.  
  1504. for ( let row of rows ) {
  1505. let preppedRow = [];
  1506. row = row.replace(/(<a[^>]+?>).+?<\/a>/g,'$1'); // remove link display name because some have 2+ spaces, leading to incorrect split for cells array
  1507. let cells = row.split(spaces);
  1508. let link;
  1509. for ( let cell of cells ) {
  1510. if ( cell.trim().length > 0 ) {
  1511. if ( cell.indexOf('href="') > 0 && cell.search(/href="[?|\/"]|Parent Directory/) === -1 ) {
  1512. link = $(cell).attr('href');
  1513. } else {
  1514. if ( cell.search(/href="|<img |<hr>/) === -1 ) {
  1515. preppedRow.push(cell);
  1516. }
  1517. }
  1518. }
  1519. }
  1520. if ( link !== undefined ) { preppedRow.unshift(link); } // add link to front of preppedRow
  1521. if ( preppedRow.length > 1 ) { preppedIndex.push(preppedRow); }
  1522. }
  1523. return preppedIndex;
  1524. }
  1525. // Index Prep: convert table type function
  1526. function convertTableType(type,items) { // for local chrome indexes and server-generated table-type indexes
  1527. let preppedIndex = [];
  1528. const rows = Array.from(items.find('> tr:not(.PARENT)'));
  1529. for ( let row of rows ) {
  1530. if (row.innerText.search(/Parent Directory/) === -1 ) {
  1531. let preppedRow = [];
  1532. let cells = Array.from( $(row).find('td') );
  1533. let link = $(cells).find('a').attr('href');
  1534. for ( let cell of cells ) {
  1535. cell = cell.innerHTML.trim();
  1536. if ( cell.length > 0 && cell.search(/^&nbsp;$|href="|<img /m) === -1 ) {
  1537. preppedRow.push( cell );
  1538. }
  1539. }
  1540. if ( link !== undefined ) { preppedRow.unshift(link); }
  1541. if ( preppedRow.length > 1 ) { preppedIndex.push(preppedRow); } // preppedRow.length > 2 in order to omit parent directory row
  1542. }
  1543. }
  1544. return preppedIndex;
  1545. }
  1546. // Index Prep: convert error pages (page not found, etc.)
  1547. function convertErrorType(items) {
  1548. items = items.replace(/ style="[^"]*?"/g,'').replace(/<hr>/g,'');
  1549. items = '<div id="error_message"><div id="error_message_icon"></div>'+ items +'</div>';
  1550. return items;
  1551. }
  1552.  
  1553. // Index Prep: Build new Index from prepped rows
  1554. function buildNewIndex(preppedIndex,sort) {
  1555. let newIndexItems = [];
  1556. let i = 0;
  1557. for ( let row of preppedIndex ) {
  1558. // Get row attrs and text
  1559. const rowLink = row[0] !== undefined ? row[0].replace(/&amp;/g,'&') : '';//.replace(//,''); // decode some reserved characters
  1560. const rowName = getItemName(rowLink).replace(/^\s/m,'\&nbsp;').replace(/^\//m,'').replace(/([-_——])/g,'$1<wbr>'); // display name, with word breaks added after unbreakable chars
  1561. const rowSortName = getItemName(rowLink).replace(/^\//m,'').replace('/','').toLocaleLowerCase();
  1562. const sizesAndDates = getItemSizeAndDate(row);
  1563. const rowSize = sizesAndDates[0];
  1564. const rowSortSize = sizesAndDates[1];
  1565. const rowDate = sizesAndDates[2];
  1566. const rowSortDate = sizesAndDates[3];
  1567. const rowExt = getItemExt(rowLink);
  1568. const rowSortKind = getItemKind(rowExt);
  1569. const rowKind = rowSortKind.slice(0,1).toUpperCase() + rowSortKind.slice(1);
  1570. const rowClasses = getItemClasses(rowName,rowSortKind,rowExt);
  1571. // Assemble row elements
  1572. let newRow = $('<tr></tr>').attr('id','rowid-'+ i).addClass(rowClasses).attr('data-kind',rowSortKind).attr('data-ext',rowExt);
  1573. const checkbox = ( rowClasses.indexOf('media') > 0 ? $('<input type="checkbox" tabindex="-1" checked="true" />') : '' );
  1574. const nameSpan = $('<span></span>').append(checkbox, rowName);
  1575. const cellLink = $('<a></a>').addClass('icon').attr('href',rowLink).append(nameSpan);
  1576. const cellName = $('<td></td>').addClass('name').attr('data-name',rowSortName).append(cellLink);
  1577. const cellSize = $('<td></td>').addClass('size details').attr('data-size',rowSortSize).append(rowSize);
  1578. const cellDate = $('<td></td>').addClass('date details').attr('data-date',rowSortDate).append(rowDate);
  1579. const cellKind = $('<td></td>').addClass('kind details').attr('data-kind',rowSortKind).append(rowKind);
  1580. const cellExt = $('<td></td>').addClass('ext details').attr('data-ext',rowExt);
  1581. // Assemble row
  1582. newRow.append(cellName, cellSize, cellDate, cellKind, cellExt);
  1583. newIndexItems.push(newRow[0]);
  1584. i++;
  1585. }
  1586. if ( sort === undefined ) { sort = getQuery('sort_by'); }
  1587. let sortedIndexItems = sortDirList($(newIndexItems), 'sort_by_'+ sort, 1); // initial sort
  1588. return sortedIndexItems;
  1589. }
  1590. // Index Prep: get row name
  1591. function getItemName(link) {
  1592. let name;
  1593. try { name = decodeURIComponentSafe(link); }
  1594. catch (error) { name = link.replace(/%20/g,' ').replace(/\s{2,}/,' '); }
  1595.  
  1596. if ( name.split('/').length > 2 ) { // get name only if x = full path
  1597. let arr = name.split('/');
  1598. if ( name.startsWith('/') && name.endsWith('/') ) { // dirs
  1599. name = arr[arr.length - 2] + '/';
  1600. } else {
  1601. name = arr[arr.length - 1]; // files
  1602. }
  1603. }
  1604. return name;
  1605. }
  1606. // Index Prep: get row classes
  1607. function getItemClasses(name,kind,ext) {
  1608. let itemClasses = [];
  1609. itemClasses.push(kind);
  1610. if ( ext.search(/dir|app/) === -1 ) {
  1611. itemClasses.push('file');
  1612. }
  1613. if ( ext === 'app' ) {
  1614. if ( $settings.apps_as_dirs === false ) {
  1615. itemClasses.push('file');
  1616. } else {
  1617. itemClasses.push('dir');
  1618. }
  1619. }
  1620. if ( name.endsWith('symlink') || name.endsWith('alias') || name.endsWith('symbolic link') ) {
  1621. itemClasses.push('alias');
  1622. }
  1623. if ( name.indexOf('.') === 0 ) {
  1624. itemClasses.push('invisible');
  1625. }
  1626. if ( !JSON.stringify($row_types).match( escapeStr(ext) ) ) { // else classify as "other" if extension is not in $row_types.
  1627. itemClasses.push('other'); //itemType = 'Other'; itemKind = 'other';
  1628. } else if ( kind === '' ) {
  1629. // itemClasses.push('code'); //itemType = 'Code'; itemKind = 'code';
  1630. } else {
  1631. itemClasses.push(ext);
  1632. }
  1633. if ( $row_settings.ignore.includes( ext ) ) {
  1634. itemClasses.push('ignore');
  1635. }
  1636. if ( $row_settings.exclude.includes( ext ) ) {
  1637. itemClasses.push('exclude');
  1638. }
  1639. if ( kind === 'audio' || kind === 'video' ) {
  1640. itemClasses.push('media');
  1641. }
  1642. itemClasses = Array.from(new Set(itemClasses)); // remove dupe classes
  1643. return itemClasses.join(' ');
  1644. }
  1645. // Index Prep: get formatted row size and date
  1646. function getItemSizeAndDate(cells) {
  1647. let sizesAndDates = [];
  1648. let rowDisplaySize, rowSortSize, rowDisplayDate, rowSortDate;
  1649. if ( cells.length > 1 ) {
  1650. if ( cells[1].search(/[-:\/]/) !== -1 ) { // test for typical date/time separators.
  1651. rowDisplayDate = cells[1];
  1652. rowDisplaySize = cells[2];
  1653. } else {
  1654. rowDisplayDate = cells[2];
  1655. rowDisplaySize = cells[1];
  1656. }
  1657. }
  1658. // size
  1659. let sizeUnits = /[BYTES|B|K|KB|MB|GB|TB|PB|EB|ZB|YB]/;
  1660. if ( rowDisplaySize === undefined || rowDisplaySize === '' || rowDisplaySize === '-' || rowDisplaySize === ',' ) {
  1661. rowDisplaySize = '&mdash;'; rowSortSize = '0'; // if no size supplied, use these defaults
  1662. } else {
  1663. rowSortSize = getItemSortSize(rowDisplaySize);
  1664. rowDisplaySize = ( rowDisplaySize.toUpperCase().endsWith('B') ? rowDisplaySize : rowDisplaySize + 'B');
  1665. if ( !rowDisplaySize.toUpperCase().match(sizeUnits) ) { // if provided size is only numeric
  1666. rowDisplaySize = formatBytes(rowDisplaySize,1);
  1667. } else {
  1668. rowDisplaySize = rowDisplaySize.replace('K','k').replace(/(\d+)\s*([A-z])/,'$1 $2');
  1669. }
  1670. }
  1671. // date
  1672. if ( rowDisplayDate === undefined || rowDisplayDate === '' || rowDisplayDate === '-' ) {
  1673. rowDisplayDate = '&mdash;'; rowSortDate = '0';
  1674. } else {
  1675. rowSortDate = getItemDate(rowDisplayDate);
  1676. }
  1677. sizesAndDates.push(rowDisplaySize,rowSortSize,rowDisplayDate,rowSortDate);
  1678. return sizesAndDates;
  1679. }
  1680. // Index Prep: get row size for sorting
  1681. function getItemSortSize(val) {
  1682. let sortSize;
  1683. let values = val.replace(/(\d+)\s*([A-z])/,'$1 $2').split(' ');
  1684. let size = values[0];
  1685. let unit = values[1];
  1686. if ( unit !== undefined ) { unit = unit.toUpperCase(); }
  1687. 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
  1688. sortSize = size * factor[unit]; // convert byte size to multiplication factor
  1689. return sortSize;
  1690. }
  1691. // convert numeric sizes to display format
  1692. function formatBytes(val, decimals) {
  1693. if (val === 0) return '0 Bytes';
  1694. const k = 1024;
  1695. const dm = decimals < 0 ? 0 : decimals;
  1696. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  1697. const i = Math.floor(Math.log(val) / Math.log(k));
  1698. return parseFloat((val / Math.pow(k, i)).toFixed(dm)) +' '+ sizes[i];
  1699. }
  1700. // process date
  1701. function processDate(match,p1,p2,p3) { //date formats: 2017-10-09 13:12 || 2015-07-25T02:02:57.000Z || 12-Mon-2017 21:11
  1702. const mo = 'JanFebMarAprMayJunJulAugSepOctNovDec'.indexOf(p2)/3 + 1; // e.g., convert month into number, or use number
  1703. return p3 +'-'+ mo +'-'+ p1;
  1704. }
  1705. // Index Prep: get row date 2015-07-25T02:22:00.000Z
  1706. function getItemDate(val) {
  1707. let sortDate = val.replace(/^(\d{2})-(\w{3})-(\d{4})/m, processDate) // convert Month to number
  1708. .replace(/\b(\d{1})[-:\/]/g,'0$1/') // add leading 0 for single digit numbers
  1709. .replace(/(\d{2})\/(\d{2})\/(\d{2}),/,'$3$1$2') // reorder MM/DD/YY dates
  1710. .replace(/-|:|\s+|\//g,''); // remove spacing characters
  1711. return sortDate;
  1712. }
  1713. // Index Prep: get row kind
  1714. function getItemKind(ext) {
  1715. let kind = '';
  1716. if ( ext === 'dir' || ext === 'app' ) {
  1717. kind = ext;
  1718. } else {
  1719. for ( let types in $row_types ) {
  1720. if ( $row_types[types].includes( ext ) ) {
  1721. kind = types;
  1722. return kind;
  1723. }
  1724. }
  1725. }
  1726. if ( kind === '' ) { kind = 'other'; }
  1727. return kind;
  1728. }
  1729. // Index Prep: get row extension
  1730. function getItemExt(link) {
  1731. let ext = '';
  1732. if ( link.endsWith('app/') || link.endsWith('exe') ) {
  1733. ext = 'app';
  1734. } else if ( link.endsWith('/') ) {
  1735. ext = 'dir';
  1736. } else if ( link.indexOf('.') < 0 ) { // if no '.' in link, ...
  1737. ext = link.slice(link.lastIndexOf('/') + 1).toLowerCase();
  1738. } else { // find the last . and get the remaining characters
  1739. ext = link.slice(link.lastIndexOf('.') + 1).toLowerCase();
  1740. }
  1741. return ext;
  1742. }
  1743. // END INDEX PREP
  1744. // ***** MAKE NEW INDEX ***** //
  1745. function makeNewIndex(el,sort) {
  1746. const indexItems = getIndexItems(el);
  1747. const items = indexItems[0];
  1748. const type = indexItems[1];
  1749. const convertedIndex = convertIndexItems( type, items ); // = array of rows: ["link","date","size"]
  1750. if ( type === 'error' ) {
  1751. return [convertedIndex];
  1752. } else {
  1753. let newIndex = buildNewIndex( convertedIndex, sort );
  1754. return [newIndex];
  1755. }
  1756. }
  1757. function appendNewIndex(body_top) { // setUpUI();
  1758. const newIndex = makeNewIndex(body_top);
  1759. $dir_list_body.empty().append( newIndex);
  1760. $dir_list.find('#stats').html(getIndexStats($dir_list.find('#tbody tr')));
  1761. }
  1762. // get and set index stats
  1763. function getIndexStats(el) {
  1764. const total = el.length;
  1765. const dirs = el.filter('.dir').length;
  1766. const files = el.filter('.file').length;
  1767. const stats = total +' items: '+ dirs +' directories, '+ files +' files';
  1768. return stats;
  1769. }
  1770. // ***** END DIR_LIST SETUP ***** //
  1771.  
  1772. // ***** UI SETUP ***** //
  1773. // Build UI: Append all assembled elements to $body
  1774. function buildUI() {
  1775. if ( window.self === window.top ) { // if it's an iframe...
  1776. $('head').prepend('<meta charset="utf-8">');
  1777. $('head #title').removeAttr('id'); // not sure where this id is being added, but it must be removed...
  1778. $('body').attr('id','top').attr('lang','en').find('script').remove();
  1779. addStyles( $('head') );
  1780. appendNewIndex($('body'));
  1781. $('body').empty().append($main_content);
  1782. } else {
  1783. $('body').attr('id','iframe_body');
  1784. }
  1785. }
  1786. buildUI();
  1787.  
  1788. // Define additional UI Element refs
  1789. const $body = $('body#top');
  1790. const $iframe_body = $('body#iframe_body');
  1791. const $iFrame_head = $iframe_body.prev('head');
  1792. const $dir_list_row = $dir_list_body.find('> tr');
  1793. const $audio_files = $dir_list_body.find('.audio');
  1794. const $font_files = $dir_list_body.find('.font');
  1795. const $image_files = $dir_list_body.find('.image');
  1796. const $media_files = $dir_list_body.find('.media');
  1797. const $video_files = $dir_list_body.find('.video');
  1798. function $selected_file() { return $dir_list_body.find('.selected'); }
  1799. function $playing_file() { return $dir_list_body.find('.playing'); }
  1800.  
  1801. // UI Setup: build UI and add body classes and other initial settings
  1802. function setupUIprefs() {
  1803. for ( let key in $settings ) {
  1804. if ( getQuery(key) === 'true' ) {
  1805. $body.addClass(key);
  1806. } else { // non-boolean settings and others
  1807. if ( key === 'theme' ) { $body.addClass( 'theme_'+ getQuery('theme') ); }
  1808. if ( key === 'sort_by' ) {
  1809. $body.addClass( 'sort_by_'+ getQuery(key) );
  1810. $('#sorting').find('th[id="sort_by_'+ getQuery(key) +'"]').addClass('up');
  1811. }
  1812. if ( key === 'default_text_view' ) {
  1813. if ( getQuery(key) === 'source_text' ) { $body.addClass('source_text'); } else { $body.addClass('preview_text'); }
  1814. }
  1815. if ( getQuery('toggle_sidebar') === 'true' ) { $body.addClass( 'has_hidden_sidebar' ); }
  1816. }
  1817. }
  1818. if ( navigator.vendor.indexOf('Google') > -1 ) { $body.addClass('is_chrome'); }
  1819. if ( navigator.userAgent.indexOf('Firefox') > -1 ) { $body.addClass('is_gecko'); }
  1820. if ( navigator.vendor.indexOf('Apple') === 0 ) { $body.addClass('is_safari'); }
  1821. if ( $audio_files.length > 0 ) { $body.add($dir_list).addClass('has_audio has_media'); }
  1822. if ( $font_files.length > 0 ) { $body.addClass('has_fonts'); }
  1823. if ( $image_files.length > 0 ) { $body.addClass('has_images'); }
  1824. if ( $video_files.length > 0 ) { $body.add($dir_list).addClass('has_video has_media'); }
  1825. // UI Setup: show invisibles
  1826. if ( navigator.platform.indexOf('Win') > -1 || $location.indexOf('file:') < 0 ) {
  1827. $('#show_invisibles').closest('label').hide();
  1828. } else if ( $body.hasClass('show_invisibles') ) {
  1829. $('#show_invisibles').attr('checked','checked');
  1830. }
  1831. }
  1832. // Get DOMTokenList of body classes
  1833. function getClassList(id) { return document.getElementById(id).classList; }
  1834. //
  1835. function setUpUI() {
  1836. if ( window.self === window.top) {
  1837. setupUIprefs();
  1838. initMedia();
  1839. autoSelectFile();
  1840. autoLoadCoverArt();
  1841. setContentTitle();
  1842. setContentHeight();
  1843. } else {
  1844. setUpIframeUI( getQuery('enable_text_editing') );
  1845. }
  1846. document.title = 'Index of: '+ $location;
  1847. }
  1848. setUpUI();
  1849.  
  1850. // SET UI TO DEFAULT SETTINGS: remove queries;
  1851. function defaultSettings() {
  1852. let $location = window.location.href;
  1853. $location = $location.slice(0,$location.lastIndexOf('?'));
  1854. window.location.assign($location);
  1855. }
  1856. $('#default_settings').on('click', function(e) {
  1857. e.preventDefault();
  1858. e.stopPropagation();
  1859. $('#bookmarks').hide();
  1860. 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.' ) ) {
  1861. defaultSettings();
  1862. }
  1863. });
  1864. // EXPORT SETTINGS
  1865. function saveSettings(filename, data) {
  1866. const blob = new Blob([data], {type: 'text/html'});
  1867. const elem = window.document.createElement('a');
  1868. elem.href = window.URL.createObjectURL(blob);
  1869. elem.download = filename;
  1870. document.body.appendChild(elem);
  1871. elem.click();
  1872. document.body.removeChild(elem);
  1873. URL.revokeObjectURL(blob);
  1874. }
  1875. $('#export_settings').on('click',function(e) {
  1876. e.preventDefault();
  1877. e.stopPropagation();
  1878. $('#bookmarks').hide();
  1879. const $settings_string = ( JSON.stringify($settings,null,'\t'));
  1880. saveSettings('settings.txt',$settings_string);
  1881. });
  1882.  
  1883. // Click Menu Link (with warning)
  1884. function setLocation(link) { window.location = link; }
  1885. $('#parent_dir_menu,#parents_dir_menu + .menu,#bookmarks .bookmark').on('click','a',function(e) {
  1886. e.preventDefault();
  1887. if ( $(this).attr('href').indexOf('file://') > -1 && $protocol !== 'file:' ) {
  1888. $body.addClass('has_warning').find('#warnings').addClass('local');
  1889. } else {
  1890. showWarning( 'setLocation', thisLink($(this)) );
  1891. }
  1892. });
  1893. // Show Menus
  1894. function showMenus(el) {
  1895. let $position = $(el).position();
  1896. $(el).find('> ul').css({'top':$position.top + $(el).innerHeight() + 'px'}).toggle().parent('td').siblings('td').find('.menu').hide();
  1897. }
  1898. $('#parents_dir_menu').add('#bookmarks_menu').parent('td').on('click',function(e) {
  1899. e.stopPropagation();
  1900. showMenus(this);
  1901. });
  1902. // Hide Menus
  1903. $(document).on('click', function() { $('.menu').hide(); });
  1904.  
  1905. // Toggle UI Preferences
  1906. function toggleUIpref(prefID) {
  1907. let prefClass = prefID;
  1908. if ( prefID === 'split_view' ) {
  1909. sendMessage('iframe','split_view');
  1910. }
  1911. if ( prefID.startsWith('sort_by') ) {
  1912. $body.removeClass('sort_by_default sort_by_name sort_by_size sort_by_date sort_by_kind sort_by_ext');
  1913. $('#bookmarks').hide(); // don't hide menus after click?
  1914. }
  1915. if ( prefID.startsWith('theme') ) {
  1916. prefID = ( $body.hasClass('theme_dark') ? 'theme_dark' : 'theme_light' );
  1917. prefClass = 'theme_dark theme_light';
  1918. }
  1919. if ( prefID.endsWith('text') ) {
  1920. prefClass = 'preview_text source_text';
  1921. sendMessage('iframe','default_text_view');
  1922. }
  1923. toggleQuery(prefID);
  1924. $body.toggleClass(prefClass);
  1925. setContentHeight();
  1926. scrollThis('tbody','selected',false); // true = instant scroll
  1927. if ( prefID === 'enable_text_editing' ) {
  1928. $('.selected.text, .selected.markdown').click();
  1929. }
  1930. }
  1931. // Click Toggle UI Pref elements
  1932. $('.toggle_UI_pref').on('click',function(e) {
  1933. if ( !$(this).is('input') ) {
  1934. e.preventDefault(); // allow checkboxes to be checked
  1935. }
  1936. toggleUIpref( $(this).attr('id') );
  1937. });
  1938.  
  1939. // Toggle Sidebar
  1940. function toggleSidebar() {
  1941. $body.toggleClass('has_hidden_sidebar');
  1942. if ( $body.hasClass('has_hidden_sidebar') ) { setQuery('toggle_sidebar','true'); } else { removeQuery('toggle_sidebar'); }
  1943. setContentHeight();
  1944. scrollThis('tbody','selected',true); // true = instant scroll
  1945. }
  1946. $('#toggle_sidebar').on('click', function() {
  1947. toggleSidebar();
  1948. });
  1949.  
  1950. // RESIZE Sidebar/Content Pane
  1951. function resizeSidebar(f) {
  1952. f.stopPropagation();
  1953. const $sidebar_wrapper = $('#sidebar_wrapper');
  1954. const $startX = f.pageX;
  1955. let $window_width = window.innerWidth;
  1956. let $sidebar_width = $sidebar_wrapper.width();
  1957. $('#overlay').css({'display':'block','z-index':'1'});
  1958. $('#handle').css({'z-index':'9999'});
  1959. $body.css({'-webkit-user-select':'none','-moz-user-select':'none','user-select':'none'});
  1960.  
  1961. $(document).on('mousemove',function(e) {
  1962. e.stopPropagation();
  1963. e.preventDefault();
  1964. const $deltaX = e.pageX - $startX;
  1965. if ( e.pageX > 230 && e.pageX < $window_width - 200 ) {
  1966. $sidebar_wrapper.css({'width':$sidebar_width + $deltaX + 'px'});
  1967. $content_pane.css({'width':($window_width - $sidebar_width) - $deltaX + 'px'});
  1968. }
  1969. setContentHeight();
  1970. scrollThis('tbody','selected',false); // true = instant scroll
  1971. });
  1972. $(document).on('mouseup',function() {
  1973. $('#overlay').css({'display':'none','z-index':'unset'});
  1974. $('#handle').css({'z-index':'unset'});
  1975. $body.css({'-webkit-user-select':'unset','-moz-user-select':'unset','user-select':'unset'});
  1976. $(document).off('mousemove');
  1977. $sidebar_width = $sidebar_wrapper.width();
  1978. setQuery('width',$sidebar_width);
  1979. });
  1980. }
  1981. $('#handle').on('mousedown', function(f) {
  1982. f.stopPropagation();
  1983. resizeSidebar(f);
  1984. });
  1985.  
  1986. // ***** BASIC UI FUNCTIONS ***** //
  1987. // Get dir_list item row
  1988. function thisRow(x) {
  1989. return $(x).closest('#dir_list > tbody > tr').length > 0 ? $(x).closest('#dir_list > tbody > tr') : $(x).closest('#dir_list > li');
  1990. }
  1991. function thisID(x) {
  1992. return thisRow(x).attr('id');
  1993. }
  1994. // Get row link
  1995. function thisLink(x) {
  1996. return $(x).find('a').length > 0 ? $(x).find('a').attr('href') : $(x).attr('href');
  1997. }
  1998. // Get row name
  1999. function thisText(x) {
  2000. return $(x).find('a span').length > 0 ? decodeURIComponentSafe( $(x).find('a span').text().toLocaleLowerCase() ) : decodeURIComponentSafe( $(x).text().toLocaleLowerCase() );
  2001. }
  2002. // get row text
  2003. function thisExt(x) {
  2004. let $this_name = thisText(x);
  2005. return $this_name.endsWith('app/') ? 'app' : $this_name.endsWith('/') ? '/' : $this_name.lastIndexOf('.') === -1 ? undefined : $this_name.toLocaleLowerCase().slice( $this_name.lastIndexOf('.') + 1 );
  2006. }
  2007. function getElById(id) {
  2008. return $(document.getElementById(id) );
  2009. }
  2010.  
  2011. // SET CONTENT HEIGHT
  2012. function setContentHeight() {
  2013. let $title = $('#title');
  2014. // accommodate multi-line title names in preview pane
  2015. if ( $title.outerWidth() > ( $('#content_title').innerWidth() - 2 * $('#title_buttons_left').outerWidth() ) ) {
  2016. $title.css({'margin-top':'2em'});
  2017. } else {
  2018. $title.css({'margin-top':'0'});
  2019. }
  2020. let $window_height = window.innerHeight;
  2021. let $content_header_height = $('#content_header').outerHeight();
  2022.  
  2023. $('#sidebar, #main_content, #content_pane').css({'height':$window_height });
  2024. $dir_list.css({'height':$window_height - $('#sidebar_header').outerHeight(), 'max-height':$window_height - $('#sidebar_header').outerHeight() });
  2025. $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() });
  2026. $('#iframe_body').find('#tbody').css({'top':$('#iframe_body').find('#thead').height() + 1 +'px'});
  2027. $content_font.css({'padding-bottom': $('#font_info th').outerHeight() +'px' });
  2028.  
  2029. $('#prev_track, #next_track, #close_audio').css({'height':$('#audio').height() }); // set height of audio controls
  2030. $('#content_container, #glyph_viewer').css({'top':$content_header_height +'px' });
  2031. $('#content_pane.has_image #content_image').css({'top':$('#content_header').height() });
  2032. setDimensions($('tr.image.selected'));
  2033. }
  2034. window.addEventListener('resize', setContentHeight );
  2035.  
  2036. // SET CONTENT TITLE
  2037. function setContentTitle(kind) {
  2038. let $title = $('#title span');
  2039. let $title_text = '';
  2040. if ( $playing_file().hasClass('audio') ) { // set audio player title
  2041. $('#content_audio_title').find('td').empty().text( $playing_file().find('td.name a').text() );
  2042. }
  2043. if ( $content_pane.hasClass('has_grid') ) { // set main title for other content
  2044. $title_text = $('#parents_dir_menu').find('> div').html().split('<wbr>').reverse()[1];
  2045. } else if ( $('#toggle_info').hasClass('selected') ) {
  2046. $title_text = 'Source of: '+ $current_dir_path;
  2047. } else if ( $body.hasClass('has_text') ) {
  2048. $title_text = 'Text Editor';
  2049. } else if ( $selected_file().hasClass('audio') ) {
  2050. return;
  2051. } else if ( !$selected_file().hasClass('audio') || $content_pane.hasClass('has_hidden_text') ) {
  2052. $title_text = $selected_file().not('.audio').find('td.name a span').text(); // Assemble title
  2053. }
  2054. $title.removeClass().empty().html($title_text);
  2055. if ( kind !== undefined && !['audio','dir','font','image','pdf','video'].includes(kind) ) {
  2056. $title.addClass('has_'+ kind);
  2057. }
  2058. if ( $title.outerWidth() > ( $('#content_title').innerWidth() - 2 * $('#title_buttons_left').outerWidth() ) ) { $title.css({'margin-top':'2em'}); } else { $title.css({'margin-top':'0'}); }
  2059. }
  2060. // Get Image Dimensions
  2061. function getDimensions(link, callback) {
  2062. if ( link !== undefined ) {
  2063. let img = new Image();
  2064. img.src = link;
  2065. img.onload = function() { callback( this.width, this.height ); };
  2066. }
  2067. }
  2068. function setDimensions(row) {
  2069. if ( $content_pane.hasClass('has_image') || $content_pane.hasClass('has_zoom_image') ) {
  2070. getDimensions( thisLink(row), function( width, height ) {
  2071. $('#title').attr('data-after',' (' + width + 'px × ' + height + 'px) ('+ ( ($content_image.find('img').width()/width)*100 ).toFixed(1) +'%)');
  2072. });
  2073. } else {
  2074. $('#title').removeAttr('data-after'); // remove image dimensions
  2075. }
  2076. }
  2077. // Scroll Selected Items
  2078. function scrollThis(elID,className,bool) {
  2079. let $behavior = 'smooth';
  2080. if ( bool !== undefined ) { $behavior = 'instant'; }
  2081. let $block = ( $body.hasClass('is_gecko') ? 'start' : 'nearest' );
  2082. if ( document.getElementsByClassName(className).length !== undefined && document.getElementsByClassName(className).length > 0 ) {
  2083. document.getElementById(elID).getElementsByClassName(className)[0].scrollIntoView({ behavior:$behavior, block:$block, inline:'nearest' });
  2084. }
  2085. setContentHeight();
  2086. }
  2087.  
  2088. // ***** SORTING ***** //
  2089. function sortIndex(els,id,sortDirection) { // id = sort type
  2090. let sorted = [];
  2091. const newSort = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }); // needs to be above makeNewIndex()
  2092. sorted = els.removeClass('sorted').sort((a, b) => {
  2093. let aName, bName;
  2094. if ( $('body').hasClass('has_playlist') ) {
  2095. aName = $(a).attr('id');
  2096. bName = $(b).attr('id');
  2097. } else {
  2098. aName = $(a).find('td.name').data('name');
  2099. bName = $(b).find('td.name').data('name');
  2100. }
  2101. let aData = $(a).find('td[data-'+ id +']').data(id);
  2102. let bData = $(b).find('td[data-'+ id +']').data(id);
  2103. if ( sortDirection === 1 ) { // sort by detail data value, then by name (i.e., if data values are the same, sort by name)
  2104. if ( newSort.compare(aData, bData) === 0 ) {
  2105. return newSort.compare(aName, bName);
  2106. } else {
  2107. return newSort.compare(aData, bData);
  2108. }
  2109. } else { // reverse sort
  2110. if ( newSort.compare(bData, aData) === 0 ) {
  2111. return newSort.compare(bName, aName);
  2112. } else {
  2113. return newSort.compare(bData, aData);
  2114. }
  2115. }
  2116. });
  2117. sorted = sorted.sort((a, b) => { // add sorted style (rules between different rows)
  2118. if ( id === 'kind' || id === 'ext' && sortDirection === 1 ) {
  2119. if ( $(a).find('td[data-'+ id +']').data(id) !== $(b).find('td[data-'+ id +']').data(id) ) { $(a).addClass('sorted'); }
  2120. }
  2121. if ( id === 'kind' || id === 'ext' && sortDirection === -1 ) {
  2122. if ( $(b).find('td[data-'+ id +']').data(id) !== $(a).find('td[data-'+ id +']').data(id) ) { $(a).addClass('sorted'); }
  2123. }
  2124.  
  2125. });
  2126. return sorted;
  2127. }
  2128. // Sort the Dir List on click
  2129. function sortDirList(rows, id, sortDirection) {
  2130. const $sort_all = rows;
  2131. const $sort_dirs = $sort_all.filter('.dir:not(.app)');
  2132. const $sort_files = $sort_all.filter('.file,.app');
  2133. const $sort_id = id.slice(8);// === 'default' ? 'name' : id;
  2134. let $sorted = [];
  2135.  
  2136. if ( $sort_id === 'default' || ( $sort_id !== 'name' && $settings.dirs_on_top === true )) {
  2137. const $sorted_dirs = sortIndex($sort_dirs, $sort_id, sortDirection);
  2138. const $sorted_files = sortIndex( $sort_files, $sort_id, sortDirection );
  2139. if (sortDirection === 1) {
  2140. $sorted = $.merge($sorted_dirs,$sorted_files);
  2141. } else {
  2142. $sorted = $.merge($sorted_files,$sorted_dirs);
  2143. }
  2144. } else {
  2145. $sorted = sortIndex( $sort_all, $sort_id, sortDirection );
  2146. }
  2147. return $sorted;
  2148. }
  2149. // Sort on click
  2150. function clickSort(id) {
  2151. const el = $(getElById(id)); // id from th sort item = 'sort_by_xxx'
  2152. let sortDirection = ( el.hasClass('up') ? -1 : 1 ); // Only reverse sort order after clicking a sort column once.
  2153. // SORT EM!
  2154. let rows = ( $body.hasClass('has_playlist') ? $('#tbody').find('tr') : $dir_list_row );
  2155. const $sorted_index = sortDirList( rows, id, sortDirection );
  2156. $dir_list_body.empty().append($sorted_index);
  2157. $('div[id="'+ id +'"]').toggleClass('up').siblings().removeClass('up');
  2158. if ( $content_grid.hasClass('has_font_grid') ) { $('#show_font_grid').click(); }
  2159. if ( $content_grid.hasClass('has_image_grid') ) { $('#show_image_grid').click(); }
  2160. if ( $content_grid.hasClass('has_grid') ) { $('#grid_btn').click(); }
  2161. setContentHeight();
  2162. scrollThis('tbody','selected',false); // true = instant scroll
  2163. }
  2164. // Sort on clicking dir_list sort item
  2165. $('#sorting').on('click','div.sorting:not(.disabled)',function(e) {
  2166. e.preventDefault();
  2167. e.stopPropagation();
  2168. clickSort( $(this).attr('id') );
  2169. });
  2170. // Sort Menu: click the list header that contains the selected menu text.
  2171. $('#sort_menu').on('click','li:not(.disabled)',function(e) {
  2172. e.preventDefault();
  2173. e.stopPropagation();
  2174. $('#sorting div[id="sort_by_'+ $(this).attr('id') +'"]').click(); // click corresponding sidebar sort item
  2175. });
  2176. // ***** END SORTING ***** //
  2177. // ***** END BASIC UI FUNCTIONS ***** //
  2178.  
  2179. // ***** CONTENT PANE ***** //
  2180. // SELECT ROW on click and set classes for $content_pane
  2181. function selectThis(rowID) {
  2182. $('#toggle_info').removeClass('selected');
  2183. let row = $(getElById(rowID));
  2184. const $grid_selected = $content_grid.find('> div[data-id="'+ rowID +'"]');
  2185. if ( $content_pane.hasClass('has_grid') || $content_pane.hasClass('has_hidden_grid') ) { // Select corresponding grid item
  2186. row.addClass('selected').siblings().removeClass('selected hovered');
  2187. $grid_selected.addClass('selected').siblings().removeClass('selected');
  2188. } else { // remove classes from rows, but leave .audio with playing
  2189. if ( row.attr('id') === 'toggle_info' ) {
  2190. row.toggleClass('selected loaded');
  2191. $dir_list.find('#tbody .selected').removeClass('selected');
  2192. } else {
  2193. row.addClass('selected').siblings().removeClass('selected hovered');
  2194. }
  2195. }
  2196. }
  2197.  
  2198. //***** SHOW CONTENT *****//
  2199. function showAudio(rowID) {
  2200. let row = getElById(rowID);
  2201. if ( $content_video.hasClass('has_content') ) { $('#title span').empty(); }
  2202. closeMedia('video');
  2203. if ( row.hasClass('audio') ) { row.addClass('playing selected').siblings('.media').removeClass('playing selected'); }
  2204. $audio_player.attr('src', thisLink( row ) );
  2205. $content_pane.addClass('has_audio');
  2206. $('#content_audio_title').find('td').empty().text( $playing_file().find('td.name a').text() );
  2207. setContentHeight();
  2208. }
  2209.  
  2210. // showTextEditor();
  2211.  
  2212. // Show Grid
  2213. function showGrid() {
  2214. $content_pane.removeClass('has_hidden_grid').addClass('has_grid');
  2215. if ( $body.hasClass('has_text') ) { $body.toggleClass('has_text has_hidden_text'); }
  2216. closeMedia('video');
  2217. setContentTitle();
  2218. setContentHeight();
  2219. selectThis( $selected_file().attr('id') );
  2220. }
  2221. // Show Hidden Editor or Grid
  2222. function showHiddenEditorOrGrid() {
  2223. if ( $content_pane.hasClass('has_hidden_grid') && !$body.hasClass('has_hidden_text') || $content_pane.hasClass('has_hidden_grid') && $body.hasClass('has_hidden_text') ) {
  2224. $content_pane.toggleClass('has_grid has_hidden_grid'); // show grid preferentially
  2225. } else if ( !$content_pane.hasClass('has_hidden_grid') && $body.hasClass('has_hidden_text') ) {
  2226. $body.toggleClass('has_text has_hidden_text');
  2227. }
  2228. }
  2229. // Hide Editor or Grid
  2230. function hideEditorOrGrid() {
  2231. if ( $body.hasClass('has_text') ) { $body.toggleClass('has_text has_hidden_text'); }
  2232. if ( $content_pane.hasClass('has_grid') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  2233. }
  2234. // showIndexSource();
  2235.  
  2236. // Show Font (and create font items)
  2237. function showFont(row,bool,sheet) { // bool = true if for show font grid, sheet defined at fontGridItems()
  2238. $content_font.addClass('has_font').removeClass('has_font_viewer');
  2239. let fontStyles = $font_styles.sheet;
  2240. const $font_family = thisText(row);
  2241. const $font_url = thisLink(row);
  2242. const $font_grid_item_el = $('<div class="font_grid_item" data-id="'+ $(row).attr('id') +'"></div>');
  2243. if ( bool === false ) {
  2244. if ( fontStyles.cssRules.length > 0 ) { fontStyles.deleteRule(0); } // delete previous @font-face rule
  2245. fontStyles.insertRule('@font-face { font-family: "'+ $font_family +'"; src: url("'+ $font_url +'"); }');
  2246. $content_font.css({ 'font-family':'"'+ $font_family +'"' }); // set content font style
  2247. } else {
  2248. let grid_item = $font_grid_item_el.clone();
  2249. const $display_name = $font_family;
  2250. sheet.insertRule('@font-face { font-family: "'+ $font_family +'"; src: url("'+ $font_url +'"); }');
  2251. 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>' );
  2252. return grid_item;
  2253. }
  2254. }
  2255.  
  2256. // OPEN FONT
  2257. /// opentype.js font parsing
  2258. $('#open_font_label').on('click',function(e) { $('.menu').hide(); });
  2259. // Open font
  2260. $('#bookmarks').on('change','#open_font',function(e) {
  2261. openFont(e);
  2262. });
  2263. function openFont(evt) {
  2264. if (window.File && window.FileReader && window.FileList && window.Blob && window.opentype ) {
  2265. let files = evt.target.files[0];
  2266. let reader = new FileReader();
  2267. reader.readAsArrayBuffer(files);
  2268. reader.onload = function(file) {
  2269. closeOtherContent();
  2270. closeGrid();
  2271. hideEditorOrGrid();
  2272. $content_pane.addClass('has_font');
  2273. $content_font.addClass('has_content has_font_viewer').removeClass('has_font');
  2274. parseFont(reader.result);
  2275. return true;
  2276. };
  2277. $('#open_font').val(''); // reset input to allow same font to be reopened immediately after closing.
  2278. } else {
  2279. alert('File APIs are not fully supported in this browser or opentype.js is not available.');
  2280. }
  2281. }
  2282. // Parse font
  2283. function parseFont(fontblob) {
  2284. let font = window.opentype.parse(fontblob);
  2285. getFontInfo(font);
  2286. let $glyphs_container = $('#glyphs_container');
  2287. $glyphs_container.empty();
  2288. let $glyph_container = $('<div class="glyph_container"></div>');
  2289. let $glyph_canvas = $('<canvas class="glyph" width="120" height="120"></canvas>');
  2290. let $glyph_info = $('<div class="glyph_info" style="font-size:0.75rem"></div>');
  2291. let $glyph_viewer = $('#glyph_viewer');
  2292. $glyph_viewer.data('data-font-name',font.names.fullName.en);
  2293. let glyphs = font.glyphs;
  2294. $content_font.data('data-glyphs',glyphs); // add glyphs data to $content_font
  2295. // Draw glyphs
  2296. for ( let i = 0; i < glyphs.length; i++ ) {
  2297. let glyph = glyphs.glyphs[i];
  2298. // GLyph width
  2299. let boundingBox = glyph.getBoundingBox();
  2300. let glyphWidth = boundingBox.x2 - boundingBox.x1;
  2301. let contextX = (60 - glyphWidth/24);
  2302. // Add glyph info and append elements
  2303. let glyphUnicode = ( glyph.unicode !== undefined ? '#'+ glyph.unicode : glyph.unicode );
  2304. let glyphContainer = $glyph_container.clone();
  2305. let glyphCanvas = $glyph_canvas.clone();
  2306. let glyphInfo = $glyph_info.clone();
  2307. glyphInfo.text(glyph.index +': '+ glyph.name +', '+ glyphUnicode);
  2308. glyphContainer.append( glyphCanvas.clone().attr('id','glyph_'+ glyph.index ) ).append(glyphInfo);
  2309. $glyphs_container.append( glyphContainer );
  2310. // Draw glyph
  2311. let thisGlyph = document.getElementById('glyph_'+ glyph.index);
  2312. $(thisGlyph).data('contextX',contextX);
  2313. let context = thisGlyph.getContext('2d');
  2314. glyph.draw(context, contextX, 84, 72);
  2315. }
  2316. $('#title').removeAttr('data-after').find('span').empty().html(font.names.fullName.en);
  2317. setContentHeight();
  2318. }
  2319. // Get font info
  2320. function getFontInfo(font) {
  2321. let $font_names = font.names;
  2322. 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>');
  2323. for (let name in $font_names) {
  2324. let value = $font_names[name].en;
  2325. if ( name.endsWith('URL') ) {
  2326. let href = value;
  2327. if ( !value.startsWith('http') ) {
  2328. href = 'http://'+ value;
  2329. }
  2330. value = '<a href="'+ href +'" target="_blank">'+ value +'</a>';
  2331. }
  2332. $font_info.find('tbody').append('<tr><td>'+ name +': </td><td>'+ value +'</td></tr>');
  2333. }
  2334. let numGlyphs = font.numGlyphs; // glyph count
  2335. $font_info.find('tbody').append('<tr><td>numGlyphs: </td><td>'+ numGlyphs +'</td></tr>');
  2336. $content_font.find('#font_viewer').prepend($font_info);
  2337. }
  2338. // Show glyph viewer
  2339. $content_font.on('click','.glyph',function(e) {
  2340. e.stopPropagation();
  2341. let id = $(this).attr('id');
  2342. $(this).parent('div').addClass('selected').siblings().removeClass('selected');
  2343. showGlyph( id );
  2344. });
  2345. function showGlyph(id) {
  2346. let $glyph_viewer = $('#glyph_viewer');
  2347. let glyphX = $('#'+ id).data('contextX');
  2348. id = id.slice(id.lastIndexOf('_') + 1);
  2349. let glyphs = $content_font.data('data-glyphs'); // get glyphs
  2350. let glyph = glyphs.get(id);
  2351. let glyphName = glyph.name;
  2352. let glyphPath = glyph.getPath(glyphX,84,72);
  2353. let glyphSVG = glyphPath.toSVG().replace(/"/g,'\'');
  2354. // set the background SVG image:
  2355. 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>';
  2356. $glyph_viewer.show().css({'background-image': SVGprefix + glyphSVG +'</g></svg>")'});
  2357. $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
  2358. $content_font.addClass('has_glyph');
  2359. setContentHeight();
  2360. }
  2361. // Save glyph svg
  2362. $content_font.on('click','#save_svg',function(e) {
  2363. e.stopPropagation();
  2364. saveGlyph();
  2365. });
  2366. function saveGlyph() {
  2367. let filename = $('#glyph_viewer').data('data-font-name') +'—'+ $('#glyph_viewer').data('data-glyph-name') +'.svg';
  2368. 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>';
  2369. let data_suffix = '</g></svg>';
  2370. let data = data_prefix + $('#glyph_viewer').data('data-raw-svg') + data_suffix;
  2371. let blob = new Blob([data], {type: 'image/svg+xml'});
  2372. let downloadEl = window.document.createElement('a');
  2373. downloadEl.href = window.URL.createObjectURL(blob);
  2374. downloadEl.download = filename;
  2375. document.body.appendChild(downloadEl);
  2376. downloadEl.click();
  2377. document.body.removeChild(downloadEl);
  2378. URL.revokeObjectURL(blob);
  2379. }
  2380.  
  2381. // Set Content Pane classes
  2382. function setContentClasses(content_el) {
  2383. if ( content_el === 'audio' ) {
  2384. $content_pane.addClass('has_audio');
  2385. } else {
  2386. hideEditorOrGrid();
  2387. $content_pane.addClass( 'has_'+ content_el ); // remove classes, excluding grid and text classes; add content class
  2388. }
  2389. }
  2390. // Set Content Element Sources and row classes
  2391. function setContentSources(row,link,kind,content_el) {
  2392. switch(kind) {
  2393. case 'audio':
  2394. $audio_player.attr('src',link);
  2395. break;
  2396. case 'font':
  2397. showFont(row,false);
  2398. break;
  2399. case 'code':
  2400. case 'markdown':
  2401. case 'text':
  2402. link = thisLink(row) +'?split_view='+ getQuery('split_view') +'&default_text_view='+ getQuery('default_text_view');
  2403. if ( !$body.hasClass('enable_text_editing') ) { link += '&enable_text_editing=false'; } else { link += '&enable_text_editing=true'; }
  2404. break;
  2405. case 'dir':
  2406. $content_pane.toggleClass('has_iframe has_dir')
  2407. link = link + '?sort_by=' + getQuery('sort_by') +'&show_numbers='+ getQuery('show_numbers') +'&use_custom_icons='+ getQuery('use_custom_icons');
  2408. break;
  2409. case 'info':
  2410. link = $location + '?sort_by=' + getQuery('sort_by') +'&show_numbers='+ getQuery('show_numbers') +'&view_source=true';
  2411. break;
  2412. case 'pdf':
  2413. link = link + '?#view=fitB&scrollbar=1&toolbar=1&navpanes=1';
  2414. break;
  2415. }
  2416. if ( kind === 'video' ) { row.addClass('playing'); } else { row.addClass('loaded'); }
  2417. // fix for pdfs not being loaded after setting src attribute (hide and then show)
  2418. if ( kind === 'pdf' ) {
  2419. $content_pdf.hide().addClass('has_content').attr('src','').attr('src',link).show().removeAttr('srcdoc');
  2420. } else if ( kind === 'image' ) {
  2421. $('#content_'+ content_el).addClass('has_content').find('img').attr('src',link);
  2422. } else {
  2423. $('#content_'+ content_el).addClass('has_content').attr('src',link).removeAttr('srcdoc');
  2424. }
  2425. }
  2426. // Show Content
  2427. function showContent(id) { // show any content excluding grids on row click
  2428. let row = getElById(id);
  2429. if ( row.length === -1 ) { return; } // needed for left/right arrow nav when there are no valid items (i.e. images or fonts)
  2430. let kind = row.attr('data-kind');
  2431. let link = thisLink(row);
  2432. 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
  2433. if ( row.hasClass('audio') ) {
  2434. showAudio( id );
  2435. } else {
  2436. closeOtherContent(row);
  2437. setContentClasses(content_el);
  2438. setContentSources(row,link,kind,content_el);
  2439. setContentTitle(kind);
  2440. setContentHeight();
  2441. row.siblings().removeClass('loaded');
  2442. }
  2443. }
  2444.  
  2445. //***** CLOSE CONTENT (Close button or Cmd/Ctrl + W) *****//
  2446. // Close Audio/Video
  2447. function closeMedia(type) { // type === audio || video
  2448. let $mediaEl = ( type === 'audio' ? $audio_player : $content_video );
  2449. $mediaEl.trigger('pause').attr('src','');
  2450. $content_pane.removeClass('has_'+ type);
  2451. $('.media.playing, .media.loaded').removeClass('playing loaded');
  2452. if ( type === 'audio' ) {
  2453. $('#content_audio_title td').empty();
  2454. }
  2455. if ( type === 'video' ) {
  2456. $('#content_video').removeClass('has_content');
  2457. }
  2458. setContentHeight();
  2459. }
  2460. // Close Audio button click
  2461. $('#close_audio').on('click',function(e) {
  2462. e.stopPropagation();
  2463. closeMedia('audio');
  2464. $('.audio.selected').removeClass('selected');
  2465. if ( $('.loaded').length === 1 ) { $('.loaded').addClass('selected'); }
  2466. });
  2467. // Close Playlist
  2468. function closePlaylist() {
  2469. $body.removeClass('has_playlist');
  2470. $('head').find('title').text('Index of: '+ $location); // change window title back to default
  2471. $('#parents_dir_menu').find('> div').empty().html($current_dir_path);
  2472. clickSort(getQuery('sort_by'));
  2473. $dir_list.find('#stats').html(getIndexStats($dir_list.find('#tbody tr')));
  2474. if ( $('#tbody').find('.audio').length < 1 ) { $body.removeClass('has_audio'); }
  2475. }
  2476. // Close Text Editor
  2477. function closeTextEditor() {
  2478. if ( $body.hasClass('edited') ) {
  2479. showWarning('closeContent');
  2480. } else {
  2481. $body.removeClass('has_text');
  2482. if ( $content_pane.hasClass('has_hidden_grid') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  2483. }
  2484. }
  2485. // Close Grid
  2486. function closeGrid() {
  2487. $content_pane.removeClass('has_grid');
  2488. $content_grid.empty().removeClass().attr('style','').find('.image_grid_item, img').attr('style','');
  2489. if ( $body.hasClass('has_hidden_text') ) { $body.toggleClass('has_text has_hidden_text'); }
  2490. }
  2491. // Close index source preview
  2492. function closeIndexSource() {
  2493. $('#toggle_info').removeClass('selected loaded');
  2494. $content_pane.removeClass('has_iframe').find('#content_iframe').removeClass('has_content').removeAttr('src');
  2495. if ( $('.loaded:not(.audio)').length === 1 || $('.playing').length > 0 ) {
  2496. $('.loaded:not(.audio)').click();
  2497. $('.playing').addClass('selected');
  2498. }
  2499. if ( $content_pane.hasClass('has_hidden_grid') ) { showGrid(); }
  2500. setContentTitle();
  2501. }
  2502. // Close .content elements (not #content_audio, #content_text, or #content_grid) when opening new content
  2503. function closeOtherContent(row) {
  2504. if ( $content_pane.hasClass('has_pdf') ) { $('head').find('title').text('Index of: '+ $location); } // change window title back to default
  2505. // close audio/video when opening video/audio
  2506. if ( row !== undefined ) {
  2507. if ( row.hasClass('video') ) {
  2508. closeMedia('audio');
  2509. } else if ( row.hasClass('audio') ) {
  2510. closeMedia('video');
  2511. }
  2512. if ( ( $content_pane.hasClass('has_grid') || $content_pane.hasClass('has_hidden_grid') ) && !row.hasClass('image') && !row.hasClass('font') && !row.hasClass('audio') ) {
  2513. closeGrid();
  2514. $('#grid_btn').removeClass('has_grid');
  2515. }
  2516. }
  2517. // close other content
  2518. if ( $('.content.has_content').length || $content_pane.hasClass('has_ignored') ) {
  2519. let $contentID = $('.content.has_content').attr('id');
  2520. switch($contentID) { // specific cases
  2521. case 'content_font':
  2522. $content_font.attr('style','').find('#font_viewer').remove().end().append(ContentFontViewer());
  2523. break;
  2524. case 'content_image':
  2525. $content_image.removeAttr('style').find('img').removeAttr('style'); // reset image: comment out to retain image scale after loading other content
  2526. break;
  2527. case 'content_video':
  2528. closeMedia('video');
  2529. break;
  2530. }
  2531. // remove content classes and source attribute
  2532. $content_pane.removeClass('has_font has_image has_zoom_image has_pdf has_video has_iframe has_dir has_ignored')
  2533. .find('.content').removeClass('has_content has_font has_font_viewer').removeAttr('src')
  2534. .find('img').removeAttr('src');
  2535. showHiddenEditorOrGrid();
  2536. }
  2537. }
  2538. // Close Button: close any visible content
  2539. function closeContent() {
  2540. window.stop();
  2541. if ( $('#toggle_info').hasClass('selected') ) {
  2542. closeIndexSource();
  2543. } else if ( $body.hasClass('has_text') ) {
  2544. closeTextEditor();
  2545. } else if ( ( $content_pane.hasClass('has_hidden_grid has_image') || $content_pane.hasClass('has_hidden_grid has_zoom_image') ) && $content_grid.hasClass('has_image_grid') ) {
  2546. $('.loaded').removeClass('loaded');
  2547. $content_pane.toggleClass('has_hidden_grid has_grid').removeClass('has_image has_zoom_image').find('#content_image').removeClass('has_content').find('img').removeAttr('src');
  2548. scrollThis('content_grid','selected');
  2549. } else if ( $content_pane.hasClass('has_grid') ) { // close grid (i.e., don't just hide)
  2550. closeGrid();
  2551. $('#grid_btn').removeClass('has_grid');
  2552. } else if ($content_font.hasClass('has_glyph') ) {
  2553. $('#glyph_viewer').hide().attr('style','');
  2554. $content_font.addClass('has_content').removeClass('has_glyph');
  2555. scrollThis('glyphs_container','selected');
  2556. } 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') ) {
  2557. $('tr.selected:not(.audio)').removeClass('selected');
  2558. $('.loaded').removeClass('loaded');
  2559. $('#title').removeAttr('data-after').find('span').empty();
  2560. closeOtherContent();
  2561. } else if ( $body.hasClass('iframe_edited') ) { // warn if iframe edited
  2562. showWarning('closeContent');
  2563. } else if ( $content_pane.hasClass('has_audio') ) { // close audio last of all
  2564. closeMedia('audio');
  2565. $('.selected.audio').removeClass('selected');
  2566. } else if ( $body.hasClass('has_playlist') ) {
  2567. closePlaylist();
  2568. }
  2569. if ( $('#font_info').length !== 1 ) { setContentTitle(); }
  2570. setContentHeight();
  2571. }
  2572. $('#close_btn').on('click', function(e) {
  2573. e.preventDefault();
  2574. closeContent(); // close content unless body.edited or body.iframe_edited
  2575. });
  2576.  
  2577. //***** RESET CONTENT (Reset button or Cmd/Ctrl + R) *****//
  2578. function resetContent() {
  2579. if ( $content_pane.attr('class') === '' ) { window.location = window.location.href; } // reload page
  2580. if ( $content_pane.hasClass('has_audio') ) { $audio_player.prop('currentTime', 0).trigger('pause'); }
  2581. if ( $content_pane.hasClass('has_grid') ) { $('#grid_btn').click(); }
  2582. if ( $content_pane.hasClass('has_font') ) { $content_font.css({'font-size':'1em'}); }
  2583. 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'); }
  2584. if ( $content_pane.hasClass('has_video') ) { $content_video.prop('currentTime',0).trigger('pause'); }
  2585. if ( $content_pane.hasClass('has_iframe') || $content_pane.hasClass('has_dir') ) { $selected_file().find('a').click(); }
  2586. setContentHeight();
  2587. }
  2588. $('#reload_btn').on('click', function(e) {
  2589. e.preventDefault();
  2590. showWarning('resetContent');
  2591. });
  2592.  
  2593. //**********************//
  2594. //***** NAVIGATION *****//
  2595. function firstRowID(className) {
  2596. return ( $('#tbody').find(':visible:not(.unchecked)').filter(className).length ? $('#tbody').find('tr:visible:not(.unchecked)').filter(className).first().attr('id') : null );
  2597. }
  2598. function prevRowID(className) {
  2599. let row;
  2600. if ( ['.audio','.video','.media'].includes(className) ) { row = $playing_file(); } else { row = $selected_file(); }
  2601. 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');
  2602. }
  2603. function nextRowID(className) { // if nothing selected, or if no next row with classname, return first row with classname, else return next row with classname
  2604. let row;
  2605. if ( ['.audio','.video','.media'].includes(className) ) { row = $playing_file(); } else { row = $selected_file(); }
  2606. 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');
  2607. }
  2608. // function lastRowID(className) {
  2609. // return ( $('#tbody').find(':visible:not(.unchecked)').filter(className).length ? $('#tbody').find('tr:visible:not(.unchecked)').filter(className).last().attr('id') : null );
  2610. // }
  2611. function selectRowID(className,key) {
  2612. let id = '';
  2613. if ( key === 'ArrowUp' ) { id = prevRowID('.dir,.file'); }
  2614. if ( key === 'ArrowLeft' ) { id = prevRowID(className); }
  2615. if ( key === 'ArrowRight' ) { id = nextRowID(className); }
  2616. if ( key === 'ArrowDown' ) { id = nextRowID('.dir,.file'); }
  2617. return id;
  2618. }
  2619. // NAVIGATION: select GRID items by left/right arrow keys @ arrowNavigation();
  2620. function gridNavigation(key) {
  2621. let id; // = grid item data-id = corresponding dir_list item id.
  2622. let rowLength = 0; // $content_grid.hasClass('has_grid') || $('#content_font').hasClass('has_font_grid')
  2623. if ( $('#content_grid').hasClass('has_image_grid') ) { rowLength = (Math.round( $('#content_grid').innerWidth() / $('.image_grid_item').outerWidth()) - 1 ) ;}
  2624. switch(key) {
  2625. case 'ArrowDown':
  2626. 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'); }
  2627. break;
  2628. case 'ArrowUp':
  2629. 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'); }
  2630. break;
  2631. case 'ArrowLeft':
  2632. if ( $('#content_grid .selected').prev().length === 1 ) { id = $('#content_grid .selected').prev().attr('data-id'); } else { id = $('#content_grid > div').last().attr('data-id'); }
  2633. break;
  2634. case 'ArrowRight':
  2635. if ( $('#content_grid .selected').next().length === 1 ) { id = $('#content_grid .selected').next().attr('data-id'); } else { id = $('#content_grid > div').first().attr('data-id'); }
  2636. break;
  2637. }
  2638. if ( $content_pane.hasClass('has_hidden_grid') ) {
  2639. $('#content_grid > div[data-id="'+ id +'"]').click();
  2640. } else {
  2641. selectThis(id);
  2642. }
  2643. }
  2644. // NAVIGATION: FONTS and IMAGES by prev/next buttons
  2645. $content_pane.on( 'click','#prev_btn, #next_btn', function(e) {
  2646. e.stopPropagation();
  2647. e.preventDefault();
  2648. let key = $(this).attr('id') === 'prev_btn' ? 'ArrowLeft' : 'ArrowRight';
  2649. if ( $('#content_font').hasClass('has_font_viewer') ) {
  2650. glyphNavigation(key);
  2651. } else {
  2652. clickRow( selectRowID('.font,.image',key));
  2653. }
  2654. });
  2655. // glyph navigation
  2656. function glyphNavigation(key) {
  2657. let rowLength = Math.round( $('#glyphs_container').innerWidth() / $('.glyph_container').outerWidth() - 1 );
  2658. if ( $('#glyphs_container > .glyph_container.selected').length === 0 ) {
  2659. if ( key === 'ArrowRight' || key === 'ArrowDown' ) { $('.glyph_container').first().addClass('selected').siblings().removeClass('selected'); }
  2660. if ( key === 'ArrowLeft' || key === 'ArrowUp' ) { $('.glyph_container').last().addClass('selected').siblings().removeClass('selected'); }
  2661. } else if ( $('#glyphs_container > .glyph_container.selected').length === 1 ) {
  2662. if ( key === 'ArrowRight' ) { $('.glyph_container.selected').nextAll('.glyph_container').first().addClass('selected').siblings().removeClass('selected'); }
  2663. if ( key === 'ArrowLeft' ) { $('.glyph_container.selected').prevAll('.glyph_container').first().addClass('selected').siblings().removeClass('selected'); }
  2664. if ( key === 'ArrowDown' ) { if ( $('.glyph_container.selected').nextAll('.glyph_container').eq(rowLength).length === 1 ) { $('.glyph_container.selected').nextAll('.glyph_container').eq(rowLength).addClass('selected').siblings().removeClass('selected'); } else { $('.glyph_container').last().addClass('selected').siblings().removeClass('selected'); } }
  2665. if ( key === 'ArrowUp' ) { if ( $('.glyph_container.selected').prevAll('.glyph_container').eq(rowLength).length === 1 ) { $('.glyph_container.selected').prevAll('.glyph_container').eq(rowLength).addClass('selected').siblings().removeClass('selected'); } else { $('.glyph_container').first().addClass('selected').siblings().removeClass('selected'); } }
  2666. }
  2667. if ( $('#content_font').hasClass('has_glyph') ) { $('.glyph_container.selected .glyph').click(); } // show the selected glyph
  2668. }
  2669. // 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
  2670. function playPrevNextTrack(key) {
  2671. if ( $('.playing').length === 0 ) { // Arrow L/R selects first/last audio file if nothing selected
  2672. clickRow( selectRowID('.media',key) );
  2673. playMedia('play');
  2674. } else if ( $('.playing').length === 1 ) {
  2675. let mediaClass = ( $('.playing').hasClass('audio') ? '.audio' : '.video' );
  2676. // If shuffle play...
  2677. if ( $body.hasClass('shuffle_audio') ) {
  2678. let trackRowID = $audio_player.data('shufflelist').pop();
  2679. if ( trackRowID !== undefined ) { // if shuffle list is not empty...
  2680. showAudio( trackRowID ); // load audio...
  2681. playMedia('play'); // and play
  2682. } else if ( trackRowID === undefined ) { // if end of shufflelist...
  2683. if ( $body.hasClass('loop_audio') ) { // and if loop audio, update the shufflelist and play
  2684. updateShuffleList();
  2685. playMedia('play');
  2686. } else { // else load the first track
  2687. showAudio( firstRowID( mediaClass ));
  2688. }
  2689. }
  2690. // else if there is another media file selected, play it next
  2691. } else if ( $(mediaClass).filter('.selected').length === 1 && !$('.media.selected').hasClass('playing') ) {
  2692. showAudio( $('.media.selected').attr('id') );
  2693. playMedia('play');
  2694. } else {
  2695. if ( $body.hasClass('loop_audio') || nextRowID( mediaClass ) !== firstRowID( mediaClass ) ) {
  2696. showAudio( selectRowID( mediaClass,key ) );
  2697. playMedia('play');
  2698. } else {
  2699. showAudio( selectRowID( mediaClass,key ) );
  2700. }
  2701. }
  2702. }
  2703. }
  2704. // NAVIGATION: Audio by prev/next audio buttons
  2705. $('.prev_next_track_btn').on('click',function() {
  2706. let key = ( $(this).attr('id') === 'prev_track' ? 'ArrowLeft' : 'ArrowRight' );
  2707. playPrevNextTrack(key);
  2708. });
  2709. // NAVIGATION: Prev/Next Audio or Prev/Next File of same data-kind by arrow left/right
  2710. function leftRightArrowNavigation(className,key) {
  2711. if ( $('.selected').hasClass('audio') && $('.playing').length === 1 ) {
  2712. playPrevNextTrack(key);
  2713. } else if ( $('#toggle_info').hasClass('selected') ) { // if previewing directory source
  2714. if ( $('#tbody .loaded').length > 0 ) { clickRow( $('#tbody .loaded').attr('id') ); } else { clickRow( selectRowID('.dir,.file',key) ); }
  2715. } else {
  2716. if ( $('.selected').length === 0 ) { // else select first/last row
  2717. clickRow( selectRowID('.dir,.file',key) );
  2718. } else { // else select prev/next row of same data-kind
  2719. clickRow( selectRowID('.'+ $('.loaded,.video.playing').attr('data-kind'),key) );
  2720. }
  2721. if (className === 'video') { playMedia('play'); }
  2722. }
  2723. }
  2724. function upDownArrowNavigation(key) {
  2725. let row = $(document.getElementById(selectRowID('.dir,.file',key)));
  2726. if ( row.hasClass('audio') && $('.audio.playing').length === 1 ) { // just select audio file if another audio is playing
  2727. selectThis( row.attr('id') );
  2728. } else if ( $('#toggle_info').hasClass('selected') ) {
  2729. if ( $('#tbody .loaded').length > 0 ) {
  2730. clickRow( $('#tbody .loaded').attr('id') );
  2731. } else {
  2732. clickRow( selectRowID('.dir,.file:visible',key) );
  2733. }
  2734. } else {
  2735. clickRow( selectRowID('.dir,.file',key) );
  2736. }
  2737. }
  2738. // NAVIGATE directory index items by arrow up/down or left/right keys, with/without grid @ indexNavigation()
  2739. function arrowNavigation(className,key) {
  2740. if ( $content_pane.hasClass('has_grid') || $content_pane.hasClass('has_hidden_grid') ) { // Grid navigation: L/R arrow selects images and fonts only
  2741. gridNavigation(key);
  2742. if ( !$content_pane.hasClass('has_hidden_grid') ) { scrollThis('content_grid','selected'); }
  2743. } else if ( $('#content_font').hasClass('has_font_viewer') ) { // if previewing font glyphs
  2744. glyphNavigation(key);
  2745. scrollThis('content_container','selected');
  2746. } else if ( key === 'ArrowUp' || key === 'ArrowDown' ) {
  2747. upDownArrowNavigation(key);
  2748. scrollThis('tbody','selected');
  2749. } else { // key === 'ArrowLeft" || key === 'ArrowRight'
  2750. leftRightArrowNavigation(className,key);
  2751. scrollThis('tbody','selected');
  2752. }
  2753. }
  2754. // NAVIGATION: Main navigation by arrow keys
  2755. function indexNavigation(key) {
  2756. let className = ( $('.selected[data-kind]') === undefined ? $dir_list.find('tbody tr:visible').first().attr('data-kind') : $('.selected[data-kind]').attr('data-kind') );
  2757. arrowNavigation(className,key);
  2758. }
  2759.  
  2760. // NAVIGATE items by typed string
  2761. var str = '';
  2762. function timeoutID() {
  2763. return window.setTimeout( function() { str = ''; }, 1500 );
  2764. }
  2765. function alphaNav(e) { // Select Dir_List row by typed string; Todo: select next row by nearest letter
  2766. let timer = timeoutID();
  2767. if ( typeof timer === 'number' ) {
  2768. window.clearTimeout( timer );
  2769. timer = 0; // id
  2770. }
  2771. timeoutID();
  2772. str += e.key;
  2773. str = str.toLowerCase();
  2774. if ( $('#dir_list').find('td.name[data-name^="'+ str +'"]').length ) {
  2775. $('#dir_list').find('td.name[data-name^="'+ str +'"]').first().find('a').click();
  2776. scrollThis('tbody','selected');
  2777. // } else {
  2778. // null; // replace this with some sort of fuzzy match function? TBD
  2779. }
  2780. }
  2781. //***** END NAVIGATION *****//
  2782.  
  2783. //***** CLICK TO SELECT/SHOW CONTENT *****//
  2784.  
  2785. // CLICK element by id
  2786. function clickThis(id) {
  2787. let el = $(document.getElementById(id));
  2788. if ( el.find('a').length > 0 ) { el.find('a').click(); } else { el.click(); }
  2789. }
  2790. // CLICK Row
  2791. function clickRow(id) {
  2792. selectThis(id);
  2793. showContent(id);
  2794. }
  2795. $body.find('#tbody').on('click','tr', function(e) {
  2796. e.preventDefault();
  2797. e.stopPropagation();
  2798. if ( $(this).hasClass('playing') ) {
  2799. playPauseMedia();
  2800. } else {
  2801. showWarning( 'clickRow', $(this).attr('id') );
  2802. }
  2803. });
  2804. // Show current dir source in $content_iframe
  2805. $('#toggle_info').on('click',function(e) {
  2806. e.stopPropagation();
  2807. if ( $(this).hasClass('selected') ) {
  2808. $('#close_btn').click();
  2809. } else {
  2810. showWarning( 'clickRow', $(this).attr('id') );
  2811. }
  2812. });
  2813.  
  2814. // DOUBLE-CLICK Row to open directory
  2815. function doubleClickRow(id) { // row.dir only
  2816. let row = getElById(id);
  2817. let $query_str = decodeURIComponentSafe(window.location.search);
  2818. if ( $query_str === '' ) { $query_str = '?'; }
  2819. const $current_index = row.prevAll('.dir:visible').length;
  2820. if ( $query_str.indexOf('history') !== -1 ) {
  2821. $query_str = $query_str.replace(/&selected=\d+/,'').replace(/&history=/,'&history='+ $current_index +'+');
  2822. } else {
  2823. $query_str = $query_str.replace(/&selected=\d+/,'') + '&history='+ $current_index;
  2824. }
  2825. window.location = row.find('a').attr('href') + $query_str;
  2826. }
  2827. $('#tbody').find('tr.dir').on('dblclick', function(e) {
  2828. e.preventDefault();
  2829. e.stopPropagation();
  2830. showWarning( 'doubleClickRow', $(this).attr('id') );
  2831. });
  2832. // CLICK grid item
  2833. $content_grid.on('click','div', function(e) {
  2834. e.preventDefault();
  2835. let id = $(this).attr('data-id');
  2836. $(this).addClass('selected').siblings().removeClass('selected');
  2837. getElById(id).click();
  2838. });
  2839.  
  2840. // HOVER Grid Item
  2841. $content_grid.on('mouseenter','> div:not(.selected)',function() {
  2842. thisRow($dir_list.find('a[href*="'+ thisLink(this) +'"]')).addClass('hovered');
  2843. }).on('mouseleave','> div:not(.selected)',function() {
  2844. thisRow($dir_list.find('a[href*="'+ thisLink(this) +'"]')).removeClass('hovered');
  2845. });
  2846. // HOVER Dir_list_row and highlight corresponding grid item
  2847. $dir_list_row.hover(function() {
  2848. if ( $content_grid.is(':visible') ) {
  2849. $content_grid.find('[href*="'+ thisLink(this) +'"]').closest('div').addClass('hovered');
  2850. }
  2851. }, function() {
  2852. if ( $content_grid.is(':visible') ) {
  2853. $content_grid.find('.hovered').removeClass('hovered');
  2854. }
  2855. });
  2856.  
  2857. //***** AUTOLOAD CONTENT: index files or files from the file shortcut list *****//
  2858. function autoSelectFile() {
  2859. let $query_prefs = getQueryPrefs();
  2860. let $UI_pref_selected = ( $query_prefs.get('selected') === null ? '' : $query_prefs.get('selected') );
  2861. if ( getQuery('file') !== undefined && getQuery('file').length > 0 && window.top == window.self ) { // load individual files
  2862. clickRow( $dir_list.find('a[href*="'+ getQuery('file') +'"]').closest('tr').attr('id') );
  2863. removeQuery('file');
  2864. } else if ( $UI_pref_selected !== '' ) {
  2865. clickRow( $dir_list.find('tr.dir:visible').eq($UI_pref_selected).attr('id') );
  2866. } else if ( $body.hasClass('autoload_index_files') && $dir_list.find( 'a[href*="/index."]').length > 0 ) { // else load index file
  2867. clickRow( $dir_list.find('a[href*="/index."]').closest('tr').attr('id') );
  2868. } else if ( !$body.hasClass('has_media') ) { // else select first non-media item
  2869. // clickRow( $dir_list.find('#tbody tr:visible:not(.media):not(.invisible):not(.ignored)').first(0).attr('id') );
  2870. }
  2871. if ( $body.hasClass('autoload_media') && $body.hasClass('has_media') ) { // else if audio and images, load cover art
  2872. clickRow( firstRowID('.audio,.video') );
  2873. if ( $playing_file() ) { scrollThis('tbody','playing'); }
  2874. }
  2875. if ( $selected_file() ) { scrollThis('tbody','selected'); }
  2876. }
  2877.  
  2878. // Autoload Cover Art
  2879. function getImageNames() {
  2880. let image_names = [];
  2881. $image_files.each(function() {
  2882. let name = $(this).find('td.name').attr('data-name');
  2883. name = name.slice(0,name.lastIndexOf('.'));
  2884. image_names.push( name );
  2885. });
  2886. return image_names;
  2887. }
  2888. function getCoverArtID() {
  2889. const cover_names = ['cover','front'];
  2890. const image_names = getImageNames();
  2891. for ( let cover_name of cover_names ) {
  2892. if ( image_names.includes(cover_name) ) { // file name = a cover name
  2893. return $image_files.eq( image_names.indexOf(cover_name) ).attr('id');
  2894. } else if ( image_names.some( name => name.startsWith(cover_name)) ) { // file name starts with a cover name
  2895. return $image_files.find('td.name[data-name^="'+ cover_name +'"]').closest('tr').attr('id');
  2896. } else if ( image_names.some( name => name.indexOf(cover_name) > 0 ) ) { // file name includes a cover name
  2897. return $image_files.find('td.name[data-name*="'+ cover_name +'"]').closest('tr').attr('id');
  2898. } else { // else use first image
  2899. return $image_files.first().attr('id');
  2900. }
  2901. }
  2902. }
  2903. function autoLoadCoverArt() { // autoload cover art for audio if dir contains audio and images, and audio is loaded and non-image content is not loaded
  2904. let bodyClasses = getClassList('top');
  2905. if ( bodyClasses.contains( 'has_audio','has_images','autoload_media' ) && !getElById( firstRowID('.media') ).hasClass('video') ) {
  2906. let $coverID = getCoverArtID();
  2907. if ( $coverID !== undefined ) {
  2908. let row = getElById($coverID);
  2909. showContent($coverID);
  2910. row.addClass('loaded');
  2911. $('#title span').html(row.find('.name').attr('data-name'));
  2912. setDimensions($('.loaded.image'));
  2913. }
  2914. }
  2915. }
  2916.  
  2917. //***** KEYBOARD EVENTS *****//
  2918. $body.on('keydown',$dir_list,function(e) {
  2919. const $selected = ( $('#content_font').hasClass('has_font_viewer') ? $('.glyph_container.selected .glyph') : $selected_file() );
  2920.  
  2921. if ( $('#content_source').is(':focus') || $('#content_font div').is(':focus') && e.key !== 'Escape' ) {
  2922. return;
  2923. }
  2924. // Disable all keydown events except return and tab when warning is shown
  2925. if ( $('body').hasClass('has_warning') ) {
  2926. if (e.key !== 'Enter' && e.key !== 'Tab' && e.key !== 'Shift' ) {
  2927. e.preventDefault();
  2928. return false;
  2929. }
  2930. if ( e.key === 'Enter' ) {
  2931. e.preventDefault();
  2932. e.stopPropagation();
  2933. $('#warnings').find('button.focus').click();
  2934. }
  2935. if ( e.key === 'Tab' ) {
  2936. e.preventDefault();
  2937. e.stopPropagation();
  2938. if ( $('#warnings').find('button.focus').length === 0 || $('#warnings').find('button.focus').prev('button').length === 0 ) {
  2939. $('#warnings').find('button').last('button').focus().addClass('focus').siblings().removeClass('focus').blur();
  2940. } else {
  2941. $('#warnings').find('button.focus').prev('button').focus().addClass('focus').siblings().removeClass('focus').blur();
  2942. }
  2943. }
  2944. }
  2945.  
  2946. $(':focus').blur(); // Need this to able to select grid items after clicking close button (or other buttons).
  2947.  
  2948. switch ( e.key ) {
  2949. case 'ArrowUp':
  2950. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) { // Cmd/Ctrl + up arrow = go to parent directory
  2951. if ( $('#parents_dir_menu + ul a').length < 1 ) {
  2952. return;
  2953. } else {
  2954. showWarning( 'clickThis', $('#parent_dir_menu').attr('id') );
  2955. }
  2956. break;
  2957. }
  2958. if ( $('*[contentEditable="true"]').is(':focus') ) { // Allow arrow navigation within content_editable elements
  2959. return;
  2960. }
  2961. e.preventDefault();
  2962. showWarning( 'indexNavigation', 'ArrowUp' );
  2963. break;
  2964. case 'ArrowDown':
  2965. 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
  2966. return;
  2967. } else if ( $('*[contentEditable="true"]' ).is(':focus') ) {
  2968. return;
  2969. } else if ( (e.ctrl || e.metaKey) && $selected.hasClass('dir') ) {
  2970. $selected.find('a').trigger('dblclick');
  2971. break;
  2972. }
  2973. e.preventDefault();
  2974. showWarning( 'indexNavigation', 'ArrowDown' );
  2975. break;
  2976. case 'ArrowLeft':
  2977. if ( (e.ctrl || e.metaKey) || (e.ctrl && e.metaKey) ) {
  2978. return;
  2979. } else if ( $('*[contentEditable="true"]').is(':focus') ) { // Ignore Cmd/Ctrl + arrow or if focused element is content editable
  2980. return;
  2981. }
  2982. if ( (e.altKey && e.shiftKey) || e.altKey && !e.metaKey && !e.ctrlKey ) { // Skip audio 30s/10s: Opt-Shift-Arrow/Opt-Arrow
  2983. mediaSkip(e);
  2984. return;
  2985. } else {
  2986. showWarning( 'indexNavigation','ArrowLeft' );
  2987. }
  2988. break;
  2989. case 'ArrowRight':
  2990. if ( e.metaKey && !e.altKey && !e.shiftKey && $selected.hasClass('dir') ) { // Open dir with Cmd/Ctrl + Right Arrow
  2991. $selected.find('a').trigger('dblclick');
  2992. return;
  2993. }
  2994. if ( (e.ctrl || e.metaKey) || (e.ctrl && e.metaKey) ) { // Ignore Cmd/Ctrl + arrow or if focused element is content editable
  2995. return;
  2996. } else if ( $('*[contentEditable="true"]').is(':focus') || $selected.hasClass('dir ignore') ) {
  2997. return;
  2998. }
  2999. if ( (e.altKey && e.shiftKey) || e.altKey && !e.metaKey && !e.ctrlKey ) { // Skip audio 30s/10s: Opt-Shift-Arrow/Opt-Arrow
  3000. mediaSkip(e);
  3001. return;
  3002. } else {
  3003. showWarning( 'indexNavigation','ArrowRight' );
  3004. }
  3005. break;
  3006. case ' ': // space
  3007. if ( $content_pane.hasClass('has_audio') || $content_pane.hasClass('has_video') ) { // Play/pause media (space bar)
  3008. e.preventDefault();
  3009. playPauseMedia();
  3010. } else {
  3011. alphaNav(e);
  3012. }
  3013. break;
  3014. case 'Enter': // Open directories (or ignore)
  3015. if ( $selected.hasClass('app') && $settings.apps_as_dirs === false ) {
  3016. break;
  3017. } else {
  3018. if ( $selected.hasClass('dir') ) {
  3019. $selected.find('a').trigger('dblclick');
  3020. } else if ( $selected.hasClass('playing') || $selected.hasClass('video') ) { // content_audio or content_video
  3021. playPauseMedia();
  3022. } else {
  3023. $selected.click();
  3024. }
  3025. }
  3026. break;
  3027. // Alphabetical navigation
  3028. 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':
  3029. 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':
  3030. 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 'π':
  3031. 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 '≠':
  3032. case '⁄': case '€': case '‹': case '›': case 'fl': case '‡': case '°': case '·': case '‚': case '±': case '¯': case '˘': case '¿':
  3033. case 'ı': case '': case '´': case '˝': case 'ˆ': case '': case '˜': case '‰': case 'ˇ': case '¨': case '◊': case '„': case '˛': case '¸':
  3034. // 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 'ϖ':
  3035. // 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 'ϒ':
  3036. if ( !e.metaKey && !e.ctrlKey && !e.altKey ) {
  3037. alphaNav(e);
  3038. }
  3039. break;
  3040. case 'd': // Cmd/Ctrl + D: Toggle Details
  3041. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3042. e.preventDefault();
  3043. $('#show_details').click();
  3044. } else {
  3045. alphaNav(e);
  3046. }
  3047. break;
  3048. case 'e': // Cmd/Ctrl + E: Show Text Editor
  3049. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3050. e.preventDefault();
  3051. $('#text_editor_row').find('a').click();
  3052. } else {
  3053. alphaNav(e);
  3054. }
  3055. break;
  3056. case 'g': // Cmd/Ctrl + G: Show image Grid
  3057. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3058. e.preventDefault();
  3059. $('#grid_btn').click();
  3060. } else {
  3061. alphaNav(e);
  3062. }
  3063. break;
  3064. case 'i': // Cmd/Ctrl + I: Toggle Invisibles
  3065. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3066. e.preventDefault();
  3067. $('#show_invisibles').find('input').click();
  3068. } else {
  3069. alphaNav(e);
  3070. }
  3071. break;
  3072. case 'o': // Cmd/Ctrl + Shift + O: Open selected item in new window
  3073. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && e.shiftKey && !e.altKey ) {
  3074. window.open( thisLink($selected_file()) );
  3075. } else {
  3076. alphaNav(e);
  3077. }
  3078. break;
  3079. case 'r': // Cmd/Ctrl + Shift + R: Refresh
  3080. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3081. e.preventDefault();
  3082. $('#reload_btn').click();
  3083. } else {
  3084. alphaNav(e);
  3085. }
  3086. break;
  3087. case 'w': // Close content pane if Close button visible with Cmd/Crtl + W
  3088. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3089. if ( $content_pane.attr('class').indexOf('has_') > -1 || $('#toggle_info').hasClass('selected') || $body.hasClass('has_playlist') ) {
  3090. e.preventDefault();
  3091. $('#close_btn').click();
  3092. }
  3093. } else {
  3094. alphaNav(e);
  3095. }
  3096. break;
  3097. case '\\':
  3098. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3099. e.preventDefault();
  3100. $('#toggle_split_view').click();
  3101. } else {
  3102. alphaNav(e);
  3103. }
  3104. break;
  3105. case '=':
  3106. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3107. e.preventDefault();
  3108. $('#increase').click();
  3109. } else {
  3110. alphaNav(e);
  3111. }
  3112. break;
  3113. case '-':
  3114. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3115. e.preventDefault();
  3116. $('#decrease').click();
  3117. } else {
  3118. alphaNav(e);
  3119. }
  3120. break;
  3121. case 'tab':
  3122. break;
  3123. case 'Escape':
  3124. $('*:focus').blur();
  3125. break;
  3126. } // end switch
  3127. });
  3128. // ***** END KEYBOARD EVENTS ***** //
  3129.  
  3130. // ***** GRID SETUP ***** //
  3131. // Create Font Grid Items
  3132. function fontGridItems() {
  3133. let $font_grid_items_arr = [];
  3134. let $font_files = $dir_list_body.find('.font');
  3135. let fontGridStyles = $font_grid_styles.sheet;
  3136. for ( let i = 0; i < $font_files.length; i++ ) {
  3137. let newGridItem = showFont($font_files[i],true,fontGridStyles);
  3138. $font_grid_items_arr.push( newGridItem );
  3139. }
  3140. return $font_grid_items_arr;
  3141. }
  3142. // Create Image Grid Items
  3143. function imageGridItems() {
  3144. let $image_grid_items_arr = [];
  3145. let $image_files = $dir_list_body.find('.image:not(.ignore)');
  3146. for ( let i = 0; i < $image_files.length; i++ ) {
  3147. const id = $image_files.eq(i).attr('id');
  3148. const $this_link = thisLink($image_files[i]);
  3149. const exts = $row_types.image.filter( ext => $.inArray(ext, $row_settings.ignore) == -1 ); // decide which image files can be displayed
  3150. const $title_name = $this_link.slice($this_link.lastIndexOf('/') + 1);
  3151. if ( $.inArray( thisExt($image_files[i]), exts ) > -1 ) { // if this row file ext is in the image extension array
  3152. 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>';
  3153. $image_grid_items_arr.push( item );
  3154. }
  3155. }
  3156. return $image_grid_items_arr;
  3157. }
  3158. // Make Grids
  3159. function makeGrids(id) {
  3160. closeGrid();
  3161. let $title = $('#title');
  3162. $content_pane.removeClass('has_hidden_grid').addClass('has_grid');
  3163. if ( id === 'show_font_grid' || !$body.hasClass('has_images') ) { // only show font grid
  3164. $title.removeClass().addClass('font_grid');
  3165. $content_grid.addClass('has_font_grid');
  3166. $content_grid.append( fontGridItems() );
  3167. } else if ( id === 'show_image_grid' || !$body.hasClass('has_fonts') ) { // only show image grid
  3168. $title.removeClass().addClass('image_grid');
  3169. $content_grid.addClass('has_image_grid');
  3170. $content_grid.append( imageGridItems() );
  3171. } else { // show grid of both images and fonts
  3172. $title.removeClass();
  3173. if ( $body.hasClass() ) { $content_grid.addClass('has_image_grid'); } else { $content_grid.addClass('has_grid'); }
  3174. $content_grid.append( imageGridItems(), fontGridItems() );
  3175. }
  3176. }
  3177. // Click grid button
  3178. $('#sidebar_header').on('click', '#grid_btn, #show_font_grid, #show_image_grid', function(e) {
  3179. e.stopPropagation();
  3180. // if ( $content_pane.hasClass('has_grid') && $(this).attr('id') === 'grid_btn' ) {
  3181. // closeGrid();
  3182. // } else {
  3183. $('#grid_btn').addClass('has_grid');
  3184. makeGrids($(this).attr('id'));
  3185. showGrid();
  3186. // }
  3187. });
  3188.  
  3189. // ***** SCALE PREVIEWED IMAGES & FONTS ***** //
  3190. // Scale Fonts
  3191. function scaleFonts(e, incr, id) {
  3192. const $em = parseInt(getComputedStyle(document.body).fontSize); // pts/em
  3193. const getFontSize = function(el) { return parseFloat(el.css('font-size')); };
  3194. if ( id === 'decrease' ) { incr = 1/incr; }
  3195. if ( $content_pane.hasClass('has_grid') && ( $content_grid.hasClass('has_font_grid') || $content_grid.hasClass('has_grid') ) ) {
  3196. $content_grid.css({'font-size':( getFontSize($content_grid)/$em * incr ) +'em'});
  3197. return;
  3198. }
  3199. if ( $content_pane.hasClass('has_font') ) {
  3200. $content_font.css({'font-size':( getFontSize($content_font)/$em * incr ) +'em'});
  3201. return;
  3202. }
  3203. scrollThis('content_container','content_font')
  3204. }
  3205. function scaleGridImages(incr,id) {
  3206. if ( id === 'decrease' ) { incr = 1/incr; }
  3207. const $imageGridItem = $('.image_grid_item img');
  3208. let $image_grid_item_width = Number.parseFloat( $imageGridItem.width(),10) * incr;
  3209. let $image_grid_item_height = Number.parseFloat( $imageGridItem.height(),10) * incr;
  3210. let $image_grid_item_maxwidth = Number.parseFloat( $imageGridItem.css('maxWidth'),10) * incr;
  3211. let $image_grid_item_maxheight = Number.parseFloat( $imageGridItem.css('maxHeight'),10) * incr;
  3212. // prevent reducing grid image size on first scale click:
  3213. if ( $image_grid_item_width < $image_grid_item_maxwidth ) { $image_grid_item_width = $image_grid_item_maxwidth; }
  3214. if ( $image_grid_item_height < $image_grid_item_maxheight ) { $image_grid_item_height = $image_grid_item_maxheight; }
  3215. // set grid properties
  3216. $content_grid.css({'grid-template-columns':'repeat(auto-fill, minmax('+ ($image_grid_item_width +16) +'px, auto ) )'});
  3217. $content_grid.find('img').css({'max-width':( $image_grid_item_width ) +'px', 'max-height':( $image_grid_item_height ) +'px'});
  3218. return;
  3219. }
  3220. // Zoom Images on click
  3221. function scaleImages(e,incr,id) {
  3222. const $this_image = $content_image.find('img');
  3223. const $this_link = $this_image.attr('src');
  3224. const $content_container = $('#content_container');
  3225. let CC_width = function() { return Math.round($content_container.width()) };
  3226. let CC_height = function() { return Math.round($content_container.height()) };
  3227. const $this_width = Math.round($this_image.width());
  3228. const $this_height = Math.round($this_image.height());
  3229. // scale grid images
  3230. if ( $content_pane.hasClass('has_grid') && ( $content_grid.hasClass('has_image_grid') || $content_grid.hasClass('has_grid') ) ) {
  3231. scaleGridImages(incr,id);
  3232. } else { // scale single images
  3233. getDimensions( $this_link, function( width, height ) {
  3234. const $this_outer_width = Math.round($this_image.outerWidth(true));
  3235. // scale images by increment
  3236. if ( incr !== undefined && id !== undefined ) {
  3237. $content_pane.addClass('has_zoom_image').removeClass('has_image'); // remove zoom classes in case window resized after zoom
  3238. if ( id === 'increase' ) {// && $this_width < width && $this_height < height) {
  3239. $content_image.add($this_image).css({'width':$this_width * incr, 'height': 'auto', 'max-width':'none', 'max-height':'none' });
  3240. }
  3241. if ( id === 'decrease' && ( $this_width > 24 && $this_height > 24 ) ) {
  3242. $content_image.add($this_image).css({'width':$this_width / incr, 'height': 'auto', 'max-width':'none', 'max-height':'none' });
  3243. }
  3244. // keep images centered when scaling
  3245. if ( Math.round($this_image.width()) >= CC_width() ) {
  3246. $content_container.scrollLeft( ( Math.round( ( $this_image.outerWidth(true) ) - CC_width() ) )/2 ) ;
  3247. }
  3248. if ( Math.round($this_image.height()) <= CC_height() ) {
  3249. $content_image.css({ 'top':( CC_height() - Math.round( $this_image.height() ) )/2 });
  3250. } else {
  3251. $content_image.css({ 'top':0 });
  3252. $content_container.scrollTop( ( Math.round($this_image.outerHeight(true)) - CC_height())/2 ) ;
  3253. }
  3254. // else zoom single image on click
  3255. } else {
  3256. $content_image.removeAttr('style').find('img').removeAttr('style');
  3257. setContentHeight(); // needed to ensure current element positions/dimensions are set (for some reason; w/o, img_offset, etc. are inaccurate)
  3258. // but don't zoom small images:
  3259. if ( width <= CC_width() && height <= CC_height() ) {
  3260. $content_pane.removeClass('has_zoom_image').addClass('has_image');
  3261. $content_image.css({'top':$('#content_header').height()}).find('img').css({'cursor':'pointer'});
  3262. return;
  3263. }
  3264.  
  3265. const $CC_offset = $content_container.offset();
  3266. const $img_offset = $this_image.offset();
  3267. // x,y coordinates of zoom click as percentage of image width/height
  3268. const percentX = (e.pageX - $img_offset.left)/$this_width;
  3269. const percentY = (e.pageY - $img_offset.top)/$this_height;
  3270. // calculate scroll by pixel coordinates of full-size image - click coordinates and content_container offsets
  3271. const scrollX = (width * percentX) - e.pageX + $CC_offset.left;
  3272. const scrollY = (height * percentY) - e.pageY + $CC_offset.top;
  3273. $content_pane.toggleClass('has_image has_zoom_image');
  3274. if ( width > CC_width() && height < CC_height() || $this_width < CC_width() ) {
  3275. $content_container.scrollLeft( scrollX );
  3276. $content_image.css({ 'top':( CC_height() - Math.round( $this_image.height() ) )/2 });
  3277. }
  3278. if ( width < CC_width() && height > CC_height() ) {
  3279. $content_image.css({ 'top': 0 });
  3280. $content_container.scrollTop( scrollY );
  3281. }
  3282. if ( width > CC_width() && height > CC_height() ) {
  3283. $content_image.css({ 'top': 0 });
  3284. $content_container.scrollLeft( scrollX ) ;
  3285. $content_container.scrollTop( scrollY );
  3286. }
  3287. if ( $content_pane.hasClass('has_image') ) {
  3288. $content_image.css({'top':$('#content_header').height() });
  3289. }
  3290. }
  3291. setDimensions($('.selected.image,.loaded.image'));
  3292. });
  3293. }
  3294. }
  3295.  
  3296. // Soom single image on click
  3297. $content_image.on('click','img', function(e) {
  3298. scaleImages(e);
  3299. });
  3300. // Scale Fonts and Images
  3301. function scalePreviewItems(e,id) { // combine scaling into one function
  3302. scaleImages(e, 1.125, id );
  3303. scaleFonts(e, 1.125, id );
  3304. }
  3305. // Scale Button
  3306. $('#scale').on('click','span',function(e) {
  3307. e.preventDefault();
  3308. e.stopPropagation();
  3309. let id = $(this).attr('id');
  3310. scalePreviewItems(e,id);
  3311. });
  3312. // ***** END SCALE PREVIEW ITEMS ***** //
  3313.  
  3314.  
  3315. // ***** AUDIO CONTENT ***** //
  3316. // Update Playlist
  3317. function updatePlaylist() {
  3318. let playlist = [];
  3319. $audio_files.not('.unchecked').each(function() {
  3320. playlist.push( thisID( $(this) ) );
  3321. });
  3322. return playlist;
  3323. }
  3324. // Randomize Shuffle List
  3325. function shuffleArray(array) {
  3326. for ( let i = array.length - 1; i > 0; i-- ) {
  3327. const j = Math.floor(Math.random() * (i + 1));
  3328. [array[i], array[j]] = [array[j], array[i]];
  3329. }
  3330. return array;
  3331. }
  3332. // Attach Shuffle List data to $audio_player
  3333. function updateShuffleList(id) {
  3334. if ( !$body.hasClass('shuffle_audio') ) {
  3335. return;
  3336. } else if ( id !== undefined ) { // don't include .playing and .unchecked track in shufflelist
  3337. let shuffleList = $audio_player.data('shufflelist');
  3338. if ( $(document.getElementById(id)).hasClass('unchecked') || $(document.getElementById(id)).hasClass('playing') ) {
  3339. shuffleList.splice(shuffleList.indexOf(id), 1);
  3340. $audio_player.data('shufflelist',shuffleList);
  3341. } else {
  3342. shuffleList.push(id);
  3343. shuffleList = shuffleArray( shuffleList );
  3344. }
  3345. } else {
  3346. let shuffleList = shuffleArray( updatePlaylist() );
  3347. $audio_player.data('shufflelist',shuffleList);
  3348. }
  3349. }
  3350. // Check/Uncheck Audio/Video Files
  3351. function toggleChecked(e) {
  3352. e.stopPropagation();
  3353. $(this).blur();
  3354. thisRow(this).toggleClass('unchecked');
  3355. updateShuffleList(thisRow(this).attr('id'));
  3356. }
  3357. $media_files.on('click','input', toggleChecked );
  3358. // Check/Uncheck all Audio/Video Files
  3359. function toggleAllChecked(e) {
  3360. e.stopPropagation();
  3361. $dir_list_row.find('input').trigger('click');
  3362. updateShuffleList();
  3363. }
  3364. $dir_list.find('#play_toggle').on('click', toggleAllChecked );
  3365.  
  3366. // Is Playing
  3367. function isPlaying(el) {
  3368. return (el !== undefined && el.get(0).currentTime > 0 && !el.get(0).paused && !el.get(0).ended); // returns true if all conditions are true
  3369. }
  3370. // Play Media
  3371. function playMedia(task) {
  3372. if ( $playing_file().hasClass('audio') ) { $audio_player.trigger(task); } else { $content_video.trigger(task); }
  3373. }
  3374. // Skip media tracks +/-10/30 seconds
  3375. function mediaSkip(e) {
  3376. const factor = ( e.key === 'ArrowLeft' ? -1 : 1 ); // forward or backward?
  3377. const skip = ( e.altKey && e.shiftKey ? 30 : e.altKey ? 10 : null ); // 30s or 10s?
  3378. const $player = ( $playing_file().hasClass('audio') ? $audio_player : $content_video ); // audio or video?
  3379. const time = $player.prop('currentTime'); // current time
  3380. $player.prop('currentTime', time + factor*(skip)); // set time
  3381. }
  3382.  
  3383. // Play/Pause Audio/Video
  3384. function playPauseMedia() {
  3385. let $player = ( $content_pane.hasClass('has_audio') ? $('#audio') : $('#content_video') );
  3386. if ( isPlaying( $player ) ) { $player.trigger('pause'); } else { $player.trigger('play'); }
  3387. }
  3388. // Play Next Track
  3389. function playPrevNextTrackBtn(el) {
  3390. let key = ( el.attr('id') === 'prev_track' ? 'ArrowLeft' : 'ArrowRight' );
  3391. playPrevNextTrack(key);
  3392. }
  3393. // Prev/Next Track buttons
  3394. $('.prev_next_track_btn').on( 'click', function() { playPrevNextTrackBtn( $(this) ); });
  3395.  
  3396. // Toggle Shuffle Play
  3397. $('#checkbox_div').on('click','#shuffle', function() {
  3398. $body.toggleClass('shuffle_audio');
  3399. updateShuffleList();
  3400. if ( $body.hasClass('shuffle_audio') && $('.playing').length === 0 ) {
  3401. playPrevNextTrack('ArrowRight');
  3402. } else {
  3403. // do nothing: i.e., allow current track to continue playing
  3404. }
  3405. });
  3406. // Toggle Loop Play
  3407. $('#checkbox_div').on('click','#loop', function() {
  3408. $body.toggleClass('loop_audio');
  3409. document.getElementById('audio').toggleAttribute('loop');
  3410. });
  3411.  
  3412. // Initialize Audio
  3413. function initMedia() {
  3414. $('#audio, #content_video').on('ended', function() {
  3415. playPrevNextTrack('ArrowRight');
  3416. scrollThis('tbody','playing');
  3417. });
  3418. }
  3419. // ***** END AUDIO PLAYBACK ***** //
  3420.  
  3421. // ***** IFRAME SETUP ***** //
  3422. // For directory display or editable text files
  3423. // If row is a directory, set up iFrameDirUI(); if it's an editable text document, set up iFrameTextEditingUI().
  3424. function setUpIframeUI(bool) {
  3425. if ( window.self !== window.top ) {
  3426. const $textFiles = $row_types.markdown.concat($row_types.text, $row_types.code); // define which files are editable
  3427. // if selected index item is a directory, set up the directory UI....
  3428. if ( window.location.pathname.endsWith('/') ) {
  3429. iFrameDirUI( $('#iframe_body') );
  3430. }
  3431. if ( JSON.parse(bool) === true && $textFiles.includes( window.location.pathname.slice( window.location.pathname.lastIndexOf('.') + 1 ) ) ) {
  3432. $iFrame_head.append('<style>'+ $text_editing_style_rules +'</style>');
  3433. $iFrame_head.append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css"></link>');
  3434. let splitClass = ( getQuery('split_view') === 'true' ? 'split_view' : '' );
  3435. let viewClass = getQuery('default_text_view');
  3436. 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>';
  3437.  
  3438. TextEditing( '#iframe_body' );
  3439. $('#iframe_body').removeClass().addClass(splitClass).addClass(viewClass).prepend(warnings);
  3440. $('#content_source').removeClass().prop('disabled',false);
  3441. }
  3442. }
  3443. }
  3444. // IFRAME DIRECTORY Prep
  3445. function iFrameDirUI(el) { // el = iframeBody
  3446. let parentLink = decodeURIComponentSafe(window.location.pathname);
  3447. parentLink = parentLink.split('/').slice(0,-2).join('/') + window.location.search;
  3448. let queryPrefs = window.location.search;
  3449. queryPrefs = queryPrefs.slice(1).split('&');
  3450. queryPrefs = queryPrefs.map(x => x.split('='));
  3451. let prefs = Object.fromEntries(queryPrefs); // convert query array of arrays to object
  3452. let sortPref = prefs.sort_by; // sort determined by parent's current sorting pref
  3453. let numbersPref = prefs.show_numbers;
  3454. let viewSourcePref = prefs.view_source;
  3455. let iconsPref = prefs.use_custom_icons;
  3456. if ( viewSourcePref === 'true' ) {
  3457. return; // show raw directory index
  3458. } else {
  3459. if ( numbersPref === 'true' ) {
  3460. $('#iframe_body').addClass('show_numbers');
  3461. }
  3462. if ( iconsPref === 'true' ) {
  3463. $('#iframe_body').addClass('use_custom_icons');
  3464. }
  3465. $iFrame_head.find('style').remove();
  3466. $iFrame_head.append('<style>'+ $iframe_styles +'</style>');
  3467.  
  3468. const parentLinkCell = '<tr id="parent"><th colspan=4><a href="'+ parentLink +'">Parent Directory</a></th></tr>';
  3469. const sortingRow = '<tr><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>';
  3470. const preppedIndex = makeNewIndex($('#iframe_body'),sortPref);
  3471. const iFrameTable = $('<table id="dir_list"><thead id="thead">'+ parentLinkCell + sortingRow +'</thead><tbody id="tbody"></tbody></table>');
  3472. // append prepped index
  3473. el.empty().append(iFrameTable).find('tbody').append(preppedIndex);
  3474. $('#iframe_body').find('#tbody').css({'top':$('#iframe_body').find('#thead').height() +'px'});
  3475. $('#iframe_body').data('sort_direction',1).find('#dir_list').addClass('sort_by_'+ sortPref); // initial directory sort
  3476. }
  3477. }
  3478.  
  3479. // IFRAME Directory sorting
  3480. $('#iframe_body').on('click','.sorting', function() {
  3481. const $dir_list_row = $('#iframe_body').find('#tbody').find('tr');
  3482. const id = $(this).attr('id');
  3483. if ( $('#iframe_body').data('sorting') !== id ) { // if clicking sorting item for the first time
  3484. $('#iframe_body').data('sorting',id);
  3485. $('#iframe_body').data('sorting',id).data('sort_direction', 1 );
  3486. $(this).removeClass('down');
  3487. } else { // clicking the same sorting item again -- reverse sort order
  3488. $('#iframe_body').data('sort_direction', $('#iframe_body').data('sort_direction') * -1 );
  3489. $(this).toggleClass('down');
  3490. }
  3491. const sort_direction = $('#iframe_body').data('sort_direction');
  3492. const $sorted_index = sortDirList( $dir_list_row, id, sort_direction );
  3493. $('#iframe_body').find('#dir_list').removeClass().addClass(id).find('#tbody').empty().append($sorted_index);
  3494. });
  3495. // ensure that iframe directory links include query string
  3496. $('#iframe_body').on('click','#dir_list tr.dir a', function(e) {
  3497. e.preventDefault();
  3498. let link = $(this).attr('href') + window.location.search;
  3499. window.location = link;
  3500. });
  3501. //***** TEXT EDITING PANE *****//
  3502. function textEditorUI() { //
  3503. if ( $content_text.children().length === 0 ) { // only add UI once
  3504. $body.addClass('has_text');
  3505. $content_pane.removeClass('has_dir');
  3506. if ( $content_pane.hasClass('has_grid') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  3507. TextEditing('#content_text');
  3508. $content_text.find('#content_preview').html($content_text.find('#content_source').val()); // make sure any source text is also previewed.
  3509. if ( getQuery('split_view') === 'true' || getQuery('default_text_view') === 'source_text' ) { $content_text.find('#content_source').focus(); }
  3510. } else { // show text editor
  3511. if ( !$body.hasClass('has_text') ) {
  3512. $body.addClass('has_text');
  3513. } else if ( $body.hasClass('has_text') || $body.hasClass('has_hidden_text') ) {
  3514. $body.toggleClass('has_text has_hidden_text');
  3515. }
  3516. if ( $content_pane.hasClass('has_grid') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  3517. if ( $content_pane.hasClass('has_hidden_grid ') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  3518. }
  3519. setContentTitle();
  3520. setContentHeight();
  3521. }
  3522. // show text editor pane
  3523. $('#text_editor, #text_editor_row').on('click', function(e) {
  3524. e.preventDefault();
  3525. textEditorUI();
  3526. });
  3527.  
  3528. // Main Text Editing Function
  3529. function TextEditing(id) { // container_el = $content_text or $content_iframe body
  3530. let container_el = $(id);
  3531. const $srctxt = ( container_el.find('> pre').length ? container_el.find('> pre').text() : container_el.html() ); // source text equals file content or nothing
  3532.  
  3533. MDbuildUI(id);
  3534.  
  3535. const $toolbar = container_el.find('#toolbar');
  3536. const $source = container_el.find('#content_source');
  3537. const $preview = container_el.find('#content_preview');
  3538. const $MDhandle = container_el.find('#text_editing_handle');
  3539.  
  3540. MDsetupTextEditingUI(id,$srctxt);
  3541. // Toolbar button functions
  3542. $toolbar.on('click','li,span',function(e) {
  3543. e.stopPropagation();
  3544. MDtoolBarFunctions($(this).attr('id'));
  3545. });
  3546. $(window).on('resize',function() {
  3547. $source.add($preview).add($MDhandle).attr('style','');
  3548. });
  3549. $('body#top').on('input', '#content_source', function() {
  3550. $source.add($preview).css({'height':$('#main_content').height() - $('#content_header').height() - 32 });
  3551. });
  3552.  
  3553. // Resize
  3554. $MDhandle.on('mousedown', function(e) {
  3555. e.stopPropagation();
  3556. MDresizeSplit($MDhandle,$source,$preview);
  3557. });
  3558. // Click labels to toggle checkboxes
  3559. $preview.add($toolbar).on('click','label', function(e) {
  3560. e.stopPropagation();
  3561. $(this).siblings('input').click();
  3562. });
  3563. // Sync scroll
  3564. $source.on('scroll',function() { MDsyncScroll(this); });
  3565. $preview.on('scroll',function() { MDsyncScroll(this); });
  3566.  
  3567. // TEXT EDITING
  3568. // Generate Preview
  3569. const $source_text = ( $source.length === 0 ? '' : $source.val() );
  3570. MDmarkdown( $source_text, $preview );
  3571.  
  3572. // Live preview update, and set edited classes for unsaved warning
  3573. $source.on('input', function() {
  3574. if ( !$('body').hasClass('edited') && $(this).parents('#top').length === 1 ) {
  3575. $('body#top').addClass('edited');
  3576. }
  3577. if ( !$('body').hasClass('edited') && $(this).parents('#iframe_body').length === 1 ) {
  3578. $('body#iframeBody').addClass('edited');
  3579. sendMessage('top','iframe_edited','','');
  3580. }
  3581. MDlivePreview($source,$preview);
  3582. });
  3583. // Checklists
  3584. MDsetChecklistClass();
  3585. // Live checkboxes
  3586. $preview.on('click','.checklist input',function(e) {
  3587. e.stopPropagation();
  3588. MDliveCheckBoxes($(this),$source,$preview);
  3589. });
  3590. // Preview TOC click navigation
  3591. $preview.on('click','.table-of-contents a',function(e) {
  3592. e.preventDefault();
  3593. MDtocClick($(this),$preview);
  3594. });
  3595. $preview.on('click','.uplink',function(e) {
  3596. e.stopPropagation();
  3597. MDheaderClick($preview);
  3598. });
  3599. }
  3600. ///// END MAIN MD FUNCTION
  3601.  
  3602. // MARKDOWN Functions
  3603. // MD Build UI
  3604. function MDbuildUI(id) {
  3605. const toggleSplitBtn = $('<li id="toggle_split" title="Toggle Split"></li>');
  3606. const syncScrollEl = $('<li id="sync_scroll"><input name="sync_scroll" type="checkbox"><label for="sync_scroll">Sync Scroll</label></li>');
  3607. const toggleSrcBtn = $('<li id="show_source" title="Show Source"></li>');
  3608. const togglePreviewBtn = $('<li id="show_preview" title="Show Preview"></li>');
  3609. const clearTextBtn = $('<li id="clear_text" title="Clear Text">Clear</li>');
  3610. 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>');
  3611. const buttonsCont = $('<ul id="toolbar"></ul>');
  3612. buttonsCont.append(toggleSrcBtn, togglePreviewBtn, toggleSplitBtn, syncScrollEl, saveBtn, clearTextBtn);
  3613. const textEditingUI = '<textarea id="content_source"></textarea><div id="content_preview" class="markdown-body"></div><div id="text_editing_handle"></div>';
  3614. // append the UI to the container_el
  3615. $(id).prepend(buttonsCont).append(textEditingUI);
  3616. }
  3617.  
  3618. // MD Set up UI
  3619. function MDsetupTextEditingUI(id,sourceText) {
  3620. $(id).find('pre').first().remove();
  3621. $(id).find('#content_source').val(sourceText); // set source text from pre
  3622. if ( getQuery('split_view') === 'true' ) { $('body').addClass('split_view'); } else { $('body').removeClass('split_view'); }
  3623. if ( getQuery('default_text_view') === 'preview' ) { $('body').addClass('preview_text').removeClass('source_text'); } else { $('body').addClass('source_text').removeClass('preview_text'); }
  3624. if ( getQuery('sync_scroll') === 'true' ) { $('#sync_scroll input').prop({checked:true}); }
  3625. }
  3626. // MD UI Buttons functions
  3627. function MDtoolBarFunctions(id) {
  3628. let $thisFileName;
  3629. let container_el = $(getElById(id)).closest('body');
  3630. let sourceEl = container_el.find('#content_source');
  3631. let previewEl = container_el.find('#content_preview');
  3632. if ( $body.hasClass('has_text') ) {
  3633. $thisFileName = 'untitled';
  3634. } else {
  3635. $thisFileName = decodeURI(window.location.pathname.slice(window.location.pathname.lastIndexOf('/') + 1));
  3636. }
  3637. 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">';
  3638. const $saveHTMLClose = '</body></html>';
  3639. switch (id) {
  3640. case 'toggle_split':
  3641. $('body').toggleClass('split_view').find('#content_source,#content_preview,#text_editing_handle').attr('style','');
  3642. if ( container_el.hasClass('source_text') ) {
  3643. sourceEl.focus();
  3644. document.getElementById('content_source').setSelectionRange(0,0);
  3645. }
  3646. break;
  3647. case 'show_source':
  3648. 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
  3649. sourceEl.css({'width':'100%'}).focus();
  3650. document.getElementById('content_source').setSelectionRange(0,0);
  3651. break;
  3652. case 'show_preview':
  3653. container_el.removeClass('split_view source_text').addClass('preview_text').find('#content_source,#content_preview,#text_editing_handle').attr('style','');
  3654. break;
  3655. case 'clear_text':
  3656. container_el.addClass('has_warning').find('#warnings').removeClass().addClass('clear');
  3657. break;
  3658. case 'save_text':
  3659. saveMD( $thisFileName, sourceEl.val() );
  3660. break;
  3661. case 'save_HTML':
  3662. saveMD( $thisFileName.slice(0,$thisFileName.lastIndexOf('.') + 1) + 'html', $saveHTMLOpen + MDprepHTML(previewEl.html()) + $saveHTMLClose );
  3663. break;
  3664. }
  3665. }
  3666. // MD Custom pre- and post-processing for text.
  3667. function MDaddHeaderIDs(match, p1, p2, p3, offset, string) { // create header ids for TOC
  3668. return '<h'+ p1 +' id="'+ p3.toLowerCase().replace(/\s/g,'-') +'" ' + p2 +'>'+ p3;
  3669. }
  3670. function MDcustomPreProcess(src) {
  3671. return src; // we're not doing anything here just yet...
  3672. }
  3673. function MDcustomPostProcess(html) {
  3674. 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
  3675. .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
  3676. // .replace(/<li><p class="checklist">"/g,'<li class="checklist"><p>')
  3677. .replace(/^<h(\d)([^>]*)>([^<]+)/gm, MDaddHeaderIDs) // add header IDs;
  3678. .replace(/<\/h(\d)>/g,'<span class="uplink">&uarr;</span></h$1>');
  3679. return html;
  3680. }
  3681. //MD Render markdown from preprocessed source text
  3682. function MDmarkdown(sourceText,previewEl) {
  3683. const MDit = window.markdownit({linkify:false,typography:false,html:true})
  3684. .use(window.markdownitMultimdTable, {enableMultilineRows: true})
  3685. .use(window.markdownitSub)
  3686. .use(window.markdownitSup)
  3687. .use(window.markdownitFootnote)
  3688. .use(window.markdownitCentertext)
  3689. .use(window.markdownitDeflist)
  3690. .use(window.markdownitTocDoneRight)
  3691. ;
  3692. let MDpreview = MDit.render( MDcustomPreProcess( sourceText ) );
  3693. previewEl.html( MDcustomPostProcess( MDpreview ) ); // set previewed html
  3694. }
  3695. // MD Live preview, add edited warning
  3696. function MDlivePreview(sourceEl,previewEl) {
  3697. MDmarkdown( sourceEl.val(),previewEl );
  3698. MDsetChecklistClass();
  3699. }
  3700.  
  3701. // MD Live Checkboxes prep: find each instance of [ ] or [x] and replace text in index = to clicked checkbox in Preview.
  3702. function MDreplaceAt(str, replacement, position) {
  3703. str = str.substring(0, position) + replacement + str.substring(position + replacement.length);
  3704. return str;
  3705. }
  3706. function MDreplaceNthSubStr(str,substr,replacement,index) {
  3707. let count = 0;
  3708. let found = substr.exec(str);
  3709. while ( found !== null ) {
  3710. if ( count === index ) {
  3711. return MDreplaceAt(str, replacement, found.index );
  3712. } else {
  3713. count++;
  3714. found = substr.exec(str);
  3715. }
  3716. }
  3717. }
  3718. // MD Live Checkboxes
  3719. function MDliveCheckBoxes(checkbox,sourceEl,previewEl) {
  3720. $('.checklist').removeClass('clicked');
  3721. checkbox.closest('p,li,dt,dd').addClass('clicked');
  3722. const thisIndex = previewEl.find('.checklist').index( $('.clicked') );
  3723. const srctext = sourceEl.val();
  3724. const substr = new RegExp(/\[\s*.\s*\]/g);
  3725. const replacement = ( checkbox.is(':checked') ? '[x]' : '[ ]' );
  3726. sourceEl.val( MDreplaceNthSubStr(srctext, substr, replacement, thisIndex) );
  3727. }
  3728. // MD Checkbox list class: Prevent checkbox lists from having list bullets
  3729. function MDsetChecklistClass() {
  3730. $('input[type="checkbox"]').closest('ul').addClass('no_list');
  3731. }
  3732.  
  3733. // MD Resize Split View
  3734. function MDresizeSplit(handle,sourceEl,previewEl) {
  3735. let $sidebarWidth = $('#sidebar').outerWidth();
  3736. let $pageWidth = window.innerWidth;
  3737.  
  3738. $(document).on('mousemove',function(e) {
  3739. e.stopPropagation();
  3740. e.preventDefault();
  3741. let pageX = e.pageX;
  3742. if ( pageX > $sidebarWidth + 100 && pageX < $pageWidth - 100 ) { // min widths
  3743. handle.css({'left': pageX - $sidebarWidth - 4 + 'px'});
  3744. sourceEl.css({'width': pageX - $sidebarWidth + 'px'});
  3745. previewEl.css({'left': sourceEl.outerWidth() + 'px'});
  3746. }
  3747. });
  3748. handle.on('mouseup',function() {
  3749. $(document).off('mousemove');
  3750. });
  3751. }
  3752. // MD UI Sync Scroll
  3753. function MDpercentage(el) { return (el.scrollTop / (el.scrollHeight - el.offsetHeight)); }
  3754. function MDsyncScroll(el1) {
  3755. let el2 = ( el1.getAttribute('id') === 'content_preview' ? document.getElementById('content_source') : document.getElementById('content_preview') );
  3756. if ( document.querySelector('input[name="sync_scroll"').checked ) {
  3757. el2.scrollTo( 0, (MDpercentage(el1) * (el2.scrollHeight - el2.offsetHeight)).toFixed(0) ); // toFixed(0) prevents scrolling feedback loop
  3758. }
  3759. }
  3760. // click TOC anchors
  3761. function MDtocClick(el,previewEl) {
  3762. let thisId = el.attr('href');
  3763. if ( thisId ) {
  3764. previewEl.scrollTop( $(thisId).offset().top - 48 );
  3765. }
  3766. }
  3767. // click Headers to return to TOC or top
  3768. function MDheaderClick(previewEl) {
  3769. if ( previewEl.find('.table-of-contents').length > 0 ) {
  3770. document.getElementsByClassName('table-of-contents')[0].scrollIntoView(true);
  3771. } else {
  3772. document.getElementById('preview').scroll(0,0);
  3773. }
  3774. }
  3775. // MD Clear text source
  3776. function clearText(container_el) {
  3777. if ( window.top !== window.self ) { // if iframe, send message to top (to remove iframe_edited class)
  3778. sendMessage('top','clear');
  3779. }
  3780. container_el.find('#content_source').show().focus().val('');
  3781. container_el.find('#content_preview').empty();
  3782. container_el.removeClass('edited has_warning');
  3783. }
  3784. // MD SAVE SOURCE or HTML
  3785. function MDprepHTML(data) {
  3786. data = data.replace(/<span\sclass="uplink">.<\/span>/g,'');
  3787. return data;
  3788. }
  3789. function saveMD(filename, data) {
  3790. let blob = new Blob([data], {type: 'text/plain'});
  3791. let downloadEl = window.document.createElement('a');
  3792. downloadEl.href = window.URL.createObjectURL(blob);
  3793. downloadEl.download = filename;
  3794. document.body.appendChild(downloadEl);
  3795. downloadEl.click();
  3796. document.body.removeChild(downloadEl);
  3797. URL.revokeObjectURL(blob);
  3798. if ( window.top !== window.self ) { // if iframe, send message to top
  3799. sendMessage('top','clear');
  3800. }
  3801. $('body,#content_source,#content_text').removeClass('edited');
  3802. }
  3803. // list of functions to remember while sending messages and then execute after warning button click
  3804. function doFunction(funcName,args) {
  3805. var funcDictionary = { 'setLocation':setLocation, 'resetContent':resetContent, 'closeContent':closeContent, 'clickThis':clickThis, 'clickRow':clickRow, 'doubleClickRow':doubleClickRow, 'indexNavigation':indexNavigation, 'clearText':clearText, 'null':null };
  3806. return funcName === 'null' ? null : funcDictionary[funcName](args);
  3807. }
  3808. // Show warning after certain user actions if text editor or iframe has edited text; otherwise do the action.
  3809. function showWarning(funcName,args) {
  3810. // Don't show the warning if func = indexNavigation or clickRow; i.e., just hide text editor;
  3811. // In other words, only show warning when changing directories or if iframe content has been edited
  3812. if ( ( $('body').hasClass('edited') && funcName !== 'indexNavigation' && funcName !== 'clickRow' ) || $('body').hasClass('iframe_edited') ) {
  3813. if ( $('body').hasClass('edited') ) { // show warning and text editor (if hidden)
  3814. $body.addClass('has_warning').find('#warnings').removeClass().addClass('unloading');
  3815. $body.removeClass('has_hidden_text').addClass('has_text');
  3816. }
  3817. if ( $('body').hasClass('iframe_edited') ) { // if iframe is edited, send unloading message
  3818. sendMessage('iframe','unloading',funcName,args); // upon receipt of message, iframe will show its warning message, based on the funcName
  3819. }
  3820. } else {
  3821. doFunction(funcName,args);
  3822. }
  3823. }
  3824. // Send a message to iframe or parent
  3825. function sendMessage(target,message,funcName,args) {
  3826. var messageObj = { 'messageContent': message, 'functionName': funcName, 'arguments': args };
  3827. if ( target === 'iframe' ) {
  3828. let contentIFrame = document.getElementById('content_iframe');
  3829. contentIFrame.contentWindow.postMessage( messageObj, '*' );
  3830. }
  3831. if ( target === 'top' ) {
  3832. window.parent.postMessage( messageObj, '*');
  3833. }
  3834. }
  3835. // Receive a message from iframe or parent, do appropriate action
  3836. function receiveMessage(e) {
  3837. if ( e.origin === 'null' || e.origin === $origin ) {
  3838. let $message = e.data.messageContent;
  3839. let funcName = e.data.functionName;
  3840. let args = e.data.arguments;
  3841.  
  3842. if ( $message === 'split_view' ) {
  3843. $iframe_body.toggleClass('split_view');
  3844. }
  3845. if ( $message === 'default_text_view' ) {
  3846. $iframe_body.toggleClass('preview_text source_text').removeClass('split_view');
  3847. }
  3848. // warn iframe that user wants to change iframes
  3849. if ( $message === 'unloading' && !$iframe_body.hasClass('has_warning') ) {
  3850. $iframe_body.addClass('has_warning').find('#warnings').removeClass().addClass('unloading').attr('data-function_name',funcName).attr('data-args',args);
  3851. }
  3852. // let top know iframe text has been edited
  3853. if ( $message === 'iframe_edited' && !$('body#top').hasClass('iframe_edited') ) {
  3854. $('body#top').addClass('iframe_edited');
  3855. }
  3856. if ( $message === 'ignore' || $message === 'clear' ) {
  3857. $('body#top').removeClass('iframe_edited');
  3858. if ( $message === 'ignore' ) { doFunction(funcName,args); }
  3859. }
  3860. }
  3861. }
  3862. window.addEventListener('message',receiveMessage,false);
  3863.  
  3864. // Edited Warning buttons: what to do when the user clicks a warning button
  3865. function editedWarningButtons(id) {
  3866. let btn = $(document.getElementById(id));
  3867. let container_el = btn.closest('body');
  3868. let func = $('#warnings').attr('data-function_name');
  3869. let args = $('#warnings').attr('data-args');
  3870. switch(id) {
  3871. case 'warning_ignore_btn': // do the user initiated func without saving the edited text
  3872. if ( window.self !== window.top ) { // if iframe, send message to top
  3873. sendMessage('top','ignore',func,args);
  3874. }
  3875. container_el.removeClass('edited has_text has_warning');
  3876. clearText(container_el);
  3877. break;
  3878. case 'warning_cancel_btn': // cancel the func
  3879. container_el.removeClass('has_warning').find('#warnings').removeClass();
  3880. break;
  3881. case 'warning_clear_btn': // clear the text editor
  3882. clearText(container_el);
  3883. break;
  3884. case 'warning_save_btn': // save the text
  3885. if ( window.top !== window.self ) { // if iframe, send message to top
  3886. sendMessage('top','clear');
  3887. }
  3888. container_el.removeClass('edited has_warning');
  3889. $('#save_text').click();
  3890. break;
  3891. case 'warning_ok_btn': // clear the text editor
  3892. $('body').removeClass('has_warning').find('#warnings').removeClass('local');
  3893. break;
  3894. }
  3895. }
  3896. $('#warnings').on('click','button',function(e) {
  3897. e.preventDefault();
  3898. editedWarningButtons( $(this).attr('id') );
  3899. });
  3900. // Edited Warning overlay: prevent user clicks on rest of UI
  3901. $('#overlay').on('click mousedown mouseup',function(e) {
  3902. e.preventDefault();
  3903. e.stopPropagation();
  3904. return;
  3905. });
  3906.  
  3907. // END Text Editing
  3908.  
  3909. // EXPERIMENTAL: Open playlist
  3910. $('#open_playlist_label').on('click',function(e) { $('.menu').hide(); });
  3911. // Open font
  3912. $('#bookmarks').on('change','#open_playlist',function(e) {
  3913. openPlaylist(e);
  3914. });
  3915. function convertPlaylist(items) {
  3916. let preppedIndex = '';
  3917. let preppedRow = '';
  3918. let id = 0, rows, info, title, time = '0', display_time = '—', link, kind = '', display_kind, ext;
  3919. items = items.replace(/\s*#EXTM3U.*\n/,'\n').replace(/^\*\n{2,}/gm,'\n');
  3920. if ( items.indexOf('#EXTINF:') !== -1 ) {
  3921. rows = items.split('#EXTINF:');
  3922. } else {
  3923. rows = items.split('\n');
  3924. }
  3925. for ( let row of rows ) {
  3926. if ( row.indexOf('\n') !== -1 && row.trim().length > 0 ) {
  3927. row = row.trim().split('\n');
  3928. info = row[0];
  3929. time = info.slice(0,info.indexOf(','));
  3930. display_time = new Date(time * 1000).toISOString().substr(11, 8);
  3931. title = info.slice(info.indexOf(',') + 1);
  3932. link = row[1];
  3933. } else {
  3934. title = decodeURIComponentSafe(row.slice(row.lastIndexOf('/') + 1));
  3935. link = row;
  3936. }
  3937. ext = link.slice(link.lastIndexOf('.') + 1);
  3938.  
  3939. if ( $row_types.audio.includes( ext ) ) {
  3940. kind = 'audio';
  3941. display_kind = 'Audio';
  3942. } else if ( $row_types.video.includes( ext ) ) {
  3943. kind = 'video';
  3944. display_kind = 'Video';
  3945. }
  3946. if ( kind !== '' ) { // only allow supported media types
  3947. 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>';
  3948. preppedIndex += preppedRow;
  3949. }
  3950. id++;
  3951. }
  3952. closeGrid();
  3953. closeContent();
  3954. closeOtherContent();
  3955. $dir_list.find('tbody').empty().addClass('playlist').append(preppedIndex);
  3956. $dir_list.find('#stats').html(getIndexStats($dir_list.find('#tbody tr')));
  3957. $body.addClass('has_playlist has_audio');
  3958. if ( $body.hasClass('autoload_media') ) { $('#rowid-1').click(); }
  3959. setContentTitle();
  3960. setContentHeight();
  3961. scrollThis('tbody','selected',false);
  3962. }
  3963. function openPlaylist(evt) {
  3964. if (window.File && window.FileReader && window.FileList && window.Blob) {
  3965. var files = evt.target.files;
  3966. var reader = new FileReader();
  3967. reader.onload = function(file) {
  3968. convertPlaylist(file.target.result);
  3969. return true;
  3970. };
  3971. reader.readAsText(files[0]);
  3972. document.title = "Playlist: "+ files[0].name;
  3973. $('#parents_dir_menu').find('> div').empty().html( files[0].name );
  3974. $('#open_playlist').val('');
  3975. } else {
  3976. alert('File APIs are not fully supported in this browser.');
  3977. }
  3978. }
  3979.  
  3980. })();
  3981. // THE END!
  3982.