jquery.menu.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /**
  2. * jQuery EasyUI 1.3.6
  3. *
  4. * Copyright (c) 2009-2014 www.jeasyui.com. All rights reserved.
  5. *
  6. * Licensed under the GPL license: http://www.gnu.org/licenses/gpl.txt
  7. * To use it on other terms please contact us at info@jeasyui.com
  8. *
  9. */
  10. (function($){
  11. function _1(_2){
  12. $(_2).appendTo("body");
  13. $(_2).addClass("menu-top");
  14. $(document).unbind(".menu").bind("mousedown.menu",function(e){
  15. var m=$(e.target).closest("div.menu,div.combo-p");
  16. if(m.length){
  17. return;
  18. }
  19. $("body>div.menu-top:visible").menu("hide");
  20. });
  21. var _3=_4($(_2));
  22. for(var i=0;i<_3.length;i++){
  23. _5(_3[i]);
  24. }
  25. function _4(_6){
  26. var _7=[];
  27. _6.addClass("menu");
  28. _7.push(_6);
  29. if(!_6.hasClass("menu-content")){
  30. _6.children("div").each(function(){
  31. var _8=$(this).children("div");
  32. if(_8.length){
  33. _8.insertAfter(_2);
  34. this.submenu=_8;
  35. var mm=_4(_8);
  36. _7=_7.concat(mm);
  37. }
  38. });
  39. }
  40. return _7;
  41. };
  42. function _5(_9){
  43. var wh=$.parser.parseOptions(_9[0],["width","height"]);
  44. _9[0].originalHeight=wh.height||0;
  45. if(_9.hasClass("menu-content")){
  46. _9[0].originalWidth=wh.width||_9._outerWidth();
  47. }else{
  48. _9[0].originalWidth=wh.width||0;
  49. _9.children("div").each(function(){
  50. var _a=$(this);
  51. var _b=$.extend({},$.parser.parseOptions(this,["name","iconCls","href",{separator:"boolean"}]),{disabled:(_a.attr("disabled")?true:undefined)});
  52. if(_b.separator){
  53. _a.addClass("menu-sep");
  54. }
  55. if(!_a.hasClass("menu-sep")){
  56. _a[0].itemName=_b.name||"";
  57. _a[0].itemHref=_b.href||"";
  58. var _c=_a.addClass("menu-item").html();
  59. _a.empty().append($("<div class=\"menu-text\"></div>").html(_c));
  60. if(_b.iconCls){
  61. $("<div class=\"menu-icon\"></div>").addClass(_b.iconCls).appendTo(_a);
  62. }
  63. if(_b.disabled){
  64. _d(_2,_a[0],true);
  65. }
  66. if(_a[0].submenu){
  67. $("<div class=\"menu-rightarrow\"></div>").appendTo(_a);
  68. }
  69. _e(_2,_a);
  70. }
  71. });
  72. $("<div class=\"menu-line\"></div>").prependTo(_9);
  73. }
  74. _f(_2,_9);
  75. _9.hide();
  76. _10(_2,_9);
  77. };
  78. };
  79. function _f(_11,_12){
  80. var _13=$.data(_11,"menu").options;
  81. var _14=_12.attr("style")||"";
  82. _12.css({display:"block",left:-10000,height:"auto",overflow:"hidden"});
  83. var el=_12[0];
  84. var _15=el.originalWidth||0;
  85. if(!_15){
  86. _15=0;
  87. _12.find("div.menu-text").each(function(){
  88. if(_15<$(this)._outerWidth()){
  89. _15=$(this)._outerWidth();
  90. }
  91. $(this).closest("div.menu-item")._outerHeight($(this)._outerHeight()+2);
  92. });
  93. _15+=40;
  94. }
  95. _15=Math.max(_15,_13.minWidth);
  96. var _16=el.originalHeight||_12.outerHeight();
  97. var _17=Math.max(el.originalHeight,_12.outerHeight())-2;
  98. _12._outerWidth(_15)._outerHeight(_16);
  99. _12.children("div.menu-line")._outerHeight(_17);
  100. _14+=";width:"+el.style.width+";height:"+el.style.height;
  101. _12.attr("style",_14);
  102. };
  103. function _10(_18,_19){
  104. var _1a=$.data(_18,"menu");
  105. _19.unbind(".menu").bind("mouseenter.menu",function(){
  106. if(_1a.timer){
  107. clearTimeout(_1a.timer);
  108. _1a.timer=null;
  109. }
  110. }).bind("mouseleave.menu",function(){
  111. if(_1a.options.hideOnUnhover){
  112. _1a.timer=setTimeout(function(){
  113. _1b(_18);
  114. },100);
  115. }
  116. });
  117. };
  118. function _e(_1c,_1d){
  119. if(!_1d.hasClass("menu-item")){
  120. return;
  121. }
  122. _1d.unbind(".menu");
  123. _1d.bind("click.menu",function(){
  124. if($(this).hasClass("menu-item-disabled")){
  125. return;
  126. }
  127. if(!this.submenu){
  128. _1b(_1c);
  129. var _1e=$(this).attr("href");
  130. if(_1e){
  131. location.href=_1e;
  132. }
  133. }
  134. var _1f=$(_1c).menu("getItem",this);
  135. $.data(_1c,"menu").options.onClick.call(_1c,_1f);
  136. }).bind("mouseenter.menu",function(e){
  137. _1d.siblings().each(function(){
  138. if(this.submenu){
  139. _22(this.submenu);
  140. }
  141. $(this).removeClass("menu-active");
  142. });
  143. _1d.addClass("menu-active");
  144. if($(this).hasClass("menu-item-disabled")){
  145. _1d.addClass("menu-active-disabled");
  146. return;
  147. }
  148. var _20=_1d[0].submenu;
  149. if(_20){
  150. $(_1c).menu("show",{menu:_20,parent:_1d});
  151. }
  152. }).bind("mouseleave.menu",function(e){
  153. _1d.removeClass("menu-active menu-active-disabled");
  154. var _21=_1d[0].submenu;
  155. if(_21){
  156. if(e.pageX>=parseInt(_21.css("left"))){
  157. _1d.addClass("menu-active");
  158. }else{
  159. _22(_21);
  160. }
  161. }else{
  162. _1d.removeClass("menu-active");
  163. }
  164. });
  165. };
  166. function _1b(_23){
  167. var _24=$.data(_23,"menu");
  168. if(_24){
  169. if($(_23).is(":visible")){
  170. _22($(_23));
  171. _24.options.onHide.call(_23);
  172. }
  173. }
  174. return false;
  175. };
  176. function _25(_26,_27){
  177. var _28,top;
  178. _27=_27||{};
  179. var _29=$(_27.menu||_26);
  180. if(_29.hasClass("menu-top")){
  181. var _2a=$.data(_26,"menu").options;
  182. $.extend(_2a,_27);
  183. _28=_2a.left;
  184. top=_2a.top;
  185. if(_2a.alignTo){
  186. var at=$(_2a.alignTo);
  187. _28=at.offset().left;
  188. top=at.offset().top+at._outerHeight();
  189. if(_2a.align=="right"){
  190. _28+=at.outerWidth()-_29.outerWidth();
  191. }
  192. }
  193. if(_28+_29.outerWidth()>$(window)._outerWidth()+$(document)._scrollLeft()){
  194. _28=$(window)._outerWidth()+$(document).scrollLeft()-_29.outerWidth()-5;
  195. }
  196. if(_28<0){
  197. _28=0;
  198. }
  199. if(top+_29.outerHeight()>$(window)._outerHeight()+$(document).scrollTop()){
  200. top=$(window)._outerHeight()+$(document).scrollTop()-_29.outerHeight()-5;
  201. }
  202. }else{
  203. var _2b=_27.parent;
  204. _28=_2b.offset().left+_2b.outerWidth()-2;
  205. if(_28+_29.outerWidth()+5>$(window)._outerWidth()+$(document).scrollLeft()){
  206. _28=_2b.offset().left-_29.outerWidth()+2;
  207. }
  208. var top=_2b.offset().top-3;
  209. if(top+_29.outerHeight()>$(window)._outerHeight()+$(document).scrollTop()){
  210. top=$(window)._outerHeight()+$(document).scrollTop()-_29.outerHeight()-5;
  211. }
  212. }
  213. _29.css({left:_28,top:top});
  214. _29.show(0,function(){
  215. if(!_29[0].shadow){
  216. _29[0].shadow=$("<div class=\"menu-shadow\"></div>").insertAfter(_29);
  217. }
  218. _29[0].shadow.css({display:"block",zIndex:$.fn.menu.defaults.zIndex++,left:_29.css("left"),top:_29.css("top"),width:_29.outerWidth(),height:_29.outerHeight()});
  219. _29.css("z-index",$.fn.menu.defaults.zIndex++);
  220. if(_29.hasClass("menu-top")){
  221. $.data(_29[0],"menu").options.onShow.call(_29[0]);
  222. }
  223. });
  224. };
  225. function _22(_2c){
  226. if(!_2c){
  227. return;
  228. }
  229. _2d(_2c);
  230. _2c.find("div.menu-item").each(function(){
  231. if(this.submenu){
  232. _22(this.submenu);
  233. }
  234. $(this).removeClass("menu-active");
  235. });
  236. function _2d(m){
  237. m.stop(true,true);
  238. if(m[0].shadow){
  239. m[0].shadow.hide();
  240. }
  241. m.hide();
  242. };
  243. };
  244. function _2e(_2f,_30){
  245. var _31=null;
  246. var tmp=$("<div></div>");
  247. function _32(_33){
  248. _33.children("div.menu-item").each(function(){
  249. var _34=$(_2f).menu("getItem",this);
  250. var s=tmp.empty().html(_34.text).text();
  251. if(_30==$.trim(s)){
  252. _31=_34;
  253. }else{
  254. if(this.submenu&&!_31){
  255. _32(this.submenu);
  256. }
  257. }
  258. });
  259. };
  260. _32($(_2f));
  261. tmp.remove();
  262. return _31;
  263. };
  264. function _d(_35,_36,_37){
  265. var t=$(_36);
  266. if(!t.hasClass("menu-item")){
  267. return;
  268. }
  269. if(_37){
  270. t.addClass("menu-item-disabled");
  271. if(_36.onclick){
  272. _36.onclick1=_36.onclick;
  273. _36.onclick=null;
  274. }
  275. }else{
  276. t.removeClass("menu-item-disabled");
  277. if(_36.onclick1){
  278. _36.onclick=_36.onclick1;
  279. _36.onclick1=null;
  280. }
  281. }
  282. };
  283. function _38(_39,_3a){
  284. var _3b=$(_39);
  285. if(_3a.parent){
  286. if(!_3a.parent.submenu){
  287. var _3c=$("<div class=\"menu\"><div class=\"menu-line\"></div></div>").appendTo("body");
  288. _3c.hide();
  289. _3a.parent.submenu=_3c;
  290. $("<div class=\"menu-rightarrow\"></div>").appendTo(_3a.parent);
  291. }
  292. _3b=_3a.parent.submenu;
  293. }
  294. if(_3a.separator){
  295. var _3d=$("<div class=\"menu-sep\"></div>").appendTo(_3b);
  296. }else{
  297. var _3d=$("<div class=\"menu-item\"></div>").appendTo(_3b);
  298. $("<div class=\"menu-text\"></div>").html(_3a.text).appendTo(_3d);
  299. }
  300. if(_3a.iconCls){
  301. $("<div class=\"menu-icon\"></div>").addClass(_3a.iconCls).appendTo(_3d);
  302. }
  303. if(_3a.id){
  304. _3d.attr("id",_3a.id);
  305. }
  306. if(_3a.name){
  307. _3d[0].itemName=_3a.name;
  308. }
  309. if(_3a.href){
  310. _3d[0].itemHref=_3a.href;
  311. }
  312. if(_3a.onclick){
  313. if(typeof _3a.onclick=="string"){
  314. _3d.attr("onclick",_3a.onclick);
  315. }else{
  316. _3d[0].onclick=eval(_3a.onclick);
  317. }
  318. }
  319. if(_3a.handler){
  320. _3d[0].onclick=eval(_3a.handler);
  321. }
  322. if(_3a.disabled){
  323. _d(_39,_3d[0],true);
  324. }
  325. _e(_39,_3d);
  326. _10(_39,_3b);
  327. _f(_39,_3b);
  328. };
  329. function _3e(_3f,_40){
  330. function _41(el){
  331. if(el.submenu){
  332. el.submenu.children("div.menu-item").each(function(){
  333. _41(this);
  334. });
  335. var _42=el.submenu[0].shadow;
  336. if(_42){
  337. _42.remove();
  338. }
  339. el.submenu.remove();
  340. }
  341. $(el).remove();
  342. };
  343. _41(_40);
  344. };
  345. function _43(_44){
  346. $(_44).children("div.menu-item").each(function(){
  347. _3e(_44,this);
  348. });
  349. if(_44.shadow){
  350. _44.shadow.remove();
  351. }
  352. $(_44).remove();
  353. };
  354. $.fn.menu=function(_45,_46){
  355. if(typeof _45=="string"){
  356. return $.fn.menu.methods[_45](this,_46);
  357. }
  358. _45=_45||{};
  359. return this.each(function(){
  360. var _47=$.data(this,"menu");
  361. if(_47){
  362. $.extend(_47.options,_45);
  363. }else{
  364. _47=$.data(this,"menu",{options:$.extend({},$.fn.menu.defaults,$.fn.menu.parseOptions(this),_45)});
  365. _1(this);
  366. }
  367. $(this).css({left:_47.options.left,top:_47.options.top});
  368. });
  369. };
  370. $.fn.menu.methods={options:function(jq){
  371. return $.data(jq[0],"menu").options;
  372. },show:function(jq,pos){
  373. return jq.each(function(){
  374. _25(this,pos);
  375. });
  376. },hide:function(jq){
  377. return jq.each(function(){
  378. _1b(this);
  379. });
  380. },destroy:function(jq){
  381. return jq.each(function(){
  382. _43(this);
  383. });
  384. },setText:function(jq,_48){
  385. return jq.each(function(){
  386. $(_48.target).children("div.menu-text").html(_48.text);
  387. });
  388. },setIcon:function(jq,_49){
  389. return jq.each(function(){
  390. $(_49.target).children("div.menu-icon").remove();
  391. if(_49.iconCls){
  392. $("<div class=\"menu-icon\"></div>").addClass(_49.iconCls).appendTo(_49.target);
  393. }
  394. });
  395. },getItem:function(jq,_4a){
  396. var t=$(_4a);
  397. var _4b={target:_4a,id:t.attr("id"),text:$.trim(t.children("div.menu-text").html()),disabled:t.hasClass("menu-item-disabled"),name:_4a.itemName,href:_4a.itemHref,onclick:_4a.onclick};
  398. var _4c=t.children("div.menu-icon");
  399. if(_4c.length){
  400. var cc=[];
  401. var aa=_4c.attr("class").split(" ");
  402. for(var i=0;i<aa.length;i++){
  403. if(aa[i]!="menu-icon"){
  404. cc.push(aa[i]);
  405. }
  406. }
  407. _4b.iconCls=cc.join(" ");
  408. }
  409. return _4b;
  410. },findItem:function(jq,_4d){
  411. return _2e(jq[0],_4d);
  412. },appendItem:function(jq,_4e){
  413. return jq.each(function(){
  414. _38(this,_4e);
  415. });
  416. },removeItem:function(jq,_4f){
  417. return jq.each(function(){
  418. _3e(this,_4f);
  419. });
  420. },enableItem:function(jq,_50){
  421. return jq.each(function(){
  422. _d(this,_50,false);
  423. });
  424. },disableItem:function(jq,_51){
  425. return jq.each(function(){
  426. _d(this,_51,true);
  427. });
  428. }};
  429. $.fn.menu.parseOptions=function(_52){
  430. return $.extend({},$.parser.parseOptions(_52,["left","top",{minWidth:"number",hideOnUnhover:"boolean"}]));
  431. };
  432. $.fn.menu.defaults={zIndex:110000,left:0,top:0,alignTo:null,align:"left",minWidth:120,hideOnUnhover:true,onShow:function(){
  433. },onHide:function(){
  434. },onClick:function(_53){
  435. }};
  436. })(jQuery);