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

Add Names instead of Widths as an option? #10

Closed
mdmoura opened this issue Jun 16, 2012 · 3 comments
Closed

Add Names instead of Widths as an option? #10

mdmoura opened this issue Jun 16, 2012 · 3 comments

Comments

@mdmoura
Copy link

mdmoura commented Jun 16, 2012

Hello,

At the moment Response uses the following syntax:

<img src="lo-fi.png" data-src1025="hi-fi.png" alt="example" />

Imagine that later on I need to change the breakpoint 1025 ro 1020 ...

Then I will be forced to change the data-src1025 in all images.

Wouldn't it be possible to associated breakpoints values to names?

For example:

1025 would be "desktop", 760 would be "Tablet" ...

Then the images would become:

<img src="lo-fi.png" data-srcdesktop="hi-fi.png" alt="example" />

So in Response.Create there would be an option to associate widths to names as an option.

What do you think?

Thank You,
Miguel

@ryanve
Copy link
Owner

ryanve commented Jun 19, 2012

@Shapper That was actually something I was already meaning to do—I'll make sure to include it in next update. Thanks for the reminder :] Also be advised it's Response.create with a lowercase c.

@mdmoura
Copy link
Author

mdmoura commented Jun 19, 2012

I will be waiting for the change ... Any idea when it will be available?

It seems logic to have the names option. But great work.

I am using Response on a project and it works great.

Thank You,
Miguel

@ryanve
Copy link
Owner

ryanve commented Jun 19, 2012

@Shapper I just updated the source in the repo to version 0.6.0 and it has what you seek. You have to define a custom test. Like this—this works:

Response.addTest('myCustom', (function(R) { 
    // The hash's keys must match the breakpoint nicknames:
    var hash = { lo: 0, med: 481, hi: 961 }; 
    return function(breakpoint) {
        return R.viewportW() >= hash[breakpoint];
    };
}(Response))).create({
    prefix: 'my-' // specify a prefix
  , prop: 'myCustom' // must match first parameter of .addTest()
  , breakpoints: ['lo', 'med', 'hi'] // must be ordered lowest to highest
  , dynamic: true // because it changes on resize
});

and use:

<div data-my-lo="looooooo"
     data-my-med="meeeeed"
     data-my-hi="hiiiiiii"
>fallback content</div>

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

No branches or pull requests

2 participants