Howly mowly! Toggleable menus are now working with cookies
This commit is contained in:
@@ -67,8 +67,8 @@
|
|||||||
<?
|
<?
|
||||||
endif;
|
endif;
|
||||||
?>
|
?>
|
||||||
<li>
|
<li class="toggleable" id="nav_projects">
|
||||||
<a href="javascript:void(0);" onclick="$(this).parent().toggleClass('active').find('ul').slideToggle();"><?=_('Projects');?></a>
|
<a href="javascript:void(0);"><?=_('Projects');?></a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="<?=site_url('projects/create');?>" title="<?=_('Create a new project');?>"><?=_('New project');?></a></li>
|
<li><a href="<?=site_url('projects/create');?>" title="<?=_('Create a new project');?>"><?=_('New project');?></a></li>
|
||||||
<li><a href="<?=site_url('projects');?>" title="<?=_('Shows a list of all projects');?>"><?=_('Show projects');?></a></li>
|
<li><a href="<?=site_url('projects');?>" title="<?=_('Shows a list of all projects');?>"><?=_('Show projects');?></a></li>
|
||||||
@@ -83,8 +83,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="navigation">
|
<div class="navigation">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li class="toggleable" id="nav_own_projects">
|
||||||
<a href="javascript:void(0);" onclick="$(this).parent().toggleClass('active').find('ul').slideToggle();"><?=_('Own projects')?></a>
|
<a href="javascript:void(0);"><?=_('Own projects')?></a>
|
||||||
<ul>
|
<ul>
|
||||||
<?
|
<?
|
||||||
$projects = $this->project->getOwn();
|
$projects = $this->project->getOwn();
|
||||||
@@ -96,14 +96,14 @@
|
|||||||
?>
|
?>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li class="toggleable" id="nav_shared_projects">
|
||||||
<a href="javascript:void(0);" onclick="$(this).parent().toggleClass('active').find('ul').slideToggle();"><?=_('Projects shared with me')?></a>
|
<a href="javascript:void(0);"><?=_('Projects shared with me')?></a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#">Prisma</a></li>
|
<li><a href="#">Prisma</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li class="toggleable" id="nav_public_projects">
|
||||||
<a href="javascript:void(0);" onclick="$(this).parent().toggleClass('active').find('ul').slideToggle();"><?=_('Public projects')?></a>
|
<a href="javascript:void(0);"><?=_('Public projects')?></a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#">Beispielprojekt</a></li>
|
<li><a href="#">Beispielprojekt</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -22,6 +22,81 @@ function deleteConfirm(url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a cookie.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param value
|
||||||
|
* @param days
|
||||||
|
*/
|
||||||
|
function setCookie(name, value, days) {
|
||||||
|
var today = new Date();
|
||||||
|
var expire = new Date();
|
||||||
|
|
||||||
|
if (days == null || days == 0) {
|
||||||
|
days = 1;
|
||||||
|
}
|
||||||
|
expire.setTime(today.getTime() + 3600000 * 24 * days);
|
||||||
|
document.cookie = name + "=" + escape(value) + ";path=/;expires=" + expire.toGMTString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a cookie.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
function getCookie(name) {
|
||||||
|
var cookie = ' ' + document.cookie;
|
||||||
|
var index = cookie.indexOf(" " + name + "=");
|
||||||
|
|
||||||
|
if (index == -1) {
|
||||||
|
index = cookie.indexOf(";" + name + "=");
|
||||||
|
}
|
||||||
|
if (index == -1 || name == '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
var index2 = cookie.indexOf(";", index + 1);
|
||||||
|
|
||||||
|
if (index2 == -1) {
|
||||||
|
index2 = cookie.length;
|
||||||
|
}
|
||||||
|
return unescape(cookie.substring(index + name.length + 2, index2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param cookieName
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
var CookieList = function(cookieName) {
|
||||||
|
var cookie = getCookie(cookieName);
|
||||||
|
// load the items or a new array if null
|
||||||
|
var items = cookie ? cookie.split(/,/) : new Array();
|
||||||
|
|
||||||
|
return {
|
||||||
|
"add": function(val) {
|
||||||
|
// add to the items
|
||||||
|
items.push(val);
|
||||||
|
// save the items to a cookie
|
||||||
|
setCookie(cookieName, items.join(','));
|
||||||
|
}, "remove": function(val) {
|
||||||
|
// remove the value from items
|
||||||
|
items.splice(items.indexOf(val), 1);
|
||||||
|
// save the items to a cookie
|
||||||
|
setCookie(cookieName, items.join(','));
|
||||||
|
}, "clear": function() {
|
||||||
|
items = null;
|
||||||
|
// clear the cookie
|
||||||
|
setCookie(cookieName, null, null);
|
||||||
|
}, "items": function() {
|
||||||
|
// get all the items
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the changes done by in-place edit.
|
* Saves the changes done by in-place edit.
|
||||||
*
|
*
|
||||||
@@ -207,4 +282,27 @@ $(document).ready(function() {
|
|||||||
window.location = url;
|
window.location = url;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Toggleable navigation
|
||||||
|
*/
|
||||||
|
var toggleList = new CookieList("toggled");
|
||||||
|
var toggled = toggleList.items();
|
||||||
|
|
||||||
|
for (var i = 0; i < toggled.length; i++) {
|
||||||
|
$('#' + toggled[i]).toggleClass('active').find('ul').hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.toggleable').find('a').click(function() {
|
||||||
|
var id = $(this).parent().attr('id');
|
||||||
|
|
||||||
|
// toggle
|
||||||
|
$(this).parent().toggleClass('active').find('ul').toggle();
|
||||||
|
|
||||||
|
if ($(this).next().css('display') == 'none') {
|
||||||
|
toggleList.add(id);
|
||||||
|
} else {
|
||||||
|
toggleList.remove(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user