demo.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. /**
  9. * List of all the available skins
  10. *
  11. * @type Array
  12. */
  13. var my_skins = [
  14. "skin-blue",
  15. "skin-black",
  16. "skin-red",
  17. "skin-yellow",
  18. "skin-purple",
  19. "skin-green",
  20. "skin-blue-light",
  21. "skin-black-light",
  22. "skin-red-light",
  23. "skin-yellow-light",
  24. "skin-purple-light",
  25. "skin-green-light"
  26. ];
  27. //Create the new tab
  28. var tab_pane = $("<div />", {
  29. "id": "control-sidebar-theme-demo-options-tab",
  30. "class": "tab-pane active"
  31. });
  32. //Create the tab button
  33. var tab_button = $("<li />", {"class": "active"})
  34. .html("<a href='#control-sidebar-theme-demo-options-tab' data-toggle='tab'>"
  35. + "<i class='fa fa-wrench'></i>"
  36. + "</a>");
  37. //Add the tab button to the right sidebar tabs
  38. $("[href='#control-sidebar-home-tab']")
  39. .parent()
  40. .before(tab_button);
  41. //Create the menu
  42. var demo_settings = $("<div />");
  43. //Layout options
  44. demo_settings.append(
  45. "<h4 class='control-sidebar-heading'>"
  46. + "Layout Options"
  47. + "</h4>"
  48. //Fixed layout
  49. + "<div class='form-group'>"
  50. + "<label class='control-sidebar-subheading'>"
  51. + "<input type='checkbox' data-layout='fixed' class='pull-right'/> "
  52. + "Fixed layout"
  53. + "</label>"
  54. + "<p>Activate the fixed layout. You can't use fixed and boxed layouts together</p>"
  55. + "</div>"
  56. //Boxed layout
  57. + "<div class='form-group'>"
  58. + "<label class='control-sidebar-subheading'>"
  59. + "<input type='checkbox' data-layout='layout-boxed'class='pull-right'/> "
  60. + "Boxed Layout"
  61. + "</label>"
  62. + "<p>Activate the boxed layout</p>"
  63. + "</div>"
  64. //Sidebar Toggle
  65. + "<div class='form-group'>"
  66. + "<label class='control-sidebar-subheading'>"
  67. + "<input type='checkbox' data-layout='sidebar-collapse' class='pull-right'/> "
  68. + "Toggle Sidebar"
  69. + "</label>"
  70. + "<p>Toggle the left sidebar's state (open or collapse)</p>"
  71. + "</div>"
  72. //Sidebar mini expand on hover toggle
  73. + "<div class='form-group'>"
  74. + "<label class='control-sidebar-subheading'>"
  75. + "<input type='checkbox' data-enable='expandOnHover' class='pull-right'/> "
  76. + "Sidebar Expand on Hover"
  77. + "</label>"
  78. + "<p>Let the sidebar mini expand on hover</p>"
  79. + "</div>"
  80. //Control Sidebar Toggle
  81. + "<div class='form-group'>"
  82. + "<label class='control-sidebar-subheading'>"
  83. + "<input type='checkbox' data-controlsidebar='control-sidebar-open' class='pull-right'/> "
  84. + "Toggle Right Sidebar Slide"
  85. + "</label>"
  86. + "<p>Toggle between slide over content and push content effects</p>"
  87. + "</div>"
  88. //Control Sidebar Skin Toggle
  89. + "<div class='form-group'>"
  90. + "<label class='control-sidebar-subheading'>"
  91. + "<input type='checkbox' data-sidebarskin='toggle' class='pull-right'/> "
  92. + "Toggle Right Sidebar Skin"
  93. + "</label>"
  94. + "<p>Toggle between dark and light skins for the right sidebar</p>"
  95. + "</div>"
  96. );
  97. var skins_list = $("<ul />", {"class": 'list-unstyled clearfix'});
  98. //Dark sidebar skins
  99. var skin_blue =
  100. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  101. .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'>"
  102. + "<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>"
  103. + "<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>"
  104. + "</a>"
  105. + "<p class='text-center no-margin'>Blue</p>");
  106. skins_list.append(skin_blue);
  107. var skin_black =
  108. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  109. .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'>"
  110. + "<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>"
  111. + "<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>"
  112. + "</a>"
  113. + "<p class='text-center no-margin'>Black</p>");
  114. skins_list.append(skin_black);
  115. var skin_purple =
  116. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  117. .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'>"
  118. + "<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>"
  119. + "<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>"
  120. + "</a>"
  121. + "<p class='text-center no-margin'>Purple</p>");
  122. skins_list.append(skin_purple);
  123. var skin_green =
  124. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  125. .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'>"
  126. + "<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>"
  127. + "<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>"
  128. + "</a>"
  129. + "<p class='text-center no-margin'>Green</p>");
  130. skins_list.append(skin_green);
  131. var skin_red =
  132. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  133. .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'>"
  134. + "<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>"
  135. + "<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>"
  136. + "</a>"
  137. + "<p class='text-center no-margin'>Red</p>");
  138. skins_list.append(skin_red);
  139. var skin_yellow =
  140. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  141. .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'>"
  142. + "<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>"
  143. + "<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>"
  144. + "</a>"
  145. + "<p class='text-center no-margin'>Yellow</p>");
  146. skins_list.append(skin_yellow);
  147. //Light sidebar skins
  148. var skin_blue_light =
  149. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  150. .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'>"
  151. + "<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>"
  152. + "<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>"
  153. + "</a>"
  154. + "<p class='text-center no-margin' style='font-size: 12px'>Blue Light</p>");
  155. skins_list.append(skin_blue_light);
  156. var skin_black_light =
  157. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  158. .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'>"
  159. + "<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>"
  160. + "<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>"
  161. + "</a>"
  162. + "<p class='text-center no-margin' style='font-size: 12px'>Black Light</p>");
  163. skins_list.append(skin_black_light);
  164. var skin_purple_light =
  165. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  166. .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'>"
  167. + "<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>"
  168. + "<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>"
  169. + "</a>"
  170. + "<p class='text-center no-margin' style='font-size: 12px'>Purple Light</p>");
  171. skins_list.append(skin_purple_light);
  172. var skin_green_light =
  173. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  174. .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'>"
  175. + "<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>"
  176. + "<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>"
  177. + "</a>"
  178. + "<p class='text-center no-margin' style='font-size: 12px'>Green Light</p>");
  179. skins_list.append(skin_green_light);
  180. var skin_red_light =
  181. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  182. .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'>"
  183. + "<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>"
  184. + "<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>"
  185. + "</a>"
  186. + "<p class='text-center no-margin' style='font-size: 12px'>Red Light</p>");
  187. skins_list.append(skin_red_light);
  188. var skin_yellow_light =
  189. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  190. .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'>"
  191. + "<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>"
  192. + "<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>"
  193. + "</a>"
  194. + "<p class='text-center no-margin' style='font-size: 12px;'>Yellow Light</p>");
  195. skins_list.append(skin_yellow_light);
  196. demo_settings.append("<h4 class='control-sidebar-heading'>Skins</h4>");
  197. demo_settings.append(skins_list);
  198. tab_pane.append(demo_settings);
  199. $("#control-sidebar-home-tab").after(tab_pane);
  200. setup();
  201. /**
  202. * Toggles layout classes
  203. *
  204. * @param String cls the layout class to toggle
  205. * @returns void
  206. */
  207. function change_layout(cls) {
  208. $("body").toggleClass(cls);
  209. AdminLTE.layout.fixSidebar();
  210. //Fix the problem with right sidebar and layout boxed
  211. if (cls == "layout-boxed")
  212. AdminLTE.controlSidebar._fix($(".control-sidebar-bg"));
  213. if ($('body').hasClass('fixed') && cls == 'fixed') {
  214. AdminLTE.pushMenu.expandOnHover();
  215. AdminLTE.controlSidebar._fixForFixed($('.control-sidebar'));
  216. AdminLTE.layout.activate();
  217. }
  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. 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. 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);