2 * Library functions for resizing widgets
8 // event handler temporary storage variables for IE 4
10 var old_mousemove_handler
;
11 var old_mouseup_handler
;
15 // define variables used in vertical resize handlers
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
;
27 * Begin a (vertical only) resize of some element
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).
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
42 function startVertResizeDrag(evt
, resize_element
, min_height
,
43 max_height
, handle_element
)
46 // assign variables used in other handlers
48 element_being_vert_resized
= resize_element
;
49 min_vert_resize_height
= min_height
;
50 max_vert_resize_height
= max_height
;
53 // dim element to emphasize effect
55 element_being_vert_resized_orig_opacity
= element_being_vert_resized
.style
.opacity
;
56 element_being_vert_resized
.style
.opacity
= 0.25;
59 // detemine original vertical click coordinates
61 original_vert_click_pos
= evt
.clientY
;
62 original_vert_height
= element_being_vert_resized
.offsetHeight
;
65 // add drag and finish drag listeners
67 if (document
.addEventListener
) // DOM Level 2 Event Model
69 document
.addEventListener('mousemove', continueVertResizeDrag
, true);
70 document
.addEventListener('mouseup', finishVertResizeDrag
, true);
72 else if (document
.attachEvent
) // IE 5+ Event Model
74 document
.attachEvent("onmousemove", continueVertResizeDrag
);
75 document
.attachEvent("onmouseup", finishVertResizeDrag
);
77 else // IE 4 Event Model
79 old_mousemove_handler
= document
.onmousemove
;
80 old_mouseup_handler
= document
.onmouseup
;
81 document
.onmousemove
= continueVertResizeDrag
;
82 document
.onmouseup
= finishVertResizeDrag
;
86 // indicate that the event has been handled
88 if (evt
.stopPropagation
) evt
.stopPropagation(); // DOM Level 2
89 else evt
.cancelBubble
= true; // IE
92 // don't let any default action happen
94 if (evt
.preventDefault
) evt
.preventDefault(); // DOM Level 2
95 else evt
.returnValue
= false; // IE
98 // to top it all off, return false too
107 * Continue a (vertical only) resize of some element
109 * @param evt The JavaScript event object
112 function continueVertResizeDrag(evt
)
117 if (!evt
) evt
= window
.event
;
118 if (!evt
) return true;
121 // adjust height of resize item according to current mouse position
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';
129 // indicate that the event has been handled
131 if (evt
.stopPropagation
) evt
.stopPropagation(); // DOM Level 2
132 else evt
.cancelBubble
= true; // IE
135 // to top it all off, return false too
144 * Finish a (vertical only) resize of some element
146 * @param evt The JavaScript event object
149 function finishVertResizeDrag(evt
)
154 if (!evt
) evt
= window
.event
;
155 if (!evt
) return true;
158 // restore element's original opacity
160 element_being_vert_resized
.style
.opacity
= element_being_vert_resized_orig_opacity
;
163 // unregister all event listeners
165 if (document
.removeEventListener
) // DOM Event Model
167 document
.removeEventListener("mousemove", continueVertResizeDrag
, true);
168 document
.removeEventListener("mouseup", finishVertResizeDrag
, true);
170 else if (document
.detachEvent
) // IE 5+ Event Model
172 document
.detachEvent("onmousemove", continueVertResizeDrag
);
173 document
.detachEvent("onmouseup", finishVertResizeDrag
);
175 else // IE 4 Event Model
177 document
.onmousemove
= old_mousemove_handler
;
178 document
.onmouseup
= old_mouseup_handler
;
182 // indicate that the event has been handled
184 if (evt
.stopPropagation
) evt
.stopPropagation(); // DOM Level 2
185 else evt
.cancelBubble
= true; // IE
188 // to top it all off, return false too