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