mobile.system 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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: 4px;
  185. top: 4px;
  186. }
  187. </style>
  188. </head>
  189. <body>
  190. <div class="taskBar themeColor" >
  191. <div class="toggleTaskBar themeColor" shown="false" onclick="toggleTaskBar(this);">
  192. <img class="ui image sidebararrow" style="margin-top:8px; margin-left: -10px;" src="img/mobile/keyboard_arrow_right-white-48dp.svg"></img>
  193. </div>
  194. <div class="listMenuLauncher" onclick="showListMenu();">
  195. <img src="img/mobile/apps-white-48dp.svg" style="width: 30px;"/>
  196. </div>
  197. <div id="windowButtonWrapper">
  198. </div>
  199. </div>
  200. <div id="listMenu" style="left:-100%;">
  201. <div class="searchBar" onkeydown="searchModule(event);">
  202. <div class="ui icon fluid input" style="border-radius: 0px !important;">
  203. <input id="searchBar" type="text" placeholder="Search">
  204. <i class="search icon"></i>
  205. </div>
  206. </div>
  207. <dib class="listItemWrapper">
  208. <div class="groups">
  209. <div id="searchResults" class="item" style="display:none;">Search Results</div>
  210. <div class="item groupType selected" group="All">All</div>
  211. <div class="item groupType" group="Media">Media</div>
  212. <div class="item groupType" group="Office">Office</div>
  213. <div class="item groupType" group="Download">Download</div>
  214. <div class="item groupType" group="Files">Files</div>
  215. <div class="item groupType" group="Internet">Internet</div>
  216. <div class="item groupType" group="System Settings">System Settings</div>
  217. <div class="item groupType" group="System Tools">System Tools</div>
  218. <div class="item groupType" group="Utilities">Utilities</div>
  219. <div class="item groupType" group="Other">Other</div>
  220. <div class="hideListMenuButton" onclick="closeListMenu();">
  221. <img class="ui image" src="img/mobile/cancel-black-48dp.svg"></img>
  222. <p>Close Menu</p>
  223. </div>
  224. </div>
  225. <div id="listMenuItem" class="items" align="left">
  226. </div>
  227. </div>
  228. </div>
  229. <div id="mainFrame">
  230. <div id="backdrop">
  231. </div>
  232. <div id="windowWrapper">
  233. </div>
  234. </div>
  235. <script>
  236. var isDesktopMode = true; //Try to emulate Desktop mode
  237. var moduleInstalled = []; //List of installed modules on the system
  238. var desktopThemeList = []; //List of themes installed, same as desktop theme
  239. //initiation Functions
  240. initModuleList();
  241. bindGroupTypeEvents();
  242. initBackdropImage();
  243. initUserDefinedThemeColor();
  244. //Bind background click
  245. $("#mainFrame").on("touchstart", function(evt){
  246. if ($(this).hasClass("blurred") && $(".taskBar").find(".toggleTaskBar").attr("shown") == "true"){
  247. //hide the taskbar
  248. hideTaskBar();
  249. }
  250. });
  251. //Initialize background image
  252. function initBackdropImage(){
  253. $.get("system/desktop/theme", function(data) {
  254. //Return a list of theme stored on the system
  255. desktopThemeList = data;
  256. $.get("system/desktop/theme?get=true", function(data) {
  257. //Get the user theme settings
  258. changeDesktopTheme(data);
  259. });
  260. });
  261. }
  262. function initUserDefinedThemeColor(){
  263. $.ajax({
  264. url: "../../system/file_system/preference",
  265. data: {key: "themecolor"},
  266. success: function(data){
  267. if (data.error == undefined && data != ""){
  268. $(".themeColor").css("background-color", data);
  269. }
  270. }
  271. });
  272. }
  273. function changeDesktopTheme(themename){
  274. //Match the given theme to the themename
  275. if (themename.includes(":/") == false){
  276. //This is a path
  277. for (var i =0; i < desktopThemeList.length ; i++){
  278. if (desktopThemeList[i].Theme == themename){
  279. var targetImage = desktopThemeList[i].Bglist[0];
  280. $("#backdrop").css("background-image", `url(img/desktop/bg/${themename}/${targetImage})`)
  281. }
  282. }
  283. }else{
  284. //This is a path (user defined background folder)
  285. $.get("system/desktop/theme?load=" + themename, function(data){
  286. if (data.error !== undefined){
  287. //The folder is gone. Use default instead
  288. console.log(data.error);
  289. changeDesktopTheme("default");
  290. }else{
  291. $("#backdrop").css("background-image", `url(media/?file=${data[0]})`)
  292. }
  293. });
  294. }
  295. }
  296. function toggleFullScreen() {
  297. var doc = window.document;
  298. var docEl = doc.documentElement;
  299. var requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
  300. var cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;
  301. if(!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
  302. requestFullScreen.call(docEl);
  303. }
  304. else {
  305. cancelFullScreen.call(doc);
  306. }
  307. }
  308. //Sidebar
  309. function toggleTaskBar(obj){
  310. if ($(obj).attr("shown") == "true"){
  311. hideTaskBar();
  312. }else{
  313. showTaskBar();
  314. }
  315. }
  316. function hideTaskBar(){
  317. //Hide the taskBar
  318. $(".taskBar").animate({
  319. width: "30px"
  320. },300, "swing");
  321. $(".taskBar").find('.sidebararrow').attr("src","img/mobile/keyboard_arrow_right-white-48dp.svg");
  322. $(".taskBar").find(".toggleTaskBar").attr("shown","false");
  323. $("#mainFrame").removeClass("blurred");
  324. //Minimize all fwbuttons
  325. $(".floatWindowButton").each(function(){
  326. $(this).find(".minimizedElements").show();
  327. $(this).find(".normalElements").hide();
  328. });
  329. }
  330. function showTaskBar(){
  331. //Show the taskbar
  332. $(".taskBar").animate({
  333. width: "300px"
  334. }, 300, "swing", function(){
  335. //Switch all fwbuttons to normal size
  336. $(".floatWindowButton").each(function(){
  337. $(this).find(".minimizedElements").hide();
  338. $(this).find(".normalElements").show();
  339. });
  340. });
  341. $(".taskBar").find('.sidebararrow').attr("src","img/mobile/keyboard_arrow_left-white-48dp.svg");
  342. $(".taskBar").find(".toggleTaskBar").attr("shown","true");
  343. $("#mainFrame").addClass("blurred");
  344. }
  345. //List all modules
  346. function initModuleList(){
  347. $.ajax({
  348. url: "system/modules/list",
  349. success: function(data) {
  350. moduleInstalled = data;
  351. listModulesType("All");
  352. }
  353. });
  354. }
  355. //ListMenu group classification events
  356. function bindGroupTypeEvents(){
  357. $(".groupType").on("click",function(evt){
  358. //Clear all serach results
  359. $("#searchResults").slideUp('fast');
  360. listModulesType($(this).attr("group"));
  361. $(".groupType.selected").removeClass("selected");
  362. $(this).addClass("selected");
  363. /*
  364. var classificationObject = this;
  365. if ($(this).attr("group") == "All"){
  366. $('.item.module').show();
  367. } else if ($(this).attr("group") == "Other"){
  368. var excludeList = ["Media", "Office", "Download", "Files", "Internet", "System Settings", "System Tools", "Utilties"];
  369. $('.item.module').each(function(){
  370. if (excludeList.includes($(this).attr("group")) == false){
  371. $(this).show();
  372. }else{
  373. $(this).hide();
  374. }
  375. });
  376. }else{
  377. $('.item.module').each(function(){
  378. if ($(this).attr("group") == $(classificationObject).attr("group")){
  379. $(this).show();
  380. }else{
  381. $(this).hide();
  382. }
  383. });
  384. }
  385. */
  386. });
  387. }
  388. function searchModule(event) {
  389. if (event.which == 13) {
  390. var keyword = $("#searchBar").val().toLowerCase();
  391. var results = [];
  392. var lessAccurateResults = [];
  393. $(".groupType.selected").removeClass("selected");
  394. $("#searchResults").addClass("selected").slideDown('fast');
  395. //Load all search results
  396. for (var i = 0; i < moduleInstalled.length; i++) {
  397. var thisModule = moduleInstalled[i];
  398. var pathInfo = thisModule["StartDir"].split("/");
  399. for (var j = 0; j < pathInfo.length; j++) {
  400. pathInfo[j] = pathInfo[j].toLowerCase();
  401. }
  402. if (thisModule["Name"].toLowerCase().includes(keyword)) {
  403. results.push(thisModule);
  404. } else if (pathInfo.includes(keyword.toLowerCase()) || pathInfo.includes(keyword.split(" ").join("_").toLowerCase())) {
  405. lessAccurateResults.push(thisModule);
  406. }
  407. }
  408. results = results.concat(lessAccurateResults);
  409. //Append the results to list
  410. $("#listMenuItem").html("");
  411. for (var i = 0; i < results.length; i++) {
  412. generateListMenuItem(results[i]);
  413. }
  414. if (results.length == 0) {
  415. //Append a custom no results div to the content
  416. $("#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>`);
  417. }
  418. }
  419. }
  420. function listModulesType(groupType) {
  421. var listingItems = [];
  422. if (groupType == "All") {
  423. //List all of the items
  424. for (var i = 0; i < moduleInstalled.length; i++) {
  425. if (moduleInstalled[i]["StartDir"] != "") {
  426. listingItems.push(moduleInstalled[i]);
  427. }
  428. }
  429. } else if (groupType == "Other") {
  430. var excludeList = ["Media", "Office", "Download", "Files", "Internet", "System Settings", "System Tools", "Utilties"];
  431. //List the Other groups
  432. for (var i = 0; i < moduleInstalled.length; i++) {
  433. if (excludeList.includes(moduleInstalled[i]["Group"]) == false && moduleInstalled[i]["StartDir"] != "") {
  434. listingItems.push(moduleInstalled[i]);
  435. }
  436. }
  437. } else {
  438. //List the given group
  439. for (var i = 0; i < moduleInstalled.length; i++) {
  440. if (moduleInstalled[i]["Group"] == groupType && moduleInstalled[i]["StartDir"] != "") {
  441. listingItems.push(moduleInstalled[i]);
  442. }
  443. }
  444. }
  445. //List the item to the listmenu
  446. $("#listMenuItem").html("");
  447. for (var i = 0; i < listingItems.length; i++) {
  448. var thisModule = listingItems[i];
  449. generateListMenuItem(thisModule);
  450. }
  451. if (listingItems.length == 0) {
  452. $("#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>`)
  453. }
  454. }
  455. function generateListMenuItem(thisModule) {
  456. var icon = thisModule["IconPath"];
  457. if (icon == "") {
  458. //Use default system icon
  459. icon = "img/system/service.png";
  460. }
  461. var name = thisModule["Name"];
  462. var startdir = thisModule["StartDir"];
  463. var group = thisModule["Group"];
  464. var fwsupport = "false";
  465. if (thisModule["SupportFW"]) {
  466. fwsupport = "true";
  467. }
  468. $("#listMenuItem").append(`<div class="item module" module="${name}" startdir="${startdir}" fw="${fwsupport}" group="${group}" onclick="openModuleFromMenu(this);">
  469. <span>
  470. <img class="ui middle aligned tiny image" src="${icon}" style="padding-right: 12px;"></img>
  471. ${name}
  472. </span>
  473. </div>`);
  474. }
  475. function closeListMenu(callback = undefined){
  476. $("#listMenu").animate({
  477. left: window.innerWidth * -1
  478. },300,"swing", function(){
  479. $(".taskBar").animate({
  480. width: "300px",
  481. },300,"swing", function(){
  482. if (typeof callback != "undefined"){
  483. callback();
  484. }
  485. });
  486. });
  487. }
  488. //Bind swip events
  489. document.addEventListener('touchstart', handleTouchStart, false);
  490. document.addEventListener('touchmove', handleTouchMove, false);
  491. var xDown = null;
  492. var yDown = null;
  493. var swipeTarget = null;
  494. var targetType = "fw";
  495. function getTouches(evt) {
  496. return evt.touches || // browser API
  497. evt.originalEvent.touches; // jQuery
  498. }
  499. function handleTouchStart(evt) {
  500. const firstTouch = getTouches(evt)[0];
  501. if ($(evt.target).hasClass("taskBar")){
  502. swipeTarget = evt.target;
  503. targetType = "taskbar"
  504. }else{
  505. swipeTarget = getFloatWindowObjectFromPath(evt.path);
  506. }
  507. xDown = firstTouch.clientX;
  508. yDown = firstTouch.clientY;
  509. };
  510. function getFloatWindowObjectFromPath(path){
  511. var targetObject = undefined;
  512. targetType = undefined
  513. path.forEach(object => {
  514. if ($(object).hasClass("floatWindowButton")){
  515. targetObject = object
  516. targetType = "fw"
  517. }
  518. })
  519. return targetObject;
  520. }
  521. function handleTouchMove(evt) {
  522. if ( ! xDown || ! yDown ) {
  523. return;
  524. }
  525. var xUp = evt.touches[0].clientX;
  526. var yUp = evt.touches[0].clientY;
  527. var xDiff = xDown - xUp;
  528. var yDiff = yDown - yUp;
  529. if ( Math.abs( xDiff ) > Math.abs( yDiff ) ) {/*most significant*/
  530. if ( xDiff > 0 ) {
  531. /* left swipe */
  532. if (swipeTarget !== undefined && targetType == "fw"){
  533. closeFloatWindow($(swipeTarget).attr("windowId"));
  534. }else if (swipeTarget !== undefined && targetType == "taskbar"){
  535. hideTaskBar();
  536. }
  537. } else {
  538. /* right swipe */
  539. if (swipeTarget !== undefined && targetType == "fw"){
  540. //Allow left or right swipe to remove fw
  541. closeFloatWindow($(swipeTarget).attr("windowId"));
  542. }else if (swipeTarget !== undefined && targetType == "taskbar"){
  543. //Right swipe on taskbar
  544. if ($(swipeTarget).find(".toggleTaskBar").attr("shown") == "true"){
  545. //Already shown. Toggle list menu
  546. showListMenu();
  547. }else{
  548. showTaskBar();
  549. }
  550. }
  551. }
  552. } else {
  553. if ( yDiff > 0 ) {
  554. /* up swipe */
  555. } else {
  556. /* down swipe */
  557. }
  558. }
  559. /* reset values */
  560. xDown = null;
  561. yDown = null;
  562. swipeTarget = null;
  563. };
  564. function showListMenu(callback = undefined){
  565. if ($(".taskBar").find(".toggleTaskBar").attr("shown") == "false"){
  566. $(".taskBar").find(".toggleTaskBar").attr("shown", "true");
  567. $(".taskBar").find('.sidebararrow').attr("src","img/mobile/keyboard_arrow_left-white-48dp.svg");
  568. $("#mainFrame").addClass("blurred");
  569. }
  570. $(".taskBar").animate({
  571. width: window.innerWidth,
  572. },300, "swing", function(){
  573. //Switch all fwbuttons to normal size
  574. $(".floatWindowButton").each(function(){
  575. $(this).find(".minimizedElements").hide();
  576. $(this).find(".normalElements").show();
  577. });
  578. //Show list menu
  579. $("#listMenu").animate({
  580. left: 0
  581. },300,"swing", function(){
  582. if (typeof callback != "undefined"){
  583. callback();
  584. }
  585. });
  586. })
  587. }
  588. function openModule(moduleName) {
  589. $.get("system/modules/getLaunchPara?module=" + moduleName, function(data) {
  590. console.log(data);
  591. if (data.error !== undefined) {
  592. //Something went wrong.
  593. console.log("Unable to open module " + moduleName);
  594. if (data.error == "Not logged in."){
  595. //Session expired
  596. window.location.href = "login.system";
  597. }
  598. }else {
  599. //Launch the given module
  600. var url = data["StartDir"];
  601. var size = [undefined, undefined];
  602. var icon = "img/system/favicon.png";
  603. if (data["IconPath"] != "") {
  604. icon = data["IconPath"];
  605. }
  606. var title = data["Name"];
  607. //Check if the module support fw mode. If yes, launch with fwmode url. IF not, launch to index
  608. if (data["SupportFW"] == true) {
  609. if (data["LaunchFWDir"] != null) {
  610. url = data["LaunchFWDir"];
  611. }
  612. if (data["InitFWSize"] != null) {
  613. size = data["InitFWSize"];
  614. }
  615. }
  616. //Launch the given module
  617. newFloatWindow({
  618. url: url,
  619. width: size[0],
  620. height: size[1],
  621. appicon: icon,
  622. title: title
  623. });
  624. closeListMenu(function(){
  625. hideTaskBar();
  626. });
  627. }
  628. });
  629. }
  630. function openModuleFromMenu(object) {
  631. var moduleName = $(object).attr("module");
  632. openModule(moduleName);
  633. }
  634. //In mobile interface, there will be some option ignored by default
  635. function newFloatWindow(options){
  636. //Hide all other floatWindows
  637. $(".floatWindowWrapper").fadeOut("fast");
  638. //Construct the new window
  639. var windowID = Date.now();
  640. var parent = options.parent || "";
  641. var callback = options.callback || "";
  642. //Create a new iframe
  643. $("#windowWrapper").append(` <div class="floatWindowWrapper" windowId="${windowID}">
  644. <div class="floatWindow" windowId="${windowID}" parent="${parent}" callback="${callback}">
  645. <div class="fwtab">
  646. <iframe src="${options.url}" style="width: 100%; height: 100%;"></iframe>
  647. </div>
  648. </div>
  649. </div>`);
  650. //Create the button
  651. var title = options.title || "New FloatWindow";
  652. $("#windowButtonWrapper").append(`
  653. <div class="floatWindowButton" windowID="${windowID}" onclick="focusTab(this)">
  654. <div class="minimizedElements">
  655. <img class="minimizedIcon" src="${options.appicon}">
  656. </div>
  657. <div class="normalElements" style="display:none;">
  658. <img class="ui normalizedIcon middle aligned image" src="${options.appicon}">
  659. <span class="windowTitle" style="color:white;">${title}</span>
  660. <div class="closebutton" onclick="closefw(this);"><i class="remove icon"></i></div>
  661. </div>
  662. </div>
  663. `);
  664. }
  665. ///Functions realted to window resize and auto scaling
  666. function updateWindowDimensions(){
  667. $("#backdrop").css({
  668. width: window.innerWidth,
  669. height: window.innerHeight
  670. });
  671. }
  672. updateWindowDimensions();
  673. $(window).on("resize", function(data){
  674. updateWindowDimensions();
  675. })
  676. //Float Window APIs
  677. function setFloatWindowTitle(id, title){
  678. $(".floatWindowButton").each(function(){
  679. if ($(this).attr("windowId") == id){
  680. $(this).find(".windowTitle").text(title);
  681. }
  682. })
  683. }
  684. function getFloatWindowByID(id){
  685. var targetObejct = undefined;
  686. $(".floatWindowWrapper").each(function(){
  687. if ($(this).attr("windowId") == id){
  688. targetObejct = $(this);
  689. }
  690. });
  691. return targetObejct;
  692. }
  693. function MoveFloatWindowToTop(targetfw){
  694. //Check if this windows is already topped
  695. if ($(targetfw).is(":visible")){
  696. //Already topped
  697. return;
  698. }
  699. $(".floatWindowWrapper").each(function(){
  700. $(this).fadeOut("fast");
  701. });
  702. console.log(targetfw);
  703. $(targetfw).parent().fadeIn("fast");
  704. }
  705. function focusTab(object){
  706. var windowID = $(object).attr("windowId");
  707. //Hide all other flowWindows
  708. $(".floatWindowWrapper").fadeOut("fast");
  709. //Show the target fw
  710. var fw = getFloatWindowByID(windowID);
  711. fw.fadeIn("fast", function(){
  712. hideTaskBar();
  713. });
  714. }
  715. function getFloatWindowByID(id){
  716. var targetObejct = undefined;
  717. $(".floatWindowWrapper").each(function(){
  718. if ($(this).attr("windowId") == id){
  719. targetObejct = $(this);
  720. }
  721. });
  722. return targetObejct;
  723. }
  724. function setFloatWindowResizePolicy(id, allowResize){
  725. //Disabled in mobile mode
  726. }
  727. function setFloatWindowSize(id, width, height){
  728. //Disabled in mobile mode
  729. }
  730. function closeFloatWindow(windowID){
  731. //Get the content iframe with that windowID
  732. var contentWindow = getFloatWindowByID(windowID).find("iframe")[0].contentWindow;
  733. console.log(contentWindow);
  734. try {
  735. if (contentWindow.ao_module_close === undefined) {
  736. //This module do not use ao_module wrapper. Close it directly.
  737. closeFwProcess(windowID);
  738. } else {
  739. //Pass the closing events to the window itself
  740. contentWindow.ao_module_close();
  741. }
  742. } catch (ex) {
  743. //Problems of closing floatWindow. Force closing.
  744. closeFwProcess(windowID);
  745. }
  746. }
  747. function closefw(object){
  748. var windowID = $(object).parent().parent().attr("windowID");
  749. closeFloatWindow(windowID);
  750. }
  751. function closeFwProcess(windowID){
  752. //Remove the window object
  753. $(".floatWindowWrapper").each(function(){
  754. if ($(this).attr("windowId") == windowID){
  755. $(this).fadeOut("fast",function(){
  756. $(this).remove();
  757. });
  758. }
  759. });
  760. //Remove the button object
  761. $(".floatWindowButton").each(function(){
  762. if ($(this).attr("windowId") == windowID){
  763. $(this).fadeOut("fast",function(){
  764. $(this).remove();
  765. });
  766. }
  767. });
  768. }
  769. </script>
  770. </body>
  771. </html>