viewerjs-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/app/assets/javascripts/pdf.worker.js +85404 -39091
- data/app/assets/javascripts/viewerjs/ODFViewerPlugin.js +7 -6
- data/app/assets/javascripts/viewerjs/PDFViewerPlugin.js.erb +1 -1
- data/app/assets/javascripts/viewerjs/PluginLoader.js +0 -1
- data/app/assets/javascripts/viewerjs/compatibility.js +403 -383
- data/app/assets/javascripts/viewerjs/pdf.js +7202 -7216
- data/app/assets/javascripts/viewerjs/pdf_find_bar.js +135 -133
- data/app/assets/javascripts/viewerjs/pdf_find_controller.js +291 -289
- data/app/assets/javascripts/viewerjs/text_layer_builder.js +327 -327
- data/app/assets/javascripts/viewerjs/ui_utils.js +181 -181
- data/app/assets/javascripts/viewerjs/{viewer.js → viewer.js.erb} +19 -19
- data/app/assets/javascripts/viewerjs/webodf.js +11863 -606
- data/app/assets/stylesheets/ODFViewerPlugin.css.scss +1 -1
- data/app/assets/stylesheets/PDFViewerPlugin.css.scss +18 -13
- data/app/assets/stylesheets/example.local.css.scss +6 -12
- data/app/assets/stylesheets/viewer.css.scss +36 -36
- data/lib/viewerjs/rails/version.rb +1 -1
- data/lib/viewerjs/view_helpers.rb +63 -54
- metadata +2 -2
@@ -61,10 +61,10 @@ function ODFViewerPlugin() {
|
|
61
61
|
// that should probably be provided by webodf
|
62
62
|
function nsResolver(prefix) {
|
63
63
|
var ns = {
|
64
|
-
'draw'
|
65
|
-
'presentation'
|
66
|
-
'text'
|
67
|
-
'office'
|
64
|
+
'draw': "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0",
|
65
|
+
'presentation': "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0",
|
66
|
+
'text': "urn:oasis:names:tc:opendocument:xmlns:text:1.0",
|
67
|
+
'office': "urn:oasis:names:tc:opendocument:xmlns:office:1.0"
|
68
68
|
};
|
69
69
|
return ns[prefix] || console.log('prefix [' + prefix + '] unknown.');
|
70
70
|
}
|
@@ -142,7 +142,8 @@ function ODFViewerPlugin() {
|
|
142
142
|
return documentType === 'presentation';
|
143
143
|
};
|
144
144
|
|
145
|
-
this.onLoad = function () {
|
145
|
+
this.onLoad = function () {
|
146
|
+
};
|
146
147
|
|
147
148
|
this.getWidth = function () {
|
148
149
|
return odfElement.clientWidth;
|
@@ -179,7 +180,7 @@ function ODFViewerPlugin() {
|
|
179
180
|
// return a list of tuples (pagename, pagenode)
|
180
181
|
this.getPages = function () {
|
181
182
|
var pageNodes = Array.prototype.slice.call(root.getElementsByTagNameNS(nsResolver('draw'), 'page')),
|
182
|
-
pages
|
183
|
+
pages = [],
|
183
184
|
i,
|
184
185
|
tuple;
|
185
186
|
|
@@ -207,7 +207,7 @@ function PDFViewerPlugin() {
|
|
207
207
|
//TODO: Make it available from asset pipeline
|
208
208
|
// PDFJS.workerSrc = "../viewer_js/javascripts/pdf.worker.js";
|
209
209
|
PDFJS.workerSrc = "<%=javascript_path('pdf.worker.js') %>";
|
210
|
-
console.log(location);
|
210
|
+
// console.log(location);
|
211
211
|
PDFJS.getDocument(location).then(function loadPDF(doc) {
|
212
212
|
pdfDocument = doc;
|
213
213
|
container = viewContainer;
|
@@ -21,471 +21,491 @@
|
|
21
21
|
// Initializing PDFJS global object here, it case if we need to change/disable
|
22
22
|
// some PDF.js features, e.g. range requests
|
23
23
|
if (typeof PDFJS === 'undefined') {
|
24
|
-
|
24
|
+
(typeof window !== 'undefined' ? window : this).PDFJS = {};
|
25
25
|
}
|
26
26
|
|
27
27
|
// Checking if the typed arrays are supported
|
28
28
|
(function checkTypedArrayCompatibility() {
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
if (typeof Uint8Array !== 'undefined') {
|
30
|
+
// some mobile versions do not support subarray (e.g. safari 5 / iOS)
|
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
|
+
// some mobile version might not support Float64Array
|
41
|
+
if (typeof Float64Array === 'undefined')
|
42
|
+
window.Float64Array = Float32Array;
|
43
|
+
|
44
|
+
return;
|
38
45
|
}
|
39
46
|
|
40
|
-
|
41
|
-
|
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
|
-
for (var i = 0, n = array.length; i < n; ++i, ++offset)
|
55
|
-
this[offset] = array[i] & 0xFF;
|
56
|
-
}
|
57
|
-
|
58
|
-
function TypedArray(arg1) {
|
59
|
-
var result;
|
60
|
-
if (typeof arg1 === 'number') {
|
61
|
-
result = [];
|
62
|
-
for (var i = 0; i < arg1; ++i)
|
63
|
-
result[i] = 0;
|
64
|
-
} else if ('slice' in arg1) {
|
65
|
-
result = arg1.slice(0);
|
66
|
-
} else {
|
67
|
-
result = [];
|
68
|
-
for (var i = 0, n = arg1.length; i < n; ++i) {
|
69
|
-
result[i] = arg1[i];
|
70
|
-
}
|
47
|
+
function subarray(start, end) {
|
48
|
+
return new TypedArray(this.slice(start, end));
|
71
49
|
}
|
72
50
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
51
|
+
function setArrayOffset(array, offset) {
|
52
|
+
if (arguments.length < 2)
|
53
|
+
offset = 0;
|
54
|
+
for (var i = 0, n = array.length; i < n; ++i, ++offset)
|
55
|
+
this[offset] = array[i] & 0xFF;
|
56
|
+
}
|
57
|
+
|
58
|
+
function TypedArray(arg1) {
|
59
|
+
var result;
|
60
|
+
if (typeof arg1 === 'number') {
|
61
|
+
result = [];
|
62
|
+
for (var i = 0; i < arg1; ++i)
|
63
|
+
result[i] = 0;
|
64
|
+
} else if ('slice' in arg1) {
|
65
|
+
result = arg1.slice(0);
|
66
|
+
} else {
|
67
|
+
result = [];
|
68
|
+
for (var i = 0, n = arg1.length; i < n; ++i) {
|
69
|
+
result[i] = arg1[i];
|
70
|
+
}
|
71
|
+
}
|
77
72
|
|
78
|
-
|
79
|
-
|
73
|
+
result.subarray = subarray;
|
74
|
+
result.buffer = result;
|
75
|
+
result.byteLength = result.length;
|
76
|
+
result.set = setArrayOffset;
|
80
77
|
|
81
|
-
|
82
|
-
|
78
|
+
if (typeof arg1 === 'object' && arg1.buffer)
|
79
|
+
result.buffer = arg1.buffer;
|
83
80
|
|
84
|
-
|
81
|
+
return result;
|
82
|
+
}
|
85
83
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
window.Uint8Array = TypedArray;
|
85
|
+
|
86
|
+
// we don't need support for set, byteLength for 32-bit array
|
87
|
+
// so we can use the TypedArray as well
|
88
|
+
window.Uint32Array = TypedArray;
|
89
|
+
window.Int32Array = TypedArray;
|
90
|
+
window.Uint16Array = TypedArray;
|
91
|
+
window.Float32Array = TypedArray;
|
92
|
+
window.Float64Array = TypedArray;
|
93
93
|
})();
|
94
94
|
|
95
95
|
// URL = URL || webkitURL
|
96
96
|
(function normalizeURLObject() {
|
97
|
-
|
98
|
-
|
99
|
-
|
97
|
+
if (!window.URL) {
|
98
|
+
window.URL = window.webkitURL;
|
99
|
+
}
|
100
100
|
})();
|
101
101
|
|
102
102
|
// Object.create() ?
|
103
103
|
(function checkObjectCreateCompatibility() {
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
104
|
+
if (typeof Object.create !== 'undefined')
|
105
|
+
return;
|
106
|
+
|
107
|
+
Object.create = function objectCreate(proto) {
|
108
|
+
function Constructor() {
|
109
|
+
}
|
110
|
+
|
111
|
+
Constructor.prototype = proto;
|
112
|
+
return new Constructor();
|
113
|
+
};
|
112
114
|
})();
|
113
115
|
|
114
116
|
// Object.defineProperty() ?
|
115
117
|
(function checkObjectDefinePropertyCompatibility() {
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
Object.defineProperty = function objectDefineProperty(obj, name, def) {
|
134
|
-
delete obj[name];
|
135
|
-
if ('get' in def)
|
136
|
-
obj.__defineGetter__(name, def['get']);
|
137
|
-
if ('set' in def)
|
138
|
-
obj.__defineSetter__(name, def['set']);
|
139
|
-
if ('value' in def) {
|
140
|
-
obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
|
141
|
-
this.__defineGetter__(name, function objectDefinePropertyGetter() {
|
142
|
-
return value;
|
143
|
-
});
|
144
|
-
return value;
|
145
|
-
});
|
146
|
-
obj[name] = def.value;
|
118
|
+
if (typeof Object.defineProperty !== 'undefined') {
|
119
|
+
var definePropertyPossible = true;
|
120
|
+
try {
|
121
|
+
// some browsers (e.g. safari) cannot use defineProperty() on DOM objects
|
122
|
+
// and thus the native version is not sufficient
|
123
|
+
Object.defineProperty(new Image(), 'id', { value: 'test' });
|
124
|
+
// ... another test for android gb browser for non-DOM objects
|
125
|
+
var Test = function Test() {
|
126
|
+
};
|
127
|
+
Test.prototype = { get id() {
|
128
|
+
} };
|
129
|
+
Object.defineProperty(new Test(), 'id',
|
130
|
+
{ value: '', configurable: true, enumerable: true, writable: false });
|
131
|
+
} catch (e) {
|
132
|
+
definePropertyPossible = false;
|
133
|
+
}
|
134
|
+
if (definePropertyPossible) return;
|
147
135
|
}
|
148
|
-
|
136
|
+
|
137
|
+
Object.defineProperty = function objectDefineProperty(obj, name, def) {
|
138
|
+
delete obj[name];
|
139
|
+
if ('get' in def)
|
140
|
+
obj.__defineGetter__(name, def['get']);
|
141
|
+
if ('set' in def)
|
142
|
+
obj.__defineSetter__(name, def['set']);
|
143
|
+
if ('value' in def) {
|
144
|
+
obj.__defineSetter__(name, function objectDefinePropertySetter(value) {
|
145
|
+
this.__defineGetter__(name, function objectDefinePropertyGetter() {
|
146
|
+
return value;
|
147
|
+
});
|
148
|
+
return value;
|
149
|
+
});
|
150
|
+
obj[name] = def.value;
|
151
|
+
}
|
152
|
+
};
|
149
153
|
})();
|
150
154
|
|
151
155
|
// Object.keys() ?
|
152
156
|
(function checkObjectKeysCompatibility() {
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
157
|
+
if (typeof Object.keys !== 'undefined')
|
158
|
+
return;
|
159
|
+
|
160
|
+
Object.keys = function objectKeys(obj) {
|
161
|
+
var result = [];
|
162
|
+
for (var i in obj) {
|
163
|
+
if (obj.hasOwnProperty(i))
|
164
|
+
result.push(i);
|
165
|
+
}
|
166
|
+
return result;
|
167
|
+
};
|
164
168
|
})();
|
165
169
|
|
166
170
|
// No readAsArrayBuffer ?
|
167
171
|
(function checkFileReaderReadAsArrayBuffer() {
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
172
|
+
if (typeof FileReader === 'undefined')
|
173
|
+
return; // FileReader is not implemented
|
174
|
+
var frPrototype = FileReader.prototype;
|
175
|
+
// Older versions of Firefox might not have readAsArrayBuffer
|
176
|
+
if ('readAsArrayBuffer' in frPrototype)
|
177
|
+
return; // readAsArrayBuffer is implemented
|
178
|
+
Object.defineProperty(frPrototype, 'readAsArrayBuffer', {
|
179
|
+
value: function fileReaderReadAsArrayBuffer(blob) {
|
180
|
+
var fileReader = new FileReader();
|
181
|
+
var originalReader = this;
|
182
|
+
fileReader.onload = function fileReaderOnload(evt) {
|
183
|
+
var data = evt.target.result;
|
184
|
+
var buffer = new ArrayBuffer(data.length);
|
185
|
+
var uint8Array = new Uint8Array(buffer);
|
186
|
+
|
187
|
+
for (var i = 0, ii = data.length; i < ii; i++)
|
188
|
+
uint8Array[i] = data.charCodeAt(i);
|
189
|
+
|
190
|
+
Object.defineProperty(originalReader, 'result', {
|
191
|
+
value: buffer,
|
192
|
+
enumerable: true,
|
193
|
+
writable: false,
|
194
|
+
configurable: true
|
195
|
+
});
|
196
|
+
|
197
|
+
var event = document.createEvent('HTMLEvents');
|
198
|
+
event.initEvent('load', false, false);
|
199
|
+
originalReader.dispatchEvent(event);
|
200
|
+
};
|
201
|
+
fileReader.readAsBinaryString(blob);
|
202
|
+
}
|
203
|
+
});
|
200
204
|
})();
|
201
205
|
|
202
206
|
// No XMLHttpRequest.response ?
|
203
207
|
(function checkXMLHttpRequestResponseCompatibility() {
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
208
|
+
var xhrPrototype = XMLHttpRequest.prototype;
|
209
|
+
if (!('overrideMimeType' in xhrPrototype)) {
|
210
|
+
// IE10 might have response, but not overrideMimeType
|
211
|
+
Object.defineProperty(xhrPrototype, 'overrideMimeType', {
|
212
|
+
value: function xmlHttpRequestOverrideMimeType(mimeType) {
|
213
|
+
}
|
214
|
+
});
|
215
|
+
}
|
216
|
+
if ('response' in xhrPrototype ||
|
217
|
+
'mozResponseArrayBuffer' in xhrPrototype ||
|
218
|
+
'mozResponse' in xhrPrototype ||
|
219
|
+
'responseArrayBuffer' in xhrPrototype)
|
220
|
+
return;
|
221
|
+
// IE9 ?
|
222
|
+
if (typeof VBArray !== 'undefined') {
|
223
|
+
Object.defineProperty(xhrPrototype, 'response', {
|
224
|
+
get: function xmlHttpRequestResponseGet() {
|
225
|
+
return new Uint8Array(new VBArray(this.responseBody).toArray());
|
226
|
+
}
|
227
|
+
});
|
228
|
+
return;
|
229
|
+
}
|
230
|
+
|
231
|
+
// other browsers
|
232
|
+
function responseTypeSetter() {
|
233
|
+
// will be only called to set "arraybuffer"
|
234
|
+
this.overrideMimeType('text/plain; charset=x-user-defined');
|
235
|
+
}
|
236
|
+
|
237
|
+
if (typeof xhrPrototype.overrideMimeType === 'function') {
|
238
|
+
Object.defineProperty(xhrPrototype, 'responseType',
|
239
|
+
{ set: responseTypeSetter });
|
240
|
+
}
|
241
|
+
function responseGetter() {
|
242
|
+
var text = this.responseText;
|
243
|
+
var i, n = text.length;
|
244
|
+
var result = new Uint8Array(n);
|
245
|
+
for (i = 0; i < n; ++i)
|
246
|
+
result[i] = text.charCodeAt(i) & 0xFF;
|
247
|
+
return result;
|
248
|
+
}
|
249
|
+
|
250
|
+
Object.defineProperty(xhrPrototype, 'response', { get: responseGetter });
|
244
251
|
})();
|
245
252
|
|
246
253
|
// window.btoa (base64 encode function) ?
|
247
254
|
(function checkWindowBtoaCompatibility() {
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
255
|
+
if ('btoa' in window)
|
256
|
+
return;
|
257
|
+
|
258
|
+
var digits =
|
259
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
260
|
+
|
261
|
+
window.btoa = function windowBtoa(chars) {
|
262
|
+
var buffer = '';
|
263
|
+
var i, n;
|
264
|
+
for (i = 0, n = chars.length; i < n; i += 3) {
|
265
|
+
var b1 = chars.charCodeAt(i) & 0xFF;
|
266
|
+
var b2 = chars.charCodeAt(i + 1) & 0xFF;
|
267
|
+
var b3 = chars.charCodeAt(i + 2) & 0xFF;
|
268
|
+
var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
|
269
|
+
var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
|
270
|
+
var d4 = i + 2 < n ? (b3 & 0x3F) : 64;
|
271
|
+
buffer += (digits.charAt(d1) + digits.charAt(d2) +
|
272
|
+
digits.charAt(d3) + digits.charAt(d4));
|
273
|
+
}
|
274
|
+
return buffer;
|
275
|
+
};
|
269
276
|
})();
|
270
277
|
|
271
278
|
// window.atob (base64 encode function) ?
|
272
279
|
(function checkWindowAtobCompatibility() {
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
280
|
+
if ('atob' in window)
|
281
|
+
return;
|
282
|
+
|
283
|
+
// https://github.com/davidchambers/Base64.js
|
284
|
+
var digits =
|
285
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
286
|
+
window.atob = function (input) {
|
287
|
+
input = input.replace(/=+$/, '');
|
288
|
+
if (input.length % 4 == 1) throw new Error('bad atob input');
|
289
|
+
for (
|
290
|
+
// initialize result and counters
|
291
|
+
var bc = 0, bs, buffer, idx = 0, output = '';
|
292
|
+
// get next character
|
293
|
+
buffer = input.charAt(idx++);
|
294
|
+
// character found in table?
|
295
|
+
// initialize bit storage and add its ascii value
|
296
|
+
~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
|
297
|
+
// and if not first of each 4 characters,
|
298
|
+
// convert the first 8 bits to one ascii character
|
299
|
+
bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
|
300
|
+
) {
|
301
|
+
// try to find character in table (0-63, not found => -1)
|
302
|
+
buffer = digits.indexOf(buffer);
|
303
|
+
}
|
304
|
+
return output;
|
305
|
+
};
|
299
306
|
})();
|
300
307
|
|
301
308
|
// Function.prototype.bind ?
|
302
309
|
(function checkFunctionPrototypeBindCompatibility() {
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
310
|
+
if (typeof Function.prototype.bind !== 'undefined')
|
311
|
+
return;
|
312
|
+
|
313
|
+
Function.prototype.bind = function functionPrototypeBind(obj) {
|
314
|
+
var fn = this, headArgs = Array.prototype.slice.call(arguments, 1);
|
315
|
+
var bound = function functionPrototypeBindBound() {
|
316
|
+
var args = Array.prototype.concat.apply(headArgs, arguments);
|
317
|
+
return fn.apply(obj, args);
|
318
|
+
};
|
319
|
+
return bound;
|
311
320
|
};
|
312
|
-
return bound;
|
313
|
-
};
|
314
321
|
})();
|
315
322
|
|
316
323
|
// HTMLElement dataset property
|
317
324
|
(function checkDatasetProperty() {
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
325
|
+
var div = document.createElement('div');
|
326
|
+
if ('dataset' in div)
|
327
|
+
return; // dataset property exists
|
328
|
+
|
329
|
+
Object.defineProperty(HTMLElement.prototype, 'dataset', {
|
330
|
+
get: function () {
|
331
|
+
if (this._dataset)
|
332
|
+
return this._dataset;
|
333
|
+
|
334
|
+
var dataset = {};
|
335
|
+
for (var j = 0, jj = this.attributes.length; j < jj; j++) {
|
336
|
+
var attribute = this.attributes[j];
|
337
|
+
if (attribute.name.substring(0, 5) != 'data-')
|
338
|
+
continue;
|
339
|
+
var key = attribute.name.substring(5).replace(/\-([a-z])/g,
|
340
|
+
function (all, ch) {
|
341
|
+
return ch.toUpperCase();
|
342
|
+
});
|
343
|
+
dataset[key] = attribute.value;
|
344
|
+
}
|
345
|
+
|
346
|
+
Object.defineProperty(this, '_dataset', {
|
347
|
+
value: dataset,
|
348
|
+
writable: false,
|
349
|
+
enumerable: false
|
350
|
+
});
|
351
|
+
return dataset;
|
352
|
+
},
|
353
|
+
enumerable: true
|
354
|
+
});
|
346
355
|
})();
|
347
356
|
|
348
357
|
// HTMLElement classList property
|
349
358
|
(function checkClassListProperty() {
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
}
|
366
|
-
|
367
|
-
var classListPrototype = {
|
368
|
-
add: function(name) {
|
369
|
-
changeList(this.element, name, true, false);
|
370
|
-
},
|
371
|
-
contains: function(name) {
|
372
|
-
return changeList(this.element, name, false, false);
|
373
|
-
},
|
374
|
-
remove: function(name) {
|
375
|
-
changeList(this.element, name, false, true);
|
376
|
-
},
|
377
|
-
toggle: function(name) {
|
378
|
-
changeList(this.element, name, true, true);
|
359
|
+
var div = document.createElement('div');
|
360
|
+
if ('classList' in div)
|
361
|
+
return; // classList property exists
|
362
|
+
|
363
|
+
function changeList(element, itemName, add, remove) {
|
364
|
+
var s = element.className || '';
|
365
|
+
var list = s.split(/\s+/g);
|
366
|
+
if (list[0] === '') list.shift();
|
367
|
+
var index = list.indexOf(itemName);
|
368
|
+
if (index < 0 && add)
|
369
|
+
list.push(itemName);
|
370
|
+
if (index >= 0 && remove)
|
371
|
+
list.splice(index, 1);
|
372
|
+
element.className = list.join(' ');
|
373
|
+
return (index >= 0);
|
379
374
|
}
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
375
|
+
|
376
|
+
var classListPrototype = {
|
377
|
+
add: function (name) {
|
378
|
+
changeList(this.element, name, true, false);
|
379
|
+
},
|
380
|
+
contains: function (name) {
|
381
|
+
return changeList(this.element, name, false, false);
|
382
|
+
},
|
383
|
+
remove: function (name) {
|
384
|
+
changeList(this.element, name, false, true);
|
385
|
+
},
|
386
|
+
toggle: function (name) {
|
387
|
+
changeList(this.element, name, true, true);
|
392
388
|
}
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
389
|
+
};
|
390
|
+
|
391
|
+
Object.defineProperty(HTMLElement.prototype, 'classList', {
|
392
|
+
get: function () {
|
393
|
+
if (this._classList)
|
394
|
+
return this._classList;
|
395
|
+
|
396
|
+
var classList = Object.create(classListPrototype, {
|
397
|
+
element: {
|
398
|
+
value: this,
|
399
|
+
writable: false,
|
400
|
+
enumerable: true
|
401
|
+
}
|
402
|
+
});
|
403
|
+
Object.defineProperty(this, '_classList', {
|
404
|
+
value: classList,
|
405
|
+
writable: false,
|
406
|
+
enumerable: false
|
407
|
+
});
|
408
|
+
return classList;
|
409
|
+
},
|
410
|
+
enumerable: true
|
411
|
+
});
|
403
412
|
})();
|
404
413
|
|
405
414
|
// Check console compatibility
|
406
415
|
(function checkConsoleCompatibility() {
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
416
|
+
if (!('console' in window)) {
|
417
|
+
window.console = {
|
418
|
+
log: function () {
|
419
|
+
},
|
420
|
+
error: function () {
|
421
|
+
},
|
422
|
+
warn: function () {
|
423
|
+
}
|
424
|
+
};
|
425
|
+
} else if (!('bind' in console.log)) {
|
426
|
+
// native functions in IE9 might not have bind
|
427
|
+
console.log = (function (fn) {
|
428
|
+
return function (msg) {
|
429
|
+
return fn(msg);
|
430
|
+
};
|
431
|
+
})(console.log);
|
432
|
+
console.error = (function (fn) {
|
433
|
+
return function (msg) {
|
434
|
+
return fn(msg);
|
435
|
+
};
|
436
|
+
})(console.error);
|
437
|
+
console.warn = (function (fn) {
|
438
|
+
return function (msg) {
|
439
|
+
return fn(msg);
|
440
|
+
};
|
441
|
+
})(console.warn);
|
442
|
+
}
|
425
443
|
})();
|
426
444
|
|
427
445
|
// Check onclick compatibility in Opera
|
428
446
|
(function checkOnClickCompatibility() {
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
447
|
+
// workaround for reported Opera bug DSK-354448:
|
448
|
+
// onclick fires on disabled buttons with opaque content
|
449
|
+
function ignoreIfTargetDisabled(event) {
|
450
|
+
if (isDisabled(event.target)) {
|
451
|
+
event.stopPropagation();
|
452
|
+
}
|
453
|
+
}
|
454
|
+
|
455
|
+
function isDisabled(node) {
|
456
|
+
return node.disabled || (node.parentNode && isDisabled(node.parentNode));
|
457
|
+
}
|
458
|
+
|
459
|
+
if (navigator.userAgent.indexOf('Opera') != -1) {
|
460
|
+
// use browser detection since we cannot feature-check this bug
|
461
|
+
document.addEventListener('click', ignoreIfTargetDisabled, true);
|
434
462
|
}
|
435
|
-
}
|
436
|
-
function isDisabled(node) {
|
437
|
-
return node.disabled || (node.parentNode && isDisabled(node.parentNode));
|
438
|
-
}
|
439
|
-
if (navigator.userAgent.indexOf('Opera') != -1) {
|
440
|
-
// use browser detection since we cannot feature-check this bug
|
441
|
-
document.addEventListener('click', ignoreIfTargetDisabled, true);
|
442
|
-
}
|
443
463
|
})();
|
444
464
|
|
445
465
|
// Checks if possible to use URL.createObjectURL()
|
446
466
|
(function checkOnBlobSupport() {
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
467
|
+
// sometimes IE loosing the data created with createObjectURL(), see #3977
|
468
|
+
if (navigator.userAgent.indexOf('Trident') >= 0) {
|
469
|
+
PDFJS.disableCreateObjectURL = true;
|
470
|
+
}
|
451
471
|
})();
|
452
472
|
|
453
473
|
// Checks if navigator.language is supported
|
454
474
|
(function checkNavigatorLanguage() {
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
475
|
+
if ('language' in navigator)
|
476
|
+
return;
|
477
|
+
Object.defineProperty(navigator, 'language', {
|
478
|
+
get: function navigatorLanguage() {
|
479
|
+
var language = navigator.userLanguage || 'en-US';
|
480
|
+
return language.substring(0, 2).toLowerCase() +
|
481
|
+
language.substring(2).toUpperCase();
|
482
|
+
},
|
483
|
+
enumerable: true
|
484
|
+
});
|
465
485
|
})();
|
466
486
|
|
467
487
|
(function checkRangeRequests() {
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
488
|
+
// Safari has issues with cached range requests see:
|
489
|
+
// https://github.com/mozilla/pdf.js/issues/3260
|
490
|
+
// Last tested with version 6.0.4.
|
491
|
+
var isSafari = Object.prototype.toString.call(
|
492
|
+
window.HTMLElement).indexOf('Constructor') > 0;
|
493
|
+
|
494
|
+
// Older versions of Android (pre 3.0) has issues with range requests, see:
|
495
|
+
// https://github.com/mozilla/pdf.js/issues/3381.
|
496
|
+
// Make sure that we only match webkit-based Android browsers,
|
497
|
+
// since Firefox/Fennec works as expected.
|
498
|
+
var regex = /Android\s[0-2][^\d]/;
|
499
|
+
var isOldAndroid = regex.test(navigator.userAgent);
|
500
|
+
|
501
|
+
if (isSafari || isOldAndroid) {
|
502
|
+
PDFJS.disableRange = true;
|
503
|
+
}
|
484
504
|
})();
|
485
505
|
|
486
506
|
// Check if the browser supports manipulation of the history.
|
487
507
|
(function checkHistoryManipulation() {
|
488
|
-
|
489
|
-
|
490
|
-
|
508
|
+
if (!window.history.pushState) {
|
509
|
+
PDFJS.disableHistory = true;
|
510
|
+
}
|
491
511
|
})();
|