You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//if the query contains this property, then we need to do a check to see if it passes the threshold. If any of the matches are false, then the media query does not pass.
110
+
varmatch=checkForMatch(e,query);
111
+
if(!match){
112
+
didMQMatch=false;
113
+
}
114
+
});
115
+
});
116
+
117
+
returndidMQMatch;
118
+
}
119
+
120
+
functioncheckForMatch(exp,query){
121
+
varval=query[exp.property],
122
+
isMatch=false;
123
+
124
+
//if there's a value for this property, then we need to see if it is within the threshold
125
+
//doing an explicit undefined check here so that `0` goes through.
126
+
if(val!==undefined){
127
+
switch(exp.property){
128
+
case'device-width':
129
+
case'device-height':
130
+
case'width':
131
+
case'height':
132
+
isMatch=doesLengthPass(exp,val);
133
+
break;
134
+
135
+
case'color':
136
+
case'color-index':
137
+
case'monochrome':
138
+
isMatch=doesColorPass(exp,val);
139
+
break;
140
+
141
+
case'resolution':
142
+
isMatch=doesResolutionPass(exp,val);
143
+
break;
144
+
145
+
case'aspect-ratio':
146
+
isMatch=doesAspectRatioPass(exp,val);
147
+
break;
148
+
149
+
case'orientation':
150
+
case'scan':
151
+
isMatch=doesScanPass(exp,val);
152
+
break;
153
+
154
+
case'grid':
155
+
isMatch=doesGridPass(exp,val);
156
+
break;
157
+
158
+
}
159
+
160
+
returnisMatch;
161
+
}
162
+
163
+
//if there is not a value for the property, then we can return true.
164
+
else{
165
+
returntrue;
166
+
}
167
+
}
168
+
169
+
functioncheckMinMax(expVal,queryVal,modifier){
170
+
switch(modifier){
171
+
case'min':
172
+
//if the value we want is greater than the minimum required, then it's true.
173
+
if(expVal<=queryVal){
174
+
returntrue;
175
+
}
176
+
break;
177
+
case'max':
178
+
//if the value we want is less than or equal to the maximum required, then it's true.
179
+
if(expVal>=queryVal){
180
+
returntrue;
181
+
}
182
+
break;
183
+
default:
184
+
//sometimes we may not have a modifier. in this case, the value has to be an exact match.
185
+
if(expVal===queryVal){
186
+
returntrue;
187
+
}
188
+
break;
189
+
}
190
+
191
+
returnfalse;
192
+
}
193
+
194
+
functiondoesTypePass(parsed,value){
195
+
vartype=(valueinstanceof'string') ? value : 'object'
196
+
if(parsed===value){
197
+
returntrue;
198
+
}
199
+
else{
200
+
returnfalse;
201
+
}
202
+
}
203
+
204
+
functiondoesLengthPass(exp,val){
205
+
varexpToPx=toPx(exp.value),
206
+
valToPx=toPx(val);
207
+
208
+
returncheckMinMax(expToPx,valToPx,exp.modifier);
209
+
}
210
+
211
+
functiondoesColorPass(exp,val){
212
+
varexpInt;
213
+
214
+
//this is the (min-width: foo) and (color) use case, which means "any colored device"
0 commit comments