demo.js 17 KB

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