mobile.system 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. <html>
  2. <head>
  3. <title>ArozOS Mobile</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link rel="manifest" href="manifest.webmanifest">
  7. <link rel="stylesheet" href="script/semantic/semantic.css">
  8. <link rel="stylesheet" href="script/ao.css">
  9. <script type="text/javascript" src="script/jquery.min.js"></script>
  10. <script type="text/javascript" src="script/semantic/semantic.js"></script>
  11. <script type="text/javascript" src="script/ao_module.js"></script>
  12. <style>
  13. document, body{
  14. height: 100%;
  15. }
  16. .themeColor{
  17. background-color:#1c1c1c;
  18. }
  19. .taskBar{
  20. position:fixed;
  21. top:0px;
  22. left:0px;
  23. width:30px;
  24. height:100%;
  25. overflow: visible !important;
  26. z-index:999;
  27. }
  28. #mainFrame{
  29. width: calc(100% - 30px);
  30. position:fixed;
  31. top:0px;
  32. right:0px;
  33. overflow: hidden;
  34. }
  35. .toggleTaskBar{
  36. position:absolute;
  37. bottom:0px;
  38. right:0px;
  39. margin-right:-20px;
  40. width:30px;
  41. height:90px;
  42. border-radius: 0px 10px 10px 0px;
  43. }
  44. #listMenu{
  45. z-index:1000;
  46. position:fixed;
  47. top:0px;
  48. left:0px;
  49. width:100%;
  50. height:100%;
  51. padding:12px;
  52. background-color: #fcffff;
  53. box-shadow: 3px 3px 5px 0px rgba(207, 207, 207, 0.37);
  54. }
  55. #listMenu .searchBar {
  56. width: 100%;
  57. border-bottom: 2px solid #34b7eb;
  58. }
  59. #listMenu .listItemWrapper {
  60. overflow: hidden;
  61. }
  62. #listMenu .listItemWrapper .groups {
  63. background-color: #f5f5f5;
  64. width: 120px;
  65. height: calc(100% - 40px);
  66. display: inline-block;
  67. overflow-y: auto;
  68. padding-top: 8px;
  69. }
  70. #listMenu .listItemWrapper .groups .item {
  71. padding-left: 7px;
  72. padding-bottom: 6px;
  73. padding-top: 6px;
  74. cursor: pointer;
  75. }
  76. #listMenu .listItemWrapper .groups .item.selected {
  77. color: #34b7eb;
  78. }
  79. #listMenu .listItemWrapper .groups .item:hover {
  80. background-color: #dedede;
  81. }
  82. #listMenuItem{
  83. width: calc(100% - 130px) !important;
  84. float: right;
  85. overflow-y: auto;
  86. height: calc(100% - 40px) !important;
  87. }
  88. #listMenuItem img{
  89. width: 50px;
  90. }
  91. .module.item{
  92. padding:8px;
  93. }
  94. .hideListMenuButton{
  95. position: absolute;
  96. bottom:22px;
  97. left:32px;
  98. cursor:pointer;
  99. }
  100. .hideListMenuButton img{
  101. left:12px;
  102. width:50px;
  103. }
  104. .listMenuLauncher{
  105. position:absolute;
  106. bottom:12px;
  107. left:12px;
  108. cursor:pointer;
  109. }
  110. .blurred{
  111. filter: blur(3px);
  112. }
  113. #backdrop {
  114. background-repeat: no-repeat;
  115. background-size: cover;
  116. background-position: center;
  117. background-image: url('img/desktop/bg/init.jpg');
  118. width: 100%;
  119. height: 100%;
  120. overflow-x: hidden;
  121. pointer-events: none;
  122. }
  123. #windowButtonWrapper{
  124. padding-top:6px;
  125. }
  126. .floatWindowButton{
  127. padding: 5px;
  128. }
  129. .floatWindowButton .minimizedIcon{
  130. width: 20px;
  131. height:20px;
  132. }
  133. .floatWindowButton .normalElements{
  134. padding:8px;
  135. border-bottom: 1px solid #4a4a4a;
  136. cursor:pointer;
  137. vertical-align:middle;
  138. position: relative;
  139. }
  140. .floatWindowButton .normalizedIcon{
  141. width:40;
  142. height:40px;
  143. margin-right:12px;
  144. }
  145. .normalElements .windowTitle{
  146. display:inline-block;
  147. width:200px !important;
  148. vertical-align:middle;
  149. white-space: nowrap;
  150. overflow: hidden;
  151. text-overflow: ellipsis;
  152. }
  153. .fwtab{
  154. position: absolute;
  155. top:0px;
  156. right: 0px;
  157. width: 100%;
  158. height: 100%;
  159. }
  160. #windowWrapper{
  161. height: 100%;
  162. width: 100%;
  163. position: absolute;
  164. top:0px;
  165. right:0px;
  166. }
  167. .floatWindowWrapper{
  168. width: 100%;
  169. height: 100%;
  170. }
  171. .floatWindow{
  172. width: 100%;
  173. height: 100%;
  174. position: absolute;
  175. }
  176. .fwtab iframe{
  177. border: 0px solid transparent;
  178. height: 100%;
  179. }
  180. .floatWindowButton .closebutton{
  181. position: absolute;
  182. font-size: 120%;
  183. color:white;
  184. right: 0em;
  185. top: 0px;
  186. margin-top: -8px;
  187. margin-left: -4px;
  188. padding: 3px;
  189. }
  190. .floatWindowButton .externalbutton{
  191. position: absolute;
  192. font-size: 120%;
  193. color:white;
  194. right: 1.6em;
  195. top: 0px;
  196. margin-top: -8px;
  197. margin-left: -4px;
  198. padding: 3px;
  199. }
  200. #conndrop{
  201. padding: 0.5em;
  202. position: fixed;
  203. top: 0px;
  204. right: 0px;
  205. z-index: 115;
  206. width: 100px;
  207. display: none;
  208. justify-content: flex-end;
  209. pointer-events: none;
  210. }
  211. /* Magic css to make the connection logo blink */
  212. @-moz-keyframes blink {
  213. 0% {
  214. opacity:1;
  215. }
  216. 50% {
  217. opacity:0;
  218. }
  219. 100% {
  220. opacity:1;
  221. }
  222. }
  223. @-webkit-keyframes blink {
  224. 0% {
  225. opacity:1;
  226. }
  227. 50% {
  228. opacity:0;
  229. }
  230. 100% {
  231. opacity:1;
  232. }
  233. }
  234. /* IE */
  235. @-ms-keyframes blink {
  236. 0% {
  237. opacity:1;
  238. }
  239. 50% {
  240. opacity:0;
  241. }
  242. 100% {
  243. opacity:1;
  244. }
  245. }
  246. /* Opera and prob css3 final iteration */
  247. @keyframes blink {
  248. 0% {
  249. opacity:1;
  250. }
  251. 50% {
  252. opacity:0;
  253. }
  254. 100% {
  255. opacity:1;
  256. }
  257. }
  258. .blink-image {
  259. -moz-animation: blink normal 2s infinite ease-in-out; /* Firefox */
  260. -webkit-animation: blink normal 2s infinite ease-in-out; /* Webkit */
  261. -ms-animation: blink normal 2s infinite ease-in-out; /* IE */
  262. animation: blink normal 2s infinite ease-in-out; /* Opera and prob css3 final iteration */
  263. }
  264. #sidebarToggleOverlay{
  265. width: 100%;
  266. height: 100%;
  267. z-index: 995;
  268. position: fixed;
  269. top:0px;
  270. left:0px;
  271. display:none;
  272. }
  273. </style>
  274. </head>
  275. <body>
  276. <div class="taskBar themeColor" >
  277. <div class="toggleTaskBar themeColor" shown="false" onclick="toggleTaskBar(this);">
  278. <img class="ui image sidebararrow" style="margin-top:8px; margin-left: -10px;" src="img/mobile/keyboard_arrow_right-white-48dp.svg"></img>
  279. </div>
  280. <div class="listMenuLauncher" onclick="showListMenu();">
  281. <img src="img/mobile/apps-white-48dp.svg" style="width: 30px;"/>
  282. </div>
  283. <div id="windowButtonWrapper">
  284. </div>
  285. </div>
  286. <div id="listMenu" style="left:-100%;">
  287. <div class="searchBar" onkeydown="searchModule(event);">
  288. <div class="ui icon fluid input" style="border-radius: 0px !important;">
  289. <input id="searchBar" type="text" placeholder="Search">
  290. <i class="search icon"></i>
  291. </div>
  292. </div>
  293. <dib class="listItemWrapper">
  294. <div class="groups">
  295. <div id="searchResults" class="item" style="display:none;">Search Results</div>
  296. <div class="item groupType selected" group="All">All</div>
  297. <div class="item groupType" group="Media">Media</div>
  298. <div class="item groupType" group="Office">Office</div>
  299. <div class="item groupType" group="Download">Download</div>
  300. <div class="item groupType" group="Files">Files</div>
  301. <div class="item groupType" group="Internet">Internet</div>
  302. <div class="item groupType" group="System Settings">System Settings</div>
  303. <div class="item groupType" group="System Tools">System Tools</div>
  304. <div class="item groupType" group="Utilities">Utilities</div>
  305. <div class="item groupType" group="Other">Other</div>
  306. <div class="hideListMenuButton" onclick="closeListMenu();">
  307. <img class="ui image" src="img/mobile/cancel-black-48dp.svg"></img>
  308. <p>Close Menu</p>
  309. </div>
  310. </div>
  311. <div id="listMenuItem" class="items" align="left">
  312. </div>
  313. </div>
  314. </div>
  315. <div id="mainFrame">
  316. <div id="backdrop">
  317. </div>
  318. <div id="windowWrapper">
  319. </div>
  320. <div id="conndrop">
  321. <img class="ui mini image blink-image" src="SystemAO/desktop/icons/connlost.svg">
  322. </div>
  323. </div>
  324. <div id="sidebarToggleOverlay"></div>
  325. <script>
  326. var isDesktopMode = true; //Try to emulate Desktop mode
  327. var moduleInstalled = []; //List of installed modules on the system
  328. var desktopThemeList = []; //List of themes installed, same as desktop theme
  329. var listMenuShown = false;
  330. var hostInfo;
  331. //initiation Functions
  332. initHostInfo();
  333. initModuleList();
  334. bindGroupTypeEvents();
  335. initBackdropImage();
  336. initUserDefinedThemeColor();
  337. bindBackgroundClickActions();
  338. //Bind background click
  339. function bindBackgroundClickActions(){
  340. $("#mainFrame").on("touchstart click", function(evt){
  341. if ($(this).hasClass("blurred") && $(".taskBar").find(".toggleTaskBar").attr("shown") == "true"){
  342. //hide the taskbar
  343. hideTaskBar();
  344. }
  345. });
  346. $("#sidebarToggleOverlay").on("touchstart click", function(evt){
  347. if ($(".taskBar").find(".toggleTaskBar").attr("shown") == "true"){
  348. //hide the taskbar
  349. evt.preventDefault();
  350. hideTaskBar();
  351. }
  352. });
  353. }
  354. //Connection check
  355. setInterval(function() {
  356. $.ajax({
  357. url: 'system/auth/checkLogin',
  358. success: function(data) {
  359. if (data == true) {
  360. //Continue session
  361. } else {
  362. //Session timeout. Redirect to system index
  363. window.location.href = "index.html";
  364. }
  365. $("#conndrop").hide();
  366. $("#conndrop").css("display", "none");
  367. },
  368. error: function(evt) {
  369. //Server closed or freezed?
  370. $("#conndrop").show();
  371. $("#conndrop").css("display", "flex");
  372. },
  373. timeout: 15000
  374. });
  375. }, 15000);
  376. //Initiate the host information
  377. function initHostInfo(){
  378. $.get("system/desktop/host",function(data){
  379. hostInfo = data;
  380. document.title = hostInfo.Hostname;
  381. });
  382. }
  383. //Initialize background image
  384. function initBackdropImage(){
  385. $.get("system/desktop/theme", function(data) {
  386. //Return a list of theme stored on the system
  387. desktopThemeList = data;
  388. $.get("system/desktop/theme?get=true", function(data) {
  389. //Get the user theme settings
  390. changeDesktopTheme(data);
  391. });
  392. });
  393. }
  394. function initUserDefinedThemeColor(){
  395. $.ajax({
  396. url: "../../system/file_system/preference",
  397. data: {key: "themecolor"},
  398. success: function(data){
  399. if (data.error == undefined && data != ""){
  400. $(".themeColor").css("background-color", data);
  401. }
  402. }
  403. });
  404. }
  405. function changeDesktopTheme(themename){
  406. //Match the given theme to the themename
  407. if (themename.includes(":/") == false){
  408. //This is a path
  409. for (var i =0; i < desktopThemeList.length ; i++){
  410. if (desktopThemeList[i].Theme == themename){
  411. var targetImage = desktopThemeList[i].Bglist[0];
  412. $("#backdrop").css("background-image", `url(img/desktop/bg/${themename}/${targetImage})`)
  413. }
  414. }
  415. }else{
  416. //This is a path (user defined background folder)
  417. $.get("system/desktop/theme?load=" + themename, function(data){
  418. if (data.error !== undefined){
  419. //The folder is gone. Use default instead
  420. console.log(data.error);
  421. changeDesktopTheme("default");
  422. }else{
  423. $("#backdrop").css("background-image", `url(media/?file=${data[0]})`)
  424. }
  425. });
  426. }
  427. }
  428. function toggleFullScreen() {
  429. var doc = window.document;
  430. var docEl = doc.documentElement;
  431. var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
  432. var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;
  433. if(!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
  434. requestFullScreen.call(docEl);
  435. }
  436. else {
  437. cancelFullScreen.call(doc);
  438. }
  439. }
  440. //Sidebar
  441. function toggleTaskBar(obj){
  442. if ($(obj).attr("shown") == "true"){
  443. hideTaskBar();
  444. }else{
  445. showTaskBar();
  446. }
  447. }
  448. function hideTaskBar(){
  449. //Hide the taskBar
  450. $(".taskBar").animate({
  451. width: "30px"
  452. },300, "swing");
  453. $(".taskBar").find('.sidebararrow').attr("src","img/mobile/keyboard_arrow_right-white-48dp.svg");
  454. $(".taskBar").find(".toggleTaskBar").attr("shown","false");
  455. $("#mainFrame").removeClass("blurred");
  456. //Minimize all fwbuttons
  457. $(".floatWindowButton").each(function(){
  458. $(this).find(".minimizedElements").show();
  459. $(this).find(".normalElements").hide();
  460. });
  461. $("#sidebarToggleOverlay").hide();
  462. }
  463. function showTaskBar(){
  464. //Show the taskbar
  465. $(".taskBar").animate({
  466. width: "300px"
  467. }, 300, "swing", function(){
  468. //Switch all fwbuttons to normal size
  469. $(".floatWindowButton").each(function(){
  470. $(this).find(".minimizedElements").hide();
  471. $(this).find(".normalElements").show();
  472. });
  473. });
  474. $(".taskBar").find('.sidebararrow').attr("src","img/mobile/keyboard_arrow_left-white-48dp.svg");
  475. $(".taskBar").find(".toggleTaskBar").attr("shown","true");
  476. $("#mainFrame").addClass("blurred");
  477. $("#sidebarToggleOverlay").show();
  478. }
  479. //List all modules
  480. function initModuleList(){
  481. $.ajax({
  482. url: "system/modules/list",
  483. success: function(data) {
  484. moduleInstalled = data;
  485. listModulesType("All");
  486. }
  487. });
  488. }
  489. //ListMenu group classification events
  490. function bindGroupTypeEvents(){
  491. $(".groupType").on("click",function(evt){
  492. //Clear all serach results
  493. $("#searchResults").slideUp('fast');
  494. listModulesType($(this).attr("group"));
  495. $(".groupType.selected").removeClass("selected");
  496. $(this).addClass("selected");
  497. /*
  498. var classificationObject = this;
  499. if ($(this).attr("group") == "All"){
  500. $('.item.module').show();
  501. } else if ($(this).attr("group") == "Other"){
  502. var excludeList = ["Media", "Office", "Download", "Files", "Internet", "System Settings", "System Tools", "Utilties"];
  503. $('.item.module').each(function(){
  504. if (excludeList.includes($(this).attr("group")) == false){
  505. $(this).show();
  506. }else{
  507. $(this).hide();
  508. }
  509. });
  510. }else{
  511. $('.item.module').each(function(){
  512. if ($(this).attr("group") == $(classificationObject).attr("group")){
  513. $(this).show();
  514. }else{
  515. $(this).hide();
  516. }
  517. });
  518. }
  519. */
  520. });
  521. }
  522. function searchModule(event) {
  523. if (event.which == 13) {
  524. var keyword = $("#searchBar").val().toLowerCase();
  525. var results = [];
  526. var lessAccurateResults = [];
  527. $(".groupType.selected").removeClass("selected");
  528. $("#searchResults").addClass("selected").slideDown('fast');
  529. //Load all search results
  530. for (var i = 0; i < moduleInstalled.length; i++) {
  531. var thisModule = moduleInstalled[i];
  532. var pathInfo = thisModule["StartDir"].split("/");
  533. for (var j = 0; j < pathInfo.length; j++) {
  534. pathInfo[j] = pathInfo[j].toLowerCase();
  535. }
  536. if (thisModule["Name"].toLowerCase().includes(keyword)) {
  537. results.push(thisModule);
  538. } else if (pathInfo.includes(keyword.toLowerCase()) || pathInfo.includes(keyword.split(" ").join("_").toLowerCase())) {
  539. lessAccurateResults.push(thisModule);
  540. }
  541. }
  542. results = results.concat(lessAccurateResults);
  543. //Append the results to list
  544. $("#listMenuItem").html("");
  545. for (var i = 0; i < results.length; i++) {
  546. generateListMenuItem(results[i]);
  547. }
  548. if (results.length == 0) {
  549. //Append a custom no results div to the content
  550. $("#listMenuItem").append(`<div class="item module"><span><img class="ui middle aligned tiny image" src="img/system/not found.png" style="padding-right: 12px;">No Results</span></div>`);
  551. }
  552. }
  553. }
  554. function listModulesType(groupType) {
  555. var listingItems = [];
  556. if (groupType == "All") {
  557. //List all of the items
  558. for (var i = 0; i < moduleInstalled.length; i++) {
  559. if (moduleInstalled[i]["StartDir"] != "") {
  560. listingItems.push(moduleInstalled[i]);
  561. }
  562. }
  563. } else if (groupType == "Other") {
  564. var excludeList = ["Media", "Office", "Download", "Files", "Internet", "System Settings", "System Tools", "Utilties"];
  565. //List the Other groups
  566. for (var i = 0; i < moduleInstalled.length; i++) {
  567. if (excludeList.includes(moduleInstalled[i]["Group"]) == false && moduleInstalled[i]["StartDir"] != "") {
  568. listingItems.push(moduleInstalled[i]);
  569. }
  570. }
  571. } else {
  572. //List the given group
  573. for (var i = 0; i < moduleInstalled.length; i++) {
  574. if (moduleInstalled[i]["Group"] == groupType && moduleInstalled[i]["StartDir"] != "") {
  575. listingItems.push(moduleInstalled[i]);
  576. }
  577. }
  578. }
  579. //List the item to the listmenu
  580. $("#listMenuItem").html("");
  581. for (var i = 0; i < listingItems.length; i++) {
  582. var thisModule = listingItems[i];
  583. generateListMenuItem(thisModule);
  584. }
  585. if (listingItems.length == 0) {
  586. $("#listMenuItem").html(`<div class="item module"><span><img class="ui middle aligned tiny image" src="img/system/not found.png" style="padding-right: 12px;">No WebApp found</span></div>`)
  587. }
  588. }
  589. function generateListMenuItem(thisModule) {
  590. var icon = thisModule["IconPath"];
  591. if (icon == "") {
  592. //Use default system icon
  593. icon = "img/system/service.png";
  594. }
  595. var name = thisModule["Name"];
  596. var startdir = thisModule["StartDir"];
  597. var group = thisModule["Group"];
  598. var fwsupport = "false";
  599. if (thisModule["SupportFW"]) {
  600. fwsupport = "true";
  601. }
  602. $("#listMenuItem").append(`<div class="item module" module="${name}" startdir="${startdir}" fw="${fwsupport}" group="${group}" onclick="openModuleFromMenu(this);">
  603. <span>
  604. <img class="ui middle aligned tiny image" src="${icon}" style="padding-right: 12px;"></img>
  605. ${name}
  606. </span>
  607. </div>`);
  608. }
  609. function closeListMenu(callback = undefined){
  610. $("#listMenu").animate({
  611. left: window.innerWidth * -1
  612. },300,"swing", function(){
  613. $(".taskBar").animate({
  614. width: "300px",
  615. },300,"swing", function(){
  616. if (typeof callback != "undefined"){
  617. callback();
  618. }
  619. });
  620. });
  621. listMenuShown = false;
  622. }
  623. //Bind swip events
  624. document.addEventListener('touchstart', handleTouchStart, false);
  625. document.addEventListener('touchmove', handleTouchMove, false);
  626. var xDown = null;
  627. var yDown = null;
  628. var swipeTarget = null;
  629. var targetType = "fw";
  630. function getTouches(evt) {
  631. return evt.touches || // browser API
  632. evt.originalEvent.touches; // jQuery
  633. }
  634. function handleTouchStart(evt) {
  635. const firstTouch = getTouches(evt)[0];
  636. if ($(evt.target).hasClass("taskBar")){
  637. swipeTarget = evt.target;
  638. targetType = "taskbar"
  639. }else{
  640. swipeTarget = getFloatWindowObjectFromPath(evt.path);
  641. }
  642. xDown = firstTouch.clientX;
  643. yDown = firstTouch.clientY;
  644. };
  645. function getFloatWindowObjectFromPath(path){
  646. var targetObject = undefined;
  647. targetType = undefined
  648. path.forEach(object => {
  649. if ($(object).hasClass("floatWindowButton")){
  650. targetObject = object
  651. targetType = "fw"
  652. }
  653. })
  654. return targetObject;
  655. }
  656. function handleTouchMove(evt) {
  657. if ( ! xDown || ! yDown ) {
  658. return;
  659. }
  660. var xUp = evt.touches[0].clientX;
  661. var yUp = evt.touches[0].clientY;
  662. var xDiff = xDown - xUp;
  663. var yDiff = yDown - yUp;
  664. if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
  665. if ( xDiff > 0 ) {
  666. /* left swipe */
  667. if (swipeTarget !== undefined && targetType == "fw"){
  668. closeFloatWindow($(swipeTarget).attr("windowId"));
  669. }else if (swipeTarget !== undefined && targetType == "taskbar"){
  670. hideTaskBar();
  671. }
  672. } else {
  673. /* right swipe */
  674. if (swipeTarget !== undefined && targetType == "fw"){
  675. //Allow left or right swipe to remove fw
  676. closeFloatWindow($(swipeTarget).attr("windowId"));
  677. }else if (swipeTarget !== undefined && targetType == "taskbar"){
  678. //Right swipe on taskbar
  679. if ($(swipeTarget).find(".toggleTaskBar").attr("shown") == "true"){
  680. //Already shown. Toggle list menu
  681. showListMenu();
  682. }else{
  683. showTaskBar();
  684. }
  685. }
  686. }
  687. } else {
  688. if ( yDiff > 0 ) {
  689. /* up swipe */
  690. } else {
  691. /* down swipe */
  692. }
  693. }
  694. /* reset values */
  695. xDown = null;
  696. yDown = null;
  697. swipeTarget = null;
  698. };
  699. function showListMenu(callback = undefined){
  700. if ($(".taskBar").find(".toggleTaskBar").attr("shown") == "false"){
  701. $(".taskBar").find(".toggleTaskBar").attr("shown", "true");
  702. $(".taskBar").find('.sidebararrow').attr("src","img/mobile/keyboard_arrow_left-white-48dp.svg");
  703. $("#mainFrame").addClass("blurred");
  704. }
  705. $(".taskBar").animate({
  706. width: window.innerWidth,
  707. },300, "swing", function(){
  708. //Switch all fwbuttons to normal size
  709. $(".floatWindowButton").each(function(){
  710. $(this).find(".minimizedElements").hide();
  711. $(this).find(".normalElements").show();
  712. });
  713. //Show list menu
  714. $("#listMenu").animate({
  715. left: 0
  716. },300,"swing", function(){
  717. if (typeof callback != "undefined"){
  718. callback();
  719. }
  720. });
  721. });
  722. listMenuShown = true;
  723. $("#sidebarToggleOverlay").show();
  724. }
  725. function openModule(moduleName) {
  726. $.get("system/modules/getLaunchPara?module=" + moduleName, function(data) {
  727. console.log(data);
  728. if (data.error !== undefined) {
  729. //Something went wrong.
  730. console.log("Unable to open module " + moduleName);
  731. if (data.error == "Not logged in."){
  732. //Session expired
  733. window.location.href = "login.system";
  734. }
  735. }else {
  736. //Launch the given module
  737. var url = data["StartDir"];
  738. var size = [undefined, undefined];
  739. var icon = "img/system/favicon.png";
  740. if (data["IconPath"] != "") {
  741. icon = data["IconPath"];
  742. }
  743. var title = data["Name"];
  744. //Check if the module support fw mode. If yes, launch with fwmode url. IF not, launch to index
  745. if (data["SupportFW"] == true) {
  746. if (data["LaunchFWDir"] != null) {
  747. url = data["LaunchFWDir"];
  748. }
  749. if (data["InitFWSize"] != null) {
  750. size = data["InitFWSize"];
  751. }
  752. }
  753. //Launch the given module
  754. newFloatWindow({
  755. url: url,
  756. width: size[0],
  757. height: size[1],
  758. appicon: icon,
  759. title: title
  760. });
  761. closeListMenu(function(){
  762. hideTaskBar();
  763. });
  764. }
  765. });
  766. }
  767. function openModuleFromMenu(object) {
  768. var moduleName = $(object).attr("module");
  769. openModule(moduleName);
  770. }
  771. //In mobile interface, there will be some option ignored by default
  772. function newFloatWindow(options){
  773. //Hide all other floatWindows
  774. $(".floatWindowWrapper").fadeOut("fast");
  775. //Construct the new window
  776. var windowID = Date.now();
  777. var parent = options.parent || "";
  778. var callback = options.callback || "";
  779. //Create a new iframe
  780. $("#windowWrapper").append(` <div class="floatWindowWrapper" windowId="${windowID}">
  781. <div class="floatWindow" windowId="${windowID}" parent="${parent}" callback="${callback}">
  782. <div class="fwtab">
  783. <iframe src="${options.url}" style="width: 100%; height: 100%;"></iframe>
  784. </div>
  785. </div>
  786. </div>`);
  787. //Create the button
  788. var title = options.title || "New FloatWindow";
  789. $("#windowButtonWrapper").append(`
  790. <div class="floatWindowButton" windowID="${windowID}" onclick="focusTab(this)">
  791. <div class="minimizedElements">
  792. <img class="minimizedIcon" src="${options.appicon}">
  793. </div>
  794. <div class="normalElements" style="display:none;">
  795. <img class="ui normalizedIcon middle aligned image" src="${options.appicon}">
  796. <span class="windowTitle" style="color:white;">${title}</span>
  797. <div class="closebutton" onclick="closefw(this);"><i class="remove icon"></i></div>
  798. <div class="externalbutton" onclick="openfwInNewTab(this);"><i class="external icon"></i></div>
  799. </div>
  800. </div>
  801. `);
  802. }
  803. ///Functions realted to window resize and auto scaling
  804. function updateWindowDimensions(){
  805. $("#backdrop").css({
  806. width: window.innerWidth,
  807. height: window.innerHeight
  808. });
  809. if (!listMenuShown){
  810. $("#listMenu").css("left", window.innerWidth * -1);
  811. }
  812. }
  813. updateWindowDimensions();
  814. $(window).on("resize", function(data){
  815. updateWindowDimensions();
  816. })
  817. //Float Window APIs
  818. function setFloatWindowTitle(id, title){
  819. $(".floatWindowButton").each(function(){
  820. if ($(this).attr("windowId") == id){
  821. $(this).find(".windowTitle").text(title);
  822. }
  823. })
  824. }
  825. function getFloatWindowByID(id){
  826. var targetObejct = undefined;
  827. $(".floatWindowWrapper").each(function(){
  828. if ($(this).attr("windowId") == id){
  829. targetObejct = $(this);
  830. }
  831. });
  832. return targetObejct;
  833. }
  834. function MoveFloatWindowToTop(targetfw){
  835. //Check if this windows is already topped
  836. if ($(targetfw).is(":visible")){
  837. //Already topped
  838. return;
  839. }
  840. $(".floatWindowWrapper").each(function(){
  841. $(this).fadeOut("fast");
  842. });
  843. console.log(targetfw);
  844. $(targetfw).parent().fadeIn("fast");
  845. }
  846. function focusTab(object){
  847. var windowID = $(object).attr("windowId");
  848. //Hide all other flowWindows
  849. $(".floatWindowWrapper").fadeOut("fast");
  850. //Show the target fw
  851. var fw = getFloatWindowByID(windowID);
  852. fw.fadeIn("fast", function(){
  853. hideTaskBar();
  854. });
  855. }
  856. function getFloatWindowByID(id){
  857. var targetObejct = undefined;
  858. $(".floatWindowWrapper").each(function(){
  859. if ($(this).attr("windowId") == id){
  860. targetObejct = $(this);
  861. }
  862. });
  863. return targetObejct;
  864. }
  865. function setFloatWindowResizePolicy(id, allowResize){
  866. //Disabled in mobile mode
  867. }
  868. function setFloatWindowSize(id, width, height){
  869. //Disabled in mobile mode
  870. }
  871. function closeFloatWindow(windowID){
  872. //Get the content iframe with that windowID
  873. var contentWindow = getFloatWindowByID(windowID).find("iframe")[0].contentWindow;
  874. console.log(contentWindow);
  875. try {
  876. if (contentWindow.ao_module_close === undefined) {
  877. //This module do not use ao_module wrapper. Close it directly.
  878. closeFwProcess(windowID);
  879. } else {
  880. //Pass the closing events to the window itself
  881. contentWindow.ao_module_close();
  882. }
  883. } catch (ex) {
  884. //Problems of closing floatWindow. Force closing.
  885. closeFwProcess(windowID);
  886. }
  887. }
  888. function closefw(object){
  889. var windowID = $(object).parent().parent().attr("windowID");
  890. closeFloatWindow(windowID);
  891. }
  892. function openfwInNewTab(object){
  893. event.preventDefault();
  894. event.stopImmediatePropagation();
  895. var windowID = $(object).parent().parent().attr("windowID");
  896. var targetFloatWindow = null;
  897. $(".floatWindowWrapper").each(function(){
  898. if ($(this).attr("windowid") == windowID){
  899. targetFloatWindow = $(this);
  900. }
  901. });
  902. if (targetFloatWindow == null){
  903. return;
  904. }
  905. var iframe = $(targetFloatWindow).find("iframe");
  906. var url = $(iframe)[0].contentWindow.location.href;
  907. window.open(url);
  908. }
  909. //Get the window below this window id, can return null if there is no window
  910. function getPreviousWindowObject(windowID){
  911. var previousWindowID = null;
  912. var result = null;
  913. $(".floatWindowButton").each(function(){
  914. if ($(this).attr("windowid") == windowID){
  915. result = previousWindowID;
  916. }else{
  917. let thisWindowID = $(this).attr("windowid");
  918. previousWindowID = thisWindowID;
  919. }
  920. });
  921. return result;
  922. }
  923. function closeFwProcess(windowID){
  924. //Get the previous window object
  925. var previousWindowID = getPreviousWindowObject(windowID);
  926. //Remove the window object
  927. $(".floatWindowWrapper").each(function(){
  928. if ($(this).attr("windowId") == windowID){
  929. $(this).fadeOut("fast",function(){
  930. $(this).remove();
  931. });
  932. }
  933. });
  934. //Remove the button object
  935. $(".floatWindowButton").each(function(){
  936. if ($(this).attr("windowId") == windowID){
  937. $(this).fadeOut("fast",function(){
  938. $(this).remove();
  939. });
  940. }
  941. });
  942. //Focus the window behind if exists
  943. setTimeout(function(){
  944. if (previousWindowID != null){
  945. //Hide all other flowWindows
  946. $(".floatWindowWrapper").fadeOut("fast");
  947. //Show the target fw
  948. var fw = getFloatWindowByID(previousWindowID);
  949. console.log(fw);
  950. fw.fadeIn("fast", function(){
  951. });
  952. }
  953. }, 100);
  954. }
  955. function openFileWithModule(moduleLaunchInfo, openFileList) {
  956. var url = moduleLaunchInfo["StartDir"];
  957. var size = [undefined, undefined];
  958. var title = moduleLaunchInfo["Name"];
  959. var icon = "img/system/favicon.png";
  960. if (moduleLaunchInfo["IconPath"] != "") {
  961. icon = moduleLaunchInfo["IconPath"];
  962. }
  963. //Use floatWindow if exists
  964. if (moduleLaunchInfo["SupportFW"] == true && moduleLaunchInfo["LaunchFWDir"] != "") {
  965. url = moduleLaunchInfo["LaunchFWDir"];
  966. if (moduleLaunchInfo["InitFWSize"] !== null) {
  967. size = moduleLaunchInfo["InitFWSize"]
  968. }
  969. }
  970. //Use embedded mode if exists
  971. if (moduleLaunchInfo["SupportEmb"] == true && moduleLaunchInfo["LaunchEmb"] != "") {
  972. url = moduleLaunchInfo["LaunchEmb"];
  973. if (moduleLaunchInfo["InitEmbSize"] !== null) {
  974. size = moduleLaunchInfo["InitEmbSize"]
  975. }
  976. }
  977. var openParamter = encodeURIComponent(JSON.stringify(openFileList));
  978. //Add launch files info and launch floatWindow
  979. parent.newFloatWindow({
  980. url: url + "#" + openParamter,
  981. width: size[0],
  982. height: size[1],
  983. appicon: icon,
  984. title: title
  985. });
  986. }
  987. </script>
  988. </body>
  989. </html>