dwz.switchEnv.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @author zhanghuihua@msn.com
  3. */
  4. (function($){
  5. $.fn.navMenu = function(){
  6. return this.each(function(){
  7. var $box = $(this);
  8. $box.find("li>a").click(function(){
  9. var $a = $(this);
  10. $.post($a.attr("href"), {}, function(html){
  11. $("#sidebar").find(".accordion").remove().end().append(html).initUI();
  12. $box.find("li").removeClass("selected");
  13. $a.parent().addClass("selected");
  14. navTab.closeAllTab();
  15. });
  16. return false;
  17. });
  18. });
  19. }
  20. $.fn.switchEnv = function(){
  21. var op = {cities$:">ul>li", boxTitle$:">a>span"};
  22. return this.each(function(){
  23. var $this = $(this);
  24. $this.click(function(){
  25. if ($this.hasClass("selected")){
  26. _hide($this);
  27. } else {
  28. _show($this);
  29. }
  30. return false;
  31. });
  32. $this.find(op.cities$).click(function(){
  33. var $li = $(this);
  34. $.post($li.find(">a").attr("href"), {}, function(html){
  35. _hide($this);
  36. $this.find(op.boxTitle$).html($li.find(">a").html());
  37. navTab.closeAllTab();
  38. $("#sidebar").find(".accordion").remove().end().append(html).initUI();
  39. });
  40. return false;
  41. });
  42. });
  43. }
  44. function _show($box){
  45. $box.addClass("selected");
  46. $(document).bind("click",{box:$box}, _handler);
  47. }
  48. function _hide($box){
  49. $box.removeClass("selected");
  50. $(document).unbind("click", _handler);
  51. }
  52. function _handler(event){
  53. _hide(event.data.box);
  54. }
  55. })(jQuery);