Skip to content

Commit

Permalink
menu finished
Browse files Browse the repository at this point in the history
  • Loading branch information
ondras committed May 14, 2014
1 parent d586a84 commit 930ac94
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 22 deletions.
26 changes: 26 additions & 0 deletions css/menu.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#menu {
position: absolute;
z-index: 1;
border: 1px solid #666;
background-color: #fff;
}

#menu button {
display: block;
background-color: transparent;
border: none;
margin: 0;
padding: 3px 6px;
width: 120px;
}

#menu button:hover {
font-weight: bold;
}

#menu span {
display: block;
border-top: 1px solid #666;
margin-top: 4px;
padding-top: 4px;
}
12 changes: 1 addition & 11 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import url(ui.css);
@import url(item.css);
@import url(shape.css);
@import url(menu.css);

* {
font-family: source sans pro, sans-serif;
Expand Down Expand Up @@ -57,14 +58,3 @@ ul {
#tip.hidden {
opacity: 0;
}

#menu {
position: absolute;
z-index: 1;
}

#menu button {
display: block;
background-color: #fff;
border: none;
}
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ <h3>Help</h3>
</div>

<div id="menu">
<button data-command="InsertSibling"></button>
<button data-command="InsertChild"></button>
<button data-command="InsertSibling"></button>
<button data-command="Delete"></button>
<span></span>
<button data-command="Edit"></button>
<button data-command="Value"></button>
</div>

<script>
Expand Down
31 changes: 26 additions & 5 deletions my-mind.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,14 @@ MM.Item.prototype.startEditing = function() {

this._dom.text.addEventListener("input", this);
this._dom.text.addEventListener("keydown", this);
this._dom.text.addEventListener("blur", this);
return this;
}

MM.Item.prototype.stopEditing = function() {
this._dom.text.removeEventListener("input", this);
this._dom.text.removeEventListener("keydown", this);
this._dom.text.removeEventListener("blur", this);

this._dom.text.blur();
this._dom.text.contentEditable = false;
Expand All @@ -641,6 +643,10 @@ MM.Item.prototype.handleEvent = function(e) {
if (e.keyCode == 9) { e.preventDefault(); } /* TAB has a special meaning in this app, do not use it to change focus */
break;

case "blur":
MM.Command.Finish.execute();
break;

case "click":
if (this._collapsed) { this.expand(); } else { this.collapse(); }
MM.App.select(this);
Expand Down Expand Up @@ -1318,9 +1324,18 @@ MM.Menu = {
_port: null,

open: function(x, y) {
this._dom.node.style.left = x+"px";
this._dom.node.style.top = y+"px";
this._dom.node.style.display = "";
var w = this._dom.node.offsetWidth;
var h = this._dom.node.offsetHeight;

var left = x;
var top = y;

if (left > this._port.offsetWidth / 2) { left -= w; }
if (top > this._port.offsetHeight / 2) { top -= h; }

this._dom.node.style.left = left+"px";
this._dom.node.style.top = top+"px";
},

close: function() {
Expand All @@ -1333,11 +1348,17 @@ MM.Menu = {
return;
}

e.stopPropagation();
e.stopPropagation(); /* no dragdrop, no blur of activeElement */
e.preventDefault(); /* we do not want to focus the button */

var command = e.target.getAttribute("data-command");
if (!command) { return; }
MM.Command[command].execute();

command = MM.Command[command];
if (!command.isValid()) { return; }

command.execute();
this.close();
},

init: function(port) {
Expand Down Expand Up @@ -4289,7 +4310,7 @@ MM.Mouse.handleEvent = function(e) {
var item = MM.App.map.getItemFor(e.target);
if (item == MM.App.current && MM.App.editing) { return; }

document.activeElement && document.activeElement.blur(); /* blur the panel FIXME only if activeElement is in the UI? */
document.activeElement && document.activeElement.blur();
this._startDrag(e, item);
break;

Expand Down
6 changes: 6 additions & 0 deletions src/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,14 @@ MM.Item.prototype.startEditing = function() {

this._dom.text.addEventListener("input", this);
this._dom.text.addEventListener("keydown", this);
this._dom.text.addEventListener("blur", this);
return this;
}

MM.Item.prototype.stopEditing = function() {
this._dom.text.removeEventListener("input", this);
this._dom.text.removeEventListener("keydown", this);
this._dom.text.removeEventListener("blur", this);

this._dom.text.blur();
this._dom.text.contentEditable = false;
Expand All @@ -363,6 +365,10 @@ MM.Item.prototype.handleEvent = function(e) {
if (e.keyCode == 9) { e.preventDefault(); } /* TAB has a special meaning in this app, do not use it to change focus */
break;

case "blur":
MM.Command.Finish.execute();
break;

case "click":
if (this._collapsed) { this.expand(); } else { this.collapse(); }
MM.App.select(this);
Expand Down
23 changes: 19 additions & 4 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ MM.Menu = {
_port: null,

open: function(x, y) {
this._dom.node.style.left = x+"px";
this._dom.node.style.top = y+"px";
this._dom.node.style.display = "";
var w = this._dom.node.offsetWidth;
var h = this._dom.node.offsetHeight;

var left = x;
var top = y;

if (left > this._port.offsetWidth / 2) { left -= w; }
if (top > this._port.offsetHeight / 2) { top -= h; }

this._dom.node.style.left = left+"px";
this._dom.node.style.top = top+"px";
},

close: function() {
Expand All @@ -18,11 +27,17 @@ MM.Menu = {
return;
}

e.stopPropagation();
e.stopPropagation(); /* no dragdrop, no blur of activeElement */
e.preventDefault(); /* we do not want to focus the button */

var command = e.target.getAttribute("data-command");
if (!command) { return; }
MM.Command[command].execute();

command = MM.Command[command];
if (!command.isValid()) { return; }

command.execute();
this.close();
},

init: function(port) {
Expand Down
2 changes: 1 addition & 1 deletion src/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ MM.Mouse.handleEvent = function(e) {
var item = MM.App.map.getItemFor(e.target);
if (item == MM.App.current && MM.App.editing) { return; }

document.activeElement && document.activeElement.blur(); /* blur the panel FIXME only if activeElement is in the UI? */
document.activeElement && document.activeElement.blur();
this._startDrag(e, item);
break;

Expand Down

0 comments on commit 930ac94

Please sign in to comment.