MCPcopy Create free account
hub / github.com/OpenReservation/OpenReservation / applyMedia

Function applyMedia

OpenReservation/wwwroot/Scripts/respond.js:213–284  ·  view source on GitHub ↗
(fromResize)

Source from the content-addressed store, hash-verified

211
212 //enable/disable styles
213 applyMedia = function (fromResize) {
214 var name = "clientWidth",
215 docElemProp = docElem[name],
216 currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[name] || docElemProp,
217 styleBlocks = {},
218 lastLink = links[links.length - 1],
219 now = (new Date()).getTime();
220
221 //throttle resize calls
222 if (fromResize && lastCall && now - lastCall < resizeThrottle) {
223 clearTimeout(resizeDefer);
224 resizeDefer = setTimeout(applyMedia, resizeThrottle);
225 return;
226 }
227 else {
228 lastCall = now;
229 }
230
231 for (var i in mediastyles) {
232 var thisstyle = mediastyles[i],
233 min = thisstyle.minw,
234 max = thisstyle.maxw,
235 minnull = min === null,
236 maxnull = max === null,
237 em = "em";
238
239 if (!!min) {
240 min = parseFloat(min) * (min.indexOf(em) > -1 ? (eminpx || getEmValue()) : 1);
241 }
242 if (!!max) {
243 max = parseFloat(max) * (max.indexOf(em) > -1 ? (eminpx || getEmValue()) : 1);
244 }
245
246 // if there's no media query at all (the () part), or min or max is not null, and if either is present, they're true
247 if (!thisstyle.hasquery || (!minnull || !maxnull) && (minnull || currWidth >= min) && (maxnull || currWidth <= max)) {
248 if (!styleBlocks[thisstyle.media]) {
249 styleBlocks[thisstyle.media] = [];
250 }
251 styleBlocks[thisstyle.media].push(rules[thisstyle.rules]);
252 }
253 }
254
255 //remove any existing respond style element(s)
256 for (var i in appendedEls) {
257 if (appendedEls[i] && appendedEls[i].parentNode === head) {
258 head.removeChild(appendedEls[i]);
259 }
260 }
261
262 //inject active styles, grouped by media type
263 for (var i in styleBlocks) {
264 var ss = doc.createElement("style"),
265 css = styleBlocks[i].join("\n");
266
267 ss.type = "text/css";
268 ss.media = i;
269
270 //originally, ss was appended to a documentFragment and sheets were appended in bulk.

Callers 2

translateFunction · 0.85
callMediaFunction · 0.85

Calls 1

getEmValueFunction · 0.85

Tested by

no test coverage detected