Skip to content

Instantly share code, notes, and snippets.

@ClausPolanka
Created March 23, 2014 10:51
Show Gist options
  • Save ClausPolanka/9721539 to your computer and use it in GitHub Desktop.
Save ClausPolanka/9721539 to your computer and use it in GitHub Desktop.
Schoki
<html>
<head>
<title>Schoki</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<a class="menu" href="#">Home</a>
<a class="menu" href="#">Services</a>
<a class="menu" href="#">About</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js"></script>
<script>
(function() {
var currentMenuText = '';
var menuItems = $('a.menu');
menuItems.hover(
function () {
var currentMenu = $(this);
var text = currentMenu.text();
if (text.indexOf('[ ') == -1) {
currentMenu.text('[ ' + text + ' ]');
};
},
function () {
replaceBracketsOf(this, currentMenuText);
});
menuItems.click(function() {
currentMenuText = $(this).text();
menuItems.each(function() {
replaceBracketsOf(this, currentMenuText);
});
});
})();
function replaceBracketsOf(element, currentMenuText) {
var currentMenu = $(element);
var text = currentMenu.text();
if (text != currentMenuText) {
text = text.replace('[ ', '')
.replace(' ]', '');
currentMenu.text(text);
};
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment