1 line
2.6 KiB
Plaintext
1 line
2.6 KiB
Plaintext
{"version":3,"file":"browserbuttonevents.min.js","sources":["../../src/util/browserbuttonevents.js"],"sourcesContent":["/*eslint no-var: \"error\" */\n/*eslint no-unused-vars: \"off\" */\n/*eslint linebreak-style: \"off\" */\n/*eslint no-trailing-spaces: \"off\" */\n/*eslint-env es6*/\n\nimport Debugger from './debugger';\nconst debug = new Debugger(\"browserbuttonevents\");\n\n/**\n * \n * @param {function} backwardCB \n * @param {function} forwardCB \n * @param {function} reloadCB \n */\nexport function addBrowserButtonEvent(backwardCB, forwardCB = null, reloadCB = null) {\n debug.log(\"Registering navigation events\",backwardCB,forwardCB,reloadCB);\n const reorient = (e) => { // After travelling in the history stack\n const positionLastShown = Number( // If none, then zero\n sessionStorage.getItem( 'positionLastShown' ));\n// debug.log(\"Popstate event\",e,positionLastShown,history);\n let position = history.state; // Absolute position in stack\n if( position === null ) { // Meaning a new entry on the stack\n position = positionLastShown + 1; // Top of stack\n \n // (1) Stamp the entry with its own position in the stack\n history.replaceState( position, /*no title*/'' ); \n }\n \n // (2) Keep track of the last position shown\n sessionStorage.setItem( 'positionLastShown', String(position) );\n \n // (3) Discover the direction of travel by comparing the two\n const direction = Math.sign( position - positionLastShown );\n debug.log( 'Travel direction is ' + direction ); \n // One of backward (-1), reload (0) and forward (1)\n if (direction == -1 && backwardCB) {\n backwardCB();\n }\n if (direction == 1 && forwardCB) {\n forwardCB();\n }\n if (direction == 0 && reloadCB) {\n reloadCB();\n }\n };\n //addEventListener( 'pageshow', reorient );\n addEventListener( 'popstate', reorient ); // Travel in same page\n}"],"names":["backwardCB","forwardCB","reloadCB","debug","log","addEventListener","e","positionLastShown","Number","sessionStorage","getItem","position","history","state","replaceState","setItem","String","direction","Math","sign"],"mappings":"qNAesCA,gBAAYC,iEAAY,KAAMC,gEAAW,KAC3EC,MAAMC,IAAI,gCAAgCJ,WAAWC,UAAUC,UA+B/DG,iBAAkB,YA9BAC,UACRC,kBAAoBC,OACxBC,eAAeC,QAAS,0BAEtBC,SAAWC,QAAQC,MACN,OAAbF,WACAA,SAAWJ,kBAAoB,EAG/BK,QAAQE,aAAcH,SAAsB,KAIhDF,eAAeM,QAAS,oBAAqBC,OAAOL,iBAG9CM,UAAYC,KAAKC,KAAMR,SAAWJ,mBACxCJ,MAAMC,IAAK,uBAAyBa,YAElB,GAAdA,WAAmBjB,YACnBA,aAEa,GAAbiB,WAAkBhB,WAClBA,YAEa,GAAbgB,WAAkBf,UAClBA,qBApCNC,MAAQ,yEAAa"} |