@@ -28,6 +28,19 @@ window.addEventListener("load", (event) => {
2828 document . body . classList . remove ( 'darkmode' ) ;
2929 }
3030} ) ;
31+ window . addEventListener ( "load" , ( event ) => {
32+ // if there is a wiki-nav then we need to remove the class assigned by default to let more space for the content
33+ let wikiNavContentWrapper = document . getElementsByClassName ( 'wiki-nav-content-wrapper' ) . length ;
34+ if ( wikiNavContentWrapper > 0 ) {
35+ console . log ( 'wiki-nav-content-wrapper found' ) ;
36+ document . getElementsByClassName ( 'container mt-5 p-5' ) [ 0 ] . classList . remove ( 'container' ) ;
37+ document . getElementsByClassName ( 'container mt-5 p-5' ) [ 0 ] . classList . remove ( 'p-5' ) ;
38+ document . getElementsByClassName ( 'container mt-5 p-5' ) [ 0 ] . classList . remove ( 'mt-5' ) ;
39+ document . getElementsByClassName ( 'text-right' ) [ 0 ] . parentElement . classList . add ( 'container' ) ;
40+ document . getElementsByClassName ( 'text-right' ) [ 0 ] . parentElement . classList . add ( 'mt-5' ) ;
41+ document . getElementsByClassName ( 'text-right' ) [ 0 ] . parentElement . classList . add ( 'p-5' ) ;
42+ }
43+ } ) ;
3144function toggleDarkMode ( ) {
3245 let darkMode = localStorage . getItem ( 'darkMode' ) ;
3346 let darkModeId = document . getElementById ( 'darkModeId' ) ;
@@ -50,15 +63,29 @@ window.addEventListener("load", (event) => {
5063 for ( let i = 0 ; i < pre . length ; i ++ ) {
5164 let button = document . createElement ( 'button' ) ;
5265 button . className = 'btn btn-primary btn-xs' ;
53- button . style . float = 'right' ;
54- button . style . marginTop = '10px' ;
55- button . style . marginLeft = '-150px' ;
66+ button . style . cssFloat = 'right' ;
5667 button . textContent = 'Copy' ;
57- button . onclick = function ( ) {
58- copyToClipboard ( this . nextElementSibling . textContent ) ;
59- } ;
60- pre [ i ] . insertAdjacentElement ( 'beforebegin' , button )
68+ button . onclick = function ( ) {
69+ copyToClipboard ( this . nextSibling . textContent ) ;
70+ this . textContent = 'Copied' ;
71+ this . className = 'btn btn-success btn-xs' ;
72+ setTimeout ( ( ) => {
73+ this . textContent = 'Copy' ;
74+ this . className = 'btn btn-primary btn-xs' ;
75+ } , 2000 ) ;
76+ } ;
77+ // this condition is for code blocks that have not been published since upgrade to v3.0.2
78+ if ( pre [ i ] . firstChild . tagName === 'SPAN' ) {
79+ // we put all the span elements in a code element so it can be copied
80+ let code = document . createElement ( 'code' ) ;
81+ while ( pre [ i ] . firstChild ) {
82+ code . appendChild ( pre [ i ] . firstChild ) ;
83+ pre [ i ] . removeChild ( pre [ i ] . firstChild ) ;
84+ }
85+ pre [ i ] . appendChild ( code ) ;
6186 }
87+ pre [ i ] . firstChild . before ( button ) ;
88+ }
6289} ) ;
6390
6491function copyToClipboard ( text ) {
@@ -68,4 +95,4 @@ function copyToClipboard(text) {
6895 dummy . select ( ) ;
6996 document . execCommand ( 'copy' ) ;
7097 document . body . removeChild ( dummy ) ;
71- }
98+ }
0 commit comments