Layout.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * Layout.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /**
  11. * Base layout manager class.
  12. *
  13. * @class tinymce.ui.Layout
  14. */
  15. define("tinymce/ui/Layout", [
  16. "tinymce/util/Class",
  17. "tinymce/util/Tools"
  18. ], function(Class, Tools) {
  19. "use strict";
  20. return Class.extend({
  21. Defaults: {
  22. firstControlClass: 'first',
  23. lastControlClass: 'last'
  24. },
  25. /**
  26. * Constructs a layout instance with the specified settings.
  27. *
  28. * @constructor
  29. * @param {Object} settings Name/value object with settings.
  30. */
  31. init: function(settings) {
  32. this.settings = Tools.extend({}, this.Defaults, settings);
  33. },
  34. /**
  35. * This method gets invoked before the layout renders the controls.
  36. *
  37. * @method preRender
  38. * @param {tinymce.ui.Container} container Container instance to preRender.
  39. */
  40. preRender: function(container) {
  41. container.addClass(this.settings.containerClass, 'body');
  42. },
  43. /**
  44. * Applies layout classes to the container.
  45. *
  46. * @private
  47. */
  48. applyClasses: function(container) {
  49. var self = this, settings = self.settings, items, firstClass, lastClass;
  50. items = container.items().filter(':visible');
  51. firstClass = settings.firstControlClass;
  52. lastClass = settings.lastControlClass;
  53. items.each(function(item) {
  54. item.removeClass(firstClass).removeClass(lastClass);
  55. if (settings.controlClass) {
  56. item.addClass(settings.controlClass);
  57. }
  58. });
  59. items.eq(0).addClass(firstClass);
  60. items.eq(-1).addClass(lastClass);
  61. },
  62. /**
  63. * Renders the specified container and any layout specific HTML.
  64. *
  65. * @method renderHtml
  66. * @param {tinymce.ui.Container} container Container to render HTML for.
  67. */
  68. renderHtml: function(container) {
  69. var self = this, settings = self.settings, items, html = '';
  70. items = container.items();
  71. items.eq(0).addClass(settings.firstControlClass);
  72. items.eq(-1).addClass(settings.lastControlClass);
  73. items.each(function(item) {
  74. if (settings.controlClass) {
  75. item.addClass(settings.controlClass);
  76. }
  77. html += item.renderHtml();
  78. });
  79. return html;
  80. },
  81. /**
  82. * Recalculates the positions of the controls in the specified container.
  83. *
  84. * @method recalc
  85. * @param {tinymce.ui.Container} container Container instance to recalc.
  86. */
  87. recalc: function() {
  88. },
  89. /**
  90. * This method gets invoked after the layout renders the controls.
  91. *
  92. * @method postRender
  93. * @param {tinymce.ui.Container} container Container instance to postRender.
  94. */
  95. postRender: function() {
  96. }
  97. });
  98. });