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

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