File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,19 @@ function updateScastieTheme() {
37
37
scastie . Embedded ( '.scastie' , settings ) ;
38
38
}
39
39
40
+ //simulate click event without changing the view
41
+ function simulateClick ( element ) {
42
+ const x = window . scrollX ;
43
+ const y = window . scrollY ;
44
+ var event = new MouseEvent ( 'click' , {
45
+ view : window ,
46
+ bubbles : true ,
47
+ cancelable : true
48
+ } ) ;
49
+ element . dispatchEvent ( event ) ;
50
+ window . scrollTo ( x , y ) ;
51
+ }
52
+
40
53
function updateCodeBlocksAndDetails ( preferredLanguage ) {
41
54
var codeBlocks = document . querySelectorAll ( '.scastie' ) ; // Assuming all targeted code blocks have this class
42
55
codeBlocks . forEach ( function ( codeBlock ) {
@@ -67,7 +80,7 @@ function updateCodeBlocksAndDetails(preferredLanguage) {
67
80
) ;
68
81
tabLabels . forEach ( label => {
69
82
if ( label . textContent . includes ( "Verilog" ) ) {
70
- label . click ( ) ;
83
+ simulateClick ( label ) ;
71
84
}
72
85
} ) ;
73
86
} else { // VHDL
@@ -85,7 +98,7 @@ function updateCodeBlocksAndDetails(preferredLanguage) {
85
98
) ;
86
99
tabLabels . forEach ( label => {
87
100
if ( label . textContent . includes ( "VHDL" ) ) {
88
- label . click ( ) ;
101
+ simulateClick ( label ) ;
89
102
}
90
103
} ) ;
91
104
}
@@ -99,7 +112,7 @@ window.addEventListener("load", () => {
99
112
) ;
100
113
tabLabels . forEach ( label => {
101
114
if ( label . textContent . includes ( savedLanguage ) ) {
102
- label . click ( ) ;
115
+ simulateClick ( label ) ;
103
116
}
104
117
} ) ;
105
118
} ) ;
You can’t perform that action at this time.
0 commit comments