Skip to content

Commit e3aa2d7

Browse files
committed
dragdrop, github
1 parent e923a2f commit e3aa2d7

File tree

5 files changed

+51
-34
lines changed

5 files changed

+51
-34
lines changed

css/ui.css

+18-8
Original file line numberDiff line numberDiff line change
@@ -103,30 +103,40 @@
103103
border-color: #000;
104104
}
105105

106+
.ui #github {
107+
position: absolute;
108+
right: 160px;
109+
bottom: 6px;
110+
}
111+
112+
.ui #github img {
113+
vertical-align: middle;
114+
}
115+
106116
.ui ~ #toggle {
107117
position: fixed;
108-
bottom: 25px;
109-
right: 75px;
110-
width: 50px;
111-
height: 50px;
112-
line-height: 30px;
118+
bottom: 6px;
119+
right: 10px;
120+
width: 32px;
121+
height: 32px;
122+
line-height: 18px;
113123
margin: auto;
114124
border-radius: 50%;
115125
box-shadow: 0 0 2px 3px #ccf;
116126
}
117127

118128
.ui ~ #toggle:after {
119-
content: "";
129+
content: "";
120130
font-weight: bold;
121-
font-size: 28px;
131+
font-size: 22px;
122132
}
123133

124134
.ui.visible ~ #toggle {
125135
box-shadow: inset 0 0 2px 3px #ccf;
126136
}
127137

128138
.ui.visible ~ #toggle:after {
129-
content: "";
139+
content: "";
130140
}
131141

132142
.ui#help {

github.png

1.67 KB
Loading

index.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ <h3>Item</h3>
117117
<a data-color="#fa3" title="Orange" href="#"></a>
118118
</span>
119119
</p>
120+
121+
<a id="github" target="_blank" href="https://github.com/ondras/my-mind" title="GitHub project page"><img src="github.png" alt="GitHub project page" /></a>
120122
</div>
121123

122-
<button id="toggle"></button>
124+
<button id="toggle" title="Toggle UI"></button>
123125

124126
<div id="io" class="ui">
125127
<h3></h3>
@@ -230,12 +232,11 @@ <h3>Help</h3>
230232
TODO:
231233
shortterm:
232234
- firebase auth
233-
- dragdrop
235+
- docka (github wiki)
234236
235237
longterm:
236238
- firebase realtime
237239
- (custom) icons
238-
- docka (github wiki)
239240
240241
bugs:
241242

js/action.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,18 @@ MM.Action.RemoveItem.prototype.undo = function() {
4646
MM.App.select(this._item);
4747
}
4848

49-
MM.Action.MoveItem = function(item, newParent, newIndex) {
49+
MM.Action.MoveItem = function(item, newParent, newIndex, newSide) {
5050
this._item = item;
5151
this._newParent = newParent;
5252
this._newIndex = (arguments.length < 3 ? null : newIndex);
53+
this._newSide = newSide || "";
5354
this._oldParent = item.getParent();
5455
this._oldIndex = this._oldParent.getChildren().indexOf(item);
56+
this._oldSide = item.getSide();
5557
}
5658
MM.Action.MoveItem.prototype = Object.create(MM.Action.prototype);
5759
MM.Action.MoveItem.prototype.perform = function() {
60+
this._item.setSide(this._newSide);
5861
if (this._newIndex === null) {
5962
this._newParent.insertChild(this._item);
6063
} else {
@@ -63,6 +66,7 @@ MM.Action.MoveItem.prototype.perform = function() {
6366
MM.App.select(this._item);
6467
}
6568
MM.Action.MoveItem.prototype.undo = function() {
69+
this._item.setSide(this._oldSide);
6670
this._oldParent.insertChild(this._item, this._oldIndex);
6771
MM.App.select(this._newParent);
6872
}

js/app.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ MM.App = {
8585

8686
case "mousedown":
8787
e.preventDefault();
88-
this._port.style.cursor = "move";
8988
this._port.addEventListener("mousemove", this);
9089
this._port.addEventListener("mouseup", this);
9190
this._drag.mouse[0] = e.clientX;
@@ -94,14 +93,8 @@ MM.App = {
9493
var item = this.map.getItemFor(e.target);
9594
if (item && !item.isRoot()) {
9695
this._drag.item = item;
97-
var content = item.getDOM().content;
98-
this._drag.ghost = content.cloneNode(true);
99-
this._drag.ghost.classList.add("ghost");
100-
this._drag.pos[0] = content.offsetLeft;
101-
this._drag.pos[1] = content.offsetTop;
102-
this._drag.ghost.style.left = this._drag.pos[0] + "px";
103-
this._drag.ghost.style.top = this._drag.pos[1] + "px";
104-
content.parentNode.appendChild(this._drag.ghost);
96+
} else {
97+
this._port.style.cursor = "move";
10598
}
10699
break;
107100

@@ -111,10 +104,22 @@ MM.App = {
111104
this._drag.mouse[0] = e.clientX;
112105
this._drag.mouse[1] = e.clientY;
113106
if (this._drag.item) {
114-
this._drag.pos[0] += dx;
115-
this._drag.pos[1] += dy;
116-
this._drag.ghost.style.left = this._drag.pos[0] + "px";
117-
this._drag.ghost.style.top = this._drag.pos[1] + "px";
107+
if (this._drag.ghost) {
108+
this._drag.pos[0] += dx;
109+
this._drag.pos[1] += dy;
110+
this._drag.ghost.style.left = this._drag.pos[0] + "px";
111+
this._drag.ghost.style.top = this._drag.pos[1] + "px";
112+
} else {
113+
var content = this._drag.item.getDOM().content;
114+
this._drag.ghost = content.cloneNode(true);
115+
this._drag.ghost.classList.add("ghost");
116+
this._drag.pos[0] = content.offsetLeft + dx;
117+
this._drag.pos[1] = content.offsetTop + dy;
118+
this._drag.ghost.style.left = this._drag.pos[0] + "px";
119+
this._drag.ghost.style.top = this._drag.pos[1] + "px";
120+
content.parentNode.appendChild(this._drag.ghost);
121+
this._port.style.cursor = "move";
122+
}
118123
} else {
119124
this.map.moveBy(dx, dy);
120125
}
@@ -125,16 +130,16 @@ MM.App = {
125130
this._port.removeEventListener("mousemove", this);
126131
this._port.removeEventListener("mouseup", this);
127132

128-
if (this._drag.item) {
133+
if (this._drag.ghost) {
129134
var rect = this._drag.ghost.getBoundingClientRect();
130135
this._drag.ghost.parentNode.removeChild(this._drag.ghost);
131136

132137
var nearest = this.map.getClosestItem(rect.left + rect.width/2, rect.top + rect.height/2);
133138
this._finishDragDrop(this._drag.item, nearest);
134-
135-
this._drag.item = null;
136-
this._drag.ghost = null;
137139
}
140+
141+
this._drag.item = null;
142+
this._drag.ghost = null;
138143
break;
139144
} /* switch */
140145
},
@@ -177,7 +182,7 @@ MM.App = {
177182
tmp = tmp.getParent();
178183
}
179184

180-
var w1 = item.getDOM().content.offsetWidth;
185+
var w1 = item.getDOM().content.offsetWidth;
181186
var w2 = target.getDOM().content.offsetWidth;
182187
var w = Math.max(w1, w2);
183188
var h1 = item.getDOM().content.offsetHeight;
@@ -188,15 +193,12 @@ MM.App = {
188193
} else if (Math.abs(nearest.dx) < w && Math.abs(nearest.dy) < h) { /* append here */
189194
var action = new MM.Action.MoveItem(item, target);
190195
} else {
191-
// debugger;
192196
var dir = target.getParent().getLayout().getChildDirection(target);
193197
var diff = -1 * (dir == "top" || dir == "bottom" ? nearest.dx : nearest.dy);
194198

195199
var index = target.getParent().getChildren().indexOf(target);
196200
var targetIndex = index + (diff > 0 ? 1 : 0);
197-
var action = new MM.Action.MoveItem(item, target.getParent(), targetIndex);
198-
/* FIXME side + side in action */
199-
201+
var action = new MM.Action.MoveItem(item, target.getParent(), targetIndex, target.getSide());
200202
}
201203
this.action(action);
202204

0 commit comments

Comments
 (0)