function_bar.js 79 KB

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