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

idea: make it easier to disable retina on mobile #5

Closed
philfreo opened this issue May 12, 2013 · 2 comments
Closed

idea: make it easier to disable retina on mobile #5

philfreo opened this issue May 12, 2013 · 2 comments

Comments

@philfreo
Copy link

In some cases it makes sense to load retina images on retina devices, but only if they aren't mobile devices. In a responsive design, sometimes the non-retina version is already big enough to appear "retina" on mobile screens, and you don't want users on a cell internet connection to have to download too much.

I currently can work around it with some copy/pasting, but you could add an option or two that could make this easier for others. There could be a direct enabledForMobile setting, or a more generic retinaEnabledCallback.

// img.retina: load retina version if on retina device
$('img.retina').retina({ suffix: '@2x' });

// img.retina-large: load retina version only if on tablet/desktop
// (for when you don't want mobile to have to download huge images)
$('img.retina-large').retina({
    customFileNameCallback: function($this) {
        newImageSrc = $this.attr('data-retina') || $this.attr('src');
        if (!/Mobile/i.test(navigator.userAgent) ) {
            // Get filename sans extension
            var baseFileName = newImageSrc.replace(/.[^.]+$/,'');
            var baseFileExtension = newImageSrc.replace(/^.*\./,'');

            newImageSrc = baseFileName + '@2x.' + baseFileExtension; 
        }
        return newImageSrc;
    }
});

Another suggestion: make @2x the default suffix option, since that's the most common naming convention for retina images.

@tylercraft
Copy link
Owner

Thanks for the suggestions @philfreo I'm in the process of a move and probably won't have time to add these for a couple weeks. If you'd like to create a pull request, I'd love to view it and merge it.

@tylercraft
Copy link
Owner

It's a bit late I know, but I just added support for this. thanks for the suggestion!

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