2
0

hand_tool.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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('./grab_to_pan');
  21. var _ui_utils = require('./ui_utils');
  22. var HandTool = function HandToolClosure() {
  23. function HandTool(options) {
  24. var _this = this;
  25. this.container = options.container;
  26. this.eventBus = options.eventBus;
  27. var preferences = options.preferences;
  28. this.wasActive = false;
  29. this.handTool = new _grab_to_pan.GrabToPan({
  30. element: this.container,
  31. onActiveChanged: function onActiveChanged(isActive) {
  32. _this.eventBus.dispatch('handtoolchanged', { isActive: isActive });
  33. }
  34. });
  35. this.eventBus.on('togglehandtool', this.toggle.bind(this));
  36. Promise.all([_ui_utils.localized, preferences.get('enableHandToolOnLoad')]).then(function (values) {
  37. if (values[1] === true) {
  38. _this.handTool.activate();
  39. }
  40. }).catch(function rejected(reason) {});
  41. this.eventBus.on('presentationmodechanged', function (e) {
  42. if (e.switchInProgress) {
  43. return;
  44. }
  45. if (e.active) {
  46. this.enterPresentationMode();
  47. } else {
  48. this.exitPresentationMode();
  49. }
  50. }.bind(this));
  51. }
  52. HandTool.prototype = {
  53. get isActive() {
  54. return !!this.handTool.active;
  55. },
  56. toggle: function HandTool_toggle() {
  57. this.handTool.toggle();
  58. },
  59. enterPresentationMode: function HandTool_enterPresentationMode() {
  60. if (this.isActive) {
  61. this.wasActive = true;
  62. this.handTool.deactivate();
  63. }
  64. },
  65. exitPresentationMode: function HandTool_exitPresentationMode() {
  66. if (this.wasActive) {
  67. this.wasActive = false;
  68. this.handTool.activate();
  69. }
  70. }
  71. };
  72. return HandTool;
  73. }();
  74. exports.HandTool = HandTool;