Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[READY] Triggering on Events/Manually #25

Merged

Conversation

thom4parisot
Copy link
Contributor

The intention

Imager takes care about some events like scroll and resize. Depending of the OS/Browser, they are triggered in a different order, so does orientationchange.

If people also have their own business logic for these events or use a third party lazy loader like lazyload, they will hardly deal Imager as they can't control the events execution order.

The proposal

Removing the internal event listening (people use their own or plain old DOM Events), eventually providing an external plugin

var imgr = new Imager();

document.getElementById('fullscreen-button-reader').addEventListener('click', imgr.resize);

$(window).on('resize', function(){
  $get('/news').then(updateSidebarEntries).then(imgr.resize);
});

@Integralist
Copy link
Contributor

@oncletom I like this proposal, I think it could be very useful. The only thing I would like to see incorporated as well is for Imager to default to using the onresize event for those users who have very simple needs and who don't want the hassle of having to write their own event code.

I know it would be a simple case of a user just writing something like...

window.onresize = function(){
    imgr.resize();
};

...but if the resize event was the default behaviour then it would be much cleaner to encapsulate that into Imager (as we do currently) and just let the user override that if they wanted to handle that themselves.

On a side note see #30

@thom4parisot thom4parisot mentioned this pull request Oct 30, 2013
12 tasks
@thom4parisot
Copy link
Contributor Author

This is ready to be reviewed.

// default settings are
// onResize event: true
// lazyload: false

var imgr = new Imager({ onResize: false });
imgr.registerResizeEvent();

// equals
var imgr = new Imager({ onResize: true });

// and
var imgr = new Imager();

- moved event setup to init
- created dedicated method to register events whenever you want
Enabling Chrome for debug as the stack trace is more readable.
Integralist added a commit that referenced this pull request Nov 20, 2013
[READY] Triggering on Events/Manually
@Integralist Integralist merged commit 4b7fb84 into bbc:refactoring-base Nov 20, 2013
@thom4parisot thom4parisot deleted the feature-optional-events branch November 20, 2013 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants