hplus.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. //自定义js
  2. //公共配置
  3. $(document).ready(function () {
  4. // MetsiMenu
  5. $('#side-menu').metisMenu();
  6. // 打开右侧边栏
  7. $('.right-sidebar-toggle').click(function () {
  8. $('#right-sidebar').toggleClass('sidebar-open');
  9. });
  10. // 右侧边栏使用slimscroll
  11. $('.sidebar-container').slimScroll({
  12. height: '100%',
  13. railOpacity: 0.4,
  14. wheelStep: 10
  15. });
  16. // 打开聊天窗口
  17. $('.open-small-chat').click(function () {
  18. $(this).children().toggleClass('fa-comments').toggleClass('fa-remove');
  19. $('.small-chat-box').toggleClass('active');
  20. });
  21. // 聊天窗口使用slimscroll
  22. $('.small-chat-box .content').slimScroll({
  23. height: '234px',
  24. railOpacity: 0.4
  25. });
  26. // Small todo handler
  27. $('.check-link').click(function () {
  28. var button = $(this).find('i');
  29. var label = $(this).next('span');
  30. button.toggleClass('fa-check-square').toggleClass('fa-square-o');
  31. label.toggleClass('todo-completed');
  32. return false;
  33. });
  34. //固定菜单栏
  35. $(function () {
  36. $('.sidebar-collapse').slimScroll({
  37. height: '100%',
  38. railOpacity: 0.9,
  39. alwaysVisible: false
  40. });
  41. });
  42. // 菜单切换
  43. $('.navbar-minimalize').click(function () {
  44. $("body").toggleClass("mini-navbar");
  45. SmoothlyMenu();
  46. });
  47. // 侧边栏高度
  48. function fix_height() {
  49. var heightWithoutNavbar = $("body > #wrapper").height() - 61;
  50. $(".sidebard-panel").css("min-height", heightWithoutNavbar + "px");
  51. }
  52. fix_height();
  53. $(window).bind("load resize click scroll", function () {
  54. if (!$("body").hasClass('body-small')) {
  55. fix_height();
  56. }
  57. });
  58. //侧边栏滚动
  59. $(window).scroll(function () {
  60. if ($(window).scrollTop() > 0 && !$('body').hasClass('fixed-nav')) {
  61. $('#right-sidebar').addClass('sidebar-top');
  62. } else {
  63. $('#right-sidebar').removeClass('sidebar-top');
  64. }
  65. });
  66. $('.full-height-scroll').slimScroll({
  67. height: '100%'
  68. });
  69. $('#side-menu>li').click(function () {
  70. if ($('body').hasClass('mini-navbar')) {
  71. NavToggle();
  72. }
  73. });
  74. $('#side-menu>li li a').click(function () {
  75. if ($(window).width() < 769) {
  76. NavToggle();
  77. }
  78. });
  79. //点击菜单的时候高亮显示菜单
  80. $("a[name='tabMenuItem']").click(function(){
  81. clearTabMenuItem();
  82. $(this).addClass("tab-menu-selected");
  83. });
  84. $('.nav-close').click(NavToggle);
  85. //ios浏览器兼容性处理
  86. if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
  87. $('#content-main').css('overflow-y', 'auto');
  88. }
  89. });
  90. $(window).bind("load resize", function () {
  91. if ($(this).width() < 769) {
  92. $('body').addClass('mini-navbar');
  93. $('.navbar-static-side').fadeIn();
  94. }
  95. });
  96. function clearTabMenuItem(){
  97. $("a[name='tabMenuItem']").each(function(){
  98. $(this).removeClass("tab-menu-selected");
  99. });
  100. }
  101. function highLightMenuItem(hrefVal){
  102. clearTabMenuItem();
  103. $("a[href='" + hrefVal + "']").addClass("tab-menu-selected");
  104. }
  105. function NavToggle() {
  106. $('.navbar-minimalize').trigger('click');
  107. }
  108. function SmoothlyMenu() {
  109. if (!$('body').hasClass('mini-navbar')) {
  110. $('#side-menu').hide();
  111. setTimeout(
  112. function () {
  113. $('#side-menu').fadeIn(500);
  114. }, 100);
  115. } else if ($('body').hasClass('fixed-sidebar')) {
  116. $('#side-menu').hide();
  117. setTimeout(
  118. function () {
  119. $('#side-menu').fadeIn(500);
  120. }, 300);
  121. } else {
  122. $('#side-menu').removeAttr('style');
  123. }
  124. }
  125. //主题设置
  126. $(function () {
  127. // 顶部菜单固定
  128. $('#fixednavbar').click(function () {
  129. if ($('#fixednavbar').is(':checked')) {
  130. $(".navbar-static-top").removeClass('navbar-static-top').addClass('navbar-fixed-top');
  131. $("body").removeClass('boxed-layout');
  132. $("body").addClass('fixed-nav');
  133. $('#boxedlayout').prop('checked', false);
  134. if (localStorageSupport) {
  135. localStorage.setItem("boxedlayout", 'off');
  136. }
  137. if (localStorageSupport) {
  138. localStorage.setItem("fixednavbar", 'on');
  139. }
  140. } else {
  141. $(".navbar-fixed-top").removeClass('navbar-fixed-top').addClass('navbar-static-top');
  142. $("body").removeClass('fixed-nav');
  143. if (localStorageSupport) {
  144. localStorage.setItem("fixednavbar", 'off');
  145. }
  146. }
  147. });
  148. // 收起左侧菜单
  149. $('#collapsemenu').click(function () {
  150. if ($('#collapsemenu').is(':checked')) {
  151. $("body").addClass('mini-navbar');
  152. SmoothlyMenu();
  153. if (localStorageSupport) {
  154. localStorage.setItem("collapse_menu", 'on');
  155. }
  156. } else {
  157. $("body").removeClass('mini-navbar');
  158. SmoothlyMenu();
  159. if (localStorageSupport) {
  160. localStorage.setItem("collapse_menu", 'off');
  161. }
  162. }
  163. });
  164. // 固定宽度
  165. $('#boxedlayout').click(function () {
  166. if ($('#boxedlayout').is(':checked')) {
  167. $("body").addClass('boxed-layout');
  168. $('#fixednavbar').prop('checked', false);
  169. $(".navbar-fixed-top").removeClass('navbar-fixed-top').addClass('navbar-static-top');
  170. $("body").removeClass('fixed-nav');
  171. if (localStorageSupport) {
  172. localStorage.setItem("fixednavbar", 'off');
  173. }
  174. if (localStorageSupport) {
  175. localStorage.setItem("boxedlayout", 'on');
  176. }
  177. } else {
  178. $("body").removeClass('boxed-layout');
  179. if (localStorageSupport) {
  180. localStorage.setItem("boxedlayout", 'off');
  181. }
  182. }
  183. });
  184. // 默认主题
  185. $('.s-skin-0').click(function () {
  186. $("body").removeClass("skin-1");
  187. $("body").removeClass("skin-2");
  188. $("body").removeClass("skin-3");
  189. return false;
  190. });
  191. // 蓝色主题
  192. $('.s-skin-1').click(function () {
  193. $("body").removeClass("skin-2");
  194. $("body").removeClass("skin-3");
  195. $("body").addClass("skin-4");
  196. return false;
  197. });
  198. // 黄色主题
  199. $('.s-skin-3').click(function () {
  200. $("body").removeClass("skin-1");
  201. $("body").removeClass("skin-2");
  202. $("body").addClass("skin-3");
  203. return false;
  204. });
  205. if (localStorageSupport) {
  206. var collapse = localStorage.getItem("collapse_menu");
  207. var fixednavbar = localStorage.getItem("fixednavbar");
  208. var boxedlayout = localStorage.getItem("boxedlayout");
  209. if (collapse == 'on') {
  210. $('#collapsemenu').prop('checked', 'checked')
  211. }
  212. if (fixednavbar == 'on') {
  213. $('#fixednavbar').prop('checked', 'checked')
  214. }
  215. if (boxedlayout == 'on') {
  216. $('#boxedlayout').prop('checked', 'checked')
  217. }
  218. }
  219. if (localStorageSupport) {
  220. var collapse = localStorage.getItem("collapse_menu");
  221. var fixednavbar = localStorage.getItem("fixednavbar");
  222. var boxedlayout = localStorage.getItem("boxedlayout");
  223. var body = $('body');
  224. if (collapse == 'on') {
  225. if (!body.hasClass('body-small')) {
  226. body.addClass('mini-navbar');
  227. }
  228. }
  229. if (fixednavbar == 'on') {
  230. $(".navbar-static-top").removeClass('navbar-static-top').addClass('navbar-fixed-top');
  231. body.addClass('fixed-nav');
  232. }
  233. if (boxedlayout == 'on') {
  234. body.addClass('boxed-layout');
  235. }
  236. }
  237. // $('.s-skin-1').click();
  238. // $('#fixednavbar').click();
  239. });
  240. //判断浏览器是否支持html5本地存储
  241. function localStorageSupport() {
  242. return (('localStorage' in window) && window['localStorage'] !== null)
  243. }