+++ /dev/null
-// Copyright (c) 2005 Thomas Fakes (http://craz8.com)\r
-// \r
-// This code is substantially based on code from script.aculo.us which has the \r
-// following copyright and permission notice\r
-//\r
-// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)\r
-// \r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-//\r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-\r
-var Resizeable = Class.create();\r
-Resizeable.prototype = {\r
- initialize: function(element) {\r
- var options = Object.extend({\r
- top: 6,\r
- bottom: 6,\r
- left: 6,\r
- right: 6,\r
- minHeight: 0,\r
- minWidth: 0,\r
- zindex: 1000,\r
- resize: null\r
- }, arguments[1] || {});\r
-\r
- this.element = $(element);\r
- this.handle = this.element;\r
-\r
- Element.makePositioned(this.element); // fix IE \r
-\r
- this.options = options;\r
-\r
- this.active = false;\r
- this.resizing = false; \r
- this.currentDirection = '';\r
-\r
- this.eventMouseDown = this.startResize.bindAsEventListener(this);\r
- this.eventMouseUp = this.endResize.bindAsEventListener(this);\r
- this.eventMouseMove = this.update.bindAsEventListener(this);\r
- this.eventCursorCheck = this.cursor.bindAsEventListener(this);\r
- this.eventKeypress = this.keyPress.bindAsEventListener(this);\r
- \r
- this.registerEvents();\r
- },\r
- destroy: function() {\r
- Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);\r
- this.unregisterEvents();\r
- },\r
- registerEvents: function() {\r
- Event.observe(document, "mouseup", this.eventMouseUp);\r
- Event.observe(document, "mousemove", this.eventMouseMove);\r
- Event.observe(document, "keypress", this.eventKeypress);\r
- Event.observe(this.handle, "mousedown", this.eventMouseDown);\r
- Event.observe(this.element, "mousemove", this.eventCursorCheck);\r
- },\r
- unregisterEvents: function() {\r
- //if(!this.active) return;\r
- //Event.stopObserving(document, "mouseup", this.eventMouseUp);\r
- //Event.stopObserving(document, "mousemove", this.eventMouseMove);\r
- //Event.stopObserving(document, "mousemove", this.eventCursorCheck);\r
- //Event.stopObserving(document, "keypress", this.eventKeypress);\r
- },\r
- startResize: function(event) {\r
- if(Event.isLeftClick(event)) {\r
- \r
- // abort on form elements, fixes a Firefox issue\r
- var src = Event.element(event);\r
- if(src.tagName && (\r
- src.tagName=='INPUT' ||\r
- src.tagName=='SELECT' ||\r
- src.tagName=='BUTTON' ||\r
- src.tagName=='TEXTAREA')) return;\r
-\r
- var dir = this.directions(event);\r
- if (dir.length > 0) { \r
- this.active = true;\r
- var offsets = Position.cumulativeOffset(this.element);\r
- this.startTop = offsets[1];\r
- this.startLeft = offsets[0];\r
- this.startWidth = parseInt(Element.getStyle(this.element, 'width'));\r
- this.startHeight = parseInt(Element.getStyle(this.element, 'height'));\r
- this.startX = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;\r
- this.startY = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;\r
- \r
- this.currentDirection = dir;\r
- Event.stop(event);\r
- }\r
- }\r
- },\r
- finishResize: function(event, success) {\r
- // this.unregisterEvents();\r
-\r
- this.active = false;\r
- this.resizing = false;\r
-\r
- if(this.options.zindex)\r
- this.element.style.zIndex = this.originalZ;\r
- \r
- if (this.options.resize) {\r
- this.options.resize(this.element);\r
- }\r
- },\r
- keyPress: function(event) {\r
- if(this.active) {\r
- if(event.keyCode==Event.KEY_ESC) {\r
- this.finishResize(event, false);\r
- Event.stop(event);\r
- }\r
- }\r
- },\r
- endResize: function(event) {\r
- if(this.active && this.resizing) {\r
- this.finishResize(event, true);\r
- Event.stop(event);\r
- }\r
- this.active = false;\r
- this.resizing = false;\r
- },\r
- draw: function(event) {\r
- var pointer = [Event.pointerX(event), Event.pointerY(event)];\r
- var style = this.element.style;\r
- if (this.currentDirection.indexOf('n') != -1) {\r
- var pointerMoved = this.startY - pointer[1];\r
- var margin = Element.getStyle(this.element, 'margin-top') || "0";\r
- var newHeight = this.startHeight + pointerMoved;\r
- if (newHeight > this.options.minHeight) {\r
- style.height = newHeight + "px";\r
- style.top = (this.startTop - pointerMoved - parseInt(margin)) + "px";\r
- }\r
- }\r
- if (this.currentDirection.indexOf('w') != -1) {\r
- var pointerMoved = this.startX - pointer[0];\r
- var margin = Element.getStyle(this.element, 'margin-left') || "0";\r
- var newWidth = this.startWidth + pointerMoved;\r
- if (newWidth > this.options.minWidth) {\r
- style.left = (this.startLeft - pointerMoved - parseInt(margin)) + "px";\r
- style.width = newWidth + "px";\r
- }\r
- }\r
- if (this.currentDirection.indexOf('s') != -1) {\r
- var newHeight = this.startHeight + pointer[1] - this.startY;\r
- if (newHeight > this.options.minHeight) {\r
- style.height = newHeight + "px";\r
- }\r
- }\r
- if (this.currentDirection.indexOf('e') != -1) {\r
- var newWidth = this.startWidth + pointer[0] - this.startX;\r
- if (newWidth > this.options.minWidth) {\r
- style.width = newWidth + "px";\r
- }\r
- }\r
- if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering\r
- },\r
- between: function(val, low, high) {\r
- return (val >= low && val < high);\r
- },\r
- directions: function(event) {\r
- var pointer = [Event.pointerX(event), Event.pointerY(event)];\r
- var offsets = Position.cumulativeOffset(this.element);\r
- \r
- var cursor = '';\r
- if (this.between(pointer[1] - offsets[1], 0, this.options.top)) cursor += 'n';\r
- if (this.between((offsets[1] + this.element.offsetHeight) - pointer[1], 0, this.options.bottom)) cursor += 's';\r
- if (this.between(pointer[0] - offsets[0], 0, this.options.left)) cursor += 'w';\r
- if (this.between((offsets[0] + this.element.offsetWidth) - pointer[0], 0, this.options.right)) cursor += 'e';\r
-\r
- return cursor;\r
- },\r
- cursor: function(event) {\r
- var cursor = this.directions(event);\r
- if (cursor.length > 0) {\r
- cursor += '-resize';\r
- } else {\r
- cursor = '';\r
- }\r
- this.element.style.cursor = cursor; \r
- },\r
- update: function(event) {\r
- if(this.active) {\r
- if(!this.resizing) {\r
- var style = this.element.style;\r
- this.resizing = true;\r
- \r
- if(Element.getStyle(this.element,'position')=='') \r
- style.position = "relative";\r
- \r
- if(this.options.zindex) {\r
- this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);\r
- style.zIndex = this.options.zindex;\r
- }\r
- }\r
- this.draw(event);\r
-\r
- // fix AppleWebKit rendering\r
- if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0); \r
- Event.stop(event);\r
- return false;\r
- }\r
- }\r
-}\r