pdfjs_viewer-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +77 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/pdfjs_viewer/application.js +16 -0
- data/app/assets/javascripts/pdfjs_viewer/pdfjs/compatibility.js +574 -0
- data/app/assets/javascripts/pdfjs_viewer/pdfjs/l10n.js +1004 -0
- data/app/assets/javascripts/pdfjs_viewer/pdfjs/pdf.combined.js +44784 -0
- data/app/assets/javascripts/pdfjs_viewer/viewer.js +6883 -0
- data/app/assets/stylesheets/pdfjs_viewer/application.css +17 -0
- data/app/assets/stylesheets/pdfjs_viewer/full.scss +7 -0
- data/app/assets/stylesheets/pdfjs_viewer/minimal.scss +31 -0
- data/app/assets/stylesheets/pdfjs_viewer/pdfjs/viewer.css +1990 -0
- data/app/controllers/pdfjs_viewer/application_controller.rb +4 -0
- data/app/controllers/pdfjs_viewer/viewer_controller.rb +11 -0
- data/app/views/pdfjs_viewer/viewer/_viewer.html.erb +406 -0
- data/app/views/pdfjs_viewer/viewer/full.html.erb +1 -0
- data/app/views/pdfjs_viewer/viewer/minimal.html.erb +1 -0
- data/config/routes.rb +4 -0
- data/lib/pdfjs_viewer-rails.rb +18 -0
- data/lib/pdfjs_viewer-rails/helpers.rb +9 -0
- data/lib/pdfjs_viewer-rails/version.rb +5 -0
- data/lib/tasks/pdfjs_viewer_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/sample_controller.rb +8 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/sample/helper.html.erb +1 -0
- data/test/dummy/app/views/sample/show.html.erb +10 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +37 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +2455 -0
- data/test/dummy/log/test.log +1720 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/sample.pdf +0 -0
- data/test/dummy/tmp/cache/assets/development/sass/f1b3e59e51ba5ccf8dc190375cfc40e8c38f8d16/full.scssc +0 -0
- data/test/dummy/tmp/cache/assets/development/sass/f1b3e59e51ba5ccf8dc190375cfc40e8c38f8d16/minimal.scssc +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/04eae8bca898a65982980c3e50ad7fbd +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/12f627b3c5f4d1ba551ec15071b146ed +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/179e183f4ee9ccca7c8937e398f7e5ba +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/1a6d33544c20ead8fcebe2042ac1525b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/20cfc4824e896a020f7386bd98c340ed +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/21b502c161a167bfdda0fb06fefe42b7 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/24f6c5595a9b6a95fa1a17757c55261c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/395495688f5310d0645ec57873b2759e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/41a66f55761db630a20526b0b91e0343 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/4509000351818b96fa2e5239cc0e089b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/595a531e01ee23e6221c62d6d311aba1 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/597414ce2d02f11df6b8f2533b18b142 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6384899a9cb6e830fa5869ffd9de6544 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/730fa2b9535ffcaec1cb98f2daa2a15a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7e62f2ade8de8c8d58ca24ea150a4b62 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/81bfd70f6ddb31a47b5fd2283f02068d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/87ba41d384f696d9f33bcbb6d81cbf38 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/940983b263c09cef8a392334a42dc2b7 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/9439817fb117375f337c0ad9a46b1f76 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/a4b60d7ffa74f207fff9106821cd1759 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/a7f3405fc7c670abe82e4e41c64b5a33 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/a850909a3c37a59780d49c690374cf65 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ab7f07b8312f30b275efc7203f10ccda +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b134e335e41a782ac45a6f0441e5d0ee +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f16770b5fd41beb962f620a6f29110f1 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/fb9ab06a0b93b2a7be41b5ee91378ea2 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ffcc4b97c4cc77c7660fc560d5b9c86d +0 -0
- data/test/dummy/tmp/cache/assets/test/sass/f1b3e59e51ba5ccf8dc190375cfc40e8c38f8d16/full.scssc +0 -0
- data/test/dummy/tmp/cache/assets/test/sass/f1b3e59e51ba5ccf8dc190375cfc40e8c38f8d16/minimal.scssc +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/04eae8bca898a65982980c3e50ad7fbd +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/12f627b3c5f4d1ba551ec15071b146ed +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/1a6d33544c20ead8fcebe2042ac1525b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/21b502c161a167bfdda0fb06fefe42b7 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/24f6c5595a9b6a95fa1a17757c55261c +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/395495688f5310d0645ec57873b2759e +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/4509000351818b96fa2e5239cc0e089b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/595a531e01ee23e6221c62d6d311aba1 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/597414ce2d02f11df6b8f2533b18b142 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/730fa2b9535ffcaec1cb98f2daa2a15a +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/7e62f2ade8de8c8d58ca24ea150a4b62 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/81bfd70f6ddb31a47b5fd2283f02068d +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/940983b263c09cef8a392334a42dc2b7 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/9439817fb117375f337c0ad9a46b1f76 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/a4b60d7ffa74f207fff9106821cd1759 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/a7f3405fc7c670abe82e4e41c64b5a33 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/a850909a3c37a59780d49c690374cf65 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/b134e335e41a782ac45a6f0441e5d0ee +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f16770b5fd41beb962f620a6f29110f1 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/ffcc4b97c4cc77c7660fc560d5b9c86d +0 -0
- data/test/integration/viewer_test.rb +64 -0
- data/test/sandbox/full_viewer.png +0 -0
- data/test/sandbox/helper.png +0 -0
- data/test/sandbox/minimal_viewer.png +0 -0
- data/test/test_helper.rb +34 -0
- metadata +327 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 39ac04bf2bca1fb6bf133e733c3de1e2cf8f0765
|
4
|
+
data.tar.gz: 3912059cd7beb7b306cd255419faf1cdccb16687
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28fe3ac4552a1ab25bec647fe7d99f54731f7f4ab987cbd3fca197dfa0276fb1f195fb4be7c1b9c46137b0ce388367fde50fad58e3294b3aebe6a65b01d74a28
|
7
|
+
data.tar.gz: cdd80bef6c7a30a155e1e2d79f4a0c70368fda0c1a82faef61f11421555965007693ecc97248a2cfa1c1975d68fb82b0e91ec20ec5a6da0c36d3896cec283bfb
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Yves Senn
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# pdfjs_viewer-rails
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'pdfjs_viewer-rails'
|
9
|
+
```
|
10
|
+
|
11
|
+
*Note: pdfjs_viewer-rails is still in early development. Please report if you encounter any issues along the way.*
|
12
|
+
|
13
|
+
## Viewer Styles
|
14
|
+
|
15
|
+
This gem ships with two viewer styles:
|
16
|
+
|
17
|
+
**full**
|
18
|
+
|
19
|
+
<p align="center">
|
20
|
+
<img
|
21
|
+
src="https://raw.githubusercontent.com/senny/pdfjs_viewer-rails/master/doc/files/viewer_full.png"
|
22
|
+
alt="full style"/>
|
23
|
+
</p>
|
24
|
+
|
25
|
+
**minimal**
|
26
|
+
|
27
|
+
<p align="center">
|
28
|
+
<img
|
29
|
+
src="https://raw.githubusercontent.com/senny/pdfjs_viewer-rails/master/doc/files/viewer_minimal.png"
|
30
|
+
alt="minimal style"/>
|
31
|
+
</p>
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
### Using the mountable Engine
|
36
|
+
|
37
|
+
The mountable engine makes it extremely simple to integrate the PDF.js viewer
|
38
|
+
into your application:
|
39
|
+
|
40
|
+
*config/routes.rb*
|
41
|
+
```ruby
|
42
|
+
mount PdfjsViewer::Rails::Engine => "/pdfjs", as: 'pdfjs'
|
43
|
+
```
|
44
|
+
|
45
|
+
Now you can use a link in your templates to open up the viewer:
|
46
|
+
|
47
|
+
```erb
|
48
|
+
<%= link_to "display using the full viewer", pdfjs.full_path(file: "/sample.pdf") %>
|
49
|
+
<%= link_to "display using the minimal viewer", pdfjs.minimal_path(file: "/sample.pdf") %>
|
50
|
+
```
|
51
|
+
|
52
|
+
### Using the helper
|
53
|
+
|
54
|
+
If your integration scenario is more complex you may want to consider using the
|
55
|
+
`pdfjs_viewer` helper. This allows you to embed the viewer into a container like
|
56
|
+
an iframe.
|
57
|
+
|
58
|
+
```erb
|
59
|
+
<%= pdfjs_viewer pdf_url: "/sample.pdf", style: :full %>
|
60
|
+
<%= pdfjs_viewer pdf_url: "/sample.pdf", style: :minimal %>
|
61
|
+
```
|
62
|
+
|
63
|
+
NOTE: The helper will render a full HTML document and should not be used in a layout.
|
64
|
+
|
65
|
+
## Development
|
66
|
+
|
67
|
+
Tests can be executed with:
|
68
|
+
|
69
|
+
```
|
70
|
+
$ bundle exec rake
|
71
|
+
```
|
72
|
+
|
73
|
+
This will render the sample.pdf using phantomjs and save screenshots into `test/sandbox`.
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
pdfjs_viewer-rails is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'PdfjsViewer'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib'
|
31
|
+
t.libs << 'test'
|
32
|
+
t.pattern = 'test/**/*_test.rb'
|
33
|
+
t.verbose = false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
task default: :test
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require pdfjs_viewer/pdfjs/compatibility
|
14
|
+
//= require pdfjs_viewer/pdfjs/pdf.combined
|
15
|
+
//= require pdfjs_viewer/pdfjs/l10n
|
16
|
+
//= require pdfjs_viewer/viewer
|
@@ -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
|
+
})();
|