1 // Resizable textareas (fun!) |
1 // Resizable textareas (fun!) |
2 |
2 |
3 function taStartDrag() |
3 function taStartDrag() |
4 { |
4 { |
5 obj = this; |
5 obj = this; |
6 current_ta = obj.previousSibling; |
6 current_ta = obj.previousSibling; |
7 startmouseX = mouseX; |
7 startmouseX = mouseX; |
8 startmouseY = mouseY; |
8 startmouseY = mouseY; |
9 startScroll = getScrollOffset(); |
9 startScroll = getScrollOffset(); |
10 is_dragging = true; |
10 is_dragging = true; |
11 startwidth = getElementWidth(current_ta.id); |
11 startwidth = getElementWidth(current_ta.id); |
12 startheight = getElementHeight(current_ta.id); |
12 startheight = getElementHeight(current_ta.id); |
13 var body = document.getElementsByTagName('body'); |
13 var body = document.getElementsByTagName('body'); |
14 body = body[0]; |
14 body = body[0]; |
15 body.style.cursor = 's-resize'; |
15 body.style.cursor = 's-resize'; |
16 } |
16 } |
17 function taInDrag() |
17 function taInDrag() |
18 { |
18 { |
19 if(!is_dragging) return; |
19 if(!is_dragging) return; |
20 cw = startwidth; |
20 cw = startwidth; |
21 ch = startheight; |
21 ch = startheight; |
22 mx = mouseX; |
22 mx = mouseX; |
23 my = mouseY + getScrollOffset() - startScroll; |
23 my = mouseY + getScrollOffset() - startScroll; |
24 ch = -6 + ch + ( my - startmouseY ); |
24 ch = -6 + ch + ( my - startmouseY ); |
25 current_ta.style.height = ch+'px'; |
25 current_ta.style.height = ch+'px'; |
26 if(do_width) |
26 if(do_width) |
27 { |
27 { |
28 current_ta.style.width = mx+'px'; |
28 current_ta.style.width = mx+'px'; |
29 current_ta.nextSibling.style.width = mx+'px'; |
29 current_ta.nextSibling.style.width = mx+'px'; |
30 } |
30 } |
31 } |
31 } |
32 function taCloseDrag() |
32 function taCloseDrag() |
33 { |
33 { |
34 is_dragging = false; |
34 is_dragging = false; |
35 current_ta = false; |
35 current_ta = false; |
36 body = document.getElementsByTagName('body'); |
36 body = document.getElementsByTagName('body'); |
37 body = body[0]; |
37 body = body[0]; |
38 body.style.cursor = 'default'; |
38 body.style.cursor = 'default'; |
39 } |
39 } |
40 |
40 |
41 var grippied_textareas = new Array(); |
41 var grippied_textareas = new Array(); |
42 |
42 |
43 function initTextareas() |
43 function initTextareas() |
44 { |
44 { |
45 var textareas = document.getElementsByTagName('textarea'); |
45 var textareas = document.getElementsByTagName('textarea'); |
46 for (i = 0;i < textareas.length;i++) |
46 for (i = 0;i < textareas.length;i++) |
47 { |
47 { |
48 if(!textareas[i].id) |
48 if(!textareas[i].id) |
49 textareas[i].id = 'autoTextArea_'+Math.floor(Math.random()*100000); |
49 textareas[i].id = 'autoTextArea_'+Math.floor(Math.random()*100000); |
50 cta = textareas[i]; |
50 cta = textareas[i]; |
51 var divchk = ( in_array(cta.id, grippied_textareas) ) ? false : true; |
51 var divchk = ( in_array(cta.id, grippied_textareas) ) ? false : true; |
52 if(divchk) |
52 if(divchk) |
53 { |
53 { |
54 grippied_textareas.push(cta.id); |
54 grippied_textareas.push(cta.id); |
55 makeGrippy(cta); |
55 makeGrippy(cta); |
56 } |
56 } |
57 } |
57 } |
58 } |
58 } |
59 |
59 |
60 function makeGrippy(cta) |
60 function makeGrippy(cta) |
61 { |
61 { |
62 var thediv = document.createElement('div'); |
62 var thediv = document.createElement('div'); |
63 thediv.style.backgroundColor = '#ceceed'; |
63 thediv.style.backgroundColor = '#ceceed'; |
64 thediv.style.backgroundImage = 'url('+scriptPath+'/images/grippy.gif)'; |
64 thediv.style.backgroundImage = 'url('+scriptPath+'/images/grippy.gif)'; |
65 thediv.style.backgroundPosition = 'bottom right'; |
65 thediv.style.backgroundPosition = 'bottom right'; |
66 thediv.style.backgroundRepeat = 'no-repeat'; |
66 thediv.style.backgroundRepeat = 'no-repeat'; |
67 thediv.style.width = getElementWidth(cta.id)+'px'; |
67 thediv.style.width = getElementWidth(cta.id)+'px'; |
68 thediv.style.cursor = 's-resize'; |
68 thediv.style.cursor = 's-resize'; |
69 thediv.style.className = 'ThisIsATextareaGrippy'; |
69 thediv.style.className = 'ThisIsATextareaGrippy'; |
70 thediv.id = 'autoGrippy_'+Math.floor(Math.random()*100000); |
70 thediv.id = 'autoGrippy_'+Math.floor(Math.random()*100000); |
71 thediv.style.height = '12px'; |
71 thediv.style.height = '12px'; |
72 thediv.onmousedown = taStartDrag; |
72 thediv.onmousedown = taStartDrag; |
73 thediv.style.border = '1px solid #0000A0'; |
73 thediv.style.border = '1px solid #0000A0'; |
74 if(cta.style.marginBottom) |
74 if(cta.style.marginBottom) |
75 { |
75 { |
76 thediv.style.marginBottom = cta.style.marginBottom; |
76 thediv.style.marginBottom = cta.style.marginBottom; |
77 cta.style.marginBottom = '0'; |
77 cta.style.marginBottom = '0'; |
78 } |
78 } |
79 if(cta.style.marginLeft) |
79 if(cta.style.marginLeft) |
80 { |
80 { |
81 thediv.style.marginLeft = cta.style.marginLeft; |
81 thediv.style.marginLeft = cta.style.marginLeft; |
82 } |
82 } |
83 if(cta.style.marginRight) |
83 if(cta.style.marginRight) |
84 { |
84 { |
85 thediv.style.marginRight = cta.style.marginRight; |
85 thediv.style.marginRight = cta.style.marginRight; |
86 } |
86 } |
87 document.onmouseup = taCloseDrag; |
87 document.onmouseup = taCloseDrag; |
88 if(cta.nextSibling) cta.parentNode.insertBefore(thediv, cta.nextSibling); |
88 if(cta.nextSibling) cta.parentNode.insertBefore(thediv, cta.nextSibling); |
89 else cta.parentNode.appendChild(thediv); |
89 else cta.parentNode.appendChild(thediv); |
90 } |
90 } |
91 |
91 |