app/assets/javascripts/pdfjs_viewer/pdfjs/compatibility.js in pdfjs_viewer-rails-0.0.9 vs app/assets/javascripts/pdfjs_viewer/pdfjs/compatibility.js in pdfjs_viewer-rails-0.1.0
- old
+ new
@@ -10,14 +10,30 @@
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+/* eslint strict: ["error", "function"] */
+/* eslint-disable no-extend-native */
/* globals VBArray, PDFJS */
-'use strict';
+(function compatibilityWrapper() {
+ 'use strict';
+var userAgent = navigator.userAgent;
+
+var isAndroid = /Android/.test(userAgent);
+var isAndroidPre3 = /Android\s[0-2][^\d]/.test(userAgent);
+var isAndroidPre5 = /Android\s[0-4][^\d]/.test(userAgent);
+var isChrome = userAgent.indexOf('Chrom') >= 0;
+var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(userAgent);
+var isIE = userAgent.indexOf('Trident') >= 0;
+var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent);
+var isOpera = userAgent.indexOf('Opera') >= 0;
+var isSafari = /Safari\//.test(userAgent) &&
+ !/(Chrome\/|Android\s)/.test(userAgent);
+
// Initializing PDFJS global object here, it case if we need to change/disable
// some PDF.js features, e.g. range requests
if (typeof PDFJS === 'undefined') {
(typeof window !== 'undefined' ? window : this).PDFJS = {};
}
@@ -26,16 +42,16 @@
// Support: iOS<6.0 (subarray), IE<10, Android<4.0
(function checkTypedArrayCompatibility() {
if (typeof Uint8Array !== 'undefined') {
// Support: iOS<6.0
if (typeof Uint8Array.prototype.subarray === 'undefined') {
- Uint8Array.prototype.subarray = function subarray(start, end) {
- return new Uint8Array(this.slice(start, end));
- };
- Float32Array.prototype.subarray = function subarray(start, end) {
- return new Float32Array(this.slice(start, end));
- };
+ Uint8Array.prototype.subarray = function subarray(start, end) {
+ return new Uint8Array(this.slice(start, end));
+ };
+ Float32Array.prototype.subarray = function subarray(start, end) {
+ return new Float32Array(this.slice(start, end));
+ };
}
// Support: Android<4.1
if (typeof Float64Array === 'undefined') {
window.Float64Array = Float32Array;
@@ -184,13 +200,12 @@
if (typeof VBArray !== 'undefined') {
Object.defineProperty(xhrPrototype, 'response', {
get: function xmlHttpRequestResponseGet() {
if (this.responseType === 'arraybuffer') {
return new Uint8Array(new VBArray(this.responseBody).toArray());
- } else {
- return this.responseText;
}
+ return this.responseText;
}
});
return;
}
@@ -254,11 +269,11 @@
}
for (
// initialize result and counters
var bc = 0, bs, buffer, idx = 0, output = '';
// get next character
- buffer = input.charAt(idx++);
+ (buffer = input.charAt(idx++));
// character found in table?
// initialize bit storage and add its ascii value
~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
// and if not first of each 4 characters,
// convert the first 8 bits to one ascii character
@@ -426,21 +441,21 @@
}
}
function isDisabled(node) {
return node.disabled || (node.parentNode && isDisabled(node.parentNode));
}
- if (navigator.userAgent.indexOf('Opera') !== -1) {
+ if (isOpera) {
// use browser detection since we cannot feature-check this bug
document.addEventListener('click', ignoreIfTargetDisabled, true);
}
})();
// Checks if possible to use URL.createObjectURL()
// Support: IE
(function checkOnBlobSupport() {
// sometimes IE loosing the data created with createObjectURL(), see #3977
- if (navigator.userAgent.indexOf('Trident') >= 0) {
+ if (isIE) {
PDFJS.disableCreateObjectURL = true;
}
})();
// Checks if navigator.language is supported
@@ -449,30 +464,23 @@
return;
}
PDFJS.locale = navigator.userLanguage || 'en-US';
})();
+// Support: Safari 6.0+, Android<3.0, Chrome 39/40, iOS
(function checkRangeRequests() {
// Safari has issues with cached range requests see:
// https://github.com/mozilla/pdf.js/issues/3260
// Last tested with version 6.0.4.
- // Support: Safari 6.0+
- var isSafari = Object.prototype.toString.call(
- window.HTMLElement).indexOf('Constructor') > 0;
// Older versions of Android (pre 3.0) has issues with range requests, see:
// https://github.com/mozilla/pdf.js/issues/3381.
// Make sure that we only match webkit-based Android browsers,
// since Firefox/Fennec works as expected.
- // Support: Android<3.0
- var regex = /Android\s[0-2][^\d]/;
- var isOldAndroid = regex.test(navigator.userAgent);
// Range requests are broken in Chrome 39 and 40, https://crbug.com/442318
- var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(navigator.userAgent);
-
- if (isSafari || isOldAndroid || isChromeWithRangeBug) {
+ if (isSafari || isAndroidPre3 || isChromeWithRangeBug || isIOS) {
PDFJS.disableRange = true;
PDFJS.disableStream = true;
}
})();
@@ -480,11 +488,11 @@
// Support: IE<10, Android<4.2
(function checkHistoryManipulation() {
// Android 2.x has so buggy pushState support that it was removed in
// Android 3.0 and restored as late as in Android 4.2.
// Support: Android 2.x
- if (!history.pushState || navigator.userAgent.indexOf('Android 2.') >= 0) {
+ if (!history.pushState || isAndroidPre3) {
PDFJS.disableHistory = true;
}
})();
// Support: IE<11, Chrome<21, Android<4.4, Safari<6
@@ -500,21 +508,21 @@
}
} else {
// Old Chrome and Android use an inaccessible CanvasPixelArray prototype.
// Because we cannot feature detect it, we rely on user agent parsing.
var polyfill = false, versionMatch;
- if (navigator.userAgent.indexOf('Chrom') >= 0) {
- versionMatch = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
+ if (isChrome) {
+ versionMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
// Chrome < 21 lacks the set function.
polyfill = versionMatch && parseInt(versionMatch[2]) < 21;
- } else if (navigator.userAgent.indexOf('Android') >= 0) {
+ } else if (isAndroid) {
// Android < 4.4 lacks the set function.
// Android >= 4.4 will contain Chrome in the user agent,
// thus pass the Chrome check above and not reach this block.
- polyfill = /Android\s[0-4][^\d]/g.test(navigator.userAgent);
- } else if (navigator.userAgent.indexOf('Safari') >= 0) {
- versionMatch = navigator.userAgent.
+ polyfill = isAndroidPre5;
+ } else if (isSafari) {
+ versionMatch = userAgent.
match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//);
// Safari < 6 lacks the set function.
polyfill = versionMatch && parseInt(versionMatch[1]) < 6;
}
@@ -540,11 +548,10 @@
(function checkRequestAnimationFrame() {
function fakeRequestAnimationFrame(callback) {
window.setTimeout(callback, 20);
}
- var isIOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
if (isIOS) {
// requestAnimationFrame on iOS is broken, replacing with fake one.
window.requestAnimationFrame = fakeRequestAnimationFrame;
return;
}
@@ -555,25 +562,22 @@
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
fakeRequestAnimationFrame;
})();
+// Support: Android, iOS
(function checkCanvasSizeLimitation() {
- var isIOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
- var isAndroid = /Android/g.test(navigator.userAgent);
if (isIOS || isAndroid) {
// 5MP
PDFJS.maxCanvasPixels = 5242880;
}
})();
// Disable fullscreen support for certain problematic configurations.
// Support: IE11+ (when embedded).
(function checkFullscreenSupport() {
- var isEmbeddedIE = (navigator.userAgent.indexOf('Trident') >= 0 &&
- window.parent !== window);
- if (isEmbeddedIE) {
+ if (isIE && window.parent !== window) {
PDFJS.disableFullscreen = true;
}
})();
// Provides document.currentScript support
@@ -589,5 +593,47 @@
},
enumerable: true,
configurable: true
});
})();
+
+// Provides `input.type = 'type'` runtime failure protection.
+// Support: IE9,10.
+(function checkInputTypeNumberAssign() {
+ var el = document.createElement('input');
+ try {
+ el.type = 'number';
+ } catch (ex) {
+ var inputProto = el.constructor.prototype;
+ var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type');
+ Object.defineProperty(inputProto, 'type', {
+ get: function () { return typeProperty.get.call(this); },
+ set: function (value) {
+ typeProperty.set.call(this, value === 'number' ? 'text' : value);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ }
+})();
+
+// Provides correct document.readyState value for legacy browsers.
+// Support: IE9,10.
+(function checkDocumentReadyState() {
+ if (!document.attachEvent) {
+ return;
+ }
+ var documentProto = document.constructor.prototype;
+ var readyStateProto = Object.getOwnPropertyDescriptor(documentProto,
+ 'readyState');
+ Object.defineProperty(documentProto, 'readyState', {
+ get: function () {
+ var value = readyStateProto.get.call(this);
+ return value === 'interactive' ? 'loading' : value;
+ },
+ set: function (value) { readyStateProto.set.call(this, value); },
+ enumerable: true,
+ configurable: true
+ });
+})();
+
+}).call((typeof window === 'undefined') ? this : window);