OSDN Git Service

setup spinelz environment
[cloudmanganw/git_repo.git] / src / jp / sourceforge / manganetwork / page / javascripts / spinelz / window_resizeEx.js
1 // Copyright (c) 2005 spinelz.org (http://script.spinelz.org/)
2 // 
3 // This code is substantially based on code from Thomas Fakes(http://craz8.com) 
4 // which has the following copyright and permission notice
5 // 
6 // Copyright (c) 2005 Thomas Fakes (http://craz8.com)
7 // 
8 // This code is substantially based on code from script.aculo.us which has the 
9 // following copyright and permission notice
10 //
11 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
12 // 
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
32 ResizeableWindowEx = Class.create();
33 Object.extend(Object.extend(ResizeableWindowEx.prototype, Resizeable.prototype), {
34   startResize: function(event) {
35     if (Event.isLeftClick(event)) {
36       
37       // abort on form elements, fixes a Firefox issue
38       var src = Event.element(event);
39       if(src.tagName && (
40         src.tagName=='INPUT' ||
41         src.tagName=='SELECT' ||
42         src.tagName=='BUTTON' ||
43         src.tagName=='TEXTAREA')) return;
44
45       var dir = this.directions(event);
46       if (dir.length > 0) {      
47         this.active = true;
48         var offsets = Position.cumulativeOffset(this.element);
49         this.startTop = offsets[1];
50         this.startLeft = offsets[0];
51         this.startWidth = parseInt(Element.getStyle(this.element, 'width'));
52         this.startHeight = parseInt(Element.getStyle(this.element, 'height'));
53         this.startX = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
54         this.startY = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
55         
56         this.currentDirection = dir;
57         Event.stop(event);
58       }
59
60       if (this.options.restriction) {
61         var parent = this.element.parentNode;
62         var dimensions = Element.getDimensions(parent);
63         this.parentOffset = Position.cumulativeOffset(parent);
64         this.parentWidth = this.parentOffset[0] + dimensions.width;
65         this.parentHeight = this.parentOffset[1] + dimensions.height;
66       }
67     }
68   },
69
70   draw: function(event) {
71     var pointer = [Event.pointerX(event), Event.pointerY(event)];
72     if (this.options.restriction &&
73       (
74         (this.parentWidth <= pointer[0])
75         || (this.parentHeight <= pointer[1])
76         || (this.parentOffset[0] >= pointer[0])
77         || (this.parentOffset[1] >= pointer[1])
78       )) return;
79
80     var style = this.element.style;
81     var newHeight = style.height;
82     var newWidth = style.width;
83     var newTop = style.top;
84     var newLeft = style.left;
85
86     if (this.currentDirection.indexOf('n') != -1) {
87       var pointerMoved = this.startY - pointer[1];
88       var margin = Element.getStyle(this.element, 'margin-top') || "0";
89       newHeight = this.startHeight + pointerMoved;
90       newTop = (this.startTop - pointerMoved - parseInt(margin)) + "px";
91     }
92     
93     if (this.currentDirection.indexOf('w') != -1) {
94       var pointerMoved = this.startX - pointer[0];
95       var margin = Element.getStyle(this.element, 'margin-left') || "0";
96       newWidth = this.startWidth + pointerMoved;
97       newLeft = this.startLeft - pointerMoved - parseInt(margin);
98       if (this.options.restriction) newLeft -= this.parentOffset[0];
99       newLeft += 'px';
100     }
101     
102     if (this.currentDirection.indexOf('s') != -1) {
103       newHeight = this.startHeight + pointer[1] - this.startY;
104     }
105     
106     if (this.currentDirection.indexOf('e') != -1) {
107       newWidth = this.startWidth + pointer[0] - this.startX;
108     }
109     
110     var newStyle = {
111       height: newHeight,
112       width: newWidth,
113       top: newTop,
114       left: newLeft
115     }
116     if (this.options.draw) {
117       this.options.draw(newStyle, this.element);
118     }
119       
120     if (newHeight && newHeight > this.options.minHeight) {
121       style.top = newStyle.top;
122       style.height = newStyle.height + "px";
123     }
124     if (newWidth && newWidth > this.options.minWidth) {
125       style.left = newStyle.left;
126       style.width = newStyle.width + "px";
127     }
128     if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
129   }
130 });