-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomp.js
More file actions
1242 lines (1007 loc) · 30.1 KB
/
Copy pathcomp.js
File metadata and controls
1242 lines (1007 loc) · 30.1 KB
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
/**
* By www.865171.cn
* q q : 215288671
* Date : 2010.4.22
*/
/**
* 控件基类.
* 控件即是本包中已实现的控件对象.
*/
var CBase = {
//类型,保留作为Component标识.
type: 'CBase',
//代表该控件的DOM结点.
view: null,
draggable: false,
resizable: false,
id: 0,
title: '',
tleLen: 15,
//初始化.
initialize: function(opts) {
if ((typeof this.id) == 'undefined') {
this.id = CC.uniqueID();
}
//所有赋值给view的属性通过用viewAttr传递.
var viewAttr = null;
if (opts && opts.viewAttr) {
viewAttr = opts.viewAttr;
delete opts.viewAttr;
}
CC.extend(this, opts);
if (!this.view) {
this.view = CC. $C('DIV');
}
if (this.parent) {
this.parent.appendChild(this.view);
}
if (viewAttr) {
CC.extend(this.view, viewAttr);
}
//view附加一个控件本身的引用.
this.view.component = this;
}
,
//设置view的宽度.
setWidth: function(width) {
CC.style(this.view, 'width', width + 'px');
}
,
//设置view的高度.
setHeight: function(height) {
CC.style(this.view, 'width', height + 'px');
}
,
//设置view 的top.
setTop: function(top) {
CC.style(this.view, 'top', top + 'px');
}
,
setLeft: function(left) {
CC.style(this.view, 'left', left + 'px');
}
,
//是否禁用该控件的view,参数:true或false.
setDisabled: function(b) {
CC.disabled(this.view, b);
}
,
//设置view的className.
setClass: function(c) {
CC.setClass(this.view, c);
}
,
//设置控件view的属性.
//如设置高为setViewAttr('top',50);
setViewAttr: function(n, v) {
this.view[n] = v;
}
,
//设置view中任一子层id为childId的子结子的属性.
//属性也可以多层次.
//如存在一id为'_ico'子结点,设置其display属性为
//inspectAttr('_ico','style.display','block');
inspectViewAttr: function(childId, childAttrList, attrValue) {
var obj = CC.inspect(this.view, childId);
//??Shoud do this??
if (obj == null) {
return ;
}
CC.inspectAttr(obj, childAttrList, attrValue);
return obj;
}
,
//设置控件的图标,如果存在的话.
//图标结点id必须是'_ico'且在view中是唯一的.
setIcon: function(cssIco) {
this.inspectViewAttr('_ico', 'className', cssIco);
}
,
setVisible: function(b) {
CC.display(this.view, b);
}
,
//设置控件的标题,如果存在的话.
//标题结点id必须是'_tle'且在view中是唯一的.
setTitle: function(ss) {
this.title = ss;
var tle = CC.inspect(this.view, '_tle');
CC.style(tle.parentNode, 'title', tle);
tle.innerHTML = ss.truncate(this.tleLen);
}
,
//设置控件view的宽度高度.
setSize: function(width, height) {
CC.style(this.view, 'width', width + 'px');
CC.style(this.view, 'height', height + 'px');
}
,
setPosition: function(left, top) {
CC.style(this.view, 'left', left + 'px');
CC.style(this.view, 'top', top + 'px');
}
,
//控件view是否可见.
isVisible: function() {
return this.view.style.display != "none";
}
,
//为view添加DOM事件.
//useCapture:否是支持冒泡.
observe: function(name, observer, useCapture) {
Event.observe(this.view, name, observer, useCapture);
}
,
stopObserving: function(name, observer, useCapture) {
Event.stopObserving(this.view, observer, useCapture);
}
,
//设置控件是否可拖动.
//moveObj:发生拖动时要移动的结点.
setDragable: function(b, moveObj, fnOnMov, fnOnDrag, fnOnDrog) {
this.draggable = b;
(moveObj) ? Position.setDragable(this.view, moveObj, b, fnOnMov, fnOnDrag, fnOnDrog): Position.setDragable(this.view, this.view, b, fnOnMov, fnOnDrag, fnOnDrog);
}
,
//之前版本appendView已改为appendChild
//为view添加一个子DOM结点.
appendChild: function(v) {
this.view.appendChild(v);
}
,
removeChild: function(v) {
this.view.removeChild(v);
}
};
/**
* 容器类控件.
* 派生于该容器都具有appendChild,add,get,removeChild,remove,$,show,indexOf,contains方法.
*/
var CContainerBase = {};
//派生于基类.
CC.extendx(CContainerBase, CBase);
CC.extend(CContainerBase, {
children: null,
container: null,
initialize: function(opt) {
//调用父类初始化.
this._super(opt); if (!this.container) {
this.container = this.view;
}
this.children = [];
}
,
//向容器中添加一个结点.
appendChild: function(child) {
this.container.appendChild(child);
}
,
//向容器中添加一个控件,注意是控件而不是DOM结点.
//控件即是本包中已实现的控件,具有基本的view属性.
add: function(a) {
if (!this.contains(a)) {
this.children.push(a); this.container.appendChild(a.view);
}
a.parentContainer = this; return a;
}
,
//获得容器中的一个控件.
//参数a可为控件id,或控件自身.
get: function(a) {
a = this. $(a); if (this.children.indexOf(a) >= 0) {
return a;
}
return null;
}
,
removeChild: function(child) {
this.container.removeChild(child);
}
,
//参数a可为控件实例或控件ID.
remove: function(a) {
if (!a || !this.contains(a)) {
return ;
}
a.parentContainer = null;
this.children.remove(a); this.container.removeChild(a.view); return a;
}
,
//根据控件ID或控件自身安全返回容器中该控件对象.
$: function(id) {
if (id.type) {
return id;
}
var chs = this.children;
if (CC.isNumber(id)) {
return this.children[id];
}
for (var i = 0, len = chs.length; i < len; i++) {
if (chs[i].id == id) {
return chs[i];
}
}
return null;
}
,
//设置容器中指定控件的显示属性.
//b为true或false.
//参数a可为控件实例或控件ID.
show: function(a, b) {
a = this. $(a); a.setVisible(b); return a;
}
,
//返回窗口中控件的索引.
//参数a可为控件实例或控件ID.
indexOf: function(a) {
if (!a.type) {
a = this. $(a);
}
return this.children.indexOf(a);
}
,
size: function() {
return this.children.length
}
,
//容器是否包含给出控件.
//参数a可为控件实例或控件ID.
contains: function(a) {
if (!a.type) {
a = this. $(a);
}
return this.children.indexOf(a) != - 1;
}
});
//--基本Item控件
var CItem = CC.create();
//CItem.prototype派生于CBase类.
CC.extendx(CItem.prototype, CBase);
CC.extend(CItem.prototype, {
type: 'CItem',
initialize: function(opt) {
//传给父类初始化.
this._super(CC.extendIf(opt, {
view: opt.view || CC. $C( {
tagName: 'LI', innerHTML: CTemplate[this.type]
}
)
}
)); this.setTitle(this.title); this.setViewAttr('className', ''); this.setIcon(opt.icon || ''); Event.bindPassByStyle(this.view, 'on navOn', false);
}
}
);
//--Tab Item 控件
var CTabItem = CC.create();
CC.extendx(CTabItem.prototype, CBase);
CC.extend(CTabItem.prototype, {
type: 'CTabItem',
url: null,
load: false,
//每个TabItem包含一个面板作为其显示的主体.
panel: null,
onclose: null,
//该TabItem是否可关闭,不能直接设置该值,应调用setCloseable().
closeable: false,
initialize: function(opt) {
this._super(CC.extendIf(opt, {
view: CC. $C('TABLE')
}
)); var dv = CC. $C('DIV'); dv.innerHTML = CTemplate[this.type]; var tb = dv.firstChild; this.view.appendChild(tb.removeChild(tb.firstChild)); this.setTitle(this.title); this.setCloseable(this.closeable); if (this.url) {
if (!this.load) {
this.request();
}
}
}
,
//设置关闭后的回调.
//fnc参数为一个回调函数.
setOnclose: function(fnc) {
var fon = function(ev) {
Event.stop(window.event); fnc();
}; this.inspectViewAttr('_cls', 'onclick', fon);
}
,
//该TabItem是否可关闭.
setCloseable: function(b) {
this.closeable = b; var obj = CC.inspect(this.view, '_cls'); CC.display(obj, b);
}
,
//设置TabItem显示的面板,为一个DOM结点.
setPanel: function(p) {
this.panel = p;
}
,
request: function() {
if (this.url && this.panel) {
var ajax = new Ajax( {
url: this.url, displayPanel: this.panel, onSuccess: this.onContentLoaded, caller: this
}
); ajax.open(); ajax.send(null);
}
}
,
onContentLoaded: function(ajax) {
ajax.invokeHtml(); this.load = true;
}
});
//--Tab 控件,一个Tab控件由多个TabItem构成.
//监听select事件可用onselect(CTab)=...
var CTab = CC.create();
//派生于容器类.
CC.extendx(CTab.prototype, CContainerBase);
CC.extend(CTab.prototype, {
type: 'CTab',
//默认TabItem长度.
defItemLen: 130,
//该面板存放当前显示的TabItem中的面板,TabItem中的面板将放入该面板内,即Tab显示主体.
ctxPanel: null,
selected: null,
initialize: function(opt) {
this._super(opt); if (!this.ctxPanel) {
this.ctxPanel = CC. $C('DIV');
}
//重写容器类的add方法.
this.override('add', function(it) {
//selected event.
it.view.onclick = this.select.bind(this, it);
//close event.
it.view.ondblclick = this.show.bind(this, it, false); it.setOnclose(this.show.bind(this, it, false)); this._ajust(); it.parent = this;
}
);
}
,
//设置Tab控件显示主板面板.
setCtxPanel: function(v) {
this.ctxPanel = v;
}
,
_ajust: function() {
var sty = this.view.style; var w = this.view.clientWidth; var ch = this.children; var tcnt = this.children.length; var vcnt = 0; for (var i = 0; i < tcnt; i++) {
if (ch[i].isVisible()) {
vcnt++
}
}
var perw = Math.floor(w / vcnt);
if (perw > this.defItemLen) {
perw = this.defItemLen;
}
for (var i = 0; i < tcnt; i++) {
ch[i].setWidth(perw);
}
}
,
//是否显示指定的TabItem,
//参数a可为TabItem实例也可为TabItem的id,b为true或false.
show: function(a, b) {
//only one,can't set it.
if (!b && this.getDisc() == 1) {
return ;
}
a = this. $(a);
//Cann't change this attribute.
if (!a.closeable && !b) {
return false;
}
var isv = a.isVisible();
if (isv != b) {
this._ajust();
}
a.setVisible(b);
if (!b && this.selected == a) {
var idx = this.indexOf(a); var tmp = idx - 1; var chs = this.children;
while (tmp >= 0 && !chs[tmp].isVisible()) {
tmp--;
}
if (tmp >= 0) {
this.select(chs[tmp]); return ;
}
tmp = chs.length; idx += 1;
while (idx < tmp && !chs[idx].isVisible()) {
idx++;
}
if (idx < tmp) {
this.select(chs[idx]);
}
}
}
,
//选择某个TabItem,
//参数a可为TabItem实例也可为id.
select: function(a) {
if (a == '' || a == null) {
var sel = this.selected; if (sel) {
sel.setViewAttr('className', ''); this.ctxPanel.removeChild(sel.panel);
}
this.selected = ''; return ;
}
if (a == this.selected) {
return ;
}
a = this.get(a); if (a == null) {
return ;
}
this.show(a, true);
var sel = this.selected; if (sel) {
sel.setViewAttr('className', ''); this.ctxPanel.removeChild(sel.panel);
}
this.selected = a; a.setViewAttr('className', 'on'); this.ctxPanel.appendChild(a.panel); if (this.onselect) {
this.onselect(a);
}
}
,
//返回显示的TabItem个数.
getDisc: function() {
var cnt = 0; var chs = this.children; for (var i = 0, len = chs.length; i < len; i++) {
if (chs[i].isVisible()) {
cnt++;
}
}
return cnt;
}
});
//--CItemList,列表项控件.
var CItemList = CC.create();
//该控件为一个容器.
CC.extendx(CItemList.prototype, CContainerBase);
CC.extend(CItemList.prototype, {
//invoke as onclick(itemObj)
onselect: null,
selected: null,
initialize: function(opt) {
this._super(CC.extendIf(opt, {
view: CC. $C('UL')
}
)); this.setViewAttr('className', 'gFdBdy');
//@override
this.override('add', function(it) {
it.view.onclick = this.select.bind(this, it); it.parent = this;
}
);
}
,
//选择某个控件,
//参数a可为控件实例也可为id.
select: function(a) {
if (a == '' || a == null) {
var sel = this.selected; if (sel) {
sel.setViewAttr('className', '');
}
this.selected = ''; return ;
}
a = this. $(a); if (a == null) {
return ;
}
if (a == this.selected) {
return ;
}
this.show(a, true);
var sel = this.selected; if (sel) {
sel.setViewAttr('className', '');
}
this.selected = a; a.setViewAttr('className', 'on'); if (this.onselect) {
this.onselect(a);
}
}
});
//--CFolder 组控件
//CFolder控件其实由一个头部和一个CItemList控件组成.
var CFolder = CC.create();
CC.extendx(CFolder.prototype, CBase);
CC.extend(CFolder.prototype, {
type: 'CFolder',
//存放一个CItemList.
itemList: null,
isFold: false,
initialize: function(opt) {
this._super(opt); this.view.innerHTML = CTemplate[this.type]; this.itemList = new CItemList(); this.view.appendChild(this.itemList.view); this.setViewAttr('className', 'gFd'); this.inspectViewAttr('_btnFN', 'onclick', this._btnFNOnclick.bind(this)); this.setTitle(this.title);
}
,
_btnFNOnclick: function() {
var v = this.itemList.isVisible(); this.fold(v);
}
,
//添加一个CItem项.
add: function(oItem) {
this.itemList.add(oItem);
}
,
//折叠或展开.
//b:true or false.
fold: function(b) {
this.inspectViewAttr('_btnFN', 'className', b ? 'opnFd' : 'clsFd'); this.itemList.setVisible(!b);
}
}
);
//--CBarItem : Toolbar Item,工具栏项.
var CBarItem = CC.create();
CC.extendx(CBarItem.prototype, CBase);
CC.extend(CBarItem.prototype, {
type: 'CBarItem', initialize: function(opt) {
this._super(opt); this.view.innerHTML = CTemplate[this.type]; this.setViewAttr('className', 'tlBtn2'); this.setTitle(this.title); this.setIcon(this.icon); Event.bindPassByStyle(this.view, 'on', false);
}
}
);
//工具栏控件.
var CToolbar = CC.create();
CC.extendx(CToolbar.prototype, CContainerBase);
CC.extend(CToolbar.prototype, {
onselect: null,
initialize: function(opt) {
this._super(opt); this.setViewAttr('className', 'gTlBar');
//@override
this.override('add', function(it) {
if (this.onselect) {
it.view.onclick = this.onselect.bind(this, it);
}
Event.bindClickStyle(it.view, 'click', false);
}
);
}
});
/**
* window控件.
*/
var CWin = CC.create();
CC.extendx(CWin.prototype, CContainerBase);
CC.extend(CWin.prototype, {
type: 'CWin',
body: null,
bottom: null,
initialize: function(opt) {
this._super(opt); this.view.innerHTML = CTemplate[this.type]; this.setViewAttr('className', 'sysWin'); this.container = this.body = CC.inspect(this.view, '_bdy'); this.bottom = CC.inspect(this.view, '_bot'); this.setTitle(this.title || 'window ' + this.id); this.setIcon(this.icon || 'icoSw'); this.setDragable(true); this.setLeft(this.left || 283); this.setTop(this.top || 185); this.inspectViewAttr('_cls', 'onclick', this.setVisible.bind(this, false));
}
, centerWindow: function() {
this.setLeft(283); this.setTop(185);
}
,
//@override
setDragable: function(b) {
if (this.draggable != b) {
Position.setDragable(CC.inspect(this.view, '_tbar'), this.view, b); this.draggable = b;
}
}
});
/**
* 浮动提示框,显示后即被回收.
*/
var CFloatTip = CC.create();
CC.extendx(CFloatTip.prototype, CBase);
CC.extend(CFloatTip.prototype, {
type: 'CFloatTip',
timeout: 2500,
//显示位置.相对proxy.
proxy: null,
initialize: function(opt) {
this._super(opt); this.view.innerHTML = CTemplate[this.type];
this.setViewAttr('className', 'important_tip clearfix');
this.setTitle(opt.title);
this.setMsg(opt.msg);
CC.display(this.view,false);
document.body.appendChild(this.view);
//@override
this.override('setVisible', function(it) {
if (!this.proxy || !it) {
return ;
}
var offs = Position.cumulativeOffset(this.proxy);
this.setLeft(offs[0] - 2);
this.setTop(offs[1] - this.view.offsetHeight - 2);
CC.display(this.view,true);
var oThis = this;
if (this.timeout) {
setTimeout(function(){CC.display(oThis.view,false);oThis.clear();}, this.timeout);
}
}
);
}
,
clear: function() {
document.body.removeChild(this.view);
this.proxy = null;
}
,
setMsg: function(msg) {
this.inspectViewAttr('_msg', 'innerHTML', msg);
}
});
var CUtil = {
_sysWin: function() {
var w = window._sysWin;
if (!w) {
w = window._sysWin = new CWin({}
);
CC.style(_sysWin.body, 'textAlign', 'center');
document.body.appendChild(_sysWin.view);
}
w.onClose = null;
return w;
}
,
alert: function(msg, title) {
title = title || '提示';
var s = CUtil._sysWin();
s.setTitle(title);
s.bottom.innerHTML = CTemplate['CUtil.alert'];
s.body.innerHTML = msg;
s.centerWindow();
s.setVisible(true);
}
,
//inputBox(msg,title,onClick(value,state));
inputBox: function(msg, title, onClick) {
var w = CUtil._sysWin();
w.setTitle(title || '提示');
w.body.innerHTML = CTemplate['CUtil.inputBox'].replace('@{msg}', msg);
w.bottom.innerHTML = CTemplate['CUtil.inputBox.body'];
var input = CC.inspect(w.body, '_input');
var callback = function(state) {
var v = input.value;
onClick.call(this, v, state);
}
w.setVisible(true);
input.focus();
CC.inspectAttr(CC.inspect(w.bottom, '_ok'), 'onclick', function() {
if (callback(1)) {
w.setVisible(false);
}
});
CC.inspectAttr(CC.inspect(w.bottom, '_cancel'), 'onclick', function() {
w.setVisible(false);
}
);
}
,
tip: function(msg, title, proxy, timeout, getFocus) {
proxy = CC. $(proxy);
var tip = new CFloatTip( {proxy: proxy, timeout: timeout, title: title, msg: msg});
tip.setVisible(true);
if (getFocus) {
proxy.focus();
}
return tip;
}
};
//--MenuItem
var CMenuItem = CC.create();
//CMenuItem.prototype派生于CBase类.
CC.extendx(CMenuItem.prototype, CBase);
CC.extend(CMenuItem.prototype, {
type: 'CMenuItem',
//子菜单
subMenu: null,
initialize: function(opt) {
//最上层为A标签
var dv = Cache.get('div'); dv.innerHTML = CTemplate[this.type]; this._super(CC.extendIf(opt, {
view: opt.view || dv.firstChild
}
));
// IE7中innerHTML=''时会删除子结点所有数据,因此改为removeChild
dv.removeChild(dv.firstChild); Cache.put('div', dv); this.setTitle(this.title); this.setIcon(opt.icon || '');
Event.bindPassByStyle(this.view, 'itemOn', false, (function() {
//OnMouseOver : 隐藏上一菜单项的子菜单
this.parentContainer._hidePre(); if (this.subMenu) {
this.subMenu.show(true);
}
this.parentContainer._onItem = this;
}
), (function() {
//OnMouseOut :
if (this.subMenu) {
if (this.subMenu.isVisible()) {
return true;
}
}
}
), this);
var oThis = this; var onClick = (function() {
if (oThis.subMenu) {
oThis.subMenu.show(true); return ;
}
//无子菜单
oThis.parentContainer.hideAll(); Event.stopObserving(this, 'click', onClick);
}
);
Event.observe(this.view, 'click', onClick, false);
}
});
//--菜单控件
var CMenu = CC.create();
CC.extendx(CMenu.prototype, CContainerBase);
CC.extend(CMenu.prototype, {
type: 'CMenu',
//父菜单项
parentItem: null,
//上一掠过菜单项
_onItem: null,
initialize: function(opt) {
this._super(CC.extendIf(opt, {
view: CC. $C( {
tagName: 'DIV', className: 'gMenu'
}
)
}
)); this.view.innerHTML = CTemplate[this.type]; this.setWidth(120);
//撤消菜单内的onclick事件上传
this.setViewAttr('onclick', (function() {
Event.stop(window.event);
}
));
//@override
//重写容器类的add方法.
this.override('add', function(it) {
this.view.firstChild.appendChild(it.view);
}
);
//默认为不显示
this.setVisible(false);
//默认将菜单添加到DOM中
document.body.appendChild(this.view);
}
,
//把子菜单menu添加到tar项上,tar可为一个index,或一个CMenuItem对象,还可为CMenuItem的id
attach: function(menu, tar) {
tar = this. $(tar); CC.addClass(tar.view, 'sub'); menu.parentItem = tar; tar.subMenu = menu;
}
,
//撤消菜单项上的子菜单
detach: function(tar) {
tar = this. $(tar); CC.delClass(tar.view, 'sub'); tar.subMenu.parentItem = null; tar.subMenu = null;
}
,
//显示/隐藏菜单,当点击菜单外时菜单并不用消失.
show: function(b) {
if (b) {
this._autoPositioned();
}
if (!b) {
CC.each(this.children, (function(i, e) {
if (this.subMenu) {
if (this.subMenu.isVisible()) {
this.subMenu.show(false);
}
}
}
));
}
this.setVisible(b);
}
,
//显示界面菜单,与show不同,该方法在指定处显示菜单,并且当点击菜单范围外时自动消失.
//showMenu(obj,'bottom')或showMenu(120,230)
showMenu: function(a, b) {
var oThis = this; var onClick = (function() {
if (oThis.isVisible()) {
oThis.hideAll();
}
Event.stopObserving(document, 'click', onClick);
}
); Event.observe(document, 'click', onClick); var ev = window.event; if (ev) {
Event.stop(window.event);
}
if (!CC.isNumber(a)) {
var off = Position.cumulativeOffset(a); switch (b) {
case 'right':
off[0] += a.offsetWidth; break; default:
off[1] += a.offsetHeight; break;
}
this.setPosition(off[0], off[1]);
} else {
this.setPosition(a, b);
}
this.show(true);
}
,
//隐藏与该菜单相联的所有菜单(包括子菜单和父菜单).
hideAll: function() {
this.setVisible(false);
if (this._onItem) {
CC.delClass(this._onItem.view, 'itemOn');
}
CC.each(this.children, (function(i, e) {