annotation.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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, runtime, gui */
  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. /*jslint emptyblock: true*/
  76. this.onToolDone = function () {};
  77. /*jslint emptyblock: false*/
  78. callback(widget);
  79. };
  80. return AnnotationControl;
  81. });