index.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. include '../auth.php';
  3. ?>
  4. <!DOCTYPE html>
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <html lang="en">
  7. <head>
  8. <meta charset="UTF-8">
  9. <script type='text/javascript' charset='utf-8'>
  10. // Hides mobile browser's address bar when page is done loading.
  11. window.addEventListener('load', function(e) {
  12. setTimeout(function() { window.scrollTo(0, 1); }, 1);
  13. }, false);
  14. </script>
  15. <meta charset="UTF-8">
  16. <script src="../script/jquery.min.js"></script>
  17. <script src="../script/ao_module.js"></script>
  18. <title>ArOZ Onlineβ</title>
  19. <style>
  20. * {
  21. font-family: arial;
  22. }
  23. .topbar{
  24. background-color: #d6d6d6;
  25. overflow: hidden;
  26. position:fixed;
  27. top:0;left:0;
  28. width:100%;height:25px;
  29. padding-left: 5px;
  30. }
  31. button{
  32. padding: 5;
  33. border: none;
  34. background: none;
  35. height:25px;
  36. }
  37. button:hover {
  38. background-color: #edeaea;
  39. cursor: pointer;
  40. }
  41. #codeArea{
  42. width:100%;
  43. position:fixed;
  44. top:50px;
  45. left:0px;
  46. }
  47. #tabs{
  48. background-color: #d6d6d6;
  49. position:fixed;
  50. width:100%;
  51. height:25px;
  52. top:25px;
  53. left:0px;
  54. }
  55. .fileTab{
  56. background-color: #bcbcbc;
  57. display:inline;
  58. padding-left: 8px;
  59. padding-right: 1px;
  60. marign-left:1px;
  61. height:25px;
  62. border-bottom: 3px solid #878787;
  63. cursor: pointer;
  64. }
  65. .fileTab.focused{
  66. background-color: #edeaea;
  67. display:inline;
  68. border-bottom: 3px solid #5b4cff;
  69. cursor: pointer;
  70. }
  71. .closeBtn{
  72. display:inline;
  73. }
  74. .contextmenu{
  75. position:fixed;
  76. top:25px;
  77. left:0px;
  78. width:auto;
  79. height:auto;
  80. background-color:#d6d6d6;
  81. z-index:100;
  82. border-style: solid;
  83. border-width: 1px;
  84. border-color: #626263;
  85. font-size:small;
  86. max-height: 100%;
  87. overflow-y: auto;
  88. }
  89. .menuitem{
  90. padding-top: 2px;
  91. padding-bottom: 3px;
  92. padding-left: 25px;
  93. padding-right: 10px;
  94. }
  95. .menuitem:hover{
  96. background-color: #edeaea;
  97. cursor: pointer;
  98. }
  99. .middleFloat{
  100. position:fixed;
  101. top:10%;
  102. bottom: 10%;
  103. left: 30%;
  104. right: 30%;
  105. background-color:#efefef;
  106. padding:25px;
  107. overflow-y:auto;
  108. }
  109. </style>
  110. </head>
  111. <body>
  112. <div class="topbar">
  113. <button onClick="startTooggleMenu(this);">File</button>
  114. <button onClick="startTooggleMenu(this);">Edit</button>
  115. <button onClick="startTooggleMenu(this);">Search</button>
  116. <button onClick="startTooggleMenu(this);">View</button>
  117. <button onClick="startTooggleMenu(this);">Theme</button>
  118. <button onClick="startTooggleMenu(this);">Font_Size</button>
  119. <button onClick="startTooggleMenu(this);">About</button>
  120. </div>
  121. <div id="tabs" onClick="hideToggleMenu();">
  122. </div>
  123. <div id="codeArea">
  124. </div>
  125. <div id="topbarMenu" class="contextmenu" style="display:none;">
  126. </div>
  127. <div id="aboutus" class="middleFloat" style="display:none;">
  128. <h3>📝 NotepadA ArOZ Online In-System Text Editor</h3>
  129. <p>Author: Toby Chui 2017-2018</p>
  130. <hr>
  131. <p>This web based text editor for ArOZ Online System are made possible by the ace editor, jQuery and ArOZ Project. Part of the system are licensed under BSD License or MIT license. Please refer to the individual license information under the library folder. <br><br>For the rest of the system and interface, all codes are CopyRight Toby Chui feat. IMUS Laboratory and licnesed under IMUS license (which is something similar to MIT license but with some extra licensing information about hardware). Developed under ArOZ Online System for experimental purpose.<br><br>
  132. Visit <a href="https://github.com/tobychui">https://github.com/tobychui</a> for more information.</p>
  133. <hr>
  134. <p>MIT License<p>
  135. <p style="font-size:70%;">Permission is hereby granted, free of charge, to any person obtaining a copy
  136. of this software and associated documentation files (the "Software"), to deal
  137. in the Software without restriction, including without limitation the rights
  138. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  139. copies of the Software, and to permit persons to whom the Software is
  140. furnished to do so, subject to the following conditions:
  141. The above copyright notice and this permission notice shall be included in all
  142. copies or substantial portions of the Software.
  143. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  144. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  145. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  146. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  147. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  148. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  149. SOFTWARE.</p>
  150. <p>BSD License<p>
  151. <p style="font-size:70%;">All rights reserved.
  152. Redistribution and use in source and binary forms, with or without
  153. modification, are permitted provided that the following conditions are met:
  154. 1. Redistributions of source code must retain the above copyright
  155. notice, this list of conditions and the following disclaimer.
  156. 2. Redistributions in binary form must reproduce the above copyright
  157. notice, this list of conditions and the following disclaimer in the
  158. documentation and/or other materials provided with the distribution.
  159. 3. All advertising materials mentioning features or use of this software
  160. must display the following acknowledgement:
  161. This product includes software developed by the <organization>.
  162. 4. Neither the name of the <organization> nor the
  163. names of its contributors may be used to endorse or promote products
  164. derived from this software without specific prior written permission.
  165. THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY
  166. EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  167. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  168. DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  169. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  170. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  171. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  172. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  173. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  174. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</p>
  175. <hr>
  176. <button style="background-color:white;border: 1px solid #707070;" onClick="$('#aboutus').hide();">Close</button>
  177. <br><br><br><br><br>
  178. </div>
  179. <?php
  180. $draginFilePath = "";
  181. if (isset($_GET['filepath'])){
  182. $rootRealPath = str_replace("\\","/",realpath("../")). "/";
  183. if (file_exists($_GET['filepath']) == false){
  184. $_GET['filepath'] = "../" . $_GET['filepath'];
  185. }
  186. $fileRealPath = str_replace("\\","/",realpath($_GET['filepath']));
  187. $draginFilePath = str_replace($rootRealPath,"",$fileRealPath);
  188. echo $_GET['filepath'];
  189. }
  190. ?>
  191. <script>
  192. //Global variables
  193. var dragIn = "<?php echo $draginFilePath;?>";
  194. var theme = 'github';
  195. var lastSelectedMenuItem = "";
  196. var username = loadStorage("ArOZusername");
  197. var fontsize = 12;
  198. var VDI = !(!parent.isFunctionBar);
  199. var openedFilePath = [];
  200. var previousSavedState = true;
  201. var functionList = {
  202. File: ["New","Open file","Open current directory","Reload","Save","Save As","Close All Files","Print","Exit"],
  203. Edit: [],
  204. Theme:["ambiance","chaos","chrome","clouds","clouds_midnight","cobalt","crimson_editor","dawn","dracula","dreamweaver","eclipse","github","gob","gruvbox","idle_fingers","iplastic","katzenmilch","kr_theme","kuroir","merbivore","merbivore_soft","mono_industrial","monokai","pastel_on_dark","solarized_dark","solarized_light","sqlserver","terminal","textmate","tomorrow","tomorrow_night","tomorrow_night_blue","tomorrow_night_bright","tomorrow_night_eighties","twilight","vibrant_ink","xcode"],
  205. Font_Size:["8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"],
  206. About:["About NotepadA"]
  207. };
  208. //Init functions
  209. adjustCodeAreaHeight();
  210. bindListener();
  211. initTheme();
  212. initFontSize();
  213. initNotepadA();
  214. reloadAllTabs();
  215. //Init notepadA. If there are previos stored page, load them into the environment. Or otherwise, just open a blank page.
  216. function initNotepadA(){
  217. ao_module_setGlassEffectMode()
  218. ao_module_setWindowIcon("code");
  219. ao_module_setWindowSize(1080,600);
  220. if (loadStorage("NotepadA_" + username + "_sessionFiles") != ""){
  221. var pages = JSON.parse(loadStorage("NotepadA_" + username + "_sessionFiles"));
  222. for (var i =0; i < pages.length;i++){
  223. let page = pages[i];
  224. newEditor(page);
  225. }
  226. if (dragIn != ""){
  227. //If there is a file dragin, and it hasn't been opened, open it
  228. if (pages.indexOf(dragIn) == -1){
  229. newEditor(dragIn);
  230. }else{
  231. focusTab($($(".fileTab")[pages.indexOf(dragIn)]).attr("tabid"));
  232. }
  233. //alert(dragIn);
  234. }
  235. }else{
  236. if (dragIn != ""){
  237. //If there is a file dragin, open it as well.
  238. newEditor(dragIn);
  239. }else{
  240. newTab();
  241. }
  242. }
  243. setTimeout(function(){
  244. setInterval(function(){
  245. var tabid = getFocusedTab();
  246. if (tabid.length == 0){
  247. return;
  248. }
  249. var tab = findTabWithAttr("framematch",tabid[0]);
  250. var saved = checkTabSaved(tabid[0]);
  251. if (saved != previousSavedState){
  252. previousSavedState = saved;
  253. if (saved){
  254. ao_module_setWindowTitle("NotepadA &#8195; 📝 " + tab.attr("filename").replace("../../","/aor/"));
  255. }else{
  256. ao_module_setWindowTitle("NotepadA &#8195; *💾 📝 " + tab.attr("filename").replace("../../","/aor/"));
  257. }
  258. }
  259. },1000);
  260. },500);
  261. }
  262. //Add a new editor window to the editor (?) -->ALL FILE PATH PASSED IN MUST BE FROM AOR OR /media/storage*
  263. function newEditor(filepath){
  264. let tabid = Math.round((new Date()).getTime());
  265. var tab = '<div class="fileTab" tabid="'+tabid+'" framematch="ca'+tabid+'" filename="../../' + filepath +'">\
  266. loading... <div class="closeBtn">⨯</div>\
  267. </div>';
  268. var frame = '<iframe id="ca'+tabid+'" class="editor" src="ace/editor.php?theme='+theme+'&filename=../../'+filepath+'&fontsize=' + fontsize + '" width="100%" frameBorder="0"></iframe>';
  269. $("#tabs").append(tab);
  270. $("#codeArea").append(frame);
  271. updateFrameAttr('ca' + tabid);
  272. focusTab(tabid + "");
  273. if (openedFilePath.indexOf(filepath) == -1){
  274. openedFilePath.push(filepath);
  275. }
  276. setStorage("NotepadA_" + username + "_sessionFiles",JSON.stringify(openedFilePath));
  277. }
  278. function newTab(){
  279. let tabid = Math.round((new Date()).getTime());
  280. let filepath = 'NotepadA/tmp/newfile_' + tabid;
  281. var tab = '<div class="fileTab" tabid="'+tabid+'" framematch="ca'+tabid+'" filename="../../'+filepath+'">\
  282. loading... <div class="closeBtn">⨯</div>\
  283. </div>';
  284. var frame = '<iframe id="ca'+tabid+'" class="editor" src="ace/editor.php?theme='+theme+'&filename=../../'+filepath+'&fontsize=' + fontsize + '" width="100%" frameBorder="0"></iframe>';
  285. $("#tabs").append(tab);
  286. $("#codeArea").append(frame);
  287. updateFrameAttr('ca' + tabid);
  288. setTimeout(function(){focusTab(tabid + "");},100);
  289. if (openedFilePath.indexOf(filepath) == -1){
  290. openedFilePath.push(filepath);
  291. }
  292. setStorage("NotepadA_" + username + "_sessionFiles",JSON.stringify(openedFilePath));
  293. }
  294. function adjustCodeAreaHeight(){
  295. if (VDI){
  296. var h = window.innerHeight;
  297. $("#codeArea").css("height",h - 50);
  298. $(".editor").each(function(i) {
  299. $(this).attr("height",h-50);
  300. });
  301. }else{
  302. $(".editor").each(function(i) {
  303. $(this).css("height",$(document).height());
  304. });
  305. }
  306. }
  307. function checkTabSaved(framematch){
  308. var result = $("#" + framematch)[0].contentWindow.checkIsSaved();
  309. return result;
  310. }
  311. $( window ).resize(function() {
  312. adjustCodeAreaHeight();
  313. });
  314. function bindListener(){
  315. $(document).on('click', '.closeBtn', function () {
  316. removeTab($(this).parent().attr('tabid'));
  317. });
  318. $(document).on('click','.fileTab',function(){
  319. if ($(this).hasClass("closeBtn") == false){
  320. focusTab($(this).attr('tabid'));
  321. }
  322. });
  323. $(document).on('click','#codeArea',function(){
  324. $("#topbarMenu").hide();
  325. });
  326. $(document).on('click','.menuitem',function(){
  327. if (lastSelectedMenuItem == "Theme"){
  328. setTheme($(this).text());
  329. $("#topbarMenu").hide();
  330. }else if (lastSelectedMenuItem == "Font_Size"){
  331. setFontSize($(this).text());
  332. $("#topbarMenu").hide();
  333. }else if (lastSelectedMenuItem == "File"){
  334. handleFileMenu($(this).text());
  335. $("#topbarMenu").hide();
  336. }else if (lastSelectedMenuItem == "About"){
  337. handleAboutMenu($(this).text());
  338. $("#topbarMenu").hide();
  339. }else{
  340. alert(lastSelectedMenuItem);
  341. }
  342. });
  343. }
  344. function updateFrameAttr(framematch){
  345. //This function will update the tab title, iframe attr at the same time.
  346. var frame = $("#" + framematch);
  347. var tab = findTabWithAttr("framematch",framematch);
  348. var filepath = tab.attr("filename");
  349. var filedata = getFilenameAndBasedir(filepath);
  350. var basedir = filedata[0];
  351. var filename = filedata[1];
  352. //Update the tag text to the filename
  353. $(tab).html(filename + ' <div class="closeBtn">⨯</div>');
  354. //Update the iframe attr
  355. $(frame).attr("basedir",basedir);
  356. $(frame).attr("filename",filename);
  357. //
  358. adjustCodeAreaHeight();
  359. }
  360. function getFilenameAndBasedir(filepath){
  361. var f = filepath.split("/").pop();
  362. var b = filepath.replace(f,"");
  363. return [b,f];
  364. }
  365. function reloadAllTabs(){
  366. $(".fileTab").each(function(){
  367. var tid = $(this).attr("tabid");
  368. reloadTab(tid + "");
  369. updateFrameAttr($(this).attr("framematch"));
  370. });
  371. }
  372. function reloadTab(tabID){
  373. var object = findTabWithAttr("tabid",tabID);
  374. var filename = $(object).attr("filename");
  375. var codeAreaID = $(object).attr("framematch");
  376. $("#" + codeAreaID).attr("src","ace/editor.php?theme=" + theme + "&fontsize="+fontsize+"&filename=" + filename);
  377. }
  378. function handleFileMenu(itemText){
  379. var indexvalue = functionList.File.indexOf(itemText);
  380. switch (indexvalue){
  381. case 0:
  382. //nothing
  383. break;
  384. case 2:
  385. //Open the current folder in explorer
  386. var base = getFocusedTab()[1];
  387. if (base == undefined){
  388. break;
  389. }
  390. var uid = Math.round((new Date()).getTime() / 1000);
  391. var url = "SystemAOB/functions/file_system/index.php?controlLv=2&finishing=embedded&subdir=" + base;
  392. var title = "NotepadA" + " - Folder View";
  393. var icon = "folder open";
  394. newfw(url,title,icon,uid,1080,580);
  395. break;
  396. case 3:
  397. //Reload is pressed
  398. var currentFocusedtid = getFocusedTab()[0];
  399. if (currentFocusedtid == undefined){
  400. break;
  401. }
  402. var tabobject = findTabWithAttr("framematch",currentFocusedtid);
  403. reloadTab(tabobject.attr("tabid") + "");
  404. break;
  405. case 4:
  406. //Save is pressed
  407. var currentFocusedtid = getFocusedTab()[0];
  408. if (currentFocusedtid == undefined){
  409. break;
  410. }
  411. $("#" + currentFocusedtid)[0].contentWindow.Save();
  412. break;
  413. case 7:
  414. var id = getFocusedTab()[0];
  415. $("#" + id)[0].contentWindow.Print();
  416. break;
  417. case 8:
  418. if (VDI){
  419. window.location.href = "../SystemAOB/functions/killProcess.php"
  420. }else{
  421. window.location.href = "../index.php"
  422. }
  423. break;
  424. }
  425. }
  426. function handleAboutMenu(itemText){
  427. var indexvalue = functionList.About.indexOf(itemText);
  428. if (indexvalue == 0){
  429. $("#aboutus").show();
  430. }
  431. }
  432. function newfw(src,windowname,icon,uid,sizex,sizey,posx = undefined,posy = undefined,fixsize = undefined,tran = undefined){
  433. //Example
  434. //newEmbededWindow('Memo/index.php','Memo','sticky note outline','memoEmbedded',475,700);
  435. if (!VDI){
  436. return;
  437. }
  438. parent.newEmbededWindow(src,windowname,icon,uid,sizex,sizey,posx,posy,fixsize,tran);
  439. }
  440. function getFocusedTab(){
  441. result = [];
  442. $(".fileTab").each(function(){
  443. if ($(this).hasClass("focused")){
  444. //This tab is focused. Check its filename and pathinfo
  445. var id = $(this).attr("framematch");
  446. var filename = $("#" + id).attr("filename");
  447. var basedir = $("#" + id).attr("basedir");
  448. result = [id,basedir,filename];
  449. }
  450. });
  451. return result;
  452. }
  453. function setTheme(themeName){
  454. setStorage("NotepadA_theme",themeName);
  455. theme = themeName;
  456. console.log("Updating theme to: " + themeName);
  457. //Reload all tabs with the corrispoding themes after changing theme settings
  458. reloadAllTabs();
  459. }
  460. function setFontSize(newsize){
  461. setStorage("NotepadA_fontsize",newsize);
  462. fontsize = newsize;
  463. reloadAllTabs();
  464. }
  465. function initTheme(){
  466. if (loadStorage("NotepadA_theme") != ""){
  467. theme = loadStorage("NotepadA_theme");
  468. }
  469. }
  470. function initFontSize(){
  471. if (loadStorage("NotepadA_fontsize") != ""){
  472. fontsize = loadStorage("NotepadA_fontsize");
  473. }
  474. }
  475. function setStorage(name,value){
  476. localStorage.setItem(name, value);
  477. return true;
  478. }
  479. function loadStorage(name){
  480. if (localStorage.getItem(name) == null){
  481. return "";
  482. }else{
  483. return localStorage.getItem(name);
  484. }
  485. }
  486. function removeTab(tabid){
  487. var focusingTabFramematchBeforeRemove = getFocusedTab()[0];
  488. let origianlTabID = findTabWithAttr("framematch",focusingTabFramematchBeforeRemove).attr("tabid");
  489. var targetTab = findTabWithAttr("tabid",tabid);
  490. var filepath = targetTab.attr("filename").replace("../../","");
  491. var codeAreaTag = $(targetTab).attr("framematch");
  492. //Check if the tab is saved
  493. var saved = checkTabSaved(targetTab.attr("framematch"));
  494. if (saved == false){
  495. //Ask the user if confirm close
  496. var confirmClose = confirm("This file is not saved. Confirm closing?");
  497. if (confirmClose == false){
  498. return false;
  499. }
  500. }
  501. //Remove this record from the filepath so we will not open this again by the enxt time we startup NotepadA
  502. openedFilePath.remove(filepath);
  503. if ($(targetTab).hasClass("focused")){
  504. //This tab is currently focused, move focus to another tab after closing
  505. $(targetTab).remove();
  506. //I have no idea why this only works with a delay... but just don't change this.
  507. setTimeout(function(){
  508. var focusTarget = $(".fileTab").first().attr("tabid");
  509. focusTab(focusTarget); }, 100);
  510. }else{
  511. $(targetTab).remove();
  512. setTimeout(function(){ focusTab(origianlTabID);}, 100);
  513. }
  514. $("#" + codeAreaTag).remove();
  515. if ($(".fileTab").length == 0){
  516. //There is no more tab left, create a new tab instead
  517. setTimeout(function(){ newTab("untitled"); }, 100);
  518. }
  519. setStorage("NotepadA_" + username + "_sessionFiles",JSON.stringify(openedFilePath));
  520. }
  521. function hideToggleMenu(){
  522. $("#topbarMenu").hide();
  523. }
  524. function startTooggleMenu(object){
  525. var menu = $(object).text();
  526. var pos = $(object).offset().left - 5;
  527. toogleMenu(pos,menu);
  528. }
  529. function toogleMenu(left,contentID){
  530. $("#topbarMenu").css("left",left + "px");
  531. if (contentID != lastSelectedMenuItem && $("#topbarMenu").is(":visible")){
  532. $("#topbarMenu").hide();
  533. }
  534. loadOptionToMenu(contentID);
  535. $("#topbarMenu").toggle();
  536. lastSelectedMenuItem = contentID;
  537. }
  538. function loadOptionToMenu(menuItem){
  539. var items = functionList[menuItem];
  540. $("#topbarMenu").html("");
  541. for (var i=0; i < items.length;i++){
  542. $("#topbarMenu").append("<div class='menuitem'>" + items[i] + "</div>");
  543. }
  544. }
  545. function focusTab(tabid){
  546. //Defocus every tabs and hide all coding windows
  547. $(".fileTab").each(function(i) {
  548. $(this).removeClass("focused");
  549. });
  550. $(".editor").each(function(i) {
  551. $(this).hide();
  552. });
  553. //Only show the tab and code window selected
  554. var selectedTab = findTabWithAttr("tabid",tabid);
  555. $(selectedTab).addClass("focused");
  556. var corrispondingCodingTab = $(selectedTab).attr("framematch");
  557. $("#" + corrispondingCodingTab).show();
  558. if (selectedTab.attr("filename") != undefined){
  559. ao_module_setWindowTitle("NotepadA &#8195; 📝 " + selectedTab.attr("filename").replace("../../","/aor/"));
  560. }else{
  561. ao_module_setWindowTitle("NotepadA &#8195; 📝 newfile");
  562. }
  563. }
  564. function findTabWithAttr(attr,value){
  565. return $('div['+attr+'="'+value+'"]').each(function() {
  566. return this;
  567. });
  568. }
  569. Array.prototype.remove = function() {
  570. var what, a = arguments, L = a.length, ax;
  571. while (L && this.length) {
  572. what = a[--L];
  573. while ((ax = this.indexOf(what)) !== -1) {
  574. this.splice(ax, 1);
  575. }
  576. }
  577. return this;
  578. };
  579. </script>
  580. </body>
  581. </html>