| | 869 | |
| | 870 | dojo.widget.MenuBar2 = function(){ |
| | 871 | dojo.widget.HtmlWidget.call(this); |
| | 872 | } |
| | 873 | |
| | 874 | dojo.inherits(dojo.widget.MenuBar2, dojo.widget.HtmlWidget); |
| | 875 | |
| | 876 | dojo.lang.extend(dojo.widget.MenuBar2, { |
| | 877 | widgetType: "MenuBar2", |
| | 878 | isContainer: true, |
| | 879 | |
| | 880 | snarfChildDomOutput: true, |
| | 881 | |
| | 882 | currentItem: null, |
| | 883 | isExpanded: false, |
| | 884 | |
| | 885 | currentSubmenu: null, |
| | 886 | currentSubmenuTrigger: null, |
| | 887 | |
| | 888 | domNode: null, |
| | 889 | containerNode: null, |
| | 890 | |
| | 891 | templateString: '<div class="dojoMenuBar2"><div dojoAttachPoint="containerNode" class="dojoMenuBar2Client"></div></div>', |
| | 892 | templateCssPath: dojo.uri.dojoUri("src/widget/templates/HtmlMenu2.css"), |
| | 893 | |
| | 894 | itemHeight: 18, |
| | 895 | openEvent: null, |
| | 896 | |
| | 897 | |
| | 898 | postCreate: function(){ |
| | 899 | |
| | 900 | // do something here |
| | 901 | |
| | 902 | this.layoutMenuSoon(); |
| | 903 | }, |
| | 904 | |
| | 905 | layoutMenuSoon: function(){ |
| | 906 | dojo.lang.setTimeout(this, "layoutMenu", 0); |
| | 907 | }, |
| | 908 | |
| | 909 | layoutMenu: function(){ |
| | 910 | |
| | 911 | // menu must be attached to DOM for size calculations to work |
| | 912 | |
| | 913 | var parent = this.domNode.parentNode; |
| | 914 | if (! parent || parent == undefined) { |
| | 915 | document.body.appendChild(this.domNode); |
| | 916 | } |
| | 917 | |
| | 918 | |
| | 919 | // determine menu height |
| | 920 | |
| | 921 | var max_label_h = 0; |
| | 922 | |
| | 923 | for(var i=0; i<this.children.length; i++){ |
| | 924 | |
| | 925 | if (this.children[i].getLabelHeight){ |
| | 926 | |
| | 927 | max_label_h = Math.max(max_label_h, this.children[i].getLabelHeight()); |
| | 928 | } |
| | 929 | } |
| | 930 | |
| | 931 | if (isNaN(max_label_h)){ |
| | 932 | // Browser needs some more time to calculate sizes |
| | 933 | this.layoutMenuSoon(); |
| | 934 | return; |
| | 935 | } |
| | 936 | |
| | 937 | var clientLeft = dojo.style.getPixelValue(this.domNode, "padding-left", true) |
| | 938 | + dojo.style.getPixelValue(this.containerNode, "margin-left", true) |
| | 939 | + dojo.style.getPixelValue(this.containerNode, "padding-left", true); |
| | 940 | var clientTop = dojo.style.getPixelValue(this.domNode, "padding-top", true) |
| | 941 | + dojo.style.getPixelValue(this.containerNode, "padding-top", true); |
| | 942 | |
| | 943 | if (isNaN(clientLeft) || isNaN(clientTop)){ |
| | 944 | // Browser needs some more time to calculate sizes |
| | 945 | this.layoutMenuSoon(); |
| | 946 | return; |
| | 947 | } |
| | 948 | |
| | 949 | var max_item_height = 0; |
| | 950 | var x = clientLeft; |
| | 951 | |
| | 952 | for (var i=0; i<this.children.length; i++){ |
| | 953 | |
| | 954 | var ch = this.children[i]; |
| | 955 | |
| | 956 | ch.layoutItem(max_label_h); |
| | 957 | |
| | 958 | ch.leftPosition = x; |
| | 959 | ch.domNode.style.left = x + 'px'; |
| | 960 | |
| | 961 | x += dojo.style.getOuterWidth(ch.domNode); |
| | 962 | max_item_height = Math.max(max_item_height, dojo.style.getOuterHeight(ch.domNode)); |
| | 963 | } |
| | 964 | |
| | 965 | dojo.style.setContentHeight(this.containerNode, max_item_height); |
| | 966 | dojo.style.setContentHeight(this.domNode, dojo.style.getOuterHeight(this.containerNode)); |
| | 967 | }, |
| | 968 | |
| | 969 | openSubmenu: function(submenu, from_item){ |
| | 970 | |
| | 971 | var our_pos = dojo.style.getAbsolutePosition(this.domNode, false); |
| | 972 | |
| | 973 | var our_h = dojo.style.getOuterHeight(this.domNode); |
| | 974 | var item_x = from_item.leftPosition; |
| | 975 | |
| | 976 | var x = our_pos.x + item_x; |
| | 977 | var y = our_pos.y + our_h; |
| | 978 | |
| | 979 | this.currentSubmenu = submenu; |
| | 980 | this.currentSubmenu.open(x, y, this, from_item.domNode); |
| | 981 | this.currentSubmenu.parentMenuBar = this; |
| | 982 | }, |
| | 983 | |
| | 984 | closeSubmenu: function(){ |
| | 985 | |
| | 986 | if (this.currentSubmenu == null){ return; } |
| | 987 | |
| | 988 | var menu = this.currentSubmenu; |
| | 989 | this.currentSubmenu = null; |
| | 990 | menu.close(); |
| | 991 | }, |
| | 992 | |
| | 993 | itemHover: function(item){ |
| | 994 | |
| | 995 | if (item == this.currentItem) return; |
| | 996 | |
| | 997 | if (this.currentItem){ |
| | 998 | this.currentItem.unhighlightItem(); |
| | 999 | |
| | 1000 | if (this.isExpanded){ |
| | 1001 | this.closeSubmenu(); |
| | 1002 | } |
| | 1003 | } |
| | 1004 | |
| | 1005 | this.currentItem = item; |
| | 1006 | this.currentItem.highlightItem(); |
| | 1007 | |
| | 1008 | if (this.isExpanded){ |
| | 1009 | this.currentItem.expandMenu(); |
| | 1010 | } |
| | 1011 | }, |
| | 1012 | |
| | 1013 | itemUnhover: function(item){ |
| | 1014 | |
| | 1015 | if (item != this.currentItem) return; |
| | 1016 | |
| | 1017 | if (!this.isExpanded){ |
| | 1018 | this.currentItem.unhighlightItem(); |
| | 1019 | this.currentItem = null; |
| | 1020 | } |
| | 1021 | }, |
| | 1022 | |
| | 1023 | itemClick: function(item){ |
| | 1024 | |
| | 1025 | if (item != this.currentItem){ |
| | 1026 | |
| | 1027 | this.itemHover(item); |
| | 1028 | } |
| | 1029 | |
| | 1030 | if (this.isExpanded){ |
| | 1031 | |
| | 1032 | this.isExpanded = false; |
| | 1033 | this.closeSubmenu(); |
| | 1034 | |
| | 1035 | }else{ |
| | 1036 | |
| | 1037 | this.isExpanded = true; |
| | 1038 | this.currentItem.expandMenu(); |
| | 1039 | } |
| | 1040 | }, |
| | 1041 | |
| | 1042 | closedMenu: function(menu){ |
| | 1043 | |
| | 1044 | if (this.currentSubmenu == menu){ |
| | 1045 | |
| | 1046 | this.isExpanded = false; |
| | 1047 | this.itemUnhover(this.currentItem); |
| | 1048 | } |
| | 1049 | } |
| | 1050 | }); |
| | 1051 | |
| | 1052 | |
| | 1053 | dojo.widget.MenuBarItem2 = function(){ |
| | 1054 | dojo.widget.HtmlWidget.call(this); |
| | 1055 | } |
| | 1056 | |
| | 1057 | dojo.inherits(dojo.widget.MenuBarItem2, dojo.widget.HtmlWidget); |
| | 1058 | |
| | 1059 | dojo.lang.extend(dojo.widget.MenuBarItem2, { |
| | 1060 | |
| | 1061 | widgetType: "MenuBarItem2", |
| | 1062 | templateString: |
| | 1063 | '<div class="dojoMenuBarItem2">' |
| | 1064 | +'<span dojoAttachPoint="labelNode" class="dojoMenuBarItem2Label"><span><span></span></span></span>' |
| | 1065 | +'<div dojoAttachPoint="targetNode" class="dojoMenuBarItem2Target" dojoAttachEvent="onMouseOver: onHover; onMouseOut: onUnhover; onClick: _onClick;"> </div>' |
| | 1066 | +'</div>', |
| | 1067 | |
| | 1068 | // |
| | 1069 | // nodes |
| | 1070 | // |
| | 1071 | |
| | 1072 | domNode: null, |
| | 1073 | labelNode: null, |
| | 1074 | targetNode: null, |
| | 1075 | |
| | 1076 | // |
| | 1077 | // internal settings |
| | 1078 | // |
| | 1079 | |
| | 1080 | is_hovering: false, |
| | 1081 | hover_timer: null, |
| | 1082 | is_open: false, |
| | 1083 | |
| | 1084 | // |
| | 1085 | // options |
| | 1086 | // |
| | 1087 | |
| | 1088 | caption: 'Untitled', |
| | 1089 | accelKey: '', |
| | 1090 | iconSrc: '', |
| | 1091 | submenuId: '', |
| | 1092 | disabled: false, |
| | 1093 | eventNaming: "default", |
| | 1094 | |
| | 1095 | |
| | 1096 | postCreate: function(){ |
| | 1097 | |
| | 1098 | dojo.html.disableSelection(this.domNode); |
| | 1099 | |
| | 1100 | if (this.disabled){ |
| | 1101 | this.setDisabled(true); |
| | 1102 | } |
| | 1103 | |
| | 1104 | this.labelNode.childNodes[0].appendChild(document.createTextNode(this.caption)); |
| | 1105 | |
| | 1106 | this.labelShadowNode = this.labelNode.childNodes[0].childNodes[0]; |
| | 1107 | this.labelShadowNode.appendChild(document.createTextNode(this.caption)); |
| | 1108 | |
| | 1109 | if (this.eventNaming == "default") { |
| | 1110 | for (eventName in this.eventNames) { |
| | 1111 | this.eventNames[eventName] = this.widgetId+"/"+eventName; |
| | 1112 | } |
| | 1113 | } |
| | 1114 | }, |
| | 1115 | |
| | 1116 | layoutItem: function(item_h){ |
| | 1117 | |
| | 1118 | var label_w = dojo.style.getOuterWidth(this.labelNode); |
| | 1119 | |
| | 1120 | var clientLeft = dojo.style.getPixelValue(this.domNode, "padding-left", true); |
| | 1121 | var clientTop = dojo.style.getPixelValue(this.domNode, "padding-top", true); |
| | 1122 | |
| | 1123 | this.labelNode.style.left = clientLeft + 'px'; |
| | 1124 | |
| | 1125 | dojo.style.setOuterHeight(this.labelNode, item_h); |
| | 1126 | dojo.style.setContentWidth(this.domNode, label_w); |
| | 1127 | dojo.style.setContentHeight(this.domNode, item_h); |
| | 1128 | |
| | 1129 | this.labelNode.style.left = '0px'; |
| | 1130 | |
| | 1131 | dojo.style.setOuterWidth(this.targetNode, label_w); |
| | 1132 | dojo.style.setOuterHeight(this.targetNode, item_h); |
| | 1133 | }, |
| | 1134 | |
| | 1135 | getLabelHeight: function(){ |
| | 1136 | |
| | 1137 | return dojo.style.getOuterHeight(this.labelNode); |
| | 1138 | }, |
| | 1139 | |
| | 1140 | onHover: function(){ |
| | 1141 | this.parent.itemHover(this); |
| | 1142 | }, |
| | 1143 | |
| | 1144 | onUnhover: function(){ |
| | 1145 | this.parent.itemUnhover(this); |
| | 1146 | }, |
| | 1147 | |
| | 1148 | _onClick: function(){ |
| | 1149 | this.parent.itemClick(this); |
| | 1150 | }, |
| | 1151 | |
| | 1152 | highlightItem: function(){ |
| | 1153 | dojo.html.addClass(this.domNode, 'dojoMenuBarItem2Hover'); |
| | 1154 | }, |
| | 1155 | |
| | 1156 | unhighlightItem: function(){ |
| | 1157 | dojo.html.removeClass(this.domNode, 'dojoMenuBarItem2Hover'); |
| | 1158 | }, |
| | 1159 | |
| | 1160 | expandMenu: function(){ |
| | 1161 | |
| | 1162 | var submenu = dojo.widget.getWidgetById(this.submenuId); |
| | 1163 | if (submenu){ |
| | 1164 | |
| | 1165 | this.parent.openSubmenu(submenu, this); |
| | 1166 | } |
| | 1167 | }, |
| | 1168 | |
| | 1169 | setDisabled: function(value){ |
| | 1170 | this.disabled = value; |
| | 1171 | |
| | 1172 | if (this.disabled){ |
| | 1173 | dojo.html.addClass(this.domNode, 'dojoMenuBarItem2Disabled'); |
| | 1174 | }else{ |
| | 1175 | dojo.html.removeClass(this.domNode, 'dojoMenuBarItem2Disabled'); |
| | 1176 | } |
| | 1177 | } |
| | 1178 | }); |
| | 1179 | |