nathansmith / adapt

Adapt.js serves CSS based on screen width.

Home Page:http://adapt.960.gs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not an issue but an idea.

invantix opened this issue · comments

I did not see any other way to comment than to create an issue.

I like the callback feature however I needed to know the difference between page loading an resizing. I saw that you were checking url_old in adapt() so I added a boolean parameter to change() and pass it to callback():

function change(i, width, loading) {
.........

callback && callback(i, width, loading);

}

/////////////////////////////////////////////////////////////////////
And then in adapt() we call change like this:

if (!url_old) {
  // Apply changes.
  change(i, width, true);

...
else if (url_old !== url) {
// Apply changes.
change(i, width, false);

This works and my callback can behave differently on resize vs page load.

I'll look into this soon, just didn't have time today.

So, I'm a bit confused as to the benefit of this being passed, because this doesn't necessarily even mean the DOM has loaded, and certainly isn't a window.onload fire. Adapt does its initial work before any of that happens.

Meaning, if you're wanting to use Adapt for the equivalent of jQuery's $(document).ready, you'd be getting a false positive. Is that what you were getting at, or have I misunderstood?

I was not using this to tell if the DOM had finished loading.

I wanted to do nothing when this callback was called the first time the page is loaded and some work when the callback happens during a page re-size. The change worked for me.

Cheers