demo.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 ($) {
  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. /**
  28. * CSS rules for the menu
  29. *
  30. * @type Object
  31. */
  32. var menu_css = {
  33. "padding": "10px",
  34. "position": "fixed",
  35. "top": "70px",
  36. "right": "-250px",
  37. "background": "#fff",
  38. "border": "0px solid #ddd",
  39. "width": "250px",
  40. "z-index": "99999",
  41. "box-shadow": "0 1px 3px rgba(0,0,0,0.1)"
  42. };
  43. /**
  44. * CSS rules for the demo handle button
  45. *
  46. * @type Object
  47. */
  48. var handle_css = {
  49. "position": "fixed",
  50. "top": "70px",
  51. "right": "0",
  52. "background": "#fff",
  53. "border-radius": "5px 0px 0px 5px",
  54. "padding": "10px 15px",
  55. "font-size": "16px",
  56. "z-index": "99999",
  57. "cursor": "pointer",
  58. "color": "#3c8dbc",
  59. "box-shadow": "0 1px 3px rgba(0,0,0,0.1)"
  60. };
  61. //Create the handle
  62. var demo = $("<div />")
  63. .css(handle_css)
  64. .html("<i class='fa fa-gear'></i>")
  65. .addClass("no-print");
  66. //Create the menu
  67. var demo_settings = $("<div />")
  68. .css(menu_css)
  69. .addClass("no-print");
  70. demo_settings.append(
  71. "<h4 class='text-light-blue' style='margin: 0 0 5px 0; border-bottom: 1px solid #ddd; padding-bottom: 15px;'>"
  72. + "Layout Options"
  73. + "</h4>"
  74. //Fixed layout
  75. + "<div class='form-group'>"
  76. + "<div class='checkbox'>"
  77. + "<label>"
  78. + "<input type='checkbox' onchange='change_layout(\"fixed\");'/> "
  79. + "Fixed layout"
  80. + "</label>"
  81. + "</div>"
  82. + "</div>"
  83. //Boxed layout
  84. + "<div class='form-group'>"
  85. + "<div class='checkbox'>"
  86. + "<label>"
  87. + "<input type='checkbox' onchange='change_layout(\"layout-boxed\");'/> "
  88. + "Boxed Layout"
  89. + "</label>"
  90. + "</div>"
  91. + "</div>"
  92. //Sidebar Collapse
  93. + "<div class='form-group'>"
  94. + "<div class='checkbox'>"
  95. + "<label>"
  96. + "<input type='checkbox' onchange='change_layout(\"sidebar-collapse\");'/> "
  97. + "Collapsed Sidebar"
  98. + "</label>"
  99. + "</div>"
  100. + "</div>"
  101. );
  102. var skins_list = $("<ul />", {"class": 'list-unstyled'});
  103. //Dark sidebar skins
  104. var skin_blue =
  105. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  106. .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'>"
  107. + "<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>"
  108. + "<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>"
  109. + "</a>"
  110. + "<p class='text-center'>Blue</p>");
  111. skins_list.append(skin_blue);
  112. var skin_black =
  113. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  114. .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'>"
  115. + "<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>"
  116. + "<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>"
  117. + "</a>"
  118. + "<p class='text-center'>Black</p>");
  119. skins_list.append(skin_black);
  120. var skin_purple =
  121. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  122. .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'>"
  123. + "<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>"
  124. + "<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>"
  125. + "</a>"
  126. + "<p class='text-center'>Purple</p>");
  127. skins_list.append(skin_purple);
  128. var skin_green =
  129. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  130. .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'>"
  131. + "<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>"
  132. + "<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>"
  133. + "</a>"
  134. + "<p class='text-center'>Green</p>");
  135. skins_list.append(skin_green);
  136. var skin_red =
  137. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  138. .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'>"
  139. + "<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>"
  140. + "<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>"
  141. + "</a>"
  142. + "<p class='text-center'>Red</p>");
  143. skins_list.append(skin_red);
  144. var skin_yellow =
  145. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  146. .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'>"
  147. + "<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>"
  148. + "<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>"
  149. + "</a>"
  150. + "<p class='text-center'>Yellow</p>");
  151. skins_list.append(skin_yellow);
  152. //Light sidebar skins
  153. var skin_blue_light =
  154. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  155. .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'>"
  156. + "<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>"
  157. + "<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>"
  158. + "</a>"
  159. + "<p class='text-center' style='font-size: 12px'>Blue Light</p>");
  160. skins_list.append(skin_blue_light);
  161. var skin_black_light =
  162. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  163. .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'>"
  164. + "<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>"
  165. + "<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>"
  166. + "</a>"
  167. + "<p class='text-center' style='font-size: 12px'>Black Light</p>");
  168. skins_list.append(skin_black_light);
  169. var skin_purple_light =
  170. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  171. .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'>"
  172. + "<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>"
  173. + "<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>"
  174. + "</a>"
  175. + "<p class='text-center' style='font-size: 12px'>Purple Light</p>");
  176. skins_list.append(skin_purple_light);
  177. var skin_green_light =
  178. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  179. .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'>"
  180. + "<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>"
  181. + "<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>"
  182. + "</a>"
  183. + "<p class='text-center' style='font-size: 12px'>Green Light</p>");
  184. skins_list.append(skin_green_light);
  185. var skin_red_light =
  186. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  187. .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'>"
  188. + "<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>"
  189. + "<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>"
  190. + "</a>"
  191. + "<p class='text-center' style='font-size: 12px'>Red Light</p>");
  192. skins_list.append(skin_red_light);
  193. var skin_yellow_light =
  194. $("<li />", {style: "float:left; width: 33.33333%; padding: 5px;"})
  195. .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'>"
  196. + "<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>"
  197. + "<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>"
  198. + "</a>"
  199. + "<p class='text-center' style='font-size: 12px'>Yellow Light</p>");
  200. skins_list.append(skin_yellow_light);
  201. demo_settings.append("<h4 class='text-light-blue' style='margin: 0 0 5px 0; border-bottom: 1px solid #ddd; padding-bottom: 15px;'>Skins</h4>");
  202. demo_settings.append(skins_list);
  203. demo.click(function () {
  204. if (!$(this).hasClass("open")) {
  205. $(this).animate({"right": "250px"});
  206. demo_settings.animate({"right": "0"});
  207. $(this).addClass("open");
  208. } else {
  209. $(this).animate({"right": "0"});
  210. demo_settings.animate({"right": "-250px"});
  211. $(this).removeClass("open");
  212. }
  213. });
  214. $("body").append(demo);
  215. $("body").append(demo_settings);
  216. setup();
  217. /**
  218. * Toggles layout classes
  219. *
  220. * @param String cls the layout class to toggle
  221. * @returns void
  222. */
  223. function change_layout(cls) {
  224. $("body").toggleClass(cls);
  225. $.AdminLTE.layout.fixSidebar();
  226. }
  227. /**
  228. * Replaces the old skin with the new skin
  229. * @param String cls the new skin class
  230. * @returns Boolean false to prevent link's default action
  231. */
  232. function change_skin(cls) {
  233. $.each(my_skins, function (i) {
  234. $("body").removeClass(my_skins[i]);
  235. });
  236. $("body").addClass(cls);
  237. store('skin', cls);
  238. return false;
  239. }
  240. /**
  241. * Store a new settings in the browser
  242. *
  243. * @param String name Name of the setting
  244. * @param String val Value of the setting
  245. * @returns void
  246. */
  247. function store(name, val) {
  248. if (typeof (Storage) !== "undefined") {
  249. localStorage.setItem(name, val);
  250. } else {
  251. alert('Please use a modern browser to properly view this template!');
  252. }
  253. }
  254. /**
  255. * Get a prestored setting
  256. *
  257. * @param String name Name of of the setting
  258. * @returns String The value of the setting | null
  259. */
  260. function get(name) {
  261. if (typeof (Storage) !== "undefined") {
  262. return localStorage.getItem(name);
  263. } else {
  264. alert('Please use a modern browser to properly view this template!');
  265. }
  266. }
  267. /**
  268. * Retrieve default settings and apply them to the template
  269. *
  270. * @returns void
  271. */
  272. function setup() {
  273. var tmp = get('skin');
  274. if (tmp && $.inArray(tmp, my_skins))
  275. change_skin(tmp);
  276. //Add the change skin listener
  277. $("[data-skin]").on('click', function (e) {
  278. e.preventDefault();
  279. change_skin($(this).data('skin'));
  280. });
  281. }
  282. })(jQuery);