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

Merge remote-tracking branch 'mozilla/master' into textsearch

Conflicts:
	l10n/en-US/viewer.properties
	web/viewer.html
This commit is contained in:
Yury Delendik 2012-05-21 11:32:16 -05:00
commit 609b2a797e
23 changed files with 552 additions and 49 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
});
})();

View file

@ -428,6 +428,10 @@ html[dir='rtl'] .dropdownToolbarButton {
background: transparent;
}
.dropdownToolbarButton > select > option {
background: hsl(0,0%,24%);
}
#customScaleOption {
display: none;
}
@ -984,3 +988,47 @@ canvas {
#PDFBug table {
font-size: 10px;
}
@media all and (max-width: 770px) {
#scaleSelectContainer, #fileInput, #pageNumberLabel {
display: none;
}
#sidebarContainer {
top: 33px;
z-index: 100;
}
#sidebarContent {
top: 33px;
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;
}
#pageNumber {
width: 30px;
}
}
@media all and (max-width: 500px) {
#viewBookmark {
display: none;
}
html[dir='ltr'] .outerCenter {
float: left;
left: 180px;
}
html[dir='rtl'] .outerCenter {
float: right;
right: 180px;
}
}

View file

@ -89,7 +89,7 @@
<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="7">
</input>
<span id="numPages" class="toolbarLabel"></span>
@ -127,7 +127,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="10" 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

@ -333,10 +333,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', {});
@ -344,12 +349,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');
@ -1645,10 +1661,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