@@ -4,36 +4,36 @@ document.addEventListener("DOMContentLoaded", function(event) {
44 const iframeContainer = document . getElementById ( 'iframe-container' ) ;
55 const rightSideNav = document . getElementById ( 'right-side-nav' ) ;
66 const toggleNavButton = document . getElementById ( 'toggle-nav' ) ;
7-
7+
88 let tabCounter = 1 ;
99 let navOpen = true ;
10-
10+
1111 addTabButton . addEventListener ( 'click' , ( ) => {
1212 const newTab = document . createElement ( 'li' ) ;
1313 const tabTitle = document . createElement ( 'span' ) ;
1414 const newIframe = document . createElement ( 'iframe' ) ;
15-
15+
1616 tabTitle . textContent = `New Tab` ;
1717 tabTitle . className = 'tab-title' ;
1818 newTab . dataset . tabId = tabCounter ;
1919 newTab . addEventListener ( 'click' , switchTab ) ;
20- newTab . setAttribute ( 'draggable' , true ) ;
21-
20+ newTab . setAttribute ( 'draggable' , true ) ;
21+
2222 const closeButton = document . createElement ( 'button' ) ;
2323 closeButton . classList . add ( 'close-tab' ) ;
2424 closeButton . innerHTML = '✕' ;
25-
25+
2626 closeButton . addEventListener ( 'click' , ( event ) => {
2727 event . stopPropagation ( ) ;
28-
28+
2929 const tabToRemove = tabList . querySelector ( `[data-tab-id='${ newTab . dataset . tabId } ']` ) ;
3030 const iframeToRemove = iframeContainer . querySelector ( `[data-tab-id='${ newTab . dataset . tabId } ']` ) ;
31-
31+
3232 if ( tabToRemove && iframeToRemove ) {
3333 const removedTabId = parseInt ( tabToRemove . dataset . tabId ) ;
3434 tabToRemove . remove ( ) ;
3535 iframeToRemove . remove ( ) ;
36-
36+
3737 const remainingTabs = Array . from ( tabList . querySelectorAll ( 'li' ) ) ;
3838 if ( remainingTabs . length > 0 ) {
3939 let indexToActivate = remainingTabs . findIndex ( tab => parseInt ( tab . dataset . tabId ) > removedTabId ) ;
@@ -42,7 +42,7 @@ document.addEventListener("DOMContentLoaded", function(event) {
4242 }
4343 const nextTabToActivate = remainingTabs [ indexToActivate ] ;
4444 const nextIframeToActivate = iframeContainer . querySelector ( `[data-tab-id='${ nextTabToActivate . dataset . tabId } ']` ) ;
45-
45+
4646 if ( nextTabToActivate && nextIframeToActivate ) {
4747 nextTabToActivate . classList . add ( 'active' ) ;
4848 nextIframeToActivate . classList . add ( 'active' ) ;
@@ -51,47 +51,47 @@ document.addEventListener("DOMContentLoaded", function(event) {
5151 }
5252 } ) ;
5353
54-
55-
54+
55+
5656 newTab . appendChild ( tabTitle ) ;
5757 newTab . appendChild ( closeButton ) ;
5858 tabList . appendChild ( newTab ) ;
59-
59+
6060 const allTabs = Array . from ( tabList . querySelectorAll ( 'li' ) ) ;
6161 allTabs . forEach ( tab => tab . classList . remove ( 'active' ) ) ;
6262 const allIframes = Array . from ( iframeContainer . querySelectorAll ( 'iframe' ) ) ;
6363 allIframes . forEach ( iframe => iframe . classList . remove ( 'active' ) ) ;
64-
64+
6565 newTab . classList . add ( 'active' ) ;
66-
66+
6767 newIframe . src = '/' ;
6868 newIframe . dataset . tabId = tabCounter ;
6969 newIframe . classList . add ( 'active' ) ;
7070 iframeContainer . appendChild ( newIframe ) ;
71-
72- // svery epic
73- newIframe . addEventListener ( 'load' , ( ) => {
74- const title = newIframe . contentDocument . title ;
75- tabTitle . textContent = title ;
76- } ) ;
77-
71+
72+ // svery epic
73+ newIframe . addEventListener ( 'load' , ( ) => {
74+ const title = newIframe . contentDocument . title ;
75+ tabTitle . textContent = title ;
76+ } ) ;
77+
7878 tabCounter ++ ;
79- } ) ;
80-
81-
82- window . addEventListener ( 'message' , function ( event ) {
79+ } ) ;
80+
81+
82+ window . addEventListener ( 'message' , function ( event ) {
8383 console . log ( 'Received message:' , event . data ) ;
84- if ( event . data && event . data . url ) {
84+ if ( event . data && event . data . url ) {
8585 const iframes = Array . from ( iframeContainer . querySelectorAll ( 'iframe' ) ) ;
8686 const activeIframe = iframes . find ( iframe => iframe . classList . contains ( 'active' ) ) ;
87-
88- if ( activeIframe ) {
87+
88+ if ( activeIframe ) {
8989 console . log ( 'Visible iframe:' , activeIframe ) ;
9090 const tabToUpdate = tabList . querySelector ( `[data-tab-id='${ activeIframe . dataset . tabId } ']` ) ;
91- if ( tabToUpdate ) {
91+ if ( tabToUpdate ) {
9292 console . log ( 'Tab to update:' , tabToUpdate ) ;
9393 const tabTitle = tabToUpdate . querySelector ( '.tab-title' ) ;
94- if ( tabTitle ) {
94+ if ( tabTitle ) {
9595 console . log ( 'Tab title:' , tabTitle ) ;
9696 tabTitle . textContent = event . data . url
9797 console . log ( 'Hostname:' , event . data . url ) ;
@@ -107,37 +107,37 @@ document.addEventListener("DOMContentLoaded", function(event) {
107107 } else {
108108 console . log ( 'No URL data in the message.' ) ;
109109 }
110- } ) ;
111-
112-
113-
114-
115-
116- function switchTab ( event ) {
110+ } ) ;
111+
112+
113+
114+
115+
116+ function switchTab ( event ) {
117117 const tabId = event . target . closest ( 'li' ) . dataset . tabId ;
118-
118+
119119 const allTabs = Array . from ( tabList . querySelectorAll ( 'li' ) ) ;
120120 allTabs . forEach ( tab => tab . classList . remove ( 'active' ) ) ;
121121 const allIframes = Array . from ( iframeContainer . querySelectorAll ( 'iframe' ) ) ;
122122 allIframes . forEach ( iframe => iframe . classList . remove ( 'active' ) ) ;
123-
123+
124124 const selectedTab = tabList . querySelector ( `[data-tab-id='${ tabId } ']` ) ;
125125 if ( selectedTab ) {
126126 selectedTab . classList . add ( 'active' ) ;
127127 } else {
128128 console . log ( 'No selected tab found with ID:' , tabId ) ;
129129 }
130-
130+
131131 const selectedIframe = iframeContainer . querySelector ( `[data-tab-id='${ tabId } ']` ) ;
132132 if ( selectedIframe ) {
133133 selectedIframe . classList . add ( 'active' ) ;
134134 } else {
135135 console . log ( 'No selected iframe found with ID:' , tabId ) ;
136136 }
137137 }
138-
139-
140-
138+
139+
140+
141141 toggleNavButton . addEventListener ( 'click' , ( ) => {
142142 navOpen = ! navOpen ;
143143 toggleNavButton . classList . toggle ( 'open' ) ;
@@ -147,20 +147,20 @@ document.addEventListener("DOMContentLoaded", function(event) {
147147 rightSideNav . style . transform = 'translateX(-100%)' ;
148148 }
149149 } ) ;
150-
151- let dragTab = null ;
152-
153-
150+
151+ let dragTab = null ;
152+
153+
154154 tabList . addEventListener ( 'dragstart' , ( event ) => {
155155 dragTab = event . target ;
156156 } ) ;
157-
158-
157+
158+
159159 tabList . addEventListener ( 'dragover' , ( event ) => {
160160 event . preventDefault ( ) ;
161161 const targetTab = event . target ;
162162 if ( targetTab . tagName === 'LI' && targetTab !== dragTab ) {
163-
163+
164164 const targetIndex = Array . from ( tabList . children ) . indexOf ( targetTab ) ;
165165 const dragIndex = Array . from ( tabList . children ) . indexOf ( dragTab ) ;
166166 if ( targetIndex < dragIndex ) {
@@ -170,14 +170,14 @@ document.addEventListener("DOMContentLoaded", function(event) {
170170 }
171171 }
172172 } ) ;
173-
174-
173+
174+
175175 tabList . addEventListener ( 'dragend' , ( ) => {
176176 dragTab = null ;
177177 } ) ;
178-
178+
179179 const container = document . querySelector ( '.container' ) ;
180-
180+
181181 toggleNavButton . addEventListener ( 'click' , ( ) => {
182182 navOpen = ! navOpen ;
183183 toggleNavButton . classList . toggle ( 'open' ) ;
@@ -188,25 +188,39 @@ document.addEventListener("DOMContentLoaded", function(event) {
188188 rightSideNav . style . transform = 'translateX(-100%)' ;
189189 }
190190 } ) ;
191-
191+
192192 toggleNavButton . addEventListener ( 'click' , ( ) => {
193193 navOpen = ! navOpen ;
194194 toggleNavButton . classList . toggle ( 'open' ) ;
195195 container . classList . toggle ( 'nav-closed' ) ;
196196 } ) ;
197-
198- } ) ;
197+
198+ } ) ;
199+
199200function reload ( ) {
200201 const iframeContainer = document . getElementById ( 'iframe-container' ) ;
201202 const iframes = Array . from ( iframeContainer . querySelectorAll ( 'iframe' ) ) ;
202203 const activeIframe = iframes . find ( iframe => iframe . classList . contains ( 'active' ) ) ;
203- activeIframe . src = activeIframe . src ;
204+ activeIframe . src = activeIframe . src ;
204205}
206+
205207function expand ( ) {
206208 const iframeContainer = document . getElementById ( 'iframe-container' ) ;
207209 const iframes = Array . from ( iframeContainer . querySelectorAll ( 'iframe' ) ) ;
208210 const activeIframe = iframes . find ( iframe => iframe . classList . contains ( 'active' ) ) ;
209211 activeIframe . requestFullscreen ( ) ;
210212}
211213
212-
214+ function goBack ( ) {
215+ const iframeContainer = document . getElementById ( 'iframe-container' ) ;
216+ const iframes = Array . from ( iframeContainer . querySelectorAll ( 'iframe' ) ) ;
217+ const activeIframe = iframes . find ( iframe => iframe . classList . contains ( 'active' ) ) ;
218+ activeIframe . contentWindow . history . back ( ) ;
219+ }
220+
221+ function goForward ( ) {
222+ const iframeContainer = document . getElementById ( 'iframe-container' ) ;
223+ const iframes = Array . from ( iframeContainer . querySelectorAll ( 'iframe' ) ) ;
224+ const activeIframe = iframes . find ( iframe => iframe . classList . contains ( 'active' ) ) ;
225+ activeIframe . contentWindow . history . forward ( ) ;
226+ }
0 commit comments