Skip to content

Instantly share code, notes, and snippets.

@vrana
Forked from NoxArt/restore-menu-scroll.php
Last active March 16, 2025 06:40
Show Gist options
  • Save vrana/8d9e12e260731a516f973a284760aa03 to your computer and use it in GitHub Desktop.
Save vrana/8d9e12e260731a516f973a284760aa03 to your computer and use it in GitHub Desktop.
AdminerRestoreMenuScroll plugin for Adminer
<?php
/** Remembers and restores scollbar position of side menu
* @author Jiří @NoxArt Petruželka, www.noxart.cz
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerRestoreMenuScroll {
protected $script;
/**
* @param string text to append before first calendar usage
*/
public function __construct($script = "<script type='text/javascript'" . Adminer\nonce() . ">\n(function(){\nvar executed = false;\nvar saveAndRestore = function() {\nif( executed ) {\nreturn;\n}\n
executed = true;\nvar menu = document.getElementById('menu');\nvar scrolled = localStorage.getItem('_adminerScrolled');\nif( scrolled && scrolled >= 0 ) {\nmenu.scrollTop = scrolled;\n}\n
window.addEventListener('unload', function(){\nlocalStorage.setItem('_adminerScrolled', menu.scrollTop);\n});\n};\ndocument.addEventListener && document.addEventListener('DOMContentLoaded', saveAndRestore);\ndocument.attachEvent && document.attachEvent('onreadystatechange', saveAndRestore);\n})();\n</script>")
{
$this->script = $script;
}
public function head()
{
echo $this->script;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment