Convert the existing overlays to use the OverlayManager
This commit is contained in:
parent
6dc7a52e35
commit
5cd6dddeee
@ -14,15 +14,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals PDFView, Promise, mozL10n, getPDFFileNameFromURL */
|
||||
/* globals PDFView, Promise, mozL10n, getPDFFileNameFromURL, OverlayManager */
|
||||
|
||||
'use strict';
|
||||
|
||||
var DocumentProperties = {
|
||||
overlayContainer: null,
|
||||
overlayName: null,
|
||||
fileName: '',
|
||||
fileSize: '',
|
||||
visible: false,
|
||||
|
||||
// Document property fields (in the viewer).
|
||||
fileNameField: null,
|
||||
@ -39,7 +38,7 @@ var DocumentProperties = {
|
||||
pageCountField: null,
|
||||
|
||||
initialize: function documentPropertiesInitialize(options) {
|
||||
this.overlayContainer = options.overlayContainer;
|
||||
this.overlayName = options.overlayName;
|
||||
|
||||
// Set the document property fields.
|
||||
this.fileNameField = options.fileNameField;
|
||||
@ -57,24 +56,18 @@ var DocumentProperties = {
|
||||
|
||||
// Bind the event listener for the Close button.
|
||||
if (options.closeButton) {
|
||||
options.closeButton.addEventListener('click', this.hide.bind(this));
|
||||
options.closeButton.addEventListener('click', this.close.bind(this));
|
||||
}
|
||||
|
||||
this.dataAvailablePromise = new Promise(function (resolve) {
|
||||
this.resolveDataAvailable = resolve;
|
||||
}.bind(this));
|
||||
|
||||
// Bind the event listener for the Esc key (to close the dialog).
|
||||
window.addEventListener('keydown',
|
||||
function (e) {
|
||||
if (e.keyCode === 27) { // Esc key
|
||||
this.hide();
|
||||
}
|
||||
}.bind(this));
|
||||
OverlayManager.register(this.overlayName, this.close.bind(this));
|
||||
},
|
||||
|
||||
getProperties: function documentPropertiesGetProperties() {
|
||||
if (!this.visible) {
|
||||
if (!OverlayManager.active) {
|
||||
// If the dialog was closed before dataAvailablePromise was resolved,
|
||||
// don't bother updating the properties.
|
||||
return;
|
||||
@ -136,26 +129,15 @@ var DocumentProperties = {
|
||||
}
|
||||
},
|
||||
|
||||
show: function documentPropertiesShow() {
|
||||
if (this.visible) {
|
||||
return;
|
||||
}
|
||||
this.visible = true;
|
||||
this.overlayContainer.classList.remove('hidden');
|
||||
this.overlayContainer.lastElementChild.classList.remove('hidden');
|
||||
|
||||
this.dataAvailablePromise.then(function () {
|
||||
open: function documentPropertiesOpen() {
|
||||
Promise.all([OverlayManager.open(this.overlayName),
|
||||
this.dataAvailablePromise]).then(function () {
|
||||
this.getProperties();
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
hide: function documentPropertiesClose() {
|
||||
if (!this.visible) {
|
||||
return;
|
||||
}
|
||||
this.visible = false;
|
||||
this.overlayContainer.classList.add('hidden');
|
||||
this.overlayContainer.lastElementChild.classList.add('hidden');
|
||||
close: function documentPropertiesClose() {
|
||||
OverlayManager.close(this.overlayName);
|
||||
},
|
||||
|
||||
parseDate: function documentPropertiesParseDate(inputDate) {
|
||||
|
@ -14,22 +14,21 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* globals PDFJS, mozL10n */
|
||||
/* globals PDFJS, mozL10n, OverlayManager */
|
||||
|
||||
'use strict';
|
||||
|
||||
var PasswordPrompt = {
|
||||
visible: false,
|
||||
overlayName: null,
|
||||
updatePassword: null,
|
||||
reason: null,
|
||||
overlayContainer: null,
|
||||
passwordField: null,
|
||||
passwordText: null,
|
||||
passwordSubmit: null,
|
||||
passwordCancel: null,
|
||||
|
||||
initialize: function secondaryToolbarInitialize(options) {
|
||||
this.overlayContainer = options.overlayContainer;
|
||||
this.overlayName = options.overlayName;
|
||||
this.passwordField = options.passwordField;
|
||||
this.passwordText = options.passwordText;
|
||||
this.passwordSubmit = options.passwordSubmit;
|
||||
@ -39,30 +38,19 @@ var PasswordPrompt = {
|
||||
this.passwordSubmit.addEventListener('click',
|
||||
this.verifyPassword.bind(this));
|
||||
|
||||
this.passwordCancel.addEventListener('click', this.hide.bind(this));
|
||||
this.passwordCancel.addEventListener('click', this.close.bind(this));
|
||||
|
||||
this.passwordField.addEventListener('keydown',
|
||||
function (e) {
|
||||
this.passwordField.addEventListener('keydown', function (e) {
|
||||
if (e.keyCode === 13) { // Enter key
|
||||
this.verifyPassword();
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
window.addEventListener('keydown',
|
||||
function (e) {
|
||||
if (e.keyCode === 27) { // Esc key
|
||||
this.hide();
|
||||
}
|
||||
}.bind(this));
|
||||
OverlayManager.register(this.overlayName, this.close.bind(this), true);
|
||||
},
|
||||
|
||||
show: function passwordPromptShow() {
|
||||
if (this.visible) {
|
||||
return;
|
||||
}
|
||||
this.visible = true;
|
||||
this.overlayContainer.classList.remove('hidden');
|
||||
this.overlayContainer.firstElementChild.classList.remove('hidden');
|
||||
open: function passwordPromptOpen() {
|
||||
OverlayManager.open(this.overlayName).then(function () {
|
||||
this.passwordField.focus();
|
||||
|
||||
var promptString = mozL10n.get('password_label', null,
|
||||
@ -74,22 +62,19 @@ var PasswordPrompt = {
|
||||
}
|
||||
|
||||
this.passwordText.textContent = promptString;
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
hide: function passwordPromptClose() {
|
||||
if (!this.visible) {
|
||||
return;
|
||||
}
|
||||
this.visible = false;
|
||||
close: function passwordPromptClose() {
|
||||
OverlayManager.close(this.overlayName).then(function () {
|
||||
this.passwordField.value = '';
|
||||
this.overlayContainer.classList.add('hidden');
|
||||
this.overlayContainer.firstElementChild.classList.add('hidden');
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
verifyPassword: function passwordPromptVerifyPassword() {
|
||||
var password = this.passwordField.value;
|
||||
if (password && password.length > 0) {
|
||||
this.hide();
|
||||
this.close();
|
||||
return this.updatePassword(password);
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ var SecondaryToolbar = {
|
||||
},
|
||||
|
||||
documentPropertiesClick: function secondaryToolbarDocumentPropsClick(evt) {
|
||||
this.documentProperties.show();
|
||||
this.documentProperties.open();
|
||||
this.close();
|
||||
},
|
||||
|
||||
|
@ -77,10 +77,11 @@ http://sourceforge.net/adobe/cmap/wiki/License/
|
||||
<script src="pdf_find_controller.js"></script>
|
||||
<script src="pdf_history.js"></script>
|
||||
<script src="secondary_toolbar.js"></script>
|
||||
<script src="password_prompt.js"></script>
|
||||
<script src="presentation_mode.js"></script>
|
||||
<script src="grab_to_pan.js"></script>
|
||||
<script src="hand_tool.js"></script>
|
||||
<script src="overlay_manager.js"></script>
|
||||
<script src="password_prompt.js"></script>
|
||||
<script src="document_properties.js"></script>
|
||||
<!--#endif-->
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
Preferences, SidebarView, ViewHistory, PageView, ThumbnailView, URL,
|
||||
noContextMenuHandler, SecondaryToolbar, PasswordPrompt,
|
||||
PresentationMode, HandTool, Promise, DocumentProperties,
|
||||
DocumentOutlineView, DocumentAttachmentsView */
|
||||
DocumentOutlineView, DocumentAttachmentsView, OverlayManager */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -100,9 +100,10 @@ var currentPageNumber = 1;
|
||||
//#include pdf_find_controller.js
|
||||
//#include pdf_history.js
|
||||
//#include secondary_toolbar.js
|
||||
//#include password_prompt.js
|
||||
//#include presentation_mode.js
|
||||
//#include hand_tool.js
|
||||
//#include overlay_manager.js
|
||||
//#include password_prompt.js
|
||||
//#include document_properties.js
|
||||
|
||||
var PDFView = {
|
||||
@ -183,14 +184,6 @@ var PDFView = {
|
||||
documentPropertiesButton: document.getElementById('documentProperties')
|
||||
});
|
||||
|
||||
PasswordPrompt.initialize({
|
||||
overlayContainer: document.getElementById('overlayContainer'),
|
||||
passwordField: document.getElementById('password'),
|
||||
passwordText: document.getElementById('passwordText'),
|
||||
passwordSubmit: document.getElementById('passwordSubmit'),
|
||||
passwordCancel: document.getElementById('passwordCancel')
|
||||
});
|
||||
|
||||
PresentationMode.initialize({
|
||||
container: container,
|
||||
secondaryToolbar: SecondaryToolbar,
|
||||
@ -200,8 +193,16 @@ var PDFView = {
|
||||
pageRotateCcw: document.getElementById('contextPageRotateCcw')
|
||||
});
|
||||
|
||||
PasswordPrompt.initialize({
|
||||
overlayName: 'passwordOverlay',
|
||||
passwordField: document.getElementById('password'),
|
||||
passwordText: document.getElementById('passwordText'),
|
||||
passwordSubmit: document.getElementById('passwordSubmit'),
|
||||
passwordCancel: document.getElementById('passwordCancel')
|
||||
});
|
||||
|
||||
DocumentProperties.initialize({
|
||||
overlayContainer: document.getElementById('overlayContainer'),
|
||||
overlayName: 'documentPropertiesOverlay',
|
||||
closeButton: document.getElementById('documentPropertiesClose'),
|
||||
fileNameField: document.getElementById('fileNameField'),
|
||||
fileSizeField: document.getElementById('fileSizeField'),
|
||||
@ -626,7 +627,7 @@ var PDFView = {
|
||||
var passwordNeeded = function passwordNeeded(updatePassword, reason) {
|
||||
PasswordPrompt.updatePassword = updatePassword;
|
||||
PasswordPrompt.reason = reason;
|
||||
PasswordPrompt.show();
|
||||
PasswordPrompt.open();
|
||||
};
|
||||
|
||||
function getDocumentProgress(progressData) {
|
||||
@ -2165,7 +2166,7 @@ window.addEventListener('click', function click(evt) {
|
||||
}, false);
|
||||
|
||||
window.addEventListener('keydown', function keydown(evt) {
|
||||
if (PasswordPrompt.visible) {
|
||||
if (OverlayManager.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user