2
0

hand_tool.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.HandTool = undefined;
  20. var _grab_to_pan = require('pdfjs-web/grab_to_pan');
  21. var _ui_utils = require('pdfjs-web/ui_utils');
  22. var _preferences = require('pdfjs-web/preferences');
  23. var HandTool = function HandToolClosure() {
  24. function HandTool(options) {
  25. this.container = options.container;
  26. this.eventBus = options.eventBus;
  27. this.wasActive = false;
  28. this.handTool = new _grab_to_pan.GrabToPan({
  29. element: this.container,
  30. onActiveChanged: function (isActive) {
  31. this.eventBus.dispatch('handtoolchanged', { isActive: isActive });
  32. }.bind(this)
  33. });
  34. this.eventBus.on('togglehandtool', this.toggle.bind(this));
  35. Promise.all([_ui_utils.localized, _preferences.Preferences.get('enableHandToolOnLoad')]).then(function resolved(values) {
  36. if (values[1] === true) {
  37. this.handTool.activate();
  38. }
  39. }.bind(this)).catch(function rejected(reason) {});
  40. this.eventBus.on('presentationmodechanged', function (e) {
  41. if (e.switchInProgress) {
  42. return;
  43. }
  44. if (e.active) {
  45. this.enterPresentationMode();
  46. } else {
  47. this.exitPresentationMode();
  48. }
  49. }.bind(this));
  50. }
  51. HandTool.prototype = {
  52. get isActive() {
  53. return !!this.handTool.active;
  54. },
  55. toggle: function HandTool_toggle() {
  56. this.handTool.toggle();
  57. },
  58. enterPresentationMode: function HandTool_enterPresentationMode() {
  59. if (this.isActive) {
  60. this.wasActive = true;
  61. this.handTool.deactivate();
  62. }
  63. },
  64. exitPresentationMode: function HandTool_exitPresentationMode() {
  65. if (this.wasActive) {
  66. this.wasActive = false;
  67. this.handTool.activate();
  68. }
  69. }
  70. };
  71. return HandTool;
  72. }();
  73. exports.HandTool = HandTool;