text: kacheApp.service('adminSidebarService', function($window, utilityService) {
    var window = $window,
    CURRENT_URL = window.location.href.split('#')[0].split('?')[0],
    $BODY = $('body'),
    $MENU_TOGGLE = $('#menu_toggle'),
    $SIDEBAR_FOOTER = $('.sidebar-footer'),
    $LEFT_COL = $('.left_col'),
    $RIGHT_COL = $('.right_col'),
    $NAV_MENU = $('.nav_menu'),
    $FOOTER = $('footer');
  
    var setContentHeight = function () {
      // reset height
      $RIGHT_COL.css('min-height', $(window).height());
  
      var bodyHeight = $BODY.outerHeight(),
      footerHeight = $BODY.hasClass('footer_fixed') ? -10 : $FOOTER.height(),
      leftColHeight = $LEFT_COL.eq(1).height() + $SIDEBAR_FOOTER.height(),
      contentHeight = bodyHeight < leftColHeight ? leftColHeight : bodyHeight;
  
      // normalize content
      contentHeight -= $NAV_MENU.height() + footerHeight;
  
      $RIGHT_COL.css('min-height', contentHeight);
    }
        
    var initAdmin = function initAdmin() {
      $SIDEBAR_MENU = $('#sidebar-menu');
      /**
       * Resize function without multiple trigger
       * 
       * Usage:
       * $(window).smartresize(function(){  
       *     // code here
       * });
       */
      (function($,sr){
        // debouncing function from John Hann
        // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
        var debounce = function (func, threshold, execAsap) {
          var timeout;
  
          return function debounced () {
            var obj = this, args = arguments;
            function delayed () {
              if (!execAsap)
                func.apply(obj, args); 
              timeout = null; 
            }
  
            if (timeout)
              clearTimeout(timeout);
            else if (execAsap)
              func.apply(obj, args);
  
            timeout = setTimeout(delayed, threshold || 100); 
          };
        };
  
        // smartresize 
        jQuery.fn[sr] = function(fn){  return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
  
      })(jQuery,'smartresize');
  
  
      // Sidebar
      $SIDEBAR_MENU.find('a').on('click', function(ev) {
        var $li = $(this).parent();
  
        if ($li.is('.active') && $li.children('ul').first().is(':visible')) {
           //$li.removeClass('active active-sm');
          $('ul:first', $li).slideUp(function() {
            setContentHeight();
          });
        } else {
            // prevent closing menu if we are on child menu
          if (!$li.parent().is('.child_menu')) {
            $SIDEBAR_MENU.find('li').removeClass('active active-sm');
            $SIDEBAR_MENU.find('li ul').slideUp();
          }else {
            $li.parent('ul').children('li').removeClass('active current-page');
          }
          
          $li.addClass('active');
          $('ul:first', $li).slideDown(function() {
            setContentHeight();
          });
        }
      });
  
      // check active menu
      $SIDEBAR_MENU.find('a[href="' + CURRENT_URL + '"]').parent('li').addClass('current-page');
  
      $SIDEBAR_MENU.find('a').filter(function () {
        return this.href == CURRENT_URL;
      }).parent('li.child-li').parent('ul.child_menu').parent('li.main-li').addClass('active').parent('ul.side-menu').slideDown(function() {
        setContentHeight();
      });
  
      // recompute content when resizing
      $(window).smartresize(function(){  
        setContentHeight();
      });
  
      setContentHeight();
  
      // fixed sidebar
      if ($.fn.mCustomScrollbar) {
        $('.menu_fixed').mCustomScrollbar({
          autoHideScrollbar: true,
          theme: 'minimal',
          mouseWheel:{ preventDefault: true }
        });
      }
      // /Sidebar
  
      // Tooltip
      $('[data-toggle="tooltip"]').tooltip({
        container: 'body'
      });
      // /Tooltip
  
    }
  
    var toggleMenu = function toggleMenu(){
      // toggle small or large menu
      if ($BODY.hasClass('nav-md')) {
        $SIDEBAR_MENU.find('li.active ul').hide();
        $SIDEBAR_MENU.find('li.active').addClass('active-sm').removeClass('active');
      } else {
        $SIDEBAR_MENU.find('li.active-sm ul').show();
        $SIDEBAR_MENU.find('li.active-sm').addClass('active').removeClass('active-sm');
      }
  
      $BODY.toggleClass('nav-md nav-sm');
  
      setContentHeight();
    }
  
    return({
      init: initAdmin,
      toggleMenu: toggleMenu
    });
  });