history now working... (still not sure if it's needed)

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-04-22 01:49:11 +03:00
parent ad02c7e5a5
commit 0cd619d255

View File

@ -312,39 +312,38 @@ object.Constructor('BasePage', {
return this.__location ?? '/' }, return this.__location ?? '/' },
set location(path){ set location(path){
this.referrer = this.location this.referrer = this.location
var cur = this.__location =
module.path.relative(
this.location,
path)
//* XXX HISTORY... //* XXX HISTORY...
if(this.history !== false){
this.history.includes(this.__location) this.history.includes(this.__location)
&& this.history.splice( && this.history.splice(
this.history.indexOf(this.__location)+1, this.history.indexOf(this.__location)+1,
this.history.length) this.history.length)
this.history.push( this.history.push(cur) } },
this.__location =
module.path.relative(
this.location,
path)) },
/*/
this.__location =
module.path.relative(
this.location,
path) },
//*/
// referrer -- a previous page location... // referrer -- a previous page location...
referrer: undefined, referrer: undefined,
//* XXX HISTORY... //* XXX HISTORY...
// XXX should these maintain .referrer ??? // NOTE: set this to false to disable history...
__history: undefined, __history: undefined,
get history(){ get history(){
if(this.__history === false){
return false }
if(!this.hasOwnProperty('__history')){ if(!this.hasOwnProperty('__history')){
this.__history = [] } //this.__history = [] }
this.__history = (this.__history ?? []).slice() }
return this.__history }, return this.__history },
// XXX add offset argument...
back: function(offset=1){ back: function(offset=1){
var h = this.history var h = this.history
if(h.length <= 1){ if(h === false
|| h.length <= 1){
return this } return this }
// get position in history... // get position in history...
var p = h.indexOf(this.location) var p = h.indexOf(this.location)
// if outside of history go to last element...
p = p < 0 ? p = p < 0 ?
h.length h.length
: p : p