onScreen icon indicating copy to clipboard operation
onScreen copied to clipboard

Added direction to enter and leave event

Open liqueflies opened this issue 8 years ago • 6 comments

Added parameter direction to 'enter' and 'leave' callback. added sinon for testing, and test for direction parameter.

liqueflies avatar Aug 02 '16 13:08 liqueflies

Hey! Thanks for the Pull Request. The build is failing on Travis CI. Apparently due to some linting issues:

/home/travis/build/silvestreh/onScreen/test/index_test.js
    error  'calledCallback' is defined but never used                 no-unused-vars
    error  'calledCallback' is never reassigned, use 'const' instead  prefer-const
    error  Block must not be padded by blank lines                    padded-blocks

EDIT: Also, the feature seems to only cover vertical scrolling.

silvestreh avatar Aug 02 '16 22:08 silvestreh

Some other things I'm noticing… Would you care to explain these?

  • Why would scrollTop be public?
  • Could the direction parameter be part of the options object?
  • What's the benefit of knowing the direction? I'm thinking that you could check which direction you're scrolling outside the library while implementing it in a project… something like:
const os = new OnScreen();
const direction = {
    up() { /* implement to return true */ },
    down() { /* implement to return true */ },
    left() { /* implement to return true */ },
    right() { /* implement to return true */ },
};

os.on('enter', (element) => {
    if (direction.up) {
        // do something
    }
});
  • Finally: if I end up merging this PR we'll need documentation for it 😄

Thanks!

silvestreh avatar Aug 02 '16 23:08 silvestreh

the feature seems to only cover vertical scrolling

you're right, i'll fix soon

Why would scrollTop be public?

I just put it as object prop, the idea is to set a default value then on scroll (the function debouncedScroll) check the direction

Could the direction parameter be part of the options object?

not sure to understand. you want object direction on options and then set when is on debounceScroll?

What's the benefit of knowing the direction? I'm thinking that you could check which direction you're scrolling outside the library while implementing it in a project

yes, I was able to extends OnScreen also and hack this feature, but why bind another scroll event? With onscreen you can get also direction and decide to use it or not :) For that reason I decided to try improve with this feature.

I will update you with fixes if you want, thanks a lot!

liqueflies avatar Aug 03 '16 07:08 liqueflies

Added direction object, now you can check with

if(direction.up) { /* tell me baby */ }

test updated.

docs updated ! 👍

build passed on travis it seems ! 🎉

if you don't like something feel free to change, or to tell me what you prefer.

Thank you for feedback! :)

liqueflies avatar Aug 03 '16 09:08 liqueflies

Hi, for internet explorer fix direction I used x: window.pageXOffset || document.documentElement.scrollLeft, y: window.pageYOffset || document.documentElement.scrollTop

caiter78 avatar Sep 02 '16 21:09 caiter78

Added also pageXOffset and pageYOffset for solving compatibility issue. Thanks @caiter78

liqueflies avatar Sep 05 '16 07:09 liqueflies