Javascript refactoring

This commit is contained in:
Frederic Guillot
2015-08-04 22:51:44 -04:00
parent f04ec0700c
commit e13872fc2e
28 changed files with 1210 additions and 1293 deletions

50
assets/js/src/Popover.js Normal file
View File

@@ -0,0 +1,50 @@
function Popover(app) {
this.app = app;
this.router = new Router();
this.router.addRoute('screenshot-zone', Screenshot);
Mousetrap.bindGlobal("esc", this.close);
}
Popover.prototype.isOpen = function() {
return $('#popover-container').size() > 0;
};
Popover.prototype.open = function(link) {
var self = this;
$.get(link, function(content) {
$("body").append('<div id="popover-container"><div id="popover-content">' + content + '</div></div>');
self.router.dispatch();
self.app.listen();
});
};
Popover.prototype.close = function(e) {
if (e) {
e.preventDefault();
}
$('#popover-container').remove();
};
Popover.prototype.onClick = function(e) {
e.preventDefault();
e.stopPropagation();
var link = e.target.getAttribute("href");
if (! link) {
link = e.target.getAttribute("data-href");
}
if (link) {
this.open(link);
}
};
Popover.prototype.listen = function() {
$(document).on("click", ".popover", this.onClick.bind(this));
$(document).on("click", ".close-popover", this.close.bind(this));
$(document).on("click", "#popover-container", this.close.bind(this));
$(document).on("click", "#popover-content", function(e) { e.stopPropagation(); });
};