]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/debian/missing-sources/framework/Web/Javascripts/source/tinymce-405/classes/ui/Movable.js
baculum: Add missing-sources directory in debian metadata structure
[bacula/bacula] / gui / baculum / debian / missing-sources / framework / Web / Javascripts / source / tinymce-405 / classes / ui / Movable.js
1 /**
2  * Movable.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  * Movable mixin. Makes controls movable absolute and relative to other elements.
13  *
14  * @mixin tinymce.ui.Movable
15  */
16 define("tinymce/ui/Movable", [
17         "tinymce/ui/DomUtils"
18 ], function(DomUtils) {
19         "use strict";
20
21         function calculateRelativePosition(ctrl, targetElm, rel) {
22                 var ctrlElm, pos, x, y, selfW, selfH, targetW, targetH, viewport;
23
24                 viewport = DomUtils.getViewPort();
25
26                 // Get pos of target
27                 pos = DomUtils.getPos(targetElm);
28                 x = pos.x;
29                 y = pos.y;
30
31                 if (ctrl._fixed) {
32                         x -= viewport.x;
33                         y -= viewport.y;
34                 }
35
36                 // Get size of self
37                 ctrlElm = ctrl.getEl();
38                 selfW = ctrlElm.offsetWidth;
39                 selfH = ctrlElm.offsetHeight;
40
41                 // Get size of target
42                 targetW = targetElm.offsetWidth;
43                 targetH = targetElm.offsetHeight;
44
45                 // Parse align string
46                 rel = (rel || '').split('');
47
48                 // Target corners
49                 if (rel[0] === 'b') {
50                         y += targetH;
51                 }
52
53                 if (rel[1] === 'r') {
54                         x += targetW;
55                 }
56
57                 if (rel[0] === 'c') {
58                         y += Math.round(targetH / 2);
59                 }
60
61                 if (rel[1] === 'c') {
62                         x += Math.round(targetW / 2);
63                 }
64
65                 // Self corners
66                 if (rel[3] === 'b') {
67                         y -= selfH;
68                 }
69
70                 if (rel[4] === 'r') {
71                         x -= selfW;
72                 }
73
74                 if (rel[3] === 'c') {
75                         y -= Math.round(selfH / 2);
76                 }
77
78                 if (rel[4] === 'c') {
79                         x -= Math.round(selfW / 2);
80                 }
81
82                 return {
83                         x: x,
84                         y: y,
85                         w: selfW,
86                         h: selfH
87                 };
88         }
89
90         return {
91                 /**
92                  * Tests various positions to get the most suitable one.
93                  *
94                  * @method testMoveRel
95                  * @param {DOMElement} elm Element to position against.
96                  * @param {Array} rels Array with relative positions.
97                  * @return {String} Best suitable relative position.
98                  */
99                 testMoveRel: function(elm, rels) {
100                         var viewPortRect = DomUtils.getViewPort();
101
102                         for (var i = 0; i < rels.length; i++) {
103                                 var pos = calculateRelativePosition(this, elm, rels[i]);
104
105                                 if (this._fixed) {
106                                         if (pos.x > 0 && pos.x + pos.w < viewPortRect.w && pos.y > 0 && pos.y + pos.h < viewPortRect.h) {
107                                                 return rels[i];
108                                         }
109                                 } else {
110                                         if (pos.x > viewPortRect.x && pos.x + pos.w < viewPortRect.w + viewPortRect.x &&
111                                                 pos.y > viewPortRect.y && pos.y + pos.h < viewPortRect.h + viewPortRect.y) {
112                                                 return rels[i];
113                                         }
114                                 }
115                         }
116
117                         return rels[0];
118                 },
119
120                 /**
121                  * Move relative to the specified element.
122                  *
123                  * @method moveRel
124                  * @param {Element} elm Element to move relative to.
125                  * @param {String} rel Relative mode. For example: br-tl.
126                  * @return {tinymce.ui.Control} Current control instance.
127                  */
128                 moveRel: function(elm, rel) {
129                         if (typeof(rel) != 'string') {
130                                 rel = this.testMoveRel(elm, rel);
131                         }
132
133                         var pos = calculateRelativePosition(this, elm, rel);
134                         return this.moveTo(pos.x, pos.y);
135                 },
136
137                 /**
138                  * Move by a relative x, y values.
139                  *
140                  * @method moveBy
141                  * @param {Number} dx Relative x position.
142                  * @param {Number} dy Relative y position.
143                  * @return {tinymce.ui.Control} Current control instance.
144                  */
145                 moveBy: function(dx, dy) {
146                         var self = this, rect = self.layoutRect();
147
148                         self.moveTo(rect.x + dx, rect.y + dy);
149
150                         return self;
151                 },
152
153                 /**
154                  * Move to absolute position.
155                  *
156                  * @method moveTo
157                  * @param {Number} x Absolute x position.
158                  * @param {Number} y Absolute y position.
159                  * @return {tinymce.ui.Control} Current control instance.
160                  */
161                 moveTo: function(x, y) {
162                         var self = this;
163
164                         // TODO: Move this to some global class
165                         function contrain(value, max, size) {
166                                 if (value < 0) {
167                                         return 0;
168                                 }
169
170                                 if (value + size > max) {
171                                         value = max - size;
172                                         return value < 0 ? 0 : value;
173                                 }
174
175                                 return value;
176                         }
177
178                         if (self.settings.constrainToViewport) {
179                                 var viewPortRect = DomUtils.getViewPort(window);
180                                 var layoutRect = self.layoutRect();
181
182                                 x = contrain(x, viewPortRect.w + viewPortRect.x, layoutRect.w);
183                                 y = contrain(y, viewPortRect.h + viewPortRect.y, layoutRect.h);
184                         }
185
186                         if (self._rendered) {
187                                 self.layoutRect({x: x, y: y}).repaint();
188                         } else {
189                                 self.settings.x = x;
190                                 self.settings.y = y;
191                         }
192
193                         self.fire('move', {x: x, y: y});
194
195                         return self;
196                 }
197         };
198 });