OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 'use strict'; | |
6 | |
7 /** | |
8 * Creates a new OpenPDFParamsParser. This parses the open pdf parameters | |
9 * passed in the url to set initial viewport settings for opening the pdf. | |
10 * @param {string} url to be parsed. | |
11 */ | |
12 function OpenPDFParamsParser(url) { | |
13 this.url_ = url; | |
14 this.viewportSettings = {}; | |
raymes
2014/08/28 01:50:32
ditto here, maybe we can just call this "this.urlP
Nikhil
2014/08/28 05:07:37
Done.
| |
15 this.parseOpenPDFParams_(); | |
16 } | |
17 | |
18 OpenPDFParamsParser.prototype = { | |
19 /** | |
20 * @private | |
21 * Parse open PDF parameters. These parameters are mentioned in the url | |
22 * and specify actions to be performed when opening pdf files. | |
23 * See http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/ | |
24 * pdfs/pdf_open_parameters.pdf for details. | |
25 */ | |
26 parseOpenPDFParams_: function() { | |
27 var originalUrl = this.url_; | |
28 var paramIndex = originalUrl.search('#'); | |
29 if (paramIndex == -1) | |
30 return; | |
31 | |
32 var paramTokens = originalUrl.substring(paramIndex + 1).split('&'); | |
33 var paramsDictionary = {}; | |
34 for (var i = 0; i < paramTokens.length; ++i) { | |
35 var keyValueSplit = paramTokens[i].split('='); | |
36 if (keyValueSplit.length != 2) | |
37 continue; | |
38 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; | |
39 } | |
40 | |
41 if ('page' in paramsDictionary) { | |
42 // |pageNumber| is 1-based, but goToPage() take a zero-based page number. | |
43 var pageNumber = parseInt(paramsDictionary['page']); | |
44 if (!isNaN(pageNumber)) | |
45 this.viewportSettings['page'] = pageNumber - 1; | |
46 } | |
47 } | |
48 }; | |
OLD | NEW |