I'm converting one Bootstrap + jQuery theme into Angular JS and I'm having some troubles to do so. One thing is this kind of functionality provided on the JS file of the theme:
/* Sidebar Navigation functionality */
var handleNav = function() {
// Animation Speed, change the values for different results
var upSpeed = 250;
var downSpeed = 250;
// Get all vital links
var allTopLinks = $('.sidebar-nav a');
var menuLinks = $('.sidebar-nav-menu');
var submenuLinks = $('.sidebar-nav-submenu');
// Primary Accordion functionality
menuLinks.click(function(){
var link = $(this);
if (link.parent().hasClass('active') !== true) {
if (link.hasClass('open')) {
link.removeClass('open').next().slideUp(upSpeed);
// Resize #page-content to fill empty space if exists
setTimeout(resizePageContent, upSpeed);
}
else {
$('.sidebar-nav-menu.open').removeClass('open').next().slideUp(upSpeed);
link.addClass('open').next().slideDown(downSpeed);
// Resize #page-content to fill empty space if exists
setTimeout(resizePageContent, ((upSpeed > downSpeed) ? upSpeed : downSpeed));
}
}
return false;
});
// Submenu Accordion functionality
submenuLinks.click(function(){
var link = $(this);
if (link.parent().hasClass('active') !== true) {
if (link.hasClass('open')) {
link.removeClass('open').next().slideUp(upSpeed);
// Resize #page-content to fill empty space if exists
setTimeout(resizePageContent, upSpeed);
}
else {
link.closest('ul').find('.sidebar-nav-submenu.open').removeClass('open').next().slideUp(upSpeed);
link.addClass('open').next().slideDown(downSpeed);
// Resize #page-content to fill empty space if exists
setTimeout(resizePageContent, ((upSpeed > downSpeed) ? upSpeed : downSpeed));
}
}
return false;
});
};
This is a function that runs when the app starts and is responsible for attaching functionallity on the sidebar. Basically this simply attaches handles to the click event of the links on the sidebar to add the dropdown effect and to resize the main container if needed.
That's fine, however, I don't see how to make this something "angular compliant". I mean, I could run this on the view loaded event, but it doesn't seem like a good idea. I imagine I need to use directives, but in this case I don't see how. This isn't something applied to one element, is in truth a bunch of things applied to a bunch of elements.
More than that, it interferes with disconnected elements: this also resizes the main container, so this invokes some functionality on some other element of the page.
How this specific functionality could be converted to something angular compliant?
EDIT : My idea here was to create two directives menu-link
and submenu-link
and then apply this directive on each of the links themselves. The code in the directives would be the same presented here. This doesn't seem practical however, since I would need to put the directive over and over again.