app.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. *构建SDAPP
  3. */
  4. SDAPP = (function () {
  5. function App(options) {
  6. this.O = options;
  7. this.J = jQuery;
  8. this.init();
  9. }
  10. return App;
  11. })();
  12. SDAPP.prototype.init = function () {
  13. this.client();
  14. this.plugin();
  15. this.renew();
  16. }
  17. /**
  18. * getClient
  19. */
  20. SDAPP.prototype.client = function () {
  21. return {
  22. "width": this.J(window).width(),
  23. "height": this.J(window).height()
  24. };
  25. }
  26. /**
  27. * resize
  28. */
  29. SDAPP.prototype.renew = function () {
  30. var _this = this;
  31. _this.J(window).resize(function (event) {
  32. _this.client();
  33. // window.console && console.log(_this.client().width, _this.client().height);
  34. });
  35. }
  36. /**
  37. * plugin
  38. */
  39. SDAPP.prototype.plugin = function () {
  40. var _this = this;
  41. // focus
  42. // this.O['focus'] && this.J("[data-focus]").sudyfocus(this.O['focus']);
  43. // menu
  44. if (this.client().width > 1280) {
  45. /*增加*/
  46. this.J(".wp-navi").find(".menu-item").on("mouseenter", function () {
  47. _this.J(this).addClass("hover");
  48. _this.J(this).children('.sub-menu').show();
  49. }).on("mouseleave", function () {
  50. _this.J(this).removeClass("hover");
  51. _this.J(this).children('.sub-menu').hide();
  52. });
  53. }
  54. this.J(".column_title_box").on("click", function (event) {
  55. event.preventDefault();
  56. _this.J(".column_title_box .arrow").toggleClass("up")
  57. _this.J(".page_tab_list").slideToggle(200);
  58. });
  59. this.J(".page_tab_list .page_list_item.selected").find(".sub_item_link ").eq(0).addClass("selected")
  60. var $aside = this.J("#wp-navi-aside");
  61. var sideWrap = $aside.find(".navi-aside-wrap");
  62. var menuDom = this.J(".header_menu .wp-menu").clone()
  63. sideWrap.append(menuDom)
  64. this.J(".menu-switch-arrow", ".wp-navi-aside").on("click", function () {
  65. _this.J(this).toggleClass('open').siblings(".sub-menu").slideToggle(250);
  66. });
  67. this.J(".mobile_menu_taggle").on("click", function () {
  68. _this.J(".wp-navi-aside").show()
  69. _this.J(".wp-navi-aside .aside-inner").stop().animate({ right: 0 }, 250);
  70. });
  71. this.J(".navi-aside-mask").on("click", function (event) {
  72. event.preventDefault();
  73. _this.J(".wp-navi-aside .aside-inner").stop().animate({ right: "-200px" }, 250, function () {
  74. _this.J(".wp-navi-aside").hide();
  75. });
  76. });
  77. this.J(window).scroll(function (event) {
  78. var scrolltop = _this.J(window).scrollTop();
  79. if (scrolltop > 500) {
  80. _this.J("#gotop").show();
  81. } else {
  82. _this.J("#gotop").hide();
  83. }
  84. });
  85. this.J("#gotop").on("click", function () {
  86. _this.J("body,html").stop().animate({ scrollTop: 0 }, 500);
  87. });
  88. $(".search-submit").click(function (event) {
  89. $(this).removeAttr("name");
  90. event.preventDefault();
  91. var val = $.trim($(".search-input input").val());
  92. if (val !== "") {
  93. $(".wp-search").find("form").submit();
  94. } else {
  95. alert("请输入关键词");
  96. }
  97. return false;
  98. });
  99. $(".search_icon").click(function () {
  100. $(".search_box .wp-search").stop().animate({ top: "0", opacity: 1 }, 200)
  101. })
  102. $(".close_icon").click(function () {
  103. $(".search_box .wp-search").stop().animate({ top: "-100%", opacity: 0 }, 200)
  104. })
  105. }