Commit e2510437 authored by Téo Vasseur's avatar Téo Vasseur

js : vmi variable

parent 441fed5a
var views = [];
var selectedView;
var vmi = {};
vmi.views = [];
vmi.selectedView;
function View(id, parentId, classes) {
this.parentId = parentId;
this.id = id;
views.push(this);
vmi.views.push(this);
var parent = document.getElementById(parentId);
......@@ -20,51 +22,50 @@ function View(id, parentId, classes) {
// parent.appendChild(node);
}
function setView(view, panel) {
vmi.setView = function(view, panel) {
if (panel) view.parentId = panel;
document.getElementById(view.parentId).appendChild(view.node);
}
function viewSelector(view) {
vmi.viewSelector = function(view) {
var f = function() {
hideOverlays();
vmi.hideOverlays();
$(".overlay").show();
selectedView = view;
vmi.selectedView = view;
}
return f;
}
function viewSetter(view) {
vmi.viewSetter = function(view) {
var focus = function(target) {
target.className += " focused";
var listener = function() {
vmi.hideOverlays();
target.removeEventListener('click', listener);
};
target.addEventListener('click', listener);
}
var f = function(e) {
if (e.ctrlKey) {
hideOverlays();
vmi.hideOverlays();
$(".overlay").show();
selectedView = view;
vmi.selectedView = view;
focus(e.target);
} else {
setView(view);
vmi.setView(view);
}
};
return f;
}
function focus(target) {
target.className += " focused";
var listener = function() {
hideOverlays();
target.removeEventListener('click', listener);
};
target.addEventListener('click', listener);
}
function setMenuOptions() {
vmi.setMenuOptions = function() {
var menu = document.getElementById("menu");
var div;
for (var i in views) {
for (var i in vmi.views) {
div = document.createElement('div');
div.textContent = views[i].id;
div.onclick = viewSetter(views[i]);
div.textContent = vmi.views[i].id;
div.onclick = vmi.viewSetter(vmi.views[i]);
// div.ondblclick = viewSelector(views[i]);
// div.addEventListener('dblclick', focus);
......@@ -73,19 +74,19 @@ function setMenuOptions() {
}
}
function hideOverlays() {
vmi.hideOverlays = function() {
$(".overlay").hide();
$(".focused").removeClass("focused");
selectedView = undefined;
vmi.selectedView = undefined;
}
function setOverlays() {
vmi.setOverlays = function() {
var setOverlay = function(id) {
div = document.createElement('div');
div.className = "overlay";
div.onclick = function() {
setView(selectedView, id);
hideOverlays();
vmi.setView(vmi.selectedView, id);
vmi.hideOverlays();
}
document.getElementById(id).appendChild(div);
}
......
......@@ -26,8 +26,8 @@ function main() {
var v7 = new Heavy("v7", 'B');
setMenuOptions();
setOverlays();
vmi.setMenuOptions();
vmi.setOverlays();
}
main();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment