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 for directory items; audio playback with shuffle and loop; video player; edit, preview, and save markdown/plain text files; preview images and fonts; image and font grids; sorting; user-defined shortcuts; more.

当前为 2019-07-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Supercharged Local Directory File Browser
  3. // @version 4.0.4b
  4. // @description Makes file:/// directory ("Index of...") pages (and many server-generated index pages) actually useful. Adds sidebar and preview pane; keyboard navigation for directory items; audio playback with shuffle and loop; video player; edit, preview, and save markdown/plain text files; preview images and fonts; image and font grids; sorting; user-defined shortcuts; more.
  5. // @author Gaspar Schott (Michael Schrauzer) mshroud@gmail.com
  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/8.4.2/markdown-it.js
  15. // @require https://cdnjs.cloudflare.com/ajax/libs/markdown-it-footnote/3.0.1/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.1.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.  
  24. // NOTE: This script was developed in Vivaldi, running on Mac OS High Sierra. It has been tested in various Chrome and Gecko-based browsers.
  25. // It has been minimally tested on Windows and not at all on other OSes. It should work, but please report any issues.
  26. // 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).
  27.  
  28. // 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.
  29. // For Tampermonkey, go to Chrome extension page, and tick the 'Allow access to file URLs' checkbox at the Tampermonkey extension section.
  30. // For Greasemonkey, open about:config and change greasemonkey.fileIsGreaseable to true.
  31.  
  32. // @namespace https://greasyfork.org/users/16170
  33. // ==/UserScript==
  34.  
  35. (function() {
  36. 'use strict';
  37. const $ = window.jQuery;
  38.  
  39. // ***** USER SETTINGS ***** //
  40.  
  41. const $settings = {
  42. // Paste your exported settings between the two lines below:
  43. //--------------------------------------------------------//
  44.  
  45. shortcuts: // N.B.: Directory links must end with "/", file links must end with another character.
  46. // You may add as many menus and links as you like; just copy the example below and edit as needed.
  47. // Local directory shortcuts must begin with "file:///"; external shortcuts must begin with the correct protocol ("http://" or "ftp://", etc.).
  48. // Note that because of same-origin security concerns, the browser will not allow you to navigate directly from an external webpage to a local directory.
  49. [
  50. {
  51. "menu_title":"My Sample Menu",
  52. "links":
  53. [
  54. { "link_name":"My Directory Link 1", "link":"file:///Path/To/My/Directory/" },
  55. { "link_name":"My Directory Link 2", "link":"file:///Path/To/My/Directory_2/" },
  56. { "link_name":"My External Link", "link":"https://www.mywebpage.com/" },
  57. { "link_name":"My File Link", "link":"file:///Path/To/My/File.ext" },
  58. ]
  59. },
  60. {
  61. "menu_title":"My Second Sample Menu",
  62. "links":
  63. [
  64. { "link_name":"My Directory Link 1", "link":"file:///Path/To/My/Directory/" },
  65. { "link_name":"My Directory Link 2", "link":"file:///Path/To/My/Directory_2/" },
  66. { "link_name":"My External Link", "link":"https://www.mywebpage.com/" },
  67. { "link_name":"My File Link", "link":"file:///Path/To/My/File.ext" },
  68. ]
  69. },
  70. ],
  71. // GENERAL USER SETTINGS
  72. alternate_background: true, // If true (default true), alternate sidebar row background color.
  73. 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.
  74. // If false (default), treat apps as ignored files.
  75. 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).
  76. autoload_index_files: false, // If true (default: false), automatically select first "index.xxx" (.xxx !== .htm) file found in directory.
  77. // 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.
  78. theme: 'light', // Options: 'light' or 'dark'
  79. sort_by: 'default', // Choose from: 'name', 'size', 'date', 'kind', 'ext', 'default'.
  80. // default = Chrome sorting: dirs on top, files alphabetical.
  81. 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").
  82. // 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.)
  83. grid_font_size: 1, // Default = 1
  84. grid_image_size: 184, // Default = 184 (200px - 16px)
  85. show_details: true, // If true (default), hide file and directory details; if false, show them.
  86. show_ignored_files: false, // If true, ignored files will appear greyed-out.
  87. // If false (default), ignored files will be completely hidden from the file list;
  88. 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;
  89. // 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).
  90. show_invisibles: true, // Un*x/Mac OS only: If true (default), files or directories beginning with a "." will be hidden.
  91. show_numbers: true, // If true (default true), number index items
  92. UI_font: 'system-ui, sans-serif', // Choose an installed font for the UI; if undefined, use browser defaults instead.
  93. UI_font_size: '13px', // Choose a default UI font size; use any standard CSS units.
  94. use_custom_icons: true, // if true (default), use custom icons for dirs and files
  95. // if false, use browser/server default icons
  96. // TEXT EDITING SETTINGS
  97. enable_text_editing: true, // If true (default), allow plain text files to be edited.
  98. default_text_view: 'preview_text', // Options: 'source_text' or 'preview_text' for text editor.
  99. // Note that split_view = true overrides this setting.
  100. split_view: true, // If true, show split view on plain text file load.
  101. // if true (default), use default preview_text setting.
  102. sync_scroll: true // If true (default: true), show split view on plain text file load
  103. // if false, use default preview_text setting.
  104. //--------------------------------------------------------//
  105. // Paste your exported settings between the above two lines.
  106. };
  107.  
  108. // $ROW_TYPES:
  109. // DO NOT DELETE ANY EXISTING CATEGORIES!
  110. // Add file extensions for sorting and custom icon display to the existing categories.
  111. // You can also define your own new categories, but do not add an extension to more than one row_type category.
  112. // Do not add leading "." to the extensions.
  113. const $row_types = {
  114. // myRowType: ['ext1','ext2'],
  115. dir: ['/'],
  116. app: ['app/','app','exe','msi'],
  117. archive: ['7z','archive','bz2','cbr','dmg','gz','pkg','rar','tar','zip'],
  118. audio: ['aac','aif','aiff','ape','flac','m4a','mp3','ogg','opus','wav','m3u'],
  119. bin: ['dll','dylib','icc','msi'],
  120. 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'],
  121. database: ['db','sql', 'sqlite'],
  122. font: ['otf','ttf','woff','woff2','afm','pfb','pfm','tfm'],
  123. graphics: ['ai','book','dtp','eps','fm','icml','idml','indd','indt','inx','mif','pmd','pub','qxb','qxd','qxp','sla','swf'],
  124. htm: ['htm','html','xhtm','xhtml'],
  125. image: ['apng','bmp','gif','jpeg','jpg','png','svg','webp'],
  126. ignored_image: ['ai','arw','cr2','dng','eps','nef','psd','psd','raw','tif','tiff'],
  127. markdown: ['md','markdown','mdown','mkdn','mkd','mdwn','mdtxt','mdtext'],
  128. office: ['csv','doc','docx','epub','key','numbers','odf','ods','odt','pages','rtf','scriv','xls','xlsx','xlm'],
  129. pdf: ['pdf'],
  130. system: ['DS_Store','ds_store','icon','ics'],
  131. text: ['log','nfo','txt','m3u'],
  132. video: ['m4v','mov','mp4','mpeg','webm']
  133. };
  134.  
  135. // $ROW_SETTINGS: Ignore or Exclude files by extension
  136. const $row_settings = {
  137. // 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).
  138. 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),
  139. // Exclude: Files with these exensions will not be inverted in dark mode
  140. exclude: ['htm','html','xhtm','xhtml']
  141. };
  142.  
  143. // ***** END USER SETTINGS ***** //
  144.  
  145. // ## FEATURES INCLUDE:
  146. // - Resizable sidebar and directory/file preview pane.
  147. // - Arrow navigation in sidebar:
  148. // - Up and Down Arrows select next/prev item.
  149. // - Left and Right Arrows select next/prev item of same type.
  150. // - Navigate sidebar by typed string.
  151. // - Show/Hide file details (size (if avail), date modified (if avail), kind, extension).
  152. // - Sort sidebar items by name or file details.
  153. // - Default sort = sort by name with folders on top.
  154. // - Preview all file types supported by browser (html, text, images, pdf, audio, video, etc.) and preview fonts.
  155. // - Preview and edit markdown and plain text files, with option to save files locally.
  156. // - Markdown rendered with markdownit.js ( https://github.com/markdown-it/markdown-it ).
  157. // - Uses Github Markdown styles for preview ( https://github.com/sindresorhus/github-markdown-css ), with a few customizations.
  158. // - Support for:
  159. // - TOC creation ( `${toc}` ) ( https://github.com/nagaozen/markdown-it-toc-done-right )
  160. // - Multimarkdown table syntax ( https://github.com/RedBug312/markdown-it-multimd-table )
  161. // - Live checkboxes ( `\[ ], [x]` ), allowed in lists and deflists.
  162. // - Superscript ( `^sup^` ) ( https://github.com/markdown-it/markdown-it-sup )
  163. // - Subscript ( `~sub~` ) ( https://github.com/markdown-it/markdown-it-sub )
  164. // - Definition lists ( https://github.com/markdown-it/markdown-it-deflist; for syntax, see http://pandoc.org/MANUAL.html#definition-lists )
  165. // - Centered text ( `->centered<-` ) ( https://github.com/jay-hodgson/markdown-it-center-text )
  166. // - Footnotes ( https://github.com/markdown-it/markdown-it-footnote )
  167. // - View source text, preview, or split pane with proportional sync scroll.
  168. // - Save edited source text or previewed HTML.
  169. // - Create and edit text in separate text editor.
  170. // - Audio and video playback, with shuffle, loop, skip audio +/- 10 or 30 sec via keyboard.
  171. // - Preview other files (e.g., lyrics or cover art) in same directory while playing audio.
  172. // - User setting to autoload cover art (if any images in directory, load "cover.ext" or first image found)
  173. // - Grid view for images and fonts.
  174. // - 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):
  175. // - Light or Dark theme.
  176. // - Bookmarks for local or remote directories.
  177. // - Default image grid size.
  178. // - Default UI font size and font-family.
  179. // - Default UI font and font-size.
  180. // - Default file sorting.
  181. // - Sort with directories on top.
  182. // - Treat apps as directories (MacOS and *nix only)
  183. // - Show or hide invisible files.
  184. // - Show or hide ignored files in the ignored files list (see $row_settings in code below $settings).
  185. // - Show or hide file details.
  186. // - Use custom file icons or browser defaults.
  187. // - Autoload index.ext files.
  188. // - Autoload cover art in directories with audio files.
  189. // - Text editing default view: split, source, or preview.
  190. // - Text editing sync scroll: on or off.
  191.  
  192. // ## KEYBINDINGS (These don't work in all browsers):
  193.  
  194. // - <kbd>Arrow Up/Down</kbd>: Select prev/next item.
  195. // - 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.
  196. // - <kbd>Arrow Left/Right</kbd>: Select prev/next row of the same kind as the current selection.
  197. // - If current selection is a media file, select and begin playback of the next media item.
  198. // - <kbd>Opt/Alt + Arrow Left/Right</kbd>: Skip audio ±10s
  199. // - <kbd>Opt/Alt + Shift + Arrow Left/Right</kbd>: Skip audio ±30s
  200. // - <kbd>Cmd/Ctrl + Arrow Up</kbd>: Go to parent directory
  201. // - <kbd>Cmd/Ctrl + Arrow Down</kbd>: Open selected directory
  202. // - <kbd>Return</kbd>: Open selected directory, select file, or pause/play media.
  203. // - <kbd>Space</kbd>: Pause/Play media files
  204. // - <kbd>Cmd/Ctrl + D</kbd>: Toggle file details (size, date modified) in some index page types.
  205. // - <kbd>Cmd/Ctrl + E</kbd>: Show text editor.
  206. // - <kbd>Cmd/Ctrl + G</kbd>: Show or Reset Grid.
  207. // - <kbd>Cmd/Ctrl + I</kbd>: Toggle Invisibles.
  208. // - <kbd>Cmd/Ctrl + Shift + O</kbd>: Open selected item in new window/tab.
  209. // - <kbd>Cmd/Ctrl + R</kbd>: Reload grids and previewed content, reset scaled images/fonts, reset media files to beginning.
  210. // - <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.
  211. // - <kbd>Cmd/Ctrl + Shift + < or ></kbd>: Scale preview items and grids.
  212.  
  213. // CHANGELOG:
  214.  
  215. // **VERSION 4.0.4b** Wrapping things up....
  216. // **FIXED:** Left/Right arrow key navigation failed for video files
  217. // **FIXED:** Content preview title wasn't being set for autoloaded images.
  218. // **FIXED:** An issue with autoloading media and cover art when the first media file was a video.
  219. // **FIXED:** Various issues with parsing local directory indexes in Firefox.
  220. // **FIXED:** Various issues with parsing, calculating, and displaying file size and date-modified information.
  221. // **IMPROVED:** Attempted to make index-type detection and index prep more generic, so that the script will work with more sites "right out of the box."
  222. // **IMPROVED:** Made index prep much more efficient, especially for table-type index pages and directories with many items.
  223. // **IMPROVED:** Better error handling for directories with percent-necoded characters in file names.
  224. // **IMPROVED:** Changed order of sorting headers to better align with sort data in list.
  225. // **OTHER:** More minor styling issues.
  226.  
  227. // **VERSION 4.0.3b**
  228. // **ADDED:** Preview current directory index source: click the double-caret icon in the sidebar stats footer to toggle preview.
  229. // This is useful for server configurations that include information in addition to the index itself and is quicker than opening a separate "View source" tab.
  230. // **FIXED:** An issue with content display caused by the fix for pdf display in the previous version.
  231. // **FIXED:** Up directory navigation didn't correctly account for invisible files and directories when selecting previously selected directory.
  232. // **FIXED:** More issues with prepping "pre"-type index pages.
  233. // **FIXED:** Some issues with Error page display.
  234. // **FIXED:** Various minor styling issues.
  235. // **CHANGED:** Moved "Disable Text Editing" menu item to top level.
  236.  
  237. // **VERSION 4.0.2b**
  238. // **FIXED:** Pdf display (I hope).
  239.  
  240. // **VERSION 4.0.1b**
  241. // **FIXED:** Audio files weren't being loaded.
  242. // **FIXED:** Script would fail if a file name included a special regex character `[\^$.|?*+()`.
  243. // **FIXED:** Various issue with parsing "pre"-type index pages.
  244. // **IMPROVED:** Sorting and display of items with names beginning with white spaces.
  245. // **IMPROVED:** More efficient and robust index type detection.
  246. // **ADDED:** Sorting for previewed directory contents. Initial sorting is the same as the parent's current sort pref.
  247. // **ADDED:** Custom icons and numbering for previewed directory contents.
  248. // **ADDED:** Append some server info and other provided information to the stats footer.
  249. // **NOTE** that there is an issue with Chrome and pdf files.
  250.  
  251. // **VERSION 4.0.0b**
  252. // Numerous additions, improvements, and massive internal changes. Virtually no line of code has been left untouched.
  253. // **"b" === "bugs" likely. Updates will be coming.
  254. // **IMPORTANT:** This version uses a new format for user settings in the code; you will have to re-enter your defaults manually after updating.
  255. // - Do NOT use exported settings from any earlier version of the script.
  256. // **NEW:** Added independent text editor pane.
  257. // - Invoke with Cmd/Ctrl + E, or in main menu > Text Editing > Toggle Text Editor", or under "Show Details".
  258. // - To prevent loss of work (and for convenience, e.g., to refer to a file while writing), previously entered text will not be cleared when the "New" button is clicked again, when the "Close" button is clicked, or when a sidebar item is selected.
  259. // - Use the Save button to save the text as a text or html file, which can be previewed and edited as usual by navigating to its saved location.
  260. // **ADDED:** Option to number index items, with new user setting.
  261. // **ADDED:** Stats footer in sidebar showing dir and file count.
  262. // **ADDED:** Icons for shortcuts menu to indicate local vs. remote links.
  263. // **ADDED:** Text editing: Clear button to empty text editing pane.
  264. // **CHANGED:** Text editing: Github styling customizations: Make table cells top-aligned, darker blockquote text color.
  265. // **IMPROVED:** Text editing: When saving rendered HTML, header uplinks will be removed.
  266. // **IMPROVED:** Text editing: Don't close other previewed content when making new text editing pane.
  267. // **IMPROVED:** Text editing: Much improved warning system for edited text: now uses `postMessage` to communicate between iframe and parent.
  268. // **IMPROVED:** Content display: use the same code to prep and style directory contents in the preview pane.
  269. // **IMPROVED:** Live sorting of grid items (but images and fonts are still sorted separately).
  270. // **IMPROVED:** Image zoom positioned accurately under click.
  271. // **IMPROVED:** Better handling of 404 Errors (Page not found): server error message will appear in sidebar, warning icon in content pane.
  272. // **IMPROVED:** File URLs: If a file URL (instead of a directory) is entered directly in the browser URL bar, the parent directory will be loaded instead and the file automatically selected.
  273. // **IMPROVED:** Navigation: modifed highlighting styles to show when a non-audio item is selected for navigation vs. when it is loaded in preview pane but not selected (e.g. click a directory and then click an audio file; the directory item will be dimmed).
  274. // **IMPROVED:** Audio: Greatly simplified shuffle play code and fixed several bugs; shuffle list now correctly updates when individual audio tracks are checked or unchecked.
  275. // **CHANGED:** Moved scale buttons and prev/next image buttons to preview title bar.
  276. // **CHANGED:** Sort by "Name" always sorts files and directories together; "Default" sort always keeps files and directories separate.
  277. // **FIXED:** Text editing: Some issues with split-pane resizing.
  278. // **FIXED:** Cmd/Ctr+W (close) should work now: previewed content will be closed first, then audio, then the browser tab itself.
  279. // **FIXED:** Don't autoload audio cover art when next audio track begins; i.e., leave open whatever file is being previewed, including cover art or lyrics.
  280. // **FIXED:** An issue with sorting by size.
  281. // **FIXED:** An issue with the user UI font setting.
  282. // **FIXED:** Navigation by typed string now correctly scrolls directory list.
  283. // **OTHER:** Many small style fixes and tweaks. Among others, make the previewed image and image grid background color light in default theme.
  284. // **INTERNAL:** Complete code overhaul.
  285. // - Completely rewrote the code that preps the served directory index for processing by the script.
  286. // - Completely rewrote and simplied the sorting code.
  287. // - Alphabetized User Settings for easier editing.
  288. // - Fixes for additional server index configurations.
  289. // – Performance improvments (e.g., removed multiple calls to various functions, reduced initial DOM manipulation, etc.).
  290. // - General code cleanup (e.g., removed unused variables and unnecessary globals, named many formerly anonymous functions, fixed numerous syntax errors, etc.).
  291. //
  292. // **STILL TO COME:**
  293. // - Dark mode for text editing.
  294. // - Additional code cleanup, and more.
  295.  
  296. // ***** GENERAL SETUP ***** //
  297.  
  298. // ************************************ //
  299. // DON'T EDIT ANYTHING BELOW THIS LINE. //
  300. // ************************************ //
  301.  
  302. // PATHS
  303. // Fix "%" error in file name; see https://stackoverflow.com/questions/7449588/why-does-decodeuricomponent-lock-up-my-browser
  304. function decodeURIComponentSafe(s) {
  305. if ( !s ) { return s; }
  306. return decodeURIComponent(s.replace(/%(?![0-9a-fA-F]{2})/g, '%25') ); // replace % with %25 if not followed by two a-f/number
  307. }
  308.  
  309. const $protocol = window.location.protocol;
  310. const $origin = $protocol +'//'+ window.location.host;
  311. const $location = decodeURIComponentSafe( [location.protocol, '//', location.host, location.pathname].join('') );
  312. const $current_dir_path = $location.replace(/[\/|_|—]/g,'/<wbr>').replace(/\\/g,'/'); // URL w/o query string for display
  313.  
  314. function escapeStr(str) { str = str.replace(/([\^\$\|\?\*\+\(\)\[])/g,'\$1'); }
  315.  
  316. // if URL is a file, change window location to parent dir, add querystring of file name; then autoload file.
  317. function loadFile() {
  318. if ( $location.slice($location.lastIndexOf('/')).indexOf('.') !== -1 && !$location.endsWith('/') && window.top === window.self ) {
  319. let $query_prefs = getQueryPrefs();
  320. $query_prefs.set( 'file', $location.slice($location.lastIndexOf('/') + 1) );
  321. window.location = $location.slice(0,$location.lastIndexOf('/') + 1) +'?'+ $query_prefs;
  322. return;
  323. }
  324. }
  325. loadFile();
  326.  
  327. // QUERY PREFS
  328. function getQueryPrefs() { return new URL(window.location).searchParams; }
  329. // set query key/value
  330. function setQuery(key, value) {
  331. let $query_prefs = getQueryPrefs();
  332. $query_prefs.set( key, value );
  333. updateQuery($query_prefs);
  334. }
  335. // get query value
  336. function getQuery(key) {
  337. let $query_prefs = getQueryPrefs();
  338. let value = '';
  339. if ( key === 'width' ) {
  340. value = ( !$query_prefs.has(key) ? 30 : Math.round(100 * $query_prefs.get('width')/window.innerWidth) ); // number string
  341. } else {
  342. value = ( $query_prefs.has(key) ? $query_prefs.get(key) : $settings[key] !== undefined ? $settings[key].toString() : '' );
  343. }
  344. return value;
  345. }
  346. // toggle query key
  347. function toggleQuery(key) {
  348. let $query_prefs = getQueryPrefs();
  349. let nonBoolPrefs = {
  350. 'theme_light':{'theme':'dark'},
  351. 'theme_dark':{'theme':'light'},
  352. 'source_text':{'default_text_view':'preview_text'},
  353. 'preview_text':{'default_text_view':'source_text'},
  354. 'sort_by_default':{'sort_by':'default'},
  355. 'sort_by_name':{'sort_by':'name'},
  356. 'sort_by_size':{'sort_by':'size'},
  357. 'sort_by_date':{'sort_by':'date'},
  358. 'sort_by_kind':{'sort_by':'kind'},
  359. 'sort_by_ext':{'sort_by':'ext'},
  360. };
  361. var value, queryValue, settingsValue;
  362. if ( nonBoolPrefs[key] !== undefined ) {
  363. value = Object.values(nonBoolPrefs[key]).toString();
  364. key = Object.keys(nonBoolPrefs[key]).toString(); // must come after value: i.e., don't redefine key before getting value
  365. if ( $settings[key] === value ) { $query_prefs.delete( key ); } else { $query_prefs.set( key, value ); }
  366. } else {
  367. queryValue = $query_prefs.get(key);
  368. settingsValue = $settings[key];
  369. value = ( queryValue === null ? settingsValue.toString() : queryValue.toString() );
  370. value = ( value === 'true' ? 'false' : 'true' );
  371. if ( ( queryValue !== null && queryValue !== settingsValue ) ) {
  372. $query_prefs.delete( key );
  373. } else {
  374. $query_prefs.set( key, value );
  375. }
  376. }
  377. updateQuery($query_prefs);
  378. }
  379. // remove query key
  380. function removeQuery(key) {
  381. let $query_prefs = getQueryPrefs();
  382. $query_prefs.delete(key);
  383. updateQuery($query_prefs);
  384. }
  385. // update query string
  386. function updateQuery(querystr) {
  387. window.history.replaceState({}, document.title, window.location.pathname +'?'+ querystr);
  388. updateParentLinks();
  389. }
  390.  
  391. // ***** SET UP UI ELEMENTS ***** //
  392.  
  393. // ***** SIDEBAR ELEMENTS ***** //
  394. const $parent_dir_menu = $('<nav id="parent_dir_menu"><a href="">&nbsp;</a></nav>');
  395. const $parents_dir_menu = $('<nav id="parents_dir_menu"><div></div></nav><ul class="menu"></ul>');
  396. const $shortcuts_menu = $('<nav id="shortcuts_menu"><div>&nbsp;</div></nav><ul id="shortcuts" class="menu"></ul>');
  397. const $show_details = $('<button class="toggle_UI_pref" id="show_details" tabindex="-1"><span>Show details</span><span>Hide details</span></button>');
  398. const $inv_checkbox = $('<label ><input class="toggle_UI_pref" type="checkbox" id="show_invisibles" for="inv_checkbox" name="inv_checkbox" tabindex="-1" />Show Invisibles</label>');
  399. const $grid_btn = $('<div id="grid_btn" tabindex="-1" title="Show Grid"><ul class="menu"><li id="show_image_grid">Show Image Grid</li><li id="show_font_grid">Show Font Grid</li></ul></div>');
  400. const $sidebar_header = $('<table id="sidebar_header"><thead><tr id="sidebar_title"><th colspan="3">INDEX OF</th></tr></thead><tbody><tr id="sidebar_menus"><td></td><td></td><td></td></tr><tr id="sidebar_buttons"><td colspan="3"></td></tr></tbody></table>');
  401. const $text_editor_item = $('<tr id="text_editor_row"><td colspan="6"><a href="#" title="Toggle Text Editor">Text Editor</a></td></tr>');
  402. const $dir_list_head = $('<thead id="thead"><tr id="theader" class="header"><th class="toggle_UI_pref name sorting" id="sort_by_name"><span><input id="play_toggle" type="checkbox" tabindex="-1" checked="true" />Name</span></th><th class="toggle_UI_pref sorting" id="sort_by_default"><span>Default</span></th><th class="toggle_UI_pref details sorting" id="sort_by_ext"><span>Ext</span></th><th class="toggle_UI_pref details sorting" id="sort_by_size"><span>Size</span></th><th class="toggle_UI_pref details sorting" id="sort_by_date"><span>Date</span></th><th class="toggle_UI_pref details sorting" id="sort_by_kind"><span>Kind</span></th></tr></thead>');
  403. const $dir_list_body = $('<tbody id="tbody"></tbody>');
  404. var $dir_list = $('<table id="dir_list"></table>');
  405. const $sidebar = $('<div id="sidebar"></div>');
  406. const $handle = $('<div id="handle"></div>');
  407. const $sidebar_wrapper = $('<td id="sidebar_wrapper"></td>');
  408. const $toggle_sidebar = $('<div id="toggle_sidebar"></div>');
  409. const $tfoot = $('<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>');
  410. const $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>');
  411. const $overlay = $('<div id="overlay"></div>');
  412.  
  413. // ***** CONTENT PANE ELEMENTS ***** //
  414. const $content_audio_title = $('<tr id="content_audio_title"><td colspan="3"></td></tr>');
  415. const $content_audio = $('<tr id="content_audio"><td colspan="3"></td></tr>');
  416. const $prev_track = $('<div id="prev_track" class="prev_next_track_btn" title="Previous track">&nbsp;</div>');
  417. const $next_track = $('<div id="next_track" class="prev_next_track_btn" title="Next track">&nbsp;</div>');
  418. const $audio_player = $('<audio id="audio" preload="auto" tabindex="0" controls >Sorry, your browser does not support HTML5 audio.</audio>');
  419. const $loop = $('<label><input type="checkbox" id="loop" for="loop" name="loop" tabindex="0" />Loop</label>');
  420. const $shuffle = $('<label><input type="checkbox" id="shuffle" for="shuffle" name="shuffle" tabindex="0" />Shuffle</label>');
  421. const $close_audio = $('<div id="close_audio" title="Close audio"></div>');
  422. const $content_grid = $('<div id="content_grid" data-grid-scale-factor="1" data-kind="grid"></div>');
  423. const $content_text = $('<div id="content_text"></div>');
  424. const $sample_string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ<br />abcdefghijklmnopqrstuvwxyz<br />0123456789 [(!@#$%^&*;:)]';
  425. const $hamburger_string = '<h1>Typography</h1><h4>The art of using types to produce impressions on paper, vellum, &amp;c.</h4><h2>S P E C I M E N</h2><h3>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><h5> </h5>';
  426. const $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.';
  427. const $specimen = $('<div class="specimen" contenteditable="true">'+ $sample_string +'</div><div class="hamburger" contenteditable="true">'+ $hamburger_string +'</div><div class="lorem first" style="font-size:1em;" contenteditable="true">'+ $lorem_string +'</div><div class="lorem" style="font-size:1em;" contenteditable="true">'+ $lorem_string +'</div><div class="lorem" style="font-size:1em;" contenteditable="true">'+ $lorem_string +'</div>');
  428. const $content_font = $('<div id="content_font" class="content" spellcheck="false" data-kind="font"></div>');
  429. const $content_image = $('<img id="content_image" class="content" data-kind="image" />');
  430. const $content_video = $('<video id="content_video" class="content media" controls data-kind="video">Your browser does not support the video tag.</video>');
  431. const $content_pdf = $('<embed id="content_pdf" class="content" name="plugin" tabindex="0" data-kind="pdf"></embed>');
  432. // if ( navigator.userAgent.indexOf('Chrome') > -1 ) { $content_pdf.attr('type','application/x-google-chrome-pdf'); }
  433. const $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>');
  434. const $checkbox_cont = $('<div id="checkbox_div"></div>');
  435. const $title_buttons_left = $('<td id="title_buttons_left"><button id="reload_btn" tabindex="-1">Reload</button><button id="prev_next_btns" class="split_btn"><span id="prev_btn">&nbsp;</span><span id="next_btn">&nbsp;</span></button></td>');
  436. // const $content_stop_btn = $('<td><button id="stop" tabindex="-1">Stop</button></td>');
  437. const $title = $('<td id="title"></td>');
  438. const $content_title = $('<tr id="content_title"></tr>');
  439. const $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">Close</button></td>');
  440. const $content_header = $('<header id="content_header"><table><tbody></tbody></table></header>');
  441. // const $prev_btn = $('<div class="nav_btn" id="prev_btn"></div>');
  442. // const $next_btn = $('<div class="nav_btn" id="next_btn"></div>');
  443. const $content_container = $('<section id="content_container"></section>');
  444. const $content_pane = $('<td id="content_pane" class=""></td>');
  445.  
  446. const $main_content = $('<table id="main_content"><thead></thead><tbody><tr></tr></tbody><tfoot></tfoot></table>');
  447.  
  448. // SVG UI ICONS
  449. const $svg_prefix = '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\' ';
  450. const $up_arrow = $svg_prefix + 'width=\'12.728px\' height=\'7.779px\' viewBox=\'0 0 12.728 7.779\' enable-background=\'new 0 0 12.728 7.779\' xml:space=\'preserve\'><path fill=\'%23444444\' d=\'M6.364,2.828l4.95,4.949l1.414-1.414L6.364,0l0,0L0,6.363l1.413,1.416L6.364,2.828\'/></svg>")';
  451. const $up_arrow_inv = $svg_prefix + 'width=\'12.728px\' height=\'7.779px\' viewBox=\'0 0 12.728 7.779\' enable-background=\'new 0 0 12.728 7.779\' xml:space=\'preserve\'><path fill=\'%23CCCCCC\' d=\'M6.364,2.828l4.95,4.949l1.414-1.414L6.364,0l0,0L0,6.363l1.413,1.416L6.364,2.828\'/></svg>")';
  452. const $svg_arrow = $svg_prefix + 'width=\'88.4px\' height=\'141.4px\' viewBox=\'0 0 88.4 141.4\' enable-background=\'new 0 0 88.4 141.4\' xml:space=\'preserve\'><polygon fill=\'%23231F20\' points=\'70.7,0 0,70.7 70.7,141.4 88.4,123.7 35.4,70.7 88.4,17.7 \'/></svg>")';
  453. const $toggle = $svg_prefix + 'width=\'13.779px\' height=\'12.729px\' viewBox=\'2.474 -2.475 13.779 12.729\' enable-background=\'new 2.474 -2.475 13.779 12.729\' xml:space=\'preserve\'> <path fill=\'%23444444\' d=\'M5.302,3.889l4.949-4.95L8.838-2.475L2.474,3.889l0,0l6.363,6.364l1.416-1.413L5.302,3.889\'/> <path fill=\'%23444444\' d=\'M11.302,3.889l4.949-4.95l-1.414-1.414L8.474,3.889l0,0l6.363,6.364l1.416-1.413L11.302,3.889\'/> </svg>")';
  454. const $check_mark = $svg_prefix + 'width=\'17px\' height=\'14px\' viewBox=\'250.182 490.01 17 14\' enable-background=\'new 250.182 490.01 16.971 14.143\' xml:space=\'preserve\'><polygon fill=\'%23444444\' points=\'255.839,498.495 253.011,495.667 250.182,498.496 255.839,504.152 267.152,492.838 264.323,490.01 \'/></svg>")';
  455. const $check_mark_inv = $svg_prefix + 'width=\'17px\' height=\'14px\' viewBox=\'250.182 490.01 17 14\' enable-background=\'new 250.182 490.01 16.971 14.143\' xml:space=\'preserve\'><polygon fill=\'%23CCCCCC\' points=\'255.839,498.495 253.011,495.667 250.182,498.496 255.839,504.152 267.152,492.838 264.323,490.01 \'/></svg>")';
  456. const $menu_arrow = $svg_prefix + 'width=\'24px\' height=\'16px\' viewBox=\'0 0 24 16\' enable-background=\'new 0 0 24 16\' xml:space=\'preserve\'> <polygon fill=\'%23444444\' points=\'0,0 13.873,8.008 0.001,16.017 \'/> </svg>")';
  457. const $menu_arrow_inv = $svg_prefix + 'width=\'24px\' height=\'16px\' viewBox=\'0 0 24 16\' enable-background=\'new 0 0 24 16\' xml:space=\'preserve\'> <polygon fill=\'%23CCCCCC\' points=\'0,0 13.873,8.008 0.001,16.017 \'/> </svg>")';
  458. const $menu_icon = $svg_prefix + 'width=\'13px\' height=\'10px\' viewBox=\'0 0 13 10\' enable-background=\'new 0 0 13 10\' xml:space=\'preserve\'><rect fill=\'%23444444\' width=\'13\' height=\'2\'/><rect y=\'4\' fill=\'%23444444\' width=\'13\' height=\'2\'/><rect y=\'8\' fill=\'%23444444\' width=\'13\' height=\'2\'/></svg>")';
  459. const $grid_icon = $svg_prefix + 'width=\'16px\' height=\'16px\' viewBox=\'0 0 16 16\' enable-background=\'new 0 0 16 16\' xml:space=\'preserve\'><g><path fill=\'%23666666\' d=\'M5,2v3H2V2H5 M7,0H0v7h7V0L7,0z\'/></g><g><path fill=\'%23666666\' d=\'M14,2v3h-3V2H14 M16,0H9v7h7V0L16,0z\'/></g><g><path fill=\'%23666666\' d=\'M5,11v3H2v-3H5 M7,9H0v7h7V9L7,9z\'/></g><g><path fill=\'%23666666\' d=\'M14,11v3h-3v-3H14 M16,9H9v7h7V9L16,9z\'/></g></svg>")';
  460. const $grid_icon_inv = $svg_prefix + 'width=\'16px\' height=\'16px\' viewBox=\'0 0 16 16\' enable-background=\'new 0 0 16 16\' xml:space=\'preserve\'><g><path fill=\'%23CCCCCC\' d=\'M5,2v3H2V2H5 M7,0H0v7h7V0L7,0z\'/></g><g><path fill=\'%23CCCCCC\' d=\'M14,2v3h-3V2H14 M16,0H9v7h7V0L16,0z\'/></g><g><path fill=\'%23CCCCCC\' d=\'M5,11v3H2v-3H5 M7,9H0v7h7V9L7,9z\'/></g><g><path fill=\'%23CCCCCC\' d=\'M14,11v3h-3v-3H14 M16,9H9v7h7V9L16,9z\'/></g></svg>")';
  461. const $plus_sign = $svg_prefix + 'width=\'16px\' height=\'16px\' viewBox=\'0 0 16 16\' xml:space=\'preserve\'><polygon points=\'16,6.5 9.5,6.5 9.5,0 6.5,0 6.5,6.5 0,6.5 0,9.5 6.5,9.5 6.5,16 9.5,16 9.5,9.5 16,9.5 \'/></svg>")';
  462. const $minus_sign = $svg_prefix + 'width=\'16px\' height=\'16px\' viewBox=\'0 0 16 16\' xml:space=\'preserve\'> <rect x=\'1\' y=\'6.499\' width=\'14\' height=\'3.001\'/> </svg>")';
  463. const $next_track_arrow = $svg_prefix + 'width=\'12.8px\' height=\'14px\' viewBox=\'-2 0 12.8 14\' enable-background=\'new -2 0 12.8 14\' xml:space=\'preserve\'><polygon fill=\'%23919191\' points=\'10.873,14.017 0,7.01 10.872,0 \'/><rect x=\'-2\' y=\'0\' fill=\'%23919191\' width=\'2\' height=\'14\'/></svg>")';
  464. const $next_track_arrow_gecko = $svg_prefix + 'width=\'12.8px\' height=\'14px\' viewBox=\'-2 0 12.8 14\' enable-background=\'new -2 0 12.8 14\' xml:space=\'preserve\'><polygon fill=\'white\' points=\'10.873,14.017 0,7.01 10.872,0 \'/><rect x=\'-2\' y=\'0\' fill=\'white\' width=\'2\' height=\'14\'/></svg>")';
  465. const $next_track_arrow_gecko_hover = $svg_prefix + 'width=\'12.8px\' height=\'14px\' viewBox=\'-2 0 12.8 14\' enable-background=\'new -2 0 12.8 14\' xml:space=\'preserve\'><polygon fill=\'%236bb5ff\' points=\'10.873,14.017 0,7.01 10.872,0 \'/><rect x=\'-2\' y=\'0\' fill=\'%236bb5ff\' width=\'2\' height=\'14\'/></svg>")';
  466. const $music = $svg_prefix + 'width=\'143.717px\' height=\'199.404px\' viewBox=\'0 0 143.717 199.404\' enable-background=\'new 0 0 143.717 199.404\' xml:space=\'preserve\'><g opacity=\'0.2\'> <path fill=\'%23757679\' d=\'M143.717,143.82c0,10.033-4.573,18.425-13.717,25.183c-8.394,6.143-17.776,9.211-28.149,9.211 c-6.074,0-11.056-1.432-14.943-4.297c-4.301-3.275-6.45-7.849-6.45-13.719c0-9.279,4.403-17.438,13.204-24.466 c8.326-6.616,17.266-9.93,26.82-9.93c8.052,0,13.922,1.605,17.606,4.812V25.487L63.26,45.654v119.354 c0,10.03-4.573,18.427-13.717,25.181c-8.394,6.142-17.778,9.215-28.148,9.215c-6.077,0-11.055-1.437-14.947-4.302 C2.151,191.827,0,187.253,0,181.386c0-9.282,4.401-17.436,13.206-24.465c8.323-6.615,17.262-9.929,26.817-9.929 c8.051,0,13.921,1.605,17.606,4.812V23.237L143.717,0V143.82z\'/></g></svg>")';
  467. const $error_icon = $svg_prefix + 'viewBox=\'0 0 512 512\' enable-background=\'new 0 0 512 512\' xml:space=\'preserve\'><g id=\'Layer_2\'> <path fill=\'%23FFB636\' fill-opacity=\'0.75\' d=\'M12.51,470.379L234.371,16.008c6.439-13.187,25.17-13.363,31.855-0.299l232.51,454.371 c6.064,11.849-2.542,25.92-15.853,25.92H28.512C15.348,496,6.734,482.209,12.51,470.379z\'/></g><g id=\'Layer_3\'> <path fill=\'%23444444\' fill-opacity=\'0.75\' d=\'M284.332,173L272.15,336.498c-0.911,12.233-11.567,21.411-23.8,20.499 c-11.116-0.828-19.706-9.707-20.499-20.499L215.668,173c-1.413-18.961,12.813-35.478,31.774-36.89s35.478,12.813,36.89,31.774 C284.456,169.546,284.441,171.384,284.332,173z M250,391.873c-17.432,0-31.564,14.131-31.564,31.564 C218.436,440.869,232.568,455,250,455s31.564-14.131,31.564-31.564C281.564,406.004,267.432,391.873,250,391.873z\'/></g></svg>")';
  468. const $bookmark_icon = $svg_prefix + 'width=\'20px\' height=\'20px\' viewBox=\'0 0 20 20\' enable-background=\'new 0 0 20 20\' xml:space=\'preserve\'><title>bookmark outlined</title><path fill=\'%23555555\' d=\'M3,1v18l7-5l7,5V1H3z M10,11.14l-4.5,3.15V3.5h9v10.79L10,11.14z\'/></svg>")';
  469. const $bookmark_icon_dark = $svg_prefix + 'width=\'20px\' height=\'20px\' viewBox=\'0 0 20 20\' enable-background=\'new 0 0 20 20\' xml:space=\'preserve\'><title>bookmark outlined</title><path fill=\'%23AAAAAA\' d=\'M3,1v18l7-5l7,5V1H3z M10,11.14l-4.5,3.15V3.5h9v10.79L10,11.14z\'/></svg>")';
  470. // const $spinner = $svg_prefix + ' width=\'40px\' height=\'40px\' viewBox=\'-1 -1 40 40\' style=\'enable-background:new -1 -1 40 40;\' xml:space=\'preserve\'><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>")';
  471. //SVG FILE ICONS
  472. // Chrome default icons
  473. const $file_icon_dir_default = '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= ")';
  474. const $file_icon_file_default = 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAABHUlEQVR42o2RMW7DIBiF3498iHRJD5JKHurL+CRVBp+i2T16tTynF2gO0KSb5ZrBBl4HHDBuK/WXACH4eO9/CAAAbdvijzLGNE1TVZXfZuHg6XCAQESAZXbOKaXO57eiKG6ft9PrKQIkCQqFoIiQFBGlFIB5nvM8t9aOX2Nd18oDzjnPgCDpn/BH4zh2XZdlWVmWiUK4IgCBoFMUz9eP6zRN75cLgEQhcmTQIbl72O0f9865qLAAsURAAgKBJKEtgLXWvyjLuFsThCSstb8rBCaAQhDYWgIZ7myM+TUBjDHrHlZcbMYYk34cN0YSLcgS+wL0fe9TXDMbY33fR2AYBvyQ8L0Gk8MwREBrTfKe4TpTzwhArXWi8HI84h/1DfwI5mhxJamFAAAAAElFTkSuQmCC ")';
  475. // Custom file icons
  476. const $svg_icon_prefix = '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=\'14px\' height=\'14px\' viewBox=\'0 0 14 14\' enable-background=\'new 0 0 14 14\' xml:space=\'preserve\'> ';
  477. const $file_icon_dir = $svg_icon_prefix + '<polygon fill=\'%233399FF\' points=\'6.1,2.7 4.8,1 0,1 0,13 14,13 14,2.7 \'/> <rect x=\'1.5\' y=\'4.2\' fill=\'%2399CCFF\' width=\'11\' height=\'7.3\'/> </svg> ")';
  478. const $file_icon_dir_invisible = $svg_icon_prefix + '<polygon fill=\'%23888888\' points=\'6.1,2.7 4.8,1 0,1 0,13 14,13 14,2.7 \'/> <rect x=\'1.5\' y=\'4.2\' fill=\'%23BBBBBB\' width=\'11\' height=\'7.3\'/> <circle fill=\'%23888888\' cx=\'7\' cy=\'7.9\' r=\'1\'/> </svg> ")';
  479. const $file_icon_app = $svg_icon_prefix + '<g> <polygon style=\'fill:%230066FF;\' points=\'14,0 0,0 0,14 14,14 \'/> </g> <path style=\'fill:%23FFFFFF;\' d=\'M6.466,3.696L5.854,3.421c-0.175-0.078-0.381,0.003-0.455,0.18L5.086,4.348l1.241,0.578l0.315-0.791 C6.71,3.965,6.632,3.771,6.466,3.696z\'/> <polygon style=\'fill:%23FFFFFF;\' points=\'4.955,4.663 2.755,9.922 4.091,10.544 6.201,5.243 \'/> <polygon style=\'fill:%23FFFFFF;\' points=\'2.625,10.237 2.563,12.166 3.955,10.856 \'/> <polygon style=\'fill:%23FFFFFF;\' points=\'9.998,6.663 10.569,8.027 13.143,8.027 13.143,6.663 \'/> <path style=\'fill:%23FFFFFF;\' d=\'M9.838,7.164L7.594,1.797C7.52,1.619,7.314,1.538,7.139,1.616L6.527,1.893 C6.36,1.968,6.282,2.16,6.35,2.329l2.17,5.449L9.838,7.164z\'/> <polygon style=\'fill:%23FFFFFF;\' points=\'9.97,7.479 8.646,8.096 9.021,9.035 10.367,8.43 \'/> <path style=\'fill:%23FFFFFF;\' d=\'M10.479,8.753l-1.3,0.585L9.178,9.339c-0.041,0.311-0.073,0.736,0.073,1.07 c0.35,0.798,1.045,1.264,0.923,1.959c0,0,0.887-1.152,0.989-1.896C11.286,9.579,10.82,9.05,10.479,8.753z\'/> <polygon style=\'fill:%23FFFFFF;\' points=\'5.459,8.027 8.251,8.027 7.708,6.663 6.003,6.663 \'/> <polygon style=\'fill:%23FFFFFF;\' points=\'3.749,6.663 0.857,6.663 0.857,8.027 3.178,8.027 \'/> </svg> ")';
  480. const $file_icon_file = $svg_icon_prefix + '<g> <polygon fill=\'%23888888\' points=\'8.3,0 1.5,0 1.5,14 12.5,14 12.5,4.2 \'/> <polygon fill=\'%23FFFFFF\' points=\'11,12.5 3,12.5 3,1.5 6.8,1.5 6.8,5.7 11,5.7 \'/> <polygon fill=\'%23FFFFFF\' points=\'8.3,4.2 10.2,4.2 8.3,2.2 \'/> </g> </svg> ")';
  481. const $file_icon_text = $svg_icon_prefix + '<g> <polygon style=\'fill:%238888AA;\' points=\'14,0 0,0 0,14 14,14 \'/> </g> <g> <rect x=\'2.155\' y=\'2.187\' style=\'fill:%23FFFFFF;\' width=\'9.69\' height=\'1.14\'/> </g> <g> <rect x=\'2.155\' y=\'5.036\' style=\'fill:%23FFFFFF;\' width=\'9.69\' height=\'1.14\'/> </g> <g> <rect x=\'2.155\' y=\'7.886\' style=\'fill:%23FFFFFF;\' width=\'9.69\' height=\'1.141\'/> </g> <g> <rect x=\'2.155\' y=\'10.736\' style=\'fill:%23FFFFFF;\' width=\'6.555\' height=\'1.14\'/> </g> </svg> ")';
  482. const $file_icon_image = $svg_icon_prefix + '<g id=\'Layer_2\'> </g> <circle fill=\'%23FFEE22\' cx=\'5.5\' cy=\'3.2\' r=\'1.5\'/> <g> <path fill=\'%23FFFFFF\' d=\'M5.6,7.5L3.8,6L0.2,8.7c0.1,0.6,0.6,1.5,0.5,1.3l3-2.4L5.6,9l4.7-4l3.6,3.2l0,0C14,7.8,14,7.4,14,7 c0-0.1,0-0.3,0-0.4l-3.6-3.2L5.6,7.5z\'/> </g> <path fill=\'%2399AADD\' d=\'M3.8,6l1.8,1.5l4.8-4.1L14,6.6C13.8,2.9,10.7,0,7,0C3.1,0,0,3.1,0,7c0,0.6,0.1,1.2,0.2,1.7L3.8,6z\'/> <path fill=\'%233366CC\' d=\'M10.3,5L5.6,9L3.7,7.6l-3,2.4c1.1,2.4,3.5,4,6.3,4c3.4,0,6.3-2.5,6.9-5.8L10.3,5z\'/> <circle fill=\'%23FFE650\' cx=\'5.5\' cy=\'3.2\' r=\'1.5\'/> </svg> ")';
  483. const $file_icon_pdf = $svg_icon_prefix + '<g> <polygon style=\'fill:%23D84444;\' points=\'14,0 0,0 0,14 14,14 14,0 \'/> </g> <path style=\'fill:%23FFFFFF;\' d=\'M12.634,9.094c-0.074,0.047-0.288,0.075-0.423,0.075c-0.439,0-0.981-0.202-1.745-0.529 c0.294-0.022,0.562-0.031,0.803-0.031c0.441,0,0.569,0,1.002,0.108C12.7,8.824,12.705,9.047,12.634,9.094z M4.99,9.162 c0.17-0.3,0.345-0.616,0.521-0.952c0.435-0.822,0.712-1.469,0.914-1.997c0.409,0.742,0.917,1.37,1.51,1.876 C8.011,8.151,8.09,8.212,8.174,8.276C6.962,8.519,5.914,8.809,4.99,9.162z M6.404,1.383c0.241,0,0.38,0.606,0.391,1.179 c0.011,0.568-0.12,0.965-0.287,1.265c-0.14-0.441-0.203-1.129-0.203-1.581C6.305,2.245,6.295,1.383,6.404,1.383z M1.663,12.3 c0.14-0.374,0.68-1.113,1.479-1.771c0.051-0.037,0.175-0.155,0.289-0.263C2.596,11.603,2.033,12.133,1.663,12.3z M12.864,8.31 c-0.24-0.238-0.781-0.363-1.599-0.373c-0.555-0.008-1.218,0.041-1.923,0.138C9.03,7.893,8.707,7.697,8.451,7.459 c-0.683-0.64-1.25-1.524-1.606-2.497c0.021-0.094,0.044-0.171,0.062-0.253c0,0,0.383-2.186,0.28-2.925 c-0.015-0.104-0.021-0.131-0.05-0.21L7.104,1.486c-0.103-0.241-0.31-0.497-0.633-0.483L6.283,0.997H6.28 c-0.358,0-0.654,0.184-0.729,0.456c-0.233,0.864,0.007,2.15,0.444,3.818L5.882,5.544c-0.312,0.76-0.704,1.527-1.048,2.203 L4.787,7.836c-0.362,0.71-0.693,1.315-0.99,1.825l-0.31,0.165c-0.021,0.014-0.551,0.292-0.675,0.367 c-1.053,0.628-1.752,1.343-1.868,1.91c-0.037,0.179-0.009,0.41,0.178,0.52l0.299,0.148c0.129,0.064,0.269,0.096,0.406,0.096 c0.75,0,1.621-0.931,2.817-3.023c1.387-0.452,2.965-0.828,4.347-1.035c1.052,0.595,2.346,1.006,3.163,1.006 c0.146,0,0.271-0.013,0.373-0.042c0.155-0.04,0.288-0.129,0.369-0.254c0.156-0.235,0.191-0.563,0.146-0.901 C13.032,8.519,12.95,8.395,12.864,8.31z\'/> </svg> ")';
  484. const $file_icon_font = $svg_icon_prefix + '<g><polygon style=\'fill:%23770099;\' points=\'14,0 0,0 0,14 14,14 \'/></g><g><path style=\'fill:%23FFFFFF;\' d=\'M4.599,11.321h1.44V2.774H3.334v1.088H1.83V1.222h10.34v2.641h-1.505V2.774H7.977v8.547h1.393v1.457 H4.599V11.321z\'/></g></svg>")';
  485. const $file_icon_code = $svg_icon_prefix + '<g> <polygon style=\'fill:%237722DD;\' points=\'14,0 0,0 0,14 14,14 \'/> </g> <g> <path style=\'fill:%23FFFFFF;\' d=\'M5.892,12.965c-1.049,0-1.784-0.161-2.209-0.48c-0.425-0.317-0.638-0.82-0.638-1.503V8.915 c0-0.446-0.146-0.764-0.438-0.95C2.315,7.777,1.898,7.684,1.351,7.684V6.316c0.547,0,0.967-0.094,1.259-0.28s0.438-0.5,0.438-0.938 V3.006c0-0.675,0.217-1.172,0.65-1.491C4.13,1.195,4.862,1.036,5.893,1.036v1.312c-0.401,0.01-0.718,0.09-0.952,0.24 c-0.233,0.15-0.348,0.426-0.348,0.827V5.4c0,0.876-0.511,1.396-1.532,1.559v0.083c1.021,0.154,1.532,0.67,1.532,1.544v1.997 c0,0.41,0.116,0.688,0.349,0.835c0.233,0.146,0.55,0.223,0.951,0.232L5.892,12.965L5.892,12.965z\'/> <path style=\'fill:%23FFFFFF;\' d=\'M8.045,12.965v-1.313c0.392-0.009,0.706-0.089,0.944-0.239c0.236-0.15,0.355-0.426,0.355-0.829 V8.588c0-0.867,0.511-1.382,1.531-1.545V6.959C9.855,6.795,9.345,6.28,9.345,5.413V3.416c0-0.41-0.116-0.688-0.349-0.834 C8.764,2.436,8.447,2.358,8.045,2.349V1.036c1.049,0,1.785,0.159,2.21,0.479c0.423,0.319,0.637,0.821,0.637,1.505v2.065 c0,0.447,0.146,0.765,0.438,0.951c0.292,0.187,0.711,0.28,1.257,0.28v1.367c-0.546,0.012-0.967,0.107-1.259,0.287 C11.035,8.153,10.89,8.47,10.89,8.915v2.08c0,0.674-0.217,1.172-0.65,1.491C9.808,12.805,9.075,12.965,8.045,12.965z\'/> </g> </svg>")';
  486. const $file_icon_html = $svg_icon_prefix + '<path style=\'fill:%23FFFFFF;\' d=\'M7,14c-3.9,0-7-3.1-7-7C0,3.2,3.1,0,7,0H7C8.9,0,10.6,0.7,12,2C13.3,3.4,14,5.1,14,7 c0,1.9-0.7,3.6-2,5C10.7,13.3,8.9,14,7,14C7,14,7,14,7,14z\'/> <g> <path style=\'fill:%23EE7700;\' d=\'M5.3,1.1C4.7,1.9,4.2,2.6,3.8,3.5C3.4,3.3,3,3.1,2.6,2.8C3.3,2.1,4.2,1.5,5.3,1.1z M2,3.6 c0.5,0.3,1,0.6,1.5,0.8C3.3,5,3.2,5.6,3.1,6.3c0,0.1,0,0.2,0,0.3H0.9C1,5.4,1.4,4.4,2,3.6z M2,10.4c-0.6-0.9-1-1.9-1.1-3h2.1 c0,0.8,0.2,1.5,0.4,2.2C2.9,9.9,2.5,10.1,2,10.4z M2.6,11.2c0.4-0.3,0.8-0.5,1.2-0.6c0.3,0.8,0.8,1.5,1.4,2.2c0,0,0.1,0.1,0.1,0.1 C4.2,12.5,3.3,11.9,2.6,11.2z M6.5,12.9c-0.2-0.2-0.5-0.5-0.7-0.7c-0.5-0.6-0.9-1.3-1.2-1.9C5.3,10,5.9,9.9,6.5,9.9V12.9z M6.5,9 C5.8,9,5,9.1,4.3,9.4C4.1,8.7,4,8.1,4,7.5h2.6V9z M6.5,6.5H4c0-0.1,0-0.1,0-0.2c0.1-0.6,0.2-1.2,0.3-1.7C5.1,4.9,5.8,5,6.5,5V6.5z M6.5,4.1C5.9,4.1,5.3,4,4.7,3.8c0.4-1,1.1-1.9,1.9-2.6V4.1z M12,3.6c0.6,0.9,1,1.9,1.1,3h-2.2c0-0.8-0.2-1.5-0.4-2.2 C11,4.1,11.5,3.9,12,3.6z M11.3,2.7c0,0,0.1,0.1,0.1,0.1c-0.4,0.3-0.8,0.5-1.2,0.7C9.9,2.7,9.4,2,8.8,1.3C8.8,1.3,8.7,1.2,8.7,1.1 C9.7,1.4,10.6,2,11.3,2.7z M7.5,1.2c0.2,0.2,0.5,0.5,0.7,0.7C8.6,2.5,9,3.1,9.3,3.8C8.7,4,8.1,4.1,7.5,4.1V1.2z M7.5,5 c0.7,0,1.5-0.2,2.2-0.4C9.9,5.3,10,5.9,10,6.5H7.5V5z M7.5,7.5H10c0,0.1,0,0.2,0,0.2c0,0.6-0.2,1.1-0.3,1.7C9,9.1,8.2,9,7.5,9V7.5z M7.5,12.9v-3c0.6,0,1.3,0.1,1.9,0.3C8.9,11.2,8.3,12.1,7.5,12.9z M11.3,11.3c-0.7,0.7-1.6,1.3-2.6,1.5c0.6-0.7,1.1-1.5,1.5-2.3 c0.4,0.2,0.8,0.4,1.2,0.6C11.4,11.2,11.4,11.2,11.3,11.3z M10.5,9.7c0.2-0.6,0.3-1.2,0.4-1.9c0-0.1,0-0.2,0-0.3h2.2 c-0.1,1.1-0.4,2.1-1.1,3C11.5,10.1,11,9.9,10.5,9.7z M7,0C3.1,0,0,3.1,0,7s3.1,7,7,7s7-3.1,7-7S10.9,0,7,0z\'/> </g> </svg>")';
  487. const $file_icon_ignored = $svg_icon_prefix + '<path fill=\'%23CCCCCC\' d=\'M7,0C3.1,0,0,3.1,0,7c0,3.9,3.1,7,7,7c3.9,0,7-3.1,7-7C14,3.1,10.9,0,7,0L7,0z\'/><path fill=\'%23EEEEEE\' d=\'M7,2c2.8,0,5,2.2,5,5s-2.2,5-5,5c-2.8,0-5-2.2-5-5S4.2,2,7,2\'/><rect x=\'0.8\' y=\'5.9\' transform=\'matrix(0.7071 -0.7071 0.7071 0.7071 -2.8818 7.0063)\' fill=\'%23CCCCCC\' width=\'12.5\' height=\'2.3\'/></svg>")';
  488. const $file_icon_ignored_inv = $svg_icon_prefix + '<path fill=\'%23444444\' d=\'M7,0C3.1,0,0,3.1,0,7c0,3.9,3.1,7,7,7c3.9,0,7-3.1,7-7C14,3.1,10.9,0,7,0L7,0z\'/><path fill=\'%23555555\' d=\'M7,2c2.8,0,5,2.2,5,5s-2.2,5-5,5c-2.8,0-5-2.2-5-5S4.2,2,7,2\'/><rect x=\'0.8\' y=\'5.9\' transform=\'matrix(0.7071 -0.7071 0.7071 0.7071 -2.8818 7.0063)\' fill=\'%23444444\' width=\'12.5\' height=\'2.3\'/></svg>")';
  489. const $file_icon_invisible = $svg_icon_prefix + '<g> <polygon fill=\'%23888888\' points=\'8.3,0 1.5,0 1.5,14 12.5,14 12.5,4.2 \'/> <polygon fill=\'%23BBBBBB\' points=\'11,12.5 3,12.5 3,1.5 6.8,1.5 6.8,5.7 11,5.7 \'/> <polygon fill=\'%23BBBBBB\' points=\'8.3,4.2 10.2,4.2 8.3,2.2 \'/> </g> <circle fill=\'%23777777\' cx=\'7\' cy=\'9\' r=\'1\'/> </svg>")';
  490. const $file_icon_video = $svg_icon_prefix + '<path style=\'fill:%234D4D4D;\' d=\'M14,0v14h-0.94v-0.83h-1.68V14H2.62v-0.83H0.94V14H0V0h0.94v0.87h1.68V0h8.76v0.87h1.68V0H14z M10.5,5.15h-7v3.7h7V5.15z M10.5,0.71h-7v3.7h7V0.71z M10.5,9.59h-7v3.7h7V9.59z\'/></svg>")';
  491. const $file_icon_audio = $svg_prefix + 'width=\'143.717px\' height=\'199.404px\' viewBox=\'0 0 143.717 199.404\' enable-background=\'new 0 0 143.717 199.404\' xml:space=\'preserve\'><g opacity=\'1\'> <path fill=\'%23008888\' d=\'M143.717,143.82c0,10.033-4.573,18.425-13.717,25.183c-8.394,6.143-17.776,9.211-28.149,9.211 c-6.074,0-11.056-1.432-14.943-4.297c-4.301-3.275-6.45-7.849-6.45-13.719c0-9.279,4.403-17.438,13.204-24.466 c8.326-6.616,17.266-9.93,26.82-9.93c8.052,0,13.922,1.605,17.606,4.812V25.487L63.26,45.654v119.354 c0,10.03-4.573,18.427-13.717,25.181c-8.394,6.142-17.778,9.215-28.148,9.215c-6.077,0-11.055-1.437-14.947-4.302 C2.151,191.827,0,187.253,0,181.386c0-9.282,4.401-17.436,13.206-24.465c8.323-6.615,17.262-9.929,26.817-9.929 c8.051,0,13.921,1.605,17.606,4.812V23.237L143.717,0V143.82z\'/></g></svg>")';
  492. // const $file_icon_archive = 'url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\' viewBox=\'0 0 100 100\'><style type=\'text/css\'>.st0{fill:%23FFFFFF;}.st1{fill:%23D8A13F;}</style><rect class=\'st0\' width=\'100\' height=\'100\'/><path class=\'st1\' d=\'M100 100H0V0h100V100zM9.7 90h80.7V10H9.7\'/><path class=\'st1\' d=\'M72.4 38.5h-7.9v-7.9L72.4 38.5zM51.1 30.6v28.8h21.4v-19h-9.9v-9.9H51.1zM54.4 23H30.8v5.6h9.3l-5.9 4.5v4.8l8.6-6.6v-2.7h30.1v-2.3L54.4 23zM42.9 35.1l-8.6 6.6v4.8l8.6-6.6V35.1zM34.2 55.1l8.6-6.6v-4.8l-8.6 6.6V55.1zM42.9 57.1v-4.8l-8.6 6.6v2.6h-3.4v5.6h5.3v3.8H33c-0.6-1-1.6-1.6-2.8-1.6 -1.8 0-3.2 1.4-3.2 3.2s1.4 3.2 3.2 3.2c1.2 0 2.2-0.6 2.8-1.6h3.1V77h4.8v-2.9H44c0.6 1 1.6 1.6 2.8 1.6 1.8 0 3.2-1.4 3.2-3.2s-1.4-3.2-3.2-3.2c-1.2 0-2.2 0.6-2.8 1.6h-3.1v-3.8h13.5l18.5-3.3v-2.3H37.1L42.9 57.1z\'/></svg>")';
  493.  
  494. // Assemble UI Elements
  495. function assembleUIElements() {
  496. $parents_dir_menu.find('div').append( $current_dir_path );
  497. $sidebar_header.find('thead th');
  498. $sidebar_header.find('tbody tr').first().find('td').first().append( $parent_dir_menu ).next().append( $parents_dir_menu ).next().append( $shortcuts_menu );
  499. $sidebar_header.find('tbody tr:last-child td').append( $show_details, $inv_checkbox, $grid_btn );
  500. $dir_list_head.append($text_editor_item);
  501. $dir_list.append($dir_list_head, $dir_list_body, $tfoot);
  502. $sidebar.append($sidebar_header, $dir_list);
  503. $sidebar_wrapper.append( $sidebar, $handle, $toggle_sidebar );
  504. // content pane items
  505. $checkbox_cont.append( $loop, $shuffle );
  506. $content_audio.find('td').append( $prev_track, $next_track, $audio_player, $close_audio, $checkbox_cont );
  507. $content_title.append($title_buttons_left, $title, $title_buttons_right);
  508. $content_header.find('tbody').append( $content_title, $content_audio_title, $content_audio );
  509. $content_font.append( $specimen );
  510. $content_container.append( $content_grid, $content_text, $content_font, $content_image, $content_pdf, $content_video, $content_iframe );
  511. $content_pane.append( $content_header, $content_container );
  512. $main_content.find('thead').append($warnings, $overlay);
  513. }
  514.  
  515. //***** STYLES *****//
  516.  
  517. // DEFINE STYLES
  518. var $main_style_rules =
  519. // Align-content
  520. '#content_pane.has_image #content_container' + //body.theme_light #dir_list .selected.audio,
  521. '{ align-items: center; justify-content: center; }' +
  522. // BACKGROUND: COLOR
  523. '#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' +
  524. '{ background-color: lightgray }' +
  525. 'body.theme_light #dir_list tr.selected:not(.playing)' + //body.theme_light #dir_list .selected.audio,
  526. '{ background-color: lightsteelblue !important; }' +
  527. 'body.theme_light #dir_list tr.loaded:not(.selected)' + //body.theme_light #dir_list .selected.audio,
  528. '{ background-color: rgba(69%,77%,87%,0.75); }' +
  529. 'body.theme_light #dir_list tr.loaded:hover' + //body.theme_light #dir_list .selected.audio,
  530. '{ background-color: rgba(69%,77%,87%,1) !important; }' +
  531. '#content_pane.has_grid .image_grid_item::after' + //body.theme_light #dir_list .selected.audio,
  532. '{ background-color: gray; }' +
  533. 'body.theme_dark #dir_list tr.selected:not(.playing)' +
  534. '{ background-color: slategray !important; }' +
  535. 'body.theme_dark #dir_list tr.loaded:not(.selected)' +
  536. '{ background-color: rgba(44%,50%,56%,0.5); }' +
  537. 'body.theme_dark #dir_list tr.loaded:hover' +
  538. '{ background-color: rgba(44%,50%,56%,1) !important; }' +
  539. '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' +
  540. '{ background-color: #262626; }' +
  541. 'body.theme_dark #content_grid > div, body.theme_dark #content_pane.has_image, body.theme_dark #content_font, body.theme_dark #content_pane, body.theme_dark #content_pane.has_grid #content_grid::after, .split_btn::after' +
  542. '{ background-color: #333; }' +
  543. '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(.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)' +
  544. '{ background-color: #444; }' +
  545. 'body.theme_dark #sidebar, body.theme_dark #dir_list #tbody, body.theme_dark #grid_btn .menu li, 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' +
  546. '{ background-color: #555; }' +
  547. 'body.theme_dark #sidebar ul li:not(#preview_text_menu_item):hover, body.theme_dark #preview_text_menu_item span:hover, body.theme_dark #preview_text:hover, body.theme_dark #source_text:hover' +
  548. '{ background-color: #666; }' +
  549. 'body.theme_dark #sidebar .hovered, body.theme_dark #grid_btn .menu li:hover, body.theme_dark #dir_list tbody tr:hover, body.theme_dark #dir_list tbody li: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^="/"]' +
  550. '{ background-color: #777; }' +
  551. 'body.theme_light #sidebar_header thead tr, body.theme_light #sidebar_menus, #parents_dir_menu + ul li:hover, #shortcuts_menu + ul li:not(.has_submenu):not(#preview_text_menu_item):hover, body.theme_light #preview_text_menu_item span:hover, body.theme_light #preview_text:hover, body.theme_light #source_text:hover, #grid_btn.has_images.has_fonts:hover .menu li:hover, body.theme_light #dir_list tbody tr:hover, body.theme_light.alternate_background #dir_list #tbody tr:hover, body.theme_light #dir_list .hovered, body.theme_light.alternate_background #dir_list #tbody tr.hovered' +
  552. '{ background-color: #BBB; }' +
  553. '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)' +
  554. '{ background-color: #CCC; }' +
  555. 'body.theme_light #dir_list tbody' +
  556. '{ background-color: #DFDFDF; }' +
  557. 'body.theme_light #content_pane.has_image, body.theme_light #content_grid > div, #warnings, body.theme_light #content_pane.has_grid #content_grid::after, body.theme_light #content_pane.has_grid .image_grid_item::after' +
  558. '{ background-color: #EEE; }' +
  559. 'body.theme_light #content_pane, body.theme_light #content_grid, body.theme_light #content_grid div.selected, #content_font, #content_iframe, #scale, body.is_chrome #audio:focus, body.theme_light #content_grid div:hover, body.theme_light #content_grid div.hovered' +
  560. '{ background-color: #FFF; }' +
  561. // EXCLUDED: Prevent previewed files with these extensions from being inverted in dark mode
  562. //for ( i = 0; i < $row_settings.exclude.length; i += 1) {
  563. // 'body.theme_dark #content_iframe[src*="'+ $row_settings.exclude[i] +'" i] { background:#FFF; filter: unset; }' +
  564. //}
  565. 'body.is_chrome #audio' +
  566. '{ background-color: rgb(241, 243, 244); }' +
  567. 'body.theme_light #dir_list .playing, body.theme_light.has_text #text_editor_row, body.theme_light.edited #text_editor_row' +
  568. '{ background-color: #99bebf; }' +
  569. 'body.theme_dark #dir_list .playing, body.theme_dark.alternate_background #dir_list tbody tr.playing:nth-of-type(odd), body.theme_dark.has_text #text_editor_row, body.theme_dark.edited #text_editor_row' + //body.theme_dark #dir_list .selected.audio,
  570. '{ background-color: #4C7E80; }' +
  571. '#dir_list tbody tr, #dir_list .audio a, #dir_list .video a, body.has_audio #content_pane.has_ignored, body #dir_list tr.file.audio a.icon, body #dir_list tr.file.video a.icon, body.use_custom_icons #dir_list tr.file.ignore a.icon' +
  572. '{ background-color: transparent; }' +
  573. '#warnings button:focus,#warnings button.focus' +
  574. '{ background: #0E4399; }' +
  575.  
  576. // BACKGROUND: SVG IMAGES & ICONS
  577. '#parent_dir_menu a { background:' + $up_arrow + ' center no-repeat; }' +
  578. '#shortcuts_menu div { background:'+ $menu_icon + ' center no-repeat; }' +
  579. 'body.theme_light .bookmarks > a { background:'+ $bookmark_icon +' 4px no-repeat; background-size: 12px; }' +
  580. 'body.theme_dark .bookmarks > a { background:'+ $bookmark_icon_dark +' 4px no-repeat; background-size: 12px; }' +
  581. 'body.theme_light #shortcuts > li.has_submenu { background:'+ $menu_arrow +' right no-repeat; background-size: 12px; }' +
  582. 'body.theme_light #shortcuts > li.has_submenu:hover { background:#BBB '+ $menu_arrow +' right no-repeat; background-size: 12px; }' +
  583. 'body.theme_dark #shortcuts > li.has_submenu { background:'+ $menu_arrow_inv +' right no-repeat; background-size: 12px; }' +
  584. 'body.theme_dark #shortcuts > li.has_submenu:hover { background:#666 '+ $menu_arrow_inv +' right no-repeat; background-size: 12px; }' +
  585. 'body.theme_light.sort_by_default #sort_by_default span::before, body.theme_light.sort_by_name #sort_by_name span::before, body.theme_light.sort_by_size #sort_by_size span::before, body.theme_light.sort_by_date #sort_by_date span::before, body.theme_light.sort_by_kind #sort_by_kind span::before, body.theme_light.sort_by_ext #sort_by_ext span::before, body.theme_light.sort_by_default #default, body.theme_light.sort_by_name #name, body.theme_light.sort_by_size #size, body.theme_light.sort_by_date #date, body.theme_light.sort_by_kind #kind, body.theme_light.sort_by_ext #ext, body.theme_light #theme span, body.theme_light.alternate_background #alternate_background span, body.theme_light.show_numbers #show_numbers span, body.theme_light.autoload_media #autoload_media span, body.theme_light.split_view #split_view_menu_item, body.theme_light.split_view #split_view, body.theme_light:not(.enable_text_editing) #enable_text_editing, body.theme_light.source_text #source_text, body.theme_light.preview_text #preview_text { background:'+ $check_mark +' 5px center no-repeat; background-size:10px; }' +
  586. 'body.theme_dark.sort_by_default #sort_by_default span::before, body.theme_dark.sort_by_name #sort_by_name span::before, body.theme_dark.sort_by_size #sort_by_size span::before, body.theme_dark.sort_by_date #sort_by_date span::before, body.theme_dark.sort_by_kind #sort_by_kind span::before, body.theme_dark.sort_by_ext #sort_by_ext span::before, body.theme_dark.sort_by_default #default, body.theme_dark.sort_by_name #name, body.theme_dark.sort_by_size #size, body.theme_dark.sort_by_date #date, body.theme_dark.sort_by_kind #kind, body.theme_dark.sort_by_ext #ext, body.theme_dark #theme span, body.theme_dark.alternate_background #alternate_background span, body.theme_dark.show_numbers #show_numbers span, body.theme_dark.autoload_media #autoload_media span, body.theme_dark.split_view #split_view_menu_item, body.theme_dark.split_view #split_view, body.theme_dark:not(.enable_text_editing) #enable_text_editing, body.theme_dark.source_text #source_text, body.theme_dark.preview_text #preview_text { background:'+ $check_mark_inv +' 5px center no-repeat; background-size:10px; }' +
  587. 'body #grid_btn { background:'+ $grid_icon +' right 6px top 0 no-repeat; }' +
  588. 'body.theme_light.has_images.has_fonts #grid_btn:hover .menu { background: #DDD '+ $grid_icon +' right 6px top 6px no-repeat; }' +
  589. 'body.theme_dark.has_images.has_fonts #grid_btn:hover .menu { background: #555 '+ $grid_icon_inv +' right 6px top 6px no-repeat; }' +
  590. '#toggle_sidebar, #toggle_info { background:'+ $toggle +' center no-repeat; background-size:12px; }' +
  591. // 'body.theme_light #dir_list thead th.checked span::before { background-image:'+ $check_mark +'; background-repeat: no-repeat; background-size:10px; background-position: center; }' +
  592. // 'body.theme_dark #dir_list thead th.checked span::before { background-image:'+ $check_mark_inv +'; background-repeat: no-repeat; background-size:10px; background-position: center; }' +
  593. 'body.theme_light.sort_by_default #sort_by_default span::after, body.theme_light.sort_by_name #sort_by_name span::after, body.theme_light.sort_by_size #sort_by_size span::after, body.theme_light.sort_by_date #sort_by_date span::after, body.theme_light.sort_by_kind #sort_by_kind span::after, body.theme_light.sort_by_ext #sort_by_ext span::after { background-image:'+ $up_arrow +'; background-repeat: no-repeat; background-size:10px; background-position: center; }' +
  594. 'body.theme_dark.sort_by_default #sort_by_default span::after, body.theme_dark.sort_by_name #sort_by_name span::after, body.theme_dark.sort_by_size #sort_by_size span::after, body.theme_dark.sort_by_date #sort_by_date span::after, body.theme_dark.sort_by_kind #sort_by_kind span::after, body.theme_dark.sort_by_ext #sort_by_ext span::after { background-image:'+ $up_arrow_inv +'; background-repeat: no-repeat; background-size:10px; background-position: center; }' +
  595. '#dir_list tbody a { background-size:auto 13px; background-position:6px 4px; }' +
  596. 'body.has_audio #content_pane:not(.has_image):not(.has_video):not(.has_ignored) { background-image: ' + $music +'; background-position: center; background-repeat: no-repeat; background-size:33.33%; }' +
  597. '#prev_track, #next_track { background: rgb(241, 243, 244) '+ $next_track_arrow +' center no-repeat; background-blend-mode:difference; }' +
  598. '#prev_track:hover, #next_track:hover, #close_audio:hover { background-blend-mode:normal; }' +
  599. '#close_audio { background:rgb(241, 243, 244); }' +
  600. '#close_audio::after { background:'+ $plus_sign +' center no-repeat; background-blend-mode:difference; background-size:14px; }' +
  601. '#decrease { background:'+ $minus_sign +' center no-repeat; background-size: 10px; }' +
  602. '#increase { background:'+ $plus_sign +' center no-repeat; background-size: 10px; }' +
  603. '#prev_btn, #next_btn { background: ' + $svg_arrow + ' 45% center no-repeat; background-size: contain; }' +
  604. 'body #content_pane.has_ignored:not(.has_grid) { background-image:'+ $file_icon_ignored +'; background-position: center; background-repeat: no-repeat; background-size:50%; }' +
  605. 'body.theme_dark #content_pane.has_ignored:not(.has_grid) { background-color:#333; background-image:'+ $file_icon_ignored_inv +'; background-position: center; background-repeat: no-repeat; background-size:50%; }' +
  606. 'body.theme_light.is_error #content_pane { background:#FFF '+ $error_icon +' center no-repeat; background-size:50%;}' +
  607. 'body.theme_dark.is_error #content_pane { background:#333 '+ $error_icon +' center no-repeat; background-size:50%;}' +
  608. // '#content_pane.has_image #content_container, #content_pane.has_pdf #content_container { background: '+ $spinner +' center no-repeat; background-size:20px; }' +
  609. // Default File Icons
  610. 'body.use_default_icons #dir_list .dir a.icon span { background:'+ $file_icon_dir_default + ' 6px 0 no-repeat; background-size:auto 13px; }' +
  611. 'body.use_default_icons #dir_list .file a.icon span { background:'+ $file_icon_file_default + ' 6px 0 no-repeat; background-size:auto 13px; }' +
  612. // Custom File Icons
  613. 'body.use_custom_icons #dir_list tr.file:not(.dir) a.icon span { background: '+ $file_icon_file +' 6px 0 no-repeat; background-size:14px 14px; }' +
  614. 'body.use_custom_icons #dir_list tr.file.audio a.icon span, body.use_custom_icons #dir_list tr.file.video a.icon span { background: transparent; }' +
  615. 'body.use_custom_icons #dir_list tr.file.font a.icon span { background: '+ $file_icon_font +' 6px 0 no-repeat; background-size:14px 14px; }' +
  616. 'body.use_custom_icons #dir_list tr.file.image a.icon span { background: '+ $file_icon_image +' 6px 0 no-repeat; background-size:14px 14px; }' +
  617. 'body.use_custom_icons #dir_list tr.file.pdf a.icon span { background: '+ $file_icon_pdf +' 6px 0 no-repeat; background-size:14px 14px; }' +
  618. 'body.use_custom_icons #dir_list tr.file[class*="htm"] a.icon span { background: '+ $file_icon_html +' 6px 0 no-repeat; background-size:14px 14px; }' +
  619. 'body.use_custom_icons #dir_list tr.file.ignore a.icon span { background: '+ $file_icon_ignored +' 6px 0 no-repeat; }' +
  620. 'body.use_custom_icons #dir_list tr.file.invisible a.icon span { background: '+ $file_icon_invisible +' 6px 0 no-repeat; background-size:14px 14px; }' +
  621. 'body.use_custom_icons #dir_list tr.dir.invisible a.icon span { background: '+ $file_icon_dir_invisible +' 6px 0 no-repeat; background-size:14px 14px; }' +
  622. 'body.use_custom_icons #dir_list tr.dir:not(.app) a.icon span { background: '+ $file_icon_dir +' 6px 0 no-repeat; background-size:14px 14px; }' +
  623. 'body.use_custom_icons #dir_list tr.app a span { background: '+ $file_icon_app +' 6px 0 no-repeat !important; background-size:14px 14px; }' +
  624. 'body.use_custom_icons #dir_list tr.file.code a.icon span { background: '+ $file_icon_code +' 6px 0 no-repeat; background-size:14px 14px }' +
  625. 'body.use_custom_icons #dir_list tr.file.text a.icon span, body.use_custom_icons #dir_list tr.file.markdown a.icon span { background: '+ $file_icon_text +' 6px 0 no-repeat; background-size:14px 14px }' +
  626. // shortcuts icons
  627. '#shortcuts ul a { background: '+ $file_icon_file +' 8px center no-repeat; background-size:14px 14px }' +
  628. '#shortcuts ul a[href^="file"] { background: '+ $file_icon_dir +' 8px center no-repeat; background-size:14px 14px }' +
  629. '#shortcuts ul a[href^="http"] { background: '+ $file_icon_html +' 8px center no-repeat; background-size:14px 14px }' +
  630. // BORDERS
  631. ':root, html, body, #sidebar_wrapper, #sidebar_header, #dir_list, #main_content, #content_pane, #content_pdf, #content_iframe' +
  632. '{ border: 0 !important; }' +
  633. 'body.theme_dark ul' +
  634. '{ border: solid 1px #222; }' +
  635. 'button' +
  636. '{ border: solid 1px #333; }' +
  637. 'body.theme_light #sidebar ul' +
  638. '{ border: solid 1px gray; }' +
  639. // border-top
  640. 'body.theme_dark #sidebar_header .menu, body.theme_dark #grid_btn ul.menu, body.theme_dark #text_editor_row, body.theme_dark:not(.is_error) #dir_list #tbody, body.theme_dark #tfoot' +
  641. '{ border-top:solid 1px #111; }' +
  642. 'body.theme_light #dir_list tbody, #grid_btn .menu, body.theme_light #shortcuts, body.theme_light #text_editor_row, #tfoot, .font_grid_item:not(:first-of-type), .image_grid_item + .font_grid_item' +
  643. '{ border-top:solid 1px grey; }' +
  644. '#sort_by, tr.sorted, tr:not(.invisible) ~ tr.invisible + tr:not(.invisible)' + // , tr.dir ~ tr:not(.dir,.invisible,.ignore)
  645. '{ border-top:solid 1px #999; }' +
  646. // border-right
  647. '#parents_dir_menu + ul, #shortcuts_menu + ul, #grid_btn ul.menu' +
  648. '{ border-right:0 !important; }' +
  649. 'body.theme_dark #parents_dir_menu, body.theme_dark #sidebar, body.theme_dark #grid_btn .menu li, body.theme_dark #warnings' +
  650. '{ border-right:solid 1px #111; }' +
  651. '#sidebar, body.theme_light #parents_dir_menu, #grid_btn .menu li, .image_grid_item' +
  652. '{ border-right:solid 1px grey; }' +
  653. // border-bottom
  654. '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 #grid_btn .menu li:first-of-type, body.theme_dark #grid_btn ul.menu, body.theme_dark #warnings' +
  655. '{ border-bottom:solid 1px #111; }' +
  656. 'body.theme_light #sidebar_header thead tr, body.theme_light #shortcuts, body.theme_light #sidebar_menus, #grid_btn .menu li:first-of-type, #grid_btn .menu, .specimen, .font_grid_item:last-of-type, .image_grid_item' +
  657. '{ border-bottom:solid 1px grey; }' +
  658. 'body.theme_light #content_title, body.theme_light #content_pane.has_audio #content_header' +
  659. '{ border-bottom:solid 1px #888; }' +
  660. '#shortcuts_menu + ul > li.has_submenu.ruled, .rule' +
  661. '{ border-bottom:solid 1px #999; }' +
  662. 'body.theme_dark #content_pane.has_font #content_font hr, .hamburger h4' +
  663. '{ border-bottom:solid 1px #CCC; }' +
  664. // border-left
  665. '#parents_dir_menu + ul, #shortcuts_menu + ul' +
  666. '{ border-left:0; }' +
  667. 'body.theme_dark #parents_dir_menu, body.theme_dark #grid_btn ul.menu, body.theme_dark #warnings' +
  668. '{ border-left:solid 1px #111; }' +
  669. 'body.theme_light #parents_dir_menu, #grid_btn .menu' +
  670. '{ border-left:solid 1px grey; }' +
  671. // border-collapse
  672. 'table' +
  673. '{ border-collapse: collapse; }' +
  674. // border-radius
  675. 'html, body, :root' +
  676. '{ border-radius: 0; }' +
  677. 'button' +
  678. '{ border-radius: 3px; }' +
  679. '#warnings' +
  680. '{ border-radius: 0 0 3px 3px; }' +
  681. // bottom
  682. '#handle, #parent_dir_menu, #dir_list, #tfoot, #close_audio::after, #dir_list tbody, #content_container, #overlay, #content_pane.has_grid #content_grid::after, #content_pane.has_grid .image_grid_item::after, .split_btn::after' +
  683. '{ bottom: 0; }' +
  684. // box-shadow
  685. 'body.theme_light #sidebar ul' +
  686. '{ box-shadow: 0px 2px 3px -2px #888; }' +
  687. 'body.theme_dark #sidebar ul' +
  688. '{ box-shadow:0px 2px 3px -2px #111; }' +
  689. '#warnings' +
  690. '{ box-shadow:0px 2px 12px 0 #111; }' +
  691. 'body.theme_dark #grid_btn ul.menu' +
  692. '{ box-shadow:none; }' +
  693. // box-sizing
  694. 'html, body, :root, #sidebar, #grid_btn .menu li, #content_container, #content_source, #content_preview' +
  695. '{ box-sizing: border-box; }' +
  696. // clear
  697. '#dir_list tbody .name' +
  698. '{ clear:right; }' +
  699. '#checkbox_div label, #grid_btn .menu li, #content_grid .font_grid_item' +
  700. '{ clear: both; }' +
  701. // columns
  702. '.lorem + .lorem' +
  703. '{ columns:2; column-gap:2em; }' +
  704. '.lorem + .lorem + .lorem' +
  705. '{ columns:3; }' +
  706. // COLOR
  707. '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' +
  708. '{ color: #111 }' +
  709. 'body.theme_light #sidebar #tfoot tr' +
  710. '{ color: #444 }' +
  711. 'body.theme_light #dir_list tr.ignore a, body.theme_light #dir_list tr.ignore.app a' +
  712. '{ color: #777 }' +
  713. '#sort_menu .disabled span, #dir_list th.disabled' +
  714. '{ color: #999 }' +
  715. 'body.theme_dark #dir_list tr.ignore td, body.theme_dark #dir_list tr.file.ignore a, body.theme_dark #sidebar #tfoot td' +
  716. '{ color: #BBB }' +
  717. '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' +
  718. '{ color: #EEE }' +
  719. // CONTENT
  720. 'body#top.edited #warnings.unloading h3::before, #dir_list th span::before, #dir_list th 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, #close_audio::after, #content_pane.has_grid #content_grid::after, #content_pane.has_grid .image_grid_item::after' +
  721. '{ content:"" }' +
  722. '#content_pane.has_audio #content_audio_title td::before, body #content_pane.has_video #title::before' +
  723. '{ content:"Playing: " }' + // .audio, .video
  724. '#content_pane.has_dir:not(.has_grid) #title::before' +
  725. '{ content:"Index of: " }' + // .dir
  726. '#content_pane.has_grid:not(.has_ignored) #title::before' +
  727. '{ content:"Fonts and Images from: " }' + // font and image grid
  728. 'body:not(.has_images) #content_pane.has_grid:not(.has_ignored) #title::before, #content_pane.has_grid #title.font_grid::before' +
  729. '{ content:"Fonts from: " }' + // font grid
  730. 'body:not(.has_fonts) #content_pane.has_grid:not(.has_ignored) #title::before, #content_pane.has_grid #title.image_grid::before' +
  731. '{ content:"Images from: " }' + // image grid
  732. '#content_pane.has_ignored:not(.has_grid) #title::before' +
  733. '{ content:"Ignored content: " }' + // .ignored
  734. 'body.edited.has_text #title::after, body.iframe_edited:not(.has_text) #content_pane.has_iframe #title::after' +
  735. '{ content:" (edited)" }' + // .ignored
  736. 'body#top.edited #text_editor_row a:after' +
  737. '{ content: " (edited)" }' + // .dir
  738. 'body#top.edited #warnings.unloading h3::before' +
  739. '{ content: "Text Editor: " }' + // .dir
  740. '#title::after' +
  741. '{ content: attr(data-after) }' + // .dir
  742. // counter
  743. 'body.show_numbers #tbody' +
  744. '{ counter-reset: row; }' +
  745. 'body.show_numbers #tbody tr td.name a::before' +
  746. '{ counter-increment: row; content:counter(row);}' +
  747. // cursor
  748. '#sidebar_title th, #sort_menu .disabled span, #dir_list .disabled' +
  749. '{ cursor: default; }' +
  750. '#sidebar_menus td:hover, #parents_dir_menu div, #shortcuts_menu div, #grid_btn, #dir_list thead th, #toggle_info, .split_btn span' +
  751. '{ cursor: pointer; }' +
  752. '#handle' +
  753. '{ cursor: col-resize; }' +
  754. '#content_pane:not(.has_zoom_image) #content_image' +
  755. '{ cursor: zoom-in; }' +
  756. '#content_pane.has_zoom_image content_image' +
  757. '{ cursor: zoom-out; }' +
  758. // DISPLAY
  759. '#sidebar_menus ul, #show_details span, #grid_btn, #grid_btn .menu, #dir_list thead .name input, #dir_list thead th.up::before, #dir_list .details, #dir_list thead td.icon, #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_grid, #content_pane #content_text, #content_pane .content, #content_pane.has_grid .content, body.has_text .content:not(#content_text), #content_pane.has_hidden_grid #content_grid, 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' +
  760. '{ display: none; }' +
  761. 'body.is_error #sidebar_buttons, body.is_error #thead, body.is_error #text_editor_row, body.is_error #content_pane.has_iframe #content_iframe.has_content' +
  762. '{ display: none !important; }' +
  763. '#sidebar li, #parent_dir_menu, #parent_dir_menu a, #parents_dir_menu + ul li a, #shortcuts_menu + ul li a, #shortcuts_menu + ul li > span, #shortcuts_menu + ul > li:hover > ul, #shortcuts_menu + ul > li > ul:hover, body.show_details #show_details span:last-of-type, body:not(.show_details) #show_details span:first-of-type, body.has_hidden_text #text_editor_row, #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_image:not(.has_grid) #content_image, #content_pane.has_zoom_image #content_image, #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' +
  764. '{ display: block; }' +
  765. 'body.has_text #dir_list tr#text_editor_row td, body #dir_list tr#text_editor_row td a, body.show_details #text_editor_row td, body.show_details #text_editor_row td a, body.has_images.has_fonts #grid_btn:hover ul.menu' +
  766. '{ display:block !important; }' +
  767. '#parents_dir_menu div, body.has_fonts #grid_btn, body.has_images #grid_btn, #dir_list thead th span::before, #enable_text_editing::before, #dir_list thead th span::after, body.show_details #dir_list th.details:not(#name):not(#sort_by_default), body.show_details #dir_list td.details:not(.name):not(.ext), body.show_numbers #tbody tr td.name a::before, body.has_audio #dir_list thead input, #title, #checkbox_div, #prev_track, #next_track, #close_audio, #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, 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' +
  768. '{ display: inline-block; }' +
  769. '#dir_list tr td.name span, #content_pane.has_image:not(.has_grid) #content_container, #content_pane.has_video:not(.has_grid) #content_container' +
  770. '{ display: flex; }' +
  771. '#content_pane.has_audio #content_audio_title, #content_pane.has_audio #content_audio' +
  772. '{ display: table-row !important; }' +
  773. '#shortcuts_menu div, #content_pane, #content_pane.has_audio #content_audio td' +
  774. '{ display: table-cell; }' +
  775. // display grid: dir_list editor row
  776. 'body.has_text #dir_list #text_editor_row, body.show_details #text_editor_row' +
  777. '{ display: grid; grid-gap:0; grid-template-columns: 1fr; }' +
  778. // display grid: table header
  779. '#theader' +
  780. '{ display: grid; grid-gap:0; grid-template-columns: 1fr 1fr 1fr 1fr; }' +
  781. 'th#sort_by_name' +
  782. '{ grid-column: 1 / span 2; }' +
  783. 'th#sort_by_default' +
  784. '{ grid-column: 3 / span 2; }' +
  785. // display grid: dir_list rows and cells
  786. '#dir_list #tbody tr:not(.invisible), body.show_invisibles #tbody tr.invisible, body.show_details #dir_list tr td.details' +
  787. '{ display: grid; grid-gap:0; grid-template-columns: minmax(auto,6rem) 1fr minmax(auto,6rem); }' +
  788. 'td.name' +
  789. '{ grid-column: 1 / span 3; }' +
  790. 'td.size' +
  791. '{ grid-column: 1; grid-row: 2; }' +
  792. 'td.date' +
  793. '{ grid-column: 2; grid-row: 2; }' +
  794. 'td.kind' +
  795. '{ grid-column: 3; grid-row: 2; }' +
  796. // display grid: content pane grids
  797. '#content_pane.has_grid #content_grid' +
  798. '{ 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); }' +
  799. '#content_pane.has_grid #content_grid .image_grid_item' +
  800. '{ grid-column: auto; display:flex; align-items: center; }' +
  801. '#content_pane.has_grid #content_grid .font_grid_item' +
  802. '{ grid-column: 1 / -1; }' +
  803. // FILTER
  804. 'body.theme_dark #grid_btn, body.theme_dark #grid_btn .menu, body.theme_dark #parent_dir_menu, body.theme_dark #shortcuts_menu, body.theme_dark #toggle_sidebar, body.theme_dark #toggle_info' +
  805. '{ filter:invert(100%); }' +
  806. // FLOAT
  807. '#dir_list tr td.name a::before, #checkbox_div label' +
  808. '{ float: left; }' +
  809. '#grid_btn' +
  810. '{ float: right; }' +
  811. // font-family
  812. 'html, body, :root' +
  813. '{ font-family:'+ $settings.UI_font +'; }' +
  814. // font-size
  815. 'html' +
  816. '{ font-size: 100.001%; }' +
  817. 'body, :root, #content_text' +
  818. '{ font-size:'+ $settings.UI_font_size +'; }' +
  819. '#sidebar, #sidebar_header, #dir_list, #tfoot, #content_header, #content_header table, #warnings' +
  820. '{ font-size: 0.875rem; }' +
  821. '#content_grid, .font_grid_item p, #error_message h1, #error_message h2' +
  822. '{ font-size: 1rem; }' +
  823. '#content_grid .font_grid_item h2' +
  824. '{ font-size:'+ $settings.grid_font_size * 4 +'em; }' +
  825. '#content_font' +
  826. '{ font-size:'+ $settings.grid_font_size +'em; }' +
  827. '#content_font .specimen' +
  828. '{ font-size:4em; }' +
  829. '#content_font .hamburger h1' +
  830. '{ font-size: 8em }' +
  831. '#content_font .hamburger h2' +
  832. '{ font-size:6em; text-align:justify; }' +
  833. '#content_font .hamburger h3' +
  834. '{ font-size:2em; }' +
  835. '#content_font .hamburger h4' +
  836. '{ font-size:1.618em; }' +
  837. '.lorem.first:first-line' +
  838. '{ font-size:'+ $settings.grid_font_size * 1.33 +'em; }' +
  839. // font-variant
  840. '.lorem.first:first-line' +
  841. '{ font-variant: small-caps }' +
  842. // font-weight
  843. '#sidebar_title th, h1, h2, h3, h4, h5, h6' +
  844. '{ font-weight: normal }' +
  845. '#dir_list .selected a' +
  846. '{ font-weight: bold }' +
  847. // HEIGHT
  848. 'html, body, :root, #parent_dir_menu a, #dir_list, #main_content, #content_pane, #content_pdf, #content_text, #content_iframe' +
  849. '{ height: 100%; }' +
  850. '#sidebar_header, #parents_dir_menu, #parents_dir_menu div, #content_pane:not(.has_zoom_image) #content_image, #content_grid div img' +
  851. '{ height: auto; }' +
  852. '#dir_list thead th span::before, #dir_list thead th span::after' +
  853. '{ height: 8px; }' +
  854. '#toggle_sidebar, #toggle_info' +
  855. '{ height: 14px; }' +
  856. '#dir_list td.icon' +
  857. '{ height: 16px; }' +
  858. '#grid_btn, #scale, #prev_next_btns, #close_btn, #reload_btn' +
  859. '{ height: 18px; }' +
  860. '#audio' +
  861. '{ height: 32px; }' +
  862. '.image_grid_item a' +
  863. '{ align-self: center; justify-self: center; }' +
  864. //'#content_grid.has_grid .image_grid_item' +
  865. // '{ height: '+ $grid_image_size +'px; }' +
  866. '#main_content' +
  867. '{ height:'+ window.innerHeight +'px; }' +
  868. // max-height
  869. '#content_pane:not(.has_zoom_image) #content_image' +
  870. '{ max-height: calc(100% - 4em); }' +
  871. '#content_pane.has_zoom_image #content_image' +
  872. '{ max-height: none; }' +
  873. '#content_grid div img' +
  874. '{ max-height:'+ ($settings.grid_image_size) +'px; }' +
  875. // min-height
  876. '#title' +
  877. '{ min-height: 18px; }' +
  878. '#sidebar' +
  879. '{ min-height: 100%; }' +
  880. // hyphens
  881. '#parents_dir_menu div, #content_header td button, #content_font' +
  882. '{ hyphens: none; }' +
  883. 'html, body, :root, .hamburger h3, .lorem' +
  884. '{ hyphens: auto; }' +
  885. // LEFT
  886. '#sidebar ul, #parent_dir_menu, #dir_list thead, #dir_list tbody, #tfoot, #close_audio::after, body.has_hidden_sidebar #toggle_sidebar, #overlay' +
  887. '{ left: 0; }' +
  888. ' #grid_btn ul.menu' +
  889. '{ left: unset; }' +
  890. 'body.has_hidden_sidebar #sidebar_wrapper' +
  891. '{ left: 3px; }' +
  892. 'body.show_numbers #tbody tr td.name a::before' +
  893. '{ left: 6px; }' +
  894. '#warnings, .split_btn::after' +
  895. '{ left: 50%; }' +
  896. '#shortcuts_menu + ul > li > ul' +
  897. '{ left: 100%; }' +
  898. '#dir_list thead th span::before' +
  899. '{ left: -16px; }' +
  900. // letter-spacing
  901. '.lorem.first:first-line, .font_grid_item p' +
  902. '{ letter-spacing: 0.1em }' +
  903. '#sidebar_title th' +
  904. '{ letter-spacing: 0.5em }' +
  905. // line-height
  906. '.image_grid_item a' +
  907. '{ line-height: 0; }' +
  908. '.split_btn span, .font_grid_item p' +
  909. '{ line-height: 1; }' +
  910. '#content_font .specimen' +
  911. '{ line-height: 1.2; }' +
  912. '#dir_list tr a, #title, .lorem' +
  913. '{ line-height: 1.4; }' +
  914. // list-style
  915. '#sidebar ul, #grid_btn .menu li' +
  916. '{ list-style-type: none; }' +
  917. // MARGIN
  918. 'html, body, :root, #sidebar ul, #parent_dir_menu, #parent_dir_menu, #parents_dir_menu, #parents_dir_menu + ul li a, #shortcuts_menu + ul li a, #shortcuts_menu + ul li > span, #shortcuts_menu, #grid_btn, #dir_list tbody a, #content_font .hamburger *, #content_grid p, #content_grid h2, #content_text, #warnings h3' +
  919. '{ margin: 0; }' +
  920. // margin-top
  921. '.image_grid_item + .font_grid_item' +
  922. '{ margin-top:-1px; }' +
  923. '#checkbox_div label input, #show_details, body.is_error #tbody h1' +
  924. '{ margin-top: 0; }' +
  925. 'body.has_audio #dir_list input' +
  926. '{ margin-top: 1px; }' +
  927. // margin-right
  928. '#content_image, #content_video, .image_grid_item a' +
  929. '{ margin-right: auto; }' +
  930. '#increase' +
  931. '{ margin-right: -4px; }' +
  932. 'th input, tr.media input, #scale' +
  933. '{ margin-right: 8px; }' +
  934. '#show_details' +
  935. '{ margin-right: 0.5em; }' +
  936. '#warning_ignore_btn' +
  937. '{ margin-right: 2em; }' +
  938. '#checkbox_div' +
  939. '{ margin-right: calc(-6em - 4px); }' +
  940. // margin-bottom
  941. '#show_details' +
  942. '{ margin-bottom: 0; }' +
  943. 'body.has_audio #dir_list input' +
  944. '{ margin-bottom: 1px; }' +
  945. '#content_grid.has_image_grid' +
  946. '{ margin-bottom: 1rem; }' +
  947. // margin-left
  948. '#content_image, #content_video, .image_grid_item a' +
  949. '{ margin-left: auto; }' +
  950. '#decrease' +
  951. '{ margin-left: -4px; }' +
  952. 'th input' +
  953. '{ margin-left: 2px; }' +
  954. 'tr.media input' +
  955. '{ margin-left: 7px; }' +
  956. '#prev_next_btns' +
  957. '{ margin-left: 8px; }' +
  958. '#show_details, #warnings button' +
  959. '{ margin-left: 0.5em; }' +
  960. '#warnings' +
  961. '{ margin-left: -12em; }' +
  962. '#dir_list tbody tr' +
  963. '{ margin-inline-start:0; }' +
  964. // -webkit-margin
  965. '#sidebar ul' +
  966. '{ -webkit-margin-before:0em !important; -webkit-margin-after:0em !important; -webkit-padding-start:0em; }' +
  967. // Object-fit
  968. '#content_image' +
  969. '{ object-fit:contain; }' +
  970. // OPACITY
  971. '#content_pane.has_ignored::before, #close_audio::after' +
  972. '{ opacity:0.3; }' +
  973. '#close_audio:hover::after' +
  974. '{ opacity:0.6; }' +
  975. '#sidebar_menus td:last-of-type:hover > div, #shortcuts_menu div, #shortcuts_menu div, #parent_dir_menu, #content_pane:hover #prev_btn, #content_pane:hover #next_btn, #toggle_sidebar, #toggle_info, body.use_custom_icons #dir_list tr.file.ignore a.icon::before, .split_btn span' +
  976. '{ opacity: 0.7; }' +
  977. '#content_grid div img' +
  978. '{ opacity:0.8; }' +
  979. '#grid_btn:hover, #parent_dir_menu:hover, #content_pane #prev_btn:hover, #content_pane #next_btn:hover, #toggle_sidebar:hover, #toggle_info:hover, .split_btn span:hover' +
  980. '{ opacity:1; }' +
  981. // outline
  982. '#grid_btn, #dir_list tbody, #dir_list tbody a, #audio:focus, #content_grid .font_grid_item, #content_font, #warnings button:focus, #content_video' +
  983. '{ outline: none; }' +
  984. // OVERFLOW
  985. 'html, body, :root, #parents_dir_menu div, #shortcuts_menu, #dir_list, #dir_list tbody a, #main_content, #close_audio, .hamburger h1, .hamburger h2, .hamburger h4' +
  986. '{ overflow: hidden; }' +
  987. '#dir_list tbody, #next_track, #prev_track, #content_container, #content_font, #content_grid' +
  988. '{ overflow: auto; }' +
  989. '#sidebar, #content_font' +
  990. '{ overflow-wrap: break-word; }' +
  991. '.lorem' +
  992. '{ overflow-wrap: normal; }' +
  993. // PADDING
  994. 'html, body, :root, #sidebar_wrapper, #sidebar ul, #parent_dir_menu, #sidebar_header tbody tr td, #parent_dir_menu, #parent_dir_menu a, #parents_dir_menu, #shortcuts_menu, #dir_list .details a, #tfoot, #content_pane, #content_pdf, #content_iframe, #content_text, audio::-webkit-media-controls-panel' +
  995. '{ padding: 0; }' +
  996. '#sidebar_title th' +
  997. '{ padding: 4px; }' +
  998. '.image_grid_item' +
  999. '{ padding:6px; }' +
  1000. '#error_message, #warnings' +
  1001. '{ padding:1rem; }' +
  1002. // padding-top
  1003. '#dir_list thead th, #dir_list .details, #prev_track, #next_track, #close_audio' +
  1004. '{ padding-top: 0; }' +
  1005. '#show_details, #text_editor_row a, #toggle_info' +
  1006. '{ padding-top: 2px; }' +
  1007. '#parents_dir_menu div, #grid_btn .menu li, #dir_list tbody a, #stats, #title_buttons_left, #title_buttons_right, #title, body #content_audio_title td, #content_audio td' +
  1008. '{ padding-top: 4px; }' +
  1009. '#sidebar_header tbody tr:last-of-type td, #parents_dir_menu + ul li a, #shortcuts_menu + ul li a, #shortcuts_menu + ul li > span, #shortcuts_menu + ul li div span, .hamburger h4' +
  1010. '{ padding-top: 6px; }' +
  1011. '#content_header table' +
  1012. '{ padding-top: 7px; }' +
  1013. '#content_grid .font_grid_item, .font_grid_item p, #content_font div.lorem' +
  1014. '{ padding-top: 0.5rem; }' +
  1015. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #content_font div.specimen' +
  1016. '{ padding-top: 2rem; }' +
  1017. // padding-right
  1018. '#sidebar_header tbody tr:last-of-type td, #prev_track, #next_track, #prev_next_btns, #close_audio' +
  1019. '{ padding-right: 0; }' +
  1020. '#scale' +
  1021. '{ padding-right: 4px; }' +
  1022. '#parents_dir_menu div, #show_details, #grid_btn .menu li, #stats, #title_buttons_left, #title_buttons_right, #content_audio td, #close_audio' +
  1023. '{ padding-right: 6px; }' +
  1024. '#parents_dir_menu + ul li a, #shortcuts_menu + ul li a, #shortcuts_menu + ul li > span, #shortcuts_menu + ul li div span, body.show_numbers #tbody tr td.name a::before, #dir_list tbody a' +
  1025. '{ padding-right: 8px; }' +
  1026. '#dir_list td.details, #content_header table, #title' +
  1027. '{ padding-right: 12px; }' +
  1028. '#grid_btn .menu, #content_audio_title td' +
  1029. '{ padding-right: 29px; }' +
  1030. '.font_grid_item p, .font_grid_item a' +
  1031. '{ padding-right: 2rem; }' +
  1032. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #content_font div' +
  1033. '{ padding-right: 2.5rem; }' +
  1034. // padding-bottom
  1035. '#prev_track, #next_track, #close_audio' +
  1036. '{ padding-bottom: 0px }' +
  1037. '#show_details, body.is_dirs_on_top #dir_list tbody tr.sorted:not(:last-of-type)' +
  1038. '{ padding-bottom: 2px; }' +
  1039. '#title, body #content_audio_title td, #text_editor_row a, #title_buttons_left, #title_buttons_right' +
  1040. '{ padding-bottom: 3px;}' +
  1041. '#parents_dir_menu div, #grid_btn .menu li, #dir_list tbody a, #dir_list .details' +
  1042. '{ padding-bottom: 4px; }' +
  1043. '#content_header table, #dir_list tfoot td' +
  1044. '{ padding-bottom: 5px; }' +
  1045. '#sidebar_header tbody tr:last-of-type td, #parents_dir_menu + ul li a, #shortcuts_menu + ul li a, #shortcuts_menu + ul li > span, #shortcuts_menu + ul li div span, #dir_list thead th, #content_audio td' +
  1046. '{ padding-bottom: 6px; }' +
  1047. '#dir_list thead th.details, .hamburger h4' +
  1048. '{ padding-bottom: 9px; }' +
  1049. '.specimen, .font_grid_item p, .font_grid_item a' +
  1050. '{ padding-bottom: 0.5rem; }' +
  1051. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #content_font div:first-of-type, #content_font .lorem:last-of-type' +
  1052. '{ padding-bottom: 2rem; }' +
  1053. // padding-left
  1054. '#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' +
  1055. '{ padding-left: 0px; }' +
  1056. '#dir_list .audio a, #dir_list .video a, #checkbox_div, #scale' +
  1057. '{ padding-left: 4px; }' +
  1058. '#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, #show_details, #grid_btn .menu li, #title_buttons_left, #title_buttons_right, #content_audio td, #prev_track' +
  1059. '{ padding-left: 6px; }' +
  1060. '#parents_dir_menu + ul li a' +
  1061. '{ padding-left: 8px; }' +
  1062. '#content_header table, #title' +
  1063. '{ padding-left: 12px; }' +
  1064. '#shortcuts li span, #shortcuts li a' +
  1065. '{ padding-left: 20px; }' +
  1066. '#shortcuts ul li a' +
  1067. '{ padding-left: 30px; }' +
  1068. 'body.has_hidden_sidebar #title_buttons_left' +
  1069. '{ padding-left: 22px; }' +
  1070. '#dir_list #tbody tr:not(.media) a span, #text_editor_row a' +
  1071. '{ padding-left: 27px; -webkit-padding-start: 27px; }' +
  1072. '#dir_list thead th#size, #dir_list #tbody td.details.size, #content_audio_title td' +
  1073. '{ padding-left: 29px; }' +
  1074. 'tr.media a.icon' +
  1075. '{ padding-left: 31px; }' +
  1076. '.font_grid_item p, .font_grid_item a' +
  1077. '{ padding-left: 2rem; }' +
  1078. 'body:not(.has_text) #content_pane.has_image:not(.has_grid) #content_container, #content_font div' +
  1079. '{ padding-left: 2.5rem; }' +
  1080. //-webkit-padding
  1081. '#dir_list td.name a' +
  1082. '{ -webkit-padding-start:0; }' +
  1083. '#dir_list .icon + td.name a' +
  1084. '{ -webkit-padding-start:1em; }' +
  1085. // POSITION
  1086. '#sidebar_wrapper, #sidebar_header, #sidebar_buttons, #sidebar_menus td:first-of-type, #sidebar_header tbody tr:last-of-type td, #dir_list, #dir_list thead th span, 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, #shortcuts_menu + ul > li.has_submenu, #content_pane, #content_header, #content_grid, #content_text, #content_font, #content_pdf, #content_iframe, #close_audio, #content_grid div img, #content_text, .split_btn' +
  1087. '{ position: relative; }' +
  1088. '#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_image, #warnings, #overlay, #content_pane.has_grid #content_grid::after, #content_pane.has_grid .image_grid_item::after' +
  1089. '{ position: absolute; }' +
  1090. '#dir_list thead, #tfoot' +
  1091. '{ position: fixed; }' +
  1092. // RIGHT
  1093. '#sidebar ul, #parent_dir_menu, #grid_btn .menu, #dir_list thead, #dir_list tbody, #tfoot, #close_audio::after, #title_buttons_right, #next_btn, #overlay, #content_pane.has_grid #content_grid::after, #content_pane.has_grid .image_grid_item::after, #toggle_info' +
  1094. '{ right: 0; }' +
  1095. '#dir_list thead th span::after' +
  1096. '{ right: -16px; }' +
  1097. '#toggle_sidebar' +
  1098. '{ right: 4px; }' +
  1099. '#handle' +
  1100. '{ right: -4px; }' +
  1101. // table-layout
  1102. '#dir_list' +
  1103. '{ table-layout: fixed; }' +
  1104. // text-align
  1105. '#sidebar ul, #dir_list tbody, #dir_list th#sort_by_ext, #dir_list tbody .name, #dir_list thead th:not(.details), #dir_list tr.details, #title_buttons_left' +
  1106. '{ text-align: left; }' +
  1107. '#parent_dir_menu a, #parents_dir_menu, th.details, #parents_dir_menu div, #shortcuts_menu div, #content_header, #content_title, #content_audio_title, #content_audio td' +
  1108. '{ text-align: center; }' +
  1109. '#grid_btn .menu li, body.show_numbers #tbody tr td.name a::before, #dir_list th#sort_by_default, #dir_list th#sort_by_kind, #dir_list .size, #dir_list .date, #dir_list .kind, #title_buttons_right, #warnings div, .playlist_time' +
  1110. '{ text-align: right; }' +
  1111. '.hamburger, .lorem' +
  1112. '{ text-align: justify; }' +
  1113. // text-decoration
  1114. 'a, a:hover' +
  1115. '{ text-decoration: none !important; }' +
  1116. // text-transform
  1117. '.font_grid_item p' +
  1118. '{ text-transform: uppercase; }' +
  1119. // TOP
  1120. '#handle, #parent_dir_menu, #dir_list, #toggle_info, #title_buttons_left, #title_buttons_right, #close_audio::after, #prev_btn, #next_btn, #warnings, #overlay, #content_pane.has_grid #content_grid::after, .split_btn::after' +
  1121. '{ top: 0; }' +
  1122. '#shortcuts_menu + ul > li > ul, body.theme_light #grid_btn .menu' +
  1123. '{ top: -1px !important; }' +
  1124. 'body.has_hidden_sidebar #sidebar_wrapper, #dir_list thead th span::before, #dir_list thead th span::after' +
  1125. '{ top: 2px; }' +
  1126. '#toggle_sidebar' +
  1127. '{ top: 4px; }' +
  1128. 'body.theme_dark #grid_btn .menu' +
  1129. '{ top: -7px; }' +
  1130. // TRANSFORM
  1131. '#dir_list' +
  1132. '{ transform: scale(1); }' + // needed to establish #dir_list as containing block for thead and tfoot position fixed.
  1133. 'body.has_hidden_sidebar #toggle_sidebar, #dir_list thead th:not(.up) span::after, #next_track, #next_btn, #toggle_info' +
  1134. '{ transform:rotate(180deg); }' +
  1135. '#close_audio::after' +
  1136. '{ transform:rotate(45deg); }' +
  1137. // user-select
  1138. '#sidebar_header, #content_pane:not(.has_zoom_image) #content_image' +
  1139. '{ user-select:none; -webkit-user-select:none; }' +
  1140. // vertical-align
  1141. '#content_pane' +
  1142. '{ vertical-align:top; }' +
  1143. '#title_buttons_left, #title_buttons_right, #title' +
  1144. '{ vertical-align:top; }' +
  1145. // white-space
  1146. '#sidebar_header tbody tr:last-of-type td, #parents_dir_menu div, #parents_dir_menu + ul li a, #shortcuts_menu + ul li a, #shortcuts_menu + ul li > span, #dir_list tbody a, .specimen, .lorem' +
  1147. '{ white-space: normal; }' +
  1148. '#theader span, #tbody td:not(.name), #grid_btn .menu li, .hamburger h1, .hamburger h2, .hamburger h4' +
  1149. '{ white-space: pre; }' +
  1150. // WIDTH
  1151. 'html, body, :root, table, #parent_dir_menu a, #dir_list thead, #tbody, #text_editor_row td, #tbody tr, #shortcuts_menu + ul > li > ul, #grid_btn .menu li, #content_container, #content_header, #content_grid, #content_text, #content_font svg, #content_pdf, #content_iframe' +
  1152. '{ width: 100%; }' +
  1153. '#sidebar_menus td:nth-of-type(2), #dir_list .date, #title, #content_pane:not(.has_zoom_image) #content_image, #content_grid div img' +
  1154. '{ width: auto; }' +
  1155. '.split_btn span' +
  1156. '{ width: 2em; }' +
  1157. '#content_pane.has_grid #content_grid::after, #content_pane.has_grid .image_grid_item::after, .split_btn::after' +
  1158. '{ width: 1px; }' +
  1159. '#handle' +
  1160. '{ width: 8px; }' +
  1161. '#dir_list thead th span::before, #dir_list thead th span::after, #toggle_sidebar, #toggle_info' +
  1162. '{ width: 18px; }' +
  1163. '#sidebar_menus td:nth-of-type(odd)' +
  1164. '{ width: 24px; }' +
  1165. '#grid_btn' +
  1166. '{ width: 28px; }' +
  1167. '#prev_track, #next_track, #close_audio' +
  1168. '{ width: 2rem; }' +
  1169. '#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' +
  1170. '{ width: 4rem; }' +
  1171. '#shortcuts_menu div, #checkbox_div' +
  1172. '{ width: 6em; }' +
  1173. '#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' +
  1174. '{ width: 9.5em; }' +
  1175. '#warnings' +
  1176. '{ width: 26em; }' +
  1177. 'body.has_hidden_sidebar #sidebar_wrapper' +
  1178. '{ width: 0 !important; }' +
  1179. '#reload_btn, #close_btn' +
  1180. '{ width: 52px; }' +
  1181. 'body.has_hidden_sidebar #content_pane' +
  1182. '{ width: 100% !important; }' +
  1183. 'body:not(.has_hidden_sidebar) #sidebar_wrapper' +
  1184. '{ width:'+ getQuery('width').toString() +'%; }' +
  1185. 'body:not(.has_hidden_sidebar) #content_pane' +
  1186. '{ width:'+ (100 - getQuery('width')).toString() +'%; }' +
  1187. // max-width
  1188. 'html, body, :root' +
  1189. '{ max-width: 100%; }' +
  1190. '#content_pane:not(.has_zoom_image) #content_image' +
  1191. '{ max-width: calc(100% - 5em); }' +
  1192. '#content_pane.has_zoom_image #content_image' +
  1193. '{ max-width: none; }' +
  1194. '#sidebar_menus td:nth-of-type(odd)' +
  1195. '{ max-width: 24px; }' +
  1196. '#content_grid div img' +
  1197. '{ max-width:'+ ($settings.grid_image_size).toString() +'px; }' +
  1198. // min-width
  1199. 'body.show_numbers #tbody tr td.name a::before' +
  1200. '{ min-width: 17px; }' +
  1201. 'body:not(.has_hidden_sidebar) #sidebar_menus td:nth-of-type(odd)' +
  1202. '{ min-width: 24px; }' +
  1203. 'body:not(.has_hidden_sidebar) #dir_list' +
  1204. '{ min-width: 100px; }' +
  1205. 'body:not(.has_hidden_sidebar) #sidebar_wrapper' +
  1206. '{ min-width: 220px; }' +
  1207. // will-change
  1208. '#sidebar_wrapper, #content_pane' +
  1209. '{ will-change: width }' +
  1210. // word-break
  1211. '#content_header td button' +
  1212. '{ word-break: none; }' +
  1213. '#title' +
  1214. '{ word-break: break-word; }' +
  1215. '#content_font .specimen' +
  1216. '{ word-break: break-all; }' +
  1217. '.lorem' +
  1218. '{ word-break: normal; }' +
  1219. // Z-INDEX
  1220. '#content_pane' +
  1221. '{ z-index: 0; }' +
  1222. '#handle, #sidebar_wrapper' +
  1223. '{ z-index: 1 !important; }' +
  1224. '#parents_dir_menu + ul, #content_header' +
  1225. '{ z-index: 20; }' +
  1226. '#sidebar_header, #content_pane.has_grid .image_grid_item::after' +
  1227. '{ z-index: 2000; }' +
  1228. '#shortcuts_menu + ul, #toggle_sidebar' +
  1229. '{ z-index: 9997; }' +
  1230. '#overlay' +
  1231. '{ z-index: 9997; }' +
  1232. '#warnings' +
  1233. '{ z-index: 9999; }' +
  1234. 'body.has_hidden_sidebar #sidebar_header' +
  1235. '{ z-index:unset; }'
  1236. ;
  1237. // Gecko Styles:
  1238. const $gecko_style_rules =
  1239. 'html, body.is_gecko { border: solid 1px gray !important; }' +
  1240. 'body.is_gecko button { padding:revert; }' +
  1241. 'body.is_gecko #grid_btn .menu { top:-7px; left:-120px; }' +
  1242. 'body.is_gecko thead {font-size:100%;}' +
  1243. 'body.is_gecko #dir_list .dir::before {position:absolute;}' +
  1244. 'body.is_gecko.use_default_icons:not(.is_converted_list) #dir_list .file .name .icon { padding-left:4px; background:none; }' +
  1245. 'body.is_gecko.use_default_icons #dir_list .file .name .icon img { margin-right:6px; height:14px; }' +
  1246. 'body.is_gecko #tbody > tr > td:not(:first-of-type) { float:left }' +
  1247. 'body.is_gecko #content_audio_title td { padding-top: 6px; }' +
  1248. 'body.is_gecko #content_audio_title td { padding-bottom: 0; }' +
  1249. 'body.is_gecko #prev_track { padding-left: 16px; }' +
  1250. 'body.is_gecko #close_audio { background-color: #252525; }' +
  1251. 'body.is_gecko #close_audio::after { filter:invert(100%); opacity:0.5; }' +
  1252. 'body.is_gecko #close_audio:hover::after { opacity:0.75; }' +
  1253. 'body.is_gecko.dark #prev_track, body.is_gecko.dark #next_track { background: #252525 '+ $next_track_arrow_gecko +' center no-repeat; }' +
  1254. 'body.is_gecko #prev_track:hover, body.is_gecko #next_track:hover { background: #252525 '+ $next_track_arrow_gecko_hover +' center no-repeat; }'
  1255. ;
  1256. var $text_editing_style_rules =
  1257. 'html, body, #iframe_body { margin:0; padding:0; }' +
  1258. // toolbar
  1259. '#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; }' +
  1260. '#toolbar li { margin:4px; padding:4px; width:3.5em; display:block; opacity:0.5; list-style-type:none; cursor:pointer; }' +
  1261. '#toolbar li:hover, .preview_text:not(.split) #toolbar li#show_preview, .source_text:not(.split) #toolbar li#showSRC, .split #toolbar li#toggle_split, .edited #save_btn { opacity:1; }' +
  1262. '#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=\'%23444444\' d=\'M0,0v16h16V0H0z M15,15H8.5V1H15V15z M7.5,15H1V1h6.5V15z\'/></svg>") center no-repeat; }' +
  1263. '#toolbar li#sync_scroll { width:8em; float:left; opacity:1; }' +
  1264. '#toolbar li#sync_scroll input { float:left; }' +
  1265. '#toolbar li#sync_scroll label { width:8em; display:block; font-size:inherit; line-height:1.5; }' +
  1266. '#toolbar li#clear_text { height:16px; float:right; text-align:center; }' +
  1267. '#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=\'%23444444\' d=\'M16,0v10.02h-1.33V1.33H1.33v8.69H0V0H16z\'/> <path fill=\'%23444444\' 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; }' +
  1268. '#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=\'%23444444\' 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=\'%23444444\' 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=\'%23444444\' d=\'M30.98,2.65h-3.63V1.58h8.55v1.07h-3.63v9.65h-1.28V2.65z\'/> <path fill=\'%23444444\' 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; }' +
  1269. '#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=\'%23444444\' 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=\'%23444444\' 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=\'%23444444\' d=\'M30.98,2.65h-3.63V1.58h8.55v1.07h-3.63v9.65h-1.28V2.65z\'/> <path fill=\'%23444444\' 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; }' +
  1270. '.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; }' +
  1271. '#toolbar li#save_btn div { display:none; position:relative; top:-9px; left:-24px; color:#999; text-align:right; }' +
  1272. '#toolbar li#save_btn:hover div { display:block; }' +
  1273. '#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; }' +
  1274. '#toolbar li#save_btn span:first-of-type { border-bottom-width:0px; }' +
  1275. '#toolbar li#save_btn span:hover { color:#444; }' +
  1276. // resize handle
  1277. '.split_view #text_editing_handle { width:9px; position:absolute; top:0; bottom:0; left:calc(50% - 4px); cursor:col-resize; z-index:11; }' +
  1278. '#text_editing_handle { z-index:-1; }' +
  1279. // source
  1280. '#content_source { margin:0; padding: 14px; width:100%; 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*/,'') +'; }' +
  1281. '#content_source, #content_preview { position:absolute; top:32px; right:0; bottom:0; left:0; }' +
  1282. '#content_source:focus { outline:none; background:#FFF; box-shadow: inset 0 0 4px #888; }' +
  1283. // preview
  1284. '#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*/,'') +'; }' +
  1285. // split views
  1286. '.preview_text:not(.split_view) #content_source, .source_text:not(.split_view) #content_preview, li#save_btn div, .comment { display:none; }' +
  1287. '.split_view #content_preview { border-left:solid 1px #999; }' +
  1288. '.split_view #content_source {width:50%; }' +
  1289. '.split_view #content_preview {left:50%; }' +
  1290. // preview styles
  1291. '#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*/,'') +'; }' +
  1292. '#content_preview .no_list { list-style:none; }' +
  1293. '#content_preview > .no_list { padding:0; }' +
  1294. '#content_preview .text-align-center { text-align:center; }' +
  1295. '#content_preview th, #content_preview td { vertical-align:top; }' +
  1296. '#content_preview blockquote { margin-top:1em; margin-bottom:1em; color: #555; }' +
  1297. '#content_preview blockquote + blockquote { margin-top:0; }' +
  1298. '.markdown-body input[type="checkbox"] { margin-top:0.375em; margin-right:6px; float:left; }' +
  1299. 'h1 .uplink,h2 .uplink,h3 .uplink,h4 .uplink,h5 .uplink,h6 .uplink { margin:0; padding:0; display:inline-block; font-size:0.875em; cursor:pointer; transition: opacity 0.25s; opacity:0; }' +
  1300. 'h1:hover .uplink,h2:hover .uplink,h3:hover .uplink,h4:hover .uplink,h5:hover .uplink,h6:hover .uplink { transition: opacity 0.25s; opacity:0.5; }' +
  1301. '#content_preview table { font-size:inherit; }' +
  1302. '#content_preview table th { background-color:#EEE; }' +
  1303. '.markdown-body::before, .markdown-body::after { display:none !important; background:transparent; }' +
  1304. // edited warning
  1305. '#iframe_body #warnings p, #iframe_body #warnings button { display:none; }' +
  1306. '#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; }' +
  1307. '#iframe_body #warnings h3 { margin:0; font-weight:normal; }' +
  1308. '#iframe_body #warnings div { text-align:right; }' +
  1309. '#iframe_body #warnings button { margin-left:0.5em; }' +
  1310. '#iframe_body #warnings #warning_ignore_btn { margin-right:2em; }' +
  1311. '#iframe_body.has_warning #warnings, #iframe_body.has_warning #warnings.unsaved p#warning_unsaved, #iframe_body.has_warning #warnings.clear p#warning_clear { display:block; }' +
  1312. '#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 { display:inline-block; }' +
  1313. // disabled text editing
  1314. '#iframe_body.enable_text_editing #toolbar, #iframe_body.enable_text_editing #preview_text, #iframe_body.enable_text_editing #text_editing_handle { display:none; }' +
  1315. '#iframe_body.enable_text_editing #content_source.disabled { top:0; background:white; }'
  1316. ;
  1317. var $iframe_styles =
  1318. // background
  1319. '#iframe_body a.up, #iframe_body #dir_list { background:transparent; }' +
  1320. '#iframe_body :root, html, body { background-color:#BBB; }' +
  1321. '#iframe_body #thead, #tbody tr { background:rgba(221,221,221,0.5); }' +
  1322. '#iframe_body #thead tr#parent { background:rgba(144,144,144,0.33); }' +
  1323. '#iframe_body #tbody tr:nth-of-type(odd) { background:rgba(221,221,221,1); }' +
  1324. '#iframe_body #tbody tr:hover { background:#BBB; }' +
  1325. // background icons
  1326. '#iframe_body #dir_list tr td.name a::before { content:""; width:14px; height:14px; margin-right:4px; bottom:-1px;}' +
  1327. '#iframe_body #dir_list tr.dir td.name a::before { background: '+ $file_icon_dir +' center no-repeat; background-size:14px 14px; }' +
  1328. '#iframe_body #dir_list tr.file td.name a::before { background: '+ $file_icon_file +' center no-repeat; background-size:14px 14px; }' +
  1329. '#iframe_body #dir_list tr.app td.name a::before { background: '+ $file_icon_app +' center no-repeat; background-size:14px 14px; }' +
  1330. '#iframe_body #dir_list tr.audio td.name a::before { background: '+ $file_icon_audio +' center no-repeat; background-size:14px 14px; }' +
  1331. '#iframe_body #dir_list tr.video td.name a::before { background: '+ $file_icon_video +' center no-repeat; background-size:14px 14px; }' +
  1332. '#iframe_body #dir_list tr.text td.name a::before { background: '+ $file_icon_text +' center no-repeat; background-size:14px 14px; }' +
  1333. '#iframe_body #dir_list tr.image td.name a::before { background: '+ $file_icon_image +' center no-repeat; background-size:14px 14px; }' +
  1334. '#iframe_body #dir_list tr.pdf td.name a::before { background: '+ $file_icon_pdf +' center no-repeat; background-size:14px 14px; }' +
  1335. '#iframe_body #dir_list tr.font td.name a::before { background: '+ $file_icon_font +' center no-repeat; background-size:14px 14px; }' +
  1336. '#iframe_body #dir_list tr.code td.name a::before { background: '+ $file_icon_code +' center no-repeat; background-size:14px 14px; }' +
  1337. '#iframe_body #dir_list tr.htm td.name a::before { background: '+ $file_icon_html +' center no-repeat; background-size:14px 14px; }' +
  1338. '#iframe_body #dir_list tr.invisible td.name a::before { background: '+ $file_icon_invisible +' center no-repeat; background-size:14px 14px; }' +
  1339. '#iframe_body #dir_list tr.ignored td.name a::before { background: '+ $file_icon_ignored +' center no-repeat; background-size:14px 14px; }' +
  1340. '#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 { background-image:'+ $check_mark +'; background-repeat: no-repeat; background-size:10px; background-position: center; }' +
  1341. '#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 { background-image:'+ $up_arrow +'; background-repeat: no-repeat; background-size:10px; background-position: center; }' +
  1342. '#iframe_body .sorting.down span::after { transform:rotate(180deg) }' +
  1343. // border
  1344. ':root, html, #iframe_body { border:0 !important; }' +
  1345. 'html, #iframe_body { border-radius:0; }' +
  1346. '#iframe_body #dir_list { border-collapse:collapse; }' +
  1347. '#iframe_body #dir_list thead th { border-bottom:solid 1px #999; }' +
  1348. // box-sizing
  1349. '#iframe_body, iframe_body td.name, iframe_body td.details { box-sizing:border-box; }' +
  1350. // color
  1351. '#iframe_body a { color:#111111; }' +
  1352. '#iframe_body a:hover { color:#000000; }' +
  1353. '#iframe_body tr.ignore, #iframe_body tr.ignore a { color:grey; }' +
  1354. // content
  1355. '.sorting span::before,.sorting span::after { content:""; width:16px; height:8px; display:inline-block; position:relative; }' +
  1356.  
  1357. // counter
  1358. '#iframe_body tbody { counter-reset: row; }' +
  1359. '#iframe_body.show_numbers tr td.name::before { counter-increment: row; content:counter(row); margin-right:6px; min-width:1.25em; text-align:right;}' +
  1360. // cursor
  1361. '#iframe_body #dir_list th.sorting { cursor: pointer; }' +
  1362. // display
  1363. '#iframe_body #dir_list tr::before, #iframe_body #dir_list td.name input, #iframe_body td.ext { display:none; }' +
  1364. '#iframe_body a { display:block; }' +
  1365. '#parent + tr { display: grid; grid-gap:0; grid-template-columns: 50% 50%; }' +
  1366. '#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); }' +
  1367. '#iframe_body td.name, #iframe_body #sort_by_name, #iframe_body #sort_by_ext { grid-column: 1; }' +
  1368. '#iframe_body td.size, #iframe_body #sort_by_default, #iframe_body #sort_by_size { grid-column: 2; }' +
  1369. '#iframe_body td.date, #iframe_body #sort_by_date { grid-column: 3; }' +
  1370. '#iframe_body td.kind, #iframe_body #sort_by_kind { grid-column: 4; }' +
  1371. // float
  1372. '#iframe_body #dir_list td.name::before, #iframe_body #dir_list a::before { float:left; }' +
  1373. // fonts
  1374. '#iframe_body { font-family:'+ $settings.UI_font +'; }' +
  1375. '#iframe_body { font-size:'+ parseFloat($settings.UI_font_size) * 0.875 + $settings.UI_font_size.replace(/\d*/,'') +'; }' +
  1376. '#iframe_body #dir_list, #iframe_body #thead { font-size: 1em; }' +
  1377. // height
  1378. '#iframe_body, #iframe_body #dir_list { height:100%; }' +
  1379. '#iframe_body #content_source { height:inherit; }' +
  1380. '#iframe_body #thead { height:2em; max-height:2em; }' +
  1381. // line-height
  1382. '#iframe_body #tbody tr { line-height:1.5; }' +
  1383. // margin
  1384. 'html, body, #iframe_body { margin:0; }' +
  1385. '#iframe_body .dir::before, #iframe_body .file > img { margin-inline-end: 6px; }' +
  1386. // outline
  1387. '#iframe_body #dir_list tr, #iframe_body #tbody tr:hover { outline:0; }' +
  1388. // overflow
  1389. '#iframe_body, #iframe_body #dir_list, .details.date { overflow:hidden; text-overflow: ellipsis; }' +
  1390. '#iframe_body #dir_list #tbody { overflow:auto; }' +
  1391. // padding
  1392. 'html, :root, #iframe_body, body { padding:0; }' +
  1393. '#iframe_body #tbody tr td, #iframe_body #thead tr th { padding-top:3px; }' +
  1394. '#iframe_body #tbody tr td { padding-right: 6px; }' +
  1395. '#iframe_body #tbody tr td, #iframe_body #thead tr th { padding-bottom:3px; }' +
  1396. '#parent th, #iframe_body #tbody tr td.details.kind { padding-right: 1em; }' +
  1397. '#iframe_body td.details { padding-left: 6px; }' +
  1398. '#parent th, #tbody tr td.name { padding-left:1em; }' +
  1399. '#iframe_body #dir_list, #iframe_body #dir_list tr td.name a::before { position:relative; }' + // position
  1400. '#iframe_body, #iframe_body #dir_list #tbody { position:absolute; right:0; bottom:0; left:0; }' +
  1401. '#iframe_body th { text-align:center; }' + // text-align
  1402. '#iframe_body th:last-of-type, #iframe_body td.details { text-align:right; }' +
  1403. '#iframe_body th:first-of-type { text-align:left; }' +
  1404. '#iframe_body a, #iframe_body a:hover, #iframe_body td:hover { text-decoration:none !important; }' + // text-decoration
  1405. '#iframe_body a.icon { text-indent:2px; }' + // text-indent
  1406. '#iframe_body #thead { user-select:none; -webkit-user-select:none; }' +
  1407. // vertical-align
  1408. '#iframe_body td.details { vertical-align:top; }' +
  1409. // width
  1410. 'html, #iframe_body, #iframe_body #dir_list, #iframe_body #dir_list tr { width:100%; max-width:100%; min-width:100%; }' +
  1411. '#iframe_body #dir_list td:not(:first-child) { width:unset; }' +
  1412. // white-space
  1413. '#iframe_body td:not(.name) { white-space:pre; }'
  1414. ;
  1415.  
  1416. // ADD STYLES
  1417. const $font_styles = document.createElement('style');
  1418. const $font_grid_styles = document.createElement('style');
  1419.  
  1420. function addStyles(el) {
  1421. el.find('style, link[rel="stylesheet"], link[href$="css"]').remove(); // remove any existing stylesheets
  1422. el.append('<style>'+ $main_style_rules +'</style>');
  1423. el.append('<style>'+ $gecko_style_rules +'</style>');
  1424. el.append($font_styles); // empty until font is previewed
  1425. el.append($font_grid_styles); // empty until font grid is made
  1426. el.append('<style>'+ $text_editing_style_rules +'</style>');
  1427. el.append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css"></link>');
  1428. }
  1429. // ***** END STYLES ***** //
  1430.  
  1431. // ***** BUILD MENUS ***** //
  1432. // Parent and Parents Menus
  1433. function updateQueryStr(str) {
  1434. str = str.replace(/([^\?]*)selected=[^&]*(.*)$/m,'$1$2') // delete current selected query, if any
  1435. .replace(/([^\?]*)history=(\d+)\+*([^&]*)(&*)(.*)/m,'$1$4$5&selected=$2&history=$3').replace(/&{2,}/g,'&').replace(/\?&/m,'\?'); // format query with selected and history at end
  1436. if ( str.endsWith('&history=') ) { str = str.replace(/(.+)&history=$/m,'$1'); } // if no history, delete query
  1437. return str;
  1438. }
  1439. function createParentLinks() {
  1440. let $links = [];
  1441. let $protocol = window.location.protocol;
  1442. let $href = decodeURIComponentSafe(window.location.href);
  1443. let str = decodeURIComponentSafe(window.location.search);
  1444. let $linkPieces = $href.split('/');
  1445. $linkPieces = $linkPieces.slice(2,-2); // remove beginning and ending empty elements and current directory
  1446. while ( $linkPieces.length > 0 ) { // while there are link pieces...
  1447. str = updateQueryStr(str); // update selected and history
  1448. let link = $protocol +'//'+ $linkPieces.join('/') +'/'+ str; // assemble link
  1449. $links.push(link); // add to link array
  1450. $linkPieces.pop(); // remove last link piece and repeat...
  1451. }
  1452. return $links;
  1453. }
  1454. function createParentLinkItems() {
  1455. let $parent_link_menu_items = [];
  1456. let $links = createParentLinks();
  1457. $parent_dir_menu.find('a').attr( 'href', $links[0] ); // set parent link
  1458. for ( let i = 0; i < $links.length; i++ ) {
  1459. let display_name = $links[i].slice(0,$links[i].lastIndexOf('?') - 1);
  1460. display_name = display_name.replace(/\//g,'\/<wbr>');
  1461. let menu_item = '<li><a href="'+ $links[i] +'">' + display_name + '/</a></li>';
  1462. $parent_link_menu_items.push(menu_item);
  1463. }
  1464. return $parent_link_menu_items; // return parents link items
  1465. }
  1466. function updateParentLinks() { $parents_dir_menu.siblings('ul').empty().append( createParentLinkItems() ); }
  1467.  
  1468. // MENUS: User Shortcuts
  1469. function shortcutMenuItems() {
  1470. const $shortcuts = $settings.shortcuts;
  1471. let menu_items = [];
  1472. let $links_arr = [];
  1473. let $links_arr_str = '';
  1474. let $links;
  1475. if ( $shortcuts.length > 0 ) {
  1476. for ( let i = 0; i < $shortcuts.length; i+=1 ) {
  1477. $links = $shortcuts[i].links;
  1478. // make array of links
  1479. for ( let j = 0; j < $links.length; j+=1 ) {
  1480. if ( !$links[j].link.endsWith('/') ) {
  1481. $links[j].link = $links[j].link.slice(0,$links[j].link.lastIndexOf('/') + 1) + '?file=' + $links[j].link.slice($links[j].link.lastIndexOf('/') + 1) ;
  1482. }
  1483. $links_arr[j] = '<li><a href="'+ $links[j].link +'">' + $links[j].link_name + '</a></li>';
  1484. }
  1485. $links_arr_str = $links_arr.join('');
  1486. menu_items[i] = '<li class="bookmarks has_submenu"><a>'+ $shortcuts[i].menu_title +'</a><ul>'+ $links_arr_str +'</ul></li>';
  1487. }
  1488. menu_items = menu_items.join('');
  1489. }
  1490. return menu_items;
  1491. }
  1492.  
  1493. // MENUS: Other menu items
  1494. const $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>');
  1495. const $autoload_media = $('<li class="toggle_UI_pref rule" id="autoload_media"><span id="autoload_media_menu">Autoload Media</span></li>');
  1496. const $theme = $('<li id="theme"><div><span class="toggle_UI_pref" id="theme_dark">Dark Theme</span><span class="toggle_UI_pref" id="theme_light">Light Theme</span></div></li>');
  1497. const $alternate_background = $('<li class="toggle_UI_pref" id="alternate_background"><span>Alternate Backgrounds</span></li>');
  1498. const $show_numbers = $('<li class="toggle_UI_pref rule" id="show_numbers"><span>Show Numbers</span></li>');
  1499. const $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>');
  1500. const $disable_text_editing = $('<li class="rule"><span class="toggle_UI_pref" id="enable_text_editing">Disable Text Editing</span></li>');
  1501. const $default_settings = $('<li><a href="#" id="default_settings" title="Delete URL query string and reload page.">Default User Settings</a></li>');
  1502. const $export_settings = $('<li class="rule"><a href="#" id="export_settings" title="Export user settings to text file.">Export User Settings</a></li>');
  1503. const $contact_link = $('<li><a id="contact" href="mailto:mshroud@vivaldi.net">Contact</a></li>');
  1504. const $donate_link = $('<li><a id="donate" href="https://paypal.me/mschrauzer" target="_blank">Donate</a></li>');
  1505.  
  1506. function assembleMenus() { // called by buildUI();
  1507. $parents_dir_menu.siblings('ul').empty().append( createParentLinkItems() );
  1508. $shortcuts_menu.siblings('ul').append( shortcutMenuItems(), $sort_by, $theme, $alternate_background, $show_numbers, $autoload_media, $text_editing, $disable_text_editing, $default_settings, $export_settings, $contact_link, $donate_link );
  1509. }
  1510. // ***** END BUILD MENUS ***** //
  1511.  
  1512. // ***** INDEX PREP ***** //
  1513. //
  1514. function getIndexType() {
  1515. // Try to determine index type from parent directory link container,
  1516. // with fallbacks for indexes that don't have parent directories,
  1517. // or for parent directory links that aren't siblings or ancestors of the index itself.
  1518. let parentLinkParent; // Possible elements: pre, li, td, th, div -- used to determine index type
  1519. // Try to find parent directory link:
  1520. let parentLink = $('a:contains("Parent Directory"), a:contains("parent directory"), a[href="../"], a[href="/"], a[href^="?"], img[alt*="PARENTDIR"]');
  1521. if ( parentLink.length === 0 ) {
  1522. parentLinkParent = $('body').find('> ul li, > pre, > table:last-of-type tr td');
  1523. } else {
  1524. parentLinkParent = parentLink.parent(); // use original found parentLink
  1525. }
  1526. // If no parentLinkParent found, type = error; else return parent node name
  1527. let nodeName = ( parentLinkParent[0] !== undefined ? parentLinkParent[0].nodeName.toLowerCase() : '');
  1528. if ( parentLinkParent.length === 0 ) {
  1529. nodeName = 'error';
  1530. } else if ( $protocol.startsWith('file') ) {
  1531. if ( navigator.userAgent.indexOf('Firefox') > 0 ) {
  1532. nodeName = 'gecko';
  1533. }
  1534. }
  1535. let types = {'gecko':'gecko','li':'list','pre':'pre','th':'table','td':'table','div':'default','error':'error'};
  1536. let type = types[nodeName];
  1537.  
  1538. if ( type === 'table' ) {
  1539. parentLinkParent.closest('table').addClass('PARENTTABLE');
  1540. }
  1541. if ( type === 'list' ) {
  1542. parentLink.closest('ul').addClass('PARENTLIST');
  1543. }
  1544. return type;
  1545. }
  1546.  
  1547. // Return Index items, Index type, remove parent directory link, and add body class.
  1548. function getIndexItems(el) {
  1549. const type = getIndexType();
  1550. let items;
  1551.  
  1552. switch(type) {
  1553. case 'gecko':
  1554. $(el).addClass('is_converted_gecko');
  1555. items = $('body').find('> table > tbody');
  1556. break;
  1557. case 'list':
  1558. $(el).addClass('is_converted_list');
  1559. items = $('body').find('> ul');
  1560. break;
  1561. case 'pre':
  1562. $(el).addClass('is_converted_pre');
  1563. items = $('body').find('> pre').html();
  1564. break;
  1565. case 'table':
  1566. case 'td':
  1567. $(el).addClass('is_converted_table');
  1568. if ( $('table.PARENTTABLE > tbody').length === 1 ) {
  1569. items = $('table.PARENTTABLE > tbody');
  1570. } else {
  1571. items = $('table.PARENTTABLE'); // tables without tbody
  1572. }
  1573. break;
  1574. case 'default': // local chrome default
  1575. $(el).addClass('is_default');
  1576. items = $('body').find('> table').find('> tbody');
  1577. break;
  1578. case 'error': // error
  1579. $(el).addClass('is_error');
  1580. items = $('body').html();
  1581. break;
  1582. }
  1583. return [items,type];
  1584. }
  1585.  
  1586. // Index Prep: convert rows and return array of rows, with link, size, date-modified
  1587. function convertIndexItems(type,items) {
  1588. let converted = [];
  1589. switch(type) {
  1590. case 'gecko':
  1591. converted = convertGeckoType(items);
  1592. break;
  1593. case 'list':
  1594. converted = convertListType(items);
  1595. break;
  1596. case 'pre':
  1597. converted = convertPreType(items);
  1598. break;
  1599. case 'table':
  1600. case 'default': // local chrome indexes
  1601. converted = convertTableType(type,items);
  1602. break;
  1603. case 'error':
  1604. converted = convertErrorType(items);
  1605. break;
  1606. }
  1607. return converted;
  1608. }
  1609. // Index Prep: convert list type function
  1610. function convertGeckoType(items) {
  1611. let preppedIndex = [];
  1612. const rows = Array.from(items.find('> tr'));
  1613. for ( let row of rows ) {
  1614. let preppedRow = [];
  1615. let cellContents = '';
  1616. let cells = Array.from( $(row).find('> td') );
  1617. let link = ($(cells).find('a').attr('href'));
  1618. for ( let cell of cells ) {
  1619. cellContents = cell.innerText;
  1620. cellContents = ( cellContents !== undefined ? cellContents.trim() : '');
  1621. preppedRow.push(cellContents);
  1622. }
  1623. preppedRow[1] = preppedRow[1].replace(' KB','000'); // convert reported size in KB to total bytes
  1624. preppedRow[2] = preppedRow[2] + ' '+ preppedRow[3];
  1625. preppedRow = preppedRow.slice(1,-1);
  1626. if ( link.length > 0 && link !== '/' && link !== '../' ) {
  1627. preppedRow.unshift(link);
  1628. }
  1629. if ( preppedRow.length > 0 ) { preppedIndex.push(preppedRow); }
  1630. }
  1631. return preppedIndex;
  1632. }
  1633. // Index Prep: convert list type function
  1634. function convertListType(items) {
  1635. let preppedIndex = [];
  1636. const rows = Array.from(items.find('li'));
  1637. for ( let row of rows ) {
  1638. if ( row.innerHTML.indexOf('Parent Directory') === -1 ) {
  1639. let preppedRow = [];
  1640. let link = $(row).find('a').attr('href');
  1641. row = row.innerHTML.replace(/<a .+?<\/a>\s*/,'');
  1642. let cells = row.split(' ');
  1643. for ( let cell of cells ) {
  1644. if ( cell.trim().length > 0 ) {
  1645. preppedRow.push(cell);
  1646. }
  1647. }
  1648. if ( link.length > 0 && link !== '/' && link !== '../' ) {
  1649. preppedRow.unshift(link);
  1650. }
  1651. if ( preppedRow.length > 0 ) {
  1652. preppedIndex.push(preppedRow);
  1653. }
  1654. }
  1655. }
  1656. return preppedIndex;
  1657. }
  1658. // Index Prep: convert pre type function
  1659. function convertPreType(items) {
  1660. let preppedIndex = [];
  1661. items = items.replace(/<a /g,' <a ').replace(/<\/a>/g,'</a> ') // ensure two spaces after file links
  1662. .replace(/\[\s*?\]/g,'[]'); // remove empty 'alt=[ ]'
  1663. const rows = items.split('\n');
  1664. const spaces = /\s{2,}/; // assumes pre type only uses spaces between "columns"
  1665.  
  1666. for ( let row of rows ) {
  1667. let preppedRow = [];
  1668. row = row.replace(/(<a[^>]+?>).+?<\/a>/g,'$1'); // remove link display name because some have 2+ spaces, leading to incorrect split for cells array
  1669. let cells = row.split(spaces);
  1670. let link;
  1671. for ( let cell of cells ) {
  1672. if ( cell.trim().length > 0 ) {
  1673. if ( cell.indexOf('href="') > 0 && cell.search(/href="[?|\/"]|Parent Directory/) === -1 ) {
  1674. link = $(cell).attr('href');
  1675. } else {
  1676. if ( cell.search(/href="|<img |<hr>/) === -1 ) {
  1677. preppedRow.push(cell);
  1678. }
  1679. }
  1680. }
  1681. }
  1682. if ( link !== undefined ) { preppedRow.unshift(link); } // add link to front of preppedRow
  1683. if ( preppedRow.length > 1 ) { preppedIndex.push(preppedRow); }
  1684. }
  1685. return preppedIndex;
  1686. }
  1687. // Index Prep: convert table type function
  1688. function convertTableType(type,items) { // for local chrome indexes and server-generated table-type indexes
  1689. let preppedIndex = [];
  1690. const rows = Array.from(items.find('> tr:not(.PARENT)'));
  1691. for ( let row of rows ) {
  1692. if (row.innerText.search(/Parent Directory/) === -1 ) {
  1693. let preppedRow = [];
  1694. let cells = Array.from( $(row).find('td') );
  1695. let link = $(cells).find('a').attr('href');
  1696. for ( let cell of cells ) {
  1697. cell = cell.innerHTML.trim();
  1698. if ( cell.length > 0 && cell.search(/^&nbsp;$|href="|<img /m) === -1 ) {
  1699. preppedRow.push( cell );
  1700. }
  1701. }
  1702. if ( link !== undefined ) { preppedRow.unshift(link); }
  1703. if ( preppedRow.length > 1 ) { preppedIndex.push(preppedRow); } // preppedRow.length > 2 in order to omit parent directory row
  1704. }
  1705. }
  1706. return preppedIndex;
  1707. }
  1708. // Index Prep: convert error pages (page not found, etc.)
  1709. function convertErrorType(items) {
  1710. items = items.replace(/ style="[^"]*?"/g,'').replace(/<hr>/g,'');
  1711. items = '<div id="error_message"><div id="error_message_icon"></div>'+ items +'</div>';
  1712. return items;
  1713. }
  1714.  
  1715. // Index Prep: Build new Index from prepped rows
  1716. function buildNewIndex(preppedIndex,sort) {
  1717. let newIndexItems = [];
  1718. let i = 0;
  1719. for ( let row of preppedIndex ) {
  1720. // Get row attrs and text
  1721. var rowLink = row[0] !== undefined ? row[0].replace(/&amp;/g,'&') : '';//.replace(//,''); // decode some reserved characters
  1722. const rowName = getItemName(rowLink).replace(/^\s/m,'\&nbsp;').replace(/^\//m,'').replace(/([-_——])/g,'$1<wbr>'); // display name, with word breaks added after unbreakable chars
  1723. const rowSortName = getItemName(rowLink).replace(/^\//m,'').replace('/','').toLocaleLowerCase();
  1724. const sizesAndDates = getItemSizeAndDate(row);
  1725. const rowSize = sizesAndDates[0];
  1726. const rowSortSize = sizesAndDates[1];
  1727. const rowDate = sizesAndDates[2];
  1728. const rowSortDate = sizesAndDates[3];
  1729. const rowExt = getItemExt(rowLink);
  1730. const rowSortKind = getItemKind(rowExt);
  1731. const rowKind = rowSortKind.slice(0,1).toUpperCase() + rowSortKind.slice(1);
  1732. const rowClasses = getItemClasses(rowName,rowSortKind,rowExt);
  1733. // Assemble row elements
  1734. let newRow = $('<tr></tr>').attr('id','rowid-'+ i).addClass(rowClasses).attr('data-kind',rowSortKind).attr('data-ext',rowExt);
  1735. const checkbox = ( rowClasses.indexOf('media') > 0 ? $('<input type="checkbox" tabindex="-1" checked="true" />') : '' );
  1736. const nameSpan = $('<span></span>').append(checkbox, rowName);
  1737. const cellLink = $('<a></a>').addClass('icon').attr('href',rowLink).append(nameSpan);
  1738. const cellName = $('<td></td>').addClass('name').attr('data-name',rowSortName).append(cellLink);
  1739. const cellSize = $('<td></td>').addClass('size details').attr('data-size',rowSortSize).append(rowSize);
  1740. const cellDate = $('<td></td>').addClass('date details').attr('data-date',rowSortDate).append(rowDate);
  1741. const cellKind = $('<td></td>').addClass('kind details').attr('data-kind',rowSortKind).append(rowKind);
  1742. const cellExt = $('<td></td>').addClass('ext details').attr('data-ext',rowExt);
  1743. // Assemble row
  1744. newRow.append(cellName, cellSize, cellDate, cellKind, cellExt);
  1745. newIndexItems.push(newRow[0]);
  1746. i++;
  1747. }
  1748. if ( sort === undefined ) { sort = getQuery('sort_by'); }
  1749. let sortedIndexItems = sortDirList($(newIndexItems), 'sort_by_'+ sort, 1); // initial sort
  1750. return sortedIndexItems;
  1751. }
  1752. // Index Prep: get row name
  1753. function getItemName(link) {
  1754. let name;
  1755. try { name = decodeURIComponentSafe(link); }
  1756. catch (error) { name = link.replace(/%20/g,' ').replace(/\s{2,}/,' '); }
  1757.  
  1758. if ( name.split('/').length > 2 ) { // get name only if x = full path
  1759. let arr = name.split('/');
  1760. if ( name.startsWith('/') && name.endsWith('/') ) { // dirs
  1761. name = arr[arr.length - 2] + '/';
  1762. } else {
  1763. name = arr[arr.length - 1]; // files
  1764. }
  1765. }
  1766. return name;
  1767. }
  1768. // Index Prep: get row classes
  1769. function getItemClasses(name,kind,ext) {
  1770. let itemClasses = [];
  1771. itemClasses.push(kind);
  1772. if ( ext.search(/dir|app/) === -1 ) {
  1773. itemClasses.push('file');
  1774. }
  1775. if ( name.indexOf('.') === 0 ) {
  1776. itemClasses.push('invisible');
  1777. }
  1778. if ( !JSON.stringify($row_types).match( escapeStr(ext) ) ) { // else classify as "other" if extension is not in $row_types.
  1779. itemClasses.push('other'); //itemType = 'Other'; itemKind = 'other';
  1780. } else if ( kind === '' ) {
  1781. // itemClasses.push('code'); //itemType = 'Code'; itemKind = 'code';
  1782. } else {
  1783. itemClasses.push(ext);
  1784. }
  1785. if ( $row_settings.ignore.includes( ext ) ) {
  1786. itemClasses.push('ignore');
  1787. }
  1788. if ( $row_settings.exclude.includes( ext ) ) {
  1789. itemClasses.push('exclude');
  1790. }
  1791. if ( kind === 'audio' || kind === 'video' ) {
  1792. itemClasses.push('media');
  1793. }
  1794. itemClasses = Array.from(new Set(itemClasses)); // remove dupe classes
  1795. return itemClasses.join(' ');
  1796. }
  1797. // Index Prep: get formatted row size and date
  1798. function getItemSizeAndDate(cells) {
  1799. let sizesAndDates = [];
  1800. let rowDisplaySize, rowSortSize, rowDisplayDate, rowSortDate;
  1801. if ( cells.length > 1 ) {
  1802. if ( cells[1].search(/[-:\/]/) !== -1 ) {
  1803. rowDisplayDate = cells[1]; rowDisplaySize = cells[2];
  1804. } else {
  1805. rowDisplayDate = cells[2]; rowDisplaySize = cells[1];
  1806. }
  1807. }
  1808. // size
  1809. let sizeUnits = /[bytes\b|k|kb|mb|gb|tb|pb|eb|zb|yb]/;
  1810. if ( rowDisplaySize === undefined || rowDisplaySize === '' || rowDisplaySize === '-' ) {
  1811. rowDisplaySize = '&mdash;'; rowSortSize = '0';
  1812. } else {
  1813. rowSortSize = getItemSortSize(rowDisplaySize);
  1814. if ( !rowDisplaySize.toLowerCase().match(sizeUnits) ) {
  1815. rowDisplaySize = formatBytes(rowDisplaySize,1);
  1816. } else {
  1817. rowDisplaySize = rowDisplaySize.toUpperCase().replace(/(\d+)([A-z])/,'$1 $2');
  1818. }
  1819. }
  1820. // date modified
  1821. if ( rowDisplayDate === undefined || rowDisplayDate === '' || rowDisplayDate === '-' ) {
  1822. rowDisplayDate = '&mdash;'; rowSortDate = '0';
  1823. } else {
  1824. rowSortDate = getItemDate(rowDisplayDate);
  1825. }
  1826. sizesAndDates.push(rowDisplaySize,rowSortSize,rowDisplayDate,rowSortDate);
  1827. return sizesAndDates;
  1828. }
  1829. // Index Prep: get row size for sorting
  1830. function getItemSortSize(val) {
  1831. let sortSize;
  1832. let size = val.replace('&mdash;','0').replace(/[A-z\s]+/,'').trim(); // = any non-alpha chars, i.e. numbers
  1833. const unit = val.replace('&mdash;','B').replace(/[\d\\.]+/g,'').trim(); // = any non-numeric chars
  1834. 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 }; // unit to file size
  1835. sortSize = size * factor[unit]; // convert byte size to multiplication factor
  1836. return sortSize;
  1837. }
  1838. // convert numerical-only sizes to display format
  1839. function formatBytes(val, decimals) {
  1840. if (val === 0) return '0 Bytes';
  1841. const k = 1024;
  1842. const dm = decimals < 0 ? 0 : decimals;
  1843. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  1844. const i = Math.floor(Math.log(val) / Math.log(k));
  1845. return parseFloat((val / Math.pow(k, i)).toFixed(dm)) +' '+ sizes[i];
  1846. }
  1847. // process date
  1848. function processDate(match,p1,p2,p3) { //date formats: 2017-10-09 13:12 || 2015-07-25T02:02:57.000Z || 12-Mon-2017 21:11
  1849. const mo = 'JanFebMarAprMayJunJulAugSepOctNovDec'.indexOf(p2)/3 + 1; // e.g., convert month into number, or use number
  1850. return p3 +'-'+ mo +'-'+ p1;
  1851. }
  1852. // Index Prep: get row date 2015-07-25T02:22:00.000Z
  1853. function getItemDate(val) {
  1854. let sortDate = val.replace(/^(\d{2})-(\w{3})-(\d{4})/m, processDate) // convert Month to number
  1855. .replace(/\b(\d{1})[-:\/]/g,'0$1/') // add leading 0 for single digit numbers
  1856. .replace(/(\d{2})\/(\d{2})\/(\d{2}),/,'$3$1$2') // reorder MM/DD/YY dates
  1857. .replace(/-|:|\s+|\//g,''); // remove spacing characters
  1858. return sortDate;
  1859. }
  1860. // Index Prep: get row kind
  1861. function getItemKind(ext) {
  1862. let kind = '';
  1863. if ( ext === 'dir' || ext === 'app' ) {
  1864. kind = ext;
  1865. } else {
  1866. for ( let types in $row_types ) {
  1867. if ( $row_types[types].includes( ext ) ) {
  1868. kind = types;
  1869. return kind;
  1870. }
  1871. }
  1872. }
  1873. if ( kind === '' ) { kind = 'other'; }
  1874. return kind;
  1875. }
  1876. // Index Prep: get row extension
  1877. function getItemExt(link) {
  1878. let ext = '';
  1879. if ( ext.endsWith('app/') || ext.endsWith('exe') ) {
  1880. ext = 'app';
  1881. } else if ( link.endsWith('/') ) {
  1882. ext = 'dir';
  1883. } else if ( link.indexOf('.') < 0 ) { // if no '.' in link, ...
  1884. ext = link.slice(link.lastIndexOf('/') + 1).toLowerCase();
  1885. } else { // find the last . and get the remaining characters
  1886. ext = link.slice(link.lastIndexOf('.') + 1).toLowerCase();
  1887. }
  1888. return ext;
  1889. }
  1890. // END INDEX PREP
  1891. // ***** MAKE NEW INDEX ***** //
  1892. function makeNewIndex(el,sort) {
  1893. const indexItems = getIndexItems(el);
  1894. const items = indexItems[0];
  1895. const type = indexItems[1];
  1896. const convertedIndex = convertIndexItems( type, items ); // = array of rows: ["link","date","size"]
  1897. if ( type === 'error' ) {
  1898. return [convertedIndex];
  1899. } else {
  1900. let newIndex = buildNewIndex( convertedIndex, sort );
  1901. return [newIndex];
  1902. }
  1903. }
  1904. function appendNewIndex(body_top) { // setUpUI();
  1905. const newIndex = makeNewIndex(body_top);
  1906. $dir_list_body.append( newIndex);
  1907. $tfoot.find('#stats').html(getIndexStats($dir_list.find('#tbody tr')));
  1908. }
  1909. // get and set index stats
  1910. function getIndexStats(el) {
  1911. const total = el.length;
  1912. const dirs = el.filter('.dir').length;
  1913. const files = el.filter('.file').length;
  1914. const stats = total +' items: '+ dirs +' directories, '+ files +' files';
  1915. return stats;
  1916. }
  1917. // ***** END DIR_LIST SETUP ***** //
  1918.  
  1919. // ***** UI SETUP ***** //
  1920. // Build UI: Append all assembled elements to $body
  1921. function setUpBody() {
  1922. if ( window.self === window.top ) { // if it's an iframe...
  1923. $('head').prepend('<meta charset="utf-8">');
  1924. $('body').attr('id','top').attr('lang','en').find('script').remove();
  1925. } else {
  1926. $('body').attr('id','iframe_body');
  1927. }
  1928. }
  1929. function buildUI() {
  1930. setUpBody();
  1931. addStyles( $('body#top').prev('head') );
  1932. assembleUIElements();
  1933. assembleMenus();
  1934. if ( window.self === window.top ) {
  1935. appendNewIndex($('body#top'));
  1936. }
  1937. $main_content.find('tr').append( $sidebar_wrapper, $content_pane );
  1938. $('body#top').empty().append($main_content);
  1939. }
  1940. buildUI();
  1941.  
  1942. const $body = $('body#top');
  1943. const $iframe_body = $('body#iframe_body');
  1944. const $iFrame_head = $iframe_body.prev('head');
  1945. const $dir_list_row = $dir_list_body.find('> tr');
  1946. const $audio_files = $dir_list_body.find('.audio');
  1947. const $font_files = $dir_list_body.find('.font');
  1948. const $image_files = $dir_list_body.find('.image');
  1949. const $media_files = $dir_list_body.find('.media');
  1950. const $video_files = $dir_list_body.find('.video');
  1951. function $selected_file() { return $dir_list_body.find('.selected'); }
  1952. function $playing_file() { return $dir_list_body.find('.playing'); }
  1953.  
  1954. // UI Setup: build UI and add body classes and other initial settings
  1955. function setupUIprefs() {
  1956. for ( let key in $settings ) {
  1957. if ( getQuery(key) === 'true' ) {
  1958. $body.addClass(key);
  1959. } else { // non-boolean settings and others
  1960. if ( key === 'theme' ) { $body.addClass( 'theme_'+ getQuery('theme') ); }
  1961. if ( key === 'sort_by' ) {
  1962. $body.addClass( 'sort_by_'+ getQuery(key) );
  1963. $('#theader').find('th[id="sort_by_'+ getQuery(key) +'"]').addClass('up');
  1964. }
  1965. if ( key === 'default_text_view' ) {
  1966. if ( getQuery(key) === 'source_text' ) { $body.addClass('source_text'); } else { $body.addClass('preview_text'); }
  1967. }
  1968. if ( getQuery('toggle_sidebar') === 'true' ) { $body.addClass( 'has_hidden_sidebar' ); }
  1969. }
  1970. }
  1971. if ( navigator.userAgent.indexOf('Chrome') > 0 ) { $body.addClass('is_chrome'); }
  1972. if ( navigator.userAgent.indexOf('Firefox') > 0 ) { $body.addClass('is_gecko'); }
  1973. if ( $audio_files.length > 0 ) { $body.add($dir_list).addClass('has_audio has_media'); }
  1974. if ( $font_files.length > 0 ) { $body.addClass('has_fonts'); }
  1975. if ( $image_files.length > 0 ) { $body.addClass('has_images'); }
  1976. if ( $video_files.length > 0 ) { $body.add($dir_list).addClass('has_video has_media'); }
  1977. // UI Setup: show invisibles
  1978. if ( navigator.platform.indexOf('Win') > -1 || $location.indexOf('file:') < 0 ) {
  1979. $inv_checkbox.hide();
  1980. } else if ( $body.hasClass('show_invisibles') ) {
  1981. $inv_checkbox.find('input').attr('checked','checked');
  1982. }
  1983. }
  1984. // Get DOMTokenList of body classes
  1985. function getClassList(id) { return document.getElementById(id).classList; }
  1986. //
  1987. function setUpUI() {
  1988. if ( window.self === window.top) {
  1989. setupUIprefs();
  1990. initMedia();
  1991. autoSelectFile();
  1992. autoLoadCoverArt();
  1993. setContentTitle();
  1994. setContentHeight();
  1995. } else {
  1996. setUpIframeUI( getQuery('enable_text_editing') );
  1997. }
  1998. }
  1999. setUpUI();
  2000.  
  2001. // SET UI TO DEFAULT SETTINGS: remove queries;
  2002. function defaultSettings() {
  2003. let $location = window.location.href;
  2004. $location = $location.slice(0,$location.lastIndexOf('?'));
  2005. window.location.assign($location);
  2006. }
  2007. $default_settings.on('click', function() {
  2008. 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.' ) ) {
  2009. defaultSettings();
  2010. }
  2011. });
  2012. // EXPORT SETTINGS
  2013. function saveSettings(filename, data) {
  2014. const blob = new Blob([data], {type: 'text/html'});
  2015. const elem = window.document.createElement('a');
  2016. elem.href = window.URL.createObjectURL(blob);
  2017. elem.download = filename;
  2018. document.body.appendChild(elem);
  2019. elem.click();
  2020. document.body.removeChild(elem);
  2021. URL.revokeObjectURL(blob);
  2022. }
  2023. $export_settings.on('click','a',function(e) {
  2024. e.preventDefault();
  2025. const $settings_string = ( JSON.stringify($settings,null,'\t'));
  2026. saveSettings('settings.txt',$settings_string);
  2027. });
  2028.  
  2029. // Click Menu Link (with warning)
  2030. function setLocation(link) { window.location = link; }
  2031. $('#parent_dir_menu,#parents_dir_menu + .menu,#shortcuts').on('click','a',function(e) {
  2032. e.preventDefault();
  2033. if ( $(this).attr('href').indexOf('file://') > -1 && $protocol !== 'file:' ) {
  2034. $body.addClass('has_warning').find('#warnings').addClass('local');
  2035. } else {
  2036. showWarning( 'setLocation', thisLink($(this)) );
  2037. }
  2038. });
  2039. // Show Menus
  2040. function showMenus(el) {
  2041. let $position = $(el).position();
  2042. $(el).find('> ul').css({'top':$position.top + $(el).innerHeight() + 'px'}).toggle().parent('td').siblings('td').find('.menu').hide();
  2043. }
  2044. $parents_dir_menu.add($shortcuts_menu).parent('td').on('click',function(e) {
  2045. e.stopPropagation();
  2046. showMenus(this);
  2047. });
  2048. // Hide Menus
  2049. $(document).on('click', function() { $('.menu').hide(); });
  2050.  
  2051. // Toggle UI Preferences
  2052. function toggleUIpref(prefID) {
  2053. let prefClass = prefID;
  2054. if ( prefID === 'split_view' ) { sendMessage('iframe','split_view'); }
  2055. if ( prefID.startsWith('sort_by') ) { $body.removeClass('sort_by_default sort_by_name sort_by_size sort_by_date sort_by_kind sort_by_ext'); }
  2056. if ( prefID.startsWith('theme') ) { prefClass = 'theme_dark theme_light'; }
  2057. if ( prefID.endsWith('text') && !$body.hasClass(prefID) ) {
  2058. sendMessage('iframe','default_text_view');
  2059. $body.toggleClass('preview_text source_text');
  2060. }
  2061. toggleQuery(prefID);
  2062. $body.toggleClass(prefClass);
  2063. setContentHeight();
  2064. if ( prefID === 'enable_text_editing' ) { $('.selected.text, .selected.markdown').click(); }
  2065. // $('#shortcuts').hide(); // don't hide menus after click?
  2066. }
  2067. // Click Toggle UI Pref elements
  2068. $('.toggle_UI_pref').on('click',function(e) {
  2069. if ( !$(this).is('input') ) {
  2070. e.preventDefault(); // allow checkboxes to be checked
  2071. }
  2072. toggleUIpref( $(this).attr('id') );
  2073. });
  2074.  
  2075. // Toggle Sidebar
  2076. function toggleSidebar() {
  2077. $body.toggleClass('has_hidden_sidebar');
  2078. if ( $body.hasClass('has_hidden_sidebar') ) { setQuery('toggle_sidebar','true'); } else { removeQuery('toggle_sidebar'); }
  2079. setContentHeight();
  2080. scrollThis('tbody','selected',true); // true = instant scroll
  2081. }
  2082. $toggle_sidebar.on('click', function() {
  2083. toggleSidebar();
  2084. });
  2085.  
  2086. // RESIZE Sidebar/Content Pane
  2087. function resizeSidebar(f) {
  2088. f.stopPropagation();
  2089. const $startX = f.pageX;
  2090. let $window_width = window.innerWidth;
  2091. let $sidebar_width = $sidebar_wrapper.width();
  2092. $('#overlay').css({'display':'block','z-index':'1'});
  2093. $('#handle').css({'z-index':'9999'});
  2094. $body.css({'-moz-user-select':'none','user-select':'none'});
  2095.  
  2096. $(document).on('mousemove',function(e) {
  2097. e.stopPropagation();
  2098. e.preventDefault();
  2099. const $deltaX = e.pageX - $startX;
  2100. if ( e.pageX > 230 && e.pageX < $window_width - 200 ) {
  2101. $sidebar_wrapper.css({'width':$sidebar_width + $deltaX + 'px'});
  2102. $content_pane.css({'width':($window_width - $sidebar_width) - $deltaX + 'px'});
  2103. }
  2104. setContentHeight();
  2105. });
  2106. $(document).on('mouseup',function() {
  2107. $('#overlay').css({'display':'none','z-index':'unset'});
  2108. $('#handle').css({'z-index':'unset'});
  2109. $body.css({'-moz-user-select':'unset','user-select':'unset'});
  2110. $(document).off('mousemove');
  2111. $sidebar_width = $sidebar_wrapper.width();
  2112. setQuery('width',$sidebar_width);
  2113. });
  2114. }
  2115. $handle.on('mousedown', function(f) {
  2116. f.stopPropagation();
  2117. resizeSidebar(f);
  2118. });
  2119.  
  2120. // ***** BASIC UI FUNCTIONS ***** //
  2121. // Get dir_list item row
  2122. function thisRow(x) {
  2123. return $(x).closest('#dir_list > tbody > tr').length > 0 ? $(x).closest('#dir_list > tbody > tr') : $(x).closest('#dir_list > li');
  2124. }
  2125. function thisID(x) {
  2126. return thisRow(x).attr('id');
  2127. }
  2128. // Get row link
  2129. function thisLink(x) {
  2130. return $(x).find('a').length > 0 ? $(x).find('a').attr('href') : $(x).attr('href');
  2131. }
  2132. // Get row name
  2133. function thisText(x) {
  2134. return $(x).find('a span').length > 0 ? decodeURIComponentSafe( $(x).find('a span').text().toLocaleLowerCase() ) : decodeURIComponentSafe( $(x).text().toLocaleLowerCase() );
  2135. }
  2136. // get row text
  2137. function thisExt(x) {
  2138. let $this_name = thisText(x);
  2139. return $this_name.endsWith('app/') ? 'app' : $this_name.endsWith('/') ? '/' : $this_name.lastIndexOf('.') === -1 ? undefined : $this_name.toLocaleLowerCase().slice( $this_name.lastIndexOf('.') + 1 );
  2140. }
  2141. function getElById(id) {
  2142. return $(document.getElementById(id) );
  2143. }
  2144.  
  2145. // SET CONTENT HEIGHT
  2146. function setContentHeight() {
  2147. // accommodate multi-line title names in preview pane
  2148. if ( $title.outerWidth() > ( $('#content_title').innerWidth() - 2 * $('#title_buttons_left').outerWidth() ) ) {
  2149. $title.css({'margin-top':'2em'});
  2150. } else {
  2151. $title.css({'margin-top':'0'});
  2152. }
  2153. let $window_height = window.innerHeight;
  2154. let $content_header_height = $content_header.outerHeight();
  2155.  
  2156. $sidebar.add($main_content).add($content_pane).css({'height':$window_height });
  2157. $dir_list.css({'height':$window_height - $('#sidebar_header').outerHeight(), 'max-height':$window_height - $('#sidebar_header').outerHeight() });
  2158. $dir_list_body.css({'top': $dir_list_head.outerHeight(),'bottom': $dir_list.find('tfoot').outerHeight(),'height': $dir_list.innerHeight() - $dir_list_head.outerHeight() - $dir_list.find('tfoot').outerHeight(),'max-height': $dir_list.innerHeight() - $dir_list_head.outerHeight() - $dir_list.find('tfoot').outerHeight() });
  2159. $('#iframe_body').find('#tbody').css({'top':$('#iframe_body').find('#thead').height() + 1 +'px'});
  2160.  
  2161. $prev_track.add($next_track).add($close_audio).css({'height':$('#audio').height() }); // set height of audio controls
  2162. $content_container.css({'top':$content_header_height +'px' });
  2163. }
  2164. window.addEventListener('resize', setContentHeight );
  2165.  
  2166. // SET CONTENT TITLE
  2167. function setContentTitle() {
  2168. let $title_text = '';
  2169. if ( $playing_file().hasClass('audio') ) { // set audio player title
  2170. $content_audio_title.find('td').empty().text( $playing_file().find('td.name a').text() );
  2171. }
  2172. if ( $content_pane.hasClass('has_grid') ) { // set main title for other content
  2173. $title_text = $('#parents_dir_menu').find('> div').html().split('<wbr>').reverse()[1];
  2174. } else if ( $('#toggle_info').hasClass('selected') ) {
  2175. $title_text = 'Source of: '+ $current_dir_path;
  2176. } else if ( $body.hasClass('has_text') ) {
  2177. $title_text = 'Text Editor';
  2178. } else if ( $selected_file().hasClass('audio') ) {
  2179. return;
  2180. } else if ( !$selected_file().hasClass('audio') || $content_pane.hasClass('has_hidden_text') ) {
  2181. $title_text = $selected_file().not('.audio').find('td.name a span').text(); // Assemble title
  2182. }
  2183. if ( $content_pane.hasClass('has_image') ) {
  2184. setDimensions($('.selected.image'));
  2185. } else {
  2186. $title.attr('data-after',''); // remove image dimensions
  2187. }
  2188. $title.empty().html($title_text);
  2189. if ( $title.outerWidth() > ( $('#content_title').innerWidth() - 2 * $('#title_buttons_left').outerWidth() ) ) { $title.css({'margin-top':'2em'}); } else { $title.css({'margin-top':'0'}); }
  2190. }
  2191. // Get Image Dimensions
  2192. function getDimensions(link, callback) {
  2193. let img = new Image();
  2194. img.src = link;
  2195. img.onload = function() { callback( this.width, this.height ); };
  2196. }
  2197. function setDimensions(row) {
  2198. getDimensions( thisLink(row), function( width, height ) {
  2199. $title.attr('data-after',' (' + width + 'px × ' + height + 'px)');
  2200. });
  2201. }
  2202. // Scroll Selected Items
  2203. function scrollThis(elID,className,bool) {
  2204. let $behavior = 'smooth';
  2205. if ( bool !== undefined ) { $behavior = 'instant'; }
  2206. let $block = ( navigator.userAgent.indexOf('Firefox') > -1 ? 'start' : 'nearest' );
  2207. if ( document.getElementsByClassName(className).length > 0 ) {
  2208. document.getElementById(elID).getElementsByClassName(className)[0].scrollIntoView({ behavior:$behavior, block:$block, inline:'nearest' });
  2209. }
  2210. setContentHeight();
  2211. }
  2212.  
  2213. // ***** SORTING ***** //
  2214. function sortIndex(els,id,sortDirection) { // id = sort type
  2215. let sorted = [];
  2216.  
  2217. const newSort = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }); // needs to be above makeNewIndex()
  2218. sorted = els.removeClass('sorted').sort((a, b) => {
  2219. let aName = $(a).find('td.name').data('name');
  2220. let bName = $(b).find('td.name').data('name');
  2221. let aData = $(a).find('td[data-'+ id +']').data(id);
  2222. let bData = $(b).find('td[data-'+ id +']').data(id);
  2223. if ( sortDirection === 1 ) { // sort by detail data value, then by name (i.e., if data values are the same, sort by name)
  2224. if ( newSort.compare(aData, bData) === 0 ) {
  2225. return newSort.compare(aName, bName);
  2226. } else {
  2227. return newSort.compare(aData, bData);
  2228. }
  2229. } else { // reverse sort
  2230. if ( newSort.compare(bData, aData) === 0 ) {
  2231. return newSort.compare(bName, aName);
  2232. } else {
  2233. return newSort.compare(bData, aData);
  2234. }
  2235. }
  2236. });
  2237. sorted = sorted.sort((a, b) => { // add sorted style (rules between different rows)
  2238. if ( id === 'kind' || id === 'ext' && sortDirection === 1 ) {
  2239. if ( $(a).find('td[data-'+ id +']').data(id) !== $(b).find('td[data-'+ id +']').data(id) ) { $(a).addClass('sorted'); }
  2240. }
  2241. if ( id === 'kind' || id === 'ext' && sortDirection === -1 ) {
  2242. if ( $(b).find('td[data-'+ id +']').data(id) !== $(a).find('td[data-'+ id +']').data(id) ) { $(a).addClass('sorted'); }
  2243. }
  2244.  
  2245. });
  2246. return sorted;
  2247. }
  2248. // Sort the Dir List on click
  2249. function sortDirList(rows, id, sortDirection) {
  2250. const $sort_all = rows;
  2251. const $sort_dirs = $sort_all.filter('.dir:not(.app)');
  2252. const $sort_files = $sort_all.filter('.file,.app');
  2253. const $sort_id = id.slice(8);// === 'default' ? 'name' : id;
  2254.  
  2255. const $sorted_dirs = sortIndex($sort_dirs, $sort_id, sortDirection);
  2256. const $sorted_files = sortIndex( $sort_files, $sort_id, sortDirection );
  2257. const $sorted_all = sortIndex( $sort_all, $sort_id, sortDirection );
  2258. let $sorted = [];
  2259.  
  2260. if ( $sort_id === 'default' || ( $sort_id !== 'name' && $settings.dirs_on_top === true )) {
  2261. if (sortDirection === 1) {
  2262. $sorted = $.merge($sorted_dirs,$sorted_files);
  2263. } else {
  2264. $sorted = $.merge($sorted_files,$sorted_dirs);
  2265. }
  2266. } else {
  2267. $sorted = $sorted_all;
  2268. }
  2269. return $sorted;
  2270. }
  2271. // Sort on click
  2272. function clickSort(el) {
  2273. const id = el.attr('id'); // id from th sort item = 'sort_by_xxx'
  2274. var sortDirection = ( el.hasClass('up') ? -1 : 1 ); // Only reverse sort order after clicking a sort column once.
  2275. // SORT EM!
  2276. const $sorted_index = sortDirList( $dir_list_row, id, sortDirection );
  2277. $dir_list_body.append($sorted_index);
  2278. $('th[id="'+ id +'"]').toggleClass('up').siblings().removeClass('up');
  2279. if ( $content_grid.hasClass('has_font_grid') ) { $('#show_font_grid').click(); }
  2280. if ( $content_grid.hasClass('has_image_grid') ) { $('#show_image_grid').click(); }
  2281. if ( $content_grid.hasClass('has_grid') ) { $('#grid_btn').click(); }
  2282. setContentHeight();
  2283. }
  2284. // Sort on clicking dir_list sort item
  2285. $('#theader').on('click','th.sorting:not(.disabled)',function(e) {
  2286. e.preventDefault();
  2287. e.stopPropagation();
  2288. clickSort( $(this) );
  2289. });
  2290. // Sort Menu: click the list header that contains the selected menu text.
  2291. $('#sort_menu').on('click','li:not(.disabled)',function(e) {
  2292. e.preventDefault();
  2293. e.stopPropagation();
  2294. $('#theader th[id="sort_by_'+ $(this).attr('id') +'"]').click(); // click corresponding dir_list sort item
  2295. });
  2296. // ***** END SORTING ***** //
  2297. // ***** END BASIC UI FUNCTIONS ***** //
  2298.  
  2299. // ***** CONTENT PANE ***** //
  2300. // SELECT ROW on click and set classes for $content_pane
  2301. function selectThis(row) {
  2302. $('#toggle_info').removeClass('selected');
  2303. const $grid_selected = $content_grid.find('div.font_grid_item a[href="'+ thisLink(row) +'"]').closest('div').add('div.image_grid_item a[href="'+ thisLink(row) +'"]').closest('div').addBack();
  2304. if ( $content_pane.hasClass('has_grid') ) { // Select corresponding grid item
  2305. row.addClass('selected').siblings().removeClass('selected hovered');
  2306. $grid_selected.addClass('selected').siblings().removeClass('selected');
  2307. } else { // remove classes from rows, but leave .audio with playing
  2308. if ( row.attr('id') === 'toggle_info' ) {
  2309. row.toggleClass('selected loaded');
  2310. $dir_list.find('#tbody .selected').removeClass('selected');
  2311. } else {
  2312. row.addClass('selected').siblings().removeClass('selected hovered');
  2313. }
  2314. }
  2315. }
  2316.  
  2317. //***** SHOW CONTENT *****//
  2318. function showAudio(rowID) {
  2319. let row = getElById(rowID);
  2320. closeMedia('video');
  2321. if ( row.hasClass('audio') ) { row.addClass('playing selected').siblings('.media').removeClass('playing selected'); }
  2322. $audio_player.attr('src', thisLink( row ) );
  2323. $content_pane.addClass('has_audio');
  2324. $content_audio_title.find('td').empty().text( $playing_file().find('td.name a').text() );
  2325. // setContentTitle();
  2326. setContentHeight();
  2327. }
  2328. // Show Grid
  2329. function showGrid() {
  2330. $content_pane.removeClass('has_hidden_grid').addClass('has_grid');
  2331. closeMedia('video');
  2332. setContentTitle();
  2333. setContentHeight();
  2334. selectThis($selected_file());
  2335. }
  2336. // Show Font (and create font items)
  2337. function showFont(row,bool,sheet) { // bool = true if for show font grid, sheet defined at fontGridItems()
  2338. let fontStyles = $font_styles.sheet;
  2339. const $font_family = thisText(row);
  2340. const $font_url = thisLink(row);
  2341. const $font_grid_item_el = $('<div class="font_grid_item"></div>');
  2342. if ( bool === false ) {
  2343. if ( fontStyles.cssRules.length > 0 ) { fontStyles.deleteRule(0); } // delete previous @font-face rule
  2344. fontStyles.insertRule('@font-face { font-family: "'+ $font_family +'"; src: url("'+ $font_url +'"); }');
  2345. $content_font.css({ 'font-family':'"'+ $font_family +'"' }); // set content font style
  2346. } else {
  2347. let grid_item = $font_grid_item_el.clone();
  2348. const $display_name = $font_family;
  2349. sheet.insertRule('@font-face { font-family: "'+ $font_family +'"; src: url("'+ $font_url +'"); }');
  2350. grid_item.append('<p>'+ $display_name +'</p><h2 style=\'font-family: "'+ $font_family +'"\'; ><a href="'+ $font_url +'">'+ $display_name.slice(0,$font_family.lastIndexOf('.')) +'</a></h2>' );
  2351. return grid_item;
  2352. }
  2353. }
  2354. // Show/Hide Editor or Grid
  2355. function showEditorOrGrid() {
  2356. if ( $body.hasClass('has_hidden_text') ) { $body.toggleClass('has_text has_hidden_text'); }
  2357. if ( $content_pane.hasClass('has_hidden_grid') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  2358. }
  2359. function hideEditorOrGrid() {
  2360. if ( $body.hasClass('has_text') ) { $body.toggleClass('has_text has_hidden_text'); }
  2361. if ( $content_pane.hasClass('has_grid') ) { $content_pane.toggleClass('has_grid has_hidden_grid'); }
  2362. }
  2363. // Set Content Pane classes
  2364. function setContentClasses(content_el) {
  2365. if ( content_el === 'audio' ) {
  2366. $content_pane.addClass('has_audio');
  2367. } else {
  2368. hideEditorOrGrid();
  2369. let classes = ['has_font','has_image','has_zoom_image','has_pdf','has_video','has_iframe','has_dir','has_ignored'];
  2370. $content_pane.removeClass(classes.join(' ')).addClass( 'has_'+ content_el ); // remove classes, excluding grid and text classes; add content class
  2371. }
  2372. }
  2373. // Set Content Element Sources and row classes
  2374. function setContentSources(row,link,kind,content_el) {
  2375. switch(kind) {
  2376. case 'audio':
  2377. $audio_player.attr('src',link);
  2378. break;
  2379. case 'font':
  2380. showFont(row,false);
  2381. break;
  2382. case 'code':
  2383. case 'markdown':
  2384. case 'text':
  2385. link = thisLink(row) +'?split_view='+ getQuery('split_view') +'&default_text_view='+ getQuery('default_text_view');
  2386. if ( !$body.hasClass('enable_text_editing') ) { link += '&enable_text_editing=false'; } else { link += '&enable_text_editing=true'; }
  2387. break;
  2388. case 'dir':
  2389. link = link + '?sort_by=' + getQuery('sort_by') +'&show_numbers='+ getQuery('show_numbers');
  2390. break;
  2391. case 'info':
  2392. link = $location + '?sort_by=' + getQuery('sort_by') +'&show_numbers='+ getQuery('show_numbers') +'&view_source=true';
  2393. break;
  2394. case 'pdf':
  2395. link = link + '?#view=fitB&scrollbar=1&toolbar=1&navpanes=1';
  2396. break;
  2397. }
  2398. if ( kind === 'video' ) { row.addClass('playing'); } else { row.addClass('loaded'); }
  2399. // fix for pdfs not being loaded after setting src attribute (hide and then show)
  2400. if ( kind === 'pdf' ) {
  2401. $('#content_'+ content_el).addClass('has_content').hide().attr('src',link).show().removeAttr('srcdoc');
  2402. } else {
  2403. $('#content_'+ content_el).addClass('has_content').attr('src',link).removeAttr('srcdoc');
  2404. }
  2405. }
  2406. // Show Content
  2407. function showContent(row) { // show any content excluding grids on row click
  2408. if ( row.length === -1 ) { return; } // needed for left/right arrow nav when there are no valid items (i.e. images or fonts)
  2409.  
  2410. let rowID = row.attr('id');
  2411. let kind = row.attr('data-kind');
  2412. let link = thisLink(row);
  2413. 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
  2414. if ( row.hasClass('audio') ) {
  2415. showAudio( rowID );
  2416. } else {
  2417. closeContentEls(row);
  2418. setContentClasses(content_el);
  2419. setContentSources(row,link,kind,content_el);
  2420. setContentTitle();
  2421. setContentHeight();
  2422. row.siblings().removeClass('loaded');
  2423. }
  2424. }
  2425.  
  2426. //***** CLOSE CONTENT (Close button or Cmd/Ctrl + W) *****//
  2427. // Close Audio/Video
  2428. function closeMedia(type) { // type === audio || video
  2429. let $mediaEl = ( type === 'audio' ? $audio_player : $content_video );
  2430. $('.media.playing, .media.loaded').removeClass('playing loaded');
  2431. $content_pane.removeClass('has_'+ type);
  2432. $mediaEl.trigger('pause').attr('src','');
  2433. if ( type === 'audio' ) { $('#content_audio_title td').empty(); }
  2434. // if ( type === 'video' ) { $title.empty(); }
  2435. setContentHeight();
  2436. }
  2437. // Close Audio button click
  2438. $close_audio.on('click',function(e) {
  2439. e.stopPropagation();
  2440. closeMedia('audio');
  2441. $('.audio.selected').removeClass('selected');
  2442. if ( $('.loaded').length === 1 ) { $('.loaded').addClass('selected'); }
  2443. });
  2444. // Close Text Editor
  2445. // Close Grid
  2446. function closeGrid() {
  2447. $content_pane.removeClass('has_grid');
  2448. $content_grid.empty().removeClass().attr('style','').find('.image_grid_item, img').attr('style','');
  2449. }
  2450. // Close .content elements (not #content_audio, #content_text, or #content_grid) when opening new content
  2451. function closeContentEls(row) {
  2452. // close media
  2453. if ( row !== undefined ) {
  2454. if ( row.hasClass('video') ) {
  2455. closeMedia('audio');
  2456. } else if ( row.hasClass('audio') ) {
  2457. closeMedia('video');
  2458. }
  2459. }
  2460. // close content
  2461. if ( $('body').hasClass('has_text') && $(this).hasClass('selected') ) { // if text editor visible, just hide it and show selected item
  2462. $('body').removeClass('has_text').addClass('has_hidden_text');
  2463. } else if ( $('.content.has_content').length ) {
  2464. let $contentID = $('.content.has_content').attr('id');
  2465. switch($contentID) {
  2466. case 'content_font':
  2467. $content_font.css({'font-family':''});
  2468. break;
  2469. case 'content_image':
  2470. $content_pane.removeClass('has_zoom_image');
  2471. $content_image.attr('style',''); // reset image: comment out to retain image scale after loading other content
  2472. // $content_grid.find('a[href="' + thisLink(row) + '"]').parent('div').addClass('selected').siblings().removeClass('selected'); // select grid image
  2473. break;
  2474. case 'content_video':
  2475. closeMedia('video');
  2476. break;
  2477. }
  2478. $content_pane.removeClass('has_'+ $contentID.slice(8));
  2479. $('.content').removeClass('has_content').removeAttr('src');
  2480. }
  2481. }
  2482. // Close button
  2483. function closeContent() {
  2484. if ( $content_pane.hasClass('has_grid') ) { // close grid
  2485. closeGrid();
  2486. } else if ( $body.hasClass('iframe_edited') ) { // warn if iframe edited
  2487. hideEditorOrGrid();
  2488. showWarning('closeContent');
  2489. } else if ( $('#toggle_info').hasClass('selected') ) {
  2490. $content_pane.removeClass('has_iframe');
  2491. $('#toggle_info').removeClass('selected loaded');
  2492. if ( $('.loaded:not(.audio)').length === 1 ) {
  2493. let row = $('.loaded:not(.audio)');
  2494. showContent(row);
  2495. if ( $('.playing.selected').length !== 1 ) { row.addClass('selected'); }
  2496. }
  2497. } else if ( ['has_font','has_image','has_zoom_image','has_pdf','has_video','has_iframe','has_dir','has_ignored','has_text'].some( c => $content_pane.attr('class').split(' ').indexOf( c ) >= 0 ) ) {
  2498. closeContentEls(); // close content if content pane has one of these classes, except audio and grids
  2499. $('.selected:not(.audio)').removeClass('selected');
  2500. $('.loaded').removeClass('loaded');
  2501. $title.removeAttr('data-after').empty();
  2502. showEditorOrGrid();
  2503. } else if ( $body.hasClass('has_text') && !$body.hasClass('edited') ) { // simply hide unedited text editor...
  2504. $body.removeClass('has_text');
  2505. } else if ( $body.hasClass('edited') ) { // ...else show edited warning
  2506. showWarning('closeContent');
  2507. } else { // close audio last of all
  2508. closeMedia('audio');
  2509. $('.selected.audio').removeClass('selected');
  2510. }
  2511. setContentTitle();
  2512. setContentHeight();
  2513. }
  2514. $('#close_btn').on('click', function(e) {
  2515. e.preventDefault();
  2516. closeContent(); // close content unless body.edited or body.iframe_edited
  2517. });
  2518.  
  2519. //***** RESET CONTENT (Reset button or Cmd/Ctrl + R) *****//
  2520. function resetContent() {
  2521. if ( $content_pane.attr('class') === '' ) { window.location = window.location.href; } // reload page
  2522. if ( $content_pane.hasClass('has_audio') ) { $audio_player.prop('currentTime', 0).trigger('pause'); }
  2523. if ( $content_pane.hasClass('has_grid') ) { $grid_btn.click(); }
  2524. if ( $content_pane.hasClass('has_font') ) { $content_font.css({'font-size':'1em'});}
  2525. if ( $content_pane.hasClass('has_image') ) { $content_pane.removeClass('has_zoom_image').find('#content_image').attr('style',''); }
  2526. if ( $content_pane.hasClass('has_video') ) { $content_video.prop('currentTime',0).trigger('pause'); }
  2527. if ( $content_pane.hasClass('has_iframe') || $content_pane.hasClass('has_dir') ) { $selected_file().find('a').click(); }
  2528. setContentHeight();
  2529. }
  2530. $('#reload_btn').on('click', function(e) {
  2531. e.preventDefault();
  2532. showWarning('resetContent');
  2533. });
  2534.  
  2535. //**********************//
  2536. //***** NAVIGATION *****//
  2537. function firstRowID(className) {
  2538. return ( $('#tbody').find(':visible:not(.unchecked)').filter(className).length ? $('#tbody').find('tr:visible:not(.unchecked)').filter(className).first().attr('id') : null );
  2539. }
  2540. function prevRowID(className) {
  2541. let row;
  2542. if ( ['.audio','.video','.media'].includes(className) ) { row = $playing_file(); } else { row = $selected_file(); }
  2543. return ( !row.length || !row.prevAll(':visible:not(.unchecked)').filter(className).length ) ? $('#tbody').find('tr').filter(className).last().attr('id') : row.prevAll(':visible:not(.unchecked)').filter(className).first().attr('id');
  2544. }
  2545. function nextRowID(className) { // if nothing selected, or if no next row with classname, return first row with classname, else return next row with classname
  2546. let row;
  2547. if ( ['.audio','.video','.media'].includes(className) ) { row = $playing_file(); } else { row = $selected_file(); }
  2548. return ( !row.length || !row.nextAll(':visible:not(.unchecked)').filter(className).length ) ? $('#tbody').find('tr').filter(className).first().attr('id') : row.nextAll(':visible:not(.unchecked)').filter(className).first().attr('id');
  2549. }
  2550. // function lastRowID(className) {
  2551. // return ( $('#tbody').find(':visible:not(.unchecked)').filter(className).length ? $('#tbody').find('tr:visible:not(.unchecked)').filter(className).last().attr('id') : null );
  2552. // }
  2553. function selectRowID(className,key) {
  2554. let id = '';
  2555. if ( key === 'ArrowUp' ) { id = prevRowID('.dir,.file'); }
  2556. if ( key === 'ArrowLeft' ) { id = prevRowID(className); }
  2557. if ( key === 'ArrowRight' ) { id = nextRowID(className); }
  2558. if ( key === 'ArrowDown' ) { id = nextRowID('.dir,.file'); }
  2559. return id;
  2560. }
  2561. // NAVIGATION: select GRID items by left/right arrow keys @ arrowNavigation();
  2562. function gridNavigation(key) {
  2563. let className = '';
  2564. if ( $content_grid.hasClass('has_font_grid') ) { className = '.font:not(.ignore)'; }
  2565. if ( $content_grid.hasClass('has_image_grid') ) { className = '.image:not(.ignore)'; }
  2566. if ( $content_grid.hasClass('has_grid') ) { className = '.font:not(.ignore),.image:not(.ignore)'; }
  2567. selectThis( getElById(selectRowID(className,key) ) );
  2568. }
  2569. // NAVIGATION: FONTS and IMAGES by prev/next buttons
  2570. $content_pane.on( 'click','#prev_btn, #next_btn', function(e) {
  2571. e.stopPropagation();
  2572. e.preventDefault();
  2573. let key = $(this).attr('id') === 'prev_btn' ? 'ArrowLeft' : 'ArrowRight';
  2574. clickRow( selectRowID('.font,.image',key));
  2575. });
  2576. // 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
  2577. function playPrevNextTrack(key) {
  2578. if ( $('.playing').length === 0 ) { // Arrow L/R selects first/last audio file if nothing selected
  2579. clickRow( selectRowID('.media',key) );
  2580. playMedia('play');
  2581. } else if ( $('.playing').length === 1 ) {
  2582. let mediaClass = ( $('.playing').hasClass('audio') ? '.audio' : '.video' );
  2583. // If shuffle play...
  2584. if ( $body.hasClass('shuffle_audio') ) {
  2585. let trackRowID = $audio_player.data('shufflelist').pop();
  2586. if ( trackRowID !== undefined ) { // if shuffle list is not empty...
  2587. showAudio( trackRowID ); // load audio...
  2588. playMedia('play'); // and play
  2589. } else if ( trackRowID === undefined ) { // if end of shufflelist...
  2590. if ( $body.hasClass('loop_audio') ) { // and if loop audio, update the shufflelist and play
  2591. updateShuffleList();
  2592. playMedia('play');
  2593. } else { // else load the first track
  2594. showAudio( firstRowID( mediaClass ));
  2595. }
  2596. }
  2597. // else if there is another media file selected, play it next
  2598. } else if ( $(mediaClass).filter('.selected').length === 1 && !$('.media.selected').hasClass('playing') ) {
  2599. showAudio( $('.media.selected').attr('id') );
  2600. playMedia('play');
  2601. } else {
  2602. if ( $body.hasClass('loop_audio') || nextRowID( mediaClass ) !== firstRowID( mediaClass ) ) {
  2603. showAudio( selectRowID( mediaClass,key ) );
  2604. playMedia('play');
  2605. } else {
  2606. showAudio( selectRowID( mediaClass,key ) );
  2607. }
  2608. }
  2609. }
  2610. }
  2611. // NAVIGATION: Audio by prev/next audio buttons
  2612. $('.prev_next_track_btn').on('click',function() {
  2613. let key = ( $(this).attr('id') === 'prev_track' ? 'ArrowLeft' : 'ArrowRight' );
  2614. playPrevNextTrack(key);
  2615. });
  2616. // NAVIGATION: Prev/Next Audio or Prev/Next File of same data-kind by arrow left/right
  2617. function leftRightArrowNavigation(className,key) {
  2618. if ( $('.selected').hasClass('audio') && $('.playing').length === 1 ) {
  2619. playPrevNextTrack(key);
  2620. } else if ( $('#toggle_info').hasClass('selected') ) { // if previewing directory source
  2621. if ( $('#tbody .loaded').length > 0 ) { clickRow( $('#tbody .loaded').attr('id') ); } else { clickRow( selectRowID('.dir,.file',key) ); }
  2622. } else {
  2623. if ( $('.selected').length === 0 ) { // else select first/last row
  2624. clickRow( selectRowID('.dir,.file',key) );
  2625. } else { // else select prev/next row of same data-kind
  2626. clickRow( selectRowID('.'+ $('.loaded,.video.playing').attr('data-kind'),key) );
  2627. }
  2628. if (className === 'video') { playMedia('play'); }
  2629. }
  2630. }
  2631. function upDownArrowNavigation(key) {
  2632. let row = $(document.getElementById(selectRowID('.dir,.file',key)));
  2633. if ( row.hasClass('audio') && $('.audio.playing').length === 1 ) { // just select audio file if another audio is playing
  2634. selectThis( row );
  2635. } else if ( $('#toggle_info').hasClass('selected') ) {
  2636. if ( $('#tbody .loaded').length > 0 ) { clickRow( $('#tbody .loaded').attr('id') ); } else { clickRow( selectRowID('.dir,.file',key) ); }
  2637. } else {
  2638. clickRow( selectRowID('.dir,.file',key) );
  2639. }
  2640. }
  2641. // NAVIGATE directory index items by arrow up/down or left/right keys, with/without grid @ indexNavigation()
  2642. function arrowNavigation(className,key) {
  2643. if ( key === 'ArrowUp' || key === 'ArrowDown' ) {
  2644. upDownArrowNavigation(key);
  2645. } else { // key === 'ArrowLeft" || key === 'ArrowRight'
  2646. if ( $content_pane.hasClass('has_grid') ) { // Grid navigation: L/R arrow selects images and fonts only
  2647. gridNavigation(key);
  2648. } else {
  2649. leftRightArrowNavigation(className,key);
  2650. }
  2651. }
  2652. if ( $content_pane.hasClass('has_grid') ) {
  2653. scrollThis('content_grid','selected');
  2654. } else {
  2655. scrollThis('tbody','selected');
  2656. }
  2657. }
  2658.  
  2659. // NAVIGATION: Main navigation by arrow keys
  2660. function indexNavigation(key) {
  2661. let className = ( $('.selected[data-kind]') === undefined ? $dir_list.find('tbody tr:visible').first().attr('data-kind') : $('.selected[data-kind]').attr('data-kind') );
  2662. arrowNavigation(className,key);
  2663. }
  2664.  
  2665. // NAVIGATE items by typed string
  2666. var str = '';
  2667. function timeoutID() {
  2668. return window.setTimeout( function() { str = ''; }, 1500 );
  2669. }
  2670. function alphaNav(e) { // Select Dir_List row by typed string; Todo: select next row by nearest letter
  2671. let timer = timeoutID();
  2672. if ( typeof timer === 'number' ) {
  2673. window.clearTimeout( timer );
  2674. timer = 0; // id
  2675. }
  2676. timeoutID();
  2677. str += e.key;
  2678. str = str.toLowerCase();
  2679. if ( $('#dir_list').find('td.name[data-name^="'+ str +'"]').length ) {
  2680. $('#dir_list').find('td.name[data-name^="'+ str +'"]').first().find('a').click();
  2681. scrollThis('tbody','selected');
  2682. // } else {
  2683. // null; // replace this with some sort of fuzzy match function? TBD
  2684. }
  2685. }
  2686. //***** END NAVIGATION *****//
  2687.  
  2688. //***** CLICK TO SELECT/SHOW CONTENT *****//
  2689.  
  2690. // CLICK element by id
  2691. function clickThis(id) {
  2692. let el = $(document.getElementById(id));
  2693. if ( el.find('a').length > 0 ) { el.find('a').click(); } else { el.click(); }
  2694. }
  2695. // CLICK Row
  2696. function clickRow(id) {
  2697. let row = getElById(id);
  2698. selectThis(row);
  2699. showContent(row);
  2700. }
  2701. $body.find('#tbody').on('click','tr', function(e) {
  2702. e.preventDefault();
  2703. e.stopPropagation();
  2704. if ( $(this).hasClass('playing') ) {
  2705. playPauseMedia();
  2706. } else {
  2707. showWarning( 'clickRow', $(this).attr('id') );
  2708. }
  2709. });
  2710. $('#toggle_info').on('click',function(e) {
  2711. e.preventDefault();
  2712. e.stopPropagation();
  2713. if ( $(this).hasClass('selected') ) { $('#close_btn').click(); } else {showWarning( 'clickRow', $(this).attr('id') ); }
  2714. });
  2715.  
  2716. // DOUBLE-CLICK Row to open directory
  2717. function doubleClickRow(row) { // row.dir only
  2718. let $query_str = decodeURIComponentSafe(window.location.search);
  2719. if ( $query_str === '' ) { $query_str = '?'; }
  2720. const $current_index = row.prevAll('.dir:visible').length;
  2721. if ( $query_str.indexOf('history') !== -1 ) {
  2722. $query_str = $query_str.replace(/&selected=\d+/,'').replace(/&history=/,'&history='+ $current_index +'+');
  2723. } else {
  2724. $query_str = $query_str.replace(/&selected=\d+/,'') + '&history='+ $current_index;
  2725. }
  2726. window.location = row.find('a').attr('href') + $query_str;
  2727. }
  2728. $('#tbody').find('tr.dir').on('dblclick', function(e) {
  2729. e.preventDefault();
  2730. e.stopPropagation();
  2731. showWarning( 'doubleClickRow', $(this) );
  2732. });
  2733.  
  2734. // CLICK grid item
  2735. function gridItemClick(e,el) {
  2736. e.preventDefault();
  2737. clickThis( thisID($dir_list.find('a[href*="'+ thisLink(el) +'"]') ) );
  2738. }
  2739. $content_grid.on('click','div', function(e) {
  2740. gridItemClick(e,$(this));
  2741. });
  2742.  
  2743. // HOVER Grid Item
  2744. $content_grid.on('mouseenter','> div:not(.selected)',function() {
  2745. thisRow($dir_list.find('a[href*="'+ thisLink(this) +'"]')).addClass('hovered');
  2746. }).on('mouseleave','> div:not(.selected)',function() {
  2747. thisRow($dir_list.find('a[href*="'+ thisLink(this) +'"]')).removeClass('hovered');
  2748. });
  2749. // HOVER Dir_list_row and highlight corresponding grid item
  2750. $dir_list_row.hover(function() {
  2751. if ( $content_grid.is(':visible') ) {
  2752. $content_grid.find('[href*="'+ thisLink(this) +'"]').closest('div').addClass('hovered');
  2753. }
  2754. }, function() {
  2755. if ( $content_grid.is(':visible') ) {
  2756. $content_grid.find('.hovered').removeClass('hovered');
  2757. }
  2758. });
  2759.  
  2760. //***** AUTOLOAD CONTENT: index files or files from the file shortcut list *****//
  2761. function autoSelectFile() {
  2762. let $query_prefs = getQueryPrefs();
  2763. let $UI_pref_selected = ( $query_prefs.get('selected') === null ? '' : $query_prefs.get('selected') );
  2764. if ( getQuery('file') !== undefined && getQuery('file').length > 0 && window.top == window.self ) { // load individual files
  2765. clickRow( $dir_list.find('a[href*="'+ getQuery('file') +'"]').closest('tr').attr('id') );
  2766. removeQuery('file');
  2767. } else if ( $UI_pref_selected !== '' && !$body.hasClass('has_media') ) {
  2768. clickRow( $dir_list.find('tr.dir:visible').eq($UI_pref_selected).attr('id') );
  2769. } else if ( $body.hasClass('autoload_index_files') && $dir_list.find( 'a[href*="/index."]').length > 0 ) { // else load index file
  2770. clickRow( $dir_list.find('a[href*="/index."]').closest('tr').attr('id') );
  2771. } else { // else select first non-media item
  2772. // clickRow( $dir_list.find('tbody tr:not(.media):not(.invisible)').first() );
  2773. }
  2774. if ( $body.hasClass('autoload_media') && $body.hasClass('has_media') ) { // else if audio and images, load cover art
  2775. clickRow( firstRowID('.audio,.video') );
  2776. if ( $playing_file() ) { scrollThis('tbody','playing'); }
  2777. }
  2778. if ( $selected_file() ) { scrollThis('tbody','selected'); }
  2779. }
  2780.  
  2781. // Autoload Cover Art
  2782. function getImageNames() {
  2783. let image_names = [];
  2784. $image_files.each(function() {
  2785. let name = $(this).find('td.name').attr('data-name');
  2786. name = name.slice(0,name.lastIndexOf('.'));
  2787. image_names.push( name );
  2788. });
  2789. return image_names;
  2790. }
  2791. function getCoverArtID() {
  2792. const cover_names = ['cover','front'];
  2793. const image_names = getImageNames();
  2794. for ( let cover_name of cover_names ) {
  2795. if ( image_names.includes(cover_name) ) { // file name = a cover name
  2796. return $image_files.eq( image_names.indexOf(cover_name) ).attr('id');
  2797. } else if ( image_names.some( name => name.startsWith(cover_name)) ) { // file name starts with a cover name
  2798. return $image_files.find('td.name[data-name^="'+ cover_name +'"]').closest('tr').attr('id');
  2799. } else if ( image_names.some( name => name.indexOf(cover_name) > 0 ) ) { // file name includes a cover name
  2800. return $image_files.find('td.name[data-name*="'+ cover_name +'"]').closest('tr').attr('id');
  2801. } else { // else use first image
  2802. return $image_files.first().attr('id');
  2803. }
  2804. }
  2805. }
  2806. function autoLoadCoverArt() { // autoload cover art for audio if dir contains audio and images, and audio is loaded and non-image content is not loaded
  2807. let bodyClasses = getClassList('top');
  2808. if ( bodyClasses.contains( 'has_audio','has_images','autoload_media' ) && !getElById( firstRowID('.media') ).hasClass('video') ) {
  2809. // if ( $body.hasClass('has_audio') && $body.hasClass('has_images') && $body.hasClass('autoload_media') && !getElById( firstRowID('.media') ).hasClass('video') ) {
  2810. let $coverID = getCoverArtID();
  2811. if ( $coverID !== undefined ) {
  2812. let row = getElById($coverID);
  2813. showContent(row);
  2814. row.addClass('loaded');
  2815. $title.html(row.find('.name').attr('data-name'));
  2816. setDimensions($('.loaded.image'));
  2817. }
  2818. }
  2819. }
  2820.  
  2821. //***** KEYBOARD EVENTS *****//
  2822. $body.on('keydown',$dir_list,function(e) {
  2823. const $selected = $selected_file();
  2824.  
  2825. if ( $('#content_source').is(':focus') || $('#content_font div').is(':focus') && e.key !== 'Escape' ) {
  2826. return;
  2827. }
  2828. // Disable all keydown events except return and tab when warning is shown
  2829. if ( $('body').hasClass('has_warning') ) {
  2830. if (e.key !== 'Enter' && e.key !== 'Tab' && e.key !== 'Shift' ) {
  2831. e.preventDefault();
  2832. return false;
  2833. }
  2834. if ( e.key === 'Enter' ) {
  2835. e.preventDefault();
  2836. e.stopPropagation();
  2837. $('#warnings').find('button.focus').click();
  2838. }
  2839. if ( e.key === 'Tab' ) {
  2840. e.preventDefault();
  2841. e.stopPropagation();
  2842. if ( $('#warnings').find('button.focus').length === 0 || $('#warnings').find('button.focus').prev('button').length === 0 ) {
  2843. $('#warnings').find('button').last('button').focus().addClass('focus').siblings().removeClass('focus').blur();
  2844. } else {
  2845. $('#warnings').find('button.focus').prev('button').focus().addClass('focus').siblings().removeClass('focus').blur();
  2846. }
  2847. }
  2848. }
  2849.  
  2850. $(':focus').blur(); // Need this to able to select grid items after clicking close button (or other buttons).
  2851.  
  2852. switch ( e.key ) {
  2853. case 'ArrowUp':
  2854. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) { // Cmd/Ctrl + up arrow = go to parent directory
  2855. if ( $('#parents_dir_menu + ul a').length < 1 ) {
  2856. return;
  2857. } else {
  2858. showWarning( 'clickThis', $('#parent_dir_menu').attr('id') );
  2859. }
  2860. break;
  2861. }
  2862. if ( $('*[contentEditable="true"]').is(':focus') ) { // Allow arrow navigation within content_editable elements
  2863. return;
  2864. }
  2865. e.preventDefault();
  2866. showWarning( 'indexNavigation', 'ArrowUp' );
  2867. break;
  2868. case 'ArrowDown':
  2869. 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
  2870. return;
  2871. } else if ( $('*[contentEditable="true"]' ).is(':focus') ) {
  2872. return;
  2873. } else if ( (e.ctrl || e.metaKey) && $selected.hasClass('dir') ) {
  2874. $selected.find('a').trigger('dblclick');
  2875. break;
  2876. }
  2877. e.preventDefault();
  2878. showWarning( 'indexNavigation', 'ArrowDown' );
  2879. break;
  2880. case 'ArrowLeft':
  2881. if ( (e.ctrl || e.metaKey) || (e.ctrl && e.metaKey) ) {
  2882. return;
  2883. } else if ( $('*[contentEditable="true"]').is(':focus') ) { // Ignore Cmd/Ctrl + arrow or if focused element is content editable
  2884. return;
  2885. }
  2886. if ( (e.altKey && e.shiftKey) || e.altKey && !e.metaKey && !e.ctrlKey ) { // Skip audio 30s/10s: Opt-Shift-Arrow/Opt-Arrow
  2887. mediaSkip(e);
  2888. return;
  2889. } else {
  2890. showWarning( 'indexNavigation','ArrowLeft' );
  2891. }
  2892. break;
  2893. case 'ArrowRight':
  2894. if ( e.metaKey && !e.altKey && !e.shiftKey && $selected.hasClass('dir') ) { // Open dir with Cmd/Ctrl + Right Arrow
  2895. $selected.find('a').trigger('dblclick');
  2896. return;
  2897. }
  2898. if ( (e.ctrl || e.metaKey) || (e.ctrl && e.metaKey) ) { // Ignore Cmd/Ctrl + arrow or if focused element is content editable
  2899. return;
  2900. } else if ( $('*[contentEditable="true"]').is(':focus') || $selected.hasClass('dir ignore') ) {
  2901. return;
  2902. }
  2903. if ( (e.altKey && e.shiftKey) || e.altKey && !e.metaKey && !e.ctrlKey ) { // Skip audio 30s/10s: Opt-Shift-Arrow/Opt-Arrow
  2904. mediaSkip(e);
  2905. return;
  2906. } else {
  2907. showWarning( 'indexNavigation','ArrowRight' );
  2908. }
  2909. break;
  2910. case ' ': // space
  2911. if ( $content_pane.hasClass('has_audio') || $content_pane.hasClass('has_video') ) { // Play/pause media (space bar)
  2912. e.preventDefault();
  2913. playPauseMedia();
  2914. } else {
  2915. alphaNav(e);
  2916. }
  2917. break;
  2918. case 'Enter': // Open directories (or ignore)
  2919. if ( $selected.hasClass('app') && $settings.apps_as_dirs === false ) {
  2920. break;
  2921. } else {
  2922. if ( $selected.hasClass('dir') ) {
  2923. $selected.find('a').trigger('dblclick');
  2924. } else if ( $selected.hasClass('playing') || $selected.hasClass('video') ) { // content_audio or content_video
  2925. playPauseMedia();
  2926. } else {
  2927. $selected.click();
  2928. }
  2929. }
  2930. break;
  2931. // Alphabetical navigation
  2932. 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':
  2933. 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':
  2934. 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 'π':
  2935. 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 '≠':
  2936. case '⁄': case '€': case '‹': case '›': case 'fl': case '‡': case '°': case '·': case '‚': case '±': case '¯': case '˘': case '¿':
  2937. case 'ı': case '': case '´': case '˝': case 'ˆ': case '': case '˜': case '‰': case 'ˇ': case '¨': case '◊': case '„': case '˛': case '¸':
  2938. // 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 'ϖ':
  2939. // 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 'ϒ':
  2940. if ( !e.metaKey && !e.ctrlKey && !e.altKey ) {
  2941. alphaNav(e);
  2942. }
  2943. break;
  2944. case 'd': // Cmd/Ctrl + D: Toggle Details
  2945. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  2946. e.preventDefault();
  2947. $show_details.click();
  2948. } else {
  2949. alphaNav(e);
  2950. }
  2951. break;
  2952. case 'e': // Cmd/Ctrl + E: Show Text Editor
  2953. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  2954. e.preventDefault();
  2955. $('#text_editor_row').find('a').click();
  2956. } else {
  2957. alphaNav(e);
  2958. }
  2959. break;
  2960. case 'g': // Cmd/Ctrl + G: Show image Grid
  2961. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  2962. e.preventDefault();
  2963. $grid_btn.click();
  2964. } else {
  2965. alphaNav(e);
  2966. }
  2967. break;
  2968. case 'i': // Cmd/Ctrl + I: Toggle Invisibles
  2969. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  2970. e.preventDefault();
  2971. $inv_checkbox.find('input').click();
  2972. } else {
  2973. alphaNav(e);
  2974. }
  2975. break;
  2976. case 'o': // Cmd/Ctrl + Shift + O: Open selected item in new window
  2977. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && e.shiftKey && !e.altKey ) {
  2978. window.open( thisLink($selected_file()) );
  2979. } else {
  2980. alphaNav(e);
  2981. }
  2982. break;
  2983. case 'r': // Cmd/Ctrl + Shift + R: Refresh
  2984. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  2985. e.preventDefault();
  2986. $('#reload_btn').click();
  2987. } else {
  2988. alphaNav(e);
  2989. }
  2990. break;
  2991. case 'w': // Close content pane if Close button visible with Cmd/Crtl + W
  2992. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  2993. if ( $content_pane.attr('class').indexOf('has_') > -1 ) {
  2994. e.preventDefault();
  2995. $('#close_btn').click();
  2996. }
  2997. } else {
  2998. alphaNav(e);
  2999. }
  3000. break;
  3001. case '\\':
  3002. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3003. e.preventDefault();
  3004. $('#toggle_split_view').click();
  3005. } else {
  3006. alphaNav(e);
  3007. }
  3008. break;
  3009. case '=':
  3010. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3011. e.preventDefault();
  3012. $('#increase').click();
  3013. } else {
  3014. alphaNav(e);
  3015. }
  3016. break;
  3017. case '-':
  3018. if ( (navigator.platform.match('Mac') ? e.metaKey && !e.ctrlKey : e.ctrlKey) && !e.shiftKey && !e.altKey ) {
  3019. e.preventDefault();
  3020. $('#decrease').click();
  3021. } else {
  3022. alphaNav(e);
  3023. }
  3024. break;
  3025. case 'tab':
  3026. break;
  3027. case 'Escape':
  3028. $('*:focus').blur();
  3029. break;
  3030. } // end switch
  3031. });
  3032. // ***** END KEYBOARD EVENTS ***** //
  3033.  
  3034. // ***** GRID SETUP ***** //
  3035. // Create Font Grid Items
  3036. function fontGridItems() {
  3037. let $font_grid_items_arr = [];
  3038. let $font_files = $dir_list_body.find('.font');
  3039. let fontGridStyles = $font_grid_styles.sheet;
  3040. for ( let i = 1; i < $font_files.length; i++ ) {
  3041. let newGridItem = showFont($font_files[i],true,fontGridStyles);
  3042. $font_grid_items_arr.push( newGridItem );
  3043. }
  3044. return $font_grid_items_arr;
  3045. }
  3046. // Create Image Grid Items
  3047. function imageGridItems() {
  3048. let $image_grid_items_arr = [];
  3049. let $image_files = $dir_list_body.find('.image');
  3050. for ( let i = 0; i < $image_files.length; i++ ) {
  3051. const $this_link = thisLink($image_files[i]);
  3052. const exts = $row_types.image.filter( ext => $.inArray(ext, $row_settings.ignore) == -1 ); // decide which image files can be displayed
  3053. const $title_name = $this_link.slice($this_link.lastIndexOf('/') + 1);
  3054. if ( $.inArray( thisExt($image_files[i]), exts ) > -1 ) { // if this row file ext is in the image extension array
  3055. let item = '<div class="image_grid_item"><a href="'+$this_link+'"><img src="'+$this_link+'" title="'+$title_name+'" loading="lazy" /></a></div>';
  3056. $image_grid_items_arr.push( item );
  3057. }
  3058. }
  3059. return $image_grid_items_arr;
  3060. }
  3061. // Make Grids
  3062. function makeGrids(el) {
  3063. closeGrid();
  3064. $content_pane.removeClass('has_hidden_grid').addClass('has_grid');
  3065. if ( el.attr('id') === 'show_font_grid' || !$body.hasClass('has_images') ) { // only show font grid
  3066. $title.removeClass().addClass('font_grid');
  3067. $content_grid.addClass('has_font_grid');
  3068. $content_grid.append( fontGridItems() );
  3069. } else if ( el.attr('id') === 'show_image_grid' || !$body.hasClass('has_fonts') ) { // only show image grid
  3070. $title.removeClass().addClass('image_grid');
  3071. $content_grid.addClass('has_image_grid');
  3072. $content_grid.append( imageGridItems() );
  3073. } else { // show grid of both images and fonts
  3074. $title.removeClass();
  3075. if ( $body.hasClass() ) { $content_grid.addClass('has_image_grid'); } else { $content_grid.addClass('has_grid'); }
  3076. $content_grid.append( imageGridItems(), fontGridItems() );
  3077. }
  3078. }
  3079. // Click grid button
  3080. $sidebar_header.on('click', '#grid_btn, #show_font_grid, #show_image_grid', function(e) {
  3081. e.stopPropagation();
  3082. makeGrids($(this));
  3083. showGrid();
  3084. });
  3085.  
  3086. // ***** SCALE PREVIEWED IMAGES & FONTS ***** //
  3087. // Scale Fonts
  3088. function scaleFonts(incr, y) {
  3089. const $em = parseInt(getComputedStyle(document.body).fontSize); // pts/em
  3090. const getFontSize = function(el) { return parseFloat(el.css('font-size')); };
  3091. if ( y === 'decrease' ) { incr = 1/incr; }
  3092. if ( $content_pane.hasClass('has_grid') && ( $content_grid.hasClass('has_font_grid') || $content_grid.hasClass('has_grid') ) ) {
  3093. $content_grid.css({'font-size':( getFontSize($content_grid)/$em * incr ) +'em'});
  3094. return;
  3095. }
  3096. if ( $content_pane.hasClass('has_font') ) {
  3097. $content_font.css({'font-size':( getFontSize($content_font)/$em * incr ) +'em'});
  3098. return;
  3099. }
  3100. }
  3101. // Scale Images
  3102. function scaleImages(incr, y) {
  3103. if (y === 'decrease' ) { incr = 1/incr; }
  3104. if ( $content_pane.hasClass('has_image') || $content_pane.hasClass('has_zoom_image') && !$content_pane.hasClass('has_grid') ) {
  3105. var $image_width = Math.round( $content_image.width() ) * incr; // increment image size
  3106. var $image_height = Math.round( $content_image.height() ) * incr; // increment image size
  3107. $content_pane.removeClass('has_zoom_image').addClass('has_image');
  3108. $content_image.css({'width':$image_width +'px', 'height': $image_height +'px', 'max-width':'none', 'max-height':'none' });
  3109. $content_container.scrollLeft( ( $image_width - $(window).width() )/2 ) ;
  3110. // if image is wider or taller than the window height, adjust position to enable scrolling:
  3111. if ( ( ( $image_width - $(window).width() )/2 ) > 0 ) { $content_image.css({'left':0}); } else { $content_image.css({'left':'unset'}); }
  3112. if ( ( ( $image_height - $(window).height() )/2 ) > 0 ) { $content_image.css({'top':0}); } else { $content_image.css({'top':'unset'}); }
  3113. return;
  3114. }
  3115. if ( $content_pane.hasClass('has_grid') && ( $content_grid.hasClass('has_image_grid') || $content_grid.hasClass('has_grid') ) ) {
  3116. let $image_grid_item_width = Number.parseFloat( $('.image_grid_item img').width(),10) * incr;
  3117. let $image_grid_item_height = Number.parseFloat( $('.image_grid_item img').height(),10) * incr;
  3118. let $image_grid_item_maxwidth = Number.parseFloat( $('.image_grid_item img').css('maxWidth'),10) * incr;
  3119. let $image_grid_item_maxheight = Number.parseFloat( $('.image_grid_item img').css('maxHeight'),10) * incr;
  3120. // prevent reducing grid image size on first scale click:
  3121. if ( $image_grid_item_width < $image_grid_item_maxwidth ) { $image_grid_item_width = $image_grid_item_maxwidth; }
  3122. if ( $image_grid_item_height < $image_grid_item_maxheight ) { $image_grid_item_height = $image_grid_item_maxheight; }
  3123. // set grid properties
  3124. $content_grid.css({'grid-template-columns':'repeat(auto-fill, minmax('+ ($image_grid_item_width +16) +'px, auto ) )'});
  3125. $content_grid.find('img').css({'max-width':( $image_grid_item_width ) +'px', 'max-height':( $image_grid_item_height ) +'px'});
  3126. return;
  3127. }
  3128. }
  3129. // Scale Fonts and Images
  3130. function scalePreviewItems(y) { // combine scaling into one function
  3131. scaleImages( 1.125, y );
  3132. scaleFonts( 1.125, y );
  3133. }
  3134. // Scale Content
  3135. $('#scale').on('click','span',function(e) {
  3136. e.preventDefault();
  3137. e.stopPropagation();
  3138. let val = ( $(this).attr('id') === 'increase' ? 'increase' : 'decrease' );
  3139. scalePreviewItems(val);
  3140. });
  3141. // Zoom Images on click
  3142. function zoomImage(e) {
  3143. const $this_link = $content_image.attr('src');
  3144. const $offset = $content_image.offset();
  3145. const $this_width = $content_image.width();
  3146. const $this_height = $content_image.height();
  3147. const percentX = ( e.pageX - $offset.left ) / $this_width;
  3148. const percentY = ( e.pageY - $offset.top ) / $this_height;
  3149.  
  3150. if ( ( $content_image.attr('style') !== '' || $content_image.attr('style') !== undefined ) ) { $content_image.attr('style',''); }
  3151. if ( $this_link !== undefined ) {
  3152. getDimensions( $this_link, function( width, height ) {
  3153. if ( width < $content_container.width() && height < $content_container.height() ) { // don't zoom small images
  3154. $content_pane.removeClass('has_zoom_image').addClass('has_image'); // remove zoom classes in case window resized after zoom
  3155. } else if ( width > $content_container.width() && height < $content_container.height() ) { // scroll-x to click position, center vertically
  3156. $content_pane.toggleClass('has_image has_zoom_image');
  3157. if ( $content_pane.hasClass('has_image') ) { $content_image.css({'margin-top':0}); } else { $content_image.css({'margin-top': ($content_container.height() - $content_image.height() )/2 }); }
  3158. $content_container.scrollLeft( width * percentX - ( $content_container.width() * percentX ) ) ;
  3159. } else if ( width < $content_container.width() && height > $content_container.height() ) { // center horizonally
  3160. $content_pane.toggleClass('has_image has_zoom_image');
  3161. if ( $content_pane.hasClass('has_image') ) { $content_image.css({'margin-left':0}); } else { $content_image.css({'margin-left': ($content_container.width() - $content_image.width() )/2 }); }
  3162. $content_container.scrollTop( height * percentY - ( $content_container.height() * percentY ) );
  3163. } else {
  3164. $content_pane.toggleClass('has_image has_zoom_image');
  3165. $content_container.scrollLeft( width * percentX - ( $content_container.width() * percentX ) ) ;
  3166. $content_container.scrollTop( height * percentY - ( $content_container.height() * percentY ) );
  3167. }
  3168. });
  3169. }
  3170. }
  3171. $content_image.on('click', function(e) {
  3172. zoomImage(e);
  3173. });
  3174. // ***** END SCALE PREVIEW ITEMS ***** //
  3175.  
  3176.  
  3177. // ***** AUDIO CONTENT ***** //
  3178. // Update Playlist
  3179. function updatePlaylist() {
  3180. let playlist = [];
  3181. $audio_files.not('.unchecked').each(function() {
  3182. playlist.push( thisID( $(this) ) );
  3183. });
  3184. return playlist;
  3185. }
  3186. // Randomize Shuffle List
  3187. function shuffleArray(array) {
  3188. for ( let i = array.length - 1; i > 0; i-- ) {
  3189. const j = Math.floor(Math.random() * (i + 1));
  3190. [array[i], array[j]] = [array[j], array[i]];
  3191. }
  3192. return array;
  3193. }
  3194. // Attach Shuffle List data to $audio_player
  3195. function updateShuffleList(id) {
  3196. if ( !$body.hasClass('shuffle_audio') ) {
  3197. return;
  3198. } else if ( id !== undefined ) { // don't include .playing and .unchecked track in shufflelist
  3199. let shuffleList = $audio_player.data('shufflelist');
  3200. if ( $(document.getElementById(id)).hasClass('unchecked') || $(document.getElementById(id)).hasClass('playing') ) {
  3201. shuffleList.splice(shuffleList.indexOf(id), 1);
  3202. $audio_player.data('shufflelist',shuffleList);
  3203. } else {
  3204. shuffleList.push(id);
  3205. shuffleList = shuffleArray( shuffleList );
  3206. }
  3207. } else {
  3208. let shuffleList = shuffleArray( updatePlaylist() );
  3209. $audio_player.data('shufflelist',shuffleList);
  3210. }
  3211. }
  3212.  
  3213. // Check/Uncheck Audio/Video Files
  3214. function toggleChecked(e) {
  3215. e.stopPropagation();
  3216. $(this).blur();
  3217. thisRow(this).toggleClass('unchecked');
  3218. updateShuffleList(thisRow(this).attr('id'));
  3219. }
  3220. $media_files.on('click','input', toggleChecked );
  3221. // Check/Uncheck all Audio/Video Files
  3222. function toggleAllChecked(e) {
  3223. e.stopPropagation();
  3224. $dir_list_row.find('input').trigger('click');
  3225. updateShuffleList();
  3226. }
  3227. $dir_list.find('#play_toggle').on('click', toggleAllChecked );
  3228.  
  3229. // Is Playing
  3230. function isPlaying(el) {
  3231. return (el !== undefined && el.get(0).currentTime > 0 && !el.get(0).paused && !el.get(0).ended); // returns true if all conditions are true
  3232. }
  3233. // Play Media
  3234. function playMedia(task) {
  3235. if ( $playing_file().hasClass('audio') ) { $audio_player.trigger(task); } else { $content_video.trigger(task); }
  3236. }
  3237. // Skip media tracks +/-10/30 seconds
  3238. function mediaSkip(e) {
  3239. const factor = ( e.key === 'ArrowLeft' ? -1 : 1 ); // forward or backward?
  3240. const skip = ( e.altKey && e.shiftKey ? 30 : e.altKey ? 10 : null ); // 30s or 10s?
  3241. const $player = ( $playing_file().hasClass('audio') ? $audio_player : $content_video ); // audio or video?
  3242. const time = $player.prop('currentTime'); // current time
  3243. $player.prop('currentTime', time + factor*(skip)); // set time
  3244. }
  3245.  
  3246. // Play/Pause Audio/Video
  3247. function playPauseMedia() {
  3248. let $player = ( $content_pane.hasClass('has_audio') ? $('#audio') : $('#content_video') );
  3249. if ( isPlaying( $player ) ) { $player.trigger('pause'); } else { $player.trigger('play'); }
  3250. }
  3251. // Play Next Track
  3252. function playPrevNextTrackBtn(el) {
  3253. let key = ( el.attr('id') === 'prev_track' ? 'ArrowLeft' : 'ArrowRight' );
  3254. playPrevNextTrack(key);
  3255. }
  3256. // Prev/Next Track buttons
  3257. $('.prev_next_track_btn').on( 'click', function() { playPrevNextTrackBtn( $(this) ); });
  3258.  
  3259. // Toggle Shuffle Play
  3260. $('#checkbox_div').on('click','#shuffle', function() {
  3261. $body.toggleClass('shuffle_audio');
  3262. updateShuffleList();
  3263. if ( $body.hasClass('shuffle_audio') && $('.playing').length === 0 ) {
  3264. playPrevNextTrack('ArrowRight');
  3265. } else {
  3266. // do nothing: i.e., allow current track to continue playing
  3267. }
  3268. });
  3269. // Toggle Loop Play
  3270. $('#checkbox_div').on('click','#loop', function() {
  3271. $body.toggleClass('loop_audio');
  3272. document.getElementById('audio').toggleAttribute('loop');
  3273. });
  3274.  
  3275. // Initialize Audio
  3276. function initMedia() {
  3277. $('#audio, #content_video').on('ended', function() {
  3278. playPrevNextTrack('ArrowRight');
  3279. scrollThis('tbody','playing');
  3280. });
  3281. }
  3282. // ***** END AUDIO PLAYBACK ***** //
  3283.  
  3284. // ***** IFRAME SETUP ***** //
  3285. // For directory display or editable text files
  3286. // If row is a directory, set up iFrameDirUI(); if it's an editable text document, set up iFrameTextEditingUI().
  3287. function setUpIframeUI(bool) {
  3288. if ( window.self !== window.top ) {
  3289. const $textFiles = $row_types.markdown.concat($row_types.text, $row_types.code); // define which files are editable
  3290. // if selected index item is a directory, set up the directory UI....
  3291. if ( window.location.pathname.endsWith('/') ) {
  3292. iFrameDirUI( $('#iframe_body') );
  3293. }
  3294. if ( JSON.parse(bool) === true && $textFiles.includes( window.location.pathname.slice( window.location.pathname.lastIndexOf('.') + 1 ) ) ) {
  3295. $iFrame_head.append('<style>'+ $text_editing_style_rules +'</style>');
  3296. $iFrame_head.append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css"></link>');
  3297. let splitClass = ( getQuery('split_view') === 'true' ? 'split_view' : '' );
  3298. let viewClass = getQuery('default_text_view');
  3299. TextEditing( $('body:not(#top)') );
  3300. $iframe_body.removeClass().addClass(splitClass).addClass(viewClass).prepend($warnings);
  3301. $('#content_source').removeClass().prop('disabled',false);
  3302. }
  3303. }
  3304. }
  3305. // IFRAME DIRECTORY Prep
  3306. function iFrameDirUI(el) { // el = iframeBody
  3307. let parentLink = decodeURIComponentSafe(window.location.pathname);
  3308. parentLink = parentLink.split('/').slice(0,-2).join('/');
  3309. let queryPrefs = window.location.search;
  3310. queryPrefs = queryPrefs.slice(1).split('&');
  3311. let sortPref = queryPrefs[0].slice(queryPrefs[0].indexOf('=') + 1); // sort determined by parent's current sorting pref
  3312. let numbersPref = queryPrefs[1];
  3313. let viewSourcePref = queryPrefs[2];
  3314.  
  3315. if ( viewSourcePref === 'view_source=true' ) {
  3316. return;
  3317. } else {
  3318. if ( numbersPref === 'show_numbers=true' ) { $('#iframe_body').addClass('show_numbers'); }
  3319.  
  3320. $iFrame_head.find('style').remove();
  3321. $iFrame_head.append('<style>'+ $iframe_styles +'</style>');
  3322.  
  3323. const parentLinkCell = '<tr id="parent"><th colspan=4><a href="'+ parentLink +'">Parent Directory</a></th></tr>';
  3324. 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>';
  3325. const preppedIndex = makeNewIndex($('#iframe_body'),sortPref);
  3326. const iFrameTable = $('<table id="dir_list"><thead id="thead">'+ parentLinkCell + sortingRow +'</thead><tbody id="tbody"></tbody></table>');
  3327. // append prepped index
  3328. el.empty().append(iFrameTable).find('tbody').append(preppedIndex);
  3329. $('#iframe_body').find('#tbody').css({'top':$('#iframe_body').find('#thead').height() + 1 +'px'});
  3330. $('#iframe_body').data('sort_direction',1).find('#dir_list').addClass('sort_by_'+ sortPref); // initial directory sort
  3331. }
  3332. }
  3333.  
  3334. // IFRAME Directory sorting
  3335. $('#iframe_body').on('click','.sorting', function() {
  3336. const $dir_list_row = $('#iframe_body').find('#tbody').find('tr');
  3337. const id = $(this).attr('id');
  3338. if ( $('#iframe_body').data('sorting') !== id ) { // if clicking sorting item for the first time
  3339. $('#iframe_body').data('sorting',id);
  3340. $('#iframe_body').data('sorting',id).data('sort_direction', 1 );
  3341. $(this).removeClass('down');
  3342. } else { // clicking the same sorting item again -- reverse sort order
  3343. $('#iframe_body').data('sort_direction', $('#iframe_body').data('sort_direction') * -1 );
  3344. $(this).toggleClass('down');
  3345. }
  3346. const sort_direction = $('#iframe_body').data('sort_direction');
  3347. const $sorted_index = sortDirList( $dir_list_row, id, sort_direction );
  3348. $('#iframe_body').find('#dir_list').removeClass().addClass(id).find('#tbody').empty().append($sorted_index);
  3349. });
  3350.  
  3351. //***** TEXT EDITING PANE *****//
  3352. function textEditorUI(el) { //
  3353. if ( el.attr('id') === 'content_text' && $content_text.children().length === 0 ) { // only add UI once
  3354. $body.addClass('has_text');
  3355. $content_pane.removeClass('has_dir');
  3356. TextEditing($content_text);
  3357. el.find('#content_preview').html(el.find('#content_source').val()); // make sure any source text is also previewed.
  3358. if ( getQuery('split_view') === 'true' || getQuery('default_text_view') === 'source_text' ) { el.find('#content_source').focus(); }
  3359. } else { // show text editor
  3360. $body.addClass('has_text').removeClass('has_hidden_text');
  3361. }
  3362. setContentTitle();
  3363. setContentHeight();
  3364. }
  3365. // show text editor pane
  3366. $('#text_editor, #text_editor_row a').on('click', function(e) {
  3367. e.preventDefault();
  3368. textEditorUI($content_text);
  3369. });
  3370.  
  3371. // Main Text Editing Function
  3372. function TextEditing(container_el) { // container_el = $content_text or $content_iframe body
  3373. const $srctxt = ( container_el.find('> pre').length ? container_el.find('> pre').text() : container_el.html() ); // source text equals file content or nothing
  3374.  
  3375. MDbuildUI(container_el);
  3376.  
  3377. const $toolbar = container_el.find('#toolbar');
  3378. const $source = container_el.find('#content_source');
  3379. const $preview = container_el.find('#content_preview');
  3380. const $MDhandle = container_el.find('#text_editing_handle');
  3381.  
  3382. MDsetupTextEditingUI(container_el,$srctxt);
  3383. // Toolbar button functions
  3384. $toolbar.on('click','li,span',function(e) {
  3385. e.stopPropagation();
  3386. MDtoolBarFunctions($(this));
  3387. });
  3388. $(window).on('resize',function() {
  3389. $source.add($preview).add($MDhandle).attr('style','');
  3390. });
  3391. $('body#top').on('input', '#content_source', function() {
  3392. $source.add($preview).css({'height':$('#main_content').height() - $('#content_header').height() - 32 });
  3393. });
  3394.  
  3395. // Resize
  3396. $MDhandle.on('mousedown', function(e) {
  3397. e.stopPropagation();
  3398. MDresizeSplit($MDhandle,$source,$preview);
  3399. });
  3400. // Click labels to toggle checkboxes
  3401. $preview.add($toolbar).on('click','label', function(e) {
  3402. e.stopPropagation();
  3403. $(this).siblings('input').click();
  3404. });
  3405. // Sync scroll
  3406. $source.on('scroll',function() { MDsyncScroll(this); });
  3407. $preview.on('scroll',function() { MDsyncScroll(this); });
  3408.  
  3409. // TEXT EDITING
  3410. // Generate Preview
  3411. const $source_text = ( $source.length === 0 ? '' : $source.val() );
  3412. MDmarkdown( $source_text, $preview );
  3413.  
  3414. // Live preview update, and set edited classes for unsaved warning
  3415. $source.on('input', function() {
  3416. if ( !$('body').hasClass('edited') && $(this).parents('#top').length === 1 ) {
  3417. $('body#top').addClass('edited');
  3418. }
  3419. if ( !$('body').hasClass('edited') && $(this).parents('#iframe_body').length === 1 ) {
  3420. $('body#iframeBody').addClass('edited');
  3421. sendMessage('top','iframe_edited','','');
  3422. }
  3423. MDlivePreview($source,$preview);
  3424. });
  3425. // Checklists
  3426. MDsetChecklistClass();
  3427. // Live checkboxes
  3428. $preview.on('click','.checklist input',function(e) {
  3429. e.stopPropagation();
  3430. MDliveCheckBoxes($(this),$source,$preview);
  3431. });
  3432. // Preview TOC click navigation
  3433. $preview.on('click','.table-of-contents a',function(e) {
  3434. e.preventDefault();
  3435. MDtocClick($(this),$preview);
  3436. });
  3437. $preview.on('click','.uplink',function(e) {
  3438. e.stopPropagation();
  3439. MDheaderClick($preview);
  3440. });
  3441. }
  3442. ///// END MAIN MD FUNCTION
  3443.  
  3444. // MARKDOWN Functions
  3445. // MD Build UI
  3446. function MDbuildUI(container_el) {
  3447. const toggleSplitBtn = $('<li id="toggle_split" title="Toggle Split"></li>');
  3448. const syncScrollEl = $('<li id="sync_scroll"><input name="sync_scroll" type="checkbox"><label for="sync_scroll">Sync Scroll</label></li>');
  3449. const toggleSrcBtn = $('<li id="show_source" title="Show Source"></li>');
  3450. const togglePreviewBtn = $('<li id="show_preview" title="Show Preview"></li>');
  3451. const clearTextBtn = $('<li id="clear_text" title="Clear Text">Clear</li>');
  3452. 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>');
  3453. const buttonsCont = $('<ul id="toolbar"></ul>');
  3454. buttonsCont.append(toggleSrcBtn, togglePreviewBtn, toggleSplitBtn, syncScrollEl, saveBtn, clearTextBtn);
  3455. const textEditingUI = '<textarea id="content_source"></textarea><div id="content_preview" class="markdown-body"></div><div id="text_editing_handle"></div>';
  3456. // append the UI to the container_el
  3457. container_el.prepend(buttonsCont).append(textEditingUI);
  3458. }
  3459.  
  3460. // MD Set up UI
  3461. function MDsetupTextEditingUI(container_el,sourceText) {
  3462. container_el.find('pre').first().remove();
  3463. container_el.find('#content_source').val(sourceText); // set source text from pre
  3464. if ( getQuery('split_view') === 'true' ) { $('body').addClass('split_view'); } else { $('body').removeClass('split_view'); }
  3465. if ( getQuery('default_text_view') === 'preview' ) { $('body').addClass('preview_text').removeClass('source_text'); } else { $('body').addClass('source_text').removeClass('preview_text'); }
  3466. if ( getQuery('sync_scroll') === 'true' ) { $('#sync_scroll input').prop({checked:true}); }
  3467. }
  3468. // MD UI Buttons functions
  3469. function MDtoolBarFunctions(btn) {
  3470. let $thisFileName;
  3471. let container_el = btn.closest('body');
  3472. let sourceEl = container_el.find('#content_source');
  3473. let previewEl = container_el.find('#content_preview');
  3474. if ( $body.hasClass('has_text') ) {
  3475. $thisFileName = 'untitled';
  3476. } else {
  3477. $thisFileName = decodeURI(window.location.pathname.slice(window.location.pathname.lastIndexOf('/') + 1));
  3478. }
  3479. const $thisId = btn.attr('id');
  3480. 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">';
  3481. const $saveHTMLClose = '</body></html>';
  3482. switch ($thisId) {
  3483. case 'toggle_split':
  3484. $('body').toggleClass('split_view').find('#content_source,#content_preview,#text_editing_handle').attr('style','');
  3485. if ( container_el.hasClass('source_text') ) {
  3486. sourceEl.focus();
  3487. document.getElementById('content_source').setSelectionRange(0,0);
  3488. }
  3489. break;
  3490. case 'show_source':
  3491. 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
  3492. sourceEl.css({'width':'100%'}).focus();
  3493. document.getElementById('content_source').setSelectionRange(0,0);
  3494. break;
  3495. case 'show_preview':
  3496. container_el.removeClass('split_view source_text').addClass('preview_text').find('#content_source,#content_preview,#text_editing_handle').attr('style','');
  3497. break;
  3498. case 'clear_text':
  3499. container_el.addClass('has_warning').find('#warnings').removeClass().addClass('clear');
  3500. break;
  3501. case 'save_text':
  3502. saveMD( $thisFileName, sourceEl.val() );
  3503. break;
  3504. case 'save_HTML':
  3505. saveMD( $thisFileName.slice(0,$thisFileName.lastIndexOf('.') + 1) + 'html', $saveHTMLOpen + MDprepHTML(previewEl.html()) + $saveHTMLClose );
  3506. break;
  3507. }
  3508. }
  3509. // MD Custom pre- and post-processing for text.
  3510. function MDaddHeaderIDs(match, p1, p2, p3, offset, string) { // create header ids for TOC
  3511. return '<h'+ p1 +' id="'+ p3.toLowerCase().replace(/\s/g,'-') +'" ' + p2 +'>'+ p3;
  3512. }
  3513. function MDcustomPreProcess(src) {
  3514. return src; // we're not doing anything here just yet...
  3515. }
  3516. function MDcustomPostProcess(html) {
  3517. 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
  3518. .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
  3519. // .replace(/<li><p class="checklist">"/g,'<li class="checklist"><p>')
  3520. .replace(/^<h(\d)([^>]*)>([^<]+)/gm, MDaddHeaderIDs) // add header IDs;
  3521. .replace(/<\/h(\d)>/g,'<span class="uplink">&uarr;</span></h$1>');
  3522. return html;
  3523. }
  3524. //MD Render markdown from preprocessed source text
  3525. function MDmarkdown(sourceText,previewEl) {
  3526. const MDit = window.markdownit({linkify:false,typography:false,html:true})
  3527. .use(window.markdownitMultimdTable, {enableMultilineRows: true})
  3528. .use(window.markdownitSub)
  3529. .use(window.markdownitSup)
  3530. .use(window.markdownitFootnote)
  3531. .use(window.markdownitCentertext)
  3532. .use(window.markdownitDeflist)
  3533. .use(window.markdownitTocDoneRight)
  3534. ;
  3535. let MDpreview = MDit.render( MDcustomPreProcess( sourceText ) );
  3536. previewEl.html( MDcustomPostProcess( MDpreview ) ); // set previewed html
  3537. }
  3538. // MD Live preview, add edited warning
  3539. function MDlivePreview(sourceEl,previewEl) {
  3540. MDmarkdown( sourceEl.val(),previewEl );
  3541. MDsetChecklistClass();
  3542. }
  3543.  
  3544. // MD Live Checkboxes prep: find each instance of [ ] or [x] and replace text in index = to clicked checkbox in Preview.
  3545. function MDreplaceAt(str, replacement, position) {
  3546. str = str.substring(0, position) + replacement + str.substring(position + replacement.length);
  3547. return str;
  3548. }
  3549. function MDreplaceNthSubStr(str,substr,replacement,index) {
  3550. let count = 0;
  3551. let found = substr.exec(str);
  3552. while ( found !== null ) {
  3553. if ( count === index ) {
  3554. return MDreplaceAt(str, replacement, found.index );
  3555. } else {
  3556. count++;
  3557. found = substr.exec(str);
  3558. }
  3559. }
  3560. }
  3561. // MD Live Checkboxes
  3562. function MDliveCheckBoxes(checkbox,sourceEl,previewEl) {
  3563. $('.checklist').removeClass('clicked');
  3564. checkbox.closest('p,li,dt,dd').addClass('clicked');
  3565. const thisIndex = previewEl.find('.checklist').index( $('.clicked') );
  3566. const srctext = sourceEl.val();
  3567. const substr = new RegExp(/\[\s*.\s*\]/g);
  3568. const replacement = ( checkbox.is(':checked') ? '[x]' : '[ ]' );
  3569. sourceEl.val( MDreplaceNthSubStr(srctext, substr, replacement, thisIndex) );
  3570. }
  3571. // MD Checkbox list class: Prevent checkbox lists from having list bullets
  3572. function MDsetChecklistClass() {
  3573. $('input[type="checkbox"]').closest('ul').addClass('no_list');
  3574. }
  3575.  
  3576. // MD Resize Split View
  3577. function MDresizeSplit(handle,sourceEl,previewEl) {
  3578. let $sidebarWidth = $('#sidebar').outerWidth();
  3579. let $pageWidth = window.innerWidth;
  3580.  
  3581. $(document).on('mousemove',function(e) {
  3582. e.stopPropagation();
  3583. e.preventDefault();
  3584. let pageX = e.pageX;
  3585. if ( pageX > $sidebarWidth + 100 && pageX < $pageWidth - 100 ) { // min widths
  3586. handle.css({'left': pageX - $sidebarWidth - 4 + 'px'});
  3587. sourceEl.css({'width': pageX - $sidebarWidth + 'px'});
  3588. previewEl.css({'left': sourceEl.outerWidth() + 'px'});
  3589. }
  3590. });
  3591. handle.on('mouseup',function() {
  3592. $(document).off('mousemove');
  3593. });
  3594. }
  3595. // MD UI Sync Scroll
  3596. function MDpercentage(el) { return (el.scrollTop / (el.scrollHeight - el.offsetHeight)); }
  3597. function MDsyncScroll(el1) {
  3598. let el2 = ( el1.getAttribute('id') === 'content_preview' ? document.getElementById('content_source') : document.getElementById('content_preview') );
  3599. if ( document.querySelector('input[name="sync_scroll"').checked ) {
  3600. el2.scrollTo( 0, (MDpercentage(el1) * (el2.scrollHeight - el2.offsetHeight)).toFixed(0) ); // toFixed(0) prevents scrolling feedback loop
  3601. }
  3602. }
  3603. // click TOC anchors
  3604. function MDtocClick(el,previewEl) {
  3605. let thisId = el.attr('href');
  3606. if ( thisId ) {
  3607. previewEl.scrollTop( $(thisId).offset().top - 48 );
  3608. }
  3609. }
  3610. // click Headers to return to TOC or top
  3611. function MDheaderClick(previewEl) {
  3612. if ( previewEl.find('.table-of-contents').length > 0 ) {
  3613. document.getElementsByClassName('table-of-contents')[0].scrollIntoView(true);
  3614. } else {
  3615. document.getElementById('preview').scroll(0,0);
  3616. }
  3617. }
  3618. // MD Clear text source
  3619. function clearText(container_el) {
  3620. if ( window.top !== window.self ) { // if iframe, send message to top (to remove iframe_edited class)
  3621. sendMessage('top','clear');
  3622. }
  3623. container_el.find('#content_source').show().focus().val('');
  3624. container_el.find('#content_preview').empty();
  3625. container_el.removeClass('edited has_warning');
  3626. }
  3627. // MD SAVE SOURCE or HTML
  3628. function MDprepHTML(data) {
  3629. data = data.replace(/<span\sclass="uplink">.<\/span>/g,'');
  3630. return data;
  3631. }
  3632. function saveMD(filename, data) {
  3633. let blob = new Blob([data], {type: 'text/plain'});
  3634. let downloadEl = window.document.createElement('a');
  3635. downloadEl.href = window.URL.createObjectURL(blob);
  3636. downloadEl.download = filename;
  3637. document.body.appendChild(downloadEl);
  3638. downloadEl.click();
  3639. document.body.removeChild(downloadEl);
  3640. URL.revokeObjectURL(blob);
  3641. if ( window.top !== window.self ) { // if iframe, send message to top
  3642. sendMessage('top','clear');
  3643. }
  3644. $('body,#content_source,#content_text').removeClass('edited');
  3645. }
  3646. // list of functions to remember while sending messages and then execute after warning button click
  3647. function doFunction(funcName,args) {
  3648. var funcDictionary = { 'setLocation':setLocation, 'resetContent':resetContent, 'closeContent':closeContent, 'clickThis':clickThis, 'clickRow':clickRow, 'doubleClickRow':doubleClickRow, 'indexNavigation':indexNavigation, 'clearText':clearText, 'null':null };
  3649. return funcName === 'null' ? null : funcDictionary[funcName](args);
  3650. }
  3651. // Show warning after certain user actions if text editor or iframe has edited text; otherwise do the action.
  3652. function showWarning(funcName,args) {
  3653. // Don't show the warning if func = indexNavigation or clickRow; i.e., just hide text editor;
  3654. // In other words, only show warning when changing directories or if iframe content has been edited
  3655. if ( ( $('body').hasClass('edited') && funcName !== 'indexNavigation' && funcName !== 'clickRow' ) || $('body').hasClass('iframe_edited') ) {
  3656. if ( $('body').hasClass('edited') ) { // show warning and text editor (if hidden)
  3657. $body.addClass('has_warning').find('#warnings').removeClass().addClass('unloading');
  3658. $body.removeClass('has_hidden_text').addClass('has_text');
  3659. }
  3660. if ( $('body').hasClass('iframe_edited') ) { // if iframe is edited, send unloading message
  3661. sendMessage('iframe','unloading',funcName,args); // upon receipt of message, iframe will show its warning message, based on the funcName
  3662. }
  3663. } else {
  3664. doFunction(funcName,args);
  3665. }
  3666. }
  3667. // Send a message to iframe or parent
  3668. function sendMessage(target,message,funcName,args) {
  3669. var messageObj = { 'messageContent': message, 'functionName': funcName, 'arguments': args };
  3670. if ( target === 'iframe' ) {
  3671. let contentIFrame = document.getElementById('content_iframe');
  3672. contentIFrame.contentWindow.postMessage( messageObj, '*' );
  3673. }
  3674. if ( target === 'top' ) {
  3675. window.parent.postMessage( messageObj, '*');
  3676. }
  3677. }
  3678. // Receive a message from iframe or parent, do appropriate action
  3679. function receiveMessage(e) {
  3680. if ( e.origin === 'null' || e.origin === $origin ) {
  3681. let $message = e.data.messageContent;
  3682. let funcName = e.data.functionName;
  3683. let args = e.data.arguments;
  3684.  
  3685. if ( $message === 'split_view' ) {
  3686. $iframe_body.toggleClass('split_view');
  3687. }
  3688. if ( $message === 'default_text_view' ) {
  3689. $iframe_body.toggleClass('preview_text source_text').removeClass('split_view');
  3690. }
  3691. // warn iframe that user wants to change iframes
  3692. if ( $message === 'unloading' && !$iframe_body.hasClass('has_warning') ) {
  3693. $iframe_body.addClass('has_warning').find('#warnings').removeClass().addClass('unloading').attr('data-function_name',funcName).attr('data-args',args);
  3694. }
  3695. // let top know iframe text has been edited
  3696. if ( $message === 'iframe_edited' && !$('body#top').hasClass('iframe_edited') ) {
  3697. $('body#top').addClass('iframe_edited');
  3698. }
  3699. if ( $message === 'ignore' || $message === 'clear' ) {
  3700. $('body#top').removeClass('iframe_edited');
  3701. if ( $message === 'ignore' ) { doFunction(funcName,args); }
  3702. }
  3703. }
  3704. }
  3705. window.addEventListener('message',receiveMessage,false);
  3706.  
  3707. // Edited Warning buttons: what to do when the user clicks a warning button
  3708. function editedWarningButtons(id) {
  3709. let btn = $(document.getElementById(id));
  3710. let container_el = btn.closest('body');
  3711. let func = $('#warnings').attr('data-function_name');
  3712. let args = $('#warnings').attr('data-args');
  3713. switch(id) {
  3714. case 'warning_ignore_btn': // do the user initiated func without saving the edited text
  3715. if ( window.self !== window.top ) { // if iframe, send message to top
  3716. sendMessage('top','ignore',func,args);
  3717. }
  3718. container_el.removeClass('edited has_text has_warning');
  3719. clearText(container_el);
  3720. break;
  3721. case 'warning_cancel_btn': // cancel the func
  3722. container_el.removeClass('has_warning').find('#warnings').removeClass();
  3723. break;
  3724. case 'warning_clear_btn': // clear the text editor
  3725. clearText(container_el);
  3726. break;
  3727. case 'warning_save_btn': // save the text
  3728. if ( window.top !== window.self ) { // if iframe, send message to top
  3729. sendMessage('top','clear');
  3730. }
  3731. container_el.removeClass('edited has_warning');
  3732. $('#save_text').click();
  3733. break;
  3734. case 'warning_ok_btn': // clear the text editor
  3735. $('body').removeClass('has_warning').find('#warnings').removeClass('local');
  3736. break;
  3737. }
  3738. }
  3739. $('#warnings').on('click','button',function(e) {
  3740. e.preventDefault();
  3741. editedWarningButtons( $(this).attr('id') );
  3742. });
  3743. // Edited Warning overlay: prevent user clicks on rest of UI
  3744. $('#overlay').on('click mousedown mouseup',function(e) {
  3745. e.preventDefault();
  3746. e.stopPropagation();
  3747. return;
  3748. });
  3749.  
  3750. // END Text Editing
  3751.  
  3752. })();
  3753. // THE END!