Add dynamic textarea sizing slider control to compose screen (default_advanced skin...
[squirrelmail.git] / templates / default_advanced / js / resizing.js
1 /**
2 * Library functions for resizing widgets
3 *
4 */
5
6
7
8 // event handler temporary storage variables for IE 4
9 //
10 var old_mousemove_handler;
11 var old_mouseup_handler;
12
13
14
15 // define variables used in vertical resize handlers
16 //
17 var element_being_vert_resized;
18 var element_being_vert_resized_orig_opacity;
19 var min_vert_resize_height;
20 var max_vert_resize_height;
21 var original_vert_click_pos;
22 var original_vert_height;
23
24
25
26 /**
27 * Begin a (vertical only) resize of some element
28 *
29 * Note that this event handler is only intended
30 * to be called for an event (usually mousedown)
31 * that is registered as a tag attribute (not with
32 * addEventListener() and ilk).
33 *
34 * @param evt The JavaScript event object
35 * @param resize_element The element being resized
36 * @param min_height The minimum allowable resize height
37 * @param max_height The maximum allowable resize height
38 * @param handle_element The handle element that was clicked
39 * upon to initiate the resize
40 *
41 */
42 function startVertResizeDrag(evt, resize_element, min_height,
43 max_height, handle_element)
44 {
45
46 // assign variables used in other handlers
47 //
48 element_being_vert_resized = resize_element;
49 min_vert_resize_height = min_height;
50 max_vert_resize_height = max_height;
51
52
53 // dim element to emphasize effect
54 //
55 element_being_vert_resized_orig_opacity = element_being_vert_resized.style.opacity;
56 element_being_vert_resized.style.opacity = 0.25;
57
58
59 // detemine original vertical click coordinates
60 //
61 original_vert_click_pos = evt.clientY;
62 original_vert_height = element_being_vert_resized.offsetHeight;
63
64
65 // add drag and finish drag listeners
66 //
67 if (document.addEventListener) // DOM Level 2 Event Model
68 {
69 document.addEventListener('mousemove', continueVertResizeDrag, true);
70 document.addEventListener('mouseup', finishVertResizeDrag, true);
71 }
72 else if (document.attachEvent) // IE 5+ Event Model
73 {
74 document.attachEvent("onmousemove", continueVertResizeDrag);
75 document.attachEvent("onmouseup", finishVertResizeDrag);
76 }
77 else // IE 4 Event Model
78 {
79 old_mousemove_handler = document.onmousemove;
80 old_mouseup_handler = document.onmouseup;
81 document.onmousemove = continueVertResizeDrag;
82 document.onmouseup = finishVertResizeDrag;
83 }
84
85
86 // indicate that the event has been handled
87 //
88 if (evt.stopPropagation) evt.stopPropagation(); // DOM Level 2
89 else evt.cancelBubble = true; // IE
90
91
92 // don't let any default action happen
93 //
94 if (evt.preventDefault) evt.preventDefault(); // DOM Level 2
95 else evt.returnValue = false; // IE
96
97
98 // to top it all off, return false too
99 //
100 return false;
101
102 }
103
104
105
106 /**
107 * Continue a (vertical only) resize of some element
108 *
109 * @param evt The JavaScript event object
110 *
111 */
112 function continueVertResizeDrag(evt)
113 {
114
115 // IE blows
116 //
117 if (!evt) evt = window.event;
118 if (!evt) return true;
119
120
121 // adjust height of resize item according to current mouse position
122 //
123 delta_resize = original_vert_click_pos - evt.clientY;
124 new_height = original_vert_height - delta_resize;
125 if (new_height >= min_vert_resize_height && new_height <= max_vert_resize_height)
126 element_being_vert_resized.style.height = new_height + 'px';
127
128
129 // indicate that the event has been handled
130 //
131 if (evt.stopPropagation) evt.stopPropagation(); // DOM Level 2
132 else evt.cancelBubble = true; // IE
133
134
135 // to top it all off, return false too
136 //
137 return false;
138
139 }
140
141
142
143 /**
144 * Finish a (vertical only) resize of some element
145 *
146 * @param evt The JavaScript event object
147 *
148 */
149 function finishVertResizeDrag(evt)
150 {
151
152 // IE blows
153 //
154 if (!evt) evt = window.event;
155 if (!evt) return true;
156
157
158 // restore element's original opacity
159 //
160 element_being_vert_resized.style.opacity = element_being_vert_resized_orig_opacity;
161
162
163 // unregister all event listeners
164 //
165 if (document.removeEventListener) // DOM Event Model
166 {
167 document.removeEventListener("mousemove", continueVertResizeDrag, true);
168 document.removeEventListener("mouseup", finishVertResizeDrag, true);
169 }
170 else if (document.detachEvent) // IE 5+ Event Model
171 {
172 document.detachEvent("onmousemove", continueVertResizeDrag);
173 document.detachEvent("onmouseup", finishVertResizeDrag);
174 }
175 else // IE 4 Event Model
176 {
177 document.onmousemove = old_mousemove_handler;
178 document.onmouseup = old_mouseup_handler;
179 }
180
181
182 // indicate that the event has been handled
183 //
184 if (evt.stopPropagation) evt.stopPropagation(); // DOM Level 2
185 else evt.cancelBubble = true; // IE
186
187
188 // to top it all off, return false too
189 //
190 return false;
191
192 }
193
194
195