Subversion Repositories Integrator Subversion

Rev

Rev 224 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
207 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);
234 espaco 232
                        //TODO: SERÁ ATIVADO QUANDO ESTIVER APENAS O SISTEMA NOVO NO AR
233
                        //$.cookie('poseidon_menu_scroll_state', link.attr('href') + ',' + $this.menuContainer.scrollTop(), { path: '/' });
207 espaco 234
                    }
235
                }
236
            }
237
 
238
            if(submenu.length) {
239
                e.preventDefault();
240
            }
241
        });
242
 
243
        this.menu.find('ul').off('click.menu').on('click.menu', function() {
244
            if ($this.isHorizontal()) {
245
                $this.horizontalMenuClick = true;
246
            }
247
        });
248
 
249
        this.profileButton.off('click.profile').on('click.profile', function (e) {
250
            if (!$this.isHorizontal() ) {
251
                $this.profileContainer.toggleClass('layout-profile-active');
252
                $this.profileMenu.slideToggle();
253
            }
254
            else {
255
                $this.profileMenuClick = true;
256
 
257
                if ($this.profileContainer.hasClass('layout-profile-active')) {
258
                    $this.profileMenu.addClass('fadeOutUp');
259
 
260
                    setTimeout(function () {
261
                        $this.profileContainer.removeClass('layout-profile-active');
262
                        $this.profileMenu.removeClass('fadeOutUp');
263
                    }, 150);
264
                }
265
                else {
266
                    $this.profileContainer.addClass('layout-profile-active');
267
                    $this.profileMenu.addClass('fadeInDown');
268
                }
269
            }
270
 
271
            e.preventDefault();
272
        });
273
 
274
        this.menu.find('> li').on('mouseenter', function(e) {    
275
            if($this.isHorizontal() && $this.menuActive) {
276
                var item = $(this);
277
 
278
                if(!item.hasClass('active-menuitem')) {
279
                    $this.menu.find('.active-menuitem').removeClass('active-menuitem');
280
 
281
                    if($this.menuActive) {
282
                        item.addClass('active-menuitem');
283
                    }
284
                }
285
            }
286
        });
287
    },
288
 
289
    bindTopbarEvents: function() {
290
        var $this = this;
291
 
292
        this.topbarLinks.off('click.topbar').on('click.topbar', function(e) {
293
            var link = $(this),
294
            item = link.parent(),
295
            submenu = item.children('ul');
296
 
297
            if ($this.isMobile()) {
298
                $this.removeTopbarClassFromAllItems(null, 'active-topmenuitem', $this.topbarItems.filter('.active-topmenuitem').not(item));
299
            }
300
            else {
301
                $this.removeTopbarClassFromAllItems(item, 'active-topmenuitem');
302
            }
303
            $this.addTopbarClass(item, 'active-topmenuitem');
304
 
305
            $this.topbarItemClicked = true;
306
 
307
            if (submenu.length) {
308
                e.preventDefault();
309
            }
310
        });
311
 
312
        this.topbarSearchItemMenu.off('click.topbar').on('click.topbar', function(e) {
313
            $this.topbarItemClicked = true;
314
        });
315
    },
316
 
317
    bindRightPanelEvents: function() {
318
        var $this = this;
319
        var changeRightpanelState = function(e) {
320
            this.toggleClass(this.wrapper, 'layout-rightpanel-active');
321
 
322
            this.rightpanelClicked = true;
323
            e.preventDefault();
324
        };
325
 
326
        this.rightpanelButton.off('click.rightpanel').on('click.rightpanel', changeRightpanelState.bind(this));
327
        this.rightpanelExitButton.off('click.rightpanel').on('click.rightpanel', changeRightpanelState.bind(this));
328
 
329
        this.rightpanel.off('click.rightpanel').on('click.rightpanel', function() {
330
            $this.rightpanelClicked = true;
331
        });
332
    },
333
 
334
    activate: function(item) {
335
        var submenu = item.children('ul');
336
        item.addClass('active-menuitem');
337
 
338
        if(submenu.length) {
339
            submenu.slideDown();
340
        }
341
    },
342
 
343
    deactivate: function(item) {
344
        var submenu = item.children('ul');
345
        item.removeClass('active-menuitem');
346
 
347
        if(submenu.length) {
348
            submenu.hide();
349
        }
350
    },
351
 
352
    deactivateItems: function(items, animate) {
353
        var $this = this;
354
 
355
        for(var i = 0; i < items.length; i++) {
356
            var item = items.eq(i),
357
            submenu = item.children('ul');
358
 
359
            if(submenu.length) {
360
                if(item.hasClass('active-menuitem')) {
361
                    var activeSubItems = item.find('.active-menuitem');
362
                    item.removeClass('active-menuitem');
363
 
364
                    if(animate) {
365
                        submenu.slideUp('normal', function() {
366
                            $(this).parent().find('.active-menuitem').each(function() {
367
                                $this.deactivate($(this));
368
                            });
369
                        });
370
                    }
371
                    else {
372
                        item.find('.active-menuitem').each(function() {
373
                            $this.deactivate($(this));
374
                        });
375
                    }
376
                }
377
                else {
378
                    item.find('.active-menuitem').each(function() {
379
                        var subItem = $(this);
380
                        $this.deactivate(subItem);
381
                    });
382
                }
383
            }
384
            else if(item.hasClass('active-menuitem')) {
385
                $this.deactivate(item);
386
            }
387
        }
388
    },
389
 
390
    saveStaticMenuState: function() {
391
        if(this.isHorizontal()) {
392
            return;
393
        }
394
 
395
        if (!this.wrapper.hasClass('layout-static-active'))
396
            $.cookie('poseidon_menu_static', 'poseidon_menu_static', {path: '/'});
397
        else
398
            $.removeCookie('poseidon_menu_static', {path: '/'});
399
    },
400
 
401
    clearMenuState: function() {
402
        $.removeCookie('poseidon_menu_static', {path: '/'});
403
    },
404
 
405
    clearActiveItems: function() {
406
        var activeItems = this.jq.find('li.active-menuitem'),
407
        subContainers = activeItems.children('ul');
408
 
409
        activeItems.removeClass('active-menuitem');
410
        if(subContainers && subContainers.length) {
411
            subContainers.hide();
412
        }
413
    },
414
 
415
    clearLayoutState: function() {
416
        this.clearMenuState();
417
        this.clearActiveItems();
418
    },
419
 
420
    restoreMenuState: function () {
421
        var link = $('a[href^="' + this.cfg.pathname + '"]');
422
        var $this = this;
423
        if (link.length) {
424
            var menuitem = link.closest('li');
425
            var parentMenu = menuitem.closest('ul');
426
 
427
            menuitem.addClass('active-menuitem');
428
            if (parentMenu.length) {
429
                var parentMenuItem = parentMenu.closest('li');
430
                while (!parentMenuItem.hasClass('layout-root-menuitem')) {
224 espaco 431
// MODIFICAÇÃO PARA NÃO DEIXAR O PANEL ABERTO AO IDENTIFICAR O HREF DA PÁGINA                       
432
//                    parentMenuItem.addClass('active-menuitem');
433
//                    parentMenu.show();
207 espaco 434
 
435
                    parentMenu = parentMenuItem.closest('ul');
436
                    if (!parentMenu.length) {
437
                        break;
438
                    }
439
 
440
                    parentMenuItem = parentMenu.closest('li');
441
                }
442
 
443
                if (parentMenuItem.hasClass('layout-root-menuitem') && !parentMenuItem.closest('ul').hasClass('layout-menu')) {
444
                    parentMenuItem.addClass('active-menuitem');
445
                    parentMenu.show();
446
                }
447
            }
448
 
449
            setTimeout(function() {
450
                $this.restoreScrollState(menuitem);
451
            }, 100)
452
        }
453
 
454
        var sidebarCookie = $.cookie('poseidon_menu_static');
455
        if (sidebarCookie) {
456
            this.wrapper.removeClass('layout-static-active');
457
        }
458
    },
459
 
460
    restoreScrollState: function(menuitem) {
461
        var scrollState = $.cookie('poseidon_menu_scroll_state');
462
        if (scrollState) {
463
            var state = scrollState.split(',');
464
            if (state[0].startsWith(this.cfg.pathname) || this.isScrolledIntoView(menuitem, state[1])) {
465
                this.menuContainer.scrollTop(parseInt(state[1], 10));
466
            }
467
            else {
468
                this.scrollIntoView(menuitem.get(0));
469
                $.removeCookie('poseidon_menu_scroll_state', { path: '/' });
470
            }
471
        }
472
        else if (!this.isScrolledIntoView(menuitem, menuitem.scrollTop())){
473
            this.scrollIntoView(menuitem.get(0));
474
        }
475
    },
476
 
477
    scrollIntoView: function(elem) {
478
        if (document.documentElement.scrollIntoView) {
479
            elem.scrollIntoView();
480
        }
481
    },
482
 
483
    isScrolledIntoView: function(elem, scrollTop) {
484
        var viewBottom = parseInt(scrollTop, 10) + this.menuContainer.height();
485
 
486
        var elemTop = elem.position().top;
487
        var elemBottom = elemTop + elem.height();
488
 
489
        return ((elemBottom <= viewBottom) && (elemTop >= scrollTop));
490
    },
491
 
492
    removeTopbarClassFromAllItems: function(item, className, items) {
493
        var activeItems = item != null ? item.siblings('.' + className) : items;
494
 
495
        activeItems.removeClass(className);
496
        activeItems.children('ul').removeClass('fadeInDown');
497
    },
498
 
499
    addTopbarClass: function(item, className) {
500
        var submenu = item.children('ul');
501
 
502
        if (submenu.length) {
503
            if (item.hasClass(className)) {
504
                submenu.removeClass('fadeInDown').addClass('fadeOutUp');
505
 
506
                setTimeout(function() {
507
                    item.removeClass(className);
508
                    submenu.removeClass('fadeOutUp');
509
                }, 100);
510
            }
511
            else {
512
                item.addClass(className);
513
                submenu.addClass('fadeInDown');
514
            }
515
        }
516
    },
517
 
518
    hideTopBar: function() {
519
        var $this = this;
520
        this.topbarMenu.addClass('fadeOutUp');
521
 
522
        setTimeout(function() {
523
            $this.topbarMenu.removeClass('fadeOutUp topbar-menu-visible');
524
        },500);
525
    },
526
 
527
    isMobile: function() {
528
        return window.innerWidth <= 992;
529
    },
530
 
531
    isHorizontal: function() {
532
        return this.wrapper.hasClass('layout-horizontal') && !this.isMobile();
533
    },
534
    isStatic: function() {
535
        return this.wrapper.hasClass('layout-static') && !this.isMobile();
536
    }
537
});
538
 
539
PrimeFaces.PoseidonConfigurator = {
540
 
541
    changeLayout: function( componentTheme, darkMode ) {
542
        this.changeLayoutsTheme(darkMode);
543
        this.changeDemo(darkMode);
544
        this.changeComponentsTheme(componentTheme, darkMode);
545
        this.changeSectionTheme( darkMode, 'layout-menu');
546
        this.changeSectionTheme( darkMode , 'layout-topbar');
547
    },
548
 
549
    changeLayoutsTheme: function(darkMode) {
550
        newLayout = '-' + darkMode;
551
        var linkElement = $('link[href*="layout-"]');
552
        var href = linkElement.attr('href');
553
        var startIndexOf = href.indexOf('layout-') + 6;
554
        var endIndexOf = href.indexOf('.css');
555
        var currentColor = href.substring(startIndexOf, endIndexOf);
556
        this.replaceLink(linkElement, href.replace(currentColor, newLayout));
557
    },
558
 
559
    changeComponentsTheme: function(theme, darkMode) {
560
        theme = this.getColor(theme, darkMode);
561
        var library = 'primefaces-poseidon';
562
        var linkElement = $('link[href*="theme.css"]');
563
        var href = linkElement.attr('href');
564
        var index = href.indexOf(library) + 1;
565
        var currentTheme = href.substring(index + library.length);
566
 
567
        this.replaceLink(linkElement, href.replace(currentTheme, theme));
568
    },
569
 
570
    changeDemo: function(darkMode) {
571
        newLayout = '-' + darkMode;
572
        var linkElement = $('link[href*="demo-"]');
573
        var href = linkElement.attr('href');
574
        var startIndexOf = href.indexOf('demo-') + 4;
575
        var endIndexOf = href.indexOf('.css');
576
        var currentColor = href.substring(startIndexOf, endIndexOf);
577
 
578
        this.replaceLink(linkElement, href.replace(currentColor, newLayout));
579
    },
580
 
581
    changeMenuMode: function(menuMode) {
582
        var wrapper = $(document.body).children('.layout-wrapper');
583
        switch (menuMode) {
584
            case 'layout-static layout-static-active':
585
                wrapper.addClass('layout-static layout-static-active').removeClass('layout-overlay layout-slim layout-horizontal layout-slim-plus');
586
                this.clearLayoutState();
587
            break;
588
 
589
            case 'layout-overlay':
590
                wrapper.addClass('layout-overlay').removeClass('layout-static layout-slim layout-horizontal layout-slim-plus layout-static-active');
591
                this.clearLayoutState();
592
            break;
593
 
594
            case 'layout-horizontal':
595
                wrapper.addClass('layout-horizontal').removeClass('layout-static layout-overlay  layout-slim layout-slim-plus layout-static-active');
596
                this.clearLayoutState();
597
            break;
598
 
599
            default:
600
                wrapper.addClass('layout-static').removeClass('layout-overlay layout-slim layout-horizontal layout-slim-plus ');
601
                this.clearLayoutState();
602
            break;
603
        }
604
    },
605
 
606
    changeSectionTheme: function(theme, section) {
607
        var wrapperElement = $('.layout-wrapper');
608
        var styleClass = wrapperElement.attr('class');
609
        var tokens = styleClass.split(' ');
610
        var sectionClass;
611
        for (var i = 0; i < tokens.length; i++) {
612
            if (tokens[i].indexOf(section + '-') > -1) {
613
                sectionClass = tokens[i];
614
                break;
615
            }
616
        }
617
 
618
        wrapperElement.attr('class', styleClass.replace(sectionClass, section + '-' + theme));
619
    },
620
 
621
    beforeResourceChange: function() {
622
        PrimeFaces.ajax.RESOURCE = null;    //prevent resource append
623
    },
624
 
625
    replaceLink: function(linkElement, href) {
626
        PrimeFaces.ajax.RESOURCE = 'javax.faces.Resource';
627
 
628
        var isIE = this.isIE();
629
 
630
        if (isIE) {
631
            linkElement.attr('href', href);
632
        }
633
        else {
634
            var cloneLinkElement = linkElement.clone(false);
635
 
636
            cloneLinkElement.attr('href', href);
637
            linkElement.after(cloneLinkElement);
638
 
639
            cloneLinkElement.off('load').on('load', function() {
640
                linkElement.remove();
641
 
642
                // for dashboard
643
                setTimeout(function() {
644
                    if (window['redrawDoughnut']) {
645
                        window.redrawDoughnut();
646
                    }
647
                }, 1);
648
            });
649
        }
650
    },
651
 
652
    getColor: function(name, darkMode) {
653
        return name + '-' + darkMode;
654
    },
655
 
656
    isIE: function() {
657
        return /(MSIE|Trident\/|Edge\/)/i.test(navigator.userAgent);
658
    },
659
 
660
    changeMenuToRTL: function() {
661
        $('.layout-wrapper').toggleClass('layout-rtl');
662
    },
663
 
664
    clearLayoutState: function() {
665
        var menu = PF('PoseidonMenuWidget');
666
 
667
        if (menu) {
668
            menu.clearLayoutState();
669
        }
670
    },
671
 
672
    updateInputStyle: function(value) {
673
        if (value === 'filled')
674
            $(document.body).addClass('ui-input-filled');
675
        else
676
            $(document.body).removeClass('ui-input-filled');
677
    }
678
};
679
 
680
/*!
681
 * jQuery Cookie Plugin v1.4.1
682
 * https://github.com/carhartl/jquery-cookie
683
 *
684
 * Copyright 2006, 2014 Klaus Hartl
685
 * Released under the MIT license
686
 */
687
(function (factory) {
688
    if (typeof define === 'function' && define.amd) {
689
        // AMD (Register as an anonymous module)
690
        define(['jquery'], factory);
691
    } else if (typeof exports === 'object') {
692
        // Node/CommonJS
693
        module.exports = factory(require('jquery'));
694
    } else {
695
        // Browser globals
696
        factory(jQuery);
697
    }
698
}(function ($) {
699
 
700
    var pluses = /\+/g;
701
 
702
    function encode(s) {
703
        return config.raw ? s : encodeURIComponent(s);
704
    }
705
 
706
    function decode(s) {
707
        return config.raw ? s : decodeURIComponent(s);
708
    }
709
 
710
    function stringifyCookieValue(value) {
711
        return encode(config.json ? JSON.stringify(value) : String(value));
712
    }
713
 
714
    function parseCookieValue(s) {
715
        if (s.indexOf('"') === 0) {
716
            // This is a quoted cookie as according to RFC2068, unescape...
717
            s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
718
        }
719
 
720
        try {
721
            // Replace server-side written pluses with spaces.
722
            // If we can't decode the cookie, ignore it, it's unusable.
723
            // If we can't parse the cookie, ignore it, it's unusable.
724
            s = decodeURIComponent(s.replace(pluses, ' '));
725
            return config.json ? JSON.parse(s) : s;
726
        } catch (e) { }
727
    }
728
 
729
    function read(s, converter) {
730
        var value = config.raw ? s : parseCookieValue(s);
731
        return $.isFunction(converter) ? converter(value) : value;
732
    }
733
 
734
    var config = $.cookie = function (key, value, options) {
735
 
736
        // Write
737
 
738
        if (arguments.length > 1 && !$.isFunction(value)) {
739
            options = $.extend({}, config.defaults, options);
740
 
741
            if (typeof options.expires === 'number') {
742
                var days = options.expires, t = options.expires = new Date();
743
                t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
744
            }
745
 
746
            return (document.cookie = [
747
                encode(key), '=', stringifyCookieValue(value),
748
                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
749
                options.path ? '; path=' + options.path : '',
750
                options.domain ? '; domain=' + options.domain : '',
751
                options.secure ? '; secure' : ''
752
            ].join(''));
753
        }
754
 
755
        // Read
756
 
757
        var result = key ? undefined : {},
758
            // To prevent the for loop in the first place assign an empty array
759
            // in case there are no cookies at all. Also prevents odd result when
760
            // calling $.cookie().
761
            cookies = document.cookie ? document.cookie.split('; ') : [],
762
            i = 0,
763
            l = cookies.length;
764
 
765
        for (; i < l; i++) {
766
            var parts = cookies[i].split('='),
767
                name = decode(parts.shift()),
768
                cookie = parts.join('=');
769
 
770
            if (key === name) {
771
                // If second argument (value) is a function it's a converter...
772
                result = read(cookie, value);
773
                break;
774
            }
775
 
776
            // Prevent storing a cookie that we couldn't decode.
777
            if (!key && (cookie = read(cookie)) !== undefined) {
778
                result[name] = cookie;
779
            }
780
        }
781
 
782
        return result;
783
    };
784
 
785
    config.defaults = {};
786
 
787
    $.removeCookie = function (key, options) {
788
        // Must not alter options, thus extending a fresh object...
789
        $.cookie(key, '', $.extend({}, options, { expires: -1 }));
790
        return !$.cookie(key);
791
    };
792
 
793
}));
794
 
795
if (PrimeFaces.widget.InputSwitch) {
796
    PrimeFaces.widget.InputSwitch = PrimeFaces.widget.InputSwitch.extend({
797
 
798
        init: function (cfg) {
799
            this._super(cfg);
800
 
801
            if (this.input.prop('checked')) {
802
                this.jq.addClass('ui-inputswitch-checked');
803
            }
804
        },
805
 
806
        check: function () {
807
            var $this = this;
808
 
809
            this.input.prop('checked', true).trigger('change');
810
            setTimeout(function () {
811
                $this.jq.addClass('ui-inputswitch-checked');
812
            }, 100);
813
        },
814
 
815
        uncheck: function () {
816
            var $this = this;
817
 
818
            this.input.prop('checked', false).trigger('change');
819
            setTimeout(function () {
820
                $this.jq.removeClass('ui-inputswitch-checked');
821
            }, 100);
822
        }
823
    });
824
}
825
 
826
if (PrimeFaces.widget.AccordionPanel) {
827
    PrimeFaces.widget.AccordionPanel = PrimeFaces.widget.AccordionPanel.extend({
828
 
829
        init: function (cfg) {
830
            this._super(cfg);
831
 
832
            this.headers.last().addClass('ui-accordion-header-last');
833
        }
834
    });
835
}