Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2787 rexy 1
/* Bootstrap 4 for IE8 - v4.3.100          */
2
/* https://github.com/namiltd/bootstrap-ie */
3
 
4
// create the nodeType constants if the Node object is not defined
5
if (!window.Node){
6
    var Node = {
7
        ELEMENT_NODE                :  1,
8
        ATTRIBUTE_NODE              :  2,
9
        TEXT_NODE                   :  3,
10
        CDATA_SECTION_NODE          :  4,
11
        ENTITY_REFERENCE_NODE       :  5,
12
        ENTITY_NODE                 :  6,
13
        PROCESSING_INSTRUCTION_NODE :  7,
14
        COMMENT_NODE                :  8,
15
        DOCUMENT_NODE               :  9,
16
        DOCUMENT_TYPE_NODE          : 10,
17
        DOCUMENT_FRAGMENT_NODE      : 11,
18
        NOTATION_NODE               : 12
19
    };
20
}
21
 
22
(function() {
23
    if (!Object.keys) {
24
        Object.keys = function(obj) {
25
            if (obj !== Object(obj)) {
26
                throw new TypeError('Object.keys called on a non-object');
27
            }
28
 
29
            var keys = [];
30
 
31
            for (var i in obj) {
32
                if (Object.prototype.hasOwnProperty.call(obj, i)) {
33
                    keys.push(i);
34
                }
35
            }
36
 
37
            return keys;
38
        };
39
    }
40
}());
41
 
42
(function() {
43
    if (!Object.create) {
44
        Object.create = function(proto, props) {
45
            if (typeof props !== "undefined") {
46
                throw "The multiple-argument version of Object.create is not provided by this browser and cannot be shimmed.";
47
            }
48
            function ctor() { }
49
            ctor.prototype = proto;
50
 
51
            return new ctor();
52
        };
53
    }
54
}());
55
 
56
(function() {
57
    if (!Array.prototype.forEach) {
58
        Array.prototype.forEach = function(fn, scope) {
59
            for(var i = 0, len = this.length; i < len; ++i) {
60
                fn.call(scope, this[i], i, this);
61
            }
62
        };
63
    }
64
}());
65
 
66
// ES 15.2.3.6 Object.defineProperty ( O, P, Attributes )
67
// Partial support for most common case - getters, setters, and values
68
(function() {
69
    if (!Object.defineProperty ||
70
       !(function () { try { Object.defineProperty({}, 'x', {}); return true; } catch (e) { return false; } } ())) {
71
        var orig = Object.defineProperty;
72
        Object.defineProperty = function (o, prop, desc) {
73
            // In IE8 try built-in implementation for defining properties on DOM prototypes.
74
            if (orig) { try { return orig(o, prop, desc); } catch (e) {} }
75
 
76
            if (o !== Object(o)) { throw TypeError("Object.defineProperty called on non-object"); }
77
            if (Object.prototype.__defineGetter__ && ('get' in desc)) {
78
                Object.prototype.__defineGetter__.call(o, prop, desc.get);
79
            }
80
            if (Object.prototype.__defineSetter__ && ('set' in desc)) {
81
                Object.prototype.__defineSetter__.call(o, prop, desc.set);
82
            }
83
            if ('value' in desc) {
84
                o[prop] = desc.value;
85
            }
86
 
87
            return o;
88
        };
89
    }
90
}());
91
 
92
(function() {
93
    if (!Function.prototype.bind) {
94
        Function.prototype.bind = function (oThis) {
95
            if (typeof this !== "function") {
96
                // closest thing possible to the ECMAScript 5 internal IsCallable function
97
                throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
98
            }
99
 
100
        var aArgs = Array.prototype.slice.call(arguments, 1),
101
            fToBind = this,
102
            fNOP = function () {},
103
            fBound = function () {
104
                return fToBind.apply(this instanceof fNOP && oThis ? this: oThis, aArgs.concat(Array.prototype.slice.call(arguments)));
105
            };
106
 
107
            fNOP.prototype = this.prototype;
108
            fBound.prototype = new fNOP();
109
 
110
            return fBound;
111
        };
112
    }
113
}());
114
 
115
(function() {
116
    if (!Array.prototype.indexOf) {
117
        Array.prototype.indexOf = function(elt /*, from*/) {
118
            var len = this.length >>> 0;
119
 
120
            var from = Number(arguments[1]) || 0;
121
            from = (from < 0) ? Math.ceil(from) : Math.floor(from);
122
            if (from < 0) {
123
                from += len;
124
            }
125
            for (; from < len; from++) {
126
                if (from in this && this[from] === elt) {
127
                    return from;
128
                }
129
            }
130
 
131
            return -1;
132
        };
133
    }
134
}());
135
 
136
(function() {
137
  var _slice = Array.prototype.slice;
138
  Array.prototype.slice = function() {
139
    if(this instanceof Array) {
140
      return _slice.apply(this, arguments);
141
    } else {
142
      var result = [];
143
      var start = (arguments.length >= 1) ? arguments[0] : 0;
144
      var end = (arguments.length >= 2) ? arguments[1] : this.length;
145
      for(var i=start; i<end; i++) {
146
        result.push(this[i]);
147
      }
148
      return result;
149
    }
150
  };
151
})();
152
 
153
// adds classList support (as Array) to Element.prototype for IE8-9
154
(function() {
155
  Object.defineProperty(Element.prototype, 'classList', {
156
    get:function(){
157
        var element=this,domTokenList=(element.getAttribute('class')||'').replace(/^\s+|\s$/g,'').split(/\s+/g);
158
        if (domTokenList[0]==='') domTokenList.splice(0,1);
159
        function setClass(){
160
            if (domTokenList.length > 0) element.setAttribute('class', domTokenList.join(' '));
161
            else element.removeAttribute('class');
162
        }
163
        domTokenList.toggle=function(className,force){
164
            if (force!==undefined){
165
                if (force) domTokenList.add(className);
166
                else domTokenList.remove(className);
167
            }
168
            else {
169
                if (domTokenList.indexOf(className)!==-1) domTokenList.splice(domTokenList.indexOf(className),1);
170
                else domTokenList.push(className);
171
            }
172
            setClass();
173
        };
174
        domTokenList.add=function(){
175
            var args=[].slice.call(arguments);
176
            for (var i=0,l=args.length;i<l;i++){
177
                if (domTokenList.indexOf(args[i])===-1) domTokenList.push(args[i]);
178
            }
179
            setClass();
180
        };
181
        domTokenList.remove=function(){
182
            var args=[].slice.call(arguments);
183
            for (var i=0,l=args.length;i<l;i++){
184
                if (domTokenList.indexOf(args[i])!==-1) domTokenList.splice(domTokenList.indexOf(args[i]),1);
185
            }
186
            setClass();
187
        };
188
        domTokenList.item=function(i){
189
            return domTokenList[i];
190
        };
191
        domTokenList.contains=function(className){
192
            return domTokenList.indexOf(className)!==-1;
193
        };
194
        domTokenList.replace=function(oldClass,newClass){
195
            if (domTokenList.indexOf(oldClass)!==-1) domTokenList.splice(domTokenList.indexOf(oldClass),1,newClass);
196
            setClass();
197
        };
198
        domTokenList.value = (element.getAttribute('class')||'');
199
        return domTokenList;
200
    }
201
  });
202
})();
203
 
204
/**
205
 * Modified code based on remPolyfill.js (c) Nicolas Bouvrette https://github.com/nbouvrette/remPolyfill
206
 *
207
 * Customizations:
208
 *
209
 * 1) Added new method `addCallBackWhenReady` to perform callbacks once the polyfill has been applied (especially useful for
210
 *    onload scrolling events.
211
 * 2) Added REM support.
212
 *
213
 **/
214
 
215
/**
216
 * For browsers that do not support REM units, fallback to pixels.
217
 */
218
window.remPolyfill = {
219
 
220
    /** @property Number|null - The body's font size.
221
     *  @private */
222
    bodyFontSize: null,
223
 
224
    /**
225
     * Get the body font size.
226
     *
227
     * @returns {Number} - The body font size in pixel (number only).
228
     */
229
    getBodyFontSize: function() {
230
        if (!this.bodyFontSize) {
231
            if (!document.body) {
232
                var bodyElement = document.createElement('body');
233
                document.documentElement.appendChild(bodyElement);
234
                this.bodyFontSize = parseFloat(this.getStyle(document.body, 'fontSize'));
235
                document.documentElement.removeChild(bodyElement);
236
                bodyElement = null;
237
            } else {
238
                this.bodyFontSize = parseFloat(this.getStyle(document.body, 'fontSize'));
239
            }
240
        }
241
        return this.bodyFontSize;
242
    },
243
 
244
    /**
245
     * Get the style of an element for a given property.
246
     *
247
     * @private
248
     *
249
     * @param {HTMLElement} element - The HTML element.
250
     * @param {string} property     - The property of the style to get.
251
     */
252
    getStyle: function(element, property) {
253
        if (typeof window.getComputedStyle !== 'undefined') {
254
            return window.getComputedStyle(element, null).getPropertyValue(property);
255
        } else {
256
            return element.currentStyle[property];
257
        }
258
    },
259
 
260
    /**
261
     * Implement this script on a given element.
262
     *
263
     * @private
264
     *
265
     * @param {string} cssText              - The CSS text of the link element.
266
     */
267
    replaceCSS: function (cssText) {
268
        if (cssText) {
269
            // Replace all properties containing REM units with their pixel equivalents.
270
            return cssText.replace(
271
                /([\d]+\.[\d]+|\.[\d]+|[\d]+)rem/g, function (fullMatch, groupMatch) {
272
                    return Math.round(parseFloat(groupMatch * remPolyfill.getBodyFontSize())) + 'px';}
273
            ).replace(
274
                /calc\s*\(\s*\(\s*([\d]+)\s*px\s*([\+-])\s*([\d]+)\s*px\s*\)\s*\*\s*(-?[\d]+)\s*\)/g, function (fullMatch, MatchArg1, MatchSign, MatchArg2, MatchArg3) {
275
                    return ((parseInt(MatchArg1)+(MatchSign=='-'?-1:1)*parseInt(MatchArg2))*parseInt(MatchArg3))+'px';}
276
            ).replace(
277
                /calc\s*\(\s*([\d]+)\s*px\s*([\+-])\s*([\d]+)\s*px\s*\)/g, function (fullMatch, MatchArg1, MatchSign, MatchArg2) {
278
                    return (parseInt(MatchArg1)+(MatchSign=='-'?-1:1)*parseInt(MatchArg2))+'px';}
279
            ).replace(
280
                /::/g, ':'
281
            ).replace(
282
                /:disabled/g, '._disabled'
283
            ).replace(
284
                /:invalid/g, '._invalid'
285
            ).replace(
286
                /:valid/g, '._valid'
287
            ).replace(
288
                /background-color\s*:\s*rgba\s*\(\s*([\d]+)\s*,\s*([\d]+)\s*,\s*([\d]+)\s*,\s*([\d\.]+)\s*\)/g, function (fullMatch, MatchR, MatchG, MatchB, MatchA) {
289
                    var ARGBhex = (4294967296+16777216*Math.round(parseFloat(MatchA)*255)+65536*parseInt(MatchR)+256*parseInt(MatchG)+parseInt(MatchB)).toString(16).substr(1);
290
                    return 'filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#'+ARGBhex+', endColorstr=#'+ARGBhex+')';}
291
            ).replace(
292
                /rgba\s*\(\s*([\d]+)\s*,\s*([\d]+)\s*,\s*([\d]+)\s*,\s*([\d\.]+)\s*\)/g, function (fullMatch, MatchR, MatchG, MatchB, MatchA) {
293
                    var MR = parseInt(MatchR), MG = parseInt(MatchG), MB = parseInt(MatchB), MA = parseFloat(MatchA);
294
                    if ((MR==255)&&(MG==255)&&(MB==255)) { //dark background
295
                        return 'rgb(' + Math.round(MA * 255) + ', ' + Math.round(MA * 255) + ', ' + Math.round(MA * 255) +')';
296
                    } else { //else
297
                        return 'rgb(' + Math.round((1-MA) * 255 + MA * MR) + ', ' + Math.round((1-MA) * 255 + MA * MG) + ', ' + Math.round((1-MA) * 255 + MA * MB) +')';
298
                    }
299
                 }
300
            ).replace(
301
                /opacity\s*:\s*([\d]+\.[\d]+|\.[\d]+|[\d]+)/g, function (fullMatch, groupMatch) {
302
                    return 'filter:alpha(opacity=' + Math.round(parseFloat(groupMatch * 100)) + ')';}
303
            );
304
        }
305
    },
306
 
307
    /**
308
     * Implement this script on a given element.
309
     *
310
     * @param {HTMLLinkElement} linkElement - The link element to polyfill.
311
     */
312
    implement: function (linkElement) {
313
        if (!linkElement.href) {
314
            return;
315
        }
316
 
317
        var request = null;
318
 
319
        if (window.XMLHttpRequest) {
320
            request = new XMLHttpRequest();
321
        } else if (window.ActiveXObject) {
322
            try {
323
                request = new ActiveXObject("Msxml2.XMLHTTP");
324
            } catch (exception) {
325
                try {
326
                    request = new ActiveXObject("Microsoft.XMLHTTP");
327
                } catch (exception) {
328
                    request = null;
329
                }
330
            }
331
        }
332
 
333
        if (!request) {
334
            return;
335
        }
336
 
337
        request.open('GET', linkElement.href, true);
338
        request.onreadystatechange = function() {
339
            if ( request.readyState === 4 ) {
340
                linkElement.styleSheet.cssText = remPolyfill.replaceCSS(request.responseText);
341
            }
342
        };
343
 
344
        request.send(null);
345
    }
346
};
347
 
348
var linkElements = document.querySelectorAll('link[rel=stylesheet]');
349
for (var linkElementId in linkElements) {
350
    if (Object.prototype.hasOwnProperty.call(linkElements, linkElementId)) {
351
        remPolyfill.implement(linkElements[linkElementId]);
352
    }
353
}
354
 
355
/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
356
/*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */
357
(function (w) {
358
    "use strict";
359
    w.matchMedia = w.matchMedia || function (doc, undefined) {
360
            var bool, docElem = doc.documentElement, refNode = docElem.firstElementChild || docElem.firstChild,
361
                fakeBody = doc.createElement("body"), div = doc.createElement("div");
362
            div.id = "mq-test-1";
363
            div.style.cssText = "position:absolute;top:-100em";
364
            fakeBody.style.background = "none";
365
            fakeBody.appendChild(div);
366
            return function (q) {
367
                div.innerHTML = '&shy;<style media="' + q + '"> #mq-test-1 { width: 42px; }</style>';
368
                docElem.insertBefore(fakeBody, refNode);
369
                bool = div.offsetWidth === 42;
370
                docElem.removeChild(fakeBody);
371
                return {
372
                    matches: bool,
373
                    media: q
374
                };
375
            };
376
        }(w.document);
377
})(this);
378
 
379
/* Respond.js: min/max-width media query polyfill. (c) Scott Jehl. MIT Lic. j.mp/respondjs  */
380
 
381
(function (w) {
382
    "use strict";
383
    //exposed namespace
384
    var respond = {};
385
    w.respond = respond;
386
    //define update even in native-mq-supporting browsers, to avoid errors
387
    respond.update = function () {
388
    };
389
    //define ajax obj
390
    var requestQueue = [],
391
        xmlHttp = function () {
392
            var xmlhttpmethod = false;
393
            try {
394
                xmlhttpmethod = new w.XMLHttpRequest();
395
            } catch (e) {
396
                xmlhttpmethod = new w.ActiveXObject("Microsoft.XMLHTTP");
397
            }
398
            return function () {
399
                return xmlhttpmethod;
400
            };
401
        }(),
402
        //tweaked Ajax functions from Quirksmode
403
        ajax = function (url, callback) {
404
            var req = xmlHttp();
405
            if (!req) {
406
                return;
407
            }
408
            try {
409
                req.open("GET", url, true);
410
                req.onreadystatechange = function () {
411
                    if (req.readyState !== 4 || req.status !== 200 && req.status !== 304) {
412
                        return;
413
                    }
414
                    callback( remPolyfill.replaceCSS(req.responseText) );
415
                };
416
                if (req.readyState === 4) {
417
                    return;
418
                }
419
                req.send(null);
420
            }
421
            catch ( e ) {
422
            }
423
        }, isUnsupportedMediaQuery = function (query) {
424
            return query.replace(respond.regex.minmaxwh, '').match(respond.regex.other);
425
        };
426
    //expose for testing
427
    respond.ajax = ajax;
428
    respond.queue = requestQueue;
429
    respond.unsupportedmq = isUnsupportedMediaQuery;
430
    respond.regex = {
431
        media: /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,
432
        keyframes: /@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,
433
        comments: /\/\*[^*]*\*+([^/][^*]*\*+)*\//gi,
434
        urls: /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,
435
        findStyles: /@media *([^\{]+)\{([\S\s]+?)$/,
436
        only: /(only\s+)?([a-zA-Z]+)\s?/,
437
        minw: /\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/,
438
        maxw: /\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/,
439
        minmaxwh: /\(\s*m(in|ax)\-(height|width)\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/gi,
440
        other: /\([^\)]*\)/g
441
    };
442
    //expose media query support flag for external use
443
    respond.mediaQueriesSupported = w.matchMedia && w.matchMedia("only all") !== null && w.matchMedia("only all").matches;
444
    //if media queries are supported, exit here
445
    if (respond.mediaQueriesSupported) {
446
        return;
447
    }
448
    respond.callbackQueue = [];
449
    respond.addCallBackWhenReady = function (callback) {
450
        respond.callbackQueue.push(callback);
451
    };
452
    respond.callback = function () {
453
        if (respond.callbackQueue.length) {
454
            for (var callback in respond.callbackQueue) {
455
                respond.callbackQueue[callback]();
456
            }
457
        }
458
    };
459
 
460
    //define vars
461
    var doc = w.document,
462
        docElem = doc.documentElement,
463
        mediastyles = [],
464
        rules = [],
465
        appendedEls = [],
466
        parsedSheets = {},
467
        resizeThrottle = 30,
468
        head = doc.getElementsByTagName("head")[0] || docElem,
469
        base = doc.getElementsByTagName("base")[0],
470
        links = head.getElementsByTagName("link"),
471
 
472
        lastCall,
473
        resizeDefer,
474
 
475
        //cached container for 1em value, populated the first time it's needed
476
        eminpx,
477
 
478
        // returns the value of 1em in pixels
479
        getEmValue = function () {
480
            var ret,
481
                div = doc.createElement('div'),
482
                body = doc.body,
483
                originalHTMLFontSize = docElem.style.fontSize,
484
                originalBodyFontSize = body && body.style.fontSize,
485
                fakeUsed = false;
486
 
487
            div.style.cssText = "position:absolute;font-size:1em;width:1em";
488
            if (!body) {
489
                body = fakeUsed = doc.createElement("body");
490
                body.style.background = "none";
491
            }
492
            // 1em in a media query is the value of the default font size of the browser
493
            // reset docElem and body to ensure the correct value is returned
494
            docElem.style.fontSize = "100%";
495
            body.style.fontSize = "100%";
496
            body.appendChild(div);
497
            if (fakeUsed) {
498
                docElem.insertBefore(body, docElem.firstChild);
499
            }
500
            ret = div.offsetWidth;
501
            if (fakeUsed) {
502
                docElem.removeChild(body);
503
            } else {
504
                body.removeChild(div);
505
            }
506
            // restore the original values
507
            docElem.style.fontSize = originalHTMLFontSize;
508
            if (originalBodyFontSize) {
509
                body.style.fontSize = originalBodyFontSize;
510
            }
511
            //also update eminpx before returning
512
            ret = eminpx = parseFloat(ret);
513
            return ret;
514
        },
515
 
516
        //enable/disable styles
517
        applyMedia = function (fromResize) {
518
            var name = "clientWidth",
519
                docElemProp = docElem[name],
520
                currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[name] || docElemProp,
521
                styleBlocks = {},
522
                lastLink = links[links.length - 1],
523
                now = new Date().getTime();
524
 
525
            //throttle resize calls
526
 
527
            if (fromResize && lastCall && now - lastCall < resizeThrottle) {
528
                w.clearTimeout(resizeDefer);
529
                resizeDefer = w.setTimeout(applyMedia, resizeThrottle);
530
                return;
531
            } else {
532
                lastCall = now;
533
            }
534
            for (var i in mediastyles) {
535
                if (mediastyles.hasOwnProperty(i)) {
536
                    var thisstyle = mediastyles[i],
537
                        min = thisstyle.minw,
538
                        max = thisstyle.maxw,
539
                        minnull = min === null,
540
                        maxnull = max === null,
541
                        em = "em";
542
                    if (!!min) {
543
                        min = parseFloat(min) * (min.indexOf(em) > -1 ? ( eminpx || getEmValue() ) : 1);
544
                    }
545
                    if (!!max) {
546
                        max = parseFloat(max) * (max.indexOf(em) > -1 ? ( eminpx || getEmValue() ) : 1);
547
                    }
548
                    // 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
549
                    if (!thisstyle.hasquery || (!minnull || !maxnull) && (minnull || currWidth >= min) && (maxnull || currWidth <= max)) {
550
                        if (!styleBlocks[thisstyle.media]) {
551
                            styleBlocks[thisstyle.media] = [];
552
                        }
553
                        styleBlocks[thisstyle.media].push(rules[thisstyle.rules]);
554
                    }
555
                }
556
            }
557
            //remove any existing respond style element(s)
558
            for (var j in appendedEls) {
559
                if (appendedEls.hasOwnProperty(j)) {
560
                    if (appendedEls[j] && appendedEls[j].parentNode === head) {
561
                        head.removeChild(appendedEls[j]);
562
                    }
563
                }
564
            }
565
            appendedEls.length = 0;
566
            //inject active styles, grouped by media type
567
            for (var k in styleBlocks) {
568
                if (styleBlocks.hasOwnProperty(k)) {
569
                    var ss = doc.createElement("style"),
570
                        css = styleBlocks[k].join("\n");
571
                    ss.type = "text/css";
572
                    ss.media = k;
573
                    //originally, ss was appended to a documentFragment and sheets were appended in bulk.
574
                    //this caused crashes in IE in a number of circumstances, such as when the HTML element had a bg image set, so appending beforehand seems best. Thanks to @dvelyk for the initial research on this one!
575
                    head.insertBefore(ss, lastLink.nextSibling);
576
                    if (ss.styleSheet) {
577
                        ss.styleSheet.cssText = css;
578
                    } else {
579
                        ss.appendChild(doc.createTextNode(css));
580
                    }
581
                    //push to appendedEls to track for later removal
582
                    appendedEls.push(ss);
583
                }
584
            }
585
        },
586
        //find media blocks in css text, convert to style blocks
587
        translate = function (styles, href, media) {
588
            var qs = styles.replace(respond.regex.comments, "")
589
                    .replace(respond.regex.keyframes, "")
590
                    .match(respond.regex.media),
591
                ql = qs && qs.length || 0;
592
            //try to get CSS path
593
            href = href.substring(0, href.lastIndexOf("/"));
594
            var repUrls = function (css) {
595
                return css.replace(respond.regex.urls, "$1" + href + "$2$3");
596
            }, useMedia = !ql && media;
597
            //if path exists, tack on trailing slash
598
            if (href.length) {
599
                href += "/";
600
            }
601
            //if no internal queries exist, but media attr does, use that
602
            //note: this currently lacks support for situations where a media attr is specified on a link AND
603
            //its associated stylesheet has internal CSS media queries.
604
            //In those cases, the media attribute will currently be ignored.
605
            if (useMedia) {
606
                ql = 1;
607
            }
608
            for (var i = 0; i < ql; i++) {
609
                var fullq, thisq, eachq, eql;
610
                //media attr
611
                if (useMedia) {
612
                    fullq = media;
613
                    rules.push(repUrls(styles));
614
                    //parse for styles
615
                } else {
616
                    fullq = qs[i].match(respond.regex.findStyles) && RegExp.$1;
617
                    rules.push(RegExp.$2 && repUrls(RegExp.$2));
618
                }
619
                eachq = fullq.split(",");
620
                eql = eachq.length;
621
                for (var j = 0; j < eql; j++) {
622
                    thisq = eachq[j];
623
                    if (isUnsupportedMediaQuery(thisq)) {
624
                        continue;
625
                    }
626
                    mediastyles.push({
627
                        media: thisq.split("(")[0].match(respond.regex.only) && RegExp.$2 || "all",
628
                        rules: rules.length - 1,
629
                        hasquery: thisq.indexOf("(") > -1,
630
                        minw: thisq.match(respond.regex.minw) && parseFloat(RegExp.$1) + (RegExp.$2 || ""),
631
                        maxw: thisq.match(respond.regex.maxw) && parseFloat(RegExp.$1) + (RegExp.$2 || "")
632
                    });
633
                }
634
            }
635
            applyMedia();
636
        },
637
 
638
        //recurse through request queue, get css text
639
        makeRequests = function () {
640
            if (requestQueue.length) {
641
                var thisRequest = requestQueue.shift();
642
                ajax(thisRequest.href, function (styles) {
643
                    translate(styles, thisRequest.href, thisRequest.media);
644
                    parsedSheets[thisRequest.href] = true;
645
                    // by wrapping recursive function call in setTimeout
646
                    // we prevent "Stack overflow" error in IE7
647
                    w.setTimeout(function () {
648
                        makeRequests();
649
                    }, 0);
650
                });
651
            } else {
652
                respond.callback();
653
            }
654
        },
655
 
656
        //loop stylesheets, send text content to translate
657
        ripCSS = function () {
658
            for (var i = 0; i < links.length; i++) {
659
                var sheet = links[i],
660
                    href = sheet.href,
661
                    media = sheet.media,
662
                    isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";
663
                //only links plz and prevent re-parsing
664
                if (!!href && isCSS && !parsedSheets[href]) {
665
                    // selectivizr exposes css through the rawCssText expando
666
                    if (sheet.styleSheet && sheet.styleSheet.rawCssText) {
667
                        translate(sheet.styleSheet.rawCssText, href, media);
668
                        parsedSheets[href] = true;
669
                    } else {
670
                        if (!/^([a-zA-Z:]*\/\/)/.test(href) && !base ||
671
                            href.replace(RegExp.$1, "").split("/")[0] === w.location.host) {
672
                            // IE7 doesn't handle urls that start with '//' for ajax request
673
                            // manually add in the protocol
674
                            if (href.substring(0, 2) === "//") {
675
                                href = w.location.protocol + href;
676
                            }
677
                            requestQueue.push({
678
                                href: href,
679
                                media: media
680
                            });
681
                        }
682
                    }
683
                }
684
            }
685
            makeRequests();
686
        };
687
    //translate CSS
688
    ripCSS();
689
 
690
    //expose update for re-running respond later on
691
    respond.update = ripCSS;
692
 
693
    //expose getEmValue
694
    respond.getEmValue = getEmValue;
695
 
696
    //adjust on resize
697
    function callMedia() {
698
        applyMedia(true);
699
    }
700
 
701
    if (w.addEventListener) {
702
        w.addEventListener("resize", callMedia, false);
703
    }
704
    else if (w.attachEvent) {
705
        w.attachEvent("onresize", callMedia);
706
    }
707
})(this);