file_selector.html 164 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title locale="title">File Selector</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  7. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  8. <link rel="stylesheet" href="../../script/ao.css">
  9. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  10. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  11. <script type="text/javascript" src="../../script/ao_module.js"></script>
  12. <script type="text/javascript" src="../../script/applocale.js"></script>
  13. <!-- File icon / thumbnail logic shared with the File Manager -->
  14. <!-- Design tokens and components shared with the File Manager -->
  15. <link rel="stylesheet" href="shared/fs-theme.css">
  16. <link rel="stylesheet" href="shared/fs-components.css">
  17. <script type="text/javascript" src="shared/filethumb.js"></script>
  18. <style>
  19. /*
  20. ArozOS File Selector
  21. Redesigned dialog shell. Everything in here is scoped under #fsRoot
  22. so the Semantic UI base sheet (kept for ao_module compatibility)
  23. cannot bleed into the new layout.
  24. */
  25. html, body{
  26. height: 100%;
  27. margin: 0;
  28. padding: 0;
  29. overflow: hidden;
  30. background: #ffffff;
  31. }
  32. body.darkTheme{ background: #202124; }
  33. #fsRoot{
  34. /* Palette comes from shared/fs-theme.css */
  35. position: absolute;
  36. top: 0; left: 0; right: 0; bottom: 0;
  37. display: flex;
  38. flex-direction: column;
  39. background: var(--fs-bg);
  40. color: var(--fs-text);
  41. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", Roboto, Helvetica, Arial, sans-serif;
  42. font-size: 14px;
  43. -webkit-font-smoothing: antialiased;
  44. user-select: none;
  45. }
  46. #fsRoot *{
  47. box-sizing: border-box;
  48. }
  49. #fsRoot svg{
  50. display: block;
  51. width: 100%;
  52. height: 100%;
  53. }
  54. /* ---------- Title bar ---------- */
  55. .fsTitlebar{
  56. display: flex;
  57. align-items: center;
  58. gap: 9px;
  59. padding: 10px 12px 6px 14px;
  60. flex-shrink: 0;
  61. }
  62. .fsTitlebar .fsTitleIcon{
  63. width: 20px;
  64. height: 20px;
  65. color: var(--fs-accent);
  66. flex-shrink: 0;
  67. }
  68. .fsTitlebar .fsTitleText{
  69. font-size: 15px;
  70. font-weight: 600;
  71. flex-grow: 1;
  72. white-space: nowrap;
  73. overflow: hidden;
  74. text-overflow: ellipsis;
  75. }
  76. /* ---------- Navigation row ---------- */
  77. .fsNav{
  78. display: flex;
  79. align-items: center;
  80. gap: 8px;
  81. padding: 6px 14px 6px 14px;
  82. flex-shrink: 0;
  83. }
  84. .fsNavBtns{
  85. display: flex;
  86. align-items: center;
  87. gap: 4px;
  88. flex-shrink: 0;
  89. }
  90. .fsNavDivider{
  91. width: 1px;
  92. height: 18px;
  93. background: var(--fs-line);
  94. margin: 0 4px;
  95. }
  96. .fsPathbar{ flex-grow: 1; }
  97. .fsPathbar .fsPathIcon{
  98. width: 18px;
  99. height: 18px;
  100. color: var(--fs-icon);
  101. flex-shrink: 0;
  102. }
  103. .fsCrumbs{
  104. display: flex;
  105. align-items: center;
  106. gap: 2px;
  107. flex-grow: 1;
  108. min-width: 0;
  109. overflow: hidden;
  110. white-space: nowrap;
  111. }
  112. .fsCrumb{
  113. padding: 3px 7px;
  114. border-radius: 6px;
  115. cursor: pointer;
  116. color: var(--fs-text);
  117. font-size: 14px;
  118. max-width: 220px;
  119. overflow: hidden;
  120. text-overflow: ellipsis;
  121. white-space: nowrap;
  122. }
  123. .fsCrumb:hover{ background: var(--fs-fill); }
  124. .fsCrumb.last{ font-weight: 600; }
  125. .fsCrumbSep{
  126. color: var(--fs-text-faint);
  127. font-size: 13px;
  128. flex-shrink: 0;
  129. pointer-events: none;
  130. }
  131. .fsCrumbPad{
  132. flex-grow: 1;
  133. min-width: 14px;
  134. align-self: stretch;
  135. cursor: text;
  136. }
  137. #addressbar{
  138. display: none;
  139. flex-grow: 1;
  140. min-width: 0;
  141. border: none;
  142. outline: none;
  143. background: transparent;
  144. font-size: 14px;
  145. font-family: inherit;
  146. color: var(--fs-text);
  147. padding: 4px 2px;
  148. user-select: text;
  149. }
  150. .fsPathbar.editing .fsCrumbs{ display: none; }
  151. .fsPathbar.editing #addressbar{ display: block; }
  152. .fsSearch{
  153. width: 260px;
  154. flex-shrink: 0;
  155. padding-right: 10px;
  156. }
  157. .fsSearch input{
  158. flex-grow: 1;
  159. min-width: 0;
  160. border: none;
  161. outline: none;
  162. background: transparent;
  163. font-size: 14px;
  164. font-family: inherit;
  165. color: var(--fs-text);
  166. user-select: text;
  167. }
  168. .fsSearch .fsSearchIcon{
  169. width: 17px;
  170. height: 17px;
  171. color: var(--fs-text-dim);
  172. flex-shrink: 0;
  173. }
  174. /* ---------- Body ---------- */
  175. .fsBody{
  176. flex-grow: 1;
  177. display: flex;
  178. min-height: 0;
  179. border-top: 1px solid var(--fs-line);
  180. }
  181. /* ---------- Sidebar ---------- */
  182. .fsSidebar{
  183. flex: 0 0 auto;
  184. width: 200px;
  185. min-width: 200px;
  186. padding: 10px 8px 10px 10px;
  187. overflow-y: auto;
  188. overflow-x: hidden;
  189. background: var(--fs-bg);
  190. border-right: 1px solid var(--fs-line);
  191. }
  192. .fsSideTitle{
  193. font-size: 12px;
  194. color: var(--fs-text-faint);
  195. padding: 4px 8px;
  196. margin-top: 4px;
  197. }
  198. .fsSideTitle:first-child{ margin-top: 0; }
  199. .fsSideItem{
  200. display: flex;
  201. align-items: center;
  202. gap: 10px;
  203. padding: 5px 8px;
  204. border-radius: 7px;
  205. cursor: pointer;
  206. white-space: nowrap;
  207. overflow: hidden;
  208. }
  209. .fsSideItem:hover{ background: var(--fs-fill); }
  210. .fsSideItem.active{ background: var(--fs-accent-soft); color: var(--fs-accent-strong); }
  211. .fsSideItem .fsSideIcon{
  212. width: 20px;
  213. height: 20px;
  214. min-width: 20px;
  215. }
  216. .fsSideItem .fsSideLabel{
  217. overflow: hidden;
  218. text-overflow: ellipsis;
  219. }
  220. /* ---------- Sidebar splitter ---------- */
  221. /*
  222. Drag handle on the sidebar / file list boundary. It is pulled back
  223. over the sidebar border with negative margins, so widening the grab
  224. area does not push the panes apart.
  225. */
  226. .fsSplitter{
  227. flex: 0 0 auto;
  228. align-self: stretch;
  229. width: 7px;
  230. margin-left: -4px;
  231. margin-right: -3px;
  232. position: relative;
  233. z-index: 100;
  234. cursor: col-resize;
  235. background: transparent;
  236. transition: background-color 0.12s ease;
  237. }
  238. .fsSplitter:hover,
  239. .fsSplitter.dragging{
  240. background: var(--fs-accent);
  241. opacity: 0.5;
  242. }
  243. /*
  244. While dragging, the pointer keeps crossing the panes either side of
  245. the handle. Without this the cursor flickers back to the default and
  246. stray text gets selected on the way past.
  247. */
  248. body.fsResizing{
  249. cursor: col-resize;
  250. user-select: none;
  251. -webkit-user-select: none;
  252. }
  253. body.fsResizing *{
  254. cursor: col-resize !important;
  255. user-select: none;
  256. -webkit-user-select: none;
  257. }
  258. /* ---------- Main column ---------- */
  259. .fsMain{
  260. flex-grow: 1;
  261. display: flex;
  262. flex-direction: column;
  263. min-width: 0;
  264. }
  265. .fsToolbar{
  266. display: flex;
  267. align-items: center;
  268. gap: 8px;
  269. padding: 7px 12px;
  270. flex-shrink: 0;
  271. position: relative;
  272. }
  273. .fsViewToggle{
  274. display: flex;
  275. background: var(--fs-fill);
  276. border-radius: 8px;
  277. padding: 2px;
  278. gap: 2px;
  279. }
  280. .fsViewToggle button{
  281. width: 30px;
  282. height: 26px;
  283. border: none;
  284. background: transparent;
  285. border-radius: 6px;
  286. padding: 5px;
  287. color: var(--fs-icon);
  288. cursor: pointer;
  289. }
  290. .fsViewToggle button:hover{ background: var(--fs-fill-hover); }
  291. .fsViewToggle button.active{
  292. background: var(--fs-surface);
  293. color: var(--fs-accent);
  294. box-shadow: 0 1px 2px rgba(0,0,0,0.12);
  295. }
  296. .fsSortPill{
  297. height: 32px;
  298. border: 1px solid var(--fs-line);
  299. border-radius: 8px;
  300. display: flex;
  301. align-items: center;
  302. padding: 0 3px 0 10px;
  303. gap: 3px;
  304. background: var(--fs-surface);
  305. }
  306. .fsSortPill .fsSortLabel{
  307. color: var(--fs-text-dim);
  308. font-size: 12px;
  309. white-space: nowrap;
  310. }
  311. .fsSortPill select{
  312. border: none;
  313. outline: none;
  314. background: transparent;
  315. font-size: 14px;
  316. font-family: inherit;
  317. color: var(--fs-text);
  318. cursor: pointer;
  319. padding: 2px 2px;
  320. max-width: 130px;
  321. }
  322. .fsSortDir{
  323. width: 28px;
  324. height: 28px;
  325. min-width: 28px;
  326. border: none;
  327. background: transparent;
  328. border-radius: 6px;
  329. padding: 6px;
  330. color: var(--fs-icon);
  331. cursor: pointer;
  332. }
  333. .fsSortDir:hover{ background: var(--fs-fill); }
  334. .fsToolbarSpacer{ flex-grow: 1; }
  335. .fsMoreBtn{
  336. width: 32px;
  337. height: 32px;
  338. min-width: 32px;
  339. border: 1px solid var(--fs-line);
  340. background: var(--fs-surface);
  341. border-radius: 8px;
  342. padding: 7px;
  343. color: var(--fs-text);
  344. cursor: pointer;
  345. }
  346. .fsMoreBtn:hover{ background: var(--fs-fill); }
  347. .fsMoreBtn.active{ background: var(--fs-accent-soft); color: var(--fs-accent); border-color: transparent; }
  348. /* ---------- Inline rename ---------- */
  349. /* Both name labels clip to one line, the editor needs the room back */
  350. .fsTileName.editing{
  351. overflow: visible;
  352. text-overflow: clip;
  353. }
  354. .fsRowName.editing{
  355. flex-grow: 1;
  356. min-width: 0;
  357. overflow: visible;
  358. text-overflow: clip;
  359. }
  360. /* ---------- Content area ---------- */
  361. .fsContent{
  362. flex-grow: 1;
  363. display: flex;
  364. min-height: 0;
  365. }
  366. .fsFiles{
  367. flex-grow: 1;
  368. overflow: auto;
  369. min-width: 0;
  370. position: relative;
  371. }
  372. /* List view */
  373. .fsListHead{
  374. display: flex;
  375. align-items: center;
  376. padding: 0 14px 0 16px;
  377. height: 30px;
  378. border-bottom: 1px solid var(--fs-line);
  379. position: sticky;
  380. top: 0;
  381. background: var(--fs-bg);
  382. z-index: 5;
  383. }
  384. /*
  385. Column geometry is declared on the bare class names so the header
  386. cells (.fsCol) and the row cells (.fsCell) get identical boxes and
  387. stay vertically aligned with each other.
  388. */
  389. .colName,
  390. .colDate,
  391. .colType,
  392. .colSize{ padding-right: 10px; }
  393. .colName{ flex: 1 1 0%; min-width: 60px; }
  394. /*
  395. Fixed columns never shrink - fractional shrinking rounds differently
  396. in the header and in the rows and drifts them a pixel apart. When the
  397. file area gets too narrow a whole column is dropped instead, which
  398. keeps every width an exact integer in both containers.
  399. The widths come from custom properties that the header's resize
  400. grips set on #fileArea, so the header and every row pick up a
  401. dragged width from the same place.
  402. */
  403. .colDate{ flex: 0 0 var(--fs-col-date, 210px); }
  404. .colType{ flex: 0 0 var(--fs-col-type, 150px); }
  405. .colSize{ flex: 0 0 var(--fs-col-size, 110px); }
  406. /* Width driven by the file area itself, not the viewport, because the
  407. details pane takes its space away without changing the window size */
  408. #fileArea.narrow .colType{ display: none; }
  409. #fileArea.verynarrow .colDate{ display: none; }
  410. .fsListHead .fsCol{
  411. font-size: 13px;
  412. color: var(--fs-text-dim);
  413. cursor: pointer;
  414. display: flex;
  415. align-items: center;
  416. align-self: stretch;
  417. padding: 0;
  418. position: relative;
  419. }
  420. /* The hover pill lives on an inner span so it cannot alter the column box */
  421. .fsListHead .fsCol .fsColInner{
  422. display: inline-flex;
  423. align-items: center;
  424. gap: 5px;
  425. padding: 4px 6px;
  426. margin-left: -6px;
  427. border-radius: 6px;
  428. max-width: 100%;
  429. min-width: 0;
  430. }
  431. .fsListHead .fsCol .fsColInner:hover{ background: var(--fs-fill); }
  432. /* A column dragged narrower than its label clips the label, not the box */
  433. .fsListHead .fsCol .fsColLabel{
  434. overflow: hidden;
  435. text-overflow: ellipsis;
  436. white-space: nowrap;
  437. }
  438. /*
  439. Resize grip on a header cell's right edge, half over each of the two
  440. columns it separates. It outranks the next cell's hover pill, which
  441. reaches back over the boundary. The last column ends at the edge of
  442. the list, so it has nothing to trade width with and shows no grip.
  443. */
  444. .fsListHead .fsColGrip{
  445. position: absolute;
  446. top: 0;
  447. right: -4px;
  448. width: 8px;
  449. height: 100%;
  450. cursor: col-resize;
  451. z-index: 2;
  452. touch-action: none;
  453. }
  454. .fsListHead .fsCol:last-child .fsColGrip{ display: none; }
  455. .fsListHead .fsColGrip::after{
  456. content: "";
  457. position: absolute;
  458. top: 25%;
  459. left: 3px;
  460. width: 1px;
  461. height: 50%;
  462. background: var(--fs-line);
  463. }
  464. .fsListHead:hover .fsColGrip::after{ background: var(--fs-text-faint); }
  465. .fsListHead .fsColGrip:hover::after,
  466. .fsListHead .fsColGrip.dragging::after{
  467. top: 0;
  468. width: 2px;
  469. height: 100%;
  470. background: var(--fs-accent);
  471. }
  472. .fsListHead .fsCol .fsSortMark{
  473. width: 11px;
  474. height: 11px;
  475. min-width: 11px;
  476. color: var(--fs-text-dim);
  477. visibility: hidden;
  478. }
  479. .fsListHead .fsCol.sorted .fsSortMark{ visibility: visible; }
  480. .fsRow{
  481. display: flex;
  482. align-items: center;
  483. padding: 0 14px 0 16px;
  484. height: 38px;
  485. cursor: pointer;
  486. border-bottom: 1px solid var(--fs-line-soft);
  487. }
  488. .fsRow:hover{ background: var(--fs-row-hover); }
  489. /* Light fill plus a thin leading bar, so a run of selected rows stays
  490. readable instead of becoming one solid block of colour */
  491. .fsRow.selected{
  492. background: var(--fs-selected);
  493. }
  494. .fsRow.selected:hover{ background: var(--fs-selected-hover); }
  495. .fsRow.disabledObject{ opacity: 0.45; }
  496. .fsRow .fsCell{
  497. font-size: 14px;
  498. color: var(--fs-text-dim);
  499. overflow: hidden;
  500. text-overflow: ellipsis;
  501. white-space: nowrap;
  502. }
  503. .fsRow .fsCell.colName{
  504. display: flex;
  505. align-items: center;
  506. gap: 9px;
  507. color: var(--fs-text);
  508. }
  509. .fsRow .fsCell.colName .fsRowName{
  510. overflow: hidden;
  511. text-overflow: ellipsis;
  512. white-space: nowrap;
  513. }
  514. /* Grid view */
  515. .fsGrid{
  516. display: grid;
  517. grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
  518. gap: 10px;
  519. padding: 12px 14px;
  520. align-content: start;
  521. }
  522. .fsTile{
  523. border: 1px solid var(--fs-line);
  524. border-radius: 10px;
  525. padding: 8px;
  526. cursor: pointer;
  527. background: var(--fs-surface);
  528. transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  529. min-width: 0;
  530. }
  531. .fsTile:hover{ box-shadow: 0 2px 10px rgba(15,20,30,0.08); }
  532. /* A single soft border rather than the previous double ring */
  533. .fsTile.selected{
  534. border-color: var(--fs-selected-line);
  535. background: var(--fs-selected);
  536. }
  537. .fsTile.selected:hover{ background: var(--fs-selected-hover); }
  538. .fsTile.disabledObject{ opacity: 0.45; }
  539. .fsThumb{
  540. position: relative;
  541. height: 96px;
  542. border-radius: 7px;
  543. background: var(--fs-thumb-bg);
  544. display: flex;
  545. align-items: center;
  546. justify-content: center;
  547. overflow: hidden;
  548. margin-bottom: 7px;
  549. }
  550. /*
  551. Thumbnails are square while the preview box is landscape, so cover
  552. the whole box instead of letterboxing it. Anchoring to the top keeps
  553. the head of a document page in frame rather than its middle.
  554. */
  555. .fsThumb img.fsThumbImg{
  556. width: 100%;
  557. height: 100%;
  558. object-fit: cover;
  559. object-position: center top;
  560. display: none;
  561. border-radius: 7px;
  562. }
  563. .fsThumb img.fsThumbImg.loaded{ display: block; }
  564. .fsThumb .fsBigIcon{
  565. width: 56px;
  566. height: 56px;
  567. }
  568. .fsThumb.hasThumb .fsBigIcon{ display: none; }
  569. .fsAppBadge{
  570. position: absolute;
  571. right: 6px;
  572. bottom: 6px;
  573. width: 22px;
  574. height: 22px;
  575. border-radius: 5px;
  576. background: var(--fs-surface);
  577. box-shadow: 0 1px 4px rgba(15,20,30,0.25);
  578. padding: 1px;
  579. display: none;
  580. }
  581. .fsAppBadge img{ width: 100%; height: 100%; object-fit: contain; }
  582. .fsTileName{
  583. font-size: 13px;
  584. color: var(--fs-text);
  585. overflow: hidden;
  586. text-overflow: ellipsis;
  587. white-space: nowrap;
  588. margin-bottom: 2px;
  589. }
  590. .fsTileMeta{
  591. font-size: 11px;
  592. color: var(--fs-text-faint);
  593. display: flex;
  594. align-items: center;
  595. gap: 5px;
  596. min-height: 16px;
  597. }
  598. .fsTileMeta .fsTileMetaText{
  599. overflow: hidden;
  600. text-overflow: ellipsis;
  601. white-space: nowrap;
  602. flex-grow: 1;
  603. line-height: 1.5;
  604. }
  605. .fsTileMore{
  606. width: 20px;
  607. height: 20px;
  608. min-width: 20px;
  609. border: none;
  610. background: transparent;
  611. border-radius: 5px;
  612. padding: 3px;
  613. color: var(--fs-text-faint);
  614. cursor: pointer;
  615. }
  616. .fsTileMore:hover{ background: var(--fs-fill); color: var(--fs-text); }
  617. /* Empty / loading state */
  618. .fsPlaceholder{
  619. position: absolute;
  620. top: 0; left: 0; right: 0; bottom: 0;
  621. display: none;
  622. flex-direction: column;
  623. align-items: center;
  624. justify-content: center;
  625. gap: 10px;
  626. color: var(--fs-text-faint);
  627. pointer-events: none;
  628. }
  629. .fsPlaceholder.show{ display: flex; }
  630. .fsPlaceholder .fsPlaceholderIcon{
  631. width: 42px;
  632. height: 42px;
  633. opacity: 0.5;
  634. }
  635. /* ---------- Details panel ---------- */
  636. .fsDetails{
  637. width: 264px;
  638. min-width: 264px;
  639. border-left: 1px solid var(--fs-line);
  640. display: none;
  641. flex-direction: column;
  642. overflow: hidden;
  643. }
  644. .fsDetails.open{ display: flex; }
  645. .fsDetailsHead{
  646. display: flex;
  647. align-items: center;
  648. padding: 9px 9px 9px 14px;
  649. flex-shrink: 0;
  650. }
  651. .fsDetailsHead .fsDetailsTitle{
  652. font-size: 14px;
  653. font-weight: 600;
  654. flex-grow: 1;
  655. }
  656. .fsDetailsBody{
  657. flex-grow: 1;
  658. overflow-y: auto;
  659. padding: 2px 14px 14px 14px;
  660. }
  661. .fsDetailsPreview{
  662. display: flex;
  663. align-items: center;
  664. justify-content: center;
  665. height: 124px;
  666. margin-bottom: 10px;
  667. position: relative;
  668. }
  669. /* The details preview shows the whole image, so it keeps letterboxing */
  670. .fsDetailsPreview img.fsThumbImg{
  671. max-width: 100%;
  672. max-height: 100%;
  673. width: auto;
  674. height: auto;
  675. object-fit: contain;
  676. display: none;
  677. border-radius: 5px;
  678. box-shadow: 0 2px 10px rgba(15,20,30,0.2);
  679. }
  680. .fsDetailsPreview img.fsThumbImg.loaded{ display: block; }
  681. .fsDetailsPreview .fsBigIcon{ width: 74px; height: 74px; }
  682. .fsDetailsPreview.hasThumb .fsBigIcon{ display: none; }
  683. .fsDetailsName{
  684. text-align: center;
  685. font-size: 14px;
  686. font-weight: 600;
  687. margin-bottom: 12px;
  688. word-break: break-all;
  689. user-select: text;
  690. }
  691. .fsDetailRow{
  692. display: flex;
  693. align-items: flex-start;
  694. gap: 10px;
  695. padding: 6px 0;
  696. border-top: 1px solid var(--fs-line-soft);
  697. font-size: 12.5px;
  698. }
  699. .fsDetailRow .fsDetailKey{
  700. color: var(--fs-text-dim);
  701. width: 78px;
  702. min-width: 78px;
  703. }
  704. .fsDetailRow .fsDetailVal{
  705. flex-grow: 1;
  706. color: var(--fs-text);
  707. word-break: break-all;
  708. user-select: text;
  709. display: flex;
  710. align-items: center;
  711. gap: 7px;
  712. }
  713. .fsDetailRow .fsDetailVal img.fsOpenerIcon{
  714. width: 18px;
  715. height: 18px;
  716. object-fit: contain;
  717. flex-shrink: 0;
  718. }
  719. .fsDetailsEmpty{
  720. text-align: center;
  721. color: var(--fs-text-faint);
  722. padding-top: 60px;
  723. font-size: 13px;
  724. }
  725. /* ---------- Footer ---------- */
  726. .fsFooter{
  727. display: flex;
  728. align-items: center;
  729. gap: 10px;
  730. padding: 10px 14px;
  731. border-top: 1px solid var(--fs-line);
  732. flex-shrink: 0;
  733. flex-wrap: wrap;
  734. }
  735. .fsFooterLabel{
  736. font-size: 14px;
  737. color: var(--fs-text);
  738. white-space: nowrap;
  739. }
  740. .fsFooter #filename{
  741. flex-grow: 1;
  742. min-width: 120px;
  743. height: 34px;
  744. border: 1px solid var(--fs-line);
  745. border-radius: 8px;
  746. padding: 0 10px;
  747. font-size: 14px;
  748. font-family: inherit;
  749. color: var(--fs-text);
  750. outline: none;
  751. background: var(--fs-surface);
  752. user-select: text;
  753. }
  754. .fsFooter #filename:focus{ border-color: var(--fs-accent); }
  755. .fsFooter #filterSelect{
  756. height: 34px;
  757. min-width: 132px;
  758. max-width: 190px;
  759. border: 1px solid var(--fs-line);
  760. border-radius: 8px;
  761. padding: 0 6px 0 10px;
  762. font-size: 14px;
  763. font-family: inherit;
  764. color: var(--fs-text);
  765. background: var(--fs-surface);
  766. outline: none;
  767. cursor: pointer;
  768. }
  769. /* ---------- Right click menu ---------- */
  770. /*
  771. Matches the File Manager's #contextmenu (file_explorer.css): the label
  772. carries the row and a muted Semantic UI glyph sits at the trailing edge,
  773. with no glyph at all on the rows the File Manager leaves bare.
  774. Scoped to the context menu, so the toolbar dropdown (#moreMenu) keeps
  775. its leading icons - the same split the File Manager draws between its
  776. right click menu and its "more" menu.
  777. */
  778. #fsRoot #contextMenu{ min-width: 250px; }
  779. #fsRoot #contextMenu .fsMenuItem{
  780. gap: 7px;
  781. padding: 5px 7px;
  782. color: var(--fs-text);
  783. }
  784. /* Label takes up the slack, so the trailing glyph is always right aligned */
  785. #fsRoot #contextMenu .fsMenuItem > span{ flex-grow: 1; }
  786. /*
  787. The colour needs !important: ao.css styles every <i> under a themed
  788. body with a blanket rule whose :not() chain scores higher than any
  789. reasonable selector here, so it would otherwise repaint the glyph to
  790. the label colour and flatten the two-tone look.
  791. */
  792. #fsRoot #contextMenu .fsMenuItem > i.icon{
  793. width: 16px;
  794. min-width: 16px;
  795. height: auto;
  796. margin: 0 0 0 auto;
  797. font-size: 14px;
  798. text-align: center;
  799. color: var(--fs-icon) !important;
  800. opacity: 0.6;
  801. }
  802. /* ---------- Sidebar overlay (narrow windows) ---------- */
  803. .fsScrim{
  804. position: absolute;
  805. top: 0; left: 0; right: 0; bottom: 0;
  806. background: rgba(15,20,30,0.25);
  807. z-index: 190;
  808. display: none;
  809. }
  810. .fsScrim.show{ display: block; }
  811. #sidebarToggleBtn{ display: none; }
  812. /* Hide the details pane and search box when there is no room for them */
  813. @media only screen and (max-width: 900px){
  814. .fsSearch{ width: 180px; }
  815. .fsDetails{ display: none !important; }
  816. }
  817. @media only screen and (max-width: 820px){
  818. /* Drop the label before the footer controls are forced to wrap */
  819. .fsFooterLabel{ display: none; }
  820. }
  821. @media only screen and (max-width: 720px){
  822. .fsSearch{ display: none; }
  823. }
  824. @media only screen and (max-width: 560px){
  825. #sidebarToggleBtn{ display: block; }
  826. .fsSidebar{
  827. position: absolute;
  828. z-index: 200;
  829. top: 0;
  830. bottom: 0;
  831. left: 0;
  832. box-shadow: 6px 0 24px rgba(15,20,30,0.18);
  833. display: none;
  834. }
  835. .fsSidebar.open{ display: block; }
  836. /* The drawer floats over the file list, so there is no edge to drag */
  837. .fsSplitter{ display: none !important; }
  838. .fsFooter{ padding: 10px 12px; gap: 8px; }
  839. .fsBtn{ min-width: 78px; padding: 0 12px; }
  840. .fsListHead{ padding-left: 14px; padding-right: 12px; }
  841. .fsRow{ padding-left: 14px; padding-right: 12px; }
  842. }
  843. /* ---------- Dark theme ---------- */
  844. /* Palette lives in shared/fs-theme.css, keyed on body.darkTheme. */
  845. body.darkTheme #fsRoot .fsViewToggle button.active{ box-shadow: 0 1px 2px rgba(0,0,0,0.5); }
  846. body.darkTheme #fsRoot .fsTile:hover{ box-shadow: 0 2px 10px rgba(0,0,0,0.45); }
  847. /* ---------- Blocking loader (selection hand-off) ---------- */
  848. #waitloader{
  849. position: absolute;
  850. top: 0; left: 0; right: 0; bottom: 0;
  851. background: var(--fs-overlay);
  852. z-index: 900;
  853. display: none;
  854. flex-direction: column;
  855. align-items: center;
  856. justify-content: center;
  857. gap: 14px;
  858. color: var(--fs-text-dim);
  859. text-align: center;
  860. padding: 20px;
  861. }
  862. #waitloader.show{ display: flex; }
  863. /* ---------- Replace prompt (new file mode) ---------- */
  864. /*
  865. Asked before a new file is written over an existing one. An in-page
  866. dialog rather than confirm(): it follows the theme, and answering
  867. "no" leaves the user in the selector to type another name.
  868. */
  869. .fsModalScrim{
  870. position: absolute;
  871. top: 0; left: 0; right: 0; bottom: 0;
  872. z-index: 950;
  873. display: none;
  874. align-items: center;
  875. justify-content: center;
  876. padding: 16px;
  877. background: rgba(15,20,30,0.28);
  878. }
  879. body.darkTheme .fsModalScrim{ background: rgba(0,0,0,0.5); }
  880. .fsModalScrim.show{ display: flex; }
  881. .fsModal{
  882. width: 380px;
  883. max-width: 100%;
  884. background: var(--fs-surface);
  885. border: 1px solid var(--fs-line);
  886. border-radius: 12px;
  887. box-shadow: 0 12px 36px var(--fs-shadow);
  888. padding: 18px 18px 14px 18px;
  889. }
  890. .fsModalHead{
  891. display: flex;
  892. align-items: center;
  893. gap: 10px;
  894. margin-bottom: 12px;
  895. }
  896. /* !important for the same reason as the context menu glyphs above:
  897. ao.css repaints every div under a themed body in the text colour */
  898. .fsModalIcon{
  899. width: 22px;
  900. height: 22px;
  901. min-width: 22px;
  902. color: #e37400 !important;
  903. }
  904. body.darkTheme .fsModalIcon{ color: #fdd663 !important; }
  905. .fsModalTitle{
  906. font-size: 15px;
  907. font-weight: 600;
  908. color: var(--fs-text);
  909. }
  910. .fsModalFile{
  911. display: flex;
  912. align-items: center;
  913. gap: 9px;
  914. padding: 8px 10px;
  915. border-radius: 8px;
  916. background: var(--fs-fill);
  917. margin-bottom: 10px;
  918. }
  919. .fsModalFile .fsModalFileName{
  920. overflow: hidden;
  921. text-overflow: ellipsis;
  922. white-space: nowrap;
  923. color: var(--fs-text);
  924. }
  925. .fsModalText{
  926. font-size: 13px;
  927. line-height: 1.5;
  928. color: var(--fs-text-dim);
  929. }
  930. .fsModalFoot{
  931. display: flex;
  932. justify-content: flex-end;
  933. gap: 8px;
  934. margin-top: 16px;
  935. }
  936. .fsModal .fsBtn:focus-visible{
  937. outline: 2px solid var(--fs-accent);
  938. outline-offset: 2px;
  939. }
  940. </style>
  941. </head>
  942. <body>
  943. <div id="fsRoot">
  944. <!-- Title bar (shown only outside the ArozOS float window, which draws its own) -->
  945. <div class="fsTitlebar" id="fsTitlebar">
  946. <div class="fsTitleIcon" id="fsTitleIcon"></div>
  947. <div class="fsTitleText" locale="title">File Selector</div>
  948. <button class="fsCloseBtn" id="fsCloseBtn" title="Close" onclick="closeSelector();"></button>
  949. </div>
  950. <!-- Navigation -->
  951. <div class="fsNav">
  952. <div class="fsNavBtns">
  953. <button id="sidebarToggleBtn" class="fsIconBtn" title="Menu" onclick="toggleSidebar();"></button>
  954. <button id="backBtn" class="fsIconBtn" title="Back" onclick="backDir();"></button>
  955. <button id="forwardBtn" class="fsIconBtn" title="Forward" onclick="forwardDir();"></button>
  956. <div class="fsNavDivider"></div>
  957. <button id="upBtn" class="fsIconBtn" title="Parent" onclick="parentDir();"></button>
  958. </div>
  959. <div class="fsPill fsPathbar" id="pathbar" onclick="onPathbarClick(event);">
  960. <div class="fsPathIcon" id="pathIcon"></div>
  961. <div class="fsCrumbs" id="breadcrumb"></div>
  962. <input id="addressbar" type="text" spellcheck="false" autocomplete="off">
  963. <button class="fsIconBtn" id="refreshBtn" title="Refresh" style="width:30px;height:30px;min-width:30px;padding:7px;background:transparent;" onclick="event.stopPropagation();refresh();"></button>
  964. </div>
  965. <div class="fsPill fsSearch">
  966. <input id="searchInput" type="text" spellcheck="false" autocomplete="off" placeholder="Search">
  967. <div class="fsSearchIcon" id="searchIcon"></div>
  968. </div>
  969. </div>
  970. <!-- Body -->
  971. <div class="fsBody">
  972. <div class="fsScrim" id="sidebarScrim" onclick="toggleSidebar();"></div>
  973. <div class="fsSidebar" id="sidebar">
  974. <div class="fsSideTitle" locale="sidebar/quickaccess">Quick Access</div>
  975. <div id="userlist"></div>
  976. <div class="fsSideTitle" locale="sidebar/devices">Devices</div>
  977. <div id="storagelist"></div>
  978. </div>
  979. <!-- Drag handle between the sidebar and the file list, desktop layout only -->
  980. <div class="fsSplitter" id="sidebarSplitter" title="Resize"></div>
  981. <div class="fsMain">
  982. <div class="fsToolbar">
  983. <div class="fsViewToggle">
  984. <button id="viewListBtn" title="List View" onclick="setViewMode('list');"></button>
  985. <button id="viewGridBtn" title="Grid View" onclick="setViewMode('grid');"></button>
  986. </div>
  987. <div class="fsSortPill">
  988. <span class="fsSortLabel" locale="toolbar/sort">Sort:</span>
  989. <select id="sortSelect" onchange="setSortField(this.value);">
  990. <option value="name" locale="sort/name">Name</option>
  991. <option value="date" locale="sort/date">Date Modified</option>
  992. <option value="type" locale="sort/type">Type</option>
  993. <option value="size" locale="sort/size">Size</option>
  994. </select>
  995. <button class="fsSortDir" id="sortDirBtn" title="Sort Direction" onclick="toggleSortDirection();"></button>
  996. </div>
  997. <div class="fsToolbarSpacer"></div>
  998. <button class="fsMoreBtn" id="moreBtn" title="More Options" onclick="toggleMoreMenu(event);"></button>
  999. <div class="fsMenu" id="moreMenu" style="right: 14px; top: 50px;">
  1000. <div class="fsMenuItem" onclick="menuNewFolder();">
  1001. <span class="fsMenuIcon" data-icon="folderPlus"></span>
  1002. <span locale="menu/newfolder">New Folder</span>
  1003. </div>
  1004. <div class="fsMenuSep"></div>
  1005. <div class="fsMenuItem" id="menuDetails" onclick="toggleDetailsPanel();">
  1006. <span class="fsMenuIcon" data-icon="info"></span>
  1007. <span locale="menu/details">Details Pane</span>
  1008. <span class="fsMenuCheck" data-icon="check"></span>
  1009. </div>
  1010. <div class="fsMenuItem" id="menuHidden" onclick="toggleHiddenFiles();">
  1011. <span class="fsMenuIcon" data-icon="eye"></span>
  1012. <span locale="menu/hidden">Show Hidden Files</span>
  1013. <span class="fsMenuCheck" data-icon="check"></span>
  1014. </div>
  1015. </div>
  1016. </div>
  1017. <div class="fsContent">
  1018. <div class="fsFiles" id="fileArea" oncontextmenu="showFolderContextMenu(event);">
  1019. <div class="fsPlaceholder" id="loadingPlaceholder">
  1020. <div class="fsSpinner"></div>
  1021. <div locale="message/loading">Loading</div>
  1022. </div>
  1023. <div class="fsPlaceholder" id="emptyPlaceholder">
  1024. <div class="fsPlaceholderIcon" data-icon="folderOpen"></div>
  1025. <div locale="message/nofile">No file</div>
  1026. </div>
  1027. </div>
  1028. <div class="fsDetails" id="detailsPanel">
  1029. <div class="fsDetailsHead">
  1030. <div class="fsDetailsTitle" locale="details/title">Details</div>
  1031. <button class="fsCloseBtn" onclick="toggleDetailsPanel();" title="Close"></button>
  1032. </div>
  1033. <div class="fsDetailsBody" id="detailsBody">
  1034. <div class="fsDetailsEmpty" locale="details/empty">Select an item to see its details</div>
  1035. </div>
  1036. </div>
  1037. </div>
  1038. </div>
  1039. </div>
  1040. <!-- Footer -->
  1041. <div class="fsFooter">
  1042. <span class="fsFooterLabel" id="filenameLabel" locale="footer/filename">File name(N):</span>
  1043. <input id="filename" type="text" spellcheck="false" autocomplete="off" placeholder="New Filename">
  1044. <select id="filterSelect" onchange="renderFileList();"></select>
  1045. <button class="fsBtn" onclick="closeSelector();" locale="footer/cancel">Cancel</button>
  1046. <button class="fsBtn primary" id="confirmBtn" onclick="confirmSelection();" locale="footer/open">Open</button>
  1047. </div>
  1048. <!-- Right click menu, contents are rebuilt per target -->
  1049. <div class="fsMenu fsContextMenu" id="contextMenu"></div>
  1050. <div id="waitloader">
  1051. <div class="fsSpinner"></div>
  1052. <div id="waitloadertext" locale="message/waitingResp">Waiting Response</div>
  1053. </div>
  1054. <!-- New file mode: asks before an existing file is replaced, see confirmOverwrite() -->
  1055. <div class="fsModalScrim" id="overwriteDialog" onclick="if (event.target == this){ answerOverwrite(false); }">
  1056. <div class="fsModal" role="alertdialog" aria-modal="true" aria-labelledby="overwriteTitle" aria-describedby="overwriteText">
  1057. <div class="fsModalHead">
  1058. <div class="fsModalIcon" data-icon="warning"></div>
  1059. <div class="fsModalTitle" id="overwriteTitle" locale="overwrite/title">Replace existing file?</div>
  1060. </div>
  1061. <div class="fsModalFile" id="overwriteFile"></div>
  1062. <div class="fsModalText" id="overwriteText" locale="overwrite/message">A file with this name already exists in this folder. Replacing it will overwrite its current contents.</div>
  1063. <div class="fsModalFoot">
  1064. <button class="fsBtn" id="overwriteCancelBtn" onclick="answerOverwrite(false);" locale="overwrite/cancel">Cancel</button>
  1065. <button class="fsBtn primary" id="overwriteReplaceBtn" onclick="answerOverwrite(true);" locale="overwrite/replace">Replace</button>
  1066. </div>
  1067. </div>
  1068. </div>
  1069. </div>
  1070. <script>
  1071. /*
  1072. file_selector.html
  1073. Launch parameters are passed in the URL hash as a JSON object, see
  1074. ao_module_openFileSelector() in /script/ao_module.js:
  1075. {
  1076. root: "user:/", //Initial directory
  1077. fallbackRoot: "user:/", //Used when "root" no longer exists, see below
  1078. type: "file" | "folder" | "new",
  1079. allowMultiple: false,
  1080. listenerUUID: "", //localStorage key used outside the virtual desktop
  1081. options: {
  1082. defaultName: "newfile.txt",
  1083. filter: ["mp3","flac"] //Extension whitelist, no leading dot
  1084. }
  1085. }
  1086. "root" may be a directory restored from the caller's path memory, which
  1087. the user could have renamed or deleted since. When it fails to list, the
  1088. selector drops back to "fallbackRoot" (the path the calling app asked
  1089. for) before giving up on "user:/".
  1090. The result is handed back either through the float window parent callback
  1091. (inside the ArozOS desktop) or through localStorage[listenerUUID].
  1092. */
  1093. /* ------------------------------------------------------------------ */
  1094. /* State */
  1095. /* ------------------------------------------------------------------ */
  1096. var multiSelect = false;
  1097. var type = "file";
  1098. var currentDir = "user:/";
  1099. var currentFileList = []; //Raw listDir response for the current directory
  1100. var renderedFileList = []; //Filtered + sorted list currently on screen
  1101. var pathHistory = []; //Visited directories, index based for back/forward
  1102. var historyIndex = -1;
  1103. var ctrlDown = false;
  1104. var shiftDown = false;
  1105. //Multi-select uses Cmd on a Mac (Ctrl + click is the right click there)
  1106. var isMacOS = /Mac/i.test(navigator.platform || navigator.userAgent);
  1107. var lastClickedItemID = 0;
  1108. var listenerUUID = "";
  1109. var fileOptions = {};
  1110. var fallbackRoot = "user:/"; //Where to land if the requested root is gone
  1111. var viewMode = "list"; //"list" or "grid"
  1112. var sortField = "name"; //name | date | type | size
  1113. var sortAscending = true;
  1114. var showHidden = false;
  1115. var detailsOpen = false;
  1116. var searchKeyword = "";
  1117. var selectionConfirmed = false;
  1118. //List view column widths, see "List columns" below
  1119. var COLUMN_DEFAULT_WIDTHS = {date: 210, type: 150, size: 110};
  1120. var COLUMN_MIN_WIDTH = 60; //Narrowest a fixed column can be dragged
  1121. var NAME_COLUMN_MIN_WIDTH = 140; //Room the fluid name column always keeps
  1122. var columnWidths = {}; //key -> px, only the columns the user resized
  1123. var columnResizeEndedAt = 0; //Lets the click a resize leaves behind skip the sort
  1124. var rootNameMap = {}; //"user:/" -> "User"
  1125. var thumbLoader = null; //Handle from FileThumb.loadThumbnails, cancel on navigation
  1126. /* ------------------------------------------------------------------ */
  1127. /* Icons */
  1128. /* ------------------------------------------------------------------ */
  1129. /*
  1130. Inline SVG only. See CLAUDE.md rule 6 - no emoji anywhere in the
  1131. program; app specific glyphs are drawn locally.
  1132. */
  1133. var STROKE = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">';
  1134. var ICONS = {
  1135. back: STROKE + '<path d="M19 12H5M12 19l-7-7 7-7"/></svg>',
  1136. forward: STROKE + '<path d="M5 12h14M12 5l7 7-7 7"/></svg>',
  1137. up: STROKE + '<path d="M12 19V5M5 12l7-7 7 7"/></svg>',
  1138. menu: STROKE + '<path d="M4 6h16M4 12h16M4 18h16"/></svg>',
  1139. refresh: STROKE + '<path d="M21 12a9 9 0 1 1-3.2-6.9"/><path d="M21 4v5h-5"/></svg>',
  1140. search: STROKE + '<circle cx="11" cy="11" r="7"/><path d="M20 20l-3.6-3.6"/></svg>',
  1141. close: STROKE + '<path d="M18 6L6 18M6 6l12 12"/></svg>',
  1142. viewList: STROKE + '<path d="M8 6h13M8 12h13M8 18h13M3.5 6h.01M3.5 12h.01M3.5 18h.01"/></svg>',
  1143. viewGrid: STROKE + '<rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/></svg>',
  1144. more: STROKE + '<circle cx="5" cy="12" r="1.4"/><circle cx="12" cy="12" r="1.4"/><circle cx="19" cy="12" r="1.4"/></svg>',
  1145. arrowUp: STROKE + '<path d="M12 19V5M6 11l6-6 6 6"/></svg>',
  1146. arrowDown: STROKE + '<path d="M12 5v14M6 13l6 6 6-6"/></svg>',
  1147. check: STROKE + '<path d="M20 6L9 17l-5-5"/></svg>',
  1148. info: STROKE + '<circle cx="12" cy="12" r="9"/><path d="M12 16v-5M12 8h.01"/></svg>',
  1149. eye: STROKE + '<path d="M1.8 12S5.4 5 12 5s10.2 7 10.2 7-3.6 7-10.2 7S1.8 12 1.8 12z"/><circle cx="12" cy="12" r="3"/></svg>',
  1150. folderPlus: STROKE + '<path d="M3 7a2 2 0 0 1 2-2h4l2 3h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><path d="M12 12v5M9.5 14.5h5"/></svg>',
  1151. folderOpen: STROKE + '<path d="M3 7a2 2 0 0 1 2-2h4l2 3h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg>',
  1152. clock: STROKE + '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3.2 2"/></svg>',
  1153. download: STROKE + '<path d="M12 3v12M7 11l5 5 5-5"/><path d="M4 20h16"/></svg>',
  1154. document: STROKE + '<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/></svg>',
  1155. globe: STROKE + '<circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.6 3.8 5.7 3.8 9S14.5 18.4 12 21c-2.5-2.6-3.8-5.7-3.8-9S9.5 5.6 12 3z"/></svg>',
  1156. cube: STROKE + '<path d="M12 2.8l8 4.4v9.6l-8 4.4-8-4.4V7.2z"/><path d="M4 7.2l8 4.4 8-4.4M12 21.2v-9.6"/></svg>',
  1157. code: STROKE + '<path d="M9 18l-6-6 6-6M15 6l6 6-6 6"/></svg>',
  1158. warning: STROKE + '<path d="M10.3 3.9L1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z"/><path d="M12 9v4M12 17h.01"/></svg>',
  1159. trash: STROKE + '<path d="M4 7h16M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2M6 7l1 13h10l1-13"/></svg>',
  1160. drive: STROKE + '<rect x="2.5" y="5" width="19" height="14" rx="2.5"/><path d="M6.5 15h6"/><circle cx="17.5" cy="15" r="1"/></svg>',
  1161. folderSide: STROKE + '<path d="M3 7a2 2 0 0 1 2-2h4l2 3h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg>',
  1162. /* Filled sidebar glyphs, matching the coloured tiles in the design */
  1163. desktop: '<svg viewBox="0 0 24 24" fill="currentColor"><rect x="2.5" y="4" width="19" height="13" rx="2.5"/><path d="M8 20.5h8a1 1 0 0 0 0-2H8a1 1 0 0 0 0 2z"/></svg>',
  1164. image: '<svg viewBox="0 0 24 24" fill="currentColor"><rect x="2.5" y="4" width="19" height="16" rx="3"/><circle cx="8.6" cy="9.4" r="1.8" fill="#ffffff"/><path d="M4.2 18.6l4.6-5.1 3.1 3.3 3-3.4 4.9 5.2z" fill="#ffffff"/></svg>',
  1165. video: '<svg viewBox="0 0 24 24" fill="currentColor"><rect x="2.5" y="4" width="19" height="16" rx="3"/><path d="M6.4 4v16M17.6 4v16" stroke="#ffffff" stroke-width="1.4"/><path d="M2.5 12h19" stroke="#ffffff" stroke-width="1.4"/></svg>',
  1166. music: '<svg viewBox="0 0 24 24" fill="currentColor"><path d="M20 3.4v11.2a3.4 3.4 0 1 1-2-3.1V7.3l-7 1.5v8.8a3.4 3.4 0 1 1-2-3.1V6.4z"/></svg>'
  1167. };
  1168. /* ------------------------------------------------------------------ */
  1169. /* File type helpers */
  1170. /* ------------------------------------------------------------------ */
  1171. /*
  1172. Icon drawing, thumbnail streaming and the default-opener lookup are
  1173. shared with the File Manager and live in shared/filethumb.js, so both
  1174. apps render a file the same way. These thin aliases keep the call
  1175. sites below short.
  1176. */
  1177. var folderGlyph = FileThumb.folderGlyph;
  1178. var getExt = FileThumb.getExt;
  1179. var escapeHTML = FileThumb.escapeHTML;
  1180. var formatBytes = FileThumb.formatBytes;
  1181. var formatTimestamp = FileThumb.formatTimestamp;
  1182. var smallGlyph = FileThumb.smallGlyph;
  1183. var largeGlyph = FileThumb.largeGlyph;
  1184. function getCategoryColor(ext){
  1185. return FileThumb.getCategoryColor(ext);
  1186. }
  1187. function getTypeName(filename, isDir){
  1188. return FileThumb.getTypeName(filename, isDir, function(key, fallback){
  1189. return applocale.getString(key, fallback);
  1190. });
  1191. }
  1192. /* ------------------------------------------------------------------ */
  1193. /* Boot */
  1194. /* ------------------------------------------------------------------ */
  1195. injectStaticIcons();
  1196. initTheme();
  1197. if (applocale){
  1198. //Applocale found. Do localization
  1199. applocale.init("../locale/file_selector.json", function(){
  1200. applocale.translate();
  1201. captureLocalizedTemplates();
  1202. initRoots();
  1203. initSelectorObject();
  1204. });
  1205. }else{
  1206. //Applocale not found. Is this a trim down version of ArozOS?
  1207. applocale = {
  1208. getString: function(key, original){
  1209. return original;
  1210. }
  1211. }
  1212. captureLocalizedTemplates();
  1213. initRoots();
  1214. initSelectorObject();
  1215. }
  1216. //Put the inline SVG markup into every static icon slot
  1217. function injectStaticIcons(){
  1218. $("#fsTitleIcon").html(ICONS.folderSide);
  1219. $("#fsCloseBtn").html(ICONS.close);
  1220. $("#sidebarToggleBtn").html(ICONS.menu);
  1221. $("#backBtn").html(ICONS.back);
  1222. $("#forwardBtn").html(ICONS.forward);
  1223. $("#upBtn").html(ICONS.up);
  1224. $("#refreshBtn").html(ICONS.refresh);
  1225. $("#pathIcon").html(ICONS.folderSide);
  1226. $("#searchIcon").html(ICONS.search);
  1227. $("#viewListBtn").html(ICONS.viewList);
  1228. $("#viewGridBtn").html(ICONS.viewGrid);
  1229. $("#moreBtn").html(ICONS.more);
  1230. $("#sortDirBtn").html(ICONS.arrowUp);
  1231. $(".fsDetailsHead .fsCloseBtn").html(ICONS.close);
  1232. $("[data-icon]").each(function(){
  1233. var iconName = $(this).attr("data-icon");
  1234. if (ICONS[iconName] != undefined){
  1235. $(this).html(ICONS[iconName]);
  1236. }
  1237. });
  1238. }
  1239. /*
  1240. applocale.getString() ignores its "type" argument and always reads
  1241. from the "strings" table, so placeholder and title values can only be
  1242. localized through applocale.translate() rewriting the attribute.
  1243. Snapshot the translated search placeholder here and reuse it as the
  1244. template for "Search <foldername>".
  1245. */
  1246. var searchPlaceholderTemplate = "Search";
  1247. function captureLocalizedTemplates(){
  1248. searchPlaceholderTemplate = $("#searchInput").attr("placeholder") || "Search";
  1249. }
  1250. function initSelectorObject(){
  1251. var initInfo = loadSelectorInfoFromHash();
  1252. //init global var
  1253. type = initInfo.type;
  1254. multiSelect = initInfo.allowMultiple;
  1255. listenerUUID = initInfo.listenerUUID;
  1256. fallbackRoot = initInfo.fallbackRoot;
  1257. if (initInfo.options != undefined && initInfo.options != null){
  1258. fileOptions = JSON.parse(JSON.stringify(initInfo.options));
  1259. }
  1260. //The ArozOS float window already renders a title bar and a close
  1261. //button, so the built-in one is only needed in standalone windows
  1262. if (ao_module_virtualDesktop){
  1263. $("#fsTitlebar").hide();
  1264. }
  1265. //Load options and parse the UI
  1266. if (type == "new"){
  1267. if (typeof(fileOptions.defaultName) != "undefined"){
  1268. $("#filename").val(fileOptions.defaultName);
  1269. }else{
  1270. $("#filename").val("newfile.txt");
  1271. }
  1272. /*
  1273. This picker writes a new file rather than opening an
  1274. existing one, so the confirm button says so.
  1275. Resolved through getString rather than by swapping the
  1276. locale attribute: applocale.translate() has already run
  1277. by the time this executes, so a new attribute would never
  1278. be looked up and the button would stay English.
  1279. */
  1280. $("#confirmBtn").attr("locale", "footer/create")
  1281. .text(applocale.getString("footer/create", "Create"));
  1282. }else if (type == "folder"){
  1283. //A filename has no meaning when picking a folder
  1284. $("#filename").hide();
  1285. $("#filenameLabel").hide();
  1286. }
  1287. buildFilterOptions();
  1288. restoreViewPreferences(function(){
  1289. //Load the initiation directory
  1290. listDir(initInfo.root, true);
  1291. });
  1292. }
  1293. function loadSelectorInfoFromHash(){
  1294. var fallback = {
  1295. root: "user:/",
  1296. fallbackRoot: "user:/",
  1297. type: "file",
  1298. allowMultiple: false
  1299. };
  1300. if (window.location.hash.length == 0){
  1301. return fallback;
  1302. }
  1303. try{
  1304. var selectInfo = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
  1305. if (selectInfo.root == undefined){
  1306. selectInfo.root = fallback.root;
  1307. }
  1308. if (selectInfo.fallbackRoot == undefined){
  1309. //Older callers do not send one. Their root is the only path we have
  1310. selectInfo.fallbackRoot = selectInfo.root;
  1311. }
  1312. if (selectInfo.type == undefined){
  1313. selectInfo.type = fallback.type;
  1314. }
  1315. return selectInfo;
  1316. }catch(ex){
  1317. //Error parsing the input. Use default settings
  1318. return fallback;
  1319. }
  1320. }
  1321. //The caller supplied extension whitelist is a hard constraint, so when one
  1322. //is given it is the only entry in the dropdown
  1323. function buildFilterOptions(){
  1324. var select = $("#filterSelect");
  1325. select.html("");
  1326. if (fileOptions.filter != undefined && fileOptions.filter.length > 0){
  1327. var patterns = [];
  1328. for (var i = 0; i < fileOptions.filter.length; i++){
  1329. patterns.push("*." + fileOptions.filter[i]);
  1330. }
  1331. select.append('<option value="filtered">' +
  1332. escapeHTML(applocale.getString("footer/supportedfiles", "Supported Files") + " (" + patterns.join(", ") + ")") +
  1333. '</option>');
  1334. }else{
  1335. select.append('<option value="all">' +
  1336. escapeHTML(applocale.getString("footer/allfiles", "All Files") + " (*.*)") +
  1337. '</option>');
  1338. }
  1339. }
  1340. /* ------------------------------------------------------------------ */
  1341. /* Theme */
  1342. /* ------------------------------------------------------------------ */
  1343. /*
  1344. The ArozOS system theme preference (file_explorer/theme) wins when it
  1345. is set. With no stored preference the dialog follows the operating
  1346. system setting instead. Live switches - the desktop start menu toggle,
  1347. or another tab flipping the theme - arrive via ao_module_onThemeChanged.
  1348. */
  1349. var hasStoredThemePreference = false;
  1350. function applyTheme(theme){
  1351. var isDark = (theme == "dark" || theme == "darkTheme");
  1352. $("body").toggleClass("darkTheme", isDark);
  1353. $("body").toggleClass("whiteTheme", !isDark);
  1354. //Keep the float window frame in step with the dialog contents
  1355. // ao_module_setWindowTheme(isDark ? "dark" : "white");
  1356. }
  1357. function osPrefersDark(){
  1358. return window.matchMedia != undefined && window.matchMedia("(prefers-color-scheme: dark)").matches;
  1359. }
  1360. function initTheme(){
  1361. //Paint from the OS setting first so there is no light flash while
  1362. //the stored preference is still being fetched
  1363. applyTheme(osPrefersDark() ? "dark" : "light");
  1364. if (typeof ao_module_getSystemThemeColor == "function"){
  1365. ao_module_getSystemThemeColor(function(pref){
  1366. if (pref == "darkTheme" || pref == "whiteTheme"){
  1367. hasStoredThemePreference = true;
  1368. applyTheme(pref == "darkTheme" ? "dark" : "light");
  1369. }else{
  1370. //Key not found, stay on the operating system setting
  1371. hasStoredThemePreference = false;
  1372. }
  1373. });
  1374. }
  1375. //Desktop start menu toggle and cross-tab switches
  1376. if (typeof ao_module_onThemeChanged == "function"){
  1377. ao_module_onThemeChanged(function(theme){
  1378. hasStoredThemePreference = true;
  1379. applyTheme(theme);
  1380. });
  1381. }
  1382. //Only follow the OS while the user has not pinned a theme in ArozOS
  1383. if (window.matchMedia != undefined){
  1384. var query = window.matchMedia("(prefers-color-scheme: dark)");
  1385. var onOSThemeChange = function(event){
  1386. if (!hasStoredThemePreference){
  1387. applyTheme(event.matches ? "dark" : "light");
  1388. }
  1389. };
  1390. if (query.addEventListener != undefined){
  1391. query.addEventListener("change", onOSThemeChange);
  1392. }else if (query.addListener != undefined){
  1393. //Safari below 14 and older WebKit builds
  1394. query.addListener(onOSThemeChange);
  1395. }
  1396. }
  1397. }
  1398. /* ------------------------------------------------------------------ */
  1399. /* View preferences */
  1400. /* ------------------------------------------------------------------ */
  1401. function restoreViewPreferences(callback){
  1402. $.ajax({
  1403. url: "../../system/file_system/preference",
  1404. data: {key: "file_selector/view"},
  1405. success: function(data){
  1406. try{
  1407. if (typeof data == "string" && data != ""){
  1408. var pref = JSON.parse(data);
  1409. if (pref.viewMode == "grid" || pref.viewMode == "list"){
  1410. viewMode = pref.viewMode;
  1411. }
  1412. if (pref.sortField != undefined){
  1413. sortField = pref.sortField;
  1414. }
  1415. if (pref.sortAscending != undefined){
  1416. sortAscending = pref.sortAscending;
  1417. }
  1418. if (pref.detailsOpen != undefined){
  1419. detailsOpen = pref.detailsOpen;
  1420. }
  1421. if (pref.showHidden != undefined){
  1422. showHidden = pref.showHidden;
  1423. }
  1424. if (pref.columnWidths != undefined){
  1425. columnWidths = parseColumnWidths(pref.columnWidths);
  1426. }
  1427. }
  1428. }catch(ex){
  1429. //Corrupted preference. Ignore and use the defaults
  1430. }
  1431. applyViewPreferences();
  1432. callback();
  1433. },
  1434. error: function(){
  1435. applyViewPreferences();
  1436. callback();
  1437. }
  1438. });
  1439. }
  1440. function saveViewPreferences(){
  1441. var pref = {
  1442. viewMode: viewMode,
  1443. sortField: sortField,
  1444. sortAscending: sortAscending,
  1445. detailsOpen: detailsOpen,
  1446. showHidden: showHidden,
  1447. columnWidths: columnWidths
  1448. };
  1449. $.ajax({
  1450. url: "../../system/file_system/preference",
  1451. data: {key: "file_selector/view", value: JSON.stringify(pref)}
  1452. });
  1453. }
  1454. //Reflect the current preference values onto the toolbar controls
  1455. function applyViewPreferences(){
  1456. $("#viewListBtn").toggleClass("active", viewMode == "list");
  1457. $("#viewGridBtn").toggleClass("active", viewMode == "grid");
  1458. $("#sortSelect").val(sortField);
  1459. $("#sortDirBtn").html(sortAscending ? ICONS.arrowUp : ICONS.arrowDown);
  1460. $("#detailsPanel").toggleClass("open", detailsOpen);
  1461. $("#menuDetails").toggleClass("checked", detailsOpen);
  1462. $("#menuHidden").toggleClass("checked", showHidden);
  1463. applyColumnWidths();
  1464. }
  1465. function setViewMode(mode){
  1466. if (viewMode == mode){
  1467. return;
  1468. }
  1469. viewMode = mode;
  1470. applyViewPreferences();
  1471. saveViewPreferences();
  1472. renderFileList();
  1473. }
  1474. function setSortField(field){
  1475. sortField = field;
  1476. saveViewPreferences();
  1477. renderFileList();
  1478. }
  1479. function toggleSortDirection(){
  1480. sortAscending = !sortAscending;
  1481. applyViewPreferences();
  1482. saveViewPreferences();
  1483. renderFileList();
  1484. }
  1485. function toggleDetailsPanel(){
  1486. detailsOpen = !detailsOpen;
  1487. applyViewPreferences();
  1488. saveViewPreferences();
  1489. closeMoreMenu();
  1490. updateFileAreaDensity();
  1491. if (detailsOpen){
  1492. updateDetailsPanel();
  1493. }
  1494. }
  1495. function toggleHiddenFiles(){
  1496. showHidden = !showHidden;
  1497. applyViewPreferences();
  1498. saveViewPreferences();
  1499. closeMoreMenu();
  1500. refresh();
  1501. }
  1502. /* ------------------------------------------------------------------ */
  1503. /* Directory listing */
  1504. /* ------------------------------------------------------------------ */
  1505. function listDir(dir, pushHistory){
  1506. if (pushHistory === undefined){
  1507. pushHistory = true;
  1508. }
  1509. currentDir = dir;
  1510. if (pushHistory){
  1511. //Drop anything ahead of the cursor before appending, so that
  1512. //navigating after going back rewrites the forward stack
  1513. pathHistory = pathHistory.slice(0, historyIndex + 1);
  1514. pathHistory.push(dir);
  1515. historyIndex = pathHistory.length - 1;
  1516. }
  1517. updateNavButtons();
  1518. $("#addressbar").val(currentDir);
  1519. renderBreadcrumb();
  1520. updateSidebarActiveItem();
  1521. $("#searchInput").val("");
  1522. searchKeyword = "";
  1523. updateSearchPlaceholder();
  1524. setWindowTitleForSelection(0);
  1525. //Stop any in-flight thumbnail stream from the previous directory
  1526. if (thumbLoader != null){
  1527. thumbLoader.cancel();
  1528. thumbLoader = null;
  1529. }
  1530. //Any editor still on screen belongs to the outgoing listing
  1531. inlineEditActive = false;
  1532. closeActiveInlineEdit = null;
  1533. closeContextMenu();
  1534. $("#fileArea").find(".fsListHead, .fsRow, .fsGrid").remove();
  1535. $("#emptyPlaceholder").removeClass("show");
  1536. $("#loadingPlaceholder").addClass("show");
  1537. clearDetails();
  1538. $.ajax({
  1539. url: "../../system/file_system/listDir",
  1540. data: {dir: dir, sort: "default", showHidden: showHidden ? "true" : "false"},
  1541. success: function(data){
  1542. $("#loadingPlaceholder").removeClass("show");
  1543. if (data == null){
  1544. currentFileList = [];
  1545. renderFileList();
  1546. return;
  1547. }
  1548. if (data.error !== undefined){
  1549. //The directory is gone (a restored path memory entry that has
  1550. //since been renamed or deleted). Try what the calling app
  1551. //originally asked for, then the user root.
  1552. if (fallbackRoot != undefined && fallbackRoot != "" && dir != fallbackRoot){
  1553. listDir(fallbackRoot, false);
  1554. }else if (dir != "user:/"){
  1555. listDir("user:/", false);
  1556. }else{
  1557. currentFileList = [];
  1558. renderFileList();
  1559. }
  1560. return;
  1561. }
  1562. currentFileList = data;
  1563. renderFileList();
  1564. },
  1565. error: function(){
  1566. $("#loadingPlaceholder").removeClass("show");
  1567. currentFileList = [];
  1568. renderFileList();
  1569. }
  1570. });
  1571. }
  1572. function refresh(){
  1573. listDir(currentDir, false);
  1574. }
  1575. function updatePath(){
  1576. var newDir = $("#addressbar").val();
  1577. $("#pathbar").removeClass("editing");
  1578. if (newDir != "" && newDir != currentDir){
  1579. listDir(newDir);
  1580. }else{
  1581. renderBreadcrumb();
  1582. }
  1583. }
  1584. /* ------------------------------------------------------------------ */
  1585. /* Filtering, sorting and rendering */
  1586. /* ------------------------------------------------------------------ */
  1587. function passesExtensionFilter(fileObject){
  1588. if (fileObject.IsDir){
  1589. return true;
  1590. }
  1591. if (fileOptions.filter == undefined || fileOptions.filter.length == 0){
  1592. return true;
  1593. }
  1594. var ext = getExt(fileObject.Filename);
  1595. for (var i = 0; i < fileOptions.filter.length; i++){
  1596. if (String(fileOptions.filter[i]).toLowerCase().replace(/^\./, "") == ext){
  1597. return true;
  1598. }
  1599. }
  1600. return false;
  1601. }
  1602. function sortFileObjects(list){
  1603. var direction = sortAscending ? 1 : -1;
  1604. list.sort(function(a, b){
  1605. //Folders always lead, regardless of the sort direction
  1606. if (a.IsDir != b.IsDir){
  1607. return a.IsDir ? -1 : 1;
  1608. }
  1609. var result = 0;
  1610. if (sortField == "date"){
  1611. result = (a.ModTime || 0) - (b.ModTime || 0);
  1612. }else if (sortField == "size"){
  1613. result = (a.Filesize || 0) - (b.Filesize || 0);
  1614. }else if (sortField == "type"){
  1615. result = getExt(a.Filename).localeCompare(getExt(b.Filename));
  1616. }
  1617. if (result == 0){
  1618. result = a.Filename.toLowerCase().localeCompare(b.Filename.toLowerCase());
  1619. //A name tie-break stays ascending so equal keys read naturally
  1620. return sortField == "name" ? result * direction : result;
  1621. }
  1622. return result * direction;
  1623. });
  1624. return list;
  1625. }
  1626. function renderFileList(){
  1627. var list = [];
  1628. for (var i = 0; i < currentFileList.length; i++){
  1629. var fileObject = currentFileList[i];
  1630. if (!passesExtensionFilter(fileObject)){
  1631. continue;
  1632. }
  1633. if (searchKeyword != "" && fileObject.Filename.toLowerCase().indexOf(searchKeyword) < 0){
  1634. continue;
  1635. }
  1636. list.push(fileObject);
  1637. }
  1638. renderedFileList = sortFileObjects(list);
  1639. $("#fileArea").find(".fsListHead, .fsRow, .fsGrid").remove();
  1640. if (renderedFileList.length == 0){
  1641. $("#emptyPlaceholder").addClass("show");
  1642. setWindowTitleForSelection(0);
  1643. clearDetails();
  1644. return;
  1645. }
  1646. $("#emptyPlaceholder").removeClass("show");
  1647. if (viewMode == "list"){
  1648. renderListView();
  1649. }else{
  1650. renderGridView();
  1651. }
  1652. if (viewMode == "grid"){
  1653. startThumbnailLoader();
  1654. }
  1655. updateFileAreaDensity();
  1656. setWindowTitleForSelection(0);
  1657. runPostRenderActions();
  1658. }
  1659. /*
  1660. A create or rename finishes with a directory reload, so the follow up
  1661. work has to wait until the new listing has been painted.
  1662. */
  1663. var pendingSelectAfterRender = null;
  1664. function runPostRenderActions(){
  1665. if (pendingSelectAfterRender != null){
  1666. var toSelect = pendingSelectAfterRender;
  1667. pendingSelectAfterRender = null;
  1668. var dom = findFileObjectByName(toSelect);
  1669. var fileObject = getFileObjectByName(toSelect);
  1670. if (dom != null && fileObject != null && objectIsSelectable(fileObject)){
  1671. selectThis(dom, {ctrlKey: false, shiftKey: false});
  1672. }
  1673. }
  1674. if (pendingInlineRename != null){
  1675. var toEdit = pendingInlineRename;
  1676. pendingInlineRename = null;
  1677. var editDom = findFileObjectByName(toEdit);
  1678. if (editDom != null){
  1679. //Bring it into view before handing over the keyboard
  1680. if (editDom.scrollIntoView != undefined){
  1681. editDom.scrollIntoView({block: "nearest"});
  1682. }
  1683. startInlineRename(editDom);
  1684. }
  1685. }
  1686. }
  1687. function getFileObjectByName(filename){
  1688. for (var i = 0; i < currentFileList.length; i++){
  1689. if (currentFileList[i].Filename == filename){
  1690. return currentFileList[i];
  1691. }
  1692. }
  1693. return null;
  1694. }
  1695. /*
  1696. Drop list columns based on how much room the file area actually has.
  1697. A media query cannot do this because opening the details pane steals
  1698. horizontal space without changing the window width.
  1699. */
  1700. function updateFileAreaDensity(){
  1701. var width = $("#fileArea").width();
  1702. //The breakpoints suit the default widths. A resized column moves them
  1703. //by as much as it grew or shrank, so the name column keeps its room
  1704. var dateGrowth = columnWidth("date") - COLUMN_DEFAULT_WIDTHS.date;
  1705. var typeGrowth = columnWidth("type") - COLUMN_DEFAULT_WIDTHS.type;
  1706. var sizeGrowth = columnWidth("size") - COLUMN_DEFAULT_WIDTHS.size;
  1707. $("#fileArea").toggleClass("narrow", width < 580 + dateGrowth + typeGrowth + sizeGrowth)
  1708. .toggleClass("verynarrow", width < 440 + dateGrowth + sizeGrowth);
  1709. }
  1710. function renderListView(){
  1711. var head = '<div class="fsListHead">' +
  1712. sortableHeader("colName", "name", applocale.getString("list/name", "Name")) +
  1713. sortableHeader("colDate", "date", applocale.getString("list/date", "Date Modified")) +
  1714. sortableHeader("colType", "type", applocale.getString("list/type", "Type")) +
  1715. sortableHeader("colSize", "size", applocale.getString("list/size", "Size")) +
  1716. '</div>';
  1717. var rows = "";
  1718. for (var i = 0; i < renderedFileList.length; i++){
  1719. var fileObject = renderedFileList[i];
  1720. var selectable = objectIsSelectable(fileObject);
  1721. rows += '<div class="fsRow fileObject' + (selectable ? "" : " disabledObject") + '"' +
  1722. ' fid="' + i + '"' +
  1723. ' filepath="' + encodeURIComponent(fileObject.Filepath) + '"' +
  1724. ' filename="' + encodeURIComponent(fileObject.Filename) + '"' +
  1725. ' isDir="' + fileObject.IsDir + '"' +
  1726. ' onclick="selectThis(this, event);" ondblclick="openThis(this, event);"' +
  1727. ' oncontextmenu="showContextMenu(event, this);">' +
  1728. '<div class="fsCell colName">' + smallGlyph(fileObject.Filename, fileObject.IsDir) +
  1729. '<span class="fsRowName">' + escapeHTML(fileObject.Filename) + '</span></div>' +
  1730. '<div class="fsCell colDate">' + formatTimestamp(fileObject.ModTime) + '</div>' +
  1731. '<div class="fsCell colType">' + escapeHTML(getTypeName(fileObject.Filename, fileObject.IsDir)) + '</div>' +
  1732. '<div class="fsCell colSize">' + (fileObject.IsDir ? "--" : escapeHTML(fileObject.Displaysize || formatBytes(fileObject.Filesize))) + '</div>' +
  1733. '</div>';
  1734. }
  1735. $("#fileArea").append(head + rows);
  1736. }
  1737. function sortableHeader(columnClass, field, label){
  1738. var isSorted = (sortField == field);
  1739. return '<div class="fsCol ' + columnClass + (isSorted ? " sorted" : "") + '" data-col="' + field + '" onclick="onHeaderClick(\'' + field + '\');">' +
  1740. '<span class="fsColInner">' +
  1741. '<span class="fsColLabel">' + escapeHTML(label) + '</span>' +
  1742. '<span class="fsSortMark">' + (sortAscending ? ICONS.arrowUp : ICONS.arrowDown) + '</span>' +
  1743. '</span>' +
  1744. '<span class="fsColGrip" onpointerdown="startColumnResize(event, this);"' +
  1745. ' onclick="event.stopPropagation();" ondblclick="resetColumnPair(event, this);"></span>' +
  1746. '</div>';
  1747. }
  1748. function onHeaderClick(field){
  1749. //A resize that ends over its own header cell leaves a click behind
  1750. if (Date.now() - columnResizeEndedAt < 300){
  1751. return;
  1752. }
  1753. if (sortField == field){
  1754. sortAscending = !sortAscending;
  1755. }else{
  1756. sortField = field;
  1757. sortAscending = true;
  1758. }
  1759. applyViewPreferences();
  1760. saveViewPreferences();
  1761. renderFileList();
  1762. }
  1763. /* ------------------------------------------------------------------ */
  1764. /* List columns */
  1765. /* ------------------------------------------------------------------ */
  1766. /*
  1767. The grip on a header cell's right edge is the boundary between that
  1768. column and the next visible one. Dragging it trades width between
  1769. those two only, so no other column moves, and double clicking it puts
  1770. both back to their defaults - the same model as the File Manager's
  1771. details view (js/explorer/columns.js).
  1772. Name is the one fluid column and is never given a width. When it is
  1773. one of the pair only the other column is sized, and name takes up the
  1774. difference, which comes to the same thing.
  1775. */
  1776. function columnWidth(key){
  1777. return columnWidths[key] != undefined ? columnWidths[key] : COLUMN_DEFAULT_WIDTHS[key];
  1778. }
  1779. function columnMinWidth(key){
  1780. return key == "name" ? NAME_COLUMN_MIN_WIDTH : COLUMN_MIN_WIDTH;
  1781. }
  1782. //Keeps only known columns with a usable number, so a corrupted
  1783. //preference cannot break the layout
  1784. function parseColumnWidths(saved){
  1785. var widths = {};
  1786. if (saved == null || typeof saved != "object"){
  1787. return widths;
  1788. }
  1789. for (var key in COLUMN_DEFAULT_WIDTHS){
  1790. var width = parseInt(saved[key]);
  1791. if (!isNaN(width)){
  1792. widths[key] = Math.max(COLUMN_MIN_WIDTH, width);
  1793. }
  1794. }
  1795. return widths;
  1796. }
  1797. function applyColumnWidths(){
  1798. var area = document.getElementById("fileArea");
  1799. for (var key in COLUMN_DEFAULT_WIDTHS){
  1800. if (columnWidths[key] != undefined){
  1801. area.style.setProperty("--fs-col-" + key, Math.round(columnWidths[key]) + "px");
  1802. }else{
  1803. area.style.removeProperty("--fs-col-" + key);
  1804. }
  1805. }
  1806. }
  1807. //The two header cells a grip sits between, skipping columns the
  1808. //density classes have hidden
  1809. function columnPairFor(grip){
  1810. var cell = $(grip).closest(".fsCol")[0];
  1811. var cells = $(cell).parent().children(".fsCol").filter(":visible").toArray();
  1812. var next = cells[cells.indexOf(cell) + 1];
  1813. if (next == undefined){
  1814. return null;
  1815. }
  1816. return {
  1817. left: cell,
  1818. right: next,
  1819. leftKey: $(cell).attr("data-col"),
  1820. rightKey: $(next).attr("data-col")
  1821. };
  1822. }
  1823. function startColumnResize(event, grip){
  1824. if (event.button != 0){
  1825. return;
  1826. }
  1827. //Keeps the press from selecting text or reaching the sort handler
  1828. event.preventDefault();
  1829. event.stopPropagation();
  1830. var pair = columnPairFor(grip);
  1831. if (pair == null){
  1832. return;
  1833. }
  1834. var startX = event.clientX;
  1835. var startLeft = pair.left.offsetWidth;
  1836. var startRight = pair.right.offsetWidth;
  1837. var total = startLeft + startRight;
  1838. //A column a small window already squeezed under its minimum may stay
  1839. //there, it just cannot be dragged any narrower
  1840. var minLeft = Math.min(startLeft, columnMinWidth(pair.leftKey));
  1841. var maxLeft = total - Math.min(startRight, columnMinWidth(pair.rightKey));
  1842. var moved = false;
  1843. //Same capture pattern as the sidebar splitter, see initSidebarSplitter()
  1844. try { grip.setPointerCapture(event.pointerId); } catch(e) {}
  1845. grip.classList.add("dragging");
  1846. $("body").addClass("fsResizing");
  1847. function onMove(e){
  1848. var left = Math.round(Math.min(maxLeft, Math.max(minLeft, startLeft + e.clientX - startX)));
  1849. if (pair.leftKey != "name"){
  1850. columnWidths[pair.leftKey] = left;
  1851. }
  1852. if (pair.rightKey != "name"){
  1853. columnWidths[pair.rightKey] = total - left;
  1854. }
  1855. moved = moved || left != startLeft;
  1856. applyColumnWidths();
  1857. }
  1858. function onEnd(){
  1859. //Listeners go first: releasing the capture fires lostpointercapture
  1860. grip.removeEventListener("pointermove", onMove);
  1861. grip.removeEventListener("pointerup", onEnd);
  1862. grip.removeEventListener("pointercancel", onEnd);
  1863. grip.removeEventListener("lostpointercapture", onEnd);
  1864. try { grip.releasePointerCapture(event.pointerId); } catch(e) {}
  1865. grip.classList.remove("dragging");
  1866. $("body").removeClass("fsResizing");
  1867. columnResizeEndedAt = Date.now();
  1868. if (moved){
  1869. saveViewPreferences();
  1870. updateFileAreaDensity();
  1871. }
  1872. }
  1873. grip.addEventListener("pointermove", onMove);
  1874. grip.addEventListener("pointerup", onEnd);
  1875. grip.addEventListener("pointercancel", onEnd);
  1876. //Capture taken away without a pointerup ends the drag as well
  1877. grip.addEventListener("lostpointercapture", onEnd);
  1878. }
  1879. function resetColumnPair(event, grip){
  1880. event.stopPropagation();
  1881. var pair = columnPairFor(grip);
  1882. if (pair == null){
  1883. return;
  1884. }
  1885. delete columnWidths[pair.leftKey];
  1886. delete columnWidths[pair.rightKey];
  1887. applyColumnWidths();
  1888. saveViewPreferences();
  1889. updateFileAreaDensity();
  1890. }
  1891. function renderGridView(){
  1892. var tiles = "";
  1893. for (var i = 0; i < renderedFileList.length; i++){
  1894. var fileObject = renderedFileList[i];
  1895. var selectable = objectIsSelectable(fileObject);
  1896. var meta = fileObject.IsDir ?
  1897. formatTimestamp(fileObject.ModTime) :
  1898. formatTimestamp(fileObject.ModTime) + "<br>" + escapeHTML(fileObject.Displaysize || formatBytes(fileObject.Filesize));
  1899. tiles += '<div class="fsTile fileObject' + (selectable ? "" : " disabledObject") + '"' +
  1900. ' fid="' + i + '"' +
  1901. ' filepath="' + encodeURIComponent(fileObject.Filepath) + '"' +
  1902. ' filename="' + encodeURIComponent(fileObject.Filename) + '"' +
  1903. ' isDir="' + fileObject.IsDir + '"' +
  1904. ' onclick="selectThis(this, event);" ondblclick="openThis(this, event);"' +
  1905. ' oncontextmenu="showContextMenu(event, this);">' +
  1906. //Folders always keep the drawn folder glyph - no thumbnail
  1907. //and no opener badge is rendered for them at all
  1908. '<div class="fsThumb">' + largeGlyph(fileObject.Filename, fileObject.IsDir) +
  1909. (fileObject.IsDir ? "" : '<img class="fsThumbImg"><span class="fsAppBadge"><img></span>') +
  1910. '</div>' +
  1911. '<div class="fsTileName" title="' + escapeHTML(fileObject.Filename) + '">' + escapeHTML(fileObject.Filename) + '</div>' +
  1912. '<div class="fsTileMeta"><span class="fsTileMetaText">' + meta + '</span>' +
  1913. '<button class="fsTileMore" title="More" onclick="onTileMore(this, event);">' + ICONS.more + '</button>' +
  1914. '</div>' +
  1915. '</div>';
  1916. }
  1917. $("#fileArea").append('<div class="fsGrid">' + tiles + '</div>');
  1918. }
  1919. //A file object is only clickable if it matches the requested selection type
  1920. function objectIsSelectable(fileObject){
  1921. if (fileObject.IsDir){
  1922. //Folders are always navigable, and selectable in folder mode
  1923. return true;
  1924. }
  1925. return type != "folder";
  1926. }
  1927. function onTileMore(button, event){
  1928. event.stopPropagation();
  1929. var tile = $(button).closest(".fileObject");
  1930. selectThis(tile[0], {ctrlKey: false, shiftKey: false});
  1931. if (!detailsOpen){
  1932. toggleDetailsPanel();
  1933. }
  1934. /*
  1935. Show this tile explicitly rather than whatever is selected.
  1936. Plenty of items are previewable but not selectable in the
  1937. current picker mode - a folder while picking files, any file
  1938. while picking a folder - and selectThis() leaves those
  1939. unselected by design. Going through the selection here left
  1940. the panel blank for exactly those items until the tile itself
  1941. was clicked.
  1942. */
  1943. updateDetailsFor([tile[0]]);
  1944. }
  1945. /* ------------------------------------------------------------------ */
  1946. /* Thumbnails and application icons */
  1947. /* ------------------------------------------------------------------ */
  1948. function startThumbnailLoader(){
  1949. //Drop anything still streaming for the previous directory
  1950. if (thumbLoader != null){
  1951. thumbLoader.cancel();
  1952. }
  1953. var targets = [];
  1954. $("#fileArea").find(".fileObject").each(function(){
  1955. targets.push({
  1956. filename: decodeURIComponent($(this).attr("filename")),
  1957. filepath: decodeURIComponent($(this).attr("filepath")),
  1958. isDir: $(this).attr("isDir") == "true",
  1959. dom: this
  1960. });
  1961. });
  1962. thumbLoader = FileThumb.loadThumbnails({
  1963. root: "../../",
  1964. folder: currentDir,
  1965. targets: targets,
  1966. //The picker keeps the drawn folder glyph instead of the
  1967. //server rendered folder preview
  1968. includeFolders: false,
  1969. onLoad: function(target, src){
  1970. applyThumbnail(target, src);
  1971. }
  1972. });
  1973. }
  1974. function applyThumbnail(target, src){
  1975. $(target.dom).find(".fsThumbImg").attr("src", src).addClass("loaded");
  1976. $(target.dom).find(".fsThumb").addClass("hasThumb");
  1977. loadAppIconBadge(target.dom, target.filename);
  1978. //Keep the details preview in sync when the selected file resolves
  1979. var selected = $("#fileArea").find(".fileObject.selected");
  1980. if (selected.length == 1 && selected[0] == target.dom){
  1981. $("#detailsBody").find(".fsThumbImg").attr("src", src).addClass("loaded");
  1982. $("#detailsBody").find(".fsDetailsPreview").addClass("hasThumb");
  1983. }
  1984. }
  1985. //Look up the WebApp registered to open this extension and stamp its icon
  1986. //onto the thumbnail, the same way the desktop marks its file shortcuts
  1987. function loadAppIconBadge(fileObjectDOM, filename){
  1988. getDefaultOpener("." + getExt(filename), function(moduleInfo){
  1989. if (moduleInfo == null || moduleInfo.IconPath == undefined || moduleInfo.IconPath == ""){
  1990. return;
  1991. }
  1992. var badge = $(fileObjectDOM).find(".fsAppBadge");
  1993. //A module may declare an icon that is not shipped. Only reveal
  1994. //the badge once the image has actually decoded
  1995. badge.find("img").off("load error").on("load", function(){
  1996. badge.css("display", "block");
  1997. }).on("error", function(){
  1998. badge.css("display", "none");
  1999. }).attr("src", "../../" + moduleInfo.IconPath);
  2000. });
  2001. }
  2002. function getDefaultOpener(ext, callback){
  2003. FileThumb.getDefaultOpener(ext, callback, "../../");
  2004. }
  2005. /* ------------------------------------------------------------------ */
  2006. /* Breadcrumb and navigation */
  2007. /* ------------------------------------------------------------------ */
  2008. function renderBreadcrumb(){
  2009. var path = currentDir;
  2010. //Split the virtual path into its root ("user:/") and the sub path
  2011. var rootEnd = path.indexOf(":/");
  2012. var root = "";
  2013. var subpath = "";
  2014. if (rootEnd > 0){
  2015. root = path.substring(0, rootEnd + 2);
  2016. subpath = path.substring(rootEnd + 2);
  2017. }else{
  2018. root = path;
  2019. }
  2020. var crumbs = [];
  2021. crumbs.push({label: rootNameMap[root] || root, path: root});
  2022. var segments = subpath.split("/");
  2023. var accumulated = root;
  2024. for (var i = 0; i < segments.length; i++){
  2025. if (segments[i] == ""){
  2026. continue;
  2027. }
  2028. accumulated = accumulated + segments[i] + "/";
  2029. crumbs.push({label: segments[i], path: accumulated});
  2030. }
  2031. var html = "";
  2032. for (var i = 0; i < crumbs.length; i++){
  2033. if (i > 0){
  2034. html += '<span class="fsCrumbSep">&rsaquo;</span>';
  2035. }
  2036. html += '<span class="fsCrumb' + (i == crumbs.length - 1 ? " last" : "") + '"' +
  2037. ' onclick="onCrumbClick(event, \'' + encodeURIComponent(crumbs[i].path) + '\');"' +
  2038. ' title="' + escapeHTML(crumbs[i].path) + '">' + escapeHTML(crumbs[i].label) + '</span>';
  2039. }
  2040. html += '<span class="fsCrumbPad"></span>';
  2041. $("#breadcrumb").html(html);
  2042. }
  2043. //"Search tmp" - the placeholder names the folder being searched
  2044. function updateSearchPlaceholder(){
  2045. var name = getCurrentFolderName();
  2046. $("#searchInput").attr("placeholder", name == "" ? searchPlaceholderTemplate : searchPlaceholderTemplate + " " + name);
  2047. }
  2048. function getCurrentFolderName(){
  2049. var path = currentDir;
  2050. if (path.substring(path.length - 1) == "/"){
  2051. path = path.substring(0, path.length - 1);
  2052. }
  2053. if (rootNameMap[path + "/"] != undefined){
  2054. return rootNameMap[path + "/"];
  2055. }
  2056. var name = path.split("/").pop();
  2057. return name.replace(/:$/, "");
  2058. }
  2059. function onCrumbClick(event, encodedPath){
  2060. event.stopPropagation();
  2061. var target = decodeURIComponent(encodedPath);
  2062. if (target != currentDir){
  2063. listDir(target);
  2064. }
  2065. }
  2066. //Clicking the empty part of the path bar turns it into a text field,
  2067. //keeping the old manual path entry behaviour available
  2068. function onPathbarClick(event){
  2069. if ($(event.target).closest(".fsCrumb").length > 0){
  2070. return;
  2071. }
  2072. $("#pathbar").addClass("editing");
  2073. $("#addressbar").val(currentDir).focus().select();
  2074. }
  2075. $("#addressbar").on("change", function(){
  2076. updatePath();
  2077. });
  2078. $("#addressbar").on("keydown", function(event){
  2079. if (event.which == 27){
  2080. //Escape leaves the address bar without navigating
  2081. event.stopPropagation();
  2082. $("#pathbar").removeClass("editing");
  2083. $("#addressbar").blur();
  2084. }
  2085. });
  2086. $("#addressbar").on("blur", function(){
  2087. $("#pathbar").removeClass("editing");
  2088. renderBreadcrumb();
  2089. });
  2090. function updateNavButtons(){
  2091. $("#backBtn").prop("disabled", historyIndex <= 0);
  2092. $("#forwardBtn").prop("disabled", historyIndex >= pathHistory.length - 1);
  2093. $("#upBtn").prop("disabled", getParentPath(currentDir) == "");
  2094. }
  2095. function getParentPath(path){
  2096. var trimmed = path;
  2097. if (trimmed.substring(trimmed.length - 1) == "/"){
  2098. trimmed = trimmed.substring(0, trimmed.length - 1);
  2099. }
  2100. //Already at a virtual root such as "user:/", there is nowhere to go up to
  2101. if (trimmed.indexOf("/") < 0 || trimmed.substring(trimmed.length - 1) == ":"){
  2102. return "";
  2103. }
  2104. var segments = trimmed.split("/");
  2105. segments.pop();
  2106. var parent = segments.join("/");
  2107. if (parent.length == 0){
  2108. return "";
  2109. }
  2110. //One level below the root collapses back onto the root itself,
  2111. //e.g. "user:/tmp" -> "user:/"
  2112. return parent + "/";
  2113. }
  2114. function parentDir(){
  2115. var parent = getParentPath(currentDir);
  2116. if (parent != ""){
  2117. listDir(parent);
  2118. }
  2119. }
  2120. function backDir(){
  2121. if (historyIndex > 0){
  2122. historyIndex--;
  2123. listDir(pathHistory[historyIndex], false);
  2124. }
  2125. }
  2126. function forwardDir(){
  2127. if (historyIndex < pathHistory.length - 1){
  2128. historyIndex++;
  2129. listDir(pathHistory[historyIndex], false);
  2130. }
  2131. }
  2132. function openThis(object, event){
  2133. if (event != undefined && event.preventDefault != undefined){
  2134. event.preventDefault();
  2135. }
  2136. var filepath = decodeURIComponent($(object).attr("filepath"));
  2137. if ($(object).attr("isDir") == "true"){
  2138. listDir(filepath);
  2139. }else{
  2140. chooseThisFile(object);
  2141. }
  2142. }
  2143. function chooseThisFile(object){
  2144. if (type == "folder"){
  2145. return;
  2146. }
  2147. $(".fileObject.selected").removeClass("selected");
  2148. $(object).addClass("selected");
  2149. $("#filename").val(decodeURIComponent($(object).attr("filename")));
  2150. confirmSelection();
  2151. }
  2152. /* ------------------------------------------------------------------ */
  2153. /* Selection */
  2154. /* ------------------------------------------------------------------ */
  2155. function selectThis(object, event){
  2156. var isDir = $(object).attr("isDir") == "true";
  2157. var filename = decodeURIComponent($(object).attr("filename"));
  2158. var useCtrl = (event != undefined && (isMacOS ? event.metaKey : event.ctrlKey)) || ctrlDown;
  2159. var useShift = (event != undefined && event.shiftKey) || shiftDown;
  2160. if (isDir && type == "file"){
  2161. //Folders cannot be picked in file mode, but they can still be
  2162. //shown in the details pane
  2163. updateDetailsFor([object]);
  2164. return;
  2165. }else if (!isDir && type == "folder"){
  2166. updateDetailsFor([object]);
  2167. return;
  2168. }else if (type == "new" && !isDir){
  2169. //Use this filename as the newfile name (aka overwrite mode)
  2170. $("#filename").val(filename);
  2171. $(".fileObject.selected").removeClass("selected");
  2172. updateDetailsFor([object]);
  2173. return;
  2174. }else if (type == "new" && isDir){
  2175. //Selected a folder in new mode. Only preview it
  2176. updateDetailsFor([object]);
  2177. return;
  2178. }
  2179. if (multiSelect && useCtrl){
  2180. //Add this into selection list
  2181. $(object).toggleClass("selected");
  2182. }else if (multiSelect && useShift){
  2183. var start = parseInt(lastClickedItemID);
  2184. var end = parseInt($(object).attr("fid"));
  2185. if (isNaN(start)){
  2186. start = end;
  2187. }
  2188. if (start > end){
  2189. var swap = start;
  2190. start = end;
  2191. end = swap;
  2192. }
  2193. var fileObjects = $("#fileArea").find(".fileObject");
  2194. for (var k = start; k <= end; k++){
  2195. $(fileObjects[k]).addClass("selected");
  2196. }
  2197. }else{
  2198. //Reset and add this into selection list
  2199. $(".fileObject.selected").removeClass("selected");
  2200. $(object).addClass("selected");
  2201. }
  2202. //Update last selected id
  2203. lastClickedItemID = $(object).attr("fid");
  2204. var selected = $("#fileArea").find(".fileObject.selected");
  2205. if (selected.length == 1){
  2206. $("#filename").val(decodeURIComponent(selected.attr("filename")));
  2207. }else if (selected.length > 1){
  2208. $("#filename").val("");
  2209. }
  2210. setWindowTitleForSelection(selected.length);
  2211. updateDetailsFor(selected.toArray());
  2212. }
  2213. /*
  2214. applocale sets the window title to the localized "fwtitle" once the
  2215. locale file lands, and this runs again on every selection change - so
  2216. the whole string is rebuilt from the locale, base word included, or the
  2217. title would drop back to English the moment something is selected.
  2218. */
  2219. function setWindowTitleForSelection(objectCount){
  2220. //Same string as the in-dialog title bar, and the fwtitle applocale sets
  2221. var baseTitle = applocale.getString("title", "Open");
  2222. if (objectCount == 0){
  2223. ao_module_setWindowTitle(baseTitle);
  2224. return;
  2225. }
  2226. /*
  2227. Singular and plural are separate keys rather than one string with
  2228. the count spliced in: languages that do not inflect simply carry the
  2229. same text in both, while English still reads "1 file selected".
  2230. */
  2231. var countKey = (objectCount > 1) ? "title/itemsSelected" : "title/itemSelected";
  2232. var fallbackPost = (objectCount > 1) ? " items selected" : " item selected";
  2233. if (type == "file"){
  2234. countKey = (objectCount > 1) ? "title/filesSelected" : "title/fileSelected";
  2235. fallbackPost = (objectCount > 1) ? " files selected" : " file selected";
  2236. }else if (type == "folder"){
  2237. countKey = (objectCount > 1) ? "title/foldersSelected" : "title/folderSelected";
  2238. fallbackPost = (objectCount > 1) ? " folders selected" : " folder selected";
  2239. }
  2240. /*
  2241. The phrase is split around the digit - "<pre>2<post>" - because the
  2242. count does not sit in the same place in every language: Chinese puts
  2243. it in the middle ("已選取 2 個資料夾") where English trails it
  2244. ("2 files selected"). Each half carries its own spacing, so a
  2245. language that wants the digit against the following word can have
  2246. that too ("파일 2개 선택됨").
  2247. */
  2248. var pre = applocale.getString(countKey + "/pre", "");
  2249. var post = applocale.getString(countKey + "/post", fallbackPost);
  2250. ao_module_setWindowTitle(baseTitle + " (" + pre + objectCount + post + ")");
  2251. }
  2252. function confirmSelection(){
  2253. var files = [];
  2254. $("#fileArea").find(".fileObject.selected").each(function(){
  2255. files.push({
  2256. filename: decodeURIComponent($(this).attr("filename")),
  2257. filepath: decodeURIComponent($(this).attr("filepath"))
  2258. });
  2259. });
  2260. //Check if currentdir end with "/". If not, append it
  2261. if (currentDir.substr(currentDir.length - 1, 1) != "/"){
  2262. currentDir = currentDir + "/";
  2263. }
  2264. //Nothing highlighted but a name was typed: resolve it against the
  2265. //current listing, the way a native open dialog does
  2266. if (files.length == 0 && (type == "file" || type == "folder")){
  2267. var typedName = $("#filename").val().trim();
  2268. if (typedName != ""){
  2269. for (var i = 0; i < currentFileList.length; i++){
  2270. var candidate = currentFileList[i];
  2271. if (candidate.Filename == typedName &&
  2272. ((type == "folder" && candidate.IsDir) || (type == "file" && !candidate.IsDir))){
  2273. files.push({
  2274. filename: candidate.Filename,
  2275. filepath: candidate.Filepath
  2276. });
  2277. break;
  2278. }
  2279. }
  2280. }
  2281. }
  2282. //Check for special cases
  2283. if (files.length == 0 && type == "folder"){
  2284. //Select the current path as target instead
  2285. var currentPathname = currentDir.split("/");
  2286. currentPathname.pop();
  2287. currentPathname = currentPathname.pop();
  2288. if (currentPathname == ""){
  2289. currentPathname = currentDir;
  2290. }
  2291. files.push({
  2292. filename: currentPathname,
  2293. filepath: currentDir
  2294. });
  2295. }else if (files.length == 0 && type == "new"){
  2296. //Push this new file into the return structure
  2297. var newFilename = $("#filename").val();
  2298. files.push({
  2299. filename: newFilename,
  2300. filepath: currentDir + newFilename
  2301. });
  2302. }
  2303. if (type == "new" && files.length == 1){
  2304. //Writing over an existing file needs the user's say so first
  2305. confirmOverwrite(files[0], function(){
  2306. deliverSelection(files);
  2307. });
  2308. return;
  2309. }
  2310. deliverSelection(files);
  2311. }
  2312. //Hands the chosen files to the calling app and closes the selector
  2313. function deliverSelection(files){
  2314. selectionConfirmed = true;
  2315. if (ao_module_virtualDesktop){
  2316. if (!ao_module_parentCallback(files)){
  2317. //Parent callback not exists
  2318. selectionConfirmed = false;
  2319. alert("Selection Failed. Is parent window alive?");
  2320. }else{
  2321. parent.closeFwProcess(ao_module_windowID);
  2322. }
  2323. }else{
  2324. if (listenerUUID == ""){
  2325. selectionConfirmed = false;
  2326. alert("Invalid listener UUID. Please re-open your file selector.");
  2327. return;
  2328. }
  2329. localStorage.setItem(listenerUUID, JSON.stringify(files));
  2330. $("#waitloader").addClass("show");
  2331. setTimeout(function(){
  2332. $("#waitloadertext").text("System is not responding. Please close this window and retry.");
  2333. }, 10000);
  2334. }
  2335. }
  2336. /* ------------------------------------------------------------------ */
  2337. /* Replace prompt (new file mode) */
  2338. /* ------------------------------------------------------------------ */
  2339. /*
  2340. A new file name that is already taken asks before the caller is told
  2341. to write over it. The listing answers at once for what is on screen.
  2342. A name it does not hold is still checked with the server: the file
  2343. may be hidden from the listing, differ only in letter case on a case
  2344. insensitive disk, or have been created after the listing loaded.
  2345. A name taken by a folder is left to the caller, as before.
  2346. */
  2347. var overwriteCheckPending = false;
  2348. var overwriteProceed = null; //Runs on "Replace", set while the prompt is open
  2349. function confirmOverwrite(target, proceed){
  2350. if (overwriteCheckPending || overwriteDialogIsOpen()){
  2351. //A second Create press while the first is still being answered
  2352. return;
  2353. }
  2354. if (target.filename == ""){
  2355. proceed();
  2356. return;
  2357. }
  2358. var listed = getFileObjectByName(target.filename);
  2359. if (listed != null){
  2360. if (listed.IsDir){
  2361. proceed();
  2362. }else{
  2363. showOverwriteDialog(target.filename, proceed);
  2364. }
  2365. return;
  2366. }
  2367. overwriteCheckPending = true;
  2368. $.ajax({
  2369. url: "../../system/file_system/getProperties",
  2370. method: "POST",
  2371. data: {path: target.filepath},
  2372. success: function(data){
  2373. overwriteCheckPending = false;
  2374. if (data != null && data.error === undefined && !data.IsDirectory){
  2375. showOverwriteDialog(target.filename, proceed);
  2376. }else{
  2377. //Nothing there, the name is free
  2378. proceed();
  2379. }
  2380. },
  2381. error: function(){
  2382. //Could not ask. Carry on the way the selector always has
  2383. overwriteCheckPending = false;
  2384. proceed();
  2385. }
  2386. });
  2387. }
  2388. function overwriteDialogIsOpen(){
  2389. return $("#overwriteDialog").hasClass("show");
  2390. }
  2391. function showOverwriteDialog(filename, proceed){
  2392. overwriteProceed = proceed;
  2393. $("#overwriteFile").html(smallGlyph(filename, false) +
  2394. '<span class="fsModalFileName">' + escapeHTML(filename) + '</span>');
  2395. $("#overwriteFile .fsModalFileName").attr("title", filename);
  2396. closeContextMenu();
  2397. closeMoreMenu();
  2398. $("#overwriteDialog").addClass("show");
  2399. //Cancel is the default, so a stray Enter never replaces a file
  2400. $("#overwriteCancelBtn").focus();
  2401. }
  2402. function answerOverwrite(replace){
  2403. var proceed = overwriteProceed;
  2404. overwriteProceed = null;
  2405. $("#overwriteDialog").removeClass("show");
  2406. if (replace){
  2407. if (proceed != null){
  2408. proceed();
  2409. }
  2410. return;
  2411. }
  2412. //A double clicked file stays highlighted, and a highlighted file
  2413. //would be returned again in place of the name typed next
  2414. $("#fileArea").find(".fileObject.selected").removeClass("selected");
  2415. //Back to the name field with the name part selected, ready for a new one
  2416. var input = $("#filename");
  2417. var name = input.val();
  2418. var dot = name.lastIndexOf(".");
  2419. input.focus();
  2420. input[0].setSelectionRange(0, dot > 0 ? dot : name.length);
  2421. }
  2422. //The prompt keeps the keyboard until it is answered
  2423. function handleOverwriteDialogKey(event){
  2424. if (event.which == 27){
  2425. event.preventDefault();
  2426. answerOverwrite(false);
  2427. }else if (event.which == 9){
  2428. //Tab moves between the two buttons, never to the selector behind
  2429. event.preventDefault();
  2430. var cancelBtn = document.getElementById("overwriteCancelBtn");
  2431. var replaceBtn = document.getElementById("overwriteReplaceBtn");
  2432. (document.activeElement == cancelBtn ? replaceBtn : cancelBtn).focus();
  2433. }else if (event.which == 13){
  2434. //A focused button answers through its own click. Anywhere else
  2435. //Enter takes the default answer
  2436. if ($(event.target).closest("#overwriteDialog button").length == 0){
  2437. event.preventDefault();
  2438. answerOverwrite(false);
  2439. }
  2440. }
  2441. }
  2442. function cancelSelection(){
  2443. if (selectionConfirmed || listenerUUID == ""){
  2444. return;
  2445. }
  2446. localStorage.setItem(listenerUUID, JSON.stringify("&&selection_canceled&&"));
  2447. }
  2448. function closeSelector(){
  2449. cancelSelection();
  2450. if (ao_module_virtualDesktop){
  2451. parent.closeFwProcess(ao_module_windowID);
  2452. }else{
  2453. window.close();
  2454. }
  2455. }
  2456. //Handle on window close function, cancel current selection
  2457. window.onbeforeunload = function(){
  2458. cancelSelection();
  2459. }
  2460. //Overwrite the ao_module close function so closing the float window
  2461. //cancels the selection instead of silently returning nothing
  2462. function ao_module_close(){
  2463. closeSelector();
  2464. }
  2465. /* ------------------------------------------------------------------ */
  2466. /* Details panel */
  2467. /* ------------------------------------------------------------------ */
  2468. function clearDetails(){
  2469. $("#detailsBody").html('<div class="fsDetailsEmpty">' +
  2470. escapeHTML(applocale.getString("details/empty", "Select an item to see its details")) + '</div>');
  2471. }
  2472. function updateDetailsPanel(){
  2473. updateDetailsFor($("#fileArea").find(".fileObject.selected").toArray());
  2474. }
  2475. function updateDetailsFor(objects){
  2476. if (!detailsOpen){
  2477. return;
  2478. }
  2479. if (objects == undefined || objects.length == 0){
  2480. clearDetails();
  2481. return;
  2482. }
  2483. if (objects.length > 1){
  2484. renderMultiDetails(objects);
  2485. return;
  2486. }
  2487. var target = $(objects[0]);
  2488. var filename = decodeURIComponent(target.attr("filename"));
  2489. var filepath = decodeURIComponent(target.attr("filepath"));
  2490. var isDir = target.attr("isDir") == "true";
  2491. var html = '<div class="fsDetailsPreview">' + largeGlyph(filename, isDir) + '<img class="fsThumbImg"></div>' +
  2492. '<div class="fsDetailsName">' + escapeHTML(filename) + '</div>' +
  2493. '<div id="detailRows">' +
  2494. detailRow(applocale.getString("details/type", "Type"), escapeHTML(getTypeName(filename, isDir))) +
  2495. detailRow(applocale.getString("details/size", "Size"), '<span id="detailSize">' +
  2496. escapeHTML(applocale.getString("message/loading", "Loading")) + '</span>') +
  2497. detailRow(applocale.getString("details/modified", "Date Modified"), '<span id="detailModified">--</span>') +
  2498. detailRow(applocale.getString("details/path", "Path"), escapeHTML(filepath)) +
  2499. '</div>';
  2500. $("#detailsBody").html(html);
  2501. //Reuse the thumbnail already rendered in the listing, if there is one
  2502. var existingThumb = target.find(".fsThumbImg");
  2503. if (existingThumb.length > 0 && existingThumb.hasClass("loaded")){
  2504. $("#detailsBody").find(".fsThumbImg").attr("src", existingThumb.attr("src")).addClass("loaded");
  2505. $("#detailsBody").find(".fsDetailsPreview").addClass("hasThumb");
  2506. }else if (!isDir){
  2507. loadDetailsThumbnail(filepath);
  2508. }
  2509. loadDetailProperties(filepath, filename, isDir);
  2510. }
  2511. function detailRow(key, valueHTML){
  2512. return '<div class="fsDetailRow"><div class="fsDetailKey">' + escapeHTML(key) + '</div>' +
  2513. '<div class="fsDetailVal">' + valueHTML + '</div></div>';
  2514. }
  2515. function loadDetailsThumbnail(filepath){
  2516. $.ajax({
  2517. url: "../../system/file_system/loadThumbnail",
  2518. data: {vpath: filepath},
  2519. success: function(data){
  2520. if (data == undefined || data == "" || data.error != undefined){
  2521. return;
  2522. }
  2523. var selected = $("#fileArea").find(".fileObject.selected");
  2524. //Only paint it if the user has not moved the selection on
  2525. if (selected.length == 1 && decodeURIComponent(selected.attr("filepath")) != filepath){
  2526. return;
  2527. }
  2528. $("#detailsBody").find(".fsThumbImg")
  2529. .attr("src", FileThumb.base64ToDataURL(data))
  2530. .addClass("loaded");
  2531. $("#detailsBody").find(".fsDetailsPreview").addClass("hasThumb");
  2532. }
  2533. });
  2534. }
  2535. function loadDetailProperties(filepath, filename, isDir){
  2536. $.ajax({
  2537. url: "../../system/file_system/getProperties",
  2538. method: "POST",
  2539. data: {path: filepath},
  2540. success: function(data){
  2541. if (data.error !== undefined){
  2542. $("#detailSize").text("--");
  2543. return;
  2544. }
  2545. $("#detailSize").text(data.Filesize < 0 ? "--" :
  2546. formatBytes(data.Filesize) + " (" + data.Filesize.toLocaleString() + " " +
  2547. applocale.getString("details/bytes", "bytes") + ")");
  2548. $("#detailModified").text(data.LastModTime || formatTimestamp(data.LastModUnix));
  2549. if (data.Owner != undefined && data.Owner != ""){
  2550. $("#detailRows").append(detailRow(applocale.getString("details/owner", "Owner"), escapeHTML(data.Owner)));
  2551. }
  2552. if (data.Permission != undefined && data.Permission != ""){
  2553. $("#detailRows").append(detailRow(applocale.getString("details/permission", "Permission"), escapeHTML(data.Permission)));
  2554. }
  2555. },
  2556. error: function(){
  2557. $("#detailSize").text("--");
  2558. }
  2559. });
  2560. //Show which WebApp would open this file, using the registered
  2561. //default opener of its extension
  2562. if (!isDir){
  2563. getDefaultOpener("." + getExt(filename), function(moduleInfo){
  2564. if (moduleInfo == null){
  2565. return;
  2566. }
  2567. var iconHTML = "";
  2568. if (moduleInfo.IconPath != undefined && moduleInfo.IconPath != ""){
  2569. iconHTML = '<img class="fsOpenerIcon" src="../../' + escapeHTML(moduleInfo.IconPath) +
  2570. '" onerror="this.style.display=\'none\';">';
  2571. }
  2572. $("#detailRows").append(detailRow(applocale.getString("details/opensWith", "Opens With"),
  2573. iconHTML + '<span>' + escapeHTML(moduleInfo.Name || "") + '</span>'));
  2574. });
  2575. }
  2576. }
  2577. function renderMultiDetails(objects){
  2578. var folderCount = 0;
  2579. var fileCount = 0;
  2580. for (var i = 0; i < objects.length; i++){
  2581. if ($(objects[i]).attr("isDir") == "true"){
  2582. folderCount++;
  2583. }else{
  2584. fileCount++;
  2585. }
  2586. }
  2587. var html = '<div class="fsDetailsPreview">' + largeGlyph("", true) + '</div>' +
  2588. '<div class="fsDetailsName">' + objects.length + " " +
  2589. escapeHTML(applocale.getString("details/itemsSelected", "items selected")) + '</div>' +
  2590. '<div id="detailRows">' +
  2591. detailRow(applocale.getString("details/folders", "Folders"), folderCount) +
  2592. detailRow(applocale.getString("details/files", "Files"), fileCount) +
  2593. '</div>';
  2594. $("#detailsBody").html(html);
  2595. }
  2596. /* ------------------------------------------------------------------ */
  2597. /* Sidebar */
  2598. /* ------------------------------------------------------------------ */
  2599. function initRoots(){
  2600. $.get("../../system/file_system/listRoots?user=true", function(data){
  2601. $("#userlist").html("");
  2602. if (data == null || data.error != undefined){
  2603. return;
  2604. }
  2605. for (var i = 0; i < data.length; i++){
  2606. if (data[i].IsDir != true){
  2607. continue;
  2608. }
  2609. if (data[i]["Filename"].substring(0, 1) == "."){
  2610. //Do not show hidden files
  2611. continue;
  2612. }
  2613. var iconAndFolderName = getUserRootIcons(data[i]["Filename"]);
  2614. $("#userlist").append(sidebarItem(data[i]["Filepath"], iconAndFolderName[0], iconAndFolderName[1], iconAndFolderName[2]));
  2615. }
  2616. updateSidebarActiveItem();
  2617. });
  2618. $.get("../../system/file_system/listRoots", function(data){
  2619. $("#storagelist").html("");
  2620. if (data == null || data.error != undefined){
  2621. return;
  2622. }
  2623. for (var i = 0; i < data.length; i++){
  2624. rootNameMap[data[i]["RootPath"]] = data[i]["RootName"];
  2625. $("#storagelist").append(sidebarItem(data[i]["RootPath"], ICONS.drive, "#5f6368",
  2626. data[i]["RootName"] + " (" + data[i]["RootPath"] + ")"));
  2627. }
  2628. renderBreadcrumb();
  2629. updateSidebarActiveItem();
  2630. });
  2631. }
  2632. function sidebarItem(filepath, iconSVG, iconColor, label){
  2633. return '<div class="fsSideItem" filepath="' + encodeURIComponent(filepath) + '" onclick="openShortcut(this);" title="' + escapeHTML(label) + '">' +
  2634. '<span class="fsSideIcon" style="color:' + iconColor + ';">' + iconSVG + '</span>' +
  2635. '<span class="fsSideLabel">' + escapeHTML(label) + '</span></div>';
  2636. }
  2637. //Returns [svg, colour, localized name] for a user virtual root folder
  2638. function getUserRootIcons(foldername){
  2639. var icon = ICONS.folderSide;
  2640. var color = "#f0b429";
  2641. var name = foldername;
  2642. var key = foldername.toLowerCase();
  2643. if (key == "desktop"){
  2644. icon = ICONS.desktop;
  2645. color = "#1a73e8";
  2646. name = applocale.getString("sidebar/vroot/desktop", name);
  2647. }else if (key == "document"){
  2648. icon = ICONS.document;
  2649. color = "#1a73e8";
  2650. name = applocale.getString("sidebar/vroot/document", name);
  2651. }else if (key == "music" || key == "audio"){
  2652. icon = ICONS.music;
  2653. color = "#e8467c";
  2654. name = applocale.getString("sidebar/vroot/music", name);
  2655. }else if (key == "photo" || key == "picture"){
  2656. icon = ICONS.image;
  2657. color = "#2aa3d4";
  2658. name = applocale.getString("sidebar/vroot/photo", name);
  2659. }else if (key == "video" || key == "film"){
  2660. icon = ICONS.video;
  2661. color = "#8b5cf6";
  2662. name = applocale.getString("sidebar/vroot/video", name);
  2663. }else if (key == "trash" || key == "bin" || key == "rubbish"){
  2664. icon = ICONS.trash;
  2665. color = "#5f6368";
  2666. name = applocale.getString("sidebar/vroot/trash", name);
  2667. }else if (key == "download"){
  2668. icon = ICONS.download;
  2669. color = "#1a73e8";
  2670. name = applocale.getString("sidebar/vroot/download", name);
  2671. }else if (key == "www" || key == "web" || key == "mysite"){
  2672. icon = ICONS.globe;
  2673. color = "#0f9d94";
  2674. name = applocale.getString("sidebar/vroot/web", name);
  2675. }else if (key == "model"){
  2676. icon = ICONS.cube;
  2677. color = "#7c4dff";
  2678. name = applocale.getString("sidebar/vroot/model", name);
  2679. }else if (key == "appdata"){
  2680. icon = ICONS.code;
  2681. color = "#5f6368";
  2682. name = applocale.getString("sidebar/vroot/appdata", name);
  2683. }
  2684. return [icon, color, name];
  2685. }
  2686. function openShortcut(object){
  2687. var targetdir = decodeURIComponent($(object).attr("filepath"));
  2688. listDir(targetdir);
  2689. if (window.innerWidth < 560){
  2690. closeSidebar();
  2691. }
  2692. }
  2693. function updateSidebarActiveItem(){
  2694. $(".fsSideItem").each(function(){
  2695. var itemPath = decodeURIComponent($(this).attr("filepath"));
  2696. if (itemPath.substring(itemPath.length - 1) != "/"){
  2697. itemPath = itemPath + "/";
  2698. }
  2699. var here = currentDir;
  2700. if (here.substring(here.length - 1) != "/"){
  2701. here = here + "/";
  2702. }
  2703. $(this).toggleClass("active", itemPath == here);
  2704. });
  2705. }
  2706. function toggleSidebar(){
  2707. if ($("#sidebar").hasClass("open")){
  2708. closeSidebar();
  2709. }else{
  2710. $("#sidebar").addClass("open");
  2711. $("#sidebarScrim").addClass("show");
  2712. }
  2713. }
  2714. function closeSidebar(){
  2715. $("#sidebar").removeClass("open");
  2716. $("#sidebarScrim").removeClass("show");
  2717. }
  2718. /* ------------------------------------------------------------------ */
  2719. /* Sidebar resizing */
  2720. /* ------------------------------------------------------------------ */
  2721. /*
  2722. Same behaviour as the file manager's pane splitter
  2723. (js/explorer/splitter.js): drag the sidebar edge to resize it and the
  2724. width is remembered between visits. Remembered per browser rather than
  2725. per account, as it describes this window on this screen.
  2726. */
  2727. var FS_SIDEBAR_WIDTH_KEY = "file_selector/sidebarWidth";
  2728. var FS_SIDEBAR_DEFAULT_WIDTH = 200; //must match the width in the stylesheet
  2729. var FS_SIDEBAR_MIN_WIDTH = 150; //below this the root names are unreadable
  2730. var FS_SIDEBAR_MAX_WIDTH = 420;
  2731. var FS_MAIN_MIN_WIDTH = 280; //the file list never shrinks past this
  2732. var FS_SIDEBAR_DRAWER_WIDTH = 560; //matches the overlay media query
  2733. /*
  2734. The width the user asked for, which is not always the width on screen:
  2735. a narrow window can clamp it down. Kept unclamped so the sidebar springs
  2736. back to the chosen size once there is room for it again.
  2737. */
  2738. var sidebarPreferredWidth = FS_SIDEBAR_DEFAULT_WIDTH;
  2739. //Below this width the sidebar is a drawer over the file list, not a column
  2740. function sidebarIsDrawer(){
  2741. return window.innerWidth < FS_SIDEBAR_DRAWER_WIDTH;
  2742. }
  2743. /*
  2744. How wide the sidebar may get right now. The ceiling is not a fixed
  2745. number: it also has to leave FS_MAIN_MIN_WIDTH for the file list, so in
  2746. a small float window it comes down rather than letting a drag squeeze
  2747. the listing away.
  2748. */
  2749. function sidebarWidthLimits(){
  2750. var available = $(".fsBody").width() - FS_MAIN_MIN_WIDTH;
  2751. return {
  2752. min: FS_SIDEBAR_MIN_WIDTH,
  2753. max: Math.min(FS_SIDEBAR_MAX_WIDTH, available)
  2754. };
  2755. }
  2756. function clampSidebarWidth(width){
  2757. var limits = sidebarWidthLimits();
  2758. var applied = Math.round(width);
  2759. if (isNaN(applied)){
  2760. applied = FS_SIDEBAR_DEFAULT_WIDTH;
  2761. }
  2762. if (limits.max < limits.min){
  2763. //Window too narrow to honour both bounds: the floor wins, otherwise
  2764. //the sidebar would collapse to nothing
  2765. return limits.min;
  2766. }
  2767. return Math.max(limits.min, Math.min(limits.max, applied));
  2768. }
  2769. /*
  2770. Writes width and min-width together: the sidebar carries a min-width in
  2771. the stylesheet to stop flexbox shrinking it, and leaving that behind
  2772. would silently pin the pane at its old size on the way down.
  2773. */
  2774. function writeSidebarWidth(applied){
  2775. $("#sidebar").css({
  2776. "width": applied + "px",
  2777. "min-width": applied + "px"
  2778. });
  2779. }
  2780. //The drag path: what the user drags to becomes the remembered width
  2781. function setSidebarWidth(width){
  2782. sidebarPreferredWidth = clampSidebarWidth(width);
  2783. writeSidebarWidth(sidebarPreferredWidth);
  2784. return sidebarPreferredWidth;
  2785. }
  2786. /*
  2787. Re-applies the preferred width to the DOM. Also the window resize path: a
  2788. width that was legal in a bigger window can be over the ceiling in a
  2789. smaller one - and back under it when the window grows again, which is why
  2790. this clamps the preference rather than overwriting it. In the drawer
  2791. layout the inline width is dropped entirely, so the overlay keeps the
  2792. size the stylesheet gives it.
  2793. */
  2794. function applySidebarWidth(){
  2795. if (sidebarIsDrawer()){
  2796. $("#sidebar").css({ "width": "", "min-width": "" });
  2797. $("#sidebarSplitter").hide();
  2798. return;
  2799. }
  2800. $("#sidebarSplitter").show();
  2801. writeSidebarWidth(clampSidebarWidth(sidebarPreferredWidth));
  2802. }
  2803. function saveSidebarWidth(width){
  2804. try {
  2805. localStorage.setItem(FS_SIDEBAR_WIDTH_KEY, String(Math.round(width)));
  2806. } catch (e){
  2807. //Private browsing or a full store - the width simply is not remembered
  2808. }
  2809. }
  2810. function initSidebarSplitter(){
  2811. var stored = null;
  2812. try {
  2813. stored = localStorage.getItem(FS_SIDEBAR_WIDTH_KEY);
  2814. } catch (e){
  2815. stored = null;
  2816. }
  2817. if (stored != null && stored != ""){
  2818. var restored = parseInt(stored);
  2819. if (!isNaN(restored) && restored > 0){
  2820. sidebarPreferredWidth = restored;
  2821. }
  2822. }
  2823. //Clamped on the way in, so a width saved on a wider screen still fits here
  2824. applySidebarWidth();
  2825. var handle = document.getElementById("sidebarSplitter");
  2826. if (handle == null){
  2827. return;
  2828. }
  2829. /*
  2830. Pointer events rather than mousedown/mousemove: setPointerCapture
  2831. keeps the drag alive when the cursor leaves the window, which a
  2832. document level mousemove listener does not.
  2833. */
  2834. handle.addEventListener("pointerdown", function(evt){
  2835. if (evt.button != 0 || sidebarIsDrawer()){
  2836. return;
  2837. }
  2838. //Stops the drag from selecting text across the panes
  2839. evt.preventDefault();
  2840. var startX = evt.clientX;
  2841. var startWidth = $("#sidebar").outerWidth();
  2842. /*
  2843. Capture is an optimisation, not a requirement - the listeners
  2844. below are on the handle itself. It throws if the pointer is no
  2845. longer active by the time this runs, which must not abort the drag.
  2846. */
  2847. try { handle.setPointerCapture(evt.pointerId); } catch(e) {}
  2848. handle.classList.add("dragging");
  2849. //Suppresses hover effects and text selection everywhere for the drag
  2850. $("body").addClass("fsResizing");
  2851. function onMove(e){
  2852. setSidebarWidth(startWidth + (e.clientX - startX));
  2853. }
  2854. function onEnd(){
  2855. try { handle.releasePointerCapture(evt.pointerId); } catch(e) {}
  2856. handle.removeEventListener("pointermove", onMove);
  2857. handle.removeEventListener("pointerup", onEnd);
  2858. handle.removeEventListener("pointercancel", onEnd);
  2859. handle.classList.remove("dragging");
  2860. $("body").removeClass("fsResizing");
  2861. //Saved on release rather than on every move, so a drag writes once
  2862. saveSidebarWidth(sidebarPreferredWidth);
  2863. //The grid view fits its tiles to the width of the file area
  2864. updateFileAreaDensity();
  2865. }
  2866. handle.addEventListener("pointermove", onMove);
  2867. handle.addEventListener("pointerup", onEnd);
  2868. handle.addEventListener("pointercancel", onEnd);
  2869. });
  2870. }
  2871. /* ------------------------------------------------------------------ */
  2872. /* New folder */
  2873. /* ------------------------------------------------------------------ */
  2874. function menuNewFolder(){
  2875. closeMoreMenu();
  2876. newFolder();
  2877. }
  2878. /*
  2879. Creates the folder straight away under a localized default name, then
  2880. drops the freshly created item into inline edit so the user can type
  2881. over it - the same flow as the desktop file managers.
  2882. */
  2883. function newFolder(){
  2884. createFolder(getUniqueNewFolderName(), true);
  2885. }
  2886. //"New Folder", "New Folder (2)", ... so the create never collides
  2887. function getUniqueNewFolderName(){
  2888. var base = applocale.getString("newfolder/defaultname", "New Folder");
  2889. var taken = {};
  2890. currentFileList.forEach(function(fileObject){
  2891. taken[fileObject.Filename] = true;
  2892. });
  2893. if (taken[base] == undefined){
  2894. return base;
  2895. }
  2896. var counter = 2;
  2897. while (taken[base + " (" + counter + ")"] != undefined){
  2898. counter++;
  2899. }
  2900. return base + " (" + counter + ")";
  2901. }
  2902. function createFolder(folderName, editAfterCreate){
  2903. if (folderName == undefined || folderName.trim() == ""){
  2904. folderName = applocale.getString("newfolder/defaultname", "New Folder");
  2905. }
  2906. folderName = folderName.trim().replace(/[<>:"/\\|?*]/g, "_");
  2907. //Check if folder exists
  2908. var nameAlreadyExists = false;
  2909. currentFileList.forEach(function(fileObject){
  2910. if (fileObject.IsDir && fileObject.Filename == folderName){
  2911. nameAlreadyExists = true;
  2912. }
  2913. });
  2914. if (nameAlreadyExists){
  2915. alert(applocale.getString("message/folderexists", "Folder already exists"));
  2916. return;
  2917. }
  2918. //Create the new folder request
  2919. requestCSRFToken(function(token){
  2920. $.ajax({
  2921. url: "../../system/file_system/newItem",
  2922. data: {type: "folder", src: currentDir, filename: folderName, csrft: token},
  2923. success: function(data){
  2924. if (data.error !== undefined){
  2925. alert(data.error);
  2926. return;
  2927. }
  2928. if (editAfterCreate){
  2929. //Picked up by renderFileList once the listing comes back
  2930. pendingInlineRename = folderName;
  2931. }
  2932. refresh();
  2933. }
  2934. });
  2935. });
  2936. }
  2937. /* ------------------------------------------------------------------ */
  2938. /* Inline rename */
  2939. /* ------------------------------------------------------------------ */
  2940. var pendingInlineRename = null; //Filename to edit after the next render
  2941. var inlineEditActive = false;
  2942. var closeActiveInlineEdit = null; //Set while an editor is on screen
  2943. function findFileObjectByName(filename){
  2944. var match = null;
  2945. $("#fileArea").find(".fileObject").each(function(){
  2946. if (decodeURIComponent($(this).attr("filename")) == filename){
  2947. match = this;
  2948. }
  2949. });
  2950. return match;
  2951. }
  2952. function startInlineRename(fileObjectDOM){
  2953. if (fileObjectDOM == null){
  2954. return;
  2955. }
  2956. if (inlineEditActive && closeActiveInlineEdit != null){
  2957. //Commit whatever is already being edited rather than refusing.
  2958. //If focus never landed on that editor its blur would never fire
  2959. //and the flag would stay stuck, blocking every later rename.
  2960. closeActiveInlineEdit(true);
  2961. }
  2962. var target = $(fileObjectDOM);
  2963. //List view labels the name in .fsRowName, grid view in .fsTileName
  2964. var label = target.find(".fsRowName");
  2965. if (label.length == 0){
  2966. label = target.find(".fsTileName");
  2967. }
  2968. if (label.length == 0){
  2969. return;
  2970. }
  2971. var originalName = decodeURIComponent(target.attr("filename"));
  2972. var isDir = target.attr("isDir") == "true";
  2973. inlineEditActive = true;
  2974. label.addClass("editing");
  2975. label.html('<input class="fsInlineEdit" type="text" spellcheck="false" autocomplete="off">');
  2976. var input = label.find("input");
  2977. input.val(originalName);
  2978. //Swallow the row click handlers while the editor has focus
  2979. input.on("click dblclick mousedown", function(event){
  2980. event.stopPropagation();
  2981. });
  2982. var settled = false;
  2983. var finish = function(save){
  2984. if (settled){
  2985. //Enter commits and then blurs, guard the second pass
  2986. return;
  2987. }
  2988. settled = true;
  2989. inlineEditActive = false;
  2990. closeActiveInlineEdit = null;
  2991. var newName = input.val();
  2992. label.removeClass("editing");
  2993. label.text(originalName);
  2994. if (save && newName != undefined && newName.trim() != "" && newName.trim() != originalName){
  2995. commitInlineRename(target, originalName, newName.trim());
  2996. }
  2997. };
  2998. closeActiveInlineEdit = finish;
  2999. input.on("keydown", function(event){
  3000. event.stopPropagation();
  3001. if (event.which == 13){
  3002. finish(true);
  3003. }else if (event.which == 27){
  3004. finish(false);
  3005. }
  3006. });
  3007. input.on("blur", function(){
  3008. //Clicking away saves, matching the desktop file managers
  3009. finish(true);
  3010. });
  3011. input.focus();
  3012. //Preselect the basename so typing replaces the name but keeps the
  3013. //extension, except on folders where the whole name is the target
  3014. var dotIndex = originalName.lastIndexOf(".");
  3015. if (!isDir && dotIndex > 0){
  3016. input[0].setSelectionRange(0, dotIndex);
  3017. }else{
  3018. input[0].select();
  3019. }
  3020. }
  3021. function commitInlineRename(target, originalName, newName){
  3022. var safeName = newName.replace(/[<>:"/\\|?*]/g, "_");
  3023. var filepath = decodeURIComponent(target.attr("filepath"));
  3024. //Reject a name that is already used in this directory
  3025. var clash = false;
  3026. currentFileList.forEach(function(fileObject){
  3027. if (fileObject.Filename == safeName && fileObject.Filename != originalName){
  3028. clash = true;
  3029. }
  3030. });
  3031. if (clash){
  3032. alert(applocale.getString("message/nameexists", "An item with that name already exists"));
  3033. return;
  3034. }
  3035. requestCSRFToken(function(token){
  3036. $.ajax({
  3037. url: "../../system/file_system/fileOpr",
  3038. method: "POST",
  3039. data: {
  3040. opr: "rename",
  3041. src: JSON.stringify([filepath]),
  3042. new: JSON.stringify([safeName]),
  3043. csrft: token
  3044. },
  3045. success: function(data){
  3046. if (data.error !== undefined){
  3047. alert(data.error);
  3048. refresh();
  3049. return;
  3050. }
  3051. //Keep the renamed item highlighted after the reload
  3052. pendingSelectAfterRender = safeName;
  3053. refresh();
  3054. },
  3055. error: function(){
  3056. alert(applocale.getString("message/renamefailed", "Rename failed"));
  3057. refresh();
  3058. }
  3059. });
  3060. });
  3061. }
  3062. function requestCSRFToken(callback){
  3063. $.ajax({
  3064. url: "../../system/csrf/new",
  3065. success: function(token){
  3066. callback(token);
  3067. }
  3068. });
  3069. }
  3070. /* ------------------------------------------------------------------ */
  3071. /* Context menu */
  3072. /* ------------------------------------------------------------------ */
  3073. /*
  3074. Acts on the single item that was right clicked rather than on the
  3075. current selection. The selector restricts what may be selected by
  3076. launch type (a file cannot be highlighted in folder mode, and so on),
  3077. so binding the menu to one explicit target keeps destructive actions
  3078. such as Delete unambiguous.
  3079. */
  3080. var contextTarget = null;
  3081. function showContextMenu(event, fileObjectDOM){
  3082. event.preventDefault();
  3083. event.stopPropagation();
  3084. if (inlineEditActive){
  3085. return;
  3086. }
  3087. contextTarget = fileObjectDOM;
  3088. closeMoreMenu();
  3089. var isDir = $(fileObjectDOM).attr("isDir") == "true";
  3090. var menu = $("#contextMenu");
  3091. menu.html(buildContextMenuItems(isDir));
  3092. menu.addClass("open");
  3093. positionContextMenu(menu, event);
  3094. }
  3095. /*
  3096. Right click on empty space acts on the folder being browsed
  3097. rather than on any item, so it offers the two things that make
  3098. sense there. The per item handler above stops propagation, so
  3099. this only ever runs for a click that missed every file object.
  3100. */
  3101. function showFolderContextMenu(event){
  3102. event.preventDefault();
  3103. event.stopPropagation();
  3104. if (inlineEditActive){
  3105. return;
  3106. }
  3107. //No item is involved - onContextAction keys off this being null
  3108. contextTarget = null;
  3109. closeMoreMenu();
  3110. var menu = $("#contextMenu");
  3111. menu.html(buildFolderContextMenuItems());
  3112. menu.addClass("open");
  3113. positionContextMenu(menu, event);
  3114. }
  3115. function buildFolderContextMenuItems(){
  3116. var items = [];
  3117. items.push(contextMenuItem("newfolder", "folder outline",
  3118. applocale.getString("ctx/newfolder", "New Folder")));
  3119. items.push('<div class="fsMenuSep"></div>');
  3120. items.push(contextMenuItem("folderproperties", "",
  3121. applocale.getString("ctx/folderproperties", "Folder Properties")));
  3122. return items.join("");
  3123. }
  3124. //Clamp to the viewport so a menu never opens off screen
  3125. function positionContextMenu(menu, event){
  3126. var width = menu.outerWidth();
  3127. var height = menu.outerHeight();
  3128. var left = event.clientX;
  3129. var top = event.clientY;
  3130. if (left + width > window.innerWidth - 6){
  3131. left = Math.max(6, window.innerWidth - width - 6);
  3132. }
  3133. if (top + height > window.innerHeight - 6){
  3134. top = Math.max(6, window.innerHeight - height - 6);
  3135. }
  3136. menu.css({left: left + "px", top: top + "px"});
  3137. }
  3138. /*
  3139. Glyph per row is taken from the File Manager's context menu so the two
  3140. menus read the same: Open, Rename and Properties carry none there, and
  3141. both "open elsewhere" rows share the external link arrow.
  3142. */
  3143. function buildContextMenuItems(isDir){
  3144. var items = [];
  3145. items.push(contextMenuItem("open", "", applocale.getString("ctx/open", "Open")));
  3146. if (!isDir){
  3147. items.push(contextMenuItem("openwith", "external", applocale.getString("ctx/openwith", "Open With")));
  3148. }else{
  3149. items.push(contextMenuItem("opennewwindow", "external",
  3150. applocale.getString("ctx/opennewwindow", "Open in New Window")));
  3151. }
  3152. items.push('<div class="fsMenuSep"></div>');
  3153. items.push(contextMenuItem("rename", "", applocale.getString("ctx/rename", "Rename")));
  3154. items.push(contextMenuItem("delete", "trash", applocale.getString("ctx/delete", "Delete")));
  3155. items.push(contextMenuItem("download", "download", applocale.getString("ctx/download", "Download")));
  3156. items.push('<div class="fsMenuSep"></div>');
  3157. items.push(contextMenuItem("properties", "", applocale.getString("ctx/properties", "Properties")));
  3158. return items.join("");
  3159. }
  3160. /*
  3161. iconClass is a Semantic UI icon name without the trailing "icon", or an
  3162. empty string for the rows the File Manager draws without a glyph
  3163. (Open, Rename, Properties).
  3164. */
  3165. function contextMenuItem(action, iconClass, label){
  3166. return '<div class="fsMenuItem" onclick="onContextAction(\'' + action + '\');">' +
  3167. '<span>' + escapeHTML(label) + '</span>' +
  3168. (iconClass == "" ? "" : '<i class="' + iconClass + ' icon"></i>') +
  3169. '</div>';
  3170. }
  3171. function closeContextMenu(){
  3172. $("#contextMenu").removeClass("open");
  3173. }
  3174. function onContextAction(action){
  3175. var target = contextTarget;
  3176. closeContextMenu();
  3177. /*
  3178. Folder level actions come from the empty space menu and have
  3179. no target, so they are handled before the guard below.
  3180. */
  3181. if (action == "newfolder"){
  3182. newFolder();
  3183. return;
  3184. }else if (action == "folderproperties"){
  3185. ctxProperties(currentDir);
  3186. return;
  3187. }
  3188. if (target == null){
  3189. return;
  3190. }
  3191. var filepath = decodeURIComponent($(target).attr("filepath"));
  3192. var filename = decodeURIComponent($(target).attr("filename"));
  3193. var isDir = $(target).attr("isDir") == "true";
  3194. if (action == "open"){
  3195. //Same as a double click: enter the folder, or pick the file
  3196. openThis(target, {preventDefault: function(){}});
  3197. }else if (action == "openwith"){
  3198. ctxOpenWith(filepath, filename);
  3199. }else if (action == "opennewwindow"){
  3200. ctxOpenInNewWindow(filepath, filename);
  3201. }else if (action == "rename"){
  3202. startInlineRename(target);
  3203. }else if (action == "delete"){
  3204. ctxDelete(filepath, filename);
  3205. }else if (action == "download"){
  3206. ctxDownload(filepath, filename, isDir);
  3207. }else if (action == "properties"){
  3208. ctxProperties(filepath);
  3209. }
  3210. }
  3211. //Launch the opener picker so the user chooses which WebApp handles it
  3212. function ctxOpenWith(filepath, filename){
  3213. var openParameter = encodeURIComponent(JSON.stringify({
  3214. filepath: filepath,
  3215. filename: filename
  3216. }));
  3217. ao_module_newfw({
  3218. url: "SystemAO/file_system/defaultOpener.html#" + openParameter,
  3219. width: 380,
  3220. height: 560,
  3221. appicon: "SystemAO/file_system/img/opener.png",
  3222. title: "Select an opener WebApp"
  3223. });
  3224. }
  3225. //Open this folder in its own File Manager window, leaving the picker alone
  3226. function ctxOpenInNewWindow(filepath, filename){
  3227. ao_module_newfw({
  3228. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(filepath),
  3229. width: 1080,
  3230. height: 580,
  3231. appicon: "SystemAO/file_system/img/small_icon.png",
  3232. title: filename
  3233. });
  3234. }
  3235. function ctxDelete(filepath, filename){
  3236. var question = applocale.getString("message/deleteconfirm", "Move this item to the trash bin?");
  3237. if (!confirm(question + "\n\n" + filename)){
  3238. return;
  3239. }
  3240. requestCSRFToken(function(token){
  3241. $.ajax({
  3242. url: "../../system/file_system/fileOpr",
  3243. method: "POST",
  3244. data: {opr: "recycle", src: JSON.stringify([filepath]), csrft: token},
  3245. success: function(data){
  3246. if (data.error !== undefined){
  3247. alert(data.error);
  3248. }
  3249. refresh();
  3250. },
  3251. error: function(){
  3252. alert(applocale.getString("message/deletefailed", "Delete failed"));
  3253. refresh();
  3254. }
  3255. });
  3256. });
  3257. }
  3258. function ctxDownload(filepath, filename, isDir){
  3259. if (!isDir){
  3260. //Single file, stream it straight down
  3261. generateDownloadFromURL("../../media/download?file=" + encodeURIComponent(filepath), filename);
  3262. return;
  3263. }
  3264. //Folders have to be archived first, same as the File Manager does
  3265. $.ajax({
  3266. url: "../../system/file_system/zipHandler",
  3267. method: "POST",
  3268. data: {opr: "tmpzip", src: JSON.stringify([filepath]), dest: ""},
  3269. success: function(data){
  3270. if (data.error !== undefined){
  3271. alert(data.error);
  3272. return;
  3273. }
  3274. generateDownloadFromURL("../../media/download?file=" + encodeURIComponent(data), filename + ".zip");
  3275. },
  3276. error: function(){
  3277. alert(applocale.getString("message/zipfailed", "Unable to compress this folder"));
  3278. }
  3279. });
  3280. }
  3281. function generateDownloadFromURL(url, filename){
  3282. var a = document.createElement("a");
  3283. a.href = url;
  3284. a.download = filename;
  3285. document.body.appendChild(a);
  3286. a.click();
  3287. document.body.removeChild(a);
  3288. }
  3289. function ctxProperties(filepath){
  3290. ao_module_newfw({
  3291. url: "SystemAO/file_system/file_properties.html#" + encodeURIComponent(JSON.stringify([filepath])),
  3292. width: 440,
  3293. height: 560,
  3294. appicon: "SystemAO/file_system/img/properties.png",
  3295. title: "File Properties"
  3296. });
  3297. }
  3298. /* ------------------------------------------------------------------ */
  3299. /* Toolbar menu */
  3300. /* ------------------------------------------------------------------ */
  3301. function toggleMoreMenu(event){
  3302. event.stopPropagation();
  3303. var isOpen = $("#moreMenu").hasClass("open");
  3304. if (isOpen){
  3305. closeMoreMenu();
  3306. }else{
  3307. $("#moreMenu").addClass("open");
  3308. $("#moreBtn").addClass("active");
  3309. }
  3310. }
  3311. function closeMoreMenu(){
  3312. $("#moreMenu").removeClass("open");
  3313. $("#moreBtn").removeClass("active");
  3314. }
  3315. $(document).on("click", function(event){
  3316. if ($(event.target).closest("#moreMenu, #moreBtn").length == 0){
  3317. closeMoreMenu();
  3318. }
  3319. if ($(event.target).closest("#contextMenu").length == 0){
  3320. closeContextMenu();
  3321. }
  3322. });
  3323. //A right click anywhere else dismisses an open context menu
  3324. $(document).on("contextmenu", function(event){
  3325. if ($(event.target).closest(".fileObject").length == 0){
  3326. closeContextMenu();
  3327. }
  3328. });
  3329. $("#fileArea").on("scroll", function(){
  3330. closeContextMenu();
  3331. });
  3332. /* ------------------------------------------------------------------ */
  3333. /* Search */
  3334. /* ------------------------------------------------------------------ */
  3335. var searchDebounce = null;
  3336. $("#searchInput").on("input", function(){
  3337. var value = $(this).val().toLowerCase().trim();
  3338. clearTimeout(searchDebounce);
  3339. searchDebounce = setTimeout(function(){
  3340. searchKeyword = value;
  3341. renderFileList();
  3342. }, 150);
  3343. });
  3344. /* ------------------------------------------------------------------ */
  3345. /* Keyboard */
  3346. /* ------------------------------------------------------------------ */
  3347. //Ctrl, or Cmd on a Mac (keyCode 91 / 93, or 224 in Firefox)
  3348. function isMultiSelectKey(event){
  3349. if (isMacOS){
  3350. return event.key == "Meta" || event.which == 91 || event.which == 93 || event.which == 224;
  3351. }
  3352. return event.which == 17;
  3353. }
  3354. $(window).on("keydown", function(event){
  3355. if (isMultiSelectKey(event)){
  3356. ctrlDown = true;
  3357. }else if (event.which == 16){
  3358. shiftDown = true;
  3359. }else if (overwriteDialogIsOpen()){
  3360. handleOverwriteDialogKey(event);
  3361. }else if (event.which == 27){
  3362. //Escape backs out of the transient UI first, and only closes the
  3363. //whole dialog when there is nothing left to dismiss
  3364. if ($("#contextMenu").hasClass("open")){
  3365. closeContextMenu();
  3366. return;
  3367. }
  3368. if (inlineEditActive || $("#moreMenu").hasClass("open")){
  3369. closeMoreMenu();
  3370. return;
  3371. }
  3372. closeSelector();
  3373. }else if (event.which == 13){
  3374. if ($(event.target).is("#addressbar") || inlineEditActive){
  3375. return;
  3376. }
  3377. closeContextMenu();
  3378. //Enter opens the highlighted folder, or confirms the selection
  3379. var selected = $("#fileArea").find(".fileObject.selected");
  3380. if (selected.length == 1 && selected.attr("isDir") == "true" && type != "folder"){
  3381. listDir(decodeURIComponent(selected.attr("filepath")));
  3382. }else{
  3383. confirmSelection();
  3384. if (overwriteDialogIsOpen()){
  3385. //The prompt took focus during this key press. Without this
  3386. //its keypress would land on Cancel and answer it at once
  3387. event.preventDefault();
  3388. }
  3389. }
  3390. }
  3391. });
  3392. $(window).on("keyup", function(event){
  3393. if (isMultiSelectKey(event)){
  3394. ctrlDown = false;
  3395. }else if (event.which == 16){
  3396. shiftDown = false;
  3397. }
  3398. });
  3399. //A modifier released in another window (Cmd + Tab) never sends its
  3400. //keyup here, which would leave every later click multi-selecting
  3401. $(window).on("blur", function(){
  3402. ctrlDown = false;
  3403. shiftDown = false;
  3404. });
  3405. //Clicking the empty area of the file list clears the selection
  3406. $("#fileArea").on("click", function(event){
  3407. if ($(event.target).closest(".fileObject, .fsListHead").length == 0){
  3408. $(".fileObject.selected").removeClass("selected");
  3409. setWindowTitleForSelection(0);
  3410. clearDetails();
  3411. }
  3412. });
  3413. //Runs here rather than with the other init calls at the top of this
  3414. //script: the FS_SIDEBAR_* values above are var declarations, so they
  3415. //only hold their values once execution has reached them
  3416. initSidebarSplitter();
  3417. $(window).on("resize", function(){
  3418. if (window.innerWidth >= 560){
  3419. closeSidebar();
  3420. }
  3421. applySidebarWidth();
  3422. updateFileAreaDensity();
  3423. });
  3424. </script>
  3425. </body>
  3426. </html>