All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.primefaces.sticky.sticky.js Maven / Gradle / Ivy

There is a newer version: 14.0.0-RC2
Show newest version
/**
 * PrimeFaces Sticky Widget
 */
PrimeFaces.widget.Sticky = PrimeFaces.widget.BaseWidget.extend({
    
    init: function(cfg) {
        this.cfg = cfg;
        this.id = this.cfg.id;
        this.target = $(PrimeFaces.escapeClientId(this.cfg.target));
        this.cfg.margin = this.cfg.margin||0;
        this.initialState = {
            top: this.target.offset().top,
            width: this.target.width(),
            height: this.target.height()
        };
        
        var win = $(window),
        $this = this;
        
        $(window).on('scroll.' + this.cfg.id, function() {
            if(win.scrollTop() > $this.initialState.top) {
                $this.fix();
            }
            else {
                $this.restore();
            }
        });
    },
            
    refresh: function(cfg) {
        $(window).off('scroll.' + this.cfg.id);
        
        this.init(cfg);
    },
            
    fix: function() {
        if(!this.fixed) {
            this.target.css({
                'position': 'fixed',
                'top': this.cfg.margin,
                'z-index': ++PrimeFaces.zindex,
                'width': this.initialState.width
            })
            .addClass('ui-shadow ui-sticky');
            
            $('
').height(this.initialState.height).insertBefore(this.target); this.fixed = true; } }, restore: function() { if(this.fixed) { this.target.css({ position: 'static', top: 'auto', 'width': this.initialState.width }) .removeClass('ui-shadow ui-sticky'); this.target.prev('.ui-sticky-ghost').remove(); this.fixed = false; } } });




© 2015 - 2024 Weber Informatics LLC | Privacy Policy