Skip to content

Require.js plugin for loading files conditionally, based on matchMedia.

License

Notifications You must be signed in to change notification settings

e-sites/require-matchmedia-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Require.js matchMedia plugin

A Require.js plugin for loading files conditionally, based on `window.matchMedia`.

A demo can be found at: http://github.e-sites.nl/require-matchmedia-plugin (or check this video)

Disclaimer: this plugin is still work in progress! Hell, it's even my first require.js plugin...so please be gentle with me.

##Syntax

requirejs([' [script-alias] ! ( [mediaquery] ) ? [path] ']);

##Getting started Include Require.js in your project if you haven't done that already. After that, make sure you include the following options in your config.

require.config({
	paths: {
		'mm': '/matchmedia'
	},
	waitSeconds: 0 // this is needed to prevent timeout errors
});

##Examples

requirejs(['mm!(screen and (max-width: 500px))?scripts/maxwidth']);
requirejs(['mm!(screen and (min-width: 1200px))?scripts/minwidth']);
requirejs(['mm!((min-width: 768px) and (max-width: 979px))?scripts/min-maxwidth.js']);
requirejs(['mm!(all and (orientation:landscape))?scripts/orientation-landscape']);
requirejs(['mm!(all and (orientation:portrait))?scripts/orientation-portrait']);
requirejs(['mm!(only screen and (min-device-pixel-ratio:2), only screen and (min-resolution: 192dpi))?scripts/retina.js']);

##Browser support Basically all browsers that have window.matchMedia support. If not available you can use this polyfill.

##Feedback / comments Contact me on Twitter or file an issue.

##License Copyright (C) 2014 e-sites, http://e-sites.nl/ Licensed under the MIT license.

About

Require.js plugin for loading files conditionally, based on matchMedia.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published