(function ( $ ) { $.fn.BootSideMenu = function( options ) { var oldCode, newCode, side; newCode = ""; var settings = $.extend({ side:"left", autoClose:true }, options ); side = settings.side; autoClose = settings.autoClose; this.addClass(" sidebar"); if(side=="left"){ this.addClass("sidebar-left"); }else if(side=="right"){ this.addClass("sidebar-right"); }else{ this.addClass("sidebar-left"); } oldCode = this.html(); newCode += "
\n"; newCode += "
\n"+ oldCode+"
\n"; newCode += "
"; newCode += "
\n"; newCode += "    \n"; newCode += "
\n"; //Mod suggested by asingh3 //https://github.com/AndreaLombardo/BootSideMenu/issues/1 //this.html(newCode); var wrapper = $(newCode); // copy the children to the wrapper. $.each(this.children(), function () { $('.panel-content', wrapper).append(this); }); // Empty the element and then append the wrapper code. $(this).empty(); $(this).append(wrapper); if(autoClose){ $(this).find(".toggler").trigger("click"); } }; $(document).on('click', '.sidebar .list-group-item', function(){ $('.sidebar .list-group-item').each(function(){ $(this).removeClass('active'); }); $(this).addClass('active'); }); $(document).on('click', '.sidebar .list-group-item', function(event){ var idToToggle, this_offset, this_x, this_y, href, side; event.preventDefault(); href = $(this).attr('href'); if(href.substr(0,1)=='#'){ idToToggle = href.substr(1,href.length); if(searchSubMenu(idToToggle)){ this_offset = $(this).offset(); side = $(this).parent().parent().attr('data-side'); if(side=='left'){ this_x = $(this).width() + 10; this_y = this_offset.top +1; $('#'+idToToggle).css('left', this_x); $('#'+idToToggle).css('top', this_y); }else if(side=='right'){ this_x = $(this).width()+10; this_y = this_offset.top +1; $('#'+idToToggle).css('right', this_x); $('#'+idToToggle).css('top', this_y); } $('#'+idToToggle).fadeIn(); }else{ $('.submenu').fadeOut(); } } }); $(document).on('click','.toggler', function(){ var toggler = $(this); var container = toggler.parent(); //var listaClassi = container[0].classList; //Old var listaClassi = $(container[0]).attr('class').split(/\s+/); //IE9 Fix - Thanks Nicolas Renaud var side = getSide(listaClassi); var containerWidth = container.width(); var status = container.attr('data-status'); if(!status){ status = "opened"; } doAnimation(container, containerWidth, side, status); }); /*Cerca un div con classe submenu e id uguale a quello passato*/ function searchSubMenu(id){ var found = false; $('.submenu').each(function(){ var thisId = $(this).attr('id'); if(id==thisId){ found = true; } }); return found; } //restituisce il lato del sidebar in base alla classe che trova settata function getSide(listaClassi){ var side; for(var i = 0; i