desktop.system 204 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030
  1. <html>
  2. <head>
  3. <title>ArozOS Desktop</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link rel="stylesheet" href="script/tocas/tocas.css">
  7. <link id="fwcss" rel="stylesheet" href="script/ao.css">
  8. <link rel="stylesheet" href="SystemAO/desktop/script/jsCalendar/source/jsCalendar.css">
  9. <script type="text/javascript" src="script/tocas/tocas.js"></script>
  10. <script type="text/javascript" src="script/jquery.min.js"></script>
  11. <script type="text/javascript" src="script/ao_module.js"></script>
  12. <script type="text/javascript" src="SystemAO/desktop/script/jsCalendar/source/jsCalendar.js"></script>
  13. <style>
  14. body {
  15. background-repeat: no-repeat;
  16. background-size: cover;
  17. background-position: center;
  18. background-image: url('img/desktop/bg/init.jpg');
  19. width: 100%;
  20. height: 100%;
  21. }
  22. .backgroundFrame {
  23. height: 100%;
  24. min-width: 100%;
  25. background-repeat: no-repeat;
  26. background-size: cover;
  27. border: 0px solid transparent;
  28. background-position: center;
  29. position: absolute;
  30. opacity: 0;
  31. top: 0;
  32. left: 0;
  33. -webkit-transition: opacity 2s ease-in-out;
  34. -moz-transition: opacity 2s ease-in-out;
  35. -o-transition: opacity 2s ease-in-out;
  36. transition: opacity 2s ease-in-out;
  37. }
  38. .background-wrapper {
  39. border: 0px solid transparent;
  40. overflow: hidden;
  41. width: 100%;
  42. height: 100%;
  43. position: fixed;
  44. left: 0px;
  45. top: 0px;
  46. user-select: none;
  47. -moz-user-select: none;
  48. -webkit-user-drag: none;
  49. -webkit-user-select: none;
  50. -ms-user-select: none;
  51. }
  52. .showBackground {
  53. opacity: 1;
  54. }
  55. .icon-wrapper {
  56. height: 100%;
  57. width: 100%;
  58. position: fixed;
  59. top: 0px;
  60. left: 0px;
  61. padding: 5px;
  62. }
  63. .launchIcon {
  64. position: fixed;
  65. cursor: pointer;
  66. padding: 2px;
  67. }
  68. .launchIconImage.small {
  69. width: 48px;
  70. height: 48px;
  71. }
  72. .launchIconImage.medium {
  73. width: 68px;
  74. height: 68px;
  75. }
  76. .launchIconImage.big {
  77. width: 82px;
  78. height: 82px;
  79. }
  80. .launchIconWrapper {
  81. height: 100%;
  82. width: 100%;
  83. border-radius: 3px;
  84. }
  85. .launchIconWrapper.selected {
  86. background: rgba(250, 250, 250, 0.4) !important;
  87. }
  88. .launchIconText {
  89. color: white;
  90. text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
  91. text-align: center;
  92. text-overflow: ellipsis;
  93. overflow: hidden;
  94. word-break: break-all;
  95. width: 100%;
  96. font-variant-numeric: tabular-nums lining-nums;
  97. }
  98. .launchIconWrapper:hover {
  99. background: rgba(250, 250, 250, 0.2);
  100. }
  101. .launchIconText.small {
  102. margin-top: -3px;
  103. font-size: 70%;
  104. line-height: 1.55em;
  105. /*
  106. Fixed the issue of text being trimmed off due to lineheight setting
  107. */
  108. font-family: sans-serif !important;
  109. }
  110. .launchIconText.medium {
  111. margin-top: -2px;
  112. font-size: 90%;
  113. line-height: 1.2em;
  114. }
  115. .launchIconText.big {
  116. margin-top: -6px;
  117. font-size: 110%;
  118. }
  119. .navimenu {
  120. position: fixed;
  121. z-index: 1110;
  122. width: 100%;
  123. height: 36px;
  124. left: 0px;
  125. bottom: 0px;
  126. padding-left: 8px;
  127. padding-right: 8px;
  128. }
  129. .themeColor {
  130. background-color: rgba(14,14,14,0.5);
  131. backdrop-filter: blur(4px);
  132. }
  133. .themeColorSolid{
  134. background-color: rgba(14,14,14,0.9);
  135. backdrop-filter: blur(4px);
  136. }
  137. .navimenu .item {
  138. height: 36px;
  139. display: inline-block;
  140. vertical-align: top;
  141. }
  142. .navimenu .item.padding {
  143. display: inline-block;
  144. width: 12px;
  145. }
  146. .navimenu .item.clickable:hover {
  147. background-color: rgba(250, 250, 250, 0.2);
  148. cursor: pointer;
  149. }
  150. /* Floatwindow control button related css*/
  151. .navimenu .item.floatWindowButton {
  152. padding: 8px;
  153. padding-top: 10px;
  154. vertical-align: top;
  155. width: 200px;
  156. overflow: hidden;
  157. font-size: 90%;
  158. text-overflow: ellipsis;
  159. white-space: nowrap;
  160. word-break: break-all;
  161. color: white;
  162. }
  163. .navimenu .item.floatWindowButton .floatWindowAppIcon {
  164. height: 20px;
  165. margin-top: -2px;
  166. margin-right: 8px;
  167. display: inline-block;
  168. }
  169. .navimenu .item.floatWindowButton .floatWindowTitle {
  170. display: inline;
  171. color: white;
  172. padding-top: 5px;
  173. vertical-align: top;
  174. }
  175. .navimenu .item.floatWindowButton.hideText {
  176. width: 36px;
  177. }
  178. .navimenu .item.floatWindowButton.hideText .floatWindowTitle {
  179. display: none;
  180. }
  181. .navimenu .item.floatWindowButton.hideText .floatWindowAppIcon {
  182. margin-right: 0px;
  183. }
  184. #fwdragpanel {
  185. position: fixed;
  186. width: 100%;
  187. height: 100%;
  188. top: 0px;
  189. left: 0px;
  190. z-index: 100;
  191. display: none;
  192. }
  193. #tfwdragpanel{
  194. position: fixed;
  195. width: 100%;
  196. height: 100%;
  197. top: 0px;
  198. left: 0px;
  199. z-index: 500;
  200. display: none;
  201. }
  202. #stackedWindowList {
  203. position: fixed;
  204. z-index: 1112;
  205. left: 0px;
  206. bottom: 36px;
  207. width: 300px;
  208. padding-bottom: 4px;
  209. display: none;
  210. }
  211. #stackedWindowList .item {
  212. padding: 6px;
  213. display: inline-block;
  214. color: white;
  215. width: 100%;
  216. }
  217. #stackedWindowList .item img {
  218. display: inline-block;
  219. vertical-align: bottom;
  220. width: 20px;
  221. height: 20px;
  222. margin-right: 12px;
  223. margin-top: 0px;
  224. margin-left: 4px;
  225. }
  226. #stackedWindowList .item span {
  227. overflow: hidden;
  228. word-break: break-all;
  229. text-overflow: ellipsis;
  230. white-space: nowrap;
  231. width: calc(100% - 4px);
  232. }
  233. #stackedWindowList .item.clickable:hover {
  234. background-color: rgba(250, 250, 250, 0.2);
  235. cursor: pointer;
  236. }
  237. #stackedWindowList .item .closebtn {
  238. position: absolute;
  239. right: 0px;
  240. top: 8px;
  241. }
  242. #stackedWindowList .item .closebtn>img {
  243. height: 15px;
  244. width: 15px;
  245. }
  246. #listMenu {
  247. position: fixed;
  248. bottom: 36px;
  249. left: 0px;
  250. height: 500px;
  251. width: 400px;
  252. background-color: #fcffff;
  253. box-shadow: 3px 3px 5px 0px rgba(207, 207, 207, 0.37);
  254. z-index: 1113;
  255. }
  256. #listMenu.darkTheme{
  257. background-color: #242330;
  258. color: white;
  259. -webkit-box-shadow: 7px -6px 7px -1px rgba(92,92,92,0.2);
  260. -moz-box-shadow: 7px -6px 7px -1px rgba(92,92,92,0.2);
  261. box-shadow: 7px -6px 7px -1px rgba(92,92,92,0.2);
  262. }
  263. #listMenu .searchBar{
  264. width: 100%;
  265. border-bottom: 2px solid #34b7eb;
  266. }
  267. #listMenu.darkTheme .searchBar input{
  268. background-color: #17161f !important;
  269. color: white !important;
  270. border: 1px solid #17161f;
  271. }
  272. #listMenu .listItemWrapper {
  273. overflow: hidden;
  274. }
  275. #listMenu .listItemWrapper .groups {
  276. background-color: #f5f5f5;
  277. width: 120px;
  278. height: 457px;
  279. display: inline-block;
  280. overflow-y: auto;
  281. padding-top: 8px;
  282. }
  283. #listMenu.darkTheme .listItemWrapper .groups {
  284. background-color: #17161f;
  285. color: white;
  286. }
  287. #listMenu .listItemWrapper .groups .item {
  288. padding-left: 7px;
  289. padding-bottom: 6px;
  290. padding-top: 6px;
  291. cursor: pointer;
  292. }
  293. #listMenu .listItemWrapper .groups .item.selected {
  294. color: #34b7eb;
  295. }
  296. #listMenu .listItemWrapper .groups .item:hover {
  297. background-color: #dedede;
  298. }
  299. #listMenu.darkTheme .listItemWrapper .groups .item:hover {
  300. background-color: #242330;
  301. }
  302. #listMenu .listItemWrapper .items {
  303. height: 457px;
  304. width: calc(100% - 120px - 5px);
  305. display: inline-block;
  306. overflow-y: auto;
  307. padding-top: 8px;
  308. box-shadow: -2px 0px 5px 0px rgba(194, 194, 194, 0.5);
  309. vertical-align: top;
  310. }
  311. #listMenu.darkTheme .listItemWrapper .items {
  312. box-shadow: 0px 0px 0px 0px transparent;
  313. }
  314. #listMenu .listItemWrapper .items .item {
  315. padding-left: 12px;
  316. padding-top: 8px;
  317. padding-bottom: 8px;
  318. cursor: pointer;
  319. }
  320. #listMenu .listItemWrapper .items .item:hover {
  321. background-color: #f5f5f5;
  322. }
  323. #listMenu.darkTheme .listItemWrapper .items .item:hover {
  324. background-color: #17161f !important;
  325. margin-right: 5px;
  326. }
  327. #listMenu .listItemWrapper .items .item img {
  328. width: 26px;
  329. margin-right: 12px;
  330. vertical-align: middle;
  331. }
  332. #listMenu .poweroption {
  333. position: absolute;
  334. bottom: 0px;
  335. left: 0px;
  336. padding: 6px;
  337. padding-left: 7px;
  338. width: 100%;
  339. cursor: pointer;
  340. }
  341. #listMenu .poweroption:hover {
  342. background-color: #dedede;
  343. }
  344. #listMenu.darkTheme .poweroption:hover {
  345. background-color: #242330;
  346. }
  347. #contextmenu {
  348. position: fixed;
  349. z-index: 3000;
  350. left: 20px;
  351. top: 20px;
  352. }
  353. #contextmenu .item {
  354. padding: 0.6em 1em !important;
  355. }
  356. #subcontextmenu .item {
  357. padding: 0.6em 1em !important;
  358. }
  359. #selectionPanel {
  360. background-color: rgba(39, 108, 227, 0.3);
  361. border: 1px solid #276ce3;
  362. position: fixed;
  363. height: 100px;
  364. width: 100px;
  365. display: none;
  366. }
  367. .renameInput {
  368. background-color: white;
  369. border: 1px solid black;
  370. width: 100%;
  371. position: absolute;
  372. }
  373. .renameInput.big {
  374. bottom: 0px;
  375. left: 0px;
  376. font-size: 16px;
  377. line-height: 1;
  378. }
  379. .renameInput.medium {
  380. bottom: 8px;
  381. left: 0px;
  382. height: 32px;
  383. font-size: 12px;
  384. line-height: 1;
  385. }
  386. .renameInput.small {
  387. bottom: 3px;
  388. left: 0px;
  389. height: 24px;
  390. font-size: 11px;
  391. line-height: 1;
  392. }
  393. #statusbar{
  394. position:absolute;
  395. z-index:0;
  396. width:100%;
  397. height:28px;
  398. background-color: rgba(0,0,0,0.9);
  399. color:white;
  400. backdrop-filter: blur(4px);
  401. text-align:center;
  402. display: table;
  403. }
  404. .statusbarpadding{
  405. padding:4px;
  406. }
  407. .hostname{
  408. display: table-cell;
  409. text-align:left;
  410. width:100px;
  411. pointer-events:none;
  412. padding-left:18px;
  413. white-space: nowrap;
  414. user-select: none;
  415. }
  416. .quicktools{
  417. display: table-cell;
  418. text-align:right;
  419. width:45px;
  420. }
  421. .qtwrapper{
  422. padding:4px;
  423. padding-right: 8px;
  424. cursor:pointer;
  425. }
  426. .qtwrapper:hover{
  427. background-color: rgba(240,240,240,0.2);
  428. }
  429. .notificationbar{
  430. position: absolute;
  431. top:28px;
  432. width:100%;
  433. height: calc(100% - 28px);
  434. z-index:1114;
  435. }
  436. .notificationbar .content{
  437. background-color:white;
  438. margin-top:6px;
  439. margin-left: auto;
  440. margin-right: auto;
  441. width:30%;
  442. min-width:650px;
  443. height:400px;
  444. z-index:1115;
  445. padding: 3px;
  446. border-radius: 5px;
  447. }
  448. .notificationbar .cover{
  449. backdrop-filter: blur(2px);
  450. -webkit-backdrop-filter: blur(2px);
  451. position:absolute;
  452. top:0px;
  453. left:0px;
  454. width:100%;
  455. height: calc(100%);
  456. }
  457. @supports not (backdrop-filter: blur(2px)) {
  458. .notificationbar .cover{
  459. /*
  460. //Replaced with Javascript implementation on Firefox
  461. background-color: rgba(24,24,24,0.3);
  462. */
  463. }
  464. #bgwrapper{
  465. transition: all 0.5s ease;
  466. }
  467. #iconwrapper{
  468. transition: all 0.5s ease;
  469. }
  470. #navimenu{
  471. transition: all 0.5s ease;
  472. }
  473. }
  474. .notification .title{
  475. font-weight:bold;
  476. font-size:120%;
  477. }
  478. .notification .notifycontent{
  479. margin-top:-12px;
  480. }
  481. .notificationbar .clearall{
  482. position:absolute;
  483. top:0px;
  484. right:4px;
  485. cursor:pointer;
  486. }
  487. .nonotification{
  488. opacity: 0.3;
  489. pointer-events:none;
  490. position:absolute;
  491. margin-top:9em;
  492. width:100%;
  493. user-select: none;
  494. }
  495. .notification.object .closebtn{
  496. position:absolute;
  497. top:3px;
  498. right:3px;
  499. cursor:pointer;
  500. }
  501. .notification.object{
  502. padding-left:7px;
  503. border-left: 3px solid transparent;
  504. cursor:pointer;
  505. }
  506. .notification.object:hover{
  507. /*
  508. border-left: 3px solid #83D8FF;
  509. */
  510. }
  511. .blured{
  512. filter: blur(2px);
  513. }
  514. #quickAccessPanel{
  515. background-color:white;
  516. position:absolute;
  517. top:28px;
  518. right:4px;
  519. z-index:114;
  520. width:300px;
  521. border-radius: 10px;
  522. border-top-right-radius: 0px;
  523. border-top-left-radius: 0px;
  524. border: 1px solid #ebebeb;
  525. padding-top:8px;
  526. padding-bottom:8px;
  527. }
  528. #quickAccessPanel .item{
  529. padding-left:12px;
  530. padding-right:12px;
  531. padding-top:6px;
  532. padding-bottom:2px;
  533. cursor:pointer;
  534. border-left: 3px solid transparent;
  535. }
  536. #quickAccessPanel .item:hover{
  537. background-color:#fafafa;
  538. }
  539. /*
  540. Handle dark theme for the quick access panel
  541. */
  542. #quickAccessPanel.darkTheme{
  543. background-color: #242330;
  544. color: white;
  545. border: 1px solid transparent;
  546. -webkit-box-shadow: -5px 4px 7px -1px rgba(92,92,92,0.2);
  547. -moz-box-shadow: -5px 4px 7px -1px rgba(92,92,92,0.2);
  548. box-shadow: -5px 4px 7px -1px rgba(92,92,92,0.2);
  549. }
  550. #quickAccessPanel.darkTheme .item:hover{
  551. background-color:#17161f;
  552. }
  553. #quickAccessPanel.darkTheme .header{
  554. color: white;
  555. }
  556. #quickAccessPanel.darkTheme .progress{
  557. background-color: #0c0c0f;
  558. }
  559. #quickAccessPanel.darkTheme .header{
  560. color: white;
  561. }
  562. #quickAccessPanel.darkTheme .inverted.button{
  563. background-color: #17161f;
  564. border: 1px solid black;
  565. }
  566. .item.module{
  567. cursor:pointer;
  568. }
  569. .item.module:hover{
  570. background-color:#f5f5f5 !important;
  571. }
  572. /*
  573. Z-index layering
  574. Layer -1 : Background Images
  575. Layer 0 - 99: Not focused tab
  576. Layer 100: Focused tab drag drop layer
  577. Layer 101: Focused Tab
  578. ...
  579. Layer 400 - 499: Non-focused top most FloatWindows
  580. Layer 500: Top Mot FloatWindow drag drop layer
  581. Layer 501: Top Most FloatWindow
  582. ...
  583. Layer 1110: Navigation Bar
  584. Layer 1112: Stacked Window List
  585. Layer 1113: List Menu
  586. Layer 1114: Notification Bar background bluring layer
  587. Layer 1115: Notification Bar
  588. ...
  589. Layer 3000: contextmenu
  590. */
  591. </style>
  592. <script>
  593. //Force redirection if it is on mobile
  594. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  595. window.location.href = "mobile.system";
  596. }
  597. </script>
  598. </head>
  599. <body style="background-color:black;">
  600. <!-- Background frames-->
  601. <div id="bgwrapper" class="background-wrapper" allowdrop="true" ondrop="drop(event)" ondragstart="return false;" onclick="event.preventDefault(); hideAllContextMenus();" ondblclick="event.preventDefault();event.stopImmediatePropagation();" ondragover="allowDrop(event);"
  602. align="center" draggable="false">
  603. </div>
  604. <!-- Top Status Bar -->
  605. <div id="statusbar" align="center">
  606. <div class="hostname statusbarpadding">
  607. Welcome
  608. </div>
  609. <div class="clock statusbarpadding" style="display: table-cell; cursor:pointer; user-select: none;" onclick="toggleNotification();" ontouchstart="toggleNotification();">
  610. ArOZ Online Desktop
  611. </div>
  612. <div class="quicktools" onclick="showToolPanel();" ontouchend="showToolPanel();">
  613. <div class="qtwrapper">
  614. <i class="content icon"></i>
  615. </div>
  616. </div>
  617. </div>
  618. <!-- Calendar and Notification -->
  619. <div class="notificationbar" style="display:none;">
  620. <div class="content">
  621. <div id="notificationlist" style="width: calc(100% - 302px); padding:8px; margin-top:5px; padding-top:22px; overflow-y:auto; overflow-x:hidden; height: calc(100% - 12px);">
  622. <div class="nonotification">
  623. <h4 class="ts center aligned icon header">
  624. <i class="bell icon"></i>No Notification
  625. </h4>
  626. </div>
  627. <a class="clearall" onclick="clearAllNotification();">Clear All</a>
  628. </div>
  629. <div style="position:absolute; right:3px; top:3px; padding-top:8px;">
  630. <div class="ts header" style="padding-left:22px;">
  631. <div id="dayofweek" class="sub header"></div>
  632. <span id="largedate" style="font-size:120%;"></span>
  633. </div>
  634. <div class="auto-jsCalendar blue"></div>
  635. </div>
  636. </div>
  637. <div class="cover" onclick='toggleNotification("hide");' ontouchstart='toggleNotification("hide");'>
  638. </div>
  639. </div>
  640. <!-- Desktop icons-->
  641. <div id="iconwrapper">
  642. </div>
  643. <!-- Navigation Menu-->
  644. <div id="navimenu" class="navimenu themeColor">
  645. <div class="item clickable system" onclick="toggleListMenu();" ontouchstart="toggleListMenu();" >
  646. <img style="height:36px;" src="img/desktop/system_icon/list.png"></img>
  647. </div>
  648. <div class="item padding system"></div>
  649. </div>
  650. <!-- floatWindow dragging panel-->
  651. <div id="fwdragpanel"></div>
  652. <div id="tfwdragpanel"></div>
  653. <!-- Selection panel-->
  654. <div id="selectionPanel"></div>
  655. <!-- Stacked windows listing container-->
  656. <div id="stackedWindowList" class="themeColor"></div>
  657. <!-- List menu -->
  658. <div id="listMenu" class="" style="display:none;">
  659. <div class="searchBar" onkeydown="searchModule(event);">
  660. <div class="ts icon fluid input" style="border-radius: 0px !important;">
  661. <input id="searchBar" type="text" placeholder="Search">
  662. <i class="search icon"></i>
  663. </div>
  664. </div>
  665. <dib class="listItemWrapper">
  666. <div class="groups">
  667. <div id="searchResults" class="item" style="display:none;">Search Results</div>
  668. <div class="item groupType selected" group="All">All</div>
  669. <div class="item groupType" group="Media">Media</div>
  670. <div class="item groupType" group="Office">Office</div>
  671. <div class="item groupType" group="Download">Download</div>
  672. <div class="item groupType" group="Files">Files</div>
  673. <div class="item groupType" group="Internet">Internet</div>
  674. <div class="item groupType" group="System Settings">System Settings</div>
  675. <div class="item groupType" group="System Tools">System Tools</div>
  676. <div class="item groupType" group="Utilities">Utilities</div>
  677. <div class="item groupType" group="Other">Other</div>
  678. <div class="poweroption">
  679. <img id="powerIcon" style="width:18px; vertical-align: top; margin-right:4px;" src="img/system/power.svg"></img> Exit
  680. </div>
  681. </div>
  682. <div id="listMenuItem" class="items">
  683. </div>
  684. </dib>
  685. </div>
  686. <div id="contextmenu" class="ts tiny contextmenu visible" style="display:none;">
  687. </div>
  688. <div id="subcontextmenu" class="ts tiny contextmenu visible" style="display:none;">
  689. </div>
  690. <!-- Disconnected. Reconnecting interface -->
  691. <div id="connectionLost" class="ts active dimmer" style="display:none; z-index:999;">
  692. <div class="ts text indeterminate loader">Connection Lost<br>
  693. Reconnecting...</div>
  694. </div>
  695. <div id="quickAccessPanel" class="" style="display:none;">
  696. <div class="ts small single line items">
  697. <div class="item">
  698. <div class="ts mini image">
  699. <img class="usericon" src="img/desktop/system_icon/user.svg">
  700. </div>
  701. <div class="content">
  702. <div id="username" class="header">User</div>
  703. <div class="meta">
  704. <div id="usergroups">@Users</div>
  705. </div>
  706. </div>
  707. <div class="actions">
  708. <div class="ts button" onclick="logout(); hideToolPanel();">
  709. <i class="log out icon"></i> Logout
  710. </div>
  711. </div>
  712. </div>
  713. </div>
  714. <div class="item" style="padding-bottom:12px;">
  715. <i class="volume up icon"></i> System Global Volume
  716. <div class="ts fluid small progress" style="margin-top:8px; cursor:pointer;" onclick="updateVolume(this,event);" >
  717. <div id="volumebar" class="bar" style="width: 0%; background-color:#52C9FF; cursor:pointer;"></div>
  718. </div>
  719. </div>
  720. <div class="item" id="settingButton" onclick="showSystemSettings(); hideToolPanel();" ontouchend="showSystemSettings(); hideToolPanel();">
  721. <i class="setting icon"></i> System Settings
  722. <!-- <div style="float:right;"><i class="caret right icon"></i></div> -->
  723. </div>
  724. <div class="item" onclick="fullscreen(); hideToolPanel();" ontouchend="fullscreen(); hideToolPanel();">
  725. <i class="maximize icon"></i> Toggle Fullscreen
  726. </div>
  727. <div class="ts divider"></div>
  728. <!--
  729. <div class="item" onclick="logout(); hideToolPanel();">
  730. <i class="log out icon"></i> Logout
  731. </div>
  732. -->
  733. <div class="item hardware" onclick="restart(); hideToolPanel();" ontouchend="restart(); hideToolPanel();">
  734. <i class="repeat icon"></i> Restart
  735. </div>
  736. <div class="item hardware" style="color:#b51d1d;" onclick="shutdown(); hideToolPanel();" ontouchend="shutdown(); hideToolPanel();">
  737. <i class="power icon"></i> Power Off
  738. </div>
  739. </div>
  740. <script>
  741. /*
  742. ArOZ Online Desktop Interface
  743. This script maintain the usability of the desktop environment.
  744. This is not identical to the previous Desktop environment used in ArOZ Online BETA.
  745. */
  746. //System environment variables
  747. var isDesktopMode = true;
  748. var loggingOut = false;
  749. //Desktop background related
  750. var desktopThemeList = []; //Storing the list of background installed
  751. var currentBackgroundList = []; //Current list of background files
  752. var currentUserTheme = ""; //The theme for current user.
  753. var backgroundCrossfadeInterval = 30000; //Time between the crossfade of each background image
  754. var nextSlideshowIndex = 0; //The next background image index to be shown
  755. var backgroundIntervalCounter; //The interval object for background changer
  756. var desktopThemeColor = ""; //The current desktop theme color, which renders to the status bar and suchs
  757. //Desktop icon realted
  758. var desktopIconSize = "medium"; //Size of desktop icons. Allow {small / medium / big}
  759. var desktopIconPack = "default"; //Desktop icon pack to be used. Located under desktop/file_icon/{pack-name}
  760. var desktopGrids = []; //Reference virtual grid for icons on desktop
  761. var iconSize = []; //Defined the icon size for the desktop icons
  762. var desktopFileList = []; //Temperature storage of desktop filenames
  763. var startDragRelatuve = []; //Relative location of where the icon being start dragging
  764. var iconOffsetXY = [0,20]; //Pixel to offset for the icon location
  765. //Float window related
  766. var focusedWindow;
  767. const maxWindowCount = 100;
  768. var movingWindow = false;
  769. var resizingWindow = false;
  770. var resizingEdgeID = 0; //Resizing edge. {0, 1, 2, 3, 4, 5} => None, Right, Right Bottom Corner, Bottom, Left Bottom Corner, Left
  771. var stackedFloatWindowListShwon = false;
  772. //Laucnh icon related
  773. var multiSelecting = false;
  774. var multiSelectionStartPoint = [-1, -1];
  775. var clickDownOffset = [-1, -1];
  776. var renameMode = false;
  777. var operationTargetLaunchIcon;
  778. //Document key bindings
  779. var ctrlHold = false;
  780. var shiftHold = false;
  781. //ListMenu Related Paramters
  782. var moduleInstalled = [];
  783. var listMenuShown = false;
  784. //Context Menu variables
  785. var menuStartLocation = [0, 0];
  786. //Input Method Editor objects
  787. window.ime = {
  788. handler: null,
  789. focus: null
  790. };
  791. //Others
  792. var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  793. var daysNames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  794. var hostInfo = {};
  795. var userInfo = {};
  796. var hardwareman = false;
  797. var downloadMode = false;
  798. var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  799. //Initiation functions
  800. initDesktopTheme();
  801. initDesktopHostInfo();
  802. initDesktopUserInfo();
  803. initBackgroundSwitchingAnimation();
  804. //initDesktopFiles(); //Will be called in initDesktopIconPreference() -> refresh()
  805. initModuleList();
  806. initDesktopIconPreference()
  807. initUserDefinedThemeColor();
  808. hookFloatWindowEvents();
  809. hookLaunchMenuEvents();
  810. initTheme();
  811. //Login cookie expire check
  812. setInterval(function() {
  813. $.ajax({
  814. url: 'system/auth/checkLogin',
  815. success: function(data) {
  816. if (data == true) {
  817. //Continue session
  818. } else {
  819. //Session timeout. Redirect to system index
  820. loggingOut = true;
  821. window.location.href = "index.html";
  822. }
  823. $("#connectionLost").hide();
  824. document.title = hostInfo.Hostname;
  825. },
  826. error: function(evt) {
  827. //Server closed or freezed?
  828. $("#connectionLost").show();
  829. document.title = "Reconnecting...";
  830. },
  831. timeout: 15000
  832. });
  833. }, 15000);
  834. //Keep the clock updated
  835. setInterval(function(){
  836. updateClockTime();
  837. },5000);
  838. updateClockTime();
  839. function updateClockTime(){
  840. var d = new Date();
  841. var display = monthNames[d.getMonth()] + " " + d.getDate() + " " + zeropad(d.getHours(),2) + ":" + zeropad(d.getMinutes(),2);
  842. if ($(".notification.object").length > 0){
  843. display += `<span style="color: #f54242; margin-left: 8px; float: center;"><i class="notice circle icon"></i></span>`;
  844. }
  845. $(".clock").html(display);
  846. var largedate = monthNames[d.getMonth()] + " " + d.getDate() + " " + d.getFullYear()
  847. $("#largedate").text(largedate);
  848. var dow = daysNames[d.getDay()];
  849. $("#dayofweek").text(dow);
  850. }
  851. function zeropad(n, width, z) {
  852. z = z || '0';
  853. n = n + '';
  854. return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
  855. }
  856. function showToolPanel(){
  857. $("#quickAccessPanel").slideToggle("fast");
  858. }
  859. function hideToolPanel(){
  860. $("#quickAccessPanel").slideUp("fast");
  861. }
  862. function initDesktopUserInfo(){
  863. $.get("system/desktop/user", function(data){
  864. if (data.error !== undefined){
  865. alert(data.error);
  866. }else{
  867. userInfo = data;
  868. if (data.IsAdmin == false){
  869. //Hide the power buttons
  870. $(".hardware").hide();
  871. }
  872. //Update the user tag
  873. $("#username").text(userInfo.Username);
  874. $("#usergroups").text("@" + userInfo.UserGroups.join("/"));
  875. $("#usergroups").attr("title",userInfo.UserGroups.join(" / "));
  876. if (data.UserIcon !== ""){
  877. $(".usericon").attr("src",data.UserIcon);
  878. }
  879. }
  880. });
  881. }
  882. function initDesktopHostInfo(){
  883. //Load the data into variable
  884. $.get("system/desktop/host",function(data){
  885. hostInfo = data;
  886. //Update the ui element as well
  887. $(".hostname").text(hostInfo.Hostname);
  888. document.title = hostInfo.Hostname;
  889. });
  890. //Setup volume bar
  891. var currentGlobalVol = localStorage.getItem("global_volume");
  892. if (currentGlobalVol != null && currentGlobalVol != undefined && currentGlobalVol != ""){
  893. $("#volumebar").css("width", currentGlobalVol * 100 + "%");
  894. }else{
  895. currentGlobalVol = 0;
  896. localStorage.setItem("global_volume",currentGlobalVol);
  897. }
  898. //Check if hardware management mode is enabled. Hide buttons if needed
  899. $.get("system/power/accessCheck",function(data){
  900. if (data == true){
  901. //Hardware management mode is on
  902. hardwareman = true;
  903. }else{
  904. //Hardware management mode is off
  905. $(".item.hardware").hide();
  906. hardwareman = false;
  907. }
  908. });
  909. }
  910. function toggleNotification(action=undefined){
  911. var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  912. if (typeof action == "undefined"){
  913. $(".notificationbar").stop().finish().fadeToggle("fast", function(){
  914. if ($(this).is(":visible")){
  915. if (isFirefox){
  916. $("#bgwrapper").addClass("blured");
  917. $("#iconwrapper").addClass("blured");
  918. $("#navimenu").addClass("blured");
  919. $(".floatWindow").addClass("blured");
  920. $("#listMenu").addClass("blured");
  921. }
  922. }else{
  923. if (isFirefox){
  924. $("#bgwrapper").removeClass("blured");
  925. $("#iconwrapper").removeClass("blured");
  926. $("#navimenu").removeClass("blured");
  927. $(".floatWindow").removeClass("blured");
  928. $("#listMenu").removeClass("blured");
  929. }
  930. }
  931. });
  932. }else{
  933. if (action == "hide"){
  934. $(".notificationbar").stop().finish().fadeOut("fast");
  935. if (isFirefox){
  936. $("#bgwrapper").removeClass("blured");
  937. $("#iconwrapper").removeClass("blured");
  938. $("#navimenu").removeClass("blured");
  939. $(".floatWindow").removeClass("blured");
  940. $("#listMenu").removeClass("blured");
  941. }
  942. }else if (action == "show"){
  943. $(".notificationbar").stop().finish().fadeIn("fast");
  944. if (isFirefox){
  945. $("#bgwrapper").addClass("blured");
  946. $("#iconwrapper").addClass("blured");
  947. $("#navimenu").addClass("blured");
  948. $(".floatWindow").addClass("blured");
  949. $("#listMenu").addClass("blured");
  950. }
  951. }
  952. }
  953. }
  954. // ===================== LIST MENU EVENTS FUNCTIONS ===============
  955. function toggleListMenu() {
  956. $("#listMenu").stop().finish().animate({
  957. height: "toggle"
  958. }, 300, function() {
  959. if ($("#listMenu").offset().top == 0) {
  960. listMenuShown = false;
  961. } else {
  962. listMenuShown = true;
  963. }
  964. });
  965. }
  966. function initDesktopIconPreference() {
  967. getStorage("iconsize", function(catergory) {
  968. if (["small", "medium", "big"].includes(catergory)) {
  969. desktopIconSize = catergory;
  970. }
  971. refresh();
  972. hideAllContextMenus();
  973. });
  974. }
  975. function hideListMenu() {
  976. if (listMenuShown) {
  977. $("#listMenu").animate({
  978. height: "hide"
  979. }, 300);
  980. listMenuShown = false;
  981. }
  982. }
  983. function initModuleList() {
  984. $.ajax({
  985. url: "system/modules/list",
  986. success: function(data) {
  987. moduleInstalled = data;
  988. listModulesType("All");
  989. checkFileSystemAccess();
  990. //Hide the system setting button if access is denied
  991. var allowSettingAccess = false;
  992. moduleInstalled.forEach(thismod => {
  993. if (thismod.Name == "System Setting"){
  994. allowSettingAccess = true;
  995. }
  996. });
  997. if (!allowSettingAccess){
  998. $("#settingButton").hide();
  999. }
  1000. }
  1001. });
  1002. }
  1003. function hookLaunchMenuEvents(){
  1004. $(".groupType").on("click touchstart",function(){
  1005. moduleTypeButtonClicked(this);
  1006. });
  1007. $(".poweroption").on("click touchstart",function(){
  1008. logout();
  1009. });
  1010. }
  1011. function moduleTypeButtonClicked(object) {
  1012. var groupType = $(object).attr("group");
  1013. listModulesType(groupType);
  1014. $(".groupType.selected").removeClass("selected");
  1015. $(object).addClass("selected");
  1016. $("#searchResults").slideUp('fast');
  1017. $("#searchBar").val("");
  1018. }
  1019. function listModulesType(groupType) {
  1020. var listingItems = [];
  1021. if (groupType == "All") {
  1022. //List all of the items
  1023. for (var i = 0; i < moduleInstalled.length; i++) {
  1024. if (moduleInstalled[i]["StartDir"] != "") {
  1025. listingItems.push(moduleInstalled[i]);
  1026. }
  1027. }
  1028. } else if (groupType == "Other") {
  1029. var excludeList = ["Media", "Office", "Download", "Files", "Internet", "System Settings", "System Tools", "Utilities"];
  1030. //List the Other groups
  1031. for (var i = 0; i < moduleInstalled.length; i++) {
  1032. if (excludeList.includes(moduleInstalled[i]["Group"]) == false && moduleInstalled[i]["StartDir"] != "") {
  1033. console.log(moduleInstalled[i]["Group"]);
  1034. listingItems.push(moduleInstalled[i]);
  1035. }
  1036. }
  1037. } else {
  1038. //List the given group
  1039. for (var i = 0; i < moduleInstalled.length; i++) {
  1040. if (moduleInstalled[i]["Group"] == groupType && moduleInstalled[i]["StartDir"] != "") {
  1041. listingItems.push(moduleInstalled[i]);
  1042. }
  1043. }
  1044. }
  1045. //List the item to the listmenu
  1046. $("#listMenuItem").html("");
  1047. for (var i = 0; i < listingItems.length; i++) {
  1048. var thisModule = listingItems[i];
  1049. generateListMenuItem(thisModule);
  1050. }
  1051. if (listingItems.length == 0) {
  1052. $("#listMenuItem").html(`<div class="item module"><span><img src="img/system/not found.png">No WebApp found</span></div>`)
  1053. }
  1054. }
  1055. //Given a module information and generate a selectable item in the list menu
  1056. function generateListMenuItem(thisModule) {
  1057. var icon = thisModule["IconPath"];
  1058. if (icon == "") {
  1059. //Use default system icon
  1060. icon = "img/system/service.png";
  1061. }
  1062. var name = thisModule["Name"];
  1063. var startdir = thisModule["StartDir"];
  1064. var fwsupport = "false";
  1065. if (thisModule["SupportFW"]) {
  1066. fwsupport = "true";
  1067. }
  1068. $("#listMenuItem").append(`<div class="item module" module="${name}" startdir="${startdir}" fw="${fwsupport}" onclick="openModuleFromMenu(this);" ontouchstart="openModuleFromMenu(this);">
  1069. <span>
  1070. <img src="${icon}"></img>
  1071. ${name}
  1072. </span>
  1073. </div>`);
  1074. }
  1075. function searchModule(event) {
  1076. if (event.which == 13) {
  1077. var keyword = $("#searchBar").val().toLowerCase();
  1078. var results = [];
  1079. var lessAccurateResults = [];
  1080. $(".groupType.selected").removeClass("selected");
  1081. $("#searchResults").addClass("selected").slideDown('fast');
  1082. //Load all search results
  1083. for (var i = 0; i < moduleInstalled.length; i++) {
  1084. var thisModule = moduleInstalled[i];
  1085. if (thisModule["StartDir"] == ""){
  1086. continue;
  1087. }
  1088. var pathInfo = thisModule["StartDir"].split("/");
  1089. for (var j = 0; j < pathInfo.length; j++) {
  1090. pathInfo[j] = pathInfo[j].toLowerCase();
  1091. }
  1092. if (thisModule["Name"].toLowerCase().includes(keyword)) {
  1093. results.push(thisModule);
  1094. } else if (pathInfo.includes(keyword.toLowerCase()) || pathInfo.includes(keyword.split(" ").join("_").toLowerCase())) {
  1095. lessAccurateResults.push(thisModule);
  1096. }
  1097. }
  1098. results = results.concat(lessAccurateResults);
  1099. //Append the results to list
  1100. $("#listMenuItem").html("");
  1101. for (var i = 0; i < results.length; i++) {
  1102. generateListMenuItem(results[i]);
  1103. }
  1104. if (results.length == 0) {
  1105. //Append a custom no results div to the content
  1106. $("#listMenuItem").append(` <div class="item">
  1107. <span>
  1108. <img src="img/system/not found.png"></img>
  1109. No Result
  1110. </span>
  1111. </div>`);
  1112. }
  1113. }
  1114. }
  1115. function openModuleFromMenu(object) {
  1116. var moduleName = $(object).attr("module");
  1117. openModule(moduleName);
  1118. }
  1119. function openModule(moduleName, callback=undefined) {
  1120. $.get("system/modules/getLaunchPara?module=" + moduleName, function(data) {
  1121. if (data.error !== undefined) {
  1122. //Something went wrong.
  1123. console.log("Unable to open module " + moduleName);
  1124. if (data.error == "Not logged in."){
  1125. //Session expired
  1126. window.location.href = "login.system";
  1127. }
  1128. } else {
  1129. //Launch the given module
  1130. var url = data["StartDir"];
  1131. var size = [undefined, undefined];
  1132. var icon = "img/system/favicon.png";
  1133. if (data["IconPath"] != "") {
  1134. icon = data["IconPath"];
  1135. }
  1136. var title = data["Name"];
  1137. //Check if the module support fw mode. If yes, launch with fwmode url. IF not, launch to index
  1138. if (data["SupportFW"] == true) {
  1139. if (data["LaunchFWDir"] != null) {
  1140. url = data["LaunchFWDir"];
  1141. }
  1142. if (data["InitFWSize"] != null) {
  1143. size = data["InitFWSize"];
  1144. }
  1145. }
  1146. //Launch the given module
  1147. var uuid = newFloatWindow({
  1148. url: url,
  1149. width: size[0],
  1150. height: size[1],
  1151. appicon: icon,
  1152. title: title
  1153. });
  1154. if (callback !== undefined){
  1155. callback();
  1156. }
  1157. hideListMenu();
  1158. }
  1159. });
  1160. }
  1161. // ===================== FLOAT WINDOWS EVENTS =====================
  1162. function hookFloatWindowEvents() {
  1163. //Handle floatWindow mouse drag events
  1164. $(".fwdragger").off("mousedown").on("mousedown", function(evt) {
  1165. evt.preventDefault();
  1166. evt.stopImmediatePropagation();
  1167. fwdown($(this).parent(), evt);
  1168. });
  1169. $(".fwdragger").off("mousemove").on("mousemove", function(evt) {
  1170. evt.preventDefault();
  1171. evt.stopImmediatePropagation();
  1172. fwmove($(this).parent(), evt);
  1173. });
  1174. $(".fwdragger").off("mouseup").on("mouseup", function(evt) {
  1175. evt.preventDefault();
  1176. evt.stopImmediatePropagation();
  1177. fwup($(this).parent(), evt);
  1178. });
  1179. $(".fwdragger").off("touchstart").on("touchstart", function(evt) {
  1180. evt.preventDefault();
  1181. evt.stopImmediatePropagation();
  1182. fwdown($(this).parent(), evt);
  1183. });
  1184. $(".fwdragger").off("touchmove").on("touchmove", function(evt) {
  1185. evt.preventDefault();
  1186. evt.stopImmediatePropagation();
  1187. fwmove($(this).parent(), evt);
  1188. });
  1189. $(".fwdragger").off("touchend").on("touchend", function(evt) {
  1190. evt.preventDefault();
  1191. evt.stopImmediatePropagation();
  1192. fwup($(this).parent(), evt);
  1193. });
  1194. $(".fwdragger").off("dblclick").on("dblclick", function(evt) {
  1195. //Activate full screen
  1196. evt.preventDefault();
  1197. evt.stopImmediatePropagation();
  1198. //Emulate keypress on maximize btn
  1199. toggleMax($(this).parent().find(".maxToogleButton").parent()[0], evt);
  1200. });
  1201. //Floatwindow operations for touch devices
  1202. $(".maxtoggle").off("touchstart").on("touchstart",function(evt){
  1203. evt.preventDefault();
  1204. evt.stopImmediatePropagation();
  1205. toggleMax(this, evt);
  1206. });
  1207. $(".mintoggle").off("touchstart").on("touchstart",function(evt){
  1208. evt.preventDefault();
  1209. evt.stopImmediatePropagation();
  1210. min(this, evt);
  1211. });
  1212. $(".closetoggle").off("touchstart").on("touchstart",function(evt){
  1213. evt.preventDefault();
  1214. evt.stopImmediatePropagation();
  1215. closeFloatWindow(this,evt);
  1216. });
  1217. //floatWindow events for mouse
  1218. $(".maxtoggle").off("mousedown").on("mousedown",function(evt){
  1219. evt.preventDefault();
  1220. evt.stopImmediatePropagation();
  1221. toggleMax(this, evt);
  1222. });
  1223. $(".mintoggle").off("mousedown").on("mousedown",function(evt){
  1224. evt.preventDefault();
  1225. evt.stopImmediatePropagation();
  1226. min(this, evt);
  1227. });
  1228. $(".closetoggle").off("mousedown").on("mousedown",function(evt){
  1229. evt.preventDefault();
  1230. evt.stopImmediatePropagation();
  1231. closeFloatWindow(this,evt);
  1232. });
  1233. //Float Window events for resizing
  1234. $(".iframewrapper").off("mousedown").on("mousedown", function(evt) {
  1235. evt.preventDefault();
  1236. evt.stopImmediatePropagation();
  1237. if ($(this).parent().hasClass("fixedsize")) {
  1238. return false;
  1239. }
  1240. resizeDown($(this).parent(), evt);
  1241. });
  1242. $(".iframewrapper").off("mousemove").on("mousemove", function(evt) {
  1243. evt.preventDefault();
  1244. evt.stopImmediatePropagation();
  1245. if (resizingWindow == true) {
  1246. //Resizeing Move
  1247. resizeMove($(this).parent(), evt);
  1248. } else {
  1249. //Dragdropping move
  1250. fwmove($(this).parent(), evt);
  1251. }
  1252. });
  1253. $(".iframewrapper").off("mouseup").on("mouseup", function(evt) {
  1254. evt.preventDefault();
  1255. evt.stopImmediatePropagation();
  1256. resizeUp($(this).parent(), evt);
  1257. });
  1258. $(".iframewrapper").off("mouseover").on("mouseover", function(evt) {
  1259. var object = $(this).parent();
  1260. if ($(object).hasClass("fixedsize")) {
  1261. return false;
  1262. }
  1263. var dx = event.pageX - $(object).find(".iframewrapper").offset().left;
  1264. var dy = event.pageY - $(object).offset().top;
  1265. if (dx < 10 && dy > $(object).height() - 10) {
  1266. //Left Bottom Corner
  1267. $(".iframewrapper").attr("class", "iframewrapper leftCorner");
  1268. } else if (dx > $(object).width() - 10 && dy > $(object).height() - 10) {
  1269. //Right Bottom Corner
  1270. $(".iframewrapper").attr("class", "iframewrapper rightCorner");
  1271. } else if (dx < 10) {
  1272. //Dragging left edge
  1273. $(".iframewrapper").attr("class", "iframewrapper widthHover");
  1274. } else if (dx > $(object).width() - 10) {
  1275. //Dragging right edge
  1276. $(".iframewrapper").attr("class", "iframewrapper widthHover");
  1277. } else if (dy > $(object).height() - 10) {
  1278. //Bottom Edge
  1279. $(".iframewrapper").attr("class", "iframewrapper heighHover");
  1280. } else {
  1281. //???
  1282. $(".iframewrapper").attr("class", "iframewrapper");
  1283. }
  1284. });
  1285. //Hook events on the floatWindow button
  1286. $(".floatWindowButton").off("click touchstart").on("click touchstart", function(event) {
  1287. event.preventDefault();
  1288. event.stopImmediatePropagation();
  1289. $("#stackedWindowList").css("left", $(this).offset().left);
  1290. //Generate the stackedWindowList
  1291. var windowIdList = JSON.parse(decodeURIComponent($(this).attr("windowidgroup")));
  1292. if (windowIdList.length == 1) {
  1293. //There are only one window in this group. Show it anyway
  1294. var targetFW = getFloatWindowByID(windowIdList[0]);
  1295. $(targetFW).fadeIn(100);
  1296. MoveFloatWindowToTop(targetFW);
  1297. stackedFloatWindowListShwon = false;
  1298. $("#stackedWindowList").hide();
  1299. } else {
  1300. //Get icon for each windows and build the list objects
  1301. $("#stackedWindowList").html("");
  1302. for (var i = 0; i < windowIdList.length; i++) {
  1303. var iconURL = getFloatWindowIconByID(windowIdList[i]);
  1304. var title = getFloatWindowTitleByID(windowIdList[i]);
  1305. $("#stackedWindowList").append(`<div class="item clickable" windowId="${windowIdList[i]}" onclick="bringFloatWindowToFrontByFWB(this,event);" ontouchstart="bringFloatWindowToFrontByFWB(this,event);"><span><img src="${iconURL}"></img>${title}</span><div class="closebtn" onclick="closeFWviaFWB(this,event);"><img src="img/system/close.png"></img></div></div>`);
  1306. }
  1307. $("#stackedWindowList").show();
  1308. stackedFloatWindowListShwon = true;
  1309. }
  1310. });
  1311. }
  1312. var tapedTwiceTouch = false;
  1313. var timeoutObject;
  1314. var tappingTarget = undefined;
  1315. function doubleTouchHandler(object, event, callback) {
  1316. if(!tapedTwiceTouch) {
  1317. tapedTwiceTouch = true;
  1318. tappingTarget = object;
  1319. timeoutObject = setTimeout( function() { tapedTwiceTouch = false; }, 300 );
  1320. return false;
  1321. }
  1322. if (tappingTarget == object){
  1323. //Double click on the same icon
  1324. event.preventDefault();
  1325. callback(object, event);
  1326. tappingTarget = undefined;
  1327. }else{
  1328. //Although it touch twice within 300ms, but it is on different target
  1329. //Update the tab target instead.
  1330. tappingTarget = object;
  1331. tapedTwiceTouch = true;
  1332. clearTimeout(timeoutObject);
  1333. timeoutObject = setTimeout( function() { tapedTwiceTouch = false; }, 300 );
  1334. }
  1335. }
  1336. function openViaTouch(object, event){
  1337. iconDoubleClicked(object,event);
  1338. }
  1339. //Handle focus through floatWindow taskbar button
  1340. function bringFloatWindowToFrontByFWB(object, event) {
  1341. event.preventDefault();
  1342. event.stopImmediatePropagation();
  1343. var targetWFID = $(object).attr("windowId");
  1344. var targetFW = getFloatWindowByID(targetWFID);
  1345. $(targetFW).fadeIn(100);
  1346. MoveFloatWindowToTop(targetFW);
  1347. stackedFloatWindowListShwon = false;
  1348. $("#stackedWindowList").hide();
  1349. }
  1350. function closeFWviaFWB(object, event) {
  1351. event.preventDefault();
  1352. event.stopImmediatePropagation();
  1353. var targetWFID = $(object).parent().attr("windowId");
  1354. var targetFW = getFloatWindowByID(targetWFID);
  1355. closeFloatWindow(targetFW.find(".close"), event);
  1356. $(object).parent().remove();
  1357. if ($("#stackedWindowList").find(".item").length == 0) {
  1358. //There are no more things in this tab. Close this list as well.
  1359. stackedFloatWindowListShwon = false;
  1360. $("#stackedWindowList").hide();
  1361. }
  1362. }
  1363. //Handle floatWindow resize events
  1364. let resizingWindowTarget;
  1365. let resizingMinX = 0;
  1366. let minxWidth = 120;
  1367. let minHeight = 100;
  1368. function resizeDown(object, event) {
  1369. //Mouse down, start resizing
  1370. resizingWindow = true;
  1371. resizingWindowTarget = object;
  1372. resizingMinX = $(object).offset().left + $(object).width() - minxWidth;
  1373. MoveFloatWindowToTop(object);
  1374. if ($(object).hasClass("topmost")){
  1375. //Top most windows
  1376. $("#tfwdragpanel").show();
  1377. }else{
  1378. //Normal Windows
  1379. $('.floatWindow.topmost').css("pointer-events", "none");
  1380. $('.floatWindow.topmost').css("opacity", 0.7);
  1381. $("#fwdragpanel").show();
  1382. }
  1383. $(object).find(".iframecover").show();
  1384. //Check which edge is the user dragging
  1385. var dx = event.pageX - $(object).find(".iframewrapper").offset().left;
  1386. var dy = event.pageY - $(object).offset().top;
  1387. if (dx < 10 && dy > $(object).height() - 10) {
  1388. //Left Bottom Corner
  1389. resizingEdgeID = 4;
  1390. $(object).find(".iframewrapper").css('cursor', 'sw-resize');
  1391. } else if (dx > $(object).width() - 10 && dy > $(object).height() - 10) {
  1392. //Right Bottom Corner
  1393. resizingEdgeID = 2;
  1394. $(object).find(".iframewrapper").css('cursor', 'se-resize');
  1395. } else if (dx < 10) {
  1396. //Dragging left edge
  1397. resizingEdgeID = 5;
  1398. $(object).find(".iframewrapper").css('cursor', 'w-resize');
  1399. } else if (dx > $(object).width() - 10) {
  1400. //Dragging right edge
  1401. resizingEdgeID = 1;
  1402. $(object).find(".iframewrapper").css('cursor', 'w-resize');
  1403. } else if (dy > $(object).height() - 10) {
  1404. //Bottom Edge
  1405. resizingEdgeID = 3;
  1406. $(object).find(".iframewrapper").css('cursor', 's-resize');
  1407. }
  1408. }
  1409. function resizeMove(object, event) {
  1410. var posX = event.pageX;
  1411. var posY = event.pageY;
  1412. if (resizingWindow == true && resizingEdgeID != 0) {
  1413. if (resizingEdgeID == 1) {
  1414. //Width = posX - floatWindow width + 2 (for border width)
  1415. var newWidth = posX - $(object).offset().left + 2;
  1416. $(object).css("width", Math.max(newWidth, minxWidth));
  1417. } else if (resizingEdgeID == 2) {
  1418. var newWidth = posX - $(object).offset().left + 2;
  1419. var newHeight = posY - $(object).offset().top + 2;
  1420. $(object).css({
  1421. width: Math.max(newWidth, minxWidth),
  1422. height: Math.max(newHeight, minHeight)
  1423. });
  1424. } else if (resizingEdgeID == 3) {
  1425. var newHeight = posY - $(object).offset().top + 2;
  1426. $(object).css("height", Math.max(newHeight,minHeight));
  1427. } else if (resizingEdgeID == 4) {
  1428. var newWidth = $(object).offset().left - posX + $(object).width();
  1429. var newHeight = posY - $(object).offset().top + 2;
  1430. if (newWidth < minxWidth){
  1431. posX = resizingMinX;
  1432. }
  1433. $(object).css({
  1434. width: Math.max(newWidth, minxWidth),
  1435. height: Math.max(newHeight, minHeight),
  1436. left: posX
  1437. });
  1438. } else if (resizingEdgeID == 5) {
  1439. var newWidth = $(object).offset().left - posX + $(object).width();
  1440. if (newWidth < minxWidth){
  1441. posX = resizingMinX;
  1442. }
  1443. $(object).css({
  1444. width: Math.max(newWidth, minxWidth),
  1445. left: posX
  1446. });
  1447. }
  1448. }
  1449. }
  1450. function resizeUp(object, event) {
  1451. resizingWindow = false;
  1452. resizingEdgeID = 0;
  1453. $("#fwdragpanel").hide();
  1454. $("#tfwdragpanel").hide();
  1455. $('.floatWindow.topmost').css("pointer-events", "auto");
  1456. $('.floatWindow.topmost').css("opacity", 1);
  1457. $(object).find(".iframecover").hide();
  1458. $(object).find(".iframewrapper").css('cursor', '');
  1459. //Force minmium width and height on any floatWindow objects
  1460. if ($(object).width() < 120) {
  1461. $(object).css("width", "120px");
  1462. }
  1463. if ($(object).height() < 120) {
  1464. $(object).css("height", "120px");
  1465. }
  1466. resizingWindowTarget = undefined;
  1467. $(".topmost").show();
  1468. }
  1469. //Hook body mousemove assistant events
  1470. $("body").on("mousemove", function(evt) {
  1471. if (focusedWindow !== undefined && movingWindow == true) {
  1472. fwmove(focusedWindow, evt);
  1473. } else if (focusedWindow !== undefined && resizingWindow == true) {
  1474. resizeMove(focusedWindow, evt);
  1475. } else if (multiSelecting == true) {
  1476. movingMultiSelectionArea(evt);
  1477. }
  1478. });
  1479. //Hook body clicke vents
  1480. $("body").on("click", function(evt) {
  1481. if (stackedFloatWindowListShwon == true) {
  1482. //Hide the stacked Float Window list if it is shown
  1483. $("#stackedWindowList").hide();
  1484. stackedFloatWindowListShwon = false;
  1485. }
  1486. if (renameMode == true){
  1487. //Exit rename mode if the target is not on the editing launchIcon
  1488. console.log(evt.target);
  1489. if ($(evt.target).is("body")){
  1490. //End rename mode
  1491. exitRenameMode();
  1492. }
  1493. }
  1494. });
  1495. //Convert touch events to click events
  1496. function mapEventFromTouch(event){
  1497. if (typeof event.originalEvent == "undefined"){
  1498. //Mouse click / down / up events
  1499. return event;
  1500. }
  1501. try{
  1502. //Touch events
  1503. if (typeof event.pageX == "undefined"){
  1504. event.pageX = event.originalEvent.touches[0].pageX;
  1505. }
  1506. if (typeof event.pageY == "undefined"){
  1507. event.pageY = event.originalEvent.touches[0].pageY;
  1508. }
  1509. return event;
  1510. }catch{
  1511. return event;
  1512. }
  1513. }
  1514. //Please pass in the floatWindow object instead of the dragger
  1515. function fwdown(object, event) {
  1516. event = mapEventFromTouch(event);
  1517. //Hide all contenxt menus
  1518. hideAllContextMenus();
  1519. //Move the window to the top layer
  1520. MoveFloatWindowToTop(object);
  1521. //Show the background drag panel
  1522. if ($(object).hasClass("topmost")){
  1523. $("#tfwdragpanel").show();
  1524. }else{
  1525. $('.floatWindow.topmost').css("pointer-events", "none");
  1526. $('.floatWindow.topmost').css("opacity", 0.7);
  1527. $("#fwdragpanel").show();
  1528. }
  1529. //Get the relative click offset of the down event
  1530. clickDownOffset = [event.pageX - $(object).offset().left, event.pageY - $(object).offset().top];
  1531. movingWindow = true;
  1532. $(object).find(".iframecover").show();
  1533. }
  1534. function fwmove(object, event) {
  1535. event = mapEventFromTouch(event);
  1536. if (movingWindow == true) {
  1537. //Check if the object is maximized. If yes, minimized it
  1538. if ($(object).attr("max") == "true") {
  1539. var originalSize = JSON.parse(decodeURIComponent($(object).attr("orgsize")));
  1540. $(object).attr("max", "false");
  1541. $(object).attr("orgsize", "");
  1542. //Calculate new left right offsets
  1543. var clickRatio = event.pageX / window.innerWidth;
  1544. var newLeft = event.pageX - (clickRatio * originalSize[0]);
  1545. originalSize
  1546. $(object).css({
  1547. width: originalSize[0],
  1548. height: originalSize[1],
  1549. left: newLeft,
  1550. top: event.Y - 2
  1551. });
  1552. clickDownOffset[0] = clickRatio * originalSize[0];
  1553. clickDownOffset[1] = 2;
  1554. //Restore the maximize icon
  1555. $(object).find(".maxToogleButton").attr('src', "img/system/max.png")
  1556. }
  1557. $(object).css("left", event.pageX - clickDownOffset[0]);
  1558. $(object).css("top", event.pageY - clickDownOffset[1]);
  1559. }
  1560. }
  1561. function fwup(object, event) {
  1562. event = mapEventFromTouch(event);
  1563. if (movingWindow) {
  1564. $("#fwdragpanel").hide();
  1565. $("#tfwdragpanel").hide();
  1566. $('.floatWindow.topmost').css("pointer-events", "auto");
  1567. $('.floatWindow.topmost').css("opacity", 1);
  1568. $(object).find(".iframecover").hide();
  1569. movingWindow = false;
  1570. //Check if the window location is drag to the edge of the screen. If yes, toggle half screen fullscreen
  1571. //Not need to check for if max because it must be minimized during drag move
  1572. var dockMode = false;
  1573. if (event.pageX < 10) {
  1574. //Dock to left
  1575. var originalSize = [$(object).width(), $(object).height(), $(object).offset().left, $(object).offset().top];
  1576. $(object).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1577. $(object).css({
  1578. width: "50%",
  1579. height: "calc(100% - 36px)",
  1580. left: "0px",
  1581. top: "0px"
  1582. });
  1583. $(object).attr("max", "true");
  1584. $(object).find(".maxToogleButton").attr('src', "img/system/restore.png");
  1585. } else if (event.pageX > window.innerWidth - 10) {
  1586. //Dock to right
  1587. var originalSize = [$(object).width(), $(object).height(), $(object).offset().left, $(object).offset().top];
  1588. $(object).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1589. $(object).css({
  1590. width: "50%",
  1591. height: "calc(100% - 36px)",
  1592. left: (window.innerWidth / 2) + "px",
  1593. top: "0px"
  1594. });
  1595. $(object).attr("max", "true");
  1596. $(object).find(".maxToogleButton").attr('src', "img/system/restore.png");
  1597. }
  1598. }
  1599. }
  1600. //Handle floatWindow min, max and close
  1601. function min(object, event) {
  1602. event.preventDefault();
  1603. event.stopImmediatePropagation();
  1604. if (event.type == "mousedown" && event.which != 1) {
  1605. //Ignore right mouse down
  1606. return;
  1607. }
  1608. var fw = $(object).parent().parent().parent();
  1609. $(fw).fadeOut(100);
  1610. }
  1611. function toggleMax(object, event) {
  1612. event.preventDefault();
  1613. event.stopImmediatePropagation();
  1614. event = mapEventFromTouch(event);
  1615. if (event.type == "mousedown" && event.which != 1) {
  1616. //Ignore right mouse down
  1617. return;
  1618. }
  1619. if ($(object).css('display') == 'none'){
  1620. //This windows do not allow resizing.
  1621. return;
  1622. }
  1623. var fw = $(object).parent().parent().parent();
  1624. var maxedAlready = $(fw).attr('max');
  1625. MoveFloatWindowToTop(fw);
  1626. //Add transition animation
  1627. $(fw).css({
  1628. "transition": "width 0.3s ease-out, height 0.3s ease-out, top 0.3s ease-out, left 0.3s ease-out"
  1629. });
  1630. //Remove transition animation after complete wth 50ms buffer
  1631. setTimeout(function(){
  1632. $(fw).css({
  1633. "transition": ""
  1634. });
  1635. }, 350);
  1636. if (maxedAlready == "true") {
  1637. //Resize to original
  1638. console.log($(fw));
  1639. var originalSize = JSON.parse(decodeURIComponent($(fw).attr("orgsize")));
  1640. $(fw).attr("max", "false");
  1641. $(fw).attr("orgsize", "");
  1642. $(fw).css({
  1643. width: originalSize[0],
  1644. height: originalSize[1],
  1645. left: originalSize[2],
  1646. top: originalSize[3]
  1647. });
  1648. $(fw).find(".maxToogleButton").attr('src', "img/system/max.png");
  1649. } else {
  1650. //Maxmize
  1651. var originalSize = [$(fw).width(), $(fw).height(), $(fw).offset().left, $(fw).offset().top];
  1652. $(fw).attr("orgsize", encodeURIComponent(JSON.stringify(originalSize)));
  1653. $(fw).css({
  1654. width: "100%",
  1655. height: "calc(100% - 36px)",
  1656. left: "0px",
  1657. top: "0px"
  1658. });
  1659. $(fw).attr("max", "true");
  1660. $(fw).find(".maxToogleButton").attr('src', "img/system/restore.png")
  1661. }
  1662. }
  1663. function closeFloatWindow(object, event) {
  1664. if (event.type == "mousedown" && event.which != 1) {
  1665. //Ignore right mouse down on close buttons
  1666. return;
  1667. }
  1668. event.preventDefault();
  1669. event.stopImmediatePropagation();
  1670. if ($(object).is("img")) {
  1671. object = $(object).panret();
  1672. }
  1673. var fw = $(object).parent().parent().parent();
  1674. var contentWindow = $(fw).find("iframe")[0].contentWindow;
  1675. try {
  1676. if (contentWindow.ao_module_close === undefined) {
  1677. //This module do not use ao_module wrapper. Close it directly.
  1678. closeFwProcess($(fw).attr("windowId"));
  1679. } else {
  1680. //Pass the closing events to the window itself
  1681. contentWindow.ao_module_close();
  1682. }
  1683. } catch (ex) {
  1684. //Problems of closing floatWindow. Force closing.
  1685. closeFwProcess($(fw).attr("windowId"));
  1686. }
  1687. //Find the btn object that contains the windowID
  1688. var closingWindowID = $(fw).attr("windowId");
  1689. resizeAllFloatWindowButtons();
  1690. hideAllContextMenus();
  1691. }
  1692. function findFloatWindowButtonWithID(windowID) {
  1693. var targetButtonObject;
  1694. $(".floatWindowButton").each(function() {
  1695. var originalIDlist = JSON.parse(decodeURIComponent($(this).attr('windowIDGroup')));
  1696. originalIDlist = originalIDlist.map(String);
  1697. if (originalIDlist.includes(windowID)) {
  1698. targetButtonObject = $(this);
  1699. }
  1700. });
  1701. return targetButtonObject;
  1702. }
  1703. function closeFwProcess(windowID) {
  1704. //Close the floatwindow process
  1705. $(".floatWindow").each(function() {
  1706. if ($(this).attr("windowId") == windowID) {
  1707. $(this).remove();
  1708. }
  1709. });
  1710. //Remove the button from menu as well
  1711. var targetTab = findFloatWindowButtonWithID(windowID);
  1712. var originalIDlist = JSON.parse(decodeURIComponent($(targetTab).attr('windowIDGroup')));
  1713. originalIDlist = originalIDlist.map(String);
  1714. if (originalIDlist.length > 1) {
  1715. //There are more than 1 floatWindow in this tab.
  1716. var newIDList = [];
  1717. for (var i = 0; i < originalIDlist.length; i++) {
  1718. if (originalIDlist[i] != windowID) {
  1719. newIDList.push(originalIDlist[i]);
  1720. }
  1721. }
  1722. newIDListAttr = encodeURIComponent(JSON.stringify(newIDList));
  1723. //console.log("Newlist",newIDList);
  1724. $(targetTab).attr("windowIDGroup", newIDListAttr);
  1725. } else {
  1726. //This is the only floatWindow in this tab. Remove the tab itself.
  1727. $(targetTab).remove();
  1728. }
  1729. }
  1730. function PinFloatWindowToTopMostMode(object){
  1731. if ($(".floatwindow.topmost").length >= 100){
  1732. //Cannot add more topmost fw
  1733. console.log("Max number of top most floatWindow reached")
  1734. return
  1735. }
  1736. //Move the current fw to top, its z index is now 101
  1737. MoveFloatWindowToTop(object);
  1738. var windowID = $(object).attr("windowId");
  1739. console.log("[Desktop] Pinning window ID: " + windowID)
  1740. //Move this to fixed layer position
  1741. $(object).addClass("topmost");
  1742. $(object).css("z-index", 501);
  1743. }
  1744. function UnpinFloatWindowFromTopMostMode(object){
  1745. $(object).removeClass("topmost");
  1746. if (focusedWindow == object){
  1747. focusedWindow = undefined;
  1748. $(object).css("z-index", 1);
  1749. }
  1750. MoveFloatWindowToTop(object);
  1751. }
  1752. function MoveFloatWindowToTop(object) {
  1753. var windowID = $(object).attr("windowId");
  1754. var windowZindex = $(object).css("z-index");
  1755. //Shift down all floatWindows that has z-index higher than this window by 2
  1756. if (windowID == $(focusedWindow).attr("windowId")) {
  1757. //This window already at the top
  1758. return;
  1759. }
  1760. if ($(focusedWindow).hasClass("topmost")){
  1761. //The previous focused windows is topmost. Move it to layer 109
  1762. $(focusedWindow).css("z-index", 500);
  1763. $(".floatWindow.topmost").each(function(){
  1764. var thisWindowZIndex = $(this).css("z-index");
  1765. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  1766. if ($(this).attr("windowId") != windowID) {
  1767. $(this).css("z-index", thisWindowZIndex - 1);
  1768. }
  1769. }
  1770. });
  1771. }else{
  1772. //The previous focused windows is normal windows. Move it to 100
  1773. $(focusedWindow).css("z-index", 100);
  1774. //Shift all the other windows down
  1775. $(".floatWindow").each(function() {
  1776. if ($(this).hasClass("topmost")){
  1777. return;
  1778. }
  1779. var thisWindowZIndex = $(this).css("z-index");
  1780. if (parseInt(thisWindowZIndex) > parseInt(windowZindex)) {
  1781. if ($(this).attr("windowId") != windowID) {
  1782. $(this).css("z-index", thisWindowZIndex - 1);
  1783. //console.log($(this).attr("windowId"), $(this).css("z-index"));
  1784. }
  1785. }
  1786. });
  1787. }
  1788. if ($(object).hasClass("topmost")){
  1789. //The new windows is a topmost window
  1790. $(object).css("z-index", 501);
  1791. }else{
  1792. $(object).css("z-index", 101);
  1793. }
  1794. focusedWindow = $(object);
  1795. //Check if this div is hidden. If not, fade it in.
  1796. if ($(object).is(":hidden")) {
  1797. $(object).fadeIn(100);
  1798. }
  1799. }
  1800. function newFloatWindow(config, callback=undefined) {
  1801. //Check if the number of floatWindow already reaching its maxmium
  1802. if ($(".floatWindow").length > maxWindowCount){
  1803. console.log("Max number of floatWindow reached.")
  1804. return;
  1805. }
  1806. //Generate new floatwindow startup config from object
  1807. var url = defaultOrKey(config, "about:blank", "url");
  1808. var uuid = defaultOrKey(config, (new Date()).getTime(), "uid");
  1809. var width = defaultOrKey(config, 854, "width");
  1810. var height = defaultOrKey(config, 480, "height");
  1811. var moduleIcon = defaultOrKey(config, "img/system/favicon.png", "appicon");
  1812. var title = defaultOrKey(config, "New floatWindow", "title");
  1813. var left = defaultOrKey(config, 100, "left");
  1814. var top = defaultOrKey(config, 100, "top");
  1815. var parentWindowID = defaultOrKey(config, "", "parent");
  1816. var callbackFunctionName = defaultOrKey(config, "", "callback");
  1817. var bgcolor = defaultOrKey(config, "", "background-color");
  1818. //Encode function name
  1819. callbackFunctionName = encodeURIComponent(callbackFunctionName);
  1820. //Validate paramters
  1821. if (width > window.innerWidth) {
  1822. width = window.innerWidth;
  1823. }
  1824. if (height > window.innerHeight) {
  1825. height = window.innerHeight;
  1826. }
  1827. if (left + width > window.innerWidth) {
  1828. left = 0;
  1829. }
  1830. if (top + height > window.innerHeight) {
  1831. top = 0;
  1832. }
  1833. //Check if the location already cotain any window
  1834. while (floatWindowLocationDuplicated(left, top)) {
  1835. left += 30;
  1836. top += 30;
  1837. }
  1838. //Check if the opening require a overwrite on background color
  1839. var backgroundStyle = "";
  1840. if (bgcolor !== ""){
  1841. backgroundStyle = `background-color: ${bgcolor};`;
  1842. }
  1843. //Check if the theme color is applied. If yes, generate the floatWindow with overwritten theem color
  1844. var overWriteThemeColor = "";
  1845. if (desktopThemeColor != ""){
  1846. overWriteThemeColor = `background-color: ${hexToRgbA(desktopThemeColor, 0.85)}`;
  1847. }
  1848. //Append the floatWindow into the body
  1849. $("body").append(`<div class="floatWindow" windowId="${uuid}" parent="${parentWindowID}" callback="${callbackFunctionName}" style="z-index:0; width:${width}px; height:${height}px; left:${left}px; top:${top}px;${backgroundStyle}">
  1850. <div class="controls fwdragger themeColorSolid" style="${overWriteThemeColor}">
  1851. <img class="moduleicon" src="${moduleIcon}"></img>
  1852. <div class="title">${title}</div>
  1853. <div class="fwcontrol">
  1854. <div class="buttons mintoggle">
  1855. <img src="img/system/min.png"></img>
  1856. </div>
  1857. <div class="buttons maxtoggle">
  1858. <img class="maxToogleButton" src="img/system/max.png"></img>
  1859. </div>
  1860. <div class="buttons closetoggle close">
  1861. <img src="img/system/close.png"></img>
  1862. </div>
  1863. </div>
  1864. </div>
  1865. <div class="iframewrapper">
  1866. <iframe src="${url}" allowfullscreen="true"></iframe>
  1867. <div class="iframecover"></div>
  1868. </div>
  1869. </div>`);
  1870. var newWindowObject = getFloatWindowByID(uuid);
  1871. //console.log(newWindowObject);
  1872. MoveFloatWindowToTop(newWindowObject);
  1873. //Append window to taskbar
  1874. var groupInfo = url.split("/");
  1875. var group = "";
  1876. if (groupInfo.length == 1) {
  1877. group = groupInfo[0];
  1878. } else {
  1879. groupInfo.pop();
  1880. group = groupInfo.join("/");
  1881. }
  1882. //File system windows require special grouping based on their filename
  1883. if (url.includes("SystemAO/file_system/")){
  1884. group = url.split("/").pop().split(".").join("_");
  1885. }else if (url.includes("SystemAO/utilities/")){
  1886. group = url.split("/").pop().split(".").join("_");
  1887. if (group.includes("#")){
  1888. group = group.split("#")[0];
  1889. }
  1890. }
  1891. //Check if the group already exists.
  1892. var groupExists = false;
  1893. var targetGroupingTab;
  1894. $(".floatWindowButton").each(function() {
  1895. if ($(this).attr("group") == group) {
  1896. groupExists = true;
  1897. targetGroupingTab = $(this);
  1898. }
  1899. });
  1900. //Check if the group is System Explorer and held special treatment if yes
  1901. if (group.split("/").shift() == "SystemAO") {
  1902. if (url.includes("file_explorer.html") && groupExists) {
  1903. //File Manager. Group them
  1904. group = "file_explorer";
  1905. }else if (url.includes("utilities") && groupExists){
  1906. //Allow grouping
  1907. } else {
  1908. //Do not group anything from SystemAO other than file explorer
  1909. groupExists = false;
  1910. }
  1911. }
  1912. if (groupExists == false) {
  1913. //Append the item to taskbar
  1914. var windowIDGroup = encodeURIComponent(JSON.stringify([uuid]));
  1915. var floatWindowButtonObject = ` <div class="item clickable floatWindowButton onscreen" group="${group}" windowIDGroup="${windowIDGroup}">
  1916. <img class="floatWindowAppIcon" src="${moduleIcon}"></img>
  1917. <p class="floatWindowTitle">${title}</p>
  1918. </div>`;
  1919. $(".navimenu").append(floatWindowButtonObject);
  1920. } else {
  1921. //Group already exists. Add tab into that group.
  1922. var originalIDlist = JSON.parse(decodeURIComponent($(targetGroupingTab).attr('windowIDGroup')));
  1923. originalIDlist.push(uuid);
  1924. //Encode and put the group list back to the object
  1925. var newIDList = encodeURIComponent(JSON.stringify(originalIDlist));
  1926. $(targetGroupingTab).attr("windowIDGroup", newIDList);
  1927. }
  1928. hookFloatWindowEvents();
  1929. resizeAllFloatWindowButtons();
  1930. if (callback !== undefined){
  1931. callback(uuid);
  1932. }
  1933. }
  1934. function resizeAllFloatWindowButtons() {
  1935. var fwbTotalWidth = $(".floatWindowButton").length * 200;
  1936. if (fwbTotalWidth > window.innerWidth * 0.7) {
  1937. $(".floatWindowButton").addClass("hideText");
  1938. } else {
  1939. $(".floatWindowButton").removeClass("hideText");
  1940. }
  1941. }
  1942. function floatWindowLocationDuplicated(left, top) {
  1943. var duplicated = false;
  1944. $(".floatWindow").each(function() {
  1945. if ($(this).offset().left == left && $(this).offset().top == top) {
  1946. duplicated = true;
  1947. }
  1948. });
  1949. return duplicated;
  1950. }
  1951. function defaultOrKey(object, defaultvalue, key) {
  1952. if (object[key] !== undefined) {
  1953. return object[key];
  1954. }
  1955. return defaultvalue;
  1956. }
  1957. function getFloatWindowByID(id) {
  1958. var targetWindow = undefined;
  1959. $(".floatWindow").each(function() {
  1960. if ($(this).attr("windowId") == id) {
  1961. targetWindow = $(this);
  1962. }
  1963. });
  1964. return targetWindow;
  1965. }
  1966. function getFloatWindowIconByID(id) {
  1967. var targetIconURL = "img/system/favicon.png";
  1968. $(".floatWindow").each(function() {
  1969. if ($(this).attr("windowId") == id) {
  1970. //This window ID matched the target fw
  1971. targetIconURL = $(this).find(".moduleicon").attr('src');
  1972. }
  1973. });
  1974. return targetIconURL;
  1975. }
  1976. function getFloatWindowTitleByID(id) {
  1977. var title = "";
  1978. $(".floatWindow").each(function() {
  1979. if ($(this).attr("windowId") == id) {
  1980. //This window ID matched the target fw
  1981. title = $(this).find(".title").text();
  1982. }
  1983. });
  1984. return title;
  1985. }
  1986. function setFloatWindowResizePolicy(targetFWId, resizble = true) {
  1987. var targetfw = getFloatWindowByID(targetFWId);
  1988. if (resizble) {
  1989. $(targetfw).find(".maxtoggle").show();
  1990. $(targetfw).removeClass("fixedsize");
  1991. } else {
  1992. $(targetfw).find(".maxtoggle").hide();
  1993. $(targetfw).addClass("fixedsize");
  1994. }
  1995. }
  1996. function setFloatWindowSize(targetFWId, newWidth, newHeight) {
  1997. var targetfw = getFloatWindowByID(targetFWId);
  1998. $(targetfw).css({
  1999. height: newHeight,
  2000. width: newWidth
  2001. });
  2002. }
  2003. function setFloatWindowTitle(targetFWId, newTitle) {
  2004. var targetfw = getFloatWindowByID(targetFWId);
  2005. $(targetfw).find(".title").text(newTitle);
  2006. }
  2007. function openFileWithModule(moduleLaunchInfo, openFileList) {
  2008. var url = moduleLaunchInfo["StartDir"];
  2009. var size = [undefined, undefined];
  2010. var title = moduleLaunchInfo["Name"];
  2011. var icon = "img/system/favicon.png";
  2012. if (moduleLaunchInfo["IconPath"] != "") {
  2013. icon = moduleLaunchInfo["IconPath"];
  2014. }
  2015. //Use floatWindow if exists
  2016. if (moduleLaunchInfo["SupportFW"] == true && moduleLaunchInfo["LaunchFWDir"] != "") {
  2017. url = moduleLaunchInfo["LaunchFWDir"];
  2018. if (moduleLaunchInfo["InitFWSize"] !== null) {
  2019. size = moduleLaunchInfo["InitFWSize"]
  2020. }
  2021. }
  2022. //Use embedded mode if exists
  2023. if (moduleLaunchInfo["SupportEmb"] == true && moduleLaunchInfo["LaunchEmb"] != "") {
  2024. url = moduleLaunchInfo["LaunchEmb"];
  2025. if (moduleLaunchInfo["InitEmbSize"] !== null) {
  2026. size = moduleLaunchInfo["InitEmbSize"]
  2027. }
  2028. }
  2029. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  2030. //Add launch files info and launch floatWindow
  2031. parent.newFloatWindow({
  2032. url: url + "#" + openParamter,
  2033. width: size[0],
  2034. height: size[1],
  2035. appicon: icon,
  2036. title: title
  2037. });
  2038. }
  2039. //====================== DESKTOP THEME RELATED FUNCTIONS =====================
  2040. //Initiate desktop theme list and user current theme
  2041. function initDesktopTheme() {
  2042. //Update 1 April 2021: Check if the user customize the desktop with the given path
  2043. $.get("system/desktop/theme", function(data) {
  2044. //Return a list of theme stored on the system
  2045. desktopThemeList = data;
  2046. $.get("system/desktop/theme?get=true", function(data) {
  2047. //Get the user theme settings
  2048. changeDesktopTheme(data);
  2049. });
  2050. });
  2051. }
  2052. function setDesktopTheme(themeName) {
  2053. $.get("system/desktop/theme?set=" + themeName, function(data) {
  2054. //Get the user theme settings
  2055. changeDesktopTheme(themeName);
  2056. if (data.includes("Error")) {
  2057. console.log(data);
  2058. }
  2059. });
  2060. }
  2061. //Actiave background cross fade changing animation
  2062. function initBackgroundSwitchingAnimation() {
  2063. if (localStorage.getItem("ao/desktop/backgroundInterval") !== null && !isNaN(parseInt(localStorage.getItem("ao/desktop/backgroundInterval")))){
  2064. //Localstorage has interval setting that is not NaN
  2065. backgroundCrossfadeInterval = parseInt(localStorage.getItem("ao/desktop/backgroundInterval")) * 1000;
  2066. }
  2067. backgroundIntervalCounter = setInterval(function() {
  2068. $("body").css("background-image", "none").css({
  2069. 'background-color': '#000000'
  2070. });
  2071. $(".showBackground").removeClass("showBackground");
  2072. $($(".backgroundFrame")[nextSlideshowIndex]).addClass("showBackground");
  2073. nextSlideshowIndex++;
  2074. if (nextSlideshowIndex > currentBackgroundList.length - 1) {
  2075. nextSlideshowIndex = 0;
  2076. }
  2077. }, backgroundCrossfadeInterval);
  2078. }
  2079. //Function for changing the desktop theme
  2080. function changeDesktopTheme(targetThemeName) {
  2081. currentUserTheme = targetThemeName;
  2082. if (currentUserTheme.includes(":/") == false){
  2083. //This is default theme pack name
  2084. for (var i = 0; i < desktopThemeList.length; i++) {
  2085. var thisTheme = desktopThemeList[i];
  2086. if (thisTheme["Theme"] == targetThemeName) {
  2087. //Use this config as the target theme
  2088. currentBackgroundList = thisTheme["Bglist"];
  2089. break;
  2090. }
  2091. }
  2092. //Initiate the background image.
  2093. $("#bgwrapper").html("");
  2094. for (var i = 0; i < currentBackgroundList.length; i++) {
  2095. var id = "dbg" + i;
  2096. var thisImage = "img/desktop/bg/" + currentUserTheme + "/" + currentBackgroundList[i];
  2097. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2098. }
  2099. setTimeout(function() {
  2100. $("#dbg0").addClass("showBackground");
  2101. }, 300);
  2102. if (currentBackgroundList.length == 1) {
  2103. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2104. nextSlideshowIndex = 0;
  2105. }else if (currentBackgroundList.length == 0){
  2106. //Background no longer exists. Change to default
  2107. changeDesktopTheme("default");
  2108. } else {
  2109. nextSlideshowIndex = 1;
  2110. }
  2111. }else{
  2112. //This is user defined photo file
  2113. $.get("system/desktop/theme?load=" + targetThemeName, function(data){
  2114. if (data.error !== undefined){
  2115. //The folder is gone. Use default instead
  2116. console.log(data.error);
  2117. changeDesktopTheme("default");
  2118. }else{
  2119. //OK! Load it
  2120. currentBackgroundList = data;
  2121. $("#bgwrapper").html("");
  2122. for (var i = 0; i < currentBackgroundList.length; i++) {
  2123. var id = "dbg" + i;
  2124. var thisImage = "media/?file=" + currentBackgroundList[i];
  2125. $("#bgwrapper").append('<img id="' + id + '" rel="preload" draggable="false" style="background-image:url(\'' + thisImage + '\');" class="backgroundFrame"></img>');
  2126. }
  2127. setTimeout(function() {
  2128. $("#dbg0").addClass("showBackground");
  2129. }, 300);
  2130. if (currentBackgroundList.length == 1) {
  2131. //There are only 1 background in this pack. Make the next slice be 0 as well.
  2132. nextSlideshowIndex = 0;
  2133. }else if (currentBackgroundList.length == 0){
  2134. //Background no longer exists. Change to default
  2135. changeDesktopTheme("default");
  2136. } else {
  2137. nextSlideshowIndex = 1;
  2138. }
  2139. }
  2140. });
  2141. }
  2142. }
  2143. $("#bgwrapper").on("click", function(evt) {
  2144. evt.preventDefault();
  2145. });
  2146. //================== DESKTOP FILE LOCATION FUNCTIONS ====================
  2147. function initDesktopFiles(optionObject = {}, callback = undefined) {
  2148. $.get("system/desktop/listDesktop", function(data) {
  2149. //Prase optionObject
  2150. var noflash = false;
  2151. if (typeof optionObject.noflash !== "undefined"){
  2152. noflash = optionObject.noflash;
  2153. }
  2154. if (noflash){
  2155. //Only clean out those object that not exists in the new filelist
  2156. var existsingFilepaths = [];
  2157. if (data != null){
  2158. for (var i =0; i < data.length; i++){
  2159. existsingFilepaths.push(data[i].Filepath);
  2160. }
  2161. }else{
  2162. //Nothing on desktop
  2163. }
  2164. //console.log(existsingFilepaths);
  2165. //If the launchIcon path is not in the latest list, remove it from desktop
  2166. $(".launchIcon").each(function(){
  2167. if (existsingFilepaths.includes($(this).attr("filepath")) == false){
  2168. $(this).remove();
  2169. }
  2170. });
  2171. }else{
  2172. //Cleanup all previous icons
  2173. $("#iconwrapper").html("");
  2174. }
  2175. //Allocate new items location
  2176. var iheight = 106;
  2177. var iwidth = 70;
  2178. var padding = 16;
  2179. if (desktopIconSize == "small") {
  2180. iheight = 82;
  2181. iwidth = 50;
  2182. } else if (desktopIconSize == "medium") {
  2183. iheight = 106;
  2184. iwidth = 70;
  2185. } else if (desktopIconSize == "big") {
  2186. iheight = 124;
  2187. iwidth = 84;
  2188. }
  2189. iconSize = [iwidth, iheight];
  2190. var screenHeight = window.innerHeight;
  2191. var screenWidth = window.innerWidth;
  2192. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2193. var hc = Math.floor((screenWidth - padding) / iwidth);
  2194. var slots = []; //A 2D array for storing relative to absolute locations
  2195. for (var j = 0; j < hc; j++) {
  2196. var thisLocationList = [];
  2197. for (var i = 0; i < vc; i++) {
  2198. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2199. thisLocationList.push(thisLocation);
  2200. }
  2201. slots.push(thisLocationList);
  2202. }
  2203. //Store the root position (0,0) in rootPosition
  2204. let rootPosition = JSON.parse(JSON.stringify(slots[0][0]));
  2205. desktopGrids = JSON.parse(JSON.stringify(slots));
  2206. //Assign items to desktop
  2207. var unallocatedFiles = [];
  2208. let remainingSlots = JSON.parse(JSON.stringify(slots));
  2209. desktopFileList = [];
  2210. if (data === null){
  2211. //No files on desktop
  2212. return;
  2213. }
  2214. for (var i = 0; i < data.length; i++) {
  2215. var thisFile = data[i];
  2216. desktopFileList.push(JSON.parse(JSON.stringify(thisFile.Filename)));
  2217. //Get icon from the icon list
  2218. var location = [thisFile.IconX, thisFile.IconY];
  2219. if (location[0] == -1 && location[1] == -1) {
  2220. //This file is not located. Push it into unallocatedFileList
  2221. unallocatedFiles.push(thisFile);
  2222. } else if (location[0] >= slots.length || location[1] >= slots[0].length) {
  2223. //This file is outside of the screen area. Set to be be unallocatedFiles as well
  2224. unallocatedFiles.push(thisFile);
  2225. } else {
  2226. //This file is already located. Push it location into occupiedSlots
  2227. //var screenX = location[0] * iwidth + padding/2;
  2228. //var screenY = location[1] * iheight + padding/2;
  2229. var screenLocation = slots[location[0]][location[1]];
  2230. //Remove this object from remaining slots
  2231. remainingSlots[location[0]][location[1]] = undefined;
  2232. //console.log(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth);
  2233. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2234. }
  2235. }
  2236. //Foreach remaining files, assign a location for it.
  2237. var walk = [slots.length, slots[0].length];
  2238. var current = [0, 0];
  2239. for (var i = 0; i < unallocatedFiles.length; i++) {
  2240. var thisFile = unallocatedFiles[i];
  2241. try{
  2242. while (typeof(remainingSlots[current[0]][current[1]]) == "undefined") {
  2243. //This slot is not usabled. Next slot.
  2244. current[1] += 1;
  2245. if (current[1] >= walk[1]) {
  2246. current[1] = 0;
  2247. current[0] += 1;
  2248. }
  2249. if (typeof(remainingSlots[current[0]]) == "undefined"){
  2250. //Not enough space to fit the item. Move it to 0 0 instead
  2251. current = [-1,-1];
  2252. console.log(current);
  2253. break;
  2254. }
  2255. }
  2256. }catch{
  2257. //Something went wrong while assigning positions. Set at root location
  2258. current = [-1,-1];
  2259. }
  2260. //Append the icon to screen
  2261. if (current[0] == -1 && current[1] == -1){
  2262. //Screen overflow. Stack the file at (0,0)
  2263. screenLocation = [rootPosition[0], rootPosition[1]];
  2264. console.log(screenLocation);
  2265. }else{
  2266. screenLocation = remainingSlots[current[0]][current[1]];
  2267. remainingSlots[current[0]][current[1]] = undefined;
  2268. }
  2269. appendIconAtLocation(thisFile, screenLocation[0], screenLocation[1], iheight, iwidth, noflash);
  2270. //Save the icon location to server
  2271. $.ajax({
  2272. url: "system/desktop/files",
  2273. method: "POST",
  2274. data: {"set": thisFile.Filename, "x": current[0], "y": current[1]},
  2275. success: function(data) {
  2276. if (data.includes("Error")) {
  2277. console.log(data);
  2278. }
  2279. }
  2280. });
  2281. }
  2282. if (callback !== undefined) {
  2283. //console.log(callback);
  2284. callback();
  2285. }
  2286. });
  2287. }
  2288. //Handle desktop file multi selection and dragging
  2289. $("#bgwrapper").on("mousedown", function(evt) {
  2290. initMultiSelection(evt);
  2291. });
  2292. $("#bgwrapper").on("touchstart", function(evt) {
  2293. initMultiSelection(evt);
  2294. });
  2295. $("body").on("mouseup", function(evt) {
  2296. mainWindowMouseup(evt);
  2297. });
  2298. $("body").on("touchend", function(evt) {
  2299. mainWindowMouseup(evt);
  2300. });
  2301. $("#selectionPanel").on("mouseup", function(event) {
  2302. });
  2303. function mainWindowMouseup(event) {
  2304. if (event.pageX == multiSelectionStartPoint[0] && event.pageY == multiSelectionStartPoint[1]) {
  2305. //Pressdown and up at the same location
  2306. $(".launchIconWrapper.selected").removeClass("selected");
  2307. endMultiSelection(event);
  2308. } else {
  2309. //Press down and up at different location
  2310. endMultiSelection(event);
  2311. }
  2312. if (resizingWindow){
  2313. //Resizing floatWindow out of the window bound (aka someone don't know how to resize a window correctly)
  2314. resizingWindow = false;
  2315. resizingEdgeID = 0;
  2316. $("#fwdragpanel").hide();
  2317. $("#tfwdragpanel").hide();
  2318. $('.floatWindow.topmost').css("pointer-events", "auto");
  2319. $('.floatWindow.topmost').css("opacity", 1);
  2320. $(resizingWindowTarget).find(".iframecover").hide();
  2321. $(resizingWindowTarget).find(".iframewrapper").css('cursor', '');
  2322. }
  2323. }
  2324. function initMultiSelection(event) {
  2325. event.preventDefault();
  2326. multiSelecting = true;
  2327. hideAllContextMenus();
  2328. $("#selectionPanel").css({
  2329. left: event.pageX,
  2330. top: event.pageY,
  2331. width: 0,
  2332. height: 0
  2333. });
  2334. $("#selectionPanel").show();
  2335. multiSelectionStartPoint = [event.pageX, event.pageY];
  2336. }
  2337. function movingMultiSelectionArea(event) {
  2338. event.preventDefault();
  2339. var sx = multiSelectionStartPoint[0];
  2340. var sy = multiSelectionStartPoint[1];
  2341. var ex = event.pageX;
  2342. var ey = event.pageY;
  2343. var newleft = sx;
  2344. if (ex < sx) {
  2345. newleft = ex;
  2346. }
  2347. var newtop = sy;
  2348. if (ey < sy) {
  2349. newtop = ey;
  2350. }
  2351. var newWidth = Math.abs(sx - ex);
  2352. var newHeight = Math.abs(sy - ey);
  2353. $("#selectionPanel").css({
  2354. left: newleft,
  2355. top: newtop,
  2356. width: newWidth,
  2357. height: newHeight
  2358. });
  2359. //Select all the launch icon selected
  2360. selectAllLaunchIconInRange(newleft, newleft + newWidth, newtop, newtop + newHeight);
  2361. }
  2362. function endMultiSelection(event) {
  2363. event.preventDefault();
  2364. multiSelecting = false;
  2365. multiSelectionStartPoint = [-1, -1];
  2366. $("#selectionPanel").hide();
  2367. }
  2368. function selectAllLaunchIconInRange(minX, maxX, minY, maxY) {
  2369. //Select launch icons from its center point
  2370. var xOffset = iconSize[0] / 2;
  2371. var yOffset = iconSize[1] / 2;
  2372. $(".launchIconWrapper.selected").removeClass("selected");
  2373. $(".launchIcon").each(function() {
  2374. //Calculate center point for this icon
  2375. var thisX = $(this).offset().left + xOffset;
  2376. var thisY = $(this).offset().top + yOffset;
  2377. if (thisX > minX && thisX < maxX) {
  2378. if (thisY > minY && thisY < maxY) {
  2379. $(this).find(".launchIconWrapper").addClass("selected");
  2380. }
  2381. }
  2382. });
  2383. }
  2384. function redrawDesktopGrids() {
  2385. var iheight = 106;
  2386. var iwidth = 70;
  2387. var padding = 16;
  2388. if (desktopIconSize == "small") {
  2389. iheight = 82;
  2390. iwidth = 50;
  2391. } else if (desktopIconSize == "medium") {
  2392. iheight = 106;
  2393. iwidth = 70;
  2394. } else if (desktopIconSize == "big") {
  2395. iheight = 124;
  2396. iwidth = 84;
  2397. }
  2398. iconSize = [iwidth, iheight];
  2399. var screenHeight = window.innerHeight;
  2400. var screenWidth = window.innerWidth;
  2401. var vc = Math.floor((screenHeight - 20 - padding) / iheight);
  2402. var hc = Math.floor((screenWidth - padding) / iwidth);
  2403. var slots = []; //A 2D array for storing relative to absolute locations
  2404. for (var j = 0; j < hc; j++) {
  2405. var thisLocationList = [];
  2406. for (var i = 0; i < vc; i++) {
  2407. var thisLocation = [j * iwidth + padding, i * iheight + padding];
  2408. thisLocationList.push(thisLocation);
  2409. }
  2410. slots.push(thisLocationList);
  2411. }
  2412. desktopGrids = JSON.parse(JSON.stringify(slots));
  2413. }
  2414. function appendIconAtLocation(filedata, screenX, screenY, iheight, iwidth, updateMode=false) {
  2415. //Get the icon from extension
  2416. var icon = ao_module_utils.getIconFromExt(filedata.Ext.substring(1, filedata.Ext.length));
  2417. var imagePath = "img/desktop/files_icon/" + desktopIconPack + "/" + icon + ".png";
  2418. //Handle special icon types here
  2419. var size = desktopIconSize;
  2420. var filename = JSON.parse(JSON.stringify(filedata.Filename));
  2421. var filepath = JSON.parse(JSON.stringify(filedata.Filepath));
  2422. var isDir = JSON.parse(JSON.stringify(filedata.IsDir));
  2423. var isEmptyDir = JSON.parse(JSON.stringify(filedata.IsEmptyDir));
  2424. var maxlength = 12;
  2425. var type = "file";
  2426. let shortenedName = filename;
  2427. screenX += iconOffsetXY[0];
  2428. screenY += iconOffsetXY[1];
  2429. if (isDir) {
  2430. //Folder objects
  2431. icon = "folder outline";
  2432. if (isEmptyDir){
  2433. imagePath = "img/desktop/system_icon/folder.png";
  2434. }else{
  2435. imagePath = "img/desktop/system_icon/folder-with-content.png";
  2436. }
  2437. type = "folder";
  2438. } else if (isDir == false && icon == "folder outline") {
  2439. icon = "file outline";
  2440. imagePath = "img/desktop/files_icon/" + desktopIconPack + "/file outline.png";
  2441. type = "file";
  2442. } else if (filedata.Ext == ".exe" || filedata.Ext == ".elf") {
  2443. //Executable objects
  2444. imagePath = "img/desktop/system_icon/script.png";
  2445. type = "executable";
  2446. } else if (filedata.Ext == ".shortcut") {
  2447. //Shortcut
  2448. var shortcutImage = filedata.ShortcutImage;
  2449. shortenedName = JSON.parse(JSON.stringify(filedata.ShortcutName));
  2450. imagePath = shortcutImage;
  2451. type = "shortcut";
  2452. }
  2453. //Check if filename is english only.
  2454. if (/^[a-zA-Z\d .-=+]+$/.test(filename)) {
  2455. maxlength = 20;
  2456. }else{
  2457. //Check if it is under small text mode
  2458. if (size == "small"){
  2459. maxlength = 10;
  2460. }
  2461. }
  2462. if (type != "shortcut" && filename.length > maxlength) {
  2463. shortenedName = filename.substring(0, maxlength) + "...";
  2464. }
  2465. var compressedFiledata = ao_module_utils.objectToAttr(filedata);
  2466. if (updateMode){
  2467. //Update the content that already exists for the same filepath object
  2468. var updateObject = undefined;
  2469. $(".launchIcon").each(function(){
  2470. if ($(this).attr("filedata") == compressedFiledata){
  2471. updateObject = $(this);
  2472. }
  2473. });
  2474. if (updateObject !== undefined){
  2475. //Check if content identical. If yes, skip rewrite
  2476. if (updateObject.attr("filedata") == compressedFiledata){
  2477. //Identical. Skipping
  2478. }else{
  2479. //Update its contents
  2480. updateObject.attr("type", type);
  2481. updateObject.attr("filename", filename);
  2482. updateObject.attr("filepath", filepath);
  2483. updateObject.attr("filedata", compressedFiledata);
  2484. updateObject.css("width", iwidth + "px");
  2485. updateObject.css("height", iheight + "px");
  2486. updateObject.css("left", screenX + "px");
  2487. updateObject.css("top", screenY + "px");
  2488. }
  2489. }else{
  2490. //No exists. Append to wrapper
  2491. appendDesktopIcon($("#iconwrapper"),{
  2492. type: type,
  2493. filename: filename,
  2494. filepath: filepath,
  2495. compressedFiledata: compressedFiledata,
  2496. iwidth: iwidth,
  2497. iheight: iheight,
  2498. screenX: screenX,
  2499. screenY: screenY,
  2500. size: size,
  2501. imagePath: imagePath,
  2502. shortenedName: shortenedName,
  2503. });
  2504. }
  2505. }else{
  2506. //Append into the desktop
  2507. appendDesktopIcon($("#iconwrapper"),{
  2508. type: type,
  2509. filename: filename,
  2510. filepath: filepath,
  2511. compressedFiledata: compressedFiledata,
  2512. iwidth: iwidth,
  2513. iheight: iheight,
  2514. screenX: screenX,
  2515. screenY: screenY,
  2516. size: size,
  2517. imagePath: imagePath,
  2518. shortenedName: shortenedName,
  2519. });
  2520. }
  2521. }
  2522. /*
  2523. Main function to append desktop icon to desktop
  2524. Usage: Pass in the target (as jquery object, usually $("#iconwrapper")) and properties with the following object
  2525. properties = {
  2526. type: "",
  2527. filename: "",
  2528. filepath: "",
  2529. compressedFiledata: "",
  2530. iwidth: "",
  2531. iheight: "",
  2532. screenX: "",
  2533. screenY: "",
  2534. size: "",
  2535. imagePath: "",
  2536. shortenedName: "",
  2537. }
  2538. Where the enmty string is the value that require filling in
  2539. */
  2540. function appendDesktopIcon(target, properties){
  2541. var htmlType = "div";
  2542. var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  2543. if (properties.type == "file" && isChrome){
  2544. htmlType = "a";
  2545. }
  2546. var thisIcon = $(`<${htmlType} href="javascript:void(0);" class="launchIcon"
  2547. type="${properties.type}"
  2548. draggable="true"
  2549. ondragover="allowDrop(event)"
  2550. ondrop="drop(event)"
  2551. ondragstart="drag(event)"
  2552. onmousedown="iconClicked(this,event);"
  2553. ondblclick="iconDoubleClicked(this,event);"
  2554. ontouchstart="iconClicked(this,event); doubleTouchHandler(this, event,openViaTouch);"
  2555. filename="${properties.filename}"
  2556. filepath="${properties.filepath}"
  2557. filedata="${properties.compressedFiledata}"
  2558. style="width:${properties.iwidth}px; height:${properties.iheight}px;left:${properties.screenX}px; top:${properties.screenY}px;">
  2559. <span class="launchIconWrapper"><img class="launchIconImage ${properties.size}" src="${properties.imagePath}" draggable="false"></img>
  2560. <p class="launchIconText ${properties.size} ">${properties.shortenedName}</p></span>
  2561. </${htmlType}>`);
  2562. $(target).append(thisIcon);
  2563. if (properties.type == "file" && isChrome){
  2564. console.log(isChrome);
  2565. let thisFilepath = properties.filepath;
  2566. $(thisIcon)[0].addEventListener("dragstart",function(evt){
  2567. //var filecontent = toDataUrl("media/?file=" + thisFilepath);
  2568. //var fileBase64 = window.btoa(filecontent);
  2569. var targetMime = "plain/text";
  2570. $.ajax({
  2571. url: "media/getMime/?file=" + encodeURIComponent(properties.filepath),
  2572. success: function(data){
  2573. if (data.error !== undefined){
  2574. targetMime = "text/directory";
  2575. }else{
  2576. targetMime = data;
  2577. }
  2578. },
  2579. async: false
  2580. });
  2581. evt.dataTransfer.setData("DownloadURL",targetMime+":"+ properties.filename +":"+ location.protocol + "//" + location.hostname + ":" + location.port + "/media/?file=" + encodeURIComponent(properties.filepath));
  2582. //evt.dataTransfer.setData("DownloadURL","video/mp4"+":"+"test.mp4"+":"+"data:"+"video/mp4"+";base64,"+fileBase64);
  2583. },false);
  2584. }
  2585. }
  2586. // ========================== LAUNCH ICON OPERATIONS ================
  2587. //This function start all the launchicon related events
  2588. function drag(ev) {
  2589. //If rename mode, disable drag drop
  2590. if (renameMode){
  2591. return false;
  2592. }
  2593. var target = ev.target;
  2594. if (!($(ev.target).is("div") || $(ev.target).is("a"))) {
  2595. target = $(target).parent();
  2596. }
  2597. //Parse the standard filename / filepath data
  2598. var filename = $(target).attr("filename");
  2599. var filepath = $(target).attr('filepath');
  2600. ev.dataTransfer.setData("filename", filename);
  2601. ev.dataTransfer.setData("filepath", filepath);
  2602. //Parse multifile selection filedata
  2603. var filelist = [];
  2604. if ($(".launchIconWrapper.selected").length > 0){
  2605. if (ctrlHold || $(".launchIconWrapper.selected").length > 1){
  2606. //Include all objects selected
  2607. $(".launchIconWrapper.selected").each(function(){
  2608. var fd = $(this).parent().attr("filedata");
  2609. fd = JSON.parse(decodeURIComponent(fd));
  2610. filelist.push({
  2611. filename: fd.Filename,
  2612. filepath: fd.Filepath,
  2613. hostUUID: hostInfo.DeviceUUID
  2614. });
  2615. });
  2616. }else{
  2617. //Only push the one selected
  2618. filelist.push({
  2619. filename: filename,
  2620. filepath: filepath,
  2621. hostUUID: hostInfo.DeviceUUID
  2622. });
  2623. }
  2624. }else{
  2625. //There is no selected item on desktop. Use the drag drop one
  2626. filelist.push({
  2627. filename: filename,
  2628. filepath: filepath
  2629. });
  2630. }
  2631. //console.log(filelist);
  2632. ev.dataTransfer.setData("filedata", JSON.stringify(filelist));
  2633. console.log(filelist);
  2634. //Set a flag on the drag events that these files are from Desktop GUI
  2635. ev.dataTransfer.setData("desktopflag", "true");
  2636. //Record the start drop relative position of the icon object
  2637. var dx = ev.pageX - $(target).offset().left;
  2638. var dy = ev.pageY - $(target).offset().top;
  2639. startDragRelatuve = [dx, dy];
  2640. ev.stopPropagation();
  2641. }
  2642. function drop(ev) {
  2643. ev.preventDefault();
  2644. ev.stopImmediatePropagation();
  2645. var target = $(ev.target);
  2646. if (!(target.is("div") || target.is("a"))) {
  2647. target = $(target).parent();
  2648. }
  2649. if (target.hasClass("launchIconWrapper")) {
  2650. target = target.parent();
  2651. }
  2652. var thisFilepath = $(target).attr("filepath");
  2653. if (thisFilepath == ev.dataTransfer.getData("filepath")) {
  2654. //Drag and drop on the same item. Ignore it
  2655. return;
  2656. }
  2657. var sourceFilename = ev.dataTransfer.getData("filename");
  2658. var sourceFilepath = ev.dataTransfer.getData("filepath");
  2659. //To handle multiple file transfer from file explorer
  2660. var sourceFilelist = ev.dataTransfer.getData("filedata");
  2661. console.log(target)
  2662. console.log(sourceFilename);
  2663. console.log(sourceFilepath);
  2664. if (sourceFilelist !== ""){
  2665. sourceFilelist = JSON.parse(sourceFilelist);
  2666. }
  2667. console.log(sourceFilelist);
  2668. //Drop opererations
  2669. if (target.attr("id") == "bgwrapper") {
  2670. if (sourceFilename == "" && sourceFilepath == "" && ev.dataTransfer.files.length > 0){
  2671. //Drag drop from external source. Upload to desktop
  2672. //Assign the locations for the objects
  2673. var files = ev.dataTransfer.files;
  2674. var gridMaxX = desktopGrids.length;
  2675. var gridMaxY = desktopGrids[0].length;
  2676. var targetLocation = findClosestGrid((ev.clientX), (ev.clientY), false);
  2677. var targetGridLocation = targetLocation[1];
  2678. var locations = [];
  2679. for (var k =0; k < files.length; k++){
  2680. var thisLocation = JSON.parse(JSON.stringify(targetGridLocation));
  2681. //Add k to y axis of the list.
  2682. thisLocation[1] += k;
  2683. if (thisLocation[1] >= gridMaxY){
  2684. thisLocation[0]++;
  2685. thisLocation[1] = 0;
  2686. }
  2687. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2688. //Desktop full. Force put to 0 0
  2689. thisLocation[0] = 0;
  2690. thisLocation[1] = 0;
  2691. break;
  2692. }
  2693. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  2694. thisLocation[1] += 1;
  2695. if (thisLocation[1] >= gridMaxY){
  2696. //Over the screen. Shift to the row on the right
  2697. thisLocation[0]++;
  2698. thisLocation[1] = 0;
  2699. }
  2700. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  2701. //Desktop full. Force put to 0 0
  2702. thisLocation[0] = 0;
  2703. thisLocation[1] = 0;
  2704. break;
  2705. }
  2706. }
  2707. locations.push(thisLocation)
  2708. }
  2709. console.log(locations, ev.dataTransfer.files);
  2710. //Register file locations
  2711. for (var j =0; j < locations.length; j++){
  2712. let thisFile = files[j];
  2713. let thisFilename = files[j].name;
  2714. let x = parseInt(locations[j][0]);
  2715. let y = parseInt(locations[j][1]);
  2716. uploadFile(thisFile,function(){
  2717. console.log("Uploader callback");
  2718. $.ajax({
  2719. url: "system/desktop/files",
  2720. method: "POST",
  2721. data: {"set": thisFilename, "x": x, "y": y},
  2722. success: function(data) {
  2723. //Refresh the desktop
  2724. refresh(undefined, true);
  2725. }
  2726. });
  2727. });
  2728. }
  2729. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  2730. //Drag drop multiple files from desktop or file explorer to desktop
  2731. var desktopFlag = ev.dataTransfer.getData("desktopflag");
  2732. if (desktopFlag == "" || desktopFlag === undefined || desktopFlag == null){
  2733. //This is a file drag drop from not desktop to desktop
  2734. var filelist = ev.dataTransfer.getData("filedata");
  2735. if (filelist != ""){
  2736. filelist = JSON.parse(filelist);
  2737. if (filelist.length == 0){
  2738. return
  2739. }
  2740. //Get the position for this drop events and arrange grid locations
  2741. var gridPosition = gridPositionAllocate(ev.clientX, ev.clientY, filelist.length);
  2742. console.log(gridPosition)
  2743. //Check if source is also from user:/
  2744. var srcVroot = filelist[0].filepath.split(":/").shift();
  2745. var mode = "copy"
  2746. var title = "Copying "
  2747. if (srcVroot == "user"){
  2748. //Move
  2749. mode = "move"
  2750. title = "Moving "
  2751. }
  2752. //Check if any of the files already exists on desktop
  2753. /*
  2754. var duplicateFound = false;
  2755. filelist.forEach(file => {
  2756. var thisFilename = file.filename;
  2757. desktopFileList.forEach(desktopFile => {
  2758. if (desktopFile == thisFilename){
  2759. //Diplicate
  2760. duplicateFound = true;
  2761. }
  2762. });
  2763. });
  2764. */
  2765. var filepathList = [];
  2766. filelist.forEach(file => {
  2767. filepathList.push(file.filepath)
  2768. });
  2769. //Start the file operation dialog
  2770. var oprConfig = {
  2771. opr: mode,
  2772. src: filepathList,
  2773. dest: "user:/Desktop/",
  2774. overwriteMode: "ask"
  2775. }
  2776. var configHash = encodeURIComponent(JSON.stringify(oprConfig));
  2777. //Genreate window title
  2778. title = title + filepathList.length;
  2779. if (filepathList.length > 1){
  2780. title += " files";
  2781. }else{
  2782. title += " file";
  2783. }
  2784. parent.newFloatWindow({
  2785. url: "SystemAO/file_system/file_operation.html#" + configHash,
  2786. width: 400,
  2787. height: 220,
  2788. appicon: "SystemAO/file_system/img/selector.png",
  2789. title: title
  2790. });
  2791. }
  2792. }else{
  2793. //This is a file drag event from desktop, but more than one files.
  2794. //Pin the final location for the drag drop object
  2795. var sourceObject = getObjectFromPath(sourceFilepath);
  2796. var dx = startDragRelatuve[0];
  2797. var dy = startDragRelatuve[1];
  2798. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  2799. var closestLocation = targetLocation[0];
  2800. var duplicateObject = getObjectFromLocation(closestLocation[0] + iconOffsetXY[0], closestLocation[1] + iconOffsetXY[1]);
  2801. if (duplicateObject !== undefined) {
  2802. //There are already object there. Do nothing
  2803. console.log("Drop location duplicated!")
  2804. return;
  2805. }
  2806. //Get other objects that is not the one drag dropped
  2807. var iconOffset = {};
  2808. for (var i =0; i < sourceFilelist.length; i++){
  2809. var thisFile = sourceFilelist[i];
  2810. if (thisFile.filepath != sourceFilepath){
  2811. //Calculate the x y offset of this icon to the drag drop one
  2812. var thisIconObject = getObjectFromPath(thisFile.filepath);
  2813. iconOffset[thisFile.filepath] = {
  2814. dx: $(sourceObject).offset().left - $(thisIconObject).offset().left,
  2815. dy: $(sourceObject).offset().top - $(thisIconObject).offset().top
  2816. }
  2817. //console.log(thisFile.filename, iconOffset[thisFile.filepath]);
  2818. }
  2819. }
  2820. //Move the drag drop object to the desiged location
  2821. $(sourceObject).css({
  2822. left: closestLocation[0] + iconOffsetXY[0],
  2823. top: closestLocation[1] + iconOffsetXY[1]
  2824. });
  2825. //Save the drag item location
  2826. $.ajax({
  2827. url: "system/desktop/files",
  2828. method: "POST",
  2829. data: {"set": sourceFilename, "x": targetLocation[1][0], "y": targetLocation[1][1]},
  2830. success: function(data) {
  2831. //console.log(data);
  2832. }
  2833. });
  2834. //Move all the relative files to the main object
  2835. var relocatePendingObjects = [];
  2836. for (const [filepath, offset] of Object.entries(iconOffset)) {
  2837. let thisIconObject = getObjectFromPath(filepath);
  2838. let caluclatedLocation = [$(sourceObject).offset().left - offset.dx, $(sourceObject).offset().top - offset.dy];
  2839. let finalIconLocation = findClosestGrid(caluclatedLocation[0], caluclatedLocation[1]);
  2840. //Check for duplication
  2841. /*
  2842. var duplicateObject = getObjectFromLocation(finalIconLocation[0][0] + iconOffsetXY[0], finalIconLocation[0][1] + iconOffsetXY[1]);
  2843. if (duplicateObject !== undefined) {
  2844. //There are already object there. Relocate this object later
  2845. relocatePendingObjects.push(duplicateObject)
  2846. }
  2847. */
  2848. //Move this icon to designed location
  2849. $(thisIconObject).css({
  2850. left: finalIconLocation[0][0] + iconOffsetXY[0],
  2851. top: finalIconLocation[0][1] + iconOffsetXY[1]
  2852. });
  2853. let thisIconFileData = JSON.parse(decodeURIComponent($(thisIconObject).attr("filedata")));
  2854. //Record this in database
  2855. $.ajax({
  2856. url: "system/desktop/files",
  2857. method: "POST",
  2858. data: {"set": thisIconFileData.Filename, "x": finalIconLocation[1][0], "y": finalIconLocation[1][1]},
  2859. success: function(data) {
  2860. //console.log(data);
  2861. }
  2862. });
  2863. }
  2864. //Get duplication objects
  2865. for (const [filepath, offset] of Object.entries(iconOffset)) {
  2866. let thisIconObject = getObjectFromPath(filepath);
  2867. //Check for duplication
  2868. var iconLocation = [$(thisIconObject).offset().left, $(thisIconObject).offset().top];
  2869. $(".launchIcon").each(function(){
  2870. if ($(this).offset().left == iconLocation[0] && $(this).offset().top == iconLocation[1]){
  2871. //This icon is at the target icon location
  2872. if ($(this).attr("filepath") != filepath){
  2873. relocatePendingObjects.push($(this));
  2874. }
  2875. }
  2876. });
  2877. }
  2878. //Relocate objects that is in the way of moving
  2879. for (var i = 0; i < relocatePendingObjects.length; i++){
  2880. var thisObject = relocatePendingObjects[i];
  2881. console.log(thisObject);
  2882. var thisX = $(thisObject).offset().left;
  2883. var thisY = $(thisObject).offset().top;
  2884. var nextEmptyGrid = findClostestEmptyGridLocation(thisX, thisY);
  2885. //Move this file to the next empty grid location
  2886. $(thisObject).css({
  2887. left: nextEmptyGrid[0][0] + iconOffsetXY[0],
  2888. top: nextEmptyGrid[0][1] + iconOffsetXY[1]
  2889. });
  2890. //Save move record to db
  2891. let thisIconFileData = JSON.parse(decodeURIComponent($(thisObject).attr("filedata")));
  2892. $.ajax({
  2893. url: "system/desktop/files",
  2894. method: "POST",
  2895. data: {"set": thisIconFileData.Filename, "x": nextEmptyGrid[1][0], "y": nextEmptyGrid[1][1]},
  2896. success: function(data) {
  2897. //console.log(data);
  2898. }
  2899. });
  2900. }
  2901. }
  2902. }else{
  2903. //Dropping a file onto other place on desktop
  2904. var sourceObject = getObjectFromPath(sourceFilepath);
  2905. var dx = startDragRelatuve[0];
  2906. var dy = startDragRelatuve[1];
  2907. var targetLocation = findClosestGrid((ev.clientX - dx), (ev.clientY - dy));
  2908. var closestLocation = targetLocation[0];
  2909. //Check if there are objects already at that location
  2910. var duplicateObject = getObjectFromLocation(closestLocation[0], closestLocation[1]);
  2911. if (duplicateObject !== undefined) {
  2912. //There are already object there. Do nothing
  2913. console.log("Drop location duplicated!")
  2914. return;
  2915. }
  2916. var closestGridIndex = targetLocation[1];
  2917. $(sourceObject).css({
  2918. left: closestLocation[0] + iconOffsetXY[0],
  2919. top: closestLocation[1] + iconOffsetXY[1]
  2920. });
  2921. $.ajax({
  2922. url: "system/desktop/files",
  2923. method: "POST",
  2924. data: {"set": sourceFilename, "x": closestGridIndex[0], "y": closestGridIndex[1]},
  2925. success: function(data) {
  2926. //console.log(data);
  2927. }
  2928. });
  2929. }
  2930. } else if (target.attr("type") == "folder") {
  2931. //Move this file or folder into the target folder
  2932. //WIP
  2933. } else if (target.attr("type") == "shortcut") {
  2934. //Opening with the shortcut
  2935. //Check shortcut type
  2936. let shortcutData = JSON.parse(decodeURIComponent($(target).attr("filedata")));
  2937. var shortcutType = shortcutData["ShortcutType"];
  2938. if (shortcutType == "module") {
  2939. //Open the source file with this module
  2940. let openFileList = [];
  2941. if ($(".launchiconwrapper.selected").length > 0 && !Array.isArray(sourceFilelist)) {
  2942. $(".launchiconwrapper.selected").each(function() {
  2943. let thisFileData = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  2944. openFileList.push({
  2945. filename: thisFileData["Filename"],
  2946. filepath: thisFileData["Filepath"]
  2947. });
  2948. });
  2949. }else if (sourceFilelist.length > 0 && Array.isArray(sourceFilelist)){
  2950. //Open file that is transfered from file explorer.
  2951. openFileList = sourceFilelist;
  2952. console.log(openFileList);
  2953. } else {
  2954. //Only pass in the current selected file.
  2955. openFileList.push({
  2956. filename: sourceFilename,
  2957. filepath: sourceFilepath
  2958. });
  2959. }
  2960. var shortcutModule = getModuleFromShortcutInfo(shortcutData);
  2961. //console.log(openFileList);
  2962. if (shortcutModule === undefined){
  2963. //This shortcut module is not found on this server
  2964. return;
  2965. }
  2966. openFileWithModule(shortcutModule, openFileList);
  2967. } else if (shortcutType == "folder") {
  2968. //Move the source file into this folder
  2969. }
  2970. } else {
  2971. console.log("Unknown reaction type: ", target.attr("type"));
  2972. }
  2973. }
  2974. function getModuleFromShortcutInfo(shortcutInfo) {
  2975. var ShortcutPath = shortcutInfo["ShortcutPath"];
  2976. if (ShortcutPath.includes("/") == false) {
  2977. //Legacy defination. Append /index.html at the back.
  2978. ShortcutPath = ShortcutPath + "/index.html";
  2979. }
  2980. //Try to match it with the module installed
  2981. for (var i = 0; i < moduleInstalled.length; i++) {
  2982. if (moduleInstalled[i]["StartDir"] == ShortcutPath || moduleInstalled[i]["Name"] == shortcutInfo["ShortcutName"]) {
  2983. //This is the correct module to be loaded
  2984. return moduleInstalled[i];
  2985. }
  2986. }
  2987. }
  2988. //Allocate the given number of grids from desktop
  2989. function gridPositionAllocate(posx, posy, numberOfGridNeeded=1){
  2990. var gridMaxX = desktopGrids.length;
  2991. var gridMaxY = desktopGrids[0].length;
  2992. var targetLocation = findClosestGrid(posx, posy, false);
  2993. var targetGridLocation = targetLocation[1];
  2994. var previousEmptyGridPosition = targetGridLocation;
  2995. var locations = [];
  2996. for (var k =0; k < numberOfGridNeeded; k++){
  2997. var thisLocation = JSON.parse(JSON.stringify(previousEmptyGridPosition));
  2998. //Add k to y axis of the list.
  2999. thisLocation[1] += k;
  3000. if (thisLocation[1] >= gridMaxY){
  3001. thisLocation[0]++;
  3002. thisLocation[1] = 0;
  3003. }
  3004. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3005. //Desktop full. Force put to 0 0
  3006. thisLocation[0] = 0;
  3007. thisLocation[1] = 0;
  3008. break;
  3009. }
  3010. while (getObjectFromGridLocation(thisLocation[0], thisLocation[1]) !== undefined){
  3011. thisLocation[1] += 1;
  3012. if (thisLocation[1] >= gridMaxY){
  3013. //Over the screen. Shift to the row on the right
  3014. thisLocation[0]++;
  3015. thisLocation[1] = 0;
  3016. }
  3017. if (thisLocation[1] >= gridMaxY && thisLocation[0] >= gridMaxX){
  3018. //Desktop full. Force put to 0 0
  3019. thisLocation[0] = 0;
  3020. thisLocation[1] = 0;
  3021. break;
  3022. }
  3023. }
  3024. previousEmptyGridPosition = JSON.parse(JSON.stringify(thisLocation))
  3025. locations.push(thisLocation)
  3026. }
  3027. return locations
  3028. }
  3029. function setIconDesktopLocation(sourceFilename, gridIndexX, gridIndexY, callback = undefined) {
  3030. $.ajax({
  3031. url: "system/desktop/files",
  3032. method: "POST",
  3033. data: {"set": sourceFilename, "x": gridIndexX, "y": gridIndexY},
  3034. success: function(data) {
  3035. if (data.error !== undefined) {
  3036. console.log(data.error);
  3037. } else {
  3038. if (callback !== undefined) {
  3039. callback();
  3040. }
  3041. }
  3042. }
  3043. });
  3044. }
  3045. //THIS FUNCTION IS NEEDED. DO NOT DELETE ALLOWDROP FUNCTION
  3046. function allowDrop(ev) {
  3047. ev.preventDefault();
  3048. }
  3049. //Pass in the object fullpath and return the icon object onscreen
  3050. function getObjectFromPath(path) {
  3051. var object;
  3052. $(".launchIcon").each(function() {
  3053. if ($(this).attr("filepath") == path) {
  3054. object = $(this);
  3055. }
  3056. });
  3057. return object;
  3058. }
  3059. //Pass in the coordinate and check if there is another object at the same location
  3060. function getObjectFromLocation(x, y) {
  3061. var object;
  3062. $(".launchIcon").each(function() {
  3063. if ($(this).position().left == x && $(this).position().top == y) {
  3064. object = $(this);
  3065. }
  3066. });
  3067. return object;
  3068. }
  3069. //Similar function to getObjectFromLocation but using grid coordinate instead of pixel coordinate
  3070. function getObjectFromGridLocation(gx, gy){
  3071. var pos = JSON.parse(JSON.stringify(desktopGrids[gx][gy]));
  3072. pos[0] = pos[0] + iconOffsetXY[0];
  3073. pos[1] = pos[1] + iconOffsetXY[1];
  3074. return getObjectFromLocation(pos[0],pos[1]);
  3075. }
  3076. //Find the clostest empty grid, prioirty given to y first then x
  3077. function findClostestEmptyGridLocation(x, y){
  3078. //Reduce icon offset to the x y on screen coordinate
  3079. x = x - iconOffsetXY[0];
  3080. y = y - iconOffsetXY[1];
  3081. //Get the grid index from absolute coordinate
  3082. var currentGridLocation = getGridIndexFromLocation(x,y);
  3083. console.log(currentGridLocation);
  3084. //Search for the next empty location
  3085. var targetLocation = [[-1,-1],[-1,-1]];
  3086. for (var i = currentGridLocation[0]; i < desktopGrids.length; i++){
  3087. var yStart = 0;
  3088. if (i == currentGridLocation[0]){
  3089. yStart = currentGridLocation[1];
  3090. }
  3091. for (k = yStart; k < desktopGrids[i].length; k++){
  3092. var thisLocation = JSON.parse(JSON.stringify(desktopGrids[i][k]));
  3093. var offsetedLocation = [thisLocation[0], thisLocation[1]];
  3094. var possibleDuplication = getObjectFromGridLocation(i,k);
  3095. //console.log( [i,k], offsetedLocation, possibleDuplication)
  3096. if (possibleDuplication === undefined){
  3097. //This is an empty slot
  3098. targetLocation = [offsetedLocation, [i,k]];
  3099. return targetLocation;
  3100. }
  3101. }
  3102. }
  3103. return targetLocation;
  3104. }
  3105. function getGridIndexFromLocation(x,y){
  3106. var gridIndex = [-1,-1];
  3107. for (var i = 0; i < desktopGrids.length; i++){
  3108. var thisXAxis = desktopGrids[i];
  3109. if (thisXAxis[0][0] == x){
  3110. //This x matches. Match y
  3111. gridIndex[0] = i;
  3112. for (var k = 0; k < thisXAxis.length; k++){
  3113. var thisYAxis = thisXAxis[k];
  3114. if (thisYAxis[1] == y){
  3115. gridIndex[1] = k;
  3116. return gridIndex;
  3117. }
  3118. }
  3119. }
  3120. }
  3121. return gridIndex;
  3122. }
  3123. //Set allow overshoot to allow drop point to get closest grid with x / y > cursor posx /y
  3124. function findClosestGrid(x, y, allowOvershoot = true) {
  3125. var minDx = window.innerWidth;
  3126. var minDy = window.innerHeight;
  3127. var finalLocation = [-1, -1];
  3128. var gridLocation = [-1, -1];
  3129. for (var i = 0; i < desktopGrids.length; i++) {
  3130. for (var j = 0; j < desktopGrids[0].length; j++) {
  3131. var thisGridLocation = desktopGrids[i][j];
  3132. var dx = x - thisGridLocation[0];
  3133. var dy = y - thisGridLocation[1];
  3134. if (allowOvershoot) {
  3135. if (Math.abs(dx) < minDx) {
  3136. minDx = Math.abs(x - thisGridLocation[0]);
  3137. finalLocation[0] = thisGridLocation[0];
  3138. gridLocation[0] = i;
  3139. }
  3140. if (Math.abs(dy) < minDy) {
  3141. minDy = Math.abs(y - thisGridLocation[1]);
  3142. finalLocation[1] = thisGridLocation[1];
  3143. gridLocation[1] = j;
  3144. }
  3145. } else {
  3146. if (dx < minDx && dx > 0) {
  3147. minDx = Math.abs(x - thisGridLocation[0]);
  3148. finalLocation[0] = thisGridLocation[0];
  3149. gridLocation[0] = i;
  3150. }
  3151. if (dy < minDy && dy > 0) {
  3152. minDy = Math.abs(y - thisGridLocation[1]);
  3153. finalLocation[1] = thisGridLocation[1];
  3154. gridLocation[1] = j;
  3155. }
  3156. }
  3157. }
  3158. }
  3159. return [finalLocation, gridLocation];
  3160. }
  3161. //Ask for confirmation before window close
  3162. //Update 16 Feb 2021: Disabled confirmation and use a new method of implementing this later
  3163. /*
  3164. function myConfirmation() {
  3165. if (!loggingOut){
  3166. return 'Your data might not been saved. Are you sure you want to quit?';
  3167. }
  3168. }
  3169. window.onbeforeunload = myConfirmation;
  3170. */
  3171. function iconClicked(object, evt) {
  3172. if (renameMode){
  3173. //Exit rename mode if icon is clicked during renaming
  3174. if ($(object).find(".renameInput").length == 0){
  3175. exitRenameMode();
  3176. }
  3177. }
  3178. //Clicked on a launch icon.
  3179. var alreadyHighlighted = $(object).find(".launchIconWrapper").hasClass("selected");
  3180. if (alreadyHighlighted){
  3181. //Already selected
  3182. if (ctrlHold) {
  3183. //Selection
  3184. $(object).find(".launchIconWrapper").removeClass("selected");
  3185. }
  3186. }else{
  3187. //Not selected yet
  3188. if (ctrlHold) {
  3189. //Add this into selection
  3190. $(object).find(".launchIconWrapper").addClass("selected");
  3191. }else{
  3192. //Remove all others and select this
  3193. $(".launchIconWrapper.selected").removeClass("selected");
  3194. $(object).find(".launchIconWrapper").addClass("selected");
  3195. }
  3196. }
  3197. }
  3198. function iconDoubleClicked(object, evt=undefined) {
  3199. //Don't allow opening when renaming
  3200. if (renameMode){
  3201. return;
  3202. }
  3203. //Double click on a launch icon, tries to open it
  3204. var filedata = ao_module_utils.attrToObject($(object).attr("filedata"));
  3205. //console.log(filedata);
  3206. if (filedata.IsDir) {
  3207. //This is a directory. Open with file explorer
  3208. newFloatWindow({
  3209. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(filedata.Filepath),
  3210. appicon: "SystemAO/file_system/img/small_icon.png",
  3211. width: 1080,
  3212. height: 580,
  3213. title: "File Manager"
  3214. });
  3215. } else if (filedata.IsShortcut) {
  3216. //This is a shortcut. Open the target endpoint
  3217. var stype = filedata["ShortcutType"];
  3218. if (stype == "module") {
  3219. //Open the target module
  3220. openModule(filedata.ShortcutPath);
  3221. } else if (stype == "folder") {
  3222. //Open the target folder
  3223. openFolder(filedata.ShortcutPath)
  3224. }else if (stype == "url"){
  3225. //Open the target webpage in a new tab
  3226. window.open(filedata.ShortcutPath);
  3227. }else{
  3228. console.log(filedata);
  3229. }
  3230. } else {
  3231. //This is a file. Open it with default opener
  3232. $.ajax({
  3233. url: "system/modules/getDefault",
  3234. method: "GET",
  3235. data: {
  3236. opr: "launch",
  3237. ext: filedata.Ext,
  3238. mode: "launch"
  3239. },
  3240. success: function(data) {
  3241. if (data.error !== undefined) {
  3242. //No default opener assigned
  3243. var url = "SystemAO/file_system/defaultOpener.html";
  3244. var icon = "SystemAO/file_system/img/opener.png";
  3245. var title = "Select an opener WebApp: "
  3246. var openFileList = [];
  3247. var openFileObject = {
  3248. filepath: filedata.Filepath,
  3249. filename: filedata.Filename
  3250. }
  3251. openFileList.push(openFileObject);
  3252. var openParamter = encodeURIComponent(JSON.stringify(openFileObject));
  3253. newFloatWindow({
  3254. url: url + "#" + openParamter,
  3255. width: 320,
  3256. height: 510,
  3257. appicon: icon,
  3258. title: title
  3259. });
  3260. } else {
  3261. //Assigned. Launch with given paramter
  3262. var url = data["StartDir"];
  3263. var size = [undefined, undefined];
  3264. var title = data["Name"];
  3265. var icon = "img/system/favicon.png";
  3266. if (data["IconPath"] != "") {
  3267. icon = data["IconPath"];
  3268. }
  3269. //Use floatWindow if exists
  3270. if (data["SupportFW"] == true && data["LaunchFWDir"] != "") {
  3271. url = data["LaunchFWDir"];
  3272. if (data["InitFWSize"] !== null) {
  3273. size = data["InitFWSize"]
  3274. }
  3275. }
  3276. //Use embedded mode if exists
  3277. if (data["SupportEmb"] == true && data["LaunchEmb"] != "") {
  3278. url = data["LaunchEmb"];
  3279. if (data["InitEmbSize"] !== null) {
  3280. size = data["InitEmbSize"]
  3281. }
  3282. }
  3283. //Build open File Hash Data Format
  3284. var openFileList = [];
  3285. var openFileObject = {
  3286. filepath: filedata.Filepath,
  3287. filename: filedata.Filename
  3288. }
  3289. openFileList.push(openFileObject);
  3290. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  3291. //Add launch files info and launch floatWindow
  3292. newFloatWindow({
  3293. url: url + "#" + openParamter,
  3294. width: size[0],
  3295. height: size[1],
  3296. appicon: icon,
  3297. title: title
  3298. });
  3299. }
  3300. }
  3301. })
  3302. }
  3303. }
  3304. $(window).on("resize", function(event) {
  3305. redrawDesktopGrids();
  3306. resizeAllFloatWindowButtons();
  3307. })
  3308. // ======================= DOCUMENT KEY BINDING =====================
  3309. $(document).keydown(function(event) {
  3310. if (event.which == "17") {
  3311. //Pressdown of Ctrl key
  3312. ctrlHold = true;
  3313. } else if (event.which == "16") {
  3314. //Pressdown of Shift key
  3315. shiftHold = true;
  3316. }else if (event.which == "27"){
  3317. //Cancel all floatwindow events and key events
  3318. $("#fwdragpanel").hide();
  3319. $("#tfwdragpanel").hide();
  3320. $(".floatWindow").find(".iframecover").hide();
  3321. movingWindow = false;
  3322. resizingWindow = false;
  3323. resizingEdgeID = 0;
  3324. multiSelecting = false;
  3325. ctrlHold = false;
  3326. shiftHold = false;
  3327. }else if (event.which == "46"){
  3328. //Delete key
  3329. if (renameMode){
  3330. //Deleting content in textarea. Ignore delte action
  3331. return true
  3332. }
  3333. var deleteFilelist = [];
  3334. var deleteFilenameList = [];
  3335. $(".launchIconWrapper.selected").each(function(){
  3336. var fileObject = $(this).parent();
  3337. var fd = JSON.parse(decodeURIComponent((fileObject).attr("filedata")));
  3338. deleteFilelist.push(fd.Filepath);
  3339. deleteFilenameList.push(fd.Filename)
  3340. });
  3341. //Prase the filelist and pass to trash module
  3342. console.log(deleteFilelist);
  3343. $.ajax({
  3344. url: "system/file_system/fileOpr",
  3345. method:"POST",
  3346. data: {opr: "recycle", src: JSON.stringify(deleteFilelist)},
  3347. success: function(data){
  3348. if (data.error !== undefined){
  3349. alert(data.error);
  3350. }else{
  3351. refresh(undefined, true);
  3352. }
  3353. }
  3354. });
  3355. //Delete the file's desktop location
  3356. deleteFilenameList.forEach(file => {
  3357. $.ajax({
  3358. url: "system/desktop/files",
  3359. data: {del: file},
  3360. success: function(data){
  3361. if (data.error !== undefined){
  3362. console.log(data.error);
  3363. }
  3364. }
  3365. });
  3366. })
  3367. }else if (event.which == "13"){
  3368. //Enter key
  3369. if (!renameMode){
  3370. //Open selected object by emulating double click
  3371. $(".launchIconWrapper.selected").each(function(){
  3372. var object = $(this).parent();
  3373. iconDoubleClicked(object);
  3374. });
  3375. }else if (renameMode){
  3376. event.preventDefault();
  3377. exitRenameMode();
  3378. }
  3379. }else{
  3380. //console.log(event.which);
  3381. }
  3382. });
  3383. $(document).keyup(function(event) {
  3384. if (event.which == "17") {
  3385. ctrlHold = false;
  3386. } else if (event.which == "16") {
  3387. shiftHold = false;
  3388. }
  3389. });
  3390. $("#bgwrapper").on("mouseup", function(event) {
  3391. //Deselect all selected icons
  3392. event.preventDefault();
  3393. event.stopImmediatePropagation();
  3394. mainWindowMouseup(event);
  3395. });
  3396. function openFolder(virtualPath){
  3397. newFloatWindow({
  3398. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(virtualPath),
  3399. appicon: "SystemAO/file_system/img/small_icon.png",
  3400. width:1080,
  3401. height:580,
  3402. title: "File Manager"
  3403. });
  3404. }
  3405. function logout() {
  3406. loggingOut = true;
  3407. if (confirm("Exiting Session. Confirm?")){
  3408. $.get("system/auth/logout", function() {
  3409. window.location.href = "/";
  3410. });
  3411. }
  3412. hideAllContextMenus();
  3413. }
  3414. // ======================= CONTEXT MENU =============================
  3415. window.addEventListener("contextmenu",
  3416. function(e) {
  3417. e.preventDefault();
  3418. e.stopPropagation();
  3419. var clickTarget = $(e.target);
  3420. hideAllContextMenus();
  3421. showMenu = false;
  3422. $("#contextmenu").html("");
  3423. if (clickTarget.hasClass("launchIcon") || clickTarget.hasClass("launchIconImage") || clickTarget.hasClass("launchIconText")) {
  3424. //Click on an object on destkop
  3425. if (clickTarget.hasClass("launchIcon") == false) {
  3426. clickTarget = $(clickTarget).parent().parent();
  3427. }
  3428. if (!ctrlHold && !$(clickTarget).find(".launchIconWrapper").hasClass("selected")){
  3429. $(".launchIconWrapper.selected").removeClass("selected");
  3430. }
  3431. //Select this object
  3432. $(clickTarget).find(".launchIconWrapper").addClass("selected");
  3433. var objectType = $(clickTarget).attr("type");
  3434. operationTargetLaunchIcon = $(clickTarget);
  3435. //Check if selected more than one object
  3436. if ($(".launchIconWrapper.selected").length > 1){
  3437. //When the user selected more than one item on desktop
  3438. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3439. addContextMenuItem($("#contextmenu"), 'Open With', "<i class='caret right icon'></i>", "handleOpenWith", true);
  3440. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3441. addContextMenuSeperator($("#contextmenu"));
  3442. addContextMenuItem($("#contextmenu"), 'Download in Zip', "<i class='download icon'></i>", "downloadFile", false);
  3443. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='copy icon'></i>", "handleCloning", false);
  3444. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3445. addContextMenuSeperator($("#contextmenu"));
  3446. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3447. }else{
  3448. //When the user only selected one item
  3449. if (objectType == "file") {
  3450. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3451. addContextMenuItem($("#contextmenu"), 'Open With', "<i class='caret right icon'></i>", "handleOpenWith", true);
  3452. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3453. addContextMenuSeperator($("#contextmenu"));
  3454. addContextMenuItem($("#contextmenu"), 'Download', "<i class='download icon'></i>", "downloadFile", false);
  3455. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='copy icon'></i>", "handleCloning", false);
  3456. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3457. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3458. addContextMenuSeperator($("#contextmenu"));
  3459. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3460. } else if (objectType == "folder") {
  3461. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3462. addContextMenuItem($("#contextmenu"), 'Zip here', "<i class='zip icon'></i>", "handleZipFolder", false);
  3463. addContextMenuItem($("#contextmenu"), 'Share', "<i class='caret right icon'></i>", "handleFileShare", true);
  3464. addContextMenuSeperator($("#contextmenu"));
  3465. addContextMenuItem($("#contextmenu"), 'Download as Zip', "<i class='download icon'></i>", "downloadFile", false);
  3466. addContextMenuItem($("#contextmenu"), 'Make a Copy', "<i class='caret right icon'></i>", "handleCloning", false);
  3467. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3468. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3469. addContextMenuSeperator($("#contextmenu"));
  3470. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3471. } else if (objectType == "shortcut") {
  3472. var fd = JSON.parse(decodeURIComponent($(clickTarget).attr("filedata")));
  3473. console.log(fd);
  3474. if (fd.ShortcutType == "module"){
  3475. //Public WebApp
  3476. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3477. addContextMenuItem($("#contextmenu"), 'Open in New Tab', "<i class='external icon'></i>", "openWebAppInNewTab", false);
  3478. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3479. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3480. }else if (fd.ShortcutType == "folder"){
  3481. //Folder
  3482. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3483. addContextMenuItem($("#contextmenu"), 'Open File Location', "<i class='folder open icon'></i>", "handleShortcutFolderOpen", false);
  3484. addContextMenuItem($("#contextmenu"), 'Rename', undefined, "handleRename", false);
  3485. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3486. addContextMenuSeperator($("#contextmenu"));
  3487. addContextMenuItem($("#contextmenu"), 'Properties', undefined, "openObjectProperty", false);
  3488. }else{
  3489. addContextMenuItem($("#contextmenu"), 'Open', undefined, "openIconViaMenu", false);
  3490. addContextMenuItem($("#contextmenu"), 'Delete', "<i class='trash icon'></i>", "handleFileDelete", false);
  3491. }
  3492. }else{
  3493. console.log("Opening context menu on unknown type: ", objectType);
  3494. }
  3495. }
  3496. showMenu = true;
  3497. } else if (clickTarget.hasClass("backgroundFrame") || (isSafari && $(clickTarget).attr("id") == "selectionPanel")) {
  3498. //Click on the background. Load background context menu.
  3499. addContextMenuItem($("#contextmenu"), 'New', "<i class='caret right icon'></i>", "newitemmenu", true);
  3500. addContextMenuItem($("#contextmenu"), 'Refresh', "<i class='refresh icon'></i>", "handleMenuRefresh", false);
  3501. addContextMenuItem($("#contextmenu"), 'Open File Manager', undefined, "openfm", false);
  3502. //addContextMenuItem($("#contextmenu"), 'Get File from URL', "<i class='download icon'></i>", "downloadURL", false);
  3503. addContextMenuItem($("#contextmenu"), 'Personalization', "<i class='paint brush icon'></i>", "personalization", false);
  3504. addContextMenuItem($("#contextmenu"), 'Background', "<i class='caret right icon'></i>", "background", true);
  3505. addContextMenuItem($("#contextmenu"), 'Icon Size', "<i class='caret right icon'></i>", "listIconsize", true);
  3506. addContextMenuItem($("#contextmenu"), 'Toggle FullScreen', "<i class='maximize icon'></i>", "fullscreen", false);
  3507. addContextMenuItem($("#contextmenu"), 'Exit', undefined, "logout", false);
  3508. showMenu = true;
  3509. }else if (clickTarget.hasClass("fwdragger") || (clickTarget.hasClass("title") && clickTarget.parent().hasClass("fwdragger"))){
  3510. //Click on the floatWindow object
  3511. addContextMenuItem($("#contextmenu"), 'Open in New Tab', "<i class='external icon'></i>", "openSelectedFloatWindowInNewTab", false);
  3512. addContextMenuItem($("#contextmenu"), 'Refresh', "<i class='refresh icon'></i>", "refreshSelectedFloatWindow", false);
  3513. addContextMenuSeperator($("#contextmenu"));
  3514. addContextMenuItem($("#contextmenu"), 'Minimize', "<i class='window minimize icon'></i>", "minimizeSelectedFloatWindow", false);
  3515. if ($(clickTarget).parent().hasClass("fixedsize") == false && $(clickTarget).parent().parent().hasClass("fixedsize") == false){
  3516. //This FloatWindow is resizable
  3517. console.log($(clickTarget).parent());
  3518. if ($(clickTarget).parent().attr("max") !== undefined && $(clickTarget).parent().attr("max") == "true"){
  3519. addContextMenuItem($("#contextmenu"), 'Restore', "<i class='window window restore icon'></i>", "maximizeSelectedFloatWindow", false);
  3520. }else{
  3521. addContextMenuItem($("#contextmenu"), 'Maximize', "<i class='window maximize icon'></i>", "maximizeSelectedFloatWindow", false);
  3522. }
  3523. }
  3524. addContextMenuItem($("#contextmenu"), 'Close', "<i class='remove icon'></i>", "closeSelectedFloatWindow", false);
  3525. showMenu = true;
  3526. }
  3527. if (showMenu){
  3528. //Toggle context menu
  3529. $("#contextmenu").show();
  3530. var startX = e.pageX;
  3531. var startY = e.pageY;
  3532. if (e.pageX > window.innerWidth / 2){
  3533. startX = e.pageX - $("#contextmenu").width();
  3534. }
  3535. if (e.pageY > window.innerHeight / 2){
  3536. startY = e.pageY - $("#contextmenu").height();
  3537. }
  3538. $("#contextmenu").css({
  3539. left: startX,
  3540. top: startY
  3541. });
  3542. menuStartLocation = [e.pageX, e.pageY];
  3543. }
  3544. }, true);
  3545. function handleMenuRefresh() {
  3546. //This function is here to remove the object and event passed in from menu pressed object
  3547. refresh();
  3548. }
  3549. function newshortcut(){
  3550. //Show the new shortcut creation tool
  3551. newFloatWindow({
  3552. url: "SystemAO/desktop/shortcutCreator.html",
  3553. appicon: "img/desktop/system_icon/shortcut.png",
  3554. width:815,
  3555. height:485,
  3556. title: "New Shortcut"
  3557. });
  3558. hideAllContextMenus();
  3559. }
  3560. function openIconViaMenu(target, event){
  3561. $(".launchIconWrapper.selected").each(function(){
  3562. iconObject = $(this).parent();
  3563. //Emulate a doubleclick on icon
  3564. iconDoubleClicked(iconObject, event);
  3565. });
  3566. hideAllContextMenus();
  3567. }
  3568. //Opening a shortcut module from desktop to new tab
  3569. function openWebAppInNewTab(target, event){
  3570. $(".launchIconWrapper.selected").each(function(){
  3571. var fd = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3572. $.get("system/modules/getLaunchPara?module=" + fd.ShortcutPath, function(data) {
  3573. if (data.error !== undefined) {
  3574. console.log(data.error);
  3575. }else{
  3576. //Open in new tab
  3577. window.open(data.StartDir)
  3578. }
  3579. });
  3580. });
  3581. }
  3582. function downloadFile(target, event){
  3583. if ( $(".launchIconWrapper.selected").length == 1){
  3584. //Download this file directly
  3585. var rawfiledata = $(".launchIconWrapper.selected").parent().attr("filedata");
  3586. var filedata = JSON.parse(decodeURIComponent(rawfiledata));
  3587. var filepath = filedata.Filepath;
  3588. //Resolve the link to media download link
  3589. var downloadLink = "media?file=" + filepath + "&download=true";
  3590. window.open(downloadLink)
  3591. }else if ($(".launchIconWrapper.selected").length > 1){
  3592. //Create a zip file using the fs api
  3593. var filelist = [];
  3594. $(".launchIconWrapper.selected").each(function(){
  3595. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3596. var filepath = filedata.Filepath;
  3597. filelist.push(filepath);
  3598. });
  3599. $.ajax({
  3600. url: "system/file_system/zipHandler",
  3601. data: {opr: "tmpzip", src: JSON.stringify(filelist), dest: ""},
  3602. method: "POST",
  3603. success: function(data){
  3604. if (data.error !== undefined){
  3605. alert(data.error);
  3606. }else{
  3607. //Zip completed.
  3608. window.open("media?file=" + data + "&download=true");
  3609. }
  3610. }
  3611. });
  3612. }
  3613. hideAllContextMenus();
  3614. }
  3615. function handleZipFolder(){
  3616. var filelist = [];
  3617. var filename = "desktop_" + new Date().getTime() + ".zip"
  3618. if ($(".launchIconWrapper.selected").length == 1){
  3619. filename = $(".launchIconWrapper.selected").parent().attr('filename') + ".zip";
  3620. }
  3621. $(".launchIconWrapper.selected").each(function(){
  3622. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3623. var filepath = filedata.Filepath;
  3624. if (filedata.IsDir == true){
  3625. filelist.push(filepath);
  3626. }
  3627. });
  3628. $.ajax({
  3629. url: "system/file_system/zipHandler",
  3630. data: {opr: "zip", src: JSON.stringify(filelist), dest: "user:/Desktop/" + filename},
  3631. method: "POST",
  3632. success: function(data){
  3633. if (data.error !== undefined){
  3634. alert(data.error);
  3635. }else{
  3636. //Zip completed.
  3637. console.log(data);
  3638. }
  3639. }
  3640. });
  3641. //console.log(filelist);
  3642. hideAllContextMenus();
  3643. }
  3644. function handleOpenWith(target, event){
  3645. $("#subcontextmenu").html("");
  3646. $.get("system/modules/list",function(data){
  3647. if (data.error !== undefined){
  3648. alert(data.error);
  3649. }else{
  3650. var supportedModuleCount = 0;
  3651. var openWithTargets = [];
  3652. for (var i =0; i < data.length; i++){
  3653. var thisModule = data[i];
  3654. if (thisModule.SupportEmb == true){
  3655. addContextMenuItem($("#subcontextmenu"), thisModule.Name, "", "openSelectedWith", false);
  3656. }
  3657. }
  3658. }
  3659. showSubContextMenu(target);
  3660. });
  3661. }
  3662. function openObjectProperty(target, object){
  3663. var filelist = [];
  3664. $(".launchIconWrapper.selected").each(function(){
  3665. var filepath = $(this).parent().attr("filepath");
  3666. filelist.push(filepath);
  3667. });
  3668. var hashPassthrough = encodeURIComponent(JSON.stringify(filelist));
  3669. newFloatWindow({
  3670. url: "SystemAO/file_system/file_properties.html#" + hashPassthrough,
  3671. width: 340,
  3672. height: 480,
  3673. appicon: "SystemAO/file_system/img/properties.png",
  3674. title: "File Properties",
  3675. });
  3676. hideAllContextMenus();
  3677. }
  3678. function openSelectedWith(target, event){
  3679. var targetModulename = $(target).text().trim();
  3680. var openFileList = [];
  3681. $(".selected.launchIconWrapper").each(function(){
  3682. var thisFiledata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3683. openFileList.push({
  3684. filename: thisFiledata.Filename,
  3685. filepath: thisFiledata.Filepath
  3686. });
  3687. });
  3688. //Find the launch info of the module
  3689. var targetModuleInfo = undefined;
  3690. for (var i =0; i < moduleInstalled.length; i++){
  3691. if (moduleInstalled[i].Name == targetModulename){
  3692. targetModuleInfo = JSON.parse(JSON.stringify(moduleInstalled[i]));
  3693. }
  3694. }
  3695. //Open the files with the given module
  3696. openFileWithModule(targetModuleInfo, openFileList);
  3697. hideAllContextMenus();
  3698. }
  3699. function getModuleInfoFromName(moduleName){
  3700. for (var i = 0; i < moduleInstalled.length; i++){
  3701. if (moduleInstalled[i].Name == moduleName){
  3702. return moduleInstalled[i];
  3703. }
  3704. }
  3705. return false
  3706. }
  3707. function addContextMenuItem(target, keyword, hotkey = undefined, functionName, containSubMenu = false) {
  3708. var itemClass = "item";
  3709. if (containSubMenu) {
  3710. itemClass = "item submenu";
  3711. }
  3712. if (hotkey !== undefined) {
  3713. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);">
  3714. ${keyword}
  3715. <span class="description">${hotkey}</span>
  3716. </div>`);
  3717. } else {
  3718. target.append(`<div class="${itemClass}" onclick="${functionName}(this,event);">
  3719. ${keyword}
  3720. </div>`);
  3721. }
  3722. }
  3723. function listIconsize(target, event) {
  3724. $("#subcontextmenu").html("");
  3725. var smallCheckmark = undefined;
  3726. var mediumCheckmark = undefined;
  3727. var bigCheckmark = undefined;
  3728. if (desktopIconSize == "small") {
  3729. smallCheckmark = "<i class='checkmark icon'></i>";
  3730. }
  3731. if (desktopIconSize == "medium") {
  3732. mediumCheckmark = "<i class='checkmark icon'></i>";
  3733. }
  3734. if (desktopIconSize == "big") {
  3735. bigCheckmark = "<i class='checkmark icon'></i>";
  3736. }
  3737. addContextMenuItem($("#subcontextmenu"), "Small", smallCheckmark, "setDesktopIconSize", false);
  3738. addContextMenuItem($("#subcontextmenu"), "Medium", mediumCheckmark, "setDesktopIconSize", false);
  3739. addContextMenuItem($("#subcontextmenu"), "Big", bigCheckmark, "setDesktopIconSize", false);
  3740. showSubContextMenu(target);
  3741. }
  3742. function setDesktopIconSize(target, evt) {
  3743. var targetSize = $(target).text().trim().toLowerCase();
  3744. if (["small", "medium", "big"].includes(targetSize)) {
  3745. desktopIconSize = targetSize;
  3746. }
  3747. refresh();
  3748. setStorage("iconsize", desktopIconSize);
  3749. hideAllContextMenus();
  3750. }
  3751. function addContextMenuSeperator(target) {
  3752. $(target).append(`<div class="divider"></div>`);
  3753. }
  3754. function downloadURL() {
  3755. alert("WIP");
  3756. hideAllContextMenus();
  3757. }
  3758. function background(target, evt) {
  3759. $("#subcontextmenu").html('<div class="item"><i class="loading spinning icon"></i> Loading</div>');
  3760. $.get("system/desktop/theme", function(data) {
  3761. $("#subcontextmenu").html("");
  3762. for (var i = 0; i < data.length; i++) {
  3763. if (currentUserTheme == data[i].Theme) {
  3764. addContextMenuItem($("#subcontextmenu"), data[i].Theme, "<i class='checkmark icon'></i>", "setTheme", false);
  3765. } else {
  3766. addContextMenuItem($("#subcontextmenu"), data[i].Theme, undefined, "setTheme", false);
  3767. }
  3768. }
  3769. });
  3770. showSubContextMenu(target);
  3771. }
  3772. //Set theme from button click
  3773. function setTheme(target, evt) {
  3774. var theme = $(target).text().trim();
  3775. setDesktopTheme(theme);
  3776. hideAllContextMenus();
  3777. }
  3778. function personalization() {
  3779. //Show the personalization window
  3780. newFloatWindow({
  3781. url: "SystemAO/desktop/personalization.html",
  3782. appicon: "SystemAO/desktop/img/personalization.png",
  3783. width:640,
  3784. height:480,
  3785. title: "Personalization"
  3786. });
  3787. hideAllContextMenus();
  3788. }
  3789. //New folder on the menu start location
  3790. function newfolder(object, event) {
  3791. var closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  3792. let closestPixelLocation = closestLocation[0];
  3793. let closestGridIndexLocation = closestLocation[1];
  3794. //Generate new foldername
  3795. var newFolderName = "New Folder";
  3796. var counter = 1;
  3797. while (desktopFileList.includes(newFolderName)) {
  3798. newFolderName = `New Folder(${counter})`;
  3799. counter++;
  3800. }
  3801. //Check if there are already another object at that locaton
  3802. var duplicateObject = getObjectFromLocation(closestPixelLocation[0], closestPixelLocation[1]);
  3803. var createObjectLocation = true;
  3804. if (duplicateObject !== undefined) {
  3805. //Ignore create position. Let it settle on next new slot.
  3806. createObjectLocation = false;
  3807. }
  3808. //Create the folder
  3809. $.post("system/file_system/newItem", {
  3810. type: "folder",
  3811. src: "user:/Desktop/",
  3812. filename: newFolderName
  3813. }).done(function(data) {
  3814. if (data.error !== undefined) {
  3815. console.log(data.error);
  3816. } else {
  3817. if (createObjectLocation) {
  3818. setIconDesktopLocation(newFolderName, closestGridIndexLocation[0], closestGridIndexLocation[1], function() {
  3819. //After set Desktop icon, refresh the page
  3820. refresh(function() {
  3821. //After refresh the page, highlight the new folder and set it to rename mode
  3822. var targetFolderObject = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
  3823. console.log(targetFolderObject);
  3824. enableRenameOnLaunchIconObject(targetFolderObject);
  3825. });
  3826. });
  3827. }
  3828. }
  3829. });
  3830. /*
  3831. //Open new folder creation window
  3832. var existsingFileList = [];
  3833. for (var i =0; i < desktopFileList.length; i++){
  3834. existsingFileList.push({
  3835. filename: desktopFileList[i],
  3836. filepath: "user:/Desktop/" + desktopFileList[i]
  3837. });
  3838. }
  3839. newFloatWindow({
  3840. url: "SystemAO/file_system/newFolder.html#" + encodeURIComponent(JSON.stringify(existsingFileList)),
  3841. appicon: "SystemAO/file_system/img/new folder.png",
  3842. width:560,
  3843. height:340,
  3844. title: "New Folder"
  3845. });
  3846. */
  3847. hideAllContextMenus();
  3848. }
  3849. function enableRenameOnLaunchIconObject(object) {
  3850. renameMode = true;
  3851. $(".launchIcon").attr("draggable", "false");
  3852. var filedata = JSON.parse(decodeURIComponent($(object).attr("filedata")));
  3853. var originalName = filedata.Filename;
  3854. if (filedata.IsShortcut){
  3855. //Shortcut. Use its display name instead
  3856. originalName = filedata.ShortcutName;
  3857. }
  3858. $(object).find(".launchIconText").hide();
  3859. $(object).append(`<textarea class="renameInput ${desktopIconSize}" type="text" ondragstart="return false;" dblclick="event.stopImmediatePropagation(); event.stopImmediatePropagation();"maxlength="32">${originalName}</textarea>`);
  3860. $(object).find(".renameInput")[0].select();
  3861. var index = originalName.lastIndexOf(".");
  3862. console.log(index);
  3863. if( index >= 0){
  3864. $(object).find(".renameInput")[0].setSelectionRange(0, index);
  3865. }
  3866. //Updates 4-5-2021: Added IME support on rename input
  3867. $(object).find(".renameInput")[0].addEventListener("keydown", function(event){
  3868. if (window.ime && window.ime.handler != null){
  3869. window.ime.handler(event);
  3870. }else{
  3871. //No IME handler. Just continue the input
  3872. }
  3873. });
  3874. window.ime.focus = $(object).find(".renameInput")[0];
  3875. }
  3876. function exitRenameMode() {
  3877. if (renameMode) {
  3878. $(".launchIcon").attr("draggable", "true");
  3879. $(".launchIcon").find(".launchIconText").show();
  3880. //Update the folder to textarea content
  3881. $(".renameInput").each(function() {
  3882. if ($(this).text() == "") {
  3883. //Ignore this update
  3884. } else {
  3885. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3886. var filepath = filedata.Filepath;
  3887. var newFilename = $(this).val();
  3888. if (filedata.IsShortcut == true){
  3889. //Shortcut. Edit the shortcut content name
  3890. let currentInputTextArea = $(this);
  3891. $.ajax({
  3892. url: "/system/desktop/opr/renameShortcut",
  3893. data: {src: filepath, new: newFilename},
  3894. success: function(data){
  3895. if (data.error !== undefined){
  3896. //Cancel the operation
  3897. console.log("*ERROR* " + data.error);
  3898. currentInputTextArea.remove();
  3899. }else{
  3900. //No need to update the shortcut position (as its name not changed)
  3901. refresh(function() {
  3902. //Refresh the desktop
  3903. });
  3904. }
  3905. }
  3906. })
  3907. }else{
  3908. //Normal typed files / folder. Rename the object
  3909. let currentInputTextArea = $(this);
  3910. $.ajax({
  3911. url: "./system/file_system/fileOpr",
  3912. method: "POST",
  3913. data: {opr: "rename", src: JSON.stringify([filepath]), new: JSON.stringify([newFilename])},
  3914. success: function(data){
  3915. if (data.error !== undefined){
  3916. //Cancel the operation
  3917. console.log("*ERROR* " + data.error);
  3918. currentInputTextArea.remove();
  3919. }else{
  3920. //Update the new file position
  3921. let closestLocation = findClosestGrid($(currentInputTextArea).parent().offset().left, $(currentInputTextArea).parent().offset().top);
  3922. let closestGridIndexLocation = closestLocation[1];
  3923. setIconDesktopLocation(newFilename, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  3924. //Callback after setting location
  3925. refresh(function() {
  3926. //Refresh the desktop
  3927. });
  3928. });
  3929. }
  3930. }
  3931. });
  3932. }
  3933. }
  3934. });
  3935. renameMode = false;
  3936. }
  3937. }
  3938. //Handle opening shortcut folder location
  3939. function handleShortcutFolderOpen(object, event){
  3940. var openPendingFolders = [];
  3941. $(".launchIconWrapper.selected").each(function(){
  3942. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3943. console.log(filedata);
  3944. if (filedata.IsShortcut == true){
  3945. if (filedata.ShortcutType == "folder"){
  3946. openPendingFolders.push(filedata.ShortcutPath);
  3947. }else if (filedata.ShortcutType == "module"){
  3948. openPendingFolders.push("web:/" + filedata.ShortcutPath);
  3949. }
  3950. }
  3951. });
  3952. //Open all folders
  3953. openPendingFolders.forEach(folder => {
  3954. newFloatWindow({
  3955. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent(folder),
  3956. appicon: "SystemAO/file_system/img/small_icon.png",
  3957. width:1080,
  3958. height:580,
  3959. title: "File Manager"
  3960. });
  3961. })
  3962. hideAllContextMenus();
  3963. }
  3964. //Handle basic desktop file operations
  3965. function handleFileDelete(object, event){
  3966. var deleteFileList = [];
  3967. $(".launchIconWrapper.selected").each(function(){
  3968. var filedata = JSON.parse(decodeURIComponent($(this).parent().attr("filedata")));
  3969. deleteFileList.push(filedata.Filepath);
  3970. });
  3971. console.log(deleteFileList);
  3972. $.ajax({
  3973. url: "system/file_system/fileOpr",
  3974. method:"POST",
  3975. data: {opr: "recycle", src: JSON.stringify(deleteFileList)},
  3976. success: function(data){
  3977. if (data.error !== undefined){
  3978. alert(data.error);
  3979. }else{
  3980. refresh(undefined, true);
  3981. }
  3982. }
  3983. });
  3984. hideAllContextMenus();
  3985. }
  3986. //File Rename
  3987. let renamingItems = [];
  3988. function handleRename(object, event){
  3989. if ($('.launchIconWrapper.selected').length > 0){
  3990. //Enter rename mode
  3991. renamingItems = $('.launchIconWrapper.selected');
  3992. let renameTarget = $('.launchIconWrapper.selected')[0]
  3993. let fileObject = $(renameTarget).parent();
  3994. enableRenameOnLaunchIconObject(fileObject);
  3995. }
  3996. hideAllContextMenus();
  3997. }
  3998. //New item menus.
  3999. function newitemmenu(target, event) {
  4000. $("#subcontextmenu").html("");
  4001. //Append the new folder option first
  4002. addContextMenuItem($("#subcontextmenu"), 'Folder', "<i class='folder icon'></i>", "newfolder", true);
  4003. addContextMenuItem($("#subcontextmenu"), 'Shortcut', "<i class='external icon'></i>", "newshortcut", true);
  4004. addContextMenuSeperator($("#subcontextmenu"));
  4005. $.get("system/file_system/newItem", function(data) {
  4006. for (var i = 0; i < data.length; i++) {
  4007. var thisNewFile = data[i];
  4008. var icon = ao_module_utils.getIconFromExt(thisNewFile.Ext);
  4009. addContextMenuItem($("#subcontextmenu"), `<i class="${icon} icon" ext="${thisNewFile.Ext}"></i> ${thisNewFile.Desc}`, undefined, "newitem");
  4010. }
  4011. //Show sub-context menu
  4012. showSubContextMenu(target);
  4013. });
  4014. }
  4015. function showSubContextMenu(target) {
  4016. $("#subcontextmenu").show();
  4017. var targetLeft = $("#contextmenu").offset().left + $("#contextmenu").width() + 2;
  4018. var targetTop = $(target).offset().top - 1;
  4019. if (targetLeft + $("#subcontextmenu").width() > window.innerWidth){
  4020. //Overflow. Swtich to the left side of the menu
  4021. targetLeft = $("#contextmenu").offset().left - $("#subcontextmenu").width() - 2;
  4022. }
  4023. $("#subcontextmenu").css({
  4024. left: targetLeft,
  4025. top: targetTop
  4026. });
  4027. }
  4028. //Create new file item with that filename
  4029. function newitem(object, event) {
  4030. var extension = $(object).find("i").attr("ext");
  4031. //Generate a newfile name
  4032. var newfn = "NewFile" + "." + extension;
  4033. var counter = 1;
  4034. while (desktopFileList.includes(newfn)){
  4035. newfn = "NewFile (" + counter + ")." + extension;
  4036. counter++;
  4037. }
  4038. //Get the location position
  4039. let closestLocation = findClosestGrid(menuStartLocation[0], menuStartLocation[1], false);
  4040. let closestGridIndexLocation = closestLocation[1];
  4041. //Request backend to generate the new file
  4042. $.ajax({
  4043. url: "system/file_system/newItem",
  4044. data: {type: "file",src: "user:/Desktop/",filename: newfn},
  4045. success: function(data){
  4046. if (data.error !== undefined){
  4047. alert(data.error);
  4048. }else{
  4049. //Set the icon location
  4050. setIconDesktopLocation(newfn, closestGridIndexLocation[0], closestGridIndexLocation[1], function(){
  4051. //Refresh the desktop
  4052. refresh(function(){
  4053. var targetNewFile = getObjectFromGridLocation(closestGridIndexLocation[0], closestGridIndexLocation[1]);
  4054. console.log("Renaming ", targetNewFile);
  4055. enableRenameOnLaunchIconObject(targetNewFile);
  4056. });
  4057. });
  4058. }
  4059. }
  4060. });
  4061. hideAllContextMenus();
  4062. }
  4063. document.getElementById("volumebar").parentNode.addEventListener("touchstart", function(e){
  4064. updateVolume( document.getElementById("volumebar").parentNode, e);
  4065. });
  4066. function getCoordinateFromEvent(e){
  4067. var x = -1;
  4068. var y = -1;
  4069. if (e.originalEvent == undefined){
  4070. e.originalEvent = e;
  4071. }
  4072. if(e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel'){
  4073. var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
  4074. x = touch.pageX;
  4075. y = touch.pageY;
  4076. } else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
  4077. x = e.clientX;
  4078. y = e.clientY;
  4079. }else{
  4080. x = e.clientX;
  4081. y = e.clientY;
  4082. }
  4083. return [x,y];
  4084. }
  4085. function updateVolume(object, event){
  4086. var width = $(object).width();
  4087. var left = $(object).offset().left;
  4088. var clickPosition = getCoordinateFromEvent(event)[0];
  4089. var clickRel = clickPosition - left;
  4090. var percentage = clickRel / width * 100;
  4091. if (percentage < 0){
  4092. percentage = 0;
  4093. }else if (percentage > 100){
  4094. percentage = 100;
  4095. }
  4096. //Update the global volume
  4097. $(object).find(".bar").css("width",percentage + "%");
  4098. localStorage.setItem("global_volume", clickRel / width);
  4099. }
  4100. function refresh(callback = undefined, noflash=false) {
  4101. //Refresh desktop contents
  4102. let launchOption = {};
  4103. if (noflash){
  4104. launchOption = {
  4105. noflash: true
  4106. };
  4107. }else{
  4108. $(".launchIcon").remove();
  4109. }
  4110. if (callback == undefined) {
  4111. initDesktopFiles(launchOption);
  4112. } else {
  4113. initDesktopFiles(launchOption, callback);
  4114. }
  4115. hideAllContextMenus();
  4116. }
  4117. function openfm() {
  4118. //Open file explorer on desktop
  4119. newFloatWindow({
  4120. url: "SystemAO/file_system/file_explorer.html#" + encodeURIComponent("user:/Desktop"),
  4121. appicon: "SystemAO/file_system/img/small_icon.png",
  4122. width: 1080,
  4123. height: 580,
  4124. title: "File Manager"
  4125. });
  4126. hideAllContextMenus();
  4127. }
  4128. /*
  4129. Notification and Notification bar related functions
  4130. Usage:
  4131. title -> The title of the notification
  4132. content -> The content of the notification
  4133. icon (optional) -> The icon of the notification
  4134. windowOpenOption (optional) -> The window opening option for user onclick redirection
  4135. */
  4136. function sendNotification(title, content, icon="notice circle", windowOpenOption=null){
  4137. if (content.length > 100){
  4138. shortenContent = content.substring(0,100) + "...";
  4139. }else{
  4140. shortenContent = content;
  4141. }
  4142. onClickOpenWindowOption = encodeURIComponent(JSON.parse(windowOpenOption));
  4143. $("#notificationlist").append(` <div class="notification object" originalcontent="${content}" redirect="${onClickOpenWindowOption}" onclick="openNotification(this);">
  4144. <p class="title"><i class="${icon} icon"></i> ${title}</p>
  4145. <p class="notifycontent">${shortenContent}</p>
  4146. <div class="closebtn" onclick="event.stopImmediatePropagation(); closeThisNotification(this);"><i class="remove icon"></i></div>
  4147. <div class="ts divider"></div>
  4148. </div>`);
  4149. $(".nonotification").hide();
  4150. }
  4151. function openNotification(obj){
  4152. newWindowOpeningOption = JSON.parse(decodeURIComponent($(obj).attr("redirect")));
  4153. if (newWindowOpeningOption == null){
  4154. //Ignore
  4155. }else{
  4156. //Start a floatWindow to the given target
  4157. newFloatWindow(newWindowOpeningOption);
  4158. }
  4159. //Clear the notiication
  4160. closeThisNotification($(obj).find(".closebtn"));
  4161. }
  4162. function closeThisNotification(obj){
  4163. $(obj).parent().slideUp("fast",function(data){
  4164. $(this).remove();
  4165. if ($(".notification.object").length == 0){
  4166. $(".nonotification").show();
  4167. }
  4168. });
  4169. }
  4170. function clearAllNotification(){
  4171. $(".notification.object").slideUp('fast',function(data){
  4172. $(this).remove();
  4173. $(".nonotification").show();
  4174. });
  4175. }
  4176. function hideAllContextMenus() {
  4177. $("#subcontextmenu").hide();
  4178. $("#contextmenu").hide()
  4179. $("#quickAccessPanel").slideUp("fast");
  4180. }
  4181. function restart(){
  4182. if (!hardwareman){
  4183. return
  4184. }
  4185. if (confirm("Confirm Restart?")){
  4186. $.ajax({
  4187. url: "system/power/restart",
  4188. success: function(data){
  4189. if (data.error !== undefined){
  4190. alert(data.error);
  4191. }
  4192. },
  4193. error: function(){
  4194. }
  4195. });
  4196. }
  4197. }
  4198. function shutdown(){
  4199. if (!hardwareman){
  4200. return
  4201. }
  4202. if (confirm("Confirm Poweroff?")){
  4203. $.ajax({
  4204. url: "system/power/shutdown",
  4205. success: function(data){
  4206. if (data.error !== undefined){
  4207. alert(data.error);
  4208. }else{
  4209. //Shutdown suceed
  4210. }
  4211. },
  4212. error: function(){
  4213. //Shutdown suceed
  4214. }
  4215. });
  4216. }
  4217. }
  4218. function uploadFile(file, callback=undefined) {
  4219. let url = 'system/file_system/upload'
  4220. let uploadCurrentPath = "user:/Desktop/";
  4221. let formData = new FormData()
  4222. let xhr = new XMLHttpRequest()
  4223. formData.append('file', file);
  4224. formData.append('path', uploadCurrentPath);
  4225. xhr.open('POST', url, true)
  4226. xhr.upload.addEventListener("progress", function(e) {
  4227. console.log((e.loaded * 100.0 / e.total) || 100)
  4228. })
  4229. xhr.addEventListener('readystatechange', function(e) {
  4230. if (xhr.readyState == 4 && xhr.status == 200) {
  4231. if (callback !== undefined){
  4232. callback(e.target.response);
  4233. }
  4234. }
  4235. else if (xhr.readyState == 4 && xhr.status != 200) {
  4236. console.log("Upload failed :" + xhr.status);
  4237. }
  4238. })
  4239. xhr.send(formData);
  4240. }
  4241. function setStorage(key, value, callback = undefined) {
  4242. $.get("system/desktop/preference?preference=" + key + "&value=" + value, function(data) {
  4243. if (data.error !== undefined) {
  4244. console.log(data.error);
  4245. } else {
  4246. if (callback !== undefined) {
  4247. callback();
  4248. }
  4249. }
  4250. });
  4251. }
  4252. function getStorage(key, callback) {
  4253. $.get("system/desktop/preference?preference=" + key, callback);
  4254. }
  4255. function showSystemSettings(){
  4256. var hasAccessToSetting = false;
  4257. moduleInstalled.forEach(thismod => {
  4258. if (thismod.Name == "System Setting"){
  4259. openModule("System Setting");
  4260. }
  4261. })
  4262. }
  4263. function initTheme(targetTheme=undefined){
  4264. if (targetTheme == undefined){
  4265. $.get("../../system/file_system/preference?key=file_explorer/theme", function(data){
  4266. if (data == "darkTheme"){
  4267. setDarkTheme();
  4268. }
  4269. });
  4270. }else{
  4271. //Manual override mode
  4272. if (targetTheme == "darkTheme"){
  4273. setDarkTheme();
  4274. }else if (targetTheme == "whiteTheme"){
  4275. setWhiteTheme();
  4276. }
  4277. }
  4278. }
  4279. function setFloatWindowTheme(fwid, theme="dark"){
  4280. var targetFW = getFloatWindowByID(fwid);
  4281. if (theme == "dark"){
  4282. $(targetFW).removeClass("white");
  4283. }else if (theme == "white"){
  4284. $(targetFW).addClass("white");
  4285. }
  4286. }
  4287. function checkFileSystemAccess(){
  4288. var allowReadWrite = false;
  4289. moduleInstalled.forEach(thisModule => {
  4290. if (thisModule.Name == "File Manager"){
  4291. //This user has read write access to file system
  4292. allowReadWrite = true;
  4293. }
  4294. });
  4295. if (!allowReadWrite){
  4296. sendNotification("READ ONLY Account", "This account is read only. You cannot perform any file operations on this desktop.");
  4297. }
  4298. }
  4299. function setDarkTheme(){
  4300. $("#listMenu").addClass("darkTheme");
  4301. $("#powerIcon").attr("src","img/system/power-white.svg");
  4302. $("#quickAccessPanel").addClass("darkTheme");
  4303. $("#quickAccessPanel").find(".button").addClass("inverted");
  4304. }
  4305. function setWhiteTheme(){
  4306. $("#listMenu").removeClass("darkTheme");
  4307. $("#powerIcon").attr("src","img/system/power.svg");
  4308. $("#quickAccessPanel").removeClass("darkTheme");
  4309. $("#quickAccessPanel").find(".button").removeClass("inverted");
  4310. }
  4311. function hexToRgbA(hex, transparent=1){
  4312. var c;
  4313. if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
  4314. c= hex.substring(1).split('');
  4315. if(c.length== 3){
  4316. c= [c[0], c[0], c[1], c[1], c[2], c[2]];
  4317. }
  4318. c= '0x'+c.join('');
  4319. return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',' + transparent + ')';
  4320. }
  4321. throw new Error('Bad Hex');
  4322. }
  4323. function setThemeColor(newThemeColor){
  4324. //Update the global theme color
  4325. desktopThemeColor = newThemeColor;
  4326. //Update the related elements
  4327. $("#statusbar").css("background-color",newThemeColor);
  4328. $("#navimenu").css("background-color",hexToRgbA(newThemeColor, 0.5));
  4329. $(".floatWindow .controls").css("background-color",hexToRgbA(newThemeColor, 0.85));
  4330. //List menu theme color bar
  4331. $("#listMenu").find(".searchBar").css("border-bottom", "2px solid " + newThemeColor);
  4332. $("#volumebar").css("background-color", newThemeColor);
  4333. }
  4334. //Load the user define theme color to overwrite the default color if exists
  4335. function initUserDefinedThemeColor(){
  4336. $.ajax({
  4337. url: "../../system/file_system/preference",
  4338. data: {key: "themecolor"},
  4339. success: function(data){
  4340. if (data.error == undefined && data != ""){
  4341. setThemeColor(data);
  4342. }
  4343. }
  4344. });
  4345. }
  4346. //Float Window context menu
  4347. function getFocusedFloatWindowID(){
  4348. var targetFloatWindowId = "";
  4349. $(".floatWindow").each(function() {
  4350. var thisWindowZIndex = $(this).css("z-index");
  4351. if (parseInt(thisWindowZIndex) == 101){
  4352. targetFloatWindowId = $(this).attr("windowid");
  4353. }
  4354. });
  4355. return targetFloatWindowId;
  4356. }
  4357. function getFocusedFloatWindow(){
  4358. var focusedFwId = getFocusedFloatWindowID();
  4359. if (focusedFwId != ""){
  4360. var fw = getFloatWindowByID(focusedFwId);
  4361. return fw;
  4362. }else{
  4363. return undefined;
  4364. }
  4365. }
  4366. function refreshSelectedFloatWindow(target, event){
  4367. var fw = getFocusedFloatWindow();
  4368. if (fw != undefined){
  4369. $(fw).find("iframe")[0].contentWindow.location.reload();
  4370. }
  4371. hideAllContextMenus();
  4372. }
  4373. function maximizeSelectedFloatWindow(target, event){
  4374. var fw = getFocusedFloatWindow();
  4375. if (fw != undefined){
  4376. toggleMax($(fw).find(".buttons.maxtoggle"),event);
  4377. }
  4378. hideAllContextMenus();
  4379. }
  4380. function minimizeSelectedFloatWindow(target, event){
  4381. var fw = getFocusedFloatWindow();
  4382. if (fw != undefined){
  4383. min($(fw).find(".buttons.mintoggle"),event);
  4384. }
  4385. hideAllContextMenus();
  4386. }
  4387. function openSelectedFloatWindowInNewTab(){
  4388. var fw = getFocusedFloatWindow();
  4389. if (fw != undefined){
  4390. var currentURL = $(fw).find("iframe")[0].contentWindow.location;
  4391. window.open(currentURL);
  4392. }
  4393. hideAllContextMenus();
  4394. }
  4395. function closeSelectedFloatWindow(target, event){
  4396. var fw = getFocusedFloatWindow();
  4397. if (fw != undefined){
  4398. closeFloatWindow($(fw).find(".buttons.closetoggle"),event);
  4399. }
  4400. hideAllContextMenus();
  4401. }
  4402. function fullscreen() {
  4403. //Opening full screen will lead to hidden of all iframe for unknown reasons
  4404. var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
  4405. (document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
  4406. (document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
  4407. (document.msFullscreenElement && document.msFullscreenElement !== null);
  4408. var elem = document.documentElement;
  4409. if (!isInFullScreen) {
  4410. if (elem.requestFullscreen) {
  4411. elem.requestFullscreen();
  4412. } else if (elem.mozRequestFullScreen) { /* Firefox */
  4413. elem.mozRequestFullScreen();
  4414. } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
  4415. elem.webkitRequestFullscreen();
  4416. } else if (elem.msRequestFullscreen) { /* IE/Edge */
  4417. elem.msRequestFullscreen();
  4418. }
  4419. } else {
  4420. if (document.exitFullscreen) {
  4421. document.exitFullscreen();
  4422. } else if (document.webkitExitFullscreen) {
  4423. document.webkitExitFullscreen();
  4424. } else if (document.mozCancelFullScreen) {
  4425. document.mozCancelFullScreen();
  4426. } else if (document.msExitFullscreen) {
  4427. document.msExitFullscreen();
  4428. }
  4429. }
  4430. hideAllContextMenus();
  4431. }
  4432. /*
  4433. Background services for keeping desktop files updated
  4434. Same mechanism is used as file explorer
  4435. */
  4436. let desktopFileHash = "";
  4437. setInterval(function(){
  4438. getDesktopHash(function(hash){
  4439. if (desktopFileHash == ""){
  4440. //Initialization
  4441. desktopFileHash = hash;
  4442. }else if (desktopFileHash != hash){
  4443. //Changed on desktop files. Refresh
  4444. refresh();
  4445. desktopFileHash = hash;
  4446. }
  4447. //Else, no file change on desktop
  4448. });
  4449. }, 15000);
  4450. function getDesktopHash(callback){
  4451. $.ajax({
  4452. url: "../../system/file_system/listDirHash",
  4453. data: {dir: "user:/Desktop/"},
  4454. success: function(data){
  4455. if (data.error !== undefined){
  4456. }
  4457. callback(data);
  4458. }
  4459. })
  4460. }
  4461. function bindObjectToIMEEvents(object){
  4462. object.addEventListener("keydown", function(event){
  4463. if (window.ime && window.ime.handler != null){
  4464. window.ime.handler(event);
  4465. }else{
  4466. //No IME handler. Just continue the input
  4467. }
  4468. });
  4469. object.addEventListener("focus", function(event){
  4470. if (window.ime){
  4471. //IME exists. Set this field to focused field
  4472. window.ime.focus = event.target;
  4473. }
  4474. });
  4475. }
  4476. </script>
  4477. </body>
  4478. </html>