| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697 |
- <!DOCTYPE html>
- <html>
- <head>
- <title locale="title">File Selector</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
- <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
- <link rel="stylesheet" href="../../script/ao.css">
- <script type="text/javascript" src="../../script/jquery.min.js"></script>
- <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
- <script type="text/javascript" src="../../script/ao_module.js"></script>
- <script type="text/javascript" src="../../script/applocale.js"></script>
- <!-- File icon / thumbnail logic shared with the File Manager -->
- <!-- Design tokens and components shared with the File Manager -->
- <link rel="stylesheet" href="shared/fs-theme.css">
- <link rel="stylesheet" href="shared/fs-components.css">
- <script type="text/javascript" src="shared/filethumb.js"></script>
- <style>
- /*
- ArozOS File Selector
- Redesigned dialog shell. Everything in here is scoped under #fsRoot
- so the Semantic UI base sheet (kept for ao_module compatibility)
- cannot bleed into the new layout.
- */
- html, body{
- height: 100%;
- margin: 0;
- padding: 0;
- overflow: hidden;
- background: #ffffff;
- }
- body.darkTheme{ background: #202124; }
- #fsRoot{
- /* Palette comes from shared/fs-theme.css */
- position: absolute;
- top: 0; left: 0; right: 0; bottom: 0;
- display: flex;
- flex-direction: column;
- background: var(--fs-bg);
- color: var(--fs-text);
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", Roboto, Helvetica, Arial, sans-serif;
- font-size: 14px;
- -webkit-font-smoothing: antialiased;
- user-select: none;
- }
- #fsRoot *{
- box-sizing: border-box;
- }
- #fsRoot svg{
- display: block;
- width: 100%;
- height: 100%;
- }
- /* ---------- Title bar ---------- */
- .fsTitlebar{
- display: flex;
- align-items: center;
- gap: 9px;
- padding: 10px 12px 6px 14px;
- flex-shrink: 0;
- }
- .fsTitlebar .fsTitleIcon{
- width: 20px;
- height: 20px;
- color: var(--fs-accent);
- flex-shrink: 0;
- }
- .fsTitlebar .fsTitleText{
- font-size: 15px;
- font-weight: 600;
- flex-grow: 1;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- }
- /* ---------- Navigation row ---------- */
- .fsNav{
- display: flex;
- align-items: center;
- gap: 8px;
- padding: 6px 14px 6px 14px;
- flex-shrink: 0;
- }
- .fsNavBtns{
- display: flex;
- align-items: center;
- gap: 4px;
- flex-shrink: 0;
- }
- .fsNavDivider{
- width: 1px;
- height: 18px;
- background: var(--fs-line);
- margin: 0 4px;
- }
- .fsPathbar{ flex-grow: 1; }
- .fsPathbar .fsPathIcon{
- width: 18px;
- height: 18px;
- color: var(--fs-icon);
- flex-shrink: 0;
- }
- .fsCrumbs{
- display: flex;
- align-items: center;
- gap: 2px;
- flex-grow: 1;
- min-width: 0;
- overflow: hidden;
- white-space: nowrap;
- }
- .fsCrumb{
- padding: 3px 7px;
- border-radius: 6px;
- cursor: pointer;
- color: var(--fs-text);
- font-size: 14px;
- max-width: 220px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .fsCrumb:hover{ background: var(--fs-fill); }
- .fsCrumb.last{ font-weight: 600; }
- .fsCrumbSep{
- color: var(--fs-text-faint);
- font-size: 13px;
- flex-shrink: 0;
- pointer-events: none;
- }
- .fsCrumbPad{
- flex-grow: 1;
- min-width: 14px;
- align-self: stretch;
- cursor: text;
- }
- #addressbar{
- display: none;
- flex-grow: 1;
- min-width: 0;
- border: none;
- outline: none;
- background: transparent;
- font-size: 14px;
- font-family: inherit;
- color: var(--fs-text);
- padding: 4px 2px;
- user-select: text;
- }
- .fsPathbar.editing .fsCrumbs{ display: none; }
- .fsPathbar.editing #addressbar{ display: block; }
- .fsSearch{
- width: 260px;
- flex-shrink: 0;
- padding-right: 10px;
- }
- .fsSearch input{
- flex-grow: 1;
- min-width: 0;
- border: none;
- outline: none;
- background: transparent;
- font-size: 14px;
- font-family: inherit;
- color: var(--fs-text);
- user-select: text;
- }
- .fsSearch .fsSearchIcon{
- width: 17px;
- height: 17px;
- color: var(--fs-text-dim);
- flex-shrink: 0;
- }
- /* ---------- Body ---------- */
- .fsBody{
- flex-grow: 1;
- display: flex;
- min-height: 0;
- border-top: 1px solid var(--fs-line);
- }
- /* ---------- Sidebar ---------- */
- .fsSidebar{
- flex: 0 0 auto;
- width: 200px;
- min-width: 200px;
- padding: 10px 8px 10px 10px;
- overflow-y: auto;
- overflow-x: hidden;
- background: var(--fs-bg);
- border-right: 1px solid var(--fs-line);
- }
- .fsSideTitle{
- font-size: 12px;
- color: var(--fs-text-faint);
- padding: 4px 8px;
- margin-top: 4px;
- }
- .fsSideTitle:first-child{ margin-top: 0; }
- .fsSideItem{
- display: flex;
- align-items: center;
- gap: 10px;
- padding: 5px 8px;
- border-radius: 7px;
- cursor: pointer;
- white-space: nowrap;
- overflow: hidden;
- }
- .fsSideItem:hover{ background: var(--fs-fill); }
- .fsSideItem.active{ background: var(--fs-accent-soft); color: var(--fs-accent-strong); }
- .fsSideItem .fsSideIcon{
- width: 20px;
- height: 20px;
- min-width: 20px;
- }
- .fsSideItem .fsSideLabel{
- overflow: hidden;
- text-overflow: ellipsis;
- }
- /* ---------- Sidebar splitter ---------- */
- /*
- Drag handle on the sidebar / file list boundary. It is pulled back
- over the sidebar border with negative margins, so widening the grab
- area does not push the panes apart.
- */
- .fsSplitter{
- flex: 0 0 auto;
- align-self: stretch;
- width: 7px;
- margin-left: -4px;
- margin-right: -3px;
- position: relative;
- z-index: 100;
- cursor: col-resize;
- background: transparent;
- transition: background-color 0.12s ease;
- }
- .fsSplitter:hover,
- .fsSplitter.dragging{
- background: var(--fs-accent);
- opacity: 0.5;
- }
- /*
- While dragging, the pointer keeps crossing the panes either side of
- the handle. Without this the cursor flickers back to the default and
- stray text gets selected on the way past.
- */
- body.fsResizing{
- cursor: col-resize;
- user-select: none;
- -webkit-user-select: none;
- }
- body.fsResizing *{
- cursor: col-resize !important;
- user-select: none;
- -webkit-user-select: none;
- }
- /* ---------- Main column ---------- */
- .fsMain{
- flex-grow: 1;
- display: flex;
- flex-direction: column;
- min-width: 0;
- }
- .fsToolbar{
- display: flex;
- align-items: center;
- gap: 8px;
- padding: 7px 12px;
- flex-shrink: 0;
- position: relative;
- }
- .fsViewToggle{
- display: flex;
- background: var(--fs-fill);
- border-radius: 8px;
- padding: 2px;
- gap: 2px;
- }
- .fsViewToggle button{
- width: 30px;
- height: 26px;
- border: none;
- background: transparent;
- border-radius: 6px;
- padding: 5px;
- color: var(--fs-icon);
- cursor: pointer;
- }
- .fsViewToggle button:hover{ background: var(--fs-fill-hover); }
- .fsViewToggle button.active{
- background: var(--fs-surface);
- color: var(--fs-accent);
- box-shadow: 0 1px 2px rgba(0,0,0,0.12);
- }
- .fsSortPill{
- height: 32px;
- border: 1px solid var(--fs-line);
- border-radius: 8px;
- display: flex;
- align-items: center;
- padding: 0 3px 0 10px;
- gap: 3px;
- background: var(--fs-surface);
- }
- .fsSortPill .fsSortLabel{
- color: var(--fs-text-dim);
- font-size: 12px;
- white-space: nowrap;
- }
- .fsSortPill select{
- border: none;
- outline: none;
- background: transparent;
- font-size: 14px;
- font-family: inherit;
- color: var(--fs-text);
- cursor: pointer;
- padding: 2px 2px;
- max-width: 130px;
- }
- .fsSortDir{
- width: 28px;
- height: 28px;
- min-width: 28px;
- border: none;
- background: transparent;
- border-radius: 6px;
- padding: 6px;
- color: var(--fs-icon);
- cursor: pointer;
- }
- .fsSortDir:hover{ background: var(--fs-fill); }
- .fsToolbarSpacer{ flex-grow: 1; }
- .fsMoreBtn{
- width: 32px;
- height: 32px;
- min-width: 32px;
- border: 1px solid var(--fs-line);
- background: var(--fs-surface);
- border-radius: 8px;
- padding: 7px;
- color: var(--fs-text);
- cursor: pointer;
- }
- .fsMoreBtn:hover{ background: var(--fs-fill); }
- .fsMoreBtn.active{ background: var(--fs-accent-soft); color: var(--fs-accent); border-color: transparent; }
- /* ---------- Inline rename ---------- */
- /* Both name labels clip to one line, the editor needs the room back */
- .fsTileName.editing{
- overflow: visible;
- text-overflow: clip;
- }
- .fsRowName.editing{
- flex-grow: 1;
- min-width: 0;
- overflow: visible;
- text-overflow: clip;
- }
- /* ---------- Content area ---------- */
- .fsContent{
- flex-grow: 1;
- display: flex;
- min-height: 0;
- }
- .fsFiles{
- flex-grow: 1;
- overflow: auto;
- min-width: 0;
- position: relative;
- }
- /* List view */
- .fsListHead{
- display: flex;
- align-items: center;
- padding: 0 14px 0 16px;
- height: 30px;
- border-bottom: 1px solid var(--fs-line);
- position: sticky;
- top: 0;
- background: var(--fs-bg);
- z-index: 5;
- }
- /*
- Column geometry is declared on the bare class names so the header
- cells (.fsCol) and the row cells (.fsCell) get identical boxes and
- stay vertically aligned with each other.
- */
- .colName,
- .colDate,
- .colType,
- .colSize{ padding-right: 10px; }
- .colName{ flex: 1 1 0%; min-width: 60px; }
- /*
- Fixed columns never shrink - fractional shrinking rounds differently
- in the header and in the rows and drifts them a pixel apart. When the
- file area gets too narrow a whole column is dropped instead, which
- keeps every width an exact integer in both containers.
- The widths come from custom properties that the header's resize
- grips set on #fileArea, so the header and every row pick up a
- dragged width from the same place.
- */
- .colDate{ flex: 0 0 var(--fs-col-date, 210px); }
- .colType{ flex: 0 0 var(--fs-col-type, 150px); }
- .colSize{ flex: 0 0 var(--fs-col-size, 110px); }
- /* Width driven by the file area itself, not the viewport, because the
- details pane takes its space away without changing the window size */
- #fileArea.narrow .colType{ display: none; }
- #fileArea.verynarrow .colDate{ display: none; }
- .fsListHead .fsCol{
- font-size: 13px;
- color: var(--fs-text-dim);
- cursor: pointer;
- display: flex;
- align-items: center;
- align-self: stretch;
- padding: 0;
- position: relative;
- }
- /* The hover pill lives on an inner span so it cannot alter the column box */
- .fsListHead .fsCol .fsColInner{
- display: inline-flex;
- align-items: center;
- gap: 5px;
- padding: 4px 6px;
- margin-left: -6px;
- border-radius: 6px;
- max-width: 100%;
- min-width: 0;
- }
- .fsListHead .fsCol .fsColInner:hover{ background: var(--fs-fill); }
- /* A column dragged narrower than its label clips the label, not the box */
- .fsListHead .fsCol .fsColLabel{
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- /*
- Resize grip on a header cell's right edge, half over each of the two
- columns it separates. It outranks the next cell's hover pill, which
- reaches back over the boundary. The last column ends at the edge of
- the list, so it has nothing to trade width with and shows no grip.
- */
- .fsListHead .fsColGrip{
- position: absolute;
- top: 0;
- right: -4px;
- width: 8px;
- height: 100%;
- cursor: col-resize;
- z-index: 2;
- touch-action: none;
- }
- .fsListHead .fsCol:last-child .fsColGrip{ display: none; }
- .fsListHead .fsColGrip::after{
- content: "";
- position: absolute;
- top: 25%;
- left: 3px;
- width: 1px;
- height: 50%;
- background: var(--fs-line);
- }
- .fsListHead:hover .fsColGrip::after{ background: var(--fs-text-faint); }
- .fsListHead .fsColGrip:hover::after,
- .fsListHead .fsColGrip.dragging::after{
- top: 0;
- width: 2px;
- height: 100%;
- background: var(--fs-accent);
- }
- .fsListHead .fsCol .fsSortMark{
- width: 11px;
- height: 11px;
- min-width: 11px;
- color: var(--fs-text-dim);
- visibility: hidden;
- }
- .fsListHead .fsCol.sorted .fsSortMark{ visibility: visible; }
- .fsRow{
- display: flex;
- align-items: center;
- padding: 0 14px 0 16px;
- height: 38px;
- cursor: pointer;
- border-bottom: 1px solid var(--fs-line-soft);
- }
- .fsRow:hover{ background: var(--fs-row-hover); }
- /* Light fill plus a thin leading bar, so a run of selected rows stays
- readable instead of becoming one solid block of colour */
- .fsRow.selected{
- background: var(--fs-selected);
- }
- .fsRow.selected:hover{ background: var(--fs-selected-hover); }
- .fsRow.disabledObject{ opacity: 0.45; }
- .fsRow .fsCell{
- font-size: 14px;
- color: var(--fs-text-dim);
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- .fsRow .fsCell.colName{
- display: flex;
- align-items: center;
- gap: 9px;
- color: var(--fs-text);
- }
- .fsRow .fsCell.colName .fsRowName{
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- /* Grid view */
- .fsGrid{
- display: grid;
- grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
- gap: 10px;
- padding: 12px 14px;
- align-content: start;
- }
- .fsTile{
- border: 1px solid var(--fs-line);
- border-radius: 10px;
- padding: 8px;
- cursor: pointer;
- background: var(--fs-surface);
- transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
- min-width: 0;
- }
- .fsTile:hover{ box-shadow: 0 2px 10px rgba(15,20,30,0.08); }
- /* A single soft border rather than the previous double ring */
- .fsTile.selected{
- border-color: var(--fs-selected-line);
- background: var(--fs-selected);
- }
- .fsTile.selected:hover{ background: var(--fs-selected-hover); }
- .fsTile.disabledObject{ opacity: 0.45; }
- .fsThumb{
- position: relative;
- height: 96px;
- border-radius: 7px;
- background: var(--fs-thumb-bg);
- display: flex;
- align-items: center;
- justify-content: center;
- overflow: hidden;
- margin-bottom: 7px;
- }
- /*
- Thumbnails are square while the preview box is landscape, so cover
- the whole box instead of letterboxing it. Anchoring to the top keeps
- the head of a document page in frame rather than its middle.
- */
- .fsThumb img.fsThumbImg{
- width: 100%;
- height: 100%;
- object-fit: cover;
- object-position: center top;
- display: none;
- border-radius: 7px;
- }
- .fsThumb img.fsThumbImg.loaded{ display: block; }
- .fsThumb .fsBigIcon{
- width: 56px;
- height: 56px;
- }
- .fsThumb.hasThumb .fsBigIcon{ display: none; }
- .fsAppBadge{
- position: absolute;
- right: 6px;
- bottom: 6px;
- width: 22px;
- height: 22px;
- border-radius: 5px;
- background: var(--fs-surface);
- box-shadow: 0 1px 4px rgba(15,20,30,0.25);
- padding: 1px;
- display: none;
- }
- .fsAppBadge img{ width: 100%; height: 100%; object-fit: contain; }
- .fsTileName{
- font-size: 13px;
- color: var(--fs-text);
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- margin-bottom: 2px;
- }
- .fsTileMeta{
- font-size: 11px;
- color: var(--fs-text-faint);
- display: flex;
- align-items: center;
- gap: 5px;
- min-height: 16px;
- }
- .fsTileMeta .fsTileMetaText{
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- flex-grow: 1;
- line-height: 1.5;
- }
- .fsTileMore{
- width: 20px;
- height: 20px;
- min-width: 20px;
- border: none;
- background: transparent;
- border-radius: 5px;
- padding: 3px;
- color: var(--fs-text-faint);
- cursor: pointer;
- }
- .fsTileMore:hover{ background: var(--fs-fill); color: var(--fs-text); }
- /* Empty / loading state */
- .fsPlaceholder{
- position: absolute;
- top: 0; left: 0; right: 0; bottom: 0;
- display: none;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- gap: 10px;
- color: var(--fs-text-faint);
- pointer-events: none;
- }
- .fsPlaceholder.show{ display: flex; }
- .fsPlaceholder .fsPlaceholderIcon{
- width: 42px;
- height: 42px;
- opacity: 0.5;
- }
- /* ---------- Details panel ---------- */
- .fsDetails{
- width: 264px;
- min-width: 264px;
- border-left: 1px solid var(--fs-line);
- display: none;
- flex-direction: column;
- overflow: hidden;
- }
- .fsDetails.open{ display: flex; }
- .fsDetailsHead{
- display: flex;
- align-items: center;
- padding: 9px 9px 9px 14px;
- flex-shrink: 0;
- }
- .fsDetailsHead .fsDetailsTitle{
- font-size: 14px;
- font-weight: 600;
- flex-grow: 1;
- }
- .fsDetailsBody{
- flex-grow: 1;
- overflow-y: auto;
- padding: 2px 14px 14px 14px;
- }
- .fsDetailsPreview{
- display: flex;
- align-items: center;
- justify-content: center;
- height: 124px;
- margin-bottom: 10px;
- position: relative;
- }
- /* The details preview shows the whole image, so it keeps letterboxing */
- .fsDetailsPreview img.fsThumbImg{
- max-width: 100%;
- max-height: 100%;
- width: auto;
- height: auto;
- object-fit: contain;
- display: none;
- border-radius: 5px;
- box-shadow: 0 2px 10px rgba(15,20,30,0.2);
- }
- .fsDetailsPreview img.fsThumbImg.loaded{ display: block; }
- .fsDetailsPreview .fsBigIcon{ width: 74px; height: 74px; }
- .fsDetailsPreview.hasThumb .fsBigIcon{ display: none; }
- .fsDetailsName{
- text-align: center;
- font-size: 14px;
- font-weight: 600;
- margin-bottom: 12px;
- word-break: break-all;
- user-select: text;
- }
- .fsDetailRow{
- display: flex;
- align-items: flex-start;
- gap: 10px;
- padding: 6px 0;
- border-top: 1px solid var(--fs-line-soft);
- font-size: 12.5px;
- }
- .fsDetailRow .fsDetailKey{
- color: var(--fs-text-dim);
- width: 78px;
- min-width: 78px;
- }
- .fsDetailRow .fsDetailVal{
- flex-grow: 1;
- color: var(--fs-text);
- word-break: break-all;
- user-select: text;
- display: flex;
- align-items: center;
- gap: 7px;
- }
- .fsDetailRow .fsDetailVal img.fsOpenerIcon{
- width: 18px;
- height: 18px;
- object-fit: contain;
- flex-shrink: 0;
- }
- .fsDetailsEmpty{
- text-align: center;
- color: var(--fs-text-faint);
- padding-top: 60px;
- font-size: 13px;
- }
- /* ---------- Footer ---------- */
- .fsFooter{
- display: flex;
- align-items: center;
- gap: 10px;
- padding: 10px 14px;
- border-top: 1px solid var(--fs-line);
- flex-shrink: 0;
- flex-wrap: wrap;
- }
- .fsFooterLabel{
- font-size: 14px;
- color: var(--fs-text);
- white-space: nowrap;
- }
- .fsFooter #filename{
- flex-grow: 1;
- min-width: 120px;
- height: 34px;
- border: 1px solid var(--fs-line);
- border-radius: 8px;
- padding: 0 10px;
- font-size: 14px;
- font-family: inherit;
- color: var(--fs-text);
- outline: none;
- background: var(--fs-surface);
- user-select: text;
- }
- .fsFooter #filename:focus{ border-color: var(--fs-accent); }
- .fsFooter #filterSelect{
- height: 34px;
- min-width: 132px;
- max-width: 190px;
- border: 1px solid var(--fs-line);
- border-radius: 8px;
- padding: 0 6px 0 10px;
- font-size: 14px;
- font-family: inherit;
- color: var(--fs-text);
- background: var(--fs-surface);
- outline: none;
- cursor: pointer;
- }
- /* ---------- Right click menu ---------- */
- /*
- Matches the File Manager's #contextmenu (file_explorer.css): the label
- carries the row and a muted Semantic UI glyph sits at the trailing edge,
- with no glyph at all on the rows the File Manager leaves bare.
- Scoped to the context menu, so the toolbar dropdown (#moreMenu) keeps
- its leading icons - the same split the File Manager draws between its
- right click menu and its "more" menu.
- */
- #fsRoot #contextMenu{ min-width: 250px; }
- #fsRoot #contextMenu .fsMenuItem{
- gap: 7px;
- padding: 5px 7px;
- color: var(--fs-text);
- }
- /* Label takes up the slack, so the trailing glyph is always right aligned */
- #fsRoot #contextMenu .fsMenuItem > span{ flex-grow: 1; }
- /*
- The colour needs !important: ao.css styles every <i> under a themed
- body with a blanket rule whose :not() chain scores higher than any
- reasonable selector here, so it would otherwise repaint the glyph to
- the label colour and flatten the two-tone look.
- */
- #fsRoot #contextMenu .fsMenuItem > i.icon{
- width: 16px;
- min-width: 16px;
- height: auto;
- margin: 0 0 0 auto;
- font-size: 14px;
- text-align: center;
- color: var(--fs-icon) !important;
- opacity: 0.6;
- }
- /* ---------- Sidebar overlay (narrow windows) ---------- */
- .fsScrim{
- position: absolute;
- top: 0; left: 0; right: 0; bottom: 0;
- background: rgba(15,20,30,0.25);
- z-index: 190;
- display: none;
- }
- .fsScrim.show{ display: block; }
- #sidebarToggleBtn{ display: none; }
- /* Hide the details pane and search box when there is no room for them */
- @media only screen and (max-width: 900px){
- .fsSearch{ width: 180px; }
- .fsDetails{ display: none !important; }
- }
- @media only screen and (max-width: 820px){
- /* Drop the label before the footer controls are forced to wrap */
- .fsFooterLabel{ display: none; }
- }
- @media only screen and (max-width: 720px){
- .fsSearch{ display: none; }
- }
- @media only screen and (max-width: 560px){
- #sidebarToggleBtn{ display: block; }
- .fsSidebar{
- position: absolute;
- z-index: 200;
- top: 0;
- bottom: 0;
- left: 0;
- box-shadow: 6px 0 24px rgba(15,20,30,0.18);
- display: none;
- }
- .fsSidebar.open{ display: block; }
- /* The drawer floats over the file list, so there is no edge to drag */
- .fsSplitter{ display: none !important; }
- .fsFooter{ padding: 10px 12px; gap: 8px; }
- .fsBtn{ min-width: 78px; padding: 0 12px; }
- .fsListHead{ padding-left: 14px; padding-right: 12px; }
- .fsRow{ padding-left: 14px; padding-right: 12px; }
- }
- /* ---------- Dark theme ---------- */
- /* Palette lives in shared/fs-theme.css, keyed on body.darkTheme. */
- body.darkTheme #fsRoot .fsViewToggle button.active{ box-shadow: 0 1px 2px rgba(0,0,0,0.5); }
- body.darkTheme #fsRoot .fsTile:hover{ box-shadow: 0 2px 10px rgba(0,0,0,0.45); }
- /* ---------- Blocking loader (selection hand-off) ---------- */
- #waitloader{
- position: absolute;
- top: 0; left: 0; right: 0; bottom: 0;
- background: var(--fs-overlay);
- z-index: 900;
- display: none;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- gap: 14px;
- color: var(--fs-text-dim);
- text-align: center;
- padding: 20px;
- }
- #waitloader.show{ display: flex; }
- /* ---------- Replace prompt (new file mode) ---------- */
- /*
- Asked before a new file is written over an existing one. An in-page
- dialog rather than confirm(): it follows the theme, and answering
- "no" leaves the user in the selector to type another name.
- */
- .fsModalScrim{
- position: absolute;
- top: 0; left: 0; right: 0; bottom: 0;
- z-index: 950;
- display: none;
- align-items: center;
- justify-content: center;
- padding: 16px;
- background: rgba(15,20,30,0.28);
- }
- body.darkTheme .fsModalScrim{ background: rgba(0,0,0,0.5); }
- .fsModalScrim.show{ display: flex; }
- .fsModal{
- width: 380px;
- max-width: 100%;
- background: var(--fs-surface);
- border: 1px solid var(--fs-line);
- border-radius: 12px;
- box-shadow: 0 12px 36px var(--fs-shadow);
- padding: 18px 18px 14px 18px;
- }
- .fsModalHead{
- display: flex;
- align-items: center;
- gap: 10px;
- margin-bottom: 12px;
- }
- /* !important for the same reason as the context menu glyphs above:
- ao.css repaints every div under a themed body in the text colour */
- .fsModalIcon{
- width: 22px;
- height: 22px;
- min-width: 22px;
- color: #e37400 !important;
- }
- body.darkTheme .fsModalIcon{ color: #fdd663 !important; }
- .fsModalTitle{
- font-size: 15px;
- font-weight: 600;
- color: var(--fs-text);
- }
- .fsModalFile{
- display: flex;
- align-items: center;
- gap: 9px;
- padding: 8px 10px;
- border-radius: 8px;
- background: var(--fs-fill);
- margin-bottom: 10px;
- }
- .fsModalFile .fsModalFileName{
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- color: var(--fs-text);
- }
- .fsModalText{
- font-size: 13px;
- line-height: 1.5;
- color: var(--fs-text-dim);
- }
- .fsModalFoot{
- display: flex;
- justify-content: flex-end;
- gap: 8px;
- margin-top: 16px;
- }
- .fsModal .fsBtn:focus-visible{
- outline: 2px solid var(--fs-accent);
- outline-offset: 2px;
- }
- </style>
- </head>
- <body>
- <div id="fsRoot">
- <!-- Title bar (shown only outside the ArozOS float window, which draws its own) -->
- <div class="fsTitlebar" id="fsTitlebar">
- <div class="fsTitleIcon" id="fsTitleIcon"></div>
- <div class="fsTitleText" locale="title">File Selector</div>
- <button class="fsCloseBtn" id="fsCloseBtn" title="Close" onclick="closeSelector();"></button>
- </div>
- <!-- Navigation -->
- <div class="fsNav">
- <div class="fsNavBtns">
- <button id="sidebarToggleBtn" class="fsIconBtn" title="Menu" onclick="toggleSidebar();"></button>
- <button id="backBtn" class="fsIconBtn" title="Back" onclick="backDir();"></button>
- <button id="forwardBtn" class="fsIconBtn" title="Forward" onclick="forwardDir();"></button>
- <div class="fsNavDivider"></div>
- <button id="upBtn" class="fsIconBtn" title="Parent" onclick="parentDir();"></button>
- </div>
- <div class="fsPill fsPathbar" id="pathbar" onclick="onPathbarClick(event);">
- <div class="fsPathIcon" id="pathIcon"></div>
- <div class="fsCrumbs" id="breadcrumb"></div>
- <input id="addressbar" type="text" spellcheck="false" autocomplete="off">
- <button class="fsIconBtn" id="refreshBtn" title="Refresh" style="width:30px;height:30px;min-width:30px;padding:7px;background:transparent;" onclick="event.stopPropagation();refresh();"></button>
- </div>
- <div class="fsPill fsSearch">
- <input id="searchInput" type="text" spellcheck="false" autocomplete="off" placeholder="Search">
- <div class="fsSearchIcon" id="searchIcon"></div>
- </div>
- </div>
- <!-- Body -->
- <div class="fsBody">
- <div class="fsScrim" id="sidebarScrim" onclick="toggleSidebar();"></div>
- <div class="fsSidebar" id="sidebar">
- <div class="fsSideTitle" locale="sidebar/quickaccess">Quick Access</div>
- <div id="userlist"></div>
- <div class="fsSideTitle" locale="sidebar/devices">Devices</div>
- <div id="storagelist"></div>
- </div>
- <!-- Drag handle between the sidebar and the file list, desktop layout only -->
- <div class="fsSplitter" id="sidebarSplitter" title="Resize"></div>
- <div class="fsMain">
- <div class="fsToolbar">
- <div class="fsViewToggle">
- <button id="viewListBtn" title="List View" onclick="setViewMode('list');"></button>
- <button id="viewGridBtn" title="Grid View" onclick="setViewMode('grid');"></button>
- </div>
- <div class="fsSortPill">
- <span class="fsSortLabel" locale="toolbar/sort">Sort:</span>
- <select id="sortSelect" onchange="setSortField(this.value);">
- <option value="name" locale="sort/name">Name</option>
- <option value="date" locale="sort/date">Date Modified</option>
- <option value="type" locale="sort/type">Type</option>
- <option value="size" locale="sort/size">Size</option>
- </select>
- <button class="fsSortDir" id="sortDirBtn" title="Sort Direction" onclick="toggleSortDirection();"></button>
- </div>
- <div class="fsToolbarSpacer"></div>
- <button class="fsMoreBtn" id="moreBtn" title="More Options" onclick="toggleMoreMenu(event);"></button>
- <div class="fsMenu" id="moreMenu" style="right: 14px; top: 50px;">
- <div class="fsMenuItem" onclick="menuNewFolder();">
- <span class="fsMenuIcon" data-icon="folderPlus"></span>
- <span locale="menu/newfolder">New Folder</span>
- </div>
- <div class="fsMenuSep"></div>
- <div class="fsMenuItem" id="menuDetails" onclick="toggleDetailsPanel();">
- <span class="fsMenuIcon" data-icon="info"></span>
- <span locale="menu/details">Details Pane</span>
- <span class="fsMenuCheck" data-icon="check"></span>
- </div>
- <div class="fsMenuItem" id="menuHidden" onclick="toggleHiddenFiles();">
- <span class="fsMenuIcon" data-icon="eye"></span>
- <span locale="menu/hidden">Show Hidden Files</span>
- <span class="fsMenuCheck" data-icon="check"></span>
- </div>
- </div>
- </div>
- <div class="fsContent">
- <div class="fsFiles" id="fileArea" oncontextmenu="showFolderContextMenu(event);">
- <div class="fsPlaceholder" id="loadingPlaceholder">
- <div class="fsSpinner"></div>
- <div locale="message/loading">Loading</div>
- </div>
- <div class="fsPlaceholder" id="emptyPlaceholder">
- <div class="fsPlaceholderIcon" data-icon="folderOpen"></div>
- <div locale="message/nofile">No file</div>
- </div>
- </div>
- <div class="fsDetails" id="detailsPanel">
- <div class="fsDetailsHead">
- <div class="fsDetailsTitle" locale="details/title">Details</div>
- <button class="fsCloseBtn" onclick="toggleDetailsPanel();" title="Close"></button>
- </div>
- <div class="fsDetailsBody" id="detailsBody">
- <div class="fsDetailsEmpty" locale="details/empty">Select an item to see its details</div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- Footer -->
- <div class="fsFooter">
- <span class="fsFooterLabel" id="filenameLabel" locale="footer/filename">File name(N):</span>
- <input id="filename" type="text" spellcheck="false" autocomplete="off" placeholder="New Filename">
- <select id="filterSelect" onchange="renderFileList();"></select>
- <button class="fsBtn" onclick="closeSelector();" locale="footer/cancel">Cancel</button>
- <button class="fsBtn primary" id="confirmBtn" onclick="confirmSelection();" locale="footer/open">Open</button>
- </div>
- <!-- Right click menu, contents are rebuilt per target -->
- <div class="fsMenu fsContextMenu" id="contextMenu"></div>
- <div id="waitloader">
- <div class="fsSpinner"></div>
- <div id="waitloadertext" locale="message/waitingResp">Waiting Response</div>
- </div>
- <!-- New file mode: asks before an existing file is replaced, see confirmOverwrite() -->
- <div class="fsModalScrim" id="overwriteDialog" onclick="if (event.target == this){ answerOverwrite(false); }">
- <div class="fsModal" role="alertdialog" aria-modal="true" aria-labelledby="overwriteTitle" aria-describedby="overwriteText">
- <div class="fsModalHead">
- <div class="fsModalIcon" data-icon="warning"></div>
- <div class="fsModalTitle" id="overwriteTitle" locale="overwrite/title">Replace existing file?</div>
- </div>
- <div class="fsModalFile" id="overwriteFile"></div>
- <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>
- <div class="fsModalFoot">
- <button class="fsBtn" id="overwriteCancelBtn" onclick="answerOverwrite(false);" locale="overwrite/cancel">Cancel</button>
- <button class="fsBtn primary" id="overwriteReplaceBtn" onclick="answerOverwrite(true);" locale="overwrite/replace">Replace</button>
- </div>
- </div>
- </div>
- </div>
- <script>
- /*
- file_selector.html
- Launch parameters are passed in the URL hash as a JSON object, see
- ao_module_openFileSelector() in /script/ao_module.js:
- {
- root: "user:/", //Initial directory
- fallbackRoot: "user:/", //Used when "root" no longer exists, see below
- type: "file" | "folder" | "new",
- allowMultiple: false,
- listenerUUID: "", //localStorage key used outside the virtual desktop
- options: {
- defaultName: "newfile.txt",
- filter: ["mp3","flac"] //Extension whitelist, no leading dot
- }
- }
- "root" may be a directory restored from the caller's path memory, which
- the user could have renamed or deleted since. When it fails to list, the
- selector drops back to "fallbackRoot" (the path the calling app asked
- for) before giving up on "user:/".
- The result is handed back either through the float window parent callback
- (inside the ArozOS desktop) or through localStorage[listenerUUID].
- */
- /* ------------------------------------------------------------------ */
- /* State */
- /* ------------------------------------------------------------------ */
- var multiSelect = false;
- var type = "file";
- var currentDir = "user:/";
- var currentFileList = []; //Raw listDir response for the current directory
- var renderedFileList = []; //Filtered + sorted list currently on screen
- var pathHistory = []; //Visited directories, index based for back/forward
- var historyIndex = -1;
- var ctrlDown = false;
- var shiftDown = false;
- //Multi-select uses Cmd on a Mac (Ctrl + click is the right click there)
- var isMacOS = /Mac/i.test(navigator.platform || navigator.userAgent);
- var lastClickedItemID = 0;
- var listenerUUID = "";
- var fileOptions = {};
- var fallbackRoot = "user:/"; //Where to land if the requested root is gone
- var viewMode = "list"; //"list" or "grid"
- var sortField = "name"; //name | date | type | size
- var sortAscending = true;
- var showHidden = false;
- var detailsOpen = false;
- var searchKeyword = "";
- var selectionConfirmed = false;
- //List view column widths, see "List columns" below
- var COLUMN_DEFAULT_WIDTHS = {date: 210, type: 150, size: 110};
- var COLUMN_MIN_WIDTH = 60; //Narrowest a fixed column can be dragged
- var NAME_COLUMN_MIN_WIDTH = 140; //Room the fluid name column always keeps
- var columnWidths = {}; //key -> px, only the columns the user resized
- var columnResizeEndedAt = 0; //Lets the click a resize leaves behind skip the sort
- var rootNameMap = {}; //"user:/" -> "User"
- var thumbLoader = null; //Handle from FileThumb.loadThumbnails, cancel on navigation
- /* ------------------------------------------------------------------ */
- /* Icons */
- /* ------------------------------------------------------------------ */
- /*
- Inline SVG only. See CLAUDE.md rule 6 - no emoji anywhere in the
- program; app specific glyphs are drawn locally.
- */
- var STROKE = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">';
- var ICONS = {
- back: STROKE + '<path d="M19 12H5M12 19l-7-7 7-7"/></svg>',
- forward: STROKE + '<path d="M5 12h14M12 5l7 7-7 7"/></svg>',
- up: STROKE + '<path d="M12 19V5M5 12l7-7 7 7"/></svg>',
- menu: STROKE + '<path d="M4 6h16M4 12h16M4 18h16"/></svg>',
- refresh: STROKE + '<path d="M21 12a9 9 0 1 1-3.2-6.9"/><path d="M21 4v5h-5"/></svg>',
- search: STROKE + '<circle cx="11" cy="11" r="7"/><path d="M20 20l-3.6-3.6"/></svg>',
- close: STROKE + '<path d="M18 6L6 18M6 6l12 12"/></svg>',
- viewList: STROKE + '<path d="M8 6h13M8 12h13M8 18h13M3.5 6h.01M3.5 12h.01M3.5 18h.01"/></svg>',
- 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>',
- 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>',
- arrowUp: STROKE + '<path d="M12 19V5M6 11l6-6 6 6"/></svg>',
- arrowDown: STROKE + '<path d="M12 5v14M6 13l6 6 6-6"/></svg>',
- check: STROKE + '<path d="M20 6L9 17l-5-5"/></svg>',
- info: STROKE + '<circle cx="12" cy="12" r="9"/><path d="M12 16v-5M12 8h.01"/></svg>',
- 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>',
- 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>',
- 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>',
- clock: STROKE + '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3.2 2"/></svg>',
- download: STROKE + '<path d="M12 3v12M7 11l5 5 5-5"/><path d="M4 20h16"/></svg>',
- 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>',
- 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>',
- 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>',
- code: STROKE + '<path d="M9 18l-6-6 6-6M15 6l6 6-6 6"/></svg>',
- 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>',
- trash: STROKE + '<path d="M4 7h16M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2M6 7l1 13h10l1-13"/></svg>',
- 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>',
- 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>',
- /* Filled sidebar glyphs, matching the coloured tiles in the design */
- 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>',
- 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>',
- 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>',
- 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>'
- };
- /* ------------------------------------------------------------------ */
- /* File type helpers */
- /* ------------------------------------------------------------------ */
- /*
- Icon drawing, thumbnail streaming and the default-opener lookup are
- shared with the File Manager and live in shared/filethumb.js, so both
- apps render a file the same way. These thin aliases keep the call
- sites below short.
- */
- var folderGlyph = FileThumb.folderGlyph;
- var getExt = FileThumb.getExt;
- var escapeHTML = FileThumb.escapeHTML;
- var formatBytes = FileThumb.formatBytes;
- var formatTimestamp = FileThumb.formatTimestamp;
- var smallGlyph = FileThumb.smallGlyph;
- var largeGlyph = FileThumb.largeGlyph;
- function getCategoryColor(ext){
- return FileThumb.getCategoryColor(ext);
- }
- function getTypeName(filename, isDir){
- return FileThumb.getTypeName(filename, isDir, function(key, fallback){
- return applocale.getString(key, fallback);
- });
- }
- /* ------------------------------------------------------------------ */
- /* Boot */
- /* ------------------------------------------------------------------ */
- injectStaticIcons();
- initTheme();
- if (applocale){
- //Applocale found. Do localization
- applocale.init("../locale/file_selector.json", function(){
- applocale.translate();
- captureLocalizedTemplates();
- initRoots();
- initSelectorObject();
- });
- }else{
- //Applocale not found. Is this a trim down version of ArozOS?
- applocale = {
- getString: function(key, original){
- return original;
- }
- }
- captureLocalizedTemplates();
- initRoots();
- initSelectorObject();
- }
- //Put the inline SVG markup into every static icon slot
- function injectStaticIcons(){
- $("#fsTitleIcon").html(ICONS.folderSide);
- $("#fsCloseBtn").html(ICONS.close);
- $("#sidebarToggleBtn").html(ICONS.menu);
- $("#backBtn").html(ICONS.back);
- $("#forwardBtn").html(ICONS.forward);
- $("#upBtn").html(ICONS.up);
- $("#refreshBtn").html(ICONS.refresh);
- $("#pathIcon").html(ICONS.folderSide);
- $("#searchIcon").html(ICONS.search);
- $("#viewListBtn").html(ICONS.viewList);
- $("#viewGridBtn").html(ICONS.viewGrid);
- $("#moreBtn").html(ICONS.more);
- $("#sortDirBtn").html(ICONS.arrowUp);
- $(".fsDetailsHead .fsCloseBtn").html(ICONS.close);
- $("[data-icon]").each(function(){
- var iconName = $(this).attr("data-icon");
- if (ICONS[iconName] != undefined){
- $(this).html(ICONS[iconName]);
- }
- });
- }
- /*
- applocale.getString() ignores its "type" argument and always reads
- from the "strings" table, so placeholder and title values can only be
- localized through applocale.translate() rewriting the attribute.
- Snapshot the translated search placeholder here and reuse it as the
- template for "Search <foldername>".
- */
- var searchPlaceholderTemplate = "Search";
- function captureLocalizedTemplates(){
- searchPlaceholderTemplate = $("#searchInput").attr("placeholder") || "Search";
- }
- function initSelectorObject(){
- var initInfo = loadSelectorInfoFromHash();
- //init global var
- type = initInfo.type;
- multiSelect = initInfo.allowMultiple;
- listenerUUID = initInfo.listenerUUID;
- fallbackRoot = initInfo.fallbackRoot;
- if (initInfo.options != undefined && initInfo.options != null){
- fileOptions = JSON.parse(JSON.stringify(initInfo.options));
- }
- //The ArozOS float window already renders a title bar and a close
- //button, so the built-in one is only needed in standalone windows
- if (ao_module_virtualDesktop){
- $("#fsTitlebar").hide();
- }
- //Load options and parse the UI
- if (type == "new"){
- if (typeof(fileOptions.defaultName) != "undefined"){
- $("#filename").val(fileOptions.defaultName);
- }else{
- $("#filename").val("newfile.txt");
- }
- /*
- This picker writes a new file rather than opening an
- existing one, so the confirm button says so.
- Resolved through getString rather than by swapping the
- locale attribute: applocale.translate() has already run
- by the time this executes, so a new attribute would never
- be looked up and the button would stay English.
- */
- $("#confirmBtn").attr("locale", "footer/create")
- .text(applocale.getString("footer/create", "Create"));
- }else if (type == "folder"){
- //A filename has no meaning when picking a folder
- $("#filename").hide();
- $("#filenameLabel").hide();
- }
- buildFilterOptions();
- restoreViewPreferences(function(){
- //Load the initiation directory
- listDir(initInfo.root, true);
- });
- }
- function loadSelectorInfoFromHash(){
- var fallback = {
- root: "user:/",
- fallbackRoot: "user:/",
- type: "file",
- allowMultiple: false
- };
- if (window.location.hash.length == 0){
- return fallback;
- }
- try{
- var selectInfo = JSON.parse(decodeURIComponent(window.location.hash.substring(1)));
- if (selectInfo.root == undefined){
- selectInfo.root = fallback.root;
- }
- if (selectInfo.fallbackRoot == undefined){
- //Older callers do not send one. Their root is the only path we have
- selectInfo.fallbackRoot = selectInfo.root;
- }
- if (selectInfo.type == undefined){
- selectInfo.type = fallback.type;
- }
- return selectInfo;
- }catch(ex){
- //Error parsing the input. Use default settings
- return fallback;
- }
- }
- //The caller supplied extension whitelist is a hard constraint, so when one
- //is given it is the only entry in the dropdown
- function buildFilterOptions(){
- var select = $("#filterSelect");
- select.html("");
- if (fileOptions.filter != undefined && fileOptions.filter.length > 0){
- var patterns = [];
- for (var i = 0; i < fileOptions.filter.length; i++){
- patterns.push("*." + fileOptions.filter[i]);
- }
- select.append('<option value="filtered">' +
- escapeHTML(applocale.getString("footer/supportedfiles", "Supported Files") + " (" + patterns.join(", ") + ")") +
- '</option>');
- }else{
- select.append('<option value="all">' +
- escapeHTML(applocale.getString("footer/allfiles", "All Files") + " (*.*)") +
- '</option>');
- }
- }
- /* ------------------------------------------------------------------ */
- /* Theme */
- /* ------------------------------------------------------------------ */
- /*
- The ArozOS system theme preference (file_explorer/theme) wins when it
- is set. With no stored preference the dialog follows the operating
- system setting instead. Live switches - the desktop start menu toggle,
- or another tab flipping the theme - arrive via ao_module_onThemeChanged.
- */
- var hasStoredThemePreference = false;
- function applyTheme(theme){
- var isDark = (theme == "dark" || theme == "darkTheme");
- $("body").toggleClass("darkTheme", isDark);
- $("body").toggleClass("whiteTheme", !isDark);
- //Keep the float window frame in step with the dialog contents
- // ao_module_setWindowTheme(isDark ? "dark" : "white");
- }
- function osPrefersDark(){
- return window.matchMedia != undefined && window.matchMedia("(prefers-color-scheme: dark)").matches;
- }
- function initTheme(){
- //Paint from the OS setting first so there is no light flash while
- //the stored preference is still being fetched
- applyTheme(osPrefersDark() ? "dark" : "light");
- if (typeof ao_module_getSystemThemeColor == "function"){
- ao_module_getSystemThemeColor(function(pref){
- if (pref == "darkTheme" || pref == "whiteTheme"){
- hasStoredThemePreference = true;
- applyTheme(pref == "darkTheme" ? "dark" : "light");
- }else{
- //Key not found, stay on the operating system setting
- hasStoredThemePreference = false;
- }
- });
- }
- //Desktop start menu toggle and cross-tab switches
- if (typeof ao_module_onThemeChanged == "function"){
- ao_module_onThemeChanged(function(theme){
- hasStoredThemePreference = true;
- applyTheme(theme);
- });
- }
- //Only follow the OS while the user has not pinned a theme in ArozOS
- if (window.matchMedia != undefined){
- var query = window.matchMedia("(prefers-color-scheme: dark)");
- var onOSThemeChange = function(event){
- if (!hasStoredThemePreference){
- applyTheme(event.matches ? "dark" : "light");
- }
- };
- if (query.addEventListener != undefined){
- query.addEventListener("change", onOSThemeChange);
- }else if (query.addListener != undefined){
- //Safari below 14 and older WebKit builds
- query.addListener(onOSThemeChange);
- }
- }
- }
- /* ------------------------------------------------------------------ */
- /* View preferences */
- /* ------------------------------------------------------------------ */
- function restoreViewPreferences(callback){
- $.ajax({
- url: "../../system/file_system/preference",
- data: {key: "file_selector/view"},
- success: function(data){
- try{
- if (typeof data == "string" && data != ""){
- var pref = JSON.parse(data);
- if (pref.viewMode == "grid" || pref.viewMode == "list"){
- viewMode = pref.viewMode;
- }
- if (pref.sortField != undefined){
- sortField = pref.sortField;
- }
- if (pref.sortAscending != undefined){
- sortAscending = pref.sortAscending;
- }
- if (pref.detailsOpen != undefined){
- detailsOpen = pref.detailsOpen;
- }
- if (pref.showHidden != undefined){
- showHidden = pref.showHidden;
- }
- if (pref.columnWidths != undefined){
- columnWidths = parseColumnWidths(pref.columnWidths);
- }
- }
- }catch(ex){
- //Corrupted preference. Ignore and use the defaults
- }
- applyViewPreferences();
- callback();
- },
- error: function(){
- applyViewPreferences();
- callback();
- }
- });
- }
- function saveViewPreferences(){
- var pref = {
- viewMode: viewMode,
- sortField: sortField,
- sortAscending: sortAscending,
- detailsOpen: detailsOpen,
- showHidden: showHidden,
- columnWidths: columnWidths
- };
- $.ajax({
- url: "../../system/file_system/preference",
- data: {key: "file_selector/view", value: JSON.stringify(pref)}
- });
- }
- //Reflect the current preference values onto the toolbar controls
- function applyViewPreferences(){
- $("#viewListBtn").toggleClass("active", viewMode == "list");
- $("#viewGridBtn").toggleClass("active", viewMode == "grid");
- $("#sortSelect").val(sortField);
- $("#sortDirBtn").html(sortAscending ? ICONS.arrowUp : ICONS.arrowDown);
- $("#detailsPanel").toggleClass("open", detailsOpen);
- $("#menuDetails").toggleClass("checked", detailsOpen);
- $("#menuHidden").toggleClass("checked", showHidden);
- applyColumnWidths();
- }
- function setViewMode(mode){
- if (viewMode == mode){
- return;
- }
- viewMode = mode;
- applyViewPreferences();
- saveViewPreferences();
- renderFileList();
- }
- function setSortField(field){
- sortField = field;
- saveViewPreferences();
- renderFileList();
- }
- function toggleSortDirection(){
- sortAscending = !sortAscending;
- applyViewPreferences();
- saveViewPreferences();
- renderFileList();
- }
- function toggleDetailsPanel(){
- detailsOpen = !detailsOpen;
- applyViewPreferences();
- saveViewPreferences();
- closeMoreMenu();
- updateFileAreaDensity();
- if (detailsOpen){
- updateDetailsPanel();
- }
- }
- function toggleHiddenFiles(){
- showHidden = !showHidden;
- applyViewPreferences();
- saveViewPreferences();
- closeMoreMenu();
- refresh();
- }
- /* ------------------------------------------------------------------ */
- /* Directory listing */
- /* ------------------------------------------------------------------ */
- function listDir(dir, pushHistory){
- if (pushHistory === undefined){
- pushHistory = true;
- }
- currentDir = dir;
- if (pushHistory){
- //Drop anything ahead of the cursor before appending, so that
- //navigating after going back rewrites the forward stack
- pathHistory = pathHistory.slice(0, historyIndex + 1);
- pathHistory.push(dir);
- historyIndex = pathHistory.length - 1;
- }
- updateNavButtons();
- $("#addressbar").val(currentDir);
- renderBreadcrumb();
- updateSidebarActiveItem();
- $("#searchInput").val("");
- searchKeyword = "";
- updateSearchPlaceholder();
- setWindowTitleForSelection(0);
- //Stop any in-flight thumbnail stream from the previous directory
- if (thumbLoader != null){
- thumbLoader.cancel();
- thumbLoader = null;
- }
- //Any editor still on screen belongs to the outgoing listing
- inlineEditActive = false;
- closeActiveInlineEdit = null;
- closeContextMenu();
- $("#fileArea").find(".fsListHead, .fsRow, .fsGrid").remove();
- $("#emptyPlaceholder").removeClass("show");
- $("#loadingPlaceholder").addClass("show");
- clearDetails();
- $.ajax({
- url: "../../system/file_system/listDir",
- data: {dir: dir, sort: "default", showHidden: showHidden ? "true" : "false"},
- success: function(data){
- $("#loadingPlaceholder").removeClass("show");
- if (data == null){
- currentFileList = [];
- renderFileList();
- return;
- }
- if (data.error !== undefined){
- //The directory is gone (a restored path memory entry that has
- //since been renamed or deleted). Try what the calling app
- //originally asked for, then the user root.
- if (fallbackRoot != undefined && fallbackRoot != "" && dir != fallbackRoot){
- listDir(fallbackRoot, false);
- }else if (dir != "user:/"){
- listDir("user:/", false);
- }else{
- currentFileList = [];
- renderFileList();
- }
- return;
- }
- currentFileList = data;
- renderFileList();
- },
- error: function(){
- $("#loadingPlaceholder").removeClass("show");
- currentFileList = [];
- renderFileList();
- }
- });
- }
- function refresh(){
- listDir(currentDir, false);
- }
- function updatePath(){
- var newDir = $("#addressbar").val();
- $("#pathbar").removeClass("editing");
- if (newDir != "" && newDir != currentDir){
- listDir(newDir);
- }else{
- renderBreadcrumb();
- }
- }
- /* ------------------------------------------------------------------ */
- /* Filtering, sorting and rendering */
- /* ------------------------------------------------------------------ */
- function passesExtensionFilter(fileObject){
- if (fileObject.IsDir){
- return true;
- }
- if (fileOptions.filter == undefined || fileOptions.filter.length == 0){
- return true;
- }
- var ext = getExt(fileObject.Filename);
- for (var i = 0; i < fileOptions.filter.length; i++){
- if (String(fileOptions.filter[i]).toLowerCase().replace(/^\./, "") == ext){
- return true;
- }
- }
- return false;
- }
- function sortFileObjects(list){
- var direction = sortAscending ? 1 : -1;
- list.sort(function(a, b){
- //Folders always lead, regardless of the sort direction
- if (a.IsDir != b.IsDir){
- return a.IsDir ? -1 : 1;
- }
- var result = 0;
- if (sortField == "date"){
- result = (a.ModTime || 0) - (b.ModTime || 0);
- }else if (sortField == "size"){
- result = (a.Filesize || 0) - (b.Filesize || 0);
- }else if (sortField == "type"){
- result = getExt(a.Filename).localeCompare(getExt(b.Filename));
- }
- if (result == 0){
- result = a.Filename.toLowerCase().localeCompare(b.Filename.toLowerCase());
- //A name tie-break stays ascending so equal keys read naturally
- return sortField == "name" ? result * direction : result;
- }
- return result * direction;
- });
- return list;
- }
- function renderFileList(){
- var list = [];
- for (var i = 0; i < currentFileList.length; i++){
- var fileObject = currentFileList[i];
- if (!passesExtensionFilter(fileObject)){
- continue;
- }
- if (searchKeyword != "" && fileObject.Filename.toLowerCase().indexOf(searchKeyword) < 0){
- continue;
- }
- list.push(fileObject);
- }
- renderedFileList = sortFileObjects(list);
- $("#fileArea").find(".fsListHead, .fsRow, .fsGrid").remove();
- if (renderedFileList.length == 0){
- $("#emptyPlaceholder").addClass("show");
- setWindowTitleForSelection(0);
- clearDetails();
- return;
- }
- $("#emptyPlaceholder").removeClass("show");
- if (viewMode == "list"){
- renderListView();
- }else{
- renderGridView();
- }
- if (viewMode == "grid"){
- startThumbnailLoader();
- }
- updateFileAreaDensity();
- setWindowTitleForSelection(0);
- runPostRenderActions();
- }
- /*
- A create or rename finishes with a directory reload, so the follow up
- work has to wait until the new listing has been painted.
- */
- var pendingSelectAfterRender = null;
- function runPostRenderActions(){
- if (pendingSelectAfterRender != null){
- var toSelect = pendingSelectAfterRender;
- pendingSelectAfterRender = null;
- var dom = findFileObjectByName(toSelect);
- var fileObject = getFileObjectByName(toSelect);
- if (dom != null && fileObject != null && objectIsSelectable(fileObject)){
- selectThis(dom, {ctrlKey: false, shiftKey: false});
- }
- }
- if (pendingInlineRename != null){
- var toEdit = pendingInlineRename;
- pendingInlineRename = null;
- var editDom = findFileObjectByName(toEdit);
- if (editDom != null){
- //Bring it into view before handing over the keyboard
- if (editDom.scrollIntoView != undefined){
- editDom.scrollIntoView({block: "nearest"});
- }
- startInlineRename(editDom);
- }
- }
- }
- function getFileObjectByName(filename){
- for (var i = 0; i < currentFileList.length; i++){
- if (currentFileList[i].Filename == filename){
- return currentFileList[i];
- }
- }
- return null;
- }
- /*
- Drop list columns based on how much room the file area actually has.
- A media query cannot do this because opening the details pane steals
- horizontal space without changing the window width.
- */
- function updateFileAreaDensity(){
- var width = $("#fileArea").width();
- //The breakpoints suit the default widths. A resized column moves them
- //by as much as it grew or shrank, so the name column keeps its room
- var dateGrowth = columnWidth("date") - COLUMN_DEFAULT_WIDTHS.date;
- var typeGrowth = columnWidth("type") - COLUMN_DEFAULT_WIDTHS.type;
- var sizeGrowth = columnWidth("size") - COLUMN_DEFAULT_WIDTHS.size;
- $("#fileArea").toggleClass("narrow", width < 580 + dateGrowth + typeGrowth + sizeGrowth)
- .toggleClass("verynarrow", width < 440 + dateGrowth + sizeGrowth);
- }
- function renderListView(){
- var head = '<div class="fsListHead">' +
- sortableHeader("colName", "name", applocale.getString("list/name", "Name")) +
- sortableHeader("colDate", "date", applocale.getString("list/date", "Date Modified")) +
- sortableHeader("colType", "type", applocale.getString("list/type", "Type")) +
- sortableHeader("colSize", "size", applocale.getString("list/size", "Size")) +
- '</div>';
- var rows = "";
- for (var i = 0; i < renderedFileList.length; i++){
- var fileObject = renderedFileList[i];
- var selectable = objectIsSelectable(fileObject);
- rows += '<div class="fsRow fileObject' + (selectable ? "" : " disabledObject") + '"' +
- ' fid="' + i + '"' +
- ' filepath="' + encodeURIComponent(fileObject.Filepath) + '"' +
- ' filename="' + encodeURIComponent(fileObject.Filename) + '"' +
- ' isDir="' + fileObject.IsDir + '"' +
- ' onclick="selectThis(this, event);" ondblclick="openThis(this, event);"' +
- ' oncontextmenu="showContextMenu(event, this);">' +
- '<div class="fsCell colName">' + smallGlyph(fileObject.Filename, fileObject.IsDir) +
- '<span class="fsRowName">' + escapeHTML(fileObject.Filename) + '</span></div>' +
- '<div class="fsCell colDate">' + formatTimestamp(fileObject.ModTime) + '</div>' +
- '<div class="fsCell colType">' + escapeHTML(getTypeName(fileObject.Filename, fileObject.IsDir)) + '</div>' +
- '<div class="fsCell colSize">' + (fileObject.IsDir ? "--" : escapeHTML(fileObject.Displaysize || formatBytes(fileObject.Filesize))) + '</div>' +
- '</div>';
- }
- $("#fileArea").append(head + rows);
- }
- function sortableHeader(columnClass, field, label){
- var isSorted = (sortField == field);
- return '<div class="fsCol ' + columnClass + (isSorted ? " sorted" : "") + '" data-col="' + field + '" onclick="onHeaderClick(\'' + field + '\');">' +
- '<span class="fsColInner">' +
- '<span class="fsColLabel">' + escapeHTML(label) + '</span>' +
- '<span class="fsSortMark">' + (sortAscending ? ICONS.arrowUp : ICONS.arrowDown) + '</span>' +
- '</span>' +
- '<span class="fsColGrip" onpointerdown="startColumnResize(event, this);"' +
- ' onclick="event.stopPropagation();" ondblclick="resetColumnPair(event, this);"></span>' +
- '</div>';
- }
- function onHeaderClick(field){
- //A resize that ends over its own header cell leaves a click behind
- if (Date.now() - columnResizeEndedAt < 300){
- return;
- }
- if (sortField == field){
- sortAscending = !sortAscending;
- }else{
- sortField = field;
- sortAscending = true;
- }
- applyViewPreferences();
- saveViewPreferences();
- renderFileList();
- }
- /* ------------------------------------------------------------------ */
- /* List columns */
- /* ------------------------------------------------------------------ */
- /*
- The grip on a header cell's right edge is the boundary between that
- column and the next visible one. Dragging it trades width between
- those two only, so no other column moves, and double clicking it puts
- both back to their defaults - the same model as the File Manager's
- details view (js/explorer/columns.js).
- Name is the one fluid column and is never given a width. When it is
- one of the pair only the other column is sized, and name takes up the
- difference, which comes to the same thing.
- */
- function columnWidth(key){
- return columnWidths[key] != undefined ? columnWidths[key] : COLUMN_DEFAULT_WIDTHS[key];
- }
- function columnMinWidth(key){
- return key == "name" ? NAME_COLUMN_MIN_WIDTH : COLUMN_MIN_WIDTH;
- }
- //Keeps only known columns with a usable number, so a corrupted
- //preference cannot break the layout
- function parseColumnWidths(saved){
- var widths = {};
- if (saved == null || typeof saved != "object"){
- return widths;
- }
- for (var key in COLUMN_DEFAULT_WIDTHS){
- var width = parseInt(saved[key]);
- if (!isNaN(width)){
- widths[key] = Math.max(COLUMN_MIN_WIDTH, width);
- }
- }
- return widths;
- }
- function applyColumnWidths(){
- var area = document.getElementById("fileArea");
- for (var key in COLUMN_DEFAULT_WIDTHS){
- if (columnWidths[key] != undefined){
- area.style.setProperty("--fs-col-" + key, Math.round(columnWidths[key]) + "px");
- }else{
- area.style.removeProperty("--fs-col-" + key);
- }
- }
- }
- //The two header cells a grip sits between, skipping columns the
- //density classes have hidden
- function columnPairFor(grip){
- var cell = $(grip).closest(".fsCol")[0];
- var cells = $(cell).parent().children(".fsCol").filter(":visible").toArray();
- var next = cells[cells.indexOf(cell) + 1];
- if (next == undefined){
- return null;
- }
- return {
- left: cell,
- right: next,
- leftKey: $(cell).attr("data-col"),
- rightKey: $(next).attr("data-col")
- };
- }
- function startColumnResize(event, grip){
- if (event.button != 0){
- return;
- }
- //Keeps the press from selecting text or reaching the sort handler
- event.preventDefault();
- event.stopPropagation();
- var pair = columnPairFor(grip);
- if (pair == null){
- return;
- }
- var startX = event.clientX;
- var startLeft = pair.left.offsetWidth;
- var startRight = pair.right.offsetWidth;
- var total = startLeft + startRight;
- //A column a small window already squeezed under its minimum may stay
- //there, it just cannot be dragged any narrower
- var minLeft = Math.min(startLeft, columnMinWidth(pair.leftKey));
- var maxLeft = total - Math.min(startRight, columnMinWidth(pair.rightKey));
- var moved = false;
- //Same capture pattern as the sidebar splitter, see initSidebarSplitter()
- try { grip.setPointerCapture(event.pointerId); } catch(e) {}
- grip.classList.add("dragging");
- $("body").addClass("fsResizing");
- function onMove(e){
- var left = Math.round(Math.min(maxLeft, Math.max(minLeft, startLeft + e.clientX - startX)));
- if (pair.leftKey != "name"){
- columnWidths[pair.leftKey] = left;
- }
- if (pair.rightKey != "name"){
- columnWidths[pair.rightKey] = total - left;
- }
- moved = moved || left != startLeft;
- applyColumnWidths();
- }
- function onEnd(){
- //Listeners go first: releasing the capture fires lostpointercapture
- grip.removeEventListener("pointermove", onMove);
- grip.removeEventListener("pointerup", onEnd);
- grip.removeEventListener("pointercancel", onEnd);
- grip.removeEventListener("lostpointercapture", onEnd);
- try { grip.releasePointerCapture(event.pointerId); } catch(e) {}
- grip.classList.remove("dragging");
- $("body").removeClass("fsResizing");
- columnResizeEndedAt = Date.now();
- if (moved){
- saveViewPreferences();
- updateFileAreaDensity();
- }
- }
- grip.addEventListener("pointermove", onMove);
- grip.addEventListener("pointerup", onEnd);
- grip.addEventListener("pointercancel", onEnd);
- //Capture taken away without a pointerup ends the drag as well
- grip.addEventListener("lostpointercapture", onEnd);
- }
- function resetColumnPair(event, grip){
- event.stopPropagation();
- var pair = columnPairFor(grip);
- if (pair == null){
- return;
- }
- delete columnWidths[pair.leftKey];
- delete columnWidths[pair.rightKey];
- applyColumnWidths();
- saveViewPreferences();
- updateFileAreaDensity();
- }
- function renderGridView(){
- var tiles = "";
- for (var i = 0; i < renderedFileList.length; i++){
- var fileObject = renderedFileList[i];
- var selectable = objectIsSelectable(fileObject);
- var meta = fileObject.IsDir ?
- formatTimestamp(fileObject.ModTime) :
- formatTimestamp(fileObject.ModTime) + "<br>" + escapeHTML(fileObject.Displaysize || formatBytes(fileObject.Filesize));
- tiles += '<div class="fsTile fileObject' + (selectable ? "" : " disabledObject") + '"' +
- ' fid="' + i + '"' +
- ' filepath="' + encodeURIComponent(fileObject.Filepath) + '"' +
- ' filename="' + encodeURIComponent(fileObject.Filename) + '"' +
- ' isDir="' + fileObject.IsDir + '"' +
- ' onclick="selectThis(this, event);" ondblclick="openThis(this, event);"' +
- ' oncontextmenu="showContextMenu(event, this);">' +
- //Folders always keep the drawn folder glyph - no thumbnail
- //and no opener badge is rendered for them at all
- '<div class="fsThumb">' + largeGlyph(fileObject.Filename, fileObject.IsDir) +
- (fileObject.IsDir ? "" : '<img class="fsThumbImg"><span class="fsAppBadge"><img></span>') +
- '</div>' +
- '<div class="fsTileName" title="' + escapeHTML(fileObject.Filename) + '">' + escapeHTML(fileObject.Filename) + '</div>' +
- '<div class="fsTileMeta"><span class="fsTileMetaText">' + meta + '</span>' +
- '<button class="fsTileMore" title="More" onclick="onTileMore(this, event);">' + ICONS.more + '</button>' +
- '</div>' +
- '</div>';
- }
- $("#fileArea").append('<div class="fsGrid">' + tiles + '</div>');
- }
- //A file object is only clickable if it matches the requested selection type
- function objectIsSelectable(fileObject){
- if (fileObject.IsDir){
- //Folders are always navigable, and selectable in folder mode
- return true;
- }
- return type != "folder";
- }
- function onTileMore(button, event){
- event.stopPropagation();
- var tile = $(button).closest(".fileObject");
- selectThis(tile[0], {ctrlKey: false, shiftKey: false});
- if (!detailsOpen){
- toggleDetailsPanel();
- }
- /*
- Show this tile explicitly rather than whatever is selected.
- Plenty of items are previewable but not selectable in the
- current picker mode - a folder while picking files, any file
- while picking a folder - and selectThis() leaves those
- unselected by design. Going through the selection here left
- the panel blank for exactly those items until the tile itself
- was clicked.
- */
- updateDetailsFor([tile[0]]);
- }
- /* ------------------------------------------------------------------ */
- /* Thumbnails and application icons */
- /* ------------------------------------------------------------------ */
- function startThumbnailLoader(){
- //Drop anything still streaming for the previous directory
- if (thumbLoader != null){
- thumbLoader.cancel();
- }
- var targets = [];
- $("#fileArea").find(".fileObject").each(function(){
- targets.push({
- filename: decodeURIComponent($(this).attr("filename")),
- filepath: decodeURIComponent($(this).attr("filepath")),
- isDir: $(this).attr("isDir") == "true",
- dom: this
- });
- });
- thumbLoader = FileThumb.loadThumbnails({
- root: "../../",
- folder: currentDir,
- targets: targets,
- //The picker keeps the drawn folder glyph instead of the
- //server rendered folder preview
- includeFolders: false,
- onLoad: function(target, src){
- applyThumbnail(target, src);
- }
- });
- }
- function applyThumbnail(target, src){
- $(target.dom).find(".fsThumbImg").attr("src", src).addClass("loaded");
- $(target.dom).find(".fsThumb").addClass("hasThumb");
- loadAppIconBadge(target.dom, target.filename);
- //Keep the details preview in sync when the selected file resolves
- var selected = $("#fileArea").find(".fileObject.selected");
- if (selected.length == 1 && selected[0] == target.dom){
- $("#detailsBody").find(".fsThumbImg").attr("src", src).addClass("loaded");
- $("#detailsBody").find(".fsDetailsPreview").addClass("hasThumb");
- }
- }
- //Look up the WebApp registered to open this extension and stamp its icon
- //onto the thumbnail, the same way the desktop marks its file shortcuts
- function loadAppIconBadge(fileObjectDOM, filename){
- getDefaultOpener("." + getExt(filename), function(moduleInfo){
- if (moduleInfo == null || moduleInfo.IconPath == undefined || moduleInfo.IconPath == ""){
- return;
- }
- var badge = $(fileObjectDOM).find(".fsAppBadge");
- //A module may declare an icon that is not shipped. Only reveal
- //the badge once the image has actually decoded
- badge.find("img").off("load error").on("load", function(){
- badge.css("display", "block");
- }).on("error", function(){
- badge.css("display", "none");
- }).attr("src", "../../" + moduleInfo.IconPath);
- });
- }
- function getDefaultOpener(ext, callback){
- FileThumb.getDefaultOpener(ext, callback, "../../");
- }
- /* ------------------------------------------------------------------ */
- /* Breadcrumb and navigation */
- /* ------------------------------------------------------------------ */
- function renderBreadcrumb(){
- var path = currentDir;
- //Split the virtual path into its root ("user:/") and the sub path
- var rootEnd = path.indexOf(":/");
- var root = "";
- var subpath = "";
- if (rootEnd > 0){
- root = path.substring(0, rootEnd + 2);
- subpath = path.substring(rootEnd + 2);
- }else{
- root = path;
- }
- var crumbs = [];
- crumbs.push({label: rootNameMap[root] || root, path: root});
- var segments = subpath.split("/");
- var accumulated = root;
- for (var i = 0; i < segments.length; i++){
- if (segments[i] == ""){
- continue;
- }
- accumulated = accumulated + segments[i] + "/";
- crumbs.push({label: segments[i], path: accumulated});
- }
- var html = "";
- for (var i = 0; i < crumbs.length; i++){
- if (i > 0){
- html += '<span class="fsCrumbSep">›</span>';
- }
- html += '<span class="fsCrumb' + (i == crumbs.length - 1 ? " last" : "") + '"' +
- ' onclick="onCrumbClick(event, \'' + encodeURIComponent(crumbs[i].path) + '\');"' +
- ' title="' + escapeHTML(crumbs[i].path) + '">' + escapeHTML(crumbs[i].label) + '</span>';
- }
- html += '<span class="fsCrumbPad"></span>';
- $("#breadcrumb").html(html);
- }
- //"Search tmp" - the placeholder names the folder being searched
- function updateSearchPlaceholder(){
- var name = getCurrentFolderName();
- $("#searchInput").attr("placeholder", name == "" ? searchPlaceholderTemplate : searchPlaceholderTemplate + " " + name);
- }
- function getCurrentFolderName(){
- var path = currentDir;
- if (path.substring(path.length - 1) == "/"){
- path = path.substring(0, path.length - 1);
- }
- if (rootNameMap[path + "/"] != undefined){
- return rootNameMap[path + "/"];
- }
- var name = path.split("/").pop();
- return name.replace(/:$/, "");
- }
- function onCrumbClick(event, encodedPath){
- event.stopPropagation();
- var target = decodeURIComponent(encodedPath);
- if (target != currentDir){
- listDir(target);
- }
- }
- //Clicking the empty part of the path bar turns it into a text field,
- //keeping the old manual path entry behaviour available
- function onPathbarClick(event){
- if ($(event.target).closest(".fsCrumb").length > 0){
- return;
- }
- $("#pathbar").addClass("editing");
- $("#addressbar").val(currentDir).focus().select();
- }
- $("#addressbar").on("change", function(){
- updatePath();
- });
- $("#addressbar").on("keydown", function(event){
- if (event.which == 27){
- //Escape leaves the address bar without navigating
- event.stopPropagation();
- $("#pathbar").removeClass("editing");
- $("#addressbar").blur();
- }
- });
- $("#addressbar").on("blur", function(){
- $("#pathbar").removeClass("editing");
- renderBreadcrumb();
- });
- function updateNavButtons(){
- $("#backBtn").prop("disabled", historyIndex <= 0);
- $("#forwardBtn").prop("disabled", historyIndex >= pathHistory.length - 1);
- $("#upBtn").prop("disabled", getParentPath(currentDir) == "");
- }
- function getParentPath(path){
- var trimmed = path;
- if (trimmed.substring(trimmed.length - 1) == "/"){
- trimmed = trimmed.substring(0, trimmed.length - 1);
- }
- //Already at a virtual root such as "user:/", there is nowhere to go up to
- if (trimmed.indexOf("/") < 0 || trimmed.substring(trimmed.length - 1) == ":"){
- return "";
- }
- var segments = trimmed.split("/");
- segments.pop();
- var parent = segments.join("/");
- if (parent.length == 0){
- return "";
- }
- //One level below the root collapses back onto the root itself,
- //e.g. "user:/tmp" -> "user:/"
- return parent + "/";
- }
- function parentDir(){
- var parent = getParentPath(currentDir);
- if (parent != ""){
- listDir(parent);
- }
- }
- function backDir(){
- if (historyIndex > 0){
- historyIndex--;
- listDir(pathHistory[historyIndex], false);
- }
- }
- function forwardDir(){
- if (historyIndex < pathHistory.length - 1){
- historyIndex++;
- listDir(pathHistory[historyIndex], false);
- }
- }
- function openThis(object, event){
- if (event != undefined && event.preventDefault != undefined){
- event.preventDefault();
- }
- var filepath = decodeURIComponent($(object).attr("filepath"));
- if ($(object).attr("isDir") == "true"){
- listDir(filepath);
- }else{
- chooseThisFile(object);
- }
- }
- function chooseThisFile(object){
- if (type == "folder"){
- return;
- }
- $(".fileObject.selected").removeClass("selected");
- $(object).addClass("selected");
- $("#filename").val(decodeURIComponent($(object).attr("filename")));
- confirmSelection();
- }
- /* ------------------------------------------------------------------ */
- /* Selection */
- /* ------------------------------------------------------------------ */
- function selectThis(object, event){
- var isDir = $(object).attr("isDir") == "true";
- var filename = decodeURIComponent($(object).attr("filename"));
- var useCtrl = (event != undefined && (isMacOS ? event.metaKey : event.ctrlKey)) || ctrlDown;
- var useShift = (event != undefined && event.shiftKey) || shiftDown;
- if (isDir && type == "file"){
- //Folders cannot be picked in file mode, but they can still be
- //shown in the details pane
- updateDetailsFor([object]);
- return;
- }else if (!isDir && type == "folder"){
- updateDetailsFor([object]);
- return;
- }else if (type == "new" && !isDir){
- //Use this filename as the newfile name (aka overwrite mode)
- $("#filename").val(filename);
- $(".fileObject.selected").removeClass("selected");
- updateDetailsFor([object]);
- return;
- }else if (type == "new" && isDir){
- //Selected a folder in new mode. Only preview it
- updateDetailsFor([object]);
- return;
- }
- if (multiSelect && useCtrl){
- //Add this into selection list
- $(object).toggleClass("selected");
- }else if (multiSelect && useShift){
- var start = parseInt(lastClickedItemID);
- var end = parseInt($(object).attr("fid"));
- if (isNaN(start)){
- start = end;
- }
- if (start > end){
- var swap = start;
- start = end;
- end = swap;
- }
- var fileObjects = $("#fileArea").find(".fileObject");
- for (var k = start; k <= end; k++){
- $(fileObjects[k]).addClass("selected");
- }
- }else{
- //Reset and add this into selection list
- $(".fileObject.selected").removeClass("selected");
- $(object).addClass("selected");
- }
- //Update last selected id
- lastClickedItemID = $(object).attr("fid");
- var selected = $("#fileArea").find(".fileObject.selected");
- if (selected.length == 1){
- $("#filename").val(decodeURIComponent(selected.attr("filename")));
- }else if (selected.length > 1){
- $("#filename").val("");
- }
- setWindowTitleForSelection(selected.length);
- updateDetailsFor(selected.toArray());
- }
- /*
- applocale sets the window title to the localized "fwtitle" once the
- locale file lands, and this runs again on every selection change - so
- the whole string is rebuilt from the locale, base word included, or the
- title would drop back to English the moment something is selected.
- */
- function setWindowTitleForSelection(objectCount){
- //Same string as the in-dialog title bar, and the fwtitle applocale sets
- var baseTitle = applocale.getString("title", "Open");
- if (objectCount == 0){
- ao_module_setWindowTitle(baseTitle);
- return;
- }
- /*
- Singular and plural are separate keys rather than one string with
- the count spliced in: languages that do not inflect simply carry the
- same text in both, while English still reads "1 file selected".
- */
- var countKey = (objectCount > 1) ? "title/itemsSelected" : "title/itemSelected";
- var fallbackPost = (objectCount > 1) ? " items selected" : " item selected";
- if (type == "file"){
- countKey = (objectCount > 1) ? "title/filesSelected" : "title/fileSelected";
- fallbackPost = (objectCount > 1) ? " files selected" : " file selected";
- }else if (type == "folder"){
- countKey = (objectCount > 1) ? "title/foldersSelected" : "title/folderSelected";
- fallbackPost = (objectCount > 1) ? " folders selected" : " folder selected";
- }
- /*
- The phrase is split around the digit - "<pre>2<post>" - because the
- count does not sit in the same place in every language: Chinese puts
- it in the middle ("已選取 2 個資料夾") where English trails it
- ("2 files selected"). Each half carries its own spacing, so a
- language that wants the digit against the following word can have
- that too ("파일 2개 선택됨").
- */
- var pre = applocale.getString(countKey + "/pre", "");
- var post = applocale.getString(countKey + "/post", fallbackPost);
- ao_module_setWindowTitle(baseTitle + " (" + pre + objectCount + post + ")");
- }
- function confirmSelection(){
- var files = [];
- $("#fileArea").find(".fileObject.selected").each(function(){
- files.push({
- filename: decodeURIComponent($(this).attr("filename")),
- filepath: decodeURIComponent($(this).attr("filepath"))
- });
- });
- //Check if currentdir end with "/". If not, append it
- if (currentDir.substr(currentDir.length - 1, 1) != "/"){
- currentDir = currentDir + "/";
- }
- //Nothing highlighted but a name was typed: resolve it against the
- //current listing, the way a native open dialog does
- if (files.length == 0 && (type == "file" || type == "folder")){
- var typedName = $("#filename").val().trim();
- if (typedName != ""){
- for (var i = 0; i < currentFileList.length; i++){
- var candidate = currentFileList[i];
- if (candidate.Filename == typedName &&
- ((type == "folder" && candidate.IsDir) || (type == "file" && !candidate.IsDir))){
- files.push({
- filename: candidate.Filename,
- filepath: candidate.Filepath
- });
- break;
- }
- }
- }
- }
- //Check for special cases
- if (files.length == 0 && type == "folder"){
- //Select the current path as target instead
- var currentPathname = currentDir.split("/");
- currentPathname.pop();
- currentPathname = currentPathname.pop();
- if (currentPathname == ""){
- currentPathname = currentDir;
- }
- files.push({
- filename: currentPathname,
- filepath: currentDir
- });
- }else if (files.length == 0 && type == "new"){
- //Push this new file into the return structure
- var newFilename = $("#filename").val();
- files.push({
- filename: newFilename,
- filepath: currentDir + newFilename
- });
- }
- if (type == "new" && files.length == 1){
- //Writing over an existing file needs the user's say so first
- confirmOverwrite(files[0], function(){
- deliverSelection(files);
- });
- return;
- }
- deliverSelection(files);
- }
- //Hands the chosen files to the calling app and closes the selector
- function deliverSelection(files){
- selectionConfirmed = true;
- if (ao_module_virtualDesktop){
- if (!ao_module_parentCallback(files)){
- //Parent callback not exists
- selectionConfirmed = false;
- alert("Selection Failed. Is parent window alive?");
- }else{
- parent.closeFwProcess(ao_module_windowID);
- }
- }else{
- if (listenerUUID == ""){
- selectionConfirmed = false;
- alert("Invalid listener UUID. Please re-open your file selector.");
- return;
- }
- localStorage.setItem(listenerUUID, JSON.stringify(files));
- $("#waitloader").addClass("show");
- setTimeout(function(){
- $("#waitloadertext").text("System is not responding. Please close this window and retry.");
- }, 10000);
- }
- }
- /* ------------------------------------------------------------------ */
- /* Replace prompt (new file mode) */
- /* ------------------------------------------------------------------ */
- /*
- A new file name that is already taken asks before the caller is told
- to write over it. The listing answers at once for what is on screen.
- A name it does not hold is still checked with the server: the file
- may be hidden from the listing, differ only in letter case on a case
- insensitive disk, or have been created after the listing loaded.
- A name taken by a folder is left to the caller, as before.
- */
- var overwriteCheckPending = false;
- var overwriteProceed = null; //Runs on "Replace", set while the prompt is open
- function confirmOverwrite(target, proceed){
- if (overwriteCheckPending || overwriteDialogIsOpen()){
- //A second Create press while the first is still being answered
- return;
- }
- if (target.filename == ""){
- proceed();
- return;
- }
- var listed = getFileObjectByName(target.filename);
- if (listed != null){
- if (listed.IsDir){
- proceed();
- }else{
- showOverwriteDialog(target.filename, proceed);
- }
- return;
- }
- overwriteCheckPending = true;
- $.ajax({
- url: "../../system/file_system/getProperties",
- method: "POST",
- data: {path: target.filepath},
- success: function(data){
- overwriteCheckPending = false;
- if (data != null && data.error === undefined && !data.IsDirectory){
- showOverwriteDialog(target.filename, proceed);
- }else{
- //Nothing there, the name is free
- proceed();
- }
- },
- error: function(){
- //Could not ask. Carry on the way the selector always has
- overwriteCheckPending = false;
- proceed();
- }
- });
- }
- function overwriteDialogIsOpen(){
- return $("#overwriteDialog").hasClass("show");
- }
- function showOverwriteDialog(filename, proceed){
- overwriteProceed = proceed;
- $("#overwriteFile").html(smallGlyph(filename, false) +
- '<span class="fsModalFileName">' + escapeHTML(filename) + '</span>');
- $("#overwriteFile .fsModalFileName").attr("title", filename);
- closeContextMenu();
- closeMoreMenu();
- $("#overwriteDialog").addClass("show");
- //Cancel is the default, so a stray Enter never replaces a file
- $("#overwriteCancelBtn").focus();
- }
- function answerOverwrite(replace){
- var proceed = overwriteProceed;
- overwriteProceed = null;
- $("#overwriteDialog").removeClass("show");
- if (replace){
- if (proceed != null){
- proceed();
- }
- return;
- }
- //A double clicked file stays highlighted, and a highlighted file
- //would be returned again in place of the name typed next
- $("#fileArea").find(".fileObject.selected").removeClass("selected");
- //Back to the name field with the name part selected, ready for a new one
- var input = $("#filename");
- var name = input.val();
- var dot = name.lastIndexOf(".");
- input.focus();
- input[0].setSelectionRange(0, dot > 0 ? dot : name.length);
- }
- //The prompt keeps the keyboard until it is answered
- function handleOverwriteDialogKey(event){
- if (event.which == 27){
- event.preventDefault();
- answerOverwrite(false);
- }else if (event.which == 9){
- //Tab moves between the two buttons, never to the selector behind
- event.preventDefault();
- var cancelBtn = document.getElementById("overwriteCancelBtn");
- var replaceBtn = document.getElementById("overwriteReplaceBtn");
- (document.activeElement == cancelBtn ? replaceBtn : cancelBtn).focus();
- }else if (event.which == 13){
- //A focused button answers through its own click. Anywhere else
- //Enter takes the default answer
- if ($(event.target).closest("#overwriteDialog button").length == 0){
- event.preventDefault();
- answerOverwrite(false);
- }
- }
- }
- function cancelSelection(){
- if (selectionConfirmed || listenerUUID == ""){
- return;
- }
- localStorage.setItem(listenerUUID, JSON.stringify("&&selection_canceled&&"));
- }
- function closeSelector(){
- cancelSelection();
- if (ao_module_virtualDesktop){
- parent.closeFwProcess(ao_module_windowID);
- }else{
- window.close();
- }
- }
- //Handle on window close function, cancel current selection
- window.onbeforeunload = function(){
- cancelSelection();
- }
- //Overwrite the ao_module close function so closing the float window
- //cancels the selection instead of silently returning nothing
- function ao_module_close(){
- closeSelector();
- }
- /* ------------------------------------------------------------------ */
- /* Details panel */
- /* ------------------------------------------------------------------ */
- function clearDetails(){
- $("#detailsBody").html('<div class="fsDetailsEmpty">' +
- escapeHTML(applocale.getString("details/empty", "Select an item to see its details")) + '</div>');
- }
- function updateDetailsPanel(){
- updateDetailsFor($("#fileArea").find(".fileObject.selected").toArray());
- }
- function updateDetailsFor(objects){
- if (!detailsOpen){
- return;
- }
- if (objects == undefined || objects.length == 0){
- clearDetails();
- return;
- }
- if (objects.length > 1){
- renderMultiDetails(objects);
- return;
- }
- var target = $(objects[0]);
- var filename = decodeURIComponent(target.attr("filename"));
- var filepath = decodeURIComponent(target.attr("filepath"));
- var isDir = target.attr("isDir") == "true";
- var html = '<div class="fsDetailsPreview">' + largeGlyph(filename, isDir) + '<img class="fsThumbImg"></div>' +
- '<div class="fsDetailsName">' + escapeHTML(filename) + '</div>' +
- '<div id="detailRows">' +
- detailRow(applocale.getString("details/type", "Type"), escapeHTML(getTypeName(filename, isDir))) +
- detailRow(applocale.getString("details/size", "Size"), '<span id="detailSize">' +
- escapeHTML(applocale.getString("message/loading", "Loading")) + '</span>') +
- detailRow(applocale.getString("details/modified", "Date Modified"), '<span id="detailModified">--</span>') +
- detailRow(applocale.getString("details/path", "Path"), escapeHTML(filepath)) +
- '</div>';
- $("#detailsBody").html(html);
- //Reuse the thumbnail already rendered in the listing, if there is one
- var existingThumb = target.find(".fsThumbImg");
- if (existingThumb.length > 0 && existingThumb.hasClass("loaded")){
- $("#detailsBody").find(".fsThumbImg").attr("src", existingThumb.attr("src")).addClass("loaded");
- $("#detailsBody").find(".fsDetailsPreview").addClass("hasThumb");
- }else if (!isDir){
- loadDetailsThumbnail(filepath);
- }
- loadDetailProperties(filepath, filename, isDir);
- }
- function detailRow(key, valueHTML){
- return '<div class="fsDetailRow"><div class="fsDetailKey">' + escapeHTML(key) + '</div>' +
- '<div class="fsDetailVal">' + valueHTML + '</div></div>';
- }
- function loadDetailsThumbnail(filepath){
- $.ajax({
- url: "../../system/file_system/loadThumbnail",
- data: {vpath: filepath},
- success: function(data){
- if (data == undefined || data == "" || data.error != undefined){
- return;
- }
- var selected = $("#fileArea").find(".fileObject.selected");
- //Only paint it if the user has not moved the selection on
- if (selected.length == 1 && decodeURIComponent(selected.attr("filepath")) != filepath){
- return;
- }
- $("#detailsBody").find(".fsThumbImg")
- .attr("src", FileThumb.base64ToDataURL(data))
- .addClass("loaded");
- $("#detailsBody").find(".fsDetailsPreview").addClass("hasThumb");
- }
- });
- }
- function loadDetailProperties(filepath, filename, isDir){
- $.ajax({
- url: "../../system/file_system/getProperties",
- method: "POST",
- data: {path: filepath},
- success: function(data){
- if (data.error !== undefined){
- $("#detailSize").text("--");
- return;
- }
- $("#detailSize").text(data.Filesize < 0 ? "--" :
- formatBytes(data.Filesize) + " (" + data.Filesize.toLocaleString() + " " +
- applocale.getString("details/bytes", "bytes") + ")");
- $("#detailModified").text(data.LastModTime || formatTimestamp(data.LastModUnix));
- if (data.Owner != undefined && data.Owner != ""){
- $("#detailRows").append(detailRow(applocale.getString("details/owner", "Owner"), escapeHTML(data.Owner)));
- }
- if (data.Permission != undefined && data.Permission != ""){
- $("#detailRows").append(detailRow(applocale.getString("details/permission", "Permission"), escapeHTML(data.Permission)));
- }
- },
- error: function(){
- $("#detailSize").text("--");
- }
- });
- //Show which WebApp would open this file, using the registered
- //default opener of its extension
- if (!isDir){
- getDefaultOpener("." + getExt(filename), function(moduleInfo){
- if (moduleInfo == null){
- return;
- }
- var iconHTML = "";
- if (moduleInfo.IconPath != undefined && moduleInfo.IconPath != ""){
- iconHTML = '<img class="fsOpenerIcon" src="../../' + escapeHTML(moduleInfo.IconPath) +
- '" onerror="this.style.display=\'none\';">';
- }
- $("#detailRows").append(detailRow(applocale.getString("details/opensWith", "Opens With"),
- iconHTML + '<span>' + escapeHTML(moduleInfo.Name || "") + '</span>'));
- });
- }
- }
- function renderMultiDetails(objects){
- var folderCount = 0;
- var fileCount = 0;
- for (var i = 0; i < objects.length; i++){
- if ($(objects[i]).attr("isDir") == "true"){
- folderCount++;
- }else{
- fileCount++;
- }
- }
- var html = '<div class="fsDetailsPreview">' + largeGlyph("", true) + '</div>' +
- '<div class="fsDetailsName">' + objects.length + " " +
- escapeHTML(applocale.getString("details/itemsSelected", "items selected")) + '</div>' +
- '<div id="detailRows">' +
- detailRow(applocale.getString("details/folders", "Folders"), folderCount) +
- detailRow(applocale.getString("details/files", "Files"), fileCount) +
- '</div>';
- $("#detailsBody").html(html);
- }
- /* ------------------------------------------------------------------ */
- /* Sidebar */
- /* ------------------------------------------------------------------ */
- function initRoots(){
- $.get("../../system/file_system/listRoots?user=true", function(data){
- $("#userlist").html("");
- if (data == null || data.error != undefined){
- return;
- }
- for (var i = 0; i < data.length; i++){
- if (data[i].IsDir != true){
- continue;
- }
- if (data[i]["Filename"].substring(0, 1) == "."){
- //Do not show hidden files
- continue;
- }
- var iconAndFolderName = getUserRootIcons(data[i]["Filename"]);
- $("#userlist").append(sidebarItem(data[i]["Filepath"], iconAndFolderName[0], iconAndFolderName[1], iconAndFolderName[2]));
- }
- updateSidebarActiveItem();
- });
- $.get("../../system/file_system/listRoots", function(data){
- $("#storagelist").html("");
- if (data == null || data.error != undefined){
- return;
- }
- for (var i = 0; i < data.length; i++){
- rootNameMap[data[i]["RootPath"]] = data[i]["RootName"];
- $("#storagelist").append(sidebarItem(data[i]["RootPath"], ICONS.drive, "#5f6368",
- data[i]["RootName"] + " (" + data[i]["RootPath"] + ")"));
- }
- renderBreadcrumb();
- updateSidebarActiveItem();
- });
- }
- function sidebarItem(filepath, iconSVG, iconColor, label){
- return '<div class="fsSideItem" filepath="' + encodeURIComponent(filepath) + '" onclick="openShortcut(this);" title="' + escapeHTML(label) + '">' +
- '<span class="fsSideIcon" style="color:' + iconColor + ';">' + iconSVG + '</span>' +
- '<span class="fsSideLabel">' + escapeHTML(label) + '</span></div>';
- }
- //Returns [svg, colour, localized name] for a user virtual root folder
- function getUserRootIcons(foldername){
- var icon = ICONS.folderSide;
- var color = "#f0b429";
- var name = foldername;
- var key = foldername.toLowerCase();
- if (key == "desktop"){
- icon = ICONS.desktop;
- color = "#1a73e8";
- name = applocale.getString("sidebar/vroot/desktop", name);
- }else if (key == "document"){
- icon = ICONS.document;
- color = "#1a73e8";
- name = applocale.getString("sidebar/vroot/document", name);
- }else if (key == "music" || key == "audio"){
- icon = ICONS.music;
- color = "#e8467c";
- name = applocale.getString("sidebar/vroot/music", name);
- }else if (key == "photo" || key == "picture"){
- icon = ICONS.image;
- color = "#2aa3d4";
- name = applocale.getString("sidebar/vroot/photo", name);
- }else if (key == "video" || key == "film"){
- icon = ICONS.video;
- color = "#8b5cf6";
- name = applocale.getString("sidebar/vroot/video", name);
- }else if (key == "trash" || key == "bin" || key == "rubbish"){
- icon = ICONS.trash;
- color = "#5f6368";
- name = applocale.getString("sidebar/vroot/trash", name);
- }else if (key == "download"){
- icon = ICONS.download;
- color = "#1a73e8";
- name = applocale.getString("sidebar/vroot/download", name);
- }else if (key == "www" || key == "web" || key == "mysite"){
- icon = ICONS.globe;
- color = "#0f9d94";
- name = applocale.getString("sidebar/vroot/web", name);
- }else if (key == "model"){
- icon = ICONS.cube;
- color = "#7c4dff";
- name = applocale.getString("sidebar/vroot/model", name);
- }else if (key == "appdata"){
- icon = ICONS.code;
- color = "#5f6368";
- name = applocale.getString("sidebar/vroot/appdata", name);
- }
- return [icon, color, name];
- }
- function openShortcut(object){
- var targetdir = decodeURIComponent($(object).attr("filepath"));
- listDir(targetdir);
- if (window.innerWidth < 560){
- closeSidebar();
- }
- }
- function updateSidebarActiveItem(){
- $(".fsSideItem").each(function(){
- var itemPath = decodeURIComponent($(this).attr("filepath"));
- if (itemPath.substring(itemPath.length - 1) != "/"){
- itemPath = itemPath + "/";
- }
- var here = currentDir;
- if (here.substring(here.length - 1) != "/"){
- here = here + "/";
- }
- $(this).toggleClass("active", itemPath == here);
- });
- }
- function toggleSidebar(){
- if ($("#sidebar").hasClass("open")){
- closeSidebar();
- }else{
- $("#sidebar").addClass("open");
- $("#sidebarScrim").addClass("show");
- }
- }
- function closeSidebar(){
- $("#sidebar").removeClass("open");
- $("#sidebarScrim").removeClass("show");
- }
- /* ------------------------------------------------------------------ */
- /* Sidebar resizing */
- /* ------------------------------------------------------------------ */
- /*
- Same behaviour as the file manager's pane splitter
- (js/explorer/splitter.js): drag the sidebar edge to resize it and the
- width is remembered between visits. Remembered per browser rather than
- per account, as it describes this window on this screen.
- */
- var FS_SIDEBAR_WIDTH_KEY = "file_selector/sidebarWidth";
- var FS_SIDEBAR_DEFAULT_WIDTH = 200; //must match the width in the stylesheet
- var FS_SIDEBAR_MIN_WIDTH = 150; //below this the root names are unreadable
- var FS_SIDEBAR_MAX_WIDTH = 420;
- var FS_MAIN_MIN_WIDTH = 280; //the file list never shrinks past this
- var FS_SIDEBAR_DRAWER_WIDTH = 560; //matches the overlay media query
- /*
- The width the user asked for, which is not always the width on screen:
- a narrow window can clamp it down. Kept unclamped so the sidebar springs
- back to the chosen size once there is room for it again.
- */
- var sidebarPreferredWidth = FS_SIDEBAR_DEFAULT_WIDTH;
- //Below this width the sidebar is a drawer over the file list, not a column
- function sidebarIsDrawer(){
- return window.innerWidth < FS_SIDEBAR_DRAWER_WIDTH;
- }
- /*
- How wide the sidebar may get right now. The ceiling is not a fixed
- number: it also has to leave FS_MAIN_MIN_WIDTH for the file list, so in
- a small float window it comes down rather than letting a drag squeeze
- the listing away.
- */
- function sidebarWidthLimits(){
- var available = $(".fsBody").width() - FS_MAIN_MIN_WIDTH;
- return {
- min: FS_SIDEBAR_MIN_WIDTH,
- max: Math.min(FS_SIDEBAR_MAX_WIDTH, available)
- };
- }
- function clampSidebarWidth(width){
- var limits = sidebarWidthLimits();
- var applied = Math.round(width);
- if (isNaN(applied)){
- applied = FS_SIDEBAR_DEFAULT_WIDTH;
- }
- if (limits.max < limits.min){
- //Window too narrow to honour both bounds: the floor wins, otherwise
- //the sidebar would collapse to nothing
- return limits.min;
- }
- return Math.max(limits.min, Math.min(limits.max, applied));
- }
- /*
- Writes width and min-width together: the sidebar carries a min-width in
- the stylesheet to stop flexbox shrinking it, and leaving that behind
- would silently pin the pane at its old size on the way down.
- */
- function writeSidebarWidth(applied){
- $("#sidebar").css({
- "width": applied + "px",
- "min-width": applied + "px"
- });
- }
- //The drag path: what the user drags to becomes the remembered width
- function setSidebarWidth(width){
- sidebarPreferredWidth = clampSidebarWidth(width);
- writeSidebarWidth(sidebarPreferredWidth);
- return sidebarPreferredWidth;
- }
- /*
- Re-applies the preferred width to the DOM. Also the window resize path: a
- width that was legal in a bigger window can be over the ceiling in a
- smaller one - and back under it when the window grows again, which is why
- this clamps the preference rather than overwriting it. In the drawer
- layout the inline width is dropped entirely, so the overlay keeps the
- size the stylesheet gives it.
- */
- function applySidebarWidth(){
- if (sidebarIsDrawer()){
- $("#sidebar").css({ "width": "", "min-width": "" });
- $("#sidebarSplitter").hide();
- return;
- }
- $("#sidebarSplitter").show();
- writeSidebarWidth(clampSidebarWidth(sidebarPreferredWidth));
- }
- function saveSidebarWidth(width){
- try {
- localStorage.setItem(FS_SIDEBAR_WIDTH_KEY, String(Math.round(width)));
- } catch (e){
- //Private browsing or a full store - the width simply is not remembered
- }
- }
- function initSidebarSplitter(){
- var stored = null;
- try {
- stored = localStorage.getItem(FS_SIDEBAR_WIDTH_KEY);
- } catch (e){
- stored = null;
- }
- if (stored != null && stored != ""){
- var restored = parseInt(stored);
- if (!isNaN(restored) && restored > 0){
- sidebarPreferredWidth = restored;
- }
- }
- //Clamped on the way in, so a width saved on a wider screen still fits here
- applySidebarWidth();
- var handle = document.getElementById("sidebarSplitter");
- if (handle == null){
- return;
- }
- /*
- Pointer events rather than mousedown/mousemove: setPointerCapture
- keeps the drag alive when the cursor leaves the window, which a
- document level mousemove listener does not.
- */
- handle.addEventListener("pointerdown", function(evt){
- if (evt.button != 0 || sidebarIsDrawer()){
- return;
- }
- //Stops the drag from selecting text across the panes
- evt.preventDefault();
- var startX = evt.clientX;
- var startWidth = $("#sidebar").outerWidth();
- /*
- Capture is an optimisation, not a requirement - the listeners
- below are on the handle itself. It throws if the pointer is no
- longer active by the time this runs, which must not abort the drag.
- */
- try { handle.setPointerCapture(evt.pointerId); } catch(e) {}
- handle.classList.add("dragging");
- //Suppresses hover effects and text selection everywhere for the drag
- $("body").addClass("fsResizing");
- function onMove(e){
- setSidebarWidth(startWidth + (e.clientX - startX));
- }
- function onEnd(){
- try { handle.releasePointerCapture(evt.pointerId); } catch(e) {}
- handle.removeEventListener("pointermove", onMove);
- handle.removeEventListener("pointerup", onEnd);
- handle.removeEventListener("pointercancel", onEnd);
- handle.classList.remove("dragging");
- $("body").removeClass("fsResizing");
- //Saved on release rather than on every move, so a drag writes once
- saveSidebarWidth(sidebarPreferredWidth);
- //The grid view fits its tiles to the width of the file area
- updateFileAreaDensity();
- }
- handle.addEventListener("pointermove", onMove);
- handle.addEventListener("pointerup", onEnd);
- handle.addEventListener("pointercancel", onEnd);
- });
- }
- /* ------------------------------------------------------------------ */
- /* New folder */
- /* ------------------------------------------------------------------ */
- function menuNewFolder(){
- closeMoreMenu();
- newFolder();
- }
- /*
- Creates the folder straight away under a localized default name, then
- drops the freshly created item into inline edit so the user can type
- over it - the same flow as the desktop file managers.
- */
- function newFolder(){
- createFolder(getUniqueNewFolderName(), true);
- }
- //"New Folder", "New Folder (2)", ... so the create never collides
- function getUniqueNewFolderName(){
- var base = applocale.getString("newfolder/defaultname", "New Folder");
- var taken = {};
- currentFileList.forEach(function(fileObject){
- taken[fileObject.Filename] = true;
- });
- if (taken[base] == undefined){
- return base;
- }
- var counter = 2;
- while (taken[base + " (" + counter + ")"] != undefined){
- counter++;
- }
- return base + " (" + counter + ")";
- }
- function createFolder(folderName, editAfterCreate){
- if (folderName == undefined || folderName.trim() == ""){
- folderName = applocale.getString("newfolder/defaultname", "New Folder");
- }
- folderName = folderName.trim().replace(/[<>:"/\\|?*]/g, "_");
- //Check if folder exists
- var nameAlreadyExists = false;
- currentFileList.forEach(function(fileObject){
- if (fileObject.IsDir && fileObject.Filename == folderName){
- nameAlreadyExists = true;
- }
- });
- if (nameAlreadyExists){
- alert(applocale.getString("message/folderexists", "Folder already exists"));
- return;
- }
- //Create the new folder request
- requestCSRFToken(function(token){
- $.ajax({
- url: "../../system/file_system/newItem",
- data: {type: "folder", src: currentDir, filename: folderName, csrft: token},
- success: function(data){
- if (data.error !== undefined){
- alert(data.error);
- return;
- }
- if (editAfterCreate){
- //Picked up by renderFileList once the listing comes back
- pendingInlineRename = folderName;
- }
- refresh();
- }
- });
- });
- }
- /* ------------------------------------------------------------------ */
- /* Inline rename */
- /* ------------------------------------------------------------------ */
- var pendingInlineRename = null; //Filename to edit after the next render
- var inlineEditActive = false;
- var closeActiveInlineEdit = null; //Set while an editor is on screen
- function findFileObjectByName(filename){
- var match = null;
- $("#fileArea").find(".fileObject").each(function(){
- if (decodeURIComponent($(this).attr("filename")) == filename){
- match = this;
- }
- });
- return match;
- }
- function startInlineRename(fileObjectDOM){
- if (fileObjectDOM == null){
- return;
- }
- if (inlineEditActive && closeActiveInlineEdit != null){
- //Commit whatever is already being edited rather than refusing.
- //If focus never landed on that editor its blur would never fire
- //and the flag would stay stuck, blocking every later rename.
- closeActiveInlineEdit(true);
- }
- var target = $(fileObjectDOM);
- //List view labels the name in .fsRowName, grid view in .fsTileName
- var label = target.find(".fsRowName");
- if (label.length == 0){
- label = target.find(".fsTileName");
- }
- if (label.length == 0){
- return;
- }
- var originalName = decodeURIComponent(target.attr("filename"));
- var isDir = target.attr("isDir") == "true";
- inlineEditActive = true;
- label.addClass("editing");
- label.html('<input class="fsInlineEdit" type="text" spellcheck="false" autocomplete="off">');
- var input = label.find("input");
- input.val(originalName);
- //Swallow the row click handlers while the editor has focus
- input.on("click dblclick mousedown", function(event){
- event.stopPropagation();
- });
- var settled = false;
- var finish = function(save){
- if (settled){
- //Enter commits and then blurs, guard the second pass
- return;
- }
- settled = true;
- inlineEditActive = false;
- closeActiveInlineEdit = null;
- var newName = input.val();
- label.removeClass("editing");
- label.text(originalName);
- if (save && newName != undefined && newName.trim() != "" && newName.trim() != originalName){
- commitInlineRename(target, originalName, newName.trim());
- }
- };
- closeActiveInlineEdit = finish;
- input.on("keydown", function(event){
- event.stopPropagation();
- if (event.which == 13){
- finish(true);
- }else if (event.which == 27){
- finish(false);
- }
- });
- input.on("blur", function(){
- //Clicking away saves, matching the desktop file managers
- finish(true);
- });
- input.focus();
- //Preselect the basename so typing replaces the name but keeps the
- //extension, except on folders where the whole name is the target
- var dotIndex = originalName.lastIndexOf(".");
- if (!isDir && dotIndex > 0){
- input[0].setSelectionRange(0, dotIndex);
- }else{
- input[0].select();
- }
- }
- function commitInlineRename(target, originalName, newName){
- var safeName = newName.replace(/[<>:"/\\|?*]/g, "_");
- var filepath = decodeURIComponent(target.attr("filepath"));
- //Reject a name that is already used in this directory
- var clash = false;
- currentFileList.forEach(function(fileObject){
- if (fileObject.Filename == safeName && fileObject.Filename != originalName){
- clash = true;
- }
- });
- if (clash){
- alert(applocale.getString("message/nameexists", "An item with that name already exists"));
- return;
- }
- requestCSRFToken(function(token){
- $.ajax({
- url: "../../system/file_system/fileOpr",
- method: "POST",
- data: {
- opr: "rename",
- src: JSON.stringify([filepath]),
- new: JSON.stringify([safeName]),
- csrft: token
- },
- success: function(data){
- if (data.error !== undefined){
- alert(data.error);
- refresh();
- return;
- }
- //Keep the renamed item highlighted after the reload
- pendingSelectAfterRender = safeName;
- refresh();
- },
- error: function(){
- alert(applocale.getString("message/renamefailed", "Rename failed"));
- refresh();
- }
- });
- });
- }
- function requestCSRFToken(callback){
- $.ajax({
- url: "../../system/csrf/new",
- success: function(token){
- callback(token);
- }
- });
- }
- /* ------------------------------------------------------------------ */
- /* Context menu */
- /* ------------------------------------------------------------------ */
- /*
- Acts on the single item that was right clicked rather than on the
- current selection. The selector restricts what may be selected by
- launch type (a file cannot be highlighted in folder mode, and so on),
- so binding the menu to one explicit target keeps destructive actions
- such as Delete unambiguous.
- */
- var contextTarget = null;
- function showContextMenu(event, fileObjectDOM){
- event.preventDefault();
- event.stopPropagation();
- if (inlineEditActive){
- return;
- }
- contextTarget = fileObjectDOM;
- closeMoreMenu();
- var isDir = $(fileObjectDOM).attr("isDir") == "true";
- var menu = $("#contextMenu");
- menu.html(buildContextMenuItems(isDir));
- menu.addClass("open");
- positionContextMenu(menu, event);
- }
- /*
- Right click on empty space acts on the folder being browsed
- rather than on any item, so it offers the two things that make
- sense there. The per item handler above stops propagation, so
- this only ever runs for a click that missed every file object.
- */
- function showFolderContextMenu(event){
- event.preventDefault();
- event.stopPropagation();
- if (inlineEditActive){
- return;
- }
- //No item is involved - onContextAction keys off this being null
- contextTarget = null;
- closeMoreMenu();
- var menu = $("#contextMenu");
- menu.html(buildFolderContextMenuItems());
- menu.addClass("open");
- positionContextMenu(menu, event);
- }
- function buildFolderContextMenuItems(){
- var items = [];
- items.push(contextMenuItem("newfolder", "folder outline",
- applocale.getString("ctx/newfolder", "New Folder")));
- items.push('<div class="fsMenuSep"></div>');
- items.push(contextMenuItem("folderproperties", "",
- applocale.getString("ctx/folderproperties", "Folder Properties")));
- return items.join("");
- }
- //Clamp to the viewport so a menu never opens off screen
- function positionContextMenu(menu, event){
- var width = menu.outerWidth();
- var height = menu.outerHeight();
- var left = event.clientX;
- var top = event.clientY;
- if (left + width > window.innerWidth - 6){
- left = Math.max(6, window.innerWidth - width - 6);
- }
- if (top + height > window.innerHeight - 6){
- top = Math.max(6, window.innerHeight - height - 6);
- }
- menu.css({left: left + "px", top: top + "px"});
- }
- /*
- Glyph per row is taken from the File Manager's context menu so the two
- menus read the same: Open, Rename and Properties carry none there, and
- both "open elsewhere" rows share the external link arrow.
- */
- function buildContextMenuItems(isDir){
- var items = [];
- items.push(contextMenuItem("open", "", applocale.getString("ctx/open", "Open")));
- if (!isDir){
- items.push(contextMenuItem("openwith", "external", applocale.getString("ctx/openwith", "Open With")));
- }else{
- items.push(contextMenuItem("opennewwindow", "external",
- applocale.getString("ctx/opennewwindow", "Open in New Window")));
- }
- items.push('<div class="fsMenuSep"></div>');
- items.push(contextMenuItem("rename", "", applocale.getString("ctx/rename", "Rename")));
- items.push(contextMenuItem("delete", "trash", applocale.getString("ctx/delete", "Delete")));
- items.push(contextMenuItem("download", "download", applocale.getString("ctx/download", "Download")));
- items.push('<div class="fsMenuSep"></div>');
- items.push(contextMenuItem("properties", "", applocale.getString("ctx/properties", "Properties")));
- return items.join("");
- }
- /*
- iconClass is a Semantic UI icon name without the trailing "icon", or an
- empty string for the rows the File Manager draws without a glyph
- (Open, Rename, Properties).
- */
- function contextMenuItem(action, iconClass, label){
- return '<div class="fsMenuItem" onclick="onContextAction(\'' + action + '\');">' +
- '<span>' + escapeHTML(label) + '</span>' +
- (iconClass == "" ? "" : '<i class="' + iconClass + ' icon"></i>') +
- '</div>';
- }
- function closeContextMenu(){
- $("#contextMenu").removeClass("open");
- }
- function onContextAction(action){
- var target = contextTarget;
- closeContextMenu();
- /*
- Folder level actions come from the empty space menu and have
- no target, so they are handled before the guard below.
- */
- if (action == "newfolder"){
- newFolder();
- return;
- }else if (action == "folderproperties"){
- ctxProperties(currentDir);
- return;
- }
- if (target == null){
- return;
- }
- var filepath = decodeURIComponent($(target).attr("filepath"));
- var filename = decodeURIComponent($(target).attr("filename"));
- var isDir = $(target).attr("isDir") == "true";
- if (action == "open"){
- //Same as a double click: enter the folder, or pick the file
- openThis(target, {preventDefault: function(){}});
- }else if (action == "openwith"){
- ctxOpenWith(filepath, filename);
- }else if (action == "opennewwindow"){
- ctxOpenInNewWindow(filepath, filename);
- }else if (action == "rename"){
- startInlineRename(target);
- }else if (action == "delete"){
- ctxDelete(filepath, filename);
- }else if (action == "download"){
- ctxDownload(filepath, filename, isDir);
- }else if (action == "properties"){
- ctxProperties(filepath);
- }
- }
- //Launch the opener picker so the user chooses which WebApp handles it
- function ctxOpenWith(filepath, filename){
- var openParameter = encodeURIComponent(JSON.stringify({
- filepath: filepath,
- filename: filename
- }));
- ao_module_newfw({
- url: "SystemAO/file_system/defaultOpener.html#" + openParameter,
- width: 380,
- height: 560,
- appicon: "SystemAO/file_system/img/opener.png",
- title: "Select an opener WebApp"
- });
- }
- //Open this folder in its own File Manager window, leaving the picker alone
- function ctxOpenInNewWindow(filepath, filename){
- ao_module_newfw({
- url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(filepath),
- width: 1080,
- height: 580,
- appicon: "SystemAO/file_system/img/small_icon.png",
- title: filename
- });
- }
- function ctxDelete(filepath, filename){
- var question = applocale.getString("message/deleteconfirm", "Move this item to the trash bin?");
- if (!confirm(question + "\n\n" + filename)){
- return;
- }
- requestCSRFToken(function(token){
- $.ajax({
- url: "../../system/file_system/fileOpr",
- method: "POST",
- data: {opr: "recycle", src: JSON.stringify([filepath]), csrft: token},
- success: function(data){
- if (data.error !== undefined){
- alert(data.error);
- }
- refresh();
- },
- error: function(){
- alert(applocale.getString("message/deletefailed", "Delete failed"));
- refresh();
- }
- });
- });
- }
- function ctxDownload(filepath, filename, isDir){
- if (!isDir){
- //Single file, stream it straight down
- generateDownloadFromURL("../../media/download?file=" + encodeURIComponent(filepath), filename);
- return;
- }
- //Folders have to be archived first, same as the File Manager does
- $.ajax({
- url: "../../system/file_system/zipHandler",
- method: "POST",
- data: {opr: "tmpzip", src: JSON.stringify([filepath]), dest: ""},
- success: function(data){
- if (data.error !== undefined){
- alert(data.error);
- return;
- }
- generateDownloadFromURL("../../media/download?file=" + encodeURIComponent(data), filename + ".zip");
- },
- error: function(){
- alert(applocale.getString("message/zipfailed", "Unable to compress this folder"));
- }
- });
- }
- function generateDownloadFromURL(url, filename){
- var a = document.createElement("a");
- a.href = url;
- a.download = filename;
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- }
- function ctxProperties(filepath){
- ao_module_newfw({
- url: "SystemAO/file_system/file_properties.html#" + encodeURIComponent(JSON.stringify([filepath])),
- width: 440,
- height: 560,
- appicon: "SystemAO/file_system/img/properties.png",
- title: "File Properties"
- });
- }
- /* ------------------------------------------------------------------ */
- /* Toolbar menu */
- /* ------------------------------------------------------------------ */
- function toggleMoreMenu(event){
- event.stopPropagation();
- var isOpen = $("#moreMenu").hasClass("open");
- if (isOpen){
- closeMoreMenu();
- }else{
- $("#moreMenu").addClass("open");
- $("#moreBtn").addClass("active");
- }
- }
- function closeMoreMenu(){
- $("#moreMenu").removeClass("open");
- $("#moreBtn").removeClass("active");
- }
- $(document).on("click", function(event){
- if ($(event.target).closest("#moreMenu, #moreBtn").length == 0){
- closeMoreMenu();
- }
- if ($(event.target).closest("#contextMenu").length == 0){
- closeContextMenu();
- }
- });
- //A right click anywhere else dismisses an open context menu
- $(document).on("contextmenu", function(event){
- if ($(event.target).closest(".fileObject").length == 0){
- closeContextMenu();
- }
- });
- $("#fileArea").on("scroll", function(){
- closeContextMenu();
- });
- /* ------------------------------------------------------------------ */
- /* Search */
- /* ------------------------------------------------------------------ */
- var searchDebounce = null;
- $("#searchInput").on("input", function(){
- var value = $(this).val().toLowerCase().trim();
- clearTimeout(searchDebounce);
- searchDebounce = setTimeout(function(){
- searchKeyword = value;
- renderFileList();
- }, 150);
- });
- /* ------------------------------------------------------------------ */
- /* Keyboard */
- /* ------------------------------------------------------------------ */
- //Ctrl, or Cmd on a Mac (keyCode 91 / 93, or 224 in Firefox)
- function isMultiSelectKey(event){
- if (isMacOS){
- return event.key == "Meta" || event.which == 91 || event.which == 93 || event.which == 224;
- }
- return event.which == 17;
- }
- $(window).on("keydown", function(event){
- if (isMultiSelectKey(event)){
- ctrlDown = true;
- }else if (event.which == 16){
- shiftDown = true;
- }else if (overwriteDialogIsOpen()){
- handleOverwriteDialogKey(event);
- }else if (event.which == 27){
- //Escape backs out of the transient UI first, and only closes the
- //whole dialog when there is nothing left to dismiss
- if ($("#contextMenu").hasClass("open")){
- closeContextMenu();
- return;
- }
- if (inlineEditActive || $("#moreMenu").hasClass("open")){
- closeMoreMenu();
- return;
- }
- closeSelector();
- }else if (event.which == 13){
- if ($(event.target).is("#addressbar") || inlineEditActive){
- return;
- }
- closeContextMenu();
- //Enter opens the highlighted folder, or confirms the selection
- var selected = $("#fileArea").find(".fileObject.selected");
- if (selected.length == 1 && selected.attr("isDir") == "true" && type != "folder"){
- listDir(decodeURIComponent(selected.attr("filepath")));
- }else{
- confirmSelection();
- if (overwriteDialogIsOpen()){
- //The prompt took focus during this key press. Without this
- //its keypress would land on Cancel and answer it at once
- event.preventDefault();
- }
- }
- }
- });
- $(window).on("keyup", function(event){
- if (isMultiSelectKey(event)){
- ctrlDown = false;
- }else if (event.which == 16){
- shiftDown = false;
- }
- });
- //A modifier released in another window (Cmd + Tab) never sends its
- //keyup here, which would leave every later click multi-selecting
- $(window).on("blur", function(){
- ctrlDown = false;
- shiftDown = false;
- });
- //Clicking the empty area of the file list clears the selection
- $("#fileArea").on("click", function(event){
- if ($(event.target).closest(".fileObject, .fsListHead").length == 0){
- $(".fileObject.selected").removeClass("selected");
- setWindowTitleForSelection(0);
- clearDetails();
- }
- });
- //Runs here rather than with the other init calls at the top of this
- //script: the FS_SIDEBAR_* values above are var declarations, so they
- //only hold their values once execution has reached them
- initSidebarSplitter();
- $(window).on("resize", function(){
- if (window.innerWidth >= 560){
- closeSidebar();
- }
- applySidebarWidth();
- updateFileAreaDensity();
- });
- </script>
- </body>
- </html>
|