2
0

hand_tool.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  21. var _grab_to_pan = require('./grab_to_pan');
  22. var _ui_utils = require('./ui_utils');
  23. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  24. var HandTool = function () {
  25. function HandTool(_ref) {
  26. var _this = this;
  27. var container = _ref.container,
  28. eventBus = _ref.eventBus,
  29. preferences = _ref.preferences;
  30. _classCallCheck(this, HandTool);
  31. this.container = container;
  32. this.eventBus = eventBus;
  33. this.wasActive = false;
  34. this.handTool = new _grab_to_pan.GrabToPan({
  35. element: this.container,
  36. onActiveChanged: function onActiveChanged(isActive) {
  37. _this.eventBus.dispatch('handtoolchanged', { isActive: isActive });
  38. }
  39. });
  40. this.eventBus.on('togglehandtool', this.toggle.bind(this));
  41. var enableOnLoad = preferences.get('enableHandToolOnLoad');
  42. Promise.all([_ui_utils.localized, enableOnLoad]).then(function (values) {
  43. if (values[1] === true) {
  44. _this.handTool.activate();
  45. }
  46. }).catch(function (reason) {});
  47. this.eventBus.on('presentationmodechanged', function (evt) {
  48. if (evt.switchInProgress) {
  49. return;
  50. }
  51. if (evt.active) {
  52. _this.enterPresentationMode();
  53. } else {
  54. _this.exitPresentationMode();
  55. }
  56. });
  57. }
  58. _createClass(HandTool, [{
  59. key: 'toggle',
  60. value: function toggle() {
  61. this.handTool.toggle();
  62. }
  63. }, {
  64. key: 'enterPresentationMode',
  65. value: function enterPresentationMode() {
  66. if (this.isActive) {
  67. this.wasActive = true;
  68. this.handTool.deactivate();
  69. }
  70. }
  71. }, {
  72. key: 'exitPresentationMode',
  73. value: function exitPresentationMode() {
  74. if (this.wasActive) {
  75. this.wasActive = false;
  76. this.handTool.activate();
  77. }
  78. }
  79. }, {
  80. key: 'isActive',
  81. get: function get() {
  82. return !!this.handTool.active;
  83. }
  84. }]);
  85. return HandTool;
  86. }();
  87. exports.HandTool = HandTool;