-
Notifications
You must be signed in to change notification settings - Fork 0
/
pega_yui_tabview.js
1520 lines (1359 loc) · 56.9 KB
/
pega_yui_tabview.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
/*
Change #1 :Updated proto.DOMEventHandler() to resolve the click event issue in the Accordion content Div
Change#2 : Added harness wevent handler for handling both window resize and layout resize
*/
pega.namespace("pega.ui");
(function() {
/**
* The tabview module provides a widget for managing content bound to tabs.
* @module tabview
* @requires pega, dom, event, element
*
*/
/**
* A widget to control tabbed views.
* @namespace pega.ui
* @class TabView
* @extends pega.util.Element
* @constructor
* @param {HTMLElement | String | Object} el(optional) The html
* element that represents the TabView, or the attribute object to use.
* An element will be created if none provided.
* @param {Object} attr (optional) A key map of the tabView's
* initial attributes. Ignored if first arg is attributes object.
*/
pega.ui.TabView = function(el, attr) {
attr = attr || {};
if (arguments.length == 1 && !pega.lang.isString(el) && !el.nodeName) {
attr = el; // treat first arg as attr object
el = attr.element || null;
}
if (!el && !attr.element) { // create if we dont have one
el = _createTabViewElement.call(this, attr);
}
this._left = 0;
this._menuButtonListWidth = null;
this._currentMenuButtonWidth = 0;
this._tabContainerWidth = null;
this.isDCTabView = false;
pega.ui.TabView.superclass.constructor.call(this, el, attr);
if (this._scrollContainer && this._isHorizontal) {
this._hideScrollers = this._scrollContainer.getAttribute('data-hide-tab-scroll');
this._initEvents();
this._setLastOffset();
//oldWidth was used to set a conditional call to resizeTabScroll in the TabView resize handler
//We are turning off this condition. So no need to calculate this
//this._oldWidth = this._contentParent.parentNode.offsetWidth;
}
};
pega.extend(pega.ui.TabView, pega.util.Element);
var proto = pega.ui.TabView.prototype;
var Dom = pega.util.Dom;
var Event = pega.util.Event;
var Tab = pega.ui.Tab;
//Moving this functionality outside the initEvents method so it can leverage isDCTabView optimiztion
//Currently this info is not available at the time of object instantiation.
//TODO: possible scope for rewrite here to get this information to the contructor.
proto.setHarnessHeaderIconsHeightWidth = function() {
var isFormatSubTabbed, processFurther, ele;
ele = this.get("element");
if (ele) {
isFormatSubTabbed = Dom.hasClass(ele, "subTabbed");
}
processFurther = false;
if (this._harnessHeaderIcons && ((!this.isDCTabView) || (this.isDCTabView && isFormatSubTabbed))) {
processFurther = true;
}
if (processFurther) {
var tabsUL = this._tabParent;
if (tabsUL && tabsUL.offsetHeight != 0) {
//var tabsULHeight = tabsUL.offsetHeight + "px";
// Initialize width and height dynamicly.
//this._harnessHeaderIcons.style.height = Event.isIE ? (parseInt(tabsULHeight, 10) - 2 + "px") : tabsULHeight;
this._harnessHeaderIcons.style.height = tabsUL.lastChild.offsetHeight + "px";
}
this._harnessHeaderIcons.style.width = this._harnessHeaderIcons.firstChild.offsetWidth + "px";
}
}
proto._initEvents = function() {
var tabsUL = this._tabParent;
/* ---------
//perf mod - moved the initialization of harness header icon
//to outside tabview construction code and into the tabsupprt
//initializeTabs method using using setHarnessHeaderIconsHeightWidth
//
// BUG-70791 START
if (this._harnessHeaderIcons) {
if(tabsUL && tabsUL.offsetHeight != 0){
//var tabsULHeight = tabsUL.offsetHeight + "px";
// Initialize width and height dynamicly.
//this._harnessHeaderIcons.style.height = Event.isIE ? (parseInt(tabsULHeight, 10) - 2 + "px") : tabsULHeight;
this._harnessHeaderIcons.style.height = tabsUL.lastChild.offsetHeight + "px";
}
this._harnessHeaderIcons.style.width = this._harnessHeaderIcons.firstChild.offsetWidth + "px";
}
perf mod end
-------- */
// BUG-70791 END
if (this._menuButton) {
Event.addListener(this._menuButton, 'click', this.showTabsMenu, null, this);
Event.addListener(this._menuButton, 'keydown', this.showTabsMenu, null, this);
if (Event.isIE) {
this._menuButton.parentNode.onselectstart = function() {
return false;
};
}
this.objMenuXML = pega.tools.XMLDocument.get();
this.onBeforeShowMenu = new pega.util.CustomEvent("onBeforeShowMenu", this);
}
var that = this;
this.on("activeTabChange", this.focusActiveTab, null, this);
//HFix-20746
pega.u.d.registerResize(function() {
if (!that.isDCTabView) {
if (that._harnessHeaderIcons && that._harnessHeaderIcons.offsetWidth != that._harnessHeaderIcons.firstChild.offsetWidth) {
that._harnessHeaderIcons.style.width = that._harnessHeaderIcons.firstChild.offsetWidth + "px";
}
}
window.setTimeout(function() {
/* if ( that._contentParent && that._contentParent.parentNode ) {
// var newWidth = that._contentParent.parentNode.offsetWidth;
// if (newWidth != that._oldWidth) {
// that._oldWidth = newWidth;*/
if (!that.isDCTabView) {
that.resizeTabsScroll();
}
/* }
//}*/
}, 5);
});
//Required - these resize calls are attached to different events and
//are required for different scenarios
//We will optimize the toggleQuickMenu itself or totally turn it off
//At that point we can remove these
pega.ui.d.attachOnload(function() {
that._toggleQuickMenu();
}, false);
/* BUG-118069, BUG-177986 */
Event.addListener(window, 'resize', function() {
//HFix-20746
if (that.isDCTabView) {
that.resizeTabsScroll();
} else {
that._toggleQuickMenu();
}
}, null, this);
/* BUG-118069, BUG-177986 */
};
proto.resizeTabsScroll = function() {
//BUG-64430 3/13/2012 Script Error when loading portals
if (this._scrollContainer && this._isHorizontal) {
//HFix-20746
if (!this.isDCTabView) {
this._setLastOffset();
}
this._resizeScrollContainer();
this.hideTabsMenu();
this._toggleQuickMenu();
}
//BUG-64430 3/13/2012 Script Error when loading portals
}
pega.ui.TabView.selectTab = function(index) {
var tabView = pega.ui.TabView.activeTabView;
tabView.set("activeTab", tabView.getTab(index));
};
pega.ui.TabView.activeTabView = null;
proto.hideTabsMenu = function() {
pega.ui.TabView.activeTabView = this;
if (this.currentlyOpenedMenus) {
this.currentlyOpenedMenus._hideAll();
}
}
proto.showTabsMenu = function(e) {
//If the keydown event is not from enter or space then ignore it.
if (e.type == "keydown" && !(e.keyCode == 13 || e.keyCode == 32)) {
return;
}
var activeTabView = pega.ui.TabView.activeTabView;
if (activeTabView && activeTabView.currentlyOpenedMenus) {
activeTabView.currentlyOpenedMenus._hideAll();
}
pega.ui.TabView.activeTabView = this;
this.currentlyOpenedMenus = new pega.ui.menubar.Manager();
var tabStrip = this._tabParent.parentNode,
scrollContainerWidth = tabStrip.offsetWidth,
scrollLeft = Math.abs(this._left),
leftOffset = scrollLeft + scrollContainerWidth,
aTabs = this.get("tabs"),
activeIndex = this.get("activeIndex"),
dataXML = "<pagedata>\n<Menu>",
tabsLength = (this._tabPos == "Top") ? aTabs.length - 1 : aTabs.length,
ln = 4; // ln is the length of the longest title.
if (!Event.isIE || pega.u.d.inStandardsMode)
this._fixTabsDisplay("inline-block"); // BUG-73011 : This will help to get correct offset values
for (var i = 0; i < tabsLength; i++) {
var oTab = aTabs[i],
styleOverrides = {},
leftStyleOverrides = {},
tabEl = oTab.get("element"),
itemLeft = tabEl.offsetLeft,
itemWidth = tabEl.offsetWidth,
itemOffset = itemLeft + itemWidth,
/* BUG-102407 GUJAS1 05/15/2013 Send tab instance */
tabIconLabelTooltip = this.getTabLabelIconAndTooltip(tabEl, oTab),
icon = tabIconLabelTooltip.icon,
imageClass = "",
styleString = "",
leftStyleString = "",
activeStyle = "",
label = tabIconLabelTooltip.label || tabIconLabelTooltip.tooltip || "",
strToolTip = tabIconLabelTooltip.tooltip || tabIconLabelTooltip.label || "",
strValue = label;
if (itemLeft < scrollLeft || itemOffset > leftOffset) {
styleOverrides["background-color"] = "#dbdbdb";
leftStyleOverrides["background-color"] = "#dbdbdb";
}
if (activeIndex == i) {
styleOverrides["font-weight"] = "bold";
leftStyleOverrides["font-weight"] = "bold";
}
if (icon) {
leftStyleOverrides["background-image"] = "url('" + icon + "')";
leftStyleOverrides["background-repeat"] = "no-repeat";
leftStyleOverrides["background-position"] = "center";
imageClass = "tabsMenuEmptyImageDiv";
}
for (var o in styleOverrides) {
styleString += o + ":" + styleOverrides[o] + ";";
}
for (var lo in leftStyleOverrides) {
leftStyleString += lo + ":" + leftStyleOverrides[lo] + ";";
}
if (leftStyleString.length > 0) {
activeStyle += ("leftstyle = \"" + leftStyleString + "\"");
}
if (styleString.length > 0) {
activeStyle += (" middlestyle = \"" + styleString + "\" rightstyle = \"" + styleString + "\"");
}
if (label.length > 16) {
label = label.substring(0, 13) + "...";
}
if (label.length > ln) {
ln = label.length;
}
strValue = label;
// SE-34391 : Changes to escape special characters.
strToolTip = strToolTip.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
strValue = strValue.replace(/&/g,"&");
activeStyle = activeStyle.replace(/&/g,"&");
imageClass = imageClass.replace(/&/g,"&");
// BUG-62486 GUJAS1 03/20/2012 Added index of the tab to the menu key.
var snippet = '\n<Item Value="' + strValue + i + '" Caption="' + strValue + '" ToolTip="'
+ strToolTip + '" ' + activeStyle + ' ImageClass="' + imageClass
+ '" onClick="pega.ui.TabView.selectTab(' + i + ');"></Item>';
dataXML += snippet;
}
if (!Event.isIE || pega.u.d.inStandardsMode)
this._fixTabsDisplay("inline"); // BUG-73011 : Reset display value to inline
dataXML += "\n</Menu>\n</pagedata>";
var isLoaded = this.objMenuXML.loadXML(dataXML);
var xmlMenuNode = this.objMenuXML.documentElement.selectSingleNode("//Menu");
this.currentlyOpenedMenus.setStylePrefix("");
this.currentlyOpenedMenus.desktopClickHandler.srcElement = this._menuButtonList;
this.onBeforeShowMenu.fire();
this.currentlyOpenedMenus.doContextMenu(xmlMenuNode, {relativeElement: this._menuButtonList, align: "right"});
Event.stopEvent(e);
return false;
};
proto._onDOMScroll = function(evt) {
var target = evt.target ? evt.target : evt.srcElement;
if (this._isHorizontal) {
var scrollLeft = target.scrollLeft;
var maxScroll = (this._lastItemOffset - this._tabContainerWidth);
if (scrollLeft > maxScroll) {
target.scrollLeft = scrollLeft = maxScroll;
}
this._left = scrollLeft;
}
this._toggleQuickMenu();
};
proto.focusActiveTab = function(evt) {
var newEl = this._tabParent.childNodes[this.get("activeIndex")];
this.scrollToElement(newEl);
};
proto._setLastOffset = function() {
//intentional global
//try {
if (typeof gCloseAllTabsInProgress != "undefined" && gCloseAllTabsInProgress) {
return;
}
//} catch (e) {
//currently gCloseAllTabsInProgress is not initialized and throws exception unless coming from closeAllDocuments
//}
if (this._scrollContainer && this._isHorizontal) {
var childEl = this._tabParent.lastChild;
if (childEl && this._tabPos == "Top") {
childEl = childEl.previousSibling;
}
while (childEl) {
if (childEl.style.display == "none") {
childEl = childEl.previousSibling;
} else {
break;
}
}
//The calls to fixTabsDisplay is no longer required as the default styling is inline-block and no toggling is required
if (childEl && !(Dom.hasClass(childEl, "rightborder"))) {
// BUG-77009 07/25/2012 GUJAS1 Set the display of all tabs to inline-block to correctly calculate width.
//if(!Event.isIE || pega.u.d.inStandardsMode) this._fixTabsDisplay("inline-block");
this._lastItemOffset = (childEl.offsetLeft + childEl.offsetWidth);
// BUG-77009 07/25/2012 GUJAS1 Reset the display of all tabs to inline.
//if(!Event.isIE || pega.u.d.inStandardsMode) this._fixTabsDisplay("inline");//childEl.style.display = "inline";
}
this._toggleQuickMenu();
}
};
proto._toggleQuickMenu = function() {
if(!this._tabContainerWidth){
//tabstrip is not ready yet. Possibly because this is the initial load of the tab group
//We will not need to toggle the menu in this case
return;
}
var tabStrip = this._tabParent.parentNode;
if (tabStrip) {
var aTabs = this.get("tabs"),
controlsWidth = (this._left == 0) ? this._currentMenuButtonWidth : 0,
tabsLength = (this._tabPos == "Top") ? aTabs.length - 1 : aTabs.length;
if (this._tabContainerWidth == 0) {
return;
}
//For DC Tabs to always have Quick Menu
if (this.isDCTabView && this._menuButton) {
if (this._menuButtonList.style.display != "inline-block") {
this._menuButtonList.style.display = "inline-block";
}
// Fix for BUG-392611
// Hide the dc tabs overflow menu when gIsCustomTabHeaderEnabled is enabled
if(window.gIsCustomTabHeaderEnabled) {
this._menuButtonList.style.visibility = "hidden";
}
return;
}
this._reachedStart = (tabsLength == 0 || this._left <= 0);
this._reachedEnd = (tabsLength == 0 || (this._tabContainerWidth + controlsWidth + this._left) >= this._lastItemOffset);
if (this._reachedStart && this._reachedEnd) {
if (this._menuButton) {
this._menuButtonList.style.display = "none";
this._currentMenuButtonWidth = 0;
}
if (this.currentlyOpenedMenus) {
this.hideTabsMenu();
}
}
else {
if (this._menuButton) {
this._menuButtonList.style.display = "inline-block";
if (this._menuButtonListWidth == null) {
this._menuButtonListWidth = this._menuButton.offsetWidth;
}
this._currentMenuButtonWidth = this._menuButtonListWidth;
}
}
}
};
proto.scrollToElement = function(idOrEl) {
var scrollEl;
if (typeof (idOrEl) == "string") {
scrollEl = document.getElementById(idOrEl);
} else {
scrollEl = idOrEl;
}
if (scrollEl && scrollEl.nodeType && !(Dom.hasClass(scrollEl, "rightborder"))) {
var anchorElement = scrollEl.querySelector("span#TABANCHOR");
if (this._isHorizontal && anchorElement) {
scrollEl = anchorElement;
var tabStrip = this._tabParent.parentNode,
scrollContainerWidth,
tabList,
itemLeft = scrollEl.offsetLeft,
itemWidth = scrollEl.offsetWidth,
scrollLeft = Math.abs(this._left),
leftOffset,
itemOffset = itemLeft + itemWidth;
if (this._tabContainerWidth == null) {
scrollContainerWidth = this._tabContainerWidth = tabStrip.offsetWidth;
} else {
scrollContainerWidth = this._tabContainerWidth;
}
leftOffset = scrollLeft + scrollContainerWidth;
if (itemLeft > scrollLeft && itemOffset < leftOffset) {
this._toggleQuickMenu();
return; // Already in visible area.
}
if (itemOffset >= leftOffset) {
itemLeft = scrollLeft + (itemOffset - leftOffset);
}
if (itemLeft < 0) {
itemLeft = 0;
}
this._left = itemLeft;
if(window.gIsCustomTabHeaderEnabled){
tabList = tabStrip.firstElementChild;
tabList.scrollLeft = this._left;
}else{
tabStrip.scrollLeft = this._left;
}
}
}
this._toggleQuickMenu();
};
proto._fixTabsDisplay = function(value) {
/*BUG-121808: to remove the hardcoded 10000px width for tabs
* this function needs to be turned off
*/
return;
//var length = this._tabParent.lastChild.className.indexOf("rightborder") != -1 ? this._tabParent.childNodes.length - 1 : this._tabParent.childNodes.length;
//var length = this._tabPos == "Top" ? this._tabParent.childNodes.length - 1 : this._tabParent.childNodes.length;
for (var i = 0; i < this._tabParent.childNodes.length; i++) {
var node = this._tabParent.childNodes[i];
if (node.className.indexOf("rightborder") == -1) {
node.style.display = value;
}
}
}
proto._resizeScrollContainer = function() {
//HFix-20746
//intentional global
//try {
if (typeof gCloseAllTabsInProgress != "undefined" && gCloseAllTabsInProgress) {
return;
}
//} catch (e) {
//currently gCloseAllTabsInProgress is not initialized and throws exception unless coming from closeAllDocuments
//}
var tabStrip = this._tabParent.parentNode;
if (tabStrip && this._isHorizontal) {
var scrollContainerWidth = tabStrip.offsetWidth,
scrollLeft = Math.abs(this._left),
itemLeft = 0,
lastItemOffset = this._lastItemOffset,
leftOffset = lastItemOffset - scrollLeft;
if (scrollLeft > 0 && leftOffset <= scrollContainerWidth) {
itemLeft = scrollContainerWidth - leftOffset;
}
itemLeft = this._left + itemLeft;
if (itemLeft >= 0) {
itemLeft = 0;
}
this._left = itemLeft;
this._tabContainerWidth = scrollContainerWidth;
tabStrip.scrollLeft = this._left;
this.focusActiveTab();
}
};
/* BUG-102407 GUJAS1 05/15/2013 Added new param to pass tab instance, */
proto.getTabLabelIconAndTooltip = function(tabEl, oTab) {
var labelElement = tabEl.querySelector("span[data-stl]"),
tabIconElement = tabEl.getElementsByTagName("img"),
anchorElement = tabEl.querySelector("span[id='TABANCHOR']"),
customTabHeaderEle = tabEl.querySelector("div[node_name='pyCustomDCTabSection']"),
label = "", icon = "", tooltip = "";
/* BUG-102407 GUJAS1 05/15/2013 Read label/tooltip/icon from cached properties if available */
if(window.gIsCustomTabHeaderEnabled && customTabHeaderEle){
label = customTabHeaderEle.innerText;
var toolTipEle = customTabHeaderEle.querySelector("[title]");
if(toolTipEle){
tooltip = toolTipEle.title;
}
} else if (oTab) {
if (typeof oTab.label == "string" && oTab.label.length > 0) {
label = oTab.label;
}
if (typeof oTab.ToolTip == "string" && oTab.ToolTip.length > 0) {
tooltip = oTab.ToolTip;
}
if (typeof oTab.iconPath == "string" && oTab.iconPath.length > 0) {
icon = oTab.iconPath;
}
}
if (label == "" && labelElement) {
label = Dom.getInnerText(labelElement);
}
if (tooltip == "" && anchorElement) {
tooltip = anchorElement.title;
}
if (icon == "" && tabIconElement.length > 0) {
icon = tabIconElement[0].src;
tooltip = tabIconElement[0].title;
}
if(icon && tooltip==""){
tooltip = tabIconElement[0].title;
}
return {"label": label, "icon": icon, "tooltip": tooltip};
};
/**
* The className to add when building from scratch.
* @property CLASSNAME
* @default "navset"
*/
proto.CLASSNAME = 'yui-navset';
/**
* The className of the HTMLElement containing the TabView's tab elements
* to look for when building from existing markup, or to add when building
* from scratch.
* All childNodes of the tab container are treated as Tabs when building
* from existing markup.
* @property TAB_PARENT_CLASSNAME
* @default "nav"
*/
proto.TAB_PARENT_CLASSNAME = 'yui-nav';
/**
* The className of the HTMLElement containing the TabView's label elements
* to look for when building from existing markup, or to add when building
* from scratch.
* All childNodes of the content container are treated as content elements when
* building from existing markup.
* @property CONTENT_PARENT_CLASSNAME
* @default "nav-content"
*/
proto.CONTENT_PARENT_CLASSNAME = 'yui-content';
proto._tabParent = null;
proto._contentParent = null;
/**
* Adds a Tab to the TabView instance.
* If no index is specified, the tab is added to the end of the tab list.
* @method addTab
* @param {pega.ui.Tab} tab A Tab instance to add.
* @param {Integer} index The position to add the tab.
* @return void
*/
proto.addTab = function(tab, index) {
var tabs = this.get('tabs');
if (!tabs) { // not ready yet
this._queue[this._queue.length] = ['addTab', arguments];
return false;
}
index = (index === undefined) ? tabs.length : index;
tab.tabview = this;
var before = this.getTab(index);
var self = this;
var el = this.get('element');
var tabParent = this._tabParent;
var contentParent = this._contentParent;
var tabElement = tab.get('element');
var contentEl = tab.get('contentEl');
//BUG-156444 : hide tabs list container when there are no tabs
var contentElements = _getChildNodes(this._contentParent);
if (this._scrollContainer && contentElements.length > 0) {
this._scrollContainer.style.display = "";
}
if (before) {
tabParent.insertBefore(tabElement, before.get('element'));
} else {
tabParent.appendChild(tabElement);
}
if (contentEl && !Dom.isAncestor(contentParent, contentEl)) {
contentParent.appendChild(contentEl);
}
if (!tab.get('active')) {
tab.set('contentVisible', false, true); /* hide if not active */
} else {
this.set('activeTab', tab, true);
}
var activate = function(e, tabObj) {
// BUG-44883 Checkbox doesn’t work in Tab and Accordian header modes becuase of preventing the default behavior of the event. To fix this bug added below tagName condition.
var target = pega.util.Event.getTarget(e);
if (!target || !target.tagName || !target.tagName.match(/^(input|select|textarea)$/gi)) {
pega.util.Event.preventDefault(e);
}
var existingActiveTab = self.get('activeTab');
self.set('activeTab', tabObj);
if(tabObj.tabview.isDCTabView){
pega.desktop.sendEvent('DCTabSwitch', {
fromTab: {
id: existingActiveTab.label,
handle: existingActiveTab.key,
GadgetName: existingActiveTab.GadgetName
},
toTab: {
id: tabObj.label,
handle: tabObj.key,
GadgetName: tabObj.GadgetName
}
});
}
};
if (this.hasClass("with-fixed-header")) {
Event.addListener(tabElement, tab.get('activationEvent'), activate, tab);
} else {
tab.addListener(tab.get('activationEvent'), activate, tab);
}
tab.addListener('activationEventChange', function(e) {
if (e.prevValue != e.newValue) {
if (this.tabview.hasClass("with-fixed-header")) {
Event.removeListener(tab.get('element'), e.prevValue, activate, tab);
Event.addListener(tab.get('element'), e.newValue, activate, tab);
} else {
tab.removeListener(e.prevValue, activate, tab);
tab.addListener(e.newValue, activate, tab);
}
}
});
tabs.splice(index, 0, tab);
//this._setLastOffset(); //not required - has perf penalty
this.fireEvent("tabAdded", {"tabs": this.get("tabs"), "addedTab": tab});
};
/**
* Routes childNode events.
* @method DOMEventHandler
* @param {event} e The Dom event that is being handled.
* @return void
*/
proto.DOMEventHandler = function(e) {
var el = this.get('element');
var target = pega.util.Event.getTarget(e);
var tabParent = this._tabParent;
var inAccordion = false;
if (el && el.id && el.id.indexOf("PEGA_ACCORDION") == 0) {
inAccordion = true;
}
if (Dom.isAncestor(tabParent, target)) {
var tabEl;
var tab = null;
var contentEl;
var tabs = this.get('tabs');
for (var i = 0, len = tabs.length; i < len; i++) {
tabEl = tabs[i].get('element');
contentEl = tabs[i].get('contentEl');
if (inAccordion) {
var firstChild = pega.util.Dom.getChildren(tabEl)[0];
if (target == tabEl || target == firstChild || Dom.isAncestor(firstChild, target)) {
tab = tabs[i];
break; // note break
}
} else {
if ((target == tabEl || Dom.isAncestor(tabEl, target)) && (tabEl.className == null || tabEl.className.indexOf('addTab') < 0)) {
tab = tabs[i];
break; // note break
}
}
}
if (tab) {
tab.fireEvent(e.type, e);
}
}
};
/**
* Returns the Tab instance at the specified index.
* @method getTab
* @param {Integer} index The position of the Tab.
* @return pega.ui.Tab
*/
proto.getTab = function(index) {
return this.get('tabs')[index];
};
/**
* Returns the index of given tab.
* @method getTabIndex
* @param {pega.ui.Tab} tab The tab whose index will be returned.
* @return int
*/
proto.getTabIndex = function(tab) {
var index = null;
var tabs = this.get('tabs');
for (var i = 0, len = tabs.length; i < len; ++i) {
if (tab == tabs[i]) {
index = i;
break;
}
}
return index;
};
/**
* Removes the specified Tab from the TabView.
* @method removeTab
* @param {pega.ui.Tab} item The Tab instance to be removed.
* @param {boolean} pass true if MRU like mechanism is present to change active indexes. Desired by Workarea layouts.
* @return void
*/
proto.removeTab = function(tab, keepActiveIndex) {
var tabCount = this.get('tabs').length;
var index = this.getTabIndex(tab);
var nextIndex = index + 1;
if (!keepActiveIndex && tab == this.get('activeTab')) { // select next tab
if (tabCount > 1) {
if (index + 1 == tabCount) {
this.set('activeIndex', index - 1);
} else {
this.set('activeIndex', index + 1);
}
}
}
this._tabParent.removeChild(tab.get('element'));
this._contentParent.removeChild(tab.get('contentEl'));
this._configs.tabs.value.splice(index, 1);
//this._setLastOffset();
//this._resizeScrollContainer();
this.resizeTabsScroll(); //this does both the above calls and properly handles the tabs menu toggle
this.fireEvent("tabRemoved", {"tabs": this.get("tabs"), "removedTab": tab});
};
/**
* Provides a readable name for the TabView instance.
* @method toString
* @return String
*/
proto.toString = function() {
var name = this.get('id') || this.get('tagName');
return "TabView " + name;
};
/**
* The transiton to use when switching between tabs.
* @method contentTransition
*/
proto.contentTransition = function(newTab, oldTab) {
newTab.set('contentVisible', true);
oldTab.set('contentVisible', false);
};
/**
* setAttributeConfigs TabView specific properties.
* @method initAttributes
* @param {Object} attr Hash of initial attributes
*/
proto.initAttributes = function(attr) {
pega.ui.TabView.superclass.initAttributes.call(this, attr);
if (!attr.orientation) {
attr.orientation = 'top';
}
var el = this.get('element');
/**
* The Tabs belonging to the TabView instance.
* @config tabs
* @type Array
*/
this.setAttributeConfig('tabs', {
value: [],
readOnly: true
});
/**
* The container of the tabView's label elements.
* @property _tabParent
* @private
* @type HTMLElement
*/
var tabParentCandidate = Dom.getFirstChild(el);
this._isCSSResize = false;
var scrollContainerEl;
/* BUG-139599 - If Accordion has a TabGroup, then the accordion is detecting as it contains scroll container. Because of it the _tabParent was set incorrectly.: KUMAD1 */
if (el.id.indexOf("PEGA_ACCORDION") != 0) {
scrollContainerEl = Dom.getChildrenBy(el, function(obj) {
return (obj.className && obj.className.indexOf("scrlCntr") != -1);
})[0];
}
if (this.hasClass("with-fixed-header")) {
this._isCSSResize = true;
scrollContainerEl = Dom.getFirstChild(document.getElementById("dummyDiv"));
}
if (scrollContainerEl) {
this._scrollContainer = scrollContainerEl;
var tabPos = el.getAttribute('data-pos');
this._isHorizontal = (tabPos == "Top" || tabPos == "Bottom");
this._tabPos = tabPos;
if (tabPos == "Top") { //Horizontal top tabs case
if (this._isCSSResize) {
tabParentCandidate = Dom.getFirstChild(document.getElementById("dummyDiv"));
}
this._tabParent = tabParentCandidate.lastChild.firstChild;
} else if (tabPos == "Left" || tabPos == "Right") { //Vertical tabs case
var tblElement = tabParentCandidate;
if (this._isCSSResize) {
tabParentCandidate = $(".dc-" + tabPos.toLowerCase() + " .contents .pegaTabGrp .tab-ul")[0];
}
else {
tabParentCandidate = Dom.getFirstChild(tblElement.rows[0].cells[0]);
}
if (tabParentCandidate && tabPos == "Left") { // Vertical tabs on the left case
//BUG-69633 05/10/2012 GUJAS1 Markup changes have caused the UL to be the first cell element.
//this._tabParent = tabParentCandidate.lastChild;
this._tabParent = tabParentCandidate;
} else {
if (this._isCSSResize) {
tabParentCandidate = $(".dc-" + tabPos.toLowerCase() + " .contents .pegaTabGrp .tab-ul")[0];
}
else {
tabParentCandidate = Dom.getFirstChild(tblElement.rows[0].cells[1]);
}
if (tabParentCandidate && tabPos == "Right") { // Vertical tabs on the right case
//BUG-69633 05/10/2012 GUJAS1 Markup changes have caused the UL to be the first cell element.
//this._tabParent = tabParentCandidate.lastChild;
this._tabParent = tabParentCandidate;
}
}
} else if (tabPos == "Bottom") {
if (this._isCSSResize) {
tabParentCandidate = Dom.getFirstChild(document.getElementById("dummyDiv"));
} else {
tabParentCandidate = Dom.getLastChild(el);
}
this._tabParent = tabParentCandidate.lastChild.firstChild;
} else {
this._tabParent = _createTabParent.call(this);
}
// BUG-70791 START
var harnessHeaderIcons = Dom.getElementsByClassName("harnessHeaderIcons", "div", tabParentCandidate);
if (harnessHeaderIcons.length > 0) {
this._harnessHeaderIcons = harnessHeaderIcons[0];
}
// BUG-70791 END
var tabButtonsList = tabParentCandidate.getElementsByTagName("ol");
// If tabButtonsList has children, initialize scroller elements.
if (tabButtonsList.length > 0) {
/*
this._prevButtonList = tabButtonsList[0];
this._prevButton = this._prevButtonList.getElementsByTagName("a")[0];
this._nextButtonList = (tabButtonsList.length == 3) ? tabButtonsList[2] : tabButtonsList[1];
this._nextButton = this._nextButtonList.getElementsByTagName("a")[0];
*/
this._menuButtonList = tabButtonsList[0];
this._menuButton = this._menuButtonList ? this._menuButtonList.getElementsByTagName("a")[0] : null;
}
} else {
if (tabParentCandidate.nodeName === 'UL') { //Horizontal top tabs case
this._tabParent = tabParentCandidate;
} else if (tabParentCandidate.nodeName === 'TABLE') { //Vertical tabs case
var tblElement = tabParentCandidate;
tabParentCandidate = Dom.getFirstChild(tblElement.rows[0].cells[0]);
if (tabParentCandidate && tabParentCandidate.nodeName === 'UL') { // Vertical tabs on the left case
this._tabParent = tabParentCandidate;
} else {
tabParentCandidate = Dom.getFirstChild(tblElement.rows[0].cells[1]);
if (tabParentCandidate && tabParentCandidate.nodeName === 'UL') { // Vertical tabs on the right case
this._tabParent = tabParentCandidate;
}
}
} else if (tabParentCandidate.nodeName === 'DIV') {
this._tabParent = Dom.getLastChild(el);
} else {
this._tabParent = _createTabParent.call(this);
}
}
/**
* The container of the tabView's content elements.
* @property _contentParent
* @type HTMLElement
* @private
*/
this._contentParent =
this.getElementsByClassName(this.CONTENT_PARENT_CLASSNAME,
'div')[0] || _createContentParent.call(this);
/**
* How the Tabs should be oriented relative to the TabView.
* @config orientation
* @type String
* @default "top"
*/
this.setAttributeConfig('orientation', {
value: attr.orientation,
method: function(value) {
var current = this.get('orientation');
//this.addClass('yui-navset-' + value);
if (current != value) {
this.removeClass('yui-navset-' + current);
}
switch (value) {
case 'bottom':
this.appendChild(this._tabParent);
break;
}
}
});
/**
* The index of the tab currently active.
* @config activeIndex
* @type Int
*/
this.setAttributeConfig('activeIndex', {
value: attr.activeIndex,
method: function(value) {
this.set('activeTab', this.getTab(value));
},
validator: function(value) {
return !this.getTab(value).get('disabled'); // cannot activate if disabled
}
});
/**
* The tab currently active.
* @config activeTab
* @type pega.ui.Tab
*/
this.setAttributeConfig('activeTab', {
value: attr.activeTab,
method: function(tab) {
var activeTab = this.get('activeTab');
if (tab) {
tab.set('active', true);
this._configs['activeIndex'].value = this.getTabIndex(tab); // keep in sync
}
if (activeTab && activeTab != tab) {
activeTab.set('active', false);
}
if (activeTab && tab != activeTab) { // no transition if only 1
this.contentTransition(tab, activeTab);
} else if (tab) {
tab.set('contentVisible', true);
}
},
validator: function(value) {
return !value.get('disabled'); // cannot activate if disabled
}
});