Skip to content

Instantly share code, notes, and snippets.

@belackriv
Created January 17, 2017 16:15
Show Gist options
  • Save belackriv/84b5d718d3b758cce5136169ef3476a6 to your computer and use it in GitHub Desktop.
Save belackriv/84b5d718d3b758cce5136169ef3476a6 to your computer and use it in GitHub Desktop.
Mn Close on Click-off region
'use strict';
import Marionette from 'marionette';
export default Marionette.Region.extend({
onShow(view, region, options){
if(!options.event){
throw 'Must Supply an event with contextmenu show';
}
options.event.preventDefault();
options.event.stopPropagation();
region.open(view);
region.$el.position({
at: 'bottom right',
of: options.event,
collision: 'fit'
});
this.clickOffHandler = this.clickOff.bind(this, view, options.event);
$('body').on('click contextmenu', this.clickOffHandler);
},
clickOff(view, event){
this.close(view);
},
open(view){
if(view){
view.$el.css('display','block');
}else if(this.currentView){
this.currentView.$el.css('display','block');
}
},
close(view){
$('body').off('click contextmenu', this.clickOffHandler);
if(view){
view.$el.css('display','none');
}else if(this.currentView){
this.currentView.$el.css('display','none');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment