Rev 182 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 179 | espaco | 1 | /** |
| 2 | * PrimeFaces Poseidon Layout |
||
| 3 | */ |
||
| 4 | PrimeFaces.widget.Poseidon = PrimeFaces.widget.BaseWidget.extend({ |
||
| 5 | |||
| 6 | init: function(cfg) { |
||
| 7 | this._super(cfg); |
||
| 8 | this.wrapper = $(document.body).children('.layout-wrapper'); |
||
| 9 | var $this = this; |
||
| 10 | |||
| 11 | $(function() { |
||
| 12 | $this._init(); |
||
| 13 | |||
| 14 | if (!$this.wrapper.hasClass('layout-horizontal')) { |
||
| 15 | $this.restoreMenuState(); |
||
| 16 | } |
||
| 17 | }); |
||
| 18 | }, |
||
| 19 | |||
| 20 | _init: function() { |
||
| 21 | this.contentWrapper = this.wrapper.children('.layout-main'); |
||
| 22 | this.topbar = this.wrapper.find('.layout-topbar'); |
||
| 23 | this.topbarItems = this.topbar.find('.layout-topbar-actions > li.topbar-item'); |
||
| 24 | this.topbarLinks = this.topbarItems.children('a'); |
||
| 25 | this.topbarSearchItemMenu = this.topbar.find('.search-item'); |
||
| 26 | |||
| 27 | this.menuWrapper = this.wrapper.find('.menu-wrapper'); |
||
| 28 | this.menuContainer = this.menuWrapper.find('.layout-menu-container'); |
||
| 29 | this.menu = this.menuWrapper.find('.layout-menu'); |
||
| 30 | this.menuButton = this.topbar.find('.menu-button'); |
||
| 31 | this.menulinks = this.menu.find('a'); |
||
| 32 | |||
| 33 | this.profileContainer = $('.layout-profile'); |
||
| 34 | this.profileButton = this.profileContainer.children('.layout-profile-button'); |
||
| 35 | this.profileMenu = this.profileContainer.children('.layout-profile-menu'); |
||
| 36 | |||
| 37 | this.rightpanel = this.wrapper.find('.layout-rightpanel'); |
||
| 38 | this.rightpanelButton = this.topbar.find('.layout-rightpanel-button'); |
||
| 39 | this.rightpanelExitButton = this.rightpanel.find('.rightpanel-exit-button'); |
||
| 40 | |||
| 41 | this.configButton = $('#layout-config-button'); |
||
| 42 | this.configMenu = $('#layout-config'); |
||
| 43 | this.configMenuClose = this.configMenu.find('> .layout-config-content > .layout-config-close'); |
||
| 44 | |||
| 45 | this.bindEvents(); |
||
| 46 | }, |
||
| 47 | |||
| 48 | toggleClass: function(el, className) { |
||
| 49 | if (el.hasClass(className)) { |
||
| 50 | el.removeClass(className); |
||
| 51 | } |
||
| 52 | else { |
||
| 53 | el.addClass(className); |
||
| 54 | } |
||
| 55 | }, |
||
| 56 | |||
| 57 | bindEvents: function() { |
||
| 58 | var $this = this; |
||
| 59 | |||
| 60 | this.bindTopbarEvents(); |
||
| 61 | this.bindMenuEvents(); |
||
| 62 | this.bindRightPanelEvents(); |
||
| 63 | this.bindConfigEvents(); |
||
| 64 | |||
| 65 | $(document.body).off('click.layoutBody').on('click.layoutBody', function() { |
||
| 66 | if (!$this.menuClick) { |
||
| 67 | $this.wrapper.removeClass('layout-overlay-active layout-mobile-active'); |
||
| 68 | $(document.body).removeClass('blocked-scroll'); |
||
| 69 | |||
| 70 | if ($this.isHorizontal() ) { |
||
| 71 | $this.menu.find('.active-menuitem').removeClass('active-menuitem'); |
||
| 72 | $this.menuActive = false; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | if (!$this.profileMenuClick && ($this.isHorizontal())) { |
||
| 77 | $this.profileContainer.removeClass('layout-profile-active'); |
||
| 78 | } |
||
| 79 | |||
| 80 | if (!$this.topbarItemClicked) { |
||
| 81 | $this.removeTopbarClassFromAllItems(null, 'active-topmenuitem', $this.topbarItems.filter('.active-topmenuitem')); |
||
| 82 | } |
||
| 83 | |||
| 84 | if (!$this.rightpanelClicked) { |
||
| 85 | $this.wrapper.removeClass('layout-rightpanel-active'); |
||
| 86 | } |
||
| 87 | |||
| 88 | if (!$this.configMenuClicked && $this.configMenu.hasClass('layout-config-active')) { |
||
| 89 | if (!$this.wrapper.hasClass('layout-mobile-active') && !$this.wrapper.hasClass('layout-overlay-active')) { |
||
| 90 | $(document.body).removeClass('blocked-scroll'); |
||
| 91 | } |
||
| 92 | $this.configMenu.removeClass('layout-config-active'); |
||
| 93 | } |
||
| 94 | |||
| 95 | $this.topbarItemClicked = false; |
||
| 96 | $this.rightpanelClicked = false; |
||
| 97 | $this.menuClick = false; |
||
| 98 | $this.profileMenuClick = false; |
||
| 99 | $this.configMenuClicked = false; |
||
| 100 | }); |
||
| 101 | }, |
||
| 102 | |||
| 103 | bindConfigEvents: function() { |
||
| 104 | var $this = this; |
||
| 105 | |||
| 106 | this.configButton.off('click.config').on('click.config', function(e) { |
||
| 107 | $this.configMenuClicked = true; |
||
| 108 | |||
| 109 | if ($this.configMenu.hasClass('layout-config-active')) { |
||
| 110 | $this.configMenu.removeClass('layout-config-active'); |
||
| 111 | $(document.body).removeClass('blocked-scroll'); |
||
| 112 | } |
||
| 113 | else { |
||
| 114 | $this.configMenu.addClass('layout-config-active'); |
||
| 115 | $(document.body).addClass('blocked-scroll'); |
||
| 116 | } |
||
| 117 | |||
| 118 | e.preventDefault(); |
||
| 119 | }); |
||
| 120 | |||
| 121 | this.configMenuClose.off('click.config').on('click.config', function(e) { |
||
| 122 | $this.configMenu.removeClass('layout-config-active'); |
||
| 123 | $this.configMenuClicked = true; |
||
| 124 | $(document.body).removeClass('blocked-scroll'); |
||
| 125 | e.preventDefault(); |
||
| 126 | }); |
||
| 127 | |||
| 128 | this.configMenu.off('click.configMenu').on('click.configMenu', function() { |
||
| 129 | $this.configMenuClicked = true; |
||
| 130 | }); |
||
| 131 | }, |
||
| 132 | |||
| 133 | bindMenuEvents: function() { |
||
| 134 | var $this = this; |
||
| 135 | |||
| 136 | this.menuWrapper.off('click.menu').on('click.menu', function() { |
||
| 137 | if (!$this.profileMenuClick) { |
||
| 138 | $this.menuClick = true; |
||
| 139 | } |
||
| 140 | }); |
||
| 141 | |||
| 142 | this.menuButton.off('click.menu').on('click.menu', function(e) { |
||
| 143 | $this.menuClick = true; |
||
| 144 | |||
| 145 | if ($this.isMobile()) { |
||
| 146 | if ($this.wrapper.hasClass('layout-mobile-active')) { |
||
| 147 | $this.wrapper.removeClass('layout-mobile-active'); |
||
| 148 | $(document.body).removeClass('blocked-scroll'); |
||
| 149 | } |
||
| 150 | else { |
||
| 151 | $this.wrapper.addClass('layout-mobile-active'); |
||
| 152 | $(document.body).addClass('blocked-scroll'); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | else { |
||
| 156 | if ($this.isStatic()) { |
||
| 157 | $this.wrapper.toggleClass('layout-static-active'); |
||
| 158 | $this.saveStaticMenuState(); |
||
| 159 | } |
||
| 160 | else { |
||
| 161 | $this.wrapper.toggleClass('layout-overlay-active'); |
||
| 162 | } |
||
| 163 | } |
||
| 164 | |||
| 165 | e.preventDefault(); |
||
| 166 | }); |
||
| 167 | |||
| 168 | this.menulinks.off('click.menu').on('click.menu', function(e) { |
||
| 169 | var link = $(this), |
||
| 170 | item = link.parent(), |
||
| 171 | submenu = item.children('ul'); |
||
| 172 | horizontal = $this.isHorizontal(); |
||
| 173 | $this.menuClick = true; |
||
| 174 | |||
| 175 | if ($this.isHorizontal() ) { |
||
| 176 | submenu.css('display',''); |
||
| 177 | |||
| 178 | if (item.hasClass('active-menuitem')) { |
||
| 179 | if (submenu.length) { |
||
| 180 | item.removeClass('active-menuitem'); |
||
| 181 | e.preventDefault(); |
||
| 182 | } |
||
| 183 | |||
| 184 | if (item.parent().is($this.jq)) { |
||
| 185 | $this.menuActive = false; |
||
| 186 | } |
||
| 187 | } |
||
| 188 | else { |
||
| 189 | if (submenu.length > 0) { |
||
| 190 | e.preventDefault(); |
||
| 191 | } |
||
| 192 | |||
| 193 | item.siblings('.active-menuitem').removeClass('active-menuitem'); |
||
| 194 | item.addClass('active-menuitem'); |
||
| 195 | |||
| 196 | if (item.parent().is($this.jq)) { |
||
| 197 | $this.menuActive = true; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | } |
||
| 201 | else { |
||
| 202 | if(item.hasClass('active-menuitem')) { |
||
| 203 | if(submenu.length) { |
||
| 204 | item.removeClass('active-menuitem'); |
||
| 205 | |||
| 206 | if(horizontal) { |
||
| 207 | if(item.parent().is($this.jq)) { |
||
| 208 | $this.menuActive = false; |
||
| 209 | } |
||
| 210 | item.removeClass('active-menuitem'); |
||
| 211 | } |
||
| 212 | else { |
||
| 213 | submenu.slideUp(function() { |
||
| 214 | item.removeClass('active-menuitem'); |
||
| 215 | }); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | } |
||
| 219 | else { |
||
| 220 | if (horizontal) { |
||
| 221 | $this.deactivateItems(item.siblings()); |
||
| 222 | item.addClass('active-menuitem'); |
||
| 223 | $this.menuActive = true; |
||
| 224 | } |
||
| 225 | else { |
||
| 226 | $this.deactivateItems(item.siblings(), true); |
||
| 227 | var groupedItems = item.parent().closest('li'); |
||
| 228 | if (groupedItems && groupedItems.length > 0) { |
||
| 229 | $this.deactivateItems(groupedItems.siblings(), true); |
||
| 230 | } |
||
| 231 | $this.activate(item); |
||
| 232 | $.cookie('poseidon_menu_scroll_state', link.attr('href') + ',' + $this.menuContainer.scrollTop(), { path: '/' }); |
||
| 233 | } |
||
| 234 | } |
||
| 235 | } |
||
| 236 | |||
| 237 | if(submenu.length) { |
||
| 238 | e.preventDefault(); |
||
| 239 | } |
||
| 240 | }); |
||
| 241 | |||
| 242 | this.menu.find('ul').off('click.menu').on('click.menu', function() { |
||
| 243 | if ($this.isHorizontal()) { |
||
| 244 | $this.horizontalMenuClick = true; |
||
| 245 | } |
||
| 246 | }); |
||
| 247 | |||
| 248 | this.profileButton.off('click.profile').on('click.profile', function (e) { |
||
| 249 | if (!$this.isHorizontal() ) { |
||
| 250 | $this.profileContainer.toggleClass('layout-profile-active'); |
||
| 251 | $this.profileMenu.slideToggle(); |
||
| 252 | } |
||
| 253 | else { |
||
| 254 | $this.profileMenuClick = true; |
||
| 255 | |||
| 256 | if ($this.profileContainer.hasClass('layout-profile-active')) { |
||
| 257 | $this.profileMenu.addClass('fadeOutUp'); |
||
| 258 | |||
| 259 | setTimeout(function () { |
||
| 260 | $this.profileContainer.removeClass('layout-profile-active'); |
||
| 261 | $this.profileMenu.removeClass('fadeOutUp'); |
||
| 262 | }, 150); |
||
| 263 | } |
||
| 264 | else { |
||
| 265 | $this.profileContainer.addClass('layout-profile-active'); |
||
| 266 | $this.profileMenu.addClass('fadeInDown'); |
||
| 267 | } |
||
| 268 | } |
||
| 269 | |||
| 270 | e.preventDefault(); |
||
| 271 | }); |
||
| 272 | |||
| 273 | this.menu.find('> li').on('mouseenter', function(e) { |
||
| 274 | if($this.isHorizontal() && $this.menuActive) { |
||
| 275 | var item = $(this); |
||
| 276 | |||
| 277 | if(!item.hasClass('active-menuitem')) { |
||
| 278 | $this.menu.find('.active-menuitem').removeClass('active-menuitem'); |
||
| 279 | |||
| 280 | if($this.menuActive) { |
||
| 281 | item.addClass('active-menuitem'); |
||
| 282 | } |
||
| 283 | } |
||
| 284 | } |
||
| 285 | }); |
||
| 286 | }, |
||
| 287 | |||
| 288 | bindTopbarEvents: function() { |
||
| 289 | var $this = this; |
||
| 290 | |||
| 291 | this.topbarLinks.off('click.topbar').on('click.topbar', function(e) { |
||
| 292 | var link = $(this), |
||
| 293 | item = link.parent(), |
||
| 294 | submenu = item.children('ul'); |
||
| 295 | |||
| 296 | if ($this.isMobile()) { |
||
| 297 | $this.removeTopbarClassFromAllItems(null, 'active-topmenuitem', $this.topbarItems.filter('.active-topmenuitem').not(item)); |
||
| 298 | } |
||
| 299 | else { |
||
| 300 | $this.removeTopbarClassFromAllItems(item, 'active-topmenuitem'); |
||
| 301 | } |
||
| 302 | $this.addTopbarClass(item, 'active-topmenuitem'); |
||
| 303 | |||
| 304 | $this.topbarItemClicked = true; |
||
| 305 | |||
| 306 | if (submenu.length) { |
||
| 307 | e.preventDefault(); |
||
| 308 | } |
||
| 309 | }); |
||
| 310 | |||
| 311 | this.topbarSearchItemMenu.off('click.topbar').on('click.topbar', function(e) { |
||
| 312 | $this.topbarItemClicked = true; |
||
| 313 | }); |
||
| 314 | }, |
||
| 315 | |||
| 316 | bindRightPanelEvents: function() { |
||
| 317 | var $this = this; |
||
| 318 | var changeRightpanelState = function(e) { |
||
| 319 | this.toggleClass(this.wrapper, 'layout-rightpanel-active'); |
||
| 320 | |||
| 321 | this.rightpanelClicked = true; |
||
| 322 | e.preventDefault(); |
||
| 323 | }; |
||
| 324 | |||
| 325 | this.rightpanelButton.off('click.rightpanel').on('click.rightpanel', changeRightpanelState.bind(this)); |
||
| 326 | this.rightpanelExitButton.off('click.rightpanel').on('click.rightpanel', changeRightpanelState.bind(this)); |
||
| 327 | |||
| 328 | this.rightpanel.off('click.rightpanel').on('click.rightpanel', function() { |
||
| 329 | $this.rightpanelClicked = true; |
||
| 330 | }); |
||
| 331 | }, |
||
| 332 | |||
| 333 | activate: function(item) { |
||
| 334 | var submenu = item.children('ul'); |
||
| 335 | item.addClass('active-menuitem'); |
||
| 336 | |||
| 337 | if(submenu.length) { |
||
| 338 | submenu.slideDown(); |
||
| 339 | } |
||
| 340 | }, |
||
| 341 | |||
| 342 | deactivate: function(item) { |
||
| 343 | var submenu = item.children('ul'); |
||
| 344 | item.removeClass('active-menuitem'); |
||
| 345 | |||
| 346 | if(submenu.length) { |
||
| 347 | submenu.hide(); |
||
| 348 | } |
||
| 349 | }, |
||
| 350 | |||
| 351 | deactivateItems: function(items, animate) { |
||
| 352 | var $this = this; |
||
| 353 | |||
| 354 | for(var i = 0; i < items.length; i++) { |
||
| 355 | var item = items.eq(i), |
||
| 356 | submenu = item.children('ul'); |
||
| 357 | |||
| 358 | if(submenu.length) { |
||
| 359 | if(item.hasClass('active-menuitem')) { |
||
| 360 | var activeSubItems = item.find('.active-menuitem'); |
||
| 361 | item.removeClass('active-menuitem'); |
||
| 362 | |||
| 363 | if(animate) { |
||
| 364 | submenu.slideUp('normal', function() { |
||
| 365 | $(this).parent().find('.active-menuitem').each(function() { |
||
| 366 | $this.deactivate($(this)); |
||
| 367 | }); |
||
| 368 | }); |
||
| 369 | } |
||
| 370 | else { |
||
| 371 | item.find('.active-menuitem').each(function() { |
||
| 372 | $this.deactivate($(this)); |
||
| 373 | }); |
||
| 374 | } |
||
| 375 | } |
||
| 376 | else { |
||
| 377 | item.find('.active-menuitem').each(function() { |
||
| 378 | var subItem = $(this); |
||
| 379 | $this.deactivate(subItem); |
||
| 380 | }); |
||
| 381 | } |
||
| 382 | } |
||
| 383 | else if(item.hasClass('active-menuitem')) { |
||
| 384 | $this.deactivate(item); |
||
| 385 | } |
||
| 386 | } |
||
| 387 | }, |
||
| 388 | |||
| 389 | saveStaticMenuState: function() { |
||
| 390 | if(this.isHorizontal()) { |
||
| 391 | return; |
||
| 392 | } |
||
| 393 | |||
| 394 | if (!this.wrapper.hasClass('layout-static-active')) |
||
| 395 | $.cookie('poseidon_menu_static', 'poseidon_menu_static', {path: '/'}); |
||
| 396 | else |
||
| 397 | $.removeCookie('poseidon_menu_static', {path: '/'}); |
||
| 398 | }, |
||
| 399 | |||
| 400 | clearMenuState: function() { |
||
| 401 | $.removeCookie('poseidon_menu_static', {path: '/'}); |
||
| 402 | }, |
||
| 403 | |||
| 404 | clearActiveItems: function() { |
||
| 405 | var activeItems = this.jq.find('li.active-menuitem'), |
||
| 406 | subContainers = activeItems.children('ul'); |
||
| 407 | |||
| 408 | activeItems.removeClass('active-menuitem'); |
||
| 409 | if(subContainers && subContainers.length) { |
||
| 410 | subContainers.hide(); |
||
| 411 | } |
||
| 412 | }, |
||
| 413 | |||
| 414 | clearLayoutState: function() { |
||
| 415 | this.clearMenuState(); |
||
| 416 | this.clearActiveItems(); |
||
| 417 | }, |
||
| 418 | |||
| 419 | restoreMenuState: function () { |
||
| 420 | var link = $('a[href^="' + this.cfg.pathname + '"]'); |
||
| 421 | var $this = this; |
||
| 422 | if (link.length) { |
||
| 423 | var menuitem = link.closest('li'); |
||
| 424 | var parentMenu = menuitem.closest('ul'); |
||
| 425 | |||
| 426 | menuitem.addClass('active-menuitem'); |
||
| 427 | if (parentMenu.length) { |
||
| 428 | var parentMenuItem = parentMenu.closest('li'); |
||
| 429 | while (!parentMenuItem.hasClass('layout-root-menuitem')) { |
||
| 430 | parentMenuItem.addClass('active-menuitem'); |
||
| 431 | parentMenu.show(); |
||
| 432 | |||
| 433 | parentMenu = parentMenuItem.closest('ul'); |
||
| 434 | if (!parentMenu.length) { |
||
| 435 | break; |
||
| 436 | } |
||
| 437 | |||
| 438 | parentMenuItem = parentMenu.closest('li'); |
||
| 439 | } |
||
| 440 | |||
| 441 | if (parentMenuItem.hasClass('layout-root-menuitem') && !parentMenuItem.closest('ul').hasClass('layout-menu')) { |
||
| 442 | parentMenuItem.addClass('active-menuitem'); |
||
| 443 | parentMenu.show(); |
||
| 444 | } |
||
| 445 | } |
||
| 446 | |||
| 447 | setTimeout(function() { |
||
| 448 | $this.restoreScrollState(menuitem); |
||
| 449 | }, 100) |
||
| 450 | } |
||
| 451 | |||
| 452 | var sidebarCookie = $.cookie('poseidon_menu_static'); |
||
| 453 | if (sidebarCookie) { |
||
| 454 | this.wrapper.removeClass('layout-static-active'); |
||
| 455 | } |
||
| 456 | }, |
||
| 457 | |||
| 458 | restoreScrollState: function(menuitem) { |
||
| 459 | var scrollState = $.cookie('poseidon_menu_scroll_state'); |
||
| 460 | if (scrollState) { |
||
| 461 | var state = scrollState.split(','); |
||
| 462 | if (state[0].startsWith(this.cfg.pathname) || this.isScrolledIntoView(menuitem, state[1])) { |
||
| 463 | this.menuContainer.scrollTop(parseInt(state[1], 10)); |
||
| 464 | } |
||
| 465 | else { |
||
| 466 | this.scrollIntoView(menuitem.get(0)); |
||
| 467 | $.removeCookie('poseidon_menu_scroll_state', { path: '/' }); |
||
| 468 | } |
||
| 469 | } |
||
| 470 | else if (!this.isScrolledIntoView(menuitem, menuitem.scrollTop())){ |
||
| 471 | this.scrollIntoView(menuitem.get(0)); |
||
| 472 | } |
||
| 473 | }, |
||
| 474 | |||
| 475 | scrollIntoView: function(elem) { |
||
| 476 | if (document.documentElement.scrollIntoView) { |
||
| 477 | elem.scrollIntoView(); |
||
| 478 | } |
||
| 479 | }, |
||
| 480 | |||
| 481 | isScrolledIntoView: function(elem, scrollTop) { |
||
| 482 | var viewBottom = parseInt(scrollTop, 10) + this.menuContainer.height(); |
||
| 483 | |||
| 484 | var elemTop = elem.position().top; |
||
| 485 | var elemBottom = elemTop + elem.height(); |
||
| 486 | |||
| 487 | return ((elemBottom <= viewBottom) && (elemTop >= scrollTop)); |
||
| 488 | }, |
||
| 489 | |||
| 490 | removeTopbarClassFromAllItems: function(item, className, items) { |
||
| 491 | var activeItems = item != null ? item.siblings('.' + className) : items; |
||
| 492 | |||
| 493 | activeItems.removeClass(className); |
||
| 494 | activeItems.children('ul').removeClass('fadeInDown'); |
||
| 495 | }, |
||
| 496 | |||
| 497 | addTopbarClass: function(item, className) { |
||
| 498 | var submenu = item.children('ul'); |
||
| 499 | |||
| 500 | if (submenu.length) { |
||
| 501 | if (item.hasClass(className)) { |
||
| 502 | submenu.removeClass('fadeInDown').addClass('fadeOutUp'); |
||
| 503 | |||
| 504 | setTimeout(function() { |
||
| 505 | item.removeClass(className); |
||
| 506 | submenu.removeClass('fadeOutUp'); |
||
| 507 | }, 100); |
||
| 508 | } |
||
| 509 | else { |
||
| 510 | item.addClass(className); |
||
| 511 | submenu.addClass('fadeInDown'); |
||
| 512 | } |
||
| 513 | } |
||
| 514 | }, |
||
| 515 | |||
| 516 | hideTopBar: function() { |
||
| 517 | var $this = this; |
||
| 518 | this.topbarMenu.addClass('fadeOutUp'); |
||
| 519 | |||
| 520 | setTimeout(function() { |
||
| 521 | $this.topbarMenu.removeClass('fadeOutUp topbar-menu-visible'); |
||
| 522 | },500); |
||
| 523 | }, |
||
| 524 | |||
| 525 | isMobile: function() { |
||
| 526 | return window.innerWidth <= 992; |
||
| 527 | }, |
||
| 528 | |||
| 529 | isHorizontal: function() { |
||
| 530 | return this.wrapper.hasClass('layout-horizontal') && !this.isMobile(); |
||
| 531 | }, |
||
| 532 | isStatic: function() { |
||
| 533 | return this.wrapper.hasClass('layout-static') && !this.isMobile(); |
||
| 534 | } |
||
| 535 | }); |
||
| 536 | |||
| 537 | PrimeFaces.PoseidonConfigurator = { |
||
| 538 | |||
| 539 | changeLayout: function( componentTheme, darkMode ) { |
||
| 540 | this.changeLayoutsTheme(darkMode); |
||
| 541 | this.changeDemo(darkMode); |
||
| 542 | this.changeComponentsTheme(componentTheme, darkMode); |
||
| 543 | this.changeSectionTheme( darkMode, 'layout-menu'); |
||
| 544 | this.changeSectionTheme( darkMode , 'layout-topbar'); |
||
| 545 | }, |
||
| 546 | |||
| 547 | changeLayoutsTheme: function(darkMode) { |
||
| 548 | newLayout = '-' + darkMode; |
||
| 549 | var linkElement = $('link[href*="layout-"]'); |
||
| 550 | var href = linkElement.attr('href'); |
||
| 551 | var startIndexOf = href.indexOf('layout-') + 6; |
||
| 552 | var endIndexOf = href.indexOf('.css'); |
||
| 553 | var currentColor = href.substring(startIndexOf, endIndexOf); |
||
| 554 | this.replaceLink(linkElement, href.replace(currentColor, newLayout)); |
||
| 555 | }, |
||
| 556 | |||
| 557 | changeComponentsTheme: function(theme, darkMode) { |
||
| 558 | theme = this.getColor(theme, darkMode); |
||
| 559 | var library = 'primefaces-poseidon'; |
||
| 560 | var linkElement = $('link[href*="theme.css"]'); |
||
| 561 | var href = linkElement.attr('href'); |
||
| 562 | var index = href.indexOf(library) + 1; |
||
| 563 | var currentTheme = href.substring(index + library.length); |
||
| 564 | |||
| 565 | this.replaceLink(linkElement, href.replace(currentTheme, theme)); |
||
| 566 | }, |
||
| 567 | |||
| 568 | changeDemo: function(darkMode) { |
||
| 569 | newLayout = '-' + darkMode; |
||
| 570 | var linkElement = $('link[href*="demo-"]'); |
||
| 571 | var href = linkElement.attr('href'); |
||
| 572 | var startIndexOf = href.indexOf('demo-') + 4; |
||
| 573 | var endIndexOf = href.indexOf('.css'); |
||
| 574 | var currentColor = href.substring(startIndexOf, endIndexOf); |
||
| 575 | |||
| 576 | this.replaceLink(linkElement, href.replace(currentColor, newLayout)); |
||
| 577 | }, |
||
| 578 | |||
| 579 | changeMenuMode: function(menuMode) { |
||
| 580 | var wrapper = $(document.body).children('.layout-wrapper'); |
||
| 581 | switch (menuMode) { |
||
| 582 | case 'layout-static layout-static-active': |
||
| 583 | wrapper.addClass('layout-static layout-static-active').removeClass('layout-overlay layout-slim layout-horizontal layout-slim-plus'); |
||
| 584 | this.clearLayoutState(); |
||
| 585 | break; |
||
| 586 | |||
| 587 | case 'layout-overlay': |
||
| 588 | wrapper.addClass('layout-overlay').removeClass('layout-static layout-slim layout-horizontal layout-slim-plus layout-static-active'); |
||
| 589 | this.clearLayoutState(); |
||
| 590 | break; |
||
| 591 | |||
| 592 | case 'layout-horizontal': |
||
| 593 | wrapper.addClass('layout-horizontal').removeClass('layout-static layout-overlay layout-slim layout-slim-plus layout-static-active'); |
||
| 594 | this.clearLayoutState(); |
||
| 595 | break; |
||
| 596 | |||
| 597 | default: |
||
| 598 | wrapper.addClass('layout-static').removeClass('layout-overlay layout-slim layout-horizontal layout-slim-plus '); |
||
| 599 | this.clearLayoutState(); |
||
| 600 | break; |
||
| 601 | } |
||
| 602 | }, |
||
| 603 | |||
| 604 | changeSectionTheme: function(theme, section) { |
||
| 605 | var wrapperElement = $('.layout-wrapper'); |
||
| 606 | var styleClass = wrapperElement.attr('class'); |
||
| 607 | var tokens = styleClass.split(' '); |
||
| 608 | var sectionClass; |
||
| 609 | for (var i = 0; i < tokens.length; i++) { |
||
| 610 | if (tokens[i].indexOf(section + '-') > -1) { |
||
| 611 | sectionClass = tokens[i]; |
||
| 612 | break; |
||
| 613 | } |
||
| 614 | } |
||
| 615 | |||
| 616 | wrapperElement.attr('class', styleClass.replace(sectionClass, section + '-' + theme)); |
||
| 617 | }, |
||
| 618 | |||
| 619 | beforeResourceChange: function() { |
||
| 620 | PrimeFaces.ajax.RESOURCE = null; //prevent resource append |
||
| 621 | }, |
||
| 622 | |||
| 623 | replaceLink: function(linkElement, href) { |
||
| 624 | PrimeFaces.ajax.RESOURCE = 'javax.faces.Resource'; |
||
| 625 | |||
| 626 | var isIE = this.isIE(); |
||
| 627 | |||
| 628 | if (isIE) { |
||
| 629 | linkElement.attr('href', href); |
||
| 630 | } |
||
| 631 | else { |
||
| 632 | var cloneLinkElement = linkElement.clone(false); |
||
| 633 | |||
| 634 | cloneLinkElement.attr('href', href); |
||
| 635 | linkElement.after(cloneLinkElement); |
||
| 636 | |||
| 637 | cloneLinkElement.off('load').on('load', function() { |
||
| 638 | linkElement.remove(); |
||
| 639 | |||
| 640 | // for dashboard |
||
| 641 | setTimeout(function() { |
||
| 642 | if (window['redrawDoughnut']) { |
||
| 643 | window.redrawDoughnut(); |
||
| 644 | } |
||
| 645 | }, 1); |
||
| 646 | }); |
||
| 647 | } |
||
| 648 | }, |
||
| 649 | |||
| 650 | getColor: function(name, darkMode) { |
||
| 651 | return name + '-' + darkMode; |
||
| 652 | }, |
||
| 653 | |||
| 654 | isIE: function() { |
||
| 655 | return /(MSIE|Trident\/|Edge\/)/i.test(navigator.userAgent); |
||
| 656 | }, |
||
| 657 | |||
| 658 | changeMenuToRTL: function() { |
||
| 659 | $('.layout-wrapper').toggleClass('layout-rtl'); |
||
| 660 | }, |
||
| 661 | |||
| 662 | clearLayoutState: function() { |
||
| 663 | var menu = PF('PoseidonMenuWidget'); |
||
| 664 | |||
| 665 | if (menu) { |
||
| 666 | menu.clearLayoutState(); |
||
| 667 | } |
||
| 668 | }, |
||
| 669 | |||
| 670 | updateInputStyle: function(value) { |
||
| 671 | if (value === 'filled') |
||
| 672 | $(document.body).addClass('ui-input-filled'); |
||
| 673 | else |
||
| 674 | $(document.body).removeClass('ui-input-filled'); |
||
| 675 | } |
||
| 676 | }; |
||
| 677 | |||
| 678 | /*! |
||
| 679 | * jQuery Cookie Plugin v1.4.1 |
||
| 680 | * https://github.com/carhartl/jquery-cookie |
||
| 681 | * |
||
| 682 | * Copyright 2006, 2014 Klaus Hartl |
||
| 683 | * Released under the MIT license |
||
| 684 | */ |
||
| 685 | (function (factory) { |
||
| 686 | if (typeof define === 'function' && define.amd) { |
||
| 687 | // AMD (Register as an anonymous module) |
||
| 688 | define(['jquery'], factory); |
||
| 689 | } else if (typeof exports === 'object') { |
||
| 690 | // Node/CommonJS |
||
| 691 | module.exports = factory(require('jquery')); |
||
| 692 | } else { |
||
| 693 | // Browser globals |
||
| 694 | factory(jQuery); |
||
| 695 | } |
||
| 696 | }(function ($) { |
||
| 697 | |||
| 698 | var pluses = /\+/g; |
||
| 699 | |||
| 700 | function encode(s) { |
||
| 701 | return config.raw ? s : encodeURIComponent(s); |
||
| 702 | } |
||
| 703 | |||
| 704 | function decode(s) { |
||
| 705 | return config.raw ? s : decodeURIComponent(s); |
||
| 706 | } |
||
| 707 | |||
| 708 | function stringifyCookieValue(value) { |
||
| 709 | return encode(config.json ? JSON.stringify(value) : String(value)); |
||
| 710 | } |
||
| 711 | |||
| 712 | function parseCookieValue(s) { |
||
| 713 | if (s.indexOf('"') === 0) { |
||
| 714 | // This is a quoted cookie as according to RFC2068, unescape... |
||
| 715 | s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\'); |
||
| 716 | } |
||
| 717 | |||
| 718 | try { |
||
| 719 | // Replace server-side written pluses with spaces. |
||
| 720 | // If we can't decode the cookie, ignore it, it's unusable. |
||
| 721 | // If we can't parse the cookie, ignore it, it's unusable. |
||
| 722 | s = decodeURIComponent(s.replace(pluses, ' ')); |
||
| 723 | return config.json ? JSON.parse(s) : s; |
||
| 724 | } catch (e) { } |
||
| 725 | } |
||
| 726 | |||
| 727 | function read(s, converter) { |
||
| 728 | var value = config.raw ? s : parseCookieValue(s); |
||
| 729 | return $.isFunction(converter) ? converter(value) : value; |
||
| 730 | } |
||
| 731 | |||
| 732 | var config = $.cookie = function (key, value, options) { |
||
| 733 | |||
| 734 | // Write |
||
| 735 | |||
| 736 | if (arguments.length > 1 && !$.isFunction(value)) { |
||
| 737 | options = $.extend({}, config.defaults, options); |
||
| 738 | |||
| 739 | if (typeof options.expires === 'number') { |
||
| 740 | var days = options.expires, t = options.expires = new Date(); |
||
| 741 | t.setMilliseconds(t.getMilliseconds() + days * 864e+5); |
||
| 742 | } |
||
| 743 | |||
| 744 | return (document.cookie = [ |
||
| 745 | encode(key), '=', stringifyCookieValue(value), |
||
| 746 | options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE |
||
| 747 | options.path ? '; path=' + options.path : '', |
||
| 748 | options.domain ? '; domain=' + options.domain : '', |
||
| 749 | options.secure ? '; secure' : '' |
||
| 750 | ].join('')); |
||
| 751 | } |
||
| 752 | |||
| 753 | // Read |
||
| 754 | |||
| 755 | var result = key ? undefined : {}, |
||
| 756 | // To prevent the for loop in the first place assign an empty array |
||
| 757 | // in case there are no cookies at all. Also prevents odd result when |
||
| 758 | // calling $.cookie(). |
||
| 759 | cookies = document.cookie ? document.cookie.split('; ') : [], |
||
| 760 | i = 0, |
||
| 761 | l = cookies.length; |
||
| 762 | |||
| 763 | for (; i < l; i++) { |
||
| 764 | var parts = cookies[i].split('='), |
||
| 765 | name = decode(parts.shift()), |
||
| 766 | cookie = parts.join('='); |
||
| 767 | |||
| 768 | if (key === name) { |
||
| 769 | // If second argument (value) is a function it's a converter... |
||
| 770 | result = read(cookie, value); |
||
| 771 | break; |
||
| 772 | } |
||
| 773 | |||
| 774 | // Prevent storing a cookie that we couldn't decode. |
||
| 775 | if (!key && (cookie = read(cookie)) !== undefined) { |
||
| 776 | result[name] = cookie; |
||
| 777 | } |
||
| 778 | } |
||
| 779 | |||
| 780 | return result; |
||
| 781 | }; |
||
| 782 | |||
| 783 | config.defaults = {}; |
||
| 784 | |||
| 785 | $.removeCookie = function (key, options) { |
||
| 786 | // Must not alter options, thus extending a fresh object... |
||
| 787 | $.cookie(key, '', $.extend({}, options, { expires: -1 })); |
||
| 788 | return !$.cookie(key); |
||
| 789 | }; |
||
| 790 | |||
| 791 | })); |
||
| 792 | |||
| 793 | if (PrimeFaces.widget.InputSwitch) { |
||
| 794 | PrimeFaces.widget.InputSwitch = PrimeFaces.widget.InputSwitch.extend({ |
||
| 795 | |||
| 796 | init: function (cfg) { |
||
| 797 | this._super(cfg); |
||
| 798 | |||
| 799 | if (this.input.prop('checked')) { |
||
| 800 | this.jq.addClass('ui-inputswitch-checked'); |
||
| 801 | } |
||
| 802 | }, |
||
| 803 | |||
| 804 | check: function () { |
||
| 805 | var $this = this; |
||
| 806 | |||
| 807 | this.input.prop('checked', true).trigger('change'); |
||
| 808 | setTimeout(function () { |
||
| 809 | $this.jq.addClass('ui-inputswitch-checked'); |
||
| 810 | }, 100); |
||
| 811 | }, |
||
| 812 | |||
| 813 | uncheck: function () { |
||
| 814 | var $this = this; |
||
| 815 | |||
| 816 | this.input.prop('checked', false).trigger('change'); |
||
| 817 | setTimeout(function () { |
||
| 818 | $this.jq.removeClass('ui-inputswitch-checked'); |
||
| 819 | }, 100); |
||
| 820 | } |
||
| 821 | }); |
||
| 822 | } |
||
| 823 | |||
| 824 | if (PrimeFaces.widget.AccordionPanel) { |
||
| 825 | PrimeFaces.widget.AccordionPanel = PrimeFaces.widget.AccordionPanel.extend({ |
||
| 826 | |||
| 827 | init: function (cfg) { |
||
| 828 | this._super(cfg); |
||
| 829 | |||
| 830 | this.headers.last().addClass('ui-accordion-header-last'); |
||
| 831 | } |
||
| 832 | }); |
||
| 833 | } |