alignmentPane.js 4.2 KB

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