Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | /** |
| 2 | Demo script to handle the theme demo |
||
| 3 | **/ |
||
| 4 | var Demo = function () { |
||
| 5 | |||
| 6 | // Handle Theme Settings |
||
| 7 | var handleTheme = function () { |
||
| 8 | |||
| 9 | var panel = $('.theme-panel'); |
||
| 10 | |||
| 11 | if ($('body').hasClass('page-boxed') === false) { |
||
| 12 | $('.layout-option', panel).val("fluid"); |
||
| 13 | } |
||
| 14 | |||
| 15 | $('.sidebar-option', panel).val("default"); |
||
| 16 | $('.page-header-option', panel).val("fixed"); |
||
| 17 | $('.page-footer-option', panel).val("default"); |
||
| 18 | if ($('.sidebar-pos-option').attr("disabled") === false) { |
||
| 19 | $('.sidebar-pos-option', panel).val(Metronic.isRTL() ? 'right' : 'left'); |
||
| 20 | } |
||
| 21 | |||
| 22 | //handle theme layout |
||
| 23 | var resetLayout = function () { |
||
| 24 | $("body"). |
||
| 25 | removeClass("page-boxed"). |
||
| 26 | removeClass("page-footer-fixed"). |
||
| 27 | removeClass("page-sidebar-fixed"). |
||
| 28 | removeClass("page-header-fixed"). |
||
| 29 | removeClass("page-sidebar-reversed"); |
||
| 30 | |||
| 31 | $('.page-header > .page-header-inner').removeClass("container"); |
||
| 32 | |||
| 33 | if ($('.page-container').parent(".container").size() === 1) { |
||
| 34 | $('.page-container').insertAfter('body > .clearfix'); |
||
| 35 | } |
||
| 36 | |||
| 37 | if ($('.page-footer > .container').size() === 1) { |
||
| 38 | $('.page-footer').html($('.page-footer > .container').html()); |
||
| 39 | } else if ($('.page-footer').parent(".container").size() === 1) { |
||
| 40 | $('.page-footer').insertAfter('.page-container'); |
||
| 41 | $('.scroll-to-top').insertAfter('.page-footer'); |
||
| 42 | } |
||
| 43 | |||
| 44 | $(".top-menu > .navbar-nav > li.dropdown").removeClass("dropdown-dark"); |
||
| 45 | |||
| 46 | $('body > .container').remove(); |
||
| 47 | }; |
||
| 48 | |||
| 49 | var lastSelectedLayout = ''; |
||
| 50 | |||
| 51 | var setLayout = function () { |
||
| 52 | |||
| 53 | var layoutOption = $('.layout-option', panel).val(); |
||
| 54 | var sidebarOption = $('.sidebar-option', panel).val(); |
||
| 55 | var headerOption = $('.page-header-option', panel).val(); |
||
| 56 | var footerOption = $('.page-footer-option', panel).val(); |
||
| 57 | var sidebarPosOption = $('.sidebar-pos-option', panel).val(); |
||
| 58 | var sidebarStyleOption = $('.sidebar-style-option', panel).val(); |
||
| 59 | var sidebarMenuOption = $('.sidebar-menu-option', panel).val(); |
||
| 60 | var headerTopDropdownStyle = $('.page-header-top-dropdown-style-option', panel).val(); |
||
| 61 | |||
| 62 | |||
| 63 | if (sidebarOption == "fixed" && headerOption == "default") { |
||
| 64 | alert('Default Header with Fixed Sidebar option is not supported. Proceed with Fixed Header with Fixed Sidebar.'); |
||
| 65 | $('.page-header-option', panel).val("fixed"); |
||
| 66 | $('.sidebar-option', panel).val("fixed"); |
||
| 67 | sidebarOption = 'fixed'; |
||
| 68 | headerOption = 'fixed'; |
||
| 69 | } |
||
| 70 | |||
| 71 | resetLayout(); // reset layout to default state |
||
| 72 | |||
| 73 | if (layoutOption === "boxed") { |
||
| 74 | $("body").addClass("page-boxed"); |
||
| 75 | |||
| 76 | // set header |
||
| 77 | $('.page-header > .page-header-inner').addClass("container"); |
||
| 78 | var cont = $('body > .clearfix').after('<div class="container"></div>'); |
||
| 79 | |||
| 80 | // set content |
||
| 81 | $('.page-container').appendTo('body > .container'); |
||
| 82 | |||
| 83 | // set footer |
||
| 84 | if (footerOption === 'fixed') { |
||
| 85 | $('.page-footer').html('<div class="container">' + $('.page-footer').html() + '</div>'); |
||
| 86 | } else { |
||
| 87 | $('.page-footer').appendTo('body > .container'); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | if (lastSelectedLayout != layoutOption) { |
||
| 92 | //layout changed, run responsive handler: |
||
| 93 | Metronic.runResizeHandlers(); |
||
| 94 | } |
||
| 95 | lastSelectedLayout = layoutOption; |
||
| 96 | |||
| 97 | //header |
||
| 98 | if (headerOption === 'fixed') { |
||
| 99 | $("body").addClass("page-header-fixed"); |
||
| 100 | $(".page-header").removeClass("navbar-static-top").addClass("navbar-fixed-top"); |
||
| 101 | } else { |
||
| 102 | $("body").removeClass("page-header-fixed"); |
||
| 103 | $(".page-header").removeClass("navbar-fixed-top").addClass("navbar-static-top"); |
||
| 104 | } |
||
| 105 | |||
| 106 | //sidebar |
||
| 107 | if ($('body').hasClass('page-full-width') === false) { |
||
| 108 | if (sidebarOption === 'fixed') { |
||
| 109 | $("body").addClass("page-sidebar-fixed"); |
||
| 110 | $("page-sidebar-menu").addClass("page-sidebar-menu-fixed"); |
||
| 111 | $("page-sidebar-menu").removeClass("page-sidebar-menu-default"); |
||
| 112 | Layout.initFixedSidebarHoverEffect(); |
||
| 113 | } else { |
||
| 114 | $("body").removeClass("page-sidebar-fixed"); |
||
| 115 | $("page-sidebar-menu").addClass("page-sidebar-menu-default"); |
||
| 116 | $("page-sidebar-menu").removeClass("page-sidebar-menu-fixed"); |
||
| 117 | $('.page-sidebar-menu').unbind('mouseenter').unbind('mouseleave'); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | // top dropdown style |
||
| 122 | if (headerTopDropdownStyle === 'dark') { |
||
| 123 | $(".top-menu > .navbar-nav > li.dropdown").addClass("dropdown-dark"); |
||
| 124 | } else { |
||
| 125 | $(".top-menu > .navbar-nav > li.dropdown").removeClass("dropdown-dark"); |
||
| 126 | } |
||
| 127 | |||
| 128 | //footer |
||
| 129 | if (footerOption === 'fixed') { |
||
| 130 | $("body").addClass("page-footer-fixed"); |
||
| 131 | } else { |
||
| 132 | $("body").removeClass("page-footer-fixed"); |
||
| 133 | } |
||
| 134 | |||
| 135 | //sidebar style |
||
| 136 | if (sidebarStyleOption === 'compact') { |
||
| 137 | $(".page-sidebar-menu").addClass("page-sidebar-menu-compact"); |
||
| 138 | } else { |
||
| 139 | $(".page-sidebar-menu").removeClass("page-sidebar-menu-compact"); |
||
| 140 | } |
||
| 141 | |||
| 142 | //sidebar menu |
||
| 143 | if (sidebarMenuOption === 'hover') { |
||
| 144 | if (sidebarOption == 'fixed') { |
||
| 145 | $('.sidebar-menu-option', panel).val("accordion"); |
||
| 146 | alert("Hover Sidebar Menu is not compatible with Fixed Sidebar Mode. Select Default Sidebar Mode Instead."); |
||
| 147 | } else { |
||
| 148 | $(".page-sidebar-menu").addClass("page-sidebar-menu-hover-submenu"); |
||
| 149 | } |
||
| 150 | } else { |
||
| 151 | $(".page-sidebar-menu").removeClass("page-sidebar-menu-hover-submenu"); |
||
| 152 | } |
||
| 153 | |||
| 154 | //sidebar position |
||
| 155 | if (Metronic.isRTL()) { |
||
| 156 | if (sidebarPosOption === 'left') { |
||
| 157 | $("body").addClass("page-sidebar-reversed"); |
||
| 158 | $('#frontend-link').tooltip('destroy').tooltip({ |
||
| 159 | placement: 'right' |
||
| 160 | }); |
||
| 161 | } else { |
||
| 162 | $("body").removeClass("page-sidebar-reversed"); |
||
| 163 | $('#frontend-link').tooltip('destroy').tooltip({ |
||
| 164 | placement: 'left' |
||
| 165 | }); |
||
| 166 | } |
||
| 167 | } else { |
||
| 168 | if (sidebarPosOption === 'right') { |
||
| 169 | $("body").addClass("page-sidebar-reversed"); |
||
| 170 | $('#frontend-link').tooltip('destroy').tooltip({ |
||
| 171 | placement: 'left' |
||
| 172 | }); |
||
| 173 | } else { |
||
| 174 | $("body").removeClass("page-sidebar-reversed"); |
||
| 175 | $('#frontend-link').tooltip('destroy').tooltip({ |
||
| 176 | placement: 'right' |
||
| 177 | }); |
||
| 178 | } |
||
| 179 | } |
||
| 180 | |||
| 181 | Layout.fixContentHeight(); // fix content height |
||
| 182 | Layout.initFixedSidebar(); // reinitialize fixed sidebar |
||
| 183 | }; |
||
| 184 | |||
| 185 | // handle theme colors |
||
| 186 | var setColor = function (color) { |
||
| 187 | var color_ = (Metronic.isRTL() ? color + '-rtl' : color); |
||
| 188 | $('#style_color').attr("href", Layout.getLayoutCssPath() + 'themes/' + color_ + ".css"); |
||
| 189 | }; |
||
| 190 | |||
| 191 | $('.toggler', panel).click(function () { |
||
| 192 | $('.toggler').hide(); |
||
| 193 | $('.toggler-close').show(); |
||
| 194 | $('.theme-panel > .theme-options').show(); |
||
| 195 | }); |
||
| 196 | |||
| 197 | $('.toggler-close', panel).click(function () { |
||
| 198 | $('.toggler').show(); |
||
| 199 | $('.toggler-close').hide(); |
||
| 200 | $('.theme-panel > .theme-options').hide(); |
||
| 201 | }); |
||
| 202 | |||
| 203 | $('.theme-colors > ul > li', panel).click(function () { |
||
| 204 | var color = $(this).attr("data-style"); |
||
| 205 | setColor(color); |
||
| 206 | $('ul > li', panel).removeClass("current"); |
||
| 207 | $(this).addClass("current"); |
||
| 208 | }); |
||
| 209 | |||
| 210 | // set default theme options: |
||
| 211 | |||
| 212 | if ($("body").hasClass("page-boxed")) { |
||
| 213 | $('.layout-option', panel).val("boxed"); |
||
| 214 | } |
||
| 215 | |||
| 216 | if ($("body").hasClass("page-sidebar-fixed")) { |
||
| 217 | $('.sidebar-option', panel).val("fixed"); |
||
| 218 | } |
||
| 219 | |||
| 220 | if ($("body").hasClass("page-header-fixed")) { |
||
| 221 | $('.page-header-option', panel).val("fixed"); |
||
| 222 | } |
||
| 223 | |||
| 224 | if ($("body").hasClass("page-footer-fixed")) { |
||
| 225 | $('.page-footer-option', panel).val("fixed"); |
||
| 226 | } |
||
| 227 | |||
| 228 | if ($("body").hasClass("page-sidebar-reversed")) { |
||
| 229 | $('.sidebar-pos-option', panel).val("right"); |
||
| 230 | } |
||
| 231 | |||
| 232 | if ($(".page-sidebar-menu").hasClass("page-sidebar-menu-light")) { |
||
| 233 | $('.sidebar-style-option', panel).val("light"); |
||
| 234 | } |
||
| 235 | |||
| 236 | if ($(".page-sidebar-menu").hasClass("page-sidebar-menu-hover-submenu")) { |
||
| 237 | $('.sidebar-menu-option', panel).val("hover"); |
||
| 238 | } |
||
| 239 | |||
| 240 | var sidebarOption = $('.sidebar-option', panel).val(); |
||
| 241 | var headerOption = $('.page-header-option', panel).val(); |
||
| 242 | var footerOption = $('.page-footer-option', panel).val(); |
||
| 243 | var sidebarPosOption = $('.sidebar-pos-option', panel).val(); |
||
| 244 | var sidebarStyleOption = $('.sidebar-style-option', panel).val(); |
||
| 245 | var sidebarMenuOption = $('.sidebar-menu-option', panel).val(); |
||
| 246 | |||
| 247 | $('.layout-option, .page-header-top-dropdown-style-option, .page-header-option, .sidebar-option, .page-footer-option, .sidebar-pos-option, .sidebar-style-option, .sidebar-menu-option', panel).change(setLayout); |
||
| 248 | }; |
||
| 249 | |||
| 250 | // handle theme style |
||
| 251 | var setThemeStyle = function(style) { |
||
| 252 | var file = (style === 'rounded' ? 'components-rounded' : 'components'); |
||
| 253 | file = (Metronic.isRTL() ? file + '-rtl' : file); |
||
| 254 | |||
| 255 | $('#style_components').attr("href", Metronic.getGlobalCssPath() + file + ".css"); |
||
| 256 | |||
| 257 | if ($.cookie) { |
||
| 258 | $.cookie('layout-style-option', style); |
||
| 259 | } |
||
| 260 | }; |
||
| 261 | |||
| 262 | return { |
||
| 263 | |||
| 264 | //main function to initiate the theme |
||
| 265 | init: function() { |
||
| 266 | // handles style customer tool |
||
| 267 | handleTheme(); |
||
| 268 | |||
| 269 | // handle layout style change |
||
| 270 | $('.theme-panel .layout-style-option').change(function() { |
||
| 271 | setThemeStyle($(this).val()); |
||
| 272 | }); |
||
| 273 | |||
| 274 | // set layout style from cookie |
||
| 275 | if ($.cookie && $.cookie('layout-style-option') === 'rounded') { |
||
| 276 | setThemeStyle($.cookie('layout-style-option')); |
||
| 277 | $('.theme-panel .layout-style-option').val($.cookie('layout-style-option')); |
||
| 278 | } |
||
| 279 | } |
||
| 280 | }; |
||
| 281 | |||
| 282 | }(); |