alignmentPane.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 runtime,core,define,require,dijit */
  25. define("webodf/editor/widgets/dialogWidgets/alignmentPane", [], function () {
  26. "use strict";
  27. runtime.loadClass("core.CSSUnits");
  28. var AlignmentPane = function (callback) {
  29. var self = this,
  30. editorSession,
  31. contentPane,
  32. form;
  33. this.widget = function () {
  34. return contentPane;
  35. };
  36. this.value = function () {
  37. return form.get('value');
  38. };
  39. this.setStyle = function (styleName) {
  40. var style = editorSession.getParagraphStyleAttributes(styleName)['style:paragraph-properties'],
  41. cssUnits = new core.CSSUnits(),
  42. s_topMargin,
  43. s_bottomMargin,
  44. s_leftMargin,
  45. s_rightMargin,
  46. s_textAlign;
  47. if (style !== undefined) {
  48. s_topMargin = cssUnits.convertMeasure(style['fo:margin-top'], 'mm');
  49. s_leftMargin = cssUnits.convertMeasure(style['fo:margin-left'], 'mm');
  50. s_rightMargin = cssUnits.convertMeasure(style['fo:margin-right'], 'mm');
  51. s_bottomMargin = cssUnits.convertMeasure(style['fo:margin-bottom'], 'mm');
  52. s_textAlign = style['fo:text-align'];
  53. form.attr('value', {
  54. topMargin: isNaN(s_topMargin) ? 0 : s_topMargin,
  55. bottomMargin: isNaN(s_bottomMargin) ? 0 : s_bottomMargin,
  56. leftMargin: isNaN(s_leftMargin) ? 0 : s_leftMargin,
  57. rightMargin: isNaN(s_rightMargin) ? 0 : s_rightMargin,
  58. textAlign: s_textAlign && s_textAlign.length ? s_textAlign : 'left'
  59. });
  60. } else {
  61. form.attr('value', {
  62. topMargin: 0,
  63. bottomMargin: 0,
  64. leftMargin: 0,
  65. rightMargin: 0,
  66. textAlign: 'left'
  67. });
  68. }
  69. };
  70. this.setEditorSession = function(session) {
  71. editorSession = session;
  72. };
  73. function init(cb) {
  74. require([
  75. "dojo",
  76. "dojo/ready",
  77. "dojo/dom-construct",
  78. "dijit/layout/ContentPane"],
  79. function (dojo, ready, domConstruct, ContentPane) {
  80. var editorBase = dojo.config && dojo.config.paths &&
  81. dojo.config.paths['webodf/editor'];
  82. runtime.assert(editorBase, "webodf/editor path not defined in dojoConfig");
  83. ready(function () {
  84. contentPane = new ContentPane({
  85. title: runtime.tr("Alignment"),
  86. href: editorBase+"/widgets/dialogWidgets/alignmentPane.html",
  87. preload: true
  88. });
  89. contentPane.onLoad = function () {
  90. form = dijit.byId('alignmentPaneForm');
  91. runtime.translateContent(form.domNode);
  92. };
  93. return cb();
  94. });
  95. });
  96. }
  97. init(function () {
  98. return callback(self);
  99. });
  100. };
  101. return AlignmentPane;
  102. });