Giter Site home page Giter Site logo

Comments (10)

EugenFischer avatar EugenFischer commented on May 28, 2024 1

nice ...

from primefaces.

melloware avatar melloware commented on May 28, 2024

@EugenFischer when you say "long click" do you mean on a mobile browser?

from primefaces.

melloware avatar melloware commented on May 28, 2024

I just tried your scenario in Windows 11 Chrome and its not happening for me?

from primefaces.

melloware avatar melloware commented on May 28, 2024

OK nevermind it happens on the VERY FIRST click after loading the page but stops happening after that.

from primefaces.

melloware avatar melloware commented on May 28, 2024

Bug is right here....

this.jq.off('focus.pickList blur.pickList keydown.pickList', listSelector).on('focus.pickList', listSelector, null, function(e) {
            var list = $(this),
                activeItem = $this.focusedItem||list.children('.ui-state-highlight:visible:first');

from primefaces.

melloware avatar melloware commented on May 28, 2024

MonkeyPatch:

if (PrimeFaces.widget.PickList) {
    PrimeFaces.widget.PickList.prototype.bindItemEvents = function() {
        var $this = this;

        this.items.on('mouseover.pickList', function(e) {
                $(this).addClass('ui-state-hover');
            })
            .on('mouseout.pickList', function(e) {
                $(this).removeClass('ui-state-hover');
            })
            .on('click.pickList', function(e) {
                //stop propagation
                if ($this.checkboxClick || $this.dragging) {
                    $this.checkboxClick = false;
                    return;
                }

                var item = $(this),
                    parentList = item.parent(),
                    metaKey = (e.metaKey || e.ctrlKey);

                if (!e.shiftKey) {
                    if (!metaKey) {
                        $this.unselectAll();
                    }

                    if (metaKey && item.hasClass('ui-state-highlight')) {
                        $this.unselectItem(item, true);
                    } else {
                        $this.selectItem(item, true);
                        $this.cursorItem = item;
                    }
                } else {
                    $this.unselectAll();

                    if ($this.cursorItem && ($this.cursorItem.parent().is(item.parent()))) {
                        var currentItemIndex = item.index(),
                            cursorItemIndex = $this.cursorItem.index(),
                            startIndex = (currentItemIndex > cursorItemIndex) ? cursorItemIndex : currentItemIndex,
                            endIndex = (currentItemIndex > cursorItemIndex) ? (currentItemIndex + 1) : (cursorItemIndex + 1);

                        for (var i = startIndex; i < endIndex; i++) {
                            var it = parentList.children('li.ui-picklist-item').eq(i);

                            if (it.is(':visible')) {
                                if (i === (endIndex - 1))
                                    $this.selectItem(it, true);
                                else
                                    $this.selectItem(it);
                            }
                        }
                    } else {
                        $this.selectItem(item, true);
                        $this.cursorItem = item;
                    }
                }

                /* For keyboard navigation */
                $this.removeOutline();
                $this.focusedItem = item;
                parentList.trigger('focus.pickList');
            });

        if (this.cfg.transferOnDblclick) {
            this.items.on('dblclick.pickList', function() {
                var item = $(this);

                if ($(this).parent().hasClass('ui-picklist-source')) {
                    $this.transfer(item, $this.sourceList, $this.targetList, 'dblclick');
                } else {
                    $this.transfer(item, $this.targetList, $this.sourceList, 'dblclick');
                }

                /* For keyboard navigation */
                $this.removeOutline();
                $this.focusedItem = null;

                PrimeFaces.clearSelection();
            });
        }

        if (this.cfg.showCheckbox) {
            this.checkboxes.off().on('mouseenter.pickList', function(e) {
                    $(this).addClass('ui-state-hover');
                })
                .on('mouseleave.pickList', function(e) {
                    $(this).removeClass('ui-state-hover');
                })
                .on('mousedown.pickList', function(e) {
                    var item = $(this).closest('li.ui-picklist-item');
                    $this.focusedItem = item;
                })
                .on('click.pickList', function(e) {
                    $this.checkboxClick = true;

                    var item = $(this).closest('li.ui-picklist-item');
                    if ($this.cfg.transferOnCheckboxClick) {
                        if (item.parent().hasClass('ui-picklist-source')) {
                            $this.transfer(item, $this.sourceList, $this.targetList, 'checkbox', function() {
                                $this.unselectItem(item);
                            });
                        } else {
                            $this.transfer(item, $this.targetList, $this.sourceList, 'checkbox', function() {
                                $this.unselectItem(item);
                            });
                        }
                    } else {
                        if (item.hasClass('ui-state-highlight')) {
                            $this.unselectItem(item, true);
                        } else {
                            $this.selectItem(item, true);
                        }
                        $this.focusedItem = item;
                    }
                });
        }
    }
}

from primefaces.

EugenFischer avatar EugenFischer commented on May 28, 2024

awesome

from primefaces.

EugenFischer avatar EugenFischer commented on May 28, 2024

Thanks a lot.
Even if there is no direct usecase for,
but maybe you have an idea why the scrolling also happens or right-clicking on an element.

from primefaces.

melloware avatar melloware commented on May 28, 2024

oh let me check the right click i was more worried about that long left click.

from primefaces.

melloware avatar melloware commented on May 28, 2024

Try this

if (PrimeFaces.widget.PickList) {
    PrimeFaces.widget.PickList.prototype.bindItemEvents = function() {
        var $this = this;

        this.items.on('mouseover.pickList', function(e) {
                $(this).addClass('ui-state-hover');
            })
            .on('mouseout.pickList', function(e) {
                $(this).removeClass('ui-state-hover');
            })
                .on('mousedown.pickList', function(e) {
                    var item = $(this).closest('li.ui-picklist-item');
                    $this.focusedItem = item;
                })
            .on('click.pickList', function(e) {
                //stop propagation
                if ($this.checkboxClick || $this.dragging) {
                    $this.checkboxClick = false;
                    return;
                }

                var item = $(this),
                    parentList = item.parent(),
                    metaKey = (e.metaKey || e.ctrlKey);

                if (!e.shiftKey) {
                    if (!metaKey) {
                        $this.unselectAll();
                    }

                    if (metaKey && item.hasClass('ui-state-highlight')) {
                        $this.unselectItem(item, true);
                    } else {
                        $this.selectItem(item, true);
                        $this.cursorItem = item;
                    }
                } else {
                    $this.unselectAll();

                    if ($this.cursorItem && ($this.cursorItem.parent().is(item.parent()))) {
                        var currentItemIndex = item.index(),
                            cursorItemIndex = $this.cursorItem.index(),
                            startIndex = (currentItemIndex > cursorItemIndex) ? cursorItemIndex : currentItemIndex,
                            endIndex = (currentItemIndex > cursorItemIndex) ? (currentItemIndex + 1) : (cursorItemIndex + 1);

                        for (var i = startIndex; i < endIndex; i++) {
                            var it = parentList.children('li.ui-picklist-item').eq(i);

                            if (it.is(':visible')) {
                                if (i === (endIndex - 1))
                                    $this.selectItem(it, true);
                                else
                                    $this.selectItem(it);
                            }
                        }
                    } else {
                        $this.selectItem(item, true);
                        $this.cursorItem = item;
                    }
                }

                /* For keyboard navigation */
                $this.removeOutline();
                $this.focusedItem = item;
                parentList.trigger('focus.pickList');
            });

        if (this.cfg.transferOnDblclick) {
            this.items.on('dblclick.pickList', function() {
                var item = $(this);

                if ($(this).parent().hasClass('ui-picklist-source')) {
                    $this.transfer(item, $this.sourceList, $this.targetList, 'dblclick');
                } else {
                    $this.transfer(item, $this.targetList, $this.sourceList, 'dblclick');
                }

                /* For keyboard navigation */
                $this.removeOutline();
                $this.focusedItem = null;

                PrimeFaces.clearSelection();
            });
        }

        if (this.cfg.showCheckbox) {
            this.checkboxes.off().on('mouseenter.pickList', function(e) {
                    $(this).addClass('ui-state-hover');
                })
                .on('mouseleave.pickList', function(e) {
                    $(this).removeClass('ui-state-hover');
                })
                .on('mousedown.pickList', function(e) {
                    var item = $(this).closest('li.ui-picklist-item');
                    $this.focusedItem = item;
                })
                .on('click.pickList', function(e) {
                    $this.checkboxClick = true;

                    var item = $(this).closest('li.ui-picklist-item');
                    if ($this.cfg.transferOnCheckboxClick) {
                        if (item.parent().hasClass('ui-picklist-source')) {
                            $this.transfer(item, $this.sourceList, $this.targetList, 'checkbox', function() {
                                $this.unselectItem(item);
                            });
                        } else {
                            $this.transfer(item, $this.targetList, $this.sourceList, 'checkbox', function() {
                                $this.unselectItem(item);
                            });
                        }
                    } else {
                        if (item.hasClass('ui-state-highlight')) {
                            $this.unselectItem(item, true);
                        } else {
                            $this.selectItem(item, true);
                        }
                        $this.focusedItem = item;
                    }
                });
        }
    }
}

from primefaces.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.