source: temp/trunk/html/js/dragdrop.js @ 1328

Revision 1328, 4.4 KB checked in by naka, 20 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1var obj;
2var offsetX;
3var offsetY;
4var arrObj;
5var objParam;
6
7// ¥Ñ¥é¥á¡¼¥¿´ÉÍý¥¯¥é¥¹¤ÎÄêµÁ
8function SC_Param() {
9    this.ITEM_MAX = 3;     
10}
11
12// ¥µ¥¤¥º´ÉÍý¥¯¥é¥¹¤ÎÄêµÁ
13function SC_Size() {
14    this.id = '';
15    this.left = 0;
16    this.top = 0;
17    this.width = 0;
18    this.height = 0;
19    this.obj;
20};
21
22// ¥ª¥ó¥í¡¼¥É½èÍý
23onload=function () {
24    // ¥Ñ¥é¥á¡¼¥¿¤Î½é´ü²½
25    objParam = new SC_Param();
26   
27    // WIN-IE
28    if (document.all) {
29        objlist = document.all.tags("div");
30    // WIN-NN,WIN-FF   
31    } else if (document.getElementsByTagName) {
32        objlist = document.getElementsByTagName("div");
33    } else {
34        return;
35    }
36   
37    arrObj = new Array();
38    for (i = 0; i < objlist.length; i++) {
39        id = objlist[i].id;
40        arrObj[id] = new SC_Size();
41        arrObj[id].id = id;
42        arrObj[id].obj = objlist[id];
43        arrObj[id].left = objlist[id].style.left;
44        arrObj[id].top = objlist[id].style.top;
45        arrObj[id].width = objlist[id].style.width;
46        arrObj[id].height = objlist[id].style.height;
47        arrObj[id].left = Number(arrObj[id].left.replace(/px/, ''));
48        arrObj[id].top = Number(arrObj[id].top.replace(/px/, ''));
49        arrObj[id].width = Number(arrObj[id].width.replace(/px/, ''));
50        arrObj[id].height = Number(arrObj[id].height.replace(/px/, ''));
51        arrObj[id].right = Number(arrObj[id].left) + Number(arrObj[id].width);
52        arrObj[id].bottom =Number(arrObj[id].top) + Number(arrObj[id].height);
53    }
54   
55    // MouseDown¥¤¥Ù¥ó¥È½èÍý¤ÎÆþ¤ìÂØ¤¨
56    objlist['item0'].onmousedown = onMouseDown;
57    objlist['item1'].onmousedown = onMouseDown;
58    objlist['item2'].onmousedown = onMouseDown;
59   
60    document.onmousemove = onMouseMove;
61    document.onmouseup = onMouseUp;
62}
63
64// MouseDown¥¤¥Ù¥ó¥È
65function onMouseDown(e) {
66   obj = this;
67   // WIN-IE
68   if (document.all) {
69      offsetX = event.offsetX + 2;
70      offsetY = event.offsetY + 2;
71   // WIN-NN,WIN-FF
72   } else if (obj.getElementsByTagName) {
73      offsetX = e.pageX - parseInt(obj.style.left);
74      offsetY = e.pageY - parseInt(obj.style.top);
75   }
76   return false;
77}
78
79// MouseMove¥¤¥Ù¥ó¥È
80function onMouseMove(e) {
81    if (!obj) {
82        return true;
83    }   
84    // WIN-IE
85    if (document.all) {
86        x = event.clientX - offsetX;
87        // ²èÌ̳°¤Ë½Ð¤Ê¤¤¤è¤¦¤ËÀ©¸æ¤¹¤ë¡¡
88        if(x <= 0) {
89            x = 0;
90        }
91        left_max = document.body.clientWidth - arrObj[obj.id].width;
92        if(x >= left_max) {
93            x =left_max;           
94        }
95        obj.style.left = x;
96        // ²èÌ̳°¤Ë½Ð¤Ê¤¤¤è¤¦¤ËÀ©¸æ¤¹¤ë¡¡
97        y = event.clientY - offsetY;
98        if(y <= 0) {
99            y = 0;
100        }
101        top_max = document.body.clientHeight - arrObj[obj.id].height;
102        if(y >= top_max) {
103            y =top_max;         
104        }
105        obj.style.top = y;     
106    // WIN-NN,WIN-FF
107    } else if (obj.getElementsByTagName) {
108        x = e.pageX - offsetX;
109        // ²èÌ̳°¤Ë½Ð¤Ê¤¤¤è¤¦¤ËÀ©¸æ¤¹¤ë¡¡
110        if(x <= 0) {
111            x = 0;
112        }
113        left_max = window.innerWidth - arrObj[obj.id].width;
114        if(x >= left_max) {
115            x =left_max;           
116        }
117        obj.style.left = x;
118       
119        y = e.pageY - offsetY;
120        // ²èÌ̳°¤Ë½Ð¤Ê¤¤¤è¤¦¤ËÀ©¸æ¤¹¤ë¡¡
121        if(y <= 0) {
122            y = 0;
123            obj.style.top = 0;
124        }
125        top_max = window.innerHeight - arrObj[obj.id].height;
126        if(y >= top_max) {
127            y =top_max;         
128        }
129        obj.style.top = y;
130    }
131   
132    if(isInFlame('flame0', obj)) {
133        document.getElementById('td1').style.backgroundColor = '#fffadd';
134    } else {
135        document.getElementById('td1').style.backgroundColor = '#ffffff';
136    }
137    return false;
138}
139
140// MouseUp¥¤¥Ù¥ó¥È
141function onMouseUp(e) {
142    if (!obj) {
143        return true;
144    }
145   
146    if(!isInFlame('flame0', obj)) {
147        // WIN-IE
148        if (document.all) {
149            // ºÇ½é¤Î°ÌÃÖ¤ËÌ᤹
150            obj.style.left = arrObj[obj.id].left;
151            obj.style.top = arrObj[obj.id].top;
152        // WIN-NN,WIN-FF
153        } else if (obj.getElementsByTagName) {
154            // ºÇ½é¤Î°ÌÃÖ¤ËÌ᤹
155            obj.style.left = arrObj[obj.id].left;
156            obj.style.top = arrObj[obj.id].top;
157        }
158    }   
159    document.getElementById('td1').style.backgroundColor = '#ffffff';   
160    obj = null;
161}
162
163// ¥Õ¥ì¡¼¥àÆâ¤Ë¥¢¥¤¥Æ¥à¤¬Â¸ºß¤¹¤ë¤«È½Äꤹ¤ë¡¡
164function isInFlame(flame_id, item) {
165    top_val = item.style.top;
166    top_val = Number(top_val.replace(/px/, ''));
167    bottom_val = top_val + arrObj[item.id].height;
168    left_val = item.style.left;
169    left_val = Number(left_val.replace(/px/, ''))
170    right_val = left_val + arrObj[item.id].width;       
171    if(
172        top_val > arrObj[flame_id].top &&
173        bottom_val < arrObj[flame_id].bottom &&
174        left_val > arrObj[flame_id].left &&
175        right_val < arrObj[flame_id].right
176        ) {
177        return true;
178    }
179    return false;
180}
181
182// Á÷¿®Á°¤Î½èÍý
183function preSubmit() {
184    for(i = 0; i < 3; i++) {
185        id = 'item' + i;
186        obj = arrObj[id].obj;
187        if(isInFlame ('flame0', obj)) {
188            document.form1[obj.id].value = "in";
189        } else {
190            document.form1[obj.id].value = "out";
191        }
192    }
193}
194
195
196
Note: See TracBrowser for help on using the repository browser.