function GrabDragDropClass() { this.mouse_x=0; this.mouse_y=0; this.drag_object_name = ""; this.old_zIndex = 0; this.old_onmousedown = ""; this.target_name = ""; this.drag_trigger_name = ""; this.resize_trigger_name = ""; this.initialize = function (target_name, drag_trigger_name, resize_trigger_name) { var this_class = this; this.target_name = target_name; this.drag_trigger_name = drag_trigger_name; this.resize_trigger_name = resize_trigger_name; $(this.target_name).onmouseover = function () { this_class.on_mouse_over(); } $(this.drag_trigger_name).onmouseover = function () { this.style.cursor='Hand'; } $(this.drag_trigger_name).onmouseout = function () { this.style.cursor='default'; } $(this.drag_trigger_name).onmousedown = function () { this_class.grab(this_class.target_name); } if (this.resize_trigger_name != "") { $(this.resize_trigger_name).onmouseover = function () { this.style.cursor='se-resize'; } $(this.resize_trigger_name).onmouseout = function () { this.style.cursor='default'; } $(this.resize_trigger_name).onmousedown = function () { this_class.resize_grab(this_class.target_name); } } } this.set_mouse_point = function () { var mouse_point = this.get_mouse_point(); this.mouse_x = mouse_point[0]; this.mouse_y = mouse_point[1]; } this.get_mouse_point = function () { if (chk_browser("FireFox") == true) return (get_mouse_point()); var point = new Array(); var e = window.event; if (e) { if (e.pageX || e.pageY) { point.push(e.pageX); point.push(e.pageY); } else if (e.clientX || e.clientY) { point.push(e.clientX + document.body.scrollLeft); point.push(e.clientY + document.body.scrollTop); } } if (point[0] < 10) point[0] = 10; if (point[1] < 10) point[1] = 10; return (point); } this.grab = function (obj_name) { var this_class = this; //var max_zIndex = this.get_max_zIndex(); //var this_zIndex = parseInt($(this.target_name).style.zIndex, 10); if (this.before_grab() == false) return (false); this.drag_object_name = obj_name; this.set_mouse_point(); //if (this_zIndex <= max_zIndex) // $(this.target_name).style.zIndex = max_zIndex + 1; //setOpacity(this.drag_object_name, 3); this.old_onmousedown = $(this.drag_trigger_name).onmousedown; document.onmousedown = function () { return (false); } document.onmousemove = function (_event) { if (chk_browser("Firefox")) FF_mouse_point(_event); this_class.drag(); return (false); } document.onmouseup = function () { this_class.drop(); return (false); } $(this.drag_trigger_name).onmousedown = function () { return (false); } if (this.on_grab() == false) return (false); if (this.after_grab() == false) return (false); return (false); } this.drop = function () { if (this.before_drop() == false) return (false); try { //setOpacity(this.target_name, 10); this.drag_object_name = ""; $(this.drag_trigger_name).onmousedown = this.old_onmousedown; document.onmousemove = null; document.onmousedown = null; document.onmouseup = null; if (chk_browser("Firefox")) document.onmousemove = FF_mouse_point; if (this.on_drop() == false) return (false); } catch (e) { return (false); } if (this.after_drop() == false) return (false); } this.drag = function () { var e = window.event; if (e.button == 0) { this.drop(); return (false); } var _obj = ""; var _diff_x, _diff_y; var _obj_x, _obj_y; var mouse_point = this.get_mouse_point(); if (this.before_drag() == false) return (false); try { _obj = $(this.drag_object_name) } catch (e) { this.drop(); return (false); } if (this.drag_object_name == "") { this.drop(); return (false); } _diff_x = mouse_point[0] - this.mouse_x; _diff_y = mouse_point[1] - this.mouse_y; this.mouse_x = mouse_point[0]; this.mouse_y = mouse_point[1]; _obj_x = parseInt(_obj.style.left, 10); _obj_y = parseInt(_obj.style.top, 10); if (_obj_x < 10) _obj_x = 10; if (_obj_y < 10) _obj_y = 10; _obj.style.left = (_obj_x + _diff_x).toString(10) + 'px'; _obj.style.top = (_obj_y + _diff_y).toString(10) + 'px'; if (this.on_drag() == false) return (false); if (this.after_drag() == false) return (false); return (false); } this.on_grab = function () { } this.before_grab = function () { } this.after_grab = function () { } this.on_drag = function () { } this.before_drag = function () { } this.after_drag = function () { var _obj = $(this.target_name) var _obj_x = parseInt(_obj.style.left, 10); var _obj_y = parseInt(_obj.style.top, 10); window.status = "layer(x, y) = (" + _obj_x + ", " + _obj_y + ")" ; } this.on_drop = function () { window.status = ""; } this.before_drop = function () { } this.after_drop = function () { } this.resize_grab = function (obj_name) { var this_class = this; var max_zIndex = this.get_max_zIndex(); var this_zIndex = parseInt($(this.target_name).style.zIndex, 10); if (this.before_resize_grab() == false) return (false); this.drag_object_name = obj_name; this.set_mouse_point(); this.old_zIndex = $(this.target_name).style.zIndex; if (this_zIndex = max_zIndex) $(this.target_name).style.zIndex = max_zIndex + 1; setOpacity(this.target_name, 3); this.drag_object_name = obj_name; this.set_mouse_point(); this.old_onmousedown = $(this.resize_trigger_name).onmousedown; $(this.resize_trigger_name).onmousedown = function () { return (false); } document.onmousedown = function () { return (false); } document.onmousemove = function () { this_class.resize_drag(); } document.onmouseup = function () { this_class.resize_drop(); } if (this.on_resize_grab() == false) return (false); if (this.after_resize_grab() == false) return (false); return (false); } this.resize_drag = function () { if (this.drag_object_name == "") return (false); var _obj = $(this.target_name) var _diff_x, _diff_y; var _obj_x, _obj_y; var mouse_point = this.get_mouse_point(); _diff_x = mouse_point[0] - this.mouse_x; _diff_y = mouse_point[1] - this.mouse_y; this.mouse_x = mouse_point[0]; this.mouse_y = mouse_point[1]; _obj_x = parseInt(_obj.style.width, 10); _obj_y = parseInt(_obj.style.height, 10); _obj.style.width = (_obj_x + _diff_x).toString(10) + 'px'; _obj.style.height = (_obj_y + _diff_y).toString(10) + 'px'; return (false); } this.resize_drop = function () { try { setOpacity(this.target_name, 10); this.drag_object_name = ""; $(this.resize_trigger_name).onmousedown = this.old_onmousedown; document.onmousemove = null; document.onmousedown = null; document.onmouseup = null; } catch (e) { } } this.on_resize_grab = function () { } this.before_resize_grab = function () { } this.after_resize_grab = function () { } this.on_resize_drag = function () { } this.before_resize_drag = function () { } this.after_resize_drag = function () { } this.on_resize_drop = function () { } this.before_resize_drop = function () { } this.after_resize_drop = function () { } this.on_mouse_over = function () { } this.on_mouse_out = function () { } this.get_max_zIndex = function () { var max_zIndex = 0; var _ele = document.getElementsByTagName("div"); for (var i = 0; i < _ele.length; i++) { if (_ele[i].id != this.target_name) { var this_zIndex = parseInt(_ele[i].style.zIndex, 10); if (this_zIndex > max_zIndex) max_zIndex = this_zIndex; } } return (max_zIndex); } }