1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Merge branch 'master' of github.com:mozilla/pdf.js into fallback-ui

Conflicts:
	extensions/firefox/components/PdfStreamConverter.js
This commit is contained in:
Brendan Dahl 2012-05-24 14:01:10 -07:00
commit 2da12930a6
43 changed files with 1052 additions and 179 deletions

View file

@ -120,6 +120,9 @@
return new Uint8Array(new VBArray(this.responseBody).toArray());
}
});
Object.defineProperty(xhrPrototype, 'overrideMimeType', {
value: function xmlHttpRequestOverrideMimeType(mimeType) {}
});
return;
}
@ -217,15 +220,84 @@
var div = document.createElement('div');
if ('dataset' in div)
return; // dataset property exists
var oldCreateElement = document.createElement;
document.createElement = function newCreateElement() {
var result = oldCreateElement.apply(document, arguments);
if (arguments[0] === 'div') {
// creating dataset property for the div elements
result.dataset = {};
Object.defineProperty(HTMLElement.prototype, 'dataset', {
get: function() {
if (this._dataset)
return this._dataset;
var dataset = {};
for (var j = 0, jj = this.attributes.length; j < jj; j++) {
var attribute = this.attributes[j];
if (attribute.name.substring(0, 5) != 'data-')
continue;
var key = attribute.name.substring(5).replace(/\-([a-z])/g,
function(all, ch) { return ch.toUpperCase(); });
dataset[key] = attribute.value;
}
Object.defineProperty(this, '_dataset', {
value: dataset,
writable: false,
enumerable: false
});
return dataset;
},
enumerable: true
});
})();
// HTMLElement classList property
(function checkClassListProperty() {
var div = document.createElement('div');
if ('classList' in div)
return; // classList property exists
function changeList(element, itemName, add, remove) {
var s = element.className || '';
var list = s.split(/\s+/g);
if (list[0] == '') list.shift();
var index = list.indexOf(itemName);
if (index < 0 && add)
list.push(itemName);
if (index >= 0 && remove)
list.splice(index, 1);
element.className = list.join(' ');
}
var classListPrototype = {
add: function(name) {
changeList(this.element, name, true, false);
},
remove: function(name) {
changeList(this.element, name, false, true);
},
toggle: function(name) {
changeList(this.element, name, true, true);
}
return result;
};
Object.defineProperty(HTMLElement.prototype, 'classList', {
get: function() {
if (this._classList)
return this._classList;
var classList = Object.create(classListPrototype, {
element: {
value: this,
writable: false,
enumerable: true
}
});
Object.defineProperty(this, '_classList', {
value: classList,
writable: false,
enumerable: false
});
return classList;
},
enumerable: true
});
})();
// Check console compatability
@ -252,3 +324,17 @@
document.addEventListener('click', ignoreIfTargetDisabled, true);
}
})();
// Checks if navigator.language is supported
(function checkNavigatorLanguage() {
if ('language' in navigator)
return;
Object.defineProperty(navigator, 'language', {
get: function navigatorLanguage() {
var language = navigator.userLanguage || 'en-US';
return language.substring(0, 2).toLowerCase() +
language.substring(2).toUpperCase();
},
enumerable: true
});
})();

Binary file not shown.

After

Width:  |  Height:  |  Size: 708 B

View file

@ -424,6 +424,10 @@ html[dir='rtl'] .dropdownToolbarButton {
background: transparent;
}
.dropdownToolbarButton > select > option {
background: hsl(0,0%,24%);
}
#customScaleOption {
display: none;
}
@ -497,6 +501,11 @@ html[dir='rtl'] .toolbarButton.pageDown::before {
content: url(images/toolbarButton-print.png);
}
.toolbarButton.openFile::before {
display: inline-block;
content: url(images/toolbarButton-openFile.png);
}
.toolbarButton.download::before {
display: inline-block;
content: url(images/toolbarButton-download.png);
@ -927,3 +936,52 @@ canvas {
#PDFBug table {
font-size: 10px;
}
@media all and (max-width: 950px) {
html[dir='ltr'] #outerContainer.sidebarMoving .outerCenter,
html[dir='ltr'] #outerContainer.sidebarOpen .outerCenter {
float: left;
left: 180px;
}
html[dir='rtl'] #outerContainer.sidebarMoving .outerCenter,
html[dir='rtl'] #outerContainer.sidebarOpen .outerCenter {
float: right;
right: 180px;
}
}
@media all and (max-width: 770px) {
#sidebarContainer {
top: 33px;
z-index: 100;
}
#sidebarContent {
top: 32px;
background-color: hsla(0,0%,0%,.7);
}
#thumbnailView, #outlineView {
top: 66px;
}
html[dir='ltr'] #outerContainer.sidebarOpen > #mainContainer {
left: 0px;
}
html[dir='rtl'] #outerContainer.sidebarOpen > #mainContainer {
right: 0px;
}
html[dir='ltr'] .outerCenter {
float: left;
left: 180px;
}
html[dir='rtl'] .outerCenter {
float: right;
right: 180px;
}
}
@media all and (max-width: 600px) {
#toolbarViewerRight {
display: none;
}
}

View file

@ -81,20 +81,16 @@
<span data-l10n-id="next_label">Next</span>
</button>
</div>
<label class="toolbarLabel" for="pageNumber" data-l10n-id="page_label">Page: </label>
<label id="pageNumberLabel" class="toolbarLabel" for="pageNumber" data-l10n-id="page_label">Page: </label>
<input type="number" id="pageNumber" class="toolbarField pageNumber" onchange="PDFView.page = this.value;" value="1" size="4" min="1" tabindex="6">
</input>
<span id="numPages" class="toolbarLabel"></span>
</div>
<div id="toolbarViewerRight">
<input id="fileInput" class="fileInput" type="file" oncontextmenu="return false;" tabindex="10" />
<!--
<input id="fileInput" class="fileInput" type="file" oncontextmenu="return false;" style="visibility: hidden; position: fixed; right: 0; top: 0" />
<button id="openFile" class="toolbarButton print" title="Open File" tabindex="10" data-l10n-id="open_file" onclick="document.getElementById('fileInput').click()">
<button id="openFile" class="toolbarButton openFile" title="Open File" tabindex="10" data-l10n-id="open_file" onclick="document.getElementById('fileInput').click()">
<span data-l10n-id="open_file_label">Open</span>
</button>
-->
<!--
<button id="print" class="toolbarButton print" title="Print" tabindex="11" data-l10n-id="print" onclick="window.print()">
@ -119,7 +115,7 @@
<span data-l10n-id="zoom_in_label">Zoom In</span>
</button>
</div>
<span class="dropdownToolbarButton">
<span id="scaleSelectContainer" class="dropdownToolbarButton">
<select id="scaleSelect" onchange="PDFView.parseScale(this.value);" title="Zoom" oncontextmenu="return false;" tabindex="9" data-l10n-id="zoom">
<option id="pageAutoOption" value="auto" selected="selected" data-l10n-id="page_scale_auto">Automatic Zoom</option>
<option id="pageActualOption" value="page-actual" data-l10n-id="page_scale_actual">Actual Size</option>

View file

@ -332,10 +332,15 @@ var PDFView = {
return currentPageNumber;
},
open: function pdfViewOpen(url, scale) {
this.url = url;
document.title = decodeURIComponent(getFileName(url)) || url;
open: function pdfViewOpen(url, scale, password) {
var parameters = {password: password};
if (typeof url === 'string') { // URL
this.url = url;
document.title = decodeURIComponent(getFileName(url)) || url;
parameters.url = url;
} else if (url && 'byteLength' in url) { // ArrayBuffer
parameters.data = url;
}
if (!PDFView.loadingBar) {
PDFView.loadingBar = new ProgressBar('#loadingBar', {});
@ -343,12 +348,23 @@ var PDFView = {
var self = this;
self.loading = true;
PDFJS.getDocument(url).then(
PDFJS.getDocument(parameters).then(
function getDocumentCallback(pdfDocument) {
self.load(pdfDocument, scale);
self.loading = false;
},
function getDocumentError(message, exception) {
if (exception.name === 'PasswordException') {
if (exception.code === 'needpassword') {
var promptString = mozL10n.get('request_password', null,
'PDF is protected by a password:');
password = prompt(promptString);
if (password && password.length > 0) {
return PDFView.open(url, scale, password);
}
}
}
var loadingIndicator = document.getElementById('loading');
loadingIndicator.textContent = mozL10n.get('loading_error_indicator',
null, 'Error');
@ -1366,7 +1382,7 @@ window.addEventListener('load', function webViewerLoad(evt) {
if (PDFJS.isFirefoxExtension || !window.File || !window.FileReader ||
!window.FileList || !window.Blob) {
document.getElementById('fileInput').setAttribute('hidden', 'true');
document.getElementById('openFile').setAttribute('hidden', 'true');
} else {
document.getElementById('fileInput').value = null;
}
@ -1555,10 +1571,7 @@ window.addEventListener('change', function webViewerChange(evt) {
for (var i = 0; i < data.length; i++)
uint8Array[i] = data.charCodeAt(i);
// TODO using blob instead?
PDFJS.getDocument(uint8Array).then(function(pdfDocument) {
PDFView.load(pdfDocument);
});
PDFView.open(uint8Array, 0);
};
// Read as a binary string since "readAsArrayBuffer" is not yet