function_bar.js 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963
  1. /**
  2. ArOZ Online Beta
  3. Function Bar System Script
  4. Toby Chui feat. IMUS Laboratory All Right Reserved
  5. This script is design for launching the virtual taskbar and FloatWindow system.
  6. DO NOT EDIT OR ATTEMPT TO CHANGE ANYTHING IF YOU ARE NOT SURE WHAT YOU ARE DOING.
  7. Sections of the ArOZ Online System might collapse if this script file is changed.
  8. If you decide to change anything here, please do it with your own risk.
  9. 香港制作 安全好用
  10. **/
  11. var powerManualVisable = false;
  12. var menuBarVisable = true;
  13. var fileExplorerVisable = false;
  14. var focusedObject = null;
  15. var dragging = false;
  16. var resizing = false;
  17. var lastPosition = [0,0];
  18. var focusedWindow = null;
  19. var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  20. var initialURL = "http://" + window.location.host + window.location.pathname.replace(window.location.pathname.split("/").pop(),"");
  21. var floatWindowCount = 0; //Max 50 Floating Windows
  22. var supportedModules = $("#DATA_PIPELINE_supportedModules").text().trim();
  23. var USBNo = 0;
  24. var notificationCount = 0;
  25. var isFunctionBar = true; //Reference Point for background application
  26. var windowID = $("#DATA_PIPELINE_windowID").text().trim();
  27. $("#notificationbar").css("left",$(window).width() + "px");
  28. var themeColor = {"theme":$("#DATA_PIPELINE_themeColor").text().trim(), "active":$("#DATA_PIPELINE_activeColor").text().trim()};
  29. window.mobilecheck = function() {
  30. var check = false;
  31. (function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
  32. return check;
  33. };
  34. var hash = window.location.hash.replace("#","");
  35. if (hash !== ""){
  36. $('#interface').attr('src',hash);
  37. }
  38. $( document ).ready(function() {
  39. if (window.mobilecheck()){
  40. //This device is mobile
  41. $('#menuBar').hide();
  42. $('#showMenuButton').show();
  43. menuBarVisable = false;
  44. }else{
  45. //This device is not a mobile device
  46. }
  47. //Bind the drag drop movement to all the existing divs on screen
  48. bindMotions();
  49. //Get the default USB numbers on the system
  50. UpdateUSBNo();
  51. //Assume no USB was plugged in during booting.
  52. SetUSBFound(false);
  53. //Set Interval for USB monitoring
  54. setInterval(CheckUSBChange,15000);
  55. //Set Interval to check if any iframe freezed or request external killing
  56. //setInterval(forceTerminate,3000);
  57. //Open Float Window with <src>,<title>,<iconTag>,<uid>
  58. //Example New FloatWindow call
  59. //newEmbededWindow('Audio/index.php','Audio','music','audioEmbedded');
  60. //newEmbededWindow('Video/index.php','Video','video','videoEmbedded');
  61. //newEmbededWindow('Memo/index.php','Memo','sticky note outline','memoEmbedded',475,700);
  62. });
  63. var iframeoffset;
  64. function bindMotions(object = undefined){
  65. //START OF PAGE MOTION BINDING
  66. var draggingIcon = false;
  67. var animationFinished = true;
  68. var target = $("*");
  69. if (object !== undefined){
  70. target = $("#" + object);
  71. }
  72. //Float Window Drag Drop Control Code
  73. $( ".floatWindow" ).on("mousedown", target, function( event ) {
  74. event.preventDefault();
  75. focusedObject = event.target;
  76. if ($(event.target).prop('nodeName') == "I"){
  77. focusedObject = $(focusedObject).parent();
  78. draggingIcon = true;
  79. return;
  80. }else{
  81. draggingIcon = false;
  82. }
  83. if (focusedWindow !== null && checkFocusWindowIsAlreadyFocused() === false){
  84. //Defocus the previously focued window
  85. //$(focusedWindow).parent().css('z-index',1);
  86. ShiftAllFloatWindowZIndex(true);
  87. }
  88. //Focus the new window
  89. $(focusedObject).parent().css('z-index',100);
  90. focusedWindow = focusedObject;
  91. //$('#iframeCover').show().insertAfter(focusedObject);
  92. var parentPosX = $(focusedObject).parent().offset().left;
  93. var parentPosY = $(focusedObject).parent().offset().top;
  94. /**
  95. //Deprecated since 8-3-2019, Non-glassEffect Mode windows will no longer have iframe border
  96. iframeoffset = 20;
  97. if($(focusedObject).parent().css("background-color") == "rgb(255, 255, 255)"){
  98. //If this is a floatWindows that is not supporting the glassEffect mode
  99. iframeoffset = 20;
  100. }
  101. **/
  102. iframeoffset = 20;
  103. $('#iframeCover').css({"left":parentPosX,"top":parentPosY + iframeoffset});
  104. $('#iframeCover').css('width',$(focusedObject).parent().css('width').replace("px",""));
  105. $('#iframeCover').css('height',$(focusedObject).parent().css('height').replace("px","") - iframeoffset);
  106. $('#iframeCover').css('z-index',115);
  107. $('#iframeCover').show();
  108. dragging = true;
  109. $('#backdrop').show();
  110. lastPosition[0] = event.pageX;
  111. lastPosition[1] = event.pageY;
  112. lastPosition[2] = parseInt($(focusedObject).parent().css("left").replace("px",""));
  113. lastPosition[3] = parseInt($(focusedObject).parent().css("top").replace("px",""));
  114. });
  115. $( ".floatWindow" ).on('touchstart', target, function( event ) {
  116. event.preventDefault();
  117. focusedObject = event.target;
  118. if ($(event.target).prop('nodeName') == "I"){
  119. focusedObject = $(focusedObject).parent();
  120. draggingIcon = true;
  121. return;
  122. }else{
  123. draggingIcon = false;
  124. }
  125. if (focusedWindow !== null && checkFocusWindowIsAlreadyFocused() === false){
  126. //Defocus the previously focued window
  127. //$(focusedWindow).parent().css('z-index',1);
  128. ShiftAllFloatWindowZIndex(true);
  129. }
  130. //Focus the new window
  131. $(focusedObject).parent().css('z-index',100);
  132. focusedWindow = focusedObject;
  133. var parentPosX = $(focusedObject).parent().offset().left;
  134. var parentPosY = $(focusedObject).parent().offset().top;
  135. /**
  136. //Deprecated since 8-3-2019, Non-glassEffect Mode windows will no longer have iframe border
  137. iframeoffset = 20;
  138. if($(focusedObject).parent().css("background-color") == "rgb(255, 255, 255)"){
  139. //If this is a floatWindows that is not supporting the glassEffect mode
  140. iframeoffset = 20;
  141. }
  142. **/
  143. iframeoffset = 20;
  144. $('#iframeCover').css({"left":parentPosX,"top":parentPosY + iframeoffset});
  145. $('#iframeCover').css('width',$(focusedObject).parent().css('width').replace("px",""));
  146. $('#iframeCover').css('height',$(focusedObject).parent().css('height').replace("px","") - iframeoffset);
  147. $('#iframeCover').css('z-index',115);
  148. $('#iframeCover').show();
  149. dragging = true;
  150. $('#backdrop').show();
  151. lastPosition[0] = event.originalEvent.touches[0].pageX;
  152. lastPosition[1] = event.originalEvent.touches[0].pageY;
  153. lastPosition[2] = parseInt($(focusedObject).parent().css("left").replace("px",""));
  154. lastPosition[3] = parseInt($(focusedObject).parent().css("top").replace("px",""));
  155. });
  156. //Float window dragging
  157. $(document, 'body').on("mousemove",target,function( event ) {
  158. if (dragging === true && draggingIcon === false && animationFinished === true && focusedObject != "undefined"){
  159. var parentObject = $(focusedObject).parent();
  160. if (parentObject.attr("osize") !== undefined){
  161. //Set this floatWindow to floating mode if drag during full screen
  162. var restorePoint = JSON.parse(parentObject.attr("osize"));
  163. parentObject.css("width",restorePoint[0]);
  164. parentObject.css("height",restorePoint[1]);
  165. parentObject.find(".maximizeWindow").html('<i class="small window maximize icon"></i>');
  166. parentObject.removeAttr("osize");
  167. //As the frame is scaled down, the original touching position is no longer correct. The offset x value has to be manually offset with the width of the floatWindow object
  168. var xoffsets = restorePoint[0] / 2;
  169. parentObject.css("top",parentPosY);
  170. parentObject.css("left",event.pageX - xoffsets);
  171. lastPosition[2] = parseInt($(focusedObject).parent().css("left").replace("px",""));
  172. lastPosition[3] = parseInt($(focusedObject).parent().css("top").replace("px",""));
  173. //Update the iframe cover as well
  174. $('#iframeCover').css('width',parentObject.css('width').replace("px",""));
  175. $('#iframeCover').css('height',parentObject.css('height').replace("px","") - iframeoffset);
  176. }
  177. //Move the div accordingly
  178. //$(focusedObject).css({left:event.pageX,top:event.pageY});
  179. var parentPosX = parentObject.offset().left;
  180. var parentPosY = parentObject.offset().top;
  181. $('#iframeCover').css({"left":parentPosX,"top":parentPosY + iframeoffset});
  182. var dx = event.pageX - lastPosition[0];
  183. var dy = event.pageY - lastPosition[1];
  184. var nx = lastPosition[2] + dx;
  185. var ny = lastPosition[3] + dy;
  186. parentObject.css("left", nx );
  187. parentObject.css("top", ny);
  188. }
  189. });
  190. $(document, 'body').bind('touchmove',target, function( event ) {
  191. if (dragging == true && draggingIcon == false && animationFinished == true && focusedObject != "undefined"){
  192. var parentObject = $(focusedObject).parent();
  193. if (parentObject.attr("osize") != undefined){
  194. //Set this floatWindow to floating mode if drag during full screen
  195. var restorePoint = JSON.parse(parentObject.attr("osize"));
  196. parentObject.css("width",restorePoint[0]);
  197. parentObject.css("height",restorePoint[1]);
  198. parentObject.find(".maximizeWindow").html('<i class="small window maximize icon"></i>');
  199. parentObject.removeAttr("osize");
  200. //As the frame is scaled down, the original touching position is no longer correct. The offset x value has to be manually offset with the width of the floatWindow object
  201. var xoffsets = restorePoint[0] / 2;
  202. parentObject.css("top",parentPosY);
  203. parentObject.css("left",event.originalEvent.touches[0].pageX - xoffsets);
  204. lastPosition[2] = parseInt($(focusedObject).parent().css("left").replace("px",""));
  205. lastPosition[3] = parseInt($(focusedObject).parent().css("top").replace("px",""));
  206. //Update the iframe cover as well
  207. $('#iframeCover').css('width',parentObject.css('width').replace("px",""));
  208. $('#iframeCover').css('height',parentObject.css('height').replace("px","") - iframeoffset);
  209. }
  210. //Move the div accordingly
  211. //$(focusedObject).css({left:event.pageX,top:event.pageY});
  212. var parentPosX = parentObject.offset().left;
  213. var parentPosY = parentObject.offset().top;
  214. $('#iframeCover').css({"left":parentPosX,"top":parentPosY + iframeoffset});
  215. var dx = event.originalEvent.touches[0].pageX - lastPosition[0];
  216. var dy = event.originalEvent.touches[0].pageY - lastPosition[1];
  217. var nx = lastPosition[2] + dx;
  218. var ny = lastPosition[3] + dy;
  219. parentObject.css("left", nx );
  220. parentObject.css("top", ny);
  221. }
  222. });
  223. $( ".floatWindow").on("mouseup",target,function( event ) {
  224. $("#stickingIndictor").hide();
  225. if ($("#stickingIndictor").attr("attach") != ""){
  226. var parentObject = $(focusedObject).parent();
  227. var side = $("#stickingIndictor").attr("attach");
  228. if(checkIfObjectFixedSize(parentObject)){
  229. //This window is fixed size window and cannot be scale to fit half of the screen.
  230. $("#stickingIndictor").attr("attach","");
  231. }else{
  232. var fwWidth = parentObject.width();
  233. var fwHeight = parentObject.height();
  234. if (side == "left"){
  235. parentObject.attr("osize",JSON.stringify([fwWidth,fwHeight,parentObject.offset().left,parentObject.offset().top]));
  236. parentObject.css("left",0);
  237. parentObject.css("right","");
  238. parentObject.css("top",0);
  239. parentObject.css("height","100%").css('height', '-=34px');
  240. parentObject.css("width",$(window).width()/2);
  241. $("#stickingIndictor").attr("attach","");
  242. var maxicon = $(this).find(".small.window.maximize.icon") || $(this).find(".small.window.maximize.icon");
  243. maxicon.parent().html('<i class="small window restore icon"></i>');
  244. }else if (side == "right"){
  245. parentObject.attr("osize",JSON.stringify([fwWidth,fwHeight,parentObject.offset().left,parentObject.offset().top]));
  246. parentObject.css("right",0);
  247. parentObject.css("left","");
  248. parentObject.css("top",0);
  249. if (menuBarVisable){
  250. parentObject.css("height","100%").css('height', '-=34px');
  251. }else{
  252. parentObject.css("height","100%");
  253. }
  254. parentObject.css("top",0);
  255. parentObject.css("width",$(window).width()/2);
  256. $("#stickingIndictor").attr("attach","");
  257. var maxicon = $(this).find(".small.window.maximize.icon") || $(this).find(".small.window.maximize.icon");
  258. maxicon.parent().html('<i class="small window restore icon"></i>');
  259. }
  260. }
  261. }
  262. focusedObject = null;
  263. dragging = false;
  264. $('#backdrop').hide();
  265. $('#iframeCover').hide().appendTo('body');
  266. });
  267. $( ".floatWindow" ).on('touchend',target,function( event ) {
  268. $("#stickingIndictor").hide();
  269. if ($("#stickingIndictor").attr("attach") != ""){
  270. var parentObject = $(focusedObject).parent();
  271. var side = $("#stickingIndictor").attr("attach");
  272. if(checkIfObjectFixedSize(parentObject)){
  273. //This window is fixed size window and cannot be scale to fit half of the screen.
  274. $("#stickingIndictor").attr("attach","");
  275. }else{
  276. var fwWidth = parentObject.width();
  277. var fwHeight = parentObject.height();
  278. if (side == "left"){
  279. parentObject.attr("osize",JSON.stringify([fwWidth,fwHeight,parentObject.offset().left,parentObject.offset().top]));
  280. parentObject.css("left",0);
  281. parentObject.css("right","");
  282. parentObject.css("top",0);
  283. parentObject.css("height","100%").css('height', '-=34px');
  284. parentObject.css("width",$(window).width()/2);
  285. $("#stickingIndictor").attr("attach","");
  286. var maxicon = $(this).find(".small.window.maximize.icon") || $(this).find(".small.window.maximize.icon");
  287. maxicon.parent().html('<i class="small window restore icon"></i>');
  288. }else if (side == "right"){
  289. parentObject.attr("osize",JSON.stringify([fwWidth,fwHeight,parentObject.offset().left,parentObject.offset().top]));
  290. parentObject.css("right",0);
  291. parentObject.css("left","");
  292. if (menuBarVisable){
  293. parentObject.css("height","100%").css('height', '-=34px');
  294. }else{
  295. parentObject.css("height","100%");
  296. }
  297. parentObject.css("top",0);
  298. parentObject.css("width",$(window).width()/2);
  299. $("#stickingIndictor").attr("attach","");
  300. var maxicon = $(this).find(".small.window.maximize.icon") || $(this).find(".small.window.maximize.icon");
  301. maxicon.parent().html('<i class="small window restore icon"></i>');
  302. }
  303. }
  304. }
  305. focusedObject = null;
  306. dragging = false;
  307. $('#backdrop').hide();
  308. $('#iframeCover').hide().appendTo('body');
  309. });
  310. //Resize Window Control Code
  311. var originalResizeBtnSize = [0,0];
  312. var originalColor = "";
  313. $( ".resizeWindow" ).on("mousedown",target,function( event ) {
  314. event.preventDefault();
  315. hidefwListWindow();
  316. focusedObject = event.target;
  317. if (focusedWindow != null && checkFocusWindowIsAlreadyFocused() == false){
  318. //Defocus the previously focued window
  319. //$(focusedWindow).parent().css('z-index',1);
  320. ShiftAllFloatWindowZIndex(true);
  321. }
  322. $(focusedObject).parent().css('z-index',100);
  323. $(focusedObject).parent().css('left',$(focusedObject).parent().offset().left);
  324. $(focusedObject).parent().css('right','');
  325. focusedWindow = focusedObject;
  326. originalResizeBtnSize[0] = parseInt($(focusedObject).css('width').replace("px",""));
  327. originalResizeBtnSize[1] = parseInt($(focusedObject).css('height').replace("px",""));
  328. originalColor = $(focusedObject).css('background-image');
  329. $(focusedObject).css('background','rgba(255,255,255,0.2)');
  330. $(focusedObject).css('width',$(focusedObject).parent().css('width').replace("px",""));
  331. $(focusedObject).css('height',$(focusedObject).parent().css('height').replace("px",""));
  332. resizing = true;
  333. lastPosition[0] = event.pageX;
  334. lastPosition[1] = event.pageY;
  335. lastPosition[2] = parseInt($(focusedObject).parent().css("width").replace("px",""));
  336. lastPosition[3] = parseInt($(focusedObject).parent().css("height").replace("px",""));
  337. $('#backdrop').show();
  338. });
  339. $( ".resizeWindow" ).on('touchstart',target,function( event ) {
  340. event.preventDefault();
  341. hidefwListWindow();
  342. focusedObject = event.target;
  343. if (focusedWindow != null && checkFocusWindowIsAlreadyFocused() == false){
  344. //Defocus the previously focued window
  345. //$(focusedWindow).parent().css('z-index',1);
  346. ShiftAllFloatWindowZIndex(true);
  347. }
  348. $(focusedObject).parent().css('z-index',100);
  349. $(focusedObject).parent().css('left',$(focusedObject).parent().offset().left);
  350. $(focusedObject).parent().css('right','');
  351. focusedWindow = focusedObject;
  352. originalResizeBtnSize[0] = parseInt($(focusedObject).css('width').replace("px",""));
  353. originalResizeBtnSize[1] = parseInt($(focusedObject).css('height').replace("px",""));
  354. originalColor = $(focusedObject).css('background-image');
  355. $(focusedObject).css('background','rgba(255,255,255,0.2)');
  356. $(focusedObject).css('width',$(focusedObject).parent().css('width').replace("px",""));
  357. $(focusedObject).css('height',$(focusedObject).parent().css('height').replace("px",""));
  358. resizing = true;
  359. lastPosition[0] = event.originalEvent.touches[0].pageX;
  360. lastPosition[1] = event.originalEvent.touches[0].pageY;
  361. lastPosition[2] = parseInt($(focusedObject).parent().css("width").replace("px",""));
  362. lastPosition[3] = parseInt($(focusedObject).parent().css("height").replace("px",""));
  363. $('#backdrop').show();
  364. });
  365. function checkIfObjectFixedSize(object){
  366. if(object.find(".maximizeWindow").length == 0){
  367. return true;
  368. }else{
  369. return false;
  370. }
  371. }
  372. $( ".resizeWindow" ).off("click").on("click",function(event){
  373. //The resize window should not be clickable unless the control get stuck due to unknown reason. This function fixes the sticky resize problem
  374. if ($(this).width() > 20 || $(this).height() > 15){
  375. //Something went wrong. Adjust the window size to its origianl size and default class
  376. $(this).removeAttr('style');
  377. $(this).removeClass('resizeWindow').addClass('resizeWindow');
  378. focusedObject = null;
  379. resizing = false;
  380. $('#backdrop').hide();
  381. }
  382. });
  383. $(document, 'body').on("mousemove",target,function( event ) {
  384. if (resizing == true){
  385. //Move the preview div accordingly
  386. if ($(focusedObject).parent().attr("osize") != undefined){
  387. //Set this floatWindow to floating mode if drag during full screen
  388. $(focusedObject).parent().find(".maximizeWindow").html('<i class="small window maximize icon"></i>');
  389. $(focusedObject).parent().removeAttr("osize");
  390. }
  391. var dx = event.pageX - lastPosition[0];
  392. var dy = event.pageY - lastPosition[1];
  393. var nx = lastPosition[2] + dx;
  394. var ny = lastPosition[3] + dy;
  395. if (ny < 120){ny = 120;};
  396. if (nx < 120){nx = 120;};
  397. $(focusedObject).parent().css("width", nx);
  398. $(focusedObject).parent().css("height", ny);
  399. $(focusedObject).css('width',$(focusedObject).parent().css('width').replace("px",""));
  400. $(focusedObject).css('height',$(focusedObject).parent().css('height').replace("px",""));
  401. }else{
  402. var parentObject = $(focusedObject).parent();
  403. if (event.pageX < 5 && checkIfObjectFixedSize(parentObject) == false){
  404. //Window sticking on the left
  405. $("#stickingIndictor").attr("attach",'left');
  406. /*
  407. $("#stickingIndictor").css("left",0);
  408. $("#stickingIndictor").css("right",'');
  409. $("#stickingIndictor").fadeIn('fast');
  410. */
  411. }else if (event.pageX > $(window).width() - 5 && checkIfObjectFixedSize(parentObject) == false){
  412. //Window sticking on the right
  413. $("#stickingIndictor").attr("attach",'right');
  414. /*
  415. $("#stickingIndictor").css("left",'');
  416. $("#stickingIndictor").css("right",0);
  417. $("#stickingIndictor").fadeIn('fast');
  418. */
  419. }else{
  420. $("#stickingIndictor").hide();
  421. $("#stickingIndictor").attr("attach",'');
  422. }
  423. }
  424. });
  425. $(document, 'body').bind('touchmove',target,function( event ) {
  426. if (resizing == true){
  427. //Move the preview div accordingly
  428. var dx = event.originalEvent.touches[0].pageX - lastPosition[0];
  429. var dy = event.originalEvent.touches[0].pageY - lastPosition[1];
  430. var nx = lastPosition[2] + dx;
  431. var ny = lastPosition[3] + dy;
  432. if (ny < 120){ny = 120;};
  433. if (nx < 120){nx = 120;};
  434. $(focusedObject).parent().css("width", nx);
  435. $(focusedObject).parent().css("height", ny);
  436. $(focusedObject).css('width',$(focusedObject).parent().css('width').replace("px",""));
  437. $(focusedObject).css('height',$(focusedObject).parent().css('height').replace("px",""));
  438. }else{
  439. var parentObject = $(focusedObject).parent();
  440. if (event.originalEvent.touches[0].pageX < 5 && checkIfObjectFixedSize(parentObject) == false){
  441. //Window docking on the left
  442. $("#stickingIndictor").attr("attach",'left');
  443. /*
  444. $("#stickingIndictor").css("left",0);
  445. $("#stickingIndictor").css("right",'');
  446. $("#stickingIndictor").fadeIn('fast');*/
  447. }else if (event.originalEvent.touches[0].pageX > $(window).width() - 5 && checkIfObjectFixedSize(parentObject) == false){
  448. //Window docking on the right
  449. $("#stickingIndictor").attr("attach",'right');
  450. /*
  451. $("#stickingIndictor").css("left",'');
  452. $("#stickingIndictor").css("right",0);
  453. $("#stickingIndictor").fadeIn('fast');
  454. */
  455. }else{
  456. $("#stickingIndictor").hide();
  457. $("#stickingIndictor").attr("attach",'');
  458. }
  459. }
  460. });
  461. $( ".resizeWindow" ).on("mouseup",target,function( event ) {
  462. $(focusedObject).css('width',originalResizeBtnSize[0]);
  463. $(focusedObject).css('height',originalResizeBtnSize[1]);
  464. $(focusedObject).css('background-color','');
  465. $(focusedObject).css('background-image',originalColor);
  466. focusedObject = null;
  467. resizing = false;
  468. $('#backdrop').hide();
  469. });
  470. $( ".resizeWindow" ).on('touchend',function( event ) {
  471. $(focusedObject).css('width',originalResizeBtnSize[0]);
  472. $(focusedObject).css('height',originalResizeBtnSize[1]);
  473. $(focusedObject).css('background-color','');
  474. $(focusedObject).css('background-image',originalColor);
  475. focusedObject = null;
  476. resizing = false;
  477. $('#backdrop').hide();
  478. });
  479. $(document, 'body').on("mouseup",target,function( event ) {
  480. //Resize mouse go outside of the resizing window area
  481. //Just in case there are noobs that don't know how to resize a window properly
  482. if (resizing == true){
  483. $(focusedObject).css('width',originalResizeBtnSize[0]);
  484. $(focusedObject).css('height',originalResizeBtnSize[1]);
  485. $(focusedObject).css('background-color',originalColor);
  486. focusedObject = null;
  487. resizing = false;
  488. $('#backdrop').hide();
  489. }
  490. //Just in case someone who don't know how to adjust volume correctly
  491. VolAreaMouseDown=false;
  492. });
  493. $(document, 'body').on('touchend',target,function( event ) {
  494. //Resize mouse go outside of the resizing window area
  495. //Just in case there are noobs that don't know how to resize a window properly
  496. if (resizing == true){
  497. $(focusedObject).css('width',originalResizeBtnSize[0]);
  498. $(focusedObject).css('height',originalResizeBtnSize[1]);
  499. $(focusedObject).css('background-color',originalColor);
  500. focusedObject = null;
  501. resizing = false;
  502. $('#backdrop').hide();
  503. //Just in case someone who don't know how to adjust volume correctly
  504. VolAreaMouseDown=false;
  505. }
  506. });
  507. //Floating Window closing
  508. $(".floatWindow > .closeWindow").on("mousedown",target,function(event){
  509. focusedObject = event.target;
  510. hidefwListWindow();
  511. if ($(event.target).prop('nodeName') == "I"){
  512. focusedObject = $(focusedObject).parent();
  513. }
  514. dragging = false;
  515. //Updated on 15-3-2019, check if the module contain any onclose script. If there is, use its onClose script instead.
  516. try {
  517. if ($(focusedObject).parent().parent().find("iframe")[0] != undefined && $(focusedObject).parent().parent().find("iframe")[0].contentWindow != undefined && $(focusedObject).parent().parent().find("iframe")[0].contentWindow.ao_module_close && typeof $(focusedObject).parent().parent().find("iframe")[0].contentWindow.ao_module_close === "function") {
  518. //Use ao_module_close to handle the window close instead of killing it
  519. //aka Ask the module to close itself
  520. $(focusedObject).parent().parent().find("iframe")[0].contentWindow.ao_module_close();
  521. return;
  522. }
  523. }catch(err){
  524. //This might happens when the target iframe contain external contents (hence CORS error). If that is the case, continue to process the force kill action.
  525. }
  526. var divLayer = $(focusedObject).parent().parent();
  527. var divid = divLayer.attr('id');
  528. divLayer.remove();
  529. //Section of code to remove grouped floatWindow button from menu bar
  530. removeFloatWindowFromMenuBarByID(divid);
  531. floatWindowCount --;
  532. });
  533. $(".floatWindow > .closeWindow").on('touchstart',target,function(event){
  534. focusedObject = event.target;
  535. hidefwListWindow();
  536. if ($(event.target).prop('nodeName') == "I"){
  537. focusedObject = $(focusedObject).parent();
  538. }
  539. dragging = false;
  540. //Updated on 15-3-2019, check if the module contain any onclose script. If there is, use its onClose script instead.
  541. if ($(focusedObject).parent().parent().find("iframe")[0] != undefined && $(focusedObject).parent().parent().find("iframe")[0].contentWindow != undefined && $(focusedObject).parent().parent().find("iframe")[0].contentWindow.ao_module_close && typeof $(focusedObject).parent().parent().find("iframe")[0].contentWindow.ao_module_close === "function") {
  542. //Use ao_module_close to handle the window close instead of killing it
  543. //aka Ask the module to close itself
  544. $(focusedObject).parent().parent().find("iframe")[0].contentWindow.ao_module_close();
  545. return;
  546. };
  547. var divLayer = $(focusedObject).parent().parent();
  548. var divid = divLayer.attr('id');
  549. divLayer.remove();
  550. //Section of code to remove grouped floatWindow button from menu bar
  551. removeFloatWindowFromMenuBarByID(divid);
  552. floatWindowCount --;
  553. });
  554. //Floating Window Minimizing
  555. $(".floatWindow > .minimizeWindow").on("mousedown",target,function(event){
  556. focusedObject = event.target;
  557. if ($(event.target).prop('nodeName') == "I"){
  558. focusedObject = $(focusedObject).parent();
  559. }
  560. dragging = false;
  561. var divLayer = $(focusedObject).parent().parent();
  562. animationFinished = false;
  563. divLayer.fadeOut('fast',function(){
  564. animationFinished = true;
  565. });
  566. var divid = divLayer.attr('id');
  567. //$('#' + divid + 'Btn').css('background-color','#444');
  568. $('#' + divid + 'Btn').removeClass("active");
  569. });
  570. $(".floatWindow > .minimizeWindow").on('touchstart',target,function(event){
  571. focusedObject = event.target;
  572. if ($(event.target).prop('nodeName') == "I"){
  573. focusedObject = $(focusedObject).parent();
  574. }
  575. dragging = false;
  576. var divLayer = $(focusedObject).parent().parent();
  577. divLayer.fadeOut('fast',function(){
  578. animationFinished = true;
  579. });
  580. var divid = divLayer.attr('id');
  581. //$('#' + divid + 'Btn').css('background-color','#444');
  582. $('#' + divid + 'Btn').removeClass("active");
  583. });
  584. //Float Window Maximizing
  585. $(".floatWindow > .maximizeWindow").off("mousedown").on("mousedown",target,function(event){
  586. focusedObject = event.target;
  587. if ($(event.target).prop('nodeName') == "I"){
  588. focusedObject = $(focusedObject).parent();
  589. }
  590. dragging = false;
  591. var divLayer = $(focusedObject).parent().parent();
  592. animationFinished = false;
  593. var windowWidth = $( window ).width();
  594. var windowHeight = $( window ).height();
  595. var fwWidth = divLayer.width();
  596. var fwHeight = divLayer.height();
  597. if (divLayer.attr("osize") != undefined){
  598. //Set this floatWindow to floating mode
  599. //console.log($(focusedObject).parent().parent().find(".maximizeWindow"));
  600. var restorePoint = JSON.parse(divLayer.attr("osize"));
  601. divLayer.css("width",restorePoint[0]);
  602. divLayer.css("height",restorePoint[1]);
  603. divLayer.css("top",restorePoint[3]);
  604. divLayer.css("left",restorePoint[2]);
  605. divLayer.removeAttr("osize");
  606. $(this).html('<i class="small window maximize icon"></i>');
  607. }else{
  608. //Set this floatWindow to full screen mode
  609. var posx = divLayer.css("left");
  610. var posy = divLayer.css("top");
  611. divLayer.css("width","100%");
  612. if (menuBarVisable){
  613. divLayer.css("height","100%").css('height', '-=34px');
  614. }else{
  615. divLayer.css("height","100%");
  616. }
  617. divLayer.css("top",0);
  618. divLayer.css("left",0);
  619. divLayer.attr("osize",JSON.stringify([fwWidth,fwHeight,posx,posy]));
  620. $(this).html('<i class="small window restore icon"></i>');
  621. }
  622. });
  623. $(".floatWindow > .maximizeWindow").off("touchstart").on('touchstart',target,function(event){
  624. focusedObject = event.target;
  625. if ($(event.target).prop('nodeName') == "I"){
  626. focusedObject = $(focusedObject).parent();
  627. }
  628. dragging = false;
  629. var divLayer = $(focusedObject).parent().parent();
  630. animationFinished = false;
  631. var windowWidth = $( window ).width();
  632. var windowHeight = $( window ).height();
  633. var fwWidth = divLayer.width();
  634. var fwHeight = divLayer.height();
  635. if (divLayer.attr("osize") != undefined){
  636. //Set this floatWindow to floating mode
  637. //console.log(divLayer.attr("osize"));
  638. var restorePoint = JSON.parse(divLayer.attr("osize"));
  639. divLayer.css("width",restorePoint[0]);
  640. divLayer.css("height",restorePoint[1]);
  641. divLayer.css("top",restorePoint[3]);
  642. divLayer.css("left",restorePoint[2]);
  643. divLayer.removeAttr("osize");
  644. $(this).html('<i class="small window maximize icon"></i>');
  645. }else{
  646. //Set this floatWindow to full screen mode
  647. var posx = divLayer.css("left");
  648. var posy = divLayer.css("top");
  649. divLayer.css("width",windowWidth);
  650. if (menuBarVisable){
  651. divLayer.css("height","100%").css('height', '-=34px');
  652. }else{
  653. divLayer.css("height","100%");
  654. }
  655. divLayer.css("top",0);
  656. divLayer.css("left",0);
  657. divLayer.attr("osize",JSON.stringify([fwWidth,fwHeight,posx,posy]));
  658. $(this).html('<i class="small window restore icon"></i>');
  659. }
  660. });
  661. $( ".floatWindow" ).off("dblclick").on("dblclick",function(event) {
  662. //Double click will also enter full screen mode
  663. focusedObject = event.target;
  664. if ($(focusedObject).parent().find(".resizeWindow").length == 0){
  665. //This window is not resizable
  666. return;
  667. }
  668. dragging = false;
  669. var divLayer = $(focusedObject).parent();
  670. animationFinished = false;
  671. var windowWidth = $( window ).width();
  672. var windowHeight = $( window ).height();
  673. var fwWidth = divLayer.width();
  674. var fwHeight = divLayer.height();
  675. if (divLayer.attr("osize") != undefined){
  676. //Set this floatWindow to floating mode
  677. //console.log(divLayer.attr("osize"));
  678. var restorePoint = JSON.parse(divLayer.attr("osize"));
  679. divLayer.css("width",restorePoint[0]);
  680. divLayer.css("height",restorePoint[1]);
  681. divLayer.css("top",restorePoint[3]);
  682. divLayer.css("left",restorePoint[2]);
  683. divLayer.removeAttr("osize");
  684. var maxicon = $(this).find(".small.window.restore.icon");
  685. maxicon.parent().html('<i class="small window maximize icon"></i>');
  686. }else{
  687. //Set this floatWindow to full screen mode
  688. var posx = divLayer.css("left");
  689. var posy = divLayer.css("top");
  690. divLayer.css("width",windowWidth);
  691. if (menuBarVisable){
  692. divLayer.css("height","100%").css('height', '-=34px');
  693. }else{
  694. divLayer.css("height","100%");
  695. }
  696. divLayer.css("top",0);
  697. divLayer.css("left",0);
  698. divLayer.attr("osize",JSON.stringify([fwWidth,fwHeight,posx,posy]));
  699. var maxicon = $(this).find(".small.window.maximize.icon");
  700. maxicon.parent().html('<i class="small window restore icon"></i>');
  701. }
  702. });
  703. }
  704. //END OF PAGE MOTION BINDING
  705. //Standard Menu Control Code
  706. function removeFloatWindowFromMenuBarByID(divid){
  707. //Remove floatWindow from Menu / bottom bar /
  708. if ($('#' + divid + 'Btn').length > 0){
  709. //Check if the button is shared by multiple floatWindows. If yes, keep it remained here
  710. var idlist = JSON.parse(decodeURIComponent($('#' + divid + 'Btn').attr("floatWindowUID")));
  711. idlist = idlist.map(String)
  712. if (idlist.length == 1 && idlist.includes(divid.toString())){
  713. //This is the only floatWindow that is using this button
  714. $('#' + divid + 'Btn').remove();
  715. }else{
  716. //If the btn named as this floatWindow uid, that means this is the first item in array
  717. for (var i = 0; i < idlist.length; i++){
  718. if (idlist[i] == divid){
  719. idlist.splice(i,1);
  720. }
  721. }
  722. $('#' + divid + 'Btn').attr("floatWindowUID",encodeURIComponent(JSON.stringify(idlist)));
  723. $('#' + divid + 'Btn').attr("id",idlist[0] + "Btn");
  724. $('#' + idlist[0] + 'Btn').css("border-right",idlist.length - 1 + "px solid white");
  725. }
  726. }else{
  727. //This is a floatWindow get grouped into an already existing button. The only method to remove it is search each btn until one match is found
  728. var targetBtn = "";
  729. divid = divid.toString();
  730. $(".listMenuButton").each(function(){
  731. var idlist = JSON.parse(decodeURIComponent($(this).attr("floatWindowUID")));
  732. idlist = idlist.map(String)
  733. if (idlist.includes(divid)){
  734. targetBtn = $(this).attr("id");
  735. }
  736. });
  737. if (targetBtn == ""){
  738. //floatWindow already closed
  739. return;
  740. }
  741. var idlist = JSON.parse(decodeURIComponent($("#" + targetBtn).attr("floatWindowUID")));
  742. idlist = idlist.map(String)
  743. for (var i = 0; i < idlist.length; i++){
  744. if (idlist[i] == divid){
  745. idlist.splice(i,1);
  746. }
  747. }
  748. $("#" + targetBtn).attr("floatWindowUID",encodeURIComponent(JSON.stringify(idlist)));
  749. $("#" + targetBtn).css("border-right",idlist.length - 1 + "px solid white");
  750. }
  751. }
  752. /**
  753. function closeAndReloadIframe(){
  754. fileExplorerVisable = false;
  755. $('#fileMenu').hide();
  756. $('#folderBtn').css('background-color','#333');
  757. $('#filebrowser').attr('src', 'SystemAOB/functions/file_system/embedded.php?controlLv=2')
  758. }
  759. **/
  760. function AddWindows(){
  761. $('#addWindow').clearQueue()
  762. $('#addWindow').stop()
  763. var startingLeft = $('#moreBtn').offset().left;
  764. $('#addWindow').css('left',startingLeft);
  765. var visable = ($('#addWindow').css('display') != 'none');
  766. $('#addWindow').fadeToggle('fast',function(){
  767. if (visable == true){
  768. //$('#moreBtn').css('background-color','#222');
  769. $('#moreBtn').removeClass("active");
  770. }else{
  771. //$('#moreBtn').css('background-color','#333');
  772. $('#moreBtn').addClass("active");
  773. }
  774. });
  775. }
  776. function LaunchFloatWindowFromModule(module, suppressAddWindow=false){
  777. $('#newWindow iframe').attr('src',module + "/FloatWindow.php");
  778. if (!suppressAddWindow){
  779. AddWindows();
  780. }
  781. }
  782. function TooglePowerManuel(btn){
  783. $('#powerMenu').clearQueue()
  784. $('#powerMenu').stop()
  785. if (powerManualVisable == false){
  786. $('#powerMenu').fadeToggle('fast');
  787. powerManualVisable = true;
  788. }else{
  789. $('#powerMenu').fadeToggle('fast');
  790. powerManualVisable = false;
  791. }
  792. }
  793. function ToogleMenuBar(){
  794. $('#menuBar').clearQueue()
  795. $('#menuBar').stop()
  796. if (menuBarVisable == false){
  797. //Show it
  798. $('#menuBar').fadeToggle("fast");
  799. $('#showMenuButton').fadeToggle("fast");
  800. menuBarVisable = true;
  801. }else{
  802. //Hide it
  803. $('#menuBar').fadeToggle("fast");
  804. $('#showMenuButton').fadeToggle("fast");
  805. if (powerManualVisable == true){
  806. $('#powerMenu').hide();
  807. powerManualVisable = false;
  808. }
  809. $("#USBList").fadeOut('fast');
  810. menuBarVisable = false;
  811. //And hide all the other related windows
  812. $('#powerMenu').fadeOut('fast');
  813. powerManualVisable = false;
  814. }
  815. }
  816. function ToogleFileExplorer(){
  817. var uid = Date.now();
  818. newEmbededWindow("SystemAOB/functions/file_system/index.php?controlLv=2", "Loading", "folder open outline",uid,1080,580,undefined,undefined,true,false);
  819. /**
  820. //Deprecated, replaced with a function that open a new file explorer instead
  821. $('#fileMenu').clearQueue()
  822. $('#fileMenu').stop()
  823. if (fileExplorerVisable == false){
  824. $('#fileMenu').fadeToggle('fast');
  825. $('#folderBtn').css('background-color','#222');
  826. focusFloatWindow('fileMenu');
  827. fileExplorerVisable = true;
  828. }else{
  829. $('#fileMenu').fadeToggle('fast');
  830. $('#folderBtn').css('background-color','#444');
  831. fileExplorerVisable = false;
  832. }
  833. **/
  834. }
  835. jQuery.fn.justtext = function() {
  836. return $(this) .clone()
  837. .children()
  838. .remove()
  839. .end()
  840. .text();
  841. };
  842. function newEmbededWindow(src, title, iconTag="folder", uid ,ww=720, wh=480, posx=100, posy=100, resizable=true, glassEffect=false, parentUID=null, callbackFunct=null,headless=false){
  843. if (floatWindowCount >= 50){
  844. //Reaching the maximum number of floating windows.
  845. return false;
  846. }
  847. //Check if the window already exists. If yes, only update the src of the iframe
  848. if ( $('#' + uid).length > 0 ){
  849. updateFloatWindowTitle(uid,title);
  850. $('#' + uid + ' iframe').attr('src',src);
  851. if ( $('#' + uid).css("display") == "none"){
  852. $('#' + uid).fadeIn('fast');
  853. //$('#' + uid + 'Btn').css('background-color','#222');
  854. $('#' + uid + 'Btn').addClass("active");
  855. }
  856. focusFloatWindow(uid);
  857. return;
  858. }
  859. //This function will perform automatic Motion Binding after the window is being build
  860. $.when( openFloatWindow(src,title,iconTag,uid,ww,wh,posx,posy,resizable,glassEffect,parentUID,callbackFunct,headless) ).done(function() {
  861. bindMotions(uid);
  862. killDragging();
  863. });
  864. }
  865. function focusFloatWindow(uid){
  866. focusedObject = $('#' + uid + " .floatWindow");
  867. if (focusedWindow != null && checkFocusWindowIsAlreadyFocused() == false){
  868. //Defocus the previously focued window
  869. ShiftAllFloatWindowZIndex();
  870. //$(focusedWindow).parent().css('z-index',1);
  871. }
  872. //Focus the new window
  873. $(focusedObject).parent().css('z-index',100);
  874. focusedWindow = focusedObject;
  875. }
  876. function checkFocusWindowIsAlreadyFocused(){
  877. if ($(focusedObject).parent().attr("id") == $(focusedWindow).parent().attr("id")){
  878. return true;
  879. }else{
  880. return false;
  881. }
  882. }
  883. function ShiftAllFloatWindowZIndex(onlyShiftFrontWindows = false){
  884. var previousFocusedObjectZIndex = $(focusedObject).parent().css('z-index');
  885. if (onlyShiftFrontWindows){
  886. $('.floatWindow').each(function(i) {
  887. //Shift all the floatWindows z-index by two (leaving one gap for the background cover)
  888. if ($(this).parent().css("z-index") > previousFocusedObjectZIndex - 2 && $(this).parent().attr("id") != "newWindow"){
  889. //console.log($(this).parent().css("z-index"));
  890. var newindex = $(this).parent().css("z-index") - 2;
  891. $(this).parent().css("z-index",newindex);
  892. }
  893. });
  894. }else{
  895. $('.floatWindow').each(function(i) {
  896. //Shift all the floatWindows z-index by two (leaving one gap for the background cover)
  897. if ($(this).parent().css("z-index") > 2 && $(this).parent().attr("id") != "newWindow"){
  898. var newindex = $(this).parent().css("z-index") - 2;
  899. $(this).parent().css("z-index",newindex);
  900. }
  901. });
  902. }
  903. }
  904. //Replace the title of a FloatWindow
  905. function updateFloatWindowTitle(uid,title){
  906. var oldTitle = $('#' + uid + " .floatWindow").justtext();
  907. if (title != oldTitle){
  908. //The title changed. Update the title to the new one
  909. var newHTML = $('#' + uid + " .floatWindow").html().replace(oldTitle.trim(),title);
  910. $('#' + uid + " .floatWindow").html(newHTML);
  911. bindMotions(uid);
  912. }
  913. }
  914. function checkoverlap(posx,posy){
  915. var result = false;
  916. $(".floatWindow").each(function(){
  917. if ($(this).offset().left == posx && $(this).offset().top == posy){
  918. result = true;
  919. }
  920. });
  921. return result;
  922. }
  923. //Open a new Windows
  924. function openFloatWindow(src, title, iconTag="folder", uid ,ww=720, wh=480, posx=100, posy=100, resizable=true, glassEffect=false, parentUID=null, callbackFunct=null,headless=false){
  925. //src: The path in which the new window points to
  926. //title: The title text that displace on the window top bar
  927. //iconTag: The icon used for the window label and buttons. Reference Tocas UI for the iconTag information
  928. //uid: The uid is the unique id for this window.
  929. //ww, wh: Window Width, Window Height
  930. //posx, posy: Window Position x, Window Position y
  931. var template = $('#newWindow');
  932. var newWindow = template.clone(true).appendTo('body');
  933. newWindow.attr('id',uid);
  934. //Check if there are cached window size. If yes, replace the default pass in
  935. var cache = checkCachedWindowSize(src);
  936. if (cache !== false){
  937. ww = cache[0];
  938. wh = cache[1];
  939. }
  940. //Handle the window popup location
  941. if (ww > $(document).width()){
  942. ww = $(document).width();
  943. posx = 0;
  944. }
  945. if (wh > $(document).height()){
  946. wh = $(document).height() - 35;
  947. posy = 0;
  948. }
  949. //If it is the default value, check if there are any windows overlapping the position
  950. var tmpcounter = 0; //Killswitch for while loop
  951. if (posx == 100 && posy == 100){
  952. while(checkoverlap(posx,posy) == true && tmpcounter < 50){
  953. posx += 30;
  954. posy += 30;
  955. if (posy > window.innerHeight - 25){
  956. posy = 115;
  957. }
  958. if (posx > window.innerWidth - 25){
  959. posx = 115;
  960. }
  961. tmpcounter++;
  962. }
  963. }
  964. newWindow.css({'left':posx,'top':posy,'width':ww,'height':wh});
  965. if (glassEffect == true){
  966. newWindow.css("background-color","");
  967. newWindow.css("border","0px solid transparent");
  968. newWindow.find(".floatWindow").css("background-color",$('.fwPanelColor').css("background-color"));
  969. newWindow.find(".floatWindow").css("padding-top","1px");
  970. newWindow.find(".floatWindow").find(".closeWindow").css("top","2px");
  971. newWindow.find(".floatWindow").find(".minimizeWindow").css("top","4px");
  972. newWindow.css("box-shadow","1px 1px 4px #3d3d3d");
  973. }
  974. $('#' + uid + ' iframe').attr('src',src);
  975. var newHTML = newWindow.html();
  976. newHTML = newHTML.replace("%WINDOW_TITLE%",decodeURIComponent(title));
  977. newHTML = newHTML.replace("folder icon",iconTag + " icon");
  978. if (resizable == false){
  979. newHTML = newHTML.replace('<div class="resizeWindow" align="center"></div>','');
  980. newHTML = newHTML.replace('<div style="top:5px;right:25px;cursor: pointer;position:absolute;" class="maximizeWindow"><i class="small window maximize icon"></i></div>','');
  981. if (!glassEffect){
  982. newHTML = newHTML.replace('<div style="top:5px;right:47px;cursor: pointer;position:absolute;" class="minimizeWindow"><i class="minus icon"></i></div>','<div style="top:5px;right:25px;cursor: pointer;position:absolute;" class="minimizeWindow"><i class="minus icon"></i></div>');
  983. }else{
  984. newHTML = newHTML.replace('<div style="top: 4px; right: 47px; cursor: pointer; position: absolute;" class="minimizeWindow"><i class="minus icon"></i></div>','<div style="top:5px;right:25px;cursor: pointer;position:absolute;" class="minimizeWindow"><i class="minus icon"></i></div>');
  985. }
  986. }
  987. //Append the parentUID into the window of the child object so it can know who its parent is
  988. if (parentUID != null){
  989. newHTML = ($(newHTML).attr("puid",parentUID));
  990. //Check if parent request a call back. If yes, this will be passed to the child as well
  991. if (callbackFunct != null){
  992. newHTML = ($(newHTML).attr("callback",callbackFunct));
  993. }
  994. }
  995. newWindow.html(newHTML);
  996. //newWindow.fadeIn('fast');
  997. //Increase the speed of the window loading time
  998. newWindow.fadeIn(100);
  999. if (!headless){
  1000. AppendNewIcon(iconTag,uid,src);
  1001. }
  1002. focusFloatWindow(uid);
  1003. floatWindowCount++;
  1004. }
  1005. //Append new icon to the menu bar
  1006. function AppendNewIcon(iconTag,uid,src){
  1007. var moduleBase = src.split("/").shift();
  1008. //If the moduleBase is came from desktop or systemaob, special processing is needed
  1009. if (moduleBase.toLowerCase() == "systemaob" || moduleBase.toLowerCase() == "desktop"){
  1010. //Only group those start the same script base which is under SystemAOB
  1011. if (moduleBase.toLowerCase() == "systemaob" || src.includes(".php")){
  1012. var pathdata = src.split(".php")[0].split("/");
  1013. moduleBase = pathdata.pop();
  1014. if (moduleBase == "index"){
  1015. //This might be a module inside function group (e.g. file_system/index.php), group it as file_system
  1016. moduleBase = pathdata.pop();
  1017. }
  1018. }else{
  1019. //This is a desktop module. One button per floatWindow is needed
  1020. var template = '<div id="' + uid + 'Btn" floatWindowUID="' + encodeURIComponent(JSON.stringify([uid])) +'" moduleBase="' + moduleBase + '" class="fbicon listMenuButton menuButton active" style="cursor: pointer;height:60px;" onClick="ToggleFloatWindow(this);"><i class="' + iconTag +' icon" style="line-height: 35px;"></i></div>';
  1021. $('#activatedModuleIcons').append(template);
  1022. $('#' + uid + "Btn").insertAfter('#folderBtn');
  1023. return;
  1024. }
  1025. }
  1026. if (src.includes("http") && src.includes("://")){
  1027. //Some stupid modules are passing in a fullpath (i.e. http://your_ip_here/aob/module/.....)
  1028. //Strip from the back instead.
  1029. var pathdata = src.split("/");
  1030. moduleBase = pathdata[pathdata.length - 2];
  1031. }
  1032. //console.log(src,moduleBase);
  1033. //Try to merge any windows that came from the same base Module
  1034. //First, check if there is already a button that have the same base module.
  1035. var sameBaseModuleButton = "";
  1036. $(".listMenuButton").each(function(){
  1037. var thisModuleBase = $(this).attr("moduleBase");
  1038. if(thisModuleBase.toLowerCase() == moduleBase.toLowerCase()){
  1039. sameBaseModuleButton = $(this).attr("id");
  1040. }
  1041. });
  1042. if (sameBaseModuleButton == ""){
  1043. //There is no similar matches. Append a new button
  1044. var template = '<div id="' + uid + 'Btn" floatWindowUID="' + encodeURIComponent(JSON.stringify([uid])) +'" moduleBase="' + moduleBase + '" class="fbicon listMenuButton menuButton active" style="cursor: pointer;height:60px;" onClick="ToggleFloatWindow(this);"><i class="' + iconTag +' icon" style="line-height: 35px;"></i></div>';
  1045. $('#activatedModuleIcons').append(template);
  1046. $('#' + uid + "Btn").insertAfter('#folderBtn');
  1047. }else{
  1048. //There is a button with the same type. Append to its floatWindowUIDs
  1049. var appendTarget = $("#" + sameBaseModuleButton);
  1050. var UIDList = JSON.parse(decodeURIComponent(appendTarget.attr("floatWindowUID")));
  1051. UIDList.push(uid);
  1052. var sideBorderWidth = UIDList.length - 1;
  1053. appendTarget.attr("floatWindowUID",encodeURIComponent(JSON.stringify(UIDList)));
  1054. appendTarget.css("border-right",sideBorderWidth + "px solid white");
  1055. }
  1056. /**
  1057. //Deprecated "single icon single fw" method, updated on 15-3-2019
  1058. var template = '<div id="%UID%" class="one wide column fbicon" style="cursor: pointer;background-color: #222;height:60px;" onClick="ToggleFloatWindow(' + "'" + uid +"'" + ');"><i class="%TAG% icon" style="line-height: 35px;"></i></div>';
  1059. template = template.replace("%UID%",uid + "Btn");
  1060. template = template.replace("%TAG%",iconTag);
  1061. $('#activatedModuleIcons').append(template);
  1062. $('#' + uid + "Btn").insertAfter('#folderBtn');
  1063. **/
  1064. }
  1065. //Hiding a window with btn
  1066. function ToggleFloatWindow(object){
  1067. var idlist = JSON.parse(decodeURIComponent($(object).attr("floatWindowUID")));
  1068. if (idlist.length == 1){
  1069. hidefwListWindow();
  1070. id = idlist[0];
  1071. if ($('#' + id).css('display') == 'none'){
  1072. //If the window is going to show, focus it
  1073. focusFloatWindow(id);
  1074. }
  1075. if ($('#' + id).css("z-index") < 100){
  1076. //This window is at the back of some other windows --> Bring it in front
  1077. focusFloatWindow(id);
  1078. }else{
  1079. //This window has already been focused
  1080. $('#' + id).fadeToggle('fast',function(){
  1081. if ($('#' + id).css('display') == 'none') {
  1082. //The floatwindow is now hidden
  1083. //$('#' + id + 'Btn').css('background-color','#444');
  1084. $('#' + id + 'Btn').removeClass("active");
  1085. }else{
  1086. //The floatwindow is now shown
  1087. //$('#' + id + 'Btn').css('background-color','#222');
  1088. $('#' + id + 'Btn').addClass("active");
  1089. }
  1090. });
  1091. }
  1092. }else{
  1093. //There are multiple windows hidden inside this button. Use floatWindowListWindow to show all of them.
  1094. var position = [$(object).offset().left,$(object).offset().top];
  1095. var buttonModuleBase = $(object).attr("moduleBase").trim();
  1096. $("#fwListWindow").html("");
  1097. //Load the window with all the grouped window properties
  1098. for (var i = 0; i < idlist.length; i++){
  1099. var details = getIconAndTitleFromFloatWindow(idlist[i]); //return [windowTitle,icon]
  1100. if (details != false){
  1101. var icon = details[1];
  1102. var windowTitle = details[0];
  1103. var displayBox = '<div class="selectable fwListBtn" style="border:1px solid transparent;padding:5px;padding-right:20px;" floatWindowUID="'+ encodeURIComponent(JSON.stringify([idlist[i]])) + '" onClick="ToggleFloatWindow(this);">\
  1104. <p class="ts inverted header"\ style="font-size:0.9em;">\
  1105. <i class="mini ' + icon + '"></i>' + windowTitle + '\
  1106. <button style="position:absolute;right:0px;top:3px;margin-right:-23px;color:white;cursor:pointer;" onClick="closeFromFWListWindow(this);"><i class="remove icon"></i></button>\
  1107. </p>\
  1108. </div>';
  1109. $("#fwListWindow").append(displayBox);
  1110. }else{
  1111. //console.log("CRITICAL ERROR! Unable to parse floatWindow data from attributes. Please refresh this page.");
  1112. }
  1113. }
  1114. if ($("#fwListWindow").attr("dockedModuleBase") != buttonModuleBase){
  1115. //Move and show the floatWindowListWindow
  1116. $("#fwListWindow").css("left",position[0] + "px").attr("dockedModuleBase",buttonModuleBase);
  1117. //Animated slideUp to show code
  1118. var div = $("#fwListWindow:not(:visible)");
  1119. var height = div.css({
  1120. display: "block"
  1121. }).height();
  1122. div.css({
  1123. overflow: "hidden",
  1124. height: 0
  1125. }).animate({
  1126. height: height
  1127. }, 200, function () {
  1128. $(this).css({
  1129. display: "",
  1130. overflow: "",
  1131. height: ""
  1132. });
  1133. });
  1134. }else{
  1135. //Click twice on the same button
  1136. hidefwListWindow();
  1137. }
  1138. }
  1139. }
  1140. function closeFromFWListWindow(object){
  1141. $(object).parent().parent().hide();
  1142. var fwWindowID = $(object).parent().parent().attr("floatWindowUID");
  1143. fwWindowID = JSON.parse(decodeURIComponent(fwWindowID));
  1144. closeWindow(fwWindowID);
  1145. }
  1146. function hidefwListWindow(){
  1147. //Animated slideDown to hide code
  1148. if ( $("#fwListWindow").is(':visible')){
  1149. $("#fwListWindow").attr("dockedModuleBase","");
  1150. var div = $("#fwListWindow");
  1151. var height = div.height();
  1152. div.css({
  1153. overflow: "hidden",
  1154. marginTop: 0,
  1155. height: height
  1156. }).animate({
  1157. marginTop: height,
  1158. height: 0
  1159. }, 200, function () {
  1160. $(this).css({
  1161. display: "none",
  1162. overflow: "",
  1163. height: "",
  1164. marginTop: ""
  1165. });
  1166. });
  1167. }
  1168. }
  1169. function getIconAndTitleFromFloatWindow(uid){
  1170. if ($("#" + uid).length > 0){
  1171. var target = $("#" + uid).find(".floatWindow")[0];
  1172. var windowTitle = $(target).text().trim();
  1173. var icon = $(target).find("i").attr("class");
  1174. return [windowTitle,icon];
  1175. }else{
  1176. console.log("ERROR. floatWindow with ID " + uid + " not found.");
  1177. return false;
  1178. }
  1179. }
  1180. /*
  1181. function ToogleHS(){
  1182. $('#HostServer').clearQueue()
  1183. $('#HostServer').stop()
  1184. if ($('#HostServer').css('display') == 'none'){
  1185. focusFloatWindow('HostServer');
  1186. }
  1187. $('#HostServer').fadeToggle('fast',function(){
  1188. //Check if the window is shown, change button color
  1189. if ($('#HostServer').css('display') != 'none'){
  1190. //The window is now shown
  1191. $('#diskBtn').css('background-color','#222');
  1192. //$('#hostView').attr('src','SystemAOB/functions/system_statistic/index.php');
  1193. }else{
  1194. //The window is now hidden
  1195. $('#diskBtn').css('background-color','#444');
  1196. }
  1197. });
  1198. }
  1199. function CloseHS(){
  1200. $('#HostServer').clearQueue()
  1201. $('#HostServer').stop()
  1202. $('#HostServer').hide();
  1203. $('#hostView').attr('src','SystemAOB/functions/system_statistic/index.php');
  1204. $('#diskBtn').css('background-color','#333');
  1205. }
  1206. */
  1207. //Simple Clock Script
  1208. var myVar = setInterval(function() {
  1209. myTimer();
  1210. GvolDisplay();
  1211. FloatWindowWatchDog();
  1212. }, 1000);
  1213. function myTimer() {
  1214. var d = new Date();
  1215. document.getElementById("clock").innerHTML = d.toLocaleTimeString();
  1216. }
  1217. //Display the global volume of the system set by other modules
  1218. function GvolDisplay(){
  1219. var vol = Math.round(GetStorage('global_volume') * 100);
  1220. $('#gVol').html('<i class="volume down icon"></i>' + vol + "%");
  1221. $('#volDisplay').css('width',vol + '%');
  1222. }
  1223. //Update URL onto the window top location
  1224. function updateURL(){
  1225. var iframePath = document.getElementById("interface").contentDocument.location.href;
  1226. //var baseUrl = window.location.href.split('#')[0];
  1227. //window.location.replace( baseUrl + '#' + iframePath.replace(initialURL,""));
  1228. //window.location.hash = iframePath.replace(initialURL,"");
  1229. if (iframePath.replace(initialURL,"") != ""){
  1230. history.replaceState(undefined, undefined, "#" + iframePath.replace(initialURL,""));
  1231. }else{
  1232. history.replaceState(undefined, undefined,"#index.php");
  1233. }
  1234. }
  1235. //These function is for ArOZ Online System quick storage data processing
  1236. function CheckStorage(id){
  1237. if (typeof(Storage) !== "undefined") {
  1238. return true;
  1239. } else {
  1240. return false;
  1241. }
  1242. }
  1243. function GetStorage(id){
  1244. //All data get are string
  1245. return localStorage.getItem(id);
  1246. }
  1247. function SaveStorage(id,value){
  1248. localStorage.setItem(id, value);
  1249. return true;
  1250. }
  1251. //USB Device Managing Script
  1252. function SetUSBFound(state){
  1253. if (state == true){
  1254. //New USB inserted
  1255. $('#USBopr').html("<i class='usb icon'></i>Detecting");
  1256. $.get( "SystemAOB/functions/system_statistic/usbPorts.php", function(data) {
  1257. if (data.includes("Device") && data.includes("ID")){
  1258. //This is raspberry pi
  1259. var info = data.split("ID")[1];
  1260. $('#USBopr').html("<i class='usb icon'></i>" + info);
  1261. }else{
  1262. //This is Window machine
  1263. $('#USBopr').html("<i class='usb icon'></i>" + data[0]);
  1264. }
  1265. });
  1266. }else{
  1267. //No more usb is inserted
  1268. $('#USBopr').html("<i class='usb icon'></i> USB Hub");
  1269. }
  1270. }
  1271. function CheckUSBNoDifferent(){
  1272. /*
  1273. //Refresh System are moved to the usbMount.php in AOB version 22.1.2018
  1274. if ($('#USBList').css("display") == "none"){
  1275. //Refresh the content of driver display if reshow
  1276. $('#USBListDisplay').attr('src','SystemAOB/functions/usbMount.php');
  1277. }
  1278. */
  1279. $('#USBList').clearQueue()
  1280. $('#USBList').stop()
  1281. $('#USBList').fadeToggle('fast');
  1282. $.get( "SystemAOB/functions/system_statistic/usbPorts.php", function(data) {
  1283. if (data.length != USBNo){
  1284. if (data.length > USBNo){
  1285. PopUpNewUSB();
  1286. }else if (data.length < USBNo){
  1287. USBRemoved();
  1288. }
  1289. USBNo = data.length;
  1290. }
  1291. });
  1292. }
  1293. function CheckUSBChange(){
  1294. $.get( "SystemAOB/functions/system_statistic/usbPorts.php", function(data) {
  1295. if (data.length != USBNo){
  1296. if (data.length > USBNo){
  1297. PopUpNewUSB();
  1298. }else if (data.length < USBNo){
  1299. USBRemoved();
  1300. }
  1301. USBNo = data.length;
  1302. }
  1303. });
  1304. }
  1305. function PopUpNewUSB(){
  1306. $('#USBListDisplay').attr('src','SystemAOB/functions/usbMount.php');
  1307. //alert("New USB FOUND!");
  1308. $('#umw_head').html("New USB Storage Device Found.");
  1309. $('#umw_text').html("Device auto mounting in progress. Please wait...");
  1310. $.get( "SystemAOB/functions/system_statistic/usbPorts.php", function(data) {
  1311. // $('#umw_list').html(data[0]);
  1312. $('#umw_list').html("fstab mounting in progress");
  1313. $('#umw').fadeIn('fast').delay(4000).fadeOut('fast');
  1314. });
  1315. SetUSBFound(true);
  1316. }
  1317. function USBRemoved(){
  1318. $('#USBListDisplay').attr('src','SystemAOB/functions/usbMount.php');
  1319. //alert("USB Removed");
  1320. $('#umw_head').html("USB Device Removed.");
  1321. $('#umw_text').html("Please make sure you have unmounted the device before unplugging.");
  1322. $('#umw_list').html("<i class='minus circle icon'></i> Device Removed");
  1323. $('#umw').fadeIn('fast').delay(4000).fadeOut('fast');
  1324. SetUSBFound(false);
  1325. }
  1326. function UpdateUSBNo(){
  1327. $.get( "SystemAOB/functions/system_statistic/usbPorts.php", function(data) {
  1328. USBNo = data.length;
  1329. });
  1330. }
  1331. var VolAreaMouseDown = false
  1332. //Global Vol Control Script
  1333. $('#globVolBar').on("mousedown",function(e){
  1334. VolAreaMouseDown = true;
  1335. var posX = $(this).offset().left;
  1336. var totalWidth = $(this).width();
  1337. var percentage = Math.round(((e.pageX - posX) / totalWidth) * 100);
  1338. if (percentage > 100){
  1339. percentage = 100;
  1340. }else if (percentage < 0){
  1341. percentage = 0;
  1342. }
  1343. $('#volDisplay').css('width',percentage + '%');
  1344. SaveStorage('global_volume',percentage/100)
  1345. });
  1346. $('#globVolBar').on("mousemove",function(e){
  1347. if (VolAreaMouseDown){
  1348. var posX = $(this).offset().left;
  1349. var totalWidth = $(this).width();
  1350. var percentage = Math.round(((e.pageX - posX) / totalWidth) * 100);
  1351. if (percentage > 100){
  1352. percentage = 100;
  1353. }else if (percentage < 0){
  1354. percentage = 0;
  1355. }
  1356. $('#volDisplay').css('width',percentage + '%');
  1357. SaveStorage('global_volume',percentage/100)
  1358. }
  1359. });
  1360. $('#globVolBar').on("mouseup",function(e){
  1361. VolAreaMouseDown = false;
  1362. });
  1363. //The same things as above but for tablet
  1364. $('#globVolBar').on('touchstart',function(e){
  1365. VolAreaMouseDown = true;
  1366. var posX = $(this).offset().left;
  1367. var totalWidth = $(this).width();
  1368. var percentage = Math.round(((e.pageX - posX) / totalWidth) * 100);
  1369. $('#volDisplay').css('width',percentage + '%');
  1370. //console.log(percentage);
  1371. SaveStorage('global_volume',percentage/100)
  1372. });
  1373. $('#globVolBar').bind('touchmove',function( event ) {
  1374. if (VolAreaMouseDown){
  1375. var posX = $(this).offset().left;
  1376. var totalWidth = $(this).width();
  1377. var percentage = Math.round(((e.pageX - posX) / totalWidth) * 100);
  1378. if (percentage < 0){
  1379. percentage = 0;
  1380. }else if (percentage > 100){
  1381. percentage = 100;
  1382. }
  1383. $('#volDisplay').css('width',percentage + '%');
  1384. //console.log(percentage);
  1385. SaveStorage('global_volume',percentage/100)
  1386. }
  1387. });
  1388. $('#globVolBar').on("touchend",function(e){
  1389. VolAreaMouseDown = false;
  1390. });
  1391. function mutevol(){
  1392. //mute the volume when the user press the low vol icon
  1393. $('#volDisplay').css('width','0%');
  1394. SaveStorage('global_volume',0);
  1395. }
  1396. function ToggleGlobalVol(e){
  1397. $('#globVolInterface').clearQueue();
  1398. $('#globVolInterface').stop();
  1399. $('#globVolInterface').fadeToggle('fast');
  1400. $("#globVolInterface").css("left",$("#gVol").offset().left + "px");
  1401. }
  1402. $( window ).resize(function() {
  1403. //Update the position of the global vol selector
  1404. $("#globVolInterface").css("left",$("#gVol").offset().left + "px");
  1405. $("#notificationbar").css("left",$(window).width() + "px");
  1406. $("#notificationbar").addClass("hidden");
  1407. var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
  1408. if (isChrome){
  1409. //Chrome full screen activated --> As there are some minor css problem in Chrome for unknown reasons
  1410. $("#interface").css("height",$(window).outerHeight() + "px");
  1411. }
  1412. });
  1413. var notificationbarAnimateOngoing = false;
  1414. function toggleNoticeBoard(){
  1415. if ($("#notificationbar").hasClass("hidden") && notificationbarAnimateOngoing == false){
  1416. notificationbarAnimateOngoing = true;
  1417. $("#notificationbar").removeClass("hidden");
  1418. $("#notificationbar").finish().animate({left: "-=350"},350,"swing",function(){
  1419. notificationbarAnimateOngoing = false;
  1420. });
  1421. }else if (notificationbarAnimateOngoing == false){
  1422. notificationbarAnimateOngoing = true;
  1423. $("#notificationbar").addClass("hidden");
  1424. $("#notificationbar").finish().animate({left: "+=350"},350,"swing",function(){
  1425. notificationbarAnimateOngoing = false;
  1426. });
  1427. }
  1428. }
  1429. function closemsgbox(object){
  1430. var messageboxObject = $(object).parent().parent().parent();
  1431. if (messageboxObject.hasClass("messagebox")){
  1432. messageboxObject.fadeOut('500', function() { $(this).remove(); });
  1433. notificationCount--;
  1434. if (notificationCount == 0){
  1435. setTimeout(function(){
  1436. if (!$("#notificationbar").hasClass("hidden")){
  1437. //If the notification bar is shown, hide it
  1438. toggleNoticeBoard();
  1439. }
  1440. },800);
  1441. }
  1442. }else{
  1443. console.log("ERROR! Unable to remove messagebox / messagebox not exists.");
  1444. }
  1445. }
  1446. function clearAllNotification(){
  1447. $(".messagebox").each(function(){
  1448. $(this).fadeOut(350,function(){
  1449. $(this).remove();
  1450. });
  1451. });
  1452. setTimeout(function(){
  1453. if (!$("#notificationbar").hasClass("hidden")){
  1454. //If the notification bar is shown, hide it
  1455. toggleNoticeBoard();
  1456. }
  1457. },800);
  1458. notificationCount = 0;
  1459. }
  1460. function FloatWindowWatchDog(){
  1461. //This watch dog is used to fix the FloatWindow top bar offset problem in not normal user operation in drag drop
  1462. $( ".floatWindow" ).each(function() {
  1463. var FWcontainer = $(this).parent();
  1464. var FWC_offset = FWcontainer.offset();
  1465. var FWT_offset = $(this).offset();
  1466. if (Math.round(FWC_offset.top + 2) < Math.round(FWT_offset.top) && Math.round(FWC_offset.top) != Math.round(FWT_offset.top)){
  1467. //The y axis of the window control is shifted!
  1468. dragging = false;
  1469. $(this).offset({top: FWC_offset.top, left: FWC_offset.left});
  1470. console.log("Top value mismatch --> Container: " + FWcontainer.attr("id") + " FWC_offsets: " + FWC_offset.top + "," + FWC_offset.left + " FWT_offsets: " + FWT_offset.top + "," + FWT_offset.left);
  1471. focusedObject = null;
  1472. $('#backdrop').hide();
  1473. $('#iframeCover').hide().appendTo('body');
  1474. }else if (Math.round(FWC_offset.left + 2) < Math.round(FWT_offset.left) && Math.round(FWC_offset.left) != Math.round(FWT_offset.left)){
  1475. //The x axis of the window control is shifted!
  1476. dragging = false;
  1477. $(this).offset({top: FWC_offset.top, left: FWC_offset.left});
  1478. console.log("Left value mismatch --> Container: " + FWcontainer.attr("id") + " FWC_offsets: " + FWC_offset.top + "," + FWC_offset.left + " FWT_offsets: " + FWT_offset.top + "," + FWT_offset.left);
  1479. focusedObject = null;
  1480. $('#backdrop').hide();
  1481. $('#iframeCover').hide().appendTo('body');
  1482. }
  1483. //This watch dog is used to find crashed tab and redirect it to the blue screen interface.
  1484. if (FWcontainer.attr("id") != "newWindow" && $(FWcontainer).find("iframe").attr("src") == "about:blank"){
  1485. $(FWcontainer).find("iframe").attr("src","SystemAOB/functions/crashScreen.php?errormsg=A module trying to open a new floatWindow but failed due to unknown reason.<br>" + FWcontainer.attr("id"));
  1486. var windowIDofCrashedWindow = FWcontainer.attr("id");
  1487. changeWindowTitle(windowIDofCrashedWindow,"[Crashed] FloatWindow has no response or could not be loaded")
  1488. setWindowIcon(windowIDofCrashedWindow,"remove")
  1489. }
  1490. });
  1491. }
  1492. /*
  1493. //Function removed and replaced by closeWindow() in update 20-9-2018
  1494. function forceTerminate(){
  1495. $( "iframe" ).each(function() {
  1496. var id = $(this).parent().attr("id");
  1497. if ($(this).contents().get(0).location.href != undefined){
  1498. var src = $(this).contents().get(0).location.href;
  1499. }else{
  1500. return;
  1501. }
  1502. if (src == undefined){
  1503. return;
  1504. }
  1505. if (src.includes("SystemAOB/functions/killProcess.php")){
  1506. $("#" + id).delay(500).remove();
  1507. $('#' + id + 'Btn').remove();
  1508. floatWindowCount --;
  1509. killDragging();
  1510. }
  1511. });
  1512. }
  1513. */
  1514. function ShowCalender(){
  1515. //Display the calender when the user press on the clock
  1516. $("#calGrid").fadeIn("fast");
  1517. }
  1518. function HideCalender(){
  1519. //Hide the calender when mouse leave
  1520. $("#calGrid").fadeOut("fast");
  1521. }
  1522. function killDragging(){
  1523. focusedObject = null;
  1524. dragging = false;
  1525. $('#backdrop').hide();
  1526. $('#iframeCover').hide().appendTo('body');
  1527. }
  1528. function changeWindowTitle(id,newTitle = "New Window"){
  1529. //With given ID, change the floatWindow title
  1530. //console.log(id,newTitle);
  1531. $(".floatWindow").each(function(){
  1532. var thisid = $(this).parent().attr("id");
  1533. if (thisid == id){
  1534. var windowTitle = $(this).text().trim();
  1535. var thisHTML = $(this).html();
  1536. $(this).html(thisHTML.replace(windowTitle,newTitle));
  1537. killDragging();
  1538. bindMotions(id);
  1539. }
  1540. });
  1541. }
  1542. function setWindowResizable(id){
  1543. //With given ID, change the floatWindow resizable to true
  1544. $(".floatWindow").each(function(){
  1545. var thisid = $(this).parent().attr("id");
  1546. if (thisid == id){
  1547. //if this float window exists
  1548. $(this).parent().append('<div class="resizeWindow" align="center"></div>');
  1549. killDragging();
  1550. bindMotions(id);
  1551. }
  1552. });
  1553. }
  1554. function setWindowFixedSize(id){
  1555. //With given ID, change the floatWindow resizable to false
  1556. $(".floatWindow").each(function(){
  1557. var thisid = $(this).parent().attr("id");
  1558. if (thisid == id){
  1559. //This floatWindow exists
  1560. $("#" + id + " .resizeWindow").remove();
  1561. $("#" + id + " .maximizeWindow").remove();
  1562. $("#" + id + " .minimizeWindow").css("right","25px");
  1563. killDragging();
  1564. bindMotions(id);
  1565. }
  1566. });
  1567. }
  1568. function setWindowPreferdSize(id,width,height){
  1569. //With given ID, change the floatWindow size
  1570. $(".floatWindow").each(function(){
  1571. var thisid = $(this).parent().attr("id");
  1572. if (thisid == id){
  1573. //This floatWindow exists
  1574. if (width > $(window).width()){
  1575. width = $(window).width();
  1576. $("#" + id).css("left",0);
  1577. }
  1578. $("#" + id).css("width",width);
  1579. if (height > $(document).height()){
  1580. height = $(document).height();
  1581. $("#" + id).css("top",0);
  1582. $("#" + id).css("height",height).css("height","-=35px");
  1583. }else{
  1584. $("#" + id).css("height",height);
  1585. }
  1586. killDragging();
  1587. bindMotions(id);
  1588. }
  1589. });
  1590. }
  1591. function setWindowIcon(id,iconname){
  1592. //With given ID, change the floatWindow icon
  1593. $(".floatWindow").each(function(){
  1594. var thisid = $(this).parent().attr("id");
  1595. if (thisid == id){
  1596. //This floatWindow exists
  1597. var thisHTML = $(this).html();
  1598. var iconEndPos = thisHTML.indexOf("/i>") + 3;
  1599. var controls = thisHTML.substring(iconEndPos);
  1600. var newhtml = '  <i class="'+iconname+' icon"></i>' + controls;
  1601. $(this).html(newhtml);
  1602. $("#" + id + "Btn").html('<i class="'+iconname+' icon" style="line-height: 35px;"></i>');
  1603. killDragging();
  1604. bindMotions(id);
  1605. }
  1606. });
  1607. }
  1608. function setGlassEffectMode(id){
  1609. //With given ID, change the floatWindow icon
  1610. $(".floatWindow").each(function(){
  1611. var thisid = $(this).parent().attr("id");
  1612. if (thisid == id){
  1613. //This floatWindow exists
  1614. $(this).parent().css("background-color","");
  1615. $(this).parent().css("border","0px solid transparent");
  1616. $(this).css("background-color",$(".fwPanelColor").css("background"));
  1617. $(this).css("padding-top","1px");
  1618. $(this).find(".closeWindow").css("top","2px");
  1619. $(this).find(".minimizeWindow").css("top","4px");
  1620. $(this).parent().css("box-shadow","1px 1px 4px #3d3d3d");
  1621. killDragging();
  1622. bindMotions(id);
  1623. }
  1624. });
  1625. }
  1626. function closeWindow(id){
  1627. $(".floatWindow").each(function(){
  1628. var thisid = $(this).parent().attr("id");
  1629. if (thisid == id){
  1630. //This floatWindow exists, remove the window
  1631. $(this).parent().delay(500).remove();
  1632. //Direct button remove is deprecated since 15-3-2019
  1633. //$('#' + id + 'Btn').remove();
  1634. removeFloatWindowFromMenuBarByID(id);
  1635. floatWindowCount --;
  1636. killDragging();
  1637. bindMotions(id);
  1638. }
  1639. });
  1640. }
  1641. function callToInterface(){
  1642. return frames[0];
  1643. }
  1644. function getWindowFromModule(modulename){
  1645. //Get the floatWindow id of fw that is running the same module
  1646. result = [];
  1647. $(".floatWindow").each(function(){
  1648. var iframeObject = $(this).parent().find("iframe")[0];
  1649. var src = $(iframeObject).attr("src");
  1650. if (src.substr(0,modulename.length) == modulename|| src.includes("/" + modulename + "/")){
  1651. result.push($(this).parent().attr("id"));
  1652. }
  1653. });
  1654. return result;
  1655. }
  1656. function crossFrameFunctionCall(id,funct){
  1657. if ($("#" + id).length != 0){
  1658. $("#" + id).find("iframe")[0].contentWindow.eval(funct);
  1659. }
  1660. }
  1661. function getWindowObjectFromID(id){
  1662. if ($("#" + id).length != 0){
  1663. return $("#" + id).find("iframe")[0].contentWindow;
  1664. }else{
  1665. return null;
  1666. }
  1667. }
  1668. /*
  1669. //This function has been replaced by the notification bar in 16-9-2018 updates
  1670. function msgbox(warningMsg,displayText="",title="Message Box",icon=""){
  1671. var template='<div class="msgbox" style="position:fixed;top:20%;left:20%;width:400px;max-height:300px;border-radius:0px;padding-top:0px;display:;border-width: 0px;background-color:#f2f2f2" open><div class="floatWindow" style="width:100%; position: relative; background-color:#333;color:white;left:0px;top:0px;height:20px;z-index:8;overflow:hidden;text-overflow: ellipsis;white-space: nowrap;cursor: context-menu;">   %WINDOW_TITLE%<div style="top:2px;right:3px;cursor: pointer;position:absolute;" class="closeWindow"><i class="remove icon"></i></div></div><div style="padding-top:4px;padding-bottom:4px;padding-right:6px;padding-left:10px;"><div class="ts container"><h4 class="ts header"><i class="%ICON% icon"></i><div class="content">%MESSAGEHEADER%<div class="sub header">%CONTENT%</div></div></h4></div><button class="ts inverted tiny right floated button" onClick="$(this).parent().parent().remove();" style="border-radius: 0px;">Confirm</button><br><br></div></div>';
  1672. var box = template.replace("%WINDOW_TITLE%",title);
  1673. box = box.replace("%ICON%",icon);
  1674. box = box.replace("%MESSAGEHEADER%",warningMsg);
  1675. box = box.replace("%CONTENT%",displayText);
  1676. $("body").append(box);
  1677. killDragging();
  1678. bindMotions();
  1679. }*/
  1680. var previosTimeoutEvent = undefined;
  1681. function msgbox(warningMsg,title="",redirectpath="",autoclose=true){
  1682. if (previosTimeoutEvent != undefined){
  1683. clearTimeout(previosTimeoutEvent);
  1684. }
  1685. if ($("#notificationbar").hasClass("hidden")){
  1686. //If the notice board is hidden during the notification time, show it
  1687. toggleNoticeBoard();
  1688. }
  1689. var box = "";
  1690. box += '<div class="messagebox"><div class="ts grid"><div class="twelve wide column">';
  1691. if (title != ""){
  1692. box += '<div style="color:white;font-size:130%;border-bottom:1px dashed white;">' + title + '</div>';
  1693. }
  1694. box += warningMsg;
  1695. if (redirectpath != ""){
  1696. box += '<br><a style="cursor:pointer;" href="' + redirectpath + '" target="_blank">Open in Module <i class="external icon"></i></a>';
  1697. }
  1698. box += '</div><div class="four wide column" align="right"><i class="remove icon pressable" onClick="closemsgbox(this);"></i><br><br></div></div></div>';
  1699. $(box).hide().prependTo("#messageBoard").slideDown();
  1700. playSound("script/msgbox.mp3");
  1701. notificationCount++;
  1702. if (autoclose){
  1703. previosTimeoutEvent = setTimeout(function(){
  1704. if (!$("#notificationbar").hasClass("hidden")){
  1705. //If the notification bar is shown, hide it
  1706. toggleNoticeBoard();
  1707. previosTimeoutEvent = undefined;
  1708. }
  1709. },3500);
  1710. }
  1711. }
  1712. function playSound(filename){
  1713. var audio = new Audio(filename);
  1714. audio.volume = (Math.round(GetStorage('global_volume') * 100)) / 100;
  1715. audio.play();
  1716. }
  1717. updateArOZKeypassHandler();
  1718. function updateArOZKeypassHandler(){
  1719. window.document.addEventListener('aroz-keypass', handleEvent, false)
  1720. function handleEvent(e) {
  1721. console.log(e.detail.which);
  1722. }
  1723. }
  1724. function openFullscreen() {
  1725. //Opening full screen will lead to hidden of all iframe for unknown reasons
  1726. var isInFullScreen = (document.fullscreenElement && document.fullscreenElement !== null) ||
  1727. (document.webkitFullscreenElement && document.webkitFullscreenElement !== null) ||
  1728. (document.mozFullScreenElement && document.mozFullScreenElement !== null) ||
  1729. (document.msFullscreenElement && document.msFullscreenElement !== null);
  1730. var elem = document.documentElement;
  1731. if (!isInFullScreen) {
  1732. if (elem.requestFullscreen) {
  1733. elem.requestFullscreen();
  1734. } else if (elem.mozRequestFullScreen) { /* Firefox */
  1735. elem.mozRequestFullScreen();
  1736. } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
  1737. elem.webkitRequestFullscreen();
  1738. } else if (elem.msRequestFullscreen) { /* IE/Edge */
  1739. elem.msRequestFullscreen();
  1740. }
  1741. } else {
  1742. if (document.exitFullscreen) {
  1743. document.exitFullscreen();
  1744. } else if (document.webkitExitFullscreen) {
  1745. document.webkitExitFullscreen();
  1746. } else if (document.mozCancelFullScreen) {
  1747. document.mozCancelFullScreen();
  1748. } else if (document.msExitFullscreen) {
  1749. document.msExitFullscreen();
  1750. }
  1751. }
  1752. }
  1753. $(document).keyup(function(e) {
  1754. var keycode = e.keyCode || e.which;
  1755. if (keycode == 27){
  1756. killDragging();
  1757. console.log("[info] Dragging function killed. Restarting all dragging elements.");
  1758. //bindMotions();
  1759. }else if (keycode == 120){
  1760. //On F9 being pressed, enter full screen with Javascript API
  1761. openFullscreen();
  1762. }
  1763. });
  1764. function checkCachedWindowSize(url){
  1765. //Check if there are cached window size for this interface. If yes, override the default value
  1766. if (localStorage.getItem("aosystem.fwscache") === null){
  1767. return false;
  1768. }else{
  1769. var cachedWindowSizeList = JSON.parse(localStorage.getItem("aosystem.fwscache"));
  1770. var baseurl = url;
  1771. if (url.includes("?") == true){
  1772. baseurl = url.split("?")[0];
  1773. }
  1774. for (var i =0; i < cachedWindowSizeList.length; i++){
  1775. if (cachedWindowSizeList[i][0] == baseurl || cachedWindowSizeList[i][0] == url){
  1776. //return ww and wh as array
  1777. return [cachedWindowSizeList[i][1],cachedWindowSizeList[i][2]];
  1778. }
  1779. }
  1780. }
  1781. return false;
  1782. }
  1783. //FloatWindow size caching mechanism
  1784. function cacheWindowSize(url,ww,wh,exact=false){
  1785. var baseurl = url;
  1786. if (!exact){
  1787. if (url.includes("?") == true){
  1788. baseurl = url.split("?")[0];
  1789. }
  1790. }
  1791. if (localStorage.getItem("aosystem.fwscache") === null){
  1792. localStorage.setItem("aosystem.fwscache", JSON.stringify([[baseurl,ww,wh]]));
  1793. console.log([[baseurl,ww,wh]]);
  1794. }else{
  1795. //Append to the list
  1796. var cachedWindowSizeList = JSON.parse(localStorage.getItem("aosystem.fwscache"));
  1797. //Check if the baseurl is in array
  1798. var found = false;
  1799. for (var i=0; i < cachedWindowSizeList.length; i++){
  1800. if (cachedWindowSizeList[i][0] == baseurl){
  1801. found = true;
  1802. cachedWindowSizeList[i][1] = ww;
  1803. cachedWindowSizeList[i][2] = wh;
  1804. }
  1805. }
  1806. if (!found){
  1807. cachedWindowSizeList.push([baseurl,ww,wh]);
  1808. }
  1809. localStorage.setItem("aosystem.fwscache", JSON.stringify(cachedWindowSizeList));
  1810. }
  1811. }
  1812. //Debug only function
  1813. /*
  1814. $(document).keyup(function(e) {
  1815. //Handle Error in Float Window
  1816. if (e.keyCode == 27) { // escape key
  1817. dragging = false;
  1818. FloatWindowWatchDog();
  1819. //console.log("Error while handling: " + $(focusedObject).attr("id"));
  1820. //$(focusedObject).parent().remove();
  1821. }
  1822. });
  1823. */