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