Im trying to create a tab system for my JQuery terminal, but I cant see how I can add functionality to it. For example, I want the X button to close the current tab, and a + button to open a new tab. Im not really good a javascript obviously, but how can I get started in getting this to work? I have seen an example from github that could help me, but I cant access it right now since my school blocks sites, so if you are reading this, can you get the code from here: https://gist.github.com/lawrenceamer/3f2d48be524ee0eca95ada3910d4294d and put it in stack overflow for me? Or give me tips in completing this?
This is the code I have made so far:
<link href="https://db.onlinewebfonts.com/c/1db29588408eadbd4406aae9238555eb?family=Consolas" rel="stylesheet"> <link href="thetabs.css" rel='stylesheet'>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style>
@import url('https://fonts.cdnfonts.com/css/menlo');
</style>
<style>
iframe {
width: 100%;
height: 100%;
}
a {
font-family: Menlo;
}
.ui-tabs .ui-state-active:after {
content: "x";
position: absolute;
top: 5px;
right: 5px;
font-size: 12px;
cursor: pointer;
}
.tab {
outline: none;
}
#terminal-tabs {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
}
#terminal-tabs ul {
position: sticky;
top: 0;
z-index: 1;
}
body {
zoom: reset !important;
}
#tab-1,
#tab-2,
#tab-3 {
flex-grow: 1;
display: flex;
overflow: auto;
}
#tab-1 iframe,
#tab-2 iframe,
#tab-3 iframe {
width: 100%;
height: 100%;
border: none;
}
</style>
<div id="terminal-tabs">
<ul>
<li><a href="#tab-1">My-Terminal (1)</a></li>
<li><a href="#tab-2">My-Terminal (2)</a></li>
<li><a href="#tab-3">My-Terminal (3)</a></li>
<li><a href="#tab-4">My-Terminal (4)</a></li>
</ul>
<div id="tab-1">
<!-- terminal is hosted here from iframe -->
</div>
<div id="tab-2">
<!-- terminal is hosted here from iframe -->
</div>
<div id="tab-3">
<!-- terminal is hosted here from iframe -->
</div>
<div id="tab-4">
<!-- terminal is hosted here from iframe -->
</div>
</div>
<script>
$(function() {
$("#terminal-tabs").tabs();
});
$("#terminal-tabs").on("click", ".ui-tabs-close", function() {
var panelId = $(this).closest("li").remove().attr("aria-controls");
$("#" + panelId).remove();
$("#terminal-tabs").tabs("refresh");
});
$("#terminal-tabs .ui-tabs-nav").append('<li class="ui-state-default ui-corner-top ui-tabs-new"><a href="#">+</a></li>');
$("#terminal-tabs").on("click", ".ui-tabs-new", function() {
var newTabIndex = $("#terminal-tabs .ui-tabs-nav li").length - 1;
$("#terminal-tabs").tabs("add", "#tab-" + newTabIndex, "Tab " + newTabIndex);
});
</script>
(Note: I also understand that stackoverflow is not just a site where you could ask anything and expect an answer back, but I mostly do coding on a school pc since I dont have a working pc right now, and so I try to work with what I have. And yes, I have tried to do some research on this because google exists, but with my school's blocking system, there are alot of limitations.)