|
68 | 68 | , crossover: namespaceIt('crossover') // fires on window each time dynamic breakpoint bands is crossed
|
69 | 69 | }
|
70 | 70 |
|
71 |
| - // Response.media (normalized matchMedia) |
72 |
| - // @example Response.media("(orientation:landscape)").matches |
73 |
| - // If both versions are undefined, .matches will equal undefined |
74 |
| - // Also see: band / wave / device.band / device.wave / dpr |
| 71 | + // normalized matchMedia |
75 | 72 | , matchMedia = win.matchMedia || win.msMatchMedia
|
76 |
| - , media = matchMedia || function() { return {}; } |
| 73 | + , media = matchMedia ? bind(matchMedia, win) : function() { |
| 74 | + return {}; |
| 75 | + } |
| 76 | + , mq = matchMedia ? function(q) { |
| 77 | + return !!matchMedia.call(win, q); |
| 78 | + } : function() { |
| 79 | + return false; |
| 80 | + } |
77 | 81 |
|
78 | 82 | // http://ryanve.com/lab/dimensions
|
79 | 83 | // http://github.com/ryanve/verge/issues/13
|
|
85 | 89 | var a = docElem['clientHeight'], b = win['innerHeight'];
|
86 | 90 | return a < b ? b : a;
|
87 | 91 | };
|
88 |
| - |
| 92 | + |
89 | 93 | function isNumber(item) {
|
90 | 94 | return item === +item;
|
91 | 95 | }
|
92 | 96 |
|
| 97 | + /** |
| 98 | + * @param {Function} fn |
| 99 | + * @param {*=} scope |
| 100 | + * @return {Function} |
| 101 | + */ |
| 102 | + function bind(fn, scope) { |
| 103 | + return function() { |
| 104 | + return fn.apply(scope, arguments); |
| 105 | + }; |
| 106 | + } |
| 107 | + |
93 | 108 | /**
|
94 | 109 | * @param {{length:number}} stack
|
95 | 110 | * @param {Function} fn
|
|
231 | 246 | // The generic min-device-pixel-ratio is expected to be added to the W3 spec.
|
232 | 247 | // Return false if neither method is available.
|
233 | 248 | decimal = 'only all and (min--moz-device-pixel-ratio:' + decimal + ')';
|
234 |
| - if (media(decimal).matches) return true; |
235 |
| - return !!media(decimal.replace('-moz-', '')).matches; |
| 249 | + if (mq(decimal)) return true; |
| 250 | + return mq(decimal.replace('-moz-', '')); |
236 | 251 | }
|
237 | 252 |
|
238 | 253 | /**
|
|
0 commit comments