/* eslint-env jquery */ export default class OffCanvasSearch { constructor( args = {} ) { this.toggler = args.toggler; this.overlay = args.overlay; this.search = args.search; this.close = args.close; this.initAction = this.initAction.bind( this ); this.openSearch = this.openSearch.bind( this ); this.closeSearch = this.closeSearch.bind( this ); this.init = this.init.bind( this ); this.init(); } init() { const that = this; $( this.toggler ).on( 'click', function( e ) { e.preventDefault(); that.initAction(); } ); $( this.close ).on( 'click', function( e ) { e.preventDefault(); that.closeSearch(); } ); $( this.overlay ).on( 'click', function( e ) { e.preventDefault(); that.closeSearch(); } ); } initAction() { if ( $( this.search ).hasClass( 'show' ) ) { this.closeSearch(); } else { this.openSearch(); } } openSearch() { $( this.search ).addClass( 'show' ); $( this.search ).removeClass( 'is-off' ); $( this.overlay ).removeClass( 'is-off' ); } closeSearch() { $( this.search ).removeClass( 'show' ); $( this.search ).addClass( 'is-off' ); $( this.overlay ).addClass( 'is-off' ); } }