Greasy Fork 还支持 简体中文。

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-08-25 提交的版本,檢視 最新版本

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