Skip to content
This repository was archived by the owner on Jan 21, 2019. It is now read-only.

Commit 3debc9c

Browse files
committed
Merge pull request #15 from giuseppeg/UMD
Add Module Definition (UMD)
2 parents d018c74 + 729892d commit 3debc9c

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,55 @@ jRes.getBreakpoint();
126126

127127
The breakpoint parameter is required but the enter and exit parameters are optional (of course, at least one is required for something to happen).
128128

129+
##Use as a module
130+
You can also use jRespond as a browser or Node module.
131+
###AMD module
132+
```javascript
133+
require(['jRespond'], function (jRes) {
134+
var mediaQueries = jRes([
135+
{
136+
label: 'tablet',
137+
enter: 768,
138+
exit: 979
139+
}
140+
]);
141+
142+
mediaQueries.addFunc({
143+
breakpoint: 'tablet',
144+
enter: function() {
145+
myInitFunc();
146+
},
147+
exit: function() {
148+
myUnInitFunc();
149+
}
150+
});
151+
});
152+
```
153+
###CommonJS syntax
154+
```javascript
155+
require(['require', 'jRespond'], function (require) {
156+
var jRes = require('jRespond');
157+
158+
var mediaQueries = jRes([
159+
{
160+
label: 'tablet',
161+
enter: 768,
162+
exit: 979
163+
}
164+
]);
165+
166+
mediaQueries.addFunc({
167+
breakpoint: 'tablet',
168+
enter: function() {
169+
myInitFunc();
170+
},
171+
exit: function() {
172+
myUnInitFunc();
173+
}
174+
});
175+
});
176+
```
177+
129178
##Performance
130179

131180
jRespond is 1.3kb minified and only polls for the browser width every 500ms. If it detects a change the polling speed is increased to 100ms only until the browser width stops changing.

js/jRespond.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
/*! jRespond.js v 0.10 | Author: Jeremy Fields [jeremy.fields@viget.com], 2013 | License: MIT */
22

3-
(function(win,doc,undefined) {
3+
// Universal Module Definition
4+
;(function (window, name, fn) {
5+
// Node module pattern
6+
if (typeof module === "object" && module && typeof module.exports === "object") {
7+
module.exports = fn;
8+
} else {
9+
// browser
10+
window[name] = fn;
11+
12+
// AMD definition
13+
if (typeof define === "function" && define.amd) {
14+
define(name, [], function (module) {
15+
return fn;
16+
});
17+
}
18+
}
19+
}(this, 'jRespond', function(win,doc,undefined) {
420

521
'use strict';
622

7-
win.jRespond = function(breakpoints) {
23+
return function(breakpoints) {
824

925
// array for registered functions
1026
var mediaListeners = [];
@@ -218,4 +234,4 @@
218234

219235
};
220236

221-
}(this,this.document));
237+
}(this,this.document)));

js/jRespond.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)