Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
106 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
        this.topbar = $('body > .layout-wrapper > .topbar');
10
        this.menu = this.jq;
11
        this.menuWrapper = this.menu.closest('.layout-menu');
12
        this.menulinks = this.menu.find('a');
13
        this.expandedMenuitems = this.expandedMenuitems || [];
14
        this.profileButton = $('#profile-options');
15
        this.profileMenu = $('#profile-menu');
16
        this.topbarItems = this.topbar.find('.topbar-items');
17
        this.topbarLinks = this.topbarItems.find('> li > a');
18
        this.menuButton = $('#menu-button');
19
        this.topbarMenuButton = $('#topbar-menu-button');
20
        this.menuContainer = this.wrapper.find('.layout-menu-container');
21
        this.menuActive = false;
22
        this.topbarLinkClick = false;
23
        this.topbarMenuClick = false;
24
 
25
        this._bindEvents();
26
 
27
        if(!this.wrapper.hasClass('menu-layout-horizontal')) {
28
            this.restoreMenuState();
29
        }
30
 
31
        this.menuContainer.children('.nano').nanoScroller({flash:true});
32
    },
33
 
34
    _bindEvents: function() {
35
        var $this = this;
36
 
37
        this.menuButton.on('click', function(e) {
38
            $this.menuButton.toggleClass('menu-button-rotate');
39
            $this.topbarItems.removeClass('topbar-items-visible');
40
 
41
            //overlay
42
            if($this.wrapper.hasClass('menu-layout-overlay')) {
43
                $this.wrapper.toggleClass('layout-menu-overlay-active');
44
 
45
                if($this.wrapper.hasClass('layout-menu-overlay-active')) {
46
                    $this.enableModal();
47
                    $this.enableSwipe();
48
                    $this.closeRightSidebarMenu();
49
                }
50
                else {
51
                    $this.disableModal();
52
                    $this.disableSwipe();
53
                }
54
            }
55
            //static
56
            else {
57
                if($this.isDesktop()) {
58
                    $this.wrapper.toggleClass('layout-menu-static-inactive')
59
                }
60
                else {
61
                    if($this.wrapper.hasClass('layout-menu-static-active')) {
62
                        $this.wrapper.removeClass('layout-menu-static-active');
63
                        $this.disableModal();
64
                        $this.disableSwipe();
65
                    }
66
                    else {
67
                        $this.wrapper.addClass('layout-menu-static-active');
68
                        $this.wrapper.removeClass('layout-menu-static-inactive');
69
                        $this.enableModal();
70
                        $this.enableSwipe();
71
                        $this.closeRightSidebarMenu();
72
                    }
73
                }
74
            }
75
 
76
            e.preventDefault();
77
        });
78
 
79
        this.topbarMenuButton.on('click', function(e) {
80
            $this.topbarMenuClick = true;
81
            $this.topbarItems.find('ul').removeClass('fadeInDown fadeOutUp');
82
 
83
            if($this.wrapper.hasClass('layout-menu-overlay-active')||$this.wrapper.hasClass('layout-menu-static-active')) {
84
                $this.menuButton.removeClass('menu-button-rotate');
85
                $this.wrapper.removeClass('layout-menu-overlay-active layout-menu-static-active');
86
                $this.disableModal();
87
            }
88
 
89
            if($this.topbarItems.hasClass('topbar-items-visible')) {
90
                $this.topbarItems.addClass('fadeOutUp');
91
 
92
                setTimeout(function() {
93
                    $this.topbarItems.removeClass('fadeOutUp topbar-items-visible');
94
                },500);
95
            }
96
            else {
97
                $this.topbarItems.addClass('topbar-items-visible fadeInDown');
98
            }
99
 
100
            $this.closeRightSidebarMenu();
101
 
102
            e.preventDefault();
103
        });
104
 
105
        this.menulinks.off('click').on('click', function(e) {
106
            var link = $(this),
107
            item = link.parent(),
108
            submenu = item.children('ul'),
109
            horizontal = $this.isHorizontal() && $this.isDesktop();
110
 
111
            if(horizontal) {
112
                $this.horizontalMenuClick = true;
113
                $this.closeRightSidebarMenu();
114
            }
115
 
116
            if(item.hasClass('active-menuitem')) {
117
                if(submenu.length) {
118
                    $this.removeMenuitem(item.attr('id'));
119
                    item.removeClass('active-menuitem');
120
 
121
                    if(horizontal) {
122
                        if(item.parent().is($this.jq)) {
123
                            $this.menuActive = false;
124
                        }
125
 
126
                        submenu.hide();
127
                    }
128
                    else {
129
                        submenu.slideUp();
130
                    }
131
                }
132
            }
133
            else {
134
                $this.addMenuitem(item.attr('id'));
135
 
136
                if(horizontal) {
137
                    $this.deactivateItems(item.siblings());
138
                    item.addClass('active-menuitem');
139
                    $this.menuActive = true;
140
                    submenu.show();
141
                }
142
                else {
143
                    $this.deactivateItems(item.siblings(), true);
144
                    $this.activate(item);
145
                }
146
            }
147
 
148
            if(!horizontal) {
149
                setTimeout(function() {
150
                    $(".nano").nanoScroller();
151
                }, 500);
152
            }
153
 
154
            if(submenu.length) {
155
                e.preventDefault();
156
            }
157
        });
158
 
159
        this.menu.find('> li').on('mouseenter', function(e) {    
160
            if($this.isHorizontal() && $this.isDesktop()) {
161
                var item = $(this),
162
                link = item.children('a'),
163
                submenu = item.children('ul');
164
 
165
                if(!item.hasClass('active-menuitem')) {
166
                    $this.menu.find('.active-menuitem').removeClass('active-menuitem');
167
                    $this.menu.find('ul:visible').hide();
168
                    $this.menu.find('.ink').remove();
169
 
170
                    if($this.menuActive) {
171
                        item.addClass('active-menuitem');
172
                        item.children('ul').show();
173
                    }
174
                }
175
            }
176
        });
177
 
178
        this.profileButton.on('click', function(e) {
179
            var profile = $this.profileMenu.prev('.profile'),
180
            expanded = profile.hasClass('profile-expanded');
181
 
182
            $this.profileMenu.slideToggle();
183
            $this.profileMenu.prev('.profile').toggleClass('profile-expanded');
184
            $this.setInlineProfileState(!expanded);
185
 
186
            setTimeout(function() {
187
                $(".nano").nanoScroller();
188
            }, 500);
189
 
190
            e.preventDefault();
191
        });
192
 
193
        this.topbarLinks.on('click', function(e) {
194
            var link = $(this),
195
            item = link.parent(),
196
            submenu = link.next();
197
 
198
            $this.topbarLinkClick = true;
199
 
200
            item.siblings('.active-top-menu').removeClass('active-top-menu');
201
            if($this.wrapper.hasClass('layout-menu-overlay-active')) {
202
                $this.menuButton.removeClass('menu-button-rotate');
203
                $this.wrapper.removeClass('layout-menu-overlay-active');
204
                $this.disableModal();
205
            }
206
 
207
            if($this.isDesktop()) {
208
                if(submenu.length) {
209
                    if(item.hasClass('active-top-menu')) {
210
                        submenu.addClass('fadeOutUp');
211
 
212
                        setTimeout(function() {
213
                            item.removeClass('active-top-menu'),
214
                            submenu.removeClass('fadeOutUp');
215
                        },500);
216
                    }
217
                    else {
218
                        item.addClass('active-top-menu');
219
                        submenu.addClass('fadeInDown');
220
                    }
221
                }
222
            }
223
            else {
224
                item.children('ul').removeClass('fadeInDown fadeOutUp');
225
                item.toggleClass('active-top-menu');
226
            }  
227
 
228
            $this.closeRightSidebarMenu();
229
 
230
            e.preventDefault();        
231
        });
232
 
233
        $this.topbarItems.children('.search-item').on('click', function(e) {
234
            $this.topbarLinkClick = true;
235
        });
236
 
237
        $(document.body).on('click', function() {
238
            if($this.isHorizontal() && !$this.horizontalMenuClick && $this.isDesktop()) {
239
                $this.menu.find('.active-menuitem').removeClass('active-menuitem');
240
                $this.menu.find('ul:visible').hide();
241
                $this.menuActive = false;
242
            }
243
 
244
            if(!$this.topbarMenuClick && !$this.topbarLinkClick) {
245
                $this.topbarItems.find('.active-top-menu').removeClass('active-top-menu');
246
            }
247
 
248
            if(!$this.topbarMenuClick && !$this.topbarLinkClick) {
249
                $this.topbarItems.removeClass('topbar-items-visible');
250
            }
251
 
252
            $this.horizontalMenuClick = false;
253
            $this.topbarLinkClick = false;
254
            $this.topbarMenuClick = false;
255
        });
256
 
257
        $(function() {
258
            $this._initRightSidebar();
259
        });
260
    },
261
 
262
    activate: function(item) {
263
        var submenu = item.children('ul');
264
        item.addClass('active-menuitem');
265
 
266
        if(submenu.length) {
267
            submenu.slideDown();
268
        }
269
    },
270
 
271
    deactivate: function(item) {
272
        var submenu = item.children('ul');
273
        item.removeClass('active-menuitem');
274
 
275
        if(submenu.length) {
276
            submenu.hide();
277
        }
278
    },
279
 
280
    deactivateItems: function(items, animate) {
281
        var $this = this;
282
 
283
        for(var i = 0; i < items.length; i++) {
284
            var item = items.eq(i),
285
            submenu = item.children('ul');
286
 
287
            if(submenu.length) {
288
                if(item.hasClass('active-menuitem')) {
289
                    var activeSubItems = item.find('.active-menuitem');
290
                    item.removeClass('active-menuitem');
291
                    item.find('.ink').remove();
292
 
293
                    if(animate) {
294
                        submenu.slideUp('normal', function() {
295
                            $(this).parent().find('.active-menuitem').each(function() {
296
                                $this.deactivate($(this));
297
                            });
298
                        });
299
                    }
300
                    else {
301
                        submenu.hide();
302
                        item.find('.active-menuitem').each(function() {
303
                            $this.deactivate($(this));
304
                        });
305
                    }
306
 
307
                    $this.removeMenuitem(item.attr('id'));
308
                    activeSubItems.each(function() {
309
                        $this.removeMenuitem($(this).attr('id'));
310
                    });
311
                }
312
                else {
313
                    item.find('.active-menuitem').each(function() {
314
                        var subItem = $(this);
315
                        $this.deactivate(subItem);
316
                        $this.removeMenuitem(subItem.attr('id'));
317
                    });
318
                }
319
            }
320
            else if(item.hasClass('active-menuitem')) {
321
                $this.deactivate(item);
322
                $this.removeMenuitem(item.attr('id'));
323
            }
324
        }
325
    },
326
 
327
    removeMenuitem: function (id) {
328
        this.expandedMenuitems = $.grep(this.expandedMenuitems, function (value) {
329
            return value !== id;
330
        });
331
        this.saveMenuState();
332
    },
333
 
334
    addMenuitem: function (id) {
335
        if ($.inArray(id, this.expandedMenuitems) === -1) {
336
            this.expandedMenuitems.push(id);
337
        }
338
        this.saveMenuState();
339
    },
340
 
341
    saveMenuState: function() {
342
        $.cookie('poseidon_expandeditems', this.expandedMenuitems.join(','), {path: '/'});
343
    },
344
 
345
    clearMenuState: function() {
346
        $.removeCookie('poseidon_expandeditems', {path: '/'});
347
    },
348
 
349
    setInlineProfileState: function(expanded) {
350
        if(expanded)
351
            $.cookie('poseidon_inlineprofile_expanded', "1", {path: '/'});
352
        else
353
            $.removeCookie('poseidon_inlineprofile_expanded', {path: '/'});
354
    },
355
 
356
    restoreMenuState: function() {
357
        var menucookie = $.cookie('poseidon_expandeditems');
358
        if (menucookie) {
359
            this.expandedMenuitems = menucookie.split(',');
360
            for (var i = 0; i < this.expandedMenuitems.length; i++) {
361
                var id = this.expandedMenuitems[i];
362
                if (id) {
363
                    var menuitem = $("#" + this.expandedMenuitems[i].replace(/:/g, "\\:"));
364
                    menuitem.addClass('active-menuitem');
365
 
366
                    var submenu = menuitem.children('ul');
367
                    if(submenu.length) {
368
                        submenu.show();
369
                    }
370
                }
371
            }
372
        }
373
 
374
        var inlineProfileCookie = $.cookie('poseidon_inlineprofile_expanded');
375
        if (inlineProfileCookie) {
376
            this.profileMenu.show().prev('.profile').addClass('profile-expanded');
377
        }
378
    },
379
 
380
    enableModal: function() {
381
        this.modal = this.wrapper.append('<div class="layout-mask"></div>').children('.layout-mask');
382
    },
383
 
384
    disableModal: function() {
385
        this.modal.remove();
386
    },
387
 
388
    enableSwipe: function() {
389
        var $this = this;
390
        this.menuWrapper.swipe({
391
            swipeLeft: function() {
392
                $this.menuButton.click();
393
            }
394
        });
395
    },
396
 
397
    disableSwipe: function() {
398
        this.menuWrapper.swipe('destroy');
399
    },
400
 
401
    isHorizontal: function() {
402
        return this.wrapper.hasClass('menu-layout-horizontal');
403
    },
404
 
405
    isTablet: function() {
406
        var width = window.innerWidth;
407
        return width <= 1024 && width > 640;
408
    },
409
 
410
    isDesktop: function() {
411
        return window.innerWidth > 1024;
412
    },
413
 
414
    isMobile: function() {
415
        return window.innerWidth <= 640;
416
    },
417
 
418
    _initRightSidebar: function() {
419
        var $this = this;
420
 
421
        this.rightSidebar = $('#right-sidebar');
422
        this.rightSidebarBtnOpen = $('#right-sidebar-button-open');
423
        this.rightSidebarBtnClose = $('#right-sidebar-button-close');
424
 
425
        $this.rightSidebar.children('.nano').nanoScroller({flash:true});
426
 
427
        this.rightSidebarBtnOpen.on('click', function(e) {
428
            $this.rightSidebar.addClass('right-sidebar-active');
429
            e.preventDefault();
430
        });
431
 
432
        this.rightSidebarBtnClose.on('click', function(e) {
433
            $this.rightSidebar.removeClass('right-sidebar-active');
434
            e.preventDefault();
435
        });
436
 
437
        this.rightSidebar.on('click', function() {
438
            setTimeout(function() {
439
                $this.rightSidebar.children('.nano').nanoScroller();
440
            }, 500);
441
        });
442
    },
443
 
444
    closeRightSidebarMenu: function() {
445
        if(this.rightSidebar) {
446
            this.rightSidebar.removeClass('right-sidebar-active');
447
        }
448
    }
449
 
450
});
451
 
452
/*!
453
 * jQuery Cookie Plugin v1.4.1
454
 * https://github.com/carhartl/jquery-cookie
455
 *
456
 * Copyright 2006, 2014 Klaus Hartl
457
 * Released under the MIT license
458
 */
459
(function (factory) {
460
        if (typeof define === 'function' && define.amd) {
461
                // AMD (Register as an anonymous module)
462
                define(['jquery'], factory);
463
        } else if (typeof exports === 'object') {
464
                // Node/CommonJS
465
                module.exports = factory(require('jquery'));
466
        } else {
467
                // Browser globals
468
                factory(jQuery);
469
        }
470
}(function ($) {
471
 
472
        var pluses = /\+/g;
473
 
474
        function encode(s) {
475
                return config.raw ? s : encodeURIComponent(s);
476
        }
477
 
478
        function decode(s) {
479
                return config.raw ? s : decodeURIComponent(s);
480
        }
481
 
482
        function stringifyCookieValue(value) {
483
                return encode(config.json ? JSON.stringify(value) : String(value));
484
        }
485
 
486
        function parseCookieValue(s) {
487
                if (s.indexOf('"') === 0) {
488
                        // This is a quoted cookie as according to RFC2068, unescape...
489
                        s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
490
                }
491
 
492
                try {
493
                        // Replace server-side written pluses with spaces.
494
                        // If we can't decode the cookie, ignore it, it's unusable.
495
                        // If we can't parse the cookie, ignore it, it's unusable.
496
                        s = decodeURIComponent(s.replace(pluses, ' '));
497
                        return config.json ? JSON.parse(s) : s;
498
                } catch(e) {}
499
        }
500
 
501
        function read(s, converter) {
502
                var value = config.raw ? s : parseCookieValue(s);
503
                return $.isFunction(converter) ? converter(value) : value;
504
        }
505
 
506
        var config = $.cookie = function (key, value, options) {
507
 
508
                // Write
509
 
510
                if (arguments.length > 1 && !$.isFunction(value)) {
511
                        options = $.extend({}, config.defaults, options);
512
 
513
                        if (typeof options.expires === 'number') {
514
                                var days = options.expires, t = options.expires = new Date();
515
                                t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
516
                        }
517
 
518
                        return (document.cookie = [
519
                                encode(key), '=', stringifyCookieValue(value),
520
                                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
521
                                options.path    ? '; path=' + options.path : '',
522
                                options.domain  ? '; domain=' + options.domain : '',
523
                                options.secure  ? '; secure' : ''
524
                        ].join(''));
525
                }
526
 
527
                // Read
528
 
529
                var result = key ? undefined : {},
530
                        // To prevent the for loop in the first place assign an empty array
531
                        // in case there are no cookies at all. Also prevents odd result when
532
                        // calling $.cookie().
533
                        cookies = document.cookie ? document.cookie.split('; ') : [],
534
                        i = 0,
535
                        l = cookies.length;
536
 
537
                for (; i < l; i++) {
538
                        var parts = cookies[i].split('='),
539
                                name = decode(parts.shift()),
540
                                cookie = parts.join('=');
541
 
542
                        if (key === name) {
543
                                // If second argument (value) is a function it's a converter...
544
                                result = read(cookie, value);
545
                                break;
546
                        }
547
 
548
                        // Prevent storing a cookie that we couldn't decode.
549
                        if (!key && (cookie = read(cookie)) !== undefined) {
550
                                result[name] = cookie;
551
                        }
552
                }
553
 
554
                return result;
555
        };
556
 
557
        config.defaults = {};
558
 
559
        $.removeCookie = function (key, options) {
560
                // Must not alter options, thus extending a fresh object...
561
                $.cookie(key, '', $.extend({}, options, { expires: -1 }));
562
                return !$.cookie(key);
563
        };
564
 
565
}));
566
 
567
/* Issue #924 is fixed for 5.3+ and 6.0. (compatibility with 5.3) */
568
if(window['PrimeFaces'] && window['PrimeFaces'].widget.Dialog) {
569
    PrimeFaces.widget.Dialog = PrimeFaces.widget.Dialog.extend({
570
 
571
        enableModality: function() {
572
            this._super();
573
            $(document.body).children(this.jqId + '_modal').addClass('ui-dialog-mask');
574
        },
575
 
576
        syncWindowResize: function() {}
577
    });
578
}