Greasy Fork is available in English.

Supercharged Local Directory File Browser

Makes directory index pages (either local or remote open directories) actually useful. Adds sidebar and content preview pane; keyboard navigation; sorting; light/dark UI; preview images/fonts in navigable grids; browse subdirectories w/o page reload; media playback, with shuffle/loop options; basic playlist (m3u) & cuesheet (.cue) support; create, edit, preview, save markdown/plain text files; much more.

Fra 18.06.2023. Se den seneste versjonen.

  1. /* eslint-disable no-case-declarations, no-fallthrough, indent, no-mixed-spaces-and-tabs, no-multi-spaces, no-return-assign, no-useless-escape, quotes */
  2. /* jshint esversion: 6 */
  3.  
  4. // ==UserScript==
  5. // @name Supercharged Local Directory File Browser
  6. // @version 8.0.0
  7. // @description Makes directory index pages (either local or remote open directories) actually useful. Adds sidebar and content preview pane; keyboard navigation; sorting; light/dark UI; preview images/fonts in navigable grids; browse subdirectories w/o page reload; media playback, with shuffle/loop options; basic playlist (m3u) & cuesheet (.cue) support; create, edit, preview, save markdown/plain text files; much more.
  8. // @author gaspar_schot
  9. // @license GPL-3.0-or-later
  10. // @homepageURL https://openuserjs.org/scripts/gaspar_schot/Supercharged_Local_Directory_File_Browser
  11. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACAAgMAAAC+UIlYAAAACVBMVEUmRcmZzP8zmf8pVcWPAAAAAXRSTlMAQObYZgAAAFBJREFUeF7tyqERwDAMBEE3mX5UiqDmqwwziTPHjG7xrmzrLFtRaApDIRiKQlMYCsFQFJrCUAiGotAU5hTA1WB4fhkMBsOJwWAwgHvB8CHpBcTbpxy4RZNvAAAAAElFTkSuQmCC
  12. // @match file://*/*
  13. // @match about:blank
  14. // @match https://www.example.com/path/to/directory/*
  15.  
  16. // @require https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.min.js
  17. // @require https://cdn.jsdelivr.net/npm/markdown-it-footnote@3.0.2/dist/markdown-it-footnote.min.js
  18. // @require https://cdn.jsdelivr.net/npm/markdown-it-toc-done-right@2.1.0/dist/markdown-it-toc-made-right.min.js
  19. // @require https://cdn.jsdelivr.net/npm/markdown-it-sub@1.0.0/dist/markdown-it-sub.min.js
  20. // @require https://cdn.jsdelivr.net/npm/markdown-it-sup@1.0.0/dist/markdown-it-sup.min.js
  21. // @require https://cdn.jsdelivr.net/npm/markdown-it-deflist@2.0.3/dist/markdown-it-deflist.min.js
  22. // @require https://cdn.jsdelivr.net/npm/markdown-it-multimd-table@4.0.2/dist/markdown-it-multimd-table.min.js
  23. // @require https://cdn.jsdelivr.net/npm/markdown-it-center-text@1.0.4/dist/markdown-it-center-text.min.js
  24. // @require https://cdn.jsdelivr.net/npm/opentype.js@1.3.4/dist/opentype.min.js
  25. // @require https://cdn.jsdelivr.net/npm/@gerhobbelt/markdown-it-checkbox@1.2.0-3/dist/markdownItCheckbox.umd.js
  26.  
  27.  
  28. // @namespace https://greatest.deepsurf.us/users/16170
  29. // ==/UserScript==
  30.  
  31. (function () {
  32. // ************ J + M + J ************* //
  33. 'use strict';
  34. // ***** UI SETTINGS ***** //
  35. const UI_Prefs_Bool = {
  36. alternate_background: true,
  37. apps_as_dirs: true,
  38. autoload_index_files: true,
  39. ignore_ignored_items: true,
  40. media_autoload: true,
  41. media_autoplay: true,
  42. media_play_all: true,
  43. show_details: true,
  44. show_ignored_items: true,
  45. show_image_thumbnails: true,
  46. show_image_thumbnails_always: true,
  47. show_large_image_thumbnails: true,
  48. show_invisibles: true,
  49. show_numbers: true,
  50. show_sidebar: true,
  51. text_editing_enable: true,
  52. texteditor_split_view: true,
  53. texteditor_sync_scroll: true,
  54. use_custom_icons: true,
  55. }
  56. const UI_Prefs_Non_Bool = {
  57. grid_font_size: 1, // Default = 1
  58. grid_image_size: 184, // Default = 184 (200px - 16px)
  59. sort_by: 'default', // Choose from: 'name', 'size', 'date', 'kind', 'ext', 'default ( = Chrome sorting: dirs on top, files alphabetical).
  60. sort_direction: 'ascending', // Choose from: 'ascending' (A-Z) [default] or 'descending' (Z-A).
  61. texteditor_view: 'preview', // Options: 'texteditor_preview','texteditor_view_html'
  62. theme: 'light', // Options: 'light' or 'dark'
  63. ui_font: 'system-ui, sans-serif', // Choose an installed font for the UI; if undefined, use browser defaults instead. [system-ui, sans-serif]
  64. ui_font_size: '13px', // Choose a default UI font size; use any standard CSS units.
  65. ui_scale: '100',
  66. }
  67. let UI_Settings = {
  68. ...UI_Prefs_Bool,
  69. ...UI_Prefs_Non_Bool
  70. };
  71. const Item_Kinds = {
  72. dir: ['/'], // loaded in iframe#content_iframe
  73. app: ['app/', 'app', 'appimage', 'apk', 'exe', 'ipa', 'ipk', 'jar', 'msi', 'wsf'], // generally ignored; some apps may be opened as directories
  74. alias: ['alias', 'desktop', 'directory', 'lnk', 'symlink', 'symlink/'],
  75. archive: ['7z', 'archive', 'b6z', 'bin', 'bzip', 'bz2', 'cbr', 'dmg', 'gz', 'iso', 'mpkg', 'pkg', 'rar', 'sit', 'sitx', 'tar', 'tar.gz', 'zip', 'zipx', 'zxp'], // ignored
  76. audio: ['aac', 'aif', 'aiff', 'ape', 'flac', 'm4a', 'mka', 'mp3', 'ogg', 'opus', 'wav'], // loaded in audio#audio
  77. bin: ['a', 'ase', 'bundle', 'dll', 'dyld', 'dylib', 'gem', 'icc', 'msi', 'profraw', 'pyc', 'pyo', 'o', 'rakefile', 'ri', 'so', 'torrent', 'xml', '2', 'opml', 'qm', 'scpt', 'uo', 'vsix', 'zwc'], // ignored
  78. code: ['bak', 'bash', 'bash_profile', 'bashrc', 'bat', 'cgi', 'com', 'c', 'cfg', 'cnf', 'codes', 'coffee', 'conf', 'csh', 'cshrc', 'cson', 'css', 'cuetxt', 'custom_aliases', 'd', 'default', 'description', 'dist', 'editorconfig', 'emacs', 'example', 'gemspec', 'gitconfig', 'gitignore', 'gitignore_global', 'h', 'hd', 'ini', 'js', 'json', 'jsx', 'less', 'list', 'local', 'login', 'logout', 'lua', 'mkshrc', 'old', 'pc', 'php', 'pl', 'plist', 'pre-oh-my-zsh', 'profile', 'pth', 'py', 'rb', 'rc', 'rdoc', 'sass', 'settings', 'sh', 'strings', 'taskrc', 'tcl', 'viminfo', 'vimrc', 'vue', 'vtt', 'yaml', 'yml', 'zlogin', 'zlogout', 'zpreztorc', 'zprofile', 'zsh', 'zshenv', 'zshrc'], // treated as text, opened in iframe#content_iframe text editor
  79. database: ['accdb', 'db', 'dbf', 'mdb', 'pdb', 'sql', 'sqlite', 'sqlitedb', 'sqlite3'], // ignored
  80. ebook: ['azw', 'azw1', 'azw3', 'azw4', 'epub', 'ibook', 'kfx', 'mobi', 'tpz'], // ignored
  81. font: ['otf', 'ttf', 'woff', 'woff2', 'afm', 'pfb', 'pfm', 'tfm'], // opened in div#content_font
  82. graphics: ['afdesign', 'afpub', 'ai', 'book', 'dtp', 'eps', 'fm', 'icml', 'icns', 'idml', 'indd', 'indt', 'inx', 'mif', 'pmd', 'pub', 'qxb', 'qxd', 'qxp', 'sla', 'swf', 'ai', 'arw', 'cr2', 'dng', 'eps', 'jpf', 'nef', 'psd', 'psd', 'raw', 'tif', 'tiff'], // ignored
  83. htm: ['htm', 'html', 'xhtm', 'xhtml'], // opened in iframe#content_iframe
  84. image: ['apng', 'bmp', 'gif', 'ico', 'jpeg', 'jpg', 'png', 'svg', 'webp'],
  85. link: ['url', 'webloc', 'inetloc'],
  86. markdown: ['md', 'markdown', 'mdown', 'mkdn', 'mkd', 'mdwn', 'mdtxt', 'mdtext'], // treated as text, opened in iframe#content_iframe text editor
  87. other_ignored: ['alias', 'cue', 'dat', 'dic', 'idx', 'xmp'],
  88. office: ['csv', 'doc', 'docx', 'epub', 'key', 'numbers', 'odf', 'ods', 'odt', 'pages', 'rtf', 'scriv', 'wpd', 'wps', 'xlr', 'xls', 'xlsx', 'xlm'], // ignored
  89. playlist: ['m3u', 'm3u8', 'pls', 'asx', 'wpl', 'xspf'],
  90. pdf: ['pdf'], // open in #content_pdf
  91. system: ['DS_Store', 'ds_store', 'icon', 'ics', 'spotlight-v100/', 'temporaryitems/', 'documentrevisions-v100/', 'trashes/', 'fseventsd/', 'dbfseventsd', 'file', 'programdata', 'localized'], // ignored system items
  92. text: ['log', 'nfo', 'txt', 'text', 'readme'], // opened in iframe#content_iframe text editor
  93. video: ['m4v', 'mkv', 'mov', 'mp4', 'mpeg', 'webm'] // loaded in video#content_video
  94. };
  95. const Item_Settings = { // ITEM_SETTINGS: Ignore or Exclude files by extension (prevents browser from attempting to download the file).
  96. ignored: [...Item_Kinds.archive, ...Item_Kinds.bin, ...Item_Kinds.database, ...Item_Kinds.graphics, ...Item_Kinds.other_ignored, ...Item_Kinds.office, ...Item_Kinds.playlist, ...Item_Kinds.system]
  97. };
  98.  
  99. // ***** UTILITIES ***** //
  100. function loadFileURL() { // ===> LOAD FILE URL
  101. // if window.location points to a file, change the location to the file's container dir, add search_param of file name; then load the file's container dir and load file in content pane.
  102. let search_params = getSearchParams();
  103. search_params.set('file', window.location.pathname.split('/').reverse()[0]);
  104. window.location = window.location.pathname.slice(0, window.location.pathname.lastIndexOf('/')) + '/?' + search_params;
  105. return;
  106. }
  107. if (!window.location.pathname.endsWith('/') && window.top === window.self) {
  108. loadFileURL();
  109. } // load file urls
  110. //==============================//
  111. function isTopWindow() {
  112. return (window.top === window.self || false)
  113. } // ===> TOP WINDOW OR IFRAME
  114. function getBrowser() { //*** needs testing for new userAgentData object --> what are possible brand names?; combine with getOS() // ===> GET BROWSER
  115. let brand = (navigator.userAgentData !== undefined ? navigator.userAgentData.brands[1].brand.toLowerCase() : navigator.userAgent);
  116. switch (true) {
  117. case brand === 'chromium' || (/chrome?chromium/.test(brand)):
  118. return 'is_chrome';
  119. case brand === 'msie' || (/msie/.test(brand)):
  120. return 'is_explorer';
  121. case brand === 'opera' || (/opera/.test(brand)):
  122. return 'is_opera';
  123. case brand === 'safari' || (/safari/.test(brand)):
  124. return 'is_safari';
  125. case brand === 'firefox' || (!/chrome|chromium/.test(brand)):
  126. return 'is_gecko';
  127. }
  128. }
  129.  
  130. function getOS() { // modded from https://***stackoverflow.com/questions/38241480/detect-macos-ios-windows-android-and-linux-os-with-js // ===> GET OS
  131. let platform = (navigator.userAgentData !== undefined ? navigator.userAgentData.platform : window.navigator.platform).toLowerCase();
  132. let macos_platforms = ['macos', 'macintosh', 'macintel', 'macppc', 'mac68k'],
  133. windows_platforms = ['win32', 'win64', 'windows', 'wince'],
  134. os = null;
  135. switch (true) {
  136. case macos_platforms.indexOf(platform) !== -1:
  137. os = 'macos';
  138. break;
  139. case windows_platforms.indexOf(platform) !== -1:
  140. os = 'windows';
  141. break;
  142. case !os && /Linux/.test(platform):
  143. os = 'linux';
  144. break;
  145. }
  146. return os;
  147. }
  148.  
  149. function newURL(link) {
  150. try {
  151. return new URL(link, document.baseURI);
  152. }
  153. catch (error) {
  154. return new URL(encodeURI(link));
  155. }
  156. } // ===> NEW URL
  157. function decodeURIComponentSafe(str) {
  158. if (!str) {
  159. return str;
  160. } // ===> DECODE URI COMPONENT SAFE; // Fix "%" error in file name; see stackoverflow.com/questions/7449588/why-does-decodeuricomponent-lock-up-my-browser
  161. try {
  162. return decodeURIComponent(str.replace(/%(?![0-9a-fA-F]{2})/g, '%25')).replace(/\"/g, '\"');
  163. }
  164. catch (e) {
  165. return str;
  166. } // replace % with %25 if not followed by two a-f/number; replace " with html entity
  167. }
  168.  
  169. function convertHex2Decimal(d) {
  170. return parseInt(d, 16);
  171. }
  172.  
  173. function convertDecimal2Hex(d, padding) {
  174. let hex = Number(d).toString(16);
  175. hex = (isNaN(hex) ? null : "000000".substr(0, padding - hex.length) + hex);
  176. return hex;
  177. }
  178. //==============================//
  179. const window_protocol = window.location.protocol; // GLOBAL: protocol
  180. let window_location = decodeURIComponentSafe([location.protocol, '//', location.host, location.pathname].join('')); // GLOBAL: current location
  181. const current_dir_path = window_location.replace(/([/|_|—])/g, '$1<wbr>').replace(/\\/g, '/'); // GLOBAL: current dir path w/o query string for display
  182. //==============================//
  183. function setLocation(link) {
  184. window.location = link;
  185. }
  186.  
  187. function changeLocation(args) { // args[0] === href, args[1] === 'external || ok'
  188. switch (true) {
  189. case args[1] === 'external':
  190. window.open(args[0]);
  191. break; // open external menu links: about, coffee, contact
  192. case args[1] === 'ok':
  193. window.location = args[0];
  194. break;
  195. case (/has_\w+list/.test(getClassNames('body'))):
  196. args = window.location.href; // nobreak; show playlist warning
  197. default:
  198. showWarning('setLocation', args.toString());
  199. }
  200. }
  201.  
  202. function getSearchParams() {
  203. let search_params = new URL(window.location).searchParams;
  204. search_params.sort();
  205. return search_params;
  206. } // ===> GET SEARCH PARAMS
  207. function searchParamSet(key, value, bool) {
  208. let search_params = getSearchParams();
  209. search_params.set(key, value);
  210. if (bool !== false) {
  211. updateSearchParams(search_params);
  212. }
  213. } // ===> SET SEARCH PARAM (bool false = don't update)
  214. function searchParamDelete(key) {
  215. let search_params = getSearchParams();
  216. search_params.delete(key);
  217. updateSearchParams(search_params);
  218. } // ===> REMOVE SEARCH PARAM
  219. function updateSearchParams(search_params) { // ===> UPDATE SEARCH PARAMS
  220. search_params = sanitizeSearchParams(search_params);
  221. search_params.sort(); // sort and sanitize params
  222. let search_params_str = search_params.toString().replace(/%2F/g, '').replace('/', '').replace(/%2Cfalse/g, ''); // further sanitization
  223. let new_location = (search_params_str.length === 0 ? window.location.pathname : window.location.pathname + '?' + search_params_str); // don't add ? if no search params
  224. window.history.replaceState({}, document.title, new_location); // set new location
  225. if (isTopWindow()) {
  226. updateParentLinks();
  227. }
  228. }
  229.  
  230. function sanitizeSearchParams(search_params_str) { // remove search_params that are not in UI_Settings
  231. for (let entry of search_params_str.entries()) {
  232. if (!UI_Settings[entry[0]] && !/selected|history|width/.test(entry[0])) {
  233. search_params_str.delete(entry[0]);
  234. }
  235. }
  236. return search_params_str;
  237. }
  238.  
  239. function getCurrentUIPref(pref_id) { // ===> GET SEARCH PARAM value by key
  240. let search_params = getSearchParams(),
  241. value = '';
  242. switch (true) {
  243. case pref_id === 'width':
  244. if (!isTopWindow()) {
  245. return;
  246. } // width: set the stored sidebar width or use default 30%
  247. value = (!search_params.has(pref_id) || window.innerWidth === 0 ? 30 : Math.round(100 * Number.parseInt(search_params.get('width')) / window.innerWidth));
  248. break; // percentage
  249. case pref_id === 'parent_id':
  250. value = (search_params.has(pref_id) ? search_params.get(pref_id) : UI_Settings?.[pref_id] ? UI_Settings[pref_id].toString() : '');
  251. break; //
  252. default: // if query_string has key/value pair, use it, else use key/value pair from UI_Settings
  253. value = (search_params.has(pref_id) ? search_params.get(pref_id) : UI_Settings?.[pref_id] ? UI_Settings[pref_id].toString() : pref_id);
  254. value = value?.replace('%2F', '').replace('/', ''); // some servers add a '/' to end of query string
  255. }
  256. return value;
  257. }
  258.  
  259. function getNewUIPref(key) {
  260. let value, bool_prefs = Object.keys(UI_Prefs_Bool);
  261. let non_bool_prefs = {
  262. 'sort_direction_ascending': {
  263. 'sort_direction': 'descending'
  264. },
  265. 'sort_direction_descending': {
  266. 'sort_direction': 'ascending'
  267. },
  268. 'sort_by_name': {
  269. 'sort_by': 'name'
  270. },
  271. 'sort_by_default': {
  272. 'sort_by': 'default'
  273. },
  274. 'sort_by_duration': {
  275. 'sort_by': 'duration'
  276. },
  277. 'sort_by_size': {
  278. 'sort_by': 'size'
  279. },
  280. 'sort_by_date': {
  281. 'sort_by': 'date'
  282. },
  283. 'sort_by_kind': {
  284. 'sort_by': 'kind'
  285. },
  286. 'sort_by_ext': {
  287. 'sort_by': 'ext'
  288. },
  289. 'texteditor_view': {
  290. 'texteditor_view': getCurrentUIPref('texteditor_view')
  291. },
  292. 'texteditor_view_raw': {
  293. 'texteditor_view': 'txt'
  294. },
  295. 'texteditor_view_preview': {
  296. 'texteditor_view': 'preview'
  297. },
  298. 'texteditor_view_html': {
  299. 'texteditor_view': 'html'
  300. },
  301. 'theme': {
  302. 'theme': (getCurrentUIPref('theme') === 'light' ? 'dark' : 'light')
  303. },
  304. 'theme_dark': {
  305. 'theme': 'dark'
  306. },
  307. 'theme_light': {
  308. 'theme': 'light'
  309. },
  310. 'ui_font': {
  311. 'ui_font': getCurrentUIPref('ui_font')
  312. },
  313. 'ui_scale': {
  314. 'ui_scale': getCurrentUIPref('ui_scale')
  315. }
  316. }
  317. switch (true) {
  318. case bool_prefs.includes(key):
  319. return (getCurrentUIPref(key) === 'true' ? [key, 'false'] : [key, 'true']); // toggle bool prefs
  320. default:
  321. value = Object.values(non_bool_prefs[key]).toString();
  322. key = Object.keys(non_bool_prefs[key]).toString();
  323. return [key, value]; // get value for key; then key (i.e., don't redefine key before getting value)
  324. }
  325. }
  326. let str = ''; // global str var;
  327. function timeoutID() {
  328. return window.setTimeout(() => {
  329. str = '';
  330. }, 1000);
  331. } // ===> TIMEOUT ID: reset typed string to '' after 1.5 sec.
  332. //==============================//
  333. function getEl(sel) {
  334. try {
  335. return document.querySelector(sel);
  336. }
  337. catch (error) {
  338. return null;
  339. }
  340. }
  341.  
  342. function getEls(sel) {
  343. try {
  344. return document.querySelectorAll(sel);
  345. }
  346. catch (error) {
  347. return null;
  348. }
  349. }
  350.  
  351. function elExists(sel) {
  352. return (document.querySelector(sel) !== null ? true : false);
  353. }
  354.  
  355. function fileNotFound(e, id) {
  356. if (e.type === 'error') {
  357. if (id === 'audio') {
  358. addClass('#content_pane', 'has_audio_error');
  359. setContentTitle('has_audio_error');
  360. }
  361. else {
  362. addClass('#content_pane', 'content_error');
  363. closeContent();
  364. setContentTitle('error');
  365. }
  366. }
  367. }
  368.  
  369. function getVisibleElsBySelector(sel) { // ===> GET VISIBLE ELS BY SELECTOR // remove els with display:none or 0 width/height
  370. let els = Array.from(getEls(sel)).filter((el) => {
  371. let el_styles = window.getComputedStyle(el);
  372. return (el_styles.getPropertyValue('display') !== 'none' || (el.offsetWidth > 0 || el.offsetHeight > 0));
  373. });
  374. return els;
  375. }
  376.  
  377. function getContentPaneData() {
  378. return getAttribute('#content_pane', 'data-content');
  379. } // ===> GET CONTENT_PANE DATA content
  380. function hasContent(args) { // ===> HAS CONTENT?
  381. switch (true) {
  382. case args === undefined:
  383. return (hasClass('#content_pane', 'has_audio') || getContentPaneData() !== 'has_null' ? true : false); // has any content
  384. case args.includes('audio'):
  385. return (hasClass('#content_pane', 'has_audio') && (args.includes('ignore') || getContentPaneData() === 'has_null') ? true : false); // has audio only or ignore other content
  386. case args.includes('_'):
  387. return hasClass('#content_pane', 'has_' + args);
  388. default:
  389. return (args.split(',').includes(getContentPaneData()?.split('_')[1]) ? true : false); // has named content (e.g., pdf, iframe)
  390. }
  391. }
  392.  
  393. function initContentError(id, content_el_id) {
  394. if (id !== 'close') {
  395. getEl(content_el_id).addEventListener('error', (e) => {
  396. fileNotFound(e, content_el_id);
  397. });
  398. }
  399. } // ===> INIT CONTENT ERROR
  400. //==============================//
  401. function getClassNames(sel) {
  402. return getEl(sel)?.className;
  403. }
  404.  
  405. function hasClass(sel, classname) {
  406. let el = getEl(sel);
  407. return el?.classList.contains(classname);
  408. } // ===> HAS CLASS
  409. function addClass(sel, classname) {
  410. let els = Array.from(getEls(sel)),
  411. classes = classname.split(' ').filter(item => item);
  412. els?.forEach(el => el.classList.add(...classes));
  413. } // ===> ADD CLASS
  414. function removeClass(sel, classname) { // ===> REMOVE CLASS
  415. let els = Array.from(getEls(sel)),
  416. classes = (classname?.split(' ')?.filter(item => item) || null);
  417. if (classname === undefined || classes === null) {
  418. els?.forEach(el => el.removeAttribute('class'));
  419. }
  420. else {
  421. els?.forEach(el => el.classList.remove(...classes));
  422. } // if no className provided, remove all classes
  423. }
  424.  
  425. function addRemoveClassSiblings(sel, classname) { // ===> ADD/REMOVE CLASS SIBLINGS
  426. let el = document.querySelector(sel),
  427. siblings = el?.parentElement.children;
  428. if (el !== null) {
  429. Array.from(siblings).forEach(sibling => sibling.classList.remove(...classname.replace(/\s{2,}/g, ' ').split(' ')));
  430. addClass(sel, classname);
  431. } // remove class from els & add class to selected el
  432. }
  433. //==============================//
  434. function getAttribute(sel, attributeName) {
  435. let el = getEl(sel);
  436. return el?.getAttribute(attributeName);
  437. } // ===> GET ATTRIBUTE
  438. function hasAttribute(sel, attributeName) {
  439. let el = getEl(sel);
  440. return el?.hasAttribute(attributeName);
  441. } // ===> HAS ATTRIBUTE
  442. function setAttribute(sel, attributeName, value) {
  443. let el = getEl(sel);
  444. el?.setAttribute(attributeName, value);
  445. } // ===> SET ATTRIBUTE
  446. function removeAttribute(sel, attributeNamesArr) { // ===> REMOVE ATTRIBUTE
  447. if (typeof attributeNamesArr === 'string') {
  448. attributeNamesArr = [attributeNamesArr];
  449. }
  450. let els = getEls(sel);
  451. Array.from(els)?.forEach(el => attributeNamesArr.forEach(attributeName => el.removeAttribute(attributeName)));
  452. }
  453.  
  454. function getData(sel, keyname) {
  455. let el = getEl(sel);
  456. return el.getAttribute('data-' + keyname);
  457. }
  458.  
  459. function setData(sel, keyname, value) {
  460. let el = getEl(sel);
  461. el.setAttribute('data-' + keyname, value);
  462. }
  463.  
  464. function setStyle(sel, property, value) {
  465. getEl(sel).style.setProperty(property, value);
  466. }
  467.  
  468. function setValue(sel, value) {
  469. getEl(sel).value = value;
  470. }
  471. //==============================//
  472. function clickThis(sel) {
  473. let el = getEl(sel);
  474. (el?.querySelector('a')?.click() || el?.click())
  475. } // ===> CLICK THIS by CSS selector
  476. function altKey(e) {
  477. return (!e.metaKey && !e.ctrlKey && e.altKey && !e.shiftKey);
  478. } // ===> ALT KEY test
  479. function altShiftKey(e) {
  480. return (!e.metaKey && !e.ctrlKey && e.altKey && e.shiftKey);
  481. } // ===> ALT SHIFT KEY test
  482. function cmdKey(e) {
  483. return ((e.metaKey || e.ctrlKey) && !e.altKey && !e.shiftKey);
  484. } // ===> CMD/CTRL KEY test
  485. function cmdAltKey(e) {
  486. return ((e.metaKey || e.ctrlKey) && e.altKey && !e.shiftKey);
  487. } // ===> CMD/CTRL ALT KEY test
  488. function cmdShiftKey(e) {
  489. return ((e.metaKey || e.ctrlKey) && !e.altKey && e.shiftKey);
  490. } // ===> CMD/CTRL SHIFT KEY test
  491. function eStopPrevent(e) {
  492. e?.preventDefault();
  493. e?.stopPropagation();
  494. }
  495. //============================//
  496. // ***** BASIC UI FUNCTIONS ***** //
  497. function isInViewport(sel) {
  498. const rect = (getEl(sel) !== null ? getEl(sel).getBoundingClientRect() : null);
  499. if (rect === null) {
  500. return false;
  501. }
  502. return (rect.top >= getEl('#dir_header').offsetHeight && rect.bottom <= (window.innerHeight - getEl('#dir_footer').offsetHeight || document.documentElement.clientHeight - getEl('#dir_footer').offsetHeight));
  503. }
  504.  
  505. function scrollThis(container_ID, sel, bool) { // ===> SCROLL to Selected Item
  506. let container = getEl(container_ID);
  507. if (container?.height === 0 || isInViewport(sel)) {
  508. return;
  509. } // don't scroll hidden elements
  510. let scroll_el = container?.querySelector(sel),
  511. scroll_behavior = ((bool !== undefined || bool === true) ? 'instant' : 'smooth'),
  512. scroll_block = (hasClass('body', 'is_gecko') ? 'start' : 'nearest');
  513. scroll_el?.scrollIntoView({
  514. behavior: scroll_behavior,
  515. block: scroll_block,
  516. inline: 'nearest'
  517. });
  518. }
  519.  
  520. function mouseMove(e, sel, startX, startY, elOffsetLeft, elOffsetTop) { // ===> Init events to allow glyphs to be dragged into view
  521. let scale_factor = (sel === '#font_specimen_glyph' ? 2 : 1); // scale_factor needed for svg glyphs
  522. setStyle(sel, 'left', elOffsetLeft + (e.pageX - startX) * scale_factor + 'px');
  523. setStyle(sel, 'top', elOffsetTop + (e.pageY - startY) * scale_factor + 'px');
  524. }
  525. //==============================// OPEN/SAVE FILES
  526. function openFile(args) {
  527. menuClose(); // ===> OPEN FILE; type: font or playlist.
  528. if (window.File && window.FileReader && window.FileList && window.Blob) { // if browser supports file API...
  529. let files = args[0].target.files[0],
  530. id = args[1],
  531. reader = new FileReader();
  532. switch (id) {
  533. case 'open_font':
  534. reader.readAsArrayBuffer(files);
  535. break;
  536. case 'open_playlist':
  537. reader.readAsText(files);
  538. break;
  539. } // get the file reader
  540. reader.onload = () => { // on file reader load
  541. switch (true) {
  542. case id === 'open_font':
  543. openFontFile(files, reader);
  544. break;
  545. case id === 'open_playlist':
  546. openPlaylist(files.name, '', reader.result);
  547. break;
  548. } // open the file
  549. return true;
  550. }
  551. getEl('#' + id).value = ''; // reset input to allow same item to be reopened immediately after closing
  552. }
  553. else {
  554. alert('Can\'t open file: file APIs are not fully supported in this browser.');
  555. } // else error
  556. }
  557.  
  558. function saveFile(content, mimetype, file_name) { // ===> SAVE FILE
  559. let blob = new Blob([content], {
  560. type: mimetype
  561. });
  562. let download_el = window.document.createElement('a');
  563. download_el.style = "display:none";
  564. download_el.href = window.URL.createObjectURL(blob);
  565. download_el.download = file_name; // define & style download_el
  566. document.body.appendChild(download_el);
  567. download_el.click();
  568. document.body.removeChild(download_el);
  569. URL.revokeObjectURL(blob); // add download_el, click, & remove
  570. }
  571. // END UTILITIES
  572. //==============================//
  573. // ***** SET UP UI ELEMENTS ***** //
  574. function updateParentLinkSearchParams(str) { //*** decrement selected and history values ***// // ===> UPDATE PARENT LINK SEARCH PARAMS
  575. let query_str = new URLSearchParams(str);
  576. query_str.sort(); // make new search params from window.location.search
  577. let history = (query_str.has('history') ? query_str.get('history') : undefined);
  578. switch (true) {
  579. case history !== undefined:
  580. history = history.split(' ');
  581. switch (true) {
  582. case history.length > 1:
  583. query_str.set('selected', history[0]);
  584. history.shift();
  585. query_str.set('history', history.join('+'));
  586. break;
  587. case history.length === 1:
  588. query_str.set('selected', history[0]);
  589. history.shift();
  590. query_str.delete('history');
  591. break;
  592. }
  593. break;
  594. default:
  595. query_str.delete('selected');
  596. }
  597. return decodeURIComponentSafe(query_str.toString());
  598. }
  599.  
  600. function createParentLinks() { // ===> CREATE PARENT LINKS
  601. let link, links = [],
  602. search_params = getSearchParams();
  603. search_params.sort();
  604. let query_str = search_params.toString();
  605. let link_pieces = window_location.split('/');
  606. link_pieces = link_pieces.slice(2, -2); // make array of parent directories; remove beginning and ending empty elements and current directory
  607. while (link_pieces.length > 0) { // while there are link pieces...
  608. query_str = updateParentLinkSearchParams(query_str); // update selected and history
  609. link = window_protocol + '//' + link_pieces.join('/') + '/?' + query_str;
  610. links.push(link);
  611. link_pieces.pop(); // assemble link; add to link array; remove last link piece and repeat...
  612. }
  613. return links;
  614. }
  615.  
  616. function createParentLinkItems() { // ===> CREATE PARENT LINK ITEMS
  617. let parent_link_menu_items = [],
  618. links = createParentLinks();
  619. for (let i = 0; i < links.length; i++) {
  620. let display_name = links[i].split('/?')[0];
  621. display_name = display_name.replace(/\//g, '\/<wbr>');
  622. let menu_item = `<li><a id="parents_link_${i}" href="${ links[i] }" class="display_block padding_4_8">${ display_name }/</a></li>`;
  623. parent_link_menu_items.push(menu_item);
  624. }
  625. let parent_link = (links[0] === undefined ? window.location.href : links[0]);
  626. parent_link = parent_link.replace(/parents_link_/, 'parent_link_');
  627. return [parent_link_menu_items.join(''), parent_link]; // return parents link items
  628. }
  629.  
  630. function updateParentLinks() { // ===> UPDATE PARENT LINKS and init new item events
  631. let links = createParentLinkItems();
  632. getEl('#parents_links').innerHTML = links[0];
  633. getEl('#parent_dir_nav a').href = links[1]; // add the links
  634. getEls('#dir_menu_parent a,#parents_links a').forEach(el => el.onclick = function (e) {
  635. eStopPrevent(e);
  636. showWarning('changeLocation', [this.href, 'false']);
  637. }); // reinit onclick
  638. }
  639. //==============================//
  640. // SVG UI ICONS
  641. const SVG_UI_Icons = {
  642. 'arrow': '<svg viewBox=\'0 0 20 20\' xmlns=\'http://www.w3.org/2000/svg\' class=\'invert\'><path fill=\'%23888\' fill-opacity=\'.75\' d=\'m4 4 12 6-12 6z\'/></svg>',
  643. 'bookmark': '<svg viewBox=\'0 0 20 20\' xmlns=\'http://www.w3.org/2000/svg\' class=\'invert\'><path fill=\'%23888\' d=\'m2 2c0-1.1.9-2 2-2h12a2 2 0 0 1 2 2v18l-8-4-8 4zm2 0v15l6-3 6 3v-15z\'/></svg>',
  644. 'check_mark': '<svg viewBox=\'0 0 12 9\' xmlns=\'http://www.w3.org/2000/svg\'><path fill=\'currentColor\' d=\'m-.071 10.929 2.571-2.571 4.5 4.499 10.285-10.285 2.571 2.572-12.856 12.856z\' transform=\'matrix(.55 0 0 .55 .578932 -1.01245)\'/></svg>',
  645. 'chevron': '<svg viewBox=\'0 0 24 14\' id=\'svg_chevron\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m0 0v14h3v-11h11v-3z\' transform=\'matrix(.707107 .707107 -.707107 .707107 11.8995 1)\'/></svg>',
  646. 'document': '<svg viewBox=\'0 0 20 20\' xmlns=\'http://www.w3.org/2000/svg\'><path fill=\'%23222222\' d=\'M4 18h12V6h-4V2H4v16zm-2 1V0h12l4 4v16H2v-1z\' /></svg>',
  647. 'error': '<svg viewBox=\'0 0 20 20\' xmlns=\'http://www.w3.org/2000/svg\'><g fill-opacity=\'.75\'><path d=\'m1.075 18.05 8.146-16.683c.236-.484.924-.491 1.169-.011l8.537 16.683c.223.435-.093.952-.582.952h-16.683c-.483 0-.799-.507-.587-.941z\' fill=\'%23ffb636\' /><path d=\'m11.055 7.131-.447 6.003c-.034.45-.425.787-.874.753-.408-.03-.724-.356-.753-.753l-.447-6.003c-.052-.696.47-1.302 1.167-1.354.696-.052 1.302.47 1.354 1.166.005.061.004.129 0 .188zm-1.26 8.037c-.641 0-1.159.518-1.159 1.158 0 .641.518 1.159 1.159 1.159.64 0 1.158-.518 1.158-1.159 0-.64-.518-1.158-1.158-1.158z\'/></g></svg>',
  648. 'external_link': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'M10.443,2.5l-3.439,-0l0,-1.5l5.996,0l0,6.02l-1.5,0l0,-3.455l-5.716,5.715l-1.06,-1.06l5.719,-5.72Zm1.057,5.5l-0,5l-10.5,0l-0,-10.5l5,0l-0,1.5l-3.5,0l-0,7.5l7.5,0l-0,-3.5l1.5,0Z\' style=\'fill:%23888;\'/></svg>',
  649. 'folder': '<svg viewBox=\'0 0 20 20\'><path fill=\'%23222\' d=\'m0 4c0-1.1.9-2 2-2h7l2 2h7a2 2 0 0 1 2 2v10a2 2 0 0 1 -2 2h-16a2 2 0 0 1 -2-2zm2 2v10h16v-10z\'/></svg>',
  650. 'grid': '<svg viewBox=\'0 0 20 20\'><path fill=\'currentColor\' d=\'M0 0h9v9H0V0zm2 2v5h5V2H2zm-2 9h9v9H0v-9zm2 2v5h5v-5H2zm9-13h9v9h-9V0zm2 2v5h5V2h-5zm-2 9h9v9h-9v-9zm2 2v5h5v-5h-5z\' /></svg>',
  651. 'menu': '<svg viewBox=\'0 0 13 10\'><g fill=\'%23222\'><path d=\'m0 0h13v2h-13z\'/><path d=\'m0 4h13v2h-13z\'/><path d=\'m0 8h13v2h-13z\'/></g></svg>',
  652. 'minus': '<svg viewBox=\'0 0 20 20\'><path fill=\'%23222\' d=\'m1 8h18v4h-18z\'/></svg>',
  653. 'multiply': '<svg viewBox=\'0 0 20 20\' id=\'svg_multiply\'><path fill=\'%23222\' d=\'m10 7 6-6 3 3-6 6 6 6-3 3-6-6-6 6-3-3 6-6-6-6 3-3z\'/></svg>',
  654. 'music': '<svg width=\'100%\' height=\'100%\' viewBox=\'0 0 84 84\' version=\'1.1\' xmlns=\'http://www.w3.org/2000/svg\' xml:space=\'preserve\' style=\'fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;\'><path d=\'M66.613,58.258c-0,3.775 -1.721,6.934 -5.163,9.475c-3.154,2.309 -6.683,3.463 -10.588,3.463c-2.283,-0 -4.158,-0.538 -5.616,-1.617c-1.621,-1.229 -2.429,-2.95 -2.429,-5.158c-0,-3.492 1.658,-6.558 4.966,-9.204c3.134,-2.488 6.496,-3.734 10.088,-3.734c3.029,0 5.237,0.605 6.625,1.809l-0,-39.538l-28.146,7.584l-0,44.891c-0,3.775 -1.721,6.929 -5.158,9.471c-3.159,2.313 -6.688,3.467 -10.588,3.467c-2.287,-0 -4.158,-0.542 -5.625,-1.617c-1.617,-1.233 -2.425,-2.954 -2.425,-5.158c0,-3.492 1.658,-6.559 4.967,-9.204c3.133,-2.488 6.496,-3.734 10.087,-3.734c3.029,0 5.238,0.604 6.621,1.809l0,-48.355l32.383,-8.741l0.001,54.091Z\' style=\'fill:%23888;fill-opacity:0.4;fill-rule:nonzero;\'/></svg>',
  655. 'plus': '<svg viewBox=\'0 0 20 20\'><path fill=\'%23222\' d=\'m8.001 1h3.999v7h7v4h-7l-.001 7h-3.999v-7h-7v-4h7z\'/></svg>',
  656. 'prev_next_track': '<svg viewBox=\'0 0 20 20\'><path fill=\'%23222\' d=\'m13 5h2v10h-2zm-8 0 8 5-8 5z\'/></svg>',
  657. 'spinner': '<svg viewBox=\'0 0 100 100\' class=\'display_none invert\' preserveAspectRatio=\'xMidYMid\' width=\'32\' height=\'32\' xmlns=\'http://www.w3.org/2000/svg\' id=\'loading_spinner\'><animateTransform attributeName=\'transform\' type=\'rotate\' values=\'0;45\' keyTimes=\'0;1\' dur=\'0.25s\' repeatCount=\'indefinite\'/><path fill=\'%23000\' fill-opacity=\'.66\' d=\'m29.49-5.5h8v11h-8a30 30 0 0 1 -4.75 11.46l5.66 5.66-7.78 7.78-5.66-5.66a30 30 0 0 1 -11.46 4.75v8h-11v-8a30 30 0 0 1 -11.46-4.75l-5.66 5.66-7.78-7.78 5.66-5.66a30 30 0 0 1 -4.75-11.46h-8v-11h8a30 30 0 0 1 4.75-11.46l-5.66-5.66 7.78-7.78 5.66 5.66a30 30 0 0 1 11.46-4.75v-8h11v8a30 30 0 0 1 11.46 4.75l5.66-5.66 7.78 7.78-5.66 5.66a30 30 0 0 1 4.75 11.46m-29.49-14.5a20 20 0 1 0 0 40 20 20 0 1 0 0-40\' transform=\'matrix(.7189408 .69507131 -.69507131 .7189408 50 50)\'/></svg>',
  658. 'toggle': '<svg viewBox=\'0 0 20 20\'><g fill=\'%23222\'><path d=\'m10.207 9.293-.707.707 5.657 5.657 1.414-1.414-4.242-4.243 4.242-4.243-1.414-1.414z\'/><path d=\'m4.207 9.293-.707.707 5.657 5.657 1.414-1.414-4.242-4.243 4.242-4.243-1.414-1.414z\'/></g></svg>',
  659. 'ui_layout': '<svg width=\'100px\' height=\'100%\' viewBox=\'0 0 50 39\' version=\'1.1\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\' xml:space=\'preserve\' xmlns:serif=\'http://www.serif.com/\' style=\'fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;\'><rect x=\'0.5\' y=\'0.5\' width=\'14.5\' height=\'38\' style=\'fill:rgb(204,204,204);\'/><path d=\'M50,0L50,39L0,39L0,0L50,0ZM49,1L1,1L1,38L49,38L49,1Z\'/><path d=\'M15,0.5L15,38.5\' style=\'fill:none;stroke:black;stroke-width:1px;\'/><g transform=\'matrix(1,0,0,1,0,1.5)\'><path d=\'M0.5,5L15,5\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,15.0936,-0.5)\'><path d=\'M0,5L34.406,5\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g><g transform=\'matrix(1,0,0,1,0,1.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,1.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,3.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,5.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,7.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,9.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,11.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,13.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,15.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,17.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,19.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,21.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,23.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,25.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,27.5)\'><path d=\'M2.5,7L3,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><path d=\'M0.5,36.5L15,36.5\' style=\'fill:none;stroke:black;stroke-width:1px;\'/><g transform=\'matrix(1,0,0,1,0,1.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,3.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,5.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,7.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,9.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,11.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,13.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,15.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,17.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,19.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,21.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,23.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,25.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g><g transform=\'matrix(1,0,0,1,0,27.5)\'><path d=\'M5,7L13,7\' style=\'fill:none;stroke:black;stroke-width:1px;\'/></g></g><g class=\'invert\'><g transform=\'matrix(1.42857,0,0,1.42857,22.5,10.5)\'><path d=\'M0.369,9.141C0.117,8.463 0,7.745 0,7C0,3.137 3.137,0 7,0C10.863,0 14,3.137 14,7L13.863,8.353L10.01,4.5L6.51,8L4.01,5.5L0.369,9.141Z\' style=\'fill:rgb(128,128,255);fill-rule:nonzero;\'/></g><g transform=\'matrix(1.42857,0,0,1.42857,22.5,10.5)\'><path d=\'M0.839,10.151L0.369,9.141L4.01,5.5L6.51,8L10.01,4.5L13.863,8.353C13.787,8.748 13.662,9.131 13.522,9.5L3.151,12.845C2.858,12.651 2.572,12.429 2.313,12.194L0.839,10.151Z\' style=\'fill:white;fill-rule:nonzero;\'/></g><g transform=\'matrix(1.42857,0,0,1.42857,22.5,10.5)\'><path d=\'M13.522,9.5C12.532,12.14 9.983,14 7,14C5.574,14 4.247,13.579 3.151,12.845L10.01,5.979L13.522,9.5Z\' style=\'fill:rgb(51,51,204);fill-rule:nonzero;\'/></g><g transform=\'matrix(1.42857,0,0,1.42857,22.5,10.5)\'><path d=\'M0.839,10.151L4.01,6.979L5.771,8.74L2.312,12.194C1.721,11.562 1.233,10.881 0.839,10.151Z\' style=\'fill:rgb(51,51,204);fill-rule:nonzero;\'/></g><g transform=\'matrix(1.42857,0,0,1.42857,22.5,10.5)\'><circle cx=\'6\' cy=\'3.5\' r=\'1.5\' style=\'fill:white;\'/></g></g></svg>'
  660. };
  661.  
  662. function get_SVG_UI_Icon(icon_name) {
  663. return `url("data:image/svg+xml;utf8,${ SVG_UI_Icons[icon_name] }")`;
  664. }
  665. const SVG_UI_File_Icons = { // n.b.: order is important
  666. 'file_icon_dir': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m6 2.5-1-1.5h-5v12h14v-10.5z\' fill=\'%2339f\'/><path d=\'m1.5 4h11v7.5h-11z\' fill=\'%239cf\'/></svg>',
  667. 'file_icon_dir_open': '<svg viewBox=\'0 0 14 14\' clip-rule=\'evenodd\' fill-rule=\'evenodd\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m6.1 2.7-1.3-1.7h-4.8v12h14v-10.3z\' fill=\'%2339f\' fill-rule=\'nonzero\'/><path d=\'m7 6h5.5v5.5h-11z\' fill=\'%239cf\'/></svg>',
  668. 'file_icon_file': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m8.3 0h-6.8v14h11v-9.8l-4.2-4.2z\' fill=\'%23888\'/><g fill=\'%23fff\'><path d=\'m11 12.5h-8v-11h3.8v4.2h4.2z\'/><path d=\'m8.3 4.2h1.9l-1.9-2z\'/></g></svg>',
  669. 'file_icon_invisible': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m8.3 0h-6.8v14h11v-9.8l-4.2-4.2z\' fill=\'%23888\'/><path d=\'m11 12.5h-8v-11h3.8v4.2h4.2z\' fill=\'%23bbb\'/><path d=\'m8.3 4.2h1.9l-1.9-2z\' fill=\'%23bbb\'/><circle cx=\'7\' cy=\'9\' fill=\'%23878787\' r=\'1.5\'/></svg>',
  670. 'file_icon_ignored': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'M 10.695,1.774 1.856,10.613 3.482,12.239 12.321,3.4 Z M 7,2 c 2.8,0 5,2.2 5,5 0,2.8 -2.2,5 -5,5 C 4.2,12 2,9.8 2,7 2,4.2 4.2,2 7,2 M 7,0 C 3.1,0 0,3.1 0,7 c 0,3.9 3.1,7 7,7 3.9,0 7,-3.1 7,-7 C 14,3.1 10.9,0 7,0 Z\' style=\'fill:%23888888;fill-opacity:1\' /></svg>',
  671. 'file_icon_dirinvisible': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m6 2.5-1-1.5h-5v12h14v-10.5z\' fill=\'%23888\'/><path d=\'m1.5 4h11v7.5h-11z\' fill=\'%23bbb\'/><circle cx=\'7\' cy=\'7.5\' fill=\'%23888\' r=\'1.5\'/></svg>',
  672. 'file_icon_alias': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m0 0h14v14h-14z\' fill=\'%23808080\'/><path d=\'m3 12.5c0-3.863 2.253-7.5 6.259-7.5\' fill=\'none\' stroke=\'%23fc6\' stroke-width=\'3\'/><path d=\'m13 5-4-4v8z\' fill=\'%23fc6\'/></svg>',
  673. 'file_icon_archive': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m11 8.5v-1h2v2l-5 1h-2v1.5h4v1h-4v1h-3v-1h-2v-1h2v-1.5h-2v-2h2v-6.5h-2v-2h7l5 1v2h-2v-1h-5v6.5z\' fill=\'%23666\'/></svg>',
  674. 'file_icon_app': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m6.125 0-.292 1.859c-.587.135-1.146.38-1.64.693v-.018l-1.532-1.094-1.221 1.221 1.094 1.532h.018c-.313.495-.559 1.051-.693 1.64l-1.859.292v1.75l1.859.292c.134.589.38 1.145.693 1.64h-.018l-1.094 1.532 1.221 1.221 1.532-1.094v-.018c.494.313 1.053.558 1.64.693l.292 1.859h1.75l.292-1.859c.596-.137 1.14-.372 1.64-.693l1.532 1.112 1.221-1.221-1.112-1.532c.309-.492.523-1.057.656-1.64l1.896-.292v-1.75l-1.896-.292c-.133-.583-.347-1.148-.656-1.64h.018l1.094-1.532-1.221-1.221-1.532 1.094v.018c-.5-.321-1.044-.556-1.64-.693l-.292-1.859h-1.75zm.875 4.667c1.288 0 2.333 1.036 2.333 2.333s-1.045 2.333-2.333 2.333-2.333-1.036-2.333-2.333 1.045-2.333 2.333-2.333z\' fill=\'%237a7ab8\'/></svg>',
  675. 'file_icon_audio': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><circle cx=\'7\' cy=\'7\' fill=\'%230f8a8a\' r=\'7\'/><g fill=\'%23fff\'><path d=\'m11 9.5c-.019.681-.796 1.339-1.75 1.475-.966.138-1.75-.31-1.75-1s.784-1.362 1.75-1.5c.268-.038.523-.031.75.013v-4.488h-4v6.5c-.019.681-.796 1.339-1.75 1.475-.966.138-1.75-.31-1.75-1s.784-1.362 1.75-1.5c.268-.038.523-.031.75.013v-6.488l6-1z\'/><path d=\'m11 2-6 1v2l6-1z\'/></g></svg>',
  676. 'file_icon_code': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m14 0h-14v14h14z\' fill=\'%2372d\'/><g fill=\'%23fff\'><path d=\'m5.923 12.965c-1.049 0-1.784-.161-2.209-.48-.425-.317-.638-.82-.638-1.503v-2.067c0-.446-.146-.764-.438-.95-.292-.188-.709-.281-1.256-.281v-1.368c.547 0 .967-.094 1.259-.28s.438-.5.438-.938v-2.092c0-.675.217-1.172.65-1.491.432-.32 1.164-.479 2.195-.479v1.312c-.401.01-.718.09-.952.24-.233.15-.348.426-.348.827v1.985c0 .876-.511 1.396-1.532 1.559v.083c1.021.154 1.532.67 1.532 1.544v1.997c0 .41.116.688.349.835.233.146.55.223.951.232z\'/><path d=\'m8.076 12.965v-1.313c.392-.009.706-.089.944-.239.236-.15.355-.426.355-.829v-1.996c0-.867.511-1.382 1.531-1.545v-.084c-1.02-.164-1.53-.679-1.53-1.546v-1.997c0-.41-.116-.688-.349-.834-.232-.146-.549-.224-.951-.233v-1.313c1.049 0 1.785.159 2.21.479.423.319.637.821.637 1.505v2.065c0 .447.146.765.438.951.292.187.711.28 1.257.28v1.367c-.546.012-.967.107-1.259.287-.293.183-.438.5-.438.945v2.08c0 .674-.217 1.172-.65 1.491-.432.319-1.165.479-2.195.479z\'/></g></svg>',
  677. 'file_icon_database': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m14 2.5v9c0 1.38-3.137 2.5-7 2.5s-7-1.12-7-2.5v-9\' fill=\'%23808080\'/><path d=\'m13 2.5v9c0 .828-2.689 1.5-6 1.5s-6-.672-6-1.5v-9\' fill=\'%23b4b4b4\'/><path d=\'m14 8.5c0 1.38-3.137 2.5-7 2.5s-7-1.12-7-2.5\' fill=\'%23808080\'/><path d=\'m13 8.5c0 .828-2.689 1.5-6 1.5s-6-.672-6-1.5\' fill=\'%23b4b4b4\'/><path d=\'m14 5.5c0 1.38-3.137 2.5-7 2.5s-7-1.12-7-2.5\' fill=\'%23808080\'/><path d=\'m13 5.5c0 .828-2.689 1.5-6 1.5s-6-.672-6-1.5\' fill=\'%23b4b4b4\'/><ellipse cx=\'7\' cy=\'2.5\' fill=\'%23808080\' rx=\'7\' ry=\'2.5\'/><ellipse cx=\'7\' cy=\'2.5\' fill=\'%23b4b4b4\' rx=\'5.5\' ry=\'1.5\'/></svg>',
  678. 'file_icon_ebook': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m2.668-.001c1.705.001 3.492.35 4.332 1.257.84-.908 2.627-1.256 4.332-1.257h2.668v12.541c-.818 0-2.181.005-3 .023-1.184.026-3.008.42-3 1.437l-1-.017-1 .017c.008-1.017-2-1.437-3-1.437-.819 0-2.182-.023-3-.023v-12.541h2.668z\' fill=\'%23808080\'/><g fill=\'%23cdcdcd\'><path d=\'m1.5 1.499v9.501h1.286c1.086.025 2.213.081 3.204.568l.01.006c0-2.859 0-5.717 0-8.576 0-1.136-1.49-1.398-2.336-1.47-.708-.059-1.438-.029-2.164-.029z\'/><path d=\'m12.5 1.499v9.501h-1.286c-1.086.025-2.213.081-3.204.568l-.01.006c0-2.859 0-5.717 0-8.576 0-1.136 1.49-1.398 2.336-1.47.708-.059 1.438-.029 2.164-.029z\'/></g></svg>',
  679. 'file_icon_font': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m14 0h-14v14h14z\' fill=\'%23709\'/><path d=\'m4.678 11.179h1.393v-8.266h-2.616v1.052h-1.455v-2.553h10v2.554h-1.456v-1.053h-2.599v8.266h1.347v1.409h-4.614z\' fill=\'%23fff\'/></svg>',
  680. 'file_icon_graphics': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m0 0h14v14h-14z\' fill=\'%23808080\'/><path d=\'m7.774 8.285 4.726 4.715-8-3.525-1.5-4.975h-2v-3.5h3.525l-.025 2 5 1.5 3.5 8-4.7-4.752c.127-.22.2-.476.2-.748 0-.828-.672-1.5-1.5-1.5s-1.5.672-1.5 1.5.672 1.5 1.5 1.5c.283 0 .548-.079.774-.215z\' fill=\'%23ccc\'/></svg>',
  681. 'file_icon_htm': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m6.967.5c-3.553.018-6.467 2.947-6.467 6.5 0 3.566 2.934 6.5 6.5 6.5s6.5-2.934 6.5-6.5c0-3.553-2.914-6.482-6.467-6.5zm.033 0v13m6.5-6.5h-13m1.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.366 0 2.453 1.083 4.785 2.957 6.367m1 0c1.874-1.582 2.957-3.914 2.957-6.367 0-2.452-1.083-4.784-2.957-6.366\' fill=\'%23fff\' stroke=\'%23e44d26\'/></svg>',
  682. 'file_icon_ignoredimage': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m.369 9.141c-.252-.678-.369-1.396-.369-2.141 0-3.863 3.137-7 7-7s7 3.137 7 7l-.137 1.353-3.853-3.853-3.5 3.5-2.5-2.5z\' fill=\'%23808080\'/><path d=\'m.839 10.151-.47-1.01 3.641-3.641 2.5 2.5 3.5-3.5 3.853 3.853c-.076.395-.201.778-.341 1.147l-10.371 3.345c-.293-.194-.579-.416-.838-.651z\' fill=\'%23fff\'/><path d=\'m13.522 9.5c-.99 2.64-3.539 4.5-6.522 4.5-1.426 0-2.753-.421-3.849-1.155l6.859-6.866z\' fill=\'%23808080\'/><path d=\'m.839 10.151 3.171-3.172 1.761 1.761-3.459 3.454c-.591-.632-1.079-1.313-1.473-2.043z\' fill=\'%23808080\'/><circle cx=\'6\' cy=\'3.5\' fill=\'%23fff\' r=\'1.5\'/></svg>',
  683. 'file_icon_image': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m.369 9.141c-.252-.678-.369-1.396-.369-2.141 0-3.863 3.137-7 7-7s7 3.137 7 7l-.137 1.353-3.853-3.853-3.5 3.5-2.5-2.5z\' fill=\'%238080ff\'/><path d=\'m.839 10.151-.47-1.01 3.641-3.641 2.5 2.5 3.5-3.5 3.853 3.853c-.076.395-.201.778-.341 1.147l-10.371 3.345c-.293-.194-.579-.416-.838-.651z\' fill=\'%23fff\'/><path d=\'m13.522 9.5c-.99 2.64-3.539 4.5-6.522 4.5-1.426 0-2.753-.421-3.849-1.155l6.859-6.866z\' fill=\'%2333c\'/><path d=\'m.839 10.151 3.171-3.172 1.761 1.761-3.459 3.454c-.591-.632-1.079-1.313-1.473-2.043z\' fill=\'%2333c\'/><circle cx=\'6\' cy=\'3.5\' fill=\'%23fff\' r=\'1.5\'/></svg>',
  684. 'file_icon_markdown': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m14 0h-14v14h14z\' fill=\'%236a6a95\'/><path d=\'m12 11.5h-2.5v-5.143l-2.5 2.948-2.5-2.948v5.143h-2.5v-9h2.273l2.721 3.377 2.733-3.377h2.273z\' fill=\'%23ddd\'/></svg>',
  685. 'file_icon_office': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m0 0h14v14h-14z\' fill=\'%23808080\'/><g fill=\'%23cdcdcd\'><path d=\'m10 1.5h2.5v1h-2.5z\'/><path d=\'m10 4h2.5v1h-2.5z\'/><path d=\'m10 6.5h2.5v1h-2.5z\'/><path d=\'m10 9h2.5v1h-2.5z\'/><path d=\'m10 11.5h2.5v1h-2.5z\'/><path d=\'m6.5 1.5h2.5v1h-2.5z\'/><path d=\'m6.5 4h2.5v1h-2.5z\'/><path d=\'m6.5 6.5h2.5v1h-2.5z\'/><path d=\'m6.5 9h2.5v1h-2.5z\'/><path d=\'m6.5 11.5h2.5v1h-2.5z\'/><path d=\'m1.5 1.5h4v11h-4z\'/></g></svg>',
  686. 'file_icon_pdf': '<svg clip-rule=\'evenodd\' fill-rule=\'evenodd\' viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m0 0h13.999986v13.999986h-13.999986z\' fill=\'%23e0382d\' stroke-width=\'.259259\'/><path d=\'m45 31.2c-2.6-2.7-9.7-1.6-11.4-1.4-2.5-2.4-4.2-5.3-4.8-6.3.9-2.7 1.5-5.4 1.6-8.3 0-2.5-1-5.2-3.8-5.2-1 0-1.9.6-2.4 1.4-1.2 2.1-.7 6.3 1.2 10.6-1.1 3.1-2.1 6.1-4.9 11.4-2.9 1.2-9 4-9.5 7-.2.9.1 1.8.8 2.5.7.6 1.6.9 2.5.9 3.7 0 7.3-5.1 9.8-9.4 2.1-.7 5.4-1.7 8.7-2.3 3.9 3.4 7.3 3.9 9.1 3.9 2.4 0 3.3-1 3.6-1.9.5-1 .2-2.1-.5-2.9zm-2.5 1.7c-.1.7-1 1.4-2.6 1-1.9-.5-3.6-1.4-5.1-2.6 1.3-.2 4.2-.5 6.3-.1.8.2 1.6.7 1.4 1.7zm-16.7-20.6c.2-.3.5-.5.8-.5.9 0 1.1 1.1 1.1 2-.1 2.1-.5 4.2-1.2 6.2-1.5-4-1.2-6.8-.7-7.7zm-.2 19.4c.8-1.6 1.9-4.4 2.3-5.6.9 1.5 2.4 3.3 3.2 4.1 0 .1-3.1.7-5.5 1.5zm-5.9 4c-2.3 3.8-4.7 6.2-6 6.2-.2 0-.4-.1-.6-.2-.3-.2-.4-.5-.3-.9.3-1.4 2.9-3.3 6.9-5.1z\' fill=\'%23fff\' fill-rule=\'nonzero\' transform=\'matrix(.344737 0 0 .35503 -2.77114 -2.5503)\'/></svg>',
  687. 'file_icon_playlist': '<svg viewBox=\'0 0 14 14\' clip-rule=\'evenodd\' fill-rule=\'evenodd\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m0 0h14v14h-14z\' fill=\'%23888\' fill-rule=\'nonzero\'/><path d=\'m1.5 1.5h8v1h-8zm0 2.5h8v1h-8zm0 2.5h8v1h-8zm0 2.5h7v1h-7zm0 2.5h5.5v1h-5.5zm9.5-10h1v10c-.019.681-.796 1.339-1.75 1.475-.966.138-1.75-.31-1.75-1s.784-1.362 1.75-1.5a2.28 2.28 0 0 1 .75.013z\' fill=\'%23fff\'/></svg>',
  688. 'file_icon_text': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m14 0h-14v14h14z\' fill=\'%236a6a95\'/><g fill=\'%23fff\'><path d=\'m6.5 1.5h6v1h-6z\'/><path d=\'m1.5 1.5h3.5v3.5h-3.5z\'/><path d=\'m1.5 6.5h11v1h-11z\'/><path d=\'m6.5 4h6v1h-6z\'/><path d=\'m1.5 11.5h8v1h-8z\'/><path d=\'m1.5 9h11v1h-11z\'/></g></svg>',
  689. 'file_icon_video': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m14 14v-14h-14v14z\'/><g fill=\'%23fff\'><path d=\'m9.5 3v-2h-2v2z\'/><path d=\'m3.5 3v-2h-2v2z\'/><path d=\'m6.5 3v-2h-2v2z\'/><path d=\'m12.5 3v-2h-2v2z\'/><path d=\'m9.5 13v-2h-2v2z\'/><path d=\'m3.5 13v-2h-2v2z\'/><path d=\'m6.5 13v-2h-2v2z\'/><path d=\'m12.5 13v-2h-2v2z\'/></g><path d=\'m12.5 10v-6h-11v6z\' fill=\'%23eda412\'/></svg>',
  690. 'file_icon_bin': '',
  691. 'file_icon_other': '', // <-- these two use file_icon_system:
  692. 'file_icon_system': '<svg viewBox=\'0 0 14 14\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m0 0h14v14h-14z\' fill=\'%23808080\'/><g fill=\'%23ccc\'><path d=\'m1.247 6.495h3.263v-1.067h-.881v-3.835h-.974c-.371.232-.727.371-1.284.479v.82h.928v2.536h-1.052z\'/><path d=\'m7 6.588c1.082 0 1.825-.89 1.825-2.567 0-1.67-.743-2.521-1.825-2.521s-1.825.843-1.825 2.521c0 1.677.743 2.567 1.825 2.567zm0-1.021c-.309 0-.572-.247-.572-1.546s.263-1.5.572-1.5.572.201.572 1.5-.263 1.546-.572 1.546z\'/><path d=\'m9.598 6.495h3.263v-1.067h-.882v-3.835h-.974c-.371.232-.727.371-1.283.479v.82h.927v2.536h-1.051z\'/><path d=\'m2.825 12.588c1.082 0 1.824-.89 1.824-2.567 0-1.67-.742-2.521-1.824-2.521-1.083 0-1.825.843-1.825 2.521 0 1.677.742 2.567 1.825 2.567zm0-1.021c-.31 0-.572-.247-.572-1.546s.262-1.5.572-1.5c.309 0 .572.201.572 1.5s-.263 1.546-.572 1.546z\'/><path d=\'m5.423 12.495h3.263v-1.067h-.882v-3.835h-.974c-.371.232-.727.371-1.284.479v.82h.928v2.536h-1.051z\'/><path d=\'m11.175 12.588c1.083 0 1.825-.89 1.825-2.567 0-1.67-.742-2.521-1.825-2.521-1.082 0-1.824.843-1.824 2.521 0 1.677.742 2.567 1.824 2.567zm0-1.021c-.309 0-.572-.247-.572-1.546s.263-1.5.572-1.5c.31 0 .572.201.572 1.5s-.262 1.546-.572 1.546z\'/></g></svg>'
  693. };
  694. const SVG_Text_Editing_UI_Icons = {
  695. 'toggle_theme': '<svg viewBox=\'0 0 16 16\' clip-rule=\'evenodd\' fill-rule=\'evenodd\' xmlns=\'http://www.w3.org/2000/svg\'><path d=\'m8 0c4.415 0 8 3.585 8 8s-3.585 8-8 8-8-3.585-8-8 3.585-8 8-8zm0 2c3.311 0 6 2.689 6 6s-2.689 6-6 6z\' fill=\'%23333\'/></svg>',
  696. 'show_markdown': '<svg viewBox=\'0 0 100 60\' xmlns=\'http://www.w3.org/2000/svg\' width=\'100\'><g fill=\'%23333\'><path d=\'M42.215 60l.17-46.24h-.255L30.06 60h-7.99L10.255 13.76H10L10.169 60H.905V-.18H14.59l11.56 44.03h.34L37.794-.18H52.16V60h-9.945zM99.589 29.996c0 9.519-1.997 16.901-5.992 22.142C89.602 57.38 83.722 60 75.959 60H60.914V-.18h15.13c7.706 0 13.558 2.65 17.553 7.948 3.995 5.299 5.992 12.708 5.992 22.228zm-10.2 0c0-3.57-.326-6.686-.978-9.35-.651-2.663-1.572-4.873-2.762-6.63-1.19-1.756-2.607-3.073-4.25-3.953-1.645-.878-3.43-1.317-5.355-1.317h-4.845v42.33h4.845c1.926 0 3.711-.438 5.355-1.317 1.643-.878 3.06-2.195 4.25-3.953 1.189-1.756 2.11-3.952 2.762-6.587.651-2.637.978-5.709.978-9.223z\'/></g></svg>',
  697. 'show_source': '<svg viewBox=\'0 0 22 14\' xmlns=\'http://www.w3.org/2000/svg\' fill-rule=\'evenodd\' clip-rule=\'evenodd\'><path fill=\'none\' d=\'M0 0h21.996v14H0z\'/><clipPath id=\'a\'><path d=\'M0 0h21.996v14H0z\'/></clipPath><g clip-path=\'url(%23a)\' fill=\'%23333\'><path d=\'M0 7.393v-.786l6.062-3.5.75 1.3L2.32 7l4.492 2.593-.75 1.3L0 7.393zM21.996 6.607v.786l-6.062 3.5-.75-1.3L19.676 7l-4.492-2.593.75-1.3 6.062 3.5zM15.15 1.313l-1.3-.75-7 12.124 1.3.75 7-12.124z\'/></g></svg>',
  698. 'show_preview': '<svg viewBox=\'0 0 16 16\' xmlns=\'http://www.w3.org/2000/svg\' fill-rule=\'evenodd\' clip-rule=\'evenodd\'><path d=\'M10 2.5V1H0v1.5h4V15h2V2.5h4zM9 6.5V8h2v4.053c0 2.211 1.547 3.442 3 3.442.989 0 1.556-.258 2-.495v-1.5c-.565.257-.882.376-1.507.376-.847 0-1.493-.474-1.493-1.876V8h2.5V6.5H13v-3h-1.98v3H9z\' fill=\'%23333\' fill-rule=\'nonzero\'/></svg>',
  699. 'show_html': '<svg viewBox=\'0 0 22 16\' xmlns=\'http://www.w3.org/2000/svg\' fill-rule=\'evenodd\' clip-rule=\'evenodd\'><path fill=\'none\' d=\'M0 0h21.022v16H0z\'/><clipPath id=\'a\'><path d=\'M0 0h21.022v16H0z\'/></clipPath><g clip-path=\'url(%23a)\' fill=\'%23333\'><path d=\'M7.732.222L9.5 1.99 3.49 8l6.01 6.01-1.768 1.768L-.046 8 7.732.222zM13.268 15.778L11.5 14.01 17.51 8 11.5 1.99 13.268.222 21.046 8l-7.778 7.778z\'/></g></svg>',
  700. 'toggle_split': '<svg viewBox=\'0 0 16 16\' xmlns=\'http://www.w3.org/2000/svg\' fill-rule=\'evenodd\' clip-rule=\'evenodd\'><path d=\'M0 0v16h16V0H0zm14 14H9V2h5v12zm-7 0H2V2h5v12z\' fill=\'%23333\' fill-rule=\'nonzero\'/></svg>',
  701. 'save_btn': '<svg viewBox=\'0 0 16 16\' xmlns=\'http://www.w3.org/2000/svg\' fill-rule=\'evenodd\' clip-rule=\'evenodd\'><g fill=\'currentColor\'><path d=\'M16 0v10.02L14 10V2H2v8l-2 .02V0h16z\' fill-rule=\'nonzero\'/><path d=\'M7 5h2v9H7z\'/><path d=\'M3.757 11.757l1.415-1.414L8 13.172l2.828-2.829 1.415 1.414L8 16l-4.243-4.243z\'/></g></svg>',
  702. 'save_btn_edited': '<svg viewBox=\'0 0 16 16\' xmlns=\'http://www.w3.org/2000/svg\' fill-rule=\'evenodd\' clip-rule=\'evenodd\'><g fill=\'%23DD2222\'><path d=\'M16 0v10.02L14 10V2H2v8l-2 .02V0h16z\' fill-rule=\'nonzero\'/><path d=\'M7 5h2v9H7z\'/><path d=\'M3.757 11.757l1.415-1.414L8 13.172l2.828-2.829 1.415 1.414L8 16l-4.243-4.243z\'/></g></svg>'
  703. };
  704. // ===> GET SVG UI ICON by name
  705. function get_SVG_UI_File_Icon(icon_name) { // ===> GET SVG UI FILE Icon by name
  706. switch (icon_name) {
  707. case 'favicon':
  708. return '<link href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACAAgMAAAC+UIlYAAAACVBMVEUmRcmZzP8zmf8pVcWPAAAAAXRSTlMAQObYZgAAAFBJREFUeF7tyqERwDAMBEE3mX5UiqDmqwwziTPHjG7xrmzrLFtRaApDIRiKQlMYCsFQFJrCUAiGotAU5hTA1WB4fhkMBsOJwWAwgHvB8CHpBcTbpxy4RZNvAAAAAElFTkSuQmCC" rel="icon" sizes="16x16" />';
  709. case 'file_icon_dir_default':
  710. 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= ")';
  711. case 'file_icon_file_default':
  712. return 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAABnRSTlMAAAAAAABupgeRAAABHUlEQVR42o2RMW7DIBiF3498iHRJD5JKHurL+CRVBp+i2T16tTynF2gO0KSb5ZrBBl4HHDBuK/WXACH4eO9/CAAAbdvijzLGNE1TVZXfZuHg6XCAQESAZXbOKaXO57eiKG6ft9PrKQIkCQqFoIiQFBGlFIB5nvM8t9aOX2Nd18oDzjnPgCDpn/BH4zh2XZdlWVmWiUK4IgCBoFMUz9eP6zRN75cLgEQhcmTQIbl72O0f9865qLAAsURAAgKBJKEtgLXWvyjLuFsThCSstb8rBCaAQhDYWgIZ7myM+TUBjDHrHlZcbMYYk34cN0YSLcgS+wL0fe9TXDMbY33fR2AYBvyQ8L0Gk8MwREBrTfKe4TpTzwhArXWi8HI84h/1DfwI5mhxJamFAAAAAElFTkSuQmCC ")';
  713. default:
  714. return 'url("data:image/svg+xml;utf8,' + SVG_UI_File_Icons[icon_name] + '")';
  715. }
  716. }
  717.  
  718. function CSS_UI_Icon_Rules() { // programatically add File icon CSS rules // ===> CSS UI ICON RULES
  719. let rules = '',
  720. kind, class_name;
  721. for (let icon in SVG_UI_File_Icons) {
  722. kind = icon.slice(icon.lastIndexOf('_') + 1);
  723. class_name = kind;
  724. if (class_name !== ('file')) { // exceptions:
  725. if (kind === 'dirinvisible') {
  726. class_name = 'dir.invisible';
  727. }
  728. if (kind === 'ignoredimage') {
  729. class_name = 'ignored_image';
  730. }
  731. if (kind === 'open') {
  732. class_name = 'has_subdirectory';
  733. kind = 'dir_open';
  734. }
  735. if (/alias|symlink/.test(kind)) {
  736. class_name = 'link';
  737. }
  738. if (/bin|other/.test(kind)) {
  739. kind = 'system';
  740. }
  741. rules += `body:not(.use_custom_icons_false) .${ class_name } .has_icon_before_before, #content_pane[data-content^="has_${ class_name }"] #content_title span::before,body:not(.use_custom_icons_false) .${ class_name }.has_icon_before::before, .${ class_name } .has_icon_before::before { background-image: url("data:image/svg+xml;utf8,${ SVG_UI_File_Icons['file_icon_'+kind] }"); }`; // add custom file icons
  742. }
  743. }
  744. return rules;
  745. }
  746. // END SVG UI ICONS
  747. //==============================// UI HTML
  748. // SIDEBAR ELEMENTS
  749. const Directory_Header_Menu_Elements = `
  750. <li id="go_to_item" class="no_checkmark border_bottom" title="Go to item..."><span class="menu_item">Go to item&hellip; (&#8984;&#8679;J)</span><input id="go_to_item_input" class="display_none resize_none whitespace_pre" rows="1" placeholder="Item row number" spellcheck="false" /></li>
  751. <li id="menu_sort_by" class="has_submenu border_bottom error_display_none"><span class="menu_item">Sort by&hellip;</span>${SVG_UI_Icons.arrow}
  752. <ul id="sort_menu" class="submenu box_shadow_menu background_grey_80 border_all"> <li id="menu_sort_by_name" class="is_submenu_item toggle_UI_pref sorting" data-ui_pref="sort_by_name"><span class="menu_item">Name</span></li> <li id="menu_sort_by_duration" class="is_submenu_item toggle_UI_pref sorting" data-ui_pref="sort_by_duration"><span class="menu_item">Duration</span></li> <li id="menu_sort_by_size" class="is_submenu_item toggle_UI_pref sorting" data-ui_pref="sort_by_size"><span class="menu_item">Size</span></li> <li id="menu_sort_by_date" class="is_submenu_item toggle_UI_pref sorting" data-ui_pref="sort_by_date"><span class="menu_item">Date</span></li> <li id="menu_sort_by_kind" class="is_submenu_item toggle_UI_pref sorting" data-ui_pref="sort_by_kind"><span class="menu_item">Kind</span></li> <li id="menu_sort_by_ext" class="is_submenu_item toggle_UI_pref sorting" data-ui_pref="sort_by_ext"><span class="menu_item">Extension</span></li> <li id="menu_sort_by_default" class="is_submenu_item toggle_UI_pref sorting" data-ui_pref="sort_by_default"><span class="menu_item">Default</span></li> </ul></li>
  753. <li id="UI_settings" class="has_submenu"><span class="menu_item">UI Preferences</span>${SVG_UI_Icons.arrow}
  754. <ul id="UI_settings_submenu" class="submenu box_shadow_menu background_grey_80 border_all">
  755. <li id="menu_theme_container" class="is_submenu_item" title="Set the main UI theme (light or dark)."><span id="menu_theme" class="toggle_UI_pref menu_item checkmark ignore_warning" data-ui_pref="theme"><span> Theme</span></span></li>
  756. <li id="alternate_background" class="is_submenu_item toggle_UI_pref ignore_warning" data-ui_pref="alternate_background" title="Alternate backgrounds of directory items."><span class="menu_item checkmark">Alternate Backgrounds</span></li>
  757. <li id="show_numbers" class="is_submenu_item toggle_UI_pref ignore_warning border_bottom error_display_none" data-ui_pref="show_numbers" title="Number directory list items."><span class="menu_item checkmark">Show Numbers</span></li>
  758. <li id="use_custom_icons" class="is_submenu_item toggle_UI_pref ignore_warning" data-ui_pref="use_custom_icons" title="Use custom or browser/server default file and dir icons"><span class="menu_item checkmark">Use Custom Icons</span></li>
  759. <li id="show_image_thumbnails" class="is_submenu_item toggle_UI_pref ignore_warning" data-ui_pref="show_image_thumbnails" title="Show image thumbnails in directory list items."><span class="menu_item checkmark">Show Image Thumbnails</span></li>
  760. <li id="show_large_image_thumbnails" class="is_submenu_item toggle_UI_pref ignore_warning" data-ui_pref="show_large_image_thumbnails" title="Use large image thumbnails."><span class="menu_item checkmark">Use Large Image Thumbnails</span></li>
  761. <li id="show_image_thumbnails_always" class="is_submenu_item toggle_UI_pref ignore_warning border_bottom" data-ui_pref="show_image_thumbnails_always" title="Always show image thumbnails no matter how many images are in directory."><span class="menu_item checkmark">Always Show Image Thumbnails</span></li>
  762. <li id="ui_font" class="is_submenu_item ignore_warning no_checkmark" data-ui_pref="ui_font" title="Enter the name of an installed font."><span class="menu_item">Set UI Font&hellip;</span><input id="ui_font_input" class="display_none resize_none whitespace_pre" rows="1" placeholder="CSS Font Family" spellcheck="false" /></li>
  763. <li id="ui_scale" class="is_submenu_item ignore_warning display_flex flex_column no_checkmark" data-ui_pref="ui_scale" title="Scale the UI. Double-click to reset."><span class="menu_item">Scale UI&hellip;</span><span id="ui_scale_input_container" class="flex_justify_center_row padding_4_6"><input id="ui_scale_input" class="width_100 whitespace_pre display_block resize_none" type="range" min="75" max="125" step="1" placeholder="Scale UI"></span></li>
  764. </ul></li>
  765. <li id="file_handling" class="has_submenu error_display_none"><span class="menu_item">File Handling Preferences</span>${SVG_UI_Icons.arrow}
  766. <ul id="file_handling_submenu" class="submenu box_shadow_menu background_grey_80 border_all">
  767. <li id="show_invisible_items" class="is_submenu_item toggle_UI_pref" data-ui_pref="show_invisibles" title="Show/hide invisible items"><span class="menu_item checkmark">Show Invisible Items (&#8984;&#8679;I)</span></li>
  768. <li id="show_ignored_items" class="is_submenu_item toggle_UI_pref" data-ui_pref="show_ignored_items" title="Show/hide ignored items (from the list of ignored file types in the user settings)."><span class="menu_item checkmark">Show Ignored Items</span></li>
  769. <li id="ignore_ignored_items" class="is_submenu_item toggle_UI_pref border_bottom" data-ui_pref="ignore_ignored_items" title="If checked, the browser will not attempt to load ignored items (from the list of ignored file types in the user settings). It is recommended to leave this checked."><span class="menu_item checkmark">Ignore Ignored Items</span></li>
  770. <li id="autoload_index_files" class="is_submenu_item toggle_UI_pref" data-ui_pref="autoload_index_files" title="Automatically load html index file."><span id="autoload_index_files_menu" class="menu_item checkmark">Autoload Index Files</span></li>
  771. </ul></li>
  772. <li id="media_settings" class="has_submenu error_display_none"><span class="menu_item">Media Preferences</span>${SVG_UI_Icons.arrow}
  773. <ul id="UI_settings_submenu" class="submenu box_shadow_menu background_grey_80 border_all">
  774. <li id="media_autoload" class="is_submenu_item toggle_UI_pref" data-ui_pref="media_autoload" title="Automatically select and load the first media item in a directory and cover art (if any)."><span id="media_autoload_menu" class="menu_item checkmark">Autoload Media</span></li>
  775. <li id="media_autoplay" class="is_submenu_item toggle_UI_pref" data-ui_pref="media_autoplay" title="Automatically play the next media item."><span id="media_autoload_menu" class="menu_item checkmark">Autoplay Media</span></li>
  776. <li id="media_play_all" class="is_submenu_item toggle_UI_pref border_bottom" data-ui_pref="media_play_all" title="If checked, autoplay all media types (i.e., audio and video), else just autoplay the currently selected/playing media type."><span class="menu_item checkmark">Play All Media Files</span></li>
  777. <li id="loop_media_files" class="is_submenu_item" title="If checked, loop media playback."><span id="loop_media_menu" class="menu_item">Loop Media Playback</span></li>
  778. <li id="shuffle_media_files" class="is_submenu_item border_bottom" title="If checked, shuffle media playback."><span id="shuffle_media_menu" class="menu_item">Shuffle Media Playback</span></li>
  779. <li id="refresh_media_durations" class="is_submenu_item border_bottom" title=""><span id="refresh_media_durations_menu" class="menu_item">Refresh Media Durations</span></li>
  780. </ul></li>
  781. <li id="text_editing" class="has_submenu error_display_none"><span class="menu_item">Text Editing Preferences</span>${SVG_UI_Icons.arrow} <ul id="text_editing_menu" class="submenu box_shadow_menu background_grey_80 border_all"> <li id="toggle_text_editing" class="error_display_none" title="Enable/disable editing of text files. Does not effect main text editor."><span id="text_editing_enable" class="toggle_UI_pref menu_item checkmark" data-ui_pref="text_editing_enable"><span id="disable">Text File Editing </span></span></li> <li id="texteditor_menu_item" class="is_submenu_item border_bottom" title="Toggle the main text editor."><span id="texteditor" class="menu_item">Toggle Text Editor </span></li>
  782. <li id="texteditor_split_view" class="is_submenu_item toggle_UI_pref border_bottom" data-ui_pref="texteditor_split_view" title="Toggle display of default text view and both source and rendered text."><span class="menu_item checkmark">Split View</span></li>
  783. <li id="toggle_texteditor_raw_menu" class="is_submenu_item toggle_UI_pref" data-ui_pref="texteditor_view_raw"><span id="toggle_texteditor_raw" class="menu_item">View Source Text</span></li>
  784. <li id="toggle_texteditor_preview_menu" class="is_submenu_item toggle_UI_pref" data-ui_pref="texteditor_view_preview"><span id="toggle_texteditor_preview" class="menu_item">View Styled Text</span></li>
  785. <li id="toggle_texteditor_html_menu" class="is_submenu_item toggle_UI_pref" data-ui_pref="texteditor_view_html"><span id="toggle_texteditor_html" class="menu_item">View Rendered HTML</span></li></ul>
  786.  
  787. <li id="default_settings" class="border_bottom"><span class="menu_item" href="#" title="Delete custom UI preferences stored in the URL query string and reload page.">Default Preferences</span></li>
  788. <li id="playlist_options" class="has_submenu border_bottom error_display_none"><span class="menu_item">Playlists</span>${SVG_UI_Icons.arrow} <ul id="playlist_menu" class="submenu box_shadow_menu background_grey_80 border_all"> <li id="open_playlist_container" class="is_submenu_item"><label id="open_playlist_label" class="menu_item" for="open_playlist" title="Open local .m3u playlist/filelist file.">Open Playlist/Filelist File&hellip;</label><input type="file" id="open_playlist" name="open_playlist" accept=".m3u,.m3u8"></li> <li id="close_playlist_container" class="is_submenu_item display_none"><span id="close_playlist" class="menu_item" href="#">Close Playlist/Filelist</span></li> <li class="is_submenu_item"><span id="make_playlist" class="menu_item border_top error_display_none" href="#" title="Make an .m3u playlist/filelist of the items in the current directory (if any).">Make Playlist/Filelist&hellip;</span></li> </ul></li>
  789. <li id="open_font_file" class="border_bottom error_display_none"><label id="open_font_label" class="menu_item" for="open_font" title="Open font file (.oft, .ttf, .woff) to view glyph repertoire and font info; save individual glyphs as .svg.">Open Font File&hellip;</label><input type="file" id="open_font" name="open_font" accept=".otf,.ttf,.woff"></li>
  790. <li id="about" class="" title="Go to script home page."><a id="about_link" class="menu_item flex_grow_1 ignore_warning" href="https://openuserjs.org/scripts/gaspar_schot/Supercharged_Local_Directory_File_Browser" target="_blank"><span class="icon_container"></span>Script Home &#8599;</a></li>
  791. <li id="show_help" class="" title="Show help."><span class="menu_item flex_grow_1"><span class="icon_container"></span>Help</span></li>
  792. <li id="donate" class="" title="Buy me a coffee!"><a id="donate_link" class="menu_item flex_grow_1 ignore_warning" href="https://www.buymeacoffee.com/fiLtliTFxQ" target="_blank" rel="noopener"><span class="icon_container"></span>Buy me a Coffee <svg xmlns="http://www.w3.org/2000/svg" width="14px" viewBox="0 0 64 64" enable-background="new 0 0 64 64"><path d="m32 2c-16.568 0-30 13.432-30 30 0 16.568 13.432 30 30 30s30-13.432 30-30c0-16.568-13.432-30-30-30m0 48c-1.371-1.814-20.53-12.883-16.602-25.218 3.53-11.073 15.094-6.597 16.602-.594 1.094-5.635 12.949-10.694 16.604.584 3.925 12.136-15.237 23.785-16.604 25.228" fill="#757575"/></svg></a></li>
  793. <li id="contact" class="" title="Send me an email."><a id="contact_link" class="menu_item flex_grow_1 ignore_warning" href="mailto:mshroud@protonmail.com"><span class="icon_container"></span>Contact</a></li>
  794. `;
  795. const Directory_Header_Elements = function (body_id, parent_link) {
  796. let checked = '',
  797. parent_links = createParentLinkItems(),
  798. dir_header_title_element = '',
  799. dir_header_menus = '',
  800. texteditor_element = '';
  801. if (getCurrentUIPref('show_invisibles') === 'true') {
  802. checked = 'checked="true"';
  803. }
  804. switch (body_id) {
  805. case 'top_body':
  806. dir_header_title_element = `<div id="dir_header_title" class="display_flex flex_row border_bottom background_grey_75 normal"><div class="dir_header_title_div center padding_4_6"></div></div>`;
  807. dir_header_menus = `<div id="dir_menus" class="display_flex flex_row background_grey_75 border_bottom pointer">
  808. <div id="dir_menu_parent" class="menu_container flex_justify_center width_24px padding_0"> <nav id="parent_dir_nav" class="flex_justify_center invert"><a href="${ parent_links[1] }" title="Parent Directory (&#8984;&uarr;)" class="flex_justify_center"><div class="display_flex">${ SVG_UI_Icons.chevron }${ SVG_UI_Icons.multiply }</div></a></nav> </div>
  809. <div id="dir_menu_parents" class="menu_container padding_0 flex_grow_1"> <nav id="parents_dir_nav" class="display_flex border_right line_height_1_4 border_left"> <div id="current_dir_path" class="bold flex_justify_center hyphens_none pointer z_index_9998" title="Parent Directories"><span class="has_icon_before">${ current_dir_path }</span></div> </nav> <ul id="parents_links" class="menu background_grey_85 position_absolute position_LR_0 border_top border_bottom margin_0 padding_0 display_none box_shadow_menu z_index_9998">${ parent_links[0] }</ul> </div>
  810. <div id="dir_menu_main_container" class="menu_container width_24px flex_justify_center margin_0 padding_0"> <nav id="dir_menu_main_container_nav" class="invert pointer width_14px_contents" title="Show main menu (&#8984;E); navigate by arrow keys or typed string."><div class="display_flex">${ SVG_UI_Icons.menu }</div></nav> <ul id="dir_menu_main" class="menu position_absolute background_grey_80 border_top border_bottom margin_0 padding_0 display_none box_shadow_menu position_LR_0 z_index_9998"> ${ Directory_Header_Menu_Elements } </ul> </div>
  811. </div>`;
  812. texteditor_element = `<ul id="show_texteditor" class="bold border_bottom display_none"><li class="padding_4_6 width_100 background_grey_80" title="Toggle Text Editor (&#8984;&#8679;E)"><span>Text Editor</span></li></ul>`;
  813. break;
  814. case 'iframe':
  815. dir_header_menus = `<ul id="change_dirs" class="flex_justify_center_row flex_justify_contents border_bottom background_grey_75"> <li id="parent" class="flex_grow_1 no_highlight"><a href="${ parent_link }" id="iframe_parent_link" class="display_inline_flex" title="Go to parent directory"><span class="width_14px_contents invert">${ SVG_UI_Icons.chevron }</span>Parent Directory</a></li> <li id="open_in_sidebar" class="align_right flex_grow_1 no_highlight"><a href="#" title="Open this directory in sidebar">Open in Sidebar<span class="width_14px_contents invert transform_rotate_270_contents">${ SVG_UI_Icons.chevron }</span></a></li> </ul>`;
  816. break;
  817. }
  818. return `<header id="dir_header" class="display_flex flex_column text_color_default font_size_small z_index_3">
  819. ${ dir_header_title_element }
  820. <div id="dir_header_utilities" class="display_flex flex_column">
  821. ${ dir_header_menus }
  822. <ul id="dir_header_utilities_row_1" class="display_flex flex_row position_relative background_grey_80 border_bottom">
  823. <li id="directory_buttons_left" class="display_flex no_highlight"> <button id="show_details" class="toggle_UI_pref pointer" data-ui_pref="show_details" tabindex="-1" title="Toggle display of directory item detail information (&#8984;D)"><span id="show"> details</span></button></li> <li class="display_flex no_highlight"><label id="show_invisibles_container" for="inv_checkbox" class="margin_0 padding_0 flex_justify_center_row"><input class="toggle_UI_pref margin_0" type="checkbox" id="show_invisibles" data-ui_pref="show_invisibles" title="Toggle display of invisible items (&#8984&#8679;;I)" name="inv_checkbox" tabindex="-1"${ checked } /><span>&nbsp;Show Invisibles</span></label> </li>
  824. <li id="show_grid_btn" class="has_flyout_menu width_24px display_none position_relative pointer margin_0 padding_0 z_index_9997 no_highlight" tabindex="-1" title="Show Grid (&#8984;G)"><div class="display_flex width_14px_contents background_grey_80">${ SVG_UI_Icons.grid}</div> <ul class="menu has_popout_menu display_none position_absolute margin_0 padding_0 box_shadow_menu border_all background_grey_80"><div class="display_flex width_24px width_14px_contents">${ SVG_UI_Icons.grid}</div> <li id="show_image_grid" class="item_1 border_right border_bottom background_grey_80">Show Image Grid</li> <li id="show_font_grid" class="item_2 border_right background_grey_80">Show Font Grid</li> </ul> </li>
  825. </ul>
  826. <div id="sorting" class="background_grey_80">
  827. <ul id="sorting_row_1" class="whitespace_pre pointer container display_flex flex_justify_contents border_bottom"> <li id="sort_by_name" class="whitespace_pre pointer toggle_UI_pref name sorting align_left no_highlight" data-ui_pref="sort_by_name" title="Sort by name"><span><input id="play_toggle" class="whitespace_pre pointer display_none position_relative" type="checkbox" tabindex="-1" checked="true" />Name</span></li> <li id="sort_by_default" class="whitespace_pre pointer toggle_UI_pref sorting align_right no_highlight" data-ui_pref="sort_by_default" title="Default sort"><span>Default</span></li> <li id="sort_by_duration" class="whitespace_pre pointer toggle_UI_pref sorting align_right display_none no_highlight" data-ui_pref="sort_by_duration" title="Sort by media duration"><span>Duration</span></li> </ul>
  828. <ul id="sorting_row_2" class="whitespace_pre pointer iframe_item border_bottom display_none"> <li id="sort_by_ext" class="whitespace_pre pointer toggle_UI_pref details sorting align_left no_highlight" data-ui_pref="sort_by_ext" title="Sort by extension"><span>Ext</span></li> <li id="sort_by_duration" class="whitespace_pre pointer toggle_UI_pref sorting align_right display_none no_highlight" data-ui_pref="sort_by_duration" title="Sort by media duration"><span>Duration</span></li> <li id="sort_by_size" class="whitespace_pre pointer toggle_UI_pref details sorting center no_highlight" data-ui_pref="sort_by_size" title="Sort by size"><span>Size</span></li> <li id="sort_by_date" class="whitespace_pre pointer toggle_UI_pref details sorting center no_highlight" data-ui_pref="sort_by_date" title="Sort by date"><span>Date</span></li> <li id="sort_by_kind" class="whitespace_pre pointer toggle_UI_pref details sorting align_right no_highlight" data-ui_pref="sort_by_kind" title="Sort by kind"><span>Kind</span></li> </ul>
  829. </div>
  830. ${ texteditor_element }
  831. </div>
  832. </header>`;
  833. };
  834. const Directory_Elements = function (body_id, parent_link) { // Assemble directory elements for both top and iframe directories
  835. let dir_footer_utilities = '',
  836. directory_utilities = '';
  837. if (body_id === 'top_body') { // various elements not needed in iframe directories
  838. dir_footer_utilities = `<div id="dir_footer_utilities" class="width_24px flex_justify_center position_relative invert pointer z_index_1"><div class="width_18px_contents display_flex transform_rotate_180">${ SVG_UI_Icons.toggle }</div> <ul class="has_popout_menu invert margin_0 padding_0 display_none border_all position_absolute background_grey_80"> <li id="open_in_content_pane" class="align_right border_bottom padding_4_6">Open Sidebar in Content Pane</li> <li id="show_directory_source" class="align_right padding_4_6" data-kind="show_directory_source">View Sidebar Directory Source</li> </ul> </div>`;
  839. directory_utilities = `<div id="dir_utilities"><div id="handle" class="position_absolute z_index_1"></div> <div id="show_sidebar" class="toggle_UI_pref width_24px width_18px_contents position_absolute flex_justify_center invert pointer z_index_9997" data-ui_pref="show_sidebar" title="Toggle Sidebar (&#8984;\\)">${ SVG_UI_Icons.toggle }</div></div> </div>`;
  840. }
  841. const dir_nav = `<nav id="dir_nav" class="display_flex flex_column background_grey_85 font_size_small"><div id="dir_nav_inner" class="position_relative">
  842. <div id="directory_list_outer" class="position_relative"><ol id="directory_list" class="display_flex flex_column margin_0 padding_0 text_color_default border_bottom" tabindex="0">insert_prepped_index</ol></div>
  843. </div></nav>`;
  844. const dir_footer = `<footer id="dir_footer" class="display_flex flex_row position_relative background_grey_85 border_top text_color_default error_display_none font_size_small">insert_stats${ dir_footer_utilities }</footer>`;
  845. return `<div id="dir_wrapper" class="${body_id} display_flex flex_column position_relative border_right padding_0 z_index_1" style="width:${ Number(getCurrentUIPref("width")) }%">
  846. ${ Directory_Header_Elements(body_id,parent_link) } ${ dir_nav } ${ dir_footer } ${ directory_utilities }
  847. </div>`;
  848. };
  849. //==============================//
  850. // CONTENT PANE ELEMENTS
  851. const Text_Editing_UI_Elements = `
  852. <div id="toolbar" class="border_bottom background_grey_80 position_relative text_color_default display_flex width_100">
  853. <ul id="toolbar_buttons" class="display_flex flex_row flex_grow_1 margin_0 padding_0"> <li id="toggle_texteditor_view_raw" class="toggle_UI_pref toolbar_icon display_flex no_highlight" data-ui_pref="texteditor_view_raw" title="Show source"><div class="display_flex width_16px_contents invert">${ SVG_Text_Editing_UI_Icons.show_markdown }</div></li> <li id="toggle_texteditor_view_preview" class="toggle_UI_pref toolbar_icon display_flex no_highlight" data-ui_pref="texteditor_view_preview" title="Show rendered markdown"><div class="display_flex width_14px_contents invert">${ SVG_Text_Editing_UI_Icons.show_preview }</div></li> <li id="toggle_texteditor_view_html" class="toggle_UI_pref toolbar_icon display_flex no_highlight" data-ui_pref="texteditor_view_html" title="Show formatted HTML"><div class="display_flex width_18px_contents invert">${ SVG_Text_Editing_UI_Icons.show_html }</div></li> <li id="toggle_texteditor_split_view" class="toggle_UI_pref toolbar_icon display_flex no_highlight" data-ui_pref="texteditor_split_view" title="Toggle Split View"><div class="display_flex width_14px_contents invert">${ SVG_Text_Editing_UI_Icons.toggle_split }</div></li> <li id="texteditor_sync_scroll" class="toggle_UI_pref checkbox_container flex_justify_center_row no_highlight" data-ui_pref="texteditor_sync_scroll"><input id="texteditor_sync_scroll_input" class="flex_justify_center_row position_relative" data-ui_pref="texteditor_sync_scroll" name="texteditor_sync_scroll" type="checkbox"><label id="texteditor_sync_scroll_label" for="texteditor_sync_scroll" class="flex_justify_center_row whitespace_pre" data-ui_pref="texteditor_sync_scroll">Sync Scroll</label></li> <li class="display_flex flex_grow_1 no_highlight">&nbsp;</li> <li id="clear_text" class="toolbar_icon no_highlight" title="Clear Text">Clear</li> <li id="save_btn" class="has_flyout_menu width_24px display_flex position_relative pointer margin_0 padding_0 z_index_9997" title=""><div class="display_flex width_14px_contents">${ SVG_Text_Editing_UI_Icons.save_btn}</div><ul class="menu has_popout_menu display_none position_absolute margin_0 padding_0 box_shadow_menu border_top border_bottom border_left background_grey_80"> <li id="save_text" class="item_1 border_right border_bottom background_grey_85" title="Save source text"><span id="save_text_link" target="_blank">Save Source</span></li> <li id="save_btn_icon" class="item_1 no_highlight">${ SVG_Text_Editing_UI_Icons.save_btn}</li> <li id="save_HTML" class="item_2 border_right background_grey_85" title="Save rendered html"><span id="save_HTML_link" target="_blank">Save HTML</span></li> </ul></li> </ul>
  854. </div>
  855. <div id="text_container" class="display_flex flex_grow_1 overflow_hidden"> <textarea id="texteditor_txt_pane" class="texteditor_pane margin_0 border_0 height_100 line_height_1_2 text_color_default resize_none display_none z_index_1" tabindex="0"></textarea> <div id="texteditor_preview_pane" class="texteditor_pane margin_0 border_0 line_height_1_2 text_color_default height_100 display_none markdown_body z_index_1" tabindex="0"></div> <textarea id="texteditor_html_pane" class="texteditor_pane margin_0 height_100 line_height_1_2 border_0 text_color_default resize_none display_none z_index_1" tabindex="0" readonly></textarea>
  856. <div id="text_editing_handle" class="position_absolute z_index_3"></div></div>
  857. `;
  858. const Content_Text_Elements = `<div id="content_texteditor" class="background_grey_85 margin_0 padding_0 width_100 height_100 overflow_hidden position_absolute z_index_1 flex_column flex_grow_1 display_none">${ Text_Editing_UI_Elements }</div>`;
  859. const Content_Audio_Elements = `
  860. <div id="content_audio_title" class="flex_justify_center_row background_grey_80 bold center" title="Click to toggle .m3u playlist entry."><span class="pointer line_height_1_4"></span></div>
  861. <div id="content_audio" class="display_flex flex_row border_bottom background_grey_80">
  862. <div id="audio_container" class="display_flex flex_row border_all">
  863. <nav id="cuesheet_track_list_container_audio" class="cuesheet_track_list_container border_right" title="Cue sheet track list"> <div class="box_shadow_menu display_none font_size_small position_absolute position_LR_0 z_index_1"><ul id="cuesheet_track_list_audio" class="cuesheet_track_list background_grey_85 border_bottom margin_0 padding_0"> </ul></div> </nav>
  864. <div id="prev_track" class="prev_next_btn audio_controls flex_justify_center pointer" title="Previous track"><div class="display_flex width_24px_contents transform_rotate_180">${ SVG_UI_Icons.prev_next_track }</div></div>
  865. <div id="next_track" class="prev_next_btn audio_controls flex_justify_center border_right pointer" title="Next track"><div class="display_flex width_24px_contents">${ SVG_UI_Icons.prev_next_track }</div></div>
  866. <audio id="audio" preload="auto" tabindex="0" controls>Sorry, your browser does not support HTML5 audio.</audio>
  867. <div id="close_audio" class="audio_controls border_left flex_justify_center position_relative pointer" title="Close audio"><div class="display_flex width_14px_contents">${ SVG_UI_Icons.multiply }</div></div>
  868. <div id="audio_options" class="display_flex flex_column">
  869. <label id="loop_label" for="loop"><input type="checkbox" id="loop" name="loop" tabindex="0" />Loop</label>
  870. <label id="shuffle_label" class="whitespace_pre" for="shuffle"><input type="checkbox" id="shuffle" name="shuffle" tabindex="0" />Shuffle</label>
  871. </div>
  872. </div>
  873. </div>
  874. <div id="content_audio_playlist_item" class="playlist_entry_container border_bottom background_grey_85 center display_none"><textarea id="content_audio_playlist_item_textarea" class="text_color_default padding_4_6 border_0" rows="3" spellcheck="false"></textarea></div>`;
  875. const Content_Font_Viewer = '<div id="font_file_viewer" class="position_absolute position_0 display_none"><div id="font_file_glyph_viewer" class="invert margin_0 padding_0 position_absolute position_0 display_none z_index_2"></div><ol id="font_file_grid" class="font_grid position_relative padding_0 center display_grid overflow_x_hidden"></ol></div>';
  876. const font_toolbar = `<div id="font_toolbar" class="display_none margin_0 position_relative background_grey_80 border_bottom z_index_3">
  877. <ol id="font_specimen_variants" class="display_none flex_row flex_grow_1 border_bottom"><li id="font_variants" class="flex_justify_center no_highlight" title="Font Variants"><select id="font_variant_select" data-tab_order="10" label="Font Variants">
  878. <option value="">OpenType Feature Tags</option>
  879. <optgroup label="Caps"> <option value="normal" data-prop="font-variant-caps" data-value="normal">Normal </option> <option value="smcp" title="smcp" data-prop="font-variant-caps" data-value="small-caps">Small Caps </option> <option value="c2sc" title="c2sc" data-prop="font-variant-caps" data-value="all-small-caps">All Small Caps </option> <option value="pcap" title="pcap" data-prop="font-variant-caps" data-value="petite-caps">Petite Caps </option> <option value="c2pc" title="c2pc" data-prop="font-variant-caps" data-value="all-petit-caps">All Petite Caps </option> <option value="unic" title="unic" data-prop="font-variant-caps" data-value="unicase">Unicase </option> <option value="titl" title="titl" data-prop="font-variant-caps" data-value="titling-caps">Titling Caps </option> <option value="case" title="case">Case Sensitive Forms </option> <option value="ordn" title="ordn">Ordinals </option> </optgroup>
  880. <optgroup label="Alternatives"> <option value="normal" data-prop="font-variant-alternates" data-value="normal">Normal </option> <option value="aalt" title="aalt">Access All Alternates </option> <option value="nalt" title="nalt" data-prop="font-variant-alternates" data-value="'nalt'">Annotation 1-99 </option> <option value="cv01" title="cv01" data-prop="font-variant-alternates" data-value="\"cv01\"">Character Variant 1–99 </option> <option value="calt" title="calt" data-prop="font-variant-alternates" data-value="cv01">Contextual Alts 1-99 </option> <option value="hist" title="hist">Historical Forms </option> <option value="ornm" title="ornm" data-prop="font-variant-alternates" data-value="ornm">Ornaments 1-99 </option> <option value="salt" title="salt" data-prop="font-variant-alternates" data-value="salt">Stylistic Alternates 1-99 </option> <option value="ss01" title="ss01" data-prop="font-variant-alternates" data-value="ss01">Stylistic Set 120 </option> <option value="swsh" title="swsh" data-prop="font-variant-alternates" data-value="\"swsh\"">Swash 1-99 </option> <option value="cswh" title="cswh">Contextual Swash </option> </optgroup>
  881. <optgroup label="Ligatures"> <option value="normal" data-prop="font-variant-ligatures" data-value="normal">Normal </option> <option value="liga" title="liga" data-prop="font-variant-ligatures" data-value="common-ligatures">Common Ligatures </option> <option value="clig" title="clig" data-prop="font-variant-ligatures" data-value="contextual">Contextual Ligatures </option> <option value="dlig" title="dlig" data-prop="font-variant-ligatures" data-value="discretionary-ligatures">Discretionary Ligatures </option> <option value="hlig" title="hlig" data-prop="font-variant-ligatures" data-value="historical-ligatures">Historical Ligatures </option> </optgroup>
  882. <optgroup label="Numbers"> <option value="normal" data-prop="font-variant-numeric" data-value="normal">Normal </option> <option value="dnom" title="dnom" data-prop="font-variant-numeric" data-value="ordinal">Ordinal </option> <option value="zero" title="zero" data-prop="font-variant-numeric" data-value="slashed-zero">Slashed Zero </option> <option value="lnum" title="lnum" data-prop="font-variant-numeric" data-value="lining-nums">Lining Figures </option> <option value="onum" title="onum" data-prop="font-variant-numeric" data-value="oldstyle-nums">Oldstyle Figures </option> <option value="pnum" title="pnum" data-prop="font-variant-numeric" data-value="proportional-nums">Proportional Figures </option> <option value="tnum" title="tnum" data-prop="font-variant-numeric" data-value="tablular-nums">Tabular Figures </option> <option value="frac" title="frac" data-prop="font-variant-numeric" data-value="diagonal-fractions">Fractions </option> <option value="afrc" title="afrc" data-prop="font-variant-numeric" data-value="stacked-fractions">Alternative Fractions </option> <option value="numr" title="numr">Numerator </option> <option value="sinf" title="sinf">Scientific Inferiors </option> <option value="mgrk" title="mgrk">Mathematical Greek </option> </optgroup>
  883. <optgroup label="Position"> <option value="normal" data-prop="font-variant-position" data-value="normal">Normal </option> <option value="subs" title="subs" data-prop="font-variant-position" data-value="sub">Subscript </option> <option value="sups" title="sups" data-prop="font-variant-position" data-value="super">Superscript </option> </optgroup>
  884. </select></li>
  885. <li id="font_tag" class="flex_justify_center no_highlight" data-salt=""><span class="flex_justify_center position_relative"><textarea id="font_tag_textarea" data-tab_order="12" class="resize_none" rows="1" cols="5" spellcheck="false" maxlength="8" placeholder="otftag" title="Enter an OpenType Feature Tag (e.g.: &ldquo;smcp&rdquo;)"></textarea></span></li>
  886. <li class="spacer no_highlight width_100"></li>
  887. <li id="unicode_char_planes" class="flex_justify_center no_highlight" title="Unicode Code Ranges"><select id="unicode_char_ranges_select" data-tab_order="13">
  888. <option value="">Unicode Code Ranges</option>
  889. <optgroup label="Basic Multilingual Plane"> <option id="BMP_Range_01" value="BMP_Range_01" data-block_start="0000" data-block_end="0FFF">BMP-01: U+0000U+0FFF</option> <option id="BMP_Range_02" value="BMP_Range_02" data-block_start="1000" data-block_end="1FFF">BMP-02: U+1000–U+1FFF</option> <option id="BMP_Range_03" value="BMP_Range_03" data-block_start="2000" data-block_end="2FFF">BMP-03: U+2000U+2FFF</option> <option id="BMP_Range_04" value="BMP_Range_04" data-block_start="3000" data-block_end="3FFF">BMP-04: U+3000–U+3FFF</option> <option id="BMP_Range_05" value="BMP_Range_05" data-block_start="4000" data-block_end="4FFF">BMP-05: U+4000U+4FFF</option> <option id="BMP_Range_06" value="BMP_Range_06" data-block_start="5000" data-block_end="5FFF">BMP-06: U+5000–U+5FFF</option> <option id="BMP_Range_07" value="BMP_Range_07" data-block_start="6000" data-block_end="6FFF">BMP-07: U+6000U+6FFF</option> <option id="BMP_Range_08" value="BMP_Range_08" data-block_start="7000" data-block_end="7FFF">BMP-08: U+7000–U+7FFF</option> <option id="BMP_Range_09" value="BMP_Range_09" data-block_start="8000" data-block_end="8FFF">BMP-09: U+8000U+8FFF</option> <option id="BMP_Range_10" value="BMP_Range_10" data-block_start="9000" data-block_end="9FFF">BMP-10: U+9000–U+9FFF</option> <option id="BMP_Range_11" value="BMP_Range_11" data-block_start="A000" data-block_end="AFFF">BMP-11: U+A000U+AFFF</option> <option id="BMP_Range_12" value="BMP_Range_12" data-block_start="B000" data-block_end="BFFF">BMP-12: U+B000–U+BFFF</option> <option id="BMP_Range_13" value="BMP_Range_13" data-block_start="C000" data-block_end="CFFF">BMP-13: U+C000U+CFFF</option> <option id="BMP_Range_14" value="BMP_Range_14" data-block_start="D000" data-block_end="DFFF">BMP-14: U+D000–U+DFFF</option> <option id="BMP_Range_15" value="BMP_Range_15" data-block_start="E000" data-block_end="EFFF">BMP-15: U+E000U+EFFF</option> <option id="BMP_Range_16" value="BMP_Range_16" data-block_start="F000" data-block_end="FFFF">BMP-16: U+F000–U+FFFF</option> </optgroup>
  890. <optgroup label="Supplementary Multilingual Plane" data-block_start="10000" data-block_end="10FFF"> <option id="SMP_Range_01" value="SMP_Range_01">SMP-01: U+10000U+10FFF</option> <option id="SMP_Range_02" value="SMP_Range_02" data-block_start="11000" data-block_end="11FFF">SMP-02: U+11000–U+11FFF</option> <option id="SMP_Range_03" value="SMP_Range_03" data-block_start="12000" data-block_end="12FFF">SMP-03: U+12000U+12FFF</option> <option id="SMP_Range_04" value="SMP_Range_04" data-block_start="13000" data-block_end="13FFF">SMP-04: U+13000–U+13FFF</option> <option id="SMP_Range_05" value="SMP_Range_05" data-block_start="14000" data-block_end="14FFF">SMP-05: U+14000U+14FFF</option> <option id="SMP_Range_06" value="SMP_Range_06" data-block_start="15000" data-block_end="15FFF">SMP-06: U+15000–U+15FFF</option> <option id="SMP_Range_07" value="SMP_Range_07" data-block_start="16000" data-block_end="16FFF">SMP-07: U+16000U+16FFF</option> <option id="SMP_Range_08" value="SMP_Range_08" data-block_start="17000" data-block_end="17FFF">SMP-08: U+17000–U+17FFF</option> <option id="SMP_Range_09" value="SMP_Range_09" data-block_start="18000" data-block_end="18FFF">SMP-09: U+18000U+18FFF</option> <option id="SMP_Range_10" value="SMP_Range_10" data-block_start="19000" data-block_end="19FFF">SMP-10: U+19000–U+19FFF</option> <option id="SMP_Range_11" value="SMP_Range_11" data-block_start="1A000" data-block_end="1AFFF">SMP-11: U+1A000U+1AFFF</option> <option id="SMP_Range_12" value="SMP_Range_12" data-block_start="1B000" data-block_end="1BFFF">SMP-12: U+1B000–U+1BFFF</option> <option id="SMP_Range_13" value="SMP_Range_13" data-block_start="1C000" data-block_end="1CFFF">SMP-13: U+1C000U+1CFFF</option> <option id="SMP_Range_14" value="SMP_Range_14" data-block_start="1D000" data-block_end="1DFFF">SMP-14: U+1D000–U+1DFFF</option> <option id="SMP_Range_15" value="SMP_Range_15" data-block_start="1E000" data-block_end="1EFFF">SMP-15: U+1E000U+1EFFF</option> <option id="SMP_Range_16" value="SMP_Range_16" data-block_start="1F000" data-block_end="1FFFF">SMP-16: U+1F000–U+1FFFF</option> </optgroup>
  891. <optgroup label="Supplementary Ideographic Plane" data-block_start="20000" data-block_end="20FFF"> <option id="SIP_Range_01" value="SIP_Range_01">SIP-01: U+20000U+20FFF</option> <option id="SIP_Range_02" value="SIP_Range_02" data-block_start="21000" data-block_end="21FFF">SIP-02: U+21000–U+21FFF</option> <option id="SIP_Range_03" value="SIP_Range_03" data-block_start="22000" data-block_end="22FFF">SIP-03: U+22000U+22FFF</option> <option id="SIP_Range_04" value="SIP_Range_04" data-block_start="23000" data-block_end="23FFF">SIP-04: U+23000–U+23FFF</option> <option id="SIP_Range_05" value="SIP_Range_05" data-block_start="24000" data-block_end="24FFF">SIP-05: U+24000U+24FFF</option> <option id="SIP_Range_06" value="SIP_Range_06" data-block_start="25000" data-block_end="25FFF">SIP-06: U+25000–U+25FFF</option> <option id="SIP_Range_07" value="SIP_Range_07" data-block_start="26000" data-block_end="26FFF">SIP-07: U+26000U+26FFF</option> <option id="SIP_Range_08" value="SIP_Range_08" data-block_start="27000" data-block_end="27FFF">SIP-08: U+27000–U+27FFF</option> <option id="SIP_Range_09" value="SIP_Range_09" data-block_start="28000" data-block_end="28FFF">SIP-09: U+28000U+28FFF</option> <option id="SIP_Range_10" value="SIP_Range_10" data-block_start="29000" data-block_end="29FFF">SIP-10: U+29000–U+29FFF</option> <option id="SIP_Range_11" value="SIP_Range_11" data-block_start="2A000" data-block_end="2AFFF">SIP-11: U+2A000U+2AFFF</option> <option id="SIP_Range_12" value="SIP_Range_12" data-block_start="2B000" data-block_end="2BFFF">SIP-12: U+2B000–U+2BFFF</option> <option id="SIP_Range_13" value="SIP_Range_13" data-block_start="2C000" data-block_end="2CFFF">SIP-13: U+2C000U+2CFFF</option> <option id="SIP_Range_14" value="SIP_Range_14" data-block_start="2D000" data-block_end="2DFFF">SIP-14: U+2D000–U+2DFFF</option> <option id="SIP_Range_15" value="SIP_Range_15" data-block_start="2E000" data-block_end="2EFFF">SIP-15: U+2E000U+2EFFF</option> <option id="SIP_Range_16" value="SIP_Range_16" data-block_start="2F000" data-block_end="2FFFF">SIP-16: U+2F000–U+2FFFF</option> </optgroup>
  892. <optgroup label="Tertiary Ideographic Plane" data-block_start="30000" data-block_end="30FFF"> <option id="TIP_Range_01" value="TIP_Range_01">TIP-01: U+30000U+30FFF</option> <option id="TIP_Range_02" value="TIP_Range_02" data-block_start="31000" data-block_end="31FFF">TIP-02: U+31000–U+31FFF</option> </optgroup>
  893. <optgroup label="Supplementary Special-Purpose Plane" data-block_start="E0000" data-block_end="E0FFF"> <option id="SSP_Range_01" value="SSP_Range_01">SSP-01: U+E0000U+E0FFF</option> </optgroup>
  894. </select></li>
  895. </ol>
  896. <ol id="font_specimen_adjustments" class="display_flex flex_row flex_grow_1">
  897. <li class="no_highlight" data-inputid="font_size"><span class="flex_justify_center"><input type="range" id="font_size" data-tab_order="14" name="font_size" min="0" max="2" step="any"><label for="font_size">Font Size</label></span></li> <li class="no_highlight display_none" data-inputid="line_height"><span class="flex_justify_center"><input type="range" id="line_height" data-tab_order="15" name="line_height" min="-1.2" max="1.2" step="any"><label for="line_height">Line Height</label></span></li> <li class="no_highlight display_none" data-inputid="letter_spacing"><span class="flex_justify_center"><input type="range" id="letter_spacing" data-tab_order="16" name="letter_spacing" min="-100" max="100" step="1"><label for="letter_spacing">Letter Spacing</label></span></li>
  898. <li class="spacer no_highlight width_100"></li>
  899. <li data-inputid="text_color" class="display_flex no_highlight"><span class="flex_justify_center position_relative"><textarea id="text_color" class="whitespace_pre resize_none" data-tab_order="17" rows="1" cols="7" spellcheck="false" placeholder="CSS color"></textarea> Text Color</span></li> <li data-inputid="text_stroke_width" class="display_flex no_highlight"><span class="flex_justify_center"><input type="range" id="text_stroke_width" data-tab_order="18" name="font_size" min="-0.5" max="0.5" step="any" title="In supported browsers only."><label for="text_stroke_width">Text Stroke Width</label></span></li> <li data-inputid="text_stroke_color" class="display_flex no_highlight"><span class="flex_justify_center position_relative"><textarea id="text_stroke_color" class="whitespace_pre resize_none" data-tab_order="19" rows="1" cols="7" spellcheck="false" placeholder="CSS color"></textarea>Text Stroke Color</span></li>
  900. </ol></div>`;
  901. const Content_Font_Elements = function () {
  902. const sample_string = `ABCDEFGHIJKLMNOPQRSTUVWXYZ<br />abcdefghijklmnopqrstuvwxyz<br />0123456789<br />!"#$%&'()*+,-./:;<=>?@[\\]^_\`{|}~`;
  903. const lorem_string = `Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`;
  904. return `<div id="font_specimen_viewer" class="padding_0 display_none">
  905. <ol id="font_specimen_grid" class="font_grid display_grid overflow_visible"></ol>
  906. <div id="font_specimen"> <div id="font_specimen_1" class="specimen border_bottom_x margin_0 overflow_visible normal" data-tab_order="1" contenteditable="true">${ sample_string }</div> <div id="font_specimen_2" class="specimen border_bottom_x align_left overflow_visible normal" data-tab_order="2" contenteditable="true" tabindex="0"><h2 id="specimen_2" class="margin_0 line_height_1 normal">Typography</h2><p id="specimen_2H4">The art of using types to produce impressions on paper, vellum, &amp;c.</p></div> <div id="font_specimen_3" class="specimen border_bottom_x align_justify overflow_visible normal line_height_1" data-tab_order="3" contenteditable="true"><h3 id="specimen_3" class="margin_0 normal">S P E C I M E N</h3><p id="specimen_3H3" class="margin_0">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.</p></div> <div id="font_specimen_4" class="specimen overflow_visible normal" data-tab_order="4" contenteditable="true" tabindex="0"> <div id="lorem" class="lorem align_justify">${ lorem_string }</div><div id="lorem_2" class="lorem align_justify">${ lorem_string }</div><div id="lorem_3" class="lorem align_justify">${ lorem_string }</div></div></div>
  907. <div id="font_specimen_glyph_viewer" class="background_grey_90 display_none overflow_visible normal"><div id="font_specimen_glyph" class="flex_justify_center position_fixed position_0 z_index_2" data-scale="1"></div><div id="font_specimen_glyph_overlay" class="position_fixed position_0 background_grey_100 z_index_1"></div></div>
  908. </div> ${ Content_Font_Viewer }`;
  909. };
  910. const Content_Header_Elements = `
  911. <header id="content_header" class="font_size_small z_index_3">
  912. <div id="audio_wrapper" class="text_color_default background_grey_75 display_none"> ${ Content_Audio_Elements } </div>
  913. <div id="content_title_container" class="title display_flex text_color_default border_bottom">
  914. <div id="title_buttons_left" class="display_flex padding_4_6 align_left">
  915. <nav id="cuesheet_track_list_container_video" class="cuesheet_track_list_container background_grey_75" title="Cue sheet track list"><div class="box_shadow_menu display_none font_size_small position_absolute position_LR_0 z_index_1"><ul id="cuesheet_track_list_video" class="cuesheet_track_list border_bottom margin_0 padding_0 display_none"></ul></div></nav>
  916. <button id="reload_btn" tabindex="-1"><span></span></button> <button id="prev_next_btns" class="split_btn padding_0 position_relative display_none" tabindex="-1"><span id="prev_btn" class="prev_next_btn flex_justify_center"><span class="transform_rotate_270_contents">${ SVG_UI_Icons.chevron }</span></span><span id="next_btn" class="prev_next_btn flex_justify_center"><span class="display_flex transform_rotate_90_contents">${ SVG_UI_Icons.chevron }</span></span></button>
  917. </div>
  918. <div id="content_title" class="pointer center hyphens_none line_height_1_4 flex_justify_center_row flex_grow_1"><div><span class="has_icon_before bold"></span></div></div>
  919. <div id="title_buttons_right" class="display_flex padding_4_6 align_right"> <button id="scale" class="split_btn padding_0 position_relative display_none" tabindex="-1"><span id="decrease" class="flex_justify_center" title="Reduce"><div class="display_flex width_10px_contents">${ SVG_UI_Icons.minus }</div></span><span id="increase" class="flex_justify_center" title="Enlarge"><div class="display_flex width_10px_contents">${ SVG_UI_Icons.plus }</div></span></button> <button id="open_in_texteditor" class="display_none" title="Open in Text Editor" tabindex="-1"><span>Edit</span></button> <button id="save_svg" class="display_none whitespace_pre" title="Save glyph as svg"><span>Save SVG</span></button> <button id="close_btn" tabindex="-1" title="Close Content"><span></span></button></div>
  920. </div>
  921. <div id="content_playlist_item" class="playlist_entry_container border_bottom background_grey_85 center display_none"><textarea id="content_playlist_item_textarea" class="text_color_default padding_4_6 border_0" rows="3" spellcheck="false"></textarea></div>
  922. ${ font_toolbar }
  923. </header>`;
  924. // CONTENT containers
  925. const Content_Pane_Elements = `<div id="content_pane" class="display_flex flex_column flex_grow_1 position_relative padding_0" data-content="has_null">
  926. ${ Content_Header_Elements }
  927. <main id="content_container" class="display_flex position_relative background_grey_85 margin_0 padding_0"> ${ SVG_UI_Icons.spinner } <ol id="content_grid" class="content_el" data-kind="grid"></ol> ${ Content_Text_Elements } <div id="content_font" class="content_el background_grey_90 hyphens_none position_relative text_color_default" spellcheck="false" data-kind="font">${ Content_Font_Elements() }</div> <div id="content_image_container" class="content_el background_grey_95 position_relative margin_0" data-kind="image"><img id="content_image" class="content_el position_relative" src="#" alt="" tabindex="0" /></div> <embed id="content_pdf" class="content_el position_relative border_0" tabindex="0" data-kind="pdf"> <video id="content_video" class="content_el background_grey_95 media position_absolute" controls data-kind="video">Your browser does not support the video tag.</video> <iframe id="content_iframe" class="content_el position_relative border_0" name="content_iframe" sandbox="allow-scripts allow-same-origin allow-modals allow-popups" tabindex="0"></iframe> <iframe id="content_iframe_utility" class="display_none" name="content_iframe_utility" sandbox="allow-scripts allow-same-origin allow-modals allow-popups" tabindex="0"></iframe> </main>
  928. </div>`;
  929. //==============================//
  930. // UTILITIES HTML (warnings and help)
  931. const Utilities_Warnings = `
  932. <header id="warnings_header" class="text_color_default background_grey_85"><h3 id="warning_header" class="display_none margin_0"><span>Warning:</span></h3><h3 id="make_playlist_header" class="display_none margin_0 normal"><span>Make Playlist/Filelist (.m3u)</span></h3></header>
  933. <div id="warnings" class="text_color_default background_grey_85">
  934. <div id="warning_open_font" class="warning">Are you sure you want to close the font file?</div> <div id="warning_close_font" class="warning">Are you sure you want to close the font file?</div> <div id="warning_unsaved_text" class="warning">You have unsaved changes.</div> <div id="warning_clear_text" class="warning">Are you sure you want to clear all your text?</div> <div id="warning_local_file" class="warning">Can&rsquo;t load local file from non-local page.</div> <div id="warning_close_playlist" class="warning">Are you sure you want to close the playlist?</div> <div id="warning_local_playlist" class="warning">This playlist contains local files. <br />&emsp;Please reload this playlist from a local page in order to play them.</div> <div id="warning_non_local_file" class="warning">This is a non-local file/dir/link. Would you like to open it in a new window?</div>
  935. <div id="warning_make_playlist" class="warning"> <form id="make_playlist_form" action="#"><fieldset class="margin_0 padding_0 border_0"> <div><input name="make_playlist" type="radio" id="all_items" checked><label for="all_items">All items</label></div> <div class="indent"><input name="make_playlist" type="radio" id="directories_only"><label for="directories_only">Directories only</label></div> <div class="indent"><input name="make_playlist" type="radio" id="files_only"><label for="files_only">Files only</label></div> <div><input name="make_playlist" type="radio" id="media_files_only"><label for="media_files_only">All media files</label></div> <div class="indent"><input name="make_playlist" type="radio" id="audio_files_only"><label for="audio_files_only">Audio files only</label></div> <div class="indent"><input name="make_playlist" type="radio" id="video_files_only"><label for="video_files_only">Video files only</label></div> <div><input name="make_playlist" type="radio" id="all_non_media_files"><label for="all_non_media_files">All non-media items</label></div> </fieldset></form> </div>
  936. </div>
  937. <div id="warning_buttons_container" class="display_flex flex_column background_grey_90"> <div id="warning_buttons" class="display_flex flex_row"> <button id="warning_btn_dont_save" class="warning_button">Don&rsquo;t Save</button> <button id="warning_btn_cancel" class="warning_button">Cancel</button> <button id="warning_btn_clear" class="warning_button">Clear</button> <button id="warning_btn_save" class="warning_button">Save</button> <button id="warning_btn_ok" class="warning_button">OK</button> </div> </div>`;
  938. const Utilities_Help = `
  939. <header id="help_header" class="title display_grid padding_4_6 position_LR_0 text_color_default border_bottom_x background_grey_75 center position_fixed"><span class="spacer"></span><span class="bold flex_justify_center">HELP</span><button id="close_help" class="focus"><span>Close</span></button></header><section class="line_height_1_4">
  940. <ol style="margin:1em 3em 0;list-style-type:decimal;" class="no_highlight bold">CONTENTS<li class="no_highlight">I. About this Script</li><li class="no_highlight">II. Keyboard Shortcuts</li><li class="no_highlight">III. Usage: The Main Menu</li><li class="no_highlight">IV. Other Script Functions</li><li class="no_highlight">V. Troubleshooting</li></ol>
  941. <h2><strong>I. ABOUT THIS SCRIPT</strong></h2>
  942. <p>This script works &ldquo;out-of-the-box&rdquo; on local directories. To enable it to work on a remote directory, add its url to the list of included/allowed sites in your userscript manager&rsquo;s settings for this script.</p>
  943. <p class="bold"><a href="https://openuserjs.org/scripts/gaspar_schot/Supercharged_Local_Directory_File_Browser" class="has_icon_before link text_color_default" target="_blank">Script home: openuserjs.org</a></p>
  944. <p><span style="float:left; margin:4px 6px 0 0;">${ SVG_UI_Icons.ui_layout }</span>The UI consists of two main parts: the navigation <strong>Sidebar</strong> on the left and the preview <strong>Content Pane</strong> on the right. The Sidebar shows all the files in the current directory, while the Content Pane shows a preview of the items selected in the Sidebar.</p>
  945. <p>The <strong>Sidebar</strong> contains a <strong>Header</strong> area, the <strong>Directory List</strong> itself, and a <strong>Footer</strong>.</p>
  946. <p>The <strong>Sidebar</strong> is resizeable, or it can be hidden entirely via the double-chevron button at the Sidebar top right.</p>
  947. <p>The <strong>Sidebar Header</strong> includes a <strong>Parent Directory</strong> button, a <strong>Parent Directories</strong> menu, and the <strong>Main Menu</strong>. and below these, <strong>Show Details</strong> and <strong>Show Invisibles</strong> items, a <strong>Show Grid</strong> button (when appropriate), and sort by <strong>Name</strong> or <strong>Default</strong> items; if <strong>Show Details</strong> is selected, additional sorting options are shown, along with the <strong>Text Editor</strong> item. All of these items are also available in the Main Menu, and some can be toggled via a keyboard shortcut (see below).</p>
  948. <p> The <strong>Content Pane</strong> displays the selected sidebar item.</p>
  949. <ul><li class="no_hover no_highlight">The content pane can be focused by tabbing from the sidebar or clicking.</li>
  950. <li class="no_hover no_highlight">Clicking the title of the content pane title reveals a playlist item than can be copied into an m3u file.</li>
  951. <li class="no_hover no_highlight">Previewed Content</li>
  952. <ul><li class="no_hover no_highlight">Directories
  953. <dl><dd><Previewed directories in the Content Pane inherit the sorting and other UI preferences from the Sidebar directory list. They can be navigated independently from the Sidebar via the Parent Directory link in the header or Cmd-Up Arrow.</dd>
  954. <dd>An item in the content pane header allows previewed directories to be opened into the sidebar.</dd>
  955. <dd>A selected item can be previewed by pressing the spacebar. This is similar to the &ldquo;quicklook&rdquo; function in MacOS.</dd>
  956. <dd>Double-clicking a selected directory list item or typing Cmd-Down Arrow will open it in the content pane, replacing the previewed directory. Closing the item via the Close Button or Cmd-W will restore the original previewed directory.</dd>
  957. </dl>
  958. </li>
  959. </li>
  960. <p>The <strong>Footer</strong> displays <strong>Stats</strong> for the items in the current directory, with detailed stats shown if you click the footer. There is also a popup menu on the right that allows you to display the Sidebar directory or the raw directory index in the Content Pane.</p>
  961. <ul id="utilities_help" class="info_list font_size_small border_all padding_0 no_highlight"> <li id="shortcuts" class="info_list_header display_grid center bold no_hover no_highlight"><span class="col_1">II. KEYBOARD SHORTCUTS</span><span class="col_2">DESCRIPTION</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&uarr;</kbd> or <kbd>&darr;</kbd></span><span class="col_2">Select the previous/next sidebar item or previewed directory item.<br />If audio is playing, and the previous/next file is also audio, the file will be highlighted but not loaded in the audio player; press <kbd>return</kbd> to load it.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&larr;</kbd> or <kbd>&rarr;</kbd></span><span class="col_2">Select prev/next item of the same kind as the current selection.<br />If current selection is a media file, select and begin playback of the next media item.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8997;</kbd><kbd>&larr;</kbd> or <kbd>&#8594;</kbd></span><span class="col_2">Skip media &plusmn;10 seconds.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8997;</kbd><kbd>&#8679;</kbd><kbd>&larr;</kbd> or <kbd>&rarr;</kbd></span><span class="col_2">Skip media &plusmn;30 seconds.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>&uarr;</kbd></span><span class="col_2">Go to parent directory.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>&darr;</kbd></span><span class="col_2">Go to selected sidebar directory.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>&rarr;</kbd></span><span class="col_2">Open selected sidebar directory as subdirectory.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>&larr;</kbd></span><span class="col_2">1. Close selected subdirectory, or <br />2. jump from selected subdirectory item to parent directory, or <br />3. jump up to closest open subdirectory, or <br />4. jump up to top of directory list.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>Escape</kbd></span><span class="col_2">Close menus and help, unfocus textareas and content pane, etc.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>Return</kbd></span><span class="col_2">Open selected sidebar directory, select file, or pause/play media.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>Space</kbd></span><span class="col_2">Pause/Play media files (if media player loaded).<br />&ldquo;Quicklook&rdquo; selected content pane directory list item.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>Tab</kbd></span><span class="col_2">Toggle focus between sidebar and content pane.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>&#8679;</kbd><kbd>D</kbd></span><span class="col_2">Toggle file details (size, date modified, kind) in some index page types.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>E</kbd></span><span class="col_2">Toggle main menu.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>&#8679;</kbd><kbd>E</kbd></span><span class="col_2">Show text editor.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>G</kbd></span><span class="col_2">Show or reload image or font grids.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>&#8679;</kbd><kbd>I</kbd></span><span class="col_2">Toggle invisible files.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>&#8679;</kbd><kbd>J</kbd></span><span class="col_2">Go to item by row number.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>&#8679;</kbd><kbd>O</kbd></span><span class="col_2">Open selected sidebar item in new window/tab.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>R</kbd></span><span class="col_2">Reload grids and previewed content, reset scaled images/fonts, reset media files to beginning.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>W</kbd></span><span class="col_2">Close previewed content (doesn&rsquo;t work in all browsers; use close button instead), or close window if no content is being previewed.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>&#8679;</kbd><kbd>&lt;</kbd> or <kbd>&gt;</kbd></span><span class="col_2">Scale preview items and grids.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8984;</kbd><kbd>\\</kbd></span><span class="col_2">Toggle sidebar.</span></li> <li class="display_grid no_hover no_highlight"><span class="col_1"><kbd>&#8679;</kbd><kbd>&#8984;</kbd><kbd>\\</kbd></span><span class="col_2">Toggle text editor split view.</span></li> </ul>
  962. <h2 id="usage"><strong>III. USAGE</strong></h2>
  963. <div id="help_main_menu" class="border_top_x invert">
  964. <p><span class="invert width_14px_contents">${ SVG_UI_Icons.menu }</span><strong> MAIN MENU</strong> (&#8984;+E)<br />The Main Menu contains the following top-level items:<p>
  965. <ol style="margin:0 3em;list-style-type:decimal;" class="no_highlight bold"><li class="no_highlight">Go to item... (&#8984;+&#8679;+J)</li><li class="no_highlight" style="margin-top:6px;">Sort by...</li><li class="no_highlight" style="margin-top:6px;">UI Preferences</li><li class="no_highlight">File Handling Preferences</li><li class="no_highlight">Media Preferences</li><li class="no_highlight">Text Editing Preferences</li><li class="no_highlight">Default Preferences</li><li class="no_highlight" style="margin-top:6px;">Playlists</li><li class="no_highlight" style="margin-top:6px;">Open Font File...</li><li class="no_highlight" style="margin-top:6px;">Script Home</li><li class="no_highlight">Help</li><li class="no_highlight">Buy me a Coffee</li><li class="no_highlight">Contact</li></ol>
  966. <dl class="border_top_x padding_top_1rem"><dt>1. Go to Item...</dt> <dd>Select a sidebar item by its row number (displayed if "Show Numbers" pref is set). Useful especially for large directories. Directory list can also be navigated by typed strings.</dd></dl>
  967. <dl class="border_top_x padding_top_1rem padding_bottom_1rem"><dt>2. Sort By...</dt><dd>Sort directory items by <strong>Name</strong>, <strong>Size</strong>, <strong>Date</strong>, <strong>Kind</strong>, <strong>Extension</strong>, <strong>Duration</strong> (media items only). <strong>Default</strong> sort = sort items by Name, with directories on top.</dd>
  968. <dd>Clicking the sort preference again will reverse the sort.</dd>
  969. <dd>Sorting preferences are also available in the Sidebar Header.</dd>
  970. <dd>Note that many server configurations don't report directory size, so when sorting by size, directories will be on top, sorted by name.</dd>
  971. </dl>
  972. <p class="border_top_x"><strong>3. UI PREFERENCES</strong><br />Selecting one of the sorting or preferences items will add the new preference setting to the URL query string, so that the setting will persist as you navigate within the same window, or if you bookmark the page.</p>
  973. <dl><dt>a. Light Theme/Dark Theme</dt> <dd>Change the UI theme.</dd></dl>
  974. <dl><dt>b. Alternate Backgrounds</dt> <dd>Alternate background colors for directory list items.</dd></dl>
  975. <dl><dt>c. Show Numbers</dt> <dd>Show numbers for directory list items.</dd></dl>
  976. <dl><dt>d. Use Custom Icons</dt> <dd>If enabled, use file and directory items provided by the script; if disabled, use the browser's default icons.</dd></dl>
  977. <dl><dt>e. Show Image Thumbnails</dt> <dd>Replaces the generic image file icon with a small thumbnail of the image itself. Enabling this setting may slow down page load, because each image file in the directory must be processed.</dd></dl>
  978. <dl><dt>f. Use Large Image Thumbnails</dt> <dd>If "Show Image Thumbnails" is enabled, the thumbnail enlarged.</dd></dl>
  979. <dl><dt>g. Always Show Image Thumbnails</dt> <dd>Image thumbnails are always shown, no matter how many images are in the directory. This overrides the default behavior which automatically disables thumbnail display for directories containing more than 2000 items in order to improve performance.</dd></dl>
  980. <dl><dt>h. Set UI Font</dt> <dd>Set a custom font for the UI.</dd></dl>
  981. <dl><dt>i. Scale UI</dt> <dd>Scale the entire UI (50%–150%). Double-click the label to quickly reset the scale to 100%.</dd></dl>
  982. <p class="border_top_x"><strong>4. FILE HANDLING PREFERENCES</strong></p>
  983. <dl><dt>a. Show/Hide Invisible Items</dt> <dd>It does what it says on the tin...</dd></dl>
  984. <dl><dt>b. Show/Hide Ignored Items</dt> <dd>Ignored items include files that the browser cannot handle natively (e.g., common Office and graphics files, various binary files, etc.). Hide them to reduce clutter.</dd>
  985. <dl><dt>c. Ignore Ignored Items</dt> <dd>Prevent normal browser behavior for handling such files, which is to open a download file dialog.</dd></dl>
  986. <dl><dt>d. Autoload Index Files</dt> <dd>Automatically load "index.html" or similar files in the Content Pane when the directory loads.</dd></dl>
  987. <p class="border_top_x"><strong>5. MEDIA PREFERENCES</strong></p>
  988. <dl><dt>a. Autoload Media</dt> <dd>If enabled, automatically load the first media file (audio or video) when the directory loads.</dd>
  989. <dd>For audio files, this will also automatically load any cover art (image file) found in the same directory. The script will first look for an image file with <i>exactly</i> the same name as the currently selected/playing audio file, followed in order by files containing the words cover”, front”, album”, jacket”, sleeve”, cd”, disc”, insert”, liner”, or notes.” If it finds no matching files, it will load the first image file it finds. Cover art will be automatically loaded whenever a new audio file is selected for playback.</dd></dl>
  990. <dl><dt>b. Autoplay Media</dt> <dd>If enabled, play the next media file when the currently playing media file ends.</dd></dl>
  991. <dl><dt>c. Play All Media Files</dt> <dd>If disabled (and Autoplay Media enabled), only play media of the same type (audio or video) as the currently playing media file.</dd></dl>
  992. <dl><dt>d. Loop Media Playback</dt> <dd>Loop media playback to the first media item when the last media item ends and continue playing. This option can also be enabled from the audio player.</dd></dl>
  993. <dl><dt>e. Shuffle Media Playback</dt> <dd>Randomize the order of media playback. This option can also be enabled from the audio player.</dd></dl>
  994. <p class="border_top_x"><strong>6. TEXT EDITING PREFERENCES</strong></p>
  995. <dl><dt>a. Text Editing Enabled/Disabled</dt><dd>If text editing is disabled, text files are displayed as normal files.</dd></dl>
  996. <dl><dt>b. Text Editing Options</dt><dd>Toggle the Text Editor. Select Editor UI theme: Default = same as main UI. Toggle split view. Select view of raw text, preview text, rendered HTML.</dd></dl>
  997. <dl class="border_top_x padding_top_1rem padding_bottom_1rem"><dt>7. DEFAULT PREFERENCES</dt><dd>Resets UI to defaults by removing manually set preferences from the URL query string.</dd></dl>
  998. <p class="border_top_x"><strong>8. PLAYLISTS</strong></p>
  999. <dl><dt>a. Open Playlist/Filelist</dt> <dd>Click to load a local .m3u file. See below for more details.</dd></dl>
  1000. <dl><dt>b. Make Playlist/Filelist</dt><dd>Save the files in the current sidebar directory as an .m3u playlist/filelist. Choose audio, video, all media, all non-media, all items, directories or files only.</dd></dl>
  1001. <dl class="border_top_x padding_top_1rem"><dt><strong>9. OPEN FONT FILE</strong></dt> <dd>Load a local font file to view information about the font and its complete glyph repertoire.</dd>
  1002. <dd>Glyph grids can be navigated with the arrow keys. Individual glyphs can be selected by clicking them or pressing <kbd>Return</kbd>.</dd><dd>Individual glyphs may be saved as .svg files.</dd></dl>
  1003. <dl class="border_top_x padding_top_1rem"><dt><strong>10. SCRIPT HOME</strong></dt> <dd><strong><a href="https://openuserjs.org/scripts/gaspar_schot/Supercharged_Local_Directory_File_Browser" class="link text_color_default" target="_blank">openuserjs.org</a></strong>.</dd>
  1004. <dl><dt><strong>11. HELP</strong></dt><dd>Show this help page.</dd></dl>
  1005. <dl><dt><strong>12. BUY ME A COFFEE</strong></dt><dd><strong><a id="donate_link" class="ignore_warning" href="https://www.buymeacoffee.com/fiLtliTFxQ" target="_blank" rel="noopener">Coding is a lot of work...</a></strong></dd></dl>
  1006. <dl><dt><strong>13. CONTACT</strong></dt><dd><strong><a id="contact_link" class="ignore_warning" href="mailto:mshroud@protonmail.com">Email</a></strong> me about anything to do with the script.</dd></dl>
  1007. </div>
  1008. <h2 id="other_functions" class="border_top_x padding_top_1rem"><strong>IV. OTHER SCRIPT FUNCTIONS</strong></h2>
  1009. <dl><dt>NAVIGATION</dt>
  1010. <dd>Use the up and down arrow keys to navigate items in the sidebar and previewed directories in the content pane.</dd>
  1011. <dd>Use the left and right arrow keys to navigate items of the same kind as the currently selected item.</dd>
  1012. <dd>Use the Tab key to toggle the focus between the sidebar and the content pane.</dd>
  1013. <dd>Type a letter or letters to navigate the directory by file name.</dd>
  1014. <dd>Type Cmd+Down-Arrow to navigate to the selected directory.</dd>
  1015. <dd>Click a directory icon in the sidebar or select it and type Cmd/Ctrl Right Arrow to open subdirectory; click again to close or type Cmd/Ctrl Left Arrow.</dd></dl><dl><dt>Images, Fonts, Font Glyphs</dt><dd>Previewed items can be scaled with <kbd>Cmd/Ctr +/&ndash;</kbd> keys.</dd></dl> <dl><dt>IMAGE AND FONT GRIDS</dt><dd>If a directory contains images and/or font files, the "Show Grid" icon will appear in the sidebar. Click it (or type <kbd>Cmd/Ctr+G</kbd>) to show a grid of the available items.</dd><dd>Grids can be navigated with the arrow keys, and individual grid items may be viewed by clicking them or pressing <kbd>Return</kbd>.</dd><dd>When a grid item is being viewed, the grid can still be navigated with the arrow keys.</dd><dd>Closing a selected grid item will show the grid again.</dd></dl>
  1016. <dl><dt>PLAYLISTS AND FILELISTS (m3u)</dt><dd>The script supports basic .m3u playlists containing links to audio or video files. It also has custom support for "filelists," which are standard .m3u files that contain links to <i>any</i> type of file or directory.</dd><dd>Note: if you change the extension of an ordinary .m3u file to .txt, the script will read it normally as an editable text file.<br />Double-clicking the selected file in the sidebar, or typing <code>Cmd/Ctr + Down Arrow</code> or <code>Cmd/Ctr + Return</code>, will open the playlist/filelist in the sidebar.<br />NOTE: The text must begin with #EXTM3U for this work.</dd></dl>
  1017. <dl><dt>CUE SHEETS (cue)</dt><dd>When a media file (audio or video) is loaded, the script will look for a .cue file in the same directory with <i>EXACTLY</i> the same name as the media file.</dd><dd>If it finds one, it will load the Track ID, the PERFORMER, the TITLE, and the INDEX (time position) into a menu next to the audio player; there is no support for other commands.</dd><dd>Tracks can be selected by clicking the item, and played or paused by clicking the selected item.</dd><dd>.cue files can also be selected independently in the sidebar and edited and saved (locally). This may be handy for creating "on the fly" bookmarks for a long media track before closing the page.</dd><dd>Note that you can also create and save (locally) a new .cue file by using the Text Editor.</dd><dd>Note (MacOS): If you prefer not to clutter the sidebar with .cue files, you may make them invisible by adding a dot to beginning of the file name; the script will still find them.</dd></dl>
  1018. <h2 id="troubleshooting" class="border_top_x padding_top_1rem"><strong>V. TROUBLESHOOTING</strong></h2>
  1019. <dl><dt>The script doesnt work with a specific directory.</dt><dd>If you have a javascript blocker installed in your browser (and if you don’t, you should), try disabling some of the site-specific scripts and XHR requests, as they may be interfering with the execution of this script.</dd><dd>Alternately, if you do have a javascript blocker installed, you may need to allow some scripts and XHR requests instead.</dd><dd>If the open directory still does not display correctly, check to see if cookies from the site are blocked.</dd><dd>Try deleting preferences from the Main Menu or removing the query string from the URL in the browser.</dd></dl>
  1020. <dl><dt>A specific item in a directory does not display correctly.</dt><dd>Confirm that the file is one that browser is capable of rendering. This script cannot display files that the browser itself cannot display.</dd><dd>If the item is from a playlist (m3u) and links to a remote site (e.g., archive.org), check your javascript blocker and cookies for any that need to be allowed from that site.</dd></dl>
  1021. <dl><dt>If you think you have found a bug, please <a class="ignore_warning" href="mailto:mshroud@protonmail.com"><i>contact me</i></a>.</dt></dl><p>&nbsp;</p></div>
  1022. </div>
  1023. </section>`;
  1024. let Utilities_Elements = function (body_id) {
  1025. let help_elements = '';
  1026. if (body_id === 'top_body') {
  1027. help_elements = `<aside id="help_container" class="background_grey_90 display_none">${ Utilities_Help }</aside>`;
  1028. }
  1029. return `<div id="utilities" class="position_absolute display_none position_LR_0 z_index_9999"> <aside id="warnings_container" class="overflow_hidden background_grey_90 hyphens_none z_index_9999">${ Utilities_Warnings }</aside> ${ help_elements } </div>`;
  1030. }
  1031. // ===> END UI HTML
  1032. //==============================//
  1033. // ===> STYLES
  1034. const background_images = `
  1035. /* BACKGROUND IMAGES & FILE ICONS */
  1036. .menu_item::before { content:""; width:12px; max-width:12px; min-width:12px; height:9px; margin:2px 0 -2px; background-position:center; background-repeat:no-repeat; display:flex; }
  1037. .submenu .menu_item::before { width:24px; max-width:24px; min-width:24px; }
  1038. .has_background, .has_background_before::before, .has_background_after::after { background-repeat:no-repeat; background-position:center; background-color:transparent !important; }
  1039. .bookmark > a::before { background-image:${ get_SVG_UI_Icon("bookmark") }; }
  1040. :is(.sort_by_default #menu_sort_by_default, .sort_by_name #menu_sort_by_name, .sort_by_duration #menu_sort_by_duration, .sort_by_size #menu_sort_by_size, .sort_by_date #menu_sort_by_date, .sort_by_kind #menu_sort_by_kind, .sort_by_ext #menu_sort_by_ext, #menu_theme_container, #toggle_text_editing) .menu_item::before, :is(.sort_by_default #sort_by_default, .sort_by_name #sort_by_name, .sort_by_duration #sort_by_duration, .sort_by_size #sort_by_size, .sort_by_date #sort_by_date, .sort_by_kind #sort_by_kind, .sort_by_ext #sort_by_ext) span::before, .loop_media #loop_media_menu::before, .shuffle_media #shuffle_media_menu::before, .background_color_check_mark::before, .texteditor_view_raw #toggle_texteditor_raw::before, .texteditor_view_preview #toggle_texteditor_preview::before, .texteditor_view_html #toggle_texteditor_html::before, body:not(.text_editing_enable_false) #text_editing_enable::before, .texteditor_view_html #texteditor_view_html::before, .cuesheet_track.selected .cue_track_id::before, .menu_item.checkmark::before { background-image:${ get_SVG_UI_Icon("check_mark") }; }
  1041. :is( .show_invisibles_false #show_invisible_items, .alternate_background_false #alternate_background, .show_numbers_false #show_numbers, .use_custom_icons_false #use_custom_icons, .show_image_thumbnails_false #show_image_thumbnails, .show_image_thumbnails_always_false #show_image_thumbnails_always, .show_large_image_thumbnails_false #show_large_image_thumbnails, .show_ignored_items_false #show_ignored_items, .ignore_ignored_items_false #ignore_ignored_items, .autoload_index_files_false #autoload_index_files, .media_autoload_false #media_autoload, .media_autoplay_false #media_autoplay, .media_play_all_false #media_play_all, .texteditor_split_view_false #texteditor_split_view ) .menu_item.checkmark::before
  1042. { background-image:none; }
  1043. .sort_by_default #sort_by_default span::after, .sort_by_name #sort_by_name span::after, .sort_by_duration #sort_by_duration span::after, .sort_by_size #sort_by_size span::after, .sort_by_date #sort_by_date span::after, .sort_by_kind #sort_by_kind span::after, .sort_by_ext #sort_by_ext span::after { background-image:${ get_SVG_UI_Icon("chevron") }; background-size:75%; transform:rotate(180deg); }
  1044. .is_error #dir_nav, .is_error #current_dir_path span::before { background-image:${ get_SVG_UI_Icon("error") }; }
  1045. .is_error #dir_nav { background-repeat:no-repeat; background-position:center top 6rem; background-size:6rem;}
  1046. .is_error #current_dir_path span::before { float:none; display:inline-flex; margin:0 0 -2px 0; width:24px; }
  1047. #content_pane[data-content="has_ignored"] #content_container { background-image:${ get_SVG_UI_File_Icon('file_icon_ignored') }; background-size:28px; }
  1048. #content_pane.has_audio[data-content="has_null"]:not([data-loaded="unloaded"]) #content_container, #content_pane.has_audio:not([data-content]) #content_container, .has_audio #content_pane[data-content="has_null"]:not([data-loaded="unloaded"]) #content_container, .has_audio #content_pane:not([data-content])[data-loaded="loaded"] #content_container
  1049. { background-image:${ get_SVG_UI_Icon("music") }; }
  1050. ${ CSS_UI_Icon_Rules() }
  1051. #dir_menu_main ul a::before { background-image:${ get_SVG_UI_File_Icon('file_icon_file') }; }
  1052. #dir_menu_main ul a[href^="file"]::before, #current_dir_path span::before { background-image:${ get_SVG_UI_File_Icon('file_icon_dir') }; margin-bottom:-3px; }
  1053. #dir_menu_main ul a[href^="http"]::before { background-image:${ get_SVG_UI_File_Icon('file_icon_htm') }; }
  1054. body.use_custom_icons_false .dir .has_icon_before_before { background-image:${ get_SVG_UI_File_Icon('file_icon_dir_default') }; background-size:auto 13px; }
  1055. body.use_custom_icons_false.show_image_thumbnails_false .file:not(.app) .has_icon_before_before, body.use_custom_icons_false:not(.show_image_thumbnails_false) .file:not(.app) .has_icon_before_before
  1056. { background-image:${ get_SVG_UI_File_Icon('file_icon_file_default') }; background-size:auto 13px; }
  1057. body:not(.use_custom_icons_false).show_image_thumbnails_false .image .has_icon_before_before { background-image:${ get_SVG_UI_File_Icon('file_icon_image') } }
  1058. .has_playlist #current_dir_path span::before { background-image:${get_SVG_UI_File_Icon('file_icon_playlist')}; display:inline-flex; margin:-2px 0 0; width:24px; vertical-align:middle;}
  1059. .dirlist_item.dir:not(.has_subdirectory) .has_icon_before_before:hover { background-image:${ get_SVG_UI_Icon('chevron') }; transform:rotate(90deg); filter:invert(1); }
  1060. .dirlist_item.dir.has_subdirectory .has_icon_before_before:hover { background-image:${ get_SVG_UI_Icon('chevron') }; transform:rotate(180deg); filter:invert(1); }
  1061. .dirlist_item.non_local .name_span span::before { background-image:${ get_SVG_UI_Icon('external_link') }; content:""; width:20px; min-width:20px; height:14px; margin-top:-3px; margin-bottom:-3px; background-position:left center; background-repeat:no-repeat; background-blend-mode:screen; display:inline-block; }
  1062. .dirlist_item.dir:is(.selected,:hover) a .has_icon_before_before, .dirlist_item.other:is(.selected,:hover) a .has_icon_before_before,
  1063. .dirlist_item.system:is(.selected,:hover) a .has_icon_before_before, .dirlist_item.bin:is(.selected,:hover) a .has_icon_before_before,
  1064. .dirlist_item.invisible:is(.selected,:hover) a .has_icon_before_before, .dirlist_item.markdown:is(.selected,:hover) a .has_icon_before_before
  1065. { filter:brightness(var(--brightness_low)); }
  1066. .theme_light .dirlist_item.audio:is(.selected,:hover) a .has_icon_before_before { filter:brightness(.66) contrast(1.66) saturate(2.66); mix-blend-mode:hard-light; }
  1067. .theme_dark .dirlist_item.audio:is(.selected,:hover) a .has_icon_before_before { filter:brightness(1.33); }
  1068. .dirlist_item.selected:is(.archive,.app) a .has_icon_before_before, .dirlist_item:is(.archive,.app):hover a .has_icon_before_before
  1069. { filter:brightness(var(--brightness_high)) saturate(6); }
  1070. .dirlist_item.non_local:is(.selected,.audio_loaded) .name_span span::before, .dirlist_item.non_local:hover .name_span span::before { filter:brightness(2); }
  1071.  
  1072. .dirlist_subdir_loading .has_icon_before_before { background-image:${ get_SVG_UI_Icon('spinner') } !important; filter:invert(1); background-size:20px; }
  1073. `;
  1074. const global_styles = `
  1075. :root { --font_size_small:0.875rem; color-scheme:none; --text_color_default:hsl(0,0%,var(--percent_10)); --text_color_selected:white; }
  1076. .theme_light {
  1077. --percent_100:100%; --percent_95:95%; --percent_90:90%; --percent_85:85%; --percent_80:80%; --percent_75:75%; --percent_70:70%; --percent_65:65%; --percent_60:60%; --percent_55:55%;
  1078. --percent_50:50%; --percent_45:45%; --percent_40:40%; --percent_35:35%; --percent_30:30%; --percent_25:25%; --percent_20:20%; --percent_15:15%; --percent_10:10%; --percent_05:05%; --percent_00:00%;
  1079. --border_lum:40%; --border_lum_inverted:40%; --brightness_low:1.15; --brightness_med:1.33; --brightness_high:1.875;
  1080. }
  1081. .theme_dark {
  1082. --percent_100:00%; --percent_95:05%; --percent_90:10%; --percent_85:15%; --percent_80:20%; --percent_75:25%; --percent_70:30%; --percent_65:35%; --percent_60:40%; --percent_55:45%;
  1083. --percent_50:50%; --percent_45:55%; --percent_40:60%; --percent_35:65%; --percent_30:70%; --percent_25:75%; --percent_20:80%; --percent_15:85%; --percent_10:90%; --percent_05:95%; --percent_00:100%;
  1084. --border_lum:05%; --border_lum_inverted:40%; --brightness_low:1.15; --brightness_med:1.5; --brightness_high:1.66;
  1085. }
  1086. :root, html, body { margin:0; padding:0; border:0; border-radius:0; overflow:hidden; display:flex; flex-direction:row; width:100%; height:100vh; font-family:${UI_Prefs_Non_Bool.ui_font}; font-size:${ UI_Prefs_Non_Bool.ui_font_size}; hyphens:auto; transform-origin:0 0; }
  1087. a, a:hover { color:inherit; font-weight:inherit; text-decoration:none !important; }
  1088. ul, li { list-style:none; }
  1089. svg { margin:auto; }
  1090. .selected, .audio_loaded { --background_opacity:1; } :hover, .hovered { --background_opacity:0.75; }
  1091. .focus_content #dir_wrapper .selected, .focus_content #dir_wrapper .audio_loaded { --background_opacity:0.50; }
  1092. .focus_content #dir_wrapper :hover, .focus_content #dir_wrapper .hovered { --background_opacity:0.25; }
  1093. .align_left { text-align:left; } .center { text-align:center; } .align_right { text-align:right; } .align_justify { text-align:justify; text-justify:inter-character; hyphens:auto; }
  1094. .background_grey_60 { background-color:hsl(0,0%,var(--percent_60)); } .background_grey_65 { background-color:hsl(0,0%,var(--percent_65)); }
  1095. .background_grey_70 { background-color:hsl(0,0%,var(--percent_70)); } .background_grey_75, body { background-color:hsl(0,0%,var(--percent_75)); }
  1096. .background_grey_80 { background-color:hsl(0,0%,var(--percent_80)); }
  1097. .background_grey_85, .dirlist_item:nth-of-type(odd), .cuesheet_track:not(.header):nth-of-type(odd), #utilities_help li:nth-of-type(even), body.alternate_background_false .dirlist_item:nth-of-type(even)
  1098. { background-color:hsl(0,0%,var(--percent_85)); }
  1099. .background_grey_90, .dirlist_item:nth-of-type(even), .cuesheet_track:not(.header):nth-of-type(even), #stats li:nth-of-type(even) { background-color:hsl(0,0%,var(--percent_90)); }
  1100. .background_grey_95, .background_grey_90:hover, .background_grey_90.hovered, .background_grey_90.selected, .background_grey_90:focus { background-color:hsl(0,0%,var(--percent_95)); }
  1101. .background_grey_100, .background_grey_95:hover, .background_grey_95.hovered, .background_grey_95.selected { background-color:hsl(0,0%,var(--percent_100)); }
  1102. ${ background_images }
  1103. .border_0 { border: none; } .border_all { border: solid 1px hsl(0,0%,var(--border_lum)); }
  1104. .border_top { border-top: solid 1px hsl(0,0%,var(--border_lum)); } .border_right { border-right: solid 1px hsl(0,0%,var(--border_lum)); }
  1105. .border_bottom { border-bottom: solid 1px hsl(0,0%,var(--border_lum)); } .border_left { border-left: solid 1px hsl(0,0%,var(--border_lum)); }
  1106. .border_top_x { border-top: solid 1px hsl(0,0%,var(--border_lum_inverted)); } .border_right_x { border-right: solid 1px hsl(0,0%,var(--border_lum_inverted)); } /* "x" = inverted for theme_dark */
  1107. .border_bottom_x { border-bottom: solid 1px hsl(0,0%,var(--border_lum_inverted)); } .border_left_x { border-left: solid 1px hsl(0,0%,var(--border_lum_inverted)); }
  1108. .box_shadow_menu { box-shadow:0px 4px 6px -3px #000; }
  1109. .display_grid, .info_list:hover li, .has_flyout_menu:hover ul { display:grid; }
  1110. .display_none, .error_display_none { display:none; } .display_block { display:block; } .display_flex { display:flex; } .display_inline_flex { display:inline-flex; } .flex_column { flex-direction:column; } flex-direction:column; } .flex_row { flex-direction:row; }
  1111. .flex_justify_center { display:flex; flex-direction:column; justify-content:center; flex-grow:1; align-items:center; align-self:stretch; text-align:center; }
  1112. .flex_justify_center_row { display:flex; flex-direction:row; justify-content:center; flex-grow:1; align-items:center; }
  1113. .flex_justify_contents { justify-content:space-between; }
  1114. .flex_grow_1 { flex-grow:1; }
  1115. .font_size_small { font-size:var(--font_size_small); }
  1116. .has_flyout_menu { outline:none; justify-content:center; align-content:center; }
  1117. .has_flyout_menu ul li { width:100%; margin:0; padding:4px 6px; text-align:right; box-sizing:border-box; white-space:pre; grid-column:1; }
  1118. .has_flyout_menu ul div { grid-column:2; padding-top:8px; }
  1119. .has_flyout_menu .item_1 { grid-row:1; } .has_flyout_menu .item_2 { grid-row:2; }
  1120. .height_100 { height:100%; }
  1121. .hyphens_none { hyphens:none; }
  1122. .info_list { background-color:hsl(0,0%,var(--percent_80)); color:hsl(0,0%,var(--percent_10)); }
  1123. .info_list li { grid-template-columns:minmax(33%,100%) min(66%); border-top:solid 1px hsl(0,0%,var(--border_lum)); }
  1124. .info_list li.info_list_header { border-top:none; }
  1125. .info_list li .col_1 { font-weight:bold; text-align:right; border-right:solid 1px hsl(0,0%,var(--border_lum)); }
  1126. .info_list span { display:inline-block; padding:4px 6px; }
  1127. .line_height_1 { line-height:1; } .line_height_1_2, .info_list span { line-height:1.2; } .line_height_1_4 { line-height:1.4; }
  1128. .margin_0, header, footer, nav, ol, ul, li { margin:0; }
  1129. .media.local input { cursor:not-allowed; }
  1130. .normal { font-weight:normal; }
  1131. .overflow_auto { overflow:auto; } .overflow_hidden { overflow:hidden; } .overflow_visible { overflow:visible; } .overflow_x_hidden { overflow-x:hidden; }
  1132. .padding_0, header, footer, nav, a, ol, ul, li { padding:0; }
  1133. .padding_4_6 { padding:4px 6px; } .padding_4_8 { padding:4px 8px; } .padding_6_8 { padding:6px 8px; } .padding_top_1rem { padding-top:1rem; } .padding_bottom_1rem { padding-bottom:1rem; }
  1134. .pointer, label, input { cursor:pointer; } .cursor_default { cursor:default; }
  1135. input[disabled], input[disabled] + label { opacity:0.66; }
  1136. div:has(> input[disabled]), input[disabled], input[disabled] + label { cursor:not-allowed; }
  1137. .position_absolute { position:absolute; } .position_relative { position:relative; } .position_fixed { position:fixed; } .position_0 { top:0; right:0; bottom:0; left:0; } .position_LR_0 { left:0; right:0; }
  1138. .resize_none { resize:none; }
  1139. .theme_dark .invert { filter:invert(1); }
  1140. .transform_rotate_90, .transform_rotate_90_contents > * { transform:rotate(90deg); }
  1141. .transform_rotate_180, .transform_rotate_180_contents > * { transform:rotate(180deg); }
  1142. .transform_rotate_270, .transform_rotate_270_contents > * { transform:rotate(270deg); }
  1143. .whitespace_pre { white-space:pre; }
  1144. .width_10px, .width_10px_contents > * { width:10px; max-width:10px; min-width:10px; } .width_12px, .width_12px_contents > * { width:12px; max-width:12px; min-width:12px; }
  1145. .width_14px, .width_14px_contents > * { width:14px; max-width:14px; min-width:14px; } .width_16px, .width_16px_contents > * { width:16px; max-width:16px; min-width:16px; }
  1146. .width_18px, .width_18px_contents > * { width:18px; max-width:18px; min-width:18px; } .width_24px, .width_24px_contents > * { width:24px; max-width:24px; min-width:24px; }
  1147. .width_100 { width:100% !important; }
  1148. .z_index_1 { z-index:1; } .z_index_2 { z-index:2; } .z_index_3 { z-index:3; } .z_index_9997 { z-index:9997; } .z_index_9998 { z-index:9998; } .z_index_9999 { z-index:9999; }
  1149.  
  1150. /* HIGHLIGHT COLORS: selected & hovered media and non_media items */
  1151. .theme_light {
  1152. --non_media_item_background_h:216deg; --non_media_item_background_s:100%; --non_media_item_background_l:50%; --non_media_item_background_a:0.8;
  1153. --media_item_background_h:180deg; --media_item_background_s:100%; --media_item_background_l:33%; --media_item_background_a:1;
  1154. --texteditor_item_background_h:250deg; --texteditor_item_background_s:66%; --texteditor_item_background_l:66%; --texteditor_item_background_a:1.00;
  1155. }
  1156. .theme_dark {
  1157. --non_media_item_background_h:216deg; --non_media_item_background_s:80%; --non_media_item_background_l:60%; --non_media_item_background_a:0.8;
  1158. --media_item_background_h:180deg; --media_item_background_s:50%; --media_item_background_l:40%; --media_item_background_a:1;
  1159. --texteditor_item_background_h:250deg; --texteditor_item_background_s:50%; --texteditor_item_background_l:60%; --texteditor_item_background_a:1.00;
  1160. }
  1161. li, div {
  1162. --non_media_background: hsla(var(--non_media_item_background_h), var(--non_media_item_background_s), var(--non_media_item_background_l), var(--non_media_item_background_a));
  1163. --media_background: hsla(var(--media_item_background_h), var(--media_item_background_s), var(--media_item_background_l), var(--media_item_background_a));
  1164. --texteditor_item_background: hsla(var(--texteditor_item_background_h), var(--texteditor_item_background_s), var(--texteditor_item_background_l), var(--texteditor_item_background_a))
  1165. }
  1166. /* NON-MEDIA ITEMS BACKGROUND , li:not(.media):not(.no_highlight):hover, li.hovered */
  1167. li.selected:not(.media), li:not(.media):not(.no_highlight):hover, li.hovered, li.content_loaded { background-color:var(--non_media_background) !important; } /* all selected items, hovered non-dirlist items */
  1168. #dir_nav li:not(.media):hover { --non_media_item_background_a:0.5; background-color:var(--non_media_background); } /* hovered dirlist items */
  1169. li.grid_item.selected { --non_media_item_background_a:0.75; background-color:var(--non_media_background); } /* selected grid items */
  1170. li.grid_item:hover, li.grid_item.hovered { --non_media_item_background_a:0.40; background-color:var(--non_media_background); } /* hovered grid items */
  1171. body.no_hover li.grid_item:is(:not(.selected):hover,.hovered), body.no_hover li.grid_item:is(:not(.selected):hover,.hovered) * { background-color:transparent !important; color:inherit !important; }
  1172. /* MEDIA ITEMS BACKGROUND */
  1173. li.audio_loaded, li.video.selected { background-color:var(--media_background) !important; } /* loaded audio, selected video */
  1174. li.selected.audio { --media_item_background_a:0.80; background-color:var(--media_background) !important; } /* selected audio */
  1175. li.media:hover { --media_item_background_a:0.60; background-color:var(--media_background) !important; } /* hovered media */
  1176. li.selected + li.selected:nth-of-type(even), li.dir.hovered + li.hovered:nth-of-type(even), li.file.hovered + li.hovered:nth-of-type(odd), .info_list li:nth-of-type(even) { --non_media_item_background_a:0.60; } /* alternate highlight background with multiple selections, show stats*/
  1177. /* UNHIGHLIGHTED ITEMS: menu visible, .focus_content, .no_hover */
  1178. body[class*="has_menu"] #dir_nav, body.focus_content #dir_nav { --non_media_item_background_s:0%; --media_item_background_s:0%; }
  1179. body.theme_light[class*="has_menu"] #dir_nav, body.focus_content #dir_nav { --media_item_background_l:50%; --non_media_item_background_l:50%; }
  1180. body.theme_dark[class*="has_menu"] #dir_nav, body.focus_content #dir_nav { --media_item_background_l:40%; --non_media_item_background_l:30%; }
  1181. body.no_hover #dir_nav li:nth-of-type(even):not(.selected):hover { background-color:hsl(0,0%,var(--percent_80)) !important; }
  1182. body.no_hover #dir_nav li:nth-of-type(odd):not(.selected):hover { background-color:hsl(0,0%,var(--percent_85)) !important; }
  1183. body.no_hover #dir_nav li:not(.selected):hover { color:unset !important; }
  1184.  
  1185. /* TEXTEDITOR ITEM*/
  1186. body:is(.has_texteditor,.texteditor_edited) #show_texteditor li { background-color:var(--texteditor_item_background); }
  1187. #show_texteditor li:hover { --texteditor_item_background_a:0.7; background-color:var(--texteditor_item_background) !important; }
  1188.  
  1189. /* text color */
  1190. li:is(.selected,:hover,.hovered), li:hover li:is(:hover,.selected), li.hovered li.selected, .content_loaded, .audio_loaded, body.has_texteditor #show_texteditor, body.texteditor_edited #show_texteditor,
  1191. .grid_item:is(.selected,:hover,.hovered), .grid_item:is(.selected,:hover,.hovered) *, .grid_item.selected::before, .grid_item.selected::after { color:var(--text_color_selected) !important; } /* white */
  1192. li:is(.selected,:hover,.hovered) li, .text_color_default, .no_highlight, .no_highlight:hover, .no_highlight > li:hover, :hover:not(#svg_container) > svg, .font_glyph_item::before, .font_glyph_item::after, #font_specimen_viewer::before, .has_font_specimen_glyph #font_specimen_viewer::after, #font_file_glyph_viewer::before, #font_file_glyph_viewer::after { color:hsl(0,0%,var(--percent_10)) !important; } /* default */
  1193.  
  1194. /* font weight */
  1195. li:hover li, li.hovered li, li.selected li, body.no_hover li:hover, li:not(.grid_item).no_hover:hover { font-weight:normal !important; }
  1196. .bold, li:not(.grid_item):hover, li.hovered, li.hovered li:is(:hover,.selected), li:not(.grid_item).selected, li.selected li:hover, li.media[class*="_loaded"], #show_image_grid:hover, #show_font_grid:hover, dt
  1197. { font-weight:bold !important; }
  1198. #content_pane[data-content="has_ignored"]::before { opacity:0.3; }
  1199. .has_warning #dir_wrapper, .has_warning #content_pane, .focus_content .dirlist_item, body:is(.has_menu,.has_menu_parents,.has_menu_stats,.has_menu_grid.has_images.has_fonts) .dirlist_item:not(.hovered), body:is(.has_menu,.has_menu_parents,.has_menu_stats,.has_menu_grid.has_images.has_fonts) #content_pane, #dir_menu_parent:not(:hover), #dir_menu_main_container:not(:hover) nav, #show_grid_btn, #dir_footer_utilities, .split_btn span, .disabled:not(.local) { opacity:0.75; }
  1200. body.has_menu_footer .dirlist_item.hovered, .disabled:not(.local).selected { opacity:0.84; }
  1201. #show_grid_btn:hover, #prev_next_btns span:hover, #dir_footer_utilities:hover, .split_btn span:hover { opacity:1.0; }
  1202. `;
  1203. const utilities_styles = `
  1204. #utilities { top:0; justify-content:center; }
  1205. #warnings_container { width:26em; flex-direction:column; border-radius:0 0 3px 3px; box-shadow:0px 2px 12px #333; font-size:0.875em; color:#111; display:none; }
  1206. #warnings_header { padding:1rem 1.5rem; background-position:left 1.25rem center; background-repeat:no-repeat; background-size:24px; }
  1207. #warnings_container:not(.warning_make_playlist) #warnings_header { background-image:${ get_SVG_UI_Icon("error") }; }
  1208. #warnings_header h3 { text-indent:2.25em; }
  1209. #warnings_container:not(.warning_make_playlist) h3#warning_header, #warnings_container.warning_make_playlist h3#make_playlist_header, .warning_button.show, #warnings div.show, .has_warning #utilities, .has_warning #warnings_container, .has_help #utilities, .has_help #help_container { display:flex;}
  1210. #warnings .warning { padding:0 1.5rem 1rem; display:none; }
  1211. #warning_buttons_container { padding:1rem 1.5rem; }
  1212. button.focus, button:focus { background-color:#0E4399; color:#EEE; outline:none; }
  1213. .warning_button { min-width:4em; display:none; font-size:1em; justify-content:center; }
  1214. #warnings_container.warning_local_file #warning_local_file, #warning_btn_ok { margin-left:auto; }
  1215. #warning_btn_cancel + #warning_btn_save, #warning_btn_dont_save + #warning_btn_cancel, #warning_btn_clear { margin-right:auto; }
  1216. #warning_btn_cancel, #warning_btn_clear, #warning_btn_save { margin-left:0.5rem; }
  1217. #warnings_container.clear #warning_buttons { justify-content:space-between; }
  1218. #warning_make_playlist fieldset div { padding:0 0 2px; }
  1219. #warning_make_playlist .indent { text-indent:2em; }
  1220. #warning_make_playlist input { margin-right:6px; }
  1221. #warnings_container.warning_local_playlist #warning_local_playlist, #warnings_container.warning_local_playlist #warning_btn_ok { display:inline-block; margin-left:auto; }
  1222. .has_warning::before, .has_overlay::before { content:""; position:fixed; top:0; right:0; bottom:0; left:0; z-index:9998;-webkit-user-select:none;-moz-user-select:none; user-select:none; }
  1223.  
  1224. #help_container { padding:0 1em 1em; overflow:auto; } #help_container > header { grid-template-columns:5em auto fit-content(100%); } #help_container > section { padding-top:2rem; }
  1225. #help_container > section > div { margin-top:1rem; padding-top:1rem; } #help_container dd { margin-inline-start:1em; } #help_container dd:before { content:"∙"; margin-right:6px; }
  1226. #help_container dl + p { margin-top:1rem; padding-top:1rem; } #help_container ol li { list-style:decimal; }
  1227. #help_container kbd { min-width:1em; height:fit-content; padding:2px 6px; display:inline-block; border:solid 1px #888; border-radius:3px; text-align:center; font-family:inherit; font-size:0.875em; background-color:hsl(0,0%,var(--percent_90)); }
  1228. #help_bookmarks::before { background-image: ${ get_SVG_UI_Icon("bookmark") }; }
  1229. .has_help #utilities, .has_help #help_container { bottom:0; }
  1230. `;
  1231. const dir_header_menu_styles = `
  1232. /* PARENTS MENU */
  1233. #parent_dir_nav #svg_chevron { width:18px; } #parent_dir_nav #svg_multiply { width:14px; }
  1234. #parent_dir_nav #svg_multiply, body:is(.has_playlist,.has_filelist) #svg_chevron, body:is(:not(.has_playlist),:not(.has_filelist)) #dir_header #close_playlist_container { display:none; }
  1235. body.has_playlist #parent_dir_nav #svg_multiply, body.has_filelist #parent_dir_nav #svg_multiply, body:is(.has_playlist,.has_filelist) #dir_header #close_playlist_container { display:flex; }
  1236. #current_dir_path { padding:3px 6px; word-break:break-word; }
  1237. /* MAIN MENU */
  1238. #dir_menu_main li { display:flex; }
  1239. #dir_menu_main li.has_submenu.selected .submenu { display:block; }
  1240. #dir_menu_main li.has_submenu { position:relative; justify-content:space-between; }
  1241. #dir_menu_main li.bookmark a::before { content:""; width:24px; max-width:24px; min-width:24px; height:12px; background-size:12px; }
  1242. .submenu { width:100%; max-width:240px; display:none; margin:0; padding:0; position:absolute; top:-1px !important; left:100%; right:0; }
  1243. #dir_menu_main ul.submenu li a { padding:6px 8px 6px 0; }
  1244. #dir_menu_main input { width:0; float:left; }
  1245. .menu_item { margin:0; padding:5px 8px 5px 0; display:flex; flex-grow:1; text-align:left; }
  1246. #dir_menu_main .selected ~ li:hover .submenu, #dir_menu_main .selected ~ li .submenu:hover, .has_open, #dir_menu_main .show_input span.menu_item { display:none; }
  1247. #dir_menu_main .show_input input { display:unset; margin:2px 6px; width:100%; }
  1248. #dir_menu_main svg { margin: 0 6px; width:12px; } #dir_menu_main li.selected svg, #dir_menu_main li:hover svg, #dir_menu_main li.hovered svg { filter:invert(1); }
  1249. #ui_scale span.menu_item::after { content:attr(data-value); } #ui_scale_input_container, #ui_scale.show_input span + span { display:flex; } #ui_scale_input_container { padding-left:18px; padding-right:8px; }
  1250. /* IFRAME MENUS */
  1251. #parent { padding:5px 3px 5px 0; }
  1252. #parent span { padding:0px 1px; }
  1253. #open_in_sidebar { padding:5px 2px 5px 3px; }
  1254. `;
  1255. const dir_header_styles = ` /* for both sidebar and content_iframe */
  1256. #dir_wrapper { font-variant-numeric:tabular-nums; } #dir_wrapper.top_body { min-width:200px; } #dir_wrapper.iframe { min-width:500px; flex-basis:100%; }
  1257. #dir_header { user-select:none; -webkit-user-select:none; }
  1258. .dir_header_title_div { letter-spacing:0.5em; text-indent:0.75em; flex-basis:100%; }
  1259. .dir_header_title_div:before { content:"INDEX OF"; } .has_playlist .dir_header_title_div:before { content:"PLAYLIST"; } .has_filelist .dir_header_title_div:before { content:"FILELIST"; }
  1260. ${ dir_header_menu_styles }
  1261. /* SIDEBAR BUTTONS */
  1262. #directory_buttons_left { padding:6px; }
  1263. #show_details { margin-top:0; margin-right:8px; padding:0 4px; }
  1264. #show::before { content:"Show "; }
  1265. /* GRID BTN ---> combine style with save_btn */
  1266. #show_grid_btn { margin:0 0 0 auto; }
  1267. #show_grid_btn ul { display:none; padding-left:0px; top:-1px; right:-1px; }
  1268. #show_grid_btn ul:after { content:""; position:absolute; z-index:-1; top:0; bottom:0; left:0; right:0; background-color:hsl(0,0%,var(--percent_80)); }
  1269. #show_grid_btn ul:not(:has(li:hover)):hover { background-color:var(--non_media_background); }
  1270. #show_grid_btn ul:not(:has(li:hover)):hover svg { color:white !important; }
  1271. #show_grid_btn.has_grid div { color:#118888; }
  1272. #top_body:is(.has_images,.has_fonts) #show_grid_btn { display:flex; }
  1273. #top_body.has_images.has_fonts #show_grid_btn:hover ul { display:grid; }
  1274. /* SORTING ITEMS */
  1275. #sorting .sorting { grid-row:1; }
  1276. body:not(.show_details_false) #sorting_row_2 { display:grid; }
  1277. #sorting_row_1 span, #sorting_row_2 span, .sorting span::before, .sorting span::after { display:inline-block; }
  1278. #sorting_row_1 span, #sorting_row_2 span { padding:6px 0; }
  1279. #sorting_row_1.iframe span, #sorting_row_2.iframe span { padding:4px 0; }
  1280. #sorting span::before, #sorting span::after, .sorting .menu_item::after { content:""; width:16px; height:8px; color:#CCC; background-position:center; background-repeat:no-repeat; background-size:10px; }
  1281. .sorting.down span::after, .sort_direction_descending .sorting span::after { transform:rotate(0deg) !important; }
  1282. #sort_by_name input { margin:-2px 6px -2px 0; bottom:-2px; }
  1283. #sort_by_ext { grid-column: span 2; }
  1284. .has_media #sort_by_ext { grid-column: span 1; }
  1285. .has_media #sort_by_default { text-align:center; }
  1286. #sort_by_default.iframe, .iframe #sort_by_size, .iframe #sort_by_date { text-align:right; }
  1287. .has_media #sort_by_duration, .has_playlist #sort_by_duration, #content_body.has_media #sorting_row_2 #sort_by_duration { display:unset; }
  1288. #content_body #sorting_row_1 #sort_by_duration, #top_body #sorting_row_2 #sort_by_duration { display:none; }
  1289. /* TEXT EDITOR ITEM */
  1290. body:not(.show_details_false) #show_texteditor, body.has_texteditor #show_texteditor { display:flex; }
  1291. #show_texteditor a { padding-left:10px; }
  1292. `;
  1293. const dir_nav_styles = ` /* for both sidebar and content dirlists */
  1294. #dir_nav { overflow-y:hidden; flex-basis:100%; }
  1295. #dir_nav_inner { overflow:auto; margin-bottom:-1px; }
  1296. #dir_nav ol { -webkit-margin-before:0em !important; -webkit-margin-after:0em !important; -webkit-padding-start:0em; }
  1297. #directory_list { counter-reset:item; transition:opacity .125s; }
  1298. #directory_list:empty { border-bottom:0; padding:100%; }
  1299. .dirlist_item_input, .dirlist_item_details, .dirlist_item_details span, .dirlist_item_media_duration, .details.ext, .dirlist_item.error::before, .dirlist_item_name_a::before,
  1300. body.show_invisibles_false:not(.has_menu_stats) .dirlist_item.invisible.ignored, body.show_invisibles_false:not(.show_ignored_false):not(.has_menu_stats) .dirlist_item.invisible:not(.ignored),
  1301. body.show_invisibles_false.show_ignored_items_false:not(.has_menu_stats) .dirlist_item.ignored, body.show_invisibles_false.show_ignored_items_false:not(.has_menu_stats) .dirlist_item.invisible,
  1302. body.show_ignored_items_false:not(.show_invisibles_false):not(.has_menu_stats) .dirlist_item.ignored:not(.invisible) { display:none; }
  1303. .dirlist_item { margin-inline-start:0; display:grid; grid-gap:0; }
  1304. .top_item { grid-template-columns:minmax(8rem,auto) minmax(6em,1fr) minmax(auto,6em); }
  1305. .dirlist_item_name { grid-row:1; display:flex; -webkit-padding-start:0; -moz-padding-start:0; word-break:break-word; }
  1306. .top_item .dirlist_item_name { grid-column:1 / span 3; padding:6px 12px 6px 0; }
  1307. .dirlist_item_name::before { counter-increment:item; content:counter(item); min-width:36px; height:14px; max-height:14px; min-height:14px; text-align:right; padding:0 3px 0 0; text-indent:6px; }
  1308. .dirlist_item_input { margin:1px 6px 0 0; max-height:13px; }
  1309. .dirlist_item .desc.dirlist_item_details { padding:0 6px 4px 40px; grid-column:1 / span 3; text-align:left; white-space:unset; }
  1310. .has_icon_before::before, .has_icon_before_before { content:""; display:inline-block; background-position:center; background-repeat:no-repeat; background-size:14px,0px; }
  1311. .has_icon_before::before, .has_icon_before_before, .show_large_image_thumbnails_false .dirlist_item.image .has_icon_before_before, .show_image_thumbnails_false .dirlist_item.image .has_icon_before_before
  1312. { width:14px; height:14px; max-width:20px; max-height:14px; min-width:14px; min-height:14px; margin:0 6px 0 6px; }
  1313. .dirlist_item.image .has_icon_before_before { width:56px; height:56px; max-width:56px; max-height:56px; min-width:56px; min-height:56px; margin:0 6px; background-position:top; background-size:contain,0px; }
  1314. .ignored:not(.selected) .has_icon_before::before, .ignored:not(.selected) .has_icon_before_before, .focus_content .has_icon_before_before, .has_quicklook #dir_wrapper { filter:grayscale(100%); }
  1315. /* MEDIA ITEMS */
  1316. .top_item.media .dirlist_item_name { grid-column:1 / span 2; padding-right:0; }
  1317. .top_item.media .dirlist_item_media_duration { grid-column:3; padding:6px 12px 6px 0; }
  1318. .dirlist_item.media .dirlist_item_media_duration { grid-row:1; }
  1319. .iframe_item.media .dirlist_item_media_duration { grid-column:2; }
  1320. .media:not(.local) .dirlist_item_media_duration { display:unset; }
  1321. .dirlist_item.media .dirlist_item_media_duration:empty { background-image:${ get_SVG_UI_Icon('spinner') } !important; background-position:top 3px right 10px; background-repeat:no-repeat; background-size:20px; }
  1322. .theme_dark .dirlist_item_media_duration:empty { filter:invert(1); }
  1323. /* SORTING BORDERS */
  1324. .sort_by_default:not(.show_invisibles_false) .dir.invisible + .dir:not(.invisible), .sort_by_default:not(.show_invisibles_false) .dir:not(.invisible) + .dir.invisible { border-top:solid 1px hsl(0,0%,var(--border_lum)); }
  1325. /* ITEM DETAILS */
  1326. .dirlist_item_details { text-align:right; white-space:nowrap; }
  1327. .top_item .dirlist_item_details { padding:0 12px 4px 0; }
  1328. .dirlist_item_details.size { padding-left:12px; }
  1329. .dirlist_item_details.date { padding-bottom:0; height:1em; max-height:1em; overflow-wrap:break-word; }
  1330. .dirlist_item_details.kind::first-letter { text-transform:uppercase; }
  1331. #content_body .iframe_item { grid-template-columns: minmax(20em,100%) minmax(4em,6em) minmax(6em,8em) minmax(6em,14em) minmax(6em,8em); }
  1332. #content_body .iframe_item.non_media .dirlist_item_name { grid-column:1 / span 2; }
  1333. #content_body .iframe_item .dirlist_item_details { grid-row:1; height:1ex; }
  1334. #content_body .iframe_item .desc.dirlist_item_details { grid-row:2; grid-column:1 / span 6; height:auto; padding:0 6px 4px 40px; }
  1335. #content_body .iframe_item .dirlist_item_name_a, #content_body .iframe_item > span { padding:5px 16px 5px 0; }
  1336.  
  1337.  
  1338. body:not(.show_numbers_false) .dirlist_item_name_a::before { display:initial; }
  1339. body:not(.show_details_false) .dirlist_item_details, .media .dirlist_item_input { display:unset; }
  1340. .disabled, .ignore_ignored_items li.ignored, .has_filelist [id$="sort_by_size"], .has_playlist [id$="sort_by_size"], .has_filelist [id$="sort_by_date"], .has_playlist [id$="sort_by_date"]
  1341. { cursor:not-allowed; opacity:0.75; }
  1342. .dirlist_item.error { display:block; padding:6px 8px; }
  1343. .dirlist_item.ignored.local .dirlist_item_name_a::after { content:"\\00a0[local file]"; display:contents; font-style:italic; }
  1344. .is_error #is_error { display:block !important; grid:none !important; grid-template-columns:none !important; }
  1345. .is_error #is_error_items { display:block; }
  1346.  
  1347. `;
  1348. const iframe_dir_styles = `${ global_styles }
  1349. #content_body { overflow-x:auto; font-size:${ (parseFloat(UI_Prefs_Non_Bool.ui_font_size) * 0.875) + UI_Prefs_Non_Bool.ui_font_size.replace(/\d*/,'') }; }
  1350. .theme_dark .sorting span::before, .theme_dark .sorting span::after { filter:invert(1); }
  1351. #content_body:not(.show_details_false) #show::before { content:"Hide "; }
  1352. #content_body.show_details_false .iframe_item { grid-template-columns:auto; }
  1353. #content_body.show_details_false .media .dirlist_item_media_duration { display:none; }
  1354. #content_body #content_pane,#content_body .content_el { display:none; }
  1355. #content_body.has_quicklook #dir_nav { opacity:0.8; }
  1356. #content_body.has_quicklook #content_pane { display:flex; padding:2em; position:absolute; z-index:1; left:0; right:0; top:0; bottom:0; justify-content:center; }
  1357. #content_body.has_quicklook #content_header { padding: 0; background-color:hsl(0,0%,var(--percent_85)); border-radius: 3px 3px 0 0; border:solid 1px hsl(0,0%,var(--border_lum)); border-bottom:0; }
  1358. #content_body.has_quicklook #content_title { padding:4px 6px 0; }
  1359. #content_body.has_quicklook #content_title_container { border-bottom:0; }
  1360. #content_body.has_quicklook #content_container { padding:6px; background-color:hsl(0,0%,var(--percent_85)); box-shadow:0 0 12px #111; border-radius: 0 0 3px 3px; border:solid 1px hsl(0,0%,var(--border_lum)); border-top:0; contain:unset; flex-basis:unset; }
  1361. #content_body.has_quicklook .content_el { width:100%; }
  1362. #content_body.has_quicklook .content_el.has_content { border:solid 1px hsl(0,0%,var(--border_lum)); }
  1363. #content_body.has_quicklook .content_el.has_content,#content_body.has_quicklook .content_el:has(.has_content) { display:flex; z-index:1; }
  1364. #content_body.has_quicklook #content_container:has(#content_font.has_content, #content_pdf.has_content,#content_iframe.has_content),#content_body.has_quicklook #content_pane[data-content="has_ignored"] #content_container
  1365. { height:50%; flex-basis:unset; }
  1366. #content_body.has_quicklook #content_container:has(#content_image.has_content) { display:table; flex-basis:unset; }
  1367. #content_body.has_quicklook #content_video.has_content { position:static; }
  1368. #content_body.has_quicklook div[id^="title_buttons"], #content_body.has_quicklook #content_pane.has_audio :is(#content_title_container,#content_container), #content_body.has_quicklook #content_pane[data-content="has_ignored"] #content_iframe, #content_body.has_quicklook #content_pane[data-content="has_pdf"] #content_pdf
  1369. { display:none; }
  1370. #content_body.has_quicklook #content_pane:not([data-content="has_ignored"]) #content_font.has_content { display:grid; }
  1371. #content_body.has_quicklook #content_pane[class*="has_font_specimen"] #font_specimen_viewer { display:flex; }
  1372. #content_body.has_quicklook #content_image_container, #content_body.has_quicklook #content_iframe { max-height:88vh; }
  1373. #content_header, #content_body.has_quicklook #content_image_container, #content_body.has_quicklook #content_container:has(#content_video.has_content) { padding:0; }
  1374. #content_pane[data-content="has_pdf"] #content_container { background-image:${ get_SVG_UI_File_Icon('file_icon_ignored') }; background-size:28px; }
  1375. `;
  1376. const dir_footer_styles = ` /* for both sidebar and content_iframe */
  1377. .has_menu_stats #stats_summary, .stats_kind span.file, .stats_kind span.media, #top_body.no_hover #dir_footer_utilities { display:none; }
  1378. #dir_footer { user-select:none; -webkit-user-select:none; }
  1379. #stats_container { max-height:33vh; }
  1380. .theme_light #dir_footer_utilities:hover ul, .theme_light #dir_footer:hover, .theme_light #stats_details_summary { box-shadow:0px -4px 4px 0px rgba(128,128,128,0.6); }
  1381. .theme_dark #dir_footer_utilities:hover ul, .theme_dark #dir_footer:hover, .theme_dark #stats_details_summary { box-shadow:0px -4px 4px 0px rgba(32,32,32,0.6); }
  1382. #stats_details_summary_dirs .stats_kind::before { background-image:${ get_SVG_UI_File_Icon("file_icon_dir") }; }
  1383. #stats_details_summary_files .stats_kind::before { background-image:${ get_SVG_UI_File_Icon("file_icon_file_default") }; }
  1384. #stats_details_summary, #stats_details_items_container { overflow-y:scroll; }
  1385. #stats_summary_totals, .has_media #total_duration { display:flex; text-align:left; white-space:normal; padding-right:1em; }
  1386. #stats a { padding:3px 12px 3px 0; }
  1387. #stats a::before { content:attr(data-count); width:36px; text-align:right; }
  1388. .stats_kind span { margin-right:0.5em; white-space:pre; display:flex; }
  1389. .stats_kind > span::first-letter { text-transform:uppercase; }
  1390. #stats_details_items li.audio a span span::after { content:attr(data-audio_duration); white-space:pre; }
  1391. #stats_details_items li.video a span span::after { content:attr(data-video_duration); white-space:pre; }
  1392. #total_duration::after { content:attr(data-time_remaining); white-space:pre; }
  1393. .has_media #total_duration::before { content:"Total Time:\\00a0"; }
  1394. .stats_list_item_name_a { -webkit-padding-start:0; padding:1px 0; } .stats_list_item span::first-letter { text-transform:uppercase; }
  1395. #stats_summary, #stats_details_summary { margin-block-start:0; margin-block-end:0; }
  1396. #stats a.dirlist_item_name_a:before { display:inline-block; }
  1397. #stats_details_items { max-height:25vh; }
  1398. #stats_container, .has_menu_stats #stats_details_summary, .has_menu_stats #stats_details_items { display:block; }
  1399. #dir_footer_utilities { right:-1px; bottom:-1px; }
  1400. #dir_footer_utilities ul { bottom:0; right:0; white-space:nowrap; box-shadow:-0px -3px 6px -3px #333; }
  1401. #dir_footer_utilities:hover ul { display:block; }
  1402. .has_menu_stats #dir_footer_utilities { display:none; }
  1403. `;
  1404. const directory_utilities_styles = `
  1405. #show_sidebar { top:0; right:0; height:21px; opacity:0.6; } #show_sidebar:hover { opacity:1; }
  1406. body.show_sidebar_false #handle { display:none; } body.show_sidebar_false #show_sidebar { left:2px; transform:rotate(180deg); }
  1407. body.show_sidebar_false #dir_wrapper { width:0 !important; min-width:0; position:absolute; top:2px; left:-1px; }
  1408. body.show_sidebar_false #dir_header { z-index:unset; display:none; } body.show_sidebar_false #dir_nav { visibility:hidden; }
  1409. body.show_sidebar_false #directory_list_outer { min-width:0; } body.show_sidebar_false #content_pane { width:100% !important; }
  1410. body.show_sidebar_false #title_buttons_left { padding-left:24px; } #handle { top:0; bottom:0; right:-4px; width:7px; cursor:col-resize; }
  1411. .has_overlay #handle { z-index:9999; }
  1412. `;
  1413. const sidebar_styles = `${ dir_header_styles } ${ dir_nav_styles } ${ dir_footer_styles } ${ directory_utilities_styles }`;
  1414. /* CONTENT PANE STYLES */
  1415. const content_pane_header_styles = `
  1416. /***** CONTENT TITLE *****/
  1417. #content_title_container { overflow-x:scroll; }
  1418. #content_title { min-width:16em; min-height:18px; padding:4px 8px; word-break:break-word; }
  1419. #content_title span::before { font-weight:normal; margin-bottom:-3px; }
  1420. #content_pane.has_font_specimen #content_title div::before { content:"Font"; }
  1421. #content_pane.has_font_file #content_title div::before, #content_pane.has_font_file_glyph #content_title div::before { content:"Glyphs from font"; }
  1422. .has_directory_source #content_title div::before { content:"Source of" !important; }
  1423. .has_directory_source #content_title span::before { background-image:${ get_SVG_UI_File_Icon("file_icon_dir_default") }; height:14px !important; background-size:contain; }
  1424. #content_pane[data-content="has_grid"] #content_title div::before { content:"Fonts and Images from"; }
  1425. #content_pane[data-content="has_grid"].has_font_grid #content_title div::before { content:"Fonts from"; }
  1426. #content_pane[data-content="has_grid"].has_image_grid #content_title div::before { content:"Images from"; }
  1427. #content_pane[data-content="has_ignored"] #content_title div::before { content:"Ignored content"; }
  1428. #content_pane[data-content="has_dir"] #content_title div::before { content:"Index of"; }
  1429. body.has_texteditor .texteditor_view_raw.texteditor_split_view_false #content_title div::after { content:" (Source Text)"; }
  1430. body.has_texteditor .texteditor_view_preview.texteditor_split_view_false #content_title div::after { content:" (Text Preview)"; }
  1431. body.has_texteditor .texteditor_view_html.texteditor_split_view_false #content_title div::after { content:" (HTML Preview)"; }
  1432. body.has_texteditor #content_title div::before { content:"Text Editor" !important ; font-weight:bold; }
  1433. body.texteditor_edited.has_texteditor #content_title div::before { content:"Text Editor (edited)" !important; font-weight:bold; }
  1434. body.has_texteditor #content_title span { display:none; }
  1435. body.has_texteditor #content_title span::before { background-image:${ get_SVG_UI_File_Icon("file_icon_markdown") }; }
  1436. #content_pane[data-loaded="unloaded"] #content_title { display:flex; justify-content:center; align-items:center; }
  1437. #content_pane[data-loaded="unloaded"] #content_title div::before { content:"Loading..." }
  1438. #content_pane[data-loaded="unloaded"] #content_title span { display:none; }
  1439. #content_pane[data-content="has_grid"] #content_title span::before { background-image:${ get_SVG_UI_File_Icon("file_icon_dir") }; height:14px !important;}
  1440. #content_pane[data-content="has_image"] #content_title span::after { content:attr(data-after); font-weight:normal; white-space:pre; }
  1441. #content_pane.content_error #content_title span::before, #content_pane.content_error #content_container, #content_pane.has_audio_error #content_audio_title span::before { background-image:${ get_SVG_UI_Icon("error") }; }
  1442. body.is_error:not(.has_directory_source) #content_title span::before, #content_pane.content_error #content_title div::before { content:"ERROR:"; white-space:pre; display:inline; }
  1443. /* CONTENT TITLE BUTTONS LEFT */
  1444. #reload_btn { width:52px; } #reload_btn::before { content:"Reload"; }
  1445. #prev_next_btns { margin-left:4px; } #prev_next_btns span { width:2em; height:16px; } #prev_next_btns span:active { background-color:#0E4399; } #prev_next_btns:focus { background-color:white; }
  1446. #prev_next_btns svg { width:12px; }
  1447. /* CONTENT TITLE BUTTONS RIGHT */
  1448. #scale { margin-right:4px; background-color:#FFF; } #scale span { width:2em; }
  1449. #close_btn { width:52px; } #close_btn::before { content:"Close"; } body.has_texteditor #close_btn::before { content:"Hide"; } #content_pane[data-content="has_null"] #close_btn { display:none !important; }
  1450. .split_btn::after { content:""; position:absolute; top:0; bottom:0; left:calc(50% - 1px); border-left:solid 1px #333; } .split_btn span { display:inline-flex; }
  1451. #open_in_texteditor { margin-right:4px; }
  1452. `;
  1453. const content_pane_audio_styles = `
  1454. /* CONTENT AUDIO TITLE */
  1455. #content_audio_title span { padding:4px 6px 0; }
  1456. #content_audio_title span::before { content:""; padding-right:22px; height:14px !important; font-weight:normal; background-image:${ get_SVG_UI_File_Icon("file_icon_audio") }; background-position:center; background-position:right 4px center; background-repeat:no-repeat; }
  1457. #content_pane.has_audio #content_audio_title span::before, #content_pane[data-content="has_video"] #content_title div::before { content:"Playing:"; }
  1458. #content_pane.has_audio.has_audio_error #content_audio_title span::before { content:"ERROR:"; }
  1459. #content_pane.has_audio.has_audio_error #content_audio { padding-top:0; }
  1460. #content_pane.has_audio.has_audio_error #audio_container { display:none; }
  1461. /* CONTENT AUDIO PLAYER */
  1462. #content_audio { justify-content:center; padding:2px 6px 6px; overflow-x:auto; }
  1463. #audio_container { height:32px; background-color:rgb(241, 243, 244); }
  1464. #prev_track, #next_track { width:2rem; }
  1465. #audio { height:32px; }
  1466. audio::-webkit-media-controls-enclosure { border-radius:0; }
  1467. #close_audio { width:32px; }
  1468. #audio_options { margin-top:0; margin-right:calc(-6em - 8px); padding:0 4px; width:6em; justify-content:start; }
  1469. #loop_label input { margin:0px 4px 2px}
  1470. #shuffle_label input { margin:2px 4px 0px}
  1471. #shuffle_label::after { content:attr(data-shufflecount); }
  1472. /* CUE SHEET MENU */
  1473. .cuesheet_track_list_container { background-image:${ get_SVG_UI_File_Icon("file_icon_playlist") }; background-repeat:no-repeat; background-size:18px; background-color:inherit; display:none; }
  1474. .cuesheet_track_list_container:hover > div { display:flex; flex-direction:column; margin-top:-1px; overflow:auto; }
  1475. #cuesheet_track_list_container_audio { width:32px; background-position:center; } #cuesheet_track_list_container_video { width:24px; background-position:top left; }
  1476. #cuesheet_track_list_container_audio > div { padding-top:13px; } #cuesheet_track_list_container_video > div { padding-top:10px; }
  1477. .cuesheet_track { justify-content:space-between; grid-template-columns: 2rem minmax(6rem,1fr) minmax(6em,1fr) minmax(auto,6em); }
  1478. .cuesheet_track.selected .cue_track_id::before { content:""; width:16px; height:8px; display:flex; }
  1479. .cuesheet_track span { padding:4px 0 4px 8px; font-variant-numeric:tabular-nums; }
  1480. #cuesheet_title { padding:4px 8px; font-variant-numeric:tabular-nums; text-align:center; }
  1481. /* CONTENT TITLE PLAYLIST ENTRY (#content_playlist_item and #content_audio_playlist_item) */
  1482. .playlist_entry_container { flex-direction:row; }
  1483. .playlist_entry_container textarea { resize:vertical; background-color:transparent; }
  1484. .theme_light .playlist_entry_container:has(textarea:focus) { box-shadow:inset 0px 0px 2px 2px var(--non_media_item_background); }
  1485. .theme_dark .playlist_entry_container:has(textarea:focus) { box-shadow:inset 0px 0px 4px 1px hsl(0,0%,var(--percent_95)); }
  1486. #content_pane.has_audio #audio_wrapper, .playlist_entry_container.has_content { display:flex; flex-direction:column; }
  1487. audio::-webkit-media-controls-panel { padding:0; }
  1488. `;
  1489. const content_pane_styles = `${ content_pane_header_styles } ${ content_pane_audio_styles }
  1490. #content_pane { transform:scale(1); contain:strict; }
  1491. #content_container { align-items:center; justify-content:center; bottom:0; background-position:center; background-repeat:no-repeat; background-size:33.33%; contain:strict; flex-basis:100%; overflow:auto; }
  1492. .content_el { width:100%; height:100%; margin:0; padding:0; overflow:auto; display:none; }
  1493. #content_pane[data-loaded="unloaded"] .content_el { display:none !important; }
  1494. #content_pane[data-loaded="unloaded"]:not([data-content="has_ignored"]) #loading_spinner { display:block; }
  1495. /* CONTENT DISPLAY */
  1496. #content_pane:not([data-content="has_ignored"]) #content_font.has_content, #content_pane[data-content="has_image"] #content_image_container, #content_pane[data-content="has_grid"] #content_grid
  1497. { display:grid; }
  1498. #content_pane[data-content="has_grid"] .split_btn, #content_pane[data-content="has_image"] .split_btn, #content_pane[data-content="has_font"] .split_btn, #content_body:not(.text_editing_enable_false) #content_pane[data-content="has_htm"] #open_in_texteditor, #content_pane:not([data-content="has_ignored"]) .content_el:not(#content_font).has_content, body.has_texteditor #content_texteditor, #content_pane[class*="has_font_specimen"] #font_specimen_viewer, .has_font_specimen_glyph #font_specimen_glyph_viewer, #content_pane[class*="has_font_file"] #font_file_viewer, .has_font_file_glyph #font_file_glyph_viewer
  1499. { display:flex; }
  1500. /* CONTENT GRID (div) */
  1501. #content_grid { font-size:1rem; grid-gap:0; grid-template-columns:repeat(auto-fill, minmax(${ ( UI_Prefs_Non_Bool.grid_image_size + 16) }px, auto)); grid-auto-rows:minmax(min-content, max-content); }
  1502. #content_pane.has_hidden_grid #content_grid { max-height:100%; overflow:hidden; visibility:hidden; }
  1503. /* FONT & IMAGE GRID ITEMS */
  1504. .image_grid_item { padding:6px; grid-column:auto; line-height:0; }
  1505. .image_grid_item img { width:auto; max-width:${ (UI_Prefs_Non_Bool.grid_image_size).toString() }px; max-height:${ (UI_Prefs_Non_Bool.grid_image_size) }px; position:relative; opacity:0.9; }
  1506. .image_grid_item img[src$=".svg"] { height:100%; }
  1507. .image_grid_item.selected { box-shadow:inset 0px 0px 4px hsl(0,0%,var(--percent_60)); } .font_grid_item.selected p { font-weight:bold; } .font_grid_item.selected a { font-weight:unset; }
  1508. .image_grid_item.selected img, .font_grid_item.selected, .image_grid_item:hover, .font_grid_item:hover { opacity:1; }
  1509. .font_grid { font-size:4em !important; margin:0 0 20px; grid-gap:0; grid-template-columns:repeat(auto-fit, minmax(max(60px,1.33em), 1.5fr)); grid-auto-rows:minmax(max(60px,1.33em), max-content); line-height:unset !important; letter-spacing:unset !important; }
  1510. .font_grid_item { line-height:1; padding:8px 20px; grid-column:1 / -1; opacity:0.9; }
  1511. .font_grid_item_info { padding:0 0 6px 0; letter-spacing:0.1em; text-indent:0.1em; }
  1512. .font_grid_item h2 { font-size:${ UI_Prefs_Non_Bool.grid_font_size * 4 }em; font-weight:normal; }
  1513. .image_grid_item + .font_grid_item { margin-top:-1px; border-top:solid 1px hsl(0,0%,var(--border_lum_inverted)); }
  1514. /* CONTENT FONT.content */
  1515. #content_font { font-size:${ UI_Prefs_Non_Bool.grid_font_size }em; overflow-wrap:break-word; align-content:start; flex-direction:column; }
  1516. #content_pane.has_font_specimen #content_container, .has_font_specimen_glyph #content_container, .has_font_specimen_glyph #font_specimen, .has_font_file_glyph #content_container { overflow:hidden; }
  1517. #content_pane[data-content*="has_font"] #font_toolbar { display:grid; overflow-x:scroll; overflow-y:hidden; -webkit-user-select:none;-moz-user-select:none; user-select:none; }
  1518. #content_pane.has_font_specimen #font_specimen_variants { display:flex; } #content_pane.has_font_specimen #font_specimen_adjustments li.display_none { display:unset; }
  1519. #content_pane.has_font_file_glyph #content_font { background-color:hsl(0,0%,var(--percent_100)); }
  1520. #font_toolbar li { margin:2px; padding:0 4px; white-space:pre; }
  1521. #font_toolbar li.text { width:50%; font-size:var(--font_size_small); }
  1522. #font_variant_select { width:13em; }
  1523. #unicode_char_ranges_select { width:12em; }
  1524. #font_specimen_adjustments { font-size:0.75rem; padding-bottom:2px; }
  1525. #font_specimen_adjustments input { width:8em; }
  1526. #font_specimen_viewer { min-width:100%; flex-direction:column; }
  1527. #font_specimen_viewer .specimen { padding:20px; outline:none; color:inherit; font-weight:normal; }
  1528. #font_specimen_viewer .specimen:focus, #font_specimen_viewer .specimen:focus-visible { box-shadow:inset 0 0 2px 2px hsl(212deg 50% 60%); border-radius:3px; outline:none !important; }
  1529. .specimen:focus, specimen:focus-visible { background-color: hsl(0,0%,var(--percent_100)); }
  1530. #font_specimen_grid:empty, #font_specimen_glyph:empty, #font_specimen_grid:empty + hr { display:none; }
  1531. .font_glyph_item { grid-column:auto; display:flex; justify-content:center; position:relative; cursor:pointer; -webkit-text-stroke:inherit !important; letter-spacing:initial; line-height:initial; }
  1532. .font_glyph_item div { color:inherit; }
  1533. .font_glyph_item::before, .font_glyph_item::after, #font_specimen_viewer::before, #font_specimen_viewer::after { display:inline-block; position:absolute; font-size:0.75rem; top:0; font-family:${UI_Prefs_Non_Bool.ui_font}; opacity:0.75; font-feature-settings:normal; font-variant:normal; line-height:1.2; letter-spacing:normal; -webkit-text-stroke:0 !important; }
  1534. .font_glyph_item::before, #font_specimen_viewer::before { content:attr(data-unicode_dec); left:2px; }
  1535. .font_glyph_item::after, #font_specimen_viewer::after { content:attr(data-unicode_hex); right:2px; }
  1536. .has_font_specimen_glyph #font_specimen_viewer::before, .has_font_specimen_glyph #font_specimen_viewer::after, .has_font_file_glyph #font_file_glyph_viewer::before, .has_font_file_glyph #font_file_glyph_viewer::after { display:inline-block; padding:4px 6px; font-size:0.875rem; position:fixed; white-space:pre; opacity:1; z-index:2; }
  1537. #font_specimen_1 { font-size:4em;} #specimen_2 { font-size:8em; } #specimen_3 { font-size:6em; } #specimen_2H4 { font-size:1.618em; } #specimen_3H3 { font-size:2em; }
  1538. .lorem { font-size:1em; column-gap:1.5em; overflow-wrap:normal; }
  1539. #lorem::first-line { letter-spacing:0.1em; text-indent:0.1em; font-size:${ UI_Prefs_Non_Bool.grid_font_size * 1.33 }em; font-variant:small-caps; }
  1540. #lorem_2 { padding:12px 0 0; columns:2; }
  1541. #lorem_3 { padding:12px 0 0; columns:3; }
  1542. /* FONT GLYPHS */
  1543. #font_specimen_viewer, #font_file_viewer { line-height:1.5; background-color:inherit; }
  1544. .glyph_container:hover, .glyph_container.selected { z-index:1; }
  1545. #font_specimen_glyph, #font_specimen_glyph:not(:empty) + #font_specimen_glyph_overlay { display:flex; justify-content:center; font-size:64vw; overflow:visible; user-select:none; }
  1546. #font_file_viewer { font-family:unset; flex-direction:column; }
  1547. #content_pane.has_font_file_glyph #font_file_grid { visibility:hidden; }
  1548. #content_pane.has_font_file_glyph #font_file_viewer { overflow:hidden; }
  1549. #font_file_grid { margin-bottom:21px; }
  1550. .font_glyph_item svg { width:1em; height:1em; display:block; overflow:visible; }
  1551. .font_glyph_item g, #font_file_glyph_viewer svg g { transform-origin:center; }
  1552. #font_file_glyph_viewer { background-color:#FFF; }
  1553. #font_file_glyph_viewer::before, #font_file_glyph_viewer::after { position:absolute; color:hsl(0,0%,var(--percent_65)); }
  1554. #font_file_glyph_viewer::before { content:attr(data-unicode_dec); }
  1555. #font_file_glyph_viewer::after { content:attr(data-unicode_hex); right:0; }
  1556. .has_font_file_glyph #save_svg { display:initial; margin-right:4px; }
  1557. #save_svg_hidden { float:left; visibility:hidden; }
  1558. #font_info { max-height:${ (window.innerHeight * 0.75) }px; left:-1px; right:0; bottom:-1px; overflow-y:auto; }
  1559. #font_info:hover { box-shadow:0px 4px 6px 3px #333; }
  1560. /* OTHER CONTENT ELEMENTS */
  1561. #content_image_container { padding:2rem 2.5rem; box-sizing:border-box; }
  1562. .has_zoom_image #content_image_container, .has_scaled_image #content_image_container { padding:0; }
  1563. #content_image { margin:auto; width:auto; max-width:100%; height:auto; max-height:100%; object-fit:contain; cursor:zoom-in; }
  1564. #content_image:focus-visible { outline:none; }
  1565. #content_pane.has_zoom_image #content_image { width:fit-content; height:fit-content; max-width:unset; max-height:unset; cursor:zoom-out; }
  1566. #content_video { background:transparent; height:auto; max-width:calc(100% - 4em); max-height:calc(100% - 4em); }
  1567. #content_iframe { background:white; }
  1568. #content_pane.has_emptycontent #content_iframe { background:unset; }
  1569. `;
  1570. const main_styles = `${ global_styles }
  1571. .image_grid_item img[src$=".svg"] { width:100%; }
  1572. .cuesheet_track_list_container:hover .cuesheet_track_list, #content_grid a { display:block; }
  1573. button { background-color:hsl(0,0%,95%); border:solid 1px #333; border-radius:3px; height:18px; font-size:0.875em; font-family:${UI_Prefs_Non_Bool.ui_font} !important; cursor:pointer; }
  1574. button.focus, button:focus { outline:none; border-radius:3px !important; border-style:solid !important; border-width:1px !important; border-color:#222 !important; }
  1575. textarea:focus, audio:focus { outline:none; }
  1576. #content_title *:empty { display:none; }
  1577. /* VARIOUS CLASSES AND ELEMENTS */
  1578. /* combine with has_flyout_menu or add background color classes to elements: */
  1579.  
  1580. /* .has_popout_menu { background-color:#C0C0C0; border:solid 1px #666; }
  1581. .has_popout_menu li { background-color:#D0D0D0; }
  1582. .theme_dark #dir_wrapper .has_popout_menu { border:solid 1px #111; }
  1583. .theme_dark #dir_wrapper .has_popout_menu, .theme_dark #dir_wrapper .has_popout_menu li { background-color:#505050; }
  1584. */
  1585. /***** APPEND STYLES *****/
  1586. ${ sidebar_styles } ${ content_pane_styles } ${ utilities_styles }
  1587. `;
  1588. const conditional_styles = `
  1589. /* PSEUDO-ELEMENTS */
  1590. #reload_btn.reset::before, #content_pane:is(.has_font_specimen,.has_font_specimen_glyph,.has_font_file,.has_font_file_glyph,.has_zoom_image,.has_scaled_image) #reload_btn::before { content:"Reset"; }
  1591. .texteditor_edited #show_texteditor span:after, .iframe_edited:not(.has_texteditor) #content_pane.has_iframe #content_title div::after { content:" (edited)"; }
  1592. .theme_light #menu_theme span::before { content:"Light "; }
  1593. .theme_dark #menu_theme span::before { content:"Dark "; }
  1594. body:not(.show_details_false) #show::before { content:"Hide "; }
  1595. body.text_editing_enable_false #disable::after { content:"Disabled"; }
  1596. #disable::after { content:"Enabled"; }
  1597. .is_error #dir_header_utilities { border-bottom:0; }
  1598. #is_error { display:block !important; grid:none !important; grid-template-columns:none !important; }
  1599. .theme_dark #is_error_items, .theme_dark #dir_menu_main li > span::before, .theme_dark #sorting span::before, .theme_dark #sorting span::after, .theme_light #dir_menu_main li.selected > span::before { filter:invert(1); }
  1600. /* CONDITIONAL DISPLAY */
  1601. body:not(.alternate_background_false).is_error #alternate_background, .is_error #dir_header_utilities > div:not(:first-of-type), .is_non_local #show_invisibles_container { display:none; }
  1602. .has_media #play_toggle, .theme_dark #theme_dark, .theme_light #theme_light, #content_pane[class^="has_"] #close_btn, #content_pane[data-content="has_texteditor"] #close_btn { display:unset; }
  1603. .has_playlist #stats_summary_playlist_files, .has_filelist #stats_summary_playlist_files { display:table-row; }
  1604. .has_menu #dir_menu_main, .has_menu_parents #parents_links, body:not(.no_hover) #dir_menus .has_submenu:hover .submenu, #dir_menu_main .has_submenu.hovered .submenu, #dir_footer li, .has_warning #overlay_container, .cuesheet_track_list_container.has_cue_sheet, .has_playlist #close_playlist_container, .has_filelist #close_playlist_container { display:block; }
  1605. .has_menu_stats .dirlist_item.invisible, .has_menu_stats .dirlist_item.ignored, .has_menu_stats .dirlist_item.ignored.hovered, body:not(.show_ignored_items_false).has_menu_stats .dirlist_item.ignored, body:not(.show_ignored_items) .dirlist_item.ignored:not(.invisible) { display:grid; }
  1606. #content_pane[data-content="has_texteditor"] .content_el.has_content, #content_pane[data-content="has_texteditor"] #content_grid, #content_pane[data-content="has_grid"] #content_texteditor, #content_pane[data-content="has_grid"] .content_el.has_content { display:none !important; }
  1607. `;
  1608. const texteditor_styles = `
  1609. html, body, #content_body { margin:0; padding:0; height:100%; overflow:hidden; position:relative; font-family:${ UI_Prefs_Non_Bool.ui_font }; font-size:${ UI_Prefs_Non_Bool.ui_font_size }; }
  1610. button.focus, button:focus { outline:none; border-radius:3px !important; border-style:solid !important; border-width:1px !important; border-color:#222 !important; }
  1611. .is_texteditor #content_texteditor, body.is_text #content_texteditor { display:flex; }
  1612. /* TOOLBAR */
  1613. #toolbar { overflow:visible; z-index:100; font-size:${ parseFloat(UI_Prefs_Non_Bool.ui_font_size) * 0.875 + UI_Prefs_Non_Bool.ui_font_size.replace(/\d*/,'') }; -webkit-user-select:none; -moz-user-select:none; user-select:none; }
  1614. #content_body.text_editing_enable_false #toolbar, .texteditor_split_view_false #texteditor_sync_scroll { display:none; }
  1615. .toolbar_icon { margin:0 4px; padding:4px; min-width:16px; height:16px; cursor:pointer; opacity:0.5; }
  1616. #texteditor_sync_scroll { opacity:1; height:24px; padding:0 8px; flex-grow:unset; }
  1617. #texteditor_sync_scroll input { margin:0 4px 0 0; z-index:-1; }
  1618. #save_btn ul { top:-3px; right:-4px; }
  1619. #save_html, #save_text { grid-column:1; }
  1620. #save_btn_icon { grid-column:2; grid-row:span 2; width:32px; }
  1621. #save_btn_icon svg { margin:3px; }
  1622. .texteditor_edited #save_btn svg { color:red !important; }
  1623. #toolbar li:hover, .texteditor_view_raw #toggle_texteditor_view_raw, body:not(.texteditor_split_view_false) #toggle_texteditor_view_raw, body:not(.texteditor_split_view_false):not(.texteditor_view_html) #toggle_texteditor_view_preview, .texteditor_view_preview #toggle_texteditor_view_preview, .texteditor_view_html #toggle_texteditor_view_html, body:not(.texteditor_split_view_false) #toggle_texteditor_split_view { opacity:1; }
  1624. /* TEXT CONTENT CONTAINERS */
  1625. .texteditor_pane { padding:1em; overflow-y:scroll; box-sizing:border-box; background:transparent; font-size:${ parseFloat(UI_Prefs_Non_Bool.ui_font_size) + UI_Prefs_Non_Bool.ui_font_size.replace(/\d*/,'') }; }
  1626. body.texteditor_split_view_false .texteditor_pane { width:100%; } body:not(.texteditor_split_view_false) .texteditor_pane { width:50%; }
  1627. #text_container .texteditor_pane:focus { background-color:hsl(0,0%,var(--percent_90)); outline:none; box-shadow:inset 0px 0px 4px hsl(0,0%,var(--percent_95)); }
  1628. #text_container textarea { font-family:monospace; }
  1629. /* EDITOR PANES */
  1630. .texteditor_view_raw #texteditor_txt_pane, .texteditor_view_preview #texteditor_preview_pane, .texteditor_view_html #texteditor_html_pane,
  1631. .texteditor_view_html.texteditor_view_raw.texteditor_split_view_false #texteditor_txt_pane, .texteditor_view_preview.texteditor_view_raw.texteditor_split_view_false #texteditor_txt_pane,
  1632. .texteditor_view_html:not(.texteditor_split_view_false) #texteditor_txt_pane, .texteditor_view_preview:not(.texteditor_split_view_false) #texteditor_txt_pane { display:block; }
  1633. .texteditor_view_preview.texteditor_split_view_false #texteditor_txt_pane, .texteditor_view_preview.texteditor_view_raw.texteditor_split_view_false #texteditor_preview_pane,
  1634. .texteditor_view_html.texteditor_split_view_false #texteditor_txt_pane, .texteditor_view_html.texteditor_view_raw.texteditor_split_view_false #texteditor_html_pane { display:none; }
  1635. /* THEMES & COLORS */
  1636. .texteditor_theme_default #content_texteditor .background_grey_95, .background_grey_90:focus, #texteditor_preview_pane table th, #text_container
  1637. { background-color:hsl(0,0,var(--percent_95)); }
  1638. .theme_dark.texteditor_theme_light #content_texteditor .text_color_default, .theme_light.texteditor_theme_default #content_texteditor .text_color_default
  1639. { color:hsl(0,0%,var(--percent_05)); }
  1640. .theme_dark #content_texteditor .text_color_default, .texteditor_theme_dark #content_texteditor .text_color_default { color:#EEE; }
  1641. /* custom previewed text styles */
  1642. #texteditor_preview_pane { word-break:break-word; }
  1643. #texteditor_preview_pane pre { border:solid 1px #CCC; border-radius:3px; white-space:pre-wrap; word-break:break-word; font-size:${ parseFloat(UI_Prefs_Non_Bool.ui_font_size) + UI_Prefs_Non_Bool.ui_font_size.replace(/\d*/,'') }; }
  1644. #texteditor_preview_pane th, #texteditor_preview_pane td { vertical-align:top; }
  1645. #texteditor_preview_pane blockquote { margin-top:1em; margin-bottom:1em; color:#555; }
  1646. #texteditor_preview_pane blockquote + blockquote { margin-top:0; }
  1647. .markdown_body input[type="checkbox"] { margin-top:0.375em; margin-right:6px; float:left; }
  1648. h1 .uplink,h2 .uplink,h3 .uplink,h4 .uplink,h5 .uplink,h6 .uplink { display:inline-block; font-size:0.875em; transition:opacity 0.25s; opacity:0; cursor:pointer; margin:0; padding:0; }
  1649. h1:hover .uplink,h2:hover .uplink,h3:hover .uplink,h4:hover .uplink,h5:hover .uplink,h6:hover .uplink { transition:opacity 0.25s; opacity:0.5; }
  1650. #texteditor_preview_pane table { font-size:inherit; }
  1651. .markdown_body table tr, .markdown_body .highlight pre, .markdown_body pre { background-color:transparent !important; }
  1652. .markdown_body::before, .markdown_body::after { display:none !important; background:transparent; }
  1653. body.texteditor_split_view_false #text_editing_handle, #content_body.text_editing_enable_false #save_btn, .comment, #content_body.text_editing_enable_false #texteditor_preview { display:none; }
  1654. #content_body.has_warning::after { content:""; position:absolute; top:0; right:0; bottom:0; left:0; background:rgba(0,0,0,0.33); z-index:9998; }
  1655. #text_editing_handle { width:8px; top:0; bottom:0; left:calc(50% - 4px); cursor:col-resize; }
  1656. #text_editing_handle::before { content:""; width:1px; background:hsl(0,0%,var(--border_lum)); position:absolute; top:0; bottom:0; left:calc(50%); }
  1657. .texteditor_theme_dark #text_editing_handle::before, .theme_dark.texteditor_theme_default #text_editing_handle::before { background:#111; }
  1658. `;
  1659. // Gecko (Firefos) Styles:
  1660. const gecko_style_rules = `
  1661. .dir::before { content:"" !important; display:none !important; }
  1662. .is_gecko button { padding:revert; }
  1663. .is_gecko #show_grid_btn .menu { top:-7px; left:-120px; }
  1664. .is_gecko thead { font-size:100%; }
  1665. .is_gecko .dirlist_item.dir::before { position:absolute; }
  1666. .is_gecko .dirlist_item_name span { display:-webkit-box; width:auto; white-space:normal; }
  1667. .dirlist_item.dir td:not(:first-child), .dirlist_item.file td:not(:first-child) { width:unset !important; }
  1668. .is_gecko .dirlist_item td { min-width:calc(100% - 24px); }
  1669. .is_gecko .dir::before { content:"" !important; display:none !important; }
  1670. .is_gecko.use_default_icons:not(.is_converted_list) .dirlist_item.file .icon { padding-left:4px; background:none; }
  1671. .is_gecko.use_default_icons .dirlist_item.file .icon img { margin-right:6px; height:14px; }
  1672. .is_gecko #directory_list > tr > td:not(:first-of-type) { float:left }
  1673. .is_gecko #content_audio_title span { padding-top:6px;, padding-bottom:0; }
  1674. .is_gecko #audio,.is_gecko #audio_container { background-color:rgba(26,26,26,1); }
  1675. .is_gecko #prev_track, .is_gecko #next_track, .is_gecko #close_audio { filter:invert(1); border:none !important; }
  1676. .is_gecko #content_pane.has_zoom_image #content_image_container { display:block !important; }
  1677. `;
  1678. const safari_style_rules = `
  1679. .is_safari button { background-color:#FFF; }
  1680. .is_safari.theme_dark #prev_track, .is_safari.theme_dark #next_track, .is_safari.theme_dark #close_audio { filter:invert(1); }
  1681. `;
  1682. const chrome_style_rules = `video::-webkit-media-controls-enclosure { border-radius:0 !important; }`;
  1683. const html_style_rules = `a:focus, a:focus-visible { font-weight:bold; border-radius:1px; outline:currentcolor solid 1px; outline-offset:1px; display:inline-block; padding:0 2px; text-decoration:none; }`
  1684. //==============================//
  1685. function addStyles(user_agent) { // ===> ADD STYLES
  1686. let default_styles = `<style id="main_styles">${ main_styles }</style> <style id="conditional_styles">${ conditional_styles }</style> <style id="font_styles"></style> <style id="font_grid_styles"></style>`;
  1687. switch (user_agent) {
  1688. case user_agent === 'is_gecko':
  1689. default_styles += `<style id="gecko_style_rules">${ gecko_style_rules }</style>`;
  1690. break;
  1691. case user_agent === 'is_safari':
  1692. default_styles += `<style id="safari_style_rules">${ safari_style_rules }</style>`;
  1693. break;
  1694. case user_agent === 'is_chrome':
  1695. default_styles += `<style id="chrome_style_rules">${ chrome_style_rules }</style>`;
  1696. break;
  1697. }
  1698. return default_styles // return styles
  1699. }
  1700. // ***** END STYLES ***** //
  1701. //==============================//
  1702. // ***** INDEX PREP ***** //
  1703. // Try to determine index type from parent directory link container, with fallbacks for indexes that don't have parent directories, or for parent directory links that aren't siblings or ancestors of the index itself.
  1704. function getIndexType() { // ===> GET INDEX TYPE
  1705. let index_el = getEls('body > ul, body ul, body > pre, body > table:last-of-type, body div table');
  1706. if (index_el.length > 1) {
  1707. index_el = (Array.from(index_el).filter(el => el?.nodeName?.toLowerCase() === 'table') || index_el.reverse()[0])
  1708. } // some index pages have pre and table elements; list is usually table
  1709. index_el = index_el[0];
  1710. let node_name = (index_el !== undefined ? index_el.nodeName.toLowerCase() : 'body'); // "body" is likely to be an error page
  1711. let types = {
  1712. 'gecko': 'gecko',
  1713. 'ul': 'list',
  1714. 'pre': 'pre',
  1715. 'table': 'table',
  1716. 'th': 'table',
  1717. 'td': 'table',
  1718. 'div': 'default',
  1719. 'error': 'error',
  1720. 'body': 'error',
  1721. 'permission_denied': 'permission_denied'
  1722. }; // object array of types
  1723. return types[node_name]; // return index type
  1724. }
  1725.  
  1726. function getIndexItems(agent) {
  1727. let type = getIndexType(agent),
  1728. items; // ===> GET INDEX ITEMS // get index type, define items
  1729. switch (type) {
  1730. case 'error':
  1731. items = document.getElementsByTagName('html')[0].outerHTML;
  1732. break; // error type
  1733. case 'pre':
  1734. items = getEl('body > pre').innerHTML;
  1735. break; // pre type
  1736. case 'list':
  1737. items = getEls('body > ul li, body > * > ul li');
  1738. break; // list type
  1739. case 'table':
  1740. case 'td': // table types
  1741. switch (true) {
  1742. case elExists('table > tbody'):
  1743. items = getEls('body table > tbody tr');
  1744. break; // ordinary tables
  1745. case !elExists('table > tbody'):
  1746. items = getEls('body table tr');
  1747. break; // tables without tbody element
  1748. }
  1749. break;
  1750. case 'gecko':
  1751. items = getEls('body > table > tbody > tr');
  1752. break; // gecko type
  1753. case 'default':
  1754. items = getEls('body > table > tbody tr');
  1755. break; // default: how is this different from table type?
  1756. }
  1757. return [items, type]; // return index items and index type
  1758. }
  1759. //==============================//
  1760. function prepPreType(items_str) { // ===> PREP PRE TYPE
  1761. let prepped_index = [],
  1762. parser = new DOMParser(),
  1763. items_HTML = parser.parseFromString(items_str, "text/html"); // convert items_str to DOM html
  1764. items_HTML.querySelectorAll('hr,img').forEach(el => el.remove()); // remove junk elements
  1765. items_HTML.querySelectorAll('a').forEach( // remove junk links (sorting and parent links) or define item_link
  1766. el => {
  1767. if (/^\?|^\./m.test(el.getAttribute('href')) || /^Parent$|^Parent Directory$|^\s*Up\s*$|^\s*Root\s*$/im.test(el.innerText)) {
  1768. el.remove();
  1769. }
  1770. }
  1771. );
  1772. items_str = items_HTML.querySelector('body').innerHTML; // convert DOM html back to str
  1773. items_str = items_str.replace(/\&lt;dir\&gt;/gm, ' ').replace(/<br>/gi, '\n').replace(/[ ]*<h\d>[^<]*<\/h\d>[ ]*/gmi, '').replace(/[ ]*(<a[^>]+?>)[^<]*(<\/a>)/g, '$1$2 ').replace(/(\w)<a /g, '$1 <a '); // clean string
  1774. const items = items_str.split('\n'); // create array of item strings from items
  1775. for (let i = items.length; i--;) {
  1776. let prepped_item = [],
  1777. link;
  1778. let cells = items[i].split(/\s{2,}/);
  1779. for (let j = cells.length; j--;) {
  1780. let cell = cells[j];
  1781. if (cell.trim().length > 0 && cell.trim() !== '-') {
  1782. if (!cell.startsWith('<a ')) {
  1783. prepped_item.push(cell);
  1784. }
  1785. else {
  1786. link = cell.split('"')[1];
  1787. } // extract link
  1788. }
  1789. }
  1790. if (link === undefined || (/^\.\.$|^\.\.\/$|^\/$|^\?|\?sort=|\?path=\&/mi.test(link))) {
  1791. prepped_item = [];
  1792. }
  1793. else {
  1794. prepped_item.unshift(link);
  1795. } // exclude some items (e.g., parent directory links)
  1796. if (prepped_item.length > 0) {
  1797. prepped_index.push(prepped_item);
  1798. } // add prepped item to index
  1799. }
  1800. return prepped_index; // return prepped index
  1801. }
  1802.  
  1803. function prepListType(items) { // ===> PREP LIST TYPE
  1804. let prepped_index = [];
  1805. for (let i = items.length; i--;) {
  1806. let item = items[i];
  1807. if (item.innerHTML.indexOf('Parent Directory') === -1) {
  1808. let prepped_item = [],
  1809. link = item.querySelector('a')?.href;
  1810. item.querySelector('a')?.remove();
  1811. Array.from(item.children).forEach(child => {
  1812. if (child.innerText === '') {
  1813. child.remove();
  1814. }
  1815. }) // remove link and empty child elements
  1816. let cells = item.innerHTML.split(' '); // create array from remaining elements
  1817. for (let cell of cells) {
  1818. prepped_item.push(cell);
  1819. }
  1820. if (link === undefined || (/^\.\.$|^\.\.\/$|^\/$|^\?|\?sort=|\?path=\&/mi.test(link))) {
  1821. prepped_item = [];
  1822. }
  1823. else {
  1824. prepped_item.unshift(link);
  1825. } // exclude some items (e.g., parent directory links)
  1826. if (prepped_item.length > 0) {
  1827. prepped_index.push(prepped_item);
  1828. }
  1829. }
  1830. }
  1831. return prepped_index; // return prepped index
  1832. }
  1833.  
  1834. function prepGeckoType(items) { // ===> PREP GECKO TYPE
  1835. let prepped_index = [];
  1836. for (let item of items) {
  1837. let prepped_item = [],
  1838. cellContents = '',
  1839. cells = item.cells,
  1840. link = item.innerHTML.split('href=\"')[1].split('\">')[0];
  1841. for (let cell of cells) {
  1842. cellContents = cell.innerText;
  1843. cellContents = (cellContents !== undefined ? cellContents.trim() : '');
  1844. prepped_item.push(cellContents);
  1845. }
  1846. prepped_item[1] = prepped_item[1].replace(/\s*KB/, '000'); // convert reported size in KB to total bytes
  1847. prepped_item[2] = prepped_item[2] + ' ' + prepped_item[3];
  1848. prepped_item = prepped_item.slice(1, -1);
  1849. if (link === undefined || (/^\.\.$|^\.\.\/$|^\/$|^\?|\?sort=|\?path=\&/mi.test(link))) {
  1850. prepped_item = [];
  1851. }
  1852. else {
  1853. prepped_item.unshift(link);
  1854. } // exclude some items (e.g., parent directory links)
  1855. if (prepped_item.length > 0) {
  1856. prepped_index.push(prepped_item);
  1857. }
  1858. }
  1859. return prepped_index; // return prepped index
  1860. }
  1861.  
  1862. function prepTableType(items) { //*** for local chrome indexes and server-generated table-type indexes // ===> PREP TABLE TYPE
  1863. let prepped_index = [],
  1864. prepped_item, item, cell, cell_text;
  1865. for (item of items) {
  1866. if (item.querySelector('td a') !== null) {
  1867. let link;
  1868. prepped_item = []; // get legitimate items (i.e., those containing a link)
  1869. for (cell of item.cells) { // get text from remaining cells (date & size)
  1870. switch (true) {
  1871. case cell.querySelector('a') !== null && link === undefined:
  1872. link = item.querySelector('a')?.getAttribute('href'); // get link; add to prepped_item; ignore if link already defined
  1873. if (!/^\?|^\.\.\/$|^\|\"\/\".$/m.test(link) && !/^\s*parent directory\*$|^\*up\s*$/m.test(item.innerText.toLowerCase())) {
  1874. prepped_item.unshift(link);
  1875. } // else { prepped_item.unshift(''); }
  1876. break;
  1877. default:
  1878. cell_text = cell.innerText.trim().replace(/(^[ ]*-[ ]*$|[ ]*-[ ]*\&nbsp;[ ]*$)|\&nbsp;/m, ''); // prep cells and clean cell text
  1879. if (!/<td\s*[^>]*>dir|directory|file<\/td>|>\w*\s*file<|>\w*\s*unknown</i.test(cell.outerHTML.toLowerCase()) && cell_text !== '') {
  1880. prepped_item.push(cell_text);
  1881. } // exclude various cells
  1882. }
  1883. }
  1884. if (prepped_item.length > 1 && prepped_item[0] !== '') {
  1885. prepped_index.push(prepped_item);
  1886. } // prepped_item.length > 2 in order to omit parent directory item
  1887. }
  1888. }
  1889. return prepped_index; // return prepped index
  1890. }
  1891.  
  1892. function prepErrorType(items) {
  1893. return items;
  1894. } // ===> PREP ERROR TYPE; receives and returns html string
  1895. function prepPlaylist(items) { // ===> PREP PLAYLIST items
  1896. let prepped_index = [];
  1897. let prepped_item, link, duration, name, info;
  1898. let items_arr, type;
  1899. items = items.replace(/\s*#EXTM3U.*\s*/g, '').replace(/^\*\n{2,}/gm, '\n').replace(/\.pdf\?.+?\n/g, '.pdf\n'); //.replace(/\?/g,'%3F'); // remove header comment and multiple returns
  1900. switch (true) { // determine playlist type;
  1901. case (/#EXTINF:/i.test(items)):
  1902. type = 'extm3u';
  1903. items_arr = items.split('#EXTINF:');
  1904. break; // rows made by splitting at "#EXTIMG:" prefix
  1905. default:
  1906. type = 'm3u';
  1907. items_arr = items.split('\n');
  1908. break; // rows are just naked links
  1909. }
  1910. items_arr.forEach((item) => {
  1911. switch (true) { // get entry information: title, link, etc.
  1912. case type === 'extm3u':
  1913. item = item.trim().split('\n');
  1914. link = item[1];
  1915. info = item[0].split(',');
  1916. duration = info.shift();
  1917. name = info.join(',');
  1918. if (item[1] !== undefined) {
  1919. prepped_item = [link, duration, '', name];
  1920. }
  1921. break;
  1922. case type === 'm3u':
  1923. prepped_item = [item, '', ''];
  1924. break; // m3u with urls only
  1925. }
  1926. if (prepped_item !== undefined) {
  1927. prepped_index.push(prepped_item);
  1928. }
  1929. });
  1930. return prepped_index; // return prepped index
  1931. }
  1932.  
  1933. function convertIndexItems(items, type) {
  1934. let converted = []; // ===> CONVERT INDEX ITEMS by type; returns [prepped_index]
  1935. switch (type) {
  1936. case 'gecko':
  1937. converted = prepGeckoType(items);
  1938. break;
  1939. case 'list':
  1940. converted = prepListType(items);
  1941. break;
  1942. case 'pre':
  1943. converted = prepPreType(items);
  1944. break;
  1945. case 'table':
  1946. case 'default':
  1947. converted = prepTableType(items, type);
  1948. break;
  1949. case 'error':
  1950. converted = prepErrorType(items);
  1951. break;
  1952. }
  1953. return converted;
  1954. }
  1955. //==============================//
  1956. function buildNewIndex(id, prepped_index, sort, type, body_id) { // ===> BUILD NEW INDEX from prepped rows
  1957. let i, new_index_items = [],
  1958. body_classes = new Set();
  1959. let index_html = '';
  1960. let new_item, item, item_info = [],
  1961. item_link, item_name, item_sort_name, item_size_and_date, item_size, item_sort_size, item_date, item_sort_date, item_ext, item_description, item_sort_kind, item_classes;
  1962. let name_span, cell_link, cell_name, cell_size, cell_date, cell_kind, cell_ext, cell_time, prepped_index_length = prepped_index.length,
  1963. item_disabled, item_input;
  1964. let stats, stats_classes = [],
  1965. stats_kinds = [],
  1966. stats_total_size = 0,
  1967. media_count = 0;
  1968. let dir_list_parent_class = ((body_id === (null || 'top_body') || type === 'playlist') ? 'top_item' : 'iframe_item'); // body_id used to set dir list details style
  1969. let parent_id = (getCurrentUIPref('parent_id') || ''),
  1970. connector = (getCurrentUIPref('parent_id') ? '_' : ''),
  1971. level = (Number(getCurrentUIPref('level')) || 0),
  1972. level_style = (level === 0 ? '' : `style="padding-left:${ Number(level) * 22 }px;"`); // ensure unique ids (with parent_id) and set indents for subdirectory items
  1973. if (prepped_index_length > 5000) {
  1974. if (confirm(`This directory contains ${prepped_index_length} items; it may take a long time to process and could cause your browser to crash. Are you sure you want to open it?`) === false) {
  1975. return
  1976. }
  1977. }
  1978. switch (type) { // add body classes according to index type
  1979. case 'error':
  1980. body_classes.add('is_error');
  1981. break;
  1982. case 'pre':
  1983. body_classes.add('is_converted_pre');
  1984. break;
  1985. case 'list':
  1986. body_classes.add('is_converted_list');
  1987. break;
  1988. case 'table':
  1989. case 'td':
  1990. body_classes.add('is_converted_table');
  1991. break;
  1992. case 'default':
  1993. body_classes.add('is_default');
  1994. break;
  1995. }
  1996. // create and format directory item
  1997. for (i = 0; i < prepped_index_length; i++) {
  1998. item = prepped_index[i];
  1999. item_info = getLinkInfo(item[0]); // returns [link,name,ext,kind,item_classes,body_classes];
  2000. item_link = item_info[0];
  2001. item_name = item_info[1] || item[3]; // prep display name, with word breaks added after unbreakable chars
  2002. item_sort_name = item_name.toLocaleLowerCase();
  2003. item_size_and_date = getItemSizeAndDate(item);
  2004. item_size = item_size_and_date[0];
  2005. item_sort_size = item_size_and_date[1];
  2006. item_date = item_size_and_date[2];
  2007. item_sort_date = item_size_and_date[3];
  2008. item_ext = item_info[2];
  2009. item_sort_kind = item_info[3];
  2010. item_classes = item_info[4] + " " + dir_list_parent_class;
  2011. item_disabled = (/local/.test(item_classes) ? ' disabled="disabled"' : ''); // disable media if local file on non_local page or vice versa
  2012. item_input = (/audio|video/.test(item_sort_kind) && /top/.test(body_id) || type === 'playlist' ? `<input class="dirlist_item_input" type="checkbox" tabindex="-1" checked="true" ${item_disabled} autocomplete="off" />` : '');
  2013. // Assemble item elements
  2014. name_span = `<span class="icon has_icon_before_before"></span><span class="name_span display_flex">${ item_input }<span>${ item_name }</span></span>`;
  2015. cell_link = `<a href="${ item_link }" class="icon dirlist_item_name name dirlist_item_name_a position_relative">${ name_span }</a>`;
  2016. cell_name = `${ cell_link }`;
  2017. cell_time = `<span class="dirlist_item_media_duration align_right" data-duration=""></span>`;
  2018. cell_size = `<span class="dirlist_item_details size details" data-size="${ item_sort_size }">${ item_size }</span>`;
  2019. cell_date = `<span class="dirlist_item_details date details overflow_hidden" data-date="${ item_sort_date }">${ item_date }</span>`;
  2020. cell_kind = `<span class="dirlist_item_details kind details" data-kind="${ item_sort_kind }">${ item_sort_kind }</span>`;
  2021. cell_ext = `<span class="ext details" data-ext="${ item_ext }"></span>`;
  2022. item_description = (item[3] !== undefined ? `<span class="desc dirlist_item_details"><i>Description</i>: ${ item[3] } </span>` : ''); // some servers provide a description of the item
  2023. // Assemble item
  2024. new_item = `<li id="${ parent_id }${ connector }rowid-${ (prepped_index.length - i) }" class="dirlist_item ${ item_classes }" data-name="${ item_sort_name.split("/")[0] }" data-kind="${ item_sort_kind }" data-ext="${ item_ext }" data-level="${ level }" ${ level_style }>${ cell_name } ${ cell_time } ${ cell_size } ${ cell_date } ${ cell_kind } ${ cell_ext } ${ item_description }</li>\n`;
  2025. if (/audio|video/.test(item_sort_kind)) {
  2026. media_count += 1; // if media item...
  2027. let media_kind = item_sort_kind,
  2028. media_item_id = parent_id + connector + 'rowid-' + (prepped_index.length - i),
  2029. is_subdir = (/subdirectory/.test(window.location.search) ? true : false);
  2030. if (media_count < 1000) {
  2031. getMediaDuration(item_link, media_kind, media_item_id, is_subdir);
  2032. }
  2033. else {
  2034. new_item = new_item.replace(/data-duration="">/, 'data-duration="0">[Error]');
  2035. } // get media duration (limit to 1000 calls)
  2036. }
  2037. new_index_items.push(new_item); // add item to index items
  2038. body_classes.add(item_info[5].join(' ')); // add item classes to body_classes
  2039. stats_kinds.push(item_sort_kind);
  2040. stats_total_size += Number(item_sort_size);
  2041. stats_classes.push(item_info[6]); // STATS: add item kind; update total size; add to stats classes
  2042. }
  2043. body_classes = [...body_classes].filter(body_class => body_class).sort(); // BODY CLASSES: body_classes to array, filter empty items, sort
  2044. stats = buildStats(stats_classes, stats_kinds, stats_total_size); // STATS: build stats
  2045. if (sort === '' || sort === undefined) {
  2046. sort = getCurrentUIPref('sort_by');
  2047. } // SORT ITEMS: get sort_by pref
  2048. let sort_direction = getCurrentUIPref('sort_direction'); // get sort_direction pref
  2049. let sorted_index_items = sortDirListItems(new_index_items, 'sort_by_' + sort, sort_direction); // make initial sort
  2050. return [sorted_index_items, body_classes.join(' '), stats, index_html]; // RETURN [sorted_index_items, body_classes, stats, index_html]
  2051. }
  2052. //==============================//
  2053. function getLinkInfo(link) { // ===> GET LINK INFO; returns [link,name,ext,kind,item_classes,body_classes,link_protocol]
  2054. switch (true) {
  2055. case link === undefined:
  2056. return; // return if link undefined
  2057. case link === null:
  2058. link = getEl('#content_iframe').src;
  2059. break; // link from opening local link files links in iframe
  2060. case link.startsWith('file://') && window.location.protocol === 'file:':
  2061. link = link.split('file://')[1];
  2062. break; // local links
  2063. case link.startsWith('/') && window.location.protocol === 'file:':
  2064. link = 'file://' + link;
  2065. break; // local links
  2066. case !link.startsWith('/') && !link.endsWith('/') && !/\./.test(link):
  2067. link = '/' + link + '';
  2068. break;
  2069. }
  2070. link = link.replace(/%3C/g, '\&lt;').replace(/\.pdf\..+/, '.pdf'); // fix and sanitize links
  2071. let URL = newURL(decodeURIComponentSafe(encodeURIComponent(link)));
  2072. let prepped_link, display_name, kind, ext, item_classes = [],
  2073. body_classes = [],
  2074. stats_classes = [],
  2075. aliases = new RegExp(/(symlink|alias|symbolic link)$/, 'm'),
  2076. link_protocol = URL.protocol;
  2077. switch (true) { // prep link
  2078. case window_protocol !== 'file:': // for non-local pages
  2079. switch (true) {
  2080. case URL.protocol === 'file:':
  2081. case URL.protocol === undefined:
  2082. prepped_link = link;
  2083. item_classes.push('local', 'ignored');
  2084. break; // local links from non-local pages
  2085. default:
  2086. prepped_link = URL.href; // non-local pages
  2087. }
  2088. break;
  2089. case window_protocol === 'file:': // for non-local pages
  2090. switch (true) {
  2091. case URL.protocol !== 'file:':
  2092. prepped_link = URL.href;
  2093. item_classes.push('non_local');
  2094. break;
  2095. default:
  2096. prepped_link = URL.pathname;
  2097. }
  2098. }
  2099. switch (true) { // prepare display name, body_classes, and item_classes
  2100. case (/youtube.com|youtu.be/.test(link) && !link.indexOf('/.')):
  2101. prepped_link = link.replace(/watch%3F/, 'watch?');
  2102. kind = 'video';
  2103. item_classes.push('video', 'media');
  2104. display_name = undefined;
  2105. break; // youtube videos from playlists
  2106. case URL.pathname.endsWith('/'):
  2107. case (/\.php\?/.test(link)): // nobreak; dirs, apps and index.php? links
  2108. display_name = (URL.pathname.endsWith('/') ? URL.pathname.split('/').reverse()[1] + '/' : /\.php\?/.test(link) ? link : null);
  2109. switch (true) {
  2110. case (/\.app$|\.app\/$|\.exe$/m.test(display_name)):
  2111. ext = 'app';
  2112. kind = ext; // apps
  2113. if (UI_Prefs_Bool.apps_as_dirs === false) {
  2114. item_classes.sort().unshift('file', 'app');
  2115. }
  2116. else {
  2117. item_classes.sort().unshift('dir', 'app');
  2118. }
  2119. break;
  2120. default:
  2121. ext = 'dir';
  2122. kind = 'dir';
  2123. item_classes.unshift(kind); // dirs; remove kind from item_classes
  2124. }
  2125. item_classes.push('non_media'); // add "non_media" to item_classes
  2126. if (display_name.startsWith('.')) {
  2127. item_classes.push('invisible');
  2128. stats_classes.push('invisible');
  2129. }
  2130. break;
  2131. default: // files
  2132. display_name = prepped_link.trim().split('/?')[0].split('/').reverse()[0];
  2133. switch (true) {
  2134. case display_name.toLowerCase().endsWith('symlink'):
  2135. ext = 'symlink';
  2136. break;
  2137. case !/\./.test(display_name):
  2138. ext = display_name.toLowerCase();
  2139. break; // if no '.' in link (typical for bin files), ...
  2140. default: // find the last . and get the remaining characters
  2141. ext = display_name.slice(display_name.lastIndexOf('.') + 1).toLowerCase();
  2142. for (let item_kind in Item_Kinds) {
  2143. if (Item_Kinds[item_kind].includes(ext)) {
  2144. kind = item_kind;
  2145. }
  2146. } // kind = types
  2147. if (/url|url\/|webloc|webloc\//.test(ext)) {
  2148. kind = 'link';
  2149. } // links
  2150. switch (true) {
  2151. case kind === 'audio':
  2152. item_classes.push('media');
  2153. body_classes.push('has_media', 'has_audio');
  2154. break;
  2155. case kind === 'video':
  2156. item_classes.push('media');
  2157. body_classes.push('has_media', 'has_video');
  2158. break;
  2159. case kind === 'font':
  2160. body_classes.push('has_fonts');
  2161. break;
  2162. case kind === 'image':
  2163. body_classes.push('has_images');
  2164. break;
  2165. }
  2166. if (Item_Settings.ignored.includes(ext)) {
  2167. item_classes.push('ignored');
  2168. stats_classes.push('ignored');
  2169. }
  2170. if (display_name.startsWith('.')) {
  2171. item_classes.push('invisible');
  2172. stats_classes.push('invisible');
  2173. }
  2174. }
  2175. if (kind === undefined) {
  2176. kind = 'other';
  2177. }
  2178. if (!/audio|video/.test(kind)) {
  2179. item_classes.push('non_media');
  2180. }
  2181. item_classes.unshift(kind);
  2182. item_classes.unshift('file');
  2183. prepped_link = decodeURIComponentSafe(encodeURIComponent(prepped_link))?.trim();
  2184. }
  2185. stats_classes.push(kind);
  2186. if (ext === undefined) {
  2187. ext = '';
  2188. }
  2189. if (aliases.test(display_name)) {
  2190. item_classes.push('alias');
  2191. }
  2192. for (let item_kind_system of Item_Kinds.system) {
  2193. if (display_name?.endsWith(item_kind_system)) {
  2194. item_classes.push('ignored');
  2195. }
  2196. } // ignore various system items
  2197. item_classes = Array.from(new Set(item_classes)).filter(item => item).join(' '); // remove dupe or empty classes, join
  2198. return [prepped_link, decodeURIComponentSafe(display_name)?.trim(), ext, kind, item_classes, body_classes, stats_classes.join(' '), link_protocol, URL.origin + URL.pathname];
  2199. }
  2200. //==============================//
  2201. function getItemSizeAndDate(item) { // ===> GET ITEM SIZE AND DATE
  2202. let item_size_and_date = [],
  2203. item_display_size, item_sort_size, item_display_date, item_sort_date, size_units = /[BYTES|B|K|KB|MB|GB|TB|PB|EB|ZB|YB]/;
  2204. if (item.length > 1) { // test for typical date/time separators.
  2205. if (/[-:\/]/.test(item[1])) {
  2206. item_display_date = item[1];
  2207. item_display_size = item[2];
  2208. }
  2209. else {
  2210. item_display_date = item[2];
  2211. item_display_size = item[1];
  2212. }
  2213. }
  2214. switch (true) { // get size
  2215. case item_display_size !== undefined && item_display_size.toLowerCase() === 'dir':
  2216. case (/undefined|—|-|,|\*/.test(item_display_size)):
  2217. case item_display_size === '':
  2218. item_display_size = '&mdash;';
  2219. item_sort_size = '0';
  2220. break; // if size is undefined, empty, or punctuation, use these defaults
  2221. default:
  2222. item_sort_size = getItemSortSize(item_display_size);
  2223. switch (true) {
  2224. case !item_display_size.toUpperCase().match(size_units):
  2225. item_display_size = formatBytes(item_display_size, 1);
  2226. break; // if provided size is only numeric, format byte size
  2227. default:
  2228. item_display_size = item_display_size.replace('K', 'k').replace(/(\d+)\s*([A-z])/, '$1 $2'); // default: format and ensure display size has space between number and units
  2229. }
  2230. break;
  2231. }
  2232. if (item_display_size === 'NaN undefined') {
  2233. item_display_size = '0 B';
  2234. }
  2235. // get date
  2236. if ([undefined, '', '-'].includes(item_display_date)) {
  2237. item_display_date = '&mdash;';
  2238. item_sort_date = '0';
  2239. }
  2240. else {
  2241. item_sort_date = getItemDate(item_display_date);
  2242. }
  2243. item_display_date = item_display_date.replace(/, (.+)/, '<wbr>,&nbsp$1').replace(/ (AM|PM)$/im, '<wbr> $1').replace(/\s/g, '&nbsp;'); // ensure that time acts as a block for wrapping in narrow sidebar
  2244. item_size_and_date.push(item_display_size, item_sort_size, item_display_date, item_sort_date);
  2245. return item_size_and_date;
  2246. }
  2247.  
  2248. function getItemSortSize(val) { // GET ITEM SORT SIZE
  2249. let sort_size, values = val.replace(/(\d+)\s*([A-z]+)/, '$1 $2').split(' '),
  2250. size = values[0],
  2251. unit = values[1];
  2252. const factor = {
  2253. undefined: 1,
  2254. '': 1,
  2255. B: 1,
  2256. K: 1000,
  2257. KB: 1000,
  2258. M: 1000000,
  2259. MB: 1000000,
  2260. G: 1000000000,
  2261. GB: 1000000000,
  2262. T: 1000000000000,
  2263. TB: 1000000000000,
  2264. P: 1000000000000000,
  2265. PB: 1000000000000000,
  2266. E: 1000000000000000000,
  2267. EB: 1000000000000000000,
  2268. Z: 1000000000000000000000,
  2269. ZB: 1000000000000000000000
  2270. }; // unit to file size
  2271. if (unit !== undefined) {
  2272. unit = unit.toUpperCase();
  2273. }
  2274. sort_size = size * factor[unit]; // convert byte size to multiplication factor
  2275. return sort_size;
  2276. }
  2277.  
  2278. function formatBytes(val, decimals) { // ===> FORMAT BYTES: format numeric sizes for display
  2279. const k = 1024,
  2280. dm = (decimals < 0 ? 0 : decimals),
  2281. sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
  2282. i = Math.floor(Math.log(val) / Math.log(k));
  2283. if (val === 0) {
  2284. return '0 Bytes';
  2285. }
  2286. else {
  2287. return parseFloat((val / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
  2288. }
  2289. }
  2290.  
  2291. function processDate(match, p1, p2, p3) { //***date formats: 2017-10-09 13:12 || 2015-07-25T02:02:57.000Z || 12-Mon-2017 21:11 ***// // ===> PROCESS DATE
  2292. const mo = 'JanFebMarAprMayJunJulAugSepOctNovDec'.indexOf(p2) / 3 + 1; // e.g., convert month into number, or use number
  2293. return p3 + '-' + mo + '-' + p1; // return assembled date: YYYY-MM-DD
  2294. }
  2295.  
  2296. function getItemDate(val) { // ===> GET ITEM DATE: for sorting (YYYY-MM-DD)
  2297. let sort_date = val.replace(/^(\d{2})-(\w{3})-(\d{4})/m, processDate) // convert Month to number
  2298. .replace(/\b(\d{1})[-:/]/g, '0$1/') // add leading 0 for single digit numbers
  2299. .replace(/(\d{2})\/(\d{2})\/(\d{2}),/, '$3$1$2') // reorder MM/DD/YY dates to YY/MM/DD
  2300. .replace(/-|:|\s+|\//g, ''); // remove spacing characters
  2301. return sort_date;
  2302. }
  2303. //==============================//
  2304. var getFormattedDuration = (secs) => { // ===> GET FORMATTED TIME
  2305. if (isNaN(secs)) {
  2306. return '[Error]';
  2307. } // if server refuses to load media
  2308. let sec_num = parseInt(secs, 10),
  2309. hours = Math.floor(sec_num / 3600),
  2310. minutes = Math.floor(sec_num / 60) % 60,
  2311. seconds = sec_num % 60;
  2312. let formattedTime = [hours, minutes, seconds].map(v => v < 10 ? "0" + v : v).filter((v, i) => v !== "00" || i > 0).join(":");
  2313. formattedTime = formattedTime.replace(/^0/m, '');
  2314. return formattedTime; // remove initial 0 and return formatted time
  2315. };
  2316. async function fetchAudioDuration(link, kind) {
  2317. return new Promise((resolve, reject) => {
  2318. const media = (kind === 'audio' ? new Audio() : document.createElement('video'));
  2319. media.addEventListener('loadedmetadata', () => {
  2320. resolve(media.duration);
  2321. });
  2322. media.addEventListener('error', reject);
  2323. media.src = link.replace(/\&amp;/g, '&');
  2324. });
  2325. }
  2326. async function getMediaDuration(link, media_kind, id, is_subdir) {
  2327. try {
  2328. const duration = await fetchAudioDuration(link, media_kind);
  2329. switch (true) {
  2330. case is_subdir === true:
  2331. messageSend('top_body', 'set_media_duration', '', [id, media_kind, duration]);
  2332. break; // if subdir, send message to top with duration
  2333. default:
  2334. setMediaDuration(id, media_kind, duration); // else set media duration
  2335. }
  2336. }
  2337. catch (error) {
  2338. setMediaDuration(id, media_kind, Number.NaN);
  2339. } // if error, set duration error
  2340. }
  2341.  
  2342. function setMediaDuration(id, kind, duration) { // ===> SET MEDIA DURATION
  2343. try {
  2344. if (id === 'content_iframe_file' || /youtube.com|youtu.be/.test(getEl('#' + id + ' a').href)) {
  2345. return;
  2346. } // do not attempt to set duration for iframe files or youtube playlist items
  2347. setAttribute('#' + id + ' .dirlist_item_media_duration', 'data-duration', duration);
  2348. switch (true) {
  2349. case duration !== 0:
  2350. getEl('#' + id + ' .dirlist_item_media_duration').innerText = getFormattedDuration(duration);
  2351. removeClass('#' + id, 'disabled');
  2352. getEl('#' + id).querySelector('input').removeAttribute('disabled');
  2353. break; // if duration !== 0, add time to dir_list item details; else show spinner
  2354. default:
  2355. addClass('#' + id, 'disabled'); // if duration === 0, disable media item
  2356. }
  2357. let totalDurationEl = getEl('#total_duration'),
  2358. total_duration;
  2359. if (totalDurationEl !== null) {
  2360. total_duration = Number(totalDurationEl.getAttribute('data-total_duration'));
  2361. total_duration += Number(duration);
  2362. setAttribute('#total_duration', 'data-total_duration', total_duration);
  2363. getEl('#total_duration').innerText = getFormattedDuration(total_duration);
  2364. }
  2365. }
  2366. catch (error) {
  2367. null
  2368. }
  2369. }
  2370.  
  2371. function updateMediaDurations(id, link, kind) {
  2372. let media_items;
  2373. switch (true) {
  2374. case id === 'refresh_media_durations': // click refresh media durations menu item
  2375. media_items = Array.from(getEls('.dirlist_item.media'));
  2376. media_items = media_items.filter(el => el.querySelector('.dirlist_item_media_duration').dataset.duration === "0");
  2377. media_items.forEach(el => updateMediaDurations(el.id, el.querySelector('a').href, el.dataset.kind)); // send each media item with id back to function for default processing
  2378. if (isTopWindow()) {
  2379. messageSend('iframe', 'refresh_media_durations');
  2380. }
  2381. break;
  2382. default:
  2383. if (getEl('#' + id)?.querySelector('.dirlist_item_media_duration')?.dataset.duration === '0') {
  2384. getMediaDuration(link, kind, (duration) => {
  2385. setMediaDuration(id, kind, duration);
  2386. });
  2387. }
  2388. break;
  2389. }
  2390. }
  2391.  
  2392. function updateDurations(bool) { // bool === true: don't bother updating stats details, since they aren't visible // ===> UPDATE DURATIONS
  2393. let media_items = getEls('.dirlist_item.media');
  2394. if (media_items.length === 0) {
  2395. removeClass('body', 'has_media has_audio has_video');
  2396. return;
  2397. }
  2398. let kind, total_duration = 0,
  2399. duration = 0,
  2400. audio_duration = 0,
  2401. video_duration = 0;
  2402. for (let i = 0; i < media_items.length; i++) { // get classes and kind for each item
  2403. kind = media_items[i].getAttribute('data-kind'); // = [link,name,ext,kind,item_classes,body_classes];
  2404. duration = Number(media_items[i].getElementsByClassName('dirlist_item_media_duration')[0].getAttribute('data-duration'));
  2405. setMediaDuration(media_items[i].getAttribute('id'), kind, duration);
  2406. total_duration += duration;
  2407. setAttribute('#total_duration', 'data-total_duration', total_duration);
  2408. getEl('#total_duration').innerText = getFormattedDuration(total_duration);
  2409. addClass('body', 'has_media');
  2410. switch (true) { // update stats details
  2411. case bool === true:
  2412. break;
  2413. case kind === 'audio':
  2414. addClass('body', 'has_audio');
  2415. audio_duration += Number(duration);
  2416. getEl('#stats_details_items').querySelectorAll('span.audio')[0].setAttribute('data-audio_duration', ' (Total Time: ' + getFormattedDuration(audio_duration) + ')');
  2417. break;
  2418. case kind === 'video':
  2419. addClass('body', 'has_video');
  2420. video_duration += Number(duration);
  2421. getEl('#stats_details_items').querySelectorAll('span.video')[0].setAttribute('data-video_duration', ' (Total Time: ' + getFormattedDuration(video_duration) + ')');
  2422. break;
  2423. }
  2424. }
  2425. }
  2426. //==============================//
  2427. function buildStats(stats_classes, stats_kinds, stats_total_size) { //*** BUILD STATS
  2428. stats_classes.sort();
  2429. let total_items = stats_classes.length,
  2430. counts = {},
  2431. kinds = [],
  2432. stats_items = [],
  2433. total_dirs = 0,
  2434. total_files = 0,
  2435. total_dirs_invisible = 0,
  2436. total_files_invisible = 0,
  2437. total_invisibles = '';
  2438. for (let i = 0; i < total_items; i++) { // Get counts
  2439. stats_classes[i] = stats_classes[i].split(' ').reverse().join(' ') // reorder classes to make invisible/ignored last
  2440. counts[stats_classes[i]] = 1 + (counts[stats_classes[i]] || 0); // get key/value pairs for item_classes/total counts
  2441. switch (true) {
  2442. case (!/invisible|ignored/.test(stats_classes[i])):
  2443. break; // don't count :not(.invisible) and :not(.ignored)
  2444. case (getCurrentUIPref('show_invisibles') === 'true') && (getCurrentUIPref('show_ignored_items') === 'false'): // show_invisibles && hide_ignored
  2445. if (/invisible/.test(stats_classes[i]) && /ignored/.test(stats_classes[i])) {
  2446. break;
  2447. } // don't count .invisible.ignored
  2448. if (/dir/.test(stats_classes[i])) {
  2449. total_dirs_invisible++;
  2450. }
  2451. else {
  2452. total_files_invisible++;
  2453. }
  2454. break; // else count .ignored
  2455. case (getCurrentUIPref('show_invisibles') === 'false') && (getCurrentUIPref('show_ignored_items') === 'false'): // hide_invisibles && hide_ignored (hide all)
  2456. if (/dir/.test(stats_classes[i])) {
  2457. total_dirs_invisible++;
  2458. }
  2459. else {
  2460. total_files_invisible++;
  2461. }
  2462. break; // count .invisible and .ignored (count all)
  2463. case (getCurrentUIPref('show_invisibles') === 'true') && (getCurrentUIPref('show_ignored_items') === 'true'):
  2464. break; // don't count .invisible or .ignored (count none)
  2465. case (getCurrentUIPref('show_invisibles') === 'false') && (getCurrentUIPref('show_ignored_items') === 'true'): // hide_invisibles && show_ignored
  2466. if (!/invisible/.test(stats_classes[i]) && /ignored/.test(stats_classes[i])) {
  2467. break;
  2468. } // don't count .ignored:not(.invisible)
  2469. if (/dir/.test(stats_classes[i])) {
  2470. total_dirs_invisible++;
  2471. }
  2472. else {
  2473. total_files_invisible++;
  2474. }
  2475. break; // else count .invisible and .invisible.ignored
  2476. }
  2477. }
  2478. for (let i = 0; i < stats_kinds.length; i++) {
  2479. kinds[stats_kinds[i]] = 1 + (kinds[stats_kinds[i]] || 0);
  2480. } // get key/value pairs for item kinds/counts
  2481. total_dirs = (kinds.dir || 0);
  2482. total_files = (total_items - total_dirs); // total dirs && files count
  2483. if (getCurrentUIPref('show_invisibles') === 'false' || getCurrentUIPref('show_ignored_items') === 'false') {
  2484. total_invisibles = ' (+' + (total_dirs_invisible + total_files_invisible) + ')';
  2485. total_items = total_items - (total_dirs_invisible + total_files_invisible);
  2486. total_dirs = total_dirs - total_dirs_invisible;
  2487. total_files = total_files - total_files_invisible;
  2488. }
  2489. for (let count in counts) { // make detail item for each kind of dirlist item --> doesn't preserve order
  2490. let kinds_items = count.split(' '),
  2491. temp_items = [],
  2492. stats_Item_Kinds = '';
  2493. kinds_items.forEach(item => (!/ignored|invisible/.test(item) ? temp_items.unshift(item) : temp_items.push(item)));
  2494. kinds_items = temp_items;
  2495. kinds_items.forEach(item => (stats_Item_Kinds += (`<span class="${ item }" >` + (/ignored|invisible/.test(item) ? ' (' + item + ')' : item.trim()) + `</span>`)));
  2496. let stats_item = `<li class="stats_list_item display_grid ${ kinds_items[0] }" data-kind="${ kinds_items[0] }"><a class="icon stats_list_item_name_a display_flex" data-count="${ counts[count] }"><span class="has_icon_before_before"></span><span class="stats_list_item_name_a_span">${ stats_Item_Kinds }</span></a></li>`;
  2497. stats_items.push(stats_item);
  2498. }
  2499. stats_items.sort();
  2500. return `<nav id="stats_container" class="display_flex width_100"><div id="stats" class="normal pointer overflow_hidden font_size_small"> <ol id="stats_summary" class="background_grey_80 text_color_default margin_0 padding_0"> <li class="stats_list_item line_height_1_2 no_highlight padding_4_8"><span id="stats_summary_totals" class="display_flex align_left" data-size="${ stats_total_size }">${ total_items } Items${ total_invisibles }: ${ total_dirs } Dirs, ${ total_files } Files (${ formatBytes(stats_total_size,2) })</span><span id="total_duration" class="display_none" data-total_duration=""></span></li> </ol> <ol id="stats_details_summary" class="border_bottom position_relative background_grey_80 text_color_default margin_0 padding_0 display_none"> <li id="stats_details_summary_total" class="summary_detailed border_bottom padding_4_8 no_highlight"><span>${ total_items } Items (${ total_dirs_invisible + total_files_invisible } invisible or ignored)</span></li> <li id="stats_details_summary_dirs" class="stats_list_item line_height_1_2 dir summary_detailed background_grey_85 padding_0"><a class="icon stats_list_item_name_a display_flex" data-count="${ total_dirs }"> <span class="stats_list_item_name_a_span display_flex has_icon_before stats_kind">Dirs (${ total_dirs_invisible } invisible or ignored)</span> </a></li> <li id="stats_details_summary_files" class="stats_list_item line_height_1_2 file summary_detailed background_grey_85 padding_0"><a class="icon stats_list_item_name_a display_flex" data-count="${ total_files }"><span class="stats_list_item_name_a_span display_flex has_icon_before stats_kind">Files (${ total_files_invisible } invisible or ignored)</span></a></li> </ol> <div id="stats_details_items_container"> <ol id="stats_details_items" class="margin_0 padding_0 position_relative display_none"> ${ stats_items.join('\n') } </ol> </div> </div></nav>`;
  2501. }
  2502.  
  2503. function updateStats(bool) { // ===> UPDATE STATS (bool: add or subtract size from total)
  2504. let items = getEls('.dirlist_item'); // get all dir_list items
  2505. let stats_classes = [],
  2506. stats_kinds = [],
  2507. item_classlist = [],
  2508. total_size = 0; // define various arrays
  2509. getEls('.dirlist_item_details.size').forEach(el => total_size += Number(el.dataset.size));
  2510. let total_item_size = (bool === false ? total_size : Number(getData('#stats_summary_totals', 'size')));
  2511. let item_info;
  2512. for (let i = 0; i < items.length; i++) { // get classes and kind for each item
  2513. item_info = getLinkInfo(items[i].getElementsByClassName('dirlist_item_name_a')[0].href); // get item info = [link,name,ext,kind,item_classes,body_classes];
  2514. item_classlist = item_info[4]; // get item_classlist
  2515. item_classlist = item_classlist.replace(/file|media|audio_loaded|content_loaded|has_subdirectory|selected|non_/g, '').trim(); // remove unwanted classes --> why file and media?
  2516. stats_classes.push(item_classlist); // add item_classlist to stats_classes
  2517. stats_kinds.push(item_info[3]); // add Item_Kinds to stats_kinds
  2518. total_item_size += Number(items[i].querySelector('.size').dataset.size);
  2519. }
  2520. getEl('#stats_container').remove(); // remove old stats
  2521. getEl('#dir_footer').insertAdjacentHTML('afterbegin', buildStats(stats_classes, stats_kinds, total_item_size, 2)); // build new stats and add to dir_footer
  2522. updateDurations(true); // update after building stats
  2523. initStatsEvents(); // initial event listeners for new stats items
  2524. }
  2525. // ***** END DIR_LIST SETUP ***** //
  2526. //============================//
  2527. // ***** UI SETUP ***** //
  2528. function prepDocHead(agent) { // ===> PREP DOC HEAD
  2529. document.title = 'Index of ' + window_location; // change the doc title to current location
  2530. for (let attr_name of getEl('html').getAttributeNames()) {
  2531. getEl('html').removeAttribute(attr_name);
  2532. } // remove html attributes, if any
  2533. getEl('head title').removeAttribute('id');
  2534. getEls('head meta, head base, head link, head style, head script, head noscript').forEach(headEl => headEl.remove()); // remove various head elements
  2535. let head_content = '<meta charset="utf-8"><base href="' + window.location.origin + '">' + getEl('head').innerHTML.replace(/<!--(?!>)[\S\s]*?-->/g, ''); // add meta and remove conditional comments
  2536. if (window.location.protocol.startsWith('file')) {
  2537. head_content = get_SVG_UI_File_Icon('favicon') + head_content;
  2538. } // add custom favicon for local directories
  2539. getEl('head').innerHTML = head_content + addStyles(agent); // replace head content with prepped content
  2540. }
  2541.  
  2542. function getUIPrefBodyClasses(agent) { // ===> GET UI PREF BODY CLASSES and other initial settings
  2543. let queries = new URLSearchParams(window.location.search).entries(); // make new search params from window.location.search
  2544. queries = Object.fromEntries(queries);
  2545. let body_classes = [],
  2546. settings = Object.assign({}, queries, UI_Settings); // merge UI_Settings and query settings
  2547. for (let key in settings) {
  2548. switch (true) {
  2549. case ['grid_font_size', 'grid_image_size', 'ui_font', 'ui_scale', 'show_image_thumbnails'].includes(key):
  2550. break; // ignore these keys (values set in css or by buildTextEditorUI)
  2551. case ['sort_by', 'sort_direction', 'theme', 'texteditor_view'].includes(key):
  2552. body_classes.push(key + '_' + getCurrentUIPref(key));
  2553. break; // other non-booleans: class = key + value
  2554. case getCurrentUIPref(key) === 'false':
  2555. body_classes.push(key + '_false');
  2556. break; // booleans: only add false values
  2557. }
  2558. }
  2559. body_classes.push(agent);
  2560. body_classes.push('is_' + getOS()); // add browser and os classes
  2561. return body_classes.sort().join(' ');
  2562. }
  2563.  
  2564. function makeNewIndex(el, sort, agent, body_id) { // ===> MAKE NEW INDEX
  2565. const index_items = getIndexItems(agent),
  2566. items = index_items[0],
  2567. type = index_items[1];
  2568. const converted_index = convertIndexItems(items, type); // = array of rows: ["link","date","size"]
  2569. switch (type) {
  2570. case 'error':
  2571. return [
  2572. [
  2573. ['<tr id="is_error"><td id="is_error_items" class="padding_6_8">' + (items === undefined ? '' : items) + '</td></tr>'], 'is_error'
  2574. ], '', '', index_items
  2575. ];
  2576. default:
  2577. return [buildNewIndex(el.id, converted_index, sort, type, body_id)];
  2578. }
  2579. }
  2580. // ===> BUILD IFRAME DIR LIST UI, with utility iframe for subdirectories add
  2581. function buildIframeUI(src, file_name, agent) {
  2582. let parent_link = src.split('/').slice(0, -2).join('/') + '/',
  2583. query_str = new URLSearchParams(window.location.search.toString().slice(1));
  2584. let subdirectory = query_str.get('subdirectory') || null,
  2585. body_id = query_str.get('body_id');
  2586. let iframe_directory, iframe_head, iframe_dir_list, content_body, gecko_styles, body_classes, iframe_utility_iframe, new_index, make_new_index, additional_classes;
  2587. window.onmessage = function (e) {
  2588. messageReceive(e);
  2589. return;
  2590. } // init receive messages
  2591. switch (true) {
  2592. case window.location.search === "": // nobreak; case is true when opening dirs from sidebar source dir
  2593. case (query_str.get('show_directory_source') || query_str.get('is_error')) === 'true':
  2594. if (elExists('#iframe_dir_styles')) {
  2595. getEl('#iframe_dir_styles').remove();
  2596. }
  2597. break; // do nothing when viewing directory source or if error page...
  2598. default: // ...else set up iframe directory:
  2599. iframe_head = getEl('head');
  2600. content_body = getEl('body');
  2601. iframe_dir_list = '';
  2602. gecko_styles = '';
  2603. body_classes = [];
  2604. iframe_utility_iframe = '<iframe id="content_iframe_utility" sandbox="allow-scripts allow-same-origin allow-modals allow-popups" style="display:none;"></iframe>';
  2605. if (/\.php\?/.test(src)) {
  2606. query_str = new URLSearchParams(makeSrcSearchParams('dir'));
  2607. } // define default params for index.php?folder=... pages
  2608. for (let key of query_str.keys()) { // add various body_classes...
  2609. switch (true) {
  2610. case (/show_details|ui_font/.test(key)):
  2611. break; // show details by default
  2612. case query_str.get(key) === 'true':
  2613. break; // ignore true booleans
  2614. case query_str.get(key) === 'false':
  2615. body_classes.push(key + '_false');
  2616. break; // add body classes for false boolean params
  2617. default:
  2618. body_classes.push(key + '_' + getCurrentUIPref(key));
  2619. break; // non-boolean params (theme, sort)
  2620. }
  2621. }
  2622. if (agent === 'is_gecko') {
  2623. gecko_styles = ('<style id="gecko_style_rules">' + gecko_style_rules + '</style>');
  2624. }
  2625. new_index = makeNewIndex(content_body, query_str.get('sort_by'), '', body_id); // make new index
  2626. make_new_index = new_index[0];
  2627. additional_classes = (new_index[0][1].trim().split(/\s+/)).concat(body_classes); // define additional body classes
  2628. if (!/is_error/.test(new_index[0][1])) { // if not an a error page...build the ui
  2629. iframe_head.querySelectorAll('style,script,meta,link[rel="stylesheet"],link[href$="css"]').forEach(el => el.remove()); // remove any existing directory index styles
  2630. iframe_head.insertAdjacentHTML('beforeend', `<style id="iframe_dir_styles">${iframe_dir_styles }</style><style id="sidebar_styles">${ sidebar_styles }</style><style>${ content_pane_styles }</style><style id="font_styles"></style><style id="font_grid_styles"></style>${gecko_styles}`); // assemble the iframe head
  2631. switch (true) { // Assemble content_iframe and utility_iframe content
  2632. case subdirectory === 'true':
  2633. iframe_dir_list = `<div id="directory_list_outer"><ol id="directory_list" class="border_bottom text_color_default">${ make_new_index[0] }</ol></div>`;
  2634. break;
  2635. default:
  2636. iframe_directory = Directory_Elements('iframe', parent_link); // create iframe directory elements
  2637. iframe_dir_list = iframe_directory.replace(/insert_prepped_index/, make_new_index[0]).replace(/insert_stats/, make_new_index[2]); // assemble iframe directory
  2638. content_body.removeAttribute('style');
  2639. content_body.style.fontFamily = getCurrentUIPref('ui_font'); // remove any body inline styles; set ui_font
  2640. content_body.classList.add(...additional_classes); // add body styles
  2641. }
  2642. content_body.innerHTML = iframe_dir_list + Content_Pane_Elements; // append iframe_dir_list and content_pane for quicklook
  2643. }
  2644. if (subdirectory === null) {
  2645. content_body.insertAdjacentHTML('beforeend', iframe_utility_iframe);
  2646. initIframeEvents();
  2647. } // don't multiply utility_iframes; init iframe event listeners
  2648. if (subdirectory === 'true') {
  2649. messageSend('top_body', 'dirlist_subdir_loaded', '', [getEl('#directory_list').innerHTML, make_new_index[1], getCurrentUIPref('parent_id')]); // send prepped subdir to parent window
  2650. }
  2651. else {
  2652. messageSend('top_body', 'iframe_loaded', '', [src, file_name, 'dir']); // else send iframe_loaded message
  2653. }
  2654. }
  2655. }
  2656. // ===> BUILD TEXT EDITOR UI
  2657. function buildTextEditorUI(kind) {
  2658. let raw_markdown, body_classes = [],
  2659. content;
  2660. if (!hasClass('body', 'has_texteditorUI')) { // add classes, styles, and scripts; only add once
  2661. getEl('head').insertAdjacentHTML('beforeend', '<style id="texteditor_styles">' + texteditor_styles + '</style>');
  2662. getEl('head').insertAdjacentHTML('beforeend', '<link id="github_markdown_css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css"></link>');
  2663. if (isTopWindow()) {
  2664. getEl('#content_title span').innerHTML = '';
  2665. }
  2666. body_classes.push('has_texteditorUI', 'texteditor_view_' + getCurrentUIPref('texteditor_view'));
  2667. }
  2668. switch (true) { // get source text and append UI elements
  2669. case !isTopWindow(): // iframe text editing UI
  2670. window.onmessage = function (e) {
  2671. messageReceive(e);
  2672. return false;
  2673. } // init receive messages is_link
  2674. getEl('head').insertAdjacentHTML('afterbegin', '<meta charset="utf-8" /><meta http-equiv="Content-Type" content="text/plain; charset="utf-8">');
  2675. getEl('head').insertAdjacentHTML('beforeend', '<style id="global_styles">' + global_styles + '</style><style id="utilities_styles">' + utilities_styles + '</style>'); // add iframe text editing styles
  2676. if (kind === 'link') {
  2677. tempHideTexteditor();
  2678. } // prevent FOUC for some kinds of content...
  2679. raw_markdown = decodeURIComponentSafe(getEl('body').innerText); // get source text and decode Unicode chars.
  2680. document.body.innerHTML = Content_Text_Elements + Utilities_Elements('texteditor'); // add the UI
  2681. getEl('#texteditor_txt_pane').value = raw_markdown; // set the source text value
  2682. getEl('#texteditor_txt_pane').setSelectionRange(0, 0); // set the insertion point to the beginning of the text
  2683. if (/^\#EXTM3U/m.test(getEl('#texteditor_txt_pane').value)) {
  2684. content = getEl('#texteditor_txt_pane').value.trim();
  2685. messageSend('top_body', 'iframe_playlist', '', content);
  2686. } // playlists & filelists
  2687. addClass('body', 'is_text');
  2688. getSearchParams().forEach((key, value) => {
  2689. addClass('body', value + "_" + key);
  2690. }); // add text editor body classes
  2691. break;
  2692. }
  2693. switch (true) { // assemble text editing body classes
  2694. case getCurrentUIPref('text_editing_enable') === 'false' && !isTopWindow(): // if text editing disabled...
  2695. removeClass('body', 'texteditor_view_preview texteditor_view_html'); // remove preview and html classes
  2696. body_classes.push('texteditor_view_raw', 'text_editing_enable_false', 'texteditor_split_view_false'); // show the raw text, no split view
  2697. getEl('#texteditor_txt_pane').disabled = true;
  2698. break; // disable textarea editing
  2699. default: // ...otherwise set up text editing
  2700. if (getCurrentUIPref('texteditor_split_view') === 'false') {
  2701. body_classes.push('texteditor_split_view_false');
  2702. }
  2703. else {
  2704. body_classes.push('texteditor_view_raw');
  2705. }
  2706. if (getCurrentUIPref('texteditor_sync_scroll') === 'false') {
  2707. body_classes.push('texteditor_sync_scroll_false');
  2708. getEl('#texteditor_sync_scroll input').checked = false;
  2709. }
  2710. if (getCurrentUIPref('texteditor_sync_scroll') === 'true') {
  2711. getEl('#texteditor_sync_scroll input').checked = true;
  2712. }
  2713. }
  2714. TextEditing();
  2715. initTextEditorEvents(); // text editing functions & init text editor event listeners
  2716. }
  2717. // ===> BUILD UI: Append all assembled elements to body
  2718. function buildUI() {
  2719. let make_new_index, body_classes, main_content, agent = getBrowser(),
  2720. link_info, file_name, kind, iframe_src;
  2721. switch (true) {
  2722. case isTopWindow(): // if it's not an iframe...
  2723. make_new_index = makeNewIndex('body', '', agent, 'top_body'); // make index
  2724. if (make_new_index[0] === undefined) {
  2725. return;
  2726. } // in case user cancels processing of large directory > 5000 items
  2727. body_classes = make_new_index[0][1] + ' ' + getUIPrefBodyClasses(agent); // delete extra spaces, create array of body class names
  2728. main_content = `${ Directory_Elements('top_body') } ${ Content_Pane_Elements } ${ Utilities_Elements('top_body') }`; // assemble html elements
  2729. if (make_new_index[0][1] !== 'is_error') {
  2730. main_content = main_content.replace(/insert_prepped_index/, make_new_index[0][0]).replace(/insert_stats/, make_new_index[0][2]); // add dir_index and stats to MainContent
  2731. }
  2732. else {
  2733. main_content = main_content.replace(/insert_prepped_index/, '').replace(/<ul id=\"dir_header_utilities_row_1[\s\S]+Show Font Grid<\/li>\s*<\/ul>\s*<\/li>\s*<\/ul>/m, '').replace(/<ul id=\"show_texteditor[\s\S]+Text Editor<\/span><\/li><\/ul>/, '').replace(/<footer[\s\S]+footer>/, '');
  2734. }
  2735. document.body.innerHTML = ''; // remove body contents
  2736. prepDocHead(agent); // add title, favicon, meta tags, styles to head
  2737. setAttribute('body', 'id', 'top_body'); // add body id
  2738. setAttribute('body', 'lang', 'en'); // add body lang attr
  2739. if (document.body.getAttribute('class') !== null) {
  2740. document.body.removeAttribute('class');
  2741. } // remove body classes, if any
  2742. addClass('body', body_classes); // add body classes
  2743. document.body.innerHTML = main_content; // add main content to body
  2744. uiPrefFontSet();
  2745. uiPrefScaleSet(null, Number(getCurrentUIPref('ui_scale')), true); // set ui font and scale
  2746.  
  2747. if (make_new_index[0][1] !== 'is_error') {
  2748. initEvents();
  2749. autoLoadItems();
  2750. }
  2751. else {
  2752. initBaseEvents();
  2753. showDirectorySource(window.location.origin + window.location.pathname + '?error=is_error');
  2754. addClass('#content_iframe', 'has_content');
  2755. }
  2756. break;
  2757. case !isTopWindow() && !window.location.pathname.endsWith('.pdf'): // if iframe and not pdf (i.e. embed el), setup iframe UI
  2758. iframe_src = window.location.href;
  2759. link_info = getLinkInfo(iframe_src);
  2760. file_name = link_info[1];
  2761. kind = link_info[3];
  2762. setAttribute('body', 'id', 'content_body'); // add iframe body id
  2763. switch (true) { // determine UI type...
  2764. case (/\.php\?/.test(iframe_src)): // attempt to deal with some .php?folder links
  2765. case (/app|dir/.test(kind) && !/is_error/.test(iframe_src)):
  2766. buildIframeUI(iframe_src, file_name, agent);
  2767. addClass('body', 'is_dir');
  2768. break; // if dir, set up iframe dir list UI
  2769. case kind === 'link':
  2770. case link_info[2] === 'cuetxt':
  2771. main_content = document.body.innerText; // nobreak; if link or cuetxt, send file content to top
  2772. case (/code|text|markdown|other/.test(kind)):
  2773. buildTextEditorUI(kind);
  2774. addClass('body', 'is_text'); // if text file, set up iframe text editor
  2775. main_content = getEl('#texteditor_txt_pane').value;
  2776. break; // get text content for optional processing (cuetxt)
  2777. case kind === 'htm':
  2778. main_content = getEl('html').outerHTML;
  2779. addClass('body', 'is_html'); // nobreak; if html file, get innerHTML
  2780. default:
  2781. initIframeEvents();
  2782. break; // if any other iframe content
  2783. }
  2784. messageSend('top_body', 'iframe_loaded', '', [iframe_src, file_name, kind, null, main_content]); // send iframe_loaded message (not dir|link file) with args
  2785. break;
  2786. }
  2787. uiPrefImgThumbsToggle(getCurrentUIPref('show_image_thumbnails')); // load image thumbnails after building ui
  2788. }
  2789. buildUI();
  2790. //============================//
  2791. // INITIALIZE EVENT LISTENERS
  2792. function initEvents() {
  2793. if (window.parent !== window.top) {
  2794. return;
  2795. }
  2796. initBaseEvents();
  2797. initDirListEvents();
  2798. initStatsEvents();
  2799. initWarningEvents(); // ===> INIT EVENT LISTENERS // init base events, stats events, and dir list events
  2800. getEl('#default_settings').onclick = function (e) {
  2801. uiPrefsReset(e);
  2802. }; // settings to default
  2803. getEl('#show_directory_source').onclick = function (e) {
  2804. e.stopPropagation();
  2805. showWarning('showDirectorySource');
  2806. }; // toggle show directory source
  2807. getEl('#open_in_content_pane').onclick = function (e) {
  2808. e.stopPropagation();
  2809. showWarning('openSidebarInContentPane');
  2810. }; // open sidebar in content pane
  2811. getEl('#open_in_texteditor').onclick = function (e) {
  2812. e.preventDefault();
  2813. openInTextEditor();
  2814. }; // openInTextEditor
  2815. getEls('#open_font_label, #open_playlist_label, textarea, div[contenteditable], select, #scale').forEach(el => el.onclick = function (e) {
  2816. e.stopPropagation();
  2817. }); // stopProp on various clicks
  2818. getEls('#show_font_grid, #show_grid_btn, #show_image_grid, #show_texteditor, #texteditor').forEach(el => el.onclick = function (e) {
  2819. eStopPrevent(e);
  2820. showThis(el.id, false, true);
  2821. }); // show grids or text editor
  2822. getEl('#show_grid_btn').onmouseenter = function () {
  2823. addClass('body', 'has_menu_grid');
  2824. };
  2825. getEl('#show_grid_btn').onmouseleave = function () {
  2826. removeClass('body', 'has_menu_grid');
  2827. };
  2828. getEl('#close_audio').onclick = function (e) {
  2829. e.stopPropagation();
  2830. showMedia('close_audio');
  2831. }; // close audio button click
  2832. getEl('#dir_footer').onclick = function () {
  2833. removeClass('.dirlist_item', 'hovered');
  2834. }; //
  2835. getEl('#content_image').onclick = function (e) {
  2836. e.stopPropagation();
  2837. scaleImages(e);
  2838. }; // Zoom image on click
  2839. getEls('#content_title,#content_audio_title').forEach(el => el.onclick = function () {
  2840. playlistShowItem(el.id);
  2841. });
  2842. getEls('#open_font,#open_playlist').forEach(el => el.onclick = function (e) {
  2843. openFiles(e, el.id);
  2844. }); // Open files (onclick show warnings)
  2845. getEls('#open_font,#open_playlist').forEach(el => el.onchange = function (e) {
  2846. e.preventDefault();
  2847. e.stopPropagation();
  2848. openFiles(e, el.id);
  2849. }); // Open font and playlist files
  2850. getEl('#go_to_item').onclick = function (e) {
  2851. goToItem(e);
  2852. }; // Go to item
  2853. getEl('#show_invisible_items').onclick = function () {
  2854. getEl('#show_invisibles').click();
  2855. getEl('#show_invisibles').blur();
  2856. } //
  2857. getEl('#play_toggle').onclick = function (e) {
  2858. toggleAllChecked(e);
  2859. }; // toggle media checkboxes
  2860. getEl('#make_playlist').onclick = function (e) {
  2861. eStopPrevent(e);
  2862. showWarning('warning_make_playlist');
  2863. }; // make playlist
  2864. getEl('#save_svg').onclick = function (e) {
  2865. e.stopPropagation();
  2866. fontGlyphSave();
  2867. }; // save glyph as svg
  2868. getEl('#dir_footer_utilities').onmouseenter = function () {
  2869. addClass('body:not(.has_menu), body:not(.has_menu_parents)', 'has_menu_footer');
  2870. };
  2871. getEl('#dir_footer_utilities').onmouseleave = function () {
  2872. removeClass('body:not(.has_menu), body:not(.has_menu_parents)', 'has_menu_footer');
  2873. };
  2874. getEls('.prev_next_btn').forEach(el => el.onclick = function (e) {
  2875. contentHeaderButtons(e, el.id);
  2876. }); // ============> combine with next?
  2877. getEls('#increase,#decrease').forEach(el => el.onmousedown = function (e) {
  2878. e.preventDefault();
  2879. contentHeaderButtons(e, this.id);
  2880. }); // onclick scale buttons
  2881. getEls('#audio,#content_video').forEach(el => el.onended = function () {
  2882. navigateByArrowKey(['ArrowRight', true]);
  2883. }); // autoplay media onended
  2884. getEls('#loop_media_files,#shuffle_media_files,#audio_options input,#audio_options label').forEach(el => el.onclick = function (e) {
  2885. el.blur();
  2886. mediaPlaybackOptions(e, el.id);
  2887. }); // media loop/shuffle options
  2888. getEl('#refresh_media_durations').onclick = function () {
  2889. updateMediaDurations('refresh_media_durations');
  2890. };
  2891. getEls('#parent_dir_nav #svg_multiply,#close_playlist').forEach(el => el.onclick = function (e) {
  2892. e.preventDefault();
  2893. e.stopPropagation();
  2894. showWarning('closeContent', ['closePlaylist', 'false']);
  2895. });
  2896. }
  2897.  
  2898. function initBaseEvents() { // ===> INIT BASE EVENT LISTENERS: minimal listeners needed for error pages
  2899. window.onmessage = function (e) {
  2900. messageReceive(e);
  2901. return false;
  2902. } // init receive messages
  2903. document.body.onclick = function () {
  2904. menuClose();
  2905. }; // close menu click
  2906. getEls('.menu_container').forEach(el => el.onclick = function (e) {
  2907. e.stopPropagation();
  2908. menuShow(e, el.id);
  2909. }); // toggle menus on click
  2910. getEls('#dir_menu_main li').forEach(el => el.onclick = function (e) {
  2911. e.stopPropagation();
  2912. menuClick();
  2913. menuClose(e);
  2914. });
  2915. getEls('#dir_menu_main li').forEach(el => el.onmouseenter = function () {
  2916. removeClass('#dir_menu_main li', 'selected hovered');
  2917. addClass('#dir_menu_main li:hover', 'selected');
  2918. });
  2919. getEls('.toggle_UI_pref').forEach(el => el.onclick = function (e) {
  2920. uiPrefToggleOnClick(e, this.id);
  2921. menuClose(e);
  2922. }); // toggle UI prefs click
  2923. getEl('#font_toolbar').onclick = function (e) {
  2924. e.stopPropagation();
  2925. }
  2926. getEls('#dir_wrapper,#content_header').forEach(el => el.onclick = function (e) {
  2927. e.stopPropagation();
  2928. focusEl('#top_body');
  2929. }); // focus sidebar on click
  2930. getEls('#content_pane, #content_pane .content_el').forEach(el => el.onclick = function (e) {
  2931. e.stopPropagation();
  2932. focusEl('#' + el.id);
  2933. }); // focus content on click
  2934. getEl('#ui_font').onclick = function (e) {
  2935. uiPrefFontSet(e, this.id)
  2936. }; // show the UI font textarea
  2937. getEl('#ui_scale input').oninput = function (e) {
  2938. e.stopPropagation();
  2939. setData('#ui_scale span.menu_item', 'value', Math.round(this.value) + '%');
  2940. }; // show scale %
  2941. getEl('#ui_scale input').onmouseup = function (e) {
  2942. uiPrefScaleSet(e, this.value);
  2943. }; // scale UI
  2944. getEl('#ui_scale').ondblclick = function (e) {
  2945. uiPrefScaleSet(e, 100)
  2946. }; // set 100% scale on dblclick
  2947. getEl('#show_help').onclick = function (e) {
  2948. e.preventDefault();
  2949. addClass('#top_body', 'has_help');
  2950. }; // show help click
  2951. getEl('#close_help').onclick = function (e) {
  2952. e.preventDefault();
  2953. removeClass('body', 'has_help');
  2954. }; // close help click
  2955. getEl('#help_container').onclick = function (e) {
  2956. e.stopPropagation();
  2957. }; // help container: ignore clicks
  2958. getEl('#close_btn').onclick = function (e) {
  2959. eStopPrevent(e);
  2960. closeContent();
  2961. this.blur();
  2962. }; // close button
  2963. getEl('#reload_btn').onclick = function (e) {
  2964. eStopPrevent(e);
  2965. resetContent();
  2966. this.blur();
  2967. this.classList.remove('reset');
  2968. }; // reset btn
  2969. getEl('#handle').onmousedown = function (e) {
  2970. resizeSidebar(e);
  2971. } // resize sidebar
  2972. document.addEventListener('mouseup', function () {
  2973. document.onmousemove = null;
  2974. }); // revoke drag on mouseup
  2975. document.addEventListener('mousemove', function () {
  2976. removeClass('body', 'no_hover');
  2977. }); // remove no_hover class
  2978. }
  2979.  
  2980. function initWarningEvents() {
  2981. getEls('#warnings_container button')?.forEach(el => el.onclick = function (e) {
  2982. eStopPrevent(e);
  2983. warningButtons(el.id);
  2984. });
  2985. getEls('body.has_overlay, body.has_warning').forEach(el => el.onclick = function (e) {
  2986. eStopPrevent(e);
  2987. return;
  2988. }); // prevent user actions with warning or overlay
  2989. getEls('body.has_overlay, body.has_warning').forEach(el => el.onmousedown = function (e) {
  2990. eStopPrevent(e);
  2991. return;
  2992. }); // prevent user actions with warning or overlay
  2993. getEls('body.has_overlay, body.has_warning').forEach(el => el.onmouseup = function (e) {
  2994. eStopPrevent(e);
  2995. return;
  2996. }); // prevent user actions with warning or overlay
  2997. }
  2998.  
  2999. function initDirListEvents() {
  3000. if (!isTopWindow()) {
  3001. return;
  3002. } // ===> INIT DIR_LIST EVENT LISTENERS; called whenever new dir list items added
  3003. getEls('.dirlist_item')?.forEach(el => el.onclick = function (e) {
  3004. clickDirListItem(e, el.id);
  3005. }); // show item or play/pause media
  3006. getEls('.dirlist_item.dir .has_icon_before_before')?.forEach(el => el.onclick = function (e) {
  3007. subDirOpenClose(e, el.closest('.dirlist_item').id);
  3008. }); // open/close subdirectories
  3009. getEls('.dirlist_item.dir')?.forEach(el => el.ondblclick = function (e) {
  3010. e.preventDefault();
  3011. showWarning('dirOpen', [el.id, el.querySelector('a').href]);
  3012. });
  3013. getEls('.dirlist_item.link')?.forEach(el => el.ondblclick = function (e) {
  3014. openLinkFile(e, el.id);
  3015. }); // open link files on dblclick
  3016. getEls('.dirlist_item.media input')?.forEach(el => el.onmousedown = function (e) {
  3017. toggleChecked(e, el.closest('.dirlist_item').id);
  3018. }); // toggle media checkboxes
  3019. getEls('.dirlist_item.media input')?.forEach(el => el.onclick = function (e) {
  3020. el.blur();
  3021. e.preventDefault();
  3022. e.stopPropagation();
  3023. }); // Click media checkboxes
  3024. getEls('.dirlist_item.playlist')?.forEach(el => el.ondblclick = function (e) {
  3025. eStopPrevent(e);
  3026. clickThis('#open_playlist');
  3027. }); // open playlist
  3028. getEls('.dirlist_item.non_local')?.forEach(el => el.onmouseenter = function () {
  3029. el.title = 'Non-local file';
  3030. }); // add non-local title prop
  3031. getEl('#show_invisibles_container')?.addEventListener('click', function (e) {
  3032. e.stopPropagation();
  3033. clickThis('#show_invisibles_container input');
  3034. });
  3035. }
  3036.  
  3037. function initStatsEvents() { // ===> INIT STATS EVENT LISTENERS
  3038. getEl('#stats')?.addEventListener('mouseleave', function () {
  3039. menuClose();
  3040. });
  3041. getEl('#stats_summary')?.addEventListener('click', function (e) {
  3042. e.stopPropagation();
  3043. menuShow(e, 'stats_summary');
  3044. }); // show stats
  3045. getEls('#stats_details_items li, #stats_details_summary_dirs, #stats_details_summary_files')?.forEach(el => el.onmouseenter = function () {
  3046. getEls('.dirlist_item' + statsGetHoveredListClass(el))?.forEach(el => el.classList.add('hovered')); // add the hovered class
  3047. getEl('.dirlist_item.hovered')?.scrollIntoView({
  3048. behavior: 'smooth',
  3049. block: 'nearest',
  3050. inline: 'nearest'
  3051. }); // scroll 1st matched el
  3052. });
  3053. getEl('#stats_details_summary_total')?.addEventListener('click', function () {
  3054. menuClose();
  3055. });
  3056. getEls('#stats_details_items li, #stats_details_summary_dirs, #stats_details_summary_files')?.forEach(el => el.onmouseleave = function () {
  3057. removeClass('.dirlist_item.hovered', 'hovered');
  3058. });
  3059. getEls('#stats_details_items li, #stats_details_summary_dirs, #stats_details_summary_files')?.forEach(el => el.onclick = function () { // onclick stats footer detail items
  3060. if (!hasClass('body', 'sort_by_kind')) {
  3061. clickThis('#sort_by_kind');
  3062. } // sort by kind
  3063. if (getEl('.dirlist_item' + statsGetHoveredListClass(el)) !== null) {
  3064. if (el.classList.contains('invisible') && getCurrentUIPref('show_invisibles') === 'false') {
  3065. clickThis('#show_invisibles');
  3066. }
  3067. if (el.classList.contains('ignored') && getCurrentUIPref('show_ignored_items') === 'true') {
  3068. clickThis('#show_ignored_items');
  3069. }
  3070. if (isTopWindow()) {
  3071. showThis(getEl('.dirlist_item' + statsGetHoveredListClass(el)).id);
  3072. }
  3073. else {
  3074. showThis(getEl('.dirlist_item' + statsGetHoveredListClass(el)).id, true, false);
  3075. } // click first matched item
  3076. }
  3077. });
  3078. }
  3079.  
  3080. function initGridItemEvents() { // ===> INIT GRID ITEM EVENT LISTENERS
  3081. getEls('#content_grid .grid_item')?.forEach(el => el.onclick = function (e) {
  3082. e.preventDefault();
  3083. e.stopPropagation();
  3084. showContentGridItem(e, el.dataset.id, el.querySelector('a').href, el.dataset.kind);
  3085. }); // grid item
  3086. getEls('#content_grid .grid_item:not(.selected)')?.forEach(el => el.onmouseenter = function () {
  3087. addClass('#' + el.dataset.id, 'hovered');
  3088. scrollThis('#directory_list', '.hovered');
  3089. });
  3090. getEls('#content_grid .grid_item:not(.selected)')?.forEach(el => el.onmouseleave = function () {
  3091. removeClass('#' + el.dataset.id, 'hovered');
  3092. });
  3093. getEls('.dirlist_item.image,.dirlist_item.font')?.forEach(el => el.onmouseenter = function () {
  3094. if (hasContent('grid')) {
  3095. addClass('#content_grid > .grid_item[data-id="' + el.id + '"]', 'hovered');
  3096. scrollThis('#content_grid', '.hovered');
  3097. }
  3098. });
  3099. getEls('.dirlist_item.image,.dirlist_item.font')?.forEach(el => el.onmouseleave = function () {
  3100. if (hasContent('grid')) {
  3101. removeClass('#content_grid > .grid_item[data-id="' + el.id + '"]', 'hovered');
  3102. scrollThis('#content_grid', '.hovered');
  3103. }
  3104. });
  3105. }
  3106.  
  3107. function initCuesheetEvents() { // ===> INIT CUESHEET EVENT LISTENERS
  3108. getEls('.cuesheet_track_list_container li')?.forEach(el => el.onclick = function (e) {
  3109. menuShow(e, el.id);
  3110. });
  3111. getEls('.cuesheet_track_list_container')?.forEach(el => el.onmouseenter = function (e) { // add selected class to first track whose time is less than currentTime
  3112. menuShow(e, this.id)
  3113. if (el.id === 'cuesheet_track_list_container_video') {
  3114. getEl('#cuesheet_track_list_video').style.top = getEl('#content_title_container').clientHeight;
  3115. }
  3116. let currentTime = getEls('#audio,#content_video')?.currentTime;
  3117. el.querySelector('.cuesheet_track_list').setAttribute('data-duration', currentTime); // set duration attr of cue sheet track list
  3118. this.querySelector('.cuesheet_track_list').style.height = getEl('#content_container').height + getEl('#content_title_container').height; // set height of cue sheet track list
  3119. let currentTrack = Array.from(el?.querySelector('.cuesheet_track_list li')).reverse().filter(function () {
  3120. return parseInt(el?.dataset?.duration) <= Math.round(currentTime);
  3121. })[0];
  3122. currentTrack?.parentElement?.children?.classList.remove('selected');
  3123. currentTrack?.classList.add('selected');
  3124. });
  3125. }
  3126. //============================//
  3127. // INITIALIZE IFRAME EVENT LISTENERS
  3128. function initIframeEvents() {
  3129. initSubframeEvents();
  3130. if (isTopWindow() || window.parent !== window.top) {
  3131. return;
  3132. } // ===> INIT IFRAME EVENT LISTENERS
  3133. document.body.onclick = function (e) {
  3134. e.preventDefault();
  3135. focusEl('#content_iframe');
  3136. } // focus iframe
  3137. document.body.querySelectorAll('body,textarea,form,select,input,option')?.forEach(el => el.onclick = function (e) {
  3138. e.stopPropagation();
  3139. messageSend('top_body', 'blur_top');
  3140. el.focus();
  3141. }); // focus iframe
  3142. if (/(\.html*|\.php)$/.test(window.location.href)) {
  3143. getEls('a')?.forEach(el => el.onclick = function (e) {
  3144. iframeClick(e, '', 'link', el.getAttribute('href'));
  3145. });
  3146. return; // return if html; rest unneeded
  3147. }
  3148. document.addEventListener('mousemove', function () {
  3149. removeClass('body', 'no_hover');
  3150. }); // remove no_hover class
  3151. getEls('.dirlist_item')?.forEach(el => el.onclick = function () {
  3152. showThis(el.id, true, false);
  3153. }); // select clicked iframe dirlist item
  3154. getEls('.dirlist_item a')?.forEach(el => el.onclick = function (e) {
  3155. e.preventDefault();
  3156. }); // do nothing for iframe dirlist links
  3157. getEls('.dirlist_item.dir .has_icon_before_before')?.forEach(el => el.onclick = function (e) {
  3158. subDirOpenClose(e, el.closest('.dirlist_item').id);
  3159. }); // open/close subdirs
  3160. getEls('.dirlist_item:not(.ignored)')?.forEach(el => el.ondblclick = function (e) {
  3161. iframeClick(e, el.id, 'link', el.querySelector('a').href);
  3162. }); // dblclick open iframe dirs/files
  3163. getEl('#open_in_sidebar a')?.addEventListener('click', function (e) {
  3164. e.preventDefault();
  3165. messageSend('top_body', 'open_iframe_dir_in_sidebar', '', window.location.href);
  3166. }); // no break;
  3167. getEl('#iframe_parent_link')?.addEventListener('click', function (e) {
  3168. iframeClick(e, 'iframe_parent_link', 'link', this.href);
  3169. }); // iframe parent
  3170. getEls('.toggle_UI_pref')?.forEach(el => el.onclick = function (e) {
  3171. uiPrefToggleOnClick(e, el.id);
  3172. }); // toggle UI prefs
  3173. initStatsEvents(); // initialize stats events listeners
  3174. }
  3175.  
  3176. function initSubframeEvents() {
  3177. if (window.parent !== window.top) {
  3178. getEl('#content_body').style.pointerEvents = 'none';
  3179. getEl('#content_body').addEventListener('click', function (e) {
  3180. e.preventDefault();
  3181. e.stopPropagation();
  3182. }); // prevent events in quicklook
  3183. }
  3184. }
  3185.  
  3186. function initTextEditorEvents() {
  3187. let preview = getEl('#texteditor_preview_pane'); // ===> INIT TEXT EDITOR EVENT LISTENERS
  3188. if (!isTopWindow()) {
  3189. getEls('#content_body,#content_body #toolbar,#content_body #toolbar li').forEach(el => el.onclick = function () {
  3190. focusEl('#content_body');
  3191. });
  3192. getEl('#content_body').querySelectorAll('textarea,form,select,input,option').forEach(el => el.onclick = function (e) {
  3193. eStopPrevent(e);
  3194. });
  3195. }
  3196. getEls('#toolbar_buttons .toggle_UI_pref').forEach(el => el.onclick = function (e) {
  3197. uiPrefToggleOnClick(e, el.id);
  3198. }); // text editing UI is not in DOM on page load;
  3199. getEl('#toolbar').onmousedown = function (e) {
  3200. e.preventDefault();
  3201. }; // prevent textarea from losing focus if sidebar clicked
  3202. window.onresize = function () {
  3203. texteditor_ResetSplit();
  3204. }; // reset text editor split
  3205. getEl('#text_editing_handle').ondblclick = function (e) {
  3206. e.stopPropagation();
  3207. texteditor_ResetSplit();
  3208. }; // reset text editor split
  3209. getEl('#text_editing_handle').onmousedown = function (e) {
  3210. eStopPrevent(e);
  3211. texteditor_ResizeSplit();
  3212. }; // resize text editor panes
  3213. getEl('#text_editing_handle').onmouseup = function () {
  3214. document.onmousemove = null;
  3215. } // remove onmousemove
  3216. getEls('.checkbox_container').forEach(el => el.onclick = function (e) {
  3217. toggleCheckBox(e, this.id);
  3218. }); // toggle checkboxes (texteditor_preview, toolbar)
  3219. getEl('#texteditor_txt_pane').oninput = function () { // add edited body class; if iframe, send edited message; update live markdown preview
  3220. if (!hasClass('body', 'texteditor_edited')) {
  3221. addClass('body', 'texteditor_edited');
  3222. if (!isTopWindow()) {
  3223. messageSend('top_body', 'iframe_edited', '', '');
  3224. }
  3225. }
  3226. MDlivePreview();
  3227. };
  3228. getEls('.texteditor_pane').forEach(el => el.onscroll = function (e) {
  3229. texteditor_SyncScroll(e, this.id);
  3230. });
  3231. getEls('#save_btn li').forEach(el => el.onclick = function () {
  3232. texteditorSaveBtn(el.id);
  3233. }); // save text editor content
  3234. getEl('#clear_text').onclick = function () {
  3235. showWarning('texteditorClear');
  3236. }; // clear text button
  3237. preview.onclick = function (e) {
  3238. e.stopPropagation()
  3239. };
  3240. preview.querySelectorAll('.checklist input').forEach(el => el.onclick = function (e) {
  3241. e.stopPropagation();
  3242. MDliveCheckBoxes(el);
  3243. }); // Live checkboxes
  3244. preview.querySelectorAll('.table-of-contents a').forEach(el => el.onclick = function (e) {
  3245. e.preventDefault();
  3246. MDtocClick(el.id);
  3247. }); // Preview TOC click navigation
  3248. preview.querySelectorAll('.uplink').forEach(el => el.onclick = function (e) {
  3249. e.stopPropagation();
  3250. MDheaderClick();
  3251. }); // Click header uplinks
  3252. initWarningEvents();
  3253. }
  3254.  
  3255. function initFontPreviewEvents() { // ==> INIT FONT PREVIEW_EVENTS
  3256. getEls('#font_toolbar select,#font_toolbar textarea,#font_toolbar input').forEach(el => el.onclick = function (e) {
  3257. e.stopPropagation();
  3258. el.focus();
  3259. });
  3260. getEls('#font_toolbar label').forEach(el => el.onclick = function (e) {
  3261. e.stopPropagation();
  3262. el.parentElement.querySelector('input').focus();
  3263. }); // Stop click propagation
  3264. getEls('#content_font *').forEach(el => el.onmousedown = function (e) {
  3265. e.stopPropagation();
  3266. focusEl(el.id);
  3267. }); // Stop click propagation
  3268. getEls('#font_toolbar select').forEach(el => el.onchange = function (e) {
  3269. fontOptions(e, el.id, el.value, el.options[el.selectedIndex].dataset?.prop, el.options[el.selectedIndex].dataset?.value)
  3270. });
  3271. getEls('#font_toolbar textarea').forEach(el => el.onkeydown = function (e) {
  3272. if (/enter/.test(e.key.toLowerCase())) {
  3273. e.preventDefault();
  3274. }
  3275. }); // prevent typing return in textareas
  3276. getEls('#font_toolbar textarea,#font_toolbar input').forEach(el => el.oninput = function (e) {
  3277. fontOptions(e, el.id, el.value)
  3278. }); // init font toolbar specimen modifications
  3279. getEls('#font_specimen_adjustments li').forEach(el => el.ondblclick = function (e) {
  3280. e.stopPropagation();
  3281. fontReset(el.dataset.inputid);
  3282. }); // reset adjustments
  3283. getEl('#font_specimen_glyph').onmousedown = (e) => {
  3284. fontGlyphMove(e, '#font_specimen_glyph');
  3285. } // init move glyph
  3286. }
  3287. //============================//
  3288. // INITIALIZE KEYDOWN EVENTS
  3289. function eKey_BackSlash(e) { // "BACKSLASH" KEY
  3290. switch (true) {
  3291. case cmdShiftKey(e): // Cmd Shift + \ : toggle split
  3292. switch (true) {
  3293. case isTopWindow() && hasContent('text,code,markdown'):
  3294. messageSend('iframe', 'texteditor_split_view');
  3295. break; // send toggle split view message
  3296. case getEl('#texteditor_split_view').height > 0:
  3297. getEl('#texteditor_split_view').click();
  3298. break; // if split view visible...click toggle split
  3299. }
  3300. break;
  3301. case cmdKey(e):
  3302. if (!isTopWindow()) {
  3303. messageSend('top_body', 'show_sidebar');
  3304. }
  3305. else {
  3306. getEl('#show_sidebar').click();
  3307. }
  3308. break; // Cmd + \ : toggle sidebar
  3309. }
  3310. }
  3311.  
  3312. function eKey_Enter(e) { // "ENTER" KEY
  3313. let selected_el = (hasContent('font_file') || hasContent('font_specimen') ? getEls('#content_font .selected .glyph,#content_font .selected')[0] : getEls('.dirlist_item.selected')[0]);
  3314. switch (true) {
  3315. case hasClass('body', 'has_warning') || hasClass('body', 'has_help'):
  3316. e.preventDefault();
  3317. clickThis('button.focus, button:focus');
  3318. break; // click focused warning btn
  3319. case hasClass('body', 'focus_content') && hasContent('font') && selected_el !== null:
  3320. showFontGlyph(e, selected_el.id);
  3321. break; // show font glyph
  3322. case !isTopWindow(): // if iframe...
  3323. switch (true) {
  3324. case hasClass('body', 'has_top_menu'):
  3325. messageSend('top_body', 'menuClick');
  3326. break; // close main menu
  3327. case elExists('.dirlist_item.audio.selected') && !hasClass('.dirlist_item.audio.selected', 'audio_loaded'):
  3328. iframeClick(e, getEl('.dirlist_item.selected').id, 'dblclick', getEl('.dirlist_item.selected a').href);
  3329. break;
  3330. case elExists('.dirlist_item.selected') && cmdKey(e):
  3331. iframeClick(e, getEl('.dirlist_item.selected').id, 'dblclick', getEl('.dirlist_item.selected a').href);
  3332. break; // webloc or url file
  3333. case elExists('.dirlist_item.audio_loaded') && !hasClass('.dirlist_item.selected', 'audio_loaded'):
  3334. eStopPrevent(e);
  3335. mediaPlayPause();
  3336. break; // play/pause media
  3337. }
  3338. break;
  3339. case hasClass('body', 'has_menu'):
  3340. e.preventDefault();
  3341. menuClick();
  3342. menuClose();
  3343. messageSend('iframe', 'menu_close');
  3344. break; // click selected menu item
  3345. case selected_el?.classList.contains('app') && UI_Prefs_Bool.apps_as_dirs === false:
  3346. break; // don't open app folders
  3347. default:
  3348. switch (true) {
  3349. case selected_el?.classList.contains('.disabled'):
  3350. case hasContent('texteditor'):
  3351. break; // no nothing for disabled or default behavior
  3352. case selected_el?.classList.contains('audio') && !selected_el.classList.contains('audio_loaded'):
  3353. showMedia('audio', getEl('.dirlist_item.audio.selected').id);
  3354. break; // show selected audio file
  3355. case selected_el?.classList.contains('media'):
  3356. eStopPrevent(e);
  3357. mediaPlayPause();
  3358. break; // else play/pause media
  3359. case (/dir|link|playlist/.test(selected_el?.classList)) && cmdKey(e):
  3360. dirOpen(e, getEl('.dirlist_item.selected').id, getEl('.dirlist_item.selected a').href);
  3361. break; // open dirs, links, playlists
  3362. case (/dir|link/.test(selected_el?.classList)): // nobreak
  3363. default:
  3364. selected_el?.click(); // default: click selected item
  3365. }
  3366. }
  3367. }
  3368.  
  3369. function eKey_Escape() { // "ESCAPE" KEY
  3370. if (getAttribute('#content_pane', 'data-loaded') !== 'loaded') {
  3371. removeAttribute('#content_pane', 'data-loaded');
  3372. removeAttribute('#content_iframe', 'src');
  3373. } // close loading iframe
  3374. switch (true) {
  3375. case !isTopWindow():
  3376. if (hasClass('body', 'has_quicklook')) {
  3377. quickLookThis('close');
  3378. }
  3379. else {
  3380. messageSend('top_body', 'focus_top');
  3381. }
  3382. break; // focus top from iframe content
  3383. case document.activeElement.tagName.toLowerCase() !== 'body':
  3384. case hasClass('body', 'focus_content') && !hasClass('body', 'has_menu'):
  3385. focusEl('#top_body');
  3386. break; // focus top from non-iframe content
  3387. case document.activeElement.tagName.toLowerCase() === 'body': // if top already focussed...
  3388. switch (true) {
  3389. case hasClass('body', 'has_menu'):
  3390. case hasClass('body', 'has_menu_stats'):
  3391. menuClose();
  3392. break; // close menu or
  3393. default:
  3394. /* closeContent('esc'); */ focusEl('#top_body'); // close content
  3395. }
  3396. }
  3397. document.onmousemove = null;
  3398. window.getSelection().removeAllRanges();
  3399. window.stop(); // remove text selections; stop loading; cancel mousemove event watcher
  3400. removeClass('body', 'has_overlay');
  3401. removeClass('.dirlist_item', 'dirlist_subdir_loading');
  3402. getEls('.dirlist_item.selected,.dirlist_item.content_loaded').forEach(el => el.classList.remove('selected', 'content_loaded'));
  3403. getEls('.show_input input')?.forEach(el => el.value = '');
  3404. removeClass('.show_input', 'show_input');
  3405. if (hasClass('body', 'has_warning') || hasClass('body', 'has_help')) {
  3406. getEls('#warning_btn_cancel,#close_help').forEach(el => el.click());
  3407. } // close warnings or help
  3408. }
  3409.  
  3410. function eKey_Period(e) {
  3411. window.stop();
  3412. removeClass('.dirlist_item', 'dirlist_subdir_loading');
  3413. if (hasClass('body', 'has_warning')) {
  3414. e.preventDefault();
  3415. getEl('#warning_btn_cancel,#close_help').click();
  3416. }
  3417. if (getAttribute('#content_pane', 'data-loaded') !== 'loaded') {
  3418. closeContent('iframe');
  3419. }
  3420. }
  3421.  
  3422. function eKey_Space(e) { // "SPACE" KEY
  3423. switch (true) {
  3424. case isTopWindow():
  3425. switch (true) {
  3426. case hasContent('font_file_glyph'):
  3427. case hasContent('font_specimen_glyph'):
  3428. closeFont();
  3429. break; // close glyph
  3430. case hasContent('font') && getEl('.font_glyph_item.selected') !== null:
  3431. showFontGlyph(null, getEl('.font_glyph_item.selected').id);
  3432. break; // show glyph
  3433. case hasContent('image') && hasContent('hidden_grid'):
  3434. closeContent();
  3435. break; // close grid image
  3436. case hasContent('grid') && getEl('.image_grid_item.selected') !== null:
  3437. getEl('.image_grid_item.selected').click();
  3438. break; // show grid image
  3439. case (hasContent(['audio', 'ignore']) || hasContent('video')):
  3440. eStopPrevent(e);
  3441. mediaPlayPause();
  3442. break; // media play/pause
  3443. }
  3444. break;
  3445. case !isTopWindow():
  3446. eStopPrevent(e); // not top window
  3447. switch (true) {
  3448. case elExists('.dirlist_item.audio_loaded') && !hasClass('body', 'has_quicklook'):
  3449. messageSend('top_body', 'iframe_play_pause_media');
  3450. break; // play/pause top media if no quicklook
  3451. case hasClass('body', 'has_quicklook'):
  3452. quickLookThis('close');
  3453. break; // close quicklook
  3454. case getEl('.dirlist_item.selected') !== null:
  3455. quickLookThis(getEl('.dirlist_item.selected').id, getEl('.dirlist_item.selected').dataset.kind);
  3456. break; // show quicklook
  3457. }
  3458. }
  3459. }
  3460.  
  3461. function eKey_Tab(e) {
  3462. e.preventDefault();
  3463. let incr = (e.shiftKey === true ? 1 : -1);
  3464. navigateByTabKey(e, incr);
  3465. } // "TAB" KEY
  3466. function eKey_A(e) {
  3467. selectMultipleItems(e);
  3468. } // "A" KEY Select all dir items with cmd_key
  3469. function eKey_E(e) { // "E" KEY
  3470. switch (true) {
  3471. case hasClass('body', 'has_warning'):
  3472. break;
  3473. case cmdShiftKey(e):
  3474. eStopPrevent(e);
  3475. if (!isTopWindow()) {
  3476. messageSend('top_body', 'toggle_texteditor');
  3477. }
  3478. else {
  3479. getEl('#show_texteditor a').click();
  3480. }
  3481. addClass('#top_body', 'focus_content');
  3482. break; // toggle text editor
  3483. case cmdKey(e):
  3484. eStopPrevent(e);
  3485. if (!isTopWindow()) {
  3486. messageSend('top_body', 'toggle_menu');
  3487. }
  3488. else {
  3489. menuShow(e, 'dir_menu_main_container');
  3490. }
  3491. break; // toggle main menu
  3492. }
  3493. }
  3494.  
  3495. function eKey_R(e) { // "R" KEY
  3496. switch (true) {
  3497. case cmdKey(e) && !isTopWindow():
  3498. e.preventDefault();
  3499. messageSend('top_body', 'reload');
  3500. break; // send reload message to top
  3501. case cmdKey(e) && hasClass('#content_body', 'texteditor_edited'):
  3502. e.preventDefault();
  3503. showWarning('resetContent');
  3504. break; // warn before reloading edited iframe text files from textarea
  3505. case cmdKey(e):
  3506. if (!hasContent()) {
  3507. return true;
  3508. }
  3509. else {
  3510. e.preventDefault();
  3511. getEl('#reload_btn').click();
  3512. }
  3513. break; // reload window if no content open else reload/reset content
  3514. }
  3515. }
  3516.  
  3517. function eKey_W(e) { // "W" KEY
  3518. switch (true) {
  3519. case !isTopWindow():
  3520. e.preventDefault();
  3521. messageSend('top_body', 'close');
  3522. break; // send close message to top
  3523. case hasClass('body', 'has_help'):
  3524. getEl('#close_help').click();
  3525. break; // close help
  3526. case hasContent('audio') && hasContent('null'):
  3527. closeContent('audio');
  3528. break; // close audio when nothing else open
  3529. case (/has_\w+list/.test(getClassNames('body')) && !hasContent()):
  3530. showWarning('closeContent', ['closePlaylist', 'false']);
  3531. break; // close playlist
  3532. case !hasContent('null'):
  3533. e.preventDefault();
  3534. closeContent();
  3535. break; // close content
  3536. default:
  3537. return; // else close window (or normal behavior)
  3538. }
  3539. }
  3540. getEls('#top_body, #content_body').forEach(el => el.onkeydown = function (e) {
  3541. if (window.parent !== window.top) {
  3542. return;
  3543. } // ===> MAIN KEYDOWN EVENTS
  3544. let active_el = document.activeElement,
  3545. active_el_tag = active_el.tagName.toLowerCase(); // allow default: buttons, inputs, selects, textareas
  3546. switch (true) {
  3547. case e.key === 'Enter':
  3548. switch (true) {
  3549. case (/ui_font/.test(active_el.id)):
  3550. uiPrefFontSet(e);
  3551. break;
  3552. case (/go_to_item_input/.test(active_el.id)):
  3553. goToItem(e);
  3554. break;
  3555. default:
  3556. eKey_Enter(e, active_el);
  3557. break; // Key = Enter/Return
  3558. }
  3559. case (/button|input|select|textarea/.test(active_el_tag) && !/escape|tab|shiftkey|metakey|altkey/.test(e.key.toLowerCase()) && !(cmdKey(e) && /r|w|-|=/.test(e.key))):
  3560. return; // prevent/allow certain key combos
  3561. case active_el.hasAttribute('contentEditable') && !(/escape|tab|shiftkey|metakey|altkey/.test(e.key.toLowerCase()) && !(cmdKey(e) && /r|w|-|=/.test(e.key))):
  3562. return; // ...in certain situations.
  3563. case e.key === 'Escape':
  3564. eKey_Escape();
  3565. break;
  3566. case (/has_warning|has_help/.test(getClassNames('body')) && !(cmdKey(e) || (/escape|tab|shiftkey|enter/.test(e.key.toLowerCase())))): // nobreak
  3567. case e.key === 'shiftKey' && (hasClass('body', 'has_warning') || hasClass('body', 'has_help')):
  3568. if (e.key !== 'Enter' && e.key !== 'Tab') {
  3569. e.preventDefault();
  3570. return false;
  3571. }
  3572. break; // Key = Shift
  3573. case (/Arrow/.test(e.key)):
  3574. arrowKeyFunctions(e, false, el);
  3575. break; // (e,bool,selected_el.id); id for dblclick iframe item
  3576. case e.key === ' ':
  3577. eKey_Space(e);
  3578. break; // Key = Space
  3579. case (e.key && !e.metaKey && !e.altKey && !e.ctrlKey && e.key !== 'Tab' && !/Arrow/.test(e.key)):
  3580. navigateByTypedStr(e);
  3581. break; // alphanumeric navigation
  3582. case e.key === 'a' && cmdKey(e):
  3583. eKey_A(e);
  3584. break; // Cmd + a: select all
  3585. case e.key === 'd' && cmdShiftKey(e) && !hasClass('body', 'has_warning'):
  3586. e.preventDefault();
  3587. getEl('#show_details').click();
  3588. break; // Cmd/Ctrl + D: Toggle Details
  3589. case e.key === 'e':
  3590. eKey_E(e);
  3591. break; // Cmd/Ctrl + E: Toggle Main Menu or Text Editor
  3592. case e.key === 'g' && cmdKey(e) && (hasClass('#top_body', 'has_images') || hasClass('#top_body', 'has_fonts')):
  3593. e.preventDefault();
  3594. getEl('#show_grid_btn').click();
  3595. break; // Show grids
  3596. case e.key === 'i' && cmdShiftKey(e):
  3597. if (!isTopWindow()) {
  3598. messageSend('top_body', 'toggle_invisibles');
  3599. }
  3600. else {
  3601. getEl('#show_invisibles_container input').click();
  3602. }
  3603. break; // Toggle invisibles
  3604. case e.key === 'j' && cmdShiftKey(e):
  3605. goToItem(e);
  3606. break;
  3607. case e.key === 'o' && cmdShiftKey(e):
  3608. window.open(getAttribute('.dirlist_item.selected a', 'href'));
  3609. break; // Cmd+Shift+O: Open in new window
  3610. case e.key === 'r':
  3611. eKey_R(e);
  3612. break; // Cmd/Ctrl + Shift + R: Refresh
  3613. case e.key === 'w' && cmdKey(e):
  3614. eKey_W(e);
  3615. break; // KEY = W && Cmd/Ctrl: close content
  3616. case e.key === '=' && cmdKey(e) && hasContent('grid,image,font,glyph'):
  3617. e.preventDefault();
  3618. contentHeaderButtons(e, 'increase');
  3619. break; // Cmd/Ctrl + equals: scale larger
  3620. case e.key === '-' && cmdKey(e) && hasContent('grid,image,font,glyph'):
  3621. e.preventDefault();
  3622. contentHeaderButtons(e, 'decrease');
  3623. break; // Cmd/Ctrl + hyphen: scale smaller
  3624. case e.key === '\\':
  3625. eKey_BackSlash(e);
  3626. break; // KEY = \ BACKSLASH
  3627. case e.key === 'Tab':
  3628. eKey_Tab(e);
  3629. break; // KEY = TAB
  3630. case e.key === '.' && cmdKey(e):
  3631. eKey_Period(e);
  3632. break; // click cancel button
  3633. } // end switch
  3634. });
  3635. // ***** END EVENT LISTENER INITIALIZATION
  3636. //============================//
  3637. function menuShow(e, id) { // ===> SHOW MENUS
  3638. if (e !== null) {
  3639. e.stopPropagation();
  3640. }
  3641. if (/dir_menu/.test(id) && /has_menu/.test(getClassNames('body'))) {
  3642. menuClose();
  3643. return;
  3644. } // close menu on click if open
  3645. removeClass('body', 'has_top_menu has_menu has_menu_parents has_menu_stats is_blurred,show_sidebar_false');
  3646. removeClass('#dir_menu_main *', 'selected hovered show_input'); // remove classes
  3647. let el, menu_el = getEl('#' + id),
  3648. menu_el_classlist = menu_el.classList,
  3649. parent_nav_id, time, position = getEl('#dir_header_utilities_row_1').offsetTop - 1 + 'px'; // get clicked menu element
  3650. switch (true) {
  3651. case id === 'dir_menu_main_container':
  3652. setStyle('#' + id + ' > ul', 'top', position);
  3653. addClass('#top_body', 'has_menu');
  3654. break; // show main menu
  3655. case id === 'dir_menu_parents':
  3656. setStyle('#' + id + ' > ul', 'top', position);
  3657. addClass('body', 'has_menu_parents');
  3658. break; // show dir_menu_parents
  3659. case id === 'stats_summary':
  3660. setStyle('#stats_details_items', 'height', getEl('#stats_container').height - getEl('#stats_details_summary').height - 4); // show stats menu
  3661. updateDurations();
  3662. addClass('body', 'has_menu_stats');
  3663. break; // update durations, set classes
  3664. case menu_el_classlist.contains('has_submenu'):
  3665. removeClass('li.has_submenu', 'selected hovered');
  3666. menu_el.classList.toggle('selected');
  3667. break; // toggle open submenu
  3668. case (/about_link|donate_link|contact_link/.test(id)):
  3669. changeLocation([menu_el.href, 'external']);
  3670. break; // external menu links
  3671. case id === 'cuesheet_track_list_container_audio':
  3672. case id === 'cuesheet_track_list_container_video': // onmouseenter cue_sheet...
  3673. el = getEl('#' + id);
  3674. setStyle('#' + id + ' > div', 'top', el.offsetTop + el.clientHeight - 5 + 'px');
  3675. break; // set y position of cuesheet track list
  3676. case id.startsWith('cuesheet_item_'): // click cuesheet track list items
  3677. switch (true) {
  3678. case menu_el.classList.contains('selected'):
  3679. mediaPlayPause();
  3680. break; // play/pause if already selected
  3681. default: // otherwise select new cuesheet track list item
  3682. parent_nav_id = menu_el.closest('nav').id;
  3683. time = getEl('#' + id).getAttribute('data-duration'); // N.B.: cue time format is mm:ss:ff (ff = frames, 75 frames/sec)
  3684. addRemoveClassSiblings('#' + id, 'selected');
  3685. switch (parent_nav_id) {
  3686. case 'cuesheet_track_list_container_audio':
  3687. if (time < getEl('#audio').duration) {
  3688. getEl('#audio').currentTime = time;
  3689. }
  3690. break;
  3691. case 'cuesheet_track_list_container_video':
  3692. if (time < getEl('#content_video').duration) {
  3693. getEl('#content_video').currentTime = time;
  3694. }
  3695. break;
  3696. }
  3697. }
  3698. break;
  3699. }
  3700. }
  3701.  
  3702. function menuClick() {
  3703. getEl('#dir_menu_main .selected:not(.hovered)')?.querySelectorAll('a,span,label')[0]?.click();
  3704. if (hasClass('body', 'focus_content')) {
  3705. messageSend('iframe', 'menu_close');
  3706. }
  3707. } // ===> CLICK MENU
  3708. function menuClose() { // ==> CLOSE MENUS
  3709. removeClass('body', 'has_top_menu has_menu has_menu_parents has_menu_stats is_blurred');
  3710. removeClass('#dir_menu_main *', 'selected hovered show_input'); // remove classes
  3711. }
  3712.  
  3713. function statsGetHoveredListClass(el) {
  3714. let this_class = '.' + (el?.dataset?.kind?.split(', ')); // ===> GET HOVERED STATS CLASS
  3715. switch (true) {
  3716. case el.id === 'stats_details_summary_dirs':
  3717. this_class = '.dir';
  3718. break;
  3719. case el.id === 'stats_details_summary_files':
  3720. this_class = '.file';
  3721. break;
  3722. case this_class === '.dir':
  3723. this_class = '.dir:not(.ignored):not(.invisible):not(.app)';
  3724. break;
  3725. case this_class === '.dir.app':
  3726. this_class = '.dir.app:not(.ignored):not(.invisible)';
  3727. break;
  3728. }
  3729. return this_class;
  3730. }
  3731. //============================//
  3732. // DIRLIST CLICK AND SELECT FUNCTIONS
  3733. function clickDirListItem(e, id) {
  3734. e.preventDefault();
  3735. let el = getEl('#' + id),
  3736. src = getEl('#' + id + ' a').href; // ===> CLICK DIR LIST ITEM
  3737. switch (true) {
  3738. case window.parent !== window.top:
  3739. return;
  3740. case (!/rowid/.test(id)):
  3741. break; // null if not a dirlist item
  3742. case e.metaKey && /'app|dir|font|image/.test(getClassNames('#' + id)):
  3743. selectMultipleItems(e, id);
  3744. break; // select multiple items on click
  3745. case !isTopWindow():
  3746. e.stopPropagation();
  3747. showThis(id, true, true); // iframe dirlist items
  3748. if (el.classList.contains('audio_loaded')) {
  3749. messageSend('top_body', 'iframe_play_pause_media');
  3750. }
  3751. break; // play/pause iframe audio onclick
  3752. case el.classList.contains('audio'):
  3753. if (el.classList.contains('audio_loaded')) {
  3754. mediaPlayPause();
  3755. }
  3756. else {
  3757. showThis(id, false, true);
  3758. }
  3759. break; // play/pause media or show content on click
  3760. case el.classList.contains('video'):
  3761. if (/youtube.com|youtu.be/.test(src)) {
  3762. showThis(id);
  3763. return;
  3764. }
  3765. if (el.classList.contains('content_loaded')) {
  3766. mediaPlayPause();
  3767. }
  3768. else {
  3769. showWarning('showThis', [id]);
  3770. }
  3771. break; // '' ''
  3772. default:
  3773. switch (true) {
  3774. case hasClass('body', 'texteditor_edited') || (/has_\w+list/.test(getClassNames('#top_body'))):
  3775. showThis(id);
  3776. break; // if top edited, show item (i.e.hide text editor)
  3777. case hasClass('body', 'iframe_edited'):
  3778. messageSend('iframe', 'unloading', '', ['showThis', id]);
  3779. break; // if iframe edited, show warning
  3780. default:
  3781. showWarning('showThis', [id]); // default: show content with warning
  3782. }
  3783. }
  3784. }
  3785.  
  3786. function iframeClickLink(e, id, link) { // ===> IFRAME CLICK LINKS from html files
  3787. let url, kind;
  3788. if (!link.startsWith('#')) {
  3789. url = newURL(link);
  3790. if (e !== null) {
  3791. e.preventDefault();
  3792. }
  3793. } // if link is not a link fragment, create url, prevent default
  3794. switch (true) {
  3795. case link.startsWith('#'):
  3796. case url.href.startsWith('file:///?'):
  3797. case url === undefined:
  3798. break; // allow default link fragment behavior
  3799. case id === 'tbody':
  3800. window.location = link + '?&show_directory_source=true';
  3801. break; //
  3802. case id === 'iframe_parent_link':
  3803. messageSend('top_body', 'show_iframe_parent', '', [getEl('#iframe_parent_link').href, 'dir', 'iframe_parent']);
  3804. break; // send message "show_iframe_parent"
  3805. case url.protocol === 'file:' && window.location.protocol !== 'file:':
  3806. messageSend('top_body', 'local_link');
  3807. break; // show warning when attempting to open local links from non-local pages
  3808. case url.protocol !== 'file:' && window.location.protocol === 'file:':
  3809. window.open(link, '_blank');
  3810. break; // open remote link from local page in new tab/window
  3811. case url.protocol === 'file:' && window.location.protocol === 'file:': // nobreak; open local links to local files in iframe
  3812. case url.protocol === 'about:': // nobreak; document #link fragments
  3813. case RegExp(url.hostname).test(window.location.hostname): // nobreak; same origin links (might not include TLD) (just covering bases)
  3814. case RegExp(window.location.hostname).test(url.hostname): // no break; same origin links (might not include TLD) (just covering bases)
  3815. kind = getLinkInfo(url.href)[3];
  3816. if (/dir|app/.test(kind)) {
  3817. messageSend('top_body', 'show_iframe_dir', '', [link, kind, id]);
  3818. }
  3819. else {
  3820. messageSend('top_body', 'show_iframe_file', '', [link, kind, id]);
  3821. }
  3822. break;
  3823. default:
  3824. window.open(link, '_blank');
  3825. break; // else open external document links in new tab
  3826. }
  3827. }
  3828.  
  3829. function iframedblClickThis(e, id, link) {
  3830. e.stopPropagation(); // ===> IFRAME DOUBLECLICK THIS iframe dir_list items (files and dirs)
  3831. if (/_/.test(id)) {
  3832. id = id.split('_')[0];
  3833. } // temp: if double-clicking a subdir item, id === top parent item id; we'd like to send full subdir item id so that it can be reopened when the subdir item is closed.
  3834. let el = getEl('#' + id);
  3835. let kind = el.dataset.kind,
  3836. message = (/dir|app/.test(kind) ? 'show_iframe_dir' : 'show_iframe_file'); // get item kind
  3837. if (kind === 'audio') {
  3838. removeClass('.dirlist_item.audio', 'audio_loaded selected');
  3839. el.classList.add('audio_loaded', 'selected');
  3840. } // iframe audio
  3841. messageSend('top_body', message, '', [link, kind, id]); // send message
  3842. }
  3843.  
  3844. function iframeClick(e, id, kind, link) {
  3845. e.preventDefault();
  3846. switch (true) {
  3847. case window.parent !== window.top:
  3848. e.stopPropagation();
  3849. return;
  3850. case kind === 'dblclick':
  3851. case e.type === 'dblclick':
  3852. iframedblClickThis(e, id, link);
  3853. break;
  3854. case kind === 'dirlist_item':
  3855. clickDirListItem(e, id);
  3856. break;
  3857. case kind === 'link':
  3858. iframeClickLink(e, id, link);
  3859. break;
  3860. }
  3861. }
  3862. //============================//
  3863. // ===> CLICK TOGGLE UI PREF ELEMENTS
  3864. function uiPrefToggleOnClick(e, id) {
  3865. e.stopPropagation();
  3866. e.stopImmediatePropagation();
  3867. showWarning('uiPrefToggle', getEl('#' + id).getAttribute('data-ui_pref'));
  3868. }
  3869.  
  3870. function uiPrefToggle(pref_id) { // ===> TOGGLE UI PREFS: and update searchParams
  3871. let settings_value = [pref_id, UI_Settings[pref_id]].join('_'),
  3872. current_value = getCurrentUIPref(pref_id),
  3873. new_value = getNewUIPref(pref_id);
  3874. let message_target = (isTopWindow() ? 'iframe' : 'top_body'),
  3875. send = 'false';
  3876. if (/button|label|select|input/.test(document.activeElement.tagName.toLowerCase())) {
  3877. document.activeElement.blur();
  3878. } // blur any focused form elements
  3879. switch (true) {
  3880. case (pref_id === 'show_image_thumbnails'):
  3881. uiPrefImgThumbsToggle(new_value[1]);
  3882. send = 'true';
  3883. break;
  3884. case (/texteditor_/.test(pref_id)):
  3885. textEditorTogglePrefs(pref_id, new_value);
  3886. send = 'true';
  3887. break; // Text Editor Preferences
  3888. case !hasClass('#content_body', 'show_details_false') && pref_id === 'show_details' && !isTopWindow(): // nobreak; hide iframe details on first toggle; special case needed
  3889. case new_value[1] === 'false':
  3890. addClass('body', pref_id + '_false');
  3891. searchParamSet(pref_id, 'false');
  3892. send = 'true';
  3893. break;
  3894. case new_value[1] === 'true':
  3895. case current_value === 'false':
  3896. removeClass('body', pref_id + '_false');
  3897. searchParamDelete(pref_id);
  3898. send = 'true';
  3899. break;
  3900. case (/sort_by_/.test(pref_id)):
  3901. uiPrefSortToggle(pref_id);
  3902. break; // toggle sorting
  3903. case (/theme|theme_light|theme_dark/.test(pref_id)):
  3904. uiPrefThemeToggle(new_value);
  3905. break; // toggle light/dark theme
  3906. case new_value.length > 1 && settings_value === new_value.join('_'): // nobreak; new value === settings value
  3907. default: // other non-booleans
  3908. searchParamSet(getNewUIPref(pref_id)[0], new_value.join('_')); // set searchParam
  3909. removeClass('body', [pref_id, current_value].join('_'));
  3910. addClass('body', new_value.join('_')); // remove old body class; add new body class
  3911. send = 'true';
  3912. }
  3913. if (send === 'true' && isTopWindow() && !/show_details|show_sidebar/.test(pref_id)) {
  3914. messageSend(message_target, 'uiPrefToggle', '', pref_id);
  3915. } // send message to iframe
  3916. if (/show_invisibles|show_ignored_items/.test(pref_id)) {
  3917. updateStats();
  3918. } // update stats if necessary
  3919. }
  3920.  
  3921. function uiPrefsReset(e) {
  3922. eStopPrevent(e); // ===> DEFAULT SETTINGS: remove queries;
  3923. if (window.confirm('Are you sure you want to remove all your temporary UI settings from the URL query string?')) {
  3924. removeClass('body', 'has_menu');
  3925. let query_str = '',
  3926. selected_str = '',
  3927. history_str = '';
  3928. if (getCurrentUIPref('selected').length && getCurrentUIPref('selected').match(/[0-9\+]+?/)) {
  3929. selected_str += 'selected=' + getCurrentUIPref('selected');
  3930. }
  3931. if (getCurrentUIPref('history').length && getCurrentUIPref('history').match(/[0-9\+]+?/)) {
  3932. history_str += 'history=' + getCurrentUIPref('history');
  3933. }
  3934. query_str = history_str + '&' + selected_str;
  3935. if (query_str.length > 1) {
  3936. query_str = '?' + query_str.replace(/\s/g, '+');
  3937. }
  3938. window.location.assign(window_location + query_str);
  3939. }
  3940. }
  3941. //============================//
  3942. function uiPrefThemeToggle(new_value) { // ===> TOGGLE UI PREF THEME
  3943. new_value = new_value.join('_');
  3944. removeClass('body', 'theme_dark theme_light');
  3945. addClass('body', new_value);
  3946. if (new_value === 'theme_light') {
  3947. searchParamDelete('theme');
  3948. }
  3949. else {
  3950. searchParamSet('theme', 'dark');
  3951. }
  3952. if (isTopWindow()) {
  3953. messageSend('iframe', 'uiPrefToggle', '', new_value);
  3954. } // send message iframe
  3955. }
  3956.  
  3957. function uiPrefFontSet(e) {
  3958. eStopPrevent(e);
  3959. let value; // ===> SET UI FONT
  3960. switch (true) {
  3961. case e?.type === 'click':
  3962. getEl('#ui_font input').value = getCurrentUIPref('ui_font');
  3963. addClass('#ui_font', 'show_input');
  3964. getEl('#ui_font input').focus();
  3965. break; // show input & current ui font on click
  3966. case e?.key === 'Enter':
  3967. value = getEl('#ui_font input').value; // get the entered ui font
  3968. if (value !== '') {
  3969. document.body.style.fontFamily = value;
  3970. searchParamSet('ui_font', value);
  3971. }
  3972. else {
  3973. document.body.style.fontFamily = null;
  3974. searchParamDelete('ui_font');
  3975. }
  3976. messageSend('iframe', 'set_ui_font', '', value);
  3977. removeClass('#ui_font', 'show_input');
  3978. menuClose();
  3979. break; // set the font; close menu
  3980. default:
  3981. if (UI_Prefs_Non_Bool.ui_font !== getCurrentUIPref('ui_font')) {
  3982. document.body.style.fontFamily = getCurrentUIPref('ui_font');
  3983. } // set the ui font on page load
  3984. }
  3985. }
  3986.  
  3987. function uiPrefScaleSet(e, value, bool) { // bool === true --> from buildUI // ===> SET UI SCALE
  3988. if (e !== null) {
  3989. e.stopPropagation();
  3990. }
  3991. switch (true) {
  3992. case Math.round(value) === 100:
  3993. document.body.style.removeProperty('transform');
  3994. document.body.style.removeProperty('width');
  3995. document.body.style.removeProperty('height'); // remove body styles
  3996. getEl('#ui_scale .menu_item').dataset.value = '100%';
  3997. getEl('#ui_scale_input').value = 100; // reset input
  3998. searchParamDelete('ui_scale');
  3999. break; // delete the searchParam
  4000. default:
  4001. document.body.style.transform = 'scale(' + value + '%)';
  4002. document.body.style.width = Math.round(10000 / Number(value)) + '%';
  4003. document.body.style.height = Math.round(10000 / Number(value)) + '%'; // add body styles
  4004. searchParamSet('ui_scale', Math.round(value)); // set the searchParam
  4005. }
  4006. if (Number(value) < 100) {
  4007. document.documentElement.style.width = Math.round(10000 / Number(value)) + '%';
  4008. }
  4009. else {
  4010. document.documentElement.style.removeProperty('width');
  4011. } // scale the html element if value < 1
  4012. if (bool === true) {
  4013. getEl('#ui_scale .menu_item').dataset.value = value + '%';
  4014. getEl('#ui_scale_input').value = value;
  4015. } // set the input on load
  4016. }
  4017.  
  4018. function uiPrefImgThumbsToggle(bool) { // ===> TOGGLE UI PREF IMG THUMBS
  4019. let image_files = getEls('.dirlist_item.image'),
  4020. current_background_image, max_count = 2000; // Add/remove image thumbnails as background icons
  4021. switch (true) {
  4022. case getEl('.stats_list_item.image a')?.dataset.count > max_count && getCurrentUIPref('show_image_thumbnails_always') === 'false': // nobreak; don't show thumbs if show_image_thumbnails_always === false
  4023. case bool === 'false':
  4024. addClass('body', 'show_image_thumbnails_false');
  4025. searchParamSet('show_image_thumbnails', 'false');
  4026. break;
  4027. default:
  4028. removeClass('body', 'show_image_thumbnails_false');
  4029. searchParamDelete('show_image_thumbnails');
  4030. }
  4031. image_files.forEach((image) => {
  4032. current_background_image = image.querySelector('a .has_icon_before_before').style.backgroundImage; // get the current background_image, save for future toggle
  4033. switch (true) { // toggle thumbnail display
  4034. case getEl('.stats_list_item.image a')?.dataset.count > max_count && getCurrentUIPref('show_image_thumbnails_always') === 'false': // nobreak; don't show thumbs if show_image_thumbnails_always === false
  4035. case bool === 'false': // show default icon, don't remove existing thumbnail
  4036. image.querySelector('a .has_icon_before_before').style.backgroundImage = get_SVG_UI_File_Icon('file_icon_image') + ',' + current_background_image; // only first background image is visible
  4037. break;
  4038. default: // remove default image icon or load image thumbnail
  4039. image.querySelector('a .has_icon_before_before').style.backgroundImage = 'url("' + image.querySelector('a').href + '")';
  4040. image.querySelector('a .has_icon_before_before').dataset.image_url = 'url("' + image.querySelector('a').href + '")';
  4041. }
  4042. });
  4043. }
  4044.  
  4045. function loadImageThumbnail(id) {
  4046. let image = getEl('#' + id);
  4047. image.querySelector('a .has_icon_before_before').style.backgroundImage = 'url("' + image.querySelector('a').href + '")';
  4048. image.querySelector('a .has_icon_before_before').dataset.image_url = 'url("' + image.querySelector('a').href + '")';
  4049. }
  4050.  
  4051. function uiPrefSortToggle(pref_id) { // ===> TOGGLE UI SORT PREF
  4052. let current_sort_by = getCurrentUIPref('sort_by'),
  4053. new_sort_by = pref_id.split('_').reverse()[0];
  4054. let current_sort_direction = getCurrentUIPref('sort_direction'),
  4055. new_sort_direction = (new_sort_by !== current_sort_by ? 'ascending' : getNewUIPref('sort_direction_' + current_sort_direction)[1]);
  4056. switch (true) { // toggle sort_by
  4057. case new_sort_by !== current_sort_by:
  4058. new_sort_by === 'default' ? searchParamDelete('sort_by') : searchParamSet('sort_by', new_sort_by);
  4059. break;
  4060. case new_sort_by === current_sort_by:
  4061. break;
  4062. }
  4063. switch (true) { // toggle sort_direction
  4064. case new_sort_by !== current_sort_by: // nobreak
  4065. case current_sort_direction === 'descending':
  4066. searchParamDelete('sort_direction');
  4067. break; // delete search_param if new sort is ascending (default)
  4068. case current_sort_direction === 'ascending':
  4069. searchParamSet('sort_direction', 'descending');
  4070. break; // add descending search_param
  4071. }
  4072. removeClass('body', 'has_menu sort_by_name sort_by_default sort_by_duration sort_by_size sort_by_date sort_by_kind sort_by_ext sort_direction_ascending sort_direction_descending'); // remove all sorting body classes
  4073. addClass('body', pref_id, 'sort_direction_' + new_sort_direction);
  4074. subDirClose(); // close subdirs
  4075. // RE-SORT DIRECTORY ITEMS:
  4076. let has_dir = false,
  4077. sorted, iframe_src, iframe_url, iframe_params, items_html_arr = [];
  4078. if (isTopWindow() && hasContent('dir')) {
  4079. has_dir = true;
  4080. iframe_src = getEl('#content_iframe').src;
  4081. }
  4082. Array.from(getEls('.dirlist_item')).forEach(el => items_html_arr.push(el.outerHTML.replace(/border_bottom |border_top /g, ''))); // get elements for new sort
  4083. sorted = sortDirListItems(Array.from(items_html_arr), pref_id, new_sort_direction); // sort the items
  4084. getEl('#directory_list').innerHTML = sorted; // insert sorted items into dir_list
  4085. initDirListEvents();
  4086. initIframeEvents(); // re-initialize dir_list event listeners
  4087. switch (true) {
  4088. case hasContent('font_grid'):
  4089. showGrid('show_font_grid');
  4090. break; // sort grids --> change this to actual sort, not reload
  4091. case hasContent('image_grid'):
  4092. showGrid('show_image_grid');
  4093. break; // sort grids --> change this to actual sort, not reload
  4094. case hasContent('grid'):
  4095. showGrid('show_grid');
  4096. break; // sort grids --> change this to actual sort, not reload
  4097. case has_dir === true: // re-sort iframe directory
  4098. if (elExists('.dirlist_item.selected')) {
  4099. showThis(getEl('.dirlist_item.selected').id);
  4100. } // show the selected directory
  4101. iframe_url = new URL(iframe_src); // create url obj
  4102. iframe_params = new URLSearchParams(iframe_url.search) // create url search params
  4103. iframe_params.set('sort_by', pref_id.slice(pref_id.lastIndexOf('_') + 1)); // set sort_by
  4104. iframe_params.set('sort_direction', new_sort_direction); // set sort_direction params
  4105. iframe_url.search = iframe_params.toString(); // update url search params
  4106. getEl('#content_iframe').src = iframe_url.href;
  4107. break; // reload the iframe with new src url
  4108. case elExists('.dirlist_item.selected:not(.audio)'):
  4109. showThis(getEl('.dirlist_item.selected').id);
  4110. break; // after sort, show selected item; don't autoloadcoverart
  4111. }
  4112. }
  4113.  
  4114. function textEditorTogglePrefs(pref_id) { // ===> TOGGLE TEXT EDITOR PREFERENCES (from menus or toolbar buttons)
  4115. switch (true) {
  4116. case (/texteditor_view_raw|texteditor_view_preview|texteditor_view_html/.test(pref_id)): // toggle texteditor_preview/texteditor_view_html panes
  4117. if (hasClass('body', pref_id)) {
  4118. uiPrefToggle('texteditor_split_view');
  4119. } // don't toggle split when changing texteditor view
  4120. switch (true) {
  4121. case (/texteditor_view_raw/.test(pref_id)):
  4122. addClass('body', 'texteditor_view_raw');
  4123. break; // add pref_id bodyclass
  4124. case (/texteditor_view_preview|texteditor_view_html/.test(pref_id)):
  4125. removeClass('body', 'texteditor_view_preview texteditor_view_html');
  4126. addClass('body', pref_id); // add pref_id bodyclass
  4127. switch (true) { // toggle .texteditor_view_raw
  4128. case !hasClass('body', 'texteditor_split_view_false'):
  4129. addClass('body', 'texteditor_view_raw');
  4130. break;
  4131. default:
  4132. removeClass('body', 'texteditor_view_raw');
  4133. }
  4134. }
  4135. break;
  4136. case (/texteditor_split_view/.test(pref_id)):
  4137. switch (true) {
  4138. case !hasClass('body', 'texteditor_split_view_false'): // add split_view
  4139. addClass('body', 'texteditor_split_view_false');
  4140. searchParamSet('texteditor_split_view', 'false');
  4141. focusEl('#texteditor_txt_pane');
  4142. break;
  4143. default:
  4144. removeClass('body', 'texteditor_split_view_false');
  4145. searchParamDelete('texteditor_split_view'); // remove split_view
  4146. }
  4147. break;
  4148. case (/texteditor_sync_scroll/.test(pref_id)):
  4149. switch (true) {
  4150. case getCurrentUIPref('texteditor_sync_scroll') === 'true':
  4151. searchParamSet('texteditor_sync_scroll', 'false');
  4152. getEl('#texteditor_sync_scroll input').checked = false;
  4153. break;
  4154. default:
  4155. searchParamDelete('texteditor_sync_scroll');
  4156. getEl('#texteditor_sync_scroll input').checked = true;
  4157. }
  4158. break;
  4159. }
  4160. }
  4161. //============================//
  4162. function resizeSidebar(e) {
  4163. e.preventDefault(); // ===> RESIZE SIDEBAR/Content Pane
  4164. menuClose();
  4165. let dir_wrapper = getEl('#dir_wrapper'),
  4166. startX = e.pageX,
  4167. window_width = window.innerWidth,
  4168. sidebar_width = dir_wrapper.offsetWidth;
  4169. addClass('body', 'has_overlay'); // prevent interference from the rest of ui
  4170. document.onmousemove = (f) => {
  4171. f.stopPropagation();
  4172. f.preventDefault();
  4173. let deltaX = f.pageX - startX;
  4174. if (f.pageX > 230 && f.pageX < window_width - 200) {
  4175. dir_wrapper.style.width = (sidebar_width + deltaX) + 'px';
  4176. }
  4177. scrollThis('#directory_list', '.selected', false); // true = instant scroll
  4178. };
  4179. document.onmouseup = (e) => {
  4180. e.stopPropagation();
  4181. removeClass('body', 'has_overlay');
  4182. document.onmousemove = null;
  4183. searchParamSet('width', dir_wrapper.offsetWidth);
  4184. };
  4185. }
  4186. //============================//
  4187. // ***** SORTING ***** //
  4188. function sortAddBorders(sorted) {
  4189. let item_kinds; // ===> ADD SORTING BORDERS
  4190. for (let i = 0; i < sorted.length - 1; i++) {
  4191. item_kinds = sorted[i].match(/data-kind=\"\w+?\" /)[0];
  4192. if (sorted[i + 1].indexOf(item_kinds) === -1) {
  4193. sorted[i] = sorted[i].replace(/class=\"/, 'class="border_bottom ');
  4194. } // add border class
  4195. }
  4196. return sorted;
  4197. }
  4198.  
  4199. function sortItems(items_html_arr, sort_type, sort_direction) { // ===> SORT INDEX ITEMS
  4200. let sort_id = sort_type.split('_').reverse()[0];
  4201. const new_sort = new Intl.Collator(undefined, {
  4202. numeric: true,
  4203. sensitivity: 'base'
  4204. });
  4205. let sorted = [],
  4206. aName, bName, aData, bData; // aLevel, bLevel, aKind, bKind;
  4207. sorted = items_html_arr.sort((a, b) => { // sorted items
  4208. if (!/data-name/.test(a) || !/data-name/.test(b)) {
  4209. null;
  4210. }
  4211. else {
  4212. aName = a.replace(/(.+?)data-name="([^"]+?)"(.+)/g, '$2');
  4213. bName = b.replace(/(.+?)data-name="([^"]+?)"(.+)/g, '$2');
  4214. } // get data-name
  4215. switch (true) { // aData, bData = size, date, kind, ext, time
  4216. case !(new RegExp('data-' + sort_id)).test(a) || !(new RegExp('data-' + sort_id)).test(b):
  4217. break;
  4218. default:
  4219. aData = a.replace((new RegExp('.+?data-' + sort_id + '="([^"]+?)".+')), '$1');
  4220. bData = b.replace((new RegExp('.+?data-' + sort_id + '="([^"]+?)".+')), '$1');
  4221. }
  4222. switch (true) { // sort 'em!
  4223. case sort_direction === 'ascending':
  4224. return (new_sort.compare(aData, bData) === 0 ? new_sort.compare(aName, bName) : new_sort.compare(aData, bData)); // A-Z
  4225. case sort_direction === 'descending':
  4226. return (new_sort.compare(bData, aData) === 0 ? new_sort.compare(bName, aName) : new_sort.compare(bData, aData)); // Z-A
  4227. }
  4228. });
  4229. return sorted; // return sorted items
  4230. }
  4231.  
  4232. function sortDirListItems(items_html_arr, sort_type, sort_direction) { // ===> SORT DIR LIST on click
  4233. let sorted = [],
  4234. sort_all = items_html_arr,
  4235. sort_dirs = items_html_arr.filter(item => (/data-kind=\"dir\"/.test(item))),
  4236. sort_files = items_html_arr.filter(item => (!/data-kind=\"dir\"/.test(item)));
  4237. switch (true) {
  4238. case (/sort_by_size|sort_by_date/.test(sort_type)) && (/has_\w+list/.test(getClassNames('#top_body'))):
  4239. return items_html_arr.join('\n'); // don't sort playlists by size/date
  4240. case sort_type === 'sort_by_default': // if sort default
  4241. const sorted_dirs = sortItems(sort_dirs, sort_type, sort_direction),
  4242. sorted_files = sortItems(sort_files, sort_type, sort_direction); // ...sort dirs and files separately
  4243. switch (true) {
  4244. case sort_direction === 'ascending': // if sort ascending...
  4245. if (sorted_files[0] !== undefined && sorted_dirs[0] !== undefined && !/sort_by_kind|sort_by_ext/.test(sort_type)) {
  4246. sorted_files[0] = sorted_files[0].replace(/class=\"/, 'class="border_top '); // add border class
  4247. }
  4248. sorted = [...sorted_dirs, ...sorted_files]; // sorted = sorted_dirs.concat(sorted_files); // ...dirs before files
  4249. break;
  4250. case sort_direction === 'descending': // sort descending...
  4251. if (sorted_dirs[0] !== undefined && !/sort_by_kind|sort_by_ext/.test(sort_type)) {
  4252. sorted_dirs[0] = sorted_dirs[0].replace(/class=\"/, 'class="border_top ');
  4253. } // add border class
  4254. sorted = [...sorted_dirs, ...sorted_files]; // ...else files before dirs
  4255. }
  4256. break;
  4257. default:
  4258. sorted = sortItems(sort_all, sort_type, sort_direction); // other sorts (name, size, date): files and dirs together
  4259. }
  4260. if (/sort_by_kind|sort_by_ext/.test(sort_type)) {
  4261. sorted = sortAddBorders(sorted);
  4262. } // add borders for sort by kind and ext
  4263. return sorted.join('\n');
  4264. }
  4265. // ***** END BASIC UI FUNCTIONS ***** //
  4266. //============================//
  4267. // ***** CONTENT PANE ***** //
  4268. //============================//
  4269. function contentHeaderButtons(e, id) {
  4270. eStopPrevent(e);
  4271. let incr; // ===> CONTENT HEADER BUTTONS
  4272. switch (true) {
  4273. case (/prev|next/.test(id)): // PREV/NEXT item or audio track
  4274. let key = (/prev_btn|prev_track/.test(id) ? 'ArrowLeft' : /next_btn|next_track/.test(id) ? 'ArrowRight' : null); // define arrowkey
  4275. if (hasClass('body', 'focus_content')) {
  4276. focusEl('#content_pane');
  4277. }
  4278. else {
  4279. getEl('#' + id).parentElement.blur();
  4280. }
  4281. navigateGetEl([key, false]);
  4282. break; // get the next item
  4283. case (/increase|decrease/.test(id)):
  4284. incr = (hasContent('font_file') ? 1.0625 : 1.125);
  4285. scaleItems(e, incr, id, getContentPaneData());
  4286. break; // SCALE BUTTONS; set scaling increment
  4287. }
  4288. }
  4289. // ===> SHOW INDIVIDUAL CONTENT TYPES
  4290. //============================// MEDIA
  4291. function showMedia(kind, id, src, bool) {
  4292. let title = '';
  4293. switch (kind) {
  4294. case 'audio':
  4295. showMedia('close_video');
  4296. removeClass('#content_pane', 'has_audio_error');
  4297. switch (true) {
  4298. case id === 'content_iframe_file': // clicked iframe audio files
  4299. src = decodeURIComponentSafe(src);
  4300. title = src.slice(src.lastIndexOf('/') + 1);
  4301. addClass('#content_pane', 'has_audio has_iframe_audio');
  4302. setAttribute('#content_iframe_utility', 'src', src.slice(0, -4));
  4303. break;
  4304. default: // dir_list audio files
  4305. switch (true) {
  4306. case hasClass('#' + id, 'local'):
  4307. break;
  4308. case bool === 'true': // bool !== undefined: if from autoLoadItems, just select file (don't add .audio_loaded class)
  4309. if (getEl('.dir.content_loaded') !== undefined) {
  4310. addRemoveClassSiblings('.dir.content_loaded', 'selected');
  4311. } // select dir.selected instead of media
  4312. addClass('#' + id, 'selected');
  4313. break;
  4314. default:
  4315. addRemoveClassSiblings('#' + id, 'audio_loaded selected'); // otherwise select loaded media
  4316. }
  4317. title = getEl('#' + id).querySelector('a').innerText;
  4318. addClass('#content_pane', 'has_audio');
  4319. removeClass('#content_pane', 'has_iframe_audio');
  4320. src = getEl('#' + id).querySelector('a').getAttribute('href');
  4321. cuesheetGet(id, src, 'audio'); // get cuesheet
  4322. }
  4323. autoLoadCoverArt(bool, id);
  4324. setAttribute('#audio', 'src', src);
  4325. getEl('#content_audio_title span').innerText = title;
  4326. removeClass('#content_audio_playlist_item', 'has_content');
  4327. break;
  4328. case 'close_audio': // CLOSE AUDIO; pause media; needed in each case, not outside switch
  4329. getEl('#content_audio_title span').innerHTML = '';
  4330. removeClass('body', 'is_playing is_paused');
  4331. removeClass('.dirlist_item.audio_loaded', 'audio_loaded');
  4332. removeClass('#content_pane', 'has_audio has_iframe_audio has_audio_error');
  4333. removeClass('#content_audio_playlist_item', 'has_content');
  4334. messageSend('iframe', 'close_iframe_audio');
  4335. mediaPlayPause('close');
  4336. break;
  4337. case 'video': // SHOW VIDEO
  4338. showMedia('close_audio');
  4339. cuesheetGet(id, src, 'video');
  4340. getEl('#content_pane').dataset.content = 'has_video';
  4341. addClass('#content_video', 'has_content');
  4342. break;
  4343. case 'close_video': // CLOSE VIDEO; pause media; needed in each case, not outside switch
  4344. removeClass('.dirlist_item.video.content_loaded', 'content_loaded');
  4345. removeClass('#content_video', 'has_content');
  4346. removeAttribute('#content_video', 'src');
  4347. removeAttribute('#content_pane', 'data-content');
  4348. mediaPlayPause('close');
  4349. break;
  4350. }
  4351. updateMediaDurations(id, src, kind);
  4352. }
  4353. //============================// MEDIA PLAYBACK
  4354. function mediaGetUpdatedShuffleArray() { // ===> UPDATE TRACKLIST (for shuffle play)
  4355. let playlist = [];
  4356. Array.from(getEls('.dirlist_item.media:not(.unchecked,.disabled,.audio_loaded,.content_loaded,.selected)')).forEach(el => playlist.push(el.id)); // don't include currently selected item
  4357. return playlist;
  4358. }
  4359.  
  4360. function mediaShuffleArray(array) { // ===> SHUFFLE ARRAY: Randomize Shuffle List
  4361. for (let i = array.length - 1; i > 0; i--) {
  4362. const j = Math.floor(Math.random() * (i + 1));
  4363. [array[i], array[j]] = [array[j], array[i]];
  4364. }
  4365. return array;
  4366. }
  4367.  
  4368. function mediaShuffleListUpdate(id) { // ===> UPDATE SHUFFLE LIST
  4369. let shuffle_list;
  4370. switch (true) {
  4371. case !hasClass('body', 'shuffle_media'):
  4372. return; // don't shuffle if normal playback
  4373. case id !== undefined: // handle checked and unchecked media items: id = checked/unchecked item.id
  4374. shuffle_list = getEl('#content_audio').dataset.shufflelist.split(','); // get the dataset.shufflelist and convert to array
  4375. switch (true) {
  4376. case hasClass('#' + id, 'unchecked') || (/audio_loaded|content_loaded/.test(getEl('#' + id).classList.value)): // remove items unchecked since shuffle option first selected
  4377. shuffle_list.splice(shuffle_list.indexOf(id), 1);
  4378. break;
  4379. default:
  4380. shuffle_list.push(id);
  4381. shuffle_list = mediaShuffleArray(shuffle_list); // else add re-checked items to shufflelist
  4382. }
  4383. break;
  4384. default:
  4385. shuffle_list = mediaShuffleArray(mediaGetUpdatedShuffleArray()); // init shufflelist when shuffle option selected
  4386. }
  4387. getEl('#content_audio').dataset.shufflelist = shuffle_list;
  4388. getEl('#shuffle_label').dataset.shufflecount = ' (' + shuffle_list.length + ' remaining)';
  4389. }
  4390.  
  4391. function mediaShuffleGetNextItem() { // ===> GET NEXT SHUFFLED ITEM
  4392. let shuffle_list = getEl('#content_audio').dataset.shufflelist.split(',');
  4393. let shuffled_item_id = shuffle_list.pop(); // get last item in shufflelist for playback
  4394. getEl('#content_audio').dataset.shufflelist = shuffle_list;
  4395. return shuffled_item_id;
  4396. }
  4397.  
  4398. function toggleCheckBox(e, id) {
  4399. let input_el = getEl('#' + id).querySelector('input');
  4400. input_el.checked = !input_el.checked;
  4401. input_el.blur();
  4402. }
  4403.  
  4404. function toggleChecked(e, id) {
  4405. e.stopPropagation();
  4406. let el = getEl('#' + id),
  4407. input_el = getEl('#' + id).querySelector('input');
  4408. input_el.checked = !input_el.checked;
  4409. el.classList.toggle('unchecked');
  4410. mediaShuffleListUpdate(id);
  4411. }
  4412.  
  4413. function toggleAllChecked(e) {
  4414. e.stopPropagation();
  4415. getEls('.dirlist_item.media input').forEach(el => el.click());
  4416. mediaShuffleListUpdate();
  4417. } // ===> TOGGLE ALL MEDIA CHECKBOXES; update shufflelist
  4418. function mediaSkip(e, args) { // ===> MEDIA SKIP +/-10/30 seconds
  4419. let factor, skip;
  4420. switch (true) {
  4421. case e !== undefined:
  4422. factor = (e.key === 'ArrowLeft' ? -1 : 1);
  4423. skip = (e.altKey && e.shiftKey ? 30 : e.altKey ? 10 : null);
  4424. break; // from top
  4425. case args !== undefined:
  4426. factor = (args[0] === 'ArrowLeft' ? -1 : 1);
  4427. skip = args[1] || 0;
  4428. break; // from iframe
  4429. }
  4430. const player = (hasContent('video') ? getEl('#content_video') : getEl('#audio'));
  4431. const time = player.currentTime; // get current time
  4432. player.currentTime = time + factor * (skip); // set new time
  4433. }
  4434.  
  4435. function mediaIsPlaying(id) { // ===> IS PLAYING; returns true if all conditions are true
  4436. switch (true) {
  4437. case !isTopWindow() && !hasClass('body', 'has_quicklook'):
  4438. return (hasClass('body', 'is_playing') ? true : false);
  4439. default:
  4440. return (id !== undefined && getEl('#' + id).currentTime > 0 && !getEl('#' + id).paused && !getEl('#' + id).ended);
  4441. }
  4442. }
  4443.  
  4444. function mediaPlayPause(task) { // ===> PLAY/PAUSE MEDIA
  4445. let player_el = (hasContent('video') ? getEl('#content_video') : getEl('#audio')),
  4446. playing = mediaIsPlaying(player_el.id);
  4447. switch (true) {
  4448. case player_el === null:
  4449. break;
  4450. case task === 'close':
  4451. player_el.removeAttribute('src'); // nobreak;
  4452. case task === 'pause':
  4453. case playing === true:
  4454. try {
  4455. player_el.pause();
  4456. }
  4457. catch (e) {
  4458. null;
  4459. }
  4460. break;
  4461. case task === 'play':
  4462. case playing === false:
  4463. try {
  4464. player_el.play();
  4465. }
  4466. catch (e) {
  4467. null;
  4468. }
  4469. break;
  4470. }
  4471. if (hasContent('iframe_audio')) {
  4472. messageSend('iframe', 'setIframePlayerStatus', '', task);
  4473. }
  4474. }
  4475.  
  4476. function mediaPlayPrevNextIframeItem() { // ===> PLAY PREV/NEXT MEDIA TRACK
  4477. if (!isTopWindow()) {
  4478. getEl('.dirlist_item.selected.media a').trigger('dblclick');
  4479. messageSend('top_body', 'iframe_play_pause_media');
  4480. } // select and send message to top
  4481. }
  4482.  
  4483. function mediaPlaybackOptions(e, id) {
  4484. e.stopPropagation(); // ===> AUDIO PLAYBACK OPTIONS (shuffle, loop)
  4485. let loop_el = getEl('#loop'),
  4486. shuffle_el = getEl('#shuffle');
  4487. switch (true) {
  4488. case id === 'loop':
  4489. case id === 'loop_media_files':
  4490. document.body.classList.toggle('loop_media');
  4491. break;
  4492. case id === 'shuffle':
  4493. case id === 'shuffle_media_files':
  4494. document.body.classList.toggle('shuffle_media');
  4495. mediaShuffleListUpdate();
  4496. break;
  4497. }
  4498. switch (true) { // change audio checkboxes prop
  4499. case id === 'loop_media_files':
  4500. (loop_el.checked === true ? loop_el.checked = false : loop_el.checked = true);
  4501. break;
  4502. case id === 'shuffle_media_files':
  4503. (shuffle_el.checked === true ? shuffle_el.checked = false : shuffle_el.checked = true);
  4504. break;
  4505. }
  4506. if (shuffle_el.checked === false) {
  4507. getEl('#shuffle_label').dataset.shufflecount = '';
  4508. } // remove shufflecount
  4509. }
  4510. //============================// PLAYLISTS/FILELISTS
  4511. function openPlaylist(file_name, reader, data) { // files & reader = open .m3u file; data = m3u.txtfile content// // ===> OPEN PLAYLIST
  4512. let bool, list_class;
  4513. if (!data.startsWith('#EXTM3U')) {
  4514. return;
  4515. } // prevent reading non-playlist files
  4516. if (!/has_\w+list/.test(getClassNames('body'))) { // if body does not already have playlist or filelist...
  4517. let body_classes = document.body.classList; // ...store original dir_list and body "has_"classes as data
  4518. getEl('#directory_list').dataset.dir_list = getEl('#directory_list').innerHTML;
  4519. getEl('#directory_list').dataset.body_classes = body_classes.value; // store the original dir_list and body classes
  4520. body_classes.forEach((body_class) => {
  4521. if (body_class.startsWith('has_')) {
  4522. removeClass('body', body_class);
  4523. }
  4524. }); // remove media and other body classes
  4525. }
  4526. file_name = (file_name !== '' ? file_name : getEl('.dirlist_item.selected.playlist .dirlist_item_name_a').innerText); // get the file name for the title and current_dir_path
  4527. getEl('#current_dir_path span').innerHTML = file_name; // set sidebar header title
  4528. let new_index = buildNewIndex('', prepPlaylist(data), '', 'playlist'); // build the new dir_list
  4529. addClass('body', new_index[1]); // add playlist body classes (has_media, has_audio, etc.)
  4530. list_class = (new_index[1].split(' ').every((el) => ['has_audio', 'has_media', 'has_video'].includes(el)) ? 'has_playlist' : 'has_filelist');
  4531. addClass('body', list_class); // set play- or filelist class
  4532. if (/file:/.test(new_index) && !/file:/.test(window_protocol)) {
  4533. addClass('body', 'has_warning');
  4534. addClass('#directory_list', 'local');
  4535. showWarning('openPlaylist', 'warning_local_playlist');
  4536. } // warn local on non-local page
  4537. getEl('#directory_list').innerHTML = new_index[0]; // replace dir_list with prepared playlist
  4538. autoLoadItems(); // if autoload media...
  4539. scrollThis('#directory_list', '.selected', false);
  4540. document.title = 'Playlist: ' + file_name;
  4541. bool = true;
  4542. initEvents();
  4543. updateStats(bool);
  4544. }
  4545.  
  4546. function closePlaylist() { // files & reader = open .m3u file; data = m3u.txtfile content// // ===> OPEN PLAYLIST
  4547. closeContent('audio');
  4548. closeContent();
  4549. removeClass('body'); // close all content and remove all body classes
  4550. addClass('body', getEl('#directory_list').dataset.body_classes); // restore original body classes
  4551. getEl('head title').innerText = 'Index of ' + window_location; // restore window title
  4552. getEl('#current_dir_path span').innerHTML = current_dir_path; // restore current_dir_path tilte
  4553. getEl('#directory_list').innerHTML = getEl('#directory_list').dataset.dir_list; // restore original dir_list...
  4554. if (elExists('.dirlist_item.content_loaded')) {
  4555. showThis(getEl('.dirlist_item.content_loaded')?.id);
  4556. } // reopen selected dirlist item
  4557. if (elExists('.dirlist_item.audio_loaded')) {
  4558. showThis(getEl('.dirlist_item.audio_loaded')?.id);
  4559. } // reopen selected dirlist audio item
  4560. delete getEl('#directory_list').dataset.dir_list;
  4561. delete getEl('#directory_list').dataset.body_classes; // ...and remove data
  4562. initEvents();
  4563. updateStats(false);
  4564. }
  4565.  
  4566. function playlistMake() { // ===> MAKE PLAYLIST file from directory files for export as m3u
  4567. let items, playlist = [];
  4568. let playlist_type = getEl('#make_playlist_form input:checked').id;
  4569. switch (playlist_type) { // get playlist items according to selected type
  4570. case 'media_files_only':
  4571. items = getEls('.dirlist_item.media:not(.unchecked)');
  4572. break;
  4573. case 'audio_files_only':
  4574. items = getEls('.dirlist_item.audio:not(.unchecked)');
  4575. break;
  4576. case 'video_files_only':
  4577. items = getEls('.dirlist_item.video:not(.unchecked)');
  4578. break;
  4579. case 'all_non_media_files':
  4580. items = getEls('.dirlist_item.non_media');
  4581. break;
  4582. case 'all_items':
  4583. items = getEls('.dirlist_item');
  4584. break;
  4585. case 'directories_only':
  4586. items = getEls('.dirlist_item.dir');
  4587. break;
  4588. case 'files_only':
  4589. items = getEls('.dirlist_item.file');
  4590. break;
  4591. }
  4592. switch (true) {
  4593. default:
  4594. items.forEach((item) => {
  4595. playlist.push(playlistMakeItem(item.id, true));
  4596. }); // make playlist entry for each item
  4597. playlist = '#EXTM3U\n' + playlist.join('\n'); // add playlist header id
  4598. saveFile(playlist, 'audio/mpeg-url', (getEl('#current_dir_path').innerText).split('/').reverse()[1] + '.m3u'); // save m3u with default name = current dir name
  4599. closeWarning(); // close warning
  4600. }
  4601. }
  4602. // Make playlist entry for display in title bar
  4603. function playlistMakeItem(id, bool) { //*** id = 'content_title' or 'content_audio_title', bool = true --> from playlistMake(), otherwise from playlistShowItem(); ***//
  4604. let title, link, duration, full_path = window.location.protocol + window.location.hostname + window.location.pathname;
  4605. title = (hasContent('grid') && id === 'content_title' ? 'Files from: ' + full_path : bool === true ? getEl('#' + id).dataset.name : getEl('#' + id).innerText); // get title txt
  4606. switch (true) { // Get link
  4607. case bool === true:
  4608. link = getEl('#' + id).querySelector('a').href;
  4609. break; // get item link for filelists
  4610. case hasContent('grid') && id === 'content_title':
  4611. link = full_path;
  4612. break; // grid link = dir path
  4613. case id === 'content_title':
  4614. link = (hasContent('image') ? getAttribute('#content_image', 'src') : getAttribute('.content_el.has_content', 'src'));
  4615. break; // content link
  4616. case id === 'content_audio_title':
  4617. link = getLinkInfo(getAttribute('#audio', 'src'))[0].trim();
  4618. break; // audio link
  4619. }
  4620. link = (link.startsWith('/') ? window.location.protocol + '//' + link : link); // fix links without protocols (local files)
  4621. link = new URL(link); // make new URL from link
  4622. link = link.protocol + '//' + link.hostname + link.pathname; // compose link
  4623. duration = (hasContent('video') ? Number.parseInt(getEl('#video').duration) : id === 'content_audio_title' ? Number.parseInt(getEl('#audio').duration) : '');
  4624. return '#EXTINF:' + duration + ',' + title + '\n' + link + '\n'; // return composed playlist entry
  4625. }
  4626.  
  4627. function playlistShowItem(id) { // ===> SHOW PLAYLIST ENTRY
  4628. switch (true) {
  4629. case id === 'close':
  4630. removeClass('#content_playlist_item,#content_audio_playlist_item', 'has_content');
  4631. getEls('#content_header textarea').forEach(el => el.value = '');
  4632. return;
  4633. case hasContent('audio_error') && id === 'content_audio_title':
  4634. closeContent('audio');
  4635. case !hasContent():
  4636. case hasContent('texteditor'):
  4637. return;
  4638. }
  4639. let el_id = (id === 'content_title' ? 'content_playlist_item' : id === 'content_audio_title' ? 'content_audio_playlist_item' : '');
  4640. document.getElementById(el_id).classList.toggle('has_content');
  4641. document.getElementById(el_id).querySelector('textarea').value = playlistMakeItem(id);
  4642. textareaSelectContent(document.getElementById(el_id).querySelector('textarea').id); // add entry to the textarea
  4643. document.getElementById(el_id).querySelector('textarea').focus();
  4644. }
  4645. //============================// CUESHEETS
  4646. function cuesheetGet(id, link, kind) { // id = 'content_iframe_file' or 'dir_list.media.id', link = selected.href, kind = audio/video // ===> GET CUE SHEET
  4647. if (id === 'content_iframe_file') {
  4648. return;
  4649. } // prevent error for iframe files
  4650. removeClass('.cuesheet_track_list_container', 'has_cue_sheet'); // reset cuesheet container
  4651. getEl('#cuesheet_track_list_audio').innerHTML = ''; // empty existing cue sheet track list
  4652. let media_file_name = decodeURIComponentSafe(getEl('#' + id).dataset.name);
  4653. let cue_file_name = decodeURIComponentSafe(media_file_name).slice(0, media_file_name.lastIndexOf('.')) + '.cuetxt',
  4654. cue_file_link = '';
  4655. let cue_file = getEl('.dirlist_item.code[data-name="' + cue_file_name + '"'); // get the cuesheet id
  4656. if (cue_file !== null) {
  4657. cue_file_link = document.getElementById(cue_file.id).querySelector('a').href.trim();
  4658. getEl('#content_iframe_utility').src = cue_file_link; // set utility iframe src for processing
  4659. switch (kind) { // get durations
  4660. case 'audio':
  4661. setAttribute('#cuesheet_track_list_container_audio', 'data-duration', getEl('#audio').duration);
  4662. break;
  4663. case 'video':
  4664. setAttribute('#cuesheet_track_list_container_video', 'data-duration', getEl('#content_video').duration);
  4665. break;
  4666. }
  4667. }
  4668. }
  4669.  
  4670. function cuesheetProcess(cuesheet_text) { // ===> PROCESS CUE SHEET
  4671. let cuesheet_tracks, track, prepped_track, prepped_track_list = [],
  4672. track_header, track_id, display_time, index, index_sec, container_id, commands_arr = ['PERFORMER', 'TITLE', 'INDEX'],
  4673. track_command, classes = 'cuesheet_track display_grid background_grey_85 pointer padding_4_6';
  4674. cuesheet_text = cuesheet_text.replace(/\t/g, ' ');
  4675. cuesheet_tracks = (!cuesheet_text.startsWith('TRACK') ? cuesheet_text.slice(cuesheet_text.indexOf('TRACK ')).split('TRACK ').reverse() : cuesheet_text.split('TRACK ').reverse());
  4676. for (track of cuesheet_tracks) {
  4677. prepped_track = [];
  4678. track = track.trim().split(/[\n\r]/);
  4679. track_id = track.shift().split(' ')[0]; // for each track in the cue sheet...
  4680. for (let i = 0; i < commands_arr.length; i++) { // and for each command in commands_arr...
  4681. for (track_command of track) { // and for each command in the track
  4682. if (track_command.match(commands_arr[i])) {
  4683. track_command = track_command.trim().replace(/^(performer|title|index\s+\d+)\s*/mgi, '').replace(/^('|\"|\&quot;)|('|\"|\&quot;)$/mgi, ''); // prep the displayed track information
  4684. // format INDEX command; N.B.: time format = mm:ss:ff (ff = frames @ 75fr/sec):
  4685. if (commands_arr[i] === 'INDEX') {
  4686. display_time = track_command.replace(/INDEX\s+\d+\s+/, '');
  4687. index = display_time.split(':').reverse();
  4688. index_sec = index[0] / 75 + index[1] * 1 + index[2] * 60;
  4689. }
  4690. prepped_track[i] = '<span class="cue_' + commands_arr[i].toLowerCase() + '">' + (track_command.length === 0 ? '—' : track_command) + '</span>';
  4691. }
  4692. }
  4693. }
  4694. prepped_track.unshift(`<li id="cuesheet_item_${track_id}" class="${classes}" data-duration="${index_sec}"><span class="cue_index align_right">${track_id}</span>`); // add prepped_track prefix html
  4695. prepped_track_list.push(prepped_track.join('')); // add prepped_track to prepped_track_list
  4696. }
  4697. prepped_track_list.pop();
  4698. prepped_track_list = prepped_track_list.reverse().join('</li>') + '</li>'; // remove mystery empty track item; create prepped track list
  4699. track_header = '<li class="cuesheet_track header display_grid cursor_default background_grey_85 border_top border_bottom bold"><span class="cue_track_id"></span><span class="cue_performer">Performer</span><span class="cue_title">Title</span><span class="cue_index align_right" title="mm:ss:ff">Time</span></li>';
  4700. switch (true) {
  4701. case elExists('.dirlist_item.audio_loaded'):
  4702. case hasContent('iframe_audio'):
  4703. container_id = '#cuesheet_track_list_audio';
  4704. break;
  4705. case elExists('.dirlist_item.video.content_loaded'):
  4706. case hasContent('iframe_file'):
  4707. container_id = '#cuesheet_track_list_video';
  4708. break;
  4709. }
  4710. getEl(container_id)?.closest('nav')?.classList.add('has_cue_sheet');
  4711. getEl(container_id)?.insertAdjacentHTML('beforeend', track_header + prepped_track_list); // add cue sheet track list to menu
  4712. initCuesheetEvents(); // init cuesheet event listeners
  4713. }
  4714. //============================// FONTS
  4715. function fontRestoreOptions(id) { // restore font toolbar values after closing previewed glyph with modified options values
  4716. getEl('#font_size').value = getEl(id).dataset.scale;
  4717. getEl('#text_color').value = getEl(id).style.color; // restore size and color
  4718. switch (true) { // restore text stroke color & width
  4719. case id === '#font_file_grid':
  4720. getEl('#text_stroke_width').value = getEl(id).querySelector('svg path').getAttribute('stroke-width')?.replace(/[A-z]+/, '') || '';
  4721. getEl('#text_stroke_color').value = getEl(id).querySelector('svg path').getAttribute('stroke') || '';
  4722. break;
  4723. case id === '#font_specimen_viewer':
  4724. getEl('#text_stroke_width').value = getEl(id).style.webkitTextStrokeWidth.replace(/[A-z]+/, '');
  4725. getEl('#text_stroke_color').value = getEl(id).style.webkitTextStrokeColor;
  4726. break;
  4727. }
  4728. }
  4729.  
  4730. function showFont(id, bool, font_grid, link, i, font_items_length) { // ===> SET FONT CSS rules or create font grid items (bool === true) // id from gridMakeFontItems(); link = from previewed directory
  4731. let font_styles = getEl('#font_styles'),
  4732. border_class = '',
  4733. last_item_class = '',
  4734. display_name, font_grid_item_info = '',
  4735. font_grid_item_el = '';
  4736. let font_family = (link !== '' ? link?.slice(link.lastIndexOf('/') + 1, link?.lastIndexOf('.')) : getEl('#' + id).dataset.name);
  4737. font_family = decodeURIComponentSafe(font_family); // get CSS font family
  4738. let font_url = (link !== '' ? link : getAttribute('#' + id + ' a', 'href'));
  4739. font_url = decodeURIComponentSafe(font_url); // get CSS font src
  4740. switch (true) {
  4741. case bool === false: // If bool === false, set CSS rules for previewed fonts
  4742. font_styles.innerHTML = `@font-face { font-family: "${ font_family }"; src: url("${ font_url }"); }`; // insert new @font-face rule
  4743. addClass('#content_pane', 'has_font_specimen');
  4744. getEl('#font_specimen_viewer').style.fontFamily = '"' + font_family + '"'; // set content font style
  4745. getEl('#font_specimen_viewer').style.fontSize = getEl('#font_size').value + 'em';
  4746. getEl('#font_specimen_viewer').style.lineHeight = (Number(getEl('#line_height').value) === 0 ? 1.2 : Number(getEl('#line_height').value) + 1.2);
  4747. getEl('#font_specimen_viewer').style.letterSpacing = getEl('#letter_spacing').value;
  4748. getEl('#font_specimen_viewer').style.webkitTextStrokeWidth = getEl('#text_stroke_width').value;
  4749. getEl('#text_color').value = getEl('#font_specimen_viewer').style.color;
  4750. getEl('#text_stroke_color').value = getEl('#font_specimen_viewer').style.webkitTextStrokeColor;
  4751. break;
  4752. case font_grid === 'font_grid': // ...else (if bool === true) make grid font items
  4753. display_name = font_family;
  4754. if (i === font_items_length - 1) {
  4755. last_item_class = 'border_bottom_x';
  4756. }
  4757. if (i > 0) {
  4758. border_class = 'border_top_x';
  4759. }
  4760. font_grid_item_info = `<p class="font_grid_item_info margin_0 text_color_default font_size_small line_height_1">${ display_name.toUpperCase() }</p><h2 style=\'font-family: "${ font_family }"\'; class="margin_0 normal"><a class="text_color_default" href="${ font_url }">${ display_name.slice(0,font_family.lastIndexOf(".")) }</a></h2>`;
  4761. font_grid_item_el = `<li class="grid_item font_grid_item ${border_class} ${last_item_class} background_grey_90" data-id="${ id }" data-kind="font">${ font_grid_item_info }</li>`;
  4762. if (getEl('#font_grid_styles').innerHTML.indexOf(font_family) === -1) { // only add font family style if it isn't already there
  4763. getEl('#font_grid_styles').insertAdjacentHTML('beforeend', `@font-face { font-family: "${ font_family }"; src: url("${ font_url }"); }`);
  4764. }
  4765. return font_grid_item_el;
  4766. }
  4767. initFontPreviewEvents();
  4768. }
  4769.  
  4770. function closeFont() {
  4771. switch (true) {
  4772. case hasContent('iframe_file,iframe_dir'):
  4773. showThis(getEl('.dirlist_item.non_media.selected')?.id);
  4774. break; // if iframe item, reopen sidebar dir
  4775. case hasContent('font_file_glyph'):
  4776. removeClass('#content_pane', 'has_font_file_glyph');
  4777. addClass('#content_pane', 'has_font_file'); // CLOSE FONT_FILE_GLYPH font_specimen_grid
  4778. getEl('#svg_container g').style.transform = 'scale(1)';
  4779. fontRestoreOptions('#font_file_grid');
  4780. break; // reset font_scale slider
  4781. case hasContent('font_file'):
  4782. showWarning('showFont', 'close');
  4783. break; // CLOSE FONT FILE with warning
  4784. case hasContent('font_specimen_glyph'): // CLOSE FONT_SPECIMEN_GLYPH
  4785. removeClass('#content_pane', 'has_font_specimen_glyph');
  4786. addClass('#content_pane', 'has_font_specimen');
  4787. removeAttribute('#font_specimen_glyph', 'style');
  4788. removeAttribute('#font_specimen_viewer', ['data-char', 'data-unicode_hex']);
  4789. getEl('#font_specimen_glyph').innerText = '';
  4790. fontRestoreOptions('#font_specimen_viewer');
  4791. break; // reset font_scale slider
  4792. // close font_specimen
  4793. case getEl('#font_specimen_grid').children?.length > 0:
  4794. getEl('#font_specimen_grid').innerHTML = '';
  4795. getEl('#unicode_char_ranges_select').value = '';
  4796. showContentPaneEl('font');
  4797. break;
  4798. case hasContent('font_specimen'):
  4799. getEl('#content_pane').dataset.content = 'has_null';
  4800. getEl('#content_pane').dataset.loaded_id = null;
  4801. removeClass('#content_pane', 'has_font_specimen has_file');
  4802. removeClass('#content_font', 'has_content');
  4803. setContentTitle('close');
  4804. break;
  4805. // close font
  4806. default:
  4807. setAttribute('#content_pane', 'data-content', 'has_null');
  4808. removeClass('#content_pane', 'has_font_specimen has_font_specimen_glyph has_font_file has_font_file_glyph');
  4809. removeClass('#content_font', 'has_content');
  4810. removeAttribute('#content_font', 'src');
  4811. removeAttribute('#font_specimen_viewer', 'style');
  4812. setContentTitle('close');
  4813. focusEl('#top_body');
  4814. break;
  4815. }
  4816. }
  4817.  
  4818. function showFontGlyph(e, id) {
  4819. e?.stopPropagation(); // ===> SHOW INDIVIDUAL GLYPH
  4820. let this_glyph, glyph_viewer, data_glyph_SVG, glyph_name, unicode_dec, unicode_hex, svg_container;
  4821. if ((e?.type === 'click' || e?.key === 'Enter') && /glyph_container/.test(id)) {
  4822. removeClass('#font_file_grid .selected', 'selected');
  4823. addClass('#' + id, 'selected');
  4824. } // select clicked or
  4825. if (!hasContent('font_file_glyph') && !hasContent('font_specimen_glyph')) {
  4826. getEl('#font_size').value = 1;
  4827. }
  4828. switch (true) {
  4829. case id === 'close':
  4830. case id === 'close_specimen':
  4831. closeContent('font');
  4832. return; // close font glyph
  4833. case (/font_specimen/.test(id)):
  4834. case hasContent('font_specimen'):
  4835. case hasContent('font_specimen_glyph'): // font specimens and font specimen glyphs
  4836. this_glyph = getEl('#' + id);
  4837. glyph_viewer = getEl('#font_specimen_viewer');
  4838. getEl('#font_specimen_glyph').innerText = String.fromCodePoint(this_glyph.dataset.unicode_dec); // add glyph to specimen glyph
  4839. glyph_name = String.fromCodePoint(this_glyph.dataset.unicode_dec);
  4840. unicode_dec = this_glyph.dataset.unicode_dec;
  4841. unicode_hex = this_glyph.dataset.unicode_hex;
  4842. removeClass('#content_pane', 'has_font_specimen');
  4843. addClass('#content_pane', 'has_font_specimen_glyph');
  4844. scrollThis('#font_specimen_grid', '.selected');
  4845. break; // hide font_specimen, show font_specimen glyph
  4846. case hasContent('font_file'):
  4847. case hasContent('font_file_glyph'): // font files and font file glyphs
  4848. this_glyph = getEl('#' + id) || getEl('#font_file_grid .selected');
  4849. glyph_viewer = getEl('#font_file_glyph_viewer');
  4850. data_glyph_SVG = this_glyph.querySelector('svg').cloneNode(true); // get glyph by id, glyph path, & glyph SVG
  4851. data_glyph_SVG.setAttribute('viewBox', '0 0 50 160');
  4852. data_glyph_SVG.style.width = '100%';
  4853. data_glyph_SVG.style.height = '100%';
  4854. data_glyph_SVG.style.color = getEl('#text_color').value; // set attrs & styles
  4855. data_glyph_SVG.classList.remove('invert');
  4856. data_glyph_SVG.classList.add('overflow_visible');
  4857. data_glyph_SVG.querySelector('g').style.transform = 'scale(' + glyph_viewer.dataset.scale + ')';
  4858. if (elExists('#svg_container')) { // if a glyph is being shown...
  4859. getEl('#svg_container svg').remove();
  4860. getEl('#svg_container').insertAdjacentHTML('beforeend', data_glyph_SVG.outerHTML);
  4861. svg_container = getEl('#svg_container').outerHTML; // get svg_container, add new svg;
  4862. }
  4863. else { // ...and so preserve any added styles
  4864. svg_container = '<div id="svg_container" class="display_flex invert position_relative width_100 height_100">' + data_glyph_SVG.outerHTML + '</div>'; // else create new svg container
  4865. }
  4866. getEl('#glyph_container')?.remove(); // remove existing glyph_container
  4867. glyph_viewer.insertAdjacentHTML('beforeend', '<div id="glyph_container" class="flex_justify_center">' + svg_container + '</div>'); // add the glyph_container to font_file_glyph_viewer
  4868. glyph_name = this_glyph.dataset.glyph_name;
  4869. unicode_dec = this_glyph.dataset.unicode_dec;
  4870. unicode_hex = this_glyph.dataset.unicode_hex;
  4871. getEl('#svg_container').onmousedown = function (e) {
  4872. fontGlyphMove(e, '#svg_container')
  4873. }; // init fontGlyphMove
  4874. removeClass('#content_pane', 'has_font_file');
  4875. addClass('#content_pane', 'has_font_file_glyph');
  4876. scrollThis('#font_file_grid', '.selected');
  4877. break; // hide font_file grid, show font_file_glyph
  4878. }
  4879. glyph_viewer.dataset.glyph_name = glyph_name;
  4880. glyph_viewer.dataset.unicode_dec = 'Unicode Dec: ' + unicode_dec;
  4881. glyph_viewer.dataset.unicode_hex = 'Unicode Hex: ' + unicode_hex;
  4882. }
  4883.  
  4884. function openFontFile(files, reader, bool) { // ===> OPEN FONT FILE
  4885. getEl('#font_file_viewer').remove();
  4886. getEl('#content_font').insertAdjacentHTML('beforeend', Content_Font_Viewer); // reset font_file_viewer
  4887. switch (true) {
  4888. case files === 'close': // close font file
  4889. removeClass('body', 'focus_content');
  4890. removeAttribute('#content_pane', 'data-content');
  4891. removeClass('#content_pane', 'has_font_specimen has_font_specimen_glyph has_font_file has_font_file_glyph'); // remove content_pane attrs and classes
  4892. removeClass('#content_font', 'has_content'); // remove content_font classes
  4893. getEl('#font_file_grid').innerHTML = '';
  4894. getEl('#content_title span').innerHTML = ''; // empty font_file_grid and content_title
  4895. if (bool === undefined) { // show previously loaded content or close content, but not if bool
  4896. if (getEl('.dirlist_item.content_loaded')) {
  4897. showThis(getEl('.dirlist_item.content_loaded')?.id);
  4898. }
  4899. else {
  4900. showThis('close');
  4901. } // (but not when opening new font file)
  4902. }
  4903. break;
  4904. default: // show font file
  4905. if (!hasContent('font_file') && !/has_\w+list/.test(getClassNames('#top_body'))) {
  4906. showThis('close');
  4907. } // close content & hide grids
  4908. removeClass('#content_pane', 'has_font_specimen has_font_specimen_glyph has_font_file_glyph');
  4909. addClass('#content_pane', 'has_font_file'); // content_pane classes
  4910. setContentPaneAttrs(files.name, 'font', 'content_font', files.name);
  4911. showContentPaneEl('font');
  4912. getEl('#font_file_glyph_viewer').dataset.scale = 1; // reset font file glyph viewer
  4913. makeFontGlyphItems('font_file', reader.result); // => make glyph items from font file
  4914. getEls('.glyph_container').forEach(el => el.addEventListener('click', (e) => showFontGlyph(e, el.id))); // init click listener for each glyph
  4915. focusEl('#font_file_grid'); // focus font_file_grid
  4916. }
  4917. }
  4918.  
  4919. function getFontFileInfo(font) { // ===> GET FONT INFO
  4920. let font_names = font.names,
  4921. font_info_details = '',
  4922. name, value;
  4923. for (name in font_names) {
  4924. value = font_names[name].en;
  4925. if (name.endsWith('URL')) {
  4926. let href = (!value.startsWith('http') ? 'http://' + value : value); // in case url without protocol is used
  4927. value = '<a class="bold" href="' + href + '" target="_blank">' + value + '</a>';
  4928. }
  4929. font_info_details += `<li class="display_none"><span class="col_1 font_info_name align_right"> ${name}: </span><span class="font_info_value">${value}</span></li>`;
  4930. }
  4931. let font_info = `<ul id="font_info" class="info_list font_size_small border_all margin_0 padding_0 text_color_default background_grey_80 position_fixed z_index_2"> <li class="info_list_header center bold"><span>FONT INFO:${font.names.fullName.en.toUpperCase()}</span></li> ${font_info_details} <li class="display_none"><span class="col_1 font_info_name align_right">numGlyphs: </span><span class="font_info_value">${font.numGlyphs}</span></li> </ul>`;
  4932. getEl('#font_file_viewer').insertAdjacentHTML('beforeend', font_info);
  4933. }
  4934. // FONT GLYPHS
  4935. function makeFontGlyphItem(kind, index, glyph) { // MAKE FONT GLYPH GRID ITEM; "index" is for font_specimens, "glyph" for font_files
  4936. let glyph_svg, glyph_index, glyph_name, glyph_dec, glyph_hex, glyph_path, glyph_boundingbox, tab_order = (index === 0 ? 'data-tab_order="0"' : ''); // glyph_width,glyph_height,glyph_advancewidth,glyph_leftsidebearing;
  4937. switch (kind) {
  4938. case 'font_file':
  4939. glyph_name = glyph.name;
  4940. glyph_index = glyph.index;
  4941. glyph_dec = (glyph.unicode !== undefined ? glyph.unicode : '');
  4942. glyph_hex = (glyph_dec !== null ? convertDecimal2Hex(glyph_dec, 4) : ''); // get glyph dec and hex values
  4943. glyph_path = glyph.getPath(0, 100, 72);
  4944. glyph_boundingbox = glyph_path.getBoundingBox();
  4945. glyph_path = glyph_path.toSVG().replace(/"/g, '\'').replace(/path /g, 'path fill=\'currentColor\' '); // define glyph svg path and escape "
  4946. glyph_svg = `<svg xmlns=\'http://www.w3.org/2000/svg\' x=\'0px\' y=\'0px\' viewBox=\'${(glyph_boundingbox.x1 < 0 ? 0 : glyph_boundingbox.x1)} 20 ${Math.abs(glyph_boundingbox.x2)} ${glyph_boundingbox.y2}\' xml:space=\'preserve\' preserveAspectRatio=\'xMidYMid meet\'><g>${glyph_path}</g></svg>`;
  4947. break;
  4948. case 'font_specimen':
  4949. glyph_index = index;
  4950. glyph_dec = index;
  4951. glyph_hex = convertDecimal2Hex(index, 4);
  4952. break;
  4953. }
  4954. return `<li id="${kind}_glyph_container_${glyph_index}" data-id="glyph_container_${glyph_index}" data-glyph_name="${glyph_name || ''}" ${tab_order} data-unicode_dec="${glyph_dec}" data-unicode_hex="U+${glyph_hex}" class="grid_item font_glyph_item glyph_container flex_justify_center border_right_x border_bottom_x position_relative"><div class="glyph display_block">${glyph_svg || String.fromCharCode(glyph_index)}</div></li>`; // return glyph item
  4955. }
  4956.  
  4957. function makeFontGlyphItems(kind, data, bool) { // MAKE FONT GLYPH GRIDS; kind,data === font_specimen,char_block_id or font_file,fontblob
  4958. let glyph_items = '',
  4959. font_file, font_glyphs, font_file_grid = getEl('#font_file_grid'),
  4960. loop_start, loop_end;
  4961. switch (kind) {
  4962. case 'font_file': // display font_file glyphs
  4963. font_file = window.opentype.parse(data); // parse font (req opentype.js)
  4964. font_glyphs = font_file.glyphs; // get font glyphs
  4965. getEl('#font_file_glyph_viewer').dataset.font_name = font_file.names.fullName.en; // add font name to glyph viewer dataset
  4966. loop_start = 0, loop_end = font_glyphs.length;
  4967. break;
  4968. case 'font_specimen': // for displaying unicode char_block ranges
  4969. if (data !== '') {
  4970. loop_start = convertHex2Decimal(getEl('#' + data).dataset.block_start);
  4971. loop_end = convertHex2Decimal(getEl('#' + data).dataset.block_end) + 1;
  4972. }
  4973. break; // loop char_block start/end range
  4974. }
  4975. for (let i = loop_start; i < loop_end; i++) {
  4976. glyph_items += makeFontGlyphItem(kind, i, font_glyphs?.glyphs?.[i]);
  4977. } // loop make glyph items for glyph grids
  4978. switch (true) {
  4979. case bool:
  4980. return glyph_items;
  4981. case data === '':
  4982. getEl('#font_specimen_grid').innerHTML = '';
  4983. break; // close font_specimen_grid
  4984. case kind === 'font_file':
  4985. getFontFileInfo(font_file);
  4986. font_file_grid.insertAdjacentHTML('beforeend', glyph_items);
  4987. initFontPreviewEvents();
  4988. break;
  4989. case kind === 'font_specimen':
  4990. getEl('#font_specimen_grid').innerHTML = glyph_items.trim();
  4991. initFontPreviewEvents();
  4992. focusEl('#content_pane');
  4993. break;
  4994. }
  4995. }
  4996.  
  4997. function fontGlyphMove(e, sel) {
  4998. e.stopPropagation();
  4999. let startX = e.pageX,
  5000. startY = e.pageY,
  5001. elOffsetLeft = getEl(sel).offsetLeft,
  5002. elOffsetTop = getEl(sel).offsetTop;
  5003. document.onmousemove = function (e) {
  5004. mouseMove(e, sel, startX, startY, elOffsetLeft, elOffsetTop);
  5005. }
  5006. }
  5007.  
  5008. function fontGlyphSave() { // ===> SAVE GLYPH SVG
  5009. let data = getEl('#svg_container svg').cloneNode(true),
  5010. file_name = getEl('#font_file_glyph_viewer').dataset.font_name + '_' + getEl('#font_file_glyph_viewer').dataset.glyph_name;
  5011. data.setAttribute('viewBox', '0 0 120 120');
  5012. data.removeAttribute('class');
  5013. data.querySelector('g').removeAttribute('style');
  5014. saveFile(data.outerHTML, 'image/svg+xml', file_name);
  5015. }
  5016. // FONT UTILITIES
  5017. function fontOptions(e, id, value, variant_prop, variant_value) {
  5018. eStopPrevent(e); // value sets select el and font-feature-settings; if variant_prop exists, it is used to set font-variant value
  5019. let props = {
  5020. 'font_size': 'font-size',
  5021. 'line_height': 'line-height',
  5022. 'letter_spacing': 'letter-spacing',
  5023. 'text_color': 'color',
  5024. 'text_stroke_width': '-webkit-text-stroke-width',
  5025. 'text_stroke_color': '-webkit-text-stroke-color'
  5026. };
  5027. let prop = (variant_prop || props[id] || 'font-feature-settings'),
  5028. units = (/font_size|letter_spacing|text_stroke_width/.test(id) ? 'em' : ''),
  5029. text_stroke_color, current_stroke_color, fontElId;
  5030. switch (true) { // font_toolbar row 1: #font_specimen_variants
  5031. // #font_toolbar row 1 items: font_file_viewer
  5032. case (/font_variant_select/.test(id)):
  5033. setValue('#font_tag_textarea', value);
  5034. getEl('#' + id).focus();
  5035. break; // select variants/stylistic sets
  5036. case id === 'font_tag_textarea': // textarea font tags; set corresponding font_variant_select value
  5037. switch (true) {
  5038. case value === null:
  5039. setValue('#font_tag_textarea', '');
  5040. return; // if value === null: reset
  5041. case Number(value?.length) < 4:
  5042. setValue('#font_variant_select', '');
  5043. break; //
  5044. case value?.startsWith('cv'):
  5045. setValue('#font_variant_select', 'cv01');
  5046. break; //
  5047. case value?.startsWith('nalt'):
  5048. setValue('#font_variant_select', 'nalt');
  5049. break; //
  5050. case value?.startsWith('ornm'):
  5051. setValue('#font_variant_select', 'ornm');
  5052. break; //
  5053. case value?.startsWith('salt'):
  5054. setValue('#font_variant_select', 'salt');
  5055. break; //
  5056. case value?.startsWith('ss'):
  5057. setValue('#font_variant_select', 'ss01');
  5058. break; //
  5059. case value?.startsWith('swsh'):
  5060. setValue('#font_variant_select', 'swsh');
  5061. break; //
  5062. default:
  5063. setValue('#font_variant_select', value.slice(0, 4));
  5064. break; //
  5065. }
  5066. break; // focus font_tag_textarea
  5067. case id === 'unicode_char_ranges_select':
  5068. makeFontGlyphItems('font_specimen', value);
  5069. getEl('#content_font').scroll(0, 0);
  5070. return; // unicode chars startsWith
  5071. // #font_toolbar row 2 items:
  5072. case id === 'font_size':
  5073. scaleFonts(null, value, 'font_size');
  5074. return;
  5075. case id === 'line_height':
  5076. value = Number(value) + 1.2;
  5077. if (value === 1.2) {
  5078. getEl('#' + id).value = 0;
  5079. }
  5080. break; // line-height; default 1.2
  5081. case id === 'letter_spacing':
  5082. value = (Number(value) < 0 ? value / 50 : Math.pow(value / 50, 2));
  5083. if (value === 0) {
  5084. getEl('#' + id).value = 0;
  5085. }
  5086. break; // letter-spacing
  5087. case id === 'text_color':
  5088. if (value === null) {
  5089. getEl('#' + id).value = '';
  5090. value = '';
  5091. }
  5092. break; // if value === null: reset
  5093. case id === 'text_stroke_width':
  5094. current_stroke_color = getEl('#text_stroke_color').value;
  5095. text_stroke_color = (value < 0 ? 'white' : (current_stroke_color === '' || /white|black/.test(current_stroke_color)) && value > 0 ? 'black' : current_stroke_color)
  5096. getEl('#font_specimen_viewer')?.style.setProperty('-webkit-text-stroke-color', text_stroke_color);
  5097. value = Math.abs(Number(value));
  5098. if (value === 0) {
  5099. getEl('#' + id).value = 0;
  5100. getEl('#text_stroke_color').value = '';
  5101. }
  5102. break; // if value === 0: reset
  5103. case id === 'text_stroke_color':
  5104. if (value === null) {
  5105. getEl('#' + id).value = '';
  5106. fontOptions(null, 'text_stroke_width', null);
  5107. } // if value === null: reset
  5108. value = (getEl('#text_stroke_width').value < 0 ? 'white' : getEl('#text_stroke_color').value !== '' ? getEl('#text_stroke_color').value : 'black');
  5109. break;
  5110. }
  5111. switch (true) { // determine element(s) to target
  5112. case hasContent('font_file_glyph'):
  5113. fontElId = (/text_stroke/.test(id) ? '#svg_container path' : '#svg_container');
  5114. break; // el = svg_container or svg path
  5115. case hasContent('font_file'):
  5116. fontElId = (/text_stroke/.test(id) ? '#font_file_viewer path' : '#font_file_grid');
  5117. break; // el = svg_container or svg path
  5118. case hasContent('font_specimen_glyph'):
  5119. fontElId = '#font_specimen_glyph';
  5120. break;
  5121. case hasContent('font_specimen'):
  5122. fontElId = '#font_specimen_viewer';
  5123. break;
  5124. }
  5125. switch (true) { // apply style to font element
  5126. case hasContent('font_file') && /text_stroke/.test(id): // if font_file and text_stroke style...
  5127. current_stroke_color = getEl('#text_stroke_color').value;
  5128. text_stroke_color = (getEl('#text_stroke_width').value < 0 ? 'white' : (current_stroke_color === '' || /white|black/.test(current_stroke_color)) && value > 0 ? 'black' : current_stroke_color)
  5129. prop = (id === 'text_stroke_width' ? 'stroke-width' : 'stroke');
  5130. getEls(fontElId).forEach(el => el.setAttribute(prop, value + units));
  5131. if (id === 'text_stroke_width') {
  5132. getEls(fontElId).forEach(el => el.setAttribute('stroke', text_stroke_color));
  5133. }
  5134. break; // set prop on font file svg paths
  5135. default:
  5136. switch (true) {
  5137. case (/^cv|^ss|salt|swsh|ornm|nalt/.test(value) || id === 'font_tag_textarea'):
  5138. prop = 'font-feature-settings';
  5139. value = '"' + value.slice(0, 4) + '" ' + value.slice(4);
  5140. getEl('#font_tag_textarea').focus();
  5141. break;
  5142. case props[id] !== undefined:
  5143. break;
  5144. case variant_value !== undefined:
  5145. value = variant_value;
  5146. break;
  5147. case value?.length < 4:
  5148. value = '';
  5149. break;
  5150. }
  5151. getEl(fontElId)?.style.setProperty(prop, value + units); // default: set style properties
  5152. }
  5153. }
  5154.  
  5155. function fontReset(id) {
  5156. let el_ids = ['font_tag_textarea', 'font_size', 'line_height', 'letter_spacing', 'text_color', 'text_stroke_width', 'text_stroke_color'],
  5157. current_font;
  5158. switch (true) {
  5159. case id === 'reset':
  5160. setValue('#font_variant_select', '');
  5161. el_ids.forEach(el_id => getEl('#' + el_id).value = null); // default toolbar values
  5162. switch (true) {
  5163. case hasContent('font_specimen'): // reset font_specimen
  5164. current_font = getEl('#font_specimen_viewer').style.fontFamily;
  5165. getEl('#font_specimen_viewer').removeAttribute('style');
  5166. getEl('#font_specimen_viewer').style.fontFamily = current_font;
  5167. break;
  5168. case hasContent('font_file'):
  5169. getEl('#font_file_grid').dataset.scale = 1; // reset font_file
  5170. getEls('#font_file_grid, #font_file_grid svg g').forEach(el => el.removeAttribute('style'));
  5171. getEls('#font_file_grid svg path').forEach(el => el.removeAttribute('stroke'));
  5172. break;
  5173. }
  5174. default:
  5175. if (id === 'font_size' && hasContent('font_file')) { // reset all font options...
  5176. getEl('#font_file_grid').removeAttribute('style');
  5177. getEl('#font_file_grid').querySelectorAll('svg g').forEach(function (el) {
  5178. el.style.transform = 'none'
  5179. });
  5180. getEl('#' + id).value = 1;
  5181. }
  5182. else {
  5183. fontOptions(null, id, null); // or reset individual font options by id
  5184. }
  5185. }
  5186. }
  5187. //============================// GRIDS
  5188. function showGrid(id) { // ===> SHOW GRID
  5189. if (id !== undefined) {
  5190. gridMake(id);
  5191. } // initial make grid items; otherwise, just unhide existing grid (see below)
  5192. let selected_ID = (getEl('.dirlist_item.selected')?.id || undefined);
  5193. addClass('#show_grid_btn', 'has_grid'); // add class to #show_grid_btn button
  5194. setAttribute('#content_pane', 'data-content', 'has_grid'); // set content_pane data-content attribute
  5195. removeClass('#content_pane', 'has_hidden_grid has_dir has_file');
  5196. removeClass('#content_pane div', 'selected hovered'); // remove classes from selected grid item; show hidden grid, remove content_pane classes
  5197. setContentTitle('', 'grid');
  5198. addClass('#content_pane div[data-id="' + selected_ID + '"]', 'selected'); // reselect selected grid item
  5199. focusEl('#content_grid'); // focus grid
  5200. }
  5201.  
  5202. function closeGrid(id) { // ===> CLOSE GRID
  5203. switch (true) {
  5204. case id === 'hide':
  5205. removeAttribute('#content_pane', 'data-content');
  5206. addClass('#content_pane', 'has_hidden_grid');
  5207. break; // hide grid, e.g., when viewing a grid item or other item
  5208. default:
  5209. switch (true) {
  5210. case hasContent('font'):
  5211. case hasContent('image'):
  5212. showGrid();
  5213. break;
  5214. default:
  5215. removeAttribute('#content_pane', 'data-content');
  5216. removeClass('#content_pane', 'has_image_grid has_font_grid'); // remove #content_pane classes & data-content attribute
  5217. removeAttribute('#content_grid', 'style');
  5218. getEl('#content_grid').innerHTML = ''; // remove #content_grid style & all grid els
  5219. removeClass('#show_grid_btn', 'has_grid'); // remove #show_grid_btn button class
  5220. focusEl('#top_body');
  5221. if (getEl('.dirlist_item.hovered') !== null) {
  5222. showThis(getEl('.dirlist_item.hovered').id);
  5223. removeClass('.dirlist_item.hovered', 'hovered');
  5224. }
  5225. else {
  5226. showThis(getVisibleElsBySelector('.dirlist_item')[0].id); // focus sidebar; show 1st sidebar item
  5227. }
  5228. break;
  5229. }
  5230. break;
  5231. }
  5232. }
  5233.  
  5234. function showContentGridItem(e, id, src, kind) {
  5235. e.preventDefault(); // ===> SHOW GRID ITEM
  5236. closeGrid('hide'); // hide grid
  5237. switch (true) {
  5238. case elExists('#' + id):
  5239. addRemoveClassSiblings('#' + id, 'selected', 'selected');
  5240. getEl('#' + id).click();
  5241. break; // normal grid item display
  5242. case !elExists('#' + id):
  5243. showThis('', false, true, [src, kind]);
  5244. break; // show grid items from closed subdirectory
  5245. }
  5246. }
  5247. // ***** IMAGE/FONT GRID SETUP
  5248. function gridMakeFontItems(id) { // ===> FONT GRID ITEMS
  5249. let font_grid_items = '',
  5250. font_files = (id !== undefined ? getEls('#' + id) : getEls('.dirlist_item.font')),
  5251. new_grid_item, font_items_length = font_files.length;
  5252. for (let i = 0; i < font_items_length; i++) { // for each font...
  5253. new_grid_item = showFont(font_files[i].id, true, 'font_grid', '', i, font_items_length); // make new font_grid_item
  5254. font_grid_items += new_grid_item; // add it to the font_grid_items
  5255. }
  5256. return font_grid_items; // return font_grid_items
  5257. }
  5258.  
  5259. function gridMakeImageItems(id) { // ===> IMAGE GRID ITEMS
  5260. let image_grid_items = '';
  5261. let image_files = (id !== undefined ? getEls('#' + id) : getEls('.dirlist_item.image:not(.ignored)'));
  5262. let image_files_length = image_files.length,
  5263. classes = 'grid_item image_grid_item flex_justify_center border_right_x border_bottom_x';
  5264. for (let i = 0; i < image_files_length; i++) {
  5265. const this_id = image_files[i].id;
  5266. const this_link = image_files[i].querySelector('a').href;
  5267. const exts = Item_Kinds.image.filter(ext => !Item_Settings.ignored.includes(ext)); // decide which image files can be displayed
  5268. const title_name = this_link.slice(this_link.lastIndexOf('/') + 1);
  5269. if (exts.includes(image_files[i].dataset.ext)) { // if item ext is in the image extension array...
  5270. let item = `<li class="${ classes } background_grey_90" data-ID="${ this_id }" data-index="${ i }" data-kind="image"><a href="${ this_link }"><img src="${ this_link }" title="${ title_name }" loading="lazy" /></a></li>`; // make new image_grid_item
  5271. image_grid_items += item; // ...add it to the image_grid_items
  5272. }
  5273. }
  5274. return image_grid_items; // return image_grid_items
  5275. }
  5276.  
  5277. function gridMake(id) {
  5278. let el, kind; // ===> MAKE GRIDS
  5279. if (/rowid/.test(id)) {
  5280. el = getEl('#' + id);
  5281. kind = el.dataset.kind;
  5282. }
  5283. else {
  5284. getEl('#content_grid').innerHTML = '';
  5285. } // remove previous grid items or make single grid item
  5286. removeClass('#content_pane', 'has_hidden_grid has_image_grid has_font_grid'); // reset content_pane grid classes
  5287. switch (true) { // determine which grid type to make
  5288. case el !== undefined:
  5289. switch (kind) { // make single grid items on cmd-click
  5290. case 'font':
  5291. getEl('#content_grid').insertAdjacentHTML('beforeend', gridMakeFontItems(id));
  5292. break; // make single font grid item
  5293. case 'image':
  5294. getEl('#content_grid').insertAdjacentHTML('beforeend', gridMakeImageItems(id));
  5295. break; // make single image grid item
  5296. }
  5297. break;
  5298. case id === 'show_font_grid':
  5299. addClass('#content_pane', 'has_font_grid');
  5300. getEl('#content_grid').innerHTML = gridMakeFontItems();
  5301. break; // make font grid
  5302. case id === 'show_image_grid':
  5303. addClass('#content_pane', 'has_image_grid');
  5304. getEl('#content_grid').innerHTML = gridMakeImageItems();
  5305. break; // make image grid
  5306. default:
  5307. getEl('#content_grid').innerHTML = gridMakeImageItems() + gridMakeFontItems(); // make image and font grid
  5308. }
  5309. initGridItemEvents(); // register event watchers for added grid elements
  5310. }
  5311. // ***** IMAGE/FONT/GLYPH SCALE
  5312. function scaleItems(e, incr, id, kind) {
  5313. addClass('#reload_btn', 'reset'); // add reset class to reload button
  5314. switch (kind) {
  5315. case 'has_grid':
  5316. scaleFonts(e, incr, id);
  5317. scaleImages(e, incr, id);
  5318. break; // scale grids
  5319. case 'has_font':
  5320. scaleFonts(e, incr, id);
  5321. break; // scale glyphs
  5322. case 'has_image':
  5323. scaleImages(e, incr, id);
  5324. break; // scale glyphs or images and fonts
  5325. }
  5326. }
  5327.  
  5328. function scaleFonts(e, scale, id) {
  5329. scale = (scale <= 0 ? (1, getEl('#font_size').value = 1) : scale);
  5330. let incr = Number(scale).toFixed(4);
  5331. if (id === 'decrease') {
  5332. incr = 1 / incr;
  5333. scale = 1 / scale
  5334. } // ===> SCALE FONTS: +/- buttons or slider
  5335. let content_grid = getEl('#content_grid'),
  5336. font_specimen_viewer = getEl('#font_specimen_viewer'),
  5337. font_file_glyph, font_file_grid = getEl('#font_file_grid'),
  5338. value, font_input_value, data_scale, transform_scale, translateY, el_id;
  5339. let font_size = parseInt(getComputedStyle(document.body).fontSize).toFixed(4),
  5340. fontGetSize = function (el) {
  5341. return Number.parseFloat(window.getComputedStyle(el).fontSize).toFixed(4);
  5342. };
  5343. switch (true) {
  5344. case hasContent('grid'):
  5345. setStyle('#content_grid', 'font-size', (fontGetSize(content_grid) / font_size * incr) + 'em');
  5346. break; // scale grid font items
  5347. // font files
  5348. case hasContent('font_file_glyph'):
  5349. font_file_glyph = getEl('#font_file_glyph_viewer g'); // scale font file glyph
  5350. data_scale = font_file_glyph.style.transform;
  5351. data_scale = Number(data_scale.match(/[\.\d]+/g));
  5352. if (data_scale === 0) {
  5353. data_scale = 1;
  5354. } // define data_scale...
  5355. switch (true) {
  5356. case scale === null:
  5357. data_scale = 1;
  5358. font_input_value = 1;
  5359. break;
  5360. case (/increase|decrease/.test(id)):
  5361. data_scale = incr * data_scale;
  5362. font_input_value = Math.pow(data_scale, 0.2);
  5363. break; // ...for +/- buttons; set #font-size value
  5364. default:
  5365. data_scale = (data_scale >= 1 ? Math.pow(incr, 5) : Math.pow(incr, 1.25)); // ...for #font_size slider
  5366. }
  5367. font_file_glyph.style.transform = 'scale(' + data_scale + ')';
  5368. break; // scale glyph
  5369. case hasContent('font_file'):
  5370. if (/increase|decrease/.test(id)) {
  5371. scale = (font_file_grid.dataset.scale === undefined ? scale : Number(font_file_grid.dataset.scale) <= 0 ? 1 : Number(font_file_grid.dataset.scale) + Number(scale) - 1); // scale
  5372. scale = Number(scale) * Number(incr);
  5373. font_input_value = scale; // set slider value
  5374. }
  5375. transform_scale = (scale >= 1 ? Math.pow(scale, 4) : Math.pow(scale, 1.125));
  5376. translateY = (Number(scale) < 0.5 ? 0.5 : Number(scale) < 1.5 ? (1 - scale) : -0.5); // transform_scale & translateY
  5377. font_file_grid.querySelectorAll('svg g').forEach(function (el) {
  5378. el.style.transform = 'scale(' + transform_scale + ') translateY(' + translateY + 'em)';
  5379. }); // set transform scale & translateY
  5380. if (scale > 0.33) {
  5381. font_file_grid.style.gridTemplateColumns = 'repeat(auto-fit, minmax(max(52px,' + Math.pow(scale, 3) * 1.33 + 'em ), 1.5fr))'; // scale font file grid cols
  5382. font_file_grid.style.gridAutoRows = 'minmax(max(52px,' + Math.pow(scale, 3.33) * 1.33 + 'em), max-content)'; // scale font file grid rows
  5383. }
  5384. font_file_grid.dataset.scale = scale;
  5385. break;
  5386. // font specimens
  5387. case hasContent('font_specimen_glyph'):
  5388. el_id = '#font_specimen_glyph'; // scale font specimen glyph (in vw)
  5389. switch (id) {
  5390. case 'font_size': // from font_size input slider
  5391. if (incr === null) {
  5392. value = 64;
  5393. }
  5394. else {
  5395. value = 64 * Math.pow(incr, 3)
  5396. } // max value of incr = 64 * 2^3 = 512 // reset if scale is 0
  5397. setStyle(el_id, 'font-size', value + 'vw');
  5398. getEl(el_id).dataset.scale = Number(value / 64).toFixed(4);
  5399. break;
  5400. default: // from increase/decrease buttons
  5401. getEl(el_id).dataset.scale = Number(getEl(el_id).dataset.scale) * incr;
  5402. data_scale = Number(getEl(el_id).dataset.scale); // update data-scale; define data_scale
  5403. value = (64 * data_scale) + 'vw';
  5404. setStyle(el_id, 'font-size', value);
  5405. font_input_value = Math.pow(data_scale, 0.3333); // set the font-size using data-scale
  5406. }
  5407. break;
  5408. case hasContent('font_specimen'):
  5409. el_id = '#font_specimen_viewer';
  5410. switch (id) { // scale font specimen
  5411. case 'font_size': // from font_size input slider
  5412. if (Number(incr) === Number(0.0000)) {
  5413. incr = 1;
  5414. getEl('#' + id).value = 1;
  5415. } // reset font size
  5416. setStyle(el_id, 'font-size', (Math.pow(incr, 4) + 'em'));
  5417. getEl(el_id).dataset.scale = Number(incr).toFixed(4);
  5418. break; // set the font size
  5419. default: // from increase/decrease buttons
  5420. if (Number(fontGetSize(font_specimen_viewer)) === 0) {
  5421. incr = 1;
  5422. }
  5423. else {
  5424. incr = Number(fontGetSize(font_specimen_viewer) / font_size * incr);
  5425. } // reset if scale is 0
  5426. getEl(el_id).dataset.scale = incr.toFixed(4);
  5427. setStyle(el_id, 'font-size', incr.toFixed(4) + 'em');
  5428. font_input_value = Math.pow(incr, 0.25);
  5429. }
  5430. break;
  5431. }
  5432. if ((id === 'font_size' && scale === null) || id !== 'font_size') {
  5433. getEl('#font_size').value = font_input_value
  5434. } // set #font_size input value
  5435. scrollThis('#content_container', '#content_font'); // scroll content_font
  5436. }
  5437.  
  5438. function scaleImages(e, incr, id) { // ===> ZOOM IMAGES ON CLICK
  5439. let content_el = (elExists('#content_body') && elExists('#content_body > img') ? getEl('#content_body') : getEl('#content_container'));
  5440. let this_img = (elExists('#content_body > img') ? getEl('#content_body > img') : getEl('#content_image')); // define this_img
  5441. let CC_width = Math.round(content_el.offsetWidth),
  5442. CC_height = Math.round(content_el.offsetHeight); // content_container dimensions
  5443. let img_width = Math.round(this_img.offsetWidth),
  5444. img_height = Math.round(this_img.offsetHeight); // this_img dimensions
  5445. let CC_offset, img_offset, percentX, percentY, scrollX, scrollY;
  5446. const iframe_delta = (getEls('#content_body > img').length === 1 ? Number.parseInt(getEl('#content_body').style.padding) : 0);
  5447. switch (true) {
  5448. case hasContent('grid'):
  5449. scaleImageGrid(incr, id);
  5450. break; // scale grid images
  5451. default: // scale single images
  5452. imageGetDimensions(this_img.src, (width, height) => {
  5453. switch (true) {
  5454. case incr !== undefined && id !== undefined: // scale images by increment
  5455. addClass('#content_pane', 'has_scaled_image');
  5456. removeClass('#content_pane', 'has_zoom_image'); // remove zoom classes in case window resized after zoom
  5457. switch (true) {
  5458. case id === 'increase':
  5459. this_img.style.cssText = `width:${img_width * incr}px; height:auto; max-width:none; max-height:none;`;
  5460. break;
  5461. case id === 'decrease' && (img_width >= 1 && img_height >= 1):
  5462. this_img.style.cssText = `width:${img_width / incr}px; height:auto; max-width:none; max-height:none;`;
  5463. break;
  5464. }
  5465. if (Math.round(this_img.offsetWidth) >= CC_width) {
  5466. getEl('#content_image_container').scrollLeft = (Math.round(this_img.offsetWidth) - CC_width) / 2;
  5467. } // keep scaled img centered
  5468. switch (true) { // keep scaled img centered
  5469. case Math.round(this_img.offsetHeight) <= CC_height:
  5470. getEl('#content_image_container').scrollTop = (CC_height - Math.round(this_img.offsetHeight)) / 2;
  5471. break;
  5472. default:
  5473. getEl('#content_image_container').scrollTop = (Math.round(this_img.offsetHeight) - CC_height) / 2;
  5474. break;
  5475. }
  5476. break;
  5477. default: // else zoom single image on click
  5478. if (width <= CC_width && height <= CC_height) { // click to toggle small images between 100% and full size
  5479. if (/100%/.test(this_img.getAttribute('style'))) {
  5480. this_img.removeAttribute('style');
  5481. }
  5482. else {
  5483. this_img.style.width = '100%';
  5484. }
  5485. removeClass('#content_pane', 'has_zoom_image has_scaled_image');
  5486. return; // no need to set scroll position
  5487. }
  5488. CC_offset = content_el.getBoundingClientRect();
  5489. img_offset = this_img.getBoundingClientRect(); // get offsets
  5490. percentX = Number((e.pageX - img_offset.left) / img_width).toFixed(2);
  5491. percentY = Number((e.pageY - img_offset.top) / img_height).toFixed(2) // x,y coordinates of zoom click as % of image width/height
  5492. scrollX = (width * percentX) - e.pageX + CC_offset.left - (iframe_delta * width / img_width); // calculate clicked x-coordinates for full-size image
  5493. scrollY = (height * percentY) - e.pageY + CC_offset.top - (iframe_delta * height / img_height); // calculate clicked y-coordinate for full-size image
  5494. removeClass('#content_pane', 'has_scaled_image'); // in case image scaled already
  5495. getEl('#content_pane').classList.toggle('has_zoom_image');
  5496. getEl('#content_image_container').scrollTo(scrollX, scrollY); // scroll to clicked position
  5497. }
  5498. });
  5499. imageSetDimensions();
  5500. focusEl('#content_image_container'); // set image dimensions
  5501. }
  5502. }
  5503.  
  5504. function scaleImageGrid(incr, id) { // ===> SCALE IMAGE GRID ITEMS
  5505. if (id === 'decrease') {
  5506. incr = 1 / incr;
  5507. }
  5508. let grid_container = getEl('#content_grid'),
  5509. grid_items = getEls('.image_grid_item img');
  5510. if (!grid_items?.length) {
  5511. return;
  5512. }
  5513. let grid_item_width = Number.parseFloat(grid_items[0].offsetWidth, 10) * incr;
  5514. let grid_item_height = Number.parseFloat(grid_items[0].offsetHeight, 10) * incr;
  5515. let grid_item_max_width = Number.parseFloat(grid_items[0].style.maxWidth, 10) * incr;
  5516. let grid_item_max_height = Number.parseFloat(grid_items[0].style.maxHeight, 10) * incr;
  5517. if (grid_item_width < grid_item_max_width) {
  5518. grid_item_width = grid_item_max_width;
  5519. } // don't reduce grid image size on first scale click
  5520. if (grid_item_height < grid_item_max_height) {
  5521. grid_item_height = grid_item_max_height;
  5522. } // don't reduce grid image size on first scale click
  5523. grid_container.style.gridTemplateColumns = 'repeat(auto-fill, minmax(' + (grid_item_width + 16) + 'px, auto ) )'; // set grid properties
  5524. grid_items.forEach((el) => {
  5525. el.style.maxWidth = grid_item_width + 'px';
  5526. el.style.maxHeight = grid_item_height + 'px';
  5527. }); // set grid properties
  5528. return;
  5529. }
  5530.  
  5531. function imageGetDimensions(link, callback) {
  5532. if (link !== undefined) {
  5533. let img = new Image();
  5534. img.src = link;
  5535. img.onload = function () {
  5536. callback(this.width, this.height);
  5537. };
  5538. img = null;
  5539. }
  5540. } // GET IMG DIMENSIONS
  5541. function imageSetDimensions() {
  5542. if (!isTopWindow()) {
  5543. return;
  5544. } // ===> SET IMAGE DIMENSIONS; // ignore iframe image
  5545. switch (true) {
  5546. case hasContent('image'):
  5547. imageGetDimensions(getAttribute('#content_image', 'src'), function (width, height) { // imageGetDimensions()
  5548. let percentage = ((getEl('#content_image').width / width) * 100).toFixed(1); // define percentage
  5549. setAttribute('#content_title span', 'data-after', ' (' + width + 'px × ' + height + 'px) (' + percentage + '%)'); // set dataset.after for content_title
  5550. });
  5551. break;
  5552. default:
  5553. removeAttribute('#content_title span', 'data-after'); // remove image dimensions
  5554. }
  5555. }
  5556. //============================// SHOW TEXT EDITOR
  5557. function showTextEditor(bool) { // ===> SHOW TEXT EDITOR; bool === false => hide editor
  5558. switch (true) {
  5559. case bool === false:
  5560. case hasClass('body', 'has_texteditor'):
  5561. removeClass('body', 'has_texteditor');
  5562. focusEl('#top_body');
  5563. break;
  5564. case !hasClass('body', 'has_texteditorUI'):
  5565. buildTextEditorUI(); // no break; add the text editor UI if needed
  5566. default:
  5567. addClass('body', 'has_texteditor');
  5568. getEl('#texteditor_txt_pane').focus(); // show editor: add texteditor class, focus texteditor
  5569. }
  5570. }
  5571.  
  5572. function tempHideTexteditor() {
  5573. getEl('head').insertAdjacentHTML('beforeend', '<style id="temp_styles">#text_container{ display:none;}</style>');
  5574. } // ...hide editor UI for link files until formatted_link received from top
  5575. // to prevent FOUC for some kinds of content...
  5576. function showTexteditorPreview(content) { // ===> SHOW TEXTEDITOR PREVIEW
  5577. removeClass('#content_body', 'texteditor_view_raw texteditor_view_html'); // remove classes
  5578. addClass('#content_body', 'is_link texteditor_split_view_false texteditor_view_preview text_editing_enable_false'); // add classes to prevent editing without changing UI_Pref
  5579. getEl('#texteditor_preview_pane').innerHTML = content; // insert processed text from top
  5580. getEl('#temp_styles').remove(); // show texteditor after hiding it until processed content received
  5581. }
  5582. //============================// PDF
  5583. function showPDF() { // ===> SET UP CONTENT_PDF
  5584. let pdf_container = `<embed id="content_pdf" class="content_el position_relative border_0" tabindex="0" data-kind="pdf">`; // replace content_pdf for each pdf
  5585. getEl('#content_pdf').remove(); // remove existing content_pdf el
  5586. getEl('#content_image_container').insertAdjacentHTML('afterend', pdf_container); // add new content_pdf el
  5587. }
  5588. //============================// LINK FILES
  5589. function openLinkFile(e, id) {
  5590. eStopPrevent(e); // ===> OPEN LINK FILES: on cmd-arrowdown or dblclick (webloc, url)
  5591. let link = getEl('#' + id).dataset.link; // get the link
  5592. switch (true) {
  5593. case link === undefined:
  5594. break;
  5595. case !hasClass('#' + id, 'non_local'):
  5596. if (!isTopWindow()) {
  5597. window.location = link;
  5598. }
  5599. else {
  5600. showThis('open_link_file', false, true, [link, 'link']);
  5601. }
  5602. break;
  5603. default:
  5604. window.open(link); // else open link file links in new window
  5605. }
  5606. }
  5607.  
  5608. function linkFileProcess() { // ===> LINK FILE PROCESS: on "iframe_loaded" message received
  5609. let link_item = getEl('.dirlist_item.selected.link'),
  5610. link_content = link_item?.dataset.html_content || '',
  5611. regex = /URL\=(.+?)$|<key>URL<\/key>\s*<string\>(.+?)<\/string\>/im;
  5612. let link = (link_content.match(regex)?.[1] || link_content.match(regex)?.[2]),
  5613. link_class = '',
  5614. link_target = '',
  5615. formatted_link; // get the link; define link elements
  5616. if (window_protocol === 'file:' && !link.startsWith('file')) {
  5617. getEl('.dirlist_item.selected').classList.add('non_local');
  5618. link_class = ' class="non_local"';
  5619. link_target = ' target="_blank"';
  5620. }
  5621. if (window_protocol !== 'file:' && link.startsWith('file')) {
  5622. getEl('.dirlist_item.selected').classList.add('local');
  5623. link_class = ' class="local"';
  5624. }
  5625. formatted_link = '<a id="link_file_01" href="' + link + '"' + link_class + link_target + '>' + link + '</a>'; // assemble formatted link
  5626. link_item.dataset.link = link; // set data-link on sidebar item
  5627. link_item.dataset.html_content = null; // remove data-html_content
  5628. messageSend('iframe', 'show_texteditor_preview', '', formatted_link); // send formatted link to iframe for display
  5629. }
  5630. //============================// DIRECTORY SOURCE
  5631. function showDirectorySource(link) { // ===> SHOW DIRECTORY SOURCE
  5632. switch (true) {
  5633. case hasClass('body', 'has_directory_source'):
  5634. removeClass('body', 'has_directory_source');
  5635. showThis(getEl('.dirlist_item.non_media.selected').id);
  5636. break; // close if open
  5637. default:
  5638. addClass('body', 'has_directory_source');
  5639. showThis('show_directory_source', false, true, [(link || window_location)]);
  5640. setAttribute('#content_pane', 'data-loaded', 'loaded'); // else show directory source
  5641. }
  5642. }
  5643.  
  5644. function openSidebarInContentPane() {
  5645. showThis('open_sidebar_in_content_pane', false, true, [window_location, 'dir']);
  5646. addClass('#top_body', 'open_sidebar_in_content_pane');
  5647. } // ===> OPEN SIDEBAR IN CONTENT PANE
  5648. function openInTextEditor() { // ===> OPEN IN TEXT EDITOR
  5649. let html = getEl('.dirlist_item.htm.content_loaded').dataset.html_content;
  5650. showTextEditor(true);
  5651. if (html !== undefined) {
  5652. getEl('#texteditor_txt_pane').value = html;
  5653. getEl('#texteditor_preview_pane').value = html;
  5654. getEl('#texteditor_html_pane').value = html;
  5655. } // set previewed text
  5656. getEl('#open_in_texteditor')?.blur();
  5657. }
  5658. // END SHOW INDIVIDUAL CONTENT TYPES
  5659. //============================// AUTOLOAD CONTENT
  5660. function autoLoadItems() { // ===> AUTOLOAD FILE: index files or files from the file shortcut list
  5661. let selected_el = getEl('.dirlist_item.dir[id="rowid-' + Number(getCurrentUIPref("selected")) + '"]');
  5662. switch (true) {
  5663. case (selected_el !== null && isTopWindow() && getSearchParams().has('selected')):
  5664. showThis(selected_el.id);
  5665. break; // select from searchParam; prevents being overridden by autoload media
  5666. case (getCurrentUIPref('autoload_index_files') !== 'false' && elExists('.dirlist_item.file.htm a[href*="/index."]')): // load index file
  5667. showThis(getEl('.dirlist_item.file.htm a[href*="/index."]').closest('.dirlist_item').id);
  5668. break;
  5669. case selected_el !== null && selected_el.classList.contains('local'):
  5670. case !isTopWindow():
  5671. break; // do nothing for local files or iframes
  5672. case getSearchParams().has('file'): { // load files (from bookmark or url)
  5673. let file_name = decodeURIComponentSafe(getCurrentUIPref('file'));
  5674. let file = Array.from(getEls('.dirlist_item.file')).filter(el => el.dataset.name === file_name);
  5675. if (file[0] !== undefined) {
  5676. showThis(file[0].id);
  5677. }
  5678. searchParamDelete('file');
  5679. }
  5680. break;
  5681. case hasClass('body', 'has_video'):
  5682. getEl('video').volume = '0.5'; // video; set video volume
  5683. if (getCurrentUIPref('media_autoload') === 'true' && !hasClass('body', 'has_audio')) {
  5684. showThis(getEl('.dirlist_item.video')?.id);
  5685. break;
  5686. } // load video only if no audio
  5687. case hasClass('body', 'has_audio'):
  5688. getEl('audio').volume = '0.5'; // audio; set audio volume
  5689. if (getCurrentUIPref('media_autoload') === 'true') {
  5690. showThis(getEl('.dirlist_item.audio')?.id);
  5691. }
  5692. break; // load audio
  5693. case selected_el !== null:
  5694. showThis(selected_el.id, false, true);
  5695. break;
  5696. }
  5697. if (getEl('.content_el.has_content') === null) {
  5698. getEl('#content_pane').dataset.content = 'has_null';
  5699. }
  5700. if (selected_el !== null) {
  5701. scrollThis('#directory_list', '.selected');
  5702. }
  5703. }
  5704.  
  5705. function getImageNames(id) { // ===> GET IMAGE NAMES (for cover art)
  5706. let images = getEls('.dirlist_item.image'),
  5707. image_names = [],
  5708. image_name, subdir_prefix;
  5709. if (id.includes('_')) {
  5710. subdir_prefix = RegExp("^" + id.slice(0, id.lastIndexOf('_') + 1), 'm');
  5711. images = Array.from(images).filter(image => subdir_prefix.test(image.id)); // filter images by subdir of selected item
  5712. }
  5713. for (let image of images) {
  5714. if (image.id.split('_').length === id.split('_').length) { // if audio and found image in same dir level...
  5715. image_name = image.dataset.name;
  5716. image_name = image_name.slice(0, image_name.lastIndexOf('.'));
  5717. image_names.push({
  5718. 'id': image.id,
  5719. 'name': image_name
  5720. }); // get image name w/o extension, add to image_names
  5721. }
  5722. }
  5723. return image_names;
  5724. }
  5725.  
  5726. function getCoverArtID(id) { // ===> GET COVER ART ID
  5727. let cover_art_id, match, exact_match, cover_names = ['cover', 'front', 'album', 'jacket', 'sleeve', 'cd', 'disc', 'insert', 'liner', 'notes'];
  5728. let selected_audio_name = (getEl('.file.audio.selected')?.dataset.name || undefined); // is there an image file with the same name?
  5729. if (selected_audio_name !== undefined) {
  5730. selected_audio_name = selected_audio_name.slice(0, selected_audio_name.lastIndexOf('.'));
  5731. cover_names.unshift(selected_audio_name);
  5732. } // prep the name & add to cover names
  5733. const image_names = getImageNames(id); // get names of all image files
  5734. if (image_names?.length === 0) {
  5735. closeContent('image');
  5736. return;
  5737. } // close existing image if no cover art found
  5738. for (let cover_name of cover_names) { // test available image names against cover names
  5739. exact_match = image_names.filter(el => el.name === cover_name);
  5740. match = image_names.filter(el => el.name.indexOf(cover_name) > -1); // check for exact and partial matches
  5741. switch (true) {
  5742. case exact_match.length > 0:
  5743. return cover_art_id = exact_match[0].id; // if exact match, return
  5744. case match.length > 0:
  5745. return cover_art_id = match[0].id; // else return first match
  5746. }
  5747. }
  5748. if (cover_art_id === undefined) {
  5749. return cover_art_id = image_names[0].id;
  5750. } // if no matches, return first image id
  5751. }
  5752.  
  5753. function autoLoadCoverArt(bool, id) { // ===> AUTOLOAD COVER ART if dir contains audio & images
  5754. if (bool === false || !isTopWindow() || !hasClass('body', 'has_images') || !hasClass('body', 'has_audio')) {
  5755. getEl('#content_pane').dataset.content = 'has_null';
  5756. return;
  5757. } // do nothing if no audio or images
  5758. let cover_ID = getCoverArtID(id),
  5759. selected_ID = (getCurrentUIPref('selected').length > 0 ? 'rowid-' + getCurrentUIPref('selected') : undefined);
  5760. if (selected_ID !== undefined && typeof selected_ID === 'number') {
  5761. removeClass('.dirlist_item.media', 'selected');
  5762. addClass('#' + selected_ID, 'selected');
  5763. }
  5764. if (cover_ID !== undefined) {
  5765. showThis(cover_ID, false, true, [getEl('#' + cover_ID).querySelector('a').href, 'autoloadcoverart']);
  5766. } // close other content, show cover art, reset .selected class
  5767. }
  5768. //============================//
  5769. // ***** MAIN SHOW CONTENT FUNCTIONS ***** //
  5770. //============================//
  5771. // LINKS, SEARCH PARAMS, AND QUERIES
  5772. function makeSrcSearchParams(kind) { // ===> GET LINK QUERIES
  5773. let query_str = '',
  5774. params;
  5775. const makeSearchParams = (params, query_str) => {
  5776. query_str = new URLSearchParams();
  5777. for (let param of params) {
  5778. query_str.append(param, getCurrentUIPref(param));
  5779. }
  5780. return query_str;
  5781. } // ===> MAKE SEARCH PARAMS
  5782. switch (true) {
  5783. case (/audio|font|image|video|htm/.test(kind)):
  5784. break; // no query_str for audio, fonts, images, video, or htm
  5785. case kind === 'show_directory_source':
  5786. query_str = '?&show_directory_source=true';
  5787. break; // view directory source
  5788. case kind === 'pdf':
  5789. query_str = '#view=fitB&scrollbar=1&toolbar=1&navpanes=1';
  5790. break; // query_str for pdfs
  5791. case (/text|markdown|code|other|link/.test(kind)): // editable text files (including dot and plaintext files ["other"])
  5792. params = ['theme', 'text_editing_enable', 'texteditor_view', 'texteditor_split_view', 'texteditor_sync_scroll']; // define array of required params for text editing
  5793. query_str = '?' + makeSearchParams(params).toString();
  5794. break; // compose query_str for text files
  5795. case (/app|dir/.test(kind)):
  5796. params = ['sort_by', 'sort_direction', 'show_details', 'show_image_thumbnails', 'show_image_thumbnails_always', 'show_large_image_thumbnails', 'show_numbers', 'use_custom_icons', 'show_invisibles', 'show_ignored_items', 'ignore_ignored_items', 'alternate_background', 'theme', 'media_play_all'];
  5797. if (getSearchParams().has('ui_font')) {
  5798. params.push('ui_font');
  5799. }
  5800. query_str = '?' + makeSearchParams(params).toString();
  5801. break; // define array of params for dirs; compose query_str for dirs
  5802. }
  5803. return query_str; // return query_str
  5804. }
  5805. //============================// DIRS & SUBDIRS
  5806. function dirOpen(args) { // args: [dir.selected.id,dir.selected a.href] // ===> OPEN DIR (dirs only): update selected and history searchParam in querystring
  5807. const updateHistory = function (id) {
  5808. let id_arr = id.split('_');
  5809. id_arr = id_arr.map(el => el.split('-')[1]);
  5810. return id_arr.reverse().join('+');
  5811. } // get numerical part(s) of selected dir/subdir id
  5812. let item = document.getElementById(args[0]),
  5813. history = updateHistory(args[0]),
  5814. searchParams = getSearchParams(); // get selected item, history, and searchParams object
  5815. if (item.classList.contains('dir') && item.classList.contains('invisible') && item.classList.contains('ignored')) {
  5816. return;
  5817. } // don't attempt to open ignored invisible dirs (chiefly system dirs)
  5818. searchParams.delete('selected'); // delete 'selected' searchParam
  5819. history = (searchParams.has('history') ? history + '+' + searchParams.get('history') : history);
  5820. searchParams.set('history', history); // configure and set 'history' searchParam
  5821. window.location = args[1] + '?' + searchParams.toString().replace(/%2B/g, '+'); // set the window location, replacing encoded + sign.
  5822. }
  5823.  
  5824. function subDirOpen(parent_id) { // ===> OPEN SUDIRECTORY
  5825. let parent_el = document.getElementById(parent_id),
  5826. parent_link = parent_el.querySelector('a').href,
  5827. level = Number(parent_el.dataset.level) + 1,
  5828. body_id = document.body.id; // define subdir level
  5829. let content_iframe_utility_src = parent_link + makeSrcSearchParams('dir') + '&parent_id=' + parent_id + '&subdirectory=true&level=' + level + '&body_id=' + body_id; // assemble src link for utility_iframe
  5830. setAttribute('#content_iframe_utility', 'src', content_iframe_utility_src); // set src for utility_iframe (which processes dir & sends it back to top)
  5831. parent_el.classList.add('dirlist_subdir_loading'); // removed when iframe_utility sends loaded message with subdir data
  5832. }
  5833.  
  5834. function subDirClose(subdir_id) { // ===> CLOSE SUBDIRECTOY
  5835. if (!elExists('.dirlist_item.has_subdirectory')) {
  5836. return;
  5837. }
  5838. let classes = [{
  5839. font: 'has_fonts'
  5840. }, {
  5841. image: 'has_images'
  5842. }, {
  5843. media: 'has_media'
  5844. }]; // if no items with these classes found, remove the body class
  5845. removeClass('#' + subdir_id, 'has_subdirectory');
  5846. getEls('.dirlist_item').forEach((el) => {
  5847. if (el.id.startsWith(subdir_id + '_')) {
  5848. el.remove();
  5849. }
  5850. }); // remove all items whose id begins with subdirectory parent id
  5851. classes.forEach((item) => {
  5852. let key = Object.keys(item).toString();
  5853. if (!elExists('#directory_list li.' + key)) {
  5854. removeClass('body', item[key].toString())
  5855. }
  5856. });
  5857. if (!elExists('.dirlist_item.selected')) {
  5858. getEl('#' + subdir_id).classList.add('selected');
  5859. } // select closed dir if no other selected item exists
  5860. updateStats(false);
  5861. }
  5862.  
  5863. function subDirOpenClose(e, id) {
  5864. if (e !== null) {
  5865. eStopPrevent(e);
  5866. e.stopImmediatePropagation();
  5867. } // ===> OPEN CLOSE SUBDIRECTORY; e === null when opening multiple subdirs
  5868. let parent_el = getEl('#' + id);
  5869. removeClass('body', 'has_menu_stats');
  5870. switch (true) {
  5871. case (parent_el.querySelector('.name') !== null && /\.trashes|\.temporaryitems|\.spotlight-v\d+/.test(parent_el.querySelector('.name').dataset.name)):
  5872. parent_el.classList.remove('dirlist_subdir_loading');
  5873. break;
  5874. default:
  5875. if (parent_el.classList.contains('has_subdirectory')) {
  5876. subDirClose(id);
  5877. }
  5878. else {
  5879. subDirOpen(id);
  5880. } // if ( e !== null ) { showThis(id,true,false); } // select parent dir // open/close the subdir
  5881. }
  5882. }
  5883.  
  5884. function subDirInsert(args) { // args = [items,classes,parent_id]; message received: add the subdirectory to the dir_list, update stats, check for additional selected dirs
  5885. let parent_item, source_el;
  5886. if (!elExists('.dirlist_item.dirlist_subdir_loading')) {
  5887. return;
  5888. }
  5889. else {
  5890. parent_item = document.getElementById(args[2]);
  5891. } // select loading dir by id (args[2])
  5892. parent_item.classList.remove('dirlist_subdir_loading');
  5893. parent_item.classList.add('has_subdirectory'); // remove "loading" class, add "has_subdirectory" class
  5894. parent_item.insertAdjacentHTML('afterend', args[0]); // insert subdir items
  5895. if (getCurrentUIPref('show_image_thumbnails') === 'true') {
  5896. uiPrefImgThumbsToggle('true');
  5897. }
  5898. updateStats(true); // update stats
  5899. ['has_fonts', 'has_images', 'has_media', 'has_audio'].forEach((subdir_class) => {
  5900. if (args[1].split(' ').includes(subdir_class)) {
  5901. addClass('body', subdir_class)
  5902. }
  5903. }); // add new body classes
  5904. initDirListEvents();
  5905. initIframeEvents(); // init dir_list event listeners
  5906. if (elExists('.dir.selected:not(.has_subdirectory)') && parent_item.classList.contains('selected')) { // open multiple selected subdirs, but don't open selected if current item is not selected
  5907. subDirOpenClose(null, getEl('.dir.selected:not(.has_subdirectory)').id); // i.e., allow unselected dirs to be opened by icon click without also opening selected dirs
  5908. }
  5909. if (isTopWindow()) { // reselect current content (audio or content_pane) if it was originally in newly-reopened subdirectory:
  5910. if (/media/.test(args[1])) { // autoload media from new subdirs, if no media or other content currently loaded
  5911. if (!hasContent()) {
  5912. showThis(getEl('.dirlist_item.media[id^="' + parent_item.id + '"]').id);
  5913. }
  5914. }
  5915. if (!hasContent('null')) {
  5916. source_el = getEl('#' + getEl('#content_pane').dataset.loaded_id); // get content_el by content_source
  5917. if (source_el !== null) {
  5918. removeClass('.dirlist_item.non_media.selected,.dirlist_item.non_media.content_loaded', 'selected content_loaded');
  5919. source_el.classList.add('selected', 'content_loaded');
  5920. }
  5921. }
  5922. }
  5923. }
  5924. //============================//
  5925. // FOCUS ELS
  5926. function focusEl(sel, e) { // ===> FOCUS CONTENT
  5927. let content_pane_data = getContentPaneData(),
  5928. content_el_id = ('content' + content_pane_data?.slice(3) || ''),
  5929. bool = false,
  5930. incr = 1;
  5931. sel = (sel === null || sel === undefined ? '#top_body' : !sel.startsWith('#') ? '#' + sel : sel); // enforce correct sel format
  5932. menuClose();
  5933. document.activeElement.blur(); // close menus, blur active element
  5934. switch (true) {
  5935. case sel === '#top_body':
  5936. case sel === undefined: // focus sidebar
  5937. switch (true) {
  5938. case isTopWindow():
  5939. removeClass('body', 'focus_content');
  5940. getEl(sel).focus();
  5941. scrollThis('#directory_list', '.selected');
  5942. break;
  5943. case !isTopWindow():
  5944. messageSend('top_body', 'focus_top');
  5945. break;
  5946. }
  5947. break;
  5948. case sel === '#content_iframe':
  5949. switch (true) {
  5950. case isTopWindow():
  5951. addClass('body', 'focus_content');
  5952. getEl('#content_iframe').focus();
  5953. if (e !== undefined && e.key === 'Tab') {
  5954. if (e.shiftKey) {
  5955. bool = true;
  5956. incr = -1;
  5957. }
  5958. switch (true) {
  5959. case hasContent('dir'):
  5960. messageSend('iframe', 'iframe_navigation', '', [e.key, bool]);
  5961. break;
  5962. case hasContent('code,htm,markdown,text,other,link'):
  5963. messageSend('iframe', 'navigateTabKeyFocus', null, ['texteditor', incr]);
  5964. break;
  5965. }
  5966. }
  5967. break;
  5968. case !isTopWindow():
  5969. quickLookThis('close');
  5970. messageSend('top_body', 'focus_iframe');
  5971. break;
  5972. }
  5973. break;
  5974. case sel === '#content_pane':
  5975. break; // <-- test and clean this focusEl\('#content_pane
  5976. case sel !== '#top_body': // All other sel
  5977. addClass('#top_body', 'focus_content');
  5978. removeClass('body', 'is_blurred');
  5979. switch (true) { // switch according to content_pane_data
  5980. case content_pane_data === undefined && isTopWindow():
  5981. removeClass('body', 'focus_content');
  5982. document.body.focus();
  5983. break; // don't focus undefined content
  5984. case hasContent('font'):
  5985. getEl(sel)?.focus();
  5986. if (!hasContent('font_specimen_glyph') && !hasContent('font_file_glyph')) {
  5987. removeClass('#content_font .selected', 'selected');
  5988. }
  5989. switch (true) {
  5990. case sel === '#font_file_glyph_container_0':
  5991. addClass(sel, 'selected');
  5992. scrollThis('#font_file_grid', '.selected');
  5993. getEl(sel)?.focus();
  5994. break;
  5995. case sel === '#font_specimen_glyph_container_0':
  5996. addClass(sel, 'selected');
  5997. scrollThis('#font_specimen_grid', '.selected');
  5998. break;
  5999. }
  6000.  
  6001. switch (true) {
  6002. default:
  6003. getEl(sel)?.focus();
  6004. break;
  6005. case sel === '#font_toolbar':
  6006. getEl(sel)?.focus();
  6007. break;
  6008. case e?.key === 'Tab' || sel === '#font_specimen_1':
  6009. getEl('#font_specimen_1')?.focus();
  6010. break;
  6011. }
  6012. break;
  6013. case hasContent('grid,image,video,pdf'):
  6014. document.getElementById(content_el_id).focus();
  6015. break;
  6016. default:
  6017. getEl(sel)?.focus();
  6018. }
  6019. break;
  6020. }
  6021. }
  6022. //============================//
  6023. // SELECT DIR LIST ITEMS
  6024. function selectThisItem(id, bool) {
  6025. let el = getEl('#' + id),
  6026. kind = (el?.dataset?.kind ?? null); //, id_arr; // ===> SELECT THIS on click and set classes for content_pane; bool
  6027. switch (true) {
  6028. case id === 'close':
  6029. case getEl('#' + id) || id === 'open_sidebar_in_content_pane':
  6030. return;
  6031. case el === null:
  6032. break;
  6033. case kind === 'audio': // audio: add/remove selected class
  6034. removeClass('.audio', 'selected');
  6035. el.classList.add('selected');
  6036. if (!isTopWindow()) {
  6037. removeClass('.non_media', 'selected content_loaded');
  6038. }
  6039. break; // iframe dirlists
  6040. default: // select dir_list item
  6041. removeClass('body', 'has_directory_source');
  6042. addRemoveClassSiblings('#' + id + ':not(.audio)', 'selected content_loaded'); // remove classes from siblings, but leave .audio with playing
  6043. }
  6044. if (!/audio/.test(kind) && !/grid|/.test(id)) {
  6045. addRemoveClassSiblings('#' + id, 'content_loaded', 'content_loaded');
  6046. } // only remove siblings content_loaded class and change content_pane data-source if not audio
  6047. if (/audio|video/.test(kind)) {
  6048. updateMediaDurations(id, getEl('#' + id).querySelector('a').href, getEl('#' + id).dataset.kind);
  6049. }
  6050. if (/image/.test(kind) && getCurrentUIPref('show_image_thumbnails') === 'true' && getCurrentUIPref('show_image_thumbnails_always') === 'false') {
  6051. loadImageThumbnail(id);
  6052. } // load thumbnail if image_count > 2000
  6053. if (bool !== false) {
  6054. scrollThis('#directory_list', '.selected');
  6055. } // bool = false from autoloadcover art
  6056. }
  6057.  
  6058. function selectMultipleItems(e, id) {
  6059. e.preventDefault(); // ===> SELECT MULTIPLE ITEMS
  6060. let el = (id !== undefined ? getEl('#' + id) : null),
  6061. els, kind = (el?.dataset.kind || 'dir');
  6062. if (elExists('#content_grid div[data-id="' + id + '"]')) {
  6063. return
  6064. } // don't add items that are already in grid
  6065. switch (true) {
  6066. case e.key === 'a':
  6067. e.preventDefault(); // cmd-A
  6068. if (isTopWindow()) {
  6069. closeContent();
  6070. }
  6071. kind = (getEls('.dirlist_item.dir.selected,.dirlist_item.app.selected,.dirlist_item.image.selected,.dirlist_item.font.selected')[0]?.dataset.kind || 'dir');
  6072. els = getEls('.dirlist_item.' + kind);
  6073. els?.forEach(el => el.classList.add('selected'));
  6074. if (/image|font/.test(kind)) {
  6075. showGrid('show_' + kind + '_grid');
  6076. }
  6077. break; // show grid of fonts/images
  6078. case (/image|font/.test(kind)) && !el.classList.contains('selected') && isTopWindow():
  6079. showGrid(id);
  6080. break; // makes font/image grids
  6081. case (/dir|app/.test(kind)):
  6082. removeClass('.dirlist_item.file.selected', 'selected');
  6083. removeClass('.dirlist_item.content_loaded', 'content_loaded');
  6084. el.classList.add('selected');
  6085. break; // select dirs
  6086. case (/code|htm|markdown|text/.test(kind)) && isTopWindow(): // text
  6087. removeClass('.dirlist_item.dir.selected', 'selected');
  6088. removeClass('.dirlist_item.dir.content_loaded', 'content_loaded'); // deselect dirs
  6089. el.classList.add('selected'); // select item
  6090. break;
  6091. }
  6092. }
  6093. //============================//
  6094. // ===> SHOW CONTENT FUNCTIONS
  6095. function openFiles(e, id) {
  6096. let funcName = id; // id/funcName === 'open_font' or 'open_playlist'
  6097. switch (e.type) {
  6098. case 'click':
  6099. switch (true) { // These cases are only for when a playlist or font file is already open (check for edited content_iframe...)
  6100. case (/has_\w+list/.test(getClassNames('body'))):
  6101. e.preventDefault();
  6102. showWarning(funcName, 'close_playlist');
  6103. break; // showWarning('openFile');
  6104. case hasContent('font_file'):
  6105. e.preventDefault();
  6106. showWarning(funcName, 'close_font');
  6107. break; // showWarning('openFile');
  6108. }
  6109. break;
  6110. case 'change':
  6111. openFile([e, id]);
  6112. break;
  6113. }
  6114. }
  6115. // ===> SET CONTENT TITLE
  6116. function setContentTitle(id, kind, file_name, src, bool) { // ===> SET CONTENT TITLE
  6117. let title_text = '',
  6118. selected_item = getEl('.dirlist_item.selected'),
  6119. selected_link, content_link, content_link_info = getLinkInfo(src);
  6120. let title_span = (kind === 'has_audio_error' ? getEl('#content_audio_title span') : getEl('#content_title span'));
  6121. switch (true) {
  6122. case id === 'close':
  6123. removeAttribute('#content_title span', 'data-after');
  6124. break;
  6125. default:
  6126. selected_link = (selected_item !== null ? decodeURIComponentSafe(selected_item.querySelector('a').pathname).trim() : ''); // get selected item link
  6127. content_link = (content_link_info !== undefined ? decodeURIComponentSafe(content_link_info[0]).trim() : ''); // get content link
  6128. switch (true) {
  6129. case kind === 'has_audio_error':
  6130. title_text = "Audio file not found";
  6131. break; // audio error title
  6132. case kind === 'content_error':
  6133. title_text = "File not found";
  6134. break; // content error title
  6135. case kind === 'grid':
  6136. title_text = current_dir_path;
  6137. break; // grid title
  6138. case selected_link !== content_link && bool !== false: // nav unsynced iframe items and...
  6139. try {
  6140. title_text = decodeURIComponentSafe(content_link_info[8])
  6141. }
  6142. catch (error) {
  6143. title_text = content_link;
  6144. }
  6145. break; // ...error pages
  6146. default:
  6147. title_text = file_name; // nav synced iframe items
  6148. }
  6149. title_text = title_text?.split('/').join('/<wbr>')?.split('_').join('_<wbr>'); // allow nice line breaks in title
  6150. if (kind === 'image') {
  6151. imageSetDimensions();
  6152. } // show images; set image dimensions
  6153. }
  6154. if (title_span !== null) {
  6155. title_span.innerHTML = title_text;
  6156. } // set title text
  6157. }
  6158.  
  6159. function showContentPaneEl(id) {
  6160. setAttribute('#content_pane', 'data-content', 'has_' + id);
  6161. addClass('#content_' + id, 'has_content');
  6162. getEl('#content_title span').innerHTML = getAttribute('#content_pane', 'data-loaded_id');
  6163. }
  6164.  
  6165. function setContentPaneAttrs(id, kind, content_el_id) { // ===> SET CONTENT PANE ATTRIBUTES
  6166. let class_str_iframe = (id === 'content_iframe_file' ? 'iframe_' : ''),
  6167. class_str_kind = (/app|dir/.test(kind) ? 'dir' : 'file'); // set strings to insert in content_pane class
  6168. switch (true) {
  6169. case id === 'close':
  6170. removeClass('#content_pane', 'content_error has_file has_dir has_zoom_image has_scaled_image has_emptycontent'); // removeclass various iframe_dir_src
  6171. removeAttribute('#content_pane .has_content', 'style');
  6172. removeAttribute('#content_pane', 'data-loaded_id'); // remove inline styles and data-loaded_id
  6173. setAttribute('#content_pane', 'data-content', 'has_null');
  6174. setAttribute('#content_pane', 'data-loaded', 'loaded'); // set data-content=has_null, data-loaded=loaded (remove spinner)
  6175. break;
  6176. default:
  6177. switch (true) {
  6178. case (/content_iframe_dir|content_iframe_parent|open_link_file/.test(id)):
  6179. removeClass('#content_pane', 'has_iframe_file');
  6180. addClass('#content_pane', 'has_iframe_dir');
  6181. break; // iframe_dirs
  6182. case (/content_iframe_file/.test(id)):
  6183. removeClass('#content_pane', 'has_dir');
  6184. addClass('#content_pane', 'has_iframe_file');
  6185. break; // iframe files
  6186. case (/^rowid/.test(id)):
  6187. default:
  6188. removeClass('#content_pane', 'has_dir has_file has_iframe_dir has_iframe_file');
  6189. break; // all sidebar items
  6190. }
  6191. removeClass('#content_pane', 'content_error has_emptycontent'); // removeclass #content_pane error
  6192. addClass('#content_pane', 'has_' + class_str_iframe + class_str_kind); // addclass #content_pane "has_"+ kind
  6193. setAttribute('#content_pane', 'data-content', 'has_' + kind); // add data.content to content_pane
  6194. setAttribute('#content_pane', 'data-loaded_id', id); // hide all iframe content until loaded, show loading spinner:
  6195. if (/content_iframe/.test(content_el_id) && !/ignored/.test(kind)) {
  6196. setAttribute('#content_pane', 'data-loaded', 'unloaded');
  6197. }
  6198. else {
  6199. setAttribute('#content_pane', 'data-loaded', 'loaded');
  6200. }
  6201. }
  6202. }
  6203.  
  6204. function setContentElAttrs(id, content_el_id, kind, src, selected_id) { // ===> SET CONTENT EL ATTRIBUTES
  6205. switch (true) {
  6206. case (/content_iframe_dir|content_iframe_parent|open_link_file/.test(id)): // iframe_dirs
  6207. setAttribute('#content_iframe', 'data-iframe_dir_src', src); // if iframe_dir, set iframe_dir_src attr
  6208. if (!hasAttribute('#content_iframe', 'data-iframe_selected_dir_id')) {
  6209. setAttribute('#content_iframe', 'data-iframe_selected_dir_id', selected_id);
  6210. } // select iframe_dirlist selected if iframe_dir
  6211. break;
  6212. case (/content_iframe_file/.test(id)):
  6213. setAttribute('#content_iframe', 'data-iframe_selected_id', selected_id);
  6214. break; // iframe files
  6215. case kind === 'ignored':
  6216. return; // ignored
  6217. }
  6218. removeAttribute('.content_el', 'src');
  6219. setAttribute(content_el_id, 'src', src); // set content el source
  6220. removeClass('.content_el.has_content', 'has_content');
  6221. addClass(content_el_id, 'has_content'); // addclass .has_content to content_el and remove from siblings
  6222. if (kind === 'image') {
  6223. imageSetDimensions();
  6224. } // set image dimensions if necessary
  6225. }
  6226.  
  6227. function iframeLoadedFunctions(id, kind, file_name, content) {
  6228. let focus_el; // ===> IFRAME LOADED FUNCTIONS
  6229. setAttribute('#content_pane', 'data-loaded', 'loaded'); // set data-loaded (remove loading spinner)
  6230. if (hasAttribute('#content_iframe', 'data-iframe_selected_id')) { // select iframe_dirlist selected IFF is iframe_dir
  6231. messageSend('iframe', 'select_iframe_item', '', getEl('#content_iframe').dataset.iframe_selected_id); // tell iframe to reselect original item
  6232. getEl('#content_iframe').removeAttribute('data-iframe_selected_id'); // remove data-iframe_selected_id
  6233. focus_el = '#content_iframe';
  6234. }
  6235. if (hasAttribute('#content_iframe', 'data-iframe_selected_dir_id') && !hasContent('iframe_dir')) { // reselect originally opened iframe dir after closing any iframe dir opened from it
  6236. messageSend('iframe', 'select_iframe_item', '', getEl('#content_iframe').dataset.iframe_selected_dir_id); // (i.e., when selected sidebar dir is reopened after navigating in the iframe)
  6237. getEl('#content_iframe').removeAttribute('data-iframe_selected_dir_id'); // remove data-iframe_selected_dir_id
  6238. focus_el = '#content_iframe';
  6239. }
  6240. delete getEl('.dirlist_item[data-html_content]')?.dataset?.html_content; // remove existing data-html_content
  6241. getEl('.dirlist_item.selected')?.classList.add('content_loaded'); // add content_loaded class to dirlist_item
  6242. getEl('.dirlist_item.content_loaded')?.setAttribute('data-html_content', content); // set data-html_content for sidebar items (for processing cue, playlists, link files, html, etc.)
  6243. switch (true) {
  6244. case file_name.endsWith('.cuetxt'): {
  6245. cuesheetProcess(content);
  6246. }
  6247. break; // process cuesheet files; name must end with ".cuetxt"
  6248. case kind === 'link': {
  6249. linkFileProcess();
  6250. }
  6251. break; // process link files
  6252. case kind === 'htm' && content === '': {
  6253. addClass('#content_pane', 'has_emptycontent');
  6254. }
  6255. break; // if content == '', set empty class
  6256. case hasClass('#top_body', 'open_sidebar_in_content_pane'):
  6257. addClass('#top_body', 'no_hover');
  6258. removeClass('#top_body', 'open_sidebar_in_content_pane');
  6259. focus_el = '#content_iframe';
  6260. break;
  6261. }
  6262. if (focus_el !== undefined) {
  6263. focusEl(focus_el);
  6264. } // focus element after iframe loaded
  6265. }
  6266. // ===> SHOW THIS ITEM // file_name = link_info[1], file_ext = link_info[2], kind = link_info[3], item_classes = link_info[4], body_classes = link_info[5], stats_classes = link_info[6];
  6267. function showThisItem(id, args) { // ===> SHOW CONTENT // args = [link,kind,selected_id (for iframe dirs/files)] or "close"; bool === false for proper content title for autoload_coverart
  6268. let link_info = (/rowid/.test(id) ? (getLinkInfo(getAttribute('#' + id + ' a', 'href'))) : args !== undefined ? getLinkInfo(args[0]) : id);
  6269. let src, file_name, kind, content_el_id, selected_id = (args?.[2] || undefined),
  6270. content = (args?.[4] || ''),
  6271. link_protocol = link_info?.[7];
  6272. let bool = (args?.[1] === 'autoloadcoverart' ? false : true); // bool: tell set_content_title to use name for cover art, not file path
  6273. if (typeof link_info !== 'string' && link_info !== undefined) {
  6274. src = link_info[0];
  6275. file_name = link_info[1];
  6276. kind = (link_info[4].includes('ignored') ? 'ignored' : link_info[3]);
  6277. } // src, file_name, kind
  6278. if (!/editor/.test(id)) {
  6279. removeClass('body', 'has_texteditor');
  6280. }
  6281. playlistShowItem('close'); // close texteditor and make playlist item textarea
  6282. switch (true) { // make content src string
  6283. case id === 'close':
  6284. kind = 'close';
  6285. id = 'close';
  6286. break;
  6287. case (/\.php\?/.test(src)):
  6288. break;
  6289. case id === '':
  6290. src = args[0];
  6291. kind = args[1];
  6292. break; // id = '' typically when grid items remain after closing subdirectory
  6293. case id === 'open_sidebar_in_content_pane':
  6294. src = args[0] + makeSrcSearchParams('dir');
  6295. kind = args[1];
  6296. break;
  6297. case (/iframe_parent|iframe_dir|open_link_file/.test(id)):
  6298. src += makeSrcSearchParams('dir');
  6299. break; // prep for iframe dirs
  6300. case (/rowid/.test(id)):
  6301. case id === 'content_iframe_file':
  6302. src += makeSrcSearchParams(kind);
  6303. break; //
  6304. }
  6305. content_el_id = (['audio', 'font', 'image', 'pdf', 'video'].includes(kind) ? '#content_' + kind : id === 'close' ? 'close' : '#content_iframe');
  6306. switch (true) { // SHOW INDIVIDUAL CONTENT TYPES
  6307. case hasContent('font_file') && !/audio/.test(kind):
  6308. showWarning('closeContent');
  6309. break; // prevent accidentally closing font file
  6310. case (/audio/.test(kind)):
  6311. showMedia(kind, id, src);
  6312. break; // show audio or audio_close
  6313. case (/editor/.test(id)):
  6314. showTextEditor();
  6315. break; // show top text editor
  6316. case (/iframe_loaded/.test(id)):
  6317. iframeLoadedFunctions(id, kind, file_name, content);
  6318. break; // iframe_loaded
  6319. case (/grid/.test(id)):
  6320. showGrid(id);
  6321. break; // show grid
  6322. case (window.location.protocol !== link_protocol) && link_protocol !== undefined && !['audio', 'font', 'image', 'pdf', 'video', 'dir', 'app'].includes(kind): // replace this text with test has non_local class?
  6323. switch (true) {
  6324. case link_protocol !== 'file:':
  6325. showWarning('non_local_file', [src]);
  6326. break; // warning non-local file on local page (for playlist pages)
  6327. case link_protocol === 'file:':
  6328. showWarning('local_file');
  6329. break; // warning local file on non-local page (for playlist pages)
  6330. }
  6331. showThis('close');
  6332. break; // close previous content
  6333. case kind === 'ignored' && getCurrentUIPref('ignore_ignored_items') === 'false':
  6334. window.location = src;
  6335. break; // attempt to open ignored files if ignore ignored items enabled
  6336. default:
  6337. switch (true) {
  6338. case (/autoloadcoverart/.test(kind)):
  6339. bool = false;
  6340. break;
  6341. case (/font/.test(kind)):
  6342. showFont(id, false, '', src);
  6343. break; // show font specimen; init font preview event listeners
  6344. case (/pdf/.test(kind)):
  6345. showPDF();
  6346. break; // show pdf: setup new #content_pdf el
  6347. case (/video/.test(kind)):
  6348. showMedia('video', id, src);
  6349. break; // show video
  6350. }
  6351. if (/font|image/.test(kind) && hasContent('grid')) {
  6352. closeGrid('hide');
  6353. }
  6354. if (!hasContent('font_file_glyph')) {
  6355. setContentPaneAttrs(id, kind, content_el_id);
  6356. setContentElAttrs(id, content_el_id, kind, src, selected_id);
  6357. setContentTitle(id, kind, file_name, src, bool);
  6358. initContentError(id, content_el_id);
  6359. }
  6360. }
  6361. }
  6362. // ===> SHOW THIS // bool_1 !== false: select item; bool_2 !== false: show item
  6363. function showThis(id, bool_1, bool_2, args) {
  6364. if (bool_1 !== false) {
  6365. selectThisItem(id);
  6366. }
  6367. if (bool_2 !== false) {
  6368. showThisItem(id, args);
  6369. }
  6370. } // ===> SHOW THIS (args = [src,kind,selected_id])
  6371. function quickLookThis(id, kind) {
  6372. getEl('#audio').blur();
  6373. getEl('#content_video').blur(); // prevent media play on space key if focused
  6374. switch (true) {
  6375. case window.parent !== window.top:
  6376. break; // prevent infinite quicklook regression
  6377. case id === 'close':
  6378. closeContent();
  6379. removeClass('body', 'has_quicklook');
  6380. getEl('#content_pane .selected')?.scrollIntoView({
  6381. behavior: "smooth",
  6382. block: "nearest"
  6383. });
  6384. break; // scroll grid item into view
  6385. default:
  6386. addClass('body', 'has_quicklook');
  6387. showMedia('close_audio');
  6388. showThis(id);
  6389. if (/audio|video/.test(kind)) {
  6390. mediaPlayPause('play');
  6391. }
  6392. }
  6393. }
  6394. //============================//
  6395. // ===> CLOSE CONTENT
  6396. function closeContent(kind) { // Close all .content elements before opening any new .content from sidebar. // ===> CLOSE CONTENT
  6397. let content_el_id = (getEl('.content_el.has_content')?.id || '');
  6398. kind = (kind || content_el_id.split('_')[1]);
  6399. switch (true) { // additional actions for specific cases
  6400. case hasContent('hidden_grid'):
  6401. showGrid();
  6402. break; // show hidden grid
  6403. case kind === 'grid':
  6404. case hasContent('grid'):
  6405. closeGrid();
  6406. break; // close grid
  6407. case kind === 'font':
  6408. case hasContent('font_file_glyph') || hasContent('font_specimen_glyph'):
  6409. case hasContent('font'):
  6410. showWarning('close_font', 'close_font');
  6411. break; // close font specimen
  6412. case kind === 'playlist':
  6413. case (/has_\w+list/.test(getClassNames('body'))):
  6414. showWarning('close_playlist', 'close_playlist');
  6415. break; // close playlist/filelist
  6416. case kind === 'texteditor':
  6417. case hasClass('body', 'has_texteditor'):
  6418. showTextEditor(false);
  6419. break; // hide text editor
  6420. case hasContent('audio'):
  6421. showMedia('close_audio');
  6422. break; // close audio if content pane empty
  6423. case hasClass('body', 'iframe_edited'):
  6424. messageSend('iframe', 'unloading', 'closeContent');
  6425. break; // close edited iframe file with warning
  6426. case hasClass('body', 'has_directory_source') && !hasClass('body', 'is_error'):
  6427. showDirectorySource();
  6428. break; // close directory source, reopen selected sidebar item
  6429. case kind === 'esc':
  6430. removeClass('.selected,.content_loaded,.hovered,.is_blurred', 'selected content_loaded hovered,is_blurred');
  6431. removeClass('body', 'focus_content');
  6432. break;
  6433. default:
  6434. showThis('close');
  6435. removeClass('body', 'focus_content has_directory_source');
  6436. break; //
  6437. case hasContent('iframe_file') && !hasContent('iframe_dir'): // if content has iframe file opened from sidebar dir
  6438. case !hasContent('iframe_file') && hasContent('iframe_dir'): // or if content has iframe dir...
  6439. removeClass('#content_pane', 'has_iframe_file'); // remove has_iframe_file class
  6440. showThis(getEl('.dirlist_item.non_media.selected')?.id);
  6441. break; // show the selected sidebar dir
  6442. case hasContent('iframe_file') && hasContent('iframe_dir'): // if content has iframe file from iframe dir...
  6443. removeClass('#content_pane', 'has_iframe_dir'); // remove has_iframe_dir class
  6444. showThis('content_iframe_dir', false, true, [getAttribute('#content_iframe', 'data-iframe_dir_src'), 'dir']); // show the iframe dir
  6445. removeAttribute('#content_iframe', 'data-iframe_dir_src');
  6446. break;
  6447. }
  6448. return;
  6449. }
  6450. //============================//
  6451. // ===> RESET CONTENT (Reset button or Cmd/Ctrl + R)
  6452. function resetContent() { // ===> RELOAD CONTENT
  6453. let content_pane_data = getContentPaneData();
  6454. switch (true) {
  6455. case !hasContent():
  6456. location.reload();
  6457. break; // reload window if no content visible
  6458. case hasContent('audio'):
  6459. getEl('#audio').currentTime = 0;
  6460. getEl('#audio').pause(); // nobreak; pause audio, reset time to 0
  6461. case hasContent('video'):
  6462. getEl('#content_video').currentTime = 0;
  6463. getEl('#content_video').pause();
  6464. break; // pause video, reset time to 0
  6465. }
  6466. switch (true) { // reset other content
  6467. case hasContent('texteditor'):
  6468. case (/has_\w+list/.test(getClassNames('#top_body'))):
  6469. break; // do nothing for audio, video, text editor, playlist content.
  6470. case hasContent('grid'):
  6471. removeAttribute('#content_grid,.image_grid_item img', 'style');
  6472. showGrid();
  6473. break; // reset grid
  6474. case hasContent('font'):
  6475. fontReset('reset');
  6476. break;
  6477. case hasContent('image'):
  6478. closeContent();
  6479. if (elExists('.image.selected') || elExists('.image.content_loaded')) {
  6480. showThis(getEl('.dirlist_item.image.content_loaded').id);
  6481. }
  6482. break;
  6483. case hasContent('text,markdown,htm,iframe,dir'):
  6484. switch (true) {
  6485. case hasClass('body', 'iframe_edited'):
  6486. messageSend('iframe', 'reloading', 'resetContent');
  6487. break;
  6488. default:
  6489. showThis(getEl('.dirlist_item.content_loaded').id);
  6490. }
  6491. case hasContent('audio') || hasContent('video'):
  6492. break; // don't do anything else for audio, video, text editor, playlist content.
  6493. case (/has_ignored|undefined/.test(content_pane_data)):
  6494. window.location = window.location.href;
  6495. break; // reload page
  6496. }
  6497. delete getEl('#content_pane').dataset.loaded; // remove dataset.loaded in case file can't be read by utility iframe
  6498. }
  6499. //**********************// ===> NAVIGATION
  6500. function navigationGetType() { // ===> GET NAVIGATION TYPE
  6501. let content_pane_data = (elExists('#content_pane') ? getContentPaneData() : 'iframe'),
  6502. nav_type;
  6503. switch (true) {
  6504. case hasClass('body', 'has_menu'):
  6505. nav_type = (getEl('#dir_menu_main .hovered') ? '#dir_menu_main .hovered ul' : '#dir_menu_main');
  6506. break; // submenu or menu
  6507. case content_pane_data === 'iframe' && elExists('#directory_list'):
  6508. nav_type = '#directory_list';
  6509. break; // iframe dir_list
  6510. case (hasContent('font_file_glyph') || hasContent('font_file')) && hasClass('body', 'focus_content'):
  6511. nav_type = '#font_file_grid';
  6512. break; // font file glyphs
  6513. case getEl('#font_specimen_grid').children.length > 0 && hasClass('body', 'focus_content') && document.activeElement.contentEditable !== true:
  6514. nav_type = '#font_specimen_grid';
  6515. break; // font specimen glyphs
  6516. case hasContent('image,font') && hasContent('hidden_grid') && hasClass('body', 'focus_content'):
  6517. case hasContent('grid') && hasClass('body', 'focus_content'):
  6518. nav_type = '#content_grid';
  6519. break; // grids
  6520. default:
  6521. nav_type = '#directory_list'; // default: dir_list
  6522. }
  6523. return nav_type; // = selector of container of items to be navigated
  6524. }
  6525.  
  6526. function navigateGetEl(args) { // ===> GET NEXT NAVIGATED ITEM
  6527. let els, els_length, selected_el_index, key = args[0],
  6528. bool = args[1],
  6529. nav_type = navigationGetType(),
  6530. selected_el, selected_el_kind, navigated_el;
  6531. switch (true) { // Get selected_el
  6532. case bool === true:
  6533. selected_el = getEl('.media.selected') || getEls('.audio_loaded,.media.content_loaded,.dirlist_item.is_blurred')[0] || getEl('.media');
  6534. break; // bool === true: autoplay media
  6535. default:
  6536. selected_el = getEl(nav_type).querySelector('.selected'); // get currently selected item
  6537. }
  6538. if (selected_el !== null) {
  6539. selected_el.classList.remove('selected'); // If there is a selected item...remove its selected class
  6540. if (!/warning_buttons/.test(nav_type)) {
  6541. switch (true) { // get both images and fonts from mixed grids for L/R navigation...
  6542. case nav_type === '#content_grid' && elExists('.image_grid_item') && elExists('.font_grid_item'):
  6543. selected_el_kind = new RegExp(/image|font/);
  6544. break;
  6545. default:
  6546. selected_el_kind = new RegExp(selected_el.dataset.kind); // or get selected_el kind (for L/R navigation)
  6547. }
  6548. }
  6549. if (/audio|video/.test(selected_el_kind) && hasClass('body', 'media_play_all')) {
  6550. selected_el_kind = /audio|video/;
  6551. } // but if media_play_all, get both media kinds
  6552. if (selected_el.classList.contains('hovered') && /ArrowUp|ArrowDown/.test(key)) {
  6553. getEl('#dir_menu_main .hovered').classList.remove('hovered');
  6554. }
  6555. }
  6556. els = Array.from(getEl(nav_type).children).filter((el) => { // Get all navigable elements and filter
  6557. if (/font_specimen_grid|font_file_grid|content_grid/.test(nav_type) || el.offsetWidth > 0 && el.offsetHeight > 0) { // only return visible items (or glyphs grid items)
  6558. if (selected_el !== null && /ArrowLeft|ArrowRight/.test(key) && !/warning_buttons|menu/.test(nav_type)) { // if L/R arrow and not menu or warning, and selected_el !== null...
  6559. return selected_el_kind.test(el.dataset.kind) && !el.classList.contains('unchecked'); // ...return all unchecked items of same kind as selected_el
  6560. }
  6561. else {
  6562. return true; // else return all items
  6563. }
  6564. }
  6565. });
  6566. els_length = els.length;
  6567. selected_el_index = (selected_el === null ? -1 : els.indexOf(selected_el)); // get index of selected item from filtered els or -1 if null
  6568. switch (true) { // GET NEXT NAVIGATED ELEMENT
  6569. case hasClass('body', 'has_directory_source'): // if viewing directory source, arrows will reopen selected sidebar item
  6570. if (elExists('.dirlist_item.content_loaded')) {
  6571. showThis(getEl('.dirlist_item.content_loaded').id);
  6572. }
  6573. else {
  6574. showThis(selected_el.id);
  6575. }
  6576. return;
  6577. case key === 'Tab':
  6578. if (selected_el === null) {
  6579. navigated_el = (bool !== true ? els[0] : els[els_length - 1])
  6580. }
  6581. else {
  6582. navigated_el = selected_el;
  6583. }
  6584. break; // navigation from tab into iframe
  6585. case key === 'ArrowUp':
  6586. case key === 'ArrowLeft': // ArrowUp / ArrowDown
  6587. switch (true) {
  6588. case (/audio|video/.test(selected_el_kind) && key === 'ArrowLeft'):
  6589. navigated_el = navigateGetMediaLeftRightEl(els, selected_el, selected_el_index, key);
  6590. break; // media
  6591. case (/font_file|grid/.test(nav_type) && !hasClass('body', 'has_menu')):
  6592. navigated_el = els[navigateGetGridItemIndex(selected_el_index, els_length, nav_type, key)];
  6593. break;
  6594. case (hasClass('body', 'has_menu') && selected_el === null && key === 'ArrowLeft'):
  6595. navigated_el = getEl('#dir_menu_parents');
  6596. break; // select parents menu if no main menu item selected
  6597. case (selected_el === null || (selected_el_index === 0 && !key === 'ArrowLeft')):
  6598. navigated_el = els[els_length - 1];
  6599. break; // select last if nothing selected
  6600. case (selected_el.classList.contains('is_submenu_item') && key === 'ArrowLeft'):
  6601. navigated_el = navigateGetSubMenuEl(selected_el, key);
  6602. break; // go to parent menu
  6603. case (selected_el_index === 0):
  6604. navigated_el = els[els_length - 1];
  6605. break; // additional case for menus
  6606. default:
  6607. navigated_el = els[selected_el_index - 1]; // default dir_list and menu items
  6608. }
  6609. break;
  6610. case key === 'ArrowDown':
  6611. case key === 'ArrowRight': // ArrowLeft / ArrowRight
  6612. switch (true) {
  6613. case (/audio|video/.test(selected_el_kind) && key === 'ArrowRight'):
  6614. switch (true) { // if autoplay off, navigated_el = selected_el, else navigated_el = next media item
  6615. case hasClass('body', 'media_autoplay_false') && bool === true:
  6616. navigated_el = selected_el;
  6617. break;
  6618. default:
  6619. navigated_el = navigateGetMediaLeftRightEl(els, selected_el, selected_el_index, key);
  6620. }
  6621. break;
  6622. case (/font_file|grid/.test(nav_type) && !hasClass('body', 'has_menu')):
  6623. navigated_el = els[navigateGetGridItemIndex(selected_el_index, els_length, nav_type, key)];
  6624. break;
  6625. case (selected_el === null || selected_el_index === els_length - 1):
  6626. navigated_el = els[0];
  6627. break; // select first if nothing selected
  6628. case (selected_el.classList.contains('has_submenu') && key === 'ArrowRight'):
  6629. navigated_el = navigateGetSubMenuEl(selected_el, key);
  6630. break; // open submenu
  6631. default:
  6632. navigated_el = els[selected_el_index + 1]; // default dir_list and menu items
  6633. }
  6634. break;
  6635. }
  6636. switch (true) { // WHAT TO DO WITH NAVIGATED ELEMENT:
  6637. case navigated_el === undefined:
  6638. navigated_el = (/ArrowUp|ArrowLeft/.test(key) ? els[els_length - 1] : /ArrowDown|ArrowRight/.test(key) ? els[0] : null);
  6639. if (navigated_el !== null) {
  6640. showThis(navigated_el.id);
  6641. }
  6642. break;
  6643. case (/grid|menu/.test(nav_type)):
  6644. navigated_el.classList.add('selected'); // for grids and menus; ...add selected class to navigated_el
  6645. switch (true) {
  6646. case hasClass('body', 'has_menu'):
  6647. case hasClass('body', 'has_menu_parents'):
  6648. break;
  6649. case navigated_el.id === 'dir_menu_parents':
  6650. menuShow(null, 'dir_menu_parents');
  6651. break;
  6652. case hasContent('font_specimen_glyph'):
  6653. showFontGlyph(null, navigated_el.id);
  6654. break;
  6655. case hasContent('font_file_glyph'):
  6656. showFontGlyph(null, navigated_el.id);
  6657. break; // show the navigated font file glyph
  6658. case (/grid/.test(nav_type)):
  6659. getEl('#directory_list .selected')?.scrollIntoView({
  6660. block: "nearest"
  6661. }); // scroll dir_list item into view
  6662. getEl('#content_pane .selected')?.scrollIntoView({
  6663. behavior: "smooth",
  6664. block: "nearest"
  6665. }); // scroll grid item into view
  6666. break;
  6667. }
  6668. break;
  6669. case !isTopWindow():
  6670. switch (true) {
  6671. case hasClass('#content_body', 'has_quicklook'):
  6672. quickLookThis(navigated_el.id, navigated_el.dataset.kind);
  6673. break; // either quicklook or select item
  6674. default:
  6675. showThis(navigated_el.id, true, false);
  6676. }
  6677. break;
  6678. case (/ArrowUp|ArrowDown/.test(key) && navigated_el.dataset.kind === 'audio' && !hasClass('#content_body', 'has_quicklook')):
  6679. showThis(navigated_el.id, true, false);
  6680. break; // only select audio on U/D arrow
  6681. case (/ArrowLeft|ArrowRight/.test(key) && navigated_el.classList.contains('media')):
  6682. switch (true) {
  6683. case hasClass('body', 'media_autoplay_false') && bool === 'true':
  6684. showThis(selected_el.id, true, false);
  6685. break;
  6686. default:
  6687. showThis(navigated_el.id); // L/R arrow: load and play media
  6688. if (selected_el_index === els_length - 1 && !hasClass('body', 'loop_media') && bool === true) {
  6689. null;
  6690. }
  6691. else {
  6692. mediaPlayPause('play');
  6693. } // if last item & !loop, select first item, else play
  6694. }
  6695. break;
  6696. default:
  6697. showThis(navigated_el.id); // default: show item
  6698. }
  6699. }
  6700.  
  6701. function navigateGetGridItemIndex(selected_el_index, els_length, nav_type, key) { // ===> GRID NAVIGATION
  6702. let grid_col_count, grid_row_count, grid_item_index;
  6703. if (/ArrowUp|ArrowDown/.test(key)) { // calculate number of grid rows and columns
  6704. grid_col_count = (Math.round(getEl(nav_type).offsetWidth / getEl(nav_type + ' > li').offsetWidth)); // number of grid items per row
  6705. grid_row_count = Math.floor(els_length / grid_col_count); // number of full grid rows
  6706. }
  6707. switch (true) {
  6708. case key === 'ArrowUp': // ArrowUp
  6709. switch (true) {
  6710. case selected_el_index === -1:
  6711. grid_item_index = els_length - 1;
  6712. break; // if nothing selected
  6713. case selected_el_index < grid_col_count: // if selected el is in first grid row...
  6714. switch (true) { // ...and if it is in a column to the right of last item in last row get...
  6715. case (grid_col_count * grid_row_count) + selected_el_index >= els_length:
  6716. grid_item_index = selected_el_index + (grid_col_count * (grid_row_count - 1));
  6717. break; // last in penultimate col or...
  6718. default:
  6719. grid_item_index = selected_el_index + (grid_col_count * grid_row_count); // last in last row
  6720. }
  6721. break;
  6722. default:
  6723. grid_item_index = selected_el_index - grid_col_count; // default: grid_item_index = selected_el_index - length of grid row
  6724. }
  6725. break;
  6726. case key === 'ArrowDown': // ArrowDown
  6727. switch (true) {
  6728. case selected_el_index === -1:
  6729. grid_item_index = 0;
  6730. break; // if nothing selected, get first item
  6731. case selected_el_index + 1 + grid_col_count > els_length:
  6732. grid_item_index = (selected_el_index - (grid_col_count * (grid_row_count - 1))) % grid_col_count;
  6733. break; // if selected is last in column
  6734. default:
  6735. grid_item_index = selected_el_index + grid_col_count; // default: index = selected_el_index plus the length of the grid row
  6736. }
  6737. break;
  6738. case key === 'ArrowLeft':
  6739. grid_item_index = ((selected_el_index === -1 || selected_el_index === 0) ? els_length - 1 : selected_el_index - 1);
  6740. break; // if first or nothing selected, get last or prev
  6741. case key === 'ArrowRight':
  6742. grid_item_index = ((selected_el_index === -1 || selected_el_index + 1 === els_length) ? 0 : selected_el_index + 1);
  6743. break; // if last or nothing selected, get first or next
  6744. }
  6745. if (!hasContent('font_file') && nav_type !== '#font_specimen_grid' && nav_type !== '#font_file_grid') { // select corresponding dir_list item for image/font grids, but not font files
  6746. removeClass('.dirlist_item', 'selected hovered');
  6747. removeClass('.dirlist_item.content_loaded', 'content_loaded'); // remove classes from dir_list items
  6748. let selected_id = getEl(nav_type).querySelectorAll('.grid_item')?.[grid_item_index]?.dataset.id; // get the data-id from the currently selected grid item
  6749. if (selected_id) {
  6750. getEl('#' + selected_id)?.classList.add('selected');
  6751. getEl('.dirlist_item.selected')?.scrollIntoView({
  6752. behavior: "smooth",
  6753. block: "nearest"
  6754. });
  6755. } // select & scroll dir_list item into view
  6756. }
  6757. return grid_item_index;
  6758. }
  6759.  
  6760. function navigateGetSubMenuEl(selected_el, key) {
  6761. let navigated_el; // ===> SUBMENU NAVIGATION
  6762. switch (true) {
  6763. case selected_el?.classList.contains('has_submenu') && key === 'ArrowRight':
  6764. selected_el.classList.add('hovered');
  6765. navigated_el = selected_el.querySelector('ul li');
  6766. navigated_el.classList.add('selected');
  6767. break;
  6768. case selected_el?.classList.contains('is_submenu_item') && key === 'ArrowLeft':
  6769. removeClass('#dir_menu_main li.is_submenu_item.selected', 'selected');
  6770. navigated_el = getEl('#dir_menu_main .hovered');
  6771. navigated_el.classList.add('selected');
  6772. navigated_el.classList.remove('hovered');
  6773. break;
  6774. }
  6775. return navigated_el;
  6776. }
  6777.  
  6778. function navigateGetMediaLeftRightEl(els, selected_el, selected_el_index, key) {
  6779. let navigated_el, navigated_el_id; // ===> MEDIA LEFT/RIGHT NAVIGATION (Audio)
  6780. switch (true) {
  6781. case hasClass('body', 'shuffle_media'):
  6782. navigated_el_id = mediaShuffleGetNextItem(); // if shuffle play enabled...get the next shuffled item id
  6783. switch (true) { // but if all shuffled items have been played (i.e., navigated_el_id === ''): if loop, update shufflelist, get next item; else get first item.
  6784. case navigated_el_id === '':
  6785. navigated_el = (hasClass('body', 'loop_media') ? (mediaShuffleListUpdate(), navigated_el = getEl('#' + mediaShuffleGetNextItem())) : navigated_el = els[0]);
  6786. break;
  6787. default:
  6788. navigated_el = getEl('#' + navigated_el_id); // else get next item in the shufflelist
  6789. }
  6790. getEl('#shuffle_label').dataset.shufflecount = ' (' + getAttribute('#content_audio', 'data-shufflelist').split(',').length + ' remaining)';
  6791. break;
  6792. case !selected_el.classList.contains('audio_loaded') && selected_el.classList.contains('audio') && isTopWindow():
  6793. navigated_el = selected_el;
  6794. break; // if selected audio item not loaded, select it
  6795. case key === 'ArrowRight':
  6796. navigated_el = (selected_el_index + 1 < els.length ? els[selected_el_index + 1] : navigated_el = els[0]);
  6797. break; // if selected not last, select next, else select first
  6798. case key === 'ArrowLeft':
  6799. navigated_el = (selected_el_index - 1 !== -1 ? els[selected_el_index - 1] : navigated_el = els[els.length - 1]);
  6800. break; // if selected not first, select prev item, else last
  6801. }
  6802. selected_el.classList.remove('audio_loaded', 'content_loaded'); // deselect currently selected media item class
  6803. return navigated_el;
  6804. }
  6805.  
  6806. function navigateWarningBtns(e) { // ===> NAVIGATE WARNING BUTTONS
  6807. let buttons = getVisibleElsBySelector('#warning_buttons button');
  6808. let focused_button = getVisibleElsBySelector('#warning_buttons :focus,#warning_buttons .focus')[0],
  6809. focused_btn_index = buttons.indexOf(focused_button);
  6810. removeClass('#warning_buttons button', 'focus');
  6811. switch (true) {
  6812. case e.shiftKey:
  6813. switch (true) {
  6814. case focused_button === null || buttons.indexOf(focused_button) === 0:
  6815. buttons[buttons.length - 1].focus();
  6816. buttons[buttons.length - 1].classList.add('focus');
  6817. break; // focus last button
  6818. default:
  6819. buttons[focused_btn_index - 1].classList.add('focus');
  6820. buttons[focused_btn_index - 1].focus(); // else focus previous button
  6821. }
  6822. break;
  6823. default: // e.Tab
  6824. switch (true) {
  6825. case focused_button === null || buttons.indexOf(focused_button) === buttons.length - 1:
  6826. buttons[0].focus();
  6827. buttons[0].classList.add('focus');
  6828. break; // focus first button
  6829. default:
  6830. buttons[focused_btn_index + 1].classList.add('focus');
  6831. buttons[focused_btn_index + 1].focus(); // else focus next button
  6832. }
  6833. }
  6834. }
  6835.  
  6836. function navigateByArrowModKey(e, id) { // ===> ARROW KEY MODIFIER FUNCTIONS
  6837. let args = [e.key],
  6838. selected_el;
  6839. if (cmdAltKey(e) && (/ArrowLeft|ArrowRight|ArrowUp|ArrowDown/.test(e.key))) {
  6840. return;
  6841. }
  6842. else {
  6843. e.preventDefault();
  6844. } // prevents starting audio play when changing tabs; allows browser tab cycling
  6845. switch (true) {
  6846. case (/ArrowUp|ArrowDown/.test(e.key) && e.shiftKey && !cmdKey(e) && !altKey(e)): // e.shiftKey => select multiple items
  6847. let prev_el = getEl('#' + id).previousElementSibling,
  6848. next_el = getEl('#' + id).nextElementSibling;
  6849. let sibling_id = (e.key === 'ArrowUp' && prev_el !== null ? prev_el.id : e.key === 'ArrowDown' && next_el !== null ? next_el.id : null);
  6850. if (sibling_id !== null) {
  6851. selectMultipleItems(e, sibling_id);
  6852. } // if there is a sibling, select it
  6853. break;
  6854. case (/ArrowLeft|ArrowRight/.test(e.key) && (altKey(e) || altShiftKey(e))): // alt/shift + L/R => mediaSkip(e)
  6855. if (e.shiftKey) {
  6856. args.push(30);
  6857. }
  6858. else {
  6859. args.push(10);
  6860. } // scrub 10s or 30s
  6861. if (!isTopWindow()) {
  6862. messageSend('top_body', 'mediaSkip', 'mediaSkip', args);
  6863. }
  6864. else {
  6865. mediaSkip(e);
  6866. }
  6867. break;
  6868. case cmdKey(e) && e.key === 'ArrowUp': // Cmd/Ctrl + Up
  6869. switch (true) {
  6870. case hasClass('body', 'is_dir'):
  6871. case !isTopWindow():
  6872. iframeClick(e, 'iframe_parent_link', 'link', getEl('#iframe_parent_link').href);
  6873. break; // go to iframe parent
  6874. case isTopWindow() && hasClass('body', 'focus_content') && hasClass('#content_iframe', 'has_content'):
  6875. messageSend('iframe', 'open_iframe_parent_dir');
  6876. break; // fallback for go to iframe parent in case top is incorrectly focused
  6877. default:
  6878. e.preventDefault();
  6879. showWarning('changeLocation', [getEl('#parent_dir_nav a').href, 'false']);
  6880. break; // go to parent (with warning for playlists/fonts/edited text)
  6881. }
  6882. break;
  6883. case cmdKey(e) && e.key === 'ArrowDown': // Cmd/Ctrl + Down
  6884. switch (true) {
  6885. case !elExists('.selected'):
  6886. break; // do nothing if nothing selected
  6887. case elExists('#content_body #directory_list') && cmdKey(e):
  6888. iframeClick(e, id, 'dblclick', getEl('#' + id).querySelector('a').href);
  6889. break;
  6890. case hasClass('.dirlist_item.selected', 'link'):
  6891. openLinkFile(e, getEl('.dirlist_item.selected.link').id);
  6892. break; // open webloc or url files
  6893. case hasClass('.dirlist_item.selected', 'playlist'):
  6894. openPlaylist('', '', getEl('.dirlist_item.selected.playlist').dataset.playlist);
  6895. break; // open playlist or filelist
  6896. case isTopWindow() && hasClass('body', 'focus_content'):
  6897. focusEl('#content_iframe', e);
  6898. break; // select first item if nothing selected in iframe
  6899. case isTopWindow() && hasClass('.dirlist_item.selected', 'file') && !hasClass('.dirlist_item.selected', 'link'):
  6900. break; // ? do nothing for link files
  6901. case isTopWindow() && hasClass('.dirlist_item.selected', 'dir') && hasClass('.dirlist_item.selected', 'app') && UI_Prefs_Bool.apps_as_dirs === false:
  6902. break; // break if not viewing apps as dirs
  6903. default:
  6904. showWarning('dirOpen', [getAttribute('.dirlist_item.selected', 'id'), getAttribute('.dirlist_item.selected a', 'href')]);
  6905. // else double-click directories and all iframe items to open them
  6906. }
  6907. break;
  6908. case cmdKey(e) && e.key === 'ArrowLeft': // Cmd/Ctrl + Left
  6909. switch (true) {
  6910. case elExists('.dirlist_item.dir.selected.has_subdirectory'):
  6911. getEls('.dirlist_item.dir.selected.has_subdirectory').forEach(dir => subDirClose(dir.id));
  6912. break; // close all selected subdirectories
  6913. case !hasClass('.dirlist_item.selected', 'has_subdirectory') && elExists('.dirlist_item.has_subdirectory'): // if selected item is in subdirectory...
  6914. selected_el = getEl('.dirlist_item.selected');
  6915. if (selected_el === null || selected_el.previousElementSibling === null) {
  6916. break;
  6917. } // do nothing if no selection or prev element
  6918. while (!selected_el.previousElementSibling.classList.contains('has_subdirectory')) {
  6919. selected_el = selected_el.previousElementSibling;
  6920. } // find subdir "parent" === prev .has_subdirectory
  6921. if (selected_el !== null && selected_el.previousElementSibling !== null) {
  6922. showThis(selected_el.previousElementSibling.id);
  6923. }
  6924. break; // select and show parent dir
  6925. default:
  6926. showThis(getVisibleElsBySelector('.dirlist_item')[0].id); // select first visible item
  6927. }
  6928. break;
  6929. case cmdKey(e) && e.key === 'ArrowRight':
  6930. try {
  6931. subDirOpen(getEl('.dirlist_item.dir.selected:not(.has_subdirectory)').id);
  6932. }
  6933. catch (e) {
  6934. null;
  6935. }
  6936. break; // Cmd/Ctrl + R: open (1st) selected subdirectory
  6937. case e.shiftKey:
  6938. navigateGetEl([e.key, false, true]);
  6939. break;
  6940. }
  6941. }
  6942.  
  6943. function navigateByArrowKey(args) {
  6944. navigateGetEl(args);
  6945. } // args[0] = key, args[1] = bool (for autoplay media),bool = shift // ===> ARROW KEY NAVIGATION
  6946. function arrowKeyFunctions(e, bool, el) { // 'e' = keyboardEvent or string (e.g. 'ArrowLeft/Right' from clickPrevNextButtons() // ===> ARROW KEY FUNCTIONS
  6947. addClass('body', 'no_hover');
  6948. if (hasClass('body', 'has_help')) {
  6949. getEl('#help_container').focus();
  6950. return true;
  6951. }
  6952. let id = (/ArrowUp|ArrowLeft/.test(e.key) ? el?.querySelector('.selected')?.id : Array.from(el?.querySelectorAll('.selected'))?.reverse()[0]?.id); // get first or last selected item
  6953. if (!/texteditor/.test(document.activeElement.id) && !/textarea/.test(document.activeElement.tagName.toLowerCase())) {
  6954. window.getSelection().removeAllRanges();
  6955. document.activeElement.blur();
  6956. } // TEST all situations
  6957. switch (true) {
  6958. case (/a|input|select|textarea/.test(document.activeElement.tagName.toLowerCase())) && !cmdKey(e): // nobreak: allow normal arrow key functions
  6959. case (/texteditor/.test(document.activeElement.id)) && !cmdKey(e): // nobreak // " "
  6960. case document.activeElement.hasAttribute('contentEditable') && !cmdKey(e): // nobreak // " "
  6961. case !isTopWindow() && !elExists('#content_body #directory_list') && !cmdKey(e):
  6962. return; // iframe is not a dir_list
  6963. case hasContent('pdf') && hasClass('body', 'focus_content'):
  6964. focusEl('#content_pdf');
  6965. break; // focus content_pdf
  6966. case ((hasContent('zoom_image') || hasContent('scaled_image')) && hasClass('body', 'focus_content')):
  6967. focusEl('#content_image');
  6968. return; // scroll imgs
  6969. case e.altKey:
  6970. case e.ctrlKey:
  6971. case e.metaKey:
  6972. case e.shiftKey:
  6973. navigateByArrowModKey(e, id);
  6974. break; // arrow keys + modifiers
  6975. case isTopWindow() && hasClass('body', 'iframe_edited'):
  6976. e.preventDefault();
  6977. messageSend('iframe', 'unloading', '', ['arrow_key_navigation', e.key]);
  6978. break;
  6979. case isTopWindow() && hasClass('body', 'focus_content') && hasContent('dir'):
  6980. e.preventDefault(); // req. after nav to iframe dir_list parent dir
  6981. switch (true) {
  6982. case hasClass('body', 'has_menu'):
  6983. navigateByArrowKey([e.key, false]);
  6984. break;
  6985. default:
  6986. messageSend('iframe', 'iframe_navigation', '', [e.key, false]);
  6987. getEl('#content_iframe').focus();
  6988. }
  6989. break;
  6990. case hasClass('body', 'has_top_menu') && !isTopWindow():
  6991. e.preventDefault();
  6992. messageSend('top_body', 'arrow_key_navigation', 'navigateByArrowKey', [e.key, false]);
  6993. break; // menu navigation from focused iframe
  6994. case hasClass('body', 'has_quicklook'):
  6995. e.preventDefault();
  6996. navigateByArrowKey([e.key, bool]);
  6997. break;
  6998. default:
  6999. e.preventDefault();
  7000. showWarning('navigateByArrowKey', [e.key, bool]); // normal arrow key navigation, with warning
  7001. }
  7002. }
  7003. // NAVIGATION Go to Item
  7004. function goToItem(e) {
  7005. e.stopPropagation();
  7006. e.preventDefault();
  7007. let value, input_el = getEl('#go_to_item input');
  7008. switch (true) {
  7009. case e.key === 'j' && cmdShiftKey(e):
  7010. menuShow(e, 'dir_menu_main_container'); // nobreak; show menu
  7011. case e?.type === 'click' && document.activeElement.id !== 'go_to_item_input':
  7012. addClass('#go_to_item', 'show_input');
  7013. getEl('#go_to_item input').focus();
  7014. break; // show input on click
  7015. case e?.key === 'Enter':
  7016. default:
  7017. value = input_el.value - 1;
  7018. removeClass('#go_to_item', 'show_input');
  7019. input_el.value = null;
  7020. menuClose();
  7021. showThis(getEls('#directory_list .dirlist_item')[value]?.id);
  7022. break; // get the entered ui font
  7023. }
  7024. }
  7025. // NAVIGATION Tab Key
  7026. function navigateTabKeyFocus(kind, incr) {
  7027. let sel = {
  7028. 'font': '#content_font .selected,#content_font *[data-tab_order],#font_toolbar *[data-tab_order]',
  7029. 'grid': '#content_grid,#top_body',
  7030. 'html': 'a,button,input,select,textarea,div[contenteditable]',
  7031. 'link': '#texteditor_preview_pane a',
  7032. 'texteditor': '#content_texteditor .texteditor_pane'
  7033. } // tab-able elements by nav type
  7034. let els = Array.from(getEls(sel[kind])).filter(el => el.offsetWidth > 0 && el.offsetHeight > 0),
  7035. el_ids, next_item_id, font_els = []; // get tab-able elements; other vars
  7036. let active_el = (kind === 'font' ? getEls('#content_font .selected,#content_font *:focus,#font_toolbar *:focus')[0] : document.activeElement);
  7037. if (els !== null) {
  7038. el_ids = (kind !== 'html' ? els.map(el => el.id) : els.map(el => els.indexOf(el)))
  7039. }
  7040. else {
  7041. return null
  7042. } // get ids or define ids by index
  7043. if (kind === 'font' && incr === 1) { // reorder font_specimen items
  7044. font_els = el_ids.filter(id => (/font_specimen/.test(id)));
  7045. el_ids = el_ids.filter(id => (!/font_specimen/.test(id)));
  7046. if (incr === -1) {
  7047. el_ids.reverse();
  7048. }
  7049. el_ids = font_els.concat(el_ids);
  7050. if (getEl('#font_file_grid .selected')) {
  7051. null;
  7052. }
  7053. }
  7054. switch (true) { // get first or last item...
  7055. case active_el === undefined && kind === 'font' && incr === 1:
  7056. case (active_el?.tagName.toLowerCase() === 'body' || active_el === null) && incr === 1:
  7057. next_item_id = el_ids[0];
  7058. break;
  7059. case active_el === undefined && kind === 'font' && incr === -1:
  7060. case (active_el?.tagName.toLowerCase() === 'body' || active_el === null) && incr === -1:
  7061. next_item_id = el_ids[el_ids.length - 1];
  7062. break;
  7063. default:
  7064. next_item_id = (kind !== 'html' ? el_ids[el_ids.indexOf(active_el.id) + incr] : el_ids[els.indexOf(active_el) + incr]);
  7065. break; // or tab to next item for any other content
  7066. }
  7067. switch (true) {
  7068. case next_item_id === undefined:
  7069. if (kind === 'font' && !hasClass('body', 'focus_content')) {
  7070. addClass('body', 'focus_content');
  7071. }
  7072. else {
  7073. focusEl('#top_body');
  7074. }
  7075. break; //focus top or font
  7076. case kind === 'grid':
  7077. focusEl('#content_grid');
  7078. break;
  7079. case kind !== 'html':
  7080. focusEl('#' + next_item_id);
  7081. break;
  7082. case kind === 'html':
  7083. if (!getEl('#html_styles')) {
  7084. document.head.insertAdjacentHTML('beforeend', '<style id="html_styles">' + html_style_rules + '</style>');
  7085. }
  7086. els[next_item_id].focus({
  7087. focusVisible: true
  7088. });
  7089. break;
  7090. }
  7091. }
  7092.  
  7093. function navigateByTabKey(e, incr) { // ===> NAVIGATION TAB KEY
  7094. if (e === null) {
  7095. null
  7096. }
  7097. else {
  7098. incr = (e.shiftKey ? -1 : 1);
  7099. } // e === null if from message navigateTabKeyFocus;
  7100. let content_pane_data = getContentPaneData(),
  7101. content_el_id = 'content' + content_pane_data?.slice(3) || null,
  7102. next_item_id;
  7103. switch (true) { // non-default cases
  7104. case hasClass('body', 'has_warning'):
  7105. navigateWarningBtns(e);
  7106. break; // nav warning buttons
  7107. case hasContent('texteditor'):
  7108. navigateTabKeyFocus('texteditor', incr);
  7109. break; // focus font preview, grid, text editor els
  7110. case hasContent('font,grid'):
  7111. navigateTabKeyFocus(content_pane_data.slice(4), incr);
  7112. break; // focus font preview, grid, text editor els
  7113. case !isTopWindow():
  7114. switch (true) {
  7115. case hasClass('body', 'is_dir'):
  7116. messageSend('top_body', 'focus_top');
  7117. break;
  7118. case hasClass('body', 'is_link'):
  7119. navigateTabKeyFocus('link', incr);
  7120. break; // nav link file
  7121. case hasClass('body', 'is_html'):
  7122. navigateTabKeyFocus('html', incr);
  7123. break; // nav html file els (links, etc.)
  7124. case hasClass('body', 'is_text'):
  7125. navigateTabKeyFocus('texteditor', incr);
  7126. break; // nav html file els (links, etc.)
  7127. }
  7128. break;
  7129. default:
  7130. switch (true) {
  7131. case hasContent('image,pdf,video') && !hasClass('body', 'focus_content'):
  7132. next_item_id = content_el_id;
  7133. break; // tab into images, pdf, video
  7134. case hasClass('body', 'has_texteditor') && !hasClass('body', 'focus_content'): // tab into text editor
  7135. case hasContent('dir,htm,markdown,text,code,other,link'):
  7136. next_item_id = '#content_iframe';
  7137. break; // tab into iframe dirs and text files
  7138. case hasClass('body', 'focus_content'):
  7139. next_item_id = '#top_body';
  7140. break; // tab into top
  7141. }
  7142. focusEl(next_item_id, e); // focusEl
  7143. }
  7144. }
  7145. // NAVIGATION Other
  7146. function navigateByTypedStr(e) {
  7147. let items, item, timer; // ===> NAVIGATE BY TYPED STRING
  7148. switch (true) {
  7149. case (/textarea|input/.test(document.activeElement.tagName.toLowerCase()) || document.activeElement.getAttribute('contentEditable') === true):
  7150. return; // ignore editable textareas
  7151. default:
  7152. timer = timeoutID();
  7153. if (typeof timer === 'number') {
  7154. window.clearTimeout(timer);
  7155. timer = 0;
  7156. }
  7157. timeoutID(); // set timer for typed string
  7158. str += e.key.toLowerCase(); // define typed string
  7159. switch (true) {
  7160. case hasClass('#top_body', 'has_menu'): // navigate main menu
  7161. items = (getEls('#dir_menu_main > li.has_submenu.hovered').length > 0 ? getEls('#dir_menu_main > li.has_submenu.hovered li') : getEls('#dir_menu_main > li')); // get menu or submenu items
  7162. items = Array.from(items).filter(item => item.innerText.toLowerCase().startsWith(str)); // get menu items and filter items that match typed string
  7163. if (items.length > 0) {
  7164. item = items[0];
  7165. item?.parentNode.querySelector('.selected')?.classList.remove('selected');
  7166. item?.classList.add('selected');
  7167. }
  7168. break; // select if matching menu item found
  7169. default:
  7170. if (elExists('.dirlist_item[data-name^="' + str + '"]')) {
  7171. showThis(getEl('.dirlist_item[data-name^="' + str + '"]').id);
  7172. scrollThis('#directory_list', '.selected');
  7173. } // select dir_list item
  7174. }
  7175. }
  7176. }
  7177. // ===> END NAVIGATION
  7178. //============================//
  7179. // ===> TEXT EDITING
  7180. function TextEditing() { // ===> TEXT EDITING Function: create Markdown Preview
  7181. let raw_markdown = (elExists('#texteditor_txt_pane') ? getEl('#texteditor_txt_pane').value.toString() : '');
  7182. MDmarkdown(raw_markdown, getEl('#texteditor_html_pane'));
  7183. MDsetChecklistClass(); // set checklist class in case any added
  7184. }
  7185.  
  7186. function textareaSelectContent(id) {
  7187. let textarea_el = getEl('#' + id);
  7188. focusEl('#' + id);
  7189. textarea_el.select();
  7190. textarea_el.scrollTop = 0;
  7191. } // ===> SELECT TEXTAREA CONTENT
  7192. function texteditorClear() { // ===> CLEAR TEXT
  7193. if (!isTopWindow()) {
  7194. messageSend('top_body', 'iframe_edited');
  7195. addClass('body', 'texteditor_edited');
  7196. }
  7197. else {
  7198. removeClass('body', 'texteditor_edited');
  7199. }
  7200. getEl('#texteditor_txt_pane').value = '';
  7201. getEl('#texteditor_preview_pane').innerHTML = '';
  7202. getEl('#texteditor_html_pane').value = '';
  7203. getEl('#texteditor_txt_pane').style.width = '';
  7204. focusEl('#texteditor_txt_pane');
  7205. removeAttribute('#texteditor_preview_pane', 'srcdoc');
  7206. }
  7207.  
  7208. function texteditorSaveBtn(id) {
  7209. let data, file_name, ext = ''; // let Text_Files = Text_Files.map( item => '.'+item ); // ===> SAVE BUTTON
  7210. switch (true) {
  7211. case hasContent('texteditor'):
  7212. file_name = 'untitled';
  7213. break;
  7214. default:
  7215. file_name = decodeURIComponentSafe(window.location.pathname.split('/').reverse()[0]);
  7216. }
  7217. switch (true) {
  7218. case id === 'save_text':
  7219. data = getEl('#texteditor_txt_pane').value;
  7220. break; // if ( Text_Files.() ) { ext = '.md'; } break;
  7221. case id === 'save_HTML':
  7222. data = MDprepHTML(getEl('#texteditor_preview_pane').innerHTML);
  7223. ext = '.html';
  7224. break;
  7225. }
  7226. saveMD(data, file_name + ext);
  7227. }
  7228.  
  7229. function MDprepHTML(data) { // ===> MD PREP HTML for saving
  7230. let save_HTML_open = `<!DOCTYPE html><html><head><meta charset="utf-8" /><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">`,
  7231. save_HTML_close = '</body></html>';
  7232. data = data.replace(/<span\sclass="uplink">.<\/span>/g, '');
  7233. return save_HTML_open + data + save_HTML_close;
  7234. }
  7235.  
  7236. function saveMD(data, file_name) { // ===> SAVE MD
  7237. if (!isTopWindow()) {
  7238. messageSend('top_body', 'save_text', '', [data, file_name]);
  7239. }
  7240. else {
  7241. saveFile(data, 'text/plain', file_name);
  7242. } // #top_body must save text, else a new window opens containing blob content
  7243. removeClass('body,#texteditor_txt_pane,#content_texteditor', 'texteditor_edited');
  7244. }
  7245. // MD Custom pre- and post-processing for text.
  7246. function MDcustomPreProcess(src) {
  7247. return src;
  7248. } // ===> MD CUSTOM PREPROCESS (we're not doing anything here just yet...)
  7249. function MDcustomPostProcess(html) { // ===> MD CUSTOM POSTPROCESS
  7250. 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
  7251. .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
  7252. .replace(/<li><p class="checklist">"/g, '<li class="checklist"><p>');
  7253. return html;
  7254. }
  7255.  
  7256. function MDmarkdown(raw_markdown) { // ===> MDMARKDOWN: Render markdown from processed source text
  7257. const MDit = window.markdownit({
  7258. linkify: false,
  7259. typography: false,
  7260. html: true
  7261. }).use(window.markdownitMultimdTable, {
  7262. enableMultilineRows: true
  7263. })
  7264. .use(window.markdownitCheckbox).use(window.markdownitSub).use(window.markdownitSup).use(window.markdownitFootnote).use(window.markdownitCentertext).use(window.markdownitDeflist).use(window.markdownitTocDoneRight);
  7265. let MD_Preview = MDcustomPostProcess(MDit.render(MDcustomPreProcess(raw_markdown)));
  7266. let MD_script = `<style>body{margin:0;padding:0;}</style>`; // inline scripts to permit sync scrolling and focus
  7267. getEl('#texteditor_preview_pane').innerHTML = MD_script + MD_Preview; // set previewed text
  7268. let source_HTML = MD_Preview.toString();
  7269. getEl('#texteditor_html_pane').value = source_HTML; // set raw html view
  7270. }
  7271.  
  7272. function MDlivePreview() {
  7273. MDmarkdown(getEl('#texteditor_txt_pane').value);
  7274. MDsetChecklistClass();
  7275. } // ===> MD LIVE PREVIEW
  7276. function MDreplaceAt(str, replacement, position) {
  7277. str = str.substring(0, position) + replacement + str.substring(position + replacement.length);
  7278. return str;
  7279. }
  7280.  
  7281. function MDreplaceNthSubStr(str, substr, replacement, index) {
  7282. let count = 0,
  7283. found = substr.exec(str);
  7284. while (found !== null) {
  7285. if (count === index) {
  7286. return MDreplaceAt(str, replacement, found.index);
  7287. }
  7288. else {
  7289. count++;
  7290. found = substr.exec(str);
  7291. }
  7292. }
  7293. }
  7294.  
  7295. function MDliveCheckBoxes(checkbox, source_el, preview_el) { // ===> MD LIVE CHECKBOXES
  7296. removeClass('.checklist', 'clicked');
  7297. checkbox.closest('p,li,dt,dd').classList.add('clicked');
  7298. const this_index = preview_el.querySelector('.checklist').index(preview_el.querySelector('.checklist .clicked'));
  7299. const src_text = source_el.value;
  7300. const substr = new RegExp(/\[\s*.\s*\]/g);
  7301. const replacement = (checkbox.is(':checked') ? '[x]' : '[ ]');
  7302. source_el.value = MDreplaceNthSubStr(src_text, substr, replacement, this_index);
  7303. }
  7304.  
  7305. function MDsetChecklistClass() {
  7306. getEls('#text_container input[type="checkbox"]').forEach(el => el.closest('ul').style.cssText = 'list-style:none;padding:0;');
  7307. } // ===> MD SET CHECKBOX LIST CLASS
  7308. function texteditor_ResizeSplit() { // ===> MD RESIZE SPLIT VIEW
  7309. let page_width = window.innerWidth,
  7310. editor_width = getEl('#content_texteditor').offsetWidth,
  7311. editor_offsetLeft = (document.body.id === 'top_body' ? getEl('#content_pane').offsetLeft : 0);
  7312. document.onmousemove = function (e) {
  7313. eStopPrevent(e);
  7314. let pageX = e.pageX;
  7315. if (pageX > editor_offsetLeft + 150 && pageX < page_width - 150) { // min split pane widths
  7316. setStyle('#text_editing_handle', 'left', pageX - editor_offsetLeft - 4 + 'px');
  7317. setStyle('#texteditor_txt_pane', 'width', pageX - editor_offsetLeft + 'px');
  7318. setStyle('#texteditor_preview_pane', 'width', editor_width + editor_offsetLeft - pageX + 'px');
  7319. setStyle('#texteditor_html_pane', 'width', editor_width + editor_offsetLeft - pageX + 'px');
  7320. }
  7321. }
  7322. }
  7323.  
  7324. function texteditor_ResetSplit() {
  7325. getEls('#text_container .texteditor_pane,#text_editing_handle').forEach(el => el.removeAttribute('style'));
  7326. }
  7327.  
  7328. function texteditor_SyncScroll(e) { // ===> MD SYNC SCROLL
  7329. if (!getEl('input[name="texteditor_sync_scroll"').checked || hasClass('body', 'texteditor_split_view_false')) {
  7330. return;
  7331. } // ignore if no split or no sync scroll
  7332. let scrolled = e.currentTarget,
  7333. scrolled_scrollTop = scrolled.scrollTop,
  7334. scrolled_height = scrolled.scrollHeight,
  7335. scrolled_percentage = (scrolled_scrollTop / scrolled_height).toFixed(4);
  7336. let synced_id = ['texteditor_txt_pane', 'texteditor_preview_pane', 'texteditor_html_pane'].filter(el => el !== scrolled.id).filter(el => document.getElementById(el).offsetHeight > 0).toString();
  7337. let synced = document.getElementById(synced_id); // the element to be sync scrolled
  7338. synced.scrollTo(0, (scrolled_percentage * synced.scrollHeight).toFixed(0), {
  7339. behavior: 'smooth'
  7340. });
  7341. }
  7342.  
  7343. function MDtocClick(id) {
  7344. let thisId = getEl('#' + id).href;
  7345. if (thisId !== null) {
  7346. getEl('#texteditor_preview_pane').scrollTop = getEl('#' + id).offset().top - 48;
  7347. }
  7348. } // ===> MD TOC CLICK anchors
  7349. function MDheaderClick() { // ===> MD HEADER CLICK
  7350. switch (true) {
  7351. case elExists('#texteditor_preview_pane .table-of-contents'):
  7352. getEl('#texteditor_preview_pane').getElementsByClassName('table-of-contents')[0].scrollIntoView({
  7353. behavior: "smooth",
  7354. block: "nearest"
  7355. });
  7356. break;
  7357. default:
  7358. getEl('#texteditor_preview_pane').scroll(0, 0);
  7359. }
  7360. }
  7361. //***********************//
  7362. // MESSAGES
  7363. function messageSend(target, message, funcName, args) { // ===> SEND MESSAGE to iframe or parent
  7364. let messageObj = {
  7365. 'messageContent': message,
  7366. 'functionName': funcName,
  7367. 'arguments': args
  7368. };
  7369. switch (target) {
  7370. case 'iframe':
  7371. getEl('#content_iframe').contentWindow.postMessage(messageObj, '*');
  7372. break;
  7373. case 'top_body':
  7374. window.parent.postMessage(messageObj, '*');
  7375. break;
  7376. }
  7377. }
  7378.  
  7379. function messageReceive(e) { // ===> RECEIVE MESSAGE from iframe or parent, do appropriate action
  7380. if (e.data.messageContent === 'iframe_loaded') {
  7381. showThis('iframe_loaded', false, true, e.data.arguments);
  7382. }
  7383. else if (e.origin === 'null' || e.origin === origin) {
  7384. let message = e.data.messageContent,
  7385. args = e.data.arguments;
  7386. switch (message) {
  7387. case 'uiPrefToggle':
  7388. uiPrefToggle(args);
  7389. break;
  7390. case 'toggleIframeUIPref':
  7391. document.body.classList.toggle(args);
  7392. break;
  7393. case 'set_ui_font':
  7394. if (args !== '') {
  7395. document.body.style.fontFamily = args;
  7396. }
  7397. else {
  7398. document.body.style.fontFamily = null;
  7399. }
  7400. break; // set iframe ui font
  7401. case 'arrow_key_navigation':
  7402. removeClass('body', 'iframe_edited');
  7403. navigateByArrowKey(args);
  7404. break; // class_name, key
  7405. case 'iframe_navigation':
  7406. addClass('body', 'no_hover');
  7407. navigateByArrowKey(args);
  7408. break; // get first or last iframe dirlist item
  7409. case 'show_sidebar':
  7410. document.body.classList.toggle(getNewUIPref('show_sidebar')[0]);
  7411. break;
  7412. case 'toggle_menu':
  7413. menuShow(null, 'dir_menu_main_container');
  7414. messageSend('iframe', 'has_top_menu');
  7415. break; // show menu, tell iframe to allow menu arrow navigation
  7416. case 'menu_close':
  7417. menuClose();
  7418. break;
  7419. case 'has_top_menu':
  7420. addClass('#content_body', 'has_top_menu is_blurred');
  7421. break; // tell iframe top has menu to allow arrow navigation
  7422. case 'menu_selection':
  7423. case 'menuClick':
  7424. menuClick();
  7425. break; // show menu
  7426. case 'menu_navigation':
  7427. navigateByArrowKey(args);
  7428. break; // menu navigation from iframe
  7429. case 'toggle_invisibles':
  7430. getEl('#show_invisibles input').click();
  7431. getEl('#show_invisibles input').blur();
  7432. break;
  7433. case 'blur_top':
  7434. addClass('#top_body', 'focus_content');
  7435. break;
  7436. case 'focus_top': // close menus and refocus content or focus sidebar
  7437. switch (true) {
  7438. case hasClass('#top_body', 'focus_content') && hasClass('#top_body', 'has_menu'):
  7439. focusEl('#content_pane');
  7440. break;
  7441. default:
  7442. focusEl('#top_body');
  7443. break;
  7444. }
  7445. break;
  7446. case 'focus_iframe':
  7447. addClass('body', 'focus_content');
  7448. break; // focusEl('#content_iframe'); break;
  7449. case 'theme_light':
  7450. case 'theme_dark': // toggle iframe UI theme and iframe Text Editor theme
  7451. getEl('#content_body').classList.remove('theme_dark', 'theme_light');
  7452. getEl('#content_body').classList.add(message, 'texteditor_' + message);
  7453. break; // change iframe dir theme
  7454. case 'show_iframe_parent':
  7455. showThis('content_iframe_parent', false, true, args);
  7456. break; // args[0] === item link, args[1] === item kind
  7457. case 'show_iframe_dir':
  7458. showThis('content_iframe_dir', false, true, args);
  7459. break; // args[0] === item link, args[1] === item kind
  7460. case 'show_iframe_file':
  7461. showThis('content_iframe_file', false, true, args);
  7462. break; // args[0] === item link, args[1] === item kind
  7463. case 'select_iframe_item':
  7464. getEl('#' + args)?.classList.add('selected');
  7465. scrollThis('#directory_list', '.selected', false);
  7466. break;
  7467. case 'open_iframe_dir_in_sidebar':
  7468. window.location = args;
  7469. break; // tell top to open iframe directory in sidebar; args: iframe dir url
  7470. case 'open_iframe_parent_dir':
  7471. iframeClick(e, 'parent', 'link', getAttribute('#iframe_parent_link', 'href'));
  7472. break; // getEl('##parent').find('a').click();
  7473. case 'close':
  7474. clickThis('#close_btn');
  7475. break; // escape content_iframe and close content
  7476. case 'close_content':
  7477. showThis('close');
  7478. removeClass('body', 'iframe_edited');
  7479. focusEl('#top_body');
  7480. break; // close edited_iframe text after clicking "Save/Don't Save" buttons
  7481. case 'reload':
  7482. showWarning('resetContent');
  7483. break; // reload content
  7484. case 'resetContent':
  7485. showThis(getEl('.dirlist_item.content_loaded').id);
  7486. removeClass('body', 'iframe_edited');
  7487. break; // reload iframe content after "Save/Don't Save" buttons
  7488. case 'showThis':
  7489. removeClass('body', 'iframe_edited');
  7490. focusEl('#top_body');
  7491. showThis(args);
  7492. break; // show clicked/navigated sidebar item after "Save/Don't Save" buttons
  7493. case 'show_numbers':
  7494. case 'show_invisibles':
  7495. case 'alternate_background':
  7496. case 'show_ignored_items':
  7497. case 'ignore_ignored_items':
  7498. getEl('#content_body').classList.toggle(message);
  7499. break; // toggle iframe dir_list UI prefs from main menu:
  7500. case 'show_image_thumbnails':
  7501. uiPrefImgThumbsToggle();
  7502. break; // toggle image thumbnails in iframe
  7503. // AUDIO MESSAGES
  7504. case 'iframe_play_pause_media':
  7505. mediaPlayPause();
  7506. break; // tell top to play/pause audio from iframe click
  7507. case 'mediaSkip':
  7508. mediaSkip(undefined, args);
  7509. break; // tell top to mediaskip from focused iframe
  7510. case 'play_prev_next_iframe_audio':
  7511. mediaPlayPrevNextIframeItem(args);
  7512. break; // play next iframe track
  7513. case 'close_iframe_audio':
  7514. removeClass('.audio_loaded', 'audio_loaded');
  7515. break; // remove iframe audio loaded class
  7516. case 'set_media_duration':
  7517. setMediaDuration(args[0], args[1], args[2], true);
  7518. break; // set media durations for subdirs [id, item_sort_kind, duration]
  7519. case 'refresh_media_durations':
  7520. updateMediaDurations('refresh_media_durations');
  7521. break;
  7522. // TEXT EDITING MESSAGES
  7523. case 'navigateTabKeyFocus':
  7524. navigateTabKeyFocus(args[0], args[1]);
  7525. break; // args[0] = kind, args[1] = incr (tab:1,shift+tab:-1)
  7526. case 'texteditor_split_view':
  7527. uiPrefToggle('texteditor_split_view');
  7528. break;
  7529. case 'iframe_edited':
  7530. if (!hasClass('#top_body', 'iframe_edited')) {
  7531. addClass('#top_body', 'iframe_edited');
  7532. }
  7533. break; // let top know iframe text has been edited
  7534. case 'texteditor_toolbar_button':
  7535. if (!isTopWindow()) {
  7536. document.body.classList.toggle(args);
  7537. }
  7538. else {
  7539. uiPrefToggle(args);
  7540. }
  7541. break;
  7542. case 'clear':
  7543. addClass('#top_body', 'iframe_edited');
  7544. break; // add edited class after clearing text from edited iframe file
  7545. case 'save_text':
  7546. removeClass('body', 'iframe_edited');
  7547. saveFile(args[0], 'text/plain', args[1]);
  7548. break;
  7549. case 'iframe_text_saved':
  7550. removeClass('body', 'iframe_edited');
  7551. break;
  7552. case 'toggle_texteditor':
  7553. showTextEditor(true);
  7554. break;
  7555. case 'unloading':
  7556. showWarning('closeContent', args);
  7557. break; // show unsaved changes warning in iframe
  7558. case 'reloading':
  7559. showWarning('resetContent');
  7560. break;
  7561. case 'iframe_loaded':
  7562. showThis('iframe_loaded', false, true, args);
  7563. break; // args = [iframe_src,file_name,kind,content]
  7564. case 'dirlist_subdir_loaded':
  7565. subDirInsert(args);
  7566. break; // when subdirs processed, insert subdirs in dirlist
  7567. case 'show_texteditor_preview':
  7568. showTexteditorPreview(args);
  7569. break; // only show previewed text for certain files (e.g., webloc, url)
  7570. // OTHERS
  7571. case 'local_link':
  7572. showWarning('warning_local_file');
  7573. break; // local link warning
  7574. case 'iframe_playlist': // iframe_playlist
  7575. getEls('.dirlist_item.text').forEach(el => el.removeAttribute('data-playlist'));
  7576. removeClass('.dirlist_item.text', 'playlist');
  7577. if (elExists('.dirlist_item.text.selected')) {
  7578. getEl('.dirlist_item.text.selected').dataset.playlist = args;
  7579. }
  7580. addClass('.dirlist_item.text.selected', 'playlist');
  7581. break;
  7582. case 'setIframePlayerStatus': // for iframe audio playback
  7583. if (args === 'play') {
  7584. removeClass('body', 'is_paused');
  7585. addClass('body', 'is_playing');
  7586. }
  7587. else {
  7588. removeClass('body', 'is_playing');
  7589. addClass('body', 'is_paused');
  7590. }
  7591. break;
  7592. }
  7593. }
  7594. }
  7595.  
  7596. // END MESSAGES
  7597. //============================//
  7598. // WARNINGS
  7599. function doFunction(funcName, args) { // ===> DO FUNCTION
  7600. let funcDictionary = {
  7601. 'navigateByArrowKey': navigateByArrowKey,
  7602. 'showThis': showThis,
  7603. 'dirOpen': dirOpen,
  7604. 'null': null,
  7605. 'menuClick': menuClick,
  7606. 'clickThis': clickThis,
  7607. 'texteditorClear': texteditorClear,
  7608. 'closeContent': closeContent,
  7609. 'showFont': showFont,
  7610. 'showFontGlyph': showFontGlyph,
  7611. 'mediaSkip': mediaSkip,
  7612. 'openSidebarInContentPane': openSidebarInContentPane,
  7613. 'resetContent': resetContent,
  7614. 'setLocation': setLocation,
  7615. 'showDirectorySource': showDirectorySource,
  7616. 'uiPrefToggle': uiPrefToggle,
  7617. 'openInTextEditor': openInTextEditor,
  7618. 'playlistMake': playlistMake,
  7619. 'changeLocation': changeLocation
  7620. }; // list of functions to remember and execute after warning button click
  7621. return funcName === 'null' ? null : funcDictionary[funcName](args); // return the function and call it with args
  7622. }
  7623.  
  7624. function showWarning(funcName, args) { // ===> SHOW WARNING
  7625. switch (true) {
  7626. case funcName === null:
  7627. break;
  7628. case (/warning_make_playlist/.test(funcName)):
  7629. getEls('#directories_only,#files_only,#audio_files_only,#video_files_only,#media_files_only,#all_non_media_files').forEach(el => el.removeAttribute('disabled')); // setup makeplaylist alert
  7630. if (getEl('.dirlist_item.dir') === null) {
  7631. getEl('#directories_only').disabled = 'disabled';
  7632. }
  7633. if (getEl('.dirlist_item.file') === null) {
  7634. getEl('#files_only').disabled = 'disabled';
  7635. }
  7636. if (!hasClass('body', 'has_audio')) {
  7637. getEl('#audio_files_only').disabled = 'disabled';
  7638. }
  7639. if (!hasClass('body', 'has_video')) {
  7640. getEl('#video_files_only').disabled = 'disabled';
  7641. }
  7642. if (!hasClass('body', 'has_media')) {
  7643. getEl('#media_files_only').disabled = 'disabled';
  7644. }
  7645. if (getEl('.dirlist_item.non_media') === null) {
  7646. getEl('#all_non_media_files').disabled = 'disabled';
  7647. }
  7648. openWarning('warning_make_playlist', ['warning_btn_ok', 'warning_btn_cancel'], 'playlistMake', args);
  7649. break; // make playlist/filelist
  7650. case (/open_font|open_playlist|close_font|close_playlist/.test(funcName)): // close playlist or font file; args === close_font, close_playlist; if funcName[close_] === args, close item, else open file
  7651. openWarning('warning_' + args, ['warning_btn_cancel', 'warning_btn_ok'], funcName, args);
  7652. break;
  7653. case (/texteditorClear/.test(funcName)):
  7654. openWarning('warning_clear_text', ['warning_btn_ok', 'warning_btn_save', 'warning_btn_cancel'], funcName);
  7655. break;
  7656. case (/non_local_file/.test(funcName)):
  7657. openWarning('warning_non_local_file', ['warning_btn_ok', 'warning_btn_cancel'], null, args);
  7658. break;
  7659. case (/local_file/.test(funcName)):
  7660. openWarning('warning_local_file', ['warning_btn_ok']);
  7661. break;
  7662. case (/showThis|closeContent|resetContent|changeLocation|setLocation/.test(funcName)): // warnings for various cases
  7663. switch (true) {
  7664. case !isTopWindow():
  7665. switch (true) {
  7666. case args?.length === 2:
  7667. openWarning('unloading', ['warning_btn_save', 'warning_btn_dont_save', 'warning_btn_cancel'], args[0], args[1]);
  7668. break; // iframe edited warning for dirlist_item click
  7669. default:
  7670. openWarning('unloading', ['warning_btn_save', 'warning_btn_dont_save', 'warning_btn_cancel'], funcName, args); // iframe unload warning for close/resetContent
  7671. }
  7672. break;
  7673. default:
  7674. doFunction(funcName, [args]);
  7675. break; // default: perform the requested function w/o warning
  7676. }
  7677. break;
  7678. default:
  7679. switch (true) {
  7680. case hasClass('body', 'iframe_edited'):
  7681. messageSend('iframe', 'unloading', funcName, args);
  7682. break; // send unloading message for closeContent or resetContent
  7683. case hasClass('body', 'texteditor_edited') && !/navigateByArrowKey|uiPrefToggle/.test(funcName):
  7684. case funcName === 'texteditorClear':
  7685. if (isTopWindow()) {
  7686. removeClass('#content_pane', 'has_hidden_texteditor');
  7687. getEl('#content_pane').dataset.content = 'has_texteditor';
  7688. }
  7689. openWarning('texteditorClear', ['warning_btn_save', 'warning_btn_dont_save', 'warning_btn_cancel']);
  7690. break;
  7691. default:
  7692. doFunction(funcName, args);
  7693. break;
  7694. }
  7695. }
  7696. }
  7697.  
  7698. function openWarning(id, buttonids, funcName, args) { // ===> OPEN WARNING
  7699. addClass('body', 'has_warning');
  7700. removeAttribute('#warnings_container', 'class');
  7701. addClass('#warnings_container', id);
  7702. addClass('#' + id, 'show');
  7703. buttonids.forEach(el => addClass('#' + el, 'show')); // show warning buttons and message
  7704. getEl('#' + buttonids[0]).classList.add('focus'); // focus default warning button
  7705. if (funcName !== undefined) {
  7706. getEl('#warnings_container').dataset.funcname = funcName;
  7707. } // store funcName and args to complete after clicking warning button
  7708. if (args !== undefined) {
  7709. getEl('#warnings_container').dataset.args = args;
  7710. }
  7711. }
  7712.  
  7713. function closeWarning() { // ===> CLOSE WARNINGS
  7714. removeClass('body', 'has_warning');
  7715. getEls('#warnings_container .show,#warnings_container .focus').forEach(el => el.classList.remove('show', 'focus'));
  7716. removeAttribute('#warnings_container', ['class', 'data-funcname']);
  7717. }
  7718.  
  7719. function warningButtons(id) { // ===> WARNING BUTTONs: what to do after warning button click
  7720. let funcName = getEl('#warnings_container').dataset.funcname || '',
  7721. args = getEl('#warnings_container').dataset.args || '';
  7722. switch (id) {
  7723. case 'warning_btn_save': // Save/Don't Save Buttons
  7724. switch (true) { // After clicking Save/Don't Save Button...
  7725. case !isTopWindow():
  7726. messageSend('top_body', getEl('#warnings_container').dataset.funcname, getEl('#warnings_container').dataset.funcname, [getEl('#warnings_container').dataset.args]);
  7727. break; // funcName to top
  7728. default:
  7729. removeClass('body', 'iframe_edited');
  7730. doFunction(funcName, args);
  7731. focusEl('#top_body'); // remove iframe_edited class; do the function, if any; focus sidebar
  7732. }
  7733. delete getEl('#warnings_container').dataset.funcname;
  7734. delete getEl('#warnings_container').dataset.args; // remove warnings_container data
  7735. if (id === 'warning_btn_save') {
  7736. getEl('#save_text_link').click();
  7737. }
  7738. break; // if id = save button, click save text link
  7739. case 'warning_btn_dont_save':
  7740. switch (true) {
  7741. case !isTopWindow():
  7742. messageSend('top_body', 'close_content');
  7743. break;
  7744. default:
  7745. doFunction(funcName, [args, 'ok']);
  7746. }
  7747. break;
  7748. case 'warning_btn_cancel':
  7749. switch (true) {
  7750. case isTopWindow():
  7751. if (hasClass('body', 'focus_content')) {
  7752. focusEl('#content_pane');
  7753. }
  7754. else {
  7755. focusEl('#top_body');
  7756. }
  7757. break; // Cancel Button
  7758. case !isTopWindow():
  7759. if (getEl('#warnings_container').dataset.args === 'warning_btn_save' && getEl('#warnings_container').dataset.funcname === 'closeContent') {
  7760. messageSend('top_body', 'close_content');
  7761. }
  7762. break;
  7763. }
  7764. break;
  7765. case 'warning_btn_clear':
  7766. texteditorClear();
  7767. break; // Clear text editor
  7768. case 'warning_btn_ok': // OK Button
  7769. switch (true) {
  7770. case hasClass('#warnings_container', 'warning_close_font'):
  7771. closeWarning();
  7772. openFontFile('close');
  7773. closeContent();
  7774. if (funcName !== args) {
  7775. getEl('#' + funcName).click();
  7776. }
  7777. return; // close font file, open file by funcName (if funcName !== args)
  7778. case hasClass('#warnings_container', 'warning_close_playlist'):
  7779. closeWarning();
  7780. closePlaylist();
  7781. closeContent();
  7782. if (funcName !== args) {
  7783. getEl('#' + funcName).click();
  7784. }
  7785. return; // close playlist, open file by funcName (e.g. close_playlist && open_font)
  7786. case hasClass('#warnings_container', 'warning_local_playlist'): // no break; local playlist
  7787. case hasClass('#warnings_container', 'warning_local_file'): // no break; local file
  7788. case hasClass('#warnings_container', 'warning_non_local_file'):
  7789. open(args, '_blank');
  7790. break; // no break; open non_local file in new window
  7791. }
  7792. doFunction(funcName, args);
  7793. break; // do the function, if any, after clicking OK button
  7794. }
  7795. closeWarning();
  7796. }
  7797. // END WARNINGS
  7798. //============================//
  7799. // FINIS! † DEO GRATIAS † //
  7800. })();