annotation.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Copyright (C) 2013 KO GmbH <copyright@kogmbh.com>
  3. *
  4. * @licstart
  5. * This file is part of WebODF.
  6. *
  7. * WebODF is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU Affero General Public License (GNU AGPL)
  9. * as published by the Free Software Foundation, either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * WebODF is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with WebODF. If not, see <http://www.gnu.org/licenses/>.
  19. * @licend
  20. *
  21. * @source: http://www.webodf.org/
  22. * @source: https://github.com/kogmbh/WebODF/
  23. */
  24. /*global define, require */
  25. define("webodf/editor/widgets/annotation", [
  26. "dijit/form/Button"],
  27. function (Button) {
  28. "use strict";
  29. var AnnotationControl = function (callback) {
  30. var self = this,
  31. editorSession,
  32. widget = {},
  33. addAnnotationButton,
  34. annotationController;
  35. addAnnotationButton = new Button({
  36. label: runtime.tr('Annotate'),
  37. disabled: true,
  38. showLabel: false,
  39. iconClass: 'dijitIconBookmark',
  40. onClick: function () {
  41. if (annotationController) {
  42. annotationController.addAnnotation();
  43. self.onToolDone();
  44. }
  45. }
  46. });
  47. widget.children = [addAnnotationButton];
  48. widget.startup = function () {
  49. widget.children.forEach(function (element) {
  50. element.startup();
  51. });
  52. };
  53. widget.placeAt = function (container) {
  54. widget.children.forEach(function (element) {
  55. element.placeAt(container);
  56. });
  57. return widget;
  58. };
  59. function onAnnotatableChanged(isAnnotatable) {
  60. addAnnotationButton.setAttribute('disabled', !isAnnotatable);
  61. }
  62. this.setEditorSession = function (session) {
  63. if (editorSession) {
  64. annotationController.unsubscribe(gui.AnnotationController.annotatableChanged, onAnnotatableChanged);
  65. }
  66. editorSession = session;
  67. if (editorSession) {
  68. annotationController = editorSession.sessionController.getAnnotationController();
  69. annotationController.subscribe(gui.AnnotationController.annotatableChanged, onAnnotatableChanged);
  70. onAnnotatableChanged(annotationController.isAnnotatable());
  71. } else {
  72. addAnnotationButton.setAttribute('disabled', true);
  73. }
  74. };
  75. this.onToolDone = function () {};
  76. callback(widget);
  77. };
  78. return AnnotationControl;
  79. }
  80. );