hand_tool.js 2.2 KB

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