demo.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. 'use strict'
  9. /**
  10. * Get access to plugins
  11. */
  12. $('[data-toggle="control-sidebar"]').controlSidebar()
  13. $('[data-toggle="push-menu"]').pushMenu()
  14. var $pushMenu = $('[data-toggle="push-menu"]').data('lte.pushmenu')
  15. var $controlSidebar = $('[data-toggle="control-sidebar"]').data('lte.controlsidebar')
  16. var $layout = $('body').data('lte.layout')
  17. $(window).on('load', function() {
  18. // Reinitialize variables on load
  19. $pushMenu = $('[data-toggle="push-menu"]').data('lte.pushmenu')
  20. $controlSidebar = $('[data-toggle="control-sidebar"]').data('lte.controlsidebar')
  21. $layout = $('body').data('lte.layout')
  22. })
  23. /**
  24. * List of all the available skins
  25. *
  26. * @type Array
  27. */
  28. var mySkins = [
  29. 'skin-blue',
  30. 'skin-black',
  31. 'skin-red',
  32. 'skin-yellow',
  33. 'skin-purple',
  34. 'skin-green',
  35. 'skin-blue-light',
  36. 'skin-black-light',
  37. 'skin-red-light',
  38. 'skin-yellow-light',
  39. 'skin-purple-light',
  40. 'skin-green-light'
  41. ]
  42. /**
  43. * Get a prestored setting
  44. *
  45. * @param String name Name of of the setting
  46. * @returns String The value of the setting | null
  47. */
  48. function get(name) {
  49. if (typeof (Storage) !== 'undefined') {
  50. return localStorage.getItem(name)
  51. } else {
  52. window.alert('Please use a modern browser to properly view this template!')
  53. }
  54. }
  55. /**
  56. * Store a new settings in the browser
  57. *
  58. * @param String name Name of the setting
  59. * @param String val Value of the setting
  60. * @returns void
  61. */
  62. function store(name, val) {
  63. if (typeof (Storage) !== 'undefined') {
  64. localStorage.setItem(name, val)
  65. } else {
  66. window.alert('Please use a modern browser to properly view this template!')
  67. }
  68. }
  69. /**
  70. * Toggles layout classes
  71. *
  72. * @param String cls the layout class to toggle
  73. * @returns void
  74. */
  75. function changeLayout(cls) {
  76. $('body').toggleClass(cls)
  77. $layout.fixSidebar()
  78. if ($('body').hasClass('fixed') && cls == 'fixed') {
  79. $pushMenu.expandOnHover()
  80. $layout.activate()
  81. }
  82. $controlSidebar.fix()
  83. }
  84. /**
  85. * Replaces the old skin with the new skin
  86. * @param String cls the new skin class
  87. * @returns Boolean false to prevent link's default action
  88. */
  89. function changeSkin(cls) {
  90. $.each(mySkins, function (i) {
  91. $('body').removeClass(mySkins[i])
  92. })
  93. $('body').addClass(cls)
  94. store('skin', cls)
  95. return false
  96. }
  97. /**
  98. * Retrieve default settings and apply them to the template
  99. *
  100. * @returns void
  101. */
  102. function setup() {
  103. var tmp = get('skin')
  104. if (tmp && $.inArray(tmp, mySkins))
  105. changeSkin(tmp)
  106. // Add the change skin listener
  107. $('[data-skin]').on('click', function (e) {
  108. if ($(this).hasClass('knob'))
  109. return
  110. e.preventDefault()
  111. changeSkin($(this).data('skin'))
  112. })
  113. // Add the layout manager
  114. $('[data-layout]').on('click', function () {
  115. changeLayout($(this).data('layout'))
  116. })
  117. $('[data-controlsidebar]').on('click', function () {
  118. changeLayout($(this).data('controlsidebar'))
  119. var slide = !$controlSidebar.options.slide
  120. $controlSidebar.options.slide = slide
  121. if (!slide)
  122. $('.control-sidebar').removeClass('control-sidebar-open')
  123. })
  124. $('[data-sidebarskin="toggle"]').on('click', function () {
  125. var $sidebar = $('.control-sidebar')
  126. if ($sidebar.hasClass('control-sidebar-dark')) {
  127. $sidebar.removeClass('control-sidebar-dark')
  128. $sidebar.addClass('control-sidebar-light')
  129. } else {
  130. $sidebar.removeClass('control-sidebar-light')
  131. $sidebar.addClass('control-sidebar-dark')
  132. }
  133. })
  134. $('[data-enable="expandOnHover"]').on('click', function () {
  135. $(this).attr('disabled', true)
  136. $pushMenu.expandOnHover()
  137. if (!$('body').hasClass('sidebar-collapse'))
  138. $('[data-layout="sidebar-collapse"]').click()
  139. })
  140. // Reset options
  141. if ($('body').hasClass('fixed')) {
  142. $('[data-layout="fixed"]').attr('checked', 'checked')
  143. }
  144. if ($('body').hasClass('layout-boxed')) {
  145. $('[data-layout="layout-boxed"]').attr('checked', 'checked')
  146. }
  147. if ($('body').hasClass('sidebar-collapse')) {
  148. $('[data-layout="sidebar-collapse"]').attr('checked', 'checked')
  149. }
  150. }
  151. // Create the new tab
  152. var $tabPane = $('<div />', {
  153. 'id': 'control-sidebar-theme-demo-options-tab',
  154. 'class': 'tab-pane active'
  155. })
  156. // Create the tab button
  157. var $tabButton = $('<li />', {'class': 'active'})
  158. .html('<a href=\'#control-sidebar-theme-demo-options-tab\' data-toggle=\'tab\'>'
  159. + '<i class="fa fa-wrench"></i>'
  160. + '</a>')
  161. // Add the tab button to the right sidebar tabs
  162. $('[href="#control-sidebar-home-tab"]')
  163. .parent()
  164. .before($tabButton)
  165. // Create the menu
  166. var $demoSettings = $('<div />')
  167. // Layout options
  168. $demoSettings.append(
  169. '<h4 class="control-sidebar-heading">'
  170. + 'Layout Options'
  171. + '</h4>'
  172. // Fixed layout
  173. + '<div class="form-group">'
  174. + '<label class="control-sidebar-subheading">'
  175. + '<input type="checkbox"data-layout="fixed"class="pull-right"/> '
  176. + 'Fixed layout'
  177. + '</label>'
  178. + '<p>Activate the fixed layout. You can\'t use fixed and boxed layouts together</p>'
  179. + '</div>'
  180. // Boxed layout
  181. + '<div class="form-group">'
  182. + '<label class="control-sidebar-subheading">'
  183. + '<input type="checkbox"data-layout="layout-boxed" class="pull-right"/> '
  184. + 'Boxed Layout'
  185. + '</label>'
  186. + '<p>Activate the boxed layout</p>'
  187. + '</div>'
  188. // Sidebar Toggle
  189. + '<div class="form-group">'
  190. + '<label class="control-sidebar-subheading">'
  191. + '<input type="checkbox"data-layout="sidebar-collapse"class="pull-right"/> '
  192. + 'Toggle Sidebar'
  193. + '</label>'
  194. + '<p>Toggle the left sidebar\'s state (open or collapse)</p>'
  195. + '</div>'
  196. // Sidebar mini expand on hover toggle
  197. + '<div class="form-group">'
  198. + '<label class="control-sidebar-subheading">'
  199. + '<input type="checkbox"data-enable="expandOnHover"class="pull-right"/> '
  200. + 'Sidebar Expand on Hover'
  201. + '</label>'
  202. + '<p>Let the sidebar mini expand on hover</p>'
  203. + '</div>'
  204. // Control Sidebar Toggle
  205. + '<div class="form-group">'
  206. + '<label class="control-sidebar-subheading">'
  207. + '<input type="checkbox"data-controlsidebar="control-sidebar-open"class="pull-right"/> '
  208. + 'Toggle Right Sidebar Slide'
  209. + '</label>'
  210. + '<p>Toggle between slide over content and push content effects</p>'
  211. + '</div>'
  212. // Control Sidebar Skin Toggle
  213. + '<div class="form-group">'
  214. + '<label class="control-sidebar-subheading">'
  215. + '<input type="checkbox"data-sidebarskin="toggle"class="pull-right"/> '
  216. + 'Toggle Right Sidebar Skin'
  217. + '</label>'
  218. + '<p>Toggle between dark and light skins for the right sidebar</p>'
  219. + '</div>'
  220. )
  221. var $skinsList = $('<ul />', {'class': 'list-unstyled clearfix'})
  222. // Dark sidebar skins
  223. var $skinBlue =
  224. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  225. .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">'
  226. + '<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>'
  227. + '<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>'
  228. + '</a>'
  229. + '<p class="text-center no-margin">Blue</p>')
  230. $skinsList.append($skinBlue)
  231. var $skinBlack =
  232. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  233. .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">'
  234. + '<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>'
  235. + '<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>'
  236. + '</a>'
  237. + '<p class="text-center no-margin">Black</p>')
  238. $skinsList.append($skinBlack)
  239. var $skinPurple =
  240. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  241. .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">'
  242. + '<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>'
  243. + '<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>'
  244. + '</a>'
  245. + '<p class="text-center no-margin">Purple</p>')
  246. $skinsList.append($skinPurple)
  247. var $skinGreen =
  248. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  249. .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">'
  250. + '<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>'
  251. + '<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>'
  252. + '</a>'
  253. + '<p class="text-center no-margin">Green</p>')
  254. $skinsList.append($skinGreen)
  255. var $skinRed =
  256. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  257. .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">'
  258. + '<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>'
  259. + '<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>'
  260. + '</a>'
  261. + '<p class="text-center no-margin">Red</p>')
  262. $skinsList.append($skinRed)
  263. var $skinYellow =
  264. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  265. .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">'
  266. + '<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>'
  267. + '<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>'
  268. + '</a>'
  269. + '<p class="text-center no-margin">Yellow</p>')
  270. $skinsList.append($skinYellow)
  271. // Light sidebar skins
  272. var $skinBlueLight =
  273. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  274. .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">'
  275. + '<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>'
  276. + '<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>'
  277. + '</a>'
  278. + '<p class="text-center no-margin" style="font-size: 12px">Blue Light</p>')
  279. $skinsList.append($skinBlueLight)
  280. var $skinBlackLight =
  281. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  282. .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">'
  283. + '<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>'
  284. + '<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>'
  285. + '</a>'
  286. + '<p class="text-center no-margin" style="font-size: 12px">Black Light</p>')
  287. $skinsList.append($skinBlackLight)
  288. var $skinPurpleLight =
  289. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  290. .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">'
  291. + '<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>'
  292. + '<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>'
  293. + '</a>'
  294. + '<p class="text-center no-margin" style="font-size: 12px">Purple Light</p>')
  295. $skinsList.append($skinPurpleLight)
  296. var $skinGreenLight =
  297. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  298. .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">'
  299. + '<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>'
  300. + '<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>'
  301. + '</a>'
  302. + '<p class="text-center no-margin" style="font-size: 12px">Green Light</p>')
  303. $skinsList.append($skinGreenLight)
  304. var $skinRedLight =
  305. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  306. .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">'
  307. + '<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>'
  308. + '<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>'
  309. + '</a>'
  310. + '<p class="text-center no-margin" style="font-size: 12px">Red Light</p>')
  311. $skinsList.append($skinRedLight)
  312. var $skinYellowLight =
  313. $('<li />', {style: 'float:left; width: 33.33333%; padding: 5px;'})
  314. .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">'
  315. + '<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>'
  316. + '<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>'
  317. + '</a>'
  318. + '<p class="text-center no-margin" style="font-size: 12px">Yellow Light</p>')
  319. $skinsList.append($skinYellowLight)
  320. $demoSettings.append('<h4 class="control-sidebar-heading">Skins</h4>')
  321. $demoSettings.append($skinsList)
  322. $tabPane.append($demoSettings)
  323. $('#control-sidebar-home-tab').after($tabPane)
  324. setup()
  325. $('[data-toggle="tooltip"]').tooltip()
  326. })