demo.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /**
  2. * AdminLTE Demo Menu
  3. * ------------------
  4. * You should not use this file in production.
  5. * This file is for demo purposes only.
  6. */
  7. (function ($, AdminLTE) {
  8. "use strict";
  9. /**
  10. * List of all the available skins
  11. *
  12. * @type Array
  13. */
  14. var my_skins = [
  15. "skin-blue",
  16. "skin-black",
  17. "skin-red",
  18. "skin-yellow",
  19. "skin-purple",
  20. "skin-green",
  21. "skin-blue-light",
  22. "skin-black-light",
  23. "skin-red-light",
  24. "skin-yellow-light",
  25. "skin-purple-light",
  26. "skin-green-light"
  27. ];
  28. //Create the new tab
  29. var tab_pane = $("<div />", {
  30. "id": "control-sidebar-theme-demo-options-tab",
  31. "class": "tab-pane active"
  32. });
  33. //Create the tab button
  34. var tab_button = $("<li />", {"class": "active"})
  35. .html("<a href='#control-sidebar-theme-demo-options-tab' data-toggle='tab'>"
  36. + "<i class='fa fa-wrench'></i>"
  37. + "</a>");
  38. //Add the tab button to the right sidebar tabs
  39. $("[href='#control-sidebar-home-tab']").parent().before(tab_button);
  40. //Create the menu
  41. var demo_settings = $("<div />");
  42. //Layout options
  43. demo_settings.append(
  44. "<h4 class='control-sidebar-heading'>"
  45. + "布局选项"
  46. + "</h4>"
  47. //Fixed layout
  48. + "<div class='form-group'>"
  49. + "<label class='control-sidebar-subheading'>"
  50. + "<input type='checkbox' data-layout='fixed' class='pull-right'/> "
  51. + "全屏"
  52. + "</label>"
  53. + "<p>全屏布局,收起顶部</p>"
  54. + "</div>"
  55. //Boxed layout
  56. + "<div class='form-group'>"
  57. + "<label class='control-sidebar-subheading'>"
  58. + "<input type='checkbox' data-layout='layout-boxed'class='pull-right'/> "
  59. + "窄屏"
  60. + "</label>"
  61. + "<p>窄屏居中</p>"
  62. + "</div>"
  63. //Sidebar Toggle
  64. + "<div class='form-group'>"
  65. + "<label class='control-sidebar-subheading'>"
  66. + "<input type='checkbox' data-layout='sidebar-collapse' class='pull-right'/> "
  67. + "收起菜单"
  68. + "</label>"
  69. + "<p>左侧菜单栏收缩</p>"
  70. + "</div>"
  71. //Sidebar mini expand on hover toggle
  72. + "<div class='form-group'>"
  73. + "<label class='control-sidebar-subheading'>"
  74. + "<input type='checkbox' data-enable='expandOnHover' class='pull-right'/> "
  75. + "侧栏悬浮收起"
  76. + "</label>"
  77. + "<p>侧栏导航鼠标经过显示</p>"
  78. + "</div>"
  79. //Control Sidebar Toggle
  80. + "<div class='form-group'>"
  81. + "<label class='control-sidebar-subheading'>"
  82. + "<input type='checkbox' data-controlsidebar='control-sidebar-open' class='pull-right'/> "
  83. + "收起右侧挂件"
  84. + "</label>"
  85. + "<p>隐藏挂件框</p>"
  86. + "</div>"
  87. //Control Sidebar Skin Toggle
  88. + "<div class='form-group'>"
  89. + "<label class='control-sidebar-subheading'>"
  90. + "<input type='checkbox' data-sidebarskin='toggle' class='pull-right'/> "
  91. + "改变挂件背景"
  92. + "</label>"
  93. + "<p>切换挂件背景颜色</p>"
  94. + "</div>"
  95. );
  96. var skins_list = $("<ul />", {"class": 'list-unstyled clearfix'});
  97. //Dark sidebar skins
  98. var skin_blue =
  99. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  100. .append("<a href='javascript:void(0);' data-skin='skin-blue' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  101. + "<div><span style='display:block; width: 20%; float: left; height: 7px; background: #367fa9;'></span><span class='bg-light-blue' style='display:block; width: 80%; float: left; height: 7px;'></span></div>"
  102. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #222d32;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  103. + "</a>"
  104. + "<p class='text-center no-margin'>蓝 黑</p>");
  105. skins_list.append(skin_blue);
  106. var skin_black =
  107. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  108. .append("<a href='javascript:void(0);' data-skin='skin-black' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  109. + "<div style='box-shadow: 0 0 2px rgba(0,0,0,0.1)' class='clearfix'><span style='display:block; width: 20%; float: left; height: 7px; background: #fefefe;'></span><span style='display:block; width: 80%; float: left; height: 7px; background: #fefefe;'></span></div>"
  110. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #222;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  111. + "</a>"
  112. + "<p class='text-center no-margin'>白 黑</p>");
  113. skins_list.append(skin_black);
  114. var skin_purple =
  115. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  116. .append("<a href='javascript:void(0);' data-skin='skin-purple' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  117. + "<div><span style='display:block; width: 20%; float: left; height: 7px;' class='bg-purple-active'></span><span class='bg-purple' style='display:block; width: 80%; float: left; height: 7px;'></span></div>"
  118. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #222d32;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  119. + "</a>"
  120. + "<p class='text-center no-margin'>紫 黑</p>");
  121. skins_list.append(skin_purple);
  122. var skin_green =
  123. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  124. .append("<a href='javascript:void(0);' data-skin='skin-green' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  125. + "<div><span style='display:block; width: 20%; float: left; height: 7px;' class='bg-green-active'></span><span class='bg-green' style='display:block; width: 80%; float: left; height: 7px;'></span></div>"
  126. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #222d32;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  127. + "</a>"
  128. + "<p class='text-center no-margin'>绿 黑</p>");
  129. skins_list.append(skin_green);
  130. var skin_red =
  131. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  132. .append("<a href='javascript:void(0);' data-skin='skin-red' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  133. + "<div><span style='display:block; width: 20%; float: left; height: 7px;' class='bg-red-active'></span><span class='bg-red' style='display:block; width: 80%; float: left; height: 7px;'></span></div>"
  134. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #222d32;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  135. + "</a>"
  136. + "<p class='text-center no-margin'>红 黑</p>");
  137. skins_list.append(skin_red);
  138. var skin_yellow =
  139. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  140. .append("<a href='javascript:void(0);' data-skin='skin-yellow' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  141. + "<div><span style='display:block; width: 20%; float: left; height: 7px;' class='bg-yellow-active'></span><span class='bg-yellow' style='display:block; width: 80%; float: left; height: 7px;'></span></div>"
  142. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #222d32;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  143. + "</a>"
  144. + "<p class='text-center no-margin'>黄 黑</p>");
  145. skins_list.append(skin_yellow);
  146. //Light sidebar skins
  147. var skin_blue_light =
  148. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  149. .append("<a href='javascript:void(0);' data-skin='skin-blue-light' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  150. + "<div><span style='display:block; width: 20%; float: left; height: 7px; background: #367fa9;'></span><span class='bg-light-blue' style='display:block; width: 80%; float: left; height: 7px;'></span></div>"
  151. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #f9fafc;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  152. + "</a>"
  153. + "<p class='text-center no-margin' style='font-size: 12px'>蓝 白</p>");
  154. skins_list.append(skin_blue_light);
  155. var skin_black_light =
  156. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  157. .append("<a href='javascript:void(0);' data-skin='skin-black-light' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  158. + "<div style='box-shadow: 0 0 2px rgba(0,0,0,0.1)' class='clearfix'><span style='display:block; width: 20%; float: left; height: 7px; background: #fefefe;'></span><span style='display:block; width: 80%; float: left; height: 7px; background: #fefefe;'></span></div>"
  159. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #f9fafc;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  160. + "</a>"
  161. + "<p class='text-center no-margin' style='font-size: 12px'>黑 白</p>");
  162. skins_list.append(skin_black_light);
  163. var skin_purple_light =
  164. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  165. .append("<a href='javascript:void(0);' data-skin='skin-purple-light' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  166. + "<div><span style='display:block; width: 20%; float: left; height: 7px;' class='bg-purple-active'></span><span class='bg-purple' style='display:block; width: 80%; float: left; height: 7px;'></span></div>"
  167. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #f9fafc;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  168. + "</a>"
  169. + "<p class='text-center no-margin' style='font-size: 12px'>紫 白</p>");
  170. skins_list.append(skin_purple_light);
  171. var skin_green_light =
  172. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  173. .append("<a href='javascript:void(0);' data-skin='skin-green-light' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  174. + "<div><span style='display:block; width: 20%; float: left; height: 7px;' class='bg-green-active'></span><span class='bg-green' style='display:block; width: 80%; float: left; height: 7px;'></span></div>"
  175. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #f9fafc;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  176. + "</a>"
  177. + "<p class='text-center no-margin' style='font-size: 12px'>绿 白</p>");
  178. skins_list.append(skin_green_light);
  179. var skin_red_light =
  180. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  181. .append("<a href='javascript:void(0);' data-skin='skin-red-light' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  182. + "<div><span style='display:block; width: 20%; float: left; height: 7px;' class='bg-red-active'></span><span class='bg-red' style='display:block; width: 80%; float: left; height: 7px;'></span></div>"
  183. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #f9fafc;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  184. + "</a>"
  185. + "<p class='text-center no-margin' style='font-size: 12px'>红 白</p>");
  186. skins_list.append(skin_red_light);
  187. var skin_yellow_light =
  188. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  189. .append("<a href='javascript:void(0);' data-skin='skin-yellow-light' style='display: block; box-shadow: 0 0 3px rgba(0,0,0,0.4)' class='clearfix full-opacity-hover'>"
  190. + "<div><span style='display:block; width: 20%; float: left; height: 7px;' class='bg-yellow-active'></span><span class='bg-yellow' style='display:block; width: 80%; float: left; height: 7px;'></span></div>"
  191. + "<div><span style='display:block; width: 20%; float: left; height: 20px; background: #f9fafc;'></span><span style='display:block; width: 80%; float: left; height: 20px; background: #f4f5f7;'></span></div>"
  192. + "</a>"
  193. + "<p class='text-center no-margin' style='font-size: 12px;'>黄 白</p>");
  194. skins_list.append(skin_yellow_light);
  195. demo_settings.append("<h4 class='control-sidebar-heading'>皮肤</h4>");
  196. demo_settings.append(skins_list);
  197. tab_pane.append(demo_settings);
  198. $("#control-sidebar-home-tab").after(tab_pane);
  199. setup();
  200. /**
  201. * Toggles layout classes
  202. *
  203. * @param String cls the layout class to toggle
  204. * @returns void
  205. */
  206. function change_layout(cls) {
  207. $("body").toggleClass(cls);
  208. AdminLTE.layout.fixSidebar();
  209. //Fix the problem with right sidebar and layout boxed
  210. if (cls == "layout-boxed")
  211. AdminLTE.controlSidebar._fix($(".control-sidebar-bg"));
  212. if ($('body').hasClass('fixed') && cls == 'fixed') {
  213. AdminLTE.pushMenu.expandOnHover();
  214. AdminLTE.layout.activate();
  215. }
  216. AdminLTE.controlSidebar._fix($(".control-sidebar-bg"));
  217. AdminLTE.controlSidebar._fix($(".control-sidebar"));
  218. }
  219. /**
  220. * Replaces the old skin with the new skin
  221. * @param String cls the new skin class
  222. * @returns Boolean false to prevent link's default action
  223. */
  224. function change_skin(cls) {
  225. $.each(my_skins, function (i) {
  226. $("body").removeClass(my_skins[i]);
  227. });
  228. $("body").addClass(cls);
  229. store('skin', cls);
  230. return false;
  231. }
  232. /**
  233. * Store a new settings in the browser
  234. *
  235. * @param String name Name of the setting
  236. * @param String val Value of the setting
  237. * @returns void
  238. */
  239. function store(name, val) {
  240. if (typeof (Storage) !== "undefined") {
  241. localStorage.setItem(name, val);
  242. } else {
  243. window.alert('Please use a modern browser to properly view this template!');
  244. }
  245. }
  246. /**
  247. * Get a prestored setting
  248. *
  249. * @param String name Name of of the setting
  250. * @returns String The value of the setting | null
  251. */
  252. function get(name) {
  253. if (typeof (Storage) !== "undefined") {
  254. return localStorage.getItem(name);
  255. } else {
  256. window.alert('Please use a modern browser to properly view this template!');
  257. }
  258. }
  259. /**
  260. * Retrieve default settings and apply them to the template
  261. *
  262. * @returns void
  263. */
  264. function setup() {
  265. var tmp = get('skin');
  266. if (tmp && $.inArray(tmp, my_skins))
  267. change_skin(tmp);
  268. //Add the change skin listener
  269. $("[data-skin]").on('click', function (e) {
  270. e.preventDefault();
  271. change_skin($(this).data('skin'));
  272. });
  273. //Add the layout manager
  274. $("[data-layout]").on('click', function () {
  275. change_layout($(this).data('layout'));
  276. });
  277. $("[data-controlsidebar]").on('click', function () {
  278. change_layout($(this).data('controlsidebar'));
  279. var slide = !AdminLTE.options.controlSidebarOptions.slide;
  280. AdminLTE.options.controlSidebarOptions.slide = slide;
  281. if (!slide)
  282. $('.control-sidebar').removeClass('control-sidebar-open');
  283. });
  284. $("[data-sidebarskin='toggle']").on('click', function () {
  285. var sidebar = $(".control-sidebar");
  286. if (sidebar.hasClass("control-sidebar-dark")) {
  287. sidebar.removeClass("control-sidebar-dark")
  288. sidebar.addClass("control-sidebar-light")
  289. } else {
  290. sidebar.removeClass("control-sidebar-light")
  291. sidebar.addClass("control-sidebar-dark")
  292. }
  293. });
  294. $("[data-enable='expandOnHover']").on('click', function () {
  295. $(this).attr('disabled', true);
  296. AdminLTE.pushMenu.expandOnHover();
  297. if (!$('body').hasClass('sidebar-collapse'))
  298. $("[data-layout='sidebar-collapse']").click();
  299. });
  300. // Reset options
  301. if ($('body').hasClass('fixed')) {
  302. $("[data-layout='fixed']").attr('checked', 'checked');
  303. }
  304. if ($('body').hasClass('layout-boxed')) {
  305. $("[data-layout='layout-boxed']").attr('checked', 'checked');
  306. }
  307. if ($('body').hasClass('sidebar-collapse')) {
  308. $("[data-layout='sidebar-collapse']").attr('checked', 'checked');
  309. }
  310. }
  311. })(jQuery, $.AdminLTE);