PageSourceSearch

https://zuccoliprimary.nt.edu.au/theme/_blueprint/js/pdf/build/compatibility.js

js zuccoliprimary.nt.edu.au collected 2026-10-07 11:48:13 UTC 21,892 bytes, 598 lines download raw bytes

1/* Copyright 2012 Mozilla Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/* globals VBArray, PDFJS */
16
17(function compatibilityWrapper() {
18    'use strict';
19
20    var userAgent = navigator.userAgent;
21
22    var isAndroid = /Android/.test(userAgent);
23    var isAndroidPre3 = /Android\s[0-2][^\d]/.test(userAgent);
24    var isAndroidPre5 = /Android\s[0-4][^\d]/.test(userAgent);
25    var isChrome = userAgent.indexOf('Chrom') >= 0;
26    var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(userAgent);
27    var isIE = userAgent.indexOf('Trident') >= 0;
28    var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent);
29    var isOpera = userAgent.indexOf('Opera') >= 0;
30    var isSafari = /Safari\//.test(userAgent) &&
31        !/(Chrome\/|Android\s)/.test(userAgent);
32
33// Initializing PDFJS global object here, it case if we need to change/disable
34// some PDF.js features, e.g. range requests
35    if (typeof PDFJS === 'undefined') {
36        (typeof window !== 'undefined' ? window : this).PDFJS = {};
37    }
38
39// Checking if the typed arrays are supported
40// Support: iOS<6.0 (subarray), IE<10, Android<4.0
41    (function checkTypedArrayCompatibility() {
42        if (typeof Uint8Array !== 'undefined') {
43            // Support: iOS<6.0
44            if (typeof Uint8Array.prototype.subarray === 'undefined') {
45                Uint8Array.prototype.subarray = function subarray(start, end) {
46                    return new Uint8Array(this.slice(start, end));
47                };
48                Float32Array.prototype.subarray = function subarray(start, end) {
49                    return new Float32Array(this.slice(start, end));
50                };
51            }
52
53            // Support: Android<4.1
54            if (typeof Float64Array === 'undefined') {
55                window.Float64Array = Float32Array;
56            }
57            return;
58        }
59
60        function subarray(start, end) {
61            return new TypedArray(this.slice(start, end));
62        }
63
64        function setArrayOffset(array, offset) {
65            if (arguments.length < 2) {
66                offset = 0;
67            }
68            for (var i = 0, n = array.length; i < n; ++i, ++offset) {
69                this[offset] = array[i] & 0xFF;
70            }
71        }
72
73        function TypedArray(arg1) {
74            var result, i, n;
75            if (typeof arg1 === 'number') {
76                result = [];
77                for (i = 0; i < arg1; ++i) {
78                    result[i] = 0;
79                }
80            } else if ('slice' in arg1) {
81                result = arg1.slice(0);
82            } else {
83                result = [];
84                for (i = 0, n = arg1.length; i < n; ++i) {
85                    result[i] = arg1[i];
86                }
87            }
88
89            result.subarray = subarray;
90            result.buffer = result;
91            result.byteLength = result.length;
92            result.set = setArrayOffset;
93
94            if (typeof arg1 === 'object' && arg1.buffer) {
95                result.buffer = arg1.buffer;
96            }
97            return result;
98        }
99
100        window.Uint8Array = TypedArray;
101        window.Int8Array = TypedArray;
102
103        // we don't need support for set, byteLength for 32-bit array
104        // so we can use the TypedArray as well
105        window.Uint32Array = TypedArray;
106        window.Int32Array = TypedArray;
107        window.Uint16Array = TypedArray;
108        window.Float32Array = TypedArray;
109        window.Float64Array = TypedArray;
110    })();
111
112// URL = URL || webkitURL
113// Support: Safari<7, Android 4.2+
114    (function normalizeURLObject() {
115        if (!window.URL) {
116            window.URL = window.webkitURL;
117        }
118    })();
119
120// Object.defineProperty()?
121// Support: Android<4.0, Safari<5.1
122    (function checkObjectDefinePropertyCompatibility() {
123        if (typeof Object.defineProperty !== 'undefined') {
124            var definePropertyPossible = true;
125            try {
126                // some browsers (e.g. safari) cannot use defineProperty() on DOM objects
127                // and thus the native version is not sufficient
128                Object.defineProperty(new Image(), 'id', { value: 'test' });
129                // ... another test for android gb browser for non-DOM objects
130                var Test = function Test() {};
131                Test.prototype = { get id() { } };
132                Object.defineProperty(new Test(), 'id',
133                    { value: '', configurable: true, enumerable: true, writable: false });
134            } catch (e) {
135                definePropertyPossible = false;
vendor: 9,645 bytes, lines 136-408
136            }
137            if (definePropertyPossible) {
138                return;
139            }
140        }
141
142        Object.defineProperty = function objectDefineProperty(obj, name, def) {
143            delete obj[name];
144            if ('get' in def) {
145                obj.__defineGetter__(name, def['get']);
146            }
147            if ('set' in def) {
148                obj.__defineSetter__(name, def['set']);
149            }
150            if ('value' in def) {
151                obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
152                    this.__defineGetter__(name, function objectDefinePropertyGetter() {
153                        return value;
154                    });
155                    return value;
156                });
157                obj[name] = def.value;
158            }
159        };
160    })();
161
162
163// No XMLHttpRequest#response?
164// Support: IE<11, Android <4.0
165    (function checkXMLHttpRequestResponseCompatibility() {
166        var xhrPrototype = XMLHttpRequest.prototype;
167        var xhr = new XMLHttpRequest();
168        if (!('overrideMimeType' in xhr)) {
169            // IE10 might have response, but not overrideMimeType
170            // Support: IE10
171            Object.defineProperty(xhrPrototype, 'overrideMimeType', {
172                value: function xmlHttpRequestOverrideMimeType(mimeType) {}
173            });
174        }
175        if ('responseType' in xhr) {
176            return;
177        }
178
179        // The worker will be using XHR, so we can save time and disable worker.
180        PDFJS.disableWorker = true;
181
182        Object.defineProperty(xhrPrototype, 'responseType', {
183            get: function xmlHttpRequestGetResponseType() {
184                return this._responseType || 'text';
185            },
186            set: function xmlHttpRequestSetResponseType(value) {
187                if (value === 'text' || value === 'arraybuffer') {
188                    this._responseType = value;
189                    if (value === 'arraybuffer' &&
190                        typeof this.overrideMimeType === 'function') {
191                        this.overrideMimeType('text/plain; charset=x-user-defined');
192                    }
193                }
194            }
195        });
196
197        // Support: IE9
198        if (typeof VBArray !== 'undefined') {
199            Object.defineProperty(xhrPrototype, 'response', {
200                get: function xmlHttpRequestResponseGet() {
201                    if (this.responseType === 'arraybuffer') {
202                        return new Uint8Array(new VBArray(this.responseBody).toArray());
203                    } else {
204                        return this.responseText;
205                    }
206                }
207            });
208            return;
209        }
210
211        Object.defineProperty(xhrPrototype, 'response', {
212            get: function xmlHttpRequestResponseGet() {
213                if (this.responseType !== 'arraybuffer') {
214                    return this.responseText;
215                }
216                var text = this.responseText;
217                var i, n = text.length;
218                var result = new Uint8Array(n);
219                for (i = 0; i < n; ++i) {
220                    result[i] = text.charCodeAt(i) & 0xFF;
221                }
222                return result.buffer;
223            }
224        });
225    })();
226
227// window.btoa (base64 encode function) ?
228// Support: IE<10
229    (function checkWindowBtoaCompatibility() {
230        if ('btoa' in window) {
231            return;
232        }
233
234        var digits =
235            'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
236
237        window.btoa = function windowBtoa(chars) {
238            var buffer = '';
239            var i, n;
240            for (i = 0, n = chars.length; i < n; i += 3) {
241                var b1 = chars.charCodeAt(i) & 0xFF;
242                var b2 = chars.charCodeAt(i + 1) & 0xFF;
243                var b3 = chars.charCodeAt(i + 2) & 0xFF;
244                var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
245                var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
246                var d4 = i + 2 < n ? (b3 & 0x3F) : 64;
247                buffer += (digits.charAt(d1) + digits.charAt(d2) +
248                digits.charAt(d3) + digits.charAt(d4));
249            }
250            return buffer;
251        };
252    })();
253
254// window.atob (base64 encode function)?
255// Support: IE<10
256    (function checkWindowAtobCompatibility() {
257        if ('atob' in window) {
258            return;
259        }
260
261        // https://github.com/davidchambers/Base64.js
262        var digits =
263            'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
264        window.atob = function (input) {
265            input = input.replace(/=+$/, '');
266            if (input.length % 4 === 1) {
267                throw new Error('bad atob input');
268            }
269            for (
270                // initialize result and counters
271                var bc = 0, bs, buffer, idx = 0, output = '';
272                // get next character
273                buffer = input.charAt(idx++);
274                // character found in table?
275                // initialize bit storage and add its ascii value
276                ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
277                    // and if not first of each 4 characters,
278                    // convert the first 8 bits to one ascii character
279                bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
280            ) {
281                // try to find character in table (0-63, not found => -1)
282                buffer = digits.indexOf(buffer);
283            }
284            return output;
285        };
286    })();
287
288// Function.prototype.bind?
289// Support: Android<4.0, iOS<6.0
290    (function checkFunctionPrototypeBindCompatibility() {
291        if (typeof Function.prototype.bind !== 'undefined') {
292            return;
293        }
294
295        Function.prototype.bind = function functionPrototypeBind(obj) {
296            var fn = this, headArgs = Array.prototype.slice.call(arguments, 1);
297            var bound = function functionPrototypeBindBound() {
298                var args = headArgs.concat(Array.prototype.slice.call(arguments));
299                return fn.apply(obj, args);
300            };
301            return bound;
302        };
303    })();
304
305// HTMLElement dataset property
306// Support: IE<11, Safari<5.1, Android<4.0
307    (function checkDatasetProperty() {
308        var div = document.createElement('div');
309        if ('dataset' in div) {
310            return; // dataset property exists
311        }
312
313        Object.defineProperty(HTMLElement.prototype, 'dataset', {
314            get: function() {
315                if (this._dataset) {
316                    return this._dataset;
317                }
318
319                var dataset = {};
320                for (var j = 0, jj = this.attributes.length; j < jj; j++) {
321                    var attribute = this.attributes[j];
322                    if (attribute.name.substring(0, 5) !== 'data-') {
323                        continue;
324                    }
325                    var key = attribute.name.substring(5).replace(/\-([a-z])/g,
326                        function(all, ch) {
327                            return ch.toUpperCase();
328                        });
329                    dataset[key] = attribute.value;
330                }
331
332                Object.defineProperty(this, '_dataset', {
333                    value: dataset,
334                    writable: false,
335                    enumerable: false
336                });
337                return dataset;
338            },
339            enumerable: true
340        });
341    })();
342
343// HTMLElement classList property
344// Support: IE<10, Android<4.0, iOS<5.0
345    (function checkClassListProperty() {
346        var div = document.createElement('div');
347        if ('classList' in div) {
348            return; // classList property exists
349        }
350
351        function changeList(element, itemName, add, remove) {
352            var s = element.className || '';
353            var list = s.split(/\s+/g);
354            if (list[0] === '') {
355                list.shift();
356            }
357            var index = list.indexOf(itemName);
358            if (index < 0 && add) {
359                list.push(itemName);
360            }
361            if (index >= 0 && remove) {
362                list.splice(index, 1);
363            }
364            element.className = list.join(' ');
365            return (index >= 0);
366        }
367
368        var classListPrototype = {
369            add: function(name) {
370                changeList(this.element, name, true, false);
371            },
372            contains: function(name) {
373                return changeList(this.element, name, false, false);
374            },
375            remove: function(name) {
376                changeList(this.element, name, false, true);
377            },
378            toggle: function(name) {
379                changeList(this.element, name, true, true);
380            }
381        };
382
383        Object.defineProperty(HTMLElement.prototype, 'classList', {
384            get: function() {
385                if (this._classList) {
386                    return this._classList;
387                }
388
389                var classList = Object.create(classListPrototype, {
390                    element: {
391                        value: this,
392                        writable: false,
393                        enumerable: true
394                    }
395                });
396                Object.defineProperty(this, '_classList', {
397                    value: classList,
398                    writable: false,
399                    enumerable: false
400                });
401                return classList;
402            },
403            enumerable: true
404        });
405    })();
406
407// Check console compatibility
408// In older IE versions the console object is not available
409// unless console is open.
410// Support: IE<10
411    (function checkConsoleCompatibility() {
412        if (!('console' in window)) {
413            window.console = {
414                log: function() {},
415                error: function() {},
416                warn: function() {}
417            };
418        } else if (!('bind' in console.log)) {
419            // native functions in IE9 might not have bind
420            console.log = (function(fn) {
421                return function(msg) { return fn(msg); };
422            })(console.log);
423            console.error = (function(fn) {
424                return function(msg) { return fn(msg); };
425            })(console.error);
426            console.warn = (function(fn) {
427                return function(msg) { return fn(msg); };
428            })(console.warn);
429        }
430    })();
431
432// Check onclick compatibility in Opera
433// Support: Opera<15
434    (function checkOnClickCompatibility() {
435        // workaround for reported Opera bug DSK-354448:
436        // onclick fires on disabled buttons with opaque content
437        function ignoreIfTargetDisabled(event) {
438            if (isDisabled(event.target)) {
439                event.stopPropagation();
440            }
441        }
442        function isDisabled(node) {
443            return node.disabled || (node.parentNode && isDisabled(node.parentNode));
444        }
445        if (isOpera) {
446            // use browser detection since we cannot feature-check this bug
447            document.addEventListener('click', ignoreIfTargetDisabled, true);
448        }
449    })();
450
451// Checks if possible to use URL.createObjectURL()
452// Support: IE
453    (function checkOnBlobSupport() {
454        // sometimes IE loosing the data created with createObjectURL(), see #3977
455        if (isIE) {
456            PDFJS.disableCreateObjectURL = true;
457        }
458    })();
459
460// Checks if navigator.language is supported
461    (function checkNavigatorLanguage() {
462        if ('language' in navigator) {
463            return;
464        }
465        PDFJS.locale = navigator.userLanguage || 'en-US';
466    })();
467
468// Support: Safari 6.0+, Android<3.0, Chrome 39/40, iOS
469    (function checkRangeRequests() {
470        // Safari has issues with cached range requests see:
471        // https://github.com/mozilla/pdf.js/issues/3260
472        // Last tested with version 6.0.4.
473
474        // Older versions of Android (pre 3.0) has issues with range requests, see:
475        // https://github.com/mozilla/pdf.js/issues/3381.
476        // Make sure that we only match webkit-based Android browsers,
477        // since Firefox/Fennec works as expected.
478
479        // Range requests are broken in Chrome 39 and 40, https://crbug.com/442318
480        if (isSafari || isAndroidPre3 || isChromeWithRangeBug || isIOS) {
481            PDFJS.disableRange = true;
482            PDFJS.disableStream = true;
483        }
484    })();
485
486// Check if the browser supports manipulation of the history.
487// Support: IE<10, Android<4.2
488    (function checkHistoryManipulation() {
489        // Android 2.x has so buggy pushState support that it was removed in
490        // Android 3.0 and restored as late as in Android 4.2.
491        // Support: Android 2.x
492        if (!history.pushState || isAndroidPre3) {
493            PDFJS.disableHistory = true;
494        }
495    })();
496
497// Support: IE<11, Chrome<21, Android<4.4, Safari<6
498    (function checkSetPresenceInImageData() {
499        // IE < 11 will use window.CanvasPixelArray which lacks set function.
500        if (window.CanvasPixelArray) {
501            if (typeof window.CanvasPixelArray.prototype.set !== 'function') {
502                window.CanvasPixelArray.prototype.set = function(arr) {
503                    for (var i = 0, ii = this.length; i < ii; i++) {
504                        this[i] = arr[i];
505                    }
506                };
507            }
508        } else {
509            // Old Chrome and Android use an inaccessible CanvasPixelArray prototype.
510            // Because we cannot feature detect it, we rely on user agent parsing.
511            var polyfill = false, versionMatch;
512            if (isChrome) {
513                versionMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
514                // Chrome < 21 lacks the set function.
515                polyfill = versionMatch && parseInt(versionMatch[2]) < 21;
516            } else if (isAndroid) {
517                // Android < 4.4 lacks the set function.
518                // Android >
518= 4.4 will contain Chrome in the user agent,
519                // thus pass the Chrome check above and not reach this block.
520                polyfill = isAndroidPre5;
521            } else if (isSafari) {
522                versionMatch = userAgent.
523                    match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//);
524                // Safari < 6 lacks the set function.
525                polyfill = versionMatch && parseInt(versionMatch[1]) < 6;
526            }
527
528            if (polyfill) {
529                var contextPrototype = window.CanvasRenderingContext2D.prototype;
530                var createImageData = contextPrototype.createImageData;
531                contextPrototype.createImageData = function(w, h) {
532                    var imageData = createImageData.call(this, w, h);
533                    imageData.data.set = function(arr) {
534                        for (var i = 0, ii = this.length; i < ii; i++) {
535                            this[i] = arr[i];
536                        }
537                    };
538                    return imageData;
539                };
540                // this closure will be kept referenced, so clear its vars
541                contextPrototype = null;
542            }
543        }
544    })();
545
546// Support: IE<10, Android<4.0, iOS
547    (function checkRequestAnimationFrame() {
548        function fakeRequestAnimationFrame(callback) {
549            window.setTimeout(callback, 20);
550        }
551
552        if (isIOS) {
553            // requestAnimationFrame on iOS is broken, replacing with fake one.
554            window.requestAnimationFrame = fakeRequestAnimationFrame;
555            return;
556        }
557        if ('requestAnimationFrame' in window) {
558            return;
559        }
560        window.requestAnimationFrame =
561            window.mozRequestAnimationFrame ||
562            window.webkitRequestAnimationFrame ||
563            fakeRequestAnimationFrame;
564    })();
565
566// Support: Android, iOS
567    (function checkCanvasSizeLimitation() {
568        if (isIOS || isAndroid) {
569            // 5MP
570            PDFJS.maxCanvasPixels = 5242880;
571        }
572    })();
573
574// Disable fullscreen support for certain problematic configurations.
575// Support: IE11+ (when embedded).
576    (function checkFullscreenSupport() {
577        if (isIE && window.parent !== window) {
578            PDFJS.disableFullscreen = true;
579        }
580    })();
581
582// Provides document.currentScript support
583// Support: IE, Chrome<29.
584    (function checkCurrentScript() {
585        if ('currentScript' in document) {
586            return;
587        }
588        Object.defineProperty(document, 'currentScript', {
589            get: function () {
590                var scripts = document.getElementsByTagName('script');
591                return scripts[scripts.length - 1];
592            },
593            enumerable: true,
594            configurable: true
595        });
596    })();
597
598}).call((typeof window === 'undefined') ? this : window);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.