You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

201 lines
4.7 KiB

  1. // Menu Bar
  2. function MenuToolbar(parent) {
  3. this.ul = $a(parent, 'ul', 'menu_toolbar');
  4. this.cur_top_menu = null;
  5. this.max_rows = 10;
  6. this.dropdown_width = '280px';
  7. this.top_menus = {};
  8. this.top_menu_style = 'top_menu';
  9. this.top_menu_mo_style = 'top_menu_mo';
  10. this.top_menu_icon_style = 'top_menu_icon';
  11. }
  12. MenuToolbar.prototype.add_top_menu = function(label, onclick, add_icon) {
  13. var li = $a(this.ul, 'li');
  14. li.item = new MenuToolbarItem(this, li, label, onclick, add_icon);
  15. this.top_menus[label] = li.item.wrapper;
  16. return li.item.wrapper;
  17. }
  18. function MenuToolbarItem(tbar, parent, label, onclick, add_icon) {
  19. var me = this;
  20. this.wrapper = $a(parent, 'div', tbar.top_menu_style);
  21. // add icon
  22. if(add_icon) {
  23. var t = make_table(this.wrapper, 1, 2, null, ['22px', null], {verticalAlign:'middle'});
  24. $y(t,{borderCollapse:'collapse'});
  25. var icon = $a($td(t,0,0), 'div', 'wntoolbar-icon ' + add_icon);
  26. $td(t,0,1).innerHTML = label;
  27. } else {
  28. this.wrapper.innerHTML = label;
  29. }
  30. this.wrapper.onclick = function() { onclick(); };
  31. this.def_class = tbar.top_menu_style;
  32. // mouseovers
  33. this.wrapper.onmouseover = function() {
  34. this.set_selected();
  35. if(this.my_mouseover)this.my_mouseover(this);
  36. }
  37. this.wrapper.onmouseout = function() {
  38. if(this.my_mouseout)
  39. this.my_mouseout(this);
  40. this.set_unselected();
  41. }
  42. // select / unselect
  43. this.wrapper.set_unselected = function() {
  44. if(me.wrapper.dropdown && me.wrapper.dropdown.is_active) {
  45. return;
  46. }
  47. me.wrapper.className = me.def_class;
  48. }
  49. this.wrapper.set_selected = function() {
  50. if(me.cur_top_menu)
  51. me.cur_top_menu.set_unselected();
  52. me.wrapper.className = me.def_class + ' '+tbar.top_menu_mo_style;
  53. me.cur_top_menu = this;
  54. }
  55. }
  56. var closetimer;
  57. function mclose(opt) { // close all active
  58. for(var i=0;i<all_dropdowns.length;i++) {
  59. if(all_dropdowns[i].is_active)
  60. if(opt && opt==all_dropdowns[i]) { /* don't hide caller */ }
  61. else all_dropdowns[i].hide();
  62. }
  63. }
  64. function mclosetime() { closetimer = window.setTimeout(mclose, 700); }
  65. function mcancelclosetime() { if(closetimer) { window.clearTimeout(closetimer); closetimer = null; } }
  66. MenuToolbar.prototype.make_dropdown = function(tm) {
  67. var me = this;
  68. tm.dropdown = new DropdownMenu(tm, this.dropdown_width);
  69. // triggers on top menu
  70. tm.my_mouseover = function() {
  71. this.dropdown.show();
  72. }
  73. tm.my_mouseout = function() {
  74. this.dropdown.clear();
  75. }
  76. }
  77. MenuToolbar.prototype.add_item = function(top_menu_label, label, onclick, on_top) {
  78. var me = this;
  79. var tm = this.top_menus[top_menu_label];
  80. if(!tm.dropdown)
  81. this.make_dropdown(tm, this.dropdown_width);
  82. return tm.dropdown.add_item(label, onclick, on_top);
  83. }
  84. var all_dropdowns = []; var cur_dropdown;
  85. function DropdownMenu(parent, width) {
  86. this.body = $a(parent, 'div', 'menu_toolbar_dropdown', {width:(width ? width : '140px'), display:'none'});
  87. this.parent = parent;
  88. this.items = {};
  89. this.item_style = 'dd_item';
  90. this.item_mo_style = 'dd_item_mo';
  91. this.list = [];
  92. this.max_height = 400;
  93. this.keypressdelta = 500;
  94. var me = this;
  95. this.body.onmouseout = function() { me.clear(); }
  96. this.body.onmouseover = function() {
  97. mcancelclosetime();
  98. } // re-entered
  99. this.clear_user_inp = function() { me.user_inp = '';}
  100. this.show = function() {
  101. // close others
  102. mclose(me);
  103. // clear menu timeout
  104. mcancelclosetime();
  105. hide_selects();
  106. me.is_active = 1;
  107. $ds(me.body); // show
  108. if(cint(me.body.clientHeight) >= me.max_height) {
  109. $y(me.body, {height:me.max_height + 'px'});
  110. me.scrollbars = 1;
  111. } else {
  112. $y(me.body, {height:null});
  113. me.scrollbars = 0;
  114. }
  115. }
  116. this.hide = function() {
  117. $dh(me.body);
  118. //$dh(me.body); // hide
  119. if(!frozen)show_selects();
  120. // clear from active list
  121. me.is_active = 0;
  122. // events on label
  123. if(me.parent && me.parent.set_unselected) {
  124. me.parent.set_unselected();
  125. }
  126. }
  127. this.clear = function() {
  128. mcancelclosetime();
  129. mclosetime();
  130. }
  131. all_dropdowns.push(me);
  132. }
  133. DropdownMenu.prototype.add_item = function(label, onclick, on_top) {
  134. var me = this;
  135. if(on_top) {
  136. var mi = document.createElement('div');
  137. me.body.insertBefore(mi, me.body.firstChild);
  138. mi.className = this.item_style;
  139. } else {
  140. var mi = $a(this.body, 'div', this.item_style);
  141. }
  142. mi.innerHTML = label;
  143. mi.label = label;
  144. mi.my_onclick = onclick;
  145. mi.onclick = function() { mclose(); this.my_onclick(); };
  146. mi.highlight = function() {
  147. if(me.cur_mi) me.cur_mi.clear();
  148. this.className = me.item_style + ' ' + me.item_mo_style;
  149. me.cur_mi=this;
  150. }
  151. mi.clear = function() {
  152. this.className = me.item_style;
  153. }
  154. mi.onmouseover = mi.highlight;
  155. mi.onmouseout = mi.clear;
  156. mi.bring_to_top = function() { me.body.insertBefore(this, me.body.firstChild); }
  157. //var k=0, e=mi;
  158. //while (e = e.previousSibling) { ++k;}
  159. //mi.idx = k;
  160. return mi;
  161. }