var SmartMenu = {
opts: {
className: 'active'
},
init: function() {
this.view = $( '[data-controller="SmartMenu"]' );
this.menuElements = this.view.find( '.cell' );
this.smartElements = this.view.find( '.smart_menu' );
this.events();
},
events: function() {
var _this = this;
this.menuElements.on( 'mouseenter mouseleave', function( e ) {
var $this = $( this );
var id = $this.data().id;
switch ( e.type ) {
case "mouseenter":
_this.show( id );
break;
case "mouseleave":
_this.hide( id );
break;
default:
var msg = "No such event actions."
if ( typeof console.warn !== 'undefined' ) {
console.warn( msg );
} else {
console.log( msg );
}
break;
}
});
},
show: function( id ) {
if ( this.smartElements.filter( '[data-id=' + id + ']' ).length > 0 ) {
this.menuElements.filter( '[data-id=' + id + ']' ).addClass( this.opts.className );
}
},
hide: function( id ) {
this.menuElements.filter( '[data-id=' + id + ']' ).removeClass( this.opts.className );
}
}
$(function(){
SmartMenu.init();
});