-
Notifications
You must be signed in to change notification settings - Fork 0
/
drydock.js
3047 lines (2525 loc) · 68.6 KB
/
drydock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var DryDock = (function (window, $, Node, Math, JSON) {
var NAME_PREFIX = 'dd-';
function isFunction(object) {
return typeof object == 'function';
}
function blur() {
var element = $.activeElement;
switch (element) {
case null:
case $.documentElement:
case $.body: return;
}
element.blur();
}
function createDiv(className) {
var div = $.createElement('div');
div.className = className;
return div;
}
function toTouch(listener) {
return function (event) {
return listener.call(this, event.touches[0]);
};
}
var inherit = (function (_) {
return function (constructor, base) {
_.prototype = base;
return new _(constructor);
};
})(function (constructor) {
this.constructor = constructor;
constructor.prototype = this;
});
var Vector = (function () {
function Vector(x, y) {
this.x = x;
this.y = y;
}
var prototype = Vector.prototype;
Vector.ZERO = new Vector(0, 0);
Vector.from = function (event) {
return new Vector(
event.clientX,
event.clientY);
};
prototype.plus = function (vector) {
return new Vector(
this.x + vector.x,
this.y + vector.y);
};
prototype.minus = function (vector) {
return new Vector(
this.x - vector.x,
this.y - vector.y);
};
prototype.of = function (rect) {
return new Vector(
this.x - rect.left,
this.y - rect.top);
};
prototype.min = function (vector) {
return new Vector(
Math.min(this.x, vector.x),
Math.min(this.y, vector.y));
};
prototype.max = function (vector) {
return new Vector(
Math.max(this.x, vector.x),
Math.max(this.y, vector.y));
};
prototype.round = function () {
return new Vector(
Math.round(this.x),
Math.round(this.y));
};
prototype.square = function () {
return this.x * this.x +
this.y * this.y;
};
prototype.equals = function (vector) {
return this.x == vector.x
&& this.y == vector.y;
};
return Vector;
})();
var Size = (function () {
function Size(width, height) {
this.width = width;
this.height = height;
}
var prototype = Size.prototype;
Size.from = function (element) {
return new Size(
element.clientWidth,
element.clientHeight);
};
prototype.max = function (size) {
return new Size(
Math.max(this.width, size.width),
Math.max(this.height, size.height));
};
prototype.shrink = function (value) {
return new Size(
this.width - value,
this.height - value);
};
return Size;
})();
var Rect = (function () {
function Rect(top, left, width, height) {
this.top = top;
this.left = left;
this.width = width;
this.height = height;
}
var prototype = Rect.prototype;
Rect.from = function (rect) {
return new Rect(
rect.top,
rect.left,
rect.width,
rect.height);
};
prototype.plus = function (vector) {
return new Rect(
this.top + vector.y,
this.left + vector.x,
this.width, this.height);
};
prototype.of = function (rect) {
return new Rect(
this.top - rect.top,
this.left - rect.left,
this.width, this.height);
};
prototype.max = function (value) {
return new Rect(
this.top, this.left,
Math.max(this.width, value),
Math.max(this.height, value));
};
prototype.round = function () {
return new Rect(
Math.round(this.top),
Math.round(this.left),
Math.round(this.width),
Math.round(this.height));
};
prototype.right = function () {
return this.left + this.width;
};
prototype.bottom = function () {
return this.top + this.height;
};
prototype.contains = function (vector) {
return this.left <= vector.x && vector.x < this.right()
&& this.top <= vector.y && vector.y < this.bottom();
};
prototype.equals = function (rect) {
return this.top == rect.top
&& this.left == rect.left
&& this.width == rect.width
&& this.height == rect.height;
};
return Rect;
})();
var EdgeDef = (function () {
function EdgeDef(className) {
this.className = NAME_PREFIX + className;
}
var VS = [
EdgeDef.TOP = new EdgeDef('top'),
EdgeDef.MIDDLE = new EdgeDef('middle'),
EdgeDef.BOTTOM = new EdgeDef('bottom')
];
var HS = [
EdgeDef.LEFT = new EdgeDef('left'),
EdgeDef.CENTER = new EdgeDef('center'),
EdgeDef.RIGHT = new EdgeDef('right')
];
var NS = 'ns-resize', NESW = 'nesw-resize';
var EW = 'ew-resize', NWSE = 'nwse-resize';
var CURSORS = [
[NWSE, NS , NESW],
[ EW , null, EW ],
[NESW, NS , NWSE]
];
EdgeDef.forEach = function (object) {
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
object.forEdgeDef(VS[i], HS[j], CURSORS[i][j]);
}}
};
return EdgeDef;
})();
var ButtonDef = (function () {
function ButtonDef(letter, horizontal, order) {
this.letter = letter;
this.horizontal = horizontal;
this.order = order;
}
var prototype = ButtonDef.prototype;
ButtonDef.TOP = new ButtonDef('↑', false, false);
ButtonDef.RIGHT = new ButtonDef('→', true, true);
ButtonDef.BOTTOM = new ButtonDef('↓', false, true);
ButtonDef.LEFT = new ButtonDef('←', true, false);
ButtonDef.CENTER = new ButtonDef('+', false, false);
ButtonDef.MAIN_DIV = 3;
ButtonDef.OUTER_DIV = 5;
function Diff(i, diff) {
this.i = i;
this.diff = diff;
}
function Insert(size, tSize, t, n) {
this.size = size;
this.tSize = tSize;
this.t = t;
this.n = n;
}
prototype.sizeOf = function (rect) {
var size = this.horizontal ? rect.width : rect.height;
return size - Splitter.SIZE;
};
prototype.calcInsert = function (target) {
var parent = target.parent;
var ti = target.index;
var ni = this.order ? ti + 1 : ti - 1;
var tSize = target.size;
var nSize = parent.children[ni].size;
var sSize = tSize + nSize;
var tcSize = parent.sizes[ti];
var ncSize = parent.sizes[ni];
var scSize = tcSize + ncSize;
var icSize = (scSize - Splitter.SIZE) / 3;
var acSize = icSize + Splitter.SIZE;
return new Insert(icSize, tcSize,
new Diff(ti, acSize * tSize / sSize),
new Diff(ni, acSize * nSize / sSize));
};
return ButtonDef;
})();
var ButtonPos = (function () {
function ButtonPos(rect) {
this.c = ButtonPos.center(rect);
this.f = new Vector(
GuideButton.MARGIN, GuideButton.MARGIN);
this.l = new Vector(
rect.width - GuideButton.DIFF,
rect.height - GuideButton.DIFF);
}
ButtonPos.center = function (rect) {
return new Vector(
(rect.width - GuideButton.SIZE) / 2,
(rect.height - GuideButton.SIZE) / 2);
};
return ButtonPos;
})();
var Pointer = (function () {
function Pointer(container, event, draggable) {
this.container = container;
this.point = Vector.from(event);
this.diff = Vector.ZERO;
this.first = true;
this.hardDrag = draggable.hardDrag;
this.setDragging(draggable);
}
var prototype = Pointer.prototype;
var THRESHOLD = 6 * 6; // const
prototype.setDragging = function (draggable) {
draggable.container = this.container;
this.dragging = draggable;
};
prototype.deleteContainer = function () {
delete this.dragging.container;
};
prototype.mousemove = function (event) {
var point = Vector.from(event);
var diff = point.minus(this.point);
if (this.hardDrag) {
if (diff.square() < THRESHOLD) return;
this.hardDrag = false;
}
this.point = point;
if (this.first) {
this.dragging.ondragstart();
this.first = false;
}
var sum = this.diff.plus(diff), arg = sum.round();
var ret = this.dragging.ondrag(arg);
this.diff = sum.minus(ret || arg);
};
prototype.mouseup = function () {
this.dragging.ondrop();
this.deleteContainer();
};
return Pointer;
})();
var Option = (function () {
function Option(value) {
this.value = value;
}
Option.get = function (options, key) {
if (options != null && key in options) {
return new Option(options[key]);
}
return null;
};
return Option;
})();
var Model = (function () {
function Model() {
this.classList = [this.className];
this.element = $.createElement(this.tagName);
this.element.className = this.className;
this.body = this.element;
}
var prototype = Model.prototype;
function indexOf(classList, className) {
var length = classList.length;
for (var i = 1; i < length; i++) {
if (classList[i] == className) return i;
}
return 0;
}
prototype.tagName = 'div';
prototype.className = NAME_PREFIX;
prototype.setSize = function (width, height) {
var style = this.element.style;
style.width = width + 'px';
style.height = height + 'px';
};
prototype.unsetSize = function () {
var style = this.element.style;
style.width = style.height = '';
};
prototype.setPos = function (top, left) {
var style = this.element.style;
style.top = top + 'px';
style.left = left + 'px';
};
prototype.setRect = function (rect) {
this.setPos (rect.top, rect.left);
this.setSize(rect.width, rect.height);
};
prototype.setWidth = function (width) {
this.element.style.width = width + 'px';
};
prototype.setLeft = function (left) {
this.element.style.left = left + 'px';
};
prototype.unsetLeft = function () {
this.element.style.left = '';
};
prototype.applyClass = function () {
this.element.className = this.classList.join(' ');
};
prototype.addClass = function (className) {
if (indexOf(this.classList, className)) return;
this.classList.push(className);
this.applyClass();
};
prototype.removeClass = function (className) {
var index = indexOf(this.classList, className);
if (index) {
this.classList.splice(index, 1);
this.applyClass();
}
};
return Model;
})();
var Control = (function (Base) {
function Control() {
Base.call(this);
}
var base = Base.prototype;
var prototype = inherit(Control, base);
var ACTIVE_NAME = NAME_PREFIX + 'active';
prototype.bodyRect = false;
prototype.parent = null;
prototype.onActivate = function () { };
prototype.activate = function () {
this.onActivate();
this.parent.activate();
};
prototype.getRect = function () {
var element = this.bodyRect ? this.body : this.element;
return Rect.from(element.getBoundingClientRect());
};
prototype.addActiveClass = function () {
this.addClass(ACTIVE_NAME);
};
prototype.removeActiveClass = function () {
this.removeClass(ACTIVE_NAME);
};
prototype.getContainer = function () {
return this.parent ? this.parent.getContainer() : null;
};
return Control;
})(Model);
var Draggable = (function (Base) {
function Draggable(parent) {
Base.call(this);
var self = this;
this.parent = parent;
function mousedown(event) {
var target = event.target;
if (target == this || target == self.body) {
if (event.button) self.activate();
else {
self.getContainer().mousedown(event, self);
self.onmousedown();
}
return false;
}
}
this.element.onmousedown = mousedown;
this.element.ontouchstart = toTouch(mousedown);
}
var base = Base.prototype;
var prototype = inherit(Draggable, base);
var GRABBING_NAME = NAME_PREFIX + 'grabbing';
prototype.hardDrag = false;
prototype.cursor = '';
prototype.setCursor = function (cursor) {
this.cursor = cursor;
this.element.style.cursor = cursor;
};
prototype.addGrabbingClass = function () {
this.addClass(GRABBING_NAME);
};
prototype.removeGrabbingClass = function () {
this.removeClass(GRABBING_NAME);
};
prototype.onmousedown = function () {
this.activate();
};
prototype.ondragstart = function () { };
// prototype.ondrag = function (delta) { };
prototype.ondrop = function () { };
return Draggable;
})(Control);
var Splitter = (function (Base) {
function Splitter(pane, index) {
Base.call(this, pane);
this.index = index;
this.setCursor(pane.horizontal ? 'ew-resize' : 'ns-resize');
}
var base = Base.prototype;
var prototype = inherit(Splitter, base);
Splitter.SIZE = 6; // px const
prototype.className += 'splitter';
prototype.onmousedown = function () {
base.onmousedown.call(this);
this.addGrabbingClass();
};
prototype.ondragstart = function () {
this.parent.onSplitterDragStart(this);
};
prototype.ondrag = function (delta) {
var d = this.parent.onSplitterDrag(this.index,
this.parent.horizontal ? delta.x : delta.y);
if (d) this.container.layout();
return this.parent.horizontal ?
new Vector(d, delta.y) :
new Vector(delta.x, d);
};
prototype.ondrop = function () {
this.parent.onSplitterDrop();
this.removeGrabbingClass();
};
return Splitter;
})(Draggable);
var TabStrip = (function (Base) {
function TabStrip(contents) {
Base.call(this, contents);
this.tabs = [];
}
var base = Base.prototype;
var prototype = inherit(TabStrip, base);
TabStrip.HEIGHT = 26; // px const
TabStrip.MAIN = TabStrip.HEIGHT + 2; // px const
prototype.className += 'tabstrip';
prototype.hardDrag = true;
prototype.appendTab = function (tab) {
tab.tabstrip = this;
this.tabs.push(tab);
this.body.appendChild(tab.element);
};
prototype.insertTab = function (tab, refTab) {
tab.tabstrip = this;
this.tabs.splice(refTab.index(), 0, tab);
this.body.insertBefore(tab.element, refTab.element);
};
prototype.removeTab = function (tab) {
delete tab.tabstrip;
this.tabs.splice(tab.index(), 1);
this.body.removeChild(tab.element);
};
prototype.onTabDrag = function (tab, x) {
var index = tab.index(), l = this.tabs.length;
var toIndex = index + Math.round(x / this.tabSize);
if (toIndex < 0) toIndex = 0;
if (toIndex >= l) toIndex = l - 1;
if (toIndex == index) return x;
var to = this.tabs[toIndex].element;
this.tabs.splice(index, 1);
this.tabs.splice(toIndex, 0, tab);
this.body.insertBefore(tab.element,
toIndex < index ? to : to.nextSibling);
this.parent.moveChild(index, toIndex);
this.parent.setTabSize();
return x - this.tabSize * (toIndex - index);
};
prototype.ondragstart = function () {
this.parent.onStripDragStart();
};
prototype.ondrag = function (delta) {
return this.parent.onStripDrag(delta);
};
prototype.ondrop = function () {
this.parent.onStripDrop();
};
prototype.onresize = function (size, tabSize, margin) {
var length = this.tabs.length;
var rem = margin < size ? size - margin : 0;
this.tabSize = tabSize * length > rem ?
rem / length : tabSize;
var sum = 0, prev = 0;
for (var i = 0; i < length; i++) {
sum += this.tabSize;
var pos = Math.round(sum);
this.tabs[i].setWidth(pos - prev);
prev = pos;
}
};
return TabStrip;
})(Draggable);
var Tab = (function (Base) {
var TITLE_NAME = NAME_PREFIX + 'title';
var FIXED_NAME = NAME_PREFIX + 'fixed';
function Tab(content) {
Base.call(this, content);
var title = content.getTitle();
this.textNode = $.createTextNode(title);
this.body = $.createElement('span');
this.body.className = TITLE_NAME;
this.body.appendChild(this.textNode);
var close = new Close(this, content);
this.element.title = title;
this.element.appendChild(this.body);
this.element.appendChild(close.element);
}
var base = Base.prototype;
var prototype = inherit(Tab, base);
function Drag(tab) {
var tabstrip = tab.tabstrip;
this.contents = tabstrip.parent;
this.detachable = this.contents instanceof Sub;
if (this.detachable) {
this.diff = Vector.ZERO;
this.i = tab.index();
this.size = tabstrip.tabSize;
this.min = -this.size;
this.max = this.contents.width -
this.size * (tabstrip.tabs.length - 1);
}
this.x = 0;
}
prototype.className += 'tab';
prototype.hardDrag = true;
prototype.tabstrip = null;
prototype.index = function () {
return this.parent.index;
};
prototype.setTitle = function (title) {
this.element.title = title;
this.textNode.data = title;
};
prototype.setFixed = function (fixed) {
if (fixed) {
this.addClass(FIXED_NAME);
} else {
this.removeClass(FIXED_NAME);
}
};
prototype.detach = function (drag) {
var container = this.container;
this.removeGrabbingClass();
this.setWidth(drag.size);
this.setLeft(drag.size * drag.i);
var contents = drag.contents;
var rect = contents.getRectOf(container).round();
var sub = contents.detachChild(this.parent, drag.i);
sub.detached = this;
var pointer = container.pointer;
pointer.deleteContainer();
pointer.setDragging(sub.tabstrip);
sub.onStripDragStart();
return sub.openFloat(container, rect, drag.diff);
};
prototype.ondragstart = function () {
this.drag = new Drag(this);
this.addGrabbingClass();
};
prototype.ondrag = function (delta) {
var drag = this.drag;
drag.x = this.tabstrip.onTabDrag(this, drag.x + delta.x);
if (drag.detachable) {
var diff = drag.diff;
drag.diff = diff.plus(delta);
if (drag.x < drag.min || drag.max <= drag.x ||
Math.abs(drag.diff.y) >= TabStrip.HEIGHT) {
return this.detach(drag).minus(diff);
}
}
this.setLeft(drag.x);
};
prototype.ondrop = function () {
this.removeGrabbingClass();
this.unsetLeft();
delete this.drag;
};
return Tab;
})(Draggable);
var Close = (function (Base) {
function Close(tab, content) {
Base.call(this, tab);
this.content = content;
this.element.title = '';
this.body.appendChild($.createTextNode('×'));
}
var base = Base.prototype;
var prototype = inherit(Close, base);
var CANCEL_NAME = NAME_PREFIX + 'cancel';
function Drag(rect) {
this.rect = rect;
this.hovering = true;
}
prototype.tagName = 'a';
prototype.className += 'close';
prototype.onmousedown = function () {
this.drag = new Drag(this.getRect());
this.addActiveClass();
blur();
};
prototype.ondrag = function () {
var drag = this.drag;
var point = this.container.pointer.point;
var hovering = drag.rect.contains(point);
if (hovering != drag.hovering) {
drag.hovering = hovering;
if (hovering) {
this.addActiveClass();
this.removeClass(CANCEL_NAME);
} else {
this.removeActiveClass();
this.addClass(CANCEL_NAME);
}
}
};
prototype.ondrop = function () {
if (this.drag.hovering) {
this.content.close();
this.removeActiveClass();
} else {
this.removeClass(CANCEL_NAME);
}
delete this.drag;
};
return Close;
})(Draggable);
var Edge = (function (Base) {
function Edge(frame, v, h, cursor) {
Base.call(this, frame);
this.v = v;
this.h = h;
this.addClass(v.className);
this.addClass(h.className);
this.setCursor(cursor);
}
var base = Base.prototype;
var prototype = inherit(Edge, base);
Edge.SIZE = 2; // px const
prototype.className += 'edge';
prototype.ondrag = function (delta) {
var dx = delta.x, dy = delta.y;
var rect = this.parent.rect;
var mw = rect.width - TabStrip.HEIGHT;
var mh = rect.height - TabStrip.HEIGHT;
switch (this.v) {
case EdgeDef.TOP:
var t = Edge.SIZE - rect.top;
if (dy > mh) dy = mh;
if (dy < t) dy = t;
rect.top += dy;
rect.height -= dy;
break;
case EdgeDef.BOTTOM:
if (dy < -mh) dy = -mh;
rect.height += dy;
break;
}
switch (this.h) {
case EdgeDef.LEFT:
if (dx > mw) dx = mw;
rect.left += dx;
rect.width -= dx;
break;
case EdgeDef.RIGHT:
var r = Frame.MIN_R - rect.right();
if (dx < -mw) dx = -mw;
if (dx < r) dx = r;
rect.width += dx;
break;
}
this.parent.layout();
return new Vector(dx, dy);
};
return Edge;
})(Draggable);
var GuideControl = (function (Base) {
function GuideControl(container) {
Base.call(this);
this.container = container;
}
var base = Base.prototype;
var prototype = inherit(GuideControl, base);
prototype.hide = function () {
this.element.style.display = 'none';
};
prototype.show = function () {
this.element.style.display = '';
};
prototype.setDisable = function (disable) {
this.disable = disable;
if (disable) this.hide(); else this.show();
};
return GuideControl;
})(Model);
var GuideBase = (function (Base) {
function GuideBase(container) {
Base.call(this, container);
this.area = new GuideArea(container);
this.top = new GuideButton(container, ButtonDef.TOP);
this.right = new GuideButton(container, ButtonDef.RIGHT);
this.bottom = new GuideButton(container, ButtonDef.BOTTOM);
this.left = new GuideButton(container, ButtonDef.LEFT);
this.hide();
this.body.appendChild(this.area.element);
this.body.appendChild(this.top .element);
this.body.appendChild(this.right .element);
this.body.appendChild(this.bottom.element);
this.body.appendChild(this.left .element);
}
var base = Base.prototype;
var prototype = inherit(GuideBase, base);
prototype.droppable = null;
prototype.getButton = function (vector) {
if (this.top .hitTest(vector)) return this.top;
if (this.right .hitTest(vector)) return this.right;
if (this.bottom.hitTest(vector)) return this.bottom;
if (this.left .hitTest(vector)) return this.left;
return null;
};
prototype.setDroppable = function (droppable) {
if (droppable == this.droppable) return;
if (this.droppable) {
this.droppable.onleave();
}
this.droppable = droppable;
if (droppable) {
droppable.onenter();
this.enter(droppable);
this.area.show();
} else {
this.area.hide();
}
};
prototype.onleave = function () {
this.setDroppable(null);
this.hide();
};
prototype.drop = function (contents, target) {
if (this.droppable) {
this.droppable.ondrop(contents, target);
}
this.onleave();
};
prototype.ondrop = function () {
delete this.droppable;
delete this.drag;
};
return GuideBase;
})(GuideControl);
var Guide = (function (Base) {
function Guide(container) {
Base.call(this, container);
this.child = new GuidePane(container);
this.body.appendChild(this.child.element);
}
var base = Base.prototype;
var prototype = inherit(Guide, base);
function Drag(contents) {
this.contents = contents;
this.target = null;
this.first = true;
}
prototype.className += 'guide';
prototype.drag = null;
prototype.ondragstart = function (contents) {
this.drag = new Drag(contents);