PageSourceSearch

https://fecaza.com/wp-content/plugins/wp-file-download/app/site/as…/js/pdf-embed/compatibility.js?ver=6.3.11

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