2023-08-25 16:52:26 +08:00
( function ( ) {
'use strict' ;
2023-12-09 09:36:20 +08:00
var url _re = /(axmolengine\.github\.io\/manual\/)(latest|(\d\.\d+|\d\.\d+\.\d+)(-beta\d)?)\// ;
2023-08-31 21:20:01 +08:00
var url _local = /docs\/dist\/manual\/(latest|(\d\.\d+|\d\.\d+\.\d+)(-beta\d)?)\// ;
2023-08-25 16:52:26 +08:00
var current _version _local = '@VERSION@'
var all _versions = [
@ VERLIST @
] ;
function build _select ( current _version ) {
if ( current _version == 'latest' ) {
let top _elt = document . getElementById ( "top" ) ;
let first _element = top _elt . childNodes [ 0 ] ;
let new _div = document . createElement ( "p" ) ;
new _div . innerHTML = '⚠️ This documentation corresponds to the <a style="font-familly: monospace;" href="https://github.com/axmolengine/axmol/tree/dev">latest</a> development branch of axmol. It might diverge from the official releases.' ;
new _div . style . cssText = "background-color: #ff9800; margin: 1ex auto 1ex 1em; padding: 1ex; border-radius: 1ex; display: inline-block;"
let OK = top _elt . insertBefore ( new _div , first _element ) ;
}
var buf = [ '<select>' ] ;
$ . each ( all _versions , function ( id ) {
var version = all _versions [ id ] ;
buf . push ( '<option value="' + version + '"' ) ;
if ( version == current _version ) {
buf . push ( ' selected="selected">' + version ) ;
} else {
buf . push ( '>' + version ) ;
}
buf . push ( '</option>' ) ;
} ) ;
if ( ! all _versions . includes ( current _version ) ) {
buf . push ( '<option value="' + current _version + '"' ) ;
buf . push ( ' selected="selected">' + current _version ) ;
buf . push ( '</option>' ) ;
}
buf . push ( '</select>' ) ;
return buf . join ( '' ) ;
}
function patch _url ( url , new _version ) {
2023-12-09 09:36:20 +08:00
if ( url . includes ( "axmolengine.github.io" ) ) {
return url . replace ( url _re , 'axmolengine.github.io/manual/' + new _version + '/' ) ;
2023-08-25 16:52:26 +08:00
}
else {
2023-08-31 21:20:01 +08:00
return url . replace ( url _local , 'docs/dist/manual/' + new _version + '/' ) ;
2023-08-25 16:52:26 +08:00
}
}
function on _switch ( ) {
var selected = $ ( this ) . children ( 'option:selected' ) . attr ( 'value' ) ;
var url = window . location . href ,
new _url = patch _url ( url , selected ) ;
if ( new _url != url ) {
window . location . href = new _url ;
}
}
$ ( document ) . ready ( function ( ) {
var motherNode = $ ( "#back-nav ul" ) [ 0 ] ;
var node = document . createElement ( "LI" ) ;
var spanNode = document . createElement ( "SPAN" ) ;
var titleNode = document . createTextNode ( "axmol Version: " ) ;
var textNode = document . createTextNode ( "x.y" ) ;
spanNode . setAttribute ( "class" , "version_menu" ) ;
spanNode . appendChild ( textNode ) ;
node . appendChild ( titleNode ) ;
node . appendChild ( spanNode ) ;
motherNode . insertBefore ( node , motherNode . firstChild ) ;
$ ( "#back-nav" ) . css ( "padding-top" , "0" ) . css ( "padding-bottom" , "0" ) ;
var match = url _re . exec ( window . location . href ) ;
if ( match ) {
var version = match [ 2 ] ;
var select = build _select ( version ) ;
spanNode . innerHTML = select ;
$ ( '.version_menu select' ) . bind ( 'change' , on _switch ) ;
}
else {
match = url _local . exec ( window . location . href ) ;
if ( match ) {
var version = current _version _local ;
var select = build _select ( version ) ;
spanNode . innerHTML = select ;
$ ( '.version_menu select' ) . bind ( 'change' , on _switch ) ;
}
}
} ) ;
} ) ( ) ;