viewerjs-rails 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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' : "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"
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;
@@ -41,7 +41,6 @@
41
41
  var viewer;
42
42
  function loadDocument(documentUrl) {
43
43
  window.onload = function () {
44
- console.log("Am i here!!!")
45
44
  viewer = new Viewer(new PDFViewerPlugin());
46
45
  };
47
46
  }
@@ -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
- (typeof window !== 'undefined' ? window : this).PDFJS = {};
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
- 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
- };
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
- // some mobile version might not support Float64Array
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
- 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
- result.subarray = subarray;
74
- result.buffer = result;
75
- result.byteLength = result.length;
76
- result.set = setArrayOffset;
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
- if (typeof arg1 === 'object' && arg1.buffer)
79
- result.buffer = arg1.buffer;
73
+ result.subarray = subarray;
74
+ result.buffer = result;
75
+ result.byteLength = result.length;
76
+ result.set = setArrayOffset;
80
77
 
81
- return result;
82
- }
78
+ if (typeof arg1 === 'object' && arg1.buffer)
79
+ result.buffer = arg1.buffer;
83
80
 
84
- window.Uint8Array = TypedArray;
81
+ return result;
82
+ }
85
83
 
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;
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
- if (!window.URL) {
98
- window.URL = window.webkitURL;
99
- }
97
+ if (!window.URL) {
98
+ window.URL = window.webkitURL;
99
+ }
100
100
  })();
101
101
 
102
102
  // Object.create() ?
103
103
  (function checkObjectCreateCompatibility() {
104
- if (typeof Object.create !== 'undefined')
105
- return;
106
-
107
- Object.create = function objectCreate(proto) {
108
- function Constructor() {}
109
- Constructor.prototype = proto;
110
- return new Constructor();
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
- if (typeof Object.defineProperty !== 'undefined') {
117
- var definePropertyPossible = true;
118
- try {
119
- // some browsers (e.g. safari) cannot use defineProperty() on DOM objects
120
- // and thus the native version is not sufficient
121
- Object.defineProperty(new Image(), 'id', { value: 'test' });
122
- // ... another test for android gb browser for non-DOM objects
123
- var Test = function Test() {};
124
- Test.prototype = { get id() { } };
125
- Object.defineProperty(new Test(), 'id',
126
- { value: '', configurable: true, enumerable: true, writable: false });
127
- } catch (e) {
128
- definePropertyPossible = false;
129
- }
130
- if (definePropertyPossible) return;
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
- if (typeof Object.keys !== 'undefined')
154
- return;
155
-
156
- Object.keys = function objectKeys(obj) {
157
- var result = [];
158
- for (var i in obj) {
159
- if (obj.hasOwnProperty(i))
160
- result.push(i);
161
- }
162
- return result;
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
- if (typeof FileReader === 'undefined')
169
- return; // FileReader is not implemented
170
- var frPrototype = FileReader.prototype;
171
- // Older versions of Firefox might not have readAsArrayBuffer
172
- if ('readAsArrayBuffer' in frPrototype)
173
- return; // readAsArrayBuffer is implemented
174
- Object.defineProperty(frPrototype, 'readAsArrayBuffer', {
175
- value: function fileReaderReadAsArrayBuffer(blob) {
176
- var fileReader = new FileReader();
177
- var originalReader = this;
178
- fileReader.onload = function fileReaderOnload(evt) {
179
- var data = evt.target.result;
180
- var buffer = new ArrayBuffer(data.length);
181
- var uint8Array = new Uint8Array(buffer);
182
-
183
- for (var i = 0, ii = data.length; i < ii; i++)
184
- uint8Array[i] = data.charCodeAt(i);
185
-
186
- Object.defineProperty(originalReader, 'result', {
187
- value: buffer,
188
- enumerable: true,
189
- writable: false,
190
- configurable: true
191
- });
192
-
193
- var event = document.createEvent('HTMLEvents');
194
- event.initEvent('load', false, false);
195
- originalReader.dispatchEvent(event);
196
- };
197
- fileReader.readAsBinaryString(blob);
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
- var xhrPrototype = XMLHttpRequest.prototype;
205
- if (!('overrideMimeType' in xhrPrototype)) {
206
- // IE10 might have response, but not overrideMimeType
207
- Object.defineProperty(xhrPrototype, 'overrideMimeType', {
208
- value: function xmlHttpRequestOverrideMimeType(mimeType) {}
209
- });
210
- }
211
- if ('response' in xhrPrototype ||
212
- 'mozResponseArrayBuffer' in xhrPrototype ||
213
- 'mozResponse' in xhrPrototype ||
214
- 'responseArrayBuffer' in xhrPrototype)
215
- return;
216
- // IE9 ?
217
- if (typeof VBArray !== 'undefined') {
218
- Object.defineProperty(xhrPrototype, 'response', {
219
- get: function xmlHttpRequestResponseGet() {
220
- return new Uint8Array(new VBArray(this.responseBody).toArray());
221
- }
222
- });
223
- return;
224
- }
225
-
226
- // other browsers
227
- function responseTypeSetter() {
228
- // will be only called to set "arraybuffer"
229
- this.overrideMimeType('text/plain; charset=x-user-defined');
230
- }
231
- if (typeof xhrPrototype.overrideMimeType === 'function') {
232
- Object.defineProperty(xhrPrototype, 'responseType',
233
- { set: responseTypeSetter });
234
- }
235
- function responseGetter() {
236
- var text = this.responseText;
237
- var i, n = text.length;
238
- var result = new Uint8Array(n);
239
- for (i = 0; i < n; ++i)
240
- result[i] = text.charCodeAt(i) & 0xFF;
241
- return result;
242
- }
243
- Object.defineProperty(xhrPrototype, 'response', { get: responseGetter });
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
- if ('btoa' in window)
249
- return;
250
-
251
- var digits =
252
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
253
-
254
- window.btoa = function windowBtoa(chars) {
255
- var buffer = '';
256
- var i, n;
257
- for (i = 0, n = chars.length; i < n; i += 3) {
258
- var b1 = chars.charCodeAt(i) & 0xFF;
259
- var b2 = chars.charCodeAt(i + 1) & 0xFF;
260
- var b3 = chars.charCodeAt(i + 2) & 0xFF;
261
- var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
262
- var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
263
- var d4 = i + 2 < n ? (b3 & 0x3F) : 64;
264
- buffer += (digits.charAt(d1) + digits.charAt(d2) +
265
- digits.charAt(d3) + digits.charAt(d4));
266
- }
267
- return buffer;
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
- if ('atob' in window)
274
- return;
275
-
276
- // https://github.com/davidchambers/Base64.js
277
- var digits =
278
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
279
- window.atob = function (input) {
280
- input = input.replace(/=+$/, '');
281
- if (input.length % 4 == 1) throw new Error('bad atob input');
282
- for (
283
- // initialize result and counters
284
- var bc = 0, bs, buffer, idx = 0, output = '';
285
- // get next character
286
- buffer = input.charAt(idx++);
287
- // character found in table?
288
- // initialize bit storage and add its ascii value
289
- ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
290
- // and if not first of each 4 characters,
291
- // convert the first 8 bits to one ascii character
292
- bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
293
- ) {
294
- // try to find character in table (0-63, not found => -1)
295
- buffer = digits.indexOf(buffer);
296
- }
297
- return output;
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
- if (typeof Function.prototype.bind !== 'undefined')
304
- return;
305
-
306
- Function.prototype.bind = function functionPrototypeBind(obj) {
307
- var fn = this, headArgs = Array.prototype.slice.call(arguments, 1);
308
- var bound = function functionPrototypeBindBound() {
309
- var args = Array.prototype.concat.apply(headArgs, arguments);
310
- return fn.apply(obj, args);
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
- var div = document.createElement('div');
319
- if ('dataset' in div)
320
- return; // dataset property exists
321
-
322
- Object.defineProperty(HTMLElement.prototype, 'dataset', {
323
- get: function() {
324
- if (this._dataset)
325
- return this._dataset;
326
-
327
- var dataset = {};
328
- for (var j = 0, jj = this.attributes.length; j < jj; j++) {
329
- var attribute = this.attributes[j];
330
- if (attribute.name.substring(0, 5) != 'data-')
331
- continue;
332
- var key = attribute.name.substring(5).replace(/\-([a-z])/g,
333
- function(all, ch) { return ch.toUpperCase(); });
334
- dataset[key] = attribute.value;
335
- }
336
-
337
- Object.defineProperty(this, '_dataset', {
338
- value: dataset,
339
- writable: false,
340
- enumerable: false
341
- });
342
- return dataset;
343
- },
344
- enumerable: true
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
- var div = document.createElement('div');
351
- if ('classList' in div)
352
- return; // classList property exists
353
-
354
- function changeList(element, itemName, add, remove) {
355
- var s = element.className || '';
356
- var list = s.split(/\s+/g);
357
- if (list[0] === '') list.shift();
358
- var index = list.indexOf(itemName);
359
- if (index < 0 && add)
360
- list.push(itemName);
361
- if (index >= 0 && remove)
362
- list.splice(index, 1);
363
- element.className = list.join(' ');
364
- return (index >= 0);
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
- Object.defineProperty(HTMLElement.prototype, 'classList', {
383
- get: function() {
384
- if (this._classList)
385
- return this._classList;
386
-
387
- var classList = Object.create(classListPrototype, {
388
- element: {
389
- value: this,
390
- writable: false,
391
- enumerable: true
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
- Object.defineProperty(this, '_classList', {
395
- value: classList,
396
- writable: false,
397
- enumerable: false
398
- });
399
- return classList;
400
- },
401
- enumerable: true
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
- if (!('console' in window)) {
408
- window.console = {
409
- log: function() {},
410
- error: function() {},
411
- warn: function() {}
412
- };
413
- } else if (!('bind' in console.log)) {
414
- // native functions in IE9 might not have bind
415
- console.log = (function(fn) {
416
- return function(msg) { return fn(msg); };
417
- })(console.log);
418
- console.error = (function(fn) {
419
- return function(msg) { return fn(msg); };
420
- })(console.error);
421
- console.warn = (function(fn) {
422
- return function(msg) { return fn(msg); };
423
- })(console.warn);
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
- // workaround for reported Opera bug DSK-354448:
430
- // onclick fires on disabled buttons with opaque content
431
- function ignoreIfTargetDisabled(event) {
432
- if (isDisabled(event.target)) {
433
- event.stopPropagation();
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
- // sometimes IE loosing the data created with createObjectURL(), see #3977
448
- if (navigator.userAgent.indexOf('Trident') >= 0) {
449
- PDFJS.disableCreateObjectURL = true;
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
- if ('language' in navigator)
456
- return;
457
- Object.defineProperty(navigator, 'language', {
458
- get: function navigatorLanguage() {
459
- var language = navigator.userLanguage || 'en-US';
460
- return language.substring(0, 2).toLowerCase() +
461
- language.substring(2).toUpperCase();
462
- },
463
- enumerable: true
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
- // Safari has issues with cached range requests see:
469
- // https://github.com/mozilla/pdf.js/issues/3260
470
- // Last tested with version 6.0.4.
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
- var regex = /Android\s[0-2][^\d]/;
479
- var isOldAndroid = regex.test(navigator.userAgent);
480
-
481
- if (isSafari || isOldAndroid) {
482
- PDFJS.disableRange = true;
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
- if (!window.history.pushState) {
489
- PDFJS.disableHistory = true;
490
- }
508
+ if (!window.history.pushState) {
509
+ PDFJS.disableHistory = true;
510
+ }
491
511
  })();